org-agenda.el 346 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040
  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. (defvar entry)
  84. (defvar date)
  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. (if rtnall (insert ;; all entries
  3563. (org-finalize-agenda-entries
  3564. (org-agenda-add-time-grid-maybe
  3565. rtnall ndays todayp))
  3566. "\n"))
  3567. (put-text-property s (1- (point)) 'day d)
  3568. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3569. (when (and org-agenda-clockreport-mode clocktable-start)
  3570. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3571. ;; the above line is to ensure the restricted range!
  3572. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3573. tbl)
  3574. (setq p (org-plist-delete p :block))
  3575. (setq p (plist-put p :tstart clocktable-start))
  3576. (setq p (plist-put p :tend clocktable-end))
  3577. (setq p (plist-put p :scope 'agenda))
  3578. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3579. (setq filter (or org-agenda-tag-filter-while-redo
  3580. (get 'org-agenda-tag-filter :preset-filter))))
  3581. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3582. (if (string-match "[<>=]" x)
  3583. ""
  3584. x))
  3585. filter ""))))
  3586. (setq tbl (apply 'org-get-clocktable p))
  3587. (insert tbl)))
  3588. (goto-char (point-min))
  3589. (or org-agenda-multi (org-fit-agenda-window))
  3590. (unless (and (pos-visible-in-window-p (point-min))
  3591. (pos-visible-in-window-p (point-max)))
  3592. (goto-char (1- (point-max)))
  3593. (recenter -1)
  3594. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3595. (progn
  3596. (goto-char (or start-pos 1))
  3597. (recenter 1))))
  3598. (goto-char (or start-pos 1))
  3599. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3600. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3601. (org-agenda-show-clocking-issues))
  3602. (org-finalize-agenda)
  3603. (setq buffer-read-only t)
  3604. (message "")))
  3605. (defun org-agenda-ndays-to-span (n)
  3606. "Return a span symbol for a span of N days, or N if none matches."
  3607. (cond ((symbolp n) n)
  3608. ((= n 1) 'day)
  3609. ((= n 7) 'week)
  3610. (t n)))
  3611. (defun org-agenda-span-to-ndays (span start-day)
  3612. "Return ndays from SPAN starting at START-DAY."
  3613. (cond ((numberp span) span)
  3614. ((eq span 'day) 1)
  3615. ((eq span 'week) 7)
  3616. ((eq span 'month)
  3617. (let ((date (calendar-gregorian-from-absolute start-day)))
  3618. (calendar-last-day-of-month (car date) (caddr date))))
  3619. ((eq span 'year)
  3620. (let ((date (calendar-gregorian-from-absolute start-day)))
  3621. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3622. (defun org-agenda-span-name (span)
  3623. "Return a SPAN name."
  3624. (if (null span)
  3625. ""
  3626. (if (symbolp span)
  3627. (capitalize (symbol-name span))
  3628. (format "%d days" span))))
  3629. ;;; Agenda word search
  3630. (defvar org-agenda-search-history nil)
  3631. (defvar org-todo-only nil)
  3632. (defvar org-search-syntax-table nil
  3633. "Special syntax table for org-mode search.
  3634. In this table, we have single quotes not as word constituents, to
  3635. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3636. (defun org-search-syntax-table ()
  3637. (unless org-search-syntax-table
  3638. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3639. (modify-syntax-entry ?' "." org-search-syntax-table)
  3640. (modify-syntax-entry ?` "." org-search-syntax-table))
  3641. org-search-syntax-table)
  3642. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3643. ;;;###autoload
  3644. (defun org-search-view (&optional todo-only string edit-at)
  3645. "Show all entries that contain a phrase or words or regular expressions.
  3646. With optional prefix argument TODO-ONLY, only consider entries that are
  3647. TODO entries. The argument STRING can be used to pass a default search
  3648. string into this function. If EDIT-AT is non-nil, it means that the
  3649. user should get a chance to edit this string, with cursor at position
  3650. EDIT-AT.
  3651. The search string can be viewed either as a phrase that should be found as
  3652. is, or it can be broken into a number of snippets, each of which must match
  3653. in a Boolean way to select an entry. The default depends on the variable
  3654. `org-agenda-search-view-always-boolean'.
  3655. Even if this is turned off (the default) you can always switch to
  3656. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3657. The default is a direct search of the whole phrase, where each space in
  3658. the search string can expand to an arbitrary amount of whitespace,
  3659. including newlines.
  3660. If using a Boolean search, the search string is split on whitespace and
  3661. each snippet is searched separately, with logical AND to select an entry.
  3662. Words prefixed with a minus must *not* occur in the entry. Words without
  3663. a prefix or prefixed with a plus must occur in the entry. Matching is
  3664. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3665. match whole words, not parts of a word) if
  3666. `org-agenda-search-view-force-full-words' is set (default is nil).
  3667. Boolean search snippets enclosed by curly braces are interpreted as
  3668. regular expressions that must or (when preceded with \"-\") must not
  3669. match in the entry. Snippets enclosed into double quotes will be taken
  3670. as a whole, to include whitespace.
  3671. - If the search string starts with an asterisk, search only in headlines.
  3672. - If (possibly after the leading star) the search string starts with an
  3673. exclamation mark, this also means to look at TODO entries only, an effect
  3674. that can also be achieved with a prefix argument.
  3675. - If (possibly after star and exclamation mark) the search string starts
  3676. with a colon, this will mean that the (non-regexp) snippets of the
  3677. Boolean search must match as full words.
  3678. This command searches the agenda files, and in addition the files listed
  3679. in `org-agenda-text-search-extra-files'."
  3680. (interactive "P")
  3681. (org-prepare-agenda "SEARCH")
  3682. (org-compile-prefix-format 'search)
  3683. (org-set-sorting-strategy 'search)
  3684. (let* ((props (list 'face nil
  3685. 'done-face 'org-agenda-done
  3686. 'org-not-done-regexp org-not-done-regexp
  3687. 'org-todo-regexp org-todo-regexp
  3688. 'org-complex-heading-regexp org-complex-heading-regexp
  3689. 'mouse-face 'highlight
  3690. 'help-echo (format "mouse-2 or RET jump to location")))
  3691. (full-words org-agenda-search-view-force-full-words)
  3692. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3693. regexp rtn rtnall files file pos
  3694. marker category org-category-pos tags c neg re boolean
  3695. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3696. (unless (and (not edit-at)
  3697. (stringp string)
  3698. (string-match "\\S-" string))
  3699. (setq string (read-string
  3700. (if org-agenda-search-view-always-boolean
  3701. "[+-]Word/{Regexp} ...: "
  3702. "Phrase, or [+-]Word/{Regexp} ...: ")
  3703. (cond
  3704. ((integerp edit-at) (cons string edit-at))
  3705. (edit-at string))
  3706. 'org-agenda-search-history)))
  3707. (org-set-local 'org-todo-only todo-only)
  3708. (setq org-agenda-redo-command
  3709. (list 'org-search-view (if todo-only t nil) string
  3710. '(if current-prefix-arg 1 nil)))
  3711. (setq org-agenda-query-string string)
  3712. (if (equal (string-to-char string) ?*)
  3713. (setq hdl-only t
  3714. words (substring string 1))
  3715. (setq words string))
  3716. (when (equal (string-to-char words) ?!)
  3717. (setq todo-only t
  3718. words (substring words 1)))
  3719. (when (equal (string-to-char words) ?:)
  3720. (setq full-words t
  3721. words (substring words 1)))
  3722. (if (or org-agenda-search-view-always-boolean
  3723. (member (string-to-char words) '(?- ?+ ?\{)))
  3724. (setq boolean t))
  3725. (setq words (org-split-string words))
  3726. (let (www w)
  3727. (while (setq w (pop words))
  3728. (while (and (string-match "\\\\\\'" w) words)
  3729. (setq w (concat (substring w 0 -1) " " (pop words))))
  3730. (push w www))
  3731. (setq words (nreverse www) www nil)
  3732. (while (setq w (pop words))
  3733. (when (and (string-match "\\`[-+]?{" w)
  3734. (not (string-match "}\\'" w)))
  3735. (while (and words (not (string-match "}\\'" (car words))))
  3736. (setq w (concat w " " (pop words))))
  3737. (setq w (concat w " " (pop words))))
  3738. (push w www))
  3739. (setq words (nreverse www)))
  3740. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3741. (when boolean
  3742. (let (wds w)
  3743. (while (setq w (pop words))
  3744. (if (or (equal (substring w 0 1) "\"")
  3745. (and (> (length w) 1)
  3746. (member (substring w 0 1) '("+" "-"))
  3747. (equal (substring w 1 2) "\"")))
  3748. (while (and words (not (equal (substring w -1) "\"")))
  3749. (setq w (concat w " " (pop words)))))
  3750. (and (string-match "\\`\\([-+]?\\)\"" w)
  3751. (setq w (replace-match "\\1" nil nil w)))
  3752. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3753. (push w wds))
  3754. (setq words (nreverse wds))))
  3755. (if boolean
  3756. (mapc (lambda (w)
  3757. (setq c (string-to-char w))
  3758. (if (equal c ?-)
  3759. (setq neg t w (substring w 1))
  3760. (if (equal c ?+)
  3761. (setq neg nil w (substring w 1))
  3762. (setq neg nil)))
  3763. (if (string-match "\\`{.*}\\'" w)
  3764. (setq re (substring w 1 -1))
  3765. (if full-words
  3766. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3767. (setq re (regexp-quote (downcase w)))))
  3768. (if neg (push re regexps-) (push re regexps+)))
  3769. words)
  3770. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3771. regexps+))
  3772. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3773. (if (not regexps+)
  3774. (setq regexp org-outline-regexp-bol)
  3775. (setq regexp (pop regexps+))
  3776. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3777. regexp))))
  3778. (setq files (org-agenda-files nil 'ifmode))
  3779. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3780. (pop org-agenda-text-search-extra-files)
  3781. (setq files (org-add-archive-files files)))
  3782. (setq files (append files org-agenda-text-search-extra-files)
  3783. rtnall nil)
  3784. (while (setq file (pop files))
  3785. (setq ee nil)
  3786. (catch 'nextfile
  3787. (org-check-agenda-file file)
  3788. (setq buffer (if (file-exists-p file)
  3789. (org-get-agenda-file-buffer file)
  3790. (error "No such file %s" file)))
  3791. (if (not buffer)
  3792. ;; If file does not exist, make sure an error message is sent
  3793. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3794. file))))
  3795. (with-current-buffer buffer
  3796. (with-syntax-table (org-search-syntax-table)
  3797. (unless (derived-mode-p 'org-mode)
  3798. (error "Agenda file %s is not in `org-mode'" file))
  3799. (let ((case-fold-search t))
  3800. (save-excursion
  3801. (save-restriction
  3802. (if org-agenda-restrict
  3803. (narrow-to-region org-agenda-restrict-begin
  3804. org-agenda-restrict-end)
  3805. (widen))
  3806. (goto-char (point-min))
  3807. (unless (or (org-at-heading-p)
  3808. (outline-next-heading))
  3809. (throw 'nextfile t))
  3810. (goto-char (max (point-min) (1- (point))))
  3811. (while (re-search-forward regexp nil t)
  3812. (org-back-to-heading t)
  3813. (skip-chars-forward "* ")
  3814. (setq beg (point-at-bol)
  3815. beg1 (point)
  3816. end (progn (outline-next-heading) (point)))
  3817. (catch :skip
  3818. (goto-char beg)
  3819. (org-agenda-skip)
  3820. (setq str (buffer-substring-no-properties
  3821. (point-at-bol)
  3822. (if hdl-only (point-at-eol) end)))
  3823. (mapc (lambda (wr) (when (string-match wr str)
  3824. (goto-char (1- end))
  3825. (throw :skip t)))
  3826. regexps-)
  3827. (mapc (lambda (wr) (unless (string-match wr str)
  3828. (goto-char (1- end))
  3829. (throw :skip t)))
  3830. (if todo-only
  3831. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3832. regexps+)
  3833. regexps+))
  3834. (goto-char beg)
  3835. (setq marker (org-agenda-new-marker (point))
  3836. category (org-get-category)
  3837. org-category-pos (get-text-property (point) 'org-category-position)
  3838. tags (org-get-tags-at (point))
  3839. txt (org-agenda-format-item
  3840. ""
  3841. (buffer-substring-no-properties
  3842. beg1 (point-at-eol))
  3843. category tags))
  3844. (org-add-props txt props
  3845. 'org-marker marker 'org-hd-marker marker
  3846. 'org-todo-regexp org-todo-regexp
  3847. 'org-complex-heading-regexp org-complex-heading-regexp
  3848. 'priority 1000 'org-category category
  3849. 'org-category-position org-category-pos
  3850. 'type "search")
  3851. (push txt ee)
  3852. (goto-char (1- end))))))))))
  3853. (setq rtn (nreverse ee))
  3854. (setq rtnall (append rtnall rtn)))
  3855. (if org-agenda-overriding-header
  3856. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3857. nil 'face 'org-agenda-structure) "\n")
  3858. (insert "Search words: ")
  3859. (add-text-properties (point-min) (1- (point))
  3860. (list 'face 'org-agenda-structure))
  3861. (setq pos (point))
  3862. (insert string "\n")
  3863. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3864. (setq pos (point))
  3865. (unless org-agenda-multi
  3866. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3867. (add-text-properties pos (1- (point))
  3868. (list 'face 'org-agenda-structure))))
  3869. (org-agenda-mark-header-line (point-min))
  3870. (when rtnall
  3871. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3872. (goto-char (point-min))
  3873. (or org-agenda-multi (org-fit-agenda-window))
  3874. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3875. (org-finalize-agenda)
  3876. (setq buffer-read-only t)))
  3877. ;;; Agenda TODO list
  3878. (defvar org-select-this-todo-keyword nil)
  3879. (defvar org-last-arg nil)
  3880. ;;;###autoload
  3881. (defun org-todo-list (arg)
  3882. "Show all (not done) TODO entries from all agenda file in a single list.
  3883. The prefix arg can be used to select a specific TODO keyword and limit
  3884. the list to these. When using \\[universal-argument], you will be prompted
  3885. for a keyword. A numeric prefix directly selects the Nth keyword in
  3886. `org-todo-keywords-1'."
  3887. (interactive "P")
  3888. (org-prepare-agenda "TODO")
  3889. (org-compile-prefix-format 'todo)
  3890. (org-set-sorting-strategy 'todo)
  3891. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3892. (let* ((today (org-today))
  3893. (date (calendar-gregorian-from-absolute today))
  3894. (kwds org-todo-keywords-for-agenda)
  3895. (completion-ignore-case t)
  3896. (org-select-this-todo-keyword
  3897. (if (stringp arg) arg
  3898. (and arg (integerp arg) (> arg 0)
  3899. (nth (1- arg) kwds))))
  3900. rtn rtnall files file pos)
  3901. (when (equal arg '(4))
  3902. (setq org-select-this-todo-keyword
  3903. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3904. (mapcar 'list kwds) nil nil)))
  3905. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3906. (org-set-local 'org-last-arg arg)
  3907. (setq org-agenda-redo-command
  3908. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3909. (setq files (org-agenda-files nil 'ifmode)
  3910. rtnall nil)
  3911. (while (setq file (pop files))
  3912. (catch 'nextfile
  3913. (org-check-agenda-file file)
  3914. (setq rtn (org-agenda-get-day-entries file date :todo))
  3915. (setq rtnall (append rtnall rtn))))
  3916. (if org-agenda-overriding-header
  3917. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3918. nil 'face 'org-agenda-structure) "\n")
  3919. (insert "Global list of TODO items of type: ")
  3920. (add-text-properties (point-min) (1- (point))
  3921. (list 'face 'org-agenda-structure
  3922. 'short-heading
  3923. (concat "ToDo: "
  3924. (or org-select-this-todo-keyword "ALL"))))
  3925. (org-agenda-mark-header-line (point-min))
  3926. (setq pos (point))
  3927. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3928. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3929. (setq pos (point))
  3930. (unless org-agenda-multi
  3931. (insert "Available with `N r': (0)ALL")
  3932. (let ((n 0) s)
  3933. (mapc (lambda (x)
  3934. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3935. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3936. (insert "\n "))
  3937. (insert " " s))
  3938. kwds))
  3939. (insert "\n"))
  3940. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3941. (org-agenda-mark-header-line (point-min))
  3942. (when rtnall
  3943. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3944. (goto-char (point-min))
  3945. (or org-agenda-multi (org-fit-agenda-window))
  3946. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3947. (org-finalize-agenda)
  3948. (setq buffer-read-only t)))
  3949. ;;; Agenda tags match
  3950. ;;;###autoload
  3951. (defun org-tags-view (&optional todo-only match)
  3952. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3953. The prefix arg TODO-ONLY limits the search to TODO entries."
  3954. (interactive "P")
  3955. (let* ((org-tags-match-list-sublevels
  3956. org-tags-match-list-sublevels)
  3957. (completion-ignore-case t)
  3958. rtn rtnall files file pos matcher
  3959. buffer)
  3960. (when (and (stringp match) (not (string-match "\\S-" match)))
  3961. (setq match nil))
  3962. (setq matcher (org-make-tags-matcher match)
  3963. match (car matcher) matcher (cdr matcher))
  3964. (org-prepare-agenda (concat "TAGS " match))
  3965. (org-compile-prefix-format 'tags)
  3966. (org-set-sorting-strategy 'tags)
  3967. (setq org-agenda-query-string match)
  3968. (setq org-agenda-redo-command
  3969. (list 'org-tags-view (list 'quote todo-only)
  3970. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3971. (setq files (org-agenda-files nil 'ifmode)
  3972. rtnall nil)
  3973. (while (setq file (pop files))
  3974. (catch 'nextfile
  3975. (org-check-agenda-file file)
  3976. (setq buffer (if (file-exists-p file)
  3977. (org-get-agenda-file-buffer file)
  3978. (error "No such file %s" file)))
  3979. (if (not buffer)
  3980. ;; If file does not exist, error message to agenda
  3981. (setq rtn (list
  3982. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3983. rtnall (append rtnall rtn))
  3984. (with-current-buffer buffer
  3985. (unless (derived-mode-p 'org-mode)
  3986. (error "Agenda file %s is not in `org-mode'" file))
  3987. (save-excursion
  3988. (save-restriction
  3989. (if org-agenda-restrict
  3990. (narrow-to-region org-agenda-restrict-begin
  3991. org-agenda-restrict-end)
  3992. (widen))
  3993. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3994. (setq rtnall (append rtnall rtn))))))))
  3995. (if org-agenda-overriding-header
  3996. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3997. nil 'face 'org-agenda-structure) "\n")
  3998. (insert "Headlines with TAGS match: ")
  3999. (add-text-properties (point-min) (1- (point))
  4000. (list 'face 'org-agenda-structure
  4001. 'short-heading
  4002. (concat "Match: " match)))
  4003. (setq pos (point))
  4004. (insert match "\n")
  4005. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4006. (setq pos (point))
  4007. (unless org-agenda-multi
  4008. (insert "Press `C-u r' to search again with new search string\n"))
  4009. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4010. (org-agenda-mark-header-line (point-min))
  4011. (when rtnall
  4012. (insert (org-finalize-agenda-entries rtnall) "\n"))
  4013. (goto-char (point-min))
  4014. (or org-agenda-multi (org-fit-agenda-window))
  4015. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  4016. (org-finalize-agenda)
  4017. (setq buffer-read-only t)))
  4018. ;;; Agenda Finding stuck projects
  4019. (defvar org-agenda-skip-regexp nil
  4020. "Regular expression used in skipping subtrees for the agenda.
  4021. This is basically a temporary global variable that can be set and then
  4022. used by user-defined selections using `org-agenda-skip-function'.")
  4023. (defvar org-agenda-overriding-header nil
  4024. "When set during agenda, todo and tags searches it replaces the header.
  4025. This variable should not be set directly, but custom commands can bind it
  4026. in the options section.")
  4027. (defun org-agenda-skip-entry-when-regexp-matches ()
  4028. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4029. If yes, it returns the end position of this entry, causing agenda commands
  4030. to skip the entry but continuing the search in the subtree. This is a
  4031. function that can be put into `org-agenda-skip-function' for the duration
  4032. of a command."
  4033. (let ((end (save-excursion (org-end-of-subtree t)))
  4034. skip)
  4035. (save-excursion
  4036. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4037. (and skip end)))
  4038. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4039. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4040. If yes, it returns the end position of this tree, causing agenda commands
  4041. to skip this subtree. This is a function that can be put into
  4042. `org-agenda-skip-function' for the duration of a command."
  4043. (let ((end (save-excursion (org-end-of-subtree t)))
  4044. skip)
  4045. (save-excursion
  4046. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4047. (and skip end)))
  4048. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4049. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4050. If yes, it returns the end position of the current entry (NOT the tree),
  4051. causing agenda commands to skip the entry but continuing the search in
  4052. the subtree. This is a function that can be put into
  4053. `org-agenda-skip-function' for the duration of a command. An important
  4054. use of this function is for the stuck project list."
  4055. (let ((end (save-excursion (org-end-of-subtree t)))
  4056. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4057. skip)
  4058. (save-excursion
  4059. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4060. (and skip entry-end)))
  4061. (defun org-agenda-skip-entry-if (&rest conditions)
  4062. "Skip entry if any of CONDITIONS is true.
  4063. See `org-agenda-skip-if' for details."
  4064. (org-agenda-skip-if nil conditions))
  4065. (defun org-agenda-skip-subtree-if (&rest conditions)
  4066. "Skip entry if any of CONDITIONS is true.
  4067. See `org-agenda-skip-if' for details."
  4068. (org-agenda-skip-if t conditions))
  4069. (defun org-agenda-skip-if (subtree conditions)
  4070. "Checks current entity for CONDITIONS.
  4071. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4072. the entry (i.e. the text before the next heading) is checked.
  4073. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4074. from different tests. Valid conditions are:
  4075. scheduled Check if there is a scheduled cookie
  4076. notscheduled Check if there is no scheduled cookie
  4077. deadline Check if there is a deadline
  4078. notdeadline Check if there is no deadline
  4079. timestamp Check if there is a timestamp (also deadline or scheduled)
  4080. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4081. regexp Check if regexp matches
  4082. notregexp Check if regexp does not match.
  4083. todo Check if TODO keyword matches
  4084. nottodo Check if TODO keyword does not match
  4085. The regexp is taken from the conditions list, it must come right after
  4086. the `regexp' or `notregexp' element.
  4087. `todo' and `nottodo' accept as an argument a list of todo
  4088. keywords, which may include \"*\" to match any todo keyword.
  4089. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4090. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4091. Instead of a list, a keyword class may be given. For example:
  4092. (org-agenda-skip-entry-if 'nottodo 'done)
  4093. would skip entries that haven't been marked with any of \"DONE\"
  4094. keywords. Possible classes are: `todo', `done', `any'.
  4095. If any of these conditions is met, this function returns the end point of
  4096. the entity, causing the search to continue from there. This is a function
  4097. that can be put into `org-agenda-skip-function' for the duration of a command."
  4098. (let (beg end m)
  4099. (org-back-to-heading t)
  4100. (setq beg (point)
  4101. end (if subtree
  4102. (progn (org-end-of-subtree t) (point))
  4103. (progn (outline-next-heading) (1- (point)))))
  4104. (goto-char beg)
  4105. (and
  4106. (or
  4107. (and (memq 'scheduled conditions)
  4108. (re-search-forward org-scheduled-time-regexp end t))
  4109. (and (memq 'notscheduled conditions)
  4110. (not (re-search-forward org-scheduled-time-regexp end t)))
  4111. (and (memq 'deadline conditions)
  4112. (re-search-forward org-deadline-time-regexp end t))
  4113. (and (memq 'notdeadline conditions)
  4114. (not (re-search-forward org-deadline-time-regexp end t)))
  4115. (and (memq 'timestamp conditions)
  4116. (re-search-forward org-ts-regexp end t))
  4117. (and (memq 'nottimestamp conditions)
  4118. (not (re-search-forward org-ts-regexp end t)))
  4119. (and (setq m (memq 'regexp conditions))
  4120. (stringp (nth 1 m))
  4121. (re-search-forward (nth 1 m) end t))
  4122. (and (setq m (memq 'notregexp conditions))
  4123. (stringp (nth 1 m))
  4124. (not (re-search-forward (nth 1 m) end t)))
  4125. (and (or
  4126. (setq m (memq 'nottodo conditions))
  4127. (setq m (memq 'todo-unblocked conditions))
  4128. (setq m (memq 'nottodo-unblocked conditions))
  4129. (setq m (memq 'todo conditions)))
  4130. (org-agenda-skip-if-todo m end)))
  4131. end)))
  4132. (defun org-agenda-skip-if-todo (args end)
  4133. "Helper function for `org-agenda-skip-if', do not use it directly.
  4134. ARGS is a list with first element either `todo', `nottodo',
  4135. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4136. a list of TODO keywords, or a state symbol `todo' or `done' or
  4137. `any'."
  4138. (let ((kw (car args))
  4139. (arg (cadr args))
  4140. todo-wds todo-re)
  4141. (setq todo-wds
  4142. (org-uniquify
  4143. (cond
  4144. ((listp arg) ;; list of keywords
  4145. (if (member "*" arg)
  4146. (mapcar 'substring-no-properties org-todo-keywords-1)
  4147. arg))
  4148. ((symbolp arg) ;; keyword class name
  4149. (cond
  4150. ((eq arg 'todo)
  4151. (org-delete-all org-done-keywords
  4152. (mapcar 'substring-no-properties
  4153. org-todo-keywords-1)))
  4154. ((eq arg 'done) org-done-keywords)
  4155. ((eq arg 'any)
  4156. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4157. (setq todo-re
  4158. (concat "^\\*+[ \t]+\\<\\("
  4159. (mapconcat 'identity todo-wds "\\|")
  4160. "\\)\\>"))
  4161. (cond
  4162. ((eq kw 'todo) (re-search-forward todo-re end t))
  4163. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4164. ((eq kw 'todo-unblocked)
  4165. (catch 'unblocked
  4166. (while (re-search-forward todo-re end t)
  4167. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4168. nil))
  4169. ((eq kw 'nottodo-unblocked)
  4170. (catch 'unblocked
  4171. (while (re-search-forward todo-re end t)
  4172. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4173. t))
  4174. )))
  4175. ;;;###autoload
  4176. (defun org-agenda-list-stuck-projects (&rest ignore)
  4177. "Create agenda view for projects that are stuck.
  4178. Stuck projects are project that have no next actions. For the definitions
  4179. of what a project is and how to check if it stuck, customize the variable
  4180. `org-stuck-projects'."
  4181. (interactive)
  4182. (let* ((org-agenda-skip-function
  4183. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4184. ;; We could have used org-agenda-skip-if here.
  4185. (org-agenda-overriding-header
  4186. (or org-agenda-overriding-header "List of stuck projects: "))
  4187. (matcher (nth 0 org-stuck-projects))
  4188. (todo (nth 1 org-stuck-projects))
  4189. (todo-wds (if (member "*" todo)
  4190. (progn
  4191. (org-prepare-agenda-buffers (org-agenda-files
  4192. nil 'ifmode))
  4193. (org-delete-all
  4194. org-done-keywords-for-agenda
  4195. (copy-sequence org-todo-keywords-for-agenda)))
  4196. todo))
  4197. (todo-re (concat "^\\*+[ \t]+\\("
  4198. (mapconcat 'identity todo-wds "\\|")
  4199. "\\)\\>"))
  4200. (tags (nth 2 org-stuck-projects))
  4201. (tags-re (if (member "*" tags)
  4202. (concat org-outline-regexp-bol
  4203. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4204. (if tags
  4205. (concat org-outline-regexp-bol
  4206. ".*:\\("
  4207. (mapconcat 'identity tags "\\|")
  4208. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4209. (gen-re (nth 3 org-stuck-projects))
  4210. (re-list
  4211. (delq nil
  4212. (list
  4213. (if todo todo-re)
  4214. (if tags tags-re)
  4215. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4216. gen-re)))))
  4217. (setq org-agenda-skip-regexp
  4218. (if re-list
  4219. (mapconcat 'identity re-list "\\|")
  4220. (error "No information how to identify unstuck projects")))
  4221. (org-tags-view nil matcher)
  4222. (with-current-buffer org-agenda-buffer-name
  4223. (setq org-agenda-redo-command
  4224. '(org-agenda-list-stuck-projects
  4225. (or current-prefix-arg org-last-arg))))))
  4226. ;;; Diary integration
  4227. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4228. (defvar diary-list-entries-hook)
  4229. (defvar diary-time-regexp)
  4230. (defun org-get-entries-from-diary (date)
  4231. "Get the (Emacs Calendar) diary entries for DATE."
  4232. (require 'diary-lib)
  4233. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4234. (diary-display-hook '(fancy-diary-display))
  4235. (diary-display-function 'fancy-diary-display)
  4236. (pop-up-frames nil)
  4237. (diary-list-entries-hook
  4238. (cons 'org-diary-default-entry diary-list-entries-hook))
  4239. (diary-file-name-prefix-function nil) ; turn this feature off
  4240. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4241. entries
  4242. (org-disable-agenda-to-diary t))
  4243. (save-excursion
  4244. (save-window-excursion
  4245. (funcall (if (fboundp 'diary-list-entries)
  4246. 'diary-list-entries 'list-diary-entries)
  4247. date 1)))
  4248. (if (not (get-buffer diary-fancy-buffer))
  4249. (setq entries nil)
  4250. (with-current-buffer diary-fancy-buffer
  4251. (setq buffer-read-only nil)
  4252. (if (zerop (buffer-size))
  4253. ;; No entries
  4254. (setq entries nil)
  4255. ;; Omit the date and other unnecessary stuff
  4256. (org-agenda-cleanup-fancy-diary)
  4257. ;; Add prefix to each line and extend the text properties
  4258. (if (zerop (buffer-size))
  4259. (setq entries nil)
  4260. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4261. (setq entries
  4262. (with-temp-buffer
  4263. (insert entries) (goto-char (point-min))
  4264. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4265. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4266. (replace-match (concat "; " (match-string 1)))))
  4267. (buffer-string)))))
  4268. (set-buffer-modified-p nil)
  4269. (kill-buffer diary-fancy-buffer)))
  4270. (when entries
  4271. (setq entries (org-split-string entries "\n"))
  4272. (setq entries
  4273. (mapcar
  4274. (lambda (x)
  4275. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4276. ;; Extend the text properties to the beginning of the line
  4277. (org-add-props x (text-properties-at (1- (length x)) x)
  4278. 'type "diary" 'date date 'face 'org-agenda-diary))
  4279. entries)))))
  4280. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4281. "Hook run when the fancy diary buffer is cleaned up.")
  4282. (defun org-agenda-cleanup-fancy-diary ()
  4283. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4284. This gets rid of the date, the underline under the date, and
  4285. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4286. date. It also removes lines that contain only whitespace."
  4287. (goto-char (point-min))
  4288. (if (looking-at ".*?:[ \t]*")
  4289. (progn
  4290. (replace-match "")
  4291. (re-search-forward "\n=+$" nil t)
  4292. (replace-match "")
  4293. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4294. (re-search-forward "\n=+$" nil t)
  4295. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4296. (goto-char (point-min))
  4297. (while (re-search-forward "^ +\n" nil t)
  4298. (replace-match ""))
  4299. (goto-char (point-min))
  4300. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4301. (replace-match ""))
  4302. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4303. ;; Make sure entries from the diary have the right text properties.
  4304. (eval-after-load "diary-lib"
  4305. '(if (boundp 'diary-modify-entry-list-string-function)
  4306. ;; We can rely on the hook, nothing to do
  4307. nil
  4308. ;; Hook not available, must use advice to make this work
  4309. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4310. "Make the position visible."
  4311. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4312. (stringp string)
  4313. buffer-file-name)
  4314. (setq string (org-modify-diary-entry-string string))))))
  4315. (defun org-modify-diary-entry-string (string)
  4316. "Add text properties to string, allowing org-mode to act on it."
  4317. (org-add-props string nil
  4318. 'mouse-face 'highlight
  4319. 'help-echo (if buffer-file-name
  4320. (format "mouse-2 or RET jump to diary file %s"
  4321. (abbreviate-file-name buffer-file-name))
  4322. "")
  4323. 'org-agenda-diary-link t
  4324. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4325. (defun org-diary-default-entry ()
  4326. "Add a dummy entry to the diary.
  4327. Needed to avoid empty dates which mess up holiday display."
  4328. ;; Catch the error if dealing with the new add-to-diary-alist
  4329. (when org-disable-agenda-to-diary
  4330. (condition-case nil
  4331. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4332. (error
  4333. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4334. (defun org-add-to-diary-list (&rest args)
  4335. (if (fboundp 'diary-add-to-list)
  4336. (apply 'diary-add-to-list args)
  4337. (apply 'add-to-diary-list args)))
  4338. (defvar org-diary-last-run-time nil)
  4339. ;;;###autoload
  4340. (defun org-diary (&rest args)
  4341. "Return diary information from org-files.
  4342. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4343. It accesses org files and extracts information from those files to be
  4344. listed in the diary. The function accepts arguments specifying what
  4345. items should be listed. For a list of arguments allowed here, see the
  4346. variable `org-agenda-entry-types'.
  4347. The call in the diary file should look like this:
  4348. &%%(org-diary) ~/path/to/some/orgfile.org
  4349. Use a separate line for each org file to check. Or, if you omit the file name,
  4350. all files listed in `org-agenda-files' will be checked automatically:
  4351. &%%(org-diary)
  4352. If you don't give any arguments (as in the example above), the default
  4353. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4354. So the example above may also be written as
  4355. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4356. The function expects the lisp variables `entry' and `date' to be provided
  4357. by the caller, because this is how the calendar works. Don't use this
  4358. function from a program - use `org-agenda-get-day-entries' instead."
  4359. (when (> (- (org-float-time)
  4360. org-agenda-last-marker-time)
  4361. 5)
  4362. ;; I am not sure if this works with sticky agendas, because the marker
  4363. ;; list is then no longer a global variable.
  4364. (org-agenda-reset-markers))
  4365. ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
  4366. (when (buffer-live-p org-agenda-buffer)
  4367. (org-compile-prefix-format 'agenda))
  4368. (org-set-sorting-strategy 'agenda)
  4369. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4370. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4371. (list entry)
  4372. (org-agenda-files t)))
  4373. (time (org-float-time))
  4374. file rtn results)
  4375. (when (or (not org-diary-last-run-time)
  4376. (> (- time
  4377. org-diary-last-run-time)
  4378. 3))
  4379. (org-prepare-agenda-buffers files))
  4380. (setq org-diary-last-run-time time)
  4381. ;; If this is called during org-agenda, don't return any entries to
  4382. ;; the calendar. Org Agenda will list these entries itself.
  4383. (if org-disable-agenda-to-diary (setq files nil))
  4384. (while (setq file (pop files))
  4385. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4386. (setq results (append results rtn)))
  4387. (if results
  4388. (concat (org-finalize-agenda-entries results) "\n"))))
  4389. ;;; Agenda entry finders
  4390. (defun org-agenda-get-day-entries (file date &rest args)
  4391. "Does the work for `org-diary' and `org-agenda'.
  4392. FILE is the path to a file to be checked for entries. DATE is date like
  4393. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4394. which kind of entries should be extracted. For details about these, see
  4395. the documentation of `org-diary'."
  4396. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4397. (let* ((org-startup-folded nil)
  4398. (org-startup-align-all-tables nil)
  4399. (buffer (if (file-exists-p file)
  4400. (org-get-agenda-file-buffer file)
  4401. (error "No such file %s" file)))
  4402. arg results rtn deadline-results)
  4403. (if (not buffer)
  4404. ;; If file does not exist, make sure an error message ends up in diary
  4405. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4406. (with-current-buffer buffer
  4407. (unless (derived-mode-p 'org-mode)
  4408. (error "Agenda file %s is not in `org-mode'" file))
  4409. (let ((case-fold-search nil))
  4410. (save-excursion
  4411. (save-restriction
  4412. (if org-agenda-restrict
  4413. (narrow-to-region org-agenda-restrict-begin
  4414. org-agenda-restrict-end)
  4415. (widen))
  4416. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4417. (while (setq arg (pop args))
  4418. (cond
  4419. ((and (eq arg :todo)
  4420. (equal date (calendar-gregorian-from-absolute
  4421. (org-today))))
  4422. (setq rtn (org-agenda-get-todos))
  4423. (setq results (append results rtn)))
  4424. ((eq arg :timestamp)
  4425. (setq rtn (org-agenda-get-blocks))
  4426. (setq results (append results rtn))
  4427. (setq rtn (org-agenda-get-timestamps deadline-results))
  4428. (setq results (append results rtn)))
  4429. ((eq arg :sexp)
  4430. (setq rtn (org-agenda-get-sexps))
  4431. (setq results (append results rtn)))
  4432. ((eq arg :scheduled)
  4433. (setq rtn (org-agenda-get-scheduled deadline-results))
  4434. (setq results (append results rtn)))
  4435. ((eq arg :closed)
  4436. (setq rtn (org-agenda-get-progress))
  4437. (setq results (append results rtn)))
  4438. ((eq arg :deadline)
  4439. (setq rtn (org-agenda-get-deadlines))
  4440. (setq deadline-results (copy-sequence rtn))
  4441. (setq results (append results rtn))))))))
  4442. results))))
  4443. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4444. (defun org-agenda-get-todos ()
  4445. "Return the TODO information for agenda display."
  4446. (let* ((props (list 'face nil
  4447. 'done-face 'org-agenda-done
  4448. 'org-not-done-regexp org-not-done-regexp
  4449. 'org-todo-regexp org-todo-regexp
  4450. 'org-complex-heading-regexp org-complex-heading-regexp
  4451. 'mouse-face 'highlight
  4452. 'help-echo
  4453. (format "mouse-2 or RET jump to org file %s"
  4454. (abbreviate-file-name buffer-file-name))))
  4455. (regexp (format org-heading-keyword-regexp-format
  4456. (cond
  4457. ((and org-select-this-todo-keyword
  4458. (equal org-select-this-todo-keyword "*"))
  4459. org-todo-regexp)
  4460. (org-select-this-todo-keyword
  4461. (concat "\\("
  4462. (mapconcat 'identity
  4463. (org-split-string
  4464. org-select-this-todo-keyword
  4465. "|")
  4466. "\\|") "\\)"))
  4467. (t org-not-done-regexp))))
  4468. marker priority category org-category-pos tags todo-state
  4469. ee txt beg end)
  4470. (goto-char (point-min))
  4471. (while (re-search-forward regexp nil t)
  4472. (catch :skip
  4473. (save-match-data
  4474. (beginning-of-line)
  4475. (org-agenda-skip)
  4476. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4477. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4478. (goto-char (1+ beg))
  4479. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4480. (throw :skip nil)))
  4481. (goto-char (match-beginning 2))
  4482. (setq marker (org-agenda-new-marker (match-beginning 0))
  4483. category (org-get-category)
  4484. org-category-pos (get-text-property (point) 'org-category-position)
  4485. txt (org-trim
  4486. (buffer-substring (match-beginning 2) (match-end 0)))
  4487. tags (org-get-tags-at (point))
  4488. txt (org-agenda-format-item "" txt category tags)
  4489. priority (1+ (org-get-priority txt))
  4490. todo-state (org-get-todo-state))
  4491. (org-add-props txt props
  4492. 'org-marker marker 'org-hd-marker marker
  4493. 'priority priority 'org-category category
  4494. 'org-category-position org-category-pos
  4495. 'type "todo" 'todo-state todo-state)
  4496. (push txt ee)
  4497. (if org-agenda-todo-list-sublevels
  4498. (goto-char (match-end 2))
  4499. (org-end-of-subtree 'invisible))))
  4500. (nreverse ee)))
  4501. (defun org-agenda-todo-custom-ignore-p (time n)
  4502. "Check whether timestamp is farther away then n number of days.
  4503. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4504. `org-agenda-todo-ignore-scheduled' or
  4505. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4506. (let ((days (org-days-to-time time)))
  4507. (if (>= n 0)
  4508. (>= days n)
  4509. (<= days n))))
  4510. ;;;###autoload
  4511. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4512. (&optional end)
  4513. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4514. (when (or org-agenda-todo-ignore-with-date
  4515. org-agenda-todo-ignore-scheduled
  4516. org-agenda-todo-ignore-deadlines
  4517. org-agenda-todo-ignore-timestamp)
  4518. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4519. (save-excursion
  4520. (or (and org-agenda-todo-ignore-with-date
  4521. (re-search-forward org-ts-regexp end t))
  4522. (and org-agenda-todo-ignore-scheduled
  4523. (re-search-forward org-scheduled-time-regexp end t)
  4524. (cond
  4525. ((eq org-agenda-todo-ignore-scheduled 'future)
  4526. (> (org-days-to-time (match-string 1)) 0))
  4527. ((eq org-agenda-todo-ignore-scheduled 'past)
  4528. (<= (org-days-to-time (match-string 1)) 0))
  4529. ((numberp org-agenda-todo-ignore-scheduled)
  4530. (org-agenda-todo-custom-ignore-p
  4531. (match-string 1) org-agenda-todo-ignore-scheduled))
  4532. (t)))
  4533. (and org-agenda-todo-ignore-deadlines
  4534. (re-search-forward org-deadline-time-regexp end t)
  4535. (cond
  4536. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4537. ((eq org-agenda-todo-ignore-deadlines 'far)
  4538. (not (org-deadline-close (match-string 1))))
  4539. ((eq org-agenda-todo-ignore-deadlines 'future)
  4540. (> (org-days-to-time (match-string 1)) 0))
  4541. ((eq org-agenda-todo-ignore-deadlines 'past)
  4542. (<= (org-days-to-time (match-string 1)) 0))
  4543. ((numberp org-agenda-todo-ignore-deadlines)
  4544. (org-agenda-todo-custom-ignore-p
  4545. (match-string 1) org-agenda-todo-ignore-deadlines))
  4546. (t (org-deadline-close (match-string 1)))))
  4547. (and org-agenda-todo-ignore-timestamp
  4548. (let ((buffer (current-buffer))
  4549. (regexp
  4550. (concat
  4551. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4552. (start (point)))
  4553. ;; Copy current buffer into a temporary one
  4554. (with-temp-buffer
  4555. (insert-buffer-substring buffer start end)
  4556. (goto-char (point-min))
  4557. ;; Delete SCHEDULED and DEADLINE items
  4558. (while (re-search-forward regexp end t)
  4559. (delete-region (match-beginning 0) (match-end 0)))
  4560. (goto-char (point-min))
  4561. ;; No search for timestamp left
  4562. (when (re-search-forward org-ts-regexp nil t)
  4563. (cond
  4564. ((eq org-agenda-todo-ignore-timestamp 'future)
  4565. (> (org-days-to-time (match-string 1)) 0))
  4566. ((eq org-agenda-todo-ignore-timestamp 'past)
  4567. (<= (org-days-to-time (match-string 1)) 0))
  4568. ((numberp org-agenda-todo-ignore-timestamp)
  4569. (org-agenda-todo-custom-ignore-p
  4570. (match-string 1) org-agenda-todo-ignore-timestamp))
  4571. (t))))))))))
  4572. (defconst org-agenda-no-heading-message
  4573. "No heading for this item in buffer or region.")
  4574. (defun org-agenda-get-timestamps (&optional deadline-results)
  4575. "Return the date stamp information for agenda display."
  4576. (let* ((props (list 'face 'org-agenda-calendar-event
  4577. 'org-not-done-regexp org-not-done-regexp
  4578. 'org-todo-regexp org-todo-regexp
  4579. 'org-complex-heading-regexp org-complex-heading-regexp
  4580. 'mouse-face 'highlight
  4581. 'help-echo
  4582. (format "mouse-2 or RET jump to org file %s"
  4583. (abbreviate-file-name buffer-file-name))))
  4584. (d1 (calendar-absolute-from-gregorian date))
  4585. mm
  4586. (deadline-position-alist
  4587. (mapcar (lambda (a) (and (setq mm (get-text-property
  4588. 0 'org-hd-marker a))
  4589. (cons (marker-position mm) a)))
  4590. deadline-results))
  4591. (remove-re
  4592. (concat
  4593. (regexp-quote
  4594. (format-time-string
  4595. "<%Y-%m-%d"
  4596. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4597. ".*?>"))
  4598. (regexp
  4599. (concat
  4600. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4601. (regexp-quote
  4602. (substring
  4603. (format-time-string
  4604. (car org-time-stamp-formats)
  4605. (apply 'encode-time ; DATE bound by calendar
  4606. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4607. 1 11))
  4608. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4609. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4610. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4611. donep tmp priority category org-category-pos ee txt timestr tags
  4612. b0 b3 e3 head todo-state end-of-match show-all)
  4613. (goto-char (point-min))
  4614. (while (setq end-of-match (re-search-forward regexp nil t))
  4615. (setq b0 (match-beginning 0)
  4616. b3 (match-beginning 3) e3 (match-end 3)
  4617. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4618. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4619. (member todo-state
  4620. org-agenda-repeating-timestamp-show-all)))
  4621. (catch :skip
  4622. (and (org-at-date-range-p) (throw :skip nil))
  4623. (org-agenda-skip)
  4624. (if (and (match-end 1)
  4625. (not (= d1 (org-time-string-to-absolute
  4626. (match-string 1) d1 nil show-all
  4627. (current-buffer) b0))))
  4628. (throw :skip nil))
  4629. (if (and e3
  4630. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4631. (throw :skip nil))
  4632. (setq tmp (buffer-substring (max (point-min)
  4633. (- b0 org-ds-keyword-length))
  4634. b0)
  4635. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4636. inactivep (= (char-after b0) ?\[)
  4637. deadlinep (string-match org-deadline-regexp tmp)
  4638. scheduledp (string-match org-scheduled-regexp tmp)
  4639. closedp (and org-agenda-include-inactive-timestamps
  4640. (string-match org-closed-string tmp))
  4641. clockp (and org-agenda-include-inactive-timestamps
  4642. (or (string-match org-clock-string tmp)
  4643. (string-match "]-+\\'" tmp)))
  4644. donep (member todo-state org-done-keywords))
  4645. (if (or scheduledp deadlinep closedp clockp
  4646. (and donep org-agenda-skip-timestamp-if-done))
  4647. (throw :skip t))
  4648. (if (string-match ">" timestr)
  4649. ;; substring should only run to end of time stamp
  4650. (setq timestr (substring timestr 0 (match-end 0))))
  4651. (setq marker (org-agenda-new-marker b0)
  4652. category (org-get-category b0)
  4653. org-category-pos (get-text-property b0 'org-category-position))
  4654. (save-excursion
  4655. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4656. (setq txt org-agenda-no-heading-message)
  4657. (goto-char (match-beginning 0))
  4658. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4659. (assoc (point) deadline-position-alist))
  4660. (throw :skip nil))
  4661. (setq hdmarker (org-agenda-new-marker)
  4662. tags (org-get-tags-at))
  4663. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4664. (setq head (or (match-string 1) ""))
  4665. (setq txt (org-agenda-format-item
  4666. (if inactivep org-agenda-inactive-leader nil)
  4667. head category tags timestr
  4668. remove-re)))
  4669. (setq priority (org-get-priority txt))
  4670. (org-add-props txt props
  4671. 'org-marker marker 'org-hd-marker hdmarker)
  4672. (org-add-props txt nil 'priority priority
  4673. 'org-category category 'date date
  4674. 'org-category-position org-category-pos
  4675. 'todo-state todo-state
  4676. 'type "timestamp")
  4677. (push txt ee))
  4678. (if org-agenda-skip-additional-timestamps-same-entry
  4679. (outline-next-heading)
  4680. (goto-char end-of-match))))
  4681. (nreverse ee)))
  4682. (defun org-agenda-get-sexps ()
  4683. "Return the sexp information for agenda display."
  4684. (require 'diary-lib)
  4685. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4686. 'mouse-face 'highlight
  4687. 'help-echo
  4688. (format "mouse-2 or RET jump to org file %s"
  4689. (abbreviate-file-name buffer-file-name))))
  4690. (regexp "^&?%%(")
  4691. marker category extra org-category-pos ee txt tags entry
  4692. result beg b sexp sexp-entry todo-state)
  4693. (goto-char (point-min))
  4694. (while (re-search-forward regexp nil t)
  4695. (catch :skip
  4696. (org-agenda-skip)
  4697. (setq beg (match-beginning 0))
  4698. (goto-char (1- (match-end 0)))
  4699. (setq b (point))
  4700. (forward-sexp 1)
  4701. (setq sexp (buffer-substring b (point)))
  4702. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4703. (org-trim (match-string 1))
  4704. ""))
  4705. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4706. (when result
  4707. (setq marker (org-agenda-new-marker beg)
  4708. category (org-get-category beg)
  4709. org-category-pos (get-text-property beg 'org-category-position)
  4710. todo-state (org-get-todo-state))
  4711. (dolist (r (if (stringp result)
  4712. (list result)
  4713. result)) ;; we expect a list here
  4714. (when (and org-agenda-diary-sexp-prefix
  4715. (string-match org-agenda-diary-sexp-prefix r))
  4716. (setq extra (match-string 0 r)
  4717. r (replace-match "" nil nil r)))
  4718. (if (string-match "\\S-" r)
  4719. (setq txt r)
  4720. (setq txt "SEXP entry returned empty string"))
  4721. (setq txt (org-agenda-format-item
  4722. extra txt category tags 'time))
  4723. (org-add-props txt props 'org-marker marker)
  4724. (org-add-props txt nil
  4725. 'org-category category 'date date 'todo-state todo-state
  4726. 'org-category-position org-category-pos
  4727. 'type "sexp")
  4728. (push txt ee)))))
  4729. (nreverse ee)))
  4730. ;; Calendar sanity: define some functions that are independent of
  4731. ;; `calendar-date-style'.
  4732. ;; Normally I would like to use ISO format when calling the diary functions,
  4733. ;; but to make sure we still have Emacs 22 compatibility we bind
  4734. ;; also `european-calendar-style' and use european format
  4735. (defun org-anniversary (year month day &optional mark)
  4736. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4737. (org-no-warnings
  4738. (let ((calendar-date-style 'european) (european-calendar-style t))
  4739. (diary-anniversary day month year mark))))
  4740. (defun org-cyclic (N year month day &optional mark)
  4741. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4742. (org-no-warnings
  4743. (let ((calendar-date-style 'european) (european-calendar-style t))
  4744. (diary-cyclic N day month year mark))))
  4745. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4746. "Like `diary-block', but with fixed (ISO) order of arguments."
  4747. (org-no-warnings
  4748. (let ((calendar-date-style 'european) (european-calendar-style t))
  4749. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4750. (defun org-date (year month day &optional mark)
  4751. "Like `diary-date', but with fixed (ISO) order of arguments."
  4752. (org-no-warnings
  4753. (let ((calendar-date-style 'european) (european-calendar-style t))
  4754. (diary-date day month year mark))))
  4755. (defalias 'org-float 'diary-float)
  4756. ;; Define the` org-class' function
  4757. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4758. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4759. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4760. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4761. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4762. `holidays', then any date that is known by the Emacs calendar to be a
  4763. holiday will also be skipped."
  4764. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4765. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4766. (d (calendar-absolute-from-gregorian date)))
  4767. (and
  4768. (<= date1 d)
  4769. (<= d date2)
  4770. (= (calendar-day-of-week date) dayname)
  4771. (or (not skip-weeks)
  4772. (progn
  4773. (require 'cal-iso)
  4774. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4775. (not (and (memq 'holidays skip-weeks)
  4776. (calendar-check-holidays date)))
  4777. entry)))
  4778. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4779. "Like `org-class', but honor `calendar-date-style'.
  4780. The order of the first 2 times 3 arguments depends on the variable
  4781. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4782. So for American calendars, give this as MONTH DAY YEAR, for European as
  4783. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4784. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4785. is any number of ISO weeks in the block period for which the item should
  4786. be skipped.
  4787. This function is here only for backward compatibility and it is deprecated,
  4788. please use `org-class' instead."
  4789. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4790. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4791. (org-class
  4792. (nth 2 date1) (car date1) (nth 1 date1)
  4793. (nth 2 date2) (car date2) (nth 1 date2)
  4794. dayname skip-weeks)))
  4795. (make-obsolete 'org-diary-class 'org-class "")
  4796. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4797. (defalias 'org-get-closed 'org-agenda-get-progress)
  4798. (defun org-agenda-get-progress ()
  4799. "Return the logged TODO entries for agenda display."
  4800. (let* ((props (list 'mouse-face 'highlight
  4801. 'org-not-done-regexp org-not-done-regexp
  4802. 'org-todo-regexp org-todo-regexp
  4803. 'org-complex-heading-regexp org-complex-heading-regexp
  4804. 'help-echo
  4805. (format "mouse-2 or RET jump to org file %s"
  4806. (abbreviate-file-name buffer-file-name))))
  4807. (items (if (consp org-agenda-show-log-scoped)
  4808. org-agenda-show-log-scoped
  4809. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4810. '(clock)
  4811. org-agenda-log-mode-items)))
  4812. (parts
  4813. (delq nil
  4814. (list
  4815. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4816. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4817. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4818. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4819. (error "`org-agenda-log-mode-items' is empty")))
  4820. (regexp (concat
  4821. "\\(" parts-re "\\)"
  4822. " *\\["
  4823. (regexp-quote
  4824. (substring
  4825. (format-time-string
  4826. (car org-time-stamp-formats)
  4827. (apply 'encode-time ; DATE bound by calendar
  4828. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4829. 1 11))))
  4830. (org-agenda-search-headline-for-time nil)
  4831. marker hdmarker priority category org-category-pos tags closedp
  4832. statep clockp state ee txt extra timestr rest clocked)
  4833. (goto-char (point-min))
  4834. (while (re-search-forward regexp nil t)
  4835. (catch :skip
  4836. (org-agenda-skip)
  4837. (setq marker (org-agenda-new-marker (match-beginning 0))
  4838. closedp (equal (match-string 1) org-closed-string)
  4839. statep (equal (string-to-char (match-string 1)) ?-)
  4840. clockp (not (or closedp statep))
  4841. state (and statep (match-string 2))
  4842. category (org-get-category (match-beginning 0))
  4843. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4844. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4845. (when (string-match "\\]" timestr)
  4846. ;; substring should only run to end of time stamp
  4847. (setq rest (substring timestr (match-end 0))
  4848. timestr (substring timestr 0 (match-end 0)))
  4849. (if (and (not closedp) (not statep)
  4850. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4851. rest))
  4852. (progn (setq timestr (concat (substring timestr 0 -1)
  4853. "-" (match-string 1 rest) "]"))
  4854. (setq clocked (match-string 2 rest)))
  4855. (setq clocked "-")))
  4856. (save-excursion
  4857. (setq extra
  4858. (cond
  4859. ((not org-agenda-log-mode-add-notes) nil)
  4860. (statep
  4861. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4862. (match-string 1)))
  4863. (clockp
  4864. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4865. (match-string 1)))))
  4866. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4867. (setq txt org-agenda-no-heading-message)
  4868. (goto-char (match-beginning 0))
  4869. (setq hdmarker (org-agenda-new-marker)
  4870. tags (org-get-tags-at))
  4871. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4872. (setq txt (match-string 1))
  4873. (when extra
  4874. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4875. (setq txt (concat (substring txt 0 (match-beginning 1))
  4876. " - " extra " " (match-string 2 txt)))
  4877. (setq txt (concat txt " - " extra))))
  4878. (setq txt (org-agenda-format-item
  4879. (cond
  4880. (closedp "Closed: ")
  4881. (statep (concat "State: (" state ")"))
  4882. (t (concat "Clocked: (" clocked ")")))
  4883. txt category tags timestr)))
  4884. (setq priority 100000)
  4885. (org-add-props txt props
  4886. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4887. 'priority priority 'org-category category
  4888. 'org-category-position org-category-pos
  4889. 'type "closed" 'date date
  4890. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4891. (push txt ee))
  4892. (goto-char (point-at-eol))))
  4893. (nreverse ee)))
  4894. (defun org-agenda-show-clocking-issues ()
  4895. "Add overlays, showing issues with clocking.
  4896. See also the user option `org-agenda-clock-consistency-checks'."
  4897. (interactive)
  4898. (let* ((pl org-agenda-clock-consistency-checks)
  4899. (re (concat "^[ \t]*"
  4900. org-clock-string
  4901. "[ \t]+"
  4902. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4903. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4904. (tlstart 0.)
  4905. (tlend 0.)
  4906. (maxtime (org-hh:mm-string-to-minutes
  4907. (or (plist-get pl :max-duration) "24:00")))
  4908. (mintime (org-hh:mm-string-to-minutes
  4909. (or (plist-get pl :min-duration) 0)))
  4910. (maxgap (org-hh:mm-string-to-minutes
  4911. ;; default 30:00 means never complain
  4912. (or (plist-get pl :max-gap) "30:00")))
  4913. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4914. (plist-get pl :gap-ok-around)))
  4915. (def-face (or (plist-get pl :default-face)
  4916. '((:background "DarkRed") (:foreground "white"))))
  4917. issue face m te ts dt ov)
  4918. (goto-char (point-min))
  4919. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4920. (setq issue nil face def-face)
  4921. (catch 'next
  4922. (setq m (org-get-at-bol 'org-marker)
  4923. te nil ts nil)
  4924. (unless (and m (markerp m))
  4925. (setq issue "No valid clock line") (throw 'next t))
  4926. (org-with-point-at m
  4927. (save-excursion
  4928. (goto-char (point-at-bol))
  4929. (unless (looking-at re)
  4930. (error "No valid Clock line")
  4931. (throw 'next t))
  4932. (unless (match-end 3)
  4933. (setq issue "No end time"
  4934. face (or (plist-get pl :no-end-time-face) face))
  4935. (throw 'next t))
  4936. (setq ts (match-string 1)
  4937. te (match-string 3)
  4938. ts (org-float-time
  4939. (apply 'encode-time (org-parse-time-string ts)))
  4940. te (org-float-time
  4941. (apply 'encode-time (org-parse-time-string te)))
  4942. dt (- te ts))))
  4943. (cond
  4944. ((> dt (* 60 maxtime))
  4945. ;; a very long clocking chunk
  4946. (setq issue (format "Clocking interval is very long: %s"
  4947. (org-minutes-to-hh:mm-string
  4948. (floor (/ (float dt) 60.))))
  4949. face (or (plist-get pl :long-face) face)))
  4950. ((< dt (* 60 mintime))
  4951. ;; a very short clocking chunk
  4952. (setq issue (format "Clocking interval is very short: %s"
  4953. (org-minutes-to-hh:mm-string
  4954. (floor (/ (float dt) 60.))))
  4955. face (or (plist-get pl :short-face) face)))
  4956. ((and (> tlend 0) (< ts tlend))
  4957. ;; Two clock entries are overlapping
  4958. (setq issue (format "Clocking overlap: %d minutes"
  4959. (/ (- tlend ts) 60))
  4960. face (or (plist-get pl :overlap-face) face)))
  4961. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4962. ;; There is a gap, lets see if we need to report it
  4963. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4964. (setq issue (format "Clocking gap: %d minutes"
  4965. (/ (- ts tlend) 60))
  4966. face (or (plist-get pl :gap-face) face))))
  4967. (t nil)))
  4968. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4969. (when issue
  4970. ;; OK, there was some issue, add an overlay to show the issue
  4971. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4972. (overlay-put ov 'before-string
  4973. (concat
  4974. (org-add-props
  4975. (format "%-43s" (concat " " issue))
  4976. nil
  4977. 'face face)
  4978. "\n"))
  4979. (overlay-put ov 'evaporate t)))))
  4980. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4981. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4982. (catch 'exit
  4983. (unless ok-list
  4984. ;; there are no OK times for gaps...
  4985. (throw 'exit nil))
  4986. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4987. ;; This is more than 24 hours, so it is OK.
  4988. ;; because we have at least one OK time, that must be in the
  4989. ;; 24 hour interval.
  4990. (throw 'exit t))
  4991. ;; We have a shorter gap.
  4992. ;; Now we have to get the minute of the day when these times are
  4993. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4994. (t2dec (decode-time (seconds-to-time t2)))
  4995. ;; compute the minute on the day
  4996. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4997. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4998. (when (< min2 min1)
  4999. ;; if min2 is smaller than min1, this means it is on the next day.
  5000. ;; Wrap it to after midnight.
  5001. (setq min2 (+ min2 1440)))
  5002. ;; Now check if any of the OK times is in the gap
  5003. (mapc (lambda (x)
  5004. ;; Wrap the time to after midnight if necessary
  5005. (if (< x min1) (setq x (+ x 1440)))
  5006. ;; Check if in interval
  5007. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5008. ok-list)
  5009. ;; Nope, this gap is not OK
  5010. nil)))
  5011. (defun org-agenda-get-deadlines ()
  5012. "Return the deadline information for agenda display."
  5013. (let* ((props (list 'mouse-face 'highlight
  5014. 'org-not-done-regexp org-not-done-regexp
  5015. 'org-todo-regexp org-todo-regexp
  5016. 'org-complex-heading-regexp org-complex-heading-regexp
  5017. 'help-echo
  5018. (format "mouse-2 or RET jump to org file %s"
  5019. (abbreviate-file-name buffer-file-name))))
  5020. (regexp org-deadline-time-regexp)
  5021. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5022. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5023. d2 diff dfrac wdays pos pos1 category org-category-pos
  5024. tags suppress-prewarning ee txt head face s todo-state
  5025. show-all upcomingp donep timestr)
  5026. (goto-char (point-min))
  5027. (while (re-search-forward regexp nil t)
  5028. (setq suppress-prewarning nil)
  5029. (catch :skip
  5030. (org-agenda-skip)
  5031. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5032. (save-match-data
  5033. (string-match org-scheduled-time-regexp
  5034. (buffer-substring (point-at-bol)
  5035. (point-at-eol)))))
  5036. (setq suppress-prewarning
  5037. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5038. org-agenda-skip-deadline-prewarning-if-scheduled
  5039. 0)))
  5040. (setq s (match-string 1)
  5041. txt nil
  5042. pos (1- (match-beginning 1))
  5043. todo-state (save-match-data (org-get-todo-state))
  5044. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5045. (member todo-state
  5046. org-agenda-repeating-timestamp-show-all))
  5047. d2 (org-time-string-to-absolute
  5048. (match-string 1) d1 'past show-all
  5049. (current-buffer) pos)
  5050. diff (- d2 d1)
  5051. wdays (if suppress-prewarning
  5052. (let ((org-deadline-warning-days suppress-prewarning))
  5053. (org-get-wdays s))
  5054. (org-get-wdays s))
  5055. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5056. upcomingp (and todayp (> diff 0)))
  5057. ;; When to show a deadline in the calendar:
  5058. ;; If the expiration is within wdays warning time.
  5059. ;; Past-due deadlines are only shown on the current date
  5060. (if (and (or (and (<= diff wdays)
  5061. (and todayp (not org-agenda-only-exact-dates)))
  5062. (= diff 0)))
  5063. (save-excursion
  5064. ;; (setq todo-state (org-get-todo-state))
  5065. (setq donep (member todo-state org-done-keywords))
  5066. (if (and donep
  5067. (or org-agenda-skip-deadline-if-done
  5068. (not (= diff 0))))
  5069. (setq txt nil)
  5070. (setq category (org-get-category)
  5071. org-category-pos (get-text-property (point) 'org-category-position))
  5072. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5073. (setq txt org-agenda-no-heading-message)
  5074. (goto-char (match-end 0))
  5075. (setq pos1 (match-beginning 0))
  5076. (setq tags (org-get-tags-at pos1))
  5077. (setq head (buffer-substring-no-properties
  5078. (point)
  5079. (progn (skip-chars-forward "^\r\n")
  5080. (point))))
  5081. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5082. (setq timestr
  5083. (concat (substring s (match-beginning 1)) " "))
  5084. (setq timestr 'time))
  5085. (setq txt (org-agenda-format-item
  5086. (if (= diff 0)
  5087. (car org-agenda-deadline-leaders)
  5088. (if (functionp
  5089. (nth 1 org-agenda-deadline-leaders))
  5090. (funcall
  5091. (nth 1 org-agenda-deadline-leaders)
  5092. diff date)
  5093. (format (nth 1 org-agenda-deadline-leaders)
  5094. diff)))
  5095. head category tags
  5096. (if (not (= diff 0)) nil timestr)))))
  5097. (when txt
  5098. (setq face (org-agenda-deadline-face dfrac))
  5099. (org-add-props txt props
  5100. 'org-marker (org-agenda-new-marker pos)
  5101. 'org-hd-marker (org-agenda-new-marker pos1)
  5102. 'priority (+ (- diff)
  5103. (org-get-priority txt))
  5104. 'org-category category
  5105. 'org-category-position org-category-pos
  5106. 'todo-state todo-state
  5107. 'type (if upcomingp "upcoming-deadline" "deadline")
  5108. 'date (if upcomingp date d2)
  5109. 'face (if donep 'org-agenda-done face)
  5110. 'undone-face face 'done-face 'org-agenda-done)
  5111. (push txt ee))))))
  5112. (nreverse ee)))
  5113. (defun org-agenda-deadline-face (fraction)
  5114. "Return the face to displaying a deadline item.
  5115. FRACTION is what fraction of the head-warning time has passed."
  5116. (let ((faces org-agenda-deadline-faces) f)
  5117. (catch 'exit
  5118. (while (setq f (pop faces))
  5119. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5120. (defun org-agenda-get-scheduled (&optional deadline-results)
  5121. "Return the scheduled information for agenda display."
  5122. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5123. 'org-todo-regexp org-todo-regexp
  5124. 'org-complex-heading-regexp org-complex-heading-regexp
  5125. 'done-face 'org-agenda-done
  5126. 'mouse-face 'highlight
  5127. 'help-echo
  5128. (format "mouse-2 or RET jump to org file %s"
  5129. (abbreviate-file-name buffer-file-name))))
  5130. (regexp org-scheduled-time-regexp)
  5131. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5132. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5133. mm
  5134. (deadline-position-alist
  5135. (mapcar (lambda (a) (and (setq mm (get-text-property
  5136. 0 'org-hd-marker a))
  5137. (cons (marker-position mm) a)))
  5138. deadline-results))
  5139. d2 diff pos pos1 category org-category-pos tags donep
  5140. ee txt head pastschedp todo-state face timestr s habitp show-all)
  5141. (goto-char (point-min))
  5142. (while (re-search-forward regexp nil t)
  5143. (catch :skip
  5144. (org-agenda-skip)
  5145. (setq s (match-string 1)
  5146. txt nil
  5147. pos (1- (match-beginning 1))
  5148. todo-state (save-match-data (org-get-todo-state))
  5149. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5150. (member todo-state
  5151. org-agenda-repeating-timestamp-show-all))
  5152. d2 (org-time-string-to-absolute
  5153. (match-string 1) d1 'past show-all
  5154. (current-buffer) pos)
  5155. diff (- d2 d1))
  5156. (setq pastschedp (and todayp (< diff 0)))
  5157. ;; When to show a scheduled item in the calendar:
  5158. ;; If it is on or past the date.
  5159. (when (or (and (< diff 0)
  5160. (< (abs diff) org-scheduled-past-days)
  5161. (and todayp (not org-agenda-only-exact-dates)))
  5162. (= diff 0))
  5163. (save-excursion
  5164. (setq donep (member todo-state org-done-keywords))
  5165. (if (and donep
  5166. (or org-agenda-skip-scheduled-if-done
  5167. (not (= diff 0))
  5168. (and (functionp 'org-is-habit-p)
  5169. (org-is-habit-p))))
  5170. (setq txt nil)
  5171. (setq habitp (and (functionp 'org-is-habit-p)
  5172. (org-is-habit-p)))
  5173. (setq category (org-get-category)
  5174. org-category-pos (get-text-property (point) 'org-category-position))
  5175. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5176. (setq txt org-agenda-no-heading-message)
  5177. (goto-char (match-end 0))
  5178. (setq pos1 (match-beginning 0))
  5179. (if habitp
  5180. (if (or (not org-habit-show-habits)
  5181. (and (not todayp)
  5182. org-habit-show-habits-only-for-today))
  5183. (throw :skip nil))
  5184. (if (and
  5185. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5186. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5187. pastschedp))
  5188. (setq mm (assoc pos1 deadline-position-alist)))
  5189. (throw :skip nil)))
  5190. (setq tags (org-get-tags-at))
  5191. (setq head (buffer-substring-no-properties
  5192. (point)
  5193. (progn (skip-chars-forward "^\r\n") (point))))
  5194. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5195. (setq timestr
  5196. (concat (substring s (match-beginning 1)) " "))
  5197. (setq timestr 'time))
  5198. (setq txt (org-agenda-format-item
  5199. (if (= diff 0)
  5200. (car org-agenda-scheduled-leaders)
  5201. (format (nth 1 org-agenda-scheduled-leaders)
  5202. (- 1 diff)))
  5203. head category tags
  5204. (if (not (= diff 0)) nil timestr)
  5205. nil habitp))))
  5206. (when txt
  5207. (setq face
  5208. (cond
  5209. ((and (not habitp) pastschedp)
  5210. 'org-scheduled-previously)
  5211. (todayp 'org-scheduled-today)
  5212. (t 'org-scheduled))
  5213. habitp (and habitp (org-habit-parse-todo)))
  5214. (org-add-props txt props
  5215. 'undone-face face
  5216. 'face (if donep 'org-agenda-done face)
  5217. 'org-marker (org-agenda-new-marker pos)
  5218. 'org-hd-marker (org-agenda-new-marker pos1)
  5219. 'type (if pastschedp "past-scheduled" "scheduled")
  5220. 'date (if pastschedp d2 date)
  5221. 'priority (if habitp
  5222. (org-habit-get-priority habitp)
  5223. (+ 94 (- 5 diff) (org-get-priority txt)))
  5224. 'org-category category
  5225. 'org-category-position org-category-pos
  5226. 'org-habit-p habitp
  5227. 'todo-state todo-state)
  5228. (push txt ee))))))
  5229. (nreverse ee)))
  5230. (defun org-agenda-get-blocks ()
  5231. "Return the date-range information for agenda display."
  5232. (let* ((props (list 'face nil
  5233. 'org-not-done-regexp org-not-done-regexp
  5234. 'org-todo-regexp org-todo-regexp
  5235. 'org-complex-heading-regexp org-complex-heading-regexp
  5236. 'mouse-face 'highlight
  5237. 'help-echo
  5238. (format "mouse-2 or RET jump to org file %s"
  5239. (abbreviate-file-name buffer-file-name))))
  5240. (regexp org-tr-regexp)
  5241. (d0 (calendar-absolute-from-gregorian date))
  5242. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5243. todo-state tags pos head donep)
  5244. (goto-char (point-min))
  5245. (while (re-search-forward regexp nil t)
  5246. (catch :skip
  5247. (org-agenda-skip)
  5248. (setq pos (point))
  5249. (let ((start-time (match-string 1))
  5250. (end-time (match-string 2)))
  5251. (setq s1 (match-string 1)
  5252. s2 (match-string 2)
  5253. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5254. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5255. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5256. ;; Only allow days between the limits, because the normal
  5257. ;; date stamps will catch the limits.
  5258. (save-excursion
  5259. (setq todo-state (org-get-todo-state))
  5260. (setq donep (member todo-state org-done-keywords))
  5261. (if (and donep org-agenda-skip-timestamp-if-done)
  5262. (throw :skip t))
  5263. (setq marker (org-agenda-new-marker (point)))
  5264. (setq category (org-get-category)
  5265. org-category-pos (get-text-property (point) 'org-category-position))
  5266. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5267. (setq txt org-agenda-no-heading-message)
  5268. (goto-char (match-beginning 0))
  5269. (setq hdmarker (org-agenda-new-marker (point)))
  5270. (setq tags (org-get-tags-at))
  5271. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5272. (setq head (match-string 1))
  5273. (let ((remove-re
  5274. (if org-agenda-remove-timeranges-from-blocks
  5275. (concat
  5276. "<" (regexp-quote s1) ".*?>"
  5277. "--"
  5278. "<" (regexp-quote s2) ".*?>")
  5279. nil)))
  5280. (setq txt (org-agenda-format-item
  5281. (format
  5282. (nth (if (= d1 d2) 0 1)
  5283. org-agenda-timerange-leaders)
  5284. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5285. head category tags
  5286. (cond ((and (= d1 d0) (= d2 d0))
  5287. (concat "<" start-time ">--<" end-time ">"))
  5288. ((= d1 d0)
  5289. (concat "<" start-time ">"))
  5290. ((= d2 d0)
  5291. (concat "<" end-time ">"))
  5292. (t nil))
  5293. remove-re))))
  5294. (org-add-props txt props
  5295. 'org-marker marker 'org-hd-marker hdmarker
  5296. 'type "block" 'date date
  5297. 'todo-state todo-state
  5298. 'priority (org-get-priority txt) 'org-category category
  5299. 'org-category-position org-category-pos)
  5300. (push txt ee))))
  5301. (goto-char pos)))
  5302. ;; Sort the entries by expiration date.
  5303. (nreverse ee)))
  5304. ;;; Agenda presentation and sorting
  5305. (defvar org-prefix-has-time nil
  5306. "A flag, set by `org-compile-prefix-format'.
  5307. The flag is set if the currently compiled format contains a `%t'.")
  5308. (defvar org-prefix-has-tag nil
  5309. "A flag, set by `org-compile-prefix-format'.
  5310. The flag is set if the currently compiled format contains a `%T'.")
  5311. (defvar org-prefix-has-effort nil
  5312. "A flag, set by `org-compile-prefix-format'.
  5313. The flag is set if the currently compiled format contains a `%e'.")
  5314. (defvar org-prefix-category-length nil
  5315. "Used by `org-compile-prefix-format' to remember the category field width.")
  5316. (defvar org-prefix-category-max-length nil
  5317. "Used by `org-compile-prefix-format' to remember the category field width.")
  5318. (defun org-agenda-get-category-icon (category)
  5319. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5320. (dolist (entry org-agenda-category-icon-alist)
  5321. (when (org-string-match-p (car entry) category)
  5322. (if (listp (cadr entry))
  5323. (return (cadr entry))
  5324. (return (apply 'create-image (cdr entry)))))))
  5325. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5326. remove-re habitp)
  5327. "Format TXT to be inserted into the agenda buffer.
  5328. In particular, it adds the prefix and corresponding text properties. EXTRA
  5329. must be a string and replaces the `%s' specifier in the prefix format.
  5330. CATEGORY (string, symbol or nil) may be used to overrule the default
  5331. category taken from local variable or file name. It will replace the `%c'
  5332. specifier in the format. DOTIME, when non-nil, indicates that a
  5333. time-of-day should be extracted from TXT for sorting of this entry, and for
  5334. the `%t' specifier in the format. When DOTIME is a string, this string is
  5335. searched for a time before TXT is. TAGS can be the tags of the headline.
  5336. Any match of REMOVE-RE will be removed from TXT."
  5337. ;; We keep the org-prefix-* variable values along with a compiled
  5338. ;; formatter, so that multiple agendas existing at the same time, do
  5339. ;; not step on each other toes.
  5340. ;;
  5341. ;; It was inconvenient to make these variables buffer local in
  5342. ;; Agenda buffers, because this function expects to be called with
  5343. ;; the buffer where item comes from being current, and not agenda
  5344. ;; buffer
  5345. (let* ((bindings (car org-prefix-format-compiled))
  5346. (formatter (cadr org-prefix-format-compiled)))
  5347. (loop for (var value) in bindings
  5348. do (set var value))
  5349. (save-match-data
  5350. ;; Diary entries sometimes have extra whitespace at the beginning
  5351. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5352. ;; Fix the tags part in txt
  5353. (setq txt (org-agenda-fix-displayed-tags
  5354. txt tags
  5355. org-agenda-show-inherited-tags
  5356. org-agenda-hide-tags-regexp))
  5357. (let* ((category (or category
  5358. (if (stringp org-category)
  5359. org-category
  5360. (and org-category (symbol-name org-category)))
  5361. (if buffer-file-name
  5362. (file-name-sans-extension
  5363. (file-name-nondirectory buffer-file-name))
  5364. "")))
  5365. (category-icon (org-agenda-get-category-icon category))
  5366. (category-icon (if category-icon
  5367. (propertize " " 'display category-icon)
  5368. ""))
  5369. ;; time, tag, effort are needed for the eval of the prefix format
  5370. (tag (if tags (nth (1- (length tags)) tags) ""))
  5371. time effort neffort
  5372. (ts (if dotime (concat
  5373. (if (stringp dotime) dotime "")
  5374. (and org-agenda-search-headline-for-time txt))))
  5375. (time-of-day (and dotime (org-get-time-of-day ts)))
  5376. stamp plain s0 s1 s2 rtn srp l
  5377. duration thecategory)
  5378. (and (derived-mode-p 'org-mode) buffer-file-name
  5379. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5380. (when (and dotime time-of-day)
  5381. ;; Extract starting and ending time and move them to prefix
  5382. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5383. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5384. (setq s0 (match-string 0 ts)
  5385. srp (and stamp (match-end 3))
  5386. s1 (match-string (if plain 1 2) ts)
  5387. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5388. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5389. ;; them, we might want to remove them there to avoid duplication.
  5390. ;; The user can turn this off with a variable.
  5391. (if (and org-prefix-has-time
  5392. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5393. (string-match (concat (regexp-quote s0) " *") txt)
  5394. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5395. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5396. (= (match-beginning 0) 0)
  5397. t))
  5398. (setq txt (replace-match "" nil nil txt))))
  5399. ;; Normalize the time(s) to 24 hour
  5400. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5401. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5402. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5403. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5404. (setq s2
  5405. (org-minutes-to-hh:mm-string
  5406. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5407. ;; Compute the duration
  5408. (when s2
  5409. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5410. (org-hh:mm-string-to-minutes s1)))))
  5411. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5412. txt)
  5413. ;; Tags are in the string
  5414. (if (or (eq org-agenda-remove-tags t)
  5415. (and org-agenda-remove-tags
  5416. org-prefix-has-tag))
  5417. (setq txt (replace-match "" t t txt))
  5418. (setq txt (replace-match
  5419. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5420. (match-string 2 txt))
  5421. t t txt))))
  5422. (when (derived-mode-p 'org-mode)
  5423. (setq effort
  5424. (condition-case nil
  5425. (org-get-effort
  5426. (or (get-text-property 0 'org-hd-marker txt)
  5427. (get-text-property 0 'org-marker txt)))
  5428. (error nil)))
  5429. (when effort
  5430. (setq neffort (org-duration-string-to-minutes effort)
  5431. effort (setq effort (concat "[" effort "]")))))
  5432. ;; prevent erroring out with %e format when there is no effort
  5433. (or effort (setq effort ""))
  5434. (when remove-re
  5435. (while (string-match remove-re txt)
  5436. (setq txt (replace-match "" t t txt))))
  5437. ;; Set org-heading property on `txt' to mark the start of the
  5438. ;; heading.
  5439. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5440. ;; Prepare the variables needed in the eval of the compiled format
  5441. (setq time (cond (s2 (concat
  5442. (org-agenda-time-of-day-to-ampm-maybe s1)
  5443. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5444. (if org-agenda-timegrid-use-ampm " ")))
  5445. (s1 (concat
  5446. (org-agenda-time-of-day-to-ampm-maybe s1)
  5447. (if org-agenda-timegrid-use-ampm
  5448. "........ "
  5449. "......")))
  5450. (t ""))
  5451. extra (or (and (not habitp) extra) "")
  5452. category (if (symbolp category) (symbol-name category) category)
  5453. thecategory (copy-sequence category))
  5454. (if (string-match org-bracket-link-regexp category)
  5455. (progn
  5456. (setq l (if (match-end 3)
  5457. (- (match-end 3) (match-beginning 3))
  5458. (- (match-end 1) (match-beginning 1))))
  5459. (when (< l (or org-prefix-category-length 0))
  5460. (setq category (copy-sequence category))
  5461. (org-add-props category nil
  5462. 'extra-space (make-string
  5463. (- org-prefix-category-length l 1) ?\ ))))
  5464. (if (and org-prefix-category-max-length
  5465. (>= (length category) org-prefix-category-max-length))
  5466. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5467. ;; Evaluate the compiled format
  5468. (setq rtn (concat (eval formatter) txt))
  5469. ;; And finally add the text properties
  5470. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5471. (org-add-props rtn nil
  5472. 'org-category (if thecategory (downcase thecategory) category)
  5473. 'tags (mapcar 'org-downcase-keep-props tags)
  5474. 'org-highest-priority org-highest-priority
  5475. 'org-lowest-priority org-lowest-priority
  5476. 'time-of-day time-of-day
  5477. 'duration duration
  5478. 'effort effort
  5479. 'effort-minutes neffort
  5480. 'txt txt
  5481. 'time time
  5482. 'extra extra
  5483. 'format org-prefix-format-compiled
  5484. 'dotime dotime)))))
  5485. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5486. "Remove tags string from TXT, and add a modified list of tags.
  5487. The modified list may contain inherited tags, and tags matched by
  5488. `org-agenda-hide-tags-regexp' will be removed."
  5489. (when (or add-inherited hide-re)
  5490. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5491. (setq txt (substring txt 0 (match-beginning 0))))
  5492. (setq tags
  5493. (delq nil
  5494. (mapcar (lambda (tg)
  5495. (if (or (and hide-re (string-match hide-re tg))
  5496. (and (not add-inherited)
  5497. (get-text-property 0 'inherited tg)))
  5498. nil
  5499. tg))
  5500. tags)))
  5501. (when tags
  5502. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5503. i)
  5504. (setq txt (concat txt " :"
  5505. (mapconcat
  5506. (lambda (x)
  5507. (setq i (get-text-property 0 'inherited x))
  5508. (if (and have-i (not i))
  5509. (progn
  5510. (setq have-i nil)
  5511. (concat ":" x))
  5512. x))
  5513. tags ":")
  5514. (if have-i "::" ":"))))))
  5515. txt)
  5516. (defun org-downcase-keep-props (s)
  5517. (let ((props (text-properties-at 0 s)))
  5518. (setq s (downcase s))
  5519. (add-text-properties 0 (length s) props s)
  5520. s))
  5521. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5522. (defvar org-agenda-sorting-strategy-selected nil)
  5523. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5524. (catch 'exit
  5525. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5526. ((and todayp (member 'today (car org-agenda-time-grid))))
  5527. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5528. ((member 'weekly (car org-agenda-time-grid)))
  5529. (t (throw 'exit list)))
  5530. (let* ((have (delq nil (mapcar
  5531. (lambda (x) (get-text-property 1 'time-of-day x))
  5532. list)))
  5533. (string (nth 1 org-agenda-time-grid))
  5534. (gridtimes (nth 2 org-agenda-time-grid))
  5535. (req (car org-agenda-time-grid))
  5536. (remove (member 'remove-match req))
  5537. new time)
  5538. (if (and (member 'require-timed req) (not have))
  5539. ;; don't show empty grid
  5540. (throw 'exit list))
  5541. (while (setq time (pop gridtimes))
  5542. (unless (and remove (member time have))
  5543. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5544. (push (org-agenda-format-item
  5545. nil string "" nil
  5546. (concat (substring time 0 -2) ":" (substring time -2)))
  5547. new)
  5548. (put-text-property
  5549. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5550. (when (and todayp org-agenda-show-current-time-in-grid)
  5551. (push (org-agenda-format-item
  5552. nil
  5553. org-agenda-current-time-string
  5554. "" nil
  5555. (format-time-string "%H:%M "))
  5556. new)
  5557. (put-text-property
  5558. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5559. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5560. (append new list)
  5561. (append list new)))))
  5562. (defun org-compile-prefix-format (key)
  5563. "Compile the prefix format into a Lisp form that can be evaluated.
  5564. The resulting form and associated variable bindings is returned
  5565. and stored in the variable `org-prefix-format-compiled'."
  5566. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5567. org-prefix-category-length nil
  5568. org-prefix-has-effort nil)
  5569. (let ((s (cond
  5570. ((stringp org-agenda-prefix-format)
  5571. org-agenda-prefix-format)
  5572. ((assq key org-agenda-prefix-format)
  5573. (cdr (assq key org-agenda-prefix-format)))
  5574. (t " %-12:c%?-12t% s")))
  5575. (start 0)
  5576. varform vars var e c f opt)
  5577. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5578. s start)
  5579. (setq var (or (cdr (assoc (match-string 4 s)
  5580. '(("c" . category) ("t" . time) ("s" . extra)
  5581. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5582. 'eval)
  5583. c (or (match-string 3 s) "")
  5584. opt (match-beginning 1)
  5585. start (1+ (match-beginning 0)))
  5586. (if (equal var 'time) (setq org-prefix-has-time t))
  5587. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5588. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5589. (setq f (concat "%" (match-string 2 s) "s"))
  5590. (when (equal var 'category)
  5591. (setq org-prefix-category-length
  5592. (floor (abs (string-to-number (match-string 2 s)))))
  5593. (setq org-prefix-category-max-length
  5594. (let ((x (match-string 2 s)))
  5595. (save-match-data
  5596. (if (string-match "\\.[0-9]+" x)
  5597. (string-to-number (substring (match-string 0 x) 1)))))))
  5598. (if (eq var 'eval)
  5599. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5600. (if opt
  5601. (setq varform
  5602. `(if (equal "" ,var)
  5603. ""
  5604. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5605. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5606. (setq s (replace-match "%s" t nil s))
  5607. (push varform vars))
  5608. (setq vars (nreverse vars))
  5609. (with-current-buffer org-agenda-buffer
  5610. (setq org-prefix-format-compiled
  5611. (list
  5612. `((org-prefix-has-time ,org-prefix-has-time)
  5613. (org-prefix-has-tag ,org-prefix-has-tag)
  5614. (org-prefix-category-length ,org-prefix-category-length)
  5615. (org-prefix-has-effort ,org-prefix-has-effort))
  5616. `(format ,s ,@vars))))))
  5617. (defun org-set-sorting-strategy (key)
  5618. (if (symbolp (car org-agenda-sorting-strategy))
  5619. ;; the old format
  5620. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5621. (setq org-agenda-sorting-strategy-selected
  5622. (or (cdr (assq key org-agenda-sorting-strategy))
  5623. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5624. '(time-up category-keep priority-down)))))
  5625. (defun org-get-time-of-day (s &optional string mod24)
  5626. "Check string S for a time of day.
  5627. If found, return it as a military time number between 0 and 2400.
  5628. If not found, return nil.
  5629. The optional STRING argument forces conversion into a 5 character wide string
  5630. HH:MM."
  5631. (save-match-data
  5632. (when
  5633. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5634. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5635. (let* ((h (string-to-number (match-string 1 s)))
  5636. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5637. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5638. (am-p (equal ampm "am"))
  5639. (h1 (cond ((not ampm) h)
  5640. ((= h 12) (if am-p 0 12))
  5641. (t (+ h (if am-p 0 12)))))
  5642. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5643. (mod h1 24) h1))
  5644. (t0 (+ (* 100 h2) m))
  5645. (t1 (concat (if (>= h1 24) "+" " ")
  5646. (if (and org-agenda-time-leading-zero
  5647. (< t0 1000)) "0" "")
  5648. (if (< t0 100) "0" "")
  5649. (if (< t0 10) "0" "")
  5650. (int-to-string t0))))
  5651. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5652. (defvar org-agenda-before-sorting-filter-function nil
  5653. "Function to be applied to agenda items prior to sorting.
  5654. Prior to sorting also means just before they are inserted into the agenda.
  5655. To aid sorting, you may revisit the original entries and add more text
  5656. properties which will later be used by the sorting functions.
  5657. The function should take a string argument, an agenda line.
  5658. It has access to the text properties in that line, which contain among
  5659. other things, the property `org-hd-marker' that points to the entry
  5660. where the line comes from. Note that not all lines going into the agenda
  5661. have this property, only most.
  5662. The function should return the modified string. It is probably best
  5663. to ONLY change text properties.
  5664. You can also use this function as a filter, by returning nil for lines
  5665. you don't want to have in the agenda at all. For this application, you
  5666. could bind the variable in the options section of a custom command.")
  5667. (defun org-finalize-agenda-entries (list &optional nosort)
  5668. "Sort and concatenate the agenda items."
  5669. (setq list (mapcar 'org-agenda-highlight-todo list))
  5670. (if nosort
  5671. list
  5672. (when org-agenda-before-sorting-filter-function
  5673. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5674. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5675. (defun org-agenda-highlight-todo (x)
  5676. (let ((org-done-keywords org-done-keywords-for-agenda)
  5677. (case-fold-search nil)
  5678. re)
  5679. (if (eq x 'line)
  5680. (save-excursion
  5681. (beginning-of-line 1)
  5682. (setq re (org-get-at-bol 'org-todo-regexp))
  5683. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5684. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5685. (add-text-properties (match-beginning 0) (match-end 1)
  5686. (list 'face (org-get-todo-face 1)))
  5687. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5688. (delete-region (match-beginning 1) (1- (match-end 0)))
  5689. (goto-char (match-beginning 1))
  5690. (insert (format org-agenda-todo-keyword-format s)))))
  5691. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5692. (setq re (get-text-property 0 'org-todo-regexp x))
  5693. (when (and re
  5694. ;; Test `pl' because if there's no heading content,
  5695. ;; there's no point matching to highlight. Note
  5696. ;; that if we didn't test `pl' first, and there
  5697. ;; happened to be no keyword from `org-todo-regexp'
  5698. ;; on this heading line, then the `equal' comparison
  5699. ;; afterwards would spuriously succeed in the case
  5700. ;; where `pl' is nil -- causing an args-out-of-range
  5701. ;; error when we try to add text properties to text
  5702. ;; that isn't there.
  5703. pl
  5704. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5705. x pl) pl))
  5706. (add-text-properties
  5707. (or (match-end 1) (match-end 0)) (match-end 0)
  5708. (list 'face (org-get-todo-face (match-string 2 x)))
  5709. x)
  5710. (when (match-end 1)
  5711. (setq x (concat (substring x 0 (match-end 1))
  5712. (format org-agenda-todo-keyword-format
  5713. (match-string 2 x))
  5714. (org-add-props " " (text-properties-at 0 x))
  5715. (substring x (match-end 3)))))))
  5716. x)))
  5717. (defsubst org-cmp-priority (a b)
  5718. "Compare the priorities of string A and B."
  5719. (let ((pa (or (get-text-property 1 'priority a) 0))
  5720. (pb (or (get-text-property 1 'priority b) 0)))
  5721. (cond ((> pa pb) +1)
  5722. ((< pa pb) -1)
  5723. (t nil))))
  5724. (defsubst org-cmp-effort (a b)
  5725. "Compare the effort values of string A and B."
  5726. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5727. (ea (or (get-text-property 1 'effort-minutes a) def))
  5728. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5729. (cond ((> ea eb) +1)
  5730. ((< ea eb) -1)
  5731. (t nil))))
  5732. (defsubst org-cmp-category (a b)
  5733. "Compare the string values of categories of strings A and B."
  5734. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5735. (cb (or (get-text-property 1 'org-category b) "")))
  5736. (cond ((string-lessp ca cb) -1)
  5737. ((string-lessp cb ca) +1)
  5738. (t nil))))
  5739. (defsubst org-cmp-todo-state (a b)
  5740. "Compare the todo states of strings A and B."
  5741. (let* ((ma (or (get-text-property 1 'org-marker a)
  5742. (get-text-property 1 'org-hd-marker a)))
  5743. (mb (or (get-text-property 1 'org-marker b)
  5744. (get-text-property 1 'org-hd-marker b)))
  5745. (fa (and ma (marker-buffer ma)))
  5746. (fb (and mb (marker-buffer mb)))
  5747. (todo-kwds
  5748. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5749. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5750. (ta (or (get-text-property 1 'todo-state a) ""))
  5751. (tb (or (get-text-property 1 'todo-state b) ""))
  5752. (la (- (length (member ta todo-kwds))))
  5753. (lb (- (length (member tb todo-kwds))))
  5754. (donepa (member ta org-done-keywords-for-agenda))
  5755. (donepb (member tb org-done-keywords-for-agenda)))
  5756. (cond ((and donepa (not donepb)) -1)
  5757. ((and (not donepa) donepb) +1)
  5758. ((< la lb) -1)
  5759. ((< lb la) +1)
  5760. (t nil))))
  5761. (defsubst org-cmp-alpha (a b)
  5762. "Compare the headlines, alphabetically."
  5763. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5764. (plb (text-property-any 0 (length b) 'org-heading t b))
  5765. (ta (and pla (substring a pla)))
  5766. (tb (and plb (substring b plb))))
  5767. (when pla
  5768. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5769. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5770. (setq ta (substring ta (match-end 0))))
  5771. (setq ta (downcase ta)))
  5772. (when plb
  5773. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5774. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5775. (setq tb (substring tb (match-end 0))))
  5776. (setq tb (downcase tb)))
  5777. (cond ((not ta) +1)
  5778. ((not tb) -1)
  5779. ((string-lessp ta tb) -1)
  5780. ((string-lessp tb ta) +1)
  5781. (t nil))))
  5782. (defsubst org-cmp-tag (a b)
  5783. "Compare the string values of the first tags of A and B."
  5784. (let ((ta (car (last (get-text-property 1 'tags a))))
  5785. (tb (car (last (get-text-property 1 'tags b)))))
  5786. (cond ((not ta) +1)
  5787. ((not tb) -1)
  5788. ((string-lessp ta tb) -1)
  5789. ((string-lessp tb ta) +1)
  5790. (t nil))))
  5791. (defsubst org-cmp-time (a b)
  5792. "Compare the time-of-day values of strings A and B."
  5793. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5794. (ta (or (get-text-property 1 'time-of-day a) def))
  5795. (tb (or (get-text-property 1 'time-of-day b) def)))
  5796. (cond ((< ta tb) -1)
  5797. ((< tb ta) +1)
  5798. (t nil))))
  5799. (defsubst org-cmp-habit-p (a b)
  5800. "Compare the todo states of strings A and B."
  5801. (let ((ha (get-text-property 1 'org-habit-p a))
  5802. (hb (get-text-property 1 'org-habit-p b)))
  5803. (cond ((and ha (not hb)) -1)
  5804. ((and (not ha) hb) +1)
  5805. (t nil))))
  5806. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5807. (defun org-entries-lessp (a b)
  5808. "Predicate for sorting agenda entries."
  5809. ;; The following variables will be used when the form is evaluated.
  5810. ;; So even though the compiler complains, keep them.
  5811. (let* ((ss org-agenda-sorting-strategy-selected)
  5812. (time-up (and (org-em 'time-up 'time-down ss)
  5813. (org-cmp-time a b)))
  5814. (time-down (if time-up (- time-up) nil))
  5815. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5816. (org-cmp-priority a b)))
  5817. (priority-down (if priority-up (- priority-up) nil))
  5818. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5819. (org-cmp-effort a b)))
  5820. (effort-down (if effort-up (- effort-up) nil))
  5821. (category-up (and (or (org-em 'category-up 'category-down ss)
  5822. (memq 'category-keep ss))
  5823. (org-cmp-category a b)))
  5824. (category-down (if category-up (- category-up) nil))
  5825. (category-keep (if category-up +1 nil))
  5826. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5827. (org-cmp-tag a b)))
  5828. (tag-down (if tag-up (- tag-up) nil))
  5829. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5830. (org-cmp-todo-state a b)))
  5831. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5832. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5833. (org-cmp-habit-p a b)))
  5834. (habit-down (if habit-up (- habit-up) nil))
  5835. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5836. (org-cmp-alpha a b)))
  5837. (alpha-down (if alpha-up (- alpha-up) nil))
  5838. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5839. user-defined-up user-defined-down)
  5840. (if (and need-user-cmp org-agenda-cmp-user-defined
  5841. (functionp org-agenda-cmp-user-defined))
  5842. (setq user-defined-up
  5843. (funcall org-agenda-cmp-user-defined a b)
  5844. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5845. (cdr (assoc
  5846. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5847. '((-1 . t) (1 . nil) (nil . nil))))))
  5848. ;;; Agenda restriction lock
  5849. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5850. "Overlay to mark the headline to which agenda commands are restricted.")
  5851. (overlay-put org-agenda-restriction-lock-overlay
  5852. 'face 'org-agenda-restriction-lock)
  5853. (overlay-put org-agenda-restriction-lock-overlay
  5854. 'help-echo "Agendas are currently limited to this subtree.")
  5855. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5856. (defun org-agenda-set-restriction-lock (&optional type)
  5857. "Set restriction lock for agenda, to current subtree or file.
  5858. Restriction will be the file if TYPE is `file', or if type is the
  5859. universal prefix '(4), or if the cursor is before the first headline
  5860. in the file. Otherwise, restriction will be to the current subtree."
  5861. (interactive "P")
  5862. (and (equal type '(4)) (setq type 'file))
  5863. (setq type (cond
  5864. (type type)
  5865. ((org-at-heading-p) 'subtree)
  5866. ((condition-case nil (org-back-to-heading t) (error nil))
  5867. 'subtree)
  5868. (t 'file)))
  5869. (if (eq type 'subtree)
  5870. (progn
  5871. (setq org-agenda-restrict t)
  5872. (setq org-agenda-overriding-restriction 'subtree)
  5873. (put 'org-agenda-files 'org-restrict
  5874. (list (buffer-file-name (buffer-base-buffer))))
  5875. (org-back-to-heading t)
  5876. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5877. (move-marker org-agenda-restrict-begin (point))
  5878. (move-marker org-agenda-restrict-end
  5879. (save-excursion (org-end-of-subtree t)))
  5880. (message "Locking agenda restriction to subtree"))
  5881. (put 'org-agenda-files 'org-restrict
  5882. (list (buffer-file-name (buffer-base-buffer))))
  5883. (setq org-agenda-restrict nil)
  5884. (setq org-agenda-overriding-restriction 'file)
  5885. (move-marker org-agenda-restrict-begin nil)
  5886. (move-marker org-agenda-restrict-end nil)
  5887. (message "Locking agenda restriction to file"))
  5888. (setq current-prefix-arg nil)
  5889. (org-agenda-maybe-redo))
  5890. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5891. "Remove the agenda restriction lock."
  5892. (interactive "P")
  5893. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5894. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5895. (setq org-agenda-overriding-restriction nil)
  5896. (setq org-agenda-restrict nil)
  5897. (put 'org-agenda-files 'org-restrict nil)
  5898. (move-marker org-agenda-restrict-begin nil)
  5899. (move-marker org-agenda-restrict-end nil)
  5900. (setq current-prefix-arg nil)
  5901. (message "Agenda restriction lock removed")
  5902. (or noupdate (org-agenda-maybe-redo)))
  5903. (defun org-agenda-maybe-redo ()
  5904. "If there is any window showing the agenda view, update it."
  5905. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5906. (w0 (selected-window)))
  5907. (when w
  5908. (select-window w)
  5909. (org-agenda-redo)
  5910. (select-window w0)
  5911. (if org-agenda-overriding-restriction
  5912. (message "Agenda view shifted to new %s restriction"
  5913. org-agenda-overriding-restriction)
  5914. (message "Agenda restriction lock removed")))))
  5915. ;;; Agenda commands
  5916. (defun org-agenda-check-type (error &rest types)
  5917. "Check if agenda buffer is of allowed type.
  5918. If ERROR is non-nil, throw an error, otherwise just return nil."
  5919. (if (memq org-agenda-type types)
  5920. t
  5921. (if error
  5922. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5923. nil)))
  5924. (defun org-agenda-Quit (&optional arg)
  5925. "Exit agenda by removing the window or the buffer"
  5926. (interactive)
  5927. (if org-agenda-columns-active
  5928. (org-columns-quit)
  5929. (let ((buf (current-buffer)))
  5930. (if (eq org-agenda-window-setup 'other-frame)
  5931. (progn
  5932. (org-agenda-reset-markers)
  5933. (kill-buffer buf)
  5934. (org-columns-remove-overlays)
  5935. (setq org-agenda-archives-mode nil)
  5936. (delete-frame))
  5937. (and (not (eq org-agenda-window-setup 'current-window))
  5938. (not (one-window-p))
  5939. (delete-window))
  5940. (org-agenda-reset-markers)
  5941. (kill-buffer buf)
  5942. (org-columns-remove-overlays)
  5943. (setq org-agenda-archives-mode nil)))
  5944. ;; Maybe restore the pre-agenda window configuration.
  5945. (and org-agenda-restore-windows-after-quit
  5946. (not (eq org-agenda-window-setup 'other-frame))
  5947. org-pre-agenda-window-conf
  5948. (set-window-configuration org-pre-agenda-window-conf))))
  5949. (defun org-agenda-quit ()
  5950. "Exit agenda by killing agenda buffer or burying it when
  5951. `org-agenda-sticky' is non-NIL"
  5952. (interactive)
  5953. (if org-agenda-columns-active
  5954. (org-columns-quit)
  5955. (if org-agenda-sticky
  5956. (let ((buf (current-buffer)))
  5957. (if (eq org-agenda-window-setup 'other-frame)
  5958. (progn
  5959. (delete-frame))
  5960. (and (not (eq org-agenda-window-setup 'current-window))
  5961. (not (one-window-p))
  5962. (delete-window)))
  5963. (with-current-buffer buf
  5964. (bury-buffer)
  5965. ;; Maybe restore the pre-agenda window configuration.
  5966. (and org-agenda-restore-windows-after-quit
  5967. (not (eq org-agenda-window-setup 'other-frame))
  5968. org-pre-agenda-window-conf
  5969. (set-window-configuration org-pre-agenda-window-conf))))
  5970. (org-agenda-Quit))))
  5971. (defun org-agenda-exit ()
  5972. "Exit agenda by removing the window or the buffer.
  5973. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5974. Org-mode buffers visited directly by the user will not be touched."
  5975. (interactive)
  5976. (org-release-buffers org-agenda-new-buffers)
  5977. (setq org-agenda-new-buffers nil)
  5978. (org-agenda-Quit))
  5979. (defun org-agenda-kill-all-agenda-buffers ()
  5980. "Kill all buffers in `org-agena-mode'.
  5981. This is used when toggling sticky agendas. You can also explicitly invoke it
  5982. with `C-c a C-k'."
  5983. (interactive)
  5984. (let (blist)
  5985. (dolist (buf (buffer-list))
  5986. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5987. (push buf blist)))
  5988. (mapc 'kill-buffer blist)))
  5989. (defun org-agenda-execute (arg)
  5990. "Execute another agenda command, keeping same window.
  5991. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5992. in the agenda."
  5993. (interactive "P")
  5994. (let ((org-agenda-window-setup 'current-window))
  5995. (org-agenda arg)))
  5996. (defun org-agenda-redo ()
  5997. "Rebuild Agenda.
  5998. When this is the global TODO list, a prefix argument will be interpreted."
  5999. (interactive)
  6000. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  6001. (org-agenda-sticky nil)
  6002. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6003. org-agenda-buffer-name))
  6004. (org-agenda-keep-modes t)
  6005. (tag-filter org-agenda-tag-filter)
  6006. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6007. (top-cat-filter org-agenda-top-category-filter)
  6008. (cat-filter org-agenda-category-filter)
  6009. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6010. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6011. (cols org-agenda-columns-active)
  6012. (line (org-current-line))
  6013. (window-line (- line (org-current-line (window-start))))
  6014. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  6015. (put 'org-agenda-tag-filter :preset-filter nil)
  6016. (put 'org-agenda-category-filter :preset-filter nil)
  6017. (and cols (org-columns-quit))
  6018. (message "Rebuilding agenda buffer...")
  6019. (org-let lprops '(eval org-agenda-redo-command))
  6020. (setq org-agenda-undo-list nil
  6021. org-agenda-pending-undo-list nil)
  6022. (message "Rebuilding agenda buffer...done")
  6023. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6024. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6025. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6026. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6027. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6028. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6029. (org-goto-line line)
  6030. (recenter window-line)))
  6031. (defvar org-global-tags-completion-table nil)
  6032. (defvar org-agenda-filter-form nil)
  6033. (defvar org-agenda-filtered-by-category nil)
  6034. (defun org-agenda-filter-by-category (strip)
  6035. "Keep only those lines in the agenda buffer that have a specific category.
  6036. The category is that of the current line."
  6037. (interactive "P")
  6038. (if org-agenda-filtered-by-category
  6039. (org-agenda-filter-show-all-cat)
  6040. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6041. (if cat (org-agenda-filter-apply
  6042. (list (concat (if strip "-" "+") cat)) 'category)
  6043. (error "No category at point")))))
  6044. (defun org-find-top-category (&optional pos)
  6045. (save-excursion
  6046. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6047. (if pos (goto-char pos))
  6048. ;; Skip up to the topmost parent
  6049. (while (ignore-errors (outline-up-heading 1) t))
  6050. (ignore-errors
  6051. (nth 4 (org-heading-components))))))
  6052. (defvar org-agenda-filtered-by-top-category nil)
  6053. (defun org-agenda-filter-by-top-category (strip)
  6054. "Keep only those lines in the agenda buffer that have a specific category.
  6055. The category is that of the current line."
  6056. (interactive "P")
  6057. (if org-agenda-filtered-by-top-category
  6058. (progn
  6059. (setq org-agenda-filtered-by-top-category nil
  6060. org-agenda-top-category-filter nil)
  6061. (org-agenda-filter-show-all-cat))
  6062. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6063. (if cat (org-agenda-filter-top-category-apply cat strip)
  6064. (error "No top-level category at point")))))
  6065. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6066. "Keep only those lines in the agenda buffer that have a specific tag.
  6067. The tag is selected with its fast selection letter, as configured.
  6068. With prefix argument STRIP, remove all lines that do have the tag.
  6069. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6070. used to narrow the search - the interactive user can also press `-' or `+'
  6071. to switch to narrowing."
  6072. (interactive "P")
  6073. (let* ((alist org-tag-alist-for-agenda)
  6074. (tag-chars (mapconcat
  6075. (lambda (x) (if (and (not (symbolp (car x)))
  6076. (cdr x))
  6077. (char-to-string (cdr x))
  6078. ""))
  6079. alist ""))
  6080. (efforts (org-split-string
  6081. (or (cdr (assoc (concat org-effort-property "_ALL")
  6082. org-global-properties))
  6083. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6084. "")))
  6085. (effort-op org-agenda-filter-effort-default-operator)
  6086. (effort-prompt "")
  6087. (inhibit-read-only t)
  6088. (current org-agenda-tag-filter)
  6089. maybe-refresh a n tag)
  6090. (unless char
  6091. (message
  6092. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6093. (if narrow "Narrow" "Filter") tag-chars
  6094. (if org-agenda-auto-exclude-function "[RET], " ""))
  6095. (setq char (read-char-exclusive)))
  6096. (when (member char '(?+ ?-))
  6097. ;; Narrowing down
  6098. (cond ((equal char ?-) (setq strip t narrow t))
  6099. ((equal char ?+) (setq strip nil narrow t)))
  6100. (message
  6101. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6102. (setq char (read-char-exclusive)))
  6103. (when (member char '(?< ?> ?= ??))
  6104. ;; An effort operator
  6105. (setq effort-op (char-to-string char))
  6106. (setq alist nil) ; to make sure it will be interpreted as effort.
  6107. (unless (equal char ??)
  6108. (loop for i from 0 to 9 do
  6109. (setq effort-prompt
  6110. (concat
  6111. effort-prompt " ["
  6112. (if (= i 9) "0" (int-to-string (1+ i)))
  6113. "]" (nth i efforts))))
  6114. (message "Effort%s: %s " effort-op effort-prompt)
  6115. (setq char (read-char-exclusive))
  6116. (when (or (< char ?0) (> char ?9))
  6117. (error "Need 1-9,0 to select effort"))))
  6118. (when (equal char ?\t)
  6119. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6120. (org-set-local 'org-global-tags-completion-table
  6121. (org-global-tags-completion-table)))
  6122. (let ((completion-ignore-case t))
  6123. (setq tag (org-icompleting-read
  6124. "Tag: " org-global-tags-completion-table))))
  6125. (cond
  6126. ((equal char ?\r)
  6127. (org-agenda-filter-show-all-tag)
  6128. (when org-agenda-auto-exclude-function
  6129. (setq org-agenda-tag-filter '())
  6130. (dolist (tag (org-agenda-get-represented-tags))
  6131. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6132. (if modifier
  6133. (push modifier org-agenda-tag-filter))))
  6134. (if (not (null org-agenda-tag-filter))
  6135. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6136. (setq maybe-refresh t))
  6137. ((equal char ?/)
  6138. (org-agenda-filter-show-all-tag)
  6139. (when (get 'org-agenda-tag-filter :preset-filter)
  6140. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6141. (setq maybe-refresh t))
  6142. ((equal char ?. )
  6143. (setq org-agenda-tag-filter
  6144. (mapcar (lambda(tag) (concat "+" tag))
  6145. (org-get-at-bol 'tags)))
  6146. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6147. (setq maybe-refresh t))
  6148. ((or (equal char ?\ )
  6149. (setq a (rassoc char alist))
  6150. (and (>= char ?0) (<= char ?9)
  6151. (setq n (if (= char ?0) 9 (- char ?0 1))
  6152. tag (concat effort-op (nth n efforts))
  6153. a (cons tag nil)))
  6154. (and (= char ??)
  6155. (setq tag "?eff")
  6156. a (cons tag nil))
  6157. (and tag (setq a (cons tag nil))))
  6158. (org-agenda-filter-show-all-tag)
  6159. (setq tag (car a))
  6160. (setq org-agenda-tag-filter
  6161. (cons (concat (if strip "-" "+") tag)
  6162. (if narrow current nil)))
  6163. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6164. (setq maybe-refresh t))
  6165. (t (error "Invalid tag selection character %c" char)))
  6166. (when (and maybe-refresh
  6167. (eq org-agenda-clockreport-mode 'with-filter))
  6168. (org-agenda-redo))))
  6169. (defun org-agenda-get-represented-tags ()
  6170. "Get a list of all tags currently represented in the agenda."
  6171. (let (p tags)
  6172. (save-excursion
  6173. (goto-char (point-min))
  6174. (while (setq p (next-single-property-change (point) 'tags))
  6175. (goto-char p)
  6176. (mapc (lambda (x) (add-to-list 'tags x))
  6177. (get-text-property (point) 'tags))))
  6178. tags))
  6179. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6180. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6181. (interactive "P")
  6182. (org-agenda-filter-by-tag strip char 'refine))
  6183. (defun org-agenda-filter-make-matcher ()
  6184. "Create the form that tests a line for agenda filter."
  6185. (let (f f1)
  6186. ;; first compute the tag-filter matcher
  6187. (dolist (x (delete-dups
  6188. (append (get 'org-agenda-tag-filter
  6189. :preset-filter) org-agenda-tag-filter)))
  6190. (if (member x '("-" "+"))
  6191. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6192. (if (string-match "[<=>?]" x)
  6193. (setq f1 (org-agenda-filter-effort-form x))
  6194. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6195. (if (equal (string-to-char x) ?-)
  6196. (setq f1 (list 'not f1))))
  6197. (push f1 f))
  6198. ;; then compute the category-filter matcher
  6199. (dolist (x (delete-dups
  6200. (append (get 'org-agenda-category-filter
  6201. :preset-filter) org-agenda-category-filter)))
  6202. (if (equal "-" (substring x 0 1))
  6203. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6204. (setq f1 (list 'equal (substring x 1) 'cat)))
  6205. (push f1 f))
  6206. (cons 'and (nreverse f))))
  6207. (defun org-agenda-filter-effort-form (e)
  6208. "Return the form to compare the effort of the current line with what E says.
  6209. E looks like \"+<2:25\"."
  6210. (let (op)
  6211. (setq e (substring e 1))
  6212. (setq op (string-to-char e) e (substring e 1))
  6213. (setq op (cond ((equal op ?<) '<=)
  6214. ((equal op ?>) '>=)
  6215. ((equal op ??) op)
  6216. (t '=)))
  6217. (list 'org-agenda-compare-effort (list 'quote op)
  6218. (org-duration-string-to-minutes e))))
  6219. (defun org-agenda-compare-effort (op value)
  6220. "Compare the effort of the current line with VALUE, using OP.
  6221. If the line does not have an effort defined, return nil."
  6222. (let ((eff (org-get-at-bol 'effort-minutes)))
  6223. (if (equal op ??)
  6224. (not eff)
  6225. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6226. value))))
  6227. (defun org-agenda-filter-apply (filter type)
  6228. "Set FILTER as the new agenda filter and apply it."
  6229. (let (tags cat)
  6230. (if (eq type 'tag)
  6231. (setq org-agenda-tag-filter filter)
  6232. (setq org-agenda-category-filter filter))
  6233. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6234. (if (and (eq type 'category)
  6235. (not (equal (substring (car filter) 0 1) "-")))
  6236. ;; Only set `org-agenda-filtered-by-category' to t
  6237. ;; when a unique category is used as the filter
  6238. (setq org-agenda-filtered-by-category t))
  6239. (org-agenda-set-mode-name)
  6240. (save-excursion
  6241. (goto-char (point-min))
  6242. (while (not (eobp))
  6243. (if (org-get-at-bol 'org-marker)
  6244. (progn
  6245. (setq tags (org-get-at-bol 'tags) ; used in eval
  6246. cat (get-text-property (point) 'org-category))
  6247. (if (not (eval org-agenda-filter-form))
  6248. (org-agenda-filter-hide-line type))
  6249. (beginning-of-line 2))
  6250. (beginning-of-line 2))))
  6251. (if (get-char-property (point) 'invisible)
  6252. (ignore-errors (org-agenda-previous-line)))))
  6253. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6254. "Set FILTER as the new agenda filter and apply it."
  6255. (org-agenda-set-mode-name)
  6256. (save-excursion
  6257. (goto-char (point-min))
  6258. (while (not (eobp))
  6259. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6260. (topcat (and pos (org-find-top-category pos))))
  6261. (if (and topcat (funcall (if negative 'identity 'not)
  6262. (string= category topcat)))
  6263. (org-agenda-filter-hide-line 'category)))
  6264. (beginning-of-line 2)))
  6265. (if (get-char-property (point) 'invisible)
  6266. (org-agenda-previous-line))
  6267. (setq org-agenda-top-category-filter category
  6268. org-agenda-filtered-by-top-category t))
  6269. (defun org-agenda-filter-hide-line (type)
  6270. (let (ov)
  6271. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6272. (point-at-eol)))
  6273. (overlay-put ov 'invisible t)
  6274. (overlay-put ov 'type type)
  6275. (if (eq type 'tag)
  6276. (push ov org-agenda-tag-filter-overlays)
  6277. (push ov org-agenda-cat-filter-overlays))))
  6278. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6279. (setq pos (or pos (point)))
  6280. (save-excursion
  6281. (dolist (ov (overlays-at pos))
  6282. (when (and (overlay-get ov 'invisible)
  6283. (eq (overlay-get ov 'type) 'tag))
  6284. (goto-char pos)
  6285. (if (< (overlay-start ov) (point-at-eol))
  6286. (move-overlay ov (point-at-eol)
  6287. (overlay-end ov)))))))
  6288. (defun org-agenda-filter-show-all-tag nil
  6289. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6290. (setq org-agenda-tag-filter-overlays nil
  6291. org-agenda-tag-filter nil
  6292. org-agenda-filter-form nil)
  6293. (org-agenda-set-mode-name))
  6294. (defun org-agenda-filter-show-all-cat nil
  6295. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6296. (setq org-agenda-cat-filter-overlays nil
  6297. org-agenda-filtered-by-category nil
  6298. org-agenda-category-filter nil
  6299. org-agenda-filter-form nil)
  6300. (org-agenda-set-mode-name))
  6301. (defun org-agenda-manipulate-query-add ()
  6302. "Manipulate the query by adding a search term with positive selection.
  6303. Positive selection means the term must be matched for selection of an entry."
  6304. (interactive)
  6305. (org-agenda-manipulate-query ?\[))
  6306. (defun org-agenda-manipulate-query-subtract ()
  6307. "Manipulate the query by adding a search term with negative selection.
  6308. Negative selection means term must not be matched for selection of an entry."
  6309. (interactive)
  6310. (org-agenda-manipulate-query ?\]))
  6311. (defun org-agenda-manipulate-query-add-re ()
  6312. "Manipulate the query by adding a search regexp with positive selection.
  6313. Positive selection means the regexp must match for selection of an entry."
  6314. (interactive)
  6315. (org-agenda-manipulate-query ?\{))
  6316. (defun org-agenda-manipulate-query-subtract-re ()
  6317. "Manipulate the query by adding a search regexp with negative selection.
  6318. Negative selection means regexp must not match for selection of an entry."
  6319. (interactive)
  6320. (org-agenda-manipulate-query ?\}))
  6321. (defun org-agenda-manipulate-query (char)
  6322. (cond
  6323. ((memq org-agenda-type '(timeline agenda))
  6324. (let ((org-agenda-include-inactive-timestamps t))
  6325. (org-agenda-redo))
  6326. (message "Display now includes inactive timestamps as well"))
  6327. ((eq org-agenda-type 'search)
  6328. (org-add-to-string
  6329. 'org-agenda-query-string
  6330. (if org-agenda-last-search-view-search-was-boolean
  6331. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6332. (?\{ . " +{}") (?\} . " -{}"))))
  6333. " "))
  6334. (setq org-agenda-redo-command
  6335. (list 'org-search-view
  6336. org-todo-only
  6337. org-agenda-query-string
  6338. (+ (length org-agenda-query-string)
  6339. (if (member char '(?\{ ?\})) 0 1))))
  6340. (set-register org-agenda-query-register org-agenda-query-string)
  6341. (org-agenda-redo))
  6342. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6343. org-agenda-type))))
  6344. (defun org-add-to-string (var string)
  6345. (set var (concat (symbol-value var) string)))
  6346. (defun org-agenda-goto-date (date)
  6347. "Jump to DATE in agenda."
  6348. (interactive (list (let ((org-read-date-prefer-future
  6349. (eval org-agenda-jump-prefer-future)))
  6350. (org-read-date))))
  6351. (org-agenda-list nil date))
  6352. (defun org-agenda-goto-today ()
  6353. "Go to today."
  6354. (interactive)
  6355. (org-agenda-check-type t 'timeline 'agenda)
  6356. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6357. (cond
  6358. (tdpos (goto-char tdpos))
  6359. ((eq org-agenda-type 'agenda)
  6360. (let* ((sd (org-agenda-compute-starting-span
  6361. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6362. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6363. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6364. (org-agenda-redo)
  6365. (org-agenda-find-same-or-today-or-agenda)))
  6366. (t (error "Cannot find today")))))
  6367. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6368. (goto-char
  6369. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6370. (text-property-any (point-min) (point-max) 'org-today t)
  6371. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6372. (point-min))))
  6373. (defun org-agenda-later (arg)
  6374. "Go forward in time by thee current span.
  6375. With prefix ARG, go forward that many times the current span."
  6376. (interactive "p")
  6377. (org-agenda-check-type t 'agenda)
  6378. (let* ((span org-agenda-current-span)
  6379. (sd org-starting-day)
  6380. (greg (calendar-gregorian-from-absolute sd))
  6381. (cnt (org-get-at-bol 'org-day-cnt))
  6382. greg2)
  6383. (cond
  6384. ((eq span 'day)
  6385. (setq sd (+ arg sd)))
  6386. ((eq span 'week)
  6387. (setq sd (+ (* 7 arg) sd)))
  6388. ((eq span 'month)
  6389. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6390. sd (calendar-absolute-from-gregorian greg2))
  6391. (setcar greg2 (1+ (car greg2))))
  6392. ((eq span 'year)
  6393. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6394. sd (calendar-absolute-from-gregorian greg2))
  6395. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6396. (t
  6397. (setq sd (+ (* span arg) sd))))
  6398. (let ((org-agenda-overriding-arguments
  6399. (list (car org-agenda-last-arguments) sd span t)))
  6400. (org-agenda-redo)
  6401. (org-agenda-find-same-or-today-or-agenda cnt))))
  6402. (defun org-agenda-earlier (arg)
  6403. "Go backward in time by the current span.
  6404. With prefix ARG, go backward that many times the current span."
  6405. (interactive "p")
  6406. (org-agenda-later (- arg)))
  6407. (defun org-agenda-view-mode-dispatch ()
  6408. "Call one of the view mode commands."
  6409. (interactive)
  6410. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6411. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6412. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6413. [E]ntryText")
  6414. (let ((a (read-char-exclusive)))
  6415. (case a
  6416. (?\ (call-interactively 'org-agenda-reset-view))
  6417. (?d (call-interactively 'org-agenda-day-view))
  6418. (?w (call-interactively 'org-agenda-week-view))
  6419. (?m (call-interactively 'org-agenda-month-view))
  6420. (?y (call-interactively 'org-agenda-year-view))
  6421. (?l (call-interactively 'org-agenda-log-mode))
  6422. (?L (org-agenda-log-mode '(4)))
  6423. (?c (org-agenda-log-mode 'clockcheck))
  6424. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6425. (?a (call-interactively 'org-agenda-archives-mode))
  6426. (?A (org-agenda-archives-mode 'files))
  6427. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6428. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6429. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6430. (?D (call-interactively 'org-agenda-toggle-diary))
  6431. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6432. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6433. (org-agenda-check-type t 'timeline 'agenda)
  6434. (org-agenda-redo))
  6435. (message "Display now includes inactive timestamps as well"))
  6436. (?q (message "Abort"))
  6437. (otherwise (error "Invalid key" )))))
  6438. (defun org-agenda-reset-view ()
  6439. "Switch to default view for agenda."
  6440. (interactive)
  6441. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6442. (defun org-agenda-day-view (&optional day-of-year)
  6443. "Switch to daily view for agenda.
  6444. With argument DAY-OF-YEAR, switch to that day of the year."
  6445. (interactive "P")
  6446. (org-agenda-change-time-span 'day day-of-year))
  6447. (defun org-agenda-week-view (&optional iso-week)
  6448. "Switch to daily view for agenda.
  6449. With argument ISO-WEEK, switch to the corresponding ISO week.
  6450. If ISO-WEEK has more then 2 digits, only the last two encode the
  6451. week. Any digits before this encode a year. So 200712 means
  6452. week 12 of year 2007. Years in the range 1938-2037 can also be
  6453. written as 2-digit years."
  6454. (interactive "P")
  6455. (org-agenda-change-time-span 'week iso-week))
  6456. (defun org-agenda-month-view (&optional month)
  6457. "Switch to monthly view for agenda.
  6458. With argument MONTH, switch to that month."
  6459. (interactive "P")
  6460. (org-agenda-change-time-span 'month month))
  6461. (defun org-agenda-year-view (&optional year)
  6462. "Switch to yearly view for agenda.
  6463. With argument YEAR, switch to that year.
  6464. If MONTH has more then 2 digits, only the last two encode the
  6465. month. Any digits before this encode a year. So 200712 means
  6466. December year 2007. Years in the range 1938-2037 can also be
  6467. written as 2-digit years."
  6468. (interactive "P")
  6469. (when year
  6470. (setq year (org-small-year-to-year year)))
  6471. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6472. (org-agenda-change-time-span 'year year)
  6473. (error "Abort")))
  6474. (defun org-agenda-change-time-span (span &optional n)
  6475. "Change the agenda view to SPAN.
  6476. SPAN may be `day', `week', `month', `year'."
  6477. (org-agenda-check-type t 'agenda)
  6478. (if (and (not n) (equal org-agenda-current-span span))
  6479. (error "Viewing span is already \"%s\"" span))
  6480. (let* ((sd (or (org-get-at-bol 'day)
  6481. org-starting-day))
  6482. (sd (org-agenda-compute-starting-span sd span n))
  6483. (org-agenda-overriding-arguments
  6484. (or org-agenda-overriding-arguments
  6485. (list (car org-agenda-last-arguments) sd span t))))
  6486. (org-agenda-redo)
  6487. (org-agenda-find-same-or-today-or-agenda))
  6488. (org-agenda-set-mode-name)
  6489. (message "Switched to %s view" span))
  6490. (defun org-agenda-compute-starting-span (sd span &optional n)
  6491. "Compute starting date for agenda.
  6492. SPAN may be `day', `week', `month', `year'. The return value
  6493. is a cons cell with the starting date and the number of days,
  6494. so that the date SD will be in that range."
  6495. (let* ((greg (calendar-gregorian-from-absolute sd))
  6496. (dg (nth 1 greg))
  6497. (mg (car greg))
  6498. (yg (nth 2 greg)))
  6499. (cond
  6500. ((eq span 'day)
  6501. (when n
  6502. (setq sd (+ (calendar-absolute-from-gregorian
  6503. (list mg 1 yg))
  6504. n -1))))
  6505. ((eq span 'week)
  6506. (let* ((nt (calendar-day-of-week
  6507. (calendar-gregorian-from-absolute sd)))
  6508. (d (if org-agenda-start-on-weekday
  6509. (- nt org-agenda-start-on-weekday)
  6510. 0))
  6511. y1)
  6512. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6513. (when n
  6514. (require 'cal-iso)
  6515. (when (> n 99)
  6516. (setq y1 (org-small-year-to-year (/ n 100))
  6517. n (mod n 100)))
  6518. (setq sd
  6519. (calendar-absolute-from-iso
  6520. (list n 1
  6521. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6522. ((eq span 'month)
  6523. (let (y1)
  6524. (when (and n (> n 99))
  6525. (setq y1 (org-small-year-to-year (/ n 100))
  6526. n (mod n 100)))
  6527. (setq sd (calendar-absolute-from-gregorian
  6528. (list (or n mg) 1 (or y1 yg))))))
  6529. ((eq span 'year)
  6530. (setq sd (calendar-absolute-from-gregorian
  6531. (list 1 1 (or n yg))))))
  6532. sd))
  6533. (defun org-agenda-next-date-line (&optional arg)
  6534. "Jump to the next line indicating a date in agenda buffer."
  6535. (interactive "p")
  6536. (org-agenda-check-type t 'agenda 'timeline)
  6537. (beginning-of-line 1)
  6538. ;; This does not work if user makes date format that starts with a blank
  6539. (if (looking-at "^\\S-") (forward-char 1))
  6540. (if (not (re-search-forward "^\\S-" nil t arg))
  6541. (progn
  6542. (backward-char 1)
  6543. (error "No next date after this line in this buffer")))
  6544. (goto-char (match-beginning 0)))
  6545. (defun org-agenda-previous-date-line (&optional arg)
  6546. "Jump to the previous line indicating a date in agenda buffer."
  6547. (interactive "p")
  6548. (org-agenda-check-type t 'agenda 'timeline)
  6549. (beginning-of-line 1)
  6550. (if (not (re-search-backward "^\\S-" nil t arg))
  6551. (error "No previous date before this line in this buffer")))
  6552. ;; Initialize the highlight
  6553. (defvar org-hl (make-overlay 1 1))
  6554. (overlay-put org-hl 'face 'highlight)
  6555. (defun org-highlight (begin end &optional buffer)
  6556. "Highlight a region with overlay."
  6557. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6558. (defun org-unhighlight ()
  6559. "Detach overlay INDEX."
  6560. (org-detach-overlay org-hl))
  6561. ;; FIXME this is currently not used.
  6562. (defun org-highlight-until-next-command (beg end &optional buffer)
  6563. "Move the highlight overlay to BEG/END, remove it before the next command."
  6564. (org-highlight beg end buffer)
  6565. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6566. (defun org-unhighlight-once ()
  6567. "Remove the highlight from its position, and this function from the hook."
  6568. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6569. (org-unhighlight))
  6570. (defun org-agenda-follow-mode ()
  6571. "Toggle follow mode in an agenda buffer."
  6572. (interactive)
  6573. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6574. (org-agenda-set-mode-name)
  6575. (org-agenda-do-context-action)
  6576. (message "Follow mode is %s"
  6577. (if org-agenda-follow-mode "on" "off")))
  6578. (defun org-agenda-entry-text-mode (&optional arg)
  6579. "Toggle entry text mode in an agenda buffer."
  6580. (interactive "P")
  6581. (setq org-agenda-entry-text-mode (or (integerp arg)
  6582. (not org-agenda-entry-text-mode)))
  6583. (org-agenda-entry-text-hide)
  6584. (and org-agenda-entry-text-mode
  6585. (let ((org-agenda-entry-text-maxlines
  6586. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6587. (org-agenda-entry-text-show)))
  6588. (org-agenda-set-mode-name)
  6589. (message "Entry text mode is %s. Maximum number of lines is %d"
  6590. (if org-agenda-entry-text-mode "on" "off")
  6591. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6592. (defun org-agenda-clockreport-mode (&optional with-filter)
  6593. "Toggle clocktable mode in an agenda buffer.
  6594. With prefix arg WITH-FILTER, make the clocktable respect the current
  6595. agenda filter."
  6596. (interactive "P")
  6597. (org-agenda-check-type t 'agenda)
  6598. (if with-filter
  6599. (setq org-agenda-clockreport-mode 'with-filter)
  6600. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6601. (org-agenda-set-mode-name)
  6602. (org-agenda-redo)
  6603. (message "Clocktable mode is %s"
  6604. (if org-agenda-clockreport-mode "on" "off")))
  6605. (defun org-agenda-log-mode (&optional special)
  6606. "Toggle log mode in an agenda buffer.
  6607. With argument SPECIAL, show all possible log items, not only the ones
  6608. configured in `org-agenda-log-mode-items'.
  6609. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6610. (interactive "P")
  6611. (org-agenda-check-type t 'agenda 'timeline)
  6612. (setq org-agenda-show-log
  6613. (cond
  6614. ((equal special '(16)) 'only)
  6615. ((eq special 'clockcheck)
  6616. (if (eq org-agenda-show-log 'clockcheck)
  6617. nil 'clockcheck))
  6618. (special '(closed clock state))
  6619. (t (not org-agenda-show-log))))
  6620. (org-agenda-set-mode-name)
  6621. (org-agenda-redo)
  6622. (message "Log mode is %s"
  6623. (if org-agenda-show-log "on" "off")))
  6624. (defun org-agenda-archives-mode (&optional with-files)
  6625. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6626. When called with a prefix argument, include all archive files as well."
  6627. (interactive "P")
  6628. (setq org-agenda-archives-mode
  6629. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6630. (org-agenda-set-mode-name)
  6631. (org-agenda-redo)
  6632. (message
  6633. "%s"
  6634. (cond
  6635. ((eq org-agenda-archives-mode nil)
  6636. "No archives are included")
  6637. ((eq org-agenda-archives-mode 'trees)
  6638. (format "Trees with :%s: tag are included" org-archive-tag))
  6639. ((eq org-agenda-archives-mode t)
  6640. (format "Trees with :%s: tag and all active archive files are included"
  6641. org-archive-tag)))))
  6642. (defun org-agenda-toggle-diary ()
  6643. "Toggle diary inclusion in an agenda buffer."
  6644. (interactive)
  6645. (org-agenda-check-type t 'agenda)
  6646. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6647. (org-agenda-redo)
  6648. (org-agenda-set-mode-name)
  6649. (message "Diary inclusion turned %s"
  6650. (if org-agenda-include-diary "on" "off")))
  6651. (defun org-agenda-toggle-deadlines ()
  6652. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6653. (interactive)
  6654. (org-agenda-check-type t 'agenda)
  6655. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6656. (org-agenda-redo)
  6657. (org-agenda-set-mode-name)
  6658. (message "Deadlines inclusion turned %s"
  6659. (if org-agenda-include-deadlines "on" "off")))
  6660. (defun org-agenda-toggle-time-grid ()
  6661. "Toggle time grid in an agenda buffer."
  6662. (interactive)
  6663. (org-agenda-check-type t 'agenda)
  6664. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6665. (org-agenda-redo)
  6666. (org-agenda-set-mode-name)
  6667. (message "Time-grid turned %s"
  6668. (if org-agenda-use-time-grid "on" "off")))
  6669. (defun org-agenda-set-mode-name ()
  6670. "Set the mode name to indicate all the small mode settings."
  6671. (setq mode-name
  6672. (list "Org-Agenda"
  6673. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6674. " "
  6675. '(:eval (org-agenda-span-name org-agenda-current-span))
  6676. (if org-agenda-follow-mode " Follow" "")
  6677. (if org-agenda-entry-text-mode " ETxt" "")
  6678. (if org-agenda-include-diary " Diary" "")
  6679. (if org-agenda-include-deadlines " Ddl" "")
  6680. (if org-agenda-use-time-grid " Grid" "")
  6681. (if (and (boundp 'org-habit-show-habits)
  6682. org-habit-show-habits) " Habit" "")
  6683. (cond
  6684. ((consp org-agenda-show-log) " LogAll")
  6685. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6686. (org-agenda-show-log " Log")
  6687. (t ""))
  6688. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6689. :preset-filter))
  6690. '(:eval (org-propertize
  6691. (concat " <"
  6692. (mapconcat
  6693. 'identity
  6694. (append
  6695. (get 'org-agenda-category-filter :preset-filter)
  6696. org-agenda-category-filter)
  6697. "")
  6698. ">")
  6699. 'face 'org-agenda-filter-category
  6700. 'help-echo "Category used in filtering"))
  6701. "")
  6702. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6703. :preset-filter))
  6704. '(:eval (org-propertize
  6705. (concat " {"
  6706. (mapconcat
  6707. 'identity
  6708. (append
  6709. (get 'org-agenda-tag-filter :preset-filter)
  6710. org-agenda-tag-filter)
  6711. "")
  6712. "}")
  6713. 'face 'org-agenda-filter-tags
  6714. 'help-echo "Tags used in filtering"))
  6715. "")
  6716. (if org-agenda-archives-mode
  6717. (if (eq org-agenda-archives-mode t)
  6718. " Archives"
  6719. (format " :%s:" org-archive-tag))
  6720. "")
  6721. (if org-agenda-clockreport-mode
  6722. (if (eq org-agenda-clockreport-mode 'with-filter)
  6723. " Clock{}" " Clock")
  6724. "")))
  6725. (force-mode-line-update))
  6726. (defun org-agenda-post-command-hook ()
  6727. (setq org-agenda-type
  6728. (or (get-text-property (point) 'org-agenda-type)
  6729. (get-text-property (max (point-min) (1- (point)))
  6730. 'org-agenda-type))))
  6731. (defun org-agenda-next-line ()
  6732. "Move cursor to the next line, and show if follow mode is active."
  6733. (interactive)
  6734. (call-interactively 'next-line)
  6735. (org-agenda-do-context-action))
  6736. (defun org-agenda-previous-line ()
  6737. "Move cursor to the previous line, and show if follow-mode is active."
  6738. (interactive)
  6739. (call-interactively 'previous-line)
  6740. (org-agenda-do-context-action))
  6741. (defun org-agenda-do-context-action ()
  6742. "Show outline path and, maybe, follow mode window."
  6743. (let ((m (org-get-at-bol 'org-marker)))
  6744. (when (and (markerp m) (marker-buffer m))
  6745. (and org-agenda-follow-mode
  6746. (if org-agenda-follow-indirect
  6747. (org-agenda-tree-to-indirect-buffer)
  6748. (org-agenda-show)))
  6749. (and org-agenda-show-outline-path
  6750. (org-with-point-at m (org-display-outline-path t))))))
  6751. (defun org-agenda-show-priority ()
  6752. "Show the priority of the current item.
  6753. This priority is composed of the main priority given with the [#A] cookies,
  6754. and by additional input from the age of a schedules or deadline entry."
  6755. (interactive)
  6756. (let* ((pri (org-get-at-bol 'priority)))
  6757. (message "Priority is %d" (if pri pri -1000))))
  6758. (defun org-agenda-show-tags ()
  6759. "Show the tags applicable to the current item."
  6760. (interactive)
  6761. (let* ((tags (org-get-at-bol 'tags)))
  6762. (if tags
  6763. (message "Tags are :%s:"
  6764. (org-no-properties (mapconcat 'identity tags ":")))
  6765. (message "No tags associated with this line"))))
  6766. (defun org-agenda-goto (&optional highlight)
  6767. "Go to the Org-mode file which contains the item at point."
  6768. (interactive)
  6769. (let* ((marker (or (org-get-at-bol 'org-marker)
  6770. (org-agenda-error)))
  6771. (buffer (marker-buffer marker))
  6772. (pos (marker-position marker)))
  6773. (switch-to-buffer-other-window buffer)
  6774. (widen)
  6775. (push-mark)
  6776. (goto-char pos)
  6777. (when (derived-mode-p 'org-mode)
  6778. (org-show-context 'agenda)
  6779. (save-excursion
  6780. (and (outline-next-heading)
  6781. (org-flag-heading nil)))) ; show the next heading
  6782. (when (outline-invisible-p)
  6783. (show-entry)) ; display invisible text
  6784. (recenter (/ (window-height) 2))
  6785. (run-hooks 'org-agenda-after-show-hook)
  6786. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6787. (defvar org-agenda-after-show-hook nil
  6788. "Normal hook run after an item has been shown from the agenda.
  6789. Point is in the buffer where the item originated.")
  6790. (defun org-agenda-kill ()
  6791. "Kill the entry or subtree belonging to the current agenda entry."
  6792. (interactive)
  6793. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6794. (let* ((marker (or (org-get-at-bol 'org-marker)
  6795. (org-agenda-error)))
  6796. (buffer (marker-buffer marker))
  6797. (pos (marker-position marker))
  6798. (type (org-get-at-bol 'type))
  6799. dbeg dend (n 0) conf)
  6800. (org-with-remote-undo buffer
  6801. (with-current-buffer buffer
  6802. (save-excursion
  6803. (goto-char pos)
  6804. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  6805. (setq dbeg (progn (org-back-to-heading t) (point))
  6806. dend (org-end-of-subtree t t))
  6807. (setq dbeg (point-at-bol)
  6808. dend (min (point-max) (1+ (point-at-eol)))))
  6809. (goto-char dbeg)
  6810. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6811. (setq conf (or (eq t org-agenda-confirm-kill)
  6812. (and (numberp org-agenda-confirm-kill)
  6813. (> n org-agenda-confirm-kill))))
  6814. (and conf
  6815. (not (y-or-n-p
  6816. (format "Delete entry with %d lines in buffer \"%s\"? "
  6817. n (buffer-name buffer))))
  6818. (error "Abort"))
  6819. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6820. (with-current-buffer buffer (delete-region dbeg dend))
  6821. (message "Agenda item and source killed"))))
  6822. (defvar org-archive-default-command)
  6823. (defun org-agenda-archive-default ()
  6824. "Archive the entry or subtree belonging to the current agenda entry."
  6825. (interactive)
  6826. (require 'org-archive)
  6827. (org-agenda-archive-with org-archive-default-command))
  6828. (defun org-agenda-archive-default-with-confirmation ()
  6829. "Archive the entry or subtree belonging to the current agenda entry."
  6830. (interactive)
  6831. (require 'org-archive)
  6832. (org-agenda-archive-with org-archive-default-command 'confirm))
  6833. (defun org-agenda-archive ()
  6834. "Archive the entry or subtree belonging to the current agenda entry."
  6835. (interactive)
  6836. (org-agenda-archive-with 'org-archive-subtree))
  6837. (defun org-agenda-archive-to-archive-sibling ()
  6838. "Move the entry to the archive sibling."
  6839. (interactive)
  6840. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6841. (defun org-agenda-archive-with (cmd &optional confirm)
  6842. "Move the entry to the archive sibling."
  6843. (interactive)
  6844. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6845. (let* ((marker (or (org-get-at-bol 'org-marker)
  6846. (org-agenda-error)))
  6847. (buffer (marker-buffer marker))
  6848. (pos (marker-position marker)))
  6849. (org-with-remote-undo buffer
  6850. (with-current-buffer buffer
  6851. (if (derived-mode-p 'org-mode)
  6852. (if (and confirm
  6853. (not (y-or-n-p "Archive this subtree or entry? ")))
  6854. (error "Abort")
  6855. (save-excursion
  6856. (goto-char pos)
  6857. (org-remove-subtree-entries-from-agenda)
  6858. (org-back-to-heading t)
  6859. (funcall cmd)))
  6860. (error "Archiving works only in Org-mode files"))))))
  6861. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6862. "Remove all lines in the agenda that correspond to a given subtree.
  6863. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6864. If this information is not given, the function uses the tree at point."
  6865. (let ((buf (or buf (current-buffer))) m p)
  6866. (save-excursion
  6867. (unless (and beg end)
  6868. (org-back-to-heading t)
  6869. (setq beg (point))
  6870. (org-end-of-subtree t)
  6871. (setq end (point)))
  6872. (set-buffer (get-buffer org-agenda-buffer-name))
  6873. (save-excursion
  6874. (goto-char (point-max))
  6875. (beginning-of-line 1)
  6876. (while (not (bobp))
  6877. (when (and (setq m (org-get-at-bol 'org-marker))
  6878. (equal buf (marker-buffer m))
  6879. (setq p (marker-position m))
  6880. (>= p beg)
  6881. (< p end))
  6882. (let ((inhibit-read-only t))
  6883. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6884. (beginning-of-line 0))))))
  6885. (defun org-agenda-refile (&optional goto rfloc no-update)
  6886. "Refile the item at point."
  6887. (interactive "P")
  6888. (if (equal goto '(16))
  6889. (org-refile-goto-last-stored)
  6890. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6891. (org-agenda-error)))
  6892. (buffer (marker-buffer marker))
  6893. (pos (marker-position marker))
  6894. (rfloc (or rfloc
  6895. (org-refile-get-location
  6896. (if goto "Goto" "Refile to") buffer
  6897. org-refile-allow-creating-parent-nodes))))
  6898. (with-current-buffer buffer
  6899. (save-excursion
  6900. (save-restriction
  6901. (widen)
  6902. (goto-char marker)
  6903. (org-remove-subtree-entries-from-agenda)
  6904. (org-refile goto buffer rfloc)))))
  6905. (unless no-update (org-agenda-redo))))
  6906. (defun org-agenda-open-link (&optional arg)
  6907. "Follow the link in the current line, if any.
  6908. This looks for a link in the displayed line in the agenda. It also looks
  6909. at the text of the entry itself."
  6910. (interactive "P")
  6911. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6912. (org-get-at-bol 'org-marker)))
  6913. (buffer (and marker (marker-buffer marker)))
  6914. (prefix (buffer-substring
  6915. (point-at-bol) (point-at-eol))))
  6916. (cond
  6917. (buffer
  6918. (with-current-buffer buffer
  6919. (save-excursion
  6920. (save-restriction
  6921. (widen)
  6922. (goto-char marker)
  6923. (org-offer-links-in-entry arg prefix)))))
  6924. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6925. (save-excursion
  6926. (beginning-of-line 1)
  6927. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6928. (org-open-link-from-string (match-string 1)))
  6929. (t (error "No link to open here")))))
  6930. (defun org-agenda-copy-local-variable (var)
  6931. "Get a variable from a referenced buffer and install it here."
  6932. (let ((m (org-get-at-bol 'org-marker)))
  6933. (when (and m (buffer-live-p (marker-buffer m)))
  6934. (org-set-local var (with-current-buffer (marker-buffer m)
  6935. (symbol-value var))))))
  6936. (defun org-agenda-switch-to (&optional delete-other-windows)
  6937. "Go to the Org-mode file which contains the item at point."
  6938. (interactive)
  6939. (if (and org-return-follows-link
  6940. (not (org-get-at-bol 'org-marker))
  6941. (org-in-regexp org-bracket-link-regexp))
  6942. (org-open-link-from-string (match-string 0))
  6943. (let* ((marker (or (org-get-at-bol 'org-marker)
  6944. (org-agenda-error)))
  6945. (buffer (marker-buffer marker))
  6946. (pos (marker-position marker)))
  6947. (org-pop-to-buffer-same-window buffer)
  6948. (and delete-other-windows (delete-other-windows))
  6949. (widen)
  6950. (goto-char pos)
  6951. (when (derived-mode-p 'org-mode)
  6952. (org-show-context 'agenda)
  6953. (save-excursion
  6954. (and (outline-next-heading)
  6955. (org-flag-heading nil))) ; show the next heading
  6956. (when (outline-invisible-p)
  6957. (show-entry)))))) ; display invisible text
  6958. (defun org-agenda-goto-mouse (ev)
  6959. "Go to the Org-mode file which contains the item at the mouse click."
  6960. (interactive "e")
  6961. (mouse-set-point ev)
  6962. (org-agenda-goto))
  6963. (defun org-agenda-show (&optional full-entry)
  6964. "Display the Org-mode file which contains the item at point.
  6965. With prefix argument FULL-ENTRY, make the entire entry visible
  6966. if it was hidden in the outline."
  6967. (interactive "P")
  6968. (let ((win (selected-window)))
  6969. (if full-entry
  6970. (let ((org-show-entry-below t))
  6971. (org-agenda-goto t))
  6972. (org-agenda-goto t))
  6973. (select-window win)))
  6974. (defvar org-agenda-show-window nil)
  6975. (defun org-agenda-show-and-scroll-up (&optional arg)
  6976. "Display the Org-mode file which contains the item at point.
  6977. When called repeatedly, scroll the window that is displaying the buffer.
  6978. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6979. `show-subtree' to display the item, so that drawers and logbooks stay
  6980. folded."
  6981. (interactive "P")
  6982. (let ((win (selected-window)))
  6983. (if (and (window-live-p org-agenda-show-window)
  6984. (eq this-command last-command))
  6985. (progn
  6986. (select-window org-agenda-show-window)
  6987. (ignore-errors (scroll-up)))
  6988. (org-agenda-goto t)
  6989. (if arg (org-show-entry) (show-subtree))
  6990. (setq org-agenda-show-window (selected-window)))
  6991. (select-window win)))
  6992. (defun org-agenda-show-scroll-down ()
  6993. "Scroll down the window showing the agenda."
  6994. (interactive)
  6995. (let ((win (selected-window)))
  6996. (when (window-live-p org-agenda-show-window)
  6997. (select-window org-agenda-show-window)
  6998. (ignore-errors (scroll-down))
  6999. (select-window win))))
  7000. (defun org-agenda-show-1 (&optional more)
  7001. "Display the Org-mode file which contains the item at point.
  7002. The prefix arg selects the amount of information to display:
  7003. 0 hide the subtree
  7004. 1 just show the entry according to defaults.
  7005. 2 show the children view
  7006. 3 show the subtree view
  7007. 4 show the entire subtree and any LOGBOOK drawers
  7008. 5 show the entire subtree and any drawers
  7009. With prefix argument FULL-ENTRY, make the entire entry visible
  7010. if it was hidden in the outline."
  7011. (interactive "p")
  7012. (let ((win (selected-window)))
  7013. (org-agenda-goto t)
  7014. (org-recenter-heading 1)
  7015. (cond
  7016. ((= more 0)
  7017. (hide-subtree)
  7018. (save-excursion
  7019. (org-back-to-heading)
  7020. (run-hook-with-args 'org-cycle-hook 'folded))
  7021. (message "Remote: FOLDED"))
  7022. ((and (org-called-interactively-p 'any) (= more 1))
  7023. (message "Remote: show with default settings"))
  7024. ((= more 2)
  7025. (show-entry)
  7026. (show-children)
  7027. (save-excursion
  7028. (org-back-to-heading)
  7029. (run-hook-with-args 'org-cycle-hook 'children))
  7030. (message "Remote: CHILDREN"))
  7031. ((= more 3)
  7032. (show-subtree)
  7033. (save-excursion
  7034. (org-back-to-heading)
  7035. (run-hook-with-args 'org-cycle-hook 'subtree))
  7036. (message "Remote: SUBTREE"))
  7037. ((= more 4)
  7038. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7039. (org-drawer-regexp
  7040. (concat "^[ \t]*:\\("
  7041. (mapconcat 'regexp-quote org-drawers "\\|")
  7042. "\\):[ \t]*$")))
  7043. (show-subtree)
  7044. (save-excursion
  7045. (org-back-to-heading)
  7046. (org-cycle-hide-drawers 'subtree)))
  7047. (message "Remote: SUBTREE AND LOGBOOK"))
  7048. ((> more 4)
  7049. (show-subtree)
  7050. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7051. (select-window win)))
  7052. (defun org-recenter-heading (n)
  7053. (save-excursion
  7054. (org-back-to-heading)
  7055. (recenter n)))
  7056. (defvar org-agenda-cycle-counter nil)
  7057. (defun org-agenda-cycle-show (&optional n)
  7058. "Show the current entry in another window, with default settings.
  7059. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7060. When use repeatedly in immediate succession, the remote entry will cycle
  7061. through visibility
  7062. children -> subtree -> folded
  7063. When called with a numeric prefix arg, that arg will be passed through to
  7064. `org-agenda-show-1'. For the interpretation of that argument, see the
  7065. docstring of `org-agenda-show-1'."
  7066. (interactive "P")
  7067. (if (integerp n)
  7068. (setq org-agenda-cycle-counter n)
  7069. (if (not (eq last-command this-command))
  7070. (setq org-agenda-cycle-counter 1)
  7071. (if (equal org-agenda-cycle-counter 0)
  7072. (setq org-agenda-cycle-counter 2)
  7073. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7074. (if (> org-agenda-cycle-counter 3)
  7075. (setq org-agenda-cycle-counter 0)))))
  7076. (org-agenda-show-1 org-agenda-cycle-counter))
  7077. (defun org-agenda-recenter (arg)
  7078. "Display the Org-mode file which contains the item at point and recenter."
  7079. (interactive "P")
  7080. (let ((win (selected-window)))
  7081. (org-agenda-goto t)
  7082. (recenter arg)
  7083. (select-window win)))
  7084. (defun org-agenda-show-mouse (ev)
  7085. "Display the Org-mode file which contains the item at the mouse click."
  7086. (interactive "e")
  7087. (mouse-set-point ev)
  7088. (org-agenda-show))
  7089. (defun org-agenda-check-no-diary ()
  7090. "Check if the entry is a diary link and abort if yes."
  7091. (if (org-get-at-bol 'org-agenda-diary-link)
  7092. (org-agenda-error)))
  7093. (defun org-agenda-error ()
  7094. (error "Command not allowed in this line"))
  7095. (defun org-agenda-tree-to-indirect-buffer ()
  7096. "Show the subtree corresponding to the current entry in an indirect buffer.
  7097. This calls the command `org-tree-to-indirect-buffer' from the original
  7098. Org-mode buffer.
  7099. With numerical prefix arg ARG, go up to this level and then take that tree.
  7100. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7101. use the dedicated frame)."
  7102. (interactive)
  7103. (if (and current-prefix-arg (listp current-prefix-arg))
  7104. (org-agenda-do-tree-to-indirect-buffer)
  7105. (let ((agenda-window (selected-window))
  7106. (indirect-window
  7107. (and org-last-indirect-buffer
  7108. (get-buffer-window org-last-indirect-buffer))))
  7109. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7110. (unwind-protect
  7111. (progn
  7112. (unless (and indirect-window (window-live-p indirect-window))
  7113. (setq indirect-window (split-window agenda-window)))
  7114. (select-window indirect-window)
  7115. (switch-to-buffer org-last-indirect-buffer :norecord)
  7116. (fit-window-to-buffer indirect-window))
  7117. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7118. (defun org-agenda-do-tree-to-indirect-buffer ()
  7119. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7120. (org-agenda-check-no-diary)
  7121. (let* ((marker (or (org-get-at-bol 'org-marker)
  7122. (org-agenda-error)))
  7123. (buffer (marker-buffer marker))
  7124. (pos (marker-position marker)))
  7125. (with-current-buffer buffer
  7126. (save-excursion
  7127. (goto-char pos)
  7128. (call-interactively 'org-tree-to-indirect-buffer)))))
  7129. (defvar org-last-heading-marker (make-marker)
  7130. "Marker pointing to the headline that last changed its TODO state
  7131. by a remote command from the agenda.")
  7132. (defun org-agenda-todo-nextset ()
  7133. "Switch TODO entry to next sequence."
  7134. (interactive)
  7135. (org-agenda-todo 'nextset))
  7136. (defun org-agenda-todo-previousset ()
  7137. "Switch TODO entry to previous sequence."
  7138. (interactive)
  7139. (org-agenda-todo 'previousset))
  7140. (defun org-agenda-todo (&optional arg)
  7141. "Cycle TODO state of line at point, also in Org-mode file.
  7142. This changes the line at point, all other lines in the agenda referring to
  7143. the same tree node, and the headline of the tree node in the Org-mode file."
  7144. (interactive "P")
  7145. (org-agenda-check-no-diary)
  7146. (let* ((col (current-column))
  7147. (marker (or (org-get-at-bol 'org-marker)
  7148. (org-agenda-error)))
  7149. (buffer (marker-buffer marker))
  7150. (pos (marker-position marker))
  7151. (hdmarker (org-get-at-bol 'org-hd-marker))
  7152. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7153. (inhibit-read-only t)
  7154. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7155. (org-with-remote-undo buffer
  7156. (with-current-buffer buffer
  7157. (widen)
  7158. (goto-char pos)
  7159. (org-show-context 'agenda)
  7160. (save-excursion
  7161. (and (outline-next-heading)
  7162. (org-flag-heading nil))) ; show the next heading
  7163. (let ((current-prefix-arg arg))
  7164. (call-interactively 'org-todo))
  7165. (and (bolp) (forward-char 1))
  7166. (setq newhead (org-get-heading))
  7167. (when (and (org-bound-and-true-p
  7168. org-agenda-headline-snapshot-before-repeat)
  7169. (not (equal org-agenda-headline-snapshot-before-repeat
  7170. newhead))
  7171. todayp)
  7172. (setq newhead org-agenda-headline-snapshot-before-repeat
  7173. just-one t))
  7174. (save-excursion
  7175. (org-back-to-heading)
  7176. (move-marker org-last-heading-marker (point))))
  7177. (beginning-of-line 1)
  7178. (save-excursion
  7179. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7180. (org-move-to-column col))))
  7181. (defun org-agenda-add-note (&optional arg)
  7182. "Add a time-stamped note to the entry at point."
  7183. (interactive "P")
  7184. (org-agenda-check-no-diary)
  7185. (let* ((marker (or (org-get-at-bol 'org-marker)
  7186. (org-agenda-error)))
  7187. (buffer (marker-buffer marker))
  7188. (pos (marker-position marker))
  7189. (hdmarker (org-get-at-bol 'org-hd-marker))
  7190. (inhibit-read-only t))
  7191. (with-current-buffer buffer
  7192. (widen)
  7193. (goto-char pos)
  7194. (org-show-context 'agenda)
  7195. (save-excursion
  7196. (and (outline-next-heading)
  7197. (org-flag-heading nil))) ; show the next heading
  7198. (org-add-note))))
  7199. (defun org-agenda-change-all-lines (newhead hdmarker
  7200. &optional fixface just-this)
  7201. "Change all lines in the agenda buffer which match HDMARKER.
  7202. The new content of the line will be NEWHEAD (as modified by
  7203. `org-agenda-format-item'). HDMARKER is checked with
  7204. `equal' against all `org-hd-marker' text properties in the file.
  7205. If FIXFACE is non-nil, the face of each item is modified according to
  7206. the new TODO state.
  7207. If JUST-THIS is non-nil, change just the current line, not all.
  7208. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7209. (let* ((inhibit-read-only t)
  7210. (line (org-current-line))
  7211. (org-agenda-buffer (current-buffer))
  7212. (thetags (with-current-buffer (marker-buffer hdmarker)
  7213. (save-excursion (save-restriction (widen)
  7214. (goto-char hdmarker)
  7215. (org-get-tags-at)))))
  7216. props m pl undone-face done-face finish new dotime cat tags)
  7217. (save-excursion
  7218. (goto-char (point-max))
  7219. (beginning-of-line 1)
  7220. (while (not finish)
  7221. (setq finish (bobp))
  7222. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7223. (or (not just-this) (= (org-current-line) line))
  7224. (equal m hdmarker))
  7225. (setq props (text-properties-at (point))
  7226. dotime (org-get-at-bol 'dotime)
  7227. cat (org-get-at-bol 'org-category)
  7228. tags thetags
  7229. new
  7230. (let ((org-prefix-format-compiled
  7231. (or (get-text-property (point) 'format)
  7232. org-prefix-format-compiled))
  7233. (extra (org-get-at-bol 'extra)))
  7234. (with-current-buffer (marker-buffer hdmarker)
  7235. (save-excursion
  7236. (save-restriction
  7237. (widen)
  7238. (org-agenda-format-item extra newhead cat tags dotime)))))
  7239. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7240. undone-face (org-get-at-bol 'undone-face)
  7241. done-face (org-get-at-bol 'done-face))
  7242. (beginning-of-line 1)
  7243. (cond
  7244. ((equal new "")
  7245. (and (looking-at ".*\n?") (replace-match "")))
  7246. ((looking-at ".*")
  7247. (replace-match new t t)
  7248. (beginning-of-line 1)
  7249. (add-text-properties (point-at-bol) (point-at-eol) props)
  7250. (when fixface
  7251. (add-text-properties
  7252. (point-at-bol) (point-at-eol)
  7253. (list 'face
  7254. (if org-last-todo-state-is-todo
  7255. undone-face done-face))))
  7256. (org-agenda-highlight-todo 'line)
  7257. (beginning-of-line 1))
  7258. (t (error "Line update did not work"))))
  7259. (beginning-of-line 0)))
  7260. (org-finalize-agenda)))
  7261. (defun org-agenda-align-tags (&optional line)
  7262. "Align all tags in agenda items to `org-agenda-tags-column'."
  7263. (let ((inhibit-read-only t) l c)
  7264. (save-excursion
  7265. (goto-char (if line (point-at-bol) (point-min)))
  7266. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7267. (if line (point-at-eol) nil) t)
  7268. (add-text-properties
  7269. (match-beginning 2) (match-end 2)
  7270. (list 'face (delq nil (let ((prop (get-text-property
  7271. (match-beginning 2) 'face)))
  7272. (or (listp prop) (setq prop (list prop)))
  7273. (if (memq 'org-tag prop)
  7274. prop
  7275. (cons 'org-tag prop))))))
  7276. (setq l (- (match-end 2) (match-beginning 2))
  7277. c (if (< org-agenda-tags-column 0)
  7278. (- (abs org-agenda-tags-column) l)
  7279. org-agenda-tags-column))
  7280. (delete-region (match-beginning 1) (match-end 1))
  7281. (goto-char (match-beginning 1))
  7282. (insert (org-add-props
  7283. (make-string (max 1 (- c (current-column))) ?\ )
  7284. (plist-put (copy-sequence (text-properties-at (point)))
  7285. 'face nil))))
  7286. (goto-char (point-min))
  7287. (org-font-lock-add-tag-faces (point-max)))))
  7288. (defun org-agenda-priority-up ()
  7289. "Increase the priority of line at point, also in Org-mode file."
  7290. (interactive)
  7291. (org-agenda-priority 'up))
  7292. (defun org-agenda-priority-down ()
  7293. "Decrease the priority of line at point, also in Org-mode file."
  7294. (interactive)
  7295. (org-agenda-priority 'down))
  7296. (defun org-agenda-priority (&optional force-direction)
  7297. "Set the priority of line at point, also in Org-mode file.
  7298. This changes the line at point, all other lines in the agenda referring to
  7299. the same tree node, and the headline of the tree node in the Org-mode file."
  7300. (interactive)
  7301. (unless org-enable-priority-commands
  7302. (error "Priority commands are disabled"))
  7303. (org-agenda-check-no-diary)
  7304. (let* ((marker (or (org-get-at-bol 'org-marker)
  7305. (org-agenda-error)))
  7306. (hdmarker (org-get-at-bol 'org-hd-marker))
  7307. (buffer (marker-buffer hdmarker))
  7308. (pos (marker-position hdmarker))
  7309. (inhibit-read-only t)
  7310. newhead)
  7311. (org-with-remote-undo buffer
  7312. (with-current-buffer buffer
  7313. (widen)
  7314. (goto-char pos)
  7315. (org-show-context 'agenda)
  7316. (save-excursion
  7317. (and (outline-next-heading)
  7318. (org-flag-heading nil))) ; show the next heading
  7319. (funcall 'org-priority force-direction)
  7320. (end-of-line 1)
  7321. (setq newhead (org-get-heading)))
  7322. (org-agenda-change-all-lines newhead hdmarker)
  7323. (beginning-of-line 1))))
  7324. ;; FIXME: should fix the tags property of the agenda line.
  7325. (defun org-agenda-set-tags (&optional tag onoff)
  7326. "Set tags for the current headline."
  7327. (interactive)
  7328. (org-agenda-check-no-diary)
  7329. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7330. (call-interactively 'org-change-tag-in-region)
  7331. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7332. (org-agenda-error)))
  7333. (buffer (marker-buffer hdmarker))
  7334. (pos (marker-position hdmarker))
  7335. (inhibit-read-only t)
  7336. newhead)
  7337. (org-with-remote-undo buffer
  7338. (with-current-buffer buffer
  7339. (widen)
  7340. (goto-char pos)
  7341. (save-excursion
  7342. (org-show-context 'agenda))
  7343. (save-excursion
  7344. (and (outline-next-heading)
  7345. (org-flag-heading nil))) ; show the next heading
  7346. (goto-char pos)
  7347. (if tag
  7348. (org-toggle-tag tag onoff)
  7349. (call-interactively 'org-set-tags))
  7350. (end-of-line 1)
  7351. (setq newhead (org-get-heading)))
  7352. (org-agenda-change-all-lines newhead hdmarker)
  7353. (beginning-of-line 1)))))
  7354. (defun org-agenda-set-property ()
  7355. "Set a property for the current headline."
  7356. (interactive)
  7357. (org-agenda-check-no-diary)
  7358. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7359. (org-agenda-error)))
  7360. (buffer (marker-buffer hdmarker))
  7361. (pos (marker-position hdmarker))
  7362. (inhibit-read-only t)
  7363. newhead)
  7364. (org-with-remote-undo buffer
  7365. (with-current-buffer buffer
  7366. (widen)
  7367. (goto-char pos)
  7368. (save-excursion
  7369. (org-show-context 'agenda))
  7370. (save-excursion
  7371. (and (outline-next-heading)
  7372. (org-flag-heading nil))) ; show the next heading
  7373. (goto-char pos)
  7374. (call-interactively 'org-set-property)))))
  7375. (defun org-agenda-set-effort ()
  7376. "Set the effort property for the current headline."
  7377. (interactive)
  7378. (org-agenda-check-no-diary)
  7379. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7380. (org-agenda-error)))
  7381. (buffer (marker-buffer hdmarker))
  7382. (pos (marker-position hdmarker))
  7383. (inhibit-read-only t)
  7384. newhead)
  7385. (org-with-remote-undo buffer
  7386. (with-current-buffer buffer
  7387. (widen)
  7388. (goto-char pos)
  7389. (save-excursion
  7390. (org-show-context 'agenda))
  7391. (save-excursion
  7392. (and (outline-next-heading)
  7393. (org-flag-heading nil))) ; show the next heading
  7394. (goto-char pos)
  7395. (call-interactively 'org-set-effort)
  7396. (end-of-line 1)
  7397. (setq newhead (org-get-heading)))
  7398. (org-agenda-change-all-lines newhead hdmarker))))
  7399. (defun org-agenda-toggle-archive-tag ()
  7400. "Toggle the archive tag for the current entry."
  7401. (interactive)
  7402. (org-agenda-check-no-diary)
  7403. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7404. (org-agenda-error)))
  7405. (buffer (marker-buffer hdmarker))
  7406. (pos (marker-position hdmarker))
  7407. (inhibit-read-only t)
  7408. newhead)
  7409. (org-with-remote-undo buffer
  7410. (with-current-buffer buffer
  7411. (widen)
  7412. (goto-char pos)
  7413. (org-show-context 'agenda)
  7414. (save-excursion
  7415. (and (outline-next-heading)
  7416. (org-flag-heading nil))) ; show the next heading
  7417. (call-interactively 'org-toggle-archive-tag)
  7418. (end-of-line 1)
  7419. (setq newhead (org-get-heading)))
  7420. (org-agenda-change-all-lines newhead hdmarker)
  7421. (beginning-of-line 1))))
  7422. (defun org-agenda-do-date-later (arg)
  7423. (interactive "P")
  7424. (cond
  7425. ((or (equal arg '(16))
  7426. (memq last-command
  7427. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7428. (setq this-command 'org-agenda-date-later-minutes)
  7429. (org-agenda-date-later-minutes 1))
  7430. ((or (equal arg '(4))
  7431. (memq last-command
  7432. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7433. (setq this-command 'org-agenda-date-later-hours)
  7434. (org-agenda-date-later-hours 1))
  7435. (t
  7436. (org-agenda-date-later (prefix-numeric-value arg)))))
  7437. (defun org-agenda-do-date-earlier (arg)
  7438. (interactive "P")
  7439. (cond
  7440. ((or (equal arg '(16))
  7441. (memq last-command
  7442. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7443. (setq this-command 'org-agenda-date-earlier-minutes)
  7444. (org-agenda-date-earlier-minutes 1))
  7445. ((or (equal arg '(4))
  7446. (memq last-command
  7447. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7448. (setq this-command 'org-agenda-date-earlier-hours)
  7449. (org-agenda-date-earlier-hours 1))
  7450. (t
  7451. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7452. (defun org-agenda-date-later (arg &optional what)
  7453. "Change the date of this item to ARG day(s) later."
  7454. (interactive "p")
  7455. (org-agenda-check-type t 'agenda 'timeline)
  7456. (org-agenda-check-no-diary)
  7457. (let* ((marker (or (org-get-at-bol 'org-marker)
  7458. (org-agenda-error)))
  7459. (buffer (marker-buffer marker))
  7460. (pos (marker-position marker))
  7461. cdate today)
  7462. (org-with-remote-undo buffer
  7463. (with-current-buffer buffer
  7464. (widen)
  7465. (goto-char pos)
  7466. (if (not (org-at-timestamp-p))
  7467. (error "Cannot find time stamp"))
  7468. (when (and org-agenda-move-date-from-past-immediately-to-today
  7469. (equal arg 1)
  7470. (or (not what) (eq what 'day))
  7471. (not (save-match-data (org-at-date-range-p))))
  7472. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7473. cdate (calendar-absolute-from-gregorian
  7474. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7475. today (org-today))
  7476. (if (> today cdate)
  7477. ;; immediately shift to today
  7478. (setq arg (- today cdate))))
  7479. (org-timestamp-change arg (or what 'day))
  7480. (when (and (org-at-date-range-p)
  7481. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7482. (let ((end org-last-changed-timestamp))
  7483. (org-timestamp-change arg (or what 'day))
  7484. (setq org-last-changed-timestamp
  7485. (concat org-last-changed-timestamp "--" end)))))
  7486. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7487. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7488. (defun org-agenda-date-earlier (arg &optional what)
  7489. "Change the date of this item to ARG day(s) earlier."
  7490. (interactive "p")
  7491. (org-agenda-date-later (- arg) what))
  7492. (defun org-agenda-date-later-minutes (arg)
  7493. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7494. (interactive "p")
  7495. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7496. (org-agenda-date-later arg 'minute))
  7497. (defun org-agenda-date-earlier-minutes (arg)
  7498. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7499. (interactive "p")
  7500. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7501. (org-agenda-date-earlier arg 'minute))
  7502. (defun org-agenda-date-later-hours (arg)
  7503. "Change the time of this item, in hour steps."
  7504. (interactive "p")
  7505. (org-agenda-date-later arg 'hour))
  7506. (defun org-agenda-date-earlier-hours (arg)
  7507. "Change the time of this item, in hour steps."
  7508. (interactive "p")
  7509. (org-agenda-date-earlier arg 'hour))
  7510. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7511. "Show new date stamp via text properties."
  7512. ;; We use text properties to make this undoable
  7513. (let ((inhibit-read-only t)
  7514. (buffer-invisibility-spec))
  7515. (setq stamp (concat " " prefix " => " stamp))
  7516. (save-excursion
  7517. (goto-char (point-max))
  7518. (while (not (bobp))
  7519. (when (equal marker (org-get-at-bol 'org-marker))
  7520. (org-move-to-column (- (window-width) (length stamp)) t)
  7521. (org-agenda-fix-tags-filter-overlays-at (point))
  7522. (if (featurep 'xemacs)
  7523. ;; Use `duplicable' property to trigger undo recording
  7524. (let ((ex (make-extent nil nil))
  7525. (gl (make-glyph stamp)))
  7526. (set-glyph-face gl 'secondary-selection)
  7527. (set-extent-properties
  7528. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7529. (insert-extent ex (1- (point)) (point-at-eol)))
  7530. (add-text-properties
  7531. (1- (point)) (point-at-eol)
  7532. (list 'display (org-add-props stamp nil
  7533. 'face 'secondary-selection))))
  7534. (beginning-of-line 1))
  7535. (beginning-of-line 0)))))
  7536. (defun org-agenda-date-prompt (arg)
  7537. "Change the date of this item. Date is prompted for, with default today.
  7538. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7539. be used to request time specification in the time stamp."
  7540. (interactive "P")
  7541. (org-agenda-check-type t 'agenda 'timeline)
  7542. (org-agenda-check-no-diary)
  7543. (let* ((marker (or (org-get-at-bol 'org-marker)
  7544. (org-agenda-error)))
  7545. (buffer (marker-buffer marker))
  7546. (pos (marker-position marker)))
  7547. (org-with-remote-undo buffer
  7548. (with-current-buffer buffer
  7549. (widen)
  7550. (goto-char pos)
  7551. (if (not (org-at-timestamp-p t))
  7552. (error "Cannot find time stamp"))
  7553. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7554. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7555. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7556. (defun org-agenda-schedule (arg &optional time)
  7557. "Schedule the item at point.
  7558. ARG is passed through to `org-schedule'."
  7559. (interactive "P")
  7560. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7561. (org-agenda-check-no-diary)
  7562. (let* ((marker (or (org-get-at-bol 'org-marker)
  7563. (org-agenda-error)))
  7564. (type (marker-insertion-type marker))
  7565. (buffer (marker-buffer marker))
  7566. (pos (marker-position marker))
  7567. (org-insert-labeled-timestamps-at-point nil)
  7568. ts)
  7569. (set-marker-insertion-type marker t)
  7570. (org-with-remote-undo buffer
  7571. (with-current-buffer buffer
  7572. (widen)
  7573. (goto-char pos)
  7574. (setq ts (org-schedule arg time)))
  7575. (org-agenda-show-new-time marker ts "S"))
  7576. (message "Item scheduled for %s" ts)))
  7577. (defun org-agenda-deadline (arg &optional time)
  7578. "Schedule the item at point.
  7579. ARG is passed through to `org-deadline'."
  7580. (interactive "P")
  7581. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7582. (org-agenda-check-no-diary)
  7583. (let* ((marker (or (org-get-at-bol 'org-marker)
  7584. (org-agenda-error)))
  7585. (buffer (marker-buffer marker))
  7586. (pos (marker-position marker))
  7587. (org-insert-labeled-timestamps-at-point nil)
  7588. ts)
  7589. (org-with-remote-undo buffer
  7590. (with-current-buffer buffer
  7591. (widen)
  7592. (goto-char pos)
  7593. (setq ts (org-deadline arg time)))
  7594. (org-agenda-show-new-time marker ts "D"))
  7595. (message "Deadline for this item set to %s" ts)))
  7596. (defun org-agenda-action ()
  7597. "Select entry for agenda action, or execute an agenda action.
  7598. This command prompts for another letter. Valid inputs are:
  7599. m Mark the entry at point for an agenda action
  7600. s Schedule the marked entry to the date at the cursor
  7601. d Set the deadline of the marked entry to the date at the cursor
  7602. r Call `org-remember' with cursor date as the default date
  7603. c Call `org-capture' with cursor date as the default date
  7604. SPC Show marked entry in other window
  7605. TAB Visit marked entry in other window
  7606. The cursor may be at a date in the calendar, or in the Org agenda."
  7607. (interactive)
  7608. (let (ans)
  7609. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7610. (setq ans (read-char-exclusive))
  7611. (cond
  7612. ((equal ans ?m)
  7613. ;; Mark this entry
  7614. (if (eq major-mode 'org-agenda-mode)
  7615. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7616. (org-get-at-bol 'org-marker))))
  7617. (if m
  7618. (progn
  7619. (move-marker org-agenda-action-marker
  7620. (marker-position m) (marker-buffer m))
  7621. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7622. (error "Don't know which entry to mark")))
  7623. (error "This command works only in the agenda")))
  7624. ((equal ans ?s)
  7625. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7626. ((equal ans ?d)
  7627. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7628. ((equal ans ?r)
  7629. (org-agenda-do-action '(org-remember) t))
  7630. ((equal ans ?c)
  7631. (org-agenda-do-action '(org-capture) t))
  7632. ((equal ans ?\ )
  7633. (let ((cw (selected-window)))
  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. (select-window cw)))
  7639. ((equal ans ?\C-i)
  7640. (org-switch-to-buffer-other-window
  7641. (marker-buffer org-agenda-action-marker))
  7642. (goto-char org-agenda-action-marker)
  7643. (org-show-context 'agenda))
  7644. (t (error "Invalid agenda action %c" ans)))))
  7645. (defun org-agenda-do-action (form &optional current-buffer)
  7646. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7647. (let ((org-overriding-default-time (org-get-cursor-date)))
  7648. (if current-buffer
  7649. (eval form)
  7650. (if (not (marker-buffer org-agenda-action-marker))
  7651. (error "No entry has been selected for agenda action")
  7652. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7653. (save-excursion
  7654. (save-restriction
  7655. (widen)
  7656. (goto-char org-agenda-action-marker)
  7657. (eval form))))))))
  7658. (defun org-agenda-clock-in (&optional arg)
  7659. "Start the clock on the currently selected item."
  7660. (interactive "P")
  7661. (org-agenda-check-no-diary)
  7662. (if (equal arg '(4))
  7663. (org-clock-in arg)
  7664. (let* ((marker (or (org-get-at-bol 'org-marker)
  7665. (org-agenda-error)))
  7666. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7667. marker))
  7668. (pos (marker-position marker))
  7669. newhead)
  7670. (org-with-remote-undo (marker-buffer marker)
  7671. (with-current-buffer (marker-buffer marker)
  7672. (widen)
  7673. (goto-char pos)
  7674. (org-show-context 'agenda)
  7675. (org-show-entry)
  7676. (org-cycle-hide-drawers 'children)
  7677. (org-clock-in arg)
  7678. (setq newhead (org-get-heading)))
  7679. (org-agenda-change-all-lines newhead hdmarker)))))
  7680. (defun org-agenda-clock-out ()
  7681. "Stop the currently running clock."
  7682. (interactive)
  7683. (unless (marker-buffer org-clock-marker)
  7684. (error "No running clock"))
  7685. (let ((marker (make-marker)) newhead)
  7686. (org-with-remote-undo (marker-buffer org-clock-marker)
  7687. (with-current-buffer (marker-buffer org-clock-marker)
  7688. (save-excursion
  7689. (save-restriction
  7690. (widen)
  7691. (goto-char org-clock-marker)
  7692. (org-back-to-heading t)
  7693. (move-marker marker (point))
  7694. (org-clock-out)
  7695. (setq newhead (org-get-heading))))))
  7696. (org-agenda-change-all-lines newhead marker)
  7697. (move-marker marker nil)))
  7698. (defun org-agenda-clock-cancel (&optional arg)
  7699. "Cancel the currently running clock."
  7700. (interactive "P")
  7701. (unless (marker-buffer org-clock-marker)
  7702. (error "No running clock"))
  7703. (org-with-remote-undo (marker-buffer org-clock-marker)
  7704. (org-clock-cancel)))
  7705. (defun org-agenda-clock-goto ()
  7706. "Jump to the currently clocked in task within the agenda.
  7707. If the currently clocked in task is not listed in the agenda
  7708. buffer, display it in another window."
  7709. (interactive)
  7710. (let (pos)
  7711. (mapc (lambda (o)
  7712. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7713. (setq pos (overlay-start o))))
  7714. (overlays-in (point-min) (point-max)))
  7715. (cond (pos (goto-char pos))
  7716. ;; If the currently clocked entry is not in the agenda
  7717. ;; buffer, we visit it in another window:
  7718. (org-clock-current-task
  7719. (org-switch-to-buffer-other-window (org-clock-goto)))
  7720. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7721. (defun org-agenda-diary-entry-in-org-file ()
  7722. "Make a diary entry in the file `org-agenda-diary-file'."
  7723. (let (d1 d2 char (text "") dp1 dp2)
  7724. (if (equal (buffer-name) "*Calendar*")
  7725. (setq d1 (calendar-cursor-to-date t)
  7726. d2 (car calendar-mark-ring))
  7727. (setq dp1 (get-text-property (point-at-bol) 'day))
  7728. (unless dp1 (error "No date defined in current line"))
  7729. (setq d1 (calendar-gregorian-from-absolute dp1)
  7730. d2 (and (ignore-errors (mark))
  7731. (save-excursion
  7732. (goto-char (mark))
  7733. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7734. (calendar-gregorian-from-absolute dp2))))
  7735. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7736. (setq char (read-char-exclusive))
  7737. (cond
  7738. ((equal char ?d)
  7739. (setq text (read-string "Day entry: "))
  7740. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7741. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7742. ((equal char ?a)
  7743. (setq d1 (list (car d1) (nth 1 d1)
  7744. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7745. (nth 2 d1))))
  7746. (setq text (read-string "Anniversary (use %d to show years): "))
  7747. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7748. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7749. ((equal char ?b)
  7750. (setq text (read-string "Block entry: "))
  7751. (unless (and d1 d2 (not (equal d1 d2)))
  7752. (error "No block of days selected"))
  7753. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7754. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7755. ((equal char ?j)
  7756. (org-switch-to-buffer-other-window
  7757. (find-file-noselect org-agenda-diary-file))
  7758. (require 'org-datetree)
  7759. (org-datetree-find-date-create d1)
  7760. (org-reveal t))
  7761. (t (error "Invalid selection character `%c'" char)))))
  7762. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7763. "Where in `org-agenda-diary-file' should new entries be added?
  7764. Valid values:
  7765. date-tree in the date tree, as child of the date
  7766. top-level as top-level entries at the end of the file."
  7767. :group 'org-agenda
  7768. :type '(choice
  7769. (const :tag "in a date tree" date-tree)
  7770. (const :tag "as top level at end of file" top-level)))
  7771. (defcustom org-agenda-insert-diary-extract-time nil
  7772. "Non-nil means extract any time specification from the diary entry."
  7773. :group 'org-agenda
  7774. :version "24.1"
  7775. :type 'boolean)
  7776. (defcustom org-agenda-bulk-mark-char ">"
  7777. "A single-character string to be used as the bulk mark."
  7778. :group 'org-agenda
  7779. :version "24.1"
  7780. :type 'string)
  7781. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7782. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7783. If TEXT is not empty, it will become the headline of the new entry, and
  7784. the resulting entry will not be shown. When TEXT is empty, switch to
  7785. `org-agenda-diary-file' and let the user finish the entry there."
  7786. (let ((cw (current-window-configuration)))
  7787. (org-switch-to-buffer-other-window
  7788. (find-file-noselect org-agenda-diary-file))
  7789. (widen)
  7790. (goto-char (point-min))
  7791. (cond
  7792. ((eq type 'anniversary)
  7793. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7794. (progn
  7795. (or (org-at-heading-p t)
  7796. (progn
  7797. (outline-next-heading)
  7798. (insert "* Anniversaries\n\n")
  7799. (beginning-of-line -1)))))
  7800. (outline-next-heading)
  7801. (org-back-over-empty-lines)
  7802. (backward-char 1)
  7803. (insert "\n")
  7804. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7805. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7806. ((eq type 'day)
  7807. (let ((org-prefix-has-time t)
  7808. (org-agenda-time-leading-zero t)
  7809. fmt time time2)
  7810. (if org-agenda-insert-diary-extract-time
  7811. ;; Use org-agenda-format-item to parse text for a time-range and
  7812. ;; remove it. FIXME: This is a hack, we should refactor
  7813. ;; that function to make time extraction available separately
  7814. (setq fmt (org-agenda-format-item nil text nil nil t)
  7815. time (get-text-property 0 'time fmt)
  7816. time2 (if (> (length time) 0)
  7817. ;; split-string removes trailing ...... if
  7818. ;; no end time given. First space
  7819. ;; separates time from date.
  7820. (concat " " (car (split-string time "\\.")))
  7821. nil)
  7822. text (get-text-property 0 'txt fmt)))
  7823. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7824. (org-agenda-insert-diary-as-top-level text)
  7825. (require 'org-datetree)
  7826. (org-datetree-find-date-create d1)
  7827. (org-agenda-insert-diary-make-new-entry text))
  7828. (org-insert-time-stamp (org-time-from-absolute
  7829. (calendar-absolute-from-gregorian d1))
  7830. nil nil nil nil time2))
  7831. (end-of-line 0))
  7832. ((eq type 'block)
  7833. (if (> (calendar-absolute-from-gregorian d1)
  7834. (calendar-absolute-from-gregorian d2))
  7835. (setq d1 (prog1 d2 (setq d2 d1))))
  7836. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7837. (org-agenda-insert-diary-as-top-level text)
  7838. (require 'org-datetree)
  7839. (org-datetree-find-date-create d1)
  7840. (org-agenda-insert-diary-make-new-entry text))
  7841. (org-insert-time-stamp (org-time-from-absolute
  7842. (calendar-absolute-from-gregorian d1)))
  7843. (insert "--")
  7844. (org-insert-time-stamp (org-time-from-absolute
  7845. (calendar-absolute-from-gregorian d2)))
  7846. (end-of-line 0)))
  7847. (if (string-match "\\S-" text)
  7848. (progn
  7849. (set-window-configuration cw)
  7850. (message "%s entry added to %s"
  7851. (capitalize (symbol-name type))
  7852. (abbreviate-file-name org-agenda-diary-file)))
  7853. (org-reveal t)
  7854. (message "Please finish entry here"))))
  7855. (defun org-agenda-insert-diary-as-top-level (text)
  7856. "Make new entry as a top-level entry at the end of the file.
  7857. Add TEXT as headline, and position the cursor in the second line so that
  7858. a timestamp can be added there."
  7859. (widen)
  7860. (goto-char (point-max))
  7861. (or (bolp) (insert "\n"))
  7862. (insert "* " text "\n")
  7863. (if org-adapt-indentation (org-indent-to-column 2)))
  7864. (defun org-agenda-insert-diary-make-new-entry (text)
  7865. "Make new entry as last child of current entry.
  7866. Add TEXT as headline, and position the cursor in the second line so that
  7867. a timestamp can be added there."
  7868. (let ((org-show-following-heading t)
  7869. (org-show-siblings t)
  7870. (org-show-hierarchy-above t)
  7871. (org-show-entry-below t)
  7872. col)
  7873. (outline-next-heading)
  7874. (org-back-over-empty-lines)
  7875. (or (looking-at "[ \t]*$")
  7876. (progn (insert "\n") (backward-char 1)))
  7877. (org-insert-heading nil t)
  7878. (org-do-demote)
  7879. (setq col (current-column))
  7880. (insert text "\n")
  7881. (if org-adapt-indentation (org-indent-to-column col))
  7882. (let ((org-show-following-heading t)
  7883. (org-show-siblings t)
  7884. (org-show-hierarchy-above t)
  7885. (org-show-entry-below t))
  7886. (org-show-context))))
  7887. (defun org-agenda-diary-entry ()
  7888. "Make a diary entry, like the `i' command from the calendar.
  7889. All the standard commands work: block, weekly etc.
  7890. When `org-agenda-diary-file' points to a file,
  7891. `org-agenda-diary-entry-in-org-file' is called instead to create
  7892. entries in that Org-mode file."
  7893. (interactive)
  7894. (org-agenda-check-type t 'agenda 'timeline)
  7895. (if (not (eq org-agenda-diary-file 'diary-file))
  7896. (org-agenda-diary-entry-in-org-file)
  7897. (require 'diary-lib)
  7898. (let* ((char (progn
  7899. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7900. (read-char-exclusive)))
  7901. (cmd (cdr (assoc char
  7902. '((?d . insert-diary-entry)
  7903. (?w . insert-weekly-diary-entry)
  7904. (?m . insert-monthly-diary-entry)
  7905. (?y . insert-yearly-diary-entry)
  7906. (?a . insert-anniversary-diary-entry)
  7907. (?b . insert-block-diary-entry)
  7908. (?c . insert-cyclic-diary-entry)))))
  7909. (oldf (symbol-function 'calendar-cursor-to-date))
  7910. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7911. (point (point))
  7912. (mark (or (mark t) (point))))
  7913. (unless cmd
  7914. (error "No command associated with <%c>" char))
  7915. (unless (and (get-text-property point 'day)
  7916. (or (not (equal ?b char))
  7917. (get-text-property mark 'day)))
  7918. (error "Don't know which date to use for diary entry"))
  7919. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7920. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7921. (let ((calendar-mark-ring
  7922. (list (calendar-gregorian-from-absolute
  7923. (or (get-text-property mark 'day)
  7924. (get-text-property point 'day))))))
  7925. (unwind-protect
  7926. (progn
  7927. (fset 'calendar-cursor-to-date
  7928. (lambda (&optional error dummy)
  7929. (calendar-gregorian-from-absolute
  7930. (get-text-property point 'day))))
  7931. (call-interactively cmd))
  7932. (fset 'calendar-cursor-to-date oldf))))))
  7933. (defun org-agenda-execute-calendar-command (cmd)
  7934. "Execute a calendar command from the agenda, with the date associated to
  7935. the cursor position."
  7936. (org-agenda-check-type t 'agenda 'timeline)
  7937. (require 'diary-lib)
  7938. (unless (get-text-property (point) 'day)
  7939. (error "Don't know which date to use for calendar command"))
  7940. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7941. (point (point))
  7942. (date (calendar-gregorian-from-absolute
  7943. (get-text-property point 'day)))
  7944. ;; the following 2 vars are needed in the calendar
  7945. (displayed-month (car date))
  7946. (displayed-year (nth 2 date)))
  7947. (unwind-protect
  7948. (progn
  7949. (fset 'calendar-cursor-to-date
  7950. (lambda (&optional error dummy)
  7951. (calendar-gregorian-from-absolute
  7952. (get-text-property point 'day))))
  7953. (call-interactively cmd))
  7954. (fset 'calendar-cursor-to-date oldf))))
  7955. (defun org-agenda-phases-of-moon ()
  7956. "Display the phases of the moon for the 3 months around the cursor date."
  7957. (interactive)
  7958. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7959. (defun org-agenda-holidays ()
  7960. "Display the holidays for the 3 months around the cursor date."
  7961. (interactive)
  7962. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7963. (defvar calendar-longitude)
  7964. (defvar calendar-latitude)
  7965. (defvar calendar-location-name)
  7966. (defun org-agenda-sunrise-sunset (arg)
  7967. "Display sunrise and sunset for the cursor date.
  7968. Latitude and longitude can be specified with the variables
  7969. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7970. argument, latitude and longitude will be prompted for."
  7971. (interactive "P")
  7972. (require 'solar)
  7973. (let ((calendar-longitude (if arg nil calendar-longitude))
  7974. (calendar-latitude (if arg nil calendar-latitude))
  7975. (calendar-location-name
  7976. (if arg "the given coordinates" calendar-location-name)))
  7977. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7978. (defun org-agenda-goto-calendar ()
  7979. "Open the Emacs calendar with the date at the cursor."
  7980. (interactive)
  7981. (org-agenda-check-type t 'agenda 'timeline)
  7982. (let* ((day (or (get-text-property (point) 'day)
  7983. (error "Don't know which date to open in calendar")))
  7984. (date (calendar-gregorian-from-absolute day))
  7985. (calendar-move-hook nil)
  7986. (calendar-view-holidays-initially-flag nil)
  7987. (calendar-view-diary-initially-flag nil))
  7988. (calendar)
  7989. (calendar-goto-date date)))
  7990. ;;;###autoload
  7991. (defun org-calendar-goto-agenda ()
  7992. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7993. This is a command that has to be installed in `calendar-mode-map'."
  7994. (interactive)
  7995. (org-agenda-list nil (calendar-absolute-from-gregorian
  7996. (calendar-cursor-to-date))
  7997. nil))
  7998. (defun org-agenda-convert-date ()
  7999. (interactive)
  8000. (org-agenda-check-type t 'agenda 'timeline)
  8001. (let ((day (get-text-property (point) 'day))
  8002. date s)
  8003. (unless day
  8004. (error "Don't know which date to convert"))
  8005. (setq date (calendar-gregorian-from-absolute day))
  8006. (setq s (concat
  8007. "Gregorian: " (calendar-date-string date) "\n"
  8008. "ISO: " (calendar-iso-date-string date) "\n"
  8009. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8010. "Julian: " (calendar-julian-date-string date) "\n"
  8011. "Astron. JD: " (calendar-astro-date-string date)
  8012. " (Julian date number at noon UTC)\n"
  8013. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8014. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8015. "French: " (calendar-french-date-string date) "\n"
  8016. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8017. "Mayan: " (calendar-mayan-date-string date) "\n"
  8018. "Coptic: " (calendar-coptic-date-string date) "\n"
  8019. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8020. "Persian: " (calendar-persian-date-string date) "\n"
  8021. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8022. (with-output-to-temp-buffer "*Dates*"
  8023. (princ s))
  8024. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8025. ;;; Bulk commands
  8026. (defvar org-agenda-bulk-marked-entries nil
  8027. "List of markers that refer to marked entries in the agenda.")
  8028. (defun org-agenda-bulk-marked-p ()
  8029. (eq (get-char-property (point-at-bol) 'type)
  8030. 'org-marked-entry-overlay))
  8031. (defun org-agenda-bulk-mark (&optional arg)
  8032. "Mark the entry at point for future bulk action."
  8033. (interactive "p")
  8034. (dotimes (i (or arg 1))
  8035. (unless (org-get-at-bol 'org-agenda-diary-link)
  8036. (let* ((m (org-get-at-bol 'org-hd-marker))
  8037. ov)
  8038. (unless (org-agenda-bulk-marked-p)
  8039. (unless m (error "Nothing to mark at point"))
  8040. (push m org-agenda-bulk-marked-entries)
  8041. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8042. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8043. (org-get-todo-face "TODO")
  8044. 'evaporate)
  8045. (overlay-put ov 'type 'org-marked-entry-overlay))
  8046. (beginning-of-line 2)
  8047. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8048. (beginning-of-line 2))
  8049. (message "%d entries marked for bulk action"
  8050. (length org-agenda-bulk-marked-entries))))))
  8051. (defun org-agenda-bulk-mark-all ()
  8052. "Mark all entries for future agenda bulk action."
  8053. (interactive)
  8054. (org-agenda-bulk-mark-regexp "."))
  8055. (defun org-agenda-bulk-mark-regexp (regexp)
  8056. "Mark entries matching REGEXP for future agenda bulk action."
  8057. (interactive "sMark entries matching regexp: ")
  8058. (let ((entries-marked 0))
  8059. (save-excursion
  8060. (goto-char (point-min))
  8061. (goto-char (next-single-property-change (point) 'txt))
  8062. (while (re-search-forward regexp nil t)
  8063. (when (string-match regexp (get-text-property (point) 'txt))
  8064. (setq entries-marked (1+ entries-marked))
  8065. (call-interactively 'org-agenda-bulk-mark))))
  8066. (if (not entries-marked)
  8067. (message "No entry matching this regexp."))))
  8068. (defun org-agenda-bulk-unmark (&optional arg)
  8069. "Unmark the entry at point for future bulk action."
  8070. (interactive "P")
  8071. (if arg
  8072. (org-agenda-bulk-unmark-all)
  8073. (cond ((org-agenda-bulk-marked-p)
  8074. (org-agenda-bulk-remove-overlays
  8075. (point-at-bol) (+ 2 (point-at-bol)))
  8076. (setq org-agenda-bulk-marked-entries
  8077. (delete (org-get-at-bol 'org-hd-marker)
  8078. org-agenda-bulk-marked-entries))
  8079. (beginning-of-line 2)
  8080. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8081. (beginning-of-line 2))
  8082. (message "%d entries left marked for bulk action"
  8083. (length org-agenda-bulk-marked-entries)))
  8084. (t (message "No entry to unmark here")))))
  8085. (defun org-agenda-bulk-toggle ()
  8086. "Toggle marking the entry at point for bulk action."
  8087. (interactive)
  8088. (if (org-agenda-bulk-marked-p)
  8089. (org-agenda-bulk-unmark)
  8090. (org-agenda-bulk-mark)))
  8091. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8092. "Remove the mark overlays between BEG and END in the agenda buffer.
  8093. BEG and END default to the buffer limits.
  8094. This only removes the overlays, it does not remove the markers
  8095. from the list in `org-agenda-bulk-marked-entries'."
  8096. (interactive)
  8097. (mapc (lambda (ov)
  8098. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8099. (delete-overlay ov)))
  8100. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8101. (defun org-agenda-bulk-unmark-all ()
  8102. "Remove all marks in the agenda buffer.
  8103. This will remove the markers and the overlays."
  8104. (interactive)
  8105. (if (null org-agenda-bulk-marked-entries)
  8106. (message "No entry to unmark")
  8107. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8108. (setq org-agenda-bulk-marked-entries nil)
  8109. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8110. (defcustom org-agenda-persistent-marks nil
  8111. "Non-nil means marked items will stay marked after a bulk action.
  8112. You can interactively and temporarily toggle by typing `p' when you
  8113. are prompted for a bulk action."
  8114. :group 'org-agenda
  8115. :version "24.1"
  8116. :type 'boolean)
  8117. (defun org-agenda-bulk-action (&optional arg)
  8118. "Execute an remote-editing action on all marked entries.
  8119. The prefix arg is passed through to the command if possible."
  8120. (interactive "P")
  8121. ;; Make sure we have markers, and only valid ones
  8122. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8123. (mapc
  8124. (lambda (m)
  8125. (unless (and (markerp m)
  8126. (marker-buffer m)
  8127. (buffer-live-p (marker-buffer m))
  8128. (marker-position m))
  8129. (error "Marker %s for bulk command is invalid" m)))
  8130. org-agenda-bulk-marked-entries)
  8131. ;; Prompt for the bulk command
  8132. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8133. (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
  8134. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
  8135. (when org-agenda-bulk-custom-functions
  8136. (concat " Custom: ["
  8137. (mapconcat (lambda(f) (char-to-string (car f)))
  8138. org-agenda-bulk-custom-functions "")
  8139. "]"))))
  8140. (catch 'exit
  8141. (let* ((action (read-char-exclusive))
  8142. (org-log-refile (if org-log-refile 'time nil))
  8143. (entries (reverse org-agenda-bulk-marked-entries))
  8144. redo-at-end
  8145. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8146. (cond
  8147. ((equal action ?p)
  8148. (let ((org-agenda-persistent-marks
  8149. (not org-agenda-persistent-marks)))
  8150. (org-agenda-bulk-action)
  8151. (throw 'exit nil)))
  8152. ((equal action ?$)
  8153. (setq cmd '(org-agenda-archive)))
  8154. ((equal action ?A)
  8155. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8156. ((member action '(?r ?w))
  8157. (setq rfloc (org-refile-get-location
  8158. "Refile to"
  8159. (marker-buffer (car org-agenda-bulk-marked-entries))
  8160. org-refile-allow-creating-parent-nodes))
  8161. (if (nth 3 rfloc)
  8162. (setcar (nthcdr 3 rfloc)
  8163. (move-marker (make-marker) (nth 3 rfloc)
  8164. (or (get-file-buffer (nth 1 rfloc))
  8165. (find-buffer-visiting (nth 1 rfloc))
  8166. (error "This should not happen")))))
  8167. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8168. redo-at-end t))
  8169. ((equal action ?t)
  8170. (setq state (org-icompleting-read
  8171. "Todo state: "
  8172. (with-current-buffer (marker-buffer (car entries))
  8173. (mapcar 'list org-todo-keywords-1))))
  8174. (setq cmd `(let ((org-inhibit-blocking t)
  8175. (org-inhibit-logging 'note))
  8176. (org-agenda-todo ,state))))
  8177. ((memq action '(?- ?+))
  8178. (setq tag (org-icompleting-read
  8179. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8180. (with-current-buffer (marker-buffer (car entries))
  8181. (delq nil
  8182. (mapcar (lambda (x)
  8183. (if (stringp (car x)) x)) org-tag-alist)))))
  8184. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8185. ((memq action '(?s ?d))
  8186. (let* ((date (unless arg
  8187. (org-read-date
  8188. nil nil nil
  8189. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8190. (ans (if arg nil org-read-date-final-answer))
  8191. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8192. (setq cmd `(let* ((bound (fboundp 'read-string))
  8193. (old (and bound (symbol-function 'read-string))))
  8194. (unwind-protect
  8195. (progn
  8196. (fset 'read-string (lambda (&rest ignore) ,ans))
  8197. (eval '(,c1 arg)))
  8198. (if bound
  8199. (fset 'read-string old)
  8200. (fmakunbound 'read-string)))))))
  8201. ((equal action ?S)
  8202. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8203. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8204. (let ((days (read-number
  8205. (format "Scatter tasks across how many %sdays: "
  8206. (if arg "week" "")) 7)))
  8207. (setq cmd
  8208. `(let ((distance (1+ (random ,days))))
  8209. (if arg
  8210. (let ((dist distance)
  8211. (day-of-week
  8212. (calendar-day-of-week
  8213. (calendar-gregorian-from-absolute (org-today)))))
  8214. (dotimes (i (1+ dist))
  8215. (while (member day-of-week org-agenda-weekend-days)
  8216. (incf distance)
  8217. (incf day-of-week)
  8218. (if (= day-of-week 7)
  8219. (setq day-of-week 0)))
  8220. (incf day-of-week)
  8221. (if (= day-of-week 7)
  8222. (setq day-of-week 0)))))
  8223. ;; silently fail when try to replan a sexp entry
  8224. (condition-case nil
  8225. (let* ((date (calendar-gregorian-from-absolute
  8226. (+ (org-today) distance)))
  8227. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8228. (nth 2 date))))
  8229. (org-agenda-schedule nil time))
  8230. (error nil)))))))
  8231. ((assoc action org-agenda-bulk-custom-functions)
  8232. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8233. redo-at-end t))
  8234. ((equal action ?f)
  8235. (setq cmd (list (intern
  8236. (org-icompleting-read "Function: "
  8237. obarray 'fboundp t nil nil)))))
  8238. (t (error "Invalid bulk action")))
  8239. ;; Sort the markers, to make sure that parents are handled before children
  8240. (setq entries (sort entries
  8241. (lambda (a b)
  8242. (cond
  8243. ((equal (marker-buffer a) (marker-buffer b))
  8244. (< (marker-position a) (marker-position b)))
  8245. (t
  8246. (string< (buffer-name (marker-buffer a))
  8247. (buffer-name (marker-buffer b))))))))
  8248. ;; Now loop over all markers and apply cmd
  8249. (while (setq e (pop entries))
  8250. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8251. (if (not pos)
  8252. (progn (message "Skipping removed entry at %s" e)
  8253. (setq cntskip (1+ cntskip)))
  8254. (goto-char pos)
  8255. (let (org-loop-over-headlines-in-active-region)
  8256. (eval cmd))
  8257. (when (not org-agenda-persistent-marks)
  8258. (setq org-agenda-bulk-marked-entries
  8259. (delete e org-agenda-bulk-marked-entries)))
  8260. (setq cnt (1+ cnt))))
  8261. (when (not org-agenda-persistent-marks)
  8262. (org-agenda-bulk-remove-all-marks))
  8263. (when redo-at-end (org-agenda-redo))
  8264. (message "Acted on %d entries%s%s"
  8265. cnt
  8266. (if (= cntskip 0)
  8267. ""
  8268. (format ", skipped %d (disappeared before their turn)"
  8269. cntskip))
  8270. (if (not org-agenda-persistent-marks)
  8271. "" " (kept marked)"))))))
  8272. ;;; Flagging notes
  8273. (defun org-agenda-show-the-flagging-note ()
  8274. "Display the flagging note in the other window.
  8275. When called a second time in direct sequence, offer to remove the FLAGGING
  8276. tag and (if present) the flagging note."
  8277. (interactive)
  8278. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8279. (win (selected-window))
  8280. note heading newhead)
  8281. (unless hdmarker
  8282. (error "No linked entry at point"))
  8283. (if (and (eq this-command last-command)
  8284. (y-or-n-p "Unflag and remove any flagging note? "))
  8285. (progn
  8286. (org-agenda-remove-flag hdmarker)
  8287. (let ((win (get-buffer-window "*Flagging Note*")))
  8288. (and win (delete-window win)))
  8289. (message "Entry unflagged"))
  8290. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8291. (unless note
  8292. (error "No flagging note"))
  8293. (org-kill-new note)
  8294. (org-switch-to-buffer-other-window "*Flagging Note*")
  8295. (erase-buffer)
  8296. (insert note)
  8297. (goto-char (point-min))
  8298. (while (re-search-forward "\\\\n" nil t)
  8299. (replace-match "\n" t t))
  8300. (goto-char (point-min))
  8301. (select-window win)
  8302. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8303. (defun org-agenda-remove-flag (marker)
  8304. "Remove the FLAGGED tag and any flagging note in the entry."
  8305. (let (newhead)
  8306. (org-with-point-at marker
  8307. (org-toggle-tag "FLAGGED" 'off)
  8308. (org-entry-delete nil "THEFLAGGINGNOTE")
  8309. (setq newhead (org-get-heading)))
  8310. (org-agenda-change-all-lines newhead marker)
  8311. (message "Entry unflagged")))
  8312. (defun org-agenda-get-any-marker (&optional pos)
  8313. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8314. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8315. ;;; Appointment reminders
  8316. (defvar appt-time-msg-list)
  8317. ;;;###autoload
  8318. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8319. "Activate appointments found in `org-agenda-files'.
  8320. With a \\[universal-argument] prefix, refresh the list of
  8321. appointments.
  8322. If FILTER is t, interactively prompt the user for a regular
  8323. expression, and filter out entries that don't match it.
  8324. If FILTER is a string, use this string as a regular expression
  8325. for filtering entries out.
  8326. If FILTER is a function, filter out entries against which
  8327. calling the function returns nil. This function takes one
  8328. argument: an entry from `org-agenda-get-day-entries'.
  8329. FILTER can also be an alist with the car of each cell being
  8330. either 'headline or 'category. For example:
  8331. '((headline \"IMPORTANT\")
  8332. (category \"Work\"))
  8333. will only add headlines containing IMPORTANT or headlines
  8334. belonging to the \"Work\" category.
  8335. ARGS are symbols indicating what kind of entries to consider.
  8336. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8337. and :timestamp entries. See the docstring of `org-diary' for
  8338. details and examples."
  8339. (interactive "P")
  8340. (if refresh (setq appt-time-msg-list nil))
  8341. (if (eq filter t)
  8342. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8343. (let* ((cnt 0) ; count added events
  8344. (scope (or args '(:deadline :scheduled :timestamp)))
  8345. (org-agenda-new-buffers nil)
  8346. (org-deadline-warning-days 0)
  8347. ;; Do not use `org-today' here because appt only takes
  8348. ;; time and without date as argument, so it may pass wrong
  8349. ;; information otherwise
  8350. (today (org-date-to-gregorian
  8351. (time-to-days (current-time))))
  8352. (org-agenda-restrict nil)
  8353. (files (org-agenda-files 'unrestricted)) entries file
  8354. (org-agenda-buffer nil))
  8355. ;; Get all entries which may contain an appt
  8356. (org-prepare-agenda-buffers files)
  8357. (while (setq file (pop files))
  8358. (setq entries
  8359. (delq nil
  8360. (append entries
  8361. (apply 'org-agenda-get-day-entries
  8362. file today scope)))))
  8363. ;; Map thru entries and find if we should filter them out
  8364. (mapc
  8365. (lambda(x)
  8366. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8367. (cat (get-text-property 1 'org-category x))
  8368. (tod (get-text-property 1 'time-of-day x))
  8369. (ok (or (null filter)
  8370. (and (stringp filter) (string-match filter evt))
  8371. (and (functionp filter) (funcall filter x))
  8372. (and (listp filter)
  8373. (let ((cat-filter (cadr (assoc 'category filter)))
  8374. (evt-filter (cadr (assoc 'headline filter))))
  8375. (or (and (stringp cat-filter)
  8376. (string-match cat-filter cat))
  8377. (and (stringp evt-filter)
  8378. (string-match evt-filter evt))))))))
  8379. ;; FIXME: Shall we remove text-properties for the appt text?
  8380. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8381. (when (and ok tod)
  8382. (setq tod (concat "00" (number-to-string tod))
  8383. tod (when (string-match
  8384. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8385. (concat (match-string 1 tod) ":"
  8386. (match-string 2 tod))))
  8387. (appt-add tod evt)
  8388. (setq cnt (1+ cnt))))) entries)
  8389. (org-release-buffers org-agenda-new-buffers)
  8390. (if (eq cnt 0)
  8391. (message "No event to add")
  8392. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8393. (defun org-agenda-todayp (date)
  8394. "Does DATE mean today, when considering `org-extend-today-until'?"
  8395. (let ((today (org-today))
  8396. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8397. date)))
  8398. (eq date today)))
  8399. (defun org-agenda-todo-yesterday (&optional arg)
  8400. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8401. (interactive "P")
  8402. (let* ((hour (third (decode-time
  8403. (org-current-time))))
  8404. (org-extend-today-until (1+ hour)))
  8405. (org-agenda-todo arg)))
  8406. (provide 'org-agenda)
  8407. ;;; org-agenda.el ends here