org-agenda.el 308 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.4
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-span)
  217. (choice (const :tag "Day" 'day)
  218. (const :tag "Week" 'week)
  219. (const :tag "Month" 'month)
  220. (const :tag "Year" 'year)
  221. (integer :tag "Custom")))
  222. (list :tag "Fixed starting date"
  223. (const org-agenda-start-day)
  224. (string :value "2007-11-01"))
  225. (list :tag "Start on day of week"
  226. (const org-agenda-start-on-weekday)
  227. (choice :value 1
  228. (const :tag "Today" nil)
  229. (integer :tag "Weekday No.")))
  230. (list :tag "Include data from diary"
  231. (const org-agenda-include-diary)
  232. (boolean))
  233. (list :tag "Deadline Warning days"
  234. (const org-deadline-warning-days)
  235. (integer :value 1))
  236. (list :tag "Tags filter preset"
  237. (const org-agenda-filter-preset)
  238. (list
  239. (const :format "" quote)
  240. (repeat
  241. (string :tag "+tag or -tag"))))
  242. (list :tag "Set daily/weekly entry types"
  243. (const org-agenda-entry-types)
  244. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  245. (const :deadline)
  246. (const :scheduled)
  247. (const :timestamp)
  248. (const :sexp)))
  249. (list :tag "Standard skipping condition"
  250. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  251. (const org-agenda-skip-function)
  252. (list
  253. (const :format "" quote)
  254. (list
  255. (choice
  256. :tag "Skipping range"
  257. (const :tag "Skip entry" org-agenda-skip-entry-if)
  258. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  259. (repeat :inline t :tag "Conditions for skipping"
  260. (choice
  261. :tag "Condition type"
  262. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  263. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  264. (list :tag "TODO state is" :inline t
  265. (const 'todo)
  266. (choice
  267. (const :tag "any not-done state" 'todo)
  268. (const :tag "any done state" 'done)
  269. (const :tag "any state" 'any)
  270. (list :tag "Keyword list"
  271. (const :format "" quote)
  272. (repeat (string :tag "Keyword")))))
  273. (list :tag "TODO state is not" :inline t
  274. (const 'nottodo)
  275. (choice
  276. (const :tag "any not-done state" 'todo)
  277. (const :tag "any done state" 'done)
  278. (const :tag "any state" 'any)
  279. (list :tag "Keyword list"
  280. (const :format "" quote)
  281. (repeat (string :tag "Keyword")))))
  282. (const :tag "scheduled" 'scheduled)
  283. (const :tag "not scheduled" 'notscheduled)
  284. (const :tag "deadline" 'deadline)
  285. (const :tag "no deadline" 'notdeadline)
  286. (const :tag "timestamp" 'timestamp)
  287. (const :tag "no timestamp" 'nottimestamp))))))
  288. (list :tag "Non-standard skipping condition"
  289. :value (org-agenda-skip-function)
  290. (const org-agenda-skip-function)
  291. (sexp :tag "Function or form (quoted!)"))
  292. (list :tag "Any variable"
  293. (variable :tag "Variable")
  294. (sexp :tag "Value (sexp)"))))
  295. "Selection of examples for agenda command settings.
  296. This will be spliced into the custom type of
  297. `org-agenda-custom-commands'.")
  298. (defcustom org-agenda-custom-commands nil
  299. "Custom commands for the agenda.
  300. These commands will be offered on the splash screen displayed by the
  301. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  302. (key desc type match settings files)
  303. key The key (one or more characters as a string) to be associated
  304. with the command.
  305. desc A description of the command, when omitted or nil, a default
  306. description is built using MATCH.
  307. type The command type, any of the following symbols:
  308. agenda The daily/weekly agenda.
  309. todo Entries with a specific TODO keyword, in all agenda files.
  310. search Entries containing search words entry or headline.
  311. tags Tags/Property/TODO match in all agenda files.
  312. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  313. todo-tree Sparse tree of specific TODO keyword in *current* file.
  314. tags-tree Sparse tree with all tags matches in *current* file.
  315. occur-tree Occur sparse tree for *current* file.
  316. ... A user-defined function.
  317. match What to search for:
  318. - a single keyword for TODO keyword searches
  319. - a tags match expression for tags searches
  320. - a word search expression for text searches.
  321. - a regular expression for occur searches
  322. For all other commands, this should be the empty string.
  323. settings A list of option settings, similar to that in a let form, so like
  324. this: ((opt1 val1) (opt2 val2) ...). The values will be
  325. evaluated at the moment of execution, so quote them when needed.
  326. files A list of files file to write the produced agenda buffer to
  327. with the command `org-store-agenda-views'.
  328. If a file name ends in \".html\", an HTML version of the buffer
  329. is written out. If it ends in \".ps\", a postscript version is
  330. produced. Otherwise, only the plain text is written to the file.
  331. You can also define a set of commands, to create a composite agenda buffer.
  332. In this case, an entry looks like this:
  333. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  334. where
  335. desc A description string to be displayed in the dispatcher menu.
  336. cmd An agenda command, similar to the above. However, tree commands
  337. are no allowed, but instead you can get agenda and global todo list.
  338. So valid commands for a set are:
  339. (agenda \"\" settings)
  340. (alltodo \"\" settings)
  341. (stuck \"\" settings)
  342. (todo \"match\" settings files)
  343. (search \"match\" settings files)
  344. (tags \"match\" settings files)
  345. (tags-todo \"match\" settings files)
  346. Each command can carry a list of options, and another set of options can be
  347. given for the whole set of commands. Individual command options take
  348. precedence over the general options.
  349. When using several characters as key to a command, the first characters
  350. are prefix commands. For the dispatcher to display useful information, you
  351. should provide a description for the prefix, like
  352. (setq org-agenda-custom-commands
  353. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  354. (\"hl\" tags \"+HOME+Lisa\")
  355. (\"hp\" tags \"+HOME+Peter\")
  356. (\"hk\" tags \"+HOME+Kim\")))"
  357. :group 'org-agenda-custom-commands
  358. :type `(repeat
  359. (choice :value ("x" "Describe command here" tags "" nil)
  360. (list :tag "Single command"
  361. (string :tag "Access Key(s) ")
  362. (option (string :tag "Description"))
  363. (choice
  364. (const :tag "Agenda" agenda)
  365. (const :tag "TODO list" alltodo)
  366. (const :tag "Search words" search)
  367. (const :tag "Stuck projects" stuck)
  368. (const :tag "Tags/Property match (all agenda files)" tags)
  369. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  370. (const :tag "TODO keyword search (all agenda files)" todo)
  371. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  372. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  373. (const :tag "Occur tree (current buffer)" occur-tree)
  374. (sexp :tag "Other, user-defined function"))
  375. (string :tag "Match (only for some commands)")
  376. ,org-agenda-custom-commands-local-options
  377. (option (repeat :tag "Export" (file :tag "Export to"))))
  378. (list :tag "Command series, all agenda files"
  379. (string :tag "Access Key(s)")
  380. (string :tag "Description ")
  381. (repeat :tag "Component"
  382. (choice
  383. (list :tag "Agenda"
  384. (const :format "" agenda)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "TODO list (all keywords)"
  388. (const :format "" alltodo)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Search words"
  392. (const :format "" search)
  393. (string :tag "Match")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Stuck projects"
  396. (const :format "" stuck)
  397. (const :tag "" :format "" "")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search"
  400. (const :format "" tags)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search, TODO entries only"
  404. (const :format "" tags-todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "TODO keyword search"
  408. (const :format "" todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "Other, user-defined function"
  412. (symbol :tag "function")
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)))
  415. (repeat :tag "Settings for entire command set"
  416. (list (variable :tag "Any variable")
  417. (sexp :tag "Value")))
  418. (option (repeat :tag "Export" (file :tag "Export to"))))
  419. (cons :tag "Prefix key documentation"
  420. (string :tag "Access Key(s)")
  421. (string :tag "Description ")))))
  422. (defcustom org-agenda-query-register ?o
  423. "The register holding the current query string.
  424. The purpose of this is that if you construct a query string interactively,
  425. you can then use it to define a custom command."
  426. :group 'org-agenda-custom-commands
  427. :type 'character)
  428. (defcustom org-stuck-projects
  429. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  430. "How to identify stuck projects.
  431. This is a list of four items:
  432. 1. A tags/todo/property matcher string that is used to identify a project.
  433. See the manual for a description of tag and property searches.
  434. The entire tree below a headline matched by this is considered one project.
  435. 2. A list of TODO keywords identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these todo
  437. keywords, the project is considered to be not stuck. If you specify
  438. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  439. 3. A list of tags identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these tags,
  441. the project is considered to be not stuck. If you specify \"*\" as
  442. a tag, any tag will mark the project unstuck. Note that this is about
  443. the explicit presence of a tag somewhere in the subtree, inherited
  444. tags to not count here. If inherited tags make a project not stuck,
  445. use \"-TAG\" in the tags part of the matcher under (1.) above.
  446. 4. An arbitrary regular expression matching non-stuck projects.
  447. If the project turns out to be not stuck, search continues also in the
  448. subtree to see if any of the subtasks have project status.
  449. See also the variable `org-tags-match-list-sublevels' which applies
  450. to projects matched by this search as well.
  451. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  452. or `C-c a #' to produce the list."
  453. :group 'org-agenda-custom-commands
  454. :type '(list
  455. (string :tag "Tags/TODO match to identify a project")
  456. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  457. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  458. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  459. (defcustom org-agenda-filter-effort-default-operator "<"
  460. "The default operator for effort estimate filtering.
  461. If you select an effort estimate limit without first pressing an operator,
  462. this one will be used."
  463. :group 'org-agenda-custom-commands
  464. :type '(choice (const :tag "less or equal" "<")
  465. (const :tag "greater or equal"">")
  466. (const :tag "equal" "=")))
  467. (defgroup org-agenda-skip nil
  468. "Options concerning skipping parts of agenda files."
  469. :tag "Org Agenda Skip"
  470. :group 'org-agenda)
  471. (defgroup org-agenda-daily/weekly nil
  472. "Options concerning the daily/weekly agenda."
  473. :tag "Org Agenda Daily/Weekly"
  474. :group 'org-agenda)
  475. (defgroup org-agenda-todo-list nil
  476. "Options concerning the global todo list agenda view."
  477. :tag "Org Agenda Todo List"
  478. :group 'org-agenda)
  479. (defgroup org-agenda-match-view nil
  480. "Options concerning the general tags/property/todo match agenda view."
  481. :tag "Org Agenda Match View"
  482. :group 'org-agenda)
  483. (defgroup org-agenda-search-view nil
  484. "Options concerning the general tags/property/todo match agenda view."
  485. :tag "Org Agenda Match View"
  486. :group 'org-agenda)
  487. (defvar org-agenda-archives-mode nil
  488. "Non-nil means the agenda will include archived items.
  489. If this is the symbol `trees', trees in the selected agenda scope
  490. that are marked with the ARCHIVE tag will be included anyway. When this is
  491. t, also all archive files associated with the current selection of agenda
  492. files will be included.")
  493. (defcustom org-agenda-skip-comment-trees t
  494. "Non-nil means skip trees that start with the COMMENT keyword.
  495. When nil, these trees are also scanned by agenda commands."
  496. :group 'org-agenda-skip
  497. :type 'boolean)
  498. (defcustom org-agenda-todo-list-sublevels t
  499. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  500. When nil, the sublevels of a TODO entry are not checked, resulting in
  501. potentially much shorter TODO lists."
  502. :group 'org-agenda-skip
  503. :group 'org-agenda-todo-list
  504. :type 'boolean)
  505. (defcustom org-agenda-todo-ignore-with-date nil
  506. "Non-nil means don't show entries with a date in the global todo list.
  507. You can use this if you prefer to mark mere appointments with a TODO keyword,
  508. but don't want them to show up in the TODO list.
  509. When this is set, it also covers deadlines and scheduled items, the settings
  510. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  511. will be ignored.
  512. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  513. :group 'org-agenda-skip
  514. :group 'org-agenda-todo-list
  515. :type 'boolean)
  516. (defcustom org-agenda-todo-ignore-timestamp nil
  517. "Non-nil means don't show entries with a timestamp.
  518. This applies when creating the global todo list.
  519. Valid values are:
  520. past Don't show entries for today or in the past.
  521. future Don't show entries with a timestamp in the future.
  522. The idea behind this is that if it has a future
  523. timestamp, you don't want to think about it until the
  524. date.
  525. all Don't show any entries with a timestamp in the global todo list.
  526. The idea behind this is that by setting a timestamp, you
  527. have already \"taken care\" of this item.
  528. See also `org-agenda-todo-ignore-with-date'.
  529. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  530. to make his option also apply to the tags-todo list."
  531. :group 'org-agenda-skip
  532. :group 'org-agenda-todo-list
  533. :type '(choice
  534. (const :tag "Ignore future timestamp todos" future)
  535. (const :tag "Ignore past or present timestamp todos" past)
  536. (const :tag "Ignore all timestamp todos" all)
  537. (const :tag "Show timestamp todos" nil)))
  538. (defcustom org-agenda-todo-ignore-scheduled nil
  539. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  540. This applies when creating the global todo list.
  541. Valid values are:
  542. past Don't show entries scheduled today or in the past.
  543. future Don't show entries scheduled in the future.
  544. The idea behind this is that by scheduling it, you don't want to
  545. think about it until the scheduled date.
  546. all Don't show any scheduled entries in the global todo list.
  547. The idea behind this is that by scheduling it, you have already
  548. \"taken care\" of this item.
  549. t Same as `all', for backward compatibility.
  550. See also `org-agenda-todo-ignore-with-date'.
  551. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  552. to make his option also apply to the tags-todo list."
  553. :group 'org-agenda-skip
  554. :group 'org-agenda-todo-list
  555. :type '(choice
  556. (const :tag "Ignore future-scheduled todos" future)
  557. (const :tag "Ignore past- or present-scheduled todos" past)
  558. (const :tag "Ignore all scheduled todos" all)
  559. (const :tag "Ignore all scheduled todos (compatibility)" t)
  560. (const :tag "Show scheduled todos" nil)))
  561. (defcustom org-agenda-todo-ignore-deadlines nil
  562. "Non-nil means ignore some deadlined TODO items when making TODO list.
  563. There are different motivations for using different values, please think
  564. carefully when configuring this variable.
  565. This applies when creating the global todo list.
  566. Valid values are:
  567. near Don't show near deadline entries. A deadline is near when it is
  568. closer than `org-deadline-warning-days' days. The idea behind this
  569. is that such items will appear in the agenda anyway.
  570. far Don't show TODO entries where a deadline has been defined, but
  571. the deadline is not near. This is useful if you don't want to
  572. use the todo list to figure out what to do now.
  573. past Don't show entries with a deadline timestamp for today or in the past.
  574. future Don't show entries with a deadline timestamp in the future, not even
  575. when they become `near' ones. Use it with caution.
  576. all Ignore all TODO entries that do have a deadline.
  577. t Same as `near', for backward compatibility.
  578. See also `org-agenda-todo-ignore-with-date'.
  579. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  580. to make his option also apply to the tags-todo list."
  581. :group 'org-agenda-skip
  582. :group 'org-agenda-todo-list
  583. :type '(choice
  584. (const :tag "Ignore near deadlines" near)
  585. (const :tag "Ignore near deadlines (compatibility)" t)
  586. (const :tag "Ignore far deadlines" far)
  587. (const :tag "Ignore all TODOs with a deadlines" all)
  588. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  589. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  590. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  591. The variables
  592. `org-agenda-todo-ignore-with-date',
  593. `org-agenda-todo-ignore-timestamp',
  594. `org-agenda-todo-ignore-scheduled',
  595. `org-agenda-todo-ignore-deadlines'
  596. make the global TODO list skip entries that have time stamps of certain
  597. kinds. If this option is set, the same options will also apply for the
  598. tags-todo search, which is the general tags/property matcher
  599. restricted to unfinished TODO entries only."
  600. :group 'org-agenda-skip
  601. :group 'org-agenda-todo-list
  602. :group 'org-agenda-match-view
  603. :type 'boolean)
  604. (defcustom org-agenda-skip-scheduled-if-done nil
  605. "Non-nil means don't show scheduled items in agenda when they are done.
  606. This is relevant for the daily/weekly agenda, not for the TODO list. And
  607. it applies only to the actual date of the scheduling. Warnings about
  608. an item with a past scheduling dates are always turned off when the item
  609. is DONE."
  610. :group 'org-agenda-skip
  611. :group 'org-agenda-daily/weekly
  612. :type 'boolean)
  613. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  614. "Non-nil means skip scheduling line if same entry shows because of deadline.
  615. In the agenda of today, an entry can show up multiple times because
  616. it is both scheduled and has a nearby deadline, and maybe a plain time
  617. stamp as well.
  618. When this variable is t, then only the deadline is shown and the fact that
  619. the entry is scheduled today or was scheduled previously is not shown.
  620. When this variable is nil, the entry will be shown several times. When
  621. the variable is the symbol `not-today', then skip scheduled previously,
  622. but not scheduled today."
  623. :group 'org-agenda-skip
  624. :group 'org-agenda-daily/weekly
  625. :type '(choice
  626. (const :tag "Never" nil)
  627. (const :tag "Always" t)
  628. (const :tag "Not when scheduled today" not-today)))
  629. (defcustom org-agenda-skip-deadline-if-done nil
  630. "Non-nil means don't show deadlines when the corresponding item is done.
  631. When nil, the deadline is still shown and should give you a happy feeling.
  632. This is relevant for the daily/weekly agenda. And it applied only to the
  633. actually date of the deadline. Warnings about approaching and past-due
  634. deadlines are always turned off when the item is DONE."
  635. :group 'org-agenda-skip
  636. :group 'org-agenda-daily/weekly
  637. :type 'boolean)
  638. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  639. "Non-nil means skip deadline prewarning when entry is also scheduled.
  640. This will apply on all days where a prewarning for the deadline would
  641. be shown, but not at the day when the entry is actually due. On that day,
  642. the deadline will be shown anyway.
  643. This variable may be set to nil, t, or a number which will then give
  644. the number of days before the actual deadline when the prewarnings
  645. should resume.
  646. This can be used in a workflow where the first showing of the deadline will
  647. trigger you to schedule it, and then you don't want to be reminded of it
  648. because you will take care of it on the day when scheduled."
  649. :group 'org-agenda-skip
  650. :group 'org-agenda-daily/weekly
  651. :type '(choice
  652. (const :tag "Alwas show prewarning" nil)
  653. (const :tag "Remove prewarning if entry is scheduled" t)
  654. (integer :tag "Restart prewarning N days before deadline")))
  655. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  656. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  657. When non-nil, after the search for timestamps has matched once in an
  658. entry, the rest of the entry will not be searched."
  659. :group 'org-agenda-skip
  660. :type 'boolean)
  661. (defcustom org-agenda-skip-timestamp-if-done nil
  662. "Non-nil means don't select item by timestamp or -range if it is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-dim-blocked-tasks t
  667. "Non-nil means dim blocked tasks in the agenda display.
  668. This causes some overhead during agenda construction, but if you
  669. have turned on `org-enforce-todo-dependencies',
  670. `org-enforce-todo-checkbox-dependencies', or any other blocking
  671. mechanism, this will create useful feedback in the agenda.
  672. Instead of t, this variable can also have the value `invisible'.
  673. Then blocked tasks will be invisible and only become visible when
  674. they become unblocked. An exemption to this behavior is when a task is
  675. blocked because of unchecked checkboxes below it. Since checkboxes do
  676. not show up in the agenda views, making this task invisible you remove any
  677. trace from agenda views that there is something to do. Therefore, a task
  678. that is blocked because of checkboxes will never be made invisible, it
  679. will only be dimmed."
  680. :group 'org-agenda-daily/weekly
  681. :group 'org-agenda-todo-list
  682. :type '(choice
  683. (const :tag "Do not dim" nil)
  684. (const :tag "Dim to a grey face" t)
  685. (const :tag "Make invisible" invisible)))
  686. (defcustom org-timeline-show-empty-dates 3
  687. "Non-nil means `org-timeline' also shows dates without an entry.
  688. When nil, only the days which actually have entries are shown.
  689. When t, all days between the first and the last date are shown.
  690. When an integer, show also empty dates, but if there is a gap of more than
  691. N days, just insert a special line indicating the size of the gap."
  692. :group 'org-agenda-skip
  693. :type '(choice
  694. (const :tag "None" nil)
  695. (const :tag "All" t)
  696. (integer :tag "at most")))
  697. (defgroup org-agenda-startup nil
  698. "Options concerning initial settings in the Agenda in Org Mode."
  699. :tag "Org Agenda Startup"
  700. :group 'org-agenda)
  701. (defcustom org-agenda-menu-show-matcher t
  702. "Non-nil menas show the match string in the agenda dispatcher menu.
  703. When nil, the matcher string is not shown, but is put into the help-echo
  704. property so than moving the mouse over the command shows it.
  705. Setting it to nil is good if matcher strings are very long and/or if
  706. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  707. :group 'org-agenda
  708. :type 'boolean)
  709. (defcustom org-agenda-menu-two-column nil
  710. "Non-nil means, use two columns to show custom commands in the dispatcher.
  711. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  712. to nil."
  713. :group 'org-agenda
  714. :type 'boolean)
  715. (defcustom org-finalize-agenda-hook nil
  716. "Hook run just before displaying an agenda buffer."
  717. :group 'org-agenda-startup
  718. :type 'hook)
  719. (defcustom org-agenda-mouse-1-follows-link nil
  720. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  721. A longer mouse click will still set point. Does not work on XEmacs.
  722. Needs to be set before org.el is loaded."
  723. :group 'org-agenda-startup
  724. :type 'boolean)
  725. (defcustom org-agenda-start-with-follow-mode nil
  726. "The initial value of follow mode in a newly created agenda window."
  727. :group 'org-agenda-startup
  728. :type 'boolean)
  729. (defcustom org-agenda-show-outline-path t
  730. "Non-nil means show outline path in echo area after line motion."
  731. :group 'org-agenda-startup
  732. :type 'boolean)
  733. (defcustom org-agenda-start-with-entry-text-mode nil
  734. "The initial value of entry-text-mode in a newly created agenda window."
  735. :group 'org-agenda-startup
  736. :type 'boolean)
  737. (defcustom org-agenda-entry-text-maxlines 5
  738. "Number of text lines to be added when `E' is pressed in the agenda.
  739. Note that this variable only used during agenda display. Add add entry text
  740. when exporting the agenda, configure the variable
  741. `org-agenda-add-entry-ext-maxlines'."
  742. :group 'org-agenda
  743. :type 'integer)
  744. (defcustom org-agenda-entry-text-exclude-regexps nil
  745. "List of regular expressions to clean up entry text.
  746. The complete matches of all regular expressions in this list will be
  747. removed from entry text before it is shown in the agenda."
  748. :group 'org-agenda
  749. :type '(repeat (regexp)))
  750. (defvar org-agenda-entry-text-cleanup-hook nil
  751. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  752. This cleanup is done in a temporary buffer, so the function may inspect and
  753. change the entire buffer.
  754. Some default stuff like drawers and scheduling/deadline dates will already
  755. have been removed when this is called, as will any matches for regular
  756. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  757. (defvar org-agenda-include-inactive-timestamps nil
  758. "Non-nil means include inactive time stamps in agenda and timeline.")
  759. (defgroup org-agenda-windows nil
  760. "Options concerning the windows used by the Agenda in Org Mode."
  761. :tag "Org Agenda Windows"
  762. :group 'org-agenda)
  763. (defcustom org-agenda-window-setup 'reorganize-frame
  764. "How the agenda buffer should be displayed.
  765. Possible values for this option are:
  766. current-window Show agenda in the current window, keeping all other windows.
  767. other-window Use `switch-to-buffer-other-window' to display agenda.
  768. reorganize-frame Show only two windows on the current frame, the current
  769. window and the agenda.
  770. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  771. Also, when exiting the agenda, kill that frame.
  772. See also the variable `org-agenda-restore-windows-after-quit'."
  773. :group 'org-agenda-windows
  774. :type '(choice
  775. (const current-window)
  776. (const other-frame)
  777. (const other-window)
  778. (const reorganize-frame)))
  779. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  780. "The min and max height of the agenda window as a fraction of frame height.
  781. The value of the variable is a cons cell with two numbers between 0 and 1.
  782. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  783. :group 'org-agenda-windows
  784. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  785. (defcustom org-agenda-restore-windows-after-quit nil
  786. "Non-nil means restore window configuration open exiting agenda.
  787. Before the window configuration is changed for displaying the agenda,
  788. the current status is recorded. When the agenda is exited with
  789. `q' or `x' and this option is set, the old state is restored. If
  790. `org-agenda-window-setup' is `other-frame', the value of this
  791. option will be ignored."
  792. :group 'org-agenda-windows
  793. :type 'boolean)
  794. (defcustom org-agenda-ndays nil
  795. "Number of days to include in overview display.
  796. Should be 1 or 7.
  797. Obsolete, see `org-agenda-span'."
  798. :group 'org-agenda-daily/weekly
  799. :type 'integer)
  800. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  801. (defcustom org-agenda-span 'week
  802. "Number of days to include in overview display.
  803. Can be day, week, month, year, or any number of days.
  804. Custom commands can set this variable in the options section."
  805. :group 'org-agenda-daily/weekly
  806. :type '(choice (const :tag "Day" day)
  807. (const :tag "Week" week)
  808. (const :tag "Month" month)
  809. (const :tag "Year" year)
  810. (integer :tag "Custom")))
  811. (defcustom org-agenda-start-on-weekday 1
  812. "Non-nil means start the overview always on the specified weekday.
  813. 0 denotes Sunday, 1 denotes Monday etc.
  814. When nil, always start on the current day.
  815. Custom commands can set this variable in the options section."
  816. :group 'org-agenda-daily/weekly
  817. :type '(choice (const :tag "Today" nil)
  818. (integer :tag "Weekday No.")))
  819. (defcustom org-agenda-show-all-dates t
  820. "Non-nil means `org-agenda' shows every day in the selected range.
  821. When nil, only the days which actually have entries are shown."
  822. :group 'org-agenda-daily/weekly
  823. :type 'boolean)
  824. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  825. "Format string for displaying dates in the agenda.
  826. Used by the daily/weekly agenda and by the timeline. This should be
  827. a format string understood by `format-time-string', or a function returning
  828. the formatted date as a string. The function must take a single argument,
  829. a calendar-style date list like (month day year)."
  830. :group 'org-agenda-daily/weekly
  831. :type '(choice
  832. (string :tag "Format string")
  833. (function :tag "Function")))
  834. (defun org-agenda-format-date-aligned (date)
  835. "Format a date string for display in the daily/weekly agenda, or timeline.
  836. This function makes sure that dates are aligned for easy reading."
  837. (require 'cal-iso)
  838. (let* ((dayname (calendar-day-name date))
  839. (day (cadr date))
  840. (day-of-week (calendar-day-of-week date))
  841. (month (car date))
  842. (monthname (calendar-month-name month))
  843. (year (nth 2 date))
  844. (iso-week (org-days-to-iso-week
  845. (calendar-absolute-from-gregorian date)))
  846. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  847. (1- year))
  848. ((and (= month 12) (<= iso-week 1))
  849. (1+ year))
  850. (t year)))
  851. (weekstring (if (= day-of-week 1)
  852. (format " W%02d" iso-week)
  853. "")))
  854. (format "%-10s %2d %s %4d%s"
  855. dayname day monthname year weekstring)))
  856. (defcustom org-agenda-time-leading-zero nil
  857. "Non-nil means use leading zero for military times in agenda.
  858. For example, 9:30am would become 09:30 rather than 9:30."
  859. :group 'org-agenda-daily/weekly
  860. :type 'boolean)
  861. (defcustom org-agenda-timegrid-use-ampm nil
  862. "When set, show AM/PM style timestamps on the timegrid."
  863. :group 'org-agenda
  864. :type 'boolean)
  865. (defun org-agenda-time-of-day-to-ampm (time)
  866. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  867. (let* ((hour-number (string-to-number (substring time 0 -3)))
  868. (minute (substring time -2))
  869. (ampm "am"))
  870. (cond
  871. ((equal hour-number 12)
  872. (setq ampm "pm"))
  873. ((> hour-number 12)
  874. (setq ampm "pm")
  875. (setq hour-number (- hour-number 12))))
  876. (concat
  877. (if org-agenda-time-leading-zero
  878. (format "%02d" hour-number)
  879. (format "%02s" (number-to-string hour-number)))
  880. ":" minute ampm)))
  881. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  882. "Conditionally convert TIME to AM/PM format
  883. based on `org-agenda-timegrid-use-ampm'"
  884. (if org-agenda-timegrid-use-ampm
  885. (org-agenda-time-of-day-to-ampm time)
  886. time))
  887. (defcustom org-agenda-weekend-days '(6 0)
  888. "Which days are weekend?
  889. These days get the special face `org-agenda-date-weekend' in the agenda
  890. and timeline buffers."
  891. :group 'org-agenda-daily/weekly
  892. :type '(set :greedy t
  893. (const :tag "Monday" 1)
  894. (const :tag "Tuesday" 2)
  895. (const :tag "Wednesday" 3)
  896. (const :tag "Thursday" 4)
  897. (const :tag "Friday" 5)
  898. (const :tag "Saturday" 6)
  899. (const :tag "Sunday" 0)))
  900. (defcustom org-agenda-include-diary nil
  901. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  902. Custom commands can set this variable in the options section."
  903. :group 'org-agenda-daily/weekly
  904. :type 'boolean)
  905. (defcustom org-agenda-include-deadlines t
  906. "If non-nil, include entries within their deadline warning period.
  907. Custom commands can set this variable in the options section."
  908. :group 'org-agenda-daily/weekly
  909. :type 'boolean)
  910. (defcustom org-agenda-include-all-todo nil
  911. "Set means weekly/daily agenda will always contain all TODO entries.
  912. The TODO entries will be listed at the top of the agenda, before
  913. the entries for specific days.
  914. This option is deprecated, it is better to define a block agenda instead."
  915. :group 'org-agenda-daily/weekly
  916. :type 'boolean)
  917. (defcustom org-agenda-repeating-timestamp-show-all t
  918. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  919. When nil, only one occurrence is shown, either today or the
  920. nearest into the future."
  921. :group 'org-agenda-daily/weekly
  922. :type 'boolean)
  923. (defcustom org-scheduled-past-days 10000
  924. "No. of days to continue listing scheduled items that are not marked DONE.
  925. When an item is scheduled on a date, it shows up in the agenda on this
  926. day and will be listed until it is marked done for the number of days
  927. given here."
  928. :group 'org-agenda-daily/weekly
  929. :type 'integer)
  930. (defcustom org-agenda-log-mode-items '(closed clock)
  931. "List of items that should be shown in agenda log mode.
  932. This list may contain the following symbols:
  933. closed Show entries that have been closed on that day.
  934. clock Show entries that have received clocked time on that day.
  935. state Show all logged state changes.
  936. Note that instead of changing this variable, you can also press `C-u l' in
  937. the agenda to display all available LOG items temporarily."
  938. :group 'org-agenda-daily/weekly
  939. :type '(set :greedy t (const closed) (const clock) (const state)))
  940. (defcustom org-agenda-log-mode-add-notes t
  941. "Non-nil means add first line of notes to log entries in agenda views.
  942. If a log item like a state change or a clock entry is associated with
  943. notes, the first line of these notes will be added to the entry in the
  944. agenda display."
  945. :group 'org-agenda-daily/weekly
  946. :type 'boolean)
  947. (defcustom org-agenda-start-with-log-mode nil
  948. "The initial value of log-mode in a newly created agenda window."
  949. :group 'org-agenda-startup
  950. :group 'org-agenda-daily/weekly
  951. :type 'boolean)
  952. (defcustom org-agenda-start-with-clockreport-mode nil
  953. "The initial value of clockreport-mode in a newly created agenda window."
  954. :group 'org-agenda-startup
  955. :group 'org-agenda-daily/weekly
  956. :type 'boolean)
  957. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  958. "Property list with parameters for the clocktable in clockreport mode.
  959. This is the display mode that shows a clock table in the daily/weekly
  960. agenda, the properties for this dynamic block can be set here.
  961. The usual clocktable parameters are allowed here, but you cannot set
  962. the properties :name, :tstart, :tend, :block, and :scope - these will
  963. be overwritten to make sure the content accurately reflects the
  964. current display in the agenda."
  965. :group 'org-agenda-daily/weekly
  966. :type 'plist)
  967. (defcustom org-agenda-search-view-always-boolean nil
  968. "Non-nil means the search string is interpreted as individual parts.
  969. The search string for search view can either be interpreted as a phrase,
  970. or as a list of snippets that define a boolean search for a number of
  971. strings.
  972. When this is non-nil, the string will be split on whitespace, and each
  973. snippet will be searched individually, and all must match in order to
  974. select an entry. A snippet is then a single string of non-white
  975. characters, or a string in double quotes, or a regexp in {} braces.
  976. If a snippet is preceded by \"-\", the snippet must *not* match.
  977. \"+\" is syntactic sugar for positive selection. Each snippet may
  978. be found as a full word or a partial word, but see the variable
  979. `org-agenda-search-view-force-full-words'.
  980. When this is nil, search will look for the entire search phrase as one,
  981. with each space character matching any amount of whitespace, including
  982. line breaks.
  983. Even when this is nil, you can still switch to Boolean search dynamically
  984. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  985. is a regexp marked with braces like \"{abc}\", this will also switch to
  986. boolean search."
  987. :group 'org-agenda-search-view
  988. :type 'boolean)
  989. (if (fboundp 'defvaralias)
  990. (defvaralias 'org-agenda-search-view-search-words-only
  991. 'org-agenda-search-view-always-boolean))
  992. (defcustom org-agenda-search-view-force-full-words nil
  993. "Non-nil means, search words must be matches as complete words.
  994. When nil, they may also match part of a word."
  995. :group 'org-agenda-search-view
  996. :type 'boolean)
  997. (defgroup org-agenda-time-grid nil
  998. "Options concerning the time grid in the Org-mode Agenda."
  999. :tag "Org Agenda Time Grid"
  1000. :group 'org-agenda)
  1001. (defcustom org-agenda-search-headline-for-time t
  1002. "Non-nil means search headline for a time-of-day.
  1003. If the headline contains a time-of-day in one format or another, it will
  1004. be used to sort the entry into the time sequence of items for a day.
  1005. Some people have time stamps in the headline that refer to the creation
  1006. time or so, and then this produces an unwanted side effect. If this is
  1007. the case for your, use this variable to turn off searching the headline
  1008. for a time."
  1009. :group 'org-agenda-time-grid
  1010. :type 'boolean)
  1011. (defcustom org-agenda-use-time-grid t
  1012. "Non-nil means show a time grid in the agenda schedule.
  1013. A time grid is a set of lines for specific times (like every two hours between
  1014. 8:00 and 20:00). The items scheduled for a day at specific times are
  1015. sorted in between these lines.
  1016. For details about when the grid will be shown, and what it will look like, see
  1017. the variable `org-agenda-time-grid'."
  1018. :group 'org-agenda-time-grid
  1019. :type 'boolean)
  1020. (defcustom org-agenda-time-grid
  1021. '((daily today require-timed)
  1022. "----------------"
  1023. (800 1000 1200 1400 1600 1800 2000))
  1024. "The settings for time grid for agenda display.
  1025. This is a list of three items. The first item is again a list. It contains
  1026. symbols specifying conditions when the grid should be displayed:
  1027. daily if the agenda shows a single day
  1028. weekly if the agenda shows an entire week
  1029. today show grid on current date, independent of daily/weekly display
  1030. require-timed show grid only if at least one item has a time specification
  1031. The second item is a string which will be placed behind the grid time.
  1032. The third item is a list of integers, indicating the times that should have
  1033. a grid line."
  1034. :group 'org-agenda-time-grid
  1035. :type
  1036. '(list
  1037. (set :greedy t :tag "Grid Display Options"
  1038. (const :tag "Show grid in single day agenda display" daily)
  1039. (const :tag "Show grid in weekly agenda display" weekly)
  1040. (const :tag "Always show grid for today" today)
  1041. (const :tag "Show grid only if any timed entries are present"
  1042. require-timed)
  1043. (const :tag "Skip grid times already present in an entry"
  1044. remove-match))
  1045. (string :tag "Grid String")
  1046. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1047. (defcustom org-agenda-show-current-time-in-grid t
  1048. "Non-nil means show the current time in the time grid."
  1049. :group 'org-agenda-time-grid
  1050. :type 'boolean)
  1051. (defcustom org-agenda-current-time-string
  1052. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1053. "The string for the current time marker in the agenda."
  1054. :group 'org-agenda-time-grid
  1055. :type 'string)
  1056. (defgroup org-agenda-sorting nil
  1057. "Options concerning sorting in the Org-mode Agenda."
  1058. :tag "Org Agenda Sorting"
  1059. :group 'org-agenda)
  1060. (defcustom org-agenda-sorting-strategy
  1061. '((agenda habit-down time-up priority-down category-keep)
  1062. (todo priority-down category-keep)
  1063. (tags priority-down category-keep)
  1064. (search category-keep))
  1065. "Sorting structure for the agenda items of a single day.
  1066. This is a list of symbols which will be used in sequence to determine
  1067. if an entry should be listed before another entry. The following
  1068. symbols are recognized:
  1069. time-up Put entries with time-of-day indications first, early first
  1070. time-down Put entries with time-of-day indications first, late first
  1071. category-keep Keep the default order of categories, corresponding to the
  1072. sequence in `org-agenda-files'.
  1073. category-up Sort alphabetically by category, A-Z.
  1074. category-down Sort alphabetically by category, Z-A.
  1075. tag-up Sort alphabetically by last tag, A-Z.
  1076. tag-down Sort alphabetically by last tag, Z-A.
  1077. priority-up Sort numerically by priority, high priority last.
  1078. priority-down Sort numerically by priority, high priority first.
  1079. todo-state-up Sort by todo state, tasks that are done last.
  1080. todo-state-down Sort by todo state, tasks that are done first.
  1081. effort-up Sort numerically by estimated effort, high effort last.
  1082. effort-down Sort numerically by estimated effort, high effort first.
  1083. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1084. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1085. habit-up Put entries that are habits first
  1086. habit-down Put entries that are habits last
  1087. alpha-up Sort headlines alphabetically
  1088. alpha-down Sort headlines alphabetically, reversed
  1089. The different possibilities will be tried in sequence, and testing stops
  1090. if one comparison returns a \"not-equal\". For example, the default
  1091. '(time-up category-keep priority-down)
  1092. means: Pull out all entries having a specified time of day and sort them,
  1093. in order to make a time schedule for the current day the first thing in the
  1094. agenda listing for the day. Of the entries without a time indication, keep
  1095. the grouped in categories, don't sort the categories, but keep them in
  1096. the sequence given in `org-agenda-files'. Within each category sort by
  1097. priority.
  1098. Leaving out `category-keep' would mean that items will be sorted across
  1099. categories by priority.
  1100. Instead of a single list, this can also be a set of list for specific
  1101. contents, with a context symbol in the car of the list, any of
  1102. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1103. Custom commands can bind this variable in the options section."
  1104. :group 'org-agenda-sorting
  1105. :type `(choice
  1106. (repeat :tag "General" ,org-sorting-choice)
  1107. (list :tag "Individually"
  1108. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1109. (repeat ,org-sorting-choice))
  1110. (cons (const :tag "Strategy for TODO lists" todo)
  1111. (repeat ,org-sorting-choice))
  1112. (cons (const :tag "Strategy for Tags matches" tags)
  1113. (repeat ,org-sorting-choice))
  1114. (cons (const :tag "Strategy for search matches" search)
  1115. (repeat ,org-sorting-choice)))))
  1116. (defcustom org-agenda-cmp-user-defined nil
  1117. "A function to define the comparison `user-defined'.
  1118. This function must receive two arguments, agenda entry a and b.
  1119. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1120. the user comparison, return nil.
  1121. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1122. part of an agenda sorting strategy."
  1123. :group 'org-agenda-sorting
  1124. :type 'symbol)
  1125. (defcustom org-sort-agenda-notime-is-late t
  1126. "Non-nil means items without time are considered late.
  1127. This is only relevant for sorting. When t, items which have no explicit
  1128. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1129. do have a time. When nil, the default time is before 0:00. You can use this
  1130. option to decide if the schedule for today should come before or after timeless
  1131. agenda entries."
  1132. :group 'org-agenda-sorting
  1133. :type 'boolean)
  1134. (defcustom org-sort-agenda-noeffort-is-high t
  1135. "Non-nil means items without effort estimate are sorted as high effort.
  1136. This also applies when filtering an agenda view with respect to the
  1137. < or > effort operator. Then, tasks with no effort defined will be treated
  1138. as tasks with high effort.
  1139. When nil, such items are sorted as 0 minutes effort."
  1140. :group 'org-agenda-sorting
  1141. :type 'boolean)
  1142. (defgroup org-agenda-line-format nil
  1143. "Options concerning the entry prefix in the Org-mode agenda display."
  1144. :tag "Org Agenda Line Format"
  1145. :group 'org-agenda)
  1146. (defcustom org-agenda-prefix-format
  1147. '((agenda . " %i %-12:c%?-12t% s")
  1148. (timeline . " % s")
  1149. (todo . " %i %-12:c")
  1150. (tags . " %i %-12:c")
  1151. (search . " %i %-12:c"))
  1152. "Format specifications for the prefix of items in the agenda views.
  1153. An alist with four entries, for the different agenda types. The keys to the
  1154. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1155. are format strings.
  1156. This format works similar to a printf format, with the following meaning:
  1157. %c the category of the item, \"Diary\" for entries from the diary, or
  1158. as given by the CATEGORY keyword or derived from the file name.
  1159. %i the icon category of the item, as give in
  1160. `org-agenda-category-icon-alist'.
  1161. %T the *last* tag of the item. Last because inherited tags come
  1162. first in the list.
  1163. %t the time-of-day specification if one applies to the entry, in the
  1164. format HH:MM
  1165. %s Scheduling/Deadline information, a short string
  1166. All specifiers work basically like the standard `%s' of printf, but may
  1167. contain two additional characters: A question mark just after the `%' and
  1168. a whitespace/punctuation character just before the final letter.
  1169. If the first character after `%' is a question mark, the entire field
  1170. will only be included if the corresponding value applies to the
  1171. current entry. This is useful for fields which should have fixed
  1172. width when present, but zero width when absent. For example,
  1173. \"%?-12t\" will result in a 12 character time field if a time of the
  1174. day is specified, but will completely disappear in entries which do
  1175. not contain a time.
  1176. If there is punctuation or whitespace character just before the final
  1177. format letter, this character will be appended to the field value if
  1178. the value is not empty. For example, the format \"%-12:c\" leads to
  1179. \"Diary: \" if the category is \"Diary\". If the category were be
  1180. empty, no additional colon would be inserted.
  1181. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1182. - Indent the line with two space characters
  1183. - Give the category in a 12 chars wide field, padded with whitespace on
  1184. the right (because of `-'). Append a colon if there is a category
  1185. (because of `:').
  1186. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1187. time, don't put in an empty field, just skip it (because of '?').
  1188. - Finally, put the scheduling information and append a whitespace.
  1189. As another example, if you don't want the time-of-day of entries in
  1190. the prefix, you could use:
  1191. (setq org-agenda-prefix-format \" %-11:c% s\")
  1192. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1193. `org-agenda-remove-tags'.
  1194. Custom commands can set this variable in the options section."
  1195. :type '(choice
  1196. (string :tag "General format")
  1197. (list :greedy t :tag "View dependent"
  1198. (cons (const agenda) (string :tag "Format"))
  1199. (cons (const timeline) (string :tag "Format"))
  1200. (cons (const todo) (string :tag "Format"))
  1201. (cons (const tags) (string :tag "Format"))
  1202. (cons (const search) (string :tag "Format"))))
  1203. :group 'org-agenda-line-format)
  1204. (defvar org-prefix-format-compiled nil
  1205. "The compiled version of the most recently used prefix format.
  1206. See the variable `org-agenda-prefix-format'.")
  1207. (defcustom org-agenda-todo-keyword-format "%-1s"
  1208. "Format for the TODO keyword in agenda lines.
  1209. Set this to something like \"%-12s\" if you want all TODO keywords
  1210. to occupy a fixed space in the agenda display."
  1211. :group 'org-agenda-line-format
  1212. :type 'string)
  1213. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1214. "Text preceding timerange entries in the agenda view.
  1215. This is a list with two strings. The first applies when the range
  1216. is entirely on one day. The second applies if the range spans several days.
  1217. The strings may have two \"%d\" format specifiers which will be filled
  1218. with the sequence number of the days, and the total number of days in the
  1219. range, respectively."
  1220. :group 'org-agenda-line-format
  1221. :type '(list
  1222. (string :tag "Deadline today ")
  1223. (choice :tag "Deadline relative"
  1224. (string :tag "Format string")
  1225. (function))))
  1226. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1227. "Text preceding scheduled items in the agenda view.
  1228. This is a list with two strings. The first applies when the item is
  1229. scheduled on the current day. The second applies when it has been scheduled
  1230. previously, it may contain a %d indicating that this is the nth time that
  1231. this item is scheduled, due to automatic rescheduling of unfinished items
  1232. for the following day. So this number is one larger than the number of days
  1233. that passed since this item was scheduled first."
  1234. :group 'org-agenda-line-format
  1235. :type '(list
  1236. (string :tag "Scheduled today ")
  1237. (string :tag "Scheduled previously")))
  1238. (defcustom org-agenda-inactive-leader "["
  1239. "Text preceding item pulled into the agenda by inactive time stamps.
  1240. These entries are added to the agenda when pressing \"[\"."
  1241. :group 'org-agenda-line-format
  1242. :type '(list
  1243. (string :tag "Scheduled today ")
  1244. (string :tag "Scheduled previously")))
  1245. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1246. "Text preceding deadline items in the agenda view.
  1247. This is a list with two strings. The first applies when the item has its
  1248. deadline on the current day. The second applies when it is in the past or
  1249. in the future, it may contain %d to capture how many days away the deadline
  1250. is (was)."
  1251. :group 'org-agenda-line-format
  1252. :type '(list
  1253. (string :tag "Deadline today ")
  1254. (choice :tag "Deadline relative"
  1255. (string :tag "Format string")
  1256. (function))))
  1257. (defcustom org-agenda-remove-times-when-in-prefix t
  1258. "Non-nil means remove duplicate time specifications in agenda items.
  1259. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1260. time-of-day specification in a headline or diary entry is extracted and
  1261. placed into the prefix. If this option is non-nil, the original specification
  1262. \(a timestamp or -range, or just a plain time(range) specification like
  1263. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1264. cluttered.
  1265. The option can be t or nil. It may also be the symbol `beg', indicating
  1266. that the time should only be removed when it is located at the beginning of
  1267. the headline/diary entry."
  1268. :group 'org-agenda-line-format
  1269. :type '(choice
  1270. (const :tag "Always" t)
  1271. (const :tag "Never" nil)
  1272. (const :tag "When at beginning of entry" beg)))
  1273. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1274. "Non-nil means remove time ranges specifications in agenda
  1275. items that span on several days."
  1276. :group 'org-agenda-line-format
  1277. :type 'boolean)
  1278. (defcustom org-agenda-default-appointment-duration nil
  1279. "Default duration for appointments that only have a starting time.
  1280. When nil, no duration is specified in such cases.
  1281. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1282. :group 'org-agenda-line-format
  1283. :type '(choice
  1284. (integer :tag "Minutes")
  1285. (const :tag "No default duration")))
  1286. (defcustom org-agenda-show-inherited-tags t
  1287. "Non-nil means show inherited tags in each agenda line."
  1288. :group 'org-agenda-line-format
  1289. :type 'boolean)
  1290. (defcustom org-agenda-hide-tags-regexp nil
  1291. "Regular expression used to filter away specific tags in agenda views.
  1292. This means that these tags will be present, but not be shown in the agenda
  1293. line. Secondary filtering will still work on the hidden tags.
  1294. Nil means don't hide any tags."
  1295. :group 'org-agenda-line-format
  1296. :type '(choice
  1297. (const :tag "Hide none" nil)
  1298. (string :tag "Regexp ")))
  1299. (defcustom org-agenda-remove-tags nil
  1300. "Non-nil means remove the tags from the headline copy in the agenda.
  1301. When this is the symbol `prefix', only remove tags when
  1302. `org-agenda-prefix-format' contains a `%T' specifier."
  1303. :group 'org-agenda-line-format
  1304. :type '(choice
  1305. (const :tag "Always" t)
  1306. (const :tag "Never" nil)
  1307. (const :tag "When prefix format contains %T" prefix)))
  1308. (if (fboundp 'defvaralias)
  1309. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1310. 'org-agenda-remove-tags))
  1311. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1312. "Shift tags in agenda items to this column.
  1313. If this number is positive, it specifies the column. If it is negative,
  1314. it means that the tags should be flushright to that column. For example,
  1315. -80 works well for a normal 80 character screen."
  1316. :group 'org-agenda-line-format
  1317. :type 'integer)
  1318. (if (fboundp 'defvaralias)
  1319. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1320. (defcustom org-agenda-fontify-priorities 'cookies
  1321. "Non-nil means highlight low and high priorities in agenda.
  1322. When t, the highest priority entries are bold, lowest priority italic.
  1323. However, settings in `org-priority-faces' will overrule these faces.
  1324. When this variable is the symbol `cookies', only fontify the
  1325. cookies, not the entire task.
  1326. This may also be an association list of priority faces, whose
  1327. keys are the character values of `org-highest-priority',
  1328. `org-default-priority', and `org-lowest-priority' (the default values
  1329. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1330. color as a string, or a list like `(:background \"Red\")'.
  1331. If it is a color, the variable `org-faces-easy-properties'
  1332. determines if it is a foreground or a background color."
  1333. :group 'org-agenda-line-format
  1334. :type '(choice
  1335. (const :tag "Never" nil)
  1336. (const :tag "Defaults" t)
  1337. (const :tag "Cookies only" cookies)
  1338. (repeat :tag "Specify"
  1339. (list (character :tag "Priority" :value ?A)
  1340. (choice :tag "Face "
  1341. (string :tag "Color")
  1342. (sexp :tag "Face"))))))
  1343. (defcustom org-agenda-day-face-function nil
  1344. "Function called to determine what face should be used to display a day.
  1345. The only argument passed to that function is the day. It should
  1346. returns a face, or nil if does not want to specify a face and let
  1347. the normal rules apply."
  1348. :group 'org-agenda-line-format
  1349. :type 'function)
  1350. (defcustom org-agenda-category-icon-alist nil
  1351. "Alist of category icon to be displayed in agenda views.
  1352. Each entry should have the following format:
  1353. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1354. Where CATEGORY-REGEXP is a regexp matching the categories where
  1355. the icon should be displayed.
  1356. FILE-OR-DATA either a file path or a string containing image data.
  1357. The other fields can be ommited safely if not needed:
  1358. TYPE indicates the image type.
  1359. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1360. image data.
  1361. PROPS are additional image attributes to assign to the image,
  1362. like, e.g. `:ascent center'.
  1363. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1364. If you want to set the display properties yourself, just put a
  1365. list as second element:
  1366. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1367. For example, to display a 16px horizontal space for Emacs
  1368. category, you can use:
  1369. (\"Emacs\" '(space . (:width (16))))"
  1370. :group 'org-agenda-line-format
  1371. :type '(alist :key-type (string :tag "Regexp matching category")
  1372. :value-type (choice (list :tag "Icon"
  1373. (string :tag "File or data")
  1374. (symbol :tag "Type")
  1375. (boolean :tag "Data?")
  1376. (repeat :tag "Extra image properties" :inline t symbol))
  1377. (list :tag "Display properties" sexp))))
  1378. (defgroup org-agenda-column-view nil
  1379. "Options concerning column view in the agenda."
  1380. :tag "Org Agenda Column View"
  1381. :group 'org-agenda)
  1382. (defcustom org-agenda-columns-show-summaries t
  1383. "Non-nil means show summaries for columns displayed in the agenda view."
  1384. :group 'org-agenda-column-view
  1385. :type 'boolean)
  1386. (defcustom org-agenda-columns-remove-prefix-from-item t
  1387. "Non-nil means remove the prefix from a headline for agenda column view.
  1388. The special ITEM field in the columns format contains the current line, with
  1389. all information shown in other columns (like the TODO state or a tag).
  1390. When this variable is non-nil, also the agenda prefix will be removed from
  1391. the content of the ITEM field, to make sure as much as possible of the
  1392. headline can be shown in the limited width of the field."
  1393. :group 'org-agenda
  1394. :type 'boolean)
  1395. (defcustom org-agenda-columns-compute-summary-properties t
  1396. "Non-nil means recompute all summary properties before column view.
  1397. When column view in the agenda is listing properties that have a summary
  1398. operator, it can go to all relevant buffers and recompute the summaries
  1399. there. This can mean overhead for the agenda column view, but is necessary
  1400. to have thing up to date.
  1401. As a special case, a CLOCKSUM property also makes sure that the clock
  1402. computations are current."
  1403. :group 'org-agenda-column-view
  1404. :type 'boolean)
  1405. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1406. "Non-nil means the duration of an appointment will add to day effort.
  1407. The property to which appointment durations will be added is the one given
  1408. in the option `org-effort-property'. If an appointment does not have
  1409. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1410. is not set, an appointment without end time will not contribute to the time
  1411. estimate."
  1412. :group 'org-agenda-column-view
  1413. :type 'boolean)
  1414. (defcustom org-agenda-auto-exclude-function nil
  1415. "A function called with a tag to decide if it is filtered on '/ RET'.
  1416. The sole argument to the function, which is called once for each
  1417. possible tag, is a string giving the name of the tag. The
  1418. function should return either nil if the tag should be included
  1419. as normal, or \"-<TAG>\" to exclude the tag.
  1420. Note that for the purpose of tag filtering, only the lower-case version of
  1421. all tags will be considered, so that this function will only ever see
  1422. the lower-case version of all tags."
  1423. :group 'org-agenda
  1424. :type 'function)
  1425. (eval-when-compile
  1426. (require 'cl))
  1427. (require 'org)
  1428. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1429. "Execute BODY with point at location given by `org-hd-marker' property.
  1430. If STRING is non-nil, the text property will be fetched from position 0
  1431. in that string. If STRING is nil, it will be fetched from the beginning
  1432. of the current line."
  1433. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1434. 'org-hd-marker string)))
  1435. (with-current-buffer (marker-buffer marker)
  1436. (save-excursion
  1437. (goto-char marker)
  1438. ,@body))))
  1439. (defun org-add-agenda-custom-command (entry)
  1440. "Replace or add a command in `org-agenda-custom-commands'.
  1441. This is mostly for hacking and trying a new command - once the command
  1442. works you probably want to add it to `org-agenda-custom-commands' for good."
  1443. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1444. (if ass
  1445. (setcdr ass (cdr entry))
  1446. (push entry org-agenda-custom-commands))))
  1447. ;;; Define the Org-agenda-mode
  1448. (defvar org-agenda-mode-map (make-sparse-keymap)
  1449. "Keymap for `org-agenda-mode'.")
  1450. (if (fboundp 'defvaralias)
  1451. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1452. (defvar org-agenda-menu) ; defined later in this file.
  1453. (defvar org-agenda-restrict) ; defined later in this file.
  1454. (defvar org-agenda-follow-mode nil)
  1455. (defvar org-agenda-entry-text-mode nil)
  1456. (defvar org-agenda-clockreport-mode nil)
  1457. (defvar org-agenda-show-log nil)
  1458. (defvar org-agenda-redo-command nil)
  1459. (defvar org-agenda-query-string nil)
  1460. (defvar org-agenda-mode-hook nil
  1461. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1462. (defvar org-agenda-type nil)
  1463. (defvar org-agenda-force-single-file nil)
  1464. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1465. (defun org-agenda-mode ()
  1466. "Mode for time-sorted view on action items in Org-mode files.
  1467. The following commands are available:
  1468. \\{org-agenda-mode-map}"
  1469. (interactive)
  1470. (kill-all-local-variables)
  1471. (setq org-agenda-undo-list nil
  1472. org-agenda-pending-undo-list nil
  1473. org-agenda-bulk-marked-entries nil)
  1474. (setq major-mode 'org-agenda-mode)
  1475. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1476. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1477. (setq mode-name "Org-Agenda")
  1478. (use-local-map org-agenda-mode-map)
  1479. (easy-menu-add org-agenda-menu)
  1480. (if org-startup-truncated (setq truncate-lines t))
  1481. (org-set-local 'line-move-visual nil)
  1482. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1483. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1484. ;; Make sure properties are removed when copying text
  1485. (when (boundp 'buffer-substring-filters)
  1486. (org-set-local 'buffer-substring-filters
  1487. (cons (lambda (x)
  1488. (set-text-properties 0 (length x) nil x) x)
  1489. buffer-substring-filters)))
  1490. (unless org-agenda-keep-modes
  1491. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1492. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1493. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1494. org-agenda-show-log org-agenda-start-with-log-mode))
  1495. (easy-menu-change
  1496. '("Agenda") "Agenda Files"
  1497. (append
  1498. (list
  1499. (vector
  1500. (if (get 'org-agenda-files 'org-restrict)
  1501. "Restricted to single file"
  1502. "Edit File List")
  1503. '(org-edit-agenda-file-list)
  1504. (not (get 'org-agenda-files 'org-restrict)))
  1505. "--")
  1506. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1507. (org-agenda-set-mode-name)
  1508. (apply
  1509. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1510. (list 'org-agenda-mode-hook)))
  1511. (substitute-key-definition 'undo 'org-agenda-undo
  1512. org-agenda-mode-map global-map)
  1513. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1514. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1515. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1516. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1517. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1518. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1519. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1520. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1521. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1522. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1523. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1524. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1525. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1526. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1527. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1528. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1529. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1530. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1531. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1532. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1533. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1534. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1535. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1536. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1537. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1538. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1539. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1540. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1541. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1542. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1543. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1544. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1545. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1546. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1547. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1548. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1549. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1550. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1551. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1552. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1553. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1554. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1555. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1556. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1557. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1558. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1559. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1560. (while l (org-defkey org-agenda-mode-map
  1561. (int-to-string (pop l)) 'digit-argument)))
  1562. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1563. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1564. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1565. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1566. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1567. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1568. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1569. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1570. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1571. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1572. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1573. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1574. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1575. 'org-clock-modify-effort-estimate)
  1576. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1577. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1578. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1579. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1580. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1581. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1582. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1583. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1584. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1585. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1586. (substitute-key-definition 'next-line 'org-agenda-next-line
  1587. org-agenda-mode-map global-map)
  1588. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1589. org-agenda-mode-map global-map)
  1590. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1591. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1592. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1593. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1594. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1595. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1596. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1597. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1598. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1599. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1600. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1601. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1602. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1603. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1604. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1605. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1606. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1607. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1608. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1609. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1610. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1611. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1612. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1613. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1614. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1615. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1616. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1617. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1618. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1619. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1620. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1621. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1622. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1623. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1624. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1625. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1626. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1627. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1628. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1630. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1631. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1632. (when org-agenda-mouse-1-follows-link
  1633. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1634. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1635. '("Agenda"
  1636. ("Agenda Files")
  1637. "--"
  1638. ("Agenda Dates"
  1639. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1640. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1641. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1642. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1643. "--"
  1644. ("View"
  1645. ["Day View" org-agenda-day-view
  1646. :active (org-agenda-check-type nil 'agenda)
  1647. :style radio :selected (eq org-agenda-current-span 'day)
  1648. :keys "v d (or just d)"]
  1649. ["Week View" org-agenda-week-view
  1650. :active (org-agenda-check-type nil 'agenda)
  1651. :style radio :selected (eq org-agenda-current-span 'week)
  1652. :keys "v w (or just w)"]
  1653. ["Month View" org-agenda-month-view
  1654. :active (org-agenda-check-type nil 'agenda)
  1655. :style radio :selected (eq org-agenda-current-span 'month)
  1656. :keys "v m"]
  1657. ["Year View" org-agenda-year-view
  1658. :active (org-agenda-check-type nil 'agenda)
  1659. :style radio :selected (eq org-agenda-current-span 'year)
  1660. :keys "v y"]
  1661. "--"
  1662. ["Include Diary" org-agenda-toggle-diary
  1663. :style toggle :selected org-agenda-include-diary
  1664. :active (org-agenda-check-type nil 'agenda)]
  1665. ["Include Deadlines" org-agenda-toggle-deadlines
  1666. :style toggle :selected org-agenda-include-deadlines
  1667. :active (org-agenda-check-type nil 'agenda)]
  1668. ["Use Time Grid" org-agenda-toggle-time-grid
  1669. :style toggle :selected org-agenda-use-time-grid
  1670. :active (org-agenda-check-type nil 'agenda)]
  1671. "--"
  1672. ["Show clock report" org-agenda-clockreport-mode
  1673. :style toggle :selected org-agenda-clockreport-mode
  1674. :active (org-agenda-check-type nil 'agenda)]
  1675. ["Show some entry text" org-agenda-entry-text-mode
  1676. :style toggle :selected org-agenda-entry-text-mode
  1677. :active t]
  1678. "--"
  1679. ["Show Logbook entries" org-agenda-log-mode
  1680. :style toggle :selected org-agenda-show-log
  1681. :active (org-agenda-check-type nil 'agenda 'timeline)
  1682. :keys "v l (or just l)"]
  1683. ["Include archived trees" org-agenda-archives-mode
  1684. :style toggle :selected org-agenda-archives-mode :active t
  1685. :keys "v a"]
  1686. ["Include archive files" (org-agenda-archives-mode t)
  1687. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1688. :keys "v A"]
  1689. "--"
  1690. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1691. ["Write view to file" org-write-agenda t]
  1692. ["Rebuild buffer" org-agenda-redo t]
  1693. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1694. "--"
  1695. ["Show original entry" org-agenda-show t]
  1696. ["Go To (other window)" org-agenda-goto t]
  1697. ["Go To (this window)" org-agenda-switch-to t]
  1698. ["Follow Mode" org-agenda-follow-mode
  1699. :style toggle :selected org-agenda-follow-mode :active t]
  1700. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1701. "--"
  1702. ("TODO"
  1703. ["Cycle TODO" org-agenda-todo t]
  1704. ["Next TODO set" org-agenda-todo-nextset t]
  1705. ["Previous TODO set" org-agenda-todo-previousset t]
  1706. ["Add note" org-agenda-add-note t])
  1707. ("Archive/Refile/Delete"
  1708. ["Archive default" org-agenda-archive-default t]
  1709. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1710. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1711. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1712. ["Archive subtree" org-agenda-archive t]
  1713. "--"
  1714. ["Refile" org-agenda-refile t]
  1715. "--"
  1716. ["Delete subtree" org-agenda-kill t])
  1717. ("Bulk action"
  1718. ["Mark entry" org-agenda-bulk-mark t]
  1719. ["Unmark entry" org-agenda-bulk-unmark t]
  1720. ["Act on all marked" org-agenda-bulk-action t]
  1721. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1722. "--"
  1723. ("Tags and Properties"
  1724. ["Show all Tags" org-agenda-show-tags t]
  1725. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1726. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1727. "--"
  1728. ["Column View" org-columns t])
  1729. ("Deadline/Schedule"
  1730. ["Schedule" org-agenda-schedule t]
  1731. ["Set Deadline" org-agenda-deadline t]
  1732. "--"
  1733. ["Mark item" org-agenda-action :active t :keys "k m"]
  1734. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1735. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1736. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1737. "--"
  1738. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1739. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1740. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1741. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1742. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1743. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1744. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1745. ("Clock and Effort"
  1746. ["Clock in" org-agenda-clock-in t]
  1747. ["Clock out" org-agenda-clock-out t]
  1748. ["Clock cancel" org-agenda-clock-cancel t]
  1749. ["Goto running clock" org-clock-goto t]
  1750. "--"
  1751. ["Set Effort" org-agenda-set-effort t]
  1752. ["Change clocked effort" org-clock-modify-effort-estimate
  1753. (org-clock-is-active)])
  1754. ("Priority"
  1755. ["Set Priority" org-agenda-priority t]
  1756. ["Increase Priority" org-agenda-priority-up t]
  1757. ["Decrease Priority" org-agenda-priority-down t]
  1758. ["Show Priority" org-agenda-show-priority t])
  1759. ("Calendar/Diary"
  1760. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1761. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1762. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1763. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1764. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1765. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1766. "--"
  1767. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1768. "--"
  1769. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1770. "--"
  1771. ("MobileOrg"
  1772. ["Push Files and Views" org-mobile-push t]
  1773. ["Get Captured and Flagged" org-mobile-pull t]
  1774. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1775. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1776. "--"
  1777. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1778. "--"
  1779. ["Quit" org-agenda-quit t]
  1780. ["Exit and Release Buffers" org-agenda-exit t]
  1781. ))
  1782. ;;; Agenda undo
  1783. (defvar org-agenda-allow-remote-undo t
  1784. "Non-nil means allow remote undo from the agenda buffer.")
  1785. (defvar org-agenda-undo-list nil
  1786. "List of undoable operations in the agenda since last refresh.")
  1787. (defvar org-agenda-undo-has-started-in nil
  1788. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1789. (defvar org-agenda-pending-undo-list nil
  1790. "In a series of undo commands, this is the list of remaining undo items.")
  1791. (defun org-agenda-undo ()
  1792. "Undo a remote editing step in the agenda.
  1793. This undoes changes both in the agenda buffer and in the remote buffer
  1794. that have been changed along."
  1795. (interactive)
  1796. (or org-agenda-allow-remote-undo
  1797. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1798. (if (not (eq this-command last-command))
  1799. (setq org-agenda-undo-has-started-in nil
  1800. org-agenda-pending-undo-list org-agenda-undo-list))
  1801. (if (not org-agenda-pending-undo-list)
  1802. (error "No further undo information"))
  1803. (let* ((entry (pop org-agenda-pending-undo-list))
  1804. buf line cmd rembuf)
  1805. (setq cmd (pop entry) line (pop entry))
  1806. (setq rembuf (nth 2 entry))
  1807. (org-with-remote-undo rembuf
  1808. (while (bufferp (setq buf (pop entry)))
  1809. (if (pop entry)
  1810. (with-current-buffer buf
  1811. (let ((last-undo-buffer buf)
  1812. (inhibit-read-only t))
  1813. (unless (memq buf org-agenda-undo-has-started-in)
  1814. (push buf org-agenda-undo-has-started-in)
  1815. (make-local-variable 'pending-undo-list)
  1816. (undo-start))
  1817. (while (and pending-undo-list
  1818. (listp pending-undo-list)
  1819. (not (car pending-undo-list)))
  1820. (pop pending-undo-list))
  1821. (undo-more 1))))))
  1822. (org-goto-line line)
  1823. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1824. (defun org-verify-change-for-undo (l1 l2)
  1825. "Verify that a real change occurred between the undo lists L1 and L2."
  1826. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1827. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1828. (not (eq l1 l2)))
  1829. ;;; Agenda dispatch
  1830. (defvar org-agenda-restrict nil)
  1831. (defvar org-agenda-restrict-begin (make-marker))
  1832. (defvar org-agenda-restrict-end (make-marker))
  1833. (defvar org-agenda-last-dispatch-buffer nil)
  1834. (defvar org-agenda-overriding-restriction nil)
  1835. ;;;###autoload
  1836. (defun org-agenda (&optional arg keys restriction)
  1837. "Dispatch agenda commands to collect entries to the agenda buffer.
  1838. Prompts for a command to execute. Any prefix arg will be passed
  1839. on to the selected command. The default selections are:
  1840. a Call `org-agenda-list' to display the agenda for current day or week.
  1841. t Call `org-todo-list' to display the global todo list.
  1842. T Call `org-todo-list' to display the global todo list, select only
  1843. entries with a specific TODO keyword (the user gets a prompt).
  1844. m Call `org-tags-view' to display headlines with tags matching
  1845. a condition (the user is prompted for the condition).
  1846. M Like `m', but select only TODO entries, no ordinary headlines.
  1847. L Create a timeline for the current buffer.
  1848. e Export views to associated files.
  1849. s Search entries for keywords.
  1850. / Multi occur across all agenda files and also files listed
  1851. in `org-agenda-text-search-extra-files'.
  1852. < Restrict agenda commands to buffer, subtree, or region.
  1853. Press several times to get the desired effect.
  1854. > Remove a previous restriction.
  1855. # List \"stuck\" projects.
  1856. ! Configure what \"stuck\" means.
  1857. C Configure custom agenda commands.
  1858. More commands can be added by configuring the variable
  1859. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1860. searches can be pre-defined in this way.
  1861. If the current buffer is in Org-mode and visiting a file, you can also
  1862. first press `<' once to indicate that the agenda should be temporarily
  1863. \(until the next use of \\[org-agenda]) restricted to the current file.
  1864. Pressing `<' twice means to restrict to the current subtree or region
  1865. \(if active)."
  1866. (interactive "P")
  1867. (catch 'exit
  1868. (let* ((prefix-descriptions nil)
  1869. (org-agenda-window-setup (if (equal (buffer-name)
  1870. org-agenda-buffer-name)
  1871. 'current-window
  1872. org-agenda-window-setup))
  1873. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1874. (org-agenda-custom-commands
  1875. ;; normalize different versions
  1876. (delq nil
  1877. (mapcar
  1878. (lambda (x)
  1879. (cond ((stringp (cdr x))
  1880. (push x prefix-descriptions)
  1881. nil)
  1882. ((stringp (nth 1 x)) x)
  1883. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1884. (t (cons (car x) (cons "" (cdr x))))))
  1885. org-agenda-custom-commands)))
  1886. (buf (current-buffer))
  1887. (bfn (buffer-file-name (buffer-base-buffer)))
  1888. entry key type match lprops ans)
  1889. ;; Turn off restriction unless there is an overriding one,
  1890. (unless org-agenda-overriding-restriction
  1891. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1892. ;; There is a request to keep the file list in place
  1893. (put 'org-agenda-files 'org-restrict nil))
  1894. (setq org-agenda-restrict nil)
  1895. (move-marker org-agenda-restrict-begin nil)
  1896. (move-marker org-agenda-restrict-end nil))
  1897. ;; Delete old local properties
  1898. (put 'org-agenda-redo-command 'org-lprops nil)
  1899. ;; Remember where this call originated
  1900. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1901. (unless keys
  1902. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1903. keys (car ans)
  1904. restriction (cdr ans)))
  1905. ;; Establish the restriction, if any
  1906. (when (and (not org-agenda-overriding-restriction) restriction)
  1907. (put 'org-agenda-files 'org-restrict (list bfn))
  1908. (cond
  1909. ((eq restriction 'region)
  1910. (setq org-agenda-restrict t)
  1911. (move-marker org-agenda-restrict-begin (region-beginning))
  1912. (move-marker org-agenda-restrict-end (region-end)))
  1913. ((eq restriction 'subtree)
  1914. (save-excursion
  1915. (setq org-agenda-restrict t)
  1916. (org-back-to-heading t)
  1917. (move-marker org-agenda-restrict-begin (point))
  1918. (move-marker org-agenda-restrict-end
  1919. (progn (org-end-of-subtree t)))))))
  1920. ;; For example the todo list should not need it (but does...)
  1921. (cond
  1922. ((setq entry (assoc keys org-agenda-custom-commands))
  1923. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1924. (progn
  1925. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1926. lprops (nth 4 entry))
  1927. (put 'org-agenda-redo-command 'org-lprops lprops)
  1928. (cond
  1929. ((eq type 'agenda)
  1930. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1931. ((eq type 'alltodo)
  1932. (org-let lprops '(org-todo-list current-prefix-arg)))
  1933. ((eq type 'search)
  1934. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1935. ((eq type 'stuck)
  1936. (org-let lprops '(org-agenda-list-stuck-projects
  1937. current-prefix-arg)))
  1938. ((eq type 'tags)
  1939. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1940. ((eq type 'tags-todo)
  1941. (org-let lprops '(org-tags-view '(4) match)))
  1942. ((eq type 'todo)
  1943. (org-let lprops '(org-todo-list match)))
  1944. ((eq type 'tags-tree)
  1945. (org-check-for-org-mode)
  1946. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1947. ((eq type 'todo-tree)
  1948. (org-check-for-org-mode)
  1949. (org-let lprops
  1950. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1951. (regexp-quote match) "\\>"))))
  1952. ((eq type 'occur-tree)
  1953. (org-check-for-org-mode)
  1954. (org-let lprops '(org-occur match)))
  1955. ((functionp type)
  1956. (org-let lprops '(funcall type match)))
  1957. ((fboundp type)
  1958. (org-let lprops '(funcall type match)))
  1959. (t (error "Invalid custom agenda command type %s" type))))
  1960. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1961. ((equal keys "C")
  1962. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1963. (customize-variable 'org-agenda-custom-commands))
  1964. ((equal keys "a") (call-interactively 'org-agenda-list))
  1965. ((equal keys "s") (call-interactively 'org-search-view))
  1966. ((equal keys "t") (call-interactively 'org-todo-list))
  1967. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1968. ((equal keys "m") (call-interactively 'org-tags-view))
  1969. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1970. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1971. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1972. (org-add-hook
  1973. 'post-command-hook
  1974. (lambda ()
  1975. (unless (current-message)
  1976. (let* ((m (org-agenda-get-any-marker))
  1977. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1978. (when note
  1979. (message (concat
  1980. "FLAGGING-NOTE ([?] for more info): "
  1981. (org-add-props
  1982. (replace-regexp-in-string
  1983. "\\\\n" "//"
  1984. (copy-sequence note))
  1985. nil 'face 'org-warning)))))))
  1986. t t))
  1987. ((equal keys "L")
  1988. (unless (org-mode-p)
  1989. (error "This is not an Org-mode file"))
  1990. (unless restriction
  1991. (put 'org-agenda-files 'org-restrict (list bfn))
  1992. (org-call-with-arg 'org-timeline arg)))
  1993. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1994. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1995. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1996. (t (error "Invalid agenda key"))))))
  1997. (defun org-agenda-normalize-custom-commands (cmds)
  1998. (delq nil
  1999. (mapcar
  2000. (lambda (x)
  2001. (cond ((stringp (cdr x)) nil)
  2002. ((stringp (nth 1 x)) x)
  2003. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2004. (t (cons (car x) (cons "" (cdr x))))))
  2005. cmds)))
  2006. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2007. "The user interface for selecting an agenda command."
  2008. (catch 'exit
  2009. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2010. (restrict-ok (and bfn (org-mode-p)))
  2011. (region-p (org-region-active-p))
  2012. (custom org-agenda-custom-commands)
  2013. (selstring "")
  2014. restriction second-time
  2015. c entry key type match prefixes rmheader header-end custom1 desc
  2016. line lines left right n n1)
  2017. (save-window-excursion
  2018. (delete-other-windows)
  2019. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2020. (erase-buffer)
  2021. (insert (eval-when-compile
  2022. (let ((header
  2023. "
  2024. Press key for an agenda command: < Buffer, subtree/region restriction
  2025. -------------------------------- > Remove restriction
  2026. a Agenda for current week or day e Export agenda views
  2027. t List of all TODO entries T Entries with special TODO kwd
  2028. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2029. L Timeline for current buffer # List stuck projects (!=configure)
  2030. s Search for keywords C Configure custom agenda commands
  2031. / Multi-occur ? Find :FLAGGED: entries
  2032. ")
  2033. (start 0))
  2034. (while (string-match
  2035. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2036. header start)
  2037. (setq start (match-end 0))
  2038. (add-text-properties (match-beginning 2) (match-end 2)
  2039. '(face bold) header))
  2040. header)))
  2041. (setq header-end (move-marker (make-marker) (point)))
  2042. (while t
  2043. (setq custom1 custom)
  2044. (when (eq rmheader t)
  2045. (org-goto-line 1)
  2046. (re-search-forward ":" nil t)
  2047. (delete-region (match-end 0) (point-at-eol))
  2048. (forward-char 1)
  2049. (looking-at "-+")
  2050. (delete-region (match-end 0) (point-at-eol))
  2051. (move-marker header-end (match-end 0)))
  2052. (goto-char header-end)
  2053. (delete-region (point) (point-max))
  2054. ;; Produce all the lines that describe custom commands and prefixes
  2055. (setq lines nil)
  2056. (while (setq entry (pop custom1))
  2057. (setq key (car entry) desc (nth 1 entry)
  2058. type (nth 2 entry)
  2059. match (nth 3 entry))
  2060. (if (> (length key) 1)
  2061. (add-to-list 'prefixes (string-to-char key))
  2062. (setq line
  2063. (format
  2064. "%-4s%-14s"
  2065. (org-add-props (copy-sequence key)
  2066. '(face bold))
  2067. (cond
  2068. ((string-match "\\S-" desc) desc)
  2069. ((eq type 'agenda) "Agenda for current week or day")
  2070. ((eq type 'alltodo) "List of all TODO entries")
  2071. ((eq type 'search) "Word search")
  2072. ((eq type 'stuck) "List of stuck projects")
  2073. ((eq type 'todo) "TODO keyword")
  2074. ((eq type 'tags) "Tags query")
  2075. ((eq type 'tags-todo) "Tags (TODO)")
  2076. ((eq type 'tags-tree) "Tags tree")
  2077. ((eq type 'todo-tree) "TODO kwd tree")
  2078. ((eq type 'occur-tree) "Occur tree")
  2079. ((functionp type) (if (symbolp type)
  2080. (symbol-name type)
  2081. "Lambda expression"))
  2082. (t "???"))))
  2083. (if org-agenda-menu-show-matcher
  2084. (setq line
  2085. (concat line ": "
  2086. (cond
  2087. ((stringp match)
  2088. (setq match (copy-sequence match))
  2089. (org-add-props match nil 'face 'org-warning))
  2090. (match
  2091. (format "set of %d commands" (length match)))
  2092. (t ""))))
  2093. (if (org-string-nw-p match)
  2094. (add-text-properties
  2095. 0 (length line) (list 'help-echo
  2096. (concat "Matcher: "match)) line)))
  2097. (push line lines)))
  2098. (setq lines (nreverse lines))
  2099. (when prefixes
  2100. (mapc (lambda (x)
  2101. (push
  2102. (format "%s %s"
  2103. (org-add-props (char-to-string x)
  2104. nil 'face 'bold)
  2105. (or (cdr (assoc (concat selstring
  2106. (char-to-string x))
  2107. prefix-descriptions))
  2108. "Prefix key"))
  2109. lines))
  2110. prefixes))
  2111. ;; Check if we should display in two columns
  2112. (if org-agenda-menu-two-column
  2113. (progn
  2114. (setq n (length lines)
  2115. n1 (+ (/ n 2) (mod n 2))
  2116. right (nthcdr n1 lines)
  2117. left (copy-sequence lines))
  2118. (setcdr (nthcdr (1- n1) left) nil))
  2119. (setq left lines right nil))
  2120. (while left
  2121. (insert "\n" (pop left))
  2122. (when right
  2123. (if (< (current-column) 40)
  2124. (move-to-column 40 t)
  2125. (insert " "))
  2126. (insert (pop right))))
  2127. ;; Make the window the right size
  2128. (goto-char (point-min))
  2129. (if second-time
  2130. (if (not (pos-visible-in-window-p (point-max)))
  2131. (org-fit-window-to-buffer))
  2132. (setq second-time t)
  2133. (org-fit-window-to-buffer))
  2134. ;; Ask for selection
  2135. (message "Press key for agenda command%s:"
  2136. (if (or restrict-ok org-agenda-overriding-restriction)
  2137. (if org-agenda-overriding-restriction
  2138. " (restriction lock active)"
  2139. (if restriction
  2140. (format " (restricted to %s)" restriction)
  2141. " (unrestricted)"))
  2142. ""))
  2143. (setq c (read-char-exclusive))
  2144. (message "")
  2145. (cond
  2146. ((assoc (char-to-string c) custom)
  2147. (setq selstring (concat selstring (char-to-string c)))
  2148. (throw 'exit (cons selstring restriction)))
  2149. ((memq c prefixes)
  2150. (setq selstring (concat selstring (char-to-string c))
  2151. prefixes nil
  2152. rmheader (or rmheader t)
  2153. custom (delq nil (mapcar
  2154. (lambda (x)
  2155. (if (or (= (length (car x)) 1)
  2156. (/= (string-to-char (car x)) c))
  2157. nil
  2158. (cons (substring (car x) 1) (cdr x))))
  2159. custom))))
  2160. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2161. (message "Restriction is only possible in Org-mode buffers")
  2162. (ding) (sit-for 1))
  2163. ((eq c ?1)
  2164. (org-agenda-remove-restriction-lock 'noupdate)
  2165. (setq restriction 'buffer))
  2166. ((eq c ?0)
  2167. (org-agenda-remove-restriction-lock 'noupdate)
  2168. (setq restriction (if region-p 'region 'subtree)))
  2169. ((eq c ?<)
  2170. (org-agenda-remove-restriction-lock 'noupdate)
  2171. (setq restriction
  2172. (cond
  2173. ((eq restriction 'buffer)
  2174. (if region-p 'region 'subtree))
  2175. ((memq restriction '(subtree region))
  2176. nil)
  2177. (t 'buffer))))
  2178. ((eq c ?>)
  2179. (org-agenda-remove-restriction-lock 'noupdate)
  2180. (setq restriction nil))
  2181. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2182. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2183. ((and (> (length selstring) 0) (eq c ?\d))
  2184. (delete-window)
  2185. (org-agenda-get-restriction-and-command prefix-descriptions))
  2186. ((equal c ?q) (error "Abort"))
  2187. (t (error "Invalid key %c" c))))))))
  2188. (defun org-run-agenda-series (name series)
  2189. (org-let (nth 1 series) '(org-prepare-agenda name))
  2190. (let* ((org-agenda-multi t)
  2191. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2192. (cmds (car series))
  2193. (gprops (nth 1 series))
  2194. match ;; The byte compiler incorrectly complains about this. Keep it!
  2195. cmd type lprops)
  2196. (while (setq cmd (pop cmds))
  2197. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2198. (cond
  2199. ((eq type 'agenda)
  2200. (org-let2 gprops lprops
  2201. '(call-interactively 'org-agenda-list)))
  2202. ((eq type 'alltodo)
  2203. (org-let2 gprops lprops
  2204. '(call-interactively 'org-todo-list)))
  2205. ((eq type 'search)
  2206. (org-let2 gprops lprops
  2207. '(org-search-view current-prefix-arg match nil)))
  2208. ((eq type 'stuck)
  2209. (org-let2 gprops lprops
  2210. '(call-interactively 'org-agenda-list-stuck-projects)))
  2211. ((eq type 'tags)
  2212. (org-let2 gprops lprops
  2213. '(org-tags-view current-prefix-arg match)))
  2214. ((eq type 'tags-todo)
  2215. (org-let2 gprops lprops
  2216. '(org-tags-view '(4) match)))
  2217. ((eq type 'todo)
  2218. (org-let2 gprops lprops
  2219. '(org-todo-list match)))
  2220. ((fboundp type)
  2221. (org-let2 gprops lprops
  2222. '(funcall type match)))
  2223. (t (error "Invalid type in command series"))))
  2224. (widen)
  2225. (setq org-agenda-redo-command redo)
  2226. (goto-char (point-min)))
  2227. (org-fit-agenda-window)
  2228. (org-let (nth 1 series) '(org-finalize-agenda)))
  2229. ;;;###autoload
  2230. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2231. "Run an agenda command in batch mode and send the result to STDOUT.
  2232. If CMD-KEY is a string of length 1, it is used as a key in
  2233. `org-agenda-custom-commands' and triggers this command. If it is a
  2234. longer string it is used as a tags/todo match string.
  2235. Parameters are alternating variable names and values that will be bound
  2236. before running the agenda command."
  2237. (let (pars)
  2238. (while parameters
  2239. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2240. (if (> (length cmd-key) 2)
  2241. (eval (list 'let (nreverse pars)
  2242. (list 'org-tags-view nil cmd-key)))
  2243. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2244. (set-buffer org-agenda-buffer-name)
  2245. (princ (org-encode-for-stdout (buffer-string)))))
  2246. ;(defun org-encode-for-stdout (string)
  2247. ; (if (fboundp 'encode-coding-string)
  2248. ; (encode-coding-string string buffer-file-coding-system)
  2249. ; string))
  2250. (defun org-encode-for-stdout (string)
  2251. string)
  2252. (defvar org-agenda-info nil)
  2253. ;;;###autoload
  2254. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2255. "Run an agenda command in batch mode and send the result to STDOUT.
  2256. If CMD-KEY is a string of length 1, it is used as a key in
  2257. `org-agenda-custom-commands' and triggers this command. If it is a
  2258. longer string it is used as a tags/todo match string.
  2259. Parameters are alternating variable names and values that will be bound
  2260. before running the agenda command.
  2261. The output gives a line for each selected agenda item. Each
  2262. item is a list of comma-separated values, like this:
  2263. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2264. category The category of the item
  2265. head The headline, without TODO kwd, TAGS and PRIORITY
  2266. type The type of the agenda entry, can be
  2267. todo selected in TODO match
  2268. tagsmatch selected in tags match
  2269. diary imported from diary
  2270. deadline a deadline on given date
  2271. scheduled scheduled on given date
  2272. timestamp entry has timestamp on given date
  2273. closed entry was closed on given date
  2274. upcoming-deadline warning about deadline
  2275. past-scheduled forwarded scheduled item
  2276. block entry has date block including g. date
  2277. todo The todo keyword, if any
  2278. tags All tags including inherited ones, separated by colons
  2279. date The relevant date, like 2007-2-14
  2280. time The time, like 15:00-16:50
  2281. extra Sting with extra planning info
  2282. priority-l The priority letter if any was given
  2283. priority-n The computed numerical priority
  2284. agenda-day The day in the agenda where this is listed"
  2285. (let (pars)
  2286. (while parameters
  2287. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2288. (push (list 'org-agenda-remove-tags t) pars)
  2289. (if (> (length cmd-key) 2)
  2290. (eval (list 'let (nreverse pars)
  2291. (list 'org-tags-view nil cmd-key)))
  2292. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2293. (set-buffer org-agenda-buffer-name)
  2294. (let* ((lines (org-split-string (buffer-string) "\n"))
  2295. line)
  2296. (while (setq line (pop lines))
  2297. (catch 'next
  2298. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2299. (setq org-agenda-info
  2300. (org-fix-agenda-info (text-properties-at 0 line)))
  2301. (princ
  2302. (org-encode-for-stdout
  2303. (mapconcat 'org-agenda-export-csv-mapper
  2304. '(org-category txt type todo tags date time extra
  2305. priority-letter priority agenda-day)
  2306. ",")))
  2307. (princ "\n"))))))
  2308. (defun org-fix-agenda-info (props)
  2309. "Make sure all properties on an agenda item have a canonical form.
  2310. This ensures the export commands can easily use it."
  2311. (let (tmp re)
  2312. (when (setq tmp (plist-get props 'tags))
  2313. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2314. (when (setq tmp (plist-get props 'date))
  2315. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2316. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2317. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2318. (setq tmp (calendar-date-string tmp)))
  2319. (setq props (plist-put props 'date tmp)))
  2320. (when (setq tmp (plist-get props 'day))
  2321. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2322. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2323. (setq tmp (calendar-date-string tmp)))
  2324. (setq props (plist-put props 'day tmp))
  2325. (setq props (plist-put props 'agenda-day tmp)))
  2326. (when (setq tmp (plist-get props 'txt))
  2327. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2328. (plist-put props 'priority-letter (match-string 1 tmp))
  2329. (setq tmp (replace-match "" t t tmp)))
  2330. (when (and (setq re (plist-get props 'org-todo-regexp))
  2331. (setq re (concat "\\`\\.*" re " ?"))
  2332. (string-match re tmp))
  2333. (plist-put props 'todo (match-string 1 tmp))
  2334. (setq tmp (replace-match "" t t tmp)))
  2335. (plist-put props 'txt tmp)))
  2336. props)
  2337. (defun org-agenda-export-csv-mapper (prop)
  2338. (let ((res (plist-get org-agenda-info prop)))
  2339. (setq res
  2340. (cond
  2341. ((not res) "")
  2342. ((stringp res) res)
  2343. (t (prin1-to-string res))))
  2344. (while (string-match "," res)
  2345. (setq res (replace-match ";" t t res)))
  2346. (org-trim res)))
  2347. ;;;###autoload
  2348. (defun org-store-agenda-views (&rest parameters)
  2349. (interactive)
  2350. (eval (list 'org-batch-store-agenda-views)))
  2351. ;; FIXME, why is this a macro?????
  2352. ;;;###autoload
  2353. (defmacro org-batch-store-agenda-views (&rest parameters)
  2354. "Run all custom agenda commands that have a file argument."
  2355. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2356. (pop-up-frames nil)
  2357. (dir default-directory)
  2358. pars cmd thiscmdkey files opts cmd-or-set)
  2359. (while parameters
  2360. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2361. (setq pars (reverse pars))
  2362. (save-window-excursion
  2363. (while cmds
  2364. (setq cmd (pop cmds)
  2365. thiscmdkey (car cmd)
  2366. cmd-or-set (nth 2 cmd)
  2367. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2368. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2369. (if (stringp files) (setq files (list files)))
  2370. (when files
  2371. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2372. (list 'org-agenda nil thiscmdkey)))
  2373. (set-buffer org-agenda-buffer-name)
  2374. (while files
  2375. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2376. (list 'org-write-agenda
  2377. (expand-file-name (pop files) dir) nil t))))
  2378. (and (get-buffer org-agenda-buffer-name)
  2379. (kill-buffer org-agenda-buffer-name)))))))
  2380. (defun org-agenda-mark-header-line (pos)
  2381. "Mark the line at POS as an agenda structure header."
  2382. (save-excursion
  2383. (goto-char pos)
  2384. (put-text-property (point-at-bol) (point-at-eol)
  2385. 'org-agenda-structural-header t)
  2386. (when org-agenda-title-append
  2387. (put-text-property (point-at-bol) (point-at-eol)
  2388. 'org-agenda-title-append org-agenda-title-append))))
  2389. (defvar org-mobile-creating-agendas)
  2390. (defun org-write-agenda (file &optional open nosettings)
  2391. "Write the current buffer (an agenda view) as a file.
  2392. Depending on the extension of the file name, plain text (.txt),
  2393. HTML (.html or .htm) or Postscript (.ps) is produced.
  2394. If the extension is .ics, run icalendar export over all files used
  2395. to construct the agenda and limit the export to entries listed in the
  2396. agenda now.
  2397. With prefix argument OPEN, open the new file immediately.
  2398. If NOSETTINGS is given, do not scope the settings of
  2399. `org-agenda-exporter-settings' into the export commands. This is used when
  2400. the settings have already been scoped and we do not wish to overrule other,
  2401. higher priority settings."
  2402. (interactive "FWrite agenda to file: \nP")
  2403. (if (not (file-writable-p file))
  2404. (error "Cannot write agenda to file %s" file))
  2405. (org-let (if nosettings nil org-agenda-exporter-settings)
  2406. '(save-excursion
  2407. (save-window-excursion
  2408. (org-agenda-mark-filtered-text)
  2409. (let ((bs (copy-sequence (buffer-string))) beg)
  2410. (org-agenda-unmark-filtered-text)
  2411. (with-temp-buffer
  2412. (rename-buffer "Agenda View" t)
  2413. (set-buffer-modified-p nil)
  2414. (insert bs)
  2415. (org-agenda-remove-marked-text 'org-filtered)
  2416. (while (setq beg (text-property-any (point-min) (point-max)
  2417. 'org-filtered t))
  2418. (delete-region
  2419. beg (or (next-single-property-change beg 'org-filtered)
  2420. (point-max))))
  2421. (run-hooks 'org-agenda-before-write-hook)
  2422. (cond
  2423. ((org-bound-and-true-p org-mobile-creating-agendas)
  2424. (org-mobile-write-agenda-for-mobile file))
  2425. ((string-match "\\.html?\\'" file)
  2426. (require 'htmlize)
  2427. (set-buffer (htmlize-buffer (current-buffer)))
  2428. (when (and org-agenda-export-html-style
  2429. (string-match "<style>" org-agenda-export-html-style))
  2430. ;; replace <style> section with org-agenda-export-html-style
  2431. (goto-char (point-min))
  2432. (kill-region (- (search-forward "<style") 6)
  2433. (search-forward "</style>"))
  2434. (insert org-agenda-export-html-style))
  2435. (write-file file)
  2436. (kill-buffer (current-buffer))
  2437. (message "HTML written to %s" file))
  2438. ((string-match "\\.ps\\'" file)
  2439. (require 'ps-print)
  2440. (ps-print-buffer-with-faces file)
  2441. (message "Postscript written to %s" file))
  2442. ((string-match "\\.pdf\\'" file)
  2443. (require 'ps-print)
  2444. (ps-print-buffer-with-faces
  2445. (concat (file-name-sans-extension file) ".ps"))
  2446. (call-process "ps2pdf" nil nil nil
  2447. (expand-file-name
  2448. (concat (file-name-sans-extension file) ".ps"))
  2449. (expand-file-name file))
  2450. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2451. (message "PDF written to %s" file))
  2452. ((string-match "\\.ics\\'" file)
  2453. (require 'org-icalendar)
  2454. (let ((org-agenda-marker-table
  2455. (org-create-marker-find-array
  2456. (org-agenda-collect-markers)))
  2457. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2458. (org-combined-agenda-icalendar-file file))
  2459. (apply 'org-export-icalendar 'combine
  2460. (org-agenda-files nil 'ifmode))))
  2461. (t
  2462. (let ((bs (buffer-string)))
  2463. (find-file file)
  2464. (erase-buffer)
  2465. (insert bs)
  2466. (save-buffer 0)
  2467. (kill-buffer (current-buffer))
  2468. (message "Plain text written to %s" file))))))))
  2469. (set-buffer org-agenda-buffer-name))
  2470. (when open (org-open-file file)))
  2471. (defvar org-agenda-filter-overlays nil)
  2472. (defun org-agenda-mark-filtered-text ()
  2473. "Mark all text hidden by filtering with a text property."
  2474. (let ((inhibit-read-only t))
  2475. (mapc
  2476. (lambda (o)
  2477. (when (equal (overlay-buffer o) (current-buffer))
  2478. (put-text-property
  2479. (overlay-start o) (overlay-end o)
  2480. 'org-filtered t)))
  2481. org-agenda-filter-overlays)))
  2482. (defun org-agenda-unmark-filtered-text ()
  2483. "Remove the filtering text property."
  2484. (let ((inhibit-read-only t))
  2485. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2486. (defun org-agenda-remove-marked-text (property &optional value)
  2487. "Delete all text marked with VALUE of PROPERTY.
  2488. VALUE defaults to t."
  2489. (let (beg)
  2490. (setq value (or value t))
  2491. (while (setq beg (text-property-any (point-min) (point-max)
  2492. property value))
  2493. (delete-region
  2494. beg (or (next-single-property-change beg 'org-filtered)
  2495. (point-max))))))
  2496. (defun org-agenda-add-entry-text ()
  2497. "Add entry text to agenda lines.
  2498. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2499. entry text following headings shown in the agenda.
  2500. Drawers will be excluded, also the line with scheduling/deadline info."
  2501. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2502. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2503. (let (m txt)
  2504. (goto-char (point-min))
  2505. (while (not (eobp))
  2506. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2507. (beginning-of-line 2)
  2508. (setq txt (org-agenda-get-some-entry-text
  2509. m org-agenda-add-entry-text-maxlines " > "))
  2510. (end-of-line 1)
  2511. (if (string-match "\\S-" txt)
  2512. (insert "\n" txt)
  2513. (or (eobp) (forward-char 1))))))))
  2514. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2515. &rest keep)
  2516. "Extract entry text from MARKER, at most N-LINES lines.
  2517. This will ignore drawers etc, just get the text.
  2518. If INDENT is given, prefix every line with this string. If KEEP is
  2519. given, it is a list of symbols, defining stuff that should not be
  2520. removed from the entry content. Currently only `planning' is allowed here."
  2521. (let (txt drawer-re kwd-time-re ind)
  2522. (save-excursion
  2523. (with-current-buffer (marker-buffer marker)
  2524. (if (not (org-mode-p))
  2525. (setq txt "")
  2526. (save-excursion
  2527. (save-restriction
  2528. (widen)
  2529. (goto-char marker)
  2530. (end-of-line 1)
  2531. (setq txt (buffer-substring
  2532. (min (1+ (point)) (point-max))
  2533. (progn (outline-next-heading) (point)))
  2534. drawer-re org-drawer-regexp
  2535. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2536. ".*\n?"))
  2537. (with-temp-buffer
  2538. (insert txt)
  2539. (when org-agenda-add-entry-text-descriptive-links
  2540. (goto-char (point-min))
  2541. (while (org-activate-bracket-links (point-max))
  2542. (add-text-properties (match-beginning 0) (match-end 0)
  2543. '(face org-link))))
  2544. (goto-char (point-min))
  2545. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2546. (set-text-properties (match-beginning 0) (match-end 0)
  2547. nil))
  2548. (goto-char (point-min))
  2549. (while (re-search-forward drawer-re nil t)
  2550. (delete-region
  2551. (match-beginning 0)
  2552. (progn (re-search-forward
  2553. "^[ \t]*:END:.*\n?" nil 'move)
  2554. (point))))
  2555. (unless (member 'planning keep)
  2556. (goto-char (point-min))
  2557. (while (re-search-forward kwd-time-re nil t)
  2558. (replace-match "")))
  2559. (goto-char (point-min))
  2560. (when org-agenda-entry-text-exclude-regexps
  2561. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2562. (while (setq re (pop re-list))
  2563. (goto-char (point-min))
  2564. (while (re-search-forward re nil t)
  2565. (replace-match "")))))
  2566. (goto-char (point-max))
  2567. (skip-chars-backward " \t\n")
  2568. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2569. ;; find and remove min common indentation
  2570. (goto-char (point-min))
  2571. (untabify (point-min) (point-max))
  2572. (setq ind (org-get-indentation))
  2573. (while (not (eobp))
  2574. (unless (looking-at "[ \t]*$")
  2575. (setq ind (min ind (org-get-indentation))))
  2576. (beginning-of-line 2))
  2577. (goto-char (point-min))
  2578. (while (not (eobp))
  2579. (unless (looking-at "[ \t]*$")
  2580. (move-to-column ind)
  2581. (delete-region (point-at-bol) (point)))
  2582. (beginning-of-line 2))
  2583. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2584. (goto-char (point-min))
  2585. (when indent
  2586. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2587. (replace-match indent t t)))
  2588. (goto-char (point-min))
  2589. (while (looking-at "[ \t]*\n") (replace-match ""))
  2590. (goto-char (point-max))
  2591. (when (> (org-current-line)
  2592. n-lines)
  2593. (org-goto-line (1+ n-lines))
  2594. (backward-char 1))
  2595. (setq txt (buffer-substring (point-min) (point)))))))))
  2596. txt))
  2597. (defun org-agenda-collect-markers ()
  2598. "Collect the markers pointing to entries in the agenda buffer."
  2599. (let (m markers)
  2600. (save-excursion
  2601. (goto-char (point-min))
  2602. (while (not (eobp))
  2603. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2604. (org-get-at-bol 'org-marker)))
  2605. (push m markers))
  2606. (beginning-of-line 2)))
  2607. (nreverse markers)))
  2608. (defun org-create-marker-find-array (marker-list)
  2609. "Create a alist of files names with all marker positions in that file."
  2610. (let (f tbl m a p)
  2611. (while (setq m (pop marker-list))
  2612. (setq p (marker-position m)
  2613. f (buffer-file-name (or (buffer-base-buffer
  2614. (marker-buffer m))
  2615. (marker-buffer m))))
  2616. (if (setq a (assoc f tbl))
  2617. (push (marker-position m) (cdr a))
  2618. (push (list f p) tbl)))
  2619. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2620. tbl)))
  2621. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2622. (defun org-check-agenda-marker-table ()
  2623. "Check of the current entry is on the marker list."
  2624. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2625. a)
  2626. (and (setq a (assoc file org-agenda-marker-table))
  2627. (save-match-data
  2628. (save-excursion
  2629. (org-back-to-heading t)
  2630. (member (point) (cdr a)))))))
  2631. (defun org-check-for-org-mode ()
  2632. "Make sure current buffer is in org-mode. Error if not."
  2633. (or (org-mode-p)
  2634. (error "Cannot execute org-mode agenda command on buffer in %s"
  2635. major-mode)))
  2636. (defun org-fit-agenda-window ()
  2637. "Fit the window to the buffer size."
  2638. (and (memq org-agenda-window-setup '(reorganize-frame))
  2639. (fboundp 'fit-window-to-buffer)
  2640. (org-fit-window-to-buffer
  2641. nil
  2642. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2643. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2644. ;;; Agenda prepare and finalize
  2645. (defvar org-agenda-multi nil) ; dynamically scoped
  2646. (defvar org-agenda-buffer-name "*Org Agenda*")
  2647. (defvar org-pre-agenda-window-conf nil)
  2648. (defvar org-agenda-columns-active nil)
  2649. (defvar org-agenda-name nil)
  2650. (defvar org-agenda-filter nil)
  2651. (defvar org-agenda-filter-while-redo nil)
  2652. (defvar org-agenda-filter-preset nil
  2653. "A preset of the tags filter used for secondary agenda filtering.
  2654. This must be a list of strings, each string must be a single tag preceded
  2655. by \"+\" or \"-\".
  2656. This variable should not be set directly, but agenda custom commands can
  2657. bind it in the options section. The preset filter is a global property of
  2658. the entire agenda view. In a block agenda, it will not work reliably to
  2659. define a filter for one of the individual blocks. You need to set it in
  2660. the global options and expect it to be applied to the entire view.")
  2661. (defun org-prepare-agenda (&optional name)
  2662. (setq org-todo-keywords-for-agenda nil)
  2663. (setq org-done-keywords-for-agenda nil)
  2664. (setq org-drawers-for-agenda nil)
  2665. (unless org-agenda-persistent-filter
  2666. (setq org-agenda-filter nil))
  2667. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2668. (if org-agenda-multi
  2669. (progn
  2670. (setq buffer-read-only nil)
  2671. (goto-char (point-max))
  2672. (unless (or (bobp) org-agenda-compact-blocks)
  2673. (insert "\n"
  2674. (if (stringp org-agenda-block-separator)
  2675. org-agenda-block-separator
  2676. (make-string (window-width) org-agenda-block-separator))
  2677. "\n"))
  2678. (narrow-to-region (point) (point-max)))
  2679. (org-agenda-reset-markers)
  2680. (setq org-agenda-contributing-files nil)
  2681. (setq org-agenda-columns-active nil)
  2682. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2683. (setq org-todo-keywords-for-agenda
  2684. (org-uniquify org-todo-keywords-for-agenda))
  2685. (setq org-done-keywords-for-agenda
  2686. (org-uniquify org-done-keywords-for-agenda))
  2687. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2688. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2689. (awin (get-buffer-window abuf)))
  2690. (cond
  2691. ((equal (current-buffer) abuf) nil)
  2692. (awin (select-window awin))
  2693. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2694. ((equal org-agenda-window-setup 'current-window)
  2695. (switch-to-buffer abuf))
  2696. ((equal org-agenda-window-setup 'other-window)
  2697. (org-switch-to-buffer-other-window abuf))
  2698. ((equal org-agenda-window-setup 'other-frame)
  2699. (switch-to-buffer-other-frame abuf))
  2700. ((equal org-agenda-window-setup 'reorganize-frame)
  2701. (delete-other-windows)
  2702. (org-switch-to-buffer-other-window abuf)))
  2703. ;; additional test in case agenda is invoked from within agenda
  2704. ;; buffer via elisp link
  2705. (unless (equal (current-buffer) abuf)
  2706. (switch-to-buffer abuf)))
  2707. (setq buffer-read-only nil)
  2708. (let ((inhibit-read-only t)) (erase-buffer))
  2709. (org-agenda-mode)
  2710. (and name (not org-agenda-name)
  2711. (org-set-local 'org-agenda-name name)))
  2712. (setq buffer-read-only nil))
  2713. (defun org-finalize-agenda ()
  2714. "Finishing touch for the agenda buffer, called just before displaying it."
  2715. (unless org-agenda-multi
  2716. (save-excursion
  2717. (let ((inhibit-read-only t))
  2718. (goto-char (point-min))
  2719. (while (org-activate-bracket-links (point-max))
  2720. (add-text-properties (match-beginning 0) (match-end 0)
  2721. '(face org-link)))
  2722. (org-agenda-align-tags)
  2723. (unless org-agenda-with-colors
  2724. (remove-text-properties (point-min) (point-max) '(face nil))))
  2725. (if (and (boundp 'org-agenda-overriding-columns-format)
  2726. org-agenda-overriding-columns-format)
  2727. (org-set-local 'org-agenda-overriding-columns-format
  2728. org-agenda-overriding-columns-format))
  2729. (if (and (boundp 'org-agenda-view-columns-initially)
  2730. org-agenda-view-columns-initially)
  2731. (org-agenda-columns))
  2732. (when org-agenda-fontify-priorities
  2733. (org-agenda-fontify-priorities))
  2734. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2735. (org-agenda-dim-blocked-tasks))
  2736. (org-agenda-mark-clocking-task)
  2737. (when org-agenda-entry-text-mode
  2738. (org-agenda-entry-text-hide)
  2739. (org-agenda-entry-text-show))
  2740. (if (functionp 'org-habit-insert-consistency-graphs)
  2741. (org-habit-insert-consistency-graphs))
  2742. (run-hooks 'org-finalize-agenda-hook)
  2743. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2744. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2745. (org-agenda-filter-apply org-agenda-filter))
  2746. )))
  2747. (defun org-agenda-mark-clocking-task ()
  2748. "Mark the current clock entry in the agenda if it is present."
  2749. (mapc (lambda (o)
  2750. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2751. (delete-overlay o)))
  2752. (overlays-in (point-min) (point-max)))
  2753. (when (marker-buffer org-clock-hd-marker)
  2754. (save-excursion
  2755. (goto-char (point-min))
  2756. (let (s ov)
  2757. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2758. (goto-char s)
  2759. (when (equal (org-get-at-bol 'org-hd-marker)
  2760. org-clock-hd-marker)
  2761. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2762. (overlay-put ov 'type 'org-agenda-clocking)
  2763. (overlay-put ov 'face 'org-agenda-clocking)
  2764. (overlay-put ov 'help-echo
  2765. "The clock is running in this item")))))))
  2766. (defun org-agenda-fontify-priorities ()
  2767. "Make highest priority lines bold, and lowest italic."
  2768. (interactive)
  2769. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2770. (delete-overlay o)))
  2771. (overlays-in (point-min) (point-max)))
  2772. (save-excursion
  2773. (let ((inhibit-read-only t)
  2774. b e p ov h l)
  2775. (goto-char (point-min))
  2776. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2777. (setq h (or (get-char-property (point) 'org-highest-priority)
  2778. org-highest-priority)
  2779. l (or (get-char-property (point) 'org-lowest-priority)
  2780. org-lowest-priority)
  2781. p (string-to-char (match-string 1))
  2782. b (match-beginning 0)
  2783. e (if (eq org-agenda-fontify-priorities 'cookies)
  2784. (match-end 0)
  2785. (point-at-eol))
  2786. ov (make-overlay b e))
  2787. (overlay-put
  2788. ov 'face
  2789. (cond ((org-face-from-face-or-color
  2790. 'priority nil
  2791. (cdr (assoc p org-priority-faces))))
  2792. ((and (listp org-agenda-fontify-priorities)
  2793. (org-face-from-face-or-color
  2794. 'priority nil
  2795. (cdr (assoc p org-agenda-fontify-priorities)))))
  2796. ((equal p l) 'italic)
  2797. ((equal p h) 'bold)))
  2798. (overlay-put ov 'org-type 'org-priority)))))
  2799. (defun org-agenda-dim-blocked-tasks ()
  2800. "Dim currently blocked TODO's in the agenda display."
  2801. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2802. (delete-overlay o)))
  2803. (overlays-in (point-min) (point-max)))
  2804. (save-excursion
  2805. (let ((inhibit-read-only t)
  2806. (org-depend-tag-blocked nil)
  2807. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2808. org-blocked-by-checkboxes
  2809. invis1 b e p ov h l)
  2810. (goto-char (point-min))
  2811. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2812. (and pos (goto-char (1+ pos))))
  2813. (setq org-blocked-by-checkboxes nil invis1 invis)
  2814. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2815. (when (and marker
  2816. (not (with-current-buffer (marker-buffer marker)
  2817. (save-excursion
  2818. (goto-char marker)
  2819. (if (org-entry-get nil "NOBLOCKING")
  2820. t ;; Never block this entry
  2821. (run-hook-with-args-until-failure
  2822. 'org-blocker-hook
  2823. (list :type 'todo-state-change
  2824. :position marker
  2825. :from 'todo
  2826. :to 'done)))))))
  2827. (if org-blocked-by-checkboxes (setq invis1 nil))
  2828. (setq b (if invis1
  2829. (max (point-min) (1- (point-at-bol)))
  2830. (point-at-bol))
  2831. e (point-at-eol)
  2832. ov (make-overlay b e))
  2833. (if invis1
  2834. (overlay-put ov 'invisible t)
  2835. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2836. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2837. (defvar org-agenda-skip-function nil
  2838. "Function to be called at each match during agenda construction.
  2839. If this function returns nil, the current match should not be skipped.
  2840. Otherwise, the function must return a position from where the search
  2841. should be continued.
  2842. This may also be a Lisp form, it will be evaluated.
  2843. Never set this variable using `setq' or so, because then it will apply
  2844. to all future agenda commands. Instead, bind it with `let' to scope
  2845. it dynamically into the agenda-constructing command. A good way to set
  2846. it is through options in `org-agenda-custom-commands'.")
  2847. (defun org-agenda-skip ()
  2848. "Throw to `:skip' in places that should be skipped.
  2849. Also moves point to the end of the skipped region, so that search can
  2850. continue from there."
  2851. (let ((p (point-at-bol)) to fp)
  2852. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2853. (get-text-property p :org-archived)
  2854. (org-end-of-subtree t)
  2855. (throw :skip t))
  2856. (and org-agenda-skip-comment-trees
  2857. (get-text-property p :org-comment)
  2858. (org-end-of-subtree t)
  2859. (throw :skip t))
  2860. (if (equal (char-after p) ?#) (throw :skip t))
  2861. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2862. (consp org-agenda-skip-function))
  2863. (setq to (save-excursion
  2864. (save-match-data
  2865. (if fp
  2866. (funcall org-agenda-skip-function)
  2867. (eval org-agenda-skip-function))))))
  2868. (goto-char to)
  2869. (throw :skip t))))
  2870. (defvar org-agenda-markers nil
  2871. "List of all currently active markers created by `org-agenda'.")
  2872. (defvar org-agenda-last-marker-time (org-float-time)
  2873. "Creation time of the last agenda marker.")
  2874. (defun org-agenda-new-marker (&optional pos)
  2875. "Return a new agenda marker.
  2876. Org-mode keeps a list of these markers and resets them when they are
  2877. no longer in use."
  2878. (let ((m (copy-marker (or pos (point)))))
  2879. (setq org-agenda-last-marker-time (org-float-time))
  2880. (push m org-agenda-markers)
  2881. m))
  2882. (defun org-agenda-reset-markers ()
  2883. "Reset markers created by `org-agenda'."
  2884. (while org-agenda-markers
  2885. (move-marker (pop org-agenda-markers) nil)))
  2886. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2887. "Save relative positions of markers in region."
  2888. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2889. org-agenda-markers))
  2890. ;;; Entry text mode
  2891. (defun org-agenda-entry-text-show-here ()
  2892. "Add some text from the entry as context to the current line."
  2893. (let (m txt o)
  2894. (setq m (org-get-at-bol 'org-hd-marker))
  2895. (unless (marker-buffer m)
  2896. (error "No marker points to an entry here"))
  2897. (setq txt (concat "\n" (org-no-properties
  2898. (org-agenda-get-some-entry-text
  2899. m org-agenda-entry-text-maxlines " > "))))
  2900. (when (string-match "\\S-" txt)
  2901. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2902. (overlay-put o 'evaporate t)
  2903. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2904. (overlay-put o 'after-string txt))))
  2905. (defun org-agenda-entry-text-show ()
  2906. "Add entry context for all agenda lines."
  2907. (interactive)
  2908. (save-excursion
  2909. (goto-char (point-max))
  2910. (beginning-of-line 1)
  2911. (while (not (bobp))
  2912. (when (org-get-at-bol 'org-hd-marker)
  2913. (org-agenda-entry-text-show-here))
  2914. (beginning-of-line 0))))
  2915. (defun org-agenda-entry-text-hide ()
  2916. "Remove any shown entry context."
  2917. (delq nil
  2918. (mapcar (lambda (o)
  2919. (if (eq (overlay-get o 'org-overlay-type)
  2920. 'agenda-entry-content)
  2921. (progn (delete-overlay o) t)))
  2922. (overlays-in (point-min) (point-max)))))
  2923. (defun org-agenda-get-day-face (date)
  2924. "Return the face DATE should be displayed with."
  2925. (or (and (functionp org-agenda-day-face-function)
  2926. (funcall org-agenda-day-face-function date))
  2927. (cond ((org-agenda-todayp date)
  2928. 'org-agenda-date-today)
  2929. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  2930. 'org-agenda-date-weekend)
  2931. (t 'org-agenda-date))))
  2932. ;;; Agenda timeline
  2933. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2934. (defun org-timeline (&optional include-all)
  2935. "Show a time-sorted view of the entries in the current org file.
  2936. Only entries with a time stamp of today or later will be listed. With
  2937. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2938. under the current date.
  2939. If the buffer contains an active region, only check the region for
  2940. dates."
  2941. (interactive "P")
  2942. (org-compile-prefix-format 'timeline)
  2943. (org-set-sorting-strategy 'timeline)
  2944. (let* ((dopast t)
  2945. (dotodo include-all)
  2946. (doclosed org-agenda-show-log)
  2947. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2948. (current-buffer))))
  2949. (date (calendar-current-date))
  2950. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2951. (end (if (org-region-active-p) (region-end) (point-max)))
  2952. (day-numbers (org-get-all-dates beg end 'no-ranges
  2953. t doclosed ; always include today
  2954. org-timeline-show-empty-dates))
  2955. (org-deadline-warning-days 0)
  2956. (org-agenda-only-exact-dates t)
  2957. (today (org-today))
  2958. (past t)
  2959. args
  2960. s e rtn d emptyp)
  2961. (setq org-agenda-redo-command
  2962. (list 'progn
  2963. (list 'org-switch-to-buffer-other-window (current-buffer))
  2964. (list 'org-timeline (list 'quote include-all))))
  2965. (if (not dopast)
  2966. ;; Remove past dates from the list of dates.
  2967. (setq day-numbers (delq nil (mapcar (lambda(x)
  2968. (if (>= x today) x nil))
  2969. day-numbers))))
  2970. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2971. (if doclosed (push :closed args))
  2972. (push :timestamp args)
  2973. (push :deadline args)
  2974. (push :scheduled args)
  2975. (push :sexp args)
  2976. (if dotodo (push :todo args))
  2977. (insert "Timeline of file " entry "\n")
  2978. (add-text-properties (point-min) (point)
  2979. (list 'face 'org-agenda-structure))
  2980. (org-agenda-mark-header-line (point-min))
  2981. (while (setq d (pop day-numbers))
  2982. (if (and (listp d) (eq (car d) :omitted))
  2983. (progn
  2984. (setq s (point))
  2985. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2986. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2987. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2988. (if (and (>= d today)
  2989. dopast
  2990. past)
  2991. (progn
  2992. (setq past nil)
  2993. (insert (make-string 79 ?-) "\n")))
  2994. (setq date (calendar-gregorian-from-absolute d))
  2995. (setq s (point))
  2996. (setq rtn (and (not emptyp)
  2997. (apply 'org-agenda-get-day-entries entry
  2998. date args)))
  2999. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3000. (progn
  3001. (insert
  3002. (if (stringp org-agenda-format-date)
  3003. (format-time-string org-agenda-format-date
  3004. (org-time-from-absolute date))
  3005. (funcall org-agenda-format-date date))
  3006. "\n")
  3007. (put-text-property s (1- (point)) 'face
  3008. (org-agenda-get-day-face date))
  3009. (put-text-property s (1- (point)) 'org-date-line t)
  3010. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3011. (if (equal d today)
  3012. (put-text-property s (1- (point)) 'org-today t))
  3013. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3014. (put-text-property s (1- (point)) 'day d)))))
  3015. (goto-char (point-min))
  3016. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3017. (point-min)))
  3018. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3019. (org-finalize-agenda)
  3020. (setq buffer-read-only t)))
  3021. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3022. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3023. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3024. not every single day in the range. If FORCE-TODAY is non-nil, make
  3025. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3026. inactive time stamps (those in square brackets) are included.
  3027. When EMPTY is non-nil, also include days without any entries."
  3028. (let ((re (concat
  3029. (if pre-re pre-re "")
  3030. (if inactive org-ts-regexp-both org-ts-regexp)))
  3031. dates dates1 date day day1 day2 ts1 ts2)
  3032. (if force-today
  3033. (setq dates (list (org-today))))
  3034. (save-excursion
  3035. (goto-char beg)
  3036. (while (re-search-forward re end t)
  3037. (setq day (time-to-days (org-time-string-to-time
  3038. (substring (match-string 1) 0 10))))
  3039. (or (memq day dates) (push day dates)))
  3040. (unless no-ranges
  3041. (goto-char beg)
  3042. (while (re-search-forward org-tr-regexp end t)
  3043. (setq ts1 (substring (match-string 1) 0 10)
  3044. ts2 (substring (match-string 2) 0 10)
  3045. day1 (time-to-days (org-time-string-to-time ts1))
  3046. day2 (time-to-days (org-time-string-to-time ts2)))
  3047. (while (< (setq day1 (1+ day1)) day2)
  3048. (or (memq day1 dates) (push day1 dates)))))
  3049. (setq dates (sort dates '<))
  3050. (when empty
  3051. (while (setq day (pop dates))
  3052. (setq day2 (car dates))
  3053. (push day dates1)
  3054. (when (and day2 empty)
  3055. (if (or (eq empty t)
  3056. (and (numberp empty) (<= (- day2 day) empty)))
  3057. (while (< (setq day (1+ day)) day2)
  3058. (push (list day) dates1))
  3059. (push (cons :omitted (- day2 day)) dates1))))
  3060. (setq dates (nreverse dates1)))
  3061. dates)))
  3062. ;;; Agenda Daily/Weekly
  3063. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  3064. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3065. "Custom commands can set this variable in the options section.")
  3066. (defvar org-agenda-last-arguments nil
  3067. "The arguments of the previous call to `org-agenda'.")
  3068. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3069. (defvar org-agenda-current-span nil
  3070. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3071. (defvar org-include-all-loc nil) ; local variable
  3072. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3073. "List of types searched for when creating the daily/weekly agenda.
  3074. This variable is a list of symbols that controls the types of
  3075. items that appear in the daily/weekly agenda. Allowed symbols in this
  3076. list are are
  3077. :timestamp List items containing a date stamp or date range matching
  3078. the selected date. This includes sexp entries in
  3079. angular brackets.
  3080. :sexp List entries resulting from plain diary-like sexps.
  3081. :deadline List deadline due on that date. When the date is today,
  3082. also list any deadlines past due, or due within
  3083. `org-deadline-warning-days'. `:deadline' must appear before
  3084. `:scheduled' if the setting of
  3085. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3086. any effect.
  3087. :scheduled List all items which are scheduled for the given date.
  3088. The diary for *today* also contains items which were
  3089. scheduled earlier and are not yet marked DONE.
  3090. By default, all four types are turned on.
  3091. Never set this variable globally using `setq', because then it
  3092. will apply to all future agenda commands. Instead, bind it with
  3093. `let' to scope it dynamically into the the agenda-constructing
  3094. command. A good way to set it is through options in
  3095. `org-agenda-custom-commands'. For a more flexible (though
  3096. somewhat less efficient) way of determining what is included in
  3097. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3098. ;;;###autoload
  3099. (defun org-agenda-list (&optional include-all start-day span)
  3100. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3101. The view will be for the current day or week, but from the overview buffer
  3102. you will be able to go to other days/weeks.
  3103. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3104. all unfinished TODO items will also be shown, before the agenda.
  3105. This feature is considered obsolete, please use the TODO list or a block
  3106. agenda instead.
  3107. With a numeric prefix argument in an interactive call, the agenda will
  3108. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3109. the number of days. SPAN defaults to `org-agenda-span'.
  3110. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3111. given in `org-agenda-start-on-weekday'."
  3112. (interactive "P")
  3113. (if (and (integerp include-all) (> include-all 0))
  3114. (setq span include-all include-all nil))
  3115. (setq start-day (or start-day org-agenda-start-day))
  3116. (if org-agenda-overriding-arguments
  3117. (setq include-all (car org-agenda-overriding-arguments)
  3118. start-day (nth 1 org-agenda-overriding-arguments)
  3119. span (nth 2 org-agenda-overriding-arguments)))
  3120. (if (stringp start-day)
  3121. ;; Convert to an absolute day number
  3122. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3123. (setq org-agenda-last-arguments (list include-all start-day span))
  3124. (org-compile-prefix-format 'agenda)
  3125. (org-set-sorting-strategy 'agenda)
  3126. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
  3127. (today (org-today))
  3128. (sd (or start-day today))
  3129. (ndays (org-agenda-span-to-ndays span sd))
  3130. (org-agenda-start-on-weekday
  3131. (if (eq ndays 7)
  3132. org-agenda-start-on-weekday))
  3133. (thefiles (org-agenda-files nil 'ifmode))
  3134. (files thefiles)
  3135. (start (if (or (null org-agenda-start-on-weekday)
  3136. (< ndays 7))
  3137. sd
  3138. (let* ((nt (calendar-day-of-week
  3139. (calendar-gregorian-from-absolute sd)))
  3140. (n1 org-agenda-start-on-weekday)
  3141. (d (- nt n1)))
  3142. (- sd (+ (if (< d 0) 7 0) d)))))
  3143. (day-numbers (list start))
  3144. (day-cnt 0)
  3145. (inhibit-redisplay (not debug-on-error))
  3146. s e rtn rtnall file date d start-pos end-pos todayp
  3147. clocktable-start clocktable-end filter)
  3148. (setq org-agenda-redo-command
  3149. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3150. (dotimes (n (1- ndays))
  3151. (push (1+ (car day-numbers)) day-numbers))
  3152. (setq day-numbers (nreverse day-numbers))
  3153. (setq clocktable-start (car day-numbers)
  3154. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3155. (org-prepare-agenda "Day/Week")
  3156. (org-set-local 'org-starting-day (car day-numbers))
  3157. (org-set-local 'org-include-all-loc include-all)
  3158. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3159. (when (and (or include-all org-agenda-include-all-todo)
  3160. (member today day-numbers))
  3161. (setq files thefiles
  3162. rtnall nil)
  3163. (while (setq file (pop files))
  3164. (catch 'nextfile
  3165. (org-check-agenda-file file)
  3166. (setq date (calendar-gregorian-from-absolute today)
  3167. rtn (org-agenda-get-day-entries
  3168. file date :todo))
  3169. (setq rtnall (append rtnall rtn))))
  3170. (when rtnall
  3171. (insert "All currently open TODO items:\n")
  3172. (add-text-properties (point-min) (1- (point))
  3173. (list 'face 'org-agenda-structure
  3174. 'short-heading "All TODO items"))
  3175. (org-agenda-mark-header-line (point-min))
  3176. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3177. (unless org-agenda-compact-blocks
  3178. (let* ((d1 (car day-numbers))
  3179. (d2 (org-last day-numbers))
  3180. (w1 (org-days-to-iso-week d1))
  3181. (w2 (org-days-to-iso-week d2)))
  3182. (setq s (point))
  3183. (if org-agenda-overriding-header
  3184. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3185. nil 'face 'org-agenda-structure) "\n")
  3186. (insert (org-agenda-span-name span)
  3187. "-agenda"
  3188. (if (< (- d2 d1) 350)
  3189. (if (= w1 w2)
  3190. (format " (W%02d)" w1)
  3191. (format " (W%02d-W%02d)" w1 w2))
  3192. "")
  3193. ":\n")))
  3194. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3195. 'org-date-line t))
  3196. (org-agenda-mark-header-line s))
  3197. (while (setq d (pop day-numbers))
  3198. (setq date (calendar-gregorian-from-absolute d)
  3199. s (point))
  3200. (if (or (setq todayp (= d today))
  3201. (and (not start-pos) (= d sd)))
  3202. (setq start-pos (point))
  3203. (if (and start-pos (not end-pos))
  3204. (setq end-pos (point))))
  3205. (setq files thefiles
  3206. rtnall nil)
  3207. (while (setq file (pop files))
  3208. (catch 'nextfile
  3209. (org-check-agenda-file file)
  3210. (let ((org-agenda-entry-types org-agenda-entry-types))
  3211. (unless org-agenda-include-deadlines
  3212. (setq org-agenda-entry-types
  3213. (delq :deadline org-agenda-entry-types)))
  3214. (cond
  3215. ((eq org-agenda-show-log 'only)
  3216. (setq rtn (org-agenda-get-day-entries
  3217. file date :closed)))
  3218. (org-agenda-show-log
  3219. (setq rtn (apply 'org-agenda-get-day-entries
  3220. file date
  3221. (append '(:closed) org-agenda-entry-types))))
  3222. (t
  3223. (setq rtn (apply 'org-agenda-get-day-entries
  3224. file date
  3225. org-agenda-entry-types)))))
  3226. (setq rtnall (append rtnall rtn))))
  3227. (if org-agenda-include-diary
  3228. (let ((org-agenda-search-headline-for-time t))
  3229. (require 'diary-lib)
  3230. (setq rtn (org-get-entries-from-diary date))
  3231. (setq rtnall (append rtnall rtn))))
  3232. (if (or rtnall org-agenda-show-all-dates)
  3233. (progn
  3234. (setq day-cnt (1+ day-cnt))
  3235. (insert
  3236. (if (stringp org-agenda-format-date)
  3237. (format-time-string org-agenda-format-date
  3238. (org-time-from-absolute date))
  3239. (funcall org-agenda-format-date date))
  3240. "\n")
  3241. (put-text-property s (1- (point)) 'face
  3242. (org-agenda-get-day-face date))
  3243. (put-text-property s (1- (point)) 'org-date-line t)
  3244. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3245. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3246. (when todayp
  3247. (put-text-property s (1- (point)) 'org-today t))
  3248. (if rtnall (insert
  3249. (org-finalize-agenda-entries
  3250. (org-agenda-add-time-grid-maybe
  3251. rtnall ndays todayp))
  3252. "\n"))
  3253. (put-text-property s (1- (point)) 'day d)
  3254. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3255. (when (and org-agenda-clockreport-mode clocktable-start)
  3256. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3257. ;; the above line is to ensure the restricted range!
  3258. (p org-agenda-clockreport-parameter-plist)
  3259. tbl)
  3260. (setq p (org-plist-delete p :block))
  3261. (setq p (plist-put p :tstart clocktable-start))
  3262. (setq p (plist-put p :tend clocktable-end))
  3263. (setq p (plist-put p :scope 'agenda))
  3264. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3265. (setq filter (or org-agenda-filter-while-redo
  3266. (get 'org-agenda-filter :preset-filter))))
  3267. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3268. (if (string-match "[<>=]" x)
  3269. ""
  3270. x))
  3271. filter ""))))
  3272. (message "%s" (plist-get p :tags)) (sit-for 2)
  3273. (setq tbl (apply 'org-get-clocktable p))
  3274. (insert tbl)))
  3275. (goto-char (point-min))
  3276. (or org-agenda-multi (org-fit-agenda-window))
  3277. (unless (and (pos-visible-in-window-p (point-min))
  3278. (pos-visible-in-window-p (point-max)))
  3279. (goto-char (1- (point-max)))
  3280. (recenter -1)
  3281. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3282. (progn
  3283. (goto-char (or start-pos 1))
  3284. (recenter 1))))
  3285. (goto-char (or start-pos 1))
  3286. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3287. (org-finalize-agenda)
  3288. (setq buffer-read-only t)
  3289. (message "")))
  3290. (defun org-agenda-ndays-to-span (n)
  3291. "Return a span symbol for a span of N days, or N if none matches."
  3292. (cond ((symbolp n) n)
  3293. ((= n 1) 'day)
  3294. ((= n 7) 'week)
  3295. (t n)))
  3296. (defun org-agenda-span-to-ndays (span start-day)
  3297. "Return ndays from SPAN starting at START-DAY."
  3298. (cond ((numberp span) span)
  3299. ((eq span 'day) 1)
  3300. ((eq span 'week) 7)
  3301. ((eq span 'month)
  3302. (let ((date (calendar-gregorian-from-absolute start-day)))
  3303. (calendar-last-day-of-month (car date) (caddr date))))
  3304. ((eq span 'year)
  3305. (let ((date (calendar-gregorian-from-absolute start-day)))
  3306. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3307. (defun org-agenda-span-name (span)
  3308. "Return a SPAN name."
  3309. (if (null span)
  3310. ""
  3311. (if (symbolp span)
  3312. (capitalize (symbol-name span))
  3313. (format "%d days" span))))
  3314. ;;; Agenda word search
  3315. (defvar org-agenda-search-history nil)
  3316. (defvar org-todo-only nil)
  3317. (defvar org-search-syntax-table nil
  3318. "Special syntax table for org-mode search.
  3319. In this table, we have single quotes not as word constituents, to
  3320. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3321. (defun org-search-syntax-table ()
  3322. (unless org-search-syntax-table
  3323. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3324. (modify-syntax-entry ?' "." org-search-syntax-table)
  3325. (modify-syntax-entry ?` "." org-search-syntax-table))
  3326. org-search-syntax-table)
  3327. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3328. ;;;###autoload
  3329. (defun org-search-view (&optional todo-only string edit-at)
  3330. "Show all entries that contain a phrase or words or regular expressions.
  3331. With optional prefix argument TODO-ONLY, only consider entries that are
  3332. TODO entries. The argument STRING can be used to pass a default search
  3333. string into this function. If EDIT-AT is non-nil, it means that the
  3334. user should get a chance to edit this string, with cursor at position
  3335. EDIT-AT.
  3336. The search string can be viewed either as a phrase that should be found as
  3337. is, or it can be broken into a number of snippets, each of which must match
  3338. in a Boolean way to select an entry. The default depends on the variable
  3339. `org-agenda-search-view-always-boolean'.
  3340. Even if this is turned off (the default) you can always switch to
  3341. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3342. The default is a direct search of the whole phrase, where each space in
  3343. the search string can expand to an arbitrary amount of whitespace,
  3344. including newlines.
  3345. If using a Boolean search, the search string is split on whitespace and
  3346. each snippet is searched separately, with logical AND to select an entry.
  3347. Words prefixed with a minus must *not* occur in the entry. Words without
  3348. a prefix or prefixed with a plus must occur in the entry. Matching is
  3349. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3350. match whole words, not parts of a word) if
  3351. `org-agenda-search-view-force-full-words' is set (default is nil).
  3352. Boolean search snippets enclosed by curly braces are interpreted as
  3353. regular expressions that must or (when preceded with \"-\") must not
  3354. match in the entry. Snippets enclosed into double quotes will be taken
  3355. as a whole, to include whitespace.
  3356. - If the search string starts with an asterisk, search only in headlines.
  3357. - If (possibly after the leading star) the search string starts with an
  3358. exclamation mark, this also means to look at TODO entries only, an effect
  3359. that can also be achieved with a prefix argument.
  3360. - If (possibly after star and exclamation mark) the search string starts
  3361. with a colon, this will mean that the (non-regexp) snippets of the
  3362. Boolean search must match as full words.
  3363. This command searches the agenda files, and in addition the files listed
  3364. in `org-agenda-text-search-extra-files'."
  3365. (interactive "P")
  3366. (org-compile-prefix-format 'search)
  3367. (org-set-sorting-strategy 'search)
  3368. (org-prepare-agenda "SEARCH")
  3369. (let* ((props (list 'face nil
  3370. 'done-face 'org-agenda-done
  3371. 'org-not-done-regexp org-not-done-regexp
  3372. 'org-todo-regexp org-todo-regexp
  3373. 'org-complex-heading-regexp org-complex-heading-regexp
  3374. 'mouse-face 'highlight
  3375. 'help-echo (format "mouse-2 or RET jump to location")))
  3376. (full-words org-agenda-search-view-force-full-words)
  3377. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3378. regexp rtn rtnall files file pos
  3379. marker category tags c neg re boolean
  3380. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3381. (unless (and (not edit-at)
  3382. (stringp string)
  3383. (string-match "\\S-" string))
  3384. (setq string (read-string
  3385. (if org-agenda-search-view-always-boolean
  3386. "[+-]Word/{Regexp} ...: "
  3387. "Phrase, or [+-]Word/{Regexp} ...: ")
  3388. (cond
  3389. ((integerp edit-at) (cons string edit-at))
  3390. (edit-at string))
  3391. 'org-agenda-search-history)))
  3392. (org-set-local 'org-todo-only todo-only)
  3393. (setq org-agenda-redo-command
  3394. (list 'org-search-view (if todo-only t nil) string
  3395. '(if current-prefix-arg 1 nil)))
  3396. (setq org-agenda-query-string string)
  3397. (if (equal (string-to-char string) ?*)
  3398. (setq hdl-only t
  3399. words (substring string 1))
  3400. (setq words string))
  3401. (when (equal (string-to-char words) ?!)
  3402. (setq todo-only t
  3403. words (substring words 1)))
  3404. (when (equal (string-to-char words) ?:)
  3405. (setq full-words t
  3406. words (substring words 1)))
  3407. (if (or org-agenda-search-view-always-boolean
  3408. (member (string-to-char words) '(?- ?+ ?\{)))
  3409. (setq boolean t))
  3410. (setq words (org-split-string words))
  3411. (let (www w)
  3412. (while (setq w (pop words))
  3413. (while (and (string-match "\\\\\\'" w) words)
  3414. (setq w (concat (substring w 0 -1) " " (pop words))))
  3415. (push w www))
  3416. (setq words (nreverse www) www nil)
  3417. (while (setq w (pop words))
  3418. (when (and (string-match "\\`[-+]?{" w)
  3419. (not (string-match "}\\'" w)))
  3420. (while (and words (not (string-match "}\\'" (car words))))
  3421. (setq w (concat w " " (pop words))))
  3422. (setq w (concat w " " (pop words))))
  3423. (push w www))
  3424. (setq words (nreverse www)))
  3425. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3426. (when boolean
  3427. (let (wds w)
  3428. (while (setq w (pop words))
  3429. (if (or (equal (substring w 0 1) "\"")
  3430. (and (> (length w) 1)
  3431. (member (substring w 0 1) '("+" "-"))
  3432. (equal (substring w 1 2) "\"")))
  3433. (while (and words (not (equal (substring w -1) "\"")))
  3434. (setq w (concat w " " (pop words)))))
  3435. (and (string-match "\\`\\([-+]?\\)\"" w)
  3436. (setq w (replace-match "\\1" nil nil w)))
  3437. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3438. (push w wds))
  3439. (setq words (nreverse wds))))
  3440. (if boolean
  3441. (mapc (lambda (w)
  3442. (setq c (string-to-char w))
  3443. (if (equal c ?-)
  3444. (setq neg t w (substring w 1))
  3445. (if (equal c ?+)
  3446. (setq neg nil w (substring w 1))
  3447. (setq neg nil)))
  3448. (if (string-match "\\`{.*}\\'" w)
  3449. (setq re (substring w 1 -1))
  3450. (if full-words
  3451. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3452. (setq re (regexp-quote (downcase w)))))
  3453. (if neg (push re regexps-) (push re regexps+)))
  3454. words)
  3455. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3456. regexps+))
  3457. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3458. (if (not regexps+)
  3459. (setq regexp (concat "^" org-outline-regexp))
  3460. (setq regexp (pop regexps+))
  3461. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3462. regexp))))
  3463. (setq files (org-agenda-files nil 'ifmode))
  3464. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3465. (pop org-agenda-text-search-extra-files)
  3466. (setq files (org-add-archive-files files)))
  3467. (setq files (append files org-agenda-text-search-extra-files)
  3468. rtnall nil)
  3469. (while (setq file (pop files))
  3470. (setq ee nil)
  3471. (catch 'nextfile
  3472. (org-check-agenda-file file)
  3473. (setq buffer (if (file-exists-p file)
  3474. (org-get-agenda-file-buffer file)
  3475. (error "No such file %s" file)))
  3476. (if (not buffer)
  3477. ;; If file does not exist, make sure an error message is sent
  3478. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3479. file))))
  3480. (with-current-buffer buffer
  3481. (with-syntax-table (org-search-syntax-table)
  3482. (unless (org-mode-p)
  3483. (error "Agenda file %s is not in `org-mode'" file))
  3484. (let ((case-fold-search t))
  3485. (save-excursion
  3486. (save-restriction
  3487. (if org-agenda-restrict
  3488. (narrow-to-region org-agenda-restrict-begin
  3489. org-agenda-restrict-end)
  3490. (widen))
  3491. (goto-char (point-min))
  3492. (unless (or (org-on-heading-p)
  3493. (outline-next-heading))
  3494. (throw 'nextfile t))
  3495. (goto-char (max (point-min) (1- (point))))
  3496. (while (re-search-forward regexp nil t)
  3497. (org-back-to-heading t)
  3498. (skip-chars-forward "* ")
  3499. (setq beg (point-at-bol)
  3500. beg1 (point)
  3501. end (progn (outline-next-heading) (point)))
  3502. (catch :skip
  3503. (goto-char beg)
  3504. (org-agenda-skip)
  3505. (setq str (buffer-substring-no-properties
  3506. (point-at-bol)
  3507. (if hdl-only (point-at-eol) end)))
  3508. (mapc (lambda (wr) (when (string-match wr str)
  3509. (goto-char (1- end))
  3510. (throw :skip t)))
  3511. regexps-)
  3512. (mapc (lambda (wr) (unless (string-match wr str)
  3513. (goto-char (1- end))
  3514. (throw :skip t)))
  3515. (if todo-only
  3516. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3517. regexps+)
  3518. regexps+))
  3519. (goto-char beg)
  3520. (setq marker (org-agenda-new-marker (point))
  3521. category (org-get-category)
  3522. tags (org-get-tags-at (point))
  3523. txt (org-format-agenda-item
  3524. ""
  3525. (buffer-substring-no-properties
  3526. beg1 (point-at-eol))
  3527. category tags))
  3528. (org-add-props txt props
  3529. 'org-marker marker 'org-hd-marker marker
  3530. 'org-todo-regexp org-todo-regexp
  3531. 'org-complex-heading-regexp org-complex-heading-regexp
  3532. 'priority 1000 'org-category category
  3533. 'type "search")
  3534. (push txt ee)
  3535. (goto-char (1- end))))))))))
  3536. (setq rtn (nreverse ee))
  3537. (setq rtnall (append rtnall rtn)))
  3538. (if org-agenda-overriding-header
  3539. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3540. nil 'face 'org-agenda-structure) "\n")
  3541. (insert "Search words: ")
  3542. (add-text-properties (point-min) (1- (point))
  3543. (list 'face 'org-agenda-structure))
  3544. (setq pos (point))
  3545. (insert string "\n")
  3546. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3547. (setq pos (point))
  3548. (unless org-agenda-multi
  3549. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3550. (add-text-properties pos (1- (point))
  3551. (list 'face 'org-agenda-structure))))
  3552. (org-agenda-mark-header-line (point-min))
  3553. (when rtnall
  3554. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3555. (goto-char (point-min))
  3556. (or org-agenda-multi (org-fit-agenda-window))
  3557. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3558. (org-finalize-agenda)
  3559. (setq buffer-read-only t)))
  3560. ;;; Agenda TODO list
  3561. (defvar org-select-this-todo-keyword nil)
  3562. (defvar org-last-arg nil)
  3563. ;;;###autoload
  3564. (defun org-todo-list (arg)
  3565. "Show all (not done) TODO entries from all agenda file in a single list.
  3566. The prefix arg can be used to select a specific TODO keyword and limit
  3567. the list to these. When using \\[universal-argument], you will be prompted
  3568. for a keyword. A numeric prefix directly selects the Nth keyword in
  3569. `org-todo-keywords-1'."
  3570. (interactive "P")
  3571. (org-compile-prefix-format 'todo)
  3572. (org-set-sorting-strategy 'todo)
  3573. (org-prepare-agenda "TODO")
  3574. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3575. (let* ((today (org-today))
  3576. (date (calendar-gregorian-from-absolute today))
  3577. (kwds org-todo-keywords-for-agenda)
  3578. (completion-ignore-case t)
  3579. (org-select-this-todo-keyword
  3580. (if (stringp arg) arg
  3581. (and arg (integerp arg) (> arg 0)
  3582. (nth (1- arg) kwds))))
  3583. rtn rtnall files file pos)
  3584. (when (equal arg '(4))
  3585. (setq org-select-this-todo-keyword
  3586. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3587. (mapcar 'list kwds) nil nil)))
  3588. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3589. (org-set-local 'org-last-arg arg)
  3590. (setq org-agenda-redo-command
  3591. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3592. (setq files (org-agenda-files nil 'ifmode)
  3593. rtnall nil)
  3594. (while (setq file (pop files))
  3595. (catch 'nextfile
  3596. (org-check-agenda-file file)
  3597. (setq rtn (org-agenda-get-day-entries file date :todo))
  3598. (setq rtnall (append rtnall rtn))))
  3599. (if org-agenda-overriding-header
  3600. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3601. nil 'face 'org-agenda-structure) "\n")
  3602. (insert "Global list of TODO items of type: ")
  3603. (add-text-properties (point-min) (1- (point))
  3604. (list 'face 'org-agenda-structure
  3605. 'short-heading
  3606. (concat "ToDo: "
  3607. (or org-select-this-todo-keyword "ALL"))))
  3608. (org-agenda-mark-header-line (point-min))
  3609. (setq pos (point))
  3610. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3611. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3612. (setq pos (point))
  3613. (unless org-agenda-multi
  3614. (insert "Available with `N r': (0)ALL")
  3615. (let ((n 0) s)
  3616. (mapc (lambda (x)
  3617. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3618. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3619. (insert "\n "))
  3620. (insert " " s))
  3621. kwds))
  3622. (insert "\n"))
  3623. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3624. (org-agenda-mark-header-line (point-min))
  3625. (when rtnall
  3626. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3627. (goto-char (point-min))
  3628. (or org-agenda-multi (org-fit-agenda-window))
  3629. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3630. (org-finalize-agenda)
  3631. (setq buffer-read-only t)))
  3632. ;;; Agenda tags match
  3633. ;;;###autoload
  3634. (defun org-tags-view (&optional todo-only match)
  3635. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3636. The prefix arg TODO-ONLY limits the search to TODO entries."
  3637. (interactive "P")
  3638. (org-compile-prefix-format 'tags)
  3639. (org-set-sorting-strategy 'tags)
  3640. (let* ((org-tags-match-list-sublevels
  3641. org-tags-match-list-sublevels)
  3642. (completion-ignore-case t)
  3643. rtn rtnall files file pos matcher
  3644. buffer)
  3645. (when (and (stringp match) (not (string-match "\\S-" match)))
  3646. (setq match nil))
  3647. (setq matcher (org-make-tags-matcher match)
  3648. match (car matcher) matcher (cdr matcher))
  3649. (org-prepare-agenda (concat "TAGS " match))
  3650. (setq org-agenda-query-string match)
  3651. (setq org-agenda-redo-command
  3652. (list 'org-tags-view (list 'quote todo-only)
  3653. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3654. (setq files (org-agenda-files nil 'ifmode)
  3655. rtnall nil)
  3656. (while (setq file (pop files))
  3657. (catch 'nextfile
  3658. (org-check-agenda-file file)
  3659. (setq buffer (if (file-exists-p file)
  3660. (org-get-agenda-file-buffer file)
  3661. (error "No such file %s" file)))
  3662. (if (not buffer)
  3663. ;; If file does not exist, error message to agenda
  3664. (setq rtn (list
  3665. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3666. rtnall (append rtnall rtn))
  3667. (with-current-buffer buffer
  3668. (unless (org-mode-p)
  3669. (error "Agenda file %s is not in `org-mode'" file))
  3670. (save-excursion
  3671. (save-restriction
  3672. (if org-agenda-restrict
  3673. (narrow-to-region org-agenda-restrict-begin
  3674. org-agenda-restrict-end)
  3675. (widen))
  3676. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3677. (setq rtnall (append rtnall rtn))))))))
  3678. (if org-agenda-overriding-header
  3679. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3680. nil 'face 'org-agenda-structure) "\n")
  3681. (insert "Headlines with TAGS match: ")
  3682. (add-text-properties (point-min) (1- (point))
  3683. (list 'face 'org-agenda-structure
  3684. 'short-heading
  3685. (concat "Match: " match)))
  3686. (setq pos (point))
  3687. (insert match "\n")
  3688. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3689. (setq pos (point))
  3690. (unless org-agenda-multi
  3691. (insert "Press `C-u r' to search again with new search string\n"))
  3692. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3693. (org-agenda-mark-header-line (point-min))
  3694. (when rtnall
  3695. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3696. (goto-char (point-min))
  3697. (or org-agenda-multi (org-fit-agenda-window))
  3698. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3699. (org-finalize-agenda)
  3700. (setq buffer-read-only t)))
  3701. ;;; Agenda Finding stuck projects
  3702. (defvar org-agenda-skip-regexp nil
  3703. "Regular expression used in skipping subtrees for the agenda.
  3704. This is basically a temporary global variable that can be set and then
  3705. used by user-defined selections using `org-agenda-skip-function'.")
  3706. (defvar org-agenda-overriding-header nil
  3707. "When this is set during todo and tags searches, will replace header.
  3708. This variable should not be set directly, but custom commands can bind it
  3709. in the options section.")
  3710. (defun org-agenda-skip-entry-when-regexp-matches ()
  3711. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3712. If yes, it returns the end position of this entry, causing agenda commands
  3713. to skip the entry but continuing the search in the subtree. This is a
  3714. function that can be put into `org-agenda-skip-function' for the duration
  3715. of a command."
  3716. (let ((end (save-excursion (org-end-of-subtree t)))
  3717. skip)
  3718. (save-excursion
  3719. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3720. (and skip end)))
  3721. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3722. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3723. If yes, it returns the end position of this tree, causing agenda commands
  3724. to skip this subtree. This is a function that can be put into
  3725. `org-agenda-skip-function' for the duration of a command."
  3726. (let ((end (save-excursion (org-end-of-subtree t)))
  3727. skip)
  3728. (save-excursion
  3729. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3730. (and skip end)))
  3731. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3732. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3733. If yes, it returns the end position of the current entry (NOT the tree),
  3734. causing agenda commands to skip the entry but continuing the search in
  3735. the subtree. This is a function that can be put into
  3736. `org-agenda-skip-function' for the duration of a command. An important
  3737. use of this function is for the stuck project list."
  3738. (let ((end (save-excursion (org-end-of-subtree t)))
  3739. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3740. skip)
  3741. (save-excursion
  3742. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3743. (and skip entry-end)))
  3744. (defun org-agenda-skip-entry-if (&rest conditions)
  3745. "Skip entry if any of CONDITIONS is true.
  3746. See `org-agenda-skip-if' for details."
  3747. (org-agenda-skip-if nil conditions))
  3748. (defun org-agenda-skip-subtree-if (&rest conditions)
  3749. "Skip entry if any of CONDITIONS is true.
  3750. See `org-agenda-skip-if' for details."
  3751. (org-agenda-skip-if t conditions))
  3752. (defun org-agenda-skip-if (subtree conditions)
  3753. "Checks current entity for CONDITIONS.
  3754. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3755. the entry, i.e. the text before the next heading is checked.
  3756. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3757. from different tests. Valid conditions are:
  3758. scheduled Check if there is a scheduled cookie
  3759. notscheduled Check if there is no scheduled cookie
  3760. deadline Check if there is a deadline
  3761. notdeadline Check if there is no deadline
  3762. timestamp Check if there is a timestamp (also deadline or scheduled)
  3763. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3764. regexp Check if regexp matches
  3765. notregexp Check if regexp does not match.
  3766. todo Check if TODO keyword matches
  3767. nottodo Check if TODO keyword does not match
  3768. The regexp is taken from the conditions list, it must come right after
  3769. the `regexp' or `notregexp' element.
  3770. `todo' and `nottodo' accept as an argument a list of todo
  3771. keywords, which may include \"*\" to match any todo keyword.
  3772. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3773. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3774. Instead of a list a keyword class may be given
  3775. (org-agenda-skip-entry-if 'nottodo 'done)
  3776. would skip entries that haven't been marked with any of \"DONE\"
  3777. keywords. Possible classes are: `todo', `done', `any'.
  3778. If any of these conditions is met, this function returns the end point of
  3779. the entity, causing the search to continue from there. This is a function
  3780. that can be put into `org-agenda-skip-function' for the duration of a command."
  3781. (let (beg end m)
  3782. (org-back-to-heading t)
  3783. (setq beg (point)
  3784. end (if subtree
  3785. (progn (org-end-of-subtree t) (point))
  3786. (progn (outline-next-heading) (1- (point)))))
  3787. (goto-char beg)
  3788. (and
  3789. (or
  3790. (and (memq 'scheduled conditions)
  3791. (re-search-forward org-scheduled-time-regexp end t))
  3792. (and (memq 'notscheduled conditions)
  3793. (not (re-search-forward org-scheduled-time-regexp end t)))
  3794. (and (memq 'deadline conditions)
  3795. (re-search-forward org-deadline-time-regexp end t))
  3796. (and (memq 'notdeadline conditions)
  3797. (not (re-search-forward org-deadline-time-regexp end t)))
  3798. (and (memq 'timestamp conditions)
  3799. (re-search-forward org-ts-regexp end t))
  3800. (and (memq 'nottimestamp conditions)
  3801. (not (re-search-forward org-ts-regexp end t)))
  3802. (and (setq m (memq 'regexp conditions))
  3803. (stringp (nth 1 m))
  3804. (re-search-forward (nth 1 m) end t))
  3805. (and (setq m (memq 'notregexp conditions))
  3806. (stringp (nth 1 m))
  3807. (not (re-search-forward (nth 1 m) end t)))
  3808. (and (or
  3809. (setq m (memq 'todo conditions))
  3810. (setq m (memq 'nottodo conditions)))
  3811. (org-agenda-skip-if-todo m end)))
  3812. end)))
  3813. (defun org-agenda-skip-if-todo (args end)
  3814. "Helper function for `org-agenda-skip-if', do not use it directly.
  3815. ARGS is a list with first element either `todo' or `nottodo'.
  3816. The remainder is either a list of TODO keywords, or a state symbol
  3817. `todo' or `done' or `any'."
  3818. (let ((kw (car args))
  3819. (arg (cadr args))
  3820. todo-wds todo-re)
  3821. (setq todo-wds
  3822. (org-uniquify
  3823. (cond
  3824. ((listp arg) ;; list of keywords
  3825. (if (member "*" arg)
  3826. (mapcar 'substring-no-properties org-todo-keywords-1)
  3827. arg))
  3828. ((symbolp arg) ;; keyword class name
  3829. (cond
  3830. ((eq arg 'todo)
  3831. (org-delete-all org-done-keywords
  3832. (mapcar 'substring-no-properties
  3833. org-todo-keywords-1)))
  3834. ((eq arg 'done) org-done-keywords)
  3835. ((eq arg 'any)
  3836. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3837. (setq todo-re
  3838. (concat "^\\*+[ \t]+\\<\\("
  3839. (mapconcat 'identity todo-wds "\\|")
  3840. "\\)\\>"))
  3841. (if (eq kw 'todo)
  3842. (re-search-forward todo-re end t)
  3843. (not (re-search-forward todo-re end t)))))
  3844. ;;;###autoload
  3845. (defun org-agenda-list-stuck-projects (&rest ignore)
  3846. "Create agenda view for projects that are stuck.
  3847. Stuck projects are project that have no next actions. For the definitions
  3848. of what a project is and how to check if it stuck, customize the variable
  3849. `org-stuck-projects'."
  3850. (interactive)
  3851. (let* ((org-agenda-skip-function
  3852. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3853. ;; We could have used org-agenda-skip-if here.
  3854. (org-agenda-overriding-header
  3855. (or org-agenda-overriding-header "List of stuck projects: "))
  3856. (matcher (nth 0 org-stuck-projects))
  3857. (todo (nth 1 org-stuck-projects))
  3858. (todo-wds (if (member "*" todo)
  3859. (progn
  3860. (org-prepare-agenda-buffers (org-agenda-files
  3861. nil 'ifmode))
  3862. (org-delete-all
  3863. org-done-keywords-for-agenda
  3864. (copy-sequence org-todo-keywords-for-agenda)))
  3865. todo))
  3866. (todo-re (concat "^\\*+[ \t]+\\("
  3867. (mapconcat 'identity todo-wds "\\|")
  3868. "\\)\\>"))
  3869. (tags (nth 2 org-stuck-projects))
  3870. (tags-re (if (member "*" tags)
  3871. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3872. (if tags
  3873. (concat "^\\*+ .*:\\("
  3874. (mapconcat 'identity tags "\\|")
  3875. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3876. (gen-re (nth 3 org-stuck-projects))
  3877. (re-list
  3878. (delq nil
  3879. (list
  3880. (if todo todo-re)
  3881. (if tags tags-re)
  3882. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3883. gen-re)))))
  3884. (setq org-agenda-skip-regexp
  3885. (if re-list
  3886. (mapconcat 'identity re-list "\\|")
  3887. (error "No information how to identify unstuck projects")))
  3888. (org-tags-view nil matcher)
  3889. (with-current-buffer org-agenda-buffer-name
  3890. (setq org-agenda-redo-command
  3891. '(org-agenda-list-stuck-projects
  3892. (or current-prefix-arg org-last-arg))))))
  3893. ;;; Diary integration
  3894. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3895. (defvar list-diary-entries-hook)
  3896. (defun org-get-entries-from-diary (date)
  3897. "Get the (Emacs Calendar) diary entries for DATE."
  3898. (require 'diary-lib)
  3899. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3900. (diary-display-hook '(fancy-diary-display))
  3901. (diary-display-function 'fancy-diary-display)
  3902. (pop-up-frames nil)
  3903. (list-diary-entries-hook
  3904. (cons 'org-diary-default-entry list-diary-entries-hook))
  3905. (diary-file-name-prefix-function nil) ; turn this feature off
  3906. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3907. entries
  3908. (org-disable-agenda-to-diary t))
  3909. (save-excursion
  3910. (save-window-excursion
  3911. (funcall (if (fboundp 'diary-list-entries)
  3912. 'diary-list-entries 'list-diary-entries)
  3913. date 1)))
  3914. (if (not (get-buffer diary-fancy-buffer))
  3915. (setq entries nil)
  3916. (with-current-buffer diary-fancy-buffer
  3917. (setq buffer-read-only nil)
  3918. (if (zerop (buffer-size))
  3919. ;; No entries
  3920. (setq entries nil)
  3921. ;; Omit the date and other unnecessary stuff
  3922. (org-agenda-cleanup-fancy-diary)
  3923. ;; Add prefix to each line and extend the text properties
  3924. (if (zerop (buffer-size))
  3925. (setq entries nil)
  3926. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3927. (set-buffer-modified-p nil)
  3928. (kill-buffer diary-fancy-buffer)))
  3929. (when entries
  3930. (setq entries (org-split-string entries "\n"))
  3931. (setq entries
  3932. (mapcar
  3933. (lambda (x)
  3934. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3935. ;; Extend the text properties to the beginning of the line
  3936. (org-add-props x (text-properties-at (1- (length x)) x)
  3937. 'type "diary" 'date date 'face 'org-agenda-diary))
  3938. entries)))))
  3939. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3940. "Hook run when the fancy diary buffer is cleaned up.")
  3941. (defun org-agenda-cleanup-fancy-diary ()
  3942. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3943. This gets rid of the date, the underline under the date, and
  3944. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3945. date. It also removes lines that contain only whitespace."
  3946. (goto-char (point-min))
  3947. (if (looking-at ".*?:[ \t]*")
  3948. (progn
  3949. (replace-match "")
  3950. (re-search-forward "\n=+$" nil t)
  3951. (replace-match "")
  3952. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3953. (re-search-forward "\n=+$" nil t)
  3954. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3955. (goto-char (point-min))
  3956. (while (re-search-forward "^ +\n" nil t)
  3957. (replace-match ""))
  3958. (goto-char (point-min))
  3959. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3960. (replace-match ""))
  3961. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3962. ;; Make sure entries from the diary have the right text properties.
  3963. (eval-after-load "diary-lib"
  3964. '(if (boundp 'diary-modify-entry-list-string-function)
  3965. ;; We can rely on the hook, nothing to do
  3966. nil
  3967. ;; Hook not available, must use advice to make this work
  3968. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3969. "Make the position visible."
  3970. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3971. (stringp string)
  3972. buffer-file-name)
  3973. (setq string (org-modify-diary-entry-string string))))))
  3974. (defun org-modify-diary-entry-string (string)
  3975. "Add text properties to string, allowing org-mode to act on it."
  3976. (org-add-props string nil
  3977. 'mouse-face 'highlight
  3978. 'help-echo (if buffer-file-name
  3979. (format "mouse-2 or RET jump to diary file %s"
  3980. (abbreviate-file-name buffer-file-name))
  3981. "")
  3982. 'org-agenda-diary-link t
  3983. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3984. (defun org-diary-default-entry ()
  3985. "Add a dummy entry to the diary.
  3986. Needed to avoid empty dates which mess up holiday display."
  3987. ;; Catch the error if dealing with the new add-to-diary-alist
  3988. (when org-disable-agenda-to-diary
  3989. (condition-case nil
  3990. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3991. (error
  3992. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3993. (defun org-add-to-diary-list (&rest args)
  3994. (if (fboundp 'diary-add-to-list)
  3995. (apply 'diary-add-to-list args)
  3996. (apply 'add-to-diary-list args)))
  3997. (defvar org-diary-last-run-time nil)
  3998. ;;;###autoload
  3999. (defun org-diary (&rest args)
  4000. "Return diary information from org-files.
  4001. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4002. It accesses org files and extracts information from those files to be
  4003. listed in the diary. The function accepts arguments specifying what
  4004. items should be listed. For a list of arguments allowed here, see the
  4005. variable `org-agenda-entry-types'.
  4006. The call in the diary file should look like this:
  4007. &%%(org-diary) ~/path/to/some/orgfile.org
  4008. Use a separate line for each org file to check. Or, if you omit the file name,
  4009. all files listed in `org-agenda-files' will be checked automatically:
  4010. &%%(org-diary)
  4011. If you don't give any arguments (as in the example above), the default
  4012. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4013. So the example above may also be written as
  4014. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4015. The function expects the lisp variables `entry' and `date' to be provided
  4016. by the caller, because this is how the calendar works. Don't use this
  4017. function from a program - use `org-agenda-get-day-entries' instead."
  4018. (when (> (- (org-float-time)
  4019. org-agenda-last-marker-time)
  4020. 5)
  4021. (org-agenda-reset-markers))
  4022. (org-compile-prefix-format 'agenda)
  4023. (org-set-sorting-strategy 'agenda)
  4024. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4025. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4026. (list entry)
  4027. (org-agenda-files t)))
  4028. (time (org-float-time))
  4029. file rtn results)
  4030. (when (or (not org-diary-last-run-time)
  4031. (> (- time
  4032. org-diary-last-run-time)
  4033. 3))
  4034. (org-prepare-agenda-buffers files))
  4035. (setq org-diary-last-run-time time)
  4036. ;; If this is called during org-agenda, don't return any entries to
  4037. ;; the calendar. Org Agenda will list these entries itself.
  4038. (if org-disable-agenda-to-diary (setq files nil))
  4039. (while (setq file (pop files))
  4040. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4041. (setq results (append results rtn)))
  4042. (if results
  4043. (concat (org-finalize-agenda-entries results) "\n"))))
  4044. ;;; Agenda entry finders
  4045. (defun org-agenda-get-day-entries (file date &rest args)
  4046. "Does the work for `org-diary' and `org-agenda'.
  4047. FILE is the path to a file to be checked for entries. DATE is date like
  4048. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4049. which kind of entries should be extracted. For details about these, see
  4050. the documentation of `org-diary'."
  4051. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4052. (let* ((org-startup-folded nil)
  4053. (org-startup-align-all-tables nil)
  4054. (buffer (if (file-exists-p file)
  4055. (org-get-agenda-file-buffer file)
  4056. (error "No such file %s" file)))
  4057. arg results rtn deadline-results)
  4058. (if (not buffer)
  4059. ;; If file does not exist, make sure an error message ends up in diary
  4060. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4061. (with-current-buffer buffer
  4062. (unless (org-mode-p)
  4063. (error "Agenda file %s is not in `org-mode'" file))
  4064. (let ((case-fold-search nil))
  4065. (save-excursion
  4066. (save-restriction
  4067. (if org-agenda-restrict
  4068. (narrow-to-region org-agenda-restrict-begin
  4069. org-agenda-restrict-end)
  4070. (widen))
  4071. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4072. (while (setq arg (pop args))
  4073. (cond
  4074. ((and (eq arg :todo)
  4075. (equal date (calendar-current-date)))
  4076. (setq rtn (org-agenda-get-todos))
  4077. (setq results (append results rtn)))
  4078. ((eq arg :timestamp)
  4079. (setq rtn (org-agenda-get-blocks))
  4080. (setq results (append results rtn))
  4081. (setq rtn (org-agenda-get-timestamps))
  4082. (setq results (append results rtn)))
  4083. ((eq arg :sexp)
  4084. (setq rtn (org-agenda-get-sexps))
  4085. (setq results (append results rtn)))
  4086. ((eq arg :scheduled)
  4087. (setq rtn (org-agenda-get-scheduled deadline-results))
  4088. (setq results (append results rtn)))
  4089. ((eq arg :closed)
  4090. (setq rtn (org-agenda-get-progress))
  4091. (setq results (append results rtn)))
  4092. ((eq arg :deadline)
  4093. (setq rtn (org-agenda-get-deadlines))
  4094. (setq deadline-results (copy-sequence rtn))
  4095. (setq results (append results rtn))))))))
  4096. results))))
  4097. (defun org-agenda-get-todos ()
  4098. "Return the TODO information for agenda display."
  4099. (let* ((props (list 'face nil
  4100. 'done-face 'org-agenda-done
  4101. 'org-not-done-regexp org-not-done-regexp
  4102. 'org-todo-regexp org-todo-regexp
  4103. 'org-complex-heading-regexp org-complex-heading-regexp
  4104. 'mouse-face 'highlight
  4105. 'help-echo
  4106. (format "mouse-2 or RET jump to org file %s"
  4107. (abbreviate-file-name buffer-file-name))))
  4108. (regexp (concat "^\\*+[ \t]+\\("
  4109. (if org-select-this-todo-keyword
  4110. (if (equal org-select-this-todo-keyword "*")
  4111. org-todo-regexp
  4112. (concat "\\<\\("
  4113. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4114. "\\)\\>"))
  4115. org-not-done-regexp)
  4116. "[^\n\r]*\\)"))
  4117. marker priority category tags todo-state
  4118. ee txt beg end)
  4119. (goto-char (point-min))
  4120. (while (re-search-forward regexp nil t)
  4121. (catch :skip
  4122. (save-match-data
  4123. (beginning-of-line)
  4124. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4125. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4126. (goto-char (1+ beg))
  4127. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4128. (throw :skip nil)))
  4129. (goto-char beg)
  4130. (org-agenda-skip)
  4131. (goto-char (match-beginning 1))
  4132. (setq marker (org-agenda-new-marker (match-beginning 0))
  4133. category (org-get-category)
  4134. txt (match-string 1)
  4135. tags (org-get-tags-at (point))
  4136. txt (org-format-agenda-item "" txt category tags)
  4137. priority (1+ (org-get-priority txt))
  4138. todo-state (org-get-todo-state))
  4139. (org-add-props txt props
  4140. 'org-marker marker 'org-hd-marker marker
  4141. 'priority priority 'org-category category
  4142. 'type "todo" 'todo-state todo-state)
  4143. (push txt ee)
  4144. (if org-agenda-todo-list-sublevels
  4145. (goto-char (match-end 1))
  4146. (org-end-of-subtree 'invisible))))
  4147. (nreverse ee)))
  4148. ;;;###autoload
  4149. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4150. (&optional end)
  4151. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4152. (when (or org-agenda-todo-ignore-with-date
  4153. org-agenda-todo-ignore-scheduled
  4154. org-agenda-todo-ignore-deadlines
  4155. org-agenda-todo-ignore-timestamp)
  4156. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4157. (save-excursion
  4158. (or (and org-agenda-todo-ignore-with-date
  4159. (re-search-forward org-ts-regexp end t))
  4160. (and org-agenda-todo-ignore-scheduled
  4161. (re-search-forward org-scheduled-time-regexp end t)
  4162. (cond
  4163. ((eq org-agenda-todo-ignore-scheduled 'future)
  4164. (> (org-days-to-time (match-string 1)) 0))
  4165. ((eq org-agenda-todo-ignore-scheduled 'past)
  4166. (<= (org-days-to-time (match-string 1)) 0))
  4167. (t)))
  4168. (and org-agenda-todo-ignore-deadlines
  4169. (re-search-forward org-deadline-time-regexp end t)
  4170. (cond
  4171. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4172. ((eq org-agenda-todo-ignore-deadlines 'far)
  4173. (not (org-deadline-close (match-string 1))))
  4174. ((eq org-agenda-todo-ignore-deadlines 'future)
  4175. (> (org-days-to-time (match-string 1)) 0))
  4176. ((eq org-agenda-todo-ignore-deadlines 'past)
  4177. (<= (org-days-to-time (match-string 1)) 0))
  4178. (t (org-deadline-close (match-string 1)))))
  4179. (and org-agenda-todo-ignore-timestamp
  4180. (let ((buffer (current-buffer))
  4181. (regexp
  4182. (concat
  4183. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4184. (start (point)))
  4185. ;; Copy current buffer into a temporary one
  4186. (with-temp-buffer
  4187. (insert-buffer-substring buffer start end)
  4188. (goto-char (point-min))
  4189. ;; Delete SCHEDULED and DEADLINE items
  4190. (while (re-search-forward regexp end t)
  4191. (delete-region (match-beginning 0) (match-end 0)))
  4192. (goto-char (point-min))
  4193. ;; No search for timestamp left
  4194. (when (re-search-forward org-ts-regexp nil t)
  4195. (cond
  4196. ((eq org-agenda-todo-ignore-timestamp 'future)
  4197. (> (org-days-to-time (match-string 1)) 0))
  4198. ((eq org-agenda-todo-ignore-timestamp 'past)
  4199. (<= (org-days-to-time (match-string 1)) 0))
  4200. (t))))))))))
  4201. (defconst org-agenda-no-heading-message
  4202. "No heading for this item in buffer or region.")
  4203. (defun org-agenda-get-timestamps ()
  4204. "Return the date stamp information for agenda display."
  4205. (let* ((props (list 'face nil
  4206. 'org-not-done-regexp org-not-done-regexp
  4207. 'org-todo-regexp org-todo-regexp
  4208. 'org-complex-heading-regexp org-complex-heading-regexp
  4209. 'mouse-face 'highlight
  4210. 'help-echo
  4211. (format "mouse-2 or RET jump to org file %s"
  4212. (abbreviate-file-name buffer-file-name))))
  4213. (d1 (calendar-absolute-from-gregorian date))
  4214. (remove-re
  4215. (concat
  4216. (regexp-quote
  4217. (format-time-string
  4218. "<%Y-%m-%d"
  4219. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4220. ".*?>"))
  4221. (regexp
  4222. (concat
  4223. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4224. (regexp-quote
  4225. (substring
  4226. (format-time-string
  4227. (car org-time-stamp-formats)
  4228. (apply 'encode-time ; DATE bound by calendar
  4229. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4230. 1 11))
  4231. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4232. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4233. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4234. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4235. todo-state end-of-match)
  4236. (goto-char (point-min))
  4237. (while (setq end-of-match (re-search-forward regexp nil t))
  4238. (setq b0 (match-beginning 0)
  4239. b3 (match-beginning 3) e3 (match-end 3))
  4240. (catch :skip
  4241. (and (org-at-date-range-p) (throw :skip nil))
  4242. (org-agenda-skip)
  4243. (if (and (match-end 1)
  4244. (not (= d1 (org-time-string-to-absolute
  4245. (match-string 1) d1 nil
  4246. org-agenda-repeating-timestamp-show-all))))
  4247. (throw :skip nil))
  4248. (if (and e3
  4249. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4250. (throw :skip nil))
  4251. (setq tmp (buffer-substring (max (point-min)
  4252. (- b0 org-ds-keyword-length))
  4253. b0)
  4254. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4255. inactivep (= (char-after b0) ?\[)
  4256. deadlinep (string-match org-deadline-regexp tmp)
  4257. scheduledp (string-match org-scheduled-regexp tmp)
  4258. closedp (and org-agenda-include-inactive-timestamps
  4259. (string-match org-closed-string tmp))
  4260. clockp (and org-agenda-include-inactive-timestamps
  4261. (or (string-match org-clock-string tmp)
  4262. (string-match "]-+\\'" tmp)))
  4263. todo-state (ignore-errors (org-get-todo-state))
  4264. donep (member todo-state org-done-keywords))
  4265. (if (or scheduledp deadlinep closedp clockp
  4266. (and donep org-agenda-skip-timestamp-if-done))
  4267. (throw :skip t))
  4268. (if (string-match ">" timestr)
  4269. ;; substring should only run to end of time stamp
  4270. (setq timestr (substring timestr 0 (match-end 0))))
  4271. (setq marker (org-agenda-new-marker b0)
  4272. category (org-get-category b0))
  4273. (save-excursion
  4274. (if (not (re-search-backward "^\\*+ " nil t))
  4275. (setq txt org-agenda-no-heading-message)
  4276. (goto-char (match-beginning 0))
  4277. (setq hdmarker (org-agenda-new-marker)
  4278. tags (org-get-tags-at))
  4279. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4280. (setq head (match-string 1))
  4281. (setq txt (org-format-agenda-item
  4282. (if inactivep org-agenda-inactive-leader nil)
  4283. head category tags timestr nil
  4284. remove-re)))
  4285. (setq priority (org-get-priority txt))
  4286. (org-add-props txt props
  4287. 'org-marker marker 'org-hd-marker hdmarker)
  4288. (org-add-props txt nil 'priority priority
  4289. 'org-category category 'date date
  4290. 'todo-state todo-state
  4291. 'type "timestamp")
  4292. (push txt ee))
  4293. (if org-agenda-skip-additional-timestamps-same-entry
  4294. (outline-next-heading)
  4295. (goto-char end-of-match))))
  4296. (nreverse ee)))
  4297. (defun org-agenda-get-sexps ()
  4298. "Return the sexp information for agenda display."
  4299. (require 'diary-lib)
  4300. (let* ((props (list 'mouse-face 'highlight
  4301. 'help-echo
  4302. (format "mouse-2 or RET jump to org file %s"
  4303. (abbreviate-file-name buffer-file-name))))
  4304. (regexp "^&?%%(")
  4305. marker category ee txt tags entry result beg b sexp sexp-entry
  4306. todo-state)
  4307. (goto-char (point-min))
  4308. (while (re-search-forward regexp nil t)
  4309. (catch :skip
  4310. (org-agenda-skip)
  4311. (setq beg (match-beginning 0))
  4312. (goto-char (1- (match-end 0)))
  4313. (setq b (point))
  4314. (forward-sexp 1)
  4315. (setq sexp (buffer-substring b (point)))
  4316. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4317. (org-trim (match-string 1))
  4318. ""))
  4319. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4320. (when result
  4321. (setq marker (org-agenda-new-marker beg)
  4322. category (org-get-category beg)
  4323. todo-state (org-get-todo-state))
  4324. (dolist (r (if (stringp result)
  4325. (list result)
  4326. result)) ;; we expect a list here
  4327. (if (string-match "\\S-" r)
  4328. (setq txt r)
  4329. (setq txt "SEXP entry returned empty string"))
  4330. (setq txt (org-format-agenda-item
  4331. "" txt category tags 'time))
  4332. (org-add-props txt props 'org-marker marker)
  4333. (org-add-props txt nil
  4334. 'org-category category 'date date 'todo-state todo-state
  4335. 'type "sexp")
  4336. (push txt ee)))))
  4337. (nreverse ee)))
  4338. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4339. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4340. The order of the first 2 times 3 arguments depends on the variable
  4341. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4342. So for American calendars, give this as MONTH DAY YEAR, for European as
  4343. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4344. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4345. is any number of ISO weeks in the block period for which the item should
  4346. be skipped."
  4347. (let* ((date1 (calendar-absolute-from-gregorian
  4348. (org-order-calendar-date-args m1 d1 y1)))
  4349. (date2 (calendar-absolute-from-gregorian
  4350. (org-order-calendar-date-args m2 d2 y2)))
  4351. (d (calendar-absolute-from-gregorian date)))
  4352. (and
  4353. (<= date1 d)
  4354. (<= d date2)
  4355. (= (calendar-day-of-week date) dayname)
  4356. (or (not skip-weeks)
  4357. (progn
  4358. (require 'cal-iso)
  4359. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4360. entry)))
  4361. (defalias 'org-get-closed 'org-agenda-get-progress)
  4362. (defun org-agenda-get-progress ()
  4363. "Return the logged TODO entries for agenda display."
  4364. (let* ((props (list 'mouse-face 'highlight
  4365. 'org-not-done-regexp org-not-done-regexp
  4366. 'org-todo-regexp org-todo-regexp
  4367. 'org-complex-heading-regexp org-complex-heading-regexp
  4368. 'help-echo
  4369. (format "mouse-2 or RET jump to org file %s"
  4370. (abbreviate-file-name buffer-file-name))))
  4371. (items (if (consp org-agenda-show-log)
  4372. org-agenda-show-log
  4373. org-agenda-log-mode-items))
  4374. (parts
  4375. (delq nil
  4376. (list
  4377. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4378. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4379. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4380. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4381. (error "`org-agenda-log-mode-items' is empty")))
  4382. (regexp (concat
  4383. "\\(" parts-re "\\)"
  4384. " *\\["
  4385. (regexp-quote
  4386. (substring
  4387. (format-time-string
  4388. (car org-time-stamp-formats)
  4389. (apply 'encode-time ; DATE bound by calendar
  4390. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4391. 1 11))))
  4392. (org-agenda-search-headline-for-time nil)
  4393. marker hdmarker priority category tags closedp statep clockp state
  4394. ee txt extra timestr rest clocked)
  4395. (goto-char (point-min))
  4396. (while (re-search-forward regexp nil t)
  4397. (catch :skip
  4398. (org-agenda-skip)
  4399. (setq marker (org-agenda-new-marker (match-beginning 0))
  4400. closedp (equal (match-string 1) org-closed-string)
  4401. statep (equal (string-to-char (match-string 1)) ?-)
  4402. clockp (not (or closedp statep))
  4403. state (and statep (match-string 2))
  4404. category (org-get-category (match-beginning 0))
  4405. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4406. )
  4407. (when (string-match "\\]" timestr)
  4408. ;; substring should only run to end of time stamp
  4409. (setq rest (substring timestr (match-end 0))
  4410. timestr (substring timestr 0 (match-end 0)))
  4411. (if (and (not closedp) (not statep)
  4412. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4413. (progn (setq timestr (concat (substring timestr 0 -1)
  4414. "-" (match-string 1 rest) "]"))
  4415. (setq clocked (match-string 2 rest)))
  4416. (setq clocked "-")))
  4417. (save-excursion
  4418. (setq extra nil)
  4419. (cond
  4420. ((not org-agenda-log-mode-add-notes))
  4421. (statep
  4422. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4423. (setq extra (match-string 1))))
  4424. (clockp
  4425. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4426. (setq extra (match-string 1)))))
  4427. (if (not (re-search-backward "^\\*+ " nil t))
  4428. (setq txt org-agenda-no-heading-message)
  4429. (goto-char (match-beginning 0))
  4430. (setq hdmarker (org-agenda-new-marker)
  4431. tags (org-get-tags-at))
  4432. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4433. (setq txt (match-string 1))
  4434. (when extra
  4435. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4436. (setq txt (concat (substring txt 0 (match-beginning 1))
  4437. " - " extra " " (match-string 2 txt)))
  4438. (setq txt (concat txt " - " extra))))
  4439. (setq txt (org-format-agenda-item
  4440. (cond
  4441. (closedp "Closed: ")
  4442. (statep (concat "State: (" state ")"))
  4443. (t (concat "Clocked: (" clocked ")")))
  4444. txt category tags timestr)))
  4445. (setq priority 100000)
  4446. (org-add-props txt props
  4447. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4448. 'priority priority 'org-category category
  4449. 'type "closed" 'date date
  4450. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4451. (push txt ee))
  4452. (goto-char (point-at-eol))))
  4453. (nreverse ee)))
  4454. (defun org-agenda-get-deadlines ()
  4455. "Return the deadline information for agenda display."
  4456. (let* ((props (list 'mouse-face 'highlight
  4457. 'org-not-done-regexp org-not-done-regexp
  4458. 'org-todo-regexp org-todo-regexp
  4459. 'org-complex-heading-regexp org-complex-heading-regexp
  4460. 'help-echo
  4461. (format "mouse-2 or RET jump to org file %s"
  4462. (abbreviate-file-name buffer-file-name))))
  4463. (regexp org-deadline-time-regexp)
  4464. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4465. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4466. d2 diff dfrac wdays pos pos1 category tags
  4467. suppress-prewarning
  4468. ee txt head face s todo-state upcomingp donep timestr)
  4469. (goto-char (point-min))
  4470. (while (re-search-forward regexp nil t)
  4471. (setq suppress-prewarning nil)
  4472. (catch :skip
  4473. (org-agenda-skip)
  4474. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4475. (save-match-data
  4476. (string-match org-scheduled-time-regexp
  4477. (buffer-substring (point-at-bol)
  4478. (point-at-eol)))))
  4479. (setq suppress-prewarning
  4480. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4481. org-agenda-skip-deadline-prewarning-if-scheduled
  4482. 0)))
  4483. (setq s (match-string 1)
  4484. txt nil
  4485. pos (1- (match-beginning 1))
  4486. d2 (org-time-string-to-absolute
  4487. (match-string 1) d1 'past
  4488. org-agenda-repeating-timestamp-show-all)
  4489. diff (- d2 d1)
  4490. wdays (if suppress-prewarning
  4491. (let ((org-deadline-warning-days suppress-prewarning))
  4492. (org-get-wdays s))
  4493. (org-get-wdays s))
  4494. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4495. upcomingp (and todayp (> diff 0)))
  4496. ;; When to show a deadline in the calendar:
  4497. ;; If the expiration is within wdays warning time.
  4498. ;; Past-due deadlines are only shown on the current date
  4499. (if (and (or (and (<= diff wdays)
  4500. (and todayp (not org-agenda-only-exact-dates)))
  4501. (= diff 0)))
  4502. (save-excursion
  4503. (setq todo-state (org-get-todo-state))
  4504. (setq donep (member todo-state org-done-keywords))
  4505. (if (and donep
  4506. (or org-agenda-skip-deadline-if-done
  4507. (not (= diff 0))))
  4508. (setq txt nil)
  4509. (setq category (org-get-category))
  4510. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4511. (setq txt org-agenda-no-heading-message)
  4512. (goto-char (match-end 0))
  4513. (setq pos1 (match-beginning 0))
  4514. (setq tags (org-get-tags-at pos1))
  4515. (setq head (buffer-substring-no-properties
  4516. (point)
  4517. (progn (skip-chars-forward "^\r\n")
  4518. (point))))
  4519. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4520. (setq timestr
  4521. (concat (substring s (match-beginning 1)) " "))
  4522. (setq timestr 'time))
  4523. (setq txt (org-format-agenda-item
  4524. (if (= diff 0)
  4525. (car org-agenda-deadline-leaders)
  4526. (if (functionp
  4527. (nth 1 org-agenda-deadline-leaders))
  4528. (funcall
  4529. (nth 1 org-agenda-deadline-leaders)
  4530. diff date)
  4531. (format (nth 1 org-agenda-deadline-leaders)
  4532. diff)))
  4533. head category tags
  4534. (if (not (= diff 0)) nil timestr)))))
  4535. (when txt
  4536. (setq face (org-agenda-deadline-face dfrac wdays))
  4537. (org-add-props txt props
  4538. 'org-marker (org-agenda-new-marker pos)
  4539. 'org-hd-marker (org-agenda-new-marker pos1)
  4540. 'priority (+ (- diff)
  4541. (org-get-priority txt))
  4542. 'org-category category
  4543. 'todo-state todo-state
  4544. 'type (if upcomingp "upcoming-deadline" "deadline")
  4545. 'date (if upcomingp date d2)
  4546. 'face (if donep 'org-agenda-done face)
  4547. 'undone-face face 'done-face 'org-agenda-done)
  4548. (push txt ee))))))
  4549. (nreverse ee)))
  4550. (defun org-agenda-deadline-face (fraction &optional wdays)
  4551. "Return the face to displaying a deadline item.
  4552. FRACTION is what fraction of the head-warning time has passed."
  4553. (if (equal wdays 0) (setq fraction 1.))
  4554. (let ((faces org-agenda-deadline-faces) f)
  4555. (catch 'exit
  4556. (while (setq f (pop faces))
  4557. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4558. (defun org-agenda-get-scheduled (&optional deadline-results)
  4559. "Return the scheduled information for agenda display."
  4560. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4561. 'org-todo-regexp org-todo-regexp
  4562. 'org-complex-heading-regexp org-complex-heading-regexp
  4563. 'done-face 'org-agenda-done
  4564. 'mouse-face 'highlight
  4565. 'help-echo
  4566. (format "mouse-2 or RET jump to org file %s"
  4567. (abbreviate-file-name buffer-file-name))))
  4568. (regexp org-scheduled-time-regexp)
  4569. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4570. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4571. mm
  4572. (deadline-position-alist
  4573. (mapcar (lambda (a) (and (setq mm (get-text-property
  4574. 0 'org-hd-marker a))
  4575. (cons (marker-position mm) a)))
  4576. deadline-results))
  4577. d2 diff pos pos1 category tags donep
  4578. ee txt head pastschedp todo-state face timestr s habitp)
  4579. (goto-char (point-min))
  4580. (while (re-search-forward regexp nil t)
  4581. (catch :skip
  4582. (org-agenda-skip)
  4583. (setq s (match-string 1)
  4584. txt nil
  4585. pos (1- (match-beginning 1))
  4586. d2 (org-time-string-to-absolute
  4587. (match-string 1) d1 'past
  4588. org-agenda-repeating-timestamp-show-all)
  4589. diff (- d2 d1))
  4590. (setq pastschedp (and todayp (< diff 0)))
  4591. ;; When to show a scheduled item in the calendar:
  4592. ;; If it is on or past the date.
  4593. (when (or (and (< diff 0)
  4594. (< (abs diff) org-scheduled-past-days)
  4595. (and todayp (not org-agenda-only-exact-dates)))
  4596. (= diff 0))
  4597. (save-excursion
  4598. (setq todo-state (org-get-todo-state))
  4599. (setq donep (member todo-state org-done-keywords))
  4600. (if (and donep
  4601. (or org-agenda-skip-scheduled-if-done
  4602. (not (= diff 0))
  4603. (and (functionp 'org-is-habit-p)
  4604. (org-is-habit-p))))
  4605. (setq txt nil)
  4606. (setq habitp (and (functionp 'org-is-habit-p)
  4607. (org-is-habit-p)))
  4608. (setq category (org-get-category))
  4609. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4610. (setq txt org-agenda-no-heading-message)
  4611. (goto-char (match-end 0))
  4612. (setq pos1 (match-beginning 0))
  4613. (if habitp
  4614. (if (or (not org-habit-show-habits)
  4615. (and (not todayp)
  4616. org-habit-show-habits-only-for-today))
  4617. (throw :skip nil))
  4618. (if (and
  4619. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4620. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4621. pastschedp))
  4622. (setq mm (assoc pos1 deadline-position-alist)))
  4623. (throw :skip nil)))
  4624. (setq tags (org-get-tags-at))
  4625. (setq head (buffer-substring-no-properties
  4626. (point)
  4627. (progn (skip-chars-forward "^\r\n") (point))))
  4628. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4629. (setq timestr
  4630. (concat (substring s (match-beginning 1)) " "))
  4631. (setq timestr 'time))
  4632. (setq txt (org-format-agenda-item
  4633. (if (= diff 0)
  4634. (car org-agenda-scheduled-leaders)
  4635. (format (nth 1 org-agenda-scheduled-leaders)
  4636. (- 1 diff)))
  4637. head category tags
  4638. (if (not (= diff 0)) nil timestr)
  4639. nil nil habitp))))
  4640. (when txt
  4641. (setq face
  4642. (cond
  4643. ((and (not habitp) pastschedp)
  4644. 'org-scheduled-previously)
  4645. (todayp 'org-scheduled-today)
  4646. (t 'org-scheduled))
  4647. habitp (and habitp (org-habit-parse-todo)))
  4648. (org-add-props txt props
  4649. 'undone-face face
  4650. 'face (if donep 'org-agenda-done face)
  4651. 'org-marker (org-agenda-new-marker pos)
  4652. 'org-hd-marker (org-agenda-new-marker pos1)
  4653. 'type (if pastschedp "past-scheduled" "scheduled")
  4654. 'date (if pastschedp d2 date)
  4655. 'priority (if habitp
  4656. (org-habit-get-priority habitp)
  4657. (+ 94 (- 5 diff) (org-get-priority txt)))
  4658. 'org-category category
  4659. 'org-habit-p habitp
  4660. 'todo-state todo-state)
  4661. (push txt ee))))))
  4662. (nreverse ee)))
  4663. (defun org-agenda-get-blocks ()
  4664. "Return the date-range information for agenda display."
  4665. (let* ((props (list 'face nil
  4666. 'org-not-done-regexp org-not-done-regexp
  4667. 'org-todo-regexp org-todo-regexp
  4668. 'org-complex-heading-regexp org-complex-heading-regexp
  4669. 'mouse-face 'highlight
  4670. 'help-echo
  4671. (format "mouse-2 or RET jump to org file %s"
  4672. (abbreviate-file-name buffer-file-name))))
  4673. (regexp org-tr-regexp)
  4674. (d0 (calendar-absolute-from-gregorian date))
  4675. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4676. head donep)
  4677. (goto-char (point-min))
  4678. (while (re-search-forward regexp nil t)
  4679. (catch :skip
  4680. (org-agenda-skip)
  4681. (setq pos (point))
  4682. (setq timestr (match-string 0)
  4683. s1 (match-string 1)
  4684. s2 (match-string 2)
  4685. d1 (time-to-days (org-time-string-to-time s1))
  4686. d2 (time-to-days (org-time-string-to-time s2)))
  4687. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4688. ;; Only allow days between the limits, because the normal
  4689. ;; date stamps will catch the limits.
  4690. (save-excursion
  4691. (setq todo-state (org-get-todo-state))
  4692. (setq donep (member todo-state org-done-keywords))
  4693. (if (and donep org-agenda-skip-timestamp-if-done)
  4694. (throw :skip t))
  4695. (setq marker (org-agenda-new-marker (point)))
  4696. (setq category (org-get-category))
  4697. (if (not (re-search-backward "^\\*+ " nil t))
  4698. (setq txt org-agenda-no-heading-message)
  4699. (goto-char (match-beginning 0))
  4700. (setq hdmarker (org-agenda-new-marker (point)))
  4701. (setq tags (org-get-tags-at))
  4702. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4703. (setq head (match-string 1))
  4704. (let ((remove-re
  4705. (if org-agenda-remove-timeranges-from-blocks
  4706. (concat
  4707. "<" (regexp-quote s1) ".*?>"
  4708. "--"
  4709. "<" (regexp-quote s2) ".*?>")
  4710. nil)))
  4711. (setq txt (org-format-agenda-item
  4712. (format
  4713. (nth (if (= d1 d2) 0 1)
  4714. org-agenda-timerange-leaders)
  4715. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4716. head category tags
  4717. timestr nil remove-re))))
  4718. (org-add-props txt props
  4719. 'org-marker marker 'org-hd-marker hdmarker
  4720. 'type "block" 'date date
  4721. 'todo-state todo-state
  4722. 'priority (org-get-priority txt) 'org-category category)
  4723. (push txt ee)))
  4724. (goto-char pos)))
  4725. ;; Sort the entries by expiration date.
  4726. (nreverse ee)))
  4727. ;;; Agenda presentation and sorting
  4728. (defvar org-prefix-has-time nil
  4729. "A flag, set by `org-compile-prefix-format'.
  4730. The flag is set if the currently compiled format contains a `%t'.")
  4731. (defvar org-prefix-has-tag nil
  4732. "A flag, set by `org-compile-prefix-format'.
  4733. The flag is set if the currently compiled format contains a `%T'.")
  4734. (defvar org-prefix-has-effort nil
  4735. "A flag, set by `org-compile-prefix-format'.
  4736. The flag is set if the currently compiled format contains a `%e'.")
  4737. (defvar org-prefix-category-length nil
  4738. "Used by `org-compile-prefix-format' to remember the category field width.")
  4739. (defvar org-prefix-category-max-length nil
  4740. "Used by `org-compile-prefix-format' to remember the category field width.")
  4741. (defun org-agenda-get-category-icon (category)
  4742. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4743. (dolist (entry org-agenda-category-icon-alist)
  4744. (when (org-string-match-p (car entry) category)
  4745. (if (listp (cadr entry))
  4746. (return (cadr entry))
  4747. (return (apply 'create-image (cdr entry)))))))
  4748. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4749. noprefix remove-re habitp)
  4750. "Format TXT to be inserted into the agenda buffer.
  4751. In particular, it adds the prefix and corresponding text properties. EXTRA
  4752. must be a string and replaces the `%s' specifier in the prefix format.
  4753. CATEGORY (string, symbol or nil) may be used to overrule the default
  4754. category taken from local variable or file name. It will replace the `%c'
  4755. specifier in the format. DOTIME, when non-nil, indicates that a
  4756. time-of-day should be extracted from TXT for sorting of this entry, and for
  4757. the `%t' specifier in the format. When DOTIME is a string, this string is
  4758. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4759. only the correctly processes TXT should be returned - this is used by
  4760. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4761. Any match of REMOVE-RE will be removed from TXT."
  4762. (save-match-data
  4763. ;; Diary entries sometimes have extra whitespace at the beginning
  4764. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4765. ;; Fix the tags part in txt
  4766. (setq txt (org-agenda-fix-displayed-tags
  4767. txt tags
  4768. org-agenda-show-inherited-tags
  4769. org-agenda-hide-tags-regexp))
  4770. (let* ((category (or category
  4771. (if (stringp org-category)
  4772. org-category
  4773. (and org-category (symbol-name org-category)))
  4774. (if buffer-file-name
  4775. (file-name-sans-extension
  4776. (file-name-nondirectory buffer-file-name))
  4777. "")))
  4778. (category-icon (org-agenda-get-category-icon category))
  4779. (category-icon (if category-icon
  4780. (propertize " " 'display category-icon)
  4781. ""))
  4782. ;; time, tag, effort are needed for the eval of the prefix format
  4783. (tag (if tags (nth (1- (length tags)) tags) ""))
  4784. time effort neffort
  4785. (ts (if dotime (concat
  4786. (if (stringp dotime) dotime "")
  4787. (and org-agenda-search-headline-for-time txt))))
  4788. (time-of-day (and dotime (org-get-time-of-day ts)))
  4789. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4790. duration thecategory)
  4791. (and (org-mode-p) buffer-file-name
  4792. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4793. (when (and dotime time-of-day)
  4794. ;; Extract starting and ending time and move them to prefix
  4795. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4796. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4797. (setq s0 (match-string 0 ts)
  4798. srp (and stamp (match-end 3))
  4799. s1 (match-string (if plain 1 2) ts)
  4800. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4801. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4802. ;; them, we might want to remove them there to avoid duplication.
  4803. ;; The user can turn this off with a variable.
  4804. (if (and org-prefix-has-time
  4805. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4806. (string-match (concat (regexp-quote s0) " *") txt)
  4807. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4808. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4809. (= (match-beginning 0) 0)
  4810. t))
  4811. (setq txt (replace-match "" nil nil txt))))
  4812. ;; Normalize the time(s) to 24 hour
  4813. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4814. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4815. ;; Compute the duration
  4816. (when s1
  4817. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4818. (string-to-number (substring s1 3)))
  4819. t2 (cond
  4820. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4821. (string-to-number (substring s2 3))))
  4822. (org-agenda-default-appointment-duration
  4823. (+ t1 org-agenda-default-appointment-duration))
  4824. (t nil)))
  4825. (setq duration (if t2 (- t2 t1)))))
  4826. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4827. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4828. (let ((m (+ (string-to-number (match-string 2 s1))
  4829. (* 60 (string-to-number (match-string 1 s1)))
  4830. org-agenda-default-appointment-duration))
  4831. h)
  4832. (setq h (/ m 60) m (- m (* h 60)))
  4833. (setq s2 (format "%02d:%02d" h m))))
  4834. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4835. txt)
  4836. ;; Tags are in the string
  4837. (if (or (eq org-agenda-remove-tags t)
  4838. (and org-agenda-remove-tags
  4839. org-prefix-has-tag))
  4840. (setq txt (replace-match "" t t txt))
  4841. (setq txt (replace-match
  4842. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4843. (match-string 2 txt))
  4844. t t txt))))
  4845. (when (org-mode-p)
  4846. (setq effort
  4847. (condition-case nil
  4848. (org-get-effort
  4849. (or (get-text-property 0 'org-hd-marker txt)
  4850. (get-text-property 0 'org-marker txt)))
  4851. (error nil)))
  4852. (when effort
  4853. (setq neffort (org-hh:mm-string-to-minutes effort)
  4854. effort (setq effort (concat "[" effort "]" )))))
  4855. (when remove-re
  4856. (while (string-match remove-re txt)
  4857. (setq txt (replace-match "" t t txt))))
  4858. ;; Create the final string
  4859. (if noprefix
  4860. (setq rtn txt)
  4861. ;; Prepare the variables needed in the eval of the compiled format
  4862. (setq time (cond (s2 (concat
  4863. (org-agenda-time-of-day-to-ampm-maybe s1)
  4864. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  4865. (if org-agenda-timegrid-use-ampm " ")))
  4866. (s1 (concat
  4867. (org-agenda-time-of-day-to-ampm-maybe s1)
  4868. (if org-agenda-timegrid-use-ampm
  4869. "........ "
  4870. "......")))
  4871. (t ""))
  4872. extra (or (and (not habitp) extra) "")
  4873. category (if (symbolp category) (symbol-name category) category)
  4874. thecategory (copy-sequence category))
  4875. (if (string-match org-bracket-link-regexp category)
  4876. (progn
  4877. (setq l (if (match-end 3)
  4878. (- (match-end 3) (match-beginning 3))
  4879. (- (match-end 1) (match-beginning 1))))
  4880. (when (< l (or org-prefix-category-length 0))
  4881. (setq category (copy-sequence category))
  4882. (org-add-props category nil
  4883. 'extra-space (make-string
  4884. (- org-prefix-category-length l 1) ?\ ))))
  4885. (if (and org-prefix-category-max-length
  4886. (>= (length category) org-prefix-category-max-length))
  4887. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4888. ;; Evaluate the compiled format
  4889. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4890. ;; And finally add the text properties
  4891. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4892. (org-add-props rtn nil
  4893. 'org-category (if thecategory (downcase thecategory) category)
  4894. 'tags (mapcar 'org-downcase-keep-props tags)
  4895. 'org-highest-priority org-highest-priority
  4896. 'org-lowest-priority org-lowest-priority
  4897. 'prefix-length (- (length rtn) (length txt))
  4898. 'time-of-day time-of-day
  4899. 'duration duration
  4900. 'effort effort
  4901. 'effort-minutes neffort
  4902. 'txt txt
  4903. 'time time
  4904. 'extra extra
  4905. 'dotime dotime))))
  4906. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4907. "Remove tags string from TXT, and add a modified list of tags.
  4908. The modified list may contain inherited tags, and tags matched by
  4909. `org-agenda-hide-tags-regexp' will be removed."
  4910. (when (or add-inherited hide-re)
  4911. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4912. (setq txt (substring txt 0 (match-beginning 0))))
  4913. (setq tags
  4914. (delq nil
  4915. (mapcar (lambda (tg)
  4916. (if (or (and hide-re (string-match hide-re tg))
  4917. (and (not add-inherited)
  4918. (get-text-property 0 'inherited tg)))
  4919. nil
  4920. tg))
  4921. tags)))
  4922. (when tags
  4923. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4924. i)
  4925. (setq txt (concat txt " :"
  4926. (mapconcat
  4927. (lambda (x)
  4928. (setq i (get-text-property 0 'inherited x))
  4929. (if (and have-i (not i))
  4930. (progn
  4931. (setq have-i nil)
  4932. (concat ":" x))
  4933. x))
  4934. tags ":")
  4935. (if have-i "::" ":"))))))
  4936. txt)
  4937. (defun org-downcase-keep-props (s)
  4938. (let ((props (text-properties-at 0 s)))
  4939. (setq s (downcase s))
  4940. (add-text-properties 0 (length s) props s)
  4941. s))
  4942. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4943. (defvar org-agenda-sorting-strategy-selected nil)
  4944. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4945. (catch 'exit
  4946. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4947. ((and todayp (member 'today (car org-agenda-time-grid))))
  4948. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4949. ((member 'weekly (car org-agenda-time-grid)))
  4950. (t (throw 'exit list)))
  4951. (let* ((have (delq nil (mapcar
  4952. (lambda (x) (get-text-property 1 'time-of-day x))
  4953. list)))
  4954. (string (nth 1 org-agenda-time-grid))
  4955. (gridtimes (nth 2 org-agenda-time-grid))
  4956. (req (car org-agenda-time-grid))
  4957. (remove (member 'remove-match req))
  4958. new time)
  4959. (if (and (member 'require-timed req) (not have))
  4960. ;; don't show empty grid
  4961. (throw 'exit list))
  4962. (while (setq time (pop gridtimes))
  4963. (unless (and remove (member time have))
  4964. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  4965. (push (org-format-agenda-item
  4966. nil string "" nil
  4967. (concat (substring time 0 -2) ":" (substring time -2)))
  4968. new)
  4969. (put-text-property
  4970. 2 (length (car new)) 'face 'org-time-grid (car new))))
  4971. (when (and todayp org-agenda-show-current-time-in-grid)
  4972. (push (org-format-agenda-item
  4973. nil
  4974. org-agenda-current-time-string
  4975. "" nil
  4976. (format-time-string "%H:%M "))
  4977. new)
  4978. (put-text-property
  4979. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  4980. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4981. (append new list)
  4982. (append list new)))))
  4983. (defun org-eval (form)
  4984. "Eval FORM and return result."
  4985. (condition-case error
  4986. (eval form)
  4987. (error (format "%%![Error: %s]" error))))
  4988. (defun org-compile-prefix-format (key)
  4989. "Compile the prefix format into a Lisp form that can be evaluated.
  4990. The resulting form is returned and stored in the variable
  4991. `org-prefix-format-compiled'."
  4992. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4993. org-prefix-category-length nil org-prefix-has-effort nil)
  4994. (let ((s (cond
  4995. ((stringp org-agenda-prefix-format)
  4996. org-agenda-prefix-format)
  4997. ((assq key org-agenda-prefix-format)
  4998. (cdr (assq key org-agenda-prefix-format)))
  4999. (t " %-12:c%?-12t% s")))
  5000. (start 0)
  5001. varform vars var e c f opt)
  5002. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\)"
  5003. s start)
  5004. (setq var (cdr (assoc (match-string 4 s)
  5005. '(("c" . category) ("t" . time) ("s" . extra)
  5006. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5007. c (or (match-string 3 s) "")
  5008. opt (match-beginning 1)
  5009. start (1+ (match-beginning 0)))
  5010. (if (equal var 'time) (setq org-prefix-has-time t))
  5011. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5012. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5013. (setq f (concat "%" (match-string 2 s) "s"))
  5014. (when (equal var 'category)
  5015. (setq org-prefix-category-length
  5016. (floor (abs (string-to-number (match-string 2 s)))))
  5017. (setq org-prefix-category-max-length
  5018. (let ((x (match-string 2 s)))
  5019. (save-match-data
  5020. (if (string-match "\\.[0-9]+" x)
  5021. (string-to-number (substring (match-string 0 x) 1)))))))
  5022. (if opt
  5023. (setq varform
  5024. `(if (equal "" ,var)
  5025. ""
  5026. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5027. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  5028. (setq s (replace-match "%s" t nil s))
  5029. (push varform vars))
  5030. (setq vars (nreverse vars))
  5031. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5032. (defun org-set-sorting-strategy (key)
  5033. (if (symbolp (car org-agenda-sorting-strategy))
  5034. ;; the old format
  5035. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5036. (setq org-agenda-sorting-strategy-selected
  5037. (or (cdr (assq key org-agenda-sorting-strategy))
  5038. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5039. '(time-up category-keep priority-down)))))
  5040. (defun org-get-time-of-day (s &optional string mod24)
  5041. "Check string S for a time of day.
  5042. If found, return it as a military time number between 0 and 2400.
  5043. If not found, return nil.
  5044. The optional STRING argument forces conversion into a 5 character wide string
  5045. HH:MM."
  5046. (save-match-data
  5047. (when
  5048. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5049. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5050. (let* ((h (string-to-number (match-string 1 s)))
  5051. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5052. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5053. (am-p (equal ampm "am"))
  5054. (h1 (cond ((not ampm) h)
  5055. ((= h 12) (if am-p 0 12))
  5056. (t (+ h (if am-p 0 12)))))
  5057. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5058. (mod h1 24) h1))
  5059. (t0 (+ (* 100 h2) m))
  5060. (t1 (concat (if (>= h1 24) "+" " ")
  5061. (if (and org-agenda-time-leading-zero
  5062. (< t0 1000)) "0" "")
  5063. (if (< t0 100) "0" "")
  5064. (if (< t0 10) "0" "")
  5065. (int-to-string t0))))
  5066. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5067. (defvar org-agenda-before-sorting-filter-function nil
  5068. "Function to be applied to agenda items prior to sorting.
  5069. Prior to sorting also means just before they are inserted into the agenda.
  5070. To aid sorting, you may revisit the original entries and add more text
  5071. properties which will later be used by the sorting functions.
  5072. The function should take a string argument, an agenda line.
  5073. It has access to the text properties in that line, which contain among
  5074. other things, the property `org-hd-marker' that points to the entry
  5075. where the line comes from. Note that not all lines going into the agenda
  5076. have this property, only most.
  5077. The function should return the modified string. It is probably best
  5078. to ONLY change text properties.
  5079. You can also use this function as a filter, by returning nil for lines
  5080. you don't want to have in the agenda at all. For this application, you
  5081. could bind the variable in the options section of a custom command.")
  5082. (defun org-finalize-agenda-entries (list &optional nosort)
  5083. "Sort and concatenate the agenda items."
  5084. (setq list (mapcar 'org-agenda-highlight-todo list))
  5085. (if nosort
  5086. list
  5087. (when org-agenda-before-sorting-filter-function
  5088. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5089. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5090. (defun org-agenda-highlight-todo (x)
  5091. (let ((org-done-keywords org-done-keywords-for-agenda)
  5092. (case-fold-search nil)
  5093. re pl)
  5094. (if (eq x 'line)
  5095. (save-excursion
  5096. (beginning-of-line 1)
  5097. (setq re (org-get-at-bol 'org-todo-regexp))
  5098. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  5099. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5100. (add-text-properties (match-beginning 0) (match-end 1)
  5101. (list 'face (org-get-todo-face 1)))
  5102. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5103. (delete-region (match-beginning 1) (1- (match-end 0)))
  5104. (goto-char (match-beginning 1))
  5105. (insert (format org-agenda-todo-keyword-format s)))))
  5106. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  5107. pl (get-text-property 0 'prefix-length x))
  5108. (when (and re
  5109. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5110. x (or pl 0)) pl))
  5111. (add-text-properties
  5112. (or (match-end 1) (match-end 0)) (match-end 0)
  5113. (list 'face (org-get-todo-face (match-string 2 x)))
  5114. x)
  5115. (when (match-end 1)
  5116. (setq x (concat (substring x 0 (match-end 1))
  5117. (format org-agenda-todo-keyword-format
  5118. (match-string 2 x))
  5119. (org-add-props " " (text-properties-at 0 x))
  5120. (substring x (match-end 3))))))
  5121. x)))
  5122. (defsubst org-cmp-priority (a b)
  5123. "Compare the priorities of string A and B."
  5124. (let ((pa (or (get-text-property 1 'priority a) 0))
  5125. (pb (or (get-text-property 1 'priority b) 0)))
  5126. (cond ((> pa pb) +1)
  5127. ((< pa pb) -1)
  5128. (t nil))))
  5129. (defsubst org-cmp-effort (a b)
  5130. "Compare the priorities of string A and B."
  5131. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5132. (ea (or (get-text-property 1 'effort-minutes a) def))
  5133. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5134. (cond ((> ea eb) +1)
  5135. ((< ea eb) -1)
  5136. (t nil))))
  5137. (defsubst org-cmp-category (a b)
  5138. "Compare the string values of categories of strings A and B."
  5139. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5140. (cb (or (get-text-property 1 'org-category b) "")))
  5141. (cond ((string-lessp ca cb) -1)
  5142. ((string-lessp cb ca) +1)
  5143. (t nil))))
  5144. (defsubst org-cmp-todo-state (a b)
  5145. "Compare the todo states of strings A and B."
  5146. (let* ((ma (or (get-text-property 1 'org-marker a)
  5147. (get-text-property 1 'org-hd-marker a)))
  5148. (mb (or (get-text-property 1 'org-marker b)
  5149. (get-text-property 1 'org-hd-marker b)))
  5150. (fa (and ma (marker-buffer ma)))
  5151. (fb (and mb (marker-buffer mb)))
  5152. (todo-kwds
  5153. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5154. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5155. (ta (or (get-text-property 1 'todo-state a) ""))
  5156. (tb (or (get-text-property 1 'todo-state b) ""))
  5157. (la (- (length (member ta todo-kwds))))
  5158. (lb (- (length (member tb todo-kwds))))
  5159. (donepa (member ta org-done-keywords-for-agenda))
  5160. (donepb (member tb org-done-keywords-for-agenda)))
  5161. (cond ((and donepa (not donepb)) -1)
  5162. ((and (not donepa) donepb) +1)
  5163. ((< la lb) -1)
  5164. ((< lb la) +1)
  5165. (t nil))))
  5166. (defsubst org-cmp-alpha (a b)
  5167. "Compare the headlines, alphabetically."
  5168. (let* ((pla (get-text-property 0 'prefix-length a))
  5169. (plb (get-text-property 0 'prefix-length b))
  5170. (ta (and pla (substring a pla)))
  5171. (tb (and plb (substring b plb))))
  5172. (when pla
  5173. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5174. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5175. (setq ta (substring ta (match-end 0))))
  5176. (setq ta (downcase ta)))
  5177. (when plb
  5178. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5179. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5180. (setq tb (substring tb (match-end 0))))
  5181. (setq tb (downcase tb)))
  5182. (cond ((not ta) +1)
  5183. ((not tb) -1)
  5184. ((string-lessp ta tb) -1)
  5185. ((string-lessp tb ta) +1)
  5186. (t nil))))
  5187. (defsubst org-cmp-tag (a b)
  5188. "Compare the string values of the first tags of A and B."
  5189. (let ((ta (car (last (get-text-property 1 'tags a))))
  5190. (tb (car (last (get-text-property 1 'tags b)))))
  5191. (cond ((not ta) +1)
  5192. ((not tb) -1)
  5193. ((string-lessp ta tb) -1)
  5194. ((string-lessp tb ta) +1)
  5195. (t nil))))
  5196. (defsubst org-cmp-time (a b)
  5197. "Compare the time-of-day values of strings A and B."
  5198. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5199. (ta (or (get-text-property 1 'time-of-day a) def))
  5200. (tb (or (get-text-property 1 'time-of-day b) def)))
  5201. (cond ((< ta tb) -1)
  5202. ((< tb ta) +1)
  5203. (t nil))))
  5204. (defsubst org-cmp-habit-p (a b)
  5205. "Compare the todo states of strings A and B."
  5206. (let ((ha (get-text-property 1 'org-habit-p a))
  5207. (hb (get-text-property 1 'org-habit-p b)))
  5208. (cond ((and ha (not hb)) -1)
  5209. ((and (not ha) hb) +1)
  5210. (t nil))))
  5211. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5212. (defun org-entries-lessp (a b)
  5213. "Predicate for sorting agenda entries."
  5214. ;; The following variables will be used when the form is evaluated.
  5215. ;; So even though the compiler complains, keep them.
  5216. (let* ((ss org-agenda-sorting-strategy-selected)
  5217. (time-up (and (org-em 'time-up 'time-down ss)
  5218. (org-cmp-time a b)))
  5219. (time-down (if time-up (- time-up) nil))
  5220. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5221. (org-cmp-priority a b)))
  5222. (priority-down (if priority-up (- priority-up) nil))
  5223. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5224. (org-cmp-effort a b)))
  5225. (effort-down (if effort-up (- effort-up) nil))
  5226. (category-up (and (or (org-em 'category-up 'category-down ss)
  5227. (memq 'category-keep ss))
  5228. (org-cmp-category a b)))
  5229. (category-down (if category-up (- category-up) nil))
  5230. (category-keep (if category-up +1 nil))
  5231. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5232. (org-cmp-tag a b)))
  5233. (tag-down (if tag-up (- tag-up) nil))
  5234. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5235. (org-cmp-todo-state a b)))
  5236. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5237. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5238. (org-cmp-habit-p a b)))
  5239. (habit-down (if habit-up (- habit-up) nil))
  5240. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5241. (org-cmp-alpha a b)))
  5242. (alpha-down (if alpha-up (- alpha-up) nil))
  5243. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5244. user-defined-up user-defined-down)
  5245. (if (and need-user-cmp org-agenda-cmp-user-defined
  5246. (functionp org-agenda-cmp-user-defined))
  5247. (setq user-defined-up
  5248. (funcall org-agenda-cmp-user-defined a b)
  5249. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5250. (cdr (assoc
  5251. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5252. '((-1 . t) (1 . nil) (nil . nil))))))
  5253. ;;; Agenda restriction lock
  5254. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5255. "Overlay to mark the headline to which agenda commands are restricted.")
  5256. (overlay-put org-agenda-restriction-lock-overlay
  5257. 'face 'org-agenda-restriction-lock)
  5258. (overlay-put org-agenda-restriction-lock-overlay
  5259. 'help-echo "Agendas are currently limited to this subtree.")
  5260. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5261. (defun org-agenda-set-restriction-lock (&optional type)
  5262. "Set restriction lock for agenda, to current subtree or file.
  5263. Restriction will be the file if TYPE is `file', or if type is the
  5264. universal prefix '(4), or if the cursor is before the first headline
  5265. in the file. Otherwise, restriction will be to the current subtree."
  5266. (interactive "P")
  5267. (and (equal type '(4)) (setq type 'file))
  5268. (setq type (cond
  5269. (type type)
  5270. ((org-at-heading-p) 'subtree)
  5271. ((condition-case nil (org-back-to-heading t) (error nil))
  5272. 'subtree)
  5273. (t 'file)))
  5274. (if (eq type 'subtree)
  5275. (progn
  5276. (setq org-agenda-restrict t)
  5277. (setq org-agenda-overriding-restriction 'subtree)
  5278. (put 'org-agenda-files 'org-restrict
  5279. (list (buffer-file-name (buffer-base-buffer))))
  5280. (org-back-to-heading t)
  5281. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5282. (move-marker org-agenda-restrict-begin (point))
  5283. (move-marker org-agenda-restrict-end
  5284. (save-excursion (org-end-of-subtree t)))
  5285. (message "Locking agenda restriction to subtree"))
  5286. (put 'org-agenda-files 'org-restrict
  5287. (list (buffer-file-name (buffer-base-buffer))))
  5288. (setq org-agenda-restrict nil)
  5289. (setq org-agenda-overriding-restriction 'file)
  5290. (move-marker org-agenda-restrict-begin nil)
  5291. (move-marker org-agenda-restrict-end nil)
  5292. (message "Locking agenda restriction to file"))
  5293. (setq current-prefix-arg nil)
  5294. (org-agenda-maybe-redo))
  5295. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5296. "Remove the agenda restriction lock."
  5297. (interactive "P")
  5298. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5299. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5300. (setq org-agenda-overriding-restriction nil)
  5301. (setq org-agenda-restrict nil)
  5302. (put 'org-agenda-files 'org-restrict nil)
  5303. (move-marker org-agenda-restrict-begin nil)
  5304. (move-marker org-agenda-restrict-end nil)
  5305. (setq current-prefix-arg nil)
  5306. (message "Agenda restriction lock removed")
  5307. (or noupdate (org-agenda-maybe-redo)))
  5308. (defun org-agenda-maybe-redo ()
  5309. "If there is any window showing the agenda view, update it."
  5310. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5311. (w0 (selected-window)))
  5312. (when w
  5313. (select-window w)
  5314. (org-agenda-redo)
  5315. (select-window w0)
  5316. (if org-agenda-overriding-restriction
  5317. (message "Agenda view shifted to new %s restriction"
  5318. org-agenda-overriding-restriction)
  5319. (message "Agenda restriction lock removed")))))
  5320. ;;; Agenda commands
  5321. (defun org-agenda-check-type (error &rest types)
  5322. "Check if agenda buffer is of allowed type.
  5323. If ERROR is non-nil, throw an error, otherwise just return nil."
  5324. (if (memq org-agenda-type types)
  5325. t
  5326. (if error
  5327. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5328. nil)))
  5329. (defun org-agenda-quit ()
  5330. "Exit agenda by removing the window or the buffer."
  5331. (interactive)
  5332. (if org-agenda-columns-active
  5333. (org-columns-quit)
  5334. (let ((buf (current-buffer)))
  5335. (if (eq org-agenda-window-setup 'other-frame)
  5336. (progn
  5337. (kill-buffer buf)
  5338. (org-agenda-reset-markers)
  5339. (org-columns-remove-overlays)
  5340. (setq org-agenda-archives-mode nil)
  5341. (delete-frame))
  5342. (and (not (eq org-agenda-window-setup 'current-window))
  5343. (not (one-window-p))
  5344. (delete-window))
  5345. (kill-buffer buf)
  5346. (org-agenda-reset-markers)
  5347. (org-columns-remove-overlays)
  5348. (setq org-agenda-archives-mode nil)))
  5349. ;; Maybe restore the pre-agenda window configuration.
  5350. (and org-agenda-restore-windows-after-quit
  5351. (not (eq org-agenda-window-setup 'other-frame))
  5352. org-pre-agenda-window-conf
  5353. (set-window-configuration org-pre-agenda-window-conf))))
  5354. (defun org-agenda-exit ()
  5355. "Exit agenda by removing the window or the buffer.
  5356. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5357. Org-mode buffers visited directly by the user will not be touched."
  5358. (interactive)
  5359. (org-release-buffers org-agenda-new-buffers)
  5360. (setq org-agenda-new-buffers nil)
  5361. (org-agenda-quit))
  5362. (defun org-agenda-execute (arg)
  5363. "Execute another agenda command, keeping same window.
  5364. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5365. in the agenda."
  5366. (interactive "P")
  5367. (let ((org-agenda-window-setup 'current-window))
  5368. (org-agenda arg)))
  5369. (defun org-agenda-redo ()
  5370. "Rebuild Agenda.
  5371. When this is the global TODO list, a prefix argument will be interpreted."
  5372. (interactive)
  5373. (let* ((org-agenda-keep-modes t)
  5374. (filter org-agenda-filter)
  5375. (preset (get 'org-agenda-filter :preset-filter))
  5376. (org-agenda-filter-while-redo (or filter preset))
  5377. (cols org-agenda-columns-active)
  5378. (line (org-current-line))
  5379. (window-line (- line (org-current-line (window-start))))
  5380. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5381. (put 'org-agenda-filter :preset-filter nil)
  5382. (and cols (org-columns-quit))
  5383. (message "Rebuilding agenda buffer...")
  5384. (org-let lprops '(eval org-agenda-redo-command))
  5385. (setq org-agenda-undo-list nil
  5386. org-agenda-pending-undo-list nil)
  5387. (message "Rebuilding agenda buffer...done")
  5388. (put 'org-agenda-filter :preset-filter preset)
  5389. (and (or filter preset) (org-agenda-filter-apply filter))
  5390. (and cols (interactive-p) (org-agenda-columns))
  5391. (org-goto-line line)
  5392. (recenter window-line)))
  5393. (defvar org-global-tags-completion-table nil)
  5394. (defvar org-agenda-filter-form nil)
  5395. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5396. "Keep only those lines in the agenda buffer that have a specific tag.
  5397. The tag is selected with its fast selection letter, as configured.
  5398. With prefix argument STRIP, remove all lines that do have the tag.
  5399. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5400. used to narrow the search - the interactive user can also press `-' or `+'
  5401. to switch to narrowing."
  5402. (interactive "P")
  5403. (let* ((alist org-tag-alist-for-agenda)
  5404. (tag-chars (mapconcat
  5405. (lambda (x) (if (and (not (symbolp (car x)))
  5406. (cdr x))
  5407. (char-to-string (cdr x))
  5408. ""))
  5409. alist ""))
  5410. (efforts (org-split-string
  5411. (or (cdr (assoc (concat org-effort-property "_ALL")
  5412. org-global-properties))
  5413. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5414. (effort-op org-agenda-filter-effort-default-operator)
  5415. (effort-prompt "")
  5416. (inhibit-read-only t)
  5417. (current org-agenda-filter)
  5418. a n tag)
  5419. (unless char
  5420. (message
  5421. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5422. (if narrow "Narrow" "Filter") tag-chars
  5423. (if org-agenda-auto-exclude-function "[RET], " ""))
  5424. (setq char (read-char)))
  5425. (when (member char '(?+ ?-))
  5426. ;; Narrowing down
  5427. (cond ((equal char ?-) (setq strip t narrow t))
  5428. ((equal char ?+) (setq strip nil narrow t)))
  5429. (message
  5430. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5431. (setq char (read-char)))
  5432. (when (member char '(?< ?> ?= ??))
  5433. ;; An effort operator
  5434. (setq effort-op (char-to-string char))
  5435. (setq alist nil) ; to make sure it will be interpreted as effort.
  5436. (unless (equal char ??)
  5437. (loop for i from 0 to 9 do
  5438. (setq effort-prompt
  5439. (concat
  5440. effort-prompt " ["
  5441. (if (= i 9) "0" (int-to-string (1+ i)))
  5442. "]" (nth i efforts))))
  5443. (message "Effort%s: %s " effort-op effort-prompt)
  5444. (setq char (read-char))
  5445. (when (or (< char ?0) (> char ?9))
  5446. (error "Need 1-9,0 to select effort" ))))
  5447. (when (equal char ?\t)
  5448. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5449. (org-set-local 'org-global-tags-completion-table
  5450. (org-global-tags-completion-table)))
  5451. (let ((completion-ignore-case t))
  5452. (setq tag (org-icompleting-read
  5453. "Tag: " org-global-tags-completion-table))))
  5454. (cond
  5455. ((equal char ?\r)
  5456. (org-agenda-filter-by-tag-show-all)
  5457. (when org-agenda-auto-exclude-function
  5458. (setq org-agenda-filter '())
  5459. (dolist (tag (org-agenda-get-represented-tags))
  5460. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5461. (if modifier
  5462. (push modifier org-agenda-filter))))
  5463. (if (not (null org-agenda-filter))
  5464. (org-agenda-filter-apply org-agenda-filter))))
  5465. ((equal char ?/)
  5466. (org-agenda-filter-by-tag-show-all)
  5467. (when (get 'org-agenda-filter :preset-filter)
  5468. (org-agenda-filter-apply org-agenda-filter)))
  5469. ((or (equal char ?\ )
  5470. (setq a (rassoc char alist))
  5471. (and (>= char ?0) (<= char ?9)
  5472. (setq n (if (= char ?0) 9 (- char ?0 1))
  5473. tag (concat effort-op (nth n efforts))
  5474. a (cons tag nil)))
  5475. (and (= char ??)
  5476. (setq tag "?eff")
  5477. a (cons tag nil))
  5478. (and tag (setq a (cons tag nil))))
  5479. (org-agenda-filter-by-tag-show-all)
  5480. (setq tag (car a))
  5481. (setq org-agenda-filter
  5482. (cons (concat (if strip "-" "+") tag)
  5483. (if narrow current nil)))
  5484. (org-agenda-filter-apply org-agenda-filter))
  5485. (t (error "Invalid tag selection character %c" char)))))
  5486. (defun org-agenda-get-represented-tags ()
  5487. "Get a list of all tags currently represented in the agenda."
  5488. (let (p tags)
  5489. (save-excursion
  5490. (goto-char (point-min))
  5491. (while (setq p (next-single-property-change (point) 'tags))
  5492. (goto-char p)
  5493. (mapc (lambda (x) (add-to-list 'tags x))
  5494. (get-text-property (point) 'tags))))
  5495. tags))
  5496. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5497. "Refine the current filter. See `org-agenda-filter-by-tag."
  5498. (interactive "P")
  5499. (org-agenda-filter-by-tag strip char 'refine))
  5500. (defun org-agenda-filter-make-matcher ()
  5501. "Create the form that tests a line for the agenda filter."
  5502. (let (f f1)
  5503. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5504. org-agenda-filter))
  5505. (if (member x '("-" "+"))
  5506. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5507. (if (string-match "[<=>?]" x)
  5508. (setq f1 (org-agenda-filter-effort-form x))
  5509. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5510. (if (equal (string-to-char x) ?-)
  5511. (setq f1 (list 'not f1))))
  5512. (push f1 f))
  5513. (cons 'and (nreverse f))))
  5514. (defun org-agenda-filter-effort-form (e)
  5515. "Return the form to compare the effort of the current line with what E says.
  5516. E looks like \"+<2:25\"."
  5517. (let (op)
  5518. (setq e (substring e 1))
  5519. (setq op (string-to-char e) e (substring e 1))
  5520. (setq op (cond ((equal op ?<) '<=)
  5521. ((equal op ?>) '>=)
  5522. ((equal op ??) op)
  5523. (t '=)))
  5524. (list 'org-agenda-compare-effort (list 'quote op)
  5525. (org-hh:mm-string-to-minutes e))))
  5526. (defun org-agenda-compare-effort (op value)
  5527. "Compare the effort of the current line with VALUE, using OP.
  5528. If the line does not have an effort defined, return nil."
  5529. (let ((eff (org-get-at-bol 'effort-minutes)))
  5530. (if (equal op ??)
  5531. (not eff)
  5532. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5533. value))))
  5534. (defun org-agenda-filter-apply (filter)
  5535. "Set FILTER as the new agenda filter and apply it."
  5536. (let (tags)
  5537. (setq org-agenda-filter filter
  5538. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5539. (org-agenda-set-mode-name)
  5540. (save-excursion
  5541. (goto-char (point-min))
  5542. (while (not (eobp))
  5543. (if (org-get-at-bol 'org-marker)
  5544. (progn
  5545. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5546. (if (not (eval org-agenda-filter-form))
  5547. (org-agenda-filter-by-tag-hide-line))
  5548. (beginning-of-line 2))
  5549. (beginning-of-line 2))))
  5550. (if (get-char-property (point) 'invisible)
  5551. (org-agenda-previous-line))))
  5552. (defun org-agenda-filter-by-tag-hide-line ()
  5553. (let (ov)
  5554. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5555. (point-at-eol)))
  5556. (overlay-put ov 'invisible t)
  5557. (overlay-put ov 'type 'tags-filter)
  5558. (push ov org-agenda-filter-overlays)))
  5559. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5560. (setq pos (or pos (point)))
  5561. (save-excursion
  5562. (dolist (ov (overlays-at pos))
  5563. (when (and (overlay-get ov 'invisible)
  5564. (eq (overlay-get ov 'type) 'tags-filter))
  5565. (goto-char pos)
  5566. (if (< (overlay-start ov) (point-at-eol))
  5567. (move-overlay ov (point-at-eol)
  5568. (overlay-end ov)))))))
  5569. (defun org-agenda-filter-by-tag-show-all ()
  5570. (mapc 'delete-overlay org-agenda-filter-overlays)
  5571. (setq org-agenda-filter-overlays nil)
  5572. (setq org-agenda-filter nil)
  5573. (setq org-agenda-filter-form nil)
  5574. (org-agenda-set-mode-name))
  5575. (defun org-agenda-manipulate-query-add ()
  5576. "Manipulate the query by adding a search term with positive selection.
  5577. Positive selection means the term must be matched for selection of an entry."
  5578. (interactive)
  5579. (org-agenda-manipulate-query ?\[))
  5580. (defun org-agenda-manipulate-query-subtract ()
  5581. "Manipulate the query by adding a search term with negative selection.
  5582. Negative selection means term must not be matched for selection of an entry."
  5583. (interactive)
  5584. (org-agenda-manipulate-query ?\]))
  5585. (defun org-agenda-manipulate-query-add-re ()
  5586. "Manipulate the query by adding a search regexp with positive selection.
  5587. Positive selection means the regexp must match for selection of an entry."
  5588. (interactive)
  5589. (org-agenda-manipulate-query ?\{))
  5590. (defun org-agenda-manipulate-query-subtract-re ()
  5591. "Manipulate the query by adding a search regexp with negative selection.
  5592. Negative selection means regexp must not match for selection of an entry."
  5593. (interactive)
  5594. (org-agenda-manipulate-query ?\}))
  5595. (defun org-agenda-manipulate-query (char)
  5596. (cond
  5597. ((memq org-agenda-type '(timeline agenda))
  5598. (let ((org-agenda-include-inactive-timestamps t))
  5599. (org-agenda-redo))
  5600. (message "Display now includes inactive timestamps as well"))
  5601. ((eq org-agenda-type 'search)
  5602. (org-add-to-string
  5603. 'org-agenda-query-string
  5604. (if org-agenda-last-search-view-search-was-boolean
  5605. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5606. (?\{ . " +{}") (?\} . " -{}"))))
  5607. " "))
  5608. (setq org-agenda-redo-command
  5609. (list 'org-search-view
  5610. org-todo-only
  5611. org-agenda-query-string
  5612. (+ (length org-agenda-query-string)
  5613. (if (member char '(?\{ ?\})) 0 1))))
  5614. (set-register org-agenda-query-register org-agenda-query-string)
  5615. (org-agenda-redo))
  5616. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5617. org-agenda-type))))
  5618. (defun org-add-to-string (var string)
  5619. (set var (concat (symbol-value var) string)))
  5620. (defun org-agenda-goto-date (date)
  5621. "Jump to DATE in agenda."
  5622. (interactive (list (let ((org-read-date-prefer-future
  5623. (eval org-agenda-jump-prefer-future)))
  5624. (org-read-date))))
  5625. (org-agenda-list nil date))
  5626. (defun org-agenda-goto-today ()
  5627. "Go to today."
  5628. (interactive)
  5629. (org-agenda-check-type t 'timeline 'agenda)
  5630. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5631. (cond
  5632. (tdpos (goto-char tdpos))
  5633. ((eq org-agenda-type 'agenda)
  5634. (let* ((sd (org-agenda-compute-starting-span
  5635. (org-today) (or org-agenda-ndays org-agenda-span)))
  5636. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5637. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5638. (org-agenda-redo)
  5639. (org-agenda-find-same-or-today-or-agenda)))
  5640. (t (error "Cannot find today")))))
  5641. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5642. (goto-char
  5643. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5644. (text-property-any (point-min) (point-max) 'org-today t)
  5645. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5646. (point-min))))
  5647. (defun org-agenda-later (arg)
  5648. "Go forward in time by thee current span.
  5649. With prefix ARG, go forward that many times the current span."
  5650. (interactive "p")
  5651. (org-agenda-check-type t 'agenda)
  5652. (let* ((span org-agenda-current-span)
  5653. (sd org-starting-day)
  5654. (greg (calendar-gregorian-from-absolute sd))
  5655. (cnt (org-get-at-bol 'org-day-cnt))
  5656. greg2)
  5657. (cond
  5658. ((eq span 'day)
  5659. (setq sd (+ arg sd)))
  5660. ((eq span 'week)
  5661. (setq sd (+ (* 7 arg) sd)))
  5662. ((eq span 'month)
  5663. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5664. sd (calendar-absolute-from-gregorian greg2))
  5665. (setcar greg2 (1+ (car greg2))))
  5666. ((eq span 'year)
  5667. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5668. sd (calendar-absolute-from-gregorian greg2))
  5669. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5670. (t
  5671. (setq sd (+ (* span arg) sd))))
  5672. (let ((org-agenda-overriding-arguments
  5673. (list (car org-agenda-last-arguments) sd span t)))
  5674. (org-agenda-redo)
  5675. (org-agenda-find-same-or-today-or-agenda cnt))))
  5676. (defun org-agenda-earlier (arg)
  5677. "Go backward in time by the current span.
  5678. With prefix ARG, go backward that many times the current span."
  5679. (interactive "p")
  5680. (org-agenda-later (- arg)))
  5681. (defun org-agenda-view-mode-dispatch ()
  5682. "Call one of the view mode commands."
  5683. (interactive)
  5684. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5685. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5686. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5687. (let ((a (read-char-exclusive)))
  5688. (case a
  5689. (?d (call-interactively 'org-agenda-day-view))
  5690. (?w (call-interactively 'org-agenda-week-view))
  5691. (?m (call-interactively 'org-agenda-month-view))
  5692. (?y (call-interactively 'org-agenda-year-view))
  5693. (?l (call-interactively 'org-agenda-log-mode))
  5694. (?L (org-agenda-log-mode '(4)))
  5695. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5696. (?a (call-interactively 'org-agenda-archives-mode))
  5697. (?A (org-agenda-archives-mode 'files))
  5698. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5699. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5700. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5701. (?D (call-interactively 'org-agenda-toggle-diary))
  5702. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5703. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5704. (org-agenda-check-type t 'timeline 'agenda)
  5705. (org-agenda-redo))
  5706. (message "Display now includes inactive timestamps as well"))
  5707. (?q (message "Abort"))
  5708. (otherwise (error "Invalid key" )))))
  5709. (defun org-agenda-day-view (&optional day-of-year)
  5710. "Switch to daily view for agenda.
  5711. With argument DAY-OF-YEAR, switch to that day of the year."
  5712. (interactive "P")
  5713. (org-agenda-change-time-span 'day day-of-year))
  5714. (defun org-agenda-week-view (&optional iso-week)
  5715. "Switch to daily view for agenda.
  5716. With argument ISO-WEEK, switch to the corresponding ISO week.
  5717. If ISO-WEEK has more then 2 digits, only the last two encode the
  5718. week. Any digits before this encode a year. So 200712 means
  5719. week 12 of year 2007. Years in the range 1938-2037 can also be
  5720. written as 2-digit years."
  5721. (interactive "P")
  5722. (org-agenda-change-time-span 'week iso-week))
  5723. (defun org-agenda-month-view (&optional month)
  5724. "Switch to monthly view for agenda.
  5725. With argument MONTH, switch to that month."
  5726. (interactive "P")
  5727. (org-agenda-change-time-span 'month month))
  5728. (defun org-agenda-year-view (&optional year)
  5729. "Switch to yearly view for agenda.
  5730. With argument YEAR, switch to that year.
  5731. If MONTH has more then 2 digits, only the last two encode the
  5732. month. Any digits before this encode a year. So 200712 means
  5733. December year 2007. Years in the range 1938-2037 can also be
  5734. written as 2-digit years."
  5735. (interactive "P")
  5736. (when year
  5737. (setq year (org-small-year-to-year year)))
  5738. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5739. (org-agenda-change-time-span 'year year)
  5740. (error "Abort")))
  5741. (defun org-agenda-change-time-span (span &optional n)
  5742. "Change the agenda view to SPAN.
  5743. SPAN may be `day', `week', `month', `year'."
  5744. (org-agenda-check-type t 'agenda)
  5745. (if (and (not n) (equal org-agenda-current-span span))
  5746. (error "Viewing span is already \"%s\"" span))
  5747. (let* ((sd (or (org-get-at-bol 'day)
  5748. org-starting-day))
  5749. (sd (org-agenda-compute-starting-span sd span n))
  5750. (org-agenda-overriding-arguments
  5751. (list (car org-agenda-last-arguments) sd span t)))
  5752. (org-agenda-redo)
  5753. (org-agenda-find-same-or-today-or-agenda))
  5754. (org-agenda-set-mode-name)
  5755. (message "Switched to %s view" span))
  5756. (defun org-agenda-compute-starting-span (sd span &optional n)
  5757. "Compute starting date for agenda.
  5758. SPAN may be `day', `week', `month', `year'. The return value
  5759. is a cons cell with the starting date and the number of days,
  5760. so that the date SD will be in that range."
  5761. (let* ((greg (calendar-gregorian-from-absolute sd))
  5762. (dg (nth 1 greg))
  5763. (mg (car greg))
  5764. (yg (nth 2 greg)))
  5765. (cond
  5766. ((eq span 'day)
  5767. (when n
  5768. (setq sd (+ (calendar-absolute-from-gregorian
  5769. (list mg 1 yg))
  5770. n -1))))
  5771. ((eq span 'week)
  5772. (let* ((nt (calendar-day-of-week
  5773. (calendar-gregorian-from-absolute sd)))
  5774. (d (if org-agenda-start-on-weekday
  5775. (- nt org-agenda-start-on-weekday)
  5776. 0))
  5777. y1)
  5778. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5779. (when n
  5780. (require 'cal-iso)
  5781. (when (> n 99)
  5782. (setq y1 (org-small-year-to-year (/ n 100))
  5783. n (mod n 100)))
  5784. (setq sd
  5785. (calendar-absolute-from-iso
  5786. (list n 1
  5787. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  5788. ((eq span 'month)
  5789. (let (y1)
  5790. (when (and n (> n 99))
  5791. (setq y1 (org-small-year-to-year (/ n 100))
  5792. n (mod n 100)))
  5793. (setq sd (calendar-absolute-from-gregorian
  5794. (list (or n mg) 1 (or y1 yg))))))
  5795. ((eq span 'year)
  5796. (setq sd (calendar-absolute-from-gregorian
  5797. (list 1 1 (or n yg))))))
  5798. sd))
  5799. (defun org-agenda-next-date-line (&optional arg)
  5800. "Jump to the next line indicating a date in agenda buffer."
  5801. (interactive "p")
  5802. (org-agenda-check-type t 'agenda 'timeline)
  5803. (beginning-of-line 1)
  5804. ;; This does not work if user makes date format that starts with a blank
  5805. (if (looking-at "^\\S-") (forward-char 1))
  5806. (if (not (re-search-forward "^\\S-" nil t arg))
  5807. (progn
  5808. (backward-char 1)
  5809. (error "No next date after this line in this buffer")))
  5810. (goto-char (match-beginning 0)))
  5811. (defun org-agenda-previous-date-line (&optional arg)
  5812. "Jump to the previous line indicating a date in agenda buffer."
  5813. (interactive "p")
  5814. (org-agenda-check-type t 'agenda 'timeline)
  5815. (beginning-of-line 1)
  5816. (if (not (re-search-backward "^\\S-" nil t arg))
  5817. (error "No previous date before this line in this buffer")))
  5818. ;; Initialize the highlight
  5819. (defvar org-hl (make-overlay 1 1))
  5820. (overlay-put org-hl 'face 'highlight)
  5821. (defun org-highlight (begin end &optional buffer)
  5822. "Highlight a region with overlay."
  5823. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5824. (defun org-unhighlight ()
  5825. "Detach overlay INDEX."
  5826. (org-detach-overlay org-hl))
  5827. ;; FIXME this is currently not used.
  5828. (defun org-highlight-until-next-command (beg end &optional buffer)
  5829. "Move the highlight overlay to BEG/END, remove it before the next command."
  5830. (org-highlight beg end buffer)
  5831. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5832. (defun org-unhighlight-once ()
  5833. "Remove the highlight from its position, and this function from the hook."
  5834. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5835. (org-unhighlight))
  5836. (defun org-agenda-follow-mode ()
  5837. "Toggle follow mode in an agenda buffer."
  5838. (interactive)
  5839. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5840. (org-agenda-set-mode-name)
  5841. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5842. (org-agenda-show))
  5843. (message "Follow mode is %s"
  5844. (if org-agenda-follow-mode "on" "off")))
  5845. (defun org-agenda-entry-text-mode (&optional arg)
  5846. "Toggle entry text mode in an agenda buffer."
  5847. (interactive "P")
  5848. (setq org-agenda-entry-text-mode (or (integerp arg)
  5849. (not org-agenda-entry-text-mode)))
  5850. (org-agenda-entry-text-hide)
  5851. (and org-agenda-entry-text-mode
  5852. (let ((org-agenda-entry-text-maxlines
  5853. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5854. (org-agenda-entry-text-show)))
  5855. (org-agenda-set-mode-name)
  5856. (message "Entry text mode is %s. Maximum number of lines is %d"
  5857. (if org-agenda-entry-text-mode "on" "off")
  5858. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5859. (defun org-agenda-clockreport-mode (&optional with-filter)
  5860. "Toggle clocktable mode in an agenda buffer.
  5861. With prefix arg WITH-FILTER, make the clocktable respect the current
  5862. agenda filter."
  5863. (interactive "P")
  5864. (org-agenda-check-type t 'agenda)
  5865. (if with-filter
  5866. (setq org-agenda-clockreport-mode 'with-filter)
  5867. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5868. (org-agenda-set-mode-name)
  5869. (org-agenda-redo)
  5870. (message "Clocktable mode is %s"
  5871. (if org-agenda-clockreport-mode "on" "off")))
  5872. (defun org-agenda-log-mode (&optional special)
  5873. "Toggle log mode in an agenda buffer.
  5874. With argument SPECIAL, show all possible log items, not only the ones
  5875. configured in `org-agenda-log-mode-items'.
  5876. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5877. (interactive "P")
  5878. (org-agenda-check-type t 'agenda 'timeline)
  5879. (setq org-agenda-show-log
  5880. (if (equal special '(16))
  5881. 'only
  5882. (if special '(closed clock state)
  5883. (not org-agenda-show-log))))
  5884. (org-agenda-set-mode-name)
  5885. (org-agenda-redo)
  5886. (message "Log mode is %s"
  5887. (if org-agenda-show-log "on" "off")))
  5888. (defun org-agenda-archives-mode (&optional with-files)
  5889. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5890. When called with a prefix argument, include all archive files as well."
  5891. (interactive "P")
  5892. (setq org-agenda-archives-mode
  5893. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5894. (org-agenda-set-mode-name)
  5895. (org-agenda-redo)
  5896. (message
  5897. "%s"
  5898. (cond
  5899. ((eq org-agenda-archives-mode nil)
  5900. "No archives are included")
  5901. ((eq org-agenda-archives-mode 'trees)
  5902. (format "Trees with :%s: tag are included" org-archive-tag))
  5903. ((eq org-agenda-archives-mode t)
  5904. (format "Trees with :%s: tag and all active archive files are included"
  5905. org-archive-tag)))))
  5906. (defun org-agenda-toggle-diary ()
  5907. "Toggle diary inclusion in an agenda buffer."
  5908. (interactive)
  5909. (org-agenda-check-type t 'agenda)
  5910. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5911. (org-agenda-redo)
  5912. (org-agenda-set-mode-name)
  5913. (message "Diary inclusion turned %s"
  5914. (if org-agenda-include-diary "on" "off")))
  5915. (defun org-agenda-toggle-deadlines ()
  5916. "Toggle inclusion of entries with a deadline in an agenda buffer."
  5917. (interactive)
  5918. (org-agenda-check-type t 'agenda)
  5919. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5920. (org-agenda-redo)
  5921. (org-agenda-set-mode-name)
  5922. (message "Deadlines inclusion turned %s"
  5923. (if org-agenda-include-deadlines "on" "off")))
  5924. (defun org-agenda-toggle-time-grid ()
  5925. "Toggle time grid in an agenda buffer."
  5926. (interactive)
  5927. (org-agenda-check-type t 'agenda)
  5928. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5929. (org-agenda-redo)
  5930. (org-agenda-set-mode-name)
  5931. (message "Time-grid turned %s"
  5932. (if org-agenda-use-time-grid "on" "off")))
  5933. (defun org-agenda-set-mode-name ()
  5934. "Set the mode name to indicate all the small mode settings."
  5935. (setq mode-name
  5936. (list "Org-Agenda"
  5937. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5938. " "
  5939. '(:eval (org-agenda-span-name org-agenda-current-span))
  5940. (if org-agenda-follow-mode " Follow" "")
  5941. (if org-agenda-entry-text-mode " ETxt" "")
  5942. (if org-agenda-include-diary " Diary" "")
  5943. (if org-agenda-include-deadlines " Ddl" "")
  5944. (if org-agenda-use-time-grid " Grid" "")
  5945. (if (and (boundp 'org-habit-show-habits)
  5946. org-habit-show-habits) " Habit" "")
  5947. (if (consp org-agenda-show-log) " LogAll"
  5948. (if org-agenda-show-log " Log" ""))
  5949. (if (or org-agenda-filter (get 'org-agenda-filter
  5950. :preset-filter))
  5951. (concat " {" (mapconcat
  5952. 'identity
  5953. (append (get 'org-agenda-filter
  5954. :preset-filter)
  5955. org-agenda-filter) "") "}")
  5956. "")
  5957. (if org-agenda-archives-mode
  5958. (if (eq org-agenda-archives-mode t)
  5959. " Archives"
  5960. (format " :%s:" org-archive-tag))
  5961. "")
  5962. (if org-agenda-clockreport-mode
  5963. (if (eq org-agenda-clockreport-mode 'with-filter)
  5964. " Clock{}" " Clock")
  5965. "")))
  5966. (force-mode-line-update))
  5967. (defun org-agenda-post-command-hook ()
  5968. (setq org-agenda-type
  5969. (or (get-text-property (point) 'org-agenda-type)
  5970. (get-text-property (max (point-min) (1- (point)))
  5971. 'org-agenda-type))))
  5972. (defun org-agenda-next-line ()
  5973. "Move cursor to the next line, and show if follow mode is active."
  5974. (interactive)
  5975. (call-interactively 'next-line)
  5976. (org-agenda-do-context-action))
  5977. (defun org-agenda-previous-line ()
  5978. "Move cursor to the previous line, and show if follow-mode is active."
  5979. (interactive)
  5980. (call-interactively 'previous-line)
  5981. (org-agenda-do-context-action))
  5982. (defun org-agenda-do-context-action ()
  5983. "Show outline path and, maybe, follow mode window."
  5984. (let ((m (org-get-at-bol 'org-marker)))
  5985. (if (and org-agenda-follow-mode m)
  5986. (org-agenda-show))
  5987. (if (and m org-agenda-show-outline-path)
  5988. (org-with-point-at m
  5989. (org-display-outline-path t)))))
  5990. (defun org-agenda-show-priority ()
  5991. "Show the priority of the current item.
  5992. This priority is composed of the main priority given with the [#A] cookies,
  5993. and by additional input from the age of a schedules or deadline entry."
  5994. (interactive)
  5995. (let* ((pri (org-get-at-bol 'priority)))
  5996. (message "Priority is %d" (if pri pri -1000))))
  5997. (defun org-agenda-show-tags ()
  5998. "Show the tags applicable to the current item."
  5999. (interactive)
  6000. (let* ((tags (org-get-at-bol 'tags)))
  6001. (if tags
  6002. (message "Tags are :%s:"
  6003. (org-no-properties (mapconcat 'identity tags ":")))
  6004. (message "No tags associated with this line"))))
  6005. (defun org-agenda-goto (&optional highlight)
  6006. "Go to the Org-mode file which contains the item at point."
  6007. (interactive)
  6008. (let* ((marker (or (org-get-at-bol 'org-marker)
  6009. (org-agenda-error)))
  6010. (buffer (marker-buffer marker))
  6011. (pos (marker-position marker)))
  6012. (switch-to-buffer-other-window buffer)
  6013. (widen)
  6014. (push-mark)
  6015. (goto-char pos)
  6016. (when (org-mode-p)
  6017. (org-show-context 'agenda)
  6018. (save-excursion
  6019. (and (outline-next-heading)
  6020. (org-flag-heading nil)))) ; show the next heading
  6021. (recenter (/ (window-height) 2))
  6022. (run-hooks 'org-agenda-after-show-hook)
  6023. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6024. (defvar org-agenda-after-show-hook nil
  6025. "Normal hook run after an item has been shown from the agenda.
  6026. Point is in the buffer where the item originated.")
  6027. (defun org-agenda-kill ()
  6028. "Kill the entry or subtree belonging to the current agenda entry."
  6029. (interactive)
  6030. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6031. (let* ((marker (or (org-get-at-bol 'org-marker)
  6032. (org-agenda-error)))
  6033. (buffer (marker-buffer marker))
  6034. (pos (marker-position marker))
  6035. (type (org-get-at-bol 'type))
  6036. dbeg dend (n 0) conf)
  6037. (org-with-remote-undo buffer
  6038. (with-current-buffer buffer
  6039. (save-excursion
  6040. (goto-char pos)
  6041. (if (and (org-mode-p) (not (member type '("sexp"))))
  6042. (setq dbeg (progn (org-back-to-heading t) (point))
  6043. dend (org-end-of-subtree t t))
  6044. (setq dbeg (point-at-bol)
  6045. dend (min (point-max) (1+ (point-at-eol)))))
  6046. (goto-char dbeg)
  6047. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6048. (setq conf (or (eq t org-agenda-confirm-kill)
  6049. (and (numberp org-agenda-confirm-kill)
  6050. (> n org-agenda-confirm-kill))))
  6051. (and conf
  6052. (not (y-or-n-p
  6053. (format "Delete entry with %d lines in buffer \"%s\"? "
  6054. n (buffer-name buffer))))
  6055. (error "Abort"))
  6056. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6057. (with-current-buffer buffer (delete-region dbeg dend))
  6058. (message "Agenda item and source killed"))))
  6059. (defvar org-archive-default-command)
  6060. (defun org-agenda-archive-default ()
  6061. "Archive the entry or subtree belonging to the current agenda entry."
  6062. (interactive)
  6063. (require 'org-archive)
  6064. (org-agenda-archive-with org-archive-default-command))
  6065. (defun org-agenda-archive-default-with-confirmation ()
  6066. "Archive the entry or subtree belonging to the current agenda entry."
  6067. (interactive)
  6068. (require 'org-archive)
  6069. (org-agenda-archive-with org-archive-default-command 'confirm))
  6070. (defun org-agenda-archive ()
  6071. "Archive the entry or subtree belonging to the current agenda entry."
  6072. (interactive)
  6073. (org-agenda-archive-with 'org-archive-subtree))
  6074. (defun org-agenda-archive-to-archive-sibling ()
  6075. "Move the entry to the archive sibling."
  6076. (interactive)
  6077. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6078. (defun org-agenda-archive-with (cmd &optional confirm)
  6079. "Move the entry to the archive sibling."
  6080. (interactive)
  6081. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6082. (let* ((marker (or (org-get-at-bol 'org-marker)
  6083. (org-agenda-error)))
  6084. (buffer (marker-buffer marker))
  6085. (pos (marker-position marker)))
  6086. (org-with-remote-undo buffer
  6087. (with-current-buffer buffer
  6088. (if (org-mode-p)
  6089. (if (and confirm
  6090. (not (y-or-n-p "Archive this subtree or entry? ")))
  6091. (error "Abort")
  6092. (save-excursion
  6093. (goto-char pos)
  6094. (org-remove-subtree-entries-from-agenda)
  6095. (org-back-to-heading t)
  6096. (funcall cmd)))
  6097. (error "Archiving works only in Org-mode files"))))))
  6098. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6099. "Remove all lines in the agenda that correspond to a given subtree.
  6100. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6101. If this information is not given, the function uses the tree at point."
  6102. (let ((buf (or buf (current-buffer))) m p)
  6103. (save-excursion
  6104. (unless (and beg end)
  6105. (org-back-to-heading t)
  6106. (setq beg (point))
  6107. (org-end-of-subtree t)
  6108. (setq end (point)))
  6109. (set-buffer (get-buffer org-agenda-buffer-name))
  6110. (save-excursion
  6111. (goto-char (point-max))
  6112. (beginning-of-line 1)
  6113. (while (not (bobp))
  6114. (when (and (setq m (org-get-at-bol 'org-marker))
  6115. (equal buf (marker-buffer m))
  6116. (setq p (marker-position m))
  6117. (>= p beg)
  6118. (< p end))
  6119. (let ((inhibit-read-only t))
  6120. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6121. (beginning-of-line 0))))))
  6122. (defun org-agenda-refile (&optional goto rfloc no-update)
  6123. "Refile the item at point."
  6124. (interactive "P")
  6125. (if (equal goto '(16))
  6126. (org-refile-goto-last-stored)
  6127. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6128. (org-agenda-error)))
  6129. (buffer (marker-buffer marker))
  6130. (pos (marker-position marker))
  6131. (rfloc (or rfloc
  6132. (org-refile-get-location
  6133. (if goto "Goto: " "Refile to: ") buffer
  6134. org-refile-allow-creating-parent-nodes))))
  6135. (with-current-buffer buffer
  6136. (save-excursion
  6137. (save-restriction
  6138. (widen)
  6139. (goto-char marker)
  6140. (org-remove-subtree-entries-from-agenda)
  6141. (org-refile goto buffer rfloc)))))
  6142. (unless no-update (org-agenda-redo))))
  6143. (defun org-agenda-open-link (&optional arg)
  6144. "Follow the link in the current line, if any.
  6145. This looks for a link in the displayed line in the agenda. It also looks
  6146. at the text of the entry itself."
  6147. (interactive "P")
  6148. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6149. (org-get-at-bol 'org-marker)))
  6150. (buffer (and marker (marker-buffer marker)))
  6151. (prefix (buffer-substring
  6152. (point-at-bol)
  6153. (+ (point-at-bol)
  6154. (or (org-get-at-bol 'prefix-length) 0)))))
  6155. (cond
  6156. (buffer
  6157. (with-current-buffer buffer
  6158. (save-excursion
  6159. (save-restriction
  6160. (widen)
  6161. (goto-char marker)
  6162. (org-offer-links-in-entry arg prefix)))))
  6163. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6164. (save-excursion
  6165. (beginning-of-line 1)
  6166. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6167. (org-open-link-from-string (match-string 1)))
  6168. (t (error "No link to open here")))))
  6169. (defun org-agenda-copy-local-variable (var)
  6170. "Get a variable from a referenced buffer and install it here."
  6171. (let ((m (org-get-at-bol 'org-marker)))
  6172. (when (and m (buffer-live-p (marker-buffer m)))
  6173. (org-set-local var (with-current-buffer (marker-buffer m)
  6174. (symbol-value var))))))
  6175. (defun org-agenda-switch-to (&optional delete-other-windows)
  6176. "Go to the Org-mode file which contains the item at point."
  6177. (interactive)
  6178. (if (and org-return-follows-link
  6179. (not (org-get-at-bol 'org-marker))
  6180. (org-in-regexp org-bracket-link-regexp))
  6181. (org-open-link-from-string (match-string 0))
  6182. (let* ((marker (or (org-get-at-bol 'org-marker)
  6183. (org-agenda-error)))
  6184. (buffer (marker-buffer marker))
  6185. (pos (marker-position marker)))
  6186. (switch-to-buffer buffer)
  6187. (and delete-other-windows (delete-other-windows))
  6188. (widen)
  6189. (goto-char pos)
  6190. (when (org-mode-p)
  6191. (org-show-context 'agenda)
  6192. (save-excursion
  6193. (and (outline-next-heading)
  6194. (org-flag-heading nil))))))) ; show the next heading
  6195. (defun org-agenda-goto-mouse (ev)
  6196. "Go to the Org-mode file which contains the item at the mouse click."
  6197. (interactive "e")
  6198. (mouse-set-point ev)
  6199. (org-agenda-goto))
  6200. (defun org-agenda-show (&optional full-entry)
  6201. "Display the Org-mode file which contains the item at point.
  6202. With prefix argument FULL-ENTRY, make the entire entry visible
  6203. if it was hidden in the outline."
  6204. (interactive "P")
  6205. (let ((win (selected-window)))
  6206. (if full-entry
  6207. (let ((org-show-entry-below t))
  6208. (org-agenda-goto t))
  6209. (org-agenda-goto t))
  6210. (select-window win)))
  6211. (defvar org-agenda-show-window nil)
  6212. (defun org-agenda-show-and-scroll-up ()
  6213. "Display the Org-mode file which contains the item at point.
  6214. When called repeatedly, scroll the window that is displaying the buffer."
  6215. (interactive)
  6216. (let ((win (selected-window)))
  6217. (if (and (window-live-p org-agenda-show-window)
  6218. (eq this-command last-command))
  6219. (progn
  6220. (select-window org-agenda-show-window)
  6221. (ignore-errors (scroll-up)))
  6222. (org-agenda-goto t)
  6223. (show-subtree)
  6224. (setq org-agenda-show-window (selected-window)))
  6225. (select-window win)))
  6226. (defun org-agenda-show-scroll-down ()
  6227. "Scroll down the window showing the agenda."
  6228. (interactive)
  6229. (let ((win (selected-window)))
  6230. (when (window-live-p org-agenda-show-window)
  6231. (select-window org-agenda-show-window)
  6232. (ignore-errors (scroll-down))
  6233. (select-window win))))
  6234. (defun org-agenda-show-1 (&optional more)
  6235. "Display the Org-mode file which contains the item at point.
  6236. The prefix arg selects the amount of information to display:
  6237. 0 hide the subtree
  6238. 1 just show the entry according to defaults.
  6239. 2 show the children view
  6240. 3 show the subtree view
  6241. 4 show the entire subtree and any LOGBOOK drawers
  6242. 5 show the entire subtree and any drawers
  6243. With prefix argument FULL-ENTRY, make the entire entry visible
  6244. if it was hidden in the outline."
  6245. (interactive "p")
  6246. (let ((win (selected-window)))
  6247. (org-agenda-goto t)
  6248. (org-recenter-heading 1)
  6249. (cond
  6250. ((= more 0)
  6251. (hide-subtree)
  6252. (save-excursion
  6253. (org-back-to-heading)
  6254. (run-hook-with-args 'org-cycle-hook 'folded))
  6255. (message "Remote: FOLDED"))
  6256. ((and (interactive-p) (= more 1))
  6257. (message "Remote: show with default settings"))
  6258. ((= more 2)
  6259. (show-entry)
  6260. (show-children)
  6261. (save-excursion
  6262. (org-back-to-heading)
  6263. (run-hook-with-args 'org-cycle-hook 'children))
  6264. (message "Remote: CHILDREN"))
  6265. ((= more 3)
  6266. (show-subtree)
  6267. (save-excursion
  6268. (org-back-to-heading)
  6269. (run-hook-with-args 'org-cycle-hook 'subtree))
  6270. (message "Remote: SUBTREE"))
  6271. ((= more 4)
  6272. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6273. (org-drawer-regexp
  6274. (concat "^[ \t]*:\\("
  6275. (mapconcat 'regexp-quote org-drawers "\\|")
  6276. "\\):[ \t]*$")))
  6277. (show-subtree)
  6278. (save-excursion
  6279. (org-back-to-heading)
  6280. (org-cycle-hide-drawers 'subtree)))
  6281. (message "Remote: SUBTREE AND LOGBOOK"))
  6282. ((> more 4)
  6283. (show-subtree)
  6284. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6285. (select-window win)))
  6286. (defun org-recenter-heading (n)
  6287. (save-excursion
  6288. (org-back-to-heading)
  6289. (recenter n)))
  6290. (defvar org-agenda-cycle-counter nil)
  6291. (defun org-agenda-cycle-show (&optional n)
  6292. "Show the current entry in another window, with default settings.
  6293. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6294. When use repeatedly in immediate succession, the remote entry will cycle
  6295. through visibility
  6296. children -> subtree -> folded
  6297. When called with a numeric prefix arg, that arg will be passed through to
  6298. `org-agenda-show-1'. For the interpretation of that argument, see the
  6299. docstring of `org-agenda-show-1'."
  6300. (interactive "P")
  6301. (if (integerp n)
  6302. (setq org-agenda-cycle-counter n)
  6303. (if (not (eq last-command this-command))
  6304. (setq org-agenda-cycle-counter 1)
  6305. (if (equal org-agenda-cycle-counter 0)
  6306. (setq org-agenda-cycle-counter 2)
  6307. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6308. (if (> org-agenda-cycle-counter 3)
  6309. (setq org-agenda-cycle-counter 0)))))
  6310. (org-agenda-show-1 org-agenda-cycle-counter))
  6311. (defun org-agenda-recenter (arg)
  6312. "Display the Org-mode file which contains the item at point and recenter."
  6313. (interactive "P")
  6314. (let ((win (selected-window)))
  6315. (org-agenda-goto t)
  6316. (recenter arg)
  6317. (select-window win)))
  6318. (defun org-agenda-show-mouse (ev)
  6319. "Display the Org-mode file which contains the item at the mouse click."
  6320. (interactive "e")
  6321. (mouse-set-point ev)
  6322. (org-agenda-show))
  6323. (defun org-agenda-check-no-diary ()
  6324. "Check if the entry is a diary link and abort if yes."
  6325. (if (org-get-at-bol 'org-agenda-diary-link)
  6326. (org-agenda-error)))
  6327. (defun org-agenda-error ()
  6328. (error "Command not allowed in this line"))
  6329. (defun org-agenda-tree-to-indirect-buffer ()
  6330. "Show the subtree corresponding to the current entry in an indirect buffer.
  6331. This calls the command `org-tree-to-indirect-buffer' from the original
  6332. Org-mode buffer.
  6333. With numerical prefix arg ARG, go up to this level and then take that tree.
  6334. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6335. use the dedicated frame)."
  6336. (interactive)
  6337. (org-agenda-check-no-diary)
  6338. (let* ((marker (or (org-get-at-bol 'org-marker)
  6339. (org-agenda-error)))
  6340. (buffer (marker-buffer marker))
  6341. (pos (marker-position marker)))
  6342. (with-current-buffer buffer
  6343. (save-excursion
  6344. (goto-char pos)
  6345. (call-interactively 'org-tree-to-indirect-buffer)))))
  6346. (defvar org-last-heading-marker (make-marker)
  6347. "Marker pointing to the headline that last changed its TODO state
  6348. by a remote command from the agenda.")
  6349. (defun org-agenda-todo-nextset ()
  6350. "Switch TODO entry to next sequence."
  6351. (interactive)
  6352. (org-agenda-todo 'nextset))
  6353. (defun org-agenda-todo-previousset ()
  6354. "Switch TODO entry to previous sequence."
  6355. (interactive)
  6356. (org-agenda-todo 'previousset))
  6357. (defun org-agenda-todo (&optional arg)
  6358. "Cycle TODO state of line at point, also in Org-mode file.
  6359. This changes the line at point, all other lines in the agenda referring to
  6360. the same tree node, and the headline of the tree node in the Org-mode file."
  6361. (interactive "P")
  6362. (org-agenda-check-no-diary)
  6363. (let* ((col (current-column))
  6364. (marker (or (org-get-at-bol 'org-marker)
  6365. (org-agenda-error)))
  6366. (buffer (marker-buffer marker))
  6367. (pos (marker-position marker))
  6368. (hdmarker (org-get-at-bol 'org-hd-marker))
  6369. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6370. (inhibit-read-only t)
  6371. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6372. (org-with-remote-undo buffer
  6373. (with-current-buffer buffer
  6374. (widen)
  6375. (goto-char pos)
  6376. (org-show-context 'agenda)
  6377. (save-excursion
  6378. (and (outline-next-heading)
  6379. (org-flag-heading nil))) ; show the next heading
  6380. (let ((current-prefix-arg arg))
  6381. (call-interactively 'org-todo))
  6382. (and (bolp) (forward-char 1))
  6383. (setq newhead (org-get-heading))
  6384. (when (and (org-bound-and-true-p
  6385. org-agenda-headline-snapshot-before-repeat)
  6386. (not (equal org-agenda-headline-snapshot-before-repeat
  6387. newhead))
  6388. todayp)
  6389. (setq newhead org-agenda-headline-snapshot-before-repeat
  6390. just-one t))
  6391. (save-excursion
  6392. (org-back-to-heading)
  6393. (move-marker org-last-heading-marker (point))))
  6394. (beginning-of-line 1)
  6395. (save-excursion
  6396. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6397. (org-move-to-column col))))
  6398. (defun org-agenda-add-note (&optional arg)
  6399. "Add a time-stamped note to the entry at point."
  6400. (interactive "P")
  6401. (org-agenda-check-no-diary)
  6402. (let* ((marker (or (org-get-at-bol 'org-marker)
  6403. (org-agenda-error)))
  6404. (buffer (marker-buffer marker))
  6405. (pos (marker-position marker))
  6406. (hdmarker (org-get-at-bol 'org-hd-marker))
  6407. (inhibit-read-only t))
  6408. (with-current-buffer buffer
  6409. (widen)
  6410. (goto-char pos)
  6411. (org-show-context 'agenda)
  6412. (save-excursion
  6413. (and (outline-next-heading)
  6414. (org-flag-heading nil))) ; show the next heading
  6415. (org-add-note))))
  6416. (defun org-agenda-change-all-lines (newhead hdmarker
  6417. &optional fixface just-this)
  6418. "Change all lines in the agenda buffer which match HDMARKER.
  6419. The new content of the line will be NEWHEAD (as modified by
  6420. `org-format-agenda-item'). HDMARKER is checked with
  6421. `equal' against all `org-hd-marker' text properties in the file.
  6422. If FIXFACE is non-nil, the face of each item is modified according to
  6423. the new TODO state.
  6424. If JUST-THIS is non-nil, change just the current line, not all.
  6425. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6426. (let* ((inhibit-read-only t)
  6427. (line (org-current-line))
  6428. (thetags (with-current-buffer (marker-buffer hdmarker)
  6429. (save-excursion (save-restriction (widen)
  6430. (goto-char hdmarker)
  6431. (org-get-tags-at)))))
  6432. props m pl undone-face done-face finish new dotime cat tags)
  6433. (save-excursion
  6434. (goto-char (point-max))
  6435. (beginning-of-line 1)
  6436. (while (not finish)
  6437. (setq finish (bobp))
  6438. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6439. (or (not just-this) (= (org-current-line) line))
  6440. (equal m hdmarker))
  6441. (setq props (text-properties-at (point))
  6442. dotime (org-get-at-bol 'dotime)
  6443. cat (org-get-at-bol 'org-category)
  6444. tags thetags
  6445. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6446. pl (org-get-at-bol 'prefix-length)
  6447. undone-face (org-get-at-bol 'undone-face)
  6448. done-face (org-get-at-bol 'done-face))
  6449. (goto-char (+ (point) pl))
  6450. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6451. (cond
  6452. ((equal new "")
  6453. (beginning-of-line 1)
  6454. (and (looking-at ".*\n?") (replace-match "")))
  6455. ((looking-at ".*")
  6456. (replace-match new t t)
  6457. (beginning-of-line 1)
  6458. (add-text-properties (point-at-bol) (point-at-eol) props)
  6459. (when fixface
  6460. (add-text-properties
  6461. (point-at-bol) (point-at-eol)
  6462. (list 'face
  6463. (if org-last-todo-state-is-todo
  6464. undone-face done-face))))
  6465. (org-agenda-highlight-todo 'line)
  6466. (beginning-of-line 1))
  6467. (t (error "Line update did not work"))))
  6468. (beginning-of-line 0)))
  6469. (org-finalize-agenda)))
  6470. (defun org-agenda-align-tags (&optional line)
  6471. "Align all tags in agenda items to `org-agenda-tags-column'."
  6472. (let ((inhibit-read-only t) l c)
  6473. (save-excursion
  6474. (goto-char (if line (point-at-bol) (point-min)))
  6475. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6476. (if line (point-at-eol) nil) t)
  6477. (add-text-properties
  6478. (match-beginning 2) (match-end 2)
  6479. (list 'face (delq nil (let ((prop (get-text-property
  6480. (match-beginning 2) 'face)))
  6481. (or (listp prop) (setq prop (list prop)))
  6482. (if (memq 'org-tag prop)
  6483. prop
  6484. (cons 'org-tag prop))))))
  6485. (setq l (- (match-end 2) (match-beginning 2))
  6486. c (if (< org-agenda-tags-column 0)
  6487. (- (abs org-agenda-tags-column) l)
  6488. org-agenda-tags-column))
  6489. (delete-region (match-beginning 1) (match-end 1))
  6490. (goto-char (match-beginning 1))
  6491. (insert (org-add-props
  6492. (make-string (max 1 (- c (current-column))) ?\ )
  6493. (plist-put (copy-sequence (text-properties-at (point)))
  6494. 'face nil))))
  6495. (goto-char (point-min))
  6496. (org-font-lock-add-tag-faces (point-max)))))
  6497. (defun org-agenda-priority-up ()
  6498. "Increase the priority of line at point, also in Org-mode file."
  6499. (interactive)
  6500. (org-agenda-priority 'up))
  6501. (defun org-agenda-priority-down ()
  6502. "Decrease the priority of line at point, also in Org-mode file."
  6503. (interactive)
  6504. (org-agenda-priority 'down))
  6505. (defun org-agenda-priority (&optional force-direction)
  6506. "Set the priority of line at point, also in Org-mode file.
  6507. This changes the line at point, all other lines in the agenda referring to
  6508. the same tree node, and the headline of the tree node in the Org-mode file."
  6509. (interactive)
  6510. (unless org-enable-priority-commands
  6511. (error "Priority commands are disabled"))
  6512. (org-agenda-check-no-diary)
  6513. (let* ((marker (or (org-get-at-bol 'org-marker)
  6514. (org-agenda-error)))
  6515. (hdmarker (org-get-at-bol 'org-hd-marker))
  6516. (buffer (marker-buffer hdmarker))
  6517. (pos (marker-position hdmarker))
  6518. (inhibit-read-only t)
  6519. newhead)
  6520. (org-with-remote-undo buffer
  6521. (with-current-buffer buffer
  6522. (widen)
  6523. (goto-char pos)
  6524. (org-show-context 'agenda)
  6525. (save-excursion
  6526. (and (outline-next-heading)
  6527. (org-flag-heading nil))) ; show the next heading
  6528. (funcall 'org-priority force-direction)
  6529. (end-of-line 1)
  6530. (setq newhead (org-get-heading)))
  6531. (org-agenda-change-all-lines newhead hdmarker)
  6532. (beginning-of-line 1))))
  6533. ;; FIXME: should fix the tags property of the agenda line.
  6534. (defun org-agenda-set-tags (&optional tag onoff)
  6535. "Set tags for the current headline."
  6536. (interactive)
  6537. (org-agenda-check-no-diary)
  6538. (if (and (org-region-active-p) (interactive-p))
  6539. (call-interactively 'org-change-tag-in-region)
  6540. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6541. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6542. (org-agenda-error)))
  6543. (buffer (marker-buffer hdmarker))
  6544. (pos (marker-position hdmarker))
  6545. (inhibit-read-only t)
  6546. newhead)
  6547. (org-with-remote-undo buffer
  6548. (with-current-buffer buffer
  6549. (widen)
  6550. (goto-char pos)
  6551. (save-excursion
  6552. (org-show-context 'agenda))
  6553. (save-excursion
  6554. (and (outline-next-heading)
  6555. (org-flag-heading nil))) ; show the next heading
  6556. (goto-char pos)
  6557. (if tag
  6558. (org-toggle-tag tag onoff)
  6559. (call-interactively 'org-set-tags))
  6560. (end-of-line 1)
  6561. (setq newhead (org-get-heading)))
  6562. (org-agenda-change-all-lines newhead hdmarker)
  6563. (beginning-of-line 1)))))
  6564. (defun org-agenda-set-property ()
  6565. "Set a property for the current headline."
  6566. (interactive)
  6567. (org-agenda-check-no-diary)
  6568. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6569. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6570. (org-agenda-error)))
  6571. (buffer (marker-buffer hdmarker))
  6572. (pos (marker-position hdmarker))
  6573. (inhibit-read-only t)
  6574. newhead)
  6575. (org-with-remote-undo buffer
  6576. (with-current-buffer buffer
  6577. (widen)
  6578. (goto-char pos)
  6579. (save-excursion
  6580. (org-show-context 'agenda))
  6581. (save-excursion
  6582. (and (outline-next-heading)
  6583. (org-flag-heading nil))) ; show the next heading
  6584. (goto-char pos)
  6585. (call-interactively 'org-set-property)))))
  6586. (defun org-agenda-set-effort ()
  6587. "Set the effort property for the current headline."
  6588. (interactive)
  6589. (org-agenda-check-no-diary)
  6590. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6591. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6592. (org-agenda-error)))
  6593. (buffer (marker-buffer hdmarker))
  6594. (pos (marker-position hdmarker))
  6595. (inhibit-read-only t)
  6596. newhead)
  6597. (org-with-remote-undo buffer
  6598. (with-current-buffer buffer
  6599. (widen)
  6600. (goto-char pos)
  6601. (save-excursion
  6602. (org-show-context 'agenda))
  6603. (save-excursion
  6604. (and (outline-next-heading)
  6605. (org-flag-heading nil))) ; show the next heading
  6606. (goto-char pos)
  6607. (call-interactively 'org-set-effort)
  6608. (end-of-line 1)))))
  6609. (defun org-agenda-toggle-archive-tag ()
  6610. "Toggle the archive tag for the current entry."
  6611. (interactive)
  6612. (org-agenda-check-no-diary)
  6613. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6614. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6615. (org-agenda-error)))
  6616. (buffer (marker-buffer hdmarker))
  6617. (pos (marker-position hdmarker))
  6618. (inhibit-read-only t)
  6619. newhead)
  6620. (org-with-remote-undo buffer
  6621. (with-current-buffer buffer
  6622. (widen)
  6623. (goto-char pos)
  6624. (org-show-context 'agenda)
  6625. (save-excursion
  6626. (and (outline-next-heading)
  6627. (org-flag-heading nil))) ; show the next heading
  6628. (call-interactively 'org-toggle-archive-tag)
  6629. (end-of-line 1)
  6630. (setq newhead (org-get-heading)))
  6631. (org-agenda-change-all-lines newhead hdmarker)
  6632. (beginning-of-line 1))))
  6633. (defun org-agenda-do-date-later (arg)
  6634. (interactive "P")
  6635. (cond
  6636. ((or (equal arg '(16))
  6637. (memq last-command
  6638. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6639. (setq this-command 'org-agenda-date-later-minutes)
  6640. (org-agenda-date-later-minutes 1))
  6641. ((or (equal arg '(4))
  6642. (memq last-command
  6643. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6644. (setq this-command 'org-agenda-date-later-hours)
  6645. (org-agenda-date-later-hours 1))
  6646. (t
  6647. (org-agenda-date-later (prefix-numeric-value arg)))))
  6648. (defun org-agenda-do-date-earlier (arg)
  6649. (interactive "P")
  6650. (cond
  6651. ((or (equal arg '(16))
  6652. (memq last-command
  6653. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6654. (setq this-command 'org-agenda-date-earlier-minutes)
  6655. (org-agenda-date-earlier-minutes 1))
  6656. ((or (equal arg '(4))
  6657. (memq last-command
  6658. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6659. (setq this-command 'org-agenda-date-earlier-hours)
  6660. (org-agenda-date-earlier-hours 1))
  6661. (t
  6662. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6663. (defun org-agenda-date-later (arg &optional what)
  6664. "Change the date of this item to one day later."
  6665. (interactive "p")
  6666. (org-agenda-check-type t 'agenda 'timeline)
  6667. (org-agenda-check-no-diary)
  6668. (let* ((marker (or (org-get-at-bol 'org-marker)
  6669. (org-agenda-error)))
  6670. (buffer (marker-buffer marker))
  6671. (pos (marker-position marker)))
  6672. (org-with-remote-undo buffer
  6673. (with-current-buffer buffer
  6674. (widen)
  6675. (goto-char pos)
  6676. (if (not (org-at-timestamp-p))
  6677. (error "Cannot find time stamp"))
  6678. (org-timestamp-change arg (or what 'day)))
  6679. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6680. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6681. (defun org-agenda-date-earlier (arg &optional what)
  6682. "Change the date of this item to one day earlier."
  6683. (interactive "p")
  6684. (org-agenda-date-later (- arg) what))
  6685. (defun org-agenda-date-later-minutes (arg)
  6686. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6687. (interactive "p")
  6688. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6689. (org-agenda-date-later arg 'minute))
  6690. (defun org-agenda-date-earlier-minutes (arg)
  6691. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6692. (interactive "p")
  6693. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6694. (org-agenda-date-earlier arg 'minute))
  6695. (defun org-agenda-date-later-hours (arg)
  6696. "Change the time of this item, in hour steps."
  6697. (interactive "p")
  6698. (org-agenda-date-later arg 'hour))
  6699. (defun org-agenda-date-earlier-hours (arg)
  6700. "Change the time of this item, in hour steps."
  6701. (interactive "p")
  6702. (org-agenda-date-earlier arg 'hour))
  6703. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6704. "Show new date stamp via text properties."
  6705. ;; We use text properties to make this undoable
  6706. (let ((inhibit-read-only t)
  6707. (buffer-invisibility-spec))
  6708. (setq stamp (concat " " prefix " => " stamp))
  6709. (save-excursion
  6710. (goto-char (point-max))
  6711. (while (not (bobp))
  6712. (when (equal marker (org-get-at-bol 'org-marker))
  6713. (org-move-to-column (- (window-width) (length stamp)) t)
  6714. (org-agenda-fix-tags-filter-overlays-at (point))
  6715. (if (featurep 'xemacs)
  6716. ;; Use `duplicable' property to trigger undo recording
  6717. (let ((ex (make-extent nil nil))
  6718. (gl (make-glyph stamp)))
  6719. (set-glyph-face gl 'secondary-selection)
  6720. (set-extent-properties
  6721. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6722. (insert-extent ex (1- (point)) (point-at-eol)))
  6723. (add-text-properties
  6724. (1- (point)) (point-at-eol)
  6725. (list 'display (org-add-props stamp nil
  6726. 'face 'secondary-selection))))
  6727. (beginning-of-line 1))
  6728. (beginning-of-line 0)))))
  6729. (defun org-agenda-date-prompt (arg)
  6730. "Change the date of this item. Date is prompted for, with default today.
  6731. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6732. be used to request time specification in the time stamp."
  6733. (interactive "P")
  6734. (org-agenda-check-type t 'agenda 'timeline)
  6735. (org-agenda-check-no-diary)
  6736. (let* ((marker (or (org-get-at-bol 'org-marker)
  6737. (org-agenda-error)))
  6738. (buffer (marker-buffer marker))
  6739. (pos (marker-position marker)))
  6740. (org-with-remote-undo buffer
  6741. (with-current-buffer buffer
  6742. (widen)
  6743. (goto-char pos)
  6744. (if (not (org-at-timestamp-p t))
  6745. (error "Cannot find time stamp"))
  6746. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6747. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6748. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6749. (defun org-agenda-schedule (arg &optional time)
  6750. "Schedule the item at point.
  6751. Arg is passed through to `org-schedule'."
  6752. (interactive "P")
  6753. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6754. (org-agenda-check-no-diary)
  6755. (let* ((marker (or (org-get-at-bol 'org-marker)
  6756. (org-agenda-error)))
  6757. (type (marker-insertion-type marker))
  6758. (buffer (marker-buffer marker))
  6759. (pos (marker-position marker))
  6760. (org-insert-labeled-timestamps-at-point nil)
  6761. ts)
  6762. (set-marker-insertion-type marker t)
  6763. (org-with-remote-undo buffer
  6764. (with-current-buffer buffer
  6765. (widen)
  6766. (goto-char pos)
  6767. (setq ts (org-schedule arg time)))
  6768. (org-agenda-show-new-time marker ts "S"))
  6769. (message "Item scheduled for %s" ts)))
  6770. (defun org-agenda-deadline (arg &optional time)
  6771. "Schedule the item at point.
  6772. Arg is passed through to `org-deadline'."
  6773. (interactive "P")
  6774. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6775. (org-agenda-check-no-diary)
  6776. (let* ((marker (or (org-get-at-bol 'org-marker)
  6777. (org-agenda-error)))
  6778. (buffer (marker-buffer marker))
  6779. (pos (marker-position marker))
  6780. (org-insert-labeled-timestamps-at-point nil)
  6781. ts)
  6782. (org-with-remote-undo buffer
  6783. (with-current-buffer buffer
  6784. (widen)
  6785. (goto-char pos)
  6786. (setq ts (org-deadline arg time)))
  6787. (org-agenda-show-new-time marker ts "D"))
  6788. (message "Deadline for this item set to %s" ts)))
  6789. (defun org-agenda-action ()
  6790. "Select entry for agenda action, or execute an agenda action.
  6791. This command prompts for another letter. Valid inputs are:
  6792. m Mark the entry at point for an agenda action
  6793. s Schedule the marked entry to the date at the cursor
  6794. d Set the deadline of the marked entry to the date at the cursor
  6795. r Call `org-remember' with cursor date as the default date
  6796. c Call `org-capture' with cursor date as the default date
  6797. SPC Show marked entry in other window
  6798. TAB Visit marked entry in other window
  6799. The cursor may be at a date in the calendar, or in the Org agenda."
  6800. (interactive)
  6801. (let (ans)
  6802. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6803. (setq ans (read-char-exclusive))
  6804. (cond
  6805. ((equal ans ?m)
  6806. ;; Mark this entry
  6807. (if (eq major-mode 'org-agenda-mode)
  6808. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6809. (org-get-at-bol 'org-marker))))
  6810. (if m
  6811. (progn
  6812. (move-marker org-agenda-action-marker
  6813. (marker-position m) (marker-buffer m))
  6814. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6815. (error "Don't know which entry to mark")))
  6816. (error "This command works only in the agenda")))
  6817. ((equal ans ?s)
  6818. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6819. ((equal ans ?d)
  6820. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6821. ((equal ans ?r)
  6822. (org-agenda-do-action '(org-remember) t))
  6823. ((equal ans ?c)
  6824. (org-agenda-do-action '(org-capture) t))
  6825. ((equal ans ?\ )
  6826. (let ((cw (selected-window)))
  6827. (org-switch-to-buffer-other-window
  6828. (marker-buffer org-agenda-action-marker))
  6829. (goto-char org-agenda-action-marker)
  6830. (org-show-context 'agenda)
  6831. (select-window cw)))
  6832. ((equal ans ?\C-i)
  6833. (org-switch-to-buffer-other-window
  6834. (marker-buffer org-agenda-action-marker))
  6835. (goto-char org-agenda-action-marker)
  6836. (org-show-context 'agenda))
  6837. (t (error "Invalid agenda action %c" ans)))))
  6838. (defun org-agenda-do-action (form &optional current-buffer)
  6839. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6840. (let ((org-overriding-default-time (org-get-cursor-date)))
  6841. (if current-buffer
  6842. (eval form)
  6843. (if (not (marker-buffer org-agenda-action-marker))
  6844. (error "No entry has been selected for agenda action")
  6845. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6846. (save-excursion
  6847. (save-restriction
  6848. (widen)
  6849. (goto-char org-agenda-action-marker)
  6850. (eval form))))))))
  6851. (defun org-agenda-clock-in (&optional arg)
  6852. "Start the clock on the currently selected item."
  6853. (interactive "P")
  6854. (org-agenda-check-no-diary)
  6855. (if (equal arg '(4))
  6856. (org-clock-in arg)
  6857. (let* ((marker (or (org-get-at-bol 'org-marker)
  6858. (org-agenda-error)))
  6859. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6860. marker))
  6861. (pos (marker-position marker))
  6862. newhead)
  6863. (org-with-remote-undo (marker-buffer marker)
  6864. (with-current-buffer (marker-buffer marker)
  6865. (widen)
  6866. (goto-char pos)
  6867. (org-show-context 'agenda)
  6868. (org-show-entry)
  6869. (org-cycle-hide-drawers 'children)
  6870. (org-clock-in arg)
  6871. (setq newhead (org-get-heading)))
  6872. (org-agenda-change-all-lines newhead hdmarker)))))
  6873. (defun org-agenda-clock-out ()
  6874. "Stop the currently running clock."
  6875. (interactive)
  6876. (unless (marker-buffer org-clock-marker)
  6877. (error "No running clock"))
  6878. (let ((marker (make-marker)) newhead)
  6879. (org-with-remote-undo (marker-buffer org-clock-marker)
  6880. (with-current-buffer (marker-buffer org-clock-marker)
  6881. (save-excursion
  6882. (save-restriction
  6883. (widen)
  6884. (goto-char org-clock-marker)
  6885. (org-back-to-heading t)
  6886. (move-marker marker (point))
  6887. (org-clock-out)
  6888. (setq newhead (org-get-heading))))))
  6889. (org-agenda-change-all-lines newhead marker)
  6890. (move-marker marker nil)))
  6891. (defun org-agenda-clock-cancel (&optional arg)
  6892. "Cancel the currently running clock."
  6893. (interactive "P")
  6894. (unless (marker-buffer org-clock-marker)
  6895. (error "No running clock"))
  6896. (org-with-remote-undo (marker-buffer org-clock-marker)
  6897. (org-clock-cancel)))
  6898. (defun org-agenda-clock-goto ()
  6899. "Jump to the currently clocked in task within the agenda.
  6900. If the currently clocked in task is not listed in the agenda
  6901. buffer, display it in another window."
  6902. (interactive)
  6903. (let (pos)
  6904. (mapc (lambda (o)
  6905. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6906. (setq pos (overlay-start o))))
  6907. (overlays-in (point-min) (point-max)))
  6908. (cond (pos (goto-char pos))
  6909. ;; If the currently clocked entry is not in the agenda
  6910. ;; buffer, we visit it in another window:
  6911. (org-clock-current-task
  6912. (org-switch-to-buffer-other-window (org-clock-goto)))
  6913. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6914. (defun org-agenda-diary-entry-in-org-file ()
  6915. "Make a diary entry in the file `org-agenda-diary-file'."
  6916. (let (d1 d2 char (text "") dp1 dp2)
  6917. (if (equal (buffer-name) "*Calendar*")
  6918. (setq d1 (calendar-cursor-to-date t)
  6919. d2 (car calendar-mark-ring))
  6920. (setq dp1 (get-text-property (point-at-bol) 'day))
  6921. (unless dp1 (error "No date defined in current line"))
  6922. (setq d1 (calendar-gregorian-from-absolute dp1)
  6923. d2 (and (ignore-errors (mark))
  6924. (save-excursion
  6925. (goto-char (mark))
  6926. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6927. (calendar-gregorian-from-absolute dp2))))
  6928. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6929. (setq char (read-char-exclusive))
  6930. (cond
  6931. ((equal char ?d)
  6932. (setq text (read-string "Day entry: "))
  6933. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6934. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6935. ((equal char ?a)
  6936. (setq d1 (list (car d1) (nth 1 d1)
  6937. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6938. (nth 2 d1))))
  6939. (setq text (read-string "Anniversary (use %d to show years): "))
  6940. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6941. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6942. ((equal char ?b)
  6943. (setq text (read-string "Block entry: "))
  6944. (unless (and d1 d2 (not (equal d1 d2)))
  6945. (error "No block of days selected"))
  6946. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6947. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6948. ((equal char ?j)
  6949. (org-switch-to-buffer-other-window
  6950. (find-file-noselect org-agenda-diary-file))
  6951. (require 'org-datetree)
  6952. (org-datetree-find-date-create d1)
  6953. (org-reveal t))
  6954. (t (error "Invalid selection character `%c'" char)))))
  6955. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6956. "Where in `org-agenda-diary-file' should new entries be added?
  6957. Valid values:
  6958. date-tree in the date tree, as child of the date
  6959. top-level as top-level entries at the end of the file."
  6960. :group 'org-agenda
  6961. :type '(choice
  6962. (const :tag "in a date tree" date-tree)
  6963. (const :tag "as top level at end of file" top-level)))
  6964. (defcustom org-agenda-insert-diary-extract-time nil
  6965. "Non-nil means extract any time specification from the diary entry."
  6966. :group 'org-agenda
  6967. :type 'boolean)
  6968. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6969. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6970. If TEXT is not empty, it will become the headline of the new entry, and
  6971. the resulting entry will not be shown. When TEXT is empty, switch to
  6972. `org-agenda-diary-file' and let the user finish the entry there."
  6973. (let ((cw (current-window-configuration)))
  6974. (org-switch-to-buffer-other-window
  6975. (find-file-noselect org-agenda-diary-file))
  6976. (widen)
  6977. (goto-char (point-min))
  6978. (cond
  6979. ((eq type 'anniversary)
  6980. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6981. (progn
  6982. (or (org-on-heading-p t)
  6983. (progn
  6984. (outline-next-heading)
  6985. (insert "* Anniversaries\n\n")
  6986. (beginning-of-line -1)))))
  6987. (outline-next-heading)
  6988. (org-back-over-empty-lines)
  6989. (backward-char 1)
  6990. (insert "\n")
  6991. (require 'diary-lib)
  6992. (let ((calendar-date-display-form
  6993. (if (if (boundp 'calendar-date-style)
  6994. (eq calendar-date-style 'european)
  6995. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  6996. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  6997. '(day " " month " " year)
  6998. '(month " " day " " year))))
  6999. (insert (format "%%%%(diary-anniversary %s) %s"
  7000. (calendar-date-string d1 nil t) text))))
  7001. ((eq type 'day)
  7002. (let ((org-prefix-has-time t)
  7003. (org-agenda-time-leading-zero t)
  7004. fmt time time2)
  7005. (if org-agenda-insert-diary-extract-time
  7006. ;; Use org-format-agenda-item to parse text for a time-range and
  7007. ;; remove it. FIXME: This is a hack, we should refactor
  7008. ;; that function to make time extraction available separately
  7009. (setq fmt (org-format-agenda-item nil text nil nil t)
  7010. time (get-text-property 0 'time fmt)
  7011. time2 (if (> (length time) 0)
  7012. ;; split-string removes trailing ...... if
  7013. ;; no end time given. First space
  7014. ;; separates time from date.
  7015. (concat " " (car (split-string time "\\.")))
  7016. nil)
  7017. text (get-text-property 0 'txt fmt)))
  7018. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7019. (org-agenda-insert-diary-as-top-level text)
  7020. (require 'org-datetree)
  7021. (org-datetree-find-date-create d1)
  7022. (org-agenda-insert-diary-make-new-entry text))
  7023. (org-insert-time-stamp (org-time-from-absolute
  7024. (calendar-absolute-from-gregorian d1))
  7025. nil nil nil nil time2))
  7026. (end-of-line 0))
  7027. ((eq type 'block)
  7028. (if (> (calendar-absolute-from-gregorian d1)
  7029. (calendar-absolute-from-gregorian d2))
  7030. (setq d1 (prog1 d2 (setq d2 d1))))
  7031. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7032. (org-agenda-insert-diary-as-top-level text)
  7033. (require 'org-datetree)
  7034. (org-datetree-find-date-create d1)
  7035. (org-agenda-insert-diary-make-new-entry text))
  7036. (org-insert-time-stamp (org-time-from-absolute
  7037. (calendar-absolute-from-gregorian d1)))
  7038. (insert "--")
  7039. (org-insert-time-stamp (org-time-from-absolute
  7040. (calendar-absolute-from-gregorian d2)))
  7041. (end-of-line 0)))
  7042. (if (string-match "\\S-" text)
  7043. (progn
  7044. (set-window-configuration cw)
  7045. (message "%s entry added to %s"
  7046. (capitalize (symbol-name type))
  7047. (abbreviate-file-name org-agenda-diary-file)))
  7048. (org-reveal t)
  7049. (message "Please finish entry here"))))
  7050. (defun org-agenda-insert-diary-as-top-level (text)
  7051. "Make new entry as a top-level entry at the end of the file.
  7052. Add TEXT as headline, and position the cursor in the second line so that
  7053. a timestamp can be added there."
  7054. (widen)
  7055. (goto-char (point-max))
  7056. (or (bolp) (insert "\n"))
  7057. (insert "* " text "\n")
  7058. (if org-adapt-indentation (org-indent-to-column 2)))
  7059. (defun org-agenda-insert-diary-make-new-entry (text)
  7060. "Make new entry as last child of current entry.
  7061. Add TEXT as headline, and position the cursor in the second line so that
  7062. a timestamp can be added there."
  7063. (let ((org-show-following-heading t)
  7064. (org-show-siblings t)
  7065. (org-show-hierarchy-above t)
  7066. (org-show-entry-below t)
  7067. col)
  7068. (outline-next-heading)
  7069. (org-back-over-empty-lines)
  7070. (or (looking-at "[ \t]*$")
  7071. (progn (insert "\n") (backward-char 1)))
  7072. (org-insert-heading nil t)
  7073. (org-do-demote)
  7074. (setq col (current-column))
  7075. (insert text "\n")
  7076. (if org-adapt-indentation (org-indent-to-column col))
  7077. (let ((org-show-following-heading t)
  7078. (org-show-siblings t)
  7079. (org-show-hierarchy-above t)
  7080. (org-show-entry-below t))
  7081. (org-show-context))))
  7082. (defun org-agenda-diary-entry ()
  7083. "Make a diary entry, like the `i' command from the calendar.
  7084. All the standard commands work: block, weekly etc.
  7085. When `org-agenda-diary-file' points to a file,
  7086. `org-agenda-diary-entry-in-org-file' is called instead to create
  7087. entries in that Org-mode file."
  7088. (interactive)
  7089. (org-agenda-check-type t 'agenda 'timeline)
  7090. (if (not (eq org-agenda-diary-file 'diary-file))
  7091. (org-agenda-diary-entry-in-org-file)
  7092. (require 'diary-lib)
  7093. (let* ((char (progn
  7094. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7095. (read-char-exclusive)))
  7096. (cmd (cdr (assoc char
  7097. '((?d . insert-diary-entry)
  7098. (?w . insert-weekly-diary-entry)
  7099. (?m . insert-monthly-diary-entry)
  7100. (?y . insert-yearly-diary-entry)
  7101. (?a . insert-anniversary-diary-entry)
  7102. (?b . insert-block-diary-entry)
  7103. (?c . insert-cyclic-diary-entry)))))
  7104. (oldf (symbol-function 'calendar-cursor-to-date))
  7105. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7106. (point (point))
  7107. (mark (or (mark t) (point))))
  7108. (unless cmd
  7109. (error "No command associated with <%c>" char))
  7110. (unless (and (get-text-property point 'day)
  7111. (or (not (equal ?b char))
  7112. (get-text-property mark 'day)))
  7113. (error "Don't know which date to use for diary entry"))
  7114. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7115. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7116. (let ((calendar-mark-ring
  7117. (list (calendar-gregorian-from-absolute
  7118. (or (get-text-property mark 'day)
  7119. (get-text-property point 'day))))))
  7120. (unwind-protect
  7121. (progn
  7122. (fset 'calendar-cursor-to-date
  7123. (lambda (&optional error dummy)
  7124. (calendar-gregorian-from-absolute
  7125. (get-text-property point 'day))))
  7126. (call-interactively cmd))
  7127. (fset 'calendar-cursor-to-date oldf))))))
  7128. (defun org-agenda-execute-calendar-command (cmd)
  7129. "Execute a calendar command from the agenda, with the date associated to
  7130. the cursor position."
  7131. (org-agenda-check-type t 'agenda 'timeline)
  7132. (require 'diary-lib)
  7133. (unless (get-text-property (point) 'day)
  7134. (error "Don't know which date to use for calendar command"))
  7135. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7136. (point (point))
  7137. (date (calendar-gregorian-from-absolute
  7138. (get-text-property point 'day)))
  7139. ;; the following 2 vars are needed in the calendar
  7140. (displayed-month (car date))
  7141. (displayed-year (nth 2 date)))
  7142. (unwind-protect
  7143. (progn
  7144. (fset 'calendar-cursor-to-date
  7145. (lambda (&optional error dummy)
  7146. (calendar-gregorian-from-absolute
  7147. (get-text-property point 'day))))
  7148. (call-interactively cmd))
  7149. (fset 'calendar-cursor-to-date oldf))))
  7150. (defun org-agenda-phases-of-moon ()
  7151. "Display the phases of the moon for the 3 months around the cursor date."
  7152. (interactive)
  7153. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7154. (defun org-agenda-holidays ()
  7155. "Display the holidays for the 3 months around the cursor date."
  7156. (interactive)
  7157. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7158. (defvar calendar-longitude)
  7159. (defvar calendar-latitude)
  7160. (defvar calendar-location-name)
  7161. (defun org-agenda-sunrise-sunset (arg)
  7162. "Display sunrise and sunset for the cursor date.
  7163. Latitude and longitude can be specified with the variables
  7164. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7165. argument, latitude and longitude will be prompted for."
  7166. (interactive "P")
  7167. (require 'solar)
  7168. (let ((calendar-longitude (if arg nil calendar-longitude))
  7169. (calendar-latitude (if arg nil calendar-latitude))
  7170. (calendar-location-name
  7171. (if arg "the given coordinates" calendar-location-name)))
  7172. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7173. (defun org-agenda-goto-calendar ()
  7174. "Open the Emacs calendar with the date at the cursor."
  7175. (interactive)
  7176. (org-agenda-check-type t 'agenda 'timeline)
  7177. (let* ((day (or (get-text-property (point) 'day)
  7178. (error "Don't know which date to open in calendar")))
  7179. (date (calendar-gregorian-from-absolute day))
  7180. (calendar-move-hook nil)
  7181. (calendar-view-holidays-initially-flag nil)
  7182. (calendar-view-diary-initially-flag nil))
  7183. (calendar)
  7184. (calendar-goto-date date)))
  7185. ;;;###autoload
  7186. (defun org-calendar-goto-agenda ()
  7187. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7188. This is a command that has to be installed in `calendar-mode-map'."
  7189. (interactive)
  7190. (org-agenda-list nil (calendar-absolute-from-gregorian
  7191. (calendar-cursor-to-date))
  7192. nil))
  7193. (defun org-agenda-convert-date ()
  7194. (interactive)
  7195. (org-agenda-check-type t 'agenda 'timeline)
  7196. (let ((day (get-text-property (point) 'day))
  7197. date s)
  7198. (unless day
  7199. (error "Don't know which date to convert"))
  7200. (setq date (calendar-gregorian-from-absolute day))
  7201. (setq s (concat
  7202. "Gregorian: " (calendar-date-string date) "\n"
  7203. "ISO: " (calendar-iso-date-string date) "\n"
  7204. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7205. "Julian: " (calendar-julian-date-string date) "\n"
  7206. "Astron. JD: " (calendar-astro-date-string date)
  7207. " (Julian date number at noon UTC)\n"
  7208. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7209. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7210. "French: " (calendar-french-date-string date) "\n"
  7211. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7212. "Mayan: " (calendar-mayan-date-string date) "\n"
  7213. "Coptic: " (calendar-coptic-date-string date) "\n"
  7214. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7215. "Persian: " (calendar-persian-date-string date) "\n"
  7216. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7217. (with-output-to-temp-buffer "*Dates*"
  7218. (princ s))
  7219. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7220. ;;; Bulk commands
  7221. (defvar org-agenda-bulk-marked-entries nil
  7222. "List of markers that refer to marked entries in the agenda.")
  7223. (defun org-agenda-bulk-marked-p ()
  7224. (eq (get-char-property (point-at-bol) 'type)
  7225. 'org-marked-entry-overlay))
  7226. (defun org-agenda-bulk-mark (&optional arg)
  7227. "Mark the entry at point for future bulk action."
  7228. (interactive "p")
  7229. (dotimes (i (max arg 1))
  7230. (unless (org-get-at-bol 'org-agenda-diary-link)
  7231. (let* ((m (org-get-at-bol 'org-hd-marker))
  7232. ov)
  7233. (unless (org-agenda-bulk-marked-p)
  7234. (unless m (error "Nothing to mark at point"))
  7235. (push m org-agenda-bulk-marked-entries)
  7236. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7237. (org-overlay-display ov "> "
  7238. (org-get-todo-face "TODO")
  7239. 'evaporate)
  7240. (overlay-put ov 'type 'org-marked-entry-overlay))
  7241. (beginning-of-line 2)
  7242. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7243. (beginning-of-line 2))
  7244. (message "%d entries marked for bulk action"
  7245. (length org-agenda-bulk-marked-entries))))))
  7246. (defun org-agenda-bulk-unmark ()
  7247. "Unmark the entry at point for future bulk action."
  7248. (interactive)
  7249. (when (org-agenda-bulk-marked-p)
  7250. (org-agenda-bulk-remove-overlays
  7251. (point-at-bol) (+ 2 (point-at-bol)))
  7252. (setq org-agenda-bulk-marked-entries
  7253. (delete (org-get-at-bol 'org-hd-marker)
  7254. org-agenda-bulk-marked-entries)))
  7255. (beginning-of-line 2)
  7256. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7257. (beginning-of-line 2))
  7258. (message "%d entries marked for bulk action"
  7259. (length org-agenda-bulk-marked-entries)))
  7260. (defun org-agenda-bulk-toggle ()
  7261. "Toggle marking the entry at point for bulk action."
  7262. (interactive)
  7263. (if (org-agenda-bulk-marked-p)
  7264. (org-agenda-bulk-unmark)
  7265. (org-agenda-bulk-mark)))
  7266. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7267. "Remove the mark overlays between BEG and END in the agenda buffer.
  7268. BEG and END default to the buffer limits.
  7269. This only removes the overlays, it does not remove the markers
  7270. from the list in `org-agenda-bulk-marked-entries'."
  7271. (interactive)
  7272. (mapc (lambda (ov)
  7273. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7274. (delete-overlay ov)))
  7275. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7276. (defun org-agenda-bulk-remove-all-marks ()
  7277. "Remove all marks in the agenda buffer.
  7278. This will remove the markers, and the overlays."
  7279. (interactive)
  7280. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7281. (setq org-agenda-bulk-marked-entries nil)
  7282. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7283. (defun org-agenda-bulk-action (&optional arg)
  7284. "Execute an remote-editing action on all marked entries.
  7285. The prefix arg is passed through to the command if possible."
  7286. (interactive "P")
  7287. (unless org-agenda-bulk-marked-entries
  7288. (error "No entries are marked"))
  7289. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
  7290. (let* ((action (read-char-exclusive))
  7291. (org-log-refile (if org-log-refile 'time nil))
  7292. (entries (reverse org-agenda-bulk-marked-entries))
  7293. redo-at-end
  7294. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7295. (cond
  7296. ((equal action ?$)
  7297. (setq cmd '(org-agenda-archive)))
  7298. ((equal action ?A)
  7299. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7300. ((member action '(?r ?w))
  7301. (setq rfloc (org-refile-get-location
  7302. "Refile to: "
  7303. (marker-buffer (car org-agenda-bulk-marked-entries))
  7304. org-refile-allow-creating-parent-nodes))
  7305. (if (nth 3 rfloc)
  7306. (setcar (nthcdr 3 rfloc)
  7307. (move-marker (make-marker) (nth 3 rfloc)
  7308. (or (get-file-buffer (nth 1 rfloc))
  7309. (find-buffer-visiting (nth 1 rfloc))
  7310. (error "This should not happen")))))
  7311. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7312. redo-at-end t))
  7313. ((equal action ?t)
  7314. (setq state (org-icompleting-read
  7315. "Todo state: "
  7316. (with-current-buffer (marker-buffer (car entries))
  7317. (mapcar 'list org-todo-keywords-1))))
  7318. (setq cmd `(let ((org-inhibit-blocking t)
  7319. (org-inhibit-logging 'note))
  7320. (org-agenda-todo ,state))))
  7321. ((memq action '(?- ?+))
  7322. (setq tag (org-icompleting-read
  7323. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7324. (with-current-buffer (marker-buffer (car entries))
  7325. (delq nil
  7326. (mapcar (lambda (x)
  7327. (if (stringp (car x)) x)) org-tag-alist)))))
  7328. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7329. ((memq action '(?s ?d))
  7330. (let* ((date (unless arg
  7331. (org-read-date
  7332. nil nil nil
  7333. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7334. (ans (if arg nil org-read-date-final-answer))
  7335. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7336. (setq cmd `(let* ((bound (fboundp 'read-string))
  7337. (old (and bound (symbol-function 'read-string))))
  7338. (unwind-protect
  7339. (progn
  7340. (fset 'read-string (lambda (&rest ignore) ,ans))
  7341. (eval '(,c1 arg)))
  7342. (if bound
  7343. (fset 'read-string old)
  7344. (fmakunbound 'read-string)))))))
  7345. ((eq action '?S)
  7346. (let ((days (read-number
  7347. (format "Scatter tasks across how many %sdays: "
  7348. (if arg "week" "")) 7)))
  7349. (setq cmd
  7350. `(let ((distance (random ,(1+ days))))
  7351. (if arg
  7352. (let ((dist distance)
  7353. (day-of-week
  7354. (calendar-day-of-week
  7355. (calendar-gregorian-from-absolute (org-today)))))
  7356. (dotimes (i (1+ dist))
  7357. (while (member day-of-week org-agenda-weekend-days)
  7358. (incf distance)
  7359. (incf day-of-week)
  7360. (if (= day-of-week 7)
  7361. (setq day-of-week 0)))
  7362. (incf day-of-week)
  7363. (if (= day-of-week 7)
  7364. (setq day-of-week 0)))))
  7365. (org-agenda-schedule nil (current-time))
  7366. (org-agenda-date-later distance)))))
  7367. (t (error "Invalid bulk action")))
  7368. ;; Sort the markers, to make sure that parents are handled before children
  7369. (setq entries (sort entries
  7370. (lambda (a b)
  7371. (cond
  7372. ((equal (marker-buffer a) (marker-buffer b))
  7373. (< (marker-position a) (marker-position b)))
  7374. (t
  7375. (string< (buffer-name (marker-buffer a))
  7376. (buffer-name (marker-buffer b))))))))
  7377. ;; Now loop over all markers and apply cmd
  7378. (while (setq e (pop entries))
  7379. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7380. (if (not pos)
  7381. (progn (message "Skipping removed entry at %s" e)
  7382. (setq cntskip (1+ cntskip)))
  7383. (goto-char pos)
  7384. (eval cmd)
  7385. (setq org-agenda-bulk-marked-entries
  7386. (delete e org-agenda-bulk-marked-entries))
  7387. (setq cnt (1+ cnt))))
  7388. (setq org-agenda-bulk-marked-entries nil)
  7389. (org-agenda-bulk-remove-all-marks)
  7390. (when redo-at-end (org-agenda-redo))
  7391. (message "Acted on %d entries%s"
  7392. cnt
  7393. (if (= cntskip 0)
  7394. ""
  7395. (format ", skipped %d (disappeared before their turn)"
  7396. cntskip)))))
  7397. ;;; Flagging notes
  7398. (defun org-agenda-show-the-flagging-note ()
  7399. "Display the flagging note in the other window.
  7400. When called a second time in direct sequence, offer to remove the FLAGGING
  7401. tag and (if present) the flagging note."
  7402. (interactive)
  7403. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7404. (win (selected-window))
  7405. note heading newhead)
  7406. (unless hdmarker
  7407. (error "No linked entry at point"))
  7408. (if (and (eq this-command last-command)
  7409. (y-or-n-p "Unflag and remove any flagging note? "))
  7410. (progn
  7411. (org-agenda-remove-flag hdmarker)
  7412. (let ((win (get-buffer-window "*Flagging Note*")))
  7413. (and win (delete-window win)))
  7414. (message "Entry unflaged"))
  7415. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7416. (unless note
  7417. (error "No flagging note"))
  7418. (org-kill-new note)
  7419. (org-switch-to-buffer-other-window "*Flagging Note*")
  7420. (erase-buffer)
  7421. (insert note)
  7422. (goto-char (point-min))
  7423. (while (re-search-forward "\\\\n" nil t)
  7424. (replace-match "\n" t t))
  7425. (goto-char (point-min))
  7426. (select-window win)
  7427. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7428. (defun org-agenda-remove-flag (marker)
  7429. "Remove the FLAGGED tag and any flagging note in the entry."
  7430. (let (newhead)
  7431. (org-with-point-at marker
  7432. (org-toggle-tag "FLAGGED" 'off)
  7433. (org-entry-delete nil "THEFLAGGINGNOTE")
  7434. (setq newhead (org-get-heading)))
  7435. (org-agenda-change-all-lines newhead marker)
  7436. (message "Entry unflaged")))
  7437. (defun org-agenda-get-any-marker (&optional pos)
  7438. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7439. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7440. ;;; Appointment reminders
  7441. (defvar appt-time-msg-list)
  7442. ;;;###autoload
  7443. (defun org-agenda-to-appt (&optional refresh filter)
  7444. "Activate appointments found in `org-agenda-files'.
  7445. With a \\[universal-argument] prefix, refresh the list of
  7446. appointments.
  7447. If FILTER is t, interactively prompt the user for a regular
  7448. expression, and filter out entries that don't match it.
  7449. If FILTER is a string, use this string as a regular expression
  7450. for filtering entries out.
  7451. FILTER can also be an alist with the car of each cell being
  7452. either 'headline or 'category. For example:
  7453. '((headline \"IMPORTANT\")
  7454. (category \"Work\"))
  7455. will only add headlines containing IMPORTANT or headlines
  7456. belonging to the \"Work\" category."
  7457. (interactive "P")
  7458. (if refresh (setq appt-time-msg-list nil))
  7459. (if (eq filter t)
  7460. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7461. (let* ((cnt 0) ; count added events
  7462. (org-agenda-new-buffers nil)
  7463. (org-deadline-warning-days 0)
  7464. ;; Do not use `org-today' here because appt only takes
  7465. ;; time and without date as argument, so it may pass wrong
  7466. ;; information otherwise
  7467. (today (org-date-to-gregorian
  7468. (time-to-days (current-time))))
  7469. (org-agenda-restrict nil)
  7470. (files (org-agenda-files 'unrestricted)) entries file)
  7471. ;; Get all entries which may contain an appt
  7472. (org-prepare-agenda-buffers files)
  7473. (while (setq file (pop files))
  7474. (setq entries
  7475. (append entries
  7476. (org-agenda-get-day-entries
  7477. file today :timestamp :scheduled :deadline))))
  7478. (setq entries (delq nil entries))
  7479. ;; Map thru entries and find if we should filter them out
  7480. (mapc
  7481. (lambda(x)
  7482. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7483. (cat (get-text-property 1 'org-category x))
  7484. (tod (get-text-property 1 'time-of-day x))
  7485. (ok (or (null filter)
  7486. (and (stringp filter) (string-match filter evt))
  7487. (and (listp filter)
  7488. (or (string-match
  7489. (cadr (assoc 'category filter)) cat)
  7490. (string-match
  7491. (cadr (assoc 'headline filter)) evt))))))
  7492. ;; FIXME: Shall we remove text-properties for the appt text?
  7493. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7494. (when (and ok tod)
  7495. (setq tod (concat "00" (number-to-string tod))
  7496. tod (when (string-match
  7497. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7498. (concat (match-string 1 tod) ":"
  7499. (match-string 2 tod))))
  7500. (appt-add tod evt)
  7501. (setq cnt (1+ cnt))))) entries)
  7502. (org-release-buffers org-agenda-new-buffers)
  7503. (if (eq cnt 0)
  7504. (message "No event to add")
  7505. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7506. (defun org-agenda-todayp (date)
  7507. "Does DATE mean today, when considering `org-extend-today-until'?"
  7508. (let ((today (org-today))
  7509. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7510. date)))
  7511. (eq date today)))
  7512. (provide 'org-agenda)
  7513. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7514. ;;; org-agenda.el ends here