org-agenda.el 265 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  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: 6.31trans
  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. (require 'calendar))
  30. (declare-function diary-add-to-list "diary-lib"
  31. (date string specifier &optional marker globcolor literal))
  32. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  33. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  34. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  35. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  36. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  38. (declare-function calendar-french-date-string "cal-french" (&optional date))
  39. (declare-function calendar-goto-date "cal-move" (date))
  40. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  41. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  42. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  43. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  44. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  45. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  46. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  47. (declare-function org-columns-quit "org-colview" ())
  48. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  49. (defvar calendar-mode-map)
  50. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  51. ;; Defined somewhere in this file, but used before definition.
  52. (defvar org-agenda-buffer-name)
  53. (defvar org-agenda-overriding-header)
  54. (defvar org-agenda-title-append nil)
  55. (defvar entry)
  56. (defvar date)
  57. (defvar org-agenda-undo-list)
  58. (defvar org-agenda-pending-undo-list)
  59. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  60. (defcustom org-agenda-confirm-kill 1
  61. "When set, remote killing from the agenda buffer needs confirmation.
  62. When t, a confirmation is always needed. When a number N, confirmation is
  63. only needed when the text to be killed contains more than N non-white lines."
  64. :group 'org-agenda
  65. :type '(choice
  66. (const :tag "Never" nil)
  67. (const :tag "Always" t)
  68. (integer :tag "When more than N lines")))
  69. (defcustom org-agenda-compact-blocks nil
  70. "Non-nil means, make the block agenda more compact.
  71. This is done by leaving out unnecessary lines."
  72. :group 'org-agenda
  73. :type 'boolean)
  74. (defcustom org-agenda-block-separator ?=
  75. "The separator between blocks in the agenda.
  76. If this is a string, it will be used as the separator, with a newline added.
  77. If it is a character, it will be repeated to fill the window width."
  78. :group 'org-agenda
  79. :type '(choice
  80. (character)
  81. (string)))
  82. (defgroup org-agenda-export nil
  83. "Options concerning exporting agenda views in Org-mode."
  84. :tag "Org Agenda Export"
  85. :group 'org-agenda)
  86. (defcustom org-agenda-with-colors t
  87. "Non-nil means, use colors in agenda views."
  88. :group 'org-agenda-export
  89. :type 'boolean)
  90. (defcustom org-agenda-exporter-settings nil
  91. "Alist of variable/value pairs that should be active during agenda export.
  92. This is a good place to set options for ps-print and for htmlize.
  93. Note that the way this is implemented, the values will be evaluated
  94. before assigned to the variables. So make sure to quote values you do
  95. *not* want evaluated, for example
  96. (setq org-agenda-exporter-settings
  97. '((ps-print-color-p 'black-white)))"
  98. :group 'org-agenda-export
  99. :type '(repeat
  100. (list
  101. (variable)
  102. (sexp :tag "Value"))))
  103. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  104. "Hook run in temporary buffer before writing it to an export file.
  105. A useful function is `org-agenda-add-entry-text'."
  106. :group 'org-agenda-export
  107. :type 'hook
  108. :options '(org-agenda-add-entry-text))
  109. (defcustom org-agenda-add-entry-text-maxlines 0
  110. "Maximum number of entry text lines to be added to agenda.
  111. This is only relevant when `org-agenda-add-entry-text' is part of
  112. `org-agenda-before-write-hook', which it is by default.
  113. When this is 0, nothing will happen. When it is greater than 0, it
  114. specifies the maximum number of lines that will be added for each entry
  115. that is listed in the agenda view.
  116. Note that this variable is not used during display, only when exporting
  117. the agenda. For agenda display, see org-agenda-entry-text-mode and the
  118. variable `org-agenda-entry-text-maxlines'."
  119. :group 'org-agenda
  120. :type 'integer)
  121. (defcustom org-agenda-add-entry-text-descriptive-links t
  122. "Non-nil means, export org-links as descriptive links in agenda added text.
  123. This variable applies to the text added to the agenda when
  124. `org-agenda-add-entry-text-maxlines' is larger than 0.
  125. When this variable nil, the URL will (also) be shown."
  126. :group 'org-agenda
  127. :type 'boolean)
  128. (defcustom org-agenda-export-html-style ""
  129. "The style specification for exported HTML Agenda files.
  130. If this variable contains a string, it will replace the default <style>
  131. section as produced by `htmlize'.
  132. Since there are different ways of setting style information, this variable
  133. needs to contain the full HTML structure to provide a style, including the
  134. surrounding HTML tags. The style specifications should include definitions
  135. the fonts used by the agenda, here is an example:
  136. <style type=\"text/css\">
  137. p { font-weight: normal; color: gray; }
  138. .org-agenda-structure {
  139. font-size: 110%;
  140. color: #003399;
  141. font-weight: 600;
  142. }
  143. .org-todo {
  144. color: #cc6666;
  145. font-weight: bold;
  146. }
  147. .org-agenda-done {
  148. color: #339933;
  149. }
  150. .org-done {
  151. color: #339933;
  152. }
  153. .title { text-align: center; }
  154. .todo, .deadline { color: red; }
  155. .done { color: green; }
  156. </style>
  157. or, if you want to keep the style in a file,
  158. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  159. As the value of this option simply gets inserted into the HTML <head> header,
  160. you can \"misuse\" it to also add other text to the header. However,
  161. <style>...</style> is required, if not present the variable will be ignored."
  162. :group 'org-agenda-export
  163. :group 'org-export-html
  164. :type 'string)
  165. (defgroup org-agenda-custom-commands nil
  166. "Options concerning agenda views in Org-mode."
  167. :tag "Org Agenda Custom Commands"
  168. :group 'org-agenda)
  169. (defconst org-sorting-choice
  170. '(choice
  171. (const time-up) (const time-down)
  172. (const category-keep) (const category-up) (const category-down)
  173. (const tag-down) (const tag-up)
  174. (const priority-up) (const priority-down)
  175. (const todo-state-up) (const todo-state-down)
  176. (const effort-up) (const effort-down)
  177. (const user-defined-up) (const user-defined-down))
  178. "Sorting choices.")
  179. (defconst org-agenda-custom-commands-local-options
  180. `(repeat :tag "Local settings for this command. Remember to quote values"
  181. (choice :tag "Setting"
  182. (list :tag "Heading for this block"
  183. (const org-agenda-overriding-header)
  184. (string :tag "Headline"))
  185. (list :tag "Files to be searched"
  186. (const org-agenda-files)
  187. (list
  188. (const :format "" quote)
  189. (repeat (file))))
  190. (list :tag "Sorting strategy"
  191. (const org-agenda-sorting-strategy)
  192. (list
  193. (const :format "" quote)
  194. (repeat
  195. ,org-sorting-choice)))
  196. (list :tag "Prefix format"
  197. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  198. (string))
  199. (list :tag "Number of days in agenda"
  200. (const org-agenda-ndays)
  201. (integer :value 1))
  202. (list :tag "Fixed starting date"
  203. (const org-agenda-start-day)
  204. (string :value "2007-11-01"))
  205. (list :tag "Start on day of week"
  206. (const org-agenda-start-on-weekday)
  207. (choice :value 1
  208. (const :tag "Today" nil)
  209. (integer :tag "Weekday No.")))
  210. (list :tag "Include data from diary"
  211. (const org-agenda-include-diary)
  212. (boolean))
  213. (list :tag "Deadline Warning days"
  214. (const org-deadline-warning-days)
  215. (integer :value 1))
  216. (list :tag "Tags filter preset"
  217. (const org-agenda-filter-preset)
  218. (list
  219. (const :format "" quote)
  220. (repeat
  221. (string :tag "+tag or -tag"))))
  222. (list :tag "Standard skipping condition"
  223. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  224. (const org-agenda-skip-function)
  225. (list
  226. (const :format "" quote)
  227. (list
  228. (choice
  229. :tag "Skipping range"
  230. (const :tag "Skip entry" org-agenda-skip-entry-if)
  231. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  232. (repeat :inline t :tag "Conditions for skipping"
  233. (choice
  234. :tag "Condition type"
  235. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  236. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  237. (const :tag "scheduled" 'scheduled)
  238. (const :tag "not scheduled" 'notscheduled)
  239. (const :tag "deadline" 'deadline)
  240. (const :tag "no deadline" 'notdeadline)
  241. (const :tag "timestamp" 'timestamp)
  242. (const :tag "no timestamp" 'nottimestamp))))))
  243. (list :tag "Non-standard skipping condition"
  244. :value (org-agenda-skip-function)
  245. (const org-agenda-skip-function)
  246. (sexp :tag "Function or form (quoted!)"))
  247. (list :tag "Any variable"
  248. (variable :tag "Variable")
  249. (sexp :tag "Value (sexp)"))))
  250. "Selection of examples for agenda command settings.
  251. This will be spliced into the custom type of
  252. `org-agenda-custom-commands'.")
  253. (defcustom org-agenda-custom-commands nil
  254. "Custom commands for the agenda.
  255. These commands will be offered on the splash screen displayed by the
  256. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  257. (key desc type match settings files)
  258. key The key (one or more characters as a string) to be associated
  259. with the command.
  260. desc A description of the command, when omitted or nil, a default
  261. description is built using MATCH.
  262. type The command type, any of the following symbols:
  263. agenda The daily/weekly agenda.
  264. todo Entries with a specific TODO keyword, in all agenda files.
  265. search Entries containing search words entry or headline.
  266. tags Tags/Property/TODO match in all agenda files.
  267. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  268. todo-tree Sparse tree of specific TODO keyword in *current* file.
  269. tags-tree Sparse tree with all tags matches in *current* file.
  270. occur-tree Occur sparse tree for *current* file.
  271. ... A user-defined function.
  272. match What to search for:
  273. - a single keyword for TODO keyword searches
  274. - a tags match expression for tags searches
  275. - a word search expression for text searches.
  276. - a regular expression for occur searches
  277. For all other commands, this should be the empty string.
  278. settings A list of option settings, similar to that in a let form, so like
  279. this: ((opt1 val1) (opt2 val2) ...). The values will be
  280. evaluated at the moment of execution, so quote them when needed.
  281. files A list of files file to write the produced agenda buffer to
  282. with the command `org-store-agenda-views'.
  283. If a file name ends in \".html\", an HTML version of the buffer
  284. is written out. If it ends in \".ps\", a postscript version is
  285. produced. Otherwise, only the plain text is written to the file.
  286. You can also define a set of commands, to create a composite agenda buffer.
  287. In this case, an entry looks like this:
  288. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  289. where
  290. desc A description string to be displayed in the dispatcher menu.
  291. cmd An agenda command, similar to the above. However, tree commands
  292. are no allowed, but instead you can get agenda and global todo list.
  293. So valid commands for a set are:
  294. (agenda \"\" settings)
  295. (alltodo \"\" settings)
  296. (stuck \"\" settings)
  297. (todo \"match\" settings files)
  298. (search \"match\" settings files)
  299. (tags \"match\" settings files)
  300. (tags-todo \"match\" settings files)
  301. Each command can carry a list of options, and another set of options can be
  302. given for the whole set of commands. Individual command options take
  303. precedence over the general options.
  304. When using several characters as key to a command, the first characters
  305. are prefix commands. For the dispatcher to display useful information, you
  306. should provide a description for the prefix, like
  307. (setq org-agenda-custom-commands
  308. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  309. (\"hl\" tags \"+HOME+Lisa\")
  310. (\"hp\" tags \"+HOME+Peter\")
  311. (\"hk\" tags \"+HOME+Kim\")))"
  312. :group 'org-agenda-custom-commands
  313. :type `(repeat
  314. (choice :value ("x" "Describe command here" tags "" nil)
  315. (list :tag "Single command"
  316. (string :tag "Access Key(s) ")
  317. (option (string :tag "Description"))
  318. (choice
  319. (const :tag "Agenda" agenda)
  320. (const :tag "TODO list" alltodo)
  321. (const :tag "Search words" search)
  322. (const :tag "Stuck projects" stuck)
  323. (const :tag "Tags/Property match (all agenda files)" tags)
  324. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  325. (const :tag "TODO keyword search (all agenda files)" todo)
  326. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  327. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  328. (const :tag "Occur tree (current buffer)" occur-tree)
  329. (sexp :tag "Other, user-defined function"))
  330. (string :tag "Match (only for some commands)")
  331. ,org-agenda-custom-commands-local-options
  332. (option (repeat :tag "Export" (file :tag "Export to"))))
  333. (list :tag "Command series, all agenda files"
  334. (string :tag "Access Key(s)")
  335. (string :tag "Description ")
  336. (repeat :tag "Component"
  337. (choice
  338. (list :tag "Agenda"
  339. (const :format "" agenda)
  340. (const :tag "" :format "" "")
  341. ,org-agenda-custom-commands-local-options)
  342. (list :tag "TODO list (all keywords)"
  343. (const :format "" alltodo)
  344. (const :tag "" :format "" "")
  345. ,org-agenda-custom-commands-local-options)
  346. (list :tag "Search words"
  347. (const :format "" search)
  348. (string :tag "Match")
  349. ,org-agenda-custom-commands-local-options)
  350. (list :tag "Stuck projects"
  351. (const :format "" stuck)
  352. (const :tag "" :format "" "")
  353. ,org-agenda-custom-commands-local-options)
  354. (list :tag "Tags search"
  355. (const :format "" tags)
  356. (string :tag "Match")
  357. ,org-agenda-custom-commands-local-options)
  358. (list :tag "Tags search, TODO entries only"
  359. (const :format "" tags-todo)
  360. (string :tag "Match")
  361. ,org-agenda-custom-commands-local-options)
  362. (list :tag "TODO keyword search"
  363. (const :format "" todo)
  364. (string :tag "Match")
  365. ,org-agenda-custom-commands-local-options)
  366. (list :tag "Other, user-defined function"
  367. (symbol :tag "function")
  368. (string :tag "Match")
  369. ,org-agenda-custom-commands-local-options)))
  370. (repeat :tag "Settings for entire command set"
  371. (list (variable :tag "Any variable")
  372. (sexp :tag "Value")))
  373. (option (repeat :tag "Export" (file :tag "Export to"))))
  374. (cons :tag "Prefix key documentation"
  375. (string :tag "Access Key(s)")
  376. (string :tag "Description ")))))
  377. (defcustom org-agenda-query-register ?o
  378. "The register holding the current query string.
  379. The purpose of this is that if you construct a query string interactively,
  380. you can then use it to define a custom command."
  381. :group 'org-agenda-custom-commands
  382. :type 'character)
  383. (defcustom org-stuck-projects
  384. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  385. "How to identify stuck projects.
  386. This is a list of four items:
  387. 1. A tags/todo/property matcher string that is used to identify a project.
  388. See the manual for a description of tag and property searches.
  389. The entire tree below a headline matched by this is considered one project.
  390. 2. A list of TODO keywords identifying non-stuck projects.
  391. If the project subtree contains any headline with one of these todo
  392. keywords, the project is considered to be not stuck. If you specify
  393. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  394. 3. A list of tags identifying non-stuck projects.
  395. If the project subtree contains any headline with one of these tags,
  396. the project is considered to be not stuck. If you specify \"*\" as
  397. a tag, any tag will mark the project unstuck. Note that this is about
  398. the explicit presence of a tag somewhere in the subtree, inherited
  399. tags to not count here. If inherited tags make a project not stuck,
  400. use \"-TAG\" in the tags part of the matcher under (1.) above.
  401. 4. An arbitrary regular expression matching non-stuck projects.
  402. If the project turns out to be not stuck, search continues also in the
  403. subtree to see if any of the subtasks have project status.
  404. See also the variable `org-tags-match-list-sublevels' which applies
  405. to projects matched by this search as well.
  406. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  407. or `C-c a #' to produce the list."
  408. :group 'org-agenda-custom-commands
  409. :type '(list
  410. (string :tag "Tags/TODO match to identify a project")
  411. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  412. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  413. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  414. (defcustom org-agenda-filter-effort-default-operator "<"
  415. "The default operator for effort estimate filtering.
  416. If you select an effort estimate limit without first pressing an operator,
  417. this one will be used."
  418. :group 'org-agenda-custom-commands
  419. :type '(choice (const :tag "less or equal" "<")
  420. (const :tag "greater or equal"">")
  421. (const :tag "equal" "=")))
  422. (defgroup org-agenda-skip nil
  423. "Options concerning skipping parts of agenda files."
  424. :tag "Org Agenda Skip"
  425. :group 'org-agenda)
  426. (defgroup org-agenda-daily/weekly nil
  427. "Options concerning the daily/weekly agenda."
  428. :tag "Org Agenda Daily/Weekly"
  429. :group 'org-agenda)
  430. (defgroup org-agenda-todo-list nil
  431. "Options concerning the global todo list agenda view."
  432. :tag "Org Agenda Todo List"
  433. :group 'org-agenda)
  434. (defgroup org-agenda-match-view nil
  435. "Options concerning the general tags/property/todo match agenda view."
  436. :tag "Org Agenda Match View"
  437. :group 'org-agenda)
  438. (defgroup org-agenda-search-view nil
  439. "Options concerning the general tags/property/todo match agenda view."
  440. :tag "Org Agenda Match View"
  441. :group 'org-agenda)
  442. (defvar org-agenda-archives-mode nil
  443. "Non-nil means, the agenda will include archived items.
  444. If this is the symbol `trees', trees in the selected agenda scope
  445. that are marked with the ARCHIVE tag will be included anyway. When this is
  446. t, also all archive files associated with the current selection of agenda
  447. files will be included.")
  448. (defcustom org-agenda-skip-comment-trees t
  449. "Non-nil means, skip trees that start with the COMMENT keyword.
  450. When nil, these trees are also scanned by agenda commands."
  451. :group 'org-agenda-skip
  452. :type 'boolean)
  453. (defcustom org-agenda-todo-list-sublevels t
  454. "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
  455. When nil, the sublevels of a TODO entry are not checked, resulting in
  456. potentially much shorter TODO lists."
  457. :group 'org-agenda-skip
  458. :group 'org-agenda-todo-list
  459. :type 'boolean)
  460. (defcustom org-agenda-todo-ignore-with-date nil
  461. "Non-nil means, don't show entries with a date in the global todo list.
  462. You can use this if you prefer to mark mere appointments with a TODO keyword,
  463. but don't want them to show up in the TODO list.
  464. When this is set, it also covers deadlines and scheduled items, the settings
  465. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  466. will be ignored.
  467. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  468. :group 'org-agenda-skip
  469. :group 'org-agenda-todo-list
  470. :type 'boolean)
  471. (defcustom org-agenda-todo-ignore-scheduled nil
  472. "Non-nil means, don't show scheduled entries in the global todo list.
  473. The idea behind this is that by scheduling it, you have already taken care
  474. of this item.
  475. See also `org-agenda-todo-ignore-with-date'.
  476. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  477. :group 'org-agenda-skip
  478. :group 'org-agenda-todo-list
  479. :type 'boolean)
  480. (defcustom org-agenda-todo-ignore-deadlines nil
  481. "Non-nil means, don't show near deadline entries in the global todo list.
  482. Near means closer than `org-deadline-warning-days' days.
  483. The idea behind this is that such items will appear in the agenda anyway.
  484. See also `org-agenda-todo-ignore-with-date'.
  485. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  486. :group 'org-agenda-skip
  487. :group 'org-agenda-todo-list
  488. :type 'boolean)
  489. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  490. "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
  491. The variables
  492. `org-agenda-todo-ignore-with-date',
  493. `org-agenda-todo-ignore-scheduled'
  494. `org-agenda-todo-ignore-deadlines'
  495. make the global TODO list skip entries that have time stamps of certain
  496. kinds. If this option is set, the same options will also apply for the
  497. tags-todo search, which is the general tags/property matcher
  498. restricted to unfinished TODO entries only."
  499. :group 'org-agenda-skip
  500. :group 'org-agenda-todo-list
  501. :group 'org-agenda-match-view
  502. :type 'boolean)
  503. (defcustom org-agenda-skip-scheduled-if-done nil
  504. "Non-nil means don't show scheduled items in agenda when they are done.
  505. This is relevant for the daily/weekly agenda, not for the TODO list. And
  506. it applies only to the actual date of the scheduling. Warnings about
  507. an item with a past scheduling dates are always turned off when the item
  508. is DONE."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-daily/weekly
  511. :type 'boolean)
  512. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  513. "Non-nil means skip scheduling line if same entry shows because of deadline.
  514. In the agenda of today, an entry can show up multiple times because
  515. it is both scheduled and has a nearby deadline, and maybe a plain time
  516. stamp as well.
  517. When this variable is t, then only the deadline is shown and the fact that
  518. the entry is scheduled today or was scheduled previously is not shown.
  519. When this variable is nil, the entry will be shown several times. When
  520. the variable is the symbol `not-today', then skip scheduled previously,
  521. but not scheduled today."
  522. :group 'org-agenda-skip
  523. :group 'org-agenda-daily/weekly
  524. :type '(choice
  525. (const :tag "Never" nil)
  526. (const :tag "Always" t)
  527. (const :tag "Not when scheduled today" not-today)))
  528. (defcustom org-agenda-skip-deadline-if-done nil
  529. "Non-nil means don't show deadlines when the corresponding item is done.
  530. When nil, the deadline is still shown and should give you a happy feeling.
  531. This is relevant for the daily/weekly agenda. And it applied only to the
  532. actually date of the deadline. Warnings about approaching and past-due
  533. deadlines are always turned off when the item is DONE."
  534. :group 'org-agenda-skip
  535. :group 'org-agenda-daily/weekly
  536. :type 'boolean)
  537. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  538. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  539. When non-nil, after the search for timestamps has matched once in an
  540. entry, the rest of the entry will not be searched."
  541. :group 'org-agenda-skip
  542. :type 'boolean)
  543. (defcustom org-agenda-skip-timestamp-if-done nil
  544. "Non-nil means don't select item by timestamp or -range if it is DONE."
  545. :group 'org-agenda-skip
  546. :group 'org-agenda-daily/weekly
  547. :type 'boolean)
  548. (defcustom org-agenda-dim-blocked-tasks t
  549. "Non-nil means, dim blocked tasks in the agenda display.
  550. This causes some overhead during agenda construction, but if you
  551. have turned on `org-enforce-todo-dependencies',
  552. `org-enforce-todo-checkbox-dependencies', or any other blocking
  553. mechanism, this will create useful feedback in the agenda.
  554. Instead ot t, this variable can also have the value `invisible'.
  555. Then blocked tasks will be invisible and only become visible when
  556. they become unblocked. An exemption to this behavior is when a task is
  557. blocked because of unchecked checkboxes below it. Since checkboxes do
  558. not show up in the agenda views, making this task invisible you remove any
  559. trace from agenda views that there is something to do. Therefore, a task
  560. that is blocked because of checkboxes will never be made invisible, it
  561. will only be dimmed."
  562. :group 'org-agenda-daily/weekly
  563. :group 'org-agenda-todo-list
  564. :type '(choice
  565. (const :tag "Do not dim" nil)
  566. (const :tag "Dim to a grey face" t)
  567. (const :tag "Make invisibe" invisible)))
  568. (defcustom org-timeline-show-empty-dates 3
  569. "Non-nil means, `org-timeline' also shows dates without an entry.
  570. When nil, only the days which actually have entries are shown.
  571. When t, all days between the first and the last date are shown.
  572. When an integer, show also empty dates, but if there is a gap of more than
  573. N days, just insert a special line indicating the size of the gap."
  574. :group 'org-agenda-skip
  575. :type '(choice
  576. (const :tag "None" nil)
  577. (const :tag "All" t)
  578. (integer :tag "at most")))
  579. (defgroup org-agenda-startup nil
  580. "Options concerning initial settings in the Agenda in Org Mode."
  581. :tag "Org Agenda Startup"
  582. :group 'org-agenda)
  583. (defcustom org-finalize-agenda-hook nil
  584. "Hook run just before displaying an agenda buffer."
  585. :group 'org-agenda-startup
  586. :type 'hook)
  587. (defcustom org-agenda-mouse-1-follows-link nil
  588. "Non-nil means, mouse-1 on a link will follow the link in the agenda.
  589. A longer mouse click will still set point. Does not work on XEmacs.
  590. Needs to be set before org.el is loaded."
  591. :group 'org-agenda-startup
  592. :type 'boolean)
  593. (defcustom org-agenda-start-with-follow-mode nil
  594. "The initial value of follow-mode in a newly created agenda window."
  595. :group 'org-agenda-startup
  596. :type 'boolean)
  597. (defcustom org-agenda-start-with-entry-text-mode nil
  598. "The initial value of entry-text-mode in a newly created agenda window."
  599. :group 'org-agenda-startup
  600. :type 'boolean)
  601. (defcustom org-agenda-entry-text-maxlines 5
  602. "Number of text lines to be added when `E' is presed in the agenda.
  603. Note that this variable only used during agenda display. Add add entry text
  604. when exporting the agenda, configure the variable
  605. `org-agenda-add-entry-ext-maxlines'."
  606. :group 'org-agenda
  607. :type 'integer)
  608. (defcustom org-agenda-entry-text-exclude-regexps nil
  609. "List of regular expressions to clean up entry text.
  610. The complete matches of all regular expressions in this list will be
  611. removed from entry text before it is shown in the agenda."
  612. :group 'org-agenda
  613. :type '(repeat (regexp)))
  614. (defvar org-agenda-entry-text-cleanup-hook nil
  615. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  616. This cleanup is done in a temporary buffer, so the function may inspect and
  617. change the entire buffer.
  618. Some default stuff like drawers and scheduling/deadline dates will already
  619. have been removed when this is called, as will any matches for regular
  620. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  621. (defvar org-agenda-include-inactive-timestamps nil
  622. "Non-nil means, include inactive time stamps in agenda and timeline.")
  623. (defgroup org-agenda-windows nil
  624. "Options concerning the windows used by the Agenda in Org Mode."
  625. :tag "Org Agenda Windows"
  626. :group 'org-agenda)
  627. (defcustom org-agenda-window-setup 'reorganize-frame
  628. "How the agenda buffer should be displayed.
  629. Possible values for this option are:
  630. current-window Show agenda in the current window, keeping all other windows.
  631. other-window Use `switch-to-buffer-other-window' to display agenda.
  632. reorganize-frame Show only two windows on the current frame, the current
  633. window and the agenda.
  634. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  635. Also, when exiting the agenda, kill that frame.
  636. See also the variable `org-agenda-restore-windows-after-quit'."
  637. :group 'org-agenda-windows
  638. :type '(choice
  639. (const current-window)
  640. (const other-frame)
  641. (const other-window)
  642. (const reorganize-frame)))
  643. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  644. "The min and max height of the agenda window as a fraction of frame height.
  645. The value of the variable is a cons cell with two numbers between 0 and 1.
  646. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  647. :group 'org-agenda-windows
  648. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  649. (defcustom org-agenda-restore-windows-after-quit nil
  650. "Non-nil means, restore window configuration open exiting agenda.
  651. Before the window configuration is changed for displaying the agenda,
  652. the current status is recorded. When the agenda is exited with
  653. `q' or `x' and this option is set, the old state is restored. If
  654. `org-agenda-window-setup' is `other-frame', the value of this
  655. option will be ignored."
  656. :group 'org-agenda-windows
  657. :type 'boolean)
  658. (defcustom org-agenda-ndays 7
  659. "Number of days to include in overview display.
  660. Should be 1 or 7.
  661. Custom commands can set this variable in the options section."
  662. :group 'org-agenda-daily/weekly
  663. :type 'integer)
  664. (defcustom org-agenda-start-on-weekday 1
  665. "Non-nil means, start the overview always on the specified weekday.
  666. 0 denotes Sunday, 1 denotes Monday etc.
  667. When nil, always start on the current day.
  668. Custom commands can set this variable in the options section."
  669. :group 'org-agenda-daily/weekly
  670. :type '(choice (const :tag "Today" nil)
  671. (integer :tag "Weekday No.")))
  672. (defcustom org-agenda-show-all-dates t
  673. "Non-nil means, `org-agenda' shows every day in the selected range.
  674. When nil, only the days which actually have entries are shown."
  675. :group 'org-agenda-daily/weekly
  676. :type 'boolean)
  677. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  678. "Format string for displaying dates in the agenda.
  679. Used by the daily/weekly agenda and by the timeline. This should be
  680. a format string understood by `format-time-string', or a function returning
  681. the formatted date as a string. The function must take a single argument,
  682. a calendar-style date list like (month day year)."
  683. :group 'org-agenda-daily/weekly
  684. :type '(choice
  685. (string :tag "Format string")
  686. (function :tag "Function")))
  687. (defun org-agenda-format-date-aligned (date)
  688. "Format a date string for display in the daily/weekly agenda, or timeline.
  689. This function makes sure that dates are aligned for easy reading."
  690. (require 'cal-iso)
  691. (let* ((dayname (calendar-day-name date))
  692. (day (cadr date))
  693. (day-of-week (calendar-day-of-week date))
  694. (month (car date))
  695. (monthname (calendar-month-name month))
  696. (year (nth 2 date))
  697. (iso-week (org-days-to-iso-week
  698. (calendar-absolute-from-gregorian date)))
  699. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  700. (1- year))
  701. ((and (= month 12) (<= iso-week 1))
  702. (1+ year))
  703. (t year)))
  704. (weekstring (if (= day-of-week 1)
  705. (format " W%02d" iso-week)
  706. "")))
  707. (format "%-10s %2d %s %4d%s"
  708. dayname day monthname year weekstring)))
  709. (defcustom org-agenda-weekend-days '(6 0)
  710. "Which days are weekend?
  711. These days get the special face `org-agenda-date-weekend' in the agenda
  712. and timeline buffers."
  713. :group 'org-agenda-daily/weekly
  714. :type '(set :greedy t
  715. (const :tag "Monday" 1)
  716. (const :tag "Tuesday" 2)
  717. (const :tag "Wednesday" 3)
  718. (const :tag "Thursday" 4)
  719. (const :tag "Friday" 5)
  720. (const :tag "Saturday" 6)
  721. (const :tag "Sunday" 0)))
  722. (defcustom org-agenda-include-diary nil
  723. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  724. Custom commands can set this variable in the options section."
  725. :group 'org-agenda-daily/weekly
  726. :type 'boolean)
  727. (defcustom org-agenda-include-all-todo nil
  728. "Set means weekly/daily agenda will always contain all TODO entries.
  729. The TODO entries will be listed at the top of the agenda, before
  730. the entries for specific days.
  731. This option is deprecated, it is better to define a block agenda instead."
  732. :group 'org-agenda-daily/weekly
  733. :type 'boolean)
  734. (defcustom org-agenda-repeating-timestamp-show-all t
  735. "Non-nil means, show all occurrences of a repeating stamp in the agenda.
  736. When nil, only one occurrence is shown, either today or the
  737. nearest into the future."
  738. :group 'org-agenda-daily/weekly
  739. :type 'boolean)
  740. (defcustom org-scheduled-past-days 10000
  741. "No. of days to continue listing scheduled items that are not marked DONE.
  742. When an item is scheduled on a date, it shows up in the agenda on this
  743. day and will be listed until it is marked done for the number of days
  744. given here."
  745. :group 'org-agenda-daily/weekly
  746. :type 'integer)
  747. (defcustom org-agenda-log-mode-items '(closed clock)
  748. "List of items that should be shown in agenda log mode.
  749. This list may contain the following symbols:
  750. closed Show entries that have been closed on that day.
  751. clock Show entries that have received clocked time on that day.
  752. state Show all logged state changes.
  753. Note that instead of changing this variable, you can also press `C-u l' in
  754. the agenda to display all available LOG items temporarily."
  755. :group 'org-agenda-daily/weekly
  756. :type '(set :greedy t (const closed) (const clock) (const state)))
  757. (defcustom org-agenda-log-mode-add-notes t
  758. "Non-nil means, add first line of notes to log entries in agenda views.
  759. If a log item like a state change or a clock entry is associated with
  760. notes, the first line of these notes will be added to the entry in the
  761. agenda display."
  762. :group 'org-agenda-daily/weekly
  763. :type 'boolean)
  764. (defcustom org-agenda-start-with-log-mode nil
  765. "The initial value of log-mode in a newly created agenda window."
  766. :group 'org-agenda-startup
  767. :group 'org-agenda-daily/weekly
  768. :type 'boolean)
  769. (defcustom org-agenda-start-with-clockreport-mode nil
  770. "The initial value of clockreport-mode in a newly created agenda window."
  771. :group 'org-agenda-startup
  772. :group 'org-agenda-daily/weekly
  773. :type 'boolean)
  774. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  775. "Property list with parameters for the clocktable in clockreport mode.
  776. This is the display mode that shows a clock table in the daily/weekly
  777. agenda, the properties for this dynamic block can be set here.
  778. The usual clocktable parameters are allowed here, but you cannot set
  779. the properties :name, :tstart, :tend, :block, and :scope - these will
  780. be overwritten to make sure the content accurately reflects the
  781. current display in the agenda."
  782. :group 'org-agenda-daily/weekly
  783. :type 'plist)
  784. (defcustom org-agenda-search-view-search-words-only nil
  785. "Non-nil means, the search string is interpreted as individual words
  786. The search then looks for each word separately in each entry and
  787. selects entries that have matches for all words.
  788. When nil, matching as loose words will only take place if the first
  789. word is preceded by + or -. If that is not the case, the search
  790. string will just be matched as a substring in the entry, but with
  791. each space character allowing for any whitespace, including newlines."
  792. :group 'org-agenda-search-view
  793. :type 'boolean)
  794. (defgroup org-agenda-time-grid nil
  795. "Options concerning the time grid in the Org-mode Agenda."
  796. :tag "Org Agenda Time Grid"
  797. :group 'org-agenda)
  798. (defcustom org-agenda-search-headline-for-time t
  799. "Non-nil means, search headline for a time-of-day.
  800. If the headline contains a time-of-day in one format or another, it will
  801. be used to sort the entry into the time sequence of items for a day.
  802. Some people have time stamps in the headline that refer to the creation
  803. time or so, and then this produces an unwanted side effect. If this is
  804. the case for your, use this variable to turn off searching the headline
  805. for a time."
  806. :group 'org-agenda-time-grid
  807. :type 'boolean)
  808. (defcustom org-agenda-use-time-grid t
  809. "Non-nil means, show a time grid in the agenda schedule.
  810. A time grid is a set of lines for specific times (like every two hours between
  811. 8:00 and 20:00). The items scheduled for a day at specific times are
  812. sorted in between these lines.
  813. For details about when the grid will be shown, and what it will look like, see
  814. the variable `org-agenda-time-grid'."
  815. :group 'org-agenda-time-grid
  816. :type 'boolean)
  817. (defcustom org-agenda-time-grid
  818. '((daily today require-timed)
  819. "----------------"
  820. (800 1000 1200 1400 1600 1800 2000))
  821. "The settings for time grid for agenda display.
  822. This is a list of three items. The first item is again a list. It contains
  823. symbols specifying conditions when the grid should be displayed:
  824. daily if the agenda shows a single day
  825. weekly if the agenda shows an entire week
  826. today show grid on current date, independent of daily/weekly display
  827. require-timed show grid only if at least one item has a time specification
  828. The second item is a string which will be placed behind the grid time.
  829. The third item is a list of integers, indicating the times that should have
  830. a grid line."
  831. :group 'org-agenda-time-grid
  832. :type
  833. '(list
  834. (set :greedy t :tag "Grid Display Options"
  835. (const :tag "Show grid in single day agenda display" daily)
  836. (const :tag "Show grid in weekly agenda display" weekly)
  837. (const :tag "Always show grid for today" today)
  838. (const :tag "Show grid only if any timed entries are present"
  839. require-timed)
  840. (const :tag "Skip grid times already present in an entry"
  841. remove-match))
  842. (string :tag "Grid String")
  843. (repeat :tag "Grid Times" (integer :tag "Time"))))
  844. (defgroup org-agenda-sorting nil
  845. "Options concerning sorting in the Org-mode Agenda."
  846. :tag "Org Agenda Sorting"
  847. :group 'org-agenda)
  848. (defcustom org-agenda-sorting-strategy
  849. '((agenda time-up priority-down category-keep)
  850. (todo priority-down category-keep)
  851. (tags priority-down category-keep)
  852. (search category-keep))
  853. "Sorting structure for the agenda items of a single day.
  854. This is a list of symbols which will be used in sequence to determine
  855. if an entry should be listed before another entry. The following
  856. symbols are recognized:
  857. time-up Put entries with time-of-day indications first, early first
  858. time-down Put entries with time-of-day indications first, late first
  859. category-keep Keep the default order of categories, corresponding to the
  860. sequence in `org-agenda-files'.
  861. category-up Sort alphabetically by category, A-Z.
  862. category-down Sort alphabetically by category, Z-A.
  863. tag-up Sort alphabetically by last tag, A-Z.
  864. tag-down Sort alphabetically by last tag, Z-A.
  865. priority-up Sort numerically by priority, high priority last.
  866. priority-down Sort numerically by priority, high priority first.
  867. todo-state-up Sort by todo state, tasks that are done last.
  868. todo-state-down Sort by todo state, tasks that are done first.
  869. effort-up Sort numerically by estimated effort, high effort last.
  870. effort-down Sort numerically by estimated effort, high effort first.
  871. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  872. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  873. The different possibilities will be tried in sequence, and testing stops
  874. if one comparison returns a \"not-equal\". For example, the default
  875. '(time-up category-keep priority-down)
  876. means: Pull out all entries having a specified time of day and sort them,
  877. in order to make a time schedule for the current day the first thing in the
  878. agenda listing for the day. Of the entries without a time indication, keep
  879. the grouped in categories, don't sort the categories, but keep them in
  880. the sequence given in `org-agenda-files'. Within each category sort by
  881. priority.
  882. Leaving out `category-keep' would mean that items will be sorted across
  883. categories by priority.
  884. Instead of a single list, this can also be a set of list for specific
  885. contents, with a context symbol in the car of the list, any of
  886. `agenda', `todo', `tags' for the corresponding agenda views.
  887. Custom commands can bind this variable in the options section."
  888. :group 'org-agenda-sorting
  889. :type `(choice
  890. (repeat :tag "General" ,org-sorting-choice)
  891. (list :tag "Individually"
  892. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  893. (repeat ,org-sorting-choice))
  894. (cons (const :tag "Strategy for TODO lists" todo)
  895. (repeat ,org-sorting-choice))
  896. (cons (const :tag "Strategy for Tags matches" tags)
  897. (repeat ,org-sorting-choice)))))
  898. (defcustom org-agenda-cmp-user-defined nil
  899. "A function to define the comparison `user-defined'.
  900. This function must receive two arguments, agenda entry a and b.
  901. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  902. the user comparison, return nil.
  903. When this is defined, you can make `user-defined-up' and `user-defined-down'
  904. part of an agenda sorting strategy."
  905. :group 'org-agenda-sorting
  906. :type 'symbol)
  907. (defcustom org-sort-agenda-notime-is-late t
  908. "Non-nil means, items without time are considered late.
  909. This is only relevant for sorting. When t, items which have no explicit
  910. time like 15:30 will be considered as 99:01, i.e. later than any items which
  911. do have a time. When nil, the default time is before 0:00. You can use this
  912. option to decide if the schedule for today should come before or after timeless
  913. agenda entries."
  914. :group 'org-agenda-sorting
  915. :type 'boolean)
  916. (defcustom org-sort-agenda-noeffort-is-high t
  917. "Non-nil means, items without effort estimate are sorted as high effort.
  918. This also applies when filtering an agenda view with respect to the
  919. < or > effort operator. Then, tasks with no effort defined will be treated
  920. as tasks with high effort.
  921. When nil, such items are sorted as 0 minutes effort."
  922. :group 'org-agenda-sorting
  923. :type 'boolean)
  924. (defgroup org-agenda-line-format nil
  925. "Options concerning the entry prefix in the Org-mode agenda display."
  926. :tag "Org Agenda Line Format"
  927. :group 'org-agenda)
  928. (defcustom org-agenda-prefix-format
  929. '((agenda . " %-12:c%?-12t% s")
  930. (timeline . " % s")
  931. (todo . " %-12:c")
  932. (tags . " %-12:c")
  933. (search . " %-12:c"))
  934. "Format specifications for the prefix of items in the agenda views.
  935. An alist with four entries, for the different agenda types. The keys to the
  936. sublists are `agenda', `timeline', `todo', and `tags'. The values
  937. are format strings.
  938. This format works similar to a printf format, with the following meaning:
  939. %c the category of the item, \"Diary\" for entries from the diary, or
  940. as given by the CATEGORY keyword or derived from the file name.
  941. %T the *last* tag of the item. Last because inherited tags come
  942. first in the list.
  943. %t the time-of-day specification if one applies to the entry, in the
  944. format HH:MM
  945. %s Scheduling/Deadline information, a short string
  946. All specifiers work basically like the standard `%s' of printf, but may
  947. contain two additional characters: A question mark just after the `%' and
  948. a whitespace/punctuation character just before the final letter.
  949. If the first character after `%' is a question mark, the entire field
  950. will only be included if the corresponding value applies to the
  951. current entry. This is useful for fields which should have fixed
  952. width when present, but zero width when absent. For example,
  953. \"%?-12t\" will result in a 12 character time field if a time of the
  954. day is specified, but will completely disappear in entries which do
  955. not contain a time.
  956. If there is punctuation or whitespace character just before the final
  957. format letter, this character will be appended to the field value if
  958. the value is not empty. For example, the format \"%-12:c\" leads to
  959. \"Diary: \" if the category is \"Diary\". If the category were be
  960. empty, no additional colon would be interted.
  961. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  962. - Indent the line with two space characters
  963. - Give the category in a 12 chars wide field, padded with whitespace on
  964. the right (because of `-'). Append a colon if there is a category
  965. (because of `:').
  966. - If there is a time-of-day, put it into a 12 chars wide field. If no
  967. time, don't put in an empty field, just skip it (because of '?').
  968. - Finally, put the scheduling information and append a whitespace.
  969. As another example, if you don't want the time-of-day of entries in
  970. the prefix, you could use:
  971. (setq org-agenda-prefix-format \" %-11:c% s\")
  972. See also the variables `org-agenda-remove-times-when-in-prefix' and
  973. `org-agenda-remove-tags'.
  974. Custom commands can set this variable in the options section."
  975. :type '(choice
  976. (string :tag "General format")
  977. (list :greedy t :tag "View dependent"
  978. (cons (const agenda) (string :tag "Format"))
  979. (cons (const timeline) (string :tag "Format"))
  980. (cons (const todo) (string :tag "Format"))
  981. (cons (const tags) (string :tag "Format"))
  982. (cons (const search) (string :tag "Format"))))
  983. :group 'org-agenda-line-format)
  984. (defvar org-prefix-format-compiled nil
  985. "The compiled version of the most recently used prefix format.
  986. See the variable `org-agenda-prefix-format'.")
  987. (defcustom org-agenda-todo-keyword-format "%-1s"
  988. "Format for the TODO keyword in agenda lines.
  989. Set this to something like \"%-12s\" if you want all TODO keywords
  990. to occupy a fixed space in the agenda display."
  991. :group 'org-agenda-line-format
  992. :type 'string)
  993. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  994. "Text preceding timerange entries in the agenda view.
  995. This is a list with two strings. The first applies when the range
  996. is entirely on one day. The second applies if the range spans several days.
  997. The strings may have two \"%d\" format specifiers which will be filled
  998. with the sequence number of the days, and the total number of days in the
  999. range, respectively."
  1000. :group 'org-agenda-line-format
  1001. :type '(list
  1002. (string :tag "Deadline today ")
  1003. (choice :tag "Deadline relative"
  1004. (string :tag "Format string")
  1005. (function))))
  1006. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1007. "Text preceeding scheduled items in the agenda view.
  1008. This is a list with two strings. The first applies when the item is
  1009. scheduled on the current day. The second applies when it has been scheduled
  1010. previously, it may contain a %d indicating that this is the nth time that
  1011. this item is scheduled, due to automatic rescheduling of unfinished items
  1012. for the following day. So this number is one larger than the number of days
  1013. that passed since this item was scheduled first."
  1014. :group 'org-agenda-line-format
  1015. :type '(list
  1016. (string :tag "Scheduled today ")
  1017. (string :tag "Scheduled previously")))
  1018. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1019. "Text preceeding deadline items in the agenda view.
  1020. This is a list with two strings. The first applies when the item has its
  1021. deadline on the current day. The second applies when it is in the past or
  1022. in the future, it may contain %d to capture how many days away the deadline
  1023. is (was)."
  1024. :group 'org-agenda-line-format
  1025. :type '(list
  1026. (string :tag "Deadline today ")
  1027. (choice :tag "Deadline relative"
  1028. (string :tag "Format string")
  1029. (function))))
  1030. (defcustom org-agenda-remove-times-when-in-prefix t
  1031. "Non-nil means, remove duplicate time specifications in agenda items.
  1032. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1033. time-of-day specification in a headline or diary entry is extracted and
  1034. placed into the prefix. If this option is non-nil, the original specification
  1035. \(a timestamp or -range, or just a plain time(range) specification like
  1036. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1037. cluttered.
  1038. The option can be t or nil. It may also be the symbol `beg', indicating
  1039. that the time should only be removed what it is located at the beginning of
  1040. the headline/diary entry."
  1041. :group 'org-agenda-line-format
  1042. :type '(choice
  1043. (const :tag "Always" t)
  1044. (const :tag "Never" nil)
  1045. (const :tag "When at beginning of entry" beg)))
  1046. (defcustom org-agenda-default-appointment-duration nil
  1047. "Default duration for appointments that only have a starting time.
  1048. When nil, no duration is specified in such cases.
  1049. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1050. :group 'org-agenda-line-format
  1051. :type '(choice
  1052. (integer :tag "Minutes")
  1053. (const :tag "No default duration")))
  1054. (defcustom org-agenda-show-inherited-tags t
  1055. "Non-nil means, show inherited tags in each agenda line."
  1056. :group 'org-agenda-line-format
  1057. :type 'boolean)
  1058. (defcustom org-agenda-remove-tags nil
  1059. "Non-nil means, remove the tags from the headline copy in the agenda.
  1060. When this is the symbol `prefix', only remove tags when
  1061. `org-agenda-prefix-format' contains a `%T' specifier."
  1062. :group 'org-agenda-line-format
  1063. :type '(choice
  1064. (const :tag "Always" t)
  1065. (const :tag "Never" nil)
  1066. (const :tag "When prefix format contains %T" prefix)))
  1067. (if (fboundp 'defvaralias)
  1068. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1069. 'org-agenda-remove-tags))
  1070. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1071. "Shift tags in agenda items to this column.
  1072. If this number is positive, it specifies the column. If it is negative,
  1073. it means that the tags should be flushright to that column. For example,
  1074. -80 works well for a normal 80 character screen."
  1075. :group 'org-agenda-line-format
  1076. :type 'integer)
  1077. (if (fboundp 'defvaralias)
  1078. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1079. (defcustom org-agenda-fontify-priorities 'cookies
  1080. "Non-nil means, highlight low and high priorities in agenda.
  1081. When t, the highest priority entries are bold, lowest priority italic.
  1082. However, settings in org-priority-faces will overrule these faces.
  1083. When this variable is the symbol `cookies', only fontify the
  1084. cookies, not the entire task.
  1085. This may also be an association list of priority faces, whose
  1086. keys are the character values of `org-highest-priority',
  1087. `org-default-priority', and `org-lowest-priority' (the default values
  1088. are ?A, ?B, and ?C, respectively). The face may be a named face,
  1089. or a list like `(:background \"Red\")'."
  1090. :group 'org-agenda-line-format
  1091. :type '(choice
  1092. (const :tag "Never" nil)
  1093. (const :tag "Defaults" t)
  1094. (const :tag "Cookies only" cookies)
  1095. (repeat :tag "Specify"
  1096. (list (character :tag "Priority" :value ?A)
  1097. (sexp :tag "face")))))
  1098. (defgroup org-agenda-column-view nil
  1099. "Options concerning column view in the agenda."
  1100. :tag "Org Agenda Column View"
  1101. :group 'org-agenda)
  1102. (defcustom org-agenda-columns-show-summaries t
  1103. "Non-nil means, show summaries for columns displayed in the agenda view."
  1104. :group 'org-agenda-column-view
  1105. :type 'boolean)
  1106. (defcustom org-agenda-columns-remove-prefix-from-item t
  1107. "Non-nil means, remove the prefix from a headline for agenda column view.
  1108. The special ITEM field in the columns format contains the current line, with
  1109. all information shown in other columns (like the TODO state or a tag).
  1110. When this variable is non-nil, also the agenda prefix will be removed from
  1111. the content of the ITEM field, to make sure as much as possible of the
  1112. headline can be shown in the limited width of the field."
  1113. :group 'org-agenda
  1114. :type 'boolean)
  1115. (defcustom org-agenda-columns-compute-summary-properties t
  1116. "Non-nil means, recompute all summary properties before column view.
  1117. When column view in the agenda is listing properties that have a summary
  1118. operator, it can go to all relevant buffers and recompute the summaries
  1119. there. This can mean overhead for the agenda column view, but is necessary
  1120. to have thing up to date.
  1121. As a special case, a CLOCKSUM property also makes sure that the clock
  1122. computations are current."
  1123. :group 'org-agenda-column-view
  1124. :type 'boolean)
  1125. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1126. "Non-nil means, the duration of an appointment will add to day effort.
  1127. The property to which appointment durations will be added is the one given
  1128. in the option `org-effort-property'. If an appointment does not have
  1129. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1130. is not set, an appointment without end time will not contribute to the time
  1131. estimate."
  1132. :group 'org-agenda-column-view
  1133. :type 'boolean)
  1134. (eval-when-compile
  1135. (require 'cl))
  1136. (require 'org)
  1137. (defun org-add-agenda-custom-command (entry)
  1138. "Replace or add a command in `org-agenda-custom-commands'.
  1139. This is mostly for hacking and trying a new command - once the command
  1140. works you probably want to add it to `org-agenda-custom-commands' for good."
  1141. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1142. (if ass
  1143. (setcdr ass (cdr entry))
  1144. (push entry org-agenda-custom-commands))))
  1145. ;;; Define the Org-agenda-mode
  1146. (defvar org-agenda-mode-map (make-sparse-keymap)
  1147. "Keymap for `org-agenda-mode'.")
  1148. (defvar org-agenda-menu) ; defined later in this file.
  1149. (defvar org-agenda-restrict) ; defined later in this file.
  1150. (defvar org-agenda-follow-mode nil)
  1151. (defvar org-agenda-entry-text-mode nil)
  1152. (defvar org-agenda-clockreport-mode nil)
  1153. (defvar org-agenda-show-log nil)
  1154. (defvar org-agenda-redo-command nil)
  1155. (defvar org-agenda-query-string nil)
  1156. (defvar org-agenda-mode-hook nil
  1157. "Hook for org-agenda-mode, run after the mode is turned on.")
  1158. (defvar org-agenda-type nil)
  1159. (defvar org-agenda-force-single-file nil)
  1160. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1161. (defun org-agenda-mode ()
  1162. "Mode for time-sorted view on action items in Org-mode files.
  1163. The following commands are available:
  1164. \\{org-agenda-mode-map}"
  1165. (interactive)
  1166. (kill-all-local-variables)
  1167. (setq org-agenda-undo-list nil
  1168. org-agenda-pending-undo-list nil
  1169. org-agenda-bulk-marked-entries nil)
  1170. (setq major-mode 'org-agenda-mode)
  1171. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1172. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1173. (setq mode-name "Org-Agenda")
  1174. (use-local-map org-agenda-mode-map)
  1175. (easy-menu-add org-agenda-menu)
  1176. (if org-startup-truncated (setq truncate-lines t))
  1177. (org-set-local 'line-move-visual nil)
  1178. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1179. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1180. ;; Make sure properties are removed when copying text
  1181. (when (boundp 'buffer-substring-filters)
  1182. (org-set-local 'buffer-substring-filters
  1183. (cons (lambda (x)
  1184. (set-text-properties 0 (length x) nil x) x)
  1185. buffer-substring-filters)))
  1186. (unless org-agenda-keep-modes
  1187. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1188. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1189. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1190. org-agenda-show-log org-agenda-start-with-log-mode))
  1191. (easy-menu-change
  1192. '("Agenda") "Agenda Files"
  1193. (append
  1194. (list
  1195. (vector
  1196. (if (get 'org-agenda-files 'org-restrict)
  1197. "Restricted to single file"
  1198. "Edit File List")
  1199. '(org-edit-agenda-file-list)
  1200. (not (get 'org-agenda-files 'org-restrict)))
  1201. "--")
  1202. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1203. (org-agenda-set-mode-name)
  1204. (apply
  1205. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1206. (list 'org-agenda-mode-hook)))
  1207. (substitute-key-definition 'undo 'org-agenda-undo
  1208. org-agenda-mode-map global-map)
  1209. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1210. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1211. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1212. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1213. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1214. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1215. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1216. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1217. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1218. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1219. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1220. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1221. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1222. (org-defkey org-agenda-mode-map "A" 'org-agenda-archive-to-archive-sibling)
  1223. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1224. (org-defkey org-agenda-mode-map " " 'org-agenda-show)
  1225. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1226. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1227. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1228. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1229. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1230. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1231. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1232. (org-defkey org-agenda-mode-map "a" 'org-agenda-toggle-archive-tag)
  1233. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1234. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1235. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1236. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1237. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1238. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1239. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1240. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1241. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1242. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1243. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1244. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1245. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1246. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1247. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1248. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1249. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1250. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1251. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1252. (while l (org-defkey org-agenda-mode-map
  1253. (int-to-string (pop l)) 'digit-argument)))
  1254. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1255. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1256. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1257. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1258. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1259. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1260. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1261. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1262. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1263. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1264. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1265. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1266. 'org-clock-modify-effort-estimate)
  1267. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1268. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1269. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1270. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1271. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1272. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1273. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1274. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1275. (org-defkey org-agenda-mode-map "n" 'next-line)
  1276. (org-defkey org-agenda-mode-map "p" 'previous-line)
  1277. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1278. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1279. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1280. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1281. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1282. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1283. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1284. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1285. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1286. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1287. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1288. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1289. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1290. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1291. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1292. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1293. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1294. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1295. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1296. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1297. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1298. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1299. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1300. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1301. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1302. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1303. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1304. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1305. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1306. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1307. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1308. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1309. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1310. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1311. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1312. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1313. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1314. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1315. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1316. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1317. (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
  1318. "Local keymap for agenda entries from Org-mode.")
  1319. (org-defkey org-agenda-keymap
  1320. (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
  1321. (org-defkey org-agenda-keymap
  1322. (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
  1323. (when org-agenda-mouse-1-follows-link
  1324. (org-defkey org-agenda-keymap [follow-link] 'mouse-face))
  1325. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1326. '("Agenda"
  1327. ("Agenda Files")
  1328. "--"
  1329. ("Agenda Dates"
  1330. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1331. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1332. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1333. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1334. "--"
  1335. ("View"
  1336. ["Day View" org-agenda-day-view
  1337. :active (org-agenda-check-type nil 'agenda)
  1338. :style radio :selected (equal org-agenda-ndays 1)
  1339. :keys "v d (or just d)"]
  1340. ["Week View" org-agenda-week-view
  1341. :active (org-agenda-check-type nil 'agenda)
  1342. :style radio :selected (equal org-agenda-ndays 7)
  1343. :keys "v w (or just w)"]
  1344. ["Month View" org-agenda-month-view
  1345. :active (org-agenda-check-type nil 'agenda)
  1346. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1347. :keys "v m"]
  1348. ["Year View" org-agenda-year-view
  1349. :active (org-agenda-check-type nil 'agenda)
  1350. :style radio :selected (member org-agenda-ndays '(365 366))
  1351. :keys "v y"]
  1352. "--"
  1353. ["Include Diary" org-agenda-toggle-diary
  1354. :style toggle :selected org-agenda-include-diary
  1355. :active (org-agenda-check-type nil 'agenda)]
  1356. ["Use Time Grid" org-agenda-toggle-time-grid
  1357. :style toggle :selected org-agenda-use-time-grid
  1358. :active (org-agenda-check-type nil 'agenda)]
  1359. "--"
  1360. ["Show clock report" org-agenda-clockreport-mode
  1361. :style toggle :selected org-agenda-clockreport-mode
  1362. :active (org-agenda-check-type nil 'agenda)]
  1363. ["Show some entry text" org-agenda-entry-text-mode
  1364. :style toggle :selected org-agenda-entry-text-mode
  1365. :active t]
  1366. "--"
  1367. ["Show Logbook entries" org-agenda-log-mode
  1368. :style toggle :selected org-agenda-show-log
  1369. :active (org-agenda-check-type nil 'agenda 'timeline)
  1370. :keys "v l (or just l)"]
  1371. ["Include archived trees" org-agenda-archives-mode
  1372. :style toggle :selected org-agenda-archives-mode :active t
  1373. :keys "v a"]
  1374. ["Include archive files" (org-agenda-archives-mode t)
  1375. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1376. :keys "v A"]
  1377. "--"
  1378. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1379. ["Write view to file" org-write-agenda t]
  1380. ["Rebuild buffer" org-agenda-redo t]
  1381. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1382. "--"
  1383. ["Show original entry" org-agenda-show t]
  1384. ["Go To (other window)" org-agenda-goto t]
  1385. ["Go To (this window)" org-agenda-switch-to t]
  1386. ["Follow Mode" org-agenda-follow-mode
  1387. :style toggle :selected org-agenda-follow-mode :active t]
  1388. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1389. "--"
  1390. ("TODO"
  1391. ["Cycle TODO" org-agenda-todo t]
  1392. ["Next TODO set" org-agenda-todo-nextset t]
  1393. ["Previous TODO set" org-agenda-todo-previousset t]
  1394. ["Add note" org-agenda-add-note t])
  1395. ("Archive/Refile/Delete"
  1396. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1397. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1398. ["Archive subtree" org-agenda-archive t]
  1399. "--"
  1400. ["Refile" org-agenda-refile t]
  1401. "--"
  1402. ["Delete subtree" org-agenda-kill t])
  1403. ("Bulk action"
  1404. ["Mark entry" org-agenda-bulk-mark t]
  1405. ["Unmark entry" org-agenda-bulk-unmark t]
  1406. ["Act on all marked" org-agenda-bulk-action t]
  1407. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1408. "--"
  1409. ("Tags and Properties"
  1410. ["Show all Tags" org-agenda-show-tags t]
  1411. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1412. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1413. "--"
  1414. ["Column View" org-columns t])
  1415. ("Deadline/Schedule"
  1416. ["Schedule" org-agenda-schedule t]
  1417. ["Set Deadline" org-agenda-deadline t]
  1418. "--"
  1419. ["Mark item" org-agenda-action :active t :keys "k m"]
  1420. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1421. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1422. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1423. "--"
  1424. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1425. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1426. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1427. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1428. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1429. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1430. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1431. ("Clock and Effort"
  1432. ["Clock in" org-agenda-clock-in t]
  1433. ["Clock out" org-agenda-clock-out t]
  1434. ["Clock cancel" org-agenda-clock-cancel t]
  1435. ["Goto running clock" org-clock-goto t]
  1436. "--"
  1437. ["Set Effort" org-agenda-set-effort t]
  1438. ["Change clocked effort" org-clock-modify-effort-estimate
  1439. (org-clock-is-active)])
  1440. ("Priority"
  1441. ["Set Priority" org-agenda-priority t]
  1442. ["Increase Priority" org-agenda-priority-up t]
  1443. ["Decrease Priority" org-agenda-priority-down t]
  1444. ["Show Priority" org-agenda-show-priority t])
  1445. ("Calendar/Diary"
  1446. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1447. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1448. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1449. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1450. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1451. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1452. "--"
  1453. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1454. "--"
  1455. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1456. "--"
  1457. ("MobileOrg"
  1458. ["Push Files and Views" org-mobile-push t]
  1459. ["Get Captured and Flagged" org-mobile-pull t]
  1460. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1461. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1462. "--"
  1463. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1464. "--"
  1465. ["Quit" org-agenda-quit t]
  1466. ["Exit and Release Buffers" org-agenda-exit t]
  1467. ))
  1468. ;;; Agenda undo
  1469. (defvar org-agenda-allow-remote-undo t
  1470. "Non-nil means, allow remote undo from the agenda buffer.")
  1471. (defvar org-agenda-undo-list nil
  1472. "List of undoable operations in the agenda since last refresh.")
  1473. (defvar org-agenda-undo-has-started-in nil
  1474. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1475. (defvar org-agenda-pending-undo-list nil
  1476. "In a series of undo commands, this is the list of remaining undo items.")
  1477. (defun org-agenda-undo ()
  1478. "Undo a remote editing step in the agenda.
  1479. This undoes changes both in the agenda buffer and in the remote buffer
  1480. that have been changed along."
  1481. (interactive)
  1482. (or org-agenda-allow-remote-undo
  1483. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1484. (if (not (eq this-command last-command))
  1485. (setq org-agenda-undo-has-started-in nil
  1486. org-agenda-pending-undo-list org-agenda-undo-list))
  1487. (if (not org-agenda-pending-undo-list)
  1488. (error "No further undo information"))
  1489. (let* ((entry (pop org-agenda-pending-undo-list))
  1490. buf line cmd rembuf)
  1491. (setq cmd (pop entry) line (pop entry))
  1492. (setq rembuf (nth 2 entry))
  1493. (org-with-remote-undo rembuf
  1494. (while (bufferp (setq buf (pop entry)))
  1495. (if (pop entry)
  1496. (with-current-buffer buf
  1497. (let ((last-undo-buffer buf)
  1498. (inhibit-read-only t))
  1499. (unless (memq buf org-agenda-undo-has-started-in)
  1500. (push buf org-agenda-undo-has-started-in)
  1501. (make-local-variable 'pending-undo-list)
  1502. (undo-start))
  1503. (while (and pending-undo-list
  1504. (listp pending-undo-list)
  1505. (not (car pending-undo-list)))
  1506. (pop pending-undo-list))
  1507. (undo-more 1))))))
  1508. (org-goto-line line)
  1509. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1510. (defun org-verify-change-for-undo (l1 l2)
  1511. "Verify that a real change occurred between the undo lists L1 and L2."
  1512. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1513. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1514. (not (eq l1 l2)))
  1515. ;;; Agenda dispatch
  1516. (defvar org-agenda-restrict nil)
  1517. (defvar org-agenda-restrict-begin (make-marker))
  1518. (defvar org-agenda-restrict-end (make-marker))
  1519. (defvar org-agenda-last-dispatch-buffer nil)
  1520. (defvar org-agenda-overriding-restriction nil)
  1521. ;;;###autoload
  1522. (defun org-agenda (&optional arg keys restriction)
  1523. "Dispatch agenda commands to collect entries to the agenda buffer.
  1524. Prompts for a command to execute. Any prefix arg will be passed
  1525. on to the selected command. The default selections are:
  1526. a Call `org-agenda-list' to display the agenda for current day or week.
  1527. t Call `org-todo-list' to display the global todo list.
  1528. T Call `org-todo-list' to display the global todo list, select only
  1529. entries with a specific TODO keyword (the user gets a prompt).
  1530. m Call `org-tags-view' to display headlines with tags matching
  1531. a condition (the user is prompted for the condition).
  1532. M Like `m', but select only TODO entries, no ordinary headlines.
  1533. L Create a timeline for the current buffer.
  1534. e Export views to associated files.
  1535. s Search entries for keywords.
  1536. / Multi occur across all agenda files and also files listed
  1537. in `org-agenda-text-search-extra-files'.
  1538. < Restrict agenda commands to buffer, subtree, or region.
  1539. Press several times to get the desired effect.
  1540. > Remove a previous restriction.
  1541. # List \"stuck\" projects.
  1542. ! Configure what \"stuck\" means.
  1543. C Configure custom agenda commands.
  1544. More commands can be added by configuring the variable
  1545. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1546. searches can be pre-defined in this way.
  1547. If the current buffer is in Org-mode and visiting a file, you can also
  1548. first press `<' once to indicate that the agenda should be temporarily
  1549. \(until the next use of \\[org-agenda]) restricted to the current file.
  1550. Pressing `<' twice means to restrict to the current subtree or region
  1551. \(if active)."
  1552. (interactive "P")
  1553. (catch 'exit
  1554. (let* ((prefix-descriptions nil)
  1555. (org-agenda-window-setup (if (equal (buffer-name)
  1556. org-agenda-buffer-name)
  1557. 'current-window
  1558. org-agenda-window-setup))
  1559. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1560. (org-agenda-custom-commands
  1561. ;; normalize different versions
  1562. (delq nil
  1563. (mapcar
  1564. (lambda (x)
  1565. (cond ((stringp (cdr x))
  1566. (push x prefix-descriptions)
  1567. nil)
  1568. ((stringp (nth 1 x)) x)
  1569. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1570. (t (cons (car x) (cons "" (cdr x))))))
  1571. org-agenda-custom-commands)))
  1572. (buf (current-buffer))
  1573. (bfn (buffer-file-name (buffer-base-buffer)))
  1574. entry key type match lprops ans)
  1575. ;; Turn off restriction unless there is an overriding one,
  1576. (unless org-agenda-overriding-restriction
  1577. (unless (org-bound-and-true-p org-agenda-keep-restriced-file-list)
  1578. ;; There is a request to keep the file list in place
  1579. (put 'org-agenda-files 'org-restrict nil))
  1580. (setq org-agenda-restrict nil)
  1581. (move-marker org-agenda-restrict-begin nil)
  1582. (move-marker org-agenda-restrict-end nil))
  1583. ;; Delete old local properties
  1584. (put 'org-agenda-redo-command 'org-lprops nil)
  1585. ;; Remember where this call originated
  1586. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1587. (unless keys
  1588. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1589. keys (car ans)
  1590. restriction (cdr ans)))
  1591. ;; Estabish the restriction, if any
  1592. (when (and (not org-agenda-overriding-restriction) restriction)
  1593. (put 'org-agenda-files 'org-restrict (list bfn))
  1594. (cond
  1595. ((eq restriction 'region)
  1596. (setq org-agenda-restrict t)
  1597. (move-marker org-agenda-restrict-begin (region-beginning))
  1598. (move-marker org-agenda-restrict-end (region-end)))
  1599. ((eq restriction 'subtree)
  1600. (save-excursion
  1601. (setq org-agenda-restrict t)
  1602. (org-back-to-heading t)
  1603. (move-marker org-agenda-restrict-begin (point))
  1604. (move-marker org-agenda-restrict-end
  1605. (progn (org-end-of-subtree t)))))))
  1606. (require 'calendar) ; FIXME: can we avoid this for some commands?
  1607. ;; For example the todo list should not need it (but does...)
  1608. (cond
  1609. ((setq entry (assoc keys org-agenda-custom-commands))
  1610. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1611. (progn
  1612. (setq type (nth 2 entry) match (nth 3 entry) lprops (nth 4 entry))
  1613. (put 'org-agenda-redo-command 'org-lprops lprops)
  1614. (cond
  1615. ((eq type 'agenda)
  1616. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1617. ((eq type 'alltodo)
  1618. (org-let lprops '(org-todo-list current-prefix-arg)))
  1619. ((eq type 'search)
  1620. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1621. ((eq type 'stuck)
  1622. (org-let lprops '(org-agenda-list-stuck-projects
  1623. current-prefix-arg)))
  1624. ((eq type 'tags)
  1625. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1626. ((eq type 'tags-todo)
  1627. (org-let lprops '(org-tags-view '(4) match)))
  1628. ((eq type 'todo)
  1629. (org-let lprops '(org-todo-list match)))
  1630. ((eq type 'tags-tree)
  1631. (org-check-for-org-mode)
  1632. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1633. ((eq type 'todo-tree)
  1634. (org-check-for-org-mode)
  1635. (org-let lprops
  1636. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1637. (regexp-quote match) "\\>"))))
  1638. ((eq type 'occur-tree)
  1639. (org-check-for-org-mode)
  1640. (org-let lprops '(org-occur match)))
  1641. ((functionp type)
  1642. (org-let lprops '(funcall type match)))
  1643. ((fboundp type)
  1644. (org-let lprops '(funcall type match)))
  1645. (t (error "Invalid custom agenda command type %s" type))))
  1646. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1647. ((equal keys "C")
  1648. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1649. (customize-variable 'org-agenda-custom-commands))
  1650. ((equal keys "a") (call-interactively 'org-agenda-list))
  1651. ((equal keys "s") (call-interactively 'org-search-view))
  1652. ((equal keys "t") (call-interactively 'org-todo-list))
  1653. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1654. ((equal keys "m") (call-interactively 'org-tags-view))
  1655. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1656. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1657. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1658. (org-add-hook
  1659. 'post-command-hook
  1660. (lambda ()
  1661. (unless (current-message)
  1662. (let* ((m (org-agenda-get-any-marker))
  1663. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1664. (when note
  1665. (message (concat
  1666. "FLAGGING-NOTE ([?] for more info): "
  1667. (org-add-props
  1668. (replace-regexp-in-string
  1669. "\\\\n" "//"
  1670. (copy-sequence note))
  1671. nil 'face 'org-warning)))))))
  1672. t t))
  1673. ((equal keys "L")
  1674. (unless (org-mode-p)
  1675. (error "This is not an Org-mode file"))
  1676. (unless restriction
  1677. (put 'org-agenda-files 'org-restrict (list bfn))
  1678. (org-call-with-arg 'org-timeline arg)))
  1679. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1680. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1681. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1682. (t (error "Invalid agenda key"))))))
  1683. (defun org-agenda-normalize-custom-commands (cmds)
  1684. (delq nil
  1685. (mapcar
  1686. (lambda (x)
  1687. (cond ((stringp (cdr x)) nil)
  1688. ((stringp (nth 1 x)) x)
  1689. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1690. (t (cons (car x) (cons "" (cdr x))))))
  1691. cmds)))
  1692. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1693. "The user interface for selecting an agenda command."
  1694. (catch 'exit
  1695. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1696. (restrict-ok (and bfn (org-mode-p)))
  1697. (region-p (org-region-active-p))
  1698. (custom org-agenda-custom-commands)
  1699. (selstring "")
  1700. restriction second-time
  1701. c entry key type match prefixes rmheader header-end custom1 desc)
  1702. (save-window-excursion
  1703. (delete-other-windows)
  1704. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1705. (erase-buffer)
  1706. (insert (eval-when-compile
  1707. (let ((header
  1708. "
  1709. Press key for an agenda command: < Buffer, subtree/region restriction
  1710. -------------------------------- > Remove restriction
  1711. a Agenda for current week or day e Export agenda views
  1712. t List of all TODO entries T Entries with special TODO kwd
  1713. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1714. L Timeline for current buffer # List stuck projects (!=configure)
  1715. s Search for keywords C Configure custom agenda commands
  1716. / Multi-occur ? Find :FLAGGED: entries
  1717. ")
  1718. (start 0))
  1719. (while (string-match
  1720. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1721. header start)
  1722. (setq start (match-end 0))
  1723. (add-text-properties (match-beginning 2) (match-end 2)
  1724. '(face bold) header))
  1725. header)))
  1726. (setq header-end (move-marker (make-marker) (point)))
  1727. (while t
  1728. (setq custom1 custom)
  1729. (when (eq rmheader t)
  1730. (org-goto-line 1)
  1731. (re-search-forward ":" nil t)
  1732. (delete-region (match-end 0) (point-at-eol))
  1733. (forward-char 1)
  1734. (looking-at "-+")
  1735. (delete-region (match-end 0) (point-at-eol))
  1736. (move-marker header-end (match-end 0)))
  1737. (goto-char header-end)
  1738. (delete-region (point) (point-max))
  1739. (while (setq entry (pop custom1))
  1740. (setq key (car entry) desc (nth 1 entry)
  1741. type (nth 2 entry)
  1742. match (nth 3 entry))
  1743. (if (> (length key) 1)
  1744. (add-to-list 'prefixes (string-to-char key))
  1745. (insert
  1746. (format
  1747. "\n%-4s%-14s: %s"
  1748. (org-add-props (copy-sequence key)
  1749. '(face bold))
  1750. (cond
  1751. ((string-match "\\S-" desc) desc)
  1752. ((eq type 'agenda) "Agenda for current week or day")
  1753. ((eq type 'alltodo) "List of all TODO entries")
  1754. ((eq type 'search) "Word search")
  1755. ((eq type 'stuck) "List of stuck projects")
  1756. ((eq type 'todo) "TODO keyword")
  1757. ((eq type 'tags) "Tags query")
  1758. ((eq type 'tags-todo) "Tags (TODO)")
  1759. ((eq type 'tags-tree) "Tags tree")
  1760. ((eq type 'todo-tree) "TODO kwd tree")
  1761. ((eq type 'occur-tree) "Occur tree")
  1762. ((functionp type) (if (symbolp type)
  1763. (symbol-name type)
  1764. "Lambda expression"))
  1765. (t "???"))
  1766. (cond
  1767. ((stringp match)
  1768. (setq match (copy-sequence match))
  1769. (org-add-props match nil 'face 'org-warning))
  1770. (match
  1771. (format "set of %d commands" (length match)))
  1772. (t ""))))))
  1773. (when prefixes
  1774. (mapc (lambda (x)
  1775. (insert
  1776. (format "\n%s %s"
  1777. (org-add-props (char-to-string x)
  1778. nil 'face 'bold)
  1779. (or (cdr (assoc (concat selstring (char-to-string x))
  1780. prefix-descriptions))
  1781. "Prefix key"))))
  1782. prefixes))
  1783. (goto-char (point-min))
  1784. (if second-time
  1785. (if (not (pos-visible-in-window-p (point-max)))
  1786. (org-fit-window-to-buffer))
  1787. (setq second-time t)
  1788. (org-fit-window-to-buffer))
  1789. (message "Press key for agenda command%s:"
  1790. (if (or restrict-ok org-agenda-overriding-restriction)
  1791. (if org-agenda-overriding-restriction
  1792. " (restriction lock active)"
  1793. (if restriction
  1794. (format " (restricted to %s)" restriction)
  1795. " (unrestricted)"))
  1796. ""))
  1797. (setq c (read-char-exclusive))
  1798. (message "")
  1799. (cond
  1800. ((assoc (char-to-string c) custom)
  1801. (setq selstring (concat selstring (char-to-string c)))
  1802. (throw 'exit (cons selstring restriction)))
  1803. ((memq c prefixes)
  1804. (setq selstring (concat selstring (char-to-string c))
  1805. prefixes nil
  1806. rmheader (or rmheader t)
  1807. custom (delq nil (mapcar
  1808. (lambda (x)
  1809. (if (or (= (length (car x)) 1)
  1810. (/= (string-to-char (car x)) c))
  1811. nil
  1812. (cons (substring (car x) 1) (cdr x))))
  1813. custom))))
  1814. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1815. (message "Restriction is only possible in Org-mode buffers")
  1816. (ding) (sit-for 1))
  1817. ((eq c ?1)
  1818. (org-agenda-remove-restriction-lock 'noupdate)
  1819. (setq restriction 'buffer))
  1820. ((eq c ?0)
  1821. (org-agenda-remove-restriction-lock 'noupdate)
  1822. (setq restriction (if region-p 'region 'subtree)))
  1823. ((eq c ?<)
  1824. (org-agenda-remove-restriction-lock 'noupdate)
  1825. (setq restriction
  1826. (cond
  1827. ((eq restriction 'buffer)
  1828. (if region-p 'region 'subtree))
  1829. ((memq restriction '(subtree region))
  1830. nil)
  1831. (t 'buffer))))
  1832. ((eq c ?>)
  1833. (org-agenda-remove-restriction-lock 'noupdate)
  1834. (setq restriction nil))
  1835. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  1836. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  1837. ((and (> (length selstring) 0) (eq c ?\d))
  1838. (delete-window)
  1839. (org-agenda-get-restriction-and-command prefix-descriptions))
  1840. ((equal c ?q) (error "Abort"))
  1841. (t (error "Invalid key %c" c))))))))
  1842. (defun org-run-agenda-series (name series)
  1843. (org-let (nth 1 series) '(org-prepare-agenda name))
  1844. (let* ((org-agenda-multi t)
  1845. (redo (list 'org-run-agenda-series name (list 'quote series)))
  1846. (cmds (car series))
  1847. (gprops (nth 1 series))
  1848. match ;; The byte compiler incorrectly complains about this. Keep it!
  1849. cmd type lprops)
  1850. (while (setq cmd (pop cmds))
  1851. (setq type (car cmd) match (nth 1 cmd) lprops (nth 2 cmd))
  1852. (cond
  1853. ((eq type 'agenda)
  1854. (org-let2 gprops lprops
  1855. '(call-interactively 'org-agenda-list)))
  1856. ((eq type 'alltodo)
  1857. (org-let2 gprops lprops
  1858. '(call-interactively 'org-todo-list)))
  1859. ((eq type 'search)
  1860. (org-let2 gprops lprops
  1861. '(org-search-view current-prefix-arg match nil)))
  1862. ((eq type 'stuck)
  1863. (org-let2 gprops lprops
  1864. '(call-interactively 'org-agenda-list-stuck-projects)))
  1865. ((eq type 'tags)
  1866. (org-let2 gprops lprops
  1867. '(org-tags-view current-prefix-arg match)))
  1868. ((eq type 'tags-todo)
  1869. (org-let2 gprops lprops
  1870. '(org-tags-view '(4) match)))
  1871. ((eq type 'todo)
  1872. (org-let2 gprops lprops
  1873. '(org-todo-list match)))
  1874. ((fboundp type)
  1875. (org-let2 gprops lprops
  1876. '(funcall type match)))
  1877. (t (error "Invalid type in command series"))))
  1878. (widen)
  1879. (setq org-agenda-redo-command redo)
  1880. (goto-char (point-min)))
  1881. (org-fit-agenda-window)
  1882. (org-let (nth 1 series) '(org-finalize-agenda)))
  1883. ;;;###autoload
  1884. (defmacro org-batch-agenda (cmd-key &rest parameters)
  1885. "Run an agenda command in batch mode and send the result to STDOUT.
  1886. If CMD-KEY is a string of length 1, it is used as a key in
  1887. `org-agenda-custom-commands' and triggers this command. If it is a
  1888. longer string it is used as a tags/todo match string.
  1889. Paramters are alternating variable names and values that will be bound
  1890. before running the agenda command."
  1891. (let (pars)
  1892. (while parameters
  1893. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1894. (if (> (length cmd-key) 2)
  1895. (eval (list 'let (nreverse pars)
  1896. (list 'org-tags-view nil cmd-key)))
  1897. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1898. (set-buffer org-agenda-buffer-name)
  1899. (princ (org-encode-for-stdout (buffer-string)))))
  1900. ;(defun org-encode-for-stdout (string)
  1901. ; (if (fboundp 'encode-coding-string)
  1902. ; (encode-coding-string string buffer-file-coding-system)
  1903. ; string))
  1904. (defun org-encode-for-stdout (string)
  1905. string)
  1906. (defvar org-agenda-info nil)
  1907. ;;;###autoload
  1908. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  1909. "Run an agenda command in batch mode and send the result to STDOUT.
  1910. If CMD-KEY is a string of length 1, it is used as a key in
  1911. `org-agenda-custom-commands' and triggers this command. If it is a
  1912. longer string it is used as a tags/todo match string.
  1913. Paramters are alternating variable names and values that will be bound
  1914. before running the agenda command.
  1915. The output gives a line for each selected agenda item. Each
  1916. item is a list of comma-separated values, like this:
  1917. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  1918. category The category of the item
  1919. head The headline, without TODO kwd, TAGS and PRIORITY
  1920. type The type of the agenda entry, can be
  1921. todo selected in TODO match
  1922. tagsmatch selected in tags match
  1923. diary imported from diary
  1924. deadline a deadline on given date
  1925. scheduled scheduled on given date
  1926. timestamp entry has timestamp on given date
  1927. closed entry was closed on given date
  1928. upcoming-deadline warning about deadline
  1929. past-scheduled forwarded scheduled item
  1930. block entry has date block including g. date
  1931. todo The todo keyword, if any
  1932. tags All tags including inherited ones, separated by colons
  1933. date The relevant date, like 2007-2-14
  1934. time The time, like 15:00-16:50
  1935. extra Sting with extra planning info
  1936. priority-l The priority letter if any was given
  1937. priority-n The computed numerical priority
  1938. agenda-day The day in the agenda where this is listed"
  1939. (let (pars)
  1940. (while parameters
  1941. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1942. (push (list 'org-agenda-remove-tags t) pars)
  1943. (if (> (length cmd-key) 2)
  1944. (eval (list 'let (nreverse pars)
  1945. (list 'org-tags-view nil cmd-key)))
  1946. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1947. (set-buffer org-agenda-buffer-name)
  1948. (let* ((lines (org-split-string (buffer-string) "\n"))
  1949. line)
  1950. (while (setq line (pop lines))
  1951. (catch 'next
  1952. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  1953. (setq org-agenda-info
  1954. (org-fix-agenda-info (text-properties-at 0 line)))
  1955. (princ
  1956. (org-encode-for-stdout
  1957. (mapconcat 'org-agenda-export-csv-mapper
  1958. '(org-category txt type todo tags date time-of-day extra
  1959. priority-letter priority agenda-day)
  1960. ",")))
  1961. (princ "\n"))))))
  1962. (defun org-fix-agenda-info (props)
  1963. "Make sure all properties on an agenda item have a canonical form,
  1964. so the export commands can easily use it."
  1965. (let (tmp re)
  1966. (when (setq tmp (plist-get props 'tags))
  1967. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  1968. (when (setq tmp (plist-get props 'date))
  1969. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  1970. (let ((calendar-date-display-form '(year "-" month "-" day)))
  1971. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  1972. (setq tmp (calendar-date-string tmp)))
  1973. (setq props (plist-put props 'date tmp)))
  1974. (when (setq tmp (plist-get props 'day))
  1975. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  1976. (let ((calendar-date-display-form '(year "-" month "-" day)))
  1977. (setq tmp (calendar-date-string tmp)))
  1978. (setq props (plist-put props 'day tmp))
  1979. (setq props (plist-put props 'agenda-day tmp)))
  1980. (when (setq tmp (plist-get props 'txt))
  1981. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  1982. (plist-put props 'priority-letter (match-string 1 tmp))
  1983. (setq tmp (replace-match "" t t tmp)))
  1984. (when (and (setq re (plist-get props 'org-todo-regexp))
  1985. (setq re (concat "\\`\\.*" re " ?"))
  1986. (string-match re tmp))
  1987. (plist-put props 'todo (match-string 1 tmp))
  1988. (setq tmp (replace-match "" t t tmp)))
  1989. (plist-put props 'txt tmp)))
  1990. props)
  1991. (defun org-agenda-export-csv-mapper (prop)
  1992. (let ((res (plist-get org-agenda-info prop)))
  1993. (setq res
  1994. (cond
  1995. ((not res) "")
  1996. ((stringp res) res)
  1997. (t (prin1-to-string res))))
  1998. (while (string-match "," res)
  1999. (setq res (replace-match ";" t t res)))
  2000. (org-trim res)))
  2001. ;;;###autoload
  2002. (defun org-store-agenda-views (&rest parameters)
  2003. (interactive)
  2004. (eval (list 'org-batch-store-agenda-views)))
  2005. ;; FIXME, why is this a macro?????
  2006. ;;;###autoload
  2007. (defmacro org-batch-store-agenda-views (&rest parameters)
  2008. "Run all custom agenda commands that have a file argument."
  2009. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2010. (pop-up-frames nil)
  2011. (dir default-directory)
  2012. pars cmd thiscmdkey files opts cmd-or-set)
  2013. (while parameters
  2014. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2015. (setq pars (reverse pars))
  2016. (save-window-excursion
  2017. (while cmds
  2018. (setq cmd (pop cmds)
  2019. thiscmdkey (car cmd)
  2020. cmd-or-set (nth 2 cmd)
  2021. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2022. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2023. (if (stringp files) (setq files (list files)))
  2024. (when files
  2025. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2026. (list 'org-agenda nil thiscmdkey)))
  2027. (set-buffer org-agenda-buffer-name)
  2028. (while files
  2029. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2030. (list 'org-write-agenda
  2031. (expand-file-name (pop files) dir) nil t))))
  2032. (and (get-buffer org-agenda-buffer-name)
  2033. (kill-buffer org-agenda-buffer-name)))))))
  2034. (defun org-agenda-mark-header-line (pos)
  2035. "Mark the line at POS as an agenda structure header."
  2036. (save-excursion
  2037. (goto-char pos)
  2038. (put-text-property (point-at-bol) (point-at-eol)
  2039. 'org-agenda-structural-header t)
  2040. (when org-agenda-title-append
  2041. (put-text-property (point-at-bol) (point-at-eol)
  2042. 'org-agenda-title-append org-agenda-title-append))))
  2043. (defvar org-mobile-creating-agendas)
  2044. (defun org-write-agenda (file &optional open nosettings)
  2045. "Write the current buffer (an agenda view) as a file.
  2046. Depending on the extension of the file name, plain text (.txt),
  2047. HTML (.html or .htm) or Postscript (.ps) is produced.
  2048. If the extension is .ics, run icalendar export over all files used
  2049. to construct the agenda and limit the export to entries listed in the
  2050. agenda now.
  2051. With prefic argument OPEN, open the new file immediately.
  2052. If NOSETTINGS is given, do not scope the settings of
  2053. `org-agenda-exporter-settings' into the export commands. This is used when
  2054. the settings have already been scoped and we do not wish to overrule other,
  2055. higher priority settings."
  2056. (interactive "FWrite agenda to file: \nP")
  2057. (if (not (file-writable-p file))
  2058. (error "Cannot write agenda to file %s" file))
  2059. (cond
  2060. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2061. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2062. (org-let (if nosettings nil org-agenda-exporter-settings)
  2063. '(save-excursion
  2064. (save-window-excursion
  2065. (org-agenda-mark-filtered-text)
  2066. (let ((bs (copy-sequence (buffer-string))) beg)
  2067. (org-agenda-unmark-filtered-text)
  2068. (with-temp-buffer
  2069. (insert bs)
  2070. (org-agenda-remove-marked-text 'org-filtered)
  2071. (while (setq beg (text-property-any (point-min) (point-max)
  2072. 'org-filtered t))
  2073. (delete-region
  2074. beg (or (next-single-property-change beg 'org-filtered)
  2075. (point-max))))
  2076. (run-hooks 'org-agenda-before-write-hook)
  2077. (cond
  2078. ((org-bound-and-true-p org-mobile-creating-agendas)
  2079. (org-mobile-write-agenda-for-mobile file))
  2080. ((string-match "\\.html?\\'" file)
  2081. (set-buffer (htmlize-buffer (current-buffer)))
  2082. (when (and org-agenda-export-html-style
  2083. (string-match "<style>" org-agenda-export-html-style))
  2084. ;; replace <style> section with org-agenda-export-html-style
  2085. (goto-char (point-min))
  2086. (kill-region (- (search-forward "<style") 6)
  2087. (search-forward "</style>"))
  2088. (insert org-agenda-export-html-style))
  2089. (write-file file)
  2090. (kill-buffer (current-buffer))
  2091. (message "HTML written to %s" file))
  2092. ((string-match "\\.ps\\'" file)
  2093. (require 'ps-print)
  2094. (flet ((ps-get-buffer-name () "Agenda View"))
  2095. (ps-print-buffer-with-faces file))
  2096. (message "Postscript written to %s" file))
  2097. ((string-match "\\.pdf\\'" file)
  2098. (require 'ps-print)
  2099. (flet ((ps-get-buffer-name () "Agenda View"))
  2100. (ps-print-buffer-with-faces
  2101. (concat (file-name-sans-extension file) ".ps")))
  2102. (call-process "ps2pdf" nil nil nil
  2103. (expand-file-name
  2104. (concat (file-name-sans-extension file) ".ps"))
  2105. (expand-file-name file))
  2106. (message "PDF written to %s" file))
  2107. ((string-match "\\.ics\\'" file)
  2108. (require 'org-icalendar)
  2109. (let ((org-agenda-marker-table
  2110. (org-create-marker-find-array
  2111. (org-agenda-collect-markers)))
  2112. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2113. (org-combined-agenda-icalendar-file file))
  2114. (apply 'org-export-icalendar 'combine
  2115. (org-agenda-files nil 'ifmode))))
  2116. (t
  2117. (let ((bs (buffer-string)))
  2118. (find-file file)
  2119. (erase-buffer)
  2120. (insert bs)
  2121. (save-buffer 0)
  2122. (kill-buffer (current-buffer))
  2123. (message "Plain text written to %s" file))))))))
  2124. (set-buffer org-agenda-buffer-name))
  2125. (when open (org-open-file file)))
  2126. (defvar org-agenda-filter-overlays nil)
  2127. (defun org-agenda-mark-filtered-text ()
  2128. "Mark all text hidden by filtering with a text property."
  2129. (let ((inhibit-read-only t))
  2130. (mapc
  2131. (lambda (o)
  2132. (when (equal (org-overlay-buffer o) (current-buffer))
  2133. (put-text-property
  2134. (org-overlay-start o) (org-overlay-end o)
  2135. 'org-filtered t)))
  2136. org-agenda-filter-overlays)))
  2137. (defun org-agenda-unmark-filtered-text ()
  2138. "Remove the filtering text property."
  2139. (let ((inhibit-read-only t))
  2140. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2141. (defun org-agenda-remove-marked-text (property &optional value)
  2142. "Delete all text marked with VALUE of PROPERTY.
  2143. VALUE defaults to t."
  2144. (let (beg)
  2145. (setq value (or value t))
  2146. (while (setq beg (text-property-any (point-min) (point-max)
  2147. property value))
  2148. (delete-region
  2149. beg (or (next-single-property-change beg 'org-filtered)
  2150. (point-max))))))
  2151. (defun org-agenda-add-entry-text ()
  2152. "Add entry text to agenda lines.
  2153. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2154. entry text following headings shown in the agenda.
  2155. Drawers will be excluded, also the line with scheduling/deadline info."
  2156. (when (> org-agenda-add-entry-text-maxlines 0)
  2157. (let (m txt)
  2158. (goto-char (point-min))
  2159. (while (not (eobp))
  2160. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2161. (beginning-of-line 2)
  2162. (setq txt (org-agenda-get-some-entry-text
  2163. m org-agenda-add-entry-text-maxlines " > "))
  2164. (end-of-line 1)
  2165. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2166. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2167. &rest keep)
  2168. "Extract entry text from MARKER, at most N-LINES lines.
  2169. This will ignore drawers etc, just get the text.
  2170. If INDENT is given, prefix every line with this string. If KEEP is
  2171. given, it is a list of symbols, defining stuff that hould not be
  2172. removed from the entry content. Currently only `planning' is allowed here."
  2173. (let (txt drawer-re kwd-time-re ind)
  2174. (save-excursion
  2175. (with-current-buffer (marker-buffer marker)
  2176. (if (not (org-mode-p))
  2177. (setq txt "")
  2178. (save-excursion
  2179. (save-restriction
  2180. (widen)
  2181. (goto-char marker)
  2182. (end-of-line 1)
  2183. (setq txt (buffer-substring
  2184. (min (1+ (point)) (point-max))
  2185. (progn (outline-next-heading) (point)))
  2186. drawer-re org-drawer-regexp
  2187. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2188. ".*\n?"))
  2189. (with-temp-buffer
  2190. (insert txt)
  2191. (when org-agenda-add-entry-text-descriptive-links
  2192. (goto-char (point-min))
  2193. (while (org-activate-bracket-links (point-max))
  2194. (add-text-properties (match-beginning 0) (match-end 0)
  2195. '(face org-link))))
  2196. (goto-char (point-min))
  2197. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2198. (set-text-properties (match-beginning 0) (match-end 0)
  2199. nil))
  2200. (goto-char (point-min))
  2201. (while (re-search-forward drawer-re nil t)
  2202. (delete-region
  2203. (match-beginning 0)
  2204. (progn (re-search-forward
  2205. "^[ \t]*:END:.*\n?" nil 'move)
  2206. (point))))
  2207. (unless (member 'planning keep)
  2208. (goto-char (point-min))
  2209. (while (re-search-forward kwd-time-re nil t)
  2210. (replace-match "")))
  2211. (goto-char (point-min))
  2212. (when org-agenda-entry-text-exclude-regexps
  2213. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2214. (while (setq re (pop re-list))
  2215. (goto-char (point-min))
  2216. (while (re-search-forward re nil t)
  2217. (replace-match "")))))
  2218. (goto-char (point-max))
  2219. (skip-chars-backward " \t\n")
  2220. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2221. ;; find and remove min common indentation
  2222. (goto-char (point-min))
  2223. (untabify (point-min) (point-max))
  2224. (setq ind (org-get-indentation))
  2225. (while (not (eobp))
  2226. (unless (looking-at "[ \t]*$")
  2227. (setq ind (min ind (org-get-indentation))))
  2228. (beginning-of-line 2))
  2229. (goto-char (point-min))
  2230. (while (not (eobp))
  2231. (unless (looking-at "[ \t]*$")
  2232. (move-to-column ind)
  2233. (delete-region (point-at-bol) (point)))
  2234. (beginning-of-line 2))
  2235. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2236. (goto-char (point-min))
  2237. (when indent
  2238. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2239. (replace-match indent t t)))
  2240. (goto-char (point-min))
  2241. (while (looking-at "[ \t]*\n") (replace-match ""))
  2242. (goto-char (point-max))
  2243. (when (> (org-current-line)
  2244. n-lines)
  2245. (org-goto-line (1+ n-lines))
  2246. (backward-char 1))
  2247. (setq txt (buffer-substring (point-min) (point)))))))))
  2248. txt))
  2249. (defun org-agenda-collect-markers ()
  2250. "Collect the markers pointing to entries in the agenda buffer."
  2251. (let (m markers)
  2252. (save-excursion
  2253. (goto-char (point-min))
  2254. (while (not (eobp))
  2255. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2256. (org-get-at-bol 'org-marker)))
  2257. (push m markers))
  2258. (beginning-of-line 2)))
  2259. (nreverse markers)))
  2260. (defun org-create-marker-find-array (marker-list)
  2261. "Create a alist of files names with all marker positions in that file."
  2262. (let (f tbl m a p)
  2263. (while (setq m (pop marker-list))
  2264. (setq p (marker-position m)
  2265. f (buffer-file-name (or (buffer-base-buffer
  2266. (marker-buffer m))
  2267. (marker-buffer m))))
  2268. (if (setq a (assoc f tbl))
  2269. (push (marker-position m) (cdr a))
  2270. (push (list f p) tbl)))
  2271. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2272. tbl)))
  2273. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2274. (defun org-check-agenda-marker-table ()
  2275. "Check of the current entry is on the marker list."
  2276. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2277. a)
  2278. (and (setq a (assoc file org-agenda-marker-table))
  2279. (save-match-data
  2280. (save-excursion
  2281. (org-back-to-heading t)
  2282. (member (point) (cdr a)))))))
  2283. (defun org-check-for-org-mode ()
  2284. "Make sure current buffer is in org-mode. Error if not."
  2285. (or (org-mode-p)
  2286. (error "Cannot execute org-mode agenda command on buffer in %s"
  2287. major-mode)))
  2288. (defun org-fit-agenda-window ()
  2289. "Fit the window to the buffer size."
  2290. (and (memq org-agenda-window-setup '(reorganize-frame))
  2291. (fboundp 'fit-window-to-buffer)
  2292. (org-fit-window-to-buffer
  2293. nil
  2294. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2295. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2296. ;;; Agenda prepare and finalize
  2297. (defvar org-agenda-multi nil) ; dynamically scoped
  2298. (defvar org-agenda-buffer-name "*Org Agenda*")
  2299. (defvar org-pre-agenda-window-conf nil)
  2300. (defvar org-agenda-columns-active nil)
  2301. (defvar org-agenda-name nil)
  2302. (defvar org-agenda-filter nil)
  2303. (defvar org-agenda-filter-preset nil
  2304. "A preset of the tags filter used for secondary agenda filtering.
  2305. This must be a list of strings, each string must be a single tag preceeded
  2306. by \"+\" or \"-\".
  2307. This variable should not be set directly, but agenda custom commands can
  2308. bind it in the options section.")
  2309. (defun org-prepare-agenda (&optional name)
  2310. (setq org-todo-keywords-for-agenda nil)
  2311. (setq org-done-keywords-for-agenda nil)
  2312. (setq org-drawers-for-agenda nil)
  2313. (setq org-agenda-filter nil)
  2314. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2315. (if org-agenda-multi
  2316. (progn
  2317. (setq buffer-read-only nil)
  2318. (goto-char (point-max))
  2319. (unless (or (bobp) org-agenda-compact-blocks)
  2320. (insert "\n"
  2321. (if (stringp org-agenda-block-separator)
  2322. org-agenda-block-separator
  2323. (make-string (window-width) org-agenda-block-separator))
  2324. "\n"))
  2325. (narrow-to-region (point) (point-max)))
  2326. (org-agenda-reset-markers)
  2327. (setq org-agenda-contributing-files nil)
  2328. (setq org-agenda-columns-active nil)
  2329. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2330. (setq org-todo-keywords-for-agenda
  2331. (org-uniquify org-todo-keywords-for-agenda))
  2332. (setq org-done-keywords-for-agenda
  2333. (org-uniquify org-done-keywords-for-agenda))
  2334. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2335. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2336. (awin (get-buffer-window abuf)))
  2337. (cond
  2338. ((equal (current-buffer) abuf) nil)
  2339. (awin (select-window awin))
  2340. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2341. ((equal org-agenda-window-setup 'current-window)
  2342. (switch-to-buffer abuf))
  2343. ((equal org-agenda-window-setup 'other-window)
  2344. (org-switch-to-buffer-other-window abuf))
  2345. ((equal org-agenda-window-setup 'other-frame)
  2346. (switch-to-buffer-other-frame abuf))
  2347. ((equal org-agenda-window-setup 'reorganize-frame)
  2348. (delete-other-windows)
  2349. (org-switch-to-buffer-other-window abuf))))
  2350. (setq buffer-read-only nil)
  2351. (let ((inhibit-read-only t)) (erase-buffer))
  2352. (org-agenda-mode)
  2353. (and name (not org-agenda-name)
  2354. (org-set-local 'org-agenda-name name)))
  2355. (setq buffer-read-only nil))
  2356. (defun org-finalize-agenda ()
  2357. "Finishing touch for the agenda buffer, called just before displaying it."
  2358. (unless org-agenda-multi
  2359. (save-excursion
  2360. (let ((inhibit-read-only t))
  2361. (goto-char (point-min))
  2362. (while (org-activate-bracket-links (point-max))
  2363. (add-text-properties (match-beginning 0) (match-end 0)
  2364. '(face org-link)))
  2365. (org-agenda-align-tags)
  2366. (unless org-agenda-with-colors
  2367. (remove-text-properties (point-min) (point-max) '(face nil))))
  2368. (if (and (boundp 'org-agenda-overriding-columns-format)
  2369. org-agenda-overriding-columns-format)
  2370. (org-set-local 'org-agenda-overriding-columns-format
  2371. org-agenda-overriding-columns-format))
  2372. (if (and (boundp 'org-agenda-view-columns-initially)
  2373. org-agenda-view-columns-initially)
  2374. (org-agenda-columns))
  2375. (when org-agenda-fontify-priorities
  2376. (org-agenda-fontify-priorities))
  2377. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2378. (org-agenda-dim-blocked-tasks))
  2379. (org-agenda-mark-clocking-task)
  2380. (when org-agenda-entry-text-mode
  2381. (org-agenda-entry-text-hide)
  2382. (org-agenda-entry-text-show))
  2383. (run-hooks 'org-finalize-agenda-hook)
  2384. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2385. (when (get 'org-agenda-filter :preset-filter)
  2386. (org-agenda-filter-apply org-agenda-filter))
  2387. )))
  2388. (defun org-agenda-mark-clocking-task ()
  2389. "Mark the current clock entry in the agenda if it is present."
  2390. (mapc (lambda (o)
  2391. (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
  2392. (org-delete-overlay o)))
  2393. (org-overlays-in (point-min) (point-max)))
  2394. (when (marker-buffer org-clock-hd-marker)
  2395. (save-excursion
  2396. (goto-char (point-min))
  2397. (let (s ov)
  2398. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2399. (goto-char s)
  2400. (when (equal (org-get-at-bol 'org-hd-marker)
  2401. org-clock-hd-marker)
  2402. (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
  2403. (org-overlay-put ov 'type 'org-agenda-clocking)
  2404. (org-overlay-put ov 'face 'org-agenda-clocking)
  2405. (org-overlay-put ov 'help-echo
  2406. "The clock is running in this item")))))))
  2407. (defun org-agenda-fontify-priorities ()
  2408. "Make highest priority lines bold, and lowest italic."
  2409. (interactive)
  2410. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
  2411. (org-delete-overlay o)))
  2412. (org-overlays-in (point-min) (point-max)))
  2413. (save-excursion
  2414. (let ((inhibit-read-only t)
  2415. b e p ov h l)
  2416. (goto-char (point-min))
  2417. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2418. (setq h (or (get-char-property (point) 'org-highest-priority)
  2419. org-highest-priority)
  2420. l (or (get-char-property (point) 'org-lowest-priority)
  2421. org-lowest-priority)
  2422. p (string-to-char (match-string 1))
  2423. b (match-beginning 0)
  2424. e (if (eq org-agenda-fontify-priorities 'cookies)
  2425. (match-end 0)
  2426. (point-at-eol))
  2427. ov (org-make-overlay b e))
  2428. (org-overlay-put
  2429. ov 'face
  2430. (cond ((cdr (assoc p org-priority-faces)))
  2431. ((and (listp org-agenda-fontify-priorities)
  2432. (cdr (assoc p org-agenda-fontify-priorities))))
  2433. ((equal p l) 'italic)
  2434. ((equal p h) 'bold)))
  2435. (org-overlay-put ov 'org-type 'org-priority)))))
  2436. (defun org-agenda-dim-blocked-tasks ()
  2437. "Dim currently blocked TODO's in the agenda display."
  2438. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
  2439. (org-delete-overlay o)))
  2440. (org-overlays-in (point-min) (point-max)))
  2441. (save-excursion
  2442. (let ((inhibit-read-only t)
  2443. (org-depend-tag-blocked nil)
  2444. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2445. org-blocked-by-checkboxes
  2446. invis1 b e p ov h l)
  2447. (goto-char (point-min))
  2448. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2449. (and pos (goto-char (1+ pos))))
  2450. (setq org-blocked-by-checkboxes nil invis1 invis)
  2451. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2452. (when (and marker
  2453. (not (with-current-buffer (marker-buffer marker)
  2454. (save-excursion
  2455. (goto-char marker)
  2456. (if (org-entry-get nil "NOBLOCKING")
  2457. t ;; Never block this entry
  2458. (run-hook-with-args-until-failure
  2459. 'org-blocker-hook
  2460. (list :type 'todo-state-change
  2461. :position marker
  2462. :from 'todo
  2463. :to 'done)))))))
  2464. (if org-blocked-by-checkboxes (setq invis1 nil))
  2465. (setq b (if invis1
  2466. (max (point-min) (1- (point-at-bol)))
  2467. (point-at-bol))
  2468. e (point-at-eol)
  2469. ov (org-make-overlay b e))
  2470. (if invis1
  2471. (org-overlay-put ov 'invisible t)
  2472. (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2473. (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
  2474. (defvar org-agenda-skip-function nil
  2475. "Function to be called at each match during agenda construction.
  2476. If this function returns nil, the current match should not be skipped.
  2477. Otherwise, the function must return a position from where the search
  2478. should be continued.
  2479. This may also be a Lisp form, it will be evaluated.
  2480. Never set this variable using `setq' or so, because then it will apply
  2481. to all future agenda commands. Instead, bind it with `let' to scope
  2482. it dynamically into the agenda-constructing command. A good way to set
  2483. it is through options in org-agenda-custom-commands.")
  2484. (defun org-agenda-skip ()
  2485. "Throw to `:skip' in places that should be skipped.
  2486. Also moves point to the end of the skipped region, so that search can
  2487. continue from there."
  2488. (let ((p (point-at-bol)) to fp)
  2489. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2490. (get-text-property p :org-archived)
  2491. (org-end-of-subtree t)
  2492. (throw :skip t))
  2493. (and org-agenda-skip-comment-trees
  2494. (get-text-property p :org-comment)
  2495. (org-end-of-subtree t)
  2496. (throw :skip t))
  2497. (if (equal (char-after p) ?#) (throw :skip t))
  2498. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2499. (consp org-agenda-skip-function))
  2500. (setq to (save-excursion
  2501. (save-match-data
  2502. (if fp
  2503. (funcall org-agenda-skip-function)
  2504. (eval org-agenda-skip-function))))))
  2505. (goto-char to)
  2506. (throw :skip t))))
  2507. (defvar org-agenda-markers nil
  2508. "List of all currently active markers created by `org-agenda'.")
  2509. (defvar org-agenda-last-marker-time (org-float-time)
  2510. "Creation time of the last agenda marker.")
  2511. (defun org-agenda-new-marker (&optional pos)
  2512. "Return a new agenda marker.
  2513. Org-mode keeps a list of these markers and resets them when they are
  2514. no longer in use."
  2515. (let ((m (copy-marker (or pos (point)))))
  2516. (setq org-agenda-last-marker-time (org-float-time))
  2517. (push m org-agenda-markers)
  2518. m))
  2519. (defun org-agenda-reset-markers ()
  2520. "Reset markers created by `org-agenda'."
  2521. (while org-agenda-markers
  2522. (move-marker (pop org-agenda-markers) nil)))
  2523. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2524. "Save relative positions of markers in region."
  2525. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2526. org-agenda-markers))
  2527. ;;; Entry text mode
  2528. (defun org-agenda-entry-text-show-here ()
  2529. "Add some text from te entry as context to the current line."
  2530. (let (m txt o)
  2531. (setq m (org-get-at-bol 'org-hd-marker))
  2532. (unless (marker-buffer m)
  2533. (error "No marker points to an entry here"))
  2534. (setq txt (concat "\n" (org-no-properties
  2535. (org-agenda-get-some-entry-text
  2536. m org-agenda-entry-text-maxlines " > "))))
  2537. (when (string-match "\\S-" txt)
  2538. (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
  2539. (org-overlay-put o 'evaporate t)
  2540. (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
  2541. (org-overlay-put o 'after-string txt))))
  2542. (defun org-agenda-entry-text-show ()
  2543. "Add entry context for all agenda lines."
  2544. (interactive)
  2545. (save-excursion
  2546. (goto-char (point-max))
  2547. (beginning-of-line 1)
  2548. (while (not (bobp))
  2549. (when (org-get-at-bol 'org-hd-marker)
  2550. (org-agenda-entry-text-show-here))
  2551. (beginning-of-line 0))))
  2552. (defun org-agenda-entry-text-hide ()
  2553. "Remove any shown entry context."
  2554. (delq nil
  2555. (mapcar (lambda (o)
  2556. (if (eq (org-overlay-get o 'org-overlay-type)
  2557. 'agenda-entry-content)
  2558. (progn (org-delete-overlay o) t)))
  2559. (org-overlays-in (point-min) (point-max)))))
  2560. ;;; Agenda timeline
  2561. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2562. (defun org-timeline (&optional include-all)
  2563. "Show a time-sorted view of the entries in the current org file.
  2564. Only entries with a time stamp of today or later will be listed. With
  2565. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2566. under the current date.
  2567. If the buffer contains an active region, only check the region for
  2568. dates."
  2569. (interactive "P")
  2570. (require 'calendar)
  2571. (org-compile-prefix-format 'timeline)
  2572. (org-set-sorting-strategy 'timeline)
  2573. (let* ((dopast t)
  2574. (dotodo include-all)
  2575. (doclosed org-agenda-show-log)
  2576. (entry buffer-file-name)
  2577. (date (calendar-current-date))
  2578. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2579. (end (if (org-region-active-p) (region-end) (point-max)))
  2580. (day-numbers (org-get-all-dates beg end 'no-ranges
  2581. t doclosed ; always include today
  2582. org-timeline-show-empty-dates))
  2583. (org-deadline-warning-days 0)
  2584. (org-agenda-only-exact-dates t)
  2585. (today (time-to-days (current-time)))
  2586. (past t)
  2587. args
  2588. s e rtn d emptyp wd)
  2589. (setq org-agenda-redo-command
  2590. (list 'progn
  2591. (list 'org-switch-to-buffer-other-window (current-buffer))
  2592. (list 'org-timeline (list 'quote include-all))))
  2593. (if (not dopast)
  2594. ;; Remove past dates from the list of dates.
  2595. (setq day-numbers (delq nil (mapcar (lambda(x)
  2596. (if (>= x today) x nil))
  2597. day-numbers))))
  2598. (org-prepare-agenda (concat "Timeline "
  2599. (file-name-nondirectory buffer-file-name)))
  2600. (if doclosed (push :closed args))
  2601. (push :timestamp args)
  2602. (push :deadline args)
  2603. (push :scheduled args)
  2604. (push :sexp args)
  2605. (if dotodo (push :todo args))
  2606. (insert "Timeline of file " entry "\n")
  2607. (add-text-properties (point-min) (point)
  2608. (list 'face 'org-agenda-structure))
  2609. (org-agenda-mark-header-line (point-min))
  2610. (while (setq d (pop day-numbers))
  2611. (if (and (listp d) (eq (car d) :omitted))
  2612. (progn
  2613. (setq s (point))
  2614. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2615. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2616. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2617. (if (and (>= d today)
  2618. dopast
  2619. past)
  2620. (progn
  2621. (setq past nil)
  2622. (insert (make-string 79 ?-) "\n")))
  2623. (setq date (calendar-gregorian-from-absolute d)
  2624. wd (calendar-day-of-week date))
  2625. (setq s (point))
  2626. (setq rtn (and (not emptyp)
  2627. (apply 'org-agenda-get-day-entries entry
  2628. date args)))
  2629. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2630. (progn
  2631. (insert
  2632. (if (stringp org-agenda-format-date)
  2633. (format-time-string org-agenda-format-date
  2634. (org-time-from-absolute date))
  2635. (funcall org-agenda-format-date date))
  2636. "\n")
  2637. (put-text-property s (1- (point)) 'face
  2638. (if (member wd org-agenda-weekend-days)
  2639. 'org-agenda-date-weekend
  2640. 'org-agenda-date))
  2641. (put-text-property s (1- (point)) 'org-date-line t)
  2642. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2643. (if (equal d today)
  2644. (put-text-property s (1- (point)) 'org-today t))
  2645. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2646. (put-text-property s (1- (point)) 'day d)))))
  2647. (goto-char (point-min))
  2648. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2649. (point-min)))
  2650. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2651. (org-finalize-agenda)
  2652. (setq buffer-read-only t)))
  2653. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2654. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2655. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2656. not every single day in the range. If FORCE-TODAY is non-nil, make
  2657. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2658. inactive time stamps (those in square brackets) are included.
  2659. When EMPTY is non-nil, also include days without any entries."
  2660. (let ((re (concat
  2661. (if pre-re pre-re "")
  2662. (if inactive org-ts-regexp-both org-ts-regexp)))
  2663. dates dates1 date day day1 day2 ts1 ts2)
  2664. (if force-today
  2665. (setq dates (list (time-to-days (current-time)))))
  2666. (save-excursion
  2667. (goto-char beg)
  2668. (while (re-search-forward re end t)
  2669. (setq day (time-to-days (org-time-string-to-time
  2670. (substring (match-string 1) 0 10))))
  2671. (or (memq day dates) (push day dates)))
  2672. (unless no-ranges
  2673. (goto-char beg)
  2674. (while (re-search-forward org-tr-regexp end t)
  2675. (setq ts1 (substring (match-string 1) 0 10)
  2676. ts2 (substring (match-string 2) 0 10)
  2677. day1 (time-to-days (org-time-string-to-time ts1))
  2678. day2 (time-to-days (org-time-string-to-time ts2)))
  2679. (while (< (setq day1 (1+ day1)) day2)
  2680. (or (memq day1 dates) (push day1 dates)))))
  2681. (setq dates (sort dates '<))
  2682. (when empty
  2683. (while (setq day (pop dates))
  2684. (setq day2 (car dates))
  2685. (push day dates1)
  2686. (when (and day2 empty)
  2687. (if (or (eq empty t)
  2688. (and (numberp empty) (<= (- day2 day) empty)))
  2689. (while (< (setq day (1+ day)) day2)
  2690. (push (list day) dates1))
  2691. (push (cons :omitted (- day2 day)) dates1))))
  2692. (setq dates (nreverse dates1)))
  2693. dates)))
  2694. ;;; Agenda Daily/Weekly
  2695. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2696. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2697. "Custom commands can set this variable in the options section.")
  2698. (defvar org-agenda-last-arguments nil
  2699. "The arguments of the previous call to org-agenda")
  2700. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2701. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2702. (defvar org-include-all-loc nil) ; local variable
  2703. (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
  2704. ;;;###autoload
  2705. (defun org-agenda-list (&optional include-all start-day ndays)
  2706. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2707. The view will be for the current day or week, but from the overview buffer
  2708. you will be able to go to other days/weeks.
  2709. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2710. all unfinished TODO items will also be shown, before the agenda.
  2711. This feature is considered obsolete, please use the TODO list or a block
  2712. agenda instead.
  2713. With a numeric prefix argument in an interactive call, the agenda will
  2714. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2715. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2716. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2717. given in `org-agenda-start-on-weekday'."
  2718. (interactive "P")
  2719. (if (and (integerp include-all) (> include-all 0))
  2720. (setq ndays include-all include-all nil))
  2721. (setq ndays (or ndays org-agenda-ndays)
  2722. start-day (or start-day org-agenda-start-day))
  2723. (if org-agenda-overriding-arguments
  2724. (setq include-all (car org-agenda-overriding-arguments)
  2725. start-day (nth 1 org-agenda-overriding-arguments)
  2726. ndays (nth 2 org-agenda-overriding-arguments)))
  2727. (if (stringp start-day)
  2728. ;; Convert to an absolute day number
  2729. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2730. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2731. (org-compile-prefix-format 'agenda)
  2732. (org-set-sorting-strategy 'agenda)
  2733. (require 'calendar)
  2734. (let* ((org-agenda-start-on-weekday
  2735. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2736. org-agenda-start-on-weekday nil))
  2737. (thefiles (org-agenda-files nil 'ifmode))
  2738. (files thefiles)
  2739. (today (time-to-days
  2740. (time-subtract (current-time)
  2741. (list 0 (* 3600 org-extend-today-until) 0))))
  2742. (sd (or start-day today))
  2743. (start (if (or (null org-agenda-start-on-weekday)
  2744. (< org-agenda-ndays 7))
  2745. sd
  2746. (let* ((nt (calendar-day-of-week
  2747. (calendar-gregorian-from-absolute sd)))
  2748. (n1 org-agenda-start-on-weekday)
  2749. (d (- nt n1)))
  2750. (- sd (+ (if (< d 0) 7 0) d)))))
  2751. (day-numbers (list start))
  2752. (day-cnt 0)
  2753. (inhibit-redisplay (not debug-on-error))
  2754. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2755. clocktable-start clocktable-end)
  2756. (setq org-agenda-redo-command
  2757. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2758. ;; Make the list of days
  2759. (setq ndays (or ndays org-agenda-ndays)
  2760. nd ndays)
  2761. (while (> ndays 1)
  2762. (push (1+ (car day-numbers)) day-numbers)
  2763. (setq ndays (1- ndays)))
  2764. (setq day-numbers (nreverse day-numbers))
  2765. (setq clocktable-start (car day-numbers)
  2766. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2767. (org-prepare-agenda "Day/Week")
  2768. (org-set-local 'org-starting-day (car day-numbers))
  2769. (org-set-local 'org-include-all-loc include-all)
  2770. (org-set-local 'org-agenda-span
  2771. (org-agenda-ndays-to-span nd))
  2772. (when (and (or include-all org-agenda-include-all-todo)
  2773. (member today day-numbers))
  2774. (setq files thefiles
  2775. rtnall nil)
  2776. (while (setq file (pop files))
  2777. (catch 'nextfile
  2778. (org-check-agenda-file file)
  2779. (setq date (calendar-gregorian-from-absolute today)
  2780. rtn (org-agenda-get-day-entries
  2781. file date :todo))
  2782. (setq rtnall (append rtnall rtn))))
  2783. (when rtnall
  2784. (insert "All currently open TODO items:\n")
  2785. (add-text-properties (point-min) (1- (point))
  2786. (list 'face 'org-agenda-structure
  2787. 'short-heading "All TODO items"))
  2788. (org-agenda-mark-header-line (point-min))
  2789. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2790. (unless org-agenda-compact-blocks
  2791. (let* ((d1 (car day-numbers))
  2792. (d2 (org-last day-numbers))
  2793. (w1 (org-days-to-iso-week d1))
  2794. (w2 (org-days-to-iso-week d2)))
  2795. (setq s (point))
  2796. (if org-agenda-overriding-header
  2797. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2798. nil 'face 'org-agenda-structure) "\n")
  2799. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  2800. "-agenda"
  2801. (if (< (- d2 d1) 350)
  2802. (if (= w1 w2)
  2803. (format " (W%02d)" w1)
  2804. (format " (W%02d-W%02d)" w1 w2))
  2805. "")
  2806. ":\n")))
  2807. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  2808. 'org-date-line t))
  2809. (org-agenda-mark-header-line s))
  2810. (while (setq d (pop day-numbers))
  2811. (setq date (calendar-gregorian-from-absolute d)
  2812. wd (calendar-day-of-week date)
  2813. s (point))
  2814. (if (or (setq todayp (= d today))
  2815. (and (not start-pos) (= d sd)))
  2816. (setq start-pos (point))
  2817. (if (and start-pos (not end-pos))
  2818. (setq end-pos (point))))
  2819. (setq files thefiles
  2820. rtnall nil)
  2821. (while (setq file (pop files))
  2822. (catch 'nextfile
  2823. (org-check-agenda-file file)
  2824. (cond
  2825. ((eq org-agenda-show-log 'only)
  2826. (setq rtn (org-agenda-get-day-entries
  2827. file date :closed)))
  2828. (org-agenda-show-log
  2829. (setq rtn (org-agenda-get-day-entries
  2830. file date
  2831. :deadline :scheduled :timestamp :sexp :closed)))
  2832. (t
  2833. (setq rtn (org-agenda-get-day-entries
  2834. file date
  2835. :deadline :scheduled :sexp :timestamp))))
  2836. (setq rtnall (append rtnall rtn))))
  2837. (if org-agenda-include-diary
  2838. (let ((org-agenda-search-headline-for-time t))
  2839. (require 'diary-lib)
  2840. (setq rtn (org-get-entries-from-diary date))
  2841. (setq rtnall (append rtnall rtn))))
  2842. (if (or rtnall org-agenda-show-all-dates)
  2843. (progn
  2844. (setq day-cnt (1+ day-cnt))
  2845. (insert
  2846. (if (stringp org-agenda-format-date)
  2847. (format-time-string org-agenda-format-date
  2848. (org-time-from-absolute date))
  2849. (funcall org-agenda-format-date date))
  2850. "\n")
  2851. (put-text-property s (1- (point)) 'face
  2852. (if (member wd org-agenda-weekend-days)
  2853. 'org-agenda-date-weekend
  2854. 'org-agenda-date))
  2855. (put-text-property s (1- (point)) 'org-date-line t)
  2856. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2857. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  2858. (when todayp
  2859. (put-text-property s (1- (point)) 'org-today t)
  2860. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  2861. (if rtnall (insert
  2862. (org-finalize-agenda-entries
  2863. (org-agenda-add-time-grid-maybe
  2864. rtnall nd todayp))
  2865. "\n"))
  2866. (put-text-property s (1- (point)) 'day d)
  2867. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  2868. (when (and org-agenda-clockreport-mode clocktable-start)
  2869. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  2870. ;; the above line is to ensure the restricted range!
  2871. (p org-agenda-clockreport-parameter-plist)
  2872. tbl)
  2873. (setq p (org-plist-delete p :block))
  2874. (setq p (plist-put p :tstart clocktable-start))
  2875. (setq p (plist-put p :tend clocktable-end))
  2876. (setq p (plist-put p :scope 'agenda))
  2877. (setq tbl (apply 'org-get-clocktable p))
  2878. (insert tbl)))
  2879. (goto-char (point-min))
  2880. (or org-agenda-multi (org-fit-agenda-window))
  2881. (unless (and (pos-visible-in-window-p (point-min))
  2882. (pos-visible-in-window-p (point-max)))
  2883. (goto-char (1- (point-max)))
  2884. (recenter -1)
  2885. (if (not (pos-visible-in-window-p (or start-pos 1)))
  2886. (progn
  2887. (goto-char (or start-pos 1))
  2888. (recenter 1))))
  2889. (goto-char (or start-pos 1))
  2890. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  2891. (org-finalize-agenda)
  2892. (setq buffer-read-only t)
  2893. (message "")))
  2894. (defun org-agenda-ndays-to-span (n)
  2895. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  2896. ;;; Agenda word search
  2897. (defvar org-agenda-search-history nil)
  2898. (defvar org-todo-only nil)
  2899. (defvar org-search-syntax-table nil
  2900. "Special syntax table for org-mode search.
  2901. In this table, we have single quotes not as word constituents, to
  2902. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  2903. (defun org-search-syntax-table ()
  2904. (unless org-search-syntax-table
  2905. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  2906. (modify-syntax-entry ?' "." org-search-syntax-table)
  2907. (modify-syntax-entry ?` "." org-search-syntax-table))
  2908. org-search-syntax-table)
  2909. ;;;###autoload
  2910. (defun org-search-view (&optional todo-only string edit-at)
  2911. "Show all entries that contain words or regular expressions.
  2912. If the first character of the search string is an asterisks,
  2913. search only the headlines.
  2914. With optional prefix argument TODO-ONLY, only consider entries that are
  2915. TODO entries. The argument STRING can be used to pass a default search
  2916. string into this function. If EDIT-AT is non-nil, it means that the
  2917. user should get a chance to edit this string, with cursor at position
  2918. EDIT-AT.
  2919. The search string is broken into \"words\" by splitting at whitespace.
  2920. Depending on the variable `org-agenda-search-view-search-words-only'
  2921. and on wether the first character in the search string is \"+\" or \"-\",
  2922. The string is then interpreted either as a substrig with variable amounts
  2923. of whitespace, or as a list or individual words that should be matched.
  2924. The default is a substring match, where each space in the search string
  2925. can expand to an arbitrary amount of whitespace, including newlines.
  2926. If matching individual words, these words are then interpreted as a
  2927. boolean expression with logical AND. Words prefixed with a minus must
  2928. not occur in the entry. Words without a prefix or prefixed with a plus
  2929. must occur in the entry. Matching is case-insensitive and the words
  2930. are enclosed by word delimiters.
  2931. Words enclosed by curly braces are interpreted as regular expressions
  2932. that must or must not match in the entry.
  2933. If the search string starts with an asterisk, search only in headlines.
  2934. If (possibly after the leading star) the search string starts with an
  2935. exclamation mark, this also means to look at TODO entries only, an effect
  2936. that can also be achieved with a prefix argument.
  2937. This command searches the agenda files, and in addition the files listed
  2938. in `org-agenda-text-search-extra-files'."
  2939. (interactive "P")
  2940. (org-compile-prefix-format 'search)
  2941. (org-set-sorting-strategy 'search)
  2942. (org-prepare-agenda "SEARCH")
  2943. (let* ((props (list 'face nil
  2944. 'done-face 'org-agenda-done
  2945. 'org-not-done-regexp org-not-done-regexp
  2946. 'org-todo-regexp org-todo-regexp
  2947. 'org-complex-heading-regexp org-complex-heading-regexp
  2948. 'mouse-face 'highlight
  2949. 'keymap org-agenda-keymap
  2950. 'help-echo (format "mouse-2 or RET jump to location")))
  2951. regexp rtn rtnall files file pos
  2952. marker category tags c neg re as-words
  2953. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  2954. (unless (and (not edit-at)
  2955. (stringp string)
  2956. (string-match "\\S-" string))
  2957. (setq string (read-string "[+-]Word/{Regexp} ...: "
  2958. (cond
  2959. ((integerp edit-at) (cons string edit-at))
  2960. (edit-at string))
  2961. 'org-agenda-search-history)))
  2962. (org-set-local 'org-todo-only todo-only)
  2963. (setq org-agenda-redo-command
  2964. (list 'org-search-view (if todo-only t nil) string
  2965. '(if current-prefix-arg 1 nil)))
  2966. (setq org-agenda-query-string string)
  2967. (if (equal (string-to-char string) ?*)
  2968. (setq hdl-only t
  2969. words (substring string 1))
  2970. (setq words string))
  2971. (when (equal (string-to-char words) ?!)
  2972. (setq todo-only t
  2973. words (substring words 1)))
  2974. (if (or org-agenda-search-view-search-words-only
  2975. (member (string-to-char string) '(?- ?+)))
  2976. (setq as-words t))
  2977. (setq words (org-split-string words))
  2978. (if as-words
  2979. (mapc (lambda (w)
  2980. (setq c (string-to-char w))
  2981. (if (equal c ?-)
  2982. (setq neg t w (substring w 1))
  2983. (if (equal c ?+)
  2984. (setq neg nil w (substring w 1))
  2985. (setq neg nil)))
  2986. (if (string-match "\\`{.*}\\'" w)
  2987. (setq re (substring w 1 -1))
  2988. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
  2989. (if neg (push re regexps-) (push re regexps+)))
  2990. words)
  2991. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  2992. regexps+))
  2993. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  2994. (if (not regexps+)
  2995. (setq regexp (concat "^" org-outline-regexp))
  2996. (setq regexp (pop regexps+))
  2997. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  2998. regexp))))
  2999. (setq files (org-agenda-files nil 'ifmode))
  3000. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3001. (pop org-agenda-text-search-extra-files)
  3002. (setq files (org-add-archive-files files)))
  3003. (setq files (append files org-agenda-text-search-extra-files)
  3004. rtnall nil)
  3005. (while (setq file (pop files))
  3006. (setq ee nil)
  3007. (catch 'nextfile
  3008. (org-check-agenda-file file)
  3009. (setq buffer (if (file-exists-p file)
  3010. (org-get-agenda-file-buffer file)
  3011. (error "No such file %s" file)))
  3012. (if (not buffer)
  3013. ;; If file does not exist, make sure an error message is sent
  3014. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3015. file))))
  3016. (with-current-buffer buffer
  3017. (with-syntax-table (org-search-syntax-table)
  3018. (unless (org-mode-p)
  3019. (error "Agenda file %s is not in `org-mode'" file))
  3020. (let ((case-fold-search t))
  3021. (save-excursion
  3022. (save-restriction
  3023. (if org-agenda-restrict
  3024. (narrow-to-region org-agenda-restrict-begin
  3025. org-agenda-restrict-end)
  3026. (widen))
  3027. (goto-char (point-min))
  3028. (unless (or (org-on-heading-p)
  3029. (outline-next-heading))
  3030. (throw 'nextfile t))
  3031. (goto-char (max (point-min) (1- (point))))
  3032. (while (re-search-forward regexp nil t)
  3033. (org-back-to-heading t)
  3034. (skip-chars-forward "* ")
  3035. (setq beg (point-at-bol)
  3036. beg1 (point)
  3037. end (progn (outline-next-heading) (point)))
  3038. (catch :skip
  3039. (goto-char beg)
  3040. (org-agenda-skip)
  3041. (setq str (buffer-substring-no-properties
  3042. (point-at-bol)
  3043. (if hdl-only (point-at-eol) end)))
  3044. (mapc (lambda (wr) (when (string-match wr str)
  3045. (goto-char (1- end))
  3046. (throw :skip t)))
  3047. regexps-)
  3048. (mapc (lambda (wr) (unless (string-match wr str)
  3049. (goto-char (1- end))
  3050. (throw :skip t)))
  3051. (if todo-only
  3052. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3053. regexps+)
  3054. regexps+))
  3055. (goto-char beg)
  3056. (setq marker (org-agenda-new-marker (point))
  3057. category (org-get-category)
  3058. tags (org-get-tags-at (point))
  3059. txt (org-format-agenda-item
  3060. ""
  3061. (buffer-substring-no-properties
  3062. beg1 (point-at-eol))
  3063. category tags))
  3064. (org-add-props txt props
  3065. 'org-marker marker 'org-hd-marker marker
  3066. 'org-todo-regexp org-todo-regexp
  3067. 'org-complex-heading-regexp org-complex-heading-regexp
  3068. 'priority 1000 'org-category category
  3069. 'type "search")
  3070. (push txt ee)
  3071. (goto-char (1- end))))))))))
  3072. (setq rtn (nreverse ee))
  3073. (setq rtnall (append rtnall rtn)))
  3074. (if org-agenda-overriding-header
  3075. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3076. nil 'face 'org-agenda-structure) "\n")
  3077. (insert "Search words: ")
  3078. (add-text-properties (point-min) (1- (point))
  3079. (list 'face 'org-agenda-structure))
  3080. (setq pos (point))
  3081. (insert string "\n")
  3082. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3083. (setq pos (point))
  3084. (unless org-agenda-multi
  3085. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3086. (add-text-properties pos (1- (point))
  3087. (list 'face 'org-agenda-structure))))
  3088. (org-agenda-mark-header-line (point-min))
  3089. (when rtnall
  3090. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3091. (goto-char (point-min))
  3092. (or org-agenda-multi (org-fit-agenda-window))
  3093. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3094. (org-finalize-agenda)
  3095. (setq buffer-read-only t)))
  3096. ;;; Agenda TODO list
  3097. (defvar org-select-this-todo-keyword nil)
  3098. (defvar org-last-arg nil)
  3099. ;;;###autoload
  3100. (defun org-todo-list (arg)
  3101. "Show all TODO entries from all agenda file in a single list.
  3102. The prefix arg can be used to select a specific TODO keyword and limit
  3103. the list to these. When using \\[universal-argument], you will be prompted
  3104. for a keyword. A numeric prefix directly selects the Nth keyword in
  3105. `org-todo-keywords-1'."
  3106. (interactive "P")
  3107. (require 'calendar)
  3108. (org-compile-prefix-format 'todo)
  3109. (org-set-sorting-strategy 'todo)
  3110. (org-prepare-agenda "TODO")
  3111. (let* ((today (time-to-days (current-time)))
  3112. (date (calendar-gregorian-from-absolute today))
  3113. (kwds org-todo-keywords-for-agenda)
  3114. (completion-ignore-case t)
  3115. (org-select-this-todo-keyword
  3116. (if (stringp arg) arg
  3117. (and arg (integerp arg) (> arg 0)
  3118. (nth (1- arg) kwds))))
  3119. rtn rtnall files file pos)
  3120. (when (equal arg '(4))
  3121. (setq org-select-this-todo-keyword
  3122. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3123. (mapcar 'list kwds) nil nil)))
  3124. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3125. (org-set-local 'org-last-arg arg)
  3126. (setq org-agenda-redo-command
  3127. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3128. (setq files (org-agenda-files nil 'ifmode)
  3129. rtnall nil)
  3130. (while (setq file (pop files))
  3131. (catch 'nextfile
  3132. (org-check-agenda-file file)
  3133. (setq rtn (org-agenda-get-day-entries file date :todo))
  3134. (setq rtnall (append rtnall rtn))))
  3135. (if org-agenda-overriding-header
  3136. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3137. nil 'face 'org-agenda-structure) "\n")
  3138. (insert "Global list of TODO items of type: ")
  3139. (add-text-properties (point-min) (1- (point))
  3140. (list 'face 'org-agenda-structure
  3141. 'short-heading
  3142. (concat "ToDo: "
  3143. (or org-select-this-todo-keyword "ALL"))))
  3144. (org-agenda-mark-header-line (point-min))
  3145. (setq pos (point))
  3146. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3147. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3148. (setq pos (point))
  3149. (unless org-agenda-multi
  3150. (insert "Available with `N r': (0)ALL")
  3151. (let ((n 0) s)
  3152. (mapc (lambda (x)
  3153. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3154. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3155. (insert "\n "))
  3156. (insert " " s))
  3157. kwds))
  3158. (insert "\n"))
  3159. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3160. (org-agenda-mark-header-line (point-min))
  3161. (when rtnall
  3162. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3163. (goto-char (point-min))
  3164. (or org-agenda-multi (org-fit-agenda-window))
  3165. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3166. (org-finalize-agenda)
  3167. (setq buffer-read-only t)))
  3168. ;;; Agenda tags match
  3169. ;;;###autoload
  3170. (defun org-tags-view (&optional todo-only match)
  3171. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3172. The prefix arg TODO-ONLY limits the search to TODO entries."
  3173. (interactive "P")
  3174. (org-compile-prefix-format 'tags)
  3175. (org-set-sorting-strategy 'tags)
  3176. (let* ((org-tags-match-list-sublevels
  3177. ;?????? (if todo-only t org-tags-match-list-sublevels))
  3178. org-tags-match-list-sublevels)
  3179. (completion-ignore-case t)
  3180. rtn rtnall files file pos matcher
  3181. buffer)
  3182. (setq matcher (org-make-tags-matcher match)
  3183. match (car matcher) matcher (cdr matcher))
  3184. (org-prepare-agenda (concat "TAGS " match))
  3185. (setq org-agenda-query-string match)
  3186. (setq org-agenda-redo-command
  3187. (list 'org-tags-view (list 'quote todo-only)
  3188. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3189. (setq files (org-agenda-files nil 'ifmode)
  3190. rtnall nil)
  3191. (while (setq file (pop files))
  3192. (catch 'nextfile
  3193. (org-check-agenda-file file)
  3194. (setq buffer (if (file-exists-p file)
  3195. (org-get-agenda-file-buffer file)
  3196. (error "No such file %s" file)))
  3197. (if (not buffer)
  3198. ;; If file does not exist, error message to agenda
  3199. (setq rtn (list
  3200. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3201. rtnall (append rtnall rtn))
  3202. (with-current-buffer buffer
  3203. (unless (org-mode-p)
  3204. (error "Agenda file %s is not in `org-mode'" file))
  3205. (save-excursion
  3206. (save-restriction
  3207. (if org-agenda-restrict
  3208. (narrow-to-region org-agenda-restrict-begin
  3209. org-agenda-restrict-end)
  3210. (widen))
  3211. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3212. (setq rtnall (append rtnall rtn))))))))
  3213. (if org-agenda-overriding-header
  3214. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3215. nil 'face 'org-agenda-structure) "\n")
  3216. (insert "Headlines with TAGS match: ")
  3217. (add-text-properties (point-min) (1- (point))
  3218. (list 'face 'org-agenda-structure
  3219. 'short-heading
  3220. (concat "Match: " match)))
  3221. (setq pos (point))
  3222. (insert match "\n")
  3223. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3224. (setq pos (point))
  3225. (unless org-agenda-multi
  3226. (insert "Press `C-u r' to search again with new search string\n"))
  3227. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3228. (org-agenda-mark-header-line (point-min))
  3229. (when rtnall
  3230. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3231. (goto-char (point-min))
  3232. (or org-agenda-multi (org-fit-agenda-window))
  3233. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3234. (org-finalize-agenda)
  3235. (setq buffer-read-only t)))
  3236. ;;; Agenda Finding stuck projects
  3237. (defvar org-agenda-skip-regexp nil
  3238. "Regular expression used in skipping subtrees for the agenda.
  3239. This is basically a temporary global variable that can be set and then
  3240. used by user-defined selections using `org-agenda-skip-function'.")
  3241. (defvar org-agenda-overriding-header nil
  3242. "When this is set during todo and tags searches, will replace header.
  3243. This variable should not be set directly, but custom commands can bind it
  3244. in the options section.")
  3245. (defun org-agenda-skip-entry-when-regexp-matches ()
  3246. "Checks if the current entry contains match for `org-agenda-skip-regexp'.
  3247. If yes, it returns the end position of this entry, causing agenda commands
  3248. to skip the entry but continuing the search in the subtree. This is a
  3249. function that can be put into `org-agenda-skip-function' for the duration
  3250. of a command."
  3251. (let ((end (save-excursion (org-end-of-subtree t)))
  3252. skip)
  3253. (save-excursion
  3254. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3255. (and skip end)))
  3256. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3257. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3258. If yes, it returns the end position of this tree, causing agenda commands
  3259. to skip this subtree. This is a function that can be put into
  3260. `org-agenda-skip-function' for the duration of a command."
  3261. (let ((end (save-excursion (org-end-of-subtree t)))
  3262. skip)
  3263. (save-excursion
  3264. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3265. (and skip end)))
  3266. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3267. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3268. If yes, it returns the end position of the current entry (NOT the tree),
  3269. causing agenda commands to skip the entry but continuing the search in
  3270. the subtree. This is a function that can be put into
  3271. `org-agenda-skip-function' for the duration of a command. An important
  3272. use of this function is for the stuck project list."
  3273. (let ((end (save-excursion (org-end-of-subtree t)))
  3274. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3275. skip)
  3276. (save-excursion
  3277. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3278. (and skip entry-end)))
  3279. (defun org-agenda-skip-entry-if (&rest conditions)
  3280. "Skip entry if any of CONDITIONS is true.
  3281. See `org-agenda-skip-if' for details."
  3282. (org-agenda-skip-if nil conditions))
  3283. (defun org-agenda-skip-subtree-if (&rest conditions)
  3284. "Skip entry if any of CONDITIONS is true.
  3285. See `org-agenda-skip-if' for details."
  3286. (org-agenda-skip-if t conditions))
  3287. (defun org-agenda-skip-if (subtree conditions)
  3288. "Checks current entity for CONDITIONS.
  3289. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3290. the entry, i.e. the text before the next heading is checked.
  3291. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3292. from different tests. Valid conditions are:
  3293. scheduled Check if there is a scheduled cookie
  3294. notscheduled Check if there is no scheduled cookie
  3295. deadline Check if there is a deadline
  3296. notdeadline Check if there is no deadline
  3297. timestamp Check if there is a timestamp (also deadline or scheduled)
  3298. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3299. regexp Check if regexp matches
  3300. notregexp Check if regexp does not match.
  3301. The regexp is taken from the conditions list, it must come right after
  3302. the `regexp' or `notregexp' element.
  3303. If any of these conditions is met, this function returns the end point of
  3304. the entity, causing the search to continue from there. This is a function
  3305. that can be put into `org-agenda-skip-function' for the duration of a command."
  3306. (let (beg end m)
  3307. (org-back-to-heading t)
  3308. (setq beg (point)
  3309. end (if subtree
  3310. (progn (org-end-of-subtree t) (point))
  3311. (progn (outline-next-heading) (1- (point)))))
  3312. (goto-char beg)
  3313. (and
  3314. (or
  3315. (and (memq 'scheduled conditions)
  3316. (re-search-forward org-scheduled-time-regexp end t))
  3317. (and (memq 'notscheduled conditions)
  3318. (not (re-search-forward org-scheduled-time-regexp end t)))
  3319. (and (memq 'deadline conditions)
  3320. (re-search-forward org-deadline-time-regexp end t))
  3321. (and (memq 'notdeadline conditions)
  3322. (not (re-search-forward org-deadline-time-regexp end t)))
  3323. (and (memq 'timestamp conditions)
  3324. (re-search-forward org-ts-regexp end t))
  3325. (and (memq 'nottimestamp conditions)
  3326. (not (re-search-forward org-ts-regexp end t)))
  3327. (and (setq m (memq 'regexp conditions))
  3328. (stringp (nth 1 m))
  3329. (re-search-forward (nth 1 m) end t))
  3330. (and (setq m (memq 'notregexp conditions))
  3331. (stringp (nth 1 m))
  3332. (not (re-search-forward (nth 1 m) end t))))
  3333. end)))
  3334. ;;;###autoload
  3335. (defun org-agenda-list-stuck-projects (&rest ignore)
  3336. "Create agenda view for projects that are stuck.
  3337. Stuck projects are project that have no next actions. For the definitions
  3338. of what a project is and how to check if it stuck, customize the variable
  3339. `org-stuck-projects'.
  3340. MATCH is being ignored."
  3341. (interactive)
  3342. (let* ((org-agenda-skip-function
  3343. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3344. ;; We could have used org-agenda-skip-if here.
  3345. (org-agenda-overriding-header
  3346. (or org-agenda-overriding-header "List of stuck projects: "))
  3347. (matcher (nth 0 org-stuck-projects))
  3348. (todo (nth 1 org-stuck-projects))
  3349. (todo-wds (if (member "*" todo)
  3350. (progn
  3351. (org-prepare-agenda-buffers (org-agenda-files
  3352. nil 'ifmode))
  3353. (org-delete-all
  3354. org-done-keywords-for-agenda
  3355. (copy-sequence org-todo-keywords-for-agenda)))
  3356. todo))
  3357. (todo-re (concat "^\\*+[ \t]+\\("
  3358. (mapconcat 'identity todo-wds "\\|")
  3359. "\\)\\>"))
  3360. (tags (nth 2 org-stuck-projects))
  3361. (tags-re (if (member "*" tags)
  3362. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3363. (if tags
  3364. (concat "^\\*+ .*:\\("
  3365. (mapconcat 'identity tags "\\|")
  3366. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3367. (gen-re (nth 3 org-stuck-projects))
  3368. (re-list
  3369. (delq nil
  3370. (list
  3371. (if todo todo-re)
  3372. (if tags tags-re)
  3373. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3374. gen-re)))))
  3375. (setq org-agenda-skip-regexp
  3376. (if re-list
  3377. (mapconcat 'identity re-list "\\|")
  3378. (error "No information how to identify unstuck projects")))
  3379. (org-tags-view nil matcher)
  3380. (with-current-buffer org-agenda-buffer-name
  3381. (setq org-agenda-redo-command
  3382. '(org-agenda-list-stuck-projects
  3383. (or current-prefix-arg org-last-arg))))))
  3384. ;;; Diary integration
  3385. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3386. (defvar list-diary-entries-hook)
  3387. (defun org-get-entries-from-diary (date)
  3388. "Get the (Emacs Calendar) diary entries for DATE."
  3389. (require 'diary-lib)
  3390. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3391. (fancy-diary-buffer diary-fancy-buffer)
  3392. (diary-display-hook '(fancy-diary-display))
  3393. (diary-display-function 'fancy-diary-display)
  3394. (pop-up-frames nil)
  3395. (list-diary-entries-hook
  3396. (cons 'org-diary-default-entry list-diary-entries-hook))
  3397. (diary-file-name-prefix-function nil) ; turn this feature off
  3398. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3399. entries
  3400. (org-disable-agenda-to-diary t))
  3401. (save-excursion
  3402. (save-window-excursion
  3403. (funcall (if (fboundp 'diary-list-entries)
  3404. 'diary-list-entries 'list-diary-entries)
  3405. date 1)))
  3406. (if (not (get-buffer diary-fancy-buffer))
  3407. (setq entries nil)
  3408. (with-current-buffer diary-fancy-buffer
  3409. (setq buffer-read-only nil)
  3410. (if (zerop (buffer-size))
  3411. ;; No entries
  3412. (setq entries nil)
  3413. ;; Omit the date and other unnecessary stuff
  3414. (org-agenda-cleanup-fancy-diary)
  3415. ;; Add prefix to each line and extend the text properties
  3416. (if (zerop (buffer-size))
  3417. (setq entries nil)
  3418. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3419. (set-buffer-modified-p nil)
  3420. (kill-buffer diary-fancy-buffer)))
  3421. (when entries
  3422. (setq entries (org-split-string entries "\n"))
  3423. (setq entries
  3424. (mapcar
  3425. (lambda (x)
  3426. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3427. ;; Extend the text properties to the beginning of the line
  3428. (org-add-props x (text-properties-at (1- (length x)) x)
  3429. 'type "diary" 'date date))
  3430. entries)))))
  3431. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3432. "Hook run when the fancy diary buffer is cleaned up.")
  3433. (defun org-agenda-cleanup-fancy-diary ()
  3434. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3435. This gets rid of the date, the underline under the date, and
  3436. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3437. date. It also removes lines that contain only whitespace."
  3438. (goto-char (point-min))
  3439. (if (looking-at ".*?:[ \t]*")
  3440. (progn
  3441. (replace-match "")
  3442. (re-search-forward "\n=+$" nil t)
  3443. (replace-match "")
  3444. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3445. (re-search-forward "\n=+$" nil t)
  3446. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3447. (goto-char (point-min))
  3448. (while (re-search-forward "^ +\n" nil t)
  3449. (replace-match ""))
  3450. (goto-char (point-min))
  3451. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3452. (replace-match ""))
  3453. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3454. ;; Make sure entries from the diary have the right text properties.
  3455. (eval-after-load "diary-lib"
  3456. '(if (boundp 'diary-modify-entry-list-string-function)
  3457. ;; We can rely on the hook, nothing to do
  3458. nil
  3459. ;; Hook not available, must use advice to make this work
  3460. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3461. "Make the position visible."
  3462. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3463. (stringp string)
  3464. buffer-file-name)
  3465. (setq string (org-modify-diary-entry-string string))))))
  3466. (defun org-modify-diary-entry-string (string)
  3467. "Add text properties to string, allowing org-mode to act on it."
  3468. (org-add-props string nil
  3469. 'mouse-face 'highlight
  3470. 'keymap org-agenda-keymap
  3471. 'help-echo (if buffer-file-name
  3472. (format "mouse-2 or RET jump to diary file %s"
  3473. (abbreviate-file-name buffer-file-name))
  3474. "")
  3475. 'org-agenda-diary-link t
  3476. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3477. (defun org-diary-default-entry ()
  3478. "Add a dummy entry to the diary.
  3479. Needed to avoid empty dates which mess up holiday display."
  3480. ;; Catch the error if dealing with the new add-to-diary-alist
  3481. (when org-disable-agenda-to-diary
  3482. (condition-case nil
  3483. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3484. (error
  3485. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3486. (defun org-add-to-diary-list (&rest args)
  3487. (if (fboundp 'diary-add-to-list)
  3488. (apply 'diary-add-to-list args)
  3489. (apply 'add-to-diary-list args)))
  3490. ;;;###autoload
  3491. (defun org-diary (&rest args)
  3492. "Return diary information from org-files.
  3493. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3494. It accesses org files and extracts information from those files to be
  3495. listed in the diary. The function accepts arguments specifying what
  3496. items should be listed. The following arguments are allowed:
  3497. :timestamp List the headlines of items containing a date stamp or
  3498. date range matching the selected date. Deadlines will
  3499. also be listed, on the expiration day.
  3500. :sexp List entries resulting from diary-like sexps.
  3501. :deadline List any deadlines past due, or due within
  3502. `org-deadline-warning-days'. The listing occurs only
  3503. in the diary for *today*, not at any other date. If
  3504. an entry is marked DONE, it is no longer listed.
  3505. :scheduled List all items which are scheduled for the given date.
  3506. The diary for *today* also contains items which were
  3507. scheduled earlier and are not yet marked DONE.
  3508. :todo List all TODO items from the org-file. This may be a
  3509. long list - so this is not turned on by default.
  3510. Like deadlines, these entries only show up in the
  3511. diary for *today*, not at any other date.
  3512. The call in the diary file should look like this:
  3513. &%%(org-diary) ~/path/to/some/orgfile.org
  3514. Use a separate line for each org file to check. Or, if you omit the file name,
  3515. all files listed in `org-agenda-files' will be checked automatically:
  3516. &%%(org-diary)
  3517. If you don't give any arguments (as in the example above), the default
  3518. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3519. So the example above may also be written as
  3520. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3521. The function expects the lisp variables `entry' and `date' to be provided
  3522. by the caller, because this is how the calendar works. Don't use this
  3523. function from a program - use `org-agenda-get-day-entries' instead."
  3524. (when (> (- (org-float-time)
  3525. org-agenda-last-marker-time)
  3526. 5)
  3527. (org-agenda-reset-markers))
  3528. (org-compile-prefix-format 'agenda)
  3529. (org-set-sorting-strategy 'agenda)
  3530. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3531. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3532. (list entry)
  3533. (org-agenda-files t)))
  3534. file rtn results)
  3535. (org-prepare-agenda-buffers files)
  3536. ;; If this is called during org-agenda, don't return any entries to
  3537. ;; the calendar. Org Agenda will list these entries itself.
  3538. (if org-disable-agenda-to-diary (setq files nil))
  3539. (while (setq file (pop files))
  3540. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3541. (setq results (append results rtn)))
  3542. (if results
  3543. (concat (org-finalize-agenda-entries results) "\n"))))
  3544. ;;; Agenda entry finders
  3545. (defun org-agenda-get-day-entries (file date &rest args)
  3546. "Does the work for `org-diary' and `org-agenda'.
  3547. FILE is the path to a file to be checked for entries. DATE is date like
  3548. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3549. which kind of entries should be extracted. For details about these, see
  3550. the documentation of `org-diary'."
  3551. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3552. (let* ((org-startup-folded nil)
  3553. (org-startup-align-all-tables nil)
  3554. (buffer (if (file-exists-p file)
  3555. (org-get-agenda-file-buffer file)
  3556. (error "No such file %s" file)))
  3557. arg results rtn deadline-results)
  3558. (if (not buffer)
  3559. ;; If file does not exist, make sure an error message ends up in diary
  3560. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3561. (with-current-buffer buffer
  3562. (unless (org-mode-p)
  3563. (error "Agenda file %s is not in `org-mode'" file))
  3564. (let ((case-fold-search nil))
  3565. (save-excursion
  3566. (save-restriction
  3567. (if org-agenda-restrict
  3568. (narrow-to-region org-agenda-restrict-begin
  3569. org-agenda-restrict-end)
  3570. (widen))
  3571. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3572. (while (setq arg (pop args))
  3573. (cond
  3574. ((and (eq arg :todo)
  3575. (equal date (calendar-current-date)))
  3576. (setq rtn (org-agenda-get-todos))
  3577. (setq results (append results rtn)))
  3578. ((eq arg :timestamp)
  3579. (setq rtn (org-agenda-get-blocks))
  3580. (setq results (append results rtn))
  3581. (setq rtn (org-agenda-get-timestamps))
  3582. (setq results (append results rtn)))
  3583. ((eq arg :sexp)
  3584. (setq rtn (org-agenda-get-sexps))
  3585. (setq results (append results rtn)))
  3586. ((eq arg :scheduled)
  3587. (setq rtn (org-agenda-get-scheduled deadline-results))
  3588. (setq results (append results rtn)))
  3589. ((eq arg :closed)
  3590. (setq rtn (org-agenda-get-progress))
  3591. (setq results (append results rtn)))
  3592. ((eq arg :deadline)
  3593. (setq rtn (org-agenda-get-deadlines))
  3594. (setq deadline-results (copy-sequence rtn))
  3595. (setq results (append results rtn))))))))
  3596. results))))
  3597. (defun org-agenda-get-todos ()
  3598. "Return the TODO information for agenda display."
  3599. (let* ((props (list 'face nil
  3600. 'done-face 'org-agenda-done
  3601. 'org-not-done-regexp org-not-done-regexp
  3602. 'org-todo-regexp org-todo-regexp
  3603. 'org-complex-heading-regexp org-complex-heading-regexp
  3604. 'mouse-face 'highlight
  3605. 'keymap org-agenda-keymap
  3606. 'help-echo
  3607. (format "mouse-2 or RET jump to org file %s"
  3608. (abbreviate-file-name buffer-file-name))))
  3609. (regexp (concat "^\\*+[ \t]+\\("
  3610. (if org-select-this-todo-keyword
  3611. (if (equal org-select-this-todo-keyword "*")
  3612. org-todo-regexp
  3613. (concat "\\<\\("
  3614. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3615. "\\)\\>"))
  3616. org-not-done-regexp)
  3617. "[^\n\r]*\\)"))
  3618. marker priority category tags todo-state
  3619. ee txt beg end)
  3620. (goto-char (point-min))
  3621. (while (re-search-forward regexp nil t)
  3622. (catch :skip
  3623. (save-match-data
  3624. (beginning-of-line)
  3625. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3626. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3627. (goto-char (1+ beg))
  3628. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3629. (throw :skip nil)))
  3630. (goto-char beg)
  3631. (org-agenda-skip)
  3632. (goto-char (match-beginning 1))
  3633. (setq marker (org-agenda-new-marker (match-beginning 0))
  3634. category (org-get-category)
  3635. txt (match-string 1)
  3636. tags (org-get-tags-at (point))
  3637. txt (org-format-agenda-item "" txt category tags)
  3638. priority (1+ (org-get-priority txt))
  3639. todo-state (org-get-todo-state))
  3640. (org-add-props txt props
  3641. 'org-marker marker 'org-hd-marker marker
  3642. 'priority priority 'org-category category
  3643. 'type "todo" 'todo-state todo-state)
  3644. (push txt ee)
  3645. (if org-agenda-todo-list-sublevels
  3646. (goto-char (match-end 1))
  3647. (org-end-of-subtree 'invisible))))
  3648. (nreverse ee)))
  3649. ;;;###autoload
  3650. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
  3651. "Do we have a reason to ignore this todo entry because it has a time stamp?"
  3652. (when (or org-agenda-todo-ignore-with-date
  3653. org-agenda-todo-ignore-scheduled
  3654. org-agenda-todo-ignore-deadlines)
  3655. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3656. (save-excursion
  3657. (or (and org-agenda-todo-ignore-with-date
  3658. (re-search-forward org-ts-regexp end t))
  3659. (and org-agenda-todo-ignore-scheduled
  3660. (re-search-forward org-scheduled-time-regexp end t))
  3661. (and org-agenda-todo-ignore-deadlines
  3662. (re-search-forward org-deadline-time-regexp end t)
  3663. (org-deadline-close (match-string 1)))))))
  3664. (defconst org-agenda-no-heading-message
  3665. "No heading for this item in buffer or region.")
  3666. (defun org-agenda-get-timestamps ()
  3667. "Return the date stamp information for agenda display."
  3668. (let* ((props (list 'face nil
  3669. 'org-not-done-regexp org-not-done-regexp
  3670. 'org-todo-regexp org-todo-regexp
  3671. 'org-complex-heading-regexp org-complex-heading-regexp
  3672. 'mouse-face 'highlight
  3673. 'keymap org-agenda-keymap
  3674. 'help-echo
  3675. (format "mouse-2 or RET jump to org file %s"
  3676. (abbreviate-file-name buffer-file-name))))
  3677. (d1 (calendar-absolute-from-gregorian date))
  3678. (remove-re
  3679. (concat
  3680. (regexp-quote
  3681. (format-time-string
  3682. "<%Y-%m-%d"
  3683. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  3684. ".*?>"))
  3685. (regexp
  3686. (concat
  3687. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  3688. (regexp-quote
  3689. (substring
  3690. (format-time-string
  3691. (car org-time-stamp-formats)
  3692. (apply 'encode-time ; DATE bound by calendar
  3693. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3694. 1 11))
  3695. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  3696. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  3697. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  3698. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  3699. todo-state end-of-match)
  3700. (goto-char (point-min))
  3701. (while (setq end-of-match (re-search-forward regexp nil t))
  3702. (setq b0 (match-beginning 0)
  3703. b3 (match-beginning 3) e3 (match-end 3))
  3704. (catch :skip
  3705. (and (org-at-date-range-p) (throw :skip nil))
  3706. (org-agenda-skip)
  3707. (if (and (match-end 1)
  3708. (not (= d1 (org-time-string-to-absolute
  3709. (match-string 1) d1 nil
  3710. org-agenda-repeating-timestamp-show-all))))
  3711. (throw :skip nil))
  3712. (if (and e3
  3713. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  3714. (throw :skip nil))
  3715. (setq tmp (buffer-substring (max (point-min)
  3716. (- b0 org-ds-keyword-length))
  3717. b0)
  3718. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  3719. inactivep (= (char-after b0) ?\[)
  3720. deadlinep (string-match org-deadline-regexp tmp)
  3721. scheduledp (string-match org-scheduled-regexp tmp)
  3722. closedp (and org-agenda-include-inactive-timestamps
  3723. (string-match org-closed-string tmp))
  3724. clockp (and org-agenda-include-inactive-timestamps
  3725. (or (string-match org-clock-string tmp)
  3726. (string-match "]-+\\'" tmp)))
  3727. todo-state (org-get-todo-state)
  3728. donep (member todo-state org-done-keywords))
  3729. (if (or scheduledp deadlinep closedp clockp
  3730. (and donep org-agenda-skip-timestamp-if-done))
  3731. (throw :skip t))
  3732. (if (string-match ">" timestr)
  3733. ;; substring should only run to end of time stamp
  3734. (setq timestr (substring timestr 0 (match-end 0))))
  3735. (setq marker (org-agenda-new-marker b0)
  3736. category (org-get-category b0))
  3737. (save-excursion
  3738. (if (not (re-search-backward "^\\*+ " nil t))
  3739. (setq txt org-agenda-no-heading-message)
  3740. (goto-char (match-beginning 0))
  3741. (setq hdmarker (org-agenda-new-marker)
  3742. tags (org-get-tags-at))
  3743. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3744. (setq head (match-string 1))
  3745. (setq txt (org-format-agenda-item
  3746. (if inactivep "[" nil)
  3747. head category tags timestr nil
  3748. remove-re)))
  3749. (setq priority (org-get-priority txt))
  3750. (org-add-props txt props
  3751. 'org-marker marker 'org-hd-marker hdmarker)
  3752. (org-add-props txt nil 'priority priority
  3753. 'org-category category 'date date
  3754. 'todo-state todo-state
  3755. 'type "timestamp")
  3756. (push txt ee))
  3757. (if org-agenda-skip-additional-timestamps-same-entry
  3758. (outline-next-heading)
  3759. (goto-char end-of-match))))
  3760. (nreverse ee)))
  3761. (defun org-agenda-get-sexps ()
  3762. "Return the sexp information for agenda display."
  3763. (require 'diary-lib)
  3764. (let* ((props (list 'face nil
  3765. 'mouse-face 'highlight
  3766. 'keymap org-agenda-keymap
  3767. 'help-echo
  3768. (format "mouse-2 or RET jump to org file %s"
  3769. (abbreviate-file-name buffer-file-name))))
  3770. (regexp "^&?%%(")
  3771. marker category ee txt tags entry result beg b sexp sexp-entry
  3772. todo-state)
  3773. (goto-char (point-min))
  3774. (while (re-search-forward regexp nil t)
  3775. (catch :skip
  3776. (org-agenda-skip)
  3777. (setq beg (match-beginning 0))
  3778. (goto-char (1- (match-end 0)))
  3779. (setq b (point))
  3780. (forward-sexp 1)
  3781. (setq sexp (buffer-substring b (point)))
  3782. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  3783. (org-trim (match-string 1))
  3784. ""))
  3785. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  3786. (when result
  3787. (setq marker (org-agenda-new-marker beg)
  3788. category (org-get-category beg)
  3789. todo-state (org-get-todo-state))
  3790. (if (string-match "\\S-" result)
  3791. (setq txt result)
  3792. (setq txt "SEXP entry returned empty string"))
  3793. (setq txt (org-format-agenda-item
  3794. "" txt category tags 'time))
  3795. (org-add-props txt props 'org-marker marker)
  3796. (org-add-props txt nil
  3797. 'org-category category 'date date 'todo-state todo-state
  3798. 'type "sexp")
  3799. (push txt ee))))
  3800. (nreverse ee)))
  3801. (defalias 'org-get-closed 'org-agenda-get-progress)
  3802. (defun org-agenda-get-progress ()
  3803. "Return the logged TODO entries for agenda display."
  3804. (let* ((props (list 'mouse-face 'highlight
  3805. 'org-not-done-regexp org-not-done-regexp
  3806. 'org-todo-regexp org-todo-regexp
  3807. 'org-complex-heading-regexp org-complex-heading-regexp
  3808. 'keymap org-agenda-keymap
  3809. 'help-echo
  3810. (format "mouse-2 or RET jump to org file %s"
  3811. (abbreviate-file-name buffer-file-name))))
  3812. (items (if (consp org-agenda-show-log)
  3813. org-agenda-show-log
  3814. org-agenda-log-mode-items))
  3815. (parts
  3816. (delq nil
  3817. (list
  3818. (if (memq 'closed items) (concat "\\<" org-closed-string))
  3819. (if (memq 'clock items) (concat "\\<" org-clock-string))
  3820. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  3821. (parts-re (if parts (mapconcat 'identity parts "\\|")
  3822. (error "`org-agenda-log-mode-items' is empty")))
  3823. (regexp (concat
  3824. "\\(" parts-re "\\)"
  3825. " *\\["
  3826. (regexp-quote
  3827. (substring
  3828. (format-time-string
  3829. (car org-time-stamp-formats)
  3830. (apply 'encode-time ; DATE bound by calendar
  3831. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3832. 1 11))))
  3833. (org-agenda-search-headline-for-time nil)
  3834. marker hdmarker priority category tags closedp statep clockp state
  3835. ee txt extra timestr rest clocked)
  3836. (goto-char (point-min))
  3837. (while (re-search-forward regexp nil t)
  3838. (catch :skip
  3839. (org-agenda-skip)
  3840. (setq marker (org-agenda-new-marker (match-beginning 0))
  3841. closedp (equal (match-string 1) org-closed-string)
  3842. statep (equal (string-to-char (match-string 1)) ?-)
  3843. clockp (not (or closedp statep))
  3844. state (and statep (match-string 2))
  3845. category (org-get-category (match-beginning 0))
  3846. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  3847. )
  3848. (when (string-match "\\]" timestr)
  3849. ;; substring should only run to end of time stamp
  3850. (setq rest (substring timestr (match-end 0))
  3851. timestr (substring timestr 0 (match-end 0)))
  3852. (if (and (not closedp) (not statep)
  3853. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  3854. (progn (setq timestr (concat (substring timestr 0 -1)
  3855. "-" (match-string 1 rest) "]"))
  3856. (setq clocked (match-string 2 rest)))
  3857. (setq clocked "-")))
  3858. (save-excursion
  3859. (cond
  3860. ((not org-agenda-log-mode-add-notes) (setq extra nil))
  3861. (statep
  3862. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  3863. (setq extra (match-string 1))))
  3864. (clockp
  3865. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  3866. (setq extra (match-string 1))))
  3867. (t (setq extra nil)))
  3868. (if (not (re-search-backward "^\\*+ " nil t))
  3869. (setq txt org-agenda-no-heading-message)
  3870. (goto-char (match-beginning 0))
  3871. (setq hdmarker (org-agenda-new-marker)
  3872. tags (org-get-tags-at))
  3873. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3874. (setq txt (match-string 1))
  3875. (when extra
  3876. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  3877. (setq txt (concat (substring txt 0 (match-beginning 1))
  3878. " - " extra " " (match-string 2 txt)))
  3879. (setq txt (concat txt " - " extra))))
  3880. (setq txt (org-format-agenda-item
  3881. (cond
  3882. (closedp "Closed: ")
  3883. (statep (concat "State: (" state ")"))
  3884. (t (concat "Clocked: (" clocked ")")))
  3885. txt category tags timestr)))
  3886. (setq priority 100000)
  3887. (org-add-props txt props
  3888. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  3889. 'priority priority 'org-category category
  3890. 'type "closed" 'date date
  3891. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  3892. (push txt ee))
  3893. (goto-char (point-at-eol))))
  3894. (nreverse ee)))
  3895. (defun org-agenda-get-deadlines ()
  3896. "Return the deadline information for agenda display."
  3897. (let* ((props (list 'mouse-face 'highlight
  3898. 'org-not-done-regexp org-not-done-regexp
  3899. 'org-todo-regexp org-todo-regexp
  3900. 'org-complex-heading-regexp org-complex-heading-regexp
  3901. 'keymap org-agenda-keymap
  3902. 'help-echo
  3903. (format "mouse-2 or RET jump to org file %s"
  3904. (abbreviate-file-name buffer-file-name))))
  3905. (regexp org-deadline-time-regexp)
  3906. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  3907. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  3908. d2 diff dfrac wdays pos pos1 category tags
  3909. ee txt head face s todo-state upcomingp donep timestr)
  3910. (goto-char (point-min))
  3911. (while (re-search-forward regexp nil t)
  3912. (catch :skip
  3913. (org-agenda-skip)
  3914. (setq s (match-string 1)
  3915. txt nil
  3916. pos (1- (match-beginning 1))
  3917. d2 (org-time-string-to-absolute
  3918. (match-string 1) d1 'past
  3919. org-agenda-repeating-timestamp-show-all)
  3920. diff (- d2 d1)
  3921. wdays (org-get-wdays s)
  3922. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  3923. upcomingp (and todayp (> diff 0)))
  3924. ;; When to show a deadline in the calendar:
  3925. ;; If the expiration is within wdays warning time.
  3926. ;; Past-due deadlines are only shown on the current date
  3927. (if (or (and (<= diff wdays)
  3928. (and todayp (not org-agenda-only-exact-dates)))
  3929. (= diff 0))
  3930. (save-excursion
  3931. (setq todo-state (org-get-todo-state))
  3932. (setq donep (member todo-state org-done-keywords))
  3933. (if (and donep
  3934. (or org-agenda-skip-deadline-if-done
  3935. (not (= diff 0))))
  3936. (setq txt nil)
  3937. (setq category (org-get-category))
  3938. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  3939. (setq txt org-agenda-no-heading-message)
  3940. (goto-char (match-end 0))
  3941. (setq pos1 (match-beginning 0))
  3942. (setq tags (org-get-tags-at pos1))
  3943. (setq head (buffer-substring-no-properties
  3944. (point)
  3945. (progn (skip-chars-forward "^\r\n")
  3946. (point))))
  3947. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  3948. (setq timestr
  3949. (concat (substring s (match-beginning 1)) " "))
  3950. (setq timestr 'time))
  3951. (setq txt (org-format-agenda-item
  3952. (if (= diff 0)
  3953. (car org-agenda-deadline-leaders)
  3954. (if (functionp
  3955. (nth 1 org-agenda-deadline-leaders))
  3956. (funcall
  3957. (nth 1 org-agenda-deadline-leaders)
  3958. diff date)
  3959. (format (nth 1 org-agenda-deadline-leaders)
  3960. diff)))
  3961. head category tags
  3962. (if (not (= diff 0)) nil timestr)))))
  3963. (when txt
  3964. (setq face (org-agenda-deadline-face dfrac wdays))
  3965. (org-add-props txt props
  3966. 'org-marker (org-agenda-new-marker pos)
  3967. 'org-hd-marker (org-agenda-new-marker pos1)
  3968. 'priority (+ (- diff)
  3969. (org-get-priority txt))
  3970. 'org-category category
  3971. 'todo-state todo-state
  3972. 'type (if upcomingp "upcoming-deadline" "deadline")
  3973. 'date (if upcomingp date d2)
  3974. 'face (if donep 'org-agenda-done face)
  3975. 'undone-face face 'done-face 'org-agenda-done)
  3976. (push txt ee))))))
  3977. (nreverse ee)))
  3978. (defun org-agenda-deadline-face (fraction &optional wdays)
  3979. "Return the face to displaying a deadline item.
  3980. FRACTION is what fraction of the head-warning time has passed."
  3981. (if (equal wdays 0) (setq fraction 1.))
  3982. (let ((faces org-agenda-deadline-faces) f)
  3983. (catch 'exit
  3984. (while (setq f (pop faces))
  3985. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  3986. (defun org-agenda-get-scheduled (&optional deadline-results)
  3987. "Return the scheduled information for agenda display."
  3988. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  3989. 'org-todo-regexp org-todo-regexp
  3990. 'org-complex-heading-regexp org-complex-heading-regexp
  3991. 'done-face 'org-agenda-done
  3992. 'mouse-face 'highlight
  3993. 'keymap org-agenda-keymap
  3994. 'help-echo
  3995. (format "mouse-2 or RET jump to org file %s"
  3996. (abbreviate-file-name buffer-file-name))))
  3997. (regexp org-scheduled-time-regexp)
  3998. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  3999. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4000. mm
  4001. (deadline-position-alist
  4002. (mapcar (lambda (a) (and (setq mm (get-text-property
  4003. 0 'org-hd-marker a))
  4004. (cons (marker-position mm) a)))
  4005. deadline-results))
  4006. d2 diff pos pos1 category tags donep
  4007. ee txt head pastschedp todo-state face timestr s)
  4008. (goto-char (point-min))
  4009. (while (re-search-forward regexp nil t)
  4010. (catch :skip
  4011. (org-agenda-skip)
  4012. (setq s (match-string 1)
  4013. txt nil
  4014. pos (1- (match-beginning 1))
  4015. d2 (org-time-string-to-absolute
  4016. (match-string 1) d1 'past
  4017. org-agenda-repeating-timestamp-show-all)
  4018. diff (- d2 d1))
  4019. (setq pastschedp (and todayp (< diff 0)))
  4020. ;; When to show a scheduled item in the calendar:
  4021. ;; If it is on or past the date.
  4022. (if (or (and (< diff 0)
  4023. (< (abs diff) org-scheduled-past-days)
  4024. (and todayp (not org-agenda-only-exact-dates)))
  4025. (= diff 0))
  4026. (save-excursion
  4027. (setq todo-state (org-get-todo-state))
  4028. (setq donep (member todo-state org-done-keywords))
  4029. (if (and donep
  4030. (or org-agenda-skip-scheduled-if-done
  4031. (not (= diff 0))))
  4032. (setq txt nil)
  4033. (setq category (org-get-category))
  4034. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4035. (setq txt org-agenda-no-heading-message)
  4036. (goto-char (match-end 0))
  4037. (setq pos1 (match-beginning 0))
  4038. (if (and
  4039. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4040. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4041. pastschedp))
  4042. (setq mm (assoc pos1 deadline-position-alist)))
  4043. (throw :skip nil))
  4044. (setq tags (org-get-tags-at))
  4045. (setq head (buffer-substring-no-properties
  4046. (point)
  4047. (progn (skip-chars-forward "^\r\n") (point))))
  4048. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4049. (setq timestr
  4050. (concat (substring s (match-beginning 1)) " "))
  4051. (setq timestr 'time))
  4052. (setq txt (org-format-agenda-item
  4053. (if (= diff 0)
  4054. (car org-agenda-scheduled-leaders)
  4055. (format (nth 1 org-agenda-scheduled-leaders)
  4056. (- 1 diff)))
  4057. head category tags
  4058. (if (not (= diff 0)) nil timestr)))))
  4059. (when txt
  4060. (setq face
  4061. (cond
  4062. (pastschedp 'org-scheduled-previously)
  4063. (todayp 'org-scheduled-today)
  4064. (t 'org-scheduled)))
  4065. (org-add-props txt props
  4066. 'undone-face face
  4067. 'face (if donep 'org-agenda-done face)
  4068. 'org-marker (org-agenda-new-marker pos)
  4069. 'org-hd-marker (org-agenda-new-marker pos1)
  4070. 'type (if pastschedp "past-scheduled" "scheduled")
  4071. 'date (if pastschedp d2 date)
  4072. 'priority (+ 94 (- 5 diff) (org-get-priority txt))
  4073. 'org-category category
  4074. 'todo-state todo-state)
  4075. (push txt ee))))))
  4076. (nreverse ee)))
  4077. (defun org-agenda-get-blocks ()
  4078. "Return the date-range information for agenda display."
  4079. (let* ((props (list 'face nil
  4080. 'org-not-done-regexp org-not-done-regexp
  4081. 'org-todo-regexp org-todo-regexp
  4082. 'org-complex-heading-regexp org-complex-heading-regexp
  4083. 'mouse-face 'highlight
  4084. 'keymap org-agenda-keymap
  4085. 'help-echo
  4086. (format "mouse-2 or RET jump to org file %s"
  4087. (abbreviate-file-name buffer-file-name))))
  4088. (regexp org-tr-regexp)
  4089. (d0 (calendar-absolute-from-gregorian date))
  4090. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4091. head donep)
  4092. (goto-char (point-min))
  4093. (while (re-search-forward regexp nil t)
  4094. (catch :skip
  4095. (org-agenda-skip)
  4096. (setq pos (point))
  4097. (setq timestr (match-string 0)
  4098. s1 (match-string 1)
  4099. s2 (match-string 2)
  4100. d1 (time-to-days (org-time-string-to-time s1))
  4101. d2 (time-to-days (org-time-string-to-time s2)))
  4102. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4103. ;; Only allow days between the limits, because the normal
  4104. ;; date stamps will catch the limits.
  4105. (save-excursion
  4106. (setq todo-state (org-get-todo-state))
  4107. (setq donep (member todo-state org-done-keywords))
  4108. (if (and donep org-agenda-skip-timestamp-if-done)
  4109. (throw :skip t))
  4110. (setq marker (org-agenda-new-marker (point)))
  4111. (setq category (org-get-category))
  4112. (if (not (re-search-backward "^\\*+ " nil t))
  4113. (setq txt org-agenda-no-heading-message)
  4114. (goto-char (match-beginning 0))
  4115. (setq hdmarker (org-agenda-new-marker (point)))
  4116. (setq tags (org-get-tags-at))
  4117. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4118. (setq head (match-string 1))
  4119. (setq txt (org-format-agenda-item
  4120. (format
  4121. (nth (if (= d1 d2) 0 1)
  4122. org-agenda-timerange-leaders)
  4123. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4124. head category tags
  4125. (if (= d0 d1) timestr))))
  4126. (org-add-props txt props
  4127. 'org-marker marker 'org-hd-marker hdmarker
  4128. 'type "block" 'date date
  4129. 'todo-state todo-state
  4130. 'priority (org-get-priority txt) 'org-category category)
  4131. (push txt ee)))
  4132. (goto-char pos)))
  4133. ;; Sort the entries by expiration date.
  4134. (nreverse ee)))
  4135. ;;; Agenda presentation and sorting
  4136. (defvar org-prefix-has-time nil
  4137. "A flag, set by `org-compile-prefix-format'.
  4138. The flag is set if the currently compiled format contains a `%t'.")
  4139. (defvar org-prefix-has-tag nil
  4140. "A flag, set by `org-compile-prefix-format'.
  4141. The flag is set if the currently compiled format contains a `%T'.")
  4142. (defvar org-prefix-has-effort nil
  4143. "A flag, set by `org-compile-prefix-format'.
  4144. The flag is set if the currently compiled format contains a `%e'.")
  4145. (defvar org-prefix-category-length nil
  4146. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4147. (defvar org-prefix-category-max-length nil
  4148. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4149. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4150. noprefix remove-re)
  4151. "Format TXT to be inserted into the agenda buffer.
  4152. In particular, it adds the prefix and corresponding text properties. EXTRA
  4153. must be a string and replaces the `%s' specifier in the prefix format.
  4154. CATEGORY (string, symbol or nil) may be used to overrule the default
  4155. category taken from local variable or file name. It will replace the `%c'
  4156. specifier in the format. DOTIME, when non-nil, indicates that a
  4157. time-of-day should be extracted from TXT for sorting of this entry, and for
  4158. the `%t' specifier in the format. When DOTIME is a string, this string is
  4159. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4160. only the correctly processes TXT should be returned - this is used by
  4161. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4162. Any match of REMOVE-RE will be removed from TXT."
  4163. (save-match-data
  4164. ;; Diary entries sometimes have extra whitespace at the beginning
  4165. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4166. (when org-agenda-show-inherited-tags
  4167. ;; Fix the tags part in txt
  4168. (setq txt (org-agenda-add-inherited-tags txt tags)))
  4169. (let* ((category (or category
  4170. org-category
  4171. (if buffer-file-name
  4172. (file-name-sans-extension
  4173. (file-name-nondirectory buffer-file-name))
  4174. "")))
  4175. ;; time, tag, effort are needed for the eval of the prefix format
  4176. (tag (if tags (nth (1- (length tags)) tags) ""))
  4177. time effort neffort
  4178. (ts (if dotime (concat
  4179. (if (stringp dotime) dotime "")
  4180. (and org-agenda-search-headline-for-time txt))))
  4181. (time-of-day (and dotime (org-get-time-of-day ts)))
  4182. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4183. duration thecategory)
  4184. (and (org-mode-p) buffer-file-name
  4185. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4186. (when (and dotime time-of-day)
  4187. ;; Extract starting and ending time and move them to prefix
  4188. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4189. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4190. (setq s0 (match-string 0 ts)
  4191. srp (and stamp (match-end 3))
  4192. s1 (match-string (if plain 1 2) ts)
  4193. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4194. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4195. ;; them, we might want to remove them there to avoid duplication.
  4196. ;; The user can turn this off with a variable.
  4197. (if (and org-prefix-has-time
  4198. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4199. (string-match (concat (regexp-quote s0) " *") txt)
  4200. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4201. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4202. (= (match-beginning 0) 0)
  4203. t))
  4204. (setq txt (replace-match "" nil nil txt))))
  4205. ;; Normalize the time(s) to 24 hour
  4206. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4207. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4208. ;; Compute the duration
  4209. (when s1
  4210. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4211. (string-to-number (substring s1 3)))
  4212. t2 (cond
  4213. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4214. (string-to-number (substring s2 3))))
  4215. (org-agenda-default-appointment-duration
  4216. (+ t1 org-agenda-default-appointment-duration))
  4217. (t nil)))
  4218. (setq duration (if t2 (- t2 t1)))))
  4219. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4220. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4221. (let ((m (+ (string-to-number (match-string 2 s1))
  4222. (* 60 (string-to-number (match-string 1 s1)))
  4223. org-agenda-default-appointment-duration))
  4224. h)
  4225. (setq h (/ m 60) m (- m (* h 60)))
  4226. (setq s2 (format "%02d:%02d" h m))))
  4227. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4228. txt)
  4229. ;; Tags are in the string
  4230. (if (or (eq org-agenda-remove-tags t)
  4231. (and org-agenda-remove-tags
  4232. org-prefix-has-tag))
  4233. (setq txt (replace-match "" t t txt))
  4234. (setq txt (replace-match
  4235. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4236. (match-string 2 txt))
  4237. t t txt))))
  4238. (when (org-mode-p)
  4239. (setq effort
  4240. (condition-case nil
  4241. (org-get-effort
  4242. (or (get-text-property 0 'org-hd-marker txt)
  4243. (get-text-property 0 'org-marker txt)))
  4244. (error nil)))
  4245. (when effort
  4246. (setq neffort (org-hh:mm-string-to-minutes effort)
  4247. effort (setq effort (concat "[" effort "]" )))))
  4248. (when remove-re
  4249. (while (string-match remove-re txt)
  4250. (setq txt (replace-match "" t t txt))))
  4251. ;; Create the final string
  4252. (if noprefix
  4253. (setq rtn txt)
  4254. ;; Prepare the variables needed in the eval of the compiled format
  4255. (setq time (cond (s2 (concat s1 "-" s2))
  4256. (s1 (concat s1 "......"))
  4257. (t ""))
  4258. extra (or extra "")
  4259. category (if (symbolp category) (symbol-name category) category)
  4260. thecategory (copy-sequence category))
  4261. (if (string-match org-bracket-link-regexp category)
  4262. (progn
  4263. (setq l (if (match-end 3)
  4264. (- (match-end 3) (match-beginning 3))
  4265. (- (match-end 1) (match-beginning 1))))
  4266. (when (< l (or org-prefix-category-length 0))
  4267. (setq category (copy-sequence category))
  4268. (org-add-props category nil
  4269. 'extra-space (make-string
  4270. (- org-prefix-category-length l 1) ?\ ))))
  4271. (if (and org-prefix-category-max-length
  4272. (>= (length category) org-prefix-category-max-length))
  4273. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4274. ;; Evaluate the compiled format
  4275. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4276. ;; And finally add the text properties
  4277. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4278. (org-add-props rtn nil
  4279. 'org-category (if thecategory (downcase thecategory) category)
  4280. 'tags (mapcar 'org-downcase-keep-props tags)
  4281. 'org-highest-priority org-highest-priority
  4282. 'org-lowest-priority org-lowest-priority
  4283. 'prefix-length (- (length rtn) (length txt))
  4284. 'time-of-day time-of-day
  4285. 'duration duration
  4286. 'effort effort
  4287. 'effort-minutes neffort
  4288. 'txt txt
  4289. 'time time
  4290. 'extra extra
  4291. 'dotime dotime))))
  4292. (defun org-agenda-add-inherited-tags (txt tags)
  4293. "Remove tags string from TXT, and add complete list of tags.
  4294. The new list includes inherited tags. If any inherited tags are present,
  4295. a double colon separates inherited tags from local tags."
  4296. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4297. (setq txt (substring txt 0 (match-beginning 0))))
  4298. (when tags
  4299. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4300. i)
  4301. (setq txt (concat txt " :"
  4302. (mapconcat
  4303. (lambda (x)
  4304. (setq i (get-text-property 0 'inherited x))
  4305. (if (and have-i (not i))
  4306. (progn
  4307. (setq have-i nil)
  4308. (concat ":" x))
  4309. x))
  4310. tags ":")
  4311. (if have-i "::" ":")))))
  4312. txt)
  4313. (defun org-downcase-keep-props (s)
  4314. (let ((props (text-properties-at 0 s)))
  4315. (setq s (downcase s))
  4316. (add-text-properties 0 (length s) props s)
  4317. s))
  4318. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4319. (defvar org-agenda-sorting-strategy-selected nil)
  4320. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4321. (catch 'exit
  4322. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4323. ((and todayp (member 'today (car org-agenda-time-grid))))
  4324. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4325. ((member 'weekly (car org-agenda-time-grid)))
  4326. (t (throw 'exit list)))
  4327. (let* ((have (delq nil (mapcar
  4328. (lambda (x) (get-text-property 1 'time-of-day x))
  4329. list)))
  4330. (string (nth 1 org-agenda-time-grid))
  4331. (gridtimes (nth 2 org-agenda-time-grid))
  4332. (req (car org-agenda-time-grid))
  4333. (remove (member 'remove-match req))
  4334. new time)
  4335. (if (and (member 'require-timed req) (not have))
  4336. ;; don't show empty grid
  4337. (throw 'exit list))
  4338. (while (setq time (pop gridtimes))
  4339. (unless (and remove (member time have))
  4340. (setq time (int-to-string time))
  4341. (push (org-format-agenda-item
  4342. nil string "" nil
  4343. (concat (substring time 0 -2) ":" (substring time -2)))
  4344. new)
  4345. (put-text-property
  4346. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4347. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4348. (append new list)
  4349. (append list new)))))
  4350. (defun org-compile-prefix-format (key)
  4351. "Compile the prefix format into a Lisp form that can be evaluated.
  4352. The resulting form is returned and stored in the variable
  4353. `org-prefix-format-compiled'."
  4354. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4355. org-prefix-category-length nil org-prefix-has-effort nil)
  4356. (let ((s (cond
  4357. ((stringp org-agenda-prefix-format)
  4358. org-agenda-prefix-format)
  4359. ((assq key org-agenda-prefix-format)
  4360. (cdr (assq key org-agenda-prefix-format)))
  4361. (t " %-12:c%?-12t% s")))
  4362. (start 0)
  4363. varform vars var e c f opt)
  4364. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4365. s start)
  4366. (setq var (cdr (assoc (match-string 4 s)
  4367. '(("c" . category) ("t" . time) ("s" . extra)
  4368. ("T" . tag) ("e" . effort))))
  4369. c (or (match-string 3 s) "")
  4370. opt (match-beginning 1)
  4371. start (1+ (match-beginning 0)))
  4372. (if (equal var 'time) (setq org-prefix-has-time t))
  4373. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4374. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4375. (setq f (concat "%" (match-string 2 s) "s"))
  4376. (when (equal var 'category)
  4377. (setq org-prefix-category-length
  4378. (floor (abs (string-to-number (match-string 2 s)))))
  4379. (setq org-prefix-category-max-length
  4380. (let ((x (match-string 2 s)))
  4381. (save-match-data
  4382. (if (string-match "\\.[0-9]+" x)
  4383. (string-to-number (substring (match-string 0 x) 1)))))))
  4384. (if opt
  4385. (setq varform
  4386. `(if (equal "" ,var)
  4387. ""
  4388. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4389. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4390. (setq s (replace-match "%s" t nil s))
  4391. (push varform vars))
  4392. (setq vars (nreverse vars))
  4393. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4394. (defun org-set-sorting-strategy (key)
  4395. (if (symbolp (car org-agenda-sorting-strategy))
  4396. ;; the old format
  4397. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4398. (setq org-agenda-sorting-strategy-selected
  4399. (or (cdr (assq key org-agenda-sorting-strategy))
  4400. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4401. '(time-up category-keep priority-down)))))
  4402. (defun org-get-time-of-day (s &optional string mod24)
  4403. "Check string S for a time of day.
  4404. If found, return it as a military time number between 0 and 2400.
  4405. If not found, return nil.
  4406. The optional STRING argument forces conversion into a 5 character wide string
  4407. HH:MM."
  4408. (save-match-data
  4409. (when
  4410. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4411. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4412. (let* ((h (string-to-number (match-string 1 s)))
  4413. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4414. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4415. (am-p (equal ampm "am"))
  4416. (h1 (cond ((not ampm) h)
  4417. ((= h 12) (if am-p 0 12))
  4418. (t (+ h (if am-p 0 12)))))
  4419. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4420. (mod h1 24) h1))
  4421. (t0 (+ (* 100 h2) m))
  4422. (t1 (concat (if (>= h1 24) "+" " ")
  4423. (if (< t0 100) "0" "")
  4424. (if (< t0 10) "0" "")
  4425. (int-to-string t0))))
  4426. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4427. (defun org-finalize-agenda-entries (list &optional nosort)
  4428. "Sort and concatenate the agenda items."
  4429. (setq list (mapcar 'org-agenda-highlight-todo list))
  4430. (if nosort
  4431. list
  4432. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4433. (defun org-agenda-highlight-todo (x)
  4434. (let ((org-done-keywords org-done-keywords-for-agenda)
  4435. re pl)
  4436. (if (eq x 'line)
  4437. (save-excursion
  4438. (beginning-of-line 1)
  4439. (setq re (org-get-at-bol 'org-todo-regexp))
  4440. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4441. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4442. (add-text-properties (match-beginning 0) (match-end 1)
  4443. (list 'face (org-get-todo-face 1)))
  4444. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4445. (delete-region (match-beginning 1) (1- (match-end 0)))
  4446. (goto-char (match-beginning 1))
  4447. (insert (format org-agenda-todo-keyword-format s)))))
  4448. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4449. pl (get-text-property 0 'prefix-length x))
  4450. (when (and re
  4451. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4452. x (or pl 0)) pl))
  4453. (add-text-properties
  4454. (or (match-end 1) (match-end 0)) (match-end 0)
  4455. (list 'face (org-get-todo-face (match-string 2 x)))
  4456. x)
  4457. (setq x (concat (substring x 0 (match-end 1))
  4458. (format org-agenda-todo-keyword-format
  4459. (match-string 2 x))
  4460. (org-add-props " " (text-properties-at 0 x))
  4461. (substring x (match-end 3)))))
  4462. x)))
  4463. (defsubst org-cmp-priority (a b)
  4464. "Compare the priorities of string A and B."
  4465. (let ((pa (or (get-text-property 1 'priority a) 0))
  4466. (pb (or (get-text-property 1 'priority b) 0)))
  4467. (cond ((> pa pb) +1)
  4468. ((< pa pb) -1)
  4469. (t nil))))
  4470. (defsubst org-cmp-effort (a b)
  4471. "Compare the priorities of string A and B."
  4472. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4473. (ea (or (get-text-property 1 'effort-minutes a) def))
  4474. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4475. (cond ((> ea eb) +1)
  4476. ((< ea eb) -1)
  4477. (t nil))))
  4478. (defsubst org-cmp-category (a b)
  4479. "Compare the string values of categories of strings A and B."
  4480. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4481. (cb (or (get-text-property 1 'org-category b) "")))
  4482. (cond ((string-lessp ca cb) -1)
  4483. ((string-lessp cb ca) +1)
  4484. (t nil))))
  4485. (defsubst org-cmp-todo-state (a b)
  4486. "Compare the todo states of strings A and B."
  4487. (let* ((ma (or (get-text-property 1 'org-marker a)
  4488. (get-text-property 1 'org-hd-marker a)))
  4489. (mb (or (get-text-property 1 'org-marker b)
  4490. (get-text-property 1 'org-hd-marker b)))
  4491. (fa (and ma (marker-buffer ma)))
  4492. (fb (and mb (marker-buffer mb)))
  4493. (todo-kwds
  4494. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4495. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4496. (ta (or (get-text-property 1 'todo-state a) ""))
  4497. (tb (or (get-text-property 1 'todo-state b) ""))
  4498. (la (- (length (member ta todo-kwds))))
  4499. (lb (- (length (member tb todo-kwds))))
  4500. (donepa (member ta org-done-keywords-for-agenda))
  4501. (donepb (member tb org-done-keywords-for-agenda)))
  4502. (cond ((and donepa (not donepb)) -1)
  4503. ((and (not donepa) donepb) +1)
  4504. ((< la lb) -1)
  4505. ((< lb la) +1)
  4506. (t nil))))
  4507. (defsubst org-cmp-tag (a b)
  4508. "Compare the string values of the first tags of A and B."
  4509. (let ((ta (car (last (get-text-property 1 'tags a))))
  4510. (tb (car (last (get-text-property 1 'tags b)))))
  4511. (cond ((not ta) +1)
  4512. ((not tb) -1)
  4513. ((string-lessp ta tb) -1)
  4514. ((string-lessp tb ta) +1)
  4515. (t nil))))
  4516. (defsubst org-cmp-time (a b)
  4517. "Compare the time-of-day values of strings A and B."
  4518. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4519. (ta (or (get-text-property 1 'time-of-day a) def))
  4520. (tb (or (get-text-property 1 'time-of-day b) def)))
  4521. (cond ((< ta tb) -1)
  4522. ((< tb ta) +1)
  4523. (t nil))))
  4524. (defun org-entries-lessp (a b)
  4525. "Predicate for sorting agenda entries."
  4526. ;; The following variables will be used when the form is evaluated.
  4527. ;; So even though the compiler complains, keep them.
  4528. (let* ((time-up (org-cmp-time a b))
  4529. (time-down (if time-up (- time-up) nil))
  4530. (priority-up (org-cmp-priority a b))
  4531. (priority-down (if priority-up (- priority-up) nil))
  4532. (effort-up (org-cmp-effort a b))
  4533. (effort-down (if effort-up (- effort-up) nil))
  4534. (category-up (org-cmp-category a b))
  4535. (category-down (if category-up (- category-up) nil))
  4536. (category-keep (if category-up +1 nil))
  4537. (tag-up (org-cmp-tag a b))
  4538. (tag-down (if tag-up (- tag-up) nil))
  4539. (todo-state-up (org-cmp-todo-state a b))
  4540. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4541. user-defined-up user-defined-down)
  4542. (if (and org-agenda-cmp-user-defined
  4543. (functionp org-agenda-cmp-user-defined))
  4544. (setq user-defined-up
  4545. (funcall org-agenda-cmp-user-defined a b)
  4546. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  4547. (cdr (assoc
  4548. (eval (cons 'or org-agenda-sorting-strategy-selected))
  4549. '((-1 . t) (1 . nil) (nil . nil))))))
  4550. ;;; Agenda restriction lock
  4551. (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
  4552. "Overlay to mark the headline to which arenda commands are restricted.")
  4553. (org-overlay-put org-agenda-restriction-lock-overlay
  4554. 'face 'org-agenda-restriction-lock)
  4555. (org-overlay-put org-agenda-restriction-lock-overlay
  4556. 'help-echo "Agendas are currently limited to this subtree.")
  4557. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4558. (defun org-agenda-set-restriction-lock (&optional type)
  4559. "Set restriction lock for agenda, to current subtree or file.
  4560. Restriction will be the file if TYPE is `file', or if type is the
  4561. universal prefix '(4), or if the cursor is before the first headline
  4562. in the file. Otherwise, restriction will be to the current subtree."
  4563. (interactive "P")
  4564. (and (equal type '(4)) (setq type 'file))
  4565. (setq type (cond
  4566. (type type)
  4567. ((org-at-heading-p) 'subtree)
  4568. ((condition-case nil (org-back-to-heading t) (error nil))
  4569. 'subtree)
  4570. (t 'file)))
  4571. (if (eq type 'subtree)
  4572. (progn
  4573. (setq org-agenda-restrict t)
  4574. (setq org-agenda-overriding-restriction 'subtree)
  4575. (put 'org-agenda-files 'org-restrict
  4576. (list (buffer-file-name (buffer-base-buffer))))
  4577. (org-back-to-heading t)
  4578. (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  4579. (move-marker org-agenda-restrict-begin (point))
  4580. (move-marker org-agenda-restrict-end
  4581. (save-excursion (org-end-of-subtree t)))
  4582. (message "Locking agenda restriction to subtree"))
  4583. (put 'org-agenda-files 'org-restrict
  4584. (list (buffer-file-name (buffer-base-buffer))))
  4585. (setq org-agenda-restrict nil)
  4586. (setq org-agenda-overriding-restriction 'file)
  4587. (move-marker org-agenda-restrict-begin nil)
  4588. (move-marker org-agenda-restrict-end nil)
  4589. (message "Locking agenda restriction to file"))
  4590. (setq current-prefix-arg nil)
  4591. (org-agenda-maybe-redo))
  4592. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  4593. "Remove the agenda restriction lock."
  4594. (interactive "P")
  4595. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4596. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  4597. (setq org-agenda-overriding-restriction nil)
  4598. (setq org-agenda-restrict nil)
  4599. (put 'org-agenda-files 'org-restrict nil)
  4600. (move-marker org-agenda-restrict-begin nil)
  4601. (move-marker org-agenda-restrict-end nil)
  4602. (setq current-prefix-arg nil)
  4603. (message "Agenda restriction lock removed")
  4604. (or noupdate (org-agenda-maybe-redo)))
  4605. (defun org-agenda-maybe-redo ()
  4606. "If there is any window showing the agenda view, update it."
  4607. (let ((w (get-buffer-window org-agenda-buffer-name t))
  4608. (w0 (selected-window)))
  4609. (when w
  4610. (select-window w)
  4611. (org-agenda-redo)
  4612. (select-window w0)
  4613. (if org-agenda-overriding-restriction
  4614. (message "Agenda view shifted to new %s restriction"
  4615. org-agenda-overriding-restriction)
  4616. (message "Agenda restriction lock removed")))))
  4617. ;;; Agenda commands
  4618. (defun org-agenda-check-type (error &rest types)
  4619. "Check if agenda buffer is of allowed type.
  4620. If ERROR is non-nil, throw an error, otherwise just return nil."
  4621. (if (memq org-agenda-type types)
  4622. t
  4623. (if error
  4624. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  4625. nil)))
  4626. (defun org-agenda-quit ()
  4627. "Exit agenda by removing the window or the buffer."
  4628. (interactive)
  4629. (if org-agenda-columns-active
  4630. (org-columns-quit)
  4631. (let ((buf (current-buffer)))
  4632. (if (eq org-agenda-window-setup 'other-frame)
  4633. (progn
  4634. (kill-buffer buf)
  4635. (org-agenda-reset-markers)
  4636. (org-columns-remove-overlays)
  4637. (setq org-agenda-archives-mode nil)
  4638. (delete-frame))
  4639. (and (not (eq org-agenda-window-setup 'current-window))
  4640. (not (one-window-p))
  4641. (delete-window))
  4642. (kill-buffer buf)
  4643. (org-agenda-reset-markers)
  4644. (org-columns-remove-overlays)
  4645. (setq org-agenda-archives-mode nil)))
  4646. ;; Maybe restore the pre-agenda window configuration.
  4647. (and org-agenda-restore-windows-after-quit
  4648. (not (eq org-agenda-window-setup 'other-frame))
  4649. org-pre-agenda-window-conf
  4650. (set-window-configuration org-pre-agenda-window-conf))))
  4651. (defun org-agenda-exit ()
  4652. "Exit agenda by removing the window or the buffer.
  4653. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  4654. Org-mode buffers visited directly by the user will not be touched."
  4655. (interactive)
  4656. (org-release-buffers org-agenda-new-buffers)
  4657. (setq org-agenda-new-buffers nil)
  4658. (org-agenda-quit))
  4659. (defun org-agenda-execute (arg)
  4660. "Execute another agenda command, keeping same window.\\<global-map>
  4661. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  4662. (interactive "P")
  4663. (let ((org-agenda-window-setup 'current-window))
  4664. (org-agenda arg)))
  4665. (defun org-agenda-redo ()
  4666. "Rebuild Agenda.
  4667. When this is the global TODO list, a prefix argument will be interpreted."
  4668. (interactive)
  4669. (let* ((org-agenda-keep-modes t)
  4670. (filter org-agenda-filter)
  4671. (preset (get 'org-agenda-filter :preset-filter))
  4672. (cols org-agenda-columns-active)
  4673. (line (org-current-line))
  4674. (window-line (- line (org-current-line (window-start))))
  4675. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  4676. (put 'org-agenda-filter :preset-filter nil)
  4677. (and cols (org-columns-quit))
  4678. (message "Rebuilding agenda buffer...")
  4679. (org-let lprops '(eval org-agenda-redo-command))
  4680. (setq org-agenda-undo-list nil
  4681. org-agenda-pending-undo-list nil)
  4682. (message "Rebuilding agenda buffer...done")
  4683. (put 'org-agenda-filter :preset-filter preset)
  4684. (and (or filter preset) (org-agenda-filter-apply filter))
  4685. (and cols (interactive-p) (org-agenda-columns))
  4686. (org-goto-line line)
  4687. (recenter window-line)))
  4688. (defvar org-global-tags-completion-table nil)
  4689. (defvar org-agenda-filter-form nil)
  4690. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  4691. "Keep only those lines in the agenda buffer that have a specific tag.
  4692. The tag is selected with its fast selection letter, as configured.
  4693. With prefix argument STRIP, remove all lines that do have the tag.
  4694. A lisp caller can specify CHAR. NARROW means that the new tag should be
  4695. used to narrow the search - the interactive user can also press `-' or `+'
  4696. to switch to narrowing."
  4697. (interactive "P")
  4698. (let* ((alist org-tag-alist-for-agenda)
  4699. (tag-chars (mapconcat
  4700. (lambda (x) (if (cdr x) (char-to-string (cdr x)) ""))
  4701. alist ""))
  4702. (efforts (org-split-string
  4703. (or (cdr (assoc (concat org-effort-property "_ALL")
  4704. org-global-properties))
  4705. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  4706. (effort-op org-agenda-filter-effort-default-operator)
  4707. (effort-prompt "")
  4708. (inhibit-read-only t)
  4709. (current org-agenda-filter)
  4710. char a n tag)
  4711. (unless char
  4712. (message
  4713. "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
  4714. (if narrow "Narrow" "Filter") tag-chars)
  4715. (setq char (read-char)))
  4716. (when (member char '(?+ ?-))
  4717. ;; Narrowing down
  4718. (cond ((equal char ?-) (setq strip t narrow t))
  4719. ((equal char ?+) (setq strip nil narrow t)))
  4720. (message
  4721. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  4722. (setq char (read-char)))
  4723. (when (member char '(?< ?> ?= ??))
  4724. ;; An effort operator
  4725. (setq effort-op (char-to-string char))
  4726. (setq alist nil) ; to make sure it will be interpreted as effort.
  4727. (unless (equal char ??)
  4728. (loop for i from 0 to 9 do
  4729. (setq effort-prompt
  4730. (concat
  4731. effort-prompt " ["
  4732. (if (= i 9) "0" (int-to-string (1+ i)))
  4733. "]" (nth i efforts))))
  4734. (message "Effort%s: %s " effort-op effort-prompt)
  4735. (setq char (read-char))
  4736. (when (or (< char ?0) (> char ?9))
  4737. (error "Need 1-9,0 to select effort" ))))
  4738. (when (equal char ?\t)
  4739. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  4740. (org-set-local 'org-global-tags-completion-table
  4741. (org-global-tags-completion-table)))
  4742. (let ((completion-ignore-case t))
  4743. (setq tag (org-icompleting-read
  4744. "Tag: " org-global-tags-completion-table))))
  4745. (cond
  4746. ((equal char ?/)
  4747. (org-agenda-filter-by-tag-show-all)
  4748. (when (get 'org-agenda-filter :preset-filter)
  4749. (org-agenda-filter-apply org-agenda-filter)))
  4750. ((or (equal char ?\ )
  4751. (setq a (rassoc char alist))
  4752. (and (>= char ?0) (<= char ?9)
  4753. (setq n (if (= char ?0) 9 (- char ?0 1))
  4754. tag (concat effort-op (nth n efforts))
  4755. a (cons tag nil)))
  4756. (and (= char ??)
  4757. (setq tag "?eff")
  4758. a (cons tag nil))
  4759. (and tag (setq a (cons tag nil))))
  4760. (org-agenda-filter-by-tag-show-all)
  4761. (setq tag (car a))
  4762. (setq org-agenda-filter
  4763. (cons (concat (if strip "-" "+") tag)
  4764. (if narrow current nil)))
  4765. (org-agenda-filter-apply org-agenda-filter))
  4766. (t (error "Invalid tag selection character %c" char)))))
  4767. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  4768. "Refine the current filter. See `org-agenda-filter-by-tag."
  4769. (interactive "P")
  4770. (org-agenda-filter-by-tag strip char 'refine))
  4771. (defun org-agenda-filter-make-matcher ()
  4772. "Create the form that tests a line for the agenda filter."
  4773. (let (f f1)
  4774. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  4775. org-agenda-filter))
  4776. (if (member x '("-" "+"))
  4777. (setq f1 (if (equal x "-") 'tags '(not tags)))
  4778. (if (string-match "[<=>?]" x)
  4779. (setq f1 (org-agenda-filter-effort-form x))
  4780. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  4781. (if (equal (string-to-char x) ?-)
  4782. (setq f1 (list 'not f1))))
  4783. (push f1 f))
  4784. (cons 'and (nreverse f))))
  4785. (defun org-agenda-filter-effort-form (e)
  4786. "Return the form to compare the effort of the current line with what E says.
  4787. E looks line \"+<2:25\"."
  4788. (let (op)
  4789. (setq e (substring e 1))
  4790. (setq op (string-to-char e) e (substring e 1))
  4791. (setq op (cond ((equal op ?<) '<=)
  4792. ((equal op ?>) '>=)
  4793. ((equal op ??) op)
  4794. (t '=)))
  4795. (list 'org-agenda-compare-effort (list 'quote op)
  4796. (org-hh:mm-string-to-minutes e))))
  4797. (defun org-agenda-compare-effort (op value)
  4798. "Compare the effort of the current line with VALUE, using OP.
  4799. If the line does not have an effort defined, return nil."
  4800. (let ((eff (org-get-at-bol 'effort-minutes)))
  4801. (if (equal op ??)
  4802. (not eff)
  4803. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  4804. value))))
  4805. (defun org-agenda-filter-apply (filter)
  4806. "Set FILTER as the new agenda filter and apply it."
  4807. (let (tags)
  4808. (setq org-agenda-filter filter
  4809. org-agenda-filter-form (org-agenda-filter-make-matcher))
  4810. (org-agenda-set-mode-name)
  4811. (save-excursion
  4812. (goto-char (point-min))
  4813. (while (not (eobp))
  4814. (if (org-get-at-bol 'org-marker)
  4815. (progn
  4816. (setq tags (org-get-at-bol 'tags)) ; used in eval
  4817. (if (not (eval org-agenda-filter-form))
  4818. (org-agenda-filter-by-tag-hide-line))
  4819. (beginning-of-line 2))
  4820. (beginning-of-line 2))))))
  4821. (defun org-agenda-filter-by-tag-hide-line ()
  4822. (let (ov)
  4823. (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
  4824. (point-at-eol)))
  4825. (org-overlay-put ov 'invisible t)
  4826. (org-overlay-put ov 'type 'tags-filter)
  4827. (push ov org-agenda-filter-overlays)))
  4828. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  4829. (setq pos (or pos (point)))
  4830. (save-excursion
  4831. (dolist (ov (org-overlays-at pos))
  4832. (when (and (org-overlay-get ov 'invisible)
  4833. (eq (org-overlay-get ov 'type) 'tags-filter))
  4834. (goto-char pos)
  4835. (if (< (org-overlay-start ov) (point-at-eol))
  4836. (org-move-overlay ov (point-at-eol)
  4837. (org-overlay-end ov)))))))
  4838. (defun org-agenda-filter-by-tag-show-all ()
  4839. (mapc 'org-delete-overlay org-agenda-filter-overlays)
  4840. (setq org-agenda-filter-overlays nil)
  4841. (setq org-agenda-filter nil)
  4842. (setq org-agenda-filter-form nil)
  4843. (org-agenda-set-mode-name))
  4844. (defun org-agenda-manipulate-query-add ()
  4845. "Manipulate the query by adding a search term with positive selection.
  4846. Positive selection means, the term must be matched for selection of an entry."
  4847. (interactive)
  4848. (org-agenda-manipulate-query ?\[))
  4849. (defun org-agenda-manipulate-query-subtract ()
  4850. "Manipulate the query by adding a search term with negative selection.
  4851. Negative selection means, term must not be matched for selection of an entry."
  4852. (interactive)
  4853. (org-agenda-manipulate-query ?\]))
  4854. (defun org-agenda-manipulate-query-add-re ()
  4855. "Manipulate the query by adding a search regexp with positive selection.
  4856. Positive selection means, the regexp must match for selection of an entry."
  4857. (interactive)
  4858. (org-agenda-manipulate-query ?\{))
  4859. (defun org-agenda-manipulate-query-subtract-re ()
  4860. "Manipulate the query by adding a search regexp with negative selection.
  4861. Negative selection means, regexp must not match for selection of an entry."
  4862. (interactive)
  4863. (org-agenda-manipulate-query ?\}))
  4864. (defun org-agenda-manipulate-query (char)
  4865. (cond
  4866. ((memq org-agenda-type '(timeline agenda))
  4867. (let ((org-agenda-include-inactive-timestamps t))
  4868. (org-agenda-redo))
  4869. (message "Display now includes inactive timestamps as well"))
  4870. ((eq org-agenda-type 'search)
  4871. (org-add-to-string
  4872. 'org-agenda-query-string
  4873. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  4874. (?\{ . " +{}") (?\} . " -{}")))))
  4875. (setq org-agenda-redo-command
  4876. (list 'org-search-view
  4877. org-todo-only
  4878. org-agenda-query-string
  4879. (+ (length org-agenda-query-string)
  4880. (if (member char '(?\{ ?\})) 0 1))))
  4881. (set-register org-agenda-query-register org-agenda-query-string)
  4882. (org-agenda-redo))
  4883. (t (error "Cannot manipulate query for %s-type agenda buffers"
  4884. org-agenda-type))))
  4885. (defun org-add-to-string (var string)
  4886. (set var (concat (symbol-value var) string)))
  4887. (defun org-agenda-goto-date (date)
  4888. "Jump to DATE in agenda."
  4889. (interactive (list (org-read-date)))
  4890. (org-agenda-list nil date))
  4891. (defun org-agenda-goto-today ()
  4892. "Go to today."
  4893. (interactive)
  4894. (org-agenda-check-type t 'timeline 'agenda)
  4895. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  4896. (cond
  4897. (tdpos (goto-char tdpos))
  4898. ((eq org-agenda-type 'agenda)
  4899. (let* ((sd (time-to-days
  4900. (time-subtract (current-time)
  4901. (list 0 (* 3600 org-extend-today-until) 0))))
  4902. (comp (org-agenda-compute-time-span sd org-agenda-span))
  4903. (org-agenda-overriding-arguments org-agenda-last-arguments))
  4904. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  4905. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  4906. (org-agenda-redo)
  4907. (org-agenda-find-same-or-today-or-agenda)))
  4908. (t (error "Cannot find today")))))
  4909. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  4910. (goto-char
  4911. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  4912. (text-property-any (point-min) (point-max) 'org-today t)
  4913. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  4914. (point-min))))
  4915. (defun org-agenda-later (arg)
  4916. "Go forward in time by thee current span.
  4917. With prefix ARG, go forward that many times the current span."
  4918. (interactive "p")
  4919. (org-agenda-check-type t 'agenda)
  4920. (let* ((span org-agenda-span)
  4921. (sd org-starting-day)
  4922. (greg (calendar-gregorian-from-absolute sd))
  4923. (cnt (org-get-at-bol 'org-day-cnt))
  4924. greg2 nd)
  4925. (cond
  4926. ((eq span 'day)
  4927. (setq sd (+ arg sd) nd 1))
  4928. ((eq span 'week)
  4929. (setq sd (+ (* 7 arg) sd) nd 7))
  4930. ((eq span 'month)
  4931. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  4932. sd (calendar-absolute-from-gregorian greg2))
  4933. (setcar greg2 (1+ (car greg2)))
  4934. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  4935. ((eq span 'year)
  4936. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  4937. sd (calendar-absolute-from-gregorian greg2))
  4938. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  4939. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  4940. (let ((org-agenda-overriding-arguments
  4941. (list (car org-agenda-last-arguments) sd nd t)))
  4942. (org-agenda-redo)
  4943. (org-agenda-find-same-or-today-or-agenda cnt))))
  4944. (defun org-agenda-earlier (arg)
  4945. "Go backward in time by the current span.
  4946. With prefix ARG, go backward that many times the current span."
  4947. (interactive "p")
  4948. (org-agenda-later (- arg)))
  4949. (defun org-agenda-view-mode-dispatch ()
  4950. "Call one of the view mode commands."
  4951. (interactive)
  4952. (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
  4953. clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
  4954. (let ((a (read-char-exclusive)))
  4955. (case a
  4956. (?d (call-interactively 'org-agenda-day-view))
  4957. (?w (call-interactively 'org-agenda-week-view))
  4958. (?m (call-interactively 'org-agenda-month-view))
  4959. (?y (call-interactively 'org-agenda-year-view))
  4960. (?l (call-interactively 'org-agenda-log-mode))
  4961. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  4962. (?a (call-interactively 'org-agenda-archives-mode))
  4963. (?A (org-agenda-archives-mode 'files))
  4964. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  4965. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  4966. (?G (call-interactively 'org-agenda-toggle-time-grid))
  4967. (?D (call-interactively 'org-agenda-toggle-diary))
  4968. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  4969. (org-agenda-check-type t 'timeline 'agenda)
  4970. (org-agenda-redo))
  4971. (message "Display now includes inactive timestamps as well"))
  4972. (?q (message "Abort"))
  4973. (otherwise (error "Invalid key" )))))
  4974. (defun org-agenda-day-view (&optional day-of-year)
  4975. "Switch to daily view for agenda.
  4976. With argument DAY-OF-YEAR, switch to that day of the year."
  4977. (interactive "P")
  4978. (setq org-agenda-ndays 1)
  4979. (org-agenda-change-time-span 'day day-of-year))
  4980. (defun org-agenda-week-view (&optional iso-week)
  4981. "Switch to daily view for agenda.
  4982. With argument ISO-WEEK, switch to the corresponding ISO week.
  4983. If ISO-WEEK has more then 2 digits, only the last two encode the
  4984. week. Any digits before this encode a year. So 200712 means
  4985. week 12 of year 2007. Years in the range 1938-2037 can also be
  4986. written as 2-digit years."
  4987. (interactive "P")
  4988. (setq org-agenda-ndays 7)
  4989. (org-agenda-change-time-span 'week iso-week))
  4990. (defun org-agenda-month-view (&optional month)
  4991. "Switch to monthly view for agenda.
  4992. With argument MONTH, switch to that month."
  4993. (interactive "P")
  4994. (org-agenda-change-time-span 'month month))
  4995. (defun org-agenda-year-view (&optional year)
  4996. "Switch to yearly view for agenda.
  4997. With argument YEAR, switch to that year.
  4998. If MONTH has more then 2 digits, only the last two encode the
  4999. month. Any digits before this encode a year. So 200712 means
  5000. December year 2007. Years in the range 1938-2037 can also be
  5001. written as 2-digit years."
  5002. (interactive "P")
  5003. (when year
  5004. (setq year (org-small-year-to-year year)))
  5005. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5006. (org-agenda-change-time-span 'year year)
  5007. (error "Abort")))
  5008. (defun org-agenda-change-time-span (span &optional n)
  5009. "Change the agenda view to SPAN.
  5010. SPAN may be `day', `week', `month', `year'."
  5011. (org-agenda-check-type t 'agenda)
  5012. (if (and (not n) (equal org-agenda-span span))
  5013. (error "Viewing span is already \"%s\"" span))
  5014. (let* ((sd (or (org-get-at-bol 'day)
  5015. org-starting-day))
  5016. (computed (org-agenda-compute-time-span sd span n))
  5017. (org-agenda-overriding-arguments
  5018. (list (car org-agenda-last-arguments)
  5019. (car computed) (cdr computed) t)))
  5020. (org-agenda-redo)
  5021. (org-agenda-find-same-or-today-or-agenda))
  5022. (org-agenda-set-mode-name)
  5023. (message "Switched to %s view" span))
  5024. (defun org-agenda-compute-time-span (sd span &optional n)
  5025. "Compute starting date and number of days for agenda.
  5026. SPAN may be `day', `week', `month', `year'. The return value
  5027. is a cons cell with the starting date and the number of days,
  5028. so that the date SD will be in that range."
  5029. (let* ((greg (calendar-gregorian-from-absolute sd))
  5030. (dg (nth 1 greg))
  5031. (mg (car greg))
  5032. (yg (nth 2 greg))
  5033. nd w1 y1 m1 thisweek)
  5034. (cond
  5035. ((eq span 'day)
  5036. (when n
  5037. (setq sd (+ (calendar-absolute-from-gregorian
  5038. (list mg 1 yg))
  5039. n -1)))
  5040. (setq nd 1))
  5041. ((eq span 'week)
  5042. (let* ((nt (calendar-day-of-week
  5043. (calendar-gregorian-from-absolute sd)))
  5044. (d (if org-agenda-start-on-weekday
  5045. (- nt org-agenda-start-on-weekday)
  5046. 0)))
  5047. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5048. (when n
  5049. (require 'cal-iso)
  5050. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5051. (when (> n 99)
  5052. (setq y1 (org-small-year-to-year (/ n 100))
  5053. n (mod n 100)))
  5054. (setq sd
  5055. (calendar-absolute-from-iso
  5056. (list n 1
  5057. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5058. (setq nd 7)))
  5059. ((eq span 'month)
  5060. (when (and n (> n 99))
  5061. (setq y1 (org-small-year-to-year (/ n 100))
  5062. n (mod n 100)))
  5063. (setq sd (calendar-absolute-from-gregorian
  5064. (list (or n mg) 1 (or y1 yg)))
  5065. nd (- (calendar-absolute-from-gregorian
  5066. (list (1+ (or n mg)) 1 (or y1 yg)))
  5067. sd)))
  5068. ((eq span 'year)
  5069. (setq sd (calendar-absolute-from-gregorian
  5070. (list 1 1 (or n yg)))
  5071. nd (- (calendar-absolute-from-gregorian
  5072. (list 1 1 (1+ (or n yg))))
  5073. sd))))
  5074. (cons sd nd)))
  5075. (defun org-agenda-next-date-line (&optional arg)
  5076. "Jump to the next line indicating a date in agenda buffer."
  5077. (interactive "p")
  5078. (org-agenda-check-type t 'agenda 'timeline)
  5079. (beginning-of-line 1)
  5080. ;; This does not work if user makes date format that starts with a blank
  5081. (if (looking-at "^\\S-") (forward-char 1))
  5082. (if (not (re-search-forward "^\\S-" nil t arg))
  5083. (progn
  5084. (backward-char 1)
  5085. (error "No next date after this line in this buffer")))
  5086. (goto-char (match-beginning 0)))
  5087. (defun org-agenda-previous-date-line (&optional arg)
  5088. "Jump to the previous line indicating a date in agenda buffer."
  5089. (interactive "p")
  5090. (org-agenda-check-type t 'agenda 'timeline)
  5091. (beginning-of-line 1)
  5092. (if (not (re-search-backward "^\\S-" nil t arg))
  5093. (error "No previous date before this line in this buffer")))
  5094. ;; Initialize the highlight
  5095. (defvar org-hl (org-make-overlay 1 1))
  5096. (org-overlay-put org-hl 'face 'highlight)
  5097. (defun org-highlight (begin end &optional buffer)
  5098. "Highlight a region with overlay."
  5099. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  5100. org-hl begin end (or buffer (current-buffer))))
  5101. (defun org-unhighlight ()
  5102. "Detach overlay INDEX."
  5103. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  5104. ;; FIXME this is currently not used.
  5105. (defun org-highlight-until-next-command (beg end &optional buffer)
  5106. "Move the highlight overlay to BEG/END, remove it before the next command."
  5107. (org-highlight beg end buffer)
  5108. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5109. (defun org-unhighlight-once ()
  5110. "Remove the highlight from its position, and this function from the hook."
  5111. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5112. (org-unhighlight))
  5113. (defun org-agenda-follow-mode ()
  5114. "Toggle follow mode in an agenda buffer."
  5115. (interactive)
  5116. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5117. (org-agenda-set-mode-name)
  5118. (message "Follow mode is %s"
  5119. (if org-agenda-follow-mode "on" "off")))
  5120. (defun org-agenda-entry-text-mode (&optional arg)
  5121. "Toggle entry text mode in an agenda buffer."
  5122. (interactive "P")
  5123. (if (integerp arg)
  5124. (setq org-agenda-entry-text-mode t)
  5125. (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
  5126. (org-agenda-entry-text-hide)
  5127. (and org-agenda-entry-text-mode
  5128. (let ((org-agenda-entry-text-maxlines
  5129. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5130. (org-agenda-entry-text-show)))
  5131. (org-agenda-set-mode-name)
  5132. (message "Entry text mode is %s. Maximum number of lines is %d"
  5133. (if org-agenda-entry-text-mode "on" "off")
  5134. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5135. (defun org-agenda-clockreport-mode ()
  5136. "Toggle clocktable mode in an agenda buffer."
  5137. (interactive)
  5138. (org-agenda-check-type t 'agenda)
  5139. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5140. (org-agenda-set-mode-name)
  5141. (org-agenda-redo)
  5142. (message "Clocktable mode is %s"
  5143. (if org-agenda-clockreport-mode "on" "off")))
  5144. (defun org-agenda-log-mode (&optional special)
  5145. "Toggle log mode in an agenda buffer.
  5146. With argument SPECIAL, show all possible log items, not only the ones
  5147. configured in `org-agenda-log-mode-items'.
  5148. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5149. (interactive "P")
  5150. (org-agenda-check-type t 'agenda 'timeline)
  5151. (setq org-agenda-show-log
  5152. (if (equal special '(16))
  5153. 'only
  5154. (if special '(closed clock state)
  5155. (not org-agenda-show-log))))
  5156. (org-agenda-set-mode-name)
  5157. (org-agenda-redo)
  5158. (message "Log mode is %s"
  5159. (if org-agenda-show-log "on" "off")))
  5160. (defun org-agenda-archives-mode (&optional with-files)
  5161. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5162. When called with a prefix argument, include all archive files as well."
  5163. (interactive "P")
  5164. (setq org-agenda-archives-mode
  5165. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5166. (org-agenda-set-mode-name)
  5167. (org-agenda-redo)
  5168. (message
  5169. "%s"
  5170. (cond
  5171. ((eq org-agenda-archives-mode nil)
  5172. "No archives are included")
  5173. ((eq org-agenda-archives-mode 'trees)
  5174. (format "Trees with :%s: tag are included" org-archive-tag))
  5175. ((eq org-agenda-archives-mode t)
  5176. (format "Trees with :%s: tag and all active archive files are included"
  5177. org-archive-tag)))))
  5178. (defun org-agenda-toggle-diary ()
  5179. "Toggle diary inclusion in an agenda buffer."
  5180. (interactive)
  5181. (org-agenda-check-type t 'agenda)
  5182. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5183. (org-agenda-redo)
  5184. (org-agenda-set-mode-name)
  5185. (message "Diary inclusion turned %s"
  5186. (if org-agenda-include-diary "on" "off")))
  5187. (defun org-agenda-toggle-time-grid ()
  5188. "Toggle time grid in an agenda buffer."
  5189. (interactive)
  5190. (org-agenda-check-type t 'agenda)
  5191. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5192. (org-agenda-redo)
  5193. (org-agenda-set-mode-name)
  5194. (message "Time-grid turned %s"
  5195. (if org-agenda-use-time-grid "on" "off")))
  5196. (defun org-agenda-set-mode-name ()
  5197. "Set the mode name to indicate all the small mode settings."
  5198. (setq mode-name
  5199. (concat "Org-Agenda"
  5200. (if (equal org-agenda-ndays 1) " Day" "")
  5201. (if (equal org-agenda-ndays 7) " Week" "")
  5202. (if org-agenda-follow-mode " Follow" "")
  5203. (if org-agenda-entry-text-mode " ETxt" "")
  5204. (if org-agenda-include-diary " Diary" "")
  5205. (if org-agenda-use-time-grid " Grid" "")
  5206. (if (consp org-agenda-show-log) " LogAll"
  5207. (if org-agenda-show-log " Log" ""))
  5208. (if (or org-agenda-filter (get 'org-agenda-filter
  5209. :preset-filter))
  5210. (concat " {" (mapconcat
  5211. 'identity
  5212. (append (get 'org-agenda-filter
  5213. :preset-filter)
  5214. org-agenda-filter) "") "}")
  5215. "")
  5216. (if org-agenda-archives-mode
  5217. (if (eq org-agenda-archives-mode t)
  5218. " Archives"
  5219. (format " :%s:" org-archive-tag))
  5220. "")
  5221. (if org-agenda-clockreport-mode " Clock" "")))
  5222. (force-mode-line-update))
  5223. (defun org-agenda-post-command-hook ()
  5224. (setq org-agenda-type
  5225. (or (get-text-property (point) 'org-agenda-type)
  5226. (get-text-property (max (point-min) (1- (point)))
  5227. 'org-agenda-type)))
  5228. (if (and org-agenda-follow-mode
  5229. (org-get-at-bol 'org-marker))
  5230. (org-agenda-show)))
  5231. (defun org-agenda-show-priority ()
  5232. "Show the priority of the current item.
  5233. This priority is composed of the main priority given with the [#A] cookies,
  5234. and by additional input from the age of a schedules or deadline entry."
  5235. (interactive)
  5236. (let* ((pri (org-get-at-bol 'priority)))
  5237. (message "Priority is %d" (if pri pri -1000))))
  5238. (defun org-agenda-show-tags ()
  5239. "Show the tags applicable to the current item."
  5240. (interactive)
  5241. (let* ((tags (org-get-at-bol 'tags)))
  5242. (if tags
  5243. (message "Tags are :%s:"
  5244. (org-no-properties (mapconcat 'identity tags ":")))
  5245. (message "No tags associated with this line"))))
  5246. (defun org-agenda-goto (&optional highlight)
  5247. "Go to the Org-mode file which contains the item at point."
  5248. (interactive)
  5249. (let* ((marker (or (org-get-at-bol 'org-marker)
  5250. (org-agenda-error)))
  5251. (buffer (marker-buffer marker))
  5252. (pos (marker-position marker)))
  5253. (switch-to-buffer-other-window buffer)
  5254. (widen)
  5255. (goto-char pos)
  5256. (when (org-mode-p)
  5257. (org-show-context 'agenda)
  5258. (save-excursion
  5259. (and (outline-next-heading)
  5260. (org-flag-heading nil)))) ; show the next heading
  5261. (recenter (/ (window-height) 2))
  5262. (run-hooks 'org-agenda-after-show-hook)
  5263. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5264. (defvar org-agenda-after-show-hook nil
  5265. "Normal hook run after an item has been shown from the agenda.
  5266. Point is in the buffer where the item originated.")
  5267. (defun org-agenda-kill ()
  5268. "Kill the entry or subtree belonging to the current agenda entry."
  5269. (interactive)
  5270. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5271. (let* ((marker (or (org-get-at-bol 'org-marker)
  5272. (org-agenda-error)))
  5273. (buffer (marker-buffer marker))
  5274. (pos (marker-position marker))
  5275. (type (org-get-at-bol 'type))
  5276. dbeg dend (n 0) conf)
  5277. (org-with-remote-undo buffer
  5278. (with-current-buffer buffer
  5279. (save-excursion
  5280. (goto-char pos)
  5281. (if (and (org-mode-p) (not (member type '("sexp"))))
  5282. (setq dbeg (progn (org-back-to-heading t) (point))
  5283. dend (org-end-of-subtree t t))
  5284. (setq dbeg (point-at-bol)
  5285. dend (min (point-max) (1+ (point-at-eol)))))
  5286. (goto-char dbeg)
  5287. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5288. (setq conf (or (eq t org-agenda-confirm-kill)
  5289. (and (numberp org-agenda-confirm-kill)
  5290. (> n org-agenda-confirm-kill))))
  5291. (and conf
  5292. (not (y-or-n-p
  5293. (format "Delete entry with %d lines in buffer \"%s\"? "
  5294. n (buffer-name buffer))))
  5295. (error "Abort"))
  5296. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5297. (with-current-buffer buffer (delete-region dbeg dend))
  5298. (message "Agenda item and source killed"))))
  5299. (defun org-agenda-archive ()
  5300. "Archive the entry or subtree belonging to the current agenda entry."
  5301. (interactive)
  5302. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5303. (let* ((marker (or (org-get-at-bol 'org-marker)
  5304. (org-agenda-error)))
  5305. (buffer (marker-buffer marker))
  5306. (pos (marker-position marker)))
  5307. (org-with-remote-undo buffer
  5308. (with-current-buffer buffer
  5309. (if (org-mode-p)
  5310. (save-excursion
  5311. (goto-char pos)
  5312. (org-remove-subtree-entries-from-agenda)
  5313. (org-back-to-heading t)
  5314. (org-archive-subtree))
  5315. (error "Archiving works only in Org-mode files"))))))
  5316. (defun org-agenda-archive-to-archive-sibling ()
  5317. "Move the entry to the archive sibling."
  5318. (interactive)
  5319. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5320. (let* ((marker (or (org-get-at-bol 'org-marker)
  5321. (org-agenda-error)))
  5322. (buffer (marker-buffer marker))
  5323. (pos (marker-position marker)))
  5324. (org-with-remote-undo buffer
  5325. (with-current-buffer buffer
  5326. (if (org-mode-p)
  5327. (save-excursion
  5328. (goto-char pos)
  5329. (org-remove-subtree-entries-from-agenda)
  5330. (org-back-to-heading t)
  5331. (org-archive-to-archive-sibling))
  5332. (error "Archiving works only in Org-mode files"))))))
  5333. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5334. "Remove all lines in the agenda that correspond to a given subtree.
  5335. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5336. If this information is not given, the function uses the tree at point."
  5337. (let ((buf (or buf (current-buffer))) m p)
  5338. (save-excursion
  5339. (unless (and beg end)
  5340. (org-back-to-heading t)
  5341. (setq beg (point))
  5342. (org-end-of-subtree t)
  5343. (setq end (point)))
  5344. (set-buffer (get-buffer org-agenda-buffer-name))
  5345. (save-excursion
  5346. (goto-char (point-max))
  5347. (beginning-of-line 1)
  5348. (while (not (bobp))
  5349. (when (and (setq m (org-get-at-bol 'org-marker))
  5350. (equal buf (marker-buffer m))
  5351. (setq p (marker-position m))
  5352. (>= p beg)
  5353. (< p end))
  5354. (let ((inhibit-read-only t))
  5355. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5356. (beginning-of-line 0))))))
  5357. (defun org-agenda-refile (&optional goto rfloc)
  5358. "Refile the item at point."
  5359. (interactive "P")
  5360. (if (equal goto '(16))
  5361. (org-refile-goto-last-stored)
  5362. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5363. (org-agenda-error)))
  5364. (buffer (marker-buffer marker))
  5365. (pos (marker-position marker))
  5366. (rfloc (or rfloc
  5367. (org-refile-get-location
  5368. (if goto "Goto: " "Refile to: ") buffer
  5369. org-refile-allow-creating-parent-nodes))))
  5370. (with-current-buffer buffer
  5371. (save-excursion
  5372. (save-restriction
  5373. (widen)
  5374. (goto-char marker)
  5375. (org-remove-subtree-entries-from-agenda)
  5376. (org-refile goto buffer rfloc)))))))
  5377. (defun org-agenda-open-link (&optional arg)
  5378. "Follow the link in the current line, if any.
  5379. This looks for a link in the displayed lin in the agenda. It also looks
  5380. at the text of the entry itself."
  5381. (interactive "P")
  5382. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5383. (org-get-at-bol 'org-marker)))
  5384. (buffer (and marker (marker-buffer marker)))
  5385. (prefix (buffer-substring
  5386. (point-at-bol)
  5387. (+ (point-at-bol)
  5388. (org-get-at-bol 'prefix-length)))))
  5389. (unless buffer (error "Don't know where to look for links"))
  5390. (with-current-buffer buffer
  5391. (save-excursion
  5392. (save-restriction
  5393. (widen)
  5394. (goto-char marker)
  5395. (org-offer-links-in-entry arg prefix))))))
  5396. (defun org-agenda-copy-local-variable (var)
  5397. "Get a variable from a referenced buffer and install it here."
  5398. (let ((m (org-get-at-bol 'org-marker)))
  5399. (when (and m (buffer-live-p (marker-buffer m)))
  5400. (org-set-local var (with-current-buffer (marker-buffer m)
  5401. (symbol-value var))))))
  5402. (defun org-agenda-switch-to (&optional delete-other-windows)
  5403. "Go to the Org-mode file which contains the item at point."
  5404. (interactive)
  5405. (let* ((marker (or (org-get-at-bol 'org-marker)
  5406. (org-agenda-error)))
  5407. (buffer (marker-buffer marker))
  5408. (pos (marker-position marker)))
  5409. (switch-to-buffer buffer)
  5410. (and delete-other-windows (delete-other-windows))
  5411. (widen)
  5412. (goto-char pos)
  5413. (when (org-mode-p)
  5414. (org-show-context 'agenda)
  5415. (save-excursion
  5416. (and (outline-next-heading)
  5417. (org-flag-heading nil)))))) ; show the next heading
  5418. (defun org-agenda-goto-mouse (ev)
  5419. "Go to the Org-mode file which contains the item at the mouse click."
  5420. (interactive "e")
  5421. (mouse-set-point ev)
  5422. (org-agenda-goto))
  5423. (defun org-agenda-show (&optional full-entry)
  5424. "Display the Org-mode file which contains the item at point.
  5425. With prefix argument FULL-ENTRY, make the entire entry visible
  5426. if it was hidden in the outline."
  5427. (interactive "P")
  5428. (let ((win (selected-window)))
  5429. (if full-entry
  5430. (let ((org-show-entry-below t))
  5431. (org-agenda-goto t))
  5432. (org-agenda-goto t))
  5433. (select-window win)))
  5434. (defun org-agenda-show-1 (&optional more)
  5435. "Display the Org-mode file which contains the item at point.
  5436. The prefix arg causes further revieling:
  5437. 0 hide the subtree
  5438. 1 just show the entry according to defaults.
  5439. 2 show the children view
  5440. 3 show the subtree view
  5441. 4 show the entire subtree and any LOGBOOK drawers
  5442. 5 show the entire subtree and any drawers
  5443. With prefix argument FULL-ENTRY, make the entire entry visible
  5444. if it was hidden in the outline."
  5445. (interactive "p")
  5446. (let ((win (selected-window)))
  5447. (org-agenda-goto t)
  5448. (org-recenter-heading 1)
  5449. (cond
  5450. ((= more 0)
  5451. (hide-subtree)
  5452. (save-excursion
  5453. (org-back-to-heading)
  5454. (run-hook-with-args 'org-cycle-hook 'folded))
  5455. (message "Remote: FOLDED"))
  5456. ((and (interactive-p) (= more 1))
  5457. (message "Remote: show with default settings"))
  5458. ((= more 2)
  5459. (show-entry)
  5460. (show-children)
  5461. (save-excursion
  5462. (org-back-to-heading)
  5463. (run-hook-with-args 'org-cycle-hook 'children))
  5464. (message "Remote: CHILDREN"))
  5465. ((= more 3)
  5466. (show-subtree)
  5467. (save-excursion
  5468. (org-back-to-heading)
  5469. (run-hook-with-args 'org-cycle-hook 'subtree))
  5470. (message "Remote: SUBTREE"))
  5471. ((= more 4)
  5472. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  5473. (org-drawer-regexp
  5474. (concat "^[ \t]*:\\("
  5475. (mapconcat 'regexp-quote org-drawers "\\|")
  5476. "\\):[ \t]*$")))
  5477. (show-subtree)
  5478. (save-excursion
  5479. (org-back-to-heading)
  5480. (org-cycle-hide-drawers 'subtree)))
  5481. (message "Remote: SUBTREE AND LOGBOOK"))
  5482. ((> more 4)
  5483. (show-subtree)
  5484. (message "Remote: SUBTREE AND ALL DRAWERS")))
  5485. (select-window win)))
  5486. (defun org-recenter-heading (n)
  5487. (save-excursion
  5488. (org-back-to-heading)
  5489. (recenter n)))
  5490. (defvar org-agenda-cycle-counter nil)
  5491. (defun org-agenda-cycle-show (&optional n)
  5492. "Show the current entry in another window, with default settings.
  5493. Default settings are taken from `org-show-hierarchy-above' and siblings.
  5494. When use repeatedly in immediate succession, the remote entry will cycle
  5495. through visibility
  5496. children -> subtree -> folded
  5497. When called with a numeric prefix arg, that arg will be passed through to
  5498. `org-agenda-show-1'. For the interpretation of that argument, see the
  5499. docstring of `org-agenda-show-1'."
  5500. (interactive "P")
  5501. (if (integerp n)
  5502. (setq org-agenda-cycle-counter n)
  5503. (if (not (eq last-command this-command))
  5504. (setq org-agenda-cycle-counter 1)
  5505. (if (equal org-agenda-cycle-counter 0)
  5506. (setq org-agenda-cycle-counter 2)
  5507. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  5508. (if (> org-agenda-cycle-counter 3)
  5509. (setq org-agenda-cycle-counter 0)))))
  5510. (org-agenda-show-1 org-agenda-cycle-counter))
  5511. (defun org-agenda-recenter (arg)
  5512. "Display the Org-mode file which contains the item at point and recenter."
  5513. (interactive "P")
  5514. (let ((win (selected-window)))
  5515. (org-agenda-goto t)
  5516. (recenter arg)
  5517. (select-window win)))
  5518. (defun org-agenda-show-mouse (ev)
  5519. "Display the Org-mode file which contains the item at the mouse click."
  5520. (interactive "e")
  5521. (mouse-set-point ev)
  5522. (org-agenda-show))
  5523. (defun org-agenda-check-no-diary ()
  5524. "Check if the entry is a diary link and abort if yes."
  5525. (if (org-get-at-bol 'org-agenda-diary-link)
  5526. (org-agenda-error)))
  5527. (defun org-agenda-error ()
  5528. (error "Command not allowed in this line"))
  5529. (defun org-agenda-tree-to-indirect-buffer ()
  5530. "Show the subtree corresponding to the current entry in an indirect buffer.
  5531. This calls the command `org-tree-to-indirect-buffer' from the original
  5532. Org-mode buffer.
  5533. With numerical prefix arg ARG, go up to this level and then take that tree.
  5534. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  5535. dedicated frame)."
  5536. (interactive)
  5537. (org-agenda-check-no-diary)
  5538. (let* ((marker (or (org-get-at-bol 'org-marker)
  5539. (org-agenda-error)))
  5540. (buffer (marker-buffer marker))
  5541. (pos (marker-position marker)))
  5542. (with-current-buffer buffer
  5543. (save-excursion
  5544. (goto-char pos)
  5545. (call-interactively 'org-tree-to-indirect-buffer)))))
  5546. (defvar org-last-heading-marker (make-marker)
  5547. "Marker pointing to the headline that last changed its TODO state
  5548. by a remote command from the agenda.")
  5549. (defun org-agenda-todo-nextset ()
  5550. "Switch TODO entry to next sequence."
  5551. (interactive)
  5552. (org-agenda-todo 'nextset))
  5553. (defun org-agenda-todo-previousset ()
  5554. "Switch TODO entry to previous sequence."
  5555. (interactive)
  5556. (org-agenda-todo 'previousset))
  5557. (defun org-agenda-todo (&optional arg)
  5558. "Cycle TODO state of line at point, also in Org-mode file.
  5559. This changes the line at point, all other lines in the agenda referring to
  5560. the same tree node, and the headline of the tree node in the Org-mode file."
  5561. (interactive "P")
  5562. (org-agenda-check-no-diary)
  5563. (let* ((col (current-column))
  5564. (marker (or (org-get-at-bol 'org-marker)
  5565. (org-agenda-error)))
  5566. (buffer (marker-buffer marker))
  5567. (pos (marker-position marker))
  5568. (hdmarker (org-get-at-bol 'org-hd-marker))
  5569. (todayp (equal (org-get-at-bol 'day)
  5570. (time-to-days (current-time))))
  5571. (inhibit-read-only t)
  5572. org-agenda-headline-snapshot-before-repeat newhead just-one)
  5573. (org-with-remote-undo buffer
  5574. (with-current-buffer buffer
  5575. (widen)
  5576. (goto-char pos)
  5577. (org-show-context 'agenda)
  5578. (save-excursion
  5579. (and (outline-next-heading)
  5580. (org-flag-heading nil))) ; show the next heading
  5581. (let ((current-prefix-arg arg))
  5582. (call-interactively 'org-todo))
  5583. (and (bolp) (forward-char 1))
  5584. (setq newhead (org-get-heading))
  5585. (when (and (org-bound-and-true-p
  5586. org-agenda-headline-snapshot-before-repeat)
  5587. (not (equal org-agenda-headline-snapshot-before-repeat
  5588. newhead))
  5589. todayp)
  5590. (setq newhead org-agenda-headline-snapshot-before-repeat
  5591. just-one t))
  5592. (save-excursion
  5593. (org-back-to-heading)
  5594. (move-marker org-last-heading-marker (point))))
  5595. (beginning-of-line 1)
  5596. (save-excursion
  5597. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  5598. (org-move-to-column col))))
  5599. (defun org-agenda-add-note (&optional arg)
  5600. "Add a time-stamped note to the entry at point."
  5601. (interactive "P")
  5602. (org-agenda-check-no-diary)
  5603. (let* ((marker (or (org-get-at-bol 'org-marker)
  5604. (org-agenda-error)))
  5605. (buffer (marker-buffer marker))
  5606. (pos (marker-position marker))
  5607. (hdmarker (org-get-at-bol 'org-hd-marker))
  5608. (inhibit-read-only t))
  5609. (with-current-buffer buffer
  5610. (widen)
  5611. (goto-char pos)
  5612. (org-show-context 'agenda)
  5613. (save-excursion
  5614. (and (outline-next-heading)
  5615. (org-flag-heading nil))) ; show the next heading
  5616. (org-add-note))))
  5617. (defun org-agenda-change-all-lines (newhead hdmarker
  5618. &optional fixface just-this)
  5619. "Change all lines in the agenda buffer which match HDMARKER.
  5620. The new content of the line will be NEWHEAD (as modified by
  5621. `org-format-agenda-item'). HDMARKER is checked with
  5622. `equal' against all `org-hd-marker' text properties in the file.
  5623. If FIXFACE is non-nil, the face of each item is modified according to
  5624. the new TODO state.
  5625. If JUST-THIS is non-nil, change just the current line, not all.
  5626. If FORCE-TAGS is non nil, the car of it returns the new tags."
  5627. (let* ((inhibit-read-only t)
  5628. (line (org-current-line))
  5629. (thetags (with-current-buffer (marker-buffer hdmarker)
  5630. (save-excursion (save-restriction (widen)
  5631. (goto-char hdmarker)
  5632. (org-get-tags-at)))))
  5633. props m pl undone-face done-face finish new dotime cat tags)
  5634. (save-excursion
  5635. (goto-char (point-max))
  5636. (beginning-of-line 1)
  5637. (while (not finish)
  5638. (setq finish (bobp))
  5639. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  5640. (or (not just-this) (= (org-current-line) line))
  5641. (equal m hdmarker))
  5642. (setq props (text-properties-at (point))
  5643. dotime (org-get-at-bol 'dotime)
  5644. cat (org-get-at-bol 'org-category)
  5645. tags thetags
  5646. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  5647. pl (org-get-at-bol 'prefix-length)
  5648. undone-face (org-get-at-bol 'undone-face)
  5649. done-face (org-get-at-bol 'done-face))
  5650. (goto-char (+ (point) pl))
  5651. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  5652. (cond
  5653. ((equal new "")
  5654. (beginning-of-line 1)
  5655. (and (looking-at ".*\n?") (replace-match "")))
  5656. ((looking-at ".*")
  5657. (replace-match new t t)
  5658. (beginning-of-line 1)
  5659. (add-text-properties (point-at-bol) (point-at-eol) props)
  5660. (when fixface
  5661. (add-text-properties
  5662. (point-at-bol) (point-at-eol)
  5663. (list 'face
  5664. (if org-last-todo-state-is-todo
  5665. undone-face done-face))))
  5666. (org-agenda-highlight-todo 'line)
  5667. (beginning-of-line 1))
  5668. (t (error "Line update did not work"))))
  5669. (beginning-of-line 0)))
  5670. (org-finalize-agenda)))
  5671. (defun org-agenda-align-tags (&optional line)
  5672. "Align all tags in agenda items to `org-agenda-tags-column'."
  5673. (let ((inhibit-read-only t) l c)
  5674. (save-excursion
  5675. (goto-char (if line (point-at-bol) (point-min)))
  5676. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  5677. (if line (point-at-eol) nil) t)
  5678. (add-text-properties
  5679. (match-beginning 2) (match-end 2)
  5680. (list 'face (delq nil (let ((prop (get-text-property
  5681. (match-beginning 2) 'face)))
  5682. (or (listp prop) (setq prop (list prop)))
  5683. (if (memq 'org-tag prop)
  5684. prop
  5685. (cons 'org-tag prop))))))
  5686. (setq l (- (match-end 2) (match-beginning 2))
  5687. c (if (< org-agenda-tags-column 0)
  5688. (- (abs org-agenda-tags-column) l)
  5689. org-agenda-tags-column))
  5690. (delete-region (match-beginning 1) (match-end 1))
  5691. (goto-char (match-beginning 1))
  5692. (insert (org-add-props
  5693. (make-string (max 1 (- c (current-column))) ?\ )
  5694. (text-properties-at (point)))))
  5695. (goto-char (point-min))
  5696. (org-font-lock-add-tag-faces (point-max)))))
  5697. (defun org-agenda-priority-up ()
  5698. "Increase the priority of line at point, also in Org-mode file."
  5699. (interactive)
  5700. (org-agenda-priority 'up))
  5701. (defun org-agenda-priority-down ()
  5702. "Decrease the priority of line at point, also in Org-mode file."
  5703. (interactive)
  5704. (org-agenda-priority 'down))
  5705. (defun org-agenda-priority (&optional force-direction)
  5706. "Set the priority of line at point, also in Org-mode file.
  5707. This changes the line at point, all other lines in the agenda referring to
  5708. the same tree node, and the headline of the tree node in the Org-mode file."
  5709. (interactive)
  5710. (unless org-enable-priority-commands
  5711. (error "Priority commands are disabled"))
  5712. (org-agenda-check-no-diary)
  5713. (let* ((marker (or (org-get-at-bol 'org-marker)
  5714. (org-agenda-error)))
  5715. (hdmarker (org-get-at-bol 'org-hd-marker))
  5716. (buffer (marker-buffer hdmarker))
  5717. (pos (marker-position hdmarker))
  5718. (inhibit-read-only t)
  5719. newhead)
  5720. (org-with-remote-undo buffer
  5721. (with-current-buffer buffer
  5722. (widen)
  5723. (goto-char pos)
  5724. (org-show-context 'agenda)
  5725. (save-excursion
  5726. (and (outline-next-heading)
  5727. (org-flag-heading nil))) ; show the next heading
  5728. (funcall 'org-priority force-direction)
  5729. (end-of-line 1)
  5730. (setq newhead (org-get-heading)))
  5731. (org-agenda-change-all-lines newhead hdmarker)
  5732. (beginning-of-line 1))))
  5733. ;; FIXME: should fix the tags property of the agenda line.
  5734. (defun org-agenda-set-tags (&optional tag onoff)
  5735. "Set tags for the current headline."
  5736. (interactive)
  5737. (org-agenda-check-no-diary)
  5738. (if (and (org-region-active-p) (interactive-p))
  5739. (call-interactively 'org-change-tag-in-region)
  5740. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5741. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5742. (org-agenda-error)))
  5743. (buffer (marker-buffer hdmarker))
  5744. (pos (marker-position hdmarker))
  5745. (inhibit-read-only t)
  5746. newhead)
  5747. (org-with-remote-undo buffer
  5748. (with-current-buffer buffer
  5749. (widen)
  5750. (goto-char pos)
  5751. (save-excursion
  5752. (org-show-context 'agenda))
  5753. (save-excursion
  5754. (and (outline-next-heading)
  5755. (org-flag-heading nil))) ; show the next heading
  5756. (goto-char pos)
  5757. (if tag
  5758. (org-toggle-tag tag onoff)
  5759. (call-interactively 'org-set-tags))
  5760. (end-of-line 1)
  5761. (setq newhead (org-get-heading)))
  5762. (org-agenda-change-all-lines newhead hdmarker)
  5763. (beginning-of-line 1)))))
  5764. (defun org-agenda-set-property ()
  5765. "Set a property for the current headline."
  5766. (interactive)
  5767. (org-agenda-check-no-diary)
  5768. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5769. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5770. (org-agenda-error)))
  5771. (buffer (marker-buffer hdmarker))
  5772. (pos (marker-position hdmarker))
  5773. (inhibit-read-only t)
  5774. newhead)
  5775. (org-with-remote-undo buffer
  5776. (with-current-buffer buffer
  5777. (widen)
  5778. (goto-char pos)
  5779. (save-excursion
  5780. (org-show-context 'agenda))
  5781. (save-excursion
  5782. (and (outline-next-heading)
  5783. (org-flag-heading nil))) ; show the next heading
  5784. (goto-char pos)
  5785. (call-interactively 'org-set-property)))))
  5786. (defun org-agenda-set-effort ()
  5787. "Set the effort property for the current headline."
  5788. (interactive)
  5789. (org-agenda-check-no-diary)
  5790. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5791. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5792. (org-agenda-error)))
  5793. (buffer (marker-buffer hdmarker))
  5794. (pos (marker-position hdmarker))
  5795. (inhibit-read-only t)
  5796. newhead)
  5797. (org-with-remote-undo buffer
  5798. (with-current-buffer buffer
  5799. (widen)
  5800. (goto-char pos)
  5801. (save-excursion
  5802. (org-show-context 'agenda))
  5803. (save-excursion
  5804. (and (outline-next-heading)
  5805. (org-flag-heading nil))) ; show the next heading
  5806. (goto-char pos)
  5807. (call-interactively 'org-set-effort)
  5808. (end-of-line 1)))))
  5809. (defun org-agenda-toggle-archive-tag ()
  5810. "Toggle the archive tag for the current entry."
  5811. (interactive)
  5812. (org-agenda-check-no-diary)
  5813. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5814. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5815. (org-agenda-error)))
  5816. (buffer (marker-buffer hdmarker))
  5817. (pos (marker-position hdmarker))
  5818. (inhibit-read-only t)
  5819. newhead)
  5820. (org-with-remote-undo buffer
  5821. (with-current-buffer buffer
  5822. (widen)
  5823. (goto-char pos)
  5824. (org-show-context 'agenda)
  5825. (save-excursion
  5826. (and (outline-next-heading)
  5827. (org-flag-heading nil))) ; show the next heading
  5828. (call-interactively 'org-toggle-archive-tag)
  5829. (end-of-line 1)
  5830. (setq newhead (org-get-heading)))
  5831. (org-agenda-change-all-lines newhead hdmarker)
  5832. (beginning-of-line 1))))
  5833. (defun org-agenda-do-date-later (arg)
  5834. (interactive "P")
  5835. (cond
  5836. ((or (equal arg '(16))
  5837. (memq last-command
  5838. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  5839. (setq this-command 'org-agenda-date-later-minutes)
  5840. (org-agenda-date-later-minutes 1))
  5841. ((or (equal arg '(4))
  5842. (memq last-command
  5843. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  5844. (setq this-command 'org-agenda-date-later-hours)
  5845. (org-agenda-date-later-hours 1))
  5846. (t
  5847. (org-agenda-date-later (prefix-numeric-value arg)))))
  5848. (defun org-agenda-do-date-earlier (arg)
  5849. (interactive "P")
  5850. (cond
  5851. ((or (equal arg '(16))
  5852. (memq last-command
  5853. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  5854. (setq this-command 'org-agenda-date-earlier-minutes)
  5855. (org-agenda-date-earlier-minutes 1))
  5856. ((or (equal arg '(4))
  5857. (memq last-command
  5858. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  5859. (setq this-command 'org-agenda-date-earlier-hours)
  5860. (org-agenda-date-earlier-hours 1))
  5861. (t
  5862. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  5863. (defun org-agenda-date-later (arg &optional what)
  5864. "Change the date of this item to one day later."
  5865. (interactive "p")
  5866. (org-agenda-check-type t 'agenda 'timeline)
  5867. (org-agenda-check-no-diary)
  5868. (let* ((marker (or (org-get-at-bol 'org-marker)
  5869. (org-agenda-error)))
  5870. (buffer (marker-buffer marker))
  5871. (pos (marker-position marker)))
  5872. (org-with-remote-undo buffer
  5873. (with-current-buffer buffer
  5874. (widen)
  5875. (goto-char pos)
  5876. (if (not (org-at-timestamp-p))
  5877. (error "Cannot find time stamp"))
  5878. (org-timestamp-change arg (or what 'day)))
  5879. (org-agenda-show-new-time marker org-last-changed-timestamp))
  5880. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  5881. (defun org-agenda-date-earlier (arg &optional what)
  5882. "Change the date of this item to one day earlier."
  5883. (interactive "p")
  5884. (org-agenda-date-later (- arg) what))
  5885. (defun org-agenda-date-later-minutes (arg)
  5886. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  5887. (interactive "p")
  5888. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  5889. (org-agenda-date-later arg 'minute))
  5890. (defun org-agenda-date-earlier-minutes (arg)
  5891. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  5892. (interactive "p")
  5893. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  5894. (org-agenda-date-earlier arg 'minute))
  5895. (defun org-agenda-date-later-hours (arg)
  5896. "Change the time of this item, in hour steps."
  5897. (interactive "p")
  5898. (org-agenda-date-later arg 'hour))
  5899. (defun org-agenda-date-earlier-hours (arg)
  5900. "Change the time of this item, in hour steps."
  5901. (interactive "p")
  5902. (org-agenda-date-earlier arg 'hour))
  5903. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  5904. "Show new date stamp via text properties."
  5905. ;; We use text properties to make this undoable
  5906. (let ((inhibit-read-only t)
  5907. (buffer-invisibility-spec))
  5908. (setq stamp (concat " " prefix " => " stamp))
  5909. (save-excursion
  5910. (goto-char (point-max))
  5911. (while (not (bobp))
  5912. (when (equal marker (org-get-at-bol 'org-marker))
  5913. (org-move-to-column (- (window-width) (length stamp)) t)
  5914. (org-agenda-fix-tags-filter-overlays-at (point))
  5915. (if (featurep 'xemacs)
  5916. ;; Use `duplicable' property to trigger undo recording
  5917. (let ((ex (make-extent nil nil))
  5918. (gl (make-glyph stamp)))
  5919. (set-glyph-face gl 'secondary-selection)
  5920. (set-extent-properties
  5921. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  5922. (insert-extent ex (1- (point)) (point-at-eol)))
  5923. (add-text-properties
  5924. (1- (point)) (point-at-eol)
  5925. (list 'display (org-add-props stamp nil
  5926. 'face 'secondary-selection))))
  5927. (beginning-of-line 1))
  5928. (beginning-of-line 0)))))
  5929. (defun org-agenda-date-prompt (arg)
  5930. "Change the date of this item. Date is prompted for, with default today.
  5931. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  5932. be used to request time specification in the time stamp."
  5933. (interactive "P")
  5934. (org-agenda-check-type t 'agenda 'timeline)
  5935. (org-agenda-check-no-diary)
  5936. (let* ((marker (or (org-get-at-bol 'org-marker)
  5937. (org-agenda-error)))
  5938. (buffer (marker-buffer marker))
  5939. (pos (marker-position marker)))
  5940. (org-with-remote-undo buffer
  5941. (with-current-buffer buffer
  5942. (widen)
  5943. (goto-char pos)
  5944. (if (not (org-at-timestamp-p))
  5945. (error "Cannot find time stamp"))
  5946. (org-time-stamp arg))
  5947. (org-agenda-show-new-time marker org-last-changed-timestamp))
  5948. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  5949. (defun org-agenda-schedule (arg)
  5950. "Schedule the item at point."
  5951. (interactive "P")
  5952. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  5953. (org-agenda-check-no-diary)
  5954. (let* ((marker (or (org-get-at-bol 'org-marker)
  5955. (org-agenda-error)))
  5956. (type (marker-insertion-type marker))
  5957. (buffer (marker-buffer marker))
  5958. (pos (marker-position marker))
  5959. (org-insert-labeled-timestamps-at-point nil)
  5960. ts)
  5961. (set-marker-insertion-type marker t)
  5962. (org-with-remote-undo buffer
  5963. (with-current-buffer buffer
  5964. (widen)
  5965. (goto-char pos)
  5966. (setq ts (org-schedule arg)))
  5967. (org-agenda-show-new-time marker ts "S"))
  5968. (message "Item scheduled for %s" ts)))
  5969. (defun org-agenda-deadline (arg)
  5970. "Schedule the item at point."
  5971. (interactive "P")
  5972. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  5973. (org-agenda-check-no-diary)
  5974. (let* ((marker (or (org-get-at-bol 'org-marker)
  5975. (org-agenda-error)))
  5976. (buffer (marker-buffer marker))
  5977. (pos (marker-position marker))
  5978. (org-insert-labeled-timestamps-at-point nil)
  5979. ts)
  5980. (org-with-remote-undo buffer
  5981. (with-current-buffer buffer
  5982. (widen)
  5983. (goto-char pos)
  5984. (setq ts (org-deadline arg)))
  5985. (org-agenda-show-new-time marker ts "D"))
  5986. (message "Deadline for this item set to %s" ts)))
  5987. (defun org-agenda-action ()
  5988. "Select entry for agenda action, or execute an agenda action.
  5989. This command prompts for another letter. Valid inputs are:
  5990. m Mark the entry at point for an agenda action
  5991. s Schedule the marked entry to the date at the cursor
  5992. d Set the deadline of the marked entry to the date at the cursor
  5993. r Call `org-remember' with cursor date as the default date
  5994. SPC Show marked entry in other window
  5995. TAB Visit marked entry in other window
  5996. The cursor may be at a date in the calendar, or in the Org agenda."
  5997. (interactive)
  5998. (let (ans)
  5999. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  6000. (setq ans (read-char-exclusive))
  6001. (cond
  6002. ((equal ans ?m)
  6003. ;; Mark this entry
  6004. (if (eq major-mode 'org-agenda-mode)
  6005. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6006. (org-get-at-bol 'org-marker))))
  6007. (if m
  6008. (progn
  6009. (move-marker org-agenda-action-marker
  6010. (marker-position m) (marker-buffer m))
  6011. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6012. (error "Don't know which entry to mark")))
  6013. (error "This command works only in the agenda")))
  6014. ((equal ans ?s)
  6015. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6016. ((equal ans ?d)
  6017. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6018. ((equal ans ?r)
  6019. (org-agenda-do-action '(org-remember) t))
  6020. ((equal ans ?\ )
  6021. (let ((cw (selected-window)))
  6022. (org-switch-to-buffer-other-window
  6023. (marker-buffer org-agenda-action-marker))
  6024. (goto-char org-agenda-action-marker)
  6025. (org-show-context 'agenda)
  6026. (select-window cw)))
  6027. ((equal ans ?\C-i)
  6028. (org-switch-to-buffer-other-window
  6029. (marker-buffer org-agenda-action-marker))
  6030. (goto-char org-agenda-action-marker)
  6031. (org-show-context 'agenda))
  6032. (t (error "Invalid agenda action %c" ans)))))
  6033. (defun org-agenda-do-action (form &optional current-buffer)
  6034. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6035. (let ((org-overriding-default-time (org-get-cursor-date)))
  6036. (if current-buffer
  6037. (eval form)
  6038. (if (not (marker-buffer org-agenda-action-marker))
  6039. (error "No entry has bee selected for agenda action")
  6040. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6041. (save-excursion
  6042. (save-restriction
  6043. (widen)
  6044. (goto-char org-agenda-action-marker)
  6045. (eval form))))))))
  6046. (defun org-agenda-clock-in (&optional arg)
  6047. "Start the clock on the currently selected item."
  6048. (interactive "P")
  6049. (org-agenda-check-no-diary)
  6050. (if (equal arg '(4))
  6051. (org-clock-in arg)
  6052. (let* ((marker (or (org-get-at-bol 'org-marker)
  6053. (org-agenda-error)))
  6054. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6055. marker))
  6056. (pos (marker-position marker))
  6057. newhead)
  6058. (org-with-remote-undo (marker-buffer marker)
  6059. (with-current-buffer (marker-buffer marker)
  6060. (widen)
  6061. (goto-char pos)
  6062. (org-show-context 'agenda)
  6063. (org-show-entry)
  6064. (org-cycle-hide-drawers 'children)
  6065. (org-clock-in arg)
  6066. (setq newhead (org-get-heading)))
  6067. (org-agenda-change-all-lines newhead hdmarker)))))
  6068. (defun org-agenda-clock-out (&optional arg)
  6069. "Stop the currently running clock."
  6070. (interactive "P")
  6071. (unless (marker-buffer org-clock-marker)
  6072. (error "No running clock"))
  6073. (let ((marker (make-marker)) newhead)
  6074. (org-with-remote-undo (marker-buffer org-clock-marker)
  6075. (with-current-buffer (marker-buffer org-clock-marker)
  6076. (save-excursion
  6077. (save-restriction
  6078. (widen)
  6079. (goto-char org-clock-marker)
  6080. (org-back-to-heading t)
  6081. (move-marker marker (point))
  6082. (org-clock-out)
  6083. (setq newhead (org-get-heading))))))
  6084. (org-agenda-change-all-lines newhead marker)
  6085. (move-marker marker nil)))
  6086. (defun org-agenda-clock-cancel (&optional arg)
  6087. "Cancel the currently running clock."
  6088. (interactive "P")
  6089. (unless (marker-buffer org-clock-marker)
  6090. (error "No running clock"))
  6091. (org-with-remote-undo (marker-buffer org-clock-marker)
  6092. (org-clock-cancel)))
  6093. (defun org-agenda-diary-entry ()
  6094. "Make a diary entry, like the `i' command from the calendar.
  6095. All the standard commands work: block, weekly etc."
  6096. (interactive)
  6097. (org-agenda-check-type t 'agenda 'timeline)
  6098. (require 'diary-lib)
  6099. (let* ((char (progn
  6100. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6101. (read-char-exclusive)))
  6102. (cmd (cdr (assoc char
  6103. '((?d . insert-diary-entry)
  6104. (?w . insert-weekly-diary-entry)
  6105. (?m . insert-monthly-diary-entry)
  6106. (?y . insert-yearly-diary-entry)
  6107. (?a . insert-anniversary-diary-entry)
  6108. (?b . insert-block-diary-entry)
  6109. (?c . insert-cyclic-diary-entry)))))
  6110. (oldf (symbol-function 'calendar-cursor-to-date))
  6111. ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6112. (point (point))
  6113. (mark (or (mark t) (point))))
  6114. (unless cmd
  6115. (error "No command associated with <%c>" char))
  6116. (unless (and (get-text-property point 'day)
  6117. (or (not (equal ?b char))
  6118. (get-text-property mark 'day)))
  6119. (error "Don't know which date to use for diary entry"))
  6120. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6121. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6122. (let ((calendar-mark-ring
  6123. (list (calendar-gregorian-from-absolute
  6124. (or (get-text-property mark 'day)
  6125. (get-text-property point 'day))))))
  6126. (unwind-protect
  6127. (progn
  6128. (fset 'calendar-cursor-to-date
  6129. (lambda (&optional error dummy)
  6130. (calendar-gregorian-from-absolute
  6131. (get-text-property point 'day))))
  6132. (call-interactively cmd))
  6133. (fset 'calendar-cursor-to-date oldf)))))
  6134. (defun org-agenda-execute-calendar-command (cmd)
  6135. "Execute a calendar command from the agenda, with the date associated to
  6136. the cursor position."
  6137. (org-agenda-check-type t 'agenda 'timeline)
  6138. (require 'diary-lib)
  6139. (unless (get-text-property (point) 'day)
  6140. (error "Don't know which date to use for calendar command"))
  6141. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6142. (point (point))
  6143. (date (calendar-gregorian-from-absolute
  6144. (get-text-property point 'day)))
  6145. ;; the following 2 vars are needed in the calendar
  6146. (displayed-month (car date))
  6147. (displayed-year (nth 2 date)))
  6148. (unwind-protect
  6149. (progn
  6150. (fset 'calendar-cursor-to-date
  6151. (lambda (&optional error dummy)
  6152. (calendar-gregorian-from-absolute
  6153. (get-text-property point 'day))))
  6154. (call-interactively cmd))
  6155. (fset 'calendar-cursor-to-date oldf))))
  6156. (defun org-agenda-phases-of-moon ()
  6157. "Display the phases of the moon for the 3 months around the cursor date."
  6158. (interactive)
  6159. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6160. (defun org-agenda-holidays ()
  6161. "Display the holidays for the 3 months around the cursor date."
  6162. (interactive)
  6163. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6164. (defvar calendar-longitude)
  6165. (defvar calendar-latitude)
  6166. (defvar calendar-location-name)
  6167. (defun org-agenda-sunrise-sunset (arg)
  6168. "Display sunrise and sunset for the cursor date.
  6169. Latitude and longitude can be specified with the variables
  6170. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6171. argument, latitude and longitude will be prompted for."
  6172. (interactive "P")
  6173. (require 'solar)
  6174. (let ((calendar-longitude (if arg nil calendar-longitude))
  6175. (calendar-latitude (if arg nil calendar-latitude))
  6176. (calendar-location-name
  6177. (if arg "the given coordinates" calendar-location-name)))
  6178. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6179. (defun org-agenda-goto-calendar ()
  6180. "Open the Emacs calendar with the date at the cursor."
  6181. (interactive)
  6182. (org-agenda-check-type t 'agenda 'timeline)
  6183. (let* ((day (or (get-text-property (point) 'day)
  6184. (error "Don't know which date to open in calendar")))
  6185. (date (calendar-gregorian-from-absolute day))
  6186. (calendar-move-hook nil)
  6187. (calendar-view-holidays-initially-flag nil)
  6188. (calendar-view-diary-initially-flag nil)
  6189. (view-calendar-holidays-initially nil)
  6190. (view-diary-entries-initially nil))
  6191. (calendar)
  6192. (calendar-goto-date date)))
  6193. ;;;###autoload
  6194. (defun org-calendar-goto-agenda ()
  6195. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6196. This is a command that has to be installed in `calendar-mode-map'."
  6197. (interactive)
  6198. (org-agenda-list nil (calendar-absolute-from-gregorian
  6199. (calendar-cursor-to-date))
  6200. nil))
  6201. (defun org-agenda-convert-date ()
  6202. (interactive)
  6203. (org-agenda-check-type t 'agenda 'timeline)
  6204. (let ((day (get-text-property (point) 'day))
  6205. date s)
  6206. (unless day
  6207. (error "Don't know which date to convert"))
  6208. (setq date (calendar-gregorian-from-absolute day))
  6209. (setq s (concat
  6210. "Gregorian: " (calendar-date-string date) "\n"
  6211. "ISO: " (calendar-iso-date-string date) "\n"
  6212. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6213. "Julian: " (calendar-julian-date-string date) "\n"
  6214. "Astron. JD: " (calendar-astro-date-string date)
  6215. " (Julian date number at noon UTC)\n"
  6216. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6217. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6218. "French: " (calendar-french-date-string date) "\n"
  6219. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6220. "Mayan: " (calendar-mayan-date-string date) "\n"
  6221. "Coptic: " (calendar-coptic-date-string date) "\n"
  6222. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6223. "Persian: " (calendar-persian-date-string date) "\n"
  6224. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6225. (with-output-to-temp-buffer "*Dates*"
  6226. (princ s))
  6227. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6228. ;;; Bulk commands
  6229. (defvar org-agenda-bulk-marked-entries nil
  6230. "List of markers that refer to marked entries in the agenda.")
  6231. (defun org-agenda-bulk-marked-p ()
  6232. (eq (get-char-property (point-at-bol) 'type)
  6233. 'org-marked-entry-overlay))
  6234. (defun org-agenda-bulk-mark ()
  6235. "Mark the entry at point for future bulk action."
  6236. (interactive)
  6237. (org-agenda-check-no-diary)
  6238. (let* ((m (org-get-at-bol 'org-hd-marker))
  6239. ov)
  6240. (unless (org-agenda-bulk-marked-p)
  6241. (unless m (error "Nothing to mark at point"))
  6242. (push m org-agenda-bulk-marked-entries)
  6243. (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  6244. (org-overlay-display ov "> "
  6245. (org-get-todo-face "TODO")
  6246. 'evaporate)
  6247. (org-overlay-put ov 'type 'org-marked-entry-overlay))
  6248. (beginning-of-line 2)
  6249. (message "%d entries marked for bulk action"
  6250. (length org-agenda-bulk-marked-entries))))
  6251. (defun org-agenda-bulk-unmark ()
  6252. "Unmark the entry at point for future bulk action."
  6253. (interactive)
  6254. (when (org-agenda-bulk-marked-p)
  6255. (org-agenda-bulk-remove-overlays
  6256. (point-at-bol) (+ 2 (point-at-bol)))
  6257. (setq org-agenda-bulk-marked-entries
  6258. (delete (org-get-at-bol 'org-hd-marker)
  6259. org-agenda-bulk-marked-entries)))
  6260. (beginning-of-line 2)
  6261. (message "%d entries marked for bulk action"
  6262. (length org-agenda-bulk-marked-entries)))
  6263. (defun org-agenda-bulk-toggle ()
  6264. "Toggle marking the entry at point for bulk action."
  6265. (interactive)
  6266. (if (org-agenda-bulk-marked-p)
  6267. (org-agenda-bulk-unmark)
  6268. (org-agenda-bulk-mark)))
  6269. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  6270. "Remove the mark overlays between BEG and END in the agenda buffer.
  6271. BEG and END default to the buffer limits.
  6272. This only removes the overlays, it does not remove the markers
  6273. from the list in `org-agenda-bulk-marked-entries'."
  6274. (interactive)
  6275. (mapc (lambda (ov)
  6276. (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
  6277. (org-delete-overlay ov)))
  6278. (org-overlays-in (or beg (point-min)) (or end (point-max)))))
  6279. (defun org-agenda-bulk-remove-all-marks ()
  6280. "Remove all marks in the agenda buffer.
  6281. This will remove the markers, and the overlays."
  6282. (interactive)
  6283. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  6284. (setq org-agenda-bulk-marked-entries nil)
  6285. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  6286. (defun org-agenda-bulk-action ()
  6287. "Execute an remote-editing action on all marked entries."
  6288. (interactive)
  6289. (unless org-agenda-bulk-marked-entries
  6290. (error "No entries are marked"))
  6291. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  6292. (let* ((action (read-char-exclusive))
  6293. (entries (reverse org-agenda-bulk-marked-entries))
  6294. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  6295. (cond
  6296. ((equal action ?$)
  6297. (setq cmd '(org-agenda-archive)))
  6298. ((equal action ?A)
  6299. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  6300. ((member action '(?r ?w))
  6301. (setq rfloc (org-refile-get-location
  6302. "Refile to: "
  6303. (marker-buffer (car org-agenda-bulk-marked-entries))
  6304. org-refile-allow-creating-parent-nodes))
  6305. (setcar (nthcdr 3 rfloc)
  6306. (move-marker (make-marker) (nth 3 rfloc)
  6307. (or (get-file-buffer (nth 1 rfloc))
  6308. (find-buffer-visiting (nth 1 rfloc))
  6309. (error "This should not happen"))))
  6310. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
  6311. ((equal action ?t)
  6312. (setq state (org-icompleting-read
  6313. "Todo state: "
  6314. (with-current-buffer (marker-buffer (car entries))
  6315. (mapcar 'list org-todo-keywords-1))))
  6316. (setq cmd `(let ((org-inhibit-blocking t)
  6317. (org-inhibit-logging 'note))
  6318. (org-agenda-todo ,state))))
  6319. ((memq action '(?- ?+))
  6320. (setq tag (org-icompleting-read
  6321. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  6322. (with-current-buffer (marker-buffer (car entries))
  6323. (delq nil
  6324. (mapcar (lambda (x)
  6325. (if (stringp (car x)) x)) org-tag-alist)))))
  6326. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  6327. ((memq action '(?s ?d))
  6328. (let* ((date (org-read-date
  6329. nil nil nil
  6330. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
  6331. (ans org-read-date-final-answer)
  6332. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  6333. (setq cmd `(let* ((bound (fboundp 'read-string))
  6334. (old (and bound (symbol-function 'read-string))))
  6335. (unwind-protect
  6336. (progn
  6337. (fset 'read-string (lambda (&rest ignore) ,ans))
  6338. (call-interactively ',c1))
  6339. (if bound
  6340. (fset 'read-string old)
  6341. (fmakunbound 'read-string)))))))
  6342. (t (error "Invalid bulk action")))
  6343. ;; Sort the markers, to make sure that parents are handled before children
  6344. (setq entries (sort entries
  6345. (lambda (a b)
  6346. (cond
  6347. ((equal (marker-buffer a) (marker-buffer b))
  6348. (< (marker-position a) (marker-position b)))
  6349. (t
  6350. (string< (buffer-name (marker-buffer a))
  6351. (buffer-name (marker-buffer b))))))))
  6352. ;; Now loop over all markers and apply cmd
  6353. (while (setq e (pop entries))
  6354. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  6355. (if (not pos)
  6356. (progn (message "Skipping removed entry at %s" e)
  6357. (setq cntskip (1+ cntskip)))
  6358. (goto-char pos)
  6359. (eval cmd)
  6360. (setq org-agenda-bulk-marked-entries
  6361. (delete e org-agenda-bulk-marked-entries))
  6362. (setq cnt (1+ cnt))))
  6363. (setq org-agenda-bulk-marked-entries nil)
  6364. (org-agenda-bulk-remove-all-marks)
  6365. (message "Acted on %d entries%s"
  6366. cnt
  6367. (if (= cntskip 0)
  6368. ""
  6369. (format ", skipped %d (disappeared before their turn)"
  6370. cntskip)))))
  6371. ;;; Flagging notes
  6372. (defun org-agenda-show-the-flagging-note ()
  6373. "Display the flagging note in the other window.
  6374. When called a second time in direct sequence, offer to remove the FLAGGING
  6375. tag and (if present) the flagging note."
  6376. (interactive)
  6377. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  6378. (win (selected-window))
  6379. note heading newhead)
  6380. (unless hdmarker
  6381. (error "No linked entry at point"))
  6382. (if (and (eq this-command last-command)
  6383. (y-or-n-p "Unflag and remove any flagging note? "))
  6384. (progn
  6385. (org-agenda-remove-flag hdmarker)
  6386. (let ((win (get-buffer-window "*Flagging Note*")))
  6387. (and win (delete-window win)))
  6388. (message "Entry unflaged"))
  6389. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  6390. (unless note
  6391. (error "No flagging note"))
  6392. (org-kill-new note)
  6393. (org-switch-to-buffer-other-window "*Flagging Note*")
  6394. (erase-buffer)
  6395. (insert note)
  6396. (goto-char (point-min))
  6397. (while (re-search-forward "\\\\n" nil t)
  6398. (replace-match "\n" t t))
  6399. (goto-char (point-min))
  6400. (select-window win)
  6401. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  6402. (defun org-agenda-remove-flag (marker)
  6403. "Remove the FLAGGED tag and any flaging note in the entry."
  6404. (let (newhead)
  6405. (org-with-point-at marker
  6406. (org-toggle-tag "FLAGGED" 'off)
  6407. (org-entry-delete nil "THEFLAGGINGNOTE")
  6408. (setq newhead (org-get-heading)))
  6409. (org-agenda-change-all-lines newhead marker)
  6410. (message "Entry unflaged")))
  6411. (defun org-agenda-get-any-marker (&optional pos)
  6412. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  6413. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  6414. ;;; Appointment reminders
  6415. (defvar appt-time-msg-list)
  6416. ;;;###autoload
  6417. (defun org-agenda-to-appt (&optional refresh filter)
  6418. "Activate appointments found in `org-agenda-files'.
  6419. With a \\[universal-argument] prefix, refresh the list of
  6420. appointments.
  6421. If FILTER is t, interactively prompt the user for a regular
  6422. expression, and filter out entries that don't match it.
  6423. If FILTER is a string, use this string as a regular expression
  6424. for filtering entries out.
  6425. FILTER can also be an alist with the car of each cell being
  6426. either 'headline or 'category. For example:
  6427. '((headline \"IMPORTANT\")
  6428. (category \"Work\"))
  6429. will only add headlines containing IMPORTANT or headlines
  6430. belonging to the \"Work\" category."
  6431. (interactive "P")
  6432. (require 'calendar)
  6433. (if refresh (setq appt-time-msg-list nil))
  6434. (if (eq filter t)
  6435. (setq filter (read-from-minibuffer "Regexp filter: ")))
  6436. (let* ((cnt 0) ; count added events
  6437. (org-agenda-new-buffers nil)
  6438. (org-deadline-warning-days 0)
  6439. (today (org-date-to-gregorian
  6440. (time-to-days (current-time))))
  6441. (org-agenda-restrict nil)
  6442. (files (org-agenda-files 'unrestricted)) entries file)
  6443. ;; Get all entries which may contain an appt
  6444. (org-prepare-agenda-buffers files)
  6445. (while (setq file (pop files))
  6446. (setq entries
  6447. (append entries
  6448. (org-agenda-get-day-entries
  6449. file today :timestamp :scheduled :deadline))))
  6450. (setq entries (delq nil entries))
  6451. ;; Map thru entries and find if we should filter them out
  6452. (mapc
  6453. (lambda(x)
  6454. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  6455. (cat (get-text-property 1 'org-category x))
  6456. (tod (get-text-property 1 'time-of-day x))
  6457. (ok (or (null filter)
  6458. (and (stringp filter) (string-match filter evt))
  6459. (and (listp filter)
  6460. (or (string-match
  6461. (cadr (assoc 'category filter)) cat)
  6462. (string-match
  6463. (cadr (assoc 'headline filter)) evt))))))
  6464. ;; FIXME: Shall we remove text-properties for the appt text?
  6465. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  6466. (when (and ok tod)
  6467. (setq tod (concat "00" (number-to-string tod))
  6468. tod (when (string-match
  6469. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  6470. (concat (match-string 1 tod) ":"
  6471. (match-string 2 tod))))
  6472. (appt-add tod evt)
  6473. (setq cnt (1+ cnt))))) entries)
  6474. (org-release-buffers org-agenda-new-buffers)
  6475. (if (eq cnt 0)
  6476. (message "No event to add")
  6477. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  6478. (defun org-agenda-todayp (date)
  6479. "Does DATE mean today, when considering `org-extend-today-until'?"
  6480. (let (today h)
  6481. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  6482. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  6483. (setq h (nth 2 (decode-time (current-time))))
  6484. (or (and (>= h org-extend-today-until)
  6485. (= date today))
  6486. (and (< h org-extend-today-until)
  6487. (= date (1- today))))))
  6488. (provide 'org-agenda)
  6489. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  6490. ;;; org-agenda.el ends here