org-agenda.el 255 KB

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