org-agenda.el 391 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2014 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type '(choice
  203. (const nil)
  204. (string)))
  205. (defcustom org-agenda-persistent-filter nil
  206. "When set, keep filters from one agenda view to the next."
  207. :group 'org-agenda
  208. :type 'boolean)
  209. (defgroup org-agenda-custom-commands nil
  210. "Options concerning agenda views in Org-mode."
  211. :tag "Org Agenda Custom Commands"
  212. :group 'org-agenda)
  213. (defconst org-sorting-choice
  214. '(choice
  215. (const time-up) (const time-down)
  216. (const timestamp-up) (const timestamp-down)
  217. (const scheduled-up) (const scheduled-down)
  218. (const deadline-up) (const deadline-down)
  219. (const ts-up) (const ts-down)
  220. (const tsia-up) (const tsia-down)
  221. (const category-keep) (const category-up) (const category-down)
  222. (const tag-down) (const tag-up)
  223. (const priority-up) (const priority-down)
  224. (const todo-state-up) (const todo-state-down)
  225. (const effort-up) (const effort-down)
  226. (const habit-up) (const habit-down)
  227. (const alpha-up) (const alpha-down)
  228. (const user-defined-up) (const user-defined-down))
  229. "Sorting choices.")
  230. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  231. ;; the new variable `org-agenda-tag-filter-preset'.
  232. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  233. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  234. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  235. "List of types searched for when creating the daily/weekly agenda.
  236. This variable is a list of symbols that controls the types of
  237. items that appear in the daily/weekly agenda. Allowed symbols in this
  238. list are are
  239. :timestamp List items containing a date stamp or date range matching
  240. the selected date. This includes sexp entries in angular
  241. brackets.
  242. :sexp List entries resulting from plain diary-like sexps.
  243. :deadline List deadline due on that date. When the date is today,
  244. also list any deadlines past due, or due within
  245. `org-deadline-warning-days'. `:deadline' must appear before
  246. `:scheduled' if the setting of
  247. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  248. any effect.
  249. :deadline* Same as above, but only include the deadline if it has an
  250. hour specification as [h]h:mm.
  251. :scheduled List all items which are scheduled for the given date.
  252. The diary for *today* also contains items which were
  253. scheduled earlier and are not yet marked DONE.
  254. :scheduled* Same as above, but only include the scheduled item if it
  255. has an hour specification as [h]h:mm.
  256. By default, all four non-starred types are turned on.
  257. When :scheduled* or :deadline* are included, :schedule or :deadline
  258. will be ignored.
  259. Never set this variable globally using `setq', because then it
  260. will apply to all future agenda commands. Instead, bind it with
  261. `let' to scope it dynamically into the agenda-constructing
  262. command. A good way to set it is through options in
  263. `org-agenda-custom-commands'. For a more flexible (though
  264. somewhat less efficient) way of determining what is included in
  265. the daily/weekly agenda, see `org-agenda-skip-function'.")
  266. (defconst org-agenda-custom-commands-local-options
  267. `(repeat :tag "Local settings for this command. Remember to quote values"
  268. (choice :tag "Setting"
  269. (list :tag "Heading for this block"
  270. (const org-agenda-overriding-header)
  271. (string :tag "Headline"))
  272. (list :tag "Files to be searched"
  273. (const org-agenda-files)
  274. (list
  275. (const :format "" quote)
  276. (repeat (file))))
  277. (list :tag "Sorting strategy"
  278. (const org-agenda-sorting-strategy)
  279. (list
  280. (const :format "" quote)
  281. (repeat
  282. ,org-sorting-choice)))
  283. (list :tag "Prefix format"
  284. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  285. (string))
  286. (list :tag "Number of days in agenda"
  287. (const org-agenda-span)
  288. (choice (const :tag "Day" day)
  289. (const :tag "Week" week)
  290. (const :tag "Fortnight" fortnight)
  291. (const :tag "Month" month)
  292. (const :tag "Year" year)
  293. (integer :tag "Custom")))
  294. (list :tag "Fixed starting date"
  295. (const org-agenda-start-day)
  296. (string :value "2007-11-01"))
  297. (list :tag "Start on day of week"
  298. (const org-agenda-start-on-weekday)
  299. (choice :value 1
  300. (const :tag "Today" nil)
  301. (integer :tag "Weekday No.")))
  302. (list :tag "Include data from diary"
  303. (const org-agenda-include-diary)
  304. (boolean))
  305. (list :tag "Deadline Warning days"
  306. (const org-deadline-warning-days)
  307. (integer :value 1))
  308. (list :tag "Category filter preset"
  309. (const org-agenda-category-filter-preset)
  310. (list
  311. (const :format "" quote)
  312. (repeat
  313. (string :tag "+category or -category"))))
  314. (list :tag "Tags filter preset"
  315. (const org-agenda-tag-filter-preset)
  316. (list
  317. (const :format "" quote)
  318. (repeat
  319. (string :tag "+tag or -tag"))))
  320. (list :tag "Regexp filter preset"
  321. (const org-agenda-regexp-filter-preset)
  322. (list
  323. (const :format "" quote)
  324. (repeat
  325. (string :tag "+regexp or -regexp"))))
  326. (list :tag "Set daily/weekly entry types"
  327. (const org-agenda-entry-types)
  328. (list
  329. (const :format "" quote)
  330. (set :greedy t :value ,org-agenda-entry-types
  331. (const :deadline)
  332. (const :scheduled)
  333. (const :deadline*)
  334. (const :scheduled*)
  335. (const :timestamp)
  336. (const :sexp))))
  337. (list :tag "Standard skipping condition"
  338. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  339. (const org-agenda-skip-function)
  340. (list
  341. (const :format "" quote)
  342. (list
  343. (choice
  344. :tag "Skipping range"
  345. (const :tag "Skip entry" org-agenda-skip-entry-if)
  346. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  347. (repeat :inline t :tag "Conditions for skipping"
  348. (choice
  349. :tag "Condition type"
  350. (list :tag "Regexp matches" :inline t (const :format "" regexp) (regexp))
  351. (list :tag "Regexp does not match" :inline t (const :format "" notregexp) (regexp))
  352. (list :tag "TODO state is" :inline t
  353. (const todo)
  354. (choice
  355. (const :tag "any not-done state" todo)
  356. (const :tag "any done state" done)
  357. (const :tag "any state" any)
  358. (list :tag "Keyword list"
  359. (const :format "" quote)
  360. (repeat (string :tag "Keyword")))))
  361. (list :tag "TODO state is not" :inline t
  362. (const nottodo)
  363. (choice
  364. (const :tag "any not-done state" todo)
  365. (const :tag "any done state" done)
  366. (const :tag "any state" any)
  367. (list :tag "Keyword list"
  368. (const :format "" quote)
  369. (repeat (string :tag "Keyword")))))
  370. (const :tag "scheduled" scheduled)
  371. (const :tag "not scheduled" notscheduled)
  372. (const :tag "deadline" deadline)
  373. (const :tag "no deadline" notdeadline)
  374. (const :tag "timestamp" timestamp)
  375. (const :tag "no timestamp" nottimestamp))))))
  376. (list :tag "Non-standard skipping condition"
  377. :value (org-agenda-skip-function)
  378. (const org-agenda-skip-function)
  379. (sexp :tag "Function or form (quoted!)"))
  380. (list :tag "Any variable"
  381. (variable :tag "Variable")
  382. (sexp :tag "Value (sexp)"))))
  383. "Selection of examples for agenda command settings.
  384. This will be spliced into the custom type of
  385. `org-agenda-custom-commands'.")
  386. (defcustom org-agenda-custom-commands
  387. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  388. "Custom commands for the agenda.
  389. These commands will be offered on the splash screen displayed by the
  390. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  391. (key desc type match settings files)
  392. key The key (one or more characters as a string) to be associated
  393. with the command.
  394. desc A description of the command, when omitted or nil, a default
  395. description is built using MATCH.
  396. type The command type, any of the following symbols:
  397. agenda The daily/weekly agenda.
  398. todo Entries with a specific TODO keyword, in all agenda files.
  399. search Entries containing search words entry or headline.
  400. tags Tags/Property/TODO match in all agenda files.
  401. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  402. todo-tree Sparse tree of specific TODO keyword in *current* file.
  403. tags-tree Sparse tree with all tags matches in *current* file.
  404. occur-tree Occur sparse tree for *current* file.
  405. ... A user-defined function.
  406. match What to search for:
  407. - a single keyword for TODO keyword searches
  408. - a tags match expression for tags searches
  409. - a word search expression for text searches.
  410. - a regular expression for occur searches
  411. For all other commands, this should be the empty string.
  412. settings A list of option settings, similar to that in a let form, so like
  413. this: ((opt1 val1) (opt2 val2) ...). The values will be
  414. evaluated at the moment of execution, so quote them when needed.
  415. files A list of files file to write the produced agenda buffer to
  416. with the command `org-store-agenda-views'.
  417. If a file name ends in \".html\", an HTML version of the buffer
  418. is written out. If it ends in \".ps\", a postscript version is
  419. produced. Otherwise, only the plain text is written to the file.
  420. You can also define a set of commands, to create a composite agenda buffer.
  421. In this case, an entry looks like this:
  422. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  423. where
  424. desc A description string to be displayed in the dispatcher menu.
  425. cmd An agenda command, similar to the above. However, tree commands
  426. are not allowed, but instead you can get agenda and global todo list.
  427. So valid commands for a set are:
  428. (agenda \"\" settings)
  429. (alltodo \"\" settings)
  430. (stuck \"\" settings)
  431. (todo \"match\" settings files)
  432. (search \"match\" settings files)
  433. (tags \"match\" settings files)
  434. (tags-todo \"match\" settings files)
  435. Each command can carry a list of options, and another set of options can be
  436. given for the whole set of commands. Individual command options take
  437. precedence over the general options.
  438. When using several characters as key to a command, the first characters
  439. are prefix commands. For the dispatcher to display useful information, you
  440. should provide a description for the prefix, like
  441. (setq org-agenda-custom-commands
  442. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  443. (\"hl\" tags \"+HOME+Lisa\")
  444. (\"hp\" tags \"+HOME+Peter\")
  445. (\"hk\" tags \"+HOME+Kim\")))"
  446. :group 'org-agenda-custom-commands
  447. :type `(repeat
  448. (choice :value ("x" "Describe command here" tags "" nil)
  449. (list :tag "Single command"
  450. (string :tag "Access Key(s) ")
  451. (option (string :tag "Description"))
  452. (choice
  453. (const :tag "Agenda" agenda)
  454. (const :tag "TODO list" alltodo)
  455. (const :tag "Search words" search)
  456. (const :tag "Stuck projects" stuck)
  457. (const :tag "Tags/Property match (all agenda files)" tags)
  458. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  459. (const :tag "TODO keyword search (all agenda files)" todo)
  460. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  461. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  462. (const :tag "Occur tree (current buffer)" occur-tree)
  463. (sexp :tag "Other, user-defined function"))
  464. (string :tag "Match (only for some commands)")
  465. ,org-agenda-custom-commands-local-options
  466. (option (repeat :tag "Export" (file :tag "Export to"))))
  467. (list :tag "Command series, all agenda files"
  468. (string :tag "Access Key(s)")
  469. (string :tag "Description ")
  470. (repeat :tag "Component"
  471. (choice
  472. (list :tag "Agenda"
  473. (const :format "" agenda)
  474. (const :tag "" :format "" "")
  475. ,org-agenda-custom-commands-local-options)
  476. (list :tag "TODO list (all keywords)"
  477. (const :format "" alltodo)
  478. (const :tag "" :format "" "")
  479. ,org-agenda-custom-commands-local-options)
  480. (list :tag "Search words"
  481. (const :format "" search)
  482. (string :tag "Match")
  483. ,org-agenda-custom-commands-local-options)
  484. (list :tag "Stuck projects"
  485. (const :format "" stuck)
  486. (const :tag "" :format "" "")
  487. ,org-agenda-custom-commands-local-options)
  488. (list :tag "Tags search"
  489. (const :format "" tags)
  490. (string :tag "Match")
  491. ,org-agenda-custom-commands-local-options)
  492. (list :tag "Tags search, TODO entries only"
  493. (const :format "" tags-todo)
  494. (string :tag "Match")
  495. ,org-agenda-custom-commands-local-options)
  496. (list :tag "TODO keyword search"
  497. (const :format "" todo)
  498. (string :tag "Match")
  499. ,org-agenda-custom-commands-local-options)
  500. (list :tag "Other, user-defined function"
  501. (symbol :tag "function")
  502. (string :tag "Match")
  503. ,org-agenda-custom-commands-local-options)))
  504. (repeat :tag "Settings for entire command set"
  505. (list (variable :tag "Any variable")
  506. (sexp :tag "Value")))
  507. (option (repeat :tag "Export" (file :tag "Export to"))))
  508. (cons :tag "Prefix key documentation"
  509. (string :tag "Access Key(s)")
  510. (string :tag "Description ")))))
  511. (defcustom org-agenda-query-register ?o
  512. "The register holding the current query string.
  513. The purpose of this is that if you construct a query string interactively,
  514. you can then use it to define a custom command."
  515. :group 'org-agenda-custom-commands
  516. :type 'character)
  517. (defcustom org-stuck-projects
  518. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  519. "How to identify stuck projects.
  520. This is a list of four items:
  521. 1. A tags/todo/property matcher string that is used to identify a project.
  522. See the manual for a description of tag and property searches.
  523. The entire tree below a headline matched by this is considered one project.
  524. 2. A list of TODO keywords identifying non-stuck projects.
  525. If the project subtree contains any headline with one of these todo
  526. keywords, the project is considered to be not stuck. If you specify
  527. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  528. 3. A list of tags identifying non-stuck projects.
  529. If the project subtree contains any headline with one of these tags,
  530. the project is considered to be not stuck. If you specify \"*\" as
  531. a tag, any tag will mark the project unstuck. Note that this is about
  532. the explicit presence of a tag somewhere in the subtree, inherited
  533. tags do not count here. If inherited tags make a project not stuck,
  534. use \"-TAG\" in the tags part of the matcher under (1.) above.
  535. 4. An arbitrary regular expression matching non-stuck projects.
  536. If the project turns out to be not stuck, search continues also in the
  537. subtree to see if any of the subtasks have project status.
  538. See also the variable `org-tags-match-list-sublevels' which applies
  539. to projects matched by this search as well.
  540. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  541. or `C-c a #' to produce the list."
  542. :group 'org-agenda-custom-commands
  543. :type '(list
  544. (string :tag "Tags/TODO match to identify a project")
  545. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  546. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  547. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  548. (defcustom org-agenda-filter-effort-default-operator "<"
  549. "The default operator for effort estimate filtering.
  550. If you select an effort estimate limit without first pressing an operator,
  551. this one will be used."
  552. :group 'org-agenda-custom-commands
  553. :type '(choice (const :tag "less or equal" "<")
  554. (const :tag "greater or equal"">")
  555. (const :tag "equal" "=")))
  556. (defgroup org-agenda-skip nil
  557. "Options concerning skipping parts of agenda files."
  558. :tag "Org Agenda Skip"
  559. :group 'org-agenda)
  560. (defcustom org-agenda-skip-function-global nil
  561. "Function to be called at each match during agenda construction.
  562. If this function returns nil, the current match should not be skipped.
  563. If the function decided to skip an agenda match, is must return the
  564. buffer position from which the search should be continued.
  565. This may also be a Lisp form, which will be evaluated.
  566. This variable will be applied to every agenda match, including
  567. tags/property searches and TODO lists. So try to make the test function
  568. do its checking as efficiently as possible. To implement a skipping
  569. condition just for specific agenda commands, use the variable
  570. `org-agenda-skip-function' which can be set in the options section
  571. of custom agenda commands."
  572. :group 'org-agenda-skip
  573. :type 'sexp)
  574. (defgroup org-agenda-daily/weekly nil
  575. "Options concerning the daily/weekly agenda."
  576. :tag "Org Agenda Daily/Weekly"
  577. :group 'org-agenda)
  578. (defgroup org-agenda-todo-list nil
  579. "Options concerning the global todo list agenda view."
  580. :tag "Org Agenda Todo List"
  581. :group 'org-agenda)
  582. (defgroup org-agenda-match-view nil
  583. "Options concerning the general tags/property/todo match agenda view."
  584. :tag "Org Agenda Match View"
  585. :group 'org-agenda)
  586. (defgroup org-agenda-search-view nil
  587. "Options concerning the search agenda view."
  588. :tag "Org Agenda Search View"
  589. :group 'org-agenda)
  590. (defvar org-agenda-archives-mode nil
  591. "Non-nil means the agenda will include archived items.
  592. If this is the symbol `trees', trees in the selected agenda scope
  593. that are marked with the ARCHIVE tag will be included anyway. When this is
  594. t, also all archive files associated with the current selection of agenda
  595. files will be included.")
  596. (defcustom org-agenda-restriction-lock-highlight-subtree t
  597. "Non-nil means highlight the whole subtree when restriction is active.
  598. Otherwise only highlight the headline. Highlighting the whole subtree is
  599. useful to ensure no edits happen beyond the restricted region."
  600. :group 'org-agenda
  601. :type 'boolean)
  602. (defcustom org-agenda-skip-comment-trees t
  603. "Non-nil means skip trees that start with the COMMENT keyword.
  604. When nil, these trees are also scanned by agenda commands."
  605. :group 'org-agenda-skip
  606. :type 'boolean)
  607. (defcustom org-agenda-todo-list-sublevels t
  608. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  609. When nil, the sublevels of a TODO entry are not checked, resulting in
  610. potentially much shorter TODO lists."
  611. :group 'org-agenda-skip
  612. :group 'org-agenda-todo-list
  613. :type 'boolean)
  614. (defcustom org-agenda-todo-ignore-with-date nil
  615. "Non-nil means don't show entries with a date in the global todo list.
  616. You can use this if you prefer to mark mere appointments with a TODO keyword,
  617. but don't want them to show up in the TODO list.
  618. When this is set, it also covers deadlines and scheduled items, the settings
  619. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  620. will be ignored.
  621. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  622. :group 'org-agenda-skip
  623. :group 'org-agenda-todo-list
  624. :type 'boolean)
  625. (defcustom org-agenda-todo-ignore-timestamp nil
  626. "Non-nil means don't show entries with a timestamp.
  627. This applies when creating the global todo list.
  628. Valid values are:
  629. past Don't show entries for today or in the past.
  630. future Don't show entries with a timestamp in the future.
  631. The idea behind this is that if it has a future
  632. timestamp, you don't want to think about it until the
  633. date.
  634. all Don't show any entries with a timestamp in the global todo list.
  635. The idea behind this is that by setting a timestamp, you
  636. have already \"taken care\" of this item.
  637. This variable can also have an integer as a value. If positive (N),
  638. todos with a timestamp N or more days in the future will be ignored. If
  639. negative (-N), todos with a timestamp N or more days in the past will be
  640. ignored. If 0, todos with a timestamp either today or in the future will
  641. be ignored. For example, a value of -1 will exclude todos with a
  642. timestamp in the past (yesterday or earlier), while a value of 7 will
  643. exclude todos with a timestamp a week or more in the future.
  644. See also `org-agenda-todo-ignore-with-date'.
  645. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  646. to make his option also apply to the tags-todo list."
  647. :group 'org-agenda-skip
  648. :group 'org-agenda-todo-list
  649. :version "24.1"
  650. :type '(choice
  651. (const :tag "Ignore future timestamp todos" future)
  652. (const :tag "Ignore past or present timestamp todos" past)
  653. (const :tag "Ignore all timestamp todos" all)
  654. (const :tag "Show timestamp todos" nil)
  655. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  656. (defcustom org-agenda-todo-ignore-scheduled nil
  657. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  658. This applies when creating the global todo list.
  659. Valid values are:
  660. past Don't show entries scheduled today or in the past.
  661. future Don't show entries scheduled in the future.
  662. The idea behind this is that by scheduling it, you don't want to
  663. think about it until the scheduled date.
  664. all Don't show any scheduled entries in the global todo list.
  665. The idea behind this is that by scheduling it, you have already
  666. \"taken care\" of this item.
  667. t Same as `all', for backward compatibility.
  668. This variable can also have an integer as a value. See
  669. `org-agenda-todo-ignore-timestamp' for more details.
  670. See also `org-agenda-todo-ignore-with-date'.
  671. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  672. to make his option also apply to the tags-todo list."
  673. :group 'org-agenda-skip
  674. :group 'org-agenda-todo-list
  675. :type '(choice
  676. (const :tag "Ignore future-scheduled todos" future)
  677. (const :tag "Ignore past- or present-scheduled todos" past)
  678. (const :tag "Ignore all scheduled todos" all)
  679. (const :tag "Ignore all scheduled todos (compatibility)" t)
  680. (const :tag "Show scheduled todos" nil)
  681. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  682. (defcustom org-agenda-todo-ignore-deadlines nil
  683. "Non-nil means ignore some deadline TODO items when making TODO list.
  684. There are different motivations for using different values, please think
  685. carefully when configuring this variable.
  686. This applies when creating the global todo list.
  687. Valid values are:
  688. near Don't show near deadline entries. A deadline is near when it is
  689. closer than `org-deadline-warning-days' days. The idea behind this
  690. is that such items will appear in the agenda anyway.
  691. far Don't show TODO entries where a deadline has been defined, but
  692. the deadline is not near. This is useful if you don't want to
  693. use the todo list to figure out what to do now.
  694. past Don't show entries with a deadline timestamp for today or in the past.
  695. future Don't show entries with a deadline timestamp in the future, not even
  696. when they become `near' ones. Use it with caution.
  697. all Ignore all TODO entries that do have a deadline.
  698. t Same as `near', for backward compatibility.
  699. This variable can also have an integer as a value. See
  700. `org-agenda-todo-ignore-timestamp' for more details.
  701. See also `org-agenda-todo-ignore-with-date'.
  702. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  703. to make his option also apply to the tags-todo list."
  704. :group 'org-agenda-skip
  705. :group 'org-agenda-todo-list
  706. :type '(choice
  707. (const :tag "Ignore near deadlines" near)
  708. (const :tag "Ignore near deadlines (compatibility)" t)
  709. (const :tag "Ignore far deadlines" far)
  710. (const :tag "Ignore all TODOs with a deadlines" all)
  711. (const :tag "Show all TODOs, even if they have a deadline" nil)
  712. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  713. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  714. "Time unit to use when possibly ignoring an agenda item.
  715. See the docstring of various `org-agenda-todo-ignore-*' options.
  716. The default is to compare time stamps using days. An item is thus
  717. considered to be in the future if it is at least one day after today.
  718. Non-nil means to compare time stamps using seconds. An item is then
  719. considered future if it has a time value later than current time."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-todo-list
  722. :version "24.4"
  723. :package-version '(Org . "8.0")
  724. :type '(choice
  725. (const :tag "Compare time with days" nil)
  726. (const :tag "Compare time with seconds" t)))
  727. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  728. "Non-nil means honor todo-list ignores options also in tags-todo search.
  729. The variables
  730. `org-agenda-todo-ignore-with-date',
  731. `org-agenda-todo-ignore-timestamp',
  732. `org-agenda-todo-ignore-scheduled',
  733. `org-agenda-todo-ignore-deadlines'
  734. make the global TODO list skip entries that have time stamps of certain
  735. kinds. If this option is set, the same options will also apply for the
  736. tags-todo search, which is the general tags/property matcher
  737. restricted to unfinished TODO entries only."
  738. :group 'org-agenda-skip
  739. :group 'org-agenda-todo-list
  740. :group 'org-agenda-match-view
  741. :type 'boolean)
  742. (defcustom org-agenda-skip-scheduled-if-done nil
  743. "Non-nil means don't show scheduled items in agenda when they are done.
  744. This is relevant for the daily/weekly agenda, not for the TODO list. And
  745. it applies only to the actual date of the scheduling. Warnings about
  746. an item with a past scheduling dates are always turned off when the item
  747. is DONE."
  748. :group 'org-agenda-skip
  749. :group 'org-agenda-daily/weekly
  750. :type 'boolean)
  751. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  752. "Non-nil means skip scheduling line if same entry shows because of deadline.
  753. In the agenda of today, an entry can show up multiple times
  754. because it is both scheduled and has a nearby deadline, and maybe
  755. a plain time stamp as well.
  756. When this variable is nil, the entry will be shown several times.
  757. When set to t, then only the deadline is shown and the fact that
  758. the entry is scheduled today or was scheduled previously is not
  759. shown.
  760. When set to the symbol `not-today', skip scheduled previously,
  761. but not scheduled today.
  762. When set to the symbol `repeated-after-deadline', skip scheduled
  763. items if they are repeated beyond the current deadline."
  764. :group 'org-agenda-skip
  765. :group 'org-agenda-daily/weekly
  766. :type '(choice
  767. (const :tag "Never" nil)
  768. (const :tag "Always" t)
  769. (const :tag "Not when scheduled today" not-today)
  770. (const :tag "When repeated past deadline" repeated-after-deadline)))
  771. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  772. "Non-nil means skip timestamp line if same entry shows because of deadline.
  773. In the agenda of today, an entry can show up multiple times
  774. because it has both a plain timestamp and has a nearby deadline.
  775. When this variable is t, then only the deadline is shown and the
  776. fact that the entry has a timestamp for or including today is not
  777. shown. When this variable is nil, the entry will be shown
  778. several times."
  779. :group 'org-agenda-skip
  780. :group 'org-agenda-daily/weekly
  781. :version "24.1"
  782. :type '(choice
  783. (const :tag "Never" nil)
  784. (const :tag "Always" t)))
  785. (defcustom org-agenda-skip-deadline-if-done nil
  786. "Non-nil means don't show deadlines when the corresponding item is done.
  787. When nil, the deadline is still shown and should give you a happy feeling.
  788. This is relevant for the daily/weekly agenda. And it applied only to the
  789. actually date of the deadline. Warnings about approaching and past-due
  790. deadlines are always turned off when the item is DONE."
  791. :group 'org-agenda-skip
  792. :group 'org-agenda-daily/weekly
  793. :type 'boolean)
  794. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  795. "Non-nil means skip deadline prewarning when entry is also scheduled.
  796. This will apply on all days where a prewarning for the deadline would
  797. be shown, but not at the day when the entry is actually due. On that day,
  798. the deadline will be shown anyway.
  799. This variable may be set to nil, t, the symbol `pre-scheduled',
  800. or a number which will then give the number of days before the actual
  801. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  802. eliminates the deadline prewarning only prior to the scheduled date.
  803. This can be used in a workflow where the first showing of the deadline will
  804. trigger you to schedule it, and then you don't want to be reminded of it
  805. because you will take care of it on the day when scheduled."
  806. :group 'org-agenda-skip
  807. :group 'org-agenda-daily/weekly
  808. :version "24.1"
  809. :type '(choice
  810. (const :tag "Always show prewarning" nil)
  811. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  812. (const :tag "Remove prewarning if entry is scheduled" t)
  813. (integer :tag "Restart prewarning N days before deadline")))
  814. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  815. "Non-nil means skip scheduled delay when entry also has a deadline.
  816. This variable may be set to nil, t, the symbol `post-deadline',
  817. or a number which will then give the number of days after the actual
  818. scheduled date when the delay should expire. The symbol `post-deadline'
  819. eliminates the schedule delay when the date is posterior to the deadline."
  820. :group 'org-agenda-skip
  821. :group 'org-agenda-daily/weekly
  822. :version "24.4"
  823. :package-version '(Org . "8.0")
  824. :type '(choice
  825. (const :tag "Always honor delay" nil)
  826. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  827. (const :tag "Ignore delay if entry has a deadline" t)
  828. (integer :tag "Honor delay up until N days after the scheduled date")))
  829. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  830. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  831. When non-nil, after the search for timestamps has matched once in an
  832. entry, the rest of the entry will not be searched."
  833. :group 'org-agenda-skip
  834. :type 'boolean)
  835. (defcustom org-agenda-skip-timestamp-if-done nil
  836. "Non-nil means don't select item by timestamp or -range if it is DONE."
  837. :group 'org-agenda-skip
  838. :group 'org-agenda-daily/weekly
  839. :type 'boolean)
  840. (defcustom org-agenda-dim-blocked-tasks t
  841. "Non-nil means dim blocked tasks in the agenda display.
  842. This causes some overhead during agenda construction, but if you
  843. have turned on `org-enforce-todo-dependencies',
  844. `org-enforce-todo-checkbox-dependencies', or any other blocking
  845. mechanism, this will create useful feedback in the agenda.
  846. Instead of t, this variable can also have the value `invisible'.
  847. Then blocked tasks will be invisible and only become visible when
  848. they become unblocked. An exemption to this behavior is when a task is
  849. blocked because of unchecked checkboxes below it. Since checkboxes do
  850. not show up in the agenda views, making this task invisible you remove any
  851. trace from agenda views that there is something to do. Therefore, a task
  852. that is blocked because of checkboxes will never be made invisible, it
  853. will only be dimmed."
  854. :group 'org-agenda-daily/weekly
  855. :group 'org-agenda-todo-list
  856. :version "24.3"
  857. :type '(choice
  858. (const :tag "Do not dim" nil)
  859. (const :tag "Dim to a gray face" t)
  860. (const :tag "Make invisible" invisible)))
  861. (defcustom org-timeline-show-empty-dates 3
  862. "Non-nil means `org-timeline' also shows dates without an entry.
  863. When nil, only the days which actually have entries are shown.
  864. When t, all days between the first and the last date are shown.
  865. When an integer, show also empty dates, but if there is a gap of more than
  866. N days, just insert a special line indicating the size of the gap."
  867. :group 'org-agenda-skip
  868. :type '(choice
  869. (const :tag "None" nil)
  870. (const :tag "All" t)
  871. (integer :tag "at most")))
  872. (defgroup org-agenda-startup nil
  873. "Options concerning initial settings in the Agenda in Org Mode."
  874. :tag "Org Agenda Startup"
  875. :group 'org-agenda)
  876. (defcustom org-agenda-menu-show-matcher t
  877. "Non-nil means show the match string in the agenda dispatcher menu.
  878. When nil, the matcher string is not shown, but is put into the help-echo
  879. property so than moving the mouse over the command shows it.
  880. Setting it to nil is good if matcher strings are very long and/or if
  881. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  882. :group 'org-agenda
  883. :version "24.1"
  884. :type 'boolean)
  885. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  886. (defcustom org-agenda-menu-two-columns nil
  887. "Non-nil means, use two columns to show custom commands in the dispatcher.
  888. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  889. to nil."
  890. :group 'org-agenda
  891. :version "24.1"
  892. :type 'boolean)
  893. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  894. (defcustom org-agenda-finalize-hook nil
  895. "Hook run just before displaying an agenda buffer.
  896. The buffer is still writable when the hook is called.
  897. You can modify some of the buffer substrings but you should be
  898. extra careful not to modify the text properties of the agenda
  899. headlines as the agenda display heavily relies on them."
  900. :group 'org-agenda-startup
  901. :type 'hook)
  902. (defcustom org-agenda-mouse-1-follows-link nil
  903. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  904. A longer mouse click will still set point. Does not work on XEmacs.
  905. Needs to be set before org.el is loaded."
  906. :group 'org-agenda-startup
  907. :type 'boolean)
  908. (defcustom org-agenda-start-with-follow-mode nil
  909. "The initial value of follow mode in a newly created agenda window."
  910. :group 'org-agenda-startup
  911. :type 'boolean)
  912. (defcustom org-agenda-follow-indirect nil
  913. "Non-nil means `org-agenda-follow-mode' displays only the
  914. current item's tree, in an indirect buffer."
  915. :group 'org-agenda
  916. :version "24.1"
  917. :type 'boolean)
  918. (defcustom org-agenda-show-outline-path t
  919. "Non-nil means show outline path in echo area after line motion."
  920. :group 'org-agenda-startup
  921. :type 'boolean)
  922. (defcustom org-agenda-start-with-entry-text-mode nil
  923. "The initial value of entry-text-mode in a newly created agenda window."
  924. :group 'org-agenda-startup
  925. :type 'boolean)
  926. (defcustom org-agenda-entry-text-maxlines 5
  927. "Number of text lines to be added when `E' is pressed in the agenda.
  928. Note that this variable only used during agenda display. Add add entry text
  929. when exporting the agenda, configure the variable
  930. `org-agenda-add-entry-ext-maxlines'."
  931. :group 'org-agenda
  932. :type 'integer)
  933. (defcustom org-agenda-entry-text-exclude-regexps nil
  934. "List of regular expressions to clean up entry text.
  935. The complete matches of all regular expressions in this list will be
  936. removed from entry text before it is shown in the agenda."
  937. :group 'org-agenda
  938. :type '(repeat (regexp)))
  939. (defcustom org-agenda-entry-text-leaders " > "
  940. "Text prepended to the entry text in agenda buffers."
  941. :version "24.4"
  942. :package-version '(Org . "8.0")
  943. :group 'org-agenda
  944. :type 'string)
  945. (defvar org-agenda-entry-text-cleanup-hook nil
  946. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  947. This cleanup is done in a temporary buffer, so the function may inspect and
  948. change the entire buffer.
  949. Some default stuff like drawers and scheduling/deadline dates will already
  950. have been removed when this is called, as will any matches for regular
  951. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  952. (defvar org-agenda-include-inactive-timestamps nil
  953. "Non-nil means include inactive time stamps in agenda and timeline.
  954. Dynamically scoped.")
  955. (defgroup org-agenda-windows nil
  956. "Options concerning the windows used by the Agenda in Org Mode."
  957. :tag "Org Agenda Windows"
  958. :group 'org-agenda)
  959. (defcustom org-agenda-window-setup 'reorganize-frame
  960. "How the agenda buffer should be displayed.
  961. Possible values for this option are:
  962. current-window Show agenda in the current window, keeping all other windows.
  963. other-window Use `switch-to-buffer-other-window' to display agenda.
  964. reorganize-frame Show only two windows on the current frame, the current
  965. window and the agenda.
  966. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  967. Also, when exiting the agenda, kill that frame.
  968. See also the variable `org-agenda-restore-windows-after-quit'."
  969. :group 'org-agenda-windows
  970. :type '(choice
  971. (const current-window)
  972. (const other-frame)
  973. (const other-window)
  974. (const reorganize-frame)))
  975. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  976. "The min and max height of the agenda window as a fraction of frame height.
  977. The value of the variable is a cons cell with two numbers between 0 and 1.
  978. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  979. :group 'org-agenda-windows
  980. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  981. (defcustom org-agenda-restore-windows-after-quit nil
  982. "Non-nil means restore window configuration upon exiting agenda.
  983. Before the window configuration is changed for displaying the agenda,
  984. the current status is recorded. When the agenda is exited with
  985. `q' or `x' and this option is set, the old state is restored. If
  986. `org-agenda-window-setup' is `other-frame', the value of this
  987. option will be ignored."
  988. :group 'org-agenda-windows
  989. :type 'boolean)
  990. (defcustom org-agenda-ndays nil
  991. "Number of days to include in overview display.
  992. Should be 1 or 7.
  993. Obsolete, see `org-agenda-span'."
  994. :group 'org-agenda-daily/weekly
  995. :type '(choice (const nil)
  996. (integer)))
  997. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  998. (defcustom org-agenda-span 'week
  999. "Number of days to include in overview display.
  1000. Can be day, week, month, year, or any number of days.
  1001. Custom commands can set this variable in the options section."
  1002. :group 'org-agenda-daily/weekly
  1003. :type '(choice (const :tag "Day" day)
  1004. (const :tag "Week" week)
  1005. (const :tag "Fortnight" fortnight)
  1006. (const :tag "Month" month)
  1007. (const :tag "Year" year)
  1008. (integer :tag "Custom")))
  1009. (defcustom org-agenda-start-on-weekday 1
  1010. "Non-nil means start the overview always on the specified weekday.
  1011. 0 denotes Sunday, 1 denotes Monday, etc.
  1012. When nil, always start on the current day.
  1013. Custom commands can set this variable in the options section."
  1014. :group 'org-agenda-daily/weekly
  1015. :type '(choice (const :tag "Today" nil)
  1016. (integer :tag "Weekday No.")))
  1017. (defcustom org-agenda-show-all-dates t
  1018. "Non-nil means `org-agenda' shows every day in the selected range.
  1019. When nil, only the days which actually have entries are shown."
  1020. :group 'org-agenda-daily/weekly
  1021. :type 'boolean)
  1022. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1023. "Format string for displaying dates in the agenda.
  1024. Used by the daily/weekly agenda and by the timeline. This should be
  1025. a format string understood by `format-time-string', or a function returning
  1026. the formatted date as a string. The function must take a single argument,
  1027. a calendar-style date list like (month day year)."
  1028. :group 'org-agenda-daily/weekly
  1029. :type '(choice
  1030. (string :tag "Format string")
  1031. (function :tag "Function")))
  1032. (defun org-agenda-format-date-aligned (date)
  1033. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1034. This function makes sure that dates are aligned for easy reading."
  1035. (require 'cal-iso)
  1036. (let* ((dayname (calendar-day-name date))
  1037. (day (cadr date))
  1038. (day-of-week (calendar-day-of-week date))
  1039. (month (car date))
  1040. (monthname (calendar-month-name month))
  1041. (year (nth 2 date))
  1042. (iso-week (org-days-to-iso-week
  1043. (calendar-absolute-from-gregorian date)))
  1044. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1045. (1- year))
  1046. ((and (= month 12) (<= iso-week 1))
  1047. (1+ year))
  1048. (t year)))
  1049. (weekstring (if (= day-of-week 1)
  1050. (format " W%02d" iso-week)
  1051. "")))
  1052. (format "%-10s %2d %s %4d%s"
  1053. dayname day monthname year weekstring)))
  1054. (defcustom org-agenda-time-leading-zero nil
  1055. "Non-nil means use leading zero for military times in agenda.
  1056. For example, 9:30am would become 09:30 rather than 9:30."
  1057. :group 'org-agenda-daily/weekly
  1058. :version "24.1"
  1059. :type 'boolean)
  1060. (defcustom org-agenda-timegrid-use-ampm nil
  1061. "When set, show AM/PM style timestamps on the timegrid."
  1062. :group 'org-agenda
  1063. :version "24.1"
  1064. :type 'boolean)
  1065. (defun org-agenda-time-of-day-to-ampm (time)
  1066. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1067. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1068. (minute (substring time -2))
  1069. (ampm "am"))
  1070. (cond
  1071. ((equal hour-number 12)
  1072. (setq ampm "pm"))
  1073. ((> hour-number 12)
  1074. (setq ampm "pm")
  1075. (setq hour-number (- hour-number 12))))
  1076. (concat
  1077. (if org-agenda-time-leading-zero
  1078. (format "%02d" hour-number)
  1079. (format "%02s" (number-to-string hour-number)))
  1080. ":" minute ampm)))
  1081. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1082. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1083. (if org-agenda-timegrid-use-ampm
  1084. (org-agenda-time-of-day-to-ampm time)
  1085. time))
  1086. (defcustom org-agenda-weekend-days '(6 0)
  1087. "Which days are weekend?
  1088. These days get the special face `org-agenda-date-weekend' in the agenda
  1089. and timeline buffers."
  1090. :group 'org-agenda-daily/weekly
  1091. :type '(set :greedy t
  1092. (const :tag "Monday" 1)
  1093. (const :tag "Tuesday" 2)
  1094. (const :tag "Wednesday" 3)
  1095. (const :tag "Thursday" 4)
  1096. (const :tag "Friday" 5)
  1097. (const :tag "Saturday" 6)
  1098. (const :tag "Sunday" 0)))
  1099. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1100. "Non-nil means jump to today when moving a past date forward in time.
  1101. When using S-right in the agenda to move a a date forward, and the date
  1102. stamp currently points to the past, the first key press will move it
  1103. to today. WHen nil, just move one day forward even if the date stays
  1104. in the past."
  1105. :group 'org-agenda-daily/weekly
  1106. :version "24.1"
  1107. :type 'boolean)
  1108. (defcustom org-agenda-include-diary nil
  1109. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1110. Custom commands can set this variable in the options section."
  1111. :group 'org-agenda-daily/weekly
  1112. :type 'boolean)
  1113. (defcustom org-agenda-include-deadlines t
  1114. "If non-nil, include entries within their deadline warning period.
  1115. Custom commands can set this variable in the options section."
  1116. :group 'org-agenda-daily/weekly
  1117. :version "24.1"
  1118. :type 'boolean)
  1119. (defcustom org-agenda-repeating-timestamp-show-all t
  1120. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1121. When set to a list of strings, only show occurrences of repeating
  1122. stamps for these TODO keywords. When nil, only one occurrence is
  1123. shown, either today or the nearest into the future."
  1124. :group 'org-agenda-daily/weekly
  1125. :type '(choice
  1126. (const :tag "Show repeating stamps" t)
  1127. (repeat :tag "Show repeating stamps for these TODO keywords"
  1128. (string :tag "TODO Keyword"))
  1129. (const :tag "Don't show repeating stamps" nil)))
  1130. (defcustom org-scheduled-past-days 10000
  1131. "Number of days to continue listing scheduled items not marked DONE.
  1132. When an item is scheduled on a date, it shows up in the agenda on this
  1133. day and will be listed until it is marked done for the number of days
  1134. given here."
  1135. :group 'org-agenda-daily/weekly
  1136. :type 'integer)
  1137. (defcustom org-agenda-log-mode-items '(closed clock)
  1138. "List of items that should be shown in agenda log mode.
  1139. This list may contain the following symbols:
  1140. closed Show entries that have been closed on that day.
  1141. clock Show entries that have received clocked time on that day.
  1142. state Show all logged state changes.
  1143. Note that instead of changing this variable, you can also press `C-u l' in
  1144. the agenda to display all available LOG items temporarily."
  1145. :group 'org-agenda-daily/weekly
  1146. :type '(set :greedy t (const closed) (const clock) (const state)))
  1147. (defcustom org-agenda-clock-consistency-checks
  1148. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1149. :gap-ok-around ("4:00")
  1150. :default-face ((:background "DarkRed") (:foreground "white"))
  1151. :overlap-face nil :gap-face nil :no-end-time-face nil
  1152. :long-face nil :short-face nil)
  1153. "This is a property list, with the following keys:
  1154. :max-duration Mark clocking chunks that are longer than this time.
  1155. This is a time string like \"HH:MM\", or the number
  1156. of minutes as an integer.
  1157. :min-duration Mark clocking chunks that are shorter that this.
  1158. This is a time string like \"HH:MM\", or the number
  1159. of minutes as an integer.
  1160. :max-gap Mark gaps between clocking chunks that are longer than
  1161. this duration. A number of minutes, or a string
  1162. like \"HH:MM\".
  1163. :gap-ok-around List of times during the day which are usually not working
  1164. times. When a gap is detected, but the gap contains any
  1165. of these times, the gap is *not* reported. For example,
  1166. if this is (\"4:00\" \"13:00\") then gaps that contain
  1167. 4:00 in the morning (i.e. the night) and 13:00
  1168. (i.e. a typical lunch time) do not cause a warning.
  1169. You should have at least one time during the night in this
  1170. list, or otherwise the first task each morning will trigger
  1171. a warning because it follows a long gap.
  1172. Furthermore, the following properties can be used to define faces for
  1173. issue display.
  1174. :default-face the default face, if the specific face is undefined
  1175. :overlap-face face for overlapping clocks
  1176. :gap-face face for gaps between clocks
  1177. :no-end-time-face face for incomplete clocks
  1178. :long-face face for clock intervals that are too long
  1179. :short-face face for clock intervals that are too short"
  1180. :group 'org-agenda-daily/weekly
  1181. :group 'org-clock
  1182. :version "24.1"
  1183. :type 'plist)
  1184. (defcustom org-agenda-log-mode-add-notes t
  1185. "Non-nil means add first line of notes to log entries in agenda views.
  1186. If a log item like a state change or a clock entry is associated with
  1187. notes, the first line of these notes will be added to the entry in the
  1188. agenda display."
  1189. :group 'org-agenda-daily/weekly
  1190. :type 'boolean)
  1191. (defcustom org-agenda-start-with-log-mode nil
  1192. "The initial value of log-mode in a newly created agenda window.
  1193. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1194. explanations on the possible values."
  1195. :group 'org-agenda-startup
  1196. :group 'org-agenda-daily/weekly
  1197. :type '(choice (const :tag "Don't show log items" nil)
  1198. (const :tag "Show only log items" only)
  1199. (const :tag "Show all possible log items" clockcheck)
  1200. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1201. (choice (const :tag "Show closed log items" closed)
  1202. (const :tag "Show clocked log items" clock)
  1203. (const :tag "Show all logged state changes" state)))))
  1204. (defcustom org-agenda-start-with-clockreport-mode nil
  1205. "The initial value of clockreport-mode in a newly created agenda window."
  1206. :group 'org-agenda-startup
  1207. :group 'org-agenda-daily/weekly
  1208. :type 'boolean)
  1209. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1210. "Property list with parameters for the clocktable in clockreport mode.
  1211. This is the display mode that shows a clock table in the daily/weekly
  1212. agenda, the properties for this dynamic block can be set here.
  1213. The usual clocktable parameters are allowed here, but you cannot set
  1214. the properties :name, :tstart, :tend, :block, and :scope - these will
  1215. be overwritten to make sure the content accurately reflects the
  1216. current display in the agenda."
  1217. :group 'org-agenda-daily/weekly
  1218. :type 'plist)
  1219. (defcustom org-agenda-search-view-always-boolean nil
  1220. "Non-nil means the search string is interpreted as individual parts.
  1221. The search string for search view can either be interpreted as a phrase,
  1222. or as a list of snippets that define a boolean search for a number of
  1223. strings.
  1224. When this is non-nil, the string will be split on whitespace, and each
  1225. snippet will be searched individually, and all must match in order to
  1226. select an entry. A snippet is then a single string of non-white
  1227. characters, or a string in double quotes, or a regexp in {} braces.
  1228. If a snippet is preceded by \"-\", the snippet must *not* match.
  1229. \"+\" is syntactic sugar for positive selection. Each snippet may
  1230. be found as a full word or a partial word, but see the variable
  1231. `org-agenda-search-view-force-full-words'.
  1232. When this is nil, search will look for the entire search phrase as one,
  1233. with each space character matching any amount of whitespace, including
  1234. line breaks.
  1235. Even when this is nil, you can still switch to Boolean search dynamically
  1236. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1237. is a regexp marked with braces like \"{abc}\", this will also switch to
  1238. boolean search."
  1239. :group 'org-agenda-search-view
  1240. :version "24.1"
  1241. :type 'boolean)
  1242. (org-defvaralias 'org-agenda-search-view-search-words-only
  1243. 'org-agenda-search-view-always-boolean)
  1244. (defcustom org-agenda-search-view-force-full-words nil
  1245. "Non-nil means, search words must be matches as complete words.
  1246. When nil, they may also match part of a word."
  1247. :group 'org-agenda-search-view
  1248. :version "24.1"
  1249. :type 'boolean)
  1250. (defcustom org-agenda-search-view-max-outline-level 0
  1251. "Maximum outline level to display in search view.
  1252. E.g. when this is set to 1, the search view will only
  1253. show headlines of level 1. When set to 0, the default
  1254. value, don't limit agenda view by outline level."
  1255. :group 'org-agenda-search-view
  1256. :version "24.4"
  1257. :package-version '(Org . "8.3")
  1258. :type 'integer)
  1259. (defgroup org-agenda-time-grid nil
  1260. "Options concerning the time grid in the Org-mode Agenda."
  1261. :tag "Org Agenda Time Grid"
  1262. :group 'org-agenda)
  1263. (defcustom org-agenda-search-headline-for-time t
  1264. "Non-nil means search headline for a time-of-day.
  1265. If the headline contains a time-of-day in one format or another, it will
  1266. be used to sort the entry into the time sequence of items for a day.
  1267. Some people have time stamps in the headline that refer to the creation
  1268. time or so, and then this produces an unwanted side effect. If this is
  1269. the case for your, use this variable to turn off searching the headline
  1270. for a time."
  1271. :group 'org-agenda-time-grid
  1272. :type 'boolean)
  1273. (defcustom org-agenda-use-time-grid t
  1274. "Non-nil means show a time grid in the agenda schedule.
  1275. A time grid is a set of lines for specific times (like every two hours between
  1276. 8:00 and 20:00). The items scheduled for a day at specific times are
  1277. sorted in between these lines.
  1278. For details about when the grid will be shown, and what it will look like, see
  1279. the variable `org-agenda-time-grid'."
  1280. :group 'org-agenda-time-grid
  1281. :type 'boolean)
  1282. (defcustom org-agenda-time-grid
  1283. '((daily today require-timed)
  1284. "----------------"
  1285. (800 1000 1200 1400 1600 1800 2000))
  1286. "The settings for time grid for agenda display.
  1287. This is a list of three items. The first item is again a list. It contains
  1288. symbols specifying conditions when the grid should be displayed:
  1289. daily if the agenda shows a single day
  1290. weekly if the agenda shows an entire week
  1291. today show grid on current date, independent of daily/weekly display
  1292. require-timed show grid only if at least one item has a time specification
  1293. The second item is a string which will be placed behind the grid time.
  1294. The third item is a list of integers, indicating the times that should have
  1295. a grid line."
  1296. :group 'org-agenda-time-grid
  1297. :type
  1298. '(list
  1299. (set :greedy t :tag "Grid Display Options"
  1300. (const :tag "Show grid in single day agenda display" daily)
  1301. (const :tag "Show grid in weekly agenda display" weekly)
  1302. (const :tag "Always show grid for today" today)
  1303. (const :tag "Show grid only if any timed entries are present"
  1304. require-timed)
  1305. (const :tag "Skip grid times already present in an entry"
  1306. remove-match))
  1307. (string :tag "Grid String")
  1308. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1309. (defcustom org-agenda-show-current-time-in-grid t
  1310. "Non-nil means show the current time in the time grid."
  1311. :group 'org-agenda-time-grid
  1312. :version "24.1"
  1313. :type 'boolean)
  1314. (defcustom org-agenda-current-time-string
  1315. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1316. "The string for the current time marker in the agenda."
  1317. :group 'org-agenda-time-grid
  1318. :version "24.1"
  1319. :type 'string)
  1320. (defgroup org-agenda-sorting nil
  1321. "Options concerning sorting in the Org-mode Agenda."
  1322. :tag "Org Agenda Sorting"
  1323. :group 'org-agenda)
  1324. (defcustom org-agenda-sorting-strategy
  1325. '((agenda habit-down time-up priority-down category-keep)
  1326. (todo priority-down category-keep)
  1327. (tags priority-down category-keep)
  1328. (search category-keep))
  1329. "Sorting structure for the agenda items of a single day.
  1330. This is a list of symbols which will be used in sequence to determine
  1331. if an entry should be listed before another entry. The following
  1332. symbols are recognized:
  1333. time-up Put entries with time-of-day indications first, early first
  1334. time-down Put entries with time-of-day indications first, late first
  1335. timestamp-up Sort by any timestamp, early first
  1336. timestamp-down Sort by any timestamp, late first
  1337. scheduled-up Sort by scheduled timestamp, early first
  1338. scheduled-down Sort by scheduled timestamp, late first
  1339. deadline-up Sort by deadline timestamp, early first
  1340. deadline-down Sort by deadline timestamp, late first
  1341. ts-up Sort by active timestamp, early first
  1342. ts-down Sort by active timestamp, late first
  1343. tsia-up Sort by inactive timestamp, early first
  1344. tsia-down Sort by inactive timestamp, late first
  1345. category-keep Keep the default order of categories, corresponding to the
  1346. sequence in `org-agenda-files'.
  1347. category-up Sort alphabetically by category, A-Z.
  1348. category-down Sort alphabetically by category, Z-A.
  1349. tag-up Sort alphabetically by last tag, A-Z.
  1350. tag-down Sort alphabetically by last tag, Z-A.
  1351. priority-up Sort numerically by priority, high priority last.
  1352. priority-down Sort numerically by priority, high priority first.
  1353. todo-state-up Sort by todo state, tasks that are done last.
  1354. todo-state-down Sort by todo state, tasks that are done first.
  1355. effort-up Sort numerically by estimated effort, high effort last.
  1356. effort-down Sort numerically by estimated effort, high effort first.
  1357. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1358. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1359. habit-up Put entries that are habits first
  1360. habit-down Put entries that are habits last
  1361. alpha-up Sort headlines alphabetically
  1362. alpha-down Sort headlines alphabetically, reversed
  1363. The different possibilities will be tried in sequence, and testing stops
  1364. if one comparison returns a \"not-equal\". For example, the default
  1365. '(time-up category-keep priority-down)
  1366. means: Pull out all entries having a specified time of day and sort them,
  1367. in order to make a time schedule for the current day the first thing in the
  1368. agenda listing for the day. Of the entries without a time indication, keep
  1369. the grouped in categories, don't sort the categories, but keep them in
  1370. the sequence given in `org-agenda-files'. Within each category sort by
  1371. priority.
  1372. Leaving out `category-keep' would mean that items will be sorted across
  1373. categories by priority.
  1374. Instead of a single list, this can also be a set of list for specific
  1375. contents, with a context symbol in the car of the list, any of
  1376. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1377. Custom commands can bind this variable in the options section."
  1378. :group 'org-agenda-sorting
  1379. :type `(choice
  1380. (repeat :tag "General" ,org-sorting-choice)
  1381. (list :tag "Individually"
  1382. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1383. (repeat ,org-sorting-choice))
  1384. (cons (const :tag "Strategy for TODO lists" todo)
  1385. (repeat ,org-sorting-choice))
  1386. (cons (const :tag "Strategy for Tags matches" tags)
  1387. (repeat ,org-sorting-choice))
  1388. (cons (const :tag "Strategy for search matches" search)
  1389. (repeat ,org-sorting-choice)))))
  1390. (defcustom org-agenda-cmp-user-defined nil
  1391. "A function to define the comparison `user-defined'.
  1392. This function must receive two arguments, agenda entry a and b.
  1393. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1394. the user comparison, return nil.
  1395. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1396. part of an agenda sorting strategy."
  1397. :group 'org-agenda-sorting
  1398. :type 'symbol)
  1399. (defcustom org-sort-agenda-notime-is-late t
  1400. "Non-nil means items without time are considered late.
  1401. This is only relevant for sorting. When t, items which have no explicit
  1402. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1403. do have a time. When nil, the default time is before 0:00. You can use this
  1404. option to decide if the schedule for today should come before or after timeless
  1405. agenda entries."
  1406. :group 'org-agenda-sorting
  1407. :type 'boolean)
  1408. (defcustom org-sort-agenda-noeffort-is-high t
  1409. "Non-nil means items without effort estimate are sorted as high effort.
  1410. This also applies when filtering an agenda view with respect to the
  1411. < or > effort operator. Then, tasks with no effort defined will be treated
  1412. as tasks with high effort.
  1413. When nil, such items are sorted as 0 minutes effort."
  1414. :group 'org-agenda-sorting
  1415. :type 'boolean)
  1416. (defgroup org-agenda-line-format nil
  1417. "Options concerning the entry prefix in the Org-mode agenda display."
  1418. :tag "Org Agenda Line Format"
  1419. :group 'org-agenda)
  1420. (defcustom org-agenda-prefix-format
  1421. '((agenda . " %i %-12:c%?-12t% s")
  1422. (timeline . " % s")
  1423. (todo . " %i %-12:c")
  1424. (tags . " %i %-12:c")
  1425. (search . " %i %-12:c"))
  1426. "Format specifications for the prefix of items in the agenda views.
  1427. An alist with five entries, each for the different agenda types. The
  1428. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1429. The values are format strings.
  1430. This format works similar to a printf format, with the following meaning:
  1431. %c the category of the item, \"Diary\" for entries from the diary,
  1432. or as given by the CATEGORY keyword or derived from the file name
  1433. %e the effort required by the item
  1434. %l the level of the item (insert X space(s) if item is of level X)
  1435. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1436. %T the last tag of the item (ignore inherited tags, which come first)
  1437. %t the HH:MM time-of-day specification if one applies to the entry
  1438. %s Scheduling/Deadline information, a short string
  1439. %b show breadcrumbs, i.e., the names of the higher levels
  1440. %(expression) Eval EXPRESSION and replace the control string
  1441. by the result
  1442. All specifiers work basically like the standard `%s' of printf, but may
  1443. contain two additional characters: a question mark just after the `%'
  1444. and a whitespace/punctuation character just before the final letter.
  1445. If the first character after `%' is a question mark, the entire field
  1446. will only be included if the corresponding value applies to the current
  1447. entry. This is useful for fields which should have fixed width when
  1448. present, but zero width when absent. For example, \"%?-12t\" will
  1449. result in a 12 character time field if a time of the day is specified,
  1450. but will completely disappear in entries which do not contain a time.
  1451. If there is punctuation or whitespace character just before the
  1452. final format letter, this character will be appended to the field
  1453. value if the value is not empty. For example, the format
  1454. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1455. the category is empty, no additional colon is inserted.
  1456. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1457. which means:
  1458. - Indent the line with two space characters
  1459. - Give the category a 12 chars wide field, padded with whitespace on
  1460. the right (because of `-'). Append a colon if there is a category
  1461. (because of `:').
  1462. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1463. time, don't put in an empty field, just skip it (because of '?').
  1464. - Finally, put the scheduling information.
  1465. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1466. `org-agenda-remove-tags'.
  1467. Custom commands can set this variable in the options section."
  1468. :type '(choice
  1469. (string :tag "General format")
  1470. (list :greedy t :tag "View dependent"
  1471. (cons (const agenda) (string :tag "Format"))
  1472. (cons (const timeline) (string :tag "Format"))
  1473. (cons (const todo) (string :tag "Format"))
  1474. (cons (const tags) (string :tag "Format"))
  1475. (cons (const search) (string :tag "Format"))))
  1476. :group 'org-agenda-line-format)
  1477. (defvar org-prefix-format-compiled nil
  1478. "The compiled prefix format and associated variables.
  1479. This is a list where first element is a list of variable bindings, and second
  1480. element is the compiled format expression. See the variable
  1481. `org-agenda-prefix-format'.")
  1482. (defcustom org-agenda-todo-keyword-format "%-1s"
  1483. "Format for the TODO keyword in agenda lines.
  1484. Set this to something like \"%-12s\" if you want all TODO keywords
  1485. to occupy a fixed space in the agenda display."
  1486. :group 'org-agenda-line-format
  1487. :type 'string)
  1488. (defcustom org-agenda-diary-sexp-prefix nil
  1489. "A regexp that matches part of a diary sexp entry
  1490. which should be treated as scheduling/deadline information in
  1491. `org-agenda'.
  1492. For example, you can use this to extract the `diary-remind-message' from
  1493. `diary-remind' entries."
  1494. :group 'org-agenda-line-format
  1495. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1496. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1497. "Text preceding timerange entries in the agenda view.
  1498. This is a list with two strings. The first applies when the range
  1499. is entirely on one day. The second applies if the range spans several days.
  1500. The strings may have two \"%d\" format specifiers which will be filled
  1501. with the sequence number of the days, and the total number of days in the
  1502. range, respectively."
  1503. :group 'org-agenda-line-format
  1504. :type '(list
  1505. (string :tag "Deadline today ")
  1506. (choice :tag "Deadline relative"
  1507. (string :tag "Format string")
  1508. (function))))
  1509. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1510. "Text preceding scheduled items in the agenda view.
  1511. This is a list with two strings. The first applies when the item is
  1512. scheduled on the current day. The second applies when it has been scheduled
  1513. previously, it may contain a %d indicating that this is the nth time that
  1514. this item is scheduled, due to automatic rescheduling of unfinished items
  1515. for the following day. So this number is one larger than the number of days
  1516. that passed since this item was scheduled first."
  1517. :group 'org-agenda-line-format
  1518. :version "24.4"
  1519. :package-version '(Org . "8.0")
  1520. :type '(list
  1521. (string :tag "Scheduled today ")
  1522. (string :tag "Scheduled previously")))
  1523. (defcustom org-agenda-inactive-leader "["
  1524. "Text preceding item pulled into the agenda by inactive time stamps.
  1525. These entries are added to the agenda when pressing \"[\"."
  1526. :group 'org-agenda-line-format
  1527. :version "24.1"
  1528. :type 'string)
  1529. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1530. "Text preceding deadline items in the agenda view.
  1531. This is a list with three strings. The first applies when the item has its
  1532. deadline on the current day. The second applies when the deadline is in the
  1533. future, the third one when it is in the past. The strings may contain %d
  1534. to capture the number of days."
  1535. :group 'org-agenda-line-format
  1536. :version "24.4"
  1537. :package-version '(Org . "8.0")
  1538. :type '(list
  1539. (string :tag "Deadline today ")
  1540. (string :tag "Deadline in the future ")
  1541. (string :tag "Deadline in the past ")))
  1542. (defcustom org-agenda-remove-times-when-in-prefix t
  1543. "Non-nil means remove duplicate time specifications in agenda items.
  1544. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1545. time-of-day specification in a headline or diary entry is extracted and
  1546. placed into the prefix. If this option is non-nil, the original specification
  1547. \(a timestamp or -range, or just a plain time(range) specification like
  1548. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1549. cluttered.
  1550. The option can be t or nil. It may also be the symbol `beg', indicating
  1551. that the time should only be removed when it is located at the beginning of
  1552. the headline/diary entry."
  1553. :group 'org-agenda-line-format
  1554. :type '(choice
  1555. (const :tag "Always" t)
  1556. (const :tag "Never" nil)
  1557. (const :tag "When at beginning of entry" beg)))
  1558. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1559. "Non-nil means remove time ranges specifications in agenda
  1560. items that span on several days."
  1561. :group 'org-agenda-line-format
  1562. :version "24.1"
  1563. :type 'boolean)
  1564. (defcustom org-agenda-default-appointment-duration nil
  1565. "Default duration for appointments that only have a starting time.
  1566. When nil, no duration is specified in such cases.
  1567. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1568. :group 'org-agenda-line-format
  1569. :type '(choice
  1570. (integer :tag "Minutes")
  1571. (const :tag "No default duration")))
  1572. (defcustom org-agenda-show-inherited-tags t
  1573. "Non-nil means show inherited tags in each agenda line.
  1574. When this option is set to 'always, it take precedences over
  1575. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1576. in every agenda.
  1577. When this option is set to t (the default), inherited tags are
  1578. shown when they are available, i.e. when the value of
  1579. `org-agenda-use-tag-inheritance' has been taken into account.
  1580. This can be set to a list of agenda types in which the agenda
  1581. must display the inherited tags. Available types are 'todo,
  1582. 'agenda, 'search and 'timeline.
  1583. When set to nil, never show inherited tags in agenda lines."
  1584. :group 'org-agenda-line-format
  1585. :group 'org-agenda
  1586. :version "24.3"
  1587. :type '(choice
  1588. (const :tag "Show inherited tags when available" t)
  1589. (const :tag "Always show inherited tags" always)
  1590. (repeat :tag "Show inherited tags only in selected agenda types"
  1591. (symbol :tag "Agenda type"))))
  1592. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1593. "List of agenda view types where to use tag inheritance.
  1594. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1595. controlled by `org-use-tag-inheritance'. In other agenda types,
  1596. `org-use-tag-inheritance' is not used for the selection of the
  1597. agenda entries. Still, you may want the agenda to be aware of
  1598. the inherited tags anyway, e.g. for later tag filtering.
  1599. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1600. This variable has no effect if `org-agenda-show-inherited-tags'
  1601. is set to 'always. In that case, the agenda is aware of those
  1602. tags.
  1603. The default value sets tags in every agenda type. Setting this
  1604. option to nil will speed up non-tags agenda view a lot."
  1605. :group 'org-agenda
  1606. :version "24.3"
  1607. :type '(choice
  1608. (const :tag "Use tag inheritance in all agenda types" t)
  1609. (repeat :tag "Use tag inheritance in selected agenda types"
  1610. (symbol :tag "Agenda type"))))
  1611. (defcustom org-agenda-hide-tags-regexp nil
  1612. "Regular expression used to filter away specific tags in agenda views.
  1613. This means that these tags will be present, but not be shown in the agenda
  1614. line. Secondary filtering will still work on the hidden tags.
  1615. Nil means don't hide any tags."
  1616. :group 'org-agenda-line-format
  1617. :type '(choice
  1618. (const :tag "Hide none" nil)
  1619. (string :tag "Regexp ")))
  1620. (defcustom org-agenda-remove-tags nil
  1621. "Non-nil means remove the tags from the headline copy in the agenda.
  1622. When this is the symbol `prefix', only remove tags when
  1623. `org-agenda-prefix-format' contains a `%T' specifier."
  1624. :group 'org-agenda-line-format
  1625. :type '(choice
  1626. (const :tag "Always" t)
  1627. (const :tag "Never" nil)
  1628. (const :tag "When prefix format contains %T" prefix)))
  1629. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1630. 'org-agenda-remove-tags)
  1631. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1632. "Shift tags in agenda items to this column.
  1633. If this number is positive, it specifies the column. If it is negative,
  1634. it means that the tags should be flushright to that column. For example,
  1635. -80 works well for a normal 80 character screen."
  1636. :group 'org-agenda-line-format
  1637. :type 'integer)
  1638. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1639. (defcustom org-agenda-fontify-priorities 'cookies
  1640. "Non-nil means highlight low and high priorities in agenda.
  1641. When t, the highest priority entries are bold, lowest priority italic.
  1642. However, settings in `org-priority-faces' will overrule these faces.
  1643. When this variable is the symbol `cookies', only fontify the
  1644. cookies, not the entire task.
  1645. This may also be an association list of priority faces, whose
  1646. keys are the character values of `org-highest-priority',
  1647. `org-default-priority', and `org-lowest-priority' (the default values
  1648. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1649. color as a string, or a list like `(:background \"Red\")'.
  1650. If it is a color, the variable `org-faces-easy-properties'
  1651. determines if it is a foreground or a background color."
  1652. :group 'org-agenda-line-format
  1653. :type '(choice
  1654. (const :tag "Never" nil)
  1655. (const :tag "Defaults" t)
  1656. (const :tag "Cookies only" cookies)
  1657. (repeat :tag "Specify"
  1658. (list (character :tag "Priority" :value ?A)
  1659. (choice :tag "Face "
  1660. (string :tag "Color")
  1661. (sexp :tag "Face"))))))
  1662. (defcustom org-agenda-day-face-function nil
  1663. "Function called to determine what face should be used to display a day.
  1664. The only argument passed to that function is the day. It should
  1665. returns a face, or nil if does not want to specify a face and let
  1666. the normal rules apply."
  1667. :group 'org-agenda-line-format
  1668. :version "24.1"
  1669. :type '(choice (const nil) (function)))
  1670. (defcustom org-agenda-category-icon-alist nil
  1671. "Alist of category icon to be displayed in agenda views.
  1672. Each entry should have the following format:
  1673. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1674. Where CATEGORY-REGEXP is a regexp matching the categories where
  1675. the icon should be displayed.
  1676. FILE-OR-DATA either a file path or a string containing image data.
  1677. The other fields can be omitted safely if not needed:
  1678. TYPE indicates the image type.
  1679. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1680. image data.
  1681. PROPS are additional image attributes to assign to the image,
  1682. like, e.g. `:ascent center'.
  1683. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1684. If you want to set the display properties yourself, just put a
  1685. list as second element:
  1686. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1687. For example, to display a 16px horizontal space for Emacs
  1688. category, you can use:
  1689. (\"Emacs\" '(space . (:width (16))))"
  1690. :group 'org-agenda-line-format
  1691. :version "24.1"
  1692. :type '(alist :key-type (string :tag "Regexp matching category")
  1693. :value-type (choice (list :tag "Icon"
  1694. (string :tag "File or data")
  1695. (symbol :tag "Type")
  1696. (boolean :tag "Data?")
  1697. (repeat :tag "Extra image properties" :inline t symbol))
  1698. (list :tag "Display properties" sexp))))
  1699. (defgroup org-agenda-column-view nil
  1700. "Options concerning column view in the agenda."
  1701. :tag "Org Agenda Column View"
  1702. :group 'org-agenda)
  1703. (defcustom org-agenda-columns-show-summaries t
  1704. "Non-nil means show summaries for columns displayed in the agenda view."
  1705. :group 'org-agenda-column-view
  1706. :type 'boolean)
  1707. (defcustom org-agenda-columns-compute-summary-properties t
  1708. "Non-nil means recompute all summary properties before column view.
  1709. When column view in the agenda is listing properties that have a summary
  1710. operator, it can go to all relevant buffers and recompute the summaries
  1711. there. This can mean overhead for the agenda column view, but is necessary
  1712. to have thing up to date.
  1713. As a special case, a CLOCKSUM property also makes sure that the clock
  1714. computations are current."
  1715. :group 'org-agenda-column-view
  1716. :type 'boolean)
  1717. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1718. "Non-nil means the duration of an appointment will add to day effort.
  1719. The property to which appointment durations will be added is the one given
  1720. in the option `org-effort-property'. If an appointment does not have
  1721. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1722. is not set, an appointment without end time will not contribute to the time
  1723. estimate."
  1724. :group 'org-agenda-column-view
  1725. :type 'boolean)
  1726. (defcustom org-agenda-auto-exclude-function nil
  1727. "A function called with a tag to decide if it is filtered on '/ RET'.
  1728. The sole argument to the function, which is called once for each
  1729. possible tag, is a string giving the name of the tag. The
  1730. function should return either nil if the tag should be included
  1731. as normal, or \"-<TAG>\" to exclude the tag.
  1732. Note that for the purpose of tag filtering, only the lower-case version of
  1733. all tags will be considered, so that this function will only ever see
  1734. the lower-case version of all tags."
  1735. :group 'org-agenda
  1736. :type '(choice (const nil) (function)))
  1737. (defcustom org-agenda-bulk-custom-functions nil
  1738. "Alist of characters and custom functions for bulk actions.
  1739. For example, this value makes those two functions available:
  1740. '((?R set-category)
  1741. (?C bulk-cut))
  1742. With selected entries in an agenda buffer, `B R' will call
  1743. the custom function `set-category' on the selected entries.
  1744. Note that functions in this alist don't need to be quoted."
  1745. :type 'alist
  1746. :version "24.1"
  1747. :group 'org-agenda)
  1748. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1749. "Execute BODY with point at location given by `org-hd-marker' property.
  1750. If STRING is non-nil, the text property will be fetched from position 0
  1751. in that string. If STRING is nil, it will be fetched from the beginning
  1752. of the current line."
  1753. (org-with-gensyms (marker)
  1754. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1755. 'org-hd-marker ,string)))
  1756. (with-current-buffer (marker-buffer ,marker)
  1757. (save-excursion
  1758. (goto-char ,marker)
  1759. ,@body)))))
  1760. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1761. (defun org-add-agenda-custom-command (entry)
  1762. "Replace or add a command in `org-agenda-custom-commands'.
  1763. This is mostly for hacking and trying a new command - once the command
  1764. works you probably want to add it to `org-agenda-custom-commands' for good."
  1765. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1766. (if ass
  1767. (setcdr ass (cdr entry))
  1768. (push entry org-agenda-custom-commands))))
  1769. ;;; Define the org-agenda-mode
  1770. (defvar org-agenda-mode-map (make-sparse-keymap)
  1771. "Keymap for `org-agenda-mode'.")
  1772. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1773. (defvar org-agenda-menu) ; defined later in this file.
  1774. (defvar org-agenda-restrict nil) ; defined later in this file.
  1775. (defvar org-agenda-follow-mode nil)
  1776. (defvar org-agenda-entry-text-mode nil)
  1777. (defvar org-agenda-clockreport-mode nil)
  1778. (defvar org-agenda-show-log nil)
  1779. (defvar org-agenda-redo-command nil)
  1780. (defvar org-agenda-query-string nil)
  1781. (defvar org-agenda-mode-hook nil
  1782. "Hook run after `org-agenda-mode' is turned on.
  1783. The buffer is still writable when this hook is called.")
  1784. (defvar org-agenda-type nil)
  1785. (defvar org-agenda-force-single-file nil)
  1786. (defvar org-agenda-bulk-marked-entries nil
  1787. "List of markers that refer to marked entries in the agenda.")
  1788. ;;; Multiple agenda buffers support
  1789. (defcustom org-agenda-sticky nil
  1790. "Non-nil means agenda q key will bury agenda buffers.
  1791. Agenda commands will then show existing buffer instead of generating new ones.
  1792. When nil, `q' will kill the single agenda buffer."
  1793. :group 'org-agenda
  1794. :version "24.3"
  1795. :type 'boolean)
  1796. ;;;###autoload
  1797. (defun org-toggle-sticky-agenda (&optional arg)
  1798. "Toggle `org-agenda-sticky'."
  1799. (interactive "P")
  1800. (let ((new-value (if arg
  1801. (> (prefix-numeric-value arg) 0)
  1802. (not org-agenda-sticky))))
  1803. (if (equal new-value org-agenda-sticky)
  1804. (and (org-called-interactively-p 'interactive)
  1805. (message "Sticky agenda was already %s"
  1806. (if org-agenda-sticky "enabled" "disabled")))
  1807. (setq org-agenda-sticky new-value)
  1808. (org-agenda-kill-all-agenda-buffers)
  1809. (and (org-called-interactively-p 'interactive)
  1810. (message "Sticky agenda was %s"
  1811. (if org-agenda-sticky "enabled" "disabled"))))))
  1812. (defvar org-agenda-buffer nil
  1813. "Agenda buffer currently being generated.")
  1814. (defvar org-agenda-last-prefix-arg nil)
  1815. (defvar org-agenda-this-buffer-name nil)
  1816. (defvar org-agenda-doing-sticky-redo nil)
  1817. (defvar org-agenda-this-buffer-is-sticky nil)
  1818. (defconst org-agenda-local-vars
  1819. '(org-agenda-this-buffer-name
  1820. org-agenda-undo-list
  1821. org-agenda-pending-undo-list
  1822. org-agenda-follow-mode
  1823. org-agenda-entry-text-mode
  1824. org-agenda-clockreport-mode
  1825. org-agenda-show-log
  1826. org-agenda-redo-command
  1827. org-agenda-query-string
  1828. org-agenda-type
  1829. org-agenda-bulk-marked-entries
  1830. org-agenda-undo-has-started-in
  1831. org-agenda-info
  1832. org-agenda-pre-window-conf
  1833. org-agenda-columns-active
  1834. org-agenda-tag-filter
  1835. org-agenda-category-filter
  1836. org-agenda-top-headline-filter
  1837. org-agenda-regexp-filter
  1838. org-agenda-markers
  1839. org-agenda-last-search-view-search-was-boolean
  1840. org-agenda-filtered-by-category
  1841. org-agenda-filter-form
  1842. org-agenda-cycle-counter
  1843. org-agenda-last-prefix-arg)
  1844. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1845. (defun org-agenda-mode ()
  1846. "Mode for time-sorted view on action items in Org-mode files.
  1847. The following commands are available:
  1848. \\{org-agenda-mode-map}"
  1849. (interactive)
  1850. (cond (org-agenda-doing-sticky-redo
  1851. ;; Refreshing sticky agenda-buffer
  1852. ;;
  1853. ;; Preserve the value of `org-agenda-local-vars' variables,
  1854. ;; while letting `kill-all-local-variables' kill the rest
  1855. (let ((save (buffer-local-variables)))
  1856. (kill-all-local-variables)
  1857. (mapc 'make-local-variable org-agenda-local-vars)
  1858. (dolist (elem save)
  1859. (let ((var (car elem))
  1860. (val (cdr elem)))
  1861. (when (and val
  1862. (member var org-agenda-local-vars))
  1863. (set var val)))))
  1864. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1865. (org-agenda-sticky
  1866. ;; Creating a sticky Agenda buffer for the first time
  1867. (kill-all-local-variables)
  1868. (mapc 'make-local-variable org-agenda-local-vars)
  1869. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1870. (t
  1871. ;; Creating a non-sticky agenda buffer
  1872. (kill-all-local-variables)
  1873. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1874. (setq org-agenda-undo-list nil
  1875. org-agenda-pending-undo-list nil
  1876. org-agenda-bulk-marked-entries nil)
  1877. (setq major-mode 'org-agenda-mode)
  1878. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1879. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1880. (setq mode-name "Org-Agenda")
  1881. (setq indent-tabs-mode nil)
  1882. (use-local-map org-agenda-mode-map)
  1883. (easy-menu-add org-agenda-menu)
  1884. (if org-startup-truncated (setq truncate-lines t))
  1885. (org-set-local 'line-move-visual nil)
  1886. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1887. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1888. ;; Make sure properties are removed when copying text
  1889. (org-add-hook 'filter-buffer-substring-functions
  1890. (lambda (fun start end delete)
  1891. (substring-no-properties (funcall fun start end delete)))
  1892. nil t)
  1893. (unless org-agenda-keep-modes
  1894. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1895. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1896. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1897. org-agenda-show-log org-agenda-start-with-log-mode))
  1898. (add-to-invisibility-spec '(org-filtered))
  1899. (add-to-invisibility-spec '(org-link))
  1900. (easy-menu-change
  1901. '("Agenda") "Agenda Files"
  1902. (append
  1903. (list
  1904. (vector
  1905. (if (get 'org-agenda-files 'org-restrict)
  1906. "Restricted to single file"
  1907. "Edit File List")
  1908. '(org-edit-agenda-file-list)
  1909. (not (get 'org-agenda-files 'org-restrict)))
  1910. "--")
  1911. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1912. (org-agenda-set-mode-name)
  1913. (apply
  1914. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1915. (list 'org-agenda-mode-hook)))
  1916. (substitute-key-definition 'undo 'org-agenda-undo
  1917. org-agenda-mode-map global-map)
  1918. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1919. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1920. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1921. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1922. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1923. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1924. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1925. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1926. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1927. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1928. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1929. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1930. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1931. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1932. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1933. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1934. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1935. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1936. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1940. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1941. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1942. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1943. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1944. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1945. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1946. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1947. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1948. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1949. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1950. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1951. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1952. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1953. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1954. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1955. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1956. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1957. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1958. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1959. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1960. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1961. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1962. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1963. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1964. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1965. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1966. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1967. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1968. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1969. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1970. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1971. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1972. (while l (org-defkey org-agenda-mode-map
  1973. (int-to-string (pop l)) 'digit-argument)))
  1974. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1975. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1976. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1977. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1978. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1979. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1980. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1981. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1982. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1983. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1984. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1985. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1986. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1987. 'org-clock-modify-effort-estimate)
  1988. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1989. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1990. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1991. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1992. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1993. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1994. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1995. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1996. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1997. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1998. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1999. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2000. (substitute-key-definition 'next-line 'org-agenda-next-line
  2001. org-agenda-mode-map global-map)
  2002. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2003. org-agenda-mode-map global-map)
  2004. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2005. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2006. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2007. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2008. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2009. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2010. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2011. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2012. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2013. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2014. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2015. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2016. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2017. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2018. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2019. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2021. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2022. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2023. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2024. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2025. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2026. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2027. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2028. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2029. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2030. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2031. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2033. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2034. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2035. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2036. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2037. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2038. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2039. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2040. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2041. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2042. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2043. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2044. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2045. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2046. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2048. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2049. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2050. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2051. (when org-agenda-mouse-1-follows-link
  2052. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2053. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2054. '("Agenda"
  2055. ("Agenda Files")
  2056. "--"
  2057. ("Agenda Dates"
  2058. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2059. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2060. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2061. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2062. "--"
  2063. ("View"
  2064. ["Day View" org-agenda-day-view
  2065. :active (org-agenda-check-type nil 'agenda)
  2066. :style radio :selected (eq org-agenda-current-span 'day)
  2067. :keys "v d (or just d)"]
  2068. ["Week View" org-agenda-week-view
  2069. :active (org-agenda-check-type nil 'agenda)
  2070. :style radio :selected (eq org-agenda-current-span 'week)
  2071. :keys "v w"]
  2072. ["Fortnight View" org-agenda-fortnight-view
  2073. :active (org-agenda-check-type nil 'agenda)
  2074. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2075. :keys "v f"]
  2076. ["Month View" org-agenda-month-view
  2077. :active (org-agenda-check-type nil 'agenda)
  2078. :style radio :selected (eq org-agenda-current-span 'month)
  2079. :keys "v m"]
  2080. ["Year View" org-agenda-year-view
  2081. :active (org-agenda-check-type nil 'agenda)
  2082. :style radio :selected (eq org-agenda-current-span 'year)
  2083. :keys "v y"]
  2084. "--"
  2085. ["Include Diary" org-agenda-toggle-diary
  2086. :style toggle :selected org-agenda-include-diary
  2087. :active (org-agenda-check-type nil 'agenda)]
  2088. ["Include Deadlines" org-agenda-toggle-deadlines
  2089. :style toggle :selected org-agenda-include-deadlines
  2090. :active (org-agenda-check-type nil 'agenda)]
  2091. ["Use Time Grid" org-agenda-toggle-time-grid
  2092. :style toggle :selected org-agenda-use-time-grid
  2093. :active (org-agenda-check-type nil 'agenda)]
  2094. "--"
  2095. ["Show clock report" org-agenda-clockreport-mode
  2096. :style toggle :selected org-agenda-clockreport-mode
  2097. :active (org-agenda-check-type nil 'agenda)]
  2098. ["Show some entry text" org-agenda-entry-text-mode
  2099. :style toggle :selected org-agenda-entry-text-mode
  2100. :active t]
  2101. "--"
  2102. ["Show Logbook entries" org-agenda-log-mode
  2103. :style toggle :selected org-agenda-show-log
  2104. :active (org-agenda-check-type nil 'agenda 'timeline)
  2105. :keys "v l (or just l)"]
  2106. ["Include archived trees" org-agenda-archives-mode
  2107. :style toggle :selected org-agenda-archives-mode :active t
  2108. :keys "v a"]
  2109. ["Include archive files" (org-agenda-archives-mode t)
  2110. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2111. :keys "v A"]
  2112. "--"
  2113. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2114. ["Write view to file" org-agenda-write t]
  2115. ["Rebuild buffer" org-agenda-redo t]
  2116. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2117. "--"
  2118. ["Show original entry" org-agenda-show t]
  2119. ["Go To (other window)" org-agenda-goto t]
  2120. ["Go To (this window)" org-agenda-switch-to t]
  2121. ["Capture with cursor date" org-agenda-capture t]
  2122. ["Follow Mode" org-agenda-follow-mode
  2123. :style toggle :selected org-agenda-follow-mode :active t]
  2124. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2125. "--"
  2126. ("TODO"
  2127. ["Cycle TODO" org-agenda-todo t]
  2128. ["Next TODO set" org-agenda-todo-nextset t]
  2129. ["Previous TODO set" org-agenda-todo-previousset t]
  2130. ["Add note" org-agenda-add-note t])
  2131. ("Archive/Refile/Delete"
  2132. ["Archive default" org-agenda-archive-default t]
  2133. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2134. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2135. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2136. ["Archive subtree" org-agenda-archive t]
  2137. "--"
  2138. ["Refile" org-agenda-refile t]
  2139. "--"
  2140. ["Delete subtree" org-agenda-kill t])
  2141. ("Bulk action"
  2142. ["Mark entry" org-agenda-bulk-mark t]
  2143. ["Mark all" org-agenda-bulk-mark-all t]
  2144. ["Unmark entry" org-agenda-bulk-unmark t]
  2145. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2146. ["Toggle mark" org-agenda-bulk-toggle t]
  2147. ["Toggle all" org-agenda-bulk-toggle-all t]
  2148. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2149. ["Act on all marked" org-agenda-bulk-action t]
  2150. "--"
  2151. ("Tags and Properties"
  2152. ["Show all Tags" org-agenda-show-tags t]
  2153. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2154. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2155. "--"
  2156. ["Column View" org-columns t])
  2157. ("Deadline/Schedule"
  2158. ["Schedule" org-agenda-schedule t]
  2159. ["Set Deadline" org-agenda-deadline t]
  2160. "--"
  2161. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2162. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2163. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2164. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2165. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2166. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2167. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2168. ("Clock and Effort"
  2169. ["Clock in" org-agenda-clock-in t]
  2170. ["Clock out" org-agenda-clock-out t]
  2171. ["Clock cancel" org-agenda-clock-cancel t]
  2172. ["Goto running clock" org-clock-goto t]
  2173. "--"
  2174. ["Set Effort" org-agenda-set-effort t]
  2175. ["Change clocked effort" org-clock-modify-effort-estimate
  2176. (org-clock-is-active)])
  2177. ("Priority"
  2178. ["Set Priority" org-agenda-priority t]
  2179. ["Increase Priority" org-agenda-priority-up t]
  2180. ["Decrease Priority" org-agenda-priority-down t]
  2181. ["Show Priority" org-show-priority t])
  2182. ("Calendar/Diary"
  2183. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2184. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2185. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2186. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2188. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2189. "--"
  2190. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2191. "--"
  2192. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2193. "--"
  2194. ("MobileOrg"
  2195. ["Push Files and Views" org-mobile-push t]
  2196. ["Get Captured and Flagged" org-mobile-pull t]
  2197. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2198. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2199. "--"
  2200. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2201. "--"
  2202. ["Quit" org-agenda-quit t]
  2203. ["Exit and Release Buffers" org-agenda-exit t]
  2204. ))
  2205. ;;; Agenda undo
  2206. (defvar org-agenda-allow-remote-undo t
  2207. "Non-nil means allow remote undo from the agenda buffer.")
  2208. (defvar org-agenda-undo-has-started-in nil
  2209. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2210. (defun org-agenda-undo ()
  2211. "Undo a remote editing step in the agenda.
  2212. This undoes changes both in the agenda buffer and in the remote buffer
  2213. that have been changed along."
  2214. (interactive)
  2215. (or org-agenda-allow-remote-undo
  2216. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2217. (if (not (eq this-command last-command))
  2218. (setq org-agenda-undo-has-started-in nil
  2219. org-agenda-pending-undo-list org-agenda-undo-list))
  2220. (if (not org-agenda-pending-undo-list)
  2221. (user-error "No further undo information"))
  2222. (let* ((entry (pop org-agenda-pending-undo-list))
  2223. buf line cmd rembuf)
  2224. (setq cmd (pop entry) line (pop entry))
  2225. (setq rembuf (nth 2 entry))
  2226. (org-with-remote-undo rembuf
  2227. (while (bufferp (setq buf (pop entry)))
  2228. (if (pop entry)
  2229. (with-current-buffer buf
  2230. (let ((last-undo-buffer buf)
  2231. (inhibit-read-only t))
  2232. (unless (memq buf org-agenda-undo-has-started-in)
  2233. (push buf org-agenda-undo-has-started-in)
  2234. (make-local-variable 'pending-undo-list)
  2235. (undo-start))
  2236. (while (and pending-undo-list
  2237. (listp pending-undo-list)
  2238. (not (car pending-undo-list)))
  2239. (pop pending-undo-list))
  2240. (undo-more 1))))))
  2241. (org-goto-line line)
  2242. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2243. (defun org-verify-change-for-undo (l1 l2)
  2244. "Verify that a real change occurred between the undo lists L1 and L2."
  2245. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2246. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2247. (not (eq l1 l2)))
  2248. ;;; Agenda dispatch
  2249. (defvar org-agenda-restrict-begin (make-marker))
  2250. (defvar org-agenda-restrict-end (make-marker))
  2251. (defvar org-agenda-last-dispatch-buffer nil)
  2252. (defvar org-agenda-overriding-restriction nil)
  2253. (defcustom org-agenda-custom-commands-contexts nil
  2254. "Alist of custom agenda keys and contextual rules.
  2255. For example, if you have a custom agenda command \"p\" and you
  2256. want this command to be accessible only from plain text files,
  2257. use this:
  2258. '((\"p\" ((in-file . \"\\.txt\"))))
  2259. Here are the available contexts definitions:
  2260. in-file: command displayed only in matching files
  2261. in-mode: command displayed only in matching modes
  2262. not-in-file: command not displayed in matching files
  2263. not-in-mode: command not displayed in matching modes
  2264. in-buffer: command displayed only in matching buffers
  2265. not-in-buffer: command not displayed in matching buffers
  2266. [function]: a custom function taking no argument
  2267. If you define several checks, the agenda command will be
  2268. accessible if there is at least one valid check.
  2269. You can also bind a key to another agenda custom command
  2270. depending on contextual rules.
  2271. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2272. Here it means: in .txt files, use \"p\" as the key for the
  2273. agenda command otherwise associated with \"q\". (The command
  2274. originally associated with \"q\" is not displayed to avoid
  2275. duplicates.)"
  2276. :version "24.3"
  2277. :group 'org-agenda-custom-commands
  2278. :type '(repeat (list :tag "Rule"
  2279. (string :tag " Agenda key")
  2280. (string :tag "Replace by command")
  2281. (repeat :tag "Available when"
  2282. (choice
  2283. (cons :tag "Condition"
  2284. (choice
  2285. (const :tag "In file" in-file)
  2286. (const :tag "Not in file" not-in-file)
  2287. (const :tag "In buffer" in-buffer)
  2288. (const :tag "Not in buffer" not-in-buffer)
  2289. (const :tag "In mode" in-mode)
  2290. (const :tag "Not in mode" not-in-mode))
  2291. (regexp))
  2292. (function :tag "Custom function"))))))
  2293. (defcustom org-agenda-max-entries nil
  2294. "Maximum number of entries to display in an agenda.
  2295. This can be nil (no limit) or an integer or an alist of agenda
  2296. types with an associated number of entries to display in this
  2297. type."
  2298. :version "24.4"
  2299. :package-version '(Org . "8.0")
  2300. :group 'org-agenda-custom-commands
  2301. :type '(choice (symbol :tag "No limit" nil)
  2302. (integer :tag "Max number of entries")
  2303. (repeat
  2304. (cons (choice :tag "Agenda type"
  2305. (const agenda)
  2306. (const todo)
  2307. (const tags)
  2308. (const search)
  2309. (const timeline))
  2310. (integer :tag "Max number of entries")))))
  2311. (defcustom org-agenda-max-todos nil
  2312. "Maximum number of TODOs to display in an agenda.
  2313. This can be nil (no limit) or an integer or an alist of agenda
  2314. types with an associated number of entries to display in this
  2315. type."
  2316. :version "24.4"
  2317. :package-version '(Org . "8.0")
  2318. :group 'org-agenda-custom-commands
  2319. :type '(choice (symbol :tag "No limit" nil)
  2320. (integer :tag "Max number of TODOs")
  2321. (repeat
  2322. (cons (choice :tag "Agenda type"
  2323. (const agenda)
  2324. (const todo)
  2325. (const tags)
  2326. (const search)
  2327. (const timeline))
  2328. (integer :tag "Max number of TODOs")))))
  2329. (defcustom org-agenda-max-tags nil
  2330. "Maximum number of tagged entries to display in an agenda.
  2331. This can be nil (no limit) or an integer or an alist of agenda
  2332. types with an associated number of entries to display in this
  2333. type."
  2334. :version "24.4"
  2335. :package-version '(Org . "8.0")
  2336. :group 'org-agenda-custom-commands
  2337. :type '(choice (symbol :tag "No limit" nil)
  2338. (integer :tag "Max number of tagged entries")
  2339. (repeat
  2340. (cons (choice :tag "Agenda type"
  2341. (const agenda)
  2342. (const todo)
  2343. (const tags)
  2344. (const search)
  2345. (const timeline))
  2346. (integer :tag "Max number of tagged entries")))))
  2347. (defcustom org-agenda-max-effort nil
  2348. "Maximum cumulated effort duration for the agenda.
  2349. This can be nil (no limit) or a number of minutes (as an integer)
  2350. or an alist of agenda types with an associated number of minutes
  2351. to limit entries to in this type."
  2352. :version "24.4"
  2353. :package-version '(Org . "8.0")
  2354. :group 'org-agenda-custom-commands
  2355. :type '(choice (symbol :tag "No limit" nil)
  2356. (integer :tag "Max number of minutes")
  2357. (repeat
  2358. (cons (choice :tag "Agenda type"
  2359. (const agenda)
  2360. (const todo)
  2361. (const tags)
  2362. (const search)
  2363. (const timeline))
  2364. (integer :tag "Max number of minutes")))))
  2365. (defvar org-keys nil)
  2366. (defvar org-match nil)
  2367. ;;;###autoload
  2368. (defun org-agenda (&optional arg org-keys restriction)
  2369. "Dispatch agenda commands to collect entries to the agenda buffer.
  2370. Prompts for a command to execute. Any prefix arg will be passed
  2371. on to the selected command. The default selections are:
  2372. a Call `org-agenda-list' to display the agenda for current day or week.
  2373. t Call `org-todo-list' to display the global todo list.
  2374. T Call `org-todo-list' to display the global todo list, select only
  2375. entries with a specific TODO keyword (the user gets a prompt).
  2376. m Call `org-tags-view' to display headlines with tags matching
  2377. a condition (the user is prompted for the condition).
  2378. M Like `m', but select only TODO entries, no ordinary headlines.
  2379. L Create a timeline for the current buffer.
  2380. e Export views to associated files.
  2381. s Search entries for keywords.
  2382. S Search entries for keywords, only with TODO keywords.
  2383. / Multi occur across all agenda files and also files listed
  2384. in `org-agenda-text-search-extra-files'.
  2385. < Restrict agenda commands to buffer, subtree, or region.
  2386. Press several times to get the desired effect.
  2387. > Remove a previous restriction.
  2388. # List \"stuck\" projects.
  2389. ! Configure what \"stuck\" means.
  2390. C Configure custom agenda commands.
  2391. More commands can be added by configuring the variable
  2392. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2393. searches can be pre-defined in this way.
  2394. If the current buffer is in Org-mode and visiting a file, you can also
  2395. first press `<' once to indicate that the agenda should be temporarily
  2396. \(until the next use of \\[org-agenda]) restricted to the current file.
  2397. Pressing `<' twice means to restrict to the current subtree or region
  2398. \(if active)."
  2399. (interactive "P")
  2400. (catch 'exit
  2401. (let* ((prefix-descriptions nil)
  2402. (org-agenda-buffer-name org-agenda-buffer-name)
  2403. (org-agenda-window-setup (if (equal (buffer-name)
  2404. org-agenda-buffer-name)
  2405. 'current-window
  2406. org-agenda-window-setup))
  2407. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2408. (org-agenda-custom-commands
  2409. ;; normalize different versions
  2410. (delq nil
  2411. (mapcar
  2412. (lambda (x)
  2413. (cond ((stringp (cdr x))
  2414. (push x prefix-descriptions)
  2415. nil)
  2416. ((stringp (nth 1 x)) x)
  2417. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2418. (t (cons (car x) (cons "" (cdr x))))))
  2419. org-agenda-custom-commands)))
  2420. (org-agenda-custom-commands
  2421. (org-contextualize-keys
  2422. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2423. (buf (current-buffer))
  2424. (bfn (buffer-file-name (buffer-base-buffer)))
  2425. entry key type org-match lprops ans)
  2426. ;; Turn off restriction unless there is an overriding one,
  2427. (unless org-agenda-overriding-restriction
  2428. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2429. ;; There is a request to keep the file list in place
  2430. (put 'org-agenda-files 'org-restrict nil))
  2431. (setq org-agenda-restrict nil)
  2432. (move-marker org-agenda-restrict-begin nil)
  2433. (move-marker org-agenda-restrict-end nil))
  2434. ;; Delete old local properties
  2435. (put 'org-agenda-redo-command 'org-lprops nil)
  2436. ;; Delete previously set last-arguments
  2437. (put 'org-agenda-redo-command 'last-args nil)
  2438. ;; Remember where this call originated
  2439. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2440. (unless org-keys
  2441. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2442. org-keys (car ans)
  2443. restriction (cdr ans)))
  2444. ;; If we have sticky agenda buffers, set a name for the buffer,
  2445. ;; depending on the invoking keys. The user may still set this
  2446. ;; as a command option, which will overwrite what we do here.
  2447. (if org-agenda-sticky
  2448. (setq org-agenda-buffer-name
  2449. (format "*Org Agenda(%s)*" org-keys)))
  2450. ;; Establish the restriction, if any
  2451. (when (and (not org-agenda-overriding-restriction) restriction)
  2452. (put 'org-agenda-files 'org-restrict (list bfn))
  2453. (cond
  2454. ((eq restriction 'region)
  2455. (setq org-agenda-restrict (current-buffer))
  2456. (move-marker org-agenda-restrict-begin (region-beginning))
  2457. (move-marker org-agenda-restrict-end (region-end)))
  2458. ((eq restriction 'subtree)
  2459. (save-excursion
  2460. (setq org-agenda-restrict (current-buffer))
  2461. (org-back-to-heading t)
  2462. (move-marker org-agenda-restrict-begin (point))
  2463. (move-marker org-agenda-restrict-end
  2464. (progn (org-end-of-subtree t)))))))
  2465. ;; For example the todo list should not need it (but does...)
  2466. (cond
  2467. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2468. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2469. (progn
  2470. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2471. lprops (nth 4 entry))
  2472. (if org-agenda-sticky
  2473. (setq org-agenda-buffer-name
  2474. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2475. (format "*Org Agenda(%s)*" org-keys))))
  2476. (put 'org-agenda-redo-command 'org-lprops lprops)
  2477. (cond
  2478. ((eq type 'agenda)
  2479. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2480. ((eq type 'agenda*)
  2481. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2482. ((eq type 'alltodo)
  2483. (org-let lprops '(org-todo-list current-prefix-arg)))
  2484. ((eq type 'search)
  2485. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2486. ((eq type 'stuck)
  2487. (org-let lprops '(org-agenda-list-stuck-projects
  2488. current-prefix-arg)))
  2489. ((eq type 'tags)
  2490. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2491. ((eq type 'tags-todo)
  2492. (org-let lprops '(org-tags-view '(4) org-match)))
  2493. ((eq type 'todo)
  2494. (org-let lprops '(org-todo-list org-match)))
  2495. ((eq type 'tags-tree)
  2496. (org-check-for-org-mode)
  2497. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2498. ((eq type 'todo-tree)
  2499. (org-check-for-org-mode)
  2500. (org-let lprops
  2501. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2502. (regexp-quote org-match) "\\>"))))
  2503. ((eq type 'occur-tree)
  2504. (org-check-for-org-mode)
  2505. (org-let lprops '(org-occur org-match)))
  2506. ((functionp type)
  2507. (org-let lprops '(funcall type org-match)))
  2508. ((fboundp type)
  2509. (org-let lprops '(funcall type org-match)))
  2510. (t (user-error "Invalid custom agenda command type %s" type))))
  2511. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2512. ((equal org-keys "C")
  2513. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2514. (customize-variable 'org-agenda-custom-commands))
  2515. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2516. ((equal org-keys "s") (call-interactively 'org-search-view))
  2517. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2518. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2519. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2520. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2521. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2522. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2523. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2524. (org-add-hook
  2525. 'post-command-hook
  2526. (lambda ()
  2527. (unless (current-message)
  2528. (let* ((m (org-agenda-get-any-marker))
  2529. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2530. (when note
  2531. (message (concat
  2532. "FLAGGING-NOTE ([?] for more info): "
  2533. (org-add-props
  2534. (replace-regexp-in-string
  2535. "\\\\n" "//"
  2536. (copy-sequence note))
  2537. nil 'face 'org-warning)))))))
  2538. t t))
  2539. ((equal org-keys "L")
  2540. (unless (derived-mode-p 'org-mode)
  2541. (user-error "This is not an Org-mode file"))
  2542. (unless restriction
  2543. (put 'org-agenda-files 'org-restrict (list bfn))
  2544. (org-call-with-arg 'org-timeline arg)))
  2545. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2546. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2547. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2548. (t (user-error "Invalid agenda key"))))))
  2549. (defvar org-agenda-multi)
  2550. (defun org-agenda-append-agenda ()
  2551. "Append another agenda view to the current one.
  2552. This function allows interactive building of block agendas.
  2553. Agenda views are separated by `org-agenda-block-separator'."
  2554. (interactive)
  2555. (unless (derived-mode-p 'org-agenda-mode)
  2556. (user-error "Can only append from within agenda buffer"))
  2557. (let ((org-agenda-multi t))
  2558. (org-agenda)
  2559. (widen)
  2560. (org-agenda-finalize)
  2561. (setq buffer-read-only t)
  2562. (org-agenda-fit-window-to-buffer)))
  2563. (defun org-agenda-normalize-custom-commands (cmds)
  2564. "Normalize custom commands CMDS."
  2565. (delq nil
  2566. (mapcar
  2567. (lambda (x)
  2568. (cond ((stringp (cdr x)) nil)
  2569. ((stringp (nth 1 x)) x)
  2570. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2571. (t (cons (car x) (cons "" (cdr x))))))
  2572. cmds)))
  2573. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2574. "The user interface for selecting an agenda command."
  2575. (catch 'exit
  2576. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2577. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2578. (region-p (org-region-active-p))
  2579. (custom org-agenda-custom-commands)
  2580. (selstring "")
  2581. restriction second-time
  2582. c entry key type match prefixes rmheader header-end custom1 desc
  2583. line lines left right n n1)
  2584. (save-window-excursion
  2585. (delete-other-windows)
  2586. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2587. (erase-buffer)
  2588. (insert (eval-when-compile
  2589. (let ((header
  2590. "Press key for an agenda command: < Buffer, subtree/region restriction
  2591. -------------------------------- > Remove restriction
  2592. a Agenda for current week or day e Export agenda views
  2593. t List of all TODO entries T Entries with special TODO kwd
  2594. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2595. s Search for keywords S Like s, but only TODO entries
  2596. L Timeline for current buffer # List stuck projects (!=configure)
  2597. / Multi-occur C Configure custom agenda commands
  2598. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2599. ")
  2600. (start 0))
  2601. (while (string-match
  2602. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2603. header start)
  2604. (setq start (match-end 0))
  2605. (add-text-properties (match-beginning 2) (match-end 2)
  2606. '(face bold) header))
  2607. header)))
  2608. (setq header-end (point-marker))
  2609. (while t
  2610. (setq custom1 custom)
  2611. (when (eq rmheader t)
  2612. (org-goto-line 1)
  2613. (re-search-forward ":" nil t)
  2614. (delete-region (match-end 0) (point-at-eol))
  2615. (forward-char 1)
  2616. (looking-at "-+")
  2617. (delete-region (match-end 0) (point-at-eol))
  2618. (move-marker header-end (match-end 0)))
  2619. (goto-char header-end)
  2620. (delete-region (point) (point-max))
  2621. ;; Produce all the lines that describe custom commands and prefixes
  2622. (setq lines nil)
  2623. (while (setq entry (pop custom1))
  2624. (setq key (car entry) desc (nth 1 entry)
  2625. type (nth 2 entry)
  2626. match (nth 3 entry))
  2627. (if (> (length key) 1)
  2628. (add-to-list 'prefixes (string-to-char key))
  2629. (setq line
  2630. (format
  2631. "%-4s%-14s"
  2632. (org-add-props (copy-sequence key)
  2633. '(face bold))
  2634. (cond
  2635. ((string-match "\\S-" desc) desc)
  2636. ((eq type 'agenda) "Agenda for current week or day")
  2637. ((eq type 'agenda*) "Appointments for current week or day")
  2638. ((eq type 'alltodo) "List of all TODO entries")
  2639. ((eq type 'search) "Word search")
  2640. ((eq type 'stuck) "List of stuck projects")
  2641. ((eq type 'todo) "TODO keyword")
  2642. ((eq type 'tags) "Tags query")
  2643. ((eq type 'tags-todo) "Tags (TODO)")
  2644. ((eq type 'tags-tree) "Tags tree")
  2645. ((eq type 'todo-tree) "TODO kwd tree")
  2646. ((eq type 'occur-tree) "Occur tree")
  2647. ((functionp type) (if (symbolp type)
  2648. (symbol-name type)
  2649. "Lambda expression"))
  2650. (t "???"))))
  2651. (if org-agenda-menu-show-matcher
  2652. (setq line
  2653. (concat line ": "
  2654. (cond
  2655. ((stringp match)
  2656. (setq match (copy-sequence match))
  2657. (org-add-props match nil 'face 'org-warning))
  2658. ((listp type)
  2659. (format "set of %d commands" (length type))))))
  2660. (if (org-string-nw-p match)
  2661. (add-text-properties
  2662. 0 (length line) (list 'help-echo
  2663. (concat "Matcher: " match)) line)))
  2664. (push line lines)))
  2665. (setq lines (nreverse lines))
  2666. (when prefixes
  2667. (mapc (lambda (x)
  2668. (push
  2669. (format "%s %s"
  2670. (org-add-props (char-to-string x)
  2671. nil 'face 'bold)
  2672. (or (cdr (assoc (concat selstring
  2673. (char-to-string x))
  2674. prefix-descriptions))
  2675. "Prefix key"))
  2676. lines))
  2677. prefixes))
  2678. ;; Check if we should display in two columns
  2679. (if org-agenda-menu-two-columns
  2680. (progn
  2681. (setq n (length lines)
  2682. n1 (+ (/ n 2) (mod n 2))
  2683. right (nthcdr n1 lines)
  2684. left (copy-sequence lines))
  2685. (setcdr (nthcdr (1- n1) left) nil))
  2686. (setq left lines right nil))
  2687. (while left
  2688. (insert "\n" (pop left))
  2689. (when right
  2690. (if (< (current-column) 40)
  2691. (move-to-column 40 t)
  2692. (insert " "))
  2693. (insert (pop right))))
  2694. ;; Make the window the right size
  2695. (goto-char (point-min))
  2696. (if second-time
  2697. (if (not (pos-visible-in-window-p (point-max)))
  2698. (org-fit-window-to-buffer))
  2699. (setq second-time t)
  2700. (org-fit-window-to-buffer))
  2701. ;; Ask for selection
  2702. (message "Press key for agenda command%s:"
  2703. (if (or restrict-ok org-agenda-overriding-restriction)
  2704. (if org-agenda-overriding-restriction
  2705. " (restriction lock active)"
  2706. (if restriction
  2707. (format " (restricted to %s)" restriction)
  2708. " (unrestricted)"))
  2709. ""))
  2710. (setq c (read-char-exclusive))
  2711. (message "")
  2712. (cond
  2713. ((assoc (char-to-string c) custom)
  2714. (setq selstring (concat selstring (char-to-string c)))
  2715. (throw 'exit (cons selstring restriction)))
  2716. ((memq c prefixes)
  2717. (setq selstring (concat selstring (char-to-string c))
  2718. prefixes nil
  2719. rmheader (or rmheader t)
  2720. custom (delq nil (mapcar
  2721. (lambda (x)
  2722. (if (or (= (length (car x)) 1)
  2723. (/= (string-to-char (car x)) c))
  2724. nil
  2725. (cons (substring (car x) 1) (cdr x))))
  2726. custom))))
  2727. ((eq c ?*)
  2728. (call-interactively 'org-toggle-sticky-agenda)
  2729. (sit-for 2))
  2730. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2731. (message "Restriction is only possible in Org-mode buffers")
  2732. (ding) (sit-for 1))
  2733. ((eq c ?1)
  2734. (org-agenda-remove-restriction-lock 'noupdate)
  2735. (setq restriction 'buffer))
  2736. ((eq c ?0)
  2737. (org-agenda-remove-restriction-lock 'noupdate)
  2738. (setq restriction (if region-p 'region 'subtree)))
  2739. ((eq c ?<)
  2740. (org-agenda-remove-restriction-lock 'noupdate)
  2741. (setq restriction
  2742. (cond
  2743. ((eq restriction 'buffer)
  2744. (if region-p 'region 'subtree))
  2745. ((memq restriction '(subtree region))
  2746. nil)
  2747. (t 'buffer))))
  2748. ((eq c ?>)
  2749. (org-agenda-remove-restriction-lock 'noupdate)
  2750. (setq restriction nil))
  2751. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2752. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2753. ((and (> (length selstring) 0) (eq c ?\d))
  2754. (delete-window)
  2755. (org-agenda-get-restriction-and-command prefix-descriptions))
  2756. ((equal c ?q) (error "Abort"))
  2757. (t (user-error "Invalid key %c" c))))))))
  2758. (defun org-agenda-fit-window-to-buffer ()
  2759. "Fit the window to the buffer size."
  2760. (and (memq org-agenda-window-setup '(reorganize-frame))
  2761. (fboundp 'fit-window-to-buffer)
  2762. (org-fit-window-to-buffer
  2763. nil
  2764. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2765. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2766. (defvar org-cmd nil)
  2767. (defvar org-agenda-overriding-cmd nil)
  2768. (defvar org-agenda-overriding-arguments nil)
  2769. (defvar org-agenda-overriding-cmd-arguments nil)
  2770. (defun org-agenda-run-series (name series)
  2771. "Run agenda NAME as a SERIES of agenda commands."
  2772. (org-let (nth 1 series) '(org-agenda-prepare name))
  2773. ;; We need to reset agenda markers here, because when constructing a
  2774. ;; block agenda, the individual blocks do not do that.
  2775. (org-agenda-reset-markers)
  2776. (let* ((org-agenda-multi t)
  2777. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2778. (cmds (car series))
  2779. (gprops (nth 1 series))
  2780. match ;; The byte compiler incorrectly complains about this. Keep it!
  2781. org-cmd type lprops)
  2782. (while (setq org-cmd (pop cmds))
  2783. (setq type (car org-cmd)
  2784. match (eval (nth 1 org-cmd))
  2785. lprops (nth 2 org-cmd))
  2786. (let ((org-agenda-overriding-arguments
  2787. (if (eq org-agenda-overriding-cmd org-cmd)
  2788. (or org-agenda-overriding-arguments
  2789. org-agenda-overriding-cmd-arguments))))
  2790. (cond
  2791. ((eq type 'agenda)
  2792. (org-let2 gprops lprops
  2793. '(call-interactively 'org-agenda-list)))
  2794. ((eq type 'agenda*)
  2795. (org-let2 gprops lprops
  2796. '(funcall 'org-agenda-list nil nil t)))
  2797. ((eq type 'alltodo)
  2798. (org-let2 gprops lprops
  2799. '(call-interactively 'org-todo-list)))
  2800. ((eq type 'search)
  2801. (org-let2 gprops lprops
  2802. '(org-search-view current-prefix-arg match nil)))
  2803. ((eq type 'stuck)
  2804. (org-let2 gprops lprops
  2805. '(call-interactively 'org-agenda-list-stuck-projects)))
  2806. ((eq type 'tags)
  2807. (org-let2 gprops lprops
  2808. '(org-tags-view current-prefix-arg match)))
  2809. ((eq type 'tags-todo)
  2810. (org-let2 gprops lprops
  2811. '(org-tags-view '(4) match)))
  2812. ((eq type 'todo)
  2813. (org-let2 gprops lprops
  2814. '(org-todo-list match)))
  2815. ((fboundp type)
  2816. (org-let2 gprops lprops
  2817. '(funcall type match)))
  2818. (t (error "Invalid type in command series")))))
  2819. (widen)
  2820. (let ((inhibit-read-only t))
  2821. (add-text-properties (point-min) (point-max)
  2822. `(org-series t org-series-redo-cmd ,redo)))
  2823. (setq org-agenda-redo-command redo)
  2824. (goto-char (point-min)))
  2825. (org-agenda-fit-window-to-buffer)
  2826. (org-let (nth 1 series) '(org-agenda-finalize)))
  2827. ;;;###autoload
  2828. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2829. "Run an agenda command in batch mode and send the result to STDOUT.
  2830. If CMD-KEY is a string of length 1, it is used as a key in
  2831. `org-agenda-custom-commands' and triggers this command. If it is a
  2832. longer string it is used as a tags/todo match string.
  2833. Parameters are alternating variable names and values that will be bound
  2834. before running the agenda command."
  2835. (org-eval-in-environment (org-make-parameter-alist parameters)
  2836. (let (org-agenda-sticky)
  2837. (if (> (length cmd-key) 2)
  2838. (org-tags-view nil cmd-key)
  2839. (org-agenda nil cmd-key))))
  2840. (set-buffer org-agenda-buffer-name)
  2841. (princ (buffer-string)))
  2842. (defvar org-agenda-info nil)
  2843. ;;;###autoload
  2844. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2845. "Run an agenda command in batch mode and send the result to STDOUT.
  2846. If CMD-KEY is a string of length 1, it is used as a key in
  2847. `org-agenda-custom-commands' and triggers this command. If it is a
  2848. longer string it is used as a tags/todo match string.
  2849. Parameters are alternating variable names and values that will be bound
  2850. before running the agenda command.
  2851. The output gives a line for each selected agenda item. Each
  2852. item is a list of comma-separated values, like this:
  2853. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2854. category The category of the item
  2855. head The headline, without TODO kwd, TAGS and PRIORITY
  2856. type The type of the agenda entry, can be
  2857. todo selected in TODO match
  2858. tagsmatch selected in tags match
  2859. diary imported from diary
  2860. deadline a deadline on given date
  2861. scheduled scheduled on given date
  2862. timestamp entry has timestamp on given date
  2863. closed entry was closed on given date
  2864. upcoming-deadline warning about deadline
  2865. past-scheduled forwarded scheduled item
  2866. block entry has date block including g. date
  2867. todo The todo keyword, if any
  2868. tags All tags including inherited ones, separated by colons
  2869. date The relevant date, like 2007-2-14
  2870. time The time, like 15:00-16:50
  2871. extra Sting with extra planning info
  2872. priority-l The priority letter if any was given
  2873. priority-n The computed numerical priority
  2874. agenda-day The day in the agenda where this is listed"
  2875. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2876. (org-make-parameter-alist parameters))
  2877. (if (> (length cmd-key) 2)
  2878. (org-tags-view nil cmd-key)
  2879. (org-agenda nil cmd-key)))
  2880. (set-buffer org-agenda-buffer-name)
  2881. (let* ((lines (org-split-string (buffer-string) "\n"))
  2882. line)
  2883. (while (setq line (pop lines))
  2884. (catch 'next
  2885. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2886. (setq org-agenda-info
  2887. (org-fix-agenda-info (text-properties-at 0 line)))
  2888. (princ
  2889. (mapconcat 'org-agenda-export-csv-mapper
  2890. '(org-category txt type todo tags date time extra
  2891. priority-letter priority agenda-day)
  2892. ","))
  2893. (princ "\n")))))
  2894. (defun org-fix-agenda-info (props)
  2895. "Make sure all properties on an agenda item have a canonical form.
  2896. This ensures the export commands can easily use it."
  2897. (let (tmp re)
  2898. (when (setq tmp (plist-get props 'tags))
  2899. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2900. (when (setq tmp (plist-get props 'date))
  2901. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2902. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2903. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2904. (setq tmp (calendar-date-string tmp)))
  2905. (setq props (plist-put props 'date tmp)))
  2906. (when (setq tmp (plist-get props 'day))
  2907. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2908. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2909. (setq tmp (calendar-date-string tmp)))
  2910. (setq props (plist-put props 'day tmp))
  2911. (setq props (plist-put props 'agenda-day tmp)))
  2912. (when (setq tmp (plist-get props 'txt))
  2913. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2914. (plist-put props 'priority-letter (match-string 1 tmp))
  2915. (setq tmp (replace-match "" t t tmp)))
  2916. (when (and (setq re (plist-get props 'org-todo-regexp))
  2917. (setq re (concat "\\`\\.*" re " ?"))
  2918. (string-match re tmp))
  2919. (plist-put props 'todo (match-string 1 tmp))
  2920. (setq tmp (replace-match "" t t tmp)))
  2921. (plist-put props 'txt tmp)))
  2922. props)
  2923. (defun org-agenda-export-csv-mapper (prop)
  2924. (let ((res (plist-get org-agenda-info prop)))
  2925. (setq res
  2926. (cond
  2927. ((not res) "")
  2928. ((stringp res) res)
  2929. (t (prin1-to-string res))))
  2930. (while (string-match "," res)
  2931. (setq res (replace-match ";" t t res)))
  2932. (org-trim res)))
  2933. ;;;###autoload
  2934. (defun org-store-agenda-views (&rest parameters)
  2935. "Store agenda views."
  2936. (interactive)
  2937. (eval (list 'org-batch-store-agenda-views)))
  2938. ;;;###autoload
  2939. (defmacro org-batch-store-agenda-views (&rest parameters)
  2940. "Run all custom agenda commands that have a file argument."
  2941. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2942. (pop-up-frames nil)
  2943. (dir default-directory)
  2944. (pars (org-make-parameter-alist parameters))
  2945. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2946. (save-window-excursion
  2947. (while cmds
  2948. (setq cmd (pop cmds)
  2949. thiscmdkey (car cmd)
  2950. thiscmdcmd (cdr cmd)
  2951. match (nth 2 thiscmdcmd)
  2952. bufname (if org-agenda-sticky
  2953. (or (and (stringp match)
  2954. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2955. (format "*Org Agenda(%s)*" thiscmdkey))
  2956. org-agenda-buffer-name)
  2957. cmd-or-set (nth 2 cmd)
  2958. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2959. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2960. (if (stringp files) (setq files (list files)))
  2961. (when files
  2962. (org-eval-in-environment (append org-agenda-exporter-settings
  2963. opts pars)
  2964. (org-agenda nil thiscmdkey))
  2965. (set-buffer bufname)
  2966. (while files
  2967. (org-eval-in-environment (append org-agenda-exporter-settings
  2968. opts pars)
  2969. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2970. (and (get-buffer bufname)
  2971. (kill-buffer bufname)))))))
  2972. (defvar org-agenda-current-span nil
  2973. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2974. (defun org-agenda-mark-header-line (pos)
  2975. "Mark the line at POS as an agenda structure header."
  2976. (save-excursion
  2977. (goto-char pos)
  2978. (put-text-property (point-at-bol) (point-at-eol)
  2979. 'org-agenda-structural-header t)
  2980. (when org-agenda-title-append
  2981. (put-text-property (point-at-bol) (point-at-eol)
  2982. 'org-agenda-title-append org-agenda-title-append))))
  2983. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2984. (defvar org-agenda-write-buffer-name "Agenda View")
  2985. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2986. "Write the current buffer (an agenda view) as a file.
  2987. Depending on the extension of the file name, plain text (.txt),
  2988. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2989. If the extension is .ics, run icalendar export over all files used
  2990. to construct the agenda and limit the export to entries listed in the
  2991. agenda now.
  2992. If the extension is .org, collect all subtrees corresponding to the
  2993. agenda entries and add them in an .org file.
  2994. With prefix argument OPEN, open the new file immediately.
  2995. If NOSETTINGS is given, do not scope the settings of
  2996. `org-agenda-exporter-settings' into the export commands. This is used when
  2997. the settings have already been scoped and we do not wish to overrule other,
  2998. higher priority settings.
  2999. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3000. (interactive "FWrite agenda to file: \nP")
  3001. (if (or (not (file-writable-p file))
  3002. (and (file-exists-p file)
  3003. (if (org-called-interactively-p 'any)
  3004. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3005. (user-error "Cannot write agenda to file %s" file))
  3006. (org-let (if nosettings nil org-agenda-exporter-settings)
  3007. '(save-excursion
  3008. (save-window-excursion
  3009. (let ((bs (copy-sequence (buffer-string))) beg content)
  3010. (with-temp-buffer
  3011. (rename-buffer org-agenda-write-buffer-name t)
  3012. (set-buffer-modified-p nil)
  3013. (insert bs)
  3014. (org-agenda-remove-marked-text 'org-filtered)
  3015. (run-hooks 'org-agenda-before-write-hook)
  3016. (cond
  3017. ((org-bound-and-true-p org-mobile-creating-agendas)
  3018. (org-mobile-write-agenda-for-mobile file))
  3019. ((string-match "\\.org\\'" file)
  3020. (let (content p m message-log-max)
  3021. (goto-char (point-min))
  3022. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3023. (goto-char p)
  3024. (setq m (get-text-property (point) 'org-hd-marker))
  3025. (when m
  3026. (push (save-excursion
  3027. (set-buffer (marker-buffer m))
  3028. (goto-char m)
  3029. (org-copy-subtree 1 nil t t)
  3030. org-subtree-clip)
  3031. content)))
  3032. (find-file file)
  3033. (erase-buffer)
  3034. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3035. (write-file file)
  3036. (kill-buffer (current-buffer))
  3037. (message "Org file written to %s" file)))
  3038. ((string-match "\\.html?\\'" file)
  3039. (require 'htmlize)
  3040. (set-buffer (htmlize-buffer (current-buffer)))
  3041. (when org-agenda-export-html-style
  3042. ;; replace <style> section with org-agenda-export-html-style
  3043. (goto-char (point-min))
  3044. (kill-region (- (search-forward "<style") 6)
  3045. (search-forward "</style>"))
  3046. (insert org-agenda-export-html-style))
  3047. (write-file file)
  3048. (kill-buffer (current-buffer))
  3049. (message "HTML written to %s" file))
  3050. ((string-match "\\.ps\\'" file)
  3051. (require 'ps-print)
  3052. (ps-print-buffer-with-faces file)
  3053. (message "Postscript written to %s" file))
  3054. ((string-match "\\.pdf\\'" file)
  3055. (require 'ps-print)
  3056. (ps-print-buffer-with-faces
  3057. (concat (file-name-sans-extension file) ".ps"))
  3058. (call-process "ps2pdf" nil nil nil
  3059. (expand-file-name
  3060. (concat (file-name-sans-extension file) ".ps"))
  3061. (expand-file-name file))
  3062. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3063. (message "PDF written to %s" file))
  3064. ((string-match "\\.ics\\'" file)
  3065. (require 'ox-icalendar)
  3066. (org-icalendar-export-current-agenda (expand-file-name file)))
  3067. (t
  3068. (let ((bs (buffer-string)))
  3069. (find-file file)
  3070. (erase-buffer)
  3071. (insert bs)
  3072. (save-buffer 0)
  3073. (kill-buffer (current-buffer))
  3074. (message "Plain text written to %s" file))))))))
  3075. (set-buffer (or agenda-bufname
  3076. (and (org-called-interactively-p 'any) (buffer-name))
  3077. org-agenda-buffer-name)))
  3078. (when open (org-open-file file)))
  3079. (defun org-agenda-remove-marked-text (property &optional value)
  3080. "Delete all text marked with VALUE of PROPERTY.
  3081. VALUE defaults to t."
  3082. (let (beg)
  3083. (setq value (or value t))
  3084. (while (setq beg (text-property-any (point-min) (point-max)
  3085. property value))
  3086. (delete-region
  3087. beg (or (next-single-property-change beg property)
  3088. (point-max))))))
  3089. (defun org-agenda-add-entry-text ()
  3090. "Add entry text to agenda lines.
  3091. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3092. entry text following headings shown in the agenda.
  3093. Drawers will be excluded, also the line with scheduling/deadline info."
  3094. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3095. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3096. (let (m txt)
  3097. (goto-char (point-min))
  3098. (while (not (eobp))
  3099. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3100. (beginning-of-line 2)
  3101. (setq txt (org-agenda-get-some-entry-text
  3102. m org-agenda-add-entry-text-maxlines " > "))
  3103. (end-of-line 1)
  3104. (if (string-match "\\S-" txt)
  3105. (insert "\n" txt)
  3106. (or (eobp) (forward-char 1))))))))
  3107. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3108. &rest keep)
  3109. "Extract entry text from MARKER, at most N-LINES lines.
  3110. This will ignore drawers etc, just get the text.
  3111. If INDENT is given, prefix every line with this string. If KEEP is
  3112. given, it is a list of symbols, defining stuff that should not be
  3113. removed from the entry content. Currently only `planning' is allowed here."
  3114. (let (txt drawer-re kwd-time-re ind)
  3115. (save-excursion
  3116. (with-current-buffer (marker-buffer marker)
  3117. (if (not (derived-mode-p 'org-mode))
  3118. (setq txt "")
  3119. (save-excursion
  3120. (save-restriction
  3121. (widen)
  3122. (goto-char marker)
  3123. (end-of-line 1)
  3124. (setq txt (buffer-substring
  3125. (min (1+ (point)) (point-max))
  3126. (progn (outline-next-heading) (point)))
  3127. drawer-re org-drawer-regexp
  3128. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3129. ".*\n?"))
  3130. (with-temp-buffer
  3131. (insert txt)
  3132. (when org-agenda-add-entry-text-descriptive-links
  3133. (goto-char (point-min))
  3134. (while (org-activate-bracket-links (point-max))
  3135. (add-text-properties (match-beginning 0) (match-end 0)
  3136. '(face org-link))))
  3137. (goto-char (point-min))
  3138. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3139. (set-text-properties (match-beginning 0) (match-end 0)
  3140. nil))
  3141. (goto-char (point-min))
  3142. (while (re-search-forward drawer-re nil t)
  3143. (delete-region
  3144. (match-beginning 0)
  3145. (progn (re-search-forward
  3146. "^[ \t]*:END:.*\n?" nil 'move)
  3147. (point))))
  3148. (unless (member 'planning keep)
  3149. (goto-char (point-min))
  3150. (while (re-search-forward kwd-time-re nil t)
  3151. (replace-match "")))
  3152. (goto-char (point-min))
  3153. (when org-agenda-entry-text-exclude-regexps
  3154. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3155. (while (setq re (pop re-list))
  3156. (goto-char (point-min))
  3157. (while (re-search-forward re nil t)
  3158. (replace-match "")))))
  3159. (goto-char (point-max))
  3160. (skip-chars-backward " \t\n")
  3161. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3162. ;; find and remove min common indentation
  3163. (goto-char (point-min))
  3164. (untabify (point-min) (point-max))
  3165. (setq ind (org-get-indentation))
  3166. (while (not (eobp))
  3167. (unless (looking-at "[ \t]*$")
  3168. (setq ind (min ind (org-get-indentation))))
  3169. (beginning-of-line 2))
  3170. (goto-char (point-min))
  3171. (while (not (eobp))
  3172. (unless (looking-at "[ \t]*$")
  3173. (move-to-column ind)
  3174. (delete-region (point-at-bol) (point)))
  3175. (beginning-of-line 2))
  3176. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3177. (goto-char (point-min))
  3178. (when indent
  3179. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3180. (replace-match indent t t)))
  3181. (goto-char (point-min))
  3182. (while (looking-at "[ \t]*\n") (replace-match ""))
  3183. (goto-char (point-max))
  3184. (when (> (org-current-line)
  3185. n-lines)
  3186. (org-goto-line (1+ n-lines))
  3187. (backward-char 1))
  3188. (setq txt (buffer-substring (point-min) (point)))))))))
  3189. txt))
  3190. (defun org-check-for-org-mode ()
  3191. "Make sure current buffer is in org-mode. Error if not."
  3192. (or (derived-mode-p 'org-mode)
  3193. (error "Cannot execute org-mode agenda command on buffer in %s"
  3194. major-mode)))
  3195. ;;; Agenda prepare and finalize
  3196. (defvar org-agenda-multi nil) ; dynamically scoped
  3197. (defvar org-agenda-pre-window-conf nil)
  3198. (defvar org-agenda-columns-active nil)
  3199. (defvar org-agenda-name nil)
  3200. (defvar org-agenda-tag-filter nil)
  3201. (defvar org-agenda-category-filter nil)
  3202. (defvar org-agenda-regexp-filter nil)
  3203. (defvar org-agenda-top-headline-filter nil)
  3204. (defvar org-agenda-tag-filter-while-redo nil)
  3205. (defvar org-agenda-tag-filter-preset nil
  3206. "A preset of the tags filter used for secondary agenda filtering.
  3207. This must be a list of strings, each string must be a single tag preceded
  3208. by \"+\" or \"-\".
  3209. This variable should not be set directly, but agenda custom commands can
  3210. bind it in the options section. The preset filter is a global property of
  3211. the entire agenda view. In a block agenda, it will not work reliably to
  3212. define a filter for one of the individual blocks. You need to set it in
  3213. the global options and expect it to be applied to the entire view.")
  3214. (defvar org-agenda-category-filter-preset nil
  3215. "A preset of the category filter used for secondary agenda filtering.
  3216. This must be a list of strings, each string must be a single category
  3217. preceded by \"+\" or \"-\".
  3218. This variable should not be set directly, but agenda custom commands can
  3219. bind it in the options section. The preset filter is a global property of
  3220. the entire agenda view. In a block agenda, it will not work reliably to
  3221. define a filter for one of the individual blocks. You need to set it in
  3222. the global options and expect it to be applied to the entire view.")
  3223. (defvar org-agenda-regexp-filter-preset nil
  3224. "A preset of the regexp filter used for secondary agenda filtering.
  3225. This must be a list of strings, each string must be a single regexp
  3226. preceded by \"+\" or \"-\".
  3227. This variable should not be set directly, but agenda custom commands can
  3228. bind it in the options section. The preset filter is a global property of
  3229. the entire agenda view. In a block agenda, it will not work reliably to
  3230. define a filter for one of the individual blocks. You need to set it in
  3231. the global options and expect it to be applied to the entire view.")
  3232. (defun org-agenda-use-sticky-p ()
  3233. "Return non-nil if an agenda buffer named
  3234. `org-agenda-buffer-name' exists and should be shown instead of
  3235. generating a new one."
  3236. (and
  3237. ;; turned off by user
  3238. org-agenda-sticky
  3239. ;; For multi-agenda buffer already exists
  3240. (not org-agenda-multi)
  3241. ;; buffer found
  3242. (get-buffer org-agenda-buffer-name)
  3243. ;; C-u parameter is same as last call
  3244. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3245. (and
  3246. (equal current-prefix-arg
  3247. org-agenda-last-prefix-arg)
  3248. ;; In case user turned stickiness on, while having existing
  3249. ;; Agenda buffer active, don't reuse that buffer, because it
  3250. ;; does not have org variables local
  3251. org-agenda-this-buffer-is-sticky))))
  3252. (defun org-agenda-prepare-window (abuf filter-alist)
  3253. "Setup agenda buffer in the window.
  3254. ABUF is the buffer for the agenda window.
  3255. FILTER-ALIST is an alist of filters we need to apply when
  3256. `org-agenda-persistent-filter' is non-nil."
  3257. (let* ((awin (get-buffer-window abuf)) wconf)
  3258. (cond
  3259. ((equal (current-buffer) abuf) nil)
  3260. (awin (select-window awin))
  3261. ((not (setq wconf (current-window-configuration))))
  3262. ((equal org-agenda-window-setup 'current-window)
  3263. (org-pop-to-buffer-same-window abuf))
  3264. ((equal org-agenda-window-setup 'other-window)
  3265. (org-switch-to-buffer-other-window abuf))
  3266. ((equal org-agenda-window-setup 'other-frame)
  3267. (switch-to-buffer-other-frame abuf))
  3268. ((equal org-agenda-window-setup 'reorganize-frame)
  3269. (delete-other-windows)
  3270. (org-switch-to-buffer-other-window abuf)))
  3271. (setq org-agenda-tag-filter (cdr (assoc 'tag filter-alist)))
  3272. (setq org-agenda-category-filter (cdr (assoc 'cat filter-alist)))
  3273. (setq org-agenda-regexp-filter (cdr (assoc 're filter-alist)))
  3274. ;; Additional test in case agenda is invoked from within agenda
  3275. ;; buffer via elisp link.
  3276. (unless (equal (current-buffer) abuf)
  3277. (org-pop-to-buffer-same-window abuf))
  3278. (setq org-agenda-pre-window-conf
  3279. (or org-agenda-pre-window-conf wconf))))
  3280. (defun org-agenda-prepare (&optional name)
  3281. (let ((filter-alist (if org-agenda-persistent-filter
  3282. (list `(tag . ,org-agenda-tag-filter)
  3283. `(re . ,org-agenda-regexp-filter)
  3284. `(car . ,org-agenda-category-filter)))))
  3285. (if (org-agenda-use-sticky-p)
  3286. (progn
  3287. ;; Popup existing buffer
  3288. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3289. filter-alist)
  3290. (message "Sticky Agenda buffer, use `r' to refresh")
  3291. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3292. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3293. (setq org-todo-keywords-for-agenda nil)
  3294. (setq org-drawers-for-agenda nil)
  3295. (put 'org-agenda-tag-filter :preset-filter
  3296. org-agenda-tag-filter-preset)
  3297. (put 'org-agenda-category-filter :preset-filter
  3298. org-agenda-category-filter-preset)
  3299. (put 'org-agenda-regexp-filter :preset-filter
  3300. org-agenda-regexp-filter-preset)
  3301. (if org-agenda-multi
  3302. (progn
  3303. (setq buffer-read-only nil)
  3304. (goto-char (point-max))
  3305. (unless (or (bobp) org-agenda-compact-blocks
  3306. (not org-agenda-block-separator))
  3307. (insert "\n"
  3308. (if (stringp org-agenda-block-separator)
  3309. org-agenda-block-separator
  3310. (make-string (window-width) org-agenda-block-separator))
  3311. "\n"))
  3312. (narrow-to-region (point) (point-max)))
  3313. (setq org-done-keywords-for-agenda nil)
  3314. ;; Setting any org variables that are in org-agenda-local-vars
  3315. ;; list need to be done after the prepare call
  3316. (org-agenda-prepare-window
  3317. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3318. (setq buffer-read-only nil)
  3319. (org-agenda-reset-markers)
  3320. (let ((inhibit-read-only t)) (erase-buffer))
  3321. (org-agenda-mode)
  3322. (setq org-agenda-buffer (current-buffer))
  3323. (setq org-agenda-contributing-files nil)
  3324. (setq org-agenda-columns-active nil)
  3325. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3326. (setq org-todo-keywords-for-agenda
  3327. (org-uniquify org-todo-keywords-for-agenda))
  3328. (setq org-done-keywords-for-agenda
  3329. (org-uniquify org-done-keywords-for-agenda))
  3330. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3331. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3332. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3333. (and name (not org-agenda-name)
  3334. (org-set-local 'org-agenda-name name)))
  3335. (setq buffer-read-only nil))))
  3336. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3337. (defun org-agenda-finalize ()
  3338. "Finishing touch for the agenda buffer, called just before displaying it."
  3339. (unless org-agenda-multi
  3340. (save-excursion
  3341. (let ((inhibit-read-only t))
  3342. (goto-char (point-min))
  3343. (save-excursion
  3344. (while (org-activate-bracket-links (point-max))
  3345. (add-text-properties (match-beginning 0) (match-end 0)
  3346. '(face org-link))))
  3347. (save-excursion
  3348. (while (org-activate-plain-links (point-max))
  3349. (add-text-properties (match-beginning 0) (match-end 0)
  3350. '(face org-link))))
  3351. (unless (eq org-agenda-remove-tags t)
  3352. (org-agenda-align-tags))
  3353. (unless org-agenda-with-colors
  3354. (remove-text-properties (point-min) (point-max) '(face nil)))
  3355. (if (and (boundp 'org-agenda-overriding-columns-format)
  3356. org-agenda-overriding-columns-format)
  3357. (org-set-local 'org-agenda-overriding-columns-format
  3358. org-agenda-overriding-columns-format))
  3359. (if (and (boundp 'org-agenda-view-columns-initially)
  3360. org-agenda-view-columns-initially)
  3361. (org-agenda-columns))
  3362. (when org-agenda-fontify-priorities
  3363. (org-agenda-fontify-priorities))
  3364. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3365. (org-agenda-dim-blocked-tasks))
  3366. (org-agenda-mark-clocking-task)
  3367. (when org-agenda-entry-text-mode
  3368. (org-agenda-entry-text-hide)
  3369. (org-agenda-entry-text-show))
  3370. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3371. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3372. (org-habit-insert-consistency-graphs))
  3373. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3374. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3375. (and (listp org-agenda-show-inherited-tags)
  3376. (memq org-agenda-type org-agenda-show-inherited-tags))
  3377. (and (eq org-agenda-show-inherited-tags t)
  3378. (or (eq org-agenda-use-tag-inheritance t)
  3379. (and (listp org-agenda-use-tag-inheritance)
  3380. (not (memq org-agenda-type
  3381. org-agenda-use-tag-inheritance))))))
  3382. (let (mrk)
  3383. (save-excursion
  3384. (goto-char (point-min))
  3385. (while (equal (forward-line) 0)
  3386. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3387. (put-text-property (point-at-bol) (point-at-eol)
  3388. 'tags (org-with-point-at mrk
  3389. (delete-dups
  3390. (mapcar 'downcase (org-get-tags-at))))))))))
  3391. (run-hooks 'org-agenda-finalize-hook)
  3392. (when org-agenda-top-headline-filter
  3393. (org-agenda-filter-top-headline-apply
  3394. org-agenda-top-headline-filter))
  3395. (when org-agenda-tag-filter
  3396. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3397. (when (get 'org-agenda-tag-filter :preset-filter)
  3398. (org-agenda-filter-apply
  3399. (get 'org-agenda-tag-filter :preset-filter) 'tag))
  3400. (when org-agenda-category-filter
  3401. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3402. (when (get 'org-agenda-category-filter :preset-filter)
  3403. (org-agenda-filter-apply
  3404. (get 'org-agenda-category-filter :preset-filter) 'category))
  3405. (when org-agenda-regexp-filter
  3406. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3407. (when (get 'org-agenda-regexp-filter :preset-filter)
  3408. (org-agenda-filter-apply
  3409. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3410. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3411. (defun org-agenda-mark-clocking-task ()
  3412. "Mark the current clock entry in the agenda if it is present."
  3413. ;; We need to widen when `org-agenda-finalize' is called from
  3414. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3415. (when org-clock-current-task
  3416. (save-restriction
  3417. (widen)
  3418. (org-agenda-unmark-clocking-task)
  3419. (when (marker-buffer org-clock-hd-marker)
  3420. (save-excursion
  3421. (goto-char (point-min))
  3422. (let (s ov)
  3423. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3424. (goto-char s)
  3425. (when (equal (org-get-at-bol 'org-hd-marker)
  3426. org-clock-hd-marker)
  3427. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3428. (overlay-put ov 'type 'org-agenda-clocking)
  3429. (overlay-put ov 'face 'org-agenda-clocking)
  3430. (overlay-put ov 'help-echo
  3431. "The clock is running in this item")))))))))
  3432. (defun org-agenda-unmark-clocking-task ()
  3433. "Unmark the current clocking task."
  3434. (mapc (lambda (o)
  3435. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3436. (delete-overlay o)))
  3437. (overlays-in (point-min) (point-max))))
  3438. (defun org-agenda-fontify-priorities ()
  3439. "Make highest priority lines bold, and lowest italic."
  3440. (interactive)
  3441. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3442. (delete-overlay o)))
  3443. (overlays-in (point-min) (point-max)))
  3444. (save-excursion
  3445. (let (b e p ov h l)
  3446. (goto-char (point-min))
  3447. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3448. (setq h (or (get-char-property (point) 'org-highest-priority)
  3449. org-highest-priority)
  3450. l (or (get-char-property (point) 'org-lowest-priority)
  3451. org-lowest-priority)
  3452. p (string-to-char (match-string 1))
  3453. b (match-beginning 0)
  3454. e (if (eq org-agenda-fontify-priorities 'cookies)
  3455. (match-end 0)
  3456. (point-at-eol))
  3457. ov (make-overlay b e))
  3458. (overlay-put
  3459. ov 'face
  3460. (cons (cond ((org-face-from-face-or-color
  3461. 'priority nil
  3462. (cdr (assoc p org-priority-faces))))
  3463. ((and (listp org-agenda-fontify-priorities)
  3464. (org-face-from-face-or-color
  3465. 'priority nil
  3466. (cdr (assoc p org-agenda-fontify-priorities)))))
  3467. ((equal p l) 'italic)
  3468. ((equal p h) 'bold))
  3469. 'org-priority))
  3470. (overlay-put ov 'org-type 'org-priority)))))
  3471. (defvar org-depend-tag-blocked)
  3472. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3473. "Dim currently blocked TODO's in the agenda display.
  3474. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3475. dimming them."
  3476. (interactive "P")
  3477. (when (org-called-interactively-p 'interactive)
  3478. (message "Dim or hide blocked tasks..."))
  3479. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3480. (delete-overlay o)))
  3481. (overlays-in (point-min) (point-max)))
  3482. (save-excursion
  3483. (let ((inhibit-read-only t)
  3484. (org-depend-tag-blocked nil)
  3485. (invis (or (not (null invisible))
  3486. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3487. org-blocked-by-checkboxes
  3488. invis1 b e p ov h l)
  3489. (goto-char (point-min))
  3490. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3491. (and pos (goto-char (1+ pos))))
  3492. (setq org-blocked-by-checkboxes nil invis1 invis)
  3493. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3494. (when (and marker
  3495. (with-current-buffer (marker-buffer marker)
  3496. (save-excursion (goto-char marker)
  3497. (org-entry-blocked-p))))
  3498. (if org-blocked-by-checkboxes (setq invis1 nil))
  3499. (setq b (if invis1
  3500. (max (point-min) (1- (point-at-bol)))
  3501. (point-at-bol))
  3502. e (point-at-eol)
  3503. ov (make-overlay b e))
  3504. (if invis1
  3505. (progn (overlay-put ov 'invisible t)
  3506. (overlay-put ov 'intangible t))
  3507. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3508. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3509. (when (org-called-interactively-p 'interactive)
  3510. (message "Dim or hide blocked tasks...done")))
  3511. (defvar org-agenda-skip-function nil
  3512. "Function to be called at each match during agenda construction.
  3513. If this function returns nil, the current match should not be skipped.
  3514. Otherwise, the function must return a position from where the search
  3515. should be continued.
  3516. This may also be a Lisp form, it will be evaluated.
  3517. Never set this variable using `setq' or so, because then it will apply
  3518. to all future agenda commands. If you do want a global skipping condition,
  3519. use the option `org-agenda-skip-function-global' instead.
  3520. The correct usage for `org-agenda-skip-function' is to bind it with
  3521. `let' to scope it dynamically into the agenda-constructing command.
  3522. A good way to set it is through options in `org-agenda-custom-commands'.")
  3523. (defun org-agenda-skip ()
  3524. "Throw to `:skip' in places that should be skipped.
  3525. Also moves point to the end of the skipped region, so that search can
  3526. continue from there."
  3527. (let ((p (point-at-bol)) to)
  3528. (when (or
  3529. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3530. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3531. (get-text-property p :org-archived)
  3532. (org-end-of-subtree t))
  3533. (and org-agenda-skip-comment-trees
  3534. (get-text-property p :org-comment)
  3535. (org-end-of-subtree t))
  3536. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3537. (org-agenda-skip-eval org-agenda-skip-function)))
  3538. (goto-char to))
  3539. (org-in-src-block-p t))
  3540. (throw :skip t))))
  3541. (defun org-agenda-skip-eval (form)
  3542. "If FORM is a function or a list, call (or eval) it and return the result.
  3543. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3544. and match data are returned to the previous state no matter what these
  3545. functions do."
  3546. (let (fp)
  3547. (and form
  3548. (or (setq fp (functionp form))
  3549. (consp form))
  3550. (save-excursion
  3551. (save-match-data
  3552. (if fp
  3553. (funcall form)
  3554. (eval form)))))))
  3555. (defvar org-agenda-markers nil
  3556. "List of all currently active markers created by `org-agenda'.")
  3557. (defvar org-agenda-last-marker-time (org-float-time)
  3558. "Creation time of the last agenda marker.")
  3559. (defun org-agenda-new-marker (&optional pos)
  3560. "Return a new agenda marker.
  3561. Org-mode keeps a list of these markers and resets them when they are
  3562. no longer in use."
  3563. (let ((m (copy-marker (or pos (point)))))
  3564. (setq org-agenda-last-marker-time (org-float-time))
  3565. (if org-agenda-buffer
  3566. (with-current-buffer org-agenda-buffer
  3567. (push m org-agenda-markers))
  3568. (push m org-agenda-markers))
  3569. m))
  3570. (defun org-agenda-reset-markers ()
  3571. "Reset markers created by `org-agenda'."
  3572. (while org-agenda-markers
  3573. (move-marker (pop org-agenda-markers) nil)))
  3574. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3575. "Save relative positions of markers in region.
  3576. This check for agenda markers in all agenda buffers currently active."
  3577. (dolist (buf (buffer-list))
  3578. (with-current-buffer buf
  3579. (when (eq major-mode 'org-agenda-mode)
  3580. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3581. org-agenda-markers)))))
  3582. ;;; Entry text mode
  3583. (defun org-agenda-entry-text-show-here ()
  3584. "Add some text from the entry as context to the current line."
  3585. (let (m txt o)
  3586. (setq m (org-get-at-bol 'org-hd-marker))
  3587. (unless (marker-buffer m)
  3588. (error "No marker points to an entry here"))
  3589. (setq txt (concat "\n" (org-no-properties
  3590. (org-agenda-get-some-entry-text
  3591. m org-agenda-entry-text-maxlines
  3592. org-agenda-entry-text-leaders))))
  3593. (when (string-match "\\S-" txt)
  3594. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3595. (overlay-put o 'evaporate t)
  3596. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3597. (overlay-put o 'after-string txt))))
  3598. (defun org-agenda-entry-text-show ()
  3599. "Add entry context for all agenda lines."
  3600. (interactive)
  3601. (save-excursion
  3602. (goto-char (point-max))
  3603. (beginning-of-line 1)
  3604. (while (not (bobp))
  3605. (when (org-get-at-bol 'org-hd-marker)
  3606. (org-agenda-entry-text-show-here))
  3607. (beginning-of-line 0))))
  3608. (defun org-agenda-entry-text-hide ()
  3609. "Remove any shown entry context."
  3610. (delq nil
  3611. (mapcar (lambda (o)
  3612. (if (eq (overlay-get o 'org-overlay-type)
  3613. 'agenda-entry-content)
  3614. (progn (delete-overlay o) t)))
  3615. (overlays-in (point-min) (point-max)))))
  3616. (defun org-agenda-get-day-face (date)
  3617. "Return the face DATE should be displayed with."
  3618. (or (and (functionp org-agenda-day-face-function)
  3619. (funcall org-agenda-day-face-function date))
  3620. (cond ((org-agenda-todayp date)
  3621. 'org-agenda-date-today)
  3622. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3623. 'org-agenda-date-weekend)
  3624. (t 'org-agenda-date))))
  3625. ;;; Agenda timeline
  3626. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3627. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3628. (defun org-timeline (&optional dotodo)
  3629. "Show a time-sorted view of the entries in the current org file.
  3630. Only entries with a time stamp of today or later will be listed. With
  3631. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3632. under the current date.
  3633. If the buffer contains an active region, only check the region for
  3634. dates."
  3635. (interactive "P")
  3636. (let* ((dopast t)
  3637. (org-agenda-show-log-scoped org-agenda-show-log)
  3638. (org-agenda-show-log org-agenda-show-log-scoped)
  3639. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3640. (current-buffer))))
  3641. (date (calendar-current-date))
  3642. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3643. (end (if (org-region-active-p) (region-end) (point-max)))
  3644. (day-numbers (org-get-all-dates
  3645. beg end 'no-ranges
  3646. t org-agenda-show-log-scoped ; always include today
  3647. org-timeline-show-empty-dates))
  3648. (org-deadline-warning-days 0)
  3649. (org-agenda-only-exact-dates t)
  3650. (today (org-today))
  3651. (past t)
  3652. args
  3653. s e rtn d emptyp)
  3654. (setq org-agenda-redo-command
  3655. (list 'let
  3656. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3657. (list 'org-switch-to-buffer-other-window (current-buffer))
  3658. (list 'org-timeline (list 'quote dotodo))))
  3659. (put 'org-agenda-redo-command 'org-lprops nil)
  3660. (if (not dopast)
  3661. ;; Remove past dates from the list of dates.
  3662. (setq day-numbers (delq nil (mapcar (lambda(x)
  3663. (if (>= x today) x nil))
  3664. day-numbers))))
  3665. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3666. (org-compile-prefix-format 'timeline)
  3667. (org-set-sorting-strategy 'timeline)
  3668. (if org-agenda-show-log-scoped (push :closed args))
  3669. (push :timestamp args)
  3670. (push :deadline args)
  3671. (push :scheduled args)
  3672. (push :sexp args)
  3673. (if dotodo (push :todo args))
  3674. (insert "Timeline of file " entry "\n")
  3675. (add-text-properties (point-min) (point)
  3676. (list 'face 'org-agenda-structure))
  3677. (org-agenda-mark-header-line (point-min))
  3678. (while (setq d (pop day-numbers))
  3679. (if (and (listp d) (eq (car d) :omitted))
  3680. (progn
  3681. (setq s (point))
  3682. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3683. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3684. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3685. (if (and (>= d today)
  3686. dopast
  3687. past)
  3688. (progn
  3689. (setq past nil)
  3690. (insert (make-string 79 ?-) "\n")))
  3691. (setq date (calendar-gregorian-from-absolute d))
  3692. (setq s (point))
  3693. (setq rtn (and (not emptyp)
  3694. (apply 'org-agenda-get-day-entries entry
  3695. date args)))
  3696. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3697. (progn
  3698. (insert
  3699. (if (stringp org-agenda-format-date)
  3700. (format-time-string org-agenda-format-date
  3701. (org-time-from-absolute date))
  3702. (funcall org-agenda-format-date date))
  3703. "\n")
  3704. (put-text-property s (1- (point)) 'face
  3705. (org-agenda-get-day-face date))
  3706. (put-text-property s (1- (point)) 'org-date-line t)
  3707. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3708. (if (equal d today)
  3709. (put-text-property s (1- (point)) 'org-today t))
  3710. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3711. (put-text-property s (1- (point)) 'day d)))))
  3712. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3713. (point-min)))
  3714. (add-text-properties
  3715. (point-min) (point-max)
  3716. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3717. (org-agenda-finalize)
  3718. (setq buffer-read-only t)))
  3719. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3720. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3721. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3722. not every single day in the range. If FORCE-TODAY is non-nil, make
  3723. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3724. inactive time stamps (those in square brackets) are included.
  3725. When EMPTY is non-nil, also include days without any entries."
  3726. (let ((re (concat
  3727. (if pre-re pre-re "")
  3728. (if inactive org-ts-regexp-both org-ts-regexp)))
  3729. dates dates1 date day day1 day2 ts1 ts2 pos)
  3730. (if force-today
  3731. (setq dates (list (org-today))))
  3732. (save-excursion
  3733. (goto-char beg)
  3734. (while (re-search-forward re end t)
  3735. (setq day (time-to-days (org-time-string-to-time
  3736. (substring (match-string 1) 0 10)
  3737. (current-buffer) (match-beginning 0))))
  3738. (or (memq day dates) (push day dates)))
  3739. (unless no-ranges
  3740. (goto-char beg)
  3741. (while (re-search-forward org-tr-regexp end t)
  3742. (setq pos (match-beginning 0))
  3743. (setq ts1 (substring (match-string 1) 0 10)
  3744. ts2 (substring (match-string 2) 0 10)
  3745. day1 (time-to-days (org-time-string-to-time
  3746. ts1 (current-buffer) pos))
  3747. day2 (time-to-days (org-time-string-to-time
  3748. ts2 (current-buffer) pos)))
  3749. (while (< (setq day1 (1+ day1)) day2)
  3750. (or (memq day1 dates) (push day1 dates)))))
  3751. (setq dates (sort dates '<))
  3752. (when empty
  3753. (while (setq day (pop dates))
  3754. (setq day2 (car dates))
  3755. (push day dates1)
  3756. (when (and day2 empty)
  3757. (if (or (eq empty t)
  3758. (and (numberp empty) (<= (- day2 day) empty)))
  3759. (while (< (setq day (1+ day)) day2)
  3760. (push (list day) dates1))
  3761. (push (cons :omitted (- day2 day)) dates1))))
  3762. (setq dates (nreverse dates1)))
  3763. dates)))
  3764. ;;; Agenda Daily/Weekly
  3765. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3766. "Start day for the agenda view.
  3767. Custom commands can set this variable in the options section.
  3768. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3769. input allowed when reading a date through the Org calendar.
  3770. See the docstring of `org-read-date' for details.")
  3771. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3772. (defvar org-arg-loc nil) ; local variable
  3773. (defvar org-agenda-buffer-tmp-name nil)
  3774. ;;;###autoload
  3775. (defun org-agenda-list (&optional arg start-day span with-hour)
  3776. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3777. The view will be for the current day or week, but from the overview buffer
  3778. you will be able to go to other days/weeks.
  3779. With a numeric prefix argument in an interactive call, the agenda will
  3780. span ARG days. Lisp programs should instead specify SPAN to change
  3781. the number of days. SPAN defaults to `org-agenda-span'.
  3782. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3783. given in `org-agenda-start-on-weekday'.
  3784. When WITH-HOUR is non-nil, only include scheduled and deadline
  3785. items if they have an hour specification like [h]h:mm."
  3786. (interactive "P")
  3787. (if org-agenda-overriding-arguments
  3788. (setq arg (car org-agenda-overriding-arguments)
  3789. start-day (nth 1 org-agenda-overriding-arguments)
  3790. span (nth 2 org-agenda-overriding-arguments)))
  3791. (if (and (integerp arg) (> arg 0))
  3792. (setq span arg arg nil))
  3793. (catch 'exit
  3794. (setq org-agenda-buffer-name
  3795. (or org-agenda-buffer-tmp-name
  3796. (if org-agenda-sticky
  3797. (cond ((and org-keys (stringp org-match))
  3798. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3799. (org-keys
  3800. (format "*Org Agenda(%s)*" org-keys))
  3801. (t "*Org Agenda(a)*")))
  3802. org-agenda-buffer-name))
  3803. (org-agenda-prepare "Day/Week")
  3804. (setq start-day (or start-day org-agenda-start-day))
  3805. (if (stringp start-day)
  3806. ;; Convert to an absolute day number
  3807. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3808. (org-compile-prefix-format 'agenda)
  3809. (org-set-sorting-strategy 'agenda)
  3810. (let* ((span (org-agenda-ndays-to-span
  3811. (or span org-agenda-ndays org-agenda-span)))
  3812. (today (org-today))
  3813. (sd (or start-day today))
  3814. (ndays (org-agenda-span-to-ndays span sd))
  3815. (org-agenda-start-on-weekday
  3816. (if (or (eq ndays 7) (eq ndays 14))
  3817. org-agenda-start-on-weekday))
  3818. (thefiles (org-agenda-files nil 'ifmode))
  3819. (files thefiles)
  3820. (start (if (or (null org-agenda-start-on-weekday)
  3821. (< ndays 7))
  3822. sd
  3823. (let* ((nt (calendar-day-of-week
  3824. (calendar-gregorian-from-absolute sd)))
  3825. (n1 org-agenda-start-on-weekday)
  3826. (d (- nt n1)))
  3827. (- sd (+ (if (< d 0) 7 0) d)))))
  3828. (day-numbers (list start))
  3829. (day-cnt 0)
  3830. (inhibit-redisplay (not debug-on-error))
  3831. (org-agenda-show-log-scoped org-agenda-show-log)
  3832. s e rtn rtnall file date d start-pos end-pos todayp
  3833. clocktable-start clocktable-end filter)
  3834. (setq org-agenda-redo-command
  3835. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3836. (dotimes (n (1- ndays))
  3837. (push (1+ (car day-numbers)) day-numbers))
  3838. (setq day-numbers (nreverse day-numbers))
  3839. (setq clocktable-start (car day-numbers)
  3840. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3841. (org-set-local 'org-starting-day (car day-numbers))
  3842. (org-set-local 'org-arg-loc arg)
  3843. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3844. (unless org-agenda-compact-blocks
  3845. (let* ((d1 (car day-numbers))
  3846. (d2 (org-last day-numbers))
  3847. (w1 (org-days-to-iso-week d1))
  3848. (w2 (org-days-to-iso-week d2)))
  3849. (setq s (point))
  3850. (if org-agenda-overriding-header
  3851. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3852. nil 'face 'org-agenda-structure) "\n")
  3853. (insert (org-agenda-span-name span)
  3854. "-agenda"
  3855. (if (< (- d2 d1) 350)
  3856. (if (= w1 w2)
  3857. (format " (W%02d)" w1)
  3858. (format " (W%02d-W%02d)" w1 w2))
  3859. "")
  3860. ":\n")))
  3861. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3862. 'org-date-line t))
  3863. (org-agenda-mark-header-line s))
  3864. (while (setq d (pop day-numbers))
  3865. (setq date (calendar-gregorian-from-absolute d)
  3866. s (point))
  3867. (if (or (setq todayp (= d today))
  3868. (and (not start-pos) (= d sd)))
  3869. (setq start-pos (point))
  3870. (if (and start-pos (not end-pos))
  3871. (setq end-pos (point))))
  3872. (setq files thefiles
  3873. rtnall nil)
  3874. (while (setq file (pop files))
  3875. (catch 'nextfile
  3876. (org-check-agenda-file file)
  3877. (let ((org-agenda-entry-types org-agenda-entry-types))
  3878. ;; Starred types override non-starred equivalents
  3879. (when (member :deadline* org-agenda-entry-types)
  3880. (setq org-agenda-entry-types
  3881. (delq :deadline org-agenda-entry-types)))
  3882. (when (member :scheduled* org-agenda-entry-types)
  3883. (setq org-agenda-entry-types
  3884. (delq :scheduled org-agenda-entry-types)))
  3885. ;; Honor with-hour
  3886. (when with-hour
  3887. (when (member :deadline org-agenda-entry-types)
  3888. (setq org-agenda-entry-types
  3889. (delq :deadline org-agenda-entry-types))
  3890. (push :deadline* org-agenda-entry-types))
  3891. (when (member :scheduled org-agenda-entry-types)
  3892. (setq org-agenda-entry-types
  3893. (delq :scheduled org-agenda-entry-types))
  3894. (push :scheduled* org-agenda-entry-types)))
  3895. (unless org-agenda-include-deadlines
  3896. (setq org-agenda-entry-types
  3897. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3898. (cond
  3899. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3900. (setq rtn (org-agenda-get-day-entries
  3901. file date :closed)))
  3902. (org-agenda-show-log-scoped
  3903. (setq rtn (apply 'org-agenda-get-day-entries
  3904. file date
  3905. (append '(:closed) org-agenda-entry-types))))
  3906. (t
  3907. (setq rtn (apply 'org-agenda-get-day-entries
  3908. file date
  3909. org-agenda-entry-types)))))
  3910. (setq rtnall (append rtnall rtn)))) ;; all entries
  3911. (if org-agenda-include-diary
  3912. (let ((org-agenda-search-headline-for-time t))
  3913. (require 'diary-lib)
  3914. (setq rtn (org-get-entries-from-diary date))
  3915. (setq rtnall (append rtnall rtn))))
  3916. (if (or rtnall org-agenda-show-all-dates)
  3917. (progn
  3918. (setq day-cnt (1+ day-cnt))
  3919. (insert
  3920. (if (stringp org-agenda-format-date)
  3921. (format-time-string org-agenda-format-date
  3922. (org-time-from-absolute date))
  3923. (funcall org-agenda-format-date date))
  3924. "\n")
  3925. (put-text-property s (1- (point)) 'face
  3926. (org-agenda-get-day-face date))
  3927. (put-text-property s (1- (point)) 'org-date-line t)
  3928. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3929. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3930. (when todayp
  3931. (put-text-property s (1- (point)) 'org-today t))
  3932. (setq rtnall
  3933. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3934. (if rtnall (insert ;; all entries
  3935. (org-agenda-finalize-entries rtnall 'agenda)
  3936. "\n"))
  3937. (put-text-property s (1- (point)) 'day d)
  3938. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3939. (when (and org-agenda-clockreport-mode clocktable-start)
  3940. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3941. ;; the above line is to ensure the restricted range!
  3942. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3943. tbl)
  3944. (setq p (org-plist-delete p :block))
  3945. (setq p (plist-put p :tstart clocktable-start))
  3946. (setq p (plist-put p :tend clocktable-end))
  3947. (setq p (plist-put p :scope 'agenda))
  3948. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3949. (setq filter (or org-agenda-tag-filter-while-redo
  3950. (get 'org-agenda-tag-filter :preset-filter))))
  3951. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3952. (if (string-match "[<>=]" x)
  3953. ""
  3954. x))
  3955. filter ""))))
  3956. (setq tbl (apply 'org-clock-get-clocktable p))
  3957. (insert tbl)))
  3958. (goto-char (point-min))
  3959. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3960. (unless (and (pos-visible-in-window-p (point-min))
  3961. (pos-visible-in-window-p (point-max)))
  3962. (goto-char (1- (point-max)))
  3963. (recenter -1)
  3964. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3965. (progn
  3966. (goto-char (or start-pos 1))
  3967. (recenter 1))))
  3968. (goto-char (or start-pos 1))
  3969. (add-text-properties (point-min) (point-max)
  3970. `(org-agenda-type agenda
  3971. org-last-args (,arg ,start-day ,span)
  3972. org-redo-cmd ,org-agenda-redo-command
  3973. org-series-cmd ,org-cmd))
  3974. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3975. (org-agenda-show-clocking-issues))
  3976. (org-agenda-finalize)
  3977. (setq buffer-read-only t)
  3978. (message ""))))
  3979. (defun org-agenda-ndays-to-span (n)
  3980. "Return a span symbol for a span of N days, or N if none matches."
  3981. (cond ((symbolp n) n)
  3982. ((= n 1) 'day)
  3983. ((= n 7) 'week)
  3984. ((= n 14) 'fortnight)
  3985. (t n)))
  3986. (defun org-agenda-span-to-ndays (span &optional start-day)
  3987. "Return ndays from SPAN, possibly starting at START-DAY.
  3988. START-DAY is an absolute time value."
  3989. (cond ((numberp span) span)
  3990. ((eq span 'day) 1)
  3991. ((eq span 'week) 7)
  3992. ((eq span 'fortnight) 14)
  3993. ((eq span 'month)
  3994. (let ((date (calendar-gregorian-from-absolute start-day)))
  3995. (calendar-last-day-of-month (car date) (caddr date))))
  3996. ((eq span 'year)
  3997. (let ((date (calendar-gregorian-from-absolute start-day)))
  3998. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3999. (defun org-agenda-span-name (span)
  4000. "Return a SPAN name."
  4001. (if (null span)
  4002. ""
  4003. (if (symbolp span)
  4004. (capitalize (symbol-name span))
  4005. (format "%d days" span))))
  4006. ;;; Agenda word search
  4007. (defvar org-agenda-search-history nil)
  4008. (defvar org-search-syntax-table nil
  4009. "Special syntax table for org-mode search.
  4010. In this table, we have single quotes not as word constituents, to
  4011. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4012. (defvar org-mode-syntax-table) ; From org.el
  4013. (defun org-search-syntax-table ()
  4014. (unless org-search-syntax-table
  4015. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4016. (modify-syntax-entry ?' "." org-search-syntax-table)
  4017. (modify-syntax-entry ?` "." org-search-syntax-table))
  4018. org-search-syntax-table)
  4019. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4020. ;;;###autoload
  4021. (defun org-search-view (&optional todo-only string edit-at)
  4022. "Show all entries that contain a phrase or words or regular expressions.
  4023. With optional prefix argument TODO-ONLY, only consider entries that are
  4024. TODO entries. The argument STRING can be used to pass a default search
  4025. string into this function. If EDIT-AT is non-nil, it means that the
  4026. user should get a chance to edit this string, with cursor at position
  4027. EDIT-AT.
  4028. The search string can be viewed either as a phrase that should be found as
  4029. is, or it can be broken into a number of snippets, each of which must match
  4030. in a Boolean way to select an entry. The default depends on the variable
  4031. `org-agenda-search-view-always-boolean'.
  4032. Even if this is turned off (the default) you can always switch to
  4033. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4034. The default is a direct search of the whole phrase, where each space in
  4035. the search string can expand to an arbitrary amount of whitespace,
  4036. including newlines.
  4037. If using a Boolean search, the search string is split on whitespace and
  4038. each snippet is searched separately, with logical AND to select an entry.
  4039. Words prefixed with a minus must *not* occur in the entry. Words without
  4040. a prefix or prefixed with a plus must occur in the entry. Matching is
  4041. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4042. match whole words, not parts of a word) if
  4043. `org-agenda-search-view-force-full-words' is set (default is nil).
  4044. Boolean search snippets enclosed by curly braces are interpreted as
  4045. regular expressions that must or (when preceded with \"-\") must not
  4046. match in the entry. Snippets enclosed into double quotes will be taken
  4047. as a whole, to include whitespace.
  4048. - If the search string starts with an asterisk, search only in headlines.
  4049. - If (possibly after the leading star) the search string starts with an
  4050. exclamation mark, this also means to look at TODO entries only, an effect
  4051. that can also be achieved with a prefix argument.
  4052. - If (possibly after star and exclamation mark) the search string starts
  4053. with a colon, this will mean that the (non-regexp) snippets of the
  4054. Boolean search must match as full words.
  4055. This command searches the agenda files, and in addition the files listed
  4056. in `org-agenda-text-search-extra-files'."
  4057. (interactive "P")
  4058. (if org-agenda-overriding-arguments
  4059. (setq todo-only (car org-agenda-overriding-arguments)
  4060. string (nth 1 org-agenda-overriding-arguments)
  4061. edit-at (nth 2 org-agenda-overriding-arguments)))
  4062. (let* ((props (list 'face nil
  4063. 'done-face 'org-agenda-done
  4064. 'org-not-done-regexp org-not-done-regexp
  4065. 'org-todo-regexp org-todo-regexp
  4066. 'org-complex-heading-regexp org-complex-heading-regexp
  4067. 'mouse-face 'highlight
  4068. 'help-echo (format "mouse-2 or RET jump to location")))
  4069. (full-words org-agenda-search-view-force-full-words)
  4070. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4071. regexp rtn rtnall files file pos inherited-tags
  4072. marker category category-pos level tags c neg re boolean
  4073. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4074. (unless (and (not edit-at)
  4075. (stringp string)
  4076. (string-match "\\S-" string))
  4077. (setq string (read-string
  4078. (if org-agenda-search-view-always-boolean
  4079. "[+-]Word/{Regexp} ...: "
  4080. "Phrase or [+-]Word/{Regexp} ...: ")
  4081. (cond
  4082. ((integerp edit-at) (cons string edit-at))
  4083. (edit-at string))
  4084. 'org-agenda-search-history)))
  4085. (catch 'exit
  4086. (if org-agenda-sticky
  4087. (setq org-agenda-buffer-name
  4088. (if (stringp string)
  4089. (format "*Org Agenda(%s:%s)*"
  4090. (or org-keys (or (and todo-only "S") "s")) string)
  4091. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4092. (org-agenda-prepare "SEARCH")
  4093. (org-compile-prefix-format 'search)
  4094. (org-set-sorting-strategy 'search)
  4095. (setq org-agenda-redo-command
  4096. (list 'org-search-view (if todo-only t nil)
  4097. (list 'if 'current-prefix-arg nil string)))
  4098. (setq org-agenda-query-string string)
  4099. (if (equal (string-to-char string) ?*)
  4100. (setq hdl-only t
  4101. words (substring string 1))
  4102. (setq words string))
  4103. (when (equal (string-to-char words) ?!)
  4104. (setq todo-only t
  4105. words (substring words 1)))
  4106. (when (equal (string-to-char words) ?:)
  4107. (setq full-words t
  4108. words (substring words 1)))
  4109. (if (or org-agenda-search-view-always-boolean
  4110. (member (string-to-char words) '(?- ?+ ?\{)))
  4111. (setq boolean t))
  4112. (setq words (org-split-string words))
  4113. (let (www w)
  4114. (while (setq w (pop words))
  4115. (while (and (string-match "\\\\\\'" w) words)
  4116. (setq w (concat (substring w 0 -1) " " (pop words))))
  4117. (push w www))
  4118. (setq words (nreverse www) www nil)
  4119. (while (setq w (pop words))
  4120. (when (and (string-match "\\`[-+]?{" w)
  4121. (not (string-match "}\\'" w)))
  4122. (while (and words (not (string-match "}\\'" (car words))))
  4123. (setq w (concat w " " (pop words))))
  4124. (setq w (concat w " " (pop words))))
  4125. (push w www))
  4126. (setq words (nreverse www)))
  4127. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4128. (when boolean
  4129. (let (wds w)
  4130. (while (setq w (pop words))
  4131. (if (or (equal (substring w 0 1) "\"")
  4132. (and (> (length w) 1)
  4133. (member (substring w 0 1) '("+" "-"))
  4134. (equal (substring w 1 2) "\"")))
  4135. (while (and words (not (equal (substring w -1) "\"")))
  4136. (setq w (concat w " " (pop words)))))
  4137. (and (string-match "\\`\\([-+]?\\)\"" w)
  4138. (setq w (replace-match "\\1" nil nil w)))
  4139. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4140. (push w wds))
  4141. (setq words (nreverse wds))))
  4142. (if boolean
  4143. (mapc (lambda (w)
  4144. (setq c (string-to-char w))
  4145. (if (equal c ?-)
  4146. (setq neg t w (substring w 1))
  4147. (if (equal c ?+)
  4148. (setq neg nil w (substring w 1))
  4149. (setq neg nil)))
  4150. (if (string-match "\\`{.*}\\'" w)
  4151. (setq re (substring w 1 -1))
  4152. (if full-words
  4153. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4154. (setq re (regexp-quote (downcase w)))))
  4155. (if neg (push re regexps-) (push re regexps+)))
  4156. words)
  4157. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4158. regexps+))
  4159. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4160. (if (not regexps+)
  4161. (setq regexp org-outline-regexp-bol)
  4162. (setq regexp (pop regexps+))
  4163. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4164. regexp))))
  4165. (setq files (org-agenda-files nil 'ifmode))
  4166. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4167. (pop org-agenda-text-search-extra-files)
  4168. (setq files (org-add-archive-files files)))
  4169. (setq files (append files org-agenda-text-search-extra-files)
  4170. rtnall nil)
  4171. (while (setq file (pop files))
  4172. (setq ee nil)
  4173. (catch 'nextfile
  4174. (org-check-agenda-file file)
  4175. (setq buffer (if (file-exists-p file)
  4176. (org-get-agenda-file-buffer file)
  4177. (error "No such file %s" file)))
  4178. (if (not buffer)
  4179. ;; If file does not exist, make sure an error message is sent
  4180. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4181. file))))
  4182. (with-current-buffer buffer
  4183. (with-syntax-table (org-search-syntax-table)
  4184. (unless (derived-mode-p 'org-mode)
  4185. (error "Agenda file %s is not in `org-mode'" file))
  4186. (let ((case-fold-search t))
  4187. (save-excursion
  4188. (save-restriction
  4189. (if (eq buffer org-agenda-restrict)
  4190. (narrow-to-region org-agenda-restrict-begin
  4191. org-agenda-restrict-end)
  4192. (widen))
  4193. (goto-char (point-min))
  4194. (unless (or (org-at-heading-p)
  4195. (outline-next-heading))
  4196. (throw 'nextfile t))
  4197. (goto-char (max (point-min) (1- (point))))
  4198. (while (re-search-forward regexp nil t)
  4199. (org-back-to-heading t)
  4200. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4201. (> (org-reduced-level (org-outline-level))
  4202. org-agenda-search-view-max-outline-level)
  4203. (forward-line -1)
  4204. (outline-back-to-heading t)))
  4205. (skip-chars-forward "* ")
  4206. (setq beg (point-at-bol)
  4207. beg1 (point)
  4208. end (progn
  4209. (outline-next-heading)
  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-next-heading)))
  4215. (point)))
  4216. (catch :skip
  4217. (goto-char beg)
  4218. (org-agenda-skip)
  4219. (setq str (buffer-substring-no-properties
  4220. (point-at-bol)
  4221. (if hdl-only (point-at-eol) end)))
  4222. (mapc (lambda (wr) (when (string-match wr str)
  4223. (goto-char (1- end))
  4224. (throw :skip t)))
  4225. regexps-)
  4226. (mapc (lambda (wr) (unless (string-match wr str)
  4227. (goto-char (1- end))
  4228. (throw :skip t)))
  4229. (if todo-only
  4230. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4231. regexps+)
  4232. regexps+))
  4233. (goto-char beg)
  4234. (setq marker (org-agenda-new-marker (point))
  4235. category (org-get-category)
  4236. level (make-string (org-reduced-level (org-outline-level)) ? )
  4237. category-pos (get-text-property (point) 'org-category-position)
  4238. inherited-tags
  4239. (or (eq org-agenda-show-inherited-tags 'always)
  4240. (and (listp org-agenda-show-inherited-tags)
  4241. (memq 'todo org-agenda-show-inherited-tags))
  4242. (and (eq org-agenda-show-inherited-tags t)
  4243. (or (eq org-agenda-use-tag-inheritance t)
  4244. (memq 'todo org-agenda-use-tag-inheritance))))
  4245. tags (org-get-tags-at nil (not inherited-tags))
  4246. txt (org-agenda-format-item
  4247. ""
  4248. (buffer-substring-no-properties
  4249. beg1 (point-at-eol))
  4250. level category tags t))
  4251. (org-add-props txt props
  4252. 'org-marker marker 'org-hd-marker marker
  4253. 'org-todo-regexp org-todo-regexp
  4254. 'level level
  4255. 'org-complex-heading-regexp org-complex-heading-regexp
  4256. 'priority 1000 'org-category category
  4257. 'org-category-position category-pos
  4258. 'type "search")
  4259. (push txt ee)
  4260. (goto-char (1- end))))))))))
  4261. (setq rtn (nreverse ee))
  4262. (setq rtnall (append rtnall rtn)))
  4263. (if org-agenda-overriding-header
  4264. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4265. nil 'face 'org-agenda-structure) "\n")
  4266. (insert "Search words: ")
  4267. (add-text-properties (point-min) (1- (point))
  4268. (list 'face 'org-agenda-structure))
  4269. (setq pos (point))
  4270. (insert string "\n")
  4271. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4272. (setq pos (point))
  4273. (unless org-agenda-multi
  4274. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4275. (add-text-properties pos (1- (point))
  4276. (list 'face 'org-agenda-structure))))
  4277. (org-agenda-mark-header-line (point-min))
  4278. (when rtnall
  4279. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4280. (goto-char (point-min))
  4281. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4282. (add-text-properties (point-min) (point-max)
  4283. `(org-agenda-type search
  4284. org-last-args (,todo-only ,string ,edit-at)
  4285. org-redo-cmd ,org-agenda-redo-command
  4286. org-series-cmd ,org-cmd))
  4287. (org-agenda-finalize)
  4288. (setq buffer-read-only t))))
  4289. ;;; Agenda TODO list
  4290. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4291. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4292. (concat
  4293. (if (or (equal keywords "ALL") (not keywords))
  4294. (propertize "ALL" 'face 'warning)
  4295. (mapconcat
  4296. (lambda (kw)
  4297. (propertize kw 'face (org-get-todo-face kw)))
  4298. (org-split-string keywords "|")
  4299. "|"))
  4300. "\n"))
  4301. (defvar org-select-this-todo-keyword nil)
  4302. (defvar org-last-arg nil)
  4303. ;;;###autoload
  4304. (defun org-todo-list (&optional arg)
  4305. "Show all (not done) TODO entries from all agenda file in a single list.
  4306. The prefix arg can be used to select a specific TODO keyword and limit
  4307. the list to these. When using \\[universal-argument], you will be prompted
  4308. for a keyword. A numeric prefix directly selects the Nth keyword in
  4309. `org-todo-keywords-1'."
  4310. (interactive "P")
  4311. (if org-agenda-overriding-arguments
  4312. (setq arg org-agenda-overriding-arguments))
  4313. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4314. (let* ((today (org-today))
  4315. (date (calendar-gregorian-from-absolute today))
  4316. (kwds org-todo-keywords-for-agenda)
  4317. (completion-ignore-case t)
  4318. (org-select-this-todo-keyword
  4319. (if (stringp arg) arg
  4320. (and arg (integerp arg) (> arg 0)
  4321. (nth (1- arg) kwds))))
  4322. rtn rtnall files file pos)
  4323. (when (equal arg '(4))
  4324. (setq org-select-this-todo-keyword
  4325. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4326. (mapcar 'list kwds) nil nil)))
  4327. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4328. (catch 'exit
  4329. (if org-agenda-sticky
  4330. (setq org-agenda-buffer-name
  4331. (if (stringp org-select-this-todo-keyword)
  4332. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4333. org-select-this-todo-keyword)
  4334. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4335. (org-agenda-prepare "TODO")
  4336. (org-compile-prefix-format 'todo)
  4337. (org-set-sorting-strategy 'todo)
  4338. (setq org-agenda-redo-command
  4339. `(org-todo-list (or (and (numberp current-prefix-arg)
  4340. current-prefix-arg)
  4341. ,org-select-this-todo-keyword
  4342. current-prefix-arg ,arg)))
  4343. (setq files (org-agenda-files nil 'ifmode)
  4344. rtnall nil)
  4345. (while (setq file (pop files))
  4346. (catch 'nextfile
  4347. (org-check-agenda-file file)
  4348. (setq rtn (org-agenda-get-day-entries file date :todo))
  4349. (setq rtnall (append rtnall rtn))))
  4350. (if org-agenda-overriding-header
  4351. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4352. nil 'face 'org-agenda-structure) "\n")
  4353. (insert "Global list of TODO items of type: ")
  4354. (add-text-properties (point-min) (1- (point))
  4355. (list 'face 'org-agenda-structure
  4356. 'short-heading
  4357. (concat "ToDo: "
  4358. (or org-select-this-todo-keyword "ALL"))))
  4359. (org-agenda-mark-header-line (point-min))
  4360. (insert (org-agenda-propertize-selected-todo-keywords
  4361. org-select-this-todo-keyword))
  4362. (setq pos (point))
  4363. (unless org-agenda-multi
  4364. (insert "Available with `N r': (0)[ALL]")
  4365. (let ((n 0) s)
  4366. (mapc (lambda (x)
  4367. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4368. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4369. (insert "\n "))
  4370. (insert " " s))
  4371. kwds))
  4372. (insert "\n"))
  4373. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4374. (org-agenda-mark-header-line (point-min))
  4375. (when rtnall
  4376. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4377. (goto-char (point-min))
  4378. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4379. (add-text-properties (point-min) (point-max)
  4380. `(org-agenda-type todo
  4381. org-last-args ,arg
  4382. org-redo-cmd ,org-agenda-redo-command
  4383. org-series-cmd ,org-cmd))
  4384. (org-agenda-finalize)
  4385. (setq buffer-read-only t))))
  4386. ;;; Agenda tags match
  4387. ;;;###autoload
  4388. (defun org-tags-view (&optional todo-only match)
  4389. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4390. The prefix arg TODO-ONLY limits the search to TODO entries."
  4391. (interactive "P")
  4392. (if org-agenda-overriding-arguments
  4393. (setq todo-only (car org-agenda-overriding-arguments)
  4394. match (nth 1 org-agenda-overriding-arguments)))
  4395. (let* ((org-tags-match-list-sublevels
  4396. org-tags-match-list-sublevels)
  4397. (completion-ignore-case t)
  4398. rtn rtnall files file pos matcher
  4399. buffer)
  4400. (when (and (stringp match) (not (string-match "\\S-" match)))
  4401. (setq match nil))
  4402. (catch 'exit
  4403. (if org-agenda-sticky
  4404. (setq org-agenda-buffer-name
  4405. (if (stringp match)
  4406. (format "*Org Agenda(%s:%s)*"
  4407. (or org-keys (or (and todo-only "M") "m")) match)
  4408. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4409. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4410. ;; expanding tags within `org-make-tags-matcher'
  4411. (org-agenda-prepare (concat "TAGS " match))
  4412. (setq matcher (org-make-tags-matcher match)
  4413. match (car matcher) matcher (cdr matcher))
  4414. (org-compile-prefix-format 'tags)
  4415. (org-set-sorting-strategy 'tags)
  4416. (setq org-agenda-query-string match)
  4417. (setq org-agenda-redo-command
  4418. (list 'org-tags-view `(quote ,todo-only)
  4419. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4420. (setq files (org-agenda-files nil 'ifmode)
  4421. rtnall nil)
  4422. (while (setq file (pop files))
  4423. (catch 'nextfile
  4424. (org-check-agenda-file file)
  4425. (setq buffer (if (file-exists-p file)
  4426. (org-get-agenda-file-buffer file)
  4427. (error "No such file %s" file)))
  4428. (if (not buffer)
  4429. ;; If file does not exist, error message to agenda
  4430. (setq rtn (list
  4431. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4432. rtnall (append rtnall rtn))
  4433. (with-current-buffer buffer
  4434. (unless (derived-mode-p 'org-mode)
  4435. (error "Agenda file %s is not in `org-mode'" file))
  4436. (save-excursion
  4437. (save-restriction
  4438. (if (eq buffer org-agenda-restrict)
  4439. (narrow-to-region org-agenda-restrict-begin
  4440. org-agenda-restrict-end)
  4441. (widen))
  4442. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4443. (setq rtnall (append rtnall rtn))))))))
  4444. (if org-agenda-overriding-header
  4445. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4446. nil 'face 'org-agenda-structure) "\n")
  4447. (insert "Headlines with TAGS match: ")
  4448. (add-text-properties (point-min) (1- (point))
  4449. (list 'face 'org-agenda-structure
  4450. 'short-heading
  4451. (concat "Match: " match)))
  4452. (setq pos (point))
  4453. (insert match "\n")
  4454. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4455. (setq pos (point))
  4456. (unless org-agenda-multi
  4457. (insert "Press `C-u r' to search again with new search string\n"))
  4458. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4459. (org-agenda-mark-header-line (point-min))
  4460. (when rtnall
  4461. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4462. (goto-char (point-min))
  4463. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4464. (add-text-properties (point-min) (point-max)
  4465. `(org-agenda-type tags
  4466. org-last-args (,todo-only ,match)
  4467. org-redo-cmd ,org-agenda-redo-command
  4468. org-series-cmd ,org-cmd))
  4469. (org-agenda-finalize)
  4470. (setq buffer-read-only t))))
  4471. ;;; Agenda Finding stuck projects
  4472. (defvar org-agenda-skip-regexp nil
  4473. "Regular expression used in skipping subtrees for the agenda.
  4474. This is basically a temporary global variable that can be set and then
  4475. used by user-defined selections using `org-agenda-skip-function'.")
  4476. (defvar org-agenda-overriding-header nil
  4477. "When set during agenda, todo and tags searches it replaces the header.
  4478. This variable should not be set directly, but custom commands can bind it
  4479. in the options section.")
  4480. (defun org-agenda-skip-entry-when-regexp-matches ()
  4481. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4482. If yes, it returns the end position of this entry, causing agenda commands
  4483. to skip the entry but continuing the search in the subtree. This is a
  4484. function that can be put into `org-agenda-skip-function' for the duration
  4485. of a command."
  4486. (let ((end (save-excursion (org-end-of-subtree t)))
  4487. skip)
  4488. (save-excursion
  4489. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4490. (and skip end)))
  4491. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4492. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4493. If yes, it returns the end position of this tree, causing agenda commands
  4494. to skip this subtree. This is a function that can be put into
  4495. `org-agenda-skip-function' for the duration 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-entry-when-regexp-matches-in-subtree ()
  4502. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4503. If yes, it returns the end position of the current entry (NOT the tree),
  4504. causing agenda commands to skip the entry but continuing the search in
  4505. the subtree. This is a function that can be put into
  4506. `org-agenda-skip-function' for the duration of a command. An important
  4507. use of this function is for the stuck project list."
  4508. (let ((end (save-excursion (org-end-of-subtree t)))
  4509. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4510. skip)
  4511. (save-excursion
  4512. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4513. (and skip entry-end)))
  4514. (defun org-agenda-skip-entry-if (&rest conditions)
  4515. "Skip entry if any of CONDITIONS is true.
  4516. See `org-agenda-skip-if' for details."
  4517. (org-agenda-skip-if nil conditions))
  4518. (defun org-agenda-skip-subtree-if (&rest conditions)
  4519. "Skip subtree if any of CONDITIONS is true.
  4520. See `org-agenda-skip-if' for details."
  4521. (org-agenda-skip-if t conditions))
  4522. (defun org-agenda-skip-if (subtree conditions)
  4523. "Checks current entity for CONDITIONS.
  4524. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4525. the entry (i.e. the text before the next heading) is checked.
  4526. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4527. from different tests. Valid conditions are:
  4528. scheduled Check if there is a scheduled cookie
  4529. notscheduled Check if there is no scheduled cookie
  4530. deadline Check if there is a deadline
  4531. notdeadline Check if there is no deadline
  4532. timestamp Check if there is a timestamp (also deadline or scheduled)
  4533. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4534. regexp Check if regexp matches
  4535. notregexp Check if regexp does not match.
  4536. todo Check if TODO keyword matches
  4537. nottodo Check if TODO keyword does not match
  4538. The regexp is taken from the conditions list, it must come right after
  4539. the `regexp' or `notregexp' element.
  4540. `todo' and `nottodo' accept as an argument a list of todo
  4541. keywords, which may include \"*\" to match any todo keyword.
  4542. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4543. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4544. Instead of a list, a keyword class may be given. For example:
  4545. (org-agenda-skip-entry-if 'nottodo 'done)
  4546. would skip entries that haven't been marked with any of \"DONE\"
  4547. keywords. Possible classes are: `todo', `done', `any'.
  4548. If any of these conditions is met, this function returns the end point of
  4549. the entity, causing the search to continue from there. This is a function
  4550. that can be put into `org-agenda-skip-function' for the duration of a command."
  4551. (let (beg end m)
  4552. (org-back-to-heading t)
  4553. (setq beg (point)
  4554. end (if subtree
  4555. (progn (org-end-of-subtree t) (point))
  4556. (progn (outline-next-heading) (1- (point)))))
  4557. (goto-char beg)
  4558. (and
  4559. (or
  4560. (and (memq 'scheduled conditions)
  4561. (re-search-forward org-scheduled-time-regexp end t))
  4562. (and (memq 'notscheduled conditions)
  4563. (not (re-search-forward org-scheduled-time-regexp end t)))
  4564. (and (memq 'deadline conditions)
  4565. (re-search-forward org-deadline-time-regexp end t))
  4566. (and (memq 'notdeadline conditions)
  4567. (not (re-search-forward org-deadline-time-regexp end t)))
  4568. (and (memq 'timestamp conditions)
  4569. (re-search-forward org-ts-regexp end t))
  4570. (and (memq 'nottimestamp conditions)
  4571. (not (re-search-forward org-ts-regexp end t)))
  4572. (and (setq m (memq 'regexp conditions))
  4573. (stringp (nth 1 m))
  4574. (re-search-forward (nth 1 m) end t))
  4575. (and (setq m (memq 'notregexp conditions))
  4576. (stringp (nth 1 m))
  4577. (not (re-search-forward (nth 1 m) end t)))
  4578. (and (or
  4579. (setq m (memq 'nottodo conditions))
  4580. (setq m (memq 'todo-unblocked conditions))
  4581. (setq m (memq 'nottodo-unblocked conditions))
  4582. (setq m (memq 'todo conditions)))
  4583. (org-agenda-skip-if-todo m end)))
  4584. end)))
  4585. (defun org-agenda-skip-if-todo (args end)
  4586. "Helper function for `org-agenda-skip-if', do not use it directly.
  4587. ARGS is a list with first element either `todo', `nottodo',
  4588. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4589. a list of TODO keywords, or a state symbol `todo' or `done' or
  4590. `any'."
  4591. (let ((kw (car args))
  4592. (arg (cadr args))
  4593. todo-wds todo-re)
  4594. (setq todo-wds
  4595. (org-uniquify
  4596. (cond
  4597. ((listp arg) ;; list of keywords
  4598. (if (member "*" arg)
  4599. (mapcar 'substring-no-properties org-todo-keywords-1)
  4600. arg))
  4601. ((symbolp arg) ;; keyword class name
  4602. (cond
  4603. ((eq arg 'todo)
  4604. (org-delete-all org-done-keywords
  4605. (mapcar 'substring-no-properties
  4606. org-todo-keywords-1)))
  4607. ((eq arg 'done) org-done-keywords)
  4608. ((eq arg 'any)
  4609. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4610. (setq todo-re
  4611. (concat "^\\*+[ \t]+\\<\\("
  4612. (mapconcat 'identity todo-wds "\\|")
  4613. "\\)\\>"))
  4614. (cond
  4615. ((eq kw 'todo) (re-search-forward todo-re end t))
  4616. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4617. ((eq kw 'todo-unblocked)
  4618. (catch 'unblocked
  4619. (while (re-search-forward todo-re end t)
  4620. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4621. nil))
  4622. ((eq kw 'nottodo-unblocked)
  4623. (catch 'unblocked
  4624. (while (re-search-forward todo-re end t)
  4625. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4626. t))
  4627. )))
  4628. ;;;###autoload
  4629. (defun org-agenda-list-stuck-projects (&rest ignore)
  4630. "Create agenda view for projects that are stuck.
  4631. Stuck projects are project that have no next actions. For the definitions
  4632. of what a project is and how to check if it stuck, customize the variable
  4633. `org-stuck-projects'."
  4634. (interactive)
  4635. (let* ((org-agenda-skip-function
  4636. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4637. ;; We could have used org-agenda-skip-if here.
  4638. (org-agenda-overriding-header
  4639. (or org-agenda-overriding-header "List of stuck projects: "))
  4640. (matcher (nth 0 org-stuck-projects))
  4641. (todo (nth 1 org-stuck-projects))
  4642. (todo-wds (if (member "*" todo)
  4643. (progn
  4644. (org-agenda-prepare-buffers (org-agenda-files
  4645. nil 'ifmode))
  4646. (org-delete-all
  4647. org-done-keywords-for-agenda
  4648. (copy-sequence org-todo-keywords-for-agenda)))
  4649. todo))
  4650. (todo-re (concat "^\\*+[ \t]+\\("
  4651. (mapconcat 'identity todo-wds "\\|")
  4652. "\\)\\>"))
  4653. (tags (nth 2 org-stuck-projects))
  4654. (tags-re (if (member "*" tags)
  4655. (concat org-outline-regexp-bol
  4656. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4657. (if tags
  4658. (concat org-outline-regexp-bol
  4659. ".*:\\("
  4660. (mapconcat 'identity tags "\\|")
  4661. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4662. (gen-re (nth 3 org-stuck-projects))
  4663. (re-list
  4664. (delq nil
  4665. (list
  4666. (if todo todo-re)
  4667. (if tags tags-re)
  4668. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4669. gen-re)))))
  4670. (setq org-agenda-skip-regexp
  4671. (if re-list
  4672. (mapconcat 'identity re-list "\\|")
  4673. (error "No information how to identify unstuck projects")))
  4674. (org-tags-view nil matcher)
  4675. (setq org-agenda-buffer-name (buffer-name))
  4676. (with-current-buffer org-agenda-buffer-name
  4677. (setq org-agenda-redo-command
  4678. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4679. ;;; Diary integration
  4680. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4681. (defvar diary-list-entries-hook)
  4682. (defvar diary-time-regexp)
  4683. (defun org-get-entries-from-diary (date)
  4684. "Get the (Emacs Calendar) diary entries for DATE."
  4685. (require 'diary-lib)
  4686. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4687. (diary-display-hook '(fancy-diary-display))
  4688. (diary-display-function 'fancy-diary-display)
  4689. (pop-up-frames nil)
  4690. (diary-list-entries-hook
  4691. (cons 'org-diary-default-entry diary-list-entries-hook))
  4692. (diary-file-name-prefix nil) ; turn this feature off
  4693. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4694. entries
  4695. (org-disable-agenda-to-diary t))
  4696. (save-excursion
  4697. (save-window-excursion
  4698. (funcall (if (fboundp 'diary-list-entries)
  4699. 'diary-list-entries 'list-diary-entries)
  4700. date 1)))
  4701. (if (not (get-buffer diary-fancy-buffer))
  4702. (setq entries nil)
  4703. (with-current-buffer diary-fancy-buffer
  4704. (setq buffer-read-only nil)
  4705. (if (zerop (buffer-size))
  4706. ;; No entries
  4707. (setq entries nil)
  4708. ;; Omit the date and other unnecessary stuff
  4709. (org-agenda-cleanup-fancy-diary)
  4710. ;; Add prefix to each line and extend the text properties
  4711. (if (zerop (buffer-size))
  4712. (setq entries nil)
  4713. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4714. (setq entries
  4715. (with-temp-buffer
  4716. (insert entries) (goto-char (point-min))
  4717. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4718. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4719. (replace-match (concat "; " (match-string 1)))))
  4720. (buffer-string)))))
  4721. (set-buffer-modified-p nil)
  4722. (kill-buffer diary-fancy-buffer)))
  4723. (when entries
  4724. (setq entries (org-split-string entries "\n"))
  4725. (setq entries
  4726. (mapcar
  4727. (lambda (x)
  4728. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4729. ;; Extend the text properties to the beginning of the line
  4730. (org-add-props x (text-properties-at (1- (length x)) x)
  4731. 'type "diary" 'date date 'face 'org-agenda-diary))
  4732. entries)))))
  4733. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4734. "Hook run when the fancy diary buffer is cleaned up.")
  4735. (defun org-agenda-cleanup-fancy-diary ()
  4736. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4737. This gets rid of the date, the underline under the date, and
  4738. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4739. date. It also removes lines that contain only whitespace."
  4740. (goto-char (point-min))
  4741. (if (looking-at ".*?:[ \t]*")
  4742. (progn
  4743. (replace-match "")
  4744. (re-search-forward "\n=+$" nil t)
  4745. (replace-match "")
  4746. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4747. (re-search-forward "\n=+$" nil t)
  4748. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4749. (goto-char (point-min))
  4750. (while (re-search-forward "^ +\n" nil t)
  4751. (replace-match ""))
  4752. (goto-char (point-min))
  4753. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4754. (replace-match ""))
  4755. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4756. ;; Make sure entries from the diary have the right text properties.
  4757. (eval-after-load "diary-lib"
  4758. '(if (boundp 'diary-modify-entry-list-string-function)
  4759. ;; We can rely on the hook, nothing to do
  4760. nil
  4761. ;; Hook not available, must use advice to make this work
  4762. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4763. "Make the position visible."
  4764. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4765. (stringp string)
  4766. buffer-file-name)
  4767. (setq string (org-modify-diary-entry-string string))))))
  4768. (defun org-modify-diary-entry-string (string)
  4769. "Add text properties to string, allowing org-mode to act on it."
  4770. (org-add-props string nil
  4771. 'mouse-face 'highlight
  4772. 'help-echo (if buffer-file-name
  4773. (format "mouse-2 or RET jump to diary file %s"
  4774. (abbreviate-file-name buffer-file-name))
  4775. "")
  4776. 'org-agenda-diary-link t
  4777. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4778. (defun org-diary-default-entry ()
  4779. "Add a dummy entry to the diary.
  4780. Needed to avoid empty dates which mess up holiday display."
  4781. ;; Catch the error if dealing with the new add-to-diary-alist
  4782. (when org-disable-agenda-to-diary
  4783. (condition-case nil
  4784. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4785. (error
  4786. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4787. (defun org-add-to-diary-list (&rest args)
  4788. (if (fboundp 'diary-add-to-list)
  4789. (apply 'diary-add-to-list args)
  4790. (apply 'add-to-diary-list args)))
  4791. (defvar org-diary-last-run-time nil)
  4792. ;;;###autoload
  4793. (defun org-diary (&rest args)
  4794. "Return diary information from org files.
  4795. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4796. It accesses org files and extracts information from those files to be
  4797. listed in the diary. The function accepts arguments specifying what
  4798. items should be listed. For a list of arguments allowed here, see the
  4799. variable `org-agenda-entry-types'.
  4800. The call in the diary file should look like this:
  4801. &%%(org-diary) ~/path/to/some/orgfile.org
  4802. Use a separate line for each org file to check. Or, if you omit the file name,
  4803. all files listed in `org-agenda-files' will be checked automatically:
  4804. &%%(org-diary)
  4805. If you don't give any arguments (as in the example above), the default value
  4806. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4807. So the example above may also be written as
  4808. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4809. The function expects the lisp variables `entry' and `date' to be provided
  4810. by the caller, because this is how the calendar works. Don't use this
  4811. function from a program - use `org-agenda-get-day-entries' instead."
  4812. (when (> (- (org-float-time)
  4813. org-agenda-last-marker-time)
  4814. 5)
  4815. ;; I am not sure if this works with sticky agendas, because the marker
  4816. ;; list is then no longer a global variable.
  4817. (org-agenda-reset-markers))
  4818. (org-compile-prefix-format 'agenda)
  4819. (org-set-sorting-strategy 'agenda)
  4820. (setq args (or args org-agenda-entry-types))
  4821. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4822. (list entry)
  4823. (org-agenda-files t)))
  4824. (time (org-float-time))
  4825. file rtn results)
  4826. (when (or (not org-diary-last-run-time)
  4827. (> (- time
  4828. org-diary-last-run-time)
  4829. 3))
  4830. (org-agenda-prepare-buffers files))
  4831. (setq org-diary-last-run-time time)
  4832. ;; If this is called during org-agenda, don't return any entries to
  4833. ;; the calendar. Org Agenda will list these entries itself.
  4834. (if org-disable-agenda-to-diary (setq files nil))
  4835. (while (setq file (pop files))
  4836. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4837. (setq results (append results rtn)))
  4838. (when results
  4839. (setq results
  4840. (mapcar (lambda (i) (replace-regexp-in-string
  4841. org-bracket-link-regexp "\\3" i)) results))
  4842. (concat (org-agenda-finalize-entries results) "\n"))))
  4843. ;;; Agenda entry finders
  4844. (defun org-agenda-get-day-entries (file date &rest args)
  4845. "Does the work for `org-diary' and `org-agenda'.
  4846. FILE is the path to a file to be checked for entries. DATE is date like
  4847. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4848. which kind of entries should be extracted. For details about these, see
  4849. the documentation of `org-diary'."
  4850. (setq args (or args org-agenda-entry-types))
  4851. (let* ((org-startup-folded nil)
  4852. (org-startup-align-all-tables nil)
  4853. (buffer (if (file-exists-p file)
  4854. (org-get-agenda-file-buffer file)
  4855. (error "No such file %s" file)))
  4856. arg results rtn deadline-results)
  4857. (if (not buffer)
  4858. ;; If file does not exist, make sure an error message ends up in diary
  4859. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4860. (with-current-buffer buffer
  4861. (unless (derived-mode-p 'org-mode)
  4862. (error "Agenda file %s is not in `org-mode'" file))
  4863. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4864. (let ((case-fold-search nil))
  4865. (save-excursion
  4866. (save-restriction
  4867. (if (eq buffer org-agenda-restrict)
  4868. (narrow-to-region org-agenda-restrict-begin
  4869. org-agenda-restrict-end)
  4870. (widen))
  4871. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4872. (while (setq arg (pop args))
  4873. (cond
  4874. ((and (eq arg :todo)
  4875. (equal date (calendar-gregorian-from-absolute
  4876. (org-today))))
  4877. (setq rtn (org-agenda-get-todos))
  4878. (setq results (append results rtn)))
  4879. ((eq arg :timestamp)
  4880. (setq rtn (org-agenda-get-blocks))
  4881. (setq results (append results rtn))
  4882. (setq rtn (org-agenda-get-timestamps deadline-results))
  4883. (setq results (append results rtn)))
  4884. ((eq arg :sexp)
  4885. (setq rtn (org-agenda-get-sexps))
  4886. (setq results (append results rtn)))
  4887. ((eq arg :scheduled)
  4888. (setq rtn (org-agenda-get-scheduled deadline-results))
  4889. (setq results (append results rtn)))
  4890. ((eq arg :scheduled*)
  4891. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4892. (setq results (append results rtn)))
  4893. ((eq arg :closed)
  4894. (setq rtn (org-agenda-get-progress))
  4895. (setq results (append results rtn)))
  4896. ((eq arg :deadline)
  4897. (setq rtn (org-agenda-get-deadlines))
  4898. (setq deadline-results (copy-sequence rtn))
  4899. (setq results (append results rtn)))
  4900. ((eq arg :deadline*)
  4901. (setq rtn (org-agenda-get-deadlines t))
  4902. (setq deadline-results (copy-sequence rtn))
  4903. (setq results (append results rtn))))))))
  4904. results))))
  4905. (defsubst org-em (x y list)
  4906. "Is X or Y a member of LIST?"
  4907. (or (memq x list) (memq y list)))
  4908. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4909. (defvar org-agenda-sorting-strategy-selected nil)
  4910. (defun org-agenda-get-todos ()
  4911. "Return the TODO information for agenda display."
  4912. (let* ((props (list 'face nil
  4913. 'done-face 'org-agenda-done
  4914. 'org-not-done-regexp org-not-done-regexp
  4915. 'org-todo-regexp org-todo-regexp
  4916. 'org-complex-heading-regexp org-complex-heading-regexp
  4917. 'mouse-face 'highlight
  4918. 'help-echo
  4919. (format "mouse-2 or RET jump to org file %s"
  4920. (abbreviate-file-name buffer-file-name))))
  4921. (regexp (format org-heading-keyword-regexp-format
  4922. (cond
  4923. ((and org-select-this-todo-keyword
  4924. (equal org-select-this-todo-keyword "*"))
  4925. org-todo-regexp)
  4926. (org-select-this-todo-keyword
  4927. (concat "\\("
  4928. (mapconcat 'identity
  4929. (org-split-string
  4930. org-select-this-todo-keyword
  4931. "|")
  4932. "\\|") "\\)"))
  4933. (t org-not-done-regexp))))
  4934. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4935. ee txt beg end inherited-tags todo-state-end-pos)
  4936. (goto-char (point-min))
  4937. (while (re-search-forward regexp nil t)
  4938. (catch :skip
  4939. (save-match-data
  4940. (beginning-of-line)
  4941. (org-agenda-skip)
  4942. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4943. (unless (and (setq todo-state (org-get-todo-state))
  4944. (setq todo-state-end-pos (match-end 2)))
  4945. (goto-char end)
  4946. (throw :skip nil))
  4947. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4948. (goto-char (1+ beg))
  4949. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4950. (throw :skip nil)))
  4951. (goto-char (match-beginning 2))
  4952. (setq marker (org-agenda-new-marker (match-beginning 0))
  4953. category (org-get-category)
  4954. ts-date (let (ts)
  4955. (save-match-data
  4956. (cond ((org-em 'scheduled-up 'scheduled-down
  4957. org-agenda-sorting-strategy-selected)
  4958. (setq ts (org-entry-get (point) "SCHEDULED")
  4959. ts-date-type " scheduled"))
  4960. ((org-em 'deadline-up 'deadline-down
  4961. org-agenda-sorting-strategy-selected)
  4962. (setq ts (org-entry-get (point) "DEADLINE")
  4963. ts-date-type " deadline"))
  4964. ((org-em 'ts-up 'ts-down
  4965. org-agenda-sorting-strategy-selected)
  4966. (setq ts (org-entry-get (point) "TIMESTAMP")
  4967. ts-date-type " timestamp"))
  4968. ((org-em 'tsia-up 'tsia-down
  4969. org-agenda-sorting-strategy-selected)
  4970. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4971. ts-date-type " timestamp_ia"))
  4972. ((org-em 'timestamp-up 'timestamp-down
  4973. org-agenda-sorting-strategy-selected)
  4974. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4975. (org-entry-get (point) "DEADLINE")
  4976. (org-entry-get (point) "TIMESTAMP")
  4977. (org-entry-get (point) "TIMESTAMP_IA"))
  4978. ts-date-type ""))
  4979. (t (setq ts-date-type "")))
  4980. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4981. category-pos (get-text-property (point) 'org-category-position)
  4982. txt (org-trim
  4983. (buffer-substring (match-beginning 2) (match-end 0)))
  4984. inherited-tags
  4985. (or (eq org-agenda-show-inherited-tags 'always)
  4986. (and (listp org-agenda-show-inherited-tags)
  4987. (memq 'todo org-agenda-show-inherited-tags))
  4988. (and (eq org-agenda-show-inherited-tags t)
  4989. (or (eq org-agenda-use-tag-inheritance t)
  4990. (memq 'todo org-agenda-use-tag-inheritance))))
  4991. tags (org-get-tags-at nil (not inherited-tags))
  4992. level (make-string (org-reduced-level (org-outline-level)) ? )
  4993. txt (org-agenda-format-item "" txt level category tags t)
  4994. priority (1+ (org-get-priority txt)))
  4995. (org-add-props txt props
  4996. 'org-marker marker 'org-hd-marker marker
  4997. 'priority priority 'org-category category
  4998. 'level level
  4999. 'ts-date ts-date
  5000. 'org-category-position category-pos
  5001. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5002. (push txt ee)
  5003. (if org-agenda-todo-list-sublevels
  5004. (goto-char todo-state-end-pos)
  5005. (org-end-of-subtree 'invisible))))
  5006. (nreverse ee)))
  5007. (defun org-agenda-todo-custom-ignore-p (time n)
  5008. "Check whether timestamp is farther away than n number of days.
  5009. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5010. `org-agenda-todo-ignore-scheduled' or
  5011. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5012. (let ((days (org-time-stamp-to-now
  5013. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5014. (if (>= n 0)
  5015. (>= days n)
  5016. (<= days n))))
  5017. ;;;###autoload
  5018. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5019. (&optional end)
  5020. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5021. (when (or org-agenda-todo-ignore-with-date
  5022. org-agenda-todo-ignore-scheduled
  5023. org-agenda-todo-ignore-deadlines
  5024. org-agenda-todo-ignore-timestamp)
  5025. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5026. (save-excursion
  5027. (or (and org-agenda-todo-ignore-with-date
  5028. (re-search-forward org-ts-regexp end t))
  5029. (and org-agenda-todo-ignore-scheduled
  5030. (re-search-forward org-scheduled-time-regexp end t)
  5031. (cond
  5032. ((eq org-agenda-todo-ignore-scheduled 'future)
  5033. (> (org-time-stamp-to-now
  5034. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5035. ((eq org-agenda-todo-ignore-scheduled 'past)
  5036. (<= (org-time-stamp-to-now
  5037. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5038. ((numberp org-agenda-todo-ignore-scheduled)
  5039. (org-agenda-todo-custom-ignore-p
  5040. (match-string 1) org-agenda-todo-ignore-scheduled))
  5041. (t)))
  5042. (and org-agenda-todo-ignore-deadlines
  5043. (re-search-forward org-deadline-time-regexp end t)
  5044. (cond
  5045. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5046. ((eq org-agenda-todo-ignore-deadlines 'far)
  5047. (not (org-deadline-close (match-string 1))))
  5048. ((eq org-agenda-todo-ignore-deadlines 'future)
  5049. (> (org-time-stamp-to-now
  5050. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5051. ((eq org-agenda-todo-ignore-deadlines 'past)
  5052. (<= (org-time-stamp-to-now
  5053. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5054. ((numberp org-agenda-todo-ignore-deadlines)
  5055. (org-agenda-todo-custom-ignore-p
  5056. (match-string 1) org-agenda-todo-ignore-deadlines))
  5057. (t (org-deadline-close (match-string 1)))))
  5058. (and org-agenda-todo-ignore-timestamp
  5059. (let ((buffer (current-buffer))
  5060. (regexp
  5061. (concat
  5062. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5063. (start (point)))
  5064. ;; Copy current buffer into a temporary one
  5065. (with-temp-buffer
  5066. (insert-buffer-substring buffer start end)
  5067. (goto-char (point-min))
  5068. ;; Delete SCHEDULED and DEADLINE items
  5069. (while (re-search-forward regexp end t)
  5070. (delete-region (match-beginning 0) (match-end 0)))
  5071. (goto-char (point-min))
  5072. ;; No search for timestamp left
  5073. (when (re-search-forward org-ts-regexp nil t)
  5074. (cond
  5075. ((eq org-agenda-todo-ignore-timestamp 'future)
  5076. (> (org-time-stamp-to-now
  5077. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5078. ((eq org-agenda-todo-ignore-timestamp 'past)
  5079. (<= (org-time-stamp-to-now
  5080. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5081. ((numberp org-agenda-todo-ignore-timestamp)
  5082. (org-agenda-todo-custom-ignore-p
  5083. (match-string 1) org-agenda-todo-ignore-timestamp))
  5084. (t))))))))))
  5085. (defun org-agenda-get-timestamps (&optional deadline-results)
  5086. "Return the date stamp information for agenda display."
  5087. (let* ((props (list 'face 'org-agenda-calendar-event
  5088. 'org-not-done-regexp org-not-done-regexp
  5089. 'org-todo-regexp org-todo-regexp
  5090. 'org-complex-heading-regexp org-complex-heading-regexp
  5091. 'mouse-face 'highlight
  5092. 'help-echo
  5093. (format "mouse-2 or RET jump to org file %s"
  5094. (abbreviate-file-name buffer-file-name))))
  5095. (d1 (calendar-absolute-from-gregorian date))
  5096. mm
  5097. (deadline-position-alist
  5098. (mapcar (lambda (a) (and (setq mm (get-text-property
  5099. 0 'org-hd-marker a))
  5100. (cons (marker-position mm) a)))
  5101. deadline-results))
  5102. (remove-re org-ts-regexp)
  5103. (regexp
  5104. (concat
  5105. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5106. (regexp-quote
  5107. (substring
  5108. (format-time-string
  5109. (car org-time-stamp-formats)
  5110. (apply 'encode-time ; DATE bound by calendar
  5111. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5112. 1 11))
  5113. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5114. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5115. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5116. donep tmp priority category category-pos level ee txt timestr tags
  5117. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5118. inherited-tags ts-date)
  5119. (goto-char (point-min))
  5120. (while (setq end-of-match (re-search-forward regexp nil t))
  5121. (setq b0 (match-beginning 0)
  5122. b3 (match-beginning 3) e3 (match-end 3)
  5123. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5124. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5125. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5126. (member todo-state
  5127. org-agenda-repeating-timestamp-show-all)))
  5128. (catch :skip
  5129. (and (org-at-date-range-p) (throw :skip nil))
  5130. (org-agenda-skip)
  5131. (if (and (match-end 1)
  5132. (not (= d1 (org-time-string-to-absolute
  5133. (match-string 1) d1 nil show-all
  5134. (current-buffer) b0))))
  5135. (throw :skip nil))
  5136. (if (and e3
  5137. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5138. (throw :skip nil))
  5139. (setq tmp (buffer-substring (max (point-min)
  5140. (- b0 org-ds-keyword-length))
  5141. b0)
  5142. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5143. inactivep (= (char-after b0) ?\[)
  5144. deadlinep (string-match org-deadline-regexp tmp)
  5145. scheduledp (string-match org-scheduled-regexp tmp)
  5146. closedp (and org-agenda-include-inactive-timestamps
  5147. (string-match org-closed-string tmp))
  5148. clockp (and org-agenda-include-inactive-timestamps
  5149. (or (string-match org-clock-string tmp)
  5150. (string-match "]-+\\'" tmp)))
  5151. warntime (get-text-property (point) 'org-appt-warntime)
  5152. donep (member todo-state org-done-keywords))
  5153. (if (or scheduledp deadlinep closedp clockp
  5154. (and donep org-agenda-skip-timestamp-if-done))
  5155. (throw :skip t))
  5156. (if (string-match ">" timestr)
  5157. ;; substring should only run to end of time stamp
  5158. (setq timestr (substring timestr 0 (match-end 0))))
  5159. (setq marker (org-agenda-new-marker b0)
  5160. category (org-get-category b0)
  5161. category-pos (get-text-property b0 'org-category-position))
  5162. (save-excursion
  5163. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5164. (throw :skip nil)
  5165. (goto-char (match-beginning 0))
  5166. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5167. (assoc (point) deadline-position-alist))
  5168. (throw :skip nil))
  5169. (setq hdmarker (org-agenda-new-marker)
  5170. inherited-tags
  5171. (or (eq org-agenda-show-inherited-tags 'always)
  5172. (and (listp org-agenda-show-inherited-tags)
  5173. (memq 'agenda org-agenda-show-inherited-tags))
  5174. (and (eq org-agenda-show-inherited-tags t)
  5175. (or (eq org-agenda-use-tag-inheritance t)
  5176. (memq 'agenda org-agenda-use-tag-inheritance))))
  5177. tags (org-get-tags-at nil (not inherited-tags))
  5178. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5179. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5180. (setq head (or (match-string 1) ""))
  5181. (setq txt (org-agenda-format-item
  5182. (if inactivep org-agenda-inactive-leader nil)
  5183. head level category tags timestr
  5184. remove-re habitp)))
  5185. (setq priority (org-get-priority txt))
  5186. (org-add-props txt props 'priority priority
  5187. 'org-marker marker 'org-hd-marker hdmarker
  5188. 'org-category category 'date date
  5189. 'level level
  5190. 'ts-date
  5191. (ignore-errors (org-time-string-to-absolute timestr))
  5192. 'org-category-position category-pos
  5193. 'todo-state todo-state
  5194. 'warntime warntime
  5195. 'type "timestamp")
  5196. (push txt ee))
  5197. (if org-agenda-skip-additional-timestamps-same-entry
  5198. (outline-next-heading)
  5199. (goto-char end-of-match))))
  5200. (nreverse ee)))
  5201. (defun org-agenda-get-sexps ()
  5202. "Return the sexp information for agenda display."
  5203. (require 'diary-lib)
  5204. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5205. 'mouse-face 'highlight
  5206. 'help-echo
  5207. (format "mouse-2 or RET jump to org file %s"
  5208. (abbreviate-file-name buffer-file-name))))
  5209. (regexp "^&?%%(")
  5210. marker category extra category-pos level ee txt tags entry
  5211. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5212. (goto-char (point-min))
  5213. (while (re-search-forward regexp nil t)
  5214. (catch :skip
  5215. (org-agenda-skip)
  5216. (setq beg (match-beginning 0))
  5217. (goto-char (1- (match-end 0)))
  5218. (setq b (point))
  5219. (forward-sexp 1)
  5220. (setq sexp (buffer-substring b (point)))
  5221. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5222. (org-trim (match-string 1))
  5223. ""))
  5224. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5225. (when result
  5226. (setq marker (org-agenda-new-marker beg)
  5227. level (make-string (org-reduced-level (org-outline-level)) ? )
  5228. category (org-get-category beg)
  5229. category-pos (get-text-property beg 'org-category-position)
  5230. inherited-tags
  5231. (or (eq org-agenda-show-inherited-tags 'always)
  5232. (and (listp org-agenda-show-inherited-tags)
  5233. (memq 'agenda org-agenda-show-inherited-tags))
  5234. (and (eq org-agenda-show-inherited-tags t)
  5235. (or (eq org-agenda-use-tag-inheritance t)
  5236. (memq 'agenda org-agenda-use-tag-inheritance))))
  5237. tags (org-get-tags-at nil (not inherited-tags))
  5238. todo-state (org-get-todo-state)
  5239. warntime (get-text-property (point) 'org-appt-warntime)
  5240. extra nil)
  5241. (dolist (r (if (stringp result)
  5242. (list result)
  5243. result)) ;; we expect a list here
  5244. (when (and org-agenda-diary-sexp-prefix
  5245. (string-match org-agenda-diary-sexp-prefix r))
  5246. (setq extra (match-string 0 r)
  5247. r (replace-match "" nil nil r)))
  5248. (if (string-match "\\S-" r)
  5249. (setq txt r)
  5250. (setq txt "SEXP entry returned empty string"))
  5251. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5252. (org-add-props txt props 'org-marker marker
  5253. 'org-category category 'date date 'todo-state todo-state
  5254. 'org-category-position category-pos 'tags tags
  5255. 'level level
  5256. 'type "sexp" 'warntime warntime)
  5257. (push txt ee)))))
  5258. (nreverse ee)))
  5259. ;; Calendar sanity: define some functions that are independent of
  5260. ;; `calendar-date-style'.
  5261. ;; Normally I would like to use ISO format when calling the diary functions,
  5262. ;; but to make sure we still have Emacs 22 compatibility we bind
  5263. ;; also `european-calendar-style' and use european format
  5264. (defun org-anniversary (year month day &optional mark)
  5265. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5266. (org-no-warnings
  5267. (let ((calendar-date-style 'european) (european-calendar-style t))
  5268. (diary-anniversary day month year mark))))
  5269. (defun org-cyclic (N year month day &optional mark)
  5270. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5271. (org-no-warnings
  5272. (let ((calendar-date-style 'european) (european-calendar-style t))
  5273. (diary-cyclic N day month year mark))))
  5274. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5275. "Like `diary-block', but with fixed (ISO) order of arguments."
  5276. (org-no-warnings
  5277. (let ((calendar-date-style 'european) (european-calendar-style t))
  5278. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5279. (defun org-date (year month day &optional mark)
  5280. "Like `diary-date', but with fixed (ISO) order of arguments."
  5281. (org-no-warnings
  5282. (let ((calendar-date-style 'european) (european-calendar-style t))
  5283. (diary-date day month year mark))))
  5284. ;; Define the` org-class' function
  5285. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5286. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5287. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5288. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5289. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5290. `holidays', then any date that is known by the Emacs calendar to be a
  5291. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5292. then those holidays will be skipped."
  5293. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5294. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5295. (d (calendar-absolute-from-gregorian date))
  5296. (h (when skip-weeks (calendar-check-holidays date))))
  5297. (and
  5298. (<= date1 d)
  5299. (<= d date2)
  5300. (= (calendar-day-of-week date) dayname)
  5301. (or (not skip-weeks)
  5302. (progn
  5303. (require 'cal-iso)
  5304. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5305. (not (or (and h (memq 'holidays skip-weeks))
  5306. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5307. entry)))
  5308. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5309. "Like `org-class', but honor `calendar-date-style'.
  5310. The order of the first 2 times 3 arguments depends on the variable
  5311. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5312. So for American calendars, give this as MONTH DAY YEAR, for European as
  5313. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5314. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5315. is any number of ISO weeks in the block period for which the item should
  5316. be skipped.
  5317. This function is here only for backward compatibility and it is deprecated,
  5318. please use `org-class' instead."
  5319. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5320. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5321. (org-class
  5322. (nth 2 date1) (car date1) (nth 1 date1)
  5323. (nth 2 date2) (car date2) (nth 1 date2)
  5324. dayname skip-weeks)))
  5325. (make-obsolete 'org-diary-class 'org-class "")
  5326. (defalias 'org-get-closed 'org-agenda-get-progress)
  5327. (defun org-agenda-get-progress ()
  5328. "Return the logged TODO entries for agenda display."
  5329. (let* ((props (list 'mouse-face 'highlight
  5330. 'org-not-done-regexp org-not-done-regexp
  5331. 'org-todo-regexp org-todo-regexp
  5332. 'org-complex-heading-regexp org-complex-heading-regexp
  5333. 'help-echo
  5334. (format "mouse-2 or RET jump to org file %s"
  5335. (abbreviate-file-name buffer-file-name))))
  5336. (items (if (consp org-agenda-show-log-scoped)
  5337. org-agenda-show-log-scoped
  5338. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5339. '(clock)
  5340. org-agenda-log-mode-items)))
  5341. (parts
  5342. (delq nil
  5343. (list
  5344. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5345. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5346. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5347. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5348. (error "`org-agenda-log-mode-items' is empty")))
  5349. (regexp (concat
  5350. "\\(" parts-re "\\)"
  5351. " *\\["
  5352. (regexp-quote
  5353. (substring
  5354. (format-time-string
  5355. (car org-time-stamp-formats)
  5356. (apply 'encode-time ; DATE bound by calendar
  5357. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5358. 1 11))))
  5359. (org-agenda-search-headline-for-time nil)
  5360. marker hdmarker priority category category-pos level tags closedp
  5361. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5362. (goto-char (point-min))
  5363. (while (re-search-forward regexp nil t)
  5364. (catch :skip
  5365. (org-agenda-skip)
  5366. (setq marker (org-agenda-new-marker (match-beginning 0))
  5367. closedp (equal (match-string 1) org-closed-string)
  5368. statep (equal (string-to-char (match-string 1)) ?-)
  5369. clockp (not (or closedp statep))
  5370. state (and statep (match-string 2))
  5371. category (org-get-category (match-beginning 0))
  5372. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5373. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5374. (when (string-match "\\]" timestr)
  5375. ;; substring should only run to end of time stamp
  5376. (setq rest (substring timestr (match-end 0))
  5377. timestr (substring timestr 0 (match-end 0)))
  5378. (if (and (not closedp) (not statep)
  5379. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5380. rest))
  5381. (progn (setq timestr (concat (substring timestr 0 -1)
  5382. "-" (match-string 1 rest) "]"))
  5383. (setq clocked (match-string 2 rest)))
  5384. (setq clocked "-")))
  5385. (save-excursion
  5386. (setq extra
  5387. (cond
  5388. ((not org-agenda-log-mode-add-notes) nil)
  5389. (statep
  5390. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5391. (match-string 1)))
  5392. (clockp
  5393. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5394. (match-string 1)))))
  5395. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5396. (throw :skip nil)
  5397. (goto-char (match-beginning 0))
  5398. (setq hdmarker (org-agenda-new-marker)
  5399. inherited-tags
  5400. (or (eq org-agenda-show-inherited-tags 'always)
  5401. (and (listp org-agenda-show-inherited-tags)
  5402. (memq 'todo org-agenda-show-inherited-tags))
  5403. (and (eq org-agenda-show-inherited-tags t)
  5404. (or (eq org-agenda-use-tag-inheritance t)
  5405. (memq 'todo org-agenda-use-tag-inheritance))))
  5406. tags (org-get-tags-at nil (not inherited-tags))
  5407. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5408. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5409. (setq txt (match-string 1))
  5410. (when extra
  5411. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5412. (setq txt (concat (substring txt 0 (match-beginning 1))
  5413. " - " extra " " (match-string 2 txt)))
  5414. (setq txt (concat txt " - " extra))))
  5415. (setq txt (org-agenda-format-item
  5416. (cond
  5417. (closedp "Closed: ")
  5418. (statep (concat "State: (" state ")"))
  5419. (t (concat "Clocked: (" clocked ")")))
  5420. txt level category tags timestr)))
  5421. (setq priority 100000)
  5422. (org-add-props txt props
  5423. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5424. 'priority priority 'org-category category
  5425. 'org-category-position category-pos
  5426. 'level level
  5427. 'type "closed" 'date date
  5428. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5429. (push txt ee))
  5430. (goto-char (point-at-eol))))
  5431. (nreverse ee)))
  5432. (defun org-agenda-show-clocking-issues ()
  5433. "Add overlays, showing issues with clocking.
  5434. See also the user option `org-agenda-clock-consistency-checks'."
  5435. (interactive)
  5436. (let* ((org-time-clocksum-use-effort-durations nil)
  5437. (pl org-agenda-clock-consistency-checks)
  5438. (re (concat "^[ \t]*"
  5439. org-clock-string
  5440. "[ \t]+"
  5441. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5442. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5443. (tlstart 0.)
  5444. (tlend 0.)
  5445. (maxtime (org-hh:mm-string-to-minutes
  5446. (or (plist-get pl :max-duration) "24:00")))
  5447. (mintime (org-hh:mm-string-to-minutes
  5448. (or (plist-get pl :min-duration) 0)))
  5449. (maxgap (org-hh:mm-string-to-minutes
  5450. ;; default 30:00 means never complain
  5451. (or (plist-get pl :max-gap) "30:00")))
  5452. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5453. (plist-get pl :gap-ok-around)))
  5454. (def-face (or (plist-get pl :default-face)
  5455. '((:background "DarkRed") (:foreground "white"))))
  5456. issue face m te ts dt ov)
  5457. (goto-char (point-min))
  5458. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5459. (setq issue nil face def-face)
  5460. (catch 'next
  5461. (setq m (org-get-at-bol 'org-marker)
  5462. te nil ts nil)
  5463. (unless (and m (markerp m))
  5464. (setq issue "No valid clock line") (throw 'next t))
  5465. (org-with-point-at m
  5466. (save-excursion
  5467. (goto-char (point-at-bol))
  5468. (unless (looking-at re)
  5469. (error "No valid Clock line")
  5470. (throw 'next t))
  5471. (unless (match-end 3)
  5472. (setq issue "No end time"
  5473. face (or (plist-get pl :no-end-time-face) face))
  5474. (throw 'next t))
  5475. (setq ts (match-string 1)
  5476. te (match-string 3)
  5477. ts (org-float-time
  5478. (apply 'encode-time (org-parse-time-string ts)))
  5479. te (org-float-time
  5480. (apply 'encode-time (org-parse-time-string te)))
  5481. dt (- te ts))))
  5482. (cond
  5483. ((> dt (* 60 maxtime))
  5484. ;; a very long clocking chunk
  5485. (setq issue (format "Clocking interval is very long: %s"
  5486. (org-minutes-to-clocksum-string
  5487. (floor (/ (float dt) 60.))))
  5488. face (or (plist-get pl :long-face) face)))
  5489. ((< dt (* 60 mintime))
  5490. ;; a very short clocking chunk
  5491. (setq issue (format "Clocking interval is very short: %s"
  5492. (org-minutes-to-clocksum-string
  5493. (floor (/ (float dt) 60.))))
  5494. face (or (plist-get pl :short-face) face)))
  5495. ((and (> tlend 0) (< ts tlend))
  5496. ;; Two clock entries are overlapping
  5497. (setq issue (format "Clocking overlap: %d minutes"
  5498. (/ (- tlend ts) 60))
  5499. face (or (plist-get pl :overlap-face) face)))
  5500. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5501. ;; There is a gap, lets see if we need to report it
  5502. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5503. (setq issue (format "Clocking gap: %d minutes"
  5504. (/ (- ts tlend) 60))
  5505. face (or (plist-get pl :gap-face) face))))
  5506. (t nil)))
  5507. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5508. (when issue
  5509. ;; OK, there was some issue, add an overlay to show the issue
  5510. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5511. (overlay-put ov 'before-string
  5512. (concat
  5513. (org-add-props
  5514. (format "%-43s" (concat " " issue))
  5515. nil
  5516. 'face face)
  5517. "\n"))
  5518. (overlay-put ov 'evaporate t)))))
  5519. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5520. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5521. (catch 'exit
  5522. (unless ok-list
  5523. ;; there are no OK times for gaps...
  5524. (throw 'exit nil))
  5525. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5526. ;; This is more than 24 hours, so it is OK.
  5527. ;; because we have at least one OK time, that must be in the
  5528. ;; 24 hour interval.
  5529. (throw 'exit t))
  5530. ;; We have a shorter gap.
  5531. ;; Now we have to get the minute of the day when these times are
  5532. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5533. (t2dec (decode-time (seconds-to-time t2)))
  5534. ;; compute the minute on the day
  5535. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5536. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5537. (when (< min2 min1)
  5538. ;; if min2 is smaller than min1, this means it is on the next day.
  5539. ;; Wrap it to after midnight.
  5540. (setq min2 (+ min2 1440)))
  5541. ;; Now check if any of the OK times is in the gap
  5542. (mapc (lambda (x)
  5543. ;; Wrap the time to after midnight if necessary
  5544. (if (< x min1) (setq x (+ x 1440)))
  5545. ;; Check if in interval
  5546. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5547. ok-list)
  5548. ;; Nope, this gap is not OK
  5549. nil)))
  5550. (defun org-agenda-get-deadlines (&optional with-hour)
  5551. "Return the deadline information for agenda display.
  5552. When WITH-HOUR is non-nil, only return deadlines with an hour
  5553. specification like [h]h:mm."
  5554. (let* ((props (list 'mouse-face 'highlight
  5555. 'org-not-done-regexp org-not-done-regexp
  5556. 'org-todo-regexp org-todo-regexp
  5557. 'org-complex-heading-regexp org-complex-heading-regexp
  5558. 'help-echo
  5559. (format "mouse-2 or RET jump to org file %s"
  5560. (abbreviate-file-name buffer-file-name))))
  5561. (regexp (if with-hour
  5562. org-deadline-time-hour-regexp
  5563. org-deadline-time-regexp))
  5564. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5565. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5566. (dl0 (car org-agenda-deadline-leaders))
  5567. (dl1 (nth 1 org-agenda-deadline-leaders))
  5568. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5569. d2 diff dfrac wdays pos pos1 category category-pos level
  5570. tags suppress-prewarning ee txt head face s todo-state
  5571. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5572. (goto-char (point-min))
  5573. (while (re-search-forward regexp nil t)
  5574. (catch :skip
  5575. (org-agenda-skip)
  5576. (setq s (match-string 1)
  5577. txt nil
  5578. pos (1- (match-beginning 1))
  5579. todo-state (save-match-data (org-get-todo-state))
  5580. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5581. (member todo-state
  5582. org-agenda-repeating-timestamp-show-all))
  5583. d2 (org-time-string-to-absolute
  5584. s d1 'past show-all (current-buffer) pos)
  5585. diff (- d2 d1))
  5586. (setq suppress-prewarning
  5587. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5588. (let ((item (buffer-substring (point-at-bol)
  5589. (point-at-eol))))
  5590. (save-match-data
  5591. (and (string-match
  5592. org-scheduled-time-regexp item)
  5593. (match-string 1 item)))))))
  5594. (cond
  5595. ((not ds) nil)
  5596. ;; The current item has a scheduled date (in ds), so
  5597. ;; evaluate its prewarning lead time.
  5598. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5599. ;; Use global prewarning-restart lead time.
  5600. org-agenda-skip-deadline-prewarning-if-scheduled)
  5601. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5602. 'pre-scheduled)
  5603. ;; Set prewarning to no earlier than scheduled.
  5604. (min (- d2 (org-time-string-to-absolute
  5605. ds d1 'past show-all (current-buffer) pos))
  5606. org-deadline-warning-days))
  5607. ;; Set prewarning to deadline.
  5608. (t 0))))
  5609. (setq wdays (if suppress-prewarning
  5610. (let ((org-deadline-warning-days suppress-prewarning))
  5611. (org-get-wdays s))
  5612. (org-get-wdays s))
  5613. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5614. upcomingp (and todayp (> diff 0)))
  5615. ;; When to show a deadline in the calendar:
  5616. ;; If the expiration is within wdays warning time.
  5617. ;; Past-due deadlines are only shown on the current date
  5618. (if (and (or (and (<= diff wdays)
  5619. (and todayp (not org-agenda-only-exact-dates)))
  5620. (= diff 0)))
  5621. (save-excursion
  5622. ;; (setq todo-state (org-get-todo-state))
  5623. (setq donep (member todo-state org-done-keywords))
  5624. (if (and donep
  5625. (or org-agenda-skip-deadline-if-done
  5626. (not (= diff 0))))
  5627. (setq txt nil)
  5628. (setq category (org-get-category)
  5629. warntime (get-text-property (point) 'org-appt-warntime)
  5630. category-pos (get-text-property (point) 'org-category-position))
  5631. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5632. (throw :skip nil)
  5633. (goto-char (match-end 0))
  5634. (setq pos1 (match-beginning 0))
  5635. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5636. (setq inherited-tags
  5637. (or (eq org-agenda-show-inherited-tags 'always)
  5638. (and (listp org-agenda-show-inherited-tags)
  5639. (memq 'agenda org-agenda-show-inherited-tags))
  5640. (and (eq org-agenda-show-inherited-tags t)
  5641. (or (eq org-agenda-use-tag-inheritance t)
  5642. (memq 'agenda org-agenda-use-tag-inheritance))))
  5643. tags (org-get-tags-at pos1 (not inherited-tags)))
  5644. (setq head (buffer-substring
  5645. (point)
  5646. (progn (skip-chars-forward "^\r\n")
  5647. (point))))
  5648. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5649. (setq timestr
  5650. (concat (substring s (match-beginning 1)) " "))
  5651. (setq timestr 'time))
  5652. (setq txt (org-agenda-format-item
  5653. (cond ((= diff 0) dl0)
  5654. ((> diff 0)
  5655. (if (functionp dl1)
  5656. (funcall dl1 diff date)
  5657. (format dl1 diff)))
  5658. (t
  5659. (if (functionp dl2)
  5660. (funcall dl2 diff date)
  5661. (format dl2 (if (string= dl2 dl1)
  5662. diff (abs diff))))))
  5663. head level category tags
  5664. (if (not (= diff 0)) nil timestr)))))
  5665. (when txt
  5666. (setq face (org-agenda-deadline-face dfrac))
  5667. (org-add-props txt props
  5668. 'org-marker (org-agenda-new-marker pos)
  5669. 'warntime warntime
  5670. 'level level
  5671. 'ts-date d2
  5672. 'org-hd-marker (org-agenda-new-marker pos1)
  5673. 'priority (+ (- diff)
  5674. (org-get-priority txt))
  5675. 'org-category category
  5676. 'org-category-position category-pos
  5677. 'todo-state todo-state
  5678. 'type (if upcomingp "upcoming-deadline" "deadline")
  5679. 'date (if upcomingp date d2)
  5680. 'face (if donep 'org-agenda-done face)
  5681. 'undone-face face 'done-face 'org-agenda-done)
  5682. (push txt ee))))))
  5683. (nreverse ee)))
  5684. (defun org-agenda-deadline-face (fraction)
  5685. "Return the face to displaying a deadline item.
  5686. FRACTION is what fraction of the head-warning time has passed."
  5687. (let ((faces org-agenda-deadline-faces) f)
  5688. (catch 'exit
  5689. (while (setq f (pop faces))
  5690. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5691. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5692. "Return the scheduled information for agenda display.
  5693. When WITH-HOUR is non-nil, only return scheduled items with
  5694. an hour specification like [h]h:mm."
  5695. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5696. 'org-todo-regexp org-todo-regexp
  5697. 'org-complex-heading-regexp org-complex-heading-regexp
  5698. 'done-face 'org-agenda-done
  5699. 'mouse-face 'highlight
  5700. 'help-echo
  5701. (format "mouse-2 or RET jump to org file %s"
  5702. (abbreviate-file-name buffer-file-name))))
  5703. (regexp (if with-hour
  5704. org-scheduled-time-hour-regexp
  5705. org-scheduled-time-regexp))
  5706. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5707. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5708. mm
  5709. (deadline-position-alist
  5710. (mapcar (lambda (a) (and (setq mm (get-text-property
  5711. 0 'org-hd-marker a))
  5712. (cons (marker-position mm) a)))
  5713. deadline-results))
  5714. d2 diff pos pos1 category category-pos level tags donep
  5715. ee txt head pastschedp todo-state face timestr s habitp show-all
  5716. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5717. ddays)
  5718. (goto-char (point-min))
  5719. (while (re-search-forward regexp nil t)
  5720. (catch :skip
  5721. (org-agenda-skip)
  5722. (setq s (match-string 1)
  5723. txt nil
  5724. pos (1- (match-beginning 1))
  5725. todo-state (save-match-data (org-get-todo-state))
  5726. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5727. (member todo-state
  5728. org-agenda-repeating-timestamp-show-all))
  5729. d2 (org-time-string-to-absolute
  5730. s d1 'past show-all (current-buffer) pos)
  5731. diff (- d2 d1)
  5732. warntime (get-text-property (point) 'org-appt-warntime))
  5733. (setq pastschedp (and todayp (< diff 0)))
  5734. (setq did-habit-check-p nil)
  5735. (setq suppress-delay
  5736. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5737. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5738. (save-match-data
  5739. (and (string-match
  5740. org-deadline-time-regexp item)
  5741. (match-string 1 item)))))))
  5742. (cond
  5743. ((not ds) nil)
  5744. ;; The current item has a deadline date (in ds), so
  5745. ;; evaluate its delay time.
  5746. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5747. ;; Use global delay time.
  5748. (- org-agenda-skip-scheduled-delay-if-deadline))
  5749. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5750. 'post-deadline)
  5751. ;; Set delay to no later than deadline.
  5752. (min (- d2 (org-time-string-to-absolute
  5753. ds d1 'past show-all (current-buffer) pos))
  5754. org-scheduled-delay-days))
  5755. (t 0))))
  5756. (setq ddays (if suppress-delay
  5757. (let ((org-scheduled-delay-days suppress-delay))
  5758. (org-get-wdays s t t))
  5759. (org-get-wdays s t)))
  5760. ;; Use a delay of 0 when there is a repeater and the delay is
  5761. ;; of the form --3d
  5762. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5763. (< (org-time-string-to-absolute s)
  5764. (org-time-string-to-absolute
  5765. s d2 'past nil (current-buffer) pos)))
  5766. (setq ddays 0))
  5767. ;; When to show a scheduled item in the calendar:
  5768. ;; If it is on or past the date.
  5769. (when (or (and (> ddays 0) (= diff (- ddays)))
  5770. (and (zerop ddays) (= diff 0))
  5771. (and (< (+ diff ddays) 0)
  5772. (< (abs diff) org-scheduled-past-days)
  5773. (and todayp (not org-agenda-only-exact-dates)))
  5774. ;; org-is-habit-p uses org-entry-get, which is expansive
  5775. ;; so we go extra mile to only call it once
  5776. (and todayp
  5777. (boundp 'org-habit-show-all-today)
  5778. org-habit-show-all-today
  5779. (setq did-habit-check-p t)
  5780. (setq habitp (and (functionp 'org-is-habit-p)
  5781. (org-is-habit-p)))))
  5782. (save-excursion
  5783. (setq donep (member todo-state org-done-keywords))
  5784. (if (and donep
  5785. (or org-agenda-skip-scheduled-if-done
  5786. (not (= diff 0))
  5787. (and (functionp 'org-is-habit-p)
  5788. (org-is-habit-p))))
  5789. (setq txt nil)
  5790. (setq habitp (if did-habit-check-p habitp
  5791. (and (functionp 'org-is-habit-p)
  5792. (org-is-habit-p))))
  5793. (setq category (org-get-category)
  5794. category-pos (get-text-property (point) 'org-category-position))
  5795. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5796. 'repeated-after-deadline)
  5797. (org-get-deadline-time (point))
  5798. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5799. (throw :skip nil))
  5800. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5801. (throw :skip nil)
  5802. (goto-char (match-end 0))
  5803. (setq pos1 (match-beginning 0))
  5804. (if habitp
  5805. (if (or (not org-habit-show-habits)
  5806. (and (not todayp)
  5807. (boundp 'org-habit-show-habits-only-for-today)
  5808. org-habit-show-habits-only-for-today))
  5809. (throw :skip nil))
  5810. (if (and
  5811. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5812. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5813. pastschedp))
  5814. (setq mm (assoc pos1 deadline-position-alist)))
  5815. (throw :skip nil)))
  5816. (setq inherited-tags
  5817. (or (eq org-agenda-show-inherited-tags 'always)
  5818. (and (listp org-agenda-show-inherited-tags)
  5819. (memq 'agenda org-agenda-show-inherited-tags))
  5820. (and (eq org-agenda-show-inherited-tags t)
  5821. (or (eq org-agenda-use-tag-inheritance t)
  5822. (memq 'agenda org-agenda-use-tag-inheritance))))
  5823. tags (org-get-tags-at nil (not inherited-tags)))
  5824. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5825. (setq head (buffer-substring
  5826. (point)
  5827. (progn (skip-chars-forward "^\r\n") (point))))
  5828. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5829. (setq timestr
  5830. (concat (substring s (match-beginning 1)) " "))
  5831. (setq timestr 'time))
  5832. (setq txt (org-agenda-format-item
  5833. (if (= diff 0)
  5834. (car org-agenda-scheduled-leaders)
  5835. (format (nth 1 org-agenda-scheduled-leaders)
  5836. (- 1 diff)))
  5837. head level category tags
  5838. (if (not (= diff 0)) nil timestr)
  5839. nil habitp))))
  5840. (when txt
  5841. (setq face
  5842. (cond
  5843. ((and (not habitp) pastschedp)
  5844. 'org-scheduled-previously)
  5845. (todayp 'org-scheduled-today)
  5846. (t 'org-scheduled))
  5847. habitp (and habitp (org-habit-parse-todo)))
  5848. (org-add-props txt props
  5849. 'undone-face face
  5850. 'face (if donep 'org-agenda-done face)
  5851. 'org-marker (org-agenda-new-marker pos)
  5852. 'org-hd-marker (org-agenda-new-marker pos1)
  5853. 'type (if pastschedp "past-scheduled" "scheduled")
  5854. 'date (if pastschedp d2 date)
  5855. 'ts-date d2
  5856. 'warntime warntime
  5857. 'level level
  5858. 'priority (if habitp
  5859. (org-habit-get-priority habitp)
  5860. (+ 94 (- 5 diff) (org-get-priority txt)))
  5861. 'org-category category
  5862. 'category-position category-pos
  5863. 'org-habit-p habitp
  5864. 'todo-state todo-state)
  5865. (push txt ee))))))
  5866. (nreverse ee)))
  5867. (defun org-agenda-get-blocks ()
  5868. "Return the date-range information for agenda display."
  5869. (let* ((props (list 'face nil
  5870. 'org-not-done-regexp org-not-done-regexp
  5871. 'org-todo-regexp org-todo-regexp
  5872. 'org-complex-heading-regexp org-complex-heading-regexp
  5873. 'mouse-face 'highlight
  5874. 'help-echo
  5875. (format "mouse-2 or RET jump to org file %s"
  5876. (abbreviate-file-name buffer-file-name))))
  5877. (regexp org-tr-regexp)
  5878. (d0 (calendar-absolute-from-gregorian date))
  5879. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5880. level todo-state tags pos head donep inherited-tags)
  5881. (goto-char (point-min))
  5882. (while (re-search-forward regexp nil t)
  5883. (catch :skip
  5884. (org-agenda-skip)
  5885. (setq pos (point))
  5886. (let ((start-time (match-string 1))
  5887. (end-time (match-string 2)))
  5888. (setq s1 (match-string 1)
  5889. s2 (match-string 2)
  5890. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5891. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5892. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5893. ;; Only allow days between the limits, because the normal
  5894. ;; date stamps will catch the limits.
  5895. (save-excursion
  5896. (setq todo-state (org-get-todo-state))
  5897. (setq donep (member todo-state org-done-keywords))
  5898. (if (and donep org-agenda-skip-timestamp-if-done)
  5899. (throw :skip t))
  5900. (setq marker (org-agenda-new-marker (point)))
  5901. (setq category (org-get-category)
  5902. category-pos (get-text-property (point) 'org-category-position))
  5903. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5904. (throw :skip nil)
  5905. (goto-char (match-beginning 0))
  5906. (setq hdmarker (org-agenda-new-marker (point))
  5907. inherited-tags
  5908. (or (eq org-agenda-show-inherited-tags 'always)
  5909. (and (listp org-agenda-show-inherited-tags)
  5910. (memq 'agenda org-agenda-show-inherited-tags))
  5911. (and (eq org-agenda-show-inherited-tags t)
  5912. (or (eq org-agenda-use-tag-inheritance t)
  5913. (memq 'agenda org-agenda-use-tag-inheritance))))
  5914. tags (org-get-tags-at nil (not inherited-tags)))
  5915. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5916. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5917. (setq head (match-string 1))
  5918. (let ((remove-re
  5919. (if org-agenda-remove-timeranges-from-blocks
  5920. (concat
  5921. "<" (regexp-quote s1) ".*?>"
  5922. "--"
  5923. "<" (regexp-quote s2) ".*?>")
  5924. nil)))
  5925. (setq txt (org-agenda-format-item
  5926. (format
  5927. (nth (if (= d1 d2) 0 1)
  5928. org-agenda-timerange-leaders)
  5929. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5930. head level category tags
  5931. (cond ((and (= d1 d0) (= d2 d0))
  5932. (concat "<" start-time ">--<" end-time ">"))
  5933. ((= d1 d0)
  5934. (concat "<" start-time ">"))
  5935. ((= d2 d0)
  5936. (concat "<" end-time ">")))
  5937. remove-re))))
  5938. (org-add-props txt props
  5939. 'org-marker marker 'org-hd-marker hdmarker
  5940. 'type "block" 'date date
  5941. 'level level
  5942. 'todo-state todo-state
  5943. 'priority (org-get-priority txt) 'org-category category
  5944. 'org-category-position category-pos)
  5945. (push txt ee))))
  5946. (goto-char pos)))
  5947. ;; Sort the entries by expiration date.
  5948. (nreverse ee)))
  5949. ;;; Agenda presentation and sorting
  5950. (defvar org-prefix-has-time nil
  5951. "A flag, set by `org-compile-prefix-format'.
  5952. The flag is set if the currently compiled format contains a `%t'.")
  5953. (defvar org-prefix-has-tag nil
  5954. "A flag, set by `org-compile-prefix-format'.
  5955. The flag is set if the currently compiled format contains a `%T'.")
  5956. (defvar org-prefix-has-effort nil
  5957. "A flag, set by `org-compile-prefix-format'.
  5958. The flag is set if the currently compiled format contains a `%e'.")
  5959. (defvar org-prefix-has-breadcrumbs nil
  5960. "A flag, set by `org-compile-prefix-format'.
  5961. The flag is set if the currently compiled format contains a `%b'.")
  5962. (defvar org-prefix-category-length nil
  5963. "Used by `org-compile-prefix-format' to remember the category field width.")
  5964. (defvar org-prefix-category-max-length nil
  5965. "Used by `org-compile-prefix-format' to remember the category field width.")
  5966. (defun org-agenda-get-category-icon (category)
  5967. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5968. (dolist (entry org-agenda-category-icon-alist)
  5969. (when (org-string-match-p (car entry) category)
  5970. (if (listp (cadr entry))
  5971. (return (cadr entry))
  5972. (return (apply 'create-image (cdr entry)))))))
  5973. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5974. remove-re habitp)
  5975. "Format TXT to be inserted into the agenda buffer.
  5976. In particular, add the prefix and corresponding text properties.
  5977. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5978. LEVEL may be a string to replace the `%l' specifier.
  5979. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5980. category taken from local variable or file name. It will replace the `%c'
  5981. specifier in the format.
  5982. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5983. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5984. When DOTIME is a string, this string is searched for a time before TXT is.
  5985. TAGS can be the tags of the headline.
  5986. Any match of REMOVE-RE will be removed from TXT."
  5987. ;; We keep the org-prefix-* variable values along with a compiled
  5988. ;; formatter, so that multiple agendas existing at the same time do
  5989. ;; not step on each other toes.
  5990. ;;
  5991. ;; It was inconvenient to make these variables buffer local in
  5992. ;; Agenda buffers, because this function expects to be called with
  5993. ;; the buffer where item comes from being current, and not agenda
  5994. ;; buffer
  5995. (let* ((bindings (car org-prefix-format-compiled))
  5996. (formatter (cadr org-prefix-format-compiled)))
  5997. (loop for (var value) in bindings
  5998. do (set var value))
  5999. (save-match-data
  6000. ;; Diary entries sometimes have extra whitespace at the beginning
  6001. (setq txt (org-trim txt))
  6002. ;; Fix the tags part in txt
  6003. (setq txt (org-agenda-fix-displayed-tags
  6004. txt tags
  6005. org-agenda-show-inherited-tags
  6006. org-agenda-hide-tags-regexp))
  6007. (let* ((category (or category
  6008. (if (stringp org-category)
  6009. org-category
  6010. (and org-category (symbol-name org-category)))
  6011. (if buffer-file-name
  6012. (file-name-sans-extension
  6013. (file-name-nondirectory buffer-file-name))
  6014. "")))
  6015. (category-icon (org-agenda-get-category-icon category))
  6016. (category-icon (if category-icon
  6017. (propertize " " 'display category-icon)
  6018. ""))
  6019. ;; time, tag, effort are needed for the eval of the prefix format
  6020. (tag (if tags (nth (1- (length tags)) tags) ""))
  6021. time effort neffort
  6022. (ts (if dotime (concat
  6023. (if (stringp dotime) dotime "")
  6024. (and org-agenda-search-headline-for-time txt))))
  6025. (time-of-day (and dotime (org-get-time-of-day ts)))
  6026. stamp plain s0 s1 s2 rtn srp l
  6027. duration thecategory breadcrumbs)
  6028. (and (derived-mode-p 'org-mode) buffer-file-name
  6029. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6030. (when (and dotime time-of-day)
  6031. ;; Extract starting and ending time and move them to prefix
  6032. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6033. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6034. (setq s0 (match-string 0 ts)
  6035. srp (and stamp (match-end 3))
  6036. s1 (match-string (if plain 1 2) ts)
  6037. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6038. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6039. ;; them, we might want to remove them there to avoid duplication.
  6040. ;; The user can turn this off with a variable.
  6041. (if (and org-prefix-has-time
  6042. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6043. (string-match (concat (regexp-quote s0) " *") txt)
  6044. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6045. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6046. (= (match-beginning 0) 0)
  6047. t))
  6048. (setq txt (replace-match "" nil nil txt))))
  6049. ;; Normalize the time(s) to 24 hour
  6050. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6051. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6052. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6053. (let (org-time-clocksum-use-effort-durations)
  6054. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6055. (setq s2
  6056. (org-minutes-to-clocksum-string
  6057. (+ (org-hh:mm-string-to-minutes s1)
  6058. org-agenda-default-appointment-duration)))))
  6059. ;; Compute the duration
  6060. (when s2
  6061. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6062. (org-hh:mm-string-to-minutes s1)))))
  6063. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6064. txt)
  6065. ;; Tags are in the string
  6066. (if (or (eq org-agenda-remove-tags t)
  6067. (and org-agenda-remove-tags
  6068. org-prefix-has-tag))
  6069. (setq txt (replace-match "" t t txt))
  6070. (setq txt (replace-match
  6071. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6072. (match-string 2 txt))
  6073. t t txt))))
  6074. (when (derived-mode-p 'org-mode)
  6075. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6076. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6077. ;; current buffer, so move this check outside of above
  6078. (if effort
  6079. (setq neffort (org-duration-string-to-minutes effort)
  6080. effort (setq effort (concat "[" effort "]")))
  6081. ;; prevent erroring out with %e format when there is no effort
  6082. (setq effort ""))
  6083. (when remove-re
  6084. (while (string-match remove-re txt)
  6085. (setq txt (replace-match "" t t txt))))
  6086. ;; Set org-heading property on `txt' to mark the start of the
  6087. ;; heading.
  6088. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6089. ;; Prepare the variables needed in the eval of the compiled format
  6090. (if org-prefix-has-breadcrumbs
  6091. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6092. (let ((s (org-display-outline-path nil nil "->" t)))
  6093. (if (eq "" s) "" (concat s "->"))))))
  6094. (setq time (cond (s2 (concat
  6095. (org-agenda-time-of-day-to-ampm-maybe s1)
  6096. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6097. (if org-agenda-timegrid-use-ampm " ")))
  6098. (s1 (concat
  6099. (org-agenda-time-of-day-to-ampm-maybe s1)
  6100. (if org-agenda-timegrid-use-ampm
  6101. "........ "
  6102. "......")))
  6103. (t ""))
  6104. extra (or (and (not habitp) extra) "")
  6105. category (if (symbolp category) (symbol-name category) category)
  6106. thecategory (copy-sequence category)
  6107. level (or level ""))
  6108. (if (string-match org-bracket-link-regexp category)
  6109. (progn
  6110. (setq l (if (match-end 3)
  6111. (- (match-end 3) (match-beginning 3))
  6112. (- (match-end 1) (match-beginning 1))))
  6113. (when (< l (or org-prefix-category-length 0))
  6114. (setq category (copy-sequence category))
  6115. (org-add-props category nil
  6116. 'extra-space (make-string
  6117. (- org-prefix-category-length l 1) ?\ ))))
  6118. (if (and org-prefix-category-max-length
  6119. (>= (length category) org-prefix-category-max-length))
  6120. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6121. ;; Evaluate the compiled format
  6122. (setq rtn (concat (eval formatter) txt))
  6123. ;; And finally add the text properties
  6124. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6125. (org-add-props rtn nil
  6126. 'org-category (if thecategory (downcase thecategory) category)
  6127. 'tags (mapcar 'org-downcase-keep-props tags)
  6128. 'org-highest-priority org-highest-priority
  6129. 'org-lowest-priority org-lowest-priority
  6130. 'time-of-day time-of-day
  6131. 'duration duration
  6132. 'effort effort
  6133. 'effort-minutes neffort
  6134. 'breadcrumbs breadcrumbs
  6135. 'txt txt
  6136. 'level level
  6137. 'time time
  6138. 'extra extra
  6139. 'format org-prefix-format-compiled
  6140. 'dotime dotime)))))
  6141. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6142. "Remove tags string from TXT, and add a modified list of tags.
  6143. The modified list may contain inherited tags, and tags matched by
  6144. `org-agenda-hide-tags-regexp' will be removed."
  6145. (when (or add-inherited hide-re)
  6146. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6147. (setq txt (substring txt 0 (match-beginning 0))))
  6148. (setq tags
  6149. (delq nil
  6150. (mapcar (lambda (tg)
  6151. (if (or (and hide-re (string-match hide-re tg))
  6152. (and (not add-inherited)
  6153. (get-text-property 0 'inherited tg)))
  6154. nil
  6155. tg))
  6156. tags)))
  6157. (when tags
  6158. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6159. i)
  6160. (setq txt (concat txt " :"
  6161. (mapconcat
  6162. (lambda (x)
  6163. (setq i (get-text-property 0 'inherited x))
  6164. (if (and have-i (not i))
  6165. (progn
  6166. (setq have-i nil)
  6167. (concat ":" x))
  6168. x))
  6169. tags ":")
  6170. (if have-i "::" ":"))))))
  6171. txt)
  6172. (defun org-downcase-keep-props (s)
  6173. (let ((props (text-properties-at 0 s)))
  6174. (setq s (downcase s))
  6175. (add-text-properties 0 (length s) props s)
  6176. s))
  6177. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6178. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6179. "Add a time-grid for agenda items which need it.
  6180. LIST is the list of agenda items formatted by `org-agenda-list'.
  6181. NDAYS is the span of the current agenda view.
  6182. TODAYP is `t' when the current agenda view is on today."
  6183. (catch 'exit
  6184. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6185. ((and todayp (member 'today (car org-agenda-time-grid))))
  6186. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6187. ((member 'weekly (car org-agenda-time-grid)))
  6188. (t (throw 'exit list)))
  6189. (let* ((have (delq nil (mapcar
  6190. (lambda (x) (get-text-property 1 'time-of-day x))
  6191. list)))
  6192. (string (nth 1 org-agenda-time-grid))
  6193. (gridtimes (nth 2 org-agenda-time-grid))
  6194. (req (car org-agenda-time-grid))
  6195. (remove (member 'remove-match req))
  6196. new time)
  6197. (if (and (member 'require-timed req) (not have))
  6198. ;; don't show empty grid
  6199. (throw 'exit list))
  6200. (while (setq time (pop gridtimes))
  6201. (unless (and remove (member time have))
  6202. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6203. (push (org-agenda-format-item
  6204. nil string nil "" nil
  6205. (concat (substring time 0 -2) ":" (substring time -2)))
  6206. new)
  6207. (put-text-property
  6208. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6209. (when (and todayp org-agenda-show-current-time-in-grid)
  6210. (push (org-agenda-format-item
  6211. nil org-agenda-current-time-string nil "" nil
  6212. (format-time-string "%H:%M "))
  6213. new)
  6214. (put-text-property
  6215. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6216. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6217. (append new list)
  6218. (append list new)))))
  6219. (defun org-compile-prefix-format (key)
  6220. "Compile the prefix format into a Lisp form that can be evaluated.
  6221. The resulting form and associated variable bindings is returned
  6222. and stored in the variable `org-prefix-format-compiled'."
  6223. (setq org-prefix-has-time nil
  6224. org-prefix-has-tag nil
  6225. org-prefix-category-length nil
  6226. org-prefix-has-effort nil
  6227. org-prefix-has-breadcrumbs nil)
  6228. (let ((s (cond
  6229. ((stringp org-agenda-prefix-format)
  6230. org-agenda-prefix-format)
  6231. ((assq key org-agenda-prefix-format)
  6232. (cdr (assq key org-agenda-prefix-format)))
  6233. (t " %-12:c%?-12t% s")))
  6234. (start 0)
  6235. varform vars var e c f opt)
  6236. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6237. s start)
  6238. (setq var (or (cdr (assoc (match-string 4 s)
  6239. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6240. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6241. 'eval)
  6242. c (or (match-string 3 s) "")
  6243. opt (match-beginning 1)
  6244. start (1+ (match-beginning 0)))
  6245. (if (equal var 'time) (setq org-prefix-has-time t))
  6246. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6247. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6248. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6249. (setq f (concat "%" (match-string 2 s) "s"))
  6250. (when (equal var 'category)
  6251. (setq org-prefix-category-length
  6252. (floor (abs (string-to-number (match-string 2 s)))))
  6253. (setq org-prefix-category-max-length
  6254. (let ((x (match-string 2 s)))
  6255. (save-match-data
  6256. (if (string-match "\\.[0-9]+" x)
  6257. (string-to-number (substring (match-string 0 x) 1)))))))
  6258. (if (eq var 'eval)
  6259. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6260. (if opt
  6261. (setq varform
  6262. `(if (equal "" ,var)
  6263. ""
  6264. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6265. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6266. (setq s (replace-match "%s" t nil s))
  6267. (push varform vars))
  6268. (setq vars (nreverse vars))
  6269. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6270. (setq org-prefix-format-compiled
  6271. (list
  6272. `((org-prefix-has-time ,org-prefix-has-time)
  6273. (org-prefix-has-tag ,org-prefix-has-tag)
  6274. (org-prefix-category-length ,org-prefix-category-length)
  6275. (org-prefix-has-effort ,org-prefix-has-effort)
  6276. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6277. `(format ,s ,@vars))))))
  6278. (defun org-set-sorting-strategy (key)
  6279. (if (symbolp (car org-agenda-sorting-strategy))
  6280. ;; the old format
  6281. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6282. (setq org-agenda-sorting-strategy-selected
  6283. (or (cdr (assq key org-agenda-sorting-strategy))
  6284. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6285. '(time-up category-keep priority-down)))))
  6286. (defun org-get-time-of-day (s &optional string mod24)
  6287. "Check string S for a time of day.
  6288. If found, return it as a military time number between 0 and 2400.
  6289. If not found, return nil.
  6290. The optional STRING argument forces conversion into a 5 character wide string
  6291. HH:MM."
  6292. (save-match-data
  6293. (when
  6294. (and
  6295. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6296. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6297. (not (eq (get-text-property 1 'face s) 'org-link)))
  6298. (let* ((h (string-to-number (match-string 1 s)))
  6299. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6300. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6301. (am-p (equal ampm "am"))
  6302. (h1 (cond ((not ampm) h)
  6303. ((= h 12) (if am-p 0 12))
  6304. (t (+ h (if am-p 0 12)))))
  6305. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6306. (mod h1 24) h1))
  6307. (t0 (+ (* 100 h2) m))
  6308. (t1 (concat (if (>= h1 24) "+" " ")
  6309. (if (and org-agenda-time-leading-zero
  6310. (< t0 1000)) "0" "")
  6311. (if (< t0 100) "0" "")
  6312. (if (< t0 10) "0" "")
  6313. (int-to-string t0))))
  6314. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6315. (defvar org-agenda-before-sorting-filter-function nil
  6316. "Function to be applied to agenda items prior to sorting.
  6317. Prior to sorting also means just before they are inserted into the agenda.
  6318. To aid sorting, you may revisit the original entries and add more text
  6319. properties which will later be used by the sorting functions.
  6320. The function should take a string argument, an agenda line.
  6321. It has access to the text properties in that line, which contain among
  6322. other things, the property `org-hd-marker' that points to the entry
  6323. where the line comes from. Note that not all lines going into the agenda
  6324. have this property, only most.
  6325. The function should return the modified string. It is probably best
  6326. to ONLY change text properties.
  6327. You can also use this function as a filter, by returning nil for lines
  6328. you don't want to have in the agenda at all. For this application, you
  6329. could bind the variable in the options section of a custom command.")
  6330. (defun org-agenda-finalize-entries (list &optional type)
  6331. "Sort, limit and concatenate the LIST of agenda items.
  6332. The optional argument TYPE tells the agenda type."
  6333. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6334. (cdr (assoc type org-agenda-max-effort)))
  6335. (t org-agenda-max-effort)))
  6336. (max-todo (cond ((listp org-agenda-max-todos)
  6337. (cdr (assoc type org-agenda-max-todos)))
  6338. (t org-agenda-max-todos)))
  6339. (max-tags (cond ((listp org-agenda-max-tags)
  6340. (cdr (assoc type org-agenda-max-tags)))
  6341. (t org-agenda-max-tags)))
  6342. (max-entries (cond ((listp org-agenda-max-entries)
  6343. (cdr (assoc type org-agenda-max-entries)))
  6344. (t org-agenda-max-entries))) l)
  6345. (when org-agenda-before-sorting-filter-function
  6346. (setq list
  6347. (delq nil
  6348. (mapcar
  6349. org-agenda-before-sorting-filter-function list))))
  6350. (setq list (mapcar 'org-agenda-highlight-todo list)
  6351. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6352. (when max-effort
  6353. (setq list (org-agenda-limit-entries
  6354. list 'effort-minutes max-effort 'identity)))
  6355. (when max-todo
  6356. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6357. (when max-tags
  6358. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6359. (when max-entries
  6360. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6361. (mapconcat 'identity list "\n")))
  6362. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6363. "Limit the number of agenda entries."
  6364. (let ((include (and limit (< limit 0))))
  6365. (if limit
  6366. (let ((fun (or fn (lambda (p) (if p 1))))
  6367. (lim 0))
  6368. (delq nil
  6369. (mapcar
  6370. (lambda (e)
  6371. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6372. (if pval (setq lim (+ lim pval)))
  6373. (cond ((and pval (<= lim (abs limit))) e)
  6374. ((and include (not pval)) e))))
  6375. list)))
  6376. list)))
  6377. (defun org-agenda-limit-interactively ()
  6378. "In agenda, interactively limit entries to various maximums."
  6379. (interactive)
  6380. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6381. (num (string-to-number (read-from-minibuffer "How many? "))))
  6382. (cond ((equal max ?e)
  6383. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6384. ((equal max ?t)
  6385. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6386. ((equal max ?T)
  6387. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6388. ((equal max ?E)
  6389. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6390. (org-agenda-fit-window-to-buffer))
  6391. (defun org-agenda-highlight-todo (x)
  6392. (let ((org-done-keywords org-done-keywords-for-agenda)
  6393. (case-fold-search nil)
  6394. re)
  6395. (if (eq x 'line)
  6396. (save-excursion
  6397. (beginning-of-line 1)
  6398. (setq re (org-get-at-bol 'org-todo-regexp))
  6399. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6400. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6401. (add-text-properties (match-beginning 0) (match-end 1)
  6402. (list 'face (org-get-todo-face 1)))
  6403. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6404. (delete-region (match-beginning 1) (1- (match-end 0)))
  6405. (goto-char (match-beginning 1))
  6406. (insert (format org-agenda-todo-keyword-format s)))))
  6407. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6408. (setq re (get-text-property 0 'org-todo-regexp x))
  6409. (when (and re
  6410. ;; Test `pl' because if there's no heading content,
  6411. ;; there's no point matching to highlight. Note
  6412. ;; that if we didn't test `pl' first, and there
  6413. ;; happened to be no keyword from `org-todo-regexp'
  6414. ;; on this heading line, then the `equal' comparison
  6415. ;; afterwards would spuriously succeed in the case
  6416. ;; where `pl' is nil -- causing an args-out-of-range
  6417. ;; error when we try to add text properties to text
  6418. ;; that isn't there.
  6419. pl
  6420. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6421. x pl) pl))
  6422. (add-text-properties
  6423. (or (match-end 1) (match-end 0)) (match-end 0)
  6424. (list 'face (org-get-todo-face (match-string 2 x)))
  6425. x)
  6426. (when (match-end 1)
  6427. (setq x (concat (substring x 0 (match-end 1))
  6428. (format org-agenda-todo-keyword-format
  6429. (match-string 2 x))
  6430. (org-add-props " " (text-properties-at 0 x))
  6431. (substring x (match-end 3)))))))
  6432. x)))
  6433. (defsubst org-cmp-priority (a b)
  6434. "Compare the priorities of string A and B."
  6435. (let ((pa (or (get-text-property 1 'priority a) 0))
  6436. (pb (or (get-text-property 1 'priority b) 0)))
  6437. (cond ((> pa pb) +1)
  6438. ((< pa pb) -1))))
  6439. (defsubst org-cmp-effort (a b)
  6440. "Compare the effort values of string A and B."
  6441. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6442. (ea (or (get-text-property 1 'effort-minutes a) def))
  6443. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6444. (cond ((> ea eb) +1)
  6445. ((< ea eb) -1))))
  6446. (defsubst org-cmp-category (a b)
  6447. "Compare the string values of categories of strings A and B."
  6448. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6449. (cb (or (get-text-property 1 'org-category b) "")))
  6450. (cond ((string-lessp ca cb) -1)
  6451. ((string-lessp cb ca) +1))))
  6452. (defsubst org-cmp-todo-state (a b)
  6453. "Compare the todo states of strings A and B."
  6454. (let* ((ma (or (get-text-property 1 'org-marker a)
  6455. (get-text-property 1 'org-hd-marker a)))
  6456. (mb (or (get-text-property 1 'org-marker b)
  6457. (get-text-property 1 'org-hd-marker b)))
  6458. (fa (and ma (marker-buffer ma)))
  6459. (fb (and mb (marker-buffer mb)))
  6460. (todo-kwds
  6461. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6462. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6463. (ta (or (get-text-property 1 'todo-state a) ""))
  6464. (tb (or (get-text-property 1 'todo-state b) ""))
  6465. (la (- (length (member ta todo-kwds))))
  6466. (lb (- (length (member tb todo-kwds))))
  6467. (donepa (member ta org-done-keywords-for-agenda))
  6468. (donepb (member tb org-done-keywords-for-agenda)))
  6469. (cond ((and donepa (not donepb)) -1)
  6470. ((and (not donepa) donepb) +1)
  6471. ((< la lb) -1)
  6472. ((< lb la) +1))))
  6473. (defsubst org-cmp-alpha (a b)
  6474. "Compare the headlines, alphabetically."
  6475. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6476. (plb (text-property-any 0 (length b) 'org-heading t b))
  6477. (ta (and pla (substring a pla)))
  6478. (tb (and plb (substring b plb))))
  6479. (when pla
  6480. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6481. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6482. (setq ta (substring ta (match-end 0))))
  6483. (setq ta (downcase ta)))
  6484. (when plb
  6485. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6486. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6487. (setq tb (substring tb (match-end 0))))
  6488. (setq tb (downcase tb)))
  6489. (cond ((not ta) +1)
  6490. ((not tb) -1)
  6491. ((string-lessp ta tb) -1)
  6492. ((string-lessp tb ta) +1))))
  6493. (defsubst org-cmp-tag (a b)
  6494. "Compare the string values of the first tags of A and B."
  6495. (let ((ta (car (last (get-text-property 1 'tags a))))
  6496. (tb (car (last (get-text-property 1 'tags b)))))
  6497. (cond ((not ta) +1)
  6498. ((not tb) -1)
  6499. ((string-lessp ta tb) -1)
  6500. ((string-lessp tb ta) +1))))
  6501. (defsubst org-cmp-time (a b)
  6502. "Compare the time-of-day values of strings A and B."
  6503. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6504. (ta (or (get-text-property 1 'time-of-day a) def))
  6505. (tb (or (get-text-property 1 'time-of-day b) def)))
  6506. (cond ((< ta tb) -1)
  6507. ((< tb ta) +1))))
  6508. (defsubst org-cmp-ts (a b type)
  6509. "Compare the timestamps values of entries A and B.
  6510. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6511. \"timestamp_ia\", compare within each of these type. When TYPE
  6512. is the empty string, compare all timestamps without respect of
  6513. their type."
  6514. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6515. (ta (or (and (string-match type (or (get-text-property 1 type a) ""))
  6516. (get-text-property 1 'ts-date a)) def))
  6517. (tb (or (and (string-match type (or (get-text-property 1 type b) ""))
  6518. (get-text-property 1 'ts-date b)) def)))
  6519. (cond ((< ta tb) -1)
  6520. ((< tb ta) +1))))
  6521. (defsubst org-cmp-habit-p (a b)
  6522. "Compare the todo states of strings A and B."
  6523. (let ((ha (get-text-property 1 'org-habit-p a))
  6524. (hb (get-text-property 1 'org-habit-p b)))
  6525. (cond ((and ha (not hb)) -1)
  6526. ((and (not ha) hb) +1))))
  6527. (defun org-entries-lessp (a b)
  6528. "Predicate for sorting agenda entries."
  6529. ;; The following variables will be used when the form is evaluated.
  6530. ;; So even though the compiler complains, keep them.
  6531. (let* ((ss org-agenda-sorting-strategy-selected)
  6532. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6533. (org-cmp-ts a b "")))
  6534. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6535. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6536. (org-cmp-ts a b "scheduled")))
  6537. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6538. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6539. (org-cmp-ts a b "deadline")))
  6540. (deadline-down (if deadline-up (- deadline-up) nil))
  6541. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6542. (org-cmp-ts a b "iatimestamp_ia")))
  6543. (tsia-down (if tsia-up (- tsia-up) nil))
  6544. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6545. (org-cmp-ts a b "timestamp")))
  6546. (ts-down (if ts-up (- ts-up) nil))
  6547. (time-up (and (org-em 'time-up 'time-down ss)
  6548. (org-cmp-time a b)))
  6549. (time-down (if time-up (- time-up) nil))
  6550. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6551. (org-cmp-priority a b)))
  6552. (priority-down (if priority-up (- priority-up) nil))
  6553. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6554. (org-cmp-effort a b)))
  6555. (effort-down (if effort-up (- effort-up) nil))
  6556. (category-up (and (or (org-em 'category-up 'category-down ss)
  6557. (memq 'category-keep ss))
  6558. (org-cmp-category a b)))
  6559. (category-down (if category-up (- category-up) nil))
  6560. (category-keep (if category-up +1 nil))
  6561. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6562. (org-cmp-tag a b)))
  6563. (tag-down (if tag-up (- tag-up) nil))
  6564. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6565. (org-cmp-todo-state a b)))
  6566. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6567. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6568. (org-cmp-habit-p a b)))
  6569. (habit-down (if habit-up (- habit-up) nil))
  6570. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6571. (org-cmp-alpha a b)))
  6572. (alpha-down (if alpha-up (- alpha-up) nil))
  6573. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6574. user-defined-up user-defined-down)
  6575. (if (and need-user-cmp org-agenda-cmp-user-defined
  6576. (functionp org-agenda-cmp-user-defined))
  6577. (setq user-defined-up
  6578. (funcall org-agenda-cmp-user-defined a b)
  6579. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6580. (cdr (assoc
  6581. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6582. '((-1 . t) (1 . nil) (nil . nil))))))
  6583. ;;; Agenda restriction lock
  6584. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6585. "Overlay to mark the headline to which agenda commands are restricted.")
  6586. (overlay-put org-agenda-restriction-lock-overlay
  6587. 'face 'org-agenda-restriction-lock)
  6588. (overlay-put org-agenda-restriction-lock-overlay
  6589. 'help-echo "Agendas are currently limited to this subtree.")
  6590. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6591. ;;;###autoload
  6592. (defun org-agenda-set-restriction-lock (&optional type)
  6593. "Set restriction lock for agenda, to current subtree or file.
  6594. Restriction will be the file if TYPE is `file', or if type is the
  6595. universal prefix '(4), or if the cursor is before the first headline
  6596. in the file. Otherwise, restriction will be to the current subtree."
  6597. (interactive "P")
  6598. (and (equal type '(4)) (setq type 'file))
  6599. (setq type (cond
  6600. (type type)
  6601. ((org-at-heading-p) 'subtree)
  6602. ((condition-case nil (org-back-to-heading t) (error nil))
  6603. 'subtree)
  6604. (t 'file)))
  6605. (if (eq type 'subtree)
  6606. (progn
  6607. (setq org-agenda-restrict (current-buffer))
  6608. (setq org-agenda-overriding-restriction 'subtree)
  6609. (put 'org-agenda-files 'org-restrict
  6610. (list (buffer-file-name (buffer-base-buffer))))
  6611. (org-back-to-heading t)
  6612. (move-overlay org-agenda-restriction-lock-overlay
  6613. (point)
  6614. (if org-agenda-restriction-lock-highlight-subtree
  6615. (save-excursion (org-end-of-subtree t t) (point))
  6616. (point-at-eol)))
  6617. (move-marker org-agenda-restrict-begin (point))
  6618. (move-marker org-agenda-restrict-end
  6619. (save-excursion (org-end-of-subtree t t)))
  6620. (message "Locking agenda restriction to subtree"))
  6621. (put 'org-agenda-files 'org-restrict
  6622. (list (buffer-file-name (buffer-base-buffer))))
  6623. (setq org-agenda-restrict nil)
  6624. (setq org-agenda-overriding-restriction 'file)
  6625. (move-marker org-agenda-restrict-begin nil)
  6626. (move-marker org-agenda-restrict-end nil)
  6627. (message "Locking agenda restriction to file"))
  6628. (setq current-prefix-arg nil)
  6629. (org-agenda-maybe-redo))
  6630. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6631. "Remove the agenda restriction lock."
  6632. (interactive "P")
  6633. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6634. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6635. (setq org-agenda-overriding-restriction nil)
  6636. (setq org-agenda-restrict nil)
  6637. (put 'org-agenda-files 'org-restrict nil)
  6638. (move-marker org-agenda-restrict-begin nil)
  6639. (move-marker org-agenda-restrict-end nil)
  6640. (setq current-prefix-arg nil)
  6641. (message "Agenda restriction lock removed")
  6642. (or noupdate (org-agenda-maybe-redo)))
  6643. (defun org-agenda-maybe-redo ()
  6644. "If there is any window showing the agenda view, update it."
  6645. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6646. (w0 (selected-window)))
  6647. (when w
  6648. (select-window w)
  6649. (org-agenda-redo)
  6650. (select-window w0)
  6651. (if org-agenda-overriding-restriction
  6652. (message "Agenda view shifted to new %s restriction"
  6653. org-agenda-overriding-restriction)
  6654. (message "Agenda restriction lock removed")))))
  6655. ;;; Agenda commands
  6656. (defun org-agenda-check-type (error &rest types)
  6657. "Check if agenda buffer is of allowed type.
  6658. If ERROR is non-nil, throw an error, otherwise just return nil.
  6659. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6660. (if (not org-agenda-type)
  6661. (error "No Org agenda currently displayed")
  6662. (if (memq org-agenda-type types)
  6663. t
  6664. (if error
  6665. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6666. nil))))
  6667. (defun org-agenda-Quit ()
  6668. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6669. Also restore the window configuration."
  6670. (interactive)
  6671. (if org-agenda-columns-active
  6672. (org-columns-quit)
  6673. (let ((buf (current-buffer)))
  6674. (if (eq org-agenda-window-setup 'other-frame)
  6675. (progn
  6676. (org-agenda-reset-markers)
  6677. (kill-buffer buf)
  6678. (org-columns-remove-overlays)
  6679. (setq org-agenda-archives-mode nil)
  6680. (delete-frame))
  6681. (and (not (eq org-agenda-window-setup 'current-window))
  6682. (not (one-window-p))
  6683. (delete-window))
  6684. (org-agenda-reset-markers)
  6685. (kill-buffer buf)
  6686. (org-columns-remove-overlays)
  6687. (setq org-agenda-archives-mode nil)))
  6688. (setq org-agenda-buffer nil)
  6689. ;; Maybe restore the pre-agenda window configuration.
  6690. (and org-agenda-restore-windows-after-quit
  6691. (not (eq org-agenda-window-setup 'other-frame))
  6692. org-agenda-pre-window-conf
  6693. (set-window-configuration org-agenda-pre-window-conf)
  6694. (setq org-agenda-pre-window-conf nil))))
  6695. (defun org-agenda-quit ()
  6696. "Exit the agenda and restore the window configuration.
  6697. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6698. (interactive)
  6699. (if (and (eq org-indirect-buffer-display 'other-window)
  6700. org-last-indirect-buffer)
  6701. (let ((org-last-indirect-window
  6702. (get-buffer-window org-last-indirect-buffer)))
  6703. (if org-last-indirect-window
  6704. (delete-window org-last-indirect-window))))
  6705. (if org-agenda-columns-active
  6706. (org-columns-quit)
  6707. (if org-agenda-sticky
  6708. (let ((buf (current-buffer)))
  6709. (if (eq org-agenda-window-setup 'other-frame)
  6710. (progn
  6711. (delete-frame))
  6712. (and (not (eq org-agenda-window-setup 'current-window))
  6713. (not (one-window-p))
  6714. (delete-window)))
  6715. (with-current-buffer buf
  6716. (bury-buffer)
  6717. ;; Maybe restore the pre-agenda window configuration.
  6718. (and org-agenda-restore-windows-after-quit
  6719. (not (eq org-agenda-window-setup 'other-frame))
  6720. org-agenda-pre-window-conf
  6721. (set-window-configuration org-agenda-pre-window-conf)
  6722. (setq org-agenda-pre-window-conf nil))))
  6723. (org-agenda-Quit))))
  6724. (defun org-agenda-exit ()
  6725. "Exit the agenda and restore the window configuration.
  6726. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6727. buffers visited directly by the user will not be touched."
  6728. (interactive)
  6729. (org-release-buffers org-agenda-new-buffers)
  6730. (setq org-agenda-new-buffers nil)
  6731. (org-agenda-Quit))
  6732. (defun org-agenda-kill-all-agenda-buffers ()
  6733. "Kill all buffers in `org-agenda-mode'.
  6734. This is used when toggling sticky agendas.
  6735. You can also explicitly invoke it with `C-c a C-k'."
  6736. (interactive)
  6737. (let (blist)
  6738. (dolist (buf (buffer-list))
  6739. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6740. (push buf blist)))
  6741. (mapc 'kill-buffer blist)))
  6742. (defun org-agenda-execute (arg)
  6743. "Execute another agenda command, keeping same window.
  6744. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6745. in the agenda."
  6746. (interactive "P")
  6747. (let ((org-agenda-window-setup 'current-window))
  6748. (org-agenda arg)))
  6749. (defun org-agenda-redo (&optional all)
  6750. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6751. (interactive "P")
  6752. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6753. (cpa (unless (eq all t) current-prefix-arg))
  6754. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6755. (org-agenda-sticky nil)
  6756. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6757. org-agenda-buffer-name))
  6758. (org-agenda-keep-modes t)
  6759. (tag-filter org-agenda-tag-filter)
  6760. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6761. (top-hl-filter org-agenda-top-headline-filter)
  6762. (cat-filter org-agenda-category-filter)
  6763. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6764. (re-filter org-agenda-regexp-filter)
  6765. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6766. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6767. (cols org-agenda-columns-active)
  6768. (line (org-current-line))
  6769. (window-line (- line (org-current-line (window-start))))
  6770. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6771. (redo-cmd (get-text-property p 'org-redo-cmd))
  6772. (last-args (get-text-property p 'org-last-args))
  6773. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6774. (org-agenda-overriding-cmd-arguments
  6775. (unless (eq all t)
  6776. (cond ((listp last-args)
  6777. (cons (or cpa (car last-args)) (cdr last-args)))
  6778. ((stringp last-args)
  6779. last-args))))
  6780. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6781. (put 'org-agenda-tag-filter :preset-filter nil)
  6782. (put 'org-agenda-category-filter :preset-filter nil)
  6783. (put 'org-agenda-regexp-filter :preset-filter nil)
  6784. (and cols (org-columns-quit))
  6785. (message "Rebuilding agenda buffer...")
  6786. (if series-redo-cmd
  6787. (eval series-redo-cmd)
  6788. (org-let lprops redo-cmd))
  6789. (setq org-agenda-undo-list nil
  6790. org-agenda-pending-undo-list nil
  6791. org-agenda-tag-filter tag-filter
  6792. org-agenda-category-filter cat-filter
  6793. org-agenda-regexp-filter re-filter
  6794. org-agenda-top-headline-filter top-hl-filter)
  6795. (message "Rebuilding agenda buffer...done")
  6796. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6797. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6798. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6799. (let ((tag (or tag-filter tag-preset))
  6800. (cat (or cat-filter cat-preset))
  6801. (re (or re-filter re-preset)))
  6802. (when tag (org-agenda-filter-apply tag 'tag))
  6803. (when cat (org-agenda-filter-apply cat 'category))
  6804. (when re (org-agenda-filter-apply re 'regexp)))
  6805. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6806. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6807. (org-goto-line line)
  6808. (recenter window-line)))
  6809. (defvar org-global-tags-completion-table nil)
  6810. (defvar org-agenda-filter-form nil)
  6811. (defvar org-agenda-filtered-by-category nil)
  6812. (defun org-agenda-filter-by-category (strip)
  6813. "Keep only those lines in the agenda buffer that have a specific category.
  6814. The category is that of the current line."
  6815. (interactive "P")
  6816. (if (and org-agenda-filtered-by-category
  6817. org-agenda-category-filter)
  6818. (org-agenda-filter-show-all-cat)
  6819. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6820. (cond
  6821. ((and cat strip)
  6822. (org-agenda-filter-apply
  6823. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6824. ((and cat)
  6825. (org-agenda-filter-apply
  6826. (setq org-agenda-category-filter
  6827. (list (concat "+" cat))) 'category))
  6828. (t (error "No category at point"))))))
  6829. (defun org-find-top-headline (&optional pos)
  6830. "Find the topmost parent headline and return it."
  6831. (save-excursion
  6832. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6833. (if pos (goto-char pos))
  6834. ;; Skip up to the topmost parent
  6835. (while (ignore-errors (outline-up-heading 1) t))
  6836. (ignore-errors
  6837. (nth 4 (org-heading-components))))))
  6838. (defvar org-agenda-filtered-by-top-headline nil)
  6839. (defun org-agenda-filter-by-top-headline (strip)
  6840. "Keep only those lines that are descendants from the same top headline.
  6841. The top headline is that of the current line."
  6842. (interactive "P")
  6843. (if org-agenda-filtered-by-top-headline
  6844. (progn
  6845. (setq org-agenda-filtered-by-top-headline nil
  6846. org-agenda-top-headline-filter nil)
  6847. (org-agenda-filter-show-all-top-filter))
  6848. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6849. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6850. (error "No top-level headline at point")))))
  6851. (defvar org-agenda-regexp-filter nil)
  6852. (defun org-agenda-filter-by-regexp (strip)
  6853. "Filter agenda entries by a regular expression.
  6854. Regexp filters are cumulative.
  6855. With no prefix argument, keep entries matching the regexp.
  6856. With one prefix argument, filter out entries matching the regexp.
  6857. With two prefix arguments, remove the regexp filters."
  6858. (interactive "P")
  6859. (if (not (equal strip '(16)))
  6860. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6861. (read-from-minibuffer
  6862. (if (equal strip '(4))
  6863. "Filter out entries matching regexp: "
  6864. "Narrow to entries matching regexp: ")))))
  6865. (push flt org-agenda-regexp-filter)
  6866. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6867. (org-agenda-filter-show-all-re)
  6868. (message "Regexp filter removed")))
  6869. (defun org-agenda-filter-remove-all ()
  6870. "Remove all filters from the current agenda buffer."
  6871. (interactive)
  6872. (when org-agenda-tag-filter
  6873. (org-agenda-filter-show-all-tag))
  6874. (when org-agenda-category-filter
  6875. (org-agenda-filter-show-all-cat))
  6876. (when org-agenda-regexp-filter
  6877. (org-agenda-filter-show-all-re))
  6878. (when org-agenda-top-headline-filter
  6879. (org-agenda-filter-show-all-top-filter))
  6880. (org-agenda-finalize))
  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 'top-headline)))
  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* ((b (max (point-min) (1- (point-at-bol))))
  7142. (e (point-at-eol)))
  7143. (let ((inhibit-read-only t))
  7144. (add-text-properties
  7145. b e `(invisible org-filtered org-filter-type ,type)))))
  7146. (defun org-agenda-remove-filter (type)
  7147. (interactive)
  7148. "Remove filter of type TYPE from the agenda buffer."
  7149. (save-excursion
  7150. (goto-char (point-min))
  7151. (let ((inhibit-read-only t) pos)
  7152. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7153. (goto-char pos)
  7154. (remove-text-properties
  7155. (point) (next-single-property-change (point) 'org-filter-type)
  7156. `(invisible org-filtered org-filter-type ,type))))
  7157. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7158. (setq org-agenda-filter-form nil)
  7159. (org-agenda-set-mode-name)
  7160. (org-agenda-finalize)))
  7161. (defun org-agenda-filter-show-all-tag nil
  7162. (org-agenda-remove-filter 'tag))
  7163. (defun org-agenda-filter-show-all-re nil
  7164. (org-agenda-remove-filter 'regexp))
  7165. (defun org-agenda-filter-show-all-cat nil
  7166. (org-agenda-remove-filter 'category))
  7167. (defun org-agenda-filter-show-all-top-filter nil
  7168. (org-agenda-remove-filter 'top-headline))
  7169. (defun org-agenda-manipulate-query-add ()
  7170. "Manipulate the query by adding a search term with positive selection.
  7171. Positive selection means the term must be matched for selection of an entry."
  7172. (interactive)
  7173. (org-agenda-manipulate-query ?\[))
  7174. (defun org-agenda-manipulate-query-subtract ()
  7175. "Manipulate the query by adding a search term with negative selection.
  7176. Negative selection means term must not be matched for selection of an entry."
  7177. (interactive)
  7178. (org-agenda-manipulate-query ?\]))
  7179. (defun org-agenda-manipulate-query-add-re ()
  7180. "Manipulate the query by adding a search regexp with positive selection.
  7181. Positive selection means the regexp must match for selection of an entry."
  7182. (interactive)
  7183. (org-agenda-manipulate-query ?\{))
  7184. (defun org-agenda-manipulate-query-subtract-re ()
  7185. "Manipulate the query by adding a search regexp with negative selection.
  7186. Negative selection means regexp must not match for selection of an entry."
  7187. (interactive)
  7188. (org-agenda-manipulate-query ?\}))
  7189. (defun org-agenda-manipulate-query (char)
  7190. (cond
  7191. ((memq org-agenda-type '(timeline agenda))
  7192. (let ((org-agenda-include-inactive-timestamps t))
  7193. (org-agenda-redo))
  7194. (message "Display now includes inactive timestamps as well"))
  7195. ((eq org-agenda-type 'search)
  7196. (org-add-to-string
  7197. 'org-agenda-query-string
  7198. (if org-agenda-last-search-view-search-was-boolean
  7199. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7200. (?\{ . " +{}") (?\} . " -{}"))))
  7201. " "))
  7202. (setq org-agenda-redo-command
  7203. (list 'org-search-view
  7204. (car (get-text-property (min (1- (point-max)) (point))
  7205. 'org-last-args))
  7206. org-agenda-query-string
  7207. (+ (length org-agenda-query-string)
  7208. (if (member char '(?\{ ?\})) 0 1))))
  7209. (set-register org-agenda-query-register org-agenda-query-string)
  7210. (let ((org-agenda-overriding-arguments
  7211. (cdr org-agenda-redo-command)))
  7212. (org-agenda-redo)))
  7213. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7214. org-agenda-type))))
  7215. (defun org-add-to-string (var string)
  7216. (set var (concat (symbol-value var) string)))
  7217. (defun org-agenda-goto-date (span)
  7218. "Jump to DATE in agenda."
  7219. (interactive "P")
  7220. (let* ((org-read-date-prefer-future
  7221. (eval org-agenda-jump-prefer-future))
  7222. (date (org-read-date))
  7223. (day (time-to-days (org-time-string-to-time date)))
  7224. (org-agenda-sticky-orig org-agenda-sticky)
  7225. (org-agenda-buffer-tmp-name (buffer-name))
  7226. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7227. (0-arg (or current-prefix-arg (car args)))
  7228. (2-arg (nth 2 args))
  7229. (with-hour-p (nth 4 org-agenda-redo-command))
  7230. (newcmd (list 'org-agenda-list 0-arg date
  7231. (org-agenda-span-to-ndays
  7232. 2-arg (org-time-string-to-absolute date))
  7233. with-hour-p))
  7234. (newargs (cdr newcmd))
  7235. (inhibit-read-only t)
  7236. org-agenda-sticky)
  7237. (if (not (org-agenda-check-type t 'agenda))
  7238. (error "Not available in non-agenda views")
  7239. (add-text-properties (point-min) (point-max)
  7240. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7241. (org-agenda-redo)
  7242. (goto-char (point-min))
  7243. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7244. (save-excursion (move-beginning-of-line 2) (eobp))))
  7245. (move-beginning-of-line 2))
  7246. (setq org-agenda-sticky org-agenda-sticky-orig
  7247. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7248. (defun org-agenda-goto-today ()
  7249. "Go to today."
  7250. (interactive)
  7251. (org-agenda-check-type t 'timeline 'agenda)
  7252. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7253. (curspan (nth 2 args))
  7254. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7255. (cond
  7256. (tdpos (goto-char tdpos))
  7257. ((eq org-agenda-type 'agenda)
  7258. (let* ((sd (org-agenda-compute-starting-span
  7259. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7260. (org-agenda-overriding-arguments args))
  7261. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7262. (org-agenda-redo)
  7263. (org-agenda-find-same-or-today-or-agenda)))
  7264. (t (error "Cannot find today")))))
  7265. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7266. (goto-char
  7267. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7268. (text-property-any (point-min) (point-max) 'org-today t)
  7269. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7270. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7271. (org-agenda-goto-block-beginning))
  7272. (point-min))))
  7273. (defun org-agenda-goto-block-beginning ()
  7274. "Go the agenda block beginning."
  7275. (interactive)
  7276. (if (not (derived-mode-p 'org-agenda-mode))
  7277. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7278. (let (dest)
  7279. (save-excursion
  7280. (unless (looking-at "\\'")
  7281. (forward-char))
  7282. (let* ((prop 'org-agenda-structural-header)
  7283. (p (previous-single-property-change (point) prop))
  7284. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7285. (1- (point))) prop)))
  7286. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7287. (if (not dest)
  7288. (error "Cannot find the beginning of the blog")
  7289. (goto-char dest)
  7290. (move-beginning-of-line 1)))))
  7291. (defun org-agenda-later (arg)
  7292. "Go forward in time by the current span.
  7293. With prefix ARG, go forward that many times the current span."
  7294. (interactive "p")
  7295. (org-agenda-check-type t 'agenda)
  7296. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7297. (span (or (nth 2 args) org-agenda-current-span))
  7298. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7299. (greg (calendar-gregorian-from-absolute sd))
  7300. (cnt (org-get-at-bol 'org-day-cnt))
  7301. greg2)
  7302. (cond
  7303. ((numberp span)
  7304. (setq sd (+ (* span arg) sd)))
  7305. ((eq span 'day)
  7306. (setq sd (+ arg sd)))
  7307. ((eq span 'week)
  7308. (setq sd (+ (* 7 arg) sd)))
  7309. ((eq span 'fortnight)
  7310. (setq sd (+ (* 14 arg) sd)))
  7311. ((eq span 'month)
  7312. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7313. sd (calendar-absolute-from-gregorian greg2))
  7314. (setcar greg2 (1+ (car greg2))))
  7315. ((eq span 'year)
  7316. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7317. sd (calendar-absolute-from-gregorian greg2))
  7318. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7319. (t
  7320. (setq sd (+ (* span arg) sd))))
  7321. (let ((org-agenda-overriding-cmd
  7322. ;; `cmd' may have been set by `org-agenda-run-series' which
  7323. ;; uses `org-agenda-overriding-cmd' to decide whether
  7324. ;; overriding is allowed for `cmd'
  7325. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7326. (org-agenda-overriding-arguments
  7327. (list (car args) sd span)))
  7328. (org-agenda-redo)
  7329. (org-agenda-find-same-or-today-or-agenda cnt))))
  7330. (defun org-agenda-earlier (arg)
  7331. "Go backward in time by the current span.
  7332. With prefix ARG, go backward that many times the current span."
  7333. (interactive "p")
  7334. (org-agenda-later (- arg)))
  7335. (defun org-agenda-view-mode-dispatch ()
  7336. "Call one of the view mode commands."
  7337. (interactive)
  7338. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7339. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7340. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7341. (let ((a (read-char-exclusive)))
  7342. (case a
  7343. (?\ (call-interactively 'org-agenda-reset-view))
  7344. (?d (call-interactively 'org-agenda-day-view))
  7345. (?w (call-interactively 'org-agenda-week-view))
  7346. (?t (call-interactively 'org-agenda-fortnight-view))
  7347. (?m (call-interactively 'org-agenda-month-view))
  7348. (?y (call-interactively 'org-agenda-year-view))
  7349. (?l (call-interactively 'org-agenda-log-mode))
  7350. (?L (org-agenda-log-mode '(4)))
  7351. (?c (org-agenda-log-mode 'clockcheck))
  7352. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7353. (?a (call-interactively 'org-agenda-archives-mode))
  7354. (?A (org-agenda-archives-mode 'files))
  7355. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7356. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7357. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7358. (?D (call-interactively 'org-agenda-toggle-diary))
  7359. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7360. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7361. (org-agenda-check-type t 'timeline 'agenda)
  7362. (org-agenda-redo))
  7363. (message "Display now includes inactive timestamps as well"))
  7364. (?q (message "Abort"))
  7365. (otherwise (error "Invalid key" )))))
  7366. (defun org-agenda-reset-view ()
  7367. "Switch to default view for agenda."
  7368. (interactive)
  7369. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7370. (defun org-agenda-day-view (&optional day-of-month)
  7371. "Switch to daily view for agenda.
  7372. With argument DAY-OF-MONTH, switch to that day of the month."
  7373. (interactive "P")
  7374. (org-agenda-change-time-span 'day day-of-month))
  7375. (defun org-agenda-week-view (&optional iso-week)
  7376. "Switch to daily view for agenda.
  7377. With argument ISO-WEEK, switch to the corresponding ISO week.
  7378. If ISO-WEEK has more then 2 digits, only the last two encode the
  7379. week. Any digits before this encode a year. So 200712 means
  7380. week 12 of year 2007. Years in the range 1938-2037 can also be
  7381. written as 2-digit years."
  7382. (interactive "P")
  7383. (org-agenda-change-time-span 'week iso-week))
  7384. (defun org-agenda-fortnight-view (&optional iso-week)
  7385. "Switch to daily view for agenda.
  7386. With argument ISO-WEEK, switch to the corresponding ISO week.
  7387. If ISO-WEEK has more then 2 digits, only the last two encode the
  7388. week. Any digits before this encode a year. So 200712 means
  7389. week 12 of year 2007. Years in the range 1938-2037 can also be
  7390. written as 2-digit years."
  7391. (interactive "P")
  7392. (org-agenda-change-time-span 'fortnight iso-week))
  7393. (defun org-agenda-month-view (&optional month)
  7394. "Switch to monthly view for agenda.
  7395. With argument MONTH, switch to that month."
  7396. (interactive "P")
  7397. (org-agenda-change-time-span 'month month))
  7398. (defun org-agenda-year-view (&optional year)
  7399. "Switch to yearly view for agenda.
  7400. With argument YEAR, switch to that year.
  7401. If MONTH has more then 2 digits, only the last two encode the
  7402. month. Any digits before this encode a year. So 200712 means
  7403. December year 2007. Years in the range 1938-2037 can also be
  7404. written as 2-digit years."
  7405. (interactive "P")
  7406. (when year
  7407. (setq year (org-small-year-to-year year)))
  7408. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7409. (org-agenda-change-time-span 'year year)
  7410. (error "Abort")))
  7411. (defun org-agenda-change-time-span (span &optional n)
  7412. "Change the agenda view to SPAN.
  7413. SPAN may be `day', `week', `fortnight', `month', `year'."
  7414. (org-agenda-check-type t 'agenda)
  7415. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7416. (curspan (nth 2 args)))
  7417. (if (and (not n) (equal curspan span))
  7418. (error "Viewing span is already \"%s\"" span))
  7419. (let* ((sd (or (org-get-at-bol 'day)
  7420. (nth 1 args)
  7421. org-starting-day))
  7422. (sd (org-agenda-compute-starting-span sd span n))
  7423. (org-agenda-overriding-cmd
  7424. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7425. (org-agenda-overriding-arguments
  7426. (list (car args) sd span)))
  7427. (org-agenda-redo)
  7428. (org-agenda-find-same-or-today-or-agenda))
  7429. (org-agenda-set-mode-name)
  7430. (message "Switched to %s view" span)))
  7431. (defun org-agenda-compute-starting-span (sd span &optional n)
  7432. "Compute starting date for agenda.
  7433. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7434. is a cons cell with the starting date and the number of days,
  7435. so that the date SD will be in that range."
  7436. (let* ((greg (calendar-gregorian-from-absolute sd))
  7437. (dg (nth 1 greg))
  7438. (mg (car greg))
  7439. (yg (nth 2 greg)))
  7440. (cond
  7441. ((eq span 'day)
  7442. (when n
  7443. (setq sd (+ (calendar-absolute-from-gregorian
  7444. (list mg 1 yg))
  7445. n -1))))
  7446. ((or (eq span 'week) (eq span 'fortnight))
  7447. (let* ((nt (calendar-day-of-week
  7448. (calendar-gregorian-from-absolute sd)))
  7449. (d (if org-agenda-start-on-weekday
  7450. (- nt org-agenda-start-on-weekday)
  7451. 0))
  7452. y1)
  7453. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7454. (when n
  7455. (require 'cal-iso)
  7456. (when (> n 99)
  7457. (setq y1 (org-small-year-to-year (/ n 100))
  7458. n (mod n 100)))
  7459. (setq sd
  7460. (calendar-absolute-from-iso
  7461. (list n 1
  7462. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7463. ((eq span 'month)
  7464. (let (y1)
  7465. (when (and n (> n 99))
  7466. (setq y1 (org-small-year-to-year (/ n 100))
  7467. n (mod n 100)))
  7468. (setq sd (calendar-absolute-from-gregorian
  7469. (list (or n mg) 1 (or y1 yg))))))
  7470. ((eq span 'year)
  7471. (setq sd (calendar-absolute-from-gregorian
  7472. (list 1 1 (or n yg))))))
  7473. sd))
  7474. (defun org-agenda-next-date-line (&optional arg)
  7475. "Jump to the next line indicating a date in agenda buffer."
  7476. (interactive "p")
  7477. (org-agenda-check-type t 'agenda 'timeline)
  7478. (beginning-of-line 1)
  7479. ;; This does not work if user makes date format that starts with a blank
  7480. (if (looking-at "^\\S-") (forward-char 1))
  7481. (if (not (re-search-forward "^\\S-" nil t arg))
  7482. (progn
  7483. (backward-char 1)
  7484. (error "No next date after this line in this buffer")))
  7485. (goto-char (match-beginning 0)))
  7486. (defun org-agenda-previous-date-line (&optional arg)
  7487. "Jump to the previous line indicating a date in agenda buffer."
  7488. (interactive "p")
  7489. (org-agenda-check-type t 'agenda 'timeline)
  7490. (beginning-of-line 1)
  7491. (if (not (re-search-backward "^\\S-" nil t arg))
  7492. (error "No previous date before this line in this buffer")))
  7493. ;; Initialize the highlight
  7494. (defvar org-hl (make-overlay 1 1))
  7495. (overlay-put org-hl 'face 'highlight)
  7496. (defun org-highlight (begin end &optional buffer)
  7497. "Highlight a region with overlay."
  7498. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7499. (defun org-unhighlight ()
  7500. "Detach overlay INDEX."
  7501. (org-detach-overlay org-hl))
  7502. (defun org-unhighlight-once ()
  7503. "Remove the highlight from its position, and this function from the hook."
  7504. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7505. (org-unhighlight))
  7506. (defvar org-agenda-pre-follow-window-conf nil)
  7507. (defun org-agenda-follow-mode ()
  7508. "Toggle follow mode in an agenda buffer."
  7509. (interactive)
  7510. (unless org-agenda-follow-mode
  7511. (setq org-agenda-pre-follow-window-conf
  7512. (current-window-configuration)))
  7513. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7514. (unless org-agenda-follow-mode
  7515. (set-window-configuration org-agenda-pre-follow-window-conf))
  7516. (org-agenda-set-mode-name)
  7517. (org-agenda-do-context-action)
  7518. (message "Follow mode is %s"
  7519. (if org-agenda-follow-mode "on" "off")))
  7520. (defun org-agenda-entry-text-mode (&optional arg)
  7521. "Toggle entry text mode in an agenda buffer."
  7522. (interactive "P")
  7523. (if (or org-agenda-tag-filter
  7524. org-agenda-category-filter
  7525. org-agenda-regexp-filter
  7526. org-agenda-top-headline-filter)
  7527. (user-error "Can't show entry text in filtered views")
  7528. (setq org-agenda-entry-text-mode (or (integerp arg)
  7529. (not org-agenda-entry-text-mode)))
  7530. (org-agenda-entry-text-hide)
  7531. (and org-agenda-entry-text-mode
  7532. (let ((org-agenda-entry-text-maxlines
  7533. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7534. (org-agenda-entry-text-show)))
  7535. (org-agenda-set-mode-name)
  7536. (message "Entry text mode is %s%s"
  7537. (if org-agenda-entry-text-mode "on" "off")
  7538. (if (not org-agenda-entry-text-mode) ""
  7539. (format " (maximum number of lines is %d)"
  7540. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7541. (defun org-agenda-clockreport-mode (&optional with-filter)
  7542. "Toggle clocktable mode in an agenda buffer.
  7543. With prefix arg WITH-FILTER, make the clocktable respect the current
  7544. agenda filter."
  7545. (interactive "P")
  7546. (org-agenda-check-type t 'agenda)
  7547. (if with-filter
  7548. (setq org-agenda-clockreport-mode 'with-filter)
  7549. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7550. (org-agenda-set-mode-name)
  7551. (org-agenda-redo)
  7552. (message "Clocktable mode is %s"
  7553. (if org-agenda-clockreport-mode "on" "off")))
  7554. (defun org-agenda-log-mode (&optional special)
  7555. "Toggle log mode in an agenda buffer.
  7556. With argument SPECIAL, show all possible log items, not only the ones
  7557. configured in `org-agenda-log-mode-items'.
  7558. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7559. (interactive "P")
  7560. (org-agenda-check-type t 'agenda 'timeline)
  7561. (setq org-agenda-show-log
  7562. (cond
  7563. ((equal special '(16)) 'only)
  7564. ((eq special 'clockcheck)
  7565. (if (eq org-agenda-show-log 'clockcheck)
  7566. nil 'clockcheck))
  7567. (special '(closed clock state))
  7568. (t (not org-agenda-show-log))))
  7569. (org-agenda-set-mode-name)
  7570. (org-agenda-redo)
  7571. (message "Log mode is %s"
  7572. (if org-agenda-show-log "on" "off")))
  7573. (defun org-agenda-archives-mode (&optional with-files)
  7574. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7575. When called with a prefix argument, include all archive files as well."
  7576. (interactive "P")
  7577. (setq org-agenda-archives-mode
  7578. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7579. (org-agenda-set-mode-name)
  7580. (org-agenda-redo)
  7581. (message
  7582. "%s"
  7583. (cond
  7584. ((eq org-agenda-archives-mode nil)
  7585. "No archives are included")
  7586. ((eq org-agenda-archives-mode 'trees)
  7587. (format "Trees with :%s: tag are included" org-archive-tag))
  7588. ((eq org-agenda-archives-mode t)
  7589. (format "Trees with :%s: tag and all active archive files are included"
  7590. org-archive-tag)))))
  7591. (defun org-agenda-toggle-diary ()
  7592. "Toggle diary inclusion in an agenda buffer."
  7593. (interactive)
  7594. (org-agenda-check-type t 'agenda)
  7595. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7596. (org-agenda-redo)
  7597. (org-agenda-set-mode-name)
  7598. (message "Diary inclusion turned %s"
  7599. (if org-agenda-include-diary "on" "off")))
  7600. (defun org-agenda-toggle-deadlines ()
  7601. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7602. (interactive)
  7603. (org-agenda-check-type t 'agenda)
  7604. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7605. (org-agenda-redo)
  7606. (org-agenda-set-mode-name)
  7607. (message "Deadlines inclusion turned %s"
  7608. (if org-agenda-include-deadlines "on" "off")))
  7609. (defun org-agenda-toggle-time-grid ()
  7610. "Toggle time grid in an agenda buffer."
  7611. (interactive)
  7612. (org-agenda-check-type t 'agenda)
  7613. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7614. (org-agenda-redo)
  7615. (org-agenda-set-mode-name)
  7616. (message "Time-grid turned %s"
  7617. (if org-agenda-use-time-grid "on" "off")))
  7618. (defun org-agenda-set-mode-name ()
  7619. "Set the mode name to indicate all the small mode settings."
  7620. (setq mode-name
  7621. (list "Org-Agenda"
  7622. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7623. " "
  7624. '(:eval (org-agenda-span-name org-agenda-current-span))
  7625. (if org-agenda-follow-mode " Follow" "")
  7626. (if org-agenda-entry-text-mode " ETxt" "")
  7627. (if org-agenda-include-diary " Diary" "")
  7628. (if org-agenda-include-deadlines " Ddl" "")
  7629. (if org-agenda-use-time-grid " Grid" "")
  7630. (if (and (boundp 'org-habit-show-habits)
  7631. org-habit-show-habits) " Habit" "")
  7632. (cond
  7633. ((consp org-agenda-show-log) " LogAll")
  7634. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7635. (org-agenda-show-log " Log")
  7636. (t ""))
  7637. (if (or org-agenda-category-filter
  7638. (get 'org-agenda-category-filter :preset-filter))
  7639. '(:eval (org-propertize
  7640. (concat " <"
  7641. (mapconcat
  7642. 'identity
  7643. (append
  7644. (get 'org-agenda-category-filter :preset-filter)
  7645. org-agenda-category-filter)
  7646. "")
  7647. ">")
  7648. 'face 'org-agenda-filter-category
  7649. 'help-echo "Category used in filtering")) "")
  7650. (if (or org-agenda-tag-filter
  7651. (get 'org-agenda-tag-filter :preset-filter))
  7652. '(:eval (org-propertize
  7653. (concat " {"
  7654. (mapconcat
  7655. 'identity
  7656. (append
  7657. (get 'org-agenda-tag-filter :preset-filter)
  7658. org-agenda-tag-filter)
  7659. "")
  7660. "}")
  7661. 'face 'org-agenda-filter-tags
  7662. 'help-echo "Tags used in filtering")) "")
  7663. (if (or org-agenda-regexp-filter
  7664. (get 'org-agenda-regexp-filter :preset-filter))
  7665. '(:eval (org-propertize
  7666. (concat " ["
  7667. (mapconcat
  7668. 'identity
  7669. (append
  7670. (get 'org-agenda-regexp-filter :preset-filter)
  7671. org-agenda-regexp-filter)
  7672. "")
  7673. "]")
  7674. 'face 'org-agenda-filter-regexp
  7675. 'help-echo "Regexp used in filtering")) "")
  7676. (if org-agenda-archives-mode
  7677. (if (eq org-agenda-archives-mode t)
  7678. " Archives"
  7679. (format " :%s:" org-archive-tag))
  7680. "")
  7681. (if org-agenda-clockreport-mode
  7682. (if (eq org-agenda-clockreport-mode 'with-filter)
  7683. " Clock{}" " Clock")
  7684. "")))
  7685. (force-mode-line-update))
  7686. (define-obsolete-function-alias
  7687. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7688. (defun org-agenda-update-agenda-type ()
  7689. "Update the agenda type after each command."
  7690. (setq org-agenda-type
  7691. (or (get-text-property (point) 'org-agenda-type)
  7692. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7693. (defun org-agenda-next-line ()
  7694. "Move cursor to the next line, and show if follow mode is active."
  7695. (interactive)
  7696. (call-interactively 'next-line)
  7697. (org-agenda-do-context-action))
  7698. (defun org-agenda-previous-line ()
  7699. "Move cursor to the previous line, and show if follow-mode is active."
  7700. (interactive)
  7701. (call-interactively 'previous-line)
  7702. (org-agenda-do-context-action))
  7703. (defun org-agenda-next-item (n)
  7704. "Move cursor to next agenda item."
  7705. (interactive "p")
  7706. (let ((col (current-column)))
  7707. (dotimes (c n)
  7708. (when (next-single-property-change (point-at-eol) 'org-marker)
  7709. (move-end-of-line 1)
  7710. (goto-char (next-single-property-change (point) 'org-marker))))
  7711. (org-move-to-column col))
  7712. (org-agenda-do-context-action))
  7713. (defun org-agenda-previous-item (n)
  7714. "Move cursor to next agenda item."
  7715. (interactive "p")
  7716. (dotimes (c n)
  7717. (let ((col (current-column))
  7718. (goto (save-excursion
  7719. (move-end-of-line 0)
  7720. (previous-single-property-change (point) 'org-marker))))
  7721. (if goto (goto-char goto))
  7722. (org-move-to-column col)))
  7723. (org-agenda-do-context-action))
  7724. (defun org-agenda-do-context-action ()
  7725. "Show outline path and, maybe, follow mode window."
  7726. (let ((m (org-get-at-bol 'org-marker)))
  7727. (when (and (markerp m) (marker-buffer m))
  7728. (and org-agenda-follow-mode
  7729. (if org-agenda-follow-indirect
  7730. (org-agenda-tree-to-indirect-buffer nil)
  7731. (org-agenda-show)))
  7732. (and org-agenda-show-outline-path
  7733. (org-with-point-at m (org-display-outline-path t))))))
  7734. (defun org-agenda-show-tags ()
  7735. "Show the tags applicable to the current item."
  7736. (interactive)
  7737. (let* ((tags (org-get-at-bol 'tags)))
  7738. (if tags
  7739. (message "Tags are :%s:"
  7740. (org-no-properties (mapconcat 'identity tags ":")))
  7741. (message "No tags associated with this line"))))
  7742. (defun org-agenda-goto (&optional highlight)
  7743. "Go to the Org-mode file which contains the item at point."
  7744. (interactive)
  7745. (let* ((marker (or (org-get-at-bol 'org-marker)
  7746. (org-agenda-error)))
  7747. (buffer (marker-buffer marker))
  7748. (pos (marker-position marker)))
  7749. (switch-to-buffer-other-window buffer)
  7750. (widen)
  7751. (push-mark)
  7752. (goto-char pos)
  7753. (when (derived-mode-p 'org-mode)
  7754. (org-show-context 'agenda)
  7755. (save-excursion
  7756. (and (outline-next-heading)
  7757. (org-flag-heading nil)))) ; show the next heading
  7758. (when (outline-invisible-p)
  7759. (show-entry)) ; display invisible text
  7760. (recenter (/ (window-height) 2))
  7761. (run-hooks 'org-agenda-after-show-hook)
  7762. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7763. (defvar org-agenda-after-show-hook nil
  7764. "Normal hook run after an item has been shown from the agenda.
  7765. Point is in the buffer where the item originated.")
  7766. (defun org-agenda-kill ()
  7767. "Kill the entry or subtree belonging to the current agenda entry."
  7768. (interactive)
  7769. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7770. (let* ((bufname-orig (buffer-name))
  7771. (marker (or (org-get-at-bol 'org-marker)
  7772. (org-agenda-error)))
  7773. (buffer (marker-buffer marker))
  7774. (pos (marker-position marker))
  7775. (type (org-get-at-bol 'type))
  7776. dbeg dend (n 0) conf)
  7777. (org-with-remote-undo buffer
  7778. (with-current-buffer buffer
  7779. (save-excursion
  7780. (goto-char pos)
  7781. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7782. (setq dbeg (progn (org-back-to-heading t) (point))
  7783. dend (org-end-of-subtree t t))
  7784. (setq dbeg (point-at-bol)
  7785. dend (min (point-max) (1+ (point-at-eol)))))
  7786. (goto-char dbeg)
  7787. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7788. (setq conf (or (eq t org-agenda-confirm-kill)
  7789. (and (numberp org-agenda-confirm-kill)
  7790. (> n org-agenda-confirm-kill))))
  7791. (and conf
  7792. (not (y-or-n-p
  7793. (format "Delete entry with %d lines in buffer \"%s\"? "
  7794. n (buffer-name buffer))))
  7795. (error "Abort"))
  7796. (let ((org-agenda-buffer-name bufname-orig))
  7797. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7798. (with-current-buffer buffer (delete-region dbeg dend))
  7799. (message "Agenda item and source killed"))))
  7800. (defvar org-archive-default-command) ; defined in org-archive.el
  7801. (defun org-agenda-archive-default ()
  7802. "Archive the entry or subtree belonging to the current agenda entry."
  7803. (interactive)
  7804. (require 'org-archive)
  7805. (org-agenda-archive-with org-archive-default-command))
  7806. (defun org-agenda-archive-default-with-confirmation ()
  7807. "Archive the entry or subtree belonging to the current agenda entry."
  7808. (interactive)
  7809. (require 'org-archive)
  7810. (org-agenda-archive-with org-archive-default-command 'confirm))
  7811. (defun org-agenda-archive ()
  7812. "Archive the entry or subtree belonging to the current agenda entry."
  7813. (interactive)
  7814. (org-agenda-archive-with 'org-archive-subtree))
  7815. (defun org-agenda-archive-to-archive-sibling ()
  7816. "Move the entry to the archive sibling."
  7817. (interactive)
  7818. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7819. (defun org-agenda-archive-with (cmd &optional confirm)
  7820. "Move the entry to the archive sibling."
  7821. (interactive)
  7822. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7823. (let* ((bufname-orig (buffer-name))
  7824. (marker (or (org-get-at-bol 'org-marker)
  7825. (org-agenda-error)))
  7826. (buffer (marker-buffer marker))
  7827. (pos (marker-position marker)))
  7828. (org-with-remote-undo buffer
  7829. (with-current-buffer buffer
  7830. (if (derived-mode-p 'org-mode)
  7831. (if (and confirm
  7832. (not (y-or-n-p "Archive this subtree or entry? ")))
  7833. (error "Abort")
  7834. (save-window-excursion
  7835. (goto-char pos)
  7836. (let ((org-agenda-buffer-name bufname-orig))
  7837. (org-remove-subtree-entries-from-agenda))
  7838. (org-back-to-heading t)
  7839. (funcall cmd)))
  7840. (error "Archiving works only in Org-mode files"))))))
  7841. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7842. "Remove all lines in the agenda that correspond to a given subtree.
  7843. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7844. If this information is not given, the function uses the tree at point."
  7845. (let ((buf (or buf (current-buffer))) m p)
  7846. (save-excursion
  7847. (unless (and beg end)
  7848. (org-back-to-heading t)
  7849. (setq beg (point))
  7850. (org-end-of-subtree t)
  7851. (setq end (point)))
  7852. (set-buffer (get-buffer org-agenda-buffer-name))
  7853. (save-excursion
  7854. (goto-char (point-max))
  7855. (beginning-of-line 1)
  7856. (while (not (bobp))
  7857. (when (and (setq m (org-get-at-bol 'org-marker))
  7858. (equal buf (marker-buffer m))
  7859. (setq p (marker-position m))
  7860. (>= p beg)
  7861. (< p end))
  7862. (let ((inhibit-read-only t))
  7863. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7864. (beginning-of-line 0))))))
  7865. (defun org-agenda-refile (&optional goto rfloc no-update)
  7866. "Refile the item at point.
  7867. When GOTO is 0 or '(64), clear the refile cache.
  7868. When GOTO is '(16), go to the location of the last refiled item.
  7869. RFLOC can be a refile location obtained in a different way.
  7870. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7871. (interactive "P")
  7872. (cond
  7873. ((member goto '(0 (64)))
  7874. (org-refile-cache-clear))
  7875. ((equal goto '(16))
  7876. (org-refile-goto-last-stored))
  7877. (t
  7878. (let* ((buffer-orig (buffer-name))
  7879. (marker (or (org-get-at-bol 'org-hd-marker)
  7880. (org-agenda-error)))
  7881. (buffer (marker-buffer marker))
  7882. (pos (marker-position marker))
  7883. (rfloc (or rfloc
  7884. (org-refile-get-location
  7885. (if goto "Goto" "Refile to") buffer
  7886. org-refile-allow-creating-parent-nodes))))
  7887. (with-current-buffer buffer
  7888. (save-excursion
  7889. (save-restriction
  7890. (widen)
  7891. (goto-char marker)
  7892. (let ((org-agenda-buffer-name buffer-orig))
  7893. (org-remove-subtree-entries-from-agenda))
  7894. (org-refile goto buffer rfloc)))))
  7895. (unless no-update (org-agenda-redo)))))
  7896. (defun org-agenda-open-link (&optional arg)
  7897. "Open the link(s) in the current entry, if any.
  7898. This looks for a link in the displayed line in the agenda.
  7899. It also looks at the text of the entry itself."
  7900. (interactive "P")
  7901. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7902. (org-get-at-bol 'org-marker)))
  7903. (buffer (and marker (marker-buffer marker)))
  7904. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7905. (lkall (and buffer (org-offer-links-in-entry
  7906. buffer marker arg prefix)))
  7907. (lk0 (car lkall))
  7908. (lk (if (stringp lk0) (list lk0) lk0))
  7909. (lkend (cdr lkall))
  7910. trg)
  7911. (cond
  7912. ((and buffer lk)
  7913. (mapcar (lambda(l)
  7914. (with-current-buffer buffer
  7915. (setq trg (and (string-match org-bracket-link-regexp l)
  7916. (match-string 1 l)))
  7917. (if (or (not trg) (string-match org-any-link-re trg))
  7918. (save-excursion
  7919. (save-restriction
  7920. (widen)
  7921. (goto-char marker)
  7922. (when (search-forward l nil lkend)
  7923. (goto-char (match-beginning 0))
  7924. (org-open-at-point))))
  7925. ;; This is an internal link, widen the buffer
  7926. (switch-to-buffer-other-window buffer)
  7927. (widen)
  7928. (goto-char marker)
  7929. (when (search-forward l nil lkend)
  7930. (goto-char (match-beginning 0))
  7931. (org-open-at-point)))))
  7932. lk))
  7933. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7934. (save-excursion
  7935. (beginning-of-line 1)
  7936. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7937. (org-open-link-from-string (match-string 1)))
  7938. (t (message "No link to open here")))))
  7939. (defun org-agenda-copy-local-variable (var)
  7940. "Get a variable from a referenced buffer and install it here."
  7941. (let ((m (org-get-at-bol 'org-marker)))
  7942. (when (and m (buffer-live-p (marker-buffer m)))
  7943. (org-set-local var (with-current-buffer (marker-buffer m)
  7944. (symbol-value var))))))
  7945. (defun org-agenda-switch-to (&optional delete-other-windows)
  7946. "Go to the Org-mode file which contains the item at point."
  7947. (interactive)
  7948. (if (and org-return-follows-link
  7949. (not (org-get-at-bol 'org-marker))
  7950. (org-in-regexp org-bracket-link-regexp))
  7951. (org-open-link-from-string (match-string 0))
  7952. (let* ((marker (or (org-get-at-bol 'org-marker)
  7953. (org-agenda-error)))
  7954. (buffer (marker-buffer marker))
  7955. (pos (marker-position marker)))
  7956. (org-pop-to-buffer-same-window buffer)
  7957. (and delete-other-windows (delete-other-windows))
  7958. (widen)
  7959. (goto-char pos)
  7960. (when (derived-mode-p 'org-mode)
  7961. (org-show-context 'agenda)
  7962. (save-excursion
  7963. (and (outline-next-heading)
  7964. (org-flag-heading nil))) ; show the next heading
  7965. (when (outline-invisible-p)
  7966. (show-entry)) ; display invisible text
  7967. (run-hooks 'org-agenda-after-show-hook)))))
  7968. (defun org-agenda-goto-mouse (ev)
  7969. "Go to the Org-mode file which contains the item at the mouse click."
  7970. (interactive "e")
  7971. (mouse-set-point ev)
  7972. (org-agenda-goto))
  7973. (defun org-agenda-show (&optional full-entry)
  7974. "Display the Org-mode file which contains the item at point.
  7975. With prefix argument FULL-ENTRY, make the entire entry visible
  7976. if it was hidden in the outline."
  7977. (interactive "P")
  7978. (let ((win (selected-window)))
  7979. (if full-entry
  7980. (let ((org-show-entry-below t))
  7981. (org-agenda-goto t))
  7982. (org-agenda-goto t))
  7983. (select-window win)))
  7984. (defvar org-agenda-show-window nil)
  7985. (defun org-agenda-show-and-scroll-up (&optional arg)
  7986. "Display the Org-mode file which contains the item at point.
  7987. When called repeatedly, scroll the window that is displaying the buffer.
  7988. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7989. `show-subtree' to display the item, so that drawers and logbooks stay
  7990. folded."
  7991. (interactive "P")
  7992. (let ((win (selected-window)))
  7993. (if (and (window-live-p org-agenda-show-window)
  7994. (eq this-command last-command))
  7995. (progn
  7996. (select-window org-agenda-show-window)
  7997. (ignore-errors (scroll-up)))
  7998. (org-agenda-goto t)
  7999. (if arg (org-show-entry) (show-subtree))
  8000. (setq org-agenda-show-window (selected-window)))
  8001. (select-window win)))
  8002. (defun org-agenda-show-scroll-down ()
  8003. "Scroll down the window showing the agenda."
  8004. (interactive)
  8005. (let ((win (selected-window)))
  8006. (when (window-live-p org-agenda-show-window)
  8007. (select-window org-agenda-show-window)
  8008. (ignore-errors (scroll-down))
  8009. (select-window win))))
  8010. (defun org-agenda-show-1 (&optional more)
  8011. "Display the Org-mode file which contains the item at point.
  8012. The prefix arg selects the amount of information to display:
  8013. 0 hide the subtree
  8014. 1 just show the entry according to defaults.
  8015. 2 show the children view
  8016. 3 show the subtree view
  8017. 4 show the entire subtree and any LOGBOOK drawers
  8018. 5 show the entire subtree and any drawers
  8019. With prefix argument FULL-ENTRY, make the entire entry visible
  8020. if it was hidden in the outline."
  8021. (interactive "p")
  8022. (let ((win (selected-window)))
  8023. (org-agenda-goto t)
  8024. (org-recenter-heading 1)
  8025. (cond
  8026. ((= more 0)
  8027. (hide-subtree)
  8028. (save-excursion
  8029. (org-back-to-heading)
  8030. (run-hook-with-args 'org-cycle-hook 'folded))
  8031. (message "Remote: FOLDED"))
  8032. ((and (org-called-interactively-p 'any) (= more 1))
  8033. (message "Remote: show with default settings"))
  8034. ((= more 2)
  8035. (show-entry)
  8036. (show-children)
  8037. (save-excursion
  8038. (org-back-to-heading)
  8039. (run-hook-with-args 'org-cycle-hook 'children))
  8040. (message "Remote: CHILDREN"))
  8041. ((= more 3)
  8042. (show-subtree)
  8043. (save-excursion
  8044. (org-back-to-heading)
  8045. (run-hook-with-args 'org-cycle-hook 'subtree))
  8046. (message "Remote: SUBTREE"))
  8047. ((= more 4)
  8048. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  8049. (org-drawer-regexp
  8050. (concat "^[ \t]*:\\("
  8051. (mapconcat 'regexp-quote org-drawers "\\|")
  8052. "\\):[ \t]*$")))
  8053. (show-subtree)
  8054. (save-excursion
  8055. (org-back-to-heading)
  8056. (org-cycle-hide-drawers 'subtree)))
  8057. (message "Remote: SUBTREE AND LOGBOOK"))
  8058. ((> more 4)
  8059. (show-subtree)
  8060. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8061. (select-window win)))
  8062. (defun org-recenter-heading (n)
  8063. (save-excursion
  8064. (org-back-to-heading)
  8065. (recenter n)))
  8066. (defvar org-agenda-cycle-counter nil)
  8067. (defun org-agenda-cycle-show (&optional n)
  8068. "Show the current entry in another window, with default settings.
  8069. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8070. When use repeatedly in immediate succession, the remote entry will cycle
  8071. through visibility
  8072. children -> subtree -> folded
  8073. When called with a numeric prefix arg, that arg will be passed through to
  8074. `org-agenda-show-1'. For the interpretation of that argument, see the
  8075. docstring of `org-agenda-show-1'."
  8076. (interactive "P")
  8077. (if (integerp n)
  8078. (setq org-agenda-cycle-counter n)
  8079. (if (not (eq last-command this-command))
  8080. (setq org-agenda-cycle-counter 1)
  8081. (if (equal org-agenda-cycle-counter 0)
  8082. (setq org-agenda-cycle-counter 2)
  8083. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8084. (if (> org-agenda-cycle-counter 3)
  8085. (setq org-agenda-cycle-counter 0)))))
  8086. (org-agenda-show-1 org-agenda-cycle-counter))
  8087. (defun org-agenda-recenter (arg)
  8088. "Display the Org-mode file which contains the item at point and recenter."
  8089. (interactive "P")
  8090. (let ((win (selected-window)))
  8091. (org-agenda-goto t)
  8092. (recenter arg)
  8093. (select-window win)))
  8094. (defun org-agenda-show-mouse (ev)
  8095. "Display the Org-mode file which contains the item at the mouse click."
  8096. (interactive "e")
  8097. (mouse-set-point ev)
  8098. (org-agenda-show))
  8099. (defun org-agenda-check-no-diary ()
  8100. "Check if the entry is a diary link and abort if yes."
  8101. (if (org-get-at-bol 'org-agenda-diary-link)
  8102. (org-agenda-error)))
  8103. (defun org-agenda-error ()
  8104. (error "Command not allowed in this line"))
  8105. (defun org-agenda-tree-to-indirect-buffer (arg)
  8106. "Show the subtree corresponding to the current entry in an indirect buffer.
  8107. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8108. With a numerical prefix ARG, go up to this level and then take that tree.
  8109. With a negative numeric ARG, go up by this number of levels.
  8110. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8111. use the dedicated frame)."
  8112. (interactive "P")
  8113. (if current-prefix-arg
  8114. (org-agenda-do-tree-to-indirect-buffer arg)
  8115. (let ((agenda-buffer (buffer-name))
  8116. (agenda-window (selected-window))
  8117. (indirect-window
  8118. (and org-last-indirect-buffer
  8119. (get-buffer-window org-last-indirect-buffer))))
  8120. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8121. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8122. (eq org-indirect-buffer-display 'dedicated-frame))
  8123. (unwind-protect
  8124. (unless (and indirect-window (window-live-p indirect-window))
  8125. (setq indirect-window (split-window agenda-window)))
  8126. (and indirect-window (select-window indirect-window))
  8127. (switch-to-buffer org-last-indirect-buffer :norecord)
  8128. (fit-window-to-buffer indirect-window)))
  8129. (select-window (get-buffer-window agenda-buffer)))))
  8130. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8131. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8132. (org-agenda-check-no-diary)
  8133. (let* ((marker (or (org-get-at-bol 'org-marker)
  8134. (org-agenda-error)))
  8135. (buffer (marker-buffer marker))
  8136. (pos (marker-position marker)))
  8137. (with-current-buffer buffer
  8138. (save-excursion
  8139. (goto-char pos)
  8140. (funcall 'org-tree-to-indirect-buffer arg)))))
  8141. (defvar org-last-heading-marker (make-marker)
  8142. "Marker pointing to the headline that last changed its TODO state
  8143. by a remote command from the agenda.")
  8144. (defun org-agenda-todo-nextset ()
  8145. "Switch TODO entry to next sequence."
  8146. (interactive)
  8147. (org-agenda-todo 'nextset))
  8148. (defun org-agenda-todo-previousset ()
  8149. "Switch TODO entry to previous sequence."
  8150. (interactive)
  8151. (org-agenda-todo 'previousset))
  8152. (defun org-agenda-todo (&optional arg)
  8153. "Cycle TODO state of line at point, also in Org-mode file.
  8154. This changes the line at point, all other lines in the agenda referring to
  8155. the same tree node, and the headline of the tree node in the Org-mode file."
  8156. (interactive "P")
  8157. (org-agenda-check-no-diary)
  8158. (let* ((col (current-column))
  8159. (marker (or (org-get-at-bol 'org-marker)
  8160. (org-agenda-error)))
  8161. (buffer (marker-buffer marker))
  8162. (pos (marker-position marker))
  8163. (hdmarker (org-get-at-bol 'org-hd-marker))
  8164. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8165. (inhibit-read-only t)
  8166. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8167. (org-with-remote-undo buffer
  8168. (with-current-buffer buffer
  8169. (widen)
  8170. (goto-char pos)
  8171. (org-show-context 'agenda)
  8172. (save-excursion
  8173. (and (outline-next-heading)
  8174. (org-flag-heading nil))) ; show the next heading
  8175. (let ((current-prefix-arg arg))
  8176. (call-interactively 'org-todo))
  8177. (and (bolp) (forward-char 1))
  8178. (setq newhead (org-get-heading))
  8179. (when (and (org-bound-and-true-p
  8180. org-agenda-headline-snapshot-before-repeat)
  8181. (not (equal org-agenda-headline-snapshot-before-repeat
  8182. newhead))
  8183. todayp)
  8184. (setq newhead org-agenda-headline-snapshot-before-repeat
  8185. just-one t))
  8186. (save-excursion
  8187. (org-back-to-heading)
  8188. (move-marker org-last-heading-marker (point))))
  8189. (beginning-of-line 1)
  8190. (save-window-excursion
  8191. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8192. (when (org-bound-and-true-p org-clock-out-when-done)
  8193. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8194. newhead)
  8195. (org-agenda-unmark-clocking-task))
  8196. (org-move-to-column col))))
  8197. (defun org-agenda-add-note (&optional arg)
  8198. "Add a time-stamped note to the entry at point."
  8199. (interactive "P")
  8200. (org-agenda-check-no-diary)
  8201. (let* ((marker (or (org-get-at-bol 'org-marker)
  8202. (org-agenda-error)))
  8203. (buffer (marker-buffer marker))
  8204. (pos (marker-position marker))
  8205. (hdmarker (org-get-at-bol 'org-hd-marker))
  8206. (inhibit-read-only t))
  8207. (with-current-buffer buffer
  8208. (widen)
  8209. (goto-char pos)
  8210. (org-show-context 'agenda)
  8211. (save-excursion
  8212. (and (outline-next-heading)
  8213. (org-flag-heading nil))) ; show the next heading
  8214. (org-add-note))))
  8215. (defun org-agenda-change-all-lines (newhead hdmarker
  8216. &optional fixface just-this)
  8217. "Change all lines in the agenda buffer which match HDMARKER.
  8218. The new content of the line will be NEWHEAD (as modified by
  8219. `org-agenda-format-item'). HDMARKER is checked with
  8220. `equal' against all `org-hd-marker' text properties in the file.
  8221. If FIXFACE is non-nil, the face of each item is modified according to
  8222. the new TODO state.
  8223. If JUST-THIS is non-nil, change just the current line, not all.
  8224. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8225. (let* ((inhibit-read-only t)
  8226. (line (org-current-line))
  8227. (org-agenda-buffer (current-buffer))
  8228. (thetags (with-current-buffer (marker-buffer hdmarker)
  8229. (save-excursion (save-restriction (widen)
  8230. (goto-char hdmarker)
  8231. (org-get-tags-at)))))
  8232. props m pl undone-face done-face finish new dotime level cat tags)
  8233. (save-excursion
  8234. (goto-char (point-max))
  8235. (beginning-of-line 1)
  8236. (while (not finish)
  8237. (setq finish (bobp))
  8238. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8239. (or (not just-this) (= (org-current-line) line))
  8240. (equal m hdmarker))
  8241. (setq props (text-properties-at (point))
  8242. dotime (org-get-at-bol 'dotime)
  8243. cat (org-get-at-bol 'org-category)
  8244. level (org-get-at-bol 'level)
  8245. tags thetags
  8246. new
  8247. (let ((org-prefix-format-compiled
  8248. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8249. org-prefix-format-compiled))
  8250. (extra (org-get-at-bol 'extra)))
  8251. (with-current-buffer (marker-buffer hdmarker)
  8252. (save-excursion
  8253. (save-restriction
  8254. (widen)
  8255. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8256. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8257. undone-face (org-get-at-bol 'undone-face)
  8258. done-face (org-get-at-bol 'done-face))
  8259. (beginning-of-line 1)
  8260. (cond
  8261. ((equal new "")
  8262. (and (looking-at ".*\n?") (replace-match "")))
  8263. ((looking-at ".*")
  8264. (replace-match new t t)
  8265. (beginning-of-line 1)
  8266. (add-text-properties (point-at-bol) (point-at-eol) props)
  8267. (when fixface
  8268. (add-text-properties
  8269. (point-at-bol) (point-at-eol)
  8270. (list 'face
  8271. (if org-last-todo-state-is-todo
  8272. undone-face done-face))))
  8273. (org-agenda-highlight-todo 'line)
  8274. (beginning-of-line 1))
  8275. (t (error "Line update did not work")))
  8276. (save-restriction
  8277. (narrow-to-region (point-at-bol) (point-at-eol))
  8278. (org-agenda-finalize)))
  8279. (beginning-of-line 0)))))
  8280. (defun org-agenda-align-tags (&optional line)
  8281. "Align all tags in agenda items to `org-agenda-tags-column'."
  8282. (let ((inhibit-read-only t) l c)
  8283. (save-excursion
  8284. (goto-char (if line (point-at-bol) (point-min)))
  8285. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8286. (if line (point-at-eol) nil) t)
  8287. (add-text-properties
  8288. (match-beginning 2) (match-end 2)
  8289. (list 'face (delq nil (let ((prop (get-text-property
  8290. (match-beginning 2) 'face)))
  8291. (or (listp prop) (setq prop (list prop)))
  8292. (if (memq 'org-tag prop)
  8293. prop
  8294. (cons 'org-tag prop))))))
  8295. (setq l (- (match-end 2) (match-beginning 2))
  8296. c (if (< org-agenda-tags-column 0)
  8297. (- (abs org-agenda-tags-column) l)
  8298. org-agenda-tags-column))
  8299. (delete-region (match-beginning 1) (match-end 1))
  8300. (goto-char (match-beginning 1))
  8301. (insert (org-add-props
  8302. (make-string (max 1 (- c (current-column))) ?\ )
  8303. (plist-put (copy-sequence (text-properties-at (point)))
  8304. 'face nil))))
  8305. (goto-char (point-min))
  8306. (org-font-lock-add-tag-faces (point-max)))))
  8307. (defun org-agenda-priority-up ()
  8308. "Increase the priority of line at point, also in Org-mode file."
  8309. (interactive)
  8310. (org-agenda-priority 'up))
  8311. (defun org-agenda-priority-down ()
  8312. "Decrease the priority of line at point, also in Org-mode file."
  8313. (interactive)
  8314. (org-agenda-priority 'down))
  8315. (defun org-agenda-priority (&optional force-direction)
  8316. "Set the priority of line at point, also in Org-mode file.
  8317. This changes the line at point, all other lines in the agenda referring to
  8318. the same tree node, and the headline of the tree node in the Org-mode file.
  8319. Called with a universal prefix arg, show the priority instead of setting it."
  8320. (interactive "P")
  8321. (if (equal force-direction '(4))
  8322. (org-show-priority)
  8323. (unless org-enable-priority-commands
  8324. (error "Priority commands are disabled"))
  8325. (org-agenda-check-no-diary)
  8326. (let* ((col (current-column))
  8327. (marker (or (org-get-at-bol 'org-marker)
  8328. (org-agenda-error)))
  8329. (hdmarker (org-get-at-bol 'org-hd-marker))
  8330. (buffer (marker-buffer hdmarker))
  8331. (pos (marker-position hdmarker))
  8332. (inhibit-read-only t)
  8333. newhead)
  8334. (org-with-remote-undo buffer
  8335. (with-current-buffer buffer
  8336. (widen)
  8337. (goto-char pos)
  8338. (org-show-context 'agenda)
  8339. (save-excursion
  8340. (and (outline-next-heading)
  8341. (org-flag-heading nil))) ; show the next heading
  8342. (funcall 'org-priority force-direction)
  8343. (end-of-line 1)
  8344. (setq newhead (org-get-heading)))
  8345. (org-agenda-change-all-lines newhead hdmarker)
  8346. (org-move-to-column col)))))
  8347. ;; FIXME: should fix the tags property of the agenda line.
  8348. (defun org-agenda-set-tags (&optional tag onoff)
  8349. "Set tags for the current headline."
  8350. (interactive)
  8351. (org-agenda-check-no-diary)
  8352. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8353. (call-interactively 'org-change-tag-in-region)
  8354. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8355. (org-agenda-error)))
  8356. (buffer (marker-buffer hdmarker))
  8357. (pos (marker-position hdmarker))
  8358. (inhibit-read-only t)
  8359. newhead)
  8360. (org-with-remote-undo buffer
  8361. (with-current-buffer buffer
  8362. (widen)
  8363. (goto-char pos)
  8364. (save-excursion
  8365. (org-show-context 'agenda))
  8366. (save-excursion
  8367. (and (outline-next-heading)
  8368. (org-flag-heading nil))) ; show the next heading
  8369. (goto-char pos)
  8370. (if tag
  8371. (org-toggle-tag tag onoff)
  8372. (call-interactively 'org-set-tags))
  8373. (end-of-line 1)
  8374. (setq newhead (org-get-heading)))
  8375. (org-agenda-change-all-lines newhead hdmarker)
  8376. (beginning-of-line 1)))))
  8377. (defun org-agenda-set-property ()
  8378. "Set a property for the current headline."
  8379. (interactive)
  8380. (org-agenda-check-no-diary)
  8381. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8382. (org-agenda-error)))
  8383. (buffer (marker-buffer hdmarker))
  8384. (pos (marker-position hdmarker))
  8385. (inhibit-read-only t)
  8386. newhead)
  8387. (org-with-remote-undo buffer
  8388. (with-current-buffer buffer
  8389. (widen)
  8390. (goto-char pos)
  8391. (save-excursion
  8392. (org-show-context 'agenda))
  8393. (save-excursion
  8394. (and (outline-next-heading)
  8395. (org-flag-heading nil))) ; show the next heading
  8396. (goto-char pos)
  8397. (call-interactively 'org-set-property)))))
  8398. (defun org-agenda-set-effort ()
  8399. "Set the effort property for the current headline."
  8400. (interactive)
  8401. (org-agenda-check-no-diary)
  8402. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8403. (org-agenda-error)))
  8404. (buffer (marker-buffer hdmarker))
  8405. (pos (marker-position hdmarker))
  8406. (inhibit-read-only t)
  8407. newhead)
  8408. (org-with-remote-undo buffer
  8409. (with-current-buffer buffer
  8410. (widen)
  8411. (goto-char pos)
  8412. (save-excursion
  8413. (org-show-context 'agenda))
  8414. (save-excursion
  8415. (and (outline-next-heading)
  8416. (org-flag-heading nil))) ; show the next heading
  8417. (goto-char pos)
  8418. (call-interactively 'org-set-effort)
  8419. (end-of-line 1)
  8420. (setq newhead (org-get-heading)))
  8421. (org-agenda-change-all-lines newhead hdmarker))))
  8422. (defun org-agenda-toggle-archive-tag ()
  8423. "Toggle the archive tag for the current entry."
  8424. (interactive)
  8425. (org-agenda-check-no-diary)
  8426. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8427. (org-agenda-error)))
  8428. (buffer (marker-buffer hdmarker))
  8429. (pos (marker-position hdmarker))
  8430. (inhibit-read-only t)
  8431. newhead)
  8432. (org-with-remote-undo buffer
  8433. (with-current-buffer buffer
  8434. (widen)
  8435. (goto-char pos)
  8436. (org-show-context 'agenda)
  8437. (save-excursion
  8438. (and (outline-next-heading)
  8439. (org-flag-heading nil))) ; show the next heading
  8440. (call-interactively 'org-toggle-archive-tag)
  8441. (end-of-line 1)
  8442. (setq newhead (org-get-heading)))
  8443. (org-agenda-change-all-lines newhead hdmarker)
  8444. (beginning-of-line 1))))
  8445. (defun org-agenda-do-date-later (arg)
  8446. (interactive "P")
  8447. (cond
  8448. ((or (equal arg '(16))
  8449. (memq last-command
  8450. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8451. (setq this-command 'org-agenda-date-later-minutes)
  8452. (org-agenda-date-later-minutes 1))
  8453. ((or (equal arg '(4))
  8454. (memq last-command
  8455. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8456. (setq this-command 'org-agenda-date-later-hours)
  8457. (org-agenda-date-later-hours 1))
  8458. (t
  8459. (org-agenda-date-later (prefix-numeric-value arg)))))
  8460. (defun org-agenda-do-date-earlier (arg)
  8461. (interactive "P")
  8462. (cond
  8463. ((or (equal arg '(16))
  8464. (memq last-command
  8465. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8466. (setq this-command 'org-agenda-date-earlier-minutes)
  8467. (org-agenda-date-earlier-minutes 1))
  8468. ((or (equal arg '(4))
  8469. (memq last-command
  8470. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8471. (setq this-command 'org-agenda-date-earlier-hours)
  8472. (org-agenda-date-earlier-hours 1))
  8473. (t
  8474. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8475. (defun org-agenda-date-later (arg &optional what)
  8476. "Change the date of this item to ARG day(s) later."
  8477. (interactive "p")
  8478. (org-agenda-check-type t 'agenda 'timeline)
  8479. (org-agenda-check-no-diary)
  8480. (let* ((marker (or (org-get-at-bol 'org-marker)
  8481. (org-agenda-error)))
  8482. (buffer (marker-buffer marker))
  8483. (pos (marker-position marker))
  8484. cdate today)
  8485. (org-with-remote-undo buffer
  8486. (with-current-buffer buffer
  8487. (widen)
  8488. (goto-char pos)
  8489. (if (not (org-at-timestamp-p))
  8490. (error "Cannot find time stamp"))
  8491. (when (and org-agenda-move-date-from-past-immediately-to-today
  8492. (equal arg 1)
  8493. (or (not what) (eq what 'day))
  8494. (not (save-match-data (org-at-date-range-p))))
  8495. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8496. cdate (calendar-absolute-from-gregorian
  8497. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8498. today (org-today))
  8499. (if (> today cdate)
  8500. ;; immediately shift to today
  8501. (setq arg (- today cdate))))
  8502. (org-timestamp-change arg (or what 'day))
  8503. (when (and (org-at-date-range-p)
  8504. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8505. (let ((end org-last-changed-timestamp))
  8506. (org-timestamp-change arg (or what 'day))
  8507. (setq org-last-changed-timestamp
  8508. (concat org-last-changed-timestamp "--" end)))))
  8509. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8510. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8511. (defun org-agenda-date-earlier (arg &optional what)
  8512. "Change the date of this item to ARG day(s) earlier."
  8513. (interactive "p")
  8514. (org-agenda-date-later (- arg) what))
  8515. (defun org-agenda-date-later-minutes (arg)
  8516. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8517. (interactive "p")
  8518. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8519. (org-agenda-date-later arg 'minute))
  8520. (defun org-agenda-date-earlier-minutes (arg)
  8521. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8522. (interactive "p")
  8523. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8524. (org-agenda-date-earlier arg 'minute))
  8525. (defun org-agenda-date-later-hours (arg)
  8526. "Change the time of this item, in hour steps."
  8527. (interactive "p")
  8528. (org-agenda-date-later arg 'hour))
  8529. (defun org-agenda-date-earlier-hours (arg)
  8530. "Change the time of this item, in hour steps."
  8531. (interactive "p")
  8532. (org-agenda-date-earlier arg 'hour))
  8533. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8534. "Show new date stamp via text properties."
  8535. ;; We use text properties to make this undoable
  8536. (let ((inhibit-read-only t))
  8537. (setq stamp (concat prefix " => " stamp " "))
  8538. (save-excursion
  8539. (goto-char (point-max))
  8540. (while (not (bobp))
  8541. (when (equal marker (org-get-at-bol 'org-marker))
  8542. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8543. (org-move-to-column (- (window-width) (length stamp)) t)
  8544. (if (featurep 'xemacs)
  8545. ;; Use `duplicable' property to trigger undo recording
  8546. (let ((ex (make-extent nil nil))
  8547. (gl (make-glyph stamp)))
  8548. (set-glyph-face gl 'secondary-selection)
  8549. (set-extent-properties
  8550. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8551. (insert-extent ex (1- (point)) (point-at-eol)))
  8552. (add-text-properties
  8553. (1- (point)) (point-at-eol)
  8554. (list 'display (org-add-props stamp nil
  8555. 'face '(secondary-selection default)))))
  8556. (beginning-of-line 1))
  8557. (beginning-of-line 0)))))
  8558. (defun org-agenda-date-prompt (arg)
  8559. "Change the date of this item. Date is prompted for, with default today.
  8560. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8561. be used to request time specification in the time stamp."
  8562. (interactive "P")
  8563. (org-agenda-check-type t 'agenda 'timeline)
  8564. (org-agenda-check-no-diary)
  8565. (let* ((marker (or (org-get-at-bol 'org-marker)
  8566. (org-agenda-error)))
  8567. (buffer (marker-buffer marker))
  8568. (pos (marker-position marker)))
  8569. (org-with-remote-undo buffer
  8570. (with-current-buffer buffer
  8571. (widen)
  8572. (goto-char pos)
  8573. (if (not (org-at-timestamp-p t))
  8574. (error "Cannot find time stamp"))
  8575. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8576. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8577. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8578. (defun org-agenda-schedule (arg &optional time)
  8579. "Schedule the item at point.
  8580. ARG is passed through to `org-schedule'."
  8581. (interactive "P")
  8582. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8583. (org-agenda-check-no-diary)
  8584. (let* ((marker (or (org-get-at-bol 'org-marker)
  8585. (org-agenda-error)))
  8586. (type (marker-insertion-type marker))
  8587. (buffer (marker-buffer marker))
  8588. (pos (marker-position marker))
  8589. (org-insert-labeled-timestamps-at-point nil)
  8590. ts)
  8591. (set-marker-insertion-type marker t)
  8592. (org-with-remote-undo buffer
  8593. (with-current-buffer buffer
  8594. (widen)
  8595. (goto-char pos)
  8596. (setq ts (org-schedule arg time)))
  8597. (org-agenda-show-new-time marker ts " S"))
  8598. (message "%s" ts)))
  8599. (defun org-agenda-deadline (arg &optional time)
  8600. "Schedule the item at point.
  8601. ARG is passed through to `org-deadline'."
  8602. (interactive "P")
  8603. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8604. (org-agenda-check-no-diary)
  8605. (let* ((marker (or (org-get-at-bol 'org-marker)
  8606. (org-agenda-error)))
  8607. (buffer (marker-buffer marker))
  8608. (pos (marker-position marker))
  8609. (org-insert-labeled-timestamps-at-point nil)
  8610. ts)
  8611. (org-with-remote-undo buffer
  8612. (with-current-buffer buffer
  8613. (widen)
  8614. (goto-char pos)
  8615. (setq ts (org-deadline arg time)))
  8616. (org-agenda-show-new-time marker ts " D"))
  8617. (message "%s" ts)))
  8618. (defun org-agenda-clock-in (&optional arg)
  8619. "Start the clock on the currently selected item."
  8620. (interactive "P")
  8621. (org-agenda-check-no-diary)
  8622. (if (equal arg '(4))
  8623. (org-clock-in arg)
  8624. (let* ((marker (or (org-get-at-bol 'org-marker)
  8625. (org-agenda-error)))
  8626. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8627. (pos (marker-position marker))
  8628. (col (current-column))
  8629. newhead)
  8630. (org-with-remote-undo (marker-buffer marker)
  8631. (with-current-buffer (marker-buffer marker)
  8632. (widen)
  8633. (goto-char pos)
  8634. (org-show-context 'agenda)
  8635. (org-show-entry)
  8636. (org-cycle-hide-drawers 'children)
  8637. (org-clock-in arg)
  8638. (setq newhead (org-get-heading)))
  8639. (org-agenda-change-all-lines newhead hdmarker))
  8640. (org-move-to-column col))))
  8641. (defun org-agenda-clock-out ()
  8642. "Stop the currently running clock."
  8643. (interactive)
  8644. (unless (marker-buffer org-clock-marker)
  8645. (error "No running clock"))
  8646. (let ((marker (make-marker)) (col (current-column)) newhead)
  8647. (org-with-remote-undo (marker-buffer org-clock-marker)
  8648. (with-current-buffer (marker-buffer org-clock-marker)
  8649. (save-excursion
  8650. (save-restriction
  8651. (widen)
  8652. (goto-char org-clock-marker)
  8653. (org-back-to-heading t)
  8654. (move-marker marker (point))
  8655. (org-clock-out)
  8656. (setq newhead (org-get-heading))))))
  8657. (org-agenda-change-all-lines newhead marker)
  8658. (move-marker marker nil)
  8659. (org-move-to-column col)
  8660. (org-agenda-unmark-clocking-task)))
  8661. (defun org-agenda-clock-cancel (&optional arg)
  8662. "Cancel the currently running clock."
  8663. (interactive "P")
  8664. (unless (marker-buffer org-clock-marker)
  8665. (user-error "No running clock"))
  8666. (org-with-remote-undo (marker-buffer org-clock-marker)
  8667. (org-clock-cancel)))
  8668. (defun org-agenda-clock-goto ()
  8669. "Jump to the currently clocked in task within the agenda.
  8670. If the currently clocked in task is not listed in the agenda
  8671. buffer, display it in another window."
  8672. (interactive)
  8673. (let (pos)
  8674. (mapc (lambda (o)
  8675. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8676. (setq pos (overlay-start o))))
  8677. (overlays-in (point-min) (point-max)))
  8678. (cond (pos (goto-char pos))
  8679. ;; If the currently clocked entry is not in the agenda
  8680. ;; buffer, we visit it in another window:
  8681. (org-clock-current-task
  8682. (org-switch-to-buffer-other-window (org-clock-goto)))
  8683. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8684. (defun org-agenda-diary-entry-in-org-file ()
  8685. "Make a diary entry in the file `org-agenda-diary-file'."
  8686. (let (d1 d2 char (text "") dp1 dp2)
  8687. (if (equal (buffer-name) "*Calendar*")
  8688. (setq d1 (calendar-cursor-to-date t)
  8689. d2 (car calendar-mark-ring))
  8690. (setq dp1 (get-text-property (point-at-bol) 'day))
  8691. (unless dp1 (user-error "No date defined in current line"))
  8692. (setq d1 (calendar-gregorian-from-absolute dp1)
  8693. d2 (and (ignore-errors (mark))
  8694. (save-excursion
  8695. (goto-char (mark))
  8696. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8697. (calendar-gregorian-from-absolute dp2))))
  8698. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8699. (setq char (read-char-exclusive))
  8700. (cond
  8701. ((equal char ?d)
  8702. (setq text (read-string "Day entry: "))
  8703. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8704. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8705. ((equal char ?a)
  8706. (setq d1 (list (car d1) (nth 1 d1)
  8707. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8708. (nth 2 d1))))
  8709. (setq text (read-string "Anniversary (use %d to show years): "))
  8710. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8711. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8712. ((equal char ?b)
  8713. (setq text (read-string "Block entry: "))
  8714. (unless (and d1 d2 (not (equal d1 d2)))
  8715. (user-error "No block of days selected"))
  8716. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8717. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8718. ((equal char ?j)
  8719. (org-switch-to-buffer-other-window
  8720. (find-file-noselect org-agenda-diary-file))
  8721. (require 'org-datetree)
  8722. (org-datetree-find-date-create d1)
  8723. (org-reveal t))
  8724. (t (user-error "Invalid selection character `%c'" char)))))
  8725. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8726. "Where in `org-agenda-diary-file' should new entries be added?
  8727. Valid values:
  8728. date-tree in the date tree, as child of the date
  8729. top-level as top-level entries at the end of the file."
  8730. :group 'org-agenda
  8731. :type '(choice
  8732. (const :tag "in a date tree" date-tree)
  8733. (const :tag "as top level at end of file" top-level)))
  8734. (defcustom org-agenda-insert-diary-extract-time nil
  8735. "Non-nil means extract any time specification from the diary entry."
  8736. :group 'org-agenda
  8737. :version "24.1"
  8738. :type 'boolean)
  8739. (defcustom org-agenda-bulk-mark-char ">"
  8740. "A single-character string to be used as the bulk mark."
  8741. :group 'org-agenda
  8742. :version "24.1"
  8743. :type 'string)
  8744. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8745. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8746. If TEXT is not empty, it will become the headline of the new entry, and
  8747. the resulting entry will not be shown. When TEXT is empty, switch to
  8748. `org-agenda-diary-file' and let the user finish the entry there."
  8749. (let ((cw (current-window-configuration)))
  8750. (org-switch-to-buffer-other-window
  8751. (find-file-noselect org-agenda-diary-file))
  8752. (widen)
  8753. (goto-char (point-min))
  8754. (cond
  8755. ((eq type 'anniversary)
  8756. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8757. (progn
  8758. (or (org-at-heading-p t)
  8759. (progn
  8760. (outline-next-heading)
  8761. (insert "* Anniversaries\n\n")
  8762. (beginning-of-line -1)))))
  8763. (outline-next-heading)
  8764. (org-back-over-empty-lines)
  8765. (backward-char 1)
  8766. (insert "\n")
  8767. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8768. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8769. ((eq type 'day)
  8770. (let ((org-prefix-has-time t)
  8771. (org-agenda-time-leading-zero t)
  8772. fmt time time2)
  8773. (if org-agenda-insert-diary-extract-time
  8774. ;; Use org-agenda-format-item to parse text for a time-range and
  8775. ;; remove it. FIXME: This is a hack, we should refactor
  8776. ;; that function to make time extraction available separately
  8777. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8778. time (get-text-property 0 'time fmt)
  8779. time2 (if (> (length time) 0)
  8780. ;; split-string removes trailing ...... if
  8781. ;; no end time given. First space
  8782. ;; separates time from date.
  8783. (concat " " (car (split-string time "\\.")))
  8784. nil)
  8785. text (get-text-property 0 'txt fmt)))
  8786. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8787. (org-agenda-insert-diary-as-top-level text)
  8788. (require 'org-datetree)
  8789. (org-datetree-find-date-create d1)
  8790. (org-agenda-insert-diary-make-new-entry text))
  8791. (org-insert-time-stamp (org-time-from-absolute
  8792. (calendar-absolute-from-gregorian d1))
  8793. nil nil nil nil time2))
  8794. (end-of-line 0))
  8795. ((eq type 'block)
  8796. (if (> (calendar-absolute-from-gregorian d1)
  8797. (calendar-absolute-from-gregorian d2))
  8798. (setq d1 (prog1 d2 (setq d2 d1))))
  8799. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8800. (org-agenda-insert-diary-as-top-level text)
  8801. (require 'org-datetree)
  8802. (org-datetree-find-date-create d1)
  8803. (org-agenda-insert-diary-make-new-entry text))
  8804. (org-insert-time-stamp (org-time-from-absolute
  8805. (calendar-absolute-from-gregorian d1)))
  8806. (insert "--")
  8807. (org-insert-time-stamp (org-time-from-absolute
  8808. (calendar-absolute-from-gregorian d2)))
  8809. (end-of-line 0)))
  8810. (if (string-match "\\S-" text)
  8811. (progn
  8812. (set-window-configuration cw)
  8813. (message "%s entry added to %s"
  8814. (capitalize (symbol-name type))
  8815. (abbreviate-file-name org-agenda-diary-file)))
  8816. (org-reveal t)
  8817. (message "Please finish entry here"))))
  8818. (defun org-agenda-insert-diary-as-top-level (text)
  8819. "Make new entry as a top-level entry at the end of the file.
  8820. Add TEXT as headline, and position the cursor in the second line so that
  8821. a timestamp can be added there."
  8822. (widen)
  8823. (goto-char (point-max))
  8824. (or (bolp) (insert "\n"))
  8825. (insert "* " text "\n")
  8826. (if org-adapt-indentation (org-indent-to-column 2)))
  8827. (defun org-agenda-insert-diary-make-new-entry (text)
  8828. "Make a new entry with TEXT as the first child of the current subtree.
  8829. Position the point in the line right after the new heading so
  8830. that a timestamp can be added there."
  8831. (let ((org-show-following-heading t)
  8832. (org-show-siblings t)
  8833. (org-show-hierarchy-above t)
  8834. (org-show-entry-below t)
  8835. col)
  8836. (outline-next-heading)
  8837. (org-back-over-empty-lines)
  8838. (or (looking-at "[ \t]*$")
  8839. (progn (insert "\n") (backward-char 1)))
  8840. (org-insert-heading nil t)
  8841. (org-do-demote)
  8842. (setq col (current-column))
  8843. (insert text "\n")
  8844. (if org-adapt-indentation (org-indent-to-column col))
  8845. (let ((org-show-following-heading t)
  8846. (org-show-siblings t)
  8847. (org-show-hierarchy-above t)
  8848. (org-show-entry-below t))
  8849. (org-show-context))))
  8850. (defun org-agenda-diary-entry ()
  8851. "Make a diary entry, like the `i' command from the calendar.
  8852. All the standard commands work: block, weekly etc.
  8853. When `org-agenda-diary-file' points to a file,
  8854. `org-agenda-diary-entry-in-org-file' is called instead to create
  8855. entries in that Org-mode file."
  8856. (interactive)
  8857. (if (not (eq org-agenda-diary-file 'diary-file))
  8858. (org-agenda-diary-entry-in-org-file)
  8859. (require 'diary-lib)
  8860. (let* ((char (progn
  8861. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8862. (read-char-exclusive)))
  8863. (cmd (cdr (assoc char
  8864. '((?d . insert-diary-entry)
  8865. (?w . insert-weekly-diary-entry)
  8866. (?m . insert-monthly-diary-entry)
  8867. (?y . insert-yearly-diary-entry)
  8868. (?a . insert-anniversary-diary-entry)
  8869. (?b . insert-block-diary-entry)
  8870. (?c . insert-cyclic-diary-entry)))))
  8871. (oldf (symbol-function 'calendar-cursor-to-date))
  8872. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8873. (point (point))
  8874. (mark (or (mark t) (point))))
  8875. (unless cmd
  8876. (user-error "No command associated with <%c>" char))
  8877. (unless (and (get-text-property point 'day)
  8878. (or (not (equal ?b char))
  8879. (get-text-property mark 'day)))
  8880. (user-error "Don't know which date to use for diary entry"))
  8881. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8882. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8883. (let ((calendar-mark-ring
  8884. (list (calendar-gregorian-from-absolute
  8885. (or (get-text-property mark 'day)
  8886. (get-text-property point 'day))))))
  8887. (unwind-protect
  8888. (progn
  8889. (fset 'calendar-cursor-to-date
  8890. (lambda (&optional error dummy)
  8891. (calendar-gregorian-from-absolute
  8892. (get-text-property point 'day))))
  8893. (call-interactively cmd))
  8894. (fset 'calendar-cursor-to-date oldf))))))
  8895. (defun org-agenda-execute-calendar-command (cmd)
  8896. "Execute a calendar command from the agenda with date from cursor."
  8897. (org-agenda-check-type t 'agenda 'timeline)
  8898. (require 'diary-lib)
  8899. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8900. (user-error "Don't know which date to use for the calendar command"))
  8901. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8902. (point (point))
  8903. (date (calendar-gregorian-from-absolute
  8904. (get-text-property point 'day)))
  8905. ;; the following 2 vars are needed in the calendar
  8906. (displayed-month (car date))
  8907. (displayed-year (nth 2 date)))
  8908. (unwind-protect
  8909. (progn
  8910. (fset 'calendar-cursor-to-date
  8911. (lambda (&optional error dummy)
  8912. (calendar-gregorian-from-absolute
  8913. (get-text-property point 'day))))
  8914. (call-interactively cmd))
  8915. (fset 'calendar-cursor-to-date oldf))))
  8916. (defun org-agenda-phases-of-moon ()
  8917. "Display the phases of the moon for the 3 months around the cursor date."
  8918. (interactive)
  8919. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8920. (defun org-agenda-holidays ()
  8921. "Display the holidays for the 3 months around the cursor date."
  8922. (interactive)
  8923. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8924. (defvar calendar-longitude) ; defined in calendar.el
  8925. (defvar calendar-latitude) ; defined in calendar.el
  8926. (defvar calendar-location-name) ; defined in calendar.el
  8927. (defun org-agenda-sunrise-sunset (arg)
  8928. "Display sunrise and sunset for the cursor date.
  8929. Latitude and longitude can be specified with the variables
  8930. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8931. argument, latitude and longitude will be prompted for."
  8932. (interactive "P")
  8933. (require 'solar)
  8934. (let ((calendar-longitude (if arg nil calendar-longitude))
  8935. (calendar-latitude (if arg nil calendar-latitude))
  8936. (calendar-location-name
  8937. (if arg "the given coordinates" calendar-location-name)))
  8938. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8939. (defun org-agenda-goto-calendar ()
  8940. "Open the Emacs calendar with the date at the cursor."
  8941. (interactive)
  8942. (org-agenda-check-type t 'agenda 'timeline)
  8943. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8944. (user-error "Don't know which date to open in calendar")))
  8945. (date (calendar-gregorian-from-absolute day))
  8946. (calendar-move-hook nil)
  8947. (calendar-view-holidays-initially-flag nil)
  8948. (calendar-view-diary-initially-flag nil))
  8949. (calendar)
  8950. (calendar-goto-date date)))
  8951. ;;;###autoload
  8952. (defun org-calendar-goto-agenda ()
  8953. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8954. This is a command that has to be installed in `calendar-mode-map'."
  8955. (interactive)
  8956. (org-agenda-list nil (calendar-absolute-from-gregorian
  8957. (calendar-cursor-to-date))
  8958. nil))
  8959. (defun org-agenda-convert-date ()
  8960. (interactive)
  8961. (org-agenda-check-type t 'agenda 'timeline)
  8962. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8963. date s)
  8964. (unless day
  8965. (user-error "Don't know which date to convert"))
  8966. (setq date (calendar-gregorian-from-absolute day))
  8967. (setq s (concat
  8968. "Gregorian: " (calendar-date-string date) "\n"
  8969. "ISO: " (calendar-iso-date-string date) "\n"
  8970. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8971. "Julian: " (calendar-julian-date-string date) "\n"
  8972. "Astron. JD: " (calendar-astro-date-string date)
  8973. " (Julian date number at noon UTC)\n"
  8974. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8975. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8976. "French: " (calendar-french-date-string date) "\n"
  8977. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8978. "Mayan: " (calendar-mayan-date-string date) "\n"
  8979. "Coptic: " (calendar-coptic-date-string date) "\n"
  8980. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8981. "Persian: " (calendar-persian-date-string date) "\n"
  8982. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8983. (with-output-to-temp-buffer "*Dates*"
  8984. (princ s))
  8985. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8986. ;;; Bulk commands
  8987. (defun org-agenda-bulk-marked-p ()
  8988. (eq (get-char-property (point-at-bol) 'type)
  8989. 'org-marked-entry-overlay))
  8990. (defun org-agenda-bulk-mark (&optional arg)
  8991. "Mark the entry at point for future bulk action."
  8992. (interactive "p")
  8993. (dotimes (i (or arg 1))
  8994. (unless (org-get-at-bol 'org-agenda-diary-link)
  8995. (let* ((m (org-get-at-bol 'org-hd-marker))
  8996. ov)
  8997. (unless (org-agenda-bulk-marked-p)
  8998. (unless m (user-error "Nothing to mark at point"))
  8999. (push m org-agenda-bulk-marked-entries)
  9000. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9001. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9002. (org-get-todo-face "TODO")
  9003. 'evaporate)
  9004. (overlay-put ov 'type 'org-marked-entry-overlay))
  9005. (end-of-line 1)
  9006. (or (ignore-errors
  9007. (goto-char (next-single-property-change (point) 'txt)))
  9008. (beginning-of-line 2))
  9009. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9010. (beginning-of-line 2))
  9011. (message "%d entries marked for bulk action"
  9012. (length org-agenda-bulk-marked-entries))))))
  9013. (defun org-agenda-bulk-mark-all ()
  9014. "Mark all entries for future agenda bulk action."
  9015. (interactive)
  9016. (org-agenda-bulk-mark-regexp "."))
  9017. (defun org-agenda-bulk-mark-regexp (regexp)
  9018. "Mark entries matching REGEXP for future agenda bulk action."
  9019. (interactive "sMark entries matching regexp: ")
  9020. (let ((entries-marked 0) txt-at-point)
  9021. (save-excursion
  9022. (goto-char (point-min))
  9023. (goto-char (next-single-property-change (point) 'txt))
  9024. (while (and (re-search-forward regexp nil t)
  9025. (setq txt-at-point (get-text-property (point) 'txt)))
  9026. (when (string-match regexp txt-at-point)
  9027. (setq entries-marked (1+ entries-marked))
  9028. (call-interactively 'org-agenda-bulk-mark))))
  9029. (if (not entries-marked)
  9030. (message "No entry matching this regexp."))))
  9031. (defun org-agenda-bulk-unmark (&optional arg)
  9032. "Unmark the entry at point for future bulk action."
  9033. (interactive "P")
  9034. (if arg
  9035. (org-agenda-bulk-unmark-all)
  9036. (cond ((org-agenda-bulk-marked-p)
  9037. (org-agenda-bulk-remove-overlays
  9038. (point-at-bol) (+ 2 (point-at-bol)))
  9039. (setq org-agenda-bulk-marked-entries
  9040. (delete (org-get-at-bol 'org-hd-marker)
  9041. org-agenda-bulk-marked-entries))
  9042. (end-of-line 1)
  9043. (or (ignore-errors
  9044. (goto-char (next-single-property-change (point) 'txt)))
  9045. (beginning-of-line 2))
  9046. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9047. (beginning-of-line 2))
  9048. (message "%d entries left marked for bulk action"
  9049. (length org-agenda-bulk-marked-entries)))
  9050. (t (message "No entry to unmark here")))))
  9051. (defun org-agenda-bulk-toggle-all ()
  9052. "Toggle all marks for bulk action."
  9053. (interactive)
  9054. (save-excursion
  9055. (goto-char (point-min))
  9056. (while (ignore-errors
  9057. (goto-char (next-single-property-change (point) 'txt)))
  9058. (org-agenda-bulk-toggle))))
  9059. (defun org-agenda-bulk-toggle ()
  9060. "Toggle the mark at point for bulk action."
  9061. (interactive)
  9062. (if (org-agenda-bulk-marked-p)
  9063. (org-agenda-bulk-unmark)
  9064. (org-agenda-bulk-mark)))
  9065. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9066. "Remove the mark overlays between BEG and END in the agenda buffer.
  9067. BEG and END default to the buffer limits.
  9068. This only removes the overlays, it does not remove the markers
  9069. from the list in `org-agenda-bulk-marked-entries'."
  9070. (interactive)
  9071. (mapc (lambda (ov)
  9072. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9073. (delete-overlay ov)))
  9074. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9075. (defun org-agenda-bulk-unmark-all ()
  9076. "Remove all marks in the agenda buffer.
  9077. This will remove the markers and the overlays."
  9078. (interactive)
  9079. (if (null org-agenda-bulk-marked-entries)
  9080. (message "No entry to unmark")
  9081. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9082. (setq org-agenda-bulk-marked-entries nil)
  9083. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9084. (defcustom org-agenda-persistent-marks nil
  9085. "Non-nil means marked items will stay marked after a bulk action.
  9086. You can toggle this interactively by typing `p' when prompted for a
  9087. bulk action."
  9088. :group 'org-agenda
  9089. :version "24.1"
  9090. :type 'boolean)
  9091. (defun org-agenda-bulk-action (&optional arg)
  9092. "Execute an remote-editing action on all marked entries.
  9093. The prefix arg is passed through to the command if possible."
  9094. (interactive "P")
  9095. ;; Make sure we have markers, and only valid ones
  9096. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9097. (mapc
  9098. (lambda (m)
  9099. (unless (and (markerp m)
  9100. (marker-buffer m)
  9101. (buffer-live-p (marker-buffer m))
  9102. (marker-position m))
  9103. (user-error "Marker %s for bulk command is invalid" m)))
  9104. org-agenda-bulk-marked-entries)
  9105. ;; Prompt for the bulk command
  9106. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9107. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9108. "[S]catter [f]unction "
  9109. (when org-agenda-bulk-custom-functions
  9110. (concat " Custom: ["
  9111. (mapconcat (lambda(f) (char-to-string (car f)))
  9112. org-agenda-bulk-custom-functions "")
  9113. "]"))))
  9114. (catch 'exit
  9115. (let* ((action (read-char-exclusive))
  9116. (org-log-refile (if org-log-refile 'time nil))
  9117. (entries (reverse org-agenda-bulk-marked-entries))
  9118. (org-overriding-default-time
  9119. (if (get-text-property (point) 'org-agenda-date-header)
  9120. (org-get-cursor-date)))
  9121. redo-at-end
  9122. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9123. (cond
  9124. ((equal action ?p)
  9125. (let ((org-agenda-persistent-marks
  9126. (not org-agenda-persistent-marks)))
  9127. (org-agenda-bulk-action)
  9128. (throw 'exit nil)))
  9129. ((equal action ?$)
  9130. (setq cmd '(org-agenda-archive)))
  9131. ((equal action ?A)
  9132. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9133. ((member action '(?r ?w))
  9134. (setq rfloc (org-refile-get-location
  9135. "Refile to"
  9136. (marker-buffer (car entries))
  9137. org-refile-allow-creating-parent-nodes))
  9138. (if (nth 3 rfloc)
  9139. (setcar (nthcdr 3 rfloc)
  9140. (move-marker (make-marker) (nth 3 rfloc)
  9141. (or (get-file-buffer (nth 1 rfloc))
  9142. (find-buffer-visiting (nth 1 rfloc))
  9143. (error "This should not happen")))))
  9144. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9145. redo-at-end t))
  9146. ((equal action ?t)
  9147. (setq state (org-icompleting-read
  9148. "Todo state: "
  9149. (with-current-buffer (marker-buffer (car entries))
  9150. (mapcar 'list org-todo-keywords-1))))
  9151. (setq cmd `(let ((org-inhibit-blocking t)
  9152. (org-inhibit-logging 'note))
  9153. (org-agenda-todo ,state))))
  9154. ((memq action '(?- ?+))
  9155. (setq tag (org-icompleting-read
  9156. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9157. (with-current-buffer (marker-buffer (car entries))
  9158. (delq nil
  9159. (mapcar (lambda (x)
  9160. (if (stringp (car x)) x)) org-tag-alist)))))
  9161. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9162. ((memq action '(?s ?d))
  9163. (let* ((time
  9164. (unless arg
  9165. (org-read-date
  9166. nil nil nil
  9167. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9168. org-overriding-default-time)))
  9169. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9170. (setq cmd `(eval '(,c1 arg ,time)))))
  9171. ((equal action ?S)
  9172. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9173. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9174. (let ((days (read-number
  9175. (format "Scatter tasks across how many %sdays: "
  9176. (if arg "week" "")) 7)))
  9177. (setq cmd
  9178. `(let ((distance (1+ (random ,days))))
  9179. (if arg
  9180. (let ((dist distance)
  9181. (day-of-week
  9182. (calendar-day-of-week
  9183. (calendar-gregorian-from-absolute (org-today)))))
  9184. (dotimes (i (1+ dist))
  9185. (while (member day-of-week org-agenda-weekend-days)
  9186. (incf distance)
  9187. (incf day-of-week)
  9188. (if (= day-of-week 7)
  9189. (setq day-of-week 0)))
  9190. (incf day-of-week)
  9191. (if (= day-of-week 7)
  9192. (setq day-of-week 0)))))
  9193. ;; silently fail when try to replan a sexp entry
  9194. (condition-case nil
  9195. (let* ((date (calendar-gregorian-from-absolute
  9196. (+ (org-today) distance)))
  9197. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9198. (nth 2 date))))
  9199. (org-agenda-schedule nil time))
  9200. (error nil)))))))
  9201. ((assoc action org-agenda-bulk-custom-functions)
  9202. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9203. redo-at-end t))
  9204. ((equal action ?f)
  9205. (setq cmd (list (intern
  9206. (org-icompleting-read "Function: "
  9207. obarray 'fboundp t nil nil)))))
  9208. (t (user-error "Invalid bulk action")))
  9209. ;; Sort the markers, to make sure that parents are handled before children
  9210. (setq entries (sort entries
  9211. (lambda (a b)
  9212. (cond
  9213. ((equal (marker-buffer a) (marker-buffer b))
  9214. (< (marker-position a) (marker-position b)))
  9215. (t
  9216. (string< (buffer-name (marker-buffer a))
  9217. (buffer-name (marker-buffer b))))))))
  9218. ;; Now loop over all markers and apply cmd
  9219. (while (setq e (pop entries))
  9220. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9221. (if (not pos)
  9222. (progn (message "Skipping removed entry at %s" e)
  9223. (setq cntskip (1+ cntskip)))
  9224. (goto-char pos)
  9225. (let (org-loop-over-headlines-in-active-region)
  9226. (eval cmd))
  9227. (setq cnt (1+ cnt))))
  9228. (when redo-at-end (org-agenda-redo))
  9229. (unless org-agenda-persistent-marks
  9230. (org-agenda-bulk-unmark-all))
  9231. (message "Acted on %d entries%s%s"
  9232. cnt
  9233. (if (= cntskip 0)
  9234. ""
  9235. (format ", skipped %d (disappeared before their turn)"
  9236. cntskip))
  9237. (if (not org-agenda-persistent-marks)
  9238. "" " (kept marked)"))))))
  9239. (defun org-agenda-capture (&optional with-time)
  9240. "Call `org-capture' with the date at point.
  9241. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9242. current HH:MM time."
  9243. (interactive "P")
  9244. (if (not (eq major-mode 'org-agenda-mode))
  9245. (user-error "You cannot do this outside of agenda buffers")
  9246. (let ((org-overriding-default-time
  9247. (org-get-cursor-date (equal with-time 1))))
  9248. (call-interactively 'org-capture))))
  9249. ;;; Dragging agenda lines forward/backward
  9250. (defun org-agenda-reapply-filters ()
  9251. "Re-apply all agenda filters."
  9252. (mapcar
  9253. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f))))
  9254. `((,org-agenda-tag-filter tag)
  9255. (,org-agenda-category-filter category)
  9256. (,org-agenda-regexp-filter regexp)
  9257. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9258. (,(get 'org-agenda-category-filter :preset-filter) category)
  9259. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9260. (defun org-agenda-drag-line-forward (arg &optional backward)
  9261. "Drag an agenda line forward by ARG lines.
  9262. When the optional argument `backward' is non-nil, move backward."
  9263. (interactive "p")
  9264. (let ((inhibit-read-only t) lst line)
  9265. (if (or (not (get-text-property (point) 'txt))
  9266. (save-excursion
  9267. (dotimes (n arg)
  9268. (move-beginning-of-line (if backward 0 2))
  9269. (push (not (get-text-property (point) 'txt)) lst))
  9270. (delq nil lst)))
  9271. (message "Cannot move line forward")
  9272. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9273. (move-beginning-of-line 1)
  9274. (setq line (buffer-substring (point) end))
  9275. (delete-region (point) end)
  9276. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9277. (insert line)
  9278. (org-agenda-reapply-filters)
  9279. (org-agenda-mark-clocking-task)
  9280. (move-beginning-of-line 0)))))
  9281. (defun org-agenda-drag-line-backward (arg)
  9282. "Drag an agenda line backward by ARG lines."
  9283. (interactive "p")
  9284. (org-agenda-drag-line-forward arg t))
  9285. ;;; Flagging notes
  9286. (defun org-agenda-show-the-flagging-note ()
  9287. "Display the flagging note in the other window.
  9288. When called a second time in direct sequence, offer to remove the FLAGGING
  9289. tag and (if present) the flagging note."
  9290. (interactive)
  9291. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9292. (win (selected-window))
  9293. note heading newhead)
  9294. (unless hdmarker
  9295. (user-error "No linked entry at point"))
  9296. (if (and (eq this-command last-command)
  9297. (y-or-n-p "Unflag and remove any flagging note? "))
  9298. (progn
  9299. (org-agenda-remove-flag hdmarker)
  9300. (let ((win (get-buffer-window "*Flagging Note*")))
  9301. (and win (delete-window win)))
  9302. (message "Entry unflagged"))
  9303. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9304. (unless note
  9305. (user-error "No flagging note"))
  9306. (org-kill-new note)
  9307. (org-switch-to-buffer-other-window "*Flagging Note*")
  9308. (erase-buffer)
  9309. (insert note)
  9310. (goto-char (point-min))
  9311. (while (re-search-forward "\\\\n" nil t)
  9312. (replace-match "\n" t t))
  9313. (goto-char (point-min))
  9314. (select-window win)
  9315. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9316. (defun org-agenda-remove-flag (marker)
  9317. "Remove the FLAGGED tag and any flagging note in the entry."
  9318. (let (newhead)
  9319. (org-with-point-at marker
  9320. (org-toggle-tag "FLAGGED" 'off)
  9321. (org-entry-delete nil "THEFLAGGINGNOTE")
  9322. (setq newhead (org-get-heading)))
  9323. (org-agenda-change-all-lines newhead marker)
  9324. (message "Entry unflagged")))
  9325. (defun org-agenda-get-any-marker (&optional pos)
  9326. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9327. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9328. ;;; Appointment reminders
  9329. (defvar appt-time-msg-list) ; defined in appt.el
  9330. ;;;###autoload
  9331. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9332. "Activate appointments found in `org-agenda-files'.
  9333. With a \\[universal-argument] prefix, refresh the list of
  9334. appointments.
  9335. If FILTER is t, interactively prompt the user for a regular
  9336. expression, and filter out entries that don't match it.
  9337. If FILTER is a string, use this string as a regular expression
  9338. for filtering entries out.
  9339. If FILTER is a function, filter out entries against which
  9340. calling the function returns nil. This function takes one
  9341. argument: an entry from `org-agenda-get-day-entries'.
  9342. FILTER can also be an alist with the car of each cell being
  9343. either 'headline or 'category. For example:
  9344. '((headline \"IMPORTANT\")
  9345. (category \"Work\"))
  9346. will only add headlines containing IMPORTANT or headlines
  9347. belonging to the \"Work\" category.
  9348. ARGS are symbols indicating what kind of entries to consider.
  9349. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9350. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9351. and :timestamp entries. See the docstring of `org-diary' for
  9352. details and examples.
  9353. If an entry has a APPT_WARNTIME property, its value will be used
  9354. to override `appt-message-warning-time'."
  9355. (interactive "P")
  9356. (if refresh (setq appt-time-msg-list nil))
  9357. (if (eq filter t)
  9358. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9359. (let* ((cnt 0) ; count added events
  9360. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9361. (org-agenda-new-buffers nil)
  9362. (org-deadline-warning-days 0)
  9363. ;; Do not use `org-today' here because appt only takes
  9364. ;; time and without date as argument, so it may pass wrong
  9365. ;; information otherwise
  9366. (today (org-date-to-gregorian
  9367. (time-to-days (current-time))))
  9368. (org-agenda-restrict nil)
  9369. (files (org-agenda-files 'unrestricted)) entries file
  9370. (org-agenda-buffer nil))
  9371. ;; Get all entries which may contain an appt
  9372. (org-agenda-prepare-buffers files)
  9373. (while (setq file (pop files))
  9374. (setq entries
  9375. (delq nil
  9376. (append entries
  9377. (apply 'org-agenda-get-day-entries
  9378. file today scope)))))
  9379. ;; Map thru entries and find if we should filter them out
  9380. (mapc
  9381. (lambda(x)
  9382. (let* ((evt (org-trim
  9383. (replace-regexp-in-string
  9384. org-bracket-link-regexp "\\3"
  9385. (or (get-text-property 1 'txt x) ""))))
  9386. (cat (get-text-property 1 'org-category x))
  9387. (tod (get-text-property 1 'time-of-day x))
  9388. (ok (or (null filter)
  9389. (and (stringp filter) (string-match filter evt))
  9390. (and (functionp filter) (funcall filter x))
  9391. (and (listp filter)
  9392. (let ((cat-filter (cadr (assoc 'category filter)))
  9393. (evt-filter (cadr (assoc 'headline filter))))
  9394. (or (and (stringp cat-filter)
  9395. (string-match cat-filter cat))
  9396. (and (stringp evt-filter)
  9397. (string-match evt-filter evt)))))))
  9398. (wrn (get-text-property 1 'warntime x)))
  9399. ;; FIXME: Shall we remove text-properties for the appt text?
  9400. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9401. (when (and ok tod)
  9402. (setq tod (concat "00" (number-to-string tod))
  9403. tod (when (string-match
  9404. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9405. (concat (match-string 1 tod) ":"
  9406. (match-string 2 tod))))
  9407. (if (version< emacs-version "23.3")
  9408. (appt-add tod evt)
  9409. (appt-add tod evt wrn))
  9410. (setq cnt (1+ cnt))))) entries)
  9411. (org-release-buffers org-agenda-new-buffers)
  9412. (if (eq cnt 0)
  9413. (message "No event to add")
  9414. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9415. (defun org-agenda-todayp (date)
  9416. "Does DATE mean today, when considering `org-extend-today-until'?"
  9417. (let ((today (org-today))
  9418. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9419. date)))
  9420. (eq date today)))
  9421. (defun org-agenda-todo-yesterday (&optional arg)
  9422. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9423. (interactive "P")
  9424. (let* ((hour (third (decode-time
  9425. (org-current-time))))
  9426. (org-extend-today-until (1+ hour)))
  9427. (org-agenda-todo arg)))
  9428. (provide 'org-agenda)
  9429. ;;; org-agenda.el ends here