org-agenda.el 376 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags do not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  661. "Time unit to use when possibly ignoring an agenda item.
  662. See the docstring of various `org-agenda-todo-ignore-*' options.
  663. The default is to compare time stamps using days. An item is thus
  664. considered to be in the future if it is at least one day after today.
  665. Non-nil means to compare time stamps using seconds. An item is then
  666. considered future if it has a time value later than current time."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-todo-list
  669. :type '(choice
  670. (const :tag "Compare time with days" nil)
  671. (const :tag "Compare time with seconds" t)))
  672. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  673. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  674. The variables
  675. `org-agenda-todo-ignore-with-date',
  676. `org-agenda-todo-ignore-timestamp',
  677. `org-agenda-todo-ignore-scheduled',
  678. `org-agenda-todo-ignore-deadlines'
  679. make the global TODO list skip entries that have time stamps of certain
  680. kinds. If this option is set, the same options will also apply for the
  681. tags-todo search, which is the general tags/property matcher
  682. restricted to unfinished TODO entries only."
  683. :group 'org-agenda-skip
  684. :group 'org-agenda-todo-list
  685. :group 'org-agenda-match-view
  686. :type 'boolean)
  687. (defcustom org-agenda-skip-scheduled-if-done nil
  688. "Non-nil means don't show scheduled items in agenda when they are done.
  689. This is relevant for the daily/weekly agenda, not for the TODO list. And
  690. it applies only to the actual date of the scheduling. Warnings about
  691. an item with a past scheduling dates are always turned off when the item
  692. is DONE."
  693. :group 'org-agenda-skip
  694. :group 'org-agenda-daily/weekly
  695. :type 'boolean)
  696. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  697. "Non-nil means skip scheduling line if same entry shows because of deadline.
  698. In the agenda of today, an entry can show up multiple times because
  699. it is both scheduled and has a nearby deadline, and maybe a plain time
  700. stamp as well.
  701. When this variable is t, then only the deadline is shown and the fact that
  702. the entry is scheduled today or was scheduled previously is not shown.
  703. When this variable is nil, the entry will be shown several times. When
  704. the variable is the symbol `not-today', then skip scheduled previously,
  705. but not scheduled today."
  706. :group 'org-agenda-skip
  707. :group 'org-agenda-daily/weekly
  708. :type '(choice
  709. (const :tag "Never" nil)
  710. (const :tag "Always" t)
  711. (const :tag "Not when scheduled today" not-today)))
  712. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  713. "Non-nil means skip timestamp line if same entry shows because of deadline.
  714. In the agenda of today, an entry can show up multiple times
  715. because it has both a plain timestamp and has a nearby deadline.
  716. When this variable is t, then only the deadline is shown and the
  717. fact that the entry has a timestamp for or including today is not
  718. shown. When this variable is nil, the entry will be shown
  719. several times."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :version "24.1"
  723. :type '(choice
  724. (const :tag "Never" nil)
  725. (const :tag "Always" t)))
  726. (defcustom org-agenda-skip-deadline-if-done nil
  727. "Non-nil means don't show deadlines when the corresponding item is done.
  728. When nil, the deadline is still shown and should give you a happy feeling.
  729. This is relevant for the daily/weekly agenda. And it applied only to the
  730. actually date of the deadline. Warnings about approaching and past-due
  731. deadlines are always turned off when the item is DONE."
  732. :group 'org-agenda-skip
  733. :group 'org-agenda-daily/weekly
  734. :type 'boolean)
  735. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  736. "Non-nil means skip deadline prewarning when entry is also scheduled.
  737. This will apply on all days where a prewarning for the deadline would
  738. be shown, but not at the day when the entry is actually due. On that day,
  739. the deadline will be shown anyway.
  740. This variable may be set to nil, t, the symbol `pre-scheduled',
  741. or a number which will then give the number of days before the actual
  742. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  743. eliminates the deadline prewarning only prior to the scheduled date.
  744. This can be used in a workflow where the first showing of the deadline will
  745. trigger you to schedule it, and then you don't want to be reminded of it
  746. because you will take care of it on the day when scheduled."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-daily/weekly
  749. :version "24.1"
  750. :type '(choice
  751. (const :tag "Always show prewarning" nil)
  752. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  753. (const :tag "Remove prewarning if entry is scheduled" t)
  754. (integer :tag "Restart prewarning N days before deadline")))
  755. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  756. "Non-nil means skip scheduled delay when entry also has a deadline.
  757. This variable may be set to nil, t, the symbol `post-deadline',
  758. or a number which will then give the number of days after the actual
  759. scheduled date when the delay should expire. The symbol `post-deadline'
  760. eliminates the schedule delay when the date is posterior to the deadline."
  761. :group 'org-agenda-skip
  762. :group 'org-agenda-daily/weekly
  763. :version "24.4"
  764. :package-version '(Org . "8.0")
  765. :type '(choice
  766. (const :tag "Always honor delay" nil)
  767. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  768. (const :tag "Ignore delay if entry has a deadline" t)
  769. (integer :tag "Honor delay up until N days after the scheduled date")))
  770. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  771. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  772. When non-nil, after the search for timestamps has matched once in an
  773. entry, the rest of the entry will not be searched."
  774. :group 'org-agenda-skip
  775. :type 'boolean)
  776. (defcustom org-agenda-skip-timestamp-if-done nil
  777. "Non-nil means don't select item by timestamp or -range if it is DONE."
  778. :group 'org-agenda-skip
  779. :group 'org-agenda-daily/weekly
  780. :type 'boolean)
  781. (defcustom org-agenda-dim-blocked-tasks nil
  782. "Non-nil means dim blocked tasks in the agenda display.
  783. This causes some overhead during agenda construction, but if you
  784. have turned on `org-enforce-todo-dependencies',
  785. `org-enforce-todo-checkbox-dependencies', or any other blocking
  786. mechanism, this will create useful feedback in the agenda.
  787. Instead of t, this variable can also have the value `invisible'.
  788. Then blocked tasks will be invisible and only become visible when
  789. they become unblocked. An exemption to this behavior is when a task is
  790. blocked because of unchecked checkboxes below it. Since checkboxes do
  791. not show up in the agenda views, making this task invisible you remove any
  792. trace from agenda views that there is something to do. Therefore, a task
  793. that is blocked because of checkboxes will never be made invisible, it
  794. will only be dimmed."
  795. :group 'org-agenda-daily/weekly
  796. :group 'org-agenda-todo-list
  797. :version "24.3"
  798. :type '(choice
  799. (const :tag "Do not dim" nil)
  800. (const :tag "Dim to a gray face" t)
  801. (const :tag "Make invisible" invisible)))
  802. (defcustom org-timeline-show-empty-dates 3
  803. "Non-nil means `org-timeline' also shows dates without an entry.
  804. When nil, only the days which actually have entries are shown.
  805. When t, all days between the first and the last date are shown.
  806. When an integer, show also empty dates, but if there is a gap of more than
  807. N days, just insert a special line indicating the size of the gap."
  808. :group 'org-agenda-skip
  809. :type '(choice
  810. (const :tag "None" nil)
  811. (const :tag "All" t)
  812. (integer :tag "at most")))
  813. (defgroup org-agenda-startup nil
  814. "Options concerning initial settings in the Agenda in Org Mode."
  815. :tag "Org Agenda Startup"
  816. :group 'org-agenda)
  817. (defcustom org-agenda-menu-show-matcher t
  818. "Non-nil means show the match string in the agenda dispatcher menu.
  819. When nil, the matcher string is not shown, but is put into the help-echo
  820. property so than moving the mouse over the command shows it.
  821. Setting it to nil is good if matcher strings are very long and/or if
  822. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  823. :group 'org-agenda
  824. :version "24.1"
  825. :type 'boolean)
  826. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  827. (defcustom org-agenda-menu-two-columns nil
  828. "Non-nil means, use two columns to show custom commands in the dispatcher.
  829. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  830. to nil."
  831. :group 'org-agenda
  832. :version "24.1"
  833. :type 'boolean)
  834. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  835. (defcustom org-agenda-finalize-hook nil
  836. "Hook run just before displaying an agenda buffer.
  837. The buffer is still writable when the hook is called.
  838. You can modify some of the buffer substrings but you should be
  839. extra careful not to modify the text properties of the agenda
  840. headlines as the agenda display heavily relies on them."
  841. :group 'org-agenda-startup
  842. :type 'hook)
  843. (defcustom org-agenda-mouse-1-follows-link nil
  844. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  845. A longer mouse click will still set point. Does not work on XEmacs.
  846. Needs to be set before org.el is loaded."
  847. :group 'org-agenda-startup
  848. :type 'boolean)
  849. (defcustom org-agenda-start-with-follow-mode nil
  850. "The initial value of follow mode in a newly created agenda window."
  851. :group 'org-agenda-startup
  852. :type 'boolean)
  853. (defcustom org-agenda-follow-indirect nil
  854. "Non-nil means `org-agenda-follow-mode' displays only the
  855. current item's tree, in an indirect buffer."
  856. :group 'org-agenda
  857. :version "24.1"
  858. :type 'boolean)
  859. (defcustom org-agenda-show-outline-path t
  860. "Non-nil means show outline path in echo area after line motion."
  861. :group 'org-agenda-startup
  862. :type 'boolean)
  863. (defcustom org-agenda-start-with-entry-text-mode nil
  864. "The initial value of entry-text-mode in a newly created agenda window."
  865. :group 'org-agenda-startup
  866. :type 'boolean)
  867. (defcustom org-agenda-entry-text-maxlines 5
  868. "Number of text lines to be added when `E' is pressed in the agenda.
  869. Note that this variable only used during agenda display. Add add entry text
  870. when exporting the agenda, configure the variable
  871. `org-agenda-add-entry-ext-maxlines'."
  872. :group 'org-agenda
  873. :type 'integer)
  874. (defcustom org-agenda-entry-text-exclude-regexps nil
  875. "List of regular expressions to clean up entry text.
  876. The complete matches of all regular expressions in this list will be
  877. removed from entry text before it is shown in the agenda."
  878. :group 'org-agenda
  879. :type '(repeat (regexp)))
  880. (defcustom org-agenda-entry-text-leaders " > "
  881. "Text prepended to the entry text in agenda buffers."
  882. :version "24.4"
  883. :package-version '(Org . "8.0")
  884. :group 'org-agenda
  885. :type 'string)
  886. (defvar org-agenda-entry-text-cleanup-hook nil
  887. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  888. This cleanup is done in a temporary buffer, so the function may inspect and
  889. change the entire buffer.
  890. Some default stuff like drawers and scheduling/deadline dates will already
  891. have been removed when this is called, as will any matches for regular
  892. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  893. (defvar org-agenda-include-inactive-timestamps nil
  894. "Non-nil means include inactive time stamps in agenda and timeline.
  895. Dynamically scoped.")
  896. (defgroup org-agenda-windows nil
  897. "Options concerning the windows used by the Agenda in Org Mode."
  898. :tag "Org Agenda Windows"
  899. :group 'org-agenda)
  900. (defcustom org-agenda-window-setup 'reorganize-frame
  901. "How the agenda buffer should be displayed.
  902. Possible values for this option are:
  903. current-window Show agenda in the current window, keeping all other windows.
  904. other-window Use `switch-to-buffer-other-window' to display agenda.
  905. reorganize-frame Show only two windows on the current frame, the current
  906. window and the agenda.
  907. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  908. Also, when exiting the agenda, kill that frame.
  909. See also the variable `org-agenda-restore-windows-after-quit'."
  910. :group 'org-agenda-windows
  911. :type '(choice
  912. (const current-window)
  913. (const other-frame)
  914. (const other-window)
  915. (const reorganize-frame)))
  916. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  917. "The min and max height of the agenda window as a fraction of frame height.
  918. The value of the variable is a cons cell with two numbers between 0 and 1.
  919. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  920. :group 'org-agenda-windows
  921. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  922. (defcustom org-agenda-restore-windows-after-quit nil
  923. "Non-nil means restore window configuration upon exiting agenda.
  924. Before the window configuration is changed for displaying the agenda,
  925. the current status is recorded. When the agenda is exited with
  926. `q' or `x' and this option is set, the old state is restored. If
  927. `org-agenda-window-setup' is `other-frame', the value of this
  928. option will be ignored."
  929. :group 'org-agenda-windows
  930. :type 'boolean)
  931. (defcustom org-agenda-ndays nil
  932. "Number of days to include in overview display.
  933. Should be 1 or 7.
  934. Obsolete, see `org-agenda-span'."
  935. :group 'org-agenda-daily/weekly
  936. :type 'integer)
  937. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  938. (defcustom org-agenda-span 'week
  939. "Number of days to include in overview display.
  940. Can be day, week, month, year, or any number of days.
  941. Custom commands can set this variable in the options section."
  942. :group 'org-agenda-daily/weekly
  943. :type '(choice (const :tag "Day" day)
  944. (const :tag "Week" week)
  945. (const :tag "Month" month)
  946. (const :tag "Year" year)
  947. (integer :tag "Custom")))
  948. (defcustom org-agenda-start-on-weekday 1
  949. "Non-nil means start the overview always on the specified weekday.
  950. 0 denotes Sunday, 1 denotes Monday etc.
  951. When nil, always start on the current day.
  952. Custom commands can set this variable in the options section."
  953. :group 'org-agenda-daily/weekly
  954. :type '(choice (const :tag "Today" nil)
  955. (integer :tag "Weekday No.")))
  956. (defcustom org-agenda-show-all-dates t
  957. "Non-nil means `org-agenda' shows every day in the selected range.
  958. When nil, only the days which actually have entries are shown."
  959. :group 'org-agenda-daily/weekly
  960. :type 'boolean)
  961. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  962. "Format string for displaying dates in the agenda.
  963. Used by the daily/weekly agenda and by the timeline. This should be
  964. a format string understood by `format-time-string', or a function returning
  965. the formatted date as a string. The function must take a single argument,
  966. a calendar-style date list like (month day year)."
  967. :group 'org-agenda-daily/weekly
  968. :type '(choice
  969. (string :tag "Format string")
  970. (function :tag "Function")))
  971. (defun org-agenda-format-date-aligned (date)
  972. "Format a date string for display in the daily/weekly agenda, or timeline.
  973. This function makes sure that dates are aligned for easy reading."
  974. (require 'cal-iso)
  975. (let* ((dayname (calendar-day-name date))
  976. (day (cadr date))
  977. (day-of-week (calendar-day-of-week date))
  978. (month (car date))
  979. (monthname (calendar-month-name month))
  980. (year (nth 2 date))
  981. (iso-week (org-days-to-iso-week
  982. (calendar-absolute-from-gregorian date)))
  983. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  984. (1- year))
  985. ((and (= month 12) (<= iso-week 1))
  986. (1+ year))
  987. (t year)))
  988. (weekstring (if (= day-of-week 1)
  989. (format " W%02d" iso-week)
  990. "")))
  991. (format "%-10s %2d %s %4d%s"
  992. dayname day monthname year weekstring)))
  993. (defcustom org-agenda-time-leading-zero nil
  994. "Non-nil means use leading zero for military times in agenda.
  995. For example, 9:30am would become 09:30 rather than 9:30."
  996. :group 'org-agenda-daily/weekly
  997. :version "24.1"
  998. :type 'boolean)
  999. (defcustom org-agenda-timegrid-use-ampm nil
  1000. "When set, show AM/PM style timestamps on the timegrid."
  1001. :group 'org-agenda
  1002. :version "24.1"
  1003. :type 'boolean)
  1004. (defun org-agenda-time-of-day-to-ampm (time)
  1005. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1006. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1007. (minute (substring time -2))
  1008. (ampm "am"))
  1009. (cond
  1010. ((equal hour-number 12)
  1011. (setq ampm "pm"))
  1012. ((> hour-number 12)
  1013. (setq ampm "pm")
  1014. (setq hour-number (- hour-number 12))))
  1015. (concat
  1016. (if org-agenda-time-leading-zero
  1017. (format "%02d" hour-number)
  1018. (format "%02s" (number-to-string hour-number)))
  1019. ":" minute ampm)))
  1020. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1021. "Conditionally convert TIME to AM/PM format
  1022. based on `org-agenda-timegrid-use-ampm'"
  1023. (if org-agenda-timegrid-use-ampm
  1024. (org-agenda-time-of-day-to-ampm time)
  1025. time))
  1026. (defcustom org-agenda-weekend-days '(6 0)
  1027. "Which days are weekend?
  1028. These days get the special face `org-agenda-date-weekend' in the agenda
  1029. and timeline buffers."
  1030. :group 'org-agenda-daily/weekly
  1031. :type '(set :greedy t
  1032. (const :tag "Monday" 1)
  1033. (const :tag "Tuesday" 2)
  1034. (const :tag "Wednesday" 3)
  1035. (const :tag "Thursday" 4)
  1036. (const :tag "Friday" 5)
  1037. (const :tag "Saturday" 6)
  1038. (const :tag "Sunday" 0)))
  1039. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1040. "Non-nil means jump to today when moving a past date forward in time.
  1041. When using S-right in the agenda to move a a date forward, and the date
  1042. stamp currently points to the past, the first key press will move it
  1043. to today. WHen nil, just move one day forward even if the date stays
  1044. in the past."
  1045. :group 'org-agenda-daily/weekly
  1046. :version "24.1"
  1047. :type 'boolean)
  1048. (defcustom org-agenda-include-diary nil
  1049. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1050. Custom commands can set this variable in the options section."
  1051. :group 'org-agenda-daily/weekly
  1052. :type 'boolean)
  1053. (defcustom org-agenda-include-deadlines t
  1054. "If non-nil, include entries within their deadline warning period.
  1055. Custom commands can set this variable in the options section."
  1056. :group 'org-agenda-daily/weekly
  1057. :version "24.1"
  1058. :type 'boolean)
  1059. (defcustom org-agenda-repeating-timestamp-show-all t
  1060. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1061. When set to a list of strings, only show occurrences of repeating
  1062. stamps for these TODO keywords. When nil, only one occurrence is
  1063. shown, either today or the nearest into the future."
  1064. :group 'org-agenda-daily/weekly
  1065. :type '(choice
  1066. (const :tag "Show repeating stamps" t)
  1067. (repeat :tag "Show repeating stamps for these TODO keywords"
  1068. (string :tag "TODO Keyword"))
  1069. (const :tag "Don't show repeating stamps" nil)))
  1070. (defcustom org-scheduled-past-days 10000
  1071. "No. of days to continue listing scheduled items that are not marked DONE.
  1072. When an item is scheduled on a date, it shows up in the agenda on this
  1073. day and will be listed until it is marked done for the number of days
  1074. given here."
  1075. :group 'org-agenda-daily/weekly
  1076. :type 'integer)
  1077. (defcustom org-agenda-log-mode-items '(closed clock)
  1078. "List of items that should be shown in agenda log mode.
  1079. This list may contain the following symbols:
  1080. closed Show entries that have been closed on that day.
  1081. clock Show entries that have received clocked time on that day.
  1082. state Show all logged state changes.
  1083. Note that instead of changing this variable, you can also press `C-u l' in
  1084. the agenda to display all available LOG items temporarily."
  1085. :group 'org-agenda-daily/weekly
  1086. :type '(set :greedy t (const closed) (const clock) (const state)))
  1087. (defcustom org-agenda-clock-consistency-checks
  1088. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1089. :gap-ok-around ("4:00")
  1090. :default-face ((:background "DarkRed") (:foreground "white"))
  1091. :overlap-face nil :gap-face nil :no-end-time-face nil
  1092. :long-face nil :short-face nil)
  1093. "This is a property list, with the following keys:
  1094. :max-duration Mark clocking chunks that are longer than this time.
  1095. This is a time string like \"HH:MM\", or the number
  1096. of minutes as an integer.
  1097. :min-duration Mark clocking chunks that are shorter that this.
  1098. This is a time string like \"HH:MM\", or the number
  1099. of minutes as an integer.
  1100. :max-gap Mark gaps between clocking chunks that are longer than
  1101. this duration. A number of minutes, or a string
  1102. like \"HH:MM\".
  1103. :gap-ok-around List of times during the day which are usually not working
  1104. times. When a gap is detected, but the gap contains any
  1105. of these times, the gap is *not* reported. For example,
  1106. if this is (\"4:00\" \"13:00\") then gaps that contain
  1107. 4:00 in the morning (i.e. the night) and 13:00
  1108. (i.e. a typical lunch time) do not cause a warning.
  1109. You should have at least one time during the night in this
  1110. list, or otherwise the first task each morning will trigger
  1111. a warning because it follows a long gap.
  1112. Furthermore, the following properties can be used to define faces for
  1113. issue display.
  1114. :default-face the default face, if the specific face is undefined
  1115. :overlap-face face for overlapping clocks
  1116. :gap-face face for gaps between clocks
  1117. :no-end-time-face face for incomplete clocks
  1118. :long-face face for clock intervals that are too long
  1119. :short-face face for clock intervals that are too short"
  1120. :group 'org-agenda-daily/weekly
  1121. :group 'org-clock
  1122. :version "24.1"
  1123. :type 'plist)
  1124. (defcustom org-agenda-log-mode-add-notes t
  1125. "Non-nil means add first line of notes to log entries in agenda views.
  1126. If a log item like a state change or a clock entry is associated with
  1127. notes, the first line of these notes will be added to the entry in the
  1128. agenda display."
  1129. :group 'org-agenda-daily/weekly
  1130. :type 'boolean)
  1131. (defcustom org-agenda-start-with-log-mode nil
  1132. "The initial value of log-mode in a newly created agenda window.
  1133. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1134. explanations on the possible values."
  1135. :group 'org-agenda-startup
  1136. :group 'org-agenda-daily/weekly
  1137. :type '(choice (const :tag "Don't show log items" nil)
  1138. (const :tag "Show only log items" 'only)
  1139. (const :tag "Show all possible log items" 'clockcheck)
  1140. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1141. (choice (const :tag "Show closed log items" 'closed)
  1142. (const :tag "Show clocked log items" 'clock)
  1143. (const :tag "Show all logged state changes" 'state)))))
  1144. (defcustom org-agenda-start-with-clockreport-mode nil
  1145. "The initial value of clockreport-mode in a newly created agenda window."
  1146. :group 'org-agenda-startup
  1147. :group 'org-agenda-daily/weekly
  1148. :type 'boolean)
  1149. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1150. "Property list with parameters for the clocktable in clockreport mode.
  1151. This is the display mode that shows a clock table in the daily/weekly
  1152. agenda, the properties for this dynamic block can be set here.
  1153. The usual clocktable parameters are allowed here, but you cannot set
  1154. the properties :name, :tstart, :tend, :block, and :scope - these will
  1155. be overwritten to make sure the content accurately reflects the
  1156. current display in the agenda."
  1157. :group 'org-agenda-daily/weekly
  1158. :type 'plist)
  1159. (defcustom org-agenda-search-view-always-boolean nil
  1160. "Non-nil means the search string is interpreted as individual parts.
  1161. The search string for search view can either be interpreted as a phrase,
  1162. or as a list of snippets that define a boolean search for a number of
  1163. strings.
  1164. When this is non-nil, the string will be split on whitespace, and each
  1165. snippet will be searched individually, and all must match in order to
  1166. select an entry. A snippet is then a single string of non-white
  1167. characters, or a string in double quotes, or a regexp in {} braces.
  1168. If a snippet is preceded by \"-\", the snippet must *not* match.
  1169. \"+\" is syntactic sugar for positive selection. Each snippet may
  1170. be found as a full word or a partial word, but see the variable
  1171. `org-agenda-search-view-force-full-words'.
  1172. When this is nil, search will look for the entire search phrase as one,
  1173. with each space character matching any amount of whitespace, including
  1174. line breaks.
  1175. Even when this is nil, you can still switch to Boolean search dynamically
  1176. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1177. is a regexp marked with braces like \"{abc}\", this will also switch to
  1178. boolean search."
  1179. :group 'org-agenda-search-view
  1180. :version "24.1"
  1181. :type 'boolean)
  1182. (if (fboundp 'defvaralias)
  1183. (defvaralias 'org-agenda-search-view-search-words-only
  1184. 'org-agenda-search-view-always-boolean))
  1185. (defcustom org-agenda-search-view-force-full-words nil
  1186. "Non-nil means, search words must be matches as complete words.
  1187. When nil, they may also match part of a word."
  1188. :group 'org-agenda-search-view
  1189. :version "24.1"
  1190. :type 'boolean)
  1191. (defcustom org-agenda-search-view-max-outline-level nil
  1192. "Maximum outline level to display in search view.
  1193. E.g. when this is set to 1, the search view will only
  1194. show headlines of level 1."
  1195. :group 'org-agenda-search-view
  1196. :version "24.4"
  1197. :package-version '(Org . "8.0")
  1198. :type 'integer)
  1199. (defgroup org-agenda-time-grid nil
  1200. "Options concerning the time grid in the Org-mode Agenda."
  1201. :tag "Org Agenda Time Grid"
  1202. :group 'org-agenda)
  1203. (defcustom org-agenda-search-headline-for-time t
  1204. "Non-nil means search headline for a time-of-day.
  1205. If the headline contains a time-of-day in one format or another, it will
  1206. be used to sort the entry into the time sequence of items for a day.
  1207. Some people have time stamps in the headline that refer to the creation
  1208. time or so, and then this produces an unwanted side effect. If this is
  1209. the case for your, use this variable to turn off searching the headline
  1210. for a time."
  1211. :group 'org-agenda-time-grid
  1212. :type 'boolean)
  1213. (defcustom org-agenda-use-time-grid t
  1214. "Non-nil means show a time grid in the agenda schedule.
  1215. A time grid is a set of lines for specific times (like every two hours between
  1216. 8:00 and 20:00). The items scheduled for a day at specific times are
  1217. sorted in between these lines.
  1218. For details about when the grid will be shown, and what it will look like, see
  1219. the variable `org-agenda-time-grid'."
  1220. :group 'org-agenda-time-grid
  1221. :type 'boolean)
  1222. (defcustom org-agenda-time-grid
  1223. '((daily today require-timed)
  1224. "----------------"
  1225. (800 1000 1200 1400 1600 1800 2000))
  1226. "The settings for time grid for agenda display.
  1227. This is a list of three items. The first item is again a list. It contains
  1228. symbols specifying conditions when the grid should be displayed:
  1229. daily if the agenda shows a single day
  1230. weekly if the agenda shows an entire week
  1231. today show grid on current date, independent of daily/weekly display
  1232. require-timed show grid only if at least one item has a time specification
  1233. The second item is a string which will be placed behind the grid time.
  1234. The third item is a list of integers, indicating the times that should have
  1235. a grid line."
  1236. :group 'org-agenda-time-grid
  1237. :type
  1238. '(list
  1239. (set :greedy t :tag "Grid Display Options"
  1240. (const :tag "Show grid in single day agenda display" daily)
  1241. (const :tag "Show grid in weekly agenda display" weekly)
  1242. (const :tag "Always show grid for today" today)
  1243. (const :tag "Show grid only if any timed entries are present"
  1244. require-timed)
  1245. (const :tag "Skip grid times already present in an entry"
  1246. remove-match))
  1247. (string :tag "Grid String")
  1248. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1249. (defcustom org-agenda-show-current-time-in-grid t
  1250. "Non-nil means show the current time in the time grid."
  1251. :group 'org-agenda-time-grid
  1252. :version "24.1"
  1253. :type 'boolean)
  1254. (defcustom org-agenda-current-time-string
  1255. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1256. "The string for the current time marker in the agenda."
  1257. :group 'org-agenda-time-grid
  1258. :version "24.1"
  1259. :type 'string)
  1260. (defgroup org-agenda-sorting nil
  1261. "Options concerning sorting in the Org-mode Agenda."
  1262. :tag "Org Agenda Sorting"
  1263. :group 'org-agenda)
  1264. (defcustom org-agenda-sorting-strategy
  1265. '((agenda habit-down time-up priority-down category-keep)
  1266. (todo priority-down category-keep)
  1267. (tags priority-down category-keep)
  1268. (search category-keep))
  1269. "Sorting structure for the agenda items of a single day.
  1270. This is a list of symbols which will be used in sequence to determine
  1271. if an entry should be listed before another entry. The following
  1272. symbols are recognized:
  1273. time-up Put entries with time-of-day indications first, early first
  1274. time-down Put entries with time-of-day indications first, late first
  1275. timestamp-up Sort by any timestamp, early first
  1276. timestamp-down Sort by any timestamp, late first
  1277. scheduled-up Sort by scheduled timestamp, early first
  1278. scheduled-down Sort by scheduled timestamp, late first
  1279. deadline-up Sort by deadline timestamp, early first
  1280. deadline-down Sort by deadline timestamp, late first
  1281. ts-up Sort by active timestamp, early first
  1282. ts-down Sort by active timestamp, late first
  1283. tsia-up Sort by inactive timestamp, early first
  1284. tsia-down Sort by inactive timestamp, late first
  1285. category-keep Keep the default order of categories, corresponding to the
  1286. sequence in `org-agenda-files'.
  1287. category-up Sort alphabetically by category, A-Z.
  1288. category-down Sort alphabetically by category, Z-A.
  1289. tag-up Sort alphabetically by last tag, A-Z.
  1290. tag-down Sort alphabetically by last tag, Z-A.
  1291. priority-up Sort numerically by priority, high priority last.
  1292. priority-down Sort numerically by priority, high priority first.
  1293. todo-state-up Sort by todo state, tasks that are done last.
  1294. todo-state-down Sort by todo state, tasks that are done first.
  1295. effort-up Sort numerically by estimated effort, high effort last.
  1296. effort-down Sort numerically by estimated effort, high effort first.
  1297. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1298. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1299. habit-up Put entries that are habits first
  1300. habit-down Put entries that are habits last
  1301. alpha-up Sort headlines alphabetically
  1302. alpha-down Sort headlines alphabetically, reversed
  1303. The different possibilities will be tried in sequence, and testing stops
  1304. if one comparison returns a \"not-equal\". For example, the default
  1305. '(time-up category-keep priority-down)
  1306. means: Pull out all entries having a specified time of day and sort them,
  1307. in order to make a time schedule for the current day the first thing in the
  1308. agenda listing for the day. Of the entries without a time indication, keep
  1309. the grouped in categories, don't sort the categories, but keep them in
  1310. the sequence given in `org-agenda-files'. Within each category sort by
  1311. priority.
  1312. Leaving out `category-keep' would mean that items will be sorted across
  1313. categories by priority.
  1314. Instead of a single list, this can also be a set of list for specific
  1315. contents, with a context symbol in the car of the list, any of
  1316. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1317. Custom commands can bind this variable in the options section."
  1318. :group 'org-agenda-sorting
  1319. :type `(choice
  1320. (repeat :tag "General" ,org-sorting-choice)
  1321. (list :tag "Individually"
  1322. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1323. (repeat ,org-sorting-choice))
  1324. (cons (const :tag "Strategy for TODO lists" todo)
  1325. (repeat ,org-sorting-choice))
  1326. (cons (const :tag "Strategy for Tags matches" tags)
  1327. (repeat ,org-sorting-choice))
  1328. (cons (const :tag "Strategy for search matches" search)
  1329. (repeat ,org-sorting-choice)))))
  1330. (defcustom org-agenda-cmp-user-defined nil
  1331. "A function to define the comparison `user-defined'.
  1332. This function must receive two arguments, agenda entry a and b.
  1333. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1334. the user comparison, return nil.
  1335. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1336. part of an agenda sorting strategy."
  1337. :group 'org-agenda-sorting
  1338. :type 'symbol)
  1339. (defcustom org-sort-agenda-notime-is-late t
  1340. "Non-nil means items without time are considered late.
  1341. This is only relevant for sorting. When t, items which have no explicit
  1342. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1343. do have a time. When nil, the default time is before 0:00. You can use this
  1344. option to decide if the schedule for today should come before or after timeless
  1345. agenda entries."
  1346. :group 'org-agenda-sorting
  1347. :type 'boolean)
  1348. (defcustom org-sort-agenda-noeffort-is-high t
  1349. "Non-nil means items without effort estimate are sorted as high effort.
  1350. This also applies when filtering an agenda view with respect to the
  1351. < or > effort operator. Then, tasks with no effort defined will be treated
  1352. as tasks with high effort.
  1353. When nil, such items are sorted as 0 minutes effort."
  1354. :group 'org-agenda-sorting
  1355. :type 'boolean)
  1356. (defgroup org-agenda-line-format nil
  1357. "Options concerning the entry prefix in the Org-mode agenda display."
  1358. :tag "Org Agenda Line Format"
  1359. :group 'org-agenda)
  1360. (defcustom org-agenda-prefix-format
  1361. '((agenda . " %i %-12:c%?-12t% s")
  1362. (timeline . " % s")
  1363. (todo . " %i %-12:c")
  1364. (tags . " %i %-12:c")
  1365. (search . " %i %-12:c"))
  1366. "Format specifications for the prefix of items in the agenda views.
  1367. An alist with five entries, each for the different agenda types. The
  1368. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1369. The values are format strings.
  1370. This format works similar to a printf format, with the following meaning:
  1371. %c the category of the item, \"Diary\" for entries from the diary,
  1372. or as given by the CATEGORY keyword or derived from the file name
  1373. %e the effort required by the item
  1374. %l the level of the item (insert X space(s) if item is of level X)
  1375. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1376. %T the last tag of the item (ignore inherited tags, which come first)
  1377. %t the HH:MM time-of-day specification if one applies to the entry
  1378. %s Scheduling/Deadline information, a short string
  1379. %b show breadcrumbs, i.e., the names of the higher levels
  1380. %(expression) Eval EXPRESSION and replace the control string
  1381. by the result
  1382. All specifiers work basically like the standard `%s' of printf, but may
  1383. contain two additional characters: a question mark just after the `%'
  1384. and a whitespace/punctuation character just before the final letter.
  1385. If the first character after `%' is a question mark, the entire field
  1386. will only be included if the corresponding value applies to the current
  1387. entry. This is useful for fields which should have fixed width when
  1388. present, but zero width when absent. For example, \"%?-12t\" will
  1389. result in a 12 character time field if a time of the day is specified,
  1390. but will completely disappear in entries which do not contain a time.
  1391. If there is punctuation or whitespace character just before the
  1392. final format letter, this character will be appended to the field
  1393. value if the value is not empty. For example, the format
  1394. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1395. the category is empty, no additional colon is inserted.
  1396. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1397. which means:
  1398. - Indent the line with two space characters
  1399. - Give the category a 12 chars wide field, padded with whitespace on
  1400. the right (because of `-'). Append a colon if there is a category
  1401. (because of `:').
  1402. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1403. time, don't put in an empty field, just skip it (because of '?').
  1404. - Finally, put the scheduling information.
  1405. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1406. `org-agenda-remove-tags'.
  1407. Custom commands can set this variable in the options section."
  1408. :type '(choice
  1409. (string :tag "General format")
  1410. (list :greedy t :tag "View dependent"
  1411. (cons (const agenda) (string :tag "Format"))
  1412. (cons (const timeline) (string :tag "Format"))
  1413. (cons (const todo) (string :tag "Format"))
  1414. (cons (const tags) (string :tag "Format"))
  1415. (cons (const search) (string :tag "Format"))))
  1416. :group 'org-agenda-line-format)
  1417. (defvar org-prefix-format-compiled nil
  1418. "The compiled prefix format and associated variables.
  1419. This is a list where first element is a list of variable bindings, and second
  1420. element is the compiled format expression. See the variable
  1421. `org-agenda-prefix-format'.")
  1422. (defcustom org-agenda-todo-keyword-format "%-1s"
  1423. "Format for the TODO keyword in agenda lines.
  1424. Set this to something like \"%-12s\" if you want all TODO keywords
  1425. to occupy a fixed space in the agenda display."
  1426. :group 'org-agenda-line-format
  1427. :type 'string)
  1428. (defcustom org-agenda-diary-sexp-prefix nil
  1429. "A regexp that matches part of a diary sexp entry
  1430. which should be treated as scheduling/deadline information in
  1431. `org-agenda'.
  1432. For example, you can use this to extract the `diary-remind-message' from
  1433. `diary-remind' entries."
  1434. :group 'org-agenda-line-format
  1435. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1436. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1437. "Text preceding timerange entries in the agenda view.
  1438. This is a list with two strings. The first applies when the range
  1439. is entirely on one day. The second applies if the range spans several days.
  1440. The strings may have two \"%d\" format specifiers which will be filled
  1441. with the sequence number of the days, and the total number of days in the
  1442. range, respectively."
  1443. :group 'org-agenda-line-format
  1444. :type '(list
  1445. (string :tag "Deadline today ")
  1446. (choice :tag "Deadline relative"
  1447. (string :tag "Format string")
  1448. (function))))
  1449. (defcustom org-agenda-scheduled-leaders '(" Scheduled: " "Sched.%3dx: ")
  1450. "Text preceding scheduled items in the agenda view.
  1451. This is a list with two strings. The first applies when the item is
  1452. scheduled on the current day. The second applies when it has been scheduled
  1453. previously, it may contain a %d indicating that this is the nth time that
  1454. this item is scheduled, due to automatic rescheduling of unfinished items
  1455. for the following day. So this number is one larger than the number of days
  1456. that passed since this item was scheduled first."
  1457. :group 'org-agenda-line-format
  1458. :version "24.4"
  1459. :package-version '(Org . "8.0")
  1460. :type '(list
  1461. (string :tag "Scheduled today ")
  1462. (string :tag "Scheduled previously")))
  1463. (defcustom org-agenda-inactive-leader "["
  1464. "Text preceding item pulled into the agenda by inactive time stamps.
  1465. These entries are added to the agenda when pressing \"[\"."
  1466. :group 'org-agenda-line-format
  1467. :version "24.1"
  1468. :type '(list
  1469. (string :tag "Scheduled today ")
  1470. (string :tag "Scheduled previously")))
  1471. (defcustom org-agenda-deadline-leaders '(" Deadline: " " In %3d d.: " "%3d d. ago: ")
  1472. "Text preceding deadline items in the agenda view.
  1473. This is a list with three strings. The first applies when the item has its
  1474. deadline on the current day. The second applies when the deadline is in the
  1475. future, the third one when it is in the past. The strings may contain %d
  1476. to capture the number of days."
  1477. :group 'org-agenda-line-format
  1478. :version "24.4"
  1479. :package-version '(Org . "8.0")
  1480. :type '(list
  1481. (string :tag "Deadline today ")
  1482. (choice :tag "Deadline relative"
  1483. (string :tag "Format string")
  1484. (function))))
  1485. (defcustom org-agenda-remove-times-when-in-prefix t
  1486. "Non-nil means remove duplicate time specifications in agenda items.
  1487. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1488. time-of-day specification in a headline or diary entry is extracted and
  1489. placed into the prefix. If this option is non-nil, the original specification
  1490. \(a timestamp or -range, or just a plain time(range) specification like
  1491. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1492. cluttered.
  1493. The option can be t or nil. It may also be the symbol `beg', indicating
  1494. that the time should only be removed when it is located at the beginning of
  1495. the headline/diary entry."
  1496. :group 'org-agenda-line-format
  1497. :type '(choice
  1498. (const :tag "Always" t)
  1499. (const :tag "Never" nil)
  1500. (const :tag "When at beginning of entry" beg)))
  1501. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1502. "Non-nil means remove time ranges specifications in agenda
  1503. items that span on several days."
  1504. :group 'org-agenda-line-format
  1505. :version "24.1"
  1506. :type 'boolean)
  1507. (defcustom org-agenda-default-appointment-duration nil
  1508. "Default duration for appointments that only have a starting time.
  1509. When nil, no duration is specified in such cases.
  1510. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1511. :group 'org-agenda-line-format
  1512. :type '(choice
  1513. (integer :tag "Minutes")
  1514. (const :tag "No default duration")))
  1515. (defcustom org-agenda-show-inherited-tags t
  1516. "Non-nil means show inherited tags in each agenda line.
  1517. When this option is set to 'always, it take precedences over
  1518. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1519. in every agenda.
  1520. When this option is set to t (the default), inherited tags are
  1521. shown when they are available, i.e. when the value of
  1522. `org-agenda-use-tag-inheritance' has been taken into account.
  1523. This can be set to a list of agenda types in which the agenda
  1524. must display the inherited tags. Available types are 'todo,
  1525. 'agenda, 'search and 'timeline.
  1526. When set to nil, never show inherited tags in agenda lines."
  1527. :group 'org-agenda-line-format
  1528. :group 'org-agenda
  1529. :version "24.3"
  1530. :type '(choice
  1531. (const :tag "Show inherited tags when available" t)
  1532. (const :tag "Always show inherited tags" 'always)
  1533. (repeat :tag "Show inherited tags only in selected agenda types"
  1534. (symbol :tag "Agenda type"))))
  1535. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1536. "List of agenda view types where to use tag inheritance.
  1537. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1538. controlled by `org-use-tag-inheritance'. In other agenda types,
  1539. `org-use-tag-inheritance' is not used for the selection of the
  1540. agenda entries. Still, you may want the agenda to be aware of
  1541. the inherited tags anyway, e.g. for later tag filtering.
  1542. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1543. This variable has no effect if `org-agenda-show-inherited-tags'
  1544. is set to 'always. In that case, the agenda is aware of those
  1545. tags.
  1546. The default value sets tags in every agenda type. Setting this
  1547. option to nil will speed up non-tags agenda view a lot."
  1548. :group 'org-agenda
  1549. :version "24.3"
  1550. :type '(choice
  1551. (const :tag "Use tag inheritance in all agenda types" t)
  1552. (repeat :tag "Use tag inheritance in selected agenda types"
  1553. (symbol :tag "Agenda type"))))
  1554. (defcustom org-agenda-hide-tags-regexp nil
  1555. "Regular expression used to filter away specific tags in agenda views.
  1556. This means that these tags will be present, but not be shown in the agenda
  1557. line. Secondary filtering will still work on the hidden tags.
  1558. Nil means don't hide any tags."
  1559. :group 'org-agenda-line-format
  1560. :type '(choice
  1561. (const :tag "Hide none" nil)
  1562. (string :tag "Regexp ")))
  1563. (defcustom org-agenda-remove-tags nil
  1564. "Non-nil means remove the tags from the headline copy in the agenda.
  1565. When this is the symbol `prefix', only remove tags when
  1566. `org-agenda-prefix-format' contains a `%T' specifier."
  1567. :group 'org-agenda-line-format
  1568. :type '(choice
  1569. (const :tag "Always" t)
  1570. (const :tag "Never" nil)
  1571. (const :tag "When prefix format contains %T" prefix)))
  1572. (if (fboundp 'defvaralias)
  1573. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1574. 'org-agenda-remove-tags))
  1575. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1576. "Shift tags in agenda items to this column.
  1577. If this number is positive, it specifies the column. If it is negative,
  1578. it means that the tags should be flushright to that column. For example,
  1579. -80 works well for a normal 80 character screen."
  1580. :group 'org-agenda-line-format
  1581. :type 'integer)
  1582. (if (fboundp 'defvaralias)
  1583. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1584. (defcustom org-agenda-fontify-priorities 'cookies
  1585. "Non-nil means highlight low and high priorities in agenda.
  1586. When t, the highest priority entries are bold, lowest priority italic.
  1587. However, settings in `org-priority-faces' will overrule these faces.
  1588. When this variable is the symbol `cookies', only fontify the
  1589. cookies, not the entire task.
  1590. This may also be an association list of priority faces, whose
  1591. keys are the character values of `org-highest-priority',
  1592. `org-default-priority', and `org-lowest-priority' (the default values
  1593. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1594. color as a string, or a list like `(:background \"Red\")'.
  1595. If it is a color, the variable `org-faces-easy-properties'
  1596. determines if it is a foreground or a background color."
  1597. :group 'org-agenda-line-format
  1598. :type '(choice
  1599. (const :tag "Never" nil)
  1600. (const :tag "Defaults" t)
  1601. (const :tag "Cookies only" cookies)
  1602. (repeat :tag "Specify"
  1603. (list (character :tag "Priority" :value ?A)
  1604. (choice :tag "Face "
  1605. (string :tag "Color")
  1606. (sexp :tag "Face"))))))
  1607. (defcustom org-agenda-day-face-function nil
  1608. "Function called to determine what face should be used to display a day.
  1609. The only argument passed to that function is the day. It should
  1610. returns a face, or nil if does not want to specify a face and let
  1611. the normal rules apply."
  1612. :group 'org-agenda-line-format
  1613. :version "24.1"
  1614. :type 'function)
  1615. (defcustom org-agenda-category-icon-alist nil
  1616. "Alist of category icon to be displayed in agenda views.
  1617. Each entry should have the following format:
  1618. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1619. Where CATEGORY-REGEXP is a regexp matching the categories where
  1620. the icon should be displayed.
  1621. FILE-OR-DATA either a file path or a string containing image data.
  1622. The other fields can be omitted safely if not needed:
  1623. TYPE indicates the image type.
  1624. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1625. image data.
  1626. PROPS are additional image attributes to assign to the image,
  1627. like, e.g. `:ascent center'.
  1628. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1629. If you want to set the display properties yourself, just put a
  1630. list as second element:
  1631. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1632. For example, to display a 16px horizontal space for Emacs
  1633. category, you can use:
  1634. (\"Emacs\" '(space . (:width (16))))"
  1635. :group 'org-agenda-line-format
  1636. :version "24.1"
  1637. :type '(alist :key-type (string :tag "Regexp matching category")
  1638. :value-type (choice (list :tag "Icon"
  1639. (string :tag "File or data")
  1640. (symbol :tag "Type")
  1641. (boolean :tag "Data?")
  1642. (repeat :tag "Extra image properties" :inline t symbol))
  1643. (list :tag "Display properties" sexp))))
  1644. (defgroup org-agenda-column-view nil
  1645. "Options concerning column view in the agenda."
  1646. :tag "Org Agenda Column View"
  1647. :group 'org-agenda)
  1648. (defcustom org-agenda-columns-show-summaries t
  1649. "Non-nil means show summaries for columns displayed in the agenda view."
  1650. :group 'org-agenda-column-view
  1651. :type 'boolean)
  1652. (defcustom org-agenda-columns-compute-summary-properties t
  1653. "Non-nil means recompute all summary properties before column view.
  1654. When column view in the agenda is listing properties that have a summary
  1655. operator, it can go to all relevant buffers and recompute the summaries
  1656. there. This can mean overhead for the agenda column view, but is necessary
  1657. to have thing up to date.
  1658. As a special case, a CLOCKSUM property also makes sure that the clock
  1659. computations are current."
  1660. :group 'org-agenda-column-view
  1661. :type 'boolean)
  1662. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1663. "Non-nil means the duration of an appointment will add to day effort.
  1664. The property to which appointment durations will be added is the one given
  1665. in the option `org-effort-property'. If an appointment does not have
  1666. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1667. is not set, an appointment without end time will not contribute to the time
  1668. estimate."
  1669. :group 'org-agenda-column-view
  1670. :type 'boolean)
  1671. (defcustom org-agenda-auto-exclude-function nil
  1672. "A function called with a tag to decide if it is filtered on '/ RET'.
  1673. The sole argument to the function, which is called once for each
  1674. possible tag, is a string giving the name of the tag. The
  1675. function should return either nil if the tag should be included
  1676. as normal, or \"-<TAG>\" to exclude the tag.
  1677. Note that for the purpose of tag filtering, only the lower-case version of
  1678. all tags will be considered, so that this function will only ever see
  1679. the lower-case version of all tags."
  1680. :group 'org-agenda
  1681. :type 'function)
  1682. (defcustom org-agenda-bulk-custom-functions nil
  1683. "Alist of characters and custom functions for bulk actions.
  1684. For example, this value makes those two functions available:
  1685. '((?R set-category)
  1686. (?C bulk-cut))
  1687. With selected entries in an agenda buffer, `B R' will call
  1688. the custom function `set-category' on the selected entries.
  1689. Note that functions in this alist don't need to be quoted."
  1690. :type 'alist
  1691. :version "24.1"
  1692. :group 'org-agenda)
  1693. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1694. "Execute BODY with point at location given by `org-hd-marker' property.
  1695. If STRING is non-nil, the text property will be fetched from position 0
  1696. in that string. If STRING is nil, it will be fetched from the beginning
  1697. of the current line."
  1698. (org-with-gensyms (marker)
  1699. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1700. 'org-hd-marker ,string)))
  1701. (with-current-buffer (marker-buffer ,marker)
  1702. (save-excursion
  1703. (goto-char ,marker)
  1704. ,@body)))))
  1705. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1706. (defun org-add-agenda-custom-command (entry)
  1707. "Replace or add a command in `org-agenda-custom-commands'.
  1708. This is mostly for hacking and trying a new command - once the command
  1709. works you probably want to add it to `org-agenda-custom-commands' for good."
  1710. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1711. (if ass
  1712. (setcdr ass (cdr entry))
  1713. (push entry org-agenda-custom-commands))))
  1714. ;;; Define the org-agenda-mode
  1715. (defvar org-agenda-mode-map (make-sparse-keymap)
  1716. "Keymap for `org-agenda-mode'.")
  1717. (if (fboundp 'defvaralias)
  1718. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1719. (defvar org-agenda-menu) ; defined later in this file.
  1720. (defvar org-agenda-restrict nil) ; defined later in this file.
  1721. (defvar org-agenda-follow-mode nil)
  1722. (defvar org-agenda-entry-text-mode nil)
  1723. (defvar org-agenda-clockreport-mode nil)
  1724. (defvar org-agenda-show-log nil)
  1725. (defvar org-agenda-redo-command nil)
  1726. (defvar org-agenda-query-string nil)
  1727. (defvar org-agenda-mode-hook nil
  1728. "Hook run after `org-agenda-mode' is turned on.
  1729. The buffer is still writable when this hook is called.")
  1730. (defvar org-agenda-type nil)
  1731. (defvar org-agenda-force-single-file nil)
  1732. (defvar org-agenda-bulk-marked-entries nil
  1733. "List of markers that refer to marked entries in the agenda.")
  1734. ;;; Multiple agenda buffers support
  1735. (defcustom org-agenda-sticky nil
  1736. "Non-nil means agenda q key will bury agenda buffers.
  1737. Agenda commands will then show existing buffer instead of generating new ones.
  1738. When nil, `q' will kill the single agenda buffer."
  1739. :group 'org-agenda
  1740. :version "24.3"
  1741. :type 'boolean)
  1742. ;;;###autoload
  1743. (defun org-toggle-sticky-agenda (&optional arg)
  1744. "Toggle `org-agenda-sticky'."
  1745. (interactive "P")
  1746. (let ((new-value (if arg
  1747. (> (prefix-numeric-value arg) 0)
  1748. (not org-agenda-sticky))))
  1749. (if (equal new-value org-agenda-sticky)
  1750. (and (org-called-interactively-p 'interactive)
  1751. (message "Sticky agenda was already %s"
  1752. (if org-agenda-sticky "enabled" "disabled")))
  1753. (setq org-agenda-sticky new-value)
  1754. (org-agenda-kill-all-agenda-buffers)
  1755. (and (org-called-interactively-p 'interactive)
  1756. (message "Sticky agenda was %s"
  1757. (if org-agenda-sticky "enabled" "disabled"))))))
  1758. (defvar org-agenda-buffer nil
  1759. "Agenda buffer currently being generated.")
  1760. (defvar org-agenda-last-prefix-arg nil)
  1761. (defvar org-agenda-this-buffer-name nil)
  1762. (defvar org-agenda-doing-sticky-redo nil)
  1763. (defvar org-agenda-this-buffer-is-sticky nil)
  1764. (defconst org-agenda-local-vars
  1765. '(org-agenda-this-buffer-name
  1766. org-agenda-undo-list
  1767. org-agenda-pending-undo-list
  1768. org-agenda-follow-mode
  1769. org-agenda-entry-text-mode
  1770. org-agenda-clockreport-mode
  1771. org-agenda-show-log
  1772. org-agenda-redo-command
  1773. org-agenda-query-string
  1774. org-agenda-type
  1775. org-agenda-bulk-marked-entries
  1776. org-agenda-undo-has-started-in
  1777. org-agenda-info
  1778. org-agenda-tag-filter-overlays
  1779. org-agenda-cat-filter-overlays
  1780. org-agenda-pre-window-conf
  1781. org-agenda-columns-active
  1782. org-agenda-tag-filter
  1783. org-agenda-category-filter
  1784. org-agenda-markers
  1785. org-agenda-last-search-view-search-was-boolean
  1786. org-agenda-filtered-by-category
  1787. org-agenda-filter-form
  1788. org-agenda-cycle-counter
  1789. org-agenda-last-prefix-arg)
  1790. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1791. (defun org-agenda-mode ()
  1792. "Mode for time-sorted view on action items in Org-mode files.
  1793. The following commands are available:
  1794. \\{org-agenda-mode-map}"
  1795. (interactive)
  1796. (cond (org-agenda-doing-sticky-redo
  1797. ;; Refreshing sticky agenda-buffer
  1798. ;;
  1799. ;; Preserve the value of `org-agenda-local-vars' variables,
  1800. ;; while letting `kill-all-local-variables' kill the rest
  1801. (let ((save (buffer-local-variables)))
  1802. (kill-all-local-variables)
  1803. (mapc 'make-local-variable org-agenda-local-vars)
  1804. (dolist (elem save)
  1805. (let ((var (car elem))
  1806. (val (cdr elem)))
  1807. (when (and val
  1808. (member var org-agenda-local-vars))
  1809. (set var val)))))
  1810. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1811. (org-agenda-sticky
  1812. ;; Creating a sticky Agenda buffer for the first time
  1813. (kill-all-local-variables)
  1814. (mapc 'make-local-variable org-agenda-local-vars)
  1815. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1816. (t
  1817. ;; Creating a non-sticky agenda buffer
  1818. (kill-all-local-variables)
  1819. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1820. (setq org-agenda-undo-list nil
  1821. org-agenda-pending-undo-list nil
  1822. org-agenda-bulk-marked-entries nil)
  1823. (setq major-mode 'org-agenda-mode)
  1824. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1825. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1826. (setq mode-name "Org-Agenda")
  1827. (use-local-map org-agenda-mode-map)
  1828. (easy-menu-add org-agenda-menu)
  1829. (if org-startup-truncated (setq truncate-lines t))
  1830. (org-set-local 'line-move-visual nil)
  1831. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1832. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1833. ;; Make sure properties are removed when copying text
  1834. (make-local-variable 'filter-buffer-substring-functions)
  1835. (add-hook 'filter-buffer-substring-functions
  1836. (lambda (fun start end delete)
  1837. (substring-no-properties (funcall fun start end delete))))
  1838. (unless org-agenda-keep-modes
  1839. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1840. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1841. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1842. org-agenda-show-log org-agenda-start-with-log-mode))
  1843. (easy-menu-change
  1844. '("Agenda") "Agenda Files"
  1845. (append
  1846. (list
  1847. (vector
  1848. (if (get 'org-agenda-files 'org-restrict)
  1849. "Restricted to single file"
  1850. "Edit File List")
  1851. '(org-edit-agenda-file-list)
  1852. (not (get 'org-agenda-files 'org-restrict)))
  1853. "--")
  1854. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1855. (org-agenda-set-mode-name)
  1856. (apply
  1857. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1858. (list 'org-agenda-mode-hook)))
  1859. (substitute-key-definition 'undo 'org-agenda-undo
  1860. org-agenda-mode-map global-map)
  1861. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1862. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1863. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1864. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1865. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1866. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1867. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1868. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1869. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1870. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1871. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1872. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1873. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1874. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1875. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1877. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1878. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1879. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1880. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1881. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1882. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1883. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1884. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1885. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1886. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1887. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1888. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1889. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1890. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1891. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1892. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1893. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1894. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1895. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1896. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1897. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1898. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1899. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1900. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1901. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1902. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1903. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1904. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1905. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1906. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1907. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1908. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1909. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1910. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1911. (while l (org-defkey org-agenda-mode-map
  1912. (int-to-string (pop l)) 'digit-argument)))
  1913. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1914. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1915. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1916. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1917. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1918. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1919. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1920. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1921. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1922. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1923. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1924. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1925. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1926. 'org-clock-modify-effort-estimate)
  1927. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1928. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1929. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1930. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1931. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1932. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1933. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1934. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1935. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1936. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1937. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1938. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1939. (substitute-key-definition 'next-line 'org-agenda-next-line
  1940. org-agenda-mode-map global-map)
  1941. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1942. org-agenda-mode-map global-map)
  1943. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1944. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1945. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1946. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1947. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1948. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1949. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1950. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1951. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1952. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1953. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1954. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1955. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1956. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1957. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1958. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1959. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1960. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1961. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1962. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1963. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1964. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1965. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1966. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1967. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1968. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1969. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1970. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1971. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1972. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1973. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1974. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1975. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1976. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1977. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1978. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1979. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1980. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1981. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1982. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1983. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1984. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1985. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1986. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1987. (when org-agenda-mouse-1-follows-link
  1988. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1989. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1990. '("Agenda"
  1991. ("Agenda Files")
  1992. "--"
  1993. ("Agenda Dates"
  1994. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1995. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1996. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1997. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1998. "--"
  1999. ("View"
  2000. ["Day View" org-agenda-day-view
  2001. :active (org-agenda-check-type nil 'agenda)
  2002. :style radio :selected (eq org-agenda-current-span 'day)
  2003. :keys "v d (or just d)"]
  2004. ["Week View" org-agenda-week-view
  2005. :active (org-agenda-check-type nil 'agenda)
  2006. :style radio :selected (eq org-agenda-current-span 'week)
  2007. :keys "v w (or just w)"]
  2008. ["Month View" org-agenda-month-view
  2009. :active (org-agenda-check-type nil 'agenda)
  2010. :style radio :selected (eq org-agenda-current-span 'month)
  2011. :keys "v m"]
  2012. ["Year View" org-agenda-year-view
  2013. :active (org-agenda-check-type nil 'agenda)
  2014. :style radio :selected (eq org-agenda-current-span 'year)
  2015. :keys "v y"]
  2016. "--"
  2017. ["Include Diary" org-agenda-toggle-diary
  2018. :style toggle :selected org-agenda-include-diary
  2019. :active (org-agenda-check-type nil 'agenda)]
  2020. ["Include Deadlines" org-agenda-toggle-deadlines
  2021. :style toggle :selected org-agenda-include-deadlines
  2022. :active (org-agenda-check-type nil 'agenda)]
  2023. ["Use Time Grid" org-agenda-toggle-time-grid
  2024. :style toggle :selected org-agenda-use-time-grid
  2025. :active (org-agenda-check-type nil 'agenda)]
  2026. "--"
  2027. ["Show clock report" org-agenda-clockreport-mode
  2028. :style toggle :selected org-agenda-clockreport-mode
  2029. :active (org-agenda-check-type nil 'agenda)]
  2030. ["Show some entry text" org-agenda-entry-text-mode
  2031. :style toggle :selected org-agenda-entry-text-mode
  2032. :active t]
  2033. "--"
  2034. ["Show Logbook entries" org-agenda-log-mode
  2035. :style toggle :selected org-agenda-show-log
  2036. :active (org-agenda-check-type nil 'agenda 'timeline)
  2037. :keys "v l (or just l)"]
  2038. ["Include archived trees" org-agenda-archives-mode
  2039. :style toggle :selected org-agenda-archives-mode :active t
  2040. :keys "v a"]
  2041. ["Include archive files" (org-agenda-archives-mode t)
  2042. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2043. :keys "v A"]
  2044. "--"
  2045. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2046. ["Write view to file" org-agenda-write t]
  2047. ["Rebuild buffer" org-agenda-redo t]
  2048. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2049. "--"
  2050. ["Show original entry" org-agenda-show t]
  2051. ["Go To (other window)" org-agenda-goto t]
  2052. ["Go To (this window)" org-agenda-switch-to t]
  2053. ["Capture with cursor date" org-agenda-capture t]
  2054. ["Follow Mode" org-agenda-follow-mode
  2055. :style toggle :selected org-agenda-follow-mode :active t]
  2056. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2057. "--"
  2058. ("TODO"
  2059. ["Cycle TODO" org-agenda-todo t]
  2060. ["Next TODO set" org-agenda-todo-nextset t]
  2061. ["Previous TODO set" org-agenda-todo-previousset t]
  2062. ["Add note" org-agenda-add-note t])
  2063. ("Archive/Refile/Delete"
  2064. ["Archive default" org-agenda-archive-default t]
  2065. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2066. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2067. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2068. ["Archive subtree" org-agenda-archive t]
  2069. "--"
  2070. ["Refile" org-agenda-refile t]
  2071. "--"
  2072. ["Delete subtree" org-agenda-kill t])
  2073. ("Bulk action"
  2074. ["Mark entry" org-agenda-bulk-mark t]
  2075. ["Mark all" org-agenda-bulk-mark-all t]
  2076. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2077. ["Unmark entry" org-agenda-bulk-unmark t]
  2078. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2079. ["Act on all marked" org-agenda-bulk-action t]
  2080. "--"
  2081. ("Tags and Properties"
  2082. ["Show all Tags" org-agenda-show-tags t]
  2083. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2084. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2085. "--"
  2086. ["Column View" org-columns t])
  2087. ("Deadline/Schedule"
  2088. ["Schedule" org-agenda-schedule t]
  2089. ["Set Deadline" org-agenda-deadline t]
  2090. "--"
  2091. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2092. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2093. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2094. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2095. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2096. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2097. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2098. ("Clock and Effort"
  2099. ["Clock in" org-agenda-clock-in t]
  2100. ["Clock out" org-agenda-clock-out t]
  2101. ["Clock cancel" org-agenda-clock-cancel t]
  2102. ["Goto running clock" org-clock-goto t]
  2103. "--"
  2104. ["Set Effort" org-agenda-set-effort t]
  2105. ["Change clocked effort" org-clock-modify-effort-estimate
  2106. (org-clock-is-active)])
  2107. ("Priority"
  2108. ["Set Priority" org-agenda-priority t]
  2109. ["Increase Priority" org-agenda-priority-up t]
  2110. ["Decrease Priority" org-agenda-priority-down t]
  2111. ["Show Priority" org-show-priority t])
  2112. ("Calendar/Diary"
  2113. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2114. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2115. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2116. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2117. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2118. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2119. "--"
  2120. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2121. "--"
  2122. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2123. "--"
  2124. ("MobileOrg"
  2125. ["Push Files and Views" org-mobile-push t]
  2126. ["Get Captured and Flagged" org-mobile-pull t]
  2127. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2128. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2129. "--"
  2130. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2131. "--"
  2132. ["Quit" org-agenda-quit t]
  2133. ["Exit and Release Buffers" org-agenda-exit t]
  2134. ))
  2135. ;;; Agenda undo
  2136. (defvar org-agenda-allow-remote-undo t
  2137. "Non-nil means allow remote undo from the agenda buffer.")
  2138. (defvar org-agenda-undo-has-started-in nil
  2139. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2140. (defun org-agenda-undo ()
  2141. "Undo a remote editing step in the agenda.
  2142. This undoes changes both in the agenda buffer and in the remote buffer
  2143. that have been changed along."
  2144. (interactive)
  2145. (or org-agenda-allow-remote-undo
  2146. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2147. (if (not (eq this-command last-command))
  2148. (setq org-agenda-undo-has-started-in nil
  2149. org-agenda-pending-undo-list org-agenda-undo-list))
  2150. (if (not org-agenda-pending-undo-list)
  2151. (error "No further undo information"))
  2152. (let* ((entry (pop org-agenda-pending-undo-list))
  2153. buf line cmd rembuf)
  2154. (setq cmd (pop entry) line (pop entry))
  2155. (setq rembuf (nth 2 entry))
  2156. (org-with-remote-undo rembuf
  2157. (while (bufferp (setq buf (pop entry)))
  2158. (if (pop entry)
  2159. (with-current-buffer buf
  2160. (let ((last-undo-buffer buf)
  2161. (inhibit-read-only t))
  2162. (unless (memq buf org-agenda-undo-has-started-in)
  2163. (push buf org-agenda-undo-has-started-in)
  2164. (make-local-variable 'pending-undo-list)
  2165. (undo-start))
  2166. (while (and pending-undo-list
  2167. (listp pending-undo-list)
  2168. (not (car pending-undo-list)))
  2169. (pop pending-undo-list))
  2170. (undo-more 1))))))
  2171. (org-goto-line line)
  2172. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2173. (defun org-verify-change-for-undo (l1 l2)
  2174. "Verify that a real change occurred between the undo lists L1 and L2."
  2175. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2176. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2177. (not (eq l1 l2)))
  2178. ;;; Agenda dispatch
  2179. (defvar org-agenda-restrict-begin (make-marker))
  2180. (defvar org-agenda-restrict-end (make-marker))
  2181. (defvar org-agenda-last-dispatch-buffer nil)
  2182. (defvar org-agenda-overriding-restriction nil)
  2183. (defcustom org-agenda-custom-commands-contexts nil
  2184. "Alist of custom agenda keys and contextual rules.
  2185. For example, if you have a custom agenda command \"p\" and you
  2186. want this command to be accessible only from plain text files,
  2187. use this:
  2188. '((\"p\" ((in-file . \"\\.txt\"))))
  2189. Here are the available contexts definitions:
  2190. in-file: command displayed only in matching files
  2191. in-mode: command displayed only in matching modes
  2192. not-in-file: command not displayed in matching files
  2193. not-in-mode: command not displayed in matching modes
  2194. in-buffer: command displayed only in matching buffers
  2195. not-in-buffer: command not displayed in matching buffers
  2196. [function]: a custom function taking no argument
  2197. If you define several checks, the agenda command will be
  2198. accessible if there is at least one valid check.
  2199. You can also bind a key to another agenda custom command
  2200. depending on contextual rules.
  2201. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2202. Here it means: in .txt files, use \"p\" as the key for the
  2203. agenda command otherwise associated with \"q\". (The command
  2204. originally associated with \"q\" is not displayed to avoid
  2205. duplicates.)"
  2206. :version "24.3"
  2207. :group 'org-agenda-custom-commands
  2208. :type '(repeat (list :tag "Rule"
  2209. (string :tag " Agenda key")
  2210. (string :tag "Replace by command")
  2211. (repeat :tag "Available when"
  2212. (choice
  2213. (cons :tag "Condition"
  2214. (choice
  2215. (const :tag "In file" in-file)
  2216. (const :tag "Not in file" not-in-file)
  2217. (const :tag "In buffer" in-buffer)
  2218. (const :tag "Not in buffer" not-in-buffer)
  2219. (const :tag "In mode" in-mode)
  2220. (const :tag "Not in mode" not-in-mode))
  2221. (regexp))
  2222. (function :tag "Custom function"))))))
  2223. (defcustom org-agenda-max-entries nil
  2224. "Maximum number of entries to display in an agenda.
  2225. This can be nil (no limit) or an integer or an alist of agenda
  2226. types with an associated number of entries to display in this
  2227. type."
  2228. :version "24.4"
  2229. :package-version '(Org . "8.0")
  2230. :group 'org-agenda-custom-commands
  2231. :type '(choice (symbol :tag "No limit" nil)
  2232. (integer :tag "Max number of entries")
  2233. (repeat
  2234. (cons (choice :tag "Agenda type"
  2235. (const agenda)
  2236. (const todo)
  2237. (const tags)
  2238. (const search)
  2239. (const timeline))
  2240. (integer :tag "Max number of entries")))))
  2241. (defcustom org-agenda-max-todos nil
  2242. "Maximum number of TODOs to display in an agenda.
  2243. This can be nil (no limit) or an integer or an alist of agenda
  2244. types with an associated number of entries to display in this
  2245. type."
  2246. :version "24.4"
  2247. :package-version '(Org . "8.0")
  2248. :group 'org-agenda-custom-commands
  2249. :type '(choice (symbol :tag "No limit" nil)
  2250. (integer :tag "Max number of entries")
  2251. (repeat
  2252. (cons (choice :tag "Agenda type"
  2253. (const agenda)
  2254. (const todo)
  2255. (const tags)
  2256. (const search)
  2257. (const timeline))
  2258. (integer :tag "Max number of entries")))))
  2259. (defcustom org-agenda-max-tags nil
  2260. "Maximum number of tagged entries to display in an agenda.
  2261. This can be nil (no limit) or an integer or an alist of agenda
  2262. types with an associated number of entries to display in this
  2263. type."
  2264. :version "24.4"
  2265. :package-version '(Org . "8.0")
  2266. :group 'org-agenda-custom-commands
  2267. :type '(choice (symbol :tag "No limit" nil)
  2268. (integer :tag "Max number of entries")
  2269. (repeat
  2270. (cons (choice :tag "Agenda type"
  2271. (const agenda)
  2272. (const todo)
  2273. (const tags)
  2274. (const search)
  2275. (const timeline))
  2276. (integer :tag "Max number of entries")))))
  2277. (defcustom org-agenda-max-effort nil
  2278. "Maximum cumulated effort duration for the agenda.
  2279. This can be nil (no limit) or a number of minutes (as an integer)
  2280. or an alist of agenda types with an associated number of minutes
  2281. to limit entries to in this type."
  2282. :version "24.4"
  2283. :package-version '(Org . "8.0")
  2284. :group 'org-agenda-custom-commands
  2285. :type '(choice (symbol :tag "No limit" nil)
  2286. (integer :tag "Max number of entries")
  2287. (repeat
  2288. (cons (choice :tag "Agenda type"
  2289. (const agenda)
  2290. (const todo)
  2291. (const tags)
  2292. (const search)
  2293. (const timeline))
  2294. (integer :tag "Max number of entries")))))
  2295. (defvar org-keys nil)
  2296. (defvar org-match nil)
  2297. ;;;###autoload
  2298. (defun org-agenda (&optional arg org-keys restriction)
  2299. "Dispatch agenda commands to collect entries to the agenda buffer.
  2300. Prompts for a command to execute. Any prefix arg will be passed
  2301. on to the selected command. The default selections are:
  2302. a Call `org-agenda-list' to display the agenda for current day or week.
  2303. t Call `org-todo-list' to display the global todo list.
  2304. T Call `org-todo-list' to display the global todo list, select only
  2305. entries with a specific TODO keyword (the user gets a prompt).
  2306. m Call `org-tags-view' to display headlines with tags matching
  2307. a condition (the user is prompted for the condition).
  2308. M Like `m', but select only TODO entries, no ordinary headlines.
  2309. L Create a timeline for the current buffer.
  2310. e Export views to associated files.
  2311. s Search entries for keywords.
  2312. S Search entries for keywords, only with TODO keywords.
  2313. / Multi occur across all agenda files and also files listed
  2314. in `org-agenda-text-search-extra-files'.
  2315. < Restrict agenda commands to buffer, subtree, or region.
  2316. Press several times to get the desired effect.
  2317. > Remove a previous restriction.
  2318. # List \"stuck\" projects.
  2319. ! Configure what \"stuck\" means.
  2320. C Configure custom agenda commands.
  2321. More commands can be added by configuring the variable
  2322. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2323. searches can be pre-defined in this way.
  2324. If the current buffer is in Org-mode and visiting a file, you can also
  2325. first press `<' once to indicate that the agenda should be temporarily
  2326. \(until the next use of \\[org-agenda]) restricted to the current file.
  2327. Pressing `<' twice means to restrict to the current subtree or region
  2328. \(if active)."
  2329. (interactive "P")
  2330. (catch 'exit
  2331. (let* ((prefix-descriptions nil)
  2332. (org-agenda-buffer-name org-agenda-buffer-name)
  2333. (org-agenda-window-setup (if (equal (buffer-name)
  2334. org-agenda-buffer-name)
  2335. 'current-window
  2336. org-agenda-window-setup))
  2337. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2338. (org-agenda-custom-commands
  2339. ;; normalize different versions
  2340. (delq nil
  2341. (mapcar
  2342. (lambda (x)
  2343. (cond ((stringp (cdr x))
  2344. (push x prefix-descriptions)
  2345. nil)
  2346. ((stringp (nth 1 x)) x)
  2347. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2348. (t (cons (car x) (cons "" (cdr x))))))
  2349. org-agenda-custom-commands)))
  2350. (org-agenda-custom-commands
  2351. (org-contextualize-keys
  2352. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2353. (buf (current-buffer))
  2354. (bfn (buffer-file-name (buffer-base-buffer)))
  2355. entry key type org-match lprops ans)
  2356. ;; Turn off restriction unless there is an overriding one,
  2357. (unless org-agenda-overriding-restriction
  2358. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2359. ;; There is a request to keep the file list in place
  2360. (put 'org-agenda-files 'org-restrict nil))
  2361. (setq org-agenda-restrict nil)
  2362. (move-marker org-agenda-restrict-begin nil)
  2363. (move-marker org-agenda-restrict-end nil))
  2364. ;; Delete old local properties
  2365. (put 'org-agenda-redo-command 'org-lprops nil)
  2366. ;; Delete previously set last-arguments
  2367. (put 'org-agenda-redo-command 'last-args nil)
  2368. ;; Remember where this call originated
  2369. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2370. (unless org-keys
  2371. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2372. org-keys (car ans)
  2373. restriction (cdr ans)))
  2374. ;; If we have sticky agenda buffers, set a name for the buffer,
  2375. ;; depending on the invoking keys. The user may still set this
  2376. ;; as a command option, which will overwrite what we do here.
  2377. (if org-agenda-sticky
  2378. (setq org-agenda-buffer-name
  2379. (format "*Org Agenda(%s)*" org-keys)))
  2380. ;; Establish the restriction, if any
  2381. (when (and (not org-agenda-overriding-restriction) restriction)
  2382. (put 'org-agenda-files 'org-restrict (list bfn))
  2383. (cond
  2384. ((eq restriction 'region)
  2385. (setq org-agenda-restrict t)
  2386. (move-marker org-agenda-restrict-begin (region-beginning))
  2387. (move-marker org-agenda-restrict-end (region-end)))
  2388. ((eq restriction 'subtree)
  2389. (save-excursion
  2390. (setq org-agenda-restrict t)
  2391. (org-back-to-heading t)
  2392. (move-marker org-agenda-restrict-begin (point))
  2393. (move-marker org-agenda-restrict-end
  2394. (progn (org-end-of-subtree t)))))))
  2395. ;; For example the todo list should not need it (but does...)
  2396. (cond
  2397. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2398. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2399. (progn
  2400. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2401. lprops (nth 4 entry))
  2402. (if org-agenda-sticky
  2403. (setq org-agenda-buffer-name
  2404. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2405. (format "*Org Agenda(%s)*" org-keys))))
  2406. (put 'org-agenda-redo-command 'org-lprops lprops)
  2407. (cond
  2408. ((eq type 'agenda)
  2409. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2410. ((eq type 'alltodo)
  2411. (org-let lprops '(org-todo-list current-prefix-arg)))
  2412. ((eq type 'search)
  2413. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2414. ((eq type 'stuck)
  2415. (org-let lprops '(org-agenda-list-stuck-projects
  2416. current-prefix-arg)))
  2417. ((eq type 'tags)
  2418. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2419. ((eq type 'tags-todo)
  2420. (org-let lprops '(org-tags-view '(4) org-match)))
  2421. ((eq type 'todo)
  2422. (org-let lprops '(org-todo-list org-match)))
  2423. ((eq type 'tags-tree)
  2424. (org-check-for-org-mode)
  2425. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2426. ((eq type 'todo-tree)
  2427. (org-check-for-org-mode)
  2428. (org-let lprops
  2429. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2430. (regexp-quote org-match) "\\>"))))
  2431. ((eq type 'occur-tree)
  2432. (org-check-for-org-mode)
  2433. (org-let lprops '(org-occur org-match)))
  2434. ((functionp type)
  2435. (org-let lprops '(funcall type org-match)))
  2436. ((fboundp type)
  2437. (org-let lprops '(funcall type org-match)))
  2438. (t (error "Invalid custom agenda command type %s" type))))
  2439. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2440. ((equal org-keys "C")
  2441. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2442. (customize-variable 'org-agenda-custom-commands))
  2443. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2444. ((equal org-keys "s") (call-interactively 'org-search-view))
  2445. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2446. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2447. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2448. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2449. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2450. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2451. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2452. (org-add-hook
  2453. 'post-command-hook
  2454. (lambda ()
  2455. (unless (current-message)
  2456. (let* ((m (org-agenda-get-any-marker))
  2457. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2458. (when note
  2459. (message (concat
  2460. "FLAGGING-NOTE ([?] for more info): "
  2461. (org-add-props
  2462. (replace-regexp-in-string
  2463. "\\\\n" "//"
  2464. (copy-sequence note))
  2465. nil 'face 'org-warning)))))))
  2466. t t))
  2467. ((equal org-keys "L")
  2468. (unless (derived-mode-p 'org-mode)
  2469. (error "This is not an Org-mode file"))
  2470. (unless restriction
  2471. (put 'org-agenda-files 'org-restrict (list bfn))
  2472. (org-call-with-arg 'org-timeline arg)))
  2473. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2474. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2475. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2476. (t (error "Invalid agenda key"))))))
  2477. (defun org-agenda-append-agenda ()
  2478. "Append another agenda view to the current one.
  2479. This function allows interactive building of block agendas.
  2480. Agenda views are separated by `org-agenda-block-separator'."
  2481. (interactive)
  2482. (unless (derived-mode-p 'org-agenda-mode)
  2483. (error "Can only append from within agenda buffer"))
  2484. (let ((org-agenda-multi t))
  2485. (org-agenda)
  2486. (widen)
  2487. (org-agenda-finalize)
  2488. (org-agenda-fit-window-to-buffer)))
  2489. (defun org-agenda-normalize-custom-commands (cmds)
  2490. (delq nil
  2491. (mapcar
  2492. (lambda (x)
  2493. (cond ((stringp (cdr x)) nil)
  2494. ((stringp (nth 1 x)) x)
  2495. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2496. (t (cons (car x) (cons "" (cdr x))))))
  2497. cmds)))
  2498. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2499. "The user interface for selecting an agenda command."
  2500. (catch 'exit
  2501. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2502. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2503. (region-p (org-region-active-p))
  2504. (custom org-agenda-custom-commands)
  2505. (selstring "")
  2506. restriction second-time
  2507. c entry key type match prefixes rmheader header-end custom1 desc
  2508. line lines left right n n1)
  2509. (save-window-excursion
  2510. (delete-other-windows)
  2511. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2512. (erase-buffer)
  2513. (insert (eval-when-compile
  2514. (let ((header
  2515. "Press key for an agenda command: < Buffer, subtree/region restriction
  2516. -------------------------------- > Remove restriction
  2517. a Agenda for current week or day e Export agenda views
  2518. t List of all TODO entries T Entries with special TODO kwd
  2519. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2520. s Search for keywords S Like s, but only TODO entries
  2521. L Timeline for current buffer # List stuck projects (!=configure)
  2522. / Multi-occur C Configure custom agenda commands
  2523. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2524. ")
  2525. (start 0))
  2526. (while (string-match
  2527. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2528. header start)
  2529. (setq start (match-end 0))
  2530. (add-text-properties (match-beginning 2) (match-end 2)
  2531. '(face bold) header))
  2532. header)))
  2533. (setq header-end (point-marker))
  2534. (while t
  2535. (setq custom1 custom)
  2536. (when (eq rmheader t)
  2537. (org-goto-line 1)
  2538. (re-search-forward ":" nil t)
  2539. (delete-region (match-end 0) (point-at-eol))
  2540. (forward-char 1)
  2541. (looking-at "-+")
  2542. (delete-region (match-end 0) (point-at-eol))
  2543. (move-marker header-end (match-end 0)))
  2544. (goto-char header-end)
  2545. (delete-region (point) (point-max))
  2546. ;; Produce all the lines that describe custom commands and prefixes
  2547. (setq lines nil)
  2548. (while (setq entry (pop custom1))
  2549. (setq key (car entry) desc (nth 1 entry)
  2550. type (nth 2 entry)
  2551. match (nth 3 entry))
  2552. (if (> (length key) 1)
  2553. (add-to-list 'prefixes (string-to-char key))
  2554. (setq line
  2555. (format
  2556. "%-4s%-14s"
  2557. (org-add-props (copy-sequence key)
  2558. '(face bold))
  2559. (cond
  2560. ((string-match "\\S-" desc) desc)
  2561. ((eq type 'agenda) "Agenda for current week or day")
  2562. ((eq type 'alltodo) "List of all TODO entries")
  2563. ((eq type 'search) "Word search")
  2564. ((eq type 'stuck) "List of stuck projects")
  2565. ((eq type 'todo) "TODO keyword")
  2566. ((eq type 'tags) "Tags query")
  2567. ((eq type 'tags-todo) "Tags (TODO)")
  2568. ((eq type 'tags-tree) "Tags tree")
  2569. ((eq type 'todo-tree) "TODO kwd tree")
  2570. ((eq type 'occur-tree) "Occur tree")
  2571. ((functionp type) (if (symbolp type)
  2572. (symbol-name type)
  2573. "Lambda expression"))
  2574. (t "???"))))
  2575. (if org-agenda-menu-show-matcher
  2576. (setq line
  2577. (concat line ": "
  2578. (cond
  2579. ((stringp match)
  2580. (setq match (copy-sequence match))
  2581. (org-add-props match nil 'face 'org-warning))
  2582. ((listp type)
  2583. (format "set of %d commands" (length type))))))
  2584. (if (org-string-nw-p match)
  2585. (add-text-properties
  2586. 0 (length line) (list 'help-echo
  2587. (concat "Matcher: " match)) line)))
  2588. (push line lines)))
  2589. (setq lines (nreverse lines))
  2590. (when prefixes
  2591. (mapc (lambda (x)
  2592. (push
  2593. (format "%s %s"
  2594. (org-add-props (char-to-string x)
  2595. nil 'face 'bold)
  2596. (or (cdr (assoc (concat selstring
  2597. (char-to-string x))
  2598. prefix-descriptions))
  2599. "Prefix key"))
  2600. lines))
  2601. prefixes))
  2602. ;; Check if we should display in two columns
  2603. (if org-agenda-menu-two-columns
  2604. (progn
  2605. (setq n (length lines)
  2606. n1 (+ (/ n 2) (mod n 2))
  2607. right (nthcdr n1 lines)
  2608. left (copy-sequence lines))
  2609. (setcdr (nthcdr (1- n1) left) nil))
  2610. (setq left lines right nil))
  2611. (while left
  2612. (insert "\n" (pop left))
  2613. (when right
  2614. (if (< (current-column) 40)
  2615. (move-to-column 40 t)
  2616. (insert " "))
  2617. (insert (pop right))))
  2618. ;; Make the window the right size
  2619. (goto-char (point-min))
  2620. (if second-time
  2621. (if (not (pos-visible-in-window-p (point-max)))
  2622. (org-fit-window-to-buffer))
  2623. (setq second-time t)
  2624. (org-fit-window-to-buffer))
  2625. ;; Ask for selection
  2626. (message "Press key for agenda command%s:"
  2627. (if (or restrict-ok org-agenda-overriding-restriction)
  2628. (if org-agenda-overriding-restriction
  2629. " (restriction lock active)"
  2630. (if restriction
  2631. (format " (restricted to %s)" restriction)
  2632. " (unrestricted)"))
  2633. ""))
  2634. (setq c (read-char-exclusive))
  2635. (message "")
  2636. (cond
  2637. ((assoc (char-to-string c) custom)
  2638. (setq selstring (concat selstring (char-to-string c)))
  2639. (throw 'exit (cons selstring restriction)))
  2640. ((memq c prefixes)
  2641. (setq selstring (concat selstring (char-to-string c))
  2642. prefixes nil
  2643. rmheader (or rmheader t)
  2644. custom (delq nil (mapcar
  2645. (lambda (x)
  2646. (if (or (= (length (car x)) 1)
  2647. (/= (string-to-char (car x)) c))
  2648. nil
  2649. (cons (substring (car x) 1) (cdr x))))
  2650. custom))))
  2651. ((eq c ?*)
  2652. (call-interactively 'org-toggle-sticky-agenda)
  2653. (sit-for 2))
  2654. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2655. (message "Restriction is only possible in Org-mode buffers")
  2656. (ding) (sit-for 1))
  2657. ((eq c ?1)
  2658. (org-agenda-remove-restriction-lock 'noupdate)
  2659. (setq restriction 'buffer))
  2660. ((eq c ?0)
  2661. (org-agenda-remove-restriction-lock 'noupdate)
  2662. (setq restriction (if region-p 'region 'subtree)))
  2663. ((eq c ?<)
  2664. (org-agenda-remove-restriction-lock 'noupdate)
  2665. (setq restriction
  2666. (cond
  2667. ((eq restriction 'buffer)
  2668. (if region-p 'region 'subtree))
  2669. ((memq restriction '(subtree region))
  2670. nil)
  2671. (t 'buffer))))
  2672. ((eq c ?>)
  2673. (org-agenda-remove-restriction-lock 'noupdate)
  2674. (setq restriction nil))
  2675. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2676. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2677. ((and (> (length selstring) 0) (eq c ?\d))
  2678. (delete-window)
  2679. (org-agenda-get-restriction-and-command prefix-descriptions))
  2680. ((equal c ?q) (error "Abort"))
  2681. (t (error "Invalid key %c" c))))))))
  2682. (defun org-agenda-fit-window-to-buffer ()
  2683. "Fit the window to the buffer size."
  2684. (and (memq org-agenda-window-setup '(reorganize-frame))
  2685. (fboundp 'fit-window-to-buffer)
  2686. (org-fit-window-to-buffer
  2687. nil
  2688. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2689. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2690. (defvar org-cmd nil)
  2691. (defvar org-agenda-overriding-cmd nil)
  2692. (defvar org-agenda-overriding-arguments nil)
  2693. (defvar org-agenda-overriding-cmd-arguments nil)
  2694. (defun org-agenda-run-series (name series)
  2695. (org-let (nth 1 series) '(org-agenda-prepare name))
  2696. ;; We need to reset agenda markers here, because when constructing a
  2697. ;; block agenda, the individual blocks do not do that.
  2698. (org-agenda-reset-markers)
  2699. (let* ((org-agenda-multi t)
  2700. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2701. (cmds (car series))
  2702. (gprops (nth 1 series))
  2703. match ;; The byte compiler incorrectly complains about this. Keep it!
  2704. org-cmd type lprops)
  2705. (while (setq org-cmd (pop cmds))
  2706. (setq type (car org-cmd)
  2707. match (eval (nth 1 org-cmd))
  2708. lprops (nth 2 org-cmd))
  2709. (let ((org-agenda-overriding-arguments
  2710. (if (eq org-agenda-overriding-cmd org-cmd)
  2711. (or org-agenda-overriding-arguments
  2712. org-agenda-overriding-cmd-arguments))))
  2713. (cond
  2714. ((eq type 'agenda)
  2715. (org-let2 gprops lprops
  2716. '(call-interactively 'org-agenda-list)))
  2717. ((eq type 'alltodo)
  2718. (org-let2 gprops lprops
  2719. '(call-interactively 'org-todo-list)))
  2720. ((eq type 'search)
  2721. (org-let2 gprops lprops
  2722. '(org-search-view current-prefix-arg match nil)))
  2723. ((eq type 'stuck)
  2724. (org-let2 gprops lprops
  2725. '(call-interactively 'org-agenda-list-stuck-projects)))
  2726. ((eq type 'tags)
  2727. (org-let2 gprops lprops
  2728. '(org-tags-view current-prefix-arg match)))
  2729. ((eq type 'tags-todo)
  2730. (org-let2 gprops lprops
  2731. '(org-tags-view '(4) match)))
  2732. ((eq type 'todo)
  2733. (org-let2 gprops lprops
  2734. '(org-todo-list match)))
  2735. ((fboundp type)
  2736. (org-let2 gprops lprops
  2737. '(funcall type match)))
  2738. (t (error "Invalid type in command series")))))
  2739. (widen)
  2740. (let ((inhibit-read-only t))
  2741. (add-text-properties (point-min) (point-max)
  2742. `(org-series t org-series-redo-cmd ,redo)))
  2743. (setq org-agenda-redo-command redo)
  2744. (goto-char (point-min)))
  2745. (org-agenda-fit-window-to-buffer)
  2746. (org-let (nth 1 series) '(org-agenda-finalize)))
  2747. ;;;###autoload
  2748. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2749. "Run an agenda command in batch mode and send the result to STDOUT.
  2750. If CMD-KEY is a string of length 1, it is used as a key in
  2751. `org-agenda-custom-commands' and triggers this command. If it is a
  2752. longer string it is used as a tags/todo match string.
  2753. Parameters are alternating variable names and values that will be bound
  2754. before running the agenda command."
  2755. (org-eval-in-environment (org-make-parameter-alist parameters)
  2756. (if (> (length cmd-key) 2)
  2757. (org-tags-view nil cmd-key)
  2758. (org-agenda nil cmd-key)))
  2759. (set-buffer org-agenda-buffer-name)
  2760. (princ (buffer-string)))
  2761. (defvar org-agenda-info nil)
  2762. ;;;###autoload
  2763. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2764. "Run an agenda command in batch mode and send the result to STDOUT.
  2765. If CMD-KEY is a string of length 1, it is used as a key in
  2766. `org-agenda-custom-commands' and triggers this command. If it is a
  2767. longer string it is used as a tags/todo match string.
  2768. Parameters are alternating variable names and values that will be bound
  2769. before running the agenda command.
  2770. The output gives a line for each selected agenda item. Each
  2771. item is a list of comma-separated values, like this:
  2772. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2773. category The category of the item
  2774. head The headline, without TODO kwd, TAGS and PRIORITY
  2775. type The type of the agenda entry, can be
  2776. todo selected in TODO match
  2777. tagsmatch selected in tags match
  2778. diary imported from diary
  2779. deadline a deadline on given date
  2780. scheduled scheduled on given date
  2781. timestamp entry has timestamp on given date
  2782. closed entry was closed on given date
  2783. upcoming-deadline warning about deadline
  2784. past-scheduled forwarded scheduled item
  2785. block entry has date block including g. date
  2786. todo The todo keyword, if any
  2787. tags All tags including inherited ones, separated by colons
  2788. date The relevant date, like 2007-2-14
  2789. time The time, like 15:00-16:50
  2790. extra Sting with extra planning info
  2791. priority-l The priority letter if any was given
  2792. priority-n The computed numerical priority
  2793. agenda-day The day in the agenda where this is listed"
  2794. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2795. (org-make-parameter-alist parameters))
  2796. (if (> (length cmd-key) 2)
  2797. (org-tags-view nil cmd-key)
  2798. (org-agenda nil cmd-key)))
  2799. (set-buffer org-agenda-buffer-name)
  2800. (let* ((lines (org-split-string (buffer-string) "\n"))
  2801. line)
  2802. (while (setq line (pop lines))
  2803. (catch 'next
  2804. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2805. (setq org-agenda-info
  2806. (org-fix-agenda-info (text-properties-at 0 line)))
  2807. (princ
  2808. (mapconcat 'org-agenda-export-csv-mapper
  2809. '(org-category txt type todo tags date time extra
  2810. priority-letter priority agenda-day)
  2811. ","))
  2812. (princ "\n")))))
  2813. (defun org-fix-agenda-info (props)
  2814. "Make sure all properties on an agenda item have a canonical form.
  2815. This ensures the export commands can easily use it."
  2816. (let (tmp re)
  2817. (when (setq tmp (plist-get props 'tags))
  2818. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2819. (when (setq tmp (plist-get props 'date))
  2820. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2821. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2822. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2823. (setq tmp (calendar-date-string tmp)))
  2824. (setq props (plist-put props 'date tmp)))
  2825. (when (setq tmp (plist-get props 'day))
  2826. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2827. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2828. (setq tmp (calendar-date-string tmp)))
  2829. (setq props (plist-put props 'day tmp))
  2830. (setq props (plist-put props 'agenda-day tmp)))
  2831. (when (setq tmp (plist-get props 'txt))
  2832. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2833. (plist-put props 'priority-letter (match-string 1 tmp))
  2834. (setq tmp (replace-match "" t t tmp)))
  2835. (when (and (setq re (plist-get props 'org-todo-regexp))
  2836. (setq re (concat "\\`\\.*" re " ?"))
  2837. (string-match re tmp))
  2838. (plist-put props 'todo (match-string 1 tmp))
  2839. (setq tmp (replace-match "" t t tmp)))
  2840. (plist-put props 'txt tmp)))
  2841. props)
  2842. (defun org-agenda-export-csv-mapper (prop)
  2843. (let ((res (plist-get org-agenda-info prop)))
  2844. (setq res
  2845. (cond
  2846. ((not res) "")
  2847. ((stringp res) res)
  2848. (t (prin1-to-string res))))
  2849. (while (string-match "," res)
  2850. (setq res (replace-match ";" t t res)))
  2851. (org-trim res)))
  2852. ;;;###autoload
  2853. (defun org-store-agenda-views (&rest parameters)
  2854. (interactive)
  2855. (eval (list 'org-batch-store-agenda-views)))
  2856. ;;;###autoload
  2857. (defmacro org-batch-store-agenda-views (&rest parameters)
  2858. "Run all custom agenda commands that have a file argument."
  2859. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2860. (pop-up-frames nil)
  2861. (dir default-directory)
  2862. (pars (org-make-parameter-alist parameters))
  2863. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2864. (save-window-excursion
  2865. (while cmds
  2866. (setq cmd (pop cmds)
  2867. thiscmdkey (car cmd)
  2868. thiscmdcmd (cdr cmd)
  2869. match (nth 2 thiscmdcmd)
  2870. bufname (if org-agenda-sticky
  2871. (or (and (stringp match)
  2872. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2873. (format "*Org Agenda(%s)*" thiscmdkey))
  2874. org-agenda-buffer-name)
  2875. cmd-or-set (nth 2 cmd)
  2876. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2877. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2878. (if (stringp files) (setq files (list files)))
  2879. (when files
  2880. (org-eval-in-environment (append org-agenda-exporter-settings
  2881. opts pars)
  2882. (org-agenda nil thiscmdkey))
  2883. (set-buffer bufname)
  2884. (while files
  2885. (org-eval-in-environment (append org-agenda-exporter-settings
  2886. opts pars)
  2887. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2888. (and (get-buffer bufname)
  2889. (kill-buffer bufname)))))))
  2890. (defvar org-agenda-current-span nil
  2891. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2892. (defun org-agenda-mark-header-line (pos)
  2893. "Mark the line at POS as an agenda structure header."
  2894. (save-excursion
  2895. (goto-char pos)
  2896. (put-text-property (point-at-bol) (point-at-eol)
  2897. 'org-agenda-structural-header t)
  2898. (when org-agenda-title-append
  2899. (put-text-property (point-at-bol) (point-at-eol)
  2900. 'org-agenda-title-append org-agenda-title-append))))
  2901. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2902. (defvar org-agenda-write-buffer-name "Agenda View")
  2903. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2904. "Write the current buffer (an agenda view) as a file.
  2905. Depending on the extension of the file name, plain text (.txt),
  2906. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2907. If the extension is .ics, run icalendar export over all files used
  2908. to construct the agenda and limit the export to entries listed in the
  2909. agenda now.
  2910. If the extension is .org, collect all subtrees corresponding to the
  2911. agenda entries and add them in an .org file.
  2912. With prefix argument OPEN, open the new file immediately.
  2913. If NOSETTINGS is given, do not scope the settings of
  2914. `org-agenda-exporter-settings' into the export commands. This is used when
  2915. the settings have already been scoped and we do not wish to overrule other,
  2916. higher priority settings.
  2917. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2918. (interactive "FWrite agenda to file: \nP")
  2919. (if (or (not (file-writable-p file))
  2920. (and (file-exists-p file)
  2921. (if (called-interactively-p 'any)
  2922. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  2923. (error "Cannot write agenda to file %s" file))
  2924. (org-let (if nosettings nil org-agenda-exporter-settings)
  2925. '(save-excursion
  2926. (save-window-excursion
  2927. (org-agenda-mark-filtered-text)
  2928. (let ((bs (copy-sequence (buffer-string))) beg content)
  2929. (org-agenda-unmark-filtered-text)
  2930. (with-temp-buffer
  2931. (rename-buffer org-agenda-write-buffer-name t)
  2932. (set-buffer-modified-p nil)
  2933. (insert bs)
  2934. (org-agenda-remove-marked-text 'org-filtered)
  2935. (while (setq beg (text-property-any (point-min) (point-max)
  2936. 'org-filtered t))
  2937. (delete-region
  2938. beg (or (next-single-property-change beg 'org-filtered)
  2939. (point-max))))
  2940. (run-hooks 'org-agenda-before-write-hook)
  2941. (cond
  2942. ((org-bound-and-true-p org-mobile-creating-agendas)
  2943. (org-mobile-write-agenda-for-mobile file))
  2944. ((string-match "\\.org\\'" file)
  2945. (let (content p m message-log-max)
  2946. (goto-char (point-min))
  2947. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  2948. (goto-char p)
  2949. (setq m (get-text-property (point) 'org-hd-marker))
  2950. (when m
  2951. (push (save-excursion
  2952. (set-buffer (marker-buffer m))
  2953. (goto-char m)
  2954. (org-copy-subtree 1 nil t t)
  2955. org-subtree-clip)
  2956. content)))
  2957. (find-file file)
  2958. (erase-buffer)
  2959. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  2960. (write-file file)
  2961. (kill-buffer (current-buffer))
  2962. (message "Org file written to %s" file)))
  2963. ((string-match "\\.html?\\'" file)
  2964. (require 'htmlize)
  2965. (set-buffer (htmlize-buffer (current-buffer)))
  2966. (when org-agenda-export-html-style
  2967. ;; replace <style> section with org-agenda-export-html-style
  2968. (goto-char (point-min))
  2969. (kill-region (- (search-forward "<style") 6)
  2970. (search-forward "</style>"))
  2971. (insert org-agenda-export-html-style))
  2972. (write-file file)
  2973. (kill-buffer (current-buffer))
  2974. (message "HTML written to %s" file))
  2975. ((string-match "\\.ps\\'" file)
  2976. (require 'ps-print)
  2977. (ps-print-buffer-with-faces file)
  2978. (message "Postscript written to %s" file))
  2979. ((string-match "\\.pdf\\'" file)
  2980. (require 'ps-print)
  2981. (ps-print-buffer-with-faces
  2982. (concat (file-name-sans-extension file) ".ps"))
  2983. (call-process "ps2pdf" nil nil nil
  2984. (expand-file-name
  2985. (concat (file-name-sans-extension file) ".ps"))
  2986. (expand-file-name file))
  2987. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2988. (message "PDF written to %s" file))
  2989. ((string-match "\\.ics\\'" file)
  2990. (require 'ox-icalendar)
  2991. (org-icalendar-export-current-agenda (expand-file-name file)))
  2992. (t
  2993. (let ((bs (buffer-string)))
  2994. (find-file file)
  2995. (erase-buffer)
  2996. (insert bs)
  2997. (save-buffer 0)
  2998. (kill-buffer (current-buffer))
  2999. (message "Plain text written to %s" file))))))))
  3000. (set-buffer (or agenda-bufname
  3001. (and (org-called-interactively-p 'any) (buffer-name))
  3002. org-agenda-buffer-name)))
  3003. (when open (org-open-file file)))
  3004. (defvar org-agenda-tag-filter-overlays nil)
  3005. (defvar org-agenda-cat-filter-overlays nil)
  3006. (defun org-agenda-mark-filtered-text ()
  3007. "Mark all text hidden by filtering with a text property."
  3008. (let ((inhibit-read-only t))
  3009. (mapc
  3010. (lambda (o)
  3011. (when (equal (overlay-buffer o) (current-buffer))
  3012. (put-text-property
  3013. (overlay-start o) (overlay-end o)
  3014. 'org-filtered t)))
  3015. (append org-agenda-tag-filter-overlays
  3016. org-agenda-cat-filter-overlays))))
  3017. (defun org-agenda-unmark-filtered-text ()
  3018. "Remove the filtering text property."
  3019. (let ((inhibit-read-only t))
  3020. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3021. (defun org-agenda-remove-marked-text (property &optional value)
  3022. "Delete all text marked with VALUE of PROPERTY.
  3023. VALUE defaults to t."
  3024. (let (beg)
  3025. (setq value (or value t))
  3026. (while (setq beg (text-property-any (point-min) (point-max)
  3027. property value))
  3028. (delete-region
  3029. beg (or (next-single-property-change beg 'org-filtered)
  3030. (point-max))))))
  3031. (defun org-agenda-add-entry-text ()
  3032. "Add entry text to agenda lines.
  3033. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3034. entry text following headings shown in the agenda.
  3035. Drawers will be excluded, also the line with scheduling/deadline info."
  3036. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3037. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3038. (let (m txt)
  3039. (goto-char (point-min))
  3040. (while (not (eobp))
  3041. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3042. (beginning-of-line 2)
  3043. (setq txt (org-agenda-get-some-entry-text
  3044. m org-agenda-add-entry-text-maxlines " > "))
  3045. (end-of-line 1)
  3046. (if (string-match "\\S-" txt)
  3047. (insert "\n" txt)
  3048. (or (eobp) (forward-char 1))))))))
  3049. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3050. &rest keep)
  3051. "Extract entry text from MARKER, at most N-LINES lines.
  3052. This will ignore drawers etc, just get the text.
  3053. If INDENT is given, prefix every line with this string. If KEEP is
  3054. given, it is a list of symbols, defining stuff that should not be
  3055. removed from the entry content. Currently only `planning' is allowed here."
  3056. (let (txt drawer-re kwd-time-re ind)
  3057. (save-excursion
  3058. (with-current-buffer (marker-buffer marker)
  3059. (if (not (derived-mode-p 'org-mode))
  3060. (setq txt "")
  3061. (save-excursion
  3062. (save-restriction
  3063. (widen)
  3064. (goto-char marker)
  3065. (end-of-line 1)
  3066. (setq txt (buffer-substring
  3067. (min (1+ (point)) (point-max))
  3068. (progn (outline-next-heading) (point)))
  3069. drawer-re org-drawer-regexp
  3070. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3071. ".*\n?"))
  3072. (with-temp-buffer
  3073. (insert txt)
  3074. (when org-agenda-add-entry-text-descriptive-links
  3075. (goto-char (point-min))
  3076. (while (org-activate-bracket-links (point-max))
  3077. (add-text-properties (match-beginning 0) (match-end 0)
  3078. '(face org-link))))
  3079. (goto-char (point-min))
  3080. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3081. (set-text-properties (match-beginning 0) (match-end 0)
  3082. nil))
  3083. (goto-char (point-min))
  3084. (while (re-search-forward drawer-re nil t)
  3085. (delete-region
  3086. (match-beginning 0)
  3087. (progn (re-search-forward
  3088. "^[ \t]*:END:.*\n?" nil 'move)
  3089. (point))))
  3090. (unless (member 'planning keep)
  3091. (goto-char (point-min))
  3092. (while (re-search-forward kwd-time-re nil t)
  3093. (replace-match "")))
  3094. (goto-char (point-min))
  3095. (when org-agenda-entry-text-exclude-regexps
  3096. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3097. (while (setq re (pop re-list))
  3098. (goto-char (point-min))
  3099. (while (re-search-forward re nil t)
  3100. (replace-match "")))))
  3101. (goto-char (point-max))
  3102. (skip-chars-backward " \t\n")
  3103. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3104. ;; find and remove min common indentation
  3105. (goto-char (point-min))
  3106. (untabify (point-min) (point-max))
  3107. (setq ind (org-get-indentation))
  3108. (while (not (eobp))
  3109. (unless (looking-at "[ \t]*$")
  3110. (setq ind (min ind (org-get-indentation))))
  3111. (beginning-of-line 2))
  3112. (goto-char (point-min))
  3113. (while (not (eobp))
  3114. (unless (looking-at "[ \t]*$")
  3115. (move-to-column ind)
  3116. (delete-region (point-at-bol) (point)))
  3117. (beginning-of-line 2))
  3118. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3119. (goto-char (point-min))
  3120. (when indent
  3121. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3122. (replace-match indent t t)))
  3123. (goto-char (point-min))
  3124. (while (looking-at "[ \t]*\n") (replace-match ""))
  3125. (goto-char (point-max))
  3126. (when (> (org-current-line)
  3127. n-lines)
  3128. (org-goto-line (1+ n-lines))
  3129. (backward-char 1))
  3130. (setq txt (buffer-substring (point-min) (point)))))))))
  3131. txt))
  3132. (defun org-check-for-org-mode ()
  3133. "Make sure current buffer is in org-mode. Error if not."
  3134. (or (derived-mode-p 'org-mode)
  3135. (error "Cannot execute org-mode agenda command on buffer in %s"
  3136. major-mode)))
  3137. ;;; Agenda prepare and finalize
  3138. (defvar org-agenda-multi nil) ; dynamically scoped
  3139. (defvar org-agenda-pre-window-conf nil)
  3140. (defvar org-agenda-columns-active nil)
  3141. (defvar org-agenda-name nil)
  3142. (defvar org-agenda-tag-filter nil)
  3143. (defvar org-agenda-category-filter nil)
  3144. (defvar org-agenda-top-category-filter nil)
  3145. (defvar org-agenda-tag-filter-while-redo nil)
  3146. (defvar org-agenda-tag-filter-preset nil
  3147. "A preset of the tags filter used for secondary agenda filtering.
  3148. This must be a list of strings, each string must be a single tag preceded
  3149. by \"+\" or \"-\".
  3150. This variable should not be set directly, but agenda custom commands can
  3151. bind it in the options section. The preset filter is a global property of
  3152. the entire agenda view. In a block agenda, it will not work reliably to
  3153. define a filter for one of the individual blocks. You need to set it in
  3154. the global options and expect it to be applied to the entire view.")
  3155. (defvar org-agenda-category-filter-preset nil
  3156. "A preset of the category filter used for secondary agenda filtering.
  3157. This must be a list of strings, each string must be a single category
  3158. preceded by \"+\" or \"-\".
  3159. This variable should not be set directly, but agenda custom commands can
  3160. bind it in the options section. The preset filter is a global property of
  3161. the entire agenda view. In a block agenda, it will not work reliably to
  3162. define a filter for one of the individual blocks. You need to set it in
  3163. the global options and expect it to be applied to the entire view.")
  3164. (defun org-agenda-use-sticky-p ()
  3165. "Return non-nil if an agenda buffer named
  3166. `org-agenda-buffer-name' exists and should be shown instead of
  3167. generating a new one."
  3168. (and
  3169. ;; turned off by user
  3170. org-agenda-sticky
  3171. ;; For multi-agenda buffer already exists
  3172. (not org-agenda-multi)
  3173. ;; buffer found
  3174. (get-buffer org-agenda-buffer-name)
  3175. ;; C-u parameter is same as last call
  3176. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3177. (and
  3178. (equal current-prefix-arg
  3179. org-agenda-last-prefix-arg)
  3180. ;; In case user turned stickiness on, while having existing
  3181. ;; Agenda buffer active, don't reuse that buffer, because it
  3182. ;; does not have org variables local
  3183. org-agenda-this-buffer-is-sticky))))
  3184. (defun org-agenda-prepare-window (abuf)
  3185. "Setup agenda buffer in the window."
  3186. (let* ((awin (get-buffer-window abuf))
  3187. wconf)
  3188. (cond
  3189. ((equal (current-buffer) abuf) nil)
  3190. (awin (select-window awin))
  3191. ((not (setq wconf (current-window-configuration))))
  3192. ((equal org-agenda-window-setup 'current-window)
  3193. (org-pop-to-buffer-same-window abuf))
  3194. ((equal org-agenda-window-setup 'other-window)
  3195. (org-switch-to-buffer-other-window abuf))
  3196. ((equal org-agenda-window-setup 'other-frame)
  3197. (switch-to-buffer-other-frame abuf))
  3198. ((equal org-agenda-window-setup 'reorganize-frame)
  3199. (delete-other-windows)
  3200. (org-switch-to-buffer-other-window abuf)))
  3201. ;; additional test in case agenda is invoked from within agenda
  3202. ;; buffer via elisp link
  3203. (unless (equal (current-buffer) abuf)
  3204. (org-pop-to-buffer-same-window abuf))
  3205. (setq org-agenda-pre-window-conf
  3206. (or org-agenda-pre-window-conf wconf))))
  3207. (defun org-agenda-prepare (&optional name)
  3208. (if (org-agenda-use-sticky-p)
  3209. (progn
  3210. ;; Popup existing buffer
  3211. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3212. (message "Sticky Agenda buffer, use `r' to refresh")
  3213. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3214. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3215. (setq org-todo-keywords-for-agenda nil)
  3216. (setq org-drawers-for-agenda nil)
  3217. (unless org-agenda-persistent-filter
  3218. (setq org-agenda-tag-filter nil
  3219. org-agenda-category-filter nil))
  3220. (put 'org-agenda-tag-filter :preset-filter
  3221. org-agenda-tag-filter-preset)
  3222. (put 'org-agenda-category-filter :preset-filter
  3223. org-agenda-category-filter-preset)
  3224. (if org-agenda-multi
  3225. (progn
  3226. (setq buffer-read-only nil)
  3227. (goto-char (point-max))
  3228. (unless (or (bobp) org-agenda-compact-blocks
  3229. (not org-agenda-block-separator))
  3230. (insert "\n"
  3231. (if (stringp org-agenda-block-separator)
  3232. org-agenda-block-separator
  3233. (make-string (window-width) org-agenda-block-separator))
  3234. "\n"))
  3235. (narrow-to-region (point) (point-max)))
  3236. (setq org-done-keywords-for-agenda nil)
  3237. ;; Setting any org variables that are in org-agenda-local-vars
  3238. ;; list need to be done after the prepare call
  3239. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3240. (setq buffer-read-only nil)
  3241. (org-agenda-reset-markers)
  3242. (let ((inhibit-read-only t)) (erase-buffer))
  3243. (org-agenda-mode)
  3244. (setq org-agenda-buffer (current-buffer))
  3245. (setq org-agenda-contributing-files nil)
  3246. (setq org-agenda-columns-active nil)
  3247. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3248. (setq org-todo-keywords-for-agenda
  3249. (org-uniquify org-todo-keywords-for-agenda))
  3250. (setq org-done-keywords-for-agenda
  3251. (org-uniquify org-done-keywords-for-agenda))
  3252. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3253. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3254. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3255. (and name (not org-agenda-name)
  3256. (org-set-local 'org-agenda-name name)))
  3257. (setq buffer-read-only nil)))
  3258. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3259. (defun org-agenda-finalize ()
  3260. "Finishing touch for the agenda buffer, called just before displaying it."
  3261. (unless org-agenda-multi
  3262. (save-excursion
  3263. (let ((inhibit-read-only t))
  3264. (goto-char (point-min))
  3265. (save-excursion
  3266. (while (org-activate-bracket-links (point-max))
  3267. (add-text-properties (match-beginning 0) (match-end 0)
  3268. '(face org-link))))
  3269. (save-excursion
  3270. (while (org-activate-plain-links (point-max))
  3271. (add-text-properties (match-beginning 0) (match-end 0)
  3272. '(face org-link))))
  3273. (unless (eq org-agenda-remove-tags t)
  3274. (org-agenda-align-tags))
  3275. (unless org-agenda-with-colors
  3276. (remove-text-properties (point-min) (point-max) '(face nil)))
  3277. (if (and (boundp 'org-agenda-overriding-columns-format)
  3278. org-agenda-overriding-columns-format)
  3279. (org-set-local 'org-agenda-overriding-columns-format
  3280. org-agenda-overriding-columns-format))
  3281. (if (and (boundp 'org-agenda-view-columns-initially)
  3282. org-agenda-view-columns-initially)
  3283. (org-agenda-columns))
  3284. (when org-agenda-fontify-priorities
  3285. (org-agenda-fontify-priorities))
  3286. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3287. (org-agenda-dim-blocked-tasks))
  3288. ;; We need to widen when `org-agenda-finalize' is called from
  3289. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3290. (when org-clock-current-task
  3291. (save-restriction
  3292. (widen)
  3293. (org-agenda-mark-clocking-task)))
  3294. (when org-agenda-entry-text-mode
  3295. (org-agenda-entry-text-hide)
  3296. (org-agenda-entry-text-show))
  3297. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3298. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3299. (org-habit-insert-consistency-graphs))
  3300. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3301. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3302. (and (listp org-agenda-show-inherited-tags)
  3303. (memq org-agenda-type org-agenda-show-inherited-tags))
  3304. (and (eq org-agenda-show-inherited-tags t)
  3305. (or (eq org-agenda-use-tag-inheritance t)
  3306. (and (listp org-agenda-use-tag-inheritance)
  3307. (not (memq org-agenda-type
  3308. org-agenda-use-tag-inheritance))))))
  3309. (let (mrk)
  3310. (save-excursion
  3311. (goto-char (point-min))
  3312. (while (equal (forward-line) 0)
  3313. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3314. (get-text-property (point) 'org-hd-marker)))
  3315. (put-text-property (point-at-bol) (point-at-eol)
  3316. 'tags (org-with-point-at mrk
  3317. (delete-dups
  3318. (mapcar 'downcase (org-get-tags-at))))))))))
  3319. (run-hooks 'org-agenda-finalize-hook)
  3320. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3321. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3322. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3323. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3324. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3325. (defun org-agenda-mark-clocking-task ()
  3326. "Mark the current clock entry in the agenda if it is present."
  3327. (org-agenda-unmark-clocking-task)
  3328. (when (marker-buffer org-clock-hd-marker)
  3329. (save-excursion
  3330. (goto-char (point-min))
  3331. (let (s ov)
  3332. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3333. (goto-char s)
  3334. (when (equal (org-get-at-bol 'org-hd-marker)
  3335. org-clock-hd-marker)
  3336. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3337. (overlay-put ov 'type 'org-agenda-clocking)
  3338. (overlay-put ov 'face 'org-agenda-clocking)
  3339. (overlay-put ov 'help-echo
  3340. "The clock is running in this item")))))))
  3341. (defun org-agenda-unmark-clocking-task ()
  3342. "Unmark the current clocking task."
  3343. (mapc (lambda (o)
  3344. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3345. (delete-overlay o)))
  3346. (overlays-in (point-min) (point-max))))
  3347. (defun org-agenda-fontify-priorities ()
  3348. "Make highest priority lines bold, and lowest italic."
  3349. (interactive)
  3350. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3351. (delete-overlay o)))
  3352. (overlays-in (point-min) (point-max)))
  3353. (save-excursion
  3354. (let (b e p ov h l)
  3355. (goto-char (point-min))
  3356. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3357. (setq h (or (get-char-property (point) 'org-highest-priority)
  3358. org-highest-priority)
  3359. l (or (get-char-property (point) 'org-lowest-priority)
  3360. org-lowest-priority)
  3361. p (string-to-char (match-string 1))
  3362. b (match-beginning 0)
  3363. e (if (eq org-agenda-fontify-priorities 'cookies)
  3364. (match-end 0)
  3365. (point-at-eol))
  3366. ov (make-overlay b e))
  3367. (overlay-put
  3368. ov 'face
  3369. (cons (cond ((org-face-from-face-or-color
  3370. 'priority nil
  3371. (cdr (assoc p org-priority-faces))))
  3372. ((and (listp org-agenda-fontify-priorities)
  3373. (org-face-from-face-or-color
  3374. 'priority nil
  3375. (cdr (assoc p org-agenda-fontify-priorities)))))
  3376. ((equal p l) 'italic)
  3377. ((equal p h) 'bold))
  3378. 'org-priority))
  3379. (overlay-put ov 'org-type 'org-priority)))))
  3380. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3381. (interactive "P")
  3382. "Dim currently blocked TODO's in the agenda display."
  3383. (message "Dim or hide blocked tasks...")
  3384. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3385. (delete-overlay o)))
  3386. (overlays-in (point-min) (point-max)))
  3387. (save-excursion
  3388. (let ((inhibit-read-only t)
  3389. (org-depend-tag-blocked nil)
  3390. (invis (or (not (null invisible))
  3391. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3392. org-blocked-by-checkboxes
  3393. invis1 b e p ov h l)
  3394. (goto-char (point-min))
  3395. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3396. (and pos (goto-char (1+ pos))))
  3397. (setq org-blocked-by-checkboxes nil invis1 invis)
  3398. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3399. (when (and marker
  3400. (with-current-buffer (marker-buffer marker)
  3401. (save-excursion (goto-char marker)
  3402. (org-entry-blocked-p))))
  3403. (if org-blocked-by-checkboxes (setq invis1 nil))
  3404. (setq b (if invis1
  3405. (max (point-min) (1- (point-at-bol)))
  3406. (point-at-bol))
  3407. e (point-at-eol)
  3408. ov (make-overlay b e))
  3409. (if invis1
  3410. (overlay-put ov 'invisible t)
  3411. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3412. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3413. (message "Dim or hide blocked tasks...done"))
  3414. (defvar org-agenda-skip-function nil
  3415. "Function to be called at each match during agenda construction.
  3416. If this function returns nil, the current match should not be skipped.
  3417. Otherwise, the function must return a position from where the search
  3418. should be continued.
  3419. This may also be a Lisp form, it will be evaluated.
  3420. Never set this variable using `setq' or so, because then it will apply
  3421. to all future agenda commands. If you do want a global skipping condition,
  3422. use the option `org-agenda-skip-function-global' instead.
  3423. The correct usage for `org-agenda-skip-function' is to bind it with
  3424. `let' to scope it dynamically into the agenda-constructing command.
  3425. A good way to set it is through options in `org-agenda-custom-commands'.")
  3426. (defun org-agenda-skip ()
  3427. "Throw to `:skip' in places that should be skipped.
  3428. Also moves point to the end of the skipped region, so that search can
  3429. continue from there."
  3430. (let ((p (point-at-bol)) to)
  3431. (when (or
  3432. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3433. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3434. (get-text-property p :org-archived)
  3435. (org-end-of-subtree t))
  3436. (and org-agenda-skip-comment-trees
  3437. (get-text-property p :org-comment)
  3438. (org-end-of-subtree t))
  3439. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3440. (org-agenda-skip-eval org-agenda-skip-function)))
  3441. (goto-char to))
  3442. (org-in-src-block-p t))
  3443. (throw :skip t))))
  3444. (defun org-agenda-skip-eval (form)
  3445. "If FORM is a function or a list, call (or eval) is and return result.
  3446. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3447. and match data are returned to the previous state no matter what these
  3448. functions do."
  3449. (let (fp)
  3450. (and form
  3451. (or (setq fp (functionp form))
  3452. (consp form))
  3453. (save-excursion
  3454. (save-match-data
  3455. (if fp
  3456. (funcall form)
  3457. (eval form)))))))
  3458. (defvar org-agenda-markers nil
  3459. "List of all currently active markers created by `org-agenda'.")
  3460. (defvar org-agenda-last-marker-time (org-float-time)
  3461. "Creation time of the last agenda marker.")
  3462. (defun org-agenda-new-marker (&optional pos)
  3463. "Return a new agenda marker.
  3464. Org-mode keeps a list of these markers and resets them when they are
  3465. no longer in use."
  3466. (let ((m (copy-marker (or pos (point)))))
  3467. (setq org-agenda-last-marker-time (org-float-time))
  3468. (if org-agenda-buffer
  3469. (with-current-buffer org-agenda-buffer
  3470. (push m org-agenda-markers))
  3471. (push m org-agenda-markers))
  3472. m))
  3473. (defun org-agenda-reset-markers ()
  3474. "Reset markers created by `org-agenda'."
  3475. (while org-agenda-markers
  3476. (move-marker (pop org-agenda-markers) nil)))
  3477. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3478. "Save relative positions of markers in region.
  3479. This check for agenda markers in all agenda buffers currently active."
  3480. (dolist (buf (buffer-list))
  3481. (with-current-buffer buf
  3482. (when (eq major-mode 'org-agenda-mode)
  3483. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3484. org-agenda-markers)))))
  3485. ;;; Entry text mode
  3486. (defun org-agenda-entry-text-show-here ()
  3487. "Add some text from the entry as context to the current line."
  3488. (let (m txt o)
  3489. (setq m (org-get-at-bol 'org-hd-marker))
  3490. (unless (marker-buffer m)
  3491. (error "No marker points to an entry here"))
  3492. (setq txt (concat "\n" (org-no-properties
  3493. (org-agenda-get-some-entry-text
  3494. m org-agenda-entry-text-maxlines
  3495. org-agenda-entry-text-leaders))))
  3496. (when (string-match "\\S-" txt)
  3497. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3498. (overlay-put o 'evaporate t)
  3499. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3500. (overlay-put o 'after-string txt))))
  3501. (defun org-agenda-entry-text-show ()
  3502. "Add entry context for all agenda lines."
  3503. (interactive)
  3504. (save-excursion
  3505. (goto-char (point-max))
  3506. (beginning-of-line 1)
  3507. (while (not (bobp))
  3508. (when (org-get-at-bol 'org-hd-marker)
  3509. (org-agenda-entry-text-show-here))
  3510. (beginning-of-line 0))))
  3511. (defun org-agenda-entry-text-hide ()
  3512. "Remove any shown entry context."
  3513. (delq nil
  3514. (mapcar (lambda (o)
  3515. (if (eq (overlay-get o 'org-overlay-type)
  3516. 'agenda-entry-content)
  3517. (progn (delete-overlay o) t)))
  3518. (overlays-in (point-min) (point-max)))))
  3519. (defun org-agenda-get-day-face (date)
  3520. "Return the face DATE should be displayed with."
  3521. (or (and (functionp org-agenda-day-face-function)
  3522. (funcall org-agenda-day-face-function date))
  3523. (cond ((org-agenda-todayp date)
  3524. 'org-agenda-date-today)
  3525. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3526. 'org-agenda-date-weekend)
  3527. (t 'org-agenda-date))))
  3528. ;;; Agenda timeline
  3529. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3530. (defun org-timeline (&optional dotodo)
  3531. "Show a time-sorted view of the entries in the current org file.
  3532. Only entries with a time stamp of today or later will be listed. With
  3533. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3534. under the current date.
  3535. If the buffer contains an active region, only check the region for
  3536. dates."
  3537. (interactive "P")
  3538. (let* ((dopast t)
  3539. (org-agenda-show-log-scoped org-agenda-show-log)
  3540. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3541. (current-buffer))))
  3542. (date (calendar-current-date))
  3543. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3544. (end (if (org-region-active-p) (region-end) (point-max)))
  3545. (day-numbers (org-get-all-dates
  3546. beg end 'no-ranges
  3547. t org-agenda-show-log-scoped ; always include today
  3548. org-timeline-show-empty-dates))
  3549. (org-deadline-warning-days 0)
  3550. (org-agenda-only-exact-dates t)
  3551. (today (org-today))
  3552. (past t)
  3553. args
  3554. s e rtn d emptyp)
  3555. (setq org-agenda-redo-command
  3556. (list 'progn
  3557. (list 'org-switch-to-buffer-other-window (current-buffer))
  3558. (list 'org-timeline (list 'quote dotodo))))
  3559. (if (not dopast)
  3560. ;; Remove past dates from the list of dates.
  3561. (setq day-numbers (delq nil (mapcar (lambda(x)
  3562. (if (>= x today) x nil))
  3563. day-numbers))))
  3564. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3565. (org-compile-prefix-format 'timeline)
  3566. (org-set-sorting-strategy 'timeline)
  3567. (if org-agenda-show-log-scoped (push :closed args))
  3568. (push :timestamp args)
  3569. (push :deadline args)
  3570. (push :scheduled args)
  3571. (push :sexp args)
  3572. (if dotodo (push :todo args))
  3573. (insert "Timeline of file " entry "\n")
  3574. (add-text-properties (point-min) (point)
  3575. (list 'face 'org-agenda-structure))
  3576. (org-agenda-mark-header-line (point-min))
  3577. (while (setq d (pop day-numbers))
  3578. (if (and (listp d) (eq (car d) :omitted))
  3579. (progn
  3580. (setq s (point))
  3581. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3582. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3583. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3584. (if (and (>= d today)
  3585. dopast
  3586. past)
  3587. (progn
  3588. (setq past nil)
  3589. (insert (make-string 79 ?-) "\n")))
  3590. (setq date (calendar-gregorian-from-absolute d))
  3591. (setq s (point))
  3592. (setq rtn (and (not emptyp)
  3593. (apply 'org-agenda-get-day-entries entry
  3594. date args)))
  3595. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3596. (progn
  3597. (insert
  3598. (if (stringp org-agenda-format-date)
  3599. (format-time-string org-agenda-format-date
  3600. (org-time-from-absolute date))
  3601. (funcall org-agenda-format-date date))
  3602. "\n")
  3603. (put-text-property s (1- (point)) 'face
  3604. (org-agenda-get-day-face date))
  3605. (put-text-property s (1- (point)) 'org-date-line t)
  3606. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3607. (if (equal d today)
  3608. (put-text-property s (1- (point)) 'org-today t))
  3609. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3610. (put-text-property s (1- (point)) 'day d)))))
  3611. (goto-char (point-min))
  3612. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3613. (point-min)))
  3614. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3615. (org-agenda-finalize)
  3616. (setq buffer-read-only t)))
  3617. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3618. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3619. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3620. not every single day in the range. If FORCE-TODAY is non-nil, make
  3621. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3622. inactive time stamps (those in square brackets) are included.
  3623. When EMPTY is non-nil, also include days without any entries."
  3624. (let ((re (concat
  3625. (if pre-re pre-re "")
  3626. (if inactive org-ts-regexp-both org-ts-regexp)))
  3627. dates dates1 date day day1 day2 ts1 ts2 pos)
  3628. (if force-today
  3629. (setq dates (list (org-today))))
  3630. (save-excursion
  3631. (goto-char beg)
  3632. (while (re-search-forward re end t)
  3633. (setq day (time-to-days (org-time-string-to-time
  3634. (substring (match-string 1) 0 10)
  3635. (current-buffer) (match-beginning 0))))
  3636. (or (memq day dates) (push day dates)))
  3637. (unless no-ranges
  3638. (goto-char beg)
  3639. (while (re-search-forward org-tr-regexp end t)
  3640. (setq pos (match-beginning 0))
  3641. (setq ts1 (substring (match-string 1) 0 10)
  3642. ts2 (substring (match-string 2) 0 10)
  3643. day1 (time-to-days (org-time-string-to-time
  3644. ts1 (current-buffer) pos))
  3645. day2 (time-to-days (org-time-string-to-time
  3646. ts2 (current-buffer) pos)))
  3647. (while (< (setq day1 (1+ day1)) day2)
  3648. (or (memq day1 dates) (push day1 dates)))))
  3649. (setq dates (sort dates '<))
  3650. (when empty
  3651. (while (setq day (pop dates))
  3652. (setq day2 (car dates))
  3653. (push day dates1)
  3654. (when (and day2 empty)
  3655. (if (or (eq empty t)
  3656. (and (numberp empty) (<= (- day2 day) empty)))
  3657. (while (< (setq day (1+ day)) day2)
  3658. (push (list day) dates1))
  3659. (push (cons :omitted (- day2 day)) dates1))))
  3660. (setq dates (nreverse dates1)))
  3661. dates)))
  3662. ;;; Agenda Daily/Weekly
  3663. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3664. "Start day for the agenda view.
  3665. Custom commands can set this variable in the options section.
  3666. See the docstring of `org-read-date' on allowed values.")
  3667. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3668. (defvar org-arg-loc nil) ; local variable
  3669. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3670. "List of types searched for when creating the daily/weekly agenda.
  3671. This variable is a list of symbols that controls the types of
  3672. items that appear in the daily/weekly agenda. Allowed symbols in this
  3673. list are are
  3674. :timestamp List items containing a date stamp or date range matching
  3675. the selected date. This includes sexp entries in
  3676. angular brackets.
  3677. :sexp List entries resulting from plain diary-like sexps.
  3678. :deadline List deadline due on that date. When the date is today,
  3679. also list any deadlines past due, or due within
  3680. `org-deadline-warning-days'. `:deadline' must appear before
  3681. `:scheduled' if the setting of
  3682. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3683. any effect.
  3684. :scheduled List all items which are scheduled for the given date.
  3685. The diary for *today* also contains items which were
  3686. scheduled earlier and are not yet marked DONE.
  3687. By default, all four types are turned on.
  3688. Never set this variable globally using `setq', because then it
  3689. will apply to all future agenda commands. Instead, bind it with
  3690. `let' to scope it dynamically into the agenda-constructing
  3691. command. A good way to set it is through options in
  3692. `org-agenda-custom-commands'. For a more flexible (though
  3693. somewhat less efficient) way of determining what is included in
  3694. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3695. (defvar org-agenda-buffer-tmp-name nil)
  3696. ;;;###autoload
  3697. (defun org-agenda-list (&optional arg start-day span)
  3698. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3699. The view will be for the current day or week, but from the overview buffer
  3700. you will be able to go to other days/weeks.
  3701. With a numeric prefix argument in an interactive call, the agenda will
  3702. span ARG days. Lisp programs should instead specify SPAN to change
  3703. the number of days. SPAN defaults to `org-agenda-span'.
  3704. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3705. given in `org-agenda-start-on-weekday'."
  3706. (interactive "P")
  3707. (if org-agenda-overriding-arguments
  3708. (setq arg (car org-agenda-overriding-arguments)
  3709. start-day (nth 1 org-agenda-overriding-arguments)
  3710. span (nth 2 org-agenda-overriding-arguments)))
  3711. (if (and (integerp arg) (> arg 0))
  3712. (setq span arg arg nil))
  3713. (catch 'exit
  3714. (setq org-agenda-buffer-name
  3715. (or org-agenda-buffer-tmp-name
  3716. (if org-agenda-sticky
  3717. (cond ((and org-keys (stringp org-match))
  3718. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3719. (org-keys
  3720. (format "*Org Agenda(%s)*" org-keys))
  3721. (t "*Org Agenda(a)*")))
  3722. org-agenda-buffer-name))
  3723. (org-agenda-prepare "Day/Week")
  3724. (setq start-day (or start-day org-agenda-start-day))
  3725. (if (stringp start-day)
  3726. ;; Convert to an absolute day number
  3727. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3728. (org-compile-prefix-format 'agenda)
  3729. (org-set-sorting-strategy 'agenda)
  3730. (let* ((span (org-agenda-ndays-to-span
  3731. (or span org-agenda-ndays org-agenda-span)))
  3732. (today (org-today))
  3733. (sd (or start-day today))
  3734. (ndays (org-agenda-span-to-ndays span sd))
  3735. (org-agenda-start-on-weekday
  3736. (if (eq ndays 7)
  3737. org-agenda-start-on-weekday))
  3738. (thefiles (org-agenda-files nil 'ifmode))
  3739. (files thefiles)
  3740. (start (if (or (null org-agenda-start-on-weekday)
  3741. (< ndays 7))
  3742. sd
  3743. (let* ((nt (calendar-day-of-week
  3744. (calendar-gregorian-from-absolute sd)))
  3745. (n1 org-agenda-start-on-weekday)
  3746. (d (- nt n1)))
  3747. (- sd (+ (if (< d 0) 7 0) d)))))
  3748. (day-numbers (list start))
  3749. (day-cnt 0)
  3750. (inhibit-redisplay (not debug-on-error))
  3751. (org-agenda-show-log-scoped org-agenda-show-log)
  3752. s e rtn rtnall file date d start-pos end-pos todayp
  3753. clocktable-start clocktable-end filter)
  3754. (setq org-agenda-redo-command
  3755. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3756. (dotimes (n (1- ndays))
  3757. (push (1+ (car day-numbers)) day-numbers))
  3758. (setq day-numbers (nreverse day-numbers))
  3759. (setq clocktable-start (car day-numbers)
  3760. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3761. (org-set-local 'org-starting-day (car day-numbers))
  3762. (org-set-local 'org-arg-loc arg)
  3763. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3764. (unless org-agenda-compact-blocks
  3765. (let* ((d1 (car day-numbers))
  3766. (d2 (org-last day-numbers))
  3767. (w1 (org-days-to-iso-week d1))
  3768. (w2 (org-days-to-iso-week d2)))
  3769. (setq s (point))
  3770. (if org-agenda-overriding-header
  3771. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3772. nil 'face 'org-agenda-structure) "\n")
  3773. (insert (org-agenda-span-name span)
  3774. "-agenda"
  3775. (if (< (- d2 d1) 350)
  3776. (if (= w1 w2)
  3777. (format " (W%02d)" w1)
  3778. (format " (W%02d-W%02d)" w1 w2))
  3779. "")
  3780. ":\n")))
  3781. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3782. 'org-date-line t))
  3783. (org-agenda-mark-header-line s))
  3784. (while (setq d (pop day-numbers))
  3785. (setq date (calendar-gregorian-from-absolute d)
  3786. s (point))
  3787. (if (or (setq todayp (= d today))
  3788. (and (not start-pos) (= d sd)))
  3789. (setq start-pos (point))
  3790. (if (and start-pos (not end-pos))
  3791. (setq end-pos (point))))
  3792. (setq files thefiles
  3793. rtnall nil)
  3794. (while (setq file (pop files))
  3795. (catch 'nextfile
  3796. (org-check-agenda-file file)
  3797. (let ((org-agenda-entry-types org-agenda-entry-types))
  3798. (unless org-agenda-include-deadlines
  3799. (setq org-agenda-entry-types
  3800. (delq :deadline org-agenda-entry-types)))
  3801. (cond
  3802. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3803. (setq rtn (org-agenda-get-day-entries
  3804. file date :closed)))
  3805. (org-agenda-show-log-scoped
  3806. (setq rtn (apply 'org-agenda-get-day-entries
  3807. file date
  3808. (append '(:closed) org-agenda-entry-types))))
  3809. (t
  3810. (setq rtn (apply 'org-agenda-get-day-entries
  3811. file date
  3812. org-agenda-entry-types)))))
  3813. (setq rtnall (append rtnall rtn)))) ;; all entries
  3814. (if org-agenda-include-diary
  3815. (let ((org-agenda-search-headline-for-time t))
  3816. (require 'diary-lib)
  3817. (setq rtn (org-get-entries-from-diary date))
  3818. (setq rtnall (append rtnall rtn))))
  3819. (if (or rtnall org-agenda-show-all-dates)
  3820. (progn
  3821. (setq day-cnt (1+ day-cnt))
  3822. (insert
  3823. (if (stringp org-agenda-format-date)
  3824. (format-time-string org-agenda-format-date
  3825. (org-time-from-absolute date))
  3826. (funcall org-agenda-format-date date))
  3827. "\n")
  3828. (put-text-property s (1- (point)) 'face
  3829. (org-agenda-get-day-face date))
  3830. (put-text-property s (1- (point)) 'org-date-line t)
  3831. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3832. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3833. (when todayp
  3834. (put-text-property s (1- (point)) 'org-today t))
  3835. (setq rtnall
  3836. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3837. (if rtnall (insert ;; all entries
  3838. (org-agenda-finalize-entries rtnall 'agenda)
  3839. "\n"))
  3840. (put-text-property s (1- (point)) 'day d)
  3841. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3842. (when (and org-agenda-clockreport-mode clocktable-start)
  3843. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3844. ;; the above line is to ensure the restricted range!
  3845. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3846. tbl)
  3847. (setq p (org-plist-delete p :block))
  3848. (setq p (plist-put p :tstart clocktable-start))
  3849. (setq p (plist-put p :tend clocktable-end))
  3850. (setq p (plist-put p :scope 'agenda))
  3851. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3852. (setq filter (or org-agenda-tag-filter-while-redo
  3853. (get 'org-agenda-tag-filter :preset-filter))))
  3854. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3855. (if (string-match "[<>=]" x)
  3856. ""
  3857. x))
  3858. filter ""))))
  3859. (setq tbl (apply 'org-clock-get-clocktable p))
  3860. (insert tbl)))
  3861. (goto-char (point-min))
  3862. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3863. (unless (and (pos-visible-in-window-p (point-min))
  3864. (pos-visible-in-window-p (point-max)))
  3865. (goto-char (1- (point-max)))
  3866. (recenter -1)
  3867. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3868. (progn
  3869. (goto-char (or start-pos 1))
  3870. (recenter 1))))
  3871. (goto-char (or start-pos 1))
  3872. (add-text-properties (point-min) (point-max)
  3873. `(org-agenda-type agenda
  3874. org-last-args (,arg ,start-day ,span)
  3875. org-redo-cmd ,org-agenda-redo-command
  3876. org-series-cmd ,org-cmd))
  3877. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3878. (org-agenda-show-clocking-issues))
  3879. (org-agenda-finalize)
  3880. (setq buffer-read-only t)
  3881. (message ""))))
  3882. (defun org-agenda-ndays-to-span (n)
  3883. "Return a span symbol for a span of N days, or N if none matches."
  3884. (cond ((symbolp n) n)
  3885. ((= n 1) 'day)
  3886. ((= n 7) 'week)
  3887. (t n)))
  3888. (defun org-agenda-span-to-ndays (span &optional start-day)
  3889. "Return ndays from SPAN, possibly starting at START-DAY."
  3890. (cond ((numberp span) span)
  3891. ((eq span 'day) 1)
  3892. ((eq span 'week) 7)
  3893. ((eq span 'month)
  3894. (let ((date (calendar-gregorian-from-absolute start-day)))
  3895. (calendar-last-day-of-month (car date) (caddr date))))
  3896. ((eq span 'year)
  3897. (let ((date (calendar-gregorian-from-absolute start-day)))
  3898. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3899. (defun org-agenda-span-name (span)
  3900. "Return a SPAN name."
  3901. (if (null span)
  3902. ""
  3903. (if (symbolp span)
  3904. (capitalize (symbol-name span))
  3905. (format "%d days" span))))
  3906. ;;; Agenda word search
  3907. (defvar org-agenda-search-history nil)
  3908. (defvar org-search-syntax-table nil
  3909. "Special syntax table for org-mode search.
  3910. In this table, we have single quotes not as word constituents, to
  3911. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3912. (defvar org-mode-syntax-table) ; From org.el
  3913. (defun org-search-syntax-table ()
  3914. (unless org-search-syntax-table
  3915. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3916. (modify-syntax-entry ?' "." org-search-syntax-table)
  3917. (modify-syntax-entry ?` "." org-search-syntax-table))
  3918. org-search-syntax-table)
  3919. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3920. ;;;###autoload
  3921. (defun org-search-view (&optional todo-only string edit-at)
  3922. "Show all entries that contain a phrase or words or regular expressions.
  3923. With optional prefix argument TODO-ONLY, only consider entries that are
  3924. TODO entries. The argument STRING can be used to pass a default search
  3925. string into this function. If EDIT-AT is non-nil, it means that the
  3926. user should get a chance to edit this string, with cursor at position
  3927. EDIT-AT.
  3928. The search string can be viewed either as a phrase that should be found as
  3929. is, or it can be broken into a number of snippets, each of which must match
  3930. in a Boolean way to select an entry. The default depends on the variable
  3931. `org-agenda-search-view-always-boolean'.
  3932. Even if this is turned off (the default) you can always switch to
  3933. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3934. The default is a direct search of the whole phrase, where each space in
  3935. the search string can expand to an arbitrary amount of whitespace,
  3936. including newlines.
  3937. If using a Boolean search, the search string is split on whitespace and
  3938. each snippet is searched separately, with logical AND to select an entry.
  3939. Words prefixed with a minus must *not* occur in the entry. Words without
  3940. a prefix or prefixed with a plus must occur in the entry. Matching is
  3941. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3942. match whole words, not parts of a word) if
  3943. `org-agenda-search-view-force-full-words' is set (default is nil).
  3944. Boolean search snippets enclosed by curly braces are interpreted as
  3945. regular expressions that must or (when preceded with \"-\") must not
  3946. match in the entry. Snippets enclosed into double quotes will be taken
  3947. as a whole, to include whitespace.
  3948. - If the search string starts with an asterisk, search only in headlines.
  3949. - If (possibly after the leading star) the search string starts with an
  3950. exclamation mark, this also means to look at TODO entries only, an effect
  3951. that can also be achieved with a prefix argument.
  3952. - If (possibly after star and exclamation mark) the search string starts
  3953. with a colon, this will mean that the (non-regexp) snippets of the
  3954. Boolean search must match as full words.
  3955. This command searches the agenda files, and in addition the files listed
  3956. in `org-agenda-text-search-extra-files'."
  3957. (interactive "P")
  3958. (if org-agenda-overriding-arguments
  3959. (setq todo-only (car org-agenda-overriding-arguments)
  3960. string (nth 1 org-agenda-overriding-arguments)
  3961. edit-at (nth 2 org-agenda-overriding-arguments)))
  3962. (let* ((props (list 'face nil
  3963. 'done-face 'org-agenda-done
  3964. 'org-not-done-regexp org-not-done-regexp
  3965. 'org-todo-regexp org-todo-regexp
  3966. 'org-complex-heading-regexp org-complex-heading-regexp
  3967. 'mouse-face 'highlight
  3968. 'help-echo (format "mouse-2 or RET jump to location")))
  3969. (full-words org-agenda-search-view-force-full-words)
  3970. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3971. regexp rtn rtnall files file pos inherited-tags
  3972. marker category category-pos level tags c neg re boolean
  3973. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3974. (unless (and (not edit-at)
  3975. (stringp string)
  3976. (string-match "\\S-" string))
  3977. (setq string (read-string
  3978. (if org-agenda-search-view-always-boolean
  3979. "[+-]Word/{Regexp} ...: "
  3980. "Phrase or [+-]Word/{Regexp} ...: ")
  3981. (cond
  3982. ((integerp edit-at) (cons string edit-at))
  3983. (edit-at string))
  3984. 'org-agenda-search-history)))
  3985. (catch 'exit
  3986. (if org-agenda-sticky
  3987. (setq org-agenda-buffer-name
  3988. (if (stringp string)
  3989. (format "*Org Agenda(%s:%s)*"
  3990. (or org-keys (or (and todo-only "S") "s")) string)
  3991. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3992. (org-agenda-prepare "SEARCH")
  3993. (org-compile-prefix-format 'search)
  3994. (org-set-sorting-strategy 'search)
  3995. (setq org-agenda-redo-command
  3996. (list 'org-search-view (if todo-only t nil)
  3997. (list 'if 'current-prefix-arg nil string)))
  3998. (setq org-agenda-query-string string)
  3999. (if (equal (string-to-char string) ?*)
  4000. (setq hdl-only t
  4001. words (substring string 1))
  4002. (setq words string))
  4003. (when (equal (string-to-char words) ?!)
  4004. (setq todo-only t
  4005. words (substring words 1)))
  4006. (when (equal (string-to-char words) ?:)
  4007. (setq full-words t
  4008. words (substring words 1)))
  4009. (if (or org-agenda-search-view-always-boolean
  4010. (member (string-to-char words) '(?- ?+ ?\{)))
  4011. (setq boolean t))
  4012. (setq words (org-split-string words))
  4013. (let (www w)
  4014. (while (setq w (pop words))
  4015. (while (and (string-match "\\\\\\'" w) words)
  4016. (setq w (concat (substring w 0 -1) " " (pop words))))
  4017. (push w www))
  4018. (setq words (nreverse www) www nil)
  4019. (while (setq w (pop words))
  4020. (when (and (string-match "\\`[-+]?{" w)
  4021. (not (string-match "}\\'" w)))
  4022. (while (and words (not (string-match "}\\'" (car words))))
  4023. (setq w (concat w " " (pop words))))
  4024. (setq w (concat w " " (pop words))))
  4025. (push w www))
  4026. (setq words (nreverse www)))
  4027. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4028. (when boolean
  4029. (let (wds w)
  4030. (while (setq w (pop words))
  4031. (if (or (equal (substring w 0 1) "\"")
  4032. (and (> (length w) 1)
  4033. (member (substring w 0 1) '("+" "-"))
  4034. (equal (substring w 1 2) "\"")))
  4035. (while (and words (not (equal (substring w -1) "\"")))
  4036. (setq w (concat w " " (pop words)))))
  4037. (and (string-match "\\`\\([-+]?\\)\"" w)
  4038. (setq w (replace-match "\\1" nil nil w)))
  4039. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4040. (push w wds))
  4041. (setq words (nreverse wds))))
  4042. (if boolean
  4043. (mapc (lambda (w)
  4044. (setq c (string-to-char w))
  4045. (if (equal c ?-)
  4046. (setq neg t w (substring w 1))
  4047. (if (equal c ?+)
  4048. (setq neg nil w (substring w 1))
  4049. (setq neg nil)))
  4050. (if (string-match "\\`{.*}\\'" w)
  4051. (setq re (substring w 1 -1))
  4052. (if full-words
  4053. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4054. (setq re (regexp-quote (downcase w)))))
  4055. (if neg (push re regexps-) (push re regexps+)))
  4056. words)
  4057. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4058. regexps+))
  4059. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4060. (if (not regexps+)
  4061. (setq regexp org-outline-regexp-bol)
  4062. (setq regexp (pop regexps+))
  4063. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4064. regexp))))
  4065. (setq files (org-agenda-files nil 'ifmode))
  4066. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4067. (pop org-agenda-text-search-extra-files)
  4068. (setq files (org-add-archive-files files)))
  4069. (setq files (append files org-agenda-text-search-extra-files)
  4070. rtnall nil)
  4071. (while (setq file (pop files))
  4072. (setq ee nil)
  4073. (catch 'nextfile
  4074. (org-check-agenda-file file)
  4075. (setq buffer (if (file-exists-p file)
  4076. (org-get-agenda-file-buffer file)
  4077. (error "No such file %s" file)))
  4078. (if (not buffer)
  4079. ;; If file does not exist, make sure an error message is sent
  4080. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4081. file))))
  4082. (with-current-buffer buffer
  4083. (with-syntax-table (org-search-syntax-table)
  4084. (unless (derived-mode-p 'org-mode)
  4085. (error "Agenda file %s is not in `org-mode'" file))
  4086. (let ((case-fold-search t))
  4087. (save-excursion
  4088. (save-restriction
  4089. (if org-agenda-restrict
  4090. (narrow-to-region org-agenda-restrict-begin
  4091. org-agenda-restrict-end)
  4092. (widen))
  4093. (goto-char (point-min))
  4094. (unless (or (org-at-heading-p)
  4095. (outline-next-heading))
  4096. (throw 'nextfile t))
  4097. (goto-char (max (point-min) (1- (point))))
  4098. (while (re-search-forward regexp nil t)
  4099. (org-back-to-heading t)
  4100. (while (and org-agenda-search-view-max-outline-level
  4101. (> (org-reduced-level (org-outline-level))
  4102. org-agenda-search-view-max-outline-level)
  4103. (forward-line -1)
  4104. (outline-back-to-heading t)))
  4105. (skip-chars-forward "* ")
  4106. (setq beg (point-at-bol)
  4107. beg1 (point)
  4108. end (progn
  4109. (outline-next-heading)
  4110. (while (and org-agenda-search-view-max-outline-level
  4111. (> (org-reduced-level (org-outline-level))
  4112. org-agenda-search-view-max-outline-level)
  4113. (forward-line 1)
  4114. (outline-next-heading)))
  4115. (point)))
  4116. (catch :skip
  4117. (goto-char beg)
  4118. (org-agenda-skip)
  4119. (setq str (buffer-substring-no-properties
  4120. (point-at-bol)
  4121. (if hdl-only (point-at-eol) end)))
  4122. (mapc (lambda (wr) (when (string-match wr str)
  4123. (goto-char (1- end))
  4124. (throw :skip t)))
  4125. regexps-)
  4126. (mapc (lambda (wr) (unless (string-match wr str)
  4127. (goto-char (1- end))
  4128. (throw :skip t)))
  4129. (if todo-only
  4130. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4131. regexps+)
  4132. regexps+))
  4133. (goto-char beg)
  4134. (setq marker (org-agenda-new-marker (point))
  4135. category (org-get-category)
  4136. level (make-string (org-reduced-level (org-outline-level)) ? )
  4137. category-pos (get-text-property (point) 'org-category-position)
  4138. inherited-tags
  4139. (or (eq org-agenda-show-inherited-tags 'always)
  4140. (and (listp org-agenda-show-inherited-tags)
  4141. (memq 'todo org-agenda-show-inherited-tags))
  4142. (and (eq org-agenda-show-inherited-tags t)
  4143. (or (eq org-agenda-use-tag-inheritance t)
  4144. (memq 'todo org-agenda-use-tag-inheritance))))
  4145. tags (org-get-tags-at nil (not inherited-tags))
  4146. txt (org-agenda-format-item
  4147. ""
  4148. (buffer-substring-no-properties
  4149. beg1 (point-at-eol))
  4150. level category tags t))
  4151. (org-add-props txt props
  4152. 'org-marker marker 'org-hd-marker marker
  4153. 'org-todo-regexp org-todo-regexp
  4154. 'level level
  4155. 'org-complex-heading-regexp org-complex-heading-regexp
  4156. 'priority 1000 'org-category category
  4157. 'org-category-position category-pos
  4158. 'type "search")
  4159. (push txt ee)
  4160. (goto-char (1- end))))))))))
  4161. (setq rtn (nreverse ee))
  4162. (setq rtnall (append rtnall rtn)))
  4163. (if org-agenda-overriding-header
  4164. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4165. nil 'face 'org-agenda-structure) "\n")
  4166. (insert "Search words: ")
  4167. (add-text-properties (point-min) (1- (point))
  4168. (list 'face 'org-agenda-structure))
  4169. (setq pos (point))
  4170. (insert string "\n")
  4171. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4172. (setq pos (point))
  4173. (unless org-agenda-multi
  4174. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4175. (add-text-properties pos (1- (point))
  4176. (list 'face 'org-agenda-structure))))
  4177. (org-agenda-mark-header-line (point-min))
  4178. (when rtnall
  4179. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4180. (goto-char (point-min))
  4181. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4182. (add-text-properties (point-min) (point-max)
  4183. `(org-agenda-type search
  4184. org-last-args (,todo-only ,string ,edit-at)
  4185. org-redo-cmd ,org-agenda-redo-command
  4186. org-series-cmd ,org-cmd))
  4187. (org-agenda-finalize)
  4188. (setq buffer-read-only t))))
  4189. ;;; Agenda TODO list
  4190. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4191. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4192. (concat
  4193. (if (or (equal keywords "ALL") (not keywords))
  4194. (propertize "ALL" 'face 'warning)
  4195. (mapconcat
  4196. (lambda (kw)
  4197. (propertize kw 'face (org-get-todo-face kw)))
  4198. (org-split-string keywords "|")
  4199. "|"))
  4200. "\n"))
  4201. (defvar org-select-this-todo-keyword nil)
  4202. (defvar org-last-arg nil)
  4203. ;;;###autoload
  4204. (defun org-todo-list (&optional arg)
  4205. "Show all (not done) TODO entries from all agenda file in a single list.
  4206. The prefix arg can be used to select a specific TODO keyword and limit
  4207. the list to these. When using \\[universal-argument], you will be prompted
  4208. for a keyword. A numeric prefix directly selects the Nth keyword in
  4209. `org-todo-keywords-1'."
  4210. (interactive "P")
  4211. (if org-agenda-overriding-arguments
  4212. (setq arg org-agenda-overriding-arguments))
  4213. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4214. (let* ((today (org-today))
  4215. (date (calendar-gregorian-from-absolute today))
  4216. (kwds org-todo-keywords-for-agenda)
  4217. (completion-ignore-case t)
  4218. (org-select-this-todo-keyword
  4219. (if (stringp arg) arg
  4220. (and arg (integerp arg) (> arg 0)
  4221. (nth (1- arg) kwds))))
  4222. rtn rtnall files file pos)
  4223. (when (equal arg '(4))
  4224. (setq org-select-this-todo-keyword
  4225. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4226. (mapcar 'list kwds) nil nil)))
  4227. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4228. (catch 'exit
  4229. (if org-agenda-sticky
  4230. (setq org-agenda-buffer-name
  4231. (if (stringp org-select-this-todo-keyword)
  4232. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4233. org-select-this-todo-keyword)
  4234. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4235. (org-agenda-prepare "TODO")
  4236. (org-compile-prefix-format 'todo)
  4237. (org-set-sorting-strategy 'todo)
  4238. (setq org-agenda-redo-command
  4239. `(org-todo-list (or (and (numberp current-prefix-arg)
  4240. current-prefix-arg)
  4241. ,org-select-this-todo-keyword
  4242. current-prefix-arg ,arg)))
  4243. (setq files (org-agenda-files nil 'ifmode)
  4244. rtnall nil)
  4245. (while (setq file (pop files))
  4246. (catch 'nextfile
  4247. (org-check-agenda-file file)
  4248. (setq rtn (org-agenda-get-day-entries file date :todo))
  4249. (setq rtnall (append rtnall rtn))))
  4250. (if org-agenda-overriding-header
  4251. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4252. nil 'face 'org-agenda-structure) "\n")
  4253. (insert "Global list of TODO items of type: ")
  4254. (add-text-properties (point-min) (1- (point))
  4255. (list 'face 'org-agenda-structure
  4256. 'short-heading
  4257. (concat "ToDo: "
  4258. (or org-select-this-todo-keyword "ALL"))))
  4259. (org-agenda-mark-header-line (point-min))
  4260. (insert (org-agenda-propertize-selected-todo-keywords
  4261. org-select-this-todo-keyword))
  4262. (setq pos (point))
  4263. (unless org-agenda-multi
  4264. (insert "Available with `N r': (0)[ALL]")
  4265. (let ((n 0) s)
  4266. (mapc (lambda (x)
  4267. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4268. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4269. (insert "\n "))
  4270. (insert " " s))
  4271. kwds))
  4272. (insert "\n"))
  4273. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4274. (org-agenda-mark-header-line (point-min))
  4275. (when rtnall
  4276. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4277. (goto-char (point-min))
  4278. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4279. (add-text-properties (point-min) (point-max)
  4280. `(org-agenda-type todo
  4281. org-last-args ,arg
  4282. org-redo-cmd ,org-agenda-redo-command
  4283. org-series-cmd ,org-cmd))
  4284. (org-agenda-finalize)
  4285. (setq buffer-read-only t))))
  4286. ;;; Agenda tags match
  4287. ;;;###autoload
  4288. (defun org-tags-view (&optional todo-only match)
  4289. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4290. The prefix arg TODO-ONLY limits the search to TODO entries."
  4291. (interactive "P")
  4292. (if org-agenda-overriding-arguments
  4293. (setq todo-only (car org-agenda-overriding-arguments)
  4294. match (nth 1 org-agenda-overriding-arguments)))
  4295. (let* ((org-tags-match-list-sublevels
  4296. org-tags-match-list-sublevels)
  4297. (completion-ignore-case t)
  4298. rtn rtnall files file pos matcher
  4299. buffer)
  4300. (when (and (stringp match) (not (string-match "\\S-" match)))
  4301. (setq match nil))
  4302. (setq matcher (org-make-tags-matcher match)
  4303. match (car matcher) matcher (cdr matcher))
  4304. (catch 'exit
  4305. (if org-agenda-sticky
  4306. (setq org-agenda-buffer-name
  4307. (if (stringp match)
  4308. (format "*Org Agenda(%s:%s)*"
  4309. (or org-keys (or (and todo-only "M") "m")) match)
  4310. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4311. (org-agenda-prepare (concat "TAGS " match))
  4312. (org-compile-prefix-format 'tags)
  4313. (org-set-sorting-strategy 'tags)
  4314. (setq org-agenda-query-string match)
  4315. (setq org-agenda-redo-command
  4316. (list 'org-tags-view `(quote ,todo-only)
  4317. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4318. (setq files (org-agenda-files nil 'ifmode)
  4319. rtnall nil)
  4320. (while (setq file (pop files))
  4321. (catch 'nextfile
  4322. (org-check-agenda-file file)
  4323. (setq buffer (if (file-exists-p file)
  4324. (org-get-agenda-file-buffer file)
  4325. (error "No such file %s" file)))
  4326. (if (not buffer)
  4327. ;; If file does not exist, error message to agenda
  4328. (setq rtn (list
  4329. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4330. rtnall (append rtnall rtn))
  4331. (with-current-buffer buffer
  4332. (unless (derived-mode-p 'org-mode)
  4333. (error "Agenda file %s is not in `org-mode'" file))
  4334. (save-excursion
  4335. (save-restriction
  4336. (if org-agenda-restrict
  4337. (narrow-to-region org-agenda-restrict-begin
  4338. org-agenda-restrict-end)
  4339. (widen))
  4340. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4341. (setq rtnall (append rtnall rtn))))))))
  4342. (if org-agenda-overriding-header
  4343. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4344. nil 'face 'org-agenda-structure) "\n")
  4345. (insert "Headlines with TAGS match: ")
  4346. (add-text-properties (point-min) (1- (point))
  4347. (list 'face 'org-agenda-structure
  4348. 'short-heading
  4349. (concat "Match: " match)))
  4350. (setq pos (point))
  4351. (insert match "\n")
  4352. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4353. (setq pos (point))
  4354. (unless org-agenda-multi
  4355. (insert "Press `C-u r' to search again with new search string\n"))
  4356. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4357. (org-agenda-mark-header-line (point-min))
  4358. (when rtnall
  4359. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4360. (goto-char (point-min))
  4361. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4362. (add-text-properties (point-min) (point-max)
  4363. `(org-agenda-type tags
  4364. org-last-args (,todo-only ,match)
  4365. org-redo-cmd ,org-agenda-redo-command
  4366. org-series-cmd ,org-cmd))
  4367. (org-agenda-finalize)
  4368. (setq buffer-read-only t))))
  4369. ;;; Agenda Finding stuck projects
  4370. (defvar org-agenda-skip-regexp nil
  4371. "Regular expression used in skipping subtrees for the agenda.
  4372. This is basically a temporary global variable that can be set and then
  4373. used by user-defined selections using `org-agenda-skip-function'.")
  4374. (defvar org-agenda-overriding-header nil
  4375. "When set during agenda, todo and tags searches it replaces the header.
  4376. This variable should not be set directly, but custom commands can bind it
  4377. in the options section.")
  4378. (defun org-agenda-skip-entry-when-regexp-matches ()
  4379. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4380. If yes, it returns the end position of this entry, causing agenda commands
  4381. to skip the entry but continuing the search in the subtree. This is a
  4382. function that can be put into `org-agenda-skip-function' for the duration
  4383. of a command."
  4384. (let ((end (save-excursion (org-end-of-subtree t)))
  4385. skip)
  4386. (save-excursion
  4387. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4388. (and skip end)))
  4389. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4390. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4391. If yes, it returns the end position of this tree, causing agenda commands
  4392. to skip this subtree. This is a function that can be put into
  4393. `org-agenda-skip-function' for the duration of a command."
  4394. (let ((end (save-excursion (org-end-of-subtree t)))
  4395. skip)
  4396. (save-excursion
  4397. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4398. (and skip end)))
  4399. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4400. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4401. If yes, it returns the end position of the current entry (NOT the tree),
  4402. causing agenda commands to skip the entry but continuing the search in
  4403. the subtree. This is a function that can be put into
  4404. `org-agenda-skip-function' for the duration of a command. An important
  4405. use of this function is for the stuck project list."
  4406. (let ((end (save-excursion (org-end-of-subtree t)))
  4407. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4408. skip)
  4409. (save-excursion
  4410. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4411. (and skip entry-end)))
  4412. (defun org-agenda-skip-entry-if (&rest conditions)
  4413. "Skip entry if any of CONDITIONS is true.
  4414. See `org-agenda-skip-if' for details."
  4415. (org-agenda-skip-if nil conditions))
  4416. (defun org-agenda-skip-subtree-if (&rest conditions)
  4417. "Skip entry if any of CONDITIONS is true.
  4418. See `org-agenda-skip-if' for details."
  4419. (org-agenda-skip-if t conditions))
  4420. (defun org-agenda-skip-if (subtree conditions)
  4421. "Checks current entity for CONDITIONS.
  4422. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4423. the entry (i.e. the text before the next heading) is checked.
  4424. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4425. from different tests. Valid conditions are:
  4426. scheduled Check if there is a scheduled cookie
  4427. notscheduled Check if there is no scheduled cookie
  4428. deadline Check if there is a deadline
  4429. notdeadline Check if there is no deadline
  4430. timestamp Check if there is a timestamp (also deadline or scheduled)
  4431. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4432. regexp Check if regexp matches
  4433. notregexp Check if regexp does not match.
  4434. todo Check if TODO keyword matches
  4435. nottodo Check if TODO keyword does not match
  4436. The regexp is taken from the conditions list, it must come right after
  4437. the `regexp' or `notregexp' element.
  4438. `todo' and `nottodo' accept as an argument a list of todo
  4439. keywords, which may include \"*\" to match any todo keyword.
  4440. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4441. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4442. Instead of a list, a keyword class may be given. For example:
  4443. (org-agenda-skip-entry-if 'nottodo 'done)
  4444. would skip entries that haven't been marked with any of \"DONE\"
  4445. keywords. Possible classes are: `todo', `done', `any'.
  4446. If any of these conditions is met, this function returns the end point of
  4447. the entity, causing the search to continue from there. This is a function
  4448. that can be put into `org-agenda-skip-function' for the duration of a command."
  4449. (let (beg end m)
  4450. (org-back-to-heading t)
  4451. (setq beg (point)
  4452. end (if subtree
  4453. (progn (org-end-of-subtree t) (point))
  4454. (progn (outline-next-heading) (1- (point)))))
  4455. (goto-char beg)
  4456. (and
  4457. (or
  4458. (and (memq 'scheduled conditions)
  4459. (re-search-forward org-scheduled-time-regexp end t))
  4460. (and (memq 'notscheduled conditions)
  4461. (not (re-search-forward org-scheduled-time-regexp end t)))
  4462. (and (memq 'deadline conditions)
  4463. (re-search-forward org-deadline-time-regexp end t))
  4464. (and (memq 'notdeadline conditions)
  4465. (not (re-search-forward org-deadline-time-regexp end t)))
  4466. (and (memq 'timestamp conditions)
  4467. (re-search-forward org-ts-regexp end t))
  4468. (and (memq 'nottimestamp conditions)
  4469. (not (re-search-forward org-ts-regexp end t)))
  4470. (and (setq m (memq 'regexp conditions))
  4471. (stringp (nth 1 m))
  4472. (re-search-forward (nth 1 m) end t))
  4473. (and (setq m (memq 'notregexp conditions))
  4474. (stringp (nth 1 m))
  4475. (not (re-search-forward (nth 1 m) end t)))
  4476. (and (or
  4477. (setq m (memq 'nottodo conditions))
  4478. (setq m (memq 'todo-unblocked conditions))
  4479. (setq m (memq 'nottodo-unblocked conditions))
  4480. (setq m (memq 'todo conditions)))
  4481. (org-agenda-skip-if-todo m end)))
  4482. end)))
  4483. (defun org-agenda-skip-if-todo (args end)
  4484. "Helper function for `org-agenda-skip-if', do not use it directly.
  4485. ARGS is a list with first element either `todo', `nottodo',
  4486. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4487. a list of TODO keywords, or a state symbol `todo' or `done' or
  4488. `any'."
  4489. (let ((kw (car args))
  4490. (arg (cadr args))
  4491. todo-wds todo-re)
  4492. (setq todo-wds
  4493. (org-uniquify
  4494. (cond
  4495. ((listp arg) ;; list of keywords
  4496. (if (member "*" arg)
  4497. (mapcar 'substring-no-properties org-todo-keywords-1)
  4498. arg))
  4499. ((symbolp arg) ;; keyword class name
  4500. (cond
  4501. ((eq arg 'todo)
  4502. (org-delete-all org-done-keywords
  4503. (mapcar 'substring-no-properties
  4504. org-todo-keywords-1)))
  4505. ((eq arg 'done) org-done-keywords)
  4506. ((eq arg 'any)
  4507. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4508. (setq todo-re
  4509. (concat "^\\*+[ \t]+\\<\\("
  4510. (mapconcat 'identity todo-wds "\\|")
  4511. "\\)\\>"))
  4512. (cond
  4513. ((eq kw 'todo) (re-search-forward todo-re end t))
  4514. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4515. ((eq kw 'todo-unblocked)
  4516. (catch 'unblocked
  4517. (while (re-search-forward todo-re end t)
  4518. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4519. nil))
  4520. ((eq kw 'nottodo-unblocked)
  4521. (catch 'unblocked
  4522. (while (re-search-forward todo-re end t)
  4523. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4524. t))
  4525. )))
  4526. ;;;###autoload
  4527. (defun org-agenda-list-stuck-projects (&rest ignore)
  4528. "Create agenda view for projects that are stuck.
  4529. Stuck projects are project that have no next actions. For the definitions
  4530. of what a project is and how to check if it stuck, customize the variable
  4531. `org-stuck-projects'."
  4532. (interactive)
  4533. (let* ((org-agenda-skip-function
  4534. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4535. ;; We could have used org-agenda-skip-if here.
  4536. (org-agenda-overriding-header
  4537. (or org-agenda-overriding-header "List of stuck projects: "))
  4538. (matcher (nth 0 org-stuck-projects))
  4539. (todo (nth 1 org-stuck-projects))
  4540. (todo-wds (if (member "*" todo)
  4541. (progn
  4542. (org-agenda-prepare-buffers (org-agenda-files
  4543. nil 'ifmode))
  4544. (org-delete-all
  4545. org-done-keywords-for-agenda
  4546. (copy-sequence org-todo-keywords-for-agenda)))
  4547. todo))
  4548. (todo-re (concat "^\\*+[ \t]+\\("
  4549. (mapconcat 'identity todo-wds "\\|")
  4550. "\\)\\>"))
  4551. (tags (nth 2 org-stuck-projects))
  4552. (tags-re (if (member "*" tags)
  4553. (concat org-outline-regexp-bol
  4554. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4555. (if tags
  4556. (concat org-outline-regexp-bol
  4557. ".*:\\("
  4558. (mapconcat 'identity tags "\\|")
  4559. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4560. (gen-re (nth 3 org-stuck-projects))
  4561. (re-list
  4562. (delq nil
  4563. (list
  4564. (if todo todo-re)
  4565. (if tags tags-re)
  4566. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4567. gen-re)))))
  4568. (setq org-agenda-skip-regexp
  4569. (if re-list
  4570. (mapconcat 'identity re-list "\\|")
  4571. (error "No information how to identify unstuck projects")))
  4572. (org-tags-view nil matcher)
  4573. (with-current-buffer org-agenda-buffer-name
  4574. (setq org-agenda-redo-command
  4575. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4576. ;;; Diary integration
  4577. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4578. (defvar diary-list-entries-hook)
  4579. (defvar diary-time-regexp)
  4580. (defun org-get-entries-from-diary (date)
  4581. "Get the (Emacs Calendar) diary entries for DATE."
  4582. (require 'diary-lib)
  4583. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4584. (diary-display-hook '(fancy-diary-display))
  4585. (diary-display-function 'fancy-diary-display)
  4586. (pop-up-frames nil)
  4587. (diary-list-entries-hook
  4588. (cons 'org-diary-default-entry diary-list-entries-hook))
  4589. (diary-file-name-prefix nil) ; turn this feature off
  4590. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4591. entries
  4592. (org-disable-agenda-to-diary t))
  4593. (save-excursion
  4594. (save-window-excursion
  4595. (funcall (if (fboundp 'diary-list-entries)
  4596. 'diary-list-entries 'list-diary-entries)
  4597. date 1)))
  4598. (if (not (get-buffer diary-fancy-buffer))
  4599. (setq entries nil)
  4600. (with-current-buffer diary-fancy-buffer
  4601. (setq buffer-read-only nil)
  4602. (if (zerop (buffer-size))
  4603. ;; No entries
  4604. (setq entries nil)
  4605. ;; Omit the date and other unnecessary stuff
  4606. (org-agenda-cleanup-fancy-diary)
  4607. ;; Add prefix to each line and extend the text properties
  4608. (if (zerop (buffer-size))
  4609. (setq entries nil)
  4610. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4611. (setq entries
  4612. (with-temp-buffer
  4613. (insert entries) (goto-char (point-min))
  4614. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4615. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4616. (replace-match (concat "; " (match-string 1)))))
  4617. (buffer-string)))))
  4618. (set-buffer-modified-p nil)
  4619. (kill-buffer diary-fancy-buffer)))
  4620. (when entries
  4621. (setq entries (org-split-string entries "\n"))
  4622. (setq entries
  4623. (mapcar
  4624. (lambda (x)
  4625. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4626. ;; Extend the text properties to the beginning of the line
  4627. (org-add-props x (text-properties-at (1- (length x)) x)
  4628. 'type "diary" 'date date 'face 'org-agenda-diary))
  4629. entries)))))
  4630. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4631. "Hook run when the fancy diary buffer is cleaned up.")
  4632. (defun org-agenda-cleanup-fancy-diary ()
  4633. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4634. This gets rid of the date, the underline under the date, and
  4635. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4636. date. It also removes lines that contain only whitespace."
  4637. (goto-char (point-min))
  4638. (if (looking-at ".*?:[ \t]*")
  4639. (progn
  4640. (replace-match "")
  4641. (re-search-forward "\n=+$" nil t)
  4642. (replace-match "")
  4643. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4644. (re-search-forward "\n=+$" nil t)
  4645. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4646. (goto-char (point-min))
  4647. (while (re-search-forward "^ +\n" nil t)
  4648. (replace-match ""))
  4649. (goto-char (point-min))
  4650. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4651. (replace-match ""))
  4652. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4653. ;; Make sure entries from the diary have the right text properties.
  4654. (eval-after-load "diary-lib"
  4655. '(if (boundp 'diary-modify-entry-list-string-function)
  4656. ;; We can rely on the hook, nothing to do
  4657. nil
  4658. ;; Hook not available, must use advice to make this work
  4659. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4660. "Make the position visible."
  4661. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4662. (stringp string)
  4663. buffer-file-name)
  4664. (setq string (org-modify-diary-entry-string string))))))
  4665. (defun org-modify-diary-entry-string (string)
  4666. "Add text properties to string, allowing org-mode to act on it."
  4667. (org-add-props string nil
  4668. 'mouse-face 'highlight
  4669. 'help-echo (if buffer-file-name
  4670. (format "mouse-2 or RET jump to diary file %s"
  4671. (abbreviate-file-name buffer-file-name))
  4672. "")
  4673. 'org-agenda-diary-link t
  4674. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4675. (defun org-diary-default-entry ()
  4676. "Add a dummy entry to the diary.
  4677. Needed to avoid empty dates which mess up holiday display."
  4678. ;; Catch the error if dealing with the new add-to-diary-alist
  4679. (when org-disable-agenda-to-diary
  4680. (condition-case nil
  4681. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4682. (error
  4683. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4684. (defun org-add-to-diary-list (&rest args)
  4685. (if (fboundp 'diary-add-to-list)
  4686. (apply 'diary-add-to-list args)
  4687. (apply 'add-to-diary-list args)))
  4688. (defvar org-diary-last-run-time nil)
  4689. ;;;###autoload
  4690. (defun org-diary (&rest args)
  4691. "Return diary information from org files.
  4692. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4693. It accesses org files and extracts information from those files to be
  4694. listed in the diary. The function accepts arguments specifying what
  4695. items should be listed. For a list of arguments allowed here, see the
  4696. variable `org-agenda-entry-types'.
  4697. The call in the diary file should look like this:
  4698. &%%(org-diary) ~/path/to/some/orgfile.org
  4699. Use a separate line for each org file to check. Or, if you omit the file name,
  4700. all files listed in `org-agenda-files' will be checked automatically:
  4701. &%%(org-diary)
  4702. If you don't give any arguments (as in the example above), the default
  4703. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4704. So the example above may also be written as
  4705. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4706. The function expects the lisp variables `entry' and `date' to be provided
  4707. by the caller, because this is how the calendar works. Don't use this
  4708. function from a program - use `org-agenda-get-day-entries' instead."
  4709. (when (> (- (org-float-time)
  4710. org-agenda-last-marker-time)
  4711. 5)
  4712. ;; I am not sure if this works with sticky agendas, because the marker
  4713. ;; list is then no longer a global variable.
  4714. (org-agenda-reset-markers))
  4715. (org-compile-prefix-format 'agenda)
  4716. (org-set-sorting-strategy 'agenda)
  4717. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4718. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4719. (list entry)
  4720. (org-agenda-files t)))
  4721. (time (org-float-time))
  4722. file rtn results)
  4723. (when (or (not org-diary-last-run-time)
  4724. (> (- time
  4725. org-diary-last-run-time)
  4726. 3))
  4727. (org-agenda-prepare-buffers files))
  4728. (setq org-diary-last-run-time time)
  4729. ;; If this is called during org-agenda, don't return any entries to
  4730. ;; the calendar. Org Agenda will list these entries itself.
  4731. (if org-disable-agenda-to-diary (setq files nil))
  4732. (while (setq file (pop files))
  4733. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4734. (setq results (append results rtn)))
  4735. (when results
  4736. (setq results
  4737. (mapcar (lambda (i) (replace-regexp-in-string
  4738. org-bracket-link-regexp "\\3" i)) results))
  4739. (concat (org-agenda-finalize-entries results) "\n"))))
  4740. ;;; Agenda entry finders
  4741. (defun org-agenda-get-day-entries (file date &rest args)
  4742. "Does the work for `org-diary' and `org-agenda'.
  4743. FILE is the path to a file to be checked for entries. DATE is date like
  4744. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4745. which kind of entries should be extracted. For details about these, see
  4746. the documentation of `org-diary'."
  4747. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4748. (let* ((org-startup-folded nil)
  4749. (org-startup-align-all-tables nil)
  4750. (buffer (if (file-exists-p file)
  4751. (org-get-agenda-file-buffer file)
  4752. (error "No such file %s" file)))
  4753. arg results rtn deadline-results)
  4754. (if (not buffer)
  4755. ;; If file does not exist, make sure an error message ends up in diary
  4756. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4757. (with-current-buffer buffer
  4758. (unless (derived-mode-p 'org-mode)
  4759. (error "Agenda file %s is not in `org-mode'" file))
  4760. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4761. (let ((case-fold-search nil))
  4762. (save-excursion
  4763. (save-restriction
  4764. (if org-agenda-restrict
  4765. (narrow-to-region org-agenda-restrict-begin
  4766. org-agenda-restrict-end)
  4767. (widen))
  4768. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4769. (while (setq arg (pop args))
  4770. (cond
  4771. ((and (eq arg :todo)
  4772. (equal date (calendar-gregorian-from-absolute
  4773. (org-today))))
  4774. (setq rtn (org-agenda-get-todos))
  4775. (setq results (append results rtn)))
  4776. ((eq arg :timestamp)
  4777. (setq rtn (org-agenda-get-blocks))
  4778. (setq results (append results rtn))
  4779. (setq rtn (org-agenda-get-timestamps deadline-results))
  4780. (setq results (append results rtn)))
  4781. ((eq arg :sexp)
  4782. (setq rtn (org-agenda-get-sexps))
  4783. (setq results (append results rtn)))
  4784. ((eq arg :scheduled)
  4785. (setq rtn (org-agenda-get-scheduled deadline-results))
  4786. (setq results (append results rtn)))
  4787. ((eq arg :closed)
  4788. (setq rtn (org-agenda-get-progress))
  4789. (setq results (append results rtn)))
  4790. ((eq arg :deadline)
  4791. (setq rtn (org-agenda-get-deadlines))
  4792. (setq deadline-results (copy-sequence rtn))
  4793. (setq results (append results rtn))))))))
  4794. results))))
  4795. (defsubst org-em (x y list)
  4796. "Is X or Y a member of LIST?"
  4797. (or (memq x list) (memq y list)))
  4798. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4799. (defvar org-agenda-sorting-strategy-selected nil)
  4800. (defun org-agenda-get-todos ()
  4801. "Return the TODO information for agenda display."
  4802. (let* ((props (list 'face nil
  4803. 'done-face 'org-agenda-done
  4804. 'org-not-done-regexp org-not-done-regexp
  4805. 'org-todo-regexp org-todo-regexp
  4806. 'org-complex-heading-regexp org-complex-heading-regexp
  4807. 'mouse-face 'highlight
  4808. 'help-echo
  4809. (format "mouse-2 or RET jump to org file %s"
  4810. (abbreviate-file-name buffer-file-name))))
  4811. (regexp (format org-heading-keyword-regexp-format
  4812. (cond
  4813. ((and org-select-this-todo-keyword
  4814. (equal org-select-this-todo-keyword "*"))
  4815. org-todo-regexp)
  4816. (org-select-this-todo-keyword
  4817. (concat "\\("
  4818. (mapconcat 'identity
  4819. (org-split-string
  4820. org-select-this-todo-keyword
  4821. "|")
  4822. "\\|") "\\)"))
  4823. (t org-not-done-regexp))))
  4824. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4825. ee txt beg end inherited-tags)
  4826. (goto-char (point-min))
  4827. (while (re-search-forward regexp nil t)
  4828. (catch :skip
  4829. (save-match-data
  4830. (beginning-of-line)
  4831. (org-agenda-skip)
  4832. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4833. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4834. (goto-char (1+ beg))
  4835. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4836. (throw :skip nil)))
  4837. (goto-char (match-beginning 2))
  4838. (setq marker (org-agenda-new-marker (match-beginning 0))
  4839. category (org-get-category)
  4840. ts-date (let (ts)
  4841. (save-match-data
  4842. (cond ((org-em 'scheduled-up 'scheduled-down
  4843. org-agenda-sorting-strategy-selected)
  4844. (setq ts (org-entry-get (point) "SCHEDULED")
  4845. ts-date-type " scheduled"))
  4846. ((org-em 'deadline-up 'deadline-down
  4847. org-agenda-sorting-strategy-selected)
  4848. (setq ts (org-entry-get (point) "DEADLINE")
  4849. ts-date-type " deadline"))
  4850. ((org-em 'ts-up 'ts-down
  4851. org-agenda-sorting-strategy-selected)
  4852. (setq ts (org-entry-get (point) "TIMESTAMP")
  4853. ts-date-type " timestamp"))
  4854. ((org-em 'tsia-up 'tsia-down
  4855. org-agenda-sorting-strategy-selected)
  4856. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4857. ts-date-type " timestamp_ia"))
  4858. ((org-em 'timestamp-up 'timestamp-down
  4859. org-agenda-sorting-strategy-selected)
  4860. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4861. (org-entry-get (point) "DEADLINE")
  4862. (org-entry-get (point) "TIMESTAMP")
  4863. (org-entry-get (point) "TIMESTAMP_IA"))
  4864. ts-date-type ""))
  4865. (t (setq ts-date-type "")))
  4866. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4867. category-pos (get-text-property (point) 'org-category-position)
  4868. txt (org-trim
  4869. (buffer-substring (match-beginning 2) (match-end 0)))
  4870. inherited-tags
  4871. (or (eq org-agenda-show-inherited-tags 'always)
  4872. (and (listp org-agenda-show-inherited-tags)
  4873. (memq 'todo org-agenda-show-inherited-tags))
  4874. (and (eq org-agenda-show-inherited-tags t)
  4875. (or (eq org-agenda-use-tag-inheritance t)
  4876. (memq 'todo org-agenda-use-tag-inheritance))))
  4877. tags (org-get-tags-at nil (not inherited-tags))
  4878. level (make-string (org-reduced-level (org-outline-level)) ? )
  4879. txt (org-agenda-format-item "" txt level category tags t)
  4880. priority (1+ (org-get-priority txt))
  4881. todo-state (org-get-todo-state))
  4882. (org-add-props txt props
  4883. 'org-marker marker 'org-hd-marker marker
  4884. 'priority priority 'org-category category
  4885. 'level level
  4886. 'ts-date ts-date
  4887. 'org-category-position category-pos
  4888. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4889. (push txt ee)
  4890. (if org-agenda-todo-list-sublevels
  4891. (goto-char (match-end 2))
  4892. (org-end-of-subtree 'invisible))))
  4893. (nreverse ee)))
  4894. (defun org-agenda-todo-custom-ignore-p (time n)
  4895. "Check whether timestamp is farther away than n number of days.
  4896. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4897. `org-agenda-todo-ignore-scheduled' or
  4898. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4899. (let ((days (org-time-stamp-to-now
  4900. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4901. (if (>= n 0)
  4902. (>= days n)
  4903. (<= days n))))
  4904. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4905. (&optional end)
  4906. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4907. (when (or org-agenda-todo-ignore-with-date
  4908. org-agenda-todo-ignore-scheduled
  4909. org-agenda-todo-ignore-deadlines
  4910. org-agenda-todo-ignore-timestamp)
  4911. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4912. (save-excursion
  4913. (or (and org-agenda-todo-ignore-with-date
  4914. (re-search-forward org-ts-regexp end t))
  4915. (and org-agenda-todo-ignore-scheduled
  4916. (re-search-forward org-scheduled-time-regexp end t)
  4917. (cond
  4918. ((eq org-agenda-todo-ignore-scheduled 'future)
  4919. (> (org-time-stamp-to-now
  4920. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4921. ((eq org-agenda-todo-ignore-scheduled 'past)
  4922. (<= (org-time-stamp-to-now
  4923. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4924. ((numberp org-agenda-todo-ignore-scheduled)
  4925. (org-agenda-todo-custom-ignore-p
  4926. (match-string 1) org-agenda-todo-ignore-scheduled))
  4927. (t)))
  4928. (and org-agenda-todo-ignore-deadlines
  4929. (re-search-forward org-deadline-time-regexp end t)
  4930. (cond
  4931. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4932. ((eq org-agenda-todo-ignore-deadlines 'far)
  4933. (not (org-deadline-close (match-string 1))))
  4934. ((eq org-agenda-todo-ignore-deadlines 'future)
  4935. (> (org-time-stamp-to-now
  4936. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4937. ((eq org-agenda-todo-ignore-deadlines 'past)
  4938. (<= (org-time-stamp-to-now
  4939. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4940. ((numberp org-agenda-todo-ignore-deadlines)
  4941. (org-agenda-todo-custom-ignore-p
  4942. (match-string 1) org-agenda-todo-ignore-deadlines))
  4943. (t (org-deadline-close (match-string 1)))))
  4944. (and org-agenda-todo-ignore-timestamp
  4945. (let ((buffer (current-buffer))
  4946. (regexp
  4947. (concat
  4948. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4949. (start (point)))
  4950. ;; Copy current buffer into a temporary one
  4951. (with-temp-buffer
  4952. (insert-buffer-substring buffer start end)
  4953. (goto-char (point-min))
  4954. ;; Delete SCHEDULED and DEADLINE items
  4955. (while (re-search-forward regexp end t)
  4956. (delete-region (match-beginning 0) (match-end 0)))
  4957. (goto-char (point-min))
  4958. ;; No search for timestamp left
  4959. (when (re-search-forward org-ts-regexp nil t)
  4960. (cond
  4961. ((eq org-agenda-todo-ignore-timestamp 'future)
  4962. (> (org-time-stamp-to-now
  4963. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4964. ((eq org-agenda-todo-ignore-timestamp 'past)
  4965. (<= (org-time-stamp-to-now
  4966. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4967. ((numberp org-agenda-todo-ignore-timestamp)
  4968. (org-agenda-todo-custom-ignore-p
  4969. (match-string 1) org-agenda-todo-ignore-timestamp))
  4970. (t))))))))))
  4971. (defun org-agenda-get-timestamps (&optional deadline-results)
  4972. "Return the date stamp information for agenda display."
  4973. (let* ((props (list 'face 'org-agenda-calendar-event
  4974. 'org-not-done-regexp org-not-done-regexp
  4975. 'org-todo-regexp org-todo-regexp
  4976. 'org-complex-heading-regexp org-complex-heading-regexp
  4977. 'mouse-face 'highlight
  4978. 'help-echo
  4979. (format "mouse-2 or RET jump to org file %s"
  4980. (abbreviate-file-name buffer-file-name))))
  4981. (d1 (calendar-absolute-from-gregorian date))
  4982. mm
  4983. (deadline-position-alist
  4984. (mapcar (lambda (a) (and (setq mm (get-text-property
  4985. 0 'org-hd-marker a))
  4986. (cons (marker-position mm) a)))
  4987. deadline-results))
  4988. (remove-re org-ts-regexp)
  4989. (regexp
  4990. (concat
  4991. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4992. (regexp-quote
  4993. (substring
  4994. (format-time-string
  4995. (car org-time-stamp-formats)
  4996. (apply 'encode-time ; DATE bound by calendar
  4997. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4998. 1 11))
  4999. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5000. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5001. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5002. donep tmp priority category category-pos level ee txt timestr tags
  5003. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5004. inherited-tags ts-date)
  5005. (goto-char (point-min))
  5006. (while (setq end-of-match (re-search-forward regexp nil t))
  5007. (setq b0 (match-beginning 0)
  5008. b3 (match-beginning 3) e3 (match-end 3)
  5009. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5010. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5011. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5012. (member todo-state
  5013. org-agenda-repeating-timestamp-show-all)))
  5014. (catch :skip
  5015. (and (org-at-date-range-p) (throw :skip nil))
  5016. (org-agenda-skip)
  5017. (if (and (match-end 1)
  5018. (not (= d1 (org-time-string-to-absolute
  5019. (match-string 1) d1 nil show-all
  5020. (current-buffer) b0))))
  5021. (throw :skip nil))
  5022. (if (and e3
  5023. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5024. (throw :skip nil))
  5025. (setq tmp (buffer-substring (max (point-min)
  5026. (- b0 org-ds-keyword-length))
  5027. b0)
  5028. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5029. inactivep (= (char-after b0) ?\[)
  5030. deadlinep (string-match org-deadline-regexp tmp)
  5031. scheduledp (string-match org-scheduled-regexp tmp)
  5032. closedp (and org-agenda-include-inactive-timestamps
  5033. (string-match org-closed-string tmp))
  5034. clockp (and org-agenda-include-inactive-timestamps
  5035. (or (string-match org-clock-string tmp)
  5036. (string-match "]-+\\'" tmp)))
  5037. warntime (get-text-property (point) 'org-appt-warntime)
  5038. donep (member todo-state org-done-keywords))
  5039. (if (or scheduledp deadlinep closedp clockp
  5040. (and donep org-agenda-skip-timestamp-if-done))
  5041. (throw :skip t))
  5042. (if (string-match ">" timestr)
  5043. ;; substring should only run to end of time stamp
  5044. (setq timestr (substring timestr 0 (match-end 0))))
  5045. (setq marker (org-agenda-new-marker b0)
  5046. category (org-get-category b0)
  5047. category-pos (get-text-property b0 'org-category-position))
  5048. (save-excursion
  5049. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5050. (throw :skip nil)
  5051. (goto-char (match-beginning 0))
  5052. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5053. (assoc (point) deadline-position-alist))
  5054. (throw :skip nil))
  5055. (setq hdmarker (org-agenda-new-marker)
  5056. inherited-tags
  5057. (or (eq org-agenda-show-inherited-tags 'always)
  5058. (and (listp org-agenda-show-inherited-tags)
  5059. (memq 'agenda org-agenda-show-inherited-tags))
  5060. (and (eq org-agenda-show-inherited-tags t)
  5061. (or (eq org-agenda-use-tag-inheritance t)
  5062. (memq 'agenda org-agenda-use-tag-inheritance))))
  5063. tags (org-get-tags-at nil (not inherited-tags))
  5064. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5065. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5066. (setq head (or (match-string 1) ""))
  5067. (setq txt (org-agenda-format-item
  5068. (if inactivep org-agenda-inactive-leader nil)
  5069. head level category tags timestr
  5070. remove-re habitp)))
  5071. (setq priority (org-get-priority txt))
  5072. (org-add-props txt props 'priority priority
  5073. 'org-marker marker 'org-hd-marker hdmarker
  5074. 'org-category category 'date date
  5075. 'level level
  5076. 'ts-date
  5077. (ignore-errors (org-time-string-to-absolute timestr))
  5078. 'org-category-position category-pos
  5079. 'todo-state todo-state
  5080. 'warntime warntime
  5081. 'type "timestamp")
  5082. (push txt ee))
  5083. (if org-agenda-skip-additional-timestamps-same-entry
  5084. (outline-next-heading)
  5085. (goto-char end-of-match))))
  5086. (nreverse ee)))
  5087. (defun org-agenda-get-sexps ()
  5088. "Return the sexp information for agenda display."
  5089. (require 'diary-lib)
  5090. (let* ((props (list 'face 'org-agenda-calendar-sexp
  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. (regexp "^&?%%(")
  5096. marker category extra category-pos level ee txt tags entry
  5097. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5098. (goto-char (point-min))
  5099. (while (re-search-forward regexp nil t)
  5100. (catch :skip
  5101. (org-agenda-skip)
  5102. (setq beg (match-beginning 0))
  5103. (goto-char (1- (match-end 0)))
  5104. (setq b (point))
  5105. (forward-sexp 1)
  5106. (setq sexp (buffer-substring b (point)))
  5107. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5108. (org-trim (match-string 1))
  5109. ""))
  5110. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5111. (when result
  5112. (setq marker (org-agenda-new-marker beg)
  5113. level (make-string (org-reduced-level (org-outline-level)) ? )
  5114. category (org-get-category beg)
  5115. category-pos (get-text-property beg 'org-category-position)
  5116. inherited-tags
  5117. (or (eq org-agenda-show-inherited-tags 'always)
  5118. (and (listp org-agenda-show-inherited-tags)
  5119. (memq 'agenda org-agenda-show-inherited-tags))
  5120. (and (eq org-agenda-show-inherited-tags t)
  5121. (or (eq org-agenda-use-tag-inheritance t)
  5122. (memq 'agenda org-agenda-use-tag-inheritance))))
  5123. tags (org-get-tags-at nil (not inherited-tags))
  5124. todo-state (org-get-todo-state)
  5125. warntime (get-text-property (point) 'org-appt-warntime)
  5126. extra nil)
  5127. (dolist (r (if (stringp result)
  5128. (list result)
  5129. result)) ;; we expect a list here
  5130. (when (and org-agenda-diary-sexp-prefix
  5131. (string-match org-agenda-diary-sexp-prefix r))
  5132. (setq extra (match-string 0 r)
  5133. r (replace-match "" nil nil r)))
  5134. (if (string-match "\\S-" r)
  5135. (setq txt r)
  5136. (setq txt "SEXP entry returned empty string"))
  5137. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5138. (org-add-props txt props 'org-marker marker
  5139. 'org-category category 'date date 'todo-state todo-state
  5140. 'org-category-position category-pos 'tags tags
  5141. 'level level
  5142. 'type "sexp" 'warntime warntime)
  5143. (push txt ee)))))
  5144. (nreverse ee)))
  5145. ;; Calendar sanity: define some functions that are independent of
  5146. ;; `calendar-date-style'.
  5147. ;; Normally I would like to use ISO format when calling the diary functions,
  5148. ;; but to make sure we still have Emacs 22 compatibility we bind
  5149. ;; also `european-calendar-style' and use european format
  5150. (defun org-anniversary (year month day &optional mark)
  5151. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5152. (org-no-warnings
  5153. (let ((calendar-date-style 'european) (european-calendar-style t))
  5154. (diary-anniversary day month year mark))))
  5155. (defun org-cyclic (N year month day &optional mark)
  5156. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5157. (org-no-warnings
  5158. (let ((calendar-date-style 'european) (european-calendar-style t))
  5159. (diary-cyclic N day month year mark))))
  5160. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5161. "Like `diary-block', but with fixed (ISO) order of arguments."
  5162. (org-no-warnings
  5163. (let ((calendar-date-style 'european) (european-calendar-style t))
  5164. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5165. (defun org-date (year month day &optional mark)
  5166. "Like `diary-date', but with fixed (ISO) order of arguments."
  5167. (org-no-warnings
  5168. (let ((calendar-date-style 'european) (european-calendar-style t))
  5169. (diary-date day month year mark))))
  5170. ;; Define the` org-class' function
  5171. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5172. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5173. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5174. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5175. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5176. `holidays', then any date that is known by the Emacs calendar to be a
  5177. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5178. then those holidays will be skipped."
  5179. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5180. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5181. (d (calendar-absolute-from-gregorian date))
  5182. (h (when skip-weeks (calendar-check-holidays date))))
  5183. (and
  5184. (<= date1 d)
  5185. (<= d date2)
  5186. (= (calendar-day-of-week date) dayname)
  5187. (or (not skip-weeks)
  5188. (progn
  5189. (require 'cal-iso)
  5190. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5191. (not (or (and h (memq 'holidays skip-weeks))
  5192. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5193. entry)))
  5194. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5195. "Like `org-class', but honor `calendar-date-style'.
  5196. The order of the first 2 times 3 arguments depends on the variable
  5197. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5198. So for American calendars, give this as MONTH DAY YEAR, for European as
  5199. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5200. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5201. is any number of ISO weeks in the block period for which the item should
  5202. be skipped.
  5203. This function is here only for backward compatibility and it is deprecated,
  5204. please use `org-class' instead."
  5205. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5206. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5207. (org-class
  5208. (nth 2 date1) (car date1) (nth 1 date1)
  5209. (nth 2 date2) (car date2) (nth 1 date2)
  5210. dayname skip-weeks)))
  5211. (make-obsolete 'org-diary-class 'org-class "")
  5212. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5213. (defalias 'org-get-closed 'org-agenda-get-progress)
  5214. (defun org-agenda-get-progress ()
  5215. "Return the logged TODO entries for agenda display."
  5216. (let* ((props (list 'mouse-face 'highlight
  5217. 'org-not-done-regexp org-not-done-regexp
  5218. 'org-todo-regexp org-todo-regexp
  5219. 'org-complex-heading-regexp org-complex-heading-regexp
  5220. 'help-echo
  5221. (format "mouse-2 or RET jump to org file %s"
  5222. (abbreviate-file-name buffer-file-name))))
  5223. (items (if (consp org-agenda-show-log-scoped)
  5224. org-agenda-show-log-scoped
  5225. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5226. '(clock)
  5227. org-agenda-log-mode-items)))
  5228. (parts
  5229. (delq nil
  5230. (list
  5231. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5232. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5233. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5234. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5235. (error "`org-agenda-log-mode-items' is empty")))
  5236. (regexp (concat
  5237. "\\(" parts-re "\\)"
  5238. " *\\["
  5239. (regexp-quote
  5240. (substring
  5241. (format-time-string
  5242. (car org-time-stamp-formats)
  5243. (apply 'encode-time ; DATE bound by calendar
  5244. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5245. 1 11))))
  5246. (org-agenda-search-headline-for-time nil)
  5247. marker hdmarker priority category category-pos level tags closedp
  5248. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5249. (goto-char (point-min))
  5250. (while (re-search-forward regexp nil t)
  5251. (catch :skip
  5252. (org-agenda-skip)
  5253. (setq marker (org-agenda-new-marker (match-beginning 0))
  5254. closedp (equal (match-string 1) org-closed-string)
  5255. statep (equal (string-to-char (match-string 1)) ?-)
  5256. clockp (not (or closedp statep))
  5257. state (and statep (match-string 2))
  5258. category (org-get-category (match-beginning 0))
  5259. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5260. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5261. (when (string-match "\\]" timestr)
  5262. ;; substring should only run to end of time stamp
  5263. (setq rest (substring timestr (match-end 0))
  5264. timestr (substring timestr 0 (match-end 0)))
  5265. (if (and (not closedp) (not statep)
  5266. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5267. rest))
  5268. (progn (setq timestr (concat (substring timestr 0 -1)
  5269. "-" (match-string 1 rest) "]"))
  5270. (setq clocked (match-string 2 rest)))
  5271. (setq clocked "-")))
  5272. (save-excursion
  5273. (setq extra
  5274. (cond
  5275. ((not org-agenda-log-mode-add-notes) nil)
  5276. (statep
  5277. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5278. (match-string 1)))
  5279. (clockp
  5280. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5281. (match-string 1)))))
  5282. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5283. (throw :skip nil)
  5284. (goto-char (match-beginning 0))
  5285. (setq hdmarker (org-agenda-new-marker)
  5286. inherited-tags
  5287. (or (eq org-agenda-show-inherited-tags 'always)
  5288. (and (listp org-agenda-show-inherited-tags)
  5289. (memq 'todo org-agenda-show-inherited-tags))
  5290. (and (eq org-agenda-show-inherited-tags t)
  5291. (or (eq org-agenda-use-tag-inheritance t)
  5292. (memq 'todo org-agenda-use-tag-inheritance))))
  5293. tags (org-get-tags-at nil (not inherited-tags))
  5294. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5295. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5296. (setq txt (match-string 1))
  5297. (when extra
  5298. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5299. (setq txt (concat (substring txt 0 (match-beginning 1))
  5300. " - " extra " " (match-string 2 txt)))
  5301. (setq txt (concat txt " - " extra))))
  5302. (setq txt (org-agenda-format-item
  5303. (cond
  5304. (closedp "Closed: ")
  5305. (statep (concat "State: (" state ")"))
  5306. (t (concat "Clocked: (" clocked ")")))
  5307. txt level category tags timestr)))
  5308. (setq priority 100000)
  5309. (org-add-props txt props
  5310. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5311. 'priority priority 'org-category category
  5312. 'org-category-position category-pos
  5313. 'level level
  5314. 'type "closed" 'date date
  5315. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5316. (push txt ee))
  5317. (goto-char (point-at-eol))))
  5318. (nreverse ee)))
  5319. (defun org-agenda-show-clocking-issues ()
  5320. "Add overlays, showing issues with clocking.
  5321. See also the user option `org-agenda-clock-consistency-checks'."
  5322. (interactive)
  5323. (let* ((org-time-clocksum-use-effort-durations nil)
  5324. (pl org-agenda-clock-consistency-checks)
  5325. (re (concat "^[ \t]*"
  5326. org-clock-string
  5327. "[ \t]+"
  5328. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5329. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5330. (tlstart 0.)
  5331. (tlend 0.)
  5332. (maxtime (org-hh:mm-string-to-minutes
  5333. (or (plist-get pl :max-duration) "24:00")))
  5334. (mintime (org-hh:mm-string-to-minutes
  5335. (or (plist-get pl :min-duration) 0)))
  5336. (maxgap (org-hh:mm-string-to-minutes
  5337. ;; default 30:00 means never complain
  5338. (or (plist-get pl :max-gap) "30:00")))
  5339. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5340. (plist-get pl :gap-ok-around)))
  5341. (def-face (or (plist-get pl :default-face)
  5342. '((:background "DarkRed") (:foreground "white"))))
  5343. issue face m te ts dt ov)
  5344. (goto-char (point-min))
  5345. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5346. (setq issue nil face def-face)
  5347. (catch 'next
  5348. (setq m (org-get-at-bol 'org-marker)
  5349. te nil ts nil)
  5350. (unless (and m (markerp m))
  5351. (setq issue "No valid clock line") (throw 'next t))
  5352. (org-with-point-at m
  5353. (save-excursion
  5354. (goto-char (point-at-bol))
  5355. (unless (looking-at re)
  5356. (error "No valid Clock line")
  5357. (throw 'next t))
  5358. (unless (match-end 3)
  5359. (setq issue "No end time"
  5360. face (or (plist-get pl :no-end-time-face) face))
  5361. (throw 'next t))
  5362. (setq ts (match-string 1)
  5363. te (match-string 3)
  5364. ts (org-float-time
  5365. (apply 'encode-time (org-parse-time-string ts)))
  5366. te (org-float-time
  5367. (apply 'encode-time (org-parse-time-string te)))
  5368. dt (- te ts))))
  5369. (cond
  5370. ((> dt (* 60 maxtime))
  5371. ;; a very long clocking chunk
  5372. (setq issue (format "Clocking interval is very long: %s"
  5373. (org-minutes-to-clocksum-string
  5374. (floor (/ (float dt) 60.))))
  5375. face (or (plist-get pl :long-face) face)))
  5376. ((< dt (* 60 mintime))
  5377. ;; a very short clocking chunk
  5378. (setq issue (format "Clocking interval is very short: %s"
  5379. (org-minutes-to-clocksum-string
  5380. (floor (/ (float dt) 60.))))
  5381. face (or (plist-get pl :short-face) face)))
  5382. ((and (> tlend 0) (< ts tlend))
  5383. ;; Two clock entries are overlapping
  5384. (setq issue (format "Clocking overlap: %d minutes"
  5385. (/ (- tlend ts) 60))
  5386. face (or (plist-get pl :overlap-face) face)))
  5387. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5388. ;; There is a gap, lets see if we need to report it
  5389. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5390. (setq issue (format "Clocking gap: %d minutes"
  5391. (/ (- ts tlend) 60))
  5392. face (or (plist-get pl :gap-face) face))))
  5393. (t nil)))
  5394. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5395. (when issue
  5396. ;; OK, there was some issue, add an overlay to show the issue
  5397. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5398. (overlay-put ov 'before-string
  5399. (concat
  5400. (org-add-props
  5401. (format "%-43s" (concat " " issue))
  5402. nil
  5403. 'face face)
  5404. "\n"))
  5405. (overlay-put ov 'evaporate t)))))
  5406. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5407. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5408. (catch 'exit
  5409. (unless ok-list
  5410. ;; there are no OK times for gaps...
  5411. (throw 'exit nil))
  5412. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5413. ;; This is more than 24 hours, so it is OK.
  5414. ;; because we have at least one OK time, that must be in the
  5415. ;; 24 hour interval.
  5416. (throw 'exit t))
  5417. ;; We have a shorter gap.
  5418. ;; Now we have to get the minute of the day when these times are
  5419. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5420. (t2dec (decode-time (seconds-to-time t2)))
  5421. ;; compute the minute on the day
  5422. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5423. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5424. (when (< min2 min1)
  5425. ;; if min2 is smaller than min1, this means it is on the next day.
  5426. ;; Wrap it to after midnight.
  5427. (setq min2 (+ min2 1440)))
  5428. ;; Now check if any of the OK times is in the gap
  5429. (mapc (lambda (x)
  5430. ;; Wrap the time to after midnight if necessary
  5431. (if (< x min1) (setq x (+ x 1440)))
  5432. ;; Check if in interval
  5433. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5434. ok-list)
  5435. ;; Nope, this gap is not OK
  5436. nil)))
  5437. (defun org-agenda-get-deadlines ()
  5438. "Return the deadline information for agenda display."
  5439. (let* ((props (list 'mouse-face 'highlight
  5440. 'org-not-done-regexp org-not-done-regexp
  5441. 'org-todo-regexp org-todo-regexp
  5442. 'org-complex-heading-regexp org-complex-heading-regexp
  5443. 'help-echo
  5444. (format "mouse-2 or RET jump to org file %s"
  5445. (abbreviate-file-name buffer-file-name))))
  5446. (regexp org-deadline-time-regexp)
  5447. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5448. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5449. (dl0 (car org-agenda-deadline-leaders))
  5450. (dl1 (nth 1 org-agenda-deadline-leaders))
  5451. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5452. d2 diff dfrac wdays pos pos1 category category-pos level
  5453. tags suppress-prewarning ee txt head face s todo-state
  5454. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5455. (goto-char (point-min))
  5456. (while (re-search-forward regexp nil t)
  5457. (catch :skip
  5458. (org-agenda-skip)
  5459. (setq s (match-string 1)
  5460. txt nil
  5461. pos (1- (match-beginning 1))
  5462. todo-state (save-match-data (org-get-todo-state))
  5463. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5464. (member todo-state
  5465. org-agenda-repeating-timestamp-show-all))
  5466. d2 (org-time-string-to-absolute
  5467. s d1 'past show-all (current-buffer) pos)
  5468. diff (- d2 d1))
  5469. (setq suppress-prewarning
  5470. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5471. (let ((item (buffer-substring (point-at-bol)
  5472. (point-at-eol))))
  5473. (save-match-data
  5474. (and (string-match
  5475. org-scheduled-time-regexp item)
  5476. (match-string 1 item)))))))
  5477. (cond
  5478. ((not ds) nil)
  5479. ;; The current item has a scheduled date (in ds), so
  5480. ;; evaluate its prewarning lead time.
  5481. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5482. ;; Use global prewarning-restart lead time.
  5483. org-agenda-skip-deadline-prewarning-if-scheduled)
  5484. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5485. 'pre-scheduled)
  5486. ;; Set prewarning to no earlier than scheduled.
  5487. (min (- d2 (org-time-string-to-absolute
  5488. ds d1 'past show-all (current-buffer) pos))
  5489. org-deadline-warning-days))
  5490. ;; Set prewarning to deadline.
  5491. (t 0))))
  5492. (setq wdays (if suppress-prewarning
  5493. (let ((org-deadline-warning-days suppress-prewarning))
  5494. (org-get-wdays s))
  5495. (org-get-wdays s))
  5496. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5497. upcomingp (and todayp (> diff 0)))
  5498. ;; When to show a deadline in the calendar:
  5499. ;; If the expiration is within wdays warning time.
  5500. ;; Past-due deadlines are only shown on the current date
  5501. (if (and (or (and (<= diff wdays)
  5502. (and todayp (not org-agenda-only-exact-dates)))
  5503. (= diff 0)))
  5504. (save-excursion
  5505. ;; (setq todo-state (org-get-todo-state))
  5506. (setq donep (member todo-state org-done-keywords))
  5507. (if (and donep
  5508. (or org-agenda-skip-deadline-if-done
  5509. (not (= diff 0))))
  5510. (setq txt nil)
  5511. (setq category (org-get-category)
  5512. warntime (get-text-property (point) 'org-appt-warntime)
  5513. category-pos (get-text-property (point) 'org-category-position))
  5514. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5515. (throw :skip nil)
  5516. (goto-char (match-end 0))
  5517. (setq pos1 (match-beginning 0))
  5518. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5519. (setq inherited-tags
  5520. (or (eq org-agenda-show-inherited-tags 'always)
  5521. (and (listp org-agenda-show-inherited-tags)
  5522. (memq 'agenda org-agenda-show-inherited-tags))
  5523. (and (eq org-agenda-show-inherited-tags t)
  5524. (or (eq org-agenda-use-tag-inheritance t)
  5525. (memq 'agenda org-agenda-use-tag-inheritance))))
  5526. tags (org-get-tags-at pos1 (not inherited-tags)))
  5527. (setq head (buffer-substring
  5528. (point)
  5529. (progn (skip-chars-forward "^\r\n")
  5530. (point))))
  5531. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5532. (setq timestr
  5533. (concat (substring s (match-beginning 1)) " "))
  5534. (setq timestr 'time))
  5535. (setq txt (org-agenda-format-item
  5536. (cond ((= diff 0) dl0)
  5537. ((> diff 0)
  5538. (if (functionp dl1)
  5539. (funcall dl1 diff date)
  5540. (format dl1 diff)))
  5541. (t
  5542. (if (functionp dl2)
  5543. (funcall dl2 diff date)
  5544. (format dl2 (if (string= dl2 dl1)
  5545. diff (abs diff))))))
  5546. head level category tags
  5547. (if (not (= diff 0)) nil timestr)))))
  5548. (when txt
  5549. (setq face (org-agenda-deadline-face dfrac))
  5550. (org-add-props txt props
  5551. 'org-marker (org-agenda-new-marker pos)
  5552. 'warntime warntime
  5553. 'level level
  5554. 'ts-date d2
  5555. 'org-hd-marker (org-agenda-new-marker pos1)
  5556. 'priority (+ (- diff)
  5557. (org-get-priority txt))
  5558. 'org-category category
  5559. 'org-category-position category-pos
  5560. 'todo-state todo-state
  5561. 'type (if upcomingp "upcoming-deadline" "deadline")
  5562. 'date (if upcomingp date d2)
  5563. 'face (if donep 'org-agenda-done face)
  5564. 'undone-face face 'done-face 'org-agenda-done)
  5565. (push txt ee))))))
  5566. (nreverse ee)))
  5567. (defun org-agenda-deadline-face (fraction)
  5568. "Return the face to displaying a deadline item.
  5569. FRACTION is what fraction of the head-warning time has passed."
  5570. (let ((faces org-agenda-deadline-faces) f)
  5571. (catch 'exit
  5572. (while (setq f (pop faces))
  5573. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5574. (defun org-agenda-get-scheduled (&optional deadline-results)
  5575. "Return the scheduled information for agenda display."
  5576. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5577. 'org-todo-regexp org-todo-regexp
  5578. 'org-complex-heading-regexp org-complex-heading-regexp
  5579. 'done-face 'org-agenda-done
  5580. 'mouse-face 'highlight
  5581. 'help-echo
  5582. (format "mouse-2 or RET jump to org file %s"
  5583. (abbreviate-file-name buffer-file-name))))
  5584. (regexp org-scheduled-time-regexp)
  5585. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5586. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5587. mm
  5588. (deadline-position-alist
  5589. (mapcar (lambda (a) (and (setq mm (get-text-property
  5590. 0 'org-hd-marker a))
  5591. (cons (marker-position mm) a)))
  5592. deadline-results))
  5593. d2 diff pos pos1 category category-pos level tags donep
  5594. ee txt head pastschedp todo-state face timestr s habitp show-all
  5595. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5596. ddays)
  5597. (goto-char (point-min))
  5598. (while (re-search-forward regexp nil t)
  5599. (catch :skip
  5600. (org-agenda-skip)
  5601. (setq s (match-string 1)
  5602. txt nil
  5603. pos (1- (match-beginning 1))
  5604. todo-state (save-match-data (org-get-todo-state))
  5605. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5606. (member todo-state
  5607. org-agenda-repeating-timestamp-show-all))
  5608. d2 (org-time-string-to-absolute
  5609. s d1 'past show-all (current-buffer) pos)
  5610. diff (- d2 d1)
  5611. warntime (get-text-property (point) 'org-appt-warntime))
  5612. (setq pastschedp (and todayp (< diff 0)))
  5613. (setq did-habit-check-p nil)
  5614. (setq suppress-delay
  5615. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5616. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5617. (save-match-data
  5618. (and (string-match
  5619. org-deadline-time-regexp item)
  5620. (match-string 1 item)))))))
  5621. (cond
  5622. ((not ds) nil)
  5623. ;; The current item has a deadline date (in ds), so
  5624. ;; evaluate its delay time.
  5625. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5626. ;; Use global delay time.
  5627. (- org-agenda-skip-scheduled-delay-if-deadline))
  5628. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5629. 'post-deadline)
  5630. ;; Set delay to no later than deadline.
  5631. (min (- d2 (org-time-string-to-absolute
  5632. ds d1 'past show-all (current-buffer) pos))
  5633. org-scheduled-delay-days))
  5634. (t 0))))
  5635. (setq ddays (if suppress-delay
  5636. (let ((org-scheduled-delay-days suppress-delay))
  5637. (org-get-wdays s t t))
  5638. (org-get-wdays s t)))
  5639. ;; Use a delay of 0 when there is a repeater and the delay is
  5640. ;; of the form --3d
  5641. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5642. (< (org-time-string-to-absolute s)
  5643. (org-time-string-to-absolute
  5644. s d2 'past nil (current-buffer) pos)))
  5645. (setq ddays 0))
  5646. ;; When to show a scheduled item in the calendar:
  5647. ;; If it is on or past the date.
  5648. (when (or (and (> ddays 0) (= diff (- ddays)))
  5649. (and (zerop ddays) (= diff 0))
  5650. (and (< (+ diff ddays) 0)
  5651. (< (abs diff) org-scheduled-past-days)
  5652. (and todayp (not org-agenda-only-exact-dates)))
  5653. ;; org-is-habit-p uses org-entry-get, which is expansive
  5654. ;; so we go extra mile to only call it once
  5655. (and todayp
  5656. (boundp 'org-habit-show-all-today)
  5657. org-habit-show-all-today
  5658. (setq did-habit-check-p t)
  5659. (setq habitp (and (functionp 'org-is-habit-p)
  5660. (org-is-habit-p)))))
  5661. (save-excursion
  5662. (setq donep (member todo-state org-done-keywords))
  5663. (if (and donep
  5664. (or org-agenda-skip-scheduled-if-done
  5665. (not (= diff 0))
  5666. (and (functionp 'org-is-habit-p)
  5667. (org-is-habit-p))))
  5668. (setq txt nil)
  5669. (setq habitp (if did-habit-check-p habitp
  5670. (and (functionp 'org-is-habit-p)
  5671. (org-is-habit-p))))
  5672. (setq category (org-get-category)
  5673. category-pos (get-text-property (point) 'org-category-position))
  5674. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5675. (throw :skip nil)
  5676. (goto-char (match-end 0))
  5677. (setq pos1 (match-beginning 0))
  5678. (if habitp
  5679. (if (or (not org-habit-show-habits)
  5680. (and (not todayp)
  5681. (boundp 'org-habit-show-habits-only-for-today)
  5682. org-habit-show-habits-only-for-today))
  5683. (throw :skip nil))
  5684. (if (and
  5685. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5686. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5687. pastschedp))
  5688. (setq mm (assoc pos1 deadline-position-alist)))
  5689. (throw :skip nil)))
  5690. (setq inherited-tags
  5691. (or (eq org-agenda-show-inherited-tags 'always)
  5692. (and (listp org-agenda-show-inherited-tags)
  5693. (memq 'agenda org-agenda-show-inherited-tags))
  5694. (and (eq org-agenda-show-inherited-tags t)
  5695. (or (eq org-agenda-use-tag-inheritance t)
  5696. (memq 'agenda org-agenda-use-tag-inheritance))))
  5697. tags (org-get-tags-at nil (not inherited-tags)))
  5698. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5699. (setq head (buffer-substring
  5700. (point)
  5701. (progn (skip-chars-forward "^\r\n") (point))))
  5702. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5703. (setq timestr
  5704. (concat (substring s (match-beginning 1)) " "))
  5705. (setq timestr 'time))
  5706. (setq txt (org-agenda-format-item
  5707. (if (= diff 0)
  5708. (car org-agenda-scheduled-leaders)
  5709. (format (nth 1 org-agenda-scheduled-leaders)
  5710. (- 1 diff)))
  5711. head level category tags
  5712. (if (not (= diff 0)) nil timestr)
  5713. nil habitp))))
  5714. (when txt
  5715. (setq face
  5716. (cond
  5717. ((and (not habitp) pastschedp)
  5718. 'org-scheduled-previously)
  5719. (todayp 'org-scheduled-today)
  5720. (t 'org-scheduled))
  5721. habitp (and habitp (org-habit-parse-todo)))
  5722. (org-add-props txt props
  5723. 'undone-face face
  5724. 'face (if donep 'org-agenda-done face)
  5725. 'org-marker (org-agenda-new-marker pos)
  5726. 'org-hd-marker (org-agenda-new-marker pos1)
  5727. 'type (if pastschedp "past-scheduled" "scheduled")
  5728. 'date (if pastschedp d2 date)
  5729. 'ts-date d2
  5730. 'warntime warntime
  5731. 'level level
  5732. 'priority (if habitp
  5733. (org-habit-get-priority habitp)
  5734. (+ 94 (- 5 diff) (org-get-priority txt)))
  5735. 'org-category category
  5736. 'category-position category-pos
  5737. 'org-habit-p habitp
  5738. 'todo-state todo-state)
  5739. (push txt ee))))))
  5740. (nreverse ee)))
  5741. (defun org-agenda-get-blocks ()
  5742. "Return the date-range information for agenda display."
  5743. (let* ((props (list 'face nil
  5744. 'org-not-done-regexp org-not-done-regexp
  5745. 'org-todo-regexp org-todo-regexp
  5746. 'org-complex-heading-regexp org-complex-heading-regexp
  5747. 'mouse-face 'highlight
  5748. 'help-echo
  5749. (format "mouse-2 or RET jump to org file %s"
  5750. (abbreviate-file-name buffer-file-name))))
  5751. (regexp org-tr-regexp)
  5752. (d0 (calendar-absolute-from-gregorian date))
  5753. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5754. level todo-state tags pos head donep inherited-tags)
  5755. (goto-char (point-min))
  5756. (while (re-search-forward regexp nil t)
  5757. (catch :skip
  5758. (org-agenda-skip)
  5759. (setq pos (point))
  5760. (let ((start-time (match-string 1))
  5761. (end-time (match-string 2)))
  5762. (setq s1 (match-string 1)
  5763. s2 (match-string 2)
  5764. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5765. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5766. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5767. ;; Only allow days between the limits, because the normal
  5768. ;; date stamps will catch the limits.
  5769. (save-excursion
  5770. (setq todo-state (org-get-todo-state))
  5771. (setq donep (member todo-state org-done-keywords))
  5772. (if (and donep org-agenda-skip-timestamp-if-done)
  5773. (throw :skip t))
  5774. (setq marker (org-agenda-new-marker (point)))
  5775. (setq category (org-get-category)
  5776. category-pos (get-text-property (point) 'org-category-position))
  5777. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5778. (throw :skip nil)
  5779. (goto-char (match-beginning 0))
  5780. (setq hdmarker (org-agenda-new-marker (point))
  5781. inherited-tags
  5782. (or (eq org-agenda-show-inherited-tags 'always)
  5783. (and (listp org-agenda-show-inherited-tags)
  5784. (memq 'agenda org-agenda-show-inherited-tags))
  5785. (and (eq org-agenda-show-inherited-tags t)
  5786. (or (eq org-agenda-use-tag-inheritance t)
  5787. (memq 'agenda org-agenda-use-tag-inheritance))))
  5788. tags (org-get-tags-at nil (not inherited-tags)))
  5789. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5790. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5791. (setq head (match-string 1))
  5792. (let ((remove-re
  5793. (if org-agenda-remove-timeranges-from-blocks
  5794. (concat
  5795. "<" (regexp-quote s1) ".*?>"
  5796. "--"
  5797. "<" (regexp-quote s2) ".*?>")
  5798. nil)))
  5799. (setq txt (org-agenda-format-item
  5800. (format
  5801. (nth (if (= d1 d2) 0 1)
  5802. org-agenda-timerange-leaders)
  5803. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5804. head level category tags
  5805. (cond ((and (= d1 d0) (= d2 d0))
  5806. (concat "<" start-time ">--<" end-time ">"))
  5807. ((= d1 d0)
  5808. (concat "<" start-time ">"))
  5809. ((= d2 d0)
  5810. (concat "<" end-time ">")))
  5811. remove-re))))
  5812. (org-add-props txt props
  5813. 'org-marker marker 'org-hd-marker hdmarker
  5814. 'type "block" 'date date
  5815. 'level level
  5816. 'todo-state todo-state
  5817. 'priority (org-get-priority txt) 'org-category category
  5818. 'org-category-position category-pos)
  5819. (push txt ee))))
  5820. (goto-char pos)))
  5821. ;; Sort the entries by expiration date.
  5822. (nreverse ee)))
  5823. ;;; Agenda presentation and sorting
  5824. (defvar org-prefix-has-time nil
  5825. "A flag, set by `org-compile-prefix-format'.
  5826. The flag is set if the currently compiled format contains a `%t'.")
  5827. (defvar org-prefix-has-tag nil
  5828. "A flag, set by `org-compile-prefix-format'.
  5829. The flag is set if the currently compiled format contains a `%T'.")
  5830. (defvar org-prefix-has-effort nil
  5831. "A flag, set by `org-compile-prefix-format'.
  5832. The flag is set if the currently compiled format contains a `%e'.")
  5833. (defvar org-prefix-has-breadcrumbs nil
  5834. "A flag, set by `org-compile-prefix-format'.
  5835. The flag is set if the currently compiled format contains a `%b'.")
  5836. (defvar org-prefix-category-length nil
  5837. "Used by `org-compile-prefix-format' to remember the category field width.")
  5838. (defvar org-prefix-category-max-length nil
  5839. "Used by `org-compile-prefix-format' to remember the category field width.")
  5840. (defun org-agenda-get-category-icon (category)
  5841. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5842. (dolist (entry org-agenda-category-icon-alist)
  5843. (when (org-string-match-p (car entry) category)
  5844. (if (listp (cadr entry))
  5845. (return (cadr entry))
  5846. (return (apply 'create-image (cdr entry)))))))
  5847. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5848. remove-re habitp)
  5849. "Format TXT to be inserted into the agenda buffer.
  5850. In particular, add the prefix and corresponding text properties.
  5851. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5852. LEVEL may be a string to replace the `%l' specifier.
  5853. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5854. category taken from local variable or file name. It will replace the `%c'
  5855. specifier in the format.
  5856. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5857. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5858. When DOTIME is a string, this string is searched for a time before TXT is.
  5859. TAGS can be the tags of the headline.
  5860. Any match of REMOVE-RE will be removed from TXT."
  5861. ;; We keep the org-prefix-* variable values along with a compiled
  5862. ;; formatter, so that multiple agendas existing at the same time do
  5863. ;; not step on each other toes.
  5864. ;;
  5865. ;; It was inconvenient to make these variables buffer local in
  5866. ;; Agenda buffers, because this function expects to be called with
  5867. ;; the buffer where item comes from being current, and not agenda
  5868. ;; buffer
  5869. (let* ((bindings (car org-prefix-format-compiled))
  5870. (formatter (cadr org-prefix-format-compiled)))
  5871. (loop for (var value) in bindings
  5872. do (set var value))
  5873. (save-match-data
  5874. ;; Diary entries sometimes have extra whitespace at the beginning
  5875. (setq txt (org-trim txt))
  5876. ;; Fix the tags part in txt
  5877. (setq txt (org-agenda-fix-displayed-tags
  5878. txt tags
  5879. org-agenda-show-inherited-tags
  5880. org-agenda-hide-tags-regexp))
  5881. (let* ((category (or category
  5882. (if (stringp org-category)
  5883. org-category
  5884. (and org-category (symbol-name org-category)))
  5885. (if buffer-file-name
  5886. (file-name-sans-extension
  5887. (file-name-nondirectory buffer-file-name))
  5888. "")))
  5889. (category-icon (org-agenda-get-category-icon category))
  5890. (category-icon (if category-icon
  5891. (propertize " " 'display category-icon)
  5892. ""))
  5893. ;; time, tag, effort are needed for the eval of the prefix format
  5894. (tag (if tags (nth (1- (length tags)) tags) ""))
  5895. time effort neffort
  5896. (ts (if dotime (concat
  5897. (if (stringp dotime) dotime "")
  5898. (and org-agenda-search-headline-for-time txt))))
  5899. (time-of-day (and dotime (org-get-time-of-day ts)))
  5900. stamp plain s0 s1 s2 rtn srp l
  5901. duration thecategory breadcrumbs)
  5902. (and (derived-mode-p 'org-mode) buffer-file-name
  5903. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5904. (when (and dotime time-of-day)
  5905. ;; Extract starting and ending time and move them to prefix
  5906. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5907. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5908. (setq s0 (match-string 0 ts)
  5909. srp (and stamp (match-end 3))
  5910. s1 (match-string (if plain 1 2) ts)
  5911. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5912. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5913. ;; them, we might want to remove them there to avoid duplication.
  5914. ;; The user can turn this off with a variable.
  5915. (if (and org-prefix-has-time
  5916. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5917. (string-match (concat (regexp-quote s0) " *") txt)
  5918. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5919. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5920. (= (match-beginning 0) 0)
  5921. t))
  5922. (setq txt (replace-match "" nil nil txt))))
  5923. ;; Normalize the time(s) to 24 hour
  5924. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5925. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5926. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5927. (let (org-time-clocksum-use-effort-durations)
  5928. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5929. (setq s2
  5930. (org-minutes-to-clocksum-string
  5931. (+ (org-hh:mm-string-to-minutes s1)
  5932. org-agenda-default-appointment-duration)))))
  5933. ;; Compute the duration
  5934. (when s2
  5935. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5936. (org-hh:mm-string-to-minutes s1)))))
  5937. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5938. txt)
  5939. ;; Tags are in the string
  5940. (if (or (eq org-agenda-remove-tags t)
  5941. (and org-agenda-remove-tags
  5942. org-prefix-has-tag))
  5943. (setq txt (replace-match "" t t txt))
  5944. (setq txt (replace-match
  5945. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5946. (match-string 2 txt))
  5947. t t txt))))
  5948. (when (derived-mode-p 'org-mode)
  5949. (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
  5950. (if effort
  5951. (setq neffort (org-duration-string-to-minutes effort)
  5952. effort (setq effort (concat "[" effort "]")))
  5953. ;; prevent erroring out with %e format when there is no effort
  5954. (setq effort "")))
  5955. (when remove-re
  5956. (while (string-match remove-re txt)
  5957. (setq txt (replace-match "" t t txt))))
  5958. ;; Set org-heading property on `txt' to mark the start of the
  5959. ;; heading.
  5960. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5961. ;; Prepare the variables needed in the eval of the compiled format
  5962. (if org-prefix-has-breadcrumbs
  5963. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  5964. (let ((s (org-display-outline-path nil nil "->" t)))
  5965. (if (eq "" s) "" (concat s "->"))))))
  5966. (setq time (cond (s2 (concat
  5967. (org-agenda-time-of-day-to-ampm-maybe s1)
  5968. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5969. (if org-agenda-timegrid-use-ampm " ")))
  5970. (s1 (concat
  5971. (org-agenda-time-of-day-to-ampm-maybe s1)
  5972. (if org-agenda-timegrid-use-ampm
  5973. "........ "
  5974. "......")))
  5975. (t ""))
  5976. extra (or (and (not habitp) extra) "")
  5977. category (if (symbolp category) (symbol-name category) category)
  5978. thecategory (copy-sequence category)
  5979. level (or level ""))
  5980. (if (string-match org-bracket-link-regexp category)
  5981. (progn
  5982. (setq l (if (match-end 3)
  5983. (- (match-end 3) (match-beginning 3))
  5984. (- (match-end 1) (match-beginning 1))))
  5985. (when (< l (or org-prefix-category-length 0))
  5986. (setq category (copy-sequence category))
  5987. (org-add-props category nil
  5988. 'extra-space (make-string
  5989. (- org-prefix-category-length l 1) ?\ ))))
  5990. (if (and org-prefix-category-max-length
  5991. (>= (length category) org-prefix-category-max-length))
  5992. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5993. ;; Evaluate the compiled format
  5994. (setq rtn (concat (eval formatter) txt))
  5995. ;; And finally add the text properties
  5996. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5997. (org-add-props rtn nil
  5998. 'org-category (if thecategory (downcase thecategory) category)
  5999. 'tags (mapcar 'org-downcase-keep-props tags)
  6000. 'org-highest-priority org-highest-priority
  6001. 'org-lowest-priority org-lowest-priority
  6002. 'time-of-day time-of-day
  6003. 'duration duration
  6004. 'effort effort
  6005. 'effort-minutes neffort
  6006. 'breadcrumbs breadcrumbs
  6007. 'txt txt
  6008. 'level level
  6009. 'time time
  6010. 'extra extra
  6011. 'format org-prefix-format-compiled
  6012. 'dotime dotime)))))
  6013. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6014. "Remove tags string from TXT, and add a modified list of tags.
  6015. The modified list may contain inherited tags, and tags matched by
  6016. `org-agenda-hide-tags-regexp' will be removed."
  6017. (when (or add-inherited hide-re)
  6018. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6019. (setq txt (substring txt 0 (match-beginning 0))))
  6020. (setq tags
  6021. (delq nil
  6022. (mapcar (lambda (tg)
  6023. (if (or (and hide-re (string-match hide-re tg))
  6024. (and (not add-inherited)
  6025. (get-text-property 0 'inherited tg)))
  6026. nil
  6027. tg))
  6028. tags)))
  6029. (when tags
  6030. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6031. i)
  6032. (setq txt (concat txt " :"
  6033. (mapconcat
  6034. (lambda (x)
  6035. (setq i (get-text-property 0 'inherited x))
  6036. (if (and have-i (not i))
  6037. (progn
  6038. (setq have-i nil)
  6039. (concat ":" x))
  6040. x))
  6041. tags ":")
  6042. (if have-i "::" ":"))))))
  6043. txt)
  6044. (defun org-downcase-keep-props (s)
  6045. (let ((props (text-properties-at 0 s)))
  6046. (setq s (downcase s))
  6047. (add-text-properties 0 (length s) props s)
  6048. s))
  6049. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6050. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6051. "Add a time-grid for agenda items which need it.
  6052. LIST is the list of agenda items formatted by `org-agenda-list'.
  6053. NDAYS is the span of the current agenda view.
  6054. TODAYP is `t' when the current agenda view is on today."
  6055. (catch 'exit
  6056. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6057. ((and todayp (member 'today (car org-agenda-time-grid))))
  6058. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6059. ((member 'weekly (car org-agenda-time-grid)))
  6060. (t (throw 'exit list)))
  6061. (let* ((have (delq nil (mapcar
  6062. (lambda (x) (get-text-property 1 'time-of-day x))
  6063. list)))
  6064. (string (nth 1 org-agenda-time-grid))
  6065. (gridtimes (nth 2 org-agenda-time-grid))
  6066. (req (car org-agenda-time-grid))
  6067. (remove (member 'remove-match req))
  6068. new time)
  6069. (if (and (member 'require-timed req) (not have))
  6070. ;; don't show empty grid
  6071. (throw 'exit list))
  6072. (while (setq time (pop gridtimes))
  6073. (unless (and remove (member time have))
  6074. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6075. (push (org-agenda-format-item
  6076. nil string nil "" nil
  6077. (concat (substring time 0 -2) ":" (substring time -2)))
  6078. new)
  6079. (put-text-property
  6080. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6081. (when (and todayp org-agenda-show-current-time-in-grid)
  6082. (push (org-agenda-format-item
  6083. nil org-agenda-current-time-string nil "" nil
  6084. (format-time-string "%H:%M "))
  6085. new)
  6086. (put-text-property
  6087. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6088. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6089. (append new list)
  6090. (append list new)))))
  6091. (defun org-compile-prefix-format (key)
  6092. "Compile the prefix format into a Lisp form that can be evaluated.
  6093. The resulting form and associated variable bindings is returned
  6094. and stored in the variable `org-prefix-format-compiled'."
  6095. (setq org-prefix-has-time nil
  6096. org-prefix-has-tag nil
  6097. org-prefix-category-length nil
  6098. org-prefix-has-effort nil
  6099. org-prefix-has-breadcrumbs nil)
  6100. (let ((s (cond
  6101. ((stringp org-agenda-prefix-format)
  6102. org-agenda-prefix-format)
  6103. ((assq key org-agenda-prefix-format)
  6104. (cdr (assq key org-agenda-prefix-format)))
  6105. (t " %-12:c%?-12t% s")))
  6106. (start 0)
  6107. varform vars var e c f opt)
  6108. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6109. s start)
  6110. (setq var (or (cdr (assoc (match-string 4 s)
  6111. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6112. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6113. 'eval)
  6114. c (or (match-string 3 s) "")
  6115. opt (match-beginning 1)
  6116. start (1+ (match-beginning 0)))
  6117. (if (equal var 'time) (setq org-prefix-has-time t))
  6118. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6119. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6120. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6121. (setq f (concat "%" (match-string 2 s) "s"))
  6122. (when (equal var 'category)
  6123. (setq org-prefix-category-length
  6124. (floor (abs (string-to-number (match-string 2 s)))))
  6125. (setq org-prefix-category-max-length
  6126. (let ((x (match-string 2 s)))
  6127. (save-match-data
  6128. (if (string-match "\\.[0-9]+" x)
  6129. (string-to-number (substring (match-string 0 x) 1)))))))
  6130. (if (eq var 'eval)
  6131. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6132. (if opt
  6133. (setq varform
  6134. `(if (equal "" ,var)
  6135. ""
  6136. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6137. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6138. (setq s (replace-match "%s" t nil s))
  6139. (push varform vars))
  6140. (setq vars (nreverse vars))
  6141. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6142. (setq org-prefix-format-compiled
  6143. (list
  6144. `((org-prefix-has-time ,org-prefix-has-time)
  6145. (org-prefix-has-tag ,org-prefix-has-tag)
  6146. (org-prefix-category-length ,org-prefix-category-length)
  6147. (org-prefix-has-effort ,org-prefix-has-effort)
  6148. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6149. `(format ,s ,@vars))))))
  6150. (defun org-set-sorting-strategy (key)
  6151. (if (symbolp (car org-agenda-sorting-strategy))
  6152. ;; the old format
  6153. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6154. (setq org-agenda-sorting-strategy-selected
  6155. (or (cdr (assq key org-agenda-sorting-strategy))
  6156. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6157. '(time-up category-keep priority-down)))))
  6158. (defun org-get-time-of-day (s &optional string mod24)
  6159. "Check string S for a time of day.
  6160. If found, return it as a military time number between 0 and 2400.
  6161. If not found, return nil.
  6162. The optional STRING argument forces conversion into a 5 character wide string
  6163. HH:MM."
  6164. (save-match-data
  6165. (when
  6166. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6167. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6168. (let* ((h (string-to-number (match-string 1 s)))
  6169. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6170. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6171. (am-p (equal ampm "am"))
  6172. (h1 (cond ((not ampm) h)
  6173. ((= h 12) (if am-p 0 12))
  6174. (t (+ h (if am-p 0 12)))))
  6175. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6176. (mod h1 24) h1))
  6177. (t0 (+ (* 100 h2) m))
  6178. (t1 (concat (if (>= h1 24) "+" " ")
  6179. (if (and org-agenda-time-leading-zero
  6180. (< t0 1000)) "0" "")
  6181. (if (< t0 100) "0" "")
  6182. (if (< t0 10) "0" "")
  6183. (int-to-string t0))))
  6184. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6185. (defvar org-agenda-before-sorting-filter-function nil
  6186. "Function to be applied to agenda items prior to sorting.
  6187. Prior to sorting also means just before they are inserted into the agenda.
  6188. To aid sorting, you may revisit the original entries and add more text
  6189. properties which will later be used by the sorting functions.
  6190. The function should take a string argument, an agenda line.
  6191. It has access to the text properties in that line, which contain among
  6192. other things, the property `org-hd-marker' that points to the entry
  6193. where the line comes from. Note that not all lines going into the agenda
  6194. have this property, only most.
  6195. The function should return the modified string. It is probably best
  6196. to ONLY change text properties.
  6197. You can also use this function as a filter, by returning nil for lines
  6198. you don't want to have in the agenda at all. For this application, you
  6199. could bind the variable in the options section of a custom command.")
  6200. (defun org-agenda-finalize-entries (list &optional type)
  6201. "Sort, limit and concatenate the LIST of agenda items.
  6202. The optional argument TYPE tells the agenda type."
  6203. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6204. (cdr (assoc type org-agenda-max-effort)))
  6205. (t org-agenda-max-effort)))
  6206. (max-todo (cond ((listp org-agenda-max-todos)
  6207. (cdr (assoc type org-agenda-max-todos)))
  6208. (t org-agenda-max-todos)))
  6209. (max-tags (cond ((listp org-agenda-max-tags)
  6210. (cdr (assoc type org-agenda-max-tags)))
  6211. (t org-agenda-max-tags)))
  6212. (max-entries (cond ((listp org-agenda-max-entries)
  6213. (cdr (assoc type org-agenda-max-entries)))
  6214. (t org-agenda-max-entries))) l)
  6215. (when org-agenda-before-sorting-filter-function
  6216. (setq list
  6217. (delq nil
  6218. (mapcar
  6219. org-agenda-before-sorting-filter-function list))))
  6220. (setq list (mapcar 'org-agenda-highlight-todo list)
  6221. list (mapcar 'identity (sort list 'org-entries-lessp))
  6222. list (org-agenda-limit-entries
  6223. list 'effort-minutes max-effort 'identity)
  6224. list (org-agenda-limit-entries list 'todo-state max-todo)
  6225. list (org-agenda-limit-entries list 'tags max-tags)
  6226. list (org-agenda-limit-entries list 'org-hd-marker max-entries)
  6227. list (mapconcat 'identity list "\n"))))
  6228. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6229. "Limit the number of agenda entries."
  6230. (if limit
  6231. (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
  6232. (delq nil
  6233. (mapcar
  6234. (lambda (e)
  6235. (let ((pval (funcall f (get-text-property 1 prop e))))
  6236. (if pval (setq lim (+ lim pval)))
  6237. (if (or (not pval) (<= lim limit)) e)))
  6238. list)))
  6239. list))
  6240. (defun org-agenda-highlight-todo (x)
  6241. (let ((org-done-keywords org-done-keywords-for-agenda)
  6242. (case-fold-search nil)
  6243. re)
  6244. (if (eq x 'line)
  6245. (save-excursion
  6246. (beginning-of-line 1)
  6247. (setq re (org-get-at-bol 'org-todo-regexp))
  6248. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6249. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6250. (add-text-properties (match-beginning 0) (match-end 1)
  6251. (list 'face (org-get-todo-face 1)))
  6252. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6253. (delete-region (match-beginning 1) (1- (match-end 0)))
  6254. (goto-char (match-beginning 1))
  6255. (insert (format org-agenda-todo-keyword-format s)))))
  6256. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6257. (setq re (get-text-property 0 'org-todo-regexp x))
  6258. (when (and re
  6259. ;; Test `pl' because if there's no heading content,
  6260. ;; there's no point matching to highlight. Note
  6261. ;; that if we didn't test `pl' first, and there
  6262. ;; happened to be no keyword from `org-todo-regexp'
  6263. ;; on this heading line, then the `equal' comparison
  6264. ;; afterwards would spuriously succeed in the case
  6265. ;; where `pl' is nil -- causing an args-out-of-range
  6266. ;; error when we try to add text properties to text
  6267. ;; that isn't there.
  6268. pl
  6269. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6270. x pl) pl))
  6271. (add-text-properties
  6272. (or (match-end 1) (match-end 0)) (match-end 0)
  6273. (list 'face (org-get-todo-face (match-string 2 x)))
  6274. x)
  6275. (when (match-end 1)
  6276. (setq x (concat (substring x 0 (match-end 1))
  6277. (format org-agenda-todo-keyword-format
  6278. (match-string 2 x))
  6279. (org-add-props " " (text-properties-at 0 x))
  6280. (substring x (match-end 3)))))))
  6281. x)))
  6282. (defsubst org-cmp-priority (a b)
  6283. "Compare the priorities of string A and B."
  6284. (let ((pa (or (get-text-property 1 'priority a) 0))
  6285. (pb (or (get-text-property 1 'priority b) 0)))
  6286. (cond ((> pa pb) +1)
  6287. ((< pa pb) -1))))
  6288. (defsubst org-cmp-effort (a b)
  6289. "Compare the effort values of string A and B."
  6290. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6291. (ea (or (get-text-property 1 'effort-minutes a) def))
  6292. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6293. (cond ((> ea eb) +1)
  6294. ((< ea eb) -1))))
  6295. (defsubst org-cmp-category (a b)
  6296. "Compare the string values of categories of strings A and B."
  6297. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6298. (cb (or (get-text-property 1 'org-category b) "")))
  6299. (cond ((string-lessp ca cb) -1)
  6300. ((string-lessp cb ca) +1))))
  6301. (defsubst org-cmp-todo-state (a b)
  6302. "Compare the todo states of strings A and B."
  6303. (let* ((ma (or (get-text-property 1 'org-marker a)
  6304. (get-text-property 1 'org-hd-marker a)))
  6305. (mb (or (get-text-property 1 'org-marker b)
  6306. (get-text-property 1 'org-hd-marker b)))
  6307. (fa (and ma (marker-buffer ma)))
  6308. (fb (and mb (marker-buffer mb)))
  6309. (todo-kwds
  6310. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6311. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6312. (ta (or (get-text-property 1 'todo-state a) ""))
  6313. (tb (or (get-text-property 1 'todo-state b) ""))
  6314. (la (- (length (member ta todo-kwds))))
  6315. (lb (- (length (member tb todo-kwds))))
  6316. (donepa (member ta org-done-keywords-for-agenda))
  6317. (donepb (member tb org-done-keywords-for-agenda)))
  6318. (cond ((and donepa (not donepb)) -1)
  6319. ((and (not donepa) donepb) +1)
  6320. ((< la lb) -1)
  6321. ((< lb la) +1))))
  6322. (defsubst org-cmp-alpha (a b)
  6323. "Compare the headlines, alphabetically."
  6324. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6325. (plb (text-property-any 0 (length b) 'org-heading t b))
  6326. (ta (and pla (substring a pla)))
  6327. (tb (and plb (substring b plb))))
  6328. (when pla
  6329. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6330. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6331. (setq ta (substring ta (match-end 0))))
  6332. (setq ta (downcase ta)))
  6333. (when plb
  6334. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6335. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6336. (setq tb (substring tb (match-end 0))))
  6337. (setq tb (downcase tb)))
  6338. (cond ((not ta) +1)
  6339. ((not tb) -1)
  6340. ((string-lessp ta tb) -1)
  6341. ((string-lessp tb ta) +1))))
  6342. (defsubst org-cmp-tag (a b)
  6343. "Compare the string values of the first tags of A and B."
  6344. (let ((ta (car (last (get-text-property 1 'tags a))))
  6345. (tb (car (last (get-text-property 1 'tags b)))))
  6346. (cond ((not ta) +1)
  6347. ((not tb) -1)
  6348. ((string-lessp ta tb) -1)
  6349. ((string-lessp tb ta) +1))))
  6350. (defsubst org-cmp-time (a b)
  6351. "Compare the time-of-day values of strings A and B."
  6352. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6353. (ta (or (get-text-property 1 'time-of-day a) def))
  6354. (tb (or (get-text-property 1 'time-of-day b) def)))
  6355. (cond ((< ta tb) -1)
  6356. ((< tb ta) +1))))
  6357. (defsubst org-cmp-ts (a b &optional type)
  6358. "Compare the timestamps values of entries A and B.
  6359. When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
  6360. or \"timestamp_ia\", compare within each of these type.
  6361. When TYPE is the empty string, compare all timestamps
  6362. without respect of their type."
  6363. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6364. (ta (or (and (string-match type (get-text-property 1 'type a))
  6365. (get-text-property 1 'ts-date a)) def))
  6366. (tb (or (and (string-match type (get-text-property 1 'type b))
  6367. (get-text-property 1 'ts-date b)) def)))
  6368. (cond ((< ta tb) -1)
  6369. ((< tb ta) +1))))
  6370. (defsubst org-cmp-habit-p (a b)
  6371. "Compare the todo states of strings A and B."
  6372. (let ((ha (get-text-property 1 'org-habit-p a))
  6373. (hb (get-text-property 1 'org-habit-p b)))
  6374. (cond ((and ha (not hb)) -1)
  6375. ((and (not ha) hb) +1))))
  6376. (defun org-entries-lessp (a b)
  6377. "Predicate for sorting agenda entries."
  6378. ;; The following variables will be used when the form is evaluated.
  6379. ;; So even though the compiler complains, keep them.
  6380. (let* ((ss org-agenda-sorting-strategy-selected)
  6381. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6382. (org-cmp-ts a b "")))
  6383. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6384. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6385. (org-cmp-ts a b "scheduled")))
  6386. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6387. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6388. (org-cmp-ts a b "deadline")))
  6389. (deadline-down (if deadline-up (- deadline-up) nil))
  6390. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6391. (org-cmp-ts a b "iatimestamp_ia")))
  6392. (tsia-down (if tsia-up (- tsia-up) nil))
  6393. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6394. (org-cmp-ts a b "timestamp")))
  6395. (ts-down (if ts-up (- ts-up) nil))
  6396. (time-up (and (org-em 'time-up 'time-down ss)
  6397. (org-cmp-time a b)))
  6398. (time-down (if time-up (- time-up) nil))
  6399. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6400. (org-cmp-priority a b)))
  6401. (priority-down (if priority-up (- priority-up) nil))
  6402. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6403. (org-cmp-effort a b)))
  6404. (effort-down (if effort-up (- effort-up) nil))
  6405. (category-up (and (or (org-em 'category-up 'category-down ss)
  6406. (memq 'category-keep ss))
  6407. (org-cmp-category a b)))
  6408. (category-down (if category-up (- category-up) nil))
  6409. (category-keep (if category-up +1 nil))
  6410. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6411. (org-cmp-tag a b)))
  6412. (tag-down (if tag-up (- tag-up) nil))
  6413. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6414. (org-cmp-todo-state a b)))
  6415. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6416. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6417. (org-cmp-habit-p a b)))
  6418. (habit-down (if habit-up (- habit-up) nil))
  6419. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6420. (org-cmp-alpha a b)))
  6421. (alpha-down (if alpha-up (- alpha-up) nil))
  6422. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6423. user-defined-up user-defined-down)
  6424. (if (and need-user-cmp org-agenda-cmp-user-defined
  6425. (functionp org-agenda-cmp-user-defined))
  6426. (setq user-defined-up
  6427. (funcall org-agenda-cmp-user-defined a b)
  6428. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6429. (cdr (assoc
  6430. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6431. '((-1 . t) (1 . nil) (nil . nil))))))
  6432. ;;; Agenda restriction lock
  6433. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6434. "Overlay to mark the headline to which agenda commands are restricted.")
  6435. (overlay-put org-agenda-restriction-lock-overlay
  6436. 'face 'org-agenda-restriction-lock)
  6437. (overlay-put org-agenda-restriction-lock-overlay
  6438. 'help-echo "Agendas are currently limited to this subtree.")
  6439. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6440. (defun org-agenda-set-restriction-lock (&optional type)
  6441. "Set restriction lock for agenda, to current subtree or file.
  6442. Restriction will be the file if TYPE is `file', or if type is the
  6443. universal prefix '(4), or if the cursor is before the first headline
  6444. in the file. Otherwise, restriction will be to the current subtree."
  6445. (interactive "P")
  6446. (and (equal type '(4)) (setq type 'file))
  6447. (setq type (cond
  6448. (type type)
  6449. ((org-at-heading-p) 'subtree)
  6450. ((condition-case nil (org-back-to-heading t) (error nil))
  6451. 'subtree)
  6452. (t 'file)))
  6453. (if (eq type 'subtree)
  6454. (progn
  6455. (setq org-agenda-restrict t)
  6456. (setq org-agenda-overriding-restriction 'subtree)
  6457. (put 'org-agenda-files 'org-restrict
  6458. (list (buffer-file-name (buffer-base-buffer))))
  6459. (org-back-to-heading t)
  6460. (move-overlay org-agenda-restriction-lock-overlay
  6461. (point) (save-excursion (org-end-of-subtree t t) (point)))
  6462. (move-marker org-agenda-restrict-begin (point))
  6463. (move-marker org-agenda-restrict-end
  6464. (save-excursion (org-end-of-subtree t t)))
  6465. (message "Locking agenda restriction to subtree"))
  6466. (put 'org-agenda-files 'org-restrict
  6467. (list (buffer-file-name (buffer-base-buffer))))
  6468. (setq org-agenda-restrict nil)
  6469. (setq org-agenda-overriding-restriction 'file)
  6470. (move-marker org-agenda-restrict-begin nil)
  6471. (move-marker org-agenda-restrict-end nil)
  6472. (message "Locking agenda restriction to file"))
  6473. (setq current-prefix-arg nil)
  6474. (org-agenda-maybe-redo))
  6475. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6476. "Remove the agenda restriction lock."
  6477. (interactive "P")
  6478. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6479. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6480. (setq org-agenda-overriding-restriction nil)
  6481. (setq org-agenda-restrict nil)
  6482. (put 'org-agenda-files 'org-restrict nil)
  6483. (move-marker org-agenda-restrict-begin nil)
  6484. (move-marker org-agenda-restrict-end nil)
  6485. (setq current-prefix-arg nil)
  6486. (message "Agenda restriction lock removed")
  6487. (or noupdate (org-agenda-maybe-redo)))
  6488. (defun org-agenda-maybe-redo ()
  6489. "If there is any window showing the agenda view, update it."
  6490. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6491. (w0 (selected-window)))
  6492. (when w
  6493. (select-window w)
  6494. (org-agenda-redo)
  6495. (select-window w0)
  6496. (if org-agenda-overriding-restriction
  6497. (message "Agenda view shifted to new %s restriction"
  6498. org-agenda-overriding-restriction)
  6499. (message "Agenda restriction lock removed")))))
  6500. ;;; Agenda commands
  6501. (defun org-agenda-check-type (error &rest types)
  6502. "Check if agenda buffer is of allowed type.
  6503. If ERROR is non-nil, throw an error, otherwise just return nil.
  6504. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6505. (if (not org-agenda-type)
  6506. (error "No Org agenda currently displayed")
  6507. (if (memq org-agenda-type types)
  6508. t
  6509. (if error
  6510. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6511. nil))))
  6512. (defun org-agenda-Quit ()
  6513. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6514. Also restore the window configuration."
  6515. (interactive)
  6516. (if org-agenda-columns-active
  6517. (org-columns-quit)
  6518. (let ((buf (current-buffer)))
  6519. (if (eq org-agenda-window-setup 'other-frame)
  6520. (progn
  6521. (org-agenda-reset-markers)
  6522. (kill-buffer buf)
  6523. (org-columns-remove-overlays)
  6524. (setq org-agenda-archives-mode nil)
  6525. (delete-frame))
  6526. (and (not (eq org-agenda-window-setup 'current-window))
  6527. (not (one-window-p))
  6528. (delete-window))
  6529. (org-agenda-reset-markers)
  6530. (kill-buffer buf)
  6531. (org-columns-remove-overlays)
  6532. (setq org-agenda-archives-mode nil)))
  6533. ;; Maybe restore the pre-agenda window configuration.
  6534. (and org-agenda-restore-windows-after-quit
  6535. (not (eq org-agenda-window-setup 'other-frame))
  6536. org-agenda-pre-window-conf
  6537. (set-window-configuration org-agenda-pre-window-conf)
  6538. (setq org-agenda-pre-window-conf nil))))
  6539. (defun org-agenda-quit ()
  6540. "Exit the agenda and restore the window configuration.
  6541. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6542. (interactive)
  6543. (if (and (eq org-indirect-buffer-display 'other-window)
  6544. org-last-indirect-buffer)
  6545. (let ((org-last-indirect-window
  6546. (get-buffer-window org-last-indirect-buffer)))
  6547. (if org-last-indirect-window
  6548. (delete-window org-last-indirect-window))))
  6549. (if org-agenda-columns-active
  6550. (org-columns-quit)
  6551. (if org-agenda-sticky
  6552. (let ((buf (current-buffer)))
  6553. (if (eq org-agenda-window-setup 'other-frame)
  6554. (progn
  6555. (delete-frame))
  6556. (and (not (eq org-agenda-window-setup 'current-window))
  6557. (not (one-window-p))
  6558. (delete-window)))
  6559. (with-current-buffer buf
  6560. (bury-buffer)
  6561. ;; Maybe restore the pre-agenda window configuration.
  6562. (and org-agenda-restore-windows-after-quit
  6563. (not (eq org-agenda-window-setup 'other-frame))
  6564. org-agenda-pre-window-conf
  6565. (set-window-configuration org-agenda-pre-window-conf)
  6566. (setq org-agenda-pre-window-conf nil))))
  6567. (org-agenda-Quit))))
  6568. (defun org-agenda-exit ()
  6569. "Exit the agenda and restore the window configuration.
  6570. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6571. buffers visited directly by the user will not be touched."
  6572. (interactive)
  6573. (org-release-buffers org-agenda-new-buffers)
  6574. (setq org-agenda-new-buffers nil)
  6575. (org-agenda-Quit))
  6576. (defun org-agenda-kill-all-agenda-buffers ()
  6577. "Kill all buffers in `org-agenda-mode'.
  6578. This is used when toggling sticky agendas.
  6579. You can also explicitly invoke it with `C-c a C-k'."
  6580. (interactive)
  6581. (let (blist)
  6582. (dolist (buf (buffer-list))
  6583. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6584. (push buf blist)))
  6585. (mapc 'kill-buffer blist)))
  6586. (defun org-agenda-execute (arg)
  6587. "Execute another agenda command, keeping same window.
  6588. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6589. in the agenda."
  6590. (interactive "P")
  6591. (let ((org-agenda-window-setup 'current-window))
  6592. (org-agenda arg)))
  6593. (defun org-agenda-redo (&optional all)
  6594. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6595. (interactive "P")
  6596. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6597. (cpa (unless (eq all t) current-prefix-arg))
  6598. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6599. (org-agenda-sticky nil)
  6600. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6601. org-agenda-buffer-name))
  6602. (org-agenda-keep-modes t)
  6603. (tag-filter org-agenda-tag-filter)
  6604. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6605. (top-cat-filter org-agenda-top-category-filter)
  6606. (cat-filter org-agenda-category-filter)
  6607. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6608. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6609. (cols org-agenda-columns-active)
  6610. (line (org-current-line))
  6611. (window-line (- line (org-current-line (window-start))))
  6612. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6613. (redo-cmd (get-text-property p 'org-redo-cmd))
  6614. (last-args (get-text-property p 'org-last-args))
  6615. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6616. (org-agenda-overriding-cmd-arguments
  6617. (unless (eq all t)
  6618. (cond ((listp last-args)
  6619. (cons (or cpa (car last-args)) (cdr last-args)))
  6620. ((stringp last-args)
  6621. last-args))))
  6622. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6623. (put 'org-agenda-tag-filter :preset-filter nil)
  6624. (put 'org-agenda-category-filter :preset-filter nil)
  6625. (and cols (org-columns-quit))
  6626. (message "Rebuilding agenda buffer...")
  6627. (if series-redo-cmd
  6628. (eval series-redo-cmd)
  6629. (org-let lprops '(eval redo-cmd)))
  6630. (setq org-agenda-undo-list nil
  6631. org-agenda-pending-undo-list nil)
  6632. (message "Rebuilding agenda buffer...done")
  6633. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6634. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6635. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6636. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6637. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6638. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6639. (org-goto-line line)
  6640. (recenter window-line)))
  6641. (defvar org-global-tags-completion-table nil)
  6642. (defvar org-agenda-filter-form nil)
  6643. (defvar org-agenda-filtered-by-category nil)
  6644. (defun org-agenda-filter-by-category (strip)
  6645. "Keep only those lines in the agenda buffer that have a specific category.
  6646. The category is that of the current line."
  6647. (interactive "P")
  6648. (if (and org-agenda-filtered-by-category
  6649. org-agenda-category-filter)
  6650. (org-agenda-filter-show-all-cat)
  6651. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6652. (if cat (org-agenda-filter-apply
  6653. (list (concat (if strip "-" "+") cat)) 'category)
  6654. (error "No category at point")))))
  6655. (defun org-find-top-category (&optional pos)
  6656. (save-excursion
  6657. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6658. (if pos (goto-char pos))
  6659. ;; Skip up to the topmost parent
  6660. (while (ignore-errors (outline-up-heading 1) t))
  6661. (ignore-errors
  6662. (nth 4 (org-heading-components))))))
  6663. (defvar org-agenda-filtered-by-top-category nil)
  6664. (defun org-agenda-filter-by-top-category (strip)
  6665. "Keep only those lines in the agenda buffer that have a specific category.
  6666. The category is that of the current line."
  6667. (interactive "P")
  6668. (if org-agenda-filtered-by-top-category
  6669. (progn
  6670. (setq org-agenda-filtered-by-top-category nil
  6671. org-agenda-top-category-filter nil)
  6672. (org-agenda-filter-show-all-cat))
  6673. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6674. (if cat (org-agenda-filter-top-category-apply cat strip)
  6675. (error "No top-level category at point")))))
  6676. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6677. "Keep only those lines in the agenda buffer that have a specific tag.
  6678. The tag is selected with its fast selection letter, as configured.
  6679. With prefix argument STRIP, remove all lines that do have the tag.
  6680. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6681. used to narrow the search - the interactive user can also press `-' or `+'
  6682. to switch to narrowing."
  6683. (interactive "P")
  6684. (let* ((alist org-tag-alist-for-agenda)
  6685. (tag-chars (mapconcat
  6686. (lambda (x) (if (and (not (symbolp (car x)))
  6687. (cdr x))
  6688. (char-to-string (cdr x))
  6689. ""))
  6690. alist ""))
  6691. (efforts (org-split-string
  6692. (or (cdr (assoc (concat org-effort-property "_ALL")
  6693. org-global-properties))
  6694. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6695. "")))
  6696. (effort-op org-agenda-filter-effort-default-operator)
  6697. (effort-prompt "")
  6698. (inhibit-read-only t)
  6699. (current org-agenda-tag-filter)
  6700. maybe-refresh a n tag)
  6701. (unless char
  6702. (message
  6703. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6704. (if narrow "Narrow" "Filter") tag-chars
  6705. (if org-agenda-auto-exclude-function "[RET], " ""))
  6706. (setq char (read-char-exclusive)))
  6707. (when (member char '(?+ ?-))
  6708. ;; Narrowing down
  6709. (cond ((equal char ?-) (setq strip t narrow t))
  6710. ((equal char ?+) (setq strip nil narrow t)))
  6711. (message
  6712. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6713. (setq char (read-char-exclusive)))
  6714. (when (member char '(?< ?> ?= ??))
  6715. ;; An effort operator
  6716. (setq effort-op (char-to-string char))
  6717. (setq alist nil) ; to make sure it will be interpreted as effort.
  6718. (unless (equal char ??)
  6719. (loop for i from 0 to 9 do
  6720. (setq effort-prompt
  6721. (concat
  6722. effort-prompt " ["
  6723. (if (= i 9) "0" (int-to-string (1+ i)))
  6724. "]" (nth i efforts))))
  6725. (message "Effort%s: %s " effort-op effort-prompt)
  6726. (setq char (read-char-exclusive))
  6727. (when (or (< char ?0) (> char ?9))
  6728. (error "Need 1-9,0 to select effort"))))
  6729. (when (equal char ?\t)
  6730. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6731. (org-set-local 'org-global-tags-completion-table
  6732. (org-global-tags-completion-table)))
  6733. (let ((completion-ignore-case t))
  6734. (setq tag (org-icompleting-read
  6735. "Tag: " org-global-tags-completion-table))))
  6736. (cond
  6737. ((equal char ?\r)
  6738. (org-agenda-filter-show-all-tag)
  6739. (when org-agenda-auto-exclude-function
  6740. (setq org-agenda-tag-filter '())
  6741. (dolist (tag (org-agenda-get-represented-tags))
  6742. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6743. (if modifier
  6744. (push modifier org-agenda-tag-filter))))
  6745. (if (not (null org-agenda-tag-filter))
  6746. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6747. (setq maybe-refresh t))
  6748. ((equal char ?/)
  6749. (org-agenda-filter-show-all-tag)
  6750. (when (get 'org-agenda-tag-filter :preset-filter)
  6751. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6752. (setq maybe-refresh t))
  6753. ((equal char ?. )
  6754. (setq org-agenda-tag-filter
  6755. (mapcar (lambda(tag) (concat "+" tag))
  6756. (org-get-at-bol 'tags)))
  6757. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6758. (setq maybe-refresh t))
  6759. ((or (equal char ?\ )
  6760. (setq a (rassoc char alist))
  6761. (and (>= char ?0) (<= char ?9)
  6762. (setq n (if (= char ?0) 9 (- char ?0 1))
  6763. tag (concat effort-op (nth n efforts))
  6764. a (cons tag nil)))
  6765. (and (= char ??)
  6766. (setq tag "?eff")
  6767. a (cons tag nil))
  6768. (and tag (setq a (cons tag nil))))
  6769. (org-agenda-filter-show-all-tag)
  6770. (setq tag (car a))
  6771. (setq org-agenda-tag-filter
  6772. (cons (concat (if strip "-" "+") tag)
  6773. (if narrow current nil)))
  6774. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6775. (setq maybe-refresh t))
  6776. (t (error "Invalid tag selection character %c" char)))
  6777. (when (and maybe-refresh
  6778. (eq org-agenda-clockreport-mode 'with-filter))
  6779. (org-agenda-redo))))
  6780. (defun org-agenda-get-represented-tags ()
  6781. "Get a list of all tags currently represented in the agenda."
  6782. (let (p tags)
  6783. (save-excursion
  6784. (goto-char (point-min))
  6785. (while (setq p (next-single-property-change (point) 'tags))
  6786. (goto-char p)
  6787. (mapc (lambda (x) (add-to-list 'tags x))
  6788. (get-text-property (point) 'tags))))
  6789. tags))
  6790. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6791. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6792. (interactive "P")
  6793. (org-agenda-filter-by-tag strip char 'refine))
  6794. (defun org-agenda-filter-make-matcher ()
  6795. "Create the form that tests a line for agenda filter."
  6796. (let (f f1)
  6797. ;; first compute the tag-filter matcher
  6798. (dolist (x (delete-dups
  6799. (append (get 'org-agenda-tag-filter
  6800. :preset-filter) org-agenda-tag-filter)))
  6801. (if (member x '("-" "+"))
  6802. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6803. (if (string-match "[<=>?]" x)
  6804. (setq f1 (org-agenda-filter-effort-form x))
  6805. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6806. (if (equal (string-to-char x) ?-)
  6807. (setq f1 (list 'not f1))))
  6808. (push f1 f))
  6809. ;; then compute the category-filter matcher
  6810. (dolist (x (delete-dups
  6811. (append (get 'org-agenda-category-filter
  6812. :preset-filter) org-agenda-category-filter)))
  6813. (if (equal "-" (substring x 0 1))
  6814. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6815. (setq f1 (list 'equal (substring x 1) 'cat)))
  6816. (push f1 f))
  6817. (cons 'and (nreverse f))))
  6818. (defun org-agenda-filter-effort-form (e)
  6819. "Return the form to compare the effort of the current line with what E says.
  6820. E looks like \"+<2:25\"."
  6821. (let (op)
  6822. (setq e (substring e 1))
  6823. (setq op (string-to-char e) e (substring e 1))
  6824. (setq op (cond ((equal op ?<) '<=)
  6825. ((equal op ?>) '>=)
  6826. ((equal op ??) op)
  6827. (t '=)))
  6828. (list 'org-agenda-compare-effort (list 'quote op)
  6829. (org-duration-string-to-minutes e))))
  6830. (defun org-agenda-compare-effort (op value)
  6831. "Compare the effort of the current line with VALUE, using OP.
  6832. If the line does not have an effort defined, return nil."
  6833. (let ((eff (org-get-at-bol 'effort-minutes)))
  6834. (if (equal op ??)
  6835. (not eff)
  6836. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6837. value))))
  6838. (defun org-agenda-filter-apply (filter type)
  6839. "Set FILTER as the new agenda filter and apply it."
  6840. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  6841. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  6842. (let (tags cat)
  6843. (if (eq type 'tag)
  6844. (setq org-agenda-tag-filter filter)
  6845. (setq org-agenda-category-filter filter))
  6846. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6847. (if (and (eq type 'category)
  6848. (not (equal (substring (car filter) 0 1) "-")))
  6849. ;; Only set `org-agenda-filtered-by-category' to t
  6850. ;; when a unique category is used as the filter
  6851. (setq org-agenda-filtered-by-category t))
  6852. (org-agenda-set-mode-name)
  6853. (save-excursion
  6854. (goto-char (point-min))
  6855. (while (not (eobp))
  6856. (if (org-get-at-bol 'org-marker)
  6857. (progn
  6858. (setq tags (org-get-at-bol 'tags) ; used in eval
  6859. cat (get-text-property (point) 'org-category))
  6860. (if (not (eval org-agenda-filter-form))
  6861. (org-agenda-filter-hide-line type))
  6862. (beginning-of-line 2))
  6863. (beginning-of-line 2))))
  6864. (if (get-char-property (point) 'invisible)
  6865. (ignore-errors (org-agenda-previous-line)))))
  6866. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6867. "Set FILTER as the new agenda filter and apply it."
  6868. (org-agenda-set-mode-name)
  6869. (save-excursion
  6870. (goto-char (point-min))
  6871. (while (not (eobp))
  6872. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6873. (topcat (and pos (org-find-top-category pos))))
  6874. (if (and topcat (funcall (if negative 'identity 'not)
  6875. (string= category topcat)))
  6876. (org-agenda-filter-hide-line 'category)))
  6877. (beginning-of-line 2)))
  6878. (if (get-char-property (point) 'invisible)
  6879. (org-agenda-previous-line))
  6880. (setq org-agenda-top-category-filter category
  6881. org-agenda-filtered-by-top-category t))
  6882. (defun org-agenda-filter-hide-line (type)
  6883. (let (ov)
  6884. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6885. (point-at-eol)))
  6886. (overlay-put ov 'invisible t)
  6887. (overlay-put ov 'type type)
  6888. (if (eq type 'tag)
  6889. (push ov org-agenda-tag-filter-overlays)
  6890. (push ov org-agenda-cat-filter-overlays))))
  6891. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6892. (setq pos (or pos (point)))
  6893. (save-excursion
  6894. (dolist (ov (overlays-at pos))
  6895. (when (and (overlay-get ov 'invisible)
  6896. (eq (overlay-get ov 'type) 'tag))
  6897. (goto-char pos)
  6898. (if (< (overlay-start ov) (point-at-eol))
  6899. (move-overlay ov (point-at-eol)
  6900. (overlay-end ov)))))))
  6901. (defun org-agenda-filter-show-all-tag nil
  6902. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6903. (setq org-agenda-tag-filter-overlays nil
  6904. org-agenda-tag-filter nil
  6905. org-agenda-filter-form nil)
  6906. (org-agenda-set-mode-name))
  6907. (defun org-agenda-filter-show-all-cat nil
  6908. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6909. (setq org-agenda-cat-filter-overlays nil
  6910. org-agenda-filtered-by-category nil
  6911. org-agenda-category-filter nil
  6912. org-agenda-filter-form nil)
  6913. (org-agenda-set-mode-name))
  6914. (defun org-agenda-manipulate-query-add ()
  6915. "Manipulate the query by adding a search term with positive selection.
  6916. Positive selection means the term must be matched for selection of an entry."
  6917. (interactive)
  6918. (org-agenda-manipulate-query ?\[))
  6919. (defun org-agenda-manipulate-query-subtract ()
  6920. "Manipulate the query by adding a search term with negative selection.
  6921. Negative selection means term must not be matched for selection of an entry."
  6922. (interactive)
  6923. (org-agenda-manipulate-query ?\]))
  6924. (defun org-agenda-manipulate-query-add-re ()
  6925. "Manipulate the query by adding a search regexp with positive selection.
  6926. Positive selection means the regexp must match for selection of an entry."
  6927. (interactive)
  6928. (org-agenda-manipulate-query ?\{))
  6929. (defun org-agenda-manipulate-query-subtract-re ()
  6930. "Manipulate the query by adding a search regexp with negative selection.
  6931. Negative selection means regexp must not match for selection of an entry."
  6932. (interactive)
  6933. (org-agenda-manipulate-query ?\}))
  6934. (defun org-agenda-manipulate-query (char)
  6935. (cond
  6936. ((memq org-agenda-type '(timeline agenda))
  6937. (let ((org-agenda-include-inactive-timestamps t))
  6938. (org-agenda-redo))
  6939. (message "Display now includes inactive timestamps as well"))
  6940. ((eq org-agenda-type 'search)
  6941. (org-add-to-string
  6942. 'org-agenda-query-string
  6943. (if org-agenda-last-search-view-search-was-boolean
  6944. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6945. (?\{ . " +{}") (?\} . " -{}"))))
  6946. " "))
  6947. (setq org-agenda-redo-command
  6948. (list 'org-search-view
  6949. (car (get-text-property (min (1- (point-max)) (point))
  6950. 'org-last-args))
  6951. org-agenda-query-string
  6952. (+ (length org-agenda-query-string)
  6953. (if (member char '(?\{ ?\})) 0 1))))
  6954. (set-register org-agenda-query-register org-agenda-query-string)
  6955. (let ((org-agenda-overriding-arguments
  6956. (cdr org-agenda-redo-command)))
  6957. (org-agenda-redo)))
  6958. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6959. org-agenda-type))))
  6960. (defun org-add-to-string (var string)
  6961. (set var (concat (symbol-value var) string)))
  6962. (defun org-agenda-goto-date (span)
  6963. "Jump to DATE in agenda."
  6964. (interactive "P")
  6965. (let* ((org-read-date-prefer-future
  6966. (eval org-agenda-jump-prefer-future))
  6967. (date (org-read-date))
  6968. (org-agenda-sticky-orig org-agenda-sticky)
  6969. (org-agenda-buffer-tmp-name (buffer-name))
  6970. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6971. (0-arg (or current-prefix-arg (car args)))
  6972. (2-arg (nth 2 args))
  6973. (newcmd (list 'org-agenda-list 0-arg date
  6974. (org-agenda-span-to-ndays 2-arg)))
  6975. (newargs (cdr newcmd))
  6976. (inhibit-read-only t)
  6977. org-agenda-sticky)
  6978. (if (not (org-agenda-check-type t 'agenda))
  6979. (error "Not available in non-agenda blocks")
  6980. (add-text-properties (point-min) (point-max)
  6981. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6982. (org-agenda-redo)
  6983. (setq org-agenda-sticky org-agenda-sticky-orig
  6984. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6985. (defun org-agenda-goto-today ()
  6986. "Go to today."
  6987. (interactive)
  6988. (org-agenda-check-type t 'timeline 'agenda)
  6989. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6990. (curspan (nth 2 args))
  6991. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6992. (cond
  6993. (tdpos (goto-char tdpos))
  6994. ((eq org-agenda-type 'agenda)
  6995. (let* ((sd (org-agenda-compute-starting-span
  6996. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6997. (org-agenda-overriding-arguments args))
  6998. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6999. (org-agenda-redo)
  7000. (org-agenda-find-same-or-today-or-agenda)))
  7001. (t (error "Cannot find today")))))
  7002. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7003. (goto-char
  7004. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7005. (text-property-any (point-min) (point-max) 'org-today t)
  7006. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7007. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7008. (org-agenda-goto-block-beginning))
  7009. (point-min))))
  7010. (defun org-agenda-goto-block-beginning ()
  7011. "Go the agenda block beginning."
  7012. (interactive)
  7013. (if (not (derived-mode-p 'org-agenda-mode))
  7014. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7015. (let (dest)
  7016. (save-excursion
  7017. (unless (looking-at "\\'")
  7018. (forward-char))
  7019. (let* ((prop 'org-agenda-structural-header)
  7020. (p (previous-single-property-change (point) prop))
  7021. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7022. (1- (point))) prop)))
  7023. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7024. (if (not dest)
  7025. (error "Cannot find the beginning of the blog")
  7026. (goto-char dest)
  7027. (move-beginning-of-line 1)))))
  7028. (defun org-agenda-later (arg)
  7029. "Go forward in time by the current span.
  7030. With prefix ARG, go forward that many times the current span."
  7031. (interactive "p")
  7032. (org-agenda-check-type t 'agenda)
  7033. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7034. (span (or (nth 2 args) org-agenda-current-span))
  7035. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7036. (greg (calendar-gregorian-from-absolute sd))
  7037. (cnt (org-get-at-bol 'org-day-cnt))
  7038. greg2)
  7039. (cond
  7040. ((numberp span)
  7041. (setq sd (+ (* span arg) sd)))
  7042. ((eq span 'day)
  7043. (setq sd (+ arg sd)))
  7044. ((eq span 'week)
  7045. (setq sd (+ (* 7 arg) sd)))
  7046. ((eq span 'month)
  7047. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7048. sd (calendar-absolute-from-gregorian greg2))
  7049. (setcar greg2 (1+ (car greg2))))
  7050. ((eq span 'year)
  7051. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7052. sd (calendar-absolute-from-gregorian greg2))
  7053. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7054. (t
  7055. (setq sd (+ (* span arg) sd))))
  7056. (let ((org-agenda-overriding-cmd
  7057. ;; `cmd' may have been set by `org-agenda-run-series' which
  7058. ;; uses `org-agenda-overriding-cmd' to decide whether
  7059. ;; overriding is allowed for `cmd'
  7060. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7061. (org-agenda-overriding-arguments
  7062. (list (car args) sd span)))
  7063. (org-agenda-redo)
  7064. (org-agenda-find-same-or-today-or-agenda cnt))))
  7065. (defun org-agenda-earlier (arg)
  7066. "Go backward in time by the current span.
  7067. With prefix ARG, go backward that many times the current span."
  7068. (interactive "p")
  7069. (org-agenda-later (- arg)))
  7070. (defun org-agenda-view-mode-dispatch ()
  7071. "Call one of the view mode commands."
  7072. (interactive)
  7073. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  7074. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7075. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7076. (let ((a (read-char-exclusive)))
  7077. (case a
  7078. (?\ (call-interactively 'org-agenda-reset-view))
  7079. (?d (call-interactively 'org-agenda-day-view))
  7080. (?w (call-interactively 'org-agenda-week-view))
  7081. (?m (call-interactively 'org-agenda-month-view))
  7082. (?y (call-interactively 'org-agenda-year-view))
  7083. (?l (call-interactively 'org-agenda-log-mode))
  7084. (?L (org-agenda-log-mode '(4)))
  7085. (?c (org-agenda-log-mode 'clockcheck))
  7086. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7087. (?a (call-interactively 'org-agenda-archives-mode))
  7088. (?A (org-agenda-archives-mode 'files))
  7089. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7090. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7091. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7092. (?D (call-interactively 'org-agenda-toggle-diary))
  7093. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7094. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7095. (org-agenda-check-type t 'timeline 'agenda)
  7096. (org-agenda-redo))
  7097. (message "Display now includes inactive timestamps as well"))
  7098. (?q (message "Abort"))
  7099. (otherwise (error "Invalid key" )))))
  7100. (defun org-agenda-reset-view ()
  7101. "Switch to default view for agenda."
  7102. (interactive)
  7103. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7104. (defun org-agenda-day-view (&optional day-of-year)
  7105. "Switch to daily view for agenda.
  7106. With argument DAY-OF-YEAR, switch to that day of the year."
  7107. (interactive "P")
  7108. (org-agenda-change-time-span 'day day-of-year))
  7109. (defun org-agenda-week-view (&optional iso-week)
  7110. "Switch to daily view for agenda.
  7111. With argument ISO-WEEK, switch to the corresponding ISO week.
  7112. If ISO-WEEK has more then 2 digits, only the last two encode the
  7113. week. Any digits before this encode a year. So 200712 means
  7114. week 12 of year 2007. Years in the range 1938-2037 can also be
  7115. written as 2-digit years."
  7116. (interactive "P")
  7117. (org-agenda-change-time-span 'week iso-week))
  7118. (defun org-agenda-month-view (&optional month)
  7119. "Switch to monthly view for agenda.
  7120. With argument MONTH, switch to that month."
  7121. (interactive "P")
  7122. (org-agenda-change-time-span 'month month))
  7123. (defun org-agenda-year-view (&optional year)
  7124. "Switch to yearly view for agenda.
  7125. With argument YEAR, switch to that year.
  7126. If MONTH has more then 2 digits, only the last two encode the
  7127. month. Any digits before this encode a year. So 200712 means
  7128. December year 2007. Years in the range 1938-2037 can also be
  7129. written as 2-digit years."
  7130. (interactive "P")
  7131. (when year
  7132. (setq year (org-small-year-to-year year)))
  7133. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7134. (org-agenda-change-time-span 'year year)
  7135. (error "Abort")))
  7136. (defun org-agenda-change-time-span (span &optional n)
  7137. "Change the agenda view to SPAN.
  7138. SPAN may be `day', `week', `month', `year'."
  7139. (org-agenda-check-type t 'agenda)
  7140. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7141. (curspan (nth 2 args)))
  7142. (if (and (not n) (equal curspan span))
  7143. (error "Viewing span is already \"%s\"" span))
  7144. (let* ((sd (or (org-get-at-bol 'day)
  7145. (nth 1 args)
  7146. org-starting-day))
  7147. (sd (org-agenda-compute-starting-span sd span n))
  7148. (org-agenda-overriding-cmd
  7149. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7150. (org-agenda-overriding-arguments
  7151. (list (car args) sd span)))
  7152. (org-agenda-redo)
  7153. (org-agenda-find-same-or-today-or-agenda))
  7154. (org-agenda-set-mode-name)
  7155. (message "Switched to %s view" span)))
  7156. (defun org-agenda-compute-starting-span (sd span &optional n)
  7157. "Compute starting date for agenda.
  7158. SPAN may be `day', `week', `month', `year'. The return value
  7159. is a cons cell with the starting date and the number of days,
  7160. so that the date SD will be in that range."
  7161. (let* ((greg (calendar-gregorian-from-absolute sd))
  7162. (dg (nth 1 greg))
  7163. (mg (car greg))
  7164. (yg (nth 2 greg)))
  7165. (cond
  7166. ((eq span 'day)
  7167. (when n
  7168. (setq sd (+ (calendar-absolute-from-gregorian
  7169. (list mg 1 yg))
  7170. n -1))))
  7171. ((eq span 'week)
  7172. (let* ((nt (calendar-day-of-week
  7173. (calendar-gregorian-from-absolute sd)))
  7174. (d (if org-agenda-start-on-weekday
  7175. (- nt org-agenda-start-on-weekday)
  7176. 0))
  7177. y1)
  7178. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7179. (when n
  7180. (require 'cal-iso)
  7181. (when (> n 99)
  7182. (setq y1 (org-small-year-to-year (/ n 100))
  7183. n (mod n 100)))
  7184. (setq sd
  7185. (calendar-absolute-from-iso
  7186. (list n 1
  7187. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7188. ((eq span 'month)
  7189. (let (y1)
  7190. (when (and n (> n 99))
  7191. (setq y1 (org-small-year-to-year (/ n 100))
  7192. n (mod n 100)))
  7193. (setq sd (calendar-absolute-from-gregorian
  7194. (list (or n mg) 1 (or y1 yg))))))
  7195. ((eq span 'year)
  7196. (setq sd (calendar-absolute-from-gregorian
  7197. (list 1 1 (or n yg))))))
  7198. sd))
  7199. (defun org-agenda-next-date-line (&optional arg)
  7200. "Jump to the next line indicating a date in agenda buffer."
  7201. (interactive "p")
  7202. (org-agenda-check-type t 'agenda 'timeline)
  7203. (beginning-of-line 1)
  7204. ;; This does not work if user makes date format that starts with a blank
  7205. (if (looking-at "^\\S-") (forward-char 1))
  7206. (if (not (re-search-forward "^\\S-" nil t arg))
  7207. (progn
  7208. (backward-char 1)
  7209. (error "No next date after this line in this buffer")))
  7210. (goto-char (match-beginning 0)))
  7211. (defun org-agenda-previous-date-line (&optional arg)
  7212. "Jump to the previous line indicating a date in agenda buffer."
  7213. (interactive "p")
  7214. (org-agenda-check-type t 'agenda 'timeline)
  7215. (beginning-of-line 1)
  7216. (if (not (re-search-backward "^\\S-" nil t arg))
  7217. (error "No previous date before this line in this buffer")))
  7218. ;; Initialize the highlight
  7219. (defvar org-hl (make-overlay 1 1))
  7220. (overlay-put org-hl 'face 'highlight)
  7221. (defun org-highlight (begin end &optional buffer)
  7222. "Highlight a region with overlay."
  7223. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7224. (defun org-unhighlight ()
  7225. "Detach overlay INDEX."
  7226. (org-detach-overlay org-hl))
  7227. (defun org-unhighlight-once ()
  7228. "Remove the highlight from its position, and this function from the hook."
  7229. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7230. (org-unhighlight))
  7231. (defvar org-agenda-pre-follow-window-conf nil)
  7232. (defun org-agenda-follow-mode ()
  7233. "Toggle follow mode in an agenda buffer."
  7234. (interactive)
  7235. (unless org-agenda-follow-mode
  7236. (setq org-agenda-pre-follow-window-conf
  7237. (current-window-configuration)))
  7238. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7239. (unless org-agenda-follow-mode
  7240. (set-window-configuration org-agenda-pre-follow-window-conf))
  7241. (org-agenda-set-mode-name)
  7242. (org-agenda-do-context-action)
  7243. (message "Follow mode is %s"
  7244. (if org-agenda-follow-mode "on" "off")))
  7245. (defun org-agenda-entry-text-mode (&optional arg)
  7246. "Toggle entry text mode in an agenda buffer."
  7247. (interactive "P")
  7248. (if (or org-agenda-tag-filter
  7249. org-agenda-category-filter
  7250. org-agenda-top-category-filter)
  7251. (user-error "Can't show entry text in filtered views")
  7252. (setq org-agenda-entry-text-mode (or (integerp arg)
  7253. (not org-agenda-entry-text-mode)))
  7254. (org-agenda-entry-text-hide)
  7255. (and org-agenda-entry-text-mode
  7256. (let ((org-agenda-entry-text-maxlines
  7257. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7258. (org-agenda-entry-text-show)))
  7259. (org-agenda-set-mode-name)
  7260. (message "Entry text mode is %s%s"
  7261. (if org-agenda-entry-text-mode "on" "off")
  7262. (if (not org-agenda-entry-text-mode) ""
  7263. (format " (maximum number of lines is %d)"
  7264. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7265. (defun org-agenda-clockreport-mode (&optional with-filter)
  7266. "Toggle clocktable mode in an agenda buffer.
  7267. With prefix arg WITH-FILTER, make the clocktable respect the current
  7268. agenda filter."
  7269. (interactive "P")
  7270. (org-agenda-check-type t 'agenda)
  7271. (if with-filter
  7272. (setq org-agenda-clockreport-mode 'with-filter)
  7273. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7274. (org-agenda-set-mode-name)
  7275. (org-agenda-redo)
  7276. (message "Clocktable mode is %s"
  7277. (if org-agenda-clockreport-mode "on" "off")))
  7278. (defun org-agenda-log-mode (&optional special)
  7279. "Toggle log mode in an agenda buffer.
  7280. With argument SPECIAL, show all possible log items, not only the ones
  7281. configured in `org-agenda-log-mode-items'.
  7282. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7283. (interactive "P")
  7284. (org-agenda-check-type t 'agenda 'timeline)
  7285. (setq org-agenda-show-log
  7286. (cond
  7287. ((equal special '(16)) 'only)
  7288. ((eq special 'clockcheck)
  7289. (if (eq org-agenda-show-log 'clockcheck)
  7290. nil 'clockcheck))
  7291. (special '(closed clock state))
  7292. (t (not org-agenda-show-log))))
  7293. (org-agenda-set-mode-name)
  7294. (org-agenda-redo)
  7295. (message "Log mode is %s"
  7296. (if org-agenda-show-log "on" "off")))
  7297. (defun org-agenda-archives-mode (&optional with-files)
  7298. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7299. When called with a prefix argument, include all archive files as well."
  7300. (interactive "P")
  7301. (setq org-agenda-archives-mode
  7302. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7303. (org-agenda-set-mode-name)
  7304. (org-agenda-redo)
  7305. (message
  7306. "%s"
  7307. (cond
  7308. ((eq org-agenda-archives-mode nil)
  7309. "No archives are included")
  7310. ((eq org-agenda-archives-mode 'trees)
  7311. (format "Trees with :%s: tag are included" org-archive-tag))
  7312. ((eq org-agenda-archives-mode t)
  7313. (format "Trees with :%s: tag and all active archive files are included"
  7314. org-archive-tag)))))
  7315. (defun org-agenda-toggle-diary ()
  7316. "Toggle diary inclusion in an agenda buffer."
  7317. (interactive)
  7318. (org-agenda-check-type t 'agenda)
  7319. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7320. (org-agenda-redo)
  7321. (org-agenda-set-mode-name)
  7322. (message "Diary inclusion turned %s"
  7323. (if org-agenda-include-diary "on" "off")))
  7324. (defun org-agenda-toggle-deadlines ()
  7325. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7326. (interactive)
  7327. (org-agenda-check-type t 'agenda)
  7328. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7329. (org-agenda-redo)
  7330. (org-agenda-set-mode-name)
  7331. (message "Deadlines inclusion turned %s"
  7332. (if org-agenda-include-deadlines "on" "off")))
  7333. (defun org-agenda-toggle-time-grid ()
  7334. "Toggle time grid in an agenda buffer."
  7335. (interactive)
  7336. (org-agenda-check-type t 'agenda)
  7337. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7338. (org-agenda-redo)
  7339. (org-agenda-set-mode-name)
  7340. (message "Time-grid turned %s"
  7341. (if org-agenda-use-time-grid "on" "off")))
  7342. (defun org-agenda-set-mode-name ()
  7343. "Set the mode name to indicate all the small mode settings."
  7344. (setq mode-name
  7345. (list "Org-Agenda"
  7346. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7347. " "
  7348. '(:eval (org-agenda-span-name org-agenda-current-span))
  7349. (if org-agenda-follow-mode " Follow" "")
  7350. (if org-agenda-entry-text-mode " ETxt" "")
  7351. (if org-agenda-include-diary " Diary" "")
  7352. (if org-agenda-include-deadlines " Ddl" "")
  7353. (if org-agenda-use-time-grid " Grid" "")
  7354. (if (and (boundp 'org-habit-show-habits)
  7355. org-habit-show-habits) " Habit" "")
  7356. (cond
  7357. ((consp org-agenda-show-log) " LogAll")
  7358. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7359. (org-agenda-show-log " Log")
  7360. (t ""))
  7361. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7362. :preset-filter))
  7363. '(:eval (org-propertize
  7364. (concat " <"
  7365. (mapconcat
  7366. 'identity
  7367. (append
  7368. (get 'org-agenda-category-filter :preset-filter)
  7369. org-agenda-category-filter)
  7370. "")
  7371. ">")
  7372. 'face 'org-agenda-filter-category
  7373. 'help-echo "Category used in filtering"))
  7374. "")
  7375. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7376. :preset-filter))
  7377. '(:eval (org-propertize
  7378. (concat " {"
  7379. (mapconcat
  7380. 'identity
  7381. (append
  7382. (get 'org-agenda-tag-filter :preset-filter)
  7383. org-agenda-tag-filter)
  7384. "")
  7385. "}")
  7386. 'face 'org-agenda-filter-tags
  7387. 'help-echo "Tags used in filtering"))
  7388. "")
  7389. (if org-agenda-archives-mode
  7390. (if (eq org-agenda-archives-mode t)
  7391. " Archives"
  7392. (format " :%s:" org-archive-tag))
  7393. "")
  7394. (if org-agenda-clockreport-mode
  7395. (if (eq org-agenda-clockreport-mode 'with-filter)
  7396. " Clock{}" " Clock")
  7397. "")))
  7398. (force-mode-line-update))
  7399. (define-obsolete-function-alias
  7400. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7401. (defun org-agenda-update-agenda-type ()
  7402. "Update the agenda type after each command."
  7403. (setq org-agenda-type
  7404. (or (get-text-property (point) 'org-agenda-type)
  7405. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7406. (defun org-agenda-next-line ()
  7407. "Move cursor to the next line, and show if follow mode is active."
  7408. (interactive)
  7409. (call-interactively 'next-line)
  7410. (org-agenda-do-context-action))
  7411. (defun org-agenda-previous-line ()
  7412. "Move cursor to the previous line, and show if follow-mode is active."
  7413. (interactive)
  7414. (call-interactively 'previous-line)
  7415. (org-agenda-do-context-action))
  7416. (defun org-agenda-next-item (n)
  7417. "Move cursor to next agenda item."
  7418. (interactive "p")
  7419. (let ((col (current-column)))
  7420. (dotimes (c n)
  7421. (when (next-single-property-change (point-at-eol) 'org-marker)
  7422. (move-end-of-line 1)
  7423. (goto-char (next-single-property-change (point) 'org-marker))))
  7424. (org-move-to-column col))
  7425. (org-agenda-do-context-action))
  7426. (defun org-agenda-previous-item (n)
  7427. "Move cursor to next agenda item."
  7428. (interactive "p")
  7429. (dotimes (c n)
  7430. (let ((col (current-column))
  7431. (goto (save-excursion
  7432. (move-end-of-line 0)
  7433. (previous-single-property-change (point) 'org-marker))))
  7434. (if goto (goto-char goto))
  7435. (org-move-to-column col)))
  7436. (org-agenda-do-context-action))
  7437. (defun org-agenda-do-context-action ()
  7438. "Show outline path and, maybe, follow mode window."
  7439. (let ((m (org-get-at-bol 'org-marker)))
  7440. (when (and (markerp m) (marker-buffer m))
  7441. (and org-agenda-follow-mode
  7442. (if org-agenda-follow-indirect
  7443. (org-agenda-tree-to-indirect-buffer nil)
  7444. (org-agenda-show)))
  7445. (and org-agenda-show-outline-path
  7446. (org-with-point-at m (org-display-outline-path t))))))
  7447. (defun org-agenda-show-tags ()
  7448. "Show the tags applicable to the current item."
  7449. (interactive)
  7450. (let* ((tags (org-get-at-bol 'tags)))
  7451. (if tags
  7452. (message "Tags are :%s:"
  7453. (org-no-properties (mapconcat 'identity tags ":")))
  7454. (message "No tags associated with this line"))))
  7455. (defun org-agenda-goto (&optional highlight)
  7456. "Go to the Org-mode file which contains the item at point."
  7457. (interactive)
  7458. (let* ((marker (or (org-get-at-bol 'org-marker)
  7459. (org-agenda-error)))
  7460. (buffer (marker-buffer marker))
  7461. (pos (marker-position marker)))
  7462. (switch-to-buffer-other-window buffer)
  7463. (widen)
  7464. (push-mark)
  7465. (goto-char pos)
  7466. (when (derived-mode-p 'org-mode)
  7467. (org-show-context 'agenda)
  7468. (save-excursion
  7469. (and (outline-next-heading)
  7470. (org-flag-heading nil)))) ; show the next heading
  7471. (when (outline-invisible-p)
  7472. (show-entry)) ; display invisible text
  7473. (recenter (/ (window-height) 2))
  7474. (run-hooks 'org-agenda-after-show-hook)
  7475. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7476. (defvar org-agenda-after-show-hook nil
  7477. "Normal hook run after an item has been shown from the agenda.
  7478. Point is in the buffer where the item originated.")
  7479. (defun org-agenda-kill ()
  7480. "Kill the entry or subtree belonging to the current agenda entry."
  7481. (interactive)
  7482. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7483. (let* ((bufname-orig (buffer-name))
  7484. (marker (or (org-get-at-bol 'org-marker)
  7485. (org-agenda-error)))
  7486. (buffer (marker-buffer marker))
  7487. (pos (marker-position marker))
  7488. (type (org-get-at-bol 'type))
  7489. dbeg dend (n 0) conf)
  7490. (org-with-remote-undo buffer
  7491. (with-current-buffer buffer
  7492. (save-excursion
  7493. (goto-char pos)
  7494. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7495. (setq dbeg (progn (org-back-to-heading t) (point))
  7496. dend (org-end-of-subtree t t))
  7497. (setq dbeg (point-at-bol)
  7498. dend (min (point-max) (1+ (point-at-eol)))))
  7499. (goto-char dbeg)
  7500. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7501. (setq conf (or (eq t org-agenda-confirm-kill)
  7502. (and (numberp org-agenda-confirm-kill)
  7503. (> n org-agenda-confirm-kill))))
  7504. (and conf
  7505. (not (y-or-n-p
  7506. (format "Delete entry with %d lines in buffer \"%s\"? "
  7507. n (buffer-name buffer))))
  7508. (error "Abort"))
  7509. (let ((org-agenda-buffer-name bufname-orig))
  7510. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7511. (with-current-buffer buffer (delete-region dbeg dend))
  7512. (message "Agenda item and source killed"))))
  7513. (defvar org-archive-default-command) ; defined in org-archive.el
  7514. (defun org-agenda-archive-default ()
  7515. "Archive the entry or subtree belonging to the current agenda entry."
  7516. (interactive)
  7517. (require 'org-archive)
  7518. (org-agenda-archive-with org-archive-default-command))
  7519. (defun org-agenda-archive-default-with-confirmation ()
  7520. "Archive the entry or subtree belonging to the current agenda entry."
  7521. (interactive)
  7522. (require 'org-archive)
  7523. (org-agenda-archive-with org-archive-default-command 'confirm))
  7524. (defun org-agenda-archive ()
  7525. "Archive the entry or subtree belonging to the current agenda entry."
  7526. (interactive)
  7527. (org-agenda-archive-with 'org-archive-subtree))
  7528. (defun org-agenda-archive-to-archive-sibling ()
  7529. "Move the entry to the archive sibling."
  7530. (interactive)
  7531. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7532. (defun org-agenda-archive-with (cmd &optional confirm)
  7533. "Move the entry to the archive sibling."
  7534. (interactive)
  7535. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7536. (let* ((bufname-orig (buffer-name))
  7537. (marker (or (org-get-at-bol 'org-marker)
  7538. (org-agenda-error)))
  7539. (buffer (marker-buffer marker))
  7540. (pos (marker-position marker)))
  7541. (org-with-remote-undo buffer
  7542. (with-current-buffer buffer
  7543. (if (derived-mode-p 'org-mode)
  7544. (if (and confirm
  7545. (not (y-or-n-p "Archive this subtree or entry? ")))
  7546. (error "Abort")
  7547. (save-excursion
  7548. (goto-char pos)
  7549. (let ((org-agenda-buffer-name bufname-orig))
  7550. (org-remove-subtree-entries-from-agenda))
  7551. (org-back-to-heading t)
  7552. (funcall cmd)))
  7553. (error "Archiving works only in Org-mode files"))))))
  7554. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7555. "Remove all lines in the agenda that correspond to a given subtree.
  7556. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7557. If this information is not given, the function uses the tree at point."
  7558. (let ((buf (or buf (current-buffer))) m p)
  7559. (save-excursion
  7560. (unless (and beg end)
  7561. (org-back-to-heading t)
  7562. (setq beg (point))
  7563. (org-end-of-subtree t)
  7564. (setq end (point)))
  7565. (set-buffer (get-buffer org-agenda-buffer-name))
  7566. (save-excursion
  7567. (goto-char (point-max))
  7568. (beginning-of-line 1)
  7569. (while (not (bobp))
  7570. (when (and (setq m (org-get-at-bol 'org-marker))
  7571. (equal buf (marker-buffer m))
  7572. (setq p (marker-position m))
  7573. (>= p beg)
  7574. (< p end))
  7575. (let ((inhibit-read-only t))
  7576. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7577. (beginning-of-line 0))))))
  7578. (defun org-agenda-refile (&optional goto rfloc no-update)
  7579. "Refile the item at point."
  7580. (interactive "P")
  7581. (if (equal goto '(16))
  7582. (org-refile-goto-last-stored)
  7583. (let* ((buffer-orig (buffer-name))
  7584. (marker (or (org-get-at-bol 'org-hd-marker)
  7585. (org-agenda-error)))
  7586. (buffer (marker-buffer marker))
  7587. (pos (marker-position marker))
  7588. (rfloc (or rfloc
  7589. (org-refile-get-location
  7590. (if goto "Goto" "Refile to") buffer
  7591. org-refile-allow-creating-parent-nodes))))
  7592. (with-current-buffer buffer
  7593. (save-excursion
  7594. (save-restriction
  7595. (widen)
  7596. (goto-char marker)
  7597. (let ((org-agenda-buffer-name buffer-orig))
  7598. (org-remove-subtree-entries-from-agenda))
  7599. (org-refile goto buffer rfloc)))))
  7600. (unless no-update (org-agenda-redo))))
  7601. (defun org-agenda-open-link (&optional arg)
  7602. "Open the link(s) in the current entry, if any.
  7603. This looks for a link in the displayed line in the agenda.
  7604. It also looks at the text of the entry itself."
  7605. (interactive "P")
  7606. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7607. (org-get-at-bol 'org-marker)))
  7608. (buffer (and marker (marker-buffer marker)))
  7609. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7610. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7611. (lk0 (car lkall))
  7612. (lk (if (stringp lk0) (list lk0) lk0))
  7613. (lkend (cdr lkall))
  7614. trg)
  7615. (cond
  7616. ((and buffer lk)
  7617. (mapcar (lambda(l)
  7618. (with-current-buffer buffer
  7619. (setq trg (and (string-match org-bracket-link-regexp l)
  7620. (match-string 1 l)))
  7621. (if (or (not trg) (string-match org-any-link-re trg))
  7622. (save-excursion
  7623. (save-restriction
  7624. (widen)
  7625. (goto-char marker)
  7626. (when (search-forward l nil lkend)
  7627. (goto-char (match-beginning 0))
  7628. (org-open-at-point))))
  7629. ;; This is an internal link, widen the buffer
  7630. (switch-to-buffer-other-window buffer)
  7631. (widen)
  7632. (goto-char marker)
  7633. (when (search-forward l nil lkend)
  7634. (goto-char (match-beginning 0))
  7635. (org-open-at-point)))))
  7636. lk))
  7637. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7638. (save-excursion
  7639. (beginning-of-line 1)
  7640. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7641. (org-open-link-from-string (match-string 1)))
  7642. (t (message "No link to open here")))))
  7643. (defun org-agenda-copy-local-variable (var)
  7644. "Get a variable from a referenced buffer and install it here."
  7645. (let ((m (org-get-at-bol 'org-marker)))
  7646. (when (and m (buffer-live-p (marker-buffer m)))
  7647. (org-set-local var (with-current-buffer (marker-buffer m)
  7648. (symbol-value var))))))
  7649. (defun org-agenda-switch-to (&optional delete-other-windows)
  7650. "Go to the Org-mode file which contains the item at point."
  7651. (interactive)
  7652. (if (and org-return-follows-link
  7653. (not (org-get-at-bol 'org-marker))
  7654. (org-in-regexp org-bracket-link-regexp))
  7655. (org-open-link-from-string (match-string 0))
  7656. (let* ((marker (or (org-get-at-bol 'org-marker)
  7657. (org-agenda-error)))
  7658. (buffer (marker-buffer marker))
  7659. (pos (marker-position marker)))
  7660. (org-pop-to-buffer-same-window buffer)
  7661. (and delete-other-windows (delete-other-windows))
  7662. (widen)
  7663. (goto-char pos)
  7664. (when (derived-mode-p 'org-mode)
  7665. (org-show-context 'agenda)
  7666. (save-excursion
  7667. (and (outline-next-heading)
  7668. (org-flag-heading nil))) ; show the next heading
  7669. (when (outline-invisible-p)
  7670. (show-entry)) ; display invisible text
  7671. (run-hooks 'org-agenda-after-show-hook)))))
  7672. (defun org-agenda-goto-mouse (ev)
  7673. "Go to the Org-mode file which contains the item at the mouse click."
  7674. (interactive "e")
  7675. (mouse-set-point ev)
  7676. (org-agenda-goto))
  7677. (defun org-agenda-show (&optional full-entry)
  7678. "Display the Org-mode file which contains the item at point.
  7679. With prefix argument FULL-ENTRY, make the entire entry visible
  7680. if it was hidden in the outline."
  7681. (interactive "P")
  7682. (let ((win (selected-window)))
  7683. (if full-entry
  7684. (let ((org-show-entry-below t))
  7685. (org-agenda-goto t))
  7686. (org-agenda-goto t))
  7687. (select-window win)))
  7688. (defvar org-agenda-show-window nil)
  7689. (defun org-agenda-show-and-scroll-up (&optional arg)
  7690. "Display the Org-mode file which contains the item at point.
  7691. When called repeatedly, scroll the window that is displaying the buffer.
  7692. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7693. `show-subtree' to display the item, so that drawers and logbooks stay
  7694. folded."
  7695. (interactive "P")
  7696. (let ((win (selected-window)))
  7697. (if (and (window-live-p org-agenda-show-window)
  7698. (eq this-command last-command))
  7699. (progn
  7700. (select-window org-agenda-show-window)
  7701. (ignore-errors (scroll-up)))
  7702. (org-agenda-goto t)
  7703. (if arg (org-show-entry) (show-subtree))
  7704. (setq org-agenda-show-window (selected-window)))
  7705. (select-window win)))
  7706. (defun org-agenda-show-scroll-down ()
  7707. "Scroll down the window showing the agenda."
  7708. (interactive)
  7709. (let ((win (selected-window)))
  7710. (when (window-live-p org-agenda-show-window)
  7711. (select-window org-agenda-show-window)
  7712. (ignore-errors (scroll-down))
  7713. (select-window win))))
  7714. (defun org-agenda-show-1 (&optional more)
  7715. "Display the Org-mode file which contains the item at point.
  7716. The prefix arg selects the amount of information to display:
  7717. 0 hide the subtree
  7718. 1 just show the entry according to defaults.
  7719. 2 show the children view
  7720. 3 show the subtree view
  7721. 4 show the entire subtree and any LOGBOOK drawers
  7722. 5 show the entire subtree and any drawers
  7723. With prefix argument FULL-ENTRY, make the entire entry visible
  7724. if it was hidden in the outline."
  7725. (interactive "p")
  7726. (let ((win (selected-window)))
  7727. (org-agenda-goto t)
  7728. (org-recenter-heading 1)
  7729. (cond
  7730. ((= more 0)
  7731. (hide-subtree)
  7732. (save-excursion
  7733. (org-back-to-heading)
  7734. (run-hook-with-args 'org-cycle-hook 'folded))
  7735. (message "Remote: FOLDED"))
  7736. ((and (org-called-interactively-p 'any) (= more 1))
  7737. (message "Remote: show with default settings"))
  7738. ((= more 2)
  7739. (show-entry)
  7740. (show-children)
  7741. (save-excursion
  7742. (org-back-to-heading)
  7743. (run-hook-with-args 'org-cycle-hook 'children))
  7744. (message "Remote: CHILDREN"))
  7745. ((= more 3)
  7746. (show-subtree)
  7747. (save-excursion
  7748. (org-back-to-heading)
  7749. (run-hook-with-args 'org-cycle-hook 'subtree))
  7750. (message "Remote: SUBTREE"))
  7751. ((= more 4)
  7752. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7753. (org-drawer-regexp
  7754. (concat "^[ \t]*:\\("
  7755. (mapconcat 'regexp-quote org-drawers "\\|")
  7756. "\\):[ \t]*$")))
  7757. (show-subtree)
  7758. (save-excursion
  7759. (org-back-to-heading)
  7760. (org-cycle-hide-drawers 'subtree)))
  7761. (message "Remote: SUBTREE AND LOGBOOK"))
  7762. ((> more 4)
  7763. (show-subtree)
  7764. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7765. (select-window win)))
  7766. (defun org-recenter-heading (n)
  7767. (save-excursion
  7768. (org-back-to-heading)
  7769. (recenter n)))
  7770. (defvar org-agenda-cycle-counter nil)
  7771. (defun org-agenda-cycle-show (&optional n)
  7772. "Show the current entry in another window, with default settings.
  7773. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7774. When use repeatedly in immediate succession, the remote entry will cycle
  7775. through visibility
  7776. children -> subtree -> folded
  7777. When called with a numeric prefix arg, that arg will be passed through to
  7778. `org-agenda-show-1'. For the interpretation of that argument, see the
  7779. docstring of `org-agenda-show-1'."
  7780. (interactive "P")
  7781. (if (integerp n)
  7782. (setq org-agenda-cycle-counter n)
  7783. (if (not (eq last-command this-command))
  7784. (setq org-agenda-cycle-counter 1)
  7785. (if (equal org-agenda-cycle-counter 0)
  7786. (setq org-agenda-cycle-counter 2)
  7787. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7788. (if (> org-agenda-cycle-counter 3)
  7789. (setq org-agenda-cycle-counter 0)))))
  7790. (org-agenda-show-1 org-agenda-cycle-counter))
  7791. (defun org-agenda-recenter (arg)
  7792. "Display the Org-mode file which contains the item at point and recenter."
  7793. (interactive "P")
  7794. (let ((win (selected-window)))
  7795. (org-agenda-goto t)
  7796. (recenter arg)
  7797. (select-window win)))
  7798. (defun org-agenda-show-mouse (ev)
  7799. "Display the Org-mode file which contains the item at the mouse click."
  7800. (interactive "e")
  7801. (mouse-set-point ev)
  7802. (org-agenda-show))
  7803. (defun org-agenda-check-no-diary ()
  7804. "Check if the entry is a diary link and abort if yes."
  7805. (if (org-get-at-bol 'org-agenda-diary-link)
  7806. (org-agenda-error)))
  7807. (defun org-agenda-error ()
  7808. (error "Command not allowed in this line"))
  7809. (defun org-agenda-tree-to-indirect-buffer (arg)
  7810. "Show the subtree corresponding to the current entry in an indirect buffer.
  7811. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7812. With a numerical prefix ARG, go up to this level and then take that tree.
  7813. With a negative numeric ARG, go up by this number of levels.
  7814. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7815. use the dedicated frame)."
  7816. (interactive "P")
  7817. (if current-prefix-arg
  7818. (org-agenda-do-tree-to-indirect-buffer arg)
  7819. (let ((agenda-buffer (buffer-name))
  7820. (agenda-window (selected-window))
  7821. (indirect-window
  7822. (and org-last-indirect-buffer
  7823. (get-buffer-window org-last-indirect-buffer))))
  7824. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7825. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7826. (eq org-indirect-buffer-display 'dedicated-frame))
  7827. (unwind-protect
  7828. (unless (and indirect-window (window-live-p indirect-window))
  7829. (setq indirect-window (split-window agenda-window)))
  7830. (and indirect-window (select-window indirect-window))
  7831. (switch-to-buffer org-last-indirect-buffer :norecord)
  7832. (fit-window-to-buffer indirect-window)))
  7833. (select-window (get-buffer-window agenda-buffer)))))
  7834. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7835. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7836. (org-agenda-check-no-diary)
  7837. (let* ((marker (or (org-get-at-bol 'org-marker)
  7838. (org-agenda-error)))
  7839. (buffer (marker-buffer marker))
  7840. (pos (marker-position marker)))
  7841. (with-current-buffer buffer
  7842. (save-excursion
  7843. (goto-char pos)
  7844. (funcall 'org-tree-to-indirect-buffer arg)))))
  7845. (defvar org-last-heading-marker (make-marker)
  7846. "Marker pointing to the headline that last changed its TODO state
  7847. by a remote command from the agenda.")
  7848. (defun org-agenda-todo-nextset ()
  7849. "Switch TODO entry to next sequence."
  7850. (interactive)
  7851. (org-agenda-todo 'nextset))
  7852. (defun org-agenda-todo-previousset ()
  7853. "Switch TODO entry to previous sequence."
  7854. (interactive)
  7855. (org-agenda-todo 'previousset))
  7856. (defun org-agenda-todo (&optional arg)
  7857. "Cycle TODO state of line at point, also in Org-mode file.
  7858. This changes the line at point, all other lines in the agenda referring to
  7859. the same tree node, and the headline of the tree node in the Org-mode file."
  7860. (interactive "P")
  7861. (org-agenda-check-no-diary)
  7862. (let* ((col (current-column))
  7863. (marker (or (org-get-at-bol 'org-marker)
  7864. (org-agenda-error)))
  7865. (buffer (marker-buffer marker))
  7866. (pos (marker-position marker))
  7867. (hdmarker (org-get-at-bol 'org-hd-marker))
  7868. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7869. (inhibit-read-only t)
  7870. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7871. (org-with-remote-undo buffer
  7872. (with-current-buffer buffer
  7873. (widen)
  7874. (goto-char pos)
  7875. (org-show-context 'agenda)
  7876. (save-excursion
  7877. (and (outline-next-heading)
  7878. (org-flag-heading nil))) ; show the next heading
  7879. (let ((current-prefix-arg arg))
  7880. (call-interactively 'org-todo))
  7881. (and (bolp) (forward-char 1))
  7882. (setq newhead (org-get-heading))
  7883. (when (and (org-bound-and-true-p
  7884. org-agenda-headline-snapshot-before-repeat)
  7885. (not (equal org-agenda-headline-snapshot-before-repeat
  7886. newhead))
  7887. todayp)
  7888. (setq newhead org-agenda-headline-snapshot-before-repeat
  7889. just-one t))
  7890. (save-excursion
  7891. (org-back-to-heading)
  7892. (move-marker org-last-heading-marker (point))))
  7893. (beginning-of-line 1)
  7894. (save-excursion
  7895. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7896. (org-move-to-column col))))
  7897. (defun org-agenda-add-note (&optional arg)
  7898. "Add a time-stamped note to the entry at point."
  7899. (interactive "P")
  7900. (org-agenda-check-no-diary)
  7901. (let* ((marker (or (org-get-at-bol 'org-marker)
  7902. (org-agenda-error)))
  7903. (buffer (marker-buffer marker))
  7904. (pos (marker-position marker))
  7905. (hdmarker (org-get-at-bol 'org-hd-marker))
  7906. (inhibit-read-only t))
  7907. (with-current-buffer buffer
  7908. (widen)
  7909. (goto-char pos)
  7910. (org-show-context 'agenda)
  7911. (save-excursion
  7912. (and (outline-next-heading)
  7913. (org-flag-heading nil))) ; show the next heading
  7914. (org-add-note))))
  7915. (defun org-agenda-change-all-lines (newhead hdmarker
  7916. &optional fixface just-this)
  7917. "Change all lines in the agenda buffer which match HDMARKER.
  7918. The new content of the line will be NEWHEAD (as modified by
  7919. `org-agenda-format-item'). HDMARKER is checked with
  7920. `equal' against all `org-hd-marker' text properties in the file.
  7921. If FIXFACE is non-nil, the face of each item is modified according to
  7922. the new TODO state.
  7923. If JUST-THIS is non-nil, change just the current line, not all.
  7924. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7925. (let* ((inhibit-read-only t)
  7926. (line (org-current-line))
  7927. (org-agenda-buffer (current-buffer))
  7928. (thetags (with-current-buffer (marker-buffer hdmarker)
  7929. (save-excursion (save-restriction (widen)
  7930. (goto-char hdmarker)
  7931. (org-get-tags-at)))))
  7932. props m pl undone-face done-face finish new dotime level cat tags)
  7933. (save-excursion
  7934. (goto-char (point-max))
  7935. (beginning-of-line 1)
  7936. (while (not finish)
  7937. (setq finish (bobp))
  7938. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7939. (or (not just-this) (= (org-current-line) line))
  7940. (equal m hdmarker))
  7941. (setq props (text-properties-at (point))
  7942. dotime (org-get-at-bol 'dotime)
  7943. cat (org-get-at-bol 'org-category)
  7944. level (org-get-at-bol 'level)
  7945. tags thetags
  7946. new
  7947. (let ((org-prefix-format-compiled
  7948. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7949. org-prefix-format-compiled))
  7950. (extra (org-get-at-bol 'extra)))
  7951. (with-current-buffer (marker-buffer hdmarker)
  7952. (save-excursion
  7953. (save-restriction
  7954. (widen)
  7955. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7956. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7957. undone-face (org-get-at-bol 'undone-face)
  7958. done-face (org-get-at-bol 'done-face))
  7959. (beginning-of-line 1)
  7960. (cond
  7961. ((equal new "")
  7962. (and (looking-at ".*\n?") (replace-match "")))
  7963. ((looking-at ".*")
  7964. (replace-match new t t)
  7965. (beginning-of-line 1)
  7966. (add-text-properties (point-at-bol) (point-at-eol) props)
  7967. (when fixface
  7968. (add-text-properties
  7969. (point-at-bol) (point-at-eol)
  7970. (list 'face
  7971. (if org-last-todo-state-is-todo
  7972. undone-face done-face))))
  7973. (org-agenda-highlight-todo 'line)
  7974. (beginning-of-line 1))
  7975. (t (error "Line update did not work")))
  7976. (save-restriction
  7977. (narrow-to-region (point-at-bol) (point-at-eol))
  7978. (org-agenda-finalize)))
  7979. (beginning-of-line 0)))))
  7980. (defun org-agenda-align-tags (&optional line)
  7981. "Align all tags in agenda items to `org-agenda-tags-column'."
  7982. (let ((inhibit-read-only t) l c)
  7983. (save-excursion
  7984. (goto-char (if line (point-at-bol) (point-min)))
  7985. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7986. (if line (point-at-eol) nil) t)
  7987. (add-text-properties
  7988. (match-beginning 2) (match-end 2)
  7989. (list 'face (delq nil (let ((prop (get-text-property
  7990. (match-beginning 2) 'face)))
  7991. (or (listp prop) (setq prop (list prop)))
  7992. (if (memq 'org-tag prop)
  7993. prop
  7994. (cons 'org-tag prop))))))
  7995. (setq l (- (match-end 2) (match-beginning 2))
  7996. c (if (< org-agenda-tags-column 0)
  7997. (- (abs org-agenda-tags-column) l)
  7998. org-agenda-tags-column))
  7999. (delete-region (match-beginning 1) (match-end 1))
  8000. (goto-char (match-beginning 1))
  8001. (insert (org-add-props
  8002. (make-string (max 1 (- c (current-column))) ?\ )
  8003. (plist-put (copy-sequence (text-properties-at (point)))
  8004. 'face nil))))
  8005. (goto-char (point-min))
  8006. (org-font-lock-add-tag-faces (point-max)))))
  8007. (defun org-agenda-priority-up ()
  8008. "Increase the priority of line at point, also in Org-mode file."
  8009. (interactive)
  8010. (org-agenda-priority 'up))
  8011. (defun org-agenda-priority-down ()
  8012. "Decrease the priority of line at point, also in Org-mode file."
  8013. (interactive)
  8014. (org-agenda-priority 'down))
  8015. (defun org-agenda-priority (&optional force-direction)
  8016. "Set the priority of line at point, also in Org-mode file.
  8017. This changes the line at point, all other lines in the agenda referring to
  8018. the same tree node, and the headline of the tree node in the Org-mode file.
  8019. Called with a universal prefix arg, show the priority instead of setting it."
  8020. (interactive "P")
  8021. (if (equal force-direction '(4))
  8022. (org-show-priority)
  8023. (unless org-enable-priority-commands
  8024. (error "Priority commands are disabled"))
  8025. (org-agenda-check-no-diary)
  8026. (let* ((marker (or (org-get-at-bol 'org-marker)
  8027. (org-agenda-error)))
  8028. (hdmarker (org-get-at-bol 'org-hd-marker))
  8029. (buffer (marker-buffer hdmarker))
  8030. (pos (marker-position hdmarker))
  8031. (inhibit-read-only t)
  8032. newhead)
  8033. (org-with-remote-undo buffer
  8034. (with-current-buffer buffer
  8035. (widen)
  8036. (goto-char pos)
  8037. (org-show-context 'agenda)
  8038. (save-excursion
  8039. (and (outline-next-heading)
  8040. (org-flag-heading nil))) ; show the next heading
  8041. (funcall 'org-priority force-direction)
  8042. (end-of-line 1)
  8043. (setq newhead (org-get-heading)))
  8044. (org-agenda-change-all-lines newhead hdmarker)
  8045. (beginning-of-line 1)))))
  8046. ;; FIXME: should fix the tags property of the agenda line.
  8047. (defun org-agenda-set-tags (&optional tag onoff)
  8048. "Set tags for the current headline."
  8049. (interactive)
  8050. (org-agenda-check-no-diary)
  8051. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8052. (call-interactively 'org-change-tag-in-region)
  8053. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8054. (org-agenda-error)))
  8055. (buffer (marker-buffer hdmarker))
  8056. (pos (marker-position hdmarker))
  8057. (inhibit-read-only t)
  8058. newhead)
  8059. (org-with-remote-undo buffer
  8060. (with-current-buffer buffer
  8061. (widen)
  8062. (goto-char pos)
  8063. (save-excursion
  8064. (org-show-context 'agenda))
  8065. (save-excursion
  8066. (and (outline-next-heading)
  8067. (org-flag-heading nil))) ; show the next heading
  8068. (goto-char pos)
  8069. (if tag
  8070. (org-toggle-tag tag onoff)
  8071. (call-interactively 'org-set-tags))
  8072. (end-of-line 1)
  8073. (setq newhead (org-get-heading)))
  8074. (org-agenda-change-all-lines newhead hdmarker)
  8075. (beginning-of-line 1)))))
  8076. (defun org-agenda-set-property ()
  8077. "Set a property for the current headline."
  8078. (interactive)
  8079. (org-agenda-check-no-diary)
  8080. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8081. (org-agenda-error)))
  8082. (buffer (marker-buffer hdmarker))
  8083. (pos (marker-position hdmarker))
  8084. (inhibit-read-only t)
  8085. newhead)
  8086. (org-with-remote-undo buffer
  8087. (with-current-buffer buffer
  8088. (widen)
  8089. (goto-char pos)
  8090. (save-excursion
  8091. (org-show-context 'agenda))
  8092. (save-excursion
  8093. (and (outline-next-heading)
  8094. (org-flag-heading nil))) ; show the next heading
  8095. (goto-char pos)
  8096. (call-interactively 'org-set-property)))))
  8097. (defun org-agenda-set-effort ()
  8098. "Set the effort property for the current headline."
  8099. (interactive)
  8100. (org-agenda-check-no-diary)
  8101. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8102. (org-agenda-error)))
  8103. (buffer (marker-buffer hdmarker))
  8104. (pos (marker-position hdmarker))
  8105. (inhibit-read-only t)
  8106. newhead)
  8107. (org-with-remote-undo buffer
  8108. (with-current-buffer buffer
  8109. (widen)
  8110. (goto-char pos)
  8111. (save-excursion
  8112. (org-show-context 'agenda))
  8113. (save-excursion
  8114. (and (outline-next-heading)
  8115. (org-flag-heading nil))) ; show the next heading
  8116. (goto-char pos)
  8117. (call-interactively 'org-set-effort)
  8118. (end-of-line 1)
  8119. (setq newhead (org-get-heading)))
  8120. (org-agenda-change-all-lines newhead hdmarker))))
  8121. (defun org-agenda-toggle-archive-tag ()
  8122. "Toggle the archive tag for the current entry."
  8123. (interactive)
  8124. (org-agenda-check-no-diary)
  8125. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8126. (org-agenda-error)))
  8127. (buffer (marker-buffer hdmarker))
  8128. (pos (marker-position hdmarker))
  8129. (inhibit-read-only t)
  8130. newhead)
  8131. (org-with-remote-undo buffer
  8132. (with-current-buffer buffer
  8133. (widen)
  8134. (goto-char pos)
  8135. (org-show-context 'agenda)
  8136. (save-excursion
  8137. (and (outline-next-heading)
  8138. (org-flag-heading nil))) ; show the next heading
  8139. (call-interactively 'org-toggle-archive-tag)
  8140. (end-of-line 1)
  8141. (setq newhead (org-get-heading)))
  8142. (org-agenda-change-all-lines newhead hdmarker)
  8143. (beginning-of-line 1))))
  8144. (defun org-agenda-do-date-later (arg)
  8145. (interactive "P")
  8146. (cond
  8147. ((or (equal arg '(16))
  8148. (memq last-command
  8149. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8150. (setq this-command 'org-agenda-date-later-minutes)
  8151. (org-agenda-date-later-minutes 1))
  8152. ((or (equal arg '(4))
  8153. (memq last-command
  8154. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8155. (setq this-command 'org-agenda-date-later-hours)
  8156. (org-agenda-date-later-hours 1))
  8157. (t
  8158. (org-agenda-date-later (prefix-numeric-value arg)))))
  8159. (defun org-agenda-do-date-earlier (arg)
  8160. (interactive "P")
  8161. (cond
  8162. ((or (equal arg '(16))
  8163. (memq last-command
  8164. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8165. (setq this-command 'org-agenda-date-earlier-minutes)
  8166. (org-agenda-date-earlier-minutes 1))
  8167. ((or (equal arg '(4))
  8168. (memq last-command
  8169. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8170. (setq this-command 'org-agenda-date-earlier-hours)
  8171. (org-agenda-date-earlier-hours 1))
  8172. (t
  8173. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8174. (defun org-agenda-date-later (arg &optional what)
  8175. "Change the date of this item to ARG day(s) later."
  8176. (interactive "p")
  8177. (org-agenda-check-type t 'agenda 'timeline)
  8178. (org-agenda-check-no-diary)
  8179. (let* ((marker (or (org-get-at-bol 'org-marker)
  8180. (org-agenda-error)))
  8181. (buffer (marker-buffer marker))
  8182. (pos (marker-position marker))
  8183. cdate today)
  8184. (org-with-remote-undo buffer
  8185. (with-current-buffer buffer
  8186. (widen)
  8187. (goto-char pos)
  8188. (if (not (org-at-timestamp-p))
  8189. (error "Cannot find time stamp"))
  8190. (when (and org-agenda-move-date-from-past-immediately-to-today
  8191. (equal arg 1)
  8192. (or (not what) (eq what 'day))
  8193. (not (save-match-data (org-at-date-range-p))))
  8194. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8195. cdate (calendar-absolute-from-gregorian
  8196. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8197. today (org-today))
  8198. (if (> today cdate)
  8199. ;; immediately shift to today
  8200. (setq arg (- today cdate))))
  8201. (org-timestamp-change arg (or what 'day))
  8202. (when (and (org-at-date-range-p)
  8203. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8204. (let ((end org-last-changed-timestamp))
  8205. (org-timestamp-change arg (or what 'day))
  8206. (setq org-last-changed-timestamp
  8207. (concat org-last-changed-timestamp "--" end)))))
  8208. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8209. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8210. (defun org-agenda-date-earlier (arg &optional what)
  8211. "Change the date of this item to ARG day(s) earlier."
  8212. (interactive "p")
  8213. (org-agenda-date-later (- arg) what))
  8214. (defun org-agenda-date-later-minutes (arg)
  8215. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8216. (interactive "p")
  8217. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8218. (org-agenda-date-later arg 'minute))
  8219. (defun org-agenda-date-earlier-minutes (arg)
  8220. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8221. (interactive "p")
  8222. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8223. (org-agenda-date-earlier arg 'minute))
  8224. (defun org-agenda-date-later-hours (arg)
  8225. "Change the time of this item, in hour steps."
  8226. (interactive "p")
  8227. (org-agenda-date-later arg 'hour))
  8228. (defun org-agenda-date-earlier-hours (arg)
  8229. "Change the time of this item, in hour steps."
  8230. (interactive "p")
  8231. (org-agenda-date-earlier arg 'hour))
  8232. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8233. "Show new date stamp via text properties."
  8234. ;; We use text properties to make this undoable
  8235. (let ((inhibit-read-only t))
  8236. (setq stamp (concat prefix " => " stamp " "))
  8237. (save-excursion
  8238. (goto-char (point-max))
  8239. (while (not (bobp))
  8240. (when (equal marker (org-get-at-bol 'org-marker))
  8241. (org-move-to-column (- (window-width) (length stamp)) t)
  8242. (org-agenda-fix-tags-filter-overlays-at (point))
  8243. (if (featurep 'xemacs)
  8244. ;; Use `duplicable' property to trigger undo recording
  8245. (let ((ex (make-extent nil nil))
  8246. (gl (make-glyph stamp)))
  8247. (set-glyph-face gl 'secondary-selection)
  8248. (set-extent-properties
  8249. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8250. (insert-extent ex (1- (point)) (point-at-eol)))
  8251. (add-text-properties
  8252. (1- (point)) (point-at-eol)
  8253. (list 'display (org-add-props stamp nil
  8254. 'face 'secondary-selection))))
  8255. (beginning-of-line 1))
  8256. (beginning-of-line 0)))))
  8257. (defun org-agenda-date-prompt (arg)
  8258. "Change the date of this item. Date is prompted for, with default today.
  8259. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8260. be used to request time specification in the time stamp."
  8261. (interactive "P")
  8262. (org-agenda-check-type t 'agenda 'timeline)
  8263. (org-agenda-check-no-diary)
  8264. (let* ((marker (or (org-get-at-bol 'org-marker)
  8265. (org-agenda-error)))
  8266. (buffer (marker-buffer marker))
  8267. (pos (marker-position marker)))
  8268. (org-with-remote-undo buffer
  8269. (with-current-buffer buffer
  8270. (widen)
  8271. (goto-char pos)
  8272. (if (not (org-at-timestamp-p t))
  8273. (error "Cannot find time stamp"))
  8274. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8275. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8276. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8277. (defun org-agenda-schedule (arg &optional time)
  8278. "Schedule the item at point.
  8279. ARG is passed through to `org-schedule'."
  8280. (interactive "P")
  8281. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8282. (org-agenda-check-no-diary)
  8283. (let* ((marker (or (org-get-at-bol 'org-marker)
  8284. (org-agenda-error)))
  8285. (type (marker-insertion-type marker))
  8286. (buffer (marker-buffer marker))
  8287. (pos (marker-position marker))
  8288. (org-insert-labeled-timestamps-at-point nil)
  8289. ts)
  8290. (set-marker-insertion-type marker t)
  8291. (org-with-remote-undo buffer
  8292. (with-current-buffer buffer
  8293. (widen)
  8294. (goto-char pos)
  8295. (setq ts (org-schedule arg time)))
  8296. (org-agenda-show-new-time marker ts " S"))
  8297. (message "%s" ts)))
  8298. (defun org-agenda-deadline (arg &optional time)
  8299. "Schedule the item at point.
  8300. ARG is passed through to `org-deadline'."
  8301. (interactive "P")
  8302. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8303. (org-agenda-check-no-diary)
  8304. (let* ((marker (or (org-get-at-bol 'org-marker)
  8305. (org-agenda-error)))
  8306. (buffer (marker-buffer marker))
  8307. (pos (marker-position marker))
  8308. (org-insert-labeled-timestamps-at-point nil)
  8309. ts)
  8310. (org-with-remote-undo buffer
  8311. (with-current-buffer buffer
  8312. (widen)
  8313. (goto-char pos)
  8314. (setq ts (org-deadline arg time)))
  8315. (org-agenda-show-new-time marker ts " D"))
  8316. (message "%s" ts)))
  8317. (defun org-agenda-clock-in (&optional arg)
  8318. "Start the clock on the currently selected item."
  8319. (interactive "P")
  8320. (org-agenda-check-no-diary)
  8321. (if (equal arg '(4))
  8322. (org-clock-in arg)
  8323. (let* ((marker (or (org-get-at-bol 'org-marker)
  8324. (org-agenda-error)))
  8325. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8326. (pos (marker-position marker))
  8327. (col (current-column))
  8328. newhead)
  8329. (org-with-remote-undo (marker-buffer marker)
  8330. (with-current-buffer (marker-buffer marker)
  8331. (widen)
  8332. (goto-char pos)
  8333. (org-show-context 'agenda)
  8334. (org-show-entry)
  8335. (org-cycle-hide-drawers 'children)
  8336. (org-clock-in arg)
  8337. (setq newhead (org-get-heading)))
  8338. (org-agenda-change-all-lines newhead hdmarker))
  8339. (org-move-to-column col))))
  8340. (defun org-agenda-clock-out ()
  8341. "Stop the currently running clock."
  8342. (interactive)
  8343. (unless (marker-buffer org-clock-marker)
  8344. (error "No running clock"))
  8345. (let ((marker (make-marker)) (col (current-column)) newhead)
  8346. (org-with-remote-undo (marker-buffer org-clock-marker)
  8347. (with-current-buffer (marker-buffer org-clock-marker)
  8348. (save-excursion
  8349. (save-restriction
  8350. (widen)
  8351. (goto-char org-clock-marker)
  8352. (org-back-to-heading t)
  8353. (move-marker marker (point))
  8354. (org-clock-out)
  8355. (setq newhead (org-get-heading))))))
  8356. (org-agenda-change-all-lines newhead marker)
  8357. (move-marker marker nil)
  8358. (org-move-to-column col)
  8359. (org-agenda-unmark-clocking-task)))
  8360. (defun org-agenda-clock-cancel (&optional arg)
  8361. "Cancel the currently running clock."
  8362. (interactive "P")
  8363. (unless (marker-buffer org-clock-marker)
  8364. (error "No running clock"))
  8365. (org-with-remote-undo (marker-buffer org-clock-marker)
  8366. (org-clock-cancel)))
  8367. (defun org-agenda-clock-goto ()
  8368. "Jump to the currently clocked in task within the agenda.
  8369. If the currently clocked in task is not listed in the agenda
  8370. buffer, display it in another window."
  8371. (interactive)
  8372. (let (pos)
  8373. (mapc (lambda (o)
  8374. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8375. (setq pos (overlay-start o))))
  8376. (overlays-in (point-min) (point-max)))
  8377. (cond (pos (goto-char pos))
  8378. ;; If the currently clocked entry is not in the agenda
  8379. ;; buffer, we visit it in another window:
  8380. (org-clock-current-task
  8381. (org-switch-to-buffer-other-window (org-clock-goto)))
  8382. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8383. (defun org-agenda-diary-entry-in-org-file ()
  8384. "Make a diary entry in the file `org-agenda-diary-file'."
  8385. (let (d1 d2 char (text "") dp1 dp2)
  8386. (if (equal (buffer-name) "*Calendar*")
  8387. (setq d1 (calendar-cursor-to-date t)
  8388. d2 (car calendar-mark-ring))
  8389. (setq dp1 (get-text-property (point-at-bol) 'day))
  8390. (unless dp1 (error "No date defined in current line"))
  8391. (setq d1 (calendar-gregorian-from-absolute dp1)
  8392. d2 (and (ignore-errors (mark))
  8393. (save-excursion
  8394. (goto-char (mark))
  8395. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8396. (calendar-gregorian-from-absolute dp2))))
  8397. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8398. (setq char (read-char-exclusive))
  8399. (cond
  8400. ((equal char ?d)
  8401. (setq text (read-string "Day entry: "))
  8402. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8403. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8404. ((equal char ?a)
  8405. (setq d1 (list (car d1) (nth 1 d1)
  8406. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8407. (nth 2 d1))))
  8408. (setq text (read-string "Anniversary (use %d to show years): "))
  8409. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8410. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8411. ((equal char ?b)
  8412. (setq text (read-string "Block entry: "))
  8413. (unless (and d1 d2 (not (equal d1 d2)))
  8414. (error "No block of days selected"))
  8415. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8416. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8417. ((equal char ?j)
  8418. (org-switch-to-buffer-other-window
  8419. (find-file-noselect org-agenda-diary-file))
  8420. (require 'org-datetree)
  8421. (org-datetree-find-date-create d1)
  8422. (org-reveal t))
  8423. (t (error "Invalid selection character `%c'" char)))))
  8424. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8425. "Where in `org-agenda-diary-file' should new entries be added?
  8426. Valid values:
  8427. date-tree in the date tree, as child of the date
  8428. top-level as top-level entries at the end of the file."
  8429. :group 'org-agenda
  8430. :type '(choice
  8431. (const :tag "in a date tree" date-tree)
  8432. (const :tag "as top level at end of file" top-level)))
  8433. (defcustom org-agenda-insert-diary-extract-time nil
  8434. "Non-nil means extract any time specification from the diary entry."
  8435. :group 'org-agenda
  8436. :version "24.1"
  8437. :type 'boolean)
  8438. (defcustom org-agenda-bulk-mark-char ">"
  8439. "A single-character string to be used as the bulk mark."
  8440. :group 'org-agenda
  8441. :version "24.1"
  8442. :type 'string)
  8443. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8444. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8445. If TEXT is not empty, it will become the headline of the new entry, and
  8446. the resulting entry will not be shown. When TEXT is empty, switch to
  8447. `org-agenda-diary-file' and let the user finish the entry there."
  8448. (let ((cw (current-window-configuration)))
  8449. (org-switch-to-buffer-other-window
  8450. (find-file-noselect org-agenda-diary-file))
  8451. (widen)
  8452. (goto-char (point-min))
  8453. (cond
  8454. ((eq type 'anniversary)
  8455. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8456. (progn
  8457. (or (org-at-heading-p t)
  8458. (progn
  8459. (outline-next-heading)
  8460. (insert "* Anniversaries\n\n")
  8461. (beginning-of-line -1)))))
  8462. (outline-next-heading)
  8463. (org-back-over-empty-lines)
  8464. (backward-char 1)
  8465. (insert "\n")
  8466. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8467. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8468. ((eq type 'day)
  8469. (let ((org-prefix-has-time t)
  8470. (org-agenda-time-leading-zero t)
  8471. fmt time time2)
  8472. (if org-agenda-insert-diary-extract-time
  8473. ;; Use org-agenda-format-item to parse text for a time-range and
  8474. ;; remove it. FIXME: This is a hack, we should refactor
  8475. ;; that function to make time extraction available separately
  8476. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8477. time (get-text-property 0 'time fmt)
  8478. time2 (if (> (length time) 0)
  8479. ;; split-string removes trailing ...... if
  8480. ;; no end time given. First space
  8481. ;; separates time from date.
  8482. (concat " " (car (split-string time "\\.")))
  8483. nil)
  8484. text (get-text-property 0 'txt fmt)))
  8485. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8486. (org-agenda-insert-diary-as-top-level text)
  8487. (require 'org-datetree)
  8488. (org-datetree-find-date-create d1)
  8489. (org-agenda-insert-diary-make-new-entry text))
  8490. (org-insert-time-stamp (org-time-from-absolute
  8491. (calendar-absolute-from-gregorian d1))
  8492. nil nil nil nil time2))
  8493. (end-of-line 0))
  8494. ((eq type 'block)
  8495. (if (> (calendar-absolute-from-gregorian d1)
  8496. (calendar-absolute-from-gregorian d2))
  8497. (setq d1 (prog1 d2 (setq d2 d1))))
  8498. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8499. (org-agenda-insert-diary-as-top-level text)
  8500. (require 'org-datetree)
  8501. (org-datetree-find-date-create d1)
  8502. (org-agenda-insert-diary-make-new-entry text))
  8503. (org-insert-time-stamp (org-time-from-absolute
  8504. (calendar-absolute-from-gregorian d1)))
  8505. (insert "--")
  8506. (org-insert-time-stamp (org-time-from-absolute
  8507. (calendar-absolute-from-gregorian d2)))
  8508. (end-of-line 0)))
  8509. (if (string-match "\\S-" text)
  8510. (progn
  8511. (set-window-configuration cw)
  8512. (message "%s entry added to %s"
  8513. (capitalize (symbol-name type))
  8514. (abbreviate-file-name org-agenda-diary-file)))
  8515. (org-reveal t)
  8516. (message "Please finish entry here"))))
  8517. (defun org-agenda-insert-diary-as-top-level (text)
  8518. "Make new entry as a top-level entry at the end of the file.
  8519. Add TEXT as headline, and position the cursor in the second line so that
  8520. a timestamp can be added there."
  8521. (widen)
  8522. (goto-char (point-max))
  8523. (or (bolp) (insert "\n"))
  8524. (insert "* " text "\n")
  8525. (if org-adapt-indentation (org-indent-to-column 2)))
  8526. (defun org-agenda-insert-diary-make-new-entry (text)
  8527. "Make new entry as last child of current entry.
  8528. Add TEXT as headline, and position the cursor in the second line so that
  8529. a timestamp can be added there."
  8530. (let ((org-show-following-heading t)
  8531. (org-show-siblings t)
  8532. (org-show-hierarchy-above t)
  8533. (org-show-entry-below t)
  8534. col)
  8535. (outline-next-heading)
  8536. (org-back-over-empty-lines)
  8537. (or (looking-at "[ \t]*$")
  8538. (progn (insert "\n") (backward-char 1)))
  8539. (org-insert-heading nil t)
  8540. (org-do-demote)
  8541. (setq col (current-column))
  8542. (insert text "\n")
  8543. (if org-adapt-indentation (org-indent-to-column col))
  8544. (let ((org-show-following-heading t)
  8545. (org-show-siblings t)
  8546. (org-show-hierarchy-above t)
  8547. (org-show-entry-below t))
  8548. (org-show-context))))
  8549. (defun org-agenda-diary-entry ()
  8550. "Make a diary entry, like the `i' command from the calendar.
  8551. All the standard commands work: block, weekly etc.
  8552. When `org-agenda-diary-file' points to a file,
  8553. `org-agenda-diary-entry-in-org-file' is called instead to create
  8554. entries in that Org-mode file."
  8555. (interactive)
  8556. (if (not (eq org-agenda-diary-file 'diary-file))
  8557. (org-agenda-diary-entry-in-org-file)
  8558. (require 'diary-lib)
  8559. (let* ((char (progn
  8560. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8561. (read-char-exclusive)))
  8562. (cmd (cdr (assoc char
  8563. '((?d . insert-diary-entry)
  8564. (?w . insert-weekly-diary-entry)
  8565. (?m . insert-monthly-diary-entry)
  8566. (?y . insert-yearly-diary-entry)
  8567. (?a . insert-anniversary-diary-entry)
  8568. (?b . insert-block-diary-entry)
  8569. (?c . insert-cyclic-diary-entry)))))
  8570. (oldf (symbol-function 'calendar-cursor-to-date))
  8571. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8572. (point (point))
  8573. (mark (or (mark t) (point))))
  8574. (unless cmd
  8575. (error "No command associated with <%c>" char))
  8576. (unless (and (get-text-property point 'day)
  8577. (or (not (equal ?b char))
  8578. (get-text-property mark 'day)))
  8579. (error "Don't know which date to use for diary entry"))
  8580. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8581. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8582. (let ((calendar-mark-ring
  8583. (list (calendar-gregorian-from-absolute
  8584. (or (get-text-property mark 'day)
  8585. (get-text-property point 'day))))))
  8586. (unwind-protect
  8587. (progn
  8588. (fset 'calendar-cursor-to-date
  8589. (lambda (&optional error dummy)
  8590. (calendar-gregorian-from-absolute
  8591. (get-text-property point 'day))))
  8592. (call-interactively cmd))
  8593. (fset 'calendar-cursor-to-date oldf))))))
  8594. (defun org-agenda-execute-calendar-command (cmd)
  8595. "Execute a calendar command from the agenda with date from cursor."
  8596. (org-agenda-check-type t 'agenda 'timeline)
  8597. (require 'diary-lib)
  8598. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8599. (error "Don't know which date to use for the calendar command"))
  8600. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8601. (point (point))
  8602. (date (calendar-gregorian-from-absolute
  8603. (get-text-property point 'day)))
  8604. ;; the following 2 vars are needed in the calendar
  8605. (displayed-month (car date))
  8606. (displayed-year (nth 2 date)))
  8607. (unwind-protect
  8608. (progn
  8609. (fset 'calendar-cursor-to-date
  8610. (lambda (&optional error dummy)
  8611. (calendar-gregorian-from-absolute
  8612. (get-text-property point 'day))))
  8613. (call-interactively cmd))
  8614. (fset 'calendar-cursor-to-date oldf))))
  8615. (defun org-agenda-phases-of-moon ()
  8616. "Display the phases of the moon for the 3 months around the cursor date."
  8617. (interactive)
  8618. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8619. (defun org-agenda-holidays ()
  8620. "Display the holidays for the 3 months around the cursor date."
  8621. (interactive)
  8622. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8623. (defvar calendar-longitude) ; defined in calendar.el
  8624. (defvar calendar-latitude) ; defined in calendar.el
  8625. (defvar calendar-location-name) ; defined in calendar.el
  8626. (defun org-agenda-sunrise-sunset (arg)
  8627. "Display sunrise and sunset for the cursor date.
  8628. Latitude and longitude can be specified with the variables
  8629. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8630. argument, latitude and longitude will be prompted for."
  8631. (interactive "P")
  8632. (require 'solar)
  8633. (let ((calendar-longitude (if arg nil calendar-longitude))
  8634. (calendar-latitude (if arg nil calendar-latitude))
  8635. (calendar-location-name
  8636. (if arg "the given coordinates" calendar-location-name)))
  8637. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8638. (defun org-agenda-goto-calendar ()
  8639. "Open the Emacs calendar with the date at the cursor."
  8640. (interactive)
  8641. (org-agenda-check-type t 'agenda 'timeline)
  8642. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8643. (error "Don't know which date to open in calendar")))
  8644. (date (calendar-gregorian-from-absolute day))
  8645. (calendar-move-hook nil)
  8646. (calendar-view-holidays-initially-flag nil)
  8647. (calendar-view-diary-initially-flag nil))
  8648. (calendar)
  8649. (calendar-goto-date date)))
  8650. ;;;###autoload
  8651. (defun org-calendar-goto-agenda ()
  8652. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8653. This is a command that has to be installed in `calendar-mode-map'."
  8654. (interactive)
  8655. (org-agenda-list nil (calendar-absolute-from-gregorian
  8656. (calendar-cursor-to-date))
  8657. nil))
  8658. (defun org-agenda-convert-date ()
  8659. (interactive)
  8660. (org-agenda-check-type t 'agenda 'timeline)
  8661. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8662. date s)
  8663. (unless day
  8664. (error "Don't know which date to convert"))
  8665. (setq date (calendar-gregorian-from-absolute day))
  8666. (setq s (concat
  8667. "Gregorian: " (calendar-date-string date) "\n"
  8668. "ISO: " (calendar-iso-date-string date) "\n"
  8669. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8670. "Julian: " (calendar-julian-date-string date) "\n"
  8671. "Astron. JD: " (calendar-astro-date-string date)
  8672. " (Julian date number at noon UTC)\n"
  8673. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8674. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8675. "French: " (calendar-french-date-string date) "\n"
  8676. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8677. "Mayan: " (calendar-mayan-date-string date) "\n"
  8678. "Coptic: " (calendar-coptic-date-string date) "\n"
  8679. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8680. "Persian: " (calendar-persian-date-string date) "\n"
  8681. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8682. (with-output-to-temp-buffer "*Dates*"
  8683. (princ s))
  8684. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8685. ;;; Bulk commands
  8686. (defun org-agenda-bulk-marked-p ()
  8687. (eq (get-char-property (point-at-bol) 'type)
  8688. 'org-marked-entry-overlay))
  8689. (defun org-agenda-bulk-mark (&optional arg)
  8690. "Mark the entry at point for future bulk action."
  8691. (interactive "p")
  8692. (dotimes (i (or arg 1))
  8693. (unless (org-get-at-bol 'org-agenda-diary-link)
  8694. (let* ((m (org-get-at-bol 'org-hd-marker))
  8695. ov)
  8696. (unless (org-agenda-bulk-marked-p)
  8697. (unless m (error "Nothing to mark at point"))
  8698. (push m org-agenda-bulk-marked-entries)
  8699. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8700. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8701. (org-get-todo-face "TODO")
  8702. 'evaporate)
  8703. (overlay-put ov 'type 'org-marked-entry-overlay))
  8704. (beginning-of-line 2)
  8705. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8706. (beginning-of-line 2))
  8707. (message "%d entries marked for bulk action"
  8708. (length org-agenda-bulk-marked-entries))))))
  8709. (defun org-agenda-bulk-mark-all ()
  8710. "Mark all entries for future agenda bulk action."
  8711. (interactive)
  8712. (org-agenda-bulk-mark-regexp "."))
  8713. (defun org-agenda-bulk-mark-regexp (regexp)
  8714. "Mark entries matching REGEXP for future agenda bulk action."
  8715. (interactive "sMark entries matching regexp: ")
  8716. (let ((entries-marked 0))
  8717. (save-excursion
  8718. (goto-char (point-min))
  8719. (goto-char (next-single-property-change (point) 'txt))
  8720. (while (re-search-forward regexp nil t)
  8721. (when (string-match regexp (get-text-property (point) 'txt))
  8722. (setq entries-marked (1+ entries-marked))
  8723. (call-interactively 'org-agenda-bulk-mark))))
  8724. (if (not entries-marked)
  8725. (message "No entry matching this regexp."))))
  8726. (defun org-agenda-bulk-unmark (&optional arg)
  8727. "Unmark the entry at point for future bulk action."
  8728. (interactive "P")
  8729. (if arg
  8730. (org-agenda-bulk-unmark-all)
  8731. (cond ((org-agenda-bulk-marked-p)
  8732. (org-agenda-bulk-remove-overlays
  8733. (point-at-bol) (+ 2 (point-at-bol)))
  8734. (setq org-agenda-bulk-marked-entries
  8735. (delete (org-get-at-bol 'org-hd-marker)
  8736. org-agenda-bulk-marked-entries))
  8737. (beginning-of-line 2)
  8738. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8739. (beginning-of-line 2))
  8740. (message "%d entries left marked for bulk action"
  8741. (length org-agenda-bulk-marked-entries)))
  8742. (t (message "No entry to unmark here")))))
  8743. (defun org-agenda-bulk-toggle ()
  8744. "Toggle marking the entry at point for bulk action."
  8745. (interactive)
  8746. (if (org-agenda-bulk-marked-p)
  8747. (org-agenda-bulk-unmark)
  8748. (org-agenda-bulk-mark)))
  8749. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8750. "Remove the mark overlays between BEG and END in the agenda buffer.
  8751. BEG and END default to the buffer limits.
  8752. This only removes the overlays, it does not remove the markers
  8753. from the list in `org-agenda-bulk-marked-entries'."
  8754. (interactive)
  8755. (mapc (lambda (ov)
  8756. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8757. (delete-overlay ov)))
  8758. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8759. (defun org-agenda-bulk-unmark-all ()
  8760. "Remove all marks in the agenda buffer.
  8761. This will remove the markers and the overlays."
  8762. (interactive)
  8763. (if (null org-agenda-bulk-marked-entries)
  8764. (message "No entry to unmark")
  8765. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8766. (setq org-agenda-bulk-marked-entries nil)
  8767. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8768. (defcustom org-agenda-persistent-marks nil
  8769. "Non-nil means marked items will stay marked after a bulk action.
  8770. You can toggle this interactively by typing `p' when prompted for a
  8771. bulk action."
  8772. :group 'org-agenda
  8773. :version "24.1"
  8774. :type 'boolean)
  8775. (defun org-agenda-bulk-action (&optional arg)
  8776. "Execute an remote-editing action on all marked entries.
  8777. The prefix arg is passed through to the command if possible."
  8778. (interactive "P")
  8779. ;; Make sure we have markers, and only valid ones
  8780. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8781. (mapc
  8782. (lambda (m)
  8783. (unless (and (markerp m)
  8784. (marker-buffer m)
  8785. (buffer-live-p (marker-buffer m))
  8786. (marker-position m))
  8787. (error "Marker %s for bulk command is invalid" m)))
  8788. org-agenda-bulk-marked-entries)
  8789. ;; Prompt for the bulk command
  8790. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8791. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8792. "[S]catter [f]unction "
  8793. (when org-agenda-bulk-custom-functions
  8794. (concat " Custom: ["
  8795. (mapconcat (lambda(f) (char-to-string (car f)))
  8796. org-agenda-bulk-custom-functions "")
  8797. "]"))))
  8798. (catch 'exit
  8799. (let* ((action (read-char-exclusive))
  8800. (org-log-refile (if org-log-refile 'time nil))
  8801. (entries (reverse org-agenda-bulk-marked-entries))
  8802. (org-overriding-default-time
  8803. (if (get-text-property (point) 'org-agenda-date-header)
  8804. (org-get-cursor-date)))
  8805. redo-at-end
  8806. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8807. (cond
  8808. ((equal action ?p)
  8809. (let ((org-agenda-persistent-marks
  8810. (not org-agenda-persistent-marks)))
  8811. (org-agenda-bulk-action)
  8812. (throw 'exit nil)))
  8813. ((equal action ?$)
  8814. (setq cmd '(org-agenda-archive)))
  8815. ((equal action ?A)
  8816. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8817. ((member action '(?r ?w))
  8818. (setq rfloc (org-refile-get-location
  8819. "Refile to"
  8820. (marker-buffer (car entries))
  8821. org-refile-allow-creating-parent-nodes))
  8822. (if (nth 3 rfloc)
  8823. (setcar (nthcdr 3 rfloc)
  8824. (move-marker (make-marker) (nth 3 rfloc)
  8825. (or (get-file-buffer (nth 1 rfloc))
  8826. (find-buffer-visiting (nth 1 rfloc))
  8827. (error "This should not happen")))))
  8828. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8829. redo-at-end t))
  8830. ((equal action ?t)
  8831. (setq state (org-icompleting-read
  8832. "Todo state: "
  8833. (with-current-buffer (marker-buffer (car entries))
  8834. (mapcar 'list org-todo-keywords-1))))
  8835. (setq cmd `(let ((org-inhibit-blocking t)
  8836. (org-inhibit-logging 'note))
  8837. (org-agenda-todo ,state))))
  8838. ((memq action '(?- ?+))
  8839. (setq tag (org-icompleting-read
  8840. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8841. (with-current-buffer (marker-buffer (car entries))
  8842. (delq nil
  8843. (mapcar (lambda (x)
  8844. (if (stringp (car x)) x)) org-tag-alist)))))
  8845. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8846. ((memq action '(?s ?d))
  8847. (let* ((time
  8848. (unless arg
  8849. (org-read-date
  8850. nil nil nil
  8851. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8852. org-overriding-default-time)))
  8853. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8854. (setq cmd `(eval '(,c1 arg ,time)))))
  8855. ((equal action ?S)
  8856. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8857. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8858. (let ((days (read-number
  8859. (format "Scatter tasks across how many %sdays: "
  8860. (if arg "week" "")) 7)))
  8861. (setq cmd
  8862. `(let ((distance (1+ (random ,days))))
  8863. (if arg
  8864. (let ((dist distance)
  8865. (day-of-week
  8866. (calendar-day-of-week
  8867. (calendar-gregorian-from-absolute (org-today)))))
  8868. (dotimes (i (1+ dist))
  8869. (while (member day-of-week org-agenda-weekend-days)
  8870. (incf distance)
  8871. (incf day-of-week)
  8872. (if (= day-of-week 7)
  8873. (setq day-of-week 0)))
  8874. (incf day-of-week)
  8875. (if (= day-of-week 7)
  8876. (setq day-of-week 0)))))
  8877. ;; silently fail when try to replan a sexp entry
  8878. (condition-case nil
  8879. (let* ((date (calendar-gregorian-from-absolute
  8880. (+ (org-today) distance)))
  8881. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8882. (nth 2 date))))
  8883. (org-agenda-schedule nil time))
  8884. (error nil)))))))
  8885. ((assoc action org-agenda-bulk-custom-functions)
  8886. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8887. redo-at-end t))
  8888. ((equal action ?f)
  8889. (setq cmd (list (intern
  8890. (org-icompleting-read "Function: "
  8891. obarray 'fboundp t nil nil)))))
  8892. (t (error "Invalid bulk action")))
  8893. ;; Sort the markers, to make sure that parents are handled before children
  8894. (setq entries (sort entries
  8895. (lambda (a b)
  8896. (cond
  8897. ((equal (marker-buffer a) (marker-buffer b))
  8898. (< (marker-position a) (marker-position b)))
  8899. (t
  8900. (string< (buffer-name (marker-buffer a))
  8901. (buffer-name (marker-buffer b))))))))
  8902. ;; Now loop over all markers and apply cmd
  8903. (while (setq e (pop entries))
  8904. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8905. (if (not pos)
  8906. (progn (message "Skipping removed entry at %s" e)
  8907. (setq cntskip (1+ cntskip)))
  8908. (goto-char pos)
  8909. (let (org-loop-over-headlines-in-active-region)
  8910. (eval cmd))
  8911. (setq cnt (1+ cnt))))
  8912. (when redo-at-end (org-agenda-redo))
  8913. (unless org-agenda-persistent-marks
  8914. (org-agenda-bulk-unmark-all))
  8915. (message "Acted on %d entries%s%s"
  8916. cnt
  8917. (if (= cntskip 0)
  8918. ""
  8919. (format ", skipped %d (disappeared before their turn)"
  8920. cntskip))
  8921. (if (not org-agenda-persistent-marks)
  8922. "" " (kept marked)"))))))
  8923. (defun org-agenda-capture (&optional with-time)
  8924. "Call `org-capture' with the date at point.
  8925. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  8926. current HH:MM time."
  8927. (interactive "P")
  8928. (if (not (eq major-mode 'org-agenda-mode))
  8929. (user-error "You cannot do this outside of agenda buffers")
  8930. (let ((org-overriding-default-time
  8931. (org-get-cursor-date (equal with-time 1))))
  8932. (call-interactively 'org-capture))))
  8933. ;;; Flagging notes
  8934. (defun org-agenda-show-the-flagging-note ()
  8935. "Display the flagging note in the other window.
  8936. When called a second time in direct sequence, offer to remove the FLAGGING
  8937. tag and (if present) the flagging note."
  8938. (interactive)
  8939. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8940. (win (selected-window))
  8941. note heading newhead)
  8942. (unless hdmarker
  8943. (error "No linked entry at point"))
  8944. (if (and (eq this-command last-command)
  8945. (y-or-n-p "Unflag and remove any flagging note? "))
  8946. (progn
  8947. (org-agenda-remove-flag hdmarker)
  8948. (let ((win (get-buffer-window "*Flagging Note*")))
  8949. (and win (delete-window win)))
  8950. (message "Entry unflagged"))
  8951. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8952. (unless note
  8953. (error "No flagging note"))
  8954. (org-kill-new note)
  8955. (org-switch-to-buffer-other-window "*Flagging Note*")
  8956. (erase-buffer)
  8957. (insert note)
  8958. (goto-char (point-min))
  8959. (while (re-search-forward "\\\\n" nil t)
  8960. (replace-match "\n" t t))
  8961. (goto-char (point-min))
  8962. (select-window win)
  8963. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8964. (defun org-agenda-remove-flag (marker)
  8965. "Remove the FLAGGED tag and any flagging note in the entry."
  8966. (let (newhead)
  8967. (org-with-point-at marker
  8968. (org-toggle-tag "FLAGGED" 'off)
  8969. (org-entry-delete nil "THEFLAGGINGNOTE")
  8970. (setq newhead (org-get-heading)))
  8971. (org-agenda-change-all-lines newhead marker)
  8972. (message "Entry unflagged")))
  8973. (defun org-agenda-get-any-marker (&optional pos)
  8974. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8975. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8976. ;;; Appointment reminders
  8977. (defvar appt-time-msg-list) ; defined in appt.el
  8978. ;;;###autoload
  8979. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8980. "Activate appointments found in `org-agenda-files'.
  8981. With a \\[universal-argument] prefix, refresh the list of
  8982. appointments.
  8983. If FILTER is t, interactively prompt the user for a regular
  8984. expression, and filter out entries that don't match it.
  8985. If FILTER is a string, use this string as a regular expression
  8986. for filtering entries out.
  8987. If FILTER is a function, filter out entries against which
  8988. calling the function returns nil. This function takes one
  8989. argument: an entry from `org-agenda-get-day-entries'.
  8990. FILTER can also be an alist with the car of each cell being
  8991. either 'headline or 'category. For example:
  8992. '((headline \"IMPORTANT\")
  8993. (category \"Work\"))
  8994. will only add headlines containing IMPORTANT or headlines
  8995. belonging to the \"Work\" category.
  8996. ARGS are symbols indicating what kind of entries to consider.
  8997. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8998. and :timestamp entries. See the docstring of `org-diary' for
  8999. details and examples.
  9000. If an entry has a APPT_WARNTIME property, its value will be used
  9001. to override `appt-message-warning-time'."
  9002. (interactive "P")
  9003. (if refresh (setq appt-time-msg-list nil))
  9004. (if (eq filter t)
  9005. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9006. (let* ((cnt 0) ; count added events
  9007. (scope (or args '(:deadline :scheduled :timestamp)))
  9008. (org-agenda-new-buffers nil)
  9009. (org-deadline-warning-days 0)
  9010. ;; Do not use `org-today' here because appt only takes
  9011. ;; time and without date as argument, so it may pass wrong
  9012. ;; information otherwise
  9013. (today (org-date-to-gregorian
  9014. (time-to-days (current-time))))
  9015. (org-agenda-restrict nil)
  9016. (files (org-agenda-files 'unrestricted)) entries file
  9017. (org-agenda-buffer nil))
  9018. ;; Get all entries which may contain an appt
  9019. (org-agenda-prepare-buffers files)
  9020. (while (setq file (pop files))
  9021. (setq entries
  9022. (delq nil
  9023. (append entries
  9024. (apply 'org-agenda-get-day-entries
  9025. file today scope)))))
  9026. ;; Map thru entries and find if we should filter them out
  9027. (mapc
  9028. (lambda(x)
  9029. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  9030. (cat (get-text-property 1 'org-category x))
  9031. (tod (get-text-property 1 'time-of-day x))
  9032. (ok (or (null filter)
  9033. (and (stringp filter) (string-match filter evt))
  9034. (and (functionp filter) (funcall filter x))
  9035. (and (listp filter)
  9036. (let ((cat-filter (cadr (assoc 'category filter)))
  9037. (evt-filter (cadr (assoc 'headline filter))))
  9038. (or (and (stringp cat-filter)
  9039. (string-match cat-filter cat))
  9040. (and (stringp evt-filter)
  9041. (string-match evt-filter evt)))))))
  9042. (wrn (get-text-property 1 'warntime x)))
  9043. ;; FIXME: Shall we remove text-properties for the appt text?
  9044. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9045. (when (and ok tod)
  9046. (setq tod (concat "00" (number-to-string tod))
  9047. tod (when (string-match
  9048. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9049. (concat (match-string 1 tod) ":"
  9050. (match-string 2 tod))))
  9051. (if (version< emacs-version "23.3")
  9052. (appt-add tod evt)
  9053. (appt-add tod evt wrn))
  9054. (setq cnt (1+ cnt))))) entries)
  9055. (org-release-buffers org-agenda-new-buffers)
  9056. (if (eq cnt 0)
  9057. (message "No event to add")
  9058. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9059. (defun org-agenda-todayp (date)
  9060. "Does DATE mean today, when considering `org-extend-today-until'?"
  9061. (let ((today (org-today))
  9062. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9063. date)))
  9064. (eq date today)))
  9065. (defun org-agenda-todo-yesterday (&optional arg)
  9066. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9067. (interactive "P")
  9068. (let* ((hour (third (decode-time
  9069. (org-current-time))))
  9070. (org-extend-today-until (1+ hour)))
  9071. (org-agenda-todo arg)))
  9072. (provide 'org-agenda)
  9073. ;;; org-agenda.el ends here