org-agenda.el 346 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 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. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. ;; Defined somewhere in this file, but used before definition.
  80. (defvar org-agenda-buffer-name)
  81. (defvar org-agenda-overriding-header)
  82. (defvar org-agenda-title-append nil)
  83. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  84. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  85. (defvar org-agenda-undo-list)
  86. (defvar org-agenda-pending-undo-list)
  87. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  88. (defcustom org-agenda-confirm-kill 1
  89. "When set, remote killing from the agenda buffer needs confirmation.
  90. When t, a confirmation is always needed. When a number N, confirmation is
  91. only needed when the text to be killed contains more than N non-white lines."
  92. :group 'org-agenda
  93. :type '(choice
  94. (const :tag "Never" nil)
  95. (const :tag "Always" t)
  96. (integer :tag "When more than N lines")))
  97. (defcustom org-agenda-compact-blocks nil
  98. "Non-nil means make the block agenda more compact.
  99. This is done globally by leaving out lines like the agenda span
  100. name and week number or the separator lines."
  101. :group 'org-agenda
  102. :type 'boolean)
  103. (defcustom org-agenda-block-separator ?=
  104. "The separator between blocks in the agenda.
  105. If this is a string, it will be used as the separator, with a newline added.
  106. If it is a character, it will be repeated to fill the window width.
  107. If nil the separator is disabled. In `org-agenda-custom-commands' this
  108. addresses the separator between the current and the previous block."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Disabled" nil)
  112. (character)
  113. (string)))
  114. (defgroup org-agenda-export nil
  115. "Options concerning exporting agenda views in Org-mode."
  116. :tag "Org Agenda Export"
  117. :group 'org-agenda)
  118. (defcustom org-agenda-with-colors t
  119. "Non-nil means use colors in agenda views."
  120. :group 'org-agenda-export
  121. :type 'boolean)
  122. (defcustom org-agenda-exporter-settings nil
  123. "Alist of variable/value pairs that should be active during agenda export.
  124. This is a good place to set options for ps-print and for htmlize.
  125. Note that the way this is implemented, the values will be evaluated
  126. before assigned to the variables. So make sure to quote values you do
  127. *not* want evaluated, for example
  128. (setq org-agenda-exporter-settings
  129. '((ps-print-color-p 'black-white)))"
  130. :group 'org-agenda-export
  131. :type '(repeat
  132. (list
  133. (variable)
  134. (sexp :tag "Value"))))
  135. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  136. "Hook run in temporary buffer before writing it to an export file.
  137. A useful function is `org-agenda-add-entry-text'."
  138. :group 'org-agenda-export
  139. :type 'hook
  140. :options '(org-agenda-add-entry-text))
  141. (defcustom org-agenda-add-entry-text-maxlines 0
  142. "Maximum number of entry text lines to be added to agenda.
  143. This is only relevant when `org-agenda-add-entry-text' is part of
  144. `org-agenda-before-write-hook', which it is by default.
  145. When this is 0, nothing will happen. When it is greater than 0, it
  146. specifies the maximum number of lines that will be added for each entry
  147. that is listed in the agenda view.
  148. Note that this variable is not used during display, only when exporting
  149. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  150. and `org-agenda-entry-text-maxlines'."
  151. :group 'org-agenda
  152. :type 'integer)
  153. (defcustom org-agenda-add-entry-text-descriptive-links t
  154. "Non-nil means export org-links as descriptive links in agenda added text.
  155. This variable applies to the text added to the agenda when
  156. `org-agenda-add-entry-text-maxlines' is larger than 0.
  157. When this variable nil, the URL will (also) be shown."
  158. :group 'org-agenda
  159. :type 'boolean)
  160. (defcustom org-agenda-export-html-style ""
  161. "The style specification for exported HTML Agenda files.
  162. If this variable contains a string, it will replace the default <style>
  163. section as produced by `htmlize'.
  164. Since there are different ways of setting style information, this variable
  165. needs to contain the full HTML structure to provide a style, including the
  166. surrounding HTML tags. The style specifications should include definitions
  167. the fonts used by the agenda, here is an example:
  168. <style type=\"text/css\">
  169. p { font-weight: normal; color: gray; }
  170. .org-agenda-structure {
  171. font-size: 110%;
  172. color: #003399;
  173. font-weight: 600;
  174. }
  175. .org-todo {
  176. color: #cc6666;
  177. font-weight: bold;
  178. }
  179. .org-agenda-done {
  180. color: #339933;
  181. }
  182. .org-done {
  183. color: #339933;
  184. }
  185. .title { text-align: center; }
  186. .todo, .deadline { color: red; }
  187. .done { color: green; }
  188. </style>
  189. or, if you want to keep the style in a file,
  190. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  191. As the value of this option simply gets inserted into the HTML <head> header,
  192. you can \"misuse\" it to also add other text to the header. However,
  193. <style>...</style> is required, if not present the variable will be ignored."
  194. :group 'org-agenda-export
  195. :group 'org-export-html
  196. :type 'string)
  197. (defcustom org-agenda-persistent-filter nil
  198. "When set, keep filters from one agenda view to the next."
  199. :group 'org-agenda
  200. :type 'boolean)
  201. (defgroup org-agenda-custom-commands nil
  202. "Options concerning agenda views in Org-mode."
  203. :tag "Org Agenda Custom Commands"
  204. :group 'org-agenda)
  205. (defconst org-sorting-choice
  206. '(choice
  207. (const time-up) (const time-down)
  208. (const category-keep) (const category-up) (const category-down)
  209. (const tag-down) (const tag-up)
  210. (const priority-up) (const priority-down)
  211. (const todo-state-up) (const todo-state-down)
  212. (const effort-up) (const effort-down)
  213. (const habit-up) (const habit-down)
  214. (const alpha-up) (const alpha-down)
  215. (const user-defined-up) (const user-defined-down))
  216. "Sorting choices.")
  217. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  218. ;; the new variable `org-agenda-tag-filter-preset'.
  219. (if (fboundp 'defvaralias)
  220. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  221. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  222. (defconst org-agenda-custom-commands-local-options
  223. `(repeat :tag "Local settings for this command. Remember to quote values"
  224. (choice :tag "Setting"
  225. (list :tag "Heading for this block"
  226. (const org-agenda-overriding-header)
  227. (string :tag "Headline"))
  228. (list :tag "Files to be searched"
  229. (const org-agenda-files)
  230. (list
  231. (const :format "" quote)
  232. (repeat (file))))
  233. (list :tag "Sorting strategy"
  234. (const org-agenda-sorting-strategy)
  235. (list
  236. (const :format "" quote)
  237. (repeat
  238. ,org-sorting-choice)))
  239. (list :tag "Prefix format"
  240. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  241. (string))
  242. (list :tag "Number of days in agenda"
  243. (const org-agenda-span)
  244. (choice (const :tag "Day" 'day)
  245. (const :tag "Week" 'week)
  246. (const :tag "Month" 'month)
  247. (const :tag "Year" 'year)
  248. (integer :tag "Custom")))
  249. (list :tag "Fixed starting date"
  250. (const org-agenda-start-day)
  251. (string :value "2007-11-01"))
  252. (list :tag "Start on day of week"
  253. (const org-agenda-start-on-weekday)
  254. (choice :value 1
  255. (const :tag "Today" nil)
  256. (integer :tag "Weekday No.")))
  257. (list :tag "Include data from diary"
  258. (const org-agenda-include-diary)
  259. (boolean))
  260. (list :tag "Deadline Warning days"
  261. (const org-deadline-warning-days)
  262. (integer :value 1))
  263. (list :tag "Category filter preset"
  264. (const org-agenda-category-filter-preset)
  265. (list
  266. (const :format "" quote)
  267. (repeat
  268. (string :tag "+category or -category"))))
  269. (list :tag "Tags filter preset"
  270. (const org-agenda-tag-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+tag or -tag"))))
  275. (list :tag "Set daily/weekly entry types"
  276. (const org-agenda-entry-types)
  277. (list
  278. (const :format "" quote)
  279. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  280. (const :deadline)
  281. (const :scheduled)
  282. (const :timestamp)
  283. (const :sexp))))
  284. (list :tag "Standard skipping condition"
  285. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  286. (const org-agenda-skip-function)
  287. (list
  288. (const :format "" quote)
  289. (list
  290. (choice
  291. :tag "Skipping range"
  292. (const :tag "Skip entry" org-agenda-skip-entry-if)
  293. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  294. (repeat :inline t :tag "Conditions for skipping"
  295. (choice
  296. :tag "Condition type"
  297. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  298. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  299. (list :tag "TODO state is" :inline t
  300. (const 'todo)
  301. (choice
  302. (const :tag "any not-done state" 'todo)
  303. (const :tag "any done state" 'done)
  304. (const :tag "any state" 'any)
  305. (list :tag "Keyword list"
  306. (const :format "" quote)
  307. (repeat (string :tag "Keyword")))))
  308. (list :tag "TODO state is not" :inline t
  309. (const 'nottodo)
  310. (choice
  311. (const :tag "any not-done state" 'todo)
  312. (const :tag "any done state" 'done)
  313. (const :tag "any state" 'any)
  314. (list :tag "Keyword list"
  315. (const :format "" quote)
  316. (repeat (string :tag "Keyword")))))
  317. (const :tag "scheduled" 'scheduled)
  318. (const :tag "not scheduled" 'notscheduled)
  319. (const :tag "deadline" 'deadline)
  320. (const :tag "no deadline" 'notdeadline)
  321. (const :tag "timestamp" 'timestamp)
  322. (const :tag "no timestamp" 'nottimestamp))))))
  323. (list :tag "Non-standard skipping condition"
  324. :value (org-agenda-skip-function)
  325. (const org-agenda-skip-function)
  326. (sexp :tag "Function or form (quoted!)"))
  327. (list :tag "Any variable"
  328. (variable :tag "Variable")
  329. (sexp :tag "Value (sexp)"))))
  330. "Selection of examples for agenda command settings.
  331. This will be spliced into the custom type of
  332. `org-agenda-custom-commands'.")
  333. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  334. ((agenda "") (alltodo))))
  335. "Custom commands for the agenda.
  336. These commands will be offered on the splash screen displayed by the
  337. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  338. (key desc type match settings files)
  339. key The key (one or more characters as a string) to be associated
  340. with the command.
  341. desc A description of the command, when omitted or nil, a default
  342. description is built using MATCH.
  343. type The command type, any of the following symbols:
  344. agenda The daily/weekly agenda.
  345. todo Entries with a specific TODO keyword, in all agenda files.
  346. search Entries containing search words entry or headline.
  347. tags Tags/Property/TODO match in all agenda files.
  348. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  349. todo-tree Sparse tree of specific TODO keyword in *current* file.
  350. tags-tree Sparse tree with all tags matches in *current* file.
  351. occur-tree Occur sparse tree for *current* file.
  352. ... A user-defined function.
  353. match What to search for:
  354. - a single keyword for TODO keyword searches
  355. - a tags match expression for tags searches
  356. - a word search expression for text searches.
  357. - a regular expression for occur searches
  358. For all other commands, this should be the empty string.
  359. settings A list of option settings, similar to that in a let form, so like
  360. this: ((opt1 val1) (opt2 val2) ...). The values will be
  361. evaluated at the moment of execution, so quote them when needed.
  362. files A list of files file to write the produced agenda buffer to
  363. with the command `org-store-agenda-views'.
  364. If a file name ends in \".html\", an HTML version of the buffer
  365. is written out. If it ends in \".ps\", a postscript version is
  366. produced. Otherwise, only the plain text is written to the file.
  367. You can also define a set of commands, to create a composite agenda buffer.
  368. In this case, an entry looks like this:
  369. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  370. where
  371. desc A description string to be displayed in the dispatcher menu.
  372. cmd An agenda command, similar to the above. However, tree commands
  373. are not allowed, but instead you can get agenda and global todo list.
  374. So valid commands for a set are:
  375. (agenda \"\" settings)
  376. (alltodo \"\" settings)
  377. (stuck \"\" settings)
  378. (todo \"match\" settings files)
  379. (search \"match\" settings files)
  380. (tags \"match\" settings files)
  381. (tags-todo \"match\" settings files)
  382. Each command can carry a list of options, and another set of options can be
  383. given for the whole set of commands. Individual command options take
  384. precedence over the general options.
  385. When using several characters as key to a command, the first characters
  386. are prefix commands. For the dispatcher to display useful information, you
  387. should provide a description for the prefix, like
  388. (setq org-agenda-custom-commands
  389. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  390. (\"hl\" tags \"+HOME+Lisa\")
  391. (\"hp\" tags \"+HOME+Peter\")
  392. (\"hk\" tags \"+HOME+Kim\")))"
  393. :group 'org-agenda-custom-commands
  394. :type `(repeat
  395. (choice :value ("x" "Describe command here" tags "" nil)
  396. (list :tag "Single command"
  397. (string :tag "Access Key(s) ")
  398. (option (string :tag "Description"))
  399. (choice
  400. (const :tag "Agenda" agenda)
  401. (const :tag "TODO list" alltodo)
  402. (const :tag "Search words" search)
  403. (const :tag "Stuck projects" stuck)
  404. (const :tag "Tags/Property match (all agenda files)" tags)
  405. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  406. (const :tag "TODO keyword search (all agenda files)" todo)
  407. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  408. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  409. (const :tag "Occur tree (current buffer)" occur-tree)
  410. (sexp :tag "Other, user-defined function"))
  411. (string :tag "Match (only for some commands)")
  412. ,org-agenda-custom-commands-local-options
  413. (option (repeat :tag "Export" (file :tag "Export to"))))
  414. (list :tag "Command series, all agenda files"
  415. (string :tag "Access Key(s)")
  416. (string :tag "Description ")
  417. (repeat :tag "Component"
  418. (choice
  419. (list :tag "Agenda"
  420. (const :format "" agenda)
  421. (const :tag "" :format "" "")
  422. ,org-agenda-custom-commands-local-options)
  423. (list :tag "TODO list (all keywords)"
  424. (const :format "" alltodo)
  425. (const :tag "" :format "" "")
  426. ,org-agenda-custom-commands-local-options)
  427. (list :tag "Search words"
  428. (const :format "" search)
  429. (string :tag "Match")
  430. ,org-agenda-custom-commands-local-options)
  431. (list :tag "Stuck projects"
  432. (const :format "" stuck)
  433. (const :tag "" :format "" "")
  434. ,org-agenda-custom-commands-local-options)
  435. (list :tag "Tags search"
  436. (const :format "" tags)
  437. (string :tag "Match")
  438. ,org-agenda-custom-commands-local-options)
  439. (list :tag "Tags search, TODO entries only"
  440. (const :format "" tags-todo)
  441. (string :tag "Match")
  442. ,org-agenda-custom-commands-local-options)
  443. (list :tag "TODO keyword search"
  444. (const :format "" todo)
  445. (string :tag "Match")
  446. ,org-agenda-custom-commands-local-options)
  447. (list :tag "Other, user-defined function"
  448. (symbol :tag "function")
  449. (string :tag "Match")
  450. ,org-agenda-custom-commands-local-options)))
  451. (repeat :tag "Settings for entire command set"
  452. (list (variable :tag "Any variable")
  453. (sexp :tag "Value")))
  454. (option (repeat :tag "Export" (file :tag "Export to"))))
  455. (cons :tag "Prefix key documentation"
  456. (string :tag "Access Key(s)")
  457. (string :tag "Description ")))))
  458. (defcustom org-agenda-query-register ?o
  459. "The register holding the current query string.
  460. The purpose of this is that if you construct a query string interactively,
  461. you can then use it to define a custom command."
  462. :group 'org-agenda-custom-commands
  463. :type 'character)
  464. (defcustom org-stuck-projects
  465. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  466. "How to identify stuck projects.
  467. This is a list of four items:
  468. 1. A tags/todo/property matcher string that is used to identify a project.
  469. See the manual for a description of tag and property searches.
  470. The entire tree below a headline matched by this is considered one project.
  471. 2. A list of TODO keywords identifying non-stuck projects.
  472. If the project subtree contains any headline with one of these todo
  473. keywords, the project is considered to be not stuck. If you specify
  474. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  475. 3. A list of tags identifying non-stuck projects.
  476. If the project subtree contains any headline with one of these tags,
  477. the project is considered to be not stuck. If you specify \"*\" as
  478. a tag, any tag will mark the project unstuck. Note that this is about
  479. the explicit presence of a tag somewhere in the subtree, inherited
  480. tags to not count here. If inherited tags make a project not stuck,
  481. use \"-TAG\" in the tags part of the matcher under (1.) above.
  482. 4. An arbitrary regular expression matching non-stuck projects.
  483. If the project turns out to be not stuck, search continues also in the
  484. subtree to see if any of the subtasks have project status.
  485. See also the variable `org-tags-match-list-sublevels' which applies
  486. to projects matched by this search as well.
  487. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  488. or `C-c a #' to produce the list."
  489. :group 'org-agenda-custom-commands
  490. :type '(list
  491. (string :tag "Tags/TODO match to identify a project")
  492. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  493. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  494. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  495. (defcustom org-agenda-filter-effort-default-operator "<"
  496. "The default operator for effort estimate filtering.
  497. If you select an effort estimate limit without first pressing an operator,
  498. this one will be used."
  499. :group 'org-agenda-custom-commands
  500. :type '(choice (const :tag "less or equal" "<")
  501. (const :tag "greater or equal"">")
  502. (const :tag "equal" "=")))
  503. (defgroup org-agenda-skip nil
  504. "Options concerning skipping parts of agenda files."
  505. :tag "Org Agenda Skip"
  506. :group 'org-agenda)
  507. (defcustom org-agenda-skip-function-global nil
  508. "Function to be called at each match during agenda construction.
  509. If this function returns nil, the current match should not be skipped.
  510. If the function decided to skip an agenda match, is must return the
  511. buffer position from which the search should be continued.
  512. This may also be a Lisp form, which will be evaluated.
  513. This variable will be applied to every agenda match, including
  514. tags/property searches and TODO lists. So try to make the test function
  515. do its checking as efficiently as possible. To implement a skipping
  516. condition just for specific agenda commands, use the variable
  517. `org-agenda-skip-function' which can be set in the options section
  518. of custom agenda commands."
  519. :group 'org-agenda-skip
  520. :type 'sexp)
  521. (defgroup org-agenda-daily/weekly nil
  522. "Options concerning the daily/weekly agenda."
  523. :tag "Org Agenda Daily/Weekly"
  524. :group 'org-agenda)
  525. (defgroup org-agenda-todo-list nil
  526. "Options concerning the global todo list agenda view."
  527. :tag "Org Agenda Todo List"
  528. :group 'org-agenda)
  529. (defgroup org-agenda-match-view nil
  530. "Options concerning the general tags/property/todo match agenda view."
  531. :tag "Org Agenda Match View"
  532. :group 'org-agenda)
  533. (defgroup org-agenda-search-view nil
  534. "Options concerning the general tags/property/todo match agenda view."
  535. :tag "Org Agenda Match View"
  536. :group 'org-agenda)
  537. (defvar org-agenda-archives-mode nil
  538. "Non-nil means the agenda will include archived items.
  539. If this is the symbol `trees', trees in the selected agenda scope
  540. that are marked with the ARCHIVE tag will be included anyway. When this is
  541. t, also all archive files associated with the current selection of agenda
  542. files will be included.")
  543. (defcustom org-agenda-skip-comment-trees t
  544. "Non-nil means skip trees that start with the COMMENT keyword.
  545. When nil, these trees are also scanned by agenda commands."
  546. :group 'org-agenda-skip
  547. :type 'boolean)
  548. (defcustom org-agenda-todo-list-sublevels t
  549. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  550. When nil, the sublevels of a TODO entry are not checked, resulting in
  551. potentially much shorter TODO lists."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type 'boolean)
  555. (defcustom org-agenda-todo-ignore-with-date nil
  556. "Non-nil means don't show entries with a date in the global todo list.
  557. You can use this if you prefer to mark mere appointments with a TODO keyword,
  558. but don't want them to show up in the TODO list.
  559. When this is set, it also covers deadlines and scheduled items, the settings
  560. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  561. will be ignored.
  562. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  563. :group 'org-agenda-skip
  564. :group 'org-agenda-todo-list
  565. :type 'boolean)
  566. (defcustom org-agenda-todo-ignore-timestamp nil
  567. "Non-nil means don't show entries with a timestamp.
  568. This applies when creating the global todo list.
  569. Valid values are:
  570. past Don't show entries for today or in the past.
  571. future Don't show entries with a timestamp in the future.
  572. The idea behind this is that if it has a future
  573. timestamp, you don't want to think about it until the
  574. date.
  575. all Don't show any entries with a timestamp in the global todo list.
  576. The idea behind this is that by setting a timestamp, you
  577. have already \"taken care\" of this item.
  578. This variable can also have an integer as a value. If positive (N),
  579. todos with a timestamp N or more days in the future will be ignored. If
  580. negative (-N), todos with a timestamp N or more days in the past will be
  581. ignored. If 0, todos with a timestamp either today or in the future will
  582. be ignored. For example, a value of -1 will exclude todos with a
  583. timestamp in the past (yesterday or earlier), while a value of 7 will
  584. exclude todos with a timestamp a week or more in the future.
  585. See also `org-agenda-todo-ignore-with-date'.
  586. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  587. to make his option also apply to the tags-todo list."
  588. :group 'org-agenda-skip
  589. :group 'org-agenda-todo-list
  590. :version "24.1"
  591. :type '(choice
  592. (const :tag "Ignore future timestamp todos" future)
  593. (const :tag "Ignore past or present timestamp todos" past)
  594. (const :tag "Ignore all timestamp todos" all)
  595. (const :tag "Show timestamp todos" nil)
  596. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  597. (defcustom org-agenda-todo-ignore-scheduled nil
  598. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  599. This applies when creating the global todo list.
  600. Valid values are:
  601. past Don't show entries scheduled today or in the past.
  602. future Don't show entries scheduled in the future.
  603. The idea behind this is that by scheduling it, you don't want to
  604. think about it until the scheduled date.
  605. all Don't show any scheduled entries in the global todo list.
  606. The idea behind this is that by scheduling it, you have already
  607. \"taken care\" of this item.
  608. t Same as `all', for backward compatibility.
  609. This variable can also have an integer as a value. See
  610. `org-agenda-todo-ignore-timestamp' for more details.
  611. See also `org-agenda-todo-ignore-with-date'.
  612. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  613. to make his option also apply to the tags-todo list."
  614. :group 'org-agenda-skip
  615. :group 'org-agenda-todo-list
  616. :type '(choice
  617. (const :tag "Ignore future-scheduled todos" future)
  618. (const :tag "Ignore past- or present-scheduled todos" past)
  619. (const :tag "Ignore all scheduled todos" all)
  620. (const :tag "Ignore all scheduled todos (compatibility)" t)
  621. (const :tag "Show scheduled todos" nil)
  622. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  623. (defcustom org-agenda-todo-ignore-deadlines nil
  624. "Non-nil means ignore some deadlined TODO items when making TODO list.
  625. There are different motivations for using different values, please think
  626. carefully when configuring this variable.
  627. This applies when creating the global todo list.
  628. Valid values are:
  629. near Don't show near deadline entries. A deadline is near when it is
  630. closer than `org-deadline-warning-days' days. The idea behind this
  631. is that such items will appear in the agenda anyway.
  632. far Don't show TODO entries where a deadline has been defined, but
  633. the deadline is not near. This is useful if you don't want to
  634. use the todo list to figure out what to do now.
  635. past Don't show entries with a deadline timestamp for today or in the past.
  636. future Don't show entries with a deadline timestamp in the future, not even
  637. when they become `near' ones. Use it with caution.
  638. all Ignore all TODO entries that do have a deadline.
  639. t Same as `near', for backward compatibility.
  640. This variable can also have an integer as a value. See
  641. `org-agenda-todo-ignore-timestamp' for more details.
  642. See also `org-agenda-todo-ignore-with-date'.
  643. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  644. to make his option also apply to the tags-todo list."
  645. :group 'org-agenda-skip
  646. :group 'org-agenda-todo-list
  647. :type '(choice
  648. (const :tag "Ignore near deadlines" near)
  649. (const :tag "Ignore near deadlines (compatibility)" t)
  650. (const :tag "Ignore far deadlines" far)
  651. (const :tag "Ignore all TODOs with a deadlines" all)
  652. (const :tag "Show all TODOs, even if they have a deadline" nil)
  653. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  654. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  655. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  656. The variables
  657. `org-agenda-todo-ignore-with-date',
  658. `org-agenda-todo-ignore-timestamp',
  659. `org-agenda-todo-ignore-scheduled',
  660. `org-agenda-todo-ignore-deadlines'
  661. make the global TODO list skip entries that have time stamps of certain
  662. kinds. If this option is set, the same options will also apply for the
  663. tags-todo search, which is the general tags/property matcher
  664. restricted to unfinished TODO entries only."
  665. :group 'org-agenda-skip
  666. :group 'org-agenda-todo-list
  667. :group 'org-agenda-match-view
  668. :type 'boolean)
  669. (defcustom org-agenda-skip-scheduled-if-done nil
  670. "Non-nil means don't show scheduled items in agenda when they are done.
  671. This is relevant for the daily/weekly agenda, not for the TODO list. And
  672. it applies only to the actual date of the scheduling. Warnings about
  673. an item with a past scheduling dates are always turned off when the item
  674. is DONE."
  675. :group 'org-agenda-skip
  676. :group 'org-agenda-daily/weekly
  677. :type 'boolean)
  678. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  679. "Non-nil means skip scheduling line if same entry shows because of deadline.
  680. In the agenda of today, an entry can show up multiple times because
  681. it is both scheduled and has a nearby deadline, and maybe a plain time
  682. stamp as well.
  683. When this variable is t, then only the deadline is shown and the fact that
  684. the entry is scheduled today or was scheduled previously is not shown.
  685. When this variable is nil, the entry will be shown several times. When
  686. the variable is the symbol `not-today', then skip scheduled previously,
  687. but not scheduled today."
  688. :group 'org-agenda-skip
  689. :group 'org-agenda-daily/weekly
  690. :type '(choice
  691. (const :tag "Never" nil)
  692. (const :tag "Always" t)
  693. (const :tag "Not when scheduled today" not-today)))
  694. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  695. "Non-nil means skip timestamp line if same entry shows because of deadline.
  696. In the agenda of today, an entry can show up multiple times
  697. because it has both a plain timestamp and has a nearby deadline.
  698. When this variable is t, then only the deadline is shown and the
  699. fact that the entry has a timestamp for or including today is not
  700. shown. When this variable is nil, the entry will be shown
  701. several times."
  702. :group 'org-agenda-skip
  703. :group 'org-agenda-daily/weekly
  704. :version "24.1"
  705. :type '(choice
  706. (const :tag "Never" nil)
  707. (const :tag "Always" t)))
  708. (defcustom org-agenda-skip-deadline-if-done nil
  709. "Non-nil means don't show deadlines when the corresponding item is done.
  710. When nil, the deadline is still shown and should give you a happy feeling.
  711. This is relevant for the daily/weekly agenda. And it applied only to the
  712. actually date of the deadline. Warnings about approaching and past-due
  713. deadlines are always turned off when the item is DONE."
  714. :group 'org-agenda-skip
  715. :group 'org-agenda-daily/weekly
  716. :type 'boolean)
  717. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  718. "Non-nil means skip deadline prewarning when entry is also scheduled.
  719. This will apply on all days where a prewarning for the deadline would
  720. be shown, but not at the day when the entry is actually due. On that day,
  721. the deadline will be shown anyway.
  722. This variable may be set to nil, t, or a number which will then give
  723. the number of days before the actual deadline when the prewarnings
  724. should resume.
  725. This can be used in a workflow where the first showing of the deadline will
  726. trigger you to schedule it, and then you don't want to be reminded of it
  727. because you will take care of it on the day when scheduled."
  728. :group 'org-agenda-skip
  729. :group 'org-agenda-daily/weekly
  730. :version "24.1"
  731. :type '(choice
  732. (const :tag "Alwas show prewarning" nil)
  733. (const :tag "Remove prewarning if entry is scheduled" t)
  734. (integer :tag "Restart prewarning N days before deadline")))
  735. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  736. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  737. When non-nil, after the search for timestamps has matched once in an
  738. entry, the rest of the entry will not be searched."
  739. :group 'org-agenda-skip
  740. :type 'boolean)
  741. (defcustom org-agenda-skip-timestamp-if-done nil
  742. "Non-nil means don't select item by timestamp or -range if it is DONE."
  743. :group 'org-agenda-skip
  744. :group 'org-agenda-daily/weekly
  745. :type 'boolean)
  746. (defcustom org-agenda-dim-blocked-tasks t
  747. "Non-nil means dim blocked tasks in the agenda display.
  748. This causes some overhead during agenda construction, but if you
  749. have turned on `org-enforce-todo-dependencies',
  750. `org-enforce-todo-checkbox-dependencies', or any other blocking
  751. mechanism, this will create useful feedback in the agenda.
  752. Instead of t, this variable can also have the value `invisible'.
  753. Then blocked tasks will be invisible and only become visible when
  754. they become unblocked. An exemption to this behavior is when a task is
  755. blocked because of unchecked checkboxes below it. Since checkboxes do
  756. not show up in the agenda views, making this task invisible you remove any
  757. trace from agenda views that there is something to do. Therefore, a task
  758. that is blocked because of checkboxes will never be made invisible, it
  759. will only be dimmed."
  760. :group 'org-agenda-daily/weekly
  761. :group 'org-agenda-todo-list
  762. :type '(choice
  763. (const :tag "Do not dim" nil)
  764. (const :tag "Dim to a gray face" t)
  765. (const :tag "Make invisible" invisible)))
  766. (defcustom org-timeline-show-empty-dates 3
  767. "Non-nil means `org-timeline' also shows dates without an entry.
  768. When nil, only the days which actually have entries are shown.
  769. When t, all days between the first and the last date are shown.
  770. When an integer, show also empty dates, but if there is a gap of more than
  771. N days, just insert a special line indicating the size of the gap."
  772. :group 'org-agenda-skip
  773. :type '(choice
  774. (const :tag "None" nil)
  775. (const :tag "All" t)
  776. (integer :tag "at most")))
  777. (defgroup org-agenda-startup nil
  778. "Options concerning initial settings in the Agenda in Org Mode."
  779. :tag "Org Agenda Startup"
  780. :group 'org-agenda)
  781. (defcustom org-agenda-menu-show-matcher t
  782. "Non-nil means show the match string in the agenda dispatcher menu.
  783. When nil, the matcher string is not shown, but is put into the help-echo
  784. property so than moving the mouse over the command shows it.
  785. Setting it to nil is good if matcher strings are very long and/or if
  786. you want to use two-column display (see `org-agenda-menu-two-column')."
  787. :group 'org-agenda
  788. :version "24.1"
  789. :type 'boolean)
  790. (defcustom org-agenda-menu-two-column nil
  791. "Non-nil means, use two columns to show custom commands in the dispatcher.
  792. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  793. to nil."
  794. :group 'org-agenda
  795. :version "24.1"
  796. :type 'boolean)
  797. (defcustom org-finalize-agenda-hook nil
  798. "Hook run just before displaying an agenda buffer."
  799. :group 'org-agenda-startup
  800. :type 'hook)
  801. (defcustom org-agenda-mouse-1-follows-link nil
  802. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  803. A longer mouse click will still set point. Does not work on XEmacs.
  804. Needs to be set before org.el is loaded."
  805. :group 'org-agenda-startup
  806. :type 'boolean)
  807. (defcustom org-agenda-start-with-follow-mode nil
  808. "The initial value of follow mode in a newly created agenda window."
  809. :group 'org-agenda-startup
  810. :type 'boolean)
  811. (defcustom org-agenda-follow-indirect nil
  812. "Non-nil means `org-agenda-follow-mode' displays only the
  813. current item's tree, in an indirect buffer."
  814. :group 'org-agenda
  815. :version "24.1"
  816. :type 'boolean)
  817. (defcustom org-agenda-show-outline-path t
  818. "Non-nil means show outline path in echo area after line motion."
  819. :group 'org-agenda-startup
  820. :type 'boolean)
  821. (defcustom org-agenda-start-with-entry-text-mode nil
  822. "The initial value of entry-text-mode in a newly created agenda window."
  823. :group 'org-agenda-startup
  824. :type 'boolean)
  825. (defcustom org-agenda-entry-text-maxlines 5
  826. "Number of text lines to be added when `E' is pressed in the agenda.
  827. Note that this variable only used during agenda display. Add add entry text
  828. when exporting the agenda, configure the variable
  829. `org-agenda-add-entry-ext-maxlines'."
  830. :group 'org-agenda
  831. :type 'integer)
  832. (defcustom org-agenda-entry-text-exclude-regexps nil
  833. "List of regular expressions to clean up entry text.
  834. The complete matches of all regular expressions in this list will be
  835. removed from entry text before it is shown in the agenda."
  836. :group 'org-agenda
  837. :type '(repeat (regexp)))
  838. (defvar org-agenda-entry-text-cleanup-hook nil
  839. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  840. This cleanup is done in a temporary buffer, so the function may inspect and
  841. change the entire buffer.
  842. Some default stuff like drawers and scheduling/deadline dates will already
  843. have been removed when this is called, as will any matches for regular
  844. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  845. (defvar org-agenda-include-inactive-timestamps nil
  846. "Non-nil means include inactive time stamps in agenda and timeline.
  847. Dynamically scoped.")
  848. (defgroup org-agenda-windows nil
  849. "Options concerning the windows used by the Agenda in Org Mode."
  850. :tag "Org Agenda Windows"
  851. :group 'org-agenda)
  852. (defcustom org-agenda-window-setup 'reorganize-frame
  853. "How the agenda buffer should be displayed.
  854. Possible values for this option are:
  855. current-window Show agenda in the current window, keeping all other windows.
  856. other-window Use `switch-to-buffer-other-window' to display agenda.
  857. reorganize-frame Show only two windows on the current frame, the current
  858. window and the agenda.
  859. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  860. Also, when exiting the agenda, kill that frame.
  861. See also the variable `org-agenda-restore-windows-after-quit'."
  862. :group 'org-agenda-windows
  863. :type '(choice
  864. (const current-window)
  865. (const other-frame)
  866. (const other-window)
  867. (const reorganize-frame)))
  868. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  869. "The min and max height of the agenda window as a fraction of frame height.
  870. The value of the variable is a cons cell with two numbers between 0 and 1.
  871. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  872. :group 'org-agenda-windows
  873. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  874. (defcustom org-agenda-restore-windows-after-quit nil
  875. "Non-nil means restore window configuration upon exiting agenda.
  876. Before the window configuration is changed for displaying the agenda,
  877. the current status is recorded. When the agenda is exited with
  878. `q' or `x' and this option is set, the old state is restored. If
  879. `org-agenda-window-setup' is `other-frame', the value of this
  880. option will be ignored."
  881. :group 'org-agenda-windows
  882. :type 'boolean)
  883. (defcustom org-agenda-ndays nil
  884. "Number of days to include in overview display.
  885. Should be 1 or 7.
  886. Obsolete, see `org-agenda-span'."
  887. :group 'org-agenda-daily/weekly
  888. :type 'integer)
  889. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  890. (defcustom org-agenda-span 'week
  891. "Number of days to include in overview display.
  892. Can be day, week, month, year, or any number of days.
  893. Custom commands can set this variable in the options section."
  894. :group 'org-agenda-daily/weekly
  895. :type '(choice (const :tag "Day" day)
  896. (const :tag "Week" week)
  897. (const :tag "Month" month)
  898. (const :tag "Year" year)
  899. (integer :tag "Custom")))
  900. (defcustom org-agenda-start-on-weekday 1
  901. "Non-nil means start the overview always on the specified weekday.
  902. 0 denotes Sunday, 1 denotes Monday etc.
  903. When nil, always start on the current day.
  904. Custom commands can set this variable in the options section."
  905. :group 'org-agenda-daily/weekly
  906. :type '(choice (const :tag "Today" nil)
  907. (integer :tag "Weekday No.")))
  908. (defcustom org-agenda-show-all-dates t
  909. "Non-nil means `org-agenda' shows every day in the selected range.
  910. When nil, only the days which actually have entries are shown."
  911. :group 'org-agenda-daily/weekly
  912. :type 'boolean)
  913. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  914. "Format string for displaying dates in the agenda.
  915. Used by the daily/weekly agenda and by the timeline. This should be
  916. a format string understood by `format-time-string', or a function returning
  917. the formatted date as a string. The function must take a single argument,
  918. a calendar-style date list like (month day year)."
  919. :group 'org-agenda-daily/weekly
  920. :type '(choice
  921. (string :tag "Format string")
  922. (function :tag "Function")))
  923. (defun org-agenda-format-date-aligned (date)
  924. "Format a date string for display in the daily/weekly agenda, or timeline.
  925. This function makes sure that dates are aligned for easy reading."
  926. (require 'cal-iso)
  927. (let* ((dayname (calendar-day-name date))
  928. (day (cadr date))
  929. (day-of-week (calendar-day-of-week date))
  930. (month (car date))
  931. (monthname (calendar-month-name month))
  932. (year (nth 2 date))
  933. (iso-week (org-days-to-iso-week
  934. (calendar-absolute-from-gregorian date)))
  935. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  936. (1- year))
  937. ((and (= month 12) (<= iso-week 1))
  938. (1+ year))
  939. (t year)))
  940. (weekstring (if (= day-of-week 1)
  941. (format " W%02d" iso-week)
  942. "")))
  943. (format "%-10s %2d %s %4d%s"
  944. dayname day monthname year weekstring)))
  945. (defcustom org-agenda-time-leading-zero nil
  946. "Non-nil means use leading zero for military times in agenda.
  947. For example, 9:30am would become 09:30 rather than 9:30."
  948. :group 'org-agenda-daily/weekly
  949. :version "24.1"
  950. :type 'boolean)
  951. (defcustom org-agenda-timegrid-use-ampm nil
  952. "When set, show AM/PM style timestamps on the timegrid."
  953. :group 'org-agenda
  954. :version "24.1"
  955. :type 'boolean)
  956. (defun org-agenda-time-of-day-to-ampm (time)
  957. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  958. (let* ((hour-number (string-to-number (substring time 0 -3)))
  959. (minute (substring time -2))
  960. (ampm "am"))
  961. (cond
  962. ((equal hour-number 12)
  963. (setq ampm "pm"))
  964. ((> hour-number 12)
  965. (setq ampm "pm")
  966. (setq hour-number (- hour-number 12))))
  967. (concat
  968. (if org-agenda-time-leading-zero
  969. (format "%02d" hour-number)
  970. (format "%02s" (number-to-string hour-number)))
  971. ":" minute ampm)))
  972. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  973. "Conditionally convert TIME to AM/PM format
  974. based on `org-agenda-timegrid-use-ampm'"
  975. (if org-agenda-timegrid-use-ampm
  976. (org-agenda-time-of-day-to-ampm time)
  977. time))
  978. (defcustom org-agenda-weekend-days '(6 0)
  979. "Which days are weekend?
  980. These days get the special face `org-agenda-date-weekend' in the agenda
  981. and timeline buffers."
  982. :group 'org-agenda-daily/weekly
  983. :type '(set :greedy t
  984. (const :tag "Monday" 1)
  985. (const :tag "Tuesday" 2)
  986. (const :tag "Wednesday" 3)
  987. (const :tag "Thursday" 4)
  988. (const :tag "Friday" 5)
  989. (const :tag "Saturday" 6)
  990. (const :tag "Sunday" 0)))
  991. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  992. "Non-nil means jump to today when moving a past date forward in time.
  993. When using S-right in the agenda to move a a date forward, and the date
  994. stamp currently points to the past, the first key press will move it
  995. to today. WHen nil, just move one day forward even if the date stays
  996. in the past."
  997. :group 'org-agenda-daily/weekly
  998. :version "24.1"
  999. :type 'boolean)
  1000. (defcustom org-agenda-include-diary nil
  1001. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1002. Custom commands can set this variable in the options section."
  1003. :group 'org-agenda-daily/weekly
  1004. :type 'boolean)
  1005. (defcustom org-agenda-include-deadlines t
  1006. "If non-nil, include entries within their deadline warning period.
  1007. Custom commands can set this variable in the options section."
  1008. :group 'org-agenda-daily/weekly
  1009. :version "24.1"
  1010. :type 'boolean)
  1011. (defcustom org-agenda-repeating-timestamp-show-all t
  1012. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1013. When set to a list of strings, only show occurrences of repeating
  1014. stamps for these TODO keywords. When nil, only one occurrence is
  1015. shown, either today or the nearest into the future."
  1016. :group 'org-agenda-daily/weekly
  1017. :type '(choice
  1018. (const :tag "Show repeating stamps" t)
  1019. (repeat :tag "Show repeating stamps for these TODO keywords"
  1020. (string :tag "TODO Keyword"))
  1021. (const :tag "Don't show repeating stamps" nil)))
  1022. (defcustom org-scheduled-past-days 10000
  1023. "No. of days to continue listing scheduled items that are not marked DONE.
  1024. When an item is scheduled on a date, it shows up in the agenda on this
  1025. day and will be listed until it is marked done for the number of days
  1026. given here."
  1027. :group 'org-agenda-daily/weekly
  1028. :type 'integer)
  1029. (defcustom org-agenda-log-mode-items '(closed clock)
  1030. "List of items that should be shown in agenda log mode.
  1031. This list may contain the following symbols:
  1032. closed Show entries that have been closed on that day.
  1033. clock Show entries that have received clocked time on that day.
  1034. state Show all logged state changes.
  1035. Note that instead of changing this variable, you can also press `C-u l' in
  1036. the agenda to display all available LOG items temporarily."
  1037. :group 'org-agenda-daily/weekly
  1038. :type '(set :greedy t (const closed) (const clock) (const state)))
  1039. (defcustom org-agenda-clock-consistency-checks
  1040. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1041. :gap-ok-around ("4:00")
  1042. :default-face ((:background "DarkRed") (:foreground "white"))
  1043. :overlap-face nil :gap-face nil :no-end-time-face nil
  1044. :long-face nil :short-face nil)
  1045. "This is a property list, with the following keys:
  1046. :max-duration Mark clocking chunks that are longer than this time.
  1047. This is a time string like \"HH:MM\", or the number
  1048. of minutes as an integer.
  1049. :min-duration Mark clocking chunks that are shorter that this.
  1050. This is a time string like \"HH:MM\", or the number
  1051. of minutes as an integer.
  1052. :max-gap Mark gaps between clocking chunks that are longer than
  1053. this duration. A number of minutes, or a string
  1054. like \"HH:MM\".
  1055. :gap-ok-around List of times during the day which are usually not working
  1056. times. When a gap is detected, but the gap contains any
  1057. of these times, the gap is *not* reported. For example,
  1058. if this is (\"4:00\" \"13:00\") then gaps that contain
  1059. 4:00 in the morning (i.e. the night) and 13:00
  1060. (i.e. a typical lunch time) do not cause a warning.
  1061. You should have at least one time during the night in this
  1062. list, or otherwise the first task each morning will trigger
  1063. a warning because it follows a long gap.
  1064. Furthermore, the following properties can be used to define faces for
  1065. issue display.
  1066. :default-face the default face, if the specific face is undefined
  1067. :overlap-face face for overlapping clocks
  1068. :gap-face face for gaps between clocks
  1069. :no-end-time-face face for incomplete clocks
  1070. :long-face face for clock intervals that are too long
  1071. :short-face face for clock intervals that are too short"
  1072. :group 'org-agenda-daily/weekly
  1073. :group 'org-clock
  1074. :version "24.1"
  1075. :type 'plist)
  1076. (defcustom org-agenda-log-mode-add-notes t
  1077. "Non-nil means add first line of notes to log entries in agenda views.
  1078. If a log item like a state change or a clock entry is associated with
  1079. notes, the first line of these notes will be added to the entry in the
  1080. agenda display."
  1081. :group 'org-agenda-daily/weekly
  1082. :type 'boolean)
  1083. (defcustom org-agenda-start-with-log-mode nil
  1084. "The initial value of log-mode in a newly created agenda window."
  1085. :group 'org-agenda-startup
  1086. :group 'org-agenda-daily/weekly
  1087. :type 'boolean)
  1088. (defcustom org-agenda-start-with-clockreport-mode nil
  1089. "The initial value of clockreport-mode in a newly created agenda window."
  1090. :group 'org-agenda-startup
  1091. :group 'org-agenda-daily/weekly
  1092. :type 'boolean)
  1093. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1094. "Property list with parameters for the clocktable in clockreport mode.
  1095. This is the display mode that shows a clock table in the daily/weekly
  1096. agenda, the properties for this dynamic block can be set here.
  1097. The usual clocktable parameters are allowed here, but you cannot set
  1098. the properties :name, :tstart, :tend, :block, and :scope - these will
  1099. be overwritten to make sure the content accurately reflects the
  1100. current display in the agenda."
  1101. :group 'org-agenda-daily/weekly
  1102. :type 'plist)
  1103. (defcustom org-agenda-search-view-always-boolean nil
  1104. "Non-nil means the search string is interpreted as individual parts.
  1105. The search string for search view can either be interpreted as a phrase,
  1106. or as a list of snippets that define a boolean search for a number of
  1107. strings.
  1108. When this is non-nil, the string will be split on whitespace, and each
  1109. snippet will be searched individually, and all must match in order to
  1110. select an entry. A snippet is then a single string of non-white
  1111. characters, or a string in double quotes, or a regexp in {} braces.
  1112. If a snippet is preceded by \"-\", the snippet must *not* match.
  1113. \"+\" is syntactic sugar for positive selection. Each snippet may
  1114. be found as a full word or a partial word, but see the variable
  1115. `org-agenda-search-view-force-full-words'.
  1116. When this is nil, search will look for the entire search phrase as one,
  1117. with each space character matching any amount of whitespace, including
  1118. line breaks.
  1119. Even when this is nil, you can still switch to Boolean search dynamically
  1120. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1121. is a regexp marked with braces like \"{abc}\", this will also switch to
  1122. boolean search."
  1123. :group 'org-agenda-search-view
  1124. :version "24.1"
  1125. :type 'boolean)
  1126. (if (fboundp 'defvaralias)
  1127. (defvaralias 'org-agenda-search-view-search-words-only
  1128. 'org-agenda-search-view-always-boolean))
  1129. (defcustom org-agenda-search-view-force-full-words nil
  1130. "Non-nil means, search words must be matches as complete words.
  1131. When nil, they may also match part of a word."
  1132. :group 'org-agenda-search-view
  1133. :version "24.1"
  1134. :type 'boolean)
  1135. (defgroup org-agenda-time-grid nil
  1136. "Options concerning the time grid in the Org-mode Agenda."
  1137. :tag "Org Agenda Time Grid"
  1138. :group 'org-agenda)
  1139. (defcustom org-agenda-search-headline-for-time t
  1140. "Non-nil means search headline for a time-of-day.
  1141. If the headline contains a time-of-day in one format or another, it will
  1142. be used to sort the entry into the time sequence of items for a day.
  1143. Some people have time stamps in the headline that refer to the creation
  1144. time or so, and then this produces an unwanted side effect. If this is
  1145. the case for your, use this variable to turn off searching the headline
  1146. for a time."
  1147. :group 'org-agenda-time-grid
  1148. :type 'boolean)
  1149. (defcustom org-agenda-use-time-grid t
  1150. "Non-nil means show a time grid in the agenda schedule.
  1151. A time grid is a set of lines for specific times (like every two hours between
  1152. 8:00 and 20:00). The items scheduled for a day at specific times are
  1153. sorted in between these lines.
  1154. For details about when the grid will be shown, and what it will look like, see
  1155. the variable `org-agenda-time-grid'."
  1156. :group 'org-agenda-time-grid
  1157. :type 'boolean)
  1158. (defcustom org-agenda-time-grid
  1159. '((daily today require-timed)
  1160. "----------------"
  1161. (800 1000 1200 1400 1600 1800 2000))
  1162. "The settings for time grid for agenda display.
  1163. This is a list of three items. The first item is again a list. It contains
  1164. symbols specifying conditions when the grid should be displayed:
  1165. daily if the agenda shows a single day
  1166. weekly if the agenda shows an entire week
  1167. today show grid on current date, independent of daily/weekly display
  1168. require-timed show grid only if at least one item has a time specification
  1169. The second item is a string which will be placed behind the grid time.
  1170. The third item is a list of integers, indicating the times that should have
  1171. a grid line."
  1172. :group 'org-agenda-time-grid
  1173. :type
  1174. '(list
  1175. (set :greedy t :tag "Grid Display Options"
  1176. (const :tag "Show grid in single day agenda display" daily)
  1177. (const :tag "Show grid in weekly agenda display" weekly)
  1178. (const :tag "Always show grid for today" today)
  1179. (const :tag "Show grid only if any timed entries are present"
  1180. require-timed)
  1181. (const :tag "Skip grid times already present in an entry"
  1182. remove-match))
  1183. (string :tag "Grid String")
  1184. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1185. (defcustom org-agenda-show-current-time-in-grid t
  1186. "Non-nil means show the current time in the time grid."
  1187. :group 'org-agenda-time-grid
  1188. :version "24.1"
  1189. :type 'boolean)
  1190. (defcustom org-agenda-current-time-string
  1191. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1192. "The string for the current time marker in the agenda."
  1193. :group 'org-agenda-time-grid
  1194. :version "24.1"
  1195. :type 'string)
  1196. (defgroup org-agenda-sorting nil
  1197. "Options concerning sorting in the Org-mode Agenda."
  1198. :tag "Org Agenda Sorting"
  1199. :group 'org-agenda)
  1200. (defcustom org-agenda-sorting-strategy
  1201. '((agenda habit-down time-up priority-down category-keep)
  1202. (todo priority-down category-keep)
  1203. (tags priority-down category-keep)
  1204. (search category-keep))
  1205. "Sorting structure for the agenda items of a single day.
  1206. This is a list of symbols which will be used in sequence to determine
  1207. if an entry should be listed before another entry. The following
  1208. symbols are recognized:
  1209. time-up Put entries with time-of-day indications first, early first
  1210. time-down Put entries with time-of-day indications first, late first
  1211. category-keep Keep the default order of categories, corresponding to the
  1212. sequence in `org-agenda-files'.
  1213. category-up Sort alphabetically by category, A-Z.
  1214. category-down Sort alphabetically by category, Z-A.
  1215. tag-up Sort alphabetically by last tag, A-Z.
  1216. tag-down Sort alphabetically by last tag, Z-A.
  1217. priority-up Sort numerically by priority, high priority last.
  1218. priority-down Sort numerically by priority, high priority first.
  1219. todo-state-up Sort by todo state, tasks that are done last.
  1220. todo-state-down Sort by todo state, tasks that are done first.
  1221. effort-up Sort numerically by estimated effort, high effort last.
  1222. effort-down Sort numerically by estimated effort, high effort first.
  1223. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1224. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1225. habit-up Put entries that are habits first
  1226. habit-down Put entries that are habits last
  1227. alpha-up Sort headlines alphabetically
  1228. alpha-down Sort headlines alphabetically, reversed
  1229. The different possibilities will be tried in sequence, and testing stops
  1230. if one comparison returns a \"not-equal\". For example, the default
  1231. '(time-up category-keep priority-down)
  1232. means: Pull out all entries having a specified time of day and sort them,
  1233. in order to make a time schedule for the current day the first thing in the
  1234. agenda listing for the day. Of the entries without a time indication, keep
  1235. the grouped in categories, don't sort the categories, but keep them in
  1236. the sequence given in `org-agenda-files'. Within each category sort by
  1237. priority.
  1238. Leaving out `category-keep' would mean that items will be sorted across
  1239. categories by priority.
  1240. Instead of a single list, this can also be a set of list for specific
  1241. contents, with a context symbol in the car of the list, any of
  1242. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1243. Custom commands can bind this variable in the options section."
  1244. :group 'org-agenda-sorting
  1245. :type `(choice
  1246. (repeat :tag "General" ,org-sorting-choice)
  1247. (list :tag "Individually"
  1248. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1249. (repeat ,org-sorting-choice))
  1250. (cons (const :tag "Strategy for TODO lists" todo)
  1251. (repeat ,org-sorting-choice))
  1252. (cons (const :tag "Strategy for Tags matches" tags)
  1253. (repeat ,org-sorting-choice))
  1254. (cons (const :tag "Strategy for search matches" search)
  1255. (repeat ,org-sorting-choice)))))
  1256. (defcustom org-agenda-cmp-user-defined nil
  1257. "A function to define the comparison `user-defined'.
  1258. This function must receive two arguments, agenda entry a and b.
  1259. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1260. the user comparison, return nil.
  1261. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1262. part of an agenda sorting strategy."
  1263. :group 'org-agenda-sorting
  1264. :type 'symbol)
  1265. (defcustom org-sort-agenda-notime-is-late t
  1266. "Non-nil means items without time are considered late.
  1267. This is only relevant for sorting. When t, items which have no explicit
  1268. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1269. do have a time. When nil, the default time is before 0:00. You can use this
  1270. option to decide if the schedule for today should come before or after timeless
  1271. agenda entries."
  1272. :group 'org-agenda-sorting
  1273. :type 'boolean)
  1274. (defcustom org-sort-agenda-noeffort-is-high t
  1275. "Non-nil means items without effort estimate are sorted as high effort.
  1276. This also applies when filtering an agenda view with respect to the
  1277. < or > effort operator. Then, tasks with no effort defined will be treated
  1278. as tasks with high effort.
  1279. When nil, such items are sorted as 0 minutes effort."
  1280. :group 'org-agenda-sorting
  1281. :type 'boolean)
  1282. (defgroup org-agenda-line-format nil
  1283. "Options concerning the entry prefix in the Org-mode agenda display."
  1284. :tag "Org Agenda Line Format"
  1285. :group 'org-agenda)
  1286. (defcustom org-agenda-prefix-format
  1287. '((agenda . " %i %-12:c%?-12t% s")
  1288. (timeline . " % s")
  1289. (todo . " %i %-12:c")
  1290. (tags . " %i %-12:c")
  1291. (search . " %i %-12:c"))
  1292. "Format specifications for the prefix of items in the agenda views.
  1293. An alist with five entries, each for the different agenda types. The
  1294. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1295. The values are format strings.
  1296. This format works similar to a printf format, with the following meaning:
  1297. %c the category of the item, \"Diary\" for entries from the diary,
  1298. or as given by the CATEGORY keyword or derived from the file name
  1299. %e the effort required by the item
  1300. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1301. %T the last tag of the item (ignore inherited tags, which come first)
  1302. %t the HH:MM time-of-day specification if one applies to the entry
  1303. %s Scheduling/Deadline information, a short string
  1304. %(expression) Eval EXPRESSION and replace the control string
  1305. by the result
  1306. All specifiers work basically like the standard `%s' of printf, but may
  1307. contain two additional characters: a question mark just after the `%'
  1308. and a whitespace/punctuation character just before the final letter.
  1309. If the first character after `%' is a question mark, the entire field
  1310. will only be included if the corresponding value applies to the current
  1311. entry. This is useful for fields which should have fixed width when
  1312. present, but zero width when absent. For example, \"%?-12t\" will
  1313. result in a 12 character time field if a time of the day is specified,
  1314. but will completely disappear in entries which do not contain a time.
  1315. If there is punctuation or whitespace character just before the final
  1316. format letter, this character will be appended to the field value if
  1317. the value is not empty. For example, the format \"%-12:c\" leads to
  1318. \"Diary: \" if the category is \"Diary\". If the category were be
  1319. empty, no additional colon would be inserted.
  1320. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1321. which means:
  1322. - Indent the line with two space characters
  1323. - Give the category a 12 chars wide field, padded with whitespace on
  1324. the right (because of `-'). Append a colon if there is a category
  1325. (because of `:').
  1326. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1327. time, don't put in an empty field, just skip it (because of '?').
  1328. - Finally, put the scheduling information.
  1329. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1330. `org-agenda-remove-tags'.
  1331. Custom commands can set this variable in the options section."
  1332. :type '(choice
  1333. (string :tag "General format")
  1334. (list :greedy t :tag "View dependent"
  1335. (cons (const agenda) (string :tag "Format"))
  1336. (cons (const timeline) (string :tag "Format"))
  1337. (cons (const todo) (string :tag "Format"))
  1338. (cons (const tags) (string :tag "Format"))
  1339. (cons (const search) (string :tag "Format"))))
  1340. :group 'org-agenda-line-format)
  1341. (defvar org-prefix-format-compiled nil
  1342. "The compiled prefix format and associated variables.
  1343. This is a list where first element is a list of variable bindings, and second
  1344. element is the compiled format expression. See the variable
  1345. `org-agenda-prefix-format'.")
  1346. (defcustom org-agenda-todo-keyword-format "%-1s"
  1347. "Format for the TODO keyword in agenda lines.
  1348. Set this to something like \"%-12s\" if you want all TODO keywords
  1349. to occupy a fixed space in the agenda display."
  1350. :group 'org-agenda-line-format
  1351. :type 'string)
  1352. (defcustom org-agenda-diary-sexp-prefix nil
  1353. "A regexp that matches part of a diary sexp entry
  1354. which should be treated as scheduling/deadline information in
  1355. `org-agenda'.
  1356. For example, you can use this to extract the `diary-remind-message' from
  1357. `diary-remind' entries."
  1358. :group 'org-agenda-line-format
  1359. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1360. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1361. "Text preceding timerange entries in the agenda view.
  1362. This is a list with two strings. The first applies when the range
  1363. is entirely on one day. The second applies if the range spans several days.
  1364. The strings may have two \"%d\" format specifiers which will be filled
  1365. with the sequence number of the days, and the total number of days in the
  1366. range, respectively."
  1367. :group 'org-agenda-line-format
  1368. :type '(list
  1369. (string :tag "Deadline today ")
  1370. (choice :tag "Deadline relative"
  1371. (string :tag "Format string")
  1372. (function))))
  1373. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1374. "Text preceding scheduled items in the agenda view.
  1375. This is a list with two strings. The first applies when the item is
  1376. scheduled on the current day. The second applies when it has been scheduled
  1377. previously, it may contain a %d indicating that this is the nth time that
  1378. this item is scheduled, due to automatic rescheduling of unfinished items
  1379. for the following day. So this number is one larger than the number of days
  1380. that passed since this item was scheduled first."
  1381. :group 'org-agenda-line-format
  1382. :type '(list
  1383. (string :tag "Scheduled today ")
  1384. (string :tag "Scheduled previously")))
  1385. (defcustom org-agenda-inactive-leader "["
  1386. "Text preceding item pulled into the agenda by inactive time stamps.
  1387. These entries are added to the agenda when pressing \"[\"."
  1388. :group 'org-agenda-line-format
  1389. :version "24.1"
  1390. :type '(list
  1391. (string :tag "Scheduled today ")
  1392. (string :tag "Scheduled previously")))
  1393. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1394. "Text preceding deadline items in the agenda view.
  1395. This is a list with two strings. The first applies when the item has its
  1396. deadline on the current day. The second applies when it is in the past or
  1397. in the future, it may contain %d to capture how many days away the deadline
  1398. is (was)."
  1399. :group 'org-agenda-line-format
  1400. :type '(list
  1401. (string :tag "Deadline today ")
  1402. (choice :tag "Deadline relative"
  1403. (string :tag "Format string")
  1404. (function))))
  1405. (defcustom org-agenda-remove-times-when-in-prefix t
  1406. "Non-nil means remove duplicate time specifications in agenda items.
  1407. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1408. time-of-day specification in a headline or diary entry is extracted and
  1409. placed into the prefix. If this option is non-nil, the original specification
  1410. \(a timestamp or -range, or just a plain time(range) specification like
  1411. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1412. cluttered.
  1413. The option can be t or nil. It may also be the symbol `beg', indicating
  1414. that the time should only be removed when it is located at the beginning of
  1415. the headline/diary entry."
  1416. :group 'org-agenda-line-format
  1417. :type '(choice
  1418. (const :tag "Always" t)
  1419. (const :tag "Never" nil)
  1420. (const :tag "When at beginning of entry" beg)))
  1421. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1422. "Non-nil means remove time ranges specifications in agenda
  1423. items that span on several days."
  1424. :group 'org-agenda-line-format
  1425. :version "24.1"
  1426. :type 'boolean)
  1427. (defcustom org-agenda-default-appointment-duration nil
  1428. "Default duration for appointments that only have a starting time.
  1429. When nil, no duration is specified in such cases.
  1430. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1431. :group 'org-agenda-line-format
  1432. :type '(choice
  1433. (integer :tag "Minutes")
  1434. (const :tag "No default duration")))
  1435. (defcustom org-agenda-show-inherited-tags t
  1436. "Non-nil means show inherited tags in each agenda line."
  1437. :group 'org-agenda-line-format
  1438. :type 'boolean)
  1439. (defcustom org-agenda-hide-tags-regexp nil
  1440. "Regular expression used to filter away specific tags in agenda views.
  1441. This means that these tags will be present, but not be shown in the agenda
  1442. line. Secondary filtering will still work on the hidden tags.
  1443. Nil means don't hide any tags."
  1444. :group 'org-agenda-line-format
  1445. :type '(choice
  1446. (const :tag "Hide none" nil)
  1447. (string :tag "Regexp ")))
  1448. (defcustom org-agenda-remove-tags nil
  1449. "Non-nil means remove the tags from the headline copy in the agenda.
  1450. When this is the symbol `prefix', only remove tags when
  1451. `org-agenda-prefix-format' contains a `%T' specifier."
  1452. :group 'org-agenda-line-format
  1453. :type '(choice
  1454. (const :tag "Always" t)
  1455. (const :tag "Never" nil)
  1456. (const :tag "When prefix format contains %T" prefix)))
  1457. (if (fboundp 'defvaralias)
  1458. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1459. 'org-agenda-remove-tags))
  1460. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1461. "Shift tags in agenda items to this column.
  1462. If this number is positive, it specifies the column. If it is negative,
  1463. it means that the tags should be flushright to that column. For example,
  1464. -80 works well for a normal 80 character screen."
  1465. :group 'org-agenda-line-format
  1466. :type 'integer)
  1467. (if (fboundp 'defvaralias)
  1468. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1469. (defcustom org-agenda-fontify-priorities 'cookies
  1470. "Non-nil means highlight low and high priorities in agenda.
  1471. When t, the highest priority entries are bold, lowest priority italic.
  1472. However, settings in `org-priority-faces' will overrule these faces.
  1473. When this variable is the symbol `cookies', only fontify the
  1474. cookies, not the entire task.
  1475. This may also be an association list of priority faces, whose
  1476. keys are the character values of `org-highest-priority',
  1477. `org-default-priority', and `org-lowest-priority' (the default values
  1478. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1479. color as a string, or a list like `(:background \"Red\")'.
  1480. If it is a color, the variable `org-faces-easy-properties'
  1481. determines if it is a foreground or a background color."
  1482. :group 'org-agenda-line-format
  1483. :type '(choice
  1484. (const :tag "Never" nil)
  1485. (const :tag "Defaults" t)
  1486. (const :tag "Cookies only" cookies)
  1487. (repeat :tag "Specify"
  1488. (list (character :tag "Priority" :value ?A)
  1489. (choice :tag "Face "
  1490. (string :tag "Color")
  1491. (sexp :tag "Face"))))))
  1492. (defcustom org-agenda-day-face-function nil
  1493. "Function called to determine what face should be used to display a day.
  1494. The only argument passed to that function is the day. It should
  1495. returns a face, or nil if does not want to specify a face and let
  1496. the normal rules apply."
  1497. :group 'org-agenda-line-format
  1498. :version "24.1"
  1499. :type 'function)
  1500. (defcustom org-agenda-category-icon-alist nil
  1501. "Alist of category icon to be displayed in agenda views.
  1502. Each entry should have the following format:
  1503. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1504. Where CATEGORY-REGEXP is a regexp matching the categories where
  1505. the icon should be displayed.
  1506. FILE-OR-DATA either a file path or a string containing image data.
  1507. The other fields can be omitted safely if not needed:
  1508. TYPE indicates the image type.
  1509. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1510. image data.
  1511. PROPS are additional image attributes to assign to the image,
  1512. like, e.g. `:ascent center'.
  1513. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1514. If you want to set the display properties yourself, just put a
  1515. list as second element:
  1516. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1517. For example, to display a 16px horizontal space for Emacs
  1518. category, you can use:
  1519. (\"Emacs\" '(space . (:width (16))))"
  1520. :group 'org-agenda-line-format
  1521. :version "24.1"
  1522. :type '(alist :key-type (string :tag "Regexp matching category")
  1523. :value-type (choice (list :tag "Icon"
  1524. (string :tag "File or data")
  1525. (symbol :tag "Type")
  1526. (boolean :tag "Data?")
  1527. (repeat :tag "Extra image properties" :inline t symbol))
  1528. (list :tag "Display properties" sexp))))
  1529. (defgroup org-agenda-column-view nil
  1530. "Options concerning column view in the agenda."
  1531. :tag "Org Agenda Column View"
  1532. :group 'org-agenda)
  1533. (defcustom org-agenda-columns-show-summaries t
  1534. "Non-nil means show summaries for columns displayed in the agenda view."
  1535. :group 'org-agenda-column-view
  1536. :type 'boolean)
  1537. (defcustom org-agenda-columns-compute-summary-properties t
  1538. "Non-nil means recompute all summary properties before column view.
  1539. When column view in the agenda is listing properties that have a summary
  1540. operator, it can go to all relevant buffers and recompute the summaries
  1541. there. This can mean overhead for the agenda column view, but is necessary
  1542. to have thing up to date.
  1543. As a special case, a CLOCKSUM property also makes sure that the clock
  1544. computations are current."
  1545. :group 'org-agenda-column-view
  1546. :type 'boolean)
  1547. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1548. "Non-nil means the duration of an appointment will add to day effort.
  1549. The property to which appointment durations will be added is the one given
  1550. in the option `org-effort-property'. If an appointment does not have
  1551. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1552. is not set, an appointment without end time will not contribute to the time
  1553. estimate."
  1554. :group 'org-agenda-column-view
  1555. :type 'boolean)
  1556. (defcustom org-agenda-auto-exclude-function nil
  1557. "A function called with a tag to decide if it is filtered on '/ RET'.
  1558. The sole argument to the function, which is called once for each
  1559. possible tag, is a string giving the name of the tag. The
  1560. function should return either nil if the tag should be included
  1561. as normal, or \"-<TAG>\" to exclude the tag.
  1562. Note that for the purpose of tag filtering, only the lower-case version of
  1563. all tags will be considered, so that this function will only ever see
  1564. the lower-case version of all tags."
  1565. :group 'org-agenda
  1566. :type 'function)
  1567. (defcustom org-agenda-bulk-custom-functions nil
  1568. "Alist of characters and custom functions for bulk actions.
  1569. For example, this value makes those two functions available:
  1570. '((?R set-category)
  1571. (?C bulk-cut))
  1572. With selected entries in an agenda buffer, `B R' will call
  1573. the custom function `set-category' on the selected entries.
  1574. Note that functions in this alist don't need to be quoted."
  1575. :type 'alist
  1576. :version "24.1"
  1577. :group 'org-agenda)
  1578. (eval-when-compile
  1579. (require 'cl))
  1580. (require 'org)
  1581. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1582. "Execute BODY with point at location given by `org-hd-marker' property.
  1583. If STRING is non-nil, the text property will be fetched from position 0
  1584. in that string. If STRING is nil, it will be fetched from the beginning
  1585. of the current line."
  1586. (org-with-gensyms (marker)
  1587. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1588. 'org-hd-marker ,string)))
  1589. (with-current-buffer (marker-buffer ,marker)
  1590. (save-excursion
  1591. (goto-char ,marker)
  1592. ,@body)))))
  1593. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1594. (defun org-add-agenda-custom-command (entry)
  1595. "Replace or add a command in `org-agenda-custom-commands'.
  1596. This is mostly for hacking and trying a new command - once the command
  1597. works you probably want to add it to `org-agenda-custom-commands' for good."
  1598. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1599. (if ass
  1600. (setcdr ass (cdr entry))
  1601. (push entry org-agenda-custom-commands))))
  1602. ;;; Define the org-agenda-mode
  1603. (defvar org-agenda-mode-map (make-sparse-keymap)
  1604. "Keymap for `org-agenda-mode'.")
  1605. (if (fboundp 'defvaralias)
  1606. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1607. (defvar org-agenda-menu) ; defined later in this file.
  1608. (defvar org-agenda-restrict) ; defined later in this file.
  1609. (defvar org-agenda-follow-mode nil)
  1610. (defvar org-agenda-entry-text-mode nil)
  1611. (defvar org-agenda-clockreport-mode nil)
  1612. (defvar org-agenda-show-log nil)
  1613. (defvar org-agenda-redo-command nil)
  1614. (defvar org-agenda-query-string nil)
  1615. (defvar org-agenda-mode-hook nil
  1616. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1617. (defvar org-agenda-type nil)
  1618. (defvar org-agenda-force-single-file nil)
  1619. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1620. ;;; Multiple agenda buffers support
  1621. (defcustom org-agenda-sticky nil
  1622. "Non-nil means agenda q key will bury agenda buffers.
  1623. Agenda commands will then show existing buffer instead of generating new ones.
  1624. When nil, `q' will kill the single agenda buffer."
  1625. :group 'org-agenda
  1626. :type 'boolean
  1627. :set (lambda (var val)
  1628. (if (boundp var)
  1629. (org-toggle-sticky-agenda (if val 1 0))
  1630. (set var val))))
  1631. (defun org-toggle-sticky-agenda (&optional arg)
  1632. "Toggle `org-agenda-sticky'."
  1633. (interactive "P")
  1634. (let ((new-value (if arg
  1635. (> (prefix-numeric-value arg) 0)
  1636. (not org-agenda-sticky))))
  1637. (if (equal new-value org-agenda-sticky)
  1638. (and (org-called-interactively-p 'interactive)
  1639. (message "Sticky agenda was already %s"
  1640. (if org-agenda-sticky "enabled" "disabled")))
  1641. (setq org-agenda-sticky new-value)
  1642. (org-agenda-kill-all-agenda-buffers)
  1643. (and (org-called-interactively-p 'interactive)
  1644. (message "Sticky agenda was %s"
  1645. (if org-agenda-sticky "enabled" "disabled"))))))
  1646. (defvar org-agenda-buffer nil
  1647. "Agenda buffer currently being generated.")
  1648. (defvar org-agenda-last-prefix-arg nil)
  1649. (defvar org-agenda-this-buffer-name nil)
  1650. (defvar org-agenda-doing-sticky-redo nil)
  1651. (defvar org-agenda-this-buffer-is-sticky nil)
  1652. (defconst org-agenda-local-vars
  1653. '(org-agenda-this-buffer-name
  1654. org-agenda-undo-list
  1655. org-agenda-pending-undo-list
  1656. org-agenda-follow-mode
  1657. org-agenda-entry-text-mode
  1658. org-agenda-clockreport-mode
  1659. org-agenda-show-log
  1660. org-agenda-redo-command
  1661. org-agenda-query-string
  1662. org-agenda-type
  1663. org-agenda-bulk-marked-entries
  1664. org-agenda-undo-has-started-in
  1665. org-agenda-last-arguments
  1666. org-agenda-info
  1667. org-agenda-tag-filter-overlays
  1668. org-agenda-cat-filter-overlays
  1669. org-pre-agenda-window-conf
  1670. org-agenda-columns-active
  1671. org-agenda-tag-filter
  1672. org-agenda-category-filter
  1673. org-agenda-markers
  1674. org-agenda-last-search-view-search-was-boolean
  1675. org-agenda-filtered-by-category
  1676. org-agenda-filter-form
  1677. org-agenda-show-window
  1678. org-agenda-cycle-counter
  1679. org-agenda-last-prefix-arg)
  1680. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1681. (defun org-agenda-mode ()
  1682. "Mode for time-sorted view on action items in Org-mode files.
  1683. The following commands are available:
  1684. \\{org-agenda-mode-map}"
  1685. (interactive)
  1686. (cond (org-agenda-doing-sticky-redo
  1687. ;; Refreshing sticky agenda-buffer
  1688. ;;
  1689. ;; Preserve the value of `org-agenda-local-vars' variables,
  1690. ;; while letting `kill-all-local-variables' kill the rest
  1691. (let ((save (buffer-local-variables)))
  1692. (kill-all-local-variables)
  1693. (mapc 'make-local-variable org-agenda-local-vars)
  1694. (dolist (elem save)
  1695. (let ((var (car elem))
  1696. (val (cdr elem)))
  1697. (when (and val
  1698. (member var org-agenda-local-vars))
  1699. (set var val)))))
  1700. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1701. (org-agenda-sticky
  1702. ;; Creating a sticky Agenda buffer for the first time
  1703. (kill-all-local-variables)
  1704. (mapc 'make-local-variable org-agenda-local-vars)
  1705. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1706. (t
  1707. ;; Creating a non-sticky agenda buffer
  1708. (kill-all-local-variables)
  1709. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1710. (setq org-agenda-undo-list nil
  1711. org-agenda-pending-undo-list nil
  1712. org-agenda-bulk-marked-entries nil)
  1713. (setq major-mode 'org-agenda-mode)
  1714. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1715. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1716. (setq mode-name "Org-Agenda")
  1717. (use-local-map org-agenda-mode-map)
  1718. (easy-menu-add org-agenda-menu)
  1719. (if org-startup-truncated (setq truncate-lines t))
  1720. (org-set-local 'line-move-visual nil)
  1721. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1722. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1723. ;; Make sure properties are removed when copying text
  1724. (make-local-variable 'filter-buffer-substring-functions)
  1725. (add-hook 'filter-buffer-substring-functions
  1726. (lambda (fun start end delete)
  1727. (substring-no-properties (funcall fun start end delete))))
  1728. (unless org-agenda-keep-modes
  1729. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1730. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1731. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1732. org-agenda-show-log org-agenda-start-with-log-mode))
  1733. (easy-menu-change
  1734. '("Agenda") "Agenda Files"
  1735. (append
  1736. (list
  1737. (vector
  1738. (if (get 'org-agenda-files 'org-restrict)
  1739. "Restricted to single file"
  1740. "Edit File List")
  1741. '(org-edit-agenda-file-list)
  1742. (not (get 'org-agenda-files 'org-restrict)))
  1743. "--")
  1744. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1745. (org-agenda-set-mode-name)
  1746. (apply
  1747. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1748. (list 'org-agenda-mode-hook)))
  1749. (substitute-key-definition 'undo 'org-agenda-undo
  1750. org-agenda-mode-map global-map)
  1751. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1752. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1753. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1754. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1755. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1756. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1757. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1758. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1759. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1760. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1761. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1762. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1763. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1764. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1765. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1766. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1767. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1768. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1769. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1770. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1771. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1772. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1773. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1774. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1775. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1776. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1777. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1778. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1779. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1780. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1781. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1782. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1783. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1784. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1785. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1786. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1787. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1788. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1789. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1790. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1791. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1792. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1793. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1794. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1795. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1796. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1797. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1798. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1799. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1800. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1801. (while l (org-defkey org-agenda-mode-map
  1802. (int-to-string (pop l)) 'digit-argument)))
  1803. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1804. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1805. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1806. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1807. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1808. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1809. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1810. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1811. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1812. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1813. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1814. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1815. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1816. 'org-clock-modify-effort-estimate)
  1817. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1818. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1819. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1820. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1821. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1822. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1823. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1824. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1825. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1826. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1827. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1828. (substitute-key-definition 'next-line 'org-agenda-next-line
  1829. org-agenda-mode-map global-map)
  1830. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1831. org-agenda-mode-map global-map)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1833. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1834. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1835. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1836. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1837. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1838. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1839. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1840. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1841. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1842. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1843. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1844. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1845. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1846. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1847. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1849. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1850. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1851. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1852. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1853. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1854. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1855. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1856. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1857. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1858. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1859. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1860. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1861. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1862. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1863. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1864. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1865. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1866. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1867. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1868. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1869. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1870. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1871. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1872. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1873. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1874. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1875. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1876. (when org-agenda-mouse-1-follows-link
  1877. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1878. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1879. '("Agenda"
  1880. ("Agenda Files")
  1881. "--"
  1882. ("Agenda Dates"
  1883. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1884. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1885. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1886. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1887. "--"
  1888. ("View"
  1889. ["Day View" org-agenda-day-view
  1890. :active (org-agenda-check-type nil 'agenda)
  1891. :style radio :selected (eq org-agenda-current-span 'day)
  1892. :keys "v d (or just d)"]
  1893. ["Week View" org-agenda-week-view
  1894. :active (org-agenda-check-type nil 'agenda)
  1895. :style radio :selected (eq org-agenda-current-span 'week)
  1896. :keys "v w (or just w)"]
  1897. ["Month View" org-agenda-month-view
  1898. :active (org-agenda-check-type nil 'agenda)
  1899. :style radio :selected (eq org-agenda-current-span 'month)
  1900. :keys "v m"]
  1901. ["Year View" org-agenda-year-view
  1902. :active (org-agenda-check-type nil 'agenda)
  1903. :style radio :selected (eq org-agenda-current-span 'year)
  1904. :keys "v y"]
  1905. "--"
  1906. ["Include Diary" org-agenda-toggle-diary
  1907. :style toggle :selected org-agenda-include-diary
  1908. :active (org-agenda-check-type nil 'agenda)]
  1909. ["Include Deadlines" org-agenda-toggle-deadlines
  1910. :style toggle :selected org-agenda-include-deadlines
  1911. :active (org-agenda-check-type nil 'agenda)]
  1912. ["Use Time Grid" org-agenda-toggle-time-grid
  1913. :style toggle :selected org-agenda-use-time-grid
  1914. :active (org-agenda-check-type nil 'agenda)]
  1915. "--"
  1916. ["Show clock report" org-agenda-clockreport-mode
  1917. :style toggle :selected org-agenda-clockreport-mode
  1918. :active (org-agenda-check-type nil 'agenda)]
  1919. ["Show some entry text" org-agenda-entry-text-mode
  1920. :style toggle :selected org-agenda-entry-text-mode
  1921. :active t]
  1922. "--"
  1923. ["Show Logbook entries" org-agenda-log-mode
  1924. :style toggle :selected org-agenda-show-log
  1925. :active (org-agenda-check-type nil 'agenda 'timeline)
  1926. :keys "v l (or just l)"]
  1927. ["Include archived trees" org-agenda-archives-mode
  1928. :style toggle :selected org-agenda-archives-mode :active t
  1929. :keys "v a"]
  1930. ["Include archive files" (org-agenda-archives-mode t)
  1931. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1932. :keys "v A"]
  1933. "--"
  1934. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1935. ["Write view to file" org-agenda-write t]
  1936. ["Rebuild buffer" org-agenda-redo t]
  1937. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1938. "--"
  1939. ["Show original entry" org-agenda-show t]
  1940. ["Go To (other window)" org-agenda-goto t]
  1941. ["Go To (this window)" org-agenda-switch-to t]
  1942. ["Follow Mode" org-agenda-follow-mode
  1943. :style toggle :selected org-agenda-follow-mode :active t]
  1944. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1945. "--"
  1946. ("TODO"
  1947. ["Cycle TODO" org-agenda-todo t]
  1948. ["Next TODO set" org-agenda-todo-nextset t]
  1949. ["Previous TODO set" org-agenda-todo-previousset t]
  1950. ["Add note" org-agenda-add-note t])
  1951. ("Archive/Refile/Delete"
  1952. ["Archive default" org-agenda-archive-default t]
  1953. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1954. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1955. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1956. ["Archive subtree" org-agenda-archive t]
  1957. "--"
  1958. ["Refile" org-agenda-refile t]
  1959. "--"
  1960. ["Delete subtree" org-agenda-kill t])
  1961. ("Bulk action"
  1962. ["Mark entry" org-agenda-bulk-mark t]
  1963. ["Mark all" org-agenda-bulk-mark-all t]
  1964. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1965. ["Unmark entry" org-agenda-bulk-unmark t]
  1966. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
  1967. ["Act on all marked" org-agenda-bulk-action t]
  1968. "--"
  1969. ("Tags and Properties"
  1970. ["Show all Tags" org-agenda-show-tags t]
  1971. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1972. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1973. "--"
  1974. ["Column View" org-columns t])
  1975. ("Deadline/Schedule"
  1976. ["Schedule" org-agenda-schedule t]
  1977. ["Set Deadline" org-agenda-deadline t]
  1978. "--"
  1979. ["Mark item" org-agenda-action :active t :keys "k m"]
  1980. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1981. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1982. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1983. "--"
  1984. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1985. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1986. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1987. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1988. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1989. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1990. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1991. ("Clock and Effort"
  1992. ["Clock in" org-agenda-clock-in t]
  1993. ["Clock out" org-agenda-clock-out t]
  1994. ["Clock cancel" org-agenda-clock-cancel t]
  1995. ["Goto running clock" org-clock-goto t]
  1996. "--"
  1997. ["Set Effort" org-agenda-set-effort t]
  1998. ["Change clocked effort" org-clock-modify-effort-estimate
  1999. (org-clock-is-active)])
  2000. ("Priority"
  2001. ["Set Priority" org-agenda-priority t]
  2002. ["Increase Priority" org-agenda-priority-up t]
  2003. ["Decrease Priority" org-agenda-priority-down t]
  2004. ["Show Priority" org-agenda-show-priority t])
  2005. ("Calendar/Diary"
  2006. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2007. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2008. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2009. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2010. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2011. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2012. "--"
  2013. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2014. "--"
  2015. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2016. "--"
  2017. ("MobileOrg"
  2018. ["Push Files and Views" org-mobile-push t]
  2019. ["Get Captured and Flagged" org-mobile-pull t]
  2020. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2021. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2022. "--"
  2023. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2024. "--"
  2025. ["Quit" org-agenda-quit t]
  2026. ["Exit and Release Buffers" org-agenda-exit t]
  2027. ))
  2028. ;;; Agenda undo
  2029. (defvar org-agenda-allow-remote-undo t
  2030. "Non-nil means allow remote undo from the agenda buffer.")
  2031. (defvar org-agenda-undo-list nil
  2032. "List of undoable operations in the agenda since last refresh.")
  2033. (defvar org-agenda-undo-has-started-in nil
  2034. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2035. (defvar org-agenda-pending-undo-list nil
  2036. "In a series of undo commands, this is the list of remaining undo items.")
  2037. (defun org-agenda-undo ()
  2038. "Undo a remote editing step in the agenda.
  2039. This undoes changes both in the agenda buffer and in the remote buffer
  2040. that have been changed along."
  2041. (interactive)
  2042. (or org-agenda-allow-remote-undo
  2043. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2044. (if (not (eq this-command last-command))
  2045. (setq org-agenda-undo-has-started-in nil
  2046. org-agenda-pending-undo-list org-agenda-undo-list))
  2047. (if (not org-agenda-pending-undo-list)
  2048. (error "No further undo information"))
  2049. (let* ((entry (pop org-agenda-pending-undo-list))
  2050. buf line cmd rembuf)
  2051. (setq cmd (pop entry) line (pop entry))
  2052. (setq rembuf (nth 2 entry))
  2053. (org-with-remote-undo rembuf
  2054. (while (bufferp (setq buf (pop entry)))
  2055. (if (pop entry)
  2056. (with-current-buffer buf
  2057. (let ((last-undo-buffer buf)
  2058. (inhibit-read-only t))
  2059. (unless (memq buf org-agenda-undo-has-started-in)
  2060. (push buf org-agenda-undo-has-started-in)
  2061. (make-local-variable 'pending-undo-list)
  2062. (undo-start))
  2063. (while (and pending-undo-list
  2064. (listp pending-undo-list)
  2065. (not (car pending-undo-list)))
  2066. (pop pending-undo-list))
  2067. (undo-more 1))))))
  2068. (org-goto-line line)
  2069. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2070. (defun org-verify-change-for-undo (l1 l2)
  2071. "Verify that a real change occurred between the undo lists L1 and L2."
  2072. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2073. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2074. (not (eq l1 l2)))
  2075. ;;; Agenda dispatch
  2076. (defvar org-agenda-restrict nil)
  2077. (defvar org-agenda-restrict-begin (make-marker))
  2078. (defvar org-agenda-restrict-end (make-marker))
  2079. (defvar org-agenda-last-dispatch-buffer nil)
  2080. (defvar org-agenda-overriding-restriction nil)
  2081. ;;;###autoload
  2082. (defun org-agenda (&optional arg keys restriction)
  2083. "Dispatch agenda commands to collect entries to the agenda buffer.
  2084. Prompts for a command to execute. Any prefix arg will be passed
  2085. on to the selected command. The default selections are:
  2086. a Call `org-agenda-list' to display the agenda for current day or week.
  2087. t Call `org-todo-list' to display the global todo list.
  2088. T Call `org-todo-list' to display the global todo list, select only
  2089. entries with a specific TODO keyword (the user gets a prompt).
  2090. m Call `org-tags-view' to display headlines with tags matching
  2091. a condition (the user is prompted for the condition).
  2092. M Like `m', but select only TODO entries, no ordinary headlines.
  2093. L Create a timeline for the current buffer.
  2094. e Export views to associated files.
  2095. s Search entries for keywords.
  2096. / Multi occur across all agenda files and also files listed
  2097. in `org-agenda-text-search-extra-files'.
  2098. < Restrict agenda commands to buffer, subtree, or region.
  2099. Press several times to get the desired effect.
  2100. > Remove a previous restriction.
  2101. # List \"stuck\" projects.
  2102. ! Configure what \"stuck\" means.
  2103. C Configure custom agenda commands.
  2104. More commands can be added by configuring the variable
  2105. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2106. searches can be pre-defined in this way.
  2107. If the current buffer is in Org-mode and visiting a file, you can also
  2108. first press `<' once to indicate that the agenda should be temporarily
  2109. \(until the next use of \\[org-agenda]) restricted to the current file.
  2110. Pressing `<' twice means to restrict to the current subtree or region
  2111. \(if active)."
  2112. (interactive "P")
  2113. (catch 'exit
  2114. (let* ((prefix-descriptions nil)
  2115. (org-agenda-buffer-name org-agenda-buffer-name)
  2116. (org-agenda-window-setup (if (equal (buffer-name)
  2117. org-agenda-buffer-name)
  2118. 'current-window
  2119. org-agenda-window-setup))
  2120. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2121. (org-agenda-custom-commands
  2122. ;; normalize different versions
  2123. (delq nil
  2124. (mapcar
  2125. (lambda (x)
  2126. (cond ((stringp (cdr x))
  2127. (push x prefix-descriptions)
  2128. nil)
  2129. ((stringp (nth 1 x)) x)
  2130. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2131. (t (cons (car x) (cons "" (cdr x))))))
  2132. org-agenda-custom-commands)))
  2133. (buf (current-buffer))
  2134. (bfn (buffer-file-name (buffer-base-buffer)))
  2135. entry key type match lprops ans)
  2136. ;; Turn off restriction unless there is an overriding one,
  2137. (unless org-agenda-overriding-restriction
  2138. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2139. ;; There is a request to keep the file list in place
  2140. (put 'org-agenda-files 'org-restrict nil))
  2141. (setq org-agenda-restrict nil)
  2142. (move-marker org-agenda-restrict-begin nil)
  2143. (move-marker org-agenda-restrict-end nil))
  2144. ;; Delete old local properties
  2145. (put 'org-agenda-redo-command 'org-lprops nil)
  2146. ;; Delete previously set last-arguments
  2147. (put 'org-agenda-redo-command 'last-args nil)
  2148. ;; Remember where this call originated
  2149. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2150. (unless keys
  2151. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2152. keys (car ans)
  2153. restriction (cdr ans)))
  2154. ;; If we have sticky agenda buffers, set a name for the buffer,
  2155. ;; depending on the invoking keys. The user may still set this
  2156. ;; as a command option, which will overwrite what we do here.
  2157. (if org-agenda-sticky
  2158. (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
  2159. ;; Establish the restriction, if any
  2160. (when (and (not org-agenda-overriding-restriction) restriction)
  2161. (put 'org-agenda-files 'org-restrict (list bfn))
  2162. (cond
  2163. ((eq restriction 'region)
  2164. (setq org-agenda-restrict t)
  2165. (move-marker org-agenda-restrict-begin (region-beginning))
  2166. (move-marker org-agenda-restrict-end (region-end)))
  2167. ((eq restriction 'subtree)
  2168. (save-excursion
  2169. (setq org-agenda-restrict t)
  2170. (org-back-to-heading t)
  2171. (move-marker org-agenda-restrict-begin (point))
  2172. (move-marker org-agenda-restrict-end
  2173. (progn (org-end-of-subtree t)))))))
  2174. ;; For example the todo list should not need it (but does...)
  2175. (cond
  2176. ((setq entry (assoc keys org-agenda-custom-commands))
  2177. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2178. (progn
  2179. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2180. lprops (nth 4 entry))
  2181. (put 'org-agenda-redo-command 'org-lprops lprops)
  2182. (cond
  2183. ((eq type 'agenda)
  2184. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2185. ((eq type 'alltodo)
  2186. (org-let lprops '(org-todo-list current-prefix-arg)))
  2187. ((eq type 'search)
  2188. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2189. ((eq type 'stuck)
  2190. (org-let lprops '(org-agenda-list-stuck-projects
  2191. current-prefix-arg)))
  2192. ((eq type 'tags)
  2193. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2194. ((eq type 'tags-todo)
  2195. (org-let lprops '(org-tags-view '(4) match)))
  2196. ((eq type 'todo)
  2197. (org-let lprops '(org-todo-list match)))
  2198. ((eq type 'tags-tree)
  2199. (org-check-for-org-mode)
  2200. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2201. ((eq type 'todo-tree)
  2202. (org-check-for-org-mode)
  2203. (org-let lprops
  2204. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2205. (regexp-quote match) "\\>"))))
  2206. ((eq type 'occur-tree)
  2207. (org-check-for-org-mode)
  2208. (org-let lprops '(org-occur match)))
  2209. ((functionp type)
  2210. (org-let lprops '(funcall type match)))
  2211. ((fboundp type)
  2212. (org-let lprops '(funcall type match)))
  2213. (t (error "Invalid custom agenda command type %s" type))))
  2214. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2215. ((equal keys "C")
  2216. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2217. (customize-variable 'org-agenda-custom-commands))
  2218. ((equal keys "a") (call-interactively 'org-agenda-list))
  2219. ((equal keys "s") (call-interactively 'org-search-view))
  2220. ((equal keys "t") (call-interactively 'org-todo-list))
  2221. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2222. ((equal keys "m") (call-interactively 'org-tags-view))
  2223. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2224. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2225. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2226. (org-add-hook
  2227. 'post-command-hook
  2228. (lambda ()
  2229. (unless (current-message)
  2230. (let* ((m (org-agenda-get-any-marker))
  2231. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2232. (when note
  2233. (message (concat
  2234. "FLAGGING-NOTE ([?] for more info): "
  2235. (org-add-props
  2236. (replace-regexp-in-string
  2237. "\\\\n" "//"
  2238. (copy-sequence note))
  2239. nil 'face 'org-warning)))))))
  2240. t t))
  2241. ((equal keys "L")
  2242. (unless (derived-mode-p 'org-mode)
  2243. (error "This is not an Org-mode file"))
  2244. (unless restriction
  2245. (put 'org-agenda-files 'org-restrict (list bfn))
  2246. (org-call-with-arg 'org-timeline arg)))
  2247. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2248. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2249. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2250. (t (error "Invalid agenda key"))))))
  2251. (defun org-agenda-append-agenda ()
  2252. "Append another agenda view to the current one.
  2253. This function allows interactive building of block agendas.
  2254. Agenda views are separated by `org-agenda-block-separator'."
  2255. (interactive)
  2256. (unless (string= (buffer-name) org-agenda-buffer-name)
  2257. (error "Can only append from within agenda buffer"))
  2258. (let ((org-agenda-multi t))
  2259. (org-agenda)
  2260. (widen)))
  2261. (defun org-agenda-normalize-custom-commands (cmds)
  2262. (delq nil
  2263. (mapcar
  2264. (lambda (x)
  2265. (cond ((stringp (cdr x)) nil)
  2266. ((stringp (nth 1 x)) x)
  2267. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2268. (t (cons (car x) (cons "" (cdr x))))))
  2269. cmds)))
  2270. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2271. "The user interface for selecting an agenda command."
  2272. (catch 'exit
  2273. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2274. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2275. (region-p (org-region-active-p))
  2276. (custom org-agenda-custom-commands)
  2277. (selstring "")
  2278. restriction second-time
  2279. c entry key type match prefixes rmheader header-end custom1 desc
  2280. line lines left right n n1)
  2281. (save-window-excursion
  2282. (delete-other-windows)
  2283. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2284. (erase-buffer)
  2285. (insert (eval-when-compile
  2286. (let ((header
  2287. "Press key for an agenda command: < Buffer, subtree/region restriction
  2288. -------------------------------- > Remove restriction
  2289. a Agenda for current week or day e Export agenda views
  2290. t List of all TODO entries T Entries with special TODO kwd
  2291. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2292. L Timeline for current buffer # List stuck projects (!=configure)
  2293. s Search for keywords * Toggle sticky agenda views
  2294. / Multi-occur ? Find :FLAGGED: entries
  2295. C Configure custom agenda commands
  2296. ")
  2297. (start 0))
  2298. (while (string-match
  2299. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2300. header start)
  2301. (setq start (match-end 0))
  2302. (add-text-properties (match-beginning 2) (match-end 2)
  2303. '(face bold) header))
  2304. header)))
  2305. (setq header-end (move-marker (make-marker) (point)))
  2306. (while t
  2307. (setq custom1 custom)
  2308. (when (eq rmheader t)
  2309. (org-goto-line 1)
  2310. (re-search-forward ":" nil t)
  2311. (delete-region (match-end 0) (point-at-eol))
  2312. (forward-char 1)
  2313. (looking-at "-+")
  2314. (delete-region (match-end 0) (point-at-eol))
  2315. (move-marker header-end (match-end 0)))
  2316. (goto-char header-end)
  2317. (delete-region (point) (point-max))
  2318. ;; Produce all the lines that describe custom commands and prefixes
  2319. (setq lines nil)
  2320. (while (setq entry (pop custom1))
  2321. (setq key (car entry) desc (nth 1 entry)
  2322. type (nth 2 entry)
  2323. match (nth 3 entry))
  2324. (if (> (length key) 1)
  2325. (add-to-list 'prefixes (string-to-char key))
  2326. (setq line
  2327. (format
  2328. "%-4s%-14s"
  2329. (org-add-props (copy-sequence key)
  2330. '(face bold))
  2331. (cond
  2332. ((string-match "\\S-" desc) desc)
  2333. ((eq type 'agenda) "Agenda for current week or day")
  2334. ((eq type 'alltodo) "List of all TODO entries")
  2335. ((eq type 'search) "Word search")
  2336. ((eq type 'stuck) "List of stuck projects")
  2337. ((eq type 'todo) "TODO keyword")
  2338. ((eq type 'tags) "Tags query")
  2339. ((eq type 'tags-todo) "Tags (TODO)")
  2340. ((eq type 'tags-tree) "Tags tree")
  2341. ((eq type 'todo-tree) "TODO kwd tree")
  2342. ((eq type 'occur-tree) "Occur tree")
  2343. ((functionp type) (if (symbolp type)
  2344. (symbol-name type)
  2345. "Lambda expression"))
  2346. (t "???"))))
  2347. (if org-agenda-menu-show-matcher
  2348. (setq line
  2349. (concat line ": "
  2350. (cond
  2351. ((stringp match)
  2352. (setq match (copy-sequence match))
  2353. (org-add-props match nil 'face 'org-warning))
  2354. (match
  2355. (format "set of %d commands" (length match)))
  2356. (t ""))))
  2357. (if (org-string-nw-p match)
  2358. (add-text-properties
  2359. 0 (length line) (list 'help-echo
  2360. (concat "Matcher: "match)) line)))
  2361. (push line lines)))
  2362. (setq lines (nreverse lines))
  2363. (when prefixes
  2364. (mapc (lambda (x)
  2365. (push
  2366. (format "%s %s"
  2367. (org-add-props (char-to-string x)
  2368. nil 'face 'bold)
  2369. (or (cdr (assoc (concat selstring
  2370. (char-to-string x))
  2371. prefix-descriptions))
  2372. "Prefix key"))
  2373. lines))
  2374. prefixes))
  2375. ;; Check if we should display in two columns
  2376. (if org-agenda-menu-two-column
  2377. (progn
  2378. (setq n (length lines)
  2379. n1 (+ (/ n 2) (mod n 2))
  2380. right (nthcdr n1 lines)
  2381. left (copy-sequence lines))
  2382. (setcdr (nthcdr (1- n1) left) nil))
  2383. (setq left lines right nil))
  2384. (while left
  2385. (insert "\n" (pop left))
  2386. (when right
  2387. (if (< (current-column) 40)
  2388. (move-to-column 40 t)
  2389. (insert " "))
  2390. (insert (pop right))))
  2391. ;; Make the window the right size
  2392. (goto-char (point-min))
  2393. (if second-time
  2394. (if (not (pos-visible-in-window-p (point-max)))
  2395. (org-fit-window-to-buffer))
  2396. (setq second-time t)
  2397. (org-fit-window-to-buffer))
  2398. ;; Ask for selection
  2399. (message "Press key for agenda command%s:"
  2400. (if (or restrict-ok org-agenda-overriding-restriction)
  2401. (if org-agenda-overriding-restriction
  2402. " (restriction lock active)"
  2403. (if restriction
  2404. (format " (restricted to %s)" restriction)
  2405. " (unrestricted)"))
  2406. ""))
  2407. (setq c (read-char-exclusive))
  2408. (message "")
  2409. (cond
  2410. ((assoc (char-to-string c) custom)
  2411. (setq selstring (concat selstring (char-to-string c)))
  2412. (throw 'exit (cons selstring restriction)))
  2413. ((memq c prefixes)
  2414. (setq selstring (concat selstring (char-to-string c))
  2415. prefixes nil
  2416. rmheader (or rmheader t)
  2417. custom (delq nil (mapcar
  2418. (lambda (x)
  2419. (if (or (= (length (car x)) 1)
  2420. (/= (string-to-char (car x)) c))
  2421. nil
  2422. (cons (substring (car x) 1) (cdr x))))
  2423. custom))))
  2424. ((eq c ?*)
  2425. (call-interactively 'org-toggle-sticky-agenda)
  2426. (sit-for 2))
  2427. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2428. (message "Restriction is only possible in Org-mode buffers")
  2429. (ding) (sit-for 1))
  2430. ((eq c ?1)
  2431. (org-agenda-remove-restriction-lock 'noupdate)
  2432. (setq restriction 'buffer))
  2433. ((eq c ?0)
  2434. (org-agenda-remove-restriction-lock 'noupdate)
  2435. (setq restriction (if region-p 'region 'subtree)))
  2436. ((eq c ?<)
  2437. (org-agenda-remove-restriction-lock 'noupdate)
  2438. (setq restriction
  2439. (cond
  2440. ((eq restriction 'buffer)
  2441. (if region-p 'region 'subtree))
  2442. ((memq restriction '(subtree region))
  2443. nil)
  2444. (t 'buffer))))
  2445. ((eq c ?>)
  2446. (org-agenda-remove-restriction-lock 'noupdate)
  2447. (setq restriction nil))
  2448. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2449. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2450. ((and (> (length selstring) 0) (eq c ?\d))
  2451. (delete-window)
  2452. (org-agenda-get-restriction-and-command prefix-descriptions))
  2453. ((equal c ?q) (error "Abort"))
  2454. (t (error "Invalid key %c" c))))))))
  2455. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2456. (defvar org-agenda-last-arguments nil
  2457. "The arguments of the previous call to `org-agenda'.")
  2458. (defun org-agenda-run-series (name series)
  2459. (org-let (nth 1 series) '(org-prepare-agenda name))
  2460. ;; We need to reset agenda markers here, because when constructing a
  2461. ;; block agenda, the individual blocks do not do that.
  2462. (org-agenda-reset-markers)
  2463. (let* ((org-agenda-multi t)
  2464. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2465. (org-agenda-overriding-arguments
  2466. (or org-agenda-overriding-arguments
  2467. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2468. (get 'org-agenda-redo-command 'last-args))))
  2469. (cmds (car series))
  2470. (gprops (nth 1 series))
  2471. match ;; The byte compiler incorrectly complains about this. Keep it!
  2472. cmd type lprops)
  2473. (while (setq cmd (pop cmds))
  2474. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2475. (cond
  2476. ((eq type 'agenda)
  2477. (org-let2 gprops lprops
  2478. '(call-interactively 'org-agenda-list)))
  2479. ((eq type 'alltodo)
  2480. (org-let2 gprops lprops
  2481. '(call-interactively 'org-todo-list)))
  2482. ((eq type 'search)
  2483. (org-let2 gprops lprops
  2484. '(org-search-view current-prefix-arg match nil)))
  2485. ((eq type 'stuck)
  2486. (org-let2 gprops lprops
  2487. '(call-interactively 'org-agenda-list-stuck-projects)))
  2488. ((eq type 'tags)
  2489. (org-let2 gprops lprops
  2490. '(org-tags-view current-prefix-arg match)))
  2491. ((eq type 'tags-todo)
  2492. (org-let2 gprops lprops
  2493. '(org-tags-view '(4) match)))
  2494. ((eq type 'todo)
  2495. (org-let2 gprops lprops
  2496. '(org-todo-list match)))
  2497. ((fboundp type)
  2498. (org-let2 gprops lprops
  2499. '(funcall type match)))
  2500. (t (error "Invalid type in command series"))))
  2501. (widen)
  2502. (setq org-agenda-redo-command redo)
  2503. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2504. (goto-char (point-min)))
  2505. (org-fit-agenda-window)
  2506. (org-let (nth 1 series) '(org-finalize-agenda)))
  2507. ;;;###autoload
  2508. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2509. "Run an agenda command in batch mode and send the result to STDOUT.
  2510. If CMD-KEY is a string of length 1, it is used as a key in
  2511. `org-agenda-custom-commands' and triggers this command. If it is a
  2512. longer string it is used as a tags/todo match string.
  2513. Parameters are alternating variable names and values that will be bound
  2514. before running the agenda command."
  2515. (org-eval-in-environment (org-make-parameter-alist parameters)
  2516. (if (> (length cmd-key) 2)
  2517. (org-tags-view nil cmd-key)
  2518. (org-agenda nil cmd-key)))
  2519. (set-buffer org-agenda-buffer-name)
  2520. (princ (buffer-string)))
  2521. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2522. (defvar org-agenda-info nil)
  2523. ;;;###autoload
  2524. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2525. "Run an agenda command in batch mode and send the result to STDOUT.
  2526. If CMD-KEY is a string of length 1, it is used as a key in
  2527. `org-agenda-custom-commands' and triggers this command. If it is a
  2528. longer string it is used as a tags/todo match string.
  2529. Parameters are alternating variable names and values that will be bound
  2530. before running the agenda command.
  2531. The output gives a line for each selected agenda item. Each
  2532. item is a list of comma-separated values, like this:
  2533. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2534. category The category of the item
  2535. head The headline, without TODO kwd, TAGS and PRIORITY
  2536. type The type of the agenda entry, can be
  2537. todo selected in TODO match
  2538. tagsmatch selected in tags match
  2539. diary imported from diary
  2540. deadline a deadline on given date
  2541. scheduled scheduled on given date
  2542. timestamp entry has timestamp on given date
  2543. closed entry was closed on given date
  2544. upcoming-deadline warning about deadline
  2545. past-scheduled forwarded scheduled item
  2546. block entry has date block including g. date
  2547. todo The todo keyword, if any
  2548. tags All tags including inherited ones, separated by colons
  2549. date The relevant date, like 2007-2-14
  2550. time The time, like 15:00-16:50
  2551. extra Sting with extra planning info
  2552. priority-l The priority letter if any was given
  2553. priority-n The computed numerical priority
  2554. agenda-day The day in the agenda where this is listed"
  2555. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2556. (org-make-parameter-alist parameters))
  2557. (if (> (length cmd-key) 2)
  2558. (org-tags-view nil cmd-key)
  2559. (org-agenda nil cmd-key)))
  2560. (set-buffer org-agenda-buffer-name)
  2561. (let* ((lines (org-split-string (buffer-string) "\n"))
  2562. line)
  2563. (while (setq line (pop lines))
  2564. (catch 'next
  2565. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2566. (setq org-agenda-info
  2567. (org-fix-agenda-info (text-properties-at 0 line)))
  2568. (princ
  2569. (mapconcat 'org-agenda-export-csv-mapper
  2570. '(org-category txt type todo tags date time extra
  2571. priority-letter priority agenda-day)
  2572. ","))
  2573. (princ "\n")))))
  2574. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2575. (defun org-fix-agenda-info (props)
  2576. "Make sure all properties on an agenda item have a canonical form.
  2577. This ensures the export commands can easily use it."
  2578. (let (tmp re)
  2579. (when (setq tmp (plist-get props 'tags))
  2580. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2581. (when (setq tmp (plist-get props 'date))
  2582. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2583. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2584. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2585. (setq tmp (calendar-date-string tmp)))
  2586. (setq props (plist-put props 'date tmp)))
  2587. (when (setq tmp (plist-get props 'day))
  2588. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2589. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2590. (setq tmp (calendar-date-string tmp)))
  2591. (setq props (plist-put props 'day tmp))
  2592. (setq props (plist-put props 'agenda-day tmp)))
  2593. (when (setq tmp (plist-get props 'txt))
  2594. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2595. (plist-put props 'priority-letter (match-string 1 tmp))
  2596. (setq tmp (replace-match "" t t tmp)))
  2597. (when (and (setq re (plist-get props 'org-todo-regexp))
  2598. (setq re (concat "\\`\\.*" re " ?"))
  2599. (string-match re tmp))
  2600. (plist-put props 'todo (match-string 1 tmp))
  2601. (setq tmp (replace-match "" t t tmp)))
  2602. (plist-put props 'txt tmp)))
  2603. props)
  2604. (defun org-agenda-export-csv-mapper (prop)
  2605. (let ((res (plist-get org-agenda-info prop)))
  2606. (setq res
  2607. (cond
  2608. ((not res) "")
  2609. ((stringp res) res)
  2610. (t (prin1-to-string res))))
  2611. (while (string-match "," res)
  2612. (setq res (replace-match ";" t t res)))
  2613. (org-trim res)))
  2614. ;;;###autoload
  2615. (defun org-store-agenda-views (&rest parameters)
  2616. (interactive)
  2617. (eval (list 'org-batch-store-agenda-views)))
  2618. ;;;###autoload
  2619. (defmacro org-batch-store-agenda-views (&rest parameters)
  2620. "Run all custom agenda commands that have a file argument."
  2621. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2622. (pop-up-frames nil)
  2623. (dir default-directory)
  2624. (pars (org-make-parameter-alist parameters))
  2625. cmd thiscmdkey files opts cmd-or-set)
  2626. (save-window-excursion
  2627. (while cmds
  2628. (setq cmd (pop cmds)
  2629. thiscmdkey (car cmd)
  2630. cmd-or-set (nth 2 cmd)
  2631. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2632. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2633. (if (stringp files) (setq files (list files)))
  2634. (when files
  2635. (org-eval-in-environment (append org-agenda-exporter-settings
  2636. opts pars)
  2637. (org-agenda nil thiscmdkey))
  2638. (set-buffer org-agenda-buffer-name)
  2639. (while files
  2640. (org-eval-in-environment (append org-agenda-exporter-settings
  2641. opts pars)
  2642. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2643. (and (get-buffer org-agenda-buffer-name)
  2644. (kill-buffer org-agenda-buffer-name)))))))
  2645. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2646. (defun org-agenda-mark-header-line (pos)
  2647. "Mark the line at POS as an agenda structure header."
  2648. (save-excursion
  2649. (goto-char pos)
  2650. (put-text-property (point-at-bol) (point-at-eol)
  2651. 'org-agenda-structural-header t)
  2652. (when org-agenda-title-append
  2653. (put-text-property (point-at-bol) (point-at-eol)
  2654. 'org-agenda-title-append org-agenda-title-append))))
  2655. (defvar org-mobile-creating-agendas)
  2656. (defvar org-agenda-write-buffer-name "Agenda View")
  2657. (defun org-agenda-write (file &optional open nosettings)
  2658. "Write the current buffer (an agenda view) as a file.
  2659. Depending on the extension of the file name, plain text (.txt),
  2660. HTML (.html or .htm) or Postscript (.ps) is produced.
  2661. If the extension is .ics, run icalendar export over all files used
  2662. to construct the agenda and limit the export to entries listed in the
  2663. agenda now.
  2664. With prefix argument OPEN, open the new file immediately.
  2665. If NOSETTINGS is given, do not scope the settings of
  2666. `org-agenda-exporter-settings' into the export commands. This is used when
  2667. the settings have already been scoped and we do not wish to overrule other,
  2668. higher priority settings."
  2669. (interactive "FWrite agenda to file: \nP")
  2670. (if (not (file-writable-p file))
  2671. (error "Cannot write agenda to file %s" file))
  2672. (org-let (if nosettings nil org-agenda-exporter-settings)
  2673. '(save-excursion
  2674. (save-window-excursion
  2675. (org-agenda-mark-filtered-text)
  2676. (let ((bs (copy-sequence (buffer-string))) beg)
  2677. (org-agenda-unmark-filtered-text)
  2678. (with-temp-buffer
  2679. (rename-buffer org-agenda-write-buffer-name t)
  2680. (set-buffer-modified-p nil)
  2681. (insert bs)
  2682. (org-agenda-remove-marked-text 'org-filtered)
  2683. (while (setq beg (text-property-any (point-min) (point-max)
  2684. 'org-filtered t))
  2685. (delete-region
  2686. beg (or (next-single-property-change beg 'org-filtered)
  2687. (point-max))))
  2688. (run-hooks 'org-agenda-before-write-hook)
  2689. (cond
  2690. ((org-bound-and-true-p org-mobile-creating-agendas)
  2691. (org-mobile-write-agenda-for-mobile file))
  2692. ((string-match "\\.html?\\'" file)
  2693. (require 'htmlize)
  2694. (set-buffer (htmlize-buffer (current-buffer)))
  2695. (when (and org-agenda-export-html-style
  2696. (string-match "<style>" org-agenda-export-html-style))
  2697. ;; replace <style> section with org-agenda-export-html-style
  2698. (goto-char (point-min))
  2699. (kill-region (- (search-forward "<style") 6)
  2700. (search-forward "</style>"))
  2701. (insert org-agenda-export-html-style))
  2702. (write-file file)
  2703. (kill-buffer (current-buffer))
  2704. (message "HTML written to %s" file))
  2705. ((string-match "\\.ps\\'" file)
  2706. (require 'ps-print)
  2707. (ps-print-buffer-with-faces file)
  2708. (message "Postscript written to %s" file))
  2709. ((string-match "\\.pdf\\'" file)
  2710. (require 'ps-print)
  2711. (ps-print-buffer-with-faces
  2712. (concat (file-name-sans-extension file) ".ps"))
  2713. (call-process "ps2pdf" nil nil nil
  2714. (expand-file-name
  2715. (concat (file-name-sans-extension file) ".ps"))
  2716. (expand-file-name file))
  2717. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2718. (message "PDF written to %s" file))
  2719. ((string-match "\\.ics\\'" file)
  2720. (require 'org-icalendar)
  2721. (let ((org-agenda-marker-table
  2722. (org-create-marker-find-array
  2723. (org-agenda-collect-markers)))
  2724. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2725. (org-combined-agenda-icalendar-file file))
  2726. (apply 'org-export-icalendar 'combine
  2727. (org-agenda-files nil 'ifmode))))
  2728. (t
  2729. (let ((bs (buffer-string)))
  2730. (find-file file)
  2731. (erase-buffer)
  2732. (insert bs)
  2733. (save-buffer 0)
  2734. (kill-buffer (current-buffer))
  2735. (message "Plain text written to %s" file))))))))
  2736. (set-buffer org-agenda-buffer-name))
  2737. (when open (org-open-file file)))
  2738. (defvar org-agenda-tag-filter-overlays nil)
  2739. (defvar org-agenda-cat-filter-overlays nil)
  2740. (defun org-agenda-mark-filtered-text ()
  2741. "Mark all text hidden by filtering with a text property."
  2742. (let ((inhibit-read-only t))
  2743. (mapc
  2744. (lambda (o)
  2745. (when (equal (overlay-buffer o) (current-buffer))
  2746. (put-text-property
  2747. (overlay-start o) (overlay-end o)
  2748. 'org-filtered t)))
  2749. (append org-agenda-tag-filter-overlays
  2750. org-agenda-cat-filter-overlays))))
  2751. (defun org-agenda-unmark-filtered-text ()
  2752. "Remove the filtering text property."
  2753. (let ((inhibit-read-only t))
  2754. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2755. (defun org-agenda-remove-marked-text (property &optional value)
  2756. "Delete all text marked with VALUE of PROPERTY.
  2757. VALUE defaults to t."
  2758. (let (beg)
  2759. (setq value (or value t))
  2760. (while (setq beg (text-property-any (point-min) (point-max)
  2761. property value))
  2762. (delete-region
  2763. beg (or (next-single-property-change beg 'org-filtered)
  2764. (point-max))))))
  2765. (defun org-agenda-add-entry-text ()
  2766. "Add entry text to agenda lines.
  2767. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2768. entry text following headings shown in the agenda.
  2769. Drawers will be excluded, also the line with scheduling/deadline info."
  2770. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2771. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2772. (let (m txt)
  2773. (goto-char (point-min))
  2774. (while (not (eobp))
  2775. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2776. (beginning-of-line 2)
  2777. (setq txt (org-agenda-get-some-entry-text
  2778. m org-agenda-add-entry-text-maxlines " > "))
  2779. (end-of-line 1)
  2780. (if (string-match "\\S-" txt)
  2781. (insert "\n" txt)
  2782. (or (eobp) (forward-char 1))))))))
  2783. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2784. &rest keep)
  2785. "Extract entry text from MARKER, at most N-LINES lines.
  2786. This will ignore drawers etc, just get the text.
  2787. If INDENT is given, prefix every line with this string. If KEEP is
  2788. given, it is a list of symbols, defining stuff that should not be
  2789. removed from the entry content. Currently only `planning' is allowed here."
  2790. (let (txt drawer-re kwd-time-re ind)
  2791. (save-excursion
  2792. (with-current-buffer (marker-buffer marker)
  2793. (if (not (derived-mode-p 'org-mode))
  2794. (setq txt "")
  2795. (save-excursion
  2796. (save-restriction
  2797. (widen)
  2798. (goto-char marker)
  2799. (end-of-line 1)
  2800. (setq txt (buffer-substring
  2801. (min (1+ (point)) (point-max))
  2802. (progn (outline-next-heading) (point)))
  2803. drawer-re org-drawer-regexp
  2804. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2805. ".*\n?"))
  2806. (with-temp-buffer
  2807. (insert txt)
  2808. (when org-agenda-add-entry-text-descriptive-links
  2809. (goto-char (point-min))
  2810. (while (org-activate-bracket-links (point-max))
  2811. (add-text-properties (match-beginning 0) (match-end 0)
  2812. '(face org-link))))
  2813. (goto-char (point-min))
  2814. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2815. (set-text-properties (match-beginning 0) (match-end 0)
  2816. nil))
  2817. (goto-char (point-min))
  2818. (while (re-search-forward drawer-re nil t)
  2819. (delete-region
  2820. (match-beginning 0)
  2821. (progn (re-search-forward
  2822. "^[ \t]*:END:.*\n?" nil 'move)
  2823. (point))))
  2824. (unless (member 'planning keep)
  2825. (goto-char (point-min))
  2826. (while (re-search-forward kwd-time-re nil t)
  2827. (replace-match "")))
  2828. (goto-char (point-min))
  2829. (when org-agenda-entry-text-exclude-regexps
  2830. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2831. (while (setq re (pop re-list))
  2832. (goto-char (point-min))
  2833. (while (re-search-forward re nil t)
  2834. (replace-match "")))))
  2835. (goto-char (point-max))
  2836. (skip-chars-backward " \t\n")
  2837. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2838. ;; find and remove min common indentation
  2839. (goto-char (point-min))
  2840. (untabify (point-min) (point-max))
  2841. (setq ind (org-get-indentation))
  2842. (while (not (eobp))
  2843. (unless (looking-at "[ \t]*$")
  2844. (setq ind (min ind (org-get-indentation))))
  2845. (beginning-of-line 2))
  2846. (goto-char (point-min))
  2847. (while (not (eobp))
  2848. (unless (looking-at "[ \t]*$")
  2849. (move-to-column ind)
  2850. (delete-region (point-at-bol) (point)))
  2851. (beginning-of-line 2))
  2852. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2853. (goto-char (point-min))
  2854. (when indent
  2855. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2856. (replace-match indent t t)))
  2857. (goto-char (point-min))
  2858. (while (looking-at "[ \t]*\n") (replace-match ""))
  2859. (goto-char (point-max))
  2860. (when (> (org-current-line)
  2861. n-lines)
  2862. (org-goto-line (1+ n-lines))
  2863. (backward-char 1))
  2864. (setq txt (buffer-substring (point-min) (point)))))))))
  2865. txt))
  2866. (defun org-agenda-collect-markers ()
  2867. "Collect the markers pointing to entries in the agenda buffer."
  2868. (let (m markers)
  2869. (save-excursion
  2870. (goto-char (point-min))
  2871. (while (not (eobp))
  2872. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2873. (org-get-at-bol 'org-marker)))
  2874. (push m markers))
  2875. (beginning-of-line 2)))
  2876. (nreverse markers)))
  2877. (defun org-create-marker-find-array (marker-list)
  2878. "Create a alist of files names with all marker positions in that file."
  2879. (let (f tbl m a p)
  2880. (while (setq m (pop marker-list))
  2881. (setq p (marker-position m)
  2882. f (buffer-file-name (or (buffer-base-buffer
  2883. (marker-buffer m))
  2884. (marker-buffer m))))
  2885. (if (setq a (assoc f tbl))
  2886. (push (marker-position m) (cdr a))
  2887. (push (list f p) tbl)))
  2888. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2889. tbl)))
  2890. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2891. (defun org-check-agenda-marker-table ()
  2892. "Check of the current entry is on the marker list."
  2893. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2894. a)
  2895. (and (setq a (assoc file org-agenda-marker-table))
  2896. (save-match-data
  2897. (save-excursion
  2898. (org-back-to-heading t)
  2899. (member (point) (cdr a)))))))
  2900. (defun org-check-for-org-mode ()
  2901. "Make sure current buffer is in org-mode. Error if not."
  2902. (or (derived-mode-p 'org-mode)
  2903. (error "Cannot execute org-mode agenda command on buffer in %s"
  2904. major-mode)))
  2905. (defun org-fit-agenda-window ()
  2906. "Fit the window to the buffer size."
  2907. (and (memq org-agenda-window-setup '(reorganize-frame))
  2908. (fboundp 'fit-window-to-buffer)
  2909. (org-fit-window-to-buffer
  2910. nil
  2911. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2912. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2913. ;;; Agenda prepare and finalize
  2914. (defvar org-agenda-multi nil) ; dynamically scoped
  2915. (defvar org-agenda-buffer-name "*Org Agenda*")
  2916. (defvar org-pre-agenda-window-conf nil)
  2917. (defvar org-agenda-columns-active nil)
  2918. (defvar org-agenda-name nil)
  2919. (defvar org-agenda-tag-filter nil)
  2920. (defvar org-agenda-category-filter nil)
  2921. (defvar org-agenda-top-category-filter nil)
  2922. (defvar org-agenda-tag-filter-while-redo nil)
  2923. (defvar org-agenda-tag-filter-preset nil
  2924. "A preset of the tags filter used for secondary agenda filtering.
  2925. This must be a list of strings, each string must be a single tag preceded
  2926. by \"+\" or \"-\".
  2927. This variable should not be set directly, but agenda custom commands can
  2928. bind it in the options section. The preset filter is a global property of
  2929. the entire agenda view. In a block agenda, it will not work reliably to
  2930. define a filter for one of the individual blocks. You need to set it in
  2931. the global options and expect it to be applied to the entire view.")
  2932. (defvar org-agenda-category-filter-preset nil
  2933. "A preset of the category filter used for secondary agenda filtering.
  2934. This must be a list of strings, each string must be a single category
  2935. preceded by \"+\" or \"-\".
  2936. This variable should not be set directly, but agenda custom commands can
  2937. bind it in the options section. The preset filter is a global property of
  2938. the entire agenda view. In a block agenda, it will not work reliably to
  2939. define a filter for one of the individual blocks. You need to set it in
  2940. the global options and expect it to be applied to the entire view.")
  2941. (defun org-agenda-use-sticky-p ()
  2942. "Return non-NIL if existing agenda buffer named
  2943. `org-agenda-buffer-name' exists, and should be shown instead of
  2944. generating a new one"
  2945. (and
  2946. ;; turned off by user
  2947. org-agenda-sticky
  2948. ;; For multi-agenda buffer already exists
  2949. (not org-agenda-multi)
  2950. ;; buffer found
  2951. (get-buffer org-agenda-buffer-name)
  2952. ;; C-u parameter is same as last call
  2953. (with-current-buffer (get-buffer org-agenda-buffer-name)
  2954. (and
  2955. (equal current-prefix-arg
  2956. org-agenda-last-prefix-arg)
  2957. ;; In case user turned stickiness on, while having existing
  2958. ;; Agenda buffer active, don't reuse that buffer, because it
  2959. ;; does not have org variables local
  2960. org-agenda-this-buffer-is-sticky))))
  2961. (defun org-prepare-agenda-window (abuf)
  2962. "Setup agenda buffer in the window"
  2963. (let* ((awin (get-buffer-window abuf))
  2964. wconf)
  2965. (cond
  2966. ((equal (current-buffer) abuf) nil)
  2967. (awin (select-window awin))
  2968. ((not (setq wconf (current-window-configuration))))
  2969. ((equal org-agenda-window-setup 'current-window)
  2970. (org-pop-to-buffer-same-window abuf))
  2971. ((equal org-agenda-window-setup 'other-window)
  2972. (org-switch-to-buffer-other-window abuf))
  2973. ((equal org-agenda-window-setup 'other-frame)
  2974. (switch-to-buffer-other-frame abuf))
  2975. ((equal org-agenda-window-setup 'reorganize-frame)
  2976. (delete-other-windows)
  2977. (org-switch-to-buffer-other-window abuf)))
  2978. ;; additional test in case agenda is invoked from within agenda
  2979. ;; buffer via elisp link
  2980. (unless (equal (current-buffer) abuf)
  2981. (org-pop-to-buffer-same-window abuf))
  2982. (setq org-pre-agenda-window-conf wconf)))
  2983. (defun org-prepare-agenda (&optional name)
  2984. (if (org-agenda-use-sticky-p)
  2985. (progn
  2986. ;; Popup existing buffer
  2987. (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
  2988. (message "Sticky Agenda buffer, use `r' to refresh")
  2989. (throw 'exit nil))
  2990. (setq org-todo-keywords-for-agenda nil)
  2991. (setq org-drawers-for-agenda nil)
  2992. (unless org-agenda-persistent-filter
  2993. (setq org-agenda-tag-filter nil
  2994. org-agenda-category-filter nil))
  2995. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2996. (put 'org-agenda-category-filter :preset-filter
  2997. org-agenda-category-filter-preset)
  2998. (if org-agenda-multi
  2999. (progn
  3000. (setq buffer-read-only nil)
  3001. (goto-char (point-max))
  3002. (unless (or (bobp) org-agenda-compact-blocks
  3003. (not org-agenda-block-separator))
  3004. (insert "\n"
  3005. (if (stringp org-agenda-block-separator)
  3006. org-agenda-block-separator
  3007. (make-string (window-width) org-agenda-block-separator))
  3008. "\n"))
  3009. (narrow-to-region (point) (point-max)))
  3010. (setq org-done-keywords-for-agenda nil)
  3011. ;; Setting any org variables that are in org-agenda-local-vars
  3012. ;; list need to be done after the prepare call
  3013. (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
  3014. (setq buffer-read-only nil)
  3015. (org-agenda-reset-markers)
  3016. (let ((inhibit-read-only t)) (erase-buffer))
  3017. (org-agenda-mode)
  3018. (setq org-agenda-buffer (current-buffer))
  3019. (setq org-agenda-contributing-files nil)
  3020. (setq org-agenda-columns-active nil)
  3021. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  3022. (setq org-todo-keywords-for-agenda
  3023. (org-uniquify org-todo-keywords-for-agenda))
  3024. (setq org-done-keywords-for-agenda
  3025. (org-uniquify org-done-keywords-for-agenda))
  3026. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3027. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3028. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3029. (and name (not org-agenda-name)
  3030. (org-set-local 'org-agenda-name name)))
  3031. (setq buffer-read-only nil)))
  3032. (defun org-finalize-agenda ()
  3033. "Finishing touch for the agenda buffer, called just before displaying it."
  3034. (unless org-agenda-multi
  3035. (save-excursion
  3036. (let ((inhibit-read-only t))
  3037. (goto-char (point-min))
  3038. (while (org-activate-bracket-links (point-max))
  3039. (add-text-properties (match-beginning 0) (match-end 0)
  3040. '(face org-link)))
  3041. (org-agenda-align-tags)
  3042. (unless org-agenda-with-colors
  3043. (remove-text-properties (point-min) (point-max) '(face nil))))
  3044. (if (and (boundp 'org-agenda-overriding-columns-format)
  3045. org-agenda-overriding-columns-format)
  3046. (org-set-local 'org-agenda-overriding-columns-format
  3047. org-agenda-overriding-columns-format))
  3048. (if (and (boundp 'org-agenda-view-columns-initially)
  3049. org-agenda-view-columns-initially)
  3050. (org-agenda-columns))
  3051. (when org-agenda-fontify-priorities
  3052. (org-agenda-fontify-priorities))
  3053. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3054. (org-agenda-dim-blocked-tasks))
  3055. (org-agenda-mark-clocking-task)
  3056. (when org-agenda-entry-text-mode
  3057. (org-agenda-entry-text-hide)
  3058. (org-agenda-entry-text-show))
  3059. (if (functionp 'org-habit-insert-consistency-graphs)
  3060. (org-habit-insert-consistency-graphs))
  3061. (run-hooks 'org-finalize-agenda-hook)
  3062. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3063. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3064. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3065. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3066. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3067. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3068. )))
  3069. (defun org-agenda-mark-clocking-task ()
  3070. "Mark the current clock entry in the agenda if it is present."
  3071. (mapc (lambda (o)
  3072. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3073. (delete-overlay o)))
  3074. (overlays-in (point-min) (point-max)))
  3075. (when (marker-buffer org-clock-hd-marker)
  3076. (save-excursion
  3077. (goto-char (point-min))
  3078. (let (s ov)
  3079. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3080. (goto-char s)
  3081. (when (equal (org-get-at-bol 'org-hd-marker)
  3082. org-clock-hd-marker)
  3083. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3084. (overlay-put ov 'type 'org-agenda-clocking)
  3085. (overlay-put ov 'face 'org-agenda-clocking)
  3086. (overlay-put ov 'help-echo
  3087. "The clock is running in this item")))))))
  3088. (defun org-agenda-fontify-priorities ()
  3089. "Make highest priority lines bold, and lowest italic."
  3090. (interactive)
  3091. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3092. (delete-overlay o)))
  3093. (overlays-in (point-min) (point-max)))
  3094. (save-excursion
  3095. (let ((inhibit-read-only t)
  3096. b e p ov h l)
  3097. (goto-char (point-min))
  3098. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3099. (setq h (or (get-char-property (point) 'org-highest-priority)
  3100. org-highest-priority)
  3101. l (or (get-char-property (point) 'org-lowest-priority)
  3102. org-lowest-priority)
  3103. p (string-to-char (match-string 1))
  3104. b (match-beginning 0)
  3105. e (if (eq org-agenda-fontify-priorities 'cookies)
  3106. (match-end 0)
  3107. (point-at-eol))
  3108. ov (make-overlay b e))
  3109. (overlay-put
  3110. ov 'face
  3111. (cond ((org-face-from-face-or-color
  3112. 'priority nil
  3113. (cdr (assoc p org-priority-faces))))
  3114. ((and (listp org-agenda-fontify-priorities)
  3115. (org-face-from-face-or-color
  3116. 'priority nil
  3117. (cdr (assoc p org-agenda-fontify-priorities)))))
  3118. ((equal p l) 'italic)
  3119. ((equal p h) 'bold)))
  3120. (overlay-put ov 'org-type 'org-priority)))))
  3121. (defun org-agenda-dim-blocked-tasks ()
  3122. "Dim currently blocked TODO's in the agenda display."
  3123. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3124. (delete-overlay o)))
  3125. (overlays-in (point-min) (point-max)))
  3126. (save-excursion
  3127. (let ((inhibit-read-only t)
  3128. (org-depend-tag-blocked nil)
  3129. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3130. org-blocked-by-checkboxes
  3131. invis1 b e p ov h l)
  3132. (goto-char (point-min))
  3133. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3134. (and pos (goto-char (1+ pos))))
  3135. (setq org-blocked-by-checkboxes nil invis1 invis)
  3136. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3137. (when (and marker
  3138. (with-current-buffer (marker-buffer marker)
  3139. (save-excursion (goto-char marker)
  3140. (org-entry-blocked-p))))
  3141. (if org-blocked-by-checkboxes (setq invis1 nil))
  3142. (setq b (if invis1
  3143. (max (point-min) (1- (point-at-bol)))
  3144. (point-at-bol))
  3145. e (point-at-eol)
  3146. ov (make-overlay b e))
  3147. (if invis1
  3148. (overlay-put ov 'invisible t)
  3149. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3150. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3151. (defvar org-agenda-skip-function nil
  3152. "Function to be called at each match during agenda construction.
  3153. If this function returns nil, the current match should not be skipped.
  3154. Otherwise, the function must return a position from where the search
  3155. should be continued.
  3156. This may also be a Lisp form, it will be evaluated.
  3157. Never set this variable using `setq' or so, because then it will apply
  3158. to all future agenda commands. If you do want a global skipping condition,
  3159. use the option `org-agenda-skip-function-global' instead.
  3160. The correct usage for `org-agenda-skip-function' is to bind it with
  3161. `let' to scope it dynamically into the agenda-constructing command.
  3162. A good way to set it is through options in `org-agenda-custom-commands'.")
  3163. (defun org-agenda-skip ()
  3164. "Throw to `:skip' in places that should be skipped.
  3165. Also moves point to the end of the skipped region, so that search can
  3166. continue from there."
  3167. (let ((p (point-at-bol)) to)
  3168. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3169. (get-text-property p :org-archived)
  3170. (org-end-of-subtree t)
  3171. (throw :skip t))
  3172. (and org-agenda-skip-comment-trees
  3173. (get-text-property p :org-comment)
  3174. (org-end-of-subtree t)
  3175. (throw :skip t))
  3176. (if (equal (char-after p) ?#) (throw :skip t))
  3177. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3178. (org-agenda-skip-eval org-agenda-skip-function)))
  3179. (goto-char to)
  3180. (throw :skip t))))
  3181. (defun org-agenda-skip-eval (form)
  3182. "If FORM is a function or a list, call (or eval) is and return result.
  3183. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3184. and match data are returned to the previous state no matter what these
  3185. functions do."
  3186. (let (fp)
  3187. (and form
  3188. (or (setq fp (functionp form))
  3189. (consp form))
  3190. (save-excursion
  3191. (save-match-data
  3192. (if fp
  3193. (funcall form)
  3194. (eval form)))))))
  3195. (defvar org-agenda-markers nil
  3196. "List of all currently active markers created by `org-agenda'.")
  3197. (defvar org-agenda-last-marker-time (org-float-time)
  3198. "Creation time of the last agenda marker.")
  3199. (defun org-agenda-new-marker (&optional pos)
  3200. "Return a new agenda marker.
  3201. Org-mode keeps a list of these markers and resets them when they are
  3202. no longer in use."
  3203. (let ((m (copy-marker (or pos (point)))))
  3204. (setq org-agenda-last-marker-time (org-float-time))
  3205. (if org-agenda-buffer
  3206. (with-current-buffer org-agenda-buffer
  3207. (push m org-agenda-markers))
  3208. (push m org-agenda-markers))
  3209. m))
  3210. (defun org-agenda-reset-markers ()
  3211. "Reset markers created by `org-agenda'."
  3212. (while org-agenda-markers
  3213. (move-marker (pop org-agenda-markers) nil)))
  3214. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3215. "Save relative positions of markers in region.
  3216. This check for agenda markers in all agenda buffers currently active."
  3217. (dolist (buf (buffer-list))
  3218. (with-current-buffer buf
  3219. (when (eq major-mode 'org-agenda-mode)
  3220. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3221. org-agenda-markers)))))
  3222. ;;; Entry text mode
  3223. (defun org-agenda-entry-text-show-here ()
  3224. "Add some text from the entry as context to the current line."
  3225. (let (m txt o)
  3226. (setq m (org-get-at-bol 'org-hd-marker))
  3227. (unless (marker-buffer m)
  3228. (error "No marker points to an entry here"))
  3229. (setq txt (concat "\n" (org-no-properties
  3230. (org-agenda-get-some-entry-text
  3231. m org-agenda-entry-text-maxlines " > "))))
  3232. (when (string-match "\\S-" txt)
  3233. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3234. (overlay-put o 'evaporate t)
  3235. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3236. (overlay-put o 'after-string txt))))
  3237. (defun org-agenda-entry-text-show ()
  3238. "Add entry context for all agenda lines."
  3239. (interactive)
  3240. (save-excursion
  3241. (goto-char (point-max))
  3242. (beginning-of-line 1)
  3243. (while (not (bobp))
  3244. (when (org-get-at-bol 'org-hd-marker)
  3245. (org-agenda-entry-text-show-here))
  3246. (beginning-of-line 0))))
  3247. (defun org-agenda-entry-text-hide ()
  3248. "Remove any shown entry context."
  3249. (delq nil
  3250. (mapcar (lambda (o)
  3251. (if (eq (overlay-get o 'org-overlay-type)
  3252. 'agenda-entry-content)
  3253. (progn (delete-overlay o) t)))
  3254. (overlays-in (point-min) (point-max)))))
  3255. (defun org-agenda-get-day-face (date)
  3256. "Return the face DATE should be displayed with."
  3257. (or (and (functionp org-agenda-day-face-function)
  3258. (funcall org-agenda-day-face-function date))
  3259. (cond ((org-agenda-todayp date)
  3260. 'org-agenda-date-today)
  3261. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3262. 'org-agenda-date-weekend)
  3263. (t 'org-agenda-date))))
  3264. ;;; Agenda timeline
  3265. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3266. (defun org-timeline (&optional dotodo)
  3267. "Show a time-sorted view of the entries in the current org file.
  3268. Only entries with a time stamp of today or later will be listed. With
  3269. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3270. under the current date.
  3271. If the buffer contains an active region, only check the region for
  3272. dates."
  3273. (interactive "P")
  3274. (let* ((dopast t)
  3275. (org-agenda-show-log-scoped org-agenda-show-log)
  3276. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3277. (current-buffer))))
  3278. (date (calendar-current-date))
  3279. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3280. (end (if (org-region-active-p) (region-end) (point-max)))
  3281. (day-numbers (org-get-all-dates
  3282. beg end 'no-ranges
  3283. t org-agenda-show-log-scoped ; always include today
  3284. org-timeline-show-empty-dates))
  3285. (org-deadline-warning-days 0)
  3286. (org-agenda-only-exact-dates t)
  3287. (today (org-today))
  3288. (past t)
  3289. args
  3290. s e rtn d emptyp)
  3291. (setq org-agenda-redo-command
  3292. (list 'progn
  3293. (list 'org-switch-to-buffer-other-window (current-buffer))
  3294. (list 'org-timeline (list 'quote dotodo))))
  3295. (if (not dopast)
  3296. ;; Remove past dates from the list of dates.
  3297. (setq day-numbers (delq nil (mapcar (lambda(x)
  3298. (if (>= x today) x nil))
  3299. day-numbers))))
  3300. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3301. (org-compile-prefix-format 'timeline)
  3302. (org-set-sorting-strategy 'timeline)
  3303. (if org-agenda-show-log-scoped (push :closed args))
  3304. (push :timestamp args)
  3305. (push :deadline args)
  3306. (push :scheduled args)
  3307. (push :sexp args)
  3308. (if dotodo (push :todo args))
  3309. (insert "Timeline of file " entry "\n")
  3310. (add-text-properties (point-min) (point)
  3311. (list 'face 'org-agenda-structure))
  3312. (org-agenda-mark-header-line (point-min))
  3313. (while (setq d (pop day-numbers))
  3314. (if (and (listp d) (eq (car d) :omitted))
  3315. (progn
  3316. (setq s (point))
  3317. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3318. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3319. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3320. (if (and (>= d today)
  3321. dopast
  3322. past)
  3323. (progn
  3324. (setq past nil)
  3325. (insert (make-string 79 ?-) "\n")))
  3326. (setq date (calendar-gregorian-from-absolute d))
  3327. (setq s (point))
  3328. (setq rtn (and (not emptyp)
  3329. (apply 'org-agenda-get-day-entries entry
  3330. date args)))
  3331. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3332. (progn
  3333. (insert
  3334. (if (stringp org-agenda-format-date)
  3335. (format-time-string org-agenda-format-date
  3336. (org-time-from-absolute date))
  3337. (funcall org-agenda-format-date date))
  3338. "\n")
  3339. (put-text-property s (1- (point)) 'face
  3340. (org-agenda-get-day-face date))
  3341. (put-text-property s (1- (point)) 'org-date-line t)
  3342. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3343. (if (equal d today)
  3344. (put-text-property s (1- (point)) 'org-today t))
  3345. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3346. (put-text-property s (1- (point)) 'day d)))))
  3347. (goto-char (point-min))
  3348. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3349. (point-min)))
  3350. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3351. (org-finalize-agenda)
  3352. (setq buffer-read-only t)))
  3353. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3354. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3355. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3356. not every single day in the range. If FORCE-TODAY is non-nil, make
  3357. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3358. inactive time stamps (those in square brackets) are included.
  3359. When EMPTY is non-nil, also include days without any entries."
  3360. (let ((re (concat
  3361. (if pre-re pre-re "")
  3362. (if inactive org-ts-regexp-both org-ts-regexp)))
  3363. dates dates1 date day day1 day2 ts1 ts2 pos)
  3364. (if force-today
  3365. (setq dates (list (org-today))))
  3366. (save-excursion
  3367. (goto-char beg)
  3368. (while (re-search-forward re end t)
  3369. (setq day (time-to-days (org-time-string-to-time
  3370. (substring (match-string 1) 0 10)
  3371. (current-buffer) (match-beginning 0))))
  3372. (or (memq day dates) (push day dates)))
  3373. (unless no-ranges
  3374. (goto-char beg)
  3375. (while (re-search-forward org-tr-regexp end t)
  3376. (setq pos (match-beginning 0))
  3377. (setq ts1 (substring (match-string 1) 0 10)
  3378. ts2 (substring (match-string 2) 0 10)
  3379. day1 (time-to-days (org-time-string-to-time
  3380. ts1 (current-buffer) pos))
  3381. day2 (time-to-days (org-time-string-to-time
  3382. ts2 (current-buffer) pos)))
  3383. (while (< (setq day1 (1+ day1)) day2)
  3384. (or (memq day1 dates) (push day1 dates)))))
  3385. (setq dates (sort dates '<))
  3386. (when empty
  3387. (while (setq day (pop dates))
  3388. (setq day2 (car dates))
  3389. (push day dates1)
  3390. (when (and day2 empty)
  3391. (if (or (eq empty t)
  3392. (and (numberp empty) (<= (- day2 day) empty)))
  3393. (while (< (setq day (1+ day)) day2)
  3394. (push (list day) dates1))
  3395. (push (cons :omitted (- day2 day)) dates1))))
  3396. (setq dates (nreverse dates1)))
  3397. dates)))
  3398. ;;; Agenda Daily/Weekly
  3399. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3400. "Start day for the agenda view.
  3401. Custom commands can set this variable in the options section.")
  3402. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3403. (defvar org-agenda-current-span nil
  3404. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3405. (defvar org-arg-loc nil) ; local variable
  3406. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3407. "List of types searched for when creating the daily/weekly agenda.
  3408. This variable is a list of symbols that controls the types of
  3409. items that appear in the daily/weekly agenda. Allowed symbols in this
  3410. list are are
  3411. :timestamp List items containing a date stamp or date range matching
  3412. the selected date. This includes sexp entries in
  3413. angular brackets.
  3414. :sexp List entries resulting from plain diary-like sexps.
  3415. :deadline List deadline due on that date. When the date is today,
  3416. also list any deadlines past due, or due within
  3417. `org-deadline-warning-days'. `:deadline' must appear before
  3418. `:scheduled' if the setting of
  3419. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3420. any effect.
  3421. :scheduled List all items which are scheduled for the given date.
  3422. The diary for *today* also contains items which were
  3423. scheduled earlier and are not yet marked DONE.
  3424. By default, all four types are turned on.
  3425. Never set this variable globally using `setq', because then it
  3426. will apply to all future agenda commands. Instead, bind it with
  3427. `let' to scope it dynamically into the agenda-constructing
  3428. command. A good way to set it is through options in
  3429. `org-agenda-custom-commands'. For a more flexible (though
  3430. somewhat less efficient) way of determining what is included in
  3431. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3432. ;;;###autoload
  3433. (defun org-agenda-list (&optional arg start-day span)
  3434. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3435. The view will be for the current day or week, but from the overview buffer
  3436. you will be able to go to other days/weeks.
  3437. With a numeric prefix argument in an interactive call, the agenda will
  3438. span ARG days. Lisp programs should instead specify SPAN to change
  3439. the number of days. SPAN defaults to `org-agenda-span'.
  3440. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3441. given in `org-agenda-start-on-weekday'."
  3442. (interactive "P")
  3443. (if (and (integerp arg) (> arg 0))
  3444. (setq span arg arg nil))
  3445. (org-prepare-agenda "Day/Week")
  3446. (setq start-day (or start-day org-agenda-start-day))
  3447. (if org-agenda-overriding-arguments
  3448. (setq arg (car org-agenda-overriding-arguments)
  3449. start-day (nth 1 org-agenda-overriding-arguments)
  3450. span (nth 2 org-agenda-overriding-arguments)))
  3451. (if (stringp start-day)
  3452. ;; Convert to an absolute day number
  3453. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3454. (setq org-agenda-last-arguments (list arg start-day span))
  3455. (org-compile-prefix-format 'agenda)
  3456. (org-set-sorting-strategy 'agenda)
  3457. (let* ((span (org-agenda-ndays-to-span
  3458. (or span org-agenda-ndays org-agenda-span)))
  3459. (today (org-today))
  3460. (sd (or start-day today))
  3461. (ndays (org-agenda-span-to-ndays span sd))
  3462. (org-agenda-start-on-weekday
  3463. (if (eq ndays 7)
  3464. org-agenda-start-on-weekday))
  3465. (thefiles (org-agenda-files nil 'ifmode))
  3466. (files thefiles)
  3467. (start (if (or (null org-agenda-start-on-weekday)
  3468. (< ndays 7))
  3469. sd
  3470. (let* ((nt (calendar-day-of-week
  3471. (calendar-gregorian-from-absolute sd)))
  3472. (n1 org-agenda-start-on-weekday)
  3473. (d (- nt n1)))
  3474. (- sd (+ (if (< d 0) 7 0) d)))))
  3475. (day-numbers (list start))
  3476. (day-cnt 0)
  3477. (inhibit-redisplay (not debug-on-error))
  3478. (org-agenda-show-log-scoped org-agenda-show-log)
  3479. s e rtn rtnall file date d start-pos end-pos todayp
  3480. clocktable-start clocktable-end filter)
  3481. (setq org-agenda-redo-command
  3482. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3483. (dotimes (n (1- ndays))
  3484. (push (1+ (car day-numbers)) day-numbers))
  3485. (setq day-numbers (nreverse day-numbers))
  3486. (setq clocktable-start (car day-numbers)
  3487. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3488. (org-set-local 'org-starting-day (car day-numbers))
  3489. (org-set-local 'org-arg-loc arg)
  3490. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3491. (unless org-agenda-compact-blocks
  3492. (let* ((d1 (car day-numbers))
  3493. (d2 (org-last day-numbers))
  3494. (w1 (org-days-to-iso-week d1))
  3495. (w2 (org-days-to-iso-week d2)))
  3496. (setq s (point))
  3497. (if org-agenda-overriding-header
  3498. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3499. nil 'face 'org-agenda-structure) "\n")
  3500. (insert (org-agenda-span-name span)
  3501. "-agenda"
  3502. (if (< (- d2 d1) 350)
  3503. (if (= w1 w2)
  3504. (format " (W%02d)" w1)
  3505. (format " (W%02d-W%02d)" w1 w2))
  3506. "")
  3507. ":\n")))
  3508. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3509. 'org-date-line t))
  3510. (org-agenda-mark-header-line s))
  3511. (while (setq d (pop day-numbers))
  3512. (setq date (calendar-gregorian-from-absolute d)
  3513. s (point))
  3514. (if (or (setq todayp (= d today))
  3515. (and (not start-pos) (= d sd)))
  3516. (setq start-pos (point))
  3517. (if (and start-pos (not end-pos))
  3518. (setq end-pos (point))))
  3519. (setq files thefiles
  3520. rtnall nil)
  3521. (while (setq file (pop files))
  3522. (catch 'nextfile
  3523. (org-check-agenda-file file)
  3524. (let ((org-agenda-entry-types org-agenda-entry-types))
  3525. (unless org-agenda-include-deadlines
  3526. (setq org-agenda-entry-types
  3527. (delq :deadline org-agenda-entry-types)))
  3528. (cond
  3529. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3530. (setq rtn (org-agenda-get-day-entries
  3531. file date :closed)))
  3532. (org-agenda-show-log-scoped
  3533. (setq rtn (apply 'org-agenda-get-day-entries
  3534. file date
  3535. (append '(:closed) org-agenda-entry-types))))
  3536. (t
  3537. (setq rtn (apply 'org-agenda-get-day-entries
  3538. file date
  3539. org-agenda-entry-types)))))
  3540. (setq rtnall (append rtnall rtn)))) ;; all entries
  3541. (if org-agenda-include-diary
  3542. (let ((org-agenda-search-headline-for-time t))
  3543. (require 'diary-lib)
  3544. (setq rtn (org-get-entries-from-diary date))
  3545. (setq rtnall (append rtnall rtn))))
  3546. (if (or rtnall org-agenda-show-all-dates)
  3547. (progn
  3548. (setq day-cnt (1+ day-cnt))
  3549. (insert
  3550. (if (stringp org-agenda-format-date)
  3551. (format-time-string org-agenda-format-date
  3552. (org-time-from-absolute date))
  3553. (funcall org-agenda-format-date date))
  3554. "\n")
  3555. (put-text-property s (1- (point)) 'face
  3556. (org-agenda-get-day-face date))
  3557. (put-text-property s (1- (point)) 'org-date-line t)
  3558. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3559. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3560. (when todayp
  3561. (put-text-property s (1- (point)) 'org-today t))
  3562. (setq rtnall
  3563. (append rtnall
  3564. (org-agenda-add-time-grid-maybe rtnall ndays todayp)))
  3565. (if rtnall (insert ;; all entries
  3566. (org-finalize-agenda-entries rtnall)
  3567. "\n"))
  3568. (put-text-property s (1- (point)) 'day d)
  3569. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3570. (when (and org-agenda-clockreport-mode clocktable-start)
  3571. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3572. ;; the above line is to ensure the restricted range!
  3573. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3574. tbl)
  3575. (setq p (org-plist-delete p :block))
  3576. (setq p (plist-put p :tstart clocktable-start))
  3577. (setq p (plist-put p :tend clocktable-end))
  3578. (setq p (plist-put p :scope 'agenda))
  3579. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3580. (setq filter (or org-agenda-tag-filter-while-redo
  3581. (get 'org-agenda-tag-filter :preset-filter))))
  3582. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3583. (if (string-match "[<>=]" x)
  3584. ""
  3585. x))
  3586. filter ""))))
  3587. (setq tbl (apply 'org-get-clocktable p))
  3588. (insert tbl)))
  3589. (goto-char (point-min))
  3590. (or org-agenda-multi (org-fit-agenda-window))
  3591. (unless (and (pos-visible-in-window-p (point-min))
  3592. (pos-visible-in-window-p (point-max)))
  3593. (goto-char (1- (point-max)))
  3594. (recenter -1)
  3595. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3596. (progn
  3597. (goto-char (or start-pos 1))
  3598. (recenter 1))))
  3599. (goto-char (or start-pos 1))
  3600. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3601. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3602. (org-agenda-show-clocking-issues))
  3603. (org-finalize-agenda)
  3604. (setq buffer-read-only t)
  3605. (message "")))
  3606. (defun org-agenda-ndays-to-span (n)
  3607. "Return a span symbol for a span of N days, or N if none matches."
  3608. (cond ((symbolp n) n)
  3609. ((= n 1) 'day)
  3610. ((= n 7) 'week)
  3611. (t n)))
  3612. (defun org-agenda-span-to-ndays (span start-day)
  3613. "Return ndays from SPAN starting at START-DAY."
  3614. (cond ((numberp span) span)
  3615. ((eq span 'day) 1)
  3616. ((eq span 'week) 7)
  3617. ((eq span 'month)
  3618. (let ((date (calendar-gregorian-from-absolute start-day)))
  3619. (calendar-last-day-of-month (car date) (caddr date))))
  3620. ((eq span 'year)
  3621. (let ((date (calendar-gregorian-from-absolute start-day)))
  3622. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3623. (defun org-agenda-span-name (span)
  3624. "Return a SPAN name."
  3625. (if (null span)
  3626. ""
  3627. (if (symbolp span)
  3628. (capitalize (symbol-name span))
  3629. (format "%d days" span))))
  3630. ;;; Agenda word search
  3631. (defvar org-agenda-search-history nil)
  3632. (defvar org-todo-only nil)
  3633. (defvar org-search-syntax-table nil
  3634. "Special syntax table for org-mode search.
  3635. In this table, we have single quotes not as word constituents, to
  3636. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3637. (defun org-search-syntax-table ()
  3638. (unless org-search-syntax-table
  3639. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3640. (modify-syntax-entry ?' "." org-search-syntax-table)
  3641. (modify-syntax-entry ?` "." org-search-syntax-table))
  3642. org-search-syntax-table)
  3643. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3644. ;;;###autoload
  3645. (defun org-search-view (&optional todo-only string edit-at)
  3646. "Show all entries that contain a phrase or words or regular expressions.
  3647. With optional prefix argument TODO-ONLY, only consider entries that are
  3648. TODO entries. The argument STRING can be used to pass a default search
  3649. string into this function. If EDIT-AT is non-nil, it means that the
  3650. user should get a chance to edit this string, with cursor at position
  3651. EDIT-AT.
  3652. The search string can be viewed either as a phrase that should be found as
  3653. is, or it can be broken into a number of snippets, each of which must match
  3654. in a Boolean way to select an entry. The default depends on the variable
  3655. `org-agenda-search-view-always-boolean'.
  3656. Even if this is turned off (the default) you can always switch to
  3657. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3658. The default is a direct search of the whole phrase, where each space in
  3659. the search string can expand to an arbitrary amount of whitespace,
  3660. including newlines.
  3661. If using a Boolean search, the search string is split on whitespace and
  3662. each snippet is searched separately, with logical AND to select an entry.
  3663. Words prefixed with a minus must *not* occur in the entry. Words without
  3664. a prefix or prefixed with a plus must occur in the entry. Matching is
  3665. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3666. match whole words, not parts of a word) if
  3667. `org-agenda-search-view-force-full-words' is set (default is nil).
  3668. Boolean search snippets enclosed by curly braces are interpreted as
  3669. regular expressions that must or (when preceded with \"-\") must not
  3670. match in the entry. Snippets enclosed into double quotes will be taken
  3671. as a whole, to include whitespace.
  3672. - If the search string starts with an asterisk, search only in headlines.
  3673. - If (possibly after the leading star) the search string starts with an
  3674. exclamation mark, this also means to look at TODO entries only, an effect
  3675. that can also be achieved with a prefix argument.
  3676. - If (possibly after star and exclamation mark) the search string starts
  3677. with a colon, this will mean that the (non-regexp) snippets of the
  3678. Boolean search must match as full words.
  3679. This command searches the agenda files, and in addition the files listed
  3680. in `org-agenda-text-search-extra-files'."
  3681. (interactive "P")
  3682. (org-prepare-agenda "SEARCH")
  3683. (org-compile-prefix-format 'search)
  3684. (org-set-sorting-strategy 'search)
  3685. (let* ((props (list 'face nil
  3686. 'done-face 'org-agenda-done
  3687. 'org-not-done-regexp org-not-done-regexp
  3688. 'org-todo-regexp org-todo-regexp
  3689. 'org-complex-heading-regexp org-complex-heading-regexp
  3690. 'mouse-face 'highlight
  3691. 'help-echo (format "mouse-2 or RET jump to location")))
  3692. (full-words org-agenda-search-view-force-full-words)
  3693. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3694. regexp rtn rtnall files file pos
  3695. marker category org-category-pos tags c neg re boolean
  3696. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3697. (unless (and (not edit-at)
  3698. (stringp string)
  3699. (string-match "\\S-" string))
  3700. (setq string (read-string
  3701. (if org-agenda-search-view-always-boolean
  3702. "[+-]Word/{Regexp} ...: "
  3703. "Phrase, or [+-]Word/{Regexp} ...: ")
  3704. (cond
  3705. ((integerp edit-at) (cons string edit-at))
  3706. (edit-at string))
  3707. 'org-agenda-search-history)))
  3708. (org-set-local 'org-todo-only todo-only)
  3709. (setq org-agenda-redo-command
  3710. (list 'org-search-view (if todo-only t nil) string
  3711. '(if current-prefix-arg 1 nil)))
  3712. (setq org-agenda-query-string string)
  3713. (if (equal (string-to-char string) ?*)
  3714. (setq hdl-only t
  3715. words (substring string 1))
  3716. (setq words string))
  3717. (when (equal (string-to-char words) ?!)
  3718. (setq todo-only t
  3719. words (substring words 1)))
  3720. (when (equal (string-to-char words) ?:)
  3721. (setq full-words t
  3722. words (substring words 1)))
  3723. (if (or org-agenda-search-view-always-boolean
  3724. (member (string-to-char words) '(?- ?+ ?\{)))
  3725. (setq boolean t))
  3726. (setq words (org-split-string words))
  3727. (let (www w)
  3728. (while (setq w (pop words))
  3729. (while (and (string-match "\\\\\\'" w) words)
  3730. (setq w (concat (substring w 0 -1) " " (pop words))))
  3731. (push w www))
  3732. (setq words (nreverse www) www nil)
  3733. (while (setq w (pop words))
  3734. (when (and (string-match "\\`[-+]?{" w)
  3735. (not (string-match "}\\'" w)))
  3736. (while (and words (not (string-match "}\\'" (car words))))
  3737. (setq w (concat w " " (pop words))))
  3738. (setq w (concat w " " (pop words))))
  3739. (push w www))
  3740. (setq words (nreverse www)))
  3741. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3742. (when boolean
  3743. (let (wds w)
  3744. (while (setq w (pop words))
  3745. (if (or (equal (substring w 0 1) "\"")
  3746. (and (> (length w) 1)
  3747. (member (substring w 0 1) '("+" "-"))
  3748. (equal (substring w 1 2) "\"")))
  3749. (while (and words (not (equal (substring w -1) "\"")))
  3750. (setq w (concat w " " (pop words)))))
  3751. (and (string-match "\\`\\([-+]?\\)\"" w)
  3752. (setq w (replace-match "\\1" nil nil w)))
  3753. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3754. (push w wds))
  3755. (setq words (nreverse wds))))
  3756. (if boolean
  3757. (mapc (lambda (w)
  3758. (setq c (string-to-char w))
  3759. (if (equal c ?-)
  3760. (setq neg t w (substring w 1))
  3761. (if (equal c ?+)
  3762. (setq neg nil w (substring w 1))
  3763. (setq neg nil)))
  3764. (if (string-match "\\`{.*}\\'" w)
  3765. (setq re (substring w 1 -1))
  3766. (if full-words
  3767. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3768. (setq re (regexp-quote (downcase w)))))
  3769. (if neg (push re regexps-) (push re regexps+)))
  3770. words)
  3771. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3772. regexps+))
  3773. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3774. (if (not regexps+)
  3775. (setq regexp org-outline-regexp-bol)
  3776. (setq regexp (pop regexps+))
  3777. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3778. regexp))))
  3779. (setq files (org-agenda-files nil 'ifmode))
  3780. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3781. (pop org-agenda-text-search-extra-files)
  3782. (setq files (org-add-archive-files files)))
  3783. (setq files (append files org-agenda-text-search-extra-files)
  3784. rtnall nil)
  3785. (while (setq file (pop files))
  3786. (setq ee nil)
  3787. (catch 'nextfile
  3788. (org-check-agenda-file file)
  3789. (setq buffer (if (file-exists-p file)
  3790. (org-get-agenda-file-buffer file)
  3791. (error "No such file %s" file)))
  3792. (if (not buffer)
  3793. ;; If file does not exist, make sure an error message is sent
  3794. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3795. file))))
  3796. (with-current-buffer buffer
  3797. (with-syntax-table (org-search-syntax-table)
  3798. (unless (derived-mode-p 'org-mode)
  3799. (error "Agenda file %s is not in `org-mode'" file))
  3800. (let ((case-fold-search t))
  3801. (save-excursion
  3802. (save-restriction
  3803. (if org-agenda-restrict
  3804. (narrow-to-region org-agenda-restrict-begin
  3805. org-agenda-restrict-end)
  3806. (widen))
  3807. (goto-char (point-min))
  3808. (unless (or (org-at-heading-p)
  3809. (outline-next-heading))
  3810. (throw 'nextfile t))
  3811. (goto-char (max (point-min) (1- (point))))
  3812. (while (re-search-forward regexp nil t)
  3813. (org-back-to-heading t)
  3814. (skip-chars-forward "* ")
  3815. (setq beg (point-at-bol)
  3816. beg1 (point)
  3817. end (progn (outline-next-heading) (point)))
  3818. (catch :skip
  3819. (goto-char beg)
  3820. (org-agenda-skip)
  3821. (setq str (buffer-substring-no-properties
  3822. (point-at-bol)
  3823. (if hdl-only (point-at-eol) end)))
  3824. (mapc (lambda (wr) (when (string-match wr str)
  3825. (goto-char (1- end))
  3826. (throw :skip t)))
  3827. regexps-)
  3828. (mapc (lambda (wr) (unless (string-match wr str)
  3829. (goto-char (1- end))
  3830. (throw :skip t)))
  3831. (if todo-only
  3832. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3833. regexps+)
  3834. regexps+))
  3835. (goto-char beg)
  3836. (setq marker (org-agenda-new-marker (point))
  3837. category (org-get-category)
  3838. org-category-pos (get-text-property (point) 'org-category-position)
  3839. tags (org-get-tags-at (point))
  3840. txt (org-agenda-format-item
  3841. ""
  3842. (buffer-substring-no-properties
  3843. beg1 (point-at-eol))
  3844. category tags))
  3845. (org-add-props txt props
  3846. 'org-marker marker 'org-hd-marker marker
  3847. 'org-todo-regexp org-todo-regexp
  3848. 'org-complex-heading-regexp org-complex-heading-regexp
  3849. 'priority 1000 'org-category category
  3850. 'org-category-position org-category-pos
  3851. 'type "search")
  3852. (push txt ee)
  3853. (goto-char (1- end))))))))))
  3854. (setq rtn (nreverse ee))
  3855. (setq rtnall (append rtnall rtn)))
  3856. (if org-agenda-overriding-header
  3857. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3858. nil 'face 'org-agenda-structure) "\n")
  3859. (insert "Search words: ")
  3860. (add-text-properties (point-min) (1- (point))
  3861. (list 'face 'org-agenda-structure))
  3862. (setq pos (point))
  3863. (insert string "\n")
  3864. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3865. (setq pos (point))
  3866. (unless org-agenda-multi
  3867. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3868. (add-text-properties pos (1- (point))
  3869. (list 'face 'org-agenda-structure))))
  3870. (org-agenda-mark-header-line (point-min))
  3871. (when rtnall
  3872. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3873. (goto-char (point-min))
  3874. (or org-agenda-multi (org-fit-agenda-window))
  3875. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3876. (org-finalize-agenda)
  3877. (setq buffer-read-only t)))
  3878. ;;; Agenda TODO list
  3879. (defvar org-select-this-todo-keyword nil)
  3880. (defvar org-last-arg nil)
  3881. ;;;###autoload
  3882. (defun org-todo-list (arg)
  3883. "Show all (not done) TODO entries from all agenda file in a single list.
  3884. The prefix arg can be used to select a specific TODO keyword and limit
  3885. the list to these. When using \\[universal-argument], you will be prompted
  3886. for a keyword. A numeric prefix directly selects the Nth keyword in
  3887. `org-todo-keywords-1'."
  3888. (interactive "P")
  3889. (org-prepare-agenda "TODO")
  3890. (org-compile-prefix-format 'todo)
  3891. (org-set-sorting-strategy 'todo)
  3892. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3893. (let* ((today (org-today))
  3894. (date (calendar-gregorian-from-absolute today))
  3895. (kwds org-todo-keywords-for-agenda)
  3896. (completion-ignore-case t)
  3897. (org-select-this-todo-keyword
  3898. (if (stringp arg) arg
  3899. (and arg (integerp arg) (> arg 0)
  3900. (nth (1- arg) kwds))))
  3901. rtn rtnall files file pos)
  3902. (when (equal arg '(4))
  3903. (setq org-select-this-todo-keyword
  3904. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3905. (mapcar 'list kwds) nil nil)))
  3906. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3907. (org-set-local 'org-last-arg arg)
  3908. (setq org-agenda-redo-command
  3909. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3910. (setq files (org-agenda-files nil 'ifmode)
  3911. rtnall nil)
  3912. (while (setq file (pop files))
  3913. (catch 'nextfile
  3914. (org-check-agenda-file file)
  3915. (setq rtn (org-agenda-get-day-entries file date :todo))
  3916. (setq rtnall (append rtnall rtn))))
  3917. (if org-agenda-overriding-header
  3918. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3919. nil 'face 'org-agenda-structure) "\n")
  3920. (insert "Global list of TODO items of type: ")
  3921. (add-text-properties (point-min) (1- (point))
  3922. (list 'face 'org-agenda-structure
  3923. 'short-heading
  3924. (concat "ToDo: "
  3925. (or org-select-this-todo-keyword "ALL"))))
  3926. (org-agenda-mark-header-line (point-min))
  3927. (setq pos (point))
  3928. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3929. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3930. (setq pos (point))
  3931. (unless org-agenda-multi
  3932. (insert "Available with `N r': (0)ALL")
  3933. (let ((n 0) s)
  3934. (mapc (lambda (x)
  3935. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3936. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3937. (insert "\n "))
  3938. (insert " " s))
  3939. kwds))
  3940. (insert "\n"))
  3941. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3942. (org-agenda-mark-header-line (point-min))
  3943. (when rtnall
  3944. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3945. (goto-char (point-min))
  3946. (or org-agenda-multi (org-fit-agenda-window))
  3947. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3948. (org-finalize-agenda)
  3949. (setq buffer-read-only t)))
  3950. ;;; Agenda tags match
  3951. ;;;###autoload
  3952. (defun org-tags-view (&optional todo-only match)
  3953. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3954. The prefix arg TODO-ONLY limits the search to TODO entries."
  3955. (interactive "P")
  3956. (let* ((org-tags-match-list-sublevels
  3957. org-tags-match-list-sublevels)
  3958. (completion-ignore-case t)
  3959. rtn rtnall files file pos matcher
  3960. buffer)
  3961. (when (and (stringp match) (not (string-match "\\S-" match)))
  3962. (setq match nil))
  3963. (setq matcher (org-make-tags-matcher match)
  3964. match (car matcher) matcher (cdr matcher))
  3965. (org-prepare-agenda (concat "TAGS " match))
  3966. (org-compile-prefix-format 'tags)
  3967. (org-set-sorting-strategy 'tags)
  3968. (setq org-agenda-query-string match)
  3969. (setq org-agenda-redo-command
  3970. (list 'org-tags-view (list 'quote todo-only)
  3971. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3972. (setq files (org-agenda-files nil 'ifmode)
  3973. rtnall nil)
  3974. (while (setq file (pop files))
  3975. (catch 'nextfile
  3976. (org-check-agenda-file file)
  3977. (setq buffer (if (file-exists-p file)
  3978. (org-get-agenda-file-buffer file)
  3979. (error "No such file %s" file)))
  3980. (if (not buffer)
  3981. ;; If file does not exist, error message to agenda
  3982. (setq rtn (list
  3983. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3984. rtnall (append rtnall rtn))
  3985. (with-current-buffer buffer
  3986. (unless (derived-mode-p 'org-mode)
  3987. (error "Agenda file %s is not in `org-mode'" file))
  3988. (save-excursion
  3989. (save-restriction
  3990. (if org-agenda-restrict
  3991. (narrow-to-region org-agenda-restrict-begin
  3992. org-agenda-restrict-end)
  3993. (widen))
  3994. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3995. (setq rtnall (append rtnall rtn))))))))
  3996. (if org-agenda-overriding-header
  3997. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3998. nil 'face 'org-agenda-structure) "\n")
  3999. (insert "Headlines with TAGS match: ")
  4000. (add-text-properties (point-min) (1- (point))
  4001. (list 'face 'org-agenda-structure
  4002. 'short-heading
  4003. (concat "Match: " match)))
  4004. (setq pos (point))
  4005. (insert match "\n")
  4006. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4007. (setq pos (point))
  4008. (unless org-agenda-multi
  4009. (insert "Press `C-u r' to search again with new search string\n"))
  4010. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4011. (org-agenda-mark-header-line (point-min))
  4012. (when rtnall
  4013. (insert (org-finalize-agenda-entries rtnall) "\n"))
  4014. (goto-char (point-min))
  4015. (or org-agenda-multi (org-fit-agenda-window))
  4016. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  4017. (org-finalize-agenda)
  4018. (setq buffer-read-only t)))
  4019. ;;; Agenda Finding stuck projects
  4020. (defvar org-agenda-skip-regexp nil
  4021. "Regular expression used in skipping subtrees for the agenda.
  4022. This is basically a temporary global variable that can be set and then
  4023. used by user-defined selections using `org-agenda-skip-function'.")
  4024. (defvar org-agenda-overriding-header nil
  4025. "When set during agenda, todo and tags searches it replaces the header.
  4026. This variable should not be set directly, but custom commands can bind it
  4027. in the options section.")
  4028. (defun org-agenda-skip-entry-when-regexp-matches ()
  4029. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4030. If yes, it returns the end position of this entry, causing agenda commands
  4031. to skip the entry but continuing the search in the subtree. This is a
  4032. function that can be put into `org-agenda-skip-function' for the duration
  4033. of a command."
  4034. (let ((end (save-excursion (org-end-of-subtree t)))
  4035. skip)
  4036. (save-excursion
  4037. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4038. (and skip end)))
  4039. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4040. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4041. If yes, it returns the end position of this tree, causing agenda commands
  4042. to skip this subtree. This is a function that can be put into
  4043. `org-agenda-skip-function' for the duration of a command."
  4044. (let ((end (save-excursion (org-end-of-subtree t)))
  4045. skip)
  4046. (save-excursion
  4047. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4048. (and skip end)))
  4049. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4050. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4051. If yes, it returns the end position of the current entry (NOT the tree),
  4052. causing agenda commands to skip the entry but continuing the search in
  4053. the subtree. This is a function that can be put into
  4054. `org-agenda-skip-function' for the duration of a command. An important
  4055. use of this function is for the stuck project list."
  4056. (let ((end (save-excursion (org-end-of-subtree t)))
  4057. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4058. skip)
  4059. (save-excursion
  4060. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4061. (and skip entry-end)))
  4062. (defun org-agenda-skip-entry-if (&rest conditions)
  4063. "Skip entry if any of CONDITIONS is true.
  4064. See `org-agenda-skip-if' for details."
  4065. (org-agenda-skip-if nil conditions))
  4066. (defun org-agenda-skip-subtree-if (&rest conditions)
  4067. "Skip entry if any of CONDITIONS is true.
  4068. See `org-agenda-skip-if' for details."
  4069. (org-agenda-skip-if t conditions))
  4070. (defun org-agenda-skip-if (subtree conditions)
  4071. "Checks current entity for CONDITIONS.
  4072. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4073. the entry (i.e. the text before the next heading) is checked.
  4074. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4075. from different tests. Valid conditions are:
  4076. scheduled Check if there is a scheduled cookie
  4077. notscheduled Check if there is no scheduled cookie
  4078. deadline Check if there is a deadline
  4079. notdeadline Check if there is no deadline
  4080. timestamp Check if there is a timestamp (also deadline or scheduled)
  4081. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4082. regexp Check if regexp matches
  4083. notregexp Check if regexp does not match.
  4084. todo Check if TODO keyword matches
  4085. nottodo Check if TODO keyword does not match
  4086. The regexp is taken from the conditions list, it must come right after
  4087. the `regexp' or `notregexp' element.
  4088. `todo' and `nottodo' accept as an argument a list of todo
  4089. keywords, which may include \"*\" to match any todo keyword.
  4090. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4091. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4092. Instead of a list, a keyword class may be given. For example:
  4093. (org-agenda-skip-entry-if 'nottodo 'done)
  4094. would skip entries that haven't been marked with any of \"DONE\"
  4095. keywords. Possible classes are: `todo', `done', `any'.
  4096. If any of these conditions is met, this function returns the end point of
  4097. the entity, causing the search to continue from there. This is a function
  4098. that can be put into `org-agenda-skip-function' for the duration of a command."
  4099. (let (beg end m)
  4100. (org-back-to-heading t)
  4101. (setq beg (point)
  4102. end (if subtree
  4103. (progn (org-end-of-subtree t) (point))
  4104. (progn (outline-next-heading) (1- (point)))))
  4105. (goto-char beg)
  4106. (and
  4107. (or
  4108. (and (memq 'scheduled conditions)
  4109. (re-search-forward org-scheduled-time-regexp end t))
  4110. (and (memq 'notscheduled conditions)
  4111. (not (re-search-forward org-scheduled-time-regexp end t)))
  4112. (and (memq 'deadline conditions)
  4113. (re-search-forward org-deadline-time-regexp end t))
  4114. (and (memq 'notdeadline conditions)
  4115. (not (re-search-forward org-deadline-time-regexp end t)))
  4116. (and (memq 'timestamp conditions)
  4117. (re-search-forward org-ts-regexp end t))
  4118. (and (memq 'nottimestamp conditions)
  4119. (not (re-search-forward org-ts-regexp end t)))
  4120. (and (setq m (memq 'regexp conditions))
  4121. (stringp (nth 1 m))
  4122. (re-search-forward (nth 1 m) end t))
  4123. (and (setq m (memq 'notregexp conditions))
  4124. (stringp (nth 1 m))
  4125. (not (re-search-forward (nth 1 m) end t)))
  4126. (and (or
  4127. (setq m (memq 'nottodo conditions))
  4128. (setq m (memq 'todo-unblocked conditions))
  4129. (setq m (memq 'nottodo-unblocked conditions))
  4130. (setq m (memq 'todo conditions)))
  4131. (org-agenda-skip-if-todo m end)))
  4132. end)))
  4133. (defun org-agenda-skip-if-todo (args end)
  4134. "Helper function for `org-agenda-skip-if', do not use it directly.
  4135. ARGS is a list with first element either `todo', `nottodo',
  4136. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4137. a list of TODO keywords, or a state symbol `todo' or `done' or
  4138. `any'."
  4139. (let ((kw (car args))
  4140. (arg (cadr args))
  4141. todo-wds todo-re)
  4142. (setq todo-wds
  4143. (org-uniquify
  4144. (cond
  4145. ((listp arg) ;; list of keywords
  4146. (if (member "*" arg)
  4147. (mapcar 'substring-no-properties org-todo-keywords-1)
  4148. arg))
  4149. ((symbolp arg) ;; keyword class name
  4150. (cond
  4151. ((eq arg 'todo)
  4152. (org-delete-all org-done-keywords
  4153. (mapcar 'substring-no-properties
  4154. org-todo-keywords-1)))
  4155. ((eq arg 'done) org-done-keywords)
  4156. ((eq arg 'any)
  4157. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4158. (setq todo-re
  4159. (concat "^\\*+[ \t]+\\<\\("
  4160. (mapconcat 'identity todo-wds "\\|")
  4161. "\\)\\>"))
  4162. (cond
  4163. ((eq kw 'todo) (re-search-forward todo-re end t))
  4164. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4165. ((eq kw 'todo-unblocked)
  4166. (catch 'unblocked
  4167. (while (re-search-forward todo-re end t)
  4168. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4169. nil))
  4170. ((eq kw 'nottodo-unblocked)
  4171. (catch 'unblocked
  4172. (while (re-search-forward todo-re end t)
  4173. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4174. t))
  4175. )))
  4176. ;;;###autoload
  4177. (defun org-agenda-list-stuck-projects (&rest ignore)
  4178. "Create agenda view for projects that are stuck.
  4179. Stuck projects are project that have no next actions. For the definitions
  4180. of what a project is and how to check if it stuck, customize the variable
  4181. `org-stuck-projects'."
  4182. (interactive)
  4183. (let* ((org-agenda-skip-function
  4184. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4185. ;; We could have used org-agenda-skip-if here.
  4186. (org-agenda-overriding-header
  4187. (or org-agenda-overriding-header "List of stuck projects: "))
  4188. (matcher (nth 0 org-stuck-projects))
  4189. (todo (nth 1 org-stuck-projects))
  4190. (todo-wds (if (member "*" todo)
  4191. (progn
  4192. (org-prepare-agenda-buffers (org-agenda-files
  4193. nil 'ifmode))
  4194. (org-delete-all
  4195. org-done-keywords-for-agenda
  4196. (copy-sequence org-todo-keywords-for-agenda)))
  4197. todo))
  4198. (todo-re (concat "^\\*+[ \t]+\\("
  4199. (mapconcat 'identity todo-wds "\\|")
  4200. "\\)\\>"))
  4201. (tags (nth 2 org-stuck-projects))
  4202. (tags-re (if (member "*" tags)
  4203. (concat org-outline-regexp-bol
  4204. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4205. (if tags
  4206. (concat org-outline-regexp-bol
  4207. ".*:\\("
  4208. (mapconcat 'identity tags "\\|")
  4209. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4210. (gen-re (nth 3 org-stuck-projects))
  4211. (re-list
  4212. (delq nil
  4213. (list
  4214. (if todo todo-re)
  4215. (if tags tags-re)
  4216. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4217. gen-re)))))
  4218. (setq org-agenda-skip-regexp
  4219. (if re-list
  4220. (mapconcat 'identity re-list "\\|")
  4221. (error "No information how to identify unstuck projects")))
  4222. (org-tags-view nil matcher)
  4223. (with-current-buffer org-agenda-buffer-name
  4224. (setq org-agenda-redo-command
  4225. '(org-agenda-list-stuck-projects
  4226. (or current-prefix-arg org-last-arg))))))
  4227. ;;; Diary integration
  4228. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4229. (defvar diary-list-entries-hook)
  4230. (defvar diary-time-regexp)
  4231. (defun org-get-entries-from-diary (date)
  4232. "Get the (Emacs Calendar) diary entries for DATE."
  4233. (require 'diary-lib)
  4234. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4235. (diary-display-hook '(fancy-diary-display))
  4236. (diary-display-function 'fancy-diary-display)
  4237. (pop-up-frames nil)
  4238. (diary-list-entries-hook
  4239. (cons 'org-diary-default-entry diary-list-entries-hook))
  4240. (diary-file-name-prefix-function nil) ; turn this feature off
  4241. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4242. entries
  4243. (org-disable-agenda-to-diary t))
  4244. (save-excursion
  4245. (save-window-excursion
  4246. (funcall (if (fboundp 'diary-list-entries)
  4247. 'diary-list-entries 'list-diary-entries)
  4248. date 1)))
  4249. (if (not (get-buffer diary-fancy-buffer))
  4250. (setq entries nil)
  4251. (with-current-buffer diary-fancy-buffer
  4252. (setq buffer-read-only nil)
  4253. (if (zerop (buffer-size))
  4254. ;; No entries
  4255. (setq entries nil)
  4256. ;; Omit the date and other unnecessary stuff
  4257. (org-agenda-cleanup-fancy-diary)
  4258. ;; Add prefix to each line and extend the text properties
  4259. (if (zerop (buffer-size))
  4260. (setq entries nil)
  4261. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4262. (setq entries
  4263. (with-temp-buffer
  4264. (insert entries) (goto-char (point-min))
  4265. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4266. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4267. (replace-match (concat "; " (match-string 1)))))
  4268. (buffer-string)))))
  4269. (set-buffer-modified-p nil)
  4270. (kill-buffer diary-fancy-buffer)))
  4271. (when entries
  4272. (setq entries (org-split-string entries "\n"))
  4273. (setq entries
  4274. (mapcar
  4275. (lambda (x)
  4276. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4277. ;; Extend the text properties to the beginning of the line
  4278. (org-add-props x (text-properties-at (1- (length x)) x)
  4279. 'type "diary" 'date date 'face 'org-agenda-diary))
  4280. entries)))))
  4281. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4282. "Hook run when the fancy diary buffer is cleaned up.")
  4283. (defun org-agenda-cleanup-fancy-diary ()
  4284. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4285. This gets rid of the date, the underline under the date, and
  4286. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4287. date. It also removes lines that contain only whitespace."
  4288. (goto-char (point-min))
  4289. (if (looking-at ".*?:[ \t]*")
  4290. (progn
  4291. (replace-match "")
  4292. (re-search-forward "\n=+$" nil t)
  4293. (replace-match "")
  4294. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4295. (re-search-forward "\n=+$" nil t)
  4296. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4297. (goto-char (point-min))
  4298. (while (re-search-forward "^ +\n" nil t)
  4299. (replace-match ""))
  4300. (goto-char (point-min))
  4301. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4302. (replace-match ""))
  4303. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4304. ;; Make sure entries from the diary have the right text properties.
  4305. (eval-after-load "diary-lib"
  4306. '(if (boundp 'diary-modify-entry-list-string-function)
  4307. ;; We can rely on the hook, nothing to do
  4308. nil
  4309. ;; Hook not available, must use advice to make this work
  4310. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4311. "Make the position visible."
  4312. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4313. (stringp string)
  4314. buffer-file-name)
  4315. (setq string (org-modify-diary-entry-string string))))))
  4316. (defun org-modify-diary-entry-string (string)
  4317. "Add text properties to string, allowing org-mode to act on it."
  4318. (org-add-props string nil
  4319. 'mouse-face 'highlight
  4320. 'help-echo (if buffer-file-name
  4321. (format "mouse-2 or RET jump to diary file %s"
  4322. (abbreviate-file-name buffer-file-name))
  4323. "")
  4324. 'org-agenda-diary-link t
  4325. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4326. (defun org-diary-default-entry ()
  4327. "Add a dummy entry to the diary.
  4328. Needed to avoid empty dates which mess up holiday display."
  4329. ;; Catch the error if dealing with the new add-to-diary-alist
  4330. (when org-disable-agenda-to-diary
  4331. (condition-case nil
  4332. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4333. (error
  4334. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4335. (defun org-add-to-diary-list (&rest args)
  4336. (if (fboundp 'diary-add-to-list)
  4337. (apply 'diary-add-to-list args)
  4338. (apply 'add-to-diary-list args)))
  4339. (defvar org-diary-last-run-time nil)
  4340. ;;;###autoload
  4341. (defun org-diary (&rest args)
  4342. "Return diary information from org-files.
  4343. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4344. It accesses org files and extracts information from those files to be
  4345. listed in the diary. The function accepts arguments specifying what
  4346. items should be listed. For a list of arguments allowed here, see the
  4347. variable `org-agenda-entry-types'.
  4348. The call in the diary file should look like this:
  4349. &%%(org-diary) ~/path/to/some/orgfile.org
  4350. Use a separate line for each org file to check. Or, if you omit the file name,
  4351. all files listed in `org-agenda-files' will be checked automatically:
  4352. &%%(org-diary)
  4353. If you don't give any arguments (as in the example above), the default
  4354. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4355. So the example above may also be written as
  4356. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4357. The function expects the lisp variables `entry' and `date' to be provided
  4358. by the caller, because this is how the calendar works. Don't use this
  4359. function from a program - use `org-agenda-get-day-entries' instead."
  4360. (when (> (- (org-float-time)
  4361. org-agenda-last-marker-time)
  4362. 5)
  4363. ;; I am not sure if this works with sticky agendas, because the marker
  4364. ;; list is then no longer a global variable.
  4365. (org-agenda-reset-markers))
  4366. ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
  4367. (when (buffer-live-p org-agenda-buffer)
  4368. (org-compile-prefix-format 'agenda))
  4369. (org-set-sorting-strategy 'agenda)
  4370. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4371. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4372. (list entry)
  4373. (org-agenda-files t)))
  4374. (time (org-float-time))
  4375. file rtn results)
  4376. (when (or (not org-diary-last-run-time)
  4377. (> (- time
  4378. org-diary-last-run-time)
  4379. 3))
  4380. (org-prepare-agenda-buffers files))
  4381. (setq org-diary-last-run-time time)
  4382. ;; If this is called during org-agenda, don't return any entries to
  4383. ;; the calendar. Org Agenda will list these entries itself.
  4384. (if org-disable-agenda-to-diary (setq files nil))
  4385. (while (setq file (pop files))
  4386. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4387. (setq results (append results rtn)))
  4388. (if results
  4389. (concat (org-finalize-agenda-entries results) "\n"))))
  4390. ;;; Agenda entry finders
  4391. (defun org-agenda-get-day-entries (file date &rest args)
  4392. "Does the work for `org-diary' and `org-agenda'.
  4393. FILE is the path to a file to be checked for entries. DATE is date like
  4394. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4395. which kind of entries should be extracted. For details about these, see
  4396. the documentation of `org-diary'."
  4397. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4398. (let* ((org-startup-folded nil)
  4399. (org-startup-align-all-tables nil)
  4400. (buffer (if (file-exists-p file)
  4401. (org-get-agenda-file-buffer file)
  4402. (error "No such file %s" file)))
  4403. arg results rtn deadline-results)
  4404. (if (not buffer)
  4405. ;; If file does not exist, make sure an error message ends up in diary
  4406. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4407. (with-current-buffer buffer
  4408. (unless (derived-mode-p 'org-mode)
  4409. (error "Agenda file %s is not in `org-mode'" file))
  4410. (let ((case-fold-search nil))
  4411. (save-excursion
  4412. (save-restriction
  4413. (if org-agenda-restrict
  4414. (narrow-to-region org-agenda-restrict-begin
  4415. org-agenda-restrict-end)
  4416. (widen))
  4417. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4418. (while (setq arg (pop args))
  4419. (cond
  4420. ((and (eq arg :todo)
  4421. (equal date (calendar-gregorian-from-absolute
  4422. (org-today))))
  4423. (setq rtn (org-agenda-get-todos))
  4424. (setq results (append results rtn)))
  4425. ((eq arg :timestamp)
  4426. (setq rtn (org-agenda-get-blocks))
  4427. (setq results (append results rtn))
  4428. (setq rtn (org-agenda-get-timestamps deadline-results))
  4429. (setq results (append results rtn)))
  4430. ((eq arg :sexp)
  4431. (setq rtn (org-agenda-get-sexps))
  4432. (setq results (append results rtn)))
  4433. ((eq arg :scheduled)
  4434. (setq rtn (org-agenda-get-scheduled deadline-results))
  4435. (setq results (append results rtn)))
  4436. ((eq arg :closed)
  4437. (setq rtn (org-agenda-get-progress))
  4438. (setq results (append results rtn)))
  4439. ((eq arg :deadline)
  4440. (setq rtn (org-agenda-get-deadlines))
  4441. (setq deadline-results (copy-sequence rtn))
  4442. (setq results (append results rtn))))))))
  4443. results))))
  4444. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4445. (defun org-agenda-get-todos ()
  4446. "Return the TODO information for agenda display."
  4447. (let* ((props (list 'face nil
  4448. 'done-face 'org-agenda-done
  4449. 'org-not-done-regexp org-not-done-regexp
  4450. 'org-todo-regexp org-todo-regexp
  4451. 'org-complex-heading-regexp org-complex-heading-regexp
  4452. 'mouse-face 'highlight
  4453. 'help-echo
  4454. (format "mouse-2 or RET jump to org file %s"
  4455. (abbreviate-file-name buffer-file-name))))
  4456. (regexp (format org-heading-keyword-regexp-format
  4457. (cond
  4458. ((and org-select-this-todo-keyword
  4459. (equal org-select-this-todo-keyword "*"))
  4460. org-todo-regexp)
  4461. (org-select-this-todo-keyword
  4462. (concat "\\("
  4463. (mapconcat 'identity
  4464. (org-split-string
  4465. org-select-this-todo-keyword
  4466. "|")
  4467. "\\|") "\\)"))
  4468. (t org-not-done-regexp))))
  4469. marker priority category org-category-pos tags todo-state
  4470. ee txt beg end)
  4471. (goto-char (point-min))
  4472. (while (re-search-forward regexp nil t)
  4473. (catch :skip
  4474. (save-match-data
  4475. (beginning-of-line)
  4476. (org-agenda-skip)
  4477. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4478. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4479. (goto-char (1+ beg))
  4480. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4481. (throw :skip nil)))
  4482. (goto-char (match-beginning 2))
  4483. (setq marker (org-agenda-new-marker (match-beginning 0))
  4484. category (org-get-category)
  4485. org-category-pos (get-text-property (point) 'org-category-position)
  4486. txt (org-trim
  4487. (buffer-substring (match-beginning 2) (match-end 0)))
  4488. tags (org-get-tags-at (point))
  4489. txt (org-agenda-format-item "" txt category tags)
  4490. priority (1+ (org-get-priority txt))
  4491. todo-state (org-get-todo-state))
  4492. (org-add-props txt props
  4493. 'org-marker marker 'org-hd-marker marker
  4494. 'priority priority 'org-category category
  4495. 'org-category-position org-category-pos
  4496. 'type "todo" 'todo-state todo-state)
  4497. (push txt ee)
  4498. (if org-agenda-todo-list-sublevels
  4499. (goto-char (match-end 2))
  4500. (org-end-of-subtree 'invisible))))
  4501. (nreverse ee)))
  4502. (defun org-agenda-todo-custom-ignore-p (time n)
  4503. "Check whether timestamp is farther away then n number of days.
  4504. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4505. `org-agenda-todo-ignore-scheduled' or
  4506. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4507. (let ((days (org-days-to-time time)))
  4508. (if (>= n 0)
  4509. (>= days n)
  4510. (<= days n))))
  4511. ;;;###autoload
  4512. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4513. (&optional end)
  4514. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4515. (when (or org-agenda-todo-ignore-with-date
  4516. org-agenda-todo-ignore-scheduled
  4517. org-agenda-todo-ignore-deadlines
  4518. org-agenda-todo-ignore-timestamp)
  4519. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4520. (save-excursion
  4521. (or (and org-agenda-todo-ignore-with-date
  4522. (re-search-forward org-ts-regexp end t))
  4523. (and org-agenda-todo-ignore-scheduled
  4524. (re-search-forward org-scheduled-time-regexp end t)
  4525. (cond
  4526. ((eq org-agenda-todo-ignore-scheduled 'future)
  4527. (> (org-days-to-time (match-string 1)) 0))
  4528. ((eq org-agenda-todo-ignore-scheduled 'past)
  4529. (<= (org-days-to-time (match-string 1)) 0))
  4530. ((numberp org-agenda-todo-ignore-scheduled)
  4531. (org-agenda-todo-custom-ignore-p
  4532. (match-string 1) org-agenda-todo-ignore-scheduled))
  4533. (t)))
  4534. (and org-agenda-todo-ignore-deadlines
  4535. (re-search-forward org-deadline-time-regexp end t)
  4536. (cond
  4537. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4538. ((eq org-agenda-todo-ignore-deadlines 'far)
  4539. (not (org-deadline-close (match-string 1))))
  4540. ((eq org-agenda-todo-ignore-deadlines 'future)
  4541. (> (org-days-to-time (match-string 1)) 0))
  4542. ((eq org-agenda-todo-ignore-deadlines 'past)
  4543. (<= (org-days-to-time (match-string 1)) 0))
  4544. ((numberp org-agenda-todo-ignore-deadlines)
  4545. (org-agenda-todo-custom-ignore-p
  4546. (match-string 1) org-agenda-todo-ignore-deadlines))
  4547. (t (org-deadline-close (match-string 1)))))
  4548. (and org-agenda-todo-ignore-timestamp
  4549. (let ((buffer (current-buffer))
  4550. (regexp
  4551. (concat
  4552. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4553. (start (point)))
  4554. ;; Copy current buffer into a temporary one
  4555. (with-temp-buffer
  4556. (insert-buffer-substring buffer start end)
  4557. (goto-char (point-min))
  4558. ;; Delete SCHEDULED and DEADLINE items
  4559. (while (re-search-forward regexp end t)
  4560. (delete-region (match-beginning 0) (match-end 0)))
  4561. (goto-char (point-min))
  4562. ;; No search for timestamp left
  4563. (when (re-search-forward org-ts-regexp nil t)
  4564. (cond
  4565. ((eq org-agenda-todo-ignore-timestamp 'future)
  4566. (> (org-days-to-time (match-string 1)) 0))
  4567. ((eq org-agenda-todo-ignore-timestamp 'past)
  4568. (<= (org-days-to-time (match-string 1)) 0))
  4569. ((numberp org-agenda-todo-ignore-timestamp)
  4570. (org-agenda-todo-custom-ignore-p
  4571. (match-string 1) org-agenda-todo-ignore-timestamp))
  4572. (t))))))))))
  4573. (defconst org-agenda-no-heading-message
  4574. "No heading for this item in buffer or region.")
  4575. (defun org-agenda-get-timestamps (&optional deadline-results)
  4576. "Return the date stamp information for agenda display."
  4577. (let* ((props (list 'face 'org-agenda-calendar-event
  4578. 'org-not-done-regexp org-not-done-regexp
  4579. 'org-todo-regexp org-todo-regexp
  4580. 'org-complex-heading-regexp org-complex-heading-regexp
  4581. 'mouse-face 'highlight
  4582. 'help-echo
  4583. (format "mouse-2 or RET jump to org file %s"
  4584. (abbreviate-file-name buffer-file-name))))
  4585. (d1 (calendar-absolute-from-gregorian date))
  4586. mm
  4587. (deadline-position-alist
  4588. (mapcar (lambda (a) (and (setq mm (get-text-property
  4589. 0 'org-hd-marker a))
  4590. (cons (marker-position mm) a)))
  4591. deadline-results))
  4592. (remove-re org-ts-regexp)
  4593. (regexp
  4594. (concat
  4595. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4596. (regexp-quote
  4597. (substring
  4598. (format-time-string
  4599. (car org-time-stamp-formats)
  4600. (apply 'encode-time ; DATE bound by calendar
  4601. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4602. 1 11))
  4603. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4604. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4605. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4606. donep tmp priority category org-category-pos ee txt timestr tags
  4607. b0 b3 e3 head todo-state end-of-match show-all)
  4608. (goto-char (point-min))
  4609. (while (setq end-of-match (re-search-forward regexp nil t))
  4610. (setq b0 (match-beginning 0)
  4611. b3 (match-beginning 3) e3 (match-end 3)
  4612. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4613. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4614. (member todo-state
  4615. org-agenda-repeating-timestamp-show-all)))
  4616. (catch :skip
  4617. (and (org-at-date-range-p) (throw :skip nil))
  4618. (org-agenda-skip)
  4619. (if (and (match-end 1)
  4620. (not (= d1 (org-time-string-to-absolute
  4621. (match-string 1) d1 nil show-all
  4622. (current-buffer) b0))))
  4623. (throw :skip nil))
  4624. (if (and e3
  4625. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4626. (throw :skip nil))
  4627. (setq tmp (buffer-substring (max (point-min)
  4628. (- b0 org-ds-keyword-length))
  4629. b0)
  4630. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4631. inactivep (= (char-after b0) ?\[)
  4632. deadlinep (string-match org-deadline-regexp tmp)
  4633. scheduledp (string-match org-scheduled-regexp tmp)
  4634. closedp (and org-agenda-include-inactive-timestamps
  4635. (string-match org-closed-string tmp))
  4636. clockp (and org-agenda-include-inactive-timestamps
  4637. (or (string-match org-clock-string tmp)
  4638. (string-match "]-+\\'" tmp)))
  4639. donep (member todo-state org-done-keywords))
  4640. (if (or scheduledp deadlinep closedp clockp
  4641. (and donep org-agenda-skip-timestamp-if-done))
  4642. (throw :skip t))
  4643. (if (string-match ">" timestr)
  4644. ;; substring should only run to end of time stamp
  4645. (setq timestr (substring timestr 0 (match-end 0))))
  4646. (setq marker (org-agenda-new-marker b0)
  4647. category (org-get-category b0)
  4648. org-category-pos (get-text-property b0 'org-category-position))
  4649. (save-excursion
  4650. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4651. (setq txt org-agenda-no-heading-message)
  4652. (goto-char (match-beginning 0))
  4653. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4654. (assoc (point) deadline-position-alist))
  4655. (throw :skip nil))
  4656. (setq hdmarker (org-agenda-new-marker)
  4657. tags (org-get-tags-at))
  4658. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4659. (setq head (or (match-string 1) ""))
  4660. (setq txt (org-agenda-format-item
  4661. (if inactivep org-agenda-inactive-leader nil)
  4662. head category tags timestr
  4663. remove-re)))
  4664. (setq priority (org-get-priority txt))
  4665. (org-add-props txt props
  4666. 'org-marker marker 'org-hd-marker hdmarker)
  4667. (org-add-props txt nil 'priority priority
  4668. 'org-category category 'date date
  4669. 'org-category-position org-category-pos
  4670. 'todo-state todo-state
  4671. 'type "timestamp")
  4672. (push txt ee))
  4673. (if org-agenda-skip-additional-timestamps-same-entry
  4674. (outline-next-heading)
  4675. (goto-char end-of-match))))
  4676. (nreverse ee)))
  4677. (defun org-agenda-get-sexps ()
  4678. "Return the sexp information for agenda display."
  4679. (require 'diary-lib)
  4680. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4681. 'mouse-face 'highlight
  4682. 'help-echo
  4683. (format "mouse-2 or RET jump to org file %s"
  4684. (abbreviate-file-name buffer-file-name))))
  4685. (regexp "^&?%%(")
  4686. marker category extra org-category-pos ee txt tags entry
  4687. result beg b sexp sexp-entry todo-state)
  4688. (goto-char (point-min))
  4689. (while (re-search-forward regexp nil t)
  4690. (catch :skip
  4691. (org-agenda-skip)
  4692. (setq beg (match-beginning 0))
  4693. (goto-char (1- (match-end 0)))
  4694. (setq b (point))
  4695. (forward-sexp 1)
  4696. (setq sexp (buffer-substring b (point)))
  4697. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4698. (org-trim (match-string 1))
  4699. ""))
  4700. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4701. (when result
  4702. (setq marker (org-agenda-new-marker beg)
  4703. category (org-get-category beg)
  4704. org-category-pos (get-text-property beg 'org-category-position)
  4705. todo-state (org-get-todo-state))
  4706. (dolist (r (if (stringp result)
  4707. (list result)
  4708. result)) ;; we expect a list here
  4709. (when (and org-agenda-diary-sexp-prefix
  4710. (string-match org-agenda-diary-sexp-prefix r))
  4711. (setq extra (match-string 0 r)
  4712. r (replace-match "" nil nil r)))
  4713. (if (string-match "\\S-" r)
  4714. (setq txt r)
  4715. (setq txt "SEXP entry returned empty string"))
  4716. (setq txt (org-agenda-format-item
  4717. extra txt category tags 'time))
  4718. (org-add-props txt props 'org-marker marker)
  4719. (org-add-props txt nil
  4720. 'org-category category 'date date 'todo-state todo-state
  4721. 'org-category-position org-category-pos
  4722. 'type "sexp")
  4723. (push txt ee)))))
  4724. (nreverse ee)))
  4725. ;; Calendar sanity: define some functions that are independent of
  4726. ;; `calendar-date-style'.
  4727. ;; Normally I would like to use ISO format when calling the diary functions,
  4728. ;; but to make sure we still have Emacs 22 compatibility we bind
  4729. ;; also `european-calendar-style' and use european format
  4730. (defun org-anniversary (year month day &optional mark)
  4731. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4732. (org-no-warnings
  4733. (let ((calendar-date-style 'european) (european-calendar-style t))
  4734. (diary-anniversary day month year mark))))
  4735. (defun org-cyclic (N year month day &optional mark)
  4736. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4737. (org-no-warnings
  4738. (let ((calendar-date-style 'european) (european-calendar-style t))
  4739. (diary-cyclic N day month year mark))))
  4740. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4741. "Like `diary-block', but with fixed (ISO) order of arguments."
  4742. (org-no-warnings
  4743. (let ((calendar-date-style 'european) (european-calendar-style t))
  4744. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4745. (defun org-date (year month day &optional mark)
  4746. "Like `diary-date', but with fixed (ISO) order of arguments."
  4747. (org-no-warnings
  4748. (let ((calendar-date-style 'european) (european-calendar-style t))
  4749. (diary-date day month year mark))))
  4750. (defalias 'org-float 'diary-float)
  4751. ;; Define the` org-class' function
  4752. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4753. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4754. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4755. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4756. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4757. `holidays', then any date that is known by the Emacs calendar to be a
  4758. holiday will also be skipped."
  4759. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4760. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4761. (d (calendar-absolute-from-gregorian date)))
  4762. (and
  4763. (<= date1 d)
  4764. (<= d date2)
  4765. (= (calendar-day-of-week date) dayname)
  4766. (or (not skip-weeks)
  4767. (progn
  4768. (require 'cal-iso)
  4769. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4770. (not (and (memq 'holidays skip-weeks)
  4771. (calendar-check-holidays date)))
  4772. entry)))
  4773. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4774. "Like `org-class', but honor `calendar-date-style'.
  4775. The order of the first 2 times 3 arguments depends on the variable
  4776. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4777. So for American calendars, give this as MONTH DAY YEAR, for European as
  4778. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4779. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4780. is any number of ISO weeks in the block period for which the item should
  4781. be skipped.
  4782. This function is here only for backward compatibility and it is deprecated,
  4783. please use `org-class' instead."
  4784. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4785. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4786. (org-class
  4787. (nth 2 date1) (car date1) (nth 1 date1)
  4788. (nth 2 date2) (car date2) (nth 1 date2)
  4789. dayname skip-weeks)))
  4790. (make-obsolete 'org-diary-class 'org-class "")
  4791. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4792. (defalias 'org-get-closed 'org-agenda-get-progress)
  4793. (defun org-agenda-get-progress ()
  4794. "Return the logged TODO entries for agenda display."
  4795. (let* ((props (list 'mouse-face 'highlight
  4796. 'org-not-done-regexp org-not-done-regexp
  4797. 'org-todo-regexp org-todo-regexp
  4798. 'org-complex-heading-regexp org-complex-heading-regexp
  4799. 'help-echo
  4800. (format "mouse-2 or RET jump to org file %s"
  4801. (abbreviate-file-name buffer-file-name))))
  4802. (items (if (consp org-agenda-show-log-scoped)
  4803. org-agenda-show-log-scoped
  4804. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4805. '(clock)
  4806. org-agenda-log-mode-items)))
  4807. (parts
  4808. (delq nil
  4809. (list
  4810. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4811. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4812. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4813. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4814. (error "`org-agenda-log-mode-items' is empty")))
  4815. (regexp (concat
  4816. "\\(" parts-re "\\)"
  4817. " *\\["
  4818. (regexp-quote
  4819. (substring
  4820. (format-time-string
  4821. (car org-time-stamp-formats)
  4822. (apply 'encode-time ; DATE bound by calendar
  4823. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4824. 1 11))))
  4825. (org-agenda-search-headline-for-time nil)
  4826. marker hdmarker priority category org-category-pos tags closedp
  4827. statep clockp state ee txt extra timestr rest clocked)
  4828. (goto-char (point-min))
  4829. (while (re-search-forward regexp nil t)
  4830. (catch :skip
  4831. (org-agenda-skip)
  4832. (setq marker (org-agenda-new-marker (match-beginning 0))
  4833. closedp (equal (match-string 1) org-closed-string)
  4834. statep (equal (string-to-char (match-string 1)) ?-)
  4835. clockp (not (or closedp statep))
  4836. state (and statep (match-string 2))
  4837. category (org-get-category (match-beginning 0))
  4838. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4839. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4840. (when (string-match "\\]" timestr)
  4841. ;; substring should only run to end of time stamp
  4842. (setq rest (substring timestr (match-end 0))
  4843. timestr (substring timestr 0 (match-end 0)))
  4844. (if (and (not closedp) (not statep)
  4845. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4846. rest))
  4847. (progn (setq timestr (concat (substring timestr 0 -1)
  4848. "-" (match-string 1 rest) "]"))
  4849. (setq clocked (match-string 2 rest)))
  4850. (setq clocked "-")))
  4851. (save-excursion
  4852. (setq extra
  4853. (cond
  4854. ((not org-agenda-log-mode-add-notes) nil)
  4855. (statep
  4856. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4857. (match-string 1)))
  4858. (clockp
  4859. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4860. (match-string 1)))))
  4861. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4862. (setq txt org-agenda-no-heading-message)
  4863. (goto-char (match-beginning 0))
  4864. (setq hdmarker (org-agenda-new-marker)
  4865. tags (org-get-tags-at))
  4866. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4867. (setq txt (match-string 1))
  4868. (when extra
  4869. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4870. (setq txt (concat (substring txt 0 (match-beginning 1))
  4871. " - " extra " " (match-string 2 txt)))
  4872. (setq txt (concat txt " - " extra))))
  4873. (setq txt (org-agenda-format-item
  4874. (cond
  4875. (closedp "Closed: ")
  4876. (statep (concat "State: (" state ")"))
  4877. (t (concat "Clocked: (" clocked ")")))
  4878. txt category tags timestr)))
  4879. (setq priority 100000)
  4880. (org-add-props txt props
  4881. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4882. 'priority priority 'org-category category
  4883. 'org-category-position org-category-pos
  4884. 'type "closed" 'date date
  4885. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4886. (push txt ee))
  4887. (goto-char (point-at-eol))))
  4888. (nreverse ee)))
  4889. (defun org-agenda-show-clocking-issues ()
  4890. "Add overlays, showing issues with clocking.
  4891. See also the user option `org-agenda-clock-consistency-checks'."
  4892. (interactive)
  4893. (let* ((pl org-agenda-clock-consistency-checks)
  4894. (re (concat "^[ \t]*"
  4895. org-clock-string
  4896. "[ \t]+"
  4897. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4898. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4899. (tlstart 0.)
  4900. (tlend 0.)
  4901. (maxtime (org-hh:mm-string-to-minutes
  4902. (or (plist-get pl :max-duration) "24:00")))
  4903. (mintime (org-hh:mm-string-to-minutes
  4904. (or (plist-get pl :min-duration) 0)))
  4905. (maxgap (org-hh:mm-string-to-minutes
  4906. ;; default 30:00 means never complain
  4907. (or (plist-get pl :max-gap) "30:00")))
  4908. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4909. (plist-get pl :gap-ok-around)))
  4910. (def-face (or (plist-get pl :default-face)
  4911. '((:background "DarkRed") (:foreground "white"))))
  4912. issue face m te ts dt ov)
  4913. (goto-char (point-min))
  4914. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4915. (setq issue nil face def-face)
  4916. (catch 'next
  4917. (setq m (org-get-at-bol 'org-marker)
  4918. te nil ts nil)
  4919. (unless (and m (markerp m))
  4920. (setq issue "No valid clock line") (throw 'next t))
  4921. (org-with-point-at m
  4922. (save-excursion
  4923. (goto-char (point-at-bol))
  4924. (unless (looking-at re)
  4925. (error "No valid Clock line")
  4926. (throw 'next t))
  4927. (unless (match-end 3)
  4928. (setq issue "No end time"
  4929. face (or (plist-get pl :no-end-time-face) face))
  4930. (throw 'next t))
  4931. (setq ts (match-string 1)
  4932. te (match-string 3)
  4933. ts (org-float-time
  4934. (apply 'encode-time (org-parse-time-string ts)))
  4935. te (org-float-time
  4936. (apply 'encode-time (org-parse-time-string te)))
  4937. dt (- te ts))))
  4938. (cond
  4939. ((> dt (* 60 maxtime))
  4940. ;; a very long clocking chunk
  4941. (setq issue (format "Clocking interval is very long: %s"
  4942. (org-minutes-to-hh:mm-string
  4943. (floor (/ (float dt) 60.))))
  4944. face (or (plist-get pl :long-face) face)))
  4945. ((< dt (* 60 mintime))
  4946. ;; a very short clocking chunk
  4947. (setq issue (format "Clocking interval is very short: %s"
  4948. (org-minutes-to-hh:mm-string
  4949. (floor (/ (float dt) 60.))))
  4950. face (or (plist-get pl :short-face) face)))
  4951. ((and (> tlend 0) (< ts tlend))
  4952. ;; Two clock entries are overlapping
  4953. (setq issue (format "Clocking overlap: %d minutes"
  4954. (/ (- tlend ts) 60))
  4955. face (or (plist-get pl :overlap-face) face)))
  4956. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4957. ;; There is a gap, lets see if we need to report it
  4958. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4959. (setq issue (format "Clocking gap: %d minutes"
  4960. (/ (- ts tlend) 60))
  4961. face (or (plist-get pl :gap-face) face))))
  4962. (t nil)))
  4963. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4964. (when issue
  4965. ;; OK, there was some issue, add an overlay to show the issue
  4966. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4967. (overlay-put ov 'before-string
  4968. (concat
  4969. (org-add-props
  4970. (format "%-43s" (concat " " issue))
  4971. nil
  4972. 'face face)
  4973. "\n"))
  4974. (overlay-put ov 'evaporate t)))))
  4975. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4976. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4977. (catch 'exit
  4978. (unless ok-list
  4979. ;; there are no OK times for gaps...
  4980. (throw 'exit nil))
  4981. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4982. ;; This is more than 24 hours, so it is OK.
  4983. ;; because we have at least one OK time, that must be in the
  4984. ;; 24 hour interval.
  4985. (throw 'exit t))
  4986. ;; We have a shorter gap.
  4987. ;; Now we have to get the minute of the day when these times are
  4988. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4989. (t2dec (decode-time (seconds-to-time t2)))
  4990. ;; compute the minute on the day
  4991. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4992. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4993. (when (< min2 min1)
  4994. ;; if min2 is smaller than min1, this means it is on the next day.
  4995. ;; Wrap it to after midnight.
  4996. (setq min2 (+ min2 1440)))
  4997. ;; Now check if any of the OK times is in the gap
  4998. (mapc (lambda (x)
  4999. ;; Wrap the time to after midnight if necessary
  5000. (if (< x min1) (setq x (+ x 1440)))
  5001. ;; Check if in interval
  5002. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5003. ok-list)
  5004. ;; Nope, this gap is not OK
  5005. nil)))
  5006. (defun org-agenda-get-deadlines ()
  5007. "Return the deadline information for agenda display."
  5008. (let* ((props (list 'mouse-face 'highlight
  5009. 'org-not-done-regexp org-not-done-regexp
  5010. 'org-todo-regexp org-todo-regexp
  5011. 'org-complex-heading-regexp org-complex-heading-regexp
  5012. 'help-echo
  5013. (format "mouse-2 or RET jump to org file %s"
  5014. (abbreviate-file-name buffer-file-name))))
  5015. (regexp org-deadline-time-regexp)
  5016. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5017. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5018. d2 diff dfrac wdays pos pos1 category org-category-pos
  5019. tags suppress-prewarning ee txt head face s todo-state
  5020. show-all upcomingp donep timestr)
  5021. (goto-char (point-min))
  5022. (while (re-search-forward regexp nil t)
  5023. (setq suppress-prewarning nil)
  5024. (catch :skip
  5025. (org-agenda-skip)
  5026. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5027. (save-match-data
  5028. (string-match org-scheduled-time-regexp
  5029. (buffer-substring (point-at-bol)
  5030. (point-at-eol)))))
  5031. (setq suppress-prewarning
  5032. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5033. org-agenda-skip-deadline-prewarning-if-scheduled
  5034. 0)))
  5035. (setq s (match-string 1)
  5036. txt nil
  5037. pos (1- (match-beginning 1))
  5038. todo-state (save-match-data (org-get-todo-state))
  5039. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5040. (member todo-state
  5041. org-agenda-repeating-timestamp-show-all))
  5042. d2 (org-time-string-to-absolute
  5043. (match-string 1) d1 'past show-all
  5044. (current-buffer) pos)
  5045. diff (- d2 d1)
  5046. wdays (if suppress-prewarning
  5047. (let ((org-deadline-warning-days suppress-prewarning))
  5048. (org-get-wdays s))
  5049. (org-get-wdays s))
  5050. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5051. upcomingp (and todayp (> diff 0)))
  5052. ;; When to show a deadline in the calendar:
  5053. ;; If the expiration is within wdays warning time.
  5054. ;; Past-due deadlines are only shown on the current date
  5055. (if (and (or (and (<= diff wdays)
  5056. (and todayp (not org-agenda-only-exact-dates)))
  5057. (= diff 0)))
  5058. (save-excursion
  5059. ;; (setq todo-state (org-get-todo-state))
  5060. (setq donep (member todo-state org-done-keywords))
  5061. (if (and donep
  5062. (or org-agenda-skip-deadline-if-done
  5063. (not (= diff 0))))
  5064. (setq txt nil)
  5065. (setq category (org-get-category)
  5066. org-category-pos (get-text-property (point) 'org-category-position))
  5067. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5068. (setq txt org-agenda-no-heading-message)
  5069. (goto-char (match-end 0))
  5070. (setq pos1 (match-beginning 0))
  5071. (setq tags (org-get-tags-at pos1))
  5072. (setq head (buffer-substring-no-properties
  5073. (point)
  5074. (progn (skip-chars-forward "^\r\n")
  5075. (point))))
  5076. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5077. (setq timestr
  5078. (concat (substring s (match-beginning 1)) " "))
  5079. (setq timestr 'time))
  5080. (setq txt (org-agenda-format-item
  5081. (if (= diff 0)
  5082. (car org-agenda-deadline-leaders)
  5083. (if (functionp
  5084. (nth 1 org-agenda-deadline-leaders))
  5085. (funcall
  5086. (nth 1 org-agenda-deadline-leaders)
  5087. diff date)
  5088. (format (nth 1 org-agenda-deadline-leaders)
  5089. diff)))
  5090. head category tags
  5091. (if (not (= diff 0)) nil timestr)))))
  5092. (when txt
  5093. (setq face (org-agenda-deadline-face dfrac))
  5094. (org-add-props txt props
  5095. 'org-marker (org-agenda-new-marker pos)
  5096. 'org-hd-marker (org-agenda-new-marker pos1)
  5097. 'priority (+ (- diff)
  5098. (org-get-priority txt))
  5099. 'org-category category
  5100. 'org-category-position org-category-pos
  5101. 'todo-state todo-state
  5102. 'type (if upcomingp "upcoming-deadline" "deadline")
  5103. 'date (if upcomingp date d2)
  5104. 'face (if donep 'org-agenda-done face)
  5105. 'undone-face face 'done-face 'org-agenda-done)
  5106. (push txt ee))))))
  5107. (nreverse ee)))
  5108. (defun org-agenda-deadline-face (fraction)
  5109. "Return the face to displaying a deadline item.
  5110. FRACTION is what fraction of the head-warning time has passed."
  5111. (let ((faces org-agenda-deadline-faces) f)
  5112. (catch 'exit
  5113. (while (setq f (pop faces))
  5114. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5115. (defun org-agenda-get-scheduled (&optional deadline-results)
  5116. "Return the scheduled information for agenda display."
  5117. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5118. 'org-todo-regexp org-todo-regexp
  5119. 'org-complex-heading-regexp org-complex-heading-regexp
  5120. 'done-face 'org-agenda-done
  5121. 'mouse-face 'highlight
  5122. 'help-echo
  5123. (format "mouse-2 or RET jump to org file %s"
  5124. (abbreviate-file-name buffer-file-name))))
  5125. (regexp org-scheduled-time-regexp)
  5126. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5127. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5128. mm
  5129. (deadline-position-alist
  5130. (mapcar (lambda (a) (and (setq mm (get-text-property
  5131. 0 'org-hd-marker a))
  5132. (cons (marker-position mm) a)))
  5133. deadline-results))
  5134. d2 diff pos pos1 category org-category-pos tags donep
  5135. ee txt head pastschedp todo-state face timestr s habitp show-all)
  5136. (goto-char (point-min))
  5137. (while (re-search-forward regexp nil t)
  5138. (catch :skip
  5139. (org-agenda-skip)
  5140. (setq s (match-string 1)
  5141. txt nil
  5142. pos (1- (match-beginning 1))
  5143. todo-state (save-match-data (org-get-todo-state))
  5144. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5145. (member todo-state
  5146. org-agenda-repeating-timestamp-show-all))
  5147. d2 (org-time-string-to-absolute
  5148. (match-string 1) d1 'past show-all
  5149. (current-buffer) pos)
  5150. diff (- d2 d1))
  5151. (setq pastschedp (and todayp (< diff 0)))
  5152. ;; When to show a scheduled item in the calendar:
  5153. ;; If it is on or past the date.
  5154. (when (or (and (< diff 0)
  5155. (< (abs diff) org-scheduled-past-days)
  5156. (and todayp (not org-agenda-only-exact-dates)))
  5157. (= diff 0))
  5158. (save-excursion
  5159. (setq donep (member todo-state org-done-keywords))
  5160. (if (and donep
  5161. (or org-agenda-skip-scheduled-if-done
  5162. (not (= diff 0))
  5163. (and (functionp 'org-is-habit-p)
  5164. (org-is-habit-p))))
  5165. (setq txt nil)
  5166. (setq habitp (and (functionp 'org-is-habit-p)
  5167. (org-is-habit-p)))
  5168. (setq category (org-get-category)
  5169. org-category-pos (get-text-property (point) 'org-category-position))
  5170. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5171. (setq txt org-agenda-no-heading-message)
  5172. (goto-char (match-end 0))
  5173. (setq pos1 (match-beginning 0))
  5174. (if habitp
  5175. (if (or (not org-habit-show-habits)
  5176. (and (not todayp)
  5177. org-habit-show-habits-only-for-today))
  5178. (throw :skip nil))
  5179. (if (and
  5180. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5181. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5182. pastschedp))
  5183. (setq mm (assoc pos1 deadline-position-alist)))
  5184. (throw :skip nil)))
  5185. (setq tags (org-get-tags-at))
  5186. (setq head (buffer-substring-no-properties
  5187. (point)
  5188. (progn (skip-chars-forward "^\r\n") (point))))
  5189. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5190. (setq timestr
  5191. (concat (substring s (match-beginning 1)) " "))
  5192. (setq timestr 'time))
  5193. (setq txt (org-agenda-format-item
  5194. (if (= diff 0)
  5195. (car org-agenda-scheduled-leaders)
  5196. (format (nth 1 org-agenda-scheduled-leaders)
  5197. (- 1 diff)))
  5198. head category tags
  5199. (if (not (= diff 0)) nil timestr)
  5200. nil habitp))))
  5201. (when txt
  5202. (setq face
  5203. (cond
  5204. ((and (not habitp) pastschedp)
  5205. 'org-scheduled-previously)
  5206. (todayp 'org-scheduled-today)
  5207. (t 'org-scheduled))
  5208. habitp (and habitp (org-habit-parse-todo)))
  5209. (org-add-props txt props
  5210. 'undone-face face
  5211. 'face (if donep 'org-agenda-done face)
  5212. 'org-marker (org-agenda-new-marker pos)
  5213. 'org-hd-marker (org-agenda-new-marker pos1)
  5214. 'type (if pastschedp "past-scheduled" "scheduled")
  5215. 'date (if pastschedp d2 date)
  5216. 'priority (if habitp
  5217. (org-habit-get-priority habitp)
  5218. (+ 94 (- 5 diff) (org-get-priority txt)))
  5219. 'org-category category
  5220. 'org-category-position org-category-pos
  5221. 'org-habit-p habitp
  5222. 'todo-state todo-state)
  5223. (push txt ee))))))
  5224. (nreverse ee)))
  5225. (defun org-agenda-get-blocks ()
  5226. "Return the date-range information for agenda display."
  5227. (let* ((props (list 'face nil
  5228. 'org-not-done-regexp org-not-done-regexp
  5229. 'org-todo-regexp org-todo-regexp
  5230. 'org-complex-heading-regexp org-complex-heading-regexp
  5231. 'mouse-face 'highlight
  5232. 'help-echo
  5233. (format "mouse-2 or RET jump to org file %s"
  5234. (abbreviate-file-name buffer-file-name))))
  5235. (regexp org-tr-regexp)
  5236. (d0 (calendar-absolute-from-gregorian date))
  5237. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5238. todo-state tags pos head donep)
  5239. (goto-char (point-min))
  5240. (while (re-search-forward regexp nil t)
  5241. (catch :skip
  5242. (org-agenda-skip)
  5243. (setq pos (point))
  5244. (let ((start-time (match-string 1))
  5245. (end-time (match-string 2)))
  5246. (setq s1 (match-string 1)
  5247. s2 (match-string 2)
  5248. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5249. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5250. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5251. ;; Only allow days between the limits, because the normal
  5252. ;; date stamps will catch the limits.
  5253. (save-excursion
  5254. (setq todo-state (org-get-todo-state))
  5255. (setq donep (member todo-state org-done-keywords))
  5256. (if (and donep org-agenda-skip-timestamp-if-done)
  5257. (throw :skip t))
  5258. (setq marker (org-agenda-new-marker (point)))
  5259. (setq category (org-get-category)
  5260. org-category-pos (get-text-property (point) 'org-category-position))
  5261. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5262. (setq txt org-agenda-no-heading-message)
  5263. (goto-char (match-beginning 0))
  5264. (setq hdmarker (org-agenda-new-marker (point)))
  5265. (setq tags (org-get-tags-at))
  5266. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5267. (setq head (match-string 1))
  5268. (let ((remove-re
  5269. (if org-agenda-remove-timeranges-from-blocks
  5270. (concat
  5271. "<" (regexp-quote s1) ".*?>"
  5272. "--"
  5273. "<" (regexp-quote s2) ".*?>")
  5274. nil)))
  5275. (setq txt (org-agenda-format-item
  5276. (format
  5277. (nth (if (= d1 d2) 0 1)
  5278. org-agenda-timerange-leaders)
  5279. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5280. head category tags
  5281. (cond ((and (= d1 d0) (= d2 d0))
  5282. (concat "<" start-time ">--<" end-time ">"))
  5283. ((= d1 d0)
  5284. (concat "<" start-time ">"))
  5285. ((= d2 d0)
  5286. (concat "<" end-time ">"))
  5287. (t nil))
  5288. remove-re))))
  5289. (org-add-props txt props
  5290. 'org-marker marker 'org-hd-marker hdmarker
  5291. 'type "block" 'date date
  5292. 'todo-state todo-state
  5293. 'priority (org-get-priority txt) 'org-category category
  5294. 'org-category-position org-category-pos)
  5295. (push txt ee))))
  5296. (goto-char pos)))
  5297. ;; Sort the entries by expiration date.
  5298. (nreverse ee)))
  5299. ;;; Agenda presentation and sorting
  5300. (defvar org-prefix-has-time nil
  5301. "A flag, set by `org-compile-prefix-format'.
  5302. The flag is set if the currently compiled format contains a `%t'.")
  5303. (defvar org-prefix-has-tag nil
  5304. "A flag, set by `org-compile-prefix-format'.
  5305. The flag is set if the currently compiled format contains a `%T'.")
  5306. (defvar org-prefix-has-effort nil
  5307. "A flag, set by `org-compile-prefix-format'.
  5308. The flag is set if the currently compiled format contains a `%e'.")
  5309. (defvar org-prefix-category-length nil
  5310. "Used by `org-compile-prefix-format' to remember the category field width.")
  5311. (defvar org-prefix-category-max-length nil
  5312. "Used by `org-compile-prefix-format' to remember the category field width.")
  5313. (defun org-agenda-get-category-icon (category)
  5314. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5315. (dolist (entry org-agenda-category-icon-alist)
  5316. (when (org-string-match-p (car entry) category)
  5317. (if (listp (cadr entry))
  5318. (return (cadr entry))
  5319. (return (apply 'create-image (cdr entry)))))))
  5320. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5321. remove-re habitp)
  5322. "Format TXT to be inserted into the agenda buffer.
  5323. In particular, it adds the prefix and corresponding text properties. EXTRA
  5324. must be a string and replaces the `%s' specifier in the prefix format.
  5325. CATEGORY (string, symbol or nil) may be used to overrule the default
  5326. category taken from local variable or file name. It will replace the `%c'
  5327. specifier in the format. DOTIME, when non-nil, indicates that a
  5328. time-of-day should be extracted from TXT for sorting of this entry, and for
  5329. the `%t' specifier in the format. When DOTIME is a string, this string is
  5330. searched for a time before TXT is. TAGS can be the tags of the headline.
  5331. Any match of REMOVE-RE will be removed from TXT."
  5332. ;; We keep the org-prefix-* variable values along with a compiled
  5333. ;; formatter, so that multiple agendas existing at the same time, do
  5334. ;; not step on each other toes.
  5335. ;;
  5336. ;; It was inconvenient to make these variables buffer local in
  5337. ;; Agenda buffers, because this function expects to be called with
  5338. ;; the buffer where item comes from being current, and not agenda
  5339. ;; buffer
  5340. (let* ((bindings (car org-prefix-format-compiled))
  5341. (formatter (cadr org-prefix-format-compiled)))
  5342. (loop for (var value) in bindings
  5343. do (set var value))
  5344. (save-match-data
  5345. ;; Diary entries sometimes have extra whitespace at the beginning
  5346. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5347. ;; Fix the tags part in txt
  5348. (setq txt (org-agenda-fix-displayed-tags
  5349. txt tags
  5350. org-agenda-show-inherited-tags
  5351. org-agenda-hide-tags-regexp))
  5352. (let* ((category (or category
  5353. (if (stringp org-category)
  5354. org-category
  5355. (and org-category (symbol-name org-category)))
  5356. (if buffer-file-name
  5357. (file-name-sans-extension
  5358. (file-name-nondirectory buffer-file-name))
  5359. "")))
  5360. (category-icon (org-agenda-get-category-icon category))
  5361. (category-icon (if category-icon
  5362. (propertize " " 'display category-icon)
  5363. ""))
  5364. ;; time, tag, effort are needed for the eval of the prefix format
  5365. (tag (if tags (nth (1- (length tags)) tags) ""))
  5366. time effort neffort
  5367. (ts (if dotime (concat
  5368. (if (stringp dotime) dotime "")
  5369. (and org-agenda-search-headline-for-time txt))))
  5370. (time-of-day (and dotime (org-get-time-of-day ts)))
  5371. stamp plain s0 s1 s2 rtn srp l
  5372. duration thecategory)
  5373. (and (derived-mode-p 'org-mode) buffer-file-name
  5374. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5375. (when (and dotime time-of-day)
  5376. ;; Extract starting and ending time and move them to prefix
  5377. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5378. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5379. (setq s0 (match-string 0 ts)
  5380. srp (and stamp (match-end 3))
  5381. s1 (match-string (if plain 1 2) ts)
  5382. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5383. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5384. ;; them, we might want to remove them there to avoid duplication.
  5385. ;; The user can turn this off with a variable.
  5386. (if (and org-prefix-has-time
  5387. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5388. (string-match (concat (regexp-quote s0) " *") txt)
  5389. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5390. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5391. (= (match-beginning 0) 0)
  5392. t))
  5393. (setq txt (replace-match "" nil nil txt))))
  5394. ;; Normalize the time(s) to 24 hour
  5395. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5396. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5397. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5398. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5399. (setq s2
  5400. (org-minutes-to-hh:mm-string
  5401. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5402. ;; Compute the duration
  5403. (when s2
  5404. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5405. (org-hh:mm-string-to-minutes s1)))))
  5406. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5407. txt)
  5408. ;; Tags are in the string
  5409. (if (or (eq org-agenda-remove-tags t)
  5410. (and org-agenda-remove-tags
  5411. org-prefix-has-tag))
  5412. (setq txt (replace-match "" t t txt))
  5413. (setq txt (replace-match
  5414. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5415. (match-string 2 txt))
  5416. t t txt))))
  5417. (when (derived-mode-p 'org-mode)
  5418. (setq effort
  5419. (condition-case nil
  5420. (org-get-effort
  5421. (or (get-text-property 0 'org-hd-marker txt)
  5422. (get-text-property 0 'org-marker txt)))
  5423. (error nil)))
  5424. (when effort
  5425. (setq neffort (org-duration-string-to-minutes effort)
  5426. effort (setq effort (concat "[" effort "]")))))
  5427. ;; prevent erroring out with %e format when there is no effort
  5428. (or effort (setq effort ""))
  5429. (when remove-re
  5430. (while (string-match remove-re txt)
  5431. (setq txt (replace-match "" t t txt))))
  5432. ;; Set org-heading property on `txt' to mark the start of the
  5433. ;; heading.
  5434. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5435. ;; Prepare the variables needed in the eval of the compiled format
  5436. (setq time (cond (s2 (concat
  5437. (org-agenda-time-of-day-to-ampm-maybe s1)
  5438. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5439. (if org-agenda-timegrid-use-ampm " ")))
  5440. (s1 (concat
  5441. (org-agenda-time-of-day-to-ampm-maybe s1)
  5442. (if org-agenda-timegrid-use-ampm
  5443. "........ "
  5444. "......")))
  5445. (t ""))
  5446. extra (or (and (not habitp) extra) "")
  5447. category (if (symbolp category) (symbol-name category) category)
  5448. thecategory (copy-sequence category))
  5449. (if (string-match org-bracket-link-regexp category)
  5450. (progn
  5451. (setq l (if (match-end 3)
  5452. (- (match-end 3) (match-beginning 3))
  5453. (- (match-end 1) (match-beginning 1))))
  5454. (when (< l (or org-prefix-category-length 0))
  5455. (setq category (copy-sequence category))
  5456. (org-add-props category nil
  5457. 'extra-space (make-string
  5458. (- org-prefix-category-length l 1) ?\ ))))
  5459. (if (and org-prefix-category-max-length
  5460. (>= (length category) org-prefix-category-max-length))
  5461. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5462. ;; Evaluate the compiled format
  5463. (setq rtn (concat (eval formatter) txt))
  5464. ;; And finally add the text properties
  5465. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5466. (org-add-props rtn nil
  5467. 'org-category (if thecategory (downcase thecategory) category)
  5468. 'tags (mapcar 'org-downcase-keep-props tags)
  5469. 'org-highest-priority org-highest-priority
  5470. 'org-lowest-priority org-lowest-priority
  5471. 'time-of-day time-of-day
  5472. 'duration duration
  5473. 'effort effort
  5474. 'effort-minutes neffort
  5475. 'txt txt
  5476. 'time time
  5477. 'extra extra
  5478. 'format org-prefix-format-compiled
  5479. 'dotime dotime)))))
  5480. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5481. "Remove tags string from TXT, and add a modified list of tags.
  5482. The modified list may contain inherited tags, and tags matched by
  5483. `org-agenda-hide-tags-regexp' will be removed."
  5484. (when (or add-inherited hide-re)
  5485. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5486. (setq txt (substring txt 0 (match-beginning 0))))
  5487. (setq tags
  5488. (delq nil
  5489. (mapcar (lambda (tg)
  5490. (if (or (and hide-re (string-match hide-re tg))
  5491. (and (not add-inherited)
  5492. (get-text-property 0 'inherited tg)))
  5493. nil
  5494. tg))
  5495. tags)))
  5496. (when tags
  5497. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5498. i)
  5499. (setq txt (concat txt " :"
  5500. (mapconcat
  5501. (lambda (x)
  5502. (setq i (get-text-property 0 'inherited x))
  5503. (if (and have-i (not i))
  5504. (progn
  5505. (setq have-i nil)
  5506. (concat ":" x))
  5507. x))
  5508. tags ":")
  5509. (if have-i "::" ":"))))))
  5510. txt)
  5511. (defun org-downcase-keep-props (s)
  5512. (let ((props (text-properties-at 0 s)))
  5513. (setq s (downcase s))
  5514. (add-text-properties 0 (length s) props s)
  5515. s))
  5516. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5517. (defvar org-agenda-sorting-strategy-selected nil)
  5518. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5519. (catch 'exit
  5520. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5521. ((and todayp (member 'today (car org-agenda-time-grid))))
  5522. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5523. ((member 'weekly (car org-agenda-time-grid)))
  5524. (t (throw 'exit list)))
  5525. (let* ((have (delq nil (mapcar
  5526. (lambda (x) (get-text-property 1 'time-of-day x))
  5527. list)))
  5528. (string (nth 1 org-agenda-time-grid))
  5529. (gridtimes (nth 2 org-agenda-time-grid))
  5530. (req (car org-agenda-time-grid))
  5531. (remove (member 'remove-match req))
  5532. new time)
  5533. (if (and (member 'require-timed req) (not have))
  5534. ;; don't show empty grid
  5535. (throw 'exit list))
  5536. (while (setq time (pop gridtimes))
  5537. (unless (and remove (member time have))
  5538. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5539. (push (org-agenda-format-item
  5540. nil string "" nil
  5541. (concat (substring time 0 -2) ":" (substring time -2)))
  5542. new)
  5543. (put-text-property
  5544. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5545. (when (and todayp org-agenda-show-current-time-in-grid)
  5546. (push (org-agenda-format-item
  5547. nil
  5548. org-agenda-current-time-string
  5549. "" nil
  5550. (format-time-string "%H:%M "))
  5551. new)
  5552. (put-text-property
  5553. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5554. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5555. (append new list)
  5556. (append list new)))))
  5557. (defun org-compile-prefix-format (key)
  5558. "Compile the prefix format into a Lisp form that can be evaluated.
  5559. The resulting form and associated variable bindings is returned
  5560. and stored in the variable `org-prefix-format-compiled'."
  5561. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5562. org-prefix-category-length nil
  5563. org-prefix-has-effort nil)
  5564. (let ((s (cond
  5565. ((stringp org-agenda-prefix-format)
  5566. org-agenda-prefix-format)
  5567. ((assq key org-agenda-prefix-format)
  5568. (cdr (assq key org-agenda-prefix-format)))
  5569. (t " %-12:c%?-12t% s")))
  5570. (start 0)
  5571. varform vars var e c f opt)
  5572. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5573. s start)
  5574. (setq var (or (cdr (assoc (match-string 4 s)
  5575. '(("c" . category) ("t" . time) ("s" . extra)
  5576. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5577. 'eval)
  5578. c (or (match-string 3 s) "")
  5579. opt (match-beginning 1)
  5580. start (1+ (match-beginning 0)))
  5581. (if (equal var 'time) (setq org-prefix-has-time t))
  5582. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5583. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5584. (setq f (concat "%" (match-string 2 s) "s"))
  5585. (when (equal var 'category)
  5586. (setq org-prefix-category-length
  5587. (floor (abs (string-to-number (match-string 2 s)))))
  5588. (setq org-prefix-category-max-length
  5589. (let ((x (match-string 2 s)))
  5590. (save-match-data
  5591. (if (string-match "\\.[0-9]+" x)
  5592. (string-to-number (substring (match-string 0 x) 1)))))))
  5593. (if (eq var 'eval)
  5594. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5595. (if opt
  5596. (setq varform
  5597. `(if (equal "" ,var)
  5598. ""
  5599. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5600. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5601. (setq s (replace-match "%s" t nil s))
  5602. (push varform vars))
  5603. (setq vars (nreverse vars))
  5604. (with-current-buffer org-agenda-buffer
  5605. (setq org-prefix-format-compiled
  5606. (list
  5607. `((org-prefix-has-time ,org-prefix-has-time)
  5608. (org-prefix-has-tag ,org-prefix-has-tag)
  5609. (org-prefix-category-length ,org-prefix-category-length)
  5610. (org-prefix-has-effort ,org-prefix-has-effort))
  5611. `(format ,s ,@vars))))))
  5612. (defun org-set-sorting-strategy (key)
  5613. (if (symbolp (car org-agenda-sorting-strategy))
  5614. ;; the old format
  5615. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5616. (setq org-agenda-sorting-strategy-selected
  5617. (or (cdr (assq key org-agenda-sorting-strategy))
  5618. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5619. '(time-up category-keep priority-down)))))
  5620. (defun org-get-time-of-day (s &optional string mod24)
  5621. "Check string S for a time of day.
  5622. If found, return it as a military time number between 0 and 2400.
  5623. If not found, return nil.
  5624. The optional STRING argument forces conversion into a 5 character wide string
  5625. HH:MM."
  5626. (save-match-data
  5627. (when
  5628. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5629. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5630. (let* ((h (string-to-number (match-string 1 s)))
  5631. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5632. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5633. (am-p (equal ampm "am"))
  5634. (h1 (cond ((not ampm) h)
  5635. ((= h 12) (if am-p 0 12))
  5636. (t (+ h (if am-p 0 12)))))
  5637. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5638. (mod h1 24) h1))
  5639. (t0 (+ (* 100 h2) m))
  5640. (t1 (concat (if (>= h1 24) "+" " ")
  5641. (if (and org-agenda-time-leading-zero
  5642. (< t0 1000)) "0" "")
  5643. (if (< t0 100) "0" "")
  5644. (if (< t0 10) "0" "")
  5645. (int-to-string t0))))
  5646. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5647. (defvar org-agenda-before-sorting-filter-function nil
  5648. "Function to be applied to agenda items prior to sorting.
  5649. Prior to sorting also means just before they are inserted into the agenda.
  5650. To aid sorting, you may revisit the original entries and add more text
  5651. properties which will later be used by the sorting functions.
  5652. The function should take a string argument, an agenda line.
  5653. It has access to the text properties in that line, which contain among
  5654. other things, the property `org-hd-marker' that points to the entry
  5655. where the line comes from. Note that not all lines going into the agenda
  5656. have this property, only most.
  5657. The function should return the modified string. It is probably best
  5658. to ONLY change text properties.
  5659. You can also use this function as a filter, by returning nil for lines
  5660. you don't want to have in the agenda at all. For this application, you
  5661. could bind the variable in the options section of a custom command.")
  5662. (defun org-finalize-agenda-entries (list &optional nosort)
  5663. "Sort and concatenate the agenda items."
  5664. (setq list (mapcar 'org-agenda-highlight-todo list))
  5665. (if nosort
  5666. list
  5667. (when org-agenda-before-sorting-filter-function
  5668. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5669. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5670. (defun org-agenda-highlight-todo (x)
  5671. (let ((org-done-keywords org-done-keywords-for-agenda)
  5672. (case-fold-search nil)
  5673. re)
  5674. (if (eq x 'line)
  5675. (save-excursion
  5676. (beginning-of-line 1)
  5677. (setq re (org-get-at-bol 'org-todo-regexp))
  5678. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5679. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5680. (add-text-properties (match-beginning 0) (match-end 1)
  5681. (list 'face (org-get-todo-face 1)))
  5682. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5683. (delete-region (match-beginning 1) (1- (match-end 0)))
  5684. (goto-char (match-beginning 1))
  5685. (insert (format org-agenda-todo-keyword-format s)))))
  5686. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5687. (setq re (get-text-property 0 'org-todo-regexp x))
  5688. (when (and re
  5689. ;; Test `pl' because if there's no heading content,
  5690. ;; there's no point matching to highlight. Note
  5691. ;; that if we didn't test `pl' first, and there
  5692. ;; happened to be no keyword from `org-todo-regexp'
  5693. ;; on this heading line, then the `equal' comparison
  5694. ;; afterwards would spuriously succeed in the case
  5695. ;; where `pl' is nil -- causing an args-out-of-range
  5696. ;; error when we try to add text properties to text
  5697. ;; that isn't there.
  5698. pl
  5699. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5700. x pl) pl))
  5701. (add-text-properties
  5702. (or (match-end 1) (match-end 0)) (match-end 0)
  5703. (list 'face (org-get-todo-face (match-string 2 x)))
  5704. x)
  5705. (when (match-end 1)
  5706. (setq x (concat (substring x 0 (match-end 1))
  5707. (format org-agenda-todo-keyword-format
  5708. (match-string 2 x))
  5709. (org-add-props " " (text-properties-at 0 x))
  5710. (substring x (match-end 3)))))))
  5711. x)))
  5712. (defsubst org-cmp-priority (a b)
  5713. "Compare the priorities of string A and B."
  5714. (let ((pa (or (get-text-property 1 'priority a) 0))
  5715. (pb (or (get-text-property 1 'priority b) 0)))
  5716. (cond ((> pa pb) +1)
  5717. ((< pa pb) -1)
  5718. (t nil))))
  5719. (defsubst org-cmp-effort (a b)
  5720. "Compare the effort values of string A and B."
  5721. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5722. (ea (or (get-text-property 1 'effort-minutes a) def))
  5723. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5724. (cond ((> ea eb) +1)
  5725. ((< ea eb) -1)
  5726. (t nil))))
  5727. (defsubst org-cmp-category (a b)
  5728. "Compare the string values of categories of strings A and B."
  5729. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5730. (cb (or (get-text-property 1 'org-category b) "")))
  5731. (cond ((string-lessp ca cb) -1)
  5732. ((string-lessp cb ca) +1)
  5733. (t nil))))
  5734. (defsubst org-cmp-todo-state (a b)
  5735. "Compare the todo states of strings A and B."
  5736. (let* ((ma (or (get-text-property 1 'org-marker a)
  5737. (get-text-property 1 'org-hd-marker a)))
  5738. (mb (or (get-text-property 1 'org-marker b)
  5739. (get-text-property 1 'org-hd-marker b)))
  5740. (fa (and ma (marker-buffer ma)))
  5741. (fb (and mb (marker-buffer mb)))
  5742. (todo-kwds
  5743. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5744. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5745. (ta (or (get-text-property 1 'todo-state a) ""))
  5746. (tb (or (get-text-property 1 'todo-state b) ""))
  5747. (la (- (length (member ta todo-kwds))))
  5748. (lb (- (length (member tb todo-kwds))))
  5749. (donepa (member ta org-done-keywords-for-agenda))
  5750. (donepb (member tb org-done-keywords-for-agenda)))
  5751. (cond ((and donepa (not donepb)) -1)
  5752. ((and (not donepa) donepb) +1)
  5753. ((< la lb) -1)
  5754. ((< lb la) +1)
  5755. (t nil))))
  5756. (defsubst org-cmp-alpha (a b)
  5757. "Compare the headlines, alphabetically."
  5758. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5759. (plb (text-property-any 0 (length b) 'org-heading t b))
  5760. (ta (and pla (substring a pla)))
  5761. (tb (and plb (substring b plb))))
  5762. (when pla
  5763. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5764. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5765. (setq ta (substring ta (match-end 0))))
  5766. (setq ta (downcase ta)))
  5767. (when plb
  5768. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5769. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5770. (setq tb (substring tb (match-end 0))))
  5771. (setq tb (downcase tb)))
  5772. (cond ((not ta) +1)
  5773. ((not tb) -1)
  5774. ((string-lessp ta tb) -1)
  5775. ((string-lessp tb ta) +1)
  5776. (t nil))))
  5777. (defsubst org-cmp-tag (a b)
  5778. "Compare the string values of the first tags of A and B."
  5779. (let ((ta (car (last (get-text-property 1 'tags a))))
  5780. (tb (car (last (get-text-property 1 'tags b)))))
  5781. (cond ((not ta) +1)
  5782. ((not tb) -1)
  5783. ((string-lessp ta tb) -1)
  5784. ((string-lessp tb ta) +1)
  5785. (t nil))))
  5786. (defsubst org-cmp-time (a b)
  5787. "Compare the time-of-day values of strings A and B."
  5788. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5789. (ta (or (get-text-property 1 'time-of-day a) def))
  5790. (tb (or (get-text-property 1 'time-of-day b) def)))
  5791. (cond ((< ta tb) -1)
  5792. ((< tb ta) +1)
  5793. (t nil))))
  5794. (defsubst org-cmp-habit-p (a b)
  5795. "Compare the todo states of strings A and B."
  5796. (let ((ha (get-text-property 1 'org-habit-p a))
  5797. (hb (get-text-property 1 'org-habit-p b)))
  5798. (cond ((and ha (not hb)) -1)
  5799. ((and (not ha) hb) +1)
  5800. (t nil))))
  5801. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5802. (defun org-entries-lessp (a b)
  5803. "Predicate for sorting agenda entries."
  5804. ;; The following variables will be used when the form is evaluated.
  5805. ;; So even though the compiler complains, keep them.
  5806. (let* ((ss org-agenda-sorting-strategy-selected)
  5807. (time-up (and (org-em 'time-up 'time-down ss)
  5808. (org-cmp-time a b)))
  5809. (time-down (if time-up (- time-up) nil))
  5810. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5811. (org-cmp-priority a b)))
  5812. (priority-down (if priority-up (- priority-up) nil))
  5813. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5814. (org-cmp-effort a b)))
  5815. (effort-down (if effort-up (- effort-up) nil))
  5816. (category-up (and (or (org-em 'category-up 'category-down ss)
  5817. (memq 'category-keep ss))
  5818. (org-cmp-category a b)))
  5819. (category-down (if category-up (- category-up) nil))
  5820. (category-keep (if category-up +1 nil))
  5821. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5822. (org-cmp-tag a b)))
  5823. (tag-down (if tag-up (- tag-up) nil))
  5824. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5825. (org-cmp-todo-state a b)))
  5826. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5827. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5828. (org-cmp-habit-p a b)))
  5829. (habit-down (if habit-up (- habit-up) nil))
  5830. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5831. (org-cmp-alpha a b)))
  5832. (alpha-down (if alpha-up (- alpha-up) nil))
  5833. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5834. user-defined-up user-defined-down)
  5835. (if (and need-user-cmp org-agenda-cmp-user-defined
  5836. (functionp org-agenda-cmp-user-defined))
  5837. (setq user-defined-up
  5838. (funcall org-agenda-cmp-user-defined a b)
  5839. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5840. (cdr (assoc
  5841. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5842. '((-1 . t) (1 . nil) (nil . nil))))))
  5843. ;;; Agenda restriction lock
  5844. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5845. "Overlay to mark the headline to which agenda commands are restricted.")
  5846. (overlay-put org-agenda-restriction-lock-overlay
  5847. 'face 'org-agenda-restriction-lock)
  5848. (overlay-put org-agenda-restriction-lock-overlay
  5849. 'help-echo "Agendas are currently limited to this subtree.")
  5850. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5851. (defun org-agenda-set-restriction-lock (&optional type)
  5852. "Set restriction lock for agenda, to current subtree or file.
  5853. Restriction will be the file if TYPE is `file', or if type is the
  5854. universal prefix '(4), or if the cursor is before the first headline
  5855. in the file. Otherwise, restriction will be to the current subtree."
  5856. (interactive "P")
  5857. (and (equal type '(4)) (setq type 'file))
  5858. (setq type (cond
  5859. (type type)
  5860. ((org-at-heading-p) 'subtree)
  5861. ((condition-case nil (org-back-to-heading t) (error nil))
  5862. 'subtree)
  5863. (t 'file)))
  5864. (if (eq type 'subtree)
  5865. (progn
  5866. (setq org-agenda-restrict t)
  5867. (setq org-agenda-overriding-restriction 'subtree)
  5868. (put 'org-agenda-files 'org-restrict
  5869. (list (buffer-file-name (buffer-base-buffer))))
  5870. (org-back-to-heading t)
  5871. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5872. (move-marker org-agenda-restrict-begin (point))
  5873. (move-marker org-agenda-restrict-end
  5874. (save-excursion (org-end-of-subtree t)))
  5875. (message "Locking agenda restriction to subtree"))
  5876. (put 'org-agenda-files 'org-restrict
  5877. (list (buffer-file-name (buffer-base-buffer))))
  5878. (setq org-agenda-restrict nil)
  5879. (setq org-agenda-overriding-restriction 'file)
  5880. (move-marker org-agenda-restrict-begin nil)
  5881. (move-marker org-agenda-restrict-end nil)
  5882. (message "Locking agenda restriction to file"))
  5883. (setq current-prefix-arg nil)
  5884. (org-agenda-maybe-redo))
  5885. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5886. "Remove the agenda restriction lock."
  5887. (interactive "P")
  5888. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5889. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5890. (setq org-agenda-overriding-restriction nil)
  5891. (setq org-agenda-restrict nil)
  5892. (put 'org-agenda-files 'org-restrict nil)
  5893. (move-marker org-agenda-restrict-begin nil)
  5894. (move-marker org-agenda-restrict-end nil)
  5895. (setq current-prefix-arg nil)
  5896. (message "Agenda restriction lock removed")
  5897. (or noupdate (org-agenda-maybe-redo)))
  5898. (defun org-agenda-maybe-redo ()
  5899. "If there is any window showing the agenda view, update it."
  5900. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5901. (w0 (selected-window)))
  5902. (when w
  5903. (select-window w)
  5904. (org-agenda-redo)
  5905. (select-window w0)
  5906. (if org-agenda-overriding-restriction
  5907. (message "Agenda view shifted to new %s restriction"
  5908. org-agenda-overriding-restriction)
  5909. (message "Agenda restriction lock removed")))))
  5910. ;;; Agenda commands
  5911. (defun org-agenda-check-type (error &rest types)
  5912. "Check if agenda buffer is of allowed type.
  5913. If ERROR is non-nil, throw an error, otherwise just return nil."
  5914. (if (memq org-agenda-type types)
  5915. t
  5916. (if error
  5917. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5918. nil)))
  5919. (defun org-agenda-Quit (&optional arg)
  5920. "Exit agenda by removing the window or the buffer"
  5921. (interactive)
  5922. (if org-agenda-columns-active
  5923. (org-columns-quit)
  5924. (let ((buf (current-buffer)))
  5925. (if (eq org-agenda-window-setup 'other-frame)
  5926. (progn
  5927. (org-agenda-reset-markers)
  5928. (kill-buffer buf)
  5929. (org-columns-remove-overlays)
  5930. (setq org-agenda-archives-mode nil)
  5931. (delete-frame))
  5932. (and (not (eq org-agenda-window-setup 'current-window))
  5933. (not (one-window-p))
  5934. (delete-window))
  5935. (org-agenda-reset-markers)
  5936. (kill-buffer buf)
  5937. (org-columns-remove-overlays)
  5938. (setq org-agenda-archives-mode nil)))
  5939. ;; Maybe restore the pre-agenda window configuration.
  5940. (and org-agenda-restore-windows-after-quit
  5941. (not (eq org-agenda-window-setup 'other-frame))
  5942. org-pre-agenda-window-conf
  5943. (set-window-configuration org-pre-agenda-window-conf))))
  5944. (defun org-agenda-quit ()
  5945. "Exit agenda by killing agenda buffer or burying it when
  5946. `org-agenda-sticky' is non-NIL"
  5947. (interactive)
  5948. (if org-agenda-columns-active
  5949. (org-columns-quit)
  5950. (if org-agenda-sticky
  5951. (let ((buf (current-buffer)))
  5952. (if (eq org-agenda-window-setup 'other-frame)
  5953. (progn
  5954. (delete-frame))
  5955. (and (not (eq org-agenda-window-setup 'current-window))
  5956. (not (one-window-p))
  5957. (delete-window)))
  5958. (with-current-buffer buf
  5959. (bury-buffer)
  5960. ;; Maybe restore the pre-agenda window configuration.
  5961. (and org-agenda-restore-windows-after-quit
  5962. (not (eq org-agenda-window-setup 'other-frame))
  5963. org-pre-agenda-window-conf
  5964. (set-window-configuration org-pre-agenda-window-conf))))
  5965. (org-agenda-Quit))))
  5966. (defun org-agenda-exit ()
  5967. "Exit agenda by removing the window or the buffer.
  5968. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5969. Org-mode buffers visited directly by the user will not be touched."
  5970. (interactive)
  5971. (org-release-buffers org-agenda-new-buffers)
  5972. (setq org-agenda-new-buffers nil)
  5973. (org-agenda-Quit))
  5974. (defun org-agenda-kill-all-agenda-buffers ()
  5975. "Kill all buffers in `org-agena-mode'.
  5976. This is used when toggling sticky agendas. You can also explicitly invoke it
  5977. with `C-c a C-k'."
  5978. (interactive)
  5979. (let (blist)
  5980. (dolist (buf (buffer-list))
  5981. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5982. (push buf blist)))
  5983. (mapc 'kill-buffer blist)))
  5984. (defun org-agenda-execute (arg)
  5985. "Execute another agenda command, keeping same window.
  5986. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5987. in the agenda."
  5988. (interactive "P")
  5989. (let ((org-agenda-window-setup 'current-window))
  5990. (org-agenda arg)))
  5991. (defun org-agenda-redo ()
  5992. "Rebuild Agenda.
  5993. When this is the global TODO list, a prefix argument will be interpreted."
  5994. (interactive)
  5995. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  5996. (org-agenda-sticky nil)
  5997. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  5998. org-agenda-buffer-name))
  5999. (org-agenda-keep-modes t)
  6000. (tag-filter org-agenda-tag-filter)
  6001. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6002. (top-cat-filter org-agenda-top-category-filter)
  6003. (cat-filter org-agenda-category-filter)
  6004. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6005. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6006. (cols org-agenda-columns-active)
  6007. (line (org-current-line))
  6008. (window-line (- line (org-current-line (window-start))))
  6009. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  6010. (put 'org-agenda-tag-filter :preset-filter nil)
  6011. (put 'org-agenda-category-filter :preset-filter nil)
  6012. (and cols (org-columns-quit))
  6013. (message "Rebuilding agenda buffer...")
  6014. (org-let lprops '(eval org-agenda-redo-command))
  6015. (setq org-agenda-undo-list nil
  6016. org-agenda-pending-undo-list nil)
  6017. (message "Rebuilding agenda buffer...done")
  6018. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6019. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6020. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6021. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6022. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6023. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6024. (org-goto-line line)
  6025. (recenter window-line)))
  6026. (defvar org-global-tags-completion-table nil)
  6027. (defvar org-agenda-filter-form nil)
  6028. (defvar org-agenda-filtered-by-category nil)
  6029. (defun org-agenda-filter-by-category (strip)
  6030. "Keep only those lines in the agenda buffer that have a specific category.
  6031. The category is that of the current line."
  6032. (interactive "P")
  6033. (if org-agenda-filtered-by-category
  6034. (org-agenda-filter-show-all-cat)
  6035. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6036. (if cat (org-agenda-filter-apply
  6037. (list (concat (if strip "-" "+") cat)) 'category)
  6038. (error "No category at point")))))
  6039. (defun org-find-top-category (&optional pos)
  6040. (save-excursion
  6041. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6042. (if pos (goto-char pos))
  6043. ;; Skip up to the topmost parent
  6044. (while (ignore-errors (outline-up-heading 1) t))
  6045. (ignore-errors
  6046. (nth 4 (org-heading-components))))))
  6047. (defvar org-agenda-filtered-by-top-category nil)
  6048. (defun org-agenda-filter-by-top-category (strip)
  6049. "Keep only those lines in the agenda buffer that have a specific category.
  6050. The category is that of the current line."
  6051. (interactive "P")
  6052. (if org-agenda-filtered-by-top-category
  6053. (progn
  6054. (setq org-agenda-filtered-by-top-category nil
  6055. org-agenda-top-category-filter nil)
  6056. (org-agenda-filter-show-all-cat))
  6057. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6058. (if cat (org-agenda-filter-top-category-apply cat strip)
  6059. (error "No top-level category at point")))))
  6060. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6061. "Keep only those lines in the agenda buffer that have a specific tag.
  6062. The tag is selected with its fast selection letter, as configured.
  6063. With prefix argument STRIP, remove all lines that do have the tag.
  6064. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6065. used to narrow the search - the interactive user can also press `-' or `+'
  6066. to switch to narrowing."
  6067. (interactive "P")
  6068. (let* ((alist org-tag-alist-for-agenda)
  6069. (tag-chars (mapconcat
  6070. (lambda (x) (if (and (not (symbolp (car x)))
  6071. (cdr x))
  6072. (char-to-string (cdr x))
  6073. ""))
  6074. alist ""))
  6075. (efforts (org-split-string
  6076. (or (cdr (assoc (concat org-effort-property "_ALL")
  6077. org-global-properties))
  6078. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6079. "")))
  6080. (effort-op org-agenda-filter-effort-default-operator)
  6081. (effort-prompt "")
  6082. (inhibit-read-only t)
  6083. (current org-agenda-tag-filter)
  6084. maybe-refresh a n tag)
  6085. (unless char
  6086. (message
  6087. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6088. (if narrow "Narrow" "Filter") tag-chars
  6089. (if org-agenda-auto-exclude-function "[RET], " ""))
  6090. (setq char (read-char-exclusive)))
  6091. (when (member char '(?+ ?-))
  6092. ;; Narrowing down
  6093. (cond ((equal char ?-) (setq strip t narrow t))
  6094. ((equal char ?+) (setq strip nil narrow t)))
  6095. (message
  6096. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6097. (setq char (read-char-exclusive)))
  6098. (when (member char '(?< ?> ?= ??))
  6099. ;; An effort operator
  6100. (setq effort-op (char-to-string char))
  6101. (setq alist nil) ; to make sure it will be interpreted as effort.
  6102. (unless (equal char ??)
  6103. (loop for i from 0 to 9 do
  6104. (setq effort-prompt
  6105. (concat
  6106. effort-prompt " ["
  6107. (if (= i 9) "0" (int-to-string (1+ i)))
  6108. "]" (nth i efforts))))
  6109. (message "Effort%s: %s " effort-op effort-prompt)
  6110. (setq char (read-char-exclusive))
  6111. (when (or (< char ?0) (> char ?9))
  6112. (error "Need 1-9,0 to select effort"))))
  6113. (when (equal char ?\t)
  6114. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6115. (org-set-local 'org-global-tags-completion-table
  6116. (org-global-tags-completion-table)))
  6117. (let ((completion-ignore-case t))
  6118. (setq tag (org-icompleting-read
  6119. "Tag: " org-global-tags-completion-table))))
  6120. (cond
  6121. ((equal char ?\r)
  6122. (org-agenda-filter-show-all-tag)
  6123. (when org-agenda-auto-exclude-function
  6124. (setq org-agenda-tag-filter '())
  6125. (dolist (tag (org-agenda-get-represented-tags))
  6126. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6127. (if modifier
  6128. (push modifier org-agenda-tag-filter))))
  6129. (if (not (null org-agenda-tag-filter))
  6130. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6131. (setq maybe-refresh t))
  6132. ((equal char ?/)
  6133. (org-agenda-filter-show-all-tag)
  6134. (when (get 'org-agenda-tag-filter :preset-filter)
  6135. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6136. (setq maybe-refresh t))
  6137. ((equal char ?. )
  6138. (setq org-agenda-tag-filter
  6139. (mapcar (lambda(tag) (concat "+" tag))
  6140. (org-get-at-bol 'tags)))
  6141. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6142. (setq maybe-refresh t))
  6143. ((or (equal char ?\ )
  6144. (setq a (rassoc char alist))
  6145. (and (>= char ?0) (<= char ?9)
  6146. (setq n (if (= char ?0) 9 (- char ?0 1))
  6147. tag (concat effort-op (nth n efforts))
  6148. a (cons tag nil)))
  6149. (and (= char ??)
  6150. (setq tag "?eff")
  6151. a (cons tag nil))
  6152. (and tag (setq a (cons tag nil))))
  6153. (org-agenda-filter-show-all-tag)
  6154. (setq tag (car a))
  6155. (setq org-agenda-tag-filter
  6156. (cons (concat (if strip "-" "+") tag)
  6157. (if narrow current nil)))
  6158. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6159. (setq maybe-refresh t))
  6160. (t (error "Invalid tag selection character %c" char)))
  6161. (when (and maybe-refresh
  6162. (eq org-agenda-clockreport-mode 'with-filter))
  6163. (org-agenda-redo))))
  6164. (defun org-agenda-get-represented-tags ()
  6165. "Get a list of all tags currently represented in the agenda."
  6166. (let (p tags)
  6167. (save-excursion
  6168. (goto-char (point-min))
  6169. (while (setq p (next-single-property-change (point) 'tags))
  6170. (goto-char p)
  6171. (mapc (lambda (x) (add-to-list 'tags x))
  6172. (get-text-property (point) 'tags))))
  6173. tags))
  6174. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6175. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6176. (interactive "P")
  6177. (org-agenda-filter-by-tag strip char 'refine))
  6178. (defun org-agenda-filter-make-matcher ()
  6179. "Create the form that tests a line for agenda filter."
  6180. (let (f f1)
  6181. ;; first compute the tag-filter matcher
  6182. (dolist (x (delete-dups
  6183. (append (get 'org-agenda-tag-filter
  6184. :preset-filter) org-agenda-tag-filter)))
  6185. (if (member x '("-" "+"))
  6186. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6187. (if (string-match "[<=>?]" x)
  6188. (setq f1 (org-agenda-filter-effort-form x))
  6189. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6190. (if (equal (string-to-char x) ?-)
  6191. (setq f1 (list 'not f1))))
  6192. (push f1 f))
  6193. ;; then compute the category-filter matcher
  6194. (dolist (x (delete-dups
  6195. (append (get 'org-agenda-category-filter
  6196. :preset-filter) org-agenda-category-filter)))
  6197. (if (equal "-" (substring x 0 1))
  6198. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6199. (setq f1 (list 'equal (substring x 1) 'cat)))
  6200. (push f1 f))
  6201. (cons 'and (nreverse f))))
  6202. (defun org-agenda-filter-effort-form (e)
  6203. "Return the form to compare the effort of the current line with what E says.
  6204. E looks like \"+<2:25\"."
  6205. (let (op)
  6206. (setq e (substring e 1))
  6207. (setq op (string-to-char e) e (substring e 1))
  6208. (setq op (cond ((equal op ?<) '<=)
  6209. ((equal op ?>) '>=)
  6210. ((equal op ??) op)
  6211. (t '=)))
  6212. (list 'org-agenda-compare-effort (list 'quote op)
  6213. (org-duration-string-to-minutes e))))
  6214. (defun org-agenda-compare-effort (op value)
  6215. "Compare the effort of the current line with VALUE, using OP.
  6216. If the line does not have an effort defined, return nil."
  6217. (let ((eff (org-get-at-bol 'effort-minutes)))
  6218. (if (equal op ??)
  6219. (not eff)
  6220. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6221. value))))
  6222. (defun org-agenda-filter-apply (filter type)
  6223. "Set FILTER as the new agenda filter and apply it."
  6224. (let (tags cat)
  6225. (if (eq type 'tag)
  6226. (setq org-agenda-tag-filter filter)
  6227. (setq org-agenda-category-filter filter))
  6228. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6229. (if (and (eq type 'category)
  6230. (not (equal (substring (car filter) 0 1) "-")))
  6231. ;; Only set `org-agenda-filtered-by-category' to t
  6232. ;; when a unique category is used as the filter
  6233. (setq org-agenda-filtered-by-category t))
  6234. (org-agenda-set-mode-name)
  6235. (save-excursion
  6236. (goto-char (point-min))
  6237. (while (not (eobp))
  6238. (if (org-get-at-bol 'org-marker)
  6239. (progn
  6240. (setq tags (org-get-at-bol 'tags) ; used in eval
  6241. cat (get-text-property (point) 'org-category))
  6242. (if (not (eval org-agenda-filter-form))
  6243. (org-agenda-filter-hide-line type))
  6244. (beginning-of-line 2))
  6245. (beginning-of-line 2))))
  6246. (if (get-char-property (point) 'invisible)
  6247. (ignore-errors (org-agenda-previous-line)))))
  6248. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6249. "Set FILTER as the new agenda filter and apply it."
  6250. (org-agenda-set-mode-name)
  6251. (save-excursion
  6252. (goto-char (point-min))
  6253. (while (not (eobp))
  6254. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6255. (topcat (and pos (org-find-top-category pos))))
  6256. (if (and topcat (funcall (if negative 'identity 'not)
  6257. (string= category topcat)))
  6258. (org-agenda-filter-hide-line 'category)))
  6259. (beginning-of-line 2)))
  6260. (if (get-char-property (point) 'invisible)
  6261. (org-agenda-previous-line))
  6262. (setq org-agenda-top-category-filter category
  6263. org-agenda-filtered-by-top-category t))
  6264. (defun org-agenda-filter-hide-line (type)
  6265. (let (ov)
  6266. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6267. (point-at-eol)))
  6268. (overlay-put ov 'invisible t)
  6269. (overlay-put ov 'type type)
  6270. (if (eq type 'tag)
  6271. (push ov org-agenda-tag-filter-overlays)
  6272. (push ov org-agenda-cat-filter-overlays))))
  6273. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6274. (setq pos (or pos (point)))
  6275. (save-excursion
  6276. (dolist (ov (overlays-at pos))
  6277. (when (and (overlay-get ov 'invisible)
  6278. (eq (overlay-get ov 'type) 'tag))
  6279. (goto-char pos)
  6280. (if (< (overlay-start ov) (point-at-eol))
  6281. (move-overlay ov (point-at-eol)
  6282. (overlay-end ov)))))))
  6283. (defun org-agenda-filter-show-all-tag nil
  6284. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6285. (setq org-agenda-tag-filter-overlays nil
  6286. org-agenda-tag-filter nil
  6287. org-agenda-filter-form nil)
  6288. (org-agenda-set-mode-name))
  6289. (defun org-agenda-filter-show-all-cat nil
  6290. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6291. (setq org-agenda-cat-filter-overlays nil
  6292. org-agenda-filtered-by-category nil
  6293. org-agenda-category-filter nil
  6294. org-agenda-filter-form nil)
  6295. (org-agenda-set-mode-name))
  6296. (defun org-agenda-manipulate-query-add ()
  6297. "Manipulate the query by adding a search term with positive selection.
  6298. Positive selection means the term must be matched for selection of an entry."
  6299. (interactive)
  6300. (org-agenda-manipulate-query ?\[))
  6301. (defun org-agenda-manipulate-query-subtract ()
  6302. "Manipulate the query by adding a search term with negative selection.
  6303. Negative selection means term must not be matched for selection of an entry."
  6304. (interactive)
  6305. (org-agenda-manipulate-query ?\]))
  6306. (defun org-agenda-manipulate-query-add-re ()
  6307. "Manipulate the query by adding a search regexp with positive selection.
  6308. Positive selection means the regexp must match for selection of an entry."
  6309. (interactive)
  6310. (org-agenda-manipulate-query ?\{))
  6311. (defun org-agenda-manipulate-query-subtract-re ()
  6312. "Manipulate the query by adding a search regexp with negative selection.
  6313. Negative selection means regexp must not match for selection of an entry."
  6314. (interactive)
  6315. (org-agenda-manipulate-query ?\}))
  6316. (defun org-agenda-manipulate-query (char)
  6317. (cond
  6318. ((memq org-agenda-type '(timeline agenda))
  6319. (let ((org-agenda-include-inactive-timestamps t))
  6320. (org-agenda-redo))
  6321. (message "Display now includes inactive timestamps as well"))
  6322. ((eq org-agenda-type 'search)
  6323. (org-add-to-string
  6324. 'org-agenda-query-string
  6325. (if org-agenda-last-search-view-search-was-boolean
  6326. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6327. (?\{ . " +{}") (?\} . " -{}"))))
  6328. " "))
  6329. (setq org-agenda-redo-command
  6330. (list 'org-search-view
  6331. org-todo-only
  6332. org-agenda-query-string
  6333. (+ (length org-agenda-query-string)
  6334. (if (member char '(?\{ ?\})) 0 1))))
  6335. (set-register org-agenda-query-register org-agenda-query-string)
  6336. (org-agenda-redo))
  6337. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6338. org-agenda-type))))
  6339. (defun org-add-to-string (var string)
  6340. (set var (concat (symbol-value var) string)))
  6341. (defun org-agenda-goto-date (date)
  6342. "Jump to DATE in agenda."
  6343. (interactive (list (let ((org-read-date-prefer-future
  6344. (eval org-agenda-jump-prefer-future)))
  6345. (org-read-date))))
  6346. (org-agenda-list nil date))
  6347. (defun org-agenda-goto-today ()
  6348. "Go to today."
  6349. (interactive)
  6350. (org-agenda-check-type t 'timeline 'agenda)
  6351. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6352. (cond
  6353. (tdpos (goto-char tdpos))
  6354. ((eq org-agenda-type 'agenda)
  6355. (let* ((sd (org-agenda-compute-starting-span
  6356. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6357. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6358. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6359. (org-agenda-redo)
  6360. (org-agenda-find-same-or-today-or-agenda)))
  6361. (t (error "Cannot find today")))))
  6362. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6363. (goto-char
  6364. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6365. (text-property-any (point-min) (point-max) 'org-today t)
  6366. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6367. (point-min))))
  6368. (defun org-agenda-later (arg)
  6369. "Go forward in time by thee current span.
  6370. With prefix ARG, go forward that many times the current span."
  6371. (interactive "p")
  6372. (org-agenda-check-type t 'agenda)
  6373. (let* ((span org-agenda-current-span)
  6374. (sd org-starting-day)
  6375. (greg (calendar-gregorian-from-absolute sd))
  6376. (cnt (org-get-at-bol 'org-day-cnt))
  6377. greg2)
  6378. (cond
  6379. ((eq span 'day)
  6380. (setq sd (+ arg sd)))
  6381. ((eq span 'week)
  6382. (setq sd (+ (* 7 arg) sd)))
  6383. ((eq span 'month)
  6384. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6385. sd (calendar-absolute-from-gregorian greg2))
  6386. (setcar greg2 (1+ (car greg2))))
  6387. ((eq span 'year)
  6388. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6389. sd (calendar-absolute-from-gregorian greg2))
  6390. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6391. (t
  6392. (setq sd (+ (* span arg) sd))))
  6393. (let ((org-agenda-overriding-arguments
  6394. (list (car org-agenda-last-arguments) sd span t)))
  6395. (org-agenda-redo)
  6396. (org-agenda-find-same-or-today-or-agenda cnt))))
  6397. (defun org-agenda-earlier (arg)
  6398. "Go backward in time by the current span.
  6399. With prefix ARG, go backward that many times the current span."
  6400. (interactive "p")
  6401. (org-agenda-later (- arg)))
  6402. (defun org-agenda-view-mode-dispatch ()
  6403. "Call one of the view mode commands."
  6404. (interactive)
  6405. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6406. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6407. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6408. (let ((a (read-char-exclusive)))
  6409. (case a
  6410. (?\ (call-interactively 'org-agenda-reset-view))
  6411. (?d (call-interactively 'org-agenda-day-view))
  6412. (?w (call-interactively 'org-agenda-week-view))
  6413. (?m (call-interactively 'org-agenda-month-view))
  6414. (?y (call-interactively 'org-agenda-year-view))
  6415. (?l (call-interactively 'org-agenda-log-mode))
  6416. (?L (org-agenda-log-mode '(4)))
  6417. (?c (org-agenda-log-mode 'clockcheck))
  6418. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6419. (?a (call-interactively 'org-agenda-archives-mode))
  6420. (?A (org-agenda-archives-mode 'files))
  6421. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6422. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6423. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6424. (?D (call-interactively 'org-agenda-toggle-diary))
  6425. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6426. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6427. (org-agenda-check-type t 'timeline 'agenda)
  6428. (org-agenda-redo))
  6429. (message "Display now includes inactive timestamps as well"))
  6430. (?q (message "Abort"))
  6431. (otherwise (error "Invalid key" )))))
  6432. (defun org-agenda-reset-view ()
  6433. "Switch to default view for agenda."
  6434. (interactive)
  6435. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6436. (defun org-agenda-day-view (&optional day-of-year)
  6437. "Switch to daily view for agenda.
  6438. With argument DAY-OF-YEAR, switch to that day of the year."
  6439. (interactive "P")
  6440. (org-agenda-change-time-span 'day day-of-year))
  6441. (defun org-agenda-week-view (&optional iso-week)
  6442. "Switch to daily view for agenda.
  6443. With argument ISO-WEEK, switch to the corresponding ISO week.
  6444. If ISO-WEEK has more then 2 digits, only the last two encode the
  6445. week. Any digits before this encode a year. So 200712 means
  6446. week 12 of year 2007. Years in the range 1938-2037 can also be
  6447. written as 2-digit years."
  6448. (interactive "P")
  6449. (org-agenda-change-time-span 'week iso-week))
  6450. (defun org-agenda-month-view (&optional month)
  6451. "Switch to monthly view for agenda.
  6452. With argument MONTH, switch to that month."
  6453. (interactive "P")
  6454. (org-agenda-change-time-span 'month month))
  6455. (defun org-agenda-year-view (&optional year)
  6456. "Switch to yearly view for agenda.
  6457. With argument YEAR, switch to that year.
  6458. If MONTH has more then 2 digits, only the last two encode the
  6459. month. Any digits before this encode a year. So 200712 means
  6460. December year 2007. Years in the range 1938-2037 can also be
  6461. written as 2-digit years."
  6462. (interactive "P")
  6463. (when year
  6464. (setq year (org-small-year-to-year year)))
  6465. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6466. (org-agenda-change-time-span 'year year)
  6467. (error "Abort")))
  6468. (defun org-agenda-change-time-span (span &optional n)
  6469. "Change the agenda view to SPAN.
  6470. SPAN may be `day', `week', `month', `year'."
  6471. (org-agenda-check-type t 'agenda)
  6472. (if (and (not n) (equal org-agenda-current-span span))
  6473. (error "Viewing span is already \"%s\"" span))
  6474. (let* ((sd (or (org-get-at-bol 'day)
  6475. org-starting-day))
  6476. (sd (org-agenda-compute-starting-span sd span n))
  6477. (org-agenda-overriding-arguments
  6478. (or org-agenda-overriding-arguments
  6479. (list (car org-agenda-last-arguments) sd span t))))
  6480. (org-agenda-redo)
  6481. (org-agenda-find-same-or-today-or-agenda))
  6482. (org-agenda-set-mode-name)
  6483. (message "Switched to %s view" span))
  6484. (defun org-agenda-compute-starting-span (sd span &optional n)
  6485. "Compute starting date for agenda.
  6486. SPAN may be `day', `week', `month', `year'. The return value
  6487. is a cons cell with the starting date and the number of days,
  6488. so that the date SD will be in that range."
  6489. (let* ((greg (calendar-gregorian-from-absolute sd))
  6490. (dg (nth 1 greg))
  6491. (mg (car greg))
  6492. (yg (nth 2 greg)))
  6493. (cond
  6494. ((eq span 'day)
  6495. (when n
  6496. (setq sd (+ (calendar-absolute-from-gregorian
  6497. (list mg 1 yg))
  6498. n -1))))
  6499. ((eq span 'week)
  6500. (let* ((nt (calendar-day-of-week
  6501. (calendar-gregorian-from-absolute sd)))
  6502. (d (if org-agenda-start-on-weekday
  6503. (- nt org-agenda-start-on-weekday)
  6504. 0))
  6505. y1)
  6506. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6507. (when n
  6508. (require 'cal-iso)
  6509. (when (> n 99)
  6510. (setq y1 (org-small-year-to-year (/ n 100))
  6511. n (mod n 100)))
  6512. (setq sd
  6513. (calendar-absolute-from-iso
  6514. (list n 1
  6515. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6516. ((eq span 'month)
  6517. (let (y1)
  6518. (when (and n (> n 99))
  6519. (setq y1 (org-small-year-to-year (/ n 100))
  6520. n (mod n 100)))
  6521. (setq sd (calendar-absolute-from-gregorian
  6522. (list (or n mg) 1 (or y1 yg))))))
  6523. ((eq span 'year)
  6524. (setq sd (calendar-absolute-from-gregorian
  6525. (list 1 1 (or n yg))))))
  6526. sd))
  6527. (defun org-agenda-next-date-line (&optional arg)
  6528. "Jump to the next line indicating a date in agenda buffer."
  6529. (interactive "p")
  6530. (org-agenda-check-type t 'agenda 'timeline)
  6531. (beginning-of-line 1)
  6532. ;; This does not work if user makes date format that starts with a blank
  6533. (if (looking-at "^\\S-") (forward-char 1))
  6534. (if (not (re-search-forward "^\\S-" nil t arg))
  6535. (progn
  6536. (backward-char 1)
  6537. (error "No next date after this line in this buffer")))
  6538. (goto-char (match-beginning 0)))
  6539. (defun org-agenda-previous-date-line (&optional arg)
  6540. "Jump to the previous line indicating a date in agenda buffer."
  6541. (interactive "p")
  6542. (org-agenda-check-type t 'agenda 'timeline)
  6543. (beginning-of-line 1)
  6544. (if (not (re-search-backward "^\\S-" nil t arg))
  6545. (error "No previous date before this line in this buffer")))
  6546. ;; Initialize the highlight
  6547. (defvar org-hl (make-overlay 1 1))
  6548. (overlay-put org-hl 'face 'highlight)
  6549. (defun org-highlight (begin end &optional buffer)
  6550. "Highlight a region with overlay."
  6551. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6552. (defun org-unhighlight ()
  6553. "Detach overlay INDEX."
  6554. (org-detach-overlay org-hl))
  6555. ;; FIXME this is currently not used.
  6556. (defun org-highlight-until-next-command (beg end &optional buffer)
  6557. "Move the highlight overlay to BEG/END, remove it before the next command."
  6558. (org-highlight beg end buffer)
  6559. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6560. (defun org-unhighlight-once ()
  6561. "Remove the highlight from its position, and this function from the hook."
  6562. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6563. (org-unhighlight))
  6564. (defun org-agenda-follow-mode ()
  6565. "Toggle follow mode in an agenda buffer."
  6566. (interactive)
  6567. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6568. (org-agenda-set-mode-name)
  6569. (org-agenda-do-context-action)
  6570. (message "Follow mode is %s"
  6571. (if org-agenda-follow-mode "on" "off")))
  6572. (defun org-agenda-entry-text-mode (&optional arg)
  6573. "Toggle entry text mode in an agenda buffer."
  6574. (interactive "P")
  6575. (setq org-agenda-entry-text-mode (or (integerp arg)
  6576. (not org-agenda-entry-text-mode)))
  6577. (org-agenda-entry-text-hide)
  6578. (and org-agenda-entry-text-mode
  6579. (let ((org-agenda-entry-text-maxlines
  6580. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6581. (org-agenda-entry-text-show)))
  6582. (org-agenda-set-mode-name)
  6583. (message "Entry text mode is %s. Maximum number of lines is %d"
  6584. (if org-agenda-entry-text-mode "on" "off")
  6585. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6586. (defun org-agenda-clockreport-mode (&optional with-filter)
  6587. "Toggle clocktable mode in an agenda buffer.
  6588. With prefix arg WITH-FILTER, make the clocktable respect the current
  6589. agenda filter."
  6590. (interactive "P")
  6591. (org-agenda-check-type t 'agenda)
  6592. (if with-filter
  6593. (setq org-agenda-clockreport-mode 'with-filter)
  6594. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6595. (org-agenda-set-mode-name)
  6596. (org-agenda-redo)
  6597. (message "Clocktable mode is %s"
  6598. (if org-agenda-clockreport-mode "on" "off")))
  6599. (defun org-agenda-log-mode (&optional special)
  6600. "Toggle log mode in an agenda buffer.
  6601. With argument SPECIAL, show all possible log items, not only the ones
  6602. configured in `org-agenda-log-mode-items'.
  6603. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6604. (interactive "P")
  6605. (org-agenda-check-type t 'agenda 'timeline)
  6606. (setq org-agenda-show-log
  6607. (cond
  6608. ((equal special '(16)) 'only)
  6609. ((eq special 'clockcheck)
  6610. (if (eq org-agenda-show-log 'clockcheck)
  6611. nil 'clockcheck))
  6612. (special '(closed clock state))
  6613. (t (not org-agenda-show-log))))
  6614. (org-agenda-set-mode-name)
  6615. (org-agenda-redo)
  6616. (message "Log mode is %s"
  6617. (if org-agenda-show-log "on" "off")))
  6618. (defun org-agenda-archives-mode (&optional with-files)
  6619. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6620. When called with a prefix argument, include all archive files as well."
  6621. (interactive "P")
  6622. (setq org-agenda-archives-mode
  6623. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6624. (org-agenda-set-mode-name)
  6625. (org-agenda-redo)
  6626. (message
  6627. "%s"
  6628. (cond
  6629. ((eq org-agenda-archives-mode nil)
  6630. "No archives are included")
  6631. ((eq org-agenda-archives-mode 'trees)
  6632. (format "Trees with :%s: tag are included" org-archive-tag))
  6633. ((eq org-agenda-archives-mode t)
  6634. (format "Trees with :%s: tag and all active archive files are included"
  6635. org-archive-tag)))))
  6636. (defun org-agenda-toggle-diary ()
  6637. "Toggle diary inclusion in an agenda buffer."
  6638. (interactive)
  6639. (org-agenda-check-type t 'agenda)
  6640. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6641. (org-agenda-redo)
  6642. (org-agenda-set-mode-name)
  6643. (message "Diary inclusion turned %s"
  6644. (if org-agenda-include-diary "on" "off")))
  6645. (defun org-agenda-toggle-deadlines ()
  6646. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6647. (interactive)
  6648. (org-agenda-check-type t 'agenda)
  6649. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6650. (org-agenda-redo)
  6651. (org-agenda-set-mode-name)
  6652. (message "Deadlines inclusion turned %s"
  6653. (if org-agenda-include-deadlines "on" "off")))
  6654. (defun org-agenda-toggle-time-grid ()
  6655. "Toggle time grid in an agenda buffer."
  6656. (interactive)
  6657. (org-agenda-check-type t 'agenda)
  6658. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6659. (org-agenda-redo)
  6660. (org-agenda-set-mode-name)
  6661. (message "Time-grid turned %s"
  6662. (if org-agenda-use-time-grid "on" "off")))
  6663. (defun org-agenda-set-mode-name ()
  6664. "Set the mode name to indicate all the small mode settings."
  6665. (setq mode-name
  6666. (list "Org-Agenda"
  6667. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6668. " "
  6669. '(:eval (org-agenda-span-name org-agenda-current-span))
  6670. (if org-agenda-follow-mode " Follow" "")
  6671. (if org-agenda-entry-text-mode " ETxt" "")
  6672. (if org-agenda-include-diary " Diary" "")
  6673. (if org-agenda-include-deadlines " Ddl" "")
  6674. (if org-agenda-use-time-grid " Grid" "")
  6675. (if (and (boundp 'org-habit-show-habits)
  6676. org-habit-show-habits) " Habit" "")
  6677. (cond
  6678. ((consp org-agenda-show-log) " LogAll")
  6679. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6680. (org-agenda-show-log " Log")
  6681. (t ""))
  6682. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6683. :preset-filter))
  6684. '(:eval (org-propertize
  6685. (concat " <"
  6686. (mapconcat
  6687. 'identity
  6688. (append
  6689. (get 'org-agenda-category-filter :preset-filter)
  6690. org-agenda-category-filter)
  6691. "")
  6692. ">")
  6693. 'face 'org-agenda-filter-category
  6694. 'help-echo "Category used in filtering"))
  6695. "")
  6696. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6697. :preset-filter))
  6698. '(:eval (org-propertize
  6699. (concat " {"
  6700. (mapconcat
  6701. 'identity
  6702. (append
  6703. (get 'org-agenda-tag-filter :preset-filter)
  6704. org-agenda-tag-filter)
  6705. "")
  6706. "}")
  6707. 'face 'org-agenda-filter-tags
  6708. 'help-echo "Tags used in filtering"))
  6709. "")
  6710. (if org-agenda-archives-mode
  6711. (if (eq org-agenda-archives-mode t)
  6712. " Archives"
  6713. (format " :%s:" org-archive-tag))
  6714. "")
  6715. (if org-agenda-clockreport-mode
  6716. (if (eq org-agenda-clockreport-mode 'with-filter)
  6717. " Clock{}" " Clock")
  6718. "")))
  6719. (force-mode-line-update))
  6720. (defun org-agenda-post-command-hook ()
  6721. (setq org-agenda-type
  6722. (or (get-text-property (point) 'org-agenda-type)
  6723. (get-text-property (max (point-min) (1- (point)))
  6724. 'org-agenda-type))))
  6725. (defun org-agenda-next-line ()
  6726. "Move cursor to the next line, and show if follow mode is active."
  6727. (interactive)
  6728. (call-interactively 'next-line)
  6729. (org-agenda-do-context-action))
  6730. (defun org-agenda-previous-line ()
  6731. "Move cursor to the previous line, and show if follow-mode is active."
  6732. (interactive)
  6733. (call-interactively 'previous-line)
  6734. (org-agenda-do-context-action))
  6735. (defun org-agenda-do-context-action ()
  6736. "Show outline path and, maybe, follow mode window."
  6737. (let ((m (org-get-at-bol 'org-marker)))
  6738. (when (and (markerp m) (marker-buffer m))
  6739. (and org-agenda-follow-mode
  6740. (if org-agenda-follow-indirect
  6741. (org-agenda-tree-to-indirect-buffer)
  6742. (org-agenda-show)))
  6743. (and org-agenda-show-outline-path
  6744. (org-with-point-at m (org-display-outline-path t))))))
  6745. (defun org-agenda-show-priority ()
  6746. "Show the priority of the current item.
  6747. This priority is composed of the main priority given with the [#A] cookies,
  6748. and by additional input from the age of a schedules or deadline entry."
  6749. (interactive)
  6750. (let* ((pri (org-get-at-bol 'priority)))
  6751. (message "Priority is %d" (if pri pri -1000))))
  6752. (defun org-agenda-show-tags ()
  6753. "Show the tags applicable to the current item."
  6754. (interactive)
  6755. (let* ((tags (org-get-at-bol 'tags)))
  6756. (if tags
  6757. (message "Tags are :%s:"
  6758. (org-no-properties (mapconcat 'identity tags ":")))
  6759. (message "No tags associated with this line"))))
  6760. (defun org-agenda-goto (&optional highlight)
  6761. "Go to the Org-mode file which contains the item at point."
  6762. (interactive)
  6763. (let* ((marker (or (org-get-at-bol 'org-marker)
  6764. (org-agenda-error)))
  6765. (buffer (marker-buffer marker))
  6766. (pos (marker-position marker)))
  6767. (switch-to-buffer-other-window buffer)
  6768. (widen)
  6769. (push-mark)
  6770. (goto-char pos)
  6771. (when (derived-mode-p 'org-mode)
  6772. (org-show-context 'agenda)
  6773. (save-excursion
  6774. (and (outline-next-heading)
  6775. (org-flag-heading nil)))) ; show the next heading
  6776. (when (outline-invisible-p)
  6777. (show-entry)) ; display invisible text
  6778. (recenter (/ (window-height) 2))
  6779. (run-hooks 'org-agenda-after-show-hook)
  6780. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6781. (defvar org-agenda-after-show-hook nil
  6782. "Normal hook run after an item has been shown from the agenda.
  6783. Point is in the buffer where the item originated.")
  6784. (defun org-agenda-kill ()
  6785. "Kill the entry or subtree belonging to the current agenda entry."
  6786. (interactive)
  6787. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6788. (let* ((marker (or (org-get-at-bol 'org-marker)
  6789. (org-agenda-error)))
  6790. (buffer (marker-buffer marker))
  6791. (pos (marker-position marker))
  6792. (type (org-get-at-bol 'type))
  6793. dbeg dend (n 0) conf)
  6794. (org-with-remote-undo buffer
  6795. (with-current-buffer buffer
  6796. (save-excursion
  6797. (goto-char pos)
  6798. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  6799. (setq dbeg (progn (org-back-to-heading t) (point))
  6800. dend (org-end-of-subtree t t))
  6801. (setq dbeg (point-at-bol)
  6802. dend (min (point-max) (1+ (point-at-eol)))))
  6803. (goto-char dbeg)
  6804. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6805. (setq conf (or (eq t org-agenda-confirm-kill)
  6806. (and (numberp org-agenda-confirm-kill)
  6807. (> n org-agenda-confirm-kill))))
  6808. (and conf
  6809. (not (y-or-n-p
  6810. (format "Delete entry with %d lines in buffer \"%s\"? "
  6811. n (buffer-name buffer))))
  6812. (error "Abort"))
  6813. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6814. (with-current-buffer buffer (delete-region dbeg dend))
  6815. (message "Agenda item and source killed"))))
  6816. (defvar org-archive-default-command)
  6817. (defun org-agenda-archive-default ()
  6818. "Archive the entry or subtree belonging to the current agenda entry."
  6819. (interactive)
  6820. (require 'org-archive)
  6821. (org-agenda-archive-with org-archive-default-command))
  6822. (defun org-agenda-archive-default-with-confirmation ()
  6823. "Archive the entry or subtree belonging to the current agenda entry."
  6824. (interactive)
  6825. (require 'org-archive)
  6826. (org-agenda-archive-with org-archive-default-command 'confirm))
  6827. (defun org-agenda-archive ()
  6828. "Archive the entry or subtree belonging to the current agenda entry."
  6829. (interactive)
  6830. (org-agenda-archive-with 'org-archive-subtree))
  6831. (defun org-agenda-archive-to-archive-sibling ()
  6832. "Move the entry to the archive sibling."
  6833. (interactive)
  6834. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6835. (defun org-agenda-archive-with (cmd &optional confirm)
  6836. "Move the entry to the archive sibling."
  6837. (interactive)
  6838. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6839. (let* ((marker (or (org-get-at-bol 'org-marker)
  6840. (org-agenda-error)))
  6841. (buffer (marker-buffer marker))
  6842. (pos (marker-position marker)))
  6843. (org-with-remote-undo buffer
  6844. (with-current-buffer buffer
  6845. (if (derived-mode-p 'org-mode)
  6846. (if (and confirm
  6847. (not (y-or-n-p "Archive this subtree or entry? ")))
  6848. (error "Abort")
  6849. (save-excursion
  6850. (goto-char pos)
  6851. (org-remove-subtree-entries-from-agenda)
  6852. (org-back-to-heading t)
  6853. (funcall cmd)))
  6854. (error "Archiving works only in Org-mode files"))))))
  6855. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6856. "Remove all lines in the agenda that correspond to a given subtree.
  6857. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6858. If this information is not given, the function uses the tree at point."
  6859. (let ((buf (or buf (current-buffer))) m p)
  6860. (save-excursion
  6861. (unless (and beg end)
  6862. (org-back-to-heading t)
  6863. (setq beg (point))
  6864. (org-end-of-subtree t)
  6865. (setq end (point)))
  6866. (set-buffer (get-buffer org-agenda-buffer-name))
  6867. (save-excursion
  6868. (goto-char (point-max))
  6869. (beginning-of-line 1)
  6870. (while (not (bobp))
  6871. (when (and (setq m (org-get-at-bol 'org-marker))
  6872. (equal buf (marker-buffer m))
  6873. (setq p (marker-position m))
  6874. (>= p beg)
  6875. (< p end))
  6876. (let ((inhibit-read-only t))
  6877. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6878. (beginning-of-line 0))))))
  6879. (defun org-agenda-refile (&optional goto rfloc no-update)
  6880. "Refile the item at point."
  6881. (interactive "P")
  6882. (if (equal goto '(16))
  6883. (org-refile-goto-last-stored)
  6884. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6885. (org-agenda-error)))
  6886. (buffer (marker-buffer marker))
  6887. (pos (marker-position marker))
  6888. (rfloc (or rfloc
  6889. (org-refile-get-location
  6890. (if goto "Goto" "Refile to") buffer
  6891. org-refile-allow-creating-parent-nodes))))
  6892. (with-current-buffer buffer
  6893. (save-excursion
  6894. (save-restriction
  6895. (widen)
  6896. (goto-char marker)
  6897. (org-remove-subtree-entries-from-agenda)
  6898. (org-refile goto buffer rfloc)))))
  6899. (unless no-update (org-agenda-redo))))
  6900. (defun org-agenda-open-link (&optional arg)
  6901. "Follow the link in the current line, if any.
  6902. This looks for a link in the displayed line in the agenda. It also looks
  6903. at the text of the entry itself."
  6904. (interactive "P")
  6905. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6906. (org-get-at-bol 'org-marker)))
  6907. (buffer (and marker (marker-buffer marker)))
  6908. (prefix (buffer-substring
  6909. (point-at-bol) (point-at-eol))))
  6910. (cond
  6911. (buffer
  6912. (with-current-buffer buffer
  6913. (save-excursion
  6914. (save-restriction
  6915. (widen)
  6916. (goto-char marker)
  6917. (org-offer-links-in-entry arg prefix)))))
  6918. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6919. (save-excursion
  6920. (beginning-of-line 1)
  6921. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6922. (org-open-link-from-string (match-string 1)))
  6923. (t (error "No link to open here")))))
  6924. (defun org-agenda-copy-local-variable (var)
  6925. "Get a variable from a referenced buffer and install it here."
  6926. (let ((m (org-get-at-bol 'org-marker)))
  6927. (when (and m (buffer-live-p (marker-buffer m)))
  6928. (org-set-local var (with-current-buffer (marker-buffer m)
  6929. (symbol-value var))))))
  6930. (defun org-agenda-switch-to (&optional delete-other-windows)
  6931. "Go to the Org-mode file which contains the item at point."
  6932. (interactive)
  6933. (if (and org-return-follows-link
  6934. (not (org-get-at-bol 'org-marker))
  6935. (org-in-regexp org-bracket-link-regexp))
  6936. (org-open-link-from-string (match-string 0))
  6937. (let* ((marker (or (org-get-at-bol 'org-marker)
  6938. (org-agenda-error)))
  6939. (buffer (marker-buffer marker))
  6940. (pos (marker-position marker)))
  6941. (org-pop-to-buffer-same-window buffer)
  6942. (and delete-other-windows (delete-other-windows))
  6943. (widen)
  6944. (goto-char pos)
  6945. (when (derived-mode-p 'org-mode)
  6946. (org-show-context 'agenda)
  6947. (save-excursion
  6948. (and (outline-next-heading)
  6949. (org-flag-heading nil))) ; show the next heading
  6950. (when (outline-invisible-p)
  6951. (show-entry)))))) ; display invisible text
  6952. (defun org-agenda-goto-mouse (ev)
  6953. "Go to the Org-mode file which contains the item at the mouse click."
  6954. (interactive "e")
  6955. (mouse-set-point ev)
  6956. (org-agenda-goto))
  6957. (defun org-agenda-show (&optional full-entry)
  6958. "Display the Org-mode file which contains the item at point.
  6959. With prefix argument FULL-ENTRY, make the entire entry visible
  6960. if it was hidden in the outline."
  6961. (interactive "P")
  6962. (let ((win (selected-window)))
  6963. (if full-entry
  6964. (let ((org-show-entry-below t))
  6965. (org-agenda-goto t))
  6966. (org-agenda-goto t))
  6967. (select-window win)))
  6968. (defvar org-agenda-show-window nil)
  6969. (defun org-agenda-show-and-scroll-up (&optional arg)
  6970. "Display the Org-mode file which contains the item at point.
  6971. When called repeatedly, scroll the window that is displaying the buffer.
  6972. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6973. `show-subtree' to display the item, so that drawers and logbooks stay
  6974. folded."
  6975. (interactive "P")
  6976. (let ((win (selected-window)))
  6977. (if (and (window-live-p org-agenda-show-window)
  6978. (eq this-command last-command))
  6979. (progn
  6980. (select-window org-agenda-show-window)
  6981. (ignore-errors (scroll-up)))
  6982. (org-agenda-goto t)
  6983. (if arg (org-show-entry) (show-subtree))
  6984. (setq org-agenda-show-window (selected-window)))
  6985. (select-window win)))
  6986. (defun org-agenda-show-scroll-down ()
  6987. "Scroll down the window showing the agenda."
  6988. (interactive)
  6989. (let ((win (selected-window)))
  6990. (when (window-live-p org-agenda-show-window)
  6991. (select-window org-agenda-show-window)
  6992. (ignore-errors (scroll-down))
  6993. (select-window win))))
  6994. (defun org-agenda-show-1 (&optional more)
  6995. "Display the Org-mode file which contains the item at point.
  6996. The prefix arg selects the amount of information to display:
  6997. 0 hide the subtree
  6998. 1 just show the entry according to defaults.
  6999. 2 show the children view
  7000. 3 show the subtree view
  7001. 4 show the entire subtree and any LOGBOOK drawers
  7002. 5 show the entire subtree and any drawers
  7003. With prefix argument FULL-ENTRY, make the entire entry visible
  7004. if it was hidden in the outline."
  7005. (interactive "p")
  7006. (let ((win (selected-window)))
  7007. (org-agenda-goto t)
  7008. (org-recenter-heading 1)
  7009. (cond
  7010. ((= more 0)
  7011. (hide-subtree)
  7012. (save-excursion
  7013. (org-back-to-heading)
  7014. (run-hook-with-args 'org-cycle-hook 'folded))
  7015. (message "Remote: FOLDED"))
  7016. ((and (org-called-interactively-p 'any) (= more 1))
  7017. (message "Remote: show with default settings"))
  7018. ((= more 2)
  7019. (show-entry)
  7020. (show-children)
  7021. (save-excursion
  7022. (org-back-to-heading)
  7023. (run-hook-with-args 'org-cycle-hook 'children))
  7024. (message "Remote: CHILDREN"))
  7025. ((= more 3)
  7026. (show-subtree)
  7027. (save-excursion
  7028. (org-back-to-heading)
  7029. (run-hook-with-args 'org-cycle-hook 'subtree))
  7030. (message "Remote: SUBTREE"))
  7031. ((= more 4)
  7032. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7033. (org-drawer-regexp
  7034. (concat "^[ \t]*:\\("
  7035. (mapconcat 'regexp-quote org-drawers "\\|")
  7036. "\\):[ \t]*$")))
  7037. (show-subtree)
  7038. (save-excursion
  7039. (org-back-to-heading)
  7040. (org-cycle-hide-drawers 'subtree)))
  7041. (message "Remote: SUBTREE AND LOGBOOK"))
  7042. ((> more 4)
  7043. (show-subtree)
  7044. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7045. (select-window win)))
  7046. (defun org-recenter-heading (n)
  7047. (save-excursion
  7048. (org-back-to-heading)
  7049. (recenter n)))
  7050. (defvar org-agenda-cycle-counter nil)
  7051. (defun org-agenda-cycle-show (&optional n)
  7052. "Show the current entry in another window, with default settings.
  7053. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7054. When use repeatedly in immediate succession, the remote entry will cycle
  7055. through visibility
  7056. children -> subtree -> folded
  7057. When called with a numeric prefix arg, that arg will be passed through to
  7058. `org-agenda-show-1'. For the interpretation of that argument, see the
  7059. docstring of `org-agenda-show-1'."
  7060. (interactive "P")
  7061. (if (integerp n)
  7062. (setq org-agenda-cycle-counter n)
  7063. (if (not (eq last-command this-command))
  7064. (setq org-agenda-cycle-counter 1)
  7065. (if (equal org-agenda-cycle-counter 0)
  7066. (setq org-agenda-cycle-counter 2)
  7067. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7068. (if (> org-agenda-cycle-counter 3)
  7069. (setq org-agenda-cycle-counter 0)))))
  7070. (org-agenda-show-1 org-agenda-cycle-counter))
  7071. (defun org-agenda-recenter (arg)
  7072. "Display the Org-mode file which contains the item at point and recenter."
  7073. (interactive "P")
  7074. (let ((win (selected-window)))
  7075. (org-agenda-goto t)
  7076. (recenter arg)
  7077. (select-window win)))
  7078. (defun org-agenda-show-mouse (ev)
  7079. "Display the Org-mode file which contains the item at the mouse click."
  7080. (interactive "e")
  7081. (mouse-set-point ev)
  7082. (org-agenda-show))
  7083. (defun org-agenda-check-no-diary ()
  7084. "Check if the entry is a diary link and abort if yes."
  7085. (if (org-get-at-bol 'org-agenda-diary-link)
  7086. (org-agenda-error)))
  7087. (defun org-agenda-error ()
  7088. (error "Command not allowed in this line"))
  7089. (defun org-agenda-tree-to-indirect-buffer ()
  7090. "Show the subtree corresponding to the current entry in an indirect buffer.
  7091. This calls the command `org-tree-to-indirect-buffer' from the original
  7092. Org-mode buffer.
  7093. With numerical prefix arg ARG, go up to this level and then take that tree.
  7094. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7095. use the dedicated frame)."
  7096. (interactive)
  7097. (if (and current-prefix-arg (listp current-prefix-arg))
  7098. (org-agenda-do-tree-to-indirect-buffer)
  7099. (let ((agenda-window (selected-window))
  7100. (indirect-window
  7101. (and org-last-indirect-buffer
  7102. (get-buffer-window org-last-indirect-buffer))))
  7103. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7104. (unwind-protect
  7105. (progn
  7106. (unless (and indirect-window (window-live-p indirect-window))
  7107. (setq indirect-window (split-window agenda-window)))
  7108. (select-window indirect-window)
  7109. (switch-to-buffer org-last-indirect-buffer :norecord)
  7110. (fit-window-to-buffer indirect-window))
  7111. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7112. (defun org-agenda-do-tree-to-indirect-buffer ()
  7113. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7114. (org-agenda-check-no-diary)
  7115. (let* ((marker (or (org-get-at-bol 'org-marker)
  7116. (org-agenda-error)))
  7117. (buffer (marker-buffer marker))
  7118. (pos (marker-position marker)))
  7119. (with-current-buffer buffer
  7120. (save-excursion
  7121. (goto-char pos)
  7122. (call-interactively 'org-tree-to-indirect-buffer)))))
  7123. (defvar org-last-heading-marker (make-marker)
  7124. "Marker pointing to the headline that last changed its TODO state
  7125. by a remote command from the agenda.")
  7126. (defun org-agenda-todo-nextset ()
  7127. "Switch TODO entry to next sequence."
  7128. (interactive)
  7129. (org-agenda-todo 'nextset))
  7130. (defun org-agenda-todo-previousset ()
  7131. "Switch TODO entry to previous sequence."
  7132. (interactive)
  7133. (org-agenda-todo 'previousset))
  7134. (defun org-agenda-todo (&optional arg)
  7135. "Cycle TODO state of line at point, also in Org-mode file.
  7136. This changes the line at point, all other lines in the agenda referring to
  7137. the same tree node, and the headline of the tree node in the Org-mode file."
  7138. (interactive "P")
  7139. (org-agenda-check-no-diary)
  7140. (let* ((col (current-column))
  7141. (marker (or (org-get-at-bol 'org-marker)
  7142. (org-agenda-error)))
  7143. (buffer (marker-buffer marker))
  7144. (pos (marker-position marker))
  7145. (hdmarker (org-get-at-bol 'org-hd-marker))
  7146. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7147. (inhibit-read-only t)
  7148. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7149. (org-with-remote-undo buffer
  7150. (with-current-buffer buffer
  7151. (widen)
  7152. (goto-char pos)
  7153. (org-show-context 'agenda)
  7154. (save-excursion
  7155. (and (outline-next-heading)
  7156. (org-flag-heading nil))) ; show the next heading
  7157. (let ((current-prefix-arg arg))
  7158. (call-interactively 'org-todo))
  7159. (and (bolp) (forward-char 1))
  7160. (setq newhead (org-get-heading))
  7161. (when (and (org-bound-and-true-p
  7162. org-agenda-headline-snapshot-before-repeat)
  7163. (not (equal org-agenda-headline-snapshot-before-repeat
  7164. newhead))
  7165. todayp)
  7166. (setq newhead org-agenda-headline-snapshot-before-repeat
  7167. just-one t))
  7168. (save-excursion
  7169. (org-back-to-heading)
  7170. (move-marker org-last-heading-marker (point))))
  7171. (beginning-of-line 1)
  7172. (save-excursion
  7173. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7174. (org-move-to-column col))))
  7175. (defun org-agenda-add-note (&optional arg)
  7176. "Add a time-stamped note to the entry at point."
  7177. (interactive "P")
  7178. (org-agenda-check-no-diary)
  7179. (let* ((marker (or (org-get-at-bol 'org-marker)
  7180. (org-agenda-error)))
  7181. (buffer (marker-buffer marker))
  7182. (pos (marker-position marker))
  7183. (hdmarker (org-get-at-bol 'org-hd-marker))
  7184. (inhibit-read-only t))
  7185. (with-current-buffer buffer
  7186. (widen)
  7187. (goto-char pos)
  7188. (org-show-context 'agenda)
  7189. (save-excursion
  7190. (and (outline-next-heading)
  7191. (org-flag-heading nil))) ; show the next heading
  7192. (org-add-note))))
  7193. (defun org-agenda-change-all-lines (newhead hdmarker
  7194. &optional fixface just-this)
  7195. "Change all lines in the agenda buffer which match HDMARKER.
  7196. The new content of the line will be NEWHEAD (as modified by
  7197. `org-agenda-format-item'). HDMARKER is checked with
  7198. `equal' against all `org-hd-marker' text properties in the file.
  7199. If FIXFACE is non-nil, the face of each item is modified according to
  7200. the new TODO state.
  7201. If JUST-THIS is non-nil, change just the current line, not all.
  7202. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7203. (let* ((inhibit-read-only t)
  7204. (line (org-current-line))
  7205. (org-agenda-buffer (current-buffer))
  7206. (thetags (with-current-buffer (marker-buffer hdmarker)
  7207. (save-excursion (save-restriction (widen)
  7208. (goto-char hdmarker)
  7209. (org-get-tags-at)))))
  7210. props m pl undone-face done-face finish new dotime cat tags)
  7211. (save-excursion
  7212. (goto-char (point-max))
  7213. (beginning-of-line 1)
  7214. (while (not finish)
  7215. (setq finish (bobp))
  7216. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7217. (or (not just-this) (= (org-current-line) line))
  7218. (equal m hdmarker))
  7219. (setq props (text-properties-at (point))
  7220. dotime (org-get-at-bol 'dotime)
  7221. cat (org-get-at-bol 'org-category)
  7222. tags thetags
  7223. new
  7224. (let ((org-prefix-format-compiled
  7225. (or (get-text-property (point) 'format)
  7226. org-prefix-format-compiled))
  7227. (extra (org-get-at-bol 'extra)))
  7228. (with-current-buffer (marker-buffer hdmarker)
  7229. (save-excursion
  7230. (save-restriction
  7231. (widen)
  7232. (org-agenda-format-item extra newhead cat tags dotime)))))
  7233. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7234. undone-face (org-get-at-bol 'undone-face)
  7235. done-face (org-get-at-bol 'done-face))
  7236. (beginning-of-line 1)
  7237. (cond
  7238. ((equal new "")
  7239. (and (looking-at ".*\n?") (replace-match "")))
  7240. ((looking-at ".*")
  7241. (replace-match new t t)
  7242. (beginning-of-line 1)
  7243. (add-text-properties (point-at-bol) (point-at-eol) props)
  7244. (when fixface
  7245. (add-text-properties
  7246. (point-at-bol) (point-at-eol)
  7247. (list 'face
  7248. (if org-last-todo-state-is-todo
  7249. undone-face done-face))))
  7250. (org-agenda-highlight-todo 'line)
  7251. (beginning-of-line 1))
  7252. (t (error "Line update did not work"))))
  7253. (beginning-of-line 0)))
  7254. (org-finalize-agenda)))
  7255. (defun org-agenda-align-tags (&optional line)
  7256. "Align all tags in agenda items to `org-agenda-tags-column'."
  7257. (let ((inhibit-read-only t) l c)
  7258. (save-excursion
  7259. (goto-char (if line (point-at-bol) (point-min)))
  7260. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7261. (if line (point-at-eol) nil) t)
  7262. (add-text-properties
  7263. (match-beginning 2) (match-end 2)
  7264. (list 'face (delq nil (let ((prop (get-text-property
  7265. (match-beginning 2) 'face)))
  7266. (or (listp prop) (setq prop (list prop)))
  7267. (if (memq 'org-tag prop)
  7268. prop
  7269. (cons 'org-tag prop))))))
  7270. (setq l (- (match-end 2) (match-beginning 2))
  7271. c (if (< org-agenda-tags-column 0)
  7272. (- (abs org-agenda-tags-column) l)
  7273. org-agenda-tags-column))
  7274. (delete-region (match-beginning 1) (match-end 1))
  7275. (goto-char (match-beginning 1))
  7276. (insert (org-add-props
  7277. (make-string (max 1 (- c (current-column))) ?\ )
  7278. (plist-put (copy-sequence (text-properties-at (point)))
  7279. 'face nil))))
  7280. (goto-char (point-min))
  7281. (org-font-lock-add-tag-faces (point-max)))))
  7282. (defun org-agenda-priority-up ()
  7283. "Increase the priority of line at point, also in Org-mode file."
  7284. (interactive)
  7285. (org-agenda-priority 'up))
  7286. (defun org-agenda-priority-down ()
  7287. "Decrease the priority of line at point, also in Org-mode file."
  7288. (interactive)
  7289. (org-agenda-priority 'down))
  7290. (defun org-agenda-priority (&optional force-direction)
  7291. "Set the priority of line at point, also in Org-mode file.
  7292. This changes the line at point, all other lines in the agenda referring to
  7293. the same tree node, and the headline of the tree node in the Org-mode file."
  7294. (interactive)
  7295. (unless org-enable-priority-commands
  7296. (error "Priority commands are disabled"))
  7297. (org-agenda-check-no-diary)
  7298. (let* ((marker (or (org-get-at-bol 'org-marker)
  7299. (org-agenda-error)))
  7300. (hdmarker (org-get-at-bol 'org-hd-marker))
  7301. (buffer (marker-buffer hdmarker))
  7302. (pos (marker-position hdmarker))
  7303. (inhibit-read-only t)
  7304. newhead)
  7305. (org-with-remote-undo buffer
  7306. (with-current-buffer buffer
  7307. (widen)
  7308. (goto-char pos)
  7309. (org-show-context 'agenda)
  7310. (save-excursion
  7311. (and (outline-next-heading)
  7312. (org-flag-heading nil))) ; show the next heading
  7313. (funcall 'org-priority force-direction)
  7314. (end-of-line 1)
  7315. (setq newhead (org-get-heading)))
  7316. (org-agenda-change-all-lines newhead hdmarker)
  7317. (beginning-of-line 1))))
  7318. ;; FIXME: should fix the tags property of the agenda line.
  7319. (defun org-agenda-set-tags (&optional tag onoff)
  7320. "Set tags for the current headline."
  7321. (interactive)
  7322. (org-agenda-check-no-diary)
  7323. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7324. (call-interactively 'org-change-tag-in-region)
  7325. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7326. (org-agenda-error)))
  7327. (buffer (marker-buffer hdmarker))
  7328. (pos (marker-position hdmarker))
  7329. (inhibit-read-only t)
  7330. newhead)
  7331. (org-with-remote-undo buffer
  7332. (with-current-buffer buffer
  7333. (widen)
  7334. (goto-char pos)
  7335. (save-excursion
  7336. (org-show-context 'agenda))
  7337. (save-excursion
  7338. (and (outline-next-heading)
  7339. (org-flag-heading nil))) ; show the next heading
  7340. (goto-char pos)
  7341. (if tag
  7342. (org-toggle-tag tag onoff)
  7343. (call-interactively 'org-set-tags))
  7344. (end-of-line 1)
  7345. (setq newhead (org-get-heading)))
  7346. (org-agenda-change-all-lines newhead hdmarker)
  7347. (beginning-of-line 1)))))
  7348. (defun org-agenda-set-property ()
  7349. "Set a property for the current headline."
  7350. (interactive)
  7351. (org-agenda-check-no-diary)
  7352. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7353. (org-agenda-error)))
  7354. (buffer (marker-buffer hdmarker))
  7355. (pos (marker-position hdmarker))
  7356. (inhibit-read-only t)
  7357. newhead)
  7358. (org-with-remote-undo buffer
  7359. (with-current-buffer buffer
  7360. (widen)
  7361. (goto-char pos)
  7362. (save-excursion
  7363. (org-show-context 'agenda))
  7364. (save-excursion
  7365. (and (outline-next-heading)
  7366. (org-flag-heading nil))) ; show the next heading
  7367. (goto-char pos)
  7368. (call-interactively 'org-set-property)))))
  7369. (defun org-agenda-set-effort ()
  7370. "Set the effort property for the current headline."
  7371. (interactive)
  7372. (org-agenda-check-no-diary)
  7373. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7374. (org-agenda-error)))
  7375. (buffer (marker-buffer hdmarker))
  7376. (pos (marker-position hdmarker))
  7377. (inhibit-read-only t)
  7378. newhead)
  7379. (org-with-remote-undo buffer
  7380. (with-current-buffer buffer
  7381. (widen)
  7382. (goto-char pos)
  7383. (save-excursion
  7384. (org-show-context 'agenda))
  7385. (save-excursion
  7386. (and (outline-next-heading)
  7387. (org-flag-heading nil))) ; show the next heading
  7388. (goto-char pos)
  7389. (call-interactively 'org-set-effort)
  7390. (end-of-line 1)
  7391. (setq newhead (org-get-heading)))
  7392. (org-agenda-change-all-lines newhead hdmarker))))
  7393. (defun org-agenda-toggle-archive-tag ()
  7394. "Toggle the archive tag for the current entry."
  7395. (interactive)
  7396. (org-agenda-check-no-diary)
  7397. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7398. (org-agenda-error)))
  7399. (buffer (marker-buffer hdmarker))
  7400. (pos (marker-position hdmarker))
  7401. (inhibit-read-only t)
  7402. newhead)
  7403. (org-with-remote-undo buffer
  7404. (with-current-buffer buffer
  7405. (widen)
  7406. (goto-char pos)
  7407. (org-show-context 'agenda)
  7408. (save-excursion
  7409. (and (outline-next-heading)
  7410. (org-flag-heading nil))) ; show the next heading
  7411. (call-interactively 'org-toggle-archive-tag)
  7412. (end-of-line 1)
  7413. (setq newhead (org-get-heading)))
  7414. (org-agenda-change-all-lines newhead hdmarker)
  7415. (beginning-of-line 1))))
  7416. (defun org-agenda-do-date-later (arg)
  7417. (interactive "P")
  7418. (cond
  7419. ((or (equal arg '(16))
  7420. (memq last-command
  7421. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7422. (setq this-command 'org-agenda-date-later-minutes)
  7423. (org-agenda-date-later-minutes 1))
  7424. ((or (equal arg '(4))
  7425. (memq last-command
  7426. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7427. (setq this-command 'org-agenda-date-later-hours)
  7428. (org-agenda-date-later-hours 1))
  7429. (t
  7430. (org-agenda-date-later (prefix-numeric-value arg)))))
  7431. (defun org-agenda-do-date-earlier (arg)
  7432. (interactive "P")
  7433. (cond
  7434. ((or (equal arg '(16))
  7435. (memq last-command
  7436. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7437. (setq this-command 'org-agenda-date-earlier-minutes)
  7438. (org-agenda-date-earlier-minutes 1))
  7439. ((or (equal arg '(4))
  7440. (memq last-command
  7441. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7442. (setq this-command 'org-agenda-date-earlier-hours)
  7443. (org-agenda-date-earlier-hours 1))
  7444. (t
  7445. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7446. (defun org-agenda-date-later (arg &optional what)
  7447. "Change the date of this item to ARG day(s) later."
  7448. (interactive "p")
  7449. (org-agenda-check-type t 'agenda 'timeline)
  7450. (org-agenda-check-no-diary)
  7451. (let* ((marker (or (org-get-at-bol 'org-marker)
  7452. (org-agenda-error)))
  7453. (buffer (marker-buffer marker))
  7454. (pos (marker-position marker))
  7455. cdate today)
  7456. (org-with-remote-undo buffer
  7457. (with-current-buffer buffer
  7458. (widen)
  7459. (goto-char pos)
  7460. (if (not (org-at-timestamp-p))
  7461. (error "Cannot find time stamp"))
  7462. (when (and org-agenda-move-date-from-past-immediately-to-today
  7463. (equal arg 1)
  7464. (or (not what) (eq what 'day))
  7465. (not (save-match-data (org-at-date-range-p))))
  7466. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7467. cdate (calendar-absolute-from-gregorian
  7468. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7469. today (org-today))
  7470. (if (> today cdate)
  7471. ;; immediately shift to today
  7472. (setq arg (- today cdate))))
  7473. (org-timestamp-change arg (or what 'day))
  7474. (when (and (org-at-date-range-p)
  7475. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7476. (let ((end org-last-changed-timestamp))
  7477. (org-timestamp-change arg (or what 'day))
  7478. (setq org-last-changed-timestamp
  7479. (concat org-last-changed-timestamp "--" end)))))
  7480. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7481. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7482. (defun org-agenda-date-earlier (arg &optional what)
  7483. "Change the date of this item to ARG day(s) earlier."
  7484. (interactive "p")
  7485. (org-agenda-date-later (- arg) what))
  7486. (defun org-agenda-date-later-minutes (arg)
  7487. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7488. (interactive "p")
  7489. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7490. (org-agenda-date-later arg 'minute))
  7491. (defun org-agenda-date-earlier-minutes (arg)
  7492. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7493. (interactive "p")
  7494. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7495. (org-agenda-date-earlier arg 'minute))
  7496. (defun org-agenda-date-later-hours (arg)
  7497. "Change the time of this item, in hour steps."
  7498. (interactive "p")
  7499. (org-agenda-date-later arg 'hour))
  7500. (defun org-agenda-date-earlier-hours (arg)
  7501. "Change the time of this item, in hour steps."
  7502. (interactive "p")
  7503. (org-agenda-date-earlier arg 'hour))
  7504. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7505. "Show new date stamp via text properties."
  7506. ;; We use text properties to make this undoable
  7507. (let ((inhibit-read-only t)
  7508. (buffer-invisibility-spec))
  7509. (setq stamp (concat " " prefix " => " stamp))
  7510. (save-excursion
  7511. (goto-char (point-max))
  7512. (while (not (bobp))
  7513. (when (equal marker (org-get-at-bol 'org-marker))
  7514. (org-move-to-column (- (window-width) (length stamp)) t)
  7515. (org-agenda-fix-tags-filter-overlays-at (point))
  7516. (if (featurep 'xemacs)
  7517. ;; Use `duplicable' property to trigger undo recording
  7518. (let ((ex (make-extent nil nil))
  7519. (gl (make-glyph stamp)))
  7520. (set-glyph-face gl 'secondary-selection)
  7521. (set-extent-properties
  7522. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7523. (insert-extent ex (1- (point)) (point-at-eol)))
  7524. (add-text-properties
  7525. (1- (point)) (point-at-eol)
  7526. (list 'display (org-add-props stamp nil
  7527. 'face 'secondary-selection))))
  7528. (beginning-of-line 1))
  7529. (beginning-of-line 0)))))
  7530. (defun org-agenda-date-prompt (arg)
  7531. "Change the date of this item. Date is prompted for, with default today.
  7532. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7533. be used to request time specification in the time stamp."
  7534. (interactive "P")
  7535. (org-agenda-check-type t 'agenda 'timeline)
  7536. (org-agenda-check-no-diary)
  7537. (let* ((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. (widen)
  7544. (goto-char pos)
  7545. (if (not (org-at-timestamp-p t))
  7546. (error "Cannot find time stamp"))
  7547. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7548. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7549. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7550. (defun org-agenda-schedule (arg &optional time)
  7551. "Schedule the item at point.
  7552. ARG is passed through to `org-schedule'."
  7553. (interactive "P")
  7554. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7555. (org-agenda-check-no-diary)
  7556. (let* ((marker (or (org-get-at-bol 'org-marker)
  7557. (org-agenda-error)))
  7558. (type (marker-insertion-type marker))
  7559. (buffer (marker-buffer marker))
  7560. (pos (marker-position marker))
  7561. (org-insert-labeled-timestamps-at-point nil)
  7562. ts)
  7563. (set-marker-insertion-type marker t)
  7564. (org-with-remote-undo buffer
  7565. (with-current-buffer buffer
  7566. (widen)
  7567. (goto-char pos)
  7568. (setq ts (org-schedule arg time)))
  7569. (org-agenda-show-new-time marker ts "S"))
  7570. (message "Item scheduled for %s" ts)))
  7571. (defun org-agenda-deadline (arg &optional time)
  7572. "Schedule the item at point.
  7573. ARG is passed through to `org-deadline'."
  7574. (interactive "P")
  7575. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7576. (org-agenda-check-no-diary)
  7577. (let* ((marker (or (org-get-at-bol 'org-marker)
  7578. (org-agenda-error)))
  7579. (buffer (marker-buffer marker))
  7580. (pos (marker-position marker))
  7581. (org-insert-labeled-timestamps-at-point nil)
  7582. ts)
  7583. (org-with-remote-undo buffer
  7584. (with-current-buffer buffer
  7585. (widen)
  7586. (goto-char pos)
  7587. (setq ts (org-deadline arg time)))
  7588. (org-agenda-show-new-time marker ts "D"))
  7589. (message "Deadline for this item set to %s" ts)))
  7590. (defun org-agenda-action ()
  7591. "Select entry for agenda action, or execute an agenda action.
  7592. This command prompts for another letter. Valid inputs are:
  7593. m Mark the entry at point for an agenda action
  7594. s Schedule the marked entry to the date at the cursor
  7595. d Set the deadline of the marked entry to the date at the cursor
  7596. r Call `org-remember' with cursor date as the default date
  7597. c Call `org-capture' with cursor date as the default date
  7598. SPC Show marked entry in other window
  7599. TAB Visit marked entry in other window
  7600. The cursor may be at a date in the calendar, or in the Org agenda."
  7601. (interactive)
  7602. (let (ans)
  7603. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7604. (setq ans (read-char-exclusive))
  7605. (cond
  7606. ((equal ans ?m)
  7607. ;; Mark this entry
  7608. (if (eq major-mode 'org-agenda-mode)
  7609. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7610. (org-get-at-bol 'org-marker))))
  7611. (if m
  7612. (progn
  7613. (move-marker org-agenda-action-marker
  7614. (marker-position m) (marker-buffer m))
  7615. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7616. (error "Don't know which entry to mark")))
  7617. (error "This command works only in the agenda")))
  7618. ((equal ans ?s)
  7619. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7620. ((equal ans ?d)
  7621. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7622. ((equal ans ?r)
  7623. (org-agenda-do-action '(org-remember) t))
  7624. ((equal ans ?c)
  7625. (org-agenda-do-action '(org-capture) t))
  7626. ((equal ans ?\ )
  7627. (let ((cw (selected-window)))
  7628. (org-switch-to-buffer-other-window
  7629. (marker-buffer org-agenda-action-marker))
  7630. (goto-char org-agenda-action-marker)
  7631. (org-show-context 'agenda)
  7632. (select-window cw)))
  7633. ((equal ans ?\C-i)
  7634. (org-switch-to-buffer-other-window
  7635. (marker-buffer org-agenda-action-marker))
  7636. (goto-char org-agenda-action-marker)
  7637. (org-show-context 'agenda))
  7638. (t (error "Invalid agenda action %c" ans)))))
  7639. (defun org-agenda-do-action (form &optional current-buffer)
  7640. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7641. (let ((org-overriding-default-time (org-get-cursor-date)))
  7642. (if current-buffer
  7643. (eval form)
  7644. (if (not (marker-buffer org-agenda-action-marker))
  7645. (error "No entry has been selected for agenda action")
  7646. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7647. (save-excursion
  7648. (save-restriction
  7649. (widen)
  7650. (goto-char org-agenda-action-marker)
  7651. (eval form))))))))
  7652. (defun org-agenda-clock-in (&optional arg)
  7653. "Start the clock on the currently selected item."
  7654. (interactive "P")
  7655. (org-agenda-check-no-diary)
  7656. (if (equal arg '(4))
  7657. (org-clock-in arg)
  7658. (let* ((marker (or (org-get-at-bol 'org-marker)
  7659. (org-agenda-error)))
  7660. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7661. marker))
  7662. (pos (marker-position marker))
  7663. newhead)
  7664. (org-with-remote-undo (marker-buffer marker)
  7665. (with-current-buffer (marker-buffer marker)
  7666. (widen)
  7667. (goto-char pos)
  7668. (org-show-context 'agenda)
  7669. (org-show-entry)
  7670. (org-cycle-hide-drawers 'children)
  7671. (org-clock-in arg)
  7672. (setq newhead (org-get-heading)))
  7673. (org-agenda-change-all-lines newhead hdmarker)))))
  7674. (defun org-agenda-clock-out ()
  7675. "Stop the currently running clock."
  7676. (interactive)
  7677. (unless (marker-buffer org-clock-marker)
  7678. (error "No running clock"))
  7679. (let ((marker (make-marker)) newhead)
  7680. (org-with-remote-undo (marker-buffer org-clock-marker)
  7681. (with-current-buffer (marker-buffer org-clock-marker)
  7682. (save-excursion
  7683. (save-restriction
  7684. (widen)
  7685. (goto-char org-clock-marker)
  7686. (org-back-to-heading t)
  7687. (move-marker marker (point))
  7688. (org-clock-out)
  7689. (setq newhead (org-get-heading))))))
  7690. (org-agenda-change-all-lines newhead marker)
  7691. (move-marker marker nil)))
  7692. (defun org-agenda-clock-cancel (&optional arg)
  7693. "Cancel the currently running clock."
  7694. (interactive "P")
  7695. (unless (marker-buffer org-clock-marker)
  7696. (error "No running clock"))
  7697. (org-with-remote-undo (marker-buffer org-clock-marker)
  7698. (org-clock-cancel)))
  7699. (defun org-agenda-clock-goto ()
  7700. "Jump to the currently clocked in task within the agenda.
  7701. If the currently clocked in task is not listed in the agenda
  7702. buffer, display it in another window."
  7703. (interactive)
  7704. (let (pos)
  7705. (mapc (lambda (o)
  7706. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7707. (setq pos (overlay-start o))))
  7708. (overlays-in (point-min) (point-max)))
  7709. (cond (pos (goto-char pos))
  7710. ;; If the currently clocked entry is not in the agenda
  7711. ;; buffer, we visit it in another window:
  7712. (org-clock-current-task
  7713. (org-switch-to-buffer-other-window (org-clock-goto)))
  7714. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7715. (defun org-agenda-diary-entry-in-org-file ()
  7716. "Make a diary entry in the file `org-agenda-diary-file'."
  7717. (let (d1 d2 char (text "") dp1 dp2)
  7718. (if (equal (buffer-name) "*Calendar*")
  7719. (setq d1 (calendar-cursor-to-date t)
  7720. d2 (car calendar-mark-ring))
  7721. (setq dp1 (get-text-property (point-at-bol) 'day))
  7722. (unless dp1 (error "No date defined in current line"))
  7723. (setq d1 (calendar-gregorian-from-absolute dp1)
  7724. d2 (and (ignore-errors (mark))
  7725. (save-excursion
  7726. (goto-char (mark))
  7727. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7728. (calendar-gregorian-from-absolute dp2))))
  7729. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7730. (setq char (read-char-exclusive))
  7731. (cond
  7732. ((equal char ?d)
  7733. (setq text (read-string "Day entry: "))
  7734. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7735. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7736. ((equal char ?a)
  7737. (setq d1 (list (car d1) (nth 1 d1)
  7738. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7739. (nth 2 d1))))
  7740. (setq text (read-string "Anniversary (use %d to show years): "))
  7741. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7742. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7743. ((equal char ?b)
  7744. (setq text (read-string "Block entry: "))
  7745. (unless (and d1 d2 (not (equal d1 d2)))
  7746. (error "No block of days selected"))
  7747. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7748. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7749. ((equal char ?j)
  7750. (org-switch-to-buffer-other-window
  7751. (find-file-noselect org-agenda-diary-file))
  7752. (require 'org-datetree)
  7753. (org-datetree-find-date-create d1)
  7754. (org-reveal t))
  7755. (t (error "Invalid selection character `%c'" char)))))
  7756. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7757. "Where in `org-agenda-diary-file' should new entries be added?
  7758. Valid values:
  7759. date-tree in the date tree, as child of the date
  7760. top-level as top-level entries at the end of the file."
  7761. :group 'org-agenda
  7762. :type '(choice
  7763. (const :tag "in a date tree" date-tree)
  7764. (const :tag "as top level at end of file" top-level)))
  7765. (defcustom org-agenda-insert-diary-extract-time nil
  7766. "Non-nil means extract any time specification from the diary entry."
  7767. :group 'org-agenda
  7768. :version "24.1"
  7769. :type 'boolean)
  7770. (defcustom org-agenda-bulk-mark-char ">"
  7771. "A single-character string to be used as the bulk mark."
  7772. :group 'org-agenda
  7773. :version "24.1"
  7774. :type 'string)
  7775. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7776. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7777. If TEXT is not empty, it will become the headline of the new entry, and
  7778. the resulting entry will not be shown. When TEXT is empty, switch to
  7779. `org-agenda-diary-file' and let the user finish the entry there."
  7780. (let ((cw (current-window-configuration)))
  7781. (org-switch-to-buffer-other-window
  7782. (find-file-noselect org-agenda-diary-file))
  7783. (widen)
  7784. (goto-char (point-min))
  7785. (cond
  7786. ((eq type 'anniversary)
  7787. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7788. (progn
  7789. (or (org-at-heading-p t)
  7790. (progn
  7791. (outline-next-heading)
  7792. (insert "* Anniversaries\n\n")
  7793. (beginning-of-line -1)))))
  7794. (outline-next-heading)
  7795. (org-back-over-empty-lines)
  7796. (backward-char 1)
  7797. (insert "\n")
  7798. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7799. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7800. ((eq type 'day)
  7801. (let ((org-prefix-has-time t)
  7802. (org-agenda-time-leading-zero t)
  7803. fmt time time2)
  7804. (if org-agenda-insert-diary-extract-time
  7805. ;; Use org-agenda-format-item to parse text for a time-range and
  7806. ;; remove it. FIXME: This is a hack, we should refactor
  7807. ;; that function to make time extraction available separately
  7808. (setq fmt (org-agenda-format-item nil text nil nil t)
  7809. time (get-text-property 0 'time fmt)
  7810. time2 (if (> (length time) 0)
  7811. ;; split-string removes trailing ...... if
  7812. ;; no end time given. First space
  7813. ;; separates time from date.
  7814. (concat " " (car (split-string time "\\.")))
  7815. nil)
  7816. text (get-text-property 0 'txt fmt)))
  7817. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7818. (org-agenda-insert-diary-as-top-level text)
  7819. (require 'org-datetree)
  7820. (org-datetree-find-date-create d1)
  7821. (org-agenda-insert-diary-make-new-entry text))
  7822. (org-insert-time-stamp (org-time-from-absolute
  7823. (calendar-absolute-from-gregorian d1))
  7824. nil nil nil nil time2))
  7825. (end-of-line 0))
  7826. ((eq type 'block)
  7827. (if (> (calendar-absolute-from-gregorian d1)
  7828. (calendar-absolute-from-gregorian d2))
  7829. (setq d1 (prog1 d2 (setq d2 d1))))
  7830. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7831. (org-agenda-insert-diary-as-top-level text)
  7832. (require 'org-datetree)
  7833. (org-datetree-find-date-create d1)
  7834. (org-agenda-insert-diary-make-new-entry text))
  7835. (org-insert-time-stamp (org-time-from-absolute
  7836. (calendar-absolute-from-gregorian d1)))
  7837. (insert "--")
  7838. (org-insert-time-stamp (org-time-from-absolute
  7839. (calendar-absolute-from-gregorian d2)))
  7840. (end-of-line 0)))
  7841. (if (string-match "\\S-" text)
  7842. (progn
  7843. (set-window-configuration cw)
  7844. (message "%s entry added to %s"
  7845. (capitalize (symbol-name type))
  7846. (abbreviate-file-name org-agenda-diary-file)))
  7847. (org-reveal t)
  7848. (message "Please finish entry here"))))
  7849. (defun org-agenda-insert-diary-as-top-level (text)
  7850. "Make new entry as a top-level entry at the end of the file.
  7851. Add TEXT as headline, and position the cursor in the second line so that
  7852. a timestamp can be added there."
  7853. (widen)
  7854. (goto-char (point-max))
  7855. (or (bolp) (insert "\n"))
  7856. (insert "* " text "\n")
  7857. (if org-adapt-indentation (org-indent-to-column 2)))
  7858. (defun org-agenda-insert-diary-make-new-entry (text)
  7859. "Make new entry as last child of current entry.
  7860. Add TEXT as headline, and position the cursor in the second line so that
  7861. a timestamp can be added there."
  7862. (let ((org-show-following-heading t)
  7863. (org-show-siblings t)
  7864. (org-show-hierarchy-above t)
  7865. (org-show-entry-below t)
  7866. col)
  7867. (outline-next-heading)
  7868. (org-back-over-empty-lines)
  7869. (or (looking-at "[ \t]*$")
  7870. (progn (insert "\n") (backward-char 1)))
  7871. (org-insert-heading nil t)
  7872. (org-do-demote)
  7873. (setq col (current-column))
  7874. (insert text "\n")
  7875. (if org-adapt-indentation (org-indent-to-column col))
  7876. (let ((org-show-following-heading t)
  7877. (org-show-siblings t)
  7878. (org-show-hierarchy-above t)
  7879. (org-show-entry-below t))
  7880. (org-show-context))))
  7881. (defun org-agenda-diary-entry ()
  7882. "Make a diary entry, like the `i' command from the calendar.
  7883. All the standard commands work: block, weekly etc.
  7884. When `org-agenda-diary-file' points to a file,
  7885. `org-agenda-diary-entry-in-org-file' is called instead to create
  7886. entries in that Org-mode file."
  7887. (interactive)
  7888. (org-agenda-check-type t 'agenda 'timeline)
  7889. (if (not (eq org-agenda-diary-file 'diary-file))
  7890. (org-agenda-diary-entry-in-org-file)
  7891. (require 'diary-lib)
  7892. (let* ((char (progn
  7893. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7894. (read-char-exclusive)))
  7895. (cmd (cdr (assoc char
  7896. '((?d . insert-diary-entry)
  7897. (?w . insert-weekly-diary-entry)
  7898. (?m . insert-monthly-diary-entry)
  7899. (?y . insert-yearly-diary-entry)
  7900. (?a . insert-anniversary-diary-entry)
  7901. (?b . insert-block-diary-entry)
  7902. (?c . insert-cyclic-diary-entry)))))
  7903. (oldf (symbol-function 'calendar-cursor-to-date))
  7904. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7905. (point (point))
  7906. (mark (or (mark t) (point))))
  7907. (unless cmd
  7908. (error "No command associated with <%c>" char))
  7909. (unless (and (get-text-property point 'day)
  7910. (or (not (equal ?b char))
  7911. (get-text-property mark 'day)))
  7912. (error "Don't know which date to use for diary entry"))
  7913. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7914. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7915. (let ((calendar-mark-ring
  7916. (list (calendar-gregorian-from-absolute
  7917. (or (get-text-property mark 'day)
  7918. (get-text-property point 'day))))))
  7919. (unwind-protect
  7920. (progn
  7921. (fset 'calendar-cursor-to-date
  7922. (lambda (&optional error dummy)
  7923. (calendar-gregorian-from-absolute
  7924. (get-text-property point 'day))))
  7925. (call-interactively cmd))
  7926. (fset 'calendar-cursor-to-date oldf))))))
  7927. (defun org-agenda-execute-calendar-command (cmd)
  7928. "Execute a calendar command from the agenda, with the date associated to
  7929. the cursor position."
  7930. (org-agenda-check-type t 'agenda 'timeline)
  7931. (require 'diary-lib)
  7932. (unless (get-text-property (point) 'day)
  7933. (error "Don't know which date to use for calendar command"))
  7934. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7935. (point (point))
  7936. (date (calendar-gregorian-from-absolute
  7937. (get-text-property point 'day)))
  7938. ;; the following 2 vars are needed in the calendar
  7939. (displayed-month (car date))
  7940. (displayed-year (nth 2 date)))
  7941. (unwind-protect
  7942. (progn
  7943. (fset 'calendar-cursor-to-date
  7944. (lambda (&optional error dummy)
  7945. (calendar-gregorian-from-absolute
  7946. (get-text-property point 'day))))
  7947. (call-interactively cmd))
  7948. (fset 'calendar-cursor-to-date oldf))))
  7949. (defun org-agenda-phases-of-moon ()
  7950. "Display the phases of the moon for the 3 months around the cursor date."
  7951. (interactive)
  7952. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7953. (defun org-agenda-holidays ()
  7954. "Display the holidays for the 3 months around the cursor date."
  7955. (interactive)
  7956. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7957. (defvar calendar-longitude)
  7958. (defvar calendar-latitude)
  7959. (defvar calendar-location-name)
  7960. (defun org-agenda-sunrise-sunset (arg)
  7961. "Display sunrise and sunset for the cursor date.
  7962. Latitude and longitude can be specified with the variables
  7963. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7964. argument, latitude and longitude will be prompted for."
  7965. (interactive "P")
  7966. (require 'solar)
  7967. (let ((calendar-longitude (if arg nil calendar-longitude))
  7968. (calendar-latitude (if arg nil calendar-latitude))
  7969. (calendar-location-name
  7970. (if arg "the given coordinates" calendar-location-name)))
  7971. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7972. (defun org-agenda-goto-calendar ()
  7973. "Open the Emacs calendar with the date at the cursor."
  7974. (interactive)
  7975. (org-agenda-check-type t 'agenda 'timeline)
  7976. (let* ((day (or (get-text-property (point) 'day)
  7977. (error "Don't know which date to open in calendar")))
  7978. (date (calendar-gregorian-from-absolute day))
  7979. (calendar-move-hook nil)
  7980. (calendar-view-holidays-initially-flag nil)
  7981. (calendar-view-diary-initially-flag nil))
  7982. (calendar)
  7983. (calendar-goto-date date)))
  7984. ;;;###autoload
  7985. (defun org-calendar-goto-agenda ()
  7986. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7987. This is a command that has to be installed in `calendar-mode-map'."
  7988. (interactive)
  7989. (org-agenda-list nil (calendar-absolute-from-gregorian
  7990. (calendar-cursor-to-date))
  7991. nil))
  7992. (defun org-agenda-convert-date ()
  7993. (interactive)
  7994. (org-agenda-check-type t 'agenda 'timeline)
  7995. (let ((day (get-text-property (point) 'day))
  7996. date s)
  7997. (unless day
  7998. (error "Don't know which date to convert"))
  7999. (setq date (calendar-gregorian-from-absolute day))
  8000. (setq s (concat
  8001. "Gregorian: " (calendar-date-string date) "\n"
  8002. "ISO: " (calendar-iso-date-string date) "\n"
  8003. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8004. "Julian: " (calendar-julian-date-string date) "\n"
  8005. "Astron. JD: " (calendar-astro-date-string date)
  8006. " (Julian date number at noon UTC)\n"
  8007. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8008. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8009. "French: " (calendar-french-date-string date) "\n"
  8010. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8011. "Mayan: " (calendar-mayan-date-string date) "\n"
  8012. "Coptic: " (calendar-coptic-date-string date) "\n"
  8013. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8014. "Persian: " (calendar-persian-date-string date) "\n"
  8015. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8016. (with-output-to-temp-buffer "*Dates*"
  8017. (princ s))
  8018. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8019. ;;; Bulk commands
  8020. (defvar org-agenda-bulk-marked-entries nil
  8021. "List of markers that refer to marked entries in the agenda.")
  8022. (defun org-agenda-bulk-marked-p ()
  8023. (eq (get-char-property (point-at-bol) 'type)
  8024. 'org-marked-entry-overlay))
  8025. (defun org-agenda-bulk-mark (&optional arg)
  8026. "Mark the entry at point for future bulk action."
  8027. (interactive "p")
  8028. (dotimes (i (or arg 1))
  8029. (unless (org-get-at-bol 'org-agenda-diary-link)
  8030. (let* ((m (org-get-at-bol 'org-hd-marker))
  8031. ov)
  8032. (unless (org-agenda-bulk-marked-p)
  8033. (unless m (error "Nothing to mark at point"))
  8034. (push m org-agenda-bulk-marked-entries)
  8035. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8036. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8037. (org-get-todo-face "TODO")
  8038. 'evaporate)
  8039. (overlay-put ov 'type 'org-marked-entry-overlay))
  8040. (beginning-of-line 2)
  8041. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8042. (beginning-of-line 2))
  8043. (message "%d entries marked for bulk action"
  8044. (length org-agenda-bulk-marked-entries))))))
  8045. (defun org-agenda-bulk-mark-all ()
  8046. "Mark all entries for future agenda bulk action."
  8047. (interactive)
  8048. (org-agenda-bulk-mark-regexp "."))
  8049. (defun org-agenda-bulk-mark-regexp (regexp)
  8050. "Mark entries matching REGEXP for future agenda bulk action."
  8051. (interactive "sMark entries matching regexp: ")
  8052. (let ((entries-marked 0))
  8053. (save-excursion
  8054. (goto-char (point-min))
  8055. (goto-char (next-single-property-change (point) 'txt))
  8056. (while (re-search-forward regexp nil t)
  8057. (when (string-match regexp (get-text-property (point) 'txt))
  8058. (setq entries-marked (1+ entries-marked))
  8059. (call-interactively 'org-agenda-bulk-mark))))
  8060. (if (not entries-marked)
  8061. (message "No entry matching this regexp."))))
  8062. (defun org-agenda-bulk-unmark (&optional arg)
  8063. "Unmark the entry at point for future bulk action."
  8064. (interactive "P")
  8065. (if arg
  8066. (org-agenda-bulk-unmark-all)
  8067. (cond ((org-agenda-bulk-marked-p)
  8068. (org-agenda-bulk-remove-overlays
  8069. (point-at-bol) (+ 2 (point-at-bol)))
  8070. (setq org-agenda-bulk-marked-entries
  8071. (delete (org-get-at-bol 'org-hd-marker)
  8072. org-agenda-bulk-marked-entries))
  8073. (beginning-of-line 2)
  8074. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8075. (beginning-of-line 2))
  8076. (message "%d entries left marked for bulk action"
  8077. (length org-agenda-bulk-marked-entries)))
  8078. (t (message "No entry to unmark here")))))
  8079. (defun org-agenda-bulk-toggle ()
  8080. "Toggle marking the entry at point for bulk action."
  8081. (interactive)
  8082. (if (org-agenda-bulk-marked-p)
  8083. (org-agenda-bulk-unmark)
  8084. (org-agenda-bulk-mark)))
  8085. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8086. "Remove the mark overlays between BEG and END in the agenda buffer.
  8087. BEG and END default to the buffer limits.
  8088. This only removes the overlays, it does not remove the markers
  8089. from the list in `org-agenda-bulk-marked-entries'."
  8090. (interactive)
  8091. (mapc (lambda (ov)
  8092. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8093. (delete-overlay ov)))
  8094. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8095. (defun org-agenda-bulk-unmark-all ()
  8096. "Remove all marks in the agenda buffer.
  8097. This will remove the markers and the overlays."
  8098. (interactive)
  8099. (if (null org-agenda-bulk-marked-entries)
  8100. (message "No entry to unmark")
  8101. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8102. (setq org-agenda-bulk-marked-entries nil)
  8103. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8104. (defcustom org-agenda-persistent-marks nil
  8105. "Non-nil means marked items will stay marked after a bulk action.
  8106. You can interactively and temporarily toggle by typing `p' when you
  8107. are prompted for a bulk action."
  8108. :group 'org-agenda
  8109. :version "24.1"
  8110. :type 'boolean)
  8111. (defun org-agenda-bulk-action (&optional arg)
  8112. "Execute an remote-editing action on all marked entries.
  8113. The prefix arg is passed through to the command if possible."
  8114. (interactive "P")
  8115. ;; Make sure we have markers, and only valid ones
  8116. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8117. (mapc
  8118. (lambda (m)
  8119. (unless (and (markerp m)
  8120. (marker-buffer m)
  8121. (buffer-live-p (marker-buffer m))
  8122. (marker-position m))
  8123. (error "Marker %s for bulk command is invalid" m)))
  8124. org-agenda-bulk-marked-entries)
  8125. ;; Prompt for the bulk command
  8126. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8127. (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
  8128. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
  8129. (when org-agenda-bulk-custom-functions
  8130. (concat " Custom: ["
  8131. (mapconcat (lambda(f) (char-to-string (car f)))
  8132. org-agenda-bulk-custom-functions "")
  8133. "]"))))
  8134. (catch 'exit
  8135. (let* ((action (read-char-exclusive))
  8136. (org-log-refile (if org-log-refile 'time nil))
  8137. (entries (reverse org-agenda-bulk-marked-entries))
  8138. redo-at-end
  8139. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8140. (cond
  8141. ((equal action ?p)
  8142. (let ((org-agenda-persistent-marks
  8143. (not org-agenda-persistent-marks)))
  8144. (org-agenda-bulk-action)
  8145. (throw 'exit nil)))
  8146. ((equal action ?$)
  8147. (setq cmd '(org-agenda-archive)))
  8148. ((equal action ?A)
  8149. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8150. ((member action '(?r ?w))
  8151. (setq rfloc (org-refile-get-location
  8152. "Refile to"
  8153. (marker-buffer (car org-agenda-bulk-marked-entries))
  8154. org-refile-allow-creating-parent-nodes))
  8155. (if (nth 3 rfloc)
  8156. (setcar (nthcdr 3 rfloc)
  8157. (move-marker (make-marker) (nth 3 rfloc)
  8158. (or (get-file-buffer (nth 1 rfloc))
  8159. (find-buffer-visiting (nth 1 rfloc))
  8160. (error "This should not happen")))))
  8161. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8162. redo-at-end t))
  8163. ((equal action ?t)
  8164. (setq state (org-icompleting-read
  8165. "Todo state: "
  8166. (with-current-buffer (marker-buffer (car entries))
  8167. (mapcar 'list org-todo-keywords-1))))
  8168. (setq cmd `(let ((org-inhibit-blocking t)
  8169. (org-inhibit-logging 'note))
  8170. (org-agenda-todo ,state))))
  8171. ((memq action '(?- ?+))
  8172. (setq tag (org-icompleting-read
  8173. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8174. (with-current-buffer (marker-buffer (car entries))
  8175. (delq nil
  8176. (mapcar (lambda (x)
  8177. (if (stringp (car x)) x)) org-tag-alist)))))
  8178. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8179. ((memq action '(?s ?d))
  8180. (let* ((date (unless arg
  8181. (org-read-date
  8182. nil nil nil
  8183. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8184. (ans (if arg nil org-read-date-final-answer))
  8185. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8186. (setq cmd `(let* ((bound (fboundp 'read-string))
  8187. (old (and bound (symbol-function 'read-string))))
  8188. (unwind-protect
  8189. (progn
  8190. (fset 'read-string (lambda (&rest ignore) ,ans))
  8191. (eval '(,c1 arg)))
  8192. (if bound
  8193. (fset 'read-string old)
  8194. (fmakunbound 'read-string)))))))
  8195. ((equal action ?S)
  8196. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8197. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8198. (let ((days (read-number
  8199. (format "Scatter tasks across how many %sdays: "
  8200. (if arg "week" "")) 7)))
  8201. (setq cmd
  8202. `(let ((distance (1+ (random ,days))))
  8203. (if arg
  8204. (let ((dist distance)
  8205. (day-of-week
  8206. (calendar-day-of-week
  8207. (calendar-gregorian-from-absolute (org-today)))))
  8208. (dotimes (i (1+ dist))
  8209. (while (member day-of-week org-agenda-weekend-days)
  8210. (incf distance)
  8211. (incf day-of-week)
  8212. (if (= day-of-week 7)
  8213. (setq day-of-week 0)))
  8214. (incf day-of-week)
  8215. (if (= day-of-week 7)
  8216. (setq day-of-week 0)))))
  8217. ;; silently fail when try to replan a sexp entry
  8218. (condition-case nil
  8219. (let* ((date (calendar-gregorian-from-absolute
  8220. (+ (org-today) distance)))
  8221. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8222. (nth 2 date))))
  8223. (org-agenda-schedule nil time))
  8224. (error nil)))))))
  8225. ((assoc action org-agenda-bulk-custom-functions)
  8226. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8227. redo-at-end t))
  8228. ((equal action ?f)
  8229. (setq cmd (list (intern
  8230. (org-icompleting-read "Function: "
  8231. obarray 'fboundp t nil nil)))))
  8232. (t (error "Invalid bulk action")))
  8233. ;; Sort the markers, to make sure that parents are handled before children
  8234. (setq entries (sort entries
  8235. (lambda (a b)
  8236. (cond
  8237. ((equal (marker-buffer a) (marker-buffer b))
  8238. (< (marker-position a) (marker-position b)))
  8239. (t
  8240. (string< (buffer-name (marker-buffer a))
  8241. (buffer-name (marker-buffer b))))))))
  8242. ;; Now loop over all markers and apply cmd
  8243. (while (setq e (pop entries))
  8244. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8245. (if (not pos)
  8246. (progn (message "Skipping removed entry at %s" e)
  8247. (setq cntskip (1+ cntskip)))
  8248. (goto-char pos)
  8249. (let (org-loop-over-headlines-in-active-region)
  8250. (eval cmd))
  8251. (when (not org-agenda-persistent-marks)
  8252. (setq org-agenda-bulk-marked-entries
  8253. (delete e org-agenda-bulk-marked-entries)))
  8254. (setq cnt (1+ cnt))))
  8255. (when (not org-agenda-persistent-marks)
  8256. (org-agenda-bulk-unmark-all))
  8257. (when redo-at-end (org-agenda-redo))
  8258. (message "Acted on %d entries%s%s"
  8259. cnt
  8260. (if (= cntskip 0)
  8261. ""
  8262. (format ", skipped %d (disappeared before their turn)"
  8263. cntskip))
  8264. (if (not org-agenda-persistent-marks)
  8265. "" " (kept marked)"))))))
  8266. ;;; Flagging notes
  8267. (defun org-agenda-show-the-flagging-note ()
  8268. "Display the flagging note in the other window.
  8269. When called a second time in direct sequence, offer to remove the FLAGGING
  8270. tag and (if present) the flagging note."
  8271. (interactive)
  8272. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8273. (win (selected-window))
  8274. note heading newhead)
  8275. (unless hdmarker
  8276. (error "No linked entry at point"))
  8277. (if (and (eq this-command last-command)
  8278. (y-or-n-p "Unflag and remove any flagging note? "))
  8279. (progn
  8280. (org-agenda-remove-flag hdmarker)
  8281. (let ((win (get-buffer-window "*Flagging Note*")))
  8282. (and win (delete-window win)))
  8283. (message "Entry unflagged"))
  8284. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8285. (unless note
  8286. (error "No flagging note"))
  8287. (org-kill-new note)
  8288. (org-switch-to-buffer-other-window "*Flagging Note*")
  8289. (erase-buffer)
  8290. (insert note)
  8291. (goto-char (point-min))
  8292. (while (re-search-forward "\\\\n" nil t)
  8293. (replace-match "\n" t t))
  8294. (goto-char (point-min))
  8295. (select-window win)
  8296. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8297. (defun org-agenda-remove-flag (marker)
  8298. "Remove the FLAGGED tag and any flagging note in the entry."
  8299. (let (newhead)
  8300. (org-with-point-at marker
  8301. (org-toggle-tag "FLAGGED" 'off)
  8302. (org-entry-delete nil "THEFLAGGINGNOTE")
  8303. (setq newhead (org-get-heading)))
  8304. (org-agenda-change-all-lines newhead marker)
  8305. (message "Entry unflagged")))
  8306. (defun org-agenda-get-any-marker (&optional pos)
  8307. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8308. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8309. ;;; Appointment reminders
  8310. (defvar appt-time-msg-list)
  8311. ;;;###autoload
  8312. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8313. "Activate appointments found in `org-agenda-files'.
  8314. With a \\[universal-argument] prefix, refresh the list of
  8315. appointments.
  8316. If FILTER is t, interactively prompt the user for a regular
  8317. expression, and filter out entries that don't match it.
  8318. If FILTER is a string, use this string as a regular expression
  8319. for filtering entries out.
  8320. If FILTER is a function, filter out entries against which
  8321. calling the function returns nil. This function takes one
  8322. argument: an entry from `org-agenda-get-day-entries'.
  8323. FILTER can also be an alist with the car of each cell being
  8324. either 'headline or 'category. For example:
  8325. '((headline \"IMPORTANT\")
  8326. (category \"Work\"))
  8327. will only add headlines containing IMPORTANT or headlines
  8328. belonging to the \"Work\" category.
  8329. ARGS are symbols indicating what kind of entries to consider.
  8330. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8331. and :timestamp entries. See the docstring of `org-diary' for
  8332. details and examples."
  8333. (interactive "P")
  8334. (if refresh (setq appt-time-msg-list nil))
  8335. (if (eq filter t)
  8336. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8337. (let* ((cnt 0) ; count added events
  8338. (scope (or args '(:deadline :scheduled :timestamp)))
  8339. (org-agenda-new-buffers nil)
  8340. (org-deadline-warning-days 0)
  8341. ;; Do not use `org-today' here because appt only takes
  8342. ;; time and without date as argument, so it may pass wrong
  8343. ;; information otherwise
  8344. (today (org-date-to-gregorian
  8345. (time-to-days (current-time))))
  8346. (org-agenda-restrict nil)
  8347. (files (org-agenda-files 'unrestricted)) entries file
  8348. (org-agenda-buffer nil))
  8349. ;; Get all entries which may contain an appt
  8350. (org-prepare-agenda-buffers files)
  8351. (while (setq file (pop files))
  8352. (setq entries
  8353. (delq nil
  8354. (append entries
  8355. (apply 'org-agenda-get-day-entries
  8356. file today scope)))))
  8357. ;; Map thru entries and find if we should filter them out
  8358. (mapc
  8359. (lambda(x)
  8360. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8361. (cat (get-text-property 1 'org-category x))
  8362. (tod (get-text-property 1 'time-of-day x))
  8363. (ok (or (null filter)
  8364. (and (stringp filter) (string-match filter evt))
  8365. (and (functionp filter) (funcall filter x))
  8366. (and (listp filter)
  8367. (let ((cat-filter (cadr (assoc 'category filter)))
  8368. (evt-filter (cadr (assoc 'headline filter))))
  8369. (or (and (stringp cat-filter)
  8370. (string-match cat-filter cat))
  8371. (and (stringp evt-filter)
  8372. (string-match evt-filter evt))))))))
  8373. ;; FIXME: Shall we remove text-properties for the appt text?
  8374. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8375. (when (and ok tod)
  8376. (setq tod (concat "00" (number-to-string tod))
  8377. tod (when (string-match
  8378. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8379. (concat (match-string 1 tod) ":"
  8380. (match-string 2 tod))))
  8381. (appt-add tod evt)
  8382. (setq cnt (1+ cnt))))) entries)
  8383. (org-release-buffers org-agenda-new-buffers)
  8384. (if (eq cnt 0)
  8385. (message "No event to add")
  8386. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8387. (defun org-agenda-todayp (date)
  8388. "Does DATE mean today, when considering `org-extend-today-until'?"
  8389. (let ((today (org-today))
  8390. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8391. date)))
  8392. (eq date today)))
  8393. (defun org-agenda-todo-yesterday (&optional arg)
  8394. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8395. (interactive "P")
  8396. (let* ((hour (third (decode-time
  8397. (org-current-time))))
  8398. (org-extend-today-until (1+ hour)))
  8399. (org-agenda-todo arg)))
  8400. (provide 'org-agenda)
  8401. ;;; org-agenda.el ends here