org-agenda.el 283 KB

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