org-agenda.el 343 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953
  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-deadline-if-done nil
  695. "Non-nil means don't show deadlines when the corresponding item is done.
  696. When nil, the deadline is still shown and should give you a happy feeling.
  697. This is relevant for the daily/weekly agenda. And it applied only to the
  698. actually date of the deadline. Warnings about approaching and past-due
  699. deadlines are always turned off when the item is DONE."
  700. :group 'org-agenda-skip
  701. :group 'org-agenda-daily/weekly
  702. :type 'boolean)
  703. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  704. "Non-nil means skip deadline prewarning when entry is also scheduled.
  705. This will apply on all days where a prewarning for the deadline would
  706. be shown, but not at the day when the entry is actually due. On that day,
  707. the deadline will be shown anyway.
  708. This variable may be set to nil, t, or a number which will then give
  709. the number of days before the actual deadline when the prewarnings
  710. should resume.
  711. This can be used in a workflow where the first showing of the deadline will
  712. trigger you to schedule it, and then you don't want to be reminded of it
  713. because you will take care of it on the day when scheduled."
  714. :group 'org-agenda-skip
  715. :group 'org-agenda-daily/weekly
  716. :version "24.1"
  717. :type '(choice
  718. (const :tag "Alwas show prewarning" nil)
  719. (const :tag "Remove prewarning if entry is scheduled" t)
  720. (integer :tag "Restart prewarning N days before deadline")))
  721. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  722. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  723. When non-nil, after the search for timestamps has matched once in an
  724. entry, the rest of the entry will not be searched."
  725. :group 'org-agenda-skip
  726. :type 'boolean)
  727. (defcustom org-agenda-skip-timestamp-if-done nil
  728. "Non-nil means don't select item by timestamp or -range if it is DONE."
  729. :group 'org-agenda-skip
  730. :group 'org-agenda-daily/weekly
  731. :type 'boolean)
  732. (defcustom org-agenda-dim-blocked-tasks t
  733. "Non-nil means dim blocked tasks in the agenda display.
  734. This causes some overhead during agenda construction, but if you
  735. have turned on `org-enforce-todo-dependencies',
  736. `org-enforce-todo-checkbox-dependencies', or any other blocking
  737. mechanism, this will create useful feedback in the agenda.
  738. Instead of t, this variable can also have the value `invisible'.
  739. Then blocked tasks will be invisible and only become visible when
  740. they become unblocked. An exemption to this behavior is when a task is
  741. blocked because of unchecked checkboxes below it. Since checkboxes do
  742. not show up in the agenda views, making this task invisible you remove any
  743. trace from agenda views that there is something to do. Therefore, a task
  744. that is blocked because of checkboxes will never be made invisible, it
  745. will only be dimmed."
  746. :group 'org-agenda-daily/weekly
  747. :group 'org-agenda-todo-list
  748. :type '(choice
  749. (const :tag "Do not dim" nil)
  750. (const :tag "Dim to a gray face" t)
  751. (const :tag "Make invisible" invisible)))
  752. (defcustom org-timeline-show-empty-dates 3
  753. "Non-nil means `org-timeline' also shows dates without an entry.
  754. When nil, only the days which actually have entries are shown.
  755. When t, all days between the first and the last date are shown.
  756. When an integer, show also empty dates, but if there is a gap of more than
  757. N days, just insert a special line indicating the size of the gap."
  758. :group 'org-agenda-skip
  759. :type '(choice
  760. (const :tag "None" nil)
  761. (const :tag "All" t)
  762. (integer :tag "at most")))
  763. (defgroup org-agenda-startup nil
  764. "Options concerning initial settings in the Agenda in Org Mode."
  765. :tag "Org Agenda Startup"
  766. :group 'org-agenda)
  767. (defcustom org-agenda-menu-show-matcher t
  768. "Non-nil means show the match string in the agenda dispatcher menu.
  769. When nil, the matcher string is not shown, but is put into the help-echo
  770. property so than moving the mouse over the command shows it.
  771. Setting it to nil is good if matcher strings are very long and/or if
  772. you want to use two-column display (see `org-agenda-menu-two-column')."
  773. :group 'org-agenda
  774. :version "24.1"
  775. :type 'boolean)
  776. (defcustom org-agenda-menu-two-column nil
  777. "Non-nil means, use two columns to show custom commands in the dispatcher.
  778. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  779. to nil."
  780. :group 'org-agenda
  781. :version "24.1"
  782. :type 'boolean)
  783. (defcustom org-finalize-agenda-hook nil
  784. "Hook run just before displaying an agenda buffer."
  785. :group 'org-agenda-startup
  786. :type 'hook)
  787. (defcustom org-agenda-mouse-1-follows-link nil
  788. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  789. A longer mouse click will still set point. Does not work on XEmacs.
  790. Needs to be set before org.el is loaded."
  791. :group 'org-agenda-startup
  792. :type 'boolean)
  793. (defcustom org-agenda-start-with-follow-mode nil
  794. "The initial value of follow mode in a newly created agenda window."
  795. :group 'org-agenda-startup
  796. :type 'boolean)
  797. (defcustom org-agenda-follow-indirect nil
  798. "Non-nil means `org-agenda-follow-mode' displays only the
  799. current item's tree, in an indirect buffer."
  800. :group 'org-agenda
  801. :version "24.1"
  802. :type 'boolean)
  803. (defcustom org-agenda-show-outline-path t
  804. "Non-nil means show outline path in echo area after line motion."
  805. :group 'org-agenda-startup
  806. :type 'boolean)
  807. (defcustom org-agenda-start-with-entry-text-mode nil
  808. "The initial value of entry-text-mode in a newly created agenda window."
  809. :group 'org-agenda-startup
  810. :type 'boolean)
  811. (defcustom org-agenda-entry-text-maxlines 5
  812. "Number of text lines to be added when `E' is pressed in the agenda.
  813. Note that this variable only used during agenda display. Add add entry text
  814. when exporting the agenda, configure the variable
  815. `org-agenda-add-entry-ext-maxlines'."
  816. :group 'org-agenda
  817. :type 'integer)
  818. (defcustom org-agenda-entry-text-exclude-regexps nil
  819. "List of regular expressions to clean up entry text.
  820. The complete matches of all regular expressions in this list will be
  821. removed from entry text before it is shown in the agenda."
  822. :group 'org-agenda
  823. :type '(repeat (regexp)))
  824. (defvar org-agenda-entry-text-cleanup-hook nil
  825. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  826. This cleanup is done in a temporary buffer, so the function may inspect and
  827. change the entire buffer.
  828. Some default stuff like drawers and scheduling/deadline dates will already
  829. have been removed when this is called, as will any matches for regular
  830. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  831. (defvar org-agenda-include-inactive-timestamps nil
  832. "Non-nil means include inactive time stamps in agenda and timeline.
  833. Dynamically scoped.")
  834. (defgroup org-agenda-windows nil
  835. "Options concerning the windows used by the Agenda in Org Mode."
  836. :tag "Org Agenda Windows"
  837. :group 'org-agenda)
  838. (defcustom org-agenda-window-setup 'reorganize-frame
  839. "How the agenda buffer should be displayed.
  840. Possible values for this option are:
  841. current-window Show agenda in the current window, keeping all other windows.
  842. other-window Use `switch-to-buffer-other-window' to display agenda.
  843. reorganize-frame Show only two windows on the current frame, the current
  844. window and the agenda.
  845. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  846. Also, when exiting the agenda, kill that frame.
  847. See also the variable `org-agenda-restore-windows-after-quit'."
  848. :group 'org-agenda-windows
  849. :type '(choice
  850. (const current-window)
  851. (const other-frame)
  852. (const other-window)
  853. (const reorganize-frame)))
  854. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  855. "The min and max height of the agenda window as a fraction of frame height.
  856. The value of the variable is a cons cell with two numbers between 0 and 1.
  857. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  858. :group 'org-agenda-windows
  859. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  860. (defcustom org-agenda-restore-windows-after-quit nil
  861. "Non-nil means restore window configuration upon exiting agenda.
  862. Before the window configuration is changed for displaying the agenda,
  863. the current status is recorded. When the agenda is exited with
  864. `q' or `x' and this option is set, the old state is restored. If
  865. `org-agenda-window-setup' is `other-frame', the value of this
  866. option will be ignored."
  867. :group 'org-agenda-windows
  868. :type 'boolean)
  869. (defcustom org-agenda-ndays nil
  870. "Number of days to include in overview display.
  871. Should be 1 or 7.
  872. Obsolete, see `org-agenda-span'."
  873. :group 'org-agenda-daily/weekly
  874. :type 'integer)
  875. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  876. (defcustom org-agenda-span 'week
  877. "Number of days to include in overview display.
  878. Can be day, week, month, year, or any number of days.
  879. Custom commands can set this variable in the options section."
  880. :group 'org-agenda-daily/weekly
  881. :type '(choice (const :tag "Day" day)
  882. (const :tag "Week" week)
  883. (const :tag "Month" month)
  884. (const :tag "Year" year)
  885. (integer :tag "Custom")))
  886. (defcustom org-agenda-start-on-weekday 1
  887. "Non-nil means start the overview always on the specified weekday.
  888. 0 denotes Sunday, 1 denotes Monday etc.
  889. When nil, always start on the current day.
  890. Custom commands can set this variable in the options section."
  891. :group 'org-agenda-daily/weekly
  892. :type '(choice (const :tag "Today" nil)
  893. (integer :tag "Weekday No.")))
  894. (defcustom org-agenda-show-all-dates t
  895. "Non-nil means `org-agenda' shows every day in the selected range.
  896. When nil, only the days which actually have entries are shown."
  897. :group 'org-agenda-daily/weekly
  898. :type 'boolean)
  899. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  900. "Format string for displaying dates in the agenda.
  901. Used by the daily/weekly agenda and by the timeline. This should be
  902. a format string understood by `format-time-string', or a function returning
  903. the formatted date as a string. The function must take a single argument,
  904. a calendar-style date list like (month day year)."
  905. :group 'org-agenda-daily/weekly
  906. :type '(choice
  907. (string :tag "Format string")
  908. (function :tag "Function")))
  909. (defun org-agenda-format-date-aligned (date)
  910. "Format a date string for display in the daily/weekly agenda, or timeline.
  911. This function makes sure that dates are aligned for easy reading."
  912. (require 'cal-iso)
  913. (let* ((dayname (calendar-day-name date))
  914. (day (cadr date))
  915. (day-of-week (calendar-day-of-week date))
  916. (month (car date))
  917. (monthname (calendar-month-name month))
  918. (year (nth 2 date))
  919. (iso-week (org-days-to-iso-week
  920. (calendar-absolute-from-gregorian date)))
  921. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  922. (1- year))
  923. ((and (= month 12) (<= iso-week 1))
  924. (1+ year))
  925. (t year)))
  926. (weekstring (if (= day-of-week 1)
  927. (format " W%02d" iso-week)
  928. "")))
  929. (format "%-10s %2d %s %4d%s"
  930. dayname day monthname year weekstring)))
  931. (defcustom org-agenda-time-leading-zero nil
  932. "Non-nil means use leading zero for military times in agenda.
  933. For example, 9:30am would become 09:30 rather than 9:30."
  934. :group 'org-agenda-daily/weekly
  935. :version "24.1"
  936. :type 'boolean)
  937. (defcustom org-agenda-timegrid-use-ampm nil
  938. "When set, show AM/PM style timestamps on the timegrid."
  939. :group 'org-agenda
  940. :version "24.1"
  941. :type 'boolean)
  942. (defun org-agenda-time-of-day-to-ampm (time)
  943. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  944. (let* ((hour-number (string-to-number (substring time 0 -3)))
  945. (minute (substring time -2))
  946. (ampm "am"))
  947. (cond
  948. ((equal hour-number 12)
  949. (setq ampm "pm"))
  950. ((> hour-number 12)
  951. (setq ampm "pm")
  952. (setq hour-number (- hour-number 12))))
  953. (concat
  954. (if org-agenda-time-leading-zero
  955. (format "%02d" hour-number)
  956. (format "%02s" (number-to-string hour-number)))
  957. ":" minute ampm)))
  958. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  959. "Conditionally convert TIME to AM/PM format
  960. based on `org-agenda-timegrid-use-ampm'"
  961. (if org-agenda-timegrid-use-ampm
  962. (org-agenda-time-of-day-to-ampm time)
  963. time))
  964. (defcustom org-agenda-weekend-days '(6 0)
  965. "Which days are weekend?
  966. These days get the special face `org-agenda-date-weekend' in the agenda
  967. and timeline buffers."
  968. :group 'org-agenda-daily/weekly
  969. :type '(set :greedy t
  970. (const :tag "Monday" 1)
  971. (const :tag "Tuesday" 2)
  972. (const :tag "Wednesday" 3)
  973. (const :tag "Thursday" 4)
  974. (const :tag "Friday" 5)
  975. (const :tag "Saturday" 6)
  976. (const :tag "Sunday" 0)))
  977. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  978. "Non-nil means jump to today when moving a past date forward in time.
  979. When using S-right in the agenda to move a a date forward, and the date
  980. stamp currently points to the past, the first key press will move it
  981. to today. WHen nil, just move one day forward even if the date stays
  982. in the past."
  983. :group 'org-agenda-daily/weekly
  984. :version "24.1"
  985. :type 'boolean)
  986. (defcustom org-agenda-include-diary nil
  987. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  988. Custom commands can set this variable in the options section."
  989. :group 'org-agenda-daily/weekly
  990. :type 'boolean)
  991. (defcustom org-agenda-include-deadlines t
  992. "If non-nil, include entries within their deadline warning period.
  993. Custom commands can set this variable in the options section."
  994. :group 'org-agenda-daily/weekly
  995. :version "24.1"
  996. :type 'boolean)
  997. (defcustom org-agenda-repeating-timestamp-show-all t
  998. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  999. When set to a list of strings, only show occurrences of repeating
  1000. stamps for these TODO keywords. When nil, only one occurrence is
  1001. shown, either today or the nearest into the future."
  1002. :group 'org-agenda-daily/weekly
  1003. :type '(choice
  1004. (const :tag "Show repeating stamps" t)
  1005. (repeat :tag "Show repeating stamps for these TODO keywords"
  1006. (string :tag "TODO Keyword"))
  1007. (const :tag "Don't show repeating stamps" nil)))
  1008. (defcustom org-scheduled-past-days 10000
  1009. "No. of days to continue listing scheduled items that are not marked DONE.
  1010. When an item is scheduled on a date, it shows up in the agenda on this
  1011. day and will be listed until it is marked done for the number of days
  1012. given here."
  1013. :group 'org-agenda-daily/weekly
  1014. :type 'integer)
  1015. (defcustom org-agenda-log-mode-items '(closed clock)
  1016. "List of items that should be shown in agenda log mode.
  1017. This list may contain the following symbols:
  1018. closed Show entries that have been closed on that day.
  1019. clock Show entries that have received clocked time on that day.
  1020. state Show all logged state changes.
  1021. Note that instead of changing this variable, you can also press `C-u l' in
  1022. the agenda to display all available LOG items temporarily."
  1023. :group 'org-agenda-daily/weekly
  1024. :type '(set :greedy t (const closed) (const clock) (const state)))
  1025. (defcustom org-agenda-clock-consistency-checks
  1026. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1027. :gap-ok-around ("4:00")
  1028. :default-face ((:background "DarkRed") (:foreground "white"))
  1029. :overlap-face nil :gap-face nil :no-end-time-face nil
  1030. :long-face nil :short-face nil)
  1031. "This is a property list, with the following keys:
  1032. :max-duration Mark clocking chunks that are longer than this time.
  1033. This is a time string like \"HH:MM\", or the number
  1034. of minutes as an integer.
  1035. :min-duration Mark clocking chunks that are shorter that this.
  1036. This is a time string like \"HH:MM\", or the number
  1037. of minutes as an integer.
  1038. :max-gap Mark gaps between clocking chunks that are longer than
  1039. this duration. A number of minutes, or a string
  1040. like \"HH:MM\".
  1041. :gap-ok-around List of times during the day which are usually not working
  1042. times. When a gap is detected, but the gap contains any
  1043. of these times, the gap is *not* reported. For example,
  1044. if this is (\"4:00\" \"13:00\") then gaps that contain
  1045. 4:00 in the morning (i.e. the night) and 13:00
  1046. (i.e. a typical lunch time) do not cause a warning.
  1047. You should have at least one time during the night in this
  1048. list, or otherwise the first task each morning will trigger
  1049. a warning because it follows a long gap.
  1050. Furthermore, the following properties can be used to define faces for
  1051. issue display.
  1052. :default-face the default face, if the specific face is undefined
  1053. :overlap-face face for overlapping clocks
  1054. :gap-face face for gaps between clocks
  1055. :no-end-time-face face for incomplete clocks
  1056. :long-face face for clock intervals that are too long
  1057. :short-face face for clock intervals that are too short"
  1058. :group 'org-agenda-daily/weekly
  1059. :group 'org-clock
  1060. :version "24.1"
  1061. :type 'plist)
  1062. (defcustom org-agenda-log-mode-add-notes t
  1063. "Non-nil means add first line of notes to log entries in agenda views.
  1064. If a log item like a state change or a clock entry is associated with
  1065. notes, the first line of these notes will be added to the entry in the
  1066. agenda display."
  1067. :group 'org-agenda-daily/weekly
  1068. :type 'boolean)
  1069. (defcustom org-agenda-start-with-log-mode nil
  1070. "The initial value of log-mode in a newly created agenda window."
  1071. :group 'org-agenda-startup
  1072. :group 'org-agenda-daily/weekly
  1073. :type 'boolean)
  1074. (defcustom org-agenda-start-with-clockreport-mode nil
  1075. "The initial value of clockreport-mode in a newly created agenda window."
  1076. :group 'org-agenda-startup
  1077. :group 'org-agenda-daily/weekly
  1078. :type 'boolean)
  1079. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1080. "Property list with parameters for the clocktable in clockreport mode.
  1081. This is the display mode that shows a clock table in the daily/weekly
  1082. agenda, the properties for this dynamic block can be set here.
  1083. The usual clocktable parameters are allowed here, but you cannot set
  1084. the properties :name, :tstart, :tend, :block, and :scope - these will
  1085. be overwritten to make sure the content accurately reflects the
  1086. current display in the agenda."
  1087. :group 'org-agenda-daily/weekly
  1088. :type 'plist)
  1089. (defcustom org-agenda-search-view-always-boolean nil
  1090. "Non-nil means the search string is interpreted as individual parts.
  1091. The search string for search view can either be interpreted as a phrase,
  1092. or as a list of snippets that define a boolean search for a number of
  1093. strings.
  1094. When this is non-nil, the string will be split on whitespace, and each
  1095. snippet will be searched individually, and all must match in order to
  1096. select an entry. A snippet is then a single string of non-white
  1097. characters, or a string in double quotes, or a regexp in {} braces.
  1098. If a snippet is preceded by \"-\", the snippet must *not* match.
  1099. \"+\" is syntactic sugar for positive selection. Each snippet may
  1100. be found as a full word or a partial word, but see the variable
  1101. `org-agenda-search-view-force-full-words'.
  1102. When this is nil, search will look for the entire search phrase as one,
  1103. with each space character matching any amount of whitespace, including
  1104. line breaks.
  1105. Even when this is nil, you can still switch to Boolean search dynamically
  1106. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1107. is a regexp marked with braces like \"{abc}\", this will also switch to
  1108. boolean search."
  1109. :group 'org-agenda-search-view
  1110. :version "24.1"
  1111. :type 'boolean)
  1112. (if (fboundp 'defvaralias)
  1113. (defvaralias 'org-agenda-search-view-search-words-only
  1114. 'org-agenda-search-view-always-boolean))
  1115. (defcustom org-agenda-search-view-force-full-words nil
  1116. "Non-nil means, search words must be matches as complete words.
  1117. When nil, they may also match part of a word."
  1118. :group 'org-agenda-search-view
  1119. :version "24.1"
  1120. :type 'boolean)
  1121. (defgroup org-agenda-time-grid nil
  1122. "Options concerning the time grid in the Org-mode Agenda."
  1123. :tag "Org Agenda Time Grid"
  1124. :group 'org-agenda)
  1125. (defcustom org-agenda-search-headline-for-time t
  1126. "Non-nil means search headline for a time-of-day.
  1127. If the headline contains a time-of-day in one format or another, it will
  1128. be used to sort the entry into the time sequence of items for a day.
  1129. Some people have time stamps in the headline that refer to the creation
  1130. time or so, and then this produces an unwanted side effect. If this is
  1131. the case for your, use this variable to turn off searching the headline
  1132. for a time."
  1133. :group 'org-agenda-time-grid
  1134. :type 'boolean)
  1135. (defcustom org-agenda-use-time-grid t
  1136. "Non-nil means show a time grid in the agenda schedule.
  1137. A time grid is a set of lines for specific times (like every two hours between
  1138. 8:00 and 20:00). The items scheduled for a day at specific times are
  1139. sorted in between these lines.
  1140. For details about when the grid will be shown, and what it will look like, see
  1141. the variable `org-agenda-time-grid'."
  1142. :group 'org-agenda-time-grid
  1143. :type 'boolean)
  1144. (defcustom org-agenda-time-grid
  1145. '((daily today require-timed)
  1146. "----------------"
  1147. (800 1000 1200 1400 1600 1800 2000))
  1148. "The settings for time grid for agenda display.
  1149. This is a list of three items. The first item is again a list. It contains
  1150. symbols specifying conditions when the grid should be displayed:
  1151. daily if the agenda shows a single day
  1152. weekly if the agenda shows an entire week
  1153. today show grid on current date, independent of daily/weekly display
  1154. require-timed show grid only if at least one item has a time specification
  1155. The second item is a string which will be placed behind the grid time.
  1156. The third item is a list of integers, indicating the times that should have
  1157. a grid line."
  1158. :group 'org-agenda-time-grid
  1159. :type
  1160. '(list
  1161. (set :greedy t :tag "Grid Display Options"
  1162. (const :tag "Show grid in single day agenda display" daily)
  1163. (const :tag "Show grid in weekly agenda display" weekly)
  1164. (const :tag "Always show grid for today" today)
  1165. (const :tag "Show grid only if any timed entries are present"
  1166. require-timed)
  1167. (const :tag "Skip grid times already present in an entry"
  1168. remove-match))
  1169. (string :tag "Grid String")
  1170. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1171. (defcustom org-agenda-show-current-time-in-grid t
  1172. "Non-nil means show the current time in the time grid."
  1173. :group 'org-agenda-time-grid
  1174. :version "24.1"
  1175. :type 'boolean)
  1176. (defcustom org-agenda-current-time-string
  1177. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1178. "The string for the current time marker in the agenda."
  1179. :group 'org-agenda-time-grid
  1180. :version "24.1"
  1181. :type 'string)
  1182. (defgroup org-agenda-sorting nil
  1183. "Options concerning sorting in the Org-mode Agenda."
  1184. :tag "Org Agenda Sorting"
  1185. :group 'org-agenda)
  1186. (defcustom org-agenda-sorting-strategy
  1187. '((agenda habit-down time-up priority-down category-keep)
  1188. (todo priority-down category-keep)
  1189. (tags priority-down category-keep)
  1190. (search category-keep))
  1191. "Sorting structure for the agenda items of a single day.
  1192. This is a list of symbols which will be used in sequence to determine
  1193. if an entry should be listed before another entry. The following
  1194. symbols are recognized:
  1195. time-up Put entries with time-of-day indications first, early first
  1196. time-down Put entries with time-of-day indications first, late first
  1197. category-keep Keep the default order of categories, corresponding to the
  1198. sequence in `org-agenda-files'.
  1199. category-up Sort alphabetically by category, A-Z.
  1200. category-down Sort alphabetically by category, Z-A.
  1201. tag-up Sort alphabetically by last tag, A-Z.
  1202. tag-down Sort alphabetically by last tag, Z-A.
  1203. priority-up Sort numerically by priority, high priority last.
  1204. priority-down Sort numerically by priority, high priority first.
  1205. todo-state-up Sort by todo state, tasks that are done last.
  1206. todo-state-down Sort by todo state, tasks that are done first.
  1207. effort-up Sort numerically by estimated effort, high effort last.
  1208. effort-down Sort numerically by estimated effort, high effort first.
  1209. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1210. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1211. habit-up Put entries that are habits first
  1212. habit-down Put entries that are habits last
  1213. alpha-up Sort headlines alphabetically
  1214. alpha-down Sort headlines alphabetically, reversed
  1215. The different possibilities will be tried in sequence, and testing stops
  1216. if one comparison returns a \"not-equal\". For example, the default
  1217. '(time-up category-keep priority-down)
  1218. means: Pull out all entries having a specified time of day and sort them,
  1219. in order to make a time schedule for the current day the first thing in the
  1220. agenda listing for the day. Of the entries without a time indication, keep
  1221. the grouped in categories, don't sort the categories, but keep them in
  1222. the sequence given in `org-agenda-files'. Within each category sort by
  1223. priority.
  1224. Leaving out `category-keep' would mean that items will be sorted across
  1225. categories by priority.
  1226. Instead of a single list, this can also be a set of list for specific
  1227. contents, with a context symbol in the car of the list, any of
  1228. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1229. Custom commands can bind this variable in the options section."
  1230. :group 'org-agenda-sorting
  1231. :type `(choice
  1232. (repeat :tag "General" ,org-sorting-choice)
  1233. (list :tag "Individually"
  1234. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1235. (repeat ,org-sorting-choice))
  1236. (cons (const :tag "Strategy for TODO lists" todo)
  1237. (repeat ,org-sorting-choice))
  1238. (cons (const :tag "Strategy for Tags matches" tags)
  1239. (repeat ,org-sorting-choice))
  1240. (cons (const :tag "Strategy for search matches" search)
  1241. (repeat ,org-sorting-choice)))))
  1242. (defcustom org-agenda-cmp-user-defined nil
  1243. "A function to define the comparison `user-defined'.
  1244. This function must receive two arguments, agenda entry a and b.
  1245. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1246. the user comparison, return nil.
  1247. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1248. part of an agenda sorting strategy."
  1249. :group 'org-agenda-sorting
  1250. :type 'symbol)
  1251. (defcustom org-sort-agenda-notime-is-late t
  1252. "Non-nil means items without time are considered late.
  1253. This is only relevant for sorting. When t, items which have no explicit
  1254. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1255. do have a time. When nil, the default time is before 0:00. You can use this
  1256. option to decide if the schedule for today should come before or after timeless
  1257. agenda entries."
  1258. :group 'org-agenda-sorting
  1259. :type 'boolean)
  1260. (defcustom org-sort-agenda-noeffort-is-high t
  1261. "Non-nil means items without effort estimate are sorted as high effort.
  1262. This also applies when filtering an agenda view with respect to the
  1263. < or > effort operator. Then, tasks with no effort defined will be treated
  1264. as tasks with high effort.
  1265. When nil, such items are sorted as 0 minutes effort."
  1266. :group 'org-agenda-sorting
  1267. :type 'boolean)
  1268. (defgroup org-agenda-line-format nil
  1269. "Options concerning the entry prefix in the Org-mode agenda display."
  1270. :tag "Org Agenda Line Format"
  1271. :group 'org-agenda)
  1272. (defcustom org-agenda-prefix-format
  1273. '((agenda . " %i %-12:c%?-12t% s")
  1274. (timeline . " % s")
  1275. (todo . " %i %-12:c")
  1276. (tags . " %i %-12:c")
  1277. (search . " %i %-12:c"))
  1278. "Format specifications for the prefix of items in the agenda views.
  1279. An alist with five entries, each for the different agenda types. The
  1280. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1281. The values are format strings.
  1282. This format works similar to a printf format, with the following meaning:
  1283. %c the category of the item, \"Diary\" for entries from the diary,
  1284. or as given by the CATEGORY keyword or derived from the file name
  1285. %e the effort required by the item
  1286. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1287. %T the last tag of the item (ignore inherited tags, which come first)
  1288. %t the HH:MM time-of-day specification if one applies to the entry
  1289. %s Scheduling/Deadline information, a short string
  1290. %(expression) Eval EXPRESSION and replace the control string
  1291. by the result
  1292. All specifiers work basically like the standard `%s' of printf, but may
  1293. contain two additional characters: a question mark just after the `%'
  1294. and a whitespace/punctuation character just before the final letter.
  1295. If the first character after `%' is a question mark, the entire field
  1296. will only be included if the corresponding value applies to the current
  1297. entry. This is useful for fields which should have fixed width when
  1298. present, but zero width when absent. For example, \"%?-12t\" will
  1299. result in a 12 character time field if a time of the day is specified,
  1300. but will completely disappear in entries which do not contain a time.
  1301. If there is punctuation or whitespace character just before the final
  1302. format letter, this character will be appended to the field value if
  1303. the value is not empty. For example, the format \"%-12:c\" leads to
  1304. \"Diary: \" if the category is \"Diary\". If the category were be
  1305. empty, no additional colon would be inserted.
  1306. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1307. which means:
  1308. - Indent the line with two space characters
  1309. - Give the category a 12 chars wide field, padded with whitespace on
  1310. the right (because of `-'). Append a colon if there is a category
  1311. (because of `:').
  1312. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1313. time, don't put in an empty field, just skip it (because of '?').
  1314. - Finally, put the scheduling information.
  1315. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1316. `org-agenda-remove-tags'.
  1317. Custom commands can set this variable in the options section."
  1318. :type '(choice
  1319. (string :tag "General format")
  1320. (list :greedy t :tag "View dependent"
  1321. (cons (const agenda) (string :tag "Format"))
  1322. (cons (const timeline) (string :tag "Format"))
  1323. (cons (const todo) (string :tag "Format"))
  1324. (cons (const tags) (string :tag "Format"))
  1325. (cons (const search) (string :tag "Format"))))
  1326. :group 'org-agenda-line-format)
  1327. (defvar org-prefix-format-compiled nil
  1328. "The compiled prefix format and associated variables.
  1329. This is a list where first element is a list of variable bindings, and second
  1330. element is the compiled format expression. See the variable
  1331. `org-agenda-prefix-format'.")
  1332. (defcustom org-agenda-todo-keyword-format "%-1s"
  1333. "Format for the TODO keyword in agenda lines.
  1334. Set this to something like \"%-12s\" if you want all TODO keywords
  1335. to occupy a fixed space in the agenda display."
  1336. :group 'org-agenda-line-format
  1337. :type 'string)
  1338. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1339. "Text preceding timerange entries in the agenda view.
  1340. This is a list with two strings. The first applies when the range
  1341. is entirely on one day. The second applies if the range spans several days.
  1342. The strings may have two \"%d\" format specifiers which will be filled
  1343. with the sequence number of the days, and the total number of days in the
  1344. range, respectively."
  1345. :group 'org-agenda-line-format
  1346. :type '(list
  1347. (string :tag "Deadline today ")
  1348. (choice :tag "Deadline relative"
  1349. (string :tag "Format string")
  1350. (function))))
  1351. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1352. "Text preceding scheduled items in the agenda view.
  1353. This is a list with two strings. The first applies when the item is
  1354. scheduled on the current day. The second applies when it has been scheduled
  1355. previously, it may contain a %d indicating that this is the nth time that
  1356. this item is scheduled, due to automatic rescheduling of unfinished items
  1357. for the following day. So this number is one larger than the number of days
  1358. that passed since this item was scheduled first."
  1359. :group 'org-agenda-line-format
  1360. :type '(list
  1361. (string :tag "Scheduled today ")
  1362. (string :tag "Scheduled previously")))
  1363. (defcustom org-agenda-inactive-leader "["
  1364. "Text preceding item pulled into the agenda by inactive time stamps.
  1365. These entries are added to the agenda when pressing \"[\"."
  1366. :group 'org-agenda-line-format
  1367. :version "24.1"
  1368. :type '(list
  1369. (string :tag "Scheduled today ")
  1370. (string :tag "Scheduled previously")))
  1371. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1372. "Text preceding deadline items in the agenda view.
  1373. This is a list with two strings. The first applies when the item has its
  1374. deadline on the current day. The second applies when it is in the past or
  1375. in the future, it may contain %d to capture how many days away the deadline
  1376. is (was)."
  1377. :group 'org-agenda-line-format
  1378. :type '(list
  1379. (string :tag "Deadline today ")
  1380. (choice :tag "Deadline relative"
  1381. (string :tag "Format string")
  1382. (function))))
  1383. (defcustom org-agenda-remove-times-when-in-prefix t
  1384. "Non-nil means remove duplicate time specifications in agenda items.
  1385. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1386. time-of-day specification in a headline or diary entry is extracted and
  1387. placed into the prefix. If this option is non-nil, the original specification
  1388. \(a timestamp or -range, or just a plain time(range) specification like
  1389. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1390. cluttered.
  1391. The option can be t or nil. It may also be the symbol `beg', indicating
  1392. that the time should only be removed when it is located at the beginning of
  1393. the headline/diary entry."
  1394. :group 'org-agenda-line-format
  1395. :type '(choice
  1396. (const :tag "Always" t)
  1397. (const :tag "Never" nil)
  1398. (const :tag "When at beginning of entry" beg)))
  1399. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1400. "Non-nil means remove time ranges specifications in agenda
  1401. items that span on several days."
  1402. :group 'org-agenda-line-format
  1403. :version "24.1"
  1404. :type 'boolean)
  1405. (defcustom org-agenda-default-appointment-duration nil
  1406. "Default duration for appointments that only have a starting time.
  1407. When nil, no duration is specified in such cases.
  1408. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1409. :group 'org-agenda-line-format
  1410. :type '(choice
  1411. (integer :tag "Minutes")
  1412. (const :tag "No default duration")))
  1413. (defcustom org-agenda-show-inherited-tags t
  1414. "Non-nil means show inherited tags in each agenda line."
  1415. :group 'org-agenda-line-format
  1416. :type 'boolean)
  1417. (defcustom org-agenda-hide-tags-regexp nil
  1418. "Regular expression used to filter away specific tags in agenda views.
  1419. This means that these tags will be present, but not be shown in the agenda
  1420. line. Secondary filtering will still work on the hidden tags.
  1421. Nil means don't hide any tags."
  1422. :group 'org-agenda-line-format
  1423. :type '(choice
  1424. (const :tag "Hide none" nil)
  1425. (string :tag "Regexp ")))
  1426. (defcustom org-agenda-remove-tags nil
  1427. "Non-nil means remove the tags from the headline copy in the agenda.
  1428. When this is the symbol `prefix', only remove tags when
  1429. `org-agenda-prefix-format' contains a `%T' specifier."
  1430. :group 'org-agenda-line-format
  1431. :type '(choice
  1432. (const :tag "Always" t)
  1433. (const :tag "Never" nil)
  1434. (const :tag "When prefix format contains %T" prefix)))
  1435. (if (fboundp 'defvaralias)
  1436. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1437. 'org-agenda-remove-tags))
  1438. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1439. "Shift tags in agenda items to this column.
  1440. If this number is positive, it specifies the column. If it is negative,
  1441. it means that the tags should be flushright to that column. For example,
  1442. -80 works well for a normal 80 character screen."
  1443. :group 'org-agenda-line-format
  1444. :type 'integer)
  1445. (if (fboundp 'defvaralias)
  1446. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1447. (defcustom org-agenda-fontify-priorities 'cookies
  1448. "Non-nil means highlight low and high priorities in agenda.
  1449. When t, the highest priority entries are bold, lowest priority italic.
  1450. However, settings in `org-priority-faces' will overrule these faces.
  1451. When this variable is the symbol `cookies', only fontify the
  1452. cookies, not the entire task.
  1453. This may also be an association list of priority faces, whose
  1454. keys are the character values of `org-highest-priority',
  1455. `org-default-priority', and `org-lowest-priority' (the default values
  1456. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1457. color as a string, or a list like `(:background \"Red\")'.
  1458. If it is a color, the variable `org-faces-easy-properties'
  1459. determines if it is a foreground or a background color."
  1460. :group 'org-agenda-line-format
  1461. :type '(choice
  1462. (const :tag "Never" nil)
  1463. (const :tag "Defaults" t)
  1464. (const :tag "Cookies only" cookies)
  1465. (repeat :tag "Specify"
  1466. (list (character :tag "Priority" :value ?A)
  1467. (choice :tag "Face "
  1468. (string :tag "Color")
  1469. (sexp :tag "Face"))))))
  1470. (defcustom org-agenda-day-face-function nil
  1471. "Function called to determine what face should be used to display a day.
  1472. The only argument passed to that function is the day. It should
  1473. returns a face, or nil if does not want to specify a face and let
  1474. the normal rules apply."
  1475. :group 'org-agenda-line-format
  1476. :version "24.1"
  1477. :type 'function)
  1478. (defcustom org-agenda-category-icon-alist nil
  1479. "Alist of category icon to be displayed in agenda views.
  1480. Each entry should have the following format:
  1481. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1482. Where CATEGORY-REGEXP is a regexp matching the categories where
  1483. the icon should be displayed.
  1484. FILE-OR-DATA either a file path or a string containing image data.
  1485. The other fields can be omitted safely if not needed:
  1486. TYPE indicates the image type.
  1487. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1488. image data.
  1489. PROPS are additional image attributes to assign to the image,
  1490. like, e.g. `:ascent center'.
  1491. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1492. If you want to set the display properties yourself, just put a
  1493. list as second element:
  1494. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1495. For example, to display a 16px horizontal space for Emacs
  1496. category, you can use:
  1497. (\"Emacs\" '(space . (:width (16))))"
  1498. :group 'org-agenda-line-format
  1499. :version "24.1"
  1500. :type '(alist :key-type (string :tag "Regexp matching category")
  1501. :value-type (choice (list :tag "Icon"
  1502. (string :tag "File or data")
  1503. (symbol :tag "Type")
  1504. (boolean :tag "Data?")
  1505. (repeat :tag "Extra image properties" :inline t symbol))
  1506. (list :tag "Display properties" sexp))))
  1507. (defgroup org-agenda-column-view nil
  1508. "Options concerning column view in the agenda."
  1509. :tag "Org Agenda Column View"
  1510. :group 'org-agenda)
  1511. (defcustom org-agenda-columns-show-summaries t
  1512. "Non-nil means show summaries for columns displayed in the agenda view."
  1513. :group 'org-agenda-column-view
  1514. :type 'boolean)
  1515. (defcustom org-agenda-columns-compute-summary-properties t
  1516. "Non-nil means recompute all summary properties before column view.
  1517. When column view in the agenda is listing properties that have a summary
  1518. operator, it can go to all relevant buffers and recompute the summaries
  1519. there. This can mean overhead for the agenda column view, but is necessary
  1520. to have thing up to date.
  1521. As a special case, a CLOCKSUM property also makes sure that the clock
  1522. computations are current."
  1523. :group 'org-agenda-column-view
  1524. :type 'boolean)
  1525. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1526. "Non-nil means the duration of an appointment will add to day effort.
  1527. The property to which appointment durations will be added is the one given
  1528. in the option `org-effort-property'. If an appointment does not have
  1529. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1530. is not set, an appointment without end time will not contribute to the time
  1531. estimate."
  1532. :group 'org-agenda-column-view
  1533. :type 'boolean)
  1534. (defcustom org-agenda-auto-exclude-function nil
  1535. "A function called with a tag to decide if it is filtered on '/ RET'.
  1536. The sole argument to the function, which is called once for each
  1537. possible tag, is a string giving the name of the tag. The
  1538. function should return either nil if the tag should be included
  1539. as normal, or \"-<TAG>\" to exclude the tag.
  1540. Note that for the purpose of tag filtering, only the lower-case version of
  1541. all tags will be considered, so that this function will only ever see
  1542. the lower-case version of all tags."
  1543. :group 'org-agenda
  1544. :type 'function)
  1545. (defcustom org-agenda-bulk-custom-functions nil
  1546. "Alist of characters and custom functions for bulk actions.
  1547. For example, this value makes those two functions available:
  1548. '((?R set-category)
  1549. (?C bulk-cut))
  1550. With selected entries in an agenda buffer, `B R' will call
  1551. the custom function `set-category' on the selected entries.
  1552. Note that functions in this alist don't need to be quoted."
  1553. :type 'alist
  1554. :version "24.1"
  1555. :group 'org-agenda)
  1556. (eval-when-compile
  1557. (require 'cl))
  1558. (require 'org)
  1559. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1560. "Execute BODY with point at location given by `org-hd-marker' property.
  1561. If STRING is non-nil, the text property will be fetched from position 0
  1562. in that string. If STRING is nil, it will be fetched from the beginning
  1563. of the current line."
  1564. (org-with-gensyms (marker)
  1565. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1566. 'org-hd-marker ,string)))
  1567. (with-current-buffer (marker-buffer ,marker)
  1568. (save-excursion
  1569. (goto-char ,marker)
  1570. ,@body)))))
  1571. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1572. (defun org-add-agenda-custom-command (entry)
  1573. "Replace or add a command in `org-agenda-custom-commands'.
  1574. This is mostly for hacking and trying a new command - once the command
  1575. works you probably want to add it to `org-agenda-custom-commands' for good."
  1576. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1577. (if ass
  1578. (setcdr ass (cdr entry))
  1579. (push entry org-agenda-custom-commands))))
  1580. ;;; Define the org-agenda-mode
  1581. (defvar org-agenda-mode-map (make-sparse-keymap)
  1582. "Keymap for `org-agenda-mode'.")
  1583. (if (fboundp 'defvaralias)
  1584. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1585. (defvar org-agenda-menu) ; defined later in this file.
  1586. (defvar org-agenda-restrict) ; defined later in this file.
  1587. (defvar org-agenda-follow-mode nil)
  1588. (defvar org-agenda-entry-text-mode nil)
  1589. (defvar org-agenda-clockreport-mode nil)
  1590. (defvar org-agenda-show-log nil)
  1591. (defvar org-agenda-redo-command nil)
  1592. (defvar org-agenda-query-string nil)
  1593. (defvar org-agenda-mode-hook nil
  1594. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1595. (defvar org-agenda-type nil)
  1596. (defvar org-agenda-force-single-file nil)
  1597. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1598. ;;; Multiple agenda buffers support
  1599. (defcustom org-agenda-sticky nil
  1600. "Non-nil means agenda q key will bury agenda buffers.
  1601. Agenda commands will then show existing buffer instead of generating new ones.
  1602. When nil, `q' will kill the single agenda buffer."
  1603. :group 'org-agenda
  1604. :type 'boolean
  1605. :set (lambda (var val)
  1606. (if (boundp var)
  1607. (org-toggle-sticky-agenda (if val 1 0))
  1608. (set var val))))
  1609. (defun org-toggle-sticky-agenda (&optional arg)
  1610. "Toggle `org-agenda-sticky'."
  1611. (interactive "P")
  1612. (let ((new-value (if arg
  1613. (> (prefix-numeric-value arg) 0)
  1614. (not org-agenda-sticky))))
  1615. (if (equal new-value org-agenda-sticky)
  1616. (message "Sticky agenda was already %s"
  1617. (if org-agenda-sticky "enabled" "disabled"))
  1618. (setq org-agenda-sticky new-value)
  1619. (org-agenda-kill-all-agenda-buffers)
  1620. (message "Sticky agenda was %s"
  1621. (if org-agenda-sticky "enabled" "disabled")))))
  1622. (defvar org-agenda-buffer nil
  1623. "Agenda buffer currently being generated.")
  1624. (defvar org-agenda-last-prefix-arg nil)
  1625. (defvar org-agenda-this-buffer-name nil)
  1626. (defvar org-agenda-doing-sticky-redo nil)
  1627. (defvar org-agenda-this-buffer-is-sticky nil)
  1628. (defconst org-agenda-local-vars
  1629. '(org-agenda-this-buffer-name
  1630. org-agenda-undo-list
  1631. org-agenda-pending-undo-list
  1632. org-agenda-follow-mode
  1633. org-agenda-entry-text-mode
  1634. org-agenda-clockreport-mode
  1635. org-agenda-show-log
  1636. org-agenda-redo-command
  1637. org-agenda-query-string
  1638. org-agenda-type
  1639. org-agenda-bulk-marked-entries
  1640. org-agenda-undo-has-started-in
  1641. org-agenda-last-arguments
  1642. org-agenda-info
  1643. org-agenda-tag-filter-overlays
  1644. org-agenda-cat-filter-overlays
  1645. org-pre-agenda-window-conf
  1646. org-agenda-columns-active
  1647. org-agenda-tag-filter
  1648. org-agenda-category-filter
  1649. org-agenda-markers
  1650. org-agenda-last-search-view-search-was-boolean
  1651. org-agenda-filtered-by-category
  1652. org-agenda-filter-form
  1653. org-agenda-show-window
  1654. org-agenda-cycle-counter
  1655. org-agenda-last-prefix-arg)
  1656. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1657. (defun org-agenda-mode ()
  1658. "Mode for time-sorted view on action items in Org-mode files.
  1659. The following commands are available:
  1660. \\{org-agenda-mode-map}"
  1661. (interactive)
  1662. (cond (org-agenda-doing-sticky-redo
  1663. ;; Refreshing sticky agenda-buffer
  1664. ;;
  1665. ;; Preserve the value of `org-agenda-local-vars' variables,
  1666. ;; while letting `kill-all-local-variables' kill the rest
  1667. (let ((save (buffer-local-variables)))
  1668. (kill-all-local-variables)
  1669. (mapc 'make-local-variable org-agenda-local-vars)
  1670. (dolist (elem save)
  1671. (let ((var (car elem))
  1672. (val (cdr elem)))
  1673. (when (and val
  1674. (member var org-agenda-local-vars))
  1675. (set var val)))))
  1676. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1677. (org-agenda-sticky
  1678. ;; Creating a sticky Agenda buffer for the first time
  1679. (kill-all-local-variables)
  1680. (mapc 'make-local-variable org-agenda-local-vars)
  1681. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1682. (t
  1683. ;; Creating a non-sticky agenda buffer
  1684. (kill-all-local-variables)
  1685. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1686. (setq org-agenda-undo-list nil
  1687. org-agenda-pending-undo-list nil
  1688. org-agenda-bulk-marked-entries nil)
  1689. (setq major-mode 'org-agenda-mode)
  1690. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1691. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1692. (setq mode-name "Org-Agenda")
  1693. (use-local-map org-agenda-mode-map)
  1694. (easy-menu-add org-agenda-menu)
  1695. (if org-startup-truncated (setq truncate-lines t))
  1696. (org-set-local 'line-move-visual nil)
  1697. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1698. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1699. ;; Make sure properties are removed when copying text
  1700. (when (boundp 'buffer-substring-filters)
  1701. (org-set-local 'buffer-substring-filters
  1702. (cons (lambda (x)
  1703. (set-text-properties 0 (length x) nil x) x)
  1704. buffer-substring-filters)))
  1705. (unless org-agenda-keep-modes
  1706. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1707. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1708. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1709. org-agenda-show-log org-agenda-start-with-log-mode))
  1710. (easy-menu-change
  1711. '("Agenda") "Agenda Files"
  1712. (append
  1713. (list
  1714. (vector
  1715. (if (get 'org-agenda-files 'org-restrict)
  1716. "Restricted to single file"
  1717. "Edit File List")
  1718. '(org-edit-agenda-file-list)
  1719. (not (get 'org-agenda-files 'org-restrict)))
  1720. "--")
  1721. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1722. (org-agenda-set-mode-name)
  1723. (apply
  1724. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1725. (list 'org-agenda-mode-hook)))
  1726. (substitute-key-definition 'undo 'org-agenda-undo
  1727. org-agenda-mode-map global-map)
  1728. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1729. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1730. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1731. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1732. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1733. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1734. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1735. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1736. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1737. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1738. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1739. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1740. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1741. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1742. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1743. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1744. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1745. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1746. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1747. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1748. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1749. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1750. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1751. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1752. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1753. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1754. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1755. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1756. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1757. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1758. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1759. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1760. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1761. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1762. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1763. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1764. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1765. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1766. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1767. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1768. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1769. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1770. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1771. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1772. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1773. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1774. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1775. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1776. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1777. (while l (org-defkey org-agenda-mode-map
  1778. (int-to-string (pop l)) 'digit-argument)))
  1779. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1780. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1781. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1782. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1783. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1784. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1785. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1786. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1787. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1788. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1789. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1791. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1792. 'org-clock-modify-effort-estimate)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1794. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1795. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1796. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1797. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1798. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1799. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1800. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1801. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1802. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1803. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1804. (substitute-key-definition 'next-line 'org-agenda-next-line
  1805. org-agenda-mode-map global-map)
  1806. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1807. org-agenda-mode-map global-map)
  1808. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1809. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1810. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1811. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1812. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1813. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1814. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1815. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1816. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1817. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1818. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1819. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1820. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1821. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1822. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1823. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1824. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1825. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1826. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1827. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1828. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1829. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1830. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1831. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1832. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1833. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1834. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1835. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1836. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1837. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1838. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1839. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1840. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1841. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1842. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1843. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1844. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1845. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1846. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1847. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1849. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1850. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1851. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1852. (when org-agenda-mouse-1-follows-link
  1853. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1854. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1855. '("Agenda"
  1856. ("Agenda Files")
  1857. "--"
  1858. ("Agenda Dates"
  1859. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1860. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1861. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1862. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1863. "--"
  1864. ("View"
  1865. ["Day View" org-agenda-day-view
  1866. :active (org-agenda-check-type nil 'agenda)
  1867. :style radio :selected (eq org-agenda-current-span 'day)
  1868. :keys "v d (or just d)"]
  1869. ["Week View" org-agenda-week-view
  1870. :active (org-agenda-check-type nil 'agenda)
  1871. :style radio :selected (eq org-agenda-current-span 'week)
  1872. :keys "v w (or just w)"]
  1873. ["Month View" org-agenda-month-view
  1874. :active (org-agenda-check-type nil 'agenda)
  1875. :style radio :selected (eq org-agenda-current-span 'month)
  1876. :keys "v m"]
  1877. ["Year View" org-agenda-year-view
  1878. :active (org-agenda-check-type nil 'agenda)
  1879. :style radio :selected (eq org-agenda-current-span 'year)
  1880. :keys "v y"]
  1881. "--"
  1882. ["Include Diary" org-agenda-toggle-diary
  1883. :style toggle :selected org-agenda-include-diary
  1884. :active (org-agenda-check-type nil 'agenda)]
  1885. ["Include Deadlines" org-agenda-toggle-deadlines
  1886. :style toggle :selected org-agenda-include-deadlines
  1887. :active (org-agenda-check-type nil 'agenda)]
  1888. ["Use Time Grid" org-agenda-toggle-time-grid
  1889. :style toggle :selected org-agenda-use-time-grid
  1890. :active (org-agenda-check-type nil 'agenda)]
  1891. "--"
  1892. ["Show clock report" org-agenda-clockreport-mode
  1893. :style toggle :selected org-agenda-clockreport-mode
  1894. :active (org-agenda-check-type nil 'agenda)]
  1895. ["Show some entry text" org-agenda-entry-text-mode
  1896. :style toggle :selected org-agenda-entry-text-mode
  1897. :active t]
  1898. "--"
  1899. ["Show Logbook entries" org-agenda-log-mode
  1900. :style toggle :selected org-agenda-show-log
  1901. :active (org-agenda-check-type nil 'agenda 'timeline)
  1902. :keys "v l (or just l)"]
  1903. ["Include archived trees" org-agenda-archives-mode
  1904. :style toggle :selected org-agenda-archives-mode :active t
  1905. :keys "v a"]
  1906. ["Include archive files" (org-agenda-archives-mode t)
  1907. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1908. :keys "v A"]
  1909. "--"
  1910. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1911. ["Write view to file" org-agenda-write t]
  1912. ["Rebuild buffer" org-agenda-redo t]
  1913. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1914. "--"
  1915. ["Show original entry" org-agenda-show t]
  1916. ["Go To (other window)" org-agenda-goto t]
  1917. ["Go To (this window)" org-agenda-switch-to t]
  1918. ["Follow Mode" org-agenda-follow-mode
  1919. :style toggle :selected org-agenda-follow-mode :active t]
  1920. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1921. "--"
  1922. ("TODO"
  1923. ["Cycle TODO" org-agenda-todo t]
  1924. ["Next TODO set" org-agenda-todo-nextset t]
  1925. ["Previous TODO set" org-agenda-todo-previousset t]
  1926. ["Add note" org-agenda-add-note t])
  1927. ("Archive/Refile/Delete"
  1928. ["Archive default" org-agenda-archive-default t]
  1929. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1930. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1931. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1932. ["Archive subtree" org-agenda-archive t]
  1933. "--"
  1934. ["Refile" org-agenda-refile t]
  1935. "--"
  1936. ["Delete subtree" org-agenda-kill t])
  1937. ("Bulk action"
  1938. ["Mark entry" org-agenda-bulk-mark t]
  1939. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1940. ["Unmark entry" org-agenda-bulk-unmark t]
  1941. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1942. ["Act on all marked" org-agenda-bulk-action t]
  1943. "--"
  1944. ("Tags and Properties"
  1945. ["Show all Tags" org-agenda-show-tags t]
  1946. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1947. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1948. "--"
  1949. ["Column View" org-columns t])
  1950. ("Deadline/Schedule"
  1951. ["Schedule" org-agenda-schedule t]
  1952. ["Set Deadline" org-agenda-deadline t]
  1953. "--"
  1954. ["Mark item" org-agenda-action :active t :keys "k m"]
  1955. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1956. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1957. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1958. "--"
  1959. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1960. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1961. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1962. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1963. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1964. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1965. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1966. ("Clock and Effort"
  1967. ["Clock in" org-agenda-clock-in t]
  1968. ["Clock out" org-agenda-clock-out t]
  1969. ["Clock cancel" org-agenda-clock-cancel t]
  1970. ["Goto running clock" org-clock-goto t]
  1971. "--"
  1972. ["Set Effort" org-agenda-set-effort t]
  1973. ["Change clocked effort" org-clock-modify-effort-estimate
  1974. (org-clock-is-active)])
  1975. ("Priority"
  1976. ["Set Priority" org-agenda-priority t]
  1977. ["Increase Priority" org-agenda-priority-up t]
  1978. ["Decrease Priority" org-agenda-priority-down t]
  1979. ["Show Priority" org-agenda-show-priority t])
  1980. ("Calendar/Diary"
  1981. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1982. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1983. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1984. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1985. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1986. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1987. "--"
  1988. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1989. "--"
  1990. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1991. "--"
  1992. ("MobileOrg"
  1993. ["Push Files and Views" org-mobile-push t]
  1994. ["Get Captured and Flagged" org-mobile-pull t]
  1995. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1996. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1997. "--"
  1998. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1999. "--"
  2000. ["Quit" org-agenda-quit t]
  2001. ["Exit and Release Buffers" org-agenda-exit t]
  2002. ))
  2003. ;;; Agenda undo
  2004. (defvar org-agenda-allow-remote-undo t
  2005. "Non-nil means allow remote undo from the agenda buffer.")
  2006. (defvar org-agenda-undo-list nil
  2007. "List of undoable operations in the agenda since last refresh.")
  2008. (defvar org-agenda-undo-has-started-in nil
  2009. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2010. (defvar org-agenda-pending-undo-list nil
  2011. "In a series of undo commands, this is the list of remaining undo items.")
  2012. (defun org-agenda-undo ()
  2013. "Undo a remote editing step in the agenda.
  2014. This undoes changes both in the agenda buffer and in the remote buffer
  2015. that have been changed along."
  2016. (interactive)
  2017. (or org-agenda-allow-remote-undo
  2018. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2019. (if (not (eq this-command last-command))
  2020. (setq org-agenda-undo-has-started-in nil
  2021. org-agenda-pending-undo-list org-agenda-undo-list))
  2022. (if (not org-agenda-pending-undo-list)
  2023. (error "No further undo information"))
  2024. (let* ((entry (pop org-agenda-pending-undo-list))
  2025. buf line cmd rembuf)
  2026. (setq cmd (pop entry) line (pop entry))
  2027. (setq rembuf (nth 2 entry))
  2028. (org-with-remote-undo rembuf
  2029. (while (bufferp (setq buf (pop entry)))
  2030. (if (pop entry)
  2031. (with-current-buffer buf
  2032. (let ((last-undo-buffer buf)
  2033. (inhibit-read-only t))
  2034. (unless (memq buf org-agenda-undo-has-started-in)
  2035. (push buf org-agenda-undo-has-started-in)
  2036. (make-local-variable 'pending-undo-list)
  2037. (undo-start))
  2038. (while (and pending-undo-list
  2039. (listp pending-undo-list)
  2040. (not (car pending-undo-list)))
  2041. (pop pending-undo-list))
  2042. (undo-more 1))))))
  2043. (org-goto-line line)
  2044. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2045. (defun org-verify-change-for-undo (l1 l2)
  2046. "Verify that a real change occurred between the undo lists L1 and L2."
  2047. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2048. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2049. (not (eq l1 l2)))
  2050. ;;; Agenda dispatch
  2051. (defvar org-agenda-restrict nil)
  2052. (defvar org-agenda-restrict-begin (make-marker))
  2053. (defvar org-agenda-restrict-end (make-marker))
  2054. (defvar org-agenda-last-dispatch-buffer nil)
  2055. (defvar org-agenda-overriding-restriction nil)
  2056. ;;;###autoload
  2057. (defun org-agenda (&optional arg keys restriction)
  2058. "Dispatch agenda commands to collect entries to the agenda buffer.
  2059. Prompts for a command to execute. Any prefix arg will be passed
  2060. on to the selected command. The default selections are:
  2061. a Call `org-agenda-list' to display the agenda for current day or week.
  2062. t Call `org-todo-list' to display the global todo list.
  2063. T Call `org-todo-list' to display the global todo list, select only
  2064. entries with a specific TODO keyword (the user gets a prompt).
  2065. m Call `org-tags-view' to display headlines with tags matching
  2066. a condition (the user is prompted for the condition).
  2067. M Like `m', but select only TODO entries, no ordinary headlines.
  2068. L Create a timeline for the current buffer.
  2069. e Export views to associated files.
  2070. s Search entries for keywords.
  2071. / Multi occur across all agenda files and also files listed
  2072. in `org-agenda-text-search-extra-files'.
  2073. < Restrict agenda commands to buffer, subtree, or region.
  2074. Press several times to get the desired effect.
  2075. > Remove a previous restriction.
  2076. # List \"stuck\" projects.
  2077. ! Configure what \"stuck\" means.
  2078. C Configure custom agenda commands.
  2079. More commands can be added by configuring the variable
  2080. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2081. searches can be pre-defined in this way.
  2082. If the current buffer is in Org-mode and visiting a file, you can also
  2083. first press `<' once to indicate that the agenda should be temporarily
  2084. \(until the next use of \\[org-agenda]) restricted to the current file.
  2085. Pressing `<' twice means to restrict to the current subtree or region
  2086. \(if active)."
  2087. (interactive "P")
  2088. (catch 'exit
  2089. (let* ((prefix-descriptions nil)
  2090. (org-agenda-buffer-name org-agenda-buffer-name)
  2091. (org-agenda-window-setup (if (equal (buffer-name)
  2092. org-agenda-buffer-name)
  2093. 'current-window
  2094. org-agenda-window-setup))
  2095. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2096. (org-agenda-custom-commands
  2097. ;; normalize different versions
  2098. (delq nil
  2099. (mapcar
  2100. (lambda (x)
  2101. (cond ((stringp (cdr x))
  2102. (push x prefix-descriptions)
  2103. nil)
  2104. ((stringp (nth 1 x)) x)
  2105. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2106. (t (cons (car x) (cons "" (cdr x))))))
  2107. org-agenda-custom-commands)))
  2108. (buf (current-buffer))
  2109. (bfn (buffer-file-name (buffer-base-buffer)))
  2110. entry key type match lprops ans)
  2111. ;; Turn off restriction unless there is an overriding one,
  2112. (unless org-agenda-overriding-restriction
  2113. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2114. ;; There is a request to keep the file list in place
  2115. (put 'org-agenda-files 'org-restrict nil))
  2116. (setq org-agenda-restrict nil)
  2117. (move-marker org-agenda-restrict-begin nil)
  2118. (move-marker org-agenda-restrict-end nil))
  2119. ;; Delete old local properties
  2120. (put 'org-agenda-redo-command 'org-lprops nil)
  2121. ;; Delete previously set last-arguments
  2122. (put 'org-agenda-redo-command 'last-args nil)
  2123. ;; Remember where this call originated
  2124. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2125. (unless keys
  2126. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2127. keys (car ans)
  2128. restriction (cdr ans)))
  2129. ;; If we have sticky agenda buffers, set a name for the buffer,
  2130. ;; depending on the invoking keys. The user may still set this
  2131. ;; as a command option, which will overwrite what we do here.
  2132. (if org-agenda-sticky
  2133. (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
  2134. ;; Establish the restriction, if any
  2135. (when (and (not org-agenda-overriding-restriction) restriction)
  2136. (put 'org-agenda-files 'org-restrict (list bfn))
  2137. (cond
  2138. ((eq restriction 'region)
  2139. (setq org-agenda-restrict t)
  2140. (move-marker org-agenda-restrict-begin (region-beginning))
  2141. (move-marker org-agenda-restrict-end (region-end)))
  2142. ((eq restriction 'subtree)
  2143. (save-excursion
  2144. (setq org-agenda-restrict t)
  2145. (org-back-to-heading t)
  2146. (move-marker org-agenda-restrict-begin (point))
  2147. (move-marker org-agenda-restrict-end
  2148. (progn (org-end-of-subtree t)))))))
  2149. ;; For example the todo list should not need it (but does...)
  2150. (cond
  2151. ((setq entry (assoc keys org-agenda-custom-commands))
  2152. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2153. (progn
  2154. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2155. lprops (nth 4 entry))
  2156. (put 'org-agenda-redo-command 'org-lprops lprops)
  2157. (cond
  2158. ((eq type 'agenda)
  2159. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2160. ((eq type 'alltodo)
  2161. (org-let lprops '(org-todo-list current-prefix-arg)))
  2162. ((eq type 'search)
  2163. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2164. ((eq type 'stuck)
  2165. (org-let lprops '(org-agenda-list-stuck-projects
  2166. current-prefix-arg)))
  2167. ((eq type 'tags)
  2168. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2169. ((eq type 'tags-todo)
  2170. (org-let lprops '(org-tags-view '(4) match)))
  2171. ((eq type 'todo)
  2172. (org-let lprops '(org-todo-list match)))
  2173. ((eq type 'tags-tree)
  2174. (org-check-for-org-mode)
  2175. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2176. ((eq type 'todo-tree)
  2177. (org-check-for-org-mode)
  2178. (org-let lprops
  2179. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2180. (regexp-quote match) "\\>"))))
  2181. ((eq type 'occur-tree)
  2182. (org-check-for-org-mode)
  2183. (org-let lprops '(org-occur match)))
  2184. ((functionp type)
  2185. (org-let lprops '(funcall type match)))
  2186. ((fboundp type)
  2187. (org-let lprops '(funcall type match)))
  2188. (t (error "Invalid custom agenda command type %s" type))))
  2189. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2190. ((equal keys "C")
  2191. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2192. (customize-variable 'org-agenda-custom-commands))
  2193. ((equal keys "a") (call-interactively 'org-agenda-list))
  2194. ((equal keys "s") (call-interactively 'org-search-view))
  2195. ((equal keys "t") (call-interactively 'org-todo-list))
  2196. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2197. ((equal keys "m") (call-interactively 'org-tags-view))
  2198. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2199. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2200. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2201. (org-add-hook
  2202. 'post-command-hook
  2203. (lambda ()
  2204. (unless (current-message)
  2205. (let* ((m (org-agenda-get-any-marker))
  2206. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2207. (when note
  2208. (message (concat
  2209. "FLAGGING-NOTE ([?] for more info): "
  2210. (org-add-props
  2211. (replace-regexp-in-string
  2212. "\\\\n" "//"
  2213. (copy-sequence note))
  2214. nil 'face 'org-warning)))))))
  2215. t t))
  2216. ((equal keys "L")
  2217. (unless (derived-mode-p 'org-mode)
  2218. (error "This is not an Org-mode file"))
  2219. (unless restriction
  2220. (put 'org-agenda-files 'org-restrict (list bfn))
  2221. (org-call-with-arg 'org-timeline arg)))
  2222. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2223. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2224. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2225. (t (error "Invalid agenda key"))))))
  2226. (defun org-agenda-append-agenda ()
  2227. "Append another agenda view to the current one.
  2228. This function allows interactive building of block agendas.
  2229. Agenda views are separated by `org-agenda-block-separator'."
  2230. (interactive)
  2231. (unless (string= (buffer-name) org-agenda-buffer-name)
  2232. (error "Can only append from within agenda buffer"))
  2233. (let ((org-agenda-multi t))
  2234. (org-agenda)
  2235. (widen)))
  2236. (defun org-agenda-normalize-custom-commands (cmds)
  2237. (delq nil
  2238. (mapcar
  2239. (lambda (x)
  2240. (cond ((stringp (cdr x)) nil)
  2241. ((stringp (nth 1 x)) x)
  2242. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2243. (t (cons (car x) (cons "" (cdr x))))))
  2244. cmds)))
  2245. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2246. "The user interface for selecting an agenda command."
  2247. (catch 'exit
  2248. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2249. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2250. (region-p (org-region-active-p))
  2251. (custom org-agenda-custom-commands)
  2252. (selstring "")
  2253. restriction second-time
  2254. c entry key type match prefixes rmheader header-end custom1 desc
  2255. line lines left right n n1)
  2256. (save-window-excursion
  2257. (delete-other-windows)
  2258. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2259. (erase-buffer)
  2260. (insert (eval-when-compile
  2261. (let ((header
  2262. "Press key for an agenda command: < Buffer, subtree/region restriction
  2263. -------------------------------- > Remove restriction
  2264. a Agenda for current week or day e Export agenda views
  2265. t List of all TODO entries T Entries with special TODO kwd
  2266. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2267. L Timeline for current buffer # List stuck projects (!=configure)
  2268. s Search for keywords * Toggle sticky agenda views
  2269. / Multi-occur ? Find :FLAGGED: entries
  2270. C Configure custom agenda commands
  2271. ")
  2272. (start 0))
  2273. (while (string-match
  2274. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2275. header start)
  2276. (setq start (match-end 0))
  2277. (add-text-properties (match-beginning 2) (match-end 2)
  2278. '(face bold) header))
  2279. header)))
  2280. (setq header-end (move-marker (make-marker) (point)))
  2281. (while t
  2282. (setq custom1 custom)
  2283. (when (eq rmheader t)
  2284. (org-goto-line 1)
  2285. (re-search-forward ":" nil t)
  2286. (delete-region (match-end 0) (point-at-eol))
  2287. (forward-char 1)
  2288. (looking-at "-+")
  2289. (delete-region (match-end 0) (point-at-eol))
  2290. (move-marker header-end (match-end 0)))
  2291. (goto-char header-end)
  2292. (delete-region (point) (point-max))
  2293. ;; Produce all the lines that describe custom commands and prefixes
  2294. (setq lines nil)
  2295. (while (setq entry (pop custom1))
  2296. (setq key (car entry) desc (nth 1 entry)
  2297. type (nth 2 entry)
  2298. match (nth 3 entry))
  2299. (if (> (length key) 1)
  2300. (add-to-list 'prefixes (string-to-char key))
  2301. (setq line
  2302. (format
  2303. "%-4s%-14s"
  2304. (org-add-props (copy-sequence key)
  2305. '(face bold))
  2306. (cond
  2307. ((string-match "\\S-" desc) desc)
  2308. ((eq type 'agenda) "Agenda for current week or day")
  2309. ((eq type 'alltodo) "List of all TODO entries")
  2310. ((eq type 'search) "Word search")
  2311. ((eq type 'stuck) "List of stuck projects")
  2312. ((eq type 'todo) "TODO keyword")
  2313. ((eq type 'tags) "Tags query")
  2314. ((eq type 'tags-todo) "Tags (TODO)")
  2315. ((eq type 'tags-tree) "Tags tree")
  2316. ((eq type 'todo-tree) "TODO kwd tree")
  2317. ((eq type 'occur-tree) "Occur tree")
  2318. ((functionp type) (if (symbolp type)
  2319. (symbol-name type)
  2320. "Lambda expression"))
  2321. (t "???"))))
  2322. (if org-agenda-menu-show-matcher
  2323. (setq line
  2324. (concat line ": "
  2325. (cond
  2326. ((stringp match)
  2327. (setq match (copy-sequence match))
  2328. (org-add-props match nil 'face 'org-warning))
  2329. (match
  2330. (format "set of %d commands" (length match)))
  2331. (t ""))))
  2332. (if (org-string-nw-p match)
  2333. (add-text-properties
  2334. 0 (length line) (list 'help-echo
  2335. (concat "Matcher: "match)) line)))
  2336. (push line lines)))
  2337. (setq lines (nreverse lines))
  2338. (when prefixes
  2339. (mapc (lambda (x)
  2340. (push
  2341. (format "%s %s"
  2342. (org-add-props (char-to-string x)
  2343. nil 'face 'bold)
  2344. (or (cdr (assoc (concat selstring
  2345. (char-to-string x))
  2346. prefix-descriptions))
  2347. "Prefix key"))
  2348. lines))
  2349. prefixes))
  2350. ;; Check if we should display in two columns
  2351. (if org-agenda-menu-two-column
  2352. (progn
  2353. (setq n (length lines)
  2354. n1 (+ (/ n 2) (mod n 2))
  2355. right (nthcdr n1 lines)
  2356. left (copy-sequence lines))
  2357. (setcdr (nthcdr (1- n1) left) nil))
  2358. (setq left lines right nil))
  2359. (while left
  2360. (insert "\n" (pop left))
  2361. (when right
  2362. (if (< (current-column) 40)
  2363. (move-to-column 40 t)
  2364. (insert " "))
  2365. (insert (pop right))))
  2366. ;; Make the window the right size
  2367. (goto-char (point-min))
  2368. (if second-time
  2369. (if (not (pos-visible-in-window-p (point-max)))
  2370. (org-fit-window-to-buffer))
  2371. (setq second-time t)
  2372. (org-fit-window-to-buffer))
  2373. ;; Ask for selection
  2374. (message "Press key for agenda command%s:"
  2375. (if (or restrict-ok org-agenda-overriding-restriction)
  2376. (if org-agenda-overriding-restriction
  2377. " (restriction lock active)"
  2378. (if restriction
  2379. (format " (restricted to %s)" restriction)
  2380. " (unrestricted)"))
  2381. ""))
  2382. (setq c (read-char-exclusive))
  2383. (message "")
  2384. (cond
  2385. ((assoc (char-to-string c) custom)
  2386. (setq selstring (concat selstring (char-to-string c)))
  2387. (throw 'exit (cons selstring restriction)))
  2388. ((memq c prefixes)
  2389. (setq selstring (concat selstring (char-to-string c))
  2390. prefixes nil
  2391. rmheader (or rmheader t)
  2392. custom (delq nil (mapcar
  2393. (lambda (x)
  2394. (if (or (= (length (car x)) 1)
  2395. (/= (string-to-char (car x)) c))
  2396. nil
  2397. (cons (substring (car x) 1) (cdr x))))
  2398. custom))))
  2399. ((eq c ?*)
  2400. (org-toggle-sticky-agenda)
  2401. (sit-for 2))
  2402. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2403. (message "Restriction is only possible in Org-mode buffers")
  2404. (ding) (sit-for 1))
  2405. ((eq c ?1)
  2406. (org-agenda-remove-restriction-lock 'noupdate)
  2407. (setq restriction 'buffer))
  2408. ((eq c ?0)
  2409. (org-agenda-remove-restriction-lock 'noupdate)
  2410. (setq restriction (if region-p 'region 'subtree)))
  2411. ((eq c ?<)
  2412. (org-agenda-remove-restriction-lock 'noupdate)
  2413. (setq restriction
  2414. (cond
  2415. ((eq restriction 'buffer)
  2416. (if region-p 'region 'subtree))
  2417. ((memq restriction '(subtree region))
  2418. nil)
  2419. (t 'buffer))))
  2420. ((eq c ?>)
  2421. (org-agenda-remove-restriction-lock 'noupdate)
  2422. (setq restriction nil))
  2423. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2424. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2425. ((and (> (length selstring) 0) (eq c ?\d))
  2426. (delete-window)
  2427. (org-agenda-get-restriction-and-command prefix-descriptions))
  2428. ((equal c ?q) (error "Abort"))
  2429. (t (error "Invalid key %c" c))))))))
  2430. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2431. (defvar org-agenda-last-arguments nil
  2432. "The arguments of the previous call to `org-agenda'.")
  2433. (defun org-agenda-run-series (name series)
  2434. (org-let (nth 1 series) '(org-prepare-agenda name))
  2435. ;; We need to reset agenda markers here, because when constructing a
  2436. ;; block agenda, the individual blocks do not do that.
  2437. (org-agenda-reset-markers)
  2438. (let* ((org-agenda-multi t)
  2439. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2440. (org-agenda-overriding-arguments
  2441. (or org-agenda-overriding-arguments
  2442. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2443. (get 'org-agenda-redo-command 'last-args))))
  2444. (cmds (car series))
  2445. (gprops (nth 1 series))
  2446. match ;; The byte compiler incorrectly complains about this. Keep it!
  2447. cmd type lprops)
  2448. (while (setq cmd (pop cmds))
  2449. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2450. (cond
  2451. ((eq type 'agenda)
  2452. (org-let2 gprops lprops
  2453. '(call-interactively 'org-agenda-list)))
  2454. ((eq type 'alltodo)
  2455. (org-let2 gprops lprops
  2456. '(call-interactively 'org-todo-list)))
  2457. ((eq type 'search)
  2458. (org-let2 gprops lprops
  2459. '(org-search-view current-prefix-arg match nil)))
  2460. ((eq type 'stuck)
  2461. (org-let2 gprops lprops
  2462. '(call-interactively 'org-agenda-list-stuck-projects)))
  2463. ((eq type 'tags)
  2464. (org-let2 gprops lprops
  2465. '(org-tags-view current-prefix-arg match)))
  2466. ((eq type 'tags-todo)
  2467. (org-let2 gprops lprops
  2468. '(org-tags-view '(4) match)))
  2469. ((eq type 'todo)
  2470. (org-let2 gprops lprops
  2471. '(org-todo-list match)))
  2472. ((fboundp type)
  2473. (org-let2 gprops lprops
  2474. '(funcall type match)))
  2475. (t (error "Invalid type in command series"))))
  2476. (widen)
  2477. (setq org-agenda-redo-command redo)
  2478. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2479. (goto-char (point-min)))
  2480. (org-fit-agenda-window)
  2481. (org-let (nth 1 series) '(org-finalize-agenda)))
  2482. ;;;###autoload
  2483. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2484. "Run an agenda command in batch mode and send the result to STDOUT.
  2485. If CMD-KEY is a string of length 1, it is used as a key in
  2486. `org-agenda-custom-commands' and triggers this command. If it is a
  2487. longer string it is used as a tags/todo match string.
  2488. Parameters are alternating variable names and values that will be bound
  2489. before running the agenda command."
  2490. (org-eval-in-environment (org-make-parameter-alist parameters)
  2491. (if (> (length cmd-key) 2)
  2492. (org-tags-view nil cmd-key)
  2493. (org-agenda nil cmd-key)))
  2494. (set-buffer org-agenda-buffer-name)
  2495. (princ (buffer-string)))
  2496. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2497. (defvar org-agenda-info nil)
  2498. ;;;###autoload
  2499. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2500. "Run an agenda command in batch mode and send the result to STDOUT.
  2501. If CMD-KEY is a string of length 1, it is used as a key in
  2502. `org-agenda-custom-commands' and triggers this command. If it is a
  2503. longer string it is used as a tags/todo match string.
  2504. Parameters are alternating variable names and values that will be bound
  2505. before running the agenda command.
  2506. The output gives a line for each selected agenda item. Each
  2507. item is a list of comma-separated values, like this:
  2508. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2509. category The category of the item
  2510. head The headline, without TODO kwd, TAGS and PRIORITY
  2511. type The type of the agenda entry, can be
  2512. todo selected in TODO match
  2513. tagsmatch selected in tags match
  2514. diary imported from diary
  2515. deadline a deadline on given date
  2516. scheduled scheduled on given date
  2517. timestamp entry has timestamp on given date
  2518. closed entry was closed on given date
  2519. upcoming-deadline warning about deadline
  2520. past-scheduled forwarded scheduled item
  2521. block entry has date block including g. date
  2522. todo The todo keyword, if any
  2523. tags All tags including inherited ones, separated by colons
  2524. date The relevant date, like 2007-2-14
  2525. time The time, like 15:00-16:50
  2526. extra Sting with extra planning info
  2527. priority-l The priority letter if any was given
  2528. priority-n The computed numerical priority
  2529. agenda-day The day in the agenda where this is listed"
  2530. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2531. (org-make-parameter-alist parameters))
  2532. (if (> (length cmd-key) 2)
  2533. (org-tags-view nil cmd-key)
  2534. (org-agenda nil cmd-key)))
  2535. (set-buffer org-agenda-buffer-name)
  2536. (let* ((lines (org-split-string (buffer-string) "\n"))
  2537. line)
  2538. (while (setq line (pop lines))
  2539. (catch 'next
  2540. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2541. (setq org-agenda-info
  2542. (org-fix-agenda-info (text-properties-at 0 line)))
  2543. (princ
  2544. (mapconcat 'org-agenda-export-csv-mapper
  2545. '(org-category txt type todo tags date time extra
  2546. priority-letter priority agenda-day)
  2547. ","))
  2548. (princ "\n")))))
  2549. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2550. (defun org-fix-agenda-info (props)
  2551. "Make sure all properties on an agenda item have a canonical form.
  2552. This ensures the export commands can easily use it."
  2553. (let (tmp re)
  2554. (when (setq tmp (plist-get props 'tags))
  2555. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2556. (when (setq tmp (plist-get props 'date))
  2557. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2558. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2559. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2560. (setq tmp (calendar-date-string tmp)))
  2561. (setq props (plist-put props 'date tmp)))
  2562. (when (setq tmp (plist-get props 'day))
  2563. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2564. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2565. (setq tmp (calendar-date-string tmp)))
  2566. (setq props (plist-put props 'day tmp))
  2567. (setq props (plist-put props 'agenda-day tmp)))
  2568. (when (setq tmp (plist-get props 'txt))
  2569. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2570. (plist-put props 'priority-letter (match-string 1 tmp))
  2571. (setq tmp (replace-match "" t t tmp)))
  2572. (when (and (setq re (plist-get props 'org-todo-regexp))
  2573. (setq re (concat "\\`\\.*" re " ?"))
  2574. (string-match re tmp))
  2575. (plist-put props 'todo (match-string 1 tmp))
  2576. (setq tmp (replace-match "" t t tmp)))
  2577. (plist-put props 'txt tmp)))
  2578. props)
  2579. (defun org-agenda-export-csv-mapper (prop)
  2580. (let ((res (plist-get org-agenda-info prop)))
  2581. (setq res
  2582. (cond
  2583. ((not res) "")
  2584. ((stringp res) res)
  2585. (t (prin1-to-string res))))
  2586. (while (string-match "," res)
  2587. (setq res (replace-match ";" t t res)))
  2588. (org-trim res)))
  2589. ;;;###autoload
  2590. (defun org-store-agenda-views (&rest parameters)
  2591. (interactive)
  2592. (eval (list 'org-batch-store-agenda-views)))
  2593. ;;;###autoload
  2594. (defmacro org-batch-store-agenda-views (&rest parameters)
  2595. "Run all custom agenda commands that have a file argument."
  2596. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2597. (pop-up-frames nil)
  2598. (dir default-directory)
  2599. (pars (org-make-parameter-alist parameters))
  2600. cmd thiscmdkey files opts cmd-or-set)
  2601. (save-window-excursion
  2602. (while cmds
  2603. (setq cmd (pop cmds)
  2604. thiscmdkey (car cmd)
  2605. cmd-or-set (nth 2 cmd)
  2606. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2607. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2608. (if (stringp files) (setq files (list files)))
  2609. (when files
  2610. (org-eval-in-environment (append org-agenda-exporter-settings
  2611. opts pars)
  2612. (org-agenda nil thiscmdkey))
  2613. (set-buffer org-agenda-buffer-name)
  2614. (while files
  2615. (org-eval-in-environment (append org-agenda-exporter-settings
  2616. opts pars)
  2617. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2618. (and (get-buffer org-agenda-buffer-name)
  2619. (kill-buffer org-agenda-buffer-name)))))))
  2620. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2621. (defun org-agenda-mark-header-line (pos)
  2622. "Mark the line at POS as an agenda structure header."
  2623. (save-excursion
  2624. (goto-char pos)
  2625. (put-text-property (point-at-bol) (point-at-eol)
  2626. 'org-agenda-structural-header t)
  2627. (when org-agenda-title-append
  2628. (put-text-property (point-at-bol) (point-at-eol)
  2629. 'org-agenda-title-append org-agenda-title-append))))
  2630. (defvar org-mobile-creating-agendas)
  2631. (defvar org-agenda-write-buffer-name "Agenda View")
  2632. (defun org-agenda-write (file &optional open nosettings)
  2633. "Write the current buffer (an agenda view) as a file.
  2634. Depending on the extension of the file name, plain text (.txt),
  2635. HTML (.html or .htm) or Postscript (.ps) is produced.
  2636. If the extension is .ics, run icalendar export over all files used
  2637. to construct the agenda and limit the export to entries listed in the
  2638. agenda now.
  2639. With prefix argument OPEN, open the new file immediately.
  2640. If NOSETTINGS is given, do not scope the settings of
  2641. `org-agenda-exporter-settings' into the export commands. This is used when
  2642. the settings have already been scoped and we do not wish to overrule other,
  2643. higher priority settings."
  2644. (interactive "FWrite agenda to file: \nP")
  2645. (if (not (file-writable-p file))
  2646. (error "Cannot write agenda to file %s" file))
  2647. (org-let (if nosettings nil org-agenda-exporter-settings)
  2648. '(save-excursion
  2649. (save-window-excursion
  2650. (org-agenda-mark-filtered-text)
  2651. (let ((bs (copy-sequence (buffer-string))) beg)
  2652. (org-agenda-unmark-filtered-text)
  2653. (with-temp-buffer
  2654. (rename-buffer org-agenda-write-buffer-name t)
  2655. (set-buffer-modified-p nil)
  2656. (insert bs)
  2657. (org-agenda-remove-marked-text 'org-filtered)
  2658. (while (setq beg (text-property-any (point-min) (point-max)
  2659. 'org-filtered t))
  2660. (delete-region
  2661. beg (or (next-single-property-change beg 'org-filtered)
  2662. (point-max))))
  2663. (run-hooks 'org-agenda-before-write-hook)
  2664. (cond
  2665. ((org-bound-and-true-p org-mobile-creating-agendas)
  2666. (org-mobile-write-agenda-for-mobile file))
  2667. ((string-match "\\.html?\\'" file)
  2668. (require 'htmlize)
  2669. (set-buffer (htmlize-buffer (current-buffer)))
  2670. (when (and org-agenda-export-html-style
  2671. (string-match "<style>" org-agenda-export-html-style))
  2672. ;; replace <style> section with org-agenda-export-html-style
  2673. (goto-char (point-min))
  2674. (kill-region (- (search-forward "<style") 6)
  2675. (search-forward "</style>"))
  2676. (insert org-agenda-export-html-style))
  2677. (write-file file)
  2678. (kill-buffer (current-buffer))
  2679. (message "HTML written to %s" file))
  2680. ((string-match "\\.ps\\'" file)
  2681. (require 'ps-print)
  2682. (ps-print-buffer-with-faces file)
  2683. (message "Postscript written to %s" file))
  2684. ((string-match "\\.pdf\\'" file)
  2685. (require 'ps-print)
  2686. (ps-print-buffer-with-faces
  2687. (concat (file-name-sans-extension file) ".ps"))
  2688. (call-process "ps2pdf" nil nil nil
  2689. (expand-file-name
  2690. (concat (file-name-sans-extension file) ".ps"))
  2691. (expand-file-name file))
  2692. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2693. (message "PDF written to %s" file))
  2694. ((string-match "\\.ics\\'" file)
  2695. (require 'org-icalendar)
  2696. (let ((org-agenda-marker-table
  2697. (org-create-marker-find-array
  2698. (org-agenda-collect-markers)))
  2699. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2700. (org-combined-agenda-icalendar-file file))
  2701. (apply 'org-export-icalendar 'combine
  2702. (org-agenda-files nil 'ifmode))))
  2703. (t
  2704. (let ((bs (buffer-string)))
  2705. (find-file file)
  2706. (erase-buffer)
  2707. (insert bs)
  2708. (save-buffer 0)
  2709. (kill-buffer (current-buffer))
  2710. (message "Plain text written to %s" file))))))))
  2711. (set-buffer org-agenda-buffer-name))
  2712. (when open (org-open-file file)))
  2713. (defvar org-agenda-tag-filter-overlays nil)
  2714. (defvar org-agenda-cat-filter-overlays nil)
  2715. (defun org-agenda-mark-filtered-text ()
  2716. "Mark all text hidden by filtering with a text property."
  2717. (let ((inhibit-read-only t))
  2718. (mapc
  2719. (lambda (o)
  2720. (when (equal (overlay-buffer o) (current-buffer))
  2721. (put-text-property
  2722. (overlay-start o) (overlay-end o)
  2723. 'org-filtered t)))
  2724. (append org-agenda-tag-filter-overlays
  2725. org-agenda-cat-filter-overlays))))
  2726. (defun org-agenda-unmark-filtered-text ()
  2727. "Remove the filtering text property."
  2728. (let ((inhibit-read-only t))
  2729. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2730. (defun org-agenda-remove-marked-text (property &optional value)
  2731. "Delete all text marked with VALUE of PROPERTY.
  2732. VALUE defaults to t."
  2733. (let (beg)
  2734. (setq value (or value t))
  2735. (while (setq beg (text-property-any (point-min) (point-max)
  2736. property value))
  2737. (delete-region
  2738. beg (or (next-single-property-change beg 'org-filtered)
  2739. (point-max))))))
  2740. (defun org-agenda-add-entry-text ()
  2741. "Add entry text to agenda lines.
  2742. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2743. entry text following headings shown in the agenda.
  2744. Drawers will be excluded, also the line with scheduling/deadline info."
  2745. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2746. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2747. (let (m txt)
  2748. (goto-char (point-min))
  2749. (while (not (eobp))
  2750. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2751. (beginning-of-line 2)
  2752. (setq txt (org-agenda-get-some-entry-text
  2753. m org-agenda-add-entry-text-maxlines " > "))
  2754. (end-of-line 1)
  2755. (if (string-match "\\S-" txt)
  2756. (insert "\n" txt)
  2757. (or (eobp) (forward-char 1))))))))
  2758. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2759. &rest keep)
  2760. "Extract entry text from MARKER, at most N-LINES lines.
  2761. This will ignore drawers etc, just get the text.
  2762. If INDENT is given, prefix every line with this string. If KEEP is
  2763. given, it is a list of symbols, defining stuff that should not be
  2764. removed from the entry content. Currently only `planning' is allowed here."
  2765. (let (txt drawer-re kwd-time-re ind)
  2766. (save-excursion
  2767. (with-current-buffer (marker-buffer marker)
  2768. (if (not (derived-mode-p 'org-mode))
  2769. (setq txt "")
  2770. (save-excursion
  2771. (save-restriction
  2772. (widen)
  2773. (goto-char marker)
  2774. (end-of-line 1)
  2775. (setq txt (buffer-substring
  2776. (min (1+ (point)) (point-max))
  2777. (progn (outline-next-heading) (point)))
  2778. drawer-re org-drawer-regexp
  2779. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2780. ".*\n?"))
  2781. (with-temp-buffer
  2782. (insert txt)
  2783. (when org-agenda-add-entry-text-descriptive-links
  2784. (goto-char (point-min))
  2785. (while (org-activate-bracket-links (point-max))
  2786. (add-text-properties (match-beginning 0) (match-end 0)
  2787. '(face org-link))))
  2788. (goto-char (point-min))
  2789. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2790. (set-text-properties (match-beginning 0) (match-end 0)
  2791. nil))
  2792. (goto-char (point-min))
  2793. (while (re-search-forward drawer-re nil t)
  2794. (delete-region
  2795. (match-beginning 0)
  2796. (progn (re-search-forward
  2797. "^[ \t]*:END:.*\n?" nil 'move)
  2798. (point))))
  2799. (unless (member 'planning keep)
  2800. (goto-char (point-min))
  2801. (while (re-search-forward kwd-time-re nil t)
  2802. (replace-match "")))
  2803. (goto-char (point-min))
  2804. (when org-agenda-entry-text-exclude-regexps
  2805. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2806. (while (setq re (pop re-list))
  2807. (goto-char (point-min))
  2808. (while (re-search-forward re nil t)
  2809. (replace-match "")))))
  2810. (goto-char (point-max))
  2811. (skip-chars-backward " \t\n")
  2812. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2813. ;; find and remove min common indentation
  2814. (goto-char (point-min))
  2815. (untabify (point-min) (point-max))
  2816. (setq ind (org-get-indentation))
  2817. (while (not (eobp))
  2818. (unless (looking-at "[ \t]*$")
  2819. (setq ind (min ind (org-get-indentation))))
  2820. (beginning-of-line 2))
  2821. (goto-char (point-min))
  2822. (while (not (eobp))
  2823. (unless (looking-at "[ \t]*$")
  2824. (move-to-column ind)
  2825. (delete-region (point-at-bol) (point)))
  2826. (beginning-of-line 2))
  2827. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2828. (goto-char (point-min))
  2829. (when indent
  2830. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2831. (replace-match indent t t)))
  2832. (goto-char (point-min))
  2833. (while (looking-at "[ \t]*\n") (replace-match ""))
  2834. (goto-char (point-max))
  2835. (when (> (org-current-line)
  2836. n-lines)
  2837. (org-goto-line (1+ n-lines))
  2838. (backward-char 1))
  2839. (setq txt (buffer-substring (point-min) (point)))))))))
  2840. txt))
  2841. (defun org-agenda-collect-markers ()
  2842. "Collect the markers pointing to entries in the agenda buffer."
  2843. (let (m markers)
  2844. (save-excursion
  2845. (goto-char (point-min))
  2846. (while (not (eobp))
  2847. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2848. (org-get-at-bol 'org-marker)))
  2849. (push m markers))
  2850. (beginning-of-line 2)))
  2851. (nreverse markers)))
  2852. (defun org-create-marker-find-array (marker-list)
  2853. "Create a alist of files names with all marker positions in that file."
  2854. (let (f tbl m a p)
  2855. (while (setq m (pop marker-list))
  2856. (setq p (marker-position m)
  2857. f (buffer-file-name (or (buffer-base-buffer
  2858. (marker-buffer m))
  2859. (marker-buffer m))))
  2860. (if (setq a (assoc f tbl))
  2861. (push (marker-position m) (cdr a))
  2862. (push (list f p) tbl)))
  2863. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2864. tbl)))
  2865. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2866. (defun org-check-agenda-marker-table ()
  2867. "Check of the current entry is on the marker list."
  2868. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2869. a)
  2870. (and (setq a (assoc file org-agenda-marker-table))
  2871. (save-match-data
  2872. (save-excursion
  2873. (org-back-to-heading t)
  2874. (member (point) (cdr a)))))))
  2875. (defun org-check-for-org-mode ()
  2876. "Make sure current buffer is in org-mode. Error if not."
  2877. (or (derived-mode-p 'org-mode)
  2878. (error "Cannot execute org-mode agenda command on buffer in %s"
  2879. major-mode)))
  2880. (defun org-fit-agenda-window ()
  2881. "Fit the window to the buffer size."
  2882. (and (memq org-agenda-window-setup '(reorganize-frame))
  2883. (fboundp 'fit-window-to-buffer)
  2884. (org-fit-window-to-buffer
  2885. nil
  2886. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2887. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2888. ;;; Agenda prepare and finalize
  2889. (defvar org-agenda-multi nil) ; dynamically scoped
  2890. (defvar org-agenda-buffer-name "*Org Agenda*")
  2891. (defvar org-pre-agenda-window-conf nil)
  2892. (defvar org-agenda-columns-active nil)
  2893. (defvar org-agenda-name nil)
  2894. (defvar org-agenda-tag-filter nil)
  2895. (defvar org-agenda-category-filter nil)
  2896. (defvar org-agenda-tag-filter-while-redo nil)
  2897. (defvar org-agenda-tag-filter-preset nil
  2898. "A preset of the tags filter used for secondary agenda filtering.
  2899. This must be a list of strings, each string must be a single tag preceded
  2900. by \"+\" or \"-\".
  2901. This variable should not be set directly, but agenda custom commands can
  2902. bind it in the options section. The preset filter is a global property of
  2903. the entire agenda view. In a block agenda, it will not work reliably to
  2904. define a filter for one of the individual blocks. You need to set it in
  2905. the global options and expect it to be applied to the entire view.")
  2906. (defvar org-agenda-category-filter-preset nil
  2907. "A preset of the category filter used for secondary agenda filtering.
  2908. This must be a list of strings, each string must be a single category
  2909. preceded by \"+\" or \"-\".
  2910. This variable should not be set directly, but agenda custom commands can
  2911. bind it in the options section. The preset filter is a global property of
  2912. the entire agenda view. In a block agenda, it will not work reliably to
  2913. define a filter for one of the individual blocks. You need to set it in
  2914. the global options and expect it to be applied to the entire view.")
  2915. (defun org-agenda-use-sticky-p ()
  2916. "Return non-NIL if existing agenda buffer named
  2917. `org-agenda-buffer-name' exists, and should be shown instead of
  2918. generating a new one"
  2919. (and
  2920. ;; turned off by user
  2921. org-agenda-sticky
  2922. ;; For multi-agenda buffer already exists
  2923. (not org-agenda-multi)
  2924. ;; buffer found
  2925. (get-buffer org-agenda-buffer-name)
  2926. ;; C-u parameter is same as last call
  2927. (with-current-buffer (get-buffer org-agenda-buffer-name)
  2928. (and
  2929. (equal current-prefix-arg
  2930. org-agenda-last-prefix-arg)
  2931. ;; In case user turned stickiness on, while having existing
  2932. ;; Agenda buffer active, don't reuse that buffer, because it
  2933. ;; does not have org variables local
  2934. org-agenda-this-buffer-is-sticky))))
  2935. (defun org-prepare-agenda-window (abuf)
  2936. "Setup agenda buffer in the window"
  2937. (let* ((awin (get-buffer-window abuf))
  2938. wconf)
  2939. (cond
  2940. ((equal (current-buffer) abuf) nil)
  2941. (awin (select-window awin))
  2942. ((not (setq wconf (current-window-configuration))))
  2943. ((equal org-agenda-window-setup 'current-window)
  2944. (org-pop-to-buffer-same-window abuf))
  2945. ((equal org-agenda-window-setup 'other-window)
  2946. (org-switch-to-buffer-other-window abuf))
  2947. ((equal org-agenda-window-setup 'other-frame)
  2948. (switch-to-buffer-other-frame abuf))
  2949. ((equal org-agenda-window-setup 'reorganize-frame)
  2950. (delete-other-windows)
  2951. (org-switch-to-buffer-other-window abuf)))
  2952. ;; additional test in case agenda is invoked from within agenda
  2953. ;; buffer via elisp link
  2954. (unless (equal (current-buffer) abuf)
  2955. (org-pop-to-buffer-same-window abuf))
  2956. (setq org-pre-agenda-window-conf wconf)))
  2957. (defun org-prepare-agenda (&optional name)
  2958. (if (org-agenda-use-sticky-p)
  2959. (progn
  2960. ;; Popup existing buffer
  2961. (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
  2962. (message "Sticky Agenda buffer, use `r' to refresh")
  2963. (throw 'exit nil))
  2964. (setq org-todo-keywords-for-agenda nil)
  2965. (setq org-drawers-for-agenda nil)
  2966. (unless org-agenda-persistent-filter
  2967. (setq org-agenda-tag-filter nil
  2968. org-agenda-category-filter nil))
  2969. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2970. (put 'org-agenda-category-filter :preset-filter
  2971. org-agenda-category-filter-preset)
  2972. (if org-agenda-multi
  2973. (progn
  2974. (setq buffer-read-only nil)
  2975. (goto-char (point-max))
  2976. (unless (or (bobp) org-agenda-compact-blocks
  2977. (not org-agenda-block-separator))
  2978. (insert "\n"
  2979. (if (stringp org-agenda-block-separator)
  2980. org-agenda-block-separator
  2981. (make-string (window-width) org-agenda-block-separator))
  2982. "\n"))
  2983. (narrow-to-region (point) (point-max)))
  2984. (setq org-done-keywords-for-agenda nil)
  2985. ;; Setting any org variables that are in org-agenda-local-vars
  2986. ;; list need to be done after the prepare call
  2987. (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
  2988. (setq buffer-read-only nil)
  2989. (org-agenda-reset-markers)
  2990. (let ((inhibit-read-only t)) (erase-buffer))
  2991. (org-agenda-mode)
  2992. (setq org-agenda-buffer (current-buffer))
  2993. (setq org-agenda-contributing-files nil)
  2994. (setq org-agenda-columns-active nil)
  2995. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2996. (setq org-todo-keywords-for-agenda
  2997. (org-uniquify org-todo-keywords-for-agenda))
  2998. (setq org-done-keywords-for-agenda
  2999. (org-uniquify org-done-keywords-for-agenda))
  3000. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3001. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3002. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3003. (and name (not org-agenda-name)
  3004. (org-set-local 'org-agenda-name name)))
  3005. (setq buffer-read-only nil)))
  3006. (defun org-finalize-agenda ()
  3007. "Finishing touch for the agenda buffer, called just before displaying it."
  3008. (unless org-agenda-multi
  3009. (save-excursion
  3010. (let ((inhibit-read-only t))
  3011. (goto-char (point-min))
  3012. (while (org-activate-bracket-links (point-max))
  3013. (add-text-properties (match-beginning 0) (match-end 0)
  3014. '(face org-link)))
  3015. (org-agenda-align-tags)
  3016. (unless org-agenda-with-colors
  3017. (remove-text-properties (point-min) (point-max) '(face nil))))
  3018. (if (and (boundp 'org-agenda-overriding-columns-format)
  3019. org-agenda-overriding-columns-format)
  3020. (org-set-local 'org-agenda-overriding-columns-format
  3021. org-agenda-overriding-columns-format))
  3022. (if (and (boundp 'org-agenda-view-columns-initially)
  3023. org-agenda-view-columns-initially)
  3024. (org-agenda-columns))
  3025. (when org-agenda-fontify-priorities
  3026. (org-agenda-fontify-priorities))
  3027. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3028. (org-agenda-dim-blocked-tasks))
  3029. (org-agenda-mark-clocking-task)
  3030. (when org-agenda-entry-text-mode
  3031. (org-agenda-entry-text-hide)
  3032. (org-agenda-entry-text-show))
  3033. (if (functionp 'org-habit-insert-consistency-graphs)
  3034. (org-habit-insert-consistency-graphs))
  3035. (run-hooks 'org-finalize-agenda-hook)
  3036. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3037. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3038. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3039. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3040. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3041. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3042. )))
  3043. (defun org-agenda-mark-clocking-task ()
  3044. "Mark the current clock entry in the agenda if it is present."
  3045. (mapc (lambda (o)
  3046. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3047. (delete-overlay o)))
  3048. (overlays-in (point-min) (point-max)))
  3049. (when (marker-buffer org-clock-hd-marker)
  3050. (save-excursion
  3051. (goto-char (point-min))
  3052. (let (s ov)
  3053. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3054. (goto-char s)
  3055. (when (equal (org-get-at-bol 'org-hd-marker)
  3056. org-clock-hd-marker)
  3057. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3058. (overlay-put ov 'type 'org-agenda-clocking)
  3059. (overlay-put ov 'face 'org-agenda-clocking)
  3060. (overlay-put ov 'help-echo
  3061. "The clock is running in this item")))))))
  3062. (defun org-agenda-fontify-priorities ()
  3063. "Make highest priority lines bold, and lowest italic."
  3064. (interactive)
  3065. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3066. (delete-overlay o)))
  3067. (overlays-in (point-min) (point-max)))
  3068. (save-excursion
  3069. (let ((inhibit-read-only t)
  3070. b e p ov h l)
  3071. (goto-char (point-min))
  3072. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3073. (setq h (or (get-char-property (point) 'org-highest-priority)
  3074. org-highest-priority)
  3075. l (or (get-char-property (point) 'org-lowest-priority)
  3076. org-lowest-priority)
  3077. p (string-to-char (match-string 1))
  3078. b (match-beginning 0)
  3079. e (if (eq org-agenda-fontify-priorities 'cookies)
  3080. (match-end 0)
  3081. (point-at-eol))
  3082. ov (make-overlay b e))
  3083. (overlay-put
  3084. ov 'face
  3085. (cond ((org-face-from-face-or-color
  3086. 'priority nil
  3087. (cdr (assoc p org-priority-faces))))
  3088. ((and (listp org-agenda-fontify-priorities)
  3089. (org-face-from-face-or-color
  3090. 'priority nil
  3091. (cdr (assoc p org-agenda-fontify-priorities)))))
  3092. ((equal p l) 'italic)
  3093. ((equal p h) 'bold)))
  3094. (overlay-put ov 'org-type 'org-priority)))))
  3095. (defun org-agenda-dim-blocked-tasks ()
  3096. "Dim currently blocked TODO's in the agenda display."
  3097. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3098. (delete-overlay o)))
  3099. (overlays-in (point-min) (point-max)))
  3100. (save-excursion
  3101. (let ((inhibit-read-only t)
  3102. (org-depend-tag-blocked nil)
  3103. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3104. org-blocked-by-checkboxes
  3105. invis1 b e p ov h l)
  3106. (goto-char (point-min))
  3107. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3108. (and pos (goto-char (1+ pos))))
  3109. (setq org-blocked-by-checkboxes nil invis1 invis)
  3110. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3111. (when (and marker
  3112. (with-current-buffer (marker-buffer marker)
  3113. (save-excursion (goto-char marker)
  3114. (org-entry-blocked-p))))
  3115. (if org-blocked-by-checkboxes (setq invis1 nil))
  3116. (setq b (if invis1
  3117. (max (point-min) (1- (point-at-bol)))
  3118. (point-at-bol))
  3119. e (point-at-eol)
  3120. ov (make-overlay b e))
  3121. (if invis1
  3122. (overlay-put ov 'invisible t)
  3123. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3124. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3125. (defvar org-agenda-skip-function nil
  3126. "Function to be called at each match during agenda construction.
  3127. If this function returns nil, the current match should not be skipped.
  3128. Otherwise, the function must return a position from where the search
  3129. should be continued.
  3130. This may also be a Lisp form, it will be evaluated.
  3131. Never set this variable using `setq' or so, because then it will apply
  3132. to all future agenda commands. If you do want a global skipping condition,
  3133. use the option `org-agenda-skip-function-global' instead.
  3134. The correct usage for `org-agenda-skip-function' is to bind it with
  3135. `let' to scope it dynamically into the agenda-constructing command.
  3136. A good way to set it is through options in `org-agenda-custom-commands'.")
  3137. (defun org-agenda-skip ()
  3138. "Throw to `:skip' in places that should be skipped.
  3139. Also moves point to the end of the skipped region, so that search can
  3140. continue from there."
  3141. (let ((p (point-at-bol)) to)
  3142. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3143. (get-text-property p :org-archived)
  3144. (org-end-of-subtree t)
  3145. (throw :skip t))
  3146. (and org-agenda-skip-comment-trees
  3147. (get-text-property p :org-comment)
  3148. (org-end-of-subtree t)
  3149. (throw :skip t))
  3150. (if (equal (char-after p) ?#) (throw :skip t))
  3151. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3152. (org-agenda-skip-eval org-agenda-skip-function)))
  3153. (goto-char to)
  3154. (throw :skip t))))
  3155. (defun org-agenda-skip-eval (form)
  3156. "If FORM is a function or a list, call (or eval) is and return result.
  3157. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3158. and match data are returned to the previous state no matter what these
  3159. functions do."
  3160. (let (fp)
  3161. (and form
  3162. (or (setq fp (functionp form))
  3163. (consp form))
  3164. (save-excursion
  3165. (save-match-data
  3166. (if fp
  3167. (funcall form)
  3168. (eval form)))))))
  3169. (defvar org-agenda-markers nil
  3170. "List of all currently active markers created by `org-agenda'.")
  3171. (defvar org-agenda-last-marker-time (org-float-time)
  3172. "Creation time of the last agenda marker.")
  3173. (defun org-agenda-new-marker (&optional pos)
  3174. "Return a new agenda marker.
  3175. Org-mode keeps a list of these markers and resets them when they are
  3176. no longer in use."
  3177. (let ((m (copy-marker (or pos (point)))))
  3178. (setq org-agenda-last-marker-time (org-float-time))
  3179. (if org-agenda-buffer
  3180. (with-current-buffer org-agenda-buffer
  3181. (push m org-agenda-markers))
  3182. (push m org-agenda-markers))
  3183. m))
  3184. (defun org-agenda-reset-markers ()
  3185. "Reset markers created by `org-agenda'."
  3186. (while org-agenda-markers
  3187. (move-marker (pop org-agenda-markers) nil)))
  3188. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3189. "Save relative positions of markers in region.
  3190. This check for agenda markers in all agenda buffers currently active."
  3191. (dolist (buf (buffer-list))
  3192. (with-current-buffer buf
  3193. (when (eq major-mode 'org-agenda-mode)
  3194. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3195. org-agenda-markers)))))
  3196. ;;; Entry text mode
  3197. (defun org-agenda-entry-text-show-here ()
  3198. "Add some text from the entry as context to the current line."
  3199. (let (m txt o)
  3200. (setq m (org-get-at-bol 'org-hd-marker))
  3201. (unless (marker-buffer m)
  3202. (error "No marker points to an entry here"))
  3203. (setq txt (concat "\n" (org-no-properties
  3204. (org-agenda-get-some-entry-text
  3205. m org-agenda-entry-text-maxlines " > "))))
  3206. (when (string-match "\\S-" txt)
  3207. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3208. (overlay-put o 'evaporate t)
  3209. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3210. (overlay-put o 'after-string txt))))
  3211. (defun org-agenda-entry-text-show ()
  3212. "Add entry context for all agenda lines."
  3213. (interactive)
  3214. (save-excursion
  3215. (goto-char (point-max))
  3216. (beginning-of-line 1)
  3217. (while (not (bobp))
  3218. (when (org-get-at-bol 'org-hd-marker)
  3219. (org-agenda-entry-text-show-here))
  3220. (beginning-of-line 0))))
  3221. (defun org-agenda-entry-text-hide ()
  3222. "Remove any shown entry context."
  3223. (delq nil
  3224. (mapcar (lambda (o)
  3225. (if (eq (overlay-get o 'org-overlay-type)
  3226. 'agenda-entry-content)
  3227. (progn (delete-overlay o) t)))
  3228. (overlays-in (point-min) (point-max)))))
  3229. (defun org-agenda-get-day-face (date)
  3230. "Return the face DATE should be displayed with."
  3231. (or (and (functionp org-agenda-day-face-function)
  3232. (funcall org-agenda-day-face-function date))
  3233. (cond ((org-agenda-todayp date)
  3234. 'org-agenda-date-today)
  3235. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3236. 'org-agenda-date-weekend)
  3237. (t 'org-agenda-date))))
  3238. ;;; Agenda timeline
  3239. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3240. (defun org-timeline (&optional dotodo)
  3241. "Show a time-sorted view of the entries in the current org file.
  3242. Only entries with a time stamp of today or later will be listed. With
  3243. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3244. under the current date.
  3245. If the buffer contains an active region, only check the region for
  3246. dates."
  3247. (interactive "P")
  3248. (let* ((dopast t)
  3249. (org-agenda-show-log-scoped org-agenda-show-log)
  3250. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3251. (current-buffer))))
  3252. (date (calendar-current-date))
  3253. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3254. (end (if (org-region-active-p) (region-end) (point-max)))
  3255. (day-numbers (org-get-all-dates
  3256. beg end 'no-ranges
  3257. t org-agenda-show-log-scoped ; always include today
  3258. org-timeline-show-empty-dates))
  3259. (org-deadline-warning-days 0)
  3260. (org-agenda-only-exact-dates t)
  3261. (today (org-today))
  3262. (past t)
  3263. args
  3264. s e rtn d emptyp)
  3265. (setq org-agenda-redo-command
  3266. (list 'progn
  3267. (list 'org-switch-to-buffer-other-window (current-buffer))
  3268. (list 'org-timeline (list 'quote dotodo))))
  3269. (if (not dopast)
  3270. ;; Remove past dates from the list of dates.
  3271. (setq day-numbers (delq nil (mapcar (lambda(x)
  3272. (if (>= x today) x nil))
  3273. day-numbers))))
  3274. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3275. (org-compile-prefix-format 'timeline)
  3276. (org-set-sorting-strategy 'timeline)
  3277. (if org-agenda-show-log-scoped (push :closed args))
  3278. (push :timestamp args)
  3279. (push :deadline args)
  3280. (push :scheduled args)
  3281. (push :sexp args)
  3282. (if dotodo (push :todo args))
  3283. (insert "Timeline of file " entry "\n")
  3284. (add-text-properties (point-min) (point)
  3285. (list 'face 'org-agenda-structure))
  3286. (org-agenda-mark-header-line (point-min))
  3287. (while (setq d (pop day-numbers))
  3288. (if (and (listp d) (eq (car d) :omitted))
  3289. (progn
  3290. (setq s (point))
  3291. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3292. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3293. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3294. (if (and (>= d today)
  3295. dopast
  3296. past)
  3297. (progn
  3298. (setq past nil)
  3299. (insert (make-string 79 ?-) "\n")))
  3300. (setq date (calendar-gregorian-from-absolute d))
  3301. (setq s (point))
  3302. (setq rtn (and (not emptyp)
  3303. (apply 'org-agenda-get-day-entries entry
  3304. date args)))
  3305. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3306. (progn
  3307. (insert
  3308. (if (stringp org-agenda-format-date)
  3309. (format-time-string org-agenda-format-date
  3310. (org-time-from-absolute date))
  3311. (funcall org-agenda-format-date date))
  3312. "\n")
  3313. (put-text-property s (1- (point)) 'face
  3314. (org-agenda-get-day-face date))
  3315. (put-text-property s (1- (point)) 'org-date-line t)
  3316. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3317. (if (equal d today)
  3318. (put-text-property s (1- (point)) 'org-today t))
  3319. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3320. (put-text-property s (1- (point)) 'day d)))))
  3321. (goto-char (point-min))
  3322. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3323. (point-min)))
  3324. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3325. (org-finalize-agenda)
  3326. (setq buffer-read-only t)))
  3327. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3328. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3329. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3330. not every single day in the range. If FORCE-TODAY is non-nil, make
  3331. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3332. inactive time stamps (those in square brackets) are included.
  3333. When EMPTY is non-nil, also include days without any entries."
  3334. (let ((re (concat
  3335. (if pre-re pre-re "")
  3336. (if inactive org-ts-regexp-both org-ts-regexp)))
  3337. dates dates1 date day day1 day2 ts1 ts2 pos)
  3338. (if force-today
  3339. (setq dates (list (org-today))))
  3340. (save-excursion
  3341. (goto-char beg)
  3342. (while (re-search-forward re end t)
  3343. (setq day (time-to-days (org-time-string-to-time
  3344. (substring (match-string 1) 0 10)
  3345. (current-buffer) (match-beginning 0))))
  3346. (or (memq day dates) (push day dates)))
  3347. (unless no-ranges
  3348. (goto-char beg)
  3349. (while (re-search-forward org-tr-regexp end t)
  3350. (setq pos (match-beginning 0))
  3351. (setq ts1 (substring (match-string 1) 0 10)
  3352. ts2 (substring (match-string 2) 0 10)
  3353. day1 (time-to-days (org-time-string-to-time
  3354. ts1 (current-buffer) pos))
  3355. day2 (time-to-days (org-time-string-to-time
  3356. ts2 (current-buffer) pos)))
  3357. (while (< (setq day1 (1+ day1)) day2)
  3358. (or (memq day1 dates) (push day1 dates)))))
  3359. (setq dates (sort dates '<))
  3360. (when empty
  3361. (while (setq day (pop dates))
  3362. (setq day2 (car dates))
  3363. (push day dates1)
  3364. (when (and day2 empty)
  3365. (if (or (eq empty t)
  3366. (and (numberp empty) (<= (- day2 day) empty)))
  3367. (while (< (setq day (1+ day)) day2)
  3368. (push (list day) dates1))
  3369. (push (cons :omitted (- day2 day)) dates1))))
  3370. (setq dates (nreverse dates1)))
  3371. dates)))
  3372. ;;; Agenda Daily/Weekly
  3373. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3374. "Start day for the agenda view.
  3375. Custom commands can set this variable in the options section.")
  3376. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3377. (defvar org-agenda-current-span nil
  3378. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3379. (defvar org-arg-loc nil) ; local variable
  3380. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3381. "List of types searched for when creating the daily/weekly agenda.
  3382. This variable is a list of symbols that controls the types of
  3383. items that appear in the daily/weekly agenda. Allowed symbols in this
  3384. list are are
  3385. :timestamp List items containing a date stamp or date range matching
  3386. the selected date. This includes sexp entries in
  3387. angular brackets.
  3388. :sexp List entries resulting from plain diary-like sexps.
  3389. :deadline List deadline due on that date. When the date is today,
  3390. also list any deadlines past due, or due within
  3391. `org-deadline-warning-days'. `:deadline' must appear before
  3392. `:scheduled' if the setting of
  3393. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3394. any effect.
  3395. :scheduled List all items which are scheduled for the given date.
  3396. The diary for *today* also contains items which were
  3397. scheduled earlier and are not yet marked DONE.
  3398. By default, all four types are turned on.
  3399. Never set this variable globally using `setq', because then it
  3400. will apply to all future agenda commands. Instead, bind it with
  3401. `let' to scope it dynamically into the agenda-constructing
  3402. command. A good way to set it is through options in
  3403. `org-agenda-custom-commands'. For a more flexible (though
  3404. somewhat less efficient) way of determining what is included in
  3405. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3406. ;;;###autoload
  3407. (defun org-agenda-list (&optional arg start-day span)
  3408. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3409. The view will be for the current day or week, but from the overview buffer
  3410. you will be able to go to other days/weeks.
  3411. With a numeric prefix argument in an interactive call, the agenda will
  3412. span ARG days. Lisp programs should instead specify SPAN to change
  3413. the number of days. SPAN defaults to `org-agenda-span'.
  3414. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3415. given in `org-agenda-start-on-weekday'."
  3416. (interactive "P")
  3417. (if (and (integerp arg) (> arg 0))
  3418. (setq span arg arg nil))
  3419. (org-prepare-agenda "Day/Week")
  3420. (setq start-day (or start-day org-agenda-start-day))
  3421. (if org-agenda-overriding-arguments
  3422. (setq arg (car org-agenda-overriding-arguments)
  3423. start-day (nth 1 org-agenda-overriding-arguments)
  3424. span (nth 2 org-agenda-overriding-arguments)))
  3425. (if (stringp start-day)
  3426. ;; Convert to an absolute day number
  3427. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3428. (setq org-agenda-last-arguments (list arg start-day span))
  3429. (org-compile-prefix-format 'agenda)
  3430. (org-set-sorting-strategy 'agenda)
  3431. (let* ((span (org-agenda-ndays-to-span
  3432. (or span org-agenda-ndays org-agenda-span)))
  3433. (today (org-today))
  3434. (sd (or start-day today))
  3435. (ndays (org-agenda-span-to-ndays span sd))
  3436. (org-agenda-start-on-weekday
  3437. (if (eq ndays 7)
  3438. org-agenda-start-on-weekday))
  3439. (thefiles (org-agenda-files nil 'ifmode))
  3440. (files thefiles)
  3441. (start (if (or (null org-agenda-start-on-weekday)
  3442. (< ndays 7))
  3443. sd
  3444. (let* ((nt (calendar-day-of-week
  3445. (calendar-gregorian-from-absolute sd)))
  3446. (n1 org-agenda-start-on-weekday)
  3447. (d (- nt n1)))
  3448. (- sd (+ (if (< d 0) 7 0) d)))))
  3449. (day-numbers (list start))
  3450. (day-cnt 0)
  3451. (inhibit-redisplay (not debug-on-error))
  3452. (org-agenda-show-log-scoped org-agenda-show-log)
  3453. s e rtn rtnall file date d start-pos end-pos todayp
  3454. clocktable-start clocktable-end filter)
  3455. (setq org-agenda-redo-command
  3456. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3457. (dotimes (n (1- ndays))
  3458. (push (1+ (car day-numbers)) day-numbers))
  3459. (setq day-numbers (nreverse day-numbers))
  3460. (setq clocktable-start (car day-numbers)
  3461. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3462. (org-set-local 'org-starting-day (car day-numbers))
  3463. (org-set-local 'org-arg-loc arg)
  3464. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3465. (unless org-agenda-compact-blocks
  3466. (let* ((d1 (car day-numbers))
  3467. (d2 (org-last day-numbers))
  3468. (w1 (org-days-to-iso-week d1))
  3469. (w2 (org-days-to-iso-week d2)))
  3470. (setq s (point))
  3471. (if org-agenda-overriding-header
  3472. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3473. nil 'face 'org-agenda-structure) "\n")
  3474. (insert (org-agenda-span-name span)
  3475. "-agenda"
  3476. (if (< (- d2 d1) 350)
  3477. (if (= w1 w2)
  3478. (format " (W%02d)" w1)
  3479. (format " (W%02d-W%02d)" w1 w2))
  3480. "")
  3481. ":\n")))
  3482. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3483. 'org-date-line t))
  3484. (org-agenda-mark-header-line s))
  3485. (while (setq d (pop day-numbers))
  3486. (setq date (calendar-gregorian-from-absolute d)
  3487. s (point))
  3488. (if (or (setq todayp (= d today))
  3489. (and (not start-pos) (= d sd)))
  3490. (setq start-pos (point))
  3491. (if (and start-pos (not end-pos))
  3492. (setq end-pos (point))))
  3493. (setq files thefiles
  3494. rtnall nil)
  3495. (while (setq file (pop files))
  3496. (catch 'nextfile
  3497. (org-check-agenda-file file)
  3498. (let ((org-agenda-entry-types org-agenda-entry-types))
  3499. (unless org-agenda-include-deadlines
  3500. (setq org-agenda-entry-types
  3501. (delq :deadline org-agenda-entry-types)))
  3502. (cond
  3503. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3504. (setq rtn (org-agenda-get-day-entries
  3505. file date :closed)))
  3506. (org-agenda-show-log-scoped
  3507. (setq rtn (apply 'org-agenda-get-day-entries
  3508. file date
  3509. (append '(:closed) org-agenda-entry-types))))
  3510. (t
  3511. (setq rtn (apply 'org-agenda-get-day-entries
  3512. file date
  3513. org-agenda-entry-types)))))
  3514. (setq rtnall (append rtnall rtn)))) ;; all entries
  3515. (if org-agenda-include-diary
  3516. (let ((org-agenda-search-headline-for-time t))
  3517. (require 'diary-lib)
  3518. (setq rtn (org-get-entries-from-diary date))
  3519. (setq rtnall (append rtnall rtn))))
  3520. (if (or rtnall org-agenda-show-all-dates)
  3521. (progn
  3522. (setq day-cnt (1+ day-cnt))
  3523. (insert
  3524. (if (stringp org-agenda-format-date)
  3525. (format-time-string org-agenda-format-date
  3526. (org-time-from-absolute date))
  3527. (funcall org-agenda-format-date date))
  3528. "\n")
  3529. (put-text-property s (1- (point)) 'face
  3530. (org-agenda-get-day-face date))
  3531. (put-text-property s (1- (point)) 'org-date-line t)
  3532. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3533. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3534. (when todayp
  3535. (put-text-property s (1- (point)) 'org-today t))
  3536. (if rtnall (insert ;; all entries
  3537. (org-finalize-agenda-entries
  3538. (org-agenda-add-time-grid-maybe
  3539. rtnall ndays todayp))
  3540. "\n"))
  3541. (put-text-property s (1- (point)) 'day d)
  3542. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3543. (when (and org-agenda-clockreport-mode clocktable-start)
  3544. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3545. ;; the above line is to ensure the restricted range!
  3546. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3547. tbl)
  3548. (setq p (org-plist-delete p :block))
  3549. (setq p (plist-put p :tstart clocktable-start))
  3550. (setq p (plist-put p :tend clocktable-end))
  3551. (setq p (plist-put p :scope 'agenda))
  3552. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3553. (setq filter (or org-agenda-tag-filter-while-redo
  3554. (get 'org-agenda-tag-filter :preset-filter))))
  3555. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3556. (if (string-match "[<>=]" x)
  3557. ""
  3558. x))
  3559. filter ""))))
  3560. (setq tbl (apply 'org-get-clocktable p))
  3561. (insert tbl)))
  3562. (goto-char (point-min))
  3563. (or org-agenda-multi (org-fit-agenda-window))
  3564. (unless (and (pos-visible-in-window-p (point-min))
  3565. (pos-visible-in-window-p (point-max)))
  3566. (goto-char (1- (point-max)))
  3567. (recenter -1)
  3568. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3569. (progn
  3570. (goto-char (or start-pos 1))
  3571. (recenter 1))))
  3572. (goto-char (or start-pos 1))
  3573. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3574. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3575. (org-agenda-show-clocking-issues))
  3576. (org-finalize-agenda)
  3577. (setq buffer-read-only t)
  3578. (message "")))
  3579. (defun org-agenda-ndays-to-span (n)
  3580. "Return a span symbol for a span of N days, or N if none matches."
  3581. (cond ((symbolp n) n)
  3582. ((= n 1) 'day)
  3583. ((= n 7) 'week)
  3584. (t n)))
  3585. (defun org-agenda-span-to-ndays (span start-day)
  3586. "Return ndays from SPAN starting at START-DAY."
  3587. (cond ((numberp span) span)
  3588. ((eq span 'day) 1)
  3589. ((eq span 'week) 7)
  3590. ((eq span 'month)
  3591. (let ((date (calendar-gregorian-from-absolute start-day)))
  3592. (calendar-last-day-of-month (car date) (caddr date))))
  3593. ((eq span 'year)
  3594. (let ((date (calendar-gregorian-from-absolute start-day)))
  3595. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3596. (defun org-agenda-span-name (span)
  3597. "Return a SPAN name."
  3598. (if (null span)
  3599. ""
  3600. (if (symbolp span)
  3601. (capitalize (symbol-name span))
  3602. (format "%d days" span))))
  3603. ;;; Agenda word search
  3604. (defvar org-agenda-search-history nil)
  3605. (defvar org-todo-only nil)
  3606. (defvar org-search-syntax-table nil
  3607. "Special syntax table for org-mode search.
  3608. In this table, we have single quotes not as word constituents, to
  3609. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3610. (defun org-search-syntax-table ()
  3611. (unless org-search-syntax-table
  3612. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3613. (modify-syntax-entry ?' "." org-search-syntax-table)
  3614. (modify-syntax-entry ?` "." org-search-syntax-table))
  3615. org-search-syntax-table)
  3616. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3617. ;;;###autoload
  3618. (defun org-search-view (&optional todo-only string edit-at)
  3619. "Show all entries that contain a phrase or words or regular expressions.
  3620. With optional prefix argument TODO-ONLY, only consider entries that are
  3621. TODO entries. The argument STRING can be used to pass a default search
  3622. string into this function. If EDIT-AT is non-nil, it means that the
  3623. user should get a chance to edit this string, with cursor at position
  3624. EDIT-AT.
  3625. The search string can be viewed either as a phrase that should be found as
  3626. is, or it can be broken into a number of snippets, each of which must match
  3627. in a Boolean way to select an entry. The default depends on the variable
  3628. `org-agenda-search-view-always-boolean'.
  3629. Even if this is turned off (the default) you can always switch to
  3630. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3631. The default is a direct search of the whole phrase, where each space in
  3632. the search string can expand to an arbitrary amount of whitespace,
  3633. including newlines.
  3634. If using a Boolean search, the search string is split on whitespace and
  3635. each snippet is searched separately, with logical AND to select an entry.
  3636. Words prefixed with a minus must *not* occur in the entry. Words without
  3637. a prefix or prefixed with a plus must occur in the entry. Matching is
  3638. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3639. match whole words, not parts of a word) if
  3640. `org-agenda-search-view-force-full-words' is set (default is nil).
  3641. Boolean search snippets enclosed by curly braces are interpreted as
  3642. regular expressions that must or (when preceded with \"-\") must not
  3643. match in the entry. Snippets enclosed into double quotes will be taken
  3644. as a whole, to include whitespace.
  3645. - If the search string starts with an asterisk, search only in headlines.
  3646. - If (possibly after the leading star) the search string starts with an
  3647. exclamation mark, this also means to look at TODO entries only, an effect
  3648. that can also be achieved with a prefix argument.
  3649. - If (possibly after star and exclamation mark) the search string starts
  3650. with a colon, this will mean that the (non-regexp) snippets of the
  3651. Boolean search must match as full words.
  3652. This command searches the agenda files, and in addition the files listed
  3653. in `org-agenda-text-search-extra-files'."
  3654. (interactive "P")
  3655. (org-prepare-agenda "SEARCH")
  3656. (org-compile-prefix-format 'search)
  3657. (org-set-sorting-strategy 'search)
  3658. (let* ((props (list 'face nil
  3659. 'done-face 'org-agenda-done
  3660. 'org-not-done-regexp org-not-done-regexp
  3661. 'org-todo-regexp org-todo-regexp
  3662. 'org-complex-heading-regexp org-complex-heading-regexp
  3663. 'mouse-face 'highlight
  3664. 'help-echo (format "mouse-2 or RET jump to location")))
  3665. (full-words org-agenda-search-view-force-full-words)
  3666. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3667. regexp rtn rtnall files file pos
  3668. marker category org-category-pos tags c neg re boolean
  3669. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3670. (unless (and (not edit-at)
  3671. (stringp string)
  3672. (string-match "\\S-" string))
  3673. (setq string (read-string
  3674. (if org-agenda-search-view-always-boolean
  3675. "[+-]Word/{Regexp} ...: "
  3676. "Phrase, or [+-]Word/{Regexp} ...: ")
  3677. (cond
  3678. ((integerp edit-at) (cons string edit-at))
  3679. (edit-at string))
  3680. 'org-agenda-search-history)))
  3681. (org-set-local 'org-todo-only todo-only)
  3682. (setq org-agenda-redo-command
  3683. (list 'org-search-view (if todo-only t nil) string
  3684. '(if current-prefix-arg 1 nil)))
  3685. (setq org-agenda-query-string string)
  3686. (if (equal (string-to-char string) ?*)
  3687. (setq hdl-only t
  3688. words (substring string 1))
  3689. (setq words string))
  3690. (when (equal (string-to-char words) ?!)
  3691. (setq todo-only t
  3692. words (substring words 1)))
  3693. (when (equal (string-to-char words) ?:)
  3694. (setq full-words t
  3695. words (substring words 1)))
  3696. (if (or org-agenda-search-view-always-boolean
  3697. (member (string-to-char words) '(?- ?+ ?\{)))
  3698. (setq boolean t))
  3699. (setq words (org-split-string words))
  3700. (let (www w)
  3701. (while (setq w (pop words))
  3702. (while (and (string-match "\\\\\\'" w) words)
  3703. (setq w (concat (substring w 0 -1) " " (pop words))))
  3704. (push w www))
  3705. (setq words (nreverse www) www nil)
  3706. (while (setq w (pop words))
  3707. (when (and (string-match "\\`[-+]?{" w)
  3708. (not (string-match "}\\'" w)))
  3709. (while (and words (not (string-match "}\\'" (car words))))
  3710. (setq w (concat w " " (pop words))))
  3711. (setq w (concat w " " (pop words))))
  3712. (push w www))
  3713. (setq words (nreverse www)))
  3714. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3715. (when boolean
  3716. (let (wds w)
  3717. (while (setq w (pop words))
  3718. (if (or (equal (substring w 0 1) "\"")
  3719. (and (> (length w) 1)
  3720. (member (substring w 0 1) '("+" "-"))
  3721. (equal (substring w 1 2) "\"")))
  3722. (while (and words (not (equal (substring w -1) "\"")))
  3723. (setq w (concat w " " (pop words)))))
  3724. (and (string-match "\\`\\([-+]?\\)\"" w)
  3725. (setq w (replace-match "\\1" nil nil w)))
  3726. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3727. (push w wds))
  3728. (setq words (nreverse wds))))
  3729. (if boolean
  3730. (mapc (lambda (w)
  3731. (setq c (string-to-char w))
  3732. (if (equal c ?-)
  3733. (setq neg t w (substring w 1))
  3734. (if (equal c ?+)
  3735. (setq neg nil w (substring w 1))
  3736. (setq neg nil)))
  3737. (if (string-match "\\`{.*}\\'" w)
  3738. (setq re (substring w 1 -1))
  3739. (if full-words
  3740. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3741. (setq re (regexp-quote (downcase w)))))
  3742. (if neg (push re regexps-) (push re regexps+)))
  3743. words)
  3744. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3745. regexps+))
  3746. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3747. (if (not regexps+)
  3748. (setq regexp org-outline-regexp-bol)
  3749. (setq regexp (pop regexps+))
  3750. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3751. regexp))))
  3752. (setq files (org-agenda-files nil 'ifmode))
  3753. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3754. (pop org-agenda-text-search-extra-files)
  3755. (setq files (org-add-archive-files files)))
  3756. (setq files (append files org-agenda-text-search-extra-files)
  3757. rtnall nil)
  3758. (while (setq file (pop files))
  3759. (setq ee nil)
  3760. (catch 'nextfile
  3761. (org-check-agenda-file file)
  3762. (setq buffer (if (file-exists-p file)
  3763. (org-get-agenda-file-buffer file)
  3764. (error "No such file %s" file)))
  3765. (if (not buffer)
  3766. ;; If file does not exist, make sure an error message is sent
  3767. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3768. file))))
  3769. (with-current-buffer buffer
  3770. (with-syntax-table (org-search-syntax-table)
  3771. (unless (derived-mode-p 'org-mode)
  3772. (error "Agenda file %s is not in `org-mode'" file))
  3773. (let ((case-fold-search t))
  3774. (save-excursion
  3775. (save-restriction
  3776. (if org-agenda-restrict
  3777. (narrow-to-region org-agenda-restrict-begin
  3778. org-agenda-restrict-end)
  3779. (widen))
  3780. (goto-char (point-min))
  3781. (unless (or (org-at-heading-p)
  3782. (outline-next-heading))
  3783. (throw 'nextfile t))
  3784. (goto-char (max (point-min) (1- (point))))
  3785. (while (re-search-forward regexp nil t)
  3786. (org-back-to-heading t)
  3787. (skip-chars-forward "* ")
  3788. (setq beg (point-at-bol)
  3789. beg1 (point)
  3790. end (progn (outline-next-heading) (point)))
  3791. (catch :skip
  3792. (goto-char beg)
  3793. (org-agenda-skip)
  3794. (setq str (buffer-substring-no-properties
  3795. (point-at-bol)
  3796. (if hdl-only (point-at-eol) end)))
  3797. (mapc (lambda (wr) (when (string-match wr str)
  3798. (goto-char (1- end))
  3799. (throw :skip t)))
  3800. regexps-)
  3801. (mapc (lambda (wr) (unless (string-match wr str)
  3802. (goto-char (1- end))
  3803. (throw :skip t)))
  3804. (if todo-only
  3805. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3806. regexps+)
  3807. regexps+))
  3808. (goto-char beg)
  3809. (setq marker (org-agenda-new-marker (point))
  3810. category (org-get-category)
  3811. org-category-pos (get-text-property (point) 'org-category-position)
  3812. tags (org-get-tags-at (point))
  3813. txt (org-agenda-format-item
  3814. ""
  3815. (buffer-substring-no-properties
  3816. beg1 (point-at-eol))
  3817. category tags))
  3818. (org-add-props txt props
  3819. 'org-marker marker 'org-hd-marker marker
  3820. 'org-todo-regexp org-todo-regexp
  3821. 'org-complex-heading-regexp org-complex-heading-regexp
  3822. 'priority 1000 'org-category category
  3823. 'org-category-position org-category-pos
  3824. 'type "search")
  3825. (push txt ee)
  3826. (goto-char (1- end))))))))))
  3827. (setq rtn (nreverse ee))
  3828. (setq rtnall (append rtnall rtn)))
  3829. (if org-agenda-overriding-header
  3830. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3831. nil 'face 'org-agenda-structure) "\n")
  3832. (insert "Search words: ")
  3833. (add-text-properties (point-min) (1- (point))
  3834. (list 'face 'org-agenda-structure))
  3835. (setq pos (point))
  3836. (insert string "\n")
  3837. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3838. (setq pos (point))
  3839. (unless org-agenda-multi
  3840. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3841. (add-text-properties pos (1- (point))
  3842. (list 'face 'org-agenda-structure))))
  3843. (org-agenda-mark-header-line (point-min))
  3844. (when rtnall
  3845. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3846. (goto-char (point-min))
  3847. (or org-agenda-multi (org-fit-agenda-window))
  3848. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3849. (org-finalize-agenda)
  3850. (setq buffer-read-only t)))
  3851. ;;; Agenda TODO list
  3852. (defvar org-select-this-todo-keyword nil)
  3853. (defvar org-last-arg nil)
  3854. ;;;###autoload
  3855. (defun org-todo-list (arg)
  3856. "Show all (not done) TODO entries from all agenda file in a single list.
  3857. The prefix arg can be used to select a specific TODO keyword and limit
  3858. the list to these. When using \\[universal-argument], you will be prompted
  3859. for a keyword. A numeric prefix directly selects the Nth keyword in
  3860. `org-todo-keywords-1'."
  3861. (interactive "P")
  3862. (org-prepare-agenda "TODO")
  3863. (org-compile-prefix-format 'todo)
  3864. (org-set-sorting-strategy 'todo)
  3865. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3866. (let* ((today (org-today))
  3867. (date (calendar-gregorian-from-absolute today))
  3868. (kwds org-todo-keywords-for-agenda)
  3869. (completion-ignore-case t)
  3870. (org-select-this-todo-keyword
  3871. (if (stringp arg) arg
  3872. (and arg (integerp arg) (> arg 0)
  3873. (nth (1- arg) kwds))))
  3874. rtn rtnall files file pos)
  3875. (when (equal arg '(4))
  3876. (setq org-select-this-todo-keyword
  3877. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3878. (mapcar 'list kwds) nil nil)))
  3879. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3880. (org-set-local 'org-last-arg arg)
  3881. (setq org-agenda-redo-command
  3882. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3883. (setq files (org-agenda-files nil 'ifmode)
  3884. rtnall nil)
  3885. (while (setq file (pop files))
  3886. (catch 'nextfile
  3887. (org-check-agenda-file file)
  3888. (setq rtn (org-agenda-get-day-entries file date :todo))
  3889. (setq rtnall (append rtnall rtn))))
  3890. (if org-agenda-overriding-header
  3891. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3892. nil 'face 'org-agenda-structure) "\n")
  3893. (insert "Global list of TODO items of type: ")
  3894. (add-text-properties (point-min) (1- (point))
  3895. (list 'face 'org-agenda-structure
  3896. 'short-heading
  3897. (concat "ToDo: "
  3898. (or org-select-this-todo-keyword "ALL"))))
  3899. (org-agenda-mark-header-line (point-min))
  3900. (setq pos (point))
  3901. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3902. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3903. (setq pos (point))
  3904. (unless org-agenda-multi
  3905. (insert "Available with `N r': (0)ALL")
  3906. (let ((n 0) s)
  3907. (mapc (lambda (x)
  3908. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3909. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3910. (insert "\n "))
  3911. (insert " " s))
  3912. kwds))
  3913. (insert "\n"))
  3914. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3915. (org-agenda-mark-header-line (point-min))
  3916. (when rtnall
  3917. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3918. (goto-char (point-min))
  3919. (or org-agenda-multi (org-fit-agenda-window))
  3920. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3921. (org-finalize-agenda)
  3922. (setq buffer-read-only t)))
  3923. ;;; Agenda tags match
  3924. ;;;###autoload
  3925. (defun org-tags-view (&optional todo-only match)
  3926. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3927. The prefix arg TODO-ONLY limits the search to TODO entries."
  3928. (interactive "P")
  3929. (let* ((org-tags-match-list-sublevels
  3930. org-tags-match-list-sublevels)
  3931. (completion-ignore-case t)
  3932. rtn rtnall files file pos matcher
  3933. buffer)
  3934. (when (and (stringp match) (not (string-match "\\S-" match)))
  3935. (setq match nil))
  3936. (setq matcher (org-make-tags-matcher match)
  3937. match (car matcher) matcher (cdr matcher))
  3938. (org-prepare-agenda (concat "TAGS " match))
  3939. (org-compile-prefix-format 'tags)
  3940. (org-set-sorting-strategy 'tags)
  3941. (setq org-agenda-query-string match)
  3942. (setq org-agenda-redo-command
  3943. (list 'org-tags-view (list 'quote todo-only)
  3944. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3945. (setq files (org-agenda-files nil 'ifmode)
  3946. rtnall nil)
  3947. (while (setq file (pop files))
  3948. (catch 'nextfile
  3949. (org-check-agenda-file file)
  3950. (setq buffer (if (file-exists-p file)
  3951. (org-get-agenda-file-buffer file)
  3952. (error "No such file %s" file)))
  3953. (if (not buffer)
  3954. ;; If file does not exist, error message to agenda
  3955. (setq rtn (list
  3956. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3957. rtnall (append rtnall rtn))
  3958. (with-current-buffer buffer
  3959. (unless (derived-mode-p 'org-mode)
  3960. (error "Agenda file %s is not in `org-mode'" file))
  3961. (save-excursion
  3962. (save-restriction
  3963. (if org-agenda-restrict
  3964. (narrow-to-region org-agenda-restrict-begin
  3965. org-agenda-restrict-end)
  3966. (widen))
  3967. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3968. (setq rtnall (append rtnall rtn))))))))
  3969. (if org-agenda-overriding-header
  3970. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3971. nil 'face 'org-agenda-structure) "\n")
  3972. (insert "Headlines with TAGS match: ")
  3973. (add-text-properties (point-min) (1- (point))
  3974. (list 'face 'org-agenda-structure
  3975. 'short-heading
  3976. (concat "Match: " match)))
  3977. (setq pos (point))
  3978. (insert match "\n")
  3979. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3980. (setq pos (point))
  3981. (unless org-agenda-multi
  3982. (insert "Press `C-u r' to search again with new search string\n"))
  3983. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3984. (org-agenda-mark-header-line (point-min))
  3985. (when rtnall
  3986. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3987. (goto-char (point-min))
  3988. (or org-agenda-multi (org-fit-agenda-window))
  3989. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3990. (org-finalize-agenda)
  3991. (setq buffer-read-only t)))
  3992. ;;; Agenda Finding stuck projects
  3993. (defvar org-agenda-skip-regexp nil
  3994. "Regular expression used in skipping subtrees for the agenda.
  3995. This is basically a temporary global variable that can be set and then
  3996. used by user-defined selections using `org-agenda-skip-function'.")
  3997. (defvar org-agenda-overriding-header nil
  3998. "When set during agenda, todo and tags searches it replaces the header.
  3999. This variable should not be set directly, but custom commands can bind it
  4000. in the options section.")
  4001. (defun org-agenda-skip-entry-when-regexp-matches ()
  4002. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4003. If yes, it returns the end position of this entry, causing agenda commands
  4004. to skip the entry but continuing the search in the subtree. This is a
  4005. function that can be put into `org-agenda-skip-function' for the duration
  4006. of a command."
  4007. (let ((end (save-excursion (org-end-of-subtree t)))
  4008. skip)
  4009. (save-excursion
  4010. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4011. (and skip end)))
  4012. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4013. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4014. If yes, it returns the end position of this tree, causing agenda commands
  4015. to skip this subtree. This is a function that can be put into
  4016. `org-agenda-skip-function' for the duration of a command."
  4017. (let ((end (save-excursion (org-end-of-subtree t)))
  4018. skip)
  4019. (save-excursion
  4020. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4021. (and skip end)))
  4022. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4023. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4024. If yes, it returns the end position of the current entry (NOT the tree),
  4025. causing agenda commands to skip the entry but continuing the search in
  4026. the subtree. This is a function that can be put into
  4027. `org-agenda-skip-function' for the duration of a command. An important
  4028. use of this function is for the stuck project list."
  4029. (let ((end (save-excursion (org-end-of-subtree t)))
  4030. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4031. skip)
  4032. (save-excursion
  4033. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4034. (and skip entry-end)))
  4035. (defun org-agenda-skip-entry-if (&rest conditions)
  4036. "Skip entry if any of CONDITIONS is true.
  4037. See `org-agenda-skip-if' for details."
  4038. (org-agenda-skip-if nil conditions))
  4039. (defun org-agenda-skip-subtree-if (&rest conditions)
  4040. "Skip entry if any of CONDITIONS is true.
  4041. See `org-agenda-skip-if' for details."
  4042. (org-agenda-skip-if t conditions))
  4043. (defun org-agenda-skip-if (subtree conditions)
  4044. "Checks current entity for CONDITIONS.
  4045. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4046. the entry (i.e. the text before the next heading) is checked.
  4047. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4048. from different tests. Valid conditions are:
  4049. scheduled Check if there is a scheduled cookie
  4050. notscheduled Check if there is no scheduled cookie
  4051. deadline Check if there is a deadline
  4052. notdeadline Check if there is no deadline
  4053. timestamp Check if there is a timestamp (also deadline or scheduled)
  4054. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4055. regexp Check if regexp matches
  4056. notregexp Check if regexp does not match.
  4057. todo Check if TODO keyword matches
  4058. nottodo Check if TODO keyword does not match
  4059. The regexp is taken from the conditions list, it must come right after
  4060. the `regexp' or `notregexp' element.
  4061. `todo' and `nottodo' accept as an argument a list of todo
  4062. keywords, which may include \"*\" to match any todo keyword.
  4063. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4064. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4065. Instead of a list, a keyword class may be given. For example:
  4066. (org-agenda-skip-entry-if 'nottodo 'done)
  4067. would skip entries that haven't been marked with any of \"DONE\"
  4068. keywords. Possible classes are: `todo', `done', `any'.
  4069. If any of these conditions is met, this function returns the end point of
  4070. the entity, causing the search to continue from there. This is a function
  4071. that can be put into `org-agenda-skip-function' for the duration of a command."
  4072. (let (beg end m)
  4073. (org-back-to-heading t)
  4074. (setq beg (point)
  4075. end (if subtree
  4076. (progn (org-end-of-subtree t) (point))
  4077. (progn (outline-next-heading) (1- (point)))))
  4078. (goto-char beg)
  4079. (and
  4080. (or
  4081. (and (memq 'scheduled conditions)
  4082. (re-search-forward org-scheduled-time-regexp end t))
  4083. (and (memq 'notscheduled conditions)
  4084. (not (re-search-forward org-scheduled-time-regexp end t)))
  4085. (and (memq 'deadline conditions)
  4086. (re-search-forward org-deadline-time-regexp end t))
  4087. (and (memq 'notdeadline conditions)
  4088. (not (re-search-forward org-deadline-time-regexp end t)))
  4089. (and (memq 'timestamp conditions)
  4090. (re-search-forward org-ts-regexp end t))
  4091. (and (memq 'nottimestamp conditions)
  4092. (not (re-search-forward org-ts-regexp end t)))
  4093. (and (setq m (memq 'regexp conditions))
  4094. (stringp (nth 1 m))
  4095. (re-search-forward (nth 1 m) end t))
  4096. (and (setq m (memq 'notregexp conditions))
  4097. (stringp (nth 1 m))
  4098. (not (re-search-forward (nth 1 m) end t)))
  4099. (and (or
  4100. (setq m (memq 'nottodo conditions))
  4101. (setq m (memq 'todo-unblocked conditions))
  4102. (setq m (memq 'nottodo-unblocked conditions))
  4103. (setq m (memq 'todo conditions)))
  4104. (org-agenda-skip-if-todo m end)))
  4105. end)))
  4106. (defun org-agenda-skip-if-todo (args end)
  4107. "Helper function for `org-agenda-skip-if', do not use it directly.
  4108. ARGS is a list with first element either `todo', `nottodo',
  4109. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4110. a list of TODO keywords, or a state symbol `todo' or `done' or
  4111. `any'."
  4112. (let ((kw (car args))
  4113. (arg (cadr args))
  4114. todo-wds todo-re)
  4115. (setq todo-wds
  4116. (org-uniquify
  4117. (cond
  4118. ((listp arg) ;; list of keywords
  4119. (if (member "*" arg)
  4120. (mapcar 'substring-no-properties org-todo-keywords-1)
  4121. arg))
  4122. ((symbolp arg) ;; keyword class name
  4123. (cond
  4124. ((eq arg 'todo)
  4125. (org-delete-all org-done-keywords
  4126. (mapcar 'substring-no-properties
  4127. org-todo-keywords-1)))
  4128. ((eq arg 'done) org-done-keywords)
  4129. ((eq arg 'any)
  4130. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4131. (setq todo-re
  4132. (concat "^\\*+[ \t]+\\<\\("
  4133. (mapconcat 'identity todo-wds "\\|")
  4134. "\\)\\>"))
  4135. (cond
  4136. ((eq kw 'todo) (re-search-forward todo-re end t))
  4137. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4138. ((eq kw 'todo-unblocked)
  4139. (catch 'unblocked
  4140. (while (re-search-forward todo-re end t)
  4141. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4142. nil))
  4143. ((eq kw 'nottodo-unblocked)
  4144. (catch 'unblocked
  4145. (while (re-search-forward todo-re end t)
  4146. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4147. t))
  4148. )))
  4149. ;;;###autoload
  4150. (defun org-agenda-list-stuck-projects (&rest ignore)
  4151. "Create agenda view for projects that are stuck.
  4152. Stuck projects are project that have no next actions. For the definitions
  4153. of what a project is and how to check if it stuck, customize the variable
  4154. `org-stuck-projects'."
  4155. (interactive)
  4156. (let* ((org-agenda-skip-function
  4157. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4158. ;; We could have used org-agenda-skip-if here.
  4159. (org-agenda-overriding-header
  4160. (or org-agenda-overriding-header "List of stuck projects: "))
  4161. (matcher (nth 0 org-stuck-projects))
  4162. (todo (nth 1 org-stuck-projects))
  4163. (todo-wds (if (member "*" todo)
  4164. (progn
  4165. (org-prepare-agenda-buffers (org-agenda-files
  4166. nil 'ifmode))
  4167. (org-delete-all
  4168. org-done-keywords-for-agenda
  4169. (copy-sequence org-todo-keywords-for-agenda)))
  4170. todo))
  4171. (todo-re (concat "^\\*+[ \t]+\\("
  4172. (mapconcat 'identity todo-wds "\\|")
  4173. "\\)\\>"))
  4174. (tags (nth 2 org-stuck-projects))
  4175. (tags-re (if (member "*" tags)
  4176. (concat org-outline-regexp-bol
  4177. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4178. (if tags
  4179. (concat org-outline-regexp-bol
  4180. ".*:\\("
  4181. (mapconcat 'identity tags "\\|")
  4182. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4183. (gen-re (nth 3 org-stuck-projects))
  4184. (re-list
  4185. (delq nil
  4186. (list
  4187. (if todo todo-re)
  4188. (if tags tags-re)
  4189. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4190. gen-re)))))
  4191. (setq org-agenda-skip-regexp
  4192. (if re-list
  4193. (mapconcat 'identity re-list "\\|")
  4194. (error "No information how to identify unstuck projects")))
  4195. (org-tags-view nil matcher)
  4196. (with-current-buffer org-agenda-buffer-name
  4197. (setq org-agenda-redo-command
  4198. '(org-agenda-list-stuck-projects
  4199. (or current-prefix-arg org-last-arg))))))
  4200. ;;; Diary integration
  4201. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4202. (defvar diary-list-entries-hook)
  4203. (defvar diary-time-regexp)
  4204. (defun org-get-entries-from-diary (date)
  4205. "Get the (Emacs Calendar) diary entries for DATE."
  4206. (require 'diary-lib)
  4207. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4208. (diary-display-hook '(fancy-diary-display))
  4209. (diary-display-function 'fancy-diary-display)
  4210. (pop-up-frames nil)
  4211. (diary-list-entries-hook
  4212. (cons 'org-diary-default-entry diary-list-entries-hook))
  4213. (diary-file-name-prefix-function nil) ; turn this feature off
  4214. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4215. entries
  4216. (org-disable-agenda-to-diary t))
  4217. (save-excursion
  4218. (save-window-excursion
  4219. (funcall (if (fboundp 'diary-list-entries)
  4220. 'diary-list-entries 'list-diary-entries)
  4221. date 1)))
  4222. (if (not (get-buffer diary-fancy-buffer))
  4223. (setq entries nil)
  4224. (with-current-buffer diary-fancy-buffer
  4225. (setq buffer-read-only nil)
  4226. (if (zerop (buffer-size))
  4227. ;; No entries
  4228. (setq entries nil)
  4229. ;; Omit the date and other unnecessary stuff
  4230. (org-agenda-cleanup-fancy-diary)
  4231. ;; Add prefix to each line and extend the text properties
  4232. (if (zerop (buffer-size))
  4233. (setq entries nil)
  4234. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4235. (setq entries
  4236. (with-temp-buffer
  4237. (insert entries) (goto-char (point-min))
  4238. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4239. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4240. (replace-match (concat "; " (match-string 1)))))
  4241. (buffer-string)))))
  4242. (set-buffer-modified-p nil)
  4243. (kill-buffer diary-fancy-buffer)))
  4244. (when entries
  4245. (setq entries (org-split-string entries "\n"))
  4246. (setq entries
  4247. (mapcar
  4248. (lambda (x)
  4249. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4250. ;; Extend the text properties to the beginning of the line
  4251. (org-add-props x (text-properties-at (1- (length x)) x)
  4252. 'type "diary" 'date date 'face 'org-agenda-diary))
  4253. entries)))))
  4254. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4255. "Hook run when the fancy diary buffer is cleaned up.")
  4256. (defun org-agenda-cleanup-fancy-diary ()
  4257. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4258. This gets rid of the date, the underline under the date, and
  4259. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4260. date. It also removes lines that contain only whitespace."
  4261. (goto-char (point-min))
  4262. (if (looking-at ".*?:[ \t]*")
  4263. (progn
  4264. (replace-match "")
  4265. (re-search-forward "\n=+$" nil t)
  4266. (replace-match "")
  4267. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4268. (re-search-forward "\n=+$" nil t)
  4269. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4270. (goto-char (point-min))
  4271. (while (re-search-forward "^ +\n" nil t)
  4272. (replace-match ""))
  4273. (goto-char (point-min))
  4274. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4275. (replace-match ""))
  4276. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4277. ;; Make sure entries from the diary have the right text properties.
  4278. (eval-after-load "diary-lib"
  4279. '(if (boundp 'diary-modify-entry-list-string-function)
  4280. ;; We can rely on the hook, nothing to do
  4281. nil
  4282. ;; Hook not available, must use advice to make this work
  4283. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4284. "Make the position visible."
  4285. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4286. (stringp string)
  4287. buffer-file-name)
  4288. (setq string (org-modify-diary-entry-string string))))))
  4289. (defun org-modify-diary-entry-string (string)
  4290. "Add text properties to string, allowing org-mode to act on it."
  4291. (org-add-props string nil
  4292. 'mouse-face 'highlight
  4293. 'help-echo (if buffer-file-name
  4294. (format "mouse-2 or RET jump to diary file %s"
  4295. (abbreviate-file-name buffer-file-name))
  4296. "")
  4297. 'org-agenda-diary-link t
  4298. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4299. (defun org-diary-default-entry ()
  4300. "Add a dummy entry to the diary.
  4301. Needed to avoid empty dates which mess up holiday display."
  4302. ;; Catch the error if dealing with the new add-to-diary-alist
  4303. (when org-disable-agenda-to-diary
  4304. (condition-case nil
  4305. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4306. (error
  4307. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4308. (defun org-add-to-diary-list (&rest args)
  4309. (if (fboundp 'diary-add-to-list)
  4310. (apply 'diary-add-to-list args)
  4311. (apply 'add-to-diary-list args)))
  4312. (defvar org-diary-last-run-time nil)
  4313. ;;;###autoload
  4314. (defun org-diary (&rest args)
  4315. "Return diary information from org-files.
  4316. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4317. It accesses org files and extracts information from those files to be
  4318. listed in the diary. The function accepts arguments specifying what
  4319. items should be listed. For a list of arguments allowed here, see the
  4320. variable `org-agenda-entry-types'.
  4321. The call in the diary file should look like this:
  4322. &%%(org-diary) ~/path/to/some/orgfile.org
  4323. Use a separate line for each org file to check. Or, if you omit the file name,
  4324. all files listed in `org-agenda-files' will be checked automatically:
  4325. &%%(org-diary)
  4326. If you don't give any arguments (as in the example above), the default
  4327. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4328. So the example above may also be written as
  4329. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4330. The function expects the lisp variables `entry' and `date' to be provided
  4331. by the caller, because this is how the calendar works. Don't use this
  4332. function from a program - use `org-agenda-get-day-entries' instead."
  4333. (when (> (- (org-float-time)
  4334. org-agenda-last-marker-time)
  4335. 5)
  4336. ;; I am not sure if this works with sticky agendas, because the marker
  4337. ;; list is then no longer a global variable.
  4338. (org-agenda-reset-markers))
  4339. (org-compile-prefix-format 'agenda)
  4340. (org-set-sorting-strategy 'agenda)
  4341. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4342. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4343. (list entry)
  4344. (org-agenda-files t)))
  4345. (time (org-float-time))
  4346. file rtn results)
  4347. (when (or (not org-diary-last-run-time)
  4348. (> (- time
  4349. org-diary-last-run-time)
  4350. 3))
  4351. (org-prepare-agenda-buffers files))
  4352. (setq org-diary-last-run-time time)
  4353. ;; If this is called during org-agenda, don't return any entries to
  4354. ;; the calendar. Org Agenda will list these entries itself.
  4355. (if org-disable-agenda-to-diary (setq files nil))
  4356. (while (setq file (pop files))
  4357. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4358. (setq results (append results rtn)))
  4359. (if results
  4360. (concat (org-finalize-agenda-entries results) "\n"))))
  4361. ;;; Agenda entry finders
  4362. (defun org-agenda-get-day-entries (file date &rest args)
  4363. "Does the work for `org-diary' and `org-agenda'.
  4364. FILE is the path to a file to be checked for entries. DATE is date like
  4365. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4366. which kind of entries should be extracted. For details about these, see
  4367. the documentation of `org-diary'."
  4368. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4369. (let* ((org-startup-folded nil)
  4370. (org-startup-align-all-tables nil)
  4371. (buffer (if (file-exists-p file)
  4372. (org-get-agenda-file-buffer file)
  4373. (error "No such file %s" file)))
  4374. arg results rtn deadline-results)
  4375. (if (not buffer)
  4376. ;; If file does not exist, make sure an error message ends up in diary
  4377. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4378. (with-current-buffer buffer
  4379. (unless (derived-mode-p 'org-mode)
  4380. (error "Agenda file %s is not in `org-mode'" file))
  4381. (let ((case-fold-search nil))
  4382. (save-excursion
  4383. (save-restriction
  4384. (if org-agenda-restrict
  4385. (narrow-to-region org-agenda-restrict-begin
  4386. org-agenda-restrict-end)
  4387. (widen))
  4388. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4389. (while (setq arg (pop args))
  4390. (cond
  4391. ((and (eq arg :todo)
  4392. (equal date (calendar-gregorian-from-absolute
  4393. (org-today))))
  4394. (setq rtn (org-agenda-get-todos))
  4395. (setq results (append results rtn)))
  4396. ((eq arg :timestamp)
  4397. (setq rtn (org-agenda-get-blocks))
  4398. (setq results (append results rtn))
  4399. (setq rtn (org-agenda-get-timestamps))
  4400. (setq results (append results rtn)))
  4401. ((eq arg :sexp)
  4402. (setq rtn (org-agenda-get-sexps))
  4403. (setq results (append results rtn)))
  4404. ((eq arg :scheduled)
  4405. (setq rtn (org-agenda-get-scheduled deadline-results))
  4406. (setq results (append results rtn)))
  4407. ((eq arg :closed)
  4408. (setq rtn (org-agenda-get-progress))
  4409. (setq results (append results rtn)))
  4410. ((eq arg :deadline)
  4411. (setq rtn (org-agenda-get-deadlines))
  4412. (setq deadline-results (copy-sequence rtn))
  4413. (setq results (append results rtn))))))))
  4414. results))))
  4415. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4416. (defun org-agenda-get-todos ()
  4417. "Return the TODO information for agenda display."
  4418. (let* ((props (list 'face nil
  4419. 'done-face 'org-agenda-done
  4420. 'org-not-done-regexp org-not-done-regexp
  4421. 'org-todo-regexp org-todo-regexp
  4422. 'org-complex-heading-regexp org-complex-heading-regexp
  4423. 'mouse-face 'highlight
  4424. 'help-echo
  4425. (format "mouse-2 or RET jump to org file %s"
  4426. (abbreviate-file-name buffer-file-name))))
  4427. (regexp (format org-heading-keyword-regexp-format
  4428. (cond
  4429. ((and org-select-this-todo-keyword
  4430. (equal org-select-this-todo-keyword "*"))
  4431. org-todo-regexp)
  4432. (org-select-this-todo-keyword
  4433. (concat "\\("
  4434. (mapconcat 'identity
  4435. (org-split-string
  4436. org-select-this-todo-keyword
  4437. "|")
  4438. "\\|") "\\)"))
  4439. (t org-not-done-regexp))))
  4440. marker priority category org-category-pos tags todo-state
  4441. ee txt beg end)
  4442. (goto-char (point-min))
  4443. (while (re-search-forward regexp nil t)
  4444. (catch :skip
  4445. (save-match-data
  4446. (beginning-of-line)
  4447. (org-agenda-skip)
  4448. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4449. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4450. (goto-char (1+ beg))
  4451. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4452. (throw :skip nil)))
  4453. (goto-char (match-beginning 2))
  4454. (setq marker (org-agenda-new-marker (match-beginning 0))
  4455. category (org-get-category)
  4456. org-category-pos (get-text-property (point) 'org-category-position)
  4457. txt (org-trim
  4458. (buffer-substring (match-beginning 2) (match-end 0)))
  4459. tags (org-get-tags-at (point))
  4460. txt (org-agenda-format-item "" txt category tags)
  4461. priority (1+ (org-get-priority txt))
  4462. todo-state (org-get-todo-state))
  4463. (org-add-props txt props
  4464. 'org-marker marker 'org-hd-marker marker
  4465. 'priority priority 'org-category category
  4466. 'org-category-position org-category-pos
  4467. 'type "todo" 'todo-state todo-state)
  4468. (push txt ee)
  4469. (if org-agenda-todo-list-sublevels
  4470. (goto-char (match-end 2))
  4471. (org-end-of-subtree 'invisible))))
  4472. (nreverse ee)))
  4473. (defun org-agenda-todo-custom-ignore-p (time n)
  4474. "Check whether timestamp is farther away then n number of days.
  4475. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4476. `org-agenda-todo-ignore-scheduled' or
  4477. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4478. (let ((days (org-days-to-time time)))
  4479. (if (>= n 0)
  4480. (>= days n)
  4481. (<= days n))))
  4482. ;;;###autoload
  4483. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4484. (&optional end)
  4485. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4486. (when (or org-agenda-todo-ignore-with-date
  4487. org-agenda-todo-ignore-scheduled
  4488. org-agenda-todo-ignore-deadlines
  4489. org-agenda-todo-ignore-timestamp)
  4490. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4491. (save-excursion
  4492. (or (and org-agenda-todo-ignore-with-date
  4493. (re-search-forward org-ts-regexp end t))
  4494. (and org-agenda-todo-ignore-scheduled
  4495. (re-search-forward org-scheduled-time-regexp end t)
  4496. (cond
  4497. ((eq org-agenda-todo-ignore-scheduled 'future)
  4498. (> (org-days-to-time (match-string 1)) 0))
  4499. ((eq org-agenda-todo-ignore-scheduled 'past)
  4500. (<= (org-days-to-time (match-string 1)) 0))
  4501. ((numberp org-agenda-todo-ignore-scheduled)
  4502. (org-agenda-todo-custom-ignore-p
  4503. (match-string 1) org-agenda-todo-ignore-scheduled))
  4504. (t)))
  4505. (and org-agenda-todo-ignore-deadlines
  4506. (re-search-forward org-deadline-time-regexp end t)
  4507. (cond
  4508. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4509. ((eq org-agenda-todo-ignore-deadlines 'far)
  4510. (not (org-deadline-close (match-string 1))))
  4511. ((eq org-agenda-todo-ignore-deadlines 'future)
  4512. (> (org-days-to-time (match-string 1)) 0))
  4513. ((eq org-agenda-todo-ignore-deadlines 'past)
  4514. (<= (org-days-to-time (match-string 1)) 0))
  4515. ((numberp org-agenda-todo-ignore-deadlines)
  4516. (org-agenda-todo-custom-ignore-p
  4517. (match-string 1) org-agenda-todo-ignore-deadlines))
  4518. (t (org-deadline-close (match-string 1)))))
  4519. (and org-agenda-todo-ignore-timestamp
  4520. (let ((buffer (current-buffer))
  4521. (regexp
  4522. (concat
  4523. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4524. (start (point)))
  4525. ;; Copy current buffer into a temporary one
  4526. (with-temp-buffer
  4527. (insert-buffer-substring buffer start end)
  4528. (goto-char (point-min))
  4529. ;; Delete SCHEDULED and DEADLINE items
  4530. (while (re-search-forward regexp end t)
  4531. (delete-region (match-beginning 0) (match-end 0)))
  4532. (goto-char (point-min))
  4533. ;; No search for timestamp left
  4534. (when (re-search-forward org-ts-regexp nil t)
  4535. (cond
  4536. ((eq org-agenda-todo-ignore-timestamp 'future)
  4537. (> (org-days-to-time (match-string 1)) 0))
  4538. ((eq org-agenda-todo-ignore-timestamp 'past)
  4539. (<= (org-days-to-time (match-string 1)) 0))
  4540. ((numberp org-agenda-todo-ignore-timestamp)
  4541. (org-agenda-todo-custom-ignore-p
  4542. (match-string 1) org-agenda-todo-ignore-timestamp))
  4543. (t))))))))))
  4544. (defconst org-agenda-no-heading-message
  4545. "No heading for this item in buffer or region.")
  4546. (defun org-agenda-get-timestamps ()
  4547. "Return the date stamp information for agenda display."
  4548. (let* ((props (list 'face 'org-agenda-calendar-event
  4549. 'org-not-done-regexp org-not-done-regexp
  4550. 'org-todo-regexp org-todo-regexp
  4551. 'org-complex-heading-regexp org-complex-heading-regexp
  4552. 'mouse-face 'highlight
  4553. 'help-echo
  4554. (format "mouse-2 or RET jump to org file %s"
  4555. (abbreviate-file-name buffer-file-name))))
  4556. (d1 (calendar-absolute-from-gregorian date))
  4557. (remove-re
  4558. (concat
  4559. (regexp-quote
  4560. (format-time-string
  4561. "<%Y-%m-%d"
  4562. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4563. ".*?>"))
  4564. (regexp
  4565. (concat
  4566. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4567. (regexp-quote
  4568. (substring
  4569. (format-time-string
  4570. (car org-time-stamp-formats)
  4571. (apply 'encode-time ; DATE bound by calendar
  4572. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4573. 1 11))
  4574. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4575. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4576. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4577. donep tmp priority category org-category-pos ee txt timestr tags
  4578. b0 b3 e3 head todo-state end-of-match show-all)
  4579. (goto-char (point-min))
  4580. (while (setq end-of-match (re-search-forward regexp nil t))
  4581. (setq b0 (match-beginning 0)
  4582. b3 (match-beginning 3) e3 (match-end 3)
  4583. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4584. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4585. (member todo-state
  4586. org-agenda-repeating-timestamp-show-all)))
  4587. (catch :skip
  4588. (and (org-at-date-range-p) (throw :skip nil))
  4589. (org-agenda-skip)
  4590. (if (and (match-end 1)
  4591. (not (= d1 (org-time-string-to-absolute
  4592. (match-string 1) d1 nil show-all
  4593. (current-buffer) b0))))
  4594. (throw :skip nil))
  4595. (if (and e3
  4596. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4597. (throw :skip nil))
  4598. (setq tmp (buffer-substring (max (point-min)
  4599. (- b0 org-ds-keyword-length))
  4600. b0)
  4601. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4602. inactivep (= (char-after b0) ?\[)
  4603. deadlinep (string-match org-deadline-regexp tmp)
  4604. scheduledp (string-match org-scheduled-regexp tmp)
  4605. closedp (and org-agenda-include-inactive-timestamps
  4606. (string-match org-closed-string tmp))
  4607. clockp (and org-agenda-include-inactive-timestamps
  4608. (or (string-match org-clock-string tmp)
  4609. (string-match "]-+\\'" tmp)))
  4610. donep (member todo-state org-done-keywords))
  4611. (if (or scheduledp deadlinep closedp clockp
  4612. (and donep org-agenda-skip-timestamp-if-done))
  4613. (throw :skip t))
  4614. (if (string-match ">" timestr)
  4615. ;; substring should only run to end of time stamp
  4616. (setq timestr (substring timestr 0 (match-end 0))))
  4617. (setq marker (org-agenda-new-marker b0)
  4618. category (org-get-category b0)
  4619. org-category-pos (get-text-property b0 'org-category-position))
  4620. (save-excursion
  4621. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4622. (setq txt org-agenda-no-heading-message)
  4623. (goto-char (match-beginning 0))
  4624. (setq hdmarker (org-agenda-new-marker)
  4625. tags (org-get-tags-at))
  4626. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4627. (setq head (or (match-string 1) ""))
  4628. (setq txt (org-agenda-format-item
  4629. (if inactivep org-agenda-inactive-leader nil)
  4630. head category tags timestr
  4631. remove-re)))
  4632. (setq priority (org-get-priority txt))
  4633. (org-add-props txt props
  4634. 'org-marker marker 'org-hd-marker hdmarker)
  4635. (org-add-props txt nil 'priority priority
  4636. 'org-category category 'date date
  4637. 'org-category-position org-category-pos
  4638. 'todo-state todo-state
  4639. 'type "timestamp")
  4640. (push txt ee))
  4641. (if org-agenda-skip-additional-timestamps-same-entry
  4642. (outline-next-heading)
  4643. (goto-char end-of-match))))
  4644. (nreverse ee)))
  4645. (defun org-agenda-get-sexps ()
  4646. "Return the sexp information for agenda display."
  4647. (require 'diary-lib)
  4648. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4649. 'mouse-face 'highlight
  4650. 'help-echo
  4651. (format "mouse-2 or RET jump to org file %s"
  4652. (abbreviate-file-name buffer-file-name))))
  4653. (regexp "^&?%%(")
  4654. marker category org-category-pos ee txt tags entry
  4655. result beg b sexp sexp-entry todo-state)
  4656. (goto-char (point-min))
  4657. (while (re-search-forward regexp nil t)
  4658. (catch :skip
  4659. (org-agenda-skip)
  4660. (setq beg (match-beginning 0))
  4661. (goto-char (1- (match-end 0)))
  4662. (setq b (point))
  4663. (forward-sexp 1)
  4664. (setq sexp (buffer-substring b (point)))
  4665. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4666. (org-trim (match-string 1))
  4667. ""))
  4668. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4669. (when result
  4670. (setq marker (org-agenda-new-marker beg)
  4671. category (org-get-category beg)
  4672. org-category-pos (get-text-property beg 'org-category-position)
  4673. todo-state (org-get-todo-state))
  4674. (dolist (r (if (stringp result)
  4675. (list result)
  4676. result)) ;; we expect a list here
  4677. (if (string-match "\\S-" r)
  4678. (setq txt r)
  4679. (setq txt "SEXP entry returned empty string"))
  4680. (setq txt (org-agenda-format-item
  4681. "" txt category tags 'time))
  4682. (org-add-props txt props 'org-marker marker)
  4683. (org-add-props txt nil
  4684. 'org-category category 'date date 'todo-state todo-state
  4685. 'org-category-position org-category-pos
  4686. 'type "sexp")
  4687. (push txt ee)))))
  4688. (nreverse ee)))
  4689. ;; Calendar sanity: define some functions that are independent of
  4690. ;; `calendar-date-style'.
  4691. ;; Normally I would like to use ISO format when calling the diary functions,
  4692. ;; but to make sure we still have Emacs 22 compatibility we bind
  4693. ;; also `european-calendar-style' and use european format
  4694. (defun org-anniversary (year month day &optional mark)
  4695. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4696. (org-no-warnings
  4697. (let ((calendar-date-style 'european) (european-calendar-style t))
  4698. (diary-anniversary day month year mark))))
  4699. (defun org-cyclic (N year month day &optional mark)
  4700. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4701. (org-no-warnings
  4702. (let ((calendar-date-style 'european) (european-calendar-style t))
  4703. (diary-cyclic N day month year mark))))
  4704. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4705. "Like `diary-block', but with fixed (ISO) order of arguments."
  4706. (org-no-warnings
  4707. (let ((calendar-date-style 'european) (european-calendar-style t))
  4708. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4709. (defun org-date (year month day &optional mark)
  4710. "Like `diary-date', but with fixed (ISO) order of arguments."
  4711. (org-no-warnings
  4712. (let ((calendar-date-style 'european) (european-calendar-style t))
  4713. (diary-date day month year mark))))
  4714. (defalias 'org-float 'diary-float)
  4715. ;; Define the` org-class' function
  4716. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4717. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4718. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4719. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4720. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4721. `holidays', then any date that is known by the Emacs calendar to be a
  4722. holiday will also be skipped."
  4723. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4724. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4725. (d (calendar-absolute-from-gregorian date)))
  4726. (and
  4727. (<= date1 d)
  4728. (<= d date2)
  4729. (= (calendar-day-of-week date) dayname)
  4730. (or (not skip-weeks)
  4731. (progn
  4732. (require 'cal-iso)
  4733. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4734. (not (and (memq 'holidays skip-weeks)
  4735. (calendar-check-holidays date)))
  4736. entry)))
  4737. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4738. "Like `org-class', but honor `calendar-date-style'.
  4739. The order of the first 2 times 3 arguments depends on the variable
  4740. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4741. So for American calendars, give this as MONTH DAY YEAR, for European as
  4742. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4743. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4744. is any number of ISO weeks in the block period for which the item should
  4745. be skipped.
  4746. This function is here only for backward compatibility and it is deprecated,
  4747. please use `org-class' instead."
  4748. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4749. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4750. (org-class
  4751. (nth 2 date1) (car date1) (nth 1 date1)
  4752. (nth 2 date2) (car date2) (nth 1 date2)
  4753. dayname skip-weeks)))
  4754. (make-obsolete 'org-diary-class 'org-class "")
  4755. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4756. (defalias 'org-get-closed 'org-agenda-get-progress)
  4757. (defun org-agenda-get-progress ()
  4758. "Return the logged TODO entries for agenda display."
  4759. (let* ((props (list 'mouse-face 'highlight
  4760. 'org-not-done-regexp org-not-done-regexp
  4761. 'org-todo-regexp org-todo-regexp
  4762. 'org-complex-heading-regexp org-complex-heading-regexp
  4763. 'help-echo
  4764. (format "mouse-2 or RET jump to org file %s"
  4765. (abbreviate-file-name buffer-file-name))))
  4766. (items (if (consp org-agenda-show-log-scoped)
  4767. org-agenda-show-log-scoped
  4768. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4769. '(clock)
  4770. org-agenda-log-mode-items)))
  4771. (parts
  4772. (delq nil
  4773. (list
  4774. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4775. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4776. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4777. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4778. (error "`org-agenda-log-mode-items' is empty")))
  4779. (regexp (concat
  4780. "\\(" parts-re "\\)"
  4781. " *\\["
  4782. (regexp-quote
  4783. (substring
  4784. (format-time-string
  4785. (car org-time-stamp-formats)
  4786. (apply 'encode-time ; DATE bound by calendar
  4787. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4788. 1 11))))
  4789. (org-agenda-search-headline-for-time nil)
  4790. marker hdmarker priority category org-category-pos tags closedp
  4791. statep clockp state ee txt extra timestr rest clocked)
  4792. (goto-char (point-min))
  4793. (while (re-search-forward regexp nil t)
  4794. (catch :skip
  4795. (org-agenda-skip)
  4796. (setq marker (org-agenda-new-marker (match-beginning 0))
  4797. closedp (equal (match-string 1) org-closed-string)
  4798. statep (equal (string-to-char (match-string 1)) ?-)
  4799. clockp (not (or closedp statep))
  4800. state (and statep (match-string 2))
  4801. category (org-get-category (match-beginning 0))
  4802. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4803. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4804. (when (string-match "\\]" timestr)
  4805. ;; substring should only run to end of time stamp
  4806. (setq rest (substring timestr (match-end 0))
  4807. timestr (substring timestr 0 (match-end 0)))
  4808. (if (and (not closedp) (not statep)
  4809. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4810. rest))
  4811. (progn (setq timestr (concat (substring timestr 0 -1)
  4812. "-" (match-string 1 rest) "]"))
  4813. (setq clocked (match-string 2 rest)))
  4814. (setq clocked "-")))
  4815. (save-excursion
  4816. (setq extra
  4817. (cond
  4818. ((not org-agenda-log-mode-add-notes) nil)
  4819. (statep
  4820. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4821. (match-string 1)))
  4822. (clockp
  4823. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4824. (match-string 1)))))
  4825. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4826. (setq txt org-agenda-no-heading-message)
  4827. (goto-char (match-beginning 0))
  4828. (setq hdmarker (org-agenda-new-marker)
  4829. tags (org-get-tags-at))
  4830. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4831. (setq txt (match-string 1))
  4832. (when extra
  4833. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4834. (setq txt (concat (substring txt 0 (match-beginning 1))
  4835. " - " extra " " (match-string 2 txt)))
  4836. (setq txt (concat txt " - " extra))))
  4837. (setq txt (org-agenda-format-item
  4838. (cond
  4839. (closedp "Closed: ")
  4840. (statep (concat "State: (" state ")"))
  4841. (t (concat "Clocked: (" clocked ")")))
  4842. txt category tags timestr)))
  4843. (setq priority 100000)
  4844. (org-add-props txt props
  4845. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4846. 'priority priority 'org-category category
  4847. 'org-category-position org-category-pos
  4848. 'type "closed" 'date date
  4849. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4850. (push txt ee))
  4851. (goto-char (point-at-eol))))
  4852. (nreverse ee)))
  4853. (defun org-agenda-show-clocking-issues ()
  4854. "Add overlays, showing issues with clocking.
  4855. See also the user option `org-agenda-clock-consistency-checks'."
  4856. (interactive)
  4857. (let* ((pl org-agenda-clock-consistency-checks)
  4858. (re (concat "^[ \t]*"
  4859. org-clock-string
  4860. "[ \t]+"
  4861. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4862. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4863. (tlstart 0.)
  4864. (tlend 0.)
  4865. (maxtime (org-hh:mm-string-to-minutes
  4866. (or (plist-get pl :max-duration) "24:00")))
  4867. (mintime (org-hh:mm-string-to-minutes
  4868. (or (plist-get pl :min-duration) 0)))
  4869. (maxgap (org-hh:mm-string-to-minutes
  4870. ;; default 30:00 means never complain
  4871. (or (plist-get pl :max-gap) "30:00")))
  4872. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4873. (plist-get pl :gap-ok-around)))
  4874. (def-face (or (plist-get pl :default-face)
  4875. '((:background "DarkRed") (:foreground "white"))))
  4876. issue face m te ts dt ov)
  4877. (goto-char (point-min))
  4878. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4879. (setq issue nil face def-face)
  4880. (catch 'next
  4881. (setq m (org-get-at-bol 'org-marker)
  4882. te nil ts nil)
  4883. (unless (and m (markerp m))
  4884. (setq issue "No valid clock line") (throw 'next t))
  4885. (org-with-point-at m
  4886. (save-excursion
  4887. (goto-char (point-at-bol))
  4888. (unless (looking-at re)
  4889. (error "No valid Clock line")
  4890. (throw 'next t))
  4891. (unless (match-end 3)
  4892. (setq issue "No end time"
  4893. face (or (plist-get pl :no-end-time-face) face))
  4894. (throw 'next t))
  4895. (setq ts (match-string 1)
  4896. te (match-string 3)
  4897. ts (org-float-time
  4898. (apply 'encode-time (org-parse-time-string ts)))
  4899. te (org-float-time
  4900. (apply 'encode-time (org-parse-time-string te)))
  4901. dt (- te ts))))
  4902. (cond
  4903. ((> dt (* 60 maxtime))
  4904. ;; a very long clocking chunk
  4905. (setq issue (format "Clocking interval is very long: %s"
  4906. (org-minutes-to-hh:mm-string
  4907. (floor (/ (float dt) 60.))))
  4908. face (or (plist-get pl :long-face) face)))
  4909. ((< dt (* 60 mintime))
  4910. ;; a very short clocking chunk
  4911. (setq issue (format "Clocking interval is very short: %s"
  4912. (org-minutes-to-hh:mm-string
  4913. (floor (/ (float dt) 60.))))
  4914. face (or (plist-get pl :short-face) face)))
  4915. ((and (> tlend 0) (< ts tlend))
  4916. ;; Two clock entries are overlapping
  4917. (setq issue (format "Clocking overlap: %d minutes"
  4918. (/ (- tlend ts) 60))
  4919. face (or (plist-get pl :overlap-face) face)))
  4920. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4921. ;; There is a gap, lets see if we need to report it
  4922. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4923. (setq issue (format "Clocking gap: %d minutes"
  4924. (/ (- ts tlend) 60))
  4925. face (or (plist-get pl :gap-face) face))))
  4926. (t nil)))
  4927. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4928. (when issue
  4929. ;; OK, there was some issue, add an overlay to show the issue
  4930. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4931. (overlay-put ov 'before-string
  4932. (concat
  4933. (org-add-props
  4934. (format "%-43s" (concat " " issue))
  4935. nil
  4936. 'face face)
  4937. "\n"))
  4938. (overlay-put ov 'evaporate t)))))
  4939. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4940. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4941. (catch 'exit
  4942. (unless ok-list
  4943. ;; there are no OK times for gaps...
  4944. (throw 'exit nil))
  4945. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4946. ;; This is more than 24 hours, so it is OK.
  4947. ;; because we have at least one OK time, that must be in the
  4948. ;; 24 hour interval.
  4949. (throw 'exit t))
  4950. ;; We have a shorter gap.
  4951. ;; Now we have to get the minute of the day when these times are
  4952. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4953. (t2dec (decode-time (seconds-to-time t2)))
  4954. ;; compute the minute on the day
  4955. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4956. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4957. (when (< min2 min1)
  4958. ;; if min2 is smaller than min1, this means it is on the next day.
  4959. ;; Wrap it to after midnight.
  4960. (setq min2 (+ min2 1440)))
  4961. ;; Now check if any of the OK times is in the gap
  4962. (mapc (lambda (x)
  4963. ;; Wrap the time to after midnight if necessary
  4964. (if (< x min1) (setq x (+ x 1440)))
  4965. ;; Check if in interval
  4966. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4967. ok-list)
  4968. ;; Nope, this gap is not OK
  4969. nil)))
  4970. (defun org-agenda-get-deadlines ()
  4971. "Return the deadline information for agenda display."
  4972. (let* ((props (list 'mouse-face 'highlight
  4973. 'org-not-done-regexp org-not-done-regexp
  4974. 'org-todo-regexp org-todo-regexp
  4975. 'org-complex-heading-regexp org-complex-heading-regexp
  4976. 'help-echo
  4977. (format "mouse-2 or RET jump to org file %s"
  4978. (abbreviate-file-name buffer-file-name))))
  4979. (regexp org-deadline-time-regexp)
  4980. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4981. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4982. d2 diff dfrac wdays pos pos1 category org-category-pos
  4983. tags suppress-prewarning ee txt head face s todo-state
  4984. show-all upcomingp donep timestr)
  4985. (goto-char (point-min))
  4986. (while (re-search-forward regexp nil t)
  4987. (setq suppress-prewarning nil)
  4988. (catch :skip
  4989. (org-agenda-skip)
  4990. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4991. (save-match-data
  4992. (string-match org-scheduled-time-regexp
  4993. (buffer-substring (point-at-bol)
  4994. (point-at-eol)))))
  4995. (setq suppress-prewarning
  4996. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4997. org-agenda-skip-deadline-prewarning-if-scheduled
  4998. 0)))
  4999. (setq s (match-string 1)
  5000. txt nil
  5001. pos (1- (match-beginning 1))
  5002. todo-state (save-match-data (org-get-todo-state))
  5003. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5004. (member todo-state
  5005. org-agenda-repeating-timestamp-show-all))
  5006. d2 (org-time-string-to-absolute
  5007. (match-string 1) d1 'past show-all
  5008. (current-buffer) pos)
  5009. diff (- d2 d1)
  5010. wdays (if suppress-prewarning
  5011. (let ((org-deadline-warning-days suppress-prewarning))
  5012. (org-get-wdays s))
  5013. (org-get-wdays s))
  5014. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5015. upcomingp (and todayp (> diff 0)))
  5016. ;; When to show a deadline in the calendar:
  5017. ;; If the expiration is within wdays warning time.
  5018. ;; Past-due deadlines are only shown on the current date
  5019. (if (and (or (and (<= diff wdays)
  5020. (and todayp (not org-agenda-only-exact-dates)))
  5021. (= diff 0)))
  5022. (save-excursion
  5023. ;; (setq todo-state (org-get-todo-state))
  5024. (setq donep (member todo-state org-done-keywords))
  5025. (if (and donep
  5026. (or org-agenda-skip-deadline-if-done
  5027. (not (= diff 0))))
  5028. (setq txt nil)
  5029. (setq category (org-get-category)
  5030. org-category-pos (get-text-property (point) 'org-category-position))
  5031. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5032. (setq txt org-agenda-no-heading-message)
  5033. (goto-char (match-end 0))
  5034. (setq pos1 (match-beginning 0))
  5035. (setq tags (org-get-tags-at pos1))
  5036. (setq head (buffer-substring-no-properties
  5037. (point)
  5038. (progn (skip-chars-forward "^\r\n")
  5039. (point))))
  5040. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5041. (setq timestr
  5042. (concat (substring s (match-beginning 1)) " "))
  5043. (setq timestr 'time))
  5044. (setq txt (org-agenda-format-item
  5045. (if (= diff 0)
  5046. (car org-agenda-deadline-leaders)
  5047. (if (functionp
  5048. (nth 1 org-agenda-deadline-leaders))
  5049. (funcall
  5050. (nth 1 org-agenda-deadline-leaders)
  5051. diff date)
  5052. (format (nth 1 org-agenda-deadline-leaders)
  5053. diff)))
  5054. head category tags
  5055. (if (not (= diff 0)) nil timestr)))))
  5056. (when txt
  5057. (setq face (org-agenda-deadline-face dfrac))
  5058. (org-add-props txt props
  5059. 'org-marker (org-agenda-new-marker pos)
  5060. 'org-hd-marker (org-agenda-new-marker pos1)
  5061. 'priority (+ (- diff)
  5062. (org-get-priority txt))
  5063. 'org-category category
  5064. 'org-category-position org-category-pos
  5065. 'todo-state todo-state
  5066. 'type (if upcomingp "upcoming-deadline" "deadline")
  5067. 'date (if upcomingp date d2)
  5068. 'face (if donep 'org-agenda-done face)
  5069. 'undone-face face 'done-face 'org-agenda-done)
  5070. (push txt ee))))))
  5071. (nreverse ee)))
  5072. (defun org-agenda-deadline-face (fraction)
  5073. "Return the face to displaying a deadline item.
  5074. FRACTION is what fraction of the head-warning time has passed."
  5075. (let ((faces org-agenda-deadline-faces) f)
  5076. (catch 'exit
  5077. (while (setq f (pop faces))
  5078. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5079. (defun org-agenda-get-scheduled (&optional deadline-results)
  5080. "Return the scheduled information for agenda display."
  5081. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5082. 'org-todo-regexp org-todo-regexp
  5083. 'org-complex-heading-regexp org-complex-heading-regexp
  5084. 'done-face 'org-agenda-done
  5085. 'mouse-face 'highlight
  5086. 'help-echo
  5087. (format "mouse-2 or RET jump to org file %s"
  5088. (abbreviate-file-name buffer-file-name))))
  5089. (regexp org-scheduled-time-regexp)
  5090. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5091. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5092. mm
  5093. (deadline-position-alist
  5094. (mapcar (lambda (a) (and (setq mm (get-text-property
  5095. 0 'org-hd-marker a))
  5096. (cons (marker-position mm) a)))
  5097. deadline-results))
  5098. d2 diff pos pos1 category org-category-pos tags donep
  5099. ee txt head pastschedp todo-state face timestr s habitp show-all)
  5100. (goto-char (point-min))
  5101. (while (re-search-forward regexp nil t)
  5102. (catch :skip
  5103. (org-agenda-skip)
  5104. (setq s (match-string 1)
  5105. txt nil
  5106. pos (1- (match-beginning 1))
  5107. todo-state (save-match-data (org-get-todo-state))
  5108. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5109. (member todo-state
  5110. org-agenda-repeating-timestamp-show-all))
  5111. d2 (org-time-string-to-absolute
  5112. (match-string 1) d1 'past show-all
  5113. (current-buffer) pos)
  5114. diff (- d2 d1))
  5115. (setq pastschedp (and todayp (< diff 0)))
  5116. ;; When to show a scheduled item in the calendar:
  5117. ;; If it is on or past the date.
  5118. (when (or (and (< diff 0)
  5119. (< (abs diff) org-scheduled-past-days)
  5120. (and todayp (not org-agenda-only-exact-dates)))
  5121. (= diff 0))
  5122. (save-excursion
  5123. (setq donep (member todo-state org-done-keywords))
  5124. (if (and donep
  5125. (or org-agenda-skip-scheduled-if-done
  5126. (not (= diff 0))
  5127. (and (functionp 'org-is-habit-p)
  5128. (org-is-habit-p))))
  5129. (setq txt nil)
  5130. (setq habitp (and (functionp 'org-is-habit-p)
  5131. (org-is-habit-p)))
  5132. (setq category (org-get-category)
  5133. org-category-pos (get-text-property (point) 'org-category-position))
  5134. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5135. (setq txt org-agenda-no-heading-message)
  5136. (goto-char (match-end 0))
  5137. (setq pos1 (match-beginning 0))
  5138. (if habitp
  5139. (if (or (not org-habit-show-habits)
  5140. (and (not todayp)
  5141. org-habit-show-habits-only-for-today))
  5142. (throw :skip nil))
  5143. (if (and
  5144. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5145. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5146. pastschedp))
  5147. (setq mm (assoc pos1 deadline-position-alist)))
  5148. (throw :skip nil)))
  5149. (setq tags (org-get-tags-at))
  5150. (setq head (buffer-substring-no-properties
  5151. (point)
  5152. (progn (skip-chars-forward "^\r\n") (point))))
  5153. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5154. (setq timestr
  5155. (concat (substring s (match-beginning 1)) " "))
  5156. (setq timestr 'time))
  5157. (setq txt (org-agenda-format-item
  5158. (if (= diff 0)
  5159. (car org-agenda-scheduled-leaders)
  5160. (format (nth 1 org-agenda-scheduled-leaders)
  5161. (- 1 diff)))
  5162. head category tags
  5163. (if (not (= diff 0)) nil timestr)
  5164. nil habitp))))
  5165. (when txt
  5166. (setq face
  5167. (cond
  5168. ((and (not habitp) pastschedp)
  5169. 'org-scheduled-previously)
  5170. (todayp 'org-scheduled-today)
  5171. (t 'org-scheduled))
  5172. habitp (and habitp (org-habit-parse-todo)))
  5173. (org-add-props txt props
  5174. 'undone-face face
  5175. 'face (if donep 'org-agenda-done face)
  5176. 'org-marker (org-agenda-new-marker pos)
  5177. 'org-hd-marker (org-agenda-new-marker pos1)
  5178. 'type (if pastschedp "past-scheduled" "scheduled")
  5179. 'date (if pastschedp d2 date)
  5180. 'priority (if habitp
  5181. (org-habit-get-priority habitp)
  5182. (+ 94 (- 5 diff) (org-get-priority txt)))
  5183. 'org-category category
  5184. 'org-category-position org-category-pos
  5185. 'org-habit-p habitp
  5186. 'todo-state todo-state)
  5187. (push txt ee))))))
  5188. (nreverse ee)))
  5189. (defun org-agenda-get-blocks ()
  5190. "Return the date-range information for agenda display."
  5191. (let* ((props (list 'face nil
  5192. 'org-not-done-regexp org-not-done-regexp
  5193. 'org-todo-regexp org-todo-regexp
  5194. 'org-complex-heading-regexp org-complex-heading-regexp
  5195. 'mouse-face 'highlight
  5196. 'help-echo
  5197. (format "mouse-2 or RET jump to org file %s"
  5198. (abbreviate-file-name buffer-file-name))))
  5199. (regexp org-tr-regexp)
  5200. (d0 (calendar-absolute-from-gregorian date))
  5201. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5202. todo-state tags pos head donep)
  5203. (goto-char (point-min))
  5204. (while (re-search-forward regexp nil t)
  5205. (catch :skip
  5206. (org-agenda-skip)
  5207. (setq pos (point))
  5208. (let ((start-time (match-string 1))
  5209. (end-time (match-string 2)))
  5210. (setq s1 (match-string 1)
  5211. s2 (match-string 2)
  5212. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5213. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5214. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5215. ;; Only allow days between the limits, because the normal
  5216. ;; date stamps will catch the limits.
  5217. (save-excursion
  5218. (setq todo-state (org-get-todo-state))
  5219. (setq donep (member todo-state org-done-keywords))
  5220. (if (and donep org-agenda-skip-timestamp-if-done)
  5221. (throw :skip t))
  5222. (setq marker (org-agenda-new-marker (point)))
  5223. (setq category (org-get-category)
  5224. org-category-pos (get-text-property (point) 'org-category-position))
  5225. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5226. (setq txt org-agenda-no-heading-message)
  5227. (goto-char (match-beginning 0))
  5228. (setq hdmarker (org-agenda-new-marker (point)))
  5229. (setq tags (org-get-tags-at))
  5230. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5231. (setq head (match-string 1))
  5232. (let ((remove-re
  5233. (if org-agenda-remove-timeranges-from-blocks
  5234. (concat
  5235. "<" (regexp-quote s1) ".*?>"
  5236. "--"
  5237. "<" (regexp-quote s2) ".*?>")
  5238. nil)))
  5239. (setq txt (org-agenda-format-item
  5240. (format
  5241. (nth (if (= d1 d2) 0 1)
  5242. org-agenda-timerange-leaders)
  5243. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5244. head category tags
  5245. (cond ((and (= d1 d0) (= d2 d0))
  5246. (concat "<" start-time ">--<" end-time ">"))
  5247. ((= d1 d0)
  5248. (concat "<" start-time ">"))
  5249. ((= d2 d0)
  5250. (concat "<" end-time ">"))
  5251. (t nil))
  5252. remove-re))))
  5253. (org-add-props txt props
  5254. 'org-marker marker 'org-hd-marker hdmarker
  5255. 'type "block" 'date date
  5256. 'todo-state todo-state
  5257. 'priority (org-get-priority txt) 'org-category category
  5258. 'org-category-position org-category-pos)
  5259. (push txt ee))))
  5260. (goto-char pos)))
  5261. ;; Sort the entries by expiration date.
  5262. (nreverse ee)))
  5263. ;;; Agenda presentation and sorting
  5264. (defvar org-prefix-has-time nil
  5265. "A flag, set by `org-compile-prefix-format'.
  5266. The flag is set if the currently compiled format contains a `%t'.")
  5267. (defvar org-prefix-has-tag nil
  5268. "A flag, set by `org-compile-prefix-format'.
  5269. The flag is set if the currently compiled format contains a `%T'.")
  5270. (defvar org-prefix-has-effort nil
  5271. "A flag, set by `org-compile-prefix-format'.
  5272. The flag is set if the currently compiled format contains a `%e'.")
  5273. (defvar org-prefix-category-length nil
  5274. "Used by `org-compile-prefix-format' to remember the category field width.")
  5275. (defvar org-prefix-category-max-length nil
  5276. "Used by `org-compile-prefix-format' to remember the category field width.")
  5277. (defun org-agenda-get-category-icon (category)
  5278. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5279. (dolist (entry org-agenda-category-icon-alist)
  5280. (when (org-string-match-p (car entry) category)
  5281. (if (listp (cadr entry))
  5282. (return (cadr entry))
  5283. (return (apply 'create-image (cdr entry)))))))
  5284. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5285. remove-re habitp)
  5286. "Format TXT to be inserted into the agenda buffer.
  5287. In particular, it adds the prefix and corresponding text properties. EXTRA
  5288. must be a string and replaces the `%s' specifier in the prefix format.
  5289. CATEGORY (string, symbol or nil) may be used to overrule the default
  5290. category taken from local variable or file name. It will replace the `%c'
  5291. specifier in the format. DOTIME, when non-nil, indicates that a
  5292. time-of-day should be extracted from TXT for sorting of this entry, and for
  5293. the `%t' specifier in the format. When DOTIME is a string, this string is
  5294. searched for a time before TXT is. TAGS can be the tags of the headline.
  5295. Any match of REMOVE-RE will be removed from TXT."
  5296. ;; We keep the org-prefix-* variable values along with a compiled
  5297. ;; formatter, so that multiple agendas existing at the same time, do
  5298. ;; not step on each other toes.
  5299. ;;
  5300. ;; It was inconvenient to make these variables buffer local in
  5301. ;; Agenda buffers, because this function expects to be called with
  5302. ;; the buffer where item comes from being current, and not agenda
  5303. ;; buffer
  5304. (let* ((bindings (car org-prefix-format-compiled))
  5305. (formatter (cadr org-prefix-format-compiled)))
  5306. (loop for (var value) in bindings
  5307. do (set var value))
  5308. (save-match-data
  5309. ;; Diary entries sometimes have extra whitespace at the beginning
  5310. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5311. ;; Fix the tags part in txt
  5312. (setq txt (org-agenda-fix-displayed-tags
  5313. txt tags
  5314. org-agenda-show-inherited-tags
  5315. org-agenda-hide-tags-regexp))
  5316. (let* ((category (or category
  5317. (if (stringp org-category)
  5318. org-category
  5319. (and org-category (symbol-name org-category)))
  5320. (if buffer-file-name
  5321. (file-name-sans-extension
  5322. (file-name-nondirectory buffer-file-name))
  5323. "")))
  5324. (category-icon (org-agenda-get-category-icon category))
  5325. (category-icon (if category-icon
  5326. (propertize " " 'display category-icon)
  5327. ""))
  5328. ;; time, tag, effort are needed for the eval of the prefix format
  5329. (tag (if tags (nth (1- (length tags)) tags) ""))
  5330. time effort neffort
  5331. (ts (if dotime (concat
  5332. (if (stringp dotime) dotime "")
  5333. (and org-agenda-search-headline-for-time txt))))
  5334. (time-of-day (and dotime (org-get-time-of-day ts)))
  5335. stamp plain s0 s1 s2 rtn srp l
  5336. duration thecategory)
  5337. (and (derived-mode-p 'org-mode) buffer-file-name
  5338. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5339. (when (and dotime time-of-day)
  5340. ;; Extract starting and ending time and move them to prefix
  5341. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5342. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5343. (setq s0 (match-string 0 ts)
  5344. srp (and stamp (match-end 3))
  5345. s1 (match-string (if plain 1 2) ts)
  5346. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5347. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5348. ;; them, we might want to remove them there to avoid duplication.
  5349. ;; The user can turn this off with a variable.
  5350. (if (and org-prefix-has-time
  5351. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5352. (string-match (concat (regexp-quote s0) " *") txt)
  5353. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5354. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5355. (= (match-beginning 0) 0)
  5356. t))
  5357. (setq txt (replace-match "" nil nil txt))))
  5358. ;; Normalize the time(s) to 24 hour
  5359. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5360. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5361. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5362. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5363. (setq s2
  5364. (org-minutes-to-hh:mm-string
  5365. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5366. ;; Compute the duration
  5367. (when s2
  5368. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5369. (org-hh:mm-string-to-minutes s1)))))
  5370. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5371. txt)
  5372. ;; Tags are in the string
  5373. (if (or (eq org-agenda-remove-tags t)
  5374. (and org-agenda-remove-tags
  5375. org-prefix-has-tag))
  5376. (setq txt (replace-match "" t t txt))
  5377. (setq txt (replace-match
  5378. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5379. (match-string 2 txt))
  5380. t t txt))))
  5381. (when (derived-mode-p 'org-mode)
  5382. (setq effort
  5383. (condition-case nil
  5384. (org-get-effort
  5385. (or (get-text-property 0 'org-hd-marker txt)
  5386. (get-text-property 0 'org-marker txt)))
  5387. (error nil)))
  5388. (when effort
  5389. (setq neffort (org-duration-string-to-minutes effort)
  5390. effort (setq effort (concat "[" effort "]")))))
  5391. ;; prevent erroring out with %e format when there is no effort
  5392. (or effort (setq effort ""))
  5393. (when remove-re
  5394. (while (string-match remove-re txt)
  5395. (setq txt (replace-match "" t t txt))))
  5396. ;; Set org-heading property on `txt' to mark the start of the
  5397. ;; heading.
  5398. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5399. ;; Prepare the variables needed in the eval of the compiled format
  5400. (setq time (cond (s2 (concat
  5401. (org-agenda-time-of-day-to-ampm-maybe s1)
  5402. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5403. (if org-agenda-timegrid-use-ampm " ")))
  5404. (s1 (concat
  5405. (org-agenda-time-of-day-to-ampm-maybe s1)
  5406. (if org-agenda-timegrid-use-ampm
  5407. "........ "
  5408. "......")))
  5409. (t ""))
  5410. extra (or (and (not habitp) extra) "")
  5411. category (if (symbolp category) (symbol-name category) category)
  5412. thecategory (copy-sequence category))
  5413. (if (string-match org-bracket-link-regexp category)
  5414. (progn
  5415. (setq l (if (match-end 3)
  5416. (- (match-end 3) (match-beginning 3))
  5417. (- (match-end 1) (match-beginning 1))))
  5418. (when (< l (or org-prefix-category-length 0))
  5419. (setq category (copy-sequence category))
  5420. (org-add-props category nil
  5421. 'extra-space (make-string
  5422. (- org-prefix-category-length l 1) ?\ ))))
  5423. (if (and org-prefix-category-max-length
  5424. (>= (length category) org-prefix-category-max-length))
  5425. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5426. ;; Evaluate the compiled format
  5427. (setq rtn (concat (eval formatter) txt))
  5428. ;; And finally add the text properties
  5429. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5430. (org-add-props rtn nil
  5431. 'org-category (if thecategory (downcase thecategory) category)
  5432. 'tags (mapcar 'org-downcase-keep-props tags)
  5433. 'org-highest-priority org-highest-priority
  5434. 'org-lowest-priority org-lowest-priority
  5435. 'time-of-day time-of-day
  5436. 'duration duration
  5437. 'effort effort
  5438. 'effort-minutes neffort
  5439. 'txt txt
  5440. 'time time
  5441. 'extra extra
  5442. 'format org-prefix-format-compiled
  5443. 'dotime dotime)))))
  5444. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5445. "Remove tags string from TXT, and add a modified list of tags.
  5446. The modified list may contain inherited tags, and tags matched by
  5447. `org-agenda-hide-tags-regexp' will be removed."
  5448. (when (or add-inherited hide-re)
  5449. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5450. (setq txt (substring txt 0 (match-beginning 0))))
  5451. (setq tags
  5452. (delq nil
  5453. (mapcar (lambda (tg)
  5454. (if (or (and hide-re (string-match hide-re tg))
  5455. (and (not add-inherited)
  5456. (get-text-property 0 'inherited tg)))
  5457. nil
  5458. tg))
  5459. tags)))
  5460. (when tags
  5461. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5462. i)
  5463. (setq txt (concat txt " :"
  5464. (mapconcat
  5465. (lambda (x)
  5466. (setq i (get-text-property 0 'inherited x))
  5467. (if (and have-i (not i))
  5468. (progn
  5469. (setq have-i nil)
  5470. (concat ":" x))
  5471. x))
  5472. tags ":")
  5473. (if have-i "::" ":"))))))
  5474. txt)
  5475. (defun org-downcase-keep-props (s)
  5476. (let ((props (text-properties-at 0 s)))
  5477. (setq s (downcase s))
  5478. (add-text-properties 0 (length s) props s)
  5479. s))
  5480. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5481. (defvar org-agenda-sorting-strategy-selected nil)
  5482. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5483. (catch 'exit
  5484. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5485. ((and todayp (member 'today (car org-agenda-time-grid))))
  5486. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5487. ((member 'weekly (car org-agenda-time-grid)))
  5488. (t (throw 'exit list)))
  5489. (let* ((have (delq nil (mapcar
  5490. (lambda (x) (get-text-property 1 'time-of-day x))
  5491. list)))
  5492. (string (nth 1 org-agenda-time-grid))
  5493. (gridtimes (nth 2 org-agenda-time-grid))
  5494. (req (car org-agenda-time-grid))
  5495. (remove (member 'remove-match req))
  5496. new time)
  5497. (if (and (member 'require-timed req) (not have))
  5498. ;; don't show empty grid
  5499. (throw 'exit list))
  5500. (while (setq time (pop gridtimes))
  5501. (unless (and remove (member time have))
  5502. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5503. (push (org-agenda-format-item
  5504. nil string "" nil
  5505. (concat (substring time 0 -2) ":" (substring time -2)))
  5506. new)
  5507. (put-text-property
  5508. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5509. (when (and todayp org-agenda-show-current-time-in-grid)
  5510. (push (org-agenda-format-item
  5511. nil
  5512. org-agenda-current-time-string
  5513. "" nil
  5514. (format-time-string "%H:%M "))
  5515. new)
  5516. (put-text-property
  5517. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5518. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5519. (append new list)
  5520. (append list new)))))
  5521. (defun org-compile-prefix-format (key)
  5522. "Compile the prefix format into a Lisp form that can be evaluated.
  5523. The resulting form and associated variable bindings is returned
  5524. and stored in the variable `org-prefix-format-compiled'."
  5525. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5526. org-prefix-category-length nil
  5527. org-prefix-has-effort nil)
  5528. (let ((s (cond
  5529. ((stringp org-agenda-prefix-format)
  5530. org-agenda-prefix-format)
  5531. ((assq key org-agenda-prefix-format)
  5532. (cdr (assq key org-agenda-prefix-format)))
  5533. (t " %-12:c%?-12t% s")))
  5534. (start 0)
  5535. varform vars var e c f opt)
  5536. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5537. s start)
  5538. (setq var (or (cdr (assoc (match-string 4 s)
  5539. '(("c" . category) ("t" . time) ("s" . extra)
  5540. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5541. 'eval)
  5542. c (or (match-string 3 s) "")
  5543. opt (match-beginning 1)
  5544. start (1+ (match-beginning 0)))
  5545. (if (equal var 'time) (setq org-prefix-has-time t))
  5546. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5547. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5548. (setq f (concat "%" (match-string 2 s) "s"))
  5549. (when (equal var 'category)
  5550. (setq org-prefix-category-length
  5551. (floor (abs (string-to-number (match-string 2 s)))))
  5552. (setq org-prefix-category-max-length
  5553. (let ((x (match-string 2 s)))
  5554. (save-match-data
  5555. (if (string-match "\\.[0-9]+" x)
  5556. (string-to-number (substring (match-string 0 x) 1)))))))
  5557. (if (eq var 'eval)
  5558. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5559. (if opt
  5560. (setq varform
  5561. `(if (equal "" ,var)
  5562. ""
  5563. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5564. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5565. (setq s (replace-match "%s" t nil s))
  5566. (push varform vars))
  5567. (setq vars (nreverse vars))
  5568. (with-current-buffer org-agenda-buffer
  5569. (setq org-prefix-format-compiled
  5570. (list
  5571. `((org-prefix-has-time ,org-prefix-has-time)
  5572. (org-prefix-has-tag ,org-prefix-has-tag)
  5573. (org-prefix-category-length ,org-prefix-category-length)
  5574. (org-prefix-has-effort ,org-prefix-has-effort))
  5575. `(format ,s ,@vars))))))
  5576. (defun org-set-sorting-strategy (key)
  5577. (if (symbolp (car org-agenda-sorting-strategy))
  5578. ;; the old format
  5579. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5580. (setq org-agenda-sorting-strategy-selected
  5581. (or (cdr (assq key org-agenda-sorting-strategy))
  5582. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5583. '(time-up category-keep priority-down)))))
  5584. (defun org-get-time-of-day (s &optional string mod24)
  5585. "Check string S for a time of day.
  5586. If found, return it as a military time number between 0 and 2400.
  5587. If not found, return nil.
  5588. The optional STRING argument forces conversion into a 5 character wide string
  5589. HH:MM."
  5590. (save-match-data
  5591. (when
  5592. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5593. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5594. (let* ((h (string-to-number (match-string 1 s)))
  5595. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5596. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5597. (am-p (equal ampm "am"))
  5598. (h1 (cond ((not ampm) h)
  5599. ((= h 12) (if am-p 0 12))
  5600. (t (+ h (if am-p 0 12)))))
  5601. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5602. (mod h1 24) h1))
  5603. (t0 (+ (* 100 h2) m))
  5604. (t1 (concat (if (>= h1 24) "+" " ")
  5605. (if (and org-agenda-time-leading-zero
  5606. (< t0 1000)) "0" "")
  5607. (if (< t0 100) "0" "")
  5608. (if (< t0 10) "0" "")
  5609. (int-to-string t0))))
  5610. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5611. (defvar org-agenda-before-sorting-filter-function nil
  5612. "Function to be applied to agenda items prior to sorting.
  5613. Prior to sorting also means just before they are inserted into the agenda.
  5614. To aid sorting, you may revisit the original entries and add more text
  5615. properties which will later be used by the sorting functions.
  5616. The function should take a string argument, an agenda line.
  5617. It has access to the text properties in that line, which contain among
  5618. other things, the property `org-hd-marker' that points to the entry
  5619. where the line comes from. Note that not all lines going into the agenda
  5620. have this property, only most.
  5621. The function should return the modified string. It is probably best
  5622. to ONLY change text properties.
  5623. You can also use this function as a filter, by returning nil for lines
  5624. you don't want to have in the agenda at all. For this application, you
  5625. could bind the variable in the options section of a custom command.")
  5626. (defun org-finalize-agenda-entries (list &optional nosort)
  5627. "Sort and concatenate the agenda items."
  5628. (setq list (mapcar 'org-agenda-highlight-todo list))
  5629. (if nosort
  5630. list
  5631. (when org-agenda-before-sorting-filter-function
  5632. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5633. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5634. (defun org-agenda-highlight-todo (x)
  5635. (let ((org-done-keywords org-done-keywords-for-agenda)
  5636. (case-fold-search nil)
  5637. re)
  5638. (if (eq x 'line)
  5639. (save-excursion
  5640. (beginning-of-line 1)
  5641. (setq re (org-get-at-bol 'org-todo-regexp))
  5642. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5643. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5644. (add-text-properties (match-beginning 0) (match-end 1)
  5645. (list 'face (org-get-todo-face 1)))
  5646. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5647. (delete-region (match-beginning 1) (1- (match-end 0)))
  5648. (goto-char (match-beginning 1))
  5649. (insert (format org-agenda-todo-keyword-format s)))))
  5650. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5651. (setq re (get-text-property 0 'org-todo-regexp x))
  5652. (when (and re
  5653. ;; Test `pl' because if there's no heading content,
  5654. ;; there's no point matching to highlight. Note
  5655. ;; that if we didn't test `pl' first, and there
  5656. ;; happened to be no keyword from `org-todo-regexp'
  5657. ;; on this heading line, then the `equal' comparison
  5658. ;; afterwards would spuriously succeed in the case
  5659. ;; where `pl' is nil -- causing an args-out-of-range
  5660. ;; error when we try to add text properties to text
  5661. ;; that isn't there.
  5662. pl
  5663. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5664. x pl) pl))
  5665. (add-text-properties
  5666. (or (match-end 1) (match-end 0)) (match-end 0)
  5667. (list 'face (org-get-todo-face (match-string 2 x)))
  5668. x)
  5669. (when (match-end 1)
  5670. (setq x (concat (substring x 0 (match-end 1))
  5671. (format org-agenda-todo-keyword-format
  5672. (match-string 2 x))
  5673. (org-add-props " " (text-properties-at 0 x))
  5674. (substring x (match-end 3)))))))
  5675. x)))
  5676. (defsubst org-cmp-priority (a b)
  5677. "Compare the priorities of string A and B."
  5678. (let ((pa (or (get-text-property 1 'priority a) 0))
  5679. (pb (or (get-text-property 1 'priority b) 0)))
  5680. (cond ((> pa pb) +1)
  5681. ((< pa pb) -1)
  5682. (t nil))))
  5683. (defsubst org-cmp-effort (a b)
  5684. "Compare the effort values of string A and B."
  5685. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5686. (ea (or (get-text-property 1 'effort-minutes a) def))
  5687. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5688. (cond ((> ea eb) +1)
  5689. ((< ea eb) -1)
  5690. (t nil))))
  5691. (defsubst org-cmp-category (a b)
  5692. "Compare the string values of categories of strings A and B."
  5693. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5694. (cb (or (get-text-property 1 'org-category b) "")))
  5695. (cond ((string-lessp ca cb) -1)
  5696. ((string-lessp cb ca) +1)
  5697. (t nil))))
  5698. (defsubst org-cmp-todo-state (a b)
  5699. "Compare the todo states of strings A and B."
  5700. (let* ((ma (or (get-text-property 1 'org-marker a)
  5701. (get-text-property 1 'org-hd-marker a)))
  5702. (mb (or (get-text-property 1 'org-marker b)
  5703. (get-text-property 1 'org-hd-marker b)))
  5704. (fa (and ma (marker-buffer ma)))
  5705. (fb (and mb (marker-buffer mb)))
  5706. (todo-kwds
  5707. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5708. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5709. (ta (or (get-text-property 1 'todo-state a) ""))
  5710. (tb (or (get-text-property 1 'todo-state b) ""))
  5711. (la (- (length (member ta todo-kwds))))
  5712. (lb (- (length (member tb todo-kwds))))
  5713. (donepa (member ta org-done-keywords-for-agenda))
  5714. (donepb (member tb org-done-keywords-for-agenda)))
  5715. (cond ((and donepa (not donepb)) -1)
  5716. ((and (not donepa) donepb) +1)
  5717. ((< la lb) -1)
  5718. ((< lb la) +1)
  5719. (t nil))))
  5720. (defsubst org-cmp-alpha (a b)
  5721. "Compare the headlines, alphabetically."
  5722. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5723. (plb (text-property-any 0 (length b) 'org-heading t b))
  5724. (ta (and pla (substring a pla)))
  5725. (tb (and plb (substring b plb))))
  5726. (when pla
  5727. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5728. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5729. (setq ta (substring ta (match-end 0))))
  5730. (setq ta (downcase ta)))
  5731. (when plb
  5732. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5733. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5734. (setq tb (substring tb (match-end 0))))
  5735. (setq tb (downcase tb)))
  5736. (cond ((not ta) +1)
  5737. ((not tb) -1)
  5738. ((string-lessp ta tb) -1)
  5739. ((string-lessp tb ta) +1)
  5740. (t nil))))
  5741. (defsubst org-cmp-tag (a b)
  5742. "Compare the string values of the first tags of A and B."
  5743. (let ((ta (car (last (get-text-property 1 'tags a))))
  5744. (tb (car (last (get-text-property 1 'tags b)))))
  5745. (cond ((not ta) +1)
  5746. ((not tb) -1)
  5747. ((string-lessp ta tb) -1)
  5748. ((string-lessp tb ta) +1)
  5749. (t nil))))
  5750. (defsubst org-cmp-time (a b)
  5751. "Compare the time-of-day values of strings A and B."
  5752. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5753. (ta (or (get-text-property 1 'time-of-day a) def))
  5754. (tb (or (get-text-property 1 'time-of-day b) def)))
  5755. (cond ((< ta tb) -1)
  5756. ((< tb ta) +1)
  5757. (t nil))))
  5758. (defsubst org-cmp-habit-p (a b)
  5759. "Compare the todo states of strings A and B."
  5760. (let ((ha (get-text-property 1 'org-habit-p a))
  5761. (hb (get-text-property 1 'org-habit-p b)))
  5762. (cond ((and ha (not hb)) -1)
  5763. ((and (not ha) hb) +1)
  5764. (t nil))))
  5765. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5766. (defun org-entries-lessp (a b)
  5767. "Predicate for sorting agenda entries."
  5768. ;; The following variables will be used when the form is evaluated.
  5769. ;; So even though the compiler complains, keep them.
  5770. (let* ((ss org-agenda-sorting-strategy-selected)
  5771. (time-up (and (org-em 'time-up 'time-down ss)
  5772. (org-cmp-time a b)))
  5773. (time-down (if time-up (- time-up) nil))
  5774. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5775. (org-cmp-priority a b)))
  5776. (priority-down (if priority-up (- priority-up) nil))
  5777. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5778. (org-cmp-effort a b)))
  5779. (effort-down (if effort-up (- effort-up) nil))
  5780. (category-up (and (or (org-em 'category-up 'category-down ss)
  5781. (memq 'category-keep ss))
  5782. (org-cmp-category a b)))
  5783. (category-down (if category-up (- category-up) nil))
  5784. (category-keep (if category-up +1 nil))
  5785. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5786. (org-cmp-tag a b)))
  5787. (tag-down (if tag-up (- tag-up) nil))
  5788. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5789. (org-cmp-todo-state a b)))
  5790. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5791. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5792. (org-cmp-habit-p a b)))
  5793. (habit-down (if habit-up (- habit-up) nil))
  5794. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5795. (org-cmp-alpha a b)))
  5796. (alpha-down (if alpha-up (- alpha-up) nil))
  5797. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5798. user-defined-up user-defined-down)
  5799. (if (and need-user-cmp org-agenda-cmp-user-defined
  5800. (functionp org-agenda-cmp-user-defined))
  5801. (setq user-defined-up
  5802. (funcall org-agenda-cmp-user-defined a b)
  5803. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5804. (cdr (assoc
  5805. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5806. '((-1 . t) (1 . nil) (nil . nil))))))
  5807. ;;; Agenda restriction lock
  5808. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5809. "Overlay to mark the headline to which agenda commands are restricted.")
  5810. (overlay-put org-agenda-restriction-lock-overlay
  5811. 'face 'org-agenda-restriction-lock)
  5812. (overlay-put org-agenda-restriction-lock-overlay
  5813. 'help-echo "Agendas are currently limited to this subtree.")
  5814. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5815. (defun org-agenda-set-restriction-lock (&optional type)
  5816. "Set restriction lock for agenda, to current subtree or file.
  5817. Restriction will be the file if TYPE is `file', or if type is the
  5818. universal prefix '(4), or if the cursor is before the first headline
  5819. in the file. Otherwise, restriction will be to the current subtree."
  5820. (interactive "P")
  5821. (and (equal type '(4)) (setq type 'file))
  5822. (setq type (cond
  5823. (type type)
  5824. ((org-at-heading-p) 'subtree)
  5825. ((condition-case nil (org-back-to-heading t) (error nil))
  5826. 'subtree)
  5827. (t 'file)))
  5828. (if (eq type 'subtree)
  5829. (progn
  5830. (setq org-agenda-restrict t)
  5831. (setq org-agenda-overriding-restriction 'subtree)
  5832. (put 'org-agenda-files 'org-restrict
  5833. (list (buffer-file-name (buffer-base-buffer))))
  5834. (org-back-to-heading t)
  5835. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5836. (move-marker org-agenda-restrict-begin (point))
  5837. (move-marker org-agenda-restrict-end
  5838. (save-excursion (org-end-of-subtree t)))
  5839. (message "Locking agenda restriction to subtree"))
  5840. (put 'org-agenda-files 'org-restrict
  5841. (list (buffer-file-name (buffer-base-buffer))))
  5842. (setq org-agenda-restrict nil)
  5843. (setq org-agenda-overriding-restriction 'file)
  5844. (move-marker org-agenda-restrict-begin nil)
  5845. (move-marker org-agenda-restrict-end nil)
  5846. (message "Locking agenda restriction to file"))
  5847. (setq current-prefix-arg nil)
  5848. (org-agenda-maybe-redo))
  5849. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5850. "Remove the agenda restriction lock."
  5851. (interactive "P")
  5852. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5853. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5854. (setq org-agenda-overriding-restriction nil)
  5855. (setq org-agenda-restrict nil)
  5856. (put 'org-agenda-files 'org-restrict nil)
  5857. (move-marker org-agenda-restrict-begin nil)
  5858. (move-marker org-agenda-restrict-end nil)
  5859. (setq current-prefix-arg nil)
  5860. (message "Agenda restriction lock removed")
  5861. (or noupdate (org-agenda-maybe-redo)))
  5862. (defun org-agenda-maybe-redo ()
  5863. "If there is any window showing the agenda view, update it."
  5864. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5865. (w0 (selected-window)))
  5866. (when w
  5867. (select-window w)
  5868. (org-agenda-redo)
  5869. (select-window w0)
  5870. (if org-agenda-overriding-restriction
  5871. (message "Agenda view shifted to new %s restriction"
  5872. org-agenda-overriding-restriction)
  5873. (message "Agenda restriction lock removed")))))
  5874. ;;; Agenda commands
  5875. (defun org-agenda-check-type (error &rest types)
  5876. "Check if agenda buffer is of allowed type.
  5877. If ERROR is non-nil, throw an error, otherwise just return nil."
  5878. (if (memq org-agenda-type types)
  5879. t
  5880. (if error
  5881. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5882. nil)))
  5883. (defun org-agenda-Quit (&optional arg)
  5884. "Exit agenda by removing the window or the buffer"
  5885. (interactive)
  5886. (if org-agenda-columns-active
  5887. (org-columns-quit)
  5888. (let ((buf (current-buffer)))
  5889. (if (eq org-agenda-window-setup 'other-frame)
  5890. (progn
  5891. (org-agenda-reset-markers)
  5892. (kill-buffer buf)
  5893. (org-columns-remove-overlays)
  5894. (setq org-agenda-archives-mode nil)
  5895. (delete-frame))
  5896. (and (not (eq org-agenda-window-setup 'current-window))
  5897. (not (one-window-p))
  5898. (delete-window))
  5899. (org-agenda-reset-markers)
  5900. (kill-buffer buf)
  5901. (org-columns-remove-overlays)
  5902. (setq org-agenda-archives-mode nil)))
  5903. ;; Maybe restore the pre-agenda window configuration.
  5904. (and org-agenda-restore-windows-after-quit
  5905. (not (eq org-agenda-window-setup 'other-frame))
  5906. org-pre-agenda-window-conf
  5907. (set-window-configuration org-pre-agenda-window-conf))))
  5908. (defun org-agenda-quit ()
  5909. "Exit agenda by killing agenda buffer or burying it when
  5910. `org-agenda-sticky' is non-NIL"
  5911. (interactive)
  5912. (if org-agenda-columns-active
  5913. (org-columns-quit)
  5914. (if org-agenda-sticky
  5915. (let ((buf (current-buffer)))
  5916. (if (eq org-agenda-window-setup 'other-frame)
  5917. (progn
  5918. (delete-frame))
  5919. (and (not (eq org-agenda-window-setup 'current-window))
  5920. (not (one-window-p))
  5921. (delete-window)))
  5922. (with-current-buffer buf
  5923. (bury-buffer)))
  5924. (org-agenda-Quit))))
  5925. (defun org-agenda-exit ()
  5926. "Exit agenda by removing the window or the buffer.
  5927. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5928. Org-mode buffers visited directly by the user will not be touched."
  5929. (interactive)
  5930. (org-release-buffers org-agenda-new-buffers)
  5931. (setq org-agenda-new-buffers nil)
  5932. (org-agenda-Quit))
  5933. (defun org-agenda-kill-all-agenda-buffers ()
  5934. "Kill all buffers in `org-agena-mode'.
  5935. This is used when toggling sticky agendas. You can also explicitly invoke it
  5936. with `C-c a C-k'."
  5937. (interactive)
  5938. (let (blist)
  5939. (dolist (buf (buffer-list))
  5940. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5941. (push buf blist)))
  5942. (mapc 'kill-buffer blist)))
  5943. (defun org-agenda-execute (arg)
  5944. "Execute another agenda command, keeping same window.
  5945. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5946. in the agenda."
  5947. (interactive "P")
  5948. (let ((org-agenda-window-setup 'current-window))
  5949. (org-agenda arg)))
  5950. (defun org-agenda-redo ()
  5951. "Rebuild Agenda.
  5952. When this is the global TODO list, a prefix argument will be interpreted."
  5953. (interactive)
  5954. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  5955. (org-agenda-sticky nil)
  5956. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  5957. org-agenda-buffer-name))
  5958. (org-agenda-keep-modes t)
  5959. (tag-filter org-agenda-tag-filter)
  5960. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5961. (cat-filter org-agenda-category-filter)
  5962. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5963. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5964. (cols org-agenda-columns-active)
  5965. (line (org-current-line))
  5966. (window-line (- line (org-current-line (window-start))))
  5967. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5968. (put 'org-agenda-tag-filter :preset-filter nil)
  5969. (put 'org-agenda-category-filter :preset-filter nil)
  5970. (and cols (org-columns-quit))
  5971. (message "Rebuilding agenda buffer...")
  5972. (org-let lprops '(eval org-agenda-redo-command))
  5973. (setq org-agenda-undo-list nil
  5974. org-agenda-pending-undo-list nil)
  5975. (message "Rebuilding agenda buffer...done")
  5976. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5977. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5978. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5979. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5980. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5981. (org-goto-line line)
  5982. (recenter window-line)))
  5983. (defvar org-global-tags-completion-table nil)
  5984. (defvar org-agenda-filter-form nil)
  5985. (defvar org-agenda-filtered-by-category nil)
  5986. (defun org-agenda-filter-by-category (strip)
  5987. "Keep only those lines in the agenda buffer that have a specific category.
  5988. The category is that of the current line."
  5989. (interactive "P")
  5990. (if org-agenda-filtered-by-category
  5991. (org-agenda-filter-show-all-cat)
  5992. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  5993. (if cat (org-agenda-filter-apply
  5994. (list (concat (if strip "-" "+") cat)) 'category)
  5995. (error "No category at point")))))
  5996. (defun org-find-top-category (&optional pos)
  5997. (save-excursion
  5998. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  5999. (if pos (goto-char pos))
  6000. ;; Skip up to the topmost parent
  6001. (while (ignore-errors (outline-up-heading 1) t))
  6002. (ignore-errors
  6003. (nth 4 (org-heading-components))))))
  6004. (defvar org-agenda-filtered-by-top-category nil)
  6005. (defun org-agenda-filter-by-top-category (strip)
  6006. "Keep only those lines in the agenda buffer that have a specific category.
  6007. The category is that of the current line."
  6008. (interactive "P")
  6009. (if org-agenda-filtered-by-top-category
  6010. (progn
  6011. (setq org-agenda-filtered-by-top-category nil)
  6012. (org-agenda-filter-show-all-cat))
  6013. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6014. (if cat (org-agenda-filter-top-category-apply cat strip)
  6015. (error "No top-level category at point")))))
  6016. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6017. "Keep only those lines in the agenda buffer that have a specific tag.
  6018. The tag is selected with its fast selection letter, as configured.
  6019. With prefix argument STRIP, remove all lines that do have the tag.
  6020. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6021. used to narrow the search - the interactive user can also press `-' or `+'
  6022. to switch to narrowing."
  6023. (interactive "P")
  6024. (let* ((alist org-tag-alist-for-agenda)
  6025. (tag-chars (mapconcat
  6026. (lambda (x) (if (and (not (symbolp (car x)))
  6027. (cdr x))
  6028. (char-to-string (cdr x))
  6029. ""))
  6030. alist ""))
  6031. (efforts (org-split-string
  6032. (or (cdr (assoc (concat org-effort-property "_ALL")
  6033. org-global-properties))
  6034. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6035. "")))
  6036. (effort-op org-agenda-filter-effort-default-operator)
  6037. (effort-prompt "")
  6038. (inhibit-read-only t)
  6039. (current org-agenda-tag-filter)
  6040. maybe-refresh a n tag)
  6041. (unless char
  6042. (message
  6043. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6044. (if narrow "Narrow" "Filter") tag-chars
  6045. (if org-agenda-auto-exclude-function "[RET], " ""))
  6046. (setq char (read-char-exclusive)))
  6047. (when (member char '(?+ ?-))
  6048. ;; Narrowing down
  6049. (cond ((equal char ?-) (setq strip t narrow t))
  6050. ((equal char ?+) (setq strip nil narrow t)))
  6051. (message
  6052. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6053. (setq char (read-char-exclusive)))
  6054. (when (member char '(?< ?> ?= ??))
  6055. ;; An effort operator
  6056. (setq effort-op (char-to-string char))
  6057. (setq alist nil) ; to make sure it will be interpreted as effort.
  6058. (unless (equal char ??)
  6059. (loop for i from 0 to 9 do
  6060. (setq effort-prompt
  6061. (concat
  6062. effort-prompt " ["
  6063. (if (= i 9) "0" (int-to-string (1+ i)))
  6064. "]" (nth i efforts))))
  6065. (message "Effort%s: %s " effort-op effort-prompt)
  6066. (setq char (read-char-exclusive))
  6067. (when (or (< char ?0) (> char ?9))
  6068. (error "Need 1-9,0 to select effort"))))
  6069. (when (equal char ?\t)
  6070. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6071. (org-set-local 'org-global-tags-completion-table
  6072. (org-global-tags-completion-table)))
  6073. (let ((completion-ignore-case t))
  6074. (setq tag (org-icompleting-read
  6075. "Tag: " org-global-tags-completion-table))))
  6076. (cond
  6077. ((equal char ?\r)
  6078. (org-agenda-filter-show-all-tag)
  6079. (when org-agenda-auto-exclude-function
  6080. (setq org-agenda-tag-filter '())
  6081. (dolist (tag (org-agenda-get-represented-tags))
  6082. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6083. (if modifier
  6084. (push modifier org-agenda-tag-filter))))
  6085. (if (not (null org-agenda-tag-filter))
  6086. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6087. (setq maybe-refresh t))
  6088. ((equal char ?/)
  6089. (org-agenda-filter-show-all-tag)
  6090. (when (get 'org-agenda-tag-filter :preset-filter)
  6091. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6092. (setq maybe-refresh t))
  6093. ((equal char ?. )
  6094. (setq org-agenda-tag-filter
  6095. (mapcar (lambda(tag) (concat "+" tag))
  6096. (org-get-at-bol 'tags)))
  6097. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6098. (setq maybe-refresh t))
  6099. ((or (equal char ?\ )
  6100. (setq a (rassoc char alist))
  6101. (and (>= char ?0) (<= char ?9)
  6102. (setq n (if (= char ?0) 9 (- char ?0 1))
  6103. tag (concat effort-op (nth n efforts))
  6104. a (cons tag nil)))
  6105. (and (= char ??)
  6106. (setq tag "?eff")
  6107. a (cons tag nil))
  6108. (and tag (setq a (cons tag nil))))
  6109. (org-agenda-filter-show-all-tag)
  6110. (setq tag (car a))
  6111. (setq org-agenda-tag-filter
  6112. (cons (concat (if strip "-" "+") tag)
  6113. (if narrow current nil)))
  6114. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6115. (setq maybe-refresh t))
  6116. (t (error "Invalid tag selection character %c" char)))
  6117. (when (and maybe-refresh
  6118. (eq org-agenda-clockreport-mode 'with-filter))
  6119. (org-agenda-redo))))
  6120. (defun org-agenda-get-represented-tags ()
  6121. "Get a list of all tags currently represented in the agenda."
  6122. (let (p tags)
  6123. (save-excursion
  6124. (goto-char (point-min))
  6125. (while (setq p (next-single-property-change (point) 'tags))
  6126. (goto-char p)
  6127. (mapc (lambda (x) (add-to-list 'tags x))
  6128. (get-text-property (point) 'tags))))
  6129. tags))
  6130. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6131. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6132. (interactive "P")
  6133. (org-agenda-filter-by-tag strip char 'refine))
  6134. (defun org-agenda-filter-make-matcher ()
  6135. "Create the form that tests a line for agenda filter."
  6136. (let (f f1)
  6137. ;; first compute the tag-filter matcher
  6138. (dolist (x (delete-dups
  6139. (append (get 'org-agenda-tag-filter
  6140. :preset-filter) org-agenda-tag-filter)))
  6141. (if (member x '("-" "+"))
  6142. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6143. (if (string-match "[<=>?]" x)
  6144. (setq f1 (org-agenda-filter-effort-form x))
  6145. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6146. (if (equal (string-to-char x) ?-)
  6147. (setq f1 (list 'not f1))))
  6148. (push f1 f))
  6149. ;; then compute the category-filter matcher
  6150. (dolist (x (delete-dups
  6151. (append (get 'org-agenda-category-filter
  6152. :preset-filter) org-agenda-category-filter)))
  6153. (if (equal "-" (substring x 0 1))
  6154. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6155. (setq f1 (list 'equal (substring x 1) 'cat)))
  6156. (push f1 f))
  6157. (cons 'and (nreverse f))))
  6158. (defun org-agenda-filter-effort-form (e)
  6159. "Return the form to compare the effort of the current line with what E says.
  6160. E looks like \"+<2:25\"."
  6161. (let (op)
  6162. (setq e (substring e 1))
  6163. (setq op (string-to-char e) e (substring e 1))
  6164. (setq op (cond ((equal op ?<) '<=)
  6165. ((equal op ?>) '>=)
  6166. ((equal op ??) op)
  6167. (t '=)))
  6168. (list 'org-agenda-compare-effort (list 'quote op)
  6169. (org-duration-string-to-minutes e))))
  6170. (defun org-agenda-compare-effort (op value)
  6171. "Compare the effort of the current line with VALUE, using OP.
  6172. If the line does not have an effort defined, return nil."
  6173. (let ((eff (org-get-at-bol 'effort-minutes)))
  6174. (if (equal op ??)
  6175. (not eff)
  6176. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6177. value))))
  6178. (defun org-agenda-filter-apply (filter type)
  6179. "Set FILTER as the new agenda filter and apply it."
  6180. (let (tags cat)
  6181. (if (eq type 'tag)
  6182. (setq org-agenda-tag-filter filter)
  6183. (setq org-agenda-category-filter filter))
  6184. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6185. (if (and (eq type 'category)
  6186. (not (equal (substring (car filter) 0 1) "-")))
  6187. ;; Only set `org-agenda-filtered-by-category' to t
  6188. ;; when a unique category is used as the filter
  6189. (setq org-agenda-filtered-by-category t))
  6190. (org-agenda-set-mode-name)
  6191. (save-excursion
  6192. (goto-char (point-min))
  6193. (while (not (eobp))
  6194. (if (org-get-at-bol 'org-marker)
  6195. (progn
  6196. (setq tags (org-get-at-bol 'tags) ; used in eval
  6197. cat (get-text-property (point) 'org-category))
  6198. (if (not (eval org-agenda-filter-form))
  6199. (org-agenda-filter-hide-line type))
  6200. (beginning-of-line 2))
  6201. (beginning-of-line 2))))
  6202. (if (get-char-property (point) 'invisible)
  6203. (ignore-errors (org-agenda-previous-line)))))
  6204. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6205. "Set FILTER as the new agenda filter and apply it."
  6206. (org-agenda-set-mode-name)
  6207. (save-excursion
  6208. (goto-char (point-min))
  6209. (while (not (eobp))
  6210. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6211. (topcat (and pos (org-find-top-category pos))))
  6212. (if (and topcat (funcall (if negative 'identity 'not)
  6213. (string= category topcat)))
  6214. (org-agenda-filter-hide-line 'category)))
  6215. (beginning-of-line 2)))
  6216. (if (get-char-property (point) 'invisible)
  6217. (org-agenda-previous-line))
  6218. (setq org-agenda-filtered-by-top-category t))
  6219. (defun org-agenda-filter-hide-line (type)
  6220. (let (ov)
  6221. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6222. (point-at-eol)))
  6223. (overlay-put ov 'invisible t)
  6224. (overlay-put ov 'type type)
  6225. (if (eq type 'tag)
  6226. (push ov org-agenda-tag-filter-overlays)
  6227. (push ov org-agenda-cat-filter-overlays))))
  6228. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6229. (setq pos (or pos (point)))
  6230. (save-excursion
  6231. (dolist (ov (overlays-at pos))
  6232. (when (and (overlay-get ov 'invisible)
  6233. (eq (overlay-get ov 'type) 'tag))
  6234. (goto-char pos)
  6235. (if (< (overlay-start ov) (point-at-eol))
  6236. (move-overlay ov (point-at-eol)
  6237. (overlay-end ov)))))))
  6238. (defun org-agenda-filter-show-all-tag nil
  6239. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6240. (setq org-agenda-tag-filter-overlays nil
  6241. org-agenda-tag-filter nil
  6242. org-agenda-filter-form nil)
  6243. (org-agenda-set-mode-name))
  6244. (defun org-agenda-filter-show-all-cat nil
  6245. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6246. (setq org-agenda-cat-filter-overlays nil
  6247. org-agenda-filtered-by-category nil
  6248. org-agenda-category-filter nil
  6249. org-agenda-filter-form nil)
  6250. (org-agenda-set-mode-name))
  6251. (defun org-agenda-manipulate-query-add ()
  6252. "Manipulate the query by adding a search term with positive selection.
  6253. Positive selection means the term must be matched for selection of an entry."
  6254. (interactive)
  6255. (org-agenda-manipulate-query ?\[))
  6256. (defun org-agenda-manipulate-query-subtract ()
  6257. "Manipulate the query by adding a search term with negative selection.
  6258. Negative selection means term must not be matched for selection of an entry."
  6259. (interactive)
  6260. (org-agenda-manipulate-query ?\]))
  6261. (defun org-agenda-manipulate-query-add-re ()
  6262. "Manipulate the query by adding a search regexp with positive selection.
  6263. Positive selection means the regexp must match for selection of an entry."
  6264. (interactive)
  6265. (org-agenda-manipulate-query ?\{))
  6266. (defun org-agenda-manipulate-query-subtract-re ()
  6267. "Manipulate the query by adding a search regexp with negative selection.
  6268. Negative selection means regexp must not match for selection of an entry."
  6269. (interactive)
  6270. (org-agenda-manipulate-query ?\}))
  6271. (defun org-agenda-manipulate-query (char)
  6272. (cond
  6273. ((memq org-agenda-type '(timeline agenda))
  6274. (let ((org-agenda-include-inactive-timestamps t))
  6275. (org-agenda-redo))
  6276. (message "Display now includes inactive timestamps as well"))
  6277. ((eq org-agenda-type 'search)
  6278. (org-add-to-string
  6279. 'org-agenda-query-string
  6280. (if org-agenda-last-search-view-search-was-boolean
  6281. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6282. (?\{ . " +{}") (?\} . " -{}"))))
  6283. " "))
  6284. (setq org-agenda-redo-command
  6285. (list 'org-search-view
  6286. org-todo-only
  6287. org-agenda-query-string
  6288. (+ (length org-agenda-query-string)
  6289. (if (member char '(?\{ ?\})) 0 1))))
  6290. (set-register org-agenda-query-register org-agenda-query-string)
  6291. (org-agenda-redo))
  6292. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6293. org-agenda-type))))
  6294. (defun org-add-to-string (var string)
  6295. (set var (concat (symbol-value var) string)))
  6296. (defun org-agenda-goto-date (date)
  6297. "Jump to DATE in agenda."
  6298. (interactive (list (let ((org-read-date-prefer-future
  6299. (eval org-agenda-jump-prefer-future)))
  6300. (org-read-date))))
  6301. (org-agenda-list nil date))
  6302. (defun org-agenda-goto-today ()
  6303. "Go to today."
  6304. (interactive)
  6305. (org-agenda-check-type t 'timeline 'agenda)
  6306. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6307. (cond
  6308. (tdpos (goto-char tdpos))
  6309. ((eq org-agenda-type 'agenda)
  6310. (let* ((sd (org-agenda-compute-starting-span
  6311. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6312. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6313. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6314. (org-agenda-redo)
  6315. (org-agenda-find-same-or-today-or-agenda)))
  6316. (t (error "Cannot find today")))))
  6317. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6318. (goto-char
  6319. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6320. (text-property-any (point-min) (point-max) 'org-today t)
  6321. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6322. (point-min))))
  6323. (defun org-agenda-later (arg)
  6324. "Go forward in time by thee current span.
  6325. With prefix ARG, go forward that many times the current span."
  6326. (interactive "p")
  6327. (org-agenda-check-type t 'agenda)
  6328. (let* ((span org-agenda-current-span)
  6329. (sd org-starting-day)
  6330. (greg (calendar-gregorian-from-absolute sd))
  6331. (cnt (org-get-at-bol 'org-day-cnt))
  6332. greg2)
  6333. (cond
  6334. ((eq span 'day)
  6335. (setq sd (+ arg sd)))
  6336. ((eq span 'week)
  6337. (setq sd (+ (* 7 arg) sd)))
  6338. ((eq span 'month)
  6339. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6340. sd (calendar-absolute-from-gregorian greg2))
  6341. (setcar greg2 (1+ (car greg2))))
  6342. ((eq span 'year)
  6343. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6344. sd (calendar-absolute-from-gregorian greg2))
  6345. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6346. (t
  6347. (setq sd (+ (* span arg) sd))))
  6348. (let ((org-agenda-overriding-arguments
  6349. (list (car org-agenda-last-arguments) sd span t)))
  6350. (org-agenda-redo)
  6351. (org-agenda-find-same-or-today-or-agenda cnt))))
  6352. (defun org-agenda-earlier (arg)
  6353. "Go backward in time by the current span.
  6354. With prefix ARG, go backward that many times the current span."
  6355. (interactive "p")
  6356. (org-agenda-later (- arg)))
  6357. (defun org-agenda-view-mode-dispatch ()
  6358. "Call one of the view mode commands."
  6359. (interactive)
  6360. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6361. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6362. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6363. [E]ntryText")
  6364. (let ((a (read-char-exclusive)))
  6365. (case a
  6366. (?\ (call-interactively 'org-agenda-reset-view))
  6367. (?d (call-interactively 'org-agenda-day-view))
  6368. (?w (call-interactively 'org-agenda-week-view))
  6369. (?m (call-interactively 'org-agenda-month-view))
  6370. (?y (call-interactively 'org-agenda-year-view))
  6371. (?l (call-interactively 'org-agenda-log-mode))
  6372. (?L (org-agenda-log-mode '(4)))
  6373. (?c (org-agenda-log-mode 'clockcheck))
  6374. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6375. (?a (call-interactively 'org-agenda-archives-mode))
  6376. (?A (org-agenda-archives-mode 'files))
  6377. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6378. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6379. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6380. (?D (call-interactively 'org-agenda-toggle-diary))
  6381. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6382. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6383. (org-agenda-check-type t 'timeline 'agenda)
  6384. (org-agenda-redo))
  6385. (message "Display now includes inactive timestamps as well"))
  6386. (?q (message "Abort"))
  6387. (otherwise (error "Invalid key" )))))
  6388. (defun org-agenda-reset-view ()
  6389. "Switch to default view for agenda."
  6390. (interactive)
  6391. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6392. (defun org-agenda-day-view (&optional day-of-year)
  6393. "Switch to daily view for agenda.
  6394. With argument DAY-OF-YEAR, switch to that day of the year."
  6395. (interactive "P")
  6396. (org-agenda-change-time-span 'day day-of-year))
  6397. (defun org-agenda-week-view (&optional iso-week)
  6398. "Switch to daily view for agenda.
  6399. With argument ISO-WEEK, switch to the corresponding ISO week.
  6400. If ISO-WEEK has more then 2 digits, only the last two encode the
  6401. week. Any digits before this encode a year. So 200712 means
  6402. week 12 of year 2007. Years in the range 1938-2037 can also be
  6403. written as 2-digit years."
  6404. (interactive "P")
  6405. (org-agenda-change-time-span 'week iso-week))
  6406. (defun org-agenda-month-view (&optional month)
  6407. "Switch to monthly view for agenda.
  6408. With argument MONTH, switch to that month."
  6409. (interactive "P")
  6410. (org-agenda-change-time-span 'month month))
  6411. (defun org-agenda-year-view (&optional year)
  6412. "Switch to yearly view for agenda.
  6413. With argument YEAR, switch to that year.
  6414. If MONTH has more then 2 digits, only the last two encode the
  6415. month. Any digits before this encode a year. So 200712 means
  6416. December year 2007. Years in the range 1938-2037 can also be
  6417. written as 2-digit years."
  6418. (interactive "P")
  6419. (when year
  6420. (setq year (org-small-year-to-year year)))
  6421. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6422. (org-agenda-change-time-span 'year year)
  6423. (error "Abort")))
  6424. (defun org-agenda-change-time-span (span &optional n)
  6425. "Change the agenda view to SPAN.
  6426. SPAN may be `day', `week', `month', `year'."
  6427. (org-agenda-check-type t 'agenda)
  6428. (if (and (not n) (equal org-agenda-current-span span))
  6429. (error "Viewing span is already \"%s\"" span))
  6430. (let* ((sd (or (org-get-at-bol 'day)
  6431. org-starting-day))
  6432. (sd (org-agenda-compute-starting-span sd span n))
  6433. (org-agenda-overriding-arguments
  6434. (or org-agenda-overriding-arguments
  6435. (list (car org-agenda-last-arguments) sd span t))))
  6436. (org-agenda-redo)
  6437. (org-agenda-find-same-or-today-or-agenda))
  6438. (org-agenda-set-mode-name)
  6439. (message "Switched to %s view" span))
  6440. (defun org-agenda-compute-starting-span (sd span &optional n)
  6441. "Compute starting date for agenda.
  6442. SPAN may be `day', `week', `month', `year'. The return value
  6443. is a cons cell with the starting date and the number of days,
  6444. so that the date SD will be in that range."
  6445. (let* ((greg (calendar-gregorian-from-absolute sd))
  6446. (dg (nth 1 greg))
  6447. (mg (car greg))
  6448. (yg (nth 2 greg)))
  6449. (cond
  6450. ((eq span 'day)
  6451. (when n
  6452. (setq sd (+ (calendar-absolute-from-gregorian
  6453. (list mg 1 yg))
  6454. n -1))))
  6455. ((eq span 'week)
  6456. (let* ((nt (calendar-day-of-week
  6457. (calendar-gregorian-from-absolute sd)))
  6458. (d (if org-agenda-start-on-weekday
  6459. (- nt org-agenda-start-on-weekday)
  6460. 0))
  6461. y1)
  6462. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6463. (when n
  6464. (require 'cal-iso)
  6465. (when (> n 99)
  6466. (setq y1 (org-small-year-to-year (/ n 100))
  6467. n (mod n 100)))
  6468. (setq sd
  6469. (calendar-absolute-from-iso
  6470. (list n 1
  6471. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6472. ((eq span 'month)
  6473. (let (y1)
  6474. (when (and n (> n 99))
  6475. (setq y1 (org-small-year-to-year (/ n 100))
  6476. n (mod n 100)))
  6477. (setq sd (calendar-absolute-from-gregorian
  6478. (list (or n mg) 1 (or y1 yg))))))
  6479. ((eq span 'year)
  6480. (setq sd (calendar-absolute-from-gregorian
  6481. (list 1 1 (or n yg))))))
  6482. sd))
  6483. (defun org-agenda-next-date-line (&optional arg)
  6484. "Jump to the next line indicating a date in agenda buffer."
  6485. (interactive "p")
  6486. (org-agenda-check-type t 'agenda 'timeline)
  6487. (beginning-of-line 1)
  6488. ;; This does not work if user makes date format that starts with a blank
  6489. (if (looking-at "^\\S-") (forward-char 1))
  6490. (if (not (re-search-forward "^\\S-" nil t arg))
  6491. (progn
  6492. (backward-char 1)
  6493. (error "No next date after this line in this buffer")))
  6494. (goto-char (match-beginning 0)))
  6495. (defun org-agenda-previous-date-line (&optional arg)
  6496. "Jump to the previous line indicating a date in agenda buffer."
  6497. (interactive "p")
  6498. (org-agenda-check-type t 'agenda 'timeline)
  6499. (beginning-of-line 1)
  6500. (if (not (re-search-backward "^\\S-" nil t arg))
  6501. (error "No previous date before this line in this buffer")))
  6502. ;; Initialize the highlight
  6503. (defvar org-hl (make-overlay 1 1))
  6504. (overlay-put org-hl 'face 'highlight)
  6505. (defun org-highlight (begin end &optional buffer)
  6506. "Highlight a region with overlay."
  6507. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6508. (defun org-unhighlight ()
  6509. "Detach overlay INDEX."
  6510. (org-detach-overlay org-hl))
  6511. ;; FIXME this is currently not used.
  6512. (defun org-highlight-until-next-command (beg end &optional buffer)
  6513. "Move the highlight overlay to BEG/END, remove it before the next command."
  6514. (org-highlight beg end buffer)
  6515. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6516. (defun org-unhighlight-once ()
  6517. "Remove the highlight from its position, and this function from the hook."
  6518. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6519. (org-unhighlight))
  6520. (defun org-agenda-follow-mode ()
  6521. "Toggle follow mode in an agenda buffer."
  6522. (interactive)
  6523. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6524. (org-agenda-set-mode-name)
  6525. (org-agenda-do-context-action)
  6526. (message "Follow mode is %s"
  6527. (if org-agenda-follow-mode "on" "off")))
  6528. (defun org-agenda-entry-text-mode (&optional arg)
  6529. "Toggle entry text mode in an agenda buffer."
  6530. (interactive "P")
  6531. (setq org-agenda-entry-text-mode (or (integerp arg)
  6532. (not org-agenda-entry-text-mode)))
  6533. (org-agenda-entry-text-hide)
  6534. (and org-agenda-entry-text-mode
  6535. (let ((org-agenda-entry-text-maxlines
  6536. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6537. (org-agenda-entry-text-show)))
  6538. (org-agenda-set-mode-name)
  6539. (message "Entry text mode is %s. Maximum number of lines is %d"
  6540. (if org-agenda-entry-text-mode "on" "off")
  6541. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6542. (defun org-agenda-clockreport-mode (&optional with-filter)
  6543. "Toggle clocktable mode in an agenda buffer.
  6544. With prefix arg WITH-FILTER, make the clocktable respect the current
  6545. agenda filter."
  6546. (interactive "P")
  6547. (org-agenda-check-type t 'agenda)
  6548. (if with-filter
  6549. (setq org-agenda-clockreport-mode 'with-filter)
  6550. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6551. (org-agenda-set-mode-name)
  6552. (org-agenda-redo)
  6553. (message "Clocktable mode is %s"
  6554. (if org-agenda-clockreport-mode "on" "off")))
  6555. (defun org-agenda-log-mode (&optional special)
  6556. "Toggle log mode in an agenda buffer.
  6557. With argument SPECIAL, show all possible log items, not only the ones
  6558. configured in `org-agenda-log-mode-items'.
  6559. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6560. (interactive "P")
  6561. (org-agenda-check-type t 'agenda 'timeline)
  6562. (setq org-agenda-show-log
  6563. (cond
  6564. ((equal special '(16)) 'only)
  6565. ((eq special 'clockcheck)
  6566. (if (eq org-agenda-show-log 'clockcheck)
  6567. nil 'clockcheck))
  6568. (special '(closed clock state))
  6569. (t (not org-agenda-show-log))))
  6570. (org-agenda-set-mode-name)
  6571. (org-agenda-redo)
  6572. (message "Log mode is %s"
  6573. (if org-agenda-show-log "on" "off")))
  6574. (defun org-agenda-archives-mode (&optional with-files)
  6575. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6576. When called with a prefix argument, include all archive files as well."
  6577. (interactive "P")
  6578. (setq org-agenda-archives-mode
  6579. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6580. (org-agenda-set-mode-name)
  6581. (org-agenda-redo)
  6582. (message
  6583. "%s"
  6584. (cond
  6585. ((eq org-agenda-archives-mode nil)
  6586. "No archives are included")
  6587. ((eq org-agenda-archives-mode 'trees)
  6588. (format "Trees with :%s: tag are included" org-archive-tag))
  6589. ((eq org-agenda-archives-mode t)
  6590. (format "Trees with :%s: tag and all active archive files are included"
  6591. org-archive-tag)))))
  6592. (defun org-agenda-toggle-diary ()
  6593. "Toggle diary inclusion in an agenda buffer."
  6594. (interactive)
  6595. (org-agenda-check-type t 'agenda)
  6596. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6597. (org-agenda-redo)
  6598. (org-agenda-set-mode-name)
  6599. (message "Diary inclusion turned %s"
  6600. (if org-agenda-include-diary "on" "off")))
  6601. (defun org-agenda-toggle-deadlines ()
  6602. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6603. (interactive)
  6604. (org-agenda-check-type t 'agenda)
  6605. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6606. (org-agenda-redo)
  6607. (org-agenda-set-mode-name)
  6608. (message "Deadlines inclusion turned %s"
  6609. (if org-agenda-include-deadlines "on" "off")))
  6610. (defun org-agenda-toggle-time-grid ()
  6611. "Toggle time grid in an agenda buffer."
  6612. (interactive)
  6613. (org-agenda-check-type t 'agenda)
  6614. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6615. (org-agenda-redo)
  6616. (org-agenda-set-mode-name)
  6617. (message "Time-grid turned %s"
  6618. (if org-agenda-use-time-grid "on" "off")))
  6619. (defun org-agenda-set-mode-name ()
  6620. "Set the mode name to indicate all the small mode settings."
  6621. (setq mode-name
  6622. (list "Org-Agenda"
  6623. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6624. " "
  6625. '(:eval (org-agenda-span-name org-agenda-current-span))
  6626. (if org-agenda-follow-mode " Follow" "")
  6627. (if org-agenda-entry-text-mode " ETxt" "")
  6628. (if org-agenda-include-diary " Diary" "")
  6629. (if org-agenda-include-deadlines " Ddl" "")
  6630. (if org-agenda-use-time-grid " Grid" "")
  6631. (if (and (boundp 'org-habit-show-habits)
  6632. org-habit-show-habits) " Habit" "")
  6633. (cond
  6634. ((consp org-agenda-show-log) " LogAll")
  6635. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6636. (org-agenda-show-log " Log")
  6637. (t ""))
  6638. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6639. :preset-filter))
  6640. '(:eval (org-propertize
  6641. (concat " <"
  6642. (mapconcat
  6643. 'identity
  6644. (append
  6645. (get 'org-agenda-category-filter :preset-filter)
  6646. org-agenda-category-filter)
  6647. "")
  6648. ">")
  6649. 'face 'org-agenda-filter-category
  6650. 'help-echo "Category used in filtering"))
  6651. "")
  6652. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6653. :preset-filter))
  6654. '(:eval (org-propertize
  6655. (concat " {"
  6656. (mapconcat
  6657. 'identity
  6658. (append
  6659. (get 'org-agenda-tag-filter :preset-filter)
  6660. org-agenda-tag-filter)
  6661. "")
  6662. "}")
  6663. 'face 'org-agenda-filter-tags
  6664. 'help-echo "Tags used in filtering"))
  6665. "")
  6666. (if org-agenda-archives-mode
  6667. (if (eq org-agenda-archives-mode t)
  6668. " Archives"
  6669. (format " :%s:" org-archive-tag))
  6670. "")
  6671. (if org-agenda-clockreport-mode
  6672. (if (eq org-agenda-clockreport-mode 'with-filter)
  6673. " Clock{}" " Clock")
  6674. "")))
  6675. (force-mode-line-update))
  6676. (defun org-agenda-post-command-hook ()
  6677. (setq org-agenda-type
  6678. (or (get-text-property (point) 'org-agenda-type)
  6679. (get-text-property (max (point-min) (1- (point)))
  6680. 'org-agenda-type))))
  6681. (defun org-agenda-next-line ()
  6682. "Move cursor to the next line, and show if follow mode is active."
  6683. (interactive)
  6684. (call-interactively 'next-line)
  6685. (org-agenda-do-context-action))
  6686. (defun org-agenda-previous-line ()
  6687. "Move cursor to the previous line, and show if follow-mode is active."
  6688. (interactive)
  6689. (call-interactively 'previous-line)
  6690. (org-agenda-do-context-action))
  6691. (defun org-agenda-do-context-action ()
  6692. "Show outline path and, maybe, follow mode window."
  6693. (let ((m (org-get-at-bol 'org-marker)))
  6694. (when (and (markerp m) (marker-buffer m))
  6695. (and org-agenda-follow-mode
  6696. (if org-agenda-follow-indirect
  6697. (org-agenda-tree-to-indirect-buffer)
  6698. (org-agenda-show)))
  6699. (and org-agenda-show-outline-path
  6700. (org-with-point-at m (org-display-outline-path t))))))
  6701. (defun org-agenda-show-priority ()
  6702. "Show the priority of the current item.
  6703. This priority is composed of the main priority given with the [#A] cookies,
  6704. and by additional input from the age of a schedules or deadline entry."
  6705. (interactive)
  6706. (let* ((pri (org-get-at-bol 'priority)))
  6707. (message "Priority is %d" (if pri pri -1000))))
  6708. (defun org-agenda-show-tags ()
  6709. "Show the tags applicable to the current item."
  6710. (interactive)
  6711. (let* ((tags (org-get-at-bol 'tags)))
  6712. (if tags
  6713. (message "Tags are :%s:"
  6714. (org-no-properties (mapconcat 'identity tags ":")))
  6715. (message "No tags associated with this line"))))
  6716. (defun org-agenda-goto (&optional highlight)
  6717. "Go to the Org-mode file which contains the item at point."
  6718. (interactive)
  6719. (let* ((marker (or (org-get-at-bol 'org-marker)
  6720. (org-agenda-error)))
  6721. (buffer (marker-buffer marker))
  6722. (pos (marker-position marker)))
  6723. (switch-to-buffer-other-window buffer)
  6724. (widen)
  6725. (push-mark)
  6726. (goto-char pos)
  6727. (when (derived-mode-p 'org-mode)
  6728. (org-show-context 'agenda)
  6729. (save-excursion
  6730. (and (outline-next-heading)
  6731. (org-flag-heading nil)))) ; show the next heading
  6732. (when (outline-invisible-p)
  6733. (show-entry)) ; display invisible text
  6734. (recenter (/ (window-height) 2))
  6735. (run-hooks 'org-agenda-after-show-hook)
  6736. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6737. (defvar org-agenda-after-show-hook nil
  6738. "Normal hook run after an item has been shown from the agenda.
  6739. Point is in the buffer where the item originated.")
  6740. (defun org-agenda-kill ()
  6741. "Kill the entry or subtree belonging to the current agenda entry."
  6742. (interactive)
  6743. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6744. (let* ((marker (or (org-get-at-bol 'org-marker)
  6745. (org-agenda-error)))
  6746. (buffer (marker-buffer marker))
  6747. (pos (marker-position marker))
  6748. (type (org-get-at-bol 'type))
  6749. dbeg dend (n 0) conf)
  6750. (org-with-remote-undo buffer
  6751. (with-current-buffer buffer
  6752. (save-excursion
  6753. (goto-char pos)
  6754. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  6755. (setq dbeg (progn (org-back-to-heading t) (point))
  6756. dend (org-end-of-subtree t t))
  6757. (setq dbeg (point-at-bol)
  6758. dend (min (point-max) (1+ (point-at-eol)))))
  6759. (goto-char dbeg)
  6760. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6761. (setq conf (or (eq t org-agenda-confirm-kill)
  6762. (and (numberp org-agenda-confirm-kill)
  6763. (> n org-agenda-confirm-kill))))
  6764. (and conf
  6765. (not (y-or-n-p
  6766. (format "Delete entry with %d lines in buffer \"%s\"? "
  6767. n (buffer-name buffer))))
  6768. (error "Abort"))
  6769. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6770. (with-current-buffer buffer (delete-region dbeg dend))
  6771. (message "Agenda item and source killed"))))
  6772. (defvar org-archive-default-command)
  6773. (defun org-agenda-archive-default ()
  6774. "Archive the entry or subtree belonging to the current agenda entry."
  6775. (interactive)
  6776. (require 'org-archive)
  6777. (org-agenda-archive-with org-archive-default-command))
  6778. (defun org-agenda-archive-default-with-confirmation ()
  6779. "Archive the entry or subtree belonging to the current agenda entry."
  6780. (interactive)
  6781. (require 'org-archive)
  6782. (org-agenda-archive-with org-archive-default-command 'confirm))
  6783. (defun org-agenda-archive ()
  6784. "Archive the entry or subtree belonging to the current agenda entry."
  6785. (interactive)
  6786. (org-agenda-archive-with 'org-archive-subtree))
  6787. (defun org-agenda-archive-to-archive-sibling ()
  6788. "Move the entry to the archive sibling."
  6789. (interactive)
  6790. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6791. (defun org-agenda-archive-with (cmd &optional confirm)
  6792. "Move the entry to the archive sibling."
  6793. (interactive)
  6794. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6795. (let* ((marker (or (org-get-at-bol 'org-marker)
  6796. (org-agenda-error)))
  6797. (buffer (marker-buffer marker))
  6798. (pos (marker-position marker)))
  6799. (org-with-remote-undo buffer
  6800. (with-current-buffer buffer
  6801. (if (derived-mode-p 'org-mode)
  6802. (if (and confirm
  6803. (not (y-or-n-p "Archive this subtree or entry? ")))
  6804. (error "Abort")
  6805. (save-excursion
  6806. (goto-char pos)
  6807. (org-remove-subtree-entries-from-agenda)
  6808. (org-back-to-heading t)
  6809. (funcall cmd)))
  6810. (error "Archiving works only in Org-mode files"))))))
  6811. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6812. "Remove all lines in the agenda that correspond to a given subtree.
  6813. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6814. If this information is not given, the function uses the tree at point."
  6815. (let ((buf (or buf (current-buffer))) m p)
  6816. (save-excursion
  6817. (unless (and beg end)
  6818. (org-back-to-heading t)
  6819. (setq beg (point))
  6820. (org-end-of-subtree t)
  6821. (setq end (point)))
  6822. (set-buffer (get-buffer org-agenda-buffer-name))
  6823. (save-excursion
  6824. (goto-char (point-max))
  6825. (beginning-of-line 1)
  6826. (while (not (bobp))
  6827. (when (and (setq m (org-get-at-bol 'org-marker))
  6828. (equal buf (marker-buffer m))
  6829. (setq p (marker-position m))
  6830. (>= p beg)
  6831. (< p end))
  6832. (let ((inhibit-read-only t))
  6833. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6834. (beginning-of-line 0))))))
  6835. (defun org-agenda-refile (&optional goto rfloc no-update)
  6836. "Refile the item at point."
  6837. (interactive "P")
  6838. (if (equal goto '(16))
  6839. (org-refile-goto-last-stored)
  6840. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6841. (org-agenda-error)))
  6842. (buffer (marker-buffer marker))
  6843. (pos (marker-position marker))
  6844. (rfloc (or rfloc
  6845. (org-refile-get-location
  6846. (if goto "Goto" "Refile to") buffer
  6847. org-refile-allow-creating-parent-nodes))))
  6848. (with-current-buffer buffer
  6849. (save-excursion
  6850. (save-restriction
  6851. (widen)
  6852. (goto-char marker)
  6853. (org-remove-subtree-entries-from-agenda)
  6854. (org-refile goto buffer rfloc)))))
  6855. (unless no-update (org-agenda-redo))))
  6856. (defun org-agenda-open-link (&optional arg)
  6857. "Follow the link in the current line, if any.
  6858. This looks for a link in the displayed line in the agenda. It also looks
  6859. at the text of the entry itself."
  6860. (interactive "P")
  6861. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6862. (org-get-at-bol 'org-marker)))
  6863. (buffer (and marker (marker-buffer marker)))
  6864. (prefix (buffer-substring
  6865. (point-at-bol) (point-at-eol))))
  6866. (cond
  6867. (buffer
  6868. (with-current-buffer buffer
  6869. (save-excursion
  6870. (save-restriction
  6871. (widen)
  6872. (goto-char marker)
  6873. (org-offer-links-in-entry arg prefix)))))
  6874. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6875. (save-excursion
  6876. (beginning-of-line 1)
  6877. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6878. (org-open-link-from-string (match-string 1)))
  6879. (t (error "No link to open here")))))
  6880. (defun org-agenda-copy-local-variable (var)
  6881. "Get a variable from a referenced buffer and install it here."
  6882. (let ((m (org-get-at-bol 'org-marker)))
  6883. (when (and m (buffer-live-p (marker-buffer m)))
  6884. (org-set-local var (with-current-buffer (marker-buffer m)
  6885. (symbol-value var))))))
  6886. (defun org-agenda-switch-to (&optional delete-other-windows)
  6887. "Go to the Org-mode file which contains the item at point."
  6888. (interactive)
  6889. (if (and org-return-follows-link
  6890. (not (org-get-at-bol 'org-marker))
  6891. (org-in-regexp org-bracket-link-regexp))
  6892. (org-open-link-from-string (match-string 0))
  6893. (let* ((marker (or (org-get-at-bol 'org-marker)
  6894. (org-agenda-error)))
  6895. (buffer (marker-buffer marker))
  6896. (pos (marker-position marker)))
  6897. (org-pop-to-buffer-same-window buffer)
  6898. (and delete-other-windows (delete-other-windows))
  6899. (widen)
  6900. (goto-char pos)
  6901. (when (derived-mode-p 'org-mode)
  6902. (org-show-context 'agenda)
  6903. (save-excursion
  6904. (and (outline-next-heading)
  6905. (org-flag-heading nil))) ; show the next heading
  6906. (when (outline-invisible-p)
  6907. (show-entry)))))) ; display invisible text
  6908. (defun org-agenda-goto-mouse (ev)
  6909. "Go to the Org-mode file which contains the item at the mouse click."
  6910. (interactive "e")
  6911. (mouse-set-point ev)
  6912. (org-agenda-goto))
  6913. (defun org-agenda-show (&optional full-entry)
  6914. "Display the Org-mode file which contains the item at point.
  6915. With prefix argument FULL-ENTRY, make the entire entry visible
  6916. if it was hidden in the outline."
  6917. (interactive "P")
  6918. (let ((win (selected-window)))
  6919. (if full-entry
  6920. (let ((org-show-entry-below t))
  6921. (org-agenda-goto t))
  6922. (org-agenda-goto t))
  6923. (select-window win)))
  6924. (defvar org-agenda-show-window nil)
  6925. (defun org-agenda-show-and-scroll-up (&optional arg)
  6926. "Display the Org-mode file which contains the item at point.
  6927. When called repeatedly, scroll the window that is displaying the buffer.
  6928. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6929. `show-subtree' to display the item, so that drawers and logbooks stay
  6930. folded."
  6931. (interactive "P")
  6932. (let ((win (selected-window)))
  6933. (if (and (window-live-p org-agenda-show-window)
  6934. (eq this-command last-command))
  6935. (progn
  6936. (select-window org-agenda-show-window)
  6937. (ignore-errors (scroll-up)))
  6938. (org-agenda-goto t)
  6939. (if arg (org-show-entry) (show-subtree))
  6940. (setq org-agenda-show-window (selected-window)))
  6941. (select-window win)))
  6942. (defun org-agenda-show-scroll-down ()
  6943. "Scroll down the window showing the agenda."
  6944. (interactive)
  6945. (let ((win (selected-window)))
  6946. (when (window-live-p org-agenda-show-window)
  6947. (select-window org-agenda-show-window)
  6948. (ignore-errors (scroll-down))
  6949. (select-window win))))
  6950. (defun org-agenda-show-1 (&optional more)
  6951. "Display the Org-mode file which contains the item at point.
  6952. The prefix arg selects the amount of information to display:
  6953. 0 hide the subtree
  6954. 1 just show the entry according to defaults.
  6955. 2 show the children view
  6956. 3 show the subtree view
  6957. 4 show the entire subtree and any LOGBOOK drawers
  6958. 5 show the entire subtree and any drawers
  6959. With prefix argument FULL-ENTRY, make the entire entry visible
  6960. if it was hidden in the outline."
  6961. (interactive "p")
  6962. (let ((win (selected-window)))
  6963. (org-agenda-goto t)
  6964. (org-recenter-heading 1)
  6965. (cond
  6966. ((= more 0)
  6967. (hide-subtree)
  6968. (save-excursion
  6969. (org-back-to-heading)
  6970. (run-hook-with-args 'org-cycle-hook 'folded))
  6971. (message "Remote: FOLDED"))
  6972. ((and (org-called-interactively-p 'any) (= more 1))
  6973. (message "Remote: show with default settings"))
  6974. ((= more 2)
  6975. (show-entry)
  6976. (show-children)
  6977. (save-excursion
  6978. (org-back-to-heading)
  6979. (run-hook-with-args 'org-cycle-hook 'children))
  6980. (message "Remote: CHILDREN"))
  6981. ((= more 3)
  6982. (show-subtree)
  6983. (save-excursion
  6984. (org-back-to-heading)
  6985. (run-hook-with-args 'org-cycle-hook 'subtree))
  6986. (message "Remote: SUBTREE"))
  6987. ((= more 4)
  6988. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6989. (org-drawer-regexp
  6990. (concat "^[ \t]*:\\("
  6991. (mapconcat 'regexp-quote org-drawers "\\|")
  6992. "\\):[ \t]*$")))
  6993. (show-subtree)
  6994. (save-excursion
  6995. (org-back-to-heading)
  6996. (org-cycle-hide-drawers 'subtree)))
  6997. (message "Remote: SUBTREE AND LOGBOOK"))
  6998. ((> more 4)
  6999. (show-subtree)
  7000. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7001. (select-window win)))
  7002. (defun org-recenter-heading (n)
  7003. (save-excursion
  7004. (org-back-to-heading)
  7005. (recenter n)))
  7006. (defvar org-agenda-cycle-counter nil)
  7007. (defun org-agenda-cycle-show (&optional n)
  7008. "Show the current entry in another window, with default settings.
  7009. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7010. When use repeatedly in immediate succession, the remote entry will cycle
  7011. through visibility
  7012. children -> subtree -> folded
  7013. When called with a numeric prefix arg, that arg will be passed through to
  7014. `org-agenda-show-1'. For the interpretation of that argument, see the
  7015. docstring of `org-agenda-show-1'."
  7016. (interactive "P")
  7017. (if (integerp n)
  7018. (setq org-agenda-cycle-counter n)
  7019. (if (not (eq last-command this-command))
  7020. (setq org-agenda-cycle-counter 1)
  7021. (if (equal org-agenda-cycle-counter 0)
  7022. (setq org-agenda-cycle-counter 2)
  7023. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7024. (if (> org-agenda-cycle-counter 3)
  7025. (setq org-agenda-cycle-counter 0)))))
  7026. (org-agenda-show-1 org-agenda-cycle-counter))
  7027. (defun org-agenda-recenter (arg)
  7028. "Display the Org-mode file which contains the item at point and recenter."
  7029. (interactive "P")
  7030. (let ((win (selected-window)))
  7031. (org-agenda-goto t)
  7032. (recenter arg)
  7033. (select-window win)))
  7034. (defun org-agenda-show-mouse (ev)
  7035. "Display the Org-mode file which contains the item at the mouse click."
  7036. (interactive "e")
  7037. (mouse-set-point ev)
  7038. (org-agenda-show))
  7039. (defun org-agenda-check-no-diary ()
  7040. "Check if the entry is a diary link and abort if yes."
  7041. (if (org-get-at-bol 'org-agenda-diary-link)
  7042. (org-agenda-error)))
  7043. (defun org-agenda-error ()
  7044. (error "Command not allowed in this line"))
  7045. (defun org-agenda-tree-to-indirect-buffer ()
  7046. "Show the subtree corresponding to the current entry in an indirect buffer.
  7047. This calls the command `org-tree-to-indirect-buffer' from the original
  7048. Org-mode buffer.
  7049. With numerical prefix arg ARG, go up to this level and then take that tree.
  7050. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7051. use the dedicated frame)."
  7052. (interactive)
  7053. (if (and current-prefix-arg (listp current-prefix-arg))
  7054. (org-agenda-do-tree-to-indirect-buffer)
  7055. (let ((agenda-window (selected-window))
  7056. (indirect-window
  7057. (and org-last-indirect-buffer
  7058. (get-buffer-window org-last-indirect-buffer))))
  7059. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7060. (unwind-protect
  7061. (progn
  7062. (unless (and indirect-window (window-live-p indirect-window))
  7063. (setq indirect-window (split-window agenda-window)))
  7064. (select-window indirect-window)
  7065. (switch-to-buffer org-last-indirect-buffer :norecord)
  7066. (fit-window-to-buffer indirect-window))
  7067. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7068. (defun org-agenda-do-tree-to-indirect-buffer ()
  7069. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7070. (org-agenda-check-no-diary)
  7071. (let* ((marker (or (org-get-at-bol 'org-marker)
  7072. (org-agenda-error)))
  7073. (buffer (marker-buffer marker))
  7074. (pos (marker-position marker)))
  7075. (with-current-buffer buffer
  7076. (save-excursion
  7077. (goto-char pos)
  7078. (call-interactively 'org-tree-to-indirect-buffer)))))
  7079. (defvar org-last-heading-marker (make-marker)
  7080. "Marker pointing to the headline that last changed its TODO state
  7081. by a remote command from the agenda.")
  7082. (defun org-agenda-todo-nextset ()
  7083. "Switch TODO entry to next sequence."
  7084. (interactive)
  7085. (org-agenda-todo 'nextset))
  7086. (defun org-agenda-todo-previousset ()
  7087. "Switch TODO entry to previous sequence."
  7088. (interactive)
  7089. (org-agenda-todo 'previousset))
  7090. (defun org-agenda-todo (&optional arg)
  7091. "Cycle TODO state of line at point, also in Org-mode file.
  7092. This changes the line at point, all other lines in the agenda referring to
  7093. the same tree node, and the headline of the tree node in the Org-mode file."
  7094. (interactive "P")
  7095. (org-agenda-check-no-diary)
  7096. (let* ((col (current-column))
  7097. (marker (or (org-get-at-bol 'org-marker)
  7098. (org-agenda-error)))
  7099. (buffer (marker-buffer marker))
  7100. (pos (marker-position marker))
  7101. (hdmarker (org-get-at-bol 'org-hd-marker))
  7102. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7103. (inhibit-read-only t)
  7104. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7105. (org-with-remote-undo buffer
  7106. (with-current-buffer buffer
  7107. (widen)
  7108. (goto-char pos)
  7109. (org-show-context 'agenda)
  7110. (save-excursion
  7111. (and (outline-next-heading)
  7112. (org-flag-heading nil))) ; show the next heading
  7113. (let ((current-prefix-arg arg))
  7114. (call-interactively 'org-todo))
  7115. (and (bolp) (forward-char 1))
  7116. (setq newhead (org-get-heading))
  7117. (when (and (org-bound-and-true-p
  7118. org-agenda-headline-snapshot-before-repeat)
  7119. (not (equal org-agenda-headline-snapshot-before-repeat
  7120. newhead))
  7121. todayp)
  7122. (setq newhead org-agenda-headline-snapshot-before-repeat
  7123. just-one t))
  7124. (save-excursion
  7125. (org-back-to-heading)
  7126. (move-marker org-last-heading-marker (point))))
  7127. (beginning-of-line 1)
  7128. (save-excursion
  7129. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7130. (org-move-to-column col))))
  7131. (defun org-agenda-add-note (&optional arg)
  7132. "Add a time-stamped note to the entry at point."
  7133. (interactive "P")
  7134. (org-agenda-check-no-diary)
  7135. (let* ((marker (or (org-get-at-bol 'org-marker)
  7136. (org-agenda-error)))
  7137. (buffer (marker-buffer marker))
  7138. (pos (marker-position marker))
  7139. (hdmarker (org-get-at-bol 'org-hd-marker))
  7140. (inhibit-read-only t))
  7141. (with-current-buffer buffer
  7142. (widen)
  7143. (goto-char pos)
  7144. (org-show-context 'agenda)
  7145. (save-excursion
  7146. (and (outline-next-heading)
  7147. (org-flag-heading nil))) ; show the next heading
  7148. (org-add-note))))
  7149. (defun org-agenda-change-all-lines (newhead hdmarker
  7150. &optional fixface just-this)
  7151. "Change all lines in the agenda buffer which match HDMARKER.
  7152. The new content of the line will be NEWHEAD (as modified by
  7153. `org-agenda-format-item'). HDMARKER is checked with
  7154. `equal' against all `org-hd-marker' text properties in the file.
  7155. If FIXFACE is non-nil, the face of each item is modified according to
  7156. the new TODO state.
  7157. If JUST-THIS is non-nil, change just the current line, not all.
  7158. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7159. (let* ((inhibit-read-only t)
  7160. (line (org-current-line))
  7161. (org-agenda-buffer (current-buffer))
  7162. (thetags (with-current-buffer (marker-buffer hdmarker)
  7163. (save-excursion (save-restriction (widen)
  7164. (goto-char hdmarker)
  7165. (org-get-tags-at)))))
  7166. props m pl undone-face done-face finish new dotime cat tags)
  7167. (save-excursion
  7168. (goto-char (point-max))
  7169. (beginning-of-line 1)
  7170. (while (not finish)
  7171. (setq finish (bobp))
  7172. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7173. (or (not just-this) (= (org-current-line) line))
  7174. (equal m hdmarker))
  7175. (setq props (text-properties-at (point))
  7176. dotime (org-get-at-bol 'dotime)
  7177. cat (org-get-at-bol 'org-category)
  7178. tags thetags
  7179. new
  7180. (let ((org-prefix-format-compiled
  7181. (or (get-text-property (point) 'format)
  7182. org-prefix-format-compiled))
  7183. (extra (org-get-at-bol 'extra)))
  7184. (with-current-buffer (marker-buffer hdmarker)
  7185. (save-excursion
  7186. (save-restriction
  7187. (widen)
  7188. (org-agenda-format-item extra newhead cat tags dotime)))))
  7189. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7190. undone-face (org-get-at-bol 'undone-face)
  7191. done-face (org-get-at-bol 'done-face))
  7192. (beginning-of-line 1)
  7193. (cond
  7194. ((equal new "")
  7195. (and (looking-at ".*\n?") (replace-match "")))
  7196. ((looking-at ".*")
  7197. (replace-match new t t)
  7198. (beginning-of-line 1)
  7199. (add-text-properties (point-at-bol) (point-at-eol) props)
  7200. (when fixface
  7201. (add-text-properties
  7202. (point-at-bol) (point-at-eol)
  7203. (list 'face
  7204. (if org-last-todo-state-is-todo
  7205. undone-face done-face))))
  7206. (org-agenda-highlight-todo 'line)
  7207. (beginning-of-line 1))
  7208. (t (error "Line update did not work"))))
  7209. (beginning-of-line 0)))
  7210. (org-finalize-agenda)))
  7211. (defun org-agenda-align-tags (&optional line)
  7212. "Align all tags in agenda items to `org-agenda-tags-column'."
  7213. (let ((inhibit-read-only t) l c)
  7214. (save-excursion
  7215. (goto-char (if line (point-at-bol) (point-min)))
  7216. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7217. (if line (point-at-eol) nil) t)
  7218. (add-text-properties
  7219. (match-beginning 2) (match-end 2)
  7220. (list 'face (delq nil (let ((prop (get-text-property
  7221. (match-beginning 2) 'face)))
  7222. (or (listp prop) (setq prop (list prop)))
  7223. (if (memq 'org-tag prop)
  7224. prop
  7225. (cons 'org-tag prop))))))
  7226. (setq l (- (match-end 2) (match-beginning 2))
  7227. c (if (< org-agenda-tags-column 0)
  7228. (- (abs org-agenda-tags-column) l)
  7229. org-agenda-tags-column))
  7230. (delete-region (match-beginning 1) (match-end 1))
  7231. (goto-char (match-beginning 1))
  7232. (insert (org-add-props
  7233. (make-string (max 1 (- c (current-column))) ?\ )
  7234. (plist-put (copy-sequence (text-properties-at (point)))
  7235. 'face nil))))
  7236. (goto-char (point-min))
  7237. (org-font-lock-add-tag-faces (point-max)))))
  7238. (defun org-agenda-priority-up ()
  7239. "Increase the priority of line at point, also in Org-mode file."
  7240. (interactive)
  7241. (org-agenda-priority 'up))
  7242. (defun org-agenda-priority-down ()
  7243. "Decrease the priority of line at point, also in Org-mode file."
  7244. (interactive)
  7245. (org-agenda-priority 'down))
  7246. (defun org-agenda-priority (&optional force-direction)
  7247. "Set the priority of line at point, also in Org-mode file.
  7248. This changes the line at point, all other lines in the agenda referring to
  7249. the same tree node, and the headline of the tree node in the Org-mode file."
  7250. (interactive)
  7251. (unless org-enable-priority-commands
  7252. (error "Priority commands are disabled"))
  7253. (org-agenda-check-no-diary)
  7254. (let* ((marker (or (org-get-at-bol 'org-marker)
  7255. (org-agenda-error)))
  7256. (hdmarker (org-get-at-bol 'org-hd-marker))
  7257. (buffer (marker-buffer hdmarker))
  7258. (pos (marker-position hdmarker))
  7259. (inhibit-read-only t)
  7260. newhead)
  7261. (org-with-remote-undo buffer
  7262. (with-current-buffer buffer
  7263. (widen)
  7264. (goto-char pos)
  7265. (org-show-context 'agenda)
  7266. (save-excursion
  7267. (and (outline-next-heading)
  7268. (org-flag-heading nil))) ; show the next heading
  7269. (funcall 'org-priority force-direction)
  7270. (end-of-line 1)
  7271. (setq newhead (org-get-heading)))
  7272. (org-agenda-change-all-lines newhead hdmarker)
  7273. (beginning-of-line 1))))
  7274. ;; FIXME: should fix the tags property of the agenda line.
  7275. (defun org-agenda-set-tags (&optional tag onoff)
  7276. "Set tags for the current headline."
  7277. (interactive)
  7278. (org-agenda-check-no-diary)
  7279. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7280. (call-interactively 'org-change-tag-in-region)
  7281. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7282. (org-agenda-error)))
  7283. (buffer (marker-buffer hdmarker))
  7284. (pos (marker-position hdmarker))
  7285. (inhibit-read-only t)
  7286. newhead)
  7287. (org-with-remote-undo buffer
  7288. (with-current-buffer buffer
  7289. (widen)
  7290. (goto-char pos)
  7291. (save-excursion
  7292. (org-show-context 'agenda))
  7293. (save-excursion
  7294. (and (outline-next-heading)
  7295. (org-flag-heading nil))) ; show the next heading
  7296. (goto-char pos)
  7297. (if tag
  7298. (org-toggle-tag tag onoff)
  7299. (call-interactively 'org-set-tags))
  7300. (end-of-line 1)
  7301. (setq newhead (org-get-heading)))
  7302. (org-agenda-change-all-lines newhead hdmarker)
  7303. (beginning-of-line 1)))))
  7304. (defun org-agenda-set-property ()
  7305. "Set a property for the current headline."
  7306. (interactive)
  7307. (org-agenda-check-no-diary)
  7308. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7309. (org-agenda-error)))
  7310. (buffer (marker-buffer hdmarker))
  7311. (pos (marker-position hdmarker))
  7312. (inhibit-read-only t)
  7313. newhead)
  7314. (org-with-remote-undo buffer
  7315. (with-current-buffer buffer
  7316. (widen)
  7317. (goto-char pos)
  7318. (save-excursion
  7319. (org-show-context 'agenda))
  7320. (save-excursion
  7321. (and (outline-next-heading)
  7322. (org-flag-heading nil))) ; show the next heading
  7323. (goto-char pos)
  7324. (call-interactively 'org-set-property)))))
  7325. (defun org-agenda-set-effort ()
  7326. "Set the effort property for the current headline."
  7327. (interactive)
  7328. (org-agenda-check-no-diary)
  7329. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7330. (org-agenda-error)))
  7331. (buffer (marker-buffer hdmarker))
  7332. (pos (marker-position hdmarker))
  7333. (inhibit-read-only t)
  7334. newhead)
  7335. (org-with-remote-undo buffer
  7336. (with-current-buffer buffer
  7337. (widen)
  7338. (goto-char pos)
  7339. (save-excursion
  7340. (org-show-context 'agenda))
  7341. (save-excursion
  7342. (and (outline-next-heading)
  7343. (org-flag-heading nil))) ; show the next heading
  7344. (goto-char pos)
  7345. (call-interactively 'org-set-effort)
  7346. (end-of-line 1)
  7347. (setq newhead (org-get-heading)))
  7348. (org-agenda-change-all-lines newhead hdmarker))))
  7349. (defun org-agenda-toggle-archive-tag ()
  7350. "Toggle the archive tag for the current entry."
  7351. (interactive)
  7352. (org-agenda-check-no-diary)
  7353. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7354. (org-agenda-error)))
  7355. (buffer (marker-buffer hdmarker))
  7356. (pos (marker-position hdmarker))
  7357. (inhibit-read-only t)
  7358. newhead)
  7359. (org-with-remote-undo buffer
  7360. (with-current-buffer buffer
  7361. (widen)
  7362. (goto-char pos)
  7363. (org-show-context 'agenda)
  7364. (save-excursion
  7365. (and (outline-next-heading)
  7366. (org-flag-heading nil))) ; show the next heading
  7367. (call-interactively 'org-toggle-archive-tag)
  7368. (end-of-line 1)
  7369. (setq newhead (org-get-heading)))
  7370. (org-agenda-change-all-lines newhead hdmarker)
  7371. (beginning-of-line 1))))
  7372. (defun org-agenda-do-date-later (arg)
  7373. (interactive "P")
  7374. (cond
  7375. ((or (equal arg '(16))
  7376. (memq last-command
  7377. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7378. (setq this-command 'org-agenda-date-later-minutes)
  7379. (org-agenda-date-later-minutes 1))
  7380. ((or (equal arg '(4))
  7381. (memq last-command
  7382. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7383. (setq this-command 'org-agenda-date-later-hours)
  7384. (org-agenda-date-later-hours 1))
  7385. (t
  7386. (org-agenda-date-later (prefix-numeric-value arg)))))
  7387. (defun org-agenda-do-date-earlier (arg)
  7388. (interactive "P")
  7389. (cond
  7390. ((or (equal arg '(16))
  7391. (memq last-command
  7392. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7393. (setq this-command 'org-agenda-date-earlier-minutes)
  7394. (org-agenda-date-earlier-minutes 1))
  7395. ((or (equal arg '(4))
  7396. (memq last-command
  7397. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7398. (setq this-command 'org-agenda-date-earlier-hours)
  7399. (org-agenda-date-earlier-hours 1))
  7400. (t
  7401. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7402. (defun org-agenda-date-later (arg &optional what)
  7403. "Change the date of this item to ARG day(s) later."
  7404. (interactive "p")
  7405. (org-agenda-check-type t 'agenda 'timeline)
  7406. (org-agenda-check-no-diary)
  7407. (let* ((marker (or (org-get-at-bol 'org-marker)
  7408. (org-agenda-error)))
  7409. (buffer (marker-buffer marker))
  7410. (pos (marker-position marker))
  7411. cdate today)
  7412. (org-with-remote-undo buffer
  7413. (with-current-buffer buffer
  7414. (widen)
  7415. (goto-char pos)
  7416. (if (not (org-at-timestamp-p))
  7417. (error "Cannot find time stamp"))
  7418. (when (and org-agenda-move-date-from-past-immediately-to-today
  7419. (equal arg 1)
  7420. (or (not what) (eq what 'day))
  7421. (not (save-match-data (org-at-date-range-p))))
  7422. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7423. cdate (calendar-absolute-from-gregorian
  7424. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7425. today (org-today))
  7426. (if (> today cdate)
  7427. ;; immediately shift to today
  7428. (setq arg (- today cdate))))
  7429. (org-timestamp-change arg (or what 'day))
  7430. (when (and (org-at-date-range-p)
  7431. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7432. (let ((end org-last-changed-timestamp))
  7433. (org-timestamp-change arg (or what 'day))
  7434. (setq org-last-changed-timestamp
  7435. (concat org-last-changed-timestamp "--" end)))))
  7436. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7437. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7438. (defun org-agenda-date-earlier (arg &optional what)
  7439. "Change the date of this item to ARG day(s) earlier."
  7440. (interactive "p")
  7441. (org-agenda-date-later (- arg) what))
  7442. (defun org-agenda-date-later-minutes (arg)
  7443. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7444. (interactive "p")
  7445. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7446. (org-agenda-date-later arg 'minute))
  7447. (defun org-agenda-date-earlier-minutes (arg)
  7448. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7449. (interactive "p")
  7450. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7451. (org-agenda-date-earlier arg 'minute))
  7452. (defun org-agenda-date-later-hours (arg)
  7453. "Change the time of this item, in hour steps."
  7454. (interactive "p")
  7455. (org-agenda-date-later arg 'hour))
  7456. (defun org-agenda-date-earlier-hours (arg)
  7457. "Change the time of this item, in hour steps."
  7458. (interactive "p")
  7459. (org-agenda-date-earlier arg 'hour))
  7460. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7461. "Show new date stamp via text properties."
  7462. ;; We use text properties to make this undoable
  7463. (let ((inhibit-read-only t)
  7464. (buffer-invisibility-spec))
  7465. (setq stamp (concat " " prefix " => " stamp))
  7466. (save-excursion
  7467. (goto-char (point-max))
  7468. (while (not (bobp))
  7469. (when (equal marker (org-get-at-bol 'org-marker))
  7470. (org-move-to-column (- (window-width) (length stamp)) t)
  7471. (org-agenda-fix-tags-filter-overlays-at (point))
  7472. (if (featurep 'xemacs)
  7473. ;; Use `duplicable' property to trigger undo recording
  7474. (let ((ex (make-extent nil nil))
  7475. (gl (make-glyph stamp)))
  7476. (set-glyph-face gl 'secondary-selection)
  7477. (set-extent-properties
  7478. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7479. (insert-extent ex (1- (point)) (point-at-eol)))
  7480. (add-text-properties
  7481. (1- (point)) (point-at-eol)
  7482. (list 'display (org-add-props stamp nil
  7483. 'face 'secondary-selection))))
  7484. (beginning-of-line 1))
  7485. (beginning-of-line 0)))))
  7486. (defun org-agenda-date-prompt (arg)
  7487. "Change the date of this item. Date is prompted for, with default today.
  7488. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7489. be used to request time specification in the time stamp."
  7490. (interactive "P")
  7491. (org-agenda-check-type t 'agenda 'timeline)
  7492. (org-agenda-check-no-diary)
  7493. (let* ((marker (or (org-get-at-bol 'org-marker)
  7494. (org-agenda-error)))
  7495. (buffer (marker-buffer marker))
  7496. (pos (marker-position marker)))
  7497. (org-with-remote-undo buffer
  7498. (with-current-buffer buffer
  7499. (widen)
  7500. (goto-char pos)
  7501. (if (not (org-at-timestamp-p t))
  7502. (error "Cannot find time stamp"))
  7503. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7504. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7505. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7506. (defun org-agenda-schedule (arg &optional time)
  7507. "Schedule the item at point.
  7508. ARG is passed through to `org-schedule'."
  7509. (interactive "P")
  7510. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7511. (org-agenda-check-no-diary)
  7512. (let* ((marker (or (org-get-at-bol 'org-marker)
  7513. (org-agenda-error)))
  7514. (type (marker-insertion-type marker))
  7515. (buffer (marker-buffer marker))
  7516. (pos (marker-position marker))
  7517. (org-insert-labeled-timestamps-at-point nil)
  7518. ts)
  7519. (set-marker-insertion-type marker t)
  7520. (org-with-remote-undo buffer
  7521. (with-current-buffer buffer
  7522. (widen)
  7523. (goto-char pos)
  7524. (setq ts (org-schedule arg time)))
  7525. (org-agenda-show-new-time marker ts "S"))
  7526. (message "Item scheduled for %s" ts)))
  7527. (defun org-agenda-deadline (arg &optional time)
  7528. "Schedule the item at point.
  7529. ARG is passed through to `org-deadline'."
  7530. (interactive "P")
  7531. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7532. (org-agenda-check-no-diary)
  7533. (let* ((marker (or (org-get-at-bol 'org-marker)
  7534. (org-agenda-error)))
  7535. (buffer (marker-buffer marker))
  7536. (pos (marker-position marker))
  7537. (org-insert-labeled-timestamps-at-point nil)
  7538. ts)
  7539. (org-with-remote-undo buffer
  7540. (with-current-buffer buffer
  7541. (widen)
  7542. (goto-char pos)
  7543. (setq ts (org-deadline arg time)))
  7544. (org-agenda-show-new-time marker ts "D"))
  7545. (message "Deadline for this item set to %s" ts)))
  7546. (defun org-agenda-action ()
  7547. "Select entry for agenda action, or execute an agenda action.
  7548. This command prompts for another letter. Valid inputs are:
  7549. m Mark the entry at point for an agenda action
  7550. s Schedule the marked entry to the date at the cursor
  7551. d Set the deadline of the marked entry to the date at the cursor
  7552. r Call `org-remember' with cursor date as the default date
  7553. c Call `org-capture' with cursor date as the default date
  7554. SPC Show marked entry in other window
  7555. TAB Visit marked entry in other window
  7556. The cursor may be at a date in the calendar, or in the Org agenda."
  7557. (interactive)
  7558. (let (ans)
  7559. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7560. (setq ans (read-char-exclusive))
  7561. (cond
  7562. ((equal ans ?m)
  7563. ;; Mark this entry
  7564. (if (eq major-mode 'org-agenda-mode)
  7565. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7566. (org-get-at-bol 'org-marker))))
  7567. (if m
  7568. (progn
  7569. (move-marker org-agenda-action-marker
  7570. (marker-position m) (marker-buffer m))
  7571. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7572. (error "Don't know which entry to mark")))
  7573. (error "This command works only in the agenda")))
  7574. ((equal ans ?s)
  7575. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7576. ((equal ans ?d)
  7577. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7578. ((equal ans ?r)
  7579. (org-agenda-do-action '(org-remember) t))
  7580. ((equal ans ?c)
  7581. (org-agenda-do-action '(org-capture) t))
  7582. ((equal ans ?\ )
  7583. (let ((cw (selected-window)))
  7584. (org-switch-to-buffer-other-window
  7585. (marker-buffer org-agenda-action-marker))
  7586. (goto-char org-agenda-action-marker)
  7587. (org-show-context 'agenda)
  7588. (select-window cw)))
  7589. ((equal ans ?\C-i)
  7590. (org-switch-to-buffer-other-window
  7591. (marker-buffer org-agenda-action-marker))
  7592. (goto-char org-agenda-action-marker)
  7593. (org-show-context 'agenda))
  7594. (t (error "Invalid agenda action %c" ans)))))
  7595. (defun org-agenda-do-action (form &optional current-buffer)
  7596. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7597. (let ((org-overriding-default-time (org-get-cursor-date)))
  7598. (if current-buffer
  7599. (eval form)
  7600. (if (not (marker-buffer org-agenda-action-marker))
  7601. (error "No entry has been selected for agenda action")
  7602. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7603. (save-excursion
  7604. (save-restriction
  7605. (widen)
  7606. (goto-char org-agenda-action-marker)
  7607. (eval form))))))))
  7608. (defun org-agenda-clock-in (&optional arg)
  7609. "Start the clock on the currently selected item."
  7610. (interactive "P")
  7611. (org-agenda-check-no-diary)
  7612. (if (equal arg '(4))
  7613. (org-clock-in arg)
  7614. (let* ((marker (or (org-get-at-bol 'org-marker)
  7615. (org-agenda-error)))
  7616. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7617. marker))
  7618. (pos (marker-position marker))
  7619. newhead)
  7620. (org-with-remote-undo (marker-buffer marker)
  7621. (with-current-buffer (marker-buffer marker)
  7622. (widen)
  7623. (goto-char pos)
  7624. (org-show-context 'agenda)
  7625. (org-show-entry)
  7626. (org-cycle-hide-drawers 'children)
  7627. (org-clock-in arg)
  7628. (setq newhead (org-get-heading)))
  7629. (org-agenda-change-all-lines newhead hdmarker)))))
  7630. (defun org-agenda-clock-out ()
  7631. "Stop the currently running clock."
  7632. (interactive)
  7633. (unless (marker-buffer org-clock-marker)
  7634. (error "No running clock"))
  7635. (let ((marker (make-marker)) newhead)
  7636. (org-with-remote-undo (marker-buffer org-clock-marker)
  7637. (with-current-buffer (marker-buffer org-clock-marker)
  7638. (save-excursion
  7639. (save-restriction
  7640. (widen)
  7641. (goto-char org-clock-marker)
  7642. (org-back-to-heading t)
  7643. (move-marker marker (point))
  7644. (org-clock-out)
  7645. (setq newhead (org-get-heading))))))
  7646. (org-agenda-change-all-lines newhead marker)
  7647. (move-marker marker nil)))
  7648. (defun org-agenda-clock-cancel (&optional arg)
  7649. "Cancel the currently running clock."
  7650. (interactive "P")
  7651. (unless (marker-buffer org-clock-marker)
  7652. (error "No running clock"))
  7653. (org-with-remote-undo (marker-buffer org-clock-marker)
  7654. (org-clock-cancel)))
  7655. (defun org-agenda-clock-goto ()
  7656. "Jump to the currently clocked in task within the agenda.
  7657. If the currently clocked in task is not listed in the agenda
  7658. buffer, display it in another window."
  7659. (interactive)
  7660. (let (pos)
  7661. (mapc (lambda (o)
  7662. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7663. (setq pos (overlay-start o))))
  7664. (overlays-in (point-min) (point-max)))
  7665. (cond (pos (goto-char pos))
  7666. ;; If the currently clocked entry is not in the agenda
  7667. ;; buffer, we visit it in another window:
  7668. (org-clock-current-task
  7669. (org-switch-to-buffer-other-window (org-clock-goto)))
  7670. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7671. (defun org-agenda-diary-entry-in-org-file ()
  7672. "Make a diary entry in the file `org-agenda-diary-file'."
  7673. (let (d1 d2 char (text "") dp1 dp2)
  7674. (if (equal (buffer-name) "*Calendar*")
  7675. (setq d1 (calendar-cursor-to-date t)
  7676. d2 (car calendar-mark-ring))
  7677. (setq dp1 (get-text-property (point-at-bol) 'day))
  7678. (unless dp1 (error "No date defined in current line"))
  7679. (setq d1 (calendar-gregorian-from-absolute dp1)
  7680. d2 (and (ignore-errors (mark))
  7681. (save-excursion
  7682. (goto-char (mark))
  7683. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7684. (calendar-gregorian-from-absolute dp2))))
  7685. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7686. (setq char (read-char-exclusive))
  7687. (cond
  7688. ((equal char ?d)
  7689. (setq text (read-string "Day entry: "))
  7690. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7691. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7692. ((equal char ?a)
  7693. (setq d1 (list (car d1) (nth 1 d1)
  7694. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7695. (nth 2 d1))))
  7696. (setq text (read-string "Anniversary (use %d to show years): "))
  7697. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7698. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7699. ((equal char ?b)
  7700. (setq text (read-string "Block entry: "))
  7701. (unless (and d1 d2 (not (equal d1 d2)))
  7702. (error "No block of days selected"))
  7703. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7704. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7705. ((equal char ?j)
  7706. (org-switch-to-buffer-other-window
  7707. (find-file-noselect org-agenda-diary-file))
  7708. (require 'org-datetree)
  7709. (org-datetree-find-date-create d1)
  7710. (org-reveal t))
  7711. (t (error "Invalid selection character `%c'" char)))))
  7712. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7713. "Where in `org-agenda-diary-file' should new entries be added?
  7714. Valid values:
  7715. date-tree in the date tree, as child of the date
  7716. top-level as top-level entries at the end of the file."
  7717. :group 'org-agenda
  7718. :type '(choice
  7719. (const :tag "in a date tree" date-tree)
  7720. (const :tag "as top level at end of file" top-level)))
  7721. (defcustom org-agenda-insert-diary-extract-time nil
  7722. "Non-nil means extract any time specification from the diary entry."
  7723. :group 'org-agenda
  7724. :version "24.1"
  7725. :type 'boolean)
  7726. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7727. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7728. If TEXT is not empty, it will become the headline of the new entry, and
  7729. the resulting entry will not be shown. When TEXT is empty, switch to
  7730. `org-agenda-diary-file' and let the user finish the entry there."
  7731. (let ((cw (current-window-configuration)))
  7732. (org-switch-to-buffer-other-window
  7733. (find-file-noselect org-agenda-diary-file))
  7734. (widen)
  7735. (goto-char (point-min))
  7736. (cond
  7737. ((eq type 'anniversary)
  7738. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7739. (progn
  7740. (or (org-at-heading-p t)
  7741. (progn
  7742. (outline-next-heading)
  7743. (insert "* Anniversaries\n\n")
  7744. (beginning-of-line -1)))))
  7745. (outline-next-heading)
  7746. (org-back-over-empty-lines)
  7747. (backward-char 1)
  7748. (insert "\n")
  7749. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7750. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7751. ((eq type 'day)
  7752. (let ((org-prefix-has-time t)
  7753. (org-agenda-time-leading-zero t)
  7754. fmt time time2)
  7755. (if org-agenda-insert-diary-extract-time
  7756. ;; Use org-agenda-format-item to parse text for a time-range and
  7757. ;; remove it. FIXME: This is a hack, we should refactor
  7758. ;; that function to make time extraction available separately
  7759. (setq fmt (org-agenda-format-item nil text nil nil t)
  7760. time (get-text-property 0 'time fmt)
  7761. time2 (if (> (length time) 0)
  7762. ;; split-string removes trailing ...... if
  7763. ;; no end time given. First space
  7764. ;; separates time from date.
  7765. (concat " " (car (split-string time "\\.")))
  7766. nil)
  7767. text (get-text-property 0 'txt fmt)))
  7768. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7769. (org-agenda-insert-diary-as-top-level text)
  7770. (require 'org-datetree)
  7771. (org-datetree-find-date-create d1)
  7772. (org-agenda-insert-diary-make-new-entry text))
  7773. (org-insert-time-stamp (org-time-from-absolute
  7774. (calendar-absolute-from-gregorian d1))
  7775. nil nil nil nil time2))
  7776. (end-of-line 0))
  7777. ((eq type 'block)
  7778. (if (> (calendar-absolute-from-gregorian d1)
  7779. (calendar-absolute-from-gregorian d2))
  7780. (setq d1 (prog1 d2 (setq d2 d1))))
  7781. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7782. (org-agenda-insert-diary-as-top-level text)
  7783. (require 'org-datetree)
  7784. (org-datetree-find-date-create d1)
  7785. (org-agenda-insert-diary-make-new-entry text))
  7786. (org-insert-time-stamp (org-time-from-absolute
  7787. (calendar-absolute-from-gregorian d1)))
  7788. (insert "--")
  7789. (org-insert-time-stamp (org-time-from-absolute
  7790. (calendar-absolute-from-gregorian d2)))
  7791. (end-of-line 0)))
  7792. (if (string-match "\\S-" text)
  7793. (progn
  7794. (set-window-configuration cw)
  7795. (message "%s entry added to %s"
  7796. (capitalize (symbol-name type))
  7797. (abbreviate-file-name org-agenda-diary-file)))
  7798. (org-reveal t)
  7799. (message "Please finish entry here"))))
  7800. (defun org-agenda-insert-diary-as-top-level (text)
  7801. "Make new entry as a top-level entry at the end of the file.
  7802. Add TEXT as headline, and position the cursor in the second line so that
  7803. a timestamp can be added there."
  7804. (widen)
  7805. (goto-char (point-max))
  7806. (or (bolp) (insert "\n"))
  7807. (insert "* " text "\n")
  7808. (if org-adapt-indentation (org-indent-to-column 2)))
  7809. (defun org-agenda-insert-diary-make-new-entry (text)
  7810. "Make new entry as last child of current entry.
  7811. Add TEXT as headline, and position the cursor in the second line so that
  7812. a timestamp can be added there."
  7813. (let ((org-show-following-heading t)
  7814. (org-show-siblings t)
  7815. (org-show-hierarchy-above t)
  7816. (org-show-entry-below t)
  7817. col)
  7818. (outline-next-heading)
  7819. (org-back-over-empty-lines)
  7820. (or (looking-at "[ \t]*$")
  7821. (progn (insert "\n") (backward-char 1)))
  7822. (org-insert-heading nil t)
  7823. (org-do-demote)
  7824. (setq col (current-column))
  7825. (insert text "\n")
  7826. (if org-adapt-indentation (org-indent-to-column col))
  7827. (let ((org-show-following-heading t)
  7828. (org-show-siblings t)
  7829. (org-show-hierarchy-above t)
  7830. (org-show-entry-below t))
  7831. (org-show-context))))
  7832. (defun org-agenda-diary-entry ()
  7833. "Make a diary entry, like the `i' command from the calendar.
  7834. All the standard commands work: block, weekly etc.
  7835. When `org-agenda-diary-file' points to a file,
  7836. `org-agenda-diary-entry-in-org-file' is called instead to create
  7837. entries in that Org-mode file."
  7838. (interactive)
  7839. (org-agenda-check-type t 'agenda 'timeline)
  7840. (if (not (eq org-agenda-diary-file 'diary-file))
  7841. (org-agenda-diary-entry-in-org-file)
  7842. (require 'diary-lib)
  7843. (let* ((char (progn
  7844. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7845. (read-char-exclusive)))
  7846. (cmd (cdr (assoc char
  7847. '((?d . insert-diary-entry)
  7848. (?w . insert-weekly-diary-entry)
  7849. (?m . insert-monthly-diary-entry)
  7850. (?y . insert-yearly-diary-entry)
  7851. (?a . insert-anniversary-diary-entry)
  7852. (?b . insert-block-diary-entry)
  7853. (?c . insert-cyclic-diary-entry)))))
  7854. (oldf (symbol-function 'calendar-cursor-to-date))
  7855. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7856. (point (point))
  7857. (mark (or (mark t) (point))))
  7858. (unless cmd
  7859. (error "No command associated with <%c>" char))
  7860. (unless (and (get-text-property point 'day)
  7861. (or (not (equal ?b char))
  7862. (get-text-property mark 'day)))
  7863. (error "Don't know which date to use for diary entry"))
  7864. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7865. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7866. (let ((calendar-mark-ring
  7867. (list (calendar-gregorian-from-absolute
  7868. (or (get-text-property mark 'day)
  7869. (get-text-property point 'day))))))
  7870. (unwind-protect
  7871. (progn
  7872. (fset 'calendar-cursor-to-date
  7873. (lambda (&optional error dummy)
  7874. (calendar-gregorian-from-absolute
  7875. (get-text-property point 'day))))
  7876. (call-interactively cmd))
  7877. (fset 'calendar-cursor-to-date oldf))))))
  7878. (defun org-agenda-execute-calendar-command (cmd)
  7879. "Execute a calendar command from the agenda, with the date associated to
  7880. the cursor position."
  7881. (org-agenda-check-type t 'agenda 'timeline)
  7882. (require 'diary-lib)
  7883. (unless (get-text-property (point) 'day)
  7884. (error "Don't know which date to use for calendar command"))
  7885. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7886. (point (point))
  7887. (date (calendar-gregorian-from-absolute
  7888. (get-text-property point 'day)))
  7889. ;; the following 2 vars are needed in the calendar
  7890. (displayed-month (car date))
  7891. (displayed-year (nth 2 date)))
  7892. (unwind-protect
  7893. (progn
  7894. (fset 'calendar-cursor-to-date
  7895. (lambda (&optional error dummy)
  7896. (calendar-gregorian-from-absolute
  7897. (get-text-property point 'day))))
  7898. (call-interactively cmd))
  7899. (fset 'calendar-cursor-to-date oldf))))
  7900. (defun org-agenda-phases-of-moon ()
  7901. "Display the phases of the moon for the 3 months around the cursor date."
  7902. (interactive)
  7903. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7904. (defun org-agenda-holidays ()
  7905. "Display the holidays for the 3 months around the cursor date."
  7906. (interactive)
  7907. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7908. (defvar calendar-longitude)
  7909. (defvar calendar-latitude)
  7910. (defvar calendar-location-name)
  7911. (defun org-agenda-sunrise-sunset (arg)
  7912. "Display sunrise and sunset for the cursor date.
  7913. Latitude and longitude can be specified with the variables
  7914. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7915. argument, latitude and longitude will be prompted for."
  7916. (interactive "P")
  7917. (require 'solar)
  7918. (let ((calendar-longitude (if arg nil calendar-longitude))
  7919. (calendar-latitude (if arg nil calendar-latitude))
  7920. (calendar-location-name
  7921. (if arg "the given coordinates" calendar-location-name)))
  7922. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7923. (defun org-agenda-goto-calendar ()
  7924. "Open the Emacs calendar with the date at the cursor."
  7925. (interactive)
  7926. (org-agenda-check-type t 'agenda 'timeline)
  7927. (let* ((day (or (get-text-property (point) 'day)
  7928. (error "Don't know which date to open in calendar")))
  7929. (date (calendar-gregorian-from-absolute day))
  7930. (calendar-move-hook nil)
  7931. (calendar-view-holidays-initially-flag nil)
  7932. (calendar-view-diary-initially-flag nil))
  7933. (calendar)
  7934. (calendar-goto-date date)))
  7935. ;;;###autoload
  7936. (defun org-calendar-goto-agenda ()
  7937. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7938. This is a command that has to be installed in `calendar-mode-map'."
  7939. (interactive)
  7940. (org-agenda-list nil (calendar-absolute-from-gregorian
  7941. (calendar-cursor-to-date))
  7942. nil))
  7943. (defun org-agenda-convert-date ()
  7944. (interactive)
  7945. (org-agenda-check-type t 'agenda 'timeline)
  7946. (let ((day (get-text-property (point) 'day))
  7947. date s)
  7948. (unless day
  7949. (error "Don't know which date to convert"))
  7950. (setq date (calendar-gregorian-from-absolute day))
  7951. (setq s (concat
  7952. "Gregorian: " (calendar-date-string date) "\n"
  7953. "ISO: " (calendar-iso-date-string date) "\n"
  7954. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7955. "Julian: " (calendar-julian-date-string date) "\n"
  7956. "Astron. JD: " (calendar-astro-date-string date)
  7957. " (Julian date number at noon UTC)\n"
  7958. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7959. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7960. "French: " (calendar-french-date-string date) "\n"
  7961. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7962. "Mayan: " (calendar-mayan-date-string date) "\n"
  7963. "Coptic: " (calendar-coptic-date-string date) "\n"
  7964. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7965. "Persian: " (calendar-persian-date-string date) "\n"
  7966. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7967. (with-output-to-temp-buffer "*Dates*"
  7968. (princ s))
  7969. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7970. ;;; Bulk commands
  7971. (defvar org-agenda-bulk-marked-entries nil
  7972. "List of markers that refer to marked entries in the agenda.")
  7973. (defun org-agenda-bulk-marked-p ()
  7974. (eq (get-char-property (point-at-bol) 'type)
  7975. 'org-marked-entry-overlay))
  7976. (defun org-agenda-bulk-mark (&optional arg)
  7977. "Mark the entry at point for future bulk action."
  7978. (interactive "p")
  7979. (dotimes (i (or arg 1))
  7980. (unless (org-get-at-bol 'org-agenda-diary-link)
  7981. (let* ((m (org-get-at-bol 'org-hd-marker))
  7982. ov)
  7983. (unless (org-agenda-bulk-marked-p)
  7984. (unless m (error "Nothing to mark at point"))
  7985. (push m org-agenda-bulk-marked-entries)
  7986. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7987. (org-overlay-display ov "> "
  7988. (org-get-todo-face "TODO")
  7989. 'evaporate)
  7990. (overlay-put ov 'type 'org-marked-entry-overlay))
  7991. (beginning-of-line 2)
  7992. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7993. (beginning-of-line 2))
  7994. (message "%d entries marked for bulk action"
  7995. (length org-agenda-bulk-marked-entries))))))
  7996. (defun org-agenda-bulk-mark-regexp (regexp)
  7997. "Mark entries match REGEXP."
  7998. (interactive "sMark entries matching regexp: ")
  7999. (let (entries-marked)
  8000. (save-excursion
  8001. (goto-char (point-min))
  8002. (goto-char (next-single-property-change (point) 'txt))
  8003. (while (re-search-forward regexp nil t)
  8004. (when (string-match regexp (get-text-property (point) 'txt))
  8005. (setq entries-marked (+ entries-marked 1))
  8006. (call-interactively 'org-agenda-bulk-mark))))
  8007. (if (not entries-marked)
  8008. (message "No entry matching this regexp."))))
  8009. (defun org-agenda-bulk-unmark ()
  8010. "Unmark the entry at point for future bulk action."
  8011. (interactive)
  8012. (when (org-agenda-bulk-marked-p)
  8013. (org-agenda-bulk-remove-overlays
  8014. (point-at-bol) (+ 2 (point-at-bol)))
  8015. (setq org-agenda-bulk-marked-entries
  8016. (delete (org-get-at-bol 'org-hd-marker)
  8017. org-agenda-bulk-marked-entries)))
  8018. (beginning-of-line 2)
  8019. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8020. (beginning-of-line 2))
  8021. (message "%d entries marked for bulk action"
  8022. (length org-agenda-bulk-marked-entries)))
  8023. (defun org-agenda-bulk-toggle ()
  8024. "Toggle marking the entry at point for bulk action."
  8025. (interactive)
  8026. (if (org-agenda-bulk-marked-p)
  8027. (org-agenda-bulk-unmark)
  8028. (org-agenda-bulk-mark)))
  8029. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8030. "Remove the mark overlays between BEG and END in the agenda buffer.
  8031. BEG and END default to the buffer limits.
  8032. This only removes the overlays, it does not remove the markers
  8033. from the list in `org-agenda-bulk-marked-entries'."
  8034. (interactive)
  8035. (mapc (lambda (ov)
  8036. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8037. (delete-overlay ov)))
  8038. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8039. (defun org-agenda-bulk-remove-all-marks ()
  8040. "Remove all marks in the agenda buffer.
  8041. This will remove the markers, and the overlays."
  8042. (interactive)
  8043. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8044. (setq org-agenda-bulk-marked-entries nil)
  8045. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  8046. (defun org-agenda-bulk-action (&optional arg)
  8047. "Execute an remote-editing action on all marked entries.
  8048. The prefix arg is passed through to the command if possible."
  8049. (interactive "P")
  8050. ;; Make sure we have markers, and only valid ones
  8051. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8052. (mapc
  8053. (lambda (m)
  8054. (unless (and (markerp m)
  8055. (marker-buffer m)
  8056. (buffer-live-p (marker-buffer m))
  8057. (marker-position m))
  8058. (error "Marker %s for bulk command is invalid" m)))
  8059. org-agenda-bulk-marked-entries)
  8060. ;; Prompt for the bulk command
  8061. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  8062. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  8063. (when org-agenda-bulk-custom-functions
  8064. (concat " Custom: ["
  8065. (mapconcat (lambda(f) (char-to-string (car f)))
  8066. org-agenda-bulk-custom-functions "")
  8067. "]"))))
  8068. (let* ((action (read-char-exclusive))
  8069. (org-log-refile (if org-log-refile 'time nil))
  8070. (entries (reverse org-agenda-bulk-marked-entries))
  8071. redo-at-end
  8072. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8073. (cond
  8074. ((equal action ?$)
  8075. (setq cmd '(org-agenda-archive)))
  8076. ((equal action ?A)
  8077. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8078. ((member action '(?r ?w))
  8079. (setq rfloc (org-refile-get-location
  8080. "Refile to"
  8081. (marker-buffer (car org-agenda-bulk-marked-entries))
  8082. org-refile-allow-creating-parent-nodes))
  8083. (if (nth 3 rfloc)
  8084. (setcar (nthcdr 3 rfloc)
  8085. (move-marker (make-marker) (nth 3 rfloc)
  8086. (or (get-file-buffer (nth 1 rfloc))
  8087. (find-buffer-visiting (nth 1 rfloc))
  8088. (error "This should not happen")))))
  8089. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8090. redo-at-end t))
  8091. ((equal action ?t)
  8092. (setq state (org-icompleting-read
  8093. "Todo state: "
  8094. (with-current-buffer (marker-buffer (car entries))
  8095. (mapcar 'list org-todo-keywords-1))))
  8096. (setq cmd `(let ((org-inhibit-blocking t)
  8097. (org-inhibit-logging 'note))
  8098. (org-agenda-todo ,state))))
  8099. ((memq action '(?- ?+))
  8100. (setq tag (org-icompleting-read
  8101. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8102. (with-current-buffer (marker-buffer (car entries))
  8103. (delq nil
  8104. (mapcar (lambda (x)
  8105. (if (stringp (car x)) x)) org-tag-alist)))))
  8106. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8107. ((memq action '(?s ?d))
  8108. (let* ((date (unless arg
  8109. (org-read-date
  8110. nil nil nil
  8111. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8112. (ans (if arg nil org-read-date-final-answer))
  8113. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8114. (setq cmd `(let* ((bound (fboundp 'read-string))
  8115. (old (and bound (symbol-function 'read-string))))
  8116. (unwind-protect
  8117. (progn
  8118. (fset 'read-string (lambda (&rest ignore) ,ans))
  8119. (eval '(,c1 arg)))
  8120. (if bound
  8121. (fset 'read-string old)
  8122. (fmakunbound 'read-string)))))))
  8123. ((equal action ?S)
  8124. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8125. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8126. (let ((days (read-number
  8127. (format "Scatter tasks across how many %sdays: "
  8128. (if arg "week" "")) 7)))
  8129. (setq cmd
  8130. `(let ((distance (1+ (random ,days))))
  8131. (if arg
  8132. (let ((dist distance)
  8133. (day-of-week
  8134. (calendar-day-of-week
  8135. (calendar-gregorian-from-absolute (org-today)))))
  8136. (dotimes (i (1+ dist))
  8137. (while (member day-of-week org-agenda-weekend-days)
  8138. (incf distance)
  8139. (incf day-of-week)
  8140. (if (= day-of-week 7)
  8141. (setq day-of-week 0)))
  8142. (incf day-of-week)
  8143. (if (= day-of-week 7)
  8144. (setq day-of-week 0)))))
  8145. ;; silently fail when try to replan a sexp entry
  8146. (condition-case nil
  8147. (let* ((date (calendar-gregorian-from-absolute
  8148. (+ (org-today) distance)))
  8149. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8150. (nth 2 date))))
  8151. (org-agenda-schedule nil time))
  8152. (error nil)))))))
  8153. ((assoc action org-agenda-bulk-custom-functions)
  8154. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8155. redo-at-end t))
  8156. ((equal action ?f)
  8157. (setq cmd (list (intern
  8158. (org-icompleting-read "Function: "
  8159. obarray 'fboundp t nil nil)))))
  8160. (t (error "Invalid bulk action")))
  8161. ;; Sort the markers, to make sure that parents are handled before children
  8162. (setq entries (sort entries
  8163. (lambda (a b)
  8164. (cond
  8165. ((equal (marker-buffer a) (marker-buffer b))
  8166. (< (marker-position a) (marker-position b)))
  8167. (t
  8168. (string< (buffer-name (marker-buffer a))
  8169. (buffer-name (marker-buffer b))))))))
  8170. ;; Now loop over all markers and apply cmd
  8171. (while (setq e (pop entries))
  8172. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8173. (if (not pos)
  8174. (progn (message "Skipping removed entry at %s" e)
  8175. (setq cntskip (1+ cntskip)))
  8176. (goto-char pos)
  8177. (let (org-loop-over-headlines-in-active-region)
  8178. (eval cmd))
  8179. (setq org-agenda-bulk-marked-entries
  8180. (delete e org-agenda-bulk-marked-entries))
  8181. (setq cnt (1+ cnt))))
  8182. (setq org-agenda-bulk-marked-entries nil)
  8183. (org-agenda-bulk-remove-all-marks)
  8184. (when redo-at-end (org-agenda-redo))
  8185. (message "Acted on %d entries%s"
  8186. cnt
  8187. (if (= cntskip 0)
  8188. ""
  8189. (format ", skipped %d (disappeared before their turn)"
  8190. cntskip)))))
  8191. ;;; Flagging notes
  8192. (defun org-agenda-show-the-flagging-note ()
  8193. "Display the flagging note in the other window.
  8194. When called a second time in direct sequence, offer to remove the FLAGGING
  8195. tag and (if present) the flagging note."
  8196. (interactive)
  8197. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8198. (win (selected-window))
  8199. note heading newhead)
  8200. (unless hdmarker
  8201. (error "No linked entry at point"))
  8202. (if (and (eq this-command last-command)
  8203. (y-or-n-p "Unflag and remove any flagging note? "))
  8204. (progn
  8205. (org-agenda-remove-flag hdmarker)
  8206. (let ((win (get-buffer-window "*Flagging Note*")))
  8207. (and win (delete-window win)))
  8208. (message "Entry unflagged"))
  8209. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8210. (unless note
  8211. (error "No flagging note"))
  8212. (org-kill-new note)
  8213. (org-switch-to-buffer-other-window "*Flagging Note*")
  8214. (erase-buffer)
  8215. (insert note)
  8216. (goto-char (point-min))
  8217. (while (re-search-forward "\\\\n" nil t)
  8218. (replace-match "\n" t t))
  8219. (goto-char (point-min))
  8220. (select-window win)
  8221. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8222. (defun org-agenda-remove-flag (marker)
  8223. "Remove the FLAGGED tag and any flagging note in the entry."
  8224. (let (newhead)
  8225. (org-with-point-at marker
  8226. (org-toggle-tag "FLAGGED" 'off)
  8227. (org-entry-delete nil "THEFLAGGINGNOTE")
  8228. (setq newhead (org-get-heading)))
  8229. (org-agenda-change-all-lines newhead marker)
  8230. (message "Entry unflagged")))
  8231. (defun org-agenda-get-any-marker (&optional pos)
  8232. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8233. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8234. ;;; Appointment reminders
  8235. (defvar appt-time-msg-list)
  8236. ;;;###autoload
  8237. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8238. "Activate appointments found in `org-agenda-files'.
  8239. With a \\[universal-argument] prefix, refresh the list of
  8240. appointments.
  8241. If FILTER is t, interactively prompt the user for a regular
  8242. expression, and filter out entries that don't match it.
  8243. If FILTER is a string, use this string as a regular expression
  8244. for filtering entries out.
  8245. If FILTER is a function, filter out entries against which
  8246. calling the function returns nil. This function takes one
  8247. argument: an entry from `org-agenda-get-day-entries'.
  8248. FILTER can also be an alist with the car of each cell being
  8249. either 'headline or 'category. For example:
  8250. '((headline \"IMPORTANT\")
  8251. (category \"Work\"))
  8252. will only add headlines containing IMPORTANT or headlines
  8253. belonging to the \"Work\" category.
  8254. ARGS are symbols indicating what kind of entries to consider.
  8255. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8256. and :timestamp entries. See the docstring of `org-diary' for
  8257. details and examples."
  8258. (interactive "P")
  8259. (if refresh (setq appt-time-msg-list nil))
  8260. (if (eq filter t)
  8261. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8262. (let* ((cnt 0) ; count added events
  8263. (scope (or args '(:deadline :scheduled :timestamp)))
  8264. (org-agenda-new-buffers nil)
  8265. (org-deadline-warning-days 0)
  8266. ;; Do not use `org-today' here because appt only takes
  8267. ;; time and without date as argument, so it may pass wrong
  8268. ;; information otherwise
  8269. (today (org-date-to-gregorian
  8270. (time-to-days (current-time))))
  8271. (org-agenda-restrict nil)
  8272. (files (org-agenda-files 'unrestricted)) entries file
  8273. (org-agenda-buffer nil))
  8274. ;; Get all entries which may contain an appt
  8275. (org-prepare-agenda-buffers files)
  8276. (while (setq file (pop files))
  8277. (setq entries
  8278. (delq nil
  8279. (append entries
  8280. (apply 'org-agenda-get-day-entries
  8281. file today scope)))))
  8282. ;; Map thru entries and find if we should filter them out
  8283. (mapc
  8284. (lambda(x)
  8285. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8286. (cat (get-text-property 1 'org-category x))
  8287. (tod (get-text-property 1 'time-of-day x))
  8288. (ok (or (null filter)
  8289. (and (stringp filter) (string-match filter evt))
  8290. (and (functionp filter) (funcall filter x))
  8291. (and (listp filter)
  8292. (let ((cat-filter (cadr (assoc 'category filter)))
  8293. (evt-filter (cadr (assoc 'headline filter))))
  8294. (or (and (stringp cat-filter)
  8295. (string-match cat-filter cat))
  8296. (and (stringp evt-filter)
  8297. (string-match evt-filter evt))))))))
  8298. ;; FIXME: Shall we remove text-properties for the appt text?
  8299. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8300. (when (and ok tod)
  8301. (setq tod (concat "00" (number-to-string tod))
  8302. tod (when (string-match
  8303. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8304. (concat (match-string 1 tod) ":"
  8305. (match-string 2 tod))))
  8306. (appt-add tod evt)
  8307. (setq cnt (1+ cnt))))) entries)
  8308. (org-release-buffers org-agenda-new-buffers)
  8309. (if (eq cnt 0)
  8310. (message "No event to add")
  8311. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8312. (defun org-agenda-todayp (date)
  8313. "Does DATE mean today, when considering `org-extend-today-until'?"
  8314. (let ((today (org-today))
  8315. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8316. date)))
  8317. (eq date today)))
  8318. (defun org-agenda-todo-yesterday (&optional arg)
  8319. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8320. (interactive "P")
  8321. (let* ((hour (third (decode-time
  8322. (org-current-time))))
  8323. (org-extend-today-until (1+ hour)))
  8324. (org-agenda-todo arg)))
  8325. (provide 'org-agenda)
  8326. ;;; org-agenda.el ends here