org-agenda.el 265 KB

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