org-agenda.el 308 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101
  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. %(expression) Eval EXPRESSION and replace the control string
  1167. by the result
  1168. All specifiers work basically like the standard `%s' of printf, but may
  1169. contain two additional characters: A question mark just after the `%' and
  1170. a whitespace/punctuation character just before the final letter.
  1171. If the first character after `%' is a question mark, the entire field
  1172. will only be included if the corresponding value applies to the
  1173. current entry. This is useful for fields which should have fixed
  1174. width when present, but zero width when absent. For example,
  1175. \"%?-12t\" will result in a 12 character time field if a time of the
  1176. day is specified, but will completely disappear in entries which do
  1177. not contain a time.
  1178. If there is punctuation or whitespace character just before the final
  1179. format letter, this character will be appended to the field value if
  1180. the value is not empty. For example, the format \"%-12:c\" leads to
  1181. \"Diary: \" if the category is \"Diary\". If the category were be
  1182. empty, no additional colon would be inserted.
  1183. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1184. - Indent the line with two space characters
  1185. - Give the category in a 12 chars wide field, padded with whitespace on
  1186. the right (because of `-'). Append a colon if there is a category
  1187. (because of `:').
  1188. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1189. time, don't put in an empty field, just skip it (because of '?').
  1190. - Finally, put the scheduling information and append a whitespace.
  1191. As another example, if you don't want the time-of-day of entries in
  1192. the prefix, you could use:
  1193. (setq org-agenda-prefix-format \" %-11:c% s\")
  1194. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1195. `org-agenda-remove-tags'.
  1196. Custom commands can set this variable in the options section."
  1197. :type '(choice
  1198. (string :tag "General format")
  1199. (list :greedy t :tag "View dependent"
  1200. (cons (const agenda) (string :tag "Format"))
  1201. (cons (const timeline) (string :tag "Format"))
  1202. (cons (const todo) (string :tag "Format"))
  1203. (cons (const tags) (string :tag "Format"))
  1204. (cons (const search) (string :tag "Format"))))
  1205. :group 'org-agenda-line-format)
  1206. (defvar org-prefix-format-compiled nil
  1207. "The compiled version of the most recently used prefix format.
  1208. See the variable `org-agenda-prefix-format'.")
  1209. (defcustom org-agenda-todo-keyword-format "%-1s"
  1210. "Format for the TODO keyword in agenda lines.
  1211. Set this to something like \"%-12s\" if you want all TODO keywords
  1212. to occupy a fixed space in the agenda display."
  1213. :group 'org-agenda-line-format
  1214. :type 'string)
  1215. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1216. "Text preceding timerange entries in the agenda view.
  1217. This is a list with two strings. The first applies when the range
  1218. is entirely on one day. The second applies if the range spans several days.
  1219. The strings may have two \"%d\" format specifiers which will be filled
  1220. with the sequence number of the days, and the total number of days in the
  1221. range, respectively."
  1222. :group 'org-agenda-line-format
  1223. :type '(list
  1224. (string :tag "Deadline today ")
  1225. (choice :tag "Deadline relative"
  1226. (string :tag "Format string")
  1227. (function))))
  1228. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1229. "Text preceding scheduled items in the agenda view.
  1230. This is a list with two strings. The first applies when the item is
  1231. scheduled on the current day. The second applies when it has been scheduled
  1232. previously, it may contain a %d indicating that this is the nth time that
  1233. this item is scheduled, due to automatic rescheduling of unfinished items
  1234. for the following day. So this number is one larger than the number of days
  1235. that passed since this item was scheduled first."
  1236. :group 'org-agenda-line-format
  1237. :type '(list
  1238. (string :tag "Scheduled today ")
  1239. (string :tag "Scheduled previously")))
  1240. (defcustom org-agenda-inactive-leader "["
  1241. "Text preceding item pulled into the agenda by inactive time stamps.
  1242. These entries are added to the agenda when pressing \"[\"."
  1243. :group 'org-agenda-line-format
  1244. :type '(list
  1245. (string :tag "Scheduled today ")
  1246. (string :tag "Scheduled previously")))
  1247. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1248. "Text preceding deadline items in the agenda view.
  1249. This is a list with two strings. The first applies when the item has its
  1250. deadline on the current day. The second applies when it is in the past or
  1251. in the future, it may contain %d to capture how many days away the deadline
  1252. is (was)."
  1253. :group 'org-agenda-line-format
  1254. :type '(list
  1255. (string :tag "Deadline today ")
  1256. (choice :tag "Deadline relative"
  1257. (string :tag "Format string")
  1258. (function))))
  1259. (defcustom org-agenda-remove-times-when-in-prefix t
  1260. "Non-nil means remove duplicate time specifications in agenda items.
  1261. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1262. time-of-day specification in a headline or diary entry is extracted and
  1263. placed into the prefix. If this option is non-nil, the original specification
  1264. \(a timestamp or -range, or just a plain time(range) specification like
  1265. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1266. cluttered.
  1267. The option can be t or nil. It may also be the symbol `beg', indicating
  1268. that the time should only be removed when it is located at the beginning of
  1269. the headline/diary entry."
  1270. :group 'org-agenda-line-format
  1271. :type '(choice
  1272. (const :tag "Always" t)
  1273. (const :tag "Never" nil)
  1274. (const :tag "When at beginning of entry" beg)))
  1275. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1276. "Non-nil means remove time ranges specifications in agenda
  1277. items that span on several days."
  1278. :group 'org-agenda-line-format
  1279. :type 'boolean)
  1280. (defcustom org-agenda-default-appointment-duration nil
  1281. "Default duration for appointments that only have a starting time.
  1282. When nil, no duration is specified in such cases.
  1283. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1284. :group 'org-agenda-line-format
  1285. :type '(choice
  1286. (integer :tag "Minutes")
  1287. (const :tag "No default duration")))
  1288. (defcustom org-agenda-show-inherited-tags t
  1289. "Non-nil means show inherited tags in each agenda line."
  1290. :group 'org-agenda-line-format
  1291. :type 'boolean)
  1292. (defcustom org-agenda-hide-tags-regexp nil
  1293. "Regular expression used to filter away specific tags in agenda views.
  1294. This means that these tags will be present, but not be shown in the agenda
  1295. line. Secondary filtering will still work on the hidden tags.
  1296. Nil means don't hide any tags."
  1297. :group 'org-agenda-line-format
  1298. :type '(choice
  1299. (const :tag "Hide none" nil)
  1300. (string :tag "Regexp ")))
  1301. (defcustom org-agenda-remove-tags nil
  1302. "Non-nil means remove the tags from the headline copy in the agenda.
  1303. When this is the symbol `prefix', only remove tags when
  1304. `org-agenda-prefix-format' contains a `%T' specifier."
  1305. :group 'org-agenda-line-format
  1306. :type '(choice
  1307. (const :tag "Always" t)
  1308. (const :tag "Never" nil)
  1309. (const :tag "When prefix format contains %T" prefix)))
  1310. (if (fboundp 'defvaralias)
  1311. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1312. 'org-agenda-remove-tags))
  1313. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1314. "Shift tags in agenda items to this column.
  1315. If this number is positive, it specifies the column. If it is negative,
  1316. it means that the tags should be flushright to that column. For example,
  1317. -80 works well for a normal 80 character screen."
  1318. :group 'org-agenda-line-format
  1319. :type 'integer)
  1320. (if (fboundp 'defvaralias)
  1321. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1322. (defcustom org-agenda-fontify-priorities 'cookies
  1323. "Non-nil means highlight low and high priorities in agenda.
  1324. When t, the highest priority entries are bold, lowest priority italic.
  1325. However, settings in `org-priority-faces' will overrule these faces.
  1326. When this variable is the symbol `cookies', only fontify the
  1327. cookies, not the entire task.
  1328. This may also be an association list of priority faces, whose
  1329. keys are the character values of `org-highest-priority',
  1330. `org-default-priority', and `org-lowest-priority' (the default values
  1331. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1332. color as a string, or a list like `(:background \"Red\")'.
  1333. If it is a color, the variable `org-faces-easy-properties'
  1334. determines if it is a foreground or a background color."
  1335. :group 'org-agenda-line-format
  1336. :type '(choice
  1337. (const :tag "Never" nil)
  1338. (const :tag "Defaults" t)
  1339. (const :tag "Cookies only" cookies)
  1340. (repeat :tag "Specify"
  1341. (list (character :tag "Priority" :value ?A)
  1342. (choice :tag "Face "
  1343. (string :tag "Color")
  1344. (sexp :tag "Face"))))))
  1345. (defcustom org-agenda-day-face-function nil
  1346. "Function called to determine what face should be used to display a day.
  1347. The only argument passed to that function is the day. It should
  1348. returns a face, or nil if does not want to specify a face and let
  1349. the normal rules apply."
  1350. :group 'org-agenda-line-format
  1351. :type 'function)
  1352. (defcustom org-agenda-category-icon-alist nil
  1353. "Alist of category icon to be displayed in agenda views.
  1354. Each entry should have the following format:
  1355. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1356. Where CATEGORY-REGEXP is a regexp matching the categories where
  1357. the icon should be displayed.
  1358. FILE-OR-DATA either a file path or a string containing image data.
  1359. The other fields can be ommited safely if not needed:
  1360. TYPE indicates the image type.
  1361. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1362. image data.
  1363. PROPS are additional image attributes to assign to the image,
  1364. like, e.g. `:ascent center'.
  1365. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1366. If you want to set the display properties yourself, just put a
  1367. list as second element:
  1368. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1369. For example, to display a 16px horizontal space for Emacs
  1370. category, you can use:
  1371. (\"Emacs\" '(space . (:width (16))))"
  1372. :group 'org-agenda-line-format
  1373. :type '(alist :key-type (string :tag "Regexp matching category")
  1374. :value-type (choice (list :tag "Icon"
  1375. (string :tag "File or data")
  1376. (symbol :tag "Type")
  1377. (boolean :tag "Data?")
  1378. (repeat :tag "Extra image properties" :inline t symbol))
  1379. (list :tag "Display properties" sexp))))
  1380. (defgroup org-agenda-column-view nil
  1381. "Options concerning column view in the agenda."
  1382. :tag "Org Agenda Column View"
  1383. :group 'org-agenda)
  1384. (defcustom org-agenda-columns-show-summaries t
  1385. "Non-nil means show summaries for columns displayed in the agenda view."
  1386. :group 'org-agenda-column-view
  1387. :type 'boolean)
  1388. (defcustom org-agenda-columns-remove-prefix-from-item t
  1389. "Non-nil means remove the prefix from a headline for agenda column view.
  1390. The special ITEM field in the columns format contains the current line, with
  1391. all information shown in other columns (like the TODO state or a tag).
  1392. When this variable is non-nil, also the agenda prefix will be removed from
  1393. the content of the ITEM field, to make sure as much as possible of the
  1394. headline can be shown in the limited width of the field."
  1395. :group 'org-agenda
  1396. :type 'boolean)
  1397. (defcustom org-agenda-columns-compute-summary-properties t
  1398. "Non-nil means recompute all summary properties before column view.
  1399. When column view in the agenda is listing properties that have a summary
  1400. operator, it can go to all relevant buffers and recompute the summaries
  1401. there. This can mean overhead for the agenda column view, but is necessary
  1402. to have thing up to date.
  1403. As a special case, a CLOCKSUM property also makes sure that the clock
  1404. computations are current."
  1405. :group 'org-agenda-column-view
  1406. :type 'boolean)
  1407. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1408. "Non-nil means the duration of an appointment will add to day effort.
  1409. The property to which appointment durations will be added is the one given
  1410. in the option `org-effort-property'. If an appointment does not have
  1411. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1412. is not set, an appointment without end time will not contribute to the time
  1413. estimate."
  1414. :group 'org-agenda-column-view
  1415. :type 'boolean)
  1416. (defcustom org-agenda-auto-exclude-function nil
  1417. "A function called with a tag to decide if it is filtered on '/ RET'.
  1418. The sole argument to the function, which is called once for each
  1419. possible tag, is a string giving the name of the tag. The
  1420. function should return either nil if the tag should be included
  1421. as normal, or \"-<TAG>\" to exclude the tag.
  1422. Note that for the purpose of tag filtering, only the lower-case version of
  1423. all tags will be considered, so that this function will only ever see
  1424. the lower-case version of all tags."
  1425. :group 'org-agenda
  1426. :type 'function)
  1427. (eval-when-compile
  1428. (require 'cl))
  1429. (require 'org)
  1430. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1431. "Execute BODY with point at location given by `org-hd-marker' property.
  1432. If STRING is non-nil, the text property will be fetched from position 0
  1433. in that string. If STRING is nil, it will be fetched from the beginning
  1434. of the current line."
  1435. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1436. 'org-hd-marker string)))
  1437. (with-current-buffer (marker-buffer marker)
  1438. (save-excursion
  1439. (goto-char marker)
  1440. ,@body))))
  1441. (defun org-add-agenda-custom-command (entry)
  1442. "Replace or add a command in `org-agenda-custom-commands'.
  1443. This is mostly for hacking and trying a new command - once the command
  1444. works you probably want to add it to `org-agenda-custom-commands' for good."
  1445. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1446. (if ass
  1447. (setcdr ass (cdr entry))
  1448. (push entry org-agenda-custom-commands))))
  1449. ;;; Define the Org-agenda-mode
  1450. (defvar org-agenda-mode-map (make-sparse-keymap)
  1451. "Keymap for `org-agenda-mode'.")
  1452. (if (fboundp 'defvaralias)
  1453. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1454. (defvar org-agenda-menu) ; defined later in this file.
  1455. (defvar org-agenda-restrict) ; defined later in this file.
  1456. (defvar org-agenda-follow-mode nil)
  1457. (defvar org-agenda-entry-text-mode nil)
  1458. (defvar org-agenda-clockreport-mode nil)
  1459. (defvar org-agenda-show-log nil)
  1460. (defvar org-agenda-redo-command nil)
  1461. (defvar org-agenda-query-string nil)
  1462. (defvar org-agenda-mode-hook nil
  1463. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1464. (defvar org-agenda-type nil)
  1465. (defvar org-agenda-force-single-file nil)
  1466. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1467. (defun org-agenda-mode ()
  1468. "Mode for time-sorted view on action items in Org-mode files.
  1469. The following commands are available:
  1470. \\{org-agenda-mode-map}"
  1471. (interactive)
  1472. (kill-all-local-variables)
  1473. (setq org-agenda-undo-list nil
  1474. org-agenda-pending-undo-list nil
  1475. org-agenda-bulk-marked-entries nil)
  1476. (setq major-mode 'org-agenda-mode)
  1477. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1478. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1479. (setq mode-name "Org-Agenda")
  1480. (use-local-map org-agenda-mode-map)
  1481. (easy-menu-add org-agenda-menu)
  1482. (if org-startup-truncated (setq truncate-lines t))
  1483. (org-set-local 'line-move-visual nil)
  1484. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1485. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1486. ;; Make sure properties are removed when copying text
  1487. (when (boundp 'buffer-substring-filters)
  1488. (org-set-local 'buffer-substring-filters
  1489. (cons (lambda (x)
  1490. (set-text-properties 0 (length x) nil x) x)
  1491. buffer-substring-filters)))
  1492. (unless org-agenda-keep-modes
  1493. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1494. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1495. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1496. org-agenda-show-log org-agenda-start-with-log-mode))
  1497. (easy-menu-change
  1498. '("Agenda") "Agenda Files"
  1499. (append
  1500. (list
  1501. (vector
  1502. (if (get 'org-agenda-files 'org-restrict)
  1503. "Restricted to single file"
  1504. "Edit File List")
  1505. '(org-edit-agenda-file-list)
  1506. (not (get 'org-agenda-files 'org-restrict)))
  1507. "--")
  1508. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1509. (org-agenda-set-mode-name)
  1510. (apply
  1511. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1512. (list 'org-agenda-mode-hook)))
  1513. (substitute-key-definition 'undo 'org-agenda-undo
  1514. org-agenda-mode-map global-map)
  1515. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1516. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1517. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1518. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1519. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1520. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1521. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1522. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1523. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1524. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1525. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1526. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1527. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1528. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1529. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1530. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1531. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1532. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1533. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1534. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1535. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1536. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1537. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1538. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1539. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1540. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1541. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1542. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1543. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1544. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1545. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1546. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1547. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1548. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1549. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1550. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1551. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1552. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1553. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1554. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1555. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1556. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1557. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1558. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1559. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1560. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1561. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1562. (while l (org-defkey org-agenda-mode-map
  1563. (int-to-string (pop l)) 'digit-argument)))
  1564. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1565. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1566. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1567. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1568. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1569. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1570. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1571. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1572. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1573. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1574. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1575. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1576. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1577. 'org-clock-modify-effort-estimate)
  1578. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1579. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1580. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1581. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1582. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1583. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1584. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1585. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1586. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1587. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1588. (substitute-key-definition 'next-line 'org-agenda-next-line
  1589. org-agenda-mode-map global-map)
  1590. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1591. org-agenda-mode-map global-map)
  1592. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1593. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1594. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1595. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1596. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1597. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1598. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1599. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1600. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1601. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1602. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1603. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1604. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1605. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1606. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1607. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1608. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1609. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1610. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1611. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1612. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1613. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1614. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1615. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1616. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1617. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1618. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1619. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1620. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1621. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1622. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1623. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1624. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1625. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1626. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1627. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1628. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1629. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1630. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1631. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1632. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1633. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1634. (when org-agenda-mouse-1-follows-link
  1635. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1636. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1637. '("Agenda"
  1638. ("Agenda Files")
  1639. "--"
  1640. ("Agenda Dates"
  1641. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1642. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1643. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1644. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1645. "--"
  1646. ("View"
  1647. ["Day View" org-agenda-day-view
  1648. :active (org-agenda-check-type nil 'agenda)
  1649. :style radio :selected (eq org-agenda-current-span 'day)
  1650. :keys "v d (or just d)"]
  1651. ["Week View" org-agenda-week-view
  1652. :active (org-agenda-check-type nil 'agenda)
  1653. :style radio :selected (eq org-agenda-current-span 'week)
  1654. :keys "v w (or just w)"]
  1655. ["Month View" org-agenda-month-view
  1656. :active (org-agenda-check-type nil 'agenda)
  1657. :style radio :selected (eq org-agenda-current-span 'month)
  1658. :keys "v m"]
  1659. ["Year View" org-agenda-year-view
  1660. :active (org-agenda-check-type nil 'agenda)
  1661. :style radio :selected (eq org-agenda-current-span 'year)
  1662. :keys "v y"]
  1663. "--"
  1664. ["Include Diary" org-agenda-toggle-diary
  1665. :style toggle :selected org-agenda-include-diary
  1666. :active (org-agenda-check-type nil 'agenda)]
  1667. ["Include Deadlines" org-agenda-toggle-deadlines
  1668. :style toggle :selected org-agenda-include-deadlines
  1669. :active (org-agenda-check-type nil 'agenda)]
  1670. ["Use Time Grid" org-agenda-toggle-time-grid
  1671. :style toggle :selected org-agenda-use-time-grid
  1672. :active (org-agenda-check-type nil 'agenda)]
  1673. "--"
  1674. ["Show clock report" org-agenda-clockreport-mode
  1675. :style toggle :selected org-agenda-clockreport-mode
  1676. :active (org-agenda-check-type nil 'agenda)]
  1677. ["Show some entry text" org-agenda-entry-text-mode
  1678. :style toggle :selected org-agenda-entry-text-mode
  1679. :active t]
  1680. "--"
  1681. ["Show Logbook entries" org-agenda-log-mode
  1682. :style toggle :selected org-agenda-show-log
  1683. :active (org-agenda-check-type nil 'agenda 'timeline)
  1684. :keys "v l (or just l)"]
  1685. ["Include archived trees" org-agenda-archives-mode
  1686. :style toggle :selected org-agenda-archives-mode :active t
  1687. :keys "v a"]
  1688. ["Include archive files" (org-agenda-archives-mode t)
  1689. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1690. :keys "v A"]
  1691. "--"
  1692. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1693. ["Write view to file" org-write-agenda t]
  1694. ["Rebuild buffer" org-agenda-redo t]
  1695. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1696. "--"
  1697. ["Show original entry" org-agenda-show t]
  1698. ["Go To (other window)" org-agenda-goto t]
  1699. ["Go To (this window)" org-agenda-switch-to t]
  1700. ["Follow Mode" org-agenda-follow-mode
  1701. :style toggle :selected org-agenda-follow-mode :active t]
  1702. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1703. "--"
  1704. ("TODO"
  1705. ["Cycle TODO" org-agenda-todo t]
  1706. ["Next TODO set" org-agenda-todo-nextset t]
  1707. ["Previous TODO set" org-agenda-todo-previousset t]
  1708. ["Add note" org-agenda-add-note t])
  1709. ("Archive/Refile/Delete"
  1710. ["Archive default" org-agenda-archive-default t]
  1711. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1712. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1713. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1714. ["Archive subtree" org-agenda-archive t]
  1715. "--"
  1716. ["Refile" org-agenda-refile t]
  1717. "--"
  1718. ["Delete subtree" org-agenda-kill t])
  1719. ("Bulk action"
  1720. ["Mark entry" org-agenda-bulk-mark t]
  1721. ["Unmark entry" org-agenda-bulk-unmark t]
  1722. ["Act on all marked" org-agenda-bulk-action t]
  1723. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1724. "--"
  1725. ("Tags and Properties"
  1726. ["Show all Tags" org-agenda-show-tags t]
  1727. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1728. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1729. "--"
  1730. ["Column View" org-columns t])
  1731. ("Deadline/Schedule"
  1732. ["Schedule" org-agenda-schedule t]
  1733. ["Set Deadline" org-agenda-deadline t]
  1734. "--"
  1735. ["Mark item" org-agenda-action :active t :keys "k m"]
  1736. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1737. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1738. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1739. "--"
  1740. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1741. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1742. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1743. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1744. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1745. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1746. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1747. ("Clock and Effort"
  1748. ["Clock in" org-agenda-clock-in t]
  1749. ["Clock out" org-agenda-clock-out t]
  1750. ["Clock cancel" org-agenda-clock-cancel t]
  1751. ["Goto running clock" org-clock-goto t]
  1752. "--"
  1753. ["Set Effort" org-agenda-set-effort t]
  1754. ["Change clocked effort" org-clock-modify-effort-estimate
  1755. (org-clock-is-active)])
  1756. ("Priority"
  1757. ["Set Priority" org-agenda-priority t]
  1758. ["Increase Priority" org-agenda-priority-up t]
  1759. ["Decrease Priority" org-agenda-priority-down t]
  1760. ["Show Priority" org-agenda-show-priority t])
  1761. ("Calendar/Diary"
  1762. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1763. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1764. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1765. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1766. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1767. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1768. "--"
  1769. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1770. "--"
  1771. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1772. "--"
  1773. ("MobileOrg"
  1774. ["Push Files and Views" org-mobile-push t]
  1775. ["Get Captured and Flagged" org-mobile-pull t]
  1776. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1777. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1778. "--"
  1779. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1780. "--"
  1781. ["Quit" org-agenda-quit t]
  1782. ["Exit and Release Buffers" org-agenda-exit t]
  1783. ))
  1784. ;;; Agenda undo
  1785. (defvar org-agenda-allow-remote-undo t
  1786. "Non-nil means allow remote undo from the agenda buffer.")
  1787. (defvar org-agenda-undo-list nil
  1788. "List of undoable operations in the agenda since last refresh.")
  1789. (defvar org-agenda-undo-has-started-in nil
  1790. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1791. (defvar org-agenda-pending-undo-list nil
  1792. "In a series of undo commands, this is the list of remaining undo items.")
  1793. (defun org-agenda-undo ()
  1794. "Undo a remote editing step in the agenda.
  1795. This undoes changes both in the agenda buffer and in the remote buffer
  1796. that have been changed along."
  1797. (interactive)
  1798. (or org-agenda-allow-remote-undo
  1799. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1800. (if (not (eq this-command last-command))
  1801. (setq org-agenda-undo-has-started-in nil
  1802. org-agenda-pending-undo-list org-agenda-undo-list))
  1803. (if (not org-agenda-pending-undo-list)
  1804. (error "No further undo information"))
  1805. (let* ((entry (pop org-agenda-pending-undo-list))
  1806. buf line cmd rembuf)
  1807. (setq cmd (pop entry) line (pop entry))
  1808. (setq rembuf (nth 2 entry))
  1809. (org-with-remote-undo rembuf
  1810. (while (bufferp (setq buf (pop entry)))
  1811. (if (pop entry)
  1812. (with-current-buffer buf
  1813. (let ((last-undo-buffer buf)
  1814. (inhibit-read-only t))
  1815. (unless (memq buf org-agenda-undo-has-started-in)
  1816. (push buf org-agenda-undo-has-started-in)
  1817. (make-local-variable 'pending-undo-list)
  1818. (undo-start))
  1819. (while (and pending-undo-list
  1820. (listp pending-undo-list)
  1821. (not (car pending-undo-list)))
  1822. (pop pending-undo-list))
  1823. (undo-more 1))))))
  1824. (org-goto-line line)
  1825. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1826. (defun org-verify-change-for-undo (l1 l2)
  1827. "Verify that a real change occurred between the undo lists L1 and L2."
  1828. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1829. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1830. (not (eq l1 l2)))
  1831. ;;; Agenda dispatch
  1832. (defvar org-agenda-restrict nil)
  1833. (defvar org-agenda-restrict-begin (make-marker))
  1834. (defvar org-agenda-restrict-end (make-marker))
  1835. (defvar org-agenda-last-dispatch-buffer nil)
  1836. (defvar org-agenda-overriding-restriction nil)
  1837. ;;;###autoload
  1838. (defun org-agenda (&optional arg keys restriction)
  1839. "Dispatch agenda commands to collect entries to the agenda buffer.
  1840. Prompts for a command to execute. Any prefix arg will be passed
  1841. on to the selected command. The default selections are:
  1842. a Call `org-agenda-list' to display the agenda for current day or week.
  1843. t Call `org-todo-list' to display the global todo list.
  1844. T Call `org-todo-list' to display the global todo list, select only
  1845. entries with a specific TODO keyword (the user gets a prompt).
  1846. m Call `org-tags-view' to display headlines with tags matching
  1847. a condition (the user is prompted for the condition).
  1848. M Like `m', but select only TODO entries, no ordinary headlines.
  1849. L Create a timeline for the current buffer.
  1850. e Export views to associated files.
  1851. s Search entries for keywords.
  1852. / Multi occur across all agenda files and also files listed
  1853. in `org-agenda-text-search-extra-files'.
  1854. < Restrict agenda commands to buffer, subtree, or region.
  1855. Press several times to get the desired effect.
  1856. > Remove a previous restriction.
  1857. # List \"stuck\" projects.
  1858. ! Configure what \"stuck\" means.
  1859. C Configure custom agenda commands.
  1860. More commands can be added by configuring the variable
  1861. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1862. searches can be pre-defined in this way.
  1863. If the current buffer is in Org-mode and visiting a file, you can also
  1864. first press `<' once to indicate that the agenda should be temporarily
  1865. \(until the next use of \\[org-agenda]) restricted to the current file.
  1866. Pressing `<' twice means to restrict to the current subtree or region
  1867. \(if active)."
  1868. (interactive "P")
  1869. (catch 'exit
  1870. (let* ((prefix-descriptions nil)
  1871. (org-agenda-window-setup (if (equal (buffer-name)
  1872. org-agenda-buffer-name)
  1873. 'current-window
  1874. org-agenda-window-setup))
  1875. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1876. (org-agenda-custom-commands
  1877. ;; normalize different versions
  1878. (delq nil
  1879. (mapcar
  1880. (lambda (x)
  1881. (cond ((stringp (cdr x))
  1882. (push x prefix-descriptions)
  1883. nil)
  1884. ((stringp (nth 1 x)) x)
  1885. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1886. (t (cons (car x) (cons "" (cdr x))))))
  1887. org-agenda-custom-commands)))
  1888. (buf (current-buffer))
  1889. (bfn (buffer-file-name (buffer-base-buffer)))
  1890. entry key type match lprops ans)
  1891. ;; Turn off restriction unless there is an overriding one,
  1892. (unless org-agenda-overriding-restriction
  1893. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1894. ;; There is a request to keep the file list in place
  1895. (put 'org-agenda-files 'org-restrict nil))
  1896. (setq org-agenda-restrict nil)
  1897. (move-marker org-agenda-restrict-begin nil)
  1898. (move-marker org-agenda-restrict-end nil))
  1899. ;; Delete old local properties
  1900. (put 'org-agenda-redo-command 'org-lprops nil)
  1901. ;; Remember where this call originated
  1902. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1903. (unless keys
  1904. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1905. keys (car ans)
  1906. restriction (cdr ans)))
  1907. ;; Establish the restriction, if any
  1908. (when (and (not org-agenda-overriding-restriction) restriction)
  1909. (put 'org-agenda-files 'org-restrict (list bfn))
  1910. (cond
  1911. ((eq restriction 'region)
  1912. (setq org-agenda-restrict t)
  1913. (move-marker org-agenda-restrict-begin (region-beginning))
  1914. (move-marker org-agenda-restrict-end (region-end)))
  1915. ((eq restriction 'subtree)
  1916. (save-excursion
  1917. (setq org-agenda-restrict t)
  1918. (org-back-to-heading t)
  1919. (move-marker org-agenda-restrict-begin (point))
  1920. (move-marker org-agenda-restrict-end
  1921. (progn (org-end-of-subtree t)))))))
  1922. ;; For example the todo list should not need it (but does...)
  1923. (cond
  1924. ((setq entry (assoc keys org-agenda-custom-commands))
  1925. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1926. (progn
  1927. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1928. lprops (nth 4 entry))
  1929. (put 'org-agenda-redo-command 'org-lprops lprops)
  1930. (cond
  1931. ((eq type 'agenda)
  1932. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1933. ((eq type 'alltodo)
  1934. (org-let lprops '(org-todo-list current-prefix-arg)))
  1935. ((eq type 'search)
  1936. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1937. ((eq type 'stuck)
  1938. (org-let lprops '(org-agenda-list-stuck-projects
  1939. current-prefix-arg)))
  1940. ((eq type 'tags)
  1941. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1942. ((eq type 'tags-todo)
  1943. (org-let lprops '(org-tags-view '(4) match)))
  1944. ((eq type 'todo)
  1945. (org-let lprops '(org-todo-list match)))
  1946. ((eq type 'tags-tree)
  1947. (org-check-for-org-mode)
  1948. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1949. ((eq type 'todo-tree)
  1950. (org-check-for-org-mode)
  1951. (org-let lprops
  1952. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1953. (regexp-quote match) "\\>"))))
  1954. ((eq type 'occur-tree)
  1955. (org-check-for-org-mode)
  1956. (org-let lprops '(org-occur match)))
  1957. ((functionp type)
  1958. (org-let lprops '(funcall type match)))
  1959. ((fboundp type)
  1960. (org-let lprops '(funcall type match)))
  1961. (t (error "Invalid custom agenda command type %s" type))))
  1962. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1963. ((equal keys "C")
  1964. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1965. (customize-variable 'org-agenda-custom-commands))
  1966. ((equal keys "a") (call-interactively 'org-agenda-list))
  1967. ((equal keys "s") (call-interactively 'org-search-view))
  1968. ((equal keys "t") (call-interactively 'org-todo-list))
  1969. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1970. ((equal keys "m") (call-interactively 'org-tags-view))
  1971. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1972. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1973. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1974. (org-add-hook
  1975. 'post-command-hook
  1976. (lambda ()
  1977. (unless (current-message)
  1978. (let* ((m (org-agenda-get-any-marker))
  1979. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1980. (when note
  1981. (message (concat
  1982. "FLAGGING-NOTE ([?] for more info): "
  1983. (org-add-props
  1984. (replace-regexp-in-string
  1985. "\\\\n" "//"
  1986. (copy-sequence note))
  1987. nil 'face 'org-warning)))))))
  1988. t t))
  1989. ((equal keys "L")
  1990. (unless (org-mode-p)
  1991. (error "This is not an Org-mode file"))
  1992. (unless restriction
  1993. (put 'org-agenda-files 'org-restrict (list bfn))
  1994. (org-call-with-arg 'org-timeline arg)))
  1995. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1996. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1997. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1998. (t (error "Invalid agenda key"))))))
  1999. (defun org-agenda-normalize-custom-commands (cmds)
  2000. (delq nil
  2001. (mapcar
  2002. (lambda (x)
  2003. (cond ((stringp (cdr x)) nil)
  2004. ((stringp (nth 1 x)) x)
  2005. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2006. (t (cons (car x) (cons "" (cdr x))))))
  2007. cmds)))
  2008. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2009. "The user interface for selecting an agenda command."
  2010. (catch 'exit
  2011. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2012. (restrict-ok (and bfn (org-mode-p)))
  2013. (region-p (org-region-active-p))
  2014. (custom org-agenda-custom-commands)
  2015. (selstring "")
  2016. restriction second-time
  2017. c entry key type match prefixes rmheader header-end custom1 desc
  2018. line lines left right n n1)
  2019. (save-window-excursion
  2020. (delete-other-windows)
  2021. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2022. (erase-buffer)
  2023. (insert (eval-when-compile
  2024. (let ((header
  2025. "
  2026. Press key for an agenda command: < Buffer, subtree/region restriction
  2027. -------------------------------- > Remove restriction
  2028. a Agenda for current week or day e Export agenda views
  2029. t List of all TODO entries T Entries with special TODO kwd
  2030. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2031. L Timeline for current buffer # List stuck projects (!=configure)
  2032. s Search for keywords C Configure custom agenda commands
  2033. / Multi-occur ? Find :FLAGGED: entries
  2034. ")
  2035. (start 0))
  2036. (while (string-match
  2037. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2038. header start)
  2039. (setq start (match-end 0))
  2040. (add-text-properties (match-beginning 2) (match-end 2)
  2041. '(face bold) header))
  2042. header)))
  2043. (setq header-end (move-marker (make-marker) (point)))
  2044. (while t
  2045. (setq custom1 custom)
  2046. (when (eq rmheader t)
  2047. (org-goto-line 1)
  2048. (re-search-forward ":" nil t)
  2049. (delete-region (match-end 0) (point-at-eol))
  2050. (forward-char 1)
  2051. (looking-at "-+")
  2052. (delete-region (match-end 0) (point-at-eol))
  2053. (move-marker header-end (match-end 0)))
  2054. (goto-char header-end)
  2055. (delete-region (point) (point-max))
  2056. ;; Produce all the lines that describe custom commands and prefixes
  2057. (setq lines nil)
  2058. (while (setq entry (pop custom1))
  2059. (setq key (car entry) desc (nth 1 entry)
  2060. type (nth 2 entry)
  2061. match (nth 3 entry))
  2062. (if (> (length key) 1)
  2063. (add-to-list 'prefixes (string-to-char key))
  2064. (setq line
  2065. (format
  2066. "%-4s%-14s"
  2067. (org-add-props (copy-sequence key)
  2068. '(face bold))
  2069. (cond
  2070. ((string-match "\\S-" desc) desc)
  2071. ((eq type 'agenda) "Agenda for current week or day")
  2072. ((eq type 'alltodo) "List of all TODO entries")
  2073. ((eq type 'search) "Word search")
  2074. ((eq type 'stuck) "List of stuck projects")
  2075. ((eq type 'todo) "TODO keyword")
  2076. ((eq type 'tags) "Tags query")
  2077. ((eq type 'tags-todo) "Tags (TODO)")
  2078. ((eq type 'tags-tree) "Tags tree")
  2079. ((eq type 'todo-tree) "TODO kwd tree")
  2080. ((eq type 'occur-tree) "Occur tree")
  2081. ((functionp type) (if (symbolp type)
  2082. (symbol-name type)
  2083. "Lambda expression"))
  2084. (t "???"))))
  2085. (if org-agenda-menu-show-matcher
  2086. (setq line
  2087. (concat line ": "
  2088. (cond
  2089. ((stringp match)
  2090. (setq match (copy-sequence match))
  2091. (org-add-props match nil 'face 'org-warning))
  2092. (match
  2093. (format "set of %d commands" (length match)))
  2094. (t ""))))
  2095. (if (org-string-nw-p match)
  2096. (add-text-properties
  2097. 0 (length line) (list 'help-echo
  2098. (concat "Matcher: "match)) line)))
  2099. (push line lines)))
  2100. (setq lines (nreverse lines))
  2101. (when prefixes
  2102. (mapc (lambda (x)
  2103. (push
  2104. (format "%s %s"
  2105. (org-add-props (char-to-string x)
  2106. nil 'face 'bold)
  2107. (or (cdr (assoc (concat selstring
  2108. (char-to-string x))
  2109. prefix-descriptions))
  2110. "Prefix key"))
  2111. lines))
  2112. prefixes))
  2113. ;; Check if we should display in two columns
  2114. (if org-agenda-menu-two-column
  2115. (progn
  2116. (setq n (length lines)
  2117. n1 (+ (/ n 2) (mod n 2))
  2118. right (nthcdr n1 lines)
  2119. left (copy-sequence lines))
  2120. (setcdr (nthcdr (1- n1) left) nil))
  2121. (setq left lines right nil))
  2122. (while left
  2123. (insert "\n" (pop left))
  2124. (when right
  2125. (if (< (current-column) 40)
  2126. (move-to-column 40 t)
  2127. (insert " "))
  2128. (insert (pop right))))
  2129. ;; Make the window the right size
  2130. (goto-char (point-min))
  2131. (if second-time
  2132. (if (not (pos-visible-in-window-p (point-max)))
  2133. (org-fit-window-to-buffer))
  2134. (setq second-time t)
  2135. (org-fit-window-to-buffer))
  2136. ;; Ask for selection
  2137. (message "Press key for agenda command%s:"
  2138. (if (or restrict-ok org-agenda-overriding-restriction)
  2139. (if org-agenda-overriding-restriction
  2140. " (restriction lock active)"
  2141. (if restriction
  2142. (format " (restricted to %s)" restriction)
  2143. " (unrestricted)"))
  2144. ""))
  2145. (setq c (read-char-exclusive))
  2146. (message "")
  2147. (cond
  2148. ((assoc (char-to-string c) custom)
  2149. (setq selstring (concat selstring (char-to-string c)))
  2150. (throw 'exit (cons selstring restriction)))
  2151. ((memq c prefixes)
  2152. (setq selstring (concat selstring (char-to-string c))
  2153. prefixes nil
  2154. rmheader (or rmheader t)
  2155. custom (delq nil (mapcar
  2156. (lambda (x)
  2157. (if (or (= (length (car x)) 1)
  2158. (/= (string-to-char (car x)) c))
  2159. nil
  2160. (cons (substring (car x) 1) (cdr x))))
  2161. custom))))
  2162. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2163. (message "Restriction is only possible in Org-mode buffers")
  2164. (ding) (sit-for 1))
  2165. ((eq c ?1)
  2166. (org-agenda-remove-restriction-lock 'noupdate)
  2167. (setq restriction 'buffer))
  2168. ((eq c ?0)
  2169. (org-agenda-remove-restriction-lock 'noupdate)
  2170. (setq restriction (if region-p 'region 'subtree)))
  2171. ((eq c ?<)
  2172. (org-agenda-remove-restriction-lock 'noupdate)
  2173. (setq restriction
  2174. (cond
  2175. ((eq restriction 'buffer)
  2176. (if region-p 'region 'subtree))
  2177. ((memq restriction '(subtree region))
  2178. nil)
  2179. (t 'buffer))))
  2180. ((eq c ?>)
  2181. (org-agenda-remove-restriction-lock 'noupdate)
  2182. (setq restriction nil))
  2183. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2184. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2185. ((and (> (length selstring) 0) (eq c ?\d))
  2186. (delete-window)
  2187. (org-agenda-get-restriction-and-command prefix-descriptions))
  2188. ((equal c ?q) (error "Abort"))
  2189. (t (error "Invalid key %c" c))))))))
  2190. (defun org-run-agenda-series (name series)
  2191. (org-let (nth 1 series) '(org-prepare-agenda name))
  2192. (let* ((org-agenda-multi t)
  2193. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2194. (cmds (car series))
  2195. (gprops (nth 1 series))
  2196. match ;; The byte compiler incorrectly complains about this. Keep it!
  2197. cmd type lprops)
  2198. (while (setq cmd (pop cmds))
  2199. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2200. (cond
  2201. ((eq type 'agenda)
  2202. (org-let2 gprops lprops
  2203. '(call-interactively 'org-agenda-list)))
  2204. ((eq type 'alltodo)
  2205. (org-let2 gprops lprops
  2206. '(call-interactively 'org-todo-list)))
  2207. ((eq type 'search)
  2208. (org-let2 gprops lprops
  2209. '(org-search-view current-prefix-arg match nil)))
  2210. ((eq type 'stuck)
  2211. (org-let2 gprops lprops
  2212. '(call-interactively 'org-agenda-list-stuck-projects)))
  2213. ((eq type 'tags)
  2214. (org-let2 gprops lprops
  2215. '(org-tags-view current-prefix-arg match)))
  2216. ((eq type 'tags-todo)
  2217. (org-let2 gprops lprops
  2218. '(org-tags-view '(4) match)))
  2219. ((eq type 'todo)
  2220. (org-let2 gprops lprops
  2221. '(org-todo-list match)))
  2222. ((fboundp type)
  2223. (org-let2 gprops lprops
  2224. '(funcall type match)))
  2225. (t (error "Invalid type in command series"))))
  2226. (widen)
  2227. (setq org-agenda-redo-command redo)
  2228. (goto-char (point-min)))
  2229. (org-fit-agenda-window)
  2230. (org-let (nth 1 series) '(org-finalize-agenda)))
  2231. ;;;###autoload
  2232. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2233. "Run an agenda command in batch mode and send the result to STDOUT.
  2234. If CMD-KEY is a string of length 1, it is used as a key in
  2235. `org-agenda-custom-commands' and triggers this command. If it is a
  2236. longer string it is used as a tags/todo match string.
  2237. Parameters are alternating variable names and values that will be bound
  2238. before running the agenda command."
  2239. (let (pars)
  2240. (while parameters
  2241. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2242. (if (> (length cmd-key) 2)
  2243. (eval (list 'let (nreverse pars)
  2244. (list 'org-tags-view nil cmd-key)))
  2245. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2246. (set-buffer org-agenda-buffer-name)
  2247. (princ (org-encode-for-stdout (buffer-string)))))
  2248. ;(defun org-encode-for-stdout (string)
  2249. ; (if (fboundp 'encode-coding-string)
  2250. ; (encode-coding-string string buffer-file-coding-system)
  2251. ; string))
  2252. (defun org-encode-for-stdout (string)
  2253. string)
  2254. (defvar org-agenda-info nil)
  2255. ;;;###autoload
  2256. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2257. "Run an agenda command in batch mode and send the result to STDOUT.
  2258. If CMD-KEY is a string of length 1, it is used as a key in
  2259. `org-agenda-custom-commands' and triggers this command. If it is a
  2260. longer string it is used as a tags/todo match string.
  2261. Parameters are alternating variable names and values that will be bound
  2262. before running the agenda command.
  2263. The output gives a line for each selected agenda item. Each
  2264. item is a list of comma-separated values, like this:
  2265. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2266. category The category of the item
  2267. head The headline, without TODO kwd, TAGS and PRIORITY
  2268. type The type of the agenda entry, can be
  2269. todo selected in TODO match
  2270. tagsmatch selected in tags match
  2271. diary imported from diary
  2272. deadline a deadline on given date
  2273. scheduled scheduled on given date
  2274. timestamp entry has timestamp on given date
  2275. closed entry was closed on given date
  2276. upcoming-deadline warning about deadline
  2277. past-scheduled forwarded scheduled item
  2278. block entry has date block including g. date
  2279. todo The todo keyword, if any
  2280. tags All tags including inherited ones, separated by colons
  2281. date The relevant date, like 2007-2-14
  2282. time The time, like 15:00-16:50
  2283. extra Sting with extra planning info
  2284. priority-l The priority letter if any was given
  2285. priority-n The computed numerical priority
  2286. agenda-day The day in the agenda where this is listed"
  2287. (let (pars)
  2288. (while parameters
  2289. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2290. (push (list 'org-agenda-remove-tags t) pars)
  2291. (if (> (length cmd-key) 2)
  2292. (eval (list 'let (nreverse pars)
  2293. (list 'org-tags-view nil cmd-key)))
  2294. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2295. (set-buffer org-agenda-buffer-name)
  2296. (let* ((lines (org-split-string (buffer-string) "\n"))
  2297. line)
  2298. (while (setq line (pop lines))
  2299. (catch 'next
  2300. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2301. (setq org-agenda-info
  2302. (org-fix-agenda-info (text-properties-at 0 line)))
  2303. (princ
  2304. (org-encode-for-stdout
  2305. (mapconcat 'org-agenda-export-csv-mapper
  2306. '(org-category txt type todo tags date time extra
  2307. priority-letter priority agenda-day)
  2308. ",")))
  2309. (princ "\n"))))))
  2310. (defun org-fix-agenda-info (props)
  2311. "Make sure all properties on an agenda item have a canonical form.
  2312. This ensures the export commands can easily use it."
  2313. (let (tmp re)
  2314. (when (setq tmp (plist-get props 'tags))
  2315. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2316. (when (setq tmp (plist-get props 'date))
  2317. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2318. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2319. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2320. (setq tmp (calendar-date-string tmp)))
  2321. (setq props (plist-put props 'date tmp)))
  2322. (when (setq tmp (plist-get props 'day))
  2323. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2324. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2325. (setq tmp (calendar-date-string tmp)))
  2326. (setq props (plist-put props 'day tmp))
  2327. (setq props (plist-put props 'agenda-day tmp)))
  2328. (when (setq tmp (plist-get props 'txt))
  2329. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2330. (plist-put props 'priority-letter (match-string 1 tmp))
  2331. (setq tmp (replace-match "" t t tmp)))
  2332. (when (and (setq re (plist-get props 'org-todo-regexp))
  2333. (setq re (concat "\\`\\.*" re " ?"))
  2334. (string-match re tmp))
  2335. (plist-put props 'todo (match-string 1 tmp))
  2336. (setq tmp (replace-match "" t t tmp)))
  2337. (plist-put props 'txt tmp)))
  2338. props)
  2339. (defun org-agenda-export-csv-mapper (prop)
  2340. (let ((res (plist-get org-agenda-info prop)))
  2341. (setq res
  2342. (cond
  2343. ((not res) "")
  2344. ((stringp res) res)
  2345. (t (prin1-to-string res))))
  2346. (while (string-match "," res)
  2347. (setq res (replace-match ";" t t res)))
  2348. (org-trim res)))
  2349. ;;;###autoload
  2350. (defun org-store-agenda-views (&rest parameters)
  2351. (interactive)
  2352. (eval (list 'org-batch-store-agenda-views)))
  2353. ;; FIXME, why is this a macro?????
  2354. ;;;###autoload
  2355. (defmacro org-batch-store-agenda-views (&rest parameters)
  2356. "Run all custom agenda commands that have a file argument."
  2357. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2358. (pop-up-frames nil)
  2359. (dir default-directory)
  2360. pars cmd thiscmdkey files opts cmd-or-set)
  2361. (while parameters
  2362. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2363. (setq pars (reverse pars))
  2364. (save-window-excursion
  2365. (while cmds
  2366. (setq cmd (pop cmds)
  2367. thiscmdkey (car cmd)
  2368. cmd-or-set (nth 2 cmd)
  2369. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2370. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2371. (if (stringp files) (setq files (list files)))
  2372. (when files
  2373. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2374. (list 'org-agenda nil thiscmdkey)))
  2375. (set-buffer org-agenda-buffer-name)
  2376. (while files
  2377. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2378. (list 'org-write-agenda
  2379. (expand-file-name (pop files) dir) nil t))))
  2380. (and (get-buffer org-agenda-buffer-name)
  2381. (kill-buffer org-agenda-buffer-name)))))))
  2382. (defun org-agenda-mark-header-line (pos)
  2383. "Mark the line at POS as an agenda structure header."
  2384. (save-excursion
  2385. (goto-char pos)
  2386. (put-text-property (point-at-bol) (point-at-eol)
  2387. 'org-agenda-structural-header t)
  2388. (when org-agenda-title-append
  2389. (put-text-property (point-at-bol) (point-at-eol)
  2390. 'org-agenda-title-append org-agenda-title-append))))
  2391. (defvar org-mobile-creating-agendas)
  2392. (defun org-write-agenda (file &optional open nosettings)
  2393. "Write the current buffer (an agenda view) as a file.
  2394. Depending on the extension of the file name, plain text (.txt),
  2395. HTML (.html or .htm) or Postscript (.ps) is produced.
  2396. If the extension is .ics, run icalendar export over all files used
  2397. to construct the agenda and limit the export to entries listed in the
  2398. agenda now.
  2399. With prefix argument OPEN, open the new file immediately.
  2400. If NOSETTINGS is given, do not scope the settings of
  2401. `org-agenda-exporter-settings' into the export commands. This is used when
  2402. the settings have already been scoped and we do not wish to overrule other,
  2403. higher priority settings."
  2404. (interactive "FWrite agenda to file: \nP")
  2405. (if (not (file-writable-p file))
  2406. (error "Cannot write agenda to file %s" file))
  2407. (org-let (if nosettings nil org-agenda-exporter-settings)
  2408. '(save-excursion
  2409. (save-window-excursion
  2410. (org-agenda-mark-filtered-text)
  2411. (let ((bs (copy-sequence (buffer-string))) beg)
  2412. (org-agenda-unmark-filtered-text)
  2413. (with-temp-buffer
  2414. (rename-buffer "Agenda View" t)
  2415. (set-buffer-modified-p nil)
  2416. (insert bs)
  2417. (org-agenda-remove-marked-text 'org-filtered)
  2418. (while (setq beg (text-property-any (point-min) (point-max)
  2419. 'org-filtered t))
  2420. (delete-region
  2421. beg (or (next-single-property-change beg 'org-filtered)
  2422. (point-max))))
  2423. (run-hooks 'org-agenda-before-write-hook)
  2424. (cond
  2425. ((org-bound-and-true-p org-mobile-creating-agendas)
  2426. (org-mobile-write-agenda-for-mobile file))
  2427. ((string-match "\\.html?\\'" file)
  2428. (require 'htmlize)
  2429. (set-buffer (htmlize-buffer (current-buffer)))
  2430. (when (and org-agenda-export-html-style
  2431. (string-match "<style>" org-agenda-export-html-style))
  2432. ;; replace <style> section with org-agenda-export-html-style
  2433. (goto-char (point-min))
  2434. (kill-region (- (search-forward "<style") 6)
  2435. (search-forward "</style>"))
  2436. (insert org-agenda-export-html-style))
  2437. (write-file file)
  2438. (kill-buffer (current-buffer))
  2439. (message "HTML written to %s" file))
  2440. ((string-match "\\.ps\\'" file)
  2441. (require 'ps-print)
  2442. (ps-print-buffer-with-faces file)
  2443. (message "Postscript written to %s" file))
  2444. ((string-match "\\.pdf\\'" file)
  2445. (require 'ps-print)
  2446. (ps-print-buffer-with-faces
  2447. (concat (file-name-sans-extension file) ".ps"))
  2448. (call-process "ps2pdf" nil nil nil
  2449. (expand-file-name
  2450. (concat (file-name-sans-extension file) ".ps"))
  2451. (expand-file-name file))
  2452. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2453. (message "PDF written to %s" file))
  2454. ((string-match "\\.ics\\'" file)
  2455. (require 'org-icalendar)
  2456. (let ((org-agenda-marker-table
  2457. (org-create-marker-find-array
  2458. (org-agenda-collect-markers)))
  2459. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2460. (org-combined-agenda-icalendar-file file))
  2461. (apply 'org-export-icalendar 'combine
  2462. (org-agenda-files nil 'ifmode))))
  2463. (t
  2464. (let ((bs (buffer-string)))
  2465. (find-file file)
  2466. (erase-buffer)
  2467. (insert bs)
  2468. (save-buffer 0)
  2469. (kill-buffer (current-buffer))
  2470. (message "Plain text written to %s" file))))))))
  2471. (set-buffer org-agenda-buffer-name))
  2472. (when open (org-open-file file)))
  2473. (defvar org-agenda-filter-overlays nil)
  2474. (defun org-agenda-mark-filtered-text ()
  2475. "Mark all text hidden by filtering with a text property."
  2476. (let ((inhibit-read-only t))
  2477. (mapc
  2478. (lambda (o)
  2479. (when (equal (overlay-buffer o) (current-buffer))
  2480. (put-text-property
  2481. (overlay-start o) (overlay-end o)
  2482. 'org-filtered t)))
  2483. org-agenda-filter-overlays)))
  2484. (defun org-agenda-unmark-filtered-text ()
  2485. "Remove the filtering text property."
  2486. (let ((inhibit-read-only t))
  2487. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2488. (defun org-agenda-remove-marked-text (property &optional value)
  2489. "Delete all text marked with VALUE of PROPERTY.
  2490. VALUE defaults to t."
  2491. (let (beg)
  2492. (setq value (or value t))
  2493. (while (setq beg (text-property-any (point-min) (point-max)
  2494. property value))
  2495. (delete-region
  2496. beg (or (next-single-property-change beg 'org-filtered)
  2497. (point-max))))))
  2498. (defun org-agenda-add-entry-text ()
  2499. "Add entry text to agenda lines.
  2500. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2501. entry text following headings shown in the agenda.
  2502. Drawers will be excluded, also the line with scheduling/deadline info."
  2503. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2504. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2505. (let (m txt)
  2506. (goto-char (point-min))
  2507. (while (not (eobp))
  2508. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2509. (beginning-of-line 2)
  2510. (setq txt (org-agenda-get-some-entry-text
  2511. m org-agenda-add-entry-text-maxlines " > "))
  2512. (end-of-line 1)
  2513. (if (string-match "\\S-" txt)
  2514. (insert "\n" txt)
  2515. (or (eobp) (forward-char 1))))))))
  2516. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2517. &rest keep)
  2518. "Extract entry text from MARKER, at most N-LINES lines.
  2519. This will ignore drawers etc, just get the text.
  2520. If INDENT is given, prefix every line with this string. If KEEP is
  2521. given, it is a list of symbols, defining stuff that should not be
  2522. removed from the entry content. Currently only `planning' is allowed here."
  2523. (let (txt drawer-re kwd-time-re ind)
  2524. (save-excursion
  2525. (with-current-buffer (marker-buffer marker)
  2526. (if (not (org-mode-p))
  2527. (setq txt "")
  2528. (save-excursion
  2529. (save-restriction
  2530. (widen)
  2531. (goto-char marker)
  2532. (end-of-line 1)
  2533. (setq txt (buffer-substring
  2534. (min (1+ (point)) (point-max))
  2535. (progn (outline-next-heading) (point)))
  2536. drawer-re org-drawer-regexp
  2537. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2538. ".*\n?"))
  2539. (with-temp-buffer
  2540. (insert txt)
  2541. (when org-agenda-add-entry-text-descriptive-links
  2542. (goto-char (point-min))
  2543. (while (org-activate-bracket-links (point-max))
  2544. (add-text-properties (match-beginning 0) (match-end 0)
  2545. '(face org-link))))
  2546. (goto-char (point-min))
  2547. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2548. (set-text-properties (match-beginning 0) (match-end 0)
  2549. nil))
  2550. (goto-char (point-min))
  2551. (while (re-search-forward drawer-re nil t)
  2552. (delete-region
  2553. (match-beginning 0)
  2554. (progn (re-search-forward
  2555. "^[ \t]*:END:.*\n?" nil 'move)
  2556. (point))))
  2557. (unless (member 'planning keep)
  2558. (goto-char (point-min))
  2559. (while (re-search-forward kwd-time-re nil t)
  2560. (replace-match "")))
  2561. (goto-char (point-min))
  2562. (when org-agenda-entry-text-exclude-regexps
  2563. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2564. (while (setq re (pop re-list))
  2565. (goto-char (point-min))
  2566. (while (re-search-forward re nil t)
  2567. (replace-match "")))))
  2568. (goto-char (point-max))
  2569. (skip-chars-backward " \t\n")
  2570. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2571. ;; find and remove min common indentation
  2572. (goto-char (point-min))
  2573. (untabify (point-min) (point-max))
  2574. (setq ind (org-get-indentation))
  2575. (while (not (eobp))
  2576. (unless (looking-at "[ \t]*$")
  2577. (setq ind (min ind (org-get-indentation))))
  2578. (beginning-of-line 2))
  2579. (goto-char (point-min))
  2580. (while (not (eobp))
  2581. (unless (looking-at "[ \t]*$")
  2582. (move-to-column ind)
  2583. (delete-region (point-at-bol) (point)))
  2584. (beginning-of-line 2))
  2585. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2586. (goto-char (point-min))
  2587. (when indent
  2588. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2589. (replace-match indent t t)))
  2590. (goto-char (point-min))
  2591. (while (looking-at "[ \t]*\n") (replace-match ""))
  2592. (goto-char (point-max))
  2593. (when (> (org-current-line)
  2594. n-lines)
  2595. (org-goto-line (1+ n-lines))
  2596. (backward-char 1))
  2597. (setq txt (buffer-substring (point-min) (point)))))))))
  2598. txt))
  2599. (defun org-agenda-collect-markers ()
  2600. "Collect the markers pointing to entries in the agenda buffer."
  2601. (let (m markers)
  2602. (save-excursion
  2603. (goto-char (point-min))
  2604. (while (not (eobp))
  2605. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2606. (org-get-at-bol 'org-marker)))
  2607. (push m markers))
  2608. (beginning-of-line 2)))
  2609. (nreverse markers)))
  2610. (defun org-create-marker-find-array (marker-list)
  2611. "Create a alist of files names with all marker positions in that file."
  2612. (let (f tbl m a p)
  2613. (while (setq m (pop marker-list))
  2614. (setq p (marker-position m)
  2615. f (buffer-file-name (or (buffer-base-buffer
  2616. (marker-buffer m))
  2617. (marker-buffer m))))
  2618. (if (setq a (assoc f tbl))
  2619. (push (marker-position m) (cdr a))
  2620. (push (list f p) tbl)))
  2621. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2622. tbl)))
  2623. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2624. (defun org-check-agenda-marker-table ()
  2625. "Check of the current entry is on the marker list."
  2626. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2627. a)
  2628. (and (setq a (assoc file org-agenda-marker-table))
  2629. (save-match-data
  2630. (save-excursion
  2631. (org-back-to-heading t)
  2632. (member (point) (cdr a)))))))
  2633. (defun org-check-for-org-mode ()
  2634. "Make sure current buffer is in org-mode. Error if not."
  2635. (or (org-mode-p)
  2636. (error "Cannot execute org-mode agenda command on buffer in %s"
  2637. major-mode)))
  2638. (defun org-fit-agenda-window ()
  2639. "Fit the window to the buffer size."
  2640. (and (memq org-agenda-window-setup '(reorganize-frame))
  2641. (fboundp 'fit-window-to-buffer)
  2642. (org-fit-window-to-buffer
  2643. nil
  2644. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2645. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2646. ;;; Agenda prepare and finalize
  2647. (defvar org-agenda-multi nil) ; dynamically scoped
  2648. (defvar org-agenda-buffer-name "*Org Agenda*")
  2649. (defvar org-pre-agenda-window-conf nil)
  2650. (defvar org-agenda-columns-active nil)
  2651. (defvar org-agenda-name nil)
  2652. (defvar org-agenda-filter nil)
  2653. (defvar org-agenda-filter-while-redo nil)
  2654. (defvar org-agenda-filter-preset nil
  2655. "A preset of the tags filter used for secondary agenda filtering.
  2656. This must be a list of strings, each string must be a single tag preceded
  2657. by \"+\" or \"-\".
  2658. This variable should not be set directly, but agenda custom commands can
  2659. bind it in the options section. The preset filter is a global property of
  2660. the entire agenda view. In a block agenda, it will not work reliably to
  2661. define a filter for one of the individual blocks. You need to set it in
  2662. the global options and expect it to be applied to the entire view.")
  2663. (defun org-prepare-agenda (&optional name)
  2664. (setq org-todo-keywords-for-agenda nil)
  2665. (setq org-done-keywords-for-agenda nil)
  2666. (setq org-drawers-for-agenda nil)
  2667. (unless org-agenda-persistent-filter
  2668. (setq org-agenda-filter nil))
  2669. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2670. (if org-agenda-multi
  2671. (progn
  2672. (setq buffer-read-only nil)
  2673. (goto-char (point-max))
  2674. (unless (or (bobp) org-agenda-compact-blocks)
  2675. (insert "\n"
  2676. (if (stringp org-agenda-block-separator)
  2677. org-agenda-block-separator
  2678. (make-string (window-width) org-agenda-block-separator))
  2679. "\n"))
  2680. (narrow-to-region (point) (point-max)))
  2681. (org-agenda-reset-markers)
  2682. (setq org-agenda-contributing-files nil)
  2683. (setq org-agenda-columns-active nil)
  2684. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2685. (setq org-todo-keywords-for-agenda
  2686. (org-uniquify org-todo-keywords-for-agenda))
  2687. (setq org-done-keywords-for-agenda
  2688. (org-uniquify org-done-keywords-for-agenda))
  2689. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2690. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2691. (awin (get-buffer-window abuf)))
  2692. (cond
  2693. ((equal (current-buffer) abuf) nil)
  2694. (awin (select-window awin))
  2695. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2696. ((equal org-agenda-window-setup 'current-window)
  2697. (switch-to-buffer abuf))
  2698. ((equal org-agenda-window-setup 'other-window)
  2699. (org-switch-to-buffer-other-window abuf))
  2700. ((equal org-agenda-window-setup 'other-frame)
  2701. (switch-to-buffer-other-frame abuf))
  2702. ((equal org-agenda-window-setup 'reorganize-frame)
  2703. (delete-other-windows)
  2704. (org-switch-to-buffer-other-window abuf)))
  2705. ;; additional test in case agenda is invoked from within agenda
  2706. ;; buffer via elisp link
  2707. (unless (equal (current-buffer) abuf)
  2708. (switch-to-buffer abuf)))
  2709. (setq buffer-read-only nil)
  2710. (let ((inhibit-read-only t)) (erase-buffer))
  2711. (org-agenda-mode)
  2712. (and name (not org-agenda-name)
  2713. (org-set-local 'org-agenda-name name)))
  2714. (setq buffer-read-only nil))
  2715. (defun org-finalize-agenda ()
  2716. "Finishing touch for the agenda buffer, called just before displaying it."
  2717. (unless org-agenda-multi
  2718. (save-excursion
  2719. (let ((inhibit-read-only t))
  2720. (goto-char (point-min))
  2721. (while (org-activate-bracket-links (point-max))
  2722. (add-text-properties (match-beginning 0) (match-end 0)
  2723. '(face org-link)))
  2724. (org-agenda-align-tags)
  2725. (unless org-agenda-with-colors
  2726. (remove-text-properties (point-min) (point-max) '(face nil))))
  2727. (if (and (boundp 'org-agenda-overriding-columns-format)
  2728. org-agenda-overriding-columns-format)
  2729. (org-set-local 'org-agenda-overriding-columns-format
  2730. org-agenda-overriding-columns-format))
  2731. (if (and (boundp 'org-agenda-view-columns-initially)
  2732. org-agenda-view-columns-initially)
  2733. (org-agenda-columns))
  2734. (when org-agenda-fontify-priorities
  2735. (org-agenda-fontify-priorities))
  2736. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2737. (org-agenda-dim-blocked-tasks))
  2738. (org-agenda-mark-clocking-task)
  2739. (when org-agenda-entry-text-mode
  2740. (org-agenda-entry-text-hide)
  2741. (org-agenda-entry-text-show))
  2742. (if (functionp 'org-habit-insert-consistency-graphs)
  2743. (org-habit-insert-consistency-graphs))
  2744. (run-hooks 'org-finalize-agenda-hook)
  2745. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2746. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2747. (org-agenda-filter-apply org-agenda-filter))
  2748. )))
  2749. (defun org-agenda-mark-clocking-task ()
  2750. "Mark the current clock entry in the agenda if it is present."
  2751. (mapc (lambda (o)
  2752. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2753. (delete-overlay o)))
  2754. (overlays-in (point-min) (point-max)))
  2755. (when (marker-buffer org-clock-hd-marker)
  2756. (save-excursion
  2757. (goto-char (point-min))
  2758. (let (s ov)
  2759. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2760. (goto-char s)
  2761. (when (equal (org-get-at-bol 'org-hd-marker)
  2762. org-clock-hd-marker)
  2763. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2764. (overlay-put ov 'type 'org-agenda-clocking)
  2765. (overlay-put ov 'face 'org-agenda-clocking)
  2766. (overlay-put ov 'help-echo
  2767. "The clock is running in this item")))))))
  2768. (defun org-agenda-fontify-priorities ()
  2769. "Make highest priority lines bold, and lowest italic."
  2770. (interactive)
  2771. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2772. (delete-overlay o)))
  2773. (overlays-in (point-min) (point-max)))
  2774. (save-excursion
  2775. (let ((inhibit-read-only t)
  2776. b e p ov h l)
  2777. (goto-char (point-min))
  2778. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2779. (setq h (or (get-char-property (point) 'org-highest-priority)
  2780. org-highest-priority)
  2781. l (or (get-char-property (point) 'org-lowest-priority)
  2782. org-lowest-priority)
  2783. p (string-to-char (match-string 1))
  2784. b (match-beginning 0)
  2785. e (if (eq org-agenda-fontify-priorities 'cookies)
  2786. (match-end 0)
  2787. (point-at-eol))
  2788. ov (make-overlay b e))
  2789. (overlay-put
  2790. ov 'face
  2791. (cond ((org-face-from-face-or-color
  2792. 'priority nil
  2793. (cdr (assoc p org-priority-faces))))
  2794. ((and (listp org-agenda-fontify-priorities)
  2795. (org-face-from-face-or-color
  2796. 'priority nil
  2797. (cdr (assoc p org-agenda-fontify-priorities)))))
  2798. ((equal p l) 'italic)
  2799. ((equal p h) 'bold)))
  2800. (overlay-put ov 'org-type 'org-priority)))))
  2801. (defun org-agenda-dim-blocked-tasks ()
  2802. "Dim currently blocked TODO's in the agenda display."
  2803. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2804. (delete-overlay o)))
  2805. (overlays-in (point-min) (point-max)))
  2806. (save-excursion
  2807. (let ((inhibit-read-only t)
  2808. (org-depend-tag-blocked nil)
  2809. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2810. org-blocked-by-checkboxes
  2811. invis1 b e p ov h l)
  2812. (goto-char (point-min))
  2813. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2814. (and pos (goto-char (1+ pos))))
  2815. (setq org-blocked-by-checkboxes nil invis1 invis)
  2816. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2817. (when (and marker
  2818. (not (with-current-buffer (marker-buffer marker)
  2819. (save-excursion
  2820. (goto-char marker)
  2821. (if (org-entry-get nil "NOBLOCKING")
  2822. t ;; Never block this entry
  2823. (run-hook-with-args-until-failure
  2824. 'org-blocker-hook
  2825. (list :type 'todo-state-change
  2826. :position marker
  2827. :from 'todo
  2828. :to 'done)))))))
  2829. (if org-blocked-by-checkboxes (setq invis1 nil))
  2830. (setq b (if invis1
  2831. (max (point-min) (1- (point-at-bol)))
  2832. (point-at-bol))
  2833. e (point-at-eol)
  2834. ov (make-overlay b e))
  2835. (if invis1
  2836. (overlay-put ov 'invisible t)
  2837. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2838. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2839. (defvar org-agenda-skip-function nil
  2840. "Function to be called at each match during agenda construction.
  2841. If this function returns nil, the current match should not be skipped.
  2842. Otherwise, the function must return a position from where the search
  2843. should be continued.
  2844. This may also be a Lisp form, it will be evaluated.
  2845. Never set this variable using `setq' or so, because then it will apply
  2846. to all future agenda commands. Instead, bind it with `let' to scope
  2847. it dynamically into the agenda-constructing command. A good way to set
  2848. it is through options in `org-agenda-custom-commands'.")
  2849. (defun org-agenda-skip ()
  2850. "Throw to `:skip' in places that should be skipped.
  2851. Also moves point to the end of the skipped region, so that search can
  2852. continue from there."
  2853. (let ((p (point-at-bol)) to fp)
  2854. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2855. (get-text-property p :org-archived)
  2856. (org-end-of-subtree t)
  2857. (throw :skip t))
  2858. (and org-agenda-skip-comment-trees
  2859. (get-text-property p :org-comment)
  2860. (org-end-of-subtree t)
  2861. (throw :skip t))
  2862. (if (equal (char-after p) ?#) (throw :skip t))
  2863. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2864. (consp org-agenda-skip-function))
  2865. (setq to (save-excursion
  2866. (save-match-data
  2867. (if fp
  2868. (funcall org-agenda-skip-function)
  2869. (eval org-agenda-skip-function))))))
  2870. (goto-char to)
  2871. (throw :skip t))))
  2872. (defvar org-agenda-markers nil
  2873. "List of all currently active markers created by `org-agenda'.")
  2874. (defvar org-agenda-last-marker-time (org-float-time)
  2875. "Creation time of the last agenda marker.")
  2876. (defun org-agenda-new-marker (&optional pos)
  2877. "Return a new agenda marker.
  2878. Org-mode keeps a list of these markers and resets them when they are
  2879. no longer in use."
  2880. (let ((m (copy-marker (or pos (point)))))
  2881. (setq org-agenda-last-marker-time (org-float-time))
  2882. (push m org-agenda-markers)
  2883. m))
  2884. (defun org-agenda-reset-markers ()
  2885. "Reset markers created by `org-agenda'."
  2886. (while org-agenda-markers
  2887. (move-marker (pop org-agenda-markers) nil)))
  2888. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2889. "Save relative positions of markers in region."
  2890. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2891. org-agenda-markers))
  2892. ;;; Entry text mode
  2893. (defun org-agenda-entry-text-show-here ()
  2894. "Add some text from the entry as context to the current line."
  2895. (let (m txt o)
  2896. (setq m (org-get-at-bol 'org-hd-marker))
  2897. (unless (marker-buffer m)
  2898. (error "No marker points to an entry here"))
  2899. (setq txt (concat "\n" (org-no-properties
  2900. (org-agenda-get-some-entry-text
  2901. m org-agenda-entry-text-maxlines " > "))))
  2902. (when (string-match "\\S-" txt)
  2903. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2904. (overlay-put o 'evaporate t)
  2905. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2906. (overlay-put o 'after-string txt))))
  2907. (defun org-agenda-entry-text-show ()
  2908. "Add entry context for all agenda lines."
  2909. (interactive)
  2910. (save-excursion
  2911. (goto-char (point-max))
  2912. (beginning-of-line 1)
  2913. (while (not (bobp))
  2914. (when (org-get-at-bol 'org-hd-marker)
  2915. (org-agenda-entry-text-show-here))
  2916. (beginning-of-line 0))))
  2917. (defun org-agenda-entry-text-hide ()
  2918. "Remove any shown entry context."
  2919. (delq nil
  2920. (mapcar (lambda (o)
  2921. (if (eq (overlay-get o 'org-overlay-type)
  2922. 'agenda-entry-content)
  2923. (progn (delete-overlay o) t)))
  2924. (overlays-in (point-min) (point-max)))))
  2925. (defun org-agenda-get-day-face (date)
  2926. "Return the face DATE should be displayed with."
  2927. (or (and (functionp org-agenda-day-face-function)
  2928. (funcall org-agenda-day-face-function date))
  2929. (cond ((org-agenda-todayp date)
  2930. 'org-agenda-date-today)
  2931. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  2932. 'org-agenda-date-weekend)
  2933. (t 'org-agenda-date))))
  2934. ;;; Agenda timeline
  2935. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2936. (defun org-timeline (&optional include-all)
  2937. "Show a time-sorted view of the entries in the current org file.
  2938. Only entries with a time stamp of today or later will be listed. With
  2939. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2940. under the current date.
  2941. If the buffer contains an active region, only check the region for
  2942. dates."
  2943. (interactive "P")
  2944. (org-compile-prefix-format 'timeline)
  2945. (org-set-sorting-strategy 'timeline)
  2946. (let* ((dopast t)
  2947. (dotodo include-all)
  2948. (doclosed org-agenda-show-log)
  2949. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2950. (current-buffer))))
  2951. (date (calendar-current-date))
  2952. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2953. (end (if (org-region-active-p) (region-end) (point-max)))
  2954. (day-numbers (org-get-all-dates beg end 'no-ranges
  2955. t doclosed ; always include today
  2956. org-timeline-show-empty-dates))
  2957. (org-deadline-warning-days 0)
  2958. (org-agenda-only-exact-dates t)
  2959. (today (org-today))
  2960. (past t)
  2961. args
  2962. s e rtn d emptyp)
  2963. (setq org-agenda-redo-command
  2964. (list 'progn
  2965. (list 'org-switch-to-buffer-other-window (current-buffer))
  2966. (list 'org-timeline (list 'quote include-all))))
  2967. (if (not dopast)
  2968. ;; Remove past dates from the list of dates.
  2969. (setq day-numbers (delq nil (mapcar (lambda(x)
  2970. (if (>= x today) x nil))
  2971. day-numbers))))
  2972. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2973. (if doclosed (push :closed args))
  2974. (push :timestamp args)
  2975. (push :deadline args)
  2976. (push :scheduled args)
  2977. (push :sexp args)
  2978. (if dotodo (push :todo args))
  2979. (insert "Timeline of file " entry "\n")
  2980. (add-text-properties (point-min) (point)
  2981. (list 'face 'org-agenda-structure))
  2982. (org-agenda-mark-header-line (point-min))
  2983. (while (setq d (pop day-numbers))
  2984. (if (and (listp d) (eq (car d) :omitted))
  2985. (progn
  2986. (setq s (point))
  2987. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2988. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2989. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2990. (if (and (>= d today)
  2991. dopast
  2992. past)
  2993. (progn
  2994. (setq past nil)
  2995. (insert (make-string 79 ?-) "\n")))
  2996. (setq date (calendar-gregorian-from-absolute d))
  2997. (setq s (point))
  2998. (setq rtn (and (not emptyp)
  2999. (apply 'org-agenda-get-day-entries entry
  3000. date args)))
  3001. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3002. (progn
  3003. (insert
  3004. (if (stringp org-agenda-format-date)
  3005. (format-time-string org-agenda-format-date
  3006. (org-time-from-absolute date))
  3007. (funcall org-agenda-format-date date))
  3008. "\n")
  3009. (put-text-property s (1- (point)) 'face
  3010. (org-agenda-get-day-face date))
  3011. (put-text-property s (1- (point)) 'org-date-line t)
  3012. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3013. (if (equal d today)
  3014. (put-text-property s (1- (point)) 'org-today t))
  3015. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3016. (put-text-property s (1- (point)) 'day d)))))
  3017. (goto-char (point-min))
  3018. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3019. (point-min)))
  3020. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3021. (org-finalize-agenda)
  3022. (setq buffer-read-only t)))
  3023. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3024. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3025. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3026. not every single day in the range. If FORCE-TODAY is non-nil, make
  3027. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3028. inactive time stamps (those in square brackets) are included.
  3029. When EMPTY is non-nil, also include days without any entries."
  3030. (let ((re (concat
  3031. (if pre-re pre-re "")
  3032. (if inactive org-ts-regexp-both org-ts-regexp)))
  3033. dates dates1 date day day1 day2 ts1 ts2)
  3034. (if force-today
  3035. (setq dates (list (org-today))))
  3036. (save-excursion
  3037. (goto-char beg)
  3038. (while (re-search-forward re end t)
  3039. (setq day (time-to-days (org-time-string-to-time
  3040. (substring (match-string 1) 0 10))))
  3041. (or (memq day dates) (push day dates)))
  3042. (unless no-ranges
  3043. (goto-char beg)
  3044. (while (re-search-forward org-tr-regexp end t)
  3045. (setq ts1 (substring (match-string 1) 0 10)
  3046. ts2 (substring (match-string 2) 0 10)
  3047. day1 (time-to-days (org-time-string-to-time ts1))
  3048. day2 (time-to-days (org-time-string-to-time ts2)))
  3049. (while (< (setq day1 (1+ day1)) day2)
  3050. (or (memq day1 dates) (push day1 dates)))))
  3051. (setq dates (sort dates '<))
  3052. (when empty
  3053. (while (setq day (pop dates))
  3054. (setq day2 (car dates))
  3055. (push day dates1)
  3056. (when (and day2 empty)
  3057. (if (or (eq empty t)
  3058. (and (numberp empty) (<= (- day2 day) empty)))
  3059. (while (< (setq day (1+ day)) day2)
  3060. (push (list day) dates1))
  3061. (push (cons :omitted (- day2 day)) dates1))))
  3062. (setq dates (nreverse dates1)))
  3063. dates)))
  3064. ;;; Agenda Daily/Weekly
  3065. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  3066. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3067. "Custom commands can set this variable in the options section.")
  3068. (defvar org-agenda-last-arguments nil
  3069. "The arguments of the previous call to `org-agenda'.")
  3070. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3071. (defvar org-agenda-current-span nil
  3072. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3073. (defvar org-include-all-loc nil) ; local variable
  3074. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3075. "List of types searched for when creating the daily/weekly agenda.
  3076. This variable is a list of symbols that controls the types of
  3077. items that appear in the daily/weekly agenda. Allowed symbols in this
  3078. list are are
  3079. :timestamp List items containing a date stamp or date range matching
  3080. the selected date. This includes sexp entries in
  3081. angular brackets.
  3082. :sexp List entries resulting from plain diary-like sexps.
  3083. :deadline List deadline due on that date. When the date is today,
  3084. also list any deadlines past due, or due within
  3085. `org-deadline-warning-days'. `:deadline' must appear before
  3086. `:scheduled' if the setting of
  3087. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3088. any effect.
  3089. :scheduled List all items which are scheduled for the given date.
  3090. The diary for *today* also contains items which were
  3091. scheduled earlier and are not yet marked DONE.
  3092. By default, all four types are turned on.
  3093. Never set this variable globally using `setq', because then it
  3094. will apply to all future agenda commands. Instead, bind it with
  3095. `let' to scope it dynamically into the the agenda-constructing
  3096. command. A good way to set it is through options in
  3097. `org-agenda-custom-commands'. For a more flexible (though
  3098. somewhat less efficient) way of determining what is included in
  3099. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3100. ;;;###autoload
  3101. (defun org-agenda-list (&optional include-all start-day span)
  3102. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3103. The view will be for the current day or week, but from the overview buffer
  3104. you will be able to go to other days/weeks.
  3105. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3106. all unfinished TODO items will also be shown, before the agenda.
  3107. This feature is considered obsolete, please use the TODO list or a block
  3108. agenda instead.
  3109. With a numeric prefix argument in an interactive call, the agenda will
  3110. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3111. the number of days. SPAN defaults to `org-agenda-span'.
  3112. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3113. given in `org-agenda-start-on-weekday'."
  3114. (interactive "P")
  3115. (if (and (integerp include-all) (> include-all 0))
  3116. (setq span include-all include-all nil))
  3117. (setq start-day (or start-day org-agenda-start-day))
  3118. (if org-agenda-overriding-arguments
  3119. (setq include-all (car org-agenda-overriding-arguments)
  3120. start-day (nth 1 org-agenda-overriding-arguments)
  3121. span (nth 2 org-agenda-overriding-arguments)))
  3122. (if (stringp start-day)
  3123. ;; Convert to an absolute day number
  3124. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3125. (setq org-agenda-last-arguments (list include-all start-day span))
  3126. (org-compile-prefix-format 'agenda)
  3127. (org-set-sorting-strategy 'agenda)
  3128. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
  3129. (today (org-today))
  3130. (sd (or start-day today))
  3131. (ndays (org-agenda-span-to-ndays span sd))
  3132. (org-agenda-start-on-weekday
  3133. (if (eq ndays 7)
  3134. org-agenda-start-on-weekday))
  3135. (thefiles (org-agenda-files nil 'ifmode))
  3136. (files thefiles)
  3137. (start (if (or (null org-agenda-start-on-weekday)
  3138. (< ndays 7))
  3139. sd
  3140. (let* ((nt (calendar-day-of-week
  3141. (calendar-gregorian-from-absolute sd)))
  3142. (n1 org-agenda-start-on-weekday)
  3143. (d (- nt n1)))
  3144. (- sd (+ (if (< d 0) 7 0) d)))))
  3145. (day-numbers (list start))
  3146. (day-cnt 0)
  3147. (inhibit-redisplay (not debug-on-error))
  3148. s e rtn rtnall file date d start-pos end-pos todayp
  3149. clocktable-start clocktable-end filter)
  3150. (setq org-agenda-redo-command
  3151. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3152. (dotimes (n (1- ndays))
  3153. (push (1+ (car day-numbers)) day-numbers))
  3154. (setq day-numbers (nreverse day-numbers))
  3155. (setq clocktable-start (car day-numbers)
  3156. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3157. (org-prepare-agenda "Day/Week")
  3158. (org-set-local 'org-starting-day (car day-numbers))
  3159. (org-set-local 'org-include-all-loc include-all)
  3160. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3161. (when (and (or include-all org-agenda-include-all-todo)
  3162. (member today day-numbers))
  3163. (setq files thefiles
  3164. rtnall nil)
  3165. (while (setq file (pop files))
  3166. (catch 'nextfile
  3167. (org-check-agenda-file file)
  3168. (setq date (calendar-gregorian-from-absolute today)
  3169. rtn (org-agenda-get-day-entries
  3170. file date :todo))
  3171. (setq rtnall (append rtnall rtn))))
  3172. (when rtnall
  3173. (insert "All currently open TODO items:\n")
  3174. (add-text-properties (point-min) (1- (point))
  3175. (list 'face 'org-agenda-structure
  3176. 'short-heading "All TODO items"))
  3177. (org-agenda-mark-header-line (point-min))
  3178. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3179. (unless org-agenda-compact-blocks
  3180. (let* ((d1 (car day-numbers))
  3181. (d2 (org-last day-numbers))
  3182. (w1 (org-days-to-iso-week d1))
  3183. (w2 (org-days-to-iso-week d2)))
  3184. (setq s (point))
  3185. (if org-agenda-overriding-header
  3186. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3187. nil 'face 'org-agenda-structure) "\n")
  3188. (insert (org-agenda-span-name span)
  3189. "-agenda"
  3190. (if (< (- d2 d1) 350)
  3191. (if (= w1 w2)
  3192. (format " (W%02d)" w1)
  3193. (format " (W%02d-W%02d)" w1 w2))
  3194. "")
  3195. ":\n")))
  3196. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3197. 'org-date-line t))
  3198. (org-agenda-mark-header-line s))
  3199. (while (setq d (pop day-numbers))
  3200. (setq date (calendar-gregorian-from-absolute d)
  3201. s (point))
  3202. (if (or (setq todayp (= d today))
  3203. (and (not start-pos) (= d sd)))
  3204. (setq start-pos (point))
  3205. (if (and start-pos (not end-pos))
  3206. (setq end-pos (point))))
  3207. (setq files thefiles
  3208. rtnall nil)
  3209. (while (setq file (pop files))
  3210. (catch 'nextfile
  3211. (org-check-agenda-file file)
  3212. (let ((org-agenda-entry-types org-agenda-entry-types))
  3213. (unless org-agenda-include-deadlines
  3214. (setq org-agenda-entry-types
  3215. (delq :deadline org-agenda-entry-types)))
  3216. (cond
  3217. ((eq org-agenda-show-log 'only)
  3218. (setq rtn (org-agenda-get-day-entries
  3219. file date :closed)))
  3220. (org-agenda-show-log
  3221. (setq rtn (apply 'org-agenda-get-day-entries
  3222. file date
  3223. (append '(:closed) org-agenda-entry-types))))
  3224. (t
  3225. (setq rtn (apply 'org-agenda-get-day-entries
  3226. file date
  3227. org-agenda-entry-types)))))
  3228. (setq rtnall (append rtnall rtn))))
  3229. (if org-agenda-include-diary
  3230. (let ((org-agenda-search-headline-for-time t))
  3231. (require 'diary-lib)
  3232. (setq rtn (org-get-entries-from-diary date))
  3233. (setq rtnall (append rtnall rtn))))
  3234. (if (or rtnall org-agenda-show-all-dates)
  3235. (progn
  3236. (setq day-cnt (1+ day-cnt))
  3237. (insert
  3238. (if (stringp org-agenda-format-date)
  3239. (format-time-string org-agenda-format-date
  3240. (org-time-from-absolute date))
  3241. (funcall org-agenda-format-date date))
  3242. "\n")
  3243. (put-text-property s (1- (point)) 'face
  3244. (org-agenda-get-day-face date))
  3245. (put-text-property s (1- (point)) 'org-date-line t)
  3246. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3247. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3248. (when todayp
  3249. (put-text-property s (1- (point)) 'org-today t))
  3250. (if rtnall (insert
  3251. (org-finalize-agenda-entries
  3252. (org-agenda-add-time-grid-maybe
  3253. rtnall ndays todayp))
  3254. "\n"))
  3255. (put-text-property s (1- (point)) 'day d)
  3256. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3257. (when (and org-agenda-clockreport-mode clocktable-start)
  3258. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3259. ;; the above line is to ensure the restricted range!
  3260. (p org-agenda-clockreport-parameter-plist)
  3261. tbl)
  3262. (setq p (org-plist-delete p :block))
  3263. (setq p (plist-put p :tstart clocktable-start))
  3264. (setq p (plist-put p :tend clocktable-end))
  3265. (setq p (plist-put p :scope 'agenda))
  3266. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3267. (setq filter (or org-agenda-filter-while-redo
  3268. (get 'org-agenda-filter :preset-filter))))
  3269. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3270. (if (string-match "[<>=]" x)
  3271. ""
  3272. x))
  3273. filter ""))))
  3274. (message "%s" (plist-get p :tags)) (sit-for 2)
  3275. (setq tbl (apply 'org-get-clocktable p))
  3276. (insert tbl)))
  3277. (goto-char (point-min))
  3278. (or org-agenda-multi (org-fit-agenda-window))
  3279. (unless (and (pos-visible-in-window-p (point-min))
  3280. (pos-visible-in-window-p (point-max)))
  3281. (goto-char (1- (point-max)))
  3282. (recenter -1)
  3283. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3284. (progn
  3285. (goto-char (or start-pos 1))
  3286. (recenter 1))))
  3287. (goto-char (or start-pos 1))
  3288. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3289. (org-finalize-agenda)
  3290. (setq buffer-read-only t)
  3291. (message "")))
  3292. (defun org-agenda-ndays-to-span (n)
  3293. "Return a span symbol for a span of N days, or N if none matches."
  3294. (cond ((symbolp n) n)
  3295. ((= n 1) 'day)
  3296. ((= n 7) 'week)
  3297. (t n)))
  3298. (defun org-agenda-span-to-ndays (span start-day)
  3299. "Return ndays from SPAN starting at START-DAY."
  3300. (cond ((numberp span) span)
  3301. ((eq span 'day) 1)
  3302. ((eq span 'week) 7)
  3303. ((eq span 'month)
  3304. (let ((date (calendar-gregorian-from-absolute start-day)))
  3305. (calendar-last-day-of-month (car date) (caddr date))))
  3306. ((eq span 'year)
  3307. (let ((date (calendar-gregorian-from-absolute start-day)))
  3308. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3309. (defun org-agenda-span-name (span)
  3310. "Return a SPAN name."
  3311. (if (null span)
  3312. ""
  3313. (if (symbolp span)
  3314. (capitalize (symbol-name span))
  3315. (format "%d days" span))))
  3316. ;;; Agenda word search
  3317. (defvar org-agenda-search-history nil)
  3318. (defvar org-todo-only nil)
  3319. (defvar org-search-syntax-table nil
  3320. "Special syntax table for org-mode search.
  3321. In this table, we have single quotes not as word constituents, to
  3322. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3323. (defun org-search-syntax-table ()
  3324. (unless org-search-syntax-table
  3325. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3326. (modify-syntax-entry ?' "." org-search-syntax-table)
  3327. (modify-syntax-entry ?` "." org-search-syntax-table))
  3328. org-search-syntax-table)
  3329. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3330. ;;;###autoload
  3331. (defun org-search-view (&optional todo-only string edit-at)
  3332. "Show all entries that contain a phrase or words or regular expressions.
  3333. With optional prefix argument TODO-ONLY, only consider entries that are
  3334. TODO entries. The argument STRING can be used to pass a default search
  3335. string into this function. If EDIT-AT is non-nil, it means that the
  3336. user should get a chance to edit this string, with cursor at position
  3337. EDIT-AT.
  3338. The search string can be viewed either as a phrase that should be found as
  3339. is, or it can be broken into a number of snippets, each of which must match
  3340. in a Boolean way to select an entry. The default depends on the variable
  3341. `org-agenda-search-view-always-boolean'.
  3342. Even if this is turned off (the default) you can always switch to
  3343. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3344. The default is a direct search of the whole phrase, where each space in
  3345. the search string can expand to an arbitrary amount of whitespace,
  3346. including newlines.
  3347. If using a Boolean search, the search string is split on whitespace and
  3348. each snippet is searched separately, with logical AND to select an entry.
  3349. Words prefixed with a minus must *not* occur in the entry. Words without
  3350. a prefix or prefixed with a plus must occur in the entry. Matching is
  3351. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3352. match whole words, not parts of a word) if
  3353. `org-agenda-search-view-force-full-words' is set (default is nil).
  3354. Boolean search snippets enclosed by curly braces are interpreted as
  3355. regular expressions that must or (when preceded with \"-\") must not
  3356. match in the entry. Snippets enclosed into double quotes will be taken
  3357. as a whole, to include whitespace.
  3358. - If the search string starts with an asterisk, search only in headlines.
  3359. - If (possibly after the leading star) the search string starts with an
  3360. exclamation mark, this also means to look at TODO entries only, an effect
  3361. that can also be achieved with a prefix argument.
  3362. - If (possibly after star and exclamation mark) the search string starts
  3363. with a colon, this will mean that the (non-regexp) snippets of the
  3364. Boolean search must match as full words.
  3365. This command searches the agenda files, and in addition the files listed
  3366. in `org-agenda-text-search-extra-files'."
  3367. (interactive "P")
  3368. (org-compile-prefix-format 'search)
  3369. (org-set-sorting-strategy 'search)
  3370. (org-prepare-agenda "SEARCH")
  3371. (let* ((props (list 'face nil
  3372. 'done-face 'org-agenda-done
  3373. 'org-not-done-regexp org-not-done-regexp
  3374. 'org-todo-regexp org-todo-regexp
  3375. 'org-complex-heading-regexp org-complex-heading-regexp
  3376. 'mouse-face 'highlight
  3377. 'help-echo (format "mouse-2 or RET jump to location")))
  3378. (full-words org-agenda-search-view-force-full-words)
  3379. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3380. regexp rtn rtnall files file pos
  3381. marker category tags c neg re boolean
  3382. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3383. (unless (and (not edit-at)
  3384. (stringp string)
  3385. (string-match "\\S-" string))
  3386. (setq string (read-string
  3387. (if org-agenda-search-view-always-boolean
  3388. "[+-]Word/{Regexp} ...: "
  3389. "Phrase, or [+-]Word/{Regexp} ...: ")
  3390. (cond
  3391. ((integerp edit-at) (cons string edit-at))
  3392. (edit-at string))
  3393. 'org-agenda-search-history)))
  3394. (org-set-local 'org-todo-only todo-only)
  3395. (setq org-agenda-redo-command
  3396. (list 'org-search-view (if todo-only t nil) string
  3397. '(if current-prefix-arg 1 nil)))
  3398. (setq org-agenda-query-string string)
  3399. (if (equal (string-to-char string) ?*)
  3400. (setq hdl-only t
  3401. words (substring string 1))
  3402. (setq words string))
  3403. (when (equal (string-to-char words) ?!)
  3404. (setq todo-only t
  3405. words (substring words 1)))
  3406. (when (equal (string-to-char words) ?:)
  3407. (setq full-words t
  3408. words (substring words 1)))
  3409. (if (or org-agenda-search-view-always-boolean
  3410. (member (string-to-char words) '(?- ?+ ?\{)))
  3411. (setq boolean t))
  3412. (setq words (org-split-string words))
  3413. (let (www w)
  3414. (while (setq w (pop words))
  3415. (while (and (string-match "\\\\\\'" w) words)
  3416. (setq w (concat (substring w 0 -1) " " (pop words))))
  3417. (push w www))
  3418. (setq words (nreverse www) www nil)
  3419. (while (setq w (pop words))
  3420. (when (and (string-match "\\`[-+]?{" w)
  3421. (not (string-match "}\\'" w)))
  3422. (while (and words (not (string-match "}\\'" (car words))))
  3423. (setq w (concat w " " (pop words))))
  3424. (setq w (concat w " " (pop words))))
  3425. (push w www))
  3426. (setq words (nreverse www)))
  3427. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3428. (when boolean
  3429. (let (wds w)
  3430. (while (setq w (pop words))
  3431. (if (or (equal (substring w 0 1) "\"")
  3432. (and (> (length w) 1)
  3433. (member (substring w 0 1) '("+" "-"))
  3434. (equal (substring w 1 2) "\"")))
  3435. (while (and words (not (equal (substring w -1) "\"")))
  3436. (setq w (concat w " " (pop words)))))
  3437. (and (string-match "\\`\\([-+]?\\)\"" w)
  3438. (setq w (replace-match "\\1" nil nil w)))
  3439. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3440. (push w wds))
  3441. (setq words (nreverse wds))))
  3442. (if boolean
  3443. (mapc (lambda (w)
  3444. (setq c (string-to-char w))
  3445. (if (equal c ?-)
  3446. (setq neg t w (substring w 1))
  3447. (if (equal c ?+)
  3448. (setq neg nil w (substring w 1))
  3449. (setq neg nil)))
  3450. (if (string-match "\\`{.*}\\'" w)
  3451. (setq re (substring w 1 -1))
  3452. (if full-words
  3453. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3454. (setq re (regexp-quote (downcase w)))))
  3455. (if neg (push re regexps-) (push re regexps+)))
  3456. words)
  3457. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3458. regexps+))
  3459. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3460. (if (not regexps+)
  3461. (setq regexp (concat "^" org-outline-regexp))
  3462. (setq regexp (pop regexps+))
  3463. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3464. regexp))))
  3465. (setq files (org-agenda-files nil 'ifmode))
  3466. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3467. (pop org-agenda-text-search-extra-files)
  3468. (setq files (org-add-archive-files files)))
  3469. (setq files (append files org-agenda-text-search-extra-files)
  3470. rtnall nil)
  3471. (while (setq file (pop files))
  3472. (setq ee nil)
  3473. (catch 'nextfile
  3474. (org-check-agenda-file file)
  3475. (setq buffer (if (file-exists-p file)
  3476. (org-get-agenda-file-buffer file)
  3477. (error "No such file %s" file)))
  3478. (if (not buffer)
  3479. ;; If file does not exist, make sure an error message is sent
  3480. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3481. file))))
  3482. (with-current-buffer buffer
  3483. (with-syntax-table (org-search-syntax-table)
  3484. (unless (org-mode-p)
  3485. (error "Agenda file %s is not in `org-mode'" file))
  3486. (let ((case-fold-search t))
  3487. (save-excursion
  3488. (save-restriction
  3489. (if org-agenda-restrict
  3490. (narrow-to-region org-agenda-restrict-begin
  3491. org-agenda-restrict-end)
  3492. (widen))
  3493. (goto-char (point-min))
  3494. (unless (or (org-on-heading-p)
  3495. (outline-next-heading))
  3496. (throw 'nextfile t))
  3497. (goto-char (max (point-min) (1- (point))))
  3498. (while (re-search-forward regexp nil t)
  3499. (org-back-to-heading t)
  3500. (skip-chars-forward "* ")
  3501. (setq beg (point-at-bol)
  3502. beg1 (point)
  3503. end (progn (outline-next-heading) (point)))
  3504. (catch :skip
  3505. (goto-char beg)
  3506. (org-agenda-skip)
  3507. (setq str (buffer-substring-no-properties
  3508. (point-at-bol)
  3509. (if hdl-only (point-at-eol) end)))
  3510. (mapc (lambda (wr) (when (string-match wr str)
  3511. (goto-char (1- end))
  3512. (throw :skip t)))
  3513. regexps-)
  3514. (mapc (lambda (wr) (unless (string-match wr str)
  3515. (goto-char (1- end))
  3516. (throw :skip t)))
  3517. (if todo-only
  3518. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3519. regexps+)
  3520. regexps+))
  3521. (goto-char beg)
  3522. (setq marker (org-agenda-new-marker (point))
  3523. category (org-get-category)
  3524. tags (org-get-tags-at (point))
  3525. txt (org-format-agenda-item
  3526. ""
  3527. (buffer-substring-no-properties
  3528. beg1 (point-at-eol))
  3529. category tags))
  3530. (org-add-props txt props
  3531. 'org-marker marker 'org-hd-marker marker
  3532. 'org-todo-regexp org-todo-regexp
  3533. 'org-complex-heading-regexp org-complex-heading-regexp
  3534. 'priority 1000 'org-category category
  3535. 'type "search")
  3536. (push txt ee)
  3537. (goto-char (1- end))))))))))
  3538. (setq rtn (nreverse ee))
  3539. (setq rtnall (append rtnall rtn)))
  3540. (if org-agenda-overriding-header
  3541. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3542. nil 'face 'org-agenda-structure) "\n")
  3543. (insert "Search words: ")
  3544. (add-text-properties (point-min) (1- (point))
  3545. (list 'face 'org-agenda-structure))
  3546. (setq pos (point))
  3547. (insert string "\n")
  3548. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3549. (setq pos (point))
  3550. (unless org-agenda-multi
  3551. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3552. (add-text-properties pos (1- (point))
  3553. (list 'face 'org-agenda-structure))))
  3554. (org-agenda-mark-header-line (point-min))
  3555. (when rtnall
  3556. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3557. (goto-char (point-min))
  3558. (or org-agenda-multi (org-fit-agenda-window))
  3559. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3560. (org-finalize-agenda)
  3561. (setq buffer-read-only t)))
  3562. ;;; Agenda TODO list
  3563. (defvar org-select-this-todo-keyword nil)
  3564. (defvar org-last-arg nil)
  3565. ;;;###autoload
  3566. (defun org-todo-list (arg)
  3567. "Show all (not done) TODO entries from all agenda file in a single list.
  3568. The prefix arg can be used to select a specific TODO keyword and limit
  3569. the list to these. When using \\[universal-argument], you will be prompted
  3570. for a keyword. A numeric prefix directly selects the Nth keyword in
  3571. `org-todo-keywords-1'."
  3572. (interactive "P")
  3573. (org-compile-prefix-format 'todo)
  3574. (org-set-sorting-strategy 'todo)
  3575. (org-prepare-agenda "TODO")
  3576. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3577. (let* ((today (org-today))
  3578. (date (calendar-gregorian-from-absolute today))
  3579. (kwds org-todo-keywords-for-agenda)
  3580. (completion-ignore-case t)
  3581. (org-select-this-todo-keyword
  3582. (if (stringp arg) arg
  3583. (and arg (integerp arg) (> arg 0)
  3584. (nth (1- arg) kwds))))
  3585. rtn rtnall files file pos)
  3586. (when (equal arg '(4))
  3587. (setq org-select-this-todo-keyword
  3588. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3589. (mapcar 'list kwds) nil nil)))
  3590. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3591. (org-set-local 'org-last-arg arg)
  3592. (setq org-agenda-redo-command
  3593. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3594. (setq files (org-agenda-files nil 'ifmode)
  3595. rtnall nil)
  3596. (while (setq file (pop files))
  3597. (catch 'nextfile
  3598. (org-check-agenda-file file)
  3599. (setq rtn (org-agenda-get-day-entries file date :todo))
  3600. (setq rtnall (append rtnall rtn))))
  3601. (if org-agenda-overriding-header
  3602. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3603. nil 'face 'org-agenda-structure) "\n")
  3604. (insert "Global list of TODO items of type: ")
  3605. (add-text-properties (point-min) (1- (point))
  3606. (list 'face 'org-agenda-structure
  3607. 'short-heading
  3608. (concat "ToDo: "
  3609. (or org-select-this-todo-keyword "ALL"))))
  3610. (org-agenda-mark-header-line (point-min))
  3611. (setq pos (point))
  3612. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3613. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3614. (setq pos (point))
  3615. (unless org-agenda-multi
  3616. (insert "Available with `N r': (0)ALL")
  3617. (let ((n 0) s)
  3618. (mapc (lambda (x)
  3619. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3620. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3621. (insert "\n "))
  3622. (insert " " s))
  3623. kwds))
  3624. (insert "\n"))
  3625. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3626. (org-agenda-mark-header-line (point-min))
  3627. (when rtnall
  3628. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3629. (goto-char (point-min))
  3630. (or org-agenda-multi (org-fit-agenda-window))
  3631. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3632. (org-finalize-agenda)
  3633. (setq buffer-read-only t)))
  3634. ;;; Agenda tags match
  3635. ;;;###autoload
  3636. (defun org-tags-view (&optional todo-only match)
  3637. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3638. The prefix arg TODO-ONLY limits the search to TODO entries."
  3639. (interactive "P")
  3640. (org-compile-prefix-format 'tags)
  3641. (org-set-sorting-strategy 'tags)
  3642. (let* ((org-tags-match-list-sublevels
  3643. org-tags-match-list-sublevels)
  3644. (completion-ignore-case t)
  3645. rtn rtnall files file pos matcher
  3646. buffer)
  3647. (when (and (stringp match) (not (string-match "\\S-" match)))
  3648. (setq match nil))
  3649. (setq matcher (org-make-tags-matcher match)
  3650. match (car matcher) matcher (cdr matcher))
  3651. (org-prepare-agenda (concat "TAGS " match))
  3652. (setq org-agenda-query-string match)
  3653. (setq org-agenda-redo-command
  3654. (list 'org-tags-view (list 'quote todo-only)
  3655. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3656. (setq files (org-agenda-files nil 'ifmode)
  3657. rtnall nil)
  3658. (while (setq file (pop files))
  3659. (catch 'nextfile
  3660. (org-check-agenda-file file)
  3661. (setq buffer (if (file-exists-p file)
  3662. (org-get-agenda-file-buffer file)
  3663. (error "No such file %s" file)))
  3664. (if (not buffer)
  3665. ;; If file does not exist, error message to agenda
  3666. (setq rtn (list
  3667. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3668. rtnall (append rtnall rtn))
  3669. (with-current-buffer buffer
  3670. (unless (org-mode-p)
  3671. (error "Agenda file %s is not in `org-mode'" file))
  3672. (save-excursion
  3673. (save-restriction
  3674. (if org-agenda-restrict
  3675. (narrow-to-region org-agenda-restrict-begin
  3676. org-agenda-restrict-end)
  3677. (widen))
  3678. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3679. (setq rtnall (append rtnall rtn))))))))
  3680. (if org-agenda-overriding-header
  3681. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3682. nil 'face 'org-agenda-structure) "\n")
  3683. (insert "Headlines with TAGS match: ")
  3684. (add-text-properties (point-min) (1- (point))
  3685. (list 'face 'org-agenda-structure
  3686. 'short-heading
  3687. (concat "Match: " match)))
  3688. (setq pos (point))
  3689. (insert match "\n")
  3690. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3691. (setq pos (point))
  3692. (unless org-agenda-multi
  3693. (insert "Press `C-u r' to search again with new search string\n"))
  3694. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3695. (org-agenda-mark-header-line (point-min))
  3696. (when rtnall
  3697. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3698. (goto-char (point-min))
  3699. (or org-agenda-multi (org-fit-agenda-window))
  3700. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3701. (org-finalize-agenda)
  3702. (setq buffer-read-only t)))
  3703. ;;; Agenda Finding stuck projects
  3704. (defvar org-agenda-skip-regexp nil
  3705. "Regular expression used in skipping subtrees for the agenda.
  3706. This is basically a temporary global variable that can be set and then
  3707. used by user-defined selections using `org-agenda-skip-function'.")
  3708. (defvar org-agenda-overriding-header nil
  3709. "When this is set during todo and tags searches, will replace header.
  3710. This variable should not be set directly, but custom commands can bind it
  3711. in the options section.")
  3712. (defun org-agenda-skip-entry-when-regexp-matches ()
  3713. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3714. If yes, it returns the end position of this entry, causing agenda commands
  3715. to skip the entry but continuing the search in the subtree. This is a
  3716. function that can be put into `org-agenda-skip-function' for the duration
  3717. of a command."
  3718. (let ((end (save-excursion (org-end-of-subtree t)))
  3719. skip)
  3720. (save-excursion
  3721. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3722. (and skip end)))
  3723. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3724. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3725. If yes, it returns the end position of this tree, causing agenda commands
  3726. to skip this subtree. This is a function that can be put into
  3727. `org-agenda-skip-function' for the duration of a command."
  3728. (let ((end (save-excursion (org-end-of-subtree t)))
  3729. skip)
  3730. (save-excursion
  3731. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3732. (and skip end)))
  3733. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3734. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3735. If yes, it returns the end position of the current entry (NOT the tree),
  3736. causing agenda commands to skip the entry but continuing the search in
  3737. the subtree. This is a function that can be put into
  3738. `org-agenda-skip-function' for the duration of a command. An important
  3739. use of this function is for the stuck project list."
  3740. (let ((end (save-excursion (org-end-of-subtree t)))
  3741. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3742. skip)
  3743. (save-excursion
  3744. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3745. (and skip entry-end)))
  3746. (defun org-agenda-skip-entry-if (&rest conditions)
  3747. "Skip entry if any of CONDITIONS is true.
  3748. See `org-agenda-skip-if' for details."
  3749. (org-agenda-skip-if nil conditions))
  3750. (defun org-agenda-skip-subtree-if (&rest conditions)
  3751. "Skip entry if any of CONDITIONS is true.
  3752. See `org-agenda-skip-if' for details."
  3753. (org-agenda-skip-if t conditions))
  3754. (defun org-agenda-skip-if (subtree conditions)
  3755. "Checks current entity for CONDITIONS.
  3756. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3757. the entry, i.e. the text before the next heading is checked.
  3758. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3759. from different tests. Valid conditions are:
  3760. scheduled Check if there is a scheduled cookie
  3761. notscheduled Check if there is no scheduled cookie
  3762. deadline Check if there is a deadline
  3763. notdeadline Check if there is no deadline
  3764. timestamp Check if there is a timestamp (also deadline or scheduled)
  3765. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3766. regexp Check if regexp matches
  3767. notregexp Check if regexp does not match.
  3768. todo Check if TODO keyword matches
  3769. nottodo Check if TODO keyword does not match
  3770. The regexp is taken from the conditions list, it must come right after
  3771. the `regexp' or `notregexp' element.
  3772. `todo' and `nottodo' accept as an argument a list of todo
  3773. keywords, which may include \"*\" to match any todo keyword.
  3774. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3775. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3776. Instead of a list a keyword class may be given
  3777. (org-agenda-skip-entry-if 'nottodo 'done)
  3778. would skip entries that haven't been marked with any of \"DONE\"
  3779. keywords. Possible classes are: `todo', `done', `any'.
  3780. If any of these conditions is met, this function returns the end point of
  3781. the entity, causing the search to continue from there. This is a function
  3782. that can be put into `org-agenda-skip-function' for the duration of a command."
  3783. (let (beg end m)
  3784. (org-back-to-heading t)
  3785. (setq beg (point)
  3786. end (if subtree
  3787. (progn (org-end-of-subtree t) (point))
  3788. (progn (outline-next-heading) (1- (point)))))
  3789. (goto-char beg)
  3790. (and
  3791. (or
  3792. (and (memq 'scheduled conditions)
  3793. (re-search-forward org-scheduled-time-regexp end t))
  3794. (and (memq 'notscheduled conditions)
  3795. (not (re-search-forward org-scheduled-time-regexp end t)))
  3796. (and (memq 'deadline conditions)
  3797. (re-search-forward org-deadline-time-regexp end t))
  3798. (and (memq 'notdeadline conditions)
  3799. (not (re-search-forward org-deadline-time-regexp end t)))
  3800. (and (memq 'timestamp conditions)
  3801. (re-search-forward org-ts-regexp end t))
  3802. (and (memq 'nottimestamp conditions)
  3803. (not (re-search-forward org-ts-regexp end t)))
  3804. (and (setq m (memq 'regexp conditions))
  3805. (stringp (nth 1 m))
  3806. (re-search-forward (nth 1 m) end t))
  3807. (and (setq m (memq 'notregexp conditions))
  3808. (stringp (nth 1 m))
  3809. (not (re-search-forward (nth 1 m) end t)))
  3810. (and (or
  3811. (setq m (memq 'todo conditions))
  3812. (setq m (memq 'nottodo conditions)))
  3813. (org-agenda-skip-if-todo m end)))
  3814. end)))
  3815. (defun org-agenda-skip-if-todo (args end)
  3816. "Helper function for `org-agenda-skip-if', do not use it directly.
  3817. ARGS is a list with first element either `todo' or `nottodo'.
  3818. The remainder is either a list of TODO keywords, or a state symbol
  3819. `todo' or `done' or `any'."
  3820. (let ((kw (car args))
  3821. (arg (cadr args))
  3822. todo-wds todo-re)
  3823. (setq todo-wds
  3824. (org-uniquify
  3825. (cond
  3826. ((listp arg) ;; list of keywords
  3827. (if (member "*" arg)
  3828. (mapcar 'substring-no-properties org-todo-keywords-1)
  3829. arg))
  3830. ((symbolp arg) ;; keyword class name
  3831. (cond
  3832. ((eq arg 'todo)
  3833. (org-delete-all org-done-keywords
  3834. (mapcar 'substring-no-properties
  3835. org-todo-keywords-1)))
  3836. ((eq arg 'done) org-done-keywords)
  3837. ((eq arg 'any)
  3838. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3839. (setq todo-re
  3840. (concat "^\\*+[ \t]+\\<\\("
  3841. (mapconcat 'identity todo-wds "\\|")
  3842. "\\)\\>"))
  3843. (if (eq kw 'todo)
  3844. (re-search-forward todo-re end t)
  3845. (not (re-search-forward todo-re end t)))))
  3846. ;;;###autoload
  3847. (defun org-agenda-list-stuck-projects (&rest ignore)
  3848. "Create agenda view for projects that are stuck.
  3849. Stuck projects are project that have no next actions. For the definitions
  3850. of what a project is and how to check if it stuck, customize the variable
  3851. `org-stuck-projects'."
  3852. (interactive)
  3853. (let* ((org-agenda-skip-function
  3854. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3855. ;; We could have used org-agenda-skip-if here.
  3856. (org-agenda-overriding-header
  3857. (or org-agenda-overriding-header "List of stuck projects: "))
  3858. (matcher (nth 0 org-stuck-projects))
  3859. (todo (nth 1 org-stuck-projects))
  3860. (todo-wds (if (member "*" todo)
  3861. (progn
  3862. (org-prepare-agenda-buffers (org-agenda-files
  3863. nil 'ifmode))
  3864. (org-delete-all
  3865. org-done-keywords-for-agenda
  3866. (copy-sequence org-todo-keywords-for-agenda)))
  3867. todo))
  3868. (todo-re (concat "^\\*+[ \t]+\\("
  3869. (mapconcat 'identity todo-wds "\\|")
  3870. "\\)\\>"))
  3871. (tags (nth 2 org-stuck-projects))
  3872. (tags-re (if (member "*" tags)
  3873. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3874. (if tags
  3875. (concat "^\\*+ .*:\\("
  3876. (mapconcat 'identity tags "\\|")
  3877. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3878. (gen-re (nth 3 org-stuck-projects))
  3879. (re-list
  3880. (delq nil
  3881. (list
  3882. (if todo todo-re)
  3883. (if tags tags-re)
  3884. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3885. gen-re)))))
  3886. (setq org-agenda-skip-regexp
  3887. (if re-list
  3888. (mapconcat 'identity re-list "\\|")
  3889. (error "No information how to identify unstuck projects")))
  3890. (org-tags-view nil matcher)
  3891. (with-current-buffer org-agenda-buffer-name
  3892. (setq org-agenda-redo-command
  3893. '(org-agenda-list-stuck-projects
  3894. (or current-prefix-arg org-last-arg))))))
  3895. ;;; Diary integration
  3896. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3897. (defvar list-diary-entries-hook)
  3898. (defun org-get-entries-from-diary (date)
  3899. "Get the (Emacs Calendar) diary entries for DATE."
  3900. (require 'diary-lib)
  3901. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3902. (diary-display-hook '(fancy-diary-display))
  3903. (diary-display-function 'fancy-diary-display)
  3904. (pop-up-frames nil)
  3905. (list-diary-entries-hook
  3906. (cons 'org-diary-default-entry list-diary-entries-hook))
  3907. (diary-file-name-prefix-function nil) ; turn this feature off
  3908. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3909. entries
  3910. (org-disable-agenda-to-diary t))
  3911. (save-excursion
  3912. (save-window-excursion
  3913. (funcall (if (fboundp 'diary-list-entries)
  3914. 'diary-list-entries 'list-diary-entries)
  3915. date 1)))
  3916. (if (not (get-buffer diary-fancy-buffer))
  3917. (setq entries nil)
  3918. (with-current-buffer diary-fancy-buffer
  3919. (setq buffer-read-only nil)
  3920. (if (zerop (buffer-size))
  3921. ;; No entries
  3922. (setq entries nil)
  3923. ;; Omit the date and other unnecessary stuff
  3924. (org-agenda-cleanup-fancy-diary)
  3925. ;; Add prefix to each line and extend the text properties
  3926. (if (zerop (buffer-size))
  3927. (setq entries nil)
  3928. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3929. (set-buffer-modified-p nil)
  3930. (kill-buffer diary-fancy-buffer)))
  3931. (when entries
  3932. (setq entries (org-split-string entries "\n"))
  3933. (setq entries
  3934. (mapcar
  3935. (lambda (x)
  3936. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3937. ;; Extend the text properties to the beginning of the line
  3938. (org-add-props x (text-properties-at (1- (length x)) x)
  3939. 'type "diary" 'date date 'face 'org-agenda-diary))
  3940. entries)))))
  3941. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3942. "Hook run when the fancy diary buffer is cleaned up.")
  3943. (defun org-agenda-cleanup-fancy-diary ()
  3944. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3945. This gets rid of the date, the underline under the date, and
  3946. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3947. date. It also removes lines that contain only whitespace."
  3948. (goto-char (point-min))
  3949. (if (looking-at ".*?:[ \t]*")
  3950. (progn
  3951. (replace-match "")
  3952. (re-search-forward "\n=+$" nil t)
  3953. (replace-match "")
  3954. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3955. (re-search-forward "\n=+$" nil t)
  3956. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3957. (goto-char (point-min))
  3958. (while (re-search-forward "^ +\n" nil t)
  3959. (replace-match ""))
  3960. (goto-char (point-min))
  3961. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3962. (replace-match ""))
  3963. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3964. ;; Make sure entries from the diary have the right text properties.
  3965. (eval-after-load "diary-lib"
  3966. '(if (boundp 'diary-modify-entry-list-string-function)
  3967. ;; We can rely on the hook, nothing to do
  3968. nil
  3969. ;; Hook not available, must use advice to make this work
  3970. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3971. "Make the position visible."
  3972. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3973. (stringp string)
  3974. buffer-file-name)
  3975. (setq string (org-modify-diary-entry-string string))))))
  3976. (defun org-modify-diary-entry-string (string)
  3977. "Add text properties to string, allowing org-mode to act on it."
  3978. (org-add-props string nil
  3979. 'mouse-face 'highlight
  3980. 'help-echo (if buffer-file-name
  3981. (format "mouse-2 or RET jump to diary file %s"
  3982. (abbreviate-file-name buffer-file-name))
  3983. "")
  3984. 'org-agenda-diary-link t
  3985. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3986. (defun org-diary-default-entry ()
  3987. "Add a dummy entry to the diary.
  3988. Needed to avoid empty dates which mess up holiday display."
  3989. ;; Catch the error if dealing with the new add-to-diary-alist
  3990. (when org-disable-agenda-to-diary
  3991. (condition-case nil
  3992. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3993. (error
  3994. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3995. (defun org-add-to-diary-list (&rest args)
  3996. (if (fboundp 'diary-add-to-list)
  3997. (apply 'diary-add-to-list args)
  3998. (apply 'add-to-diary-list args)))
  3999. (defvar org-diary-last-run-time nil)
  4000. ;;;###autoload
  4001. (defun org-diary (&rest args)
  4002. "Return diary information from org-files.
  4003. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4004. It accesses org files and extracts information from those files to be
  4005. listed in the diary. The function accepts arguments specifying what
  4006. items should be listed. For a list of arguments allowed here, see the
  4007. variable `org-agenda-entry-types'.
  4008. The call in the diary file should look like this:
  4009. &%%(org-diary) ~/path/to/some/orgfile.org
  4010. Use a separate line for each org file to check. Or, if you omit the file name,
  4011. all files listed in `org-agenda-files' will be checked automatically:
  4012. &%%(org-diary)
  4013. If you don't give any arguments (as in the example above), the default
  4014. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4015. So the example above may also be written as
  4016. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4017. The function expects the lisp variables `entry' and `date' to be provided
  4018. by the caller, because this is how the calendar works. Don't use this
  4019. function from a program - use `org-agenda-get-day-entries' instead."
  4020. (when (> (- (org-float-time)
  4021. org-agenda-last-marker-time)
  4022. 5)
  4023. (org-agenda-reset-markers))
  4024. (org-compile-prefix-format 'agenda)
  4025. (org-set-sorting-strategy 'agenda)
  4026. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4027. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4028. (list entry)
  4029. (org-agenda-files t)))
  4030. (time (org-float-time))
  4031. file rtn results)
  4032. (when (or (not org-diary-last-run-time)
  4033. (> (- time
  4034. org-diary-last-run-time)
  4035. 3))
  4036. (org-prepare-agenda-buffers files))
  4037. (setq org-diary-last-run-time time)
  4038. ;; If this is called during org-agenda, don't return any entries to
  4039. ;; the calendar. Org Agenda will list these entries itself.
  4040. (if org-disable-agenda-to-diary (setq files nil))
  4041. (while (setq file (pop files))
  4042. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4043. (setq results (append results rtn)))
  4044. (if results
  4045. (concat (org-finalize-agenda-entries results) "\n"))))
  4046. ;;; Agenda entry finders
  4047. (defun org-agenda-get-day-entries (file date &rest args)
  4048. "Does the work for `org-diary' and `org-agenda'.
  4049. FILE is the path to a file to be checked for entries. DATE is date like
  4050. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4051. which kind of entries should be extracted. For details about these, see
  4052. the documentation of `org-diary'."
  4053. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4054. (let* ((org-startup-folded nil)
  4055. (org-startup-align-all-tables nil)
  4056. (buffer (if (file-exists-p file)
  4057. (org-get-agenda-file-buffer file)
  4058. (error "No such file %s" file)))
  4059. arg results rtn deadline-results)
  4060. (if (not buffer)
  4061. ;; If file does not exist, make sure an error message ends up in diary
  4062. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4063. (with-current-buffer buffer
  4064. (unless (org-mode-p)
  4065. (error "Agenda file %s is not in `org-mode'" file))
  4066. (let ((case-fold-search nil))
  4067. (save-excursion
  4068. (save-restriction
  4069. (if org-agenda-restrict
  4070. (narrow-to-region org-agenda-restrict-begin
  4071. org-agenda-restrict-end)
  4072. (widen))
  4073. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4074. (while (setq arg (pop args))
  4075. (cond
  4076. ((and (eq arg :todo)
  4077. (equal date (calendar-current-date)))
  4078. (setq rtn (org-agenda-get-todos))
  4079. (setq results (append results rtn)))
  4080. ((eq arg :timestamp)
  4081. (setq rtn (org-agenda-get-blocks))
  4082. (setq results (append results rtn))
  4083. (setq rtn (org-agenda-get-timestamps))
  4084. (setq results (append results rtn)))
  4085. ((eq arg :sexp)
  4086. (setq rtn (org-agenda-get-sexps))
  4087. (setq results (append results rtn)))
  4088. ((eq arg :scheduled)
  4089. (setq rtn (org-agenda-get-scheduled deadline-results))
  4090. (setq results (append results rtn)))
  4091. ((eq arg :closed)
  4092. (setq rtn (org-agenda-get-progress))
  4093. (setq results (append results rtn)))
  4094. ((eq arg :deadline)
  4095. (setq rtn (org-agenda-get-deadlines))
  4096. (setq deadline-results (copy-sequence rtn))
  4097. (setq results (append results rtn))))))))
  4098. results))))
  4099. (defun org-agenda-get-todos ()
  4100. "Return the TODO information for agenda display."
  4101. (let* ((props (list 'face nil
  4102. 'done-face 'org-agenda-done
  4103. 'org-not-done-regexp org-not-done-regexp
  4104. 'org-todo-regexp org-todo-regexp
  4105. 'org-complex-heading-regexp org-complex-heading-regexp
  4106. 'mouse-face 'highlight
  4107. 'help-echo
  4108. (format "mouse-2 or RET jump to org file %s"
  4109. (abbreviate-file-name buffer-file-name))))
  4110. (regexp (concat "^\\*+[ \t]+\\("
  4111. (if org-select-this-todo-keyword
  4112. (if (equal org-select-this-todo-keyword "*")
  4113. org-todo-regexp
  4114. (concat "\\<\\("
  4115. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4116. "\\)\\>"))
  4117. org-not-done-regexp)
  4118. "[^\n\r]*\\)"))
  4119. marker priority category tags todo-state
  4120. ee txt beg end)
  4121. (goto-char (point-min))
  4122. (while (re-search-forward regexp nil t)
  4123. (catch :skip
  4124. (save-match-data
  4125. (beginning-of-line)
  4126. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4127. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4128. (goto-char (1+ beg))
  4129. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4130. (throw :skip nil)))
  4131. (goto-char beg)
  4132. (org-agenda-skip)
  4133. (goto-char (match-beginning 1))
  4134. (setq marker (org-agenda-new-marker (match-beginning 0))
  4135. category (org-get-category)
  4136. txt (match-string 1)
  4137. tags (org-get-tags-at (point))
  4138. txt (org-format-agenda-item "" txt category tags)
  4139. priority (1+ (org-get-priority txt))
  4140. todo-state (org-get-todo-state))
  4141. (org-add-props txt props
  4142. 'org-marker marker 'org-hd-marker marker
  4143. 'priority priority 'org-category category
  4144. 'type "todo" 'todo-state todo-state)
  4145. (push txt ee)
  4146. (if org-agenda-todo-list-sublevels
  4147. (goto-char (match-end 1))
  4148. (org-end-of-subtree 'invisible))))
  4149. (nreverse ee)))
  4150. ;;;###autoload
  4151. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4152. (&optional end)
  4153. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4154. (when (or org-agenda-todo-ignore-with-date
  4155. org-agenda-todo-ignore-scheduled
  4156. org-agenda-todo-ignore-deadlines
  4157. org-agenda-todo-ignore-timestamp)
  4158. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4159. (save-excursion
  4160. (or (and org-agenda-todo-ignore-with-date
  4161. (re-search-forward org-ts-regexp end t))
  4162. (and org-agenda-todo-ignore-scheduled
  4163. (re-search-forward org-scheduled-time-regexp end t)
  4164. (cond
  4165. ((eq org-agenda-todo-ignore-scheduled 'future)
  4166. (> (org-days-to-time (match-string 1)) 0))
  4167. ((eq org-agenda-todo-ignore-scheduled 'past)
  4168. (<= (org-days-to-time (match-string 1)) 0))
  4169. (t)))
  4170. (and org-agenda-todo-ignore-deadlines
  4171. (re-search-forward org-deadline-time-regexp end t)
  4172. (cond
  4173. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4174. ((eq org-agenda-todo-ignore-deadlines 'far)
  4175. (not (org-deadline-close (match-string 1))))
  4176. ((eq org-agenda-todo-ignore-deadlines 'future)
  4177. (> (org-days-to-time (match-string 1)) 0))
  4178. ((eq org-agenda-todo-ignore-deadlines 'past)
  4179. (<= (org-days-to-time (match-string 1)) 0))
  4180. (t (org-deadline-close (match-string 1)))))
  4181. (and org-agenda-todo-ignore-timestamp
  4182. (let ((buffer (current-buffer))
  4183. (regexp
  4184. (concat
  4185. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4186. (start (point)))
  4187. ;; Copy current buffer into a temporary one
  4188. (with-temp-buffer
  4189. (insert-buffer-substring buffer start end)
  4190. (goto-char (point-min))
  4191. ;; Delete SCHEDULED and DEADLINE items
  4192. (while (re-search-forward regexp end t)
  4193. (delete-region (match-beginning 0) (match-end 0)))
  4194. (goto-char (point-min))
  4195. ;; No search for timestamp left
  4196. (when (re-search-forward org-ts-regexp nil t)
  4197. (cond
  4198. ((eq org-agenda-todo-ignore-timestamp 'future)
  4199. (> (org-days-to-time (match-string 1)) 0))
  4200. ((eq org-agenda-todo-ignore-timestamp 'past)
  4201. (<= (org-days-to-time (match-string 1)) 0))
  4202. (t))))))))))
  4203. (defconst org-agenda-no-heading-message
  4204. "No heading for this item in buffer or region.")
  4205. (defun org-agenda-get-timestamps ()
  4206. "Return the date stamp information for agenda display."
  4207. (let* ((props (list 'face nil
  4208. 'org-not-done-regexp org-not-done-regexp
  4209. 'org-todo-regexp org-todo-regexp
  4210. 'org-complex-heading-regexp org-complex-heading-regexp
  4211. 'mouse-face 'highlight
  4212. 'help-echo
  4213. (format "mouse-2 or RET jump to org file %s"
  4214. (abbreviate-file-name buffer-file-name))))
  4215. (d1 (calendar-absolute-from-gregorian date))
  4216. (remove-re
  4217. (concat
  4218. (regexp-quote
  4219. (format-time-string
  4220. "<%Y-%m-%d"
  4221. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4222. ".*?>"))
  4223. (regexp
  4224. (concat
  4225. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4226. (regexp-quote
  4227. (substring
  4228. (format-time-string
  4229. (car org-time-stamp-formats)
  4230. (apply 'encode-time ; DATE bound by calendar
  4231. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4232. 1 11))
  4233. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4234. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4235. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4236. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4237. todo-state end-of-match)
  4238. (goto-char (point-min))
  4239. (while (setq end-of-match (re-search-forward regexp nil t))
  4240. (setq b0 (match-beginning 0)
  4241. b3 (match-beginning 3) e3 (match-end 3))
  4242. (catch :skip
  4243. (and (org-at-date-range-p) (throw :skip nil))
  4244. (org-agenda-skip)
  4245. (if (and (match-end 1)
  4246. (not (= d1 (org-time-string-to-absolute
  4247. (match-string 1) d1 nil
  4248. org-agenda-repeating-timestamp-show-all))))
  4249. (throw :skip nil))
  4250. (if (and e3
  4251. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4252. (throw :skip nil))
  4253. (setq tmp (buffer-substring (max (point-min)
  4254. (- b0 org-ds-keyword-length))
  4255. b0)
  4256. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4257. inactivep (= (char-after b0) ?\[)
  4258. deadlinep (string-match org-deadline-regexp tmp)
  4259. scheduledp (string-match org-scheduled-regexp tmp)
  4260. closedp (and org-agenda-include-inactive-timestamps
  4261. (string-match org-closed-string tmp))
  4262. clockp (and org-agenda-include-inactive-timestamps
  4263. (or (string-match org-clock-string tmp)
  4264. (string-match "]-+\\'" tmp)))
  4265. todo-state (ignore-errors (org-get-todo-state))
  4266. donep (member todo-state org-done-keywords))
  4267. (if (or scheduledp deadlinep closedp clockp
  4268. (and donep org-agenda-skip-timestamp-if-done))
  4269. (throw :skip t))
  4270. (if (string-match ">" timestr)
  4271. ;; substring should only run to end of time stamp
  4272. (setq timestr (substring timestr 0 (match-end 0))))
  4273. (setq marker (org-agenda-new-marker b0)
  4274. category (org-get-category b0))
  4275. (save-excursion
  4276. (if (not (re-search-backward "^\\*+ " nil t))
  4277. (setq txt org-agenda-no-heading-message)
  4278. (goto-char (match-beginning 0))
  4279. (setq hdmarker (org-agenda-new-marker)
  4280. tags (org-get-tags-at))
  4281. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4282. (setq head (match-string 1))
  4283. (setq txt (org-format-agenda-item
  4284. (if inactivep org-agenda-inactive-leader nil)
  4285. head category tags timestr nil
  4286. remove-re)))
  4287. (setq priority (org-get-priority txt))
  4288. (org-add-props txt props
  4289. 'org-marker marker 'org-hd-marker hdmarker)
  4290. (org-add-props txt nil 'priority priority
  4291. 'org-category category 'date date
  4292. 'todo-state todo-state
  4293. 'type "timestamp")
  4294. (push txt ee))
  4295. (if org-agenda-skip-additional-timestamps-same-entry
  4296. (outline-next-heading)
  4297. (goto-char end-of-match))))
  4298. (nreverse ee)))
  4299. (defun org-agenda-get-sexps ()
  4300. "Return the sexp information for agenda display."
  4301. (require 'diary-lib)
  4302. (let* ((props (list 'mouse-face 'highlight
  4303. 'help-echo
  4304. (format "mouse-2 or RET jump to org file %s"
  4305. (abbreviate-file-name buffer-file-name))))
  4306. (regexp "^&?%%(")
  4307. marker category ee txt tags entry result beg b sexp sexp-entry
  4308. todo-state)
  4309. (goto-char (point-min))
  4310. (while (re-search-forward regexp nil t)
  4311. (catch :skip
  4312. (org-agenda-skip)
  4313. (setq beg (match-beginning 0))
  4314. (goto-char (1- (match-end 0)))
  4315. (setq b (point))
  4316. (forward-sexp 1)
  4317. (setq sexp (buffer-substring b (point)))
  4318. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4319. (org-trim (match-string 1))
  4320. ""))
  4321. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4322. (when result
  4323. (setq marker (org-agenda-new-marker beg)
  4324. category (org-get-category beg)
  4325. todo-state (org-get-todo-state))
  4326. (dolist (r (if (stringp result)
  4327. (list result)
  4328. result)) ;; we expect a list here
  4329. (if (string-match "\\S-" r)
  4330. (setq txt r)
  4331. (setq txt "SEXP entry returned empty string"))
  4332. (setq txt (org-format-agenda-item
  4333. "" txt category tags 'time))
  4334. (org-add-props txt props 'org-marker marker)
  4335. (org-add-props txt nil
  4336. 'org-category category 'date date 'todo-state todo-state
  4337. 'type "sexp")
  4338. (push txt ee)))))
  4339. (nreverse ee)))
  4340. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4341. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4342. The order of the first 2 times 3 arguments depends on the variable
  4343. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4344. So for American calendars, give this as MONTH DAY YEAR, for European as
  4345. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4346. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4347. is any number of ISO weeks in the block period for which the item should
  4348. be skipped."
  4349. (let* ((date1 (calendar-absolute-from-gregorian
  4350. (org-order-calendar-date-args m1 d1 y1)))
  4351. (date2 (calendar-absolute-from-gregorian
  4352. (org-order-calendar-date-args m2 d2 y2)))
  4353. (d (calendar-absolute-from-gregorian date)))
  4354. (and
  4355. (<= date1 d)
  4356. (<= d date2)
  4357. (= (calendar-day-of-week date) dayname)
  4358. (or (not skip-weeks)
  4359. (progn
  4360. (require 'cal-iso)
  4361. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4362. entry)))
  4363. (defalias 'org-get-closed 'org-agenda-get-progress)
  4364. (defun org-agenda-get-progress ()
  4365. "Return the logged TODO entries for agenda display."
  4366. (let* ((props (list 'mouse-face 'highlight
  4367. 'org-not-done-regexp org-not-done-regexp
  4368. 'org-todo-regexp org-todo-regexp
  4369. 'org-complex-heading-regexp org-complex-heading-regexp
  4370. 'help-echo
  4371. (format "mouse-2 or RET jump to org file %s"
  4372. (abbreviate-file-name buffer-file-name))))
  4373. (items (if (consp org-agenda-show-log)
  4374. org-agenda-show-log
  4375. org-agenda-log-mode-items))
  4376. (parts
  4377. (delq nil
  4378. (list
  4379. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4380. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4381. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4382. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4383. (error "`org-agenda-log-mode-items' is empty")))
  4384. (regexp (concat
  4385. "\\(" parts-re "\\)"
  4386. " *\\["
  4387. (regexp-quote
  4388. (substring
  4389. (format-time-string
  4390. (car org-time-stamp-formats)
  4391. (apply 'encode-time ; DATE bound by calendar
  4392. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4393. 1 11))))
  4394. (org-agenda-search-headline-for-time nil)
  4395. marker hdmarker priority category tags closedp statep clockp state
  4396. ee txt extra timestr rest clocked)
  4397. (goto-char (point-min))
  4398. (while (re-search-forward regexp nil t)
  4399. (catch :skip
  4400. (org-agenda-skip)
  4401. (setq marker (org-agenda-new-marker (match-beginning 0))
  4402. closedp (equal (match-string 1) org-closed-string)
  4403. statep (equal (string-to-char (match-string 1)) ?-)
  4404. clockp (not (or closedp statep))
  4405. state (and statep (match-string 2))
  4406. category (org-get-category (match-beginning 0))
  4407. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4408. )
  4409. (when (string-match "\\]" timestr)
  4410. ;; substring should only run to end of time stamp
  4411. (setq rest (substring timestr (match-end 0))
  4412. timestr (substring timestr 0 (match-end 0)))
  4413. (if (and (not closedp) (not statep)
  4414. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4415. (progn (setq timestr (concat (substring timestr 0 -1)
  4416. "-" (match-string 1 rest) "]"))
  4417. (setq clocked (match-string 2 rest)))
  4418. (setq clocked "-")))
  4419. (save-excursion
  4420. (setq extra nil)
  4421. (cond
  4422. ((not org-agenda-log-mode-add-notes))
  4423. (statep
  4424. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4425. (setq extra (match-string 1))))
  4426. (clockp
  4427. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4428. (setq extra (match-string 1)))))
  4429. (if (not (re-search-backward "^\\*+ " nil t))
  4430. (setq txt org-agenda-no-heading-message)
  4431. (goto-char (match-beginning 0))
  4432. (setq hdmarker (org-agenda-new-marker)
  4433. tags (org-get-tags-at))
  4434. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4435. (setq txt (match-string 1))
  4436. (when extra
  4437. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4438. (setq txt (concat (substring txt 0 (match-beginning 1))
  4439. " - " extra " " (match-string 2 txt)))
  4440. (setq txt (concat txt " - " extra))))
  4441. (setq txt (org-format-agenda-item
  4442. (cond
  4443. (closedp "Closed: ")
  4444. (statep (concat "State: (" state ")"))
  4445. (t (concat "Clocked: (" clocked ")")))
  4446. txt category tags timestr)))
  4447. (setq priority 100000)
  4448. (org-add-props txt props
  4449. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4450. 'priority priority 'org-category category
  4451. 'type "closed" 'date date
  4452. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4453. (push txt ee))
  4454. (goto-char (point-at-eol))))
  4455. (nreverse ee)))
  4456. (defun org-agenda-get-deadlines ()
  4457. "Return the deadline information for agenda display."
  4458. (let* ((props (list 'mouse-face 'highlight
  4459. 'org-not-done-regexp org-not-done-regexp
  4460. 'org-todo-regexp org-todo-regexp
  4461. 'org-complex-heading-regexp org-complex-heading-regexp
  4462. 'help-echo
  4463. (format "mouse-2 or RET jump to org file %s"
  4464. (abbreviate-file-name buffer-file-name))))
  4465. (regexp org-deadline-time-regexp)
  4466. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4467. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4468. d2 diff dfrac wdays pos pos1 category tags
  4469. suppress-prewarning
  4470. ee txt head face s todo-state upcomingp donep timestr)
  4471. (goto-char (point-min))
  4472. (while (re-search-forward regexp nil t)
  4473. (setq suppress-prewarning nil)
  4474. (catch :skip
  4475. (org-agenda-skip)
  4476. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4477. (save-match-data
  4478. (string-match org-scheduled-time-regexp
  4479. (buffer-substring (point-at-bol)
  4480. (point-at-eol)))))
  4481. (setq suppress-prewarning
  4482. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4483. org-agenda-skip-deadline-prewarning-if-scheduled
  4484. 0)))
  4485. (setq s (match-string 1)
  4486. txt nil
  4487. pos (1- (match-beginning 1))
  4488. d2 (org-time-string-to-absolute
  4489. (match-string 1) d1 'past
  4490. org-agenda-repeating-timestamp-show-all)
  4491. diff (- d2 d1)
  4492. wdays (if suppress-prewarning
  4493. (let ((org-deadline-warning-days suppress-prewarning))
  4494. (org-get-wdays s))
  4495. (org-get-wdays s))
  4496. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4497. upcomingp (and todayp (> diff 0)))
  4498. ;; When to show a deadline in the calendar:
  4499. ;; If the expiration is within wdays warning time.
  4500. ;; Past-due deadlines are only shown on the current date
  4501. (if (and (or (and (<= diff wdays)
  4502. (and todayp (not org-agenda-only-exact-dates)))
  4503. (= diff 0)))
  4504. (save-excursion
  4505. (setq todo-state (org-get-todo-state))
  4506. (setq donep (member todo-state org-done-keywords))
  4507. (if (and donep
  4508. (or org-agenda-skip-deadline-if-done
  4509. (not (= diff 0))))
  4510. (setq txt nil)
  4511. (setq category (org-get-category))
  4512. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4513. (setq txt org-agenda-no-heading-message)
  4514. (goto-char (match-end 0))
  4515. (setq pos1 (match-beginning 0))
  4516. (setq tags (org-get-tags-at pos1))
  4517. (setq head (buffer-substring-no-properties
  4518. (point)
  4519. (progn (skip-chars-forward "^\r\n")
  4520. (point))))
  4521. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4522. (setq timestr
  4523. (concat (substring s (match-beginning 1)) " "))
  4524. (setq timestr 'time))
  4525. (setq txt (org-format-agenda-item
  4526. (if (= diff 0)
  4527. (car org-agenda-deadline-leaders)
  4528. (if (functionp
  4529. (nth 1 org-agenda-deadline-leaders))
  4530. (funcall
  4531. (nth 1 org-agenda-deadline-leaders)
  4532. diff date)
  4533. (format (nth 1 org-agenda-deadline-leaders)
  4534. diff)))
  4535. head category tags
  4536. (if (not (= diff 0)) nil timestr)))))
  4537. (when txt
  4538. (setq face (org-agenda-deadline-face dfrac wdays))
  4539. (org-add-props txt props
  4540. 'org-marker (org-agenda-new-marker pos)
  4541. 'org-hd-marker (org-agenda-new-marker pos1)
  4542. 'priority (+ (- diff)
  4543. (org-get-priority txt))
  4544. 'org-category category
  4545. 'todo-state todo-state
  4546. 'type (if upcomingp "upcoming-deadline" "deadline")
  4547. 'date (if upcomingp date d2)
  4548. 'face (if donep 'org-agenda-done face)
  4549. 'undone-face face 'done-face 'org-agenda-done)
  4550. (push txt ee))))))
  4551. (nreverse ee)))
  4552. (defun org-agenda-deadline-face (fraction &optional wdays)
  4553. "Return the face to displaying a deadline item.
  4554. FRACTION is what fraction of the head-warning time has passed."
  4555. (if (equal wdays 0) (setq fraction 1.))
  4556. (let ((faces org-agenda-deadline-faces) f)
  4557. (catch 'exit
  4558. (while (setq f (pop faces))
  4559. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4560. (defun org-agenda-get-scheduled (&optional deadline-results)
  4561. "Return the scheduled information for agenda display."
  4562. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4563. 'org-todo-regexp org-todo-regexp
  4564. 'org-complex-heading-regexp org-complex-heading-regexp
  4565. 'done-face 'org-agenda-done
  4566. 'mouse-face 'highlight
  4567. 'help-echo
  4568. (format "mouse-2 or RET jump to org file %s"
  4569. (abbreviate-file-name buffer-file-name))))
  4570. (regexp org-scheduled-time-regexp)
  4571. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4572. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4573. mm
  4574. (deadline-position-alist
  4575. (mapcar (lambda (a) (and (setq mm (get-text-property
  4576. 0 'org-hd-marker a))
  4577. (cons (marker-position mm) a)))
  4578. deadline-results))
  4579. d2 diff pos pos1 category tags donep
  4580. ee txt head pastschedp todo-state face timestr s habitp)
  4581. (goto-char (point-min))
  4582. (while (re-search-forward regexp nil t)
  4583. (catch :skip
  4584. (org-agenda-skip)
  4585. (setq s (match-string 1)
  4586. txt nil
  4587. pos (1- (match-beginning 1))
  4588. d2 (org-time-string-to-absolute
  4589. (match-string 1) d1 'past
  4590. org-agenda-repeating-timestamp-show-all)
  4591. diff (- d2 d1))
  4592. (setq pastschedp (and todayp (< diff 0)))
  4593. ;; When to show a scheduled item in the calendar:
  4594. ;; If it is on or past the date.
  4595. (when (or (and (< diff 0)
  4596. (< (abs diff) org-scheduled-past-days)
  4597. (and todayp (not org-agenda-only-exact-dates)))
  4598. (= diff 0))
  4599. (save-excursion
  4600. (setq todo-state (org-get-todo-state))
  4601. (setq donep (member todo-state org-done-keywords))
  4602. (if (and donep
  4603. (or org-agenda-skip-scheduled-if-done
  4604. (not (= diff 0))
  4605. (and (functionp 'org-is-habit-p)
  4606. (org-is-habit-p))))
  4607. (setq txt nil)
  4608. (setq habitp (and (functionp 'org-is-habit-p)
  4609. (org-is-habit-p)))
  4610. (setq category (org-get-category))
  4611. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4612. (setq txt org-agenda-no-heading-message)
  4613. (goto-char (match-end 0))
  4614. (setq pos1 (match-beginning 0))
  4615. (if habitp
  4616. (if (or (not org-habit-show-habits)
  4617. (and (not todayp)
  4618. org-habit-show-habits-only-for-today))
  4619. (throw :skip nil))
  4620. (if (and
  4621. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4622. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4623. pastschedp))
  4624. (setq mm (assoc pos1 deadline-position-alist)))
  4625. (throw :skip nil)))
  4626. (setq tags (org-get-tags-at))
  4627. (setq head (buffer-substring-no-properties
  4628. (point)
  4629. (progn (skip-chars-forward "^\r\n") (point))))
  4630. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4631. (setq timestr
  4632. (concat (substring s (match-beginning 1)) " "))
  4633. (setq timestr 'time))
  4634. (setq txt (org-format-agenda-item
  4635. (if (= diff 0)
  4636. (car org-agenda-scheduled-leaders)
  4637. (format (nth 1 org-agenda-scheduled-leaders)
  4638. (- 1 diff)))
  4639. head category tags
  4640. (if (not (= diff 0)) nil timestr)
  4641. nil nil habitp))))
  4642. (when txt
  4643. (setq face
  4644. (cond
  4645. ((and (not habitp) pastschedp)
  4646. 'org-scheduled-previously)
  4647. (todayp 'org-scheduled-today)
  4648. (t 'org-scheduled))
  4649. habitp (and habitp (org-habit-parse-todo)))
  4650. (org-add-props txt props
  4651. 'undone-face face
  4652. 'face (if donep 'org-agenda-done face)
  4653. 'org-marker (org-agenda-new-marker pos)
  4654. 'org-hd-marker (org-agenda-new-marker pos1)
  4655. 'type (if pastschedp "past-scheduled" "scheduled")
  4656. 'date (if pastschedp d2 date)
  4657. 'priority (if habitp
  4658. (org-habit-get-priority habitp)
  4659. (+ 94 (- 5 diff) (org-get-priority txt)))
  4660. 'org-category category
  4661. 'org-habit-p habitp
  4662. 'todo-state todo-state)
  4663. (push txt ee))))))
  4664. (nreverse ee)))
  4665. (defun org-agenda-get-blocks ()
  4666. "Return the date-range information for agenda display."
  4667. (let* ((props (list 'face nil
  4668. 'org-not-done-regexp org-not-done-regexp
  4669. 'org-todo-regexp org-todo-regexp
  4670. 'org-complex-heading-regexp org-complex-heading-regexp
  4671. 'mouse-face 'highlight
  4672. 'help-echo
  4673. (format "mouse-2 or RET jump to org file %s"
  4674. (abbreviate-file-name buffer-file-name))))
  4675. (regexp org-tr-regexp)
  4676. (d0 (calendar-absolute-from-gregorian date))
  4677. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4678. head donep)
  4679. (goto-char (point-min))
  4680. (while (re-search-forward regexp nil t)
  4681. (catch :skip
  4682. (org-agenda-skip)
  4683. (setq pos (point))
  4684. (setq timestr (match-string 0)
  4685. s1 (match-string 1)
  4686. s2 (match-string 2)
  4687. d1 (time-to-days (org-time-string-to-time s1))
  4688. d2 (time-to-days (org-time-string-to-time s2)))
  4689. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4690. ;; Only allow days between the limits, because the normal
  4691. ;; date stamps will catch the limits.
  4692. (save-excursion
  4693. (setq todo-state (org-get-todo-state))
  4694. (setq donep (member todo-state org-done-keywords))
  4695. (if (and donep org-agenda-skip-timestamp-if-done)
  4696. (throw :skip t))
  4697. (setq marker (org-agenda-new-marker (point)))
  4698. (setq category (org-get-category))
  4699. (if (not (re-search-backward "^\\*+ " nil t))
  4700. (setq txt org-agenda-no-heading-message)
  4701. (goto-char (match-beginning 0))
  4702. (setq hdmarker (org-agenda-new-marker (point)))
  4703. (setq tags (org-get-tags-at))
  4704. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4705. (setq head (match-string 1))
  4706. (let ((remove-re
  4707. (if org-agenda-remove-timeranges-from-blocks
  4708. (concat
  4709. "<" (regexp-quote s1) ".*?>"
  4710. "--"
  4711. "<" (regexp-quote s2) ".*?>")
  4712. nil)))
  4713. (setq txt (org-format-agenda-item
  4714. (format
  4715. (nth (if (= d1 d2) 0 1)
  4716. org-agenda-timerange-leaders)
  4717. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4718. head category tags
  4719. timestr nil remove-re))))
  4720. (org-add-props txt props
  4721. 'org-marker marker 'org-hd-marker hdmarker
  4722. 'type "block" 'date date
  4723. 'todo-state todo-state
  4724. 'priority (org-get-priority txt) 'org-category category)
  4725. (push txt ee)))
  4726. (goto-char pos)))
  4727. ;; Sort the entries by expiration date.
  4728. (nreverse ee)))
  4729. ;;; Agenda presentation and sorting
  4730. (defvar org-prefix-has-time nil
  4731. "A flag, set by `org-compile-prefix-format'.
  4732. The flag is set if the currently compiled format contains a `%t'.")
  4733. (defvar org-prefix-has-tag nil
  4734. "A flag, set by `org-compile-prefix-format'.
  4735. The flag is set if the currently compiled format contains a `%T'.")
  4736. (defvar org-prefix-has-effort nil
  4737. "A flag, set by `org-compile-prefix-format'.
  4738. The flag is set if the currently compiled format contains a `%e'.")
  4739. (defvar org-prefix-category-length nil
  4740. "Used by `org-compile-prefix-format' to remember the category field width.")
  4741. (defvar org-prefix-category-max-length nil
  4742. "Used by `org-compile-prefix-format' to remember the category field width.")
  4743. (defun org-agenda-get-category-icon (category)
  4744. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4745. (dolist (entry org-agenda-category-icon-alist)
  4746. (when (org-string-match-p (car entry) category)
  4747. (if (listp (cadr entry))
  4748. (return (cadr entry))
  4749. (return (apply 'create-image (cdr entry)))))))
  4750. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4751. noprefix remove-re habitp)
  4752. "Format TXT to be inserted into the agenda buffer.
  4753. In particular, it adds the prefix and corresponding text properties. EXTRA
  4754. must be a string and replaces the `%s' specifier in the prefix format.
  4755. CATEGORY (string, symbol or nil) may be used to overrule the default
  4756. category taken from local variable or file name. It will replace the `%c'
  4757. specifier in the format. DOTIME, when non-nil, indicates that a
  4758. time-of-day should be extracted from TXT for sorting of this entry, and for
  4759. the `%t' specifier in the format. When DOTIME is a string, this string is
  4760. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4761. only the correctly processes TXT should be returned - this is used by
  4762. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4763. Any match of REMOVE-RE will be removed from TXT."
  4764. (save-match-data
  4765. ;; Diary entries sometimes have extra whitespace at the beginning
  4766. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4767. ;; Fix the tags part in txt
  4768. (setq txt (org-agenda-fix-displayed-tags
  4769. txt tags
  4770. org-agenda-show-inherited-tags
  4771. org-agenda-hide-tags-regexp))
  4772. (let* ((category (or category
  4773. (if (stringp org-category)
  4774. org-category
  4775. (and org-category (symbol-name org-category)))
  4776. (if buffer-file-name
  4777. (file-name-sans-extension
  4778. (file-name-nondirectory buffer-file-name))
  4779. "")))
  4780. (category-icon (org-agenda-get-category-icon category))
  4781. (category-icon (if category-icon
  4782. (propertize " " 'display category-icon)
  4783. ""))
  4784. ;; time, tag, effort are needed for the eval of the prefix format
  4785. (tag (if tags (nth (1- (length tags)) tags) ""))
  4786. time effort neffort
  4787. (ts (if dotime (concat
  4788. (if (stringp dotime) dotime "")
  4789. (and org-agenda-search-headline-for-time txt))))
  4790. (time-of-day (and dotime (org-get-time-of-day ts)))
  4791. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4792. duration thecategory)
  4793. (and (org-mode-p) buffer-file-name
  4794. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4795. (when (and dotime time-of-day)
  4796. ;; Extract starting and ending time and move them to prefix
  4797. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4798. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4799. (setq s0 (match-string 0 ts)
  4800. srp (and stamp (match-end 3))
  4801. s1 (match-string (if plain 1 2) ts)
  4802. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4803. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4804. ;; them, we might want to remove them there to avoid duplication.
  4805. ;; The user can turn this off with a variable.
  4806. (if (and org-prefix-has-time
  4807. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4808. (string-match (concat (regexp-quote s0) " *") txt)
  4809. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4810. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4811. (= (match-beginning 0) 0)
  4812. t))
  4813. (setq txt (replace-match "" nil nil txt))))
  4814. ;; Normalize the time(s) to 24 hour
  4815. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4816. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4817. ;; Compute the duration
  4818. (when s1
  4819. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4820. (string-to-number (substring s1 3)))
  4821. t2 (cond
  4822. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4823. (string-to-number (substring s2 3))))
  4824. (org-agenda-default-appointment-duration
  4825. (+ t1 org-agenda-default-appointment-duration))
  4826. (t nil)))
  4827. (setq duration (if t2 (- t2 t1)))))
  4828. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4829. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4830. (let ((m (+ (string-to-number (match-string 2 s1))
  4831. (* 60 (string-to-number (match-string 1 s1)))
  4832. org-agenda-default-appointment-duration))
  4833. h)
  4834. (setq h (/ m 60) m (- m (* h 60)))
  4835. (setq s2 (format "%02d:%02d" h m))))
  4836. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4837. txt)
  4838. ;; Tags are in the string
  4839. (if (or (eq org-agenda-remove-tags t)
  4840. (and org-agenda-remove-tags
  4841. org-prefix-has-tag))
  4842. (setq txt (replace-match "" t t txt))
  4843. (setq txt (replace-match
  4844. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4845. (match-string 2 txt))
  4846. t t txt))))
  4847. (when (org-mode-p)
  4848. (setq effort
  4849. (condition-case nil
  4850. (org-get-effort
  4851. (or (get-text-property 0 'org-hd-marker txt)
  4852. (get-text-property 0 'org-marker txt)))
  4853. (error nil)))
  4854. (when effort
  4855. (setq neffort (org-hh:mm-string-to-minutes effort)
  4856. effort (setq effort (concat "[" effort "]" )))))
  4857. (when remove-re
  4858. (while (string-match remove-re txt)
  4859. (setq txt (replace-match "" t t txt))))
  4860. ;; Create the final string
  4861. (if noprefix
  4862. (setq rtn txt)
  4863. ;; Prepare the variables needed in the eval of the compiled format
  4864. (setq time (cond (s2 (concat
  4865. (org-agenda-time-of-day-to-ampm-maybe s1)
  4866. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  4867. (if org-agenda-timegrid-use-ampm " ")))
  4868. (s1 (concat
  4869. (org-agenda-time-of-day-to-ampm-maybe s1)
  4870. (if org-agenda-timegrid-use-ampm
  4871. "........ "
  4872. "......")))
  4873. (t ""))
  4874. extra (or (and (not habitp) extra) "")
  4875. category (if (symbolp category) (symbol-name category) category)
  4876. thecategory (copy-sequence category))
  4877. (if (string-match org-bracket-link-regexp category)
  4878. (progn
  4879. (setq l (if (match-end 3)
  4880. (- (match-end 3) (match-beginning 3))
  4881. (- (match-end 1) (match-beginning 1))))
  4882. (when (< l (or org-prefix-category-length 0))
  4883. (setq category (copy-sequence category))
  4884. (org-add-props category nil
  4885. 'extra-space (make-string
  4886. (- org-prefix-category-length l 1) ?\ ))))
  4887. (if (and org-prefix-category-max-length
  4888. (>= (length category) org-prefix-category-max-length))
  4889. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4890. ;; Evaluate the compiled format
  4891. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4892. ;; And finally add the text properties
  4893. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4894. (org-add-props rtn nil
  4895. 'org-category (if thecategory (downcase thecategory) category)
  4896. 'tags (mapcar 'org-downcase-keep-props tags)
  4897. 'org-highest-priority org-highest-priority
  4898. 'org-lowest-priority org-lowest-priority
  4899. 'prefix-length (- (length rtn) (length txt))
  4900. 'time-of-day time-of-day
  4901. 'duration duration
  4902. 'effort effort
  4903. 'effort-minutes neffort
  4904. 'txt txt
  4905. 'time time
  4906. 'extra extra
  4907. 'dotime dotime))))
  4908. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4909. "Remove tags string from TXT, and add a modified list of tags.
  4910. The modified list may contain inherited tags, and tags matched by
  4911. `org-agenda-hide-tags-regexp' will be removed."
  4912. (when (or add-inherited hide-re)
  4913. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4914. (setq txt (substring txt 0 (match-beginning 0))))
  4915. (setq tags
  4916. (delq nil
  4917. (mapcar (lambda (tg)
  4918. (if (or (and hide-re (string-match hide-re tg))
  4919. (and (not add-inherited)
  4920. (get-text-property 0 'inherited tg)))
  4921. nil
  4922. tg))
  4923. tags)))
  4924. (when tags
  4925. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4926. i)
  4927. (setq txt (concat txt " :"
  4928. (mapconcat
  4929. (lambda (x)
  4930. (setq i (get-text-property 0 'inherited x))
  4931. (if (and have-i (not i))
  4932. (progn
  4933. (setq have-i nil)
  4934. (concat ":" x))
  4935. x))
  4936. tags ":")
  4937. (if have-i "::" ":"))))))
  4938. txt)
  4939. (defun org-downcase-keep-props (s)
  4940. (let ((props (text-properties-at 0 s)))
  4941. (setq s (downcase s))
  4942. (add-text-properties 0 (length s) props s)
  4943. s))
  4944. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4945. (defvar org-agenda-sorting-strategy-selected nil)
  4946. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4947. (catch 'exit
  4948. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4949. ((and todayp (member 'today (car org-agenda-time-grid))))
  4950. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4951. ((member 'weekly (car org-agenda-time-grid)))
  4952. (t (throw 'exit list)))
  4953. (let* ((have (delq nil (mapcar
  4954. (lambda (x) (get-text-property 1 'time-of-day x))
  4955. list)))
  4956. (string (nth 1 org-agenda-time-grid))
  4957. (gridtimes (nth 2 org-agenda-time-grid))
  4958. (req (car org-agenda-time-grid))
  4959. (remove (member 'remove-match req))
  4960. new time)
  4961. (if (and (member 'require-timed req) (not have))
  4962. ;; don't show empty grid
  4963. (throw 'exit list))
  4964. (while (setq time (pop gridtimes))
  4965. (unless (and remove (member time have))
  4966. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  4967. (push (org-format-agenda-item
  4968. nil string "" nil
  4969. (concat (substring time 0 -2) ":" (substring time -2)))
  4970. new)
  4971. (put-text-property
  4972. 2 (length (car new)) 'face 'org-time-grid (car new))))
  4973. (when (and todayp org-agenda-show-current-time-in-grid)
  4974. (push (org-format-agenda-item
  4975. nil
  4976. org-agenda-current-time-string
  4977. "" nil
  4978. (format-time-string "%H:%M "))
  4979. new)
  4980. (put-text-property
  4981. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  4982. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4983. (append new list)
  4984. (append list new)))))
  4985. (defun org-eval (form)
  4986. "Eval FORM and return result."
  4987. (condition-case error
  4988. (eval form)
  4989. (error (format "%%![Error: %s]" error))))
  4990. (defun org-compile-prefix-format (key)
  4991. "Compile the prefix format into a Lisp form that can be evaluated.
  4992. The resulting form is returned and stored in the variable
  4993. `org-prefix-format-compiled'."
  4994. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4995. org-prefix-category-length nil org-prefix-has-effort nil)
  4996. (let ((s (cond
  4997. ((stringp org-agenda-prefix-format)
  4998. org-agenda-prefix-format)
  4999. ((assq key org-agenda-prefix-format)
  5000. (cdr (assq key org-agenda-prefix-format)))
  5001. (t " %-12:c%?-12t% s")))
  5002. (start 0)
  5003. varform vars var e c f opt)
  5004. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5005. s start)
  5006. (setq var (or (cdr (assoc (match-string 4 s)
  5007. '(("c" . category) ("t" . time) ("s" . extra)
  5008. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5009. 'eval)
  5010. c (or (match-string 3 s) "")
  5011. opt (match-beginning 1)
  5012. start (1+ (match-beginning 0)))
  5013. (if (equal var 'time) (setq org-prefix-has-time t))
  5014. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5015. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5016. (setq f (concat "%" (match-string 2 s) "s"))
  5017. (when (equal var 'category)
  5018. (setq org-prefix-category-length
  5019. (floor (abs (string-to-number (match-string 2 s)))))
  5020. (setq org-prefix-category-max-length
  5021. (let ((x (match-string 2 s)))
  5022. (save-match-data
  5023. (if (string-match "\\.[0-9]+" x)
  5024. (string-to-number (substring (match-string 0 x) 1)))))))
  5025. (if (eq var 'eval)
  5026. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5027. (if opt
  5028. (setq varform
  5029. `(if (equal "" ,var)
  5030. ""
  5031. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5032. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5033. (setq s (replace-match "%s" t nil s))
  5034. (push varform vars))
  5035. (setq vars (nreverse vars))
  5036. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5037. (defun org-set-sorting-strategy (key)
  5038. (if (symbolp (car org-agenda-sorting-strategy))
  5039. ;; the old format
  5040. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5041. (setq org-agenda-sorting-strategy-selected
  5042. (or (cdr (assq key org-agenda-sorting-strategy))
  5043. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5044. '(time-up category-keep priority-down)))))
  5045. (defun org-get-time-of-day (s &optional string mod24)
  5046. "Check string S for a time of day.
  5047. If found, return it as a military time number between 0 and 2400.
  5048. If not found, return nil.
  5049. The optional STRING argument forces conversion into a 5 character wide string
  5050. HH:MM."
  5051. (save-match-data
  5052. (when
  5053. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5054. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5055. (let* ((h (string-to-number (match-string 1 s)))
  5056. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5057. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5058. (am-p (equal ampm "am"))
  5059. (h1 (cond ((not ampm) h)
  5060. ((= h 12) (if am-p 0 12))
  5061. (t (+ h (if am-p 0 12)))))
  5062. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5063. (mod h1 24) h1))
  5064. (t0 (+ (* 100 h2) m))
  5065. (t1 (concat (if (>= h1 24) "+" " ")
  5066. (if (and org-agenda-time-leading-zero
  5067. (< t0 1000)) "0" "")
  5068. (if (< t0 100) "0" "")
  5069. (if (< t0 10) "0" "")
  5070. (int-to-string t0))))
  5071. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5072. (defvar org-agenda-before-sorting-filter-function nil
  5073. "Function to be applied to agenda items prior to sorting.
  5074. Prior to sorting also means just before they are inserted into the agenda.
  5075. To aid sorting, you may revisit the original entries and add more text
  5076. properties which will later be used by the sorting functions.
  5077. The function should take a string argument, an agenda line.
  5078. It has access to the text properties in that line, which contain among
  5079. other things, the property `org-hd-marker' that points to the entry
  5080. where the line comes from. Note that not all lines going into the agenda
  5081. have this property, only most.
  5082. The function should return the modified string. It is probably best
  5083. to ONLY change text properties.
  5084. You can also use this function as a filter, by returning nil for lines
  5085. you don't want to have in the agenda at all. For this application, you
  5086. could bind the variable in the options section of a custom command.")
  5087. (defun org-finalize-agenda-entries (list &optional nosort)
  5088. "Sort and concatenate the agenda items."
  5089. (setq list (mapcar 'org-agenda-highlight-todo list))
  5090. (if nosort
  5091. list
  5092. (when org-agenda-before-sorting-filter-function
  5093. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5094. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5095. (defun org-agenda-highlight-todo (x)
  5096. (let ((org-done-keywords org-done-keywords-for-agenda)
  5097. (case-fold-search nil)
  5098. re pl)
  5099. (if (eq x 'line)
  5100. (save-excursion
  5101. (beginning-of-line 1)
  5102. (setq re (org-get-at-bol 'org-todo-regexp))
  5103. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  5104. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5105. (add-text-properties (match-beginning 0) (match-end 1)
  5106. (list 'face (org-get-todo-face 1)))
  5107. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5108. (delete-region (match-beginning 1) (1- (match-end 0)))
  5109. (goto-char (match-beginning 1))
  5110. (insert (format org-agenda-todo-keyword-format s)))))
  5111. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  5112. pl (get-text-property 0 'prefix-length x))
  5113. (when (and re
  5114. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5115. x (or pl 0)) pl))
  5116. (add-text-properties
  5117. (or (match-end 1) (match-end 0)) (match-end 0)
  5118. (list 'face (org-get-todo-face (match-string 2 x)))
  5119. x)
  5120. (when (match-end 1)
  5121. (setq x (concat (substring x 0 (match-end 1))
  5122. (format org-agenda-todo-keyword-format
  5123. (match-string 2 x))
  5124. (org-add-props " " (text-properties-at 0 x))
  5125. (substring x (match-end 3))))))
  5126. x)))
  5127. (defsubst org-cmp-priority (a b)
  5128. "Compare the priorities of string A and B."
  5129. (let ((pa (or (get-text-property 1 'priority a) 0))
  5130. (pb (or (get-text-property 1 'priority b) 0)))
  5131. (cond ((> pa pb) +1)
  5132. ((< pa pb) -1)
  5133. (t nil))))
  5134. (defsubst org-cmp-effort (a b)
  5135. "Compare the priorities of string A and B."
  5136. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5137. (ea (or (get-text-property 1 'effort-minutes a) def))
  5138. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5139. (cond ((> ea eb) +1)
  5140. ((< ea eb) -1)
  5141. (t nil))))
  5142. (defsubst org-cmp-category (a b)
  5143. "Compare the string values of categories of strings A and B."
  5144. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5145. (cb (or (get-text-property 1 'org-category b) "")))
  5146. (cond ((string-lessp ca cb) -1)
  5147. ((string-lessp cb ca) +1)
  5148. (t nil))))
  5149. (defsubst org-cmp-todo-state (a b)
  5150. "Compare the todo states of strings A and B."
  5151. (let* ((ma (or (get-text-property 1 'org-marker a)
  5152. (get-text-property 1 'org-hd-marker a)))
  5153. (mb (or (get-text-property 1 'org-marker b)
  5154. (get-text-property 1 'org-hd-marker b)))
  5155. (fa (and ma (marker-buffer ma)))
  5156. (fb (and mb (marker-buffer mb)))
  5157. (todo-kwds
  5158. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5159. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5160. (ta (or (get-text-property 1 'todo-state a) ""))
  5161. (tb (or (get-text-property 1 'todo-state b) ""))
  5162. (la (- (length (member ta todo-kwds))))
  5163. (lb (- (length (member tb todo-kwds))))
  5164. (donepa (member ta org-done-keywords-for-agenda))
  5165. (donepb (member tb org-done-keywords-for-agenda)))
  5166. (cond ((and donepa (not donepb)) -1)
  5167. ((and (not donepa) donepb) +1)
  5168. ((< la lb) -1)
  5169. ((< lb la) +1)
  5170. (t nil))))
  5171. (defsubst org-cmp-alpha (a b)
  5172. "Compare the headlines, alphabetically."
  5173. (let* ((pla (get-text-property 0 'prefix-length a))
  5174. (plb (get-text-property 0 'prefix-length b))
  5175. (ta (and pla (substring a pla)))
  5176. (tb (and plb (substring b plb))))
  5177. (when pla
  5178. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5179. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5180. (setq ta (substring ta (match-end 0))))
  5181. (setq ta (downcase ta)))
  5182. (when plb
  5183. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5184. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5185. (setq tb (substring tb (match-end 0))))
  5186. (setq tb (downcase tb)))
  5187. (cond ((not ta) +1)
  5188. ((not tb) -1)
  5189. ((string-lessp ta tb) -1)
  5190. ((string-lessp tb ta) +1)
  5191. (t nil))))
  5192. (defsubst org-cmp-tag (a b)
  5193. "Compare the string values of the first tags of A and B."
  5194. (let ((ta (car (last (get-text-property 1 'tags a))))
  5195. (tb (car (last (get-text-property 1 'tags b)))))
  5196. (cond ((not ta) +1)
  5197. ((not tb) -1)
  5198. ((string-lessp ta tb) -1)
  5199. ((string-lessp tb ta) +1)
  5200. (t nil))))
  5201. (defsubst org-cmp-time (a b)
  5202. "Compare the time-of-day values of strings A and B."
  5203. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5204. (ta (or (get-text-property 1 'time-of-day a) def))
  5205. (tb (or (get-text-property 1 'time-of-day b) def)))
  5206. (cond ((< ta tb) -1)
  5207. ((< tb ta) +1)
  5208. (t nil))))
  5209. (defsubst org-cmp-habit-p (a b)
  5210. "Compare the todo states of strings A and B."
  5211. (let ((ha (get-text-property 1 'org-habit-p a))
  5212. (hb (get-text-property 1 'org-habit-p b)))
  5213. (cond ((and ha (not hb)) -1)
  5214. ((and (not ha) hb) +1)
  5215. (t nil))))
  5216. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5217. (defun org-entries-lessp (a b)
  5218. "Predicate for sorting agenda entries."
  5219. ;; The following variables will be used when the form is evaluated.
  5220. ;; So even though the compiler complains, keep them.
  5221. (let* ((ss org-agenda-sorting-strategy-selected)
  5222. (time-up (and (org-em 'time-up 'time-down ss)
  5223. (org-cmp-time a b)))
  5224. (time-down (if time-up (- time-up) nil))
  5225. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5226. (org-cmp-priority a b)))
  5227. (priority-down (if priority-up (- priority-up) nil))
  5228. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5229. (org-cmp-effort a b)))
  5230. (effort-down (if effort-up (- effort-up) nil))
  5231. (category-up (and (or (org-em 'category-up 'category-down ss)
  5232. (memq 'category-keep ss))
  5233. (org-cmp-category a b)))
  5234. (category-down (if category-up (- category-up) nil))
  5235. (category-keep (if category-up +1 nil))
  5236. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5237. (org-cmp-tag a b)))
  5238. (tag-down (if tag-up (- tag-up) nil))
  5239. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5240. (org-cmp-todo-state a b)))
  5241. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5242. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5243. (org-cmp-habit-p a b)))
  5244. (habit-down (if habit-up (- habit-up) nil))
  5245. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5246. (org-cmp-alpha a b)))
  5247. (alpha-down (if alpha-up (- alpha-up) nil))
  5248. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5249. user-defined-up user-defined-down)
  5250. (if (and need-user-cmp org-agenda-cmp-user-defined
  5251. (functionp org-agenda-cmp-user-defined))
  5252. (setq user-defined-up
  5253. (funcall org-agenda-cmp-user-defined a b)
  5254. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5255. (cdr (assoc
  5256. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5257. '((-1 . t) (1 . nil) (nil . nil))))))
  5258. ;;; Agenda restriction lock
  5259. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5260. "Overlay to mark the headline to which agenda commands are restricted.")
  5261. (overlay-put org-agenda-restriction-lock-overlay
  5262. 'face 'org-agenda-restriction-lock)
  5263. (overlay-put org-agenda-restriction-lock-overlay
  5264. 'help-echo "Agendas are currently limited to this subtree.")
  5265. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5266. (defun org-agenda-set-restriction-lock (&optional type)
  5267. "Set restriction lock for agenda, to current subtree or file.
  5268. Restriction will be the file if TYPE is `file', or if type is the
  5269. universal prefix '(4), or if the cursor is before the first headline
  5270. in the file. Otherwise, restriction will be to the current subtree."
  5271. (interactive "P")
  5272. (and (equal type '(4)) (setq type 'file))
  5273. (setq type (cond
  5274. (type type)
  5275. ((org-at-heading-p) 'subtree)
  5276. ((condition-case nil (org-back-to-heading t) (error nil))
  5277. 'subtree)
  5278. (t 'file)))
  5279. (if (eq type 'subtree)
  5280. (progn
  5281. (setq org-agenda-restrict t)
  5282. (setq org-agenda-overriding-restriction 'subtree)
  5283. (put 'org-agenda-files 'org-restrict
  5284. (list (buffer-file-name (buffer-base-buffer))))
  5285. (org-back-to-heading t)
  5286. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5287. (move-marker org-agenda-restrict-begin (point))
  5288. (move-marker org-agenda-restrict-end
  5289. (save-excursion (org-end-of-subtree t)))
  5290. (message "Locking agenda restriction to subtree"))
  5291. (put 'org-agenda-files 'org-restrict
  5292. (list (buffer-file-name (buffer-base-buffer))))
  5293. (setq org-agenda-restrict nil)
  5294. (setq org-agenda-overriding-restriction 'file)
  5295. (move-marker org-agenda-restrict-begin nil)
  5296. (move-marker org-agenda-restrict-end nil)
  5297. (message "Locking agenda restriction to file"))
  5298. (setq current-prefix-arg nil)
  5299. (org-agenda-maybe-redo))
  5300. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5301. "Remove the agenda restriction lock."
  5302. (interactive "P")
  5303. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5304. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5305. (setq org-agenda-overriding-restriction nil)
  5306. (setq org-agenda-restrict nil)
  5307. (put 'org-agenda-files 'org-restrict nil)
  5308. (move-marker org-agenda-restrict-begin nil)
  5309. (move-marker org-agenda-restrict-end nil)
  5310. (setq current-prefix-arg nil)
  5311. (message "Agenda restriction lock removed")
  5312. (or noupdate (org-agenda-maybe-redo)))
  5313. (defun org-agenda-maybe-redo ()
  5314. "If there is any window showing the agenda view, update it."
  5315. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5316. (w0 (selected-window)))
  5317. (when w
  5318. (select-window w)
  5319. (org-agenda-redo)
  5320. (select-window w0)
  5321. (if org-agenda-overriding-restriction
  5322. (message "Agenda view shifted to new %s restriction"
  5323. org-agenda-overriding-restriction)
  5324. (message "Agenda restriction lock removed")))))
  5325. ;;; Agenda commands
  5326. (defun org-agenda-check-type (error &rest types)
  5327. "Check if agenda buffer is of allowed type.
  5328. If ERROR is non-nil, throw an error, otherwise just return nil."
  5329. (if (memq org-agenda-type types)
  5330. t
  5331. (if error
  5332. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5333. nil)))
  5334. (defun org-agenda-quit ()
  5335. "Exit agenda by removing the window or the buffer."
  5336. (interactive)
  5337. (if org-agenda-columns-active
  5338. (org-columns-quit)
  5339. (let ((buf (current-buffer)))
  5340. (if (eq org-agenda-window-setup 'other-frame)
  5341. (progn
  5342. (kill-buffer buf)
  5343. (org-agenda-reset-markers)
  5344. (org-columns-remove-overlays)
  5345. (setq org-agenda-archives-mode nil)
  5346. (delete-frame))
  5347. (and (not (eq org-agenda-window-setup 'current-window))
  5348. (not (one-window-p))
  5349. (delete-window))
  5350. (kill-buffer buf)
  5351. (org-agenda-reset-markers)
  5352. (org-columns-remove-overlays)
  5353. (setq org-agenda-archives-mode nil)))
  5354. ;; Maybe restore the pre-agenda window configuration.
  5355. (and org-agenda-restore-windows-after-quit
  5356. (not (eq org-agenda-window-setup 'other-frame))
  5357. org-pre-agenda-window-conf
  5358. (set-window-configuration org-pre-agenda-window-conf))))
  5359. (defun org-agenda-exit ()
  5360. "Exit agenda by removing the window or the buffer.
  5361. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5362. Org-mode buffers visited directly by the user will not be touched."
  5363. (interactive)
  5364. (org-release-buffers org-agenda-new-buffers)
  5365. (setq org-agenda-new-buffers nil)
  5366. (org-agenda-quit))
  5367. (defun org-agenda-execute (arg)
  5368. "Execute another agenda command, keeping same window.
  5369. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5370. in the agenda."
  5371. (interactive "P")
  5372. (let ((org-agenda-window-setup 'current-window))
  5373. (org-agenda arg)))
  5374. (defun org-agenda-redo ()
  5375. "Rebuild Agenda.
  5376. When this is the global TODO list, a prefix argument will be interpreted."
  5377. (interactive)
  5378. (let* ((org-agenda-keep-modes t)
  5379. (filter org-agenda-filter)
  5380. (preset (get 'org-agenda-filter :preset-filter))
  5381. (org-agenda-filter-while-redo (or filter preset))
  5382. (cols org-agenda-columns-active)
  5383. (line (org-current-line))
  5384. (window-line (- line (org-current-line (window-start))))
  5385. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5386. (put 'org-agenda-filter :preset-filter nil)
  5387. (and cols (org-columns-quit))
  5388. (message "Rebuilding agenda buffer...")
  5389. (org-let lprops '(eval org-agenda-redo-command))
  5390. (setq org-agenda-undo-list nil
  5391. org-agenda-pending-undo-list nil)
  5392. (message "Rebuilding agenda buffer...done")
  5393. (put 'org-agenda-filter :preset-filter preset)
  5394. (and (or filter preset) (org-agenda-filter-apply filter))
  5395. (and cols (interactive-p) (org-agenda-columns))
  5396. (org-goto-line line)
  5397. (recenter window-line)))
  5398. (defvar org-global-tags-completion-table nil)
  5399. (defvar org-agenda-filter-form nil)
  5400. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5401. "Keep only those lines in the agenda buffer that have a specific tag.
  5402. The tag is selected with its fast selection letter, as configured.
  5403. With prefix argument STRIP, remove all lines that do have the tag.
  5404. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5405. used to narrow the search - the interactive user can also press `-' or `+'
  5406. to switch to narrowing."
  5407. (interactive "P")
  5408. (let* ((alist org-tag-alist-for-agenda)
  5409. (tag-chars (mapconcat
  5410. (lambda (x) (if (and (not (symbolp (car x)))
  5411. (cdr x))
  5412. (char-to-string (cdr x))
  5413. ""))
  5414. alist ""))
  5415. (efforts (org-split-string
  5416. (or (cdr (assoc (concat org-effort-property "_ALL")
  5417. org-global-properties))
  5418. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5419. (effort-op org-agenda-filter-effort-default-operator)
  5420. (effort-prompt "")
  5421. (inhibit-read-only t)
  5422. (current org-agenda-filter)
  5423. a n tag)
  5424. (unless char
  5425. (message
  5426. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5427. (if narrow "Narrow" "Filter") tag-chars
  5428. (if org-agenda-auto-exclude-function "[RET], " ""))
  5429. (setq char (read-char)))
  5430. (when (member char '(?+ ?-))
  5431. ;; Narrowing down
  5432. (cond ((equal char ?-) (setq strip t narrow t))
  5433. ((equal char ?+) (setq strip nil narrow t)))
  5434. (message
  5435. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5436. (setq char (read-char)))
  5437. (when (member char '(?< ?> ?= ??))
  5438. ;; An effort operator
  5439. (setq effort-op (char-to-string char))
  5440. (setq alist nil) ; to make sure it will be interpreted as effort.
  5441. (unless (equal char ??)
  5442. (loop for i from 0 to 9 do
  5443. (setq effort-prompt
  5444. (concat
  5445. effort-prompt " ["
  5446. (if (= i 9) "0" (int-to-string (1+ i)))
  5447. "]" (nth i efforts))))
  5448. (message "Effort%s: %s " effort-op effort-prompt)
  5449. (setq char (read-char))
  5450. (when (or (< char ?0) (> char ?9))
  5451. (error "Need 1-9,0 to select effort" ))))
  5452. (when (equal char ?\t)
  5453. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5454. (org-set-local 'org-global-tags-completion-table
  5455. (org-global-tags-completion-table)))
  5456. (let ((completion-ignore-case t))
  5457. (setq tag (org-icompleting-read
  5458. "Tag: " org-global-tags-completion-table))))
  5459. (cond
  5460. ((equal char ?\r)
  5461. (org-agenda-filter-by-tag-show-all)
  5462. (when org-agenda-auto-exclude-function
  5463. (setq org-agenda-filter '())
  5464. (dolist (tag (org-agenda-get-represented-tags))
  5465. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5466. (if modifier
  5467. (push modifier org-agenda-filter))))
  5468. (if (not (null org-agenda-filter))
  5469. (org-agenda-filter-apply org-agenda-filter))))
  5470. ((equal char ?/)
  5471. (org-agenda-filter-by-tag-show-all)
  5472. (when (get 'org-agenda-filter :preset-filter)
  5473. (org-agenda-filter-apply org-agenda-filter)))
  5474. ((or (equal char ?\ )
  5475. (setq a (rassoc char alist))
  5476. (and (>= char ?0) (<= char ?9)
  5477. (setq n (if (= char ?0) 9 (- char ?0 1))
  5478. tag (concat effort-op (nth n efforts))
  5479. a (cons tag nil)))
  5480. (and (= char ??)
  5481. (setq tag "?eff")
  5482. a (cons tag nil))
  5483. (and tag (setq a (cons tag nil))))
  5484. (org-agenda-filter-by-tag-show-all)
  5485. (setq tag (car a))
  5486. (setq org-agenda-filter
  5487. (cons (concat (if strip "-" "+") tag)
  5488. (if narrow current nil)))
  5489. (org-agenda-filter-apply org-agenda-filter))
  5490. (t (error "Invalid tag selection character %c" char)))))
  5491. (defun org-agenda-get-represented-tags ()
  5492. "Get a list of all tags currently represented in the agenda."
  5493. (let (p tags)
  5494. (save-excursion
  5495. (goto-char (point-min))
  5496. (while (setq p (next-single-property-change (point) 'tags))
  5497. (goto-char p)
  5498. (mapc (lambda (x) (add-to-list 'tags x))
  5499. (get-text-property (point) 'tags))))
  5500. tags))
  5501. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5502. "Refine the current filter. See `org-agenda-filter-by-tag."
  5503. (interactive "P")
  5504. (org-agenda-filter-by-tag strip char 'refine))
  5505. (defun org-agenda-filter-make-matcher ()
  5506. "Create the form that tests a line for the agenda filter."
  5507. (let (f f1)
  5508. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5509. org-agenda-filter))
  5510. (if (member x '("-" "+"))
  5511. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5512. (if (string-match "[<=>?]" x)
  5513. (setq f1 (org-agenda-filter-effort-form x))
  5514. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5515. (if (equal (string-to-char x) ?-)
  5516. (setq f1 (list 'not f1))))
  5517. (push f1 f))
  5518. (cons 'and (nreverse f))))
  5519. (defun org-agenda-filter-effort-form (e)
  5520. "Return the form to compare the effort of the current line with what E says.
  5521. E looks like \"+<2:25\"."
  5522. (let (op)
  5523. (setq e (substring e 1))
  5524. (setq op (string-to-char e) e (substring e 1))
  5525. (setq op (cond ((equal op ?<) '<=)
  5526. ((equal op ?>) '>=)
  5527. ((equal op ??) op)
  5528. (t '=)))
  5529. (list 'org-agenda-compare-effort (list 'quote op)
  5530. (org-hh:mm-string-to-minutes e))))
  5531. (defun org-agenda-compare-effort (op value)
  5532. "Compare the effort of the current line with VALUE, using OP.
  5533. If the line does not have an effort defined, return nil."
  5534. (let ((eff (org-get-at-bol 'effort-minutes)))
  5535. (if (equal op ??)
  5536. (not eff)
  5537. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5538. value))))
  5539. (defun org-agenda-filter-apply (filter)
  5540. "Set FILTER as the new agenda filter and apply it."
  5541. (let (tags)
  5542. (setq org-agenda-filter filter
  5543. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5544. (org-agenda-set-mode-name)
  5545. (save-excursion
  5546. (goto-char (point-min))
  5547. (while (not (eobp))
  5548. (if (org-get-at-bol 'org-marker)
  5549. (progn
  5550. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5551. (if (not (eval org-agenda-filter-form))
  5552. (org-agenda-filter-by-tag-hide-line))
  5553. (beginning-of-line 2))
  5554. (beginning-of-line 2))))
  5555. (if (get-char-property (point) 'invisible)
  5556. (org-agenda-previous-line))))
  5557. (defun org-agenda-filter-by-tag-hide-line ()
  5558. (let (ov)
  5559. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5560. (point-at-eol)))
  5561. (overlay-put ov 'invisible t)
  5562. (overlay-put ov 'type 'tags-filter)
  5563. (push ov org-agenda-filter-overlays)))
  5564. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5565. (setq pos (or pos (point)))
  5566. (save-excursion
  5567. (dolist (ov (overlays-at pos))
  5568. (when (and (overlay-get ov 'invisible)
  5569. (eq (overlay-get ov 'type) 'tags-filter))
  5570. (goto-char pos)
  5571. (if (< (overlay-start ov) (point-at-eol))
  5572. (move-overlay ov (point-at-eol)
  5573. (overlay-end ov)))))))
  5574. (defun org-agenda-filter-by-tag-show-all ()
  5575. (mapc 'delete-overlay org-agenda-filter-overlays)
  5576. (setq org-agenda-filter-overlays nil)
  5577. (setq org-agenda-filter nil)
  5578. (setq org-agenda-filter-form nil)
  5579. (org-agenda-set-mode-name))
  5580. (defun org-agenda-manipulate-query-add ()
  5581. "Manipulate the query by adding a search term with positive selection.
  5582. Positive selection means the term must be matched for selection of an entry."
  5583. (interactive)
  5584. (org-agenda-manipulate-query ?\[))
  5585. (defun org-agenda-manipulate-query-subtract ()
  5586. "Manipulate the query by adding a search term with negative selection.
  5587. Negative selection means term must not be matched for selection of an entry."
  5588. (interactive)
  5589. (org-agenda-manipulate-query ?\]))
  5590. (defun org-agenda-manipulate-query-add-re ()
  5591. "Manipulate the query by adding a search regexp with positive selection.
  5592. Positive selection means the regexp must match for selection of an entry."
  5593. (interactive)
  5594. (org-agenda-manipulate-query ?\{))
  5595. (defun org-agenda-manipulate-query-subtract-re ()
  5596. "Manipulate the query by adding a search regexp with negative selection.
  5597. Negative selection means regexp must not match for selection of an entry."
  5598. (interactive)
  5599. (org-agenda-manipulate-query ?\}))
  5600. (defun org-agenda-manipulate-query (char)
  5601. (cond
  5602. ((memq org-agenda-type '(timeline agenda))
  5603. (let ((org-agenda-include-inactive-timestamps t))
  5604. (org-agenda-redo))
  5605. (message "Display now includes inactive timestamps as well"))
  5606. ((eq org-agenda-type 'search)
  5607. (org-add-to-string
  5608. 'org-agenda-query-string
  5609. (if org-agenda-last-search-view-search-was-boolean
  5610. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5611. (?\{ . " +{}") (?\} . " -{}"))))
  5612. " "))
  5613. (setq org-agenda-redo-command
  5614. (list 'org-search-view
  5615. org-todo-only
  5616. org-agenda-query-string
  5617. (+ (length org-agenda-query-string)
  5618. (if (member char '(?\{ ?\})) 0 1))))
  5619. (set-register org-agenda-query-register org-agenda-query-string)
  5620. (org-agenda-redo))
  5621. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5622. org-agenda-type))))
  5623. (defun org-add-to-string (var string)
  5624. (set var (concat (symbol-value var) string)))
  5625. (defun org-agenda-goto-date (date)
  5626. "Jump to DATE in agenda."
  5627. (interactive (list (let ((org-read-date-prefer-future
  5628. (eval org-agenda-jump-prefer-future)))
  5629. (org-read-date))))
  5630. (org-agenda-list nil date))
  5631. (defun org-agenda-goto-today ()
  5632. "Go to today."
  5633. (interactive)
  5634. (org-agenda-check-type t 'timeline 'agenda)
  5635. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5636. (cond
  5637. (tdpos (goto-char tdpos))
  5638. ((eq org-agenda-type 'agenda)
  5639. (let* ((sd (org-agenda-compute-starting-span
  5640. (org-today) (or org-agenda-ndays org-agenda-span)))
  5641. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5642. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5643. (org-agenda-redo)
  5644. (org-agenda-find-same-or-today-or-agenda)))
  5645. (t (error "Cannot find today")))))
  5646. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5647. (goto-char
  5648. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5649. (text-property-any (point-min) (point-max) 'org-today t)
  5650. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5651. (point-min))))
  5652. (defun org-agenda-later (arg)
  5653. "Go forward in time by thee current span.
  5654. With prefix ARG, go forward that many times the current span."
  5655. (interactive "p")
  5656. (org-agenda-check-type t 'agenda)
  5657. (let* ((span org-agenda-current-span)
  5658. (sd org-starting-day)
  5659. (greg (calendar-gregorian-from-absolute sd))
  5660. (cnt (org-get-at-bol 'org-day-cnt))
  5661. greg2)
  5662. (cond
  5663. ((eq span 'day)
  5664. (setq sd (+ arg sd)))
  5665. ((eq span 'week)
  5666. (setq sd (+ (* 7 arg) sd)))
  5667. ((eq span 'month)
  5668. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5669. sd (calendar-absolute-from-gregorian greg2))
  5670. (setcar greg2 (1+ (car greg2))))
  5671. ((eq span 'year)
  5672. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5673. sd (calendar-absolute-from-gregorian greg2))
  5674. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5675. (t
  5676. (setq sd (+ (* span arg) sd))))
  5677. (let ((org-agenda-overriding-arguments
  5678. (list (car org-agenda-last-arguments) sd span t)))
  5679. (org-agenda-redo)
  5680. (org-agenda-find-same-or-today-or-agenda cnt))))
  5681. (defun org-agenda-earlier (arg)
  5682. "Go backward in time by the current span.
  5683. With prefix ARG, go backward that many times the current span."
  5684. (interactive "p")
  5685. (org-agenda-later (- arg)))
  5686. (defun org-agenda-view-mode-dispatch ()
  5687. "Call one of the view mode commands."
  5688. (interactive)
  5689. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5690. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5691. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5692. (let ((a (read-char-exclusive)))
  5693. (case a
  5694. (?d (call-interactively 'org-agenda-day-view))
  5695. (?w (call-interactively 'org-agenda-week-view))
  5696. (?m (call-interactively 'org-agenda-month-view))
  5697. (?y (call-interactively 'org-agenda-year-view))
  5698. (?l (call-interactively 'org-agenda-log-mode))
  5699. (?L (org-agenda-log-mode '(4)))
  5700. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5701. (?a (call-interactively 'org-agenda-archives-mode))
  5702. (?A (org-agenda-archives-mode 'files))
  5703. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5704. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5705. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5706. (?D (call-interactively 'org-agenda-toggle-diary))
  5707. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5708. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5709. (org-agenda-check-type t 'timeline 'agenda)
  5710. (org-agenda-redo))
  5711. (message "Display now includes inactive timestamps as well"))
  5712. (?q (message "Abort"))
  5713. (otherwise (error "Invalid key" )))))
  5714. (defun org-agenda-day-view (&optional day-of-year)
  5715. "Switch to daily view for agenda.
  5716. With argument DAY-OF-YEAR, switch to that day of the year."
  5717. (interactive "P")
  5718. (org-agenda-change-time-span 'day day-of-year))
  5719. (defun org-agenda-week-view (&optional iso-week)
  5720. "Switch to daily view for agenda.
  5721. With argument ISO-WEEK, switch to the corresponding ISO week.
  5722. If ISO-WEEK has more then 2 digits, only the last two encode the
  5723. week. Any digits before this encode a year. So 200712 means
  5724. week 12 of year 2007. Years in the range 1938-2037 can also be
  5725. written as 2-digit years."
  5726. (interactive "P")
  5727. (org-agenda-change-time-span 'week iso-week))
  5728. (defun org-agenda-month-view (&optional month)
  5729. "Switch to monthly view for agenda.
  5730. With argument MONTH, switch to that month."
  5731. (interactive "P")
  5732. (org-agenda-change-time-span 'month month))
  5733. (defun org-agenda-year-view (&optional year)
  5734. "Switch to yearly view for agenda.
  5735. With argument YEAR, switch to that year.
  5736. If MONTH has more then 2 digits, only the last two encode the
  5737. month. Any digits before this encode a year. So 200712 means
  5738. December year 2007. Years in the range 1938-2037 can also be
  5739. written as 2-digit years."
  5740. (interactive "P")
  5741. (when year
  5742. (setq year (org-small-year-to-year year)))
  5743. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5744. (org-agenda-change-time-span 'year year)
  5745. (error "Abort")))
  5746. (defun org-agenda-change-time-span (span &optional n)
  5747. "Change the agenda view to SPAN.
  5748. SPAN may be `day', `week', `month', `year'."
  5749. (org-agenda-check-type t 'agenda)
  5750. (if (and (not n) (equal org-agenda-current-span span))
  5751. (error "Viewing span is already \"%s\"" span))
  5752. (let* ((sd (or (org-get-at-bol 'day)
  5753. org-starting-day))
  5754. (sd (org-agenda-compute-starting-span sd span n))
  5755. (org-agenda-overriding-arguments
  5756. (list (car org-agenda-last-arguments) sd span t)))
  5757. (org-agenda-redo)
  5758. (org-agenda-find-same-or-today-or-agenda))
  5759. (org-agenda-set-mode-name)
  5760. (message "Switched to %s view" span))
  5761. (defun org-agenda-compute-starting-span (sd span &optional n)
  5762. "Compute starting date for agenda.
  5763. SPAN may be `day', `week', `month', `year'. The return value
  5764. is a cons cell with the starting date and the number of days,
  5765. so that the date SD will be in that range."
  5766. (let* ((greg (calendar-gregorian-from-absolute sd))
  5767. (dg (nth 1 greg))
  5768. (mg (car greg))
  5769. (yg (nth 2 greg)))
  5770. (cond
  5771. ((eq span 'day)
  5772. (when n
  5773. (setq sd (+ (calendar-absolute-from-gregorian
  5774. (list mg 1 yg))
  5775. n -1))))
  5776. ((eq span 'week)
  5777. (let* ((nt (calendar-day-of-week
  5778. (calendar-gregorian-from-absolute sd)))
  5779. (d (if org-agenda-start-on-weekday
  5780. (- nt org-agenda-start-on-weekday)
  5781. 0))
  5782. y1)
  5783. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5784. (when n
  5785. (require 'cal-iso)
  5786. (when (> n 99)
  5787. (setq y1 (org-small-year-to-year (/ n 100))
  5788. n (mod n 100)))
  5789. (setq sd
  5790. (calendar-absolute-from-iso
  5791. (list n 1
  5792. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  5793. ((eq span 'month)
  5794. (let (y1)
  5795. (when (and n (> n 99))
  5796. (setq y1 (org-small-year-to-year (/ n 100))
  5797. n (mod n 100)))
  5798. (setq sd (calendar-absolute-from-gregorian
  5799. (list (or n mg) 1 (or y1 yg))))))
  5800. ((eq span 'year)
  5801. (setq sd (calendar-absolute-from-gregorian
  5802. (list 1 1 (or n yg))))))
  5803. sd))
  5804. (defun org-agenda-next-date-line (&optional arg)
  5805. "Jump to the next line indicating a date in agenda buffer."
  5806. (interactive "p")
  5807. (org-agenda-check-type t 'agenda 'timeline)
  5808. (beginning-of-line 1)
  5809. ;; This does not work if user makes date format that starts with a blank
  5810. (if (looking-at "^\\S-") (forward-char 1))
  5811. (if (not (re-search-forward "^\\S-" nil t arg))
  5812. (progn
  5813. (backward-char 1)
  5814. (error "No next date after this line in this buffer")))
  5815. (goto-char (match-beginning 0)))
  5816. (defun org-agenda-previous-date-line (&optional arg)
  5817. "Jump to the previous line indicating a date in agenda buffer."
  5818. (interactive "p")
  5819. (org-agenda-check-type t 'agenda 'timeline)
  5820. (beginning-of-line 1)
  5821. (if (not (re-search-backward "^\\S-" nil t arg))
  5822. (error "No previous date before this line in this buffer")))
  5823. ;; Initialize the highlight
  5824. (defvar org-hl (make-overlay 1 1))
  5825. (overlay-put org-hl 'face 'highlight)
  5826. (defun org-highlight (begin end &optional buffer)
  5827. "Highlight a region with overlay."
  5828. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5829. (defun org-unhighlight ()
  5830. "Detach overlay INDEX."
  5831. (org-detach-overlay org-hl))
  5832. ;; FIXME this is currently not used.
  5833. (defun org-highlight-until-next-command (beg end &optional buffer)
  5834. "Move the highlight overlay to BEG/END, remove it before the next command."
  5835. (org-highlight beg end buffer)
  5836. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5837. (defun org-unhighlight-once ()
  5838. "Remove the highlight from its position, and this function from the hook."
  5839. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5840. (org-unhighlight))
  5841. (defun org-agenda-follow-mode ()
  5842. "Toggle follow mode in an agenda buffer."
  5843. (interactive)
  5844. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5845. (org-agenda-set-mode-name)
  5846. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5847. (org-agenda-show))
  5848. (message "Follow mode is %s"
  5849. (if org-agenda-follow-mode "on" "off")))
  5850. (defun org-agenda-entry-text-mode (&optional arg)
  5851. "Toggle entry text mode in an agenda buffer."
  5852. (interactive "P")
  5853. (setq org-agenda-entry-text-mode (or (integerp arg)
  5854. (not org-agenda-entry-text-mode)))
  5855. (org-agenda-entry-text-hide)
  5856. (and org-agenda-entry-text-mode
  5857. (let ((org-agenda-entry-text-maxlines
  5858. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5859. (org-agenda-entry-text-show)))
  5860. (org-agenda-set-mode-name)
  5861. (message "Entry text mode is %s. Maximum number of lines is %d"
  5862. (if org-agenda-entry-text-mode "on" "off")
  5863. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5864. (defun org-agenda-clockreport-mode (&optional with-filter)
  5865. "Toggle clocktable mode in an agenda buffer.
  5866. With prefix arg WITH-FILTER, make the clocktable respect the current
  5867. agenda filter."
  5868. (interactive "P")
  5869. (org-agenda-check-type t 'agenda)
  5870. (if with-filter
  5871. (setq org-agenda-clockreport-mode 'with-filter)
  5872. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5873. (org-agenda-set-mode-name)
  5874. (org-agenda-redo)
  5875. (message "Clocktable mode is %s"
  5876. (if org-agenda-clockreport-mode "on" "off")))
  5877. (defun org-agenda-log-mode (&optional special)
  5878. "Toggle log mode in an agenda buffer.
  5879. With argument SPECIAL, show all possible log items, not only the ones
  5880. configured in `org-agenda-log-mode-items'.
  5881. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5882. (interactive "P")
  5883. (org-agenda-check-type t 'agenda 'timeline)
  5884. (setq org-agenda-show-log
  5885. (if (equal special '(16))
  5886. 'only
  5887. (if special '(closed clock state)
  5888. (not org-agenda-show-log))))
  5889. (org-agenda-set-mode-name)
  5890. (org-agenda-redo)
  5891. (message "Log mode is %s"
  5892. (if org-agenda-show-log "on" "off")))
  5893. (defun org-agenda-archives-mode (&optional with-files)
  5894. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5895. When called with a prefix argument, include all archive files as well."
  5896. (interactive "P")
  5897. (setq org-agenda-archives-mode
  5898. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5899. (org-agenda-set-mode-name)
  5900. (org-agenda-redo)
  5901. (message
  5902. "%s"
  5903. (cond
  5904. ((eq org-agenda-archives-mode nil)
  5905. "No archives are included")
  5906. ((eq org-agenda-archives-mode 'trees)
  5907. (format "Trees with :%s: tag are included" org-archive-tag))
  5908. ((eq org-agenda-archives-mode t)
  5909. (format "Trees with :%s: tag and all active archive files are included"
  5910. org-archive-tag)))))
  5911. (defun org-agenda-toggle-diary ()
  5912. "Toggle diary inclusion in an agenda buffer."
  5913. (interactive)
  5914. (org-agenda-check-type t 'agenda)
  5915. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5916. (org-agenda-redo)
  5917. (org-agenda-set-mode-name)
  5918. (message "Diary inclusion turned %s"
  5919. (if org-agenda-include-diary "on" "off")))
  5920. (defun org-agenda-toggle-deadlines ()
  5921. "Toggle inclusion of entries with a deadline in an agenda buffer."
  5922. (interactive)
  5923. (org-agenda-check-type t 'agenda)
  5924. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5925. (org-agenda-redo)
  5926. (org-agenda-set-mode-name)
  5927. (message "Deadlines inclusion turned %s"
  5928. (if org-agenda-include-deadlines "on" "off")))
  5929. (defun org-agenda-toggle-time-grid ()
  5930. "Toggle time grid in an agenda buffer."
  5931. (interactive)
  5932. (org-agenda-check-type t 'agenda)
  5933. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5934. (org-agenda-redo)
  5935. (org-agenda-set-mode-name)
  5936. (message "Time-grid turned %s"
  5937. (if org-agenda-use-time-grid "on" "off")))
  5938. (defun org-agenda-set-mode-name ()
  5939. "Set the mode name to indicate all the small mode settings."
  5940. (setq mode-name
  5941. (list "Org-Agenda"
  5942. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5943. " "
  5944. '(:eval (org-agenda-span-name org-agenda-current-span))
  5945. (if org-agenda-follow-mode " Follow" "")
  5946. (if org-agenda-entry-text-mode " ETxt" "")
  5947. (if org-agenda-include-diary " Diary" "")
  5948. (if org-agenda-include-deadlines " Ddl" "")
  5949. (if org-agenda-use-time-grid " Grid" "")
  5950. (if (and (boundp 'org-habit-show-habits)
  5951. org-habit-show-habits) " Habit" "")
  5952. (if (consp org-agenda-show-log) " LogAll"
  5953. (if org-agenda-show-log " Log" ""))
  5954. (if (or org-agenda-filter (get 'org-agenda-filter
  5955. :preset-filter))
  5956. (concat " {" (mapconcat
  5957. 'identity
  5958. (append (get 'org-agenda-filter
  5959. :preset-filter)
  5960. org-agenda-filter) "") "}")
  5961. "")
  5962. (if org-agenda-archives-mode
  5963. (if (eq org-agenda-archives-mode t)
  5964. " Archives"
  5965. (format " :%s:" org-archive-tag))
  5966. "")
  5967. (if org-agenda-clockreport-mode
  5968. (if (eq org-agenda-clockreport-mode 'with-filter)
  5969. " Clock{}" " Clock")
  5970. "")))
  5971. (force-mode-line-update))
  5972. (defun org-agenda-post-command-hook ()
  5973. (setq org-agenda-type
  5974. (or (get-text-property (point) 'org-agenda-type)
  5975. (get-text-property (max (point-min) (1- (point)))
  5976. 'org-agenda-type))))
  5977. (defun org-agenda-next-line ()
  5978. "Move cursor to the next line, and show if follow mode is active."
  5979. (interactive)
  5980. (call-interactively 'next-line)
  5981. (org-agenda-do-context-action))
  5982. (defun org-agenda-previous-line ()
  5983. "Move cursor to the previous line, and show if follow-mode is active."
  5984. (interactive)
  5985. (call-interactively 'previous-line)
  5986. (org-agenda-do-context-action))
  5987. (defun org-agenda-do-context-action ()
  5988. "Show outline path and, maybe, follow mode window."
  5989. (let ((m (org-get-at-bol 'org-marker)))
  5990. (if (and org-agenda-follow-mode m)
  5991. (org-agenda-show))
  5992. (if (and m org-agenda-show-outline-path)
  5993. (org-with-point-at m
  5994. (org-display-outline-path t)))))
  5995. (defun org-agenda-show-priority ()
  5996. "Show the priority of the current item.
  5997. This priority is composed of the main priority given with the [#A] cookies,
  5998. and by additional input from the age of a schedules or deadline entry."
  5999. (interactive)
  6000. (let* ((pri (org-get-at-bol 'priority)))
  6001. (message "Priority is %d" (if pri pri -1000))))
  6002. (defun org-agenda-show-tags ()
  6003. "Show the tags applicable to the current item."
  6004. (interactive)
  6005. (let* ((tags (org-get-at-bol 'tags)))
  6006. (if tags
  6007. (message "Tags are :%s:"
  6008. (org-no-properties (mapconcat 'identity tags ":")))
  6009. (message "No tags associated with this line"))))
  6010. (defun org-agenda-goto (&optional highlight)
  6011. "Go to the Org-mode file which contains the item at point."
  6012. (interactive)
  6013. (let* ((marker (or (org-get-at-bol 'org-marker)
  6014. (org-agenda-error)))
  6015. (buffer (marker-buffer marker))
  6016. (pos (marker-position marker)))
  6017. (switch-to-buffer-other-window buffer)
  6018. (widen)
  6019. (push-mark)
  6020. (goto-char pos)
  6021. (when (org-mode-p)
  6022. (org-show-context 'agenda)
  6023. (save-excursion
  6024. (and (outline-next-heading)
  6025. (org-flag-heading nil)))) ; show the next heading
  6026. (when (outline-invisible-p)
  6027. (show-entry)) ; display invisible text
  6028. (recenter (/ (window-height) 2))
  6029. (run-hooks 'org-agenda-after-show-hook)
  6030. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6031. (defvar org-agenda-after-show-hook nil
  6032. "Normal hook run after an item has been shown from the agenda.
  6033. Point is in the buffer where the item originated.")
  6034. (defun org-agenda-kill ()
  6035. "Kill the entry or subtree belonging to the current agenda entry."
  6036. (interactive)
  6037. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6038. (let* ((marker (or (org-get-at-bol 'org-marker)
  6039. (org-agenda-error)))
  6040. (buffer (marker-buffer marker))
  6041. (pos (marker-position marker))
  6042. (type (org-get-at-bol 'type))
  6043. dbeg dend (n 0) conf)
  6044. (org-with-remote-undo buffer
  6045. (with-current-buffer buffer
  6046. (save-excursion
  6047. (goto-char pos)
  6048. (if (and (org-mode-p) (not (member type '("sexp"))))
  6049. (setq dbeg (progn (org-back-to-heading t) (point))
  6050. dend (org-end-of-subtree t t))
  6051. (setq dbeg (point-at-bol)
  6052. dend (min (point-max) (1+ (point-at-eol)))))
  6053. (goto-char dbeg)
  6054. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6055. (setq conf (or (eq t org-agenda-confirm-kill)
  6056. (and (numberp org-agenda-confirm-kill)
  6057. (> n org-agenda-confirm-kill))))
  6058. (and conf
  6059. (not (y-or-n-p
  6060. (format "Delete entry with %d lines in buffer \"%s\"? "
  6061. n (buffer-name buffer))))
  6062. (error "Abort"))
  6063. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6064. (with-current-buffer buffer (delete-region dbeg dend))
  6065. (message "Agenda item and source killed"))))
  6066. (defvar org-archive-default-command)
  6067. (defun org-agenda-archive-default ()
  6068. "Archive the entry or subtree belonging to the current agenda entry."
  6069. (interactive)
  6070. (require 'org-archive)
  6071. (org-agenda-archive-with org-archive-default-command))
  6072. (defun org-agenda-archive-default-with-confirmation ()
  6073. "Archive the entry or subtree belonging to the current agenda entry."
  6074. (interactive)
  6075. (require 'org-archive)
  6076. (org-agenda-archive-with org-archive-default-command 'confirm))
  6077. (defun org-agenda-archive ()
  6078. "Archive the entry or subtree belonging to the current agenda entry."
  6079. (interactive)
  6080. (org-agenda-archive-with 'org-archive-subtree))
  6081. (defun org-agenda-archive-to-archive-sibling ()
  6082. "Move the entry to the archive sibling."
  6083. (interactive)
  6084. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6085. (defun org-agenda-archive-with (cmd &optional confirm)
  6086. "Move the entry to the archive sibling."
  6087. (interactive)
  6088. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6089. (let* ((marker (or (org-get-at-bol 'org-marker)
  6090. (org-agenda-error)))
  6091. (buffer (marker-buffer marker))
  6092. (pos (marker-position marker)))
  6093. (org-with-remote-undo buffer
  6094. (with-current-buffer buffer
  6095. (if (org-mode-p)
  6096. (if (and confirm
  6097. (not (y-or-n-p "Archive this subtree or entry? ")))
  6098. (error "Abort")
  6099. (save-excursion
  6100. (goto-char pos)
  6101. (org-remove-subtree-entries-from-agenda)
  6102. (org-back-to-heading t)
  6103. (funcall cmd)))
  6104. (error "Archiving works only in Org-mode files"))))))
  6105. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6106. "Remove all lines in the agenda that correspond to a given subtree.
  6107. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6108. If this information is not given, the function uses the tree at point."
  6109. (let ((buf (or buf (current-buffer))) m p)
  6110. (save-excursion
  6111. (unless (and beg end)
  6112. (org-back-to-heading t)
  6113. (setq beg (point))
  6114. (org-end-of-subtree t)
  6115. (setq end (point)))
  6116. (set-buffer (get-buffer org-agenda-buffer-name))
  6117. (save-excursion
  6118. (goto-char (point-max))
  6119. (beginning-of-line 1)
  6120. (while (not (bobp))
  6121. (when (and (setq m (org-get-at-bol 'org-marker))
  6122. (equal buf (marker-buffer m))
  6123. (setq p (marker-position m))
  6124. (>= p beg)
  6125. (< p end))
  6126. (let ((inhibit-read-only t))
  6127. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6128. (beginning-of-line 0))))))
  6129. (defun org-agenda-refile (&optional goto rfloc no-update)
  6130. "Refile the item at point."
  6131. (interactive "P")
  6132. (if (equal goto '(16))
  6133. (org-refile-goto-last-stored)
  6134. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6135. (org-agenda-error)))
  6136. (buffer (marker-buffer marker))
  6137. (pos (marker-position marker))
  6138. (rfloc (or rfloc
  6139. (org-refile-get-location
  6140. (if goto "Goto: " "Refile to: ") buffer
  6141. org-refile-allow-creating-parent-nodes))))
  6142. (with-current-buffer buffer
  6143. (save-excursion
  6144. (save-restriction
  6145. (widen)
  6146. (goto-char marker)
  6147. (org-remove-subtree-entries-from-agenda)
  6148. (org-refile goto buffer rfloc)))))
  6149. (unless no-update (org-agenda-redo))))
  6150. (defun org-agenda-open-link (&optional arg)
  6151. "Follow the link in the current line, if any.
  6152. This looks for a link in the displayed line in the agenda. It also looks
  6153. at the text of the entry itself."
  6154. (interactive "P")
  6155. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6156. (org-get-at-bol 'org-marker)))
  6157. (buffer (and marker (marker-buffer marker)))
  6158. (prefix (buffer-substring
  6159. (point-at-bol)
  6160. (+ (point-at-bol)
  6161. (or (org-get-at-bol 'prefix-length) 0)))))
  6162. (cond
  6163. (buffer
  6164. (with-current-buffer buffer
  6165. (save-excursion
  6166. (save-restriction
  6167. (widen)
  6168. (goto-char marker)
  6169. (org-offer-links-in-entry arg prefix)))))
  6170. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6171. (save-excursion
  6172. (beginning-of-line 1)
  6173. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6174. (org-open-link-from-string (match-string 1)))
  6175. (t (error "No link to open here")))))
  6176. (defun org-agenda-copy-local-variable (var)
  6177. "Get a variable from a referenced buffer and install it here."
  6178. (let ((m (org-get-at-bol 'org-marker)))
  6179. (when (and m (buffer-live-p (marker-buffer m)))
  6180. (org-set-local var (with-current-buffer (marker-buffer m)
  6181. (symbol-value var))))))
  6182. (defun org-agenda-switch-to (&optional delete-other-windows)
  6183. "Go to the Org-mode file which contains the item at point."
  6184. (interactive)
  6185. (if (and org-return-follows-link
  6186. (not (org-get-at-bol 'org-marker))
  6187. (org-in-regexp org-bracket-link-regexp))
  6188. (org-open-link-from-string (match-string 0))
  6189. (let* ((marker (or (org-get-at-bol 'org-marker)
  6190. (org-agenda-error)))
  6191. (buffer (marker-buffer marker))
  6192. (pos (marker-position marker)))
  6193. (switch-to-buffer buffer)
  6194. (and delete-other-windows (delete-other-windows))
  6195. (widen)
  6196. (goto-char pos)
  6197. (when (org-mode-p)
  6198. (org-show-context 'agenda)
  6199. (save-excursion
  6200. (and (outline-next-heading)
  6201. (org-flag-heading nil))) ; show the next heading
  6202. (when (outline-invisible-p)
  6203. (show-entry)))))) ; display invisible text
  6204. (defun org-agenda-goto-mouse (ev)
  6205. "Go to the Org-mode file which contains the item at the mouse click."
  6206. (interactive "e")
  6207. (mouse-set-point ev)
  6208. (org-agenda-goto))
  6209. (defun org-agenda-show (&optional full-entry)
  6210. "Display the Org-mode file which contains the item at point.
  6211. With prefix argument FULL-ENTRY, make the entire entry visible
  6212. if it was hidden in the outline."
  6213. (interactive "P")
  6214. (let ((win (selected-window)))
  6215. (if full-entry
  6216. (let ((org-show-entry-below t))
  6217. (org-agenda-goto t))
  6218. (org-agenda-goto t))
  6219. (select-window win)))
  6220. (defvar org-agenda-show-window nil)
  6221. (defun org-agenda-show-and-scroll-up ()
  6222. "Display the Org-mode file which contains the item at point.
  6223. When called repeatedly, scroll the window that is displaying the buffer."
  6224. (interactive)
  6225. (let ((win (selected-window)))
  6226. (if (and (window-live-p org-agenda-show-window)
  6227. (eq this-command last-command))
  6228. (progn
  6229. (select-window org-agenda-show-window)
  6230. (ignore-errors (scroll-up)))
  6231. (org-agenda-goto t)
  6232. (show-subtree)
  6233. (setq org-agenda-show-window (selected-window)))
  6234. (select-window win)))
  6235. (defun org-agenda-show-scroll-down ()
  6236. "Scroll down the window showing the agenda."
  6237. (interactive)
  6238. (let ((win (selected-window)))
  6239. (when (window-live-p org-agenda-show-window)
  6240. (select-window org-agenda-show-window)
  6241. (ignore-errors (scroll-down))
  6242. (select-window win))))
  6243. (defun org-agenda-show-1 (&optional more)
  6244. "Display the Org-mode file which contains the item at point.
  6245. The prefix arg selects the amount of information to display:
  6246. 0 hide the subtree
  6247. 1 just show the entry according to defaults.
  6248. 2 show the children view
  6249. 3 show the subtree view
  6250. 4 show the entire subtree and any LOGBOOK drawers
  6251. 5 show the entire subtree and any drawers
  6252. With prefix argument FULL-ENTRY, make the entire entry visible
  6253. if it was hidden in the outline."
  6254. (interactive "p")
  6255. (let ((win (selected-window)))
  6256. (org-agenda-goto t)
  6257. (org-recenter-heading 1)
  6258. (cond
  6259. ((= more 0)
  6260. (hide-subtree)
  6261. (save-excursion
  6262. (org-back-to-heading)
  6263. (run-hook-with-args 'org-cycle-hook 'folded))
  6264. (message "Remote: FOLDED"))
  6265. ((and (interactive-p) (= more 1))
  6266. (message "Remote: show with default settings"))
  6267. ((= more 2)
  6268. (show-entry)
  6269. (show-children)
  6270. (save-excursion
  6271. (org-back-to-heading)
  6272. (run-hook-with-args 'org-cycle-hook 'children))
  6273. (message "Remote: CHILDREN"))
  6274. ((= more 3)
  6275. (show-subtree)
  6276. (save-excursion
  6277. (org-back-to-heading)
  6278. (run-hook-with-args 'org-cycle-hook 'subtree))
  6279. (message "Remote: SUBTREE"))
  6280. ((= more 4)
  6281. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6282. (org-drawer-regexp
  6283. (concat "^[ \t]*:\\("
  6284. (mapconcat 'regexp-quote org-drawers "\\|")
  6285. "\\):[ \t]*$")))
  6286. (show-subtree)
  6287. (save-excursion
  6288. (org-back-to-heading)
  6289. (org-cycle-hide-drawers 'subtree)))
  6290. (message "Remote: SUBTREE AND LOGBOOK"))
  6291. ((> more 4)
  6292. (show-subtree)
  6293. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6294. (select-window win)))
  6295. (defun org-recenter-heading (n)
  6296. (save-excursion
  6297. (org-back-to-heading)
  6298. (recenter n)))
  6299. (defvar org-agenda-cycle-counter nil)
  6300. (defun org-agenda-cycle-show (&optional n)
  6301. "Show the current entry in another window, with default settings.
  6302. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6303. When use repeatedly in immediate succession, the remote entry will cycle
  6304. through visibility
  6305. children -> subtree -> folded
  6306. When called with a numeric prefix arg, that arg will be passed through to
  6307. `org-agenda-show-1'. For the interpretation of that argument, see the
  6308. docstring of `org-agenda-show-1'."
  6309. (interactive "P")
  6310. (if (integerp n)
  6311. (setq org-agenda-cycle-counter n)
  6312. (if (not (eq last-command this-command))
  6313. (setq org-agenda-cycle-counter 1)
  6314. (if (equal org-agenda-cycle-counter 0)
  6315. (setq org-agenda-cycle-counter 2)
  6316. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6317. (if (> org-agenda-cycle-counter 3)
  6318. (setq org-agenda-cycle-counter 0)))))
  6319. (org-agenda-show-1 org-agenda-cycle-counter))
  6320. (defun org-agenda-recenter (arg)
  6321. "Display the Org-mode file which contains the item at point and recenter."
  6322. (interactive "P")
  6323. (let ((win (selected-window)))
  6324. (org-agenda-goto t)
  6325. (recenter arg)
  6326. (select-window win)))
  6327. (defun org-agenda-show-mouse (ev)
  6328. "Display the Org-mode file which contains the item at the mouse click."
  6329. (interactive "e")
  6330. (mouse-set-point ev)
  6331. (org-agenda-show))
  6332. (defun org-agenda-check-no-diary ()
  6333. "Check if the entry is a diary link and abort if yes."
  6334. (if (org-get-at-bol 'org-agenda-diary-link)
  6335. (org-agenda-error)))
  6336. (defun org-agenda-error ()
  6337. (error "Command not allowed in this line"))
  6338. (defun org-agenda-tree-to-indirect-buffer ()
  6339. "Show the subtree corresponding to the current entry in an indirect buffer.
  6340. This calls the command `org-tree-to-indirect-buffer' from the original
  6341. Org-mode buffer.
  6342. With numerical prefix arg ARG, go up to this level and then take that tree.
  6343. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6344. use the dedicated frame)."
  6345. (interactive)
  6346. (org-agenda-check-no-diary)
  6347. (let* ((marker (or (org-get-at-bol 'org-marker)
  6348. (org-agenda-error)))
  6349. (buffer (marker-buffer marker))
  6350. (pos (marker-position marker)))
  6351. (with-current-buffer buffer
  6352. (save-excursion
  6353. (goto-char pos)
  6354. (call-interactively 'org-tree-to-indirect-buffer)))))
  6355. (defvar org-last-heading-marker (make-marker)
  6356. "Marker pointing to the headline that last changed its TODO state
  6357. by a remote command from the agenda.")
  6358. (defun org-agenda-todo-nextset ()
  6359. "Switch TODO entry to next sequence."
  6360. (interactive)
  6361. (org-agenda-todo 'nextset))
  6362. (defun org-agenda-todo-previousset ()
  6363. "Switch TODO entry to previous sequence."
  6364. (interactive)
  6365. (org-agenda-todo 'previousset))
  6366. (defun org-agenda-todo (&optional arg)
  6367. "Cycle TODO state of line at point, also in Org-mode file.
  6368. This changes the line at point, all other lines in the agenda referring to
  6369. the same tree node, and the headline of the tree node in the Org-mode file."
  6370. (interactive "P")
  6371. (org-agenda-check-no-diary)
  6372. (let* ((col (current-column))
  6373. (marker (or (org-get-at-bol 'org-marker)
  6374. (org-agenda-error)))
  6375. (buffer (marker-buffer marker))
  6376. (pos (marker-position marker))
  6377. (hdmarker (org-get-at-bol 'org-hd-marker))
  6378. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6379. (inhibit-read-only t)
  6380. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6381. (org-with-remote-undo buffer
  6382. (with-current-buffer buffer
  6383. (widen)
  6384. (goto-char pos)
  6385. (org-show-context 'agenda)
  6386. (save-excursion
  6387. (and (outline-next-heading)
  6388. (org-flag-heading nil))) ; show the next heading
  6389. (let ((current-prefix-arg arg))
  6390. (call-interactively 'org-todo))
  6391. (and (bolp) (forward-char 1))
  6392. (setq newhead (org-get-heading))
  6393. (when (and (org-bound-and-true-p
  6394. org-agenda-headline-snapshot-before-repeat)
  6395. (not (equal org-agenda-headline-snapshot-before-repeat
  6396. newhead))
  6397. todayp)
  6398. (setq newhead org-agenda-headline-snapshot-before-repeat
  6399. just-one t))
  6400. (save-excursion
  6401. (org-back-to-heading)
  6402. (move-marker org-last-heading-marker (point))))
  6403. (beginning-of-line 1)
  6404. (save-excursion
  6405. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6406. (org-move-to-column col))))
  6407. (defun org-agenda-add-note (&optional arg)
  6408. "Add a time-stamped note to the entry at point."
  6409. (interactive "P")
  6410. (org-agenda-check-no-diary)
  6411. (let* ((marker (or (org-get-at-bol 'org-marker)
  6412. (org-agenda-error)))
  6413. (buffer (marker-buffer marker))
  6414. (pos (marker-position marker))
  6415. (hdmarker (org-get-at-bol 'org-hd-marker))
  6416. (inhibit-read-only t))
  6417. (with-current-buffer buffer
  6418. (widen)
  6419. (goto-char pos)
  6420. (org-show-context 'agenda)
  6421. (save-excursion
  6422. (and (outline-next-heading)
  6423. (org-flag-heading nil))) ; show the next heading
  6424. (org-add-note))))
  6425. (defun org-agenda-change-all-lines (newhead hdmarker
  6426. &optional fixface just-this)
  6427. "Change all lines in the agenda buffer which match HDMARKER.
  6428. The new content of the line will be NEWHEAD (as modified by
  6429. `org-format-agenda-item'). HDMARKER is checked with
  6430. `equal' against all `org-hd-marker' text properties in the file.
  6431. If FIXFACE is non-nil, the face of each item is modified according to
  6432. the new TODO state.
  6433. If JUST-THIS is non-nil, change just the current line, not all.
  6434. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6435. (let* ((inhibit-read-only t)
  6436. (line (org-current-line))
  6437. (thetags (with-current-buffer (marker-buffer hdmarker)
  6438. (save-excursion (save-restriction (widen)
  6439. (goto-char hdmarker)
  6440. (org-get-tags-at)))))
  6441. props m pl undone-face done-face finish new dotime cat tags)
  6442. (save-excursion
  6443. (goto-char (point-max))
  6444. (beginning-of-line 1)
  6445. (while (not finish)
  6446. (setq finish (bobp))
  6447. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6448. (or (not just-this) (= (org-current-line) line))
  6449. (equal m hdmarker))
  6450. (setq props (text-properties-at (point))
  6451. dotime (org-get-at-bol 'dotime)
  6452. cat (org-get-at-bol 'org-category)
  6453. tags thetags
  6454. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6455. pl (org-get-at-bol 'prefix-length)
  6456. undone-face (org-get-at-bol 'undone-face)
  6457. done-face (org-get-at-bol 'done-face))
  6458. (goto-char (+ (point) pl))
  6459. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6460. (cond
  6461. ((equal new "")
  6462. (beginning-of-line 1)
  6463. (and (looking-at ".*\n?") (replace-match "")))
  6464. ((looking-at ".*")
  6465. (replace-match new t t)
  6466. (beginning-of-line 1)
  6467. (add-text-properties (point-at-bol) (point-at-eol) props)
  6468. (when fixface
  6469. (add-text-properties
  6470. (point-at-bol) (point-at-eol)
  6471. (list 'face
  6472. (if org-last-todo-state-is-todo
  6473. undone-face done-face))))
  6474. (org-agenda-highlight-todo 'line)
  6475. (beginning-of-line 1))
  6476. (t (error "Line update did not work"))))
  6477. (beginning-of-line 0)))
  6478. (org-finalize-agenda)))
  6479. (defun org-agenda-align-tags (&optional line)
  6480. "Align all tags in agenda items to `org-agenda-tags-column'."
  6481. (let ((inhibit-read-only t) l c)
  6482. (save-excursion
  6483. (goto-char (if line (point-at-bol) (point-min)))
  6484. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6485. (if line (point-at-eol) nil) t)
  6486. (add-text-properties
  6487. (match-beginning 2) (match-end 2)
  6488. (list 'face (delq nil (let ((prop (get-text-property
  6489. (match-beginning 2) 'face)))
  6490. (or (listp prop) (setq prop (list prop)))
  6491. (if (memq 'org-tag prop)
  6492. prop
  6493. (cons 'org-tag prop))))))
  6494. (setq l (- (match-end 2) (match-beginning 2))
  6495. c (if (< org-agenda-tags-column 0)
  6496. (- (abs org-agenda-tags-column) l)
  6497. org-agenda-tags-column))
  6498. (delete-region (match-beginning 1) (match-end 1))
  6499. (goto-char (match-beginning 1))
  6500. (insert (org-add-props
  6501. (make-string (max 1 (- c (current-column))) ?\ )
  6502. (plist-put (copy-sequence (text-properties-at (point)))
  6503. 'face nil))))
  6504. (goto-char (point-min))
  6505. (org-font-lock-add-tag-faces (point-max)))))
  6506. (defun org-agenda-priority-up ()
  6507. "Increase the priority of line at point, also in Org-mode file."
  6508. (interactive)
  6509. (org-agenda-priority 'up))
  6510. (defun org-agenda-priority-down ()
  6511. "Decrease the priority of line at point, also in Org-mode file."
  6512. (interactive)
  6513. (org-agenda-priority 'down))
  6514. (defun org-agenda-priority (&optional force-direction)
  6515. "Set the priority of line at point, also in Org-mode file.
  6516. This changes the line at point, all other lines in the agenda referring to
  6517. the same tree node, and the headline of the tree node in the Org-mode file."
  6518. (interactive)
  6519. (unless org-enable-priority-commands
  6520. (error "Priority commands are disabled"))
  6521. (org-agenda-check-no-diary)
  6522. (let* ((marker (or (org-get-at-bol 'org-marker)
  6523. (org-agenda-error)))
  6524. (hdmarker (org-get-at-bol 'org-hd-marker))
  6525. (buffer (marker-buffer hdmarker))
  6526. (pos (marker-position hdmarker))
  6527. (inhibit-read-only t)
  6528. newhead)
  6529. (org-with-remote-undo buffer
  6530. (with-current-buffer buffer
  6531. (widen)
  6532. (goto-char pos)
  6533. (org-show-context 'agenda)
  6534. (save-excursion
  6535. (and (outline-next-heading)
  6536. (org-flag-heading nil))) ; show the next heading
  6537. (funcall 'org-priority force-direction)
  6538. (end-of-line 1)
  6539. (setq newhead (org-get-heading)))
  6540. (org-agenda-change-all-lines newhead hdmarker)
  6541. (beginning-of-line 1))))
  6542. ;; FIXME: should fix the tags property of the agenda line.
  6543. (defun org-agenda-set-tags (&optional tag onoff)
  6544. "Set tags for the current headline."
  6545. (interactive)
  6546. (org-agenda-check-no-diary)
  6547. (if (and (org-region-active-p) (interactive-p))
  6548. (call-interactively 'org-change-tag-in-region)
  6549. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6550. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6551. (org-agenda-error)))
  6552. (buffer (marker-buffer hdmarker))
  6553. (pos (marker-position hdmarker))
  6554. (inhibit-read-only t)
  6555. newhead)
  6556. (org-with-remote-undo buffer
  6557. (with-current-buffer buffer
  6558. (widen)
  6559. (goto-char pos)
  6560. (save-excursion
  6561. (org-show-context 'agenda))
  6562. (save-excursion
  6563. (and (outline-next-heading)
  6564. (org-flag-heading nil))) ; show the next heading
  6565. (goto-char pos)
  6566. (if tag
  6567. (org-toggle-tag tag onoff)
  6568. (call-interactively 'org-set-tags))
  6569. (end-of-line 1)
  6570. (setq newhead (org-get-heading)))
  6571. (org-agenda-change-all-lines newhead hdmarker)
  6572. (beginning-of-line 1)))))
  6573. (defun org-agenda-set-property ()
  6574. "Set a property for the current headline."
  6575. (interactive)
  6576. (org-agenda-check-no-diary)
  6577. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6578. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6579. (org-agenda-error)))
  6580. (buffer (marker-buffer hdmarker))
  6581. (pos (marker-position hdmarker))
  6582. (inhibit-read-only t)
  6583. newhead)
  6584. (org-with-remote-undo buffer
  6585. (with-current-buffer buffer
  6586. (widen)
  6587. (goto-char pos)
  6588. (save-excursion
  6589. (org-show-context 'agenda))
  6590. (save-excursion
  6591. (and (outline-next-heading)
  6592. (org-flag-heading nil))) ; show the next heading
  6593. (goto-char pos)
  6594. (call-interactively 'org-set-property)))))
  6595. (defun org-agenda-set-effort ()
  6596. "Set the effort property for the current headline."
  6597. (interactive)
  6598. (org-agenda-check-no-diary)
  6599. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6600. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6601. (org-agenda-error)))
  6602. (buffer (marker-buffer hdmarker))
  6603. (pos (marker-position hdmarker))
  6604. (inhibit-read-only t)
  6605. newhead)
  6606. (org-with-remote-undo buffer
  6607. (with-current-buffer buffer
  6608. (widen)
  6609. (goto-char pos)
  6610. (save-excursion
  6611. (org-show-context 'agenda))
  6612. (save-excursion
  6613. (and (outline-next-heading)
  6614. (org-flag-heading nil))) ; show the next heading
  6615. (goto-char pos)
  6616. (call-interactively 'org-set-effort)
  6617. (end-of-line 1)))))
  6618. (defun org-agenda-toggle-archive-tag ()
  6619. "Toggle the archive tag for the current entry."
  6620. (interactive)
  6621. (org-agenda-check-no-diary)
  6622. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6623. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6624. (org-agenda-error)))
  6625. (buffer (marker-buffer hdmarker))
  6626. (pos (marker-position hdmarker))
  6627. (inhibit-read-only t)
  6628. newhead)
  6629. (org-with-remote-undo buffer
  6630. (with-current-buffer buffer
  6631. (widen)
  6632. (goto-char pos)
  6633. (org-show-context 'agenda)
  6634. (save-excursion
  6635. (and (outline-next-heading)
  6636. (org-flag-heading nil))) ; show the next heading
  6637. (call-interactively 'org-toggle-archive-tag)
  6638. (end-of-line 1)
  6639. (setq newhead (org-get-heading)))
  6640. (org-agenda-change-all-lines newhead hdmarker)
  6641. (beginning-of-line 1))))
  6642. (defun org-agenda-do-date-later (arg)
  6643. (interactive "P")
  6644. (cond
  6645. ((or (equal arg '(16))
  6646. (memq last-command
  6647. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6648. (setq this-command 'org-agenda-date-later-minutes)
  6649. (org-agenda-date-later-minutes 1))
  6650. ((or (equal arg '(4))
  6651. (memq last-command
  6652. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6653. (setq this-command 'org-agenda-date-later-hours)
  6654. (org-agenda-date-later-hours 1))
  6655. (t
  6656. (org-agenda-date-later (prefix-numeric-value arg)))))
  6657. (defun org-agenda-do-date-earlier (arg)
  6658. (interactive "P")
  6659. (cond
  6660. ((or (equal arg '(16))
  6661. (memq last-command
  6662. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6663. (setq this-command 'org-agenda-date-earlier-minutes)
  6664. (org-agenda-date-earlier-minutes 1))
  6665. ((or (equal arg '(4))
  6666. (memq last-command
  6667. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6668. (setq this-command 'org-agenda-date-earlier-hours)
  6669. (org-agenda-date-earlier-hours 1))
  6670. (t
  6671. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6672. (defun org-agenda-date-later (arg &optional what)
  6673. "Change the date of this item to one day later."
  6674. (interactive "p")
  6675. (org-agenda-check-type t 'agenda 'timeline)
  6676. (org-agenda-check-no-diary)
  6677. (let* ((marker (or (org-get-at-bol 'org-marker)
  6678. (org-agenda-error)))
  6679. (buffer (marker-buffer marker))
  6680. (pos (marker-position marker)))
  6681. (org-with-remote-undo buffer
  6682. (with-current-buffer buffer
  6683. (widen)
  6684. (goto-char pos)
  6685. (if (not (org-at-timestamp-p))
  6686. (error "Cannot find time stamp"))
  6687. (org-timestamp-change arg (or what 'day)))
  6688. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6689. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6690. (defun org-agenda-date-earlier (arg &optional what)
  6691. "Change the date of this item to one day earlier."
  6692. (interactive "p")
  6693. (org-agenda-date-later (- arg) what))
  6694. (defun org-agenda-date-later-minutes (arg)
  6695. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6696. (interactive "p")
  6697. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6698. (org-agenda-date-later arg 'minute))
  6699. (defun org-agenda-date-earlier-minutes (arg)
  6700. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6701. (interactive "p")
  6702. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6703. (org-agenda-date-earlier arg 'minute))
  6704. (defun org-agenda-date-later-hours (arg)
  6705. "Change the time of this item, in hour steps."
  6706. (interactive "p")
  6707. (org-agenda-date-later arg 'hour))
  6708. (defun org-agenda-date-earlier-hours (arg)
  6709. "Change the time of this item, in hour steps."
  6710. (interactive "p")
  6711. (org-agenda-date-earlier arg 'hour))
  6712. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6713. "Show new date stamp via text properties."
  6714. ;; We use text properties to make this undoable
  6715. (let ((inhibit-read-only t)
  6716. (buffer-invisibility-spec))
  6717. (setq stamp (concat " " prefix " => " stamp))
  6718. (save-excursion
  6719. (goto-char (point-max))
  6720. (while (not (bobp))
  6721. (when (equal marker (org-get-at-bol 'org-marker))
  6722. (org-move-to-column (- (window-width) (length stamp)) t)
  6723. (org-agenda-fix-tags-filter-overlays-at (point))
  6724. (if (featurep 'xemacs)
  6725. ;; Use `duplicable' property to trigger undo recording
  6726. (let ((ex (make-extent nil nil))
  6727. (gl (make-glyph stamp)))
  6728. (set-glyph-face gl 'secondary-selection)
  6729. (set-extent-properties
  6730. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6731. (insert-extent ex (1- (point)) (point-at-eol)))
  6732. (add-text-properties
  6733. (1- (point)) (point-at-eol)
  6734. (list 'display (org-add-props stamp nil
  6735. 'face 'secondary-selection))))
  6736. (beginning-of-line 1))
  6737. (beginning-of-line 0)))))
  6738. (defun org-agenda-date-prompt (arg)
  6739. "Change the date of this item. Date is prompted for, with default today.
  6740. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6741. be used to request time specification in the time stamp."
  6742. (interactive "P")
  6743. (org-agenda-check-type t 'agenda 'timeline)
  6744. (org-agenda-check-no-diary)
  6745. (let* ((marker (or (org-get-at-bol 'org-marker)
  6746. (org-agenda-error)))
  6747. (buffer (marker-buffer marker))
  6748. (pos (marker-position marker)))
  6749. (org-with-remote-undo buffer
  6750. (with-current-buffer buffer
  6751. (widen)
  6752. (goto-char pos)
  6753. (if (not (org-at-timestamp-p t))
  6754. (error "Cannot find time stamp"))
  6755. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6756. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6757. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6758. (defun org-agenda-schedule (arg &optional time)
  6759. "Schedule the item at point.
  6760. Arg is passed through to `org-schedule'."
  6761. (interactive "P")
  6762. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6763. (org-agenda-check-no-diary)
  6764. (let* ((marker (or (org-get-at-bol 'org-marker)
  6765. (org-agenda-error)))
  6766. (type (marker-insertion-type marker))
  6767. (buffer (marker-buffer marker))
  6768. (pos (marker-position marker))
  6769. (org-insert-labeled-timestamps-at-point nil)
  6770. ts)
  6771. (set-marker-insertion-type marker t)
  6772. (org-with-remote-undo buffer
  6773. (with-current-buffer buffer
  6774. (widen)
  6775. (goto-char pos)
  6776. (setq ts (org-schedule arg time)))
  6777. (org-agenda-show-new-time marker ts "S"))
  6778. (message "Item scheduled for %s" ts)))
  6779. (defun org-agenda-deadline (arg &optional time)
  6780. "Schedule the item at point.
  6781. Arg is passed through to `org-deadline'."
  6782. (interactive "P")
  6783. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6784. (org-agenda-check-no-diary)
  6785. (let* ((marker (or (org-get-at-bol 'org-marker)
  6786. (org-agenda-error)))
  6787. (buffer (marker-buffer marker))
  6788. (pos (marker-position marker))
  6789. (org-insert-labeled-timestamps-at-point nil)
  6790. ts)
  6791. (org-with-remote-undo buffer
  6792. (with-current-buffer buffer
  6793. (widen)
  6794. (goto-char pos)
  6795. (setq ts (org-deadline arg time)))
  6796. (org-agenda-show-new-time marker ts "D"))
  6797. (message "Deadline for this item set to %s" ts)))
  6798. (defun org-agenda-action ()
  6799. "Select entry for agenda action, or execute an agenda action.
  6800. This command prompts for another letter. Valid inputs are:
  6801. m Mark the entry at point for an agenda action
  6802. s Schedule the marked entry to the date at the cursor
  6803. d Set the deadline of the marked entry to the date at the cursor
  6804. r Call `org-remember' with cursor date as the default date
  6805. c Call `org-capture' with cursor date as the default date
  6806. SPC Show marked entry in other window
  6807. TAB Visit marked entry in other window
  6808. The cursor may be at a date in the calendar, or in the Org agenda."
  6809. (interactive)
  6810. (let (ans)
  6811. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6812. (setq ans (read-char-exclusive))
  6813. (cond
  6814. ((equal ans ?m)
  6815. ;; Mark this entry
  6816. (if (eq major-mode 'org-agenda-mode)
  6817. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6818. (org-get-at-bol 'org-marker))))
  6819. (if m
  6820. (progn
  6821. (move-marker org-agenda-action-marker
  6822. (marker-position m) (marker-buffer m))
  6823. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6824. (error "Don't know which entry to mark")))
  6825. (error "This command works only in the agenda")))
  6826. ((equal ans ?s)
  6827. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6828. ((equal ans ?d)
  6829. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6830. ((equal ans ?r)
  6831. (org-agenda-do-action '(org-remember) t))
  6832. ((equal ans ?c)
  6833. (org-agenda-do-action '(org-capture) t))
  6834. ((equal ans ?\ )
  6835. (let ((cw (selected-window)))
  6836. (org-switch-to-buffer-other-window
  6837. (marker-buffer org-agenda-action-marker))
  6838. (goto-char org-agenda-action-marker)
  6839. (org-show-context 'agenda)
  6840. (select-window cw)))
  6841. ((equal ans ?\C-i)
  6842. (org-switch-to-buffer-other-window
  6843. (marker-buffer org-agenda-action-marker))
  6844. (goto-char org-agenda-action-marker)
  6845. (org-show-context 'agenda))
  6846. (t (error "Invalid agenda action %c" ans)))))
  6847. (defun org-agenda-do-action (form &optional current-buffer)
  6848. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6849. (let ((org-overriding-default-time (org-get-cursor-date)))
  6850. (if current-buffer
  6851. (eval form)
  6852. (if (not (marker-buffer org-agenda-action-marker))
  6853. (error "No entry has been selected for agenda action")
  6854. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6855. (save-excursion
  6856. (save-restriction
  6857. (widen)
  6858. (goto-char org-agenda-action-marker)
  6859. (eval form))))))))
  6860. (defun org-agenda-clock-in (&optional arg)
  6861. "Start the clock on the currently selected item."
  6862. (interactive "P")
  6863. (org-agenda-check-no-diary)
  6864. (if (equal arg '(4))
  6865. (org-clock-in arg)
  6866. (let* ((marker (or (org-get-at-bol 'org-marker)
  6867. (org-agenda-error)))
  6868. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6869. marker))
  6870. (pos (marker-position marker))
  6871. newhead)
  6872. (org-with-remote-undo (marker-buffer marker)
  6873. (with-current-buffer (marker-buffer marker)
  6874. (widen)
  6875. (goto-char pos)
  6876. (org-show-context 'agenda)
  6877. (org-show-entry)
  6878. (org-cycle-hide-drawers 'children)
  6879. (org-clock-in arg)
  6880. (setq newhead (org-get-heading)))
  6881. (org-agenda-change-all-lines newhead hdmarker)))))
  6882. (defun org-agenda-clock-out ()
  6883. "Stop the currently running clock."
  6884. (interactive)
  6885. (unless (marker-buffer org-clock-marker)
  6886. (error "No running clock"))
  6887. (let ((marker (make-marker)) newhead)
  6888. (org-with-remote-undo (marker-buffer org-clock-marker)
  6889. (with-current-buffer (marker-buffer org-clock-marker)
  6890. (save-excursion
  6891. (save-restriction
  6892. (widen)
  6893. (goto-char org-clock-marker)
  6894. (org-back-to-heading t)
  6895. (move-marker marker (point))
  6896. (org-clock-out)
  6897. (setq newhead (org-get-heading))))))
  6898. (org-agenda-change-all-lines newhead marker)
  6899. (move-marker marker nil)))
  6900. (defun org-agenda-clock-cancel (&optional arg)
  6901. "Cancel the currently running clock."
  6902. (interactive "P")
  6903. (unless (marker-buffer org-clock-marker)
  6904. (error "No running clock"))
  6905. (org-with-remote-undo (marker-buffer org-clock-marker)
  6906. (org-clock-cancel)))
  6907. (defun org-agenda-clock-goto ()
  6908. "Jump to the currently clocked in task within the agenda.
  6909. If the currently clocked in task is not listed in the agenda
  6910. buffer, display it in another window."
  6911. (interactive)
  6912. (let (pos)
  6913. (mapc (lambda (o)
  6914. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6915. (setq pos (overlay-start o))))
  6916. (overlays-in (point-min) (point-max)))
  6917. (cond (pos (goto-char pos))
  6918. ;; If the currently clocked entry is not in the agenda
  6919. ;; buffer, we visit it in another window:
  6920. (org-clock-current-task
  6921. (org-switch-to-buffer-other-window (org-clock-goto)))
  6922. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6923. (defun org-agenda-diary-entry-in-org-file ()
  6924. "Make a diary entry in the file `org-agenda-diary-file'."
  6925. (let (d1 d2 char (text "") dp1 dp2)
  6926. (if (equal (buffer-name) "*Calendar*")
  6927. (setq d1 (calendar-cursor-to-date t)
  6928. d2 (car calendar-mark-ring))
  6929. (setq dp1 (get-text-property (point-at-bol) 'day))
  6930. (unless dp1 (error "No date defined in current line"))
  6931. (setq d1 (calendar-gregorian-from-absolute dp1)
  6932. d2 (and (ignore-errors (mark))
  6933. (save-excursion
  6934. (goto-char (mark))
  6935. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6936. (calendar-gregorian-from-absolute dp2))))
  6937. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6938. (setq char (read-char-exclusive))
  6939. (cond
  6940. ((equal char ?d)
  6941. (setq text (read-string "Day entry: "))
  6942. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6943. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6944. ((equal char ?a)
  6945. (setq d1 (list (car d1) (nth 1 d1)
  6946. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6947. (nth 2 d1))))
  6948. (setq text (read-string "Anniversary (use %d to show years): "))
  6949. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6950. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6951. ((equal char ?b)
  6952. (setq text (read-string "Block entry: "))
  6953. (unless (and d1 d2 (not (equal d1 d2)))
  6954. (error "No block of days selected"))
  6955. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6956. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6957. ((equal char ?j)
  6958. (org-switch-to-buffer-other-window
  6959. (find-file-noselect org-agenda-diary-file))
  6960. (require 'org-datetree)
  6961. (org-datetree-find-date-create d1)
  6962. (org-reveal t))
  6963. (t (error "Invalid selection character `%c'" char)))))
  6964. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6965. "Where in `org-agenda-diary-file' should new entries be added?
  6966. Valid values:
  6967. date-tree in the date tree, as child of the date
  6968. top-level as top-level entries at the end of the file."
  6969. :group 'org-agenda
  6970. :type '(choice
  6971. (const :tag "in a date tree" date-tree)
  6972. (const :tag "as top level at end of file" top-level)))
  6973. (defcustom org-agenda-insert-diary-extract-time nil
  6974. "Non-nil means extract any time specification from the diary entry."
  6975. :group 'org-agenda
  6976. :type 'boolean)
  6977. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6978. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6979. If TEXT is not empty, it will become the headline of the new entry, and
  6980. the resulting entry will not be shown. When TEXT is empty, switch to
  6981. `org-agenda-diary-file' and let the user finish the entry there."
  6982. (let ((cw (current-window-configuration)))
  6983. (org-switch-to-buffer-other-window
  6984. (find-file-noselect org-agenda-diary-file))
  6985. (widen)
  6986. (goto-char (point-min))
  6987. (cond
  6988. ((eq type 'anniversary)
  6989. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6990. (progn
  6991. (or (org-on-heading-p t)
  6992. (progn
  6993. (outline-next-heading)
  6994. (insert "* Anniversaries\n\n")
  6995. (beginning-of-line -1)))))
  6996. (outline-next-heading)
  6997. (org-back-over-empty-lines)
  6998. (backward-char 1)
  6999. (insert "\n")
  7000. (require 'diary-lib)
  7001. (let ((calendar-date-display-form
  7002. (if (if (boundp 'calendar-date-style)
  7003. (eq calendar-date-style 'european)
  7004. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  7005. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  7006. '(day " " month " " year)
  7007. '(month " " day " " year))))
  7008. (insert (format "%%%%(diary-anniversary %s) %s"
  7009. (calendar-date-string d1 nil t) text))))
  7010. ((eq type 'day)
  7011. (let ((org-prefix-has-time t)
  7012. (org-agenda-time-leading-zero t)
  7013. fmt time time2)
  7014. (if org-agenda-insert-diary-extract-time
  7015. ;; Use org-format-agenda-item to parse text for a time-range and
  7016. ;; remove it. FIXME: This is a hack, we should refactor
  7017. ;; that function to make time extraction available separately
  7018. (setq fmt (org-format-agenda-item nil text nil nil t)
  7019. time (get-text-property 0 'time fmt)
  7020. time2 (if (> (length time) 0)
  7021. ;; split-string removes trailing ...... if
  7022. ;; no end time given. First space
  7023. ;; separates time from date.
  7024. (concat " " (car (split-string time "\\.")))
  7025. nil)
  7026. text (get-text-property 0 'txt fmt)))
  7027. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7028. (org-agenda-insert-diary-as-top-level text)
  7029. (require 'org-datetree)
  7030. (org-datetree-find-date-create d1)
  7031. (org-agenda-insert-diary-make-new-entry text))
  7032. (org-insert-time-stamp (org-time-from-absolute
  7033. (calendar-absolute-from-gregorian d1))
  7034. nil nil nil nil time2))
  7035. (end-of-line 0))
  7036. ((eq type 'block)
  7037. (if (> (calendar-absolute-from-gregorian d1)
  7038. (calendar-absolute-from-gregorian d2))
  7039. (setq d1 (prog1 d2 (setq d2 d1))))
  7040. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7041. (org-agenda-insert-diary-as-top-level text)
  7042. (require 'org-datetree)
  7043. (org-datetree-find-date-create d1)
  7044. (org-agenda-insert-diary-make-new-entry text))
  7045. (org-insert-time-stamp (org-time-from-absolute
  7046. (calendar-absolute-from-gregorian d1)))
  7047. (insert "--")
  7048. (org-insert-time-stamp (org-time-from-absolute
  7049. (calendar-absolute-from-gregorian d2)))
  7050. (end-of-line 0)))
  7051. (if (string-match "\\S-" text)
  7052. (progn
  7053. (set-window-configuration cw)
  7054. (message "%s entry added to %s"
  7055. (capitalize (symbol-name type))
  7056. (abbreviate-file-name org-agenda-diary-file)))
  7057. (org-reveal t)
  7058. (message "Please finish entry here"))))
  7059. (defun org-agenda-insert-diary-as-top-level (text)
  7060. "Make new entry as a top-level entry at the end of the file.
  7061. Add TEXT as headline, and position the cursor in the second line so that
  7062. a timestamp can be added there."
  7063. (widen)
  7064. (goto-char (point-max))
  7065. (or (bolp) (insert "\n"))
  7066. (insert "* " text "\n")
  7067. (if org-adapt-indentation (org-indent-to-column 2)))
  7068. (defun org-agenda-insert-diary-make-new-entry (text)
  7069. "Make new entry as last child of current entry.
  7070. Add TEXT as headline, and position the cursor in the second line so that
  7071. a timestamp can be added there."
  7072. (let ((org-show-following-heading t)
  7073. (org-show-siblings t)
  7074. (org-show-hierarchy-above t)
  7075. (org-show-entry-below t)
  7076. col)
  7077. (outline-next-heading)
  7078. (org-back-over-empty-lines)
  7079. (or (looking-at "[ \t]*$")
  7080. (progn (insert "\n") (backward-char 1)))
  7081. (org-insert-heading nil t)
  7082. (org-do-demote)
  7083. (setq col (current-column))
  7084. (insert text "\n")
  7085. (if org-adapt-indentation (org-indent-to-column col))
  7086. (let ((org-show-following-heading t)
  7087. (org-show-siblings t)
  7088. (org-show-hierarchy-above t)
  7089. (org-show-entry-below t))
  7090. (org-show-context))))
  7091. (defun org-agenda-diary-entry ()
  7092. "Make a diary entry, like the `i' command from the calendar.
  7093. All the standard commands work: block, weekly etc.
  7094. When `org-agenda-diary-file' points to a file,
  7095. `org-agenda-diary-entry-in-org-file' is called instead to create
  7096. entries in that Org-mode file."
  7097. (interactive)
  7098. (org-agenda-check-type t 'agenda 'timeline)
  7099. (if (not (eq org-agenda-diary-file 'diary-file))
  7100. (org-agenda-diary-entry-in-org-file)
  7101. (require 'diary-lib)
  7102. (let* ((char (progn
  7103. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7104. (read-char-exclusive)))
  7105. (cmd (cdr (assoc char
  7106. '((?d . insert-diary-entry)
  7107. (?w . insert-weekly-diary-entry)
  7108. (?m . insert-monthly-diary-entry)
  7109. (?y . insert-yearly-diary-entry)
  7110. (?a . insert-anniversary-diary-entry)
  7111. (?b . insert-block-diary-entry)
  7112. (?c . insert-cyclic-diary-entry)))))
  7113. (oldf (symbol-function 'calendar-cursor-to-date))
  7114. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7115. (point (point))
  7116. (mark (or (mark t) (point))))
  7117. (unless cmd
  7118. (error "No command associated with <%c>" char))
  7119. (unless (and (get-text-property point 'day)
  7120. (or (not (equal ?b char))
  7121. (get-text-property mark 'day)))
  7122. (error "Don't know which date to use for diary entry"))
  7123. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7124. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7125. (let ((calendar-mark-ring
  7126. (list (calendar-gregorian-from-absolute
  7127. (or (get-text-property mark 'day)
  7128. (get-text-property point 'day))))))
  7129. (unwind-protect
  7130. (progn
  7131. (fset 'calendar-cursor-to-date
  7132. (lambda (&optional error dummy)
  7133. (calendar-gregorian-from-absolute
  7134. (get-text-property point 'day))))
  7135. (call-interactively cmd))
  7136. (fset 'calendar-cursor-to-date oldf))))))
  7137. (defun org-agenda-execute-calendar-command (cmd)
  7138. "Execute a calendar command from the agenda, with the date associated to
  7139. the cursor position."
  7140. (org-agenda-check-type t 'agenda 'timeline)
  7141. (require 'diary-lib)
  7142. (unless (get-text-property (point) 'day)
  7143. (error "Don't know which date to use for calendar command"))
  7144. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7145. (point (point))
  7146. (date (calendar-gregorian-from-absolute
  7147. (get-text-property point 'day)))
  7148. ;; the following 2 vars are needed in the calendar
  7149. (displayed-month (car date))
  7150. (displayed-year (nth 2 date)))
  7151. (unwind-protect
  7152. (progn
  7153. (fset 'calendar-cursor-to-date
  7154. (lambda (&optional error dummy)
  7155. (calendar-gregorian-from-absolute
  7156. (get-text-property point 'day))))
  7157. (call-interactively cmd))
  7158. (fset 'calendar-cursor-to-date oldf))))
  7159. (defun org-agenda-phases-of-moon ()
  7160. "Display the phases of the moon for the 3 months around the cursor date."
  7161. (interactive)
  7162. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7163. (defun org-agenda-holidays ()
  7164. "Display the holidays for the 3 months around the cursor date."
  7165. (interactive)
  7166. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7167. (defvar calendar-longitude)
  7168. (defvar calendar-latitude)
  7169. (defvar calendar-location-name)
  7170. (defun org-agenda-sunrise-sunset (arg)
  7171. "Display sunrise and sunset for the cursor date.
  7172. Latitude and longitude can be specified with the variables
  7173. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7174. argument, latitude and longitude will be prompted for."
  7175. (interactive "P")
  7176. (require 'solar)
  7177. (let ((calendar-longitude (if arg nil calendar-longitude))
  7178. (calendar-latitude (if arg nil calendar-latitude))
  7179. (calendar-location-name
  7180. (if arg "the given coordinates" calendar-location-name)))
  7181. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7182. (defun org-agenda-goto-calendar ()
  7183. "Open the Emacs calendar with the date at the cursor."
  7184. (interactive)
  7185. (org-agenda-check-type t 'agenda 'timeline)
  7186. (let* ((day (or (get-text-property (point) 'day)
  7187. (error "Don't know which date to open in calendar")))
  7188. (date (calendar-gregorian-from-absolute day))
  7189. (calendar-move-hook nil)
  7190. (calendar-view-holidays-initially-flag nil)
  7191. (calendar-view-diary-initially-flag nil))
  7192. (calendar)
  7193. (calendar-goto-date date)))
  7194. ;;;###autoload
  7195. (defun org-calendar-goto-agenda ()
  7196. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7197. This is a command that has to be installed in `calendar-mode-map'."
  7198. (interactive)
  7199. (org-agenda-list nil (calendar-absolute-from-gregorian
  7200. (calendar-cursor-to-date))
  7201. nil))
  7202. (defun org-agenda-convert-date ()
  7203. (interactive)
  7204. (org-agenda-check-type t 'agenda 'timeline)
  7205. (let ((day (get-text-property (point) 'day))
  7206. date s)
  7207. (unless day
  7208. (error "Don't know which date to convert"))
  7209. (setq date (calendar-gregorian-from-absolute day))
  7210. (setq s (concat
  7211. "Gregorian: " (calendar-date-string date) "\n"
  7212. "ISO: " (calendar-iso-date-string date) "\n"
  7213. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7214. "Julian: " (calendar-julian-date-string date) "\n"
  7215. "Astron. JD: " (calendar-astro-date-string date)
  7216. " (Julian date number at noon UTC)\n"
  7217. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7218. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7219. "French: " (calendar-french-date-string date) "\n"
  7220. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7221. "Mayan: " (calendar-mayan-date-string date) "\n"
  7222. "Coptic: " (calendar-coptic-date-string date) "\n"
  7223. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7224. "Persian: " (calendar-persian-date-string date) "\n"
  7225. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7226. (with-output-to-temp-buffer "*Dates*"
  7227. (princ s))
  7228. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7229. ;;; Bulk commands
  7230. (defvar org-agenda-bulk-marked-entries nil
  7231. "List of markers that refer to marked entries in the agenda.")
  7232. (defun org-agenda-bulk-marked-p ()
  7233. (eq (get-char-property (point-at-bol) 'type)
  7234. 'org-marked-entry-overlay))
  7235. (defun org-agenda-bulk-mark (&optional arg)
  7236. "Mark the entry at point for future bulk action."
  7237. (interactive "p")
  7238. (dotimes (i (max arg 1))
  7239. (unless (org-get-at-bol 'org-agenda-diary-link)
  7240. (let* ((m (org-get-at-bol 'org-hd-marker))
  7241. ov)
  7242. (unless (org-agenda-bulk-marked-p)
  7243. (unless m (error "Nothing to mark at point"))
  7244. (push m org-agenda-bulk-marked-entries)
  7245. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7246. (org-overlay-display ov "> "
  7247. (org-get-todo-face "TODO")
  7248. 'evaporate)
  7249. (overlay-put ov 'type 'org-marked-entry-overlay))
  7250. (beginning-of-line 2)
  7251. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7252. (beginning-of-line 2))
  7253. (message "%d entries marked for bulk action"
  7254. (length org-agenda-bulk-marked-entries))))))
  7255. (defun org-agenda-bulk-unmark ()
  7256. "Unmark the entry at point for future bulk action."
  7257. (interactive)
  7258. (when (org-agenda-bulk-marked-p)
  7259. (org-agenda-bulk-remove-overlays
  7260. (point-at-bol) (+ 2 (point-at-bol)))
  7261. (setq org-agenda-bulk-marked-entries
  7262. (delete (org-get-at-bol 'org-hd-marker)
  7263. org-agenda-bulk-marked-entries)))
  7264. (beginning-of-line 2)
  7265. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7266. (beginning-of-line 2))
  7267. (message "%d entries marked for bulk action"
  7268. (length org-agenda-bulk-marked-entries)))
  7269. (defun org-agenda-bulk-toggle ()
  7270. "Toggle marking the entry at point for bulk action."
  7271. (interactive)
  7272. (if (org-agenda-bulk-marked-p)
  7273. (org-agenda-bulk-unmark)
  7274. (org-agenda-bulk-mark)))
  7275. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7276. "Remove the mark overlays between BEG and END in the agenda buffer.
  7277. BEG and END default to the buffer limits.
  7278. This only removes the overlays, it does not remove the markers
  7279. from the list in `org-agenda-bulk-marked-entries'."
  7280. (interactive)
  7281. (mapc (lambda (ov)
  7282. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7283. (delete-overlay ov)))
  7284. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7285. (defun org-agenda-bulk-remove-all-marks ()
  7286. "Remove all marks in the agenda buffer.
  7287. This will remove the markers, and the overlays."
  7288. (interactive)
  7289. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7290. (setq org-agenda-bulk-marked-entries nil)
  7291. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7292. (defun org-agenda-bulk-action (&optional arg)
  7293. "Execute an remote-editing action on all marked entries.
  7294. The prefix arg is passed through to the command if possible."
  7295. (interactive "P")
  7296. (unless org-agenda-bulk-marked-entries
  7297. (error "No entries are marked"))
  7298. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
  7299. (let* ((action (read-char-exclusive))
  7300. (org-log-refile (if org-log-refile 'time nil))
  7301. (entries (reverse org-agenda-bulk-marked-entries))
  7302. redo-at-end
  7303. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7304. (cond
  7305. ((equal action ?$)
  7306. (setq cmd '(org-agenda-archive)))
  7307. ((equal action ?A)
  7308. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7309. ((member action '(?r ?w))
  7310. (setq rfloc (org-refile-get-location
  7311. "Refile to: "
  7312. (marker-buffer (car org-agenda-bulk-marked-entries))
  7313. org-refile-allow-creating-parent-nodes))
  7314. (if (nth 3 rfloc)
  7315. (setcar (nthcdr 3 rfloc)
  7316. (move-marker (make-marker) (nth 3 rfloc)
  7317. (or (get-file-buffer (nth 1 rfloc))
  7318. (find-buffer-visiting (nth 1 rfloc))
  7319. (error "This should not happen")))))
  7320. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7321. redo-at-end t))
  7322. ((equal action ?t)
  7323. (setq state (org-icompleting-read
  7324. "Todo state: "
  7325. (with-current-buffer (marker-buffer (car entries))
  7326. (mapcar 'list org-todo-keywords-1))))
  7327. (setq cmd `(let ((org-inhibit-blocking t)
  7328. (org-inhibit-logging 'note))
  7329. (org-agenda-todo ,state))))
  7330. ((memq action '(?- ?+))
  7331. (setq tag (org-icompleting-read
  7332. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7333. (with-current-buffer (marker-buffer (car entries))
  7334. (delq nil
  7335. (mapcar (lambda (x)
  7336. (if (stringp (car x)) x)) org-tag-alist)))))
  7337. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7338. ((memq action '(?s ?d))
  7339. (let* ((date (unless arg
  7340. (org-read-date
  7341. nil nil nil
  7342. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7343. (ans (if arg nil org-read-date-final-answer))
  7344. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7345. (setq cmd `(let* ((bound (fboundp 'read-string))
  7346. (old (and bound (symbol-function 'read-string))))
  7347. (unwind-protect
  7348. (progn
  7349. (fset 'read-string (lambda (&rest ignore) ,ans))
  7350. (eval '(,c1 arg)))
  7351. (if bound
  7352. (fset 'read-string old)
  7353. (fmakunbound 'read-string)))))))
  7354. ((eq action '?S)
  7355. (let ((days (read-number
  7356. (format "Scatter tasks across how many %sdays: "
  7357. (if arg "week" "")) 7)))
  7358. (setq cmd
  7359. `(let ((distance (1+ (random ,days))))
  7360. (if arg
  7361. (let ((dist distance)
  7362. (day-of-week
  7363. (calendar-day-of-week
  7364. (calendar-gregorian-from-absolute (org-today)))))
  7365. (dotimes (i (1+ dist))
  7366. (while (member day-of-week org-agenda-weekend-days)
  7367. (incf distance)
  7368. (incf day-of-week)
  7369. (if (= day-of-week 7)
  7370. (setq day-of-week 0)))
  7371. (incf day-of-week)
  7372. (if (= day-of-week 7)
  7373. (setq day-of-week 0)))))
  7374. (org-agenda-schedule nil (current-time))
  7375. (org-agenda-date-later distance)))))
  7376. (t (error "Invalid bulk action")))
  7377. ;; Sort the markers, to make sure that parents are handled before children
  7378. (setq entries (sort entries
  7379. (lambda (a b)
  7380. (cond
  7381. ((equal (marker-buffer a) (marker-buffer b))
  7382. (< (marker-position a) (marker-position b)))
  7383. (t
  7384. (string< (buffer-name (marker-buffer a))
  7385. (buffer-name (marker-buffer b))))))))
  7386. ;; Now loop over all markers and apply cmd
  7387. (while (setq e (pop entries))
  7388. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7389. (if (not pos)
  7390. (progn (message "Skipping removed entry at %s" e)
  7391. (setq cntskip (1+ cntskip)))
  7392. (goto-char pos)
  7393. (eval cmd)
  7394. (setq org-agenda-bulk-marked-entries
  7395. (delete e org-agenda-bulk-marked-entries))
  7396. (setq cnt (1+ cnt))))
  7397. (setq org-agenda-bulk-marked-entries nil)
  7398. (org-agenda-bulk-remove-all-marks)
  7399. (when redo-at-end (org-agenda-redo))
  7400. (message "Acted on %d entries%s"
  7401. cnt
  7402. (if (= cntskip 0)
  7403. ""
  7404. (format ", skipped %d (disappeared before their turn)"
  7405. cntskip)))))
  7406. ;;; Flagging notes
  7407. (defun org-agenda-show-the-flagging-note ()
  7408. "Display the flagging note in the other window.
  7409. When called a second time in direct sequence, offer to remove the FLAGGING
  7410. tag and (if present) the flagging note."
  7411. (interactive)
  7412. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7413. (win (selected-window))
  7414. note heading newhead)
  7415. (unless hdmarker
  7416. (error "No linked entry at point"))
  7417. (if (and (eq this-command last-command)
  7418. (y-or-n-p "Unflag and remove any flagging note? "))
  7419. (progn
  7420. (org-agenda-remove-flag hdmarker)
  7421. (let ((win (get-buffer-window "*Flagging Note*")))
  7422. (and win (delete-window win)))
  7423. (message "Entry unflaged"))
  7424. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7425. (unless note
  7426. (error "No flagging note"))
  7427. (org-kill-new note)
  7428. (org-switch-to-buffer-other-window "*Flagging Note*")
  7429. (erase-buffer)
  7430. (insert note)
  7431. (goto-char (point-min))
  7432. (while (re-search-forward "\\\\n" nil t)
  7433. (replace-match "\n" t t))
  7434. (goto-char (point-min))
  7435. (select-window win)
  7436. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7437. (defun org-agenda-remove-flag (marker)
  7438. "Remove the FLAGGED tag and any flagging note in the entry."
  7439. (let (newhead)
  7440. (org-with-point-at marker
  7441. (org-toggle-tag "FLAGGED" 'off)
  7442. (org-entry-delete nil "THEFLAGGINGNOTE")
  7443. (setq newhead (org-get-heading)))
  7444. (org-agenda-change-all-lines newhead marker)
  7445. (message "Entry unflaged")))
  7446. (defun org-agenda-get-any-marker (&optional pos)
  7447. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7448. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7449. ;;; Appointment reminders
  7450. (defvar appt-time-msg-list)
  7451. ;;;###autoload
  7452. (defun org-agenda-to-appt (&optional refresh filter)
  7453. "Activate appointments found in `org-agenda-files'.
  7454. With a \\[universal-argument] prefix, refresh the list of
  7455. appointments.
  7456. If FILTER is t, interactively prompt the user for a regular
  7457. expression, and filter out entries that don't match it.
  7458. If FILTER is a string, use this string as a regular expression
  7459. for filtering entries out.
  7460. FILTER can also be an alist with the car of each cell being
  7461. either 'headline or 'category. For example:
  7462. '((headline \"IMPORTANT\")
  7463. (category \"Work\"))
  7464. will only add headlines containing IMPORTANT or headlines
  7465. belonging to the \"Work\" category."
  7466. (interactive "P")
  7467. (if refresh (setq appt-time-msg-list nil))
  7468. (if (eq filter t)
  7469. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7470. (let* ((cnt 0) ; count added events
  7471. (org-agenda-new-buffers nil)
  7472. (org-deadline-warning-days 0)
  7473. ;; Do not use `org-today' here because appt only takes
  7474. ;; time and without date as argument, so it may pass wrong
  7475. ;; information otherwise
  7476. (today (org-date-to-gregorian
  7477. (time-to-days (current-time))))
  7478. (org-agenda-restrict nil)
  7479. (files (org-agenda-files 'unrestricted)) entries file)
  7480. ;; Get all entries which may contain an appt
  7481. (org-prepare-agenda-buffers files)
  7482. (while (setq file (pop files))
  7483. (setq entries
  7484. (append entries
  7485. (org-agenda-get-day-entries
  7486. file today :timestamp :scheduled :deadline))))
  7487. (setq entries (delq nil entries))
  7488. ;; Map thru entries and find if we should filter them out
  7489. (mapc
  7490. (lambda(x)
  7491. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7492. (cat (get-text-property 1 'org-category x))
  7493. (tod (get-text-property 1 'time-of-day x))
  7494. (ok (or (null filter)
  7495. (and (stringp filter) (string-match filter evt))
  7496. (and (listp filter)
  7497. (or (string-match
  7498. (cadr (assoc 'category filter)) cat)
  7499. (string-match
  7500. (cadr (assoc 'headline filter)) evt))))))
  7501. ;; FIXME: Shall we remove text-properties for the appt text?
  7502. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7503. (when (and ok tod)
  7504. (setq tod (concat "00" (number-to-string tod))
  7505. tod (when (string-match
  7506. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7507. (concat (match-string 1 tod) ":"
  7508. (match-string 2 tod))))
  7509. (appt-add tod evt)
  7510. (setq cnt (1+ cnt))))) entries)
  7511. (org-release-buffers org-agenda-new-buffers)
  7512. (if (eq cnt 0)
  7513. (message "No event to add")
  7514. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7515. (defun org-agenda-todayp (date)
  7516. "Does DATE mean today, when considering `org-extend-today-until'?"
  7517. (let ((today (org-today))
  7518. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7519. date)))
  7520. (eq date today)))
  7521. (provide 'org-agenda)
  7522. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7523. ;;; org-agenda.el ends here