org-agenda.el 368 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags to not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  661. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  662. The variables
  663. `org-agenda-todo-ignore-with-date',
  664. `org-agenda-todo-ignore-timestamp',
  665. `org-agenda-todo-ignore-scheduled',
  666. `org-agenda-todo-ignore-deadlines'
  667. make the global TODO list skip entries that have time stamps of certain
  668. kinds. If this option is set, the same options will also apply for the
  669. tags-todo search, which is the general tags/property matcher
  670. restricted to unfinished TODO entries only."
  671. :group 'org-agenda-skip
  672. :group 'org-agenda-todo-list
  673. :group 'org-agenda-match-view
  674. :type 'boolean)
  675. (defcustom org-agenda-skip-scheduled-if-done nil
  676. "Non-nil means don't show scheduled items in agenda when they are done.
  677. This is relevant for the daily/weekly agenda, not for the TODO list. And
  678. it applies only to the actual date of the scheduling. Warnings about
  679. an item with a past scheduling dates are always turned off when the item
  680. is DONE."
  681. :group 'org-agenda-skip
  682. :group 'org-agenda-daily/weekly
  683. :type 'boolean)
  684. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  685. "Non-nil means skip scheduling line if same entry shows because of deadline.
  686. In the agenda of today, an entry can show up multiple times because
  687. it is both scheduled and has a nearby deadline, and maybe a plain time
  688. stamp as well.
  689. When this variable is t, then only the deadline is shown and the fact that
  690. the entry is scheduled today or was scheduled previously is not shown.
  691. When this variable is nil, the entry will be shown several times. When
  692. the variable is the symbol `not-today', then skip scheduled previously,
  693. but not scheduled today."
  694. :group 'org-agenda-skip
  695. :group 'org-agenda-daily/weekly
  696. :type '(choice
  697. (const :tag "Never" nil)
  698. (const :tag "Always" t)
  699. (const :tag "Not when scheduled today" not-today)))
  700. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  701. "Non-nil means skip timestamp line if same entry shows because of deadline.
  702. In the agenda of today, an entry can show up multiple times
  703. because it has both a plain timestamp and has a nearby deadline.
  704. When this variable is t, then only the deadline is shown and the
  705. fact that the entry has a timestamp for or including today is not
  706. shown. When this variable is nil, the entry will be shown
  707. several times."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-daily/weekly
  710. :version "24.1"
  711. :type '(choice
  712. (const :tag "Never" nil)
  713. (const :tag "Always" t)))
  714. (defcustom org-agenda-skip-deadline-if-done nil
  715. "Non-nil means don't show deadlines when the corresponding item is done.
  716. When nil, the deadline is still shown and should give you a happy feeling.
  717. This is relevant for the daily/weekly agenda. And it applied only to the
  718. actually date of the deadline. Warnings about approaching and past-due
  719. deadlines are always turned off when the item is DONE."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :type 'boolean)
  723. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  724. "Non-nil means skip deadline prewarning when entry is also scheduled.
  725. This will apply on all days where a prewarning for the deadline would
  726. be shown, but not at the day when the entry is actually due. On that day,
  727. the deadline will be shown anyway.
  728. This variable may be set to nil, t, or a number which will then give
  729. the number of days before the actual deadline when the prewarnings
  730. should resume.
  731. This can be used in a workflow where the first showing of the deadline will
  732. trigger you to schedule it, and then you don't want to be reminded of it
  733. because you will take care of it on the day when scheduled."
  734. :group 'org-agenda-skip
  735. :group 'org-agenda-daily/weekly
  736. :version "24.1"
  737. :type '(choice
  738. (const :tag "Always show prewarning" nil)
  739. (const :tag "Remove prewarning if entry is scheduled" t)
  740. (integer :tag "Restart prewarning N days before deadline")))
  741. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  742. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  743. When non-nil, after the search for timestamps has matched once in an
  744. entry, the rest of the entry will not be searched."
  745. :group 'org-agenda-skip
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-timestamp-if-done nil
  748. "Non-nil means don't select item by timestamp or -range if it is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-dim-blocked-tasks nil
  753. "Non-nil means dim blocked tasks in the agenda display.
  754. This causes some overhead during agenda construction, but if you
  755. have turned on `org-enforce-todo-dependencies',
  756. `org-enforce-todo-checkbox-dependencies', or any other blocking
  757. mechanism, this will create useful feedback in the agenda.
  758. Instead of t, this variable can also have the value `invisible'.
  759. Then blocked tasks will be invisible and only become visible when
  760. they become unblocked. An exemption to this behavior is when a task is
  761. blocked because of unchecked checkboxes below it. Since checkboxes do
  762. not show up in the agenda views, making this task invisible you remove any
  763. trace from agenda views that there is something to do. Therefore, a task
  764. that is blocked because of checkboxes will never be made invisible, it
  765. will only be dimmed."
  766. :group 'org-agenda-daily/weekly
  767. :group 'org-agenda-todo-list
  768. :version "24.3"
  769. :type '(choice
  770. (const :tag "Do not dim" nil)
  771. (const :tag "Dim to a gray face" t)
  772. (const :tag "Make invisible" invisible)))
  773. (defcustom org-timeline-show-empty-dates 3
  774. "Non-nil means `org-timeline' also shows dates without an entry.
  775. When nil, only the days which actually have entries are shown.
  776. When t, all days between the first and the last date are shown.
  777. When an integer, show also empty dates, but if there is a gap of more than
  778. N days, just insert a special line indicating the size of the gap."
  779. :group 'org-agenda-skip
  780. :type '(choice
  781. (const :tag "None" nil)
  782. (const :tag "All" t)
  783. (integer :tag "at most")))
  784. (defgroup org-agenda-startup nil
  785. "Options concerning initial settings in the Agenda in Org Mode."
  786. :tag "Org Agenda Startup"
  787. :group 'org-agenda)
  788. (defcustom org-agenda-menu-show-matcher t
  789. "Non-nil means show the match string in the agenda dispatcher menu.
  790. When nil, the matcher string is not shown, but is put into the help-echo
  791. property so than moving the mouse over the command shows it.
  792. Setting it to nil is good if matcher strings are very long and/or if
  793. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  794. :group 'org-agenda
  795. :version "24.1"
  796. :type 'boolean)
  797. (org-define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  798. (defcustom org-agenda-menu-two-columns nil
  799. "Non-nil means, use two columns to show custom commands in the dispatcher.
  800. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  801. to nil."
  802. :group 'org-agenda
  803. :version "24.1"
  804. :type 'boolean)
  805. (org-define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  806. (defcustom org-agenda-finalize-hook nil
  807. "Hook run just before displaying an agenda buffer.
  808. The buffer is still writable when the hook is called.
  809. You can modify some of the buffer substrings but you should be
  810. extra careful not to modify the text properties of the agenda
  811. headlines as the agenda display heavily relies on them."
  812. :group 'org-agenda-startup
  813. :type 'hook)
  814. (defcustom org-agenda-mouse-1-follows-link nil
  815. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  816. A longer mouse click will still set point. Does not work on XEmacs.
  817. Needs to be set before org.el is loaded."
  818. :group 'org-agenda-startup
  819. :type 'boolean)
  820. (defcustom org-agenda-start-with-follow-mode nil
  821. "The initial value of follow mode in a newly created agenda window."
  822. :group 'org-agenda-startup
  823. :type 'boolean)
  824. (defcustom org-agenda-follow-indirect nil
  825. "Non-nil means `org-agenda-follow-mode' displays only the
  826. current item's tree, in an indirect buffer."
  827. :group 'org-agenda
  828. :version "24.1"
  829. :type 'boolean)
  830. (defcustom org-agenda-show-outline-path t
  831. "Non-nil means show outline path in echo area after line motion."
  832. :group 'org-agenda-startup
  833. :type 'boolean)
  834. (defcustom org-agenda-start-with-entry-text-mode nil
  835. "The initial value of entry-text-mode in a newly created agenda window."
  836. :group 'org-agenda-startup
  837. :type 'boolean)
  838. (defcustom org-agenda-entry-text-maxlines 5
  839. "Number of text lines to be added when `E' is pressed in the agenda.
  840. Note that this variable only used during agenda display. Add add entry text
  841. when exporting the agenda, configure the variable
  842. `org-agenda-add-entry-ext-maxlines'."
  843. :group 'org-agenda
  844. :type 'integer)
  845. (defcustom org-agenda-entry-text-exclude-regexps nil
  846. "List of regular expressions to clean up entry text.
  847. The complete matches of all regular expressions in this list will be
  848. removed from entry text before it is shown in the agenda."
  849. :group 'org-agenda
  850. :type '(repeat (regexp)))
  851. (defvar org-agenda-entry-text-cleanup-hook nil
  852. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  853. This cleanup is done in a temporary buffer, so the function may inspect and
  854. change the entire buffer.
  855. Some default stuff like drawers and scheduling/deadline dates will already
  856. have been removed when this is called, as will any matches for regular
  857. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  858. (defvar org-agenda-include-inactive-timestamps nil
  859. "Non-nil means include inactive time stamps in agenda and timeline.
  860. Dynamically scoped.")
  861. (defgroup org-agenda-windows nil
  862. "Options concerning the windows used by the Agenda in Org Mode."
  863. :tag "Org Agenda Windows"
  864. :group 'org-agenda)
  865. (defcustom org-agenda-window-setup 'reorganize-frame
  866. "How the agenda buffer should be displayed.
  867. Possible values for this option are:
  868. current-window Show agenda in the current window, keeping all other windows.
  869. other-window Use `switch-to-buffer-other-window' to display agenda.
  870. reorganize-frame Show only two windows on the current frame, the current
  871. window and the agenda.
  872. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  873. Also, when exiting the agenda, kill that frame.
  874. See also the variable `org-agenda-restore-windows-after-quit'."
  875. :group 'org-agenda-windows
  876. :type '(choice
  877. (const current-window)
  878. (const other-frame)
  879. (const other-window)
  880. (const reorganize-frame)))
  881. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  882. "The min and max height of the agenda window as a fraction of frame height.
  883. The value of the variable is a cons cell with two numbers between 0 and 1.
  884. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  885. :group 'org-agenda-windows
  886. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  887. (defcustom org-agenda-restore-windows-after-quit nil
  888. "Non-nil means restore window configuration upon exiting agenda.
  889. Before the window configuration is changed for displaying the agenda,
  890. the current status is recorded. When the agenda is exited with
  891. `q' or `x' and this option is set, the old state is restored. If
  892. `org-agenda-window-setup' is `other-frame', the value of this
  893. option will be ignored."
  894. :group 'org-agenda-windows
  895. :type 'boolean)
  896. (defcustom org-agenda-ndays nil
  897. "Number of days to include in overview display.
  898. Should be 1 or 7.
  899. Obsolete, see `org-agenda-span'."
  900. :group 'org-agenda-daily/weekly
  901. :type 'integer)
  902. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  903. (defcustom org-agenda-span 'week
  904. "Number of days to include in overview display.
  905. Can be day, week, month, year, or any number of days.
  906. Custom commands can set this variable in the options section."
  907. :group 'org-agenda-daily/weekly
  908. :type '(choice (const :tag "Day" day)
  909. (const :tag "Week" week)
  910. (const :tag "Month" month)
  911. (const :tag "Year" year)
  912. (integer :tag "Custom")))
  913. (defcustom org-agenda-start-on-weekday 1
  914. "Non-nil means start the overview always on the specified weekday.
  915. 0 denotes Sunday, 1 denotes Monday etc.
  916. When nil, always start on the current day.
  917. Custom commands can set this variable in the options section."
  918. :group 'org-agenda-daily/weekly
  919. :type '(choice (const :tag "Today" nil)
  920. (integer :tag "Weekday No.")))
  921. (defcustom org-agenda-show-all-dates t
  922. "Non-nil means `org-agenda' shows every day in the selected range.
  923. When nil, only the days which actually have entries are shown."
  924. :group 'org-agenda-daily/weekly
  925. :type 'boolean)
  926. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  927. "Format string for displaying dates in the agenda.
  928. Used by the daily/weekly agenda and by the timeline. This should be
  929. a format string understood by `format-time-string', or a function returning
  930. the formatted date as a string. The function must take a single argument,
  931. a calendar-style date list like (month day year)."
  932. :group 'org-agenda-daily/weekly
  933. :type '(choice
  934. (string :tag "Format string")
  935. (function :tag "Function")))
  936. (defun org-agenda-format-date-aligned (date)
  937. "Format a date string for display in the daily/weekly agenda, or timeline.
  938. This function makes sure that dates are aligned for easy reading."
  939. (require 'cal-iso)
  940. (let* ((dayname (calendar-day-name date))
  941. (day (cadr date))
  942. (day-of-week (calendar-day-of-week date))
  943. (month (car date))
  944. (monthname (calendar-month-name month))
  945. (year (nth 2 date))
  946. (iso-week (org-days-to-iso-week
  947. (calendar-absolute-from-gregorian date)))
  948. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  949. (1- year))
  950. ((and (= month 12) (<= iso-week 1))
  951. (1+ year))
  952. (t year)))
  953. (weekstring (if (= day-of-week 1)
  954. (format " W%02d" iso-week)
  955. "")))
  956. (format "%-10s %2d %s %4d%s"
  957. dayname day monthname year weekstring)))
  958. (defcustom org-agenda-time-leading-zero nil
  959. "Non-nil means use leading zero for military times in agenda.
  960. For example, 9:30am would become 09:30 rather than 9:30."
  961. :group 'org-agenda-daily/weekly
  962. :version "24.1"
  963. :type 'boolean)
  964. (defcustom org-agenda-timegrid-use-ampm nil
  965. "When set, show AM/PM style timestamps on the timegrid."
  966. :group 'org-agenda
  967. :version "24.1"
  968. :type 'boolean)
  969. (defun org-agenda-time-of-day-to-ampm (time)
  970. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  971. (let* ((hour-number (string-to-number (substring time 0 -3)))
  972. (minute (substring time -2))
  973. (ampm "am"))
  974. (cond
  975. ((equal hour-number 12)
  976. (setq ampm "pm"))
  977. ((> hour-number 12)
  978. (setq ampm "pm")
  979. (setq hour-number (- hour-number 12))))
  980. (concat
  981. (if org-agenda-time-leading-zero
  982. (format "%02d" hour-number)
  983. (format "%02s" (number-to-string hour-number)))
  984. ":" minute ampm)))
  985. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  986. "Conditionally convert TIME to AM/PM format
  987. based on `org-agenda-timegrid-use-ampm'"
  988. (if org-agenda-timegrid-use-ampm
  989. (org-agenda-time-of-day-to-ampm time)
  990. time))
  991. (defcustom org-agenda-weekend-days '(6 0)
  992. "Which days are weekend?
  993. These days get the special face `org-agenda-date-weekend' in the agenda
  994. and timeline buffers."
  995. :group 'org-agenda-daily/weekly
  996. :type '(set :greedy t
  997. (const :tag "Monday" 1)
  998. (const :tag "Tuesday" 2)
  999. (const :tag "Wednesday" 3)
  1000. (const :tag "Thursday" 4)
  1001. (const :tag "Friday" 5)
  1002. (const :tag "Saturday" 6)
  1003. (const :tag "Sunday" 0)))
  1004. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1005. "Non-nil means jump to today when moving a past date forward in time.
  1006. When using S-right in the agenda to move a a date forward, and the date
  1007. stamp currently points to the past, the first key press will move it
  1008. to today. WHen nil, just move one day forward even if the date stays
  1009. in the past."
  1010. :group 'org-agenda-daily/weekly
  1011. :version "24.1"
  1012. :type 'boolean)
  1013. (defcustom org-agenda-include-diary nil
  1014. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1015. Custom commands can set this variable in the options section."
  1016. :group 'org-agenda-daily/weekly
  1017. :type 'boolean)
  1018. (defcustom org-agenda-include-deadlines t
  1019. "If non-nil, include entries within their deadline warning period.
  1020. Custom commands can set this variable in the options section."
  1021. :group 'org-agenda-daily/weekly
  1022. :version "24.1"
  1023. :type 'boolean)
  1024. (defcustom org-agenda-repeating-timestamp-show-all t
  1025. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1026. When set to a list of strings, only show occurrences of repeating
  1027. stamps for these TODO keywords. When nil, only one occurrence is
  1028. shown, either today or the nearest into the future."
  1029. :group 'org-agenda-daily/weekly
  1030. :type '(choice
  1031. (const :tag "Show repeating stamps" t)
  1032. (repeat :tag "Show repeating stamps for these TODO keywords"
  1033. (string :tag "TODO Keyword"))
  1034. (const :tag "Don't show repeating stamps" nil)))
  1035. (defcustom org-scheduled-past-days 10000
  1036. "No. of days to continue listing scheduled items that are not marked DONE.
  1037. When an item is scheduled on a date, it shows up in the agenda on this
  1038. day and will be listed until it is marked done for the number of days
  1039. given here."
  1040. :group 'org-agenda-daily/weekly
  1041. :type 'integer)
  1042. (defcustom org-agenda-log-mode-items '(closed clock)
  1043. "List of items that should be shown in agenda log mode.
  1044. This list may contain the following symbols:
  1045. closed Show entries that have been closed on that day.
  1046. clock Show entries that have received clocked time on that day.
  1047. state Show all logged state changes.
  1048. Note that instead of changing this variable, you can also press `C-u l' in
  1049. the agenda to display all available LOG items temporarily."
  1050. :group 'org-agenda-daily/weekly
  1051. :type '(set :greedy t (const closed) (const clock) (const state)))
  1052. (defcustom org-agenda-clock-consistency-checks
  1053. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1054. :gap-ok-around ("4:00")
  1055. :default-face ((:background "DarkRed") (:foreground "white"))
  1056. :overlap-face nil :gap-face nil :no-end-time-face nil
  1057. :long-face nil :short-face nil)
  1058. "This is a property list, with the following keys:
  1059. :max-duration Mark clocking chunks that are longer than this time.
  1060. This is a time string like \"HH:MM\", or the number
  1061. of minutes as an integer.
  1062. :min-duration Mark clocking chunks that are shorter that this.
  1063. This is a time string like \"HH:MM\", or the number
  1064. of minutes as an integer.
  1065. :max-gap Mark gaps between clocking chunks that are longer than
  1066. this duration. A number of minutes, or a string
  1067. like \"HH:MM\".
  1068. :gap-ok-around List of times during the day which are usually not working
  1069. times. When a gap is detected, but the gap contains any
  1070. of these times, the gap is *not* reported. For example,
  1071. if this is (\"4:00\" \"13:00\") then gaps that contain
  1072. 4:00 in the morning (i.e. the night) and 13:00
  1073. (i.e. a typical lunch time) do not cause a warning.
  1074. You should have at least one time during the night in this
  1075. list, or otherwise the first task each morning will trigger
  1076. a warning because it follows a long gap.
  1077. Furthermore, the following properties can be used to define faces for
  1078. issue display.
  1079. :default-face the default face, if the specific face is undefined
  1080. :overlap-face face for overlapping clocks
  1081. :gap-face face for gaps between clocks
  1082. :no-end-time-face face for incomplete clocks
  1083. :long-face face for clock intervals that are too long
  1084. :short-face face for clock intervals that are too short"
  1085. :group 'org-agenda-daily/weekly
  1086. :group 'org-clock
  1087. :version "24.1"
  1088. :type 'plist)
  1089. (defcustom org-agenda-log-mode-add-notes t
  1090. "Non-nil means add first line of notes to log entries in agenda views.
  1091. If a log item like a state change or a clock entry is associated with
  1092. notes, the first line of these notes will be added to the entry in the
  1093. agenda display."
  1094. :group 'org-agenda-daily/weekly
  1095. :type 'boolean)
  1096. (defcustom org-agenda-start-with-log-mode nil
  1097. "The initial value of log-mode in a newly created agenda window.
  1098. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1099. explanations on the possible values."
  1100. :group 'org-agenda-startup
  1101. :group 'org-agenda-daily/weekly
  1102. :type '(choice (const :tag "Don't show log items" nil)
  1103. (const :tag "Show only log items" 'only)
  1104. (const :tag "Show all possible log items" 'clockcheck)
  1105. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1106. (choice (const :tag "Show closed log items" 'closed)
  1107. (const :tag "Show clocked log items" 'clock)
  1108. (const :tag "Show all logged state changes" 'state)))))
  1109. (defcustom org-agenda-start-with-clockreport-mode nil
  1110. "The initial value of clockreport-mode in a newly created agenda window."
  1111. :group 'org-agenda-startup
  1112. :group 'org-agenda-daily/weekly
  1113. :type 'boolean)
  1114. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1115. "Property list with parameters for the clocktable in clockreport mode.
  1116. This is the display mode that shows a clock table in the daily/weekly
  1117. agenda, the properties for this dynamic block can be set here.
  1118. The usual clocktable parameters are allowed here, but you cannot set
  1119. the properties :name, :tstart, :tend, :block, and :scope - these will
  1120. be overwritten to make sure the content accurately reflects the
  1121. current display in the agenda."
  1122. :group 'org-agenda-daily/weekly
  1123. :type 'plist)
  1124. (defcustom org-agenda-search-view-always-boolean nil
  1125. "Non-nil means the search string is interpreted as individual parts.
  1126. The search string for search view can either be interpreted as a phrase,
  1127. or as a list of snippets that define a boolean search for a number of
  1128. strings.
  1129. When this is non-nil, the string will be split on whitespace, and each
  1130. snippet will be searched individually, and all must match in order to
  1131. select an entry. A snippet is then a single string of non-white
  1132. characters, or a string in double quotes, or a regexp in {} braces.
  1133. If a snippet is preceded by \"-\", the snippet must *not* match.
  1134. \"+\" is syntactic sugar for positive selection. Each snippet may
  1135. be found as a full word or a partial word, but see the variable
  1136. `org-agenda-search-view-force-full-words'.
  1137. When this is nil, search will look for the entire search phrase as one,
  1138. with each space character matching any amount of whitespace, including
  1139. line breaks.
  1140. Even when this is nil, you can still switch to Boolean search dynamically
  1141. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1142. is a regexp marked with braces like \"{abc}\", this will also switch to
  1143. boolean search."
  1144. :group 'org-agenda-search-view
  1145. :version "24.1"
  1146. :type 'boolean)
  1147. (if (fboundp 'defvaralias)
  1148. (defvaralias 'org-agenda-search-view-search-words-only
  1149. 'org-agenda-search-view-always-boolean))
  1150. (defcustom org-agenda-search-view-force-full-words nil
  1151. "Non-nil means, search words must be matches as complete words.
  1152. When nil, they may also match part of a word."
  1153. :group 'org-agenda-search-view
  1154. :version "24.1"
  1155. :type 'boolean)
  1156. (defgroup org-agenda-time-grid nil
  1157. "Options concerning the time grid in the Org-mode Agenda."
  1158. :tag "Org Agenda Time Grid"
  1159. :group 'org-agenda)
  1160. (defcustom org-agenda-search-headline-for-time t
  1161. "Non-nil means search headline for a time-of-day.
  1162. If the headline contains a time-of-day in one format or another, it will
  1163. be used to sort the entry into the time sequence of items for a day.
  1164. Some people have time stamps in the headline that refer to the creation
  1165. time or so, and then this produces an unwanted side effect. If this is
  1166. the case for your, use this variable to turn off searching the headline
  1167. for a time."
  1168. :group 'org-agenda-time-grid
  1169. :type 'boolean)
  1170. (defcustom org-agenda-use-time-grid t
  1171. "Non-nil means show a time grid in the agenda schedule.
  1172. A time grid is a set of lines for specific times (like every two hours between
  1173. 8:00 and 20:00). The items scheduled for a day at specific times are
  1174. sorted in between these lines.
  1175. For details about when the grid will be shown, and what it will look like, see
  1176. the variable `org-agenda-time-grid'."
  1177. :group 'org-agenda-time-grid
  1178. :type 'boolean)
  1179. (defcustom org-agenda-time-grid
  1180. '((daily today require-timed)
  1181. "----------------"
  1182. (800 1000 1200 1400 1600 1800 2000))
  1183. "The settings for time grid for agenda display.
  1184. This is a list of three items. The first item is again a list. It contains
  1185. symbols specifying conditions when the grid should be displayed:
  1186. daily if the agenda shows a single day
  1187. weekly if the agenda shows an entire week
  1188. today show grid on current date, independent of daily/weekly display
  1189. require-timed show grid only if at least one item has a time specification
  1190. The second item is a string which will be placed behind the grid time.
  1191. The third item is a list of integers, indicating the times that should have
  1192. a grid line."
  1193. :group 'org-agenda-time-grid
  1194. :type
  1195. '(list
  1196. (set :greedy t :tag "Grid Display Options"
  1197. (const :tag "Show grid in single day agenda display" daily)
  1198. (const :tag "Show grid in weekly agenda display" weekly)
  1199. (const :tag "Always show grid for today" today)
  1200. (const :tag "Show grid only if any timed entries are present"
  1201. require-timed)
  1202. (const :tag "Skip grid times already present in an entry"
  1203. remove-match))
  1204. (string :tag "Grid String")
  1205. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1206. (defcustom org-agenda-show-current-time-in-grid t
  1207. "Non-nil means show the current time in the time grid."
  1208. :group 'org-agenda-time-grid
  1209. :version "24.1"
  1210. :type 'boolean)
  1211. (defcustom org-agenda-current-time-string
  1212. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1213. "The string for the current time marker in the agenda."
  1214. :group 'org-agenda-time-grid
  1215. :version "24.1"
  1216. :type 'string)
  1217. (defgroup org-agenda-sorting nil
  1218. "Options concerning sorting in the Org-mode Agenda."
  1219. :tag "Org Agenda Sorting"
  1220. :group 'org-agenda)
  1221. (defcustom org-agenda-sorting-strategy
  1222. '((agenda habit-down time-up priority-down category-keep)
  1223. (todo priority-down category-keep)
  1224. (tags priority-down category-keep)
  1225. (search category-keep))
  1226. "Sorting structure for the agenda items of a single day.
  1227. This is a list of symbols which will be used in sequence to determine
  1228. if an entry should be listed before another entry. The following
  1229. symbols are recognized:
  1230. time-up Put entries with time-of-day indications first, early first
  1231. time-down Put entries with time-of-day indications first, late first
  1232. category-keep Keep the default order of categories, corresponding to the
  1233. sequence in `org-agenda-files'.
  1234. category-up Sort alphabetically by category, A-Z.
  1235. category-down Sort alphabetically by category, Z-A.
  1236. tag-up Sort alphabetically by last tag, A-Z.
  1237. tag-down Sort alphabetically by last tag, Z-A.
  1238. priority-up Sort numerically by priority, high priority last.
  1239. priority-down Sort numerically by priority, high priority first.
  1240. todo-state-up Sort by todo state, tasks that are done last.
  1241. todo-state-down Sort by todo state, tasks that are done first.
  1242. effort-up Sort numerically by estimated effort, high effort last.
  1243. effort-down Sort numerically by estimated effort, high effort first.
  1244. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1245. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1246. habit-up Put entries that are habits first
  1247. habit-down Put entries that are habits last
  1248. alpha-up Sort headlines alphabetically
  1249. alpha-down Sort headlines alphabetically, reversed
  1250. The different possibilities will be tried in sequence, and testing stops
  1251. if one comparison returns a \"not-equal\". For example, the default
  1252. '(time-up category-keep priority-down)
  1253. means: Pull out all entries having a specified time of day and sort them,
  1254. in order to make a time schedule for the current day the first thing in the
  1255. agenda listing for the day. Of the entries without a time indication, keep
  1256. the grouped in categories, don't sort the categories, but keep them in
  1257. the sequence given in `org-agenda-files'. Within each category sort by
  1258. priority.
  1259. Leaving out `category-keep' would mean that items will be sorted across
  1260. categories by priority.
  1261. Instead of a single list, this can also be a set of list for specific
  1262. contents, with a context symbol in the car of the list, any of
  1263. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1264. Custom commands can bind this variable in the options section."
  1265. :group 'org-agenda-sorting
  1266. :type `(choice
  1267. (repeat :tag "General" ,org-sorting-choice)
  1268. (list :tag "Individually"
  1269. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1270. (repeat ,org-sorting-choice))
  1271. (cons (const :tag "Strategy for TODO lists" todo)
  1272. (repeat ,org-sorting-choice))
  1273. (cons (const :tag "Strategy for Tags matches" tags)
  1274. (repeat ,org-sorting-choice))
  1275. (cons (const :tag "Strategy for search matches" search)
  1276. (repeat ,org-sorting-choice)))))
  1277. (defcustom org-agenda-cmp-user-defined nil
  1278. "A function to define the comparison `user-defined'.
  1279. This function must receive two arguments, agenda entry a and b.
  1280. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1281. the user comparison, return nil.
  1282. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1283. part of an agenda sorting strategy."
  1284. :group 'org-agenda-sorting
  1285. :type 'symbol)
  1286. (defcustom org-sort-agenda-notime-is-late t
  1287. "Non-nil means items without time are considered late.
  1288. This is only relevant for sorting. When t, items which have no explicit
  1289. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1290. do have a time. When nil, the default time is before 0:00. You can use this
  1291. option to decide if the schedule for today should come before or after timeless
  1292. agenda entries."
  1293. :group 'org-agenda-sorting
  1294. :type 'boolean)
  1295. (defcustom org-sort-agenda-noeffort-is-high t
  1296. "Non-nil means items without effort estimate are sorted as high effort.
  1297. This also applies when filtering an agenda view with respect to the
  1298. < or > effort operator. Then, tasks with no effort defined will be treated
  1299. as tasks with high effort.
  1300. When nil, such items are sorted as 0 minutes effort."
  1301. :group 'org-agenda-sorting
  1302. :type 'boolean)
  1303. (defgroup org-agenda-line-format nil
  1304. "Options concerning the entry prefix in the Org-mode agenda display."
  1305. :tag "Org Agenda Line Format"
  1306. :group 'org-agenda)
  1307. (defcustom org-agenda-prefix-format
  1308. '((agenda . " %i %-12:c%?-12t% s")
  1309. (timeline . " % s")
  1310. (todo . " %i %-12:c")
  1311. (tags . " %i %-12:c")
  1312. (search . " %i %-12:c"))
  1313. "Format specifications for the prefix of items in the agenda views.
  1314. An alist with five entries, each for the different agenda types. The
  1315. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1316. The values are format strings.
  1317. This format works similar to a printf format, with the following meaning:
  1318. %c the category of the item, \"Diary\" for entries from the diary,
  1319. or as given by the CATEGORY keyword or derived from the file name
  1320. %e the effort required by the item
  1321. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1322. %T the last tag of the item (ignore inherited tags, which come first)
  1323. %t the HH:MM time-of-day specification if one applies to the entry
  1324. %s Scheduling/Deadline information, a short string
  1325. %(expression) Eval EXPRESSION and replace the control string
  1326. by the result
  1327. All specifiers work basically like the standard `%s' of printf, but may
  1328. contain two additional characters: a question mark just after the `%'
  1329. and a whitespace/punctuation character just before the final letter.
  1330. If the first character after `%' is a question mark, the entire field
  1331. will only be included if the corresponding value applies to the current
  1332. entry. This is useful for fields which should have fixed width when
  1333. present, but zero width when absent. For example, \"%?-12t\" will
  1334. result in a 12 character time field if a time of the day is specified,
  1335. but will completely disappear in entries which do not contain a time.
  1336. If there is punctuation or whitespace character just before the final
  1337. format letter, this character will be appended to the field value if
  1338. the value is not empty. For example, the format \"%-12:c\" leads to
  1339. \"Diary: \" if the category is \"Diary\". If the category were be
  1340. empty, no additional colon would be inserted.
  1341. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1342. which means:
  1343. - Indent the line with two space characters
  1344. - Give the category a 12 chars wide field, padded with whitespace on
  1345. the right (because of `-'). Append a colon if there is a category
  1346. (because of `:').
  1347. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1348. time, don't put in an empty field, just skip it (because of '?').
  1349. - Finally, put the scheduling information.
  1350. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1351. `org-agenda-remove-tags'.
  1352. Custom commands can set this variable in the options section."
  1353. :type '(choice
  1354. (string :tag "General format")
  1355. (list :greedy t :tag "View dependent"
  1356. (cons (const agenda) (string :tag "Format"))
  1357. (cons (const timeline) (string :tag "Format"))
  1358. (cons (const todo) (string :tag "Format"))
  1359. (cons (const tags) (string :tag "Format"))
  1360. (cons (const search) (string :tag "Format"))))
  1361. :group 'org-agenda-line-format)
  1362. (defvar org-prefix-format-compiled nil
  1363. "The compiled prefix format and associated variables.
  1364. This is a list where first element is a list of variable bindings, and second
  1365. element is the compiled format expression. See the variable
  1366. `org-agenda-prefix-format'.")
  1367. (defcustom org-agenda-todo-keyword-format "%-1s"
  1368. "Format for the TODO keyword in agenda lines.
  1369. Set this to something like \"%-12s\" if you want all TODO keywords
  1370. to occupy a fixed space in the agenda display."
  1371. :group 'org-agenda-line-format
  1372. :type 'string)
  1373. (defcustom org-agenda-diary-sexp-prefix nil
  1374. "A regexp that matches part of a diary sexp entry
  1375. which should be treated as scheduling/deadline information in
  1376. `org-agenda'.
  1377. For example, you can use this to extract the `diary-remind-message' from
  1378. `diary-remind' entries."
  1379. :group 'org-agenda-line-format
  1380. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1381. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1382. "Text preceding timerange entries in the agenda view.
  1383. This is a list with two strings. The first applies when the range
  1384. is entirely on one day. The second applies if the range spans several days.
  1385. The strings may have two \"%d\" format specifiers which will be filled
  1386. with the sequence number of the days, and the total number of days in the
  1387. range, respectively."
  1388. :group 'org-agenda-line-format
  1389. :type '(list
  1390. (string :tag "Deadline today ")
  1391. (choice :tag "Deadline relative"
  1392. (string :tag "Format string")
  1393. (function))))
  1394. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1395. "Text preceding scheduled items in the agenda view.
  1396. This is a list with two strings. The first applies when the item is
  1397. scheduled on the current day. The second applies when it has been scheduled
  1398. previously, it may contain a %d indicating that this is the nth time that
  1399. this item is scheduled, due to automatic rescheduling of unfinished items
  1400. for the following day. So this number is one larger than the number of days
  1401. that passed since this item was scheduled first."
  1402. :group 'org-agenda-line-format
  1403. :type '(list
  1404. (string :tag "Scheduled today ")
  1405. (string :tag "Scheduled previously")))
  1406. (defcustom org-agenda-inactive-leader "["
  1407. "Text preceding item pulled into the agenda by inactive time stamps.
  1408. These entries are added to the agenda when pressing \"[\"."
  1409. :group 'org-agenda-line-format
  1410. :version "24.1"
  1411. :type '(list
  1412. (string :tag "Scheduled today ")
  1413. (string :tag "Scheduled previously")))
  1414. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1415. "Text preceding deadline items in the agenda view.
  1416. This is a list with two strings. The first applies when the item has its
  1417. deadline on the current day. The second applies when it is in the past or
  1418. in the future, it may contain %d to capture how many days away the deadline
  1419. is (was)."
  1420. :group 'org-agenda-line-format
  1421. :type '(list
  1422. (string :tag "Deadline today ")
  1423. (choice :tag "Deadline relative"
  1424. (string :tag "Format string")
  1425. (function))))
  1426. (defcustom org-agenda-remove-times-when-in-prefix t
  1427. "Non-nil means remove duplicate time specifications in agenda items.
  1428. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1429. time-of-day specification in a headline or diary entry is extracted and
  1430. placed into the prefix. If this option is non-nil, the original specification
  1431. \(a timestamp or -range, or just a plain time(range) specification like
  1432. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1433. cluttered.
  1434. The option can be t or nil. It may also be the symbol `beg', indicating
  1435. that the time should only be removed when it is located at the beginning of
  1436. the headline/diary entry."
  1437. :group 'org-agenda-line-format
  1438. :type '(choice
  1439. (const :tag "Always" t)
  1440. (const :tag "Never" nil)
  1441. (const :tag "When at beginning of entry" beg)))
  1442. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1443. "Non-nil means remove time ranges specifications in agenda
  1444. items that span on several days."
  1445. :group 'org-agenda-line-format
  1446. :version "24.1"
  1447. :type 'boolean)
  1448. (defcustom org-agenda-default-appointment-duration nil
  1449. "Default duration for appointments that only have a starting time.
  1450. When nil, no duration is specified in such cases.
  1451. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1452. :group 'org-agenda-line-format
  1453. :type '(choice
  1454. (integer :tag "Minutes")
  1455. (const :tag "No default duration")))
  1456. (defcustom org-agenda-show-inherited-tags t
  1457. "Non-nil means show inherited tags in each agenda line."
  1458. :group 'org-agenda-line-format
  1459. :type 'boolean)
  1460. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1461. "List of agenda view types where to use tag inheritance.
  1462. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1463. controlled by `org-use-tag-inheritance'. In other agenda types,
  1464. `org-use-tag-inheritance' is not used when selecting the agenda
  1465. entries, but you may want the agenda to use the inherited tags
  1466. anyway, e.g. for later tag filtering.
  1467. The default value reset tags in every agenda type. Setting this
  1468. option to nil will speed up non-tags agenda view a lot.
  1469. Allowed value are 'todo, 'search, 'timeline and 'agenda."
  1470. :version "24.3"
  1471. :group 'org-agenda
  1472. :type '(repeat (symbol :tag "Agenda type")))
  1473. (defcustom org-agenda-hide-tags-regexp nil
  1474. "Regular expression used to filter away specific tags in agenda views.
  1475. This means that these tags will be present, but not be shown in the agenda
  1476. line. Secondary filtering will still work on the hidden tags.
  1477. Nil means don't hide any tags."
  1478. :group 'org-agenda-line-format
  1479. :type '(choice
  1480. (const :tag "Hide none" nil)
  1481. (string :tag "Regexp ")))
  1482. (defcustom org-agenda-remove-tags nil
  1483. "Non-nil means remove the tags from the headline copy in the agenda.
  1484. When this is the symbol `prefix', only remove tags when
  1485. `org-agenda-prefix-format' contains a `%T' specifier."
  1486. :group 'org-agenda-line-format
  1487. :type '(choice
  1488. (const :tag "Always" t)
  1489. (const :tag "Never" nil)
  1490. (const :tag "When prefix format contains %T" prefix)))
  1491. (if (fboundp 'defvaralias)
  1492. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1493. 'org-agenda-remove-tags))
  1494. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1495. "Shift tags in agenda items to this column.
  1496. If this number is positive, it specifies the column. If it is negative,
  1497. it means that the tags should be flushright to that column. For example,
  1498. -80 works well for a normal 80 character screen."
  1499. :group 'org-agenda-line-format
  1500. :type 'integer)
  1501. (if (fboundp 'defvaralias)
  1502. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1503. (defcustom org-agenda-fontify-priorities 'cookies
  1504. "Non-nil means highlight low and high priorities in agenda.
  1505. When t, the highest priority entries are bold, lowest priority italic.
  1506. However, settings in `org-priority-faces' will overrule these faces.
  1507. When this variable is the symbol `cookies', only fontify the
  1508. cookies, not the entire task.
  1509. This may also be an association list of priority faces, whose
  1510. keys are the character values of `org-highest-priority',
  1511. `org-default-priority', and `org-lowest-priority' (the default values
  1512. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1513. color as a string, or a list like `(:background \"Red\")'.
  1514. If it is a color, the variable `org-faces-easy-properties'
  1515. determines if it is a foreground or a background color."
  1516. :group 'org-agenda-line-format
  1517. :type '(choice
  1518. (const :tag "Never" nil)
  1519. (const :tag "Defaults" t)
  1520. (const :tag "Cookies only" cookies)
  1521. (repeat :tag "Specify"
  1522. (list (character :tag "Priority" :value ?A)
  1523. (choice :tag "Face "
  1524. (string :tag "Color")
  1525. (sexp :tag "Face"))))))
  1526. (defcustom org-agenda-day-face-function nil
  1527. "Function called to determine what face should be used to display a day.
  1528. The only argument passed to that function is the day. It should
  1529. returns a face, or nil if does not want to specify a face and let
  1530. the normal rules apply."
  1531. :group 'org-agenda-line-format
  1532. :version "24.1"
  1533. :type 'function)
  1534. (defcustom org-agenda-category-icon-alist nil
  1535. "Alist of category icon to be displayed in agenda views.
  1536. Each entry should have the following format:
  1537. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1538. Where CATEGORY-REGEXP is a regexp matching the categories where
  1539. the icon should be displayed.
  1540. FILE-OR-DATA either a file path or a string containing image data.
  1541. The other fields can be omitted safely if not needed:
  1542. TYPE indicates the image type.
  1543. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1544. image data.
  1545. PROPS are additional image attributes to assign to the image,
  1546. like, e.g. `:ascent center'.
  1547. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1548. If you want to set the display properties yourself, just put a
  1549. list as second element:
  1550. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1551. For example, to display a 16px horizontal space for Emacs
  1552. category, you can use:
  1553. (\"Emacs\" '(space . (:width (16))))"
  1554. :group 'org-agenda-line-format
  1555. :version "24.1"
  1556. :type '(alist :key-type (string :tag "Regexp matching category")
  1557. :value-type (choice (list :tag "Icon"
  1558. (string :tag "File or data")
  1559. (symbol :tag "Type")
  1560. (boolean :tag "Data?")
  1561. (repeat :tag "Extra image properties" :inline t symbol))
  1562. (list :tag "Display properties" sexp))))
  1563. (defgroup org-agenda-column-view nil
  1564. "Options concerning column view in the agenda."
  1565. :tag "Org Agenda Column View"
  1566. :group 'org-agenda)
  1567. (defcustom org-agenda-columns-show-summaries t
  1568. "Non-nil means show summaries for columns displayed in the agenda view."
  1569. :group 'org-agenda-column-view
  1570. :type 'boolean)
  1571. (defcustom org-agenda-columns-compute-summary-properties t
  1572. "Non-nil means recompute all summary properties before column view.
  1573. When column view in the agenda is listing properties that have a summary
  1574. operator, it can go to all relevant buffers and recompute the summaries
  1575. there. This can mean overhead for the agenda column view, but is necessary
  1576. to have thing up to date.
  1577. As a special case, a CLOCKSUM property also makes sure that the clock
  1578. computations are current."
  1579. :group 'org-agenda-column-view
  1580. :type 'boolean)
  1581. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1582. "Non-nil means the duration of an appointment will add to day effort.
  1583. The property to which appointment durations will be added is the one given
  1584. in the option `org-effort-property'. If an appointment does not have
  1585. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1586. is not set, an appointment without end time will not contribute to the time
  1587. estimate."
  1588. :group 'org-agenda-column-view
  1589. :type 'boolean)
  1590. (defcustom org-agenda-auto-exclude-function nil
  1591. "A function called with a tag to decide if it is filtered on '/ RET'.
  1592. The sole argument to the function, which is called once for each
  1593. possible tag, is a string giving the name of the tag. The
  1594. function should return either nil if the tag should be included
  1595. as normal, or \"-<TAG>\" to exclude the tag.
  1596. Note that for the purpose of tag filtering, only the lower-case version of
  1597. all tags will be considered, so that this function will only ever see
  1598. the lower-case version of all tags."
  1599. :group 'org-agenda
  1600. :type 'function)
  1601. (defcustom org-agenda-bulk-custom-functions nil
  1602. "Alist of characters and custom functions for bulk actions.
  1603. For example, this value makes those two functions available:
  1604. '((?R set-category)
  1605. (?C bulk-cut))
  1606. With selected entries in an agenda buffer, `B R' will call
  1607. the custom function `set-category' on the selected entries.
  1608. Note that functions in this alist don't need to be quoted."
  1609. :type 'alist
  1610. :version "24.1"
  1611. :group 'org-agenda)
  1612. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1613. "Execute BODY with point at location given by `org-hd-marker' property.
  1614. If STRING is non-nil, the text property will be fetched from position 0
  1615. in that string. If STRING is nil, it will be fetched from the beginning
  1616. of the current line."
  1617. (org-with-gensyms (marker)
  1618. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1619. 'org-hd-marker ,string)))
  1620. (with-current-buffer (marker-buffer ,marker)
  1621. (save-excursion
  1622. (goto-char ,marker)
  1623. ,@body)))))
  1624. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1625. (defun org-add-agenda-custom-command (entry)
  1626. "Replace or add a command in `org-agenda-custom-commands'.
  1627. This is mostly for hacking and trying a new command - once the command
  1628. works you probably want to add it to `org-agenda-custom-commands' for good."
  1629. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1630. (if ass
  1631. (setcdr ass (cdr entry))
  1632. (push entry org-agenda-custom-commands))))
  1633. ;;; Define the org-agenda-mode
  1634. (defvar org-agenda-mode-map (make-sparse-keymap)
  1635. "Keymap for `org-agenda-mode'.")
  1636. (if (fboundp 'defvaralias)
  1637. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1638. (defvar org-agenda-menu) ; defined later in this file.
  1639. (defvar org-agenda-restrict nil) ; defined later in this file.
  1640. (defvar org-agenda-follow-mode nil)
  1641. (defvar org-agenda-entry-text-mode nil)
  1642. (defvar org-agenda-clockreport-mode nil)
  1643. (defvar org-agenda-show-log nil)
  1644. (defvar org-agenda-redo-command nil)
  1645. (defvar org-agenda-query-string nil)
  1646. (defvar org-agenda-mode-hook nil
  1647. "Hook run after `org-agenda-mode' is turned on.
  1648. The buffer is still writable when this hook is called.")
  1649. (defvar org-agenda-type nil)
  1650. (defvar org-agenda-force-single-file nil)
  1651. (defvar org-agenda-bulk-marked-entries nil
  1652. "List of markers that refer to marked entries in the agenda.")
  1653. ;;; Multiple agenda buffers support
  1654. (defcustom org-agenda-sticky nil
  1655. "Non-nil means agenda q key will bury agenda buffers.
  1656. Agenda commands will then show existing buffer instead of generating new ones.
  1657. When nil, `q' will kill the single agenda buffer."
  1658. :group 'org-agenda
  1659. :version "24.3"
  1660. :type 'boolean)
  1661. ;;;###autoload
  1662. (defun org-toggle-sticky-agenda (&optional arg)
  1663. "Toggle `org-agenda-sticky'."
  1664. (interactive "P")
  1665. (let ((new-value (if arg
  1666. (> (prefix-numeric-value arg) 0)
  1667. (not org-agenda-sticky))))
  1668. (if (equal new-value org-agenda-sticky)
  1669. (and (org-called-interactively-p 'interactive)
  1670. (message "Sticky agenda was already %s"
  1671. (if org-agenda-sticky "enabled" "disabled")))
  1672. (setq org-agenda-sticky new-value)
  1673. (org-agenda-kill-all-agenda-buffers)
  1674. (and (org-called-interactively-p 'interactive)
  1675. (message "Sticky agenda was %s"
  1676. (if org-agenda-sticky "enabled" "disabled"))))))
  1677. (autoload 'org-toggle-sticky-agenda "org-agenda" "\
  1678. Toggle `org-agenda-sticky'.
  1679. \(fn &optional ARG)" t nil)
  1680. (defvar org-agenda-buffer nil
  1681. "Agenda buffer currently being generated.")
  1682. (defvar org-agenda-last-prefix-arg nil)
  1683. (defvar org-agenda-this-buffer-name nil)
  1684. (defvar org-agenda-doing-sticky-redo nil)
  1685. (defvar org-agenda-this-buffer-is-sticky nil)
  1686. (defconst org-agenda-local-vars
  1687. '(org-agenda-this-buffer-name
  1688. org-agenda-undo-list
  1689. org-agenda-pending-undo-list
  1690. org-agenda-follow-mode
  1691. org-agenda-entry-text-mode
  1692. org-agenda-clockreport-mode
  1693. org-agenda-show-log
  1694. org-agenda-redo-command
  1695. org-agenda-query-string
  1696. org-agenda-type
  1697. org-agenda-bulk-marked-entries
  1698. org-agenda-undo-has-started-in
  1699. org-agenda-info
  1700. org-agenda-tag-filter-overlays
  1701. org-agenda-cat-filter-overlays
  1702. org-agenda-pre-window-conf
  1703. org-agenda-columns-active
  1704. org-agenda-tag-filter
  1705. org-agenda-category-filter
  1706. org-agenda-markers
  1707. org-agenda-last-search-view-search-was-boolean
  1708. org-agenda-filtered-by-category
  1709. org-agenda-filter-form
  1710. org-agenda-show-window
  1711. org-agenda-cycle-counter
  1712. org-agenda-last-prefix-arg)
  1713. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1714. (defun org-agenda-mode ()
  1715. "Mode for time-sorted view on action items in Org-mode files.
  1716. The following commands are available:
  1717. \\{org-agenda-mode-map}"
  1718. (interactive)
  1719. (cond (org-agenda-doing-sticky-redo
  1720. ;; Refreshing sticky agenda-buffer
  1721. ;;
  1722. ;; Preserve the value of `org-agenda-local-vars' variables,
  1723. ;; while letting `kill-all-local-variables' kill the rest
  1724. (let ((save (buffer-local-variables)))
  1725. (kill-all-local-variables)
  1726. (mapc 'make-local-variable org-agenda-local-vars)
  1727. (dolist (elem save)
  1728. (let ((var (car elem))
  1729. (val (cdr elem)))
  1730. (when (and val
  1731. (member var org-agenda-local-vars))
  1732. (set var val)))))
  1733. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1734. (org-agenda-sticky
  1735. ;; Creating a sticky Agenda buffer for the first time
  1736. (kill-all-local-variables)
  1737. (mapc 'make-local-variable org-agenda-local-vars)
  1738. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1739. (t
  1740. ;; Creating a non-sticky agenda buffer
  1741. (kill-all-local-variables)
  1742. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1743. (setq org-agenda-undo-list nil
  1744. org-agenda-pending-undo-list nil
  1745. org-agenda-bulk-marked-entries nil)
  1746. (setq major-mode 'org-agenda-mode)
  1747. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1748. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1749. (setq mode-name "Org-Agenda")
  1750. (use-local-map org-agenda-mode-map)
  1751. (easy-menu-add org-agenda-menu)
  1752. (if org-startup-truncated (setq truncate-lines t))
  1753. (org-set-local 'line-move-visual nil)
  1754. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1755. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1756. ;; Make sure properties are removed when copying text
  1757. (make-local-variable 'filter-buffer-substring-functions)
  1758. (add-hook 'filter-buffer-substring-functions
  1759. (lambda (fun start end delete)
  1760. (substring-no-properties (funcall fun start end delete))))
  1761. (unless org-agenda-keep-modes
  1762. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1763. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1764. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1765. org-agenda-show-log org-agenda-start-with-log-mode))
  1766. (easy-menu-change
  1767. '("Agenda") "Agenda Files"
  1768. (append
  1769. (list
  1770. (vector
  1771. (if (get 'org-agenda-files 'org-restrict)
  1772. "Restricted to single file"
  1773. "Edit File List")
  1774. '(org-edit-agenda-file-list)
  1775. (not (get 'org-agenda-files 'org-restrict)))
  1776. "--")
  1777. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1778. (org-agenda-set-mode-name)
  1779. (apply
  1780. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1781. (list 'org-agenda-mode-hook)))
  1782. (substitute-key-definition 'undo 'org-agenda-undo
  1783. org-agenda-mode-map global-map)
  1784. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1785. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1786. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1787. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1788. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1789. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1790. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1791. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1792. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1793. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1794. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1795. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1796. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1797. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1798. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1799. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1800. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1801. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1802. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1803. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1804. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1805. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1806. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1807. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1808. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1809. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1810. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1811. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1812. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1813. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1814. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1815. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1816. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1817. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1818. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1819. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1820. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1821. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1822. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1823. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1824. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1825. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1826. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1827. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1828. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1829. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1830. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1831. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1833. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1834. (while l (org-defkey org-agenda-mode-map
  1835. (int-to-string (pop l)) 'digit-argument)))
  1836. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1837. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1838. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1839. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1840. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1841. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1842. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1843. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1844. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1845. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1846. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1847. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1849. 'org-clock-modify-effort-estimate)
  1850. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1851. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1852. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1853. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1854. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1855. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1856. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1857. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1858. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1859. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1860. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1861. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1862. (substitute-key-definition 'next-line 'org-agenda-next-line
  1863. org-agenda-mode-map global-map)
  1864. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1865. org-agenda-mode-map global-map)
  1866. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1867. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1868. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1869. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1870. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1871. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1872. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1873. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1874. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1875. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1876. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1877. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1878. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1879. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1880. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1881. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1882. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1883. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1884. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1885. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1886. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1887. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1888. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1889. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1890. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1891. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1892. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1893. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1894. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1895. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1896. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1897. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1898. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1899. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1900. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1901. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1902. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1903. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1904. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1905. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1906. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1907. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1908. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1909. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1910. (when org-agenda-mouse-1-follows-link
  1911. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1912. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1913. '("Agenda"
  1914. ("Agenda Files")
  1915. "--"
  1916. ("Agenda Dates"
  1917. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1918. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1919. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1920. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1921. "--"
  1922. ("View"
  1923. ["Day View" org-agenda-day-view
  1924. :active (org-agenda-check-type nil 'agenda)
  1925. :style radio :selected (eq org-agenda-current-span 'day)
  1926. :keys "v d (or just d)"]
  1927. ["Week View" org-agenda-week-view
  1928. :active (org-agenda-check-type nil 'agenda)
  1929. :style radio :selected (eq org-agenda-current-span 'week)
  1930. :keys "v w (or just w)"]
  1931. ["Month View" org-agenda-month-view
  1932. :active (org-agenda-check-type nil 'agenda)
  1933. :style radio :selected (eq org-agenda-current-span 'month)
  1934. :keys "v m"]
  1935. ["Year View" org-agenda-year-view
  1936. :active (org-agenda-check-type nil 'agenda)
  1937. :style radio :selected (eq org-agenda-current-span 'year)
  1938. :keys "v y"]
  1939. "--"
  1940. ["Include Diary" org-agenda-toggle-diary
  1941. :style toggle :selected org-agenda-include-diary
  1942. :active (org-agenda-check-type nil 'agenda)]
  1943. ["Include Deadlines" org-agenda-toggle-deadlines
  1944. :style toggle :selected org-agenda-include-deadlines
  1945. :active (org-agenda-check-type nil 'agenda)]
  1946. ["Use Time Grid" org-agenda-toggle-time-grid
  1947. :style toggle :selected org-agenda-use-time-grid
  1948. :active (org-agenda-check-type nil 'agenda)]
  1949. "--"
  1950. ["Show clock report" org-agenda-clockreport-mode
  1951. :style toggle :selected org-agenda-clockreport-mode
  1952. :active (org-agenda-check-type nil 'agenda)]
  1953. ["Show some entry text" org-agenda-entry-text-mode
  1954. :style toggle :selected org-agenda-entry-text-mode
  1955. :active t]
  1956. "--"
  1957. ["Show Logbook entries" org-agenda-log-mode
  1958. :style toggle :selected org-agenda-show-log
  1959. :active (org-agenda-check-type nil 'agenda 'timeline)
  1960. :keys "v l (or just l)"]
  1961. ["Include archived trees" org-agenda-archives-mode
  1962. :style toggle :selected org-agenda-archives-mode :active t
  1963. :keys "v a"]
  1964. ["Include archive files" (org-agenda-archives-mode t)
  1965. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1966. :keys "v A"]
  1967. "--"
  1968. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1969. ["Write view to file" org-agenda-write t]
  1970. ["Rebuild buffer" org-agenda-redo t]
  1971. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1972. "--"
  1973. ["Show original entry" org-agenda-show t]
  1974. ["Go To (other window)" org-agenda-goto t]
  1975. ["Go To (this window)" org-agenda-switch-to t]
  1976. ["Capture with cursor date" org-agenda-capture t]
  1977. ["Follow Mode" org-agenda-follow-mode
  1978. :style toggle :selected org-agenda-follow-mode :active t]
  1979. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1980. "--"
  1981. ("TODO"
  1982. ["Cycle TODO" org-agenda-todo t]
  1983. ["Next TODO set" org-agenda-todo-nextset t]
  1984. ["Previous TODO set" org-agenda-todo-previousset t]
  1985. ["Add note" org-agenda-add-note t])
  1986. ("Archive/Refile/Delete"
  1987. ["Archive default" org-agenda-archive-default t]
  1988. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1989. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1990. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1991. ["Archive subtree" org-agenda-archive t]
  1992. "--"
  1993. ["Refile" org-agenda-refile t]
  1994. "--"
  1995. ["Delete subtree" org-agenda-kill t])
  1996. ("Bulk action"
  1997. ["Mark entry" org-agenda-bulk-mark t]
  1998. ["Mark all" org-agenda-bulk-mark-all t]
  1999. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2000. ["Unmark entry" org-agenda-bulk-unmark t]
  2001. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2002. ["Act on all marked" org-agenda-bulk-action t]
  2003. "--"
  2004. ("Tags and Properties"
  2005. ["Show all Tags" org-agenda-show-tags t]
  2006. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2007. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2008. "--"
  2009. ["Column View" org-columns t])
  2010. ("Deadline/Schedule"
  2011. ["Schedule" org-agenda-schedule t]
  2012. ["Set Deadline" org-agenda-deadline t]
  2013. "--"
  2014. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2015. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2016. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2017. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2018. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2019. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2020. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2021. ("Clock and Effort"
  2022. ["Clock in" org-agenda-clock-in t]
  2023. ["Clock out" org-agenda-clock-out t]
  2024. ["Clock cancel" org-agenda-clock-cancel t]
  2025. ["Goto running clock" org-clock-goto t]
  2026. "--"
  2027. ["Set Effort" org-agenda-set-effort t]
  2028. ["Change clocked effort" org-clock-modify-effort-estimate
  2029. (org-clock-is-active)])
  2030. ("Priority"
  2031. ["Set Priority" org-agenda-priority t]
  2032. ["Increase Priority" org-agenda-priority-up t]
  2033. ["Decrease Priority" org-agenda-priority-down t]
  2034. ["Show Priority" org-show-priority t])
  2035. ("Calendar/Diary"
  2036. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2037. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2038. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2039. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2040. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2041. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2042. "--"
  2043. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2044. "--"
  2045. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2046. "--"
  2047. ("MobileOrg"
  2048. ["Push Files and Views" org-mobile-push t]
  2049. ["Get Captured and Flagged" org-mobile-pull t]
  2050. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2051. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2052. "--"
  2053. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2054. "--"
  2055. ["Quit" org-agenda-quit t]
  2056. ["Exit and Release Buffers" org-agenda-exit t]
  2057. ))
  2058. ;;; Agenda undo
  2059. (defvar org-agenda-allow-remote-undo t
  2060. "Non-nil means allow remote undo from the agenda buffer.")
  2061. (defvar org-agenda-undo-has-started-in nil
  2062. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2063. (defun org-agenda-undo ()
  2064. "Undo a remote editing step in the agenda.
  2065. This undoes changes both in the agenda buffer and in the remote buffer
  2066. that have been changed along."
  2067. (interactive)
  2068. (or org-agenda-allow-remote-undo
  2069. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2070. (if (not (eq this-command last-command))
  2071. (setq org-agenda-undo-has-started-in nil
  2072. org-agenda-pending-undo-list org-agenda-undo-list))
  2073. (if (not org-agenda-pending-undo-list)
  2074. (error "No further undo information"))
  2075. (let* ((entry (pop org-agenda-pending-undo-list))
  2076. buf line cmd rembuf)
  2077. (setq cmd (pop entry) line (pop entry))
  2078. (setq rembuf (nth 2 entry))
  2079. (org-with-remote-undo rembuf
  2080. (while (bufferp (setq buf (pop entry)))
  2081. (if (pop entry)
  2082. (with-current-buffer buf
  2083. (let ((last-undo-buffer buf)
  2084. (inhibit-read-only t))
  2085. (unless (memq buf org-agenda-undo-has-started-in)
  2086. (push buf org-agenda-undo-has-started-in)
  2087. (make-local-variable 'pending-undo-list)
  2088. (undo-start))
  2089. (while (and pending-undo-list
  2090. (listp pending-undo-list)
  2091. (not (car pending-undo-list)))
  2092. (pop pending-undo-list))
  2093. (undo-more 1))))))
  2094. (org-goto-line line)
  2095. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2096. (defun org-verify-change-for-undo (l1 l2)
  2097. "Verify that a real change occurred between the undo lists L1 and L2."
  2098. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2099. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2100. (not (eq l1 l2)))
  2101. ;;; Agenda dispatch
  2102. (defvar org-agenda-restrict-begin (make-marker))
  2103. (defvar org-agenda-restrict-end (make-marker))
  2104. (defvar org-agenda-last-dispatch-buffer nil)
  2105. (defvar org-agenda-overriding-restriction nil)
  2106. (defcustom org-agenda-custom-commands-contexts nil
  2107. "Alist of custom agenda keys and contextual rules.
  2108. For example, if you have a custom agenda command \"p\" and you
  2109. want this command to be accessible only from plain text files,
  2110. use this:
  2111. '((\"p\" (in-file . \"\\.txt\")))
  2112. Here are the available contexts definitions:
  2113. in-file: command displayed only in matching files
  2114. in-mode: command displayed only in matching modes
  2115. not-in-file: command not displayed in matching files
  2116. not-in-mode: command not displayed in matching modes
  2117. [function]: a custom function taking no argument
  2118. If you define several checks, the agenda command will be
  2119. accessible if there is at least one valid check.
  2120. You can also bind a key to another agenda custom command
  2121. depending on contextual rules.
  2122. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2123. Here it means: in .txt files, use \"p\" as the key for the
  2124. agenda command otherwise associated with \"q\". (The command
  2125. originally associated with \"q\" is not displayed to avoid
  2126. duplicates.)"
  2127. :version "24.3"
  2128. :group 'org-agenda-custom-commands
  2129. :type '(repeat (list :tag "Rule"
  2130. (string :tag " Agenda key")
  2131. (string :tag "Replace by command")
  2132. (repeat :tag "Available when"
  2133. (choice
  2134. (cons :tag "Condition"
  2135. (choice
  2136. (const :tag "In file" in-file)
  2137. (const :tag "Not in file" not-in-file)
  2138. (const :tag "In mode" in-mode)
  2139. (const :tag "Not in mode" not-in-mode))
  2140. (regexp))
  2141. (function :tag "Custom function"))))))
  2142. (defvar org-keys nil)
  2143. (defvar org-match nil)
  2144. ;;;###autoload
  2145. (defun org-agenda (&optional arg org-keys restriction)
  2146. "Dispatch agenda commands to collect entries to the agenda buffer.
  2147. Prompts for a command to execute. Any prefix arg will be passed
  2148. on to the selected command. The default selections are:
  2149. a Call `org-agenda-list' to display the agenda for current day or week.
  2150. t Call `org-todo-list' to display the global todo list.
  2151. T Call `org-todo-list' to display the global todo list, select only
  2152. entries with a specific TODO keyword (the user gets a prompt).
  2153. m Call `org-tags-view' to display headlines with tags matching
  2154. a condition (the user is prompted for the condition).
  2155. M Like `m', but select only TODO entries, no ordinary headlines.
  2156. L Create a timeline for the current buffer.
  2157. e Export views to associated files.
  2158. s Search entries for keywords.
  2159. S Search entries for keywords, only with TODO keywords.
  2160. / Multi occur across all agenda files and also files listed
  2161. in `org-agenda-text-search-extra-files'.
  2162. < Restrict agenda commands to buffer, subtree, or region.
  2163. Press several times to get the desired effect.
  2164. > Remove a previous restriction.
  2165. # List \"stuck\" projects.
  2166. ! Configure what \"stuck\" means.
  2167. C Configure custom agenda commands.
  2168. More commands can be added by configuring the variable
  2169. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2170. searches can be pre-defined in this way.
  2171. If the current buffer is in Org-mode and visiting a file, you can also
  2172. first press `<' once to indicate that the agenda should be temporarily
  2173. \(until the next use of \\[org-agenda]) restricted to the current file.
  2174. Pressing `<' twice means to restrict to the current subtree or region
  2175. \(if active)."
  2176. (interactive "P")
  2177. (catch 'exit
  2178. (let* ((prefix-descriptions nil)
  2179. (org-agenda-buffer-name org-agenda-buffer-name)
  2180. (org-agenda-window-setup (if (equal (buffer-name)
  2181. org-agenda-buffer-name)
  2182. 'current-window
  2183. org-agenda-window-setup))
  2184. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2185. (org-agenda-custom-commands
  2186. ;; normalize different versions
  2187. (delq nil
  2188. (mapcar
  2189. (lambda (x)
  2190. (cond ((stringp (cdr x))
  2191. (push x prefix-descriptions)
  2192. nil)
  2193. ((stringp (nth 1 x)) x)
  2194. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2195. (t (cons (car x) (cons "" (cdr x))))))
  2196. org-agenda-custom-commands)))
  2197. (org-agenda-custom-commands
  2198. (org-contextualize-keys
  2199. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2200. (buf (current-buffer))
  2201. (bfn (buffer-file-name (buffer-base-buffer)))
  2202. entry key type org-match lprops ans)
  2203. ;; Turn off restriction unless there is an overriding one,
  2204. (unless org-agenda-overriding-restriction
  2205. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2206. ;; There is a request to keep the file list in place
  2207. (put 'org-agenda-files 'org-restrict nil))
  2208. (setq org-agenda-restrict nil)
  2209. (move-marker org-agenda-restrict-begin nil)
  2210. (move-marker org-agenda-restrict-end nil))
  2211. ;; Delete old local properties
  2212. (put 'org-agenda-redo-command 'org-lprops nil)
  2213. ;; Delete previously set last-arguments
  2214. (put 'org-agenda-redo-command 'last-args nil)
  2215. ;; Remember where this call originated
  2216. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2217. (unless org-keys
  2218. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2219. org-keys (car ans)
  2220. restriction (cdr ans)))
  2221. ;; If we have sticky agenda buffers, set a name for the buffer,
  2222. ;; depending on the invoking keys. The user may still set this
  2223. ;; as a command option, which will overwrite what we do here.
  2224. (if org-agenda-sticky
  2225. (setq org-agenda-buffer-name
  2226. (format "*Org Agenda(%s)*" org-keys)))
  2227. ;; Establish the restriction, if any
  2228. (when (and (not org-agenda-overriding-restriction) restriction)
  2229. (put 'org-agenda-files 'org-restrict (list bfn))
  2230. (cond
  2231. ((eq restriction 'region)
  2232. (setq org-agenda-restrict t)
  2233. (move-marker org-agenda-restrict-begin (region-beginning))
  2234. (move-marker org-agenda-restrict-end (region-end)))
  2235. ((eq restriction 'subtree)
  2236. (save-excursion
  2237. (setq org-agenda-restrict t)
  2238. (org-back-to-heading t)
  2239. (move-marker org-agenda-restrict-begin (point))
  2240. (move-marker org-agenda-restrict-end
  2241. (progn (org-end-of-subtree t)))))))
  2242. ;; For example the todo list should not need it (but does...)
  2243. (cond
  2244. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2245. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2246. (progn
  2247. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2248. lprops (nth 4 entry))
  2249. (if org-agenda-sticky
  2250. (setq org-agenda-buffer-name
  2251. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2252. (format "*Org Agenda(%s)*" org-keys))))
  2253. (put 'org-agenda-redo-command 'org-lprops lprops)
  2254. (cond
  2255. ((eq type 'agenda)
  2256. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2257. ((eq type 'alltodo)
  2258. (org-let lprops '(org-todo-list current-prefix-arg)))
  2259. ((eq type 'search)
  2260. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2261. ((eq type 'stuck)
  2262. (org-let lprops '(org-agenda-list-stuck-projects
  2263. current-prefix-arg)))
  2264. ((eq type 'tags)
  2265. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2266. ((eq type 'tags-todo)
  2267. (org-let lprops '(org-tags-view '(4) org-match)))
  2268. ((eq type 'todo)
  2269. (org-let lprops '(org-todo-list org-match)))
  2270. ((eq type 'tags-tree)
  2271. (org-check-for-org-mode)
  2272. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2273. ((eq type 'todo-tree)
  2274. (org-check-for-org-mode)
  2275. (org-let lprops
  2276. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2277. (regexp-quote org-match) "\\>"))))
  2278. ((eq type 'occur-tree)
  2279. (org-check-for-org-mode)
  2280. (org-let lprops '(org-occur org-match)))
  2281. ((functionp type)
  2282. (org-let lprops '(funcall type org-match)))
  2283. ((fboundp type)
  2284. (org-let lprops '(funcall type org-match)))
  2285. (t (error "Invalid custom agenda command type %s" type))))
  2286. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2287. ((equal org-keys "C")
  2288. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2289. (customize-variable 'org-agenda-custom-commands))
  2290. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2291. ((equal org-keys "s") (call-interactively 'org-search-view))
  2292. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2293. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2294. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2295. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2296. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2297. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2298. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2299. (org-add-hook
  2300. 'post-command-hook
  2301. (lambda ()
  2302. (unless (current-message)
  2303. (let* ((m (org-agenda-get-any-marker))
  2304. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2305. (when note
  2306. (message (concat
  2307. "FLAGGING-NOTE ([?] for more info): "
  2308. (org-add-props
  2309. (replace-regexp-in-string
  2310. "\\\\n" "//"
  2311. (copy-sequence note))
  2312. nil 'face 'org-warning)))))))
  2313. t t))
  2314. ((equal org-keys "L")
  2315. (unless (derived-mode-p 'org-mode)
  2316. (error "This is not an Org-mode file"))
  2317. (unless restriction
  2318. (put 'org-agenda-files 'org-restrict (list bfn))
  2319. (org-call-with-arg 'org-timeline arg)))
  2320. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2321. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2322. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2323. (t (error "Invalid agenda key"))))))
  2324. (autoload 'org-agenda "org-agenda" "\
  2325. Dispatch agenda commands to collect entries to the agenda buffer.
  2326. Prompts for a command to execute. Any prefix arg will be passed
  2327. on to the selected command. The default selections are:
  2328. a Call `org-agenda-list' to display the agenda for current day or week.
  2329. t Call `org-todo-list' to display the global todo list.
  2330. T Call `org-todo-list' to display the global todo list, select only
  2331. entries with a specific TODO keyword (the user gets a prompt).
  2332. m Call `org-tags-view' to display headlines with tags matching
  2333. a condition (the user is prompted for the condition).
  2334. M Like `m', but select only TODO entries, no ordinary headlines.
  2335. L Create a timeline for the current buffer.
  2336. e Export views to associated files.
  2337. s Search entries for keywords.
  2338. S Search entries for keywords, only with TODO keywords.
  2339. / Multi occur across all agenda files and also files listed
  2340. in `org-agenda-text-search-extra-files'.
  2341. < Restrict agenda commands to buffer, subtree, or region.
  2342. Press several times to get the desired effect.
  2343. > Remove a previous restriction.
  2344. # List \"stuck\" projects.
  2345. ! Configure what \"stuck\" means.
  2346. C Configure custom agenda commands.
  2347. More commands can be added by configuring the variable
  2348. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2349. searches can be pre-defined in this way.
  2350. If the current buffer is in Org-mode and visiting a file, you can also
  2351. first press `<' once to indicate that the agenda should be temporarily
  2352. \(until the next use of \\[org-agenda]) restricted to the current file.
  2353. Pressing `<' twice means to restrict to the current subtree or region
  2354. \(if active).
  2355. \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
  2356. (defun org-agenda-append-agenda ()
  2357. "Append another agenda view to the current one.
  2358. This function allows interactive building of block agendas.
  2359. Agenda views are separated by `org-agenda-block-separator'."
  2360. (interactive)
  2361. (unless (derived-mode-p 'org-agenda-mode)
  2362. (error "Can only append from within agenda buffer"))
  2363. (let ((org-agenda-multi t))
  2364. (org-agenda)
  2365. (widen)
  2366. (org-agenda-finalize)
  2367. (org-agenda-fit-window-to-buffer)))
  2368. (defun org-agenda-normalize-custom-commands (cmds)
  2369. (delq nil
  2370. (mapcar
  2371. (lambda (x)
  2372. (cond ((stringp (cdr x)) nil)
  2373. ((stringp (nth 1 x)) x)
  2374. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2375. (t (cons (car x) (cons "" (cdr x))))))
  2376. cmds)))
  2377. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2378. "The user interface for selecting an agenda command."
  2379. (catch 'exit
  2380. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2381. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2382. (region-p (org-region-active-p))
  2383. (custom org-agenda-custom-commands)
  2384. (selstring "")
  2385. restriction second-time
  2386. c entry key type match prefixes rmheader header-end custom1 desc
  2387. line lines left right n n1)
  2388. (save-window-excursion
  2389. (delete-other-windows)
  2390. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2391. (erase-buffer)
  2392. (insert (eval-when-compile
  2393. (let ((header
  2394. "Press key for an agenda command: < Buffer, subtree/region restriction
  2395. -------------------------------- > Remove restriction
  2396. a Agenda for current week or day e Export agenda views
  2397. t List of all TODO entries T Entries with special TODO kwd
  2398. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2399. s Search for keywords S Like s, but only TODO entries
  2400. L Timeline for current buffer # List stuck projects (!=configure)
  2401. / Multi-occur C Configure custom agenda commands
  2402. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2403. ")
  2404. (start 0))
  2405. (while (string-match
  2406. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2407. header start)
  2408. (setq start (match-end 0))
  2409. (add-text-properties (match-beginning 2) (match-end 2)
  2410. '(face bold) header))
  2411. header)))
  2412. (setq header-end (point-marker))
  2413. (while t
  2414. (setq custom1 custom)
  2415. (when (eq rmheader t)
  2416. (org-goto-line 1)
  2417. (re-search-forward ":" nil t)
  2418. (delete-region (match-end 0) (point-at-eol))
  2419. (forward-char 1)
  2420. (looking-at "-+")
  2421. (delete-region (match-end 0) (point-at-eol))
  2422. (move-marker header-end (match-end 0)))
  2423. (goto-char header-end)
  2424. (delete-region (point) (point-max))
  2425. ;; Produce all the lines that describe custom commands and prefixes
  2426. (setq lines nil)
  2427. (while (setq entry (pop custom1))
  2428. (setq key (car entry) desc (nth 1 entry)
  2429. type (nth 2 entry)
  2430. match (nth 3 entry))
  2431. (if (> (length key) 1)
  2432. (add-to-list 'prefixes (string-to-char key))
  2433. (setq line
  2434. (format
  2435. "%-4s%-14s"
  2436. (org-add-props (copy-sequence key)
  2437. '(face bold))
  2438. (cond
  2439. ((string-match "\\S-" desc) desc)
  2440. ((eq type 'agenda) "Agenda for current week or day")
  2441. ((eq type 'alltodo) "List of all TODO entries")
  2442. ((eq type 'search) "Word search")
  2443. ((eq type 'stuck) "List of stuck projects")
  2444. ((eq type 'todo) "TODO keyword")
  2445. ((eq type 'tags) "Tags query")
  2446. ((eq type 'tags-todo) "Tags (TODO)")
  2447. ((eq type 'tags-tree) "Tags tree")
  2448. ((eq type 'todo-tree) "TODO kwd tree")
  2449. ((eq type 'occur-tree) "Occur tree")
  2450. ((functionp type) (if (symbolp type)
  2451. (symbol-name type)
  2452. "Lambda expression"))
  2453. (t "???"))))
  2454. (if org-agenda-menu-show-matcher
  2455. (setq line
  2456. (concat line ": "
  2457. (cond
  2458. ((stringp match)
  2459. (setq match (copy-sequence match))
  2460. (org-add-props match nil 'face 'org-warning))
  2461. ((listp type)
  2462. (format "set of %d commands" (length type))))))
  2463. (if (org-string-nw-p match)
  2464. (add-text-properties
  2465. 0 (length line) (list 'help-echo
  2466. (concat "Matcher: " match)) line)))
  2467. (push line lines)))
  2468. (setq lines (nreverse lines))
  2469. (when prefixes
  2470. (mapc (lambda (x)
  2471. (push
  2472. (format "%s %s"
  2473. (org-add-props (char-to-string x)
  2474. nil 'face 'bold)
  2475. (or (cdr (assoc (concat selstring
  2476. (char-to-string x))
  2477. prefix-descriptions))
  2478. "Prefix key"))
  2479. lines))
  2480. prefixes))
  2481. ;; Check if we should display in two columns
  2482. (if org-agenda-menu-two-columns
  2483. (progn
  2484. (setq n (length lines)
  2485. n1 (+ (/ n 2) (mod n 2))
  2486. right (nthcdr n1 lines)
  2487. left (copy-sequence lines))
  2488. (setcdr (nthcdr (1- n1) left) nil))
  2489. (setq left lines right nil))
  2490. (while left
  2491. (insert "\n" (pop left))
  2492. (when right
  2493. (if (< (current-column) 40)
  2494. (move-to-column 40 t)
  2495. (insert " "))
  2496. (insert (pop right))))
  2497. ;; Make the window the right size
  2498. (goto-char (point-min))
  2499. (if second-time
  2500. (if (not (pos-visible-in-window-p (point-max)))
  2501. (org-fit-window-to-buffer))
  2502. (setq second-time t)
  2503. (org-fit-window-to-buffer))
  2504. ;; Ask for selection
  2505. (message "Press key for agenda command%s:"
  2506. (if (or restrict-ok org-agenda-overriding-restriction)
  2507. (if org-agenda-overriding-restriction
  2508. " (restriction lock active)"
  2509. (if restriction
  2510. (format " (restricted to %s)" restriction)
  2511. " (unrestricted)"))
  2512. ""))
  2513. (setq c (read-char-exclusive))
  2514. (message "")
  2515. (cond
  2516. ((assoc (char-to-string c) custom)
  2517. (setq selstring (concat selstring (char-to-string c)))
  2518. (throw 'exit (cons selstring restriction)))
  2519. ((memq c prefixes)
  2520. (setq selstring (concat selstring (char-to-string c))
  2521. prefixes nil
  2522. rmheader (or rmheader t)
  2523. custom (delq nil (mapcar
  2524. (lambda (x)
  2525. (if (or (= (length (car x)) 1)
  2526. (/= (string-to-char (car x)) c))
  2527. nil
  2528. (cons (substring (car x) 1) (cdr x))))
  2529. custom))))
  2530. ((eq c ?*)
  2531. (call-interactively 'org-toggle-sticky-agenda)
  2532. (sit-for 2))
  2533. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2534. (message "Restriction is only possible in Org-mode buffers")
  2535. (ding) (sit-for 1))
  2536. ((eq c ?1)
  2537. (org-agenda-remove-restriction-lock 'noupdate)
  2538. (setq restriction 'buffer))
  2539. ((eq c ?0)
  2540. (org-agenda-remove-restriction-lock 'noupdate)
  2541. (setq restriction (if region-p 'region 'subtree)))
  2542. ((eq c ?<)
  2543. (org-agenda-remove-restriction-lock 'noupdate)
  2544. (setq restriction
  2545. (cond
  2546. ((eq restriction 'buffer)
  2547. (if region-p 'region 'subtree))
  2548. ((memq restriction '(subtree region))
  2549. nil)
  2550. (t 'buffer))))
  2551. ((eq c ?>)
  2552. (org-agenda-remove-restriction-lock 'noupdate)
  2553. (setq restriction nil))
  2554. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2555. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2556. ((and (> (length selstring) 0) (eq c ?\d))
  2557. (delete-window)
  2558. (org-agenda-get-restriction-and-command prefix-descriptions))
  2559. ((equal c ?q) (error "Abort"))
  2560. (t (error "Invalid key %c" c))))))))
  2561. (defun org-agenda-fit-window-to-buffer ()
  2562. "Fit the window to the buffer size."
  2563. (and (memq org-agenda-window-setup '(reorganize-frame))
  2564. (fboundp 'fit-window-to-buffer)
  2565. (org-fit-window-to-buffer
  2566. nil
  2567. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2568. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2569. (defvar org-cmd nil)
  2570. (defvar org-agenda-overriding-cmd nil)
  2571. (defvar org-agenda-overriding-arguments nil)
  2572. (defvar org-agenda-overriding-cmd-arguments nil)
  2573. (defun org-agenda-run-series (name series)
  2574. (org-let (nth 1 series) '(org-agenda-prepare name))
  2575. ;; We need to reset agenda markers here, because when constructing a
  2576. ;; block agenda, the individual blocks do not do that.
  2577. (org-agenda-reset-markers)
  2578. (let* ((org-agenda-multi t)
  2579. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2580. (cmds (car series))
  2581. (gprops (nth 1 series))
  2582. match ;; The byte compiler incorrectly complains about this. Keep it!
  2583. org-cmd type lprops)
  2584. (while (setq org-cmd (pop cmds))
  2585. (setq type (car org-cmd)
  2586. match (eval (nth 1 org-cmd))
  2587. lprops (nth 2 org-cmd))
  2588. (let ((org-agenda-overriding-arguments
  2589. (if (eq org-agenda-overriding-cmd org-cmd)
  2590. (or org-agenda-overriding-arguments
  2591. org-agenda-overriding-cmd-arguments))))
  2592. (cond
  2593. ((eq type 'agenda)
  2594. (org-let2 gprops lprops
  2595. '(call-interactively 'org-agenda-list)))
  2596. ((eq type 'alltodo)
  2597. (org-let2 gprops lprops
  2598. '(call-interactively 'org-todo-list)))
  2599. ((eq type 'search)
  2600. (org-let2 gprops lprops
  2601. '(org-search-view current-prefix-arg match nil)))
  2602. ((eq type 'stuck)
  2603. (org-let2 gprops lprops
  2604. '(call-interactively 'org-agenda-list-stuck-projects)))
  2605. ((eq type 'tags)
  2606. (org-let2 gprops lprops
  2607. '(org-tags-view current-prefix-arg match)))
  2608. ((eq type 'tags-todo)
  2609. (org-let2 gprops lprops
  2610. '(org-tags-view '(4) match)))
  2611. ((eq type 'todo)
  2612. (org-let2 gprops lprops
  2613. '(org-todo-list match)))
  2614. ((fboundp type)
  2615. (org-let2 gprops lprops
  2616. '(funcall type match)))
  2617. (t (error "Invalid type in command series")))))
  2618. (widen)
  2619. (let ((inhibit-read-only t))
  2620. (add-text-properties (point-min) (point-max)
  2621. `(org-series t org-series-redo-cmd ,redo)))
  2622. (setq org-agenda-redo-command redo)
  2623. (goto-char (point-min)))
  2624. (org-agenda-fit-window-to-buffer)
  2625. (org-let (nth 1 series) '(org-agenda-finalize)))
  2626. ;;;###autoload
  2627. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2628. "Run an agenda command in batch mode and send the result to STDOUT.
  2629. If CMD-KEY is a string of length 1, it is used as a key in
  2630. `org-agenda-custom-commands' and triggers this command. If it is a
  2631. longer string it is used as a tags/todo match string.
  2632. Parameters are alternating variable names and values that will be bound
  2633. before running the agenda command."
  2634. (org-eval-in-environment (org-make-parameter-alist parameters)
  2635. (if (> (length cmd-key) 2)
  2636. (org-tags-view nil cmd-key)
  2637. (org-agenda nil cmd-key)))
  2638. (set-buffer org-agenda-buffer-name)
  2639. (princ (buffer-string)))
  2640. (autoload 'org-batch-agenda "org-agenda" "\
  2641. Run an agenda command in batch mode and send the result to STDOUT.
  2642. If CMD-KEY is a string of length 1, it is used as a key in
  2643. `org-agenda-custom-commands' and triggers this command. If it is a
  2644. longer string it is used as a tags/todo match string.
  2645. Parameters are alternating variable names and values that will be bound
  2646. before running the agenda command.
  2647. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2648. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2649. (defvar org-agenda-info nil)
  2650. ;;;###autoload
  2651. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2652. "Run an agenda command in batch mode and send the result to STDOUT.
  2653. If CMD-KEY is a string of length 1, it is used as a key in
  2654. `org-agenda-custom-commands' and triggers this command. If it is a
  2655. longer string it is used as a tags/todo match string.
  2656. Parameters are alternating variable names and values that will be bound
  2657. before running the agenda command.
  2658. The output gives a line for each selected agenda item. Each
  2659. item is a list of comma-separated values, like this:
  2660. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2661. category The category of the item
  2662. head The headline, without TODO kwd, TAGS and PRIORITY
  2663. type The type of the agenda entry, can be
  2664. todo selected in TODO match
  2665. tagsmatch selected in tags match
  2666. diary imported from diary
  2667. deadline a deadline on given date
  2668. scheduled scheduled on given date
  2669. timestamp entry has timestamp on given date
  2670. closed entry was closed on given date
  2671. upcoming-deadline warning about deadline
  2672. past-scheduled forwarded scheduled item
  2673. block entry has date block including g. date
  2674. todo The todo keyword, if any
  2675. tags All tags including inherited ones, separated by colons
  2676. date The relevant date, like 2007-2-14
  2677. time The time, like 15:00-16:50
  2678. extra Sting with extra planning info
  2679. priority-l The priority letter if any was given
  2680. priority-n The computed numerical priority
  2681. agenda-day The day in the agenda where this is listed"
  2682. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2683. (org-make-parameter-alist parameters))
  2684. (if (> (length cmd-key) 2)
  2685. (org-tags-view nil cmd-key)
  2686. (org-agenda nil cmd-key)))
  2687. (set-buffer org-agenda-buffer-name)
  2688. (let* ((lines (org-split-string (buffer-string) "\n"))
  2689. line)
  2690. (while (setq line (pop lines))
  2691. (catch 'next
  2692. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2693. (setq org-agenda-info
  2694. (org-fix-agenda-info (text-properties-at 0 line)))
  2695. (princ
  2696. (mapconcat 'org-agenda-export-csv-mapper
  2697. '(org-category txt type todo tags date time extra
  2698. priority-letter priority agenda-day)
  2699. ","))
  2700. (princ "\n")))))
  2701. (autoload 'org-batch-agenda-csv "org-agenda" "\
  2702. Run an agenda command in batch mode and send the result to STDOUT.
  2703. If CMD-KEY is a string of length 1, it is used as a key in
  2704. `org-agenda-custom-commands' and triggers this command. If it is a
  2705. longer string it is used as a tags/todo match string.
  2706. Parameters are alternating variable names and values that will be bound
  2707. before running the agenda command.
  2708. The output gives a line for each selected agenda item. Each
  2709. item is a list of comma-separated values, like this:
  2710. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2711. category The category of the item
  2712. head The headline, without TODO kwd, TAGS and PRIORITY
  2713. type The type of the agenda entry, can be
  2714. todo selected in TODO match
  2715. tagsmatch selected in tags match
  2716. diary imported from diary
  2717. deadline a deadline on given date
  2718. scheduled scheduled on given date
  2719. timestamp entry has timestamp on given date
  2720. closed entry was closed on given date
  2721. upcoming-deadline warning about deadline
  2722. past-scheduled forwarded scheduled item
  2723. block entry has date block including g. date
  2724. todo The todo keyword, if any
  2725. tags All tags including inherited ones, separated by colons
  2726. date The relevant date, like 2007-2-14
  2727. time The time, like 15:00-16:50
  2728. extra Sting with extra planning info
  2729. priority-l The priority letter if any was given
  2730. priority-n The computed numerical priority
  2731. agenda-day The day in the agenda where this is listed
  2732. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2733. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2734. (defun org-fix-agenda-info (props)
  2735. "Make sure all properties on an agenda item have a canonical form.
  2736. This ensures the export commands can easily use it."
  2737. (let (tmp re)
  2738. (when (setq tmp (plist-get props 'tags))
  2739. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2740. (when (setq tmp (plist-get props 'date))
  2741. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2742. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2743. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2744. (setq tmp (calendar-date-string tmp)))
  2745. (setq props (plist-put props 'date tmp)))
  2746. (when (setq tmp (plist-get props 'day))
  2747. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2748. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2749. (setq tmp (calendar-date-string tmp)))
  2750. (setq props (plist-put props 'day tmp))
  2751. (setq props (plist-put props 'agenda-day tmp)))
  2752. (when (setq tmp (plist-get props 'txt))
  2753. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2754. (plist-put props 'priority-letter (match-string 1 tmp))
  2755. (setq tmp (replace-match "" t t tmp)))
  2756. (when (and (setq re (plist-get props 'org-todo-regexp))
  2757. (setq re (concat "\\`\\.*" re " ?"))
  2758. (string-match re tmp))
  2759. (plist-put props 'todo (match-string 1 tmp))
  2760. (setq tmp (replace-match "" t t tmp)))
  2761. (plist-put props 'txt tmp)))
  2762. props)
  2763. (defun org-agenda-export-csv-mapper (prop)
  2764. (let ((res (plist-get org-agenda-info prop)))
  2765. (setq res
  2766. (cond
  2767. ((not res) "")
  2768. ((stringp res) res)
  2769. (t (prin1-to-string res))))
  2770. (while (string-match "," res)
  2771. (setq res (replace-match ";" t t res)))
  2772. (org-trim res)))
  2773. ;;;###autoload
  2774. (defun org-store-agenda-views (&rest parameters)
  2775. (interactive)
  2776. (eval (list 'org-batch-store-agenda-views)))
  2777. (autoload 'org-store-agenda-views "org-agenda" "\
  2778. \(fn &rest PARAMETERS)" t nil)
  2779. ;;;###autoload
  2780. (defmacro org-batch-store-agenda-views (&rest parameters)
  2781. "Run all custom agenda commands that have a file argument."
  2782. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2783. (pop-up-frames nil)
  2784. (dir default-directory)
  2785. (pars (org-make-parameter-alist parameters))
  2786. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2787. (save-window-excursion
  2788. (while cmds
  2789. (setq cmd (pop cmds)
  2790. thiscmdkey (car cmd)
  2791. thiscmdcmd (cdr cmd)
  2792. match (nth 2 thiscmdcmd)
  2793. bufname (if org-agenda-sticky
  2794. (or (and (stringp match)
  2795. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2796. (format "*Org Agenda(%s)*" thiscmdkey))
  2797. org-agenda-buffer-name)
  2798. cmd-or-set (nth 2 cmd)
  2799. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2800. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2801. (if (stringp files) (setq files (list files)))
  2802. (when files
  2803. (org-eval-in-environment (append org-agenda-exporter-settings
  2804. opts pars)
  2805. (org-agenda nil thiscmdkey))
  2806. (set-buffer bufname)
  2807. (while files
  2808. (org-eval-in-environment (append org-agenda-exporter-settings
  2809. opts pars)
  2810. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2811. (and (get-buffer bufname)
  2812. (kill-buffer bufname)))))))
  2813. (autoload 'org-batch-store-agenda-views "org-agenda" "\
  2814. Run all custom agenda commands that have a file argument.
  2815. \(fn &rest PARAMETERS)" nil t)
  2816. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2817. (defvar org-agenda-current-span nil
  2818. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2819. (defun org-agenda-mark-header-line (pos)
  2820. "Mark the line at POS as an agenda structure header."
  2821. (save-excursion
  2822. (goto-char pos)
  2823. (put-text-property (point-at-bol) (point-at-eol)
  2824. 'org-agenda-structural-header t)
  2825. (when org-agenda-title-append
  2826. (put-text-property (point-at-bol) (point-at-eol)
  2827. 'org-agenda-title-append org-agenda-title-append))))
  2828. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2829. (defvar org-agenda-write-buffer-name "Agenda View")
  2830. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2831. "Write the current buffer (an agenda view) as a file.
  2832. Depending on the extension of the file name, plain text (.txt),
  2833. HTML (.html or .htm) or Postscript (.ps) is produced.
  2834. If the extension is .ics, run icalendar export over all files used
  2835. to construct the agenda and limit the export to entries listed in the
  2836. agenda now.
  2837. With prefix argument OPEN, open the new file immediately.
  2838. If NOSETTINGS is given, do not scope the settings of
  2839. `org-agenda-exporter-settings' into the export commands. This is used when
  2840. the settings have already been scoped and we do not wish to overrule other,
  2841. higher priority settings.
  2842. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2843. (interactive "FWrite agenda to file: \nP")
  2844. (if (not (file-writable-p file))
  2845. (error "Cannot write agenda to file %s" file))
  2846. (org-let (if nosettings nil org-agenda-exporter-settings)
  2847. '(save-excursion
  2848. (save-window-excursion
  2849. (org-agenda-mark-filtered-text)
  2850. (let ((bs (copy-sequence (buffer-string))) beg)
  2851. (org-agenda-unmark-filtered-text)
  2852. (with-temp-buffer
  2853. (rename-buffer org-agenda-write-buffer-name t)
  2854. (set-buffer-modified-p nil)
  2855. (insert bs)
  2856. (org-agenda-remove-marked-text 'org-filtered)
  2857. (while (setq beg (text-property-any (point-min) (point-max)
  2858. 'org-filtered t))
  2859. (delete-region
  2860. beg (or (next-single-property-change beg 'org-filtered)
  2861. (point-max))))
  2862. (run-hooks 'org-agenda-before-write-hook)
  2863. (cond
  2864. ((org-bound-and-true-p org-mobile-creating-agendas)
  2865. (org-mobile-write-agenda-for-mobile file))
  2866. ((string-match "\\.html?\\'" file)
  2867. (require 'htmlize)
  2868. (set-buffer (htmlize-buffer (current-buffer)))
  2869. (when org-agenda-export-html-style
  2870. ;; replace <style> section with org-agenda-export-html-style
  2871. (goto-char (point-min))
  2872. (kill-region (- (search-forward "<style") 6)
  2873. (search-forward "</style>"))
  2874. (insert org-agenda-export-html-style))
  2875. (write-file file)
  2876. (kill-buffer (current-buffer))
  2877. (message "HTML written to %s" file))
  2878. ((string-match "\\.ps\\'" file)
  2879. (require 'ps-print)
  2880. (ps-print-buffer-with-faces file)
  2881. (message "Postscript written to %s" file))
  2882. ((string-match "\\.pdf\\'" file)
  2883. (require 'ps-print)
  2884. (ps-print-buffer-with-faces
  2885. (concat (file-name-sans-extension file) ".ps"))
  2886. (call-process "ps2pdf" nil nil nil
  2887. (expand-file-name
  2888. (concat (file-name-sans-extension file) ".ps"))
  2889. (expand-file-name file))
  2890. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2891. (message "PDF written to %s" file))
  2892. ((string-match "\\.ics\\'" file)
  2893. (require 'org-icalendar)
  2894. (let ((org-agenda-marker-table
  2895. (org-create-marker-find-array
  2896. (org-agenda-collect-markers)))
  2897. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2898. (org-combined-agenda-icalendar-file file))
  2899. (apply 'org-export-icalendar 'combine
  2900. (org-agenda-files nil 'ifmode))))
  2901. (t
  2902. (let ((bs (buffer-string)))
  2903. (find-file file)
  2904. (erase-buffer)
  2905. (insert bs)
  2906. (save-buffer 0)
  2907. (kill-buffer (current-buffer))
  2908. (message "Plain text written to %s" file))))))))
  2909. (set-buffer (or agenda-bufname
  2910. (and (org-called-interactively-p 'any) (buffer-name))
  2911. org-agenda-buffer-name)))
  2912. (when open (org-open-file file)))
  2913. (defvar org-agenda-tag-filter-overlays nil)
  2914. (defvar org-agenda-cat-filter-overlays nil)
  2915. (defun org-agenda-mark-filtered-text ()
  2916. "Mark all text hidden by filtering with a text property."
  2917. (let ((inhibit-read-only t))
  2918. (mapc
  2919. (lambda (o)
  2920. (when (equal (overlay-buffer o) (current-buffer))
  2921. (put-text-property
  2922. (overlay-start o) (overlay-end o)
  2923. 'org-filtered t)))
  2924. (append org-agenda-tag-filter-overlays
  2925. org-agenda-cat-filter-overlays))))
  2926. (defun org-agenda-unmark-filtered-text ()
  2927. "Remove the filtering text property."
  2928. (let ((inhibit-read-only t))
  2929. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2930. (defun org-agenda-remove-marked-text (property &optional value)
  2931. "Delete all text marked with VALUE of PROPERTY.
  2932. VALUE defaults to t."
  2933. (let (beg)
  2934. (setq value (or value t))
  2935. (while (setq beg (text-property-any (point-min) (point-max)
  2936. property value))
  2937. (delete-region
  2938. beg (or (next-single-property-change beg 'org-filtered)
  2939. (point-max))))))
  2940. (defun org-agenda-add-entry-text ()
  2941. "Add entry text to agenda lines.
  2942. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2943. entry text following headings shown in the agenda.
  2944. Drawers will be excluded, also the line with scheduling/deadline info."
  2945. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2946. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2947. (let (m txt)
  2948. (goto-char (point-min))
  2949. (while (not (eobp))
  2950. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2951. (beginning-of-line 2)
  2952. (setq txt (org-agenda-get-some-entry-text
  2953. m org-agenda-add-entry-text-maxlines " > "))
  2954. (end-of-line 1)
  2955. (if (string-match "\\S-" txt)
  2956. (insert "\n" txt)
  2957. (or (eobp) (forward-char 1))))))))
  2958. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2959. &rest keep)
  2960. "Extract entry text from MARKER, at most N-LINES lines.
  2961. This will ignore drawers etc, just get the text.
  2962. If INDENT is given, prefix every line with this string. If KEEP is
  2963. given, it is a list of symbols, defining stuff that should not be
  2964. removed from the entry content. Currently only `planning' is allowed here."
  2965. (let (txt drawer-re kwd-time-re ind)
  2966. (save-excursion
  2967. (with-current-buffer (marker-buffer marker)
  2968. (if (not (derived-mode-p 'org-mode))
  2969. (setq txt "")
  2970. (save-excursion
  2971. (save-restriction
  2972. (widen)
  2973. (goto-char marker)
  2974. (end-of-line 1)
  2975. (setq txt (buffer-substring
  2976. (min (1+ (point)) (point-max))
  2977. (progn (outline-next-heading) (point)))
  2978. drawer-re org-drawer-regexp
  2979. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2980. ".*\n?"))
  2981. (with-temp-buffer
  2982. (insert txt)
  2983. (when org-agenda-add-entry-text-descriptive-links
  2984. (goto-char (point-min))
  2985. (while (org-activate-bracket-links (point-max))
  2986. (add-text-properties (match-beginning 0) (match-end 0)
  2987. '(face org-link))))
  2988. (goto-char (point-min))
  2989. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2990. (set-text-properties (match-beginning 0) (match-end 0)
  2991. nil))
  2992. (goto-char (point-min))
  2993. (while (re-search-forward drawer-re nil t)
  2994. (delete-region
  2995. (match-beginning 0)
  2996. (progn (re-search-forward
  2997. "^[ \t]*:END:.*\n?" nil 'move)
  2998. (point))))
  2999. (unless (member 'planning keep)
  3000. (goto-char (point-min))
  3001. (while (re-search-forward kwd-time-re nil t)
  3002. (replace-match "")))
  3003. (goto-char (point-min))
  3004. (when org-agenda-entry-text-exclude-regexps
  3005. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3006. (while (setq re (pop re-list))
  3007. (goto-char (point-min))
  3008. (while (re-search-forward re nil t)
  3009. (replace-match "")))))
  3010. (goto-char (point-max))
  3011. (skip-chars-backward " \t\n")
  3012. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3013. ;; find and remove min common indentation
  3014. (goto-char (point-min))
  3015. (untabify (point-min) (point-max))
  3016. (setq ind (org-get-indentation))
  3017. (while (not (eobp))
  3018. (unless (looking-at "[ \t]*$")
  3019. (setq ind (min ind (org-get-indentation))))
  3020. (beginning-of-line 2))
  3021. (goto-char (point-min))
  3022. (while (not (eobp))
  3023. (unless (looking-at "[ \t]*$")
  3024. (move-to-column ind)
  3025. (delete-region (point-at-bol) (point)))
  3026. (beginning-of-line 2))
  3027. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3028. (goto-char (point-min))
  3029. (when indent
  3030. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3031. (replace-match indent t t)))
  3032. (goto-char (point-min))
  3033. (while (looking-at "[ \t]*\n") (replace-match ""))
  3034. (goto-char (point-max))
  3035. (when (> (org-current-line)
  3036. n-lines)
  3037. (org-goto-line (1+ n-lines))
  3038. (backward-char 1))
  3039. (setq txt (buffer-substring (point-min) (point)))))))))
  3040. txt))
  3041. (defun org-agenda-collect-markers ()
  3042. "Collect the markers pointing to entries in the agenda buffer."
  3043. (let (m markers)
  3044. (save-excursion
  3045. (goto-char (point-min))
  3046. (while (not (eobp))
  3047. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3048. (org-get-at-bol 'org-marker)))
  3049. (push m markers))
  3050. (beginning-of-line 2)))
  3051. (nreverse markers)))
  3052. (defun org-create-marker-find-array (marker-list)
  3053. "Create a alist of files names with all marker positions in that file."
  3054. (let (f tbl m a p)
  3055. (while (setq m (pop marker-list))
  3056. (setq p (marker-position m)
  3057. f (buffer-file-name (or (buffer-base-buffer
  3058. (marker-buffer m))
  3059. (marker-buffer m))))
  3060. (if (setq a (assoc f tbl))
  3061. (push (marker-position m) (cdr a))
  3062. (push (list f p) tbl)))
  3063. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3064. tbl)))
  3065. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3066. (defun org-check-agenda-marker-table ()
  3067. "Check of the current entry is on the marker list."
  3068. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3069. a)
  3070. (and (setq a (assoc file org-agenda-marker-table))
  3071. (save-match-data
  3072. (save-excursion
  3073. (org-back-to-heading t)
  3074. (member (point) (cdr a)))))))
  3075. (defun org-check-for-org-mode ()
  3076. "Make sure current buffer is in org-mode. Error if not."
  3077. (or (derived-mode-p 'org-mode)
  3078. (error "Cannot execute org-mode agenda command on buffer in %s"
  3079. major-mode)))
  3080. ;;; Agenda prepare and finalize
  3081. (defvar org-agenda-multi nil) ; dynamically scoped
  3082. (defvar org-agenda-pre-window-conf nil)
  3083. (defvar org-agenda-columns-active nil)
  3084. (defvar org-agenda-name nil)
  3085. (defvar org-agenda-tag-filter nil)
  3086. (defvar org-agenda-category-filter nil)
  3087. (defvar org-agenda-top-category-filter nil)
  3088. (defvar org-agenda-tag-filter-while-redo nil)
  3089. (defvar org-agenda-tag-filter-preset nil
  3090. "A preset of the tags filter used for secondary agenda filtering.
  3091. This must be a list of strings, each string must be a single tag preceded
  3092. by \"+\" or \"-\".
  3093. This variable should not be set directly, but agenda custom commands can
  3094. bind it in the options section. The preset filter is a global property of
  3095. the entire agenda view. In a block agenda, it will not work reliably to
  3096. define a filter for one of the individual blocks. You need to set it in
  3097. the global options and expect it to be applied to the entire view.")
  3098. (defvar org-agenda-category-filter-preset nil
  3099. "A preset of the category filter used for secondary agenda filtering.
  3100. This must be a list of strings, each string must be a single category
  3101. preceded by \"+\" or \"-\".
  3102. This variable should not be set directly, but agenda custom commands can
  3103. bind it in the options section. The preset filter is a global property of
  3104. the entire agenda view. In a block agenda, it will not work reliably to
  3105. define a filter for one of the individual blocks. You need to set it in
  3106. the global options and expect it to be applied to the entire view.")
  3107. (defun org-agenda-use-sticky-p ()
  3108. "Return non-nil if an agenda buffer named
  3109. `org-agenda-buffer-name' exists and should be shown instead of
  3110. generating a new one."
  3111. (and
  3112. ;; turned off by user
  3113. org-agenda-sticky
  3114. ;; For multi-agenda buffer already exists
  3115. (not org-agenda-multi)
  3116. ;; buffer found
  3117. (get-buffer org-agenda-buffer-name)
  3118. ;; C-u parameter is same as last call
  3119. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3120. (and
  3121. (equal current-prefix-arg
  3122. org-agenda-last-prefix-arg)
  3123. ;; In case user turned stickiness on, while having existing
  3124. ;; Agenda buffer active, don't reuse that buffer, because it
  3125. ;; does not have org variables local
  3126. org-agenda-this-buffer-is-sticky))))
  3127. (defun org-agenda-prepare-window (abuf)
  3128. "Setup agenda buffer in the window."
  3129. (let* ((awin (get-buffer-window abuf))
  3130. wconf)
  3131. (cond
  3132. ((equal (current-buffer) abuf) nil)
  3133. (awin (select-window awin))
  3134. ((not (setq wconf (current-window-configuration))))
  3135. ((equal org-agenda-window-setup 'current-window)
  3136. (org-pop-to-buffer-same-window abuf))
  3137. ((equal org-agenda-window-setup 'other-window)
  3138. (org-switch-to-buffer-other-window abuf))
  3139. ((equal org-agenda-window-setup 'other-frame)
  3140. (switch-to-buffer-other-frame abuf))
  3141. ((equal org-agenda-window-setup 'reorganize-frame)
  3142. (delete-other-windows)
  3143. (org-switch-to-buffer-other-window abuf)))
  3144. ;; additional test in case agenda is invoked from within agenda
  3145. ;; buffer via elisp link
  3146. (unless (equal (current-buffer) abuf)
  3147. (org-pop-to-buffer-same-window abuf))
  3148. (setq org-agenda-pre-window-conf
  3149. (or org-agenda-pre-window-conf wconf))))
  3150. (defun org-agenda-prepare (&optional name)
  3151. (if (org-agenda-use-sticky-p)
  3152. (progn
  3153. ;; Popup existing buffer
  3154. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3155. (message "Sticky Agenda buffer, use `r' to refresh")
  3156. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3157. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3158. (setq org-todo-keywords-for-agenda nil)
  3159. (setq org-drawers-for-agenda nil)
  3160. (unless org-agenda-persistent-filter
  3161. (setq org-agenda-tag-filter nil
  3162. org-agenda-category-filter nil))
  3163. (put 'org-agenda-tag-filter :preset-filter
  3164. org-agenda-tag-filter-preset)
  3165. (put 'org-agenda-category-filter :preset-filter
  3166. org-agenda-category-filter-preset)
  3167. (if org-agenda-multi
  3168. (progn
  3169. (setq buffer-read-only nil)
  3170. (goto-char (point-max))
  3171. (unless (or (bobp) org-agenda-compact-blocks
  3172. (not org-agenda-block-separator))
  3173. (insert "\n"
  3174. (if (stringp org-agenda-block-separator)
  3175. org-agenda-block-separator
  3176. (make-string (window-width) org-agenda-block-separator))
  3177. "\n"))
  3178. (narrow-to-region (point) (point-max)))
  3179. (setq org-done-keywords-for-agenda nil)
  3180. ;; Setting any org variables that are in org-agenda-local-vars
  3181. ;; list need to be done after the prepare call
  3182. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3183. (setq buffer-read-only nil)
  3184. (org-agenda-reset-markers)
  3185. (let ((inhibit-read-only t)) (erase-buffer))
  3186. (org-agenda-mode)
  3187. (setq org-agenda-buffer (current-buffer))
  3188. (setq org-agenda-contributing-files nil)
  3189. (setq org-agenda-columns-active nil)
  3190. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3191. (setq org-todo-keywords-for-agenda
  3192. (org-uniquify org-todo-keywords-for-agenda))
  3193. (setq org-done-keywords-for-agenda
  3194. (org-uniquify org-done-keywords-for-agenda))
  3195. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3196. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3197. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3198. (and name (not org-agenda-name)
  3199. (org-set-local 'org-agenda-name name)))
  3200. (setq buffer-read-only nil)))
  3201. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3202. (defun org-agenda-finalize ()
  3203. "Finishing touch for the agenda buffer, called just before displaying it."
  3204. (unless org-agenda-multi
  3205. (save-excursion
  3206. (let ((inhibit-read-only t))
  3207. (goto-char (point-min))
  3208. (save-excursion
  3209. (while (org-activate-bracket-links (point-max))
  3210. (add-text-properties (match-beginning 0) (match-end 0)
  3211. '(face org-link))))
  3212. (save-excursion
  3213. (while (org-activate-plain-links (point-max))
  3214. (add-text-properties (match-beginning 0) (match-end 0)
  3215. '(face org-link))))
  3216. (when (cadr (assoc 'org-prefix-has-tag
  3217. (car org-prefix-format-compiled)))
  3218. (org-agenda-align-tags))
  3219. (unless org-agenda-with-colors
  3220. (remove-text-properties (point-min) (point-max) '(face nil))))
  3221. (if (and (boundp 'org-agenda-overriding-columns-format)
  3222. org-agenda-overriding-columns-format)
  3223. (org-set-local 'org-agenda-overriding-columns-format
  3224. org-agenda-overriding-columns-format))
  3225. (if (and (boundp 'org-agenda-view-columns-initially)
  3226. org-agenda-view-columns-initially)
  3227. (org-agenda-columns))
  3228. (when org-agenda-fontify-priorities
  3229. (org-agenda-fontify-priorities))
  3230. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3231. (org-agenda-dim-blocked-tasks))
  3232. ;; We need to widen when `org-agenda-finalize' is called from
  3233. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3234. (when org-clock-current-task
  3235. (save-restriction
  3236. (widen)
  3237. (org-agenda-mark-clocking-task)))
  3238. (when org-agenda-entry-text-mode
  3239. (org-agenda-entry-text-hide)
  3240. (org-agenda-entry-text-show))
  3241. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3242. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3243. (org-habit-insert-consistency-graphs))
  3244. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3245. (when (delq nil (mapcar (lambda (tp) (org-agenda-check-type nil tp))
  3246. org-agenda-use-tag-inheritance))
  3247. (let (mrk)
  3248. (save-excursion
  3249. (goto-char (point-min))
  3250. (while (equal (forward-line) 0)
  3251. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3252. (get-text-property (point) 'org-hd-marker)))
  3253. (put-text-property (point-at-bol) (point-at-eol)
  3254. 'tags (org-with-point-at mrk
  3255. (delete-dups
  3256. (mapcar 'downcase (org-get-tags-at))))))))))
  3257. (let ((inhibit-read-only t))
  3258. (run-hooks 'org-agenda-finalize-hook))
  3259. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3260. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3261. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3262. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3263. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
  3264. (defun org-agenda-mark-clocking-task ()
  3265. "Mark the current clock entry in the agenda if it is present."
  3266. (mapc (lambda (o)
  3267. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3268. (delete-overlay o)))
  3269. (overlays-in (point-min) (point-max)))
  3270. (when (marker-buffer org-clock-hd-marker)
  3271. (save-excursion
  3272. (goto-char (point-min))
  3273. (let (s ov)
  3274. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3275. (goto-char s)
  3276. (when (equal (org-get-at-bol 'org-hd-marker)
  3277. org-clock-hd-marker)
  3278. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3279. (overlay-put ov 'type 'org-agenda-clocking)
  3280. (overlay-put ov 'face 'org-agenda-clocking)
  3281. (overlay-put ov 'help-echo
  3282. "The clock is running in this item")))))))
  3283. (defun org-agenda-fontify-priorities ()
  3284. "Make highest priority lines bold, and lowest italic."
  3285. (interactive)
  3286. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3287. (delete-overlay o)))
  3288. (overlays-in (point-min) (point-max)))
  3289. (save-excursion
  3290. (let ((inhibit-read-only t)
  3291. b e p ov h l)
  3292. (goto-char (point-min))
  3293. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3294. (setq h (or (get-char-property (point) 'org-highest-priority)
  3295. org-highest-priority)
  3296. l (or (get-char-property (point) 'org-lowest-priority)
  3297. org-lowest-priority)
  3298. p (string-to-char (match-string 1))
  3299. b (match-beginning 0)
  3300. e (if (eq org-agenda-fontify-priorities 'cookies)
  3301. (match-end 0)
  3302. (point-at-eol))
  3303. ov (make-overlay b e))
  3304. (overlay-put
  3305. ov 'face
  3306. (cond ((org-face-from-face-or-color
  3307. 'priority nil
  3308. (cdr (assoc p org-priority-faces))))
  3309. ((and (listp org-agenda-fontify-priorities)
  3310. (org-face-from-face-or-color
  3311. 'priority nil
  3312. (cdr (assoc p org-agenda-fontify-priorities)))))
  3313. ((equal p l) 'italic)
  3314. ((equal p h) 'bold)))
  3315. (overlay-put ov 'org-type 'org-priority)))))
  3316. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3317. (interactive "P")
  3318. "Dim currently blocked TODO's in the agenda display."
  3319. (message "Dim or hide blocked tasks...")
  3320. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3321. (delete-overlay o)))
  3322. (overlays-in (point-min) (point-max)))
  3323. (save-excursion
  3324. (let ((inhibit-read-only t)
  3325. (org-depend-tag-blocked nil)
  3326. (invis (or (not (null invisible))
  3327. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3328. org-blocked-by-checkboxes
  3329. invis1 b e p ov h l)
  3330. (goto-char (point-min))
  3331. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3332. (and pos (goto-char (1+ pos))))
  3333. (setq org-blocked-by-checkboxes nil invis1 invis)
  3334. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3335. (when (and marker
  3336. (with-current-buffer (marker-buffer marker)
  3337. (save-excursion (goto-char marker)
  3338. (org-entry-blocked-p))))
  3339. (if org-blocked-by-checkboxes (setq invis1 nil))
  3340. (setq b (if invis1
  3341. (max (point-min) (1- (point-at-bol)))
  3342. (point-at-bol))
  3343. e (point-at-eol)
  3344. ov (make-overlay b e))
  3345. (if invis1
  3346. (overlay-put ov 'invisible t)
  3347. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3348. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3349. (message "Dim or hide blocked tasks...done"))
  3350. (defvar org-agenda-skip-function nil
  3351. "Function to be called at each match during agenda construction.
  3352. If this function returns nil, the current match should not be skipped.
  3353. Otherwise, the function must return a position from where the search
  3354. should be continued.
  3355. This may also be a Lisp form, it will be evaluated.
  3356. Never set this variable using `setq' or so, because then it will apply
  3357. to all future agenda commands. If you do want a global skipping condition,
  3358. use the option `org-agenda-skip-function-global' instead.
  3359. The correct usage for `org-agenda-skip-function' is to bind it with
  3360. `let' to scope it dynamically into the agenda-constructing command.
  3361. A good way to set it is through options in `org-agenda-custom-commands'.")
  3362. (defun org-agenda-skip ()
  3363. "Throw to `:skip' in places that should be skipped.
  3364. Also moves point to the end of the skipped region, so that search can
  3365. continue from there."
  3366. (let ((p (point-at-bol)) to)
  3367. (when (org-in-src-block-p t) (throw :skip t))
  3368. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3369. (get-text-property p :org-archived)
  3370. (org-end-of-subtree t)
  3371. (throw :skip t))
  3372. (and org-agenda-skip-comment-trees
  3373. (get-text-property p :org-comment)
  3374. (org-end-of-subtree t)
  3375. (throw :skip t))
  3376. (if (equal (char-after p) ?#) (throw :skip t))
  3377. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3378. (org-agenda-skip-eval org-agenda-skip-function)))
  3379. (goto-char to)
  3380. (throw :skip t))))
  3381. (defun org-agenda-skip-eval (form)
  3382. "If FORM is a function or a list, call (or eval) is and return result.
  3383. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3384. and match data are returned to the previous state no matter what these
  3385. functions do."
  3386. (let (fp)
  3387. (and form
  3388. (or (setq fp (functionp form))
  3389. (consp form))
  3390. (save-excursion
  3391. (save-match-data
  3392. (if fp
  3393. (funcall form)
  3394. (eval form)))))))
  3395. (defvar org-agenda-markers nil
  3396. "List of all currently active markers created by `org-agenda'.")
  3397. (defvar org-agenda-last-marker-time (org-float-time)
  3398. "Creation time of the last agenda marker.")
  3399. (defun org-agenda-new-marker (&optional pos)
  3400. "Return a new agenda marker.
  3401. Org-mode keeps a list of these markers and resets them when they are
  3402. no longer in use."
  3403. (let ((m (copy-marker (or pos (point)))))
  3404. (setq org-agenda-last-marker-time (org-float-time))
  3405. (if org-agenda-buffer
  3406. (with-current-buffer org-agenda-buffer
  3407. (push m org-agenda-markers))
  3408. (push m org-agenda-markers))
  3409. m))
  3410. (defun org-agenda-reset-markers ()
  3411. "Reset markers created by `org-agenda'."
  3412. (while org-agenda-markers
  3413. (move-marker (pop org-agenda-markers) nil)))
  3414. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3415. "Save relative positions of markers in region.
  3416. This check for agenda markers in all agenda buffers currently active."
  3417. (dolist (buf (buffer-list))
  3418. (with-current-buffer buf
  3419. (when (eq major-mode 'org-agenda-mode)
  3420. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3421. org-agenda-markers)))))
  3422. ;;; Entry text mode
  3423. (defun org-agenda-entry-text-show-here ()
  3424. "Add some text from the entry as context to the current line."
  3425. (let (m txt o)
  3426. (setq m (org-get-at-bol 'org-hd-marker))
  3427. (unless (marker-buffer m)
  3428. (error "No marker points to an entry here"))
  3429. (setq txt (concat "\n" (org-no-properties
  3430. (org-agenda-get-some-entry-text
  3431. m org-agenda-entry-text-maxlines " > "))))
  3432. (when (string-match "\\S-" txt)
  3433. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3434. (overlay-put o 'evaporate t)
  3435. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3436. (overlay-put o 'after-string txt))))
  3437. (defun org-agenda-entry-text-show ()
  3438. "Add entry context for all agenda lines."
  3439. (interactive)
  3440. (save-excursion
  3441. (goto-char (point-max))
  3442. (beginning-of-line 1)
  3443. (while (not (bobp))
  3444. (when (org-get-at-bol 'org-hd-marker)
  3445. (org-agenda-entry-text-show-here))
  3446. (beginning-of-line 0))))
  3447. (defun org-agenda-entry-text-hide ()
  3448. "Remove any shown entry context."
  3449. (delq nil
  3450. (mapcar (lambda (o)
  3451. (if (eq (overlay-get o 'org-overlay-type)
  3452. 'agenda-entry-content)
  3453. (progn (delete-overlay o) t)))
  3454. (overlays-in (point-min) (point-max)))))
  3455. (defun org-agenda-get-day-face (date)
  3456. "Return the face DATE should be displayed with."
  3457. (or (and (functionp org-agenda-day-face-function)
  3458. (funcall org-agenda-day-face-function date))
  3459. (cond ((org-agenda-todayp date)
  3460. 'org-agenda-date-today)
  3461. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3462. 'org-agenda-date-weekend)
  3463. (t 'org-agenda-date))))
  3464. ;;; Agenda timeline
  3465. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3466. (defun org-timeline (&optional dotodo)
  3467. "Show a time-sorted view of the entries in the current org file.
  3468. Only entries with a time stamp of today or later will be listed. With
  3469. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3470. under the current date.
  3471. If the buffer contains an active region, only check the region for
  3472. dates."
  3473. (interactive "P")
  3474. (let* ((dopast t)
  3475. (org-agenda-show-log-scoped org-agenda-show-log)
  3476. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3477. (current-buffer))))
  3478. (date (calendar-current-date))
  3479. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3480. (end (if (org-region-active-p) (region-end) (point-max)))
  3481. (day-numbers (org-get-all-dates
  3482. beg end 'no-ranges
  3483. t org-agenda-show-log-scoped ; always include today
  3484. org-timeline-show-empty-dates))
  3485. (org-deadline-warning-days 0)
  3486. (org-agenda-only-exact-dates t)
  3487. (today (org-today))
  3488. (past t)
  3489. args
  3490. s e rtn d emptyp)
  3491. (setq org-agenda-redo-command
  3492. (list 'progn
  3493. (list 'org-switch-to-buffer-other-window (current-buffer))
  3494. (list 'org-timeline (list 'quote dotodo))))
  3495. (if (not dopast)
  3496. ;; Remove past dates from the list of dates.
  3497. (setq day-numbers (delq nil (mapcar (lambda(x)
  3498. (if (>= x today) x nil))
  3499. day-numbers))))
  3500. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3501. (org-compile-prefix-format 'timeline)
  3502. (org-set-sorting-strategy 'timeline)
  3503. (if org-agenda-show-log-scoped (push :closed args))
  3504. (push :timestamp args)
  3505. (push :deadline args)
  3506. (push :scheduled args)
  3507. (push :sexp args)
  3508. (if dotodo (push :todo args))
  3509. (insert "Timeline of file " entry "\n")
  3510. (add-text-properties (point-min) (point)
  3511. (list 'face 'org-agenda-structure))
  3512. (org-agenda-mark-header-line (point-min))
  3513. (while (setq d (pop day-numbers))
  3514. (if (and (listp d) (eq (car d) :omitted))
  3515. (progn
  3516. (setq s (point))
  3517. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3518. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3519. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3520. (if (and (>= d today)
  3521. dopast
  3522. past)
  3523. (progn
  3524. (setq past nil)
  3525. (insert (make-string 79 ?-) "\n")))
  3526. (setq date (calendar-gregorian-from-absolute d))
  3527. (setq s (point))
  3528. (setq rtn (and (not emptyp)
  3529. (apply 'org-agenda-get-day-entries entry
  3530. date args)))
  3531. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3532. (progn
  3533. (insert
  3534. (if (stringp org-agenda-format-date)
  3535. (format-time-string org-agenda-format-date
  3536. (org-time-from-absolute date))
  3537. (funcall org-agenda-format-date date))
  3538. "\n")
  3539. (put-text-property s (1- (point)) 'face
  3540. (org-agenda-get-day-face date))
  3541. (put-text-property s (1- (point)) 'org-date-line t)
  3542. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3543. (if (equal d today)
  3544. (put-text-property s (1- (point)) 'org-today t))
  3545. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3546. (put-text-property s (1- (point)) 'day d)))))
  3547. (goto-char (point-min))
  3548. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3549. (point-min)))
  3550. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3551. (org-agenda-finalize)
  3552. (setq buffer-read-only t)))
  3553. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3554. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3555. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3556. not every single day in the range. If FORCE-TODAY is non-nil, make
  3557. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3558. inactive time stamps (those in square brackets) are included.
  3559. When EMPTY is non-nil, also include days without any entries."
  3560. (let ((re (concat
  3561. (if pre-re pre-re "")
  3562. (if inactive org-ts-regexp-both org-ts-regexp)))
  3563. dates dates1 date day day1 day2 ts1 ts2 pos)
  3564. (if force-today
  3565. (setq dates (list (org-today))))
  3566. (save-excursion
  3567. (goto-char beg)
  3568. (while (re-search-forward re end t)
  3569. (setq day (time-to-days (org-time-string-to-time
  3570. (substring (match-string 1) 0 10)
  3571. (current-buffer) (match-beginning 0))))
  3572. (or (memq day dates) (push day dates)))
  3573. (unless no-ranges
  3574. (goto-char beg)
  3575. (while (re-search-forward org-tr-regexp end t)
  3576. (setq pos (match-beginning 0))
  3577. (setq ts1 (substring (match-string 1) 0 10)
  3578. ts2 (substring (match-string 2) 0 10)
  3579. day1 (time-to-days (org-time-string-to-time
  3580. ts1 (current-buffer) pos))
  3581. day2 (time-to-days (org-time-string-to-time
  3582. ts2 (current-buffer) pos)))
  3583. (while (< (setq day1 (1+ day1)) day2)
  3584. (or (memq day1 dates) (push day1 dates)))))
  3585. (setq dates (sort dates '<))
  3586. (when empty
  3587. (while (setq day (pop dates))
  3588. (setq day2 (car dates))
  3589. (push day dates1)
  3590. (when (and day2 empty)
  3591. (if (or (eq empty t)
  3592. (and (numberp empty) (<= (- day2 day) empty)))
  3593. (while (< (setq day (1+ day)) day2)
  3594. (push (list day) dates1))
  3595. (push (cons :omitted (- day2 day)) dates1))))
  3596. (setq dates (nreverse dates1)))
  3597. dates)))
  3598. ;;; Agenda Daily/Weekly
  3599. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3600. "Start day for the agenda view.
  3601. Custom commands can set this variable in the options section.")
  3602. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3603. (defvar org-arg-loc nil) ; local variable
  3604. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3605. "List of types searched for when creating the daily/weekly agenda.
  3606. This variable is a list of symbols that controls the types of
  3607. items that appear in the daily/weekly agenda. Allowed symbols in this
  3608. list are are
  3609. :timestamp List items containing a date stamp or date range matching
  3610. the selected date. This includes sexp entries in
  3611. angular brackets.
  3612. :sexp List entries resulting from plain diary-like sexps.
  3613. :deadline List deadline due on that date. When the date is today,
  3614. also list any deadlines past due, or due within
  3615. `org-deadline-warning-days'. `:deadline' must appear before
  3616. `:scheduled' if the setting of
  3617. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3618. any effect.
  3619. :scheduled List all items which are scheduled for the given date.
  3620. The diary for *today* also contains items which were
  3621. scheduled earlier and are not yet marked DONE.
  3622. By default, all four types are turned on.
  3623. Never set this variable globally using `setq', because then it
  3624. will apply to all future agenda commands. Instead, bind it with
  3625. `let' to scope it dynamically into the agenda-constructing
  3626. command. A good way to set it is through options in
  3627. `org-agenda-custom-commands'. For a more flexible (though
  3628. somewhat less efficient) way of determining what is included in
  3629. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3630. (defvar org-agenda-buffer-tmp-name nil)
  3631. ;;;###autoload
  3632. (defun org-agenda-list (&optional arg start-day span)
  3633. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3634. The view will be for the current day or week, but from the overview buffer
  3635. you will be able to go to other days/weeks.
  3636. With a numeric prefix argument in an interactive call, the agenda will
  3637. span ARG days. Lisp programs should instead specify SPAN to change
  3638. the number of days. SPAN defaults to `org-agenda-span'.
  3639. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3640. given in `org-agenda-start-on-weekday'."
  3641. (interactive "P")
  3642. (if org-agenda-overriding-arguments
  3643. (setq arg (car org-agenda-overriding-arguments)
  3644. start-day (nth 1 org-agenda-overriding-arguments)
  3645. span (nth 2 org-agenda-overriding-arguments)))
  3646. (if (and (integerp arg) (> arg 0))
  3647. (setq span arg arg nil))
  3648. (catch 'exit
  3649. (setq org-agenda-buffer-name
  3650. (or org-agenda-buffer-tmp-name
  3651. (if org-agenda-sticky
  3652. (cond ((and org-keys (stringp org-match))
  3653. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3654. (org-keys
  3655. (format "*Org Agenda(%s)*" org-keys))
  3656. (t "*Org Agenda(a)*")))
  3657. org-agenda-buffer-name))
  3658. (org-agenda-prepare "Day/Week")
  3659. (setq start-day (or start-day org-agenda-start-day))
  3660. (if (stringp start-day)
  3661. ;; Convert to an absolute day number
  3662. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3663. (org-compile-prefix-format 'agenda)
  3664. (org-set-sorting-strategy 'agenda)
  3665. (let* ((span (org-agenda-ndays-to-span
  3666. (or span org-agenda-ndays org-agenda-span)))
  3667. (today (org-today))
  3668. (sd (or start-day today))
  3669. (ndays (org-agenda-span-to-ndays span sd))
  3670. (org-agenda-start-on-weekday
  3671. (if (eq ndays 7)
  3672. org-agenda-start-on-weekday))
  3673. (thefiles (org-agenda-files nil 'ifmode))
  3674. (files thefiles)
  3675. (start (if (or (null org-agenda-start-on-weekday)
  3676. (< ndays 7))
  3677. sd
  3678. (let* ((nt (calendar-day-of-week
  3679. (calendar-gregorian-from-absolute sd)))
  3680. (n1 org-agenda-start-on-weekday)
  3681. (d (- nt n1)))
  3682. (- sd (+ (if (< d 0) 7 0) d)))))
  3683. (day-numbers (list start))
  3684. (day-cnt 0)
  3685. (inhibit-redisplay (not debug-on-error))
  3686. (org-agenda-show-log-scoped org-agenda-show-log)
  3687. s e rtn rtnall file date d start-pos end-pos todayp
  3688. clocktable-start clocktable-end filter)
  3689. (setq org-agenda-redo-command
  3690. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3691. (dotimes (n (1- ndays))
  3692. (push (1+ (car day-numbers)) day-numbers))
  3693. (setq day-numbers (nreverse day-numbers))
  3694. (setq clocktable-start (car day-numbers)
  3695. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3696. (org-set-local 'org-starting-day (car day-numbers))
  3697. (org-set-local 'org-arg-loc arg)
  3698. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3699. (unless org-agenda-compact-blocks
  3700. (let* ((d1 (car day-numbers))
  3701. (d2 (org-last day-numbers))
  3702. (w1 (org-days-to-iso-week d1))
  3703. (w2 (org-days-to-iso-week d2)))
  3704. (setq s (point))
  3705. (if org-agenda-overriding-header
  3706. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3707. nil 'face 'org-agenda-structure) "\n")
  3708. (insert (org-agenda-span-name span)
  3709. "-agenda"
  3710. (if (< (- d2 d1) 350)
  3711. (if (= w1 w2)
  3712. (format " (W%02d)" w1)
  3713. (format " (W%02d-W%02d)" w1 w2))
  3714. "")
  3715. ":\n")))
  3716. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3717. 'org-date-line t))
  3718. (org-agenda-mark-header-line s))
  3719. (while (setq d (pop day-numbers))
  3720. (setq date (calendar-gregorian-from-absolute d)
  3721. s (point))
  3722. (if (or (setq todayp (= d today))
  3723. (and (not start-pos) (= d sd)))
  3724. (setq start-pos (point))
  3725. (if (and start-pos (not end-pos))
  3726. (setq end-pos (point))))
  3727. (setq files thefiles
  3728. rtnall nil)
  3729. (while (setq file (pop files))
  3730. (catch 'nextfile
  3731. (org-check-agenda-file file)
  3732. (let ((org-agenda-entry-types org-agenda-entry-types))
  3733. (unless org-agenda-include-deadlines
  3734. (setq org-agenda-entry-types
  3735. (delq :deadline org-agenda-entry-types)))
  3736. (cond
  3737. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3738. (setq rtn (org-agenda-get-day-entries
  3739. file date :closed)))
  3740. (org-agenda-show-log-scoped
  3741. (setq rtn (apply 'org-agenda-get-day-entries
  3742. file date
  3743. (append '(:closed) org-agenda-entry-types))))
  3744. (t
  3745. (setq rtn (apply 'org-agenda-get-day-entries
  3746. file date
  3747. org-agenda-entry-types)))))
  3748. (setq rtnall (append rtnall rtn)))) ;; all entries
  3749. (if org-agenda-include-diary
  3750. (let ((org-agenda-search-headline-for-time t))
  3751. (require 'diary-lib)
  3752. (setq rtn (org-get-entries-from-diary date))
  3753. (setq rtnall (append rtnall rtn))))
  3754. (if (or rtnall org-agenda-show-all-dates)
  3755. (progn
  3756. (setq day-cnt (1+ day-cnt))
  3757. (insert
  3758. (if (stringp org-agenda-format-date)
  3759. (format-time-string org-agenda-format-date
  3760. (org-time-from-absolute date))
  3761. (funcall org-agenda-format-date date))
  3762. "\n")
  3763. (put-text-property s (1- (point)) 'face
  3764. (org-agenda-get-day-face date))
  3765. (put-text-property s (1- (point)) 'org-date-line t)
  3766. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3767. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3768. (when todayp
  3769. (put-text-property s (1- (point)) 'org-today t))
  3770. (setq rtnall
  3771. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3772. (if rtnall (insert ;; all entries
  3773. (org-agenda-finalize-entries rtnall)
  3774. "\n"))
  3775. (put-text-property s (1- (point)) 'day d)
  3776. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3777. (when (and org-agenda-clockreport-mode clocktable-start)
  3778. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3779. ;; the above line is to ensure the restricted range!
  3780. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3781. tbl)
  3782. (setq p (org-plist-delete p :block))
  3783. (setq p (plist-put p :tstart clocktable-start))
  3784. (setq p (plist-put p :tend clocktable-end))
  3785. (setq p (plist-put p :scope 'agenda))
  3786. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3787. (setq filter (or org-agenda-tag-filter-while-redo
  3788. (get 'org-agenda-tag-filter :preset-filter))))
  3789. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3790. (if (string-match "[<>=]" x)
  3791. ""
  3792. x))
  3793. filter ""))))
  3794. (setq tbl (apply 'org-clock-get-clocktable p))
  3795. (insert tbl)))
  3796. (goto-char (point-min))
  3797. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3798. (unless (and (pos-visible-in-window-p (point-min))
  3799. (pos-visible-in-window-p (point-max)))
  3800. (goto-char (1- (point-max)))
  3801. (recenter -1)
  3802. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3803. (progn
  3804. (goto-char (or start-pos 1))
  3805. (recenter 1))))
  3806. (goto-char (or start-pos 1))
  3807. (add-text-properties (point-min) (point-max)
  3808. `(org-agenda-type agenda
  3809. org-last-args (,arg ,start-day ,span)
  3810. org-redo-cmd ,org-agenda-redo-command
  3811. org-series-cmd ,org-cmd))
  3812. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3813. (org-agenda-show-clocking-issues))
  3814. (org-agenda-finalize)
  3815. (setq buffer-read-only t)
  3816. (message ""))))
  3817. (autoload 'org-agenda-list "org-agenda" "\
  3818. Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3819. The view will be for the current day or week, but from the overview buffer
  3820. you will be able to go to other days/weeks.
  3821. With a numeric prefix argument in an interactive call, the agenda will
  3822. span ARG days. Lisp programs should instead specify SPAN to change
  3823. the number of days. SPAN defaults to `org-agenda-span'.
  3824. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3825. given in `org-agenda-start-on-weekday'.
  3826. \(fn &optional ARG START-DAY SPAN)" t nil)
  3827. (defun org-agenda-ndays-to-span (n)
  3828. "Return a span symbol for a span of N days, or N if none matches."
  3829. (cond ((symbolp n) n)
  3830. ((= n 1) 'day)
  3831. ((= n 7) 'week)
  3832. (t n)))
  3833. (defun org-agenda-span-to-ndays (span &optional start-day)
  3834. "Return ndays from SPAN, possibly starting at START-DAY."
  3835. (cond ((numberp span) span)
  3836. ((eq span 'day) 1)
  3837. ((eq span 'week) 7)
  3838. ((eq span 'month)
  3839. (let ((date (calendar-gregorian-from-absolute start-day)))
  3840. (calendar-last-day-of-month (car date) (caddr date))))
  3841. ((eq span 'year)
  3842. (let ((date (calendar-gregorian-from-absolute start-day)))
  3843. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3844. (defun org-agenda-span-name (span)
  3845. "Return a SPAN name."
  3846. (if (null span)
  3847. ""
  3848. (if (symbolp span)
  3849. (capitalize (symbol-name span))
  3850. (format "%d days" span))))
  3851. ;;; Agenda word search
  3852. (defvar org-agenda-search-history nil)
  3853. (defvar org-search-syntax-table nil
  3854. "Special syntax table for org-mode search.
  3855. In this table, we have single quotes not as word constituents, to
  3856. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3857. (defvar org-mode-syntax-table) ; From org.el
  3858. (defun org-search-syntax-table ()
  3859. (unless org-search-syntax-table
  3860. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3861. (modify-syntax-entry ?' "." org-search-syntax-table)
  3862. (modify-syntax-entry ?` "." org-search-syntax-table))
  3863. org-search-syntax-table)
  3864. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3865. ;;;###autoload
  3866. (defun org-search-view (&optional todo-only string edit-at)
  3867. "Show all entries that contain a phrase or words or regular expressions.
  3868. With optional prefix argument TODO-ONLY, only consider entries that are
  3869. TODO entries. The argument STRING can be used to pass a default search
  3870. string into this function. If EDIT-AT is non-nil, it means that the
  3871. user should get a chance to edit this string, with cursor at position
  3872. EDIT-AT.
  3873. The search string can be viewed either as a phrase that should be found as
  3874. is, or it can be broken into a number of snippets, each of which must match
  3875. in a Boolean way to select an entry. The default depends on the variable
  3876. `org-agenda-search-view-always-boolean'.
  3877. Even if this is turned off (the default) you can always switch to
  3878. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3879. The default is a direct search of the whole phrase, where each space in
  3880. the search string can expand to an arbitrary amount of whitespace,
  3881. including newlines.
  3882. If using a Boolean search, the search string is split on whitespace and
  3883. each snippet is searched separately, with logical AND to select an entry.
  3884. Words prefixed with a minus must *not* occur in the entry. Words without
  3885. a prefix or prefixed with a plus must occur in the entry. Matching is
  3886. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3887. match whole words, not parts of a word) if
  3888. `org-agenda-search-view-force-full-words' is set (default is nil).
  3889. Boolean search snippets enclosed by curly braces are interpreted as
  3890. regular expressions that must or (when preceded with \"-\") must not
  3891. match in the entry. Snippets enclosed into double quotes will be taken
  3892. as a whole, to include whitespace.
  3893. - If the search string starts with an asterisk, search only in headlines.
  3894. - If (possibly after the leading star) the search string starts with an
  3895. exclamation mark, this also means to look at TODO entries only, an effect
  3896. that can also be achieved with a prefix argument.
  3897. - If (possibly after star and exclamation mark) the search string starts
  3898. with a colon, this will mean that the (non-regexp) snippets of the
  3899. Boolean search must match as full words.
  3900. This command searches the agenda files, and in addition the files listed
  3901. in `org-agenda-text-search-extra-files'."
  3902. (interactive "P")
  3903. (if org-agenda-overriding-arguments
  3904. (setq todo-only (car org-agenda-overriding-arguments)
  3905. string (nth 1 org-agenda-overriding-arguments)
  3906. edit-at (nth 2 org-agenda-overriding-arguments)))
  3907. (let* ((props (list 'face nil
  3908. 'done-face 'org-agenda-done
  3909. 'org-not-done-regexp org-not-done-regexp
  3910. 'org-todo-regexp org-todo-regexp
  3911. 'org-complex-heading-regexp org-complex-heading-regexp
  3912. 'mouse-face 'highlight
  3913. 'help-echo (format "mouse-2 or RET jump to location")))
  3914. (full-words org-agenda-search-view-force-full-words)
  3915. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3916. regexp rtn rtnall files file pos
  3917. marker category category-pos tags c neg re boolean
  3918. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3919. (unless (and (not edit-at)
  3920. (stringp string)
  3921. (string-match "\\S-" string))
  3922. (setq string (read-string
  3923. (if org-agenda-search-view-always-boolean
  3924. "[+-]Word/{Regexp} ...: "
  3925. "Phrase or [+-]Word/{Regexp} ...: ")
  3926. (cond
  3927. ((integerp edit-at) (cons string edit-at))
  3928. (edit-at string))
  3929. 'org-agenda-search-history)))
  3930. (catch 'exit
  3931. (if org-agenda-sticky
  3932. (setq org-agenda-buffer-name
  3933. (if (stringp string)
  3934. (format "*Org Agenda(%s:%s)*"
  3935. (or org-keys (or (and todo-only "S") "s")) string)
  3936. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3937. (org-agenda-prepare "SEARCH")
  3938. (org-compile-prefix-format 'search)
  3939. (org-set-sorting-strategy 'search)
  3940. (setq org-agenda-redo-command
  3941. (list 'org-search-view (if todo-only t nil)
  3942. (list 'if 'current-prefix-arg nil string)))
  3943. (setq org-agenda-query-string string)
  3944. (if (equal (string-to-char string) ?*)
  3945. (setq hdl-only t
  3946. words (substring string 1))
  3947. (setq words string))
  3948. (when (equal (string-to-char words) ?!)
  3949. (setq todo-only t
  3950. words (substring words 1)))
  3951. (when (equal (string-to-char words) ?:)
  3952. (setq full-words t
  3953. words (substring words 1)))
  3954. (if (or org-agenda-search-view-always-boolean
  3955. (member (string-to-char words) '(?- ?+ ?\{)))
  3956. (setq boolean t))
  3957. (setq words (org-split-string words))
  3958. (let (www w)
  3959. (while (setq w (pop words))
  3960. (while (and (string-match "\\\\\\'" w) words)
  3961. (setq w (concat (substring w 0 -1) " " (pop words))))
  3962. (push w www))
  3963. (setq words (nreverse www) www nil)
  3964. (while (setq w (pop words))
  3965. (when (and (string-match "\\`[-+]?{" w)
  3966. (not (string-match "}\\'" w)))
  3967. (while (and words (not (string-match "}\\'" (car words))))
  3968. (setq w (concat w " " (pop words))))
  3969. (setq w (concat w " " (pop words))))
  3970. (push w www))
  3971. (setq words (nreverse www)))
  3972. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3973. (when boolean
  3974. (let (wds w)
  3975. (while (setq w (pop words))
  3976. (if (or (equal (substring w 0 1) "\"")
  3977. (and (> (length w) 1)
  3978. (member (substring w 0 1) '("+" "-"))
  3979. (equal (substring w 1 2) "\"")))
  3980. (while (and words (not (equal (substring w -1) "\"")))
  3981. (setq w (concat w " " (pop words)))))
  3982. (and (string-match "\\`\\([-+]?\\)\"" w)
  3983. (setq w (replace-match "\\1" nil nil w)))
  3984. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3985. (push w wds))
  3986. (setq words (nreverse wds))))
  3987. (if boolean
  3988. (mapc (lambda (w)
  3989. (setq c (string-to-char w))
  3990. (if (equal c ?-)
  3991. (setq neg t w (substring w 1))
  3992. (if (equal c ?+)
  3993. (setq neg nil w (substring w 1))
  3994. (setq neg nil)))
  3995. (if (string-match "\\`{.*}\\'" w)
  3996. (setq re (substring w 1 -1))
  3997. (if full-words
  3998. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3999. (setq re (regexp-quote (downcase w)))))
  4000. (if neg (push re regexps-) (push re regexps+)))
  4001. words)
  4002. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4003. regexps+))
  4004. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4005. (if (not regexps+)
  4006. (setq regexp org-outline-regexp-bol)
  4007. (setq regexp (pop regexps+))
  4008. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4009. regexp))))
  4010. (setq files (org-agenda-files nil 'ifmode))
  4011. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4012. (pop org-agenda-text-search-extra-files)
  4013. (setq files (org-add-archive-files files)))
  4014. (setq files (append files org-agenda-text-search-extra-files)
  4015. rtnall nil)
  4016. (while (setq file (pop files))
  4017. (setq ee nil)
  4018. (catch 'nextfile
  4019. (org-check-agenda-file file)
  4020. (setq buffer (if (file-exists-p file)
  4021. (org-get-agenda-file-buffer file)
  4022. (error "No such file %s" file)))
  4023. (if (not buffer)
  4024. ;; If file does not exist, make sure an error message is sent
  4025. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4026. file))))
  4027. (with-current-buffer buffer
  4028. (with-syntax-table (org-search-syntax-table)
  4029. (unless (derived-mode-p 'org-mode)
  4030. (error "Agenda file %s is not in `org-mode'" file))
  4031. (let ((case-fold-search t))
  4032. (save-excursion
  4033. (save-restriction
  4034. (if org-agenda-restrict
  4035. (narrow-to-region org-agenda-restrict-begin
  4036. org-agenda-restrict-end)
  4037. (widen))
  4038. (goto-char (point-min))
  4039. (unless (or (org-at-heading-p)
  4040. (outline-next-heading))
  4041. (throw 'nextfile t))
  4042. (goto-char (max (point-min) (1- (point))))
  4043. (while (re-search-forward regexp nil t)
  4044. (org-back-to-heading t)
  4045. (skip-chars-forward "* ")
  4046. (setq beg (point-at-bol)
  4047. beg1 (point)
  4048. end (progn (outline-next-heading) (point)))
  4049. (catch :skip
  4050. (goto-char beg)
  4051. (org-agenda-skip)
  4052. (setq str (buffer-substring-no-properties
  4053. (point-at-bol)
  4054. (if hdl-only (point-at-eol) end)))
  4055. (mapc (lambda (wr) (when (string-match wr str)
  4056. (goto-char (1- end))
  4057. (throw :skip t)))
  4058. regexps-)
  4059. (mapc (lambda (wr) (unless (string-match wr str)
  4060. (goto-char (1- end))
  4061. (throw :skip t)))
  4062. (if todo-only
  4063. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4064. regexps+)
  4065. regexps+))
  4066. (goto-char beg)
  4067. (setq marker (org-agenda-new-marker (point))
  4068. category (org-get-category)
  4069. category-pos (get-text-property (point) 'org-category-position)
  4070. tags (org-get-tags-at nil t)
  4071. txt (org-agenda-format-item
  4072. ""
  4073. (buffer-substring-no-properties
  4074. beg1 (point-at-eol))
  4075. category tags t))
  4076. (org-add-props txt props
  4077. 'org-marker marker 'org-hd-marker marker
  4078. 'org-todo-regexp org-todo-regexp
  4079. 'org-complex-heading-regexp org-complex-heading-regexp
  4080. 'priority 1000 'org-category category
  4081. 'org-category-position category-pos
  4082. 'type "search")
  4083. (push txt ee)
  4084. (goto-char (1- end))))))))))
  4085. (setq rtn (nreverse ee))
  4086. (setq rtnall (append rtnall rtn)))
  4087. (if org-agenda-overriding-header
  4088. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4089. nil 'face 'org-agenda-structure) "\n")
  4090. (insert "Search words: ")
  4091. (add-text-properties (point-min) (1- (point))
  4092. (list 'face 'org-agenda-structure))
  4093. (setq pos (point))
  4094. (insert string "\n")
  4095. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4096. (setq pos (point))
  4097. (unless org-agenda-multi
  4098. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4099. (add-text-properties pos (1- (point))
  4100. (list 'face 'org-agenda-structure))))
  4101. (org-agenda-mark-header-line (point-min))
  4102. (when rtnall
  4103. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4104. (goto-char (point-min))
  4105. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4106. (add-text-properties (point-min) (point-max)
  4107. `(org-agenda-type search
  4108. org-last-args (,todo-only ,string ,edit-at)
  4109. org-redo-cmd ,org-agenda-redo-command
  4110. org-series-cmd ,org-cmd))
  4111. (org-agenda-finalize)
  4112. (setq buffer-read-only t))))
  4113. (autoload 'org-search-view "org-agenda" "\
  4114. Show all entries that contain a phrase or words or regular expressions.
  4115. With optional prefix argument TODO-ONLY, only consider entries that are
  4116. TODO entries. The argument STRING can be used to pass a default search
  4117. string into this function. If EDIT-AT is non-nil, it means that the
  4118. user should get a chance to edit this string, with cursor at position
  4119. EDIT-AT.
  4120. The search string can be viewed either as a phrase that should be found as
  4121. is, or it can be broken into a number of snippets, each of which must match
  4122. in a Boolean way to select an entry. The default depends on the variable
  4123. `org-agenda-search-view-always-boolean'.
  4124. Even if this is turned off (the default) you can always switch to
  4125. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4126. The default is a direct search of the whole phrase, where each space in
  4127. the search string can expand to an arbitrary amount of whitespace,
  4128. including newlines.
  4129. If using a Boolean search, the search string is split on whitespace and
  4130. each snippet is searched separately, with logical AND to select an entry.
  4131. Words prefixed with a minus must *not* occur in the entry. Words without
  4132. a prefix or prefixed with a plus must occur in the entry. Matching is
  4133. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4134. match whole words, not parts of a word) if
  4135. `org-agenda-search-view-force-full-words' is set (default is nil).
  4136. Boolean search snippets enclosed by curly braces are interpreted as
  4137. regular expressions that must or (when preceded with \"-\") must not
  4138. match in the entry. Snippets enclosed into double quotes will be taken
  4139. as a whole, to include whitespace.
  4140. - If the search string starts with an asterisk, search only in headlines.
  4141. - If (possibly after the leading star) the search string starts with an
  4142. exclamation mark, this also means to look at TODO entries only, an effect
  4143. that can also be achieved with a prefix argument.
  4144. - If (possibly after star and exclamation mark) the search string starts
  4145. with a colon, this will mean that the (non-regexp) snippets of the
  4146. Boolean search must match as full words.
  4147. This command searches the agenda files, and in addition the files listed
  4148. in `org-agenda-text-search-extra-files'.
  4149. \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
  4150. ;;; Agenda TODO list
  4151. (defvar org-select-this-todo-keyword nil)
  4152. (defvar org-last-arg nil)
  4153. ;;;###autoload
  4154. (defun org-todo-list (&optional arg)
  4155. "Show all (not done) TODO entries from all agenda file in a single list.
  4156. The prefix arg can be used to select a specific TODO keyword and limit
  4157. the list to these. When using \\[universal-argument], you will be prompted
  4158. for a keyword. A numeric prefix directly selects the Nth keyword in
  4159. `org-todo-keywords-1'."
  4160. (interactive "P")
  4161. (if org-agenda-overriding-arguments
  4162. (setq arg org-agenda-overriding-arguments))
  4163. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4164. (let* ((today (org-today))
  4165. (date (calendar-gregorian-from-absolute today))
  4166. (kwds org-todo-keywords-for-agenda)
  4167. (completion-ignore-case t)
  4168. (org-select-this-todo-keyword
  4169. (if (stringp arg) arg
  4170. (and arg (integerp arg) (> arg 0)
  4171. (nth (1- arg) kwds))))
  4172. rtn rtnall files file pos)
  4173. (when (equal arg '(4))
  4174. (setq org-select-this-todo-keyword
  4175. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4176. (mapcar 'list kwds) nil nil)))
  4177. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4178. (catch 'exit
  4179. (if org-agenda-sticky
  4180. (setq org-agenda-buffer-name
  4181. (if (stringp org-select-this-todo-keyword)
  4182. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4183. org-select-this-todo-keyword)
  4184. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4185. (org-agenda-prepare "TODO")
  4186. (org-compile-prefix-format 'todo)
  4187. (org-set-sorting-strategy 'todo)
  4188. (setq org-agenda-redo-command
  4189. `(org-todo-list (or (and (numberp current-prefix-arg)
  4190. current-prefix-arg)
  4191. ,org-select-this-todo-keyword
  4192. current-prefix-arg ,arg)))
  4193. (setq files (org-agenda-files nil 'ifmode)
  4194. rtnall nil)
  4195. (while (setq file (pop files))
  4196. (catch 'nextfile
  4197. (org-check-agenda-file file)
  4198. (setq rtn (org-agenda-get-day-entries file date :todo))
  4199. (setq rtnall (append rtnall rtn))))
  4200. (if org-agenda-overriding-header
  4201. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4202. nil 'face 'org-agenda-structure) "\n")
  4203. (insert "Global list of TODO items of type: ")
  4204. (add-text-properties (point-min) (1- (point))
  4205. (list 'face 'org-agenda-structure
  4206. 'short-heading
  4207. (concat "ToDo: "
  4208. (or org-select-this-todo-keyword "ALL"))))
  4209. (org-agenda-mark-header-line (point-min))
  4210. (setq pos (point))
  4211. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4212. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4213. (setq pos (point))
  4214. (unless org-agenda-multi
  4215. (insert "Available with `N r': (0)[ALL]")
  4216. (let ((n 0) s)
  4217. (mapc (lambda (x)
  4218. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4219. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4220. (insert "\n "))
  4221. (insert " " s))
  4222. kwds))
  4223. (insert "\n"))
  4224. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4225. (org-agenda-mark-header-line (point-min))
  4226. (when rtnall
  4227. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4228. (goto-char (point-min))
  4229. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4230. (add-text-properties (point-min) (point-max)
  4231. `(org-agenda-type todo
  4232. org-last-args ,arg
  4233. org-redo-cmd ,org-agenda-redo-command
  4234. org-series-cmd ,org-cmd))
  4235. (org-agenda-finalize)
  4236. (setq buffer-read-only t))))
  4237. (autoload 'org-todo-list "org-agenda" "\
  4238. Show all (not done) TODO entries from all agenda file in a single list.
  4239. The prefix arg can be used to select a specific TODO keyword and limit
  4240. the list to these. When using \\[universal-argument], you will be prompted
  4241. for a keyword. A numeric prefix directly selects the Nth keyword in
  4242. `org-todo-keywords-1'.
  4243. \(fn &optional ARG)" t nil)
  4244. ;;; Agenda tags match
  4245. ;;;###autoload
  4246. (defun org-tags-view (&optional todo-only match)
  4247. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4248. The prefix arg TODO-ONLY limits the search to TODO entries."
  4249. (interactive "P")
  4250. (if org-agenda-overriding-arguments
  4251. (setq todo-only (car org-agenda-overriding-arguments)
  4252. match (nth 1 org-agenda-overriding-arguments)))
  4253. (let* ((org-tags-match-list-sublevels
  4254. org-tags-match-list-sublevels)
  4255. (completion-ignore-case t)
  4256. rtn rtnall files file pos matcher
  4257. buffer)
  4258. (when (and (stringp match) (not (string-match "\\S-" match)))
  4259. (setq match nil))
  4260. (setq matcher (org-make-tags-matcher match)
  4261. match (car matcher) matcher (cdr matcher))
  4262. (catch 'exit
  4263. (if org-agenda-sticky
  4264. (setq org-agenda-buffer-name
  4265. (if (stringp match)
  4266. (format "*Org Agenda(%s:%s)*"
  4267. (or org-keys (or (and todo-only "M") "m")) match)
  4268. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4269. (org-agenda-prepare (concat "TAGS " match))
  4270. (org-compile-prefix-format 'tags)
  4271. (org-set-sorting-strategy 'tags)
  4272. (setq org-agenda-query-string match)
  4273. (setq org-agenda-redo-command
  4274. (list 'org-tags-view `(quote ,todo-only)
  4275. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4276. (setq files (org-agenda-files nil 'ifmode)
  4277. rtnall nil)
  4278. (while (setq file (pop files))
  4279. (catch 'nextfile
  4280. (org-check-agenda-file file)
  4281. (setq buffer (if (file-exists-p file)
  4282. (org-get-agenda-file-buffer file)
  4283. (error "No such file %s" file)))
  4284. (if (not buffer)
  4285. ;; If file does not exist, error message to agenda
  4286. (setq rtn (list
  4287. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4288. rtnall (append rtnall rtn))
  4289. (with-current-buffer buffer
  4290. (unless (derived-mode-p 'org-mode)
  4291. (error "Agenda file %s is not in `org-mode'" file))
  4292. (save-excursion
  4293. (save-restriction
  4294. (if org-agenda-restrict
  4295. (narrow-to-region org-agenda-restrict-begin
  4296. org-agenda-restrict-end)
  4297. (widen))
  4298. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4299. (setq rtnall (append rtnall rtn))))))))
  4300. (if org-agenda-overriding-header
  4301. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4302. nil 'face 'org-agenda-structure) "\n")
  4303. (insert "Headlines with TAGS match: ")
  4304. (add-text-properties (point-min) (1- (point))
  4305. (list 'face 'org-agenda-structure
  4306. 'short-heading
  4307. (concat "Match: " match)))
  4308. (setq pos (point))
  4309. (insert match "\n")
  4310. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4311. (setq pos (point))
  4312. (unless org-agenda-multi
  4313. (insert "Press `C-u r' to search again with new search string\n"))
  4314. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4315. (org-agenda-mark-header-line (point-min))
  4316. (when rtnall
  4317. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4318. (goto-char (point-min))
  4319. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4320. (add-text-properties (point-min) (point-max)
  4321. `(org-agenda-type tags
  4322. org-last-args (,todo-only ,match)
  4323. org-redo-cmd ,org-agenda-redo-command
  4324. org-series-cmd ,org-cmd))
  4325. (org-agenda-finalize)
  4326. (setq buffer-read-only t))))
  4327. (autoload 'org-tags-view "org-agenda" "\
  4328. Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4329. The prefix arg TODO-ONLY limits the search to TODO entries.
  4330. \(fn &optional TODO-ONLY MATCH)" t nil)
  4331. ;;; Agenda Finding stuck projects
  4332. (defvar org-agenda-skip-regexp nil
  4333. "Regular expression used in skipping subtrees for the agenda.
  4334. This is basically a temporary global variable that can be set and then
  4335. used by user-defined selections using `org-agenda-skip-function'.")
  4336. (defvar org-agenda-overriding-header nil
  4337. "When set during agenda, todo and tags searches it replaces the header.
  4338. This variable should not be set directly, but custom commands can bind it
  4339. in the options section.")
  4340. (defun org-agenda-skip-entry-when-regexp-matches ()
  4341. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4342. If yes, it returns the end position of this entry, causing agenda commands
  4343. to skip the entry but continuing the search in the subtree. This is a
  4344. function that can be put into `org-agenda-skip-function' for the duration
  4345. of a command."
  4346. (let ((end (save-excursion (org-end-of-subtree t)))
  4347. skip)
  4348. (save-excursion
  4349. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4350. (and skip end)))
  4351. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4352. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4353. If yes, it returns the end position of this tree, causing agenda commands
  4354. to skip this subtree. This is a function that can be put into
  4355. `org-agenda-skip-function' for the duration of a command."
  4356. (let ((end (save-excursion (org-end-of-subtree t)))
  4357. skip)
  4358. (save-excursion
  4359. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4360. (and skip end)))
  4361. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4362. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4363. If yes, it returns the end position of the current entry (NOT the tree),
  4364. causing agenda commands to skip the entry but continuing the search in
  4365. the subtree. This is a function that can be put into
  4366. `org-agenda-skip-function' for the duration of a command. An important
  4367. use of this function is for the stuck project list."
  4368. (let ((end (save-excursion (org-end-of-subtree t)))
  4369. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4370. skip)
  4371. (save-excursion
  4372. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4373. (and skip entry-end)))
  4374. (defun org-agenda-skip-entry-if (&rest conditions)
  4375. "Skip entry if any of CONDITIONS is true.
  4376. See `org-agenda-skip-if' for details."
  4377. (org-agenda-skip-if nil conditions))
  4378. (defun org-agenda-skip-subtree-if (&rest conditions)
  4379. "Skip entry if any of CONDITIONS is true.
  4380. See `org-agenda-skip-if' for details."
  4381. (org-agenda-skip-if t conditions))
  4382. (defun org-agenda-skip-if (subtree conditions)
  4383. "Checks current entity for CONDITIONS.
  4384. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4385. the entry (i.e. the text before the next heading) is checked.
  4386. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4387. from different tests. Valid conditions are:
  4388. scheduled Check if there is a scheduled cookie
  4389. notscheduled Check if there is no scheduled cookie
  4390. deadline Check if there is a deadline
  4391. notdeadline Check if there is no deadline
  4392. timestamp Check if there is a timestamp (also deadline or scheduled)
  4393. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4394. regexp Check if regexp matches
  4395. notregexp Check if regexp does not match.
  4396. todo Check if TODO keyword matches
  4397. nottodo Check if TODO keyword does not match
  4398. The regexp is taken from the conditions list, it must come right after
  4399. the `regexp' or `notregexp' element.
  4400. `todo' and `nottodo' accept as an argument a list of todo
  4401. keywords, which may include \"*\" to match any todo keyword.
  4402. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4403. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4404. Instead of a list, a keyword class may be given. For example:
  4405. (org-agenda-skip-entry-if 'nottodo 'done)
  4406. would skip entries that haven't been marked with any of \"DONE\"
  4407. keywords. Possible classes are: `todo', `done', `any'.
  4408. If any of these conditions is met, this function returns the end point of
  4409. the entity, causing the search to continue from there. This is a function
  4410. that can be put into `org-agenda-skip-function' for the duration of a command."
  4411. (let (beg end m)
  4412. (org-back-to-heading t)
  4413. (setq beg (point)
  4414. end (if subtree
  4415. (progn (org-end-of-subtree t) (point))
  4416. (progn (outline-next-heading) (1- (point)))))
  4417. (goto-char beg)
  4418. (and
  4419. (or
  4420. (and (memq 'scheduled conditions)
  4421. (re-search-forward org-scheduled-time-regexp end t))
  4422. (and (memq 'notscheduled conditions)
  4423. (not (re-search-forward org-scheduled-time-regexp end t)))
  4424. (and (memq 'deadline conditions)
  4425. (re-search-forward org-deadline-time-regexp end t))
  4426. (and (memq 'notdeadline conditions)
  4427. (not (re-search-forward org-deadline-time-regexp end t)))
  4428. (and (memq 'timestamp conditions)
  4429. (re-search-forward org-ts-regexp end t))
  4430. (and (memq 'nottimestamp conditions)
  4431. (not (re-search-forward org-ts-regexp end t)))
  4432. (and (setq m (memq 'regexp conditions))
  4433. (stringp (nth 1 m))
  4434. (re-search-forward (nth 1 m) end t))
  4435. (and (setq m (memq 'notregexp conditions))
  4436. (stringp (nth 1 m))
  4437. (not (re-search-forward (nth 1 m) end t)))
  4438. (and (or
  4439. (setq m (memq 'nottodo conditions))
  4440. (setq m (memq 'todo-unblocked conditions))
  4441. (setq m (memq 'nottodo-unblocked conditions))
  4442. (setq m (memq 'todo conditions)))
  4443. (org-agenda-skip-if-todo m end)))
  4444. end)))
  4445. (defun org-agenda-skip-if-todo (args end)
  4446. "Helper function for `org-agenda-skip-if', do not use it directly.
  4447. ARGS is a list with first element either `todo', `nottodo',
  4448. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4449. a list of TODO keywords, or a state symbol `todo' or `done' or
  4450. `any'."
  4451. (let ((kw (car args))
  4452. (arg (cadr args))
  4453. todo-wds todo-re)
  4454. (setq todo-wds
  4455. (org-uniquify
  4456. (cond
  4457. ((listp arg) ;; list of keywords
  4458. (if (member "*" arg)
  4459. (mapcar 'substring-no-properties org-todo-keywords-1)
  4460. arg))
  4461. ((symbolp arg) ;; keyword class name
  4462. (cond
  4463. ((eq arg 'todo)
  4464. (org-delete-all org-done-keywords
  4465. (mapcar 'substring-no-properties
  4466. org-todo-keywords-1)))
  4467. ((eq arg 'done) org-done-keywords)
  4468. ((eq arg 'any)
  4469. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4470. (setq todo-re
  4471. (concat "^\\*+[ \t]+\\<\\("
  4472. (mapconcat 'identity todo-wds "\\|")
  4473. "\\)\\>"))
  4474. (cond
  4475. ((eq kw 'todo) (re-search-forward todo-re end t))
  4476. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4477. ((eq kw 'todo-unblocked)
  4478. (catch 'unblocked
  4479. (while (re-search-forward todo-re end t)
  4480. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4481. nil))
  4482. ((eq kw 'nottodo-unblocked)
  4483. (catch 'unblocked
  4484. (while (re-search-forward todo-re end t)
  4485. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4486. t))
  4487. )))
  4488. ;;;###autoload
  4489. (defun org-agenda-list-stuck-projects (&rest ignore)
  4490. "Create agenda view for projects that are stuck.
  4491. Stuck projects are project that have no next actions. For the definitions
  4492. of what a project is and how to check if it stuck, customize the variable
  4493. `org-stuck-projects'."
  4494. (interactive)
  4495. (let* ((org-agenda-skip-function
  4496. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4497. ;; We could have used org-agenda-skip-if here.
  4498. (org-agenda-overriding-header
  4499. (or org-agenda-overriding-header "List of stuck projects: "))
  4500. (matcher (nth 0 org-stuck-projects))
  4501. (todo (nth 1 org-stuck-projects))
  4502. (todo-wds (if (member "*" todo)
  4503. (progn
  4504. (org-agenda-prepare-buffers (org-agenda-files
  4505. nil 'ifmode))
  4506. (org-delete-all
  4507. org-done-keywords-for-agenda
  4508. (copy-sequence org-todo-keywords-for-agenda)))
  4509. todo))
  4510. (todo-re (concat "^\\*+[ \t]+\\("
  4511. (mapconcat 'identity todo-wds "\\|")
  4512. "\\)\\>"))
  4513. (tags (nth 2 org-stuck-projects))
  4514. (tags-re (if (member "*" tags)
  4515. (concat org-outline-regexp-bol
  4516. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4517. (if tags
  4518. (concat org-outline-regexp-bol
  4519. ".*:\\("
  4520. (mapconcat 'identity tags "\\|")
  4521. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4522. (gen-re (nth 3 org-stuck-projects))
  4523. (re-list
  4524. (delq nil
  4525. (list
  4526. (if todo todo-re)
  4527. (if tags tags-re)
  4528. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4529. gen-re)))))
  4530. (setq org-agenda-skip-regexp
  4531. (if re-list
  4532. (mapconcat 'identity re-list "\\|")
  4533. (error "No information how to identify unstuck projects")))
  4534. (org-tags-view nil matcher)
  4535. (with-current-buffer org-agenda-buffer-name
  4536. (setq org-agenda-redo-command
  4537. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4538. (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
  4539. Create agenda view for projects that are stuck.
  4540. Stuck projects are project that have no next actions. For the definitions
  4541. of what a project is and how to check if it stuck, customize the variable
  4542. `org-stuck-projects'.
  4543. \(fn &rest IGNORE)" t nil)
  4544. ;;; Diary integration
  4545. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4546. (defvar diary-list-entries-hook)
  4547. (defvar diary-time-regexp)
  4548. (defun org-get-entries-from-diary (date)
  4549. "Get the (Emacs Calendar) diary entries for DATE."
  4550. (require 'diary-lib)
  4551. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4552. (diary-display-hook '(fancy-diary-display))
  4553. (diary-display-function 'fancy-diary-display)
  4554. (pop-up-frames nil)
  4555. (diary-list-entries-hook
  4556. (cons 'org-diary-default-entry diary-list-entries-hook))
  4557. (diary-file-name-prefix-function nil) ; turn this feature off
  4558. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4559. entries
  4560. (org-disable-agenda-to-diary t))
  4561. (save-excursion
  4562. (save-window-excursion
  4563. (funcall (if (fboundp 'diary-list-entries)
  4564. 'diary-list-entries 'list-diary-entries)
  4565. date 1)))
  4566. (if (not (get-buffer diary-fancy-buffer))
  4567. (setq entries nil)
  4568. (with-current-buffer diary-fancy-buffer
  4569. (setq buffer-read-only nil)
  4570. (if (zerop (buffer-size))
  4571. ;; No entries
  4572. (setq entries nil)
  4573. ;; Omit the date and other unnecessary stuff
  4574. (org-agenda-cleanup-fancy-diary)
  4575. ;; Add prefix to each line and extend the text properties
  4576. (if (zerop (buffer-size))
  4577. (setq entries nil)
  4578. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4579. (setq entries
  4580. (with-temp-buffer
  4581. (insert entries) (goto-char (point-min))
  4582. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4583. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4584. (replace-match (concat "; " (match-string 1)))))
  4585. (buffer-string)))))
  4586. (set-buffer-modified-p nil)
  4587. (kill-buffer diary-fancy-buffer)))
  4588. (when entries
  4589. (setq entries (org-split-string entries "\n"))
  4590. (setq entries
  4591. (mapcar
  4592. (lambda (x)
  4593. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4594. ;; Extend the text properties to the beginning of the line
  4595. (org-add-props x (text-properties-at (1- (length x)) x)
  4596. 'type "diary" 'date date 'face 'org-agenda-diary))
  4597. entries)))))
  4598. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4599. "Hook run when the fancy diary buffer is cleaned up.")
  4600. (defun org-agenda-cleanup-fancy-diary ()
  4601. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4602. This gets rid of the date, the underline under the date, and
  4603. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4604. date. It also removes lines that contain only whitespace."
  4605. (goto-char (point-min))
  4606. (if (looking-at ".*?:[ \t]*")
  4607. (progn
  4608. (replace-match "")
  4609. (re-search-forward "\n=+$" nil t)
  4610. (replace-match "")
  4611. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4612. (re-search-forward "\n=+$" nil t)
  4613. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4614. (goto-char (point-min))
  4615. (while (re-search-forward "^ +\n" nil t)
  4616. (replace-match ""))
  4617. (goto-char (point-min))
  4618. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4619. (replace-match ""))
  4620. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4621. ;; Make sure entries from the diary have the right text properties.
  4622. (eval-after-load "diary-lib"
  4623. '(if (boundp 'diary-modify-entry-list-string-function)
  4624. ;; We can rely on the hook, nothing to do
  4625. nil
  4626. ;; Hook not available, must use advice to make this work
  4627. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4628. "Make the position visible."
  4629. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4630. (stringp string)
  4631. buffer-file-name)
  4632. (setq string (org-modify-diary-entry-string string))))))
  4633. (defun org-modify-diary-entry-string (string)
  4634. "Add text properties to string, allowing org-mode to act on it."
  4635. (org-add-props string nil
  4636. 'mouse-face 'highlight
  4637. 'help-echo (if buffer-file-name
  4638. (format "mouse-2 or RET jump to diary file %s"
  4639. (abbreviate-file-name buffer-file-name))
  4640. "")
  4641. 'org-agenda-diary-link t
  4642. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4643. (defun org-diary-default-entry ()
  4644. "Add a dummy entry to the diary.
  4645. Needed to avoid empty dates which mess up holiday display."
  4646. ;; Catch the error if dealing with the new add-to-diary-alist
  4647. (when org-disable-agenda-to-diary
  4648. (condition-case nil
  4649. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4650. (error
  4651. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4652. (defun org-add-to-diary-list (&rest args)
  4653. (if (fboundp 'diary-add-to-list)
  4654. (apply 'diary-add-to-list args)
  4655. (apply 'add-to-diary-list args)))
  4656. (defvar org-diary-last-run-time nil)
  4657. ;;;###autoload
  4658. (defun org-diary (&rest args)
  4659. "Return diary information from org files.
  4660. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4661. It accesses org files and extracts information from those files to be
  4662. listed in the diary. The function accepts arguments specifying what
  4663. items should be listed. For a list of arguments allowed here, see the
  4664. variable `org-agenda-entry-types'.
  4665. The call in the diary file should look like this:
  4666. &%%(org-diary) ~/path/to/some/orgfile.org
  4667. Use a separate line for each org file to check. Or, if you omit the file name,
  4668. all files listed in `org-agenda-files' will be checked automatically:
  4669. &%%(org-diary)
  4670. If you don't give any arguments (as in the example above), the default
  4671. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4672. So the example above may also be written as
  4673. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4674. The function expects the lisp variables `entry' and `date' to be provided
  4675. by the caller, because this is how the calendar works. Don't use this
  4676. function from a program - use `org-agenda-get-day-entries' instead."
  4677. (when (> (- (org-float-time)
  4678. org-agenda-last-marker-time)
  4679. 5)
  4680. ;; I am not sure if this works with sticky agendas, because the marker
  4681. ;; list is then no longer a global variable.
  4682. (org-agenda-reset-markers))
  4683. (org-compile-prefix-format 'agenda)
  4684. (org-set-sorting-strategy 'agenda)
  4685. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4686. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4687. (list entry)
  4688. (org-agenda-files t)))
  4689. (time (org-float-time))
  4690. file rtn results)
  4691. (when (or (not org-diary-last-run-time)
  4692. (> (- time
  4693. org-diary-last-run-time)
  4694. 3))
  4695. (org-agenda-prepare-buffers files))
  4696. (setq org-diary-last-run-time time)
  4697. ;; If this is called during org-agenda, don't return any entries to
  4698. ;; the calendar. Org Agenda will list these entries itself.
  4699. (if org-disable-agenda-to-diary (setq files nil))
  4700. (while (setq file (pop files))
  4701. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4702. (setq results (append results rtn)))
  4703. (if results
  4704. (concat (org-agenda-finalize-entries results) "\n"))))
  4705. (autoload 'org-diary "org-agenda" "\
  4706. Return diary information from org files.
  4707. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4708. It accesses org files and extracts information from those files to be
  4709. listed in the diary. The function accepts arguments specifying what
  4710. items should be listed. For a list of arguments allowed here, see the
  4711. variable `org-agenda-entry-types'.
  4712. The call in the diary file should look like this:
  4713. &%%(org-diary) ~/path/to/some/orgfile.org
  4714. Use a separate line for each org file to check. Or, if you omit the file name,
  4715. all files listed in `org-agenda-files' will be checked automatically:
  4716. &%%(org-diary)
  4717. If you don't give any arguments (as in the example above), the default
  4718. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4719. So the example above may also be written as
  4720. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4721. The function expects the lisp variables `entry' and `date' to be provided
  4722. by the caller, because this is how the calendar works. Don't use this
  4723. function from a program - use `org-agenda-get-day-entries' instead.
  4724. \(fn &rest ARGS)" nil nil)
  4725. ;;; Agenda entry finders
  4726. (defun org-agenda-get-day-entries (file date &rest args)
  4727. "Does the work for `org-diary' and `org-agenda'.
  4728. FILE is the path to a file to be checked for entries. DATE is date like
  4729. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4730. which kind of entries should be extracted. For details about these, see
  4731. the documentation of `org-diary'."
  4732. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4733. (let* ((org-startup-folded nil)
  4734. (org-startup-align-all-tables nil)
  4735. (buffer (if (file-exists-p file)
  4736. (org-get-agenda-file-buffer file)
  4737. (error "No such file %s" file)))
  4738. arg results rtn deadline-results)
  4739. (if (not buffer)
  4740. ;; If file does not exist, make sure an error message ends up in diary
  4741. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4742. (with-current-buffer buffer
  4743. (unless (derived-mode-p 'org-mode)
  4744. (error "Agenda file %s is not in `org-mode'" file))
  4745. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4746. (let ((case-fold-search nil))
  4747. (save-excursion
  4748. (save-restriction
  4749. (if org-agenda-restrict
  4750. (narrow-to-region org-agenda-restrict-begin
  4751. org-agenda-restrict-end)
  4752. (widen))
  4753. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4754. (while (setq arg (pop args))
  4755. (cond
  4756. ((and (eq arg :todo)
  4757. (equal date (calendar-gregorian-from-absolute
  4758. (org-today))))
  4759. (setq rtn (org-agenda-get-todos))
  4760. (setq results (append results rtn)))
  4761. ((eq arg :timestamp)
  4762. (setq rtn (org-agenda-get-blocks))
  4763. (setq results (append results rtn))
  4764. (setq rtn (org-agenda-get-timestamps deadline-results))
  4765. (setq results (append results rtn)))
  4766. ((eq arg :sexp)
  4767. (setq rtn (org-agenda-get-sexps))
  4768. (setq results (append results rtn)))
  4769. ((eq arg :scheduled)
  4770. (setq rtn (org-agenda-get-scheduled deadline-results))
  4771. (setq results (append results rtn)))
  4772. ((eq arg :closed)
  4773. (setq rtn (org-agenda-get-progress))
  4774. (setq results (append results rtn)))
  4775. ((eq arg :deadline)
  4776. (setq rtn (org-agenda-get-deadlines))
  4777. (setq deadline-results (copy-sequence rtn))
  4778. (setq results (append results rtn))))))))
  4779. results))))
  4780. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4781. (defun org-agenda-get-todos ()
  4782. "Return the TODO information for agenda display."
  4783. (let* ((props (list 'face nil
  4784. 'done-face 'org-agenda-done
  4785. 'org-not-done-regexp org-not-done-regexp
  4786. 'org-todo-regexp org-todo-regexp
  4787. 'org-complex-heading-regexp org-complex-heading-regexp
  4788. 'mouse-face 'highlight
  4789. 'help-echo
  4790. (format "mouse-2 or RET jump to org file %s"
  4791. (abbreviate-file-name buffer-file-name))))
  4792. (regexp (format org-heading-keyword-regexp-format
  4793. (cond
  4794. ((and org-select-this-todo-keyword
  4795. (equal org-select-this-todo-keyword "*"))
  4796. org-todo-regexp)
  4797. (org-select-this-todo-keyword
  4798. (concat "\\("
  4799. (mapconcat 'identity
  4800. (org-split-string
  4801. org-select-this-todo-keyword
  4802. "|")
  4803. "\\|") "\\)"))
  4804. (t org-not-done-regexp))))
  4805. marker priority category category-pos tags todo-state
  4806. ee txt beg end)
  4807. (goto-char (point-min))
  4808. (while (re-search-forward regexp nil t)
  4809. (catch :skip
  4810. (save-match-data
  4811. (beginning-of-line)
  4812. (org-agenda-skip)
  4813. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4814. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4815. (goto-char (1+ beg))
  4816. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4817. (throw :skip nil)))
  4818. (goto-char (match-beginning 2))
  4819. (setq marker (org-agenda-new-marker (match-beginning 0))
  4820. category (org-get-category)
  4821. category-pos (get-text-property (point) 'org-category-position)
  4822. txt (org-trim
  4823. (buffer-substring (match-beginning 2) (match-end 0)))
  4824. tags (org-get-tags-at nil t)
  4825. txt (org-agenda-format-item "" txt category tags t)
  4826. priority (1+ (org-get-priority txt))
  4827. todo-state (org-get-todo-state))
  4828. (org-add-props txt props
  4829. 'org-marker marker 'org-hd-marker marker
  4830. 'priority priority 'org-category category
  4831. 'org-category-position category-pos
  4832. 'type "todo" 'todo-state todo-state)
  4833. (push txt ee)
  4834. (if org-agenda-todo-list-sublevels
  4835. (goto-char (match-end 2))
  4836. (org-end-of-subtree 'invisible))))
  4837. (nreverse ee)))
  4838. (defun org-agenda-todo-custom-ignore-p (time n)
  4839. "Check whether timestamp is farther away than n number of days.
  4840. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4841. `org-agenda-todo-ignore-scheduled' or
  4842. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4843. (let ((days (org-days-to-time time)))
  4844. (if (>= n 0)
  4845. (>= days n)
  4846. (<= days n))))
  4847. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4848. (&optional end)
  4849. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4850. (when (or org-agenda-todo-ignore-with-date
  4851. org-agenda-todo-ignore-scheduled
  4852. org-agenda-todo-ignore-deadlines
  4853. org-agenda-todo-ignore-timestamp)
  4854. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4855. (save-excursion
  4856. (or (and org-agenda-todo-ignore-with-date
  4857. (re-search-forward org-ts-regexp end t))
  4858. (and org-agenda-todo-ignore-scheduled
  4859. (re-search-forward org-scheduled-time-regexp end t)
  4860. (cond
  4861. ((eq org-agenda-todo-ignore-scheduled 'future)
  4862. (> (org-days-to-time (match-string 1)) 0))
  4863. ((eq org-agenda-todo-ignore-scheduled 'past)
  4864. (<= (org-days-to-time (match-string 1)) 0))
  4865. ((numberp org-agenda-todo-ignore-scheduled)
  4866. (org-agenda-todo-custom-ignore-p
  4867. (match-string 1) org-agenda-todo-ignore-scheduled))
  4868. (t)))
  4869. (and org-agenda-todo-ignore-deadlines
  4870. (re-search-forward org-deadline-time-regexp end t)
  4871. (cond
  4872. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4873. ((eq org-agenda-todo-ignore-deadlines 'far)
  4874. (not (org-deadline-close (match-string 1))))
  4875. ((eq org-agenda-todo-ignore-deadlines 'future)
  4876. (> (org-days-to-time (match-string 1)) 0))
  4877. ((eq org-agenda-todo-ignore-deadlines 'past)
  4878. (<= (org-days-to-time (match-string 1)) 0))
  4879. ((numberp org-agenda-todo-ignore-deadlines)
  4880. (org-agenda-todo-custom-ignore-p
  4881. (match-string 1) org-agenda-todo-ignore-deadlines))
  4882. (t (org-deadline-close (match-string 1)))))
  4883. (and org-agenda-todo-ignore-timestamp
  4884. (let ((buffer (current-buffer))
  4885. (regexp
  4886. (concat
  4887. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4888. (start (point)))
  4889. ;; Copy current buffer into a temporary one
  4890. (with-temp-buffer
  4891. (insert-buffer-substring buffer start end)
  4892. (goto-char (point-min))
  4893. ;; Delete SCHEDULED and DEADLINE items
  4894. (while (re-search-forward regexp end t)
  4895. (delete-region (match-beginning 0) (match-end 0)))
  4896. (goto-char (point-min))
  4897. ;; No search for timestamp left
  4898. (when (re-search-forward org-ts-regexp nil t)
  4899. (cond
  4900. ((eq org-agenda-todo-ignore-timestamp 'future)
  4901. (> (org-days-to-time (match-string 1)) 0))
  4902. ((eq org-agenda-todo-ignore-timestamp 'past)
  4903. (<= (org-days-to-time (match-string 1)) 0))
  4904. ((numberp org-agenda-todo-ignore-timestamp)
  4905. (org-agenda-todo-custom-ignore-p
  4906. (match-string 1) org-agenda-todo-ignore-timestamp))
  4907. (t))))))))))
  4908. (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
  4909. Do we have a reason to ignore this TODO entry because it has a time stamp?
  4910. \(fn &optional END)" nil nil)
  4911. (defconst org-agenda-no-heading-message
  4912. "No heading for this item in buffer or region.")
  4913. (defun org-agenda-get-timestamps (&optional deadline-results)
  4914. "Return the date stamp information for agenda display."
  4915. (let* ((props (list 'face 'org-agenda-calendar-event
  4916. 'org-not-done-regexp org-not-done-regexp
  4917. 'org-todo-regexp org-todo-regexp
  4918. 'org-complex-heading-regexp org-complex-heading-regexp
  4919. 'mouse-face 'highlight
  4920. 'help-echo
  4921. (format "mouse-2 or RET jump to org file %s"
  4922. (abbreviate-file-name buffer-file-name))))
  4923. (d1 (calendar-absolute-from-gregorian date))
  4924. mm
  4925. (deadline-position-alist
  4926. (mapcar (lambda (a) (and (setq mm (get-text-property
  4927. 0 'org-hd-marker a))
  4928. (cons (marker-position mm) a)))
  4929. deadline-results))
  4930. (remove-re org-ts-regexp)
  4931. (regexp
  4932. (concat
  4933. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4934. (regexp-quote
  4935. (substring
  4936. (format-time-string
  4937. (car org-time-stamp-formats)
  4938. (apply 'encode-time ; DATE bound by calendar
  4939. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4940. 1 11))
  4941. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4942. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4943. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4944. donep tmp priority category category-pos ee txt timestr tags
  4945. b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
  4946. (goto-char (point-min))
  4947. (while (setq end-of-match (re-search-forward regexp nil t))
  4948. (setq b0 (match-beginning 0)
  4949. b3 (match-beginning 3) e3 (match-end 3)
  4950. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4951. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  4952. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4953. (member todo-state
  4954. org-agenda-repeating-timestamp-show-all)))
  4955. (catch :skip
  4956. (and (org-at-date-range-p) (throw :skip nil))
  4957. (org-agenda-skip)
  4958. (if (and (match-end 1)
  4959. (not (= d1 (org-time-string-to-absolute
  4960. (match-string 1) d1 nil show-all
  4961. (current-buffer) b0))))
  4962. (throw :skip nil))
  4963. (if (and e3
  4964. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4965. (throw :skip nil))
  4966. (setq tmp (buffer-substring (max (point-min)
  4967. (- b0 org-ds-keyword-length))
  4968. b0)
  4969. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4970. inactivep (= (char-after b0) ?\[)
  4971. deadlinep (string-match org-deadline-regexp tmp)
  4972. scheduledp (string-match org-scheduled-regexp tmp)
  4973. closedp (and org-agenda-include-inactive-timestamps
  4974. (string-match org-closed-string tmp))
  4975. clockp (and org-agenda-include-inactive-timestamps
  4976. (or (string-match org-clock-string tmp)
  4977. (string-match "]-+\\'" tmp)))
  4978. warntime (get-text-property (point) 'org-appt-warntime)
  4979. donep (member todo-state org-done-keywords))
  4980. (if (or scheduledp deadlinep closedp clockp
  4981. (and donep org-agenda-skip-timestamp-if-done))
  4982. (throw :skip t))
  4983. (if (string-match ">" timestr)
  4984. ;; substring should only run to end of time stamp
  4985. (setq timestr (substring timestr 0 (match-end 0))))
  4986. (setq marker (org-agenda-new-marker b0)
  4987. category (org-get-category b0)
  4988. category-pos (get-text-property b0 'org-category-position))
  4989. (save-excursion
  4990. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4991. (setq txt org-agenda-no-heading-message)
  4992. (goto-char (match-beginning 0))
  4993. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4994. (assoc (point) deadline-position-alist))
  4995. (throw :skip nil))
  4996. (setq hdmarker (org-agenda-new-marker)
  4997. tags (org-get-tags-at nil t))
  4998. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4999. (setq head (or (match-string 1) ""))
  5000. (setq txt (org-agenda-format-item
  5001. (if inactivep org-agenda-inactive-leader nil)
  5002. head category tags timestr
  5003. remove-re habitp)))
  5004. (setq priority (org-get-priority txt))
  5005. (org-add-props txt props
  5006. 'org-marker marker 'org-hd-marker hdmarker)
  5007. (org-add-props txt nil 'priority priority
  5008. 'org-category category 'date date
  5009. 'org-category-position category-pos
  5010. 'todo-state todo-state
  5011. 'warntime warntime
  5012. 'type "timestamp")
  5013. (push txt ee))
  5014. (if org-agenda-skip-additional-timestamps-same-entry
  5015. (outline-next-heading)
  5016. (goto-char end-of-match))))
  5017. (nreverse ee)))
  5018. (defun org-agenda-get-sexps ()
  5019. "Return the sexp information for agenda display."
  5020. (require 'diary-lib)
  5021. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5022. 'mouse-face 'highlight
  5023. 'help-echo
  5024. (format "mouse-2 or RET jump to org file %s"
  5025. (abbreviate-file-name buffer-file-name))))
  5026. (regexp "^&?%%(")
  5027. marker category extra category-pos ee txt tags entry
  5028. result beg b sexp sexp-entry todo-state warntime)
  5029. (goto-char (point-min))
  5030. (while (re-search-forward regexp nil t)
  5031. (catch :skip
  5032. (org-agenda-skip)
  5033. (setq beg (match-beginning 0))
  5034. (goto-char (1- (match-end 0)))
  5035. (setq b (point))
  5036. (forward-sexp 1)
  5037. (setq sexp (buffer-substring b (point)))
  5038. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5039. (org-trim (match-string 1))
  5040. ""))
  5041. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5042. (when result
  5043. (setq marker (org-agenda-new-marker beg)
  5044. category (org-get-category beg)
  5045. category-pos (get-text-property beg 'org-category-position)
  5046. tags (save-excursion (org-back-to-heading t) (org-get-tags-at nil t))
  5047. todo-state (org-get-todo-state)
  5048. warntime (get-text-property (point) 'org-appt-warntime)
  5049. extra nil)
  5050. (dolist (r (if (stringp result)
  5051. (list result)
  5052. result)) ;; we expect a list here
  5053. (when (and org-agenda-diary-sexp-prefix
  5054. (string-match org-agenda-diary-sexp-prefix r))
  5055. (setq extra (match-string 0 r)
  5056. r (replace-match "" nil nil r)))
  5057. (if (string-match "\\S-" r)
  5058. (setq txt r)
  5059. (setq txt "SEXP entry returned empty string"))
  5060. (setq txt (org-agenda-format-item
  5061. extra txt category tags 'time))
  5062. (org-add-props txt props 'org-marker marker)
  5063. (org-add-props txt nil
  5064. 'org-category category 'date date 'todo-state todo-state
  5065. 'org-category-position category-pos 'tags tags
  5066. 'type "sexp" 'warntime warntime)
  5067. (push txt ee)))))
  5068. (nreverse ee)))
  5069. ;; Calendar sanity: define some functions that are independent of
  5070. ;; `calendar-date-style'.
  5071. ;; Normally I would like to use ISO format when calling the diary functions,
  5072. ;; but to make sure we still have Emacs 22 compatibility we bind
  5073. ;; also `european-calendar-style' and use european format
  5074. (defun org-anniversary (year month day &optional mark)
  5075. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5076. (org-no-warnings
  5077. (let ((calendar-date-style 'european) (european-calendar-style t))
  5078. (diary-anniversary day month year mark))))
  5079. (defun org-cyclic (N year month day &optional mark)
  5080. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5081. (org-no-warnings
  5082. (let ((calendar-date-style 'european) (european-calendar-style t))
  5083. (diary-cyclic N day month year mark))))
  5084. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5085. "Like `diary-block', but with fixed (ISO) order of arguments."
  5086. (org-no-warnings
  5087. (let ((calendar-date-style 'european) (european-calendar-style t))
  5088. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5089. (defun org-date (year month day &optional mark)
  5090. "Like `diary-date', but with fixed (ISO) order of arguments."
  5091. (org-no-warnings
  5092. (let ((calendar-date-style 'european) (european-calendar-style t))
  5093. (diary-date day month year mark))))
  5094. ;; Define the` org-class' function
  5095. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5096. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5097. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5098. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5099. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5100. `holidays', then any date that is known by the Emacs calendar to be a
  5101. holiday will also be skipped."
  5102. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5103. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5104. (d (calendar-absolute-from-gregorian date)))
  5105. (and
  5106. (<= date1 d)
  5107. (<= d date2)
  5108. (= (calendar-day-of-week date) dayname)
  5109. (or (not skip-weeks)
  5110. (progn
  5111. (require 'cal-iso)
  5112. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5113. (not (and (memq 'holidays skip-weeks)
  5114. (calendar-check-holidays date)))
  5115. entry)))
  5116. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5117. "Like `org-class', but honor `calendar-date-style'.
  5118. The order of the first 2 times 3 arguments depends on the variable
  5119. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5120. So for American calendars, give this as MONTH DAY YEAR, for European as
  5121. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5122. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5123. is any number of ISO weeks in the block period for which the item should
  5124. be skipped.
  5125. This function is here only for backward compatibility and it is deprecated,
  5126. please use `org-class' instead."
  5127. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5128. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5129. (org-class
  5130. (nth 2 date1) (car date1) (nth 1 date1)
  5131. (nth 2 date2) (car date2) (nth 1 date2)
  5132. dayname skip-weeks)))
  5133. (make-obsolete 'org-diary-class 'org-class "")
  5134. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5135. (defalias 'org-get-closed 'org-agenda-get-progress)
  5136. (defun org-agenda-get-progress ()
  5137. "Return the logged TODO entries for agenda display."
  5138. (let* ((props (list 'mouse-face 'highlight
  5139. 'org-not-done-regexp org-not-done-regexp
  5140. 'org-todo-regexp org-todo-regexp
  5141. 'org-complex-heading-regexp org-complex-heading-regexp
  5142. 'help-echo
  5143. (format "mouse-2 or RET jump to org file %s"
  5144. (abbreviate-file-name buffer-file-name))))
  5145. (items (if (consp org-agenda-show-log-scoped)
  5146. org-agenda-show-log-scoped
  5147. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5148. '(clock)
  5149. org-agenda-log-mode-items)))
  5150. (parts
  5151. (delq nil
  5152. (list
  5153. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5154. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5155. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5156. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5157. (error "`org-agenda-log-mode-items' is empty")))
  5158. (regexp (concat
  5159. "\\(" parts-re "\\)"
  5160. " *\\["
  5161. (regexp-quote
  5162. (substring
  5163. (format-time-string
  5164. (car org-time-stamp-formats)
  5165. (apply 'encode-time ; DATE bound by calendar
  5166. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5167. 1 11))))
  5168. (org-agenda-search-headline-for-time nil)
  5169. marker hdmarker priority category category-pos tags closedp
  5170. statep clockp state ee txt extra timestr rest clocked)
  5171. (goto-char (point-min))
  5172. (while (re-search-forward regexp nil t)
  5173. (catch :skip
  5174. (org-agenda-skip)
  5175. (setq marker (org-agenda-new-marker (match-beginning 0))
  5176. closedp (equal (match-string 1) org-closed-string)
  5177. statep (equal (string-to-char (match-string 1)) ?-)
  5178. clockp (not (or closedp statep))
  5179. state (and statep (match-string 2))
  5180. category (org-get-category (match-beginning 0))
  5181. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5182. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5183. (when (string-match "\\]" timestr)
  5184. ;; substring should only run to end of time stamp
  5185. (setq rest (substring timestr (match-end 0))
  5186. timestr (substring timestr 0 (match-end 0)))
  5187. (if (and (not closedp) (not statep)
  5188. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5189. rest))
  5190. (progn (setq timestr (concat (substring timestr 0 -1)
  5191. "-" (match-string 1 rest) "]"))
  5192. (setq clocked (match-string 2 rest)))
  5193. (setq clocked "-")))
  5194. (save-excursion
  5195. (setq extra
  5196. (cond
  5197. ((not org-agenda-log-mode-add-notes) nil)
  5198. (statep
  5199. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5200. (match-string 1)))
  5201. (clockp
  5202. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5203. (match-string 1)))))
  5204. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5205. (setq txt org-agenda-no-heading-message)
  5206. (goto-char (match-beginning 0))
  5207. (setq hdmarker (org-agenda-new-marker)
  5208. tags (org-get-tags-at nil t))
  5209. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5210. (setq txt (match-string 1))
  5211. (when extra
  5212. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5213. (setq txt (concat (substring txt 0 (match-beginning 1))
  5214. " - " extra " " (match-string 2 txt)))
  5215. (setq txt (concat txt " - " extra))))
  5216. (setq txt (org-agenda-format-item
  5217. (cond
  5218. (closedp "Closed: ")
  5219. (statep (concat "State: (" state ")"))
  5220. (t (concat "Clocked: (" clocked ")")))
  5221. txt category tags timestr)))
  5222. (setq priority 100000)
  5223. (org-add-props txt props
  5224. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5225. 'priority priority 'org-category category
  5226. 'org-category-position category-pos
  5227. 'type "closed" 'date date
  5228. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5229. (push txt ee))
  5230. (goto-char (point-at-eol))))
  5231. (nreverse ee)))
  5232. (defun org-agenda-show-clocking-issues ()
  5233. "Add overlays, showing issues with clocking.
  5234. See also the user option `org-agenda-clock-consistency-checks'."
  5235. (interactive)
  5236. (let* ((pl org-agenda-clock-consistency-checks)
  5237. (re (concat "^[ \t]*"
  5238. org-clock-string
  5239. "[ \t]+"
  5240. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5241. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5242. (tlstart 0.)
  5243. (tlend 0.)
  5244. (maxtime (org-hh:mm-string-to-minutes
  5245. (or (plist-get pl :max-duration) "24:00")))
  5246. (mintime (org-hh:mm-string-to-minutes
  5247. (or (plist-get pl :min-duration) 0)))
  5248. (maxgap (org-hh:mm-string-to-minutes
  5249. ;; default 30:00 means never complain
  5250. (or (plist-get pl :max-gap) "30:00")))
  5251. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5252. (plist-get pl :gap-ok-around)))
  5253. (def-face (or (plist-get pl :default-face)
  5254. '((:background "DarkRed") (:foreground "white"))))
  5255. issue face m te ts dt ov)
  5256. (goto-char (point-min))
  5257. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5258. (setq issue nil face def-face)
  5259. (catch 'next
  5260. (setq m (org-get-at-bol 'org-marker)
  5261. te nil ts nil)
  5262. (unless (and m (markerp m))
  5263. (setq issue "No valid clock line") (throw 'next t))
  5264. (org-with-point-at m
  5265. (save-excursion
  5266. (goto-char (point-at-bol))
  5267. (unless (looking-at re)
  5268. (error "No valid Clock line")
  5269. (throw 'next t))
  5270. (unless (match-end 3)
  5271. (setq issue "No end time"
  5272. face (or (plist-get pl :no-end-time-face) face))
  5273. (throw 'next t))
  5274. (setq ts (match-string 1)
  5275. te (match-string 3)
  5276. ts (org-float-time
  5277. (apply 'encode-time (org-parse-time-string ts)))
  5278. te (org-float-time
  5279. (apply 'encode-time (org-parse-time-string te)))
  5280. dt (- te ts))))
  5281. (cond
  5282. ((> dt (* 60 maxtime))
  5283. ;; a very long clocking chunk
  5284. (setq issue (format "Clocking interval is very long: %s"
  5285. (org-minutes-to-hh:mm-string
  5286. (floor (/ (float dt) 60.))))
  5287. face (or (plist-get pl :long-face) face)))
  5288. ((< dt (* 60 mintime))
  5289. ;; a very short clocking chunk
  5290. (setq issue (format "Clocking interval is very short: %s"
  5291. (org-minutes-to-hh:mm-string
  5292. (floor (/ (float dt) 60.))))
  5293. face (or (plist-get pl :short-face) face)))
  5294. ((and (> tlend 0) (< ts tlend))
  5295. ;; Two clock entries are overlapping
  5296. (setq issue (format "Clocking overlap: %d minutes"
  5297. (/ (- tlend ts) 60))
  5298. face (or (plist-get pl :overlap-face) face)))
  5299. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5300. ;; There is a gap, lets see if we need to report it
  5301. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5302. (setq issue (format "Clocking gap: %d minutes"
  5303. (/ (- ts tlend) 60))
  5304. face (or (plist-get pl :gap-face) face))))
  5305. (t nil)))
  5306. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5307. (when issue
  5308. ;; OK, there was some issue, add an overlay to show the issue
  5309. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5310. (overlay-put ov 'before-string
  5311. (concat
  5312. (org-add-props
  5313. (format "%-43s" (concat " " issue))
  5314. nil
  5315. 'face face)
  5316. "\n"))
  5317. (overlay-put ov 'evaporate t)))))
  5318. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5319. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5320. (catch 'exit
  5321. (unless ok-list
  5322. ;; there are no OK times for gaps...
  5323. (throw 'exit nil))
  5324. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5325. ;; This is more than 24 hours, so it is OK.
  5326. ;; because we have at least one OK time, that must be in the
  5327. ;; 24 hour interval.
  5328. (throw 'exit t))
  5329. ;; We have a shorter gap.
  5330. ;; Now we have to get the minute of the day when these times are
  5331. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5332. (t2dec (decode-time (seconds-to-time t2)))
  5333. ;; compute the minute on the day
  5334. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5335. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5336. (when (< min2 min1)
  5337. ;; if min2 is smaller than min1, this means it is on the next day.
  5338. ;; Wrap it to after midnight.
  5339. (setq min2 (+ min2 1440)))
  5340. ;; Now check if any of the OK times is in the gap
  5341. (mapc (lambda (x)
  5342. ;; Wrap the time to after midnight if necessary
  5343. (if (< x min1) (setq x (+ x 1440)))
  5344. ;; Check if in interval
  5345. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5346. ok-list)
  5347. ;; Nope, this gap is not OK
  5348. nil)))
  5349. (defun org-agenda-get-deadlines ()
  5350. "Return the deadline information for agenda display."
  5351. (let* ((props (list 'mouse-face 'highlight
  5352. 'org-not-done-regexp org-not-done-regexp
  5353. 'org-todo-regexp org-todo-regexp
  5354. 'org-complex-heading-regexp org-complex-heading-regexp
  5355. 'help-echo
  5356. (format "mouse-2 or RET jump to org file %s"
  5357. (abbreviate-file-name buffer-file-name))))
  5358. (regexp org-deadline-time-regexp)
  5359. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5360. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5361. d2 diff dfrac wdays pos pos1 category category-pos
  5362. tags suppress-prewarning ee txt head face s todo-state
  5363. show-all upcomingp donep timestr warntime)
  5364. (goto-char (point-min))
  5365. (while (re-search-forward regexp nil t)
  5366. (setq suppress-prewarning nil)
  5367. (catch :skip
  5368. (org-agenda-skip)
  5369. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5370. (save-match-data
  5371. (string-match org-scheduled-time-regexp
  5372. (buffer-substring (point-at-bol)
  5373. (point-at-eol)))))
  5374. (setq suppress-prewarning
  5375. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5376. org-agenda-skip-deadline-prewarning-if-scheduled
  5377. 0)))
  5378. (setq s (match-string 1)
  5379. txt nil
  5380. pos (1- (match-beginning 1))
  5381. todo-state (save-match-data (org-get-todo-state))
  5382. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5383. (member todo-state
  5384. org-agenda-repeating-timestamp-show-all))
  5385. d2 (org-time-string-to-absolute
  5386. (match-string 1) d1 'past show-all
  5387. (current-buffer) pos)
  5388. diff (- d2 d1)
  5389. wdays (if suppress-prewarning
  5390. (let ((org-deadline-warning-days suppress-prewarning))
  5391. (org-get-wdays s))
  5392. (org-get-wdays s))
  5393. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5394. upcomingp (and todayp (> diff 0)))
  5395. ;; When to show a deadline in the calendar:
  5396. ;; If the expiration is within wdays warning time.
  5397. ;; Past-due deadlines are only shown on the current date
  5398. (if (and (or (and (<= diff wdays)
  5399. (and todayp (not org-agenda-only-exact-dates)))
  5400. (= diff 0)))
  5401. (save-excursion
  5402. ;; (setq todo-state (org-get-todo-state))
  5403. (setq donep (member todo-state org-done-keywords))
  5404. (if (and donep
  5405. (or org-agenda-skip-deadline-if-done
  5406. (not (= diff 0))))
  5407. (setq txt nil)
  5408. (setq category (org-get-category)
  5409. warntime (get-text-property (point) 'org-appt-warntime)
  5410. category-pos (get-text-property (point) 'org-category-position))
  5411. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5412. (setq txt org-agenda-no-heading-message)
  5413. (goto-char (match-end 0))
  5414. (setq pos1 (match-beginning 0))
  5415. (setq tags (org-get-tags-at pos1 t))
  5416. (setq head (buffer-substring-no-properties
  5417. (point)
  5418. (progn (skip-chars-forward "^\r\n")
  5419. (point))))
  5420. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5421. (setq timestr
  5422. (concat (substring s (match-beginning 1)) " "))
  5423. (setq timestr 'time))
  5424. (setq txt (org-agenda-format-item
  5425. (if (= diff 0)
  5426. (car org-agenda-deadline-leaders)
  5427. (if (functionp
  5428. (nth 1 org-agenda-deadline-leaders))
  5429. (funcall
  5430. (nth 1 org-agenda-deadline-leaders)
  5431. diff date)
  5432. (format (nth 1 org-agenda-deadline-leaders)
  5433. diff)))
  5434. head category tags
  5435. (if (not (= diff 0)) nil timestr)))))
  5436. (when txt
  5437. (setq face (org-agenda-deadline-face dfrac))
  5438. (org-add-props txt props
  5439. 'org-marker (org-agenda-new-marker pos)
  5440. 'warntime warntime
  5441. 'org-hd-marker (org-agenda-new-marker pos1)
  5442. 'priority (+ (- diff)
  5443. (org-get-priority txt))
  5444. 'org-category category
  5445. 'org-category-position category-pos
  5446. 'todo-state todo-state
  5447. 'type (if upcomingp "upcoming-deadline" "deadline")
  5448. 'date (if upcomingp date d2)
  5449. 'face (if donep 'org-agenda-done face)
  5450. 'undone-face face 'done-face 'org-agenda-done)
  5451. (push txt ee))))))
  5452. (nreverse ee)))
  5453. (defun org-agenda-deadline-face (fraction)
  5454. "Return the face to displaying a deadline item.
  5455. FRACTION is what fraction of the head-warning time has passed."
  5456. (let ((faces org-agenda-deadline-faces) f)
  5457. (catch 'exit
  5458. (while (setq f (pop faces))
  5459. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5460. (defun org-agenda-get-scheduled (&optional deadline-results)
  5461. "Return the scheduled information for agenda display."
  5462. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5463. 'org-todo-regexp org-todo-regexp
  5464. 'org-complex-heading-regexp org-complex-heading-regexp
  5465. 'done-face 'org-agenda-done
  5466. 'mouse-face 'highlight
  5467. 'help-echo
  5468. (format "mouse-2 or RET jump to org file %s"
  5469. (abbreviate-file-name buffer-file-name))))
  5470. (regexp org-scheduled-time-regexp)
  5471. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5472. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5473. mm
  5474. (deadline-position-alist
  5475. (mapcar (lambda (a) (and (setq mm (get-text-property
  5476. 0 'org-hd-marker a))
  5477. (cons (marker-position mm) a)))
  5478. deadline-results))
  5479. d2 diff pos pos1 category category-pos tags donep
  5480. ee txt head pastschedp todo-state face timestr s habitp show-all
  5481. did-habit-check-p warntime)
  5482. (goto-char (point-min))
  5483. (while (re-search-forward regexp nil t)
  5484. (catch :skip
  5485. (org-agenda-skip)
  5486. (setq s (match-string 1)
  5487. txt nil
  5488. pos (1- (match-beginning 1))
  5489. todo-state (save-match-data (org-get-todo-state))
  5490. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5491. (member todo-state
  5492. org-agenda-repeating-timestamp-show-all))
  5493. d2 (org-time-string-to-absolute
  5494. (match-string 1) d1 'past show-all
  5495. (current-buffer) pos)
  5496. diff (- d2 d1)
  5497. warntime (get-text-property (point) 'org-appt-warntime))
  5498. (setq pastschedp (and todayp (< diff 0)))
  5499. (setq did-habit-check-p nil)
  5500. ;; When to show a scheduled item in the calendar:
  5501. ;; If it is on or past the date.
  5502. (when (or (and (< diff 0)
  5503. (< (abs diff) org-scheduled-past-days)
  5504. (and todayp (not org-agenda-only-exact-dates)))
  5505. (= diff 0)
  5506. ;; org-is-habit-p uses org-entry-get, which is expansive
  5507. ;; so we go extra mile to only call it once
  5508. (and todayp
  5509. (boundp 'org-habit-show-all-today)
  5510. org-habit-show-all-today
  5511. (setq did-habit-check-p t)
  5512. (setq habitp (and (functionp 'org-is-habit-p)
  5513. (org-is-habit-p)))))
  5514. (save-excursion
  5515. (setq donep (member todo-state org-done-keywords))
  5516. (if (and donep
  5517. (or org-agenda-skip-scheduled-if-done
  5518. (not (= diff 0))
  5519. (and (functionp 'org-is-habit-p)
  5520. (org-is-habit-p))))
  5521. (setq txt nil)
  5522. (setq habitp (if did-habit-check-p habitp
  5523. (and (functionp 'org-is-habit-p)
  5524. (org-is-habit-p))))
  5525. (setq category (org-get-category)
  5526. category-pos (get-text-property (point) 'org-category-position))
  5527. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5528. (setq txt org-agenda-no-heading-message)
  5529. (goto-char (match-end 0))
  5530. (setq pos1 (match-beginning 0))
  5531. (if habitp
  5532. (if (or (not org-habit-show-habits)
  5533. (and (not todayp)
  5534. (boundp 'org-habit-show-habits-only-for-today)
  5535. org-habit-show-habits-only-for-today))
  5536. (throw :skip nil))
  5537. (if (and
  5538. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5539. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5540. pastschedp))
  5541. (setq mm (assoc pos1 deadline-position-alist)))
  5542. (throw :skip nil)))
  5543. (setq tags (org-get-tags-at nil t))
  5544. (setq head (buffer-substring-no-properties
  5545. (point)
  5546. (progn (skip-chars-forward "^\r\n") (point))))
  5547. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5548. (setq timestr
  5549. (concat (substring s (match-beginning 1)) " "))
  5550. (setq timestr 'time))
  5551. (setq txt (org-agenda-format-item
  5552. (if (= diff 0)
  5553. (car org-agenda-scheduled-leaders)
  5554. (format (nth 1 org-agenda-scheduled-leaders)
  5555. (- 1 diff)))
  5556. head category tags
  5557. (if (not (= diff 0)) nil timestr)
  5558. nil habitp))))
  5559. (when txt
  5560. (setq face
  5561. (cond
  5562. ((and (not habitp) pastschedp)
  5563. 'org-scheduled-previously)
  5564. (todayp 'org-scheduled-today)
  5565. (t 'org-scheduled))
  5566. habitp (and habitp (org-habit-parse-todo)))
  5567. (org-add-props txt props
  5568. 'undone-face face
  5569. 'face (if donep 'org-agenda-done face)
  5570. 'org-marker (org-agenda-new-marker pos)
  5571. 'org-hd-marker (org-agenda-new-marker pos1)
  5572. 'type (if pastschedp "past-scheduled" "scheduled")
  5573. 'date (if pastschedp d2 date)
  5574. 'warntime warntime
  5575. 'priority (if habitp
  5576. (org-habit-get-priority habitp)
  5577. (+ 94 (- 5 diff) (org-get-priority txt)))
  5578. 'org-category category
  5579. 'category-position category-pos
  5580. 'org-habit-p habitp
  5581. 'todo-state todo-state)
  5582. (push txt ee))))))
  5583. (nreverse ee)))
  5584. (defun org-agenda-get-blocks ()
  5585. "Return the date-range information for agenda display."
  5586. (let* ((props (list 'face nil
  5587. 'org-not-done-regexp org-not-done-regexp
  5588. 'org-todo-regexp org-todo-regexp
  5589. 'org-complex-heading-regexp org-complex-heading-regexp
  5590. 'mouse-face 'highlight
  5591. 'help-echo
  5592. (format "mouse-2 or RET jump to org file %s"
  5593. (abbreviate-file-name buffer-file-name))))
  5594. (regexp org-tr-regexp)
  5595. (d0 (calendar-absolute-from-gregorian date))
  5596. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5597. todo-state tags pos head donep)
  5598. (goto-char (point-min))
  5599. (while (re-search-forward regexp nil t)
  5600. (catch :skip
  5601. (org-agenda-skip)
  5602. (setq pos (point))
  5603. (let ((start-time (match-string 1))
  5604. (end-time (match-string 2)))
  5605. (setq s1 (match-string 1)
  5606. s2 (match-string 2)
  5607. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5608. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5609. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5610. ;; Only allow days between the limits, because the normal
  5611. ;; date stamps will catch the limits.
  5612. (save-excursion
  5613. (setq todo-state (org-get-todo-state))
  5614. (setq donep (member todo-state org-done-keywords))
  5615. (if (and donep org-agenda-skip-timestamp-if-done)
  5616. (throw :skip t))
  5617. (setq marker (org-agenda-new-marker (point)))
  5618. (setq category (org-get-category)
  5619. category-pos (get-text-property (point) 'org-category-position))
  5620. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5621. (setq txt org-agenda-no-heading-message)
  5622. (goto-char (match-beginning 0))
  5623. (setq hdmarker (org-agenda-new-marker (point)))
  5624. (setq tags (org-get-tags-at nil t))
  5625. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5626. (setq head (match-string 1))
  5627. (let ((remove-re
  5628. (if org-agenda-remove-timeranges-from-blocks
  5629. (concat
  5630. "<" (regexp-quote s1) ".*?>"
  5631. "--"
  5632. "<" (regexp-quote s2) ".*?>")
  5633. nil)))
  5634. (setq txt (org-agenda-format-item
  5635. (format
  5636. (nth (if (= d1 d2) 0 1)
  5637. org-agenda-timerange-leaders)
  5638. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5639. head category tags
  5640. (cond ((and (= d1 d0) (= d2 d0))
  5641. (concat "<" start-time ">--<" end-time ">"))
  5642. ((= d1 d0)
  5643. (concat "<" start-time ">"))
  5644. ((= d2 d0)
  5645. (concat "<" end-time ">")))
  5646. remove-re))))
  5647. (org-add-props txt props
  5648. 'org-marker marker 'org-hd-marker hdmarker
  5649. 'type "block" 'date date
  5650. 'todo-state todo-state
  5651. 'priority (org-get-priority txt) 'org-category category
  5652. 'org-category-position category-pos)
  5653. (push txt ee))))
  5654. (goto-char pos)))
  5655. ;; Sort the entries by expiration date.
  5656. (nreverse ee)))
  5657. ;;; Agenda presentation and sorting
  5658. (defvar org-prefix-has-time nil
  5659. "A flag, set by `org-compile-prefix-format'.
  5660. The flag is set if the currently compiled format contains a `%t'.")
  5661. (defvar org-prefix-has-tag nil
  5662. "A flag, set by `org-compile-prefix-format'.
  5663. The flag is set if the currently compiled format contains a `%T'.")
  5664. (defvar org-prefix-has-effort nil
  5665. "A flag, set by `org-compile-prefix-format'.
  5666. The flag is set if the currently compiled format contains a `%e'.")
  5667. (defvar org-prefix-category-length nil
  5668. "Used by `org-compile-prefix-format' to remember the category field width.")
  5669. (defvar org-prefix-category-max-length nil
  5670. "Used by `org-compile-prefix-format' to remember the category field width.")
  5671. (defun org-agenda-get-category-icon (category)
  5672. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5673. (dolist (entry org-agenda-category-icon-alist)
  5674. (when (org-string-match-p (car entry) category)
  5675. (if (listp (cadr entry))
  5676. (return (cadr entry))
  5677. (return (apply 'create-image (cdr entry)))))))
  5678. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5679. remove-re habitp)
  5680. "Format TXT to be inserted into the agenda buffer.
  5681. In particular, it adds the prefix and corresponding text properties. EXTRA
  5682. must be a string and replaces the `%s' specifier in the prefix format.
  5683. CATEGORY (string, symbol or nil) may be used to overrule the default
  5684. category taken from local variable or file name. It will replace the `%c'
  5685. specifier in the format. DOTIME, when non-nil, indicates that a
  5686. time-of-day should be extracted from TXT for sorting of this entry, and for
  5687. the `%t' specifier in the format. When DOTIME is a string, this string is
  5688. searched for a time before TXT is. TAGS can be the tags of the headline.
  5689. Any match of REMOVE-RE will be removed from TXT."
  5690. ;; We keep the org-prefix-* variable values along with a compiled
  5691. ;; formatter, so that multiple agendas existing at the same time, do
  5692. ;; not step on each other toes.
  5693. ;;
  5694. ;; It was inconvenient to make these variables buffer local in
  5695. ;; Agenda buffers, because this function expects to be called with
  5696. ;; the buffer where item comes from being current, and not agenda
  5697. ;; buffer
  5698. (let* ((bindings (car org-prefix-format-compiled))
  5699. (formatter (cadr org-prefix-format-compiled)))
  5700. (loop for (var value) in bindings
  5701. do (set var value))
  5702. (save-match-data
  5703. ;; Diary entries sometimes have extra whitespace at the beginning
  5704. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5705. ;; Fix the tags part in txt
  5706. (setq txt (org-agenda-fix-displayed-tags
  5707. txt tags
  5708. org-agenda-show-inherited-tags
  5709. org-agenda-hide-tags-regexp))
  5710. (let* ((category (or category
  5711. (if (stringp org-category)
  5712. org-category
  5713. (and org-category (symbol-name org-category)))
  5714. (if buffer-file-name
  5715. (file-name-sans-extension
  5716. (file-name-nondirectory buffer-file-name))
  5717. "")))
  5718. (category-icon (org-agenda-get-category-icon category))
  5719. (category-icon (if category-icon
  5720. (propertize " " 'display category-icon)
  5721. ""))
  5722. ;; time, tag, effort are needed for the eval of the prefix format
  5723. (tag (if tags (nth (1- (length tags)) tags) ""))
  5724. time effort neffort
  5725. (ts (if dotime (concat
  5726. (if (stringp dotime) dotime "")
  5727. (and org-agenda-search-headline-for-time txt))))
  5728. (time-of-day (and dotime (org-get-time-of-day ts)))
  5729. stamp plain s0 s1 s2 rtn srp l
  5730. duration thecategory)
  5731. (and (derived-mode-p 'org-mode) buffer-file-name
  5732. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5733. (when (and dotime time-of-day)
  5734. ;; Extract starting and ending time and move them to prefix
  5735. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5736. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5737. (setq s0 (match-string 0 ts)
  5738. srp (and stamp (match-end 3))
  5739. s1 (match-string (if plain 1 2) ts)
  5740. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5741. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5742. ;; them, we might want to remove them there to avoid duplication.
  5743. ;; The user can turn this off with a variable.
  5744. (if (and org-prefix-has-time
  5745. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5746. (string-match (concat (regexp-quote s0) " *") txt)
  5747. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5748. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5749. (= (match-beginning 0) 0)
  5750. t))
  5751. (setq txt (replace-match "" nil nil txt))))
  5752. ;; Normalize the time(s) to 24 hour
  5753. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5754. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5755. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5756. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5757. (setq s2
  5758. (org-minutes-to-hh:mm-string
  5759. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5760. ;; Compute the duration
  5761. (when s2
  5762. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5763. (org-hh:mm-string-to-minutes s1)))))
  5764. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5765. txt)
  5766. ;; Tags are in the string
  5767. (if (or (eq org-agenda-remove-tags t)
  5768. (and org-agenda-remove-tags
  5769. org-prefix-has-tag))
  5770. (setq txt (replace-match "" t t txt))
  5771. (setq txt (replace-match
  5772. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5773. (match-string 2 txt))
  5774. t t txt))))
  5775. (when (derived-mode-p 'org-mode)
  5776. (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
  5777. (when effort
  5778. (setq neffort (org-duration-string-to-minutes effort)
  5779. effort (setq effort (concat "[" effort "]")))))
  5780. ;; prevent erroring out with %e format when there is no effort
  5781. (or effort (setq effort ""))
  5782. (when remove-re
  5783. (while (string-match remove-re txt)
  5784. (setq txt (replace-match "" t t txt))))
  5785. ;; Set org-heading property on `txt' to mark the start of the
  5786. ;; heading.
  5787. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5788. ;; Prepare the variables needed in the eval of the compiled format
  5789. (setq time (cond (s2 (concat
  5790. (org-agenda-time-of-day-to-ampm-maybe s1)
  5791. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5792. (if org-agenda-timegrid-use-ampm " ")))
  5793. (s1 (concat
  5794. (org-agenda-time-of-day-to-ampm-maybe s1)
  5795. (if org-agenda-timegrid-use-ampm
  5796. "........ "
  5797. "......")))
  5798. (t ""))
  5799. extra (or (and (not habitp) extra) "")
  5800. category (if (symbolp category) (symbol-name category) category)
  5801. thecategory (copy-sequence category))
  5802. (if (string-match org-bracket-link-regexp category)
  5803. (progn
  5804. (setq l (if (match-end 3)
  5805. (- (match-end 3) (match-beginning 3))
  5806. (- (match-end 1) (match-beginning 1))))
  5807. (when (< l (or org-prefix-category-length 0))
  5808. (setq category (copy-sequence category))
  5809. (org-add-props category nil
  5810. 'extra-space (make-string
  5811. (- org-prefix-category-length l 1) ?\ ))))
  5812. (if (and org-prefix-category-max-length
  5813. (>= (length category) org-prefix-category-max-length))
  5814. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5815. ;; Evaluate the compiled format
  5816. (setq rtn (concat (eval formatter) txt))
  5817. ;; And finally add the text properties
  5818. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5819. (org-add-props rtn nil
  5820. 'org-category (if thecategory (downcase thecategory) category)
  5821. 'tags (mapcar 'org-downcase-keep-props tags)
  5822. 'org-highest-priority org-highest-priority
  5823. 'org-lowest-priority org-lowest-priority
  5824. 'time-of-day time-of-day
  5825. 'duration duration
  5826. 'effort effort
  5827. 'effort-minutes neffort
  5828. 'txt txt
  5829. 'time time
  5830. 'extra extra
  5831. 'format org-prefix-format-compiled
  5832. 'dotime dotime)))))
  5833. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5834. "Remove tags string from TXT, and add a modified list of tags.
  5835. The modified list may contain inherited tags, and tags matched by
  5836. `org-agenda-hide-tags-regexp' will be removed."
  5837. (when (or add-inherited hide-re)
  5838. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5839. (setq txt (substring txt 0 (match-beginning 0))))
  5840. (setq tags
  5841. (delq nil
  5842. (mapcar (lambda (tg)
  5843. (if (or (and hide-re (string-match hide-re tg))
  5844. (and (not add-inherited)
  5845. (get-text-property 0 'inherited tg)))
  5846. nil
  5847. tg))
  5848. tags)))
  5849. (when tags
  5850. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5851. i)
  5852. (setq txt (concat txt " :"
  5853. (mapconcat
  5854. (lambda (x)
  5855. (setq i (get-text-property 0 'inherited x))
  5856. (if (and have-i (not i))
  5857. (progn
  5858. (setq have-i nil)
  5859. (concat ":" x))
  5860. x))
  5861. tags ":")
  5862. (if have-i "::" ":"))))))
  5863. txt)
  5864. (defun org-downcase-keep-props (s)
  5865. (let ((props (text-properties-at 0 s)))
  5866. (setq s (downcase s))
  5867. (add-text-properties 0 (length s) props s)
  5868. s))
  5869. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5870. (defvar org-agenda-sorting-strategy-selected nil)
  5871. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5872. (catch 'exit
  5873. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5874. ((and todayp (member 'today (car org-agenda-time-grid))))
  5875. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5876. ((member 'weekly (car org-agenda-time-grid)))
  5877. (t (throw 'exit list)))
  5878. (let* ((have (delq nil (mapcar
  5879. (lambda (x) (get-text-property 1 'time-of-day x))
  5880. list)))
  5881. (string (nth 1 org-agenda-time-grid))
  5882. (gridtimes (nth 2 org-agenda-time-grid))
  5883. (req (car org-agenda-time-grid))
  5884. (remove (member 'remove-match req))
  5885. new time)
  5886. (if (and (member 'require-timed req) (not have))
  5887. ;; don't show empty grid
  5888. (throw 'exit list))
  5889. (while (setq time (pop gridtimes))
  5890. (unless (and remove (member time have))
  5891. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5892. (push (org-agenda-format-item
  5893. nil string "" nil
  5894. (concat (substring time 0 -2) ":" (substring time -2)))
  5895. new)
  5896. (put-text-property
  5897. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5898. (when (and todayp org-agenda-show-current-time-in-grid)
  5899. (push (org-agenda-format-item
  5900. nil
  5901. org-agenda-current-time-string
  5902. "" nil
  5903. (format-time-string "%H:%M "))
  5904. new)
  5905. (put-text-property
  5906. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5907. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5908. (append new list)
  5909. (append list new)))))
  5910. (defun org-compile-prefix-format (key)
  5911. "Compile the prefix format into a Lisp form that can be evaluated.
  5912. The resulting form and associated variable bindings is returned
  5913. and stored in the variable `org-prefix-format-compiled'."
  5914. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5915. org-prefix-category-length nil
  5916. org-prefix-has-effort nil)
  5917. (let ((s (cond
  5918. ((stringp org-agenda-prefix-format)
  5919. org-agenda-prefix-format)
  5920. ((assq key org-agenda-prefix-format)
  5921. (cdr (assq key org-agenda-prefix-format)))
  5922. (t " %-12:c%?-12t% s")))
  5923. (start 0)
  5924. varform vars var e c f opt)
  5925. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5926. s start)
  5927. (setq var (or (cdr (assoc (match-string 4 s)
  5928. '(("c" . category) ("t" . time) ("s" . extra)
  5929. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5930. 'eval)
  5931. c (or (match-string 3 s) "")
  5932. opt (match-beginning 1)
  5933. start (1+ (match-beginning 0)))
  5934. (if (equal var 'time) (setq org-prefix-has-time t))
  5935. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5936. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5937. (setq f (concat "%" (match-string 2 s) "s"))
  5938. (when (equal var 'category)
  5939. (setq org-prefix-category-length
  5940. (floor (abs (string-to-number (match-string 2 s)))))
  5941. (setq org-prefix-category-max-length
  5942. (let ((x (match-string 2 s)))
  5943. (save-match-data
  5944. (if (string-match "\\.[0-9]+" x)
  5945. (string-to-number (substring (match-string 0 x) 1)))))))
  5946. (if (eq var 'eval)
  5947. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5948. (if opt
  5949. (setq varform
  5950. `(if (equal "" ,var)
  5951. ""
  5952. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5953. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5954. (setq s (replace-match "%s" t nil s))
  5955. (push varform vars))
  5956. (setq vars (nreverse vars))
  5957. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5958. (setq org-prefix-format-compiled
  5959. (list
  5960. `((org-prefix-has-time ,org-prefix-has-time)
  5961. (org-prefix-has-tag ,org-prefix-has-tag)
  5962. (org-prefix-category-length ,org-prefix-category-length)
  5963. (org-prefix-has-effort ,org-prefix-has-effort))
  5964. `(format ,s ,@vars))))))
  5965. (defun org-set-sorting-strategy (key)
  5966. (if (symbolp (car org-agenda-sorting-strategy))
  5967. ;; the old format
  5968. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5969. (setq org-agenda-sorting-strategy-selected
  5970. (or (cdr (assq key org-agenda-sorting-strategy))
  5971. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5972. '(time-up category-keep priority-down)))))
  5973. (defun org-get-time-of-day (s &optional string mod24)
  5974. "Check string S for a time of day.
  5975. If found, return it as a military time number between 0 and 2400.
  5976. If not found, return nil.
  5977. The optional STRING argument forces conversion into a 5 character wide string
  5978. HH:MM."
  5979. (save-match-data
  5980. (when
  5981. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5982. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5983. (let* ((h (string-to-number (match-string 1 s)))
  5984. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5985. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5986. (am-p (equal ampm "am"))
  5987. (h1 (cond ((not ampm) h)
  5988. ((= h 12) (if am-p 0 12))
  5989. (t (+ h (if am-p 0 12)))))
  5990. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5991. (mod h1 24) h1))
  5992. (t0 (+ (* 100 h2) m))
  5993. (t1 (concat (if (>= h1 24) "+" " ")
  5994. (if (and org-agenda-time-leading-zero
  5995. (< t0 1000)) "0" "")
  5996. (if (< t0 100) "0" "")
  5997. (if (< t0 10) "0" "")
  5998. (int-to-string t0))))
  5999. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6000. (defvar org-agenda-before-sorting-filter-function nil
  6001. "Function to be applied to agenda items prior to sorting.
  6002. Prior to sorting also means just before they are inserted into the agenda.
  6003. To aid sorting, you may revisit the original entries and add more text
  6004. properties which will later be used by the sorting functions.
  6005. The function should take a string argument, an agenda line.
  6006. It has access to the text properties in that line, which contain among
  6007. other things, the property `org-hd-marker' that points to the entry
  6008. where the line comes from. Note that not all lines going into the agenda
  6009. have this property, only most.
  6010. The function should return the modified string. It is probably best
  6011. to ONLY change text properties.
  6012. You can also use this function as a filter, by returning nil for lines
  6013. you don't want to have in the agenda at all. For this application, you
  6014. could bind the variable in the options section of a custom command.")
  6015. (defun org-agenda-finalize-entries (list &optional nosort)
  6016. "Sort and concatenate the agenda items."
  6017. (setq list (mapcar 'org-agenda-highlight-todo list))
  6018. (if nosort
  6019. list
  6020. (when org-agenda-before-sorting-filter-function
  6021. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  6022. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  6023. (defun org-agenda-highlight-todo (x)
  6024. (let ((org-done-keywords org-done-keywords-for-agenda)
  6025. (case-fold-search nil)
  6026. re)
  6027. (if (eq x 'line)
  6028. (save-excursion
  6029. (beginning-of-line 1)
  6030. (setq re (org-get-at-bol 'org-todo-regexp))
  6031. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6032. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6033. (add-text-properties (match-beginning 0) (match-end 1)
  6034. (list 'face (org-get-todo-face 1)))
  6035. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6036. (delete-region (match-beginning 1) (1- (match-end 0)))
  6037. (goto-char (match-beginning 1))
  6038. (insert (format org-agenda-todo-keyword-format s)))))
  6039. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6040. (setq re (get-text-property 0 'org-todo-regexp x))
  6041. (when (and re
  6042. ;; Test `pl' because if there's no heading content,
  6043. ;; there's no point matching to highlight. Note
  6044. ;; that if we didn't test `pl' first, and there
  6045. ;; happened to be no keyword from `org-todo-regexp'
  6046. ;; on this heading line, then the `equal' comparison
  6047. ;; afterwards would spuriously succeed in the case
  6048. ;; where `pl' is nil -- causing an args-out-of-range
  6049. ;; error when we try to add text properties to text
  6050. ;; that isn't there.
  6051. pl
  6052. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6053. x pl) pl))
  6054. (add-text-properties
  6055. (or (match-end 1) (match-end 0)) (match-end 0)
  6056. (list 'face (org-get-todo-face (match-string 2 x)))
  6057. x)
  6058. (when (match-end 1)
  6059. (setq x (concat (substring x 0 (match-end 1))
  6060. (format org-agenda-todo-keyword-format
  6061. (match-string 2 x))
  6062. (org-add-props " " (text-properties-at 0 x))
  6063. (substring x (match-end 3)))))))
  6064. x)))
  6065. (defsubst org-cmp-priority (a b)
  6066. "Compare the priorities of string A and B."
  6067. (let ((pa (or (get-text-property 1 'priority a) 0))
  6068. (pb (or (get-text-property 1 'priority b) 0)))
  6069. (cond ((> pa pb) +1)
  6070. ((< pa pb) -1))))
  6071. (defsubst org-cmp-effort (a b)
  6072. "Compare the effort values of string A and B."
  6073. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6074. (ea (or (get-text-property 1 'effort-minutes a) def))
  6075. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6076. (cond ((> ea eb) +1)
  6077. ((< ea eb) -1))))
  6078. (defsubst org-cmp-category (a b)
  6079. "Compare the string values of categories of strings A and B."
  6080. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6081. (cb (or (get-text-property 1 'org-category b) "")))
  6082. (cond ((string-lessp ca cb) -1)
  6083. ((string-lessp cb ca) +1))))
  6084. (defsubst org-cmp-todo-state (a b)
  6085. "Compare the todo states of strings A and B."
  6086. (let* ((ma (or (get-text-property 1 'org-marker a)
  6087. (get-text-property 1 'org-hd-marker a)))
  6088. (mb (or (get-text-property 1 'org-marker b)
  6089. (get-text-property 1 'org-hd-marker b)))
  6090. (fa (and ma (marker-buffer ma)))
  6091. (fb (and mb (marker-buffer mb)))
  6092. (todo-kwds
  6093. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6094. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6095. (ta (or (get-text-property 1 'todo-state a) ""))
  6096. (tb (or (get-text-property 1 'todo-state b) ""))
  6097. (la (- (length (member ta todo-kwds))))
  6098. (lb (- (length (member tb todo-kwds))))
  6099. (donepa (member ta org-done-keywords-for-agenda))
  6100. (donepb (member tb org-done-keywords-for-agenda)))
  6101. (cond ((and donepa (not donepb)) -1)
  6102. ((and (not donepa) donepb) +1)
  6103. ((< la lb) -1)
  6104. ((< lb la) +1))))
  6105. (defsubst org-cmp-alpha (a b)
  6106. "Compare the headlines, alphabetically."
  6107. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6108. (plb (text-property-any 0 (length b) 'org-heading t b))
  6109. (ta (and pla (substring a pla)))
  6110. (tb (and plb (substring b plb))))
  6111. (when pla
  6112. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6113. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6114. (setq ta (substring ta (match-end 0))))
  6115. (setq ta (downcase ta)))
  6116. (when plb
  6117. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6118. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6119. (setq tb (substring tb (match-end 0))))
  6120. (setq tb (downcase tb)))
  6121. (cond ((not ta) +1)
  6122. ((not tb) -1)
  6123. ((string-lessp ta tb) -1)
  6124. ((string-lessp tb ta) +1))))
  6125. (defsubst org-cmp-tag (a b)
  6126. "Compare the string values of the first tags of A and B."
  6127. (let ((ta (car (last (get-text-property 1 'tags a))))
  6128. (tb (car (last (get-text-property 1 'tags b)))))
  6129. (cond ((not ta) +1)
  6130. ((not tb) -1)
  6131. ((string-lessp ta tb) -1)
  6132. ((string-lessp tb ta) +1))))
  6133. (defsubst org-cmp-time (a b)
  6134. "Compare the time-of-day values of strings A and B."
  6135. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6136. (ta (or (get-text-property 1 'time-of-day a) def))
  6137. (tb (or (get-text-property 1 'time-of-day b) def)))
  6138. (cond ((< ta tb) -1)
  6139. ((< tb ta) +1))))
  6140. (defsubst org-cmp-habit-p (a b)
  6141. "Compare the todo states of strings A and B."
  6142. (let ((ha (get-text-property 1 'org-habit-p a))
  6143. (hb (get-text-property 1 'org-habit-p b)))
  6144. (cond ((and ha (not hb)) -1)
  6145. ((and (not ha) hb) +1))))
  6146. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  6147. (defun org-entries-lessp (a b)
  6148. "Predicate for sorting agenda entries."
  6149. ;; The following variables will be used when the form is evaluated.
  6150. ;; So even though the compiler complains, keep them.
  6151. (let* ((ss org-agenda-sorting-strategy-selected)
  6152. (time-up (and (org-em 'time-up 'time-down ss)
  6153. (org-cmp-time a b)))
  6154. (time-down (if time-up (- time-up) nil))
  6155. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6156. (org-cmp-priority a b)))
  6157. (priority-down (if priority-up (- priority-up) nil))
  6158. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6159. (org-cmp-effort a b)))
  6160. (effort-down (if effort-up (- effort-up) nil))
  6161. (category-up (and (or (org-em 'category-up 'category-down ss)
  6162. (memq 'category-keep ss))
  6163. (org-cmp-category a b)))
  6164. (category-down (if category-up (- category-up) nil))
  6165. (category-keep (if category-up +1 nil))
  6166. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6167. (org-cmp-tag a b)))
  6168. (tag-down (if tag-up (- tag-up) nil))
  6169. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6170. (org-cmp-todo-state a b)))
  6171. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6172. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6173. (org-cmp-habit-p a b)))
  6174. (habit-down (if habit-up (- habit-up) nil))
  6175. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6176. (org-cmp-alpha a b)))
  6177. (alpha-down (if alpha-up (- alpha-up) nil))
  6178. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6179. user-defined-up user-defined-down)
  6180. (if (and need-user-cmp org-agenda-cmp-user-defined
  6181. (functionp org-agenda-cmp-user-defined))
  6182. (setq user-defined-up
  6183. (funcall org-agenda-cmp-user-defined a b)
  6184. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6185. (cdr (assoc
  6186. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6187. '((-1 . t) (1 . nil) (nil . nil))))))
  6188. ;;; Agenda restriction lock
  6189. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6190. "Overlay to mark the headline to which agenda commands are restricted.")
  6191. (overlay-put org-agenda-restriction-lock-overlay
  6192. 'face 'org-agenda-restriction-lock)
  6193. (overlay-put org-agenda-restriction-lock-overlay
  6194. 'help-echo "Agendas are currently limited to this subtree.")
  6195. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6196. (defun org-agenda-set-restriction-lock (&optional type)
  6197. "Set restriction lock for agenda, to current subtree or file.
  6198. Restriction will be the file if TYPE is `file', or if type is the
  6199. universal prefix '(4), or if the cursor is before the first headline
  6200. in the file. Otherwise, restriction will be to the current subtree."
  6201. (interactive "P")
  6202. (and (equal type '(4)) (setq type 'file))
  6203. (setq type (cond
  6204. (type type)
  6205. ((org-at-heading-p) 'subtree)
  6206. ((condition-case nil (org-back-to-heading t) (error nil))
  6207. 'subtree)
  6208. (t 'file)))
  6209. (if (eq type 'subtree)
  6210. (progn
  6211. (setq org-agenda-restrict t)
  6212. (setq org-agenda-overriding-restriction 'subtree)
  6213. (put 'org-agenda-files 'org-restrict
  6214. (list (buffer-file-name (buffer-base-buffer))))
  6215. (org-back-to-heading t)
  6216. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6217. (move-marker org-agenda-restrict-begin (point))
  6218. (move-marker org-agenda-restrict-end
  6219. (save-excursion (org-end-of-subtree t)))
  6220. (message "Locking agenda restriction to subtree"))
  6221. (put 'org-agenda-files 'org-restrict
  6222. (list (buffer-file-name (buffer-base-buffer))))
  6223. (setq org-agenda-restrict nil)
  6224. (setq org-agenda-overriding-restriction 'file)
  6225. (move-marker org-agenda-restrict-begin nil)
  6226. (move-marker org-agenda-restrict-end nil)
  6227. (message "Locking agenda restriction to file"))
  6228. (setq current-prefix-arg nil)
  6229. (org-agenda-maybe-redo))
  6230. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6231. "Remove the agenda restriction lock."
  6232. (interactive "P")
  6233. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6234. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6235. (setq org-agenda-overriding-restriction nil)
  6236. (setq org-agenda-restrict nil)
  6237. (put 'org-agenda-files 'org-restrict nil)
  6238. (move-marker org-agenda-restrict-begin nil)
  6239. (move-marker org-agenda-restrict-end nil)
  6240. (setq current-prefix-arg nil)
  6241. (message "Agenda restriction lock removed")
  6242. (or noupdate (org-agenda-maybe-redo)))
  6243. (defun org-agenda-maybe-redo ()
  6244. "If there is any window showing the agenda view, update it."
  6245. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6246. (w0 (selected-window)))
  6247. (when w
  6248. (select-window w)
  6249. (org-agenda-redo)
  6250. (select-window w0)
  6251. (if org-agenda-overriding-restriction
  6252. (message "Agenda view shifted to new %s restriction"
  6253. org-agenda-overriding-restriction)
  6254. (message "Agenda restriction lock removed")))))
  6255. ;;; Agenda commands
  6256. (defun org-agenda-check-type (error &rest types)
  6257. "Check if agenda buffer is of allowed type.
  6258. If ERROR is non-nil, throw an error, otherwise just return nil.
  6259. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6260. (if (not org-agenda-type)
  6261. (error "No Org agenda currently displayed")
  6262. (if (memq org-agenda-type types)
  6263. t
  6264. (if error
  6265. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6266. nil))))
  6267. (defun org-agenda-Quit (&optional arg)
  6268. "Exit agenda by removing the window or the buffer."
  6269. (interactive)
  6270. (if org-agenda-columns-active
  6271. (org-columns-quit)
  6272. (let ((buf (current-buffer)))
  6273. (if (eq org-agenda-window-setup 'other-frame)
  6274. (progn
  6275. (org-agenda-reset-markers)
  6276. (kill-buffer buf)
  6277. (org-columns-remove-overlays)
  6278. (setq org-agenda-archives-mode nil)
  6279. (delete-frame))
  6280. (and (not (eq org-agenda-window-setup 'current-window))
  6281. (not (one-window-p))
  6282. (delete-window))
  6283. (org-agenda-reset-markers)
  6284. (kill-buffer buf)
  6285. (org-columns-remove-overlays)
  6286. (setq org-agenda-archives-mode nil)))
  6287. ;; Maybe restore the pre-agenda window configuration.
  6288. (and org-agenda-restore-windows-after-quit
  6289. (not (eq org-agenda-window-setup 'other-frame))
  6290. org-agenda-pre-window-conf
  6291. (set-window-configuration org-agenda-pre-window-conf)
  6292. (setq org-agenda-pre-window-conf nil))))
  6293. (defun org-agenda-quit ()
  6294. "Exit agenda by killing agenda buffer or burying it when
  6295. `org-agenda-sticky' is non-NIL"
  6296. (interactive)
  6297. (if (and (eq org-indirect-buffer-display 'other-window)
  6298. org-last-indirect-buffer)
  6299. (delete-window (get-buffer-window org-last-indirect-buffer)))
  6300. (if org-agenda-columns-active
  6301. (org-columns-quit)
  6302. (if org-agenda-sticky
  6303. (let ((buf (current-buffer)))
  6304. (if (eq org-agenda-window-setup 'other-frame)
  6305. (progn
  6306. (delete-frame))
  6307. (and (not (eq org-agenda-window-setup 'current-window))
  6308. (not (one-window-p))
  6309. (delete-window)))
  6310. (with-current-buffer buf
  6311. (bury-buffer)
  6312. ;; Maybe restore the pre-agenda window configuration.
  6313. (and org-agenda-restore-windows-after-quit
  6314. (not (eq org-agenda-window-setup 'other-frame))
  6315. org-agenda-pre-window-conf
  6316. (set-window-configuration org-agenda-pre-window-conf)
  6317. (setq org-agenda-pre-window-conf nil))))
  6318. (org-agenda-Quit))))
  6319. (defun org-agenda-exit ()
  6320. "Exit agenda by removing the window or the buffer.
  6321. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6322. Org-mode buffers visited directly by the user will not be touched."
  6323. (interactive)
  6324. (org-release-buffers org-agenda-new-buffers)
  6325. (setq org-agenda-new-buffers nil)
  6326. (org-agenda-Quit))
  6327. (defun org-agenda-kill-all-agenda-buffers ()
  6328. "Kill all buffers in `org-agenda-mode'.
  6329. This is used when toggling sticky agendas. You can also explicitly invoke it
  6330. with `C-c a C-k'."
  6331. (interactive)
  6332. (let (blist)
  6333. (dolist (buf (buffer-list))
  6334. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6335. (push buf blist)))
  6336. (mapc 'kill-buffer blist)))
  6337. (defun org-agenda-execute (arg)
  6338. "Execute another agenda command, keeping same window.
  6339. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6340. in the agenda."
  6341. (interactive "P")
  6342. (let ((org-agenda-window-setup 'current-window))
  6343. (org-agenda arg)))
  6344. (defun org-agenda-redo (&optional all)
  6345. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6346. (interactive "P")
  6347. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6348. (cpa (unless (eq all t) current-prefix-arg))
  6349. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6350. (org-agenda-sticky nil)
  6351. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6352. org-agenda-buffer-name))
  6353. (org-agenda-keep-modes t)
  6354. (tag-filter org-agenda-tag-filter)
  6355. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6356. (top-cat-filter org-agenda-top-category-filter)
  6357. (cat-filter org-agenda-category-filter)
  6358. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6359. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6360. (cols org-agenda-columns-active)
  6361. (line (org-current-line))
  6362. (window-line (- line (org-current-line (window-start))))
  6363. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6364. (redo-cmd (get-text-property p 'org-redo-cmd))
  6365. (last-args (get-text-property p 'org-last-args))
  6366. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6367. (org-agenda-overriding-cmd-arguments
  6368. (unless (eq all t)
  6369. (cond ((listp last-args)
  6370. (cons (or cpa (car last-args)) (cdr last-args)))
  6371. ((stringp last-args)
  6372. last-args))))
  6373. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6374. (put 'org-agenda-tag-filter :preset-filter nil)
  6375. (put 'org-agenda-category-filter :preset-filter nil)
  6376. (and cols (org-columns-quit))
  6377. (message "Rebuilding agenda buffer...")
  6378. (if series-redo-cmd
  6379. (eval series-redo-cmd)
  6380. (org-let lprops '(eval redo-cmd)))
  6381. (setq org-agenda-undo-list nil
  6382. org-agenda-pending-undo-list nil)
  6383. (message "Rebuilding agenda buffer...done")
  6384. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6385. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6386. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6387. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6388. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6389. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6390. (org-goto-line line)
  6391. (recenter window-line)))
  6392. (defvar org-global-tags-completion-table nil)
  6393. (defvar org-agenda-filter-form nil)
  6394. (defvar org-agenda-filtered-by-category nil)
  6395. (defun org-agenda-filter-by-category (strip)
  6396. "Keep only those lines in the agenda buffer that have a specific category.
  6397. The category is that of the current line."
  6398. (interactive "P")
  6399. (if (and org-agenda-filtered-by-category
  6400. org-agenda-category-filter)
  6401. (org-agenda-filter-show-all-cat)
  6402. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6403. (if cat (org-agenda-filter-apply
  6404. (list (concat (if strip "-" "+") cat)) 'category)
  6405. (error "No category at point")))))
  6406. (defun org-find-top-category (&optional pos)
  6407. (save-excursion
  6408. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6409. (if pos (goto-char pos))
  6410. ;; Skip up to the topmost parent
  6411. (while (ignore-errors (outline-up-heading 1) t))
  6412. (ignore-errors
  6413. (nth 4 (org-heading-components))))))
  6414. (defvar org-agenda-filtered-by-top-category nil)
  6415. (defun org-agenda-filter-by-top-category (strip)
  6416. "Keep only those lines in the agenda buffer that have a specific category.
  6417. The category is that of the current line."
  6418. (interactive "P")
  6419. (if org-agenda-filtered-by-top-category
  6420. (progn
  6421. (setq org-agenda-filtered-by-top-category nil
  6422. org-agenda-top-category-filter nil)
  6423. (org-agenda-filter-show-all-cat))
  6424. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6425. (if cat (org-agenda-filter-top-category-apply cat strip)
  6426. (error "No top-level category at point")))))
  6427. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6428. "Keep only those lines in the agenda buffer that have a specific tag.
  6429. The tag is selected with its fast selection letter, as configured.
  6430. With prefix argument STRIP, remove all lines that do have the tag.
  6431. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6432. used to narrow the search - the interactive user can also press `-' or `+'
  6433. to switch to narrowing."
  6434. (interactive "P")
  6435. (let* ((alist org-tag-alist-for-agenda)
  6436. (tag-chars (mapconcat
  6437. (lambda (x) (if (and (not (symbolp (car x)))
  6438. (cdr x))
  6439. (char-to-string (cdr x))
  6440. ""))
  6441. alist ""))
  6442. (efforts (org-split-string
  6443. (or (cdr (assoc (concat org-effort-property "_ALL")
  6444. org-global-properties))
  6445. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6446. "")))
  6447. (effort-op org-agenda-filter-effort-default-operator)
  6448. (effort-prompt "")
  6449. (inhibit-read-only t)
  6450. (current org-agenda-tag-filter)
  6451. maybe-refresh a n tag)
  6452. (unless char
  6453. (message
  6454. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6455. (if narrow "Narrow" "Filter") tag-chars
  6456. (if org-agenda-auto-exclude-function "[RET], " ""))
  6457. (setq char (read-char-exclusive)))
  6458. (when (member char '(?+ ?-))
  6459. ;; Narrowing down
  6460. (cond ((equal char ?-) (setq strip t narrow t))
  6461. ((equal char ?+) (setq strip nil narrow t)))
  6462. (message
  6463. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6464. (setq char (read-char-exclusive)))
  6465. (when (member char '(?< ?> ?= ??))
  6466. ;; An effort operator
  6467. (setq effort-op (char-to-string char))
  6468. (setq alist nil) ; to make sure it will be interpreted as effort.
  6469. (unless (equal char ??)
  6470. (loop for i from 0 to 9 do
  6471. (setq effort-prompt
  6472. (concat
  6473. effort-prompt " ["
  6474. (if (= i 9) "0" (int-to-string (1+ i)))
  6475. "]" (nth i efforts))))
  6476. (message "Effort%s: %s " effort-op effort-prompt)
  6477. (setq char (read-char-exclusive))
  6478. (when (or (< char ?0) (> char ?9))
  6479. (error "Need 1-9,0 to select effort"))))
  6480. (when (equal char ?\t)
  6481. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6482. (org-set-local 'org-global-tags-completion-table
  6483. (org-global-tags-completion-table)))
  6484. (let ((completion-ignore-case t))
  6485. (setq tag (org-icompleting-read
  6486. "Tag: " org-global-tags-completion-table))))
  6487. (cond
  6488. ((equal char ?\r)
  6489. (org-agenda-filter-show-all-tag)
  6490. (when org-agenda-auto-exclude-function
  6491. (setq org-agenda-tag-filter '())
  6492. (dolist (tag (org-agenda-get-represented-tags))
  6493. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6494. (if modifier
  6495. (push modifier org-agenda-tag-filter))))
  6496. (if (not (null org-agenda-tag-filter))
  6497. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6498. (setq maybe-refresh t))
  6499. ((equal char ?/)
  6500. (org-agenda-filter-show-all-tag)
  6501. (when (get 'org-agenda-tag-filter :preset-filter)
  6502. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6503. (setq maybe-refresh t))
  6504. ((equal char ?. )
  6505. (setq org-agenda-tag-filter
  6506. (mapcar (lambda(tag) (concat "+" tag))
  6507. (org-get-at-bol 'tags)))
  6508. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6509. (setq maybe-refresh t))
  6510. ((or (equal char ?\ )
  6511. (setq a (rassoc char alist))
  6512. (and (>= char ?0) (<= char ?9)
  6513. (setq n (if (= char ?0) 9 (- char ?0 1))
  6514. tag (concat effort-op (nth n efforts))
  6515. a (cons tag nil)))
  6516. (and (= char ??)
  6517. (setq tag "?eff")
  6518. a (cons tag nil))
  6519. (and tag (setq a (cons tag nil))))
  6520. (org-agenda-filter-show-all-tag)
  6521. (setq tag (car a))
  6522. (setq org-agenda-tag-filter
  6523. (cons (concat (if strip "-" "+") tag)
  6524. (if narrow current nil)))
  6525. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6526. (setq maybe-refresh t))
  6527. (t (error "Invalid tag selection character %c" char)))
  6528. (when (and maybe-refresh
  6529. (eq org-agenda-clockreport-mode 'with-filter))
  6530. (org-agenda-redo))))
  6531. (defun org-agenda-get-represented-tags ()
  6532. "Get a list of all tags currently represented in the agenda."
  6533. (let (p tags)
  6534. (save-excursion
  6535. (goto-char (point-min))
  6536. (while (setq p (next-single-property-change (point) 'tags))
  6537. (goto-char p)
  6538. (mapc (lambda (x) (add-to-list 'tags x))
  6539. (get-text-property (point) 'tags))))
  6540. tags))
  6541. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6542. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6543. (interactive "P")
  6544. (org-agenda-filter-by-tag strip char 'refine))
  6545. (defun org-agenda-filter-make-matcher ()
  6546. "Create the form that tests a line for agenda filter."
  6547. (let (f f1)
  6548. ;; first compute the tag-filter matcher
  6549. (dolist (x (delete-dups
  6550. (append (get 'org-agenda-tag-filter
  6551. :preset-filter) org-agenda-tag-filter)))
  6552. (if (member x '("-" "+"))
  6553. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6554. (if (string-match "[<=>?]" x)
  6555. (setq f1 (org-agenda-filter-effort-form x))
  6556. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6557. (if (equal (string-to-char x) ?-)
  6558. (setq f1 (list 'not f1))))
  6559. (push f1 f))
  6560. ;; then compute the category-filter matcher
  6561. (dolist (x (delete-dups
  6562. (append (get 'org-agenda-category-filter
  6563. :preset-filter) org-agenda-category-filter)))
  6564. (if (equal "-" (substring x 0 1))
  6565. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6566. (setq f1 (list 'equal (substring x 1) 'cat)))
  6567. (push f1 f))
  6568. (cons 'and (nreverse f))))
  6569. (defun org-agenda-filter-effort-form (e)
  6570. "Return the form to compare the effort of the current line with what E says.
  6571. E looks like \"+<2:25\"."
  6572. (let (op)
  6573. (setq e (substring e 1))
  6574. (setq op (string-to-char e) e (substring e 1))
  6575. (setq op (cond ((equal op ?<) '<=)
  6576. ((equal op ?>) '>=)
  6577. ((equal op ??) op)
  6578. (t '=)))
  6579. (list 'org-agenda-compare-effort (list 'quote op)
  6580. (org-duration-string-to-minutes e))))
  6581. (defun org-agenda-compare-effort (op value)
  6582. "Compare the effort of the current line with VALUE, using OP.
  6583. If the line does not have an effort defined, return nil."
  6584. (let ((eff (org-get-at-bol 'effort-minutes)))
  6585. (if (equal op ??)
  6586. (not eff)
  6587. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6588. value))))
  6589. (defun org-agenda-filter-apply (filter type)
  6590. "Set FILTER as the new agenda filter and apply it."
  6591. (let (tags cat)
  6592. (if (eq type 'tag)
  6593. (setq org-agenda-tag-filter filter)
  6594. (setq org-agenda-category-filter filter))
  6595. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6596. (if (and (eq type 'category)
  6597. (not (equal (substring (car filter) 0 1) "-")))
  6598. ;; Only set `org-agenda-filtered-by-category' to t
  6599. ;; when a unique category is used as the filter
  6600. (setq org-agenda-filtered-by-category t))
  6601. (org-agenda-set-mode-name)
  6602. (save-excursion
  6603. (goto-char (point-min))
  6604. (while (not (eobp))
  6605. (if (org-get-at-bol 'org-marker)
  6606. (progn
  6607. (setq tags (org-get-at-bol 'tags) ; used in eval
  6608. cat (get-text-property (point) 'org-category))
  6609. (if (not (eval org-agenda-filter-form))
  6610. (org-agenda-filter-hide-line type))
  6611. (beginning-of-line 2))
  6612. (beginning-of-line 2))))
  6613. (if (get-char-property (point) 'invisible)
  6614. (ignore-errors (org-agenda-previous-line)))))
  6615. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6616. "Set FILTER as the new agenda filter and apply it."
  6617. (org-agenda-set-mode-name)
  6618. (save-excursion
  6619. (goto-char (point-min))
  6620. (while (not (eobp))
  6621. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6622. (topcat (and pos (org-find-top-category pos))))
  6623. (if (and topcat (funcall (if negative 'identity 'not)
  6624. (string= category topcat)))
  6625. (org-agenda-filter-hide-line 'category)))
  6626. (beginning-of-line 2)))
  6627. (if (get-char-property (point) 'invisible)
  6628. (org-agenda-previous-line))
  6629. (setq org-agenda-top-category-filter category
  6630. org-agenda-filtered-by-top-category t))
  6631. (defun org-agenda-filter-hide-line (type)
  6632. (let (ov)
  6633. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6634. (point-at-eol)))
  6635. (overlay-put ov 'invisible t)
  6636. (overlay-put ov 'type type)
  6637. (if (eq type 'tag)
  6638. (push ov org-agenda-tag-filter-overlays)
  6639. (push ov org-agenda-cat-filter-overlays))))
  6640. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6641. (setq pos (or pos (point)))
  6642. (save-excursion
  6643. (dolist (ov (overlays-at pos))
  6644. (when (and (overlay-get ov 'invisible)
  6645. (eq (overlay-get ov 'type) 'tag))
  6646. (goto-char pos)
  6647. (if (< (overlay-start ov) (point-at-eol))
  6648. (move-overlay ov (point-at-eol)
  6649. (overlay-end ov)))))))
  6650. (defun org-agenda-filter-show-all-tag nil
  6651. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6652. (setq org-agenda-tag-filter-overlays nil
  6653. org-agenda-tag-filter nil
  6654. org-agenda-filter-form nil)
  6655. (org-agenda-set-mode-name))
  6656. (defun org-agenda-filter-show-all-cat nil
  6657. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6658. (setq org-agenda-cat-filter-overlays nil
  6659. org-agenda-filtered-by-category nil
  6660. org-agenda-category-filter nil
  6661. org-agenda-filter-form nil)
  6662. (org-agenda-set-mode-name))
  6663. (defun org-agenda-manipulate-query-add ()
  6664. "Manipulate the query by adding a search term with positive selection.
  6665. Positive selection means the term must be matched for selection of an entry."
  6666. (interactive)
  6667. (org-agenda-manipulate-query ?\[))
  6668. (defun org-agenda-manipulate-query-subtract ()
  6669. "Manipulate the query by adding a search term with negative selection.
  6670. Negative selection means term must not be matched for selection of an entry."
  6671. (interactive)
  6672. (org-agenda-manipulate-query ?\]))
  6673. (defun org-agenda-manipulate-query-add-re ()
  6674. "Manipulate the query by adding a search regexp with positive selection.
  6675. Positive selection means the regexp must match for selection of an entry."
  6676. (interactive)
  6677. (org-agenda-manipulate-query ?\{))
  6678. (defun org-agenda-manipulate-query-subtract-re ()
  6679. "Manipulate the query by adding a search regexp with negative selection.
  6680. Negative selection means regexp must not match for selection of an entry."
  6681. (interactive)
  6682. (org-agenda-manipulate-query ?\}))
  6683. (defun org-agenda-manipulate-query (char)
  6684. (cond
  6685. ((memq org-agenda-type '(timeline agenda))
  6686. (let ((org-agenda-include-inactive-timestamps t))
  6687. (org-agenda-redo))
  6688. (message "Display now includes inactive timestamps as well"))
  6689. ((eq org-agenda-type 'search)
  6690. (org-add-to-string
  6691. 'org-agenda-query-string
  6692. (if org-agenda-last-search-view-search-was-boolean
  6693. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6694. (?\{ . " +{}") (?\} . " -{}"))))
  6695. " "))
  6696. (setq org-agenda-redo-command
  6697. (list 'org-search-view
  6698. (car (get-text-property (min (1- (point-max)) (point))
  6699. 'org-last-args))
  6700. org-agenda-query-string
  6701. (+ (length org-agenda-query-string)
  6702. (if (member char '(?\{ ?\})) 0 1))))
  6703. (set-register org-agenda-query-register org-agenda-query-string)
  6704. (let ((org-agenda-overriding-arguments
  6705. (cdr org-agenda-redo-command)))
  6706. (org-agenda-redo)))
  6707. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6708. org-agenda-type))))
  6709. (defun org-add-to-string (var string)
  6710. (set var (concat (symbol-value var) string)))
  6711. (defun org-agenda-goto-date (span)
  6712. "Jump to DATE in agenda."
  6713. (interactive "P")
  6714. (let* ((org-read-date-prefer-future
  6715. (eval org-agenda-jump-prefer-future))
  6716. (date (org-read-date))
  6717. (org-agenda-sticky-orig org-agenda-sticky)
  6718. (org-agenda-buffer-tmp-name (buffer-name))
  6719. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6720. (0-arg (or current-prefix-arg (car args)))
  6721. (2-arg (nth 2 args))
  6722. (newcmd (list 'org-agenda-list 0-arg date
  6723. (org-agenda-span-to-ndays 2-arg)))
  6724. (newargs (cdr newcmd))
  6725. (inhibit-read-only t)
  6726. org-agenda-sticky)
  6727. (if (not (org-agenda-check-type t 'agenda))
  6728. (error "Not available in non-agenda blocks")
  6729. (add-text-properties (point-min) (point-max)
  6730. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6731. (org-agenda-redo)
  6732. (setq org-agenda-sticky org-agenda-sticky-orig
  6733. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6734. (defun org-agenda-goto-today ()
  6735. "Go to today."
  6736. (interactive)
  6737. (org-agenda-check-type t 'timeline 'agenda)
  6738. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6739. (curspan (nth 2 args))
  6740. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6741. (cond
  6742. (tdpos (goto-char tdpos))
  6743. ((eq org-agenda-type 'agenda)
  6744. (let* ((sd (org-agenda-compute-starting-span
  6745. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6746. (org-agenda-overriding-arguments args))
  6747. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6748. (org-agenda-redo)
  6749. (org-agenda-find-same-or-today-or-agenda)))
  6750. (t (error "Cannot find today")))))
  6751. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6752. (goto-char
  6753. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6754. (text-property-any (point-min) (point-max) 'org-today t)
  6755. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6756. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  6757. (org-agenda-goto-block-beginning))
  6758. (point-min))))
  6759. (defun org-agenda-goto-block-beginning ()
  6760. "Go the agenda block beginning."
  6761. (interactive)
  6762. (if (not (derived-mode-p 'org-agenda-mode))
  6763. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6764. (let (dest)
  6765. (save-excursion
  6766. (unless (looking-at "\\'")
  6767. (forward-char))
  6768. (let* ((prop 'org-agenda-structural-header)
  6769. (p (previous-single-property-change (point) prop))
  6770. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6771. (1- (point))) prop)))
  6772. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6773. (if (not dest)
  6774. (error "Cannot find the beginning of the blog")
  6775. (goto-char dest)
  6776. (move-beginning-of-line 1)))))
  6777. (defun org-agenda-later (arg)
  6778. "Go forward in time by the current span.
  6779. With prefix ARG, go forward that many times the current span."
  6780. (interactive "p")
  6781. (org-agenda-check-type t 'agenda)
  6782. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6783. (span (or (nth 2 args) org-agenda-current-span))
  6784. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6785. (greg (calendar-gregorian-from-absolute sd))
  6786. (cnt (org-get-at-bol 'org-day-cnt))
  6787. greg2)
  6788. (cond
  6789. ((numberp span)
  6790. (setq sd (+ (* span arg) sd)))
  6791. ((eq span 'day)
  6792. (setq sd (+ arg sd)))
  6793. ((eq span 'week)
  6794. (setq sd (+ (* 7 arg) sd)))
  6795. ((eq span 'month)
  6796. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6797. sd (calendar-absolute-from-gregorian greg2))
  6798. (setcar greg2 (1+ (car greg2))))
  6799. ((eq span 'year)
  6800. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6801. sd (calendar-absolute-from-gregorian greg2))
  6802. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6803. (t
  6804. (setq sd (+ (* span arg) sd))))
  6805. (let ((org-agenda-overriding-cmd
  6806. ;; `cmd' may have been set by `org-agenda-run-series' which
  6807. ;; uses `org-agenda-overriding-cmd' to decide whether
  6808. ;; overriding is allowed for `cmd'
  6809. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  6810. (org-agenda-overriding-arguments
  6811. (list (car args) sd span)))
  6812. (org-agenda-redo)
  6813. (org-agenda-find-same-or-today-or-agenda cnt))))
  6814. (defun org-agenda-earlier (arg)
  6815. "Go backward in time by the current span.
  6816. With prefix ARG, go backward that many times the current span."
  6817. (interactive "p")
  6818. (org-agenda-later (- arg)))
  6819. (defun org-agenda-view-mode-dispatch ()
  6820. "Call one of the view mode commands."
  6821. (interactive)
  6822. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6823. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6824. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6825. (let ((a (read-char-exclusive)))
  6826. (case a
  6827. (?\ (call-interactively 'org-agenda-reset-view))
  6828. (?d (call-interactively 'org-agenda-day-view))
  6829. (?w (call-interactively 'org-agenda-week-view))
  6830. (?m (call-interactively 'org-agenda-month-view))
  6831. (?y (call-interactively 'org-agenda-year-view))
  6832. (?l (call-interactively 'org-agenda-log-mode))
  6833. (?L (org-agenda-log-mode '(4)))
  6834. (?c (org-agenda-log-mode 'clockcheck))
  6835. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6836. (?a (call-interactively 'org-agenda-archives-mode))
  6837. (?A (org-agenda-archives-mode 'files))
  6838. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6839. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6840. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6841. (?D (call-interactively 'org-agenda-toggle-diary))
  6842. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6843. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6844. (org-agenda-check-type t 'timeline 'agenda)
  6845. (org-agenda-redo))
  6846. (message "Display now includes inactive timestamps as well"))
  6847. (?q (message "Abort"))
  6848. (otherwise (error "Invalid key" )))))
  6849. (defun org-agenda-reset-view ()
  6850. "Switch to default view for agenda."
  6851. (interactive)
  6852. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6853. (defun org-agenda-day-view (&optional day-of-year)
  6854. "Switch to daily view for agenda.
  6855. With argument DAY-OF-YEAR, switch to that day of the year."
  6856. (interactive "P")
  6857. (org-agenda-change-time-span 'day day-of-year))
  6858. (defun org-agenda-week-view (&optional iso-week)
  6859. "Switch to daily view for agenda.
  6860. With argument ISO-WEEK, switch to the corresponding ISO week.
  6861. If ISO-WEEK has more then 2 digits, only the last two encode the
  6862. week. Any digits before this encode a year. So 200712 means
  6863. week 12 of year 2007. Years in the range 1938-2037 can also be
  6864. written as 2-digit years."
  6865. (interactive "P")
  6866. (org-agenda-change-time-span 'week iso-week))
  6867. (defun org-agenda-month-view (&optional month)
  6868. "Switch to monthly view for agenda.
  6869. With argument MONTH, switch to that month."
  6870. (interactive "P")
  6871. (org-agenda-change-time-span 'month month))
  6872. (defun org-agenda-year-view (&optional year)
  6873. "Switch to yearly view for agenda.
  6874. With argument YEAR, switch to that year.
  6875. If MONTH has more then 2 digits, only the last two encode the
  6876. month. Any digits before this encode a year. So 200712 means
  6877. December year 2007. Years in the range 1938-2037 can also be
  6878. written as 2-digit years."
  6879. (interactive "P")
  6880. (when year
  6881. (setq year (org-small-year-to-year year)))
  6882. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6883. (org-agenda-change-time-span 'year year)
  6884. (error "Abort")))
  6885. (defun org-agenda-change-time-span (span &optional n)
  6886. "Change the agenda view to SPAN.
  6887. SPAN may be `day', `week', `month', `year'."
  6888. (org-agenda-check-type t 'agenda)
  6889. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6890. (curspan (nth 2 args)))
  6891. (if (and (not n) (equal curspan span))
  6892. (error "Viewing span is already \"%s\"" span))
  6893. (let* ((sd (or (org-get-at-bol 'day)
  6894. (nth 1 args)
  6895. org-starting-day))
  6896. (sd (org-agenda-compute-starting-span sd span n))
  6897. (org-agenda-overriding-cmd
  6898. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  6899. (org-agenda-overriding-arguments
  6900. (list (car args) sd span)))
  6901. (org-agenda-redo)
  6902. (org-agenda-find-same-or-today-or-agenda))
  6903. (org-agenda-set-mode-name)
  6904. (message "Switched to %s view" span)))
  6905. (defun org-agenda-compute-starting-span (sd span &optional n)
  6906. "Compute starting date for agenda.
  6907. SPAN may be `day', `week', `month', `year'. The return value
  6908. is a cons cell with the starting date and the number of days,
  6909. so that the date SD will be in that range."
  6910. (let* ((greg (calendar-gregorian-from-absolute sd))
  6911. (dg (nth 1 greg))
  6912. (mg (car greg))
  6913. (yg (nth 2 greg)))
  6914. (cond
  6915. ((eq span 'day)
  6916. (when n
  6917. (setq sd (+ (calendar-absolute-from-gregorian
  6918. (list mg 1 yg))
  6919. n -1))))
  6920. ((eq span 'week)
  6921. (let* ((nt (calendar-day-of-week
  6922. (calendar-gregorian-from-absolute sd)))
  6923. (d (if org-agenda-start-on-weekday
  6924. (- nt org-agenda-start-on-weekday)
  6925. 0))
  6926. y1)
  6927. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6928. (when n
  6929. (require 'cal-iso)
  6930. (when (> n 99)
  6931. (setq y1 (org-small-year-to-year (/ n 100))
  6932. n (mod n 100)))
  6933. (setq sd
  6934. (calendar-absolute-from-iso
  6935. (list n 1
  6936. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6937. ((eq span 'month)
  6938. (let (y1)
  6939. (when (and n (> n 99))
  6940. (setq y1 (org-small-year-to-year (/ n 100))
  6941. n (mod n 100)))
  6942. (setq sd (calendar-absolute-from-gregorian
  6943. (list (or n mg) 1 (or y1 yg))))))
  6944. ((eq span 'year)
  6945. (setq sd (calendar-absolute-from-gregorian
  6946. (list 1 1 (or n yg))))))
  6947. sd))
  6948. (defun org-agenda-next-date-line (&optional arg)
  6949. "Jump to the next line indicating a date in agenda buffer."
  6950. (interactive "p")
  6951. (org-agenda-check-type t 'agenda 'timeline)
  6952. (beginning-of-line 1)
  6953. ;; This does not work if user makes date format that starts with a blank
  6954. (if (looking-at "^\\S-") (forward-char 1))
  6955. (if (not (re-search-forward "^\\S-" nil t arg))
  6956. (progn
  6957. (backward-char 1)
  6958. (error "No next date after this line in this buffer")))
  6959. (goto-char (match-beginning 0)))
  6960. (defun org-agenda-previous-date-line (&optional arg)
  6961. "Jump to the previous line indicating a date in agenda buffer."
  6962. (interactive "p")
  6963. (org-agenda-check-type t 'agenda 'timeline)
  6964. (beginning-of-line 1)
  6965. (if (not (re-search-backward "^\\S-" nil t arg))
  6966. (error "No previous date before this line in this buffer")))
  6967. ;; Initialize the highlight
  6968. (defvar org-hl (make-overlay 1 1))
  6969. (overlay-put org-hl 'face 'highlight)
  6970. (defun org-highlight (begin end &optional buffer)
  6971. "Highlight a region with overlay."
  6972. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6973. (defun org-unhighlight ()
  6974. "Detach overlay INDEX."
  6975. (org-detach-overlay org-hl))
  6976. (defun org-unhighlight-once ()
  6977. "Remove the highlight from its position, and this function from the hook."
  6978. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6979. (org-unhighlight))
  6980. (defvar org-agenda-pre-follow-window-conf nil)
  6981. (defun org-agenda-follow-mode ()
  6982. "Toggle follow mode in an agenda buffer."
  6983. (interactive)
  6984. (unless org-agenda-follow-mode
  6985. (setq org-agenda-pre-follow-window-conf
  6986. (current-window-configuration)))
  6987. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6988. (unless org-agenda-follow-mode
  6989. (set-window-configuration org-agenda-pre-follow-window-conf))
  6990. (org-agenda-set-mode-name)
  6991. (org-agenda-do-context-action)
  6992. (message "Follow mode is %s"
  6993. (if org-agenda-follow-mode "on" "off")))
  6994. (defun org-agenda-entry-text-mode (&optional arg)
  6995. "Toggle entry text mode in an agenda buffer."
  6996. (interactive "P")
  6997. (setq org-agenda-entry-text-mode (or (integerp arg)
  6998. (not org-agenda-entry-text-mode)))
  6999. (org-agenda-entry-text-hide)
  7000. (and org-agenda-entry-text-mode
  7001. (let ((org-agenda-entry-text-maxlines
  7002. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7003. (org-agenda-entry-text-show)))
  7004. (org-agenda-set-mode-name)
  7005. (message "Entry text mode is %s. Maximum number of lines is %d"
  7006. (if org-agenda-entry-text-mode "on" "off")
  7007. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7008. (defun org-agenda-clockreport-mode (&optional with-filter)
  7009. "Toggle clocktable mode in an agenda buffer.
  7010. With prefix arg WITH-FILTER, make the clocktable respect the current
  7011. agenda filter."
  7012. (interactive "P")
  7013. (org-agenda-check-type t 'agenda)
  7014. (if with-filter
  7015. (setq org-agenda-clockreport-mode 'with-filter)
  7016. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7017. (org-agenda-set-mode-name)
  7018. (org-agenda-redo)
  7019. (message "Clocktable mode is %s"
  7020. (if org-agenda-clockreport-mode "on" "off")))
  7021. (defun org-agenda-log-mode (&optional special)
  7022. "Toggle log mode in an agenda buffer.
  7023. With argument SPECIAL, show all possible log items, not only the ones
  7024. configured in `org-agenda-log-mode-items'.
  7025. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7026. (interactive "P")
  7027. (org-agenda-check-type t 'agenda 'timeline)
  7028. (setq org-agenda-show-log
  7029. (cond
  7030. ((equal special '(16)) 'only)
  7031. ((eq special 'clockcheck)
  7032. (if (eq org-agenda-show-log 'clockcheck)
  7033. nil 'clockcheck))
  7034. (special '(closed clock state))
  7035. (t (not org-agenda-show-log))))
  7036. (org-agenda-set-mode-name)
  7037. (org-agenda-redo)
  7038. (message "Log mode is %s"
  7039. (if org-agenda-show-log "on" "off")))
  7040. (defun org-agenda-archives-mode (&optional with-files)
  7041. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7042. When called with a prefix argument, include all archive files as well."
  7043. (interactive "P")
  7044. (setq org-agenda-archives-mode
  7045. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7046. (org-agenda-set-mode-name)
  7047. (org-agenda-redo)
  7048. (message
  7049. "%s"
  7050. (cond
  7051. ((eq org-agenda-archives-mode nil)
  7052. "No archives are included")
  7053. ((eq org-agenda-archives-mode 'trees)
  7054. (format "Trees with :%s: tag are included" org-archive-tag))
  7055. ((eq org-agenda-archives-mode t)
  7056. (format "Trees with :%s: tag and all active archive files are included"
  7057. org-archive-tag)))))
  7058. (defun org-agenda-toggle-diary ()
  7059. "Toggle diary inclusion in an agenda buffer."
  7060. (interactive)
  7061. (org-agenda-check-type t 'agenda)
  7062. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7063. (org-agenda-redo)
  7064. (org-agenda-set-mode-name)
  7065. (message "Diary inclusion turned %s"
  7066. (if org-agenda-include-diary "on" "off")))
  7067. (defun org-agenda-toggle-deadlines ()
  7068. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7069. (interactive)
  7070. (org-agenda-check-type t 'agenda)
  7071. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7072. (org-agenda-redo)
  7073. (org-agenda-set-mode-name)
  7074. (message "Deadlines inclusion turned %s"
  7075. (if org-agenda-include-deadlines "on" "off")))
  7076. (defun org-agenda-toggle-time-grid ()
  7077. "Toggle time grid in an agenda buffer."
  7078. (interactive)
  7079. (org-agenda-check-type t 'agenda)
  7080. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7081. (org-agenda-redo)
  7082. (org-agenda-set-mode-name)
  7083. (message "Time-grid turned %s"
  7084. (if org-agenda-use-time-grid "on" "off")))
  7085. (defun org-agenda-set-mode-name ()
  7086. "Set the mode name to indicate all the small mode settings."
  7087. (setq mode-name
  7088. (list "Org-Agenda"
  7089. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7090. " "
  7091. '(:eval (org-agenda-span-name org-agenda-current-span))
  7092. (if org-agenda-follow-mode " Follow" "")
  7093. (if org-agenda-entry-text-mode " ETxt" "")
  7094. (if org-agenda-include-diary " Diary" "")
  7095. (if org-agenda-include-deadlines " Ddl" "")
  7096. (if org-agenda-use-time-grid " Grid" "")
  7097. (if (and (boundp 'org-habit-show-habits)
  7098. org-habit-show-habits) " Habit" "")
  7099. (cond
  7100. ((consp org-agenda-show-log) " LogAll")
  7101. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7102. (org-agenda-show-log " Log")
  7103. (t ""))
  7104. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7105. :preset-filter))
  7106. '(:eval (org-propertize
  7107. (concat " <"
  7108. (mapconcat
  7109. 'identity
  7110. (append
  7111. (get 'org-agenda-category-filter :preset-filter)
  7112. org-agenda-category-filter)
  7113. "")
  7114. ">")
  7115. 'face 'org-agenda-filter-category
  7116. 'help-echo "Category used in filtering"))
  7117. "")
  7118. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7119. :preset-filter))
  7120. '(:eval (org-propertize
  7121. (concat " {"
  7122. (mapconcat
  7123. 'identity
  7124. (append
  7125. (get 'org-agenda-tag-filter :preset-filter)
  7126. org-agenda-tag-filter)
  7127. "")
  7128. "}")
  7129. 'face 'org-agenda-filter-tags
  7130. 'help-echo "Tags used in filtering"))
  7131. "")
  7132. (if org-agenda-archives-mode
  7133. (if (eq org-agenda-archives-mode t)
  7134. " Archives"
  7135. (format " :%s:" org-archive-tag))
  7136. "")
  7137. (if org-agenda-clockreport-mode
  7138. (if (eq org-agenda-clockreport-mode 'with-filter)
  7139. " Clock{}" " Clock")
  7140. "")))
  7141. (force-mode-line-update))
  7142. (org-define-obsolete-function-alias
  7143. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7144. (defun org-agenda-update-agenda-type ()
  7145. "Update the agenda type after each command."
  7146. (setq org-agenda-type
  7147. (or (get-text-property (point) 'org-agenda-type)
  7148. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7149. (defun org-agenda-next-line ()
  7150. "Move cursor to the next line, and show if follow mode is active."
  7151. (interactive)
  7152. (call-interactively 'next-line)
  7153. (org-agenda-do-context-action))
  7154. (defun org-agenda-previous-line ()
  7155. "Move cursor to the previous line, and show if follow-mode is active."
  7156. (interactive)
  7157. (call-interactively 'previous-line)
  7158. (org-agenda-do-context-action))
  7159. (defun org-agenda-next-item (n)
  7160. "Move cursor to next agenda item."
  7161. (interactive "p")
  7162. (let ((col (current-column)))
  7163. (dotimes (c n)
  7164. (when (next-single-property-change (point-at-eol) 'org-marker)
  7165. (move-end-of-line 1)
  7166. (goto-char (next-single-property-change (point) 'org-marker))))
  7167. (org-move-to-column col))
  7168. (org-agenda-do-context-action))
  7169. (defun org-agenda-previous-item (n)
  7170. "Move cursor to next agenda item."
  7171. (interactive "p")
  7172. (dotimes (c n)
  7173. (let ((col (current-column))
  7174. (goto (save-excursion
  7175. (move-end-of-line 0)
  7176. (previous-single-property-change (point) 'org-marker))))
  7177. (if goto (goto-char goto))
  7178. (org-move-to-column col)))
  7179. (org-agenda-do-context-action))
  7180. (defun org-agenda-do-context-action ()
  7181. "Show outline path and, maybe, follow mode window."
  7182. (let ((m (org-get-at-bol 'org-marker)))
  7183. (when (and (markerp m) (marker-buffer m))
  7184. (and org-agenda-follow-mode
  7185. (if org-agenda-follow-indirect
  7186. (org-agenda-tree-to-indirect-buffer nil)
  7187. (org-agenda-show)))
  7188. (and org-agenda-show-outline-path
  7189. (org-with-point-at m (org-display-outline-path t))))))
  7190. (defun org-agenda-show-tags ()
  7191. "Show the tags applicable to the current item."
  7192. (interactive)
  7193. (let* ((tags (org-get-at-bol 'tags)))
  7194. (if tags
  7195. (message "Tags are :%s:"
  7196. (org-no-properties (mapconcat 'identity tags ":")))
  7197. (message "No tags associated with this line"))))
  7198. (defun org-agenda-goto (&optional highlight)
  7199. "Go to the Org-mode file which contains the item at point."
  7200. (interactive)
  7201. (let* ((marker (or (org-get-at-bol 'org-marker)
  7202. (org-agenda-error)))
  7203. (buffer (marker-buffer marker))
  7204. (pos (marker-position marker)))
  7205. (switch-to-buffer-other-window buffer)
  7206. (widen)
  7207. (push-mark)
  7208. (goto-char pos)
  7209. (when (derived-mode-p 'org-mode)
  7210. (org-show-context 'agenda)
  7211. (save-excursion
  7212. (and (outline-next-heading)
  7213. (org-flag-heading nil)))) ; show the next heading
  7214. (when (outline-invisible-p)
  7215. (show-entry)) ; display invisible text
  7216. (recenter (/ (window-height) 2))
  7217. (run-hooks 'org-agenda-after-show-hook)
  7218. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7219. (defvar org-agenda-after-show-hook nil
  7220. "Normal hook run after an item has been shown from the agenda.
  7221. Point is in the buffer where the item originated.")
  7222. (defun org-agenda-kill ()
  7223. "Kill the entry or subtree belonging to the current agenda entry."
  7224. (interactive)
  7225. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7226. (let* ((bufname-orig (buffer-name))
  7227. (marker (or (org-get-at-bol 'org-marker)
  7228. (org-agenda-error)))
  7229. (buffer (marker-buffer marker))
  7230. (pos (marker-position marker))
  7231. (type (org-get-at-bol 'type))
  7232. dbeg dend (n 0) conf)
  7233. (org-with-remote-undo buffer
  7234. (with-current-buffer buffer
  7235. (save-excursion
  7236. (goto-char pos)
  7237. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7238. (setq dbeg (progn (org-back-to-heading t) (point))
  7239. dend (org-end-of-subtree t t))
  7240. (setq dbeg (point-at-bol)
  7241. dend (min (point-max) (1+ (point-at-eol)))))
  7242. (goto-char dbeg)
  7243. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7244. (setq conf (or (eq t org-agenda-confirm-kill)
  7245. (and (numberp org-agenda-confirm-kill)
  7246. (> n org-agenda-confirm-kill))))
  7247. (and conf
  7248. (not (y-or-n-p
  7249. (format "Delete entry with %d lines in buffer \"%s\"? "
  7250. n (buffer-name buffer))))
  7251. (error "Abort"))
  7252. (let ((org-agenda-buffer-name bufname-orig))
  7253. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7254. (with-current-buffer buffer (delete-region dbeg dend))
  7255. (message "Agenda item and source killed"))))
  7256. (defvar org-archive-default-command) ; defined in org-archive.el
  7257. (defun org-agenda-archive-default ()
  7258. "Archive the entry or subtree belonging to the current agenda entry."
  7259. (interactive)
  7260. (require 'org-archive)
  7261. (org-agenda-archive-with org-archive-default-command))
  7262. (defun org-agenda-archive-default-with-confirmation ()
  7263. "Archive the entry or subtree belonging to the current agenda entry."
  7264. (interactive)
  7265. (require 'org-archive)
  7266. (org-agenda-archive-with org-archive-default-command 'confirm))
  7267. (defun org-agenda-archive ()
  7268. "Archive the entry or subtree belonging to the current agenda entry."
  7269. (interactive)
  7270. (org-agenda-archive-with 'org-archive-subtree))
  7271. (defun org-agenda-archive-to-archive-sibling ()
  7272. "Move the entry to the archive sibling."
  7273. (interactive)
  7274. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7275. (defun org-agenda-archive-with (cmd &optional confirm)
  7276. "Move the entry to the archive sibling."
  7277. (interactive)
  7278. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7279. (let* ((bufname-orig (buffer-name))
  7280. (marker (or (org-get-at-bol 'org-marker)
  7281. (org-agenda-error)))
  7282. (buffer (marker-buffer marker))
  7283. (pos (marker-position marker)))
  7284. (org-with-remote-undo buffer
  7285. (with-current-buffer buffer
  7286. (if (derived-mode-p 'org-mode)
  7287. (if (and confirm
  7288. (not (y-or-n-p "Archive this subtree or entry? ")))
  7289. (error "Abort")
  7290. (save-excursion
  7291. (goto-char pos)
  7292. (let ((org-agenda-buffer-name bufname-orig))
  7293. (org-remove-subtree-entries-from-agenda))
  7294. (org-back-to-heading t)
  7295. (funcall cmd)))
  7296. (error "Archiving works only in Org-mode files"))))))
  7297. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7298. "Remove all lines in the agenda that correspond to a given subtree.
  7299. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7300. If this information is not given, the function uses the tree at point."
  7301. (let ((buf (or buf (current-buffer))) m p)
  7302. (save-excursion
  7303. (unless (and beg end)
  7304. (org-back-to-heading t)
  7305. (setq beg (point))
  7306. (org-end-of-subtree t)
  7307. (setq end (point)))
  7308. (set-buffer (get-buffer org-agenda-buffer-name))
  7309. (save-excursion
  7310. (goto-char (point-max))
  7311. (beginning-of-line 1)
  7312. (while (not (bobp))
  7313. (when (and (setq m (org-get-at-bol 'org-marker))
  7314. (equal buf (marker-buffer m))
  7315. (setq p (marker-position m))
  7316. (>= p beg)
  7317. (< p end))
  7318. (let ((inhibit-read-only t))
  7319. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7320. (beginning-of-line 0))))))
  7321. (defun org-agenda-refile (&optional goto rfloc no-update)
  7322. "Refile the item at point."
  7323. (interactive "P")
  7324. (if (equal goto '(16))
  7325. (org-refile-goto-last-stored)
  7326. (let* ((buffer-orig (buffer-name))
  7327. (marker (or (org-get-at-bol 'org-hd-marker)
  7328. (org-agenda-error)))
  7329. (buffer (marker-buffer marker))
  7330. (pos (marker-position marker))
  7331. (rfloc (or rfloc
  7332. (org-refile-get-location
  7333. (if goto "Goto" "Refile to") buffer
  7334. org-refile-allow-creating-parent-nodes))))
  7335. (with-current-buffer buffer
  7336. (save-excursion
  7337. (save-restriction
  7338. (widen)
  7339. (goto-char marker)
  7340. (let ((org-agenda-buffer-name buffer-orig))
  7341. (org-remove-subtree-entries-from-agenda))
  7342. (org-refile goto buffer rfloc)))))
  7343. (unless no-update (org-agenda-redo))))
  7344. (defun org-agenda-open-link (&optional arg)
  7345. "Open the link(s) in the current entry, if any.
  7346. This looks for a link in the displayed line in the agenda.
  7347. It also looks at the text of the entry itself."
  7348. (interactive "P")
  7349. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7350. (org-get-at-bol 'org-marker)))
  7351. (buffer (and marker (marker-buffer marker)))
  7352. (prefix (buffer-substring
  7353. (point-at-bol) (point-at-eol)))
  7354. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7355. (lk (car lkall))
  7356. (lkend (cdr lkall))
  7357. trg)
  7358. (cond
  7359. ((and buffer (stringp lk))
  7360. (with-current-buffer buffer
  7361. (setq trg (and (string-match org-bracket-link-regexp lk)
  7362. (match-string 1 lk)))
  7363. (if (or (not trg) (string-match org-any-link-re trg))
  7364. (save-excursion
  7365. (save-restriction
  7366. (widen)
  7367. (goto-char marker)
  7368. (when (search-forward lk nil lkend)
  7369. (goto-char (match-beginning 0))
  7370. (org-open-at-point))))
  7371. ;; This is an internal link, widen the buffer
  7372. (switch-to-buffer-other-window buffer)
  7373. (widen)
  7374. (goto-char marker)
  7375. (when (search-forward lk nil lkend)
  7376. (goto-char (match-beginning 0))
  7377. (org-open-at-point)))))
  7378. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7379. (save-excursion
  7380. (beginning-of-line 1)
  7381. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7382. (org-open-link-from-string (match-string 1)))
  7383. (t (message "No link to open here")))))
  7384. (defun org-agenda-copy-local-variable (var)
  7385. "Get a variable from a referenced buffer and install it here."
  7386. (let ((m (org-get-at-bol 'org-marker)))
  7387. (when (and m (buffer-live-p (marker-buffer m)))
  7388. (org-set-local var (with-current-buffer (marker-buffer m)
  7389. (symbol-value var))))))
  7390. (defun org-agenda-switch-to (&optional delete-other-windows)
  7391. "Go to the Org-mode file which contains the item at point."
  7392. (interactive)
  7393. (if (and org-return-follows-link
  7394. (not (org-get-at-bol 'org-marker))
  7395. (org-in-regexp org-bracket-link-regexp))
  7396. (org-open-link-from-string (match-string 0))
  7397. (let* ((marker (or (org-get-at-bol 'org-marker)
  7398. (org-agenda-error)))
  7399. (buffer (marker-buffer marker))
  7400. (pos (marker-position marker)))
  7401. (org-pop-to-buffer-same-window buffer)
  7402. (and delete-other-windows (delete-other-windows))
  7403. (widen)
  7404. (goto-char pos)
  7405. (when (derived-mode-p 'org-mode)
  7406. (org-show-context 'agenda)
  7407. (save-excursion
  7408. (and (outline-next-heading)
  7409. (org-flag-heading nil))) ; show the next heading
  7410. (when (outline-invisible-p)
  7411. (show-entry)) ; display invisible text
  7412. (run-hooks 'org-agenda-after-show-hook)))))
  7413. (defun org-agenda-goto-mouse (ev)
  7414. "Go to the Org-mode file which contains the item at the mouse click."
  7415. (interactive "e")
  7416. (mouse-set-point ev)
  7417. (org-agenda-goto))
  7418. (defun org-agenda-show (&optional full-entry)
  7419. "Display the Org-mode file which contains the item at point.
  7420. With prefix argument FULL-ENTRY, make the entire entry visible
  7421. if it was hidden in the outline."
  7422. (interactive "P")
  7423. (let ((win (selected-window)))
  7424. (if full-entry
  7425. (let ((org-show-entry-below t))
  7426. (org-agenda-goto t))
  7427. (org-agenda-goto t))
  7428. (select-window win)))
  7429. (defvar org-agenda-show-window nil)
  7430. (defun org-agenda-show-and-scroll-up (&optional arg)
  7431. "Display the Org-mode file which contains the item at point.
  7432. When called repeatedly, scroll the window that is displaying the buffer.
  7433. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7434. `show-subtree' to display the item, so that drawers and logbooks stay
  7435. folded."
  7436. (interactive "P")
  7437. (let ((win (selected-window)))
  7438. (if (and (window-live-p org-agenda-show-window)
  7439. (eq this-command last-command))
  7440. (progn
  7441. (select-window org-agenda-show-window)
  7442. (ignore-errors (scroll-up)))
  7443. (org-agenda-goto t)
  7444. (if arg (org-show-entry) (show-subtree))
  7445. (setq org-agenda-show-window (selected-window)))
  7446. (select-window win)))
  7447. (defun org-agenda-show-scroll-down ()
  7448. "Scroll down the window showing the agenda."
  7449. (interactive)
  7450. (let ((win (selected-window)))
  7451. (when (window-live-p org-agenda-show-window)
  7452. (select-window org-agenda-show-window)
  7453. (ignore-errors (scroll-down))
  7454. (select-window win))))
  7455. (defun org-agenda-show-1 (&optional more)
  7456. "Display the Org-mode file which contains the item at point.
  7457. The prefix arg selects the amount of information to display:
  7458. 0 hide the subtree
  7459. 1 just show the entry according to defaults.
  7460. 2 show the children view
  7461. 3 show the subtree view
  7462. 4 show the entire subtree and any LOGBOOK drawers
  7463. 5 show the entire subtree and any drawers
  7464. With prefix argument FULL-ENTRY, make the entire entry visible
  7465. if it was hidden in the outline."
  7466. (interactive "p")
  7467. (let ((win (selected-window)))
  7468. (org-agenda-goto t)
  7469. (org-recenter-heading 1)
  7470. (cond
  7471. ((= more 0)
  7472. (hide-subtree)
  7473. (save-excursion
  7474. (org-back-to-heading)
  7475. (run-hook-with-args 'org-cycle-hook 'folded))
  7476. (message "Remote: FOLDED"))
  7477. ((and (org-called-interactively-p 'any) (= more 1))
  7478. (message "Remote: show with default settings"))
  7479. ((= more 2)
  7480. (show-entry)
  7481. (show-children)
  7482. (save-excursion
  7483. (org-back-to-heading)
  7484. (run-hook-with-args 'org-cycle-hook 'children))
  7485. (message "Remote: CHILDREN"))
  7486. ((= more 3)
  7487. (show-subtree)
  7488. (save-excursion
  7489. (org-back-to-heading)
  7490. (run-hook-with-args 'org-cycle-hook 'subtree))
  7491. (message "Remote: SUBTREE"))
  7492. ((= more 4)
  7493. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7494. (org-drawer-regexp
  7495. (concat "^[ \t]*:\\("
  7496. (mapconcat 'regexp-quote org-drawers "\\|")
  7497. "\\):[ \t]*$")))
  7498. (show-subtree)
  7499. (save-excursion
  7500. (org-back-to-heading)
  7501. (org-cycle-hide-drawers 'subtree)))
  7502. (message "Remote: SUBTREE AND LOGBOOK"))
  7503. ((> more 4)
  7504. (show-subtree)
  7505. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7506. (select-window win)))
  7507. (defun org-recenter-heading (n)
  7508. (save-excursion
  7509. (org-back-to-heading)
  7510. (recenter n)))
  7511. (defvar org-agenda-cycle-counter nil)
  7512. (defun org-agenda-cycle-show (&optional n)
  7513. "Show the current entry in another window, with default settings.
  7514. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7515. When use repeatedly in immediate succession, the remote entry will cycle
  7516. through visibility
  7517. children -> subtree -> folded
  7518. When called with a numeric prefix arg, that arg will be passed through to
  7519. `org-agenda-show-1'. For the interpretation of that argument, see the
  7520. docstring of `org-agenda-show-1'."
  7521. (interactive "P")
  7522. (if (integerp n)
  7523. (setq org-agenda-cycle-counter n)
  7524. (if (not (eq last-command this-command))
  7525. (setq org-agenda-cycle-counter 1)
  7526. (if (equal org-agenda-cycle-counter 0)
  7527. (setq org-agenda-cycle-counter 2)
  7528. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7529. (if (> org-agenda-cycle-counter 3)
  7530. (setq org-agenda-cycle-counter 0)))))
  7531. (org-agenda-show-1 org-agenda-cycle-counter))
  7532. (defun org-agenda-recenter (arg)
  7533. "Display the Org-mode file which contains the item at point and recenter."
  7534. (interactive "P")
  7535. (let ((win (selected-window)))
  7536. (org-agenda-goto t)
  7537. (recenter arg)
  7538. (select-window win)))
  7539. (defun org-agenda-show-mouse (ev)
  7540. "Display the Org-mode file which contains the item at the mouse click."
  7541. (interactive "e")
  7542. (mouse-set-point ev)
  7543. (org-agenda-show))
  7544. (defun org-agenda-check-no-diary ()
  7545. "Check if the entry is a diary link and abort if yes."
  7546. (if (org-get-at-bol 'org-agenda-diary-link)
  7547. (org-agenda-error)))
  7548. (defun org-agenda-error ()
  7549. (error "Command not allowed in this line"))
  7550. (defun org-agenda-tree-to-indirect-buffer (arg)
  7551. "Show the subtree corresponding to the current entry in an indirect buffer.
  7552. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7553. With a numerical prefix ARG, go up to this level and then take that tree.
  7554. With a negative numeric ARG, go up by this number of levels.
  7555. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7556. use the dedicated frame)."
  7557. (interactive "P")
  7558. (if current-prefix-arg
  7559. (org-agenda-do-tree-to-indirect-buffer arg)
  7560. (let ((agenda-buffer (buffer-name))
  7561. (agenda-window (selected-window))
  7562. (indirect-window
  7563. (and org-last-indirect-buffer
  7564. (get-buffer-window org-last-indirect-buffer))))
  7565. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7566. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7567. (eq org-indirect-buffer-display 'dedicated-frame))
  7568. (unwind-protect
  7569. (unless (and indirect-window (window-live-p indirect-window))
  7570. (setq indirect-window (split-window agenda-window)))
  7571. (and indirect-window (select-window indirect-window))
  7572. (switch-to-buffer org-last-indirect-buffer :norecord)
  7573. (fit-window-to-buffer indirect-window)))
  7574. (select-window (get-buffer-window agenda-buffer)))))
  7575. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7576. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7577. (org-agenda-check-no-diary)
  7578. (let* ((marker (or (org-get-at-bol 'org-marker)
  7579. (org-agenda-error)))
  7580. (buffer (marker-buffer marker))
  7581. (pos (marker-position marker)))
  7582. (with-current-buffer buffer
  7583. (save-excursion
  7584. (goto-char pos)
  7585. (funcall 'org-tree-to-indirect-buffer arg)))))
  7586. (defvar org-last-heading-marker (make-marker)
  7587. "Marker pointing to the headline that last changed its TODO state
  7588. by a remote command from the agenda.")
  7589. (defun org-agenda-todo-nextset ()
  7590. "Switch TODO entry to next sequence."
  7591. (interactive)
  7592. (org-agenda-todo 'nextset))
  7593. (defun org-agenda-todo-previousset ()
  7594. "Switch TODO entry to previous sequence."
  7595. (interactive)
  7596. (org-agenda-todo 'previousset))
  7597. (defun org-agenda-todo (&optional arg)
  7598. "Cycle TODO state of line at point, also in Org-mode file.
  7599. This changes the line at point, all other lines in the agenda referring to
  7600. the same tree node, and the headline of the tree node in the Org-mode file."
  7601. (interactive "P")
  7602. (org-agenda-check-no-diary)
  7603. (let* ((col (current-column))
  7604. (marker (or (org-get-at-bol 'org-marker)
  7605. (org-agenda-error)))
  7606. (buffer (marker-buffer marker))
  7607. (pos (marker-position marker))
  7608. (hdmarker (org-get-at-bol 'org-hd-marker))
  7609. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7610. (inhibit-read-only t)
  7611. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7612. (org-with-remote-undo buffer
  7613. (with-current-buffer buffer
  7614. (widen)
  7615. (goto-char pos)
  7616. (org-show-context 'agenda)
  7617. (save-excursion
  7618. (and (outline-next-heading)
  7619. (org-flag-heading nil))) ; show the next heading
  7620. (let ((current-prefix-arg arg))
  7621. (call-interactively 'org-todo))
  7622. (and (bolp) (forward-char 1))
  7623. (setq newhead (org-get-heading))
  7624. (when (and (org-bound-and-true-p
  7625. org-agenda-headline-snapshot-before-repeat)
  7626. (not (equal org-agenda-headline-snapshot-before-repeat
  7627. newhead))
  7628. todayp)
  7629. (setq newhead org-agenda-headline-snapshot-before-repeat
  7630. just-one t))
  7631. (save-excursion
  7632. (org-back-to-heading)
  7633. (move-marker org-last-heading-marker (point))))
  7634. (beginning-of-line 1)
  7635. (save-excursion
  7636. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7637. (org-move-to-column col))))
  7638. (defun org-agenda-add-note (&optional arg)
  7639. "Add a time-stamped note to the entry at point."
  7640. (interactive "P")
  7641. (org-agenda-check-no-diary)
  7642. (let* ((marker (or (org-get-at-bol 'org-marker)
  7643. (org-agenda-error)))
  7644. (buffer (marker-buffer marker))
  7645. (pos (marker-position marker))
  7646. (hdmarker (org-get-at-bol 'org-hd-marker))
  7647. (inhibit-read-only t))
  7648. (with-current-buffer buffer
  7649. (widen)
  7650. (goto-char pos)
  7651. (org-show-context 'agenda)
  7652. (save-excursion
  7653. (and (outline-next-heading)
  7654. (org-flag-heading nil))) ; show the next heading
  7655. (org-add-note))))
  7656. (defun org-agenda-change-all-lines (newhead hdmarker
  7657. &optional fixface just-this)
  7658. "Change all lines in the agenda buffer which match HDMARKER.
  7659. The new content of the line will be NEWHEAD (as modified by
  7660. `org-agenda-format-item'). HDMARKER is checked with
  7661. `equal' against all `org-hd-marker' text properties in the file.
  7662. If FIXFACE is non-nil, the face of each item is modified according to
  7663. the new TODO state.
  7664. If JUST-THIS is non-nil, change just the current line, not all.
  7665. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7666. (let* ((inhibit-read-only t)
  7667. (line (org-current-line))
  7668. (org-agenda-buffer (current-buffer))
  7669. (thetags (with-current-buffer (marker-buffer hdmarker)
  7670. (save-excursion (save-restriction (widen)
  7671. (goto-char hdmarker)
  7672. (org-get-tags-at)))))
  7673. props m pl undone-face done-face finish new dotime cat tags)
  7674. (save-excursion
  7675. (goto-char (point-max))
  7676. (beginning-of-line 1)
  7677. (while (not finish)
  7678. (setq finish (bobp))
  7679. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7680. (or (not just-this) (= (org-current-line) line))
  7681. (equal m hdmarker))
  7682. (setq props (text-properties-at (point))
  7683. dotime (org-get-at-bol 'dotime)
  7684. cat (org-get-at-bol 'org-category)
  7685. tags thetags
  7686. new
  7687. (let ((org-prefix-format-compiled
  7688. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7689. org-prefix-format-compiled))
  7690. (extra (org-get-at-bol 'extra)))
  7691. (with-current-buffer (marker-buffer hdmarker)
  7692. (save-excursion
  7693. (save-restriction
  7694. (widen)
  7695. (org-agenda-format-item extra newhead cat tags dotime)))))
  7696. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7697. undone-face (org-get-at-bol 'undone-face)
  7698. done-face (org-get-at-bol 'done-face))
  7699. (beginning-of-line 1)
  7700. (cond
  7701. ((equal new "")
  7702. (and (looking-at ".*\n?") (replace-match "")))
  7703. ((looking-at ".*")
  7704. (replace-match new t t)
  7705. (beginning-of-line 1)
  7706. (add-text-properties (point-at-bol) (point-at-eol) props)
  7707. (when fixface
  7708. (add-text-properties
  7709. (point-at-bol) (point-at-eol)
  7710. (list 'face
  7711. (if org-last-todo-state-is-todo
  7712. undone-face done-face))))
  7713. (org-agenda-highlight-todo 'line)
  7714. (beginning-of-line 1))
  7715. (t (error "Line update did not work")))
  7716. (save-restriction
  7717. (narrow-to-region (point-at-bol) (point-at-eol))
  7718. (org-agenda-finalize)))
  7719. (beginning-of-line 0)))))
  7720. (defun org-agenda-align-tags (&optional line)
  7721. "Align all tags in agenda items to `org-agenda-tags-column'."
  7722. (let ((inhibit-read-only t) l c)
  7723. (save-excursion
  7724. (goto-char (if line (point-at-bol) (point-min)))
  7725. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7726. (if line (point-at-eol) nil) t)
  7727. (add-text-properties
  7728. (match-beginning 2) (match-end 2)
  7729. (list 'face (delq nil (let ((prop (get-text-property
  7730. (match-beginning 2) 'face)))
  7731. (or (listp prop) (setq prop (list prop)))
  7732. (if (memq 'org-tag prop)
  7733. prop
  7734. (cons 'org-tag prop))))))
  7735. (setq l (- (match-end 2) (match-beginning 2))
  7736. c (if (< org-agenda-tags-column 0)
  7737. (- (abs org-agenda-tags-column) l)
  7738. org-agenda-tags-column))
  7739. (delete-region (match-beginning 1) (match-end 1))
  7740. (goto-char (match-beginning 1))
  7741. (insert (org-add-props
  7742. (make-string (max 1 (- c (current-column))) ?\ )
  7743. (plist-put (copy-sequence (text-properties-at (point)))
  7744. 'face nil))))
  7745. (goto-char (point-min))
  7746. (org-font-lock-add-tag-faces (point-max)))))
  7747. (defun org-agenda-priority-up ()
  7748. "Increase the priority of line at point, also in Org-mode file."
  7749. (interactive)
  7750. (org-agenda-priority 'up))
  7751. (defun org-agenda-priority-down ()
  7752. "Decrease the priority of line at point, also in Org-mode file."
  7753. (interactive)
  7754. (org-agenda-priority 'down))
  7755. (defun org-agenda-priority (&optional force-direction)
  7756. "Set the priority of line at point, also in Org-mode file.
  7757. This changes the line at point, all other lines in the agenda referring to
  7758. the same tree node, and the headline of the tree node in the Org-mode file.
  7759. Called with a universal prefix arg, show the priority instead of setting it."
  7760. (interactive "P")
  7761. (if (equal force-direction '(4))
  7762. (org-show-priority)
  7763. (unless org-enable-priority-commands
  7764. (error "Priority commands are disabled"))
  7765. (org-agenda-check-no-diary)
  7766. (let* ((marker (or (org-get-at-bol 'org-marker)
  7767. (org-agenda-error)))
  7768. (hdmarker (org-get-at-bol 'org-hd-marker))
  7769. (buffer (marker-buffer hdmarker))
  7770. (pos (marker-position hdmarker))
  7771. (inhibit-read-only t)
  7772. newhead)
  7773. (org-with-remote-undo buffer
  7774. (with-current-buffer buffer
  7775. (widen)
  7776. (goto-char pos)
  7777. (org-show-context 'agenda)
  7778. (save-excursion
  7779. (and (outline-next-heading)
  7780. (org-flag-heading nil))) ; show the next heading
  7781. (funcall 'org-priority force-direction)
  7782. (end-of-line 1)
  7783. (setq newhead (org-get-heading)))
  7784. (org-agenda-change-all-lines newhead hdmarker)
  7785. (beginning-of-line 1)))))
  7786. ;; FIXME: should fix the tags property of the agenda line.
  7787. (defun org-agenda-set-tags (&optional tag onoff)
  7788. "Set tags for the current headline."
  7789. (interactive)
  7790. (org-agenda-check-no-diary)
  7791. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7792. (call-interactively 'org-change-tag-in-region)
  7793. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7794. (org-agenda-error)))
  7795. (buffer (marker-buffer hdmarker))
  7796. (pos (marker-position hdmarker))
  7797. (inhibit-read-only t)
  7798. newhead)
  7799. (org-with-remote-undo buffer
  7800. (with-current-buffer buffer
  7801. (widen)
  7802. (goto-char pos)
  7803. (save-excursion
  7804. (org-show-context 'agenda))
  7805. (save-excursion
  7806. (and (outline-next-heading)
  7807. (org-flag-heading nil))) ; show the next heading
  7808. (goto-char pos)
  7809. (if tag
  7810. (org-toggle-tag tag onoff)
  7811. (call-interactively 'org-set-tags))
  7812. (end-of-line 1)
  7813. (setq newhead (org-get-heading)))
  7814. (org-agenda-change-all-lines newhead hdmarker)
  7815. (beginning-of-line 1)))))
  7816. (defun org-agenda-set-property ()
  7817. "Set a property for the current headline."
  7818. (interactive)
  7819. (org-agenda-check-no-diary)
  7820. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7821. (org-agenda-error)))
  7822. (buffer (marker-buffer hdmarker))
  7823. (pos (marker-position hdmarker))
  7824. (inhibit-read-only t)
  7825. newhead)
  7826. (org-with-remote-undo buffer
  7827. (with-current-buffer buffer
  7828. (widen)
  7829. (goto-char pos)
  7830. (save-excursion
  7831. (org-show-context 'agenda))
  7832. (save-excursion
  7833. (and (outline-next-heading)
  7834. (org-flag-heading nil))) ; show the next heading
  7835. (goto-char pos)
  7836. (call-interactively 'org-set-property)))))
  7837. (defun org-agenda-set-effort ()
  7838. "Set the effort property for the current headline."
  7839. (interactive)
  7840. (org-agenda-check-no-diary)
  7841. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7842. (org-agenda-error)))
  7843. (buffer (marker-buffer hdmarker))
  7844. (pos (marker-position hdmarker))
  7845. (inhibit-read-only t)
  7846. newhead)
  7847. (org-with-remote-undo buffer
  7848. (with-current-buffer buffer
  7849. (widen)
  7850. (goto-char pos)
  7851. (save-excursion
  7852. (org-show-context 'agenda))
  7853. (save-excursion
  7854. (and (outline-next-heading)
  7855. (org-flag-heading nil))) ; show the next heading
  7856. (goto-char pos)
  7857. (call-interactively 'org-set-effort)
  7858. (end-of-line 1)
  7859. (setq newhead (org-get-heading)))
  7860. (org-agenda-change-all-lines newhead hdmarker))))
  7861. (defun org-agenda-toggle-archive-tag ()
  7862. "Toggle the archive tag for the current entry."
  7863. (interactive)
  7864. (org-agenda-check-no-diary)
  7865. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7866. (org-agenda-error)))
  7867. (buffer (marker-buffer hdmarker))
  7868. (pos (marker-position hdmarker))
  7869. (inhibit-read-only t)
  7870. newhead)
  7871. (org-with-remote-undo buffer
  7872. (with-current-buffer buffer
  7873. (widen)
  7874. (goto-char pos)
  7875. (org-show-context 'agenda)
  7876. (save-excursion
  7877. (and (outline-next-heading)
  7878. (org-flag-heading nil))) ; show the next heading
  7879. (call-interactively 'org-toggle-archive-tag)
  7880. (end-of-line 1)
  7881. (setq newhead (org-get-heading)))
  7882. (org-agenda-change-all-lines newhead hdmarker)
  7883. (beginning-of-line 1))))
  7884. (defun org-agenda-do-date-later (arg)
  7885. (interactive "P")
  7886. (cond
  7887. ((or (equal arg '(16))
  7888. (memq last-command
  7889. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7890. (setq this-command 'org-agenda-date-later-minutes)
  7891. (org-agenda-date-later-minutes 1))
  7892. ((or (equal arg '(4))
  7893. (memq last-command
  7894. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7895. (setq this-command 'org-agenda-date-later-hours)
  7896. (org-agenda-date-later-hours 1))
  7897. (t
  7898. (org-agenda-date-later (prefix-numeric-value arg)))))
  7899. (defun org-agenda-do-date-earlier (arg)
  7900. (interactive "P")
  7901. (cond
  7902. ((or (equal arg '(16))
  7903. (memq last-command
  7904. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7905. (setq this-command 'org-agenda-date-earlier-minutes)
  7906. (org-agenda-date-earlier-minutes 1))
  7907. ((or (equal arg '(4))
  7908. (memq last-command
  7909. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7910. (setq this-command 'org-agenda-date-earlier-hours)
  7911. (org-agenda-date-earlier-hours 1))
  7912. (t
  7913. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7914. (defun org-agenda-date-later (arg &optional what)
  7915. "Change the date of this item to ARG day(s) later."
  7916. (interactive "p")
  7917. (org-agenda-check-type t 'agenda 'timeline)
  7918. (org-agenda-check-no-diary)
  7919. (let* ((marker (or (org-get-at-bol 'org-marker)
  7920. (org-agenda-error)))
  7921. (buffer (marker-buffer marker))
  7922. (pos (marker-position marker))
  7923. cdate today)
  7924. (org-with-remote-undo buffer
  7925. (with-current-buffer buffer
  7926. (widen)
  7927. (goto-char pos)
  7928. (if (not (org-at-timestamp-p))
  7929. (error "Cannot find time stamp"))
  7930. (when (and org-agenda-move-date-from-past-immediately-to-today
  7931. (equal arg 1)
  7932. (or (not what) (eq what 'day))
  7933. (not (save-match-data (org-at-date-range-p))))
  7934. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7935. cdate (calendar-absolute-from-gregorian
  7936. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7937. today (org-today))
  7938. (if (> today cdate)
  7939. ;; immediately shift to today
  7940. (setq arg (- today cdate))))
  7941. (org-timestamp-change arg (or what 'day))
  7942. (when (and (org-at-date-range-p)
  7943. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7944. (let ((end org-last-changed-timestamp))
  7945. (org-timestamp-change arg (or what 'day))
  7946. (setq org-last-changed-timestamp
  7947. (concat org-last-changed-timestamp "--" end)))))
  7948. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7949. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7950. (defun org-agenda-date-earlier (arg &optional what)
  7951. "Change the date of this item to ARG day(s) earlier."
  7952. (interactive "p")
  7953. (org-agenda-date-later (- arg) what))
  7954. (defun org-agenda-date-later-minutes (arg)
  7955. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7956. (interactive "p")
  7957. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7958. (org-agenda-date-later arg 'minute))
  7959. (defun org-agenda-date-earlier-minutes (arg)
  7960. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7961. (interactive "p")
  7962. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7963. (org-agenda-date-earlier arg 'minute))
  7964. (defun org-agenda-date-later-hours (arg)
  7965. "Change the time of this item, in hour steps."
  7966. (interactive "p")
  7967. (org-agenda-date-later arg 'hour))
  7968. (defun org-agenda-date-earlier-hours (arg)
  7969. "Change the time of this item, in hour steps."
  7970. (interactive "p")
  7971. (org-agenda-date-earlier arg 'hour))
  7972. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7973. "Show new date stamp via text properties."
  7974. ;; We use text properties to make this undoable
  7975. (let ((inhibit-read-only t)
  7976. (buffer-invisibility-spec))
  7977. (setq stamp (concat " " prefix " => " stamp))
  7978. (save-excursion
  7979. (goto-char (point-max))
  7980. (while (not (bobp))
  7981. (when (equal marker (org-get-at-bol 'org-marker))
  7982. (org-move-to-column (- (window-width) (length stamp)) t)
  7983. (org-agenda-fix-tags-filter-overlays-at (point))
  7984. (if (featurep 'xemacs)
  7985. ;; Use `duplicable' property to trigger undo recording
  7986. (let ((ex (make-extent nil nil))
  7987. (gl (make-glyph stamp)))
  7988. (set-glyph-face gl 'secondary-selection)
  7989. (set-extent-properties
  7990. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7991. (insert-extent ex (1- (point)) (point-at-eol)))
  7992. (add-text-properties
  7993. (1- (point)) (point-at-eol)
  7994. (list 'display (org-add-props stamp nil
  7995. 'face 'secondary-selection))))
  7996. (beginning-of-line 1))
  7997. (beginning-of-line 0)))))
  7998. (defun org-agenda-date-prompt (arg)
  7999. "Change the date of this item. Date is prompted for, with default today.
  8000. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8001. be used to request time specification in the time stamp."
  8002. (interactive "P")
  8003. (org-agenda-check-type t 'agenda 'timeline)
  8004. (org-agenda-check-no-diary)
  8005. (let* ((marker (or (org-get-at-bol 'org-marker)
  8006. (org-agenda-error)))
  8007. (buffer (marker-buffer marker))
  8008. (pos (marker-position marker)))
  8009. (org-with-remote-undo buffer
  8010. (with-current-buffer buffer
  8011. (widen)
  8012. (goto-char pos)
  8013. (if (not (org-at-timestamp-p t))
  8014. (error "Cannot find time stamp"))
  8015. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8016. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8017. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8018. (defun org-agenda-schedule (arg &optional time)
  8019. "Schedule the item at point.
  8020. ARG is passed through to `org-schedule'."
  8021. (interactive "P")
  8022. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8023. (org-agenda-check-no-diary)
  8024. (let* ((marker (or (org-get-at-bol 'org-marker)
  8025. (org-agenda-error)))
  8026. (type (marker-insertion-type marker))
  8027. (buffer (marker-buffer marker))
  8028. (pos (marker-position marker))
  8029. (org-insert-labeled-timestamps-at-point nil)
  8030. ts)
  8031. (set-marker-insertion-type marker t)
  8032. (org-with-remote-undo buffer
  8033. (with-current-buffer buffer
  8034. (widen)
  8035. (goto-char pos)
  8036. (setq ts (org-schedule arg time)))
  8037. (org-agenda-show-new-time marker ts "S"))
  8038. (message "%s" ts)))
  8039. (defun org-agenda-deadline (arg &optional time)
  8040. "Schedule the item at point.
  8041. ARG is passed through to `org-deadline'."
  8042. (interactive "P")
  8043. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8044. (org-agenda-check-no-diary)
  8045. (let* ((marker (or (org-get-at-bol 'org-marker)
  8046. (org-agenda-error)))
  8047. (buffer (marker-buffer marker))
  8048. (pos (marker-position marker))
  8049. (org-insert-labeled-timestamps-at-point nil)
  8050. ts)
  8051. (org-with-remote-undo buffer
  8052. (with-current-buffer buffer
  8053. (widen)
  8054. (goto-char pos)
  8055. (setq ts (org-deadline arg time)))
  8056. (org-agenda-show-new-time marker ts "D"))
  8057. (message "%s" ts)))
  8058. (defun org-agenda-clock-in (&optional arg)
  8059. "Start the clock on the currently selected item."
  8060. (interactive "P")
  8061. (org-agenda-check-no-diary)
  8062. (if (equal arg '(4))
  8063. (org-clock-in arg)
  8064. (let* ((marker (or (org-get-at-bol 'org-marker)
  8065. (org-agenda-error)))
  8066. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  8067. marker))
  8068. (pos (marker-position marker))
  8069. newhead)
  8070. (org-with-remote-undo (marker-buffer marker)
  8071. (with-current-buffer (marker-buffer marker)
  8072. (widen)
  8073. (goto-char pos)
  8074. (org-show-context 'agenda)
  8075. (org-show-entry)
  8076. (org-cycle-hide-drawers 'children)
  8077. (org-clock-in arg)
  8078. (setq newhead (org-get-heading)))
  8079. (org-agenda-change-all-lines newhead hdmarker)))))
  8080. (defun org-agenda-clock-out ()
  8081. "Stop the currently running clock."
  8082. (interactive)
  8083. (unless (marker-buffer org-clock-marker)
  8084. (error "No running clock"))
  8085. (let ((marker (make-marker)) newhead)
  8086. (org-with-remote-undo (marker-buffer org-clock-marker)
  8087. (with-current-buffer (marker-buffer org-clock-marker)
  8088. (save-excursion
  8089. (save-restriction
  8090. (widen)
  8091. (goto-char org-clock-marker)
  8092. (org-back-to-heading t)
  8093. (move-marker marker (point))
  8094. (org-clock-out)
  8095. (setq newhead (org-get-heading))))))
  8096. (org-agenda-change-all-lines newhead marker)
  8097. (move-marker marker nil)))
  8098. (defun org-agenda-clock-cancel (&optional arg)
  8099. "Cancel the currently running clock."
  8100. (interactive "P")
  8101. (unless (marker-buffer org-clock-marker)
  8102. (error "No running clock"))
  8103. (org-with-remote-undo (marker-buffer org-clock-marker)
  8104. (org-clock-cancel)))
  8105. (defun org-agenda-clock-goto ()
  8106. "Jump to the currently clocked in task within the agenda.
  8107. If the currently clocked in task is not listed in the agenda
  8108. buffer, display it in another window."
  8109. (interactive)
  8110. (let (pos)
  8111. (mapc (lambda (o)
  8112. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8113. (setq pos (overlay-start o))))
  8114. (overlays-in (point-min) (point-max)))
  8115. (cond (pos (goto-char pos))
  8116. ;; If the currently clocked entry is not in the agenda
  8117. ;; buffer, we visit it in another window:
  8118. (org-clock-current-task
  8119. (org-switch-to-buffer-other-window (org-clock-goto)))
  8120. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8121. (defun org-agenda-diary-entry-in-org-file ()
  8122. "Make a diary entry in the file `org-agenda-diary-file'."
  8123. (let (d1 d2 char (text "") dp1 dp2)
  8124. (if (equal (buffer-name) "*Calendar*")
  8125. (setq d1 (calendar-cursor-to-date t)
  8126. d2 (car calendar-mark-ring))
  8127. (setq dp1 (get-text-property (point-at-bol) 'day))
  8128. (unless dp1 (error "No date defined in current line"))
  8129. (setq d1 (calendar-gregorian-from-absolute dp1)
  8130. d2 (and (ignore-errors (mark))
  8131. (save-excursion
  8132. (goto-char (mark))
  8133. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8134. (calendar-gregorian-from-absolute dp2))))
  8135. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8136. (setq char (read-char-exclusive))
  8137. (cond
  8138. ((equal char ?d)
  8139. (setq text (read-string "Day entry: "))
  8140. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8141. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8142. ((equal char ?a)
  8143. (setq d1 (list (car d1) (nth 1 d1)
  8144. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8145. (nth 2 d1))))
  8146. (setq text (read-string "Anniversary (use %d to show years): "))
  8147. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8148. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8149. ((equal char ?b)
  8150. (setq text (read-string "Block entry: "))
  8151. (unless (and d1 d2 (not (equal d1 d2)))
  8152. (error "No block of days selected"))
  8153. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8154. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8155. ((equal char ?j)
  8156. (org-switch-to-buffer-other-window
  8157. (find-file-noselect org-agenda-diary-file))
  8158. (require 'org-datetree)
  8159. (org-datetree-find-date-create d1)
  8160. (org-reveal t))
  8161. (t (error "Invalid selection character `%c'" char)))))
  8162. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8163. "Where in `org-agenda-diary-file' should new entries be added?
  8164. Valid values:
  8165. date-tree in the date tree, as child of the date
  8166. top-level as top-level entries at the end of the file."
  8167. :group 'org-agenda
  8168. :type '(choice
  8169. (const :tag "in a date tree" date-tree)
  8170. (const :tag "as top level at end of file" top-level)))
  8171. (defcustom org-agenda-insert-diary-extract-time nil
  8172. "Non-nil means extract any time specification from the diary entry."
  8173. :group 'org-agenda
  8174. :version "24.1"
  8175. :type 'boolean)
  8176. (defcustom org-agenda-bulk-mark-char ">"
  8177. "A single-character string to be used as the bulk mark."
  8178. :group 'org-agenda
  8179. :version "24.1"
  8180. :type 'string)
  8181. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8182. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8183. If TEXT is not empty, it will become the headline of the new entry, and
  8184. the resulting entry will not be shown. When TEXT is empty, switch to
  8185. `org-agenda-diary-file' and let the user finish the entry there."
  8186. (let ((cw (current-window-configuration)))
  8187. (org-switch-to-buffer-other-window
  8188. (find-file-noselect org-agenda-diary-file))
  8189. (widen)
  8190. (goto-char (point-min))
  8191. (cond
  8192. ((eq type 'anniversary)
  8193. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8194. (progn
  8195. (or (org-at-heading-p t)
  8196. (progn
  8197. (outline-next-heading)
  8198. (insert "* Anniversaries\n\n")
  8199. (beginning-of-line -1)))))
  8200. (outline-next-heading)
  8201. (org-back-over-empty-lines)
  8202. (backward-char 1)
  8203. (insert "\n")
  8204. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8205. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8206. ((eq type 'day)
  8207. (let ((org-prefix-has-time t)
  8208. (org-agenda-time-leading-zero t)
  8209. fmt time time2)
  8210. (if org-agenda-insert-diary-extract-time
  8211. ;; Use org-agenda-format-item to parse text for a time-range and
  8212. ;; remove it. FIXME: This is a hack, we should refactor
  8213. ;; that function to make time extraction available separately
  8214. (setq fmt (org-agenda-format-item nil text nil nil t)
  8215. time (get-text-property 0 'time fmt)
  8216. time2 (if (> (length time) 0)
  8217. ;; split-string removes trailing ...... if
  8218. ;; no end time given. First space
  8219. ;; separates time from date.
  8220. (concat " " (car (split-string time "\\.")))
  8221. nil)
  8222. text (get-text-property 0 'txt fmt)))
  8223. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8224. (org-agenda-insert-diary-as-top-level text)
  8225. (require 'org-datetree)
  8226. (org-datetree-find-date-create d1)
  8227. (org-agenda-insert-diary-make-new-entry text))
  8228. (org-insert-time-stamp (org-time-from-absolute
  8229. (calendar-absolute-from-gregorian d1))
  8230. nil nil nil nil time2))
  8231. (end-of-line 0))
  8232. ((eq type 'block)
  8233. (if (> (calendar-absolute-from-gregorian d1)
  8234. (calendar-absolute-from-gregorian d2))
  8235. (setq d1 (prog1 d2 (setq d2 d1))))
  8236. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8237. (org-agenda-insert-diary-as-top-level text)
  8238. (require 'org-datetree)
  8239. (org-datetree-find-date-create d1)
  8240. (org-agenda-insert-diary-make-new-entry text))
  8241. (org-insert-time-stamp (org-time-from-absolute
  8242. (calendar-absolute-from-gregorian d1)))
  8243. (insert "--")
  8244. (org-insert-time-stamp (org-time-from-absolute
  8245. (calendar-absolute-from-gregorian d2)))
  8246. (end-of-line 0)))
  8247. (if (string-match "\\S-" text)
  8248. (progn
  8249. (set-window-configuration cw)
  8250. (message "%s entry added to %s"
  8251. (capitalize (symbol-name type))
  8252. (abbreviate-file-name org-agenda-diary-file)))
  8253. (org-reveal t)
  8254. (message "Please finish entry here"))))
  8255. (defun org-agenda-insert-diary-as-top-level (text)
  8256. "Make new entry as a top-level entry at the end of the file.
  8257. Add TEXT as headline, and position the cursor in the second line so that
  8258. a timestamp can be added there."
  8259. (widen)
  8260. (goto-char (point-max))
  8261. (or (bolp) (insert "\n"))
  8262. (insert "* " text "\n")
  8263. (if org-adapt-indentation (org-indent-to-column 2)))
  8264. (defun org-agenda-insert-diary-make-new-entry (text)
  8265. "Make new entry as last child of current entry.
  8266. Add TEXT as headline, and position the cursor in the second line so that
  8267. a timestamp can be added there."
  8268. (let ((org-show-following-heading t)
  8269. (org-show-siblings t)
  8270. (org-show-hierarchy-above t)
  8271. (org-show-entry-below t)
  8272. col)
  8273. (outline-next-heading)
  8274. (org-back-over-empty-lines)
  8275. (or (looking-at "[ \t]*$")
  8276. (progn (insert "\n") (backward-char 1)))
  8277. (org-insert-heading nil t)
  8278. (org-do-demote)
  8279. (setq col (current-column))
  8280. (insert text "\n")
  8281. (if org-adapt-indentation (org-indent-to-column col))
  8282. (let ((org-show-following-heading t)
  8283. (org-show-siblings t)
  8284. (org-show-hierarchy-above t)
  8285. (org-show-entry-below t))
  8286. (org-show-context))))
  8287. (defun org-agenda-diary-entry ()
  8288. "Make a diary entry, like the `i' command from the calendar.
  8289. All the standard commands work: block, weekly etc.
  8290. When `org-agenda-diary-file' points to a file,
  8291. `org-agenda-diary-entry-in-org-file' is called instead to create
  8292. entries in that Org-mode file."
  8293. (interactive)
  8294. (if (not (eq org-agenda-diary-file 'diary-file))
  8295. (org-agenda-diary-entry-in-org-file)
  8296. (require 'diary-lib)
  8297. (let* ((char (progn
  8298. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8299. (read-char-exclusive)))
  8300. (cmd (cdr (assoc char
  8301. '((?d . insert-diary-entry)
  8302. (?w . insert-weekly-diary-entry)
  8303. (?m . insert-monthly-diary-entry)
  8304. (?y . insert-yearly-diary-entry)
  8305. (?a . insert-anniversary-diary-entry)
  8306. (?b . insert-block-diary-entry)
  8307. (?c . insert-cyclic-diary-entry)))))
  8308. (oldf (symbol-function 'calendar-cursor-to-date))
  8309. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8310. (point (point))
  8311. (mark (or (mark t) (point))))
  8312. (unless cmd
  8313. (error "No command associated with <%c>" char))
  8314. (unless (and (get-text-property point 'day)
  8315. (or (not (equal ?b char))
  8316. (get-text-property mark 'day)))
  8317. (error "Don't know which date to use for diary entry"))
  8318. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8319. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8320. (let ((calendar-mark-ring
  8321. (list (calendar-gregorian-from-absolute
  8322. (or (get-text-property mark 'day)
  8323. (get-text-property point 'day))))))
  8324. (unwind-protect
  8325. (progn
  8326. (fset 'calendar-cursor-to-date
  8327. (lambda (&optional error dummy)
  8328. (calendar-gregorian-from-absolute
  8329. (get-text-property point 'day))))
  8330. (call-interactively cmd))
  8331. (fset 'calendar-cursor-to-date oldf))))))
  8332. (defun org-agenda-execute-calendar-command (cmd)
  8333. "Execute a calendar command from the agenda with date from cursor."
  8334. (org-agenda-check-type t 'agenda 'timeline)
  8335. (require 'diary-lib)
  8336. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8337. (error "Don't know which date to use for the calendar command"))
  8338. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8339. (point (point))
  8340. (date (calendar-gregorian-from-absolute
  8341. (get-text-property point 'day)))
  8342. ;; the following 2 vars are needed in the calendar
  8343. (displayed-month (car date))
  8344. (displayed-year (nth 2 date)))
  8345. (unwind-protect
  8346. (progn
  8347. (fset 'calendar-cursor-to-date
  8348. (lambda (&optional error dummy)
  8349. (calendar-gregorian-from-absolute
  8350. (get-text-property point 'day))))
  8351. (call-interactively cmd))
  8352. (fset 'calendar-cursor-to-date oldf))))
  8353. (defun org-agenda-phases-of-moon ()
  8354. "Display the phases of the moon for the 3 months around the cursor date."
  8355. (interactive)
  8356. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8357. (defun org-agenda-holidays ()
  8358. "Display the holidays for the 3 months around the cursor date."
  8359. (interactive)
  8360. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8361. (defvar calendar-longitude) ; defined in calendar.el
  8362. (defvar calendar-latitude) ; defined in calendar.el
  8363. (defvar calendar-location-name) ; defined in calendar.el
  8364. (defun org-agenda-sunrise-sunset (arg)
  8365. "Display sunrise and sunset for the cursor date.
  8366. Latitude and longitude can be specified with the variables
  8367. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8368. argument, latitude and longitude will be prompted for."
  8369. (interactive "P")
  8370. (require 'solar)
  8371. (let ((calendar-longitude (if arg nil calendar-longitude))
  8372. (calendar-latitude (if arg nil calendar-latitude))
  8373. (calendar-location-name
  8374. (if arg "the given coordinates" calendar-location-name)))
  8375. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8376. (defun org-agenda-goto-calendar ()
  8377. "Open the Emacs calendar with the date at the cursor."
  8378. (interactive)
  8379. (org-agenda-check-type t 'agenda 'timeline)
  8380. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8381. (error "Don't know which date to open in calendar")))
  8382. (date (calendar-gregorian-from-absolute day))
  8383. (calendar-move-hook nil)
  8384. (calendar-view-holidays-initially-flag nil)
  8385. (calendar-view-diary-initially-flag nil))
  8386. (calendar)
  8387. (calendar-goto-date date)))
  8388. ;;;###autoload
  8389. (defun org-calendar-goto-agenda ()
  8390. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8391. This is a command that has to be installed in `calendar-mode-map'."
  8392. (interactive)
  8393. (org-agenda-list nil (calendar-absolute-from-gregorian
  8394. (calendar-cursor-to-date))
  8395. nil))
  8396. (autoload 'org-calendar-goto-agenda "org-agenda" "\
  8397. Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8398. This is a command that has to be installed in `calendar-mode-map'.
  8399. \(fn)" t nil)
  8400. (defun org-agenda-convert-date ()
  8401. (interactive)
  8402. (org-agenda-check-type t 'agenda 'timeline)
  8403. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8404. date s)
  8405. (unless day
  8406. (error "Don't know which date to convert"))
  8407. (setq date (calendar-gregorian-from-absolute day))
  8408. (setq s (concat
  8409. "Gregorian: " (calendar-date-string date) "\n"
  8410. "ISO: " (calendar-iso-date-string date) "\n"
  8411. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8412. "Julian: " (calendar-julian-date-string date) "\n"
  8413. "Astron. JD: " (calendar-astro-date-string date)
  8414. " (Julian date number at noon UTC)\n"
  8415. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8416. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8417. "French: " (calendar-french-date-string date) "\n"
  8418. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8419. "Mayan: " (calendar-mayan-date-string date) "\n"
  8420. "Coptic: " (calendar-coptic-date-string date) "\n"
  8421. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8422. "Persian: " (calendar-persian-date-string date) "\n"
  8423. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8424. (with-output-to-temp-buffer "*Dates*"
  8425. (princ s))
  8426. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8427. ;;; Bulk commands
  8428. (defun org-agenda-bulk-marked-p ()
  8429. (eq (get-char-property (point-at-bol) 'type)
  8430. 'org-marked-entry-overlay))
  8431. (defun org-agenda-bulk-mark (&optional arg)
  8432. "Mark the entry at point for future bulk action."
  8433. (interactive "p")
  8434. (dotimes (i (or arg 1))
  8435. (unless (org-get-at-bol 'org-agenda-diary-link)
  8436. (let* ((m (org-get-at-bol 'org-hd-marker))
  8437. ov)
  8438. (unless (org-agenda-bulk-marked-p)
  8439. (unless m (error "Nothing to mark at point"))
  8440. (push m org-agenda-bulk-marked-entries)
  8441. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8442. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8443. (org-get-todo-face "TODO")
  8444. 'evaporate)
  8445. (overlay-put ov 'type 'org-marked-entry-overlay))
  8446. (beginning-of-line 2)
  8447. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8448. (beginning-of-line 2))
  8449. (message "%d entries marked for bulk action"
  8450. (length org-agenda-bulk-marked-entries))))))
  8451. (defun org-agenda-bulk-mark-all ()
  8452. "Mark all entries for future agenda bulk action."
  8453. (interactive)
  8454. (org-agenda-bulk-mark-regexp "."))
  8455. (defun org-agenda-bulk-mark-regexp (regexp)
  8456. "Mark entries matching REGEXP for future agenda bulk action."
  8457. (interactive "sMark entries matching regexp: ")
  8458. (let ((entries-marked 0))
  8459. (save-excursion
  8460. (goto-char (point-min))
  8461. (goto-char (next-single-property-change (point) 'txt))
  8462. (while (re-search-forward regexp nil t)
  8463. (when (string-match regexp (get-text-property (point) 'txt))
  8464. (setq entries-marked (1+ entries-marked))
  8465. (call-interactively 'org-agenda-bulk-mark))))
  8466. (if (not entries-marked)
  8467. (message "No entry matching this regexp."))))
  8468. (defun org-agenda-bulk-unmark (&optional arg)
  8469. "Unmark the entry at point for future bulk action."
  8470. (interactive "P")
  8471. (if arg
  8472. (org-agenda-bulk-unmark-all)
  8473. (cond ((org-agenda-bulk-marked-p)
  8474. (org-agenda-bulk-remove-overlays
  8475. (point-at-bol) (+ 2 (point-at-bol)))
  8476. (setq org-agenda-bulk-marked-entries
  8477. (delete (org-get-at-bol 'org-hd-marker)
  8478. org-agenda-bulk-marked-entries))
  8479. (beginning-of-line 2)
  8480. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8481. (beginning-of-line 2))
  8482. (message "%d entries left marked for bulk action"
  8483. (length org-agenda-bulk-marked-entries)))
  8484. (t (message "No entry to unmark here")))))
  8485. (defun org-agenda-bulk-toggle ()
  8486. "Toggle marking the entry at point for bulk action."
  8487. (interactive)
  8488. (if (org-agenda-bulk-marked-p)
  8489. (org-agenda-bulk-unmark)
  8490. (org-agenda-bulk-mark)))
  8491. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8492. "Remove the mark overlays between BEG and END in the agenda buffer.
  8493. BEG and END default to the buffer limits.
  8494. This only removes the overlays, it does not remove the markers
  8495. from the list in `org-agenda-bulk-marked-entries'."
  8496. (interactive)
  8497. (mapc (lambda (ov)
  8498. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8499. (delete-overlay ov)))
  8500. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8501. (defun org-agenda-bulk-unmark-all ()
  8502. "Remove all marks in the agenda buffer.
  8503. This will remove the markers and the overlays."
  8504. (interactive)
  8505. (if (null org-agenda-bulk-marked-entries)
  8506. (message "No entry to unmark")
  8507. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8508. (setq org-agenda-bulk-marked-entries nil)
  8509. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8510. (defcustom org-agenda-persistent-marks nil
  8511. "Non-nil means marked items will stay marked after a bulk action.
  8512. You can toggle this interactively by typing `p' when prompted for a
  8513. bulk action."
  8514. :group 'org-agenda
  8515. :version "24.1"
  8516. :type 'boolean)
  8517. (defun org-agenda-bulk-action (&optional arg)
  8518. "Execute an remote-editing action on all marked entries.
  8519. The prefix arg is passed through to the command if possible."
  8520. (interactive "P")
  8521. ;; Make sure we have markers, and only valid ones
  8522. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8523. (mapc
  8524. (lambda (m)
  8525. (unless (and (markerp m)
  8526. (marker-buffer m)
  8527. (buffer-live-p (marker-buffer m))
  8528. (marker-position m))
  8529. (error "Marker %s for bulk command is invalid" m)))
  8530. org-agenda-bulk-marked-entries)
  8531. ;; Prompt for the bulk command
  8532. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8533. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8534. "[S]catter [f]unction "
  8535. (when org-agenda-bulk-custom-functions
  8536. (concat " Custom: ["
  8537. (mapconcat (lambda(f) (char-to-string (car f)))
  8538. org-agenda-bulk-custom-functions "")
  8539. "]"))))
  8540. (catch 'exit
  8541. (let* ((action (read-char-exclusive))
  8542. (org-log-refile (if org-log-refile 'time nil))
  8543. (entries (reverse org-agenda-bulk-marked-entries))
  8544. (org-overriding-default-time
  8545. (if (get-text-property (point) 'org-agenda-date-header)
  8546. (org-get-cursor-date)))
  8547. redo-at-end
  8548. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8549. (cond
  8550. ((equal action ?p)
  8551. (let ((org-agenda-persistent-marks
  8552. (not org-agenda-persistent-marks)))
  8553. (org-agenda-bulk-action)
  8554. (throw 'exit nil)))
  8555. ((equal action ?$)
  8556. (setq cmd '(org-agenda-archive)))
  8557. ((equal action ?A)
  8558. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8559. ((member action '(?r ?w))
  8560. (setq rfloc (org-refile-get-location
  8561. "Refile to"
  8562. (marker-buffer (car entries))
  8563. org-refile-allow-creating-parent-nodes))
  8564. (if (nth 3 rfloc)
  8565. (setcar (nthcdr 3 rfloc)
  8566. (move-marker (make-marker) (nth 3 rfloc)
  8567. (or (get-file-buffer (nth 1 rfloc))
  8568. (find-buffer-visiting (nth 1 rfloc))
  8569. (error "This should not happen")))))
  8570. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8571. redo-at-end t))
  8572. ((equal action ?t)
  8573. (setq state (org-icompleting-read
  8574. "Todo state: "
  8575. (with-current-buffer (marker-buffer (car entries))
  8576. (mapcar 'list org-todo-keywords-1))))
  8577. (setq cmd `(let ((org-inhibit-blocking t)
  8578. (org-inhibit-logging 'note))
  8579. (org-agenda-todo ,state))))
  8580. ((memq action '(?- ?+))
  8581. (setq tag (org-icompleting-read
  8582. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8583. (with-current-buffer (marker-buffer (car entries))
  8584. (delq nil
  8585. (mapcar (lambda (x)
  8586. (if (stringp (car x)) x)) org-tag-alist)))))
  8587. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8588. ((memq action '(?s ?d))
  8589. (let* ((time
  8590. (unless arg
  8591. (org-read-date
  8592. nil nil nil
  8593. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8594. org-overriding-default-time)))
  8595. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8596. (setq cmd `(eval '(,c1 arg ,time)))))
  8597. ((equal action ?S)
  8598. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8599. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8600. (let ((days (read-number
  8601. (format "Scatter tasks across how many %sdays: "
  8602. (if arg "week" "")) 7)))
  8603. (setq cmd
  8604. `(let ((distance (1+ (random ,days))))
  8605. (if arg
  8606. (let ((dist distance)
  8607. (day-of-week
  8608. (calendar-day-of-week
  8609. (calendar-gregorian-from-absolute (org-today)))))
  8610. (dotimes (i (1+ dist))
  8611. (while (member day-of-week org-agenda-weekend-days)
  8612. (incf distance)
  8613. (incf day-of-week)
  8614. (if (= day-of-week 7)
  8615. (setq day-of-week 0)))
  8616. (incf day-of-week)
  8617. (if (= day-of-week 7)
  8618. (setq day-of-week 0)))))
  8619. ;; silently fail when try to replan a sexp entry
  8620. (condition-case nil
  8621. (let* ((date (calendar-gregorian-from-absolute
  8622. (+ (org-today) distance)))
  8623. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8624. (nth 2 date))))
  8625. (org-agenda-schedule nil time))
  8626. (error nil)))))))
  8627. ((assoc action org-agenda-bulk-custom-functions)
  8628. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8629. redo-at-end t))
  8630. ((equal action ?f)
  8631. (setq cmd (list (intern
  8632. (org-icompleting-read "Function: "
  8633. obarray 'fboundp t nil nil)))))
  8634. (t (error "Invalid bulk action")))
  8635. ;; Sort the markers, to make sure that parents are handled before children
  8636. (setq entries (sort entries
  8637. (lambda (a b)
  8638. (cond
  8639. ((equal (marker-buffer a) (marker-buffer b))
  8640. (< (marker-position a) (marker-position b)))
  8641. (t
  8642. (string< (buffer-name (marker-buffer a))
  8643. (buffer-name (marker-buffer b))))))))
  8644. ;; Now loop over all markers and apply cmd
  8645. (while (setq e (pop entries))
  8646. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8647. (if (not pos)
  8648. (progn (message "Skipping removed entry at %s" e)
  8649. (setq cntskip (1+ cntskip)))
  8650. (goto-char pos)
  8651. (let (org-loop-over-headlines-in-active-region)
  8652. (eval cmd))
  8653. (setq cnt (1+ cnt))))
  8654. (when redo-at-end (org-agenda-redo))
  8655. (unless org-agenda-persistent-marks
  8656. (org-agenda-bulk-unmark-all))
  8657. (message "Acted on %d entries%s%s"
  8658. cnt
  8659. (if (= cntskip 0)
  8660. ""
  8661. (format ", skipped %d (disappeared before their turn)"
  8662. cntskip))
  8663. (if (not org-agenda-persistent-marks)
  8664. "" " (kept marked)"))))))
  8665. (defun org-agenda-capture ()
  8666. "Call `org-capture' with the date at point."
  8667. (interactive)
  8668. (if (not (eq major-mode 'org-agenda-mode))
  8669. (error "You cannot do this outside of agenda buffers")
  8670. (let ((org-overriding-default-time
  8671. (org-get-cursor-date)))
  8672. (call-interactively 'org-capture))))
  8673. ;;; Flagging notes
  8674. (defun org-agenda-show-the-flagging-note ()
  8675. "Display the flagging note in the other window.
  8676. When called a second time in direct sequence, offer to remove the FLAGGING
  8677. tag and (if present) the flagging note."
  8678. (interactive)
  8679. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8680. (win (selected-window))
  8681. note heading newhead)
  8682. (unless hdmarker
  8683. (error "No linked entry at point"))
  8684. (if (and (eq this-command last-command)
  8685. (y-or-n-p "Unflag and remove any flagging note? "))
  8686. (progn
  8687. (org-agenda-remove-flag hdmarker)
  8688. (let ((win (get-buffer-window "*Flagging Note*")))
  8689. (and win (delete-window win)))
  8690. (message "Entry unflagged"))
  8691. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8692. (unless note
  8693. (error "No flagging note"))
  8694. (org-kill-new note)
  8695. (org-switch-to-buffer-other-window "*Flagging Note*")
  8696. (erase-buffer)
  8697. (insert note)
  8698. (goto-char (point-min))
  8699. (while (re-search-forward "\\\\n" nil t)
  8700. (replace-match "\n" t t))
  8701. (goto-char (point-min))
  8702. (select-window win)
  8703. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8704. (defun org-agenda-remove-flag (marker)
  8705. "Remove the FLAGGED tag and any flagging note in the entry."
  8706. (let (newhead)
  8707. (org-with-point-at marker
  8708. (org-toggle-tag "FLAGGED" 'off)
  8709. (org-entry-delete nil "THEFLAGGINGNOTE")
  8710. (setq newhead (org-get-heading)))
  8711. (org-agenda-change-all-lines newhead marker)
  8712. (message "Entry unflagged")))
  8713. (defun org-agenda-get-any-marker (&optional pos)
  8714. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8715. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8716. ;;; Appointment reminders
  8717. (defvar appt-time-msg-list) ; defined in appt.el
  8718. ;;;###autoload
  8719. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8720. "Activate appointments found in `org-agenda-files'.
  8721. With a \\[universal-argument] prefix, refresh the list of
  8722. appointments.
  8723. If FILTER is t, interactively prompt the user for a regular
  8724. expression, and filter out entries that don't match it.
  8725. If FILTER is a string, use this string as a regular expression
  8726. for filtering entries out.
  8727. If FILTER is a function, filter out entries against which
  8728. calling the function returns nil. This function takes one
  8729. argument: an entry from `org-agenda-get-day-entries'.
  8730. FILTER can also be an alist with the car of each cell being
  8731. either 'headline or 'category. For example:
  8732. '((headline \"IMPORTANT\")
  8733. (category \"Work\"))
  8734. will only add headlines containing IMPORTANT or headlines
  8735. belonging to the \"Work\" category.
  8736. ARGS are symbols indicating what kind of entries to consider.
  8737. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8738. and :timestamp entries. See the docstring of `org-diary' for
  8739. details and examples.
  8740. If an entry as a APPT_WARNTIME property, its value will be used
  8741. to override `appt-message-warning-time'."
  8742. (interactive "P")
  8743. (if refresh (setq appt-time-msg-list nil))
  8744. (if (eq filter t)
  8745. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8746. (let* ((cnt 0) ; count added events
  8747. (scope (or args '(:deadline :scheduled :timestamp)))
  8748. (org-agenda-new-buffers nil)
  8749. (org-deadline-warning-days 0)
  8750. ;; Do not use `org-today' here because appt only takes
  8751. ;; time and without date as argument, so it may pass wrong
  8752. ;; information otherwise
  8753. (today (org-date-to-gregorian
  8754. (time-to-days (current-time))))
  8755. (org-agenda-restrict nil)
  8756. (files (org-agenda-files 'unrestricted)) entries file
  8757. (org-agenda-buffer nil))
  8758. ;; Get all entries which may contain an appt
  8759. (org-agenda-prepare-buffers files)
  8760. (while (setq file (pop files))
  8761. (setq entries
  8762. (delq nil
  8763. (append entries
  8764. (apply 'org-agenda-get-day-entries
  8765. file today scope)))))
  8766. ;; Map thru entries and find if we should filter them out
  8767. (mapc
  8768. (lambda(x)
  8769. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8770. (cat (get-text-property 1 'org-category x))
  8771. (tod (get-text-property 1 'time-of-day x))
  8772. (ok (or (null filter)
  8773. (and (stringp filter) (string-match filter evt))
  8774. (and (functionp filter) (funcall filter x))
  8775. (and (listp filter)
  8776. (let ((cat-filter (cadr (assoc 'category filter)))
  8777. (evt-filter (cadr (assoc 'headline filter))))
  8778. (or (and (stringp cat-filter)
  8779. (string-match cat-filter cat))
  8780. (and (stringp evt-filter)
  8781. (string-match evt-filter evt)))))))
  8782. (wrn (get-text-property 1 'warntime x)))
  8783. ;; FIXME: Shall we remove text-properties for the appt text?
  8784. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8785. (when (and ok tod)
  8786. (setq tod (concat "00" (number-to-string tod))
  8787. tod (when (string-match
  8788. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8789. (concat (match-string 1 tod) ":"
  8790. (match-string 2 tod))))
  8791. (if (version< emacs-version "23.3")
  8792. (appt-add tod evt)
  8793. (appt-add tod evt wrn))
  8794. (setq cnt (1+ cnt))))) entries)
  8795. (org-release-buffers org-agenda-new-buffers)
  8796. (if (eq cnt 0)
  8797. (message "No event to add")
  8798. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8799. (autoload 'org-agenda-to-appt "org-agenda" "\
  8800. Activate appointments found in `org-agenda-files'.
  8801. With a \\[universal-argument] prefix, refresh the list of
  8802. appointments.
  8803. If FILTER is t, interactively prompt the user for a regular
  8804. expression, and filter out entries that don't match it.
  8805. If FILTER is a string, use this string as a regular expression
  8806. for filtering entries out.
  8807. If FILTER is a function, filter out entries against which
  8808. calling the function returns nil. This function takes one
  8809. argument: an entry from `org-agenda-get-day-entries'.
  8810. FILTER can also be an alist with the car of each cell being
  8811. either 'headline or 'category. For example:
  8812. '((headline \"IMPORTANT\")
  8813. (category \"Work\"))
  8814. will only add headlines containing IMPORTANT or headlines
  8815. belonging to the \"Work\" category.
  8816. ARGS are symbols indicating what kind of entries to consider.
  8817. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8818. and :timestamp entries. See the docstring of `org-diary' for
  8819. details and examples.
  8820. If an entry as a APPT_WARNTIME property, its value will be used
  8821. to override `appt-message-warning-time'.
  8822. \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
  8823. (defun org-agenda-todayp (date)
  8824. "Does DATE mean today, when considering `org-extend-today-until'?"
  8825. (let ((today (org-today))
  8826. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8827. date)))
  8828. (eq date today)))
  8829. (defun org-agenda-todo-yesterday (&optional arg)
  8830. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8831. (interactive "P")
  8832. (let* ((hour (third (decode-time
  8833. (org-current-time))))
  8834. (org-extend-today-until (1+ hour)))
  8835. (org-agenda-todo arg)))
  8836. (provide 'org-agenda)
  8837. ;;; org-agenda.el ends here