org-agenda.el 297 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.01trans
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  58. (defvar org-habit-show-habits)
  59. (defvar org-habit-show-habits-only-for-today)
  60. ;; Defined somewhere in this file, but used before definition.
  61. (defvar org-agenda-buffer-name)
  62. (defvar org-agenda-overriding-header)
  63. (defvar org-agenda-title-append nil)
  64. (defvar entry)
  65. (defvar date)
  66. (defvar org-agenda-undo-list)
  67. (defvar org-agenda-pending-undo-list)
  68. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  69. (defcustom org-agenda-confirm-kill 1
  70. "When set, remote killing from the agenda buffer needs confirmation.
  71. When t, a confirmation is always needed. When a number N, confirmation is
  72. only needed when the text to be killed contains more than N non-white lines."
  73. :group 'org-agenda
  74. :type '(choice
  75. (const :tag "Never" nil)
  76. (const :tag "Always" t)
  77. (integer :tag "When more than N lines")))
  78. (defcustom org-agenda-compact-blocks nil
  79. "Non-nil means make the block agenda more compact.
  80. This is done by leaving out unnecessary lines."
  81. :group 'org-agenda
  82. :type 'boolean)
  83. (defcustom org-agenda-block-separator ?=
  84. "The separator between blocks in the agenda.
  85. If this is a string, it will be used as the separator, with a newline added.
  86. If it is a character, it will be repeated to fill the window width."
  87. :group 'org-agenda
  88. :type '(choice
  89. (character)
  90. (string)))
  91. (defgroup org-agenda-export nil
  92. "Options concerning exporting agenda views in Org-mode."
  93. :tag "Org Agenda Export"
  94. :group 'org-agenda)
  95. (defcustom org-agenda-with-colors t
  96. "Non-nil means use colors in agenda views."
  97. :group 'org-agenda-export
  98. :type 'boolean)
  99. (defcustom org-agenda-exporter-settings nil
  100. "Alist of variable/value pairs that should be active during agenda export.
  101. This is a good place to set options for ps-print and for htmlize.
  102. Note that the way this is implemented, the values will be evaluated
  103. before assigned to the variables. So make sure to quote values you do
  104. *not* want evaluated, for example
  105. (setq org-agenda-exporter-settings
  106. '((ps-print-color-p 'black-white)))"
  107. :group 'org-agenda-export
  108. :type '(repeat
  109. (list
  110. (variable)
  111. (sexp :tag "Value"))))
  112. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  113. "Hook run in temporary buffer before writing it to an export file.
  114. A useful function is `org-agenda-add-entry-text'."
  115. :group 'org-agenda-export
  116. :type 'hook
  117. :options '(org-agenda-add-entry-text))
  118. (defcustom org-agenda-add-entry-text-maxlines 0
  119. "Maximum number of entry text lines to be added to agenda.
  120. This is only relevant when `org-agenda-add-entry-text' is part of
  121. `org-agenda-before-write-hook', which it is by default.
  122. When this is 0, nothing will happen. When it is greater than 0, it
  123. specifies the maximum number of lines that will be added for each entry
  124. that is listed in the agenda view.
  125. Note that this variable is not used during display, only when exporting
  126. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  127. and `org-agenda-entry-text-maxlines'."
  128. :group 'org-agenda
  129. :type 'integer)
  130. (defcustom org-agenda-add-entry-text-descriptive-links t
  131. "Non-nil means export org-links as descriptive links in agenda added text.
  132. This variable applies to the text added to the agenda when
  133. `org-agenda-add-entry-text-maxlines' is larger than 0.
  134. When this variable nil, the URL will (also) be shown."
  135. :group 'org-agenda
  136. :type 'boolean)
  137. (defcustom org-agenda-export-html-style ""
  138. "The style specification for exported HTML Agenda files.
  139. If this variable contains a string, it will replace the default <style>
  140. section as produced by `htmlize'.
  141. Since there are different ways of setting style information, this variable
  142. needs to contain the full HTML structure to provide a style, including the
  143. surrounding HTML tags. The style specifications should include definitions
  144. the fonts used by the agenda, here is an example:
  145. <style type=\"text/css\">
  146. p { font-weight: normal; color: gray; }
  147. .org-agenda-structure {
  148. font-size: 110%;
  149. color: #003399;
  150. font-weight: 600;
  151. }
  152. .org-todo {
  153. color: #cc6666;
  154. font-weight: bold;
  155. }
  156. .org-agenda-done {
  157. color: #339933;
  158. }
  159. .org-done {
  160. color: #339933;
  161. }
  162. .title { text-align: center; }
  163. .todo, .deadline { color: red; }
  164. .done { color: green; }
  165. </style>
  166. or, if you want to keep the style in a file,
  167. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  168. As the value of this option simply gets inserted into the HTML <head> header,
  169. you can \"misuse\" it to also add other text to the header. However,
  170. <style>...</style> is required, if not present the variable will be ignored."
  171. :group 'org-agenda-export
  172. :group 'org-export-html
  173. :type 'string)
  174. (defcustom org-agenda-persistent-filter nil
  175. "When set, keep filters from one agenda view to the next."
  176. :group 'org-agenda
  177. :type 'boolean)
  178. (defgroup org-agenda-custom-commands nil
  179. "Options concerning agenda views in Org-mode."
  180. :tag "Org Agenda Custom Commands"
  181. :group 'org-agenda)
  182. (defconst org-sorting-choice
  183. '(choice
  184. (const time-up) (const time-down)
  185. (const category-keep) (const category-up) (const category-down)
  186. (const tag-down) (const tag-up)
  187. (const priority-up) (const priority-down)
  188. (const todo-state-up) (const todo-state-down)
  189. (const effort-up) (const effort-down)
  190. (const habit-up) (const habit-down)
  191. (const alpha-up) (const alpha-down)
  192. (const user-defined-up) (const user-defined-down))
  193. "Sorting choices.")
  194. (defconst org-agenda-custom-commands-local-options
  195. `(repeat :tag "Local settings for this command. Remember to quote values"
  196. (choice :tag "Setting"
  197. (list :tag "Heading for this block"
  198. (const org-agenda-overriding-header)
  199. (string :tag "Headline"))
  200. (list :tag "Files to be searched"
  201. (const org-agenda-files)
  202. (list
  203. (const :format "" quote)
  204. (repeat (file))))
  205. (list :tag "Sorting strategy"
  206. (const org-agenda-sorting-strategy)
  207. (list
  208. (const :format "" quote)
  209. (repeat
  210. ,org-sorting-choice)))
  211. (list :tag "Prefix format"
  212. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  213. (string))
  214. (list :tag "Number of days in agenda"
  215. (const org-agenda-ndays)
  216. (integer :value 1))
  217. (list :tag "Fixed starting date"
  218. (const org-agenda-start-day)
  219. (string :value "2007-11-01"))
  220. (list :tag "Start on day of week"
  221. (const org-agenda-start-on-weekday)
  222. (choice :value 1
  223. (const :tag "Today" nil)
  224. (integer :tag "Weekday No.")))
  225. (list :tag "Include data from diary"
  226. (const org-agenda-include-diary)
  227. (boolean))
  228. (list :tag "Deadline Warning days"
  229. (const org-deadline-warning-days)
  230. (integer :value 1))
  231. (list :tag "Tags filter preset"
  232. (const org-agenda-filter-preset)
  233. (list
  234. (const :format "" quote)
  235. (repeat
  236. (string :tag "+tag or -tag"))))
  237. (list :tag "Set daily/weekly entry types"
  238. (const org-agenda-entry-types)
  239. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  240. (const :deadline)
  241. (const :scheduled)
  242. (const :timestamp)
  243. (const :sexp)))
  244. (list :tag "Standard skipping condition"
  245. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  246. (const org-agenda-skip-function)
  247. (list
  248. (const :format "" quote)
  249. (list
  250. (choice
  251. :tag "Skipping range"
  252. (const :tag "Skip entry" org-agenda-skip-entry-if)
  253. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  254. (repeat :inline t :tag "Conditions for skipping"
  255. (choice
  256. :tag "Condition type"
  257. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  258. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  259. (list :tag "TODO state is" :inline t
  260. (const 'todo)
  261. (choice
  262. (const :tag "any not-done state" 'todo)
  263. (const :tag "any done state" 'done)
  264. (const :tag "any state" 'any)
  265. (list :tag "Keyword list"
  266. (const :format "" quote)
  267. (repeat (string :tag "Keyword")))))
  268. (list :tag "TODO state is not" :inline t
  269. (const 'nottodo)
  270. (choice
  271. (const :tag "any not-done state" 'todo)
  272. (const :tag "any done state" 'done)
  273. (const :tag "any state" 'any)
  274. (list :tag "Keyword list"
  275. (const :format "" quote)
  276. (repeat (string :tag "Keyword")))))
  277. (const :tag "scheduled" 'scheduled)
  278. (const :tag "not scheduled" 'notscheduled)
  279. (const :tag "deadline" 'deadline)
  280. (const :tag "no deadline" 'notdeadline)
  281. (const :tag "timestamp" 'timestamp)
  282. (const :tag "no timestamp" 'nottimestamp))))))
  283. (list :tag "Non-standard skipping condition"
  284. :value (org-agenda-skip-function)
  285. (const org-agenda-skip-function)
  286. (sexp :tag "Function or form (quoted!)"))
  287. (list :tag "Any variable"
  288. (variable :tag "Variable")
  289. (sexp :tag "Value (sexp)"))))
  290. "Selection of examples for agenda command settings.
  291. This will be spliced into the custom type of
  292. `org-agenda-custom-commands'.")
  293. (defcustom org-agenda-custom-commands nil
  294. "Custom commands for the agenda.
  295. These commands will be offered on the splash screen displayed by the
  296. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  297. (key desc type match settings files)
  298. key The key (one or more characters as a string) to be associated
  299. with the command.
  300. desc A description of the command, when omitted or nil, a default
  301. description is built using MATCH.
  302. type The command type, any of the following symbols:
  303. agenda The daily/weekly agenda.
  304. todo Entries with a specific TODO keyword, in all agenda files.
  305. search Entries containing search words entry or headline.
  306. tags Tags/Property/TODO match in all agenda files.
  307. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  308. todo-tree Sparse tree of specific TODO keyword in *current* file.
  309. tags-tree Sparse tree with all tags matches in *current* file.
  310. occur-tree Occur sparse tree for *current* file.
  311. ... A user-defined function.
  312. match What to search for:
  313. - a single keyword for TODO keyword searches
  314. - a tags match expression for tags searches
  315. - a word search expression for text searches.
  316. - a regular expression for occur searches
  317. For all other commands, this should be the empty string.
  318. settings A list of option settings, similar to that in a let form, so like
  319. this: ((opt1 val1) (opt2 val2) ...). The values will be
  320. evaluated at the moment of execution, so quote them when needed.
  321. files A list of files file to write the produced agenda buffer to
  322. with the command `org-store-agenda-views'.
  323. If a file name ends in \".html\", an HTML version of the buffer
  324. is written out. If it ends in \".ps\", a postscript version is
  325. produced. Otherwise, only the plain text is written to the file.
  326. You can also define a set of commands, to create a composite agenda buffer.
  327. In this case, an entry looks like this:
  328. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  329. where
  330. desc A description string to be displayed in the dispatcher menu.
  331. cmd An agenda command, similar to the above. However, tree commands
  332. are no allowed, but instead you can get agenda and global todo list.
  333. So valid commands for a set are:
  334. (agenda \"\" settings)
  335. (alltodo \"\" settings)
  336. (stuck \"\" settings)
  337. (todo \"match\" settings files)
  338. (search \"match\" settings files)
  339. (tags \"match\" settings files)
  340. (tags-todo \"match\" settings files)
  341. Each command can carry a list of options, and another set of options can be
  342. given for the whole set of commands. Individual command options take
  343. precedence over the general options.
  344. When using several characters as key to a command, the first characters
  345. are prefix commands. For the dispatcher to display useful information, you
  346. should provide a description for the prefix, like
  347. (setq org-agenda-custom-commands
  348. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  349. (\"hl\" tags \"+HOME+Lisa\")
  350. (\"hp\" tags \"+HOME+Peter\")
  351. (\"hk\" tags \"+HOME+Kim\")))"
  352. :group 'org-agenda-custom-commands
  353. :type `(repeat
  354. (choice :value ("x" "Describe command here" tags "" nil)
  355. (list :tag "Single command"
  356. (string :tag "Access Key(s) ")
  357. (option (string :tag "Description"))
  358. (choice
  359. (const :tag "Agenda" agenda)
  360. (const :tag "TODO list" alltodo)
  361. (const :tag "Search words" search)
  362. (const :tag "Stuck projects" stuck)
  363. (const :tag "Tags/Property match (all agenda files)" tags)
  364. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  365. (const :tag "TODO keyword search (all agenda files)" todo)
  366. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  367. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  368. (const :tag "Occur tree (current buffer)" occur-tree)
  369. (sexp :tag "Other, user-defined function"))
  370. (string :tag "Match (only for some commands)")
  371. ,org-agenda-custom-commands-local-options
  372. (option (repeat :tag "Export" (file :tag "Export to"))))
  373. (list :tag "Command series, all agenda files"
  374. (string :tag "Access Key(s)")
  375. (string :tag "Description ")
  376. (repeat :tag "Component"
  377. (choice
  378. (list :tag "Agenda"
  379. (const :format "" agenda)
  380. (const :tag "" :format "" "")
  381. ,org-agenda-custom-commands-local-options)
  382. (list :tag "TODO list (all keywords)"
  383. (const :format "" alltodo)
  384. (const :tag "" :format "" "")
  385. ,org-agenda-custom-commands-local-options)
  386. (list :tag "Search words"
  387. (const :format "" search)
  388. (string :tag "Match")
  389. ,org-agenda-custom-commands-local-options)
  390. (list :tag "Stuck projects"
  391. (const :format "" stuck)
  392. (const :tag "" :format "" "")
  393. ,org-agenda-custom-commands-local-options)
  394. (list :tag "Tags search"
  395. (const :format "" tags)
  396. (string :tag "Match")
  397. ,org-agenda-custom-commands-local-options)
  398. (list :tag "Tags search, TODO entries only"
  399. (const :format "" tags-todo)
  400. (string :tag "Match")
  401. ,org-agenda-custom-commands-local-options)
  402. (list :tag "TODO keyword search"
  403. (const :format "" todo)
  404. (string :tag "Match")
  405. ,org-agenda-custom-commands-local-options)
  406. (list :tag "Other, user-defined function"
  407. (symbol :tag "function")
  408. (string :tag "Match")
  409. ,org-agenda-custom-commands-local-options)))
  410. (repeat :tag "Settings for entire command set"
  411. (list (variable :tag "Any variable")
  412. (sexp :tag "Value")))
  413. (option (repeat :tag "Export" (file :tag "Export to"))))
  414. (cons :tag "Prefix key documentation"
  415. (string :tag "Access Key(s)")
  416. (string :tag "Description ")))))
  417. (defcustom org-agenda-query-register ?o
  418. "The register holding the current query string.
  419. The purpose of this is that if you construct a query string interactively,
  420. you can then use it to define a custom command."
  421. :group 'org-agenda-custom-commands
  422. :type 'character)
  423. (defcustom org-stuck-projects
  424. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  425. "How to identify stuck projects.
  426. This is a list of four items:
  427. 1. A tags/todo/property matcher string that is used to identify a project.
  428. See the manual for a description of tag and property searches.
  429. The entire tree below a headline matched by this is considered one project.
  430. 2. A list of TODO keywords identifying non-stuck projects.
  431. If the project subtree contains any headline with one of these todo
  432. keywords, the project is considered to be not stuck. If you specify
  433. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  434. 3. A list of tags identifying non-stuck projects.
  435. If the project subtree contains any headline with one of these tags,
  436. the project is considered to be not stuck. If you specify \"*\" as
  437. a tag, any tag will mark the project unstuck. Note that this is about
  438. the explicit presence of a tag somewhere in the subtree, inherited
  439. tags to not count here. If inherited tags make a project not stuck,
  440. use \"-TAG\" in the tags part of the matcher under (1.) above.
  441. 4. An arbitrary regular expression matching non-stuck projects.
  442. If the project turns out to be not stuck, search continues also in the
  443. subtree to see if any of the subtasks have project status.
  444. See also the variable `org-tags-match-list-sublevels' which applies
  445. to projects matched by this search as well.
  446. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  447. or `C-c a #' to produce the list."
  448. :group 'org-agenda-custom-commands
  449. :type '(list
  450. (string :tag "Tags/TODO match to identify a project")
  451. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  452. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  453. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  454. (defcustom org-agenda-filter-effort-default-operator "<"
  455. "The default operator for effort estimate filtering.
  456. If you select an effort estimate limit without first pressing an operator,
  457. this one will be used."
  458. :group 'org-agenda-custom-commands
  459. :type '(choice (const :tag "less or equal" "<")
  460. (const :tag "greater or equal"">")
  461. (const :tag "equal" "=")))
  462. (defgroup org-agenda-skip nil
  463. "Options concerning skipping parts of agenda files."
  464. :tag "Org Agenda Skip"
  465. :group 'org-agenda)
  466. (defgroup org-agenda-daily/weekly nil
  467. "Options concerning the daily/weekly agenda."
  468. :tag "Org Agenda Daily/Weekly"
  469. :group 'org-agenda)
  470. (defgroup org-agenda-todo-list nil
  471. "Options concerning the global todo list agenda view."
  472. :tag "Org Agenda Todo List"
  473. :group 'org-agenda)
  474. (defgroup org-agenda-match-view nil
  475. "Options concerning the general tags/property/todo match agenda view."
  476. :tag "Org Agenda Match View"
  477. :group 'org-agenda)
  478. (defgroup org-agenda-search-view nil
  479. "Options concerning the general tags/property/todo match agenda view."
  480. :tag "Org Agenda Match View"
  481. :group 'org-agenda)
  482. (defvar org-agenda-archives-mode nil
  483. "Non-nil means the agenda will include archived items.
  484. If this is the symbol `trees', trees in the selected agenda scope
  485. that are marked with the ARCHIVE tag will be included anyway. When this is
  486. t, also all archive files associated with the current selection of agenda
  487. files will be included.")
  488. (defcustom org-agenda-skip-comment-trees t
  489. "Non-nil means skip trees that start with the COMMENT keyword.
  490. When nil, these trees are also scanned by agenda commands."
  491. :group 'org-agenda-skip
  492. :type 'boolean)
  493. (defcustom org-agenda-todo-list-sublevels t
  494. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  495. When nil, the sublevels of a TODO entry are not checked, resulting in
  496. potentially much shorter TODO lists."
  497. :group 'org-agenda-skip
  498. :group 'org-agenda-todo-list
  499. :type 'boolean)
  500. (defcustom org-agenda-todo-ignore-with-date nil
  501. "Non-nil means don't show entries with a date in the global todo list.
  502. You can use this if you prefer to mark mere appointments with a TODO keyword,
  503. but don't want them to show up in the TODO list.
  504. When this is set, it also covers deadlines and scheduled items, the settings
  505. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  506. will be ignored.
  507. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  508. :group 'org-agenda-skip
  509. :group 'org-agenda-todo-list
  510. :type 'boolean)
  511. (defcustom org-agenda-todo-ignore-scheduled nil
  512. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  513. This applies when creating the global todo list.
  514. Valid values are:
  515. past Don't show entries scheduled today or in the past.
  516. future Don't show entries scheduled in the future.
  517. The idea behind this is that by scheduling it, you don't want to
  518. think about it until the scheduled date.
  519. all Don't show any scheduled entries in the global todo list.
  520. The idea behind this is that by scheduling it, you have already
  521. \"taken care\" of this item.
  522. t Same as `all', for backward compatibility.
  523. See also `org-agenda-todo-ignore-with-date'.
  524. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  525. to make his option also apply to the tags-todo list."
  526. :group 'org-agenda-skip
  527. :group 'org-agenda-todo-list
  528. :type '(choice
  529. (const :tag "Ignore future-scheduled todos" future)
  530. (const :tag "Ignore past- or present-scheduled todos" past)
  531. (const :tag "Ignore all scheduled todos" all)
  532. (const :tag "Ignore all scheduled todos (compatibility)" t)
  533. (const :tag "Show scheduled todos" nil)))
  534. (defcustom org-agenda-todo-ignore-deadlines nil
  535. "Non-nil means ignore some deadlined TODO items when making TODO list.
  536. There are different motivations for using different values, please think
  537. carefully when configuring this variable.
  538. This applies when creating the global todo list.
  539. Valid values are:
  540. near Don't show near deadline entries. A deadline is near when it is
  541. closer than `org-deadline-warning-days' days. The idea behind this
  542. is that such items will appear in the agenda anyway.
  543. far Don't show TODO entries where a deadline has been defined, but
  544. the deadline is not near. This is useful if you don't want to
  545. use the todo list to figure out what to do now.
  546. past Don't show entries with a deadline timestamp for today or in the past.
  547. future Don't show entries with a deadline timestamp in the future, not even
  548. when they become `near' ones. Use it with caution.
  549. all Ignore all TODO entries that do have a deadline.
  550. t Same as `near', for backward compatibility.
  551. See also `org-agenda-todo-ignore-with-date'.
  552. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  553. to make his option also apply to the tags-todo list."
  554. :group 'org-agenda-skip
  555. :group 'org-agenda-todo-list
  556. :type '(choice
  557. (const :tag "Ignore near deadlines" near)
  558. (const :tag "Ignore near deadlines (compatibility)" t)
  559. (const :tag "Ignore far deadlines" far)
  560. (const :tag "Ignore all TODOs with a deadlines" all)
  561. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  562. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  563. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  564. The variables
  565. `org-agenda-todo-ignore-with-date',
  566. `org-agenda-todo-ignore-scheduled'
  567. `org-agenda-todo-ignore-deadlines'
  568. make the global TODO list skip entries that have time stamps of certain
  569. kinds. If this option is set, the same options will also apply for the
  570. tags-todo search, which is the general tags/property matcher
  571. restricted to unfinished TODO entries only."
  572. :group 'org-agenda-skip
  573. :group 'org-agenda-todo-list
  574. :group 'org-agenda-match-view
  575. :type 'boolean)
  576. (defcustom org-agenda-skip-scheduled-if-done nil
  577. "Non-nil means don't show scheduled items in agenda when they are done.
  578. This is relevant for the daily/weekly agenda, not for the TODO list. And
  579. it applies only to the actual date of the scheduling. Warnings about
  580. an item with a past scheduling dates are always turned off when the item
  581. is DONE."
  582. :group 'org-agenda-skip
  583. :group 'org-agenda-daily/weekly
  584. :type 'boolean)
  585. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  586. "Non-nil means skip scheduling line if same entry shows because of deadline.
  587. In the agenda of today, an entry can show up multiple times because
  588. it is both scheduled and has a nearby deadline, and maybe a plain time
  589. stamp as well.
  590. When this variable is t, then only the deadline is shown and the fact that
  591. the entry is scheduled today or was scheduled previously is not shown.
  592. When this variable is nil, the entry will be shown several times. When
  593. the variable is the symbol `not-today', then skip scheduled previously,
  594. but not scheduled today."
  595. :group 'org-agenda-skip
  596. :group 'org-agenda-daily/weekly
  597. :type '(choice
  598. (const :tag "Never" nil)
  599. (const :tag "Always" t)
  600. (const :tag "Not when scheduled today" not-today)))
  601. (defcustom org-agenda-skip-deadline-if-done nil
  602. "Non-nil means don't show deadlines when the corresponding item is done.
  603. When nil, the deadline is still shown and should give you a happy feeling.
  604. This is relevant for the daily/weekly agenda. And it applied only to the
  605. actually date of the deadline. Warnings about approaching and past-due
  606. deadlines are always turned off when the item is DONE."
  607. :group 'org-agenda-skip
  608. :group 'org-agenda-daily/weekly
  609. :type 'boolean)
  610. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  611. "Non-nil means skip deadline prewarning when entry is also scheduled.
  612. This will apply on all days where a prewarning for the deadline would
  613. be shown, but not at the day when the entry is actually due. On that day,
  614. the deadline will be shown anyway.
  615. This variable may be set to nil, t, or a number which will then give
  616. the number of days before the actual deadline when the prewarnings
  617. should resume.
  618. This can be used in a workflow where the first showing of the deadline will
  619. trigger you to schedule it, and then you don't want to be reminded of it
  620. because you will take care of it on the day when scheduled."
  621. :group 'org-agenda-skip
  622. :group 'org-agenda-daily/weekly
  623. :type '(choice
  624. (const :tag "Alwas show prewarning" nil)
  625. (const :tag "Remove prewarning if entry is scheduled" t)
  626. (integer :tag "Restart prewarning N days before deadline")))
  627. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  628. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  629. When non-nil, after the search for timestamps has matched once in an
  630. entry, the rest of the entry will not be searched."
  631. :group 'org-agenda-skip
  632. :type 'boolean)
  633. (defcustom org-agenda-skip-timestamp-if-done nil
  634. "Non-nil means don't select item by timestamp or -range if it is DONE."
  635. :group 'org-agenda-skip
  636. :group 'org-agenda-daily/weekly
  637. :type 'boolean)
  638. (defcustom org-agenda-dim-blocked-tasks t
  639. "Non-nil means dim blocked tasks in the agenda display.
  640. This causes some overhead during agenda construction, but if you
  641. have turned on `org-enforce-todo-dependencies',
  642. `org-enforce-todo-checkbox-dependencies', or any other blocking
  643. mechanism, this will create useful feedback in the agenda.
  644. Instead of t, this variable can also have the value `invisible'.
  645. Then blocked tasks will be invisible and only become visible when
  646. they become unblocked. An exemption to this behavior is when a task is
  647. blocked because of unchecked checkboxes below it. Since checkboxes do
  648. not show up in the agenda views, making this task invisible you remove any
  649. trace from agenda views that there is something to do. Therefore, a task
  650. that is blocked because of checkboxes will never be made invisible, it
  651. will only be dimmed."
  652. :group 'org-agenda-daily/weekly
  653. :group 'org-agenda-todo-list
  654. :type '(choice
  655. (const :tag "Do not dim" nil)
  656. (const :tag "Dim to a grey face" t)
  657. (const :tag "Make invisible" invisible)))
  658. (defcustom org-timeline-show-empty-dates 3
  659. "Non-nil means `org-timeline' also shows dates without an entry.
  660. When nil, only the days which actually have entries are shown.
  661. When t, all days between the first and the last date are shown.
  662. When an integer, show also empty dates, but if there is a gap of more than
  663. N days, just insert a special line indicating the size of the gap."
  664. :group 'org-agenda-skip
  665. :type '(choice
  666. (const :tag "None" nil)
  667. (const :tag "All" t)
  668. (integer :tag "at most")))
  669. (defgroup org-agenda-startup nil
  670. "Options concerning initial settings in the Agenda in Org Mode."
  671. :tag "Org Agenda Startup"
  672. :group 'org-agenda)
  673. (defcustom org-agenda-menu-show-matcher t
  674. "Non-nil menas show the match string in the agenda dispatcher menu.
  675. When nil, the mathcer string is not shown, but is put into the help-echo
  676. property so than moving the mouse over the command shows it.
  677. Setting it to nil if good if matcher strings are very long and/org of
  678. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  679. :group 'org-agenda
  680. :type 'boolean)
  681. (defcustom org-agenda-menu-two-column nil
  682. "Non-nil means, use two columns to show custom commands in the dispatcher.
  683. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  684. to nil."
  685. :group 'org-agenda
  686. :type 'boolean)
  687. (defcustom org-finalize-agenda-hook nil
  688. "Hook run just before displaying an agenda buffer."
  689. :group 'org-agenda-startup
  690. :type 'hook)
  691. (defcustom org-agenda-mouse-1-follows-link nil
  692. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  693. A longer mouse click will still set point. Does not work on XEmacs.
  694. Needs to be set before org.el is loaded."
  695. :group 'org-agenda-startup
  696. :type 'boolean)
  697. (defcustom org-agenda-start-with-follow-mode nil
  698. "The initial value of follow mode in a newly created agenda window."
  699. :group 'org-agenda-startup
  700. :type 'boolean)
  701. (defcustom org-agenda-show-outline-path t
  702. "Non-nil means show outline path in echo area after line motion."
  703. :group 'org-agenda-startup
  704. :type 'boolean)
  705. (defcustom org-agenda-start-with-entry-text-mode nil
  706. "The initial value of entry-text-mode in a newly created agenda window."
  707. :group 'org-agenda-startup
  708. :type 'boolean)
  709. (defcustom org-agenda-entry-text-maxlines 5
  710. "Number of text lines to be added when `E' is pressed in the agenda.
  711. Note that this variable only used during agenda display. Add add entry text
  712. when exporting the agenda, configure the variable
  713. `org-agenda-add-entry-ext-maxlines'."
  714. :group 'org-agenda
  715. :type 'integer)
  716. (defcustom org-agenda-entry-text-exclude-regexps nil
  717. "List of regular expressions to clean up entry text.
  718. The complete matches of all regular expressions in this list will be
  719. removed from entry text before it is shown in the agenda."
  720. :group 'org-agenda
  721. :type '(repeat (regexp)))
  722. (defvar org-agenda-entry-text-cleanup-hook nil
  723. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  724. This cleanup is done in a temporary buffer, so the function may inspect and
  725. change the entire buffer.
  726. Some default stuff like drawers and scheduling/deadline dates will already
  727. have been removed when this is called, as will any matches for regular
  728. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  729. (defvar org-agenda-include-inactive-timestamps nil
  730. "Non-nil means include inactive time stamps in agenda and timeline.")
  731. (defgroup org-agenda-windows nil
  732. "Options concerning the windows used by the Agenda in Org Mode."
  733. :tag "Org Agenda Windows"
  734. :group 'org-agenda)
  735. (defcustom org-agenda-window-setup 'reorganize-frame
  736. "How the agenda buffer should be displayed.
  737. Possible values for this option are:
  738. current-window Show agenda in the current window, keeping all other windows.
  739. other-window Use `switch-to-buffer-other-window' to display agenda.
  740. reorganize-frame Show only two windows on the current frame, the current
  741. window and the agenda.
  742. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  743. Also, when exiting the agenda, kill that frame.
  744. See also the variable `org-agenda-restore-windows-after-quit'."
  745. :group 'org-agenda-windows
  746. :type '(choice
  747. (const current-window)
  748. (const other-frame)
  749. (const other-window)
  750. (const reorganize-frame)))
  751. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  752. "The min and max height of the agenda window as a fraction of frame height.
  753. The value of the variable is a cons cell with two numbers between 0 and 1.
  754. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  755. :group 'org-agenda-windows
  756. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  757. (defcustom org-agenda-restore-windows-after-quit nil
  758. "Non-nil means restore window configuration open exiting agenda.
  759. Before the window configuration is changed for displaying the agenda,
  760. the current status is recorded. When the agenda is exited with
  761. `q' or `x' and this option is set, the old state is restored. If
  762. `org-agenda-window-setup' is `other-frame', the value of this
  763. option will be ignored."
  764. :group 'org-agenda-windows
  765. :type 'boolean)
  766. (defcustom org-agenda-ndays 7
  767. "Number of days to include in overview display.
  768. Should be 1 or 7.
  769. Custom commands can set this variable in the options section."
  770. :group 'org-agenda-daily/weekly
  771. :type 'integer)
  772. (defcustom org-agenda-start-on-weekday 1
  773. "Non-nil means start the overview always on the specified weekday.
  774. 0 denotes Sunday, 1 denotes Monday etc.
  775. When nil, always start on the current day.
  776. Custom commands can set this variable in the options section."
  777. :group 'org-agenda-daily/weekly
  778. :type '(choice (const :tag "Today" nil)
  779. (integer :tag "Weekday No.")))
  780. (defcustom org-agenda-show-all-dates t
  781. "Non-nil means `org-agenda' shows every day in the selected range.
  782. When nil, only the days which actually have entries are shown."
  783. :group 'org-agenda-daily/weekly
  784. :type 'boolean)
  785. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  786. "Format string for displaying dates in the agenda.
  787. Used by the daily/weekly agenda and by the timeline. This should be
  788. a format string understood by `format-time-string', or a function returning
  789. the formatted date as a string. The function must take a single argument,
  790. a calendar-style date list like (month day year)."
  791. :group 'org-agenda-daily/weekly
  792. :type '(choice
  793. (string :tag "Format string")
  794. (function :tag "Function")))
  795. (defun org-agenda-format-date-aligned (date)
  796. "Format a date string for display in the daily/weekly agenda, or timeline.
  797. This function makes sure that dates are aligned for easy reading."
  798. (require 'cal-iso)
  799. (let* ((dayname (calendar-day-name date))
  800. (day (cadr date))
  801. (day-of-week (calendar-day-of-week date))
  802. (month (car date))
  803. (monthname (calendar-month-name month))
  804. (year (nth 2 date))
  805. (iso-week (org-days-to-iso-week
  806. (calendar-absolute-from-gregorian date)))
  807. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  808. (1- year))
  809. ((and (= month 12) (<= iso-week 1))
  810. (1+ year))
  811. (t year)))
  812. (weekstring (if (= day-of-week 1)
  813. (format " W%02d" iso-week)
  814. "")))
  815. (format "%-10s %2d %s %4d%s"
  816. dayname day monthname year weekstring)))
  817. (defcustom org-agenda-time-leading-zero nil
  818. "Non-nil means use leading zero for military times in agenda.
  819. For example, 9:30am would become 09:30 rather than 9:30."
  820. :group 'org-agenda-daily/weekly
  821. :type 'boolean)
  822. (defcustom org-agenda-weekend-days '(6 0)
  823. "Which days are weekend?
  824. These days get the special face `org-agenda-date-weekend' in the agenda
  825. and timeline buffers."
  826. :group 'org-agenda-daily/weekly
  827. :type '(set :greedy t
  828. (const :tag "Monday" 1)
  829. (const :tag "Tuesday" 2)
  830. (const :tag "Wednesday" 3)
  831. (const :tag "Thursday" 4)
  832. (const :tag "Friday" 5)
  833. (const :tag "Saturday" 6)
  834. (const :tag "Sunday" 0)))
  835. (defcustom org-agenda-include-diary nil
  836. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  837. Custom commands can set this variable in the options section."
  838. :group 'org-agenda-daily/weekly
  839. :type 'boolean)
  840. (defcustom org-agenda-include-deadlines t
  841. "If non-nil, include entries within their deadline warning period.
  842. Custom commands can set this variable in the options section."
  843. :group 'org-agenda-daily/weekly
  844. :type 'boolean)
  845. (defcustom org-agenda-include-all-todo nil
  846. "Set means weekly/daily agenda will always contain all TODO entries.
  847. The TODO entries will be listed at the top of the agenda, before
  848. the entries for specific days.
  849. This option is deprecated, it is better to define a block agenda instead."
  850. :group 'org-agenda-daily/weekly
  851. :type 'boolean)
  852. (defcustom org-agenda-repeating-timestamp-show-all t
  853. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  854. When nil, only one occurrence is shown, either today or the
  855. nearest into the future."
  856. :group 'org-agenda-daily/weekly
  857. :type 'boolean)
  858. (defcustom org-scheduled-past-days 10000
  859. "No. of days to continue listing scheduled items that are not marked DONE.
  860. When an item is scheduled on a date, it shows up in the agenda on this
  861. day and will be listed until it is marked done for the number of days
  862. given here."
  863. :group 'org-agenda-daily/weekly
  864. :type 'integer)
  865. (defcustom org-agenda-log-mode-items '(closed clock)
  866. "List of items that should be shown in agenda log mode.
  867. This list may contain the following symbols:
  868. closed Show entries that have been closed on that day.
  869. clock Show entries that have received clocked time on that day.
  870. state Show all logged state changes.
  871. Note that instead of changing this variable, you can also press `C-u l' in
  872. the agenda to display all available LOG items temporarily."
  873. :group 'org-agenda-daily/weekly
  874. :type '(set :greedy t (const closed) (const clock) (const state)))
  875. (defcustom org-agenda-log-mode-add-notes t
  876. "Non-nil means add first line of notes to log entries in agenda views.
  877. If a log item like a state change or a clock entry is associated with
  878. notes, the first line of these notes will be added to the entry in the
  879. agenda display."
  880. :group 'org-agenda-daily/weekly
  881. :type 'boolean)
  882. (defcustom org-agenda-start-with-log-mode nil
  883. "The initial value of log-mode in a newly created agenda window."
  884. :group 'org-agenda-startup
  885. :group 'org-agenda-daily/weekly
  886. :type 'boolean)
  887. (defcustom org-agenda-start-with-clockreport-mode nil
  888. "The initial value of clockreport-mode in a newly created agenda window."
  889. :group 'org-agenda-startup
  890. :group 'org-agenda-daily/weekly
  891. :type 'boolean)
  892. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  893. "Property list with parameters for the clocktable in clockreport mode.
  894. This is the display mode that shows a clock table in the daily/weekly
  895. agenda, the properties for this dynamic block can be set here.
  896. The usual clocktable parameters are allowed here, but you cannot set
  897. the properties :name, :tstart, :tend, :block, and :scope - these will
  898. be overwritten to make sure the content accurately reflects the
  899. current display in the agenda."
  900. :group 'org-agenda-daily/weekly
  901. :type 'plist)
  902. (defcustom org-agenda-search-view-always-boolean nil
  903. "Non-nil means the search string is interpreted as individual parts.
  904. The search string for search view can either be interpreted as a phrase,
  905. or as a list of snippets that define a boolean search for a number of
  906. strings.
  907. When this is non-nil, the string will be split on whitespace, and each
  908. snippet will be searched individually, and all must match in order to
  909. select an entry. A snippet is then a single string of non-white
  910. characters, or a string in double quotes, or a regexp in {} braces.
  911. If a snippet is preceded by \"-\", the snippet must *not* match.
  912. \"+\" is syntactic sugar for positive selection. Each snippet may
  913. be found as a full word or a partial word, but see the variable
  914. `org-agenda-search-view-force-full-words'.
  915. When this is nil, search will look for the entire search phrase as one,
  916. with each space character matching any amount of whitespace, including
  917. line breaks.
  918. Even when this is nil, you can still switch to Boolean search dynamically
  919. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  920. is a regexp marked with braces like \"{abc}\", this will also switch to
  921. boolean search."
  922. :group 'org-agenda-search-view
  923. :type 'boolean)
  924. (if (fboundp 'defvaralias)
  925. (defvaralias 'org-agenda-search-view-search-words-only
  926. 'org-agenda-search-view-always-boolean))
  927. (defcustom org-agenda-search-view-force-full-words nil
  928. "Non-nil means, search words must be matches as complete words.
  929. When nil, they may also match part of a word."
  930. :group 'org-agenda-search-view
  931. :type 'boolean)
  932. (defgroup org-agenda-time-grid nil
  933. "Options concerning the time grid in the Org-mode Agenda."
  934. :tag "Org Agenda Time Grid"
  935. :group 'org-agenda)
  936. (defcustom org-agenda-search-headline-for-time t
  937. "Non-nil means search headline for a time-of-day.
  938. If the headline contains a time-of-day in one format or another, it will
  939. be used to sort the entry into the time sequence of items for a day.
  940. Some people have time stamps in the headline that refer to the creation
  941. time or so, and then this produces an unwanted side effect. If this is
  942. the case for your, use this variable to turn off searching the headline
  943. for a time."
  944. :group 'org-agenda-time-grid
  945. :type 'boolean)
  946. (defcustom org-agenda-use-time-grid t
  947. "Non-nil means show a time grid in the agenda schedule.
  948. A time grid is a set of lines for specific times (like every two hours between
  949. 8:00 and 20:00). The items scheduled for a day at specific times are
  950. sorted in between these lines.
  951. For details about when the grid will be shown, and what it will look like, see
  952. the variable `org-agenda-time-grid'."
  953. :group 'org-agenda-time-grid
  954. :type 'boolean)
  955. (defcustom org-agenda-time-grid
  956. '((daily today require-timed)
  957. "----------------"
  958. (800 1000 1200 1400 1600 1800 2000))
  959. "The settings for time grid for agenda display.
  960. This is a list of three items. The first item is again a list. It contains
  961. symbols specifying conditions when the grid should be displayed:
  962. daily if the agenda shows a single day
  963. weekly if the agenda shows an entire week
  964. today show grid on current date, independent of daily/weekly display
  965. require-timed show grid only if at least one item has a time specification
  966. The second item is a string which will be placed behind the grid time.
  967. The third item is a list of integers, indicating the times that should have
  968. a grid line."
  969. :group 'org-agenda-time-grid
  970. :type
  971. '(list
  972. (set :greedy t :tag "Grid Display Options"
  973. (const :tag "Show grid in single day agenda display" daily)
  974. (const :tag "Show grid in weekly agenda display" weekly)
  975. (const :tag "Always show grid for today" today)
  976. (const :tag "Show grid only if any timed entries are present"
  977. require-timed)
  978. (const :tag "Skip grid times already present in an entry"
  979. remove-match))
  980. (string :tag "Grid String")
  981. (repeat :tag "Grid Times" (integer :tag "Time"))))
  982. (defgroup org-agenda-sorting nil
  983. "Options concerning sorting in the Org-mode Agenda."
  984. :tag "Org Agenda Sorting"
  985. :group 'org-agenda)
  986. (defcustom org-agenda-sorting-strategy
  987. '((agenda habit-down time-up priority-down category-keep)
  988. (todo priority-down category-keep)
  989. (tags priority-down category-keep)
  990. (search category-keep))
  991. "Sorting structure for the agenda items of a single day.
  992. This is a list of symbols which will be used in sequence to determine
  993. if an entry should be listed before another entry. The following
  994. symbols are recognized:
  995. time-up Put entries with time-of-day indications first, early first
  996. time-down Put entries with time-of-day indications first, late first
  997. category-keep Keep the default order of categories, corresponding to the
  998. sequence in `org-agenda-files'.
  999. category-up Sort alphabetically by category, A-Z.
  1000. category-down Sort alphabetically by category, Z-A.
  1001. tag-up Sort alphabetically by last tag, A-Z.
  1002. tag-down Sort alphabetically by last tag, Z-A.
  1003. priority-up Sort numerically by priority, high priority last.
  1004. priority-down Sort numerically by priority, high priority first.
  1005. todo-state-up Sort by todo state, tasks that are done last.
  1006. todo-state-down Sort by todo state, tasks that are done first.
  1007. effort-up Sort numerically by estimated effort, high effort last.
  1008. effort-down Sort numerically by estimated effort, high effort first.
  1009. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1010. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1011. habit-up Put entries that are habits first
  1012. habit-down Put entries that are habits last
  1013. alpha-up Sort headlines alphabetically
  1014. alpha-down Sort headlines alphabetically, reversed
  1015. The different possibilities will be tried in sequence, and testing stops
  1016. if one comparison returns a \"not-equal\". For example, the default
  1017. '(time-up category-keep priority-down)
  1018. means: Pull out all entries having a specified time of day and sort them,
  1019. in order to make a time schedule for the current day the first thing in the
  1020. agenda listing for the day. Of the entries without a time indication, keep
  1021. the grouped in categories, don't sort the categories, but keep them in
  1022. the sequence given in `org-agenda-files'. Within each category sort by
  1023. priority.
  1024. Leaving out `category-keep' would mean that items will be sorted across
  1025. categories by priority.
  1026. Instead of a single list, this can also be a set of list for specific
  1027. contents, with a context symbol in the car of the list, any of
  1028. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1029. Custom commands can bind this variable in the options section."
  1030. :group 'org-agenda-sorting
  1031. :type `(choice
  1032. (repeat :tag "General" ,org-sorting-choice)
  1033. (list :tag "Individually"
  1034. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1035. (repeat ,org-sorting-choice))
  1036. (cons (const :tag "Strategy for TODO lists" todo)
  1037. (repeat ,org-sorting-choice))
  1038. (cons (const :tag "Strategy for Tags matches" tags)
  1039. (repeat ,org-sorting-choice))
  1040. (cons (const :tag "Strategy for search matches" search)
  1041. (repeat ,org-sorting-choice)))))
  1042. (defcustom org-agenda-cmp-user-defined nil
  1043. "A function to define the comparison `user-defined'.
  1044. This function must receive two arguments, agenda entry a and b.
  1045. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1046. the user comparison, return nil.
  1047. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1048. part of an agenda sorting strategy."
  1049. :group 'org-agenda-sorting
  1050. :type 'symbol)
  1051. (defcustom org-sort-agenda-notime-is-late t
  1052. "Non-nil means items without time are considered late.
  1053. This is only relevant for sorting. When t, items which have no explicit
  1054. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1055. do have a time. When nil, the default time is before 0:00. You can use this
  1056. option to decide if the schedule for today should come before or after timeless
  1057. agenda entries."
  1058. :group 'org-agenda-sorting
  1059. :type 'boolean)
  1060. (defcustom org-sort-agenda-noeffort-is-high t
  1061. "Non-nil means items without effort estimate are sorted as high effort.
  1062. This also applies when filtering an agenda view with respect to the
  1063. < or > effort operator. Then, tasks with no effort defined will be treated
  1064. as tasks with high effort.
  1065. When nil, such items are sorted as 0 minutes effort."
  1066. :group 'org-agenda-sorting
  1067. :type 'boolean)
  1068. (defgroup org-agenda-line-format nil
  1069. "Options concerning the entry prefix in the Org-mode agenda display."
  1070. :tag "Org Agenda Line Format"
  1071. :group 'org-agenda)
  1072. (defcustom org-agenda-prefix-format
  1073. '((agenda . " %-12:c%?-12t% s")
  1074. (timeline . " % s")
  1075. (todo . " %-12:c")
  1076. (tags . " %-12:c")
  1077. (search . " %-12:c"))
  1078. "Format specifications for the prefix of items in the agenda views.
  1079. An alist with four entries, for the different agenda types. The keys to the
  1080. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1081. are format strings.
  1082. This format works similar to a printf format, with the following meaning:
  1083. %c the category of the item, \"Diary\" for entries from the diary, or
  1084. as given by the CATEGORY keyword or derived from the file name.
  1085. %T the *last* tag of the item. Last because inherited tags come
  1086. first in the list.
  1087. %t the time-of-day specification if one applies to the entry, in the
  1088. format HH:MM
  1089. %s Scheduling/Deadline information, a short string
  1090. All specifiers work basically like the standard `%s' of printf, but may
  1091. contain two additional characters: A question mark just after the `%' and
  1092. a whitespace/punctuation character just before the final letter.
  1093. If the first character after `%' is a question mark, the entire field
  1094. will only be included if the corresponding value applies to the
  1095. current entry. This is useful for fields which should have fixed
  1096. width when present, but zero width when absent. For example,
  1097. \"%?-12t\" will result in a 12 character time field if a time of the
  1098. day is specified, but will completely disappear in entries which do
  1099. not contain a time.
  1100. If there is punctuation or whitespace character just before the final
  1101. format letter, this character will be appended to the field value if
  1102. the value is not empty. For example, the format \"%-12:c\" leads to
  1103. \"Diary: \" if the category is \"Diary\". If the category were be
  1104. empty, no additional colon would be inserted.
  1105. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1106. - Indent the line with two space characters
  1107. - Give the category in a 12 chars wide field, padded with whitespace on
  1108. the right (because of `-'). Append a colon if there is a category
  1109. (because of `:').
  1110. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1111. time, don't put in an empty field, just skip it (because of '?').
  1112. - Finally, put the scheduling information and append a whitespace.
  1113. As another example, if you don't want the time-of-day of entries in
  1114. the prefix, you could use:
  1115. (setq org-agenda-prefix-format \" %-11:c% s\")
  1116. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1117. `org-agenda-remove-tags'.
  1118. Custom commands can set this variable in the options section."
  1119. :type '(choice
  1120. (string :tag "General format")
  1121. (list :greedy t :tag "View dependent"
  1122. (cons (const agenda) (string :tag "Format"))
  1123. (cons (const timeline) (string :tag "Format"))
  1124. (cons (const todo) (string :tag "Format"))
  1125. (cons (const tags) (string :tag "Format"))
  1126. (cons (const search) (string :tag "Format"))))
  1127. :group 'org-agenda-line-format)
  1128. (defvar org-prefix-format-compiled nil
  1129. "The compiled version of the most recently used prefix format.
  1130. See the variable `org-agenda-prefix-format'.")
  1131. (defcustom org-agenda-todo-keyword-format "%-1s"
  1132. "Format for the TODO keyword in agenda lines.
  1133. Set this to something like \"%-12s\" if you want all TODO keywords
  1134. to occupy a fixed space in the agenda display."
  1135. :group 'org-agenda-line-format
  1136. :type 'string)
  1137. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1138. "Text preceding timerange entries in the agenda view.
  1139. This is a list with two strings. The first applies when the range
  1140. is entirely on one day. The second applies if the range spans several days.
  1141. The strings may have two \"%d\" format specifiers which will be filled
  1142. with the sequence number of the days, and the total number of days in the
  1143. range, respectively."
  1144. :group 'org-agenda-line-format
  1145. :type '(list
  1146. (string :tag "Deadline today ")
  1147. (choice :tag "Deadline relative"
  1148. (string :tag "Format string")
  1149. (function))))
  1150. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1151. "Text preceding scheduled items in the agenda view.
  1152. This is a list with two strings. The first applies when the item is
  1153. scheduled on the current day. The second applies when it has been scheduled
  1154. previously, it may contain a %d indicating that this is the nth time that
  1155. this item is scheduled, due to automatic rescheduling of unfinished items
  1156. for the following day. So this number is one larger than the number of days
  1157. that passed since this item was scheduled first."
  1158. :group 'org-agenda-line-format
  1159. :type '(list
  1160. (string :tag "Scheduled today ")
  1161. (string :tag "Scheduled previously")))
  1162. (defcustom org-agenda-inactive-leader "["
  1163. "Text preceding item pulled into the agenda by inactive time stamps.
  1164. These entries are added to the agenda when pressing \"[\"."
  1165. :group 'org-agenda-line-format
  1166. :type '(list
  1167. (string :tag "Scheduled today ")
  1168. (string :tag "Scheduled previously")))
  1169. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1170. "Text preceding deadline items in the agenda view.
  1171. This is a list with two strings. The first applies when the item has its
  1172. deadline on the current day. The second applies when it is in the past or
  1173. in the future, it may contain %d to capture how many days away the deadline
  1174. is (was)."
  1175. :group 'org-agenda-line-format
  1176. :type '(list
  1177. (string :tag "Deadline today ")
  1178. (choice :tag "Deadline relative"
  1179. (string :tag "Format string")
  1180. (function))))
  1181. (defcustom org-agenda-remove-times-when-in-prefix t
  1182. "Non-nil means remove duplicate time specifications in agenda items.
  1183. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1184. time-of-day specification in a headline or diary entry is extracted and
  1185. placed into the prefix. If this option is non-nil, the original specification
  1186. \(a timestamp or -range, or just a plain time(range) specification like
  1187. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1188. cluttered.
  1189. The option can be t or nil. It may also be the symbol `beg', indicating
  1190. that the time should only be removed when it is located at the beginning of
  1191. the headline/diary entry."
  1192. :group 'org-agenda-line-format
  1193. :type '(choice
  1194. (const :tag "Always" t)
  1195. (const :tag "Never" nil)
  1196. (const :tag "When at beginning of entry" beg)))
  1197. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1198. "Non-nil means remove time ranges specifications in agenda
  1199. items that span on several days."
  1200. :group 'org-agenda-line-format
  1201. :type 'boolean)
  1202. (defcustom org-agenda-default-appointment-duration nil
  1203. "Default duration for appointments that only have a starting time.
  1204. When nil, no duration is specified in such cases.
  1205. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1206. :group 'org-agenda-line-format
  1207. :type '(choice
  1208. (integer :tag "Minutes")
  1209. (const :tag "No default duration")))
  1210. (defcustom org-agenda-show-inherited-tags t
  1211. "Non-nil means show inherited tags in each agenda line."
  1212. :group 'org-agenda-line-format
  1213. :type 'boolean)
  1214. (defcustom org-agenda-hide-tags-regexp nil
  1215. "Regular expression used to filter away specific tags in agenda views.
  1216. This means that these tags will be present, but not be shown in the agenda
  1217. line. Secondary filtering will still work on the hidden tags.
  1218. Nil means don't hide any tags."
  1219. :group 'org-agenda-line-format
  1220. :type '(choice
  1221. (const :tag "Hide none" nil)
  1222. (string :tag "Regexp ")))
  1223. (defcustom org-agenda-remove-tags nil
  1224. "Non-nil means remove the tags from the headline copy in the agenda.
  1225. When this is the symbol `prefix', only remove tags when
  1226. `org-agenda-prefix-format' contains a `%T' specifier."
  1227. :group 'org-agenda-line-format
  1228. :type '(choice
  1229. (const :tag "Always" t)
  1230. (const :tag "Never" nil)
  1231. (const :tag "When prefix format contains %T" prefix)))
  1232. (if (fboundp 'defvaralias)
  1233. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1234. 'org-agenda-remove-tags))
  1235. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1236. "Shift tags in agenda items to this column.
  1237. If this number is positive, it specifies the column. If it is negative,
  1238. it means that the tags should be flushright to that column. For example,
  1239. -80 works well for a normal 80 character screen."
  1240. :group 'org-agenda-line-format
  1241. :type 'integer)
  1242. (if (fboundp 'defvaralias)
  1243. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1244. (defcustom org-agenda-fontify-priorities 'cookies
  1245. "Non-nil means highlight low and high priorities in agenda.
  1246. When t, the highest priority entries are bold, lowest priority italic.
  1247. However, settings in `org-priority-faces' will overrule these faces.
  1248. When this variable is the symbol `cookies', only fontify the
  1249. cookies, not the entire task.
  1250. This may also be an association list of priority faces, whose
  1251. keys are the character values of `org-highest-priority',
  1252. `org-default-priority', and `org-lowest-priority' (the default values
  1253. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1254. color as a string, or a list like `(:background \"Red\")'.
  1255. If it is a color, the variable `org-faces-easy-properties'
  1256. determines if it is a foreground or a background color."
  1257. :group 'org-agenda-line-format
  1258. :type '(choice
  1259. (const :tag "Never" nil)
  1260. (const :tag "Defaults" t)
  1261. (const :tag "Cookies only" cookies)
  1262. (repeat :tag "Specify"
  1263. (list (character :tag "Priority" :value ?A)
  1264. (choice :tag "Face "
  1265. (string :tag "Color")
  1266. (sexp :tag "Face"))))))
  1267. (defgroup org-agenda-column-view nil
  1268. "Options concerning column view in the agenda."
  1269. :tag "Org Agenda Column View"
  1270. :group 'org-agenda)
  1271. (defcustom org-agenda-columns-show-summaries t
  1272. "Non-nil means show summaries for columns displayed in the agenda view."
  1273. :group 'org-agenda-column-view
  1274. :type 'boolean)
  1275. (defcustom org-agenda-columns-remove-prefix-from-item t
  1276. "Non-nil means remove the prefix from a headline for agenda column view.
  1277. The special ITEM field in the columns format contains the current line, with
  1278. all information shown in other columns (like the TODO state or a tag).
  1279. When this variable is non-nil, also the agenda prefix will be removed from
  1280. the content of the ITEM field, to make sure as much as possible of the
  1281. headline can be shown in the limited width of the field."
  1282. :group 'org-agenda
  1283. :type 'boolean)
  1284. (defcustom org-agenda-columns-compute-summary-properties t
  1285. "Non-nil means recompute all summary properties before column view.
  1286. When column view in the agenda is listing properties that have a summary
  1287. operator, it can go to all relevant buffers and recompute the summaries
  1288. there. This can mean overhead for the agenda column view, but is necessary
  1289. to have thing up to date.
  1290. As a special case, a CLOCKSUM property also makes sure that the clock
  1291. computations are current."
  1292. :group 'org-agenda-column-view
  1293. :type 'boolean)
  1294. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1295. "Non-nil means the duration of an appointment will add to day effort.
  1296. The property to which appointment durations will be added is the one given
  1297. in the option `org-effort-property'. If an appointment does not have
  1298. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1299. is not set, an appointment without end time will not contribute to the time
  1300. estimate."
  1301. :group 'org-agenda-column-view
  1302. :type 'boolean)
  1303. (defcustom org-agenda-auto-exclude-function nil
  1304. "A function called with a tag to decide if it is filtered on '/ RET'.
  1305. The sole argument to the function, which is called once for each
  1306. possible tag, is a string giving the name of the tag. The
  1307. function should return either nil if the tag should be included
  1308. as normal, or \"-<TAG>\" to exclude the tag.
  1309. Note that for the purpose of tag filtering, only the lower-case version of
  1310. all tags will be considered, so that this function will only ever see
  1311. the lower-case version of all tags."
  1312. :group 'org-agenda
  1313. :type 'function)
  1314. (eval-when-compile
  1315. (require 'cl))
  1316. (require 'org)
  1317. (defun org-add-agenda-custom-command (entry)
  1318. "Replace or add a command in `org-agenda-custom-commands'.
  1319. This is mostly for hacking and trying a new command - once the command
  1320. works you probably want to add it to `org-agenda-custom-commands' for good."
  1321. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1322. (if ass
  1323. (setcdr ass (cdr entry))
  1324. (push entry org-agenda-custom-commands))))
  1325. ;;; Define the Org-agenda-mode
  1326. (defvar org-agenda-mode-map (make-sparse-keymap)
  1327. "Keymap for `org-agenda-mode'.")
  1328. (if (fboundp 'defvaralias)
  1329. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1330. (defvar org-agenda-menu) ; defined later in this file.
  1331. (defvar org-agenda-restrict) ; defined later in this file.
  1332. (defvar org-agenda-follow-mode nil)
  1333. (defvar org-agenda-entry-text-mode nil)
  1334. (defvar org-agenda-clockreport-mode nil)
  1335. (defvar org-agenda-show-log nil)
  1336. (defvar org-agenda-redo-command nil)
  1337. (defvar org-agenda-query-string nil)
  1338. (defvar org-agenda-mode-hook nil
  1339. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1340. (defvar org-agenda-type nil)
  1341. (defvar org-agenda-force-single-file nil)
  1342. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1343. (defun org-agenda-mode ()
  1344. "Mode for time-sorted view on action items in Org-mode files.
  1345. The following commands are available:
  1346. \\{org-agenda-mode-map}"
  1347. (interactive)
  1348. (kill-all-local-variables)
  1349. (setq org-agenda-undo-list nil
  1350. org-agenda-pending-undo-list nil
  1351. org-agenda-bulk-marked-entries nil)
  1352. (setq major-mode 'org-agenda-mode)
  1353. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1354. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1355. (setq mode-name "Org-Agenda")
  1356. (use-local-map org-agenda-mode-map)
  1357. (easy-menu-add org-agenda-menu)
  1358. (if org-startup-truncated (setq truncate-lines t))
  1359. (org-set-local 'line-move-visual nil)
  1360. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1361. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1362. ;; Make sure properties are removed when copying text
  1363. (when (boundp 'buffer-substring-filters)
  1364. (org-set-local 'buffer-substring-filters
  1365. (cons (lambda (x)
  1366. (set-text-properties 0 (length x) nil x) x)
  1367. buffer-substring-filters)))
  1368. (unless org-agenda-keep-modes
  1369. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1370. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1371. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1372. org-agenda-show-log org-agenda-start-with-log-mode))
  1373. (easy-menu-change
  1374. '("Agenda") "Agenda Files"
  1375. (append
  1376. (list
  1377. (vector
  1378. (if (get 'org-agenda-files 'org-restrict)
  1379. "Restricted to single file"
  1380. "Edit File List")
  1381. '(org-edit-agenda-file-list)
  1382. (not (get 'org-agenda-files 'org-restrict)))
  1383. "--")
  1384. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1385. (org-agenda-set-mode-name)
  1386. (apply
  1387. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1388. (list 'org-agenda-mode-hook)))
  1389. (substitute-key-definition 'undo 'org-agenda-undo
  1390. org-agenda-mode-map global-map)
  1391. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1392. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1393. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1394. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1395. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1396. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1397. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1398. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1399. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1400. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1401. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1402. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1403. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1404. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1405. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1406. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1407. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1408. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1409. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1410. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1411. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1412. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1413. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1414. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1415. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1416. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1417. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1418. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1419. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1420. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1421. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1422. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1423. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1424. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1425. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1426. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1427. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1428. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1429. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1430. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1431. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1432. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1433. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1434. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1435. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1436. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1437. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1438. (while l (org-defkey org-agenda-mode-map
  1439. (int-to-string (pop l)) 'digit-argument)))
  1440. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1441. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1442. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1443. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1444. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1445. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1446. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1447. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1448. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1449. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1450. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1451. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1452. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1453. 'org-clock-modify-effort-estimate)
  1454. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1455. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1456. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1457. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1458. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1459. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1460. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1461. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1462. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1463. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1464. (substitute-key-definition 'next-line 'org-agenda-next-line
  1465. org-agenda-mode-map global-map)
  1466. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1467. org-agenda-mode-map global-map)
  1468. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1469. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1470. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1471. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1472. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1473. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1474. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1475. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1476. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1477. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1478. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1479. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1480. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1481. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1482. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1483. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1484. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1485. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1486. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1487. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1488. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1489. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1490. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1491. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1492. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1493. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1494. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1495. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1496. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1497. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1498. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1499. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1500. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1501. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1502. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1503. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1504. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1505. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1506. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1507. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1508. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1509. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1510. (when org-agenda-mouse-1-follows-link
  1511. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1512. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1513. '("Agenda"
  1514. ("Agenda Files")
  1515. "--"
  1516. ("Agenda Dates"
  1517. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1518. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1519. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1520. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1521. "--"
  1522. ("View"
  1523. ["Day View" org-agenda-day-view
  1524. :active (org-agenda-check-type nil 'agenda)
  1525. :style radio :selected (equal org-agenda-ndays 1)
  1526. :keys "v d (or just d)"]
  1527. ["Week View" org-agenda-week-view
  1528. :active (org-agenda-check-type nil 'agenda)
  1529. :style radio :selected (equal org-agenda-ndays 7)
  1530. :keys "v w (or just w)"]
  1531. ["Month View" org-agenda-month-view
  1532. :active (org-agenda-check-type nil 'agenda)
  1533. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1534. :keys "v m"]
  1535. ["Year View" org-agenda-year-view
  1536. :active (org-agenda-check-type nil 'agenda)
  1537. :style radio :selected (member org-agenda-ndays '(365 366))
  1538. :keys "v y"]
  1539. "--"
  1540. ["Include Diary" org-agenda-toggle-diary
  1541. :style toggle :selected org-agenda-include-diary
  1542. :active (org-agenda-check-type nil 'agenda)]
  1543. ["Include Deadlines" org-agenda-toggle-deadlines
  1544. :style toggle :selected org-agenda-include-deadlines
  1545. :active (org-agenda-check-type nil 'agenda)]
  1546. ["Use Time Grid" org-agenda-toggle-time-grid
  1547. :style toggle :selected org-agenda-use-time-grid
  1548. :active (org-agenda-check-type nil 'agenda)]
  1549. "--"
  1550. ["Show clock report" org-agenda-clockreport-mode
  1551. :style toggle :selected org-agenda-clockreport-mode
  1552. :active (org-agenda-check-type nil 'agenda)]
  1553. ["Show some entry text" org-agenda-entry-text-mode
  1554. :style toggle :selected org-agenda-entry-text-mode
  1555. :active t]
  1556. "--"
  1557. ["Show Logbook entries" org-agenda-log-mode
  1558. :style toggle :selected org-agenda-show-log
  1559. :active (org-agenda-check-type nil 'agenda 'timeline)
  1560. :keys "v l (or just l)"]
  1561. ["Include archived trees" org-agenda-archives-mode
  1562. :style toggle :selected org-agenda-archives-mode :active t
  1563. :keys "v a"]
  1564. ["Include archive files" (org-agenda-archives-mode t)
  1565. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1566. :keys "v A"]
  1567. "--"
  1568. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1569. ["Write view to file" org-write-agenda t]
  1570. ["Rebuild buffer" org-agenda-redo t]
  1571. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1572. "--"
  1573. ["Show original entry" org-agenda-show t]
  1574. ["Go To (other window)" org-agenda-goto t]
  1575. ["Go To (this window)" org-agenda-switch-to t]
  1576. ["Follow Mode" org-agenda-follow-mode
  1577. :style toggle :selected org-agenda-follow-mode :active t]
  1578. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1579. "--"
  1580. ("TODO"
  1581. ["Cycle TODO" org-agenda-todo t]
  1582. ["Next TODO set" org-agenda-todo-nextset t]
  1583. ["Previous TODO set" org-agenda-todo-previousset t]
  1584. ["Add note" org-agenda-add-note t])
  1585. ("Archive/Refile/Delete"
  1586. ["Archive default" org-agenda-archive-default t]
  1587. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1588. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1589. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1590. ["Archive subtree" org-agenda-archive t]
  1591. "--"
  1592. ["Refile" org-agenda-refile t]
  1593. "--"
  1594. ["Delete subtree" org-agenda-kill t])
  1595. ("Bulk action"
  1596. ["Mark entry" org-agenda-bulk-mark t]
  1597. ["Unmark entry" org-agenda-bulk-unmark t]
  1598. ["Act on all marked" org-agenda-bulk-action t]
  1599. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1600. "--"
  1601. ("Tags and Properties"
  1602. ["Show all Tags" org-agenda-show-tags t]
  1603. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1604. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1605. "--"
  1606. ["Column View" org-columns t])
  1607. ("Deadline/Schedule"
  1608. ["Schedule" org-agenda-schedule t]
  1609. ["Set Deadline" org-agenda-deadline t]
  1610. "--"
  1611. ["Mark item" org-agenda-action :active t :keys "k m"]
  1612. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1613. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1614. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1615. "--"
  1616. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1617. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1618. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1619. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1620. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1621. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1622. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1623. ("Clock and Effort"
  1624. ["Clock in" org-agenda-clock-in t]
  1625. ["Clock out" org-agenda-clock-out t]
  1626. ["Clock cancel" org-agenda-clock-cancel t]
  1627. ["Goto running clock" org-clock-goto t]
  1628. "--"
  1629. ["Set Effort" org-agenda-set-effort t]
  1630. ["Change clocked effort" org-clock-modify-effort-estimate
  1631. (org-clock-is-active)])
  1632. ("Priority"
  1633. ["Set Priority" org-agenda-priority t]
  1634. ["Increase Priority" org-agenda-priority-up t]
  1635. ["Decrease Priority" org-agenda-priority-down t]
  1636. ["Show Priority" org-agenda-show-priority t])
  1637. ("Calendar/Diary"
  1638. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1639. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1640. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1641. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1642. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1643. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1644. "--"
  1645. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1646. "--"
  1647. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1648. "--"
  1649. ("MobileOrg"
  1650. ["Push Files and Views" org-mobile-push t]
  1651. ["Get Captured and Flagged" org-mobile-pull t]
  1652. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1653. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1654. "--"
  1655. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1656. "--"
  1657. ["Quit" org-agenda-quit t]
  1658. ["Exit and Release Buffers" org-agenda-exit t]
  1659. ))
  1660. ;;; Agenda undo
  1661. (defvar org-agenda-allow-remote-undo t
  1662. "Non-nil means allow remote undo from the agenda buffer.")
  1663. (defvar org-agenda-undo-list nil
  1664. "List of undoable operations in the agenda since last refresh.")
  1665. (defvar org-agenda-undo-has-started-in nil
  1666. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1667. (defvar org-agenda-pending-undo-list nil
  1668. "In a series of undo commands, this is the list of remaining undo items.")
  1669. (defun org-agenda-undo ()
  1670. "Undo a remote editing step in the agenda.
  1671. This undoes changes both in the agenda buffer and in the remote buffer
  1672. that have been changed along."
  1673. (interactive)
  1674. (or org-agenda-allow-remote-undo
  1675. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1676. (if (not (eq this-command last-command))
  1677. (setq org-agenda-undo-has-started-in nil
  1678. org-agenda-pending-undo-list org-agenda-undo-list))
  1679. (if (not org-agenda-pending-undo-list)
  1680. (error "No further undo information"))
  1681. (let* ((entry (pop org-agenda-pending-undo-list))
  1682. buf line cmd rembuf)
  1683. (setq cmd (pop entry) line (pop entry))
  1684. (setq rembuf (nth 2 entry))
  1685. (org-with-remote-undo rembuf
  1686. (while (bufferp (setq buf (pop entry)))
  1687. (if (pop entry)
  1688. (with-current-buffer buf
  1689. (let ((last-undo-buffer buf)
  1690. (inhibit-read-only t))
  1691. (unless (memq buf org-agenda-undo-has-started-in)
  1692. (push buf org-agenda-undo-has-started-in)
  1693. (make-local-variable 'pending-undo-list)
  1694. (undo-start))
  1695. (while (and pending-undo-list
  1696. (listp pending-undo-list)
  1697. (not (car pending-undo-list)))
  1698. (pop pending-undo-list))
  1699. (undo-more 1))))))
  1700. (org-goto-line line)
  1701. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1702. (defun org-verify-change-for-undo (l1 l2)
  1703. "Verify that a real change occurred between the undo lists L1 and L2."
  1704. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1705. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1706. (not (eq l1 l2)))
  1707. ;;; Agenda dispatch
  1708. (defvar org-agenda-restrict nil)
  1709. (defvar org-agenda-restrict-begin (make-marker))
  1710. (defvar org-agenda-restrict-end (make-marker))
  1711. (defvar org-agenda-last-dispatch-buffer nil)
  1712. (defvar org-agenda-overriding-restriction nil)
  1713. ;;;###autoload
  1714. (defun org-agenda (&optional arg keys restriction)
  1715. "Dispatch agenda commands to collect entries to the agenda buffer.
  1716. Prompts for a command to execute. Any prefix arg will be passed
  1717. on to the selected command. The default selections are:
  1718. a Call `org-agenda-list' to display the agenda for current day or week.
  1719. t Call `org-todo-list' to display the global todo list.
  1720. T Call `org-todo-list' to display the global todo list, select only
  1721. entries with a specific TODO keyword (the user gets a prompt).
  1722. m Call `org-tags-view' to display headlines with tags matching
  1723. a condition (the user is prompted for the condition).
  1724. M Like `m', but select only TODO entries, no ordinary headlines.
  1725. L Create a timeline for the current buffer.
  1726. e Export views to associated files.
  1727. s Search entries for keywords.
  1728. / Multi occur across all agenda files and also files listed
  1729. in `org-agenda-text-search-extra-files'.
  1730. < Restrict agenda commands to buffer, subtree, or region.
  1731. Press several times to get the desired effect.
  1732. > Remove a previous restriction.
  1733. # List \"stuck\" projects.
  1734. ! Configure what \"stuck\" means.
  1735. C Configure custom agenda commands.
  1736. More commands can be added by configuring the variable
  1737. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1738. searches can be pre-defined in this way.
  1739. If the current buffer is in Org-mode and visiting a file, you can also
  1740. first press `<' once to indicate that the agenda should be temporarily
  1741. \(until the next use of \\[org-agenda]) restricted to the current file.
  1742. Pressing `<' twice means to restrict to the current subtree or region
  1743. \(if active)."
  1744. (interactive "P")
  1745. (catch 'exit
  1746. (let* ((prefix-descriptions nil)
  1747. (org-agenda-window-setup (if (equal (buffer-name)
  1748. org-agenda-buffer-name)
  1749. 'current-window
  1750. org-agenda-window-setup))
  1751. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1752. (org-agenda-custom-commands
  1753. ;; normalize different versions
  1754. (delq nil
  1755. (mapcar
  1756. (lambda (x)
  1757. (cond ((stringp (cdr x))
  1758. (push x prefix-descriptions)
  1759. nil)
  1760. ((stringp (nth 1 x)) x)
  1761. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1762. (t (cons (car x) (cons "" (cdr x))))))
  1763. org-agenda-custom-commands)))
  1764. (buf (current-buffer))
  1765. (bfn (buffer-file-name (buffer-base-buffer)))
  1766. entry key type match lprops ans)
  1767. ;; Turn off restriction unless there is an overriding one,
  1768. (unless org-agenda-overriding-restriction
  1769. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1770. ;; There is a request to keep the file list in place
  1771. (put 'org-agenda-files 'org-restrict nil))
  1772. (setq org-agenda-restrict nil)
  1773. (move-marker org-agenda-restrict-begin nil)
  1774. (move-marker org-agenda-restrict-end nil))
  1775. ;; Delete old local properties
  1776. (put 'org-agenda-redo-command 'org-lprops nil)
  1777. ;; Remember where this call originated
  1778. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1779. (unless keys
  1780. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1781. keys (car ans)
  1782. restriction (cdr ans)))
  1783. ;; Establish the restriction, if any
  1784. (when (and (not org-agenda-overriding-restriction) restriction)
  1785. (put 'org-agenda-files 'org-restrict (list bfn))
  1786. (cond
  1787. ((eq restriction 'region)
  1788. (setq org-agenda-restrict t)
  1789. (move-marker org-agenda-restrict-begin (region-beginning))
  1790. (move-marker org-agenda-restrict-end (region-end)))
  1791. ((eq restriction 'subtree)
  1792. (save-excursion
  1793. (setq org-agenda-restrict t)
  1794. (org-back-to-heading t)
  1795. (move-marker org-agenda-restrict-begin (point))
  1796. (move-marker org-agenda-restrict-end
  1797. (progn (org-end-of-subtree t)))))))
  1798. ;; For example the todo list should not need it (but does...)
  1799. (cond
  1800. ((setq entry (assoc keys org-agenda-custom-commands))
  1801. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1802. (progn
  1803. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1804. lprops (nth 4 entry))
  1805. (put 'org-agenda-redo-command 'org-lprops lprops)
  1806. (cond
  1807. ((eq type 'agenda)
  1808. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1809. ((eq type 'alltodo)
  1810. (org-let lprops '(org-todo-list current-prefix-arg)))
  1811. ((eq type 'search)
  1812. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1813. ((eq type 'stuck)
  1814. (org-let lprops '(org-agenda-list-stuck-projects
  1815. current-prefix-arg)))
  1816. ((eq type 'tags)
  1817. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1818. ((eq type 'tags-todo)
  1819. (org-let lprops '(org-tags-view '(4) match)))
  1820. ((eq type 'todo)
  1821. (org-let lprops '(org-todo-list match)))
  1822. ((eq type 'tags-tree)
  1823. (org-check-for-org-mode)
  1824. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1825. ((eq type 'todo-tree)
  1826. (org-check-for-org-mode)
  1827. (org-let lprops
  1828. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1829. (regexp-quote match) "\\>"))))
  1830. ((eq type 'occur-tree)
  1831. (org-check-for-org-mode)
  1832. (org-let lprops '(org-occur match)))
  1833. ((functionp type)
  1834. (org-let lprops '(funcall type match)))
  1835. ((fboundp type)
  1836. (org-let lprops '(funcall type match)))
  1837. (t (error "Invalid custom agenda command type %s" type))))
  1838. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1839. ((equal keys "C")
  1840. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1841. (customize-variable 'org-agenda-custom-commands))
  1842. ((equal keys "a") (call-interactively 'org-agenda-list))
  1843. ((equal keys "s") (call-interactively 'org-search-view))
  1844. ((equal keys "t") (call-interactively 'org-todo-list))
  1845. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1846. ((equal keys "m") (call-interactively 'org-tags-view))
  1847. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1848. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1849. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1850. (org-add-hook
  1851. 'post-command-hook
  1852. (lambda ()
  1853. (unless (current-message)
  1854. (let* ((m (org-agenda-get-any-marker))
  1855. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1856. (when note
  1857. (message (concat
  1858. "FLAGGING-NOTE ([?] for more info): "
  1859. (org-add-props
  1860. (replace-regexp-in-string
  1861. "\\\\n" "//"
  1862. (copy-sequence note))
  1863. nil 'face 'org-warning)))))))
  1864. t t))
  1865. ((equal keys "L")
  1866. (unless (org-mode-p)
  1867. (error "This is not an Org-mode file"))
  1868. (unless restriction
  1869. (put 'org-agenda-files 'org-restrict (list bfn))
  1870. (org-call-with-arg 'org-timeline arg)))
  1871. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1872. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1873. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1874. (t (error "Invalid agenda key"))))))
  1875. (defun org-agenda-normalize-custom-commands (cmds)
  1876. (delq nil
  1877. (mapcar
  1878. (lambda (x)
  1879. (cond ((stringp (cdr x)) nil)
  1880. ((stringp (nth 1 x)) x)
  1881. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1882. (t (cons (car x) (cons "" (cdr x))))))
  1883. cmds)))
  1884. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1885. "The user interface for selecting an agenda command."
  1886. (catch 'exit
  1887. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1888. (restrict-ok (and bfn (org-mode-p)))
  1889. (region-p (org-region-active-p))
  1890. (custom org-agenda-custom-commands)
  1891. (selstring "")
  1892. restriction second-time
  1893. c entry key type match prefixes rmheader header-end custom1 desc
  1894. line lines left right n n1)
  1895. (save-window-excursion
  1896. (delete-other-windows)
  1897. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1898. (erase-buffer)
  1899. (insert (eval-when-compile
  1900. (let ((header
  1901. "
  1902. Press key for an agenda command: < Buffer, subtree/region restriction
  1903. -------------------------------- > Remove restriction
  1904. a Agenda for current week or day e Export agenda views
  1905. t List of all TODO entries T Entries with special TODO kwd
  1906. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1907. L Timeline for current buffer # List stuck projects (!=configure)
  1908. s Search for keywords C Configure custom agenda commands
  1909. / Multi-occur ? Find :FLAGGED: entries
  1910. ")
  1911. (start 0))
  1912. (while (string-match
  1913. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1914. header start)
  1915. (setq start (match-end 0))
  1916. (add-text-properties (match-beginning 2) (match-end 2)
  1917. '(face bold) header))
  1918. header)))
  1919. (setq header-end (move-marker (make-marker) (point)))
  1920. (while t
  1921. (setq custom1 custom)
  1922. (when (eq rmheader t)
  1923. (org-goto-line 1)
  1924. (re-search-forward ":" nil t)
  1925. (delete-region (match-end 0) (point-at-eol))
  1926. (forward-char 1)
  1927. (looking-at "-+")
  1928. (delete-region (match-end 0) (point-at-eol))
  1929. (move-marker header-end (match-end 0)))
  1930. (goto-char header-end)
  1931. (delete-region (point) (point-max))
  1932. ;; Produce all the lines that describe custom commands and prefixes
  1933. (setq lines nil)
  1934. (while (setq entry (pop custom1))
  1935. (setq key (car entry) desc (nth 1 entry)
  1936. type (nth 2 entry)
  1937. match (nth 3 entry))
  1938. (if (> (length key) 1)
  1939. (add-to-list 'prefixes (string-to-char key))
  1940. (setq line
  1941. (format
  1942. "%-4s%-14s"
  1943. (org-add-props (copy-sequence key)
  1944. '(face bold))
  1945. (cond
  1946. ((string-match "\\S-" desc) desc)
  1947. ((eq type 'agenda) "Agenda for current week or day")
  1948. ((eq type 'alltodo) "List of all TODO entries")
  1949. ((eq type 'search) "Word search")
  1950. ((eq type 'stuck) "List of stuck projects")
  1951. ((eq type 'todo) "TODO keyword")
  1952. ((eq type 'tags) "Tags query")
  1953. ((eq type 'tags-todo) "Tags (TODO)")
  1954. ((eq type 'tags-tree) "Tags tree")
  1955. ((eq type 'todo-tree) "TODO kwd tree")
  1956. ((eq type 'occur-tree) "Occur tree")
  1957. ((functionp type) (if (symbolp type)
  1958. (symbol-name type)
  1959. "Lambda expression"))
  1960. (t "???"))))
  1961. (if org-agenda-menu-show-matcher
  1962. (setq line
  1963. (concat line ": "
  1964. (cond
  1965. ((stringp match)
  1966. (setq match (copy-sequence match))
  1967. (org-add-props match nil 'face 'org-warning))
  1968. (match
  1969. (format "set of %d commands" (length match)))
  1970. (t ""))))
  1971. (if (org-string-nw-p match)
  1972. (add-text-properties
  1973. 0 (length line) (list 'help-echo
  1974. (concat "Matcher: "match)) line)))
  1975. (push line lines)))
  1976. (setq lines (nreverse lines))
  1977. (when prefixes
  1978. (mapc (lambda (x)
  1979. (push
  1980. (format "%s %s"
  1981. (org-add-props (char-to-string x)
  1982. nil 'face 'bold)
  1983. (or (cdr (assoc (concat selstring
  1984. (char-to-string x))
  1985. prefix-descriptions))
  1986. "Prefix key"))
  1987. lines))
  1988. prefixes))
  1989. ;; Check if we should display in two columns
  1990. (if org-agenda-menu-two-column
  1991. (progn
  1992. (setq n (length lines)
  1993. n1 (+ (/ n 2) (mod n 2))
  1994. right (nthcdr n1 lines)
  1995. left (copy-sequence lines))
  1996. (setcdr (nthcdr (1- n1) left) nil))
  1997. (setq left lines right nil))
  1998. (while left
  1999. (insert "\n" (pop left))
  2000. (when right
  2001. (if (< (current-column) 40)
  2002. (move-to-column 40 t)
  2003. (insert " "))
  2004. (insert (pop right))))
  2005. ;; Make the window the right size
  2006. (goto-char (point-min))
  2007. (if second-time
  2008. (if (not (pos-visible-in-window-p (point-max)))
  2009. (org-fit-window-to-buffer))
  2010. (setq second-time t)
  2011. (org-fit-window-to-buffer))
  2012. ;; Ask for selection
  2013. (message "Press key for agenda command%s:"
  2014. (if (or restrict-ok org-agenda-overriding-restriction)
  2015. (if org-agenda-overriding-restriction
  2016. " (restriction lock active)"
  2017. (if restriction
  2018. (format " (restricted to %s)" restriction)
  2019. " (unrestricted)"))
  2020. ""))
  2021. (setq c (read-char-exclusive))
  2022. (message "")
  2023. (cond
  2024. ((assoc (char-to-string c) custom)
  2025. (setq selstring (concat selstring (char-to-string c)))
  2026. (throw 'exit (cons selstring restriction)))
  2027. ((memq c prefixes)
  2028. (setq selstring (concat selstring (char-to-string c))
  2029. prefixes nil
  2030. rmheader (or rmheader t)
  2031. custom (delq nil (mapcar
  2032. (lambda (x)
  2033. (if (or (= (length (car x)) 1)
  2034. (/= (string-to-char (car x)) c))
  2035. nil
  2036. (cons (substring (car x) 1) (cdr x))))
  2037. custom))))
  2038. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2039. (message "Restriction is only possible in Org-mode buffers")
  2040. (ding) (sit-for 1))
  2041. ((eq c ?1)
  2042. (org-agenda-remove-restriction-lock 'noupdate)
  2043. (setq restriction 'buffer))
  2044. ((eq c ?0)
  2045. (org-agenda-remove-restriction-lock 'noupdate)
  2046. (setq restriction (if region-p 'region 'subtree)))
  2047. ((eq c ?<)
  2048. (org-agenda-remove-restriction-lock 'noupdate)
  2049. (setq restriction
  2050. (cond
  2051. ((eq restriction 'buffer)
  2052. (if region-p 'region 'subtree))
  2053. ((memq restriction '(subtree region))
  2054. nil)
  2055. (t 'buffer))))
  2056. ((eq c ?>)
  2057. (org-agenda-remove-restriction-lock 'noupdate)
  2058. (setq restriction nil))
  2059. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2060. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2061. ((and (> (length selstring) 0) (eq c ?\d))
  2062. (delete-window)
  2063. (org-agenda-get-restriction-and-command prefix-descriptions))
  2064. ((equal c ?q) (error "Abort"))
  2065. (t (error "Invalid key %c" c))))))))
  2066. (defun org-run-agenda-series (name series)
  2067. (org-let (nth 1 series) '(org-prepare-agenda name))
  2068. (let* ((org-agenda-multi t)
  2069. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2070. (cmds (car series))
  2071. (gprops (nth 1 series))
  2072. match ;; The byte compiler incorrectly complains about this. Keep it!
  2073. cmd type lprops)
  2074. (while (setq cmd (pop cmds))
  2075. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2076. (cond
  2077. ((eq type 'agenda)
  2078. (org-let2 gprops lprops
  2079. '(call-interactively 'org-agenda-list)))
  2080. ((eq type 'alltodo)
  2081. (org-let2 gprops lprops
  2082. '(call-interactively 'org-todo-list)))
  2083. ((eq type 'search)
  2084. (org-let2 gprops lprops
  2085. '(org-search-view current-prefix-arg match nil)))
  2086. ((eq type 'stuck)
  2087. (org-let2 gprops lprops
  2088. '(call-interactively 'org-agenda-list-stuck-projects)))
  2089. ((eq type 'tags)
  2090. (org-let2 gprops lprops
  2091. '(org-tags-view current-prefix-arg match)))
  2092. ((eq type 'tags-todo)
  2093. (org-let2 gprops lprops
  2094. '(org-tags-view '(4) match)))
  2095. ((eq type 'todo)
  2096. (org-let2 gprops lprops
  2097. '(org-todo-list match)))
  2098. ((fboundp type)
  2099. (org-let2 gprops lprops
  2100. '(funcall type match)))
  2101. (t (error "Invalid type in command series"))))
  2102. (widen)
  2103. (setq org-agenda-redo-command redo)
  2104. (goto-char (point-min)))
  2105. (org-fit-agenda-window)
  2106. (org-let (nth 1 series) '(org-finalize-agenda)))
  2107. ;;;###autoload
  2108. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2109. "Run an agenda command in batch mode and send the result to STDOUT.
  2110. If CMD-KEY is a string of length 1, it is used as a key in
  2111. `org-agenda-custom-commands' and triggers this command. If it is a
  2112. longer string it is used as a tags/todo match string.
  2113. Parameters are alternating variable names and values that will be bound
  2114. before running the agenda command."
  2115. (let (pars)
  2116. (while parameters
  2117. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2118. (if (> (length cmd-key) 2)
  2119. (eval (list 'let (nreverse pars)
  2120. (list 'org-tags-view nil cmd-key)))
  2121. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2122. (set-buffer org-agenda-buffer-name)
  2123. (princ (org-encode-for-stdout (buffer-string)))))
  2124. ;(defun org-encode-for-stdout (string)
  2125. ; (if (fboundp 'encode-coding-string)
  2126. ; (encode-coding-string string buffer-file-coding-system)
  2127. ; string))
  2128. (defun org-encode-for-stdout (string)
  2129. string)
  2130. (defvar org-agenda-info nil)
  2131. ;;;###autoload
  2132. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2133. "Run an agenda command in batch mode and send the result to STDOUT.
  2134. If CMD-KEY is a string of length 1, it is used as a key in
  2135. `org-agenda-custom-commands' and triggers this command. If it is a
  2136. longer string it is used as a tags/todo match string.
  2137. Parameters are alternating variable names and values that will be bound
  2138. before running the agenda command.
  2139. The output gives a line for each selected agenda item. Each
  2140. item is a list of comma-separated values, like this:
  2141. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2142. category The category of the item
  2143. head The headline, without TODO kwd, TAGS and PRIORITY
  2144. type The type of the agenda entry, can be
  2145. todo selected in TODO match
  2146. tagsmatch selected in tags match
  2147. diary imported from diary
  2148. deadline a deadline on given date
  2149. scheduled scheduled on given date
  2150. timestamp entry has timestamp on given date
  2151. closed entry was closed on given date
  2152. upcoming-deadline warning about deadline
  2153. past-scheduled forwarded scheduled item
  2154. block entry has date block including g. date
  2155. todo The todo keyword, if any
  2156. tags All tags including inherited ones, separated by colons
  2157. date The relevant date, like 2007-2-14
  2158. time The time, like 15:00-16:50
  2159. extra Sting with extra planning info
  2160. priority-l The priority letter if any was given
  2161. priority-n The computed numerical priority
  2162. agenda-day The day in the agenda where this is listed"
  2163. (let (pars)
  2164. (while parameters
  2165. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2166. (push (list 'org-agenda-remove-tags t) pars)
  2167. (if (> (length cmd-key) 2)
  2168. (eval (list 'let (nreverse pars)
  2169. (list 'org-tags-view nil cmd-key)))
  2170. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2171. (set-buffer org-agenda-buffer-name)
  2172. (let* ((lines (org-split-string (buffer-string) "\n"))
  2173. line)
  2174. (while (setq line (pop lines))
  2175. (catch 'next
  2176. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2177. (setq org-agenda-info
  2178. (org-fix-agenda-info (text-properties-at 0 line)))
  2179. (princ
  2180. (org-encode-for-stdout
  2181. (mapconcat 'org-agenda-export-csv-mapper
  2182. '(org-category txt type todo tags date time extra
  2183. priority-letter priority agenda-day)
  2184. ",")))
  2185. (princ "\n"))))))
  2186. (defun org-fix-agenda-info (props)
  2187. "Make sure all properties on an agenda item have a canonical form.
  2188. This ensures the export commands can easily use it."
  2189. (let (tmp re)
  2190. (when (setq tmp (plist-get props 'tags))
  2191. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2192. (when (setq tmp (plist-get props 'date))
  2193. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2194. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2195. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2196. (setq tmp (calendar-date-string tmp)))
  2197. (setq props (plist-put props 'date tmp)))
  2198. (when (setq tmp (plist-get props 'day))
  2199. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2200. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2201. (setq tmp (calendar-date-string tmp)))
  2202. (setq props (plist-put props 'day tmp))
  2203. (setq props (plist-put props 'agenda-day tmp)))
  2204. (when (setq tmp (plist-get props 'txt))
  2205. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2206. (plist-put props 'priority-letter (match-string 1 tmp))
  2207. (setq tmp (replace-match "" t t tmp)))
  2208. (when (and (setq re (plist-get props 'org-todo-regexp))
  2209. (setq re (concat "\\`\\.*" re " ?"))
  2210. (string-match re tmp))
  2211. (plist-put props 'todo (match-string 1 tmp))
  2212. (setq tmp (replace-match "" t t tmp)))
  2213. (plist-put props 'txt tmp)))
  2214. props)
  2215. (defun org-agenda-export-csv-mapper (prop)
  2216. (let ((res (plist-get org-agenda-info prop)))
  2217. (setq res
  2218. (cond
  2219. ((not res) "")
  2220. ((stringp res) res)
  2221. (t (prin1-to-string res))))
  2222. (while (string-match "," res)
  2223. (setq res (replace-match ";" t t res)))
  2224. (org-trim res)))
  2225. ;;;###autoload
  2226. (defun org-store-agenda-views (&rest parameters)
  2227. (interactive)
  2228. (eval (list 'org-batch-store-agenda-views)))
  2229. ;; FIXME, why is this a macro?????
  2230. ;;;###autoload
  2231. (defmacro org-batch-store-agenda-views (&rest parameters)
  2232. "Run all custom agenda commands that have a file argument."
  2233. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2234. (pop-up-frames nil)
  2235. (dir default-directory)
  2236. pars cmd thiscmdkey files opts cmd-or-set)
  2237. (while parameters
  2238. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2239. (setq pars (reverse pars))
  2240. (save-window-excursion
  2241. (while cmds
  2242. (setq cmd (pop cmds)
  2243. thiscmdkey (car cmd)
  2244. cmd-or-set (nth 2 cmd)
  2245. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2246. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2247. (if (stringp files) (setq files (list files)))
  2248. (when files
  2249. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2250. (list 'org-agenda nil thiscmdkey)))
  2251. (set-buffer org-agenda-buffer-name)
  2252. (while files
  2253. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2254. (list 'org-write-agenda
  2255. (expand-file-name (pop files) dir) nil t))))
  2256. (and (get-buffer org-agenda-buffer-name)
  2257. (kill-buffer org-agenda-buffer-name)))))))
  2258. (defun org-agenda-mark-header-line (pos)
  2259. "Mark the line at POS as an agenda structure header."
  2260. (save-excursion
  2261. (goto-char pos)
  2262. (put-text-property (point-at-bol) (point-at-eol)
  2263. 'org-agenda-structural-header t)
  2264. (when org-agenda-title-append
  2265. (put-text-property (point-at-bol) (point-at-eol)
  2266. 'org-agenda-title-append org-agenda-title-append))))
  2267. (defvar org-mobile-creating-agendas)
  2268. (defun org-write-agenda (file &optional open nosettings)
  2269. "Write the current buffer (an agenda view) as a file.
  2270. Depending on the extension of the file name, plain text (.txt),
  2271. HTML (.html or .htm) or Postscript (.ps) is produced.
  2272. If the extension is .ics, run icalendar export over all files used
  2273. to construct the agenda and limit the export to entries listed in the
  2274. agenda now.
  2275. With prefix argument OPEN, open the new file immediately.
  2276. If NOSETTINGS is given, do not scope the settings of
  2277. `org-agenda-exporter-settings' into the export commands. This is used when
  2278. the settings have already been scoped and we do not wish to overrule other,
  2279. higher priority settings."
  2280. (interactive "FWrite agenda to file: \nP")
  2281. (if (not (file-writable-p file))
  2282. (error "Cannot write agenda to file %s" file))
  2283. (cond
  2284. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2285. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2286. (org-let (if nosettings nil org-agenda-exporter-settings)
  2287. `(save-excursion
  2288. (save-window-excursion
  2289. (org-agenda-mark-filtered-text)
  2290. (let ((bs (copy-sequence (buffer-string))) beg)
  2291. (org-agenda-unmark-filtered-text)
  2292. (with-temp-buffer
  2293. (insert bs)
  2294. (org-agenda-remove-marked-text 'org-filtered)
  2295. (while (setq beg (text-property-any (point-min) (point-max)
  2296. 'org-filtered t))
  2297. (delete-region
  2298. beg (or (next-single-property-change beg 'org-filtered)
  2299. (point-max))))
  2300. (run-hooks 'org-agenda-before-write-hook)
  2301. (cond
  2302. ((org-bound-and-true-p org-mobile-creating-agendas)
  2303. (org-mobile-write-agenda-for-mobile file))
  2304. ((string-match "\\.html?\\'" file)
  2305. (set-buffer (htmlize-buffer (current-buffer)))
  2306. (when (and org-agenda-export-html-style
  2307. (string-match "<style>" org-agenda-export-html-style))
  2308. ;; replace <style> section with org-agenda-export-html-style
  2309. (goto-char (point-min))
  2310. (kill-region (- (search-forward "<style") 6)
  2311. (search-forward "</style>"))
  2312. (insert org-agenda-export-html-style))
  2313. (write-file file)
  2314. (kill-buffer (current-buffer))
  2315. (message "HTML written to %s" file))
  2316. ((string-match "\\.ps\\'" file)
  2317. (require 'ps-print)
  2318. ,(flet ((ps-get-buffer-name () "Agenda View"))
  2319. (ps-print-buffer-with-faces file))
  2320. (message "Postscript written to %s" file))
  2321. ((string-match "\\.pdf\\'" file)
  2322. (require 'ps-print)
  2323. ,(flet ((ps-get-buffer-name () "Agenda View"))
  2324. (ps-print-buffer-with-faces
  2325. (concat (file-name-sans-extension file) ".ps")))
  2326. (call-process "ps2pdf" nil nil nil
  2327. (expand-file-name
  2328. (concat (file-name-sans-extension file) ".ps"))
  2329. (expand-file-name file))
  2330. (message "PDF written to %s" file))
  2331. ((string-match "\\.ics\\'" file)
  2332. (require 'org-icalendar)
  2333. (let ((org-agenda-marker-table
  2334. (org-create-marker-find-array
  2335. (org-agenda-collect-markers)))
  2336. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2337. (org-combined-agenda-icalendar-file file))
  2338. (apply 'org-export-icalendar 'combine
  2339. (org-agenda-files nil 'ifmode))))
  2340. (t
  2341. (let ((bs (buffer-string)))
  2342. (find-file file)
  2343. (erase-buffer)
  2344. (insert bs)
  2345. (save-buffer 0)
  2346. (kill-buffer (current-buffer))
  2347. (message "Plain text written to %s" file))))))))
  2348. (set-buffer org-agenda-buffer-name))
  2349. (when open (org-open-file file)))
  2350. (defvar org-agenda-filter-overlays nil)
  2351. (defun org-agenda-mark-filtered-text ()
  2352. "Mark all text hidden by filtering with a text property."
  2353. (let ((inhibit-read-only t))
  2354. (mapc
  2355. (lambda (o)
  2356. (when (equal (overlay-buffer o) (current-buffer))
  2357. (put-text-property
  2358. (overlay-start o) (overlay-end o)
  2359. 'org-filtered t)))
  2360. org-agenda-filter-overlays)))
  2361. (defun org-agenda-unmark-filtered-text ()
  2362. "Remove the filtering text property."
  2363. (let ((inhibit-read-only t))
  2364. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2365. (defun org-agenda-remove-marked-text (property &optional value)
  2366. "Delete all text marked with VALUE of PROPERTY.
  2367. VALUE defaults to t."
  2368. (let (beg)
  2369. (setq value (or value t))
  2370. (while (setq beg (text-property-any (point-min) (point-max)
  2371. property value))
  2372. (delete-region
  2373. beg (or (next-single-property-change beg 'org-filtered)
  2374. (point-max))))))
  2375. (defun org-agenda-add-entry-text ()
  2376. "Add entry text to agenda lines.
  2377. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2378. entry text following headings shown in the agenda.
  2379. Drawers will be excluded, also the line with scheduling/deadline info."
  2380. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2381. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2382. (let (m txt)
  2383. (goto-char (point-min))
  2384. (while (not (eobp))
  2385. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2386. (beginning-of-line 2)
  2387. (setq txt (org-agenda-get-some-entry-text
  2388. m org-agenda-add-entry-text-maxlines " > "))
  2389. (end-of-line 1)
  2390. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2391. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2392. &rest keep)
  2393. "Extract entry text from MARKER, at most N-LINES lines.
  2394. This will ignore drawers etc, just get the text.
  2395. If INDENT is given, prefix every line with this string. If KEEP is
  2396. given, it is a list of symbols, defining stuff that should not be
  2397. removed from the entry content. Currently only `planning' is allowed here."
  2398. (let (txt drawer-re kwd-time-re ind)
  2399. (save-excursion
  2400. (with-current-buffer (marker-buffer marker)
  2401. (if (not (org-mode-p))
  2402. (setq txt "")
  2403. (save-excursion
  2404. (save-restriction
  2405. (widen)
  2406. (goto-char marker)
  2407. (end-of-line 1)
  2408. (setq txt (buffer-substring
  2409. (min (1+ (point)) (point-max))
  2410. (progn (outline-next-heading) (point)))
  2411. drawer-re org-drawer-regexp
  2412. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2413. ".*\n?"))
  2414. (with-temp-buffer
  2415. (insert txt)
  2416. (when org-agenda-add-entry-text-descriptive-links
  2417. (goto-char (point-min))
  2418. (while (org-activate-bracket-links (point-max))
  2419. (add-text-properties (match-beginning 0) (match-end 0)
  2420. '(face org-link))))
  2421. (goto-char (point-min))
  2422. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2423. (set-text-properties (match-beginning 0) (match-end 0)
  2424. nil))
  2425. (goto-char (point-min))
  2426. (while (re-search-forward drawer-re nil t)
  2427. (delete-region
  2428. (match-beginning 0)
  2429. (progn (re-search-forward
  2430. "^[ \t]*:END:.*\n?" nil 'move)
  2431. (point))))
  2432. (unless (member 'planning keep)
  2433. (goto-char (point-min))
  2434. (while (re-search-forward kwd-time-re nil t)
  2435. (replace-match "")))
  2436. (goto-char (point-min))
  2437. (when org-agenda-entry-text-exclude-regexps
  2438. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2439. (while (setq re (pop re-list))
  2440. (goto-char (point-min))
  2441. (while (re-search-forward re nil t)
  2442. (replace-match "")))))
  2443. (goto-char (point-max))
  2444. (skip-chars-backward " \t\n")
  2445. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2446. ;; find and remove min common indentation
  2447. (goto-char (point-min))
  2448. (untabify (point-min) (point-max))
  2449. (setq ind (org-get-indentation))
  2450. (while (not (eobp))
  2451. (unless (looking-at "[ \t]*$")
  2452. (setq ind (min ind (org-get-indentation))))
  2453. (beginning-of-line 2))
  2454. (goto-char (point-min))
  2455. (while (not (eobp))
  2456. (unless (looking-at "[ \t]*$")
  2457. (move-to-column ind)
  2458. (delete-region (point-at-bol) (point)))
  2459. (beginning-of-line 2))
  2460. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2461. (goto-char (point-min))
  2462. (when indent
  2463. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2464. (replace-match indent t t)))
  2465. (goto-char (point-min))
  2466. (while (looking-at "[ \t]*\n") (replace-match ""))
  2467. (goto-char (point-max))
  2468. (when (> (org-current-line)
  2469. n-lines)
  2470. (org-goto-line (1+ n-lines))
  2471. (backward-char 1))
  2472. (setq txt (buffer-substring (point-min) (point)))))))))
  2473. txt))
  2474. (defun org-agenda-collect-markers ()
  2475. "Collect the markers pointing to entries in the agenda buffer."
  2476. (let (m markers)
  2477. (save-excursion
  2478. (goto-char (point-min))
  2479. (while (not (eobp))
  2480. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2481. (org-get-at-bol 'org-marker)))
  2482. (push m markers))
  2483. (beginning-of-line 2)))
  2484. (nreverse markers)))
  2485. (defun org-create-marker-find-array (marker-list)
  2486. "Create a alist of files names with all marker positions in that file."
  2487. (let (f tbl m a p)
  2488. (while (setq m (pop marker-list))
  2489. (setq p (marker-position m)
  2490. f (buffer-file-name (or (buffer-base-buffer
  2491. (marker-buffer m))
  2492. (marker-buffer m))))
  2493. (if (setq a (assoc f tbl))
  2494. (push (marker-position m) (cdr a))
  2495. (push (list f p) tbl)))
  2496. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2497. tbl)))
  2498. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2499. (defun org-check-agenda-marker-table ()
  2500. "Check of the current entry is on the marker list."
  2501. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2502. a)
  2503. (and (setq a (assoc file org-agenda-marker-table))
  2504. (save-match-data
  2505. (save-excursion
  2506. (org-back-to-heading t)
  2507. (member (point) (cdr a)))))))
  2508. (defun org-check-for-org-mode ()
  2509. "Make sure current buffer is in org-mode. Error if not."
  2510. (or (org-mode-p)
  2511. (error "Cannot execute org-mode agenda command on buffer in %s"
  2512. major-mode)))
  2513. (defun org-fit-agenda-window ()
  2514. "Fit the window to the buffer size."
  2515. (and (memq org-agenda-window-setup '(reorganize-frame))
  2516. (fboundp 'fit-window-to-buffer)
  2517. (org-fit-window-to-buffer
  2518. nil
  2519. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2520. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2521. ;;; Agenda prepare and finalize
  2522. (defvar org-agenda-multi nil) ; dynamically scoped
  2523. (defvar org-agenda-buffer-name "*Org Agenda*")
  2524. (defvar org-pre-agenda-window-conf nil)
  2525. (defvar org-agenda-columns-active nil)
  2526. (defvar org-agenda-name nil)
  2527. (defvar org-agenda-filter nil)
  2528. (defvar org-agenda-filter-preset nil
  2529. "A preset of the tags filter used for secondary agenda filtering.
  2530. This must be a list of strings, each string must be a single tag preceded
  2531. by \"+\" or \"-\".
  2532. This variable should not be set directly, but agenda custom commands can
  2533. bind it in the options section. The preset filter is a global property of
  2534. the entire agenda view. In a block agenda, it will not work reliably to
  2535. define a filter for one of the individual blocks. You need to set it in
  2536. the global options and expect it to be applied to the entire view.")
  2537. (defun org-prepare-agenda (&optional name)
  2538. (setq org-todo-keywords-for-agenda nil)
  2539. (setq org-done-keywords-for-agenda nil)
  2540. (setq org-drawers-for-agenda nil)
  2541. (unless org-agenda-persistent-filter
  2542. (setq org-agenda-filter nil))
  2543. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2544. (if org-agenda-multi
  2545. (progn
  2546. (setq buffer-read-only nil)
  2547. (goto-char (point-max))
  2548. (unless (or (bobp) org-agenda-compact-blocks)
  2549. (insert "\n"
  2550. (if (stringp org-agenda-block-separator)
  2551. org-agenda-block-separator
  2552. (make-string (window-width) org-agenda-block-separator))
  2553. "\n"))
  2554. (narrow-to-region (point) (point-max)))
  2555. (org-agenda-reset-markers)
  2556. (setq org-agenda-contributing-files nil)
  2557. (setq org-agenda-columns-active nil)
  2558. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2559. (setq org-todo-keywords-for-agenda
  2560. (org-uniquify org-todo-keywords-for-agenda))
  2561. (setq org-done-keywords-for-agenda
  2562. (org-uniquify org-done-keywords-for-agenda))
  2563. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2564. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2565. (awin (get-buffer-window abuf)))
  2566. (cond
  2567. ((equal (current-buffer) abuf) nil)
  2568. (awin (select-window awin))
  2569. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2570. ((equal org-agenda-window-setup 'current-window)
  2571. (switch-to-buffer abuf))
  2572. ((equal org-agenda-window-setup 'other-window)
  2573. (org-switch-to-buffer-other-window abuf))
  2574. ((equal org-agenda-window-setup 'other-frame)
  2575. (switch-to-buffer-other-frame abuf))
  2576. ((equal org-agenda-window-setup 'reorganize-frame)
  2577. (delete-other-windows)
  2578. (org-switch-to-buffer-other-window abuf))))
  2579. (setq buffer-read-only nil)
  2580. (let ((inhibit-read-only t)) (erase-buffer))
  2581. (org-agenda-mode)
  2582. (and name (not org-agenda-name)
  2583. (org-set-local 'org-agenda-name name)))
  2584. (setq buffer-read-only nil))
  2585. (defun org-finalize-agenda ()
  2586. "Finishing touch for the agenda buffer, called just before displaying it."
  2587. (unless org-agenda-multi
  2588. (save-excursion
  2589. (let ((inhibit-read-only t))
  2590. (goto-char (point-min))
  2591. (while (org-activate-bracket-links (point-max))
  2592. (add-text-properties (match-beginning 0) (match-end 0)
  2593. '(face org-link)))
  2594. (org-agenda-align-tags)
  2595. (unless org-agenda-with-colors
  2596. (remove-text-properties (point-min) (point-max) '(face nil))))
  2597. (if (and (boundp 'org-agenda-overriding-columns-format)
  2598. org-agenda-overriding-columns-format)
  2599. (org-set-local 'org-agenda-overriding-columns-format
  2600. org-agenda-overriding-columns-format))
  2601. (if (and (boundp 'org-agenda-view-columns-initially)
  2602. org-agenda-view-columns-initially)
  2603. (org-agenda-columns))
  2604. (when org-agenda-fontify-priorities
  2605. (org-agenda-fontify-priorities))
  2606. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2607. (org-agenda-dim-blocked-tasks))
  2608. (org-agenda-mark-clocking-task)
  2609. (when org-agenda-entry-text-mode
  2610. (org-agenda-entry-text-hide)
  2611. (org-agenda-entry-text-show))
  2612. (if (functionp 'org-habit-insert-consistency-graphs)
  2613. (org-habit-insert-consistency-graphs))
  2614. (run-hooks 'org-finalize-agenda-hook)
  2615. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2616. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2617. (org-agenda-filter-apply org-agenda-filter))
  2618. )))
  2619. (defun org-agenda-mark-clocking-task ()
  2620. "Mark the current clock entry in the agenda if it is present."
  2621. (mapc (lambda (o)
  2622. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2623. (delete-overlay o)))
  2624. (overlays-in (point-min) (point-max)))
  2625. (when (marker-buffer org-clock-hd-marker)
  2626. (save-excursion
  2627. (goto-char (point-min))
  2628. (let (s ov)
  2629. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2630. (goto-char s)
  2631. (when (equal (org-get-at-bol 'org-hd-marker)
  2632. org-clock-hd-marker)
  2633. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2634. (overlay-put ov 'type 'org-agenda-clocking)
  2635. (overlay-put ov 'face 'org-agenda-clocking)
  2636. (overlay-put ov 'help-echo
  2637. "The clock is running in this item")))))))
  2638. (defun org-agenda-fontify-priorities ()
  2639. "Make highest priority lines bold, and lowest italic."
  2640. (interactive)
  2641. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2642. (delete-overlay o)))
  2643. (overlays-in (point-min) (point-max)))
  2644. (save-excursion
  2645. (let ((inhibit-read-only t)
  2646. b e p ov h l)
  2647. (goto-char (point-min))
  2648. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2649. (setq h (or (get-char-property (point) 'org-highest-priority)
  2650. org-highest-priority)
  2651. l (or (get-char-property (point) 'org-lowest-priority)
  2652. org-lowest-priority)
  2653. p (string-to-char (match-string 1))
  2654. b (match-beginning 0)
  2655. e (if (eq org-agenda-fontify-priorities 'cookies)
  2656. (match-end 0)
  2657. (point-at-eol))
  2658. ov (make-overlay b e))
  2659. (overlay-put
  2660. ov 'face
  2661. (cond ((org-face-from-face-or-color
  2662. 'priority nil
  2663. (cdr (assoc p org-priority-faces))))
  2664. ((and (listp org-agenda-fontify-priorities)
  2665. (org-face-from-face-or-color
  2666. 'priority nil
  2667. (cdr (assoc p org-agenda-fontify-priorities)))))
  2668. ((equal p l) 'italic)
  2669. ((equal p h) 'bold)))
  2670. (overlay-put ov 'org-type 'org-priority)))))
  2671. (defun org-agenda-dim-blocked-tasks ()
  2672. "Dim currently blocked TODO's in the agenda display."
  2673. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2674. (delete-overlay o)))
  2675. (overlays-in (point-min) (point-max)))
  2676. (save-excursion
  2677. (let ((inhibit-read-only t)
  2678. (org-depend-tag-blocked nil)
  2679. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2680. org-blocked-by-checkboxes
  2681. invis1 b e p ov h l)
  2682. (goto-char (point-min))
  2683. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2684. (and pos (goto-char (1+ pos))))
  2685. (setq org-blocked-by-checkboxes nil invis1 invis)
  2686. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2687. (when (and marker
  2688. (not (with-current-buffer (marker-buffer marker)
  2689. (save-excursion
  2690. (goto-char marker)
  2691. (if (org-entry-get nil "NOBLOCKING")
  2692. t ;; Never block this entry
  2693. (run-hook-with-args-until-failure
  2694. 'org-blocker-hook
  2695. (list :type 'todo-state-change
  2696. :position marker
  2697. :from 'todo
  2698. :to 'done)))))))
  2699. (if org-blocked-by-checkboxes (setq invis1 nil))
  2700. (setq b (if invis1
  2701. (max (point-min) (1- (point-at-bol)))
  2702. (point-at-bol))
  2703. e (point-at-eol)
  2704. ov (make-overlay b e))
  2705. (if invis1
  2706. (overlay-put ov 'invisible t)
  2707. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2708. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2709. (defvar org-agenda-skip-function nil
  2710. "Function to be called at each match during agenda construction.
  2711. If this function returns nil, the current match should not be skipped.
  2712. Otherwise, the function must return a position from where the search
  2713. should be continued.
  2714. This may also be a Lisp form, it will be evaluated.
  2715. Never set this variable using `setq' or so, because then it will apply
  2716. to all future agenda commands. Instead, bind it with `let' to scope
  2717. it dynamically into the agenda-constructing command. A good way to set
  2718. it is through options in `org-agenda-custom-commands'.")
  2719. (defun org-agenda-skip ()
  2720. "Throw to `:skip' in places that should be skipped.
  2721. Also moves point to the end of the skipped region, so that search can
  2722. continue from there."
  2723. (let ((p (point-at-bol)) to fp)
  2724. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2725. (get-text-property p :org-archived)
  2726. (org-end-of-subtree t)
  2727. (throw :skip t))
  2728. (and org-agenda-skip-comment-trees
  2729. (get-text-property p :org-comment)
  2730. (org-end-of-subtree t)
  2731. (throw :skip t))
  2732. (if (equal (char-after p) ?#) (throw :skip t))
  2733. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2734. (consp org-agenda-skip-function))
  2735. (setq to (save-excursion
  2736. (save-match-data
  2737. (if fp
  2738. (funcall org-agenda-skip-function)
  2739. (eval org-agenda-skip-function))))))
  2740. (goto-char to)
  2741. (throw :skip t))))
  2742. (defvar org-agenda-markers nil
  2743. "List of all currently active markers created by `org-agenda'.")
  2744. (defvar org-agenda-last-marker-time (org-float-time)
  2745. "Creation time of the last agenda marker.")
  2746. (defun org-agenda-new-marker (&optional pos)
  2747. "Return a new agenda marker.
  2748. Org-mode keeps a list of these markers and resets them when they are
  2749. no longer in use."
  2750. (let ((m (copy-marker (or pos (point)))))
  2751. (setq org-agenda-last-marker-time (org-float-time))
  2752. (push m org-agenda-markers)
  2753. m))
  2754. (defun org-agenda-reset-markers ()
  2755. "Reset markers created by `org-agenda'."
  2756. (while org-agenda-markers
  2757. (move-marker (pop org-agenda-markers) nil)))
  2758. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2759. "Save relative positions of markers in region."
  2760. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2761. org-agenda-markers))
  2762. ;;; Entry text mode
  2763. (defun org-agenda-entry-text-show-here ()
  2764. "Add some text from the entry as context to the current line."
  2765. (let (m txt o)
  2766. (setq m (org-get-at-bol 'org-hd-marker))
  2767. (unless (marker-buffer m)
  2768. (error "No marker points to an entry here"))
  2769. (setq txt (concat "\n" (org-no-properties
  2770. (org-agenda-get-some-entry-text
  2771. m org-agenda-entry-text-maxlines " > "))))
  2772. (when (string-match "\\S-" txt)
  2773. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2774. (overlay-put o 'evaporate t)
  2775. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2776. (overlay-put o 'after-string txt))))
  2777. (defun org-agenda-entry-text-show ()
  2778. "Add entry context for all agenda lines."
  2779. (interactive)
  2780. (save-excursion
  2781. (goto-char (point-max))
  2782. (beginning-of-line 1)
  2783. (while (not (bobp))
  2784. (when (org-get-at-bol 'org-hd-marker)
  2785. (org-agenda-entry-text-show-here))
  2786. (beginning-of-line 0))))
  2787. (defun org-agenda-entry-text-hide ()
  2788. "Remove any shown entry context."
  2789. (delq nil
  2790. (mapcar (lambda (o)
  2791. (if (eq (overlay-get o 'org-overlay-type)
  2792. 'agenda-entry-content)
  2793. (progn (delete-overlay o) t)))
  2794. (overlays-in (point-min) (point-max)))))
  2795. ;;; Agenda timeline
  2796. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2797. (defun org-timeline (&optional include-all)
  2798. "Show a time-sorted view of the entries in the current org file.
  2799. Only entries with a time stamp of today or later will be listed. With
  2800. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2801. under the current date.
  2802. If the buffer contains an active region, only check the region for
  2803. dates."
  2804. (interactive "P")
  2805. (org-compile-prefix-format 'timeline)
  2806. (org-set-sorting-strategy 'timeline)
  2807. (let* ((dopast t)
  2808. (dotodo include-all)
  2809. (doclosed org-agenda-show-log)
  2810. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2811. (current-buffer))))
  2812. (date (calendar-current-date))
  2813. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2814. (end (if (org-region-active-p) (region-end) (point-max)))
  2815. (day-numbers (org-get-all-dates beg end 'no-ranges
  2816. t doclosed ; always include today
  2817. org-timeline-show-empty-dates))
  2818. (org-deadline-warning-days 0)
  2819. (org-agenda-only-exact-dates t)
  2820. (today (time-to-days (current-time)))
  2821. (past t)
  2822. args
  2823. s e rtn d emptyp wd)
  2824. (setq org-agenda-redo-command
  2825. (list 'progn
  2826. (list 'org-switch-to-buffer-other-window (current-buffer))
  2827. (list 'org-timeline (list 'quote include-all))))
  2828. (if (not dopast)
  2829. ;; Remove past dates from the list of dates.
  2830. (setq day-numbers (delq nil (mapcar (lambda(x)
  2831. (if (>= x today) x nil))
  2832. day-numbers))))
  2833. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2834. (if doclosed (push :closed args))
  2835. (push :timestamp args)
  2836. (push :deadline args)
  2837. (push :scheduled args)
  2838. (push :sexp args)
  2839. (if dotodo (push :todo args))
  2840. (insert "Timeline of file " entry "\n")
  2841. (add-text-properties (point-min) (point)
  2842. (list 'face 'org-agenda-structure))
  2843. (org-agenda-mark-header-line (point-min))
  2844. (while (setq d (pop day-numbers))
  2845. (if (and (listp d) (eq (car d) :omitted))
  2846. (progn
  2847. (setq s (point))
  2848. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2849. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2850. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2851. (if (and (>= d today)
  2852. dopast
  2853. past)
  2854. (progn
  2855. (setq past nil)
  2856. (insert (make-string 79 ?-) "\n")))
  2857. (setq date (calendar-gregorian-from-absolute d)
  2858. wd (calendar-day-of-week date))
  2859. (setq s (point))
  2860. (setq rtn (and (not emptyp)
  2861. (apply 'org-agenda-get-day-entries entry
  2862. date args)))
  2863. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2864. (progn
  2865. (insert
  2866. (if (stringp org-agenda-format-date)
  2867. (format-time-string org-agenda-format-date
  2868. (org-time-from-absolute date))
  2869. (funcall org-agenda-format-date date))
  2870. "\n")
  2871. (put-text-property s (1- (point)) 'face
  2872. (if (member wd org-agenda-weekend-days)
  2873. 'org-agenda-date-weekend
  2874. 'org-agenda-date))
  2875. (put-text-property s (1- (point)) 'org-date-line t)
  2876. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2877. (if (equal d today)
  2878. (put-text-property s (1- (point)) 'org-today t))
  2879. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2880. (put-text-property s (1- (point)) 'day d)))))
  2881. (goto-char (point-min))
  2882. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2883. (point-min)))
  2884. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2885. (org-finalize-agenda)
  2886. (setq buffer-read-only t)))
  2887. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2888. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2889. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2890. not every single day in the range. If FORCE-TODAY is non-nil, make
  2891. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2892. inactive time stamps (those in square brackets) are included.
  2893. When EMPTY is non-nil, also include days without any entries."
  2894. (let ((re (concat
  2895. (if pre-re pre-re "")
  2896. (if inactive org-ts-regexp-both org-ts-regexp)))
  2897. dates dates1 date day day1 day2 ts1 ts2)
  2898. (if force-today
  2899. (setq dates (list (time-to-days (current-time)))))
  2900. (save-excursion
  2901. (goto-char beg)
  2902. (while (re-search-forward re end t)
  2903. (setq day (time-to-days (org-time-string-to-time
  2904. (substring (match-string 1) 0 10))))
  2905. (or (memq day dates) (push day dates)))
  2906. (unless no-ranges
  2907. (goto-char beg)
  2908. (while (re-search-forward org-tr-regexp end t)
  2909. (setq ts1 (substring (match-string 1) 0 10)
  2910. ts2 (substring (match-string 2) 0 10)
  2911. day1 (time-to-days (org-time-string-to-time ts1))
  2912. day2 (time-to-days (org-time-string-to-time ts2)))
  2913. (while (< (setq day1 (1+ day1)) day2)
  2914. (or (memq day1 dates) (push day1 dates)))))
  2915. (setq dates (sort dates '<))
  2916. (when empty
  2917. (while (setq day (pop dates))
  2918. (setq day2 (car dates))
  2919. (push day dates1)
  2920. (when (and day2 empty)
  2921. (if (or (eq empty t)
  2922. (and (numberp empty) (<= (- day2 day) empty)))
  2923. (while (< (setq day (1+ day)) day2)
  2924. (push (list day) dates1))
  2925. (push (cons :omitted (- day2 day)) dates1))))
  2926. (setq dates (nreverse dates1)))
  2927. dates)))
  2928. ;;; Agenda Daily/Weekly
  2929. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2930. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2931. "Custom commands can set this variable in the options section.")
  2932. (defvar org-agenda-last-arguments nil
  2933. "The arguments of the previous call to `org-agenda'.")
  2934. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2935. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2936. (defvar org-include-all-loc nil) ; local variable
  2937. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2938. "List of types searched for when creating the daily/weekly agenda.
  2939. This variable is a list of symbols that controls the types of
  2940. items that appear in the daily/weekly agenda. Allowed symbols in this
  2941. list are are
  2942. :timestamp List items containing a date stamp or date range matching
  2943. the selected date. This includes sexp entries in
  2944. angular brackets.
  2945. :sexp List entries resulting from plain diary-like sexps.
  2946. :deadline List deadline due on that date. When the date is today,
  2947. also list any deadlines past due, or due within
  2948. `org-deadline-warning-days'. `:deadline' must appear before
  2949. `:scheduled' if the setting of
  2950. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2951. any effect.
  2952. :scheduled List all items which are scheduled for the given date.
  2953. The diary for *today* also contains items which were
  2954. scheduled earlier and are not yet marked DONE.
  2955. By default, all four types are turned on.
  2956. Never set this variable globally using `setq', because then it
  2957. will apply to all future agenda commands. Instead, bind it with
  2958. `let' to scope it dynamically into the the agenda-constructing
  2959. command. A good way to set it is through options in
  2960. `org-agenda-custom-commands'. For a more flexible (though
  2961. somewhat less efficient) way of determining what is included in
  2962. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2963. ;;;###autoload
  2964. (defun org-agenda-list (&optional include-all start-day ndays)
  2965. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2966. The view will be for the current day or week, but from the overview buffer
  2967. you will be able to go to other days/weeks.
  2968. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2969. all unfinished TODO items will also be shown, before the agenda.
  2970. This feature is considered obsolete, please use the TODO list or a block
  2971. agenda instead.
  2972. With a numeric prefix argument in an interactive call, the agenda will
  2973. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2974. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2975. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2976. given in `org-agenda-start-on-weekday'."
  2977. (interactive "P")
  2978. (if (and (integerp include-all) (> include-all 0))
  2979. (setq ndays include-all include-all nil))
  2980. (setq ndays (or ndays org-agenda-ndays)
  2981. start-day (or start-day org-agenda-start-day))
  2982. (if org-agenda-overriding-arguments
  2983. (setq include-all (car org-agenda-overriding-arguments)
  2984. start-day (nth 1 org-agenda-overriding-arguments)
  2985. ndays (nth 2 org-agenda-overriding-arguments)))
  2986. (if (stringp start-day)
  2987. ;; Convert to an absolute day number
  2988. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2989. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2990. (org-compile-prefix-format 'agenda)
  2991. (org-set-sorting-strategy 'agenda)
  2992. (let* ((org-agenda-start-on-weekday
  2993. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2994. org-agenda-start-on-weekday nil))
  2995. (thefiles (org-agenda-files nil 'ifmode))
  2996. (files thefiles)
  2997. (today (time-to-days
  2998. (time-subtract (current-time)
  2999. (list 0 (* 3600 org-extend-today-until) 0))))
  3000. (sd (or start-day today))
  3001. (start (if (or (null org-agenda-start-on-weekday)
  3002. (< org-agenda-ndays 7))
  3003. sd
  3004. (let* ((nt (calendar-day-of-week
  3005. (calendar-gregorian-from-absolute sd)))
  3006. (n1 org-agenda-start-on-weekday)
  3007. (d (- nt n1)))
  3008. (- sd (+ (if (< d 0) 7 0) d)))))
  3009. (day-numbers (list start))
  3010. (day-cnt 0)
  3011. (inhibit-redisplay (not debug-on-error))
  3012. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  3013. clocktable-start clocktable-end)
  3014. (setq org-agenda-redo-command
  3015. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3016. ;; Make the list of days
  3017. (setq ndays (or ndays org-agenda-ndays)
  3018. nd ndays)
  3019. (while (> ndays 1)
  3020. (push (1+ (car day-numbers)) day-numbers)
  3021. (setq ndays (1- ndays)))
  3022. (setq day-numbers (nreverse day-numbers))
  3023. (setq clocktable-start (car day-numbers)
  3024. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3025. (org-prepare-agenda "Day/Week")
  3026. (org-set-local 'org-starting-day (car day-numbers))
  3027. (org-set-local 'org-include-all-loc include-all)
  3028. (org-set-local 'org-agenda-span
  3029. (org-agenda-ndays-to-span nd))
  3030. (when (and (or include-all org-agenda-include-all-todo)
  3031. (member today day-numbers))
  3032. (setq files thefiles
  3033. rtnall nil)
  3034. (while (setq file (pop files))
  3035. (catch 'nextfile
  3036. (org-check-agenda-file file)
  3037. (setq date (calendar-gregorian-from-absolute today)
  3038. rtn (org-agenda-get-day-entries
  3039. file date :todo))
  3040. (setq rtnall (append rtnall rtn))))
  3041. (when rtnall
  3042. (insert "All currently open TODO items:\n")
  3043. (add-text-properties (point-min) (1- (point))
  3044. (list 'face 'org-agenda-structure
  3045. 'short-heading "All TODO items"))
  3046. (org-agenda-mark-header-line (point-min))
  3047. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3048. (unless org-agenda-compact-blocks
  3049. (let* ((d1 (car day-numbers))
  3050. (d2 (org-last day-numbers))
  3051. (w1 (org-days-to-iso-week d1))
  3052. (w2 (org-days-to-iso-week d2)))
  3053. (setq s (point))
  3054. (if org-agenda-overriding-header
  3055. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3056. nil 'face 'org-agenda-structure) "\n")
  3057. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3058. "-agenda"
  3059. (if (< (- d2 d1) 350)
  3060. (if (= w1 w2)
  3061. (format " (W%02d)" w1)
  3062. (format " (W%02d-W%02d)" w1 w2))
  3063. "")
  3064. ":\n")))
  3065. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3066. 'org-date-line t))
  3067. (org-agenda-mark-header-line s))
  3068. (while (setq d (pop day-numbers))
  3069. (setq date (calendar-gregorian-from-absolute d)
  3070. wd (calendar-day-of-week date)
  3071. s (point))
  3072. (if (or (setq todayp (= d today))
  3073. (and (not start-pos) (= d sd)))
  3074. (setq start-pos (point))
  3075. (if (and start-pos (not end-pos))
  3076. (setq end-pos (point))))
  3077. (setq files thefiles
  3078. rtnall nil)
  3079. (while (setq file (pop files))
  3080. (catch 'nextfile
  3081. (org-check-agenda-file file)
  3082. (let ((org-agenda-entry-types org-agenda-entry-types))
  3083. (unless org-agenda-include-deadlines
  3084. (setq org-agenda-entry-types
  3085. (delq :deadline org-agenda-entry-types)))
  3086. (cond
  3087. ((eq org-agenda-show-log 'only)
  3088. (setq rtn (org-agenda-get-day-entries
  3089. file date :closed)))
  3090. (org-agenda-show-log
  3091. (setq rtn (apply 'org-agenda-get-day-entries
  3092. file date
  3093. (append '(:closed) org-agenda-entry-types))))
  3094. (t
  3095. (setq rtn (apply 'org-agenda-get-day-entries
  3096. file date
  3097. org-agenda-entry-types)))))
  3098. (setq rtnall (append rtnall rtn))))
  3099. (if org-agenda-include-diary
  3100. (let ((org-agenda-search-headline-for-time t))
  3101. (require 'diary-lib)
  3102. (setq rtn (org-get-entries-from-diary date))
  3103. (setq rtnall (append rtnall rtn))))
  3104. (if (or rtnall org-agenda-show-all-dates)
  3105. (progn
  3106. (setq day-cnt (1+ day-cnt))
  3107. (insert
  3108. (if (stringp org-agenda-format-date)
  3109. (format-time-string org-agenda-format-date
  3110. (org-time-from-absolute date))
  3111. (funcall org-agenda-format-date date))
  3112. "\n")
  3113. (put-text-property s (1- (point)) 'face
  3114. (if (member wd org-agenda-weekend-days)
  3115. 'org-agenda-date-weekend
  3116. 'org-agenda-date))
  3117. (put-text-property s (1- (point)) 'org-date-line t)
  3118. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3119. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3120. (when todayp
  3121. (put-text-property s (1- (point)) 'org-today t)
  3122. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3123. (if rtnall (insert
  3124. (org-finalize-agenda-entries
  3125. (org-agenda-add-time-grid-maybe
  3126. rtnall nd todayp))
  3127. "\n"))
  3128. (put-text-property s (1- (point)) 'day d)
  3129. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3130. (when (and org-agenda-clockreport-mode clocktable-start)
  3131. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3132. ;; the above line is to ensure the restricted range!
  3133. (p org-agenda-clockreport-parameter-plist)
  3134. tbl)
  3135. (setq p (org-plist-delete p :block))
  3136. (setq p (plist-put p :tstart clocktable-start))
  3137. (setq p (plist-put p :tend clocktable-end))
  3138. (setq p (plist-put p :scope 'agenda))
  3139. (setq tbl (apply 'org-get-clocktable p))
  3140. (insert tbl)))
  3141. (goto-char (point-min))
  3142. (or org-agenda-multi (org-fit-agenda-window))
  3143. (unless (and (pos-visible-in-window-p (point-min))
  3144. (pos-visible-in-window-p (point-max)))
  3145. (goto-char (1- (point-max)))
  3146. (recenter -1)
  3147. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3148. (progn
  3149. (goto-char (or start-pos 1))
  3150. (recenter 1))))
  3151. (goto-char (or start-pos 1))
  3152. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3153. (org-finalize-agenda)
  3154. (setq buffer-read-only t)
  3155. (message "")))
  3156. (defun org-agenda-ndays-to-span (n)
  3157. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3158. ;;; Agenda word search
  3159. (defvar org-agenda-search-history nil)
  3160. (defvar org-todo-only nil)
  3161. (defvar org-search-syntax-table nil
  3162. "Special syntax table for org-mode search.
  3163. In this table, we have single quotes not as word constituents, to
  3164. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3165. (defun org-search-syntax-table ()
  3166. (unless org-search-syntax-table
  3167. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3168. (modify-syntax-entry ?' "." org-search-syntax-table)
  3169. (modify-syntax-entry ?` "." org-search-syntax-table))
  3170. org-search-syntax-table)
  3171. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3172. ;;;###autoload
  3173. (defun org-search-view (&optional todo-only string edit-at)
  3174. "Show all entries that contain a phrase or words or regular expressions.
  3175. With optional prefix argument TODO-ONLY, only consider entries that are
  3176. TODO entries. The argument STRING can be used to pass a default search
  3177. string into this function. If EDIT-AT is non-nil, it means that the
  3178. user should get a chance to edit this string, with cursor at position
  3179. EDIT-AT.
  3180. The search string can be viewed either as a phrase that should be found as
  3181. is, or it can be broken into a number of snippets, each of which must match
  3182. in a Boolean way to select an entry. The default depends on the variable
  3183. `org-agenda-search-view-always-boolean'.
  3184. Even if this is turned off (the default) you can always switch to
  3185. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3186. The default is a direct search of the whole phrase, where each space in
  3187. the search string can expand to an arbitrary amount of whitespace,
  3188. including newlines.
  3189. If using a Boolean search, the search string is split on whitespace and
  3190. each snippet is searched separately, with logical AND to select an entry.
  3191. Words prefixed with a minus must *not* occur in the entry. Words without
  3192. a prefix or prefixed with a plus must occur in the entry. Matching is
  3193. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3194. match whole words, not parts of a word) if
  3195. `org-agenda-search-view-force-full-words' is set (default is nil).
  3196. Boolean search snippets enclosed by curly braces are interpreted as
  3197. regular expressions that must or (when preceded with \"-\") must not
  3198. match in the entry. Snippets enclosed into double quotes will be taken
  3199. as a whole, to include whitespace.
  3200. - If the search string starts with an asterisk, search only in headlines.
  3201. - If (possibly after the leading star) the search string starts with an
  3202. exclamation mark, this also means to look at TODO entries only, an effect
  3203. that can also be achieved with a prefix argument.
  3204. - If (possibly after star and exclamation mark) the search string starts
  3205. with a colon, this will mean that the (non-regexp) snippets of the
  3206. Boolean search must match as full words.
  3207. This command searches the agenda files, and in addition the files listed
  3208. in `org-agenda-text-search-extra-files'."
  3209. (interactive "P")
  3210. (org-compile-prefix-format 'search)
  3211. (org-set-sorting-strategy 'search)
  3212. (org-prepare-agenda "SEARCH")
  3213. (let* ((props (list 'face nil
  3214. 'done-face 'org-agenda-done
  3215. 'org-not-done-regexp org-not-done-regexp
  3216. 'org-todo-regexp org-todo-regexp
  3217. 'org-complex-heading-regexp org-complex-heading-regexp
  3218. 'mouse-face 'highlight
  3219. 'help-echo (format "mouse-2 or RET jump to location")))
  3220. (full-words org-agenda-search-view-force-full-words)
  3221. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3222. regexp rtn rtnall files file pos
  3223. marker category tags c neg re boolean
  3224. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3225. (unless (and (not edit-at)
  3226. (stringp string)
  3227. (string-match "\\S-" string))
  3228. (setq string (read-string
  3229. (if org-agenda-search-view-always-boolean
  3230. "[+-]Word/{Regexp} ...: "
  3231. "Phrase, or [+-]Word/{Regexp} ...: ")
  3232. (cond
  3233. ((integerp edit-at) (cons string edit-at))
  3234. (edit-at string))
  3235. 'org-agenda-search-history)))
  3236. (org-set-local 'org-todo-only todo-only)
  3237. (setq org-agenda-redo-command
  3238. (list 'org-search-view (if todo-only t nil) string
  3239. '(if current-prefix-arg 1 nil)))
  3240. (setq org-agenda-query-string string)
  3241. (if (equal (string-to-char string) ?*)
  3242. (setq hdl-only t
  3243. words (substring string 1))
  3244. (setq words string))
  3245. (when (equal (string-to-char words) ?!)
  3246. (setq todo-only t
  3247. words (substring words 1)))
  3248. (when (equal (string-to-char words) ?:)
  3249. (setq full-words t
  3250. words (substring words 1)))
  3251. (if (or org-agenda-search-view-always-boolean
  3252. (member (string-to-char words) '(?- ?+ ?\{)))
  3253. (setq boolean t))
  3254. (setq words (org-split-string words))
  3255. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3256. (when boolean
  3257. (let (wds w)
  3258. (while (setq w (pop words))
  3259. (if (or (equal (substring w 0 1) "\"")
  3260. (and (> (length w) 1)
  3261. (member (substring w 0 1) '("+" "-"))
  3262. (equal (substring w 1 2) "\"")))
  3263. (while (and words (not (equal (substring w -1) "\"")))
  3264. (setq w (concat w " " (pop words)))))
  3265. (and (string-match "\\`\\([-+]?\\)\"" w)
  3266. (setq w (replace-match "\\1" nil nil w)))
  3267. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3268. (push w wds))
  3269. (setq words (nreverse wds))))
  3270. (if boolean
  3271. (mapc (lambda (w)
  3272. (setq c (string-to-char w))
  3273. (if (equal c ?-)
  3274. (setq neg t w (substring w 1))
  3275. (if (equal c ?+)
  3276. (setq neg nil w (substring w 1))
  3277. (setq neg nil)))
  3278. (if (string-match "\\`{.*}\\'" w)
  3279. (setq re (substring w 1 -1))
  3280. (if full-words
  3281. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3282. (setq re (regexp-quote (downcase w)))))
  3283. (if neg (push re regexps-) (push re regexps+)))
  3284. words)
  3285. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3286. regexps+))
  3287. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3288. (if (not regexps+)
  3289. (setq regexp (concat "^" org-outline-regexp))
  3290. (setq regexp (pop regexps+))
  3291. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3292. regexp))))
  3293. (setq files (org-agenda-files nil 'ifmode))
  3294. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3295. (pop org-agenda-text-search-extra-files)
  3296. (setq files (org-add-archive-files files)))
  3297. (setq files (append files org-agenda-text-search-extra-files)
  3298. rtnall nil)
  3299. (while (setq file (pop files))
  3300. (setq ee nil)
  3301. (catch 'nextfile
  3302. (org-check-agenda-file file)
  3303. (setq buffer (if (file-exists-p file)
  3304. (org-get-agenda-file-buffer file)
  3305. (error "No such file %s" file)))
  3306. (if (not buffer)
  3307. ;; If file does not exist, make sure an error message is sent
  3308. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3309. file))))
  3310. (with-current-buffer buffer
  3311. (with-syntax-table (org-search-syntax-table)
  3312. (unless (org-mode-p)
  3313. (error "Agenda file %s is not in `org-mode'" file))
  3314. (let ((case-fold-search t))
  3315. (save-excursion
  3316. (save-restriction
  3317. (if org-agenda-restrict
  3318. (narrow-to-region org-agenda-restrict-begin
  3319. org-agenda-restrict-end)
  3320. (widen))
  3321. (goto-char (point-min))
  3322. (unless (or (org-on-heading-p)
  3323. (outline-next-heading))
  3324. (throw 'nextfile t))
  3325. (goto-char (max (point-min) (1- (point))))
  3326. (while (re-search-forward regexp nil t)
  3327. (org-back-to-heading t)
  3328. (skip-chars-forward "* ")
  3329. (setq beg (point-at-bol)
  3330. beg1 (point)
  3331. end (progn (outline-next-heading) (point)))
  3332. (catch :skip
  3333. (goto-char beg)
  3334. (org-agenda-skip)
  3335. (setq str (buffer-substring-no-properties
  3336. (point-at-bol)
  3337. (if hdl-only (point-at-eol) end)))
  3338. (mapc (lambda (wr) (when (string-match wr str)
  3339. (goto-char (1- end))
  3340. (throw :skip t)))
  3341. regexps-)
  3342. (mapc (lambda (wr) (unless (string-match wr str)
  3343. (goto-char (1- end))
  3344. (throw :skip t)))
  3345. (if todo-only
  3346. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3347. regexps+)
  3348. regexps+))
  3349. (goto-char beg)
  3350. (setq marker (org-agenda-new-marker (point))
  3351. category (org-get-category)
  3352. tags (org-get-tags-at (point))
  3353. txt (org-format-agenda-item
  3354. ""
  3355. (buffer-substring-no-properties
  3356. beg1 (point-at-eol))
  3357. category tags))
  3358. (org-add-props txt props
  3359. 'org-marker marker 'org-hd-marker marker
  3360. 'org-todo-regexp org-todo-regexp
  3361. 'org-complex-heading-regexp org-complex-heading-regexp
  3362. 'priority 1000 'org-category category
  3363. 'type "search")
  3364. (push txt ee)
  3365. (goto-char (1- end))))))))))
  3366. (setq rtn (nreverse ee))
  3367. (setq rtnall (append rtnall rtn)))
  3368. (if org-agenda-overriding-header
  3369. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3370. nil 'face 'org-agenda-structure) "\n")
  3371. (insert "Search words: ")
  3372. (add-text-properties (point-min) (1- (point))
  3373. (list 'face 'org-agenda-structure))
  3374. (setq pos (point))
  3375. (insert string "\n")
  3376. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3377. (setq pos (point))
  3378. (unless org-agenda-multi
  3379. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3380. (add-text-properties pos (1- (point))
  3381. (list 'face 'org-agenda-structure))))
  3382. (org-agenda-mark-header-line (point-min))
  3383. (when rtnall
  3384. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3385. (goto-char (point-min))
  3386. (or org-agenda-multi (org-fit-agenda-window))
  3387. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3388. (org-finalize-agenda)
  3389. (setq buffer-read-only t)))
  3390. ;;; Agenda TODO list
  3391. (defvar org-select-this-todo-keyword nil)
  3392. (defvar org-last-arg nil)
  3393. ;;;###autoload
  3394. (defun org-todo-list (arg)
  3395. "Show all (not done) TODO entries from all agenda file in a single list.
  3396. The prefix arg can be used to select a specific TODO keyword and limit
  3397. the list to these. When using \\[universal-argument], you will be prompted
  3398. for a keyword. A numeric prefix directly selects the Nth keyword in
  3399. `org-todo-keywords-1'."
  3400. (interactive "P")
  3401. (org-compile-prefix-format 'todo)
  3402. (org-set-sorting-strategy 'todo)
  3403. (org-prepare-agenda "TODO")
  3404. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3405. (let* ((today (time-to-days (current-time)))
  3406. (date (calendar-gregorian-from-absolute today))
  3407. (kwds org-todo-keywords-for-agenda)
  3408. (completion-ignore-case t)
  3409. (org-select-this-todo-keyword
  3410. (if (stringp arg) arg
  3411. (and arg (integerp arg) (> arg 0)
  3412. (nth (1- arg) kwds))))
  3413. rtn rtnall files file pos)
  3414. (when (equal arg '(4))
  3415. (setq org-select-this-todo-keyword
  3416. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3417. (mapcar 'list kwds) nil nil)))
  3418. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3419. (org-set-local 'org-last-arg arg)
  3420. (setq org-agenda-redo-command
  3421. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3422. (setq files (org-agenda-files nil 'ifmode)
  3423. rtnall nil)
  3424. (while (setq file (pop files))
  3425. (catch 'nextfile
  3426. (org-check-agenda-file file)
  3427. (setq rtn (org-agenda-get-day-entries file date :todo))
  3428. (setq rtnall (append rtnall rtn))))
  3429. (if org-agenda-overriding-header
  3430. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3431. nil 'face 'org-agenda-structure) "\n")
  3432. (insert "Global list of TODO items of type: ")
  3433. (add-text-properties (point-min) (1- (point))
  3434. (list 'face 'org-agenda-structure
  3435. 'short-heading
  3436. (concat "ToDo: "
  3437. (or org-select-this-todo-keyword "ALL"))))
  3438. (org-agenda-mark-header-line (point-min))
  3439. (setq pos (point))
  3440. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3441. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3442. (setq pos (point))
  3443. (unless org-agenda-multi
  3444. (insert "Available with `N r': (0)ALL")
  3445. (let ((n 0) s)
  3446. (mapc (lambda (x)
  3447. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3448. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3449. (insert "\n "))
  3450. (insert " " s))
  3451. kwds))
  3452. (insert "\n"))
  3453. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3454. (org-agenda-mark-header-line (point-min))
  3455. (when rtnall
  3456. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3457. (goto-char (point-min))
  3458. (or org-agenda-multi (org-fit-agenda-window))
  3459. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3460. (org-finalize-agenda)
  3461. (setq buffer-read-only t)))
  3462. ;;; Agenda tags match
  3463. ;;;###autoload
  3464. (defun org-tags-view (&optional todo-only match)
  3465. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3466. The prefix arg TODO-ONLY limits the search to TODO entries."
  3467. (interactive "P")
  3468. (org-compile-prefix-format 'tags)
  3469. (org-set-sorting-strategy 'tags)
  3470. (let* ((org-tags-match-list-sublevels
  3471. org-tags-match-list-sublevels)
  3472. (completion-ignore-case t)
  3473. rtn rtnall files file pos matcher
  3474. buffer)
  3475. (when (and (stringp match) (not (string-match "\\S-" match)))
  3476. (setq match nil))
  3477. (setq matcher (org-make-tags-matcher match)
  3478. match (car matcher) matcher (cdr matcher))
  3479. (org-prepare-agenda (concat "TAGS " match))
  3480. (setq org-agenda-query-string match)
  3481. (setq org-agenda-redo-command
  3482. (list 'org-tags-view (list 'quote todo-only)
  3483. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3484. (setq files (org-agenda-files nil 'ifmode)
  3485. rtnall nil)
  3486. (while (setq file (pop files))
  3487. (catch 'nextfile
  3488. (org-check-agenda-file file)
  3489. (setq buffer (if (file-exists-p file)
  3490. (org-get-agenda-file-buffer file)
  3491. (error "No such file %s" file)))
  3492. (if (not buffer)
  3493. ;; If file does not exist, error message to agenda
  3494. (setq rtn (list
  3495. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3496. rtnall (append rtnall rtn))
  3497. (with-current-buffer buffer
  3498. (unless (org-mode-p)
  3499. (error "Agenda file %s is not in `org-mode'" file))
  3500. (save-excursion
  3501. (save-restriction
  3502. (if org-agenda-restrict
  3503. (narrow-to-region org-agenda-restrict-begin
  3504. org-agenda-restrict-end)
  3505. (widen))
  3506. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3507. (setq rtnall (append rtnall rtn))))))))
  3508. (if org-agenda-overriding-header
  3509. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3510. nil 'face 'org-agenda-structure) "\n")
  3511. (insert "Headlines with TAGS match: ")
  3512. (add-text-properties (point-min) (1- (point))
  3513. (list 'face 'org-agenda-structure
  3514. 'short-heading
  3515. (concat "Match: " match)))
  3516. (setq pos (point))
  3517. (insert match "\n")
  3518. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3519. (setq pos (point))
  3520. (unless org-agenda-multi
  3521. (insert "Press `C-u r' to search again with new search string\n"))
  3522. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3523. (org-agenda-mark-header-line (point-min))
  3524. (when rtnall
  3525. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3526. (goto-char (point-min))
  3527. (or org-agenda-multi (org-fit-agenda-window))
  3528. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3529. (org-finalize-agenda)
  3530. (setq buffer-read-only t)))
  3531. ;;; Agenda Finding stuck projects
  3532. (defvar org-agenda-skip-regexp nil
  3533. "Regular expression used in skipping subtrees for the agenda.
  3534. This is basically a temporary global variable that can be set and then
  3535. used by user-defined selections using `org-agenda-skip-function'.")
  3536. (defvar org-agenda-overriding-header nil
  3537. "When this is set during todo and tags searches, will replace header.
  3538. This variable should not be set directly, but custom commands can bind it
  3539. in the options section.")
  3540. (defun org-agenda-skip-entry-when-regexp-matches ()
  3541. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3542. If yes, it returns the end position of this entry, causing agenda commands
  3543. to skip the entry but continuing the search in the subtree. This is a
  3544. function that can be put into `org-agenda-skip-function' for the duration
  3545. of a command."
  3546. (let ((end (save-excursion (org-end-of-subtree t)))
  3547. skip)
  3548. (save-excursion
  3549. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3550. (and skip end)))
  3551. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3552. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3553. If yes, it returns the end position of this tree, causing agenda commands
  3554. to skip this subtree. This is a function that can be put into
  3555. `org-agenda-skip-function' for the duration of a command."
  3556. (let ((end (save-excursion (org-end-of-subtree t)))
  3557. skip)
  3558. (save-excursion
  3559. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3560. (and skip end)))
  3561. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3562. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3563. If yes, it returns the end position of the current entry (NOT the tree),
  3564. causing agenda commands to skip the entry but continuing the search in
  3565. the subtree. This is a function that can be put into
  3566. `org-agenda-skip-function' for the duration of a command. An important
  3567. use of this function is for the stuck project list."
  3568. (let ((end (save-excursion (org-end-of-subtree t)))
  3569. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3570. skip)
  3571. (save-excursion
  3572. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3573. (and skip entry-end)))
  3574. (defun org-agenda-skip-entry-if (&rest conditions)
  3575. "Skip entry if any of CONDITIONS is true.
  3576. See `org-agenda-skip-if' for details."
  3577. (org-agenda-skip-if nil conditions))
  3578. (defun org-agenda-skip-subtree-if (&rest conditions)
  3579. "Skip entry if any of CONDITIONS is true.
  3580. See `org-agenda-skip-if' for details."
  3581. (org-agenda-skip-if t conditions))
  3582. (defun org-agenda-skip-if (subtree conditions)
  3583. "Checks current entity for CONDITIONS.
  3584. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3585. the entry, i.e. the text before the next heading is checked.
  3586. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3587. from different tests. Valid conditions are:
  3588. scheduled Check if there is a scheduled cookie
  3589. notscheduled Check if there is no scheduled cookie
  3590. deadline Check if there is a deadline
  3591. notdeadline Check if there is no deadline
  3592. timestamp Check if there is a timestamp (also deadline or scheduled)
  3593. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3594. regexp Check if regexp matches
  3595. notregexp Check if regexp does not match.
  3596. todo Check if TODO keyword matches
  3597. nottodo Check if TODO keyword does not match
  3598. The regexp is taken from the conditions list, it must come right after
  3599. the `regexp' or `notregexp' element.
  3600. `todo' and `nottodo' accept as an argument a list of todo
  3601. keywords, which may include \"*\" to match any todo keyword.
  3602. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3603. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3604. Instead of a list a keyword class may be given
  3605. (org-agenda-skip-entry-if 'nottodo 'done)
  3606. would skip entries that haven't been marked with any of \"DONE\"
  3607. keywords. Possible classes are: `todo', `done', `any'.
  3608. If any of these conditions is met, this function returns the end point of
  3609. the entity, causing the search to continue from there. This is a function
  3610. that can be put into `org-agenda-skip-function' for the duration of a command."
  3611. (let (beg end m)
  3612. (org-back-to-heading t)
  3613. (setq beg (point)
  3614. end (if subtree
  3615. (progn (org-end-of-subtree t) (point))
  3616. (progn (outline-next-heading) (1- (point)))))
  3617. (goto-char beg)
  3618. (and
  3619. (or
  3620. (and (memq 'scheduled conditions)
  3621. (re-search-forward org-scheduled-time-regexp end t))
  3622. (and (memq 'notscheduled conditions)
  3623. (not (re-search-forward org-scheduled-time-regexp end t)))
  3624. (and (memq 'deadline conditions)
  3625. (re-search-forward org-deadline-time-regexp end t))
  3626. (and (memq 'notdeadline conditions)
  3627. (not (re-search-forward org-deadline-time-regexp end t)))
  3628. (and (memq 'timestamp conditions)
  3629. (re-search-forward org-ts-regexp end t))
  3630. (and (memq 'nottimestamp conditions)
  3631. (not (re-search-forward org-ts-regexp end t)))
  3632. (and (setq m (memq 'regexp conditions))
  3633. (stringp (nth 1 m))
  3634. (re-search-forward (nth 1 m) end t))
  3635. (and (setq m (memq 'notregexp conditions))
  3636. (stringp (nth 1 m))
  3637. (not (re-search-forward (nth 1 m) end t)))
  3638. (and (or
  3639. (setq m (memq 'todo conditions))
  3640. (setq m (memq 'nottodo conditions)))
  3641. (org-agenda-skip-if-todo m end)))
  3642. end)))
  3643. (defun org-agenda-skip-if-todo (args end)
  3644. "Helper function for `org-agenda-skip-if', do not use it directly.
  3645. ARGS is a list with first element either `todo' or `nottodo'.
  3646. The remainder is either a list of TODO keywords, or a state symbol
  3647. `todo' or `done' or `any'."
  3648. (let ((kw (car args))
  3649. (arg (cadr args))
  3650. todo-wds todo-re)
  3651. (setq todo-wds
  3652. (org-uniquify
  3653. (cond
  3654. ((listp arg) ;; list of keywords
  3655. (if (member "*" arg)
  3656. (mapcar 'substring-no-properties org-todo-keywords-1)
  3657. arg))
  3658. ((symbolp arg) ;; keyword class name
  3659. (cond
  3660. ((eq arg 'todo)
  3661. (org-delete-all org-done-keywords
  3662. (mapcar 'substring-no-properties
  3663. org-todo-keywords-1)))
  3664. ((eq arg 'done) org-done-keywords)
  3665. ((eq arg 'any)
  3666. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3667. (setq todo-re
  3668. (concat "^\\*+[ \t]+\\<\\("
  3669. (mapconcat 'identity todo-wds "\\|")
  3670. "\\)\\>"))
  3671. (if (eq kw 'todo)
  3672. (re-search-forward todo-re end t)
  3673. (not (re-search-forward todo-re end t)))))
  3674. ;;;###autoload
  3675. (defun org-agenda-list-stuck-projects (&rest ignore)
  3676. "Create agenda view for projects that are stuck.
  3677. Stuck projects are project that have no next actions. For the definitions
  3678. of what a project is and how to check if it stuck, customize the variable
  3679. `org-stuck-projects'.
  3680. MATCH is being ignored."
  3681. (interactive)
  3682. (let* ((org-agenda-skip-function
  3683. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3684. ;; We could have used org-agenda-skip-if here.
  3685. (org-agenda-overriding-header
  3686. (or org-agenda-overriding-header "List of stuck projects: "))
  3687. (matcher (nth 0 org-stuck-projects))
  3688. (todo (nth 1 org-stuck-projects))
  3689. (todo-wds (if (member "*" todo)
  3690. (progn
  3691. (org-prepare-agenda-buffers (org-agenda-files
  3692. nil 'ifmode))
  3693. (org-delete-all
  3694. org-done-keywords-for-agenda
  3695. (copy-sequence org-todo-keywords-for-agenda)))
  3696. todo))
  3697. (todo-re (concat "^\\*+[ \t]+\\("
  3698. (mapconcat 'identity todo-wds "\\|")
  3699. "\\)\\>"))
  3700. (tags (nth 2 org-stuck-projects))
  3701. (tags-re (if (member "*" tags)
  3702. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3703. (if tags
  3704. (concat "^\\*+ .*:\\("
  3705. (mapconcat 'identity tags "\\|")
  3706. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3707. (gen-re (nth 3 org-stuck-projects))
  3708. (re-list
  3709. (delq nil
  3710. (list
  3711. (if todo todo-re)
  3712. (if tags tags-re)
  3713. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3714. gen-re)))))
  3715. (setq org-agenda-skip-regexp
  3716. (if re-list
  3717. (mapconcat 'identity re-list "\\|")
  3718. (error "No information how to identify unstuck projects")))
  3719. (org-tags-view nil matcher)
  3720. (with-current-buffer org-agenda-buffer-name
  3721. (setq org-agenda-redo-command
  3722. '(org-agenda-list-stuck-projects
  3723. (or current-prefix-arg org-last-arg))))))
  3724. ;;; Diary integration
  3725. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3726. (defvar list-diary-entries-hook)
  3727. (defun org-get-entries-from-diary (date)
  3728. "Get the (Emacs Calendar) diary entries for DATE."
  3729. (require 'diary-lib)
  3730. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3731. (diary-display-hook '(fancy-diary-display))
  3732. (diary-display-function 'fancy-diary-display)
  3733. (pop-up-frames nil)
  3734. (list-diary-entries-hook
  3735. (cons 'org-diary-default-entry list-diary-entries-hook))
  3736. (diary-file-name-prefix-function nil) ; turn this feature off
  3737. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3738. entries
  3739. (org-disable-agenda-to-diary t))
  3740. (save-excursion
  3741. (save-window-excursion
  3742. (funcall (if (fboundp 'diary-list-entries)
  3743. 'diary-list-entries 'list-diary-entries)
  3744. date 1)))
  3745. (if (not (get-buffer diary-fancy-buffer))
  3746. (setq entries nil)
  3747. (with-current-buffer diary-fancy-buffer
  3748. (setq buffer-read-only nil)
  3749. (if (zerop (buffer-size))
  3750. ;; No entries
  3751. (setq entries nil)
  3752. ;; Omit the date and other unnecessary stuff
  3753. (org-agenda-cleanup-fancy-diary)
  3754. ;; Add prefix to each line and extend the text properties
  3755. (if (zerop (buffer-size))
  3756. (setq entries nil)
  3757. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3758. (set-buffer-modified-p nil)
  3759. (kill-buffer diary-fancy-buffer)))
  3760. (when entries
  3761. (setq entries (org-split-string entries "\n"))
  3762. (setq entries
  3763. (mapcar
  3764. (lambda (x)
  3765. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3766. ;; Extend the text properties to the beginning of the line
  3767. (org-add-props x (text-properties-at (1- (length x)) x)
  3768. 'type "diary" 'date date 'face 'org-agenda-diary))
  3769. entries)))))
  3770. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3771. "Hook run when the fancy diary buffer is cleaned up.")
  3772. (defun org-agenda-cleanup-fancy-diary ()
  3773. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3774. This gets rid of the date, the underline under the date, and
  3775. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3776. date. It also removes lines that contain only whitespace."
  3777. (goto-char (point-min))
  3778. (if (looking-at ".*?:[ \t]*")
  3779. (progn
  3780. (replace-match "")
  3781. (re-search-forward "\n=+$" nil t)
  3782. (replace-match "")
  3783. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3784. (re-search-forward "\n=+$" nil t)
  3785. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3786. (goto-char (point-min))
  3787. (while (re-search-forward "^ +\n" nil t)
  3788. (replace-match ""))
  3789. (goto-char (point-min))
  3790. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3791. (replace-match ""))
  3792. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3793. ;; Make sure entries from the diary have the right text properties.
  3794. (eval-after-load "diary-lib"
  3795. '(if (boundp 'diary-modify-entry-list-string-function)
  3796. ;; We can rely on the hook, nothing to do
  3797. nil
  3798. ;; Hook not available, must use advice to make this work
  3799. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3800. "Make the position visible."
  3801. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3802. (stringp string)
  3803. buffer-file-name)
  3804. (setq string (org-modify-diary-entry-string string))))))
  3805. (defun org-modify-diary-entry-string (string)
  3806. "Add text properties to string, allowing org-mode to act on it."
  3807. (org-add-props string nil
  3808. 'mouse-face 'highlight
  3809. 'help-echo (if buffer-file-name
  3810. (format "mouse-2 or RET jump to diary file %s"
  3811. (abbreviate-file-name buffer-file-name))
  3812. "")
  3813. 'org-agenda-diary-link t
  3814. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3815. (defun org-diary-default-entry ()
  3816. "Add a dummy entry to the diary.
  3817. Needed to avoid empty dates which mess up holiday display."
  3818. ;; Catch the error if dealing with the new add-to-diary-alist
  3819. (when org-disable-agenda-to-diary
  3820. (condition-case nil
  3821. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3822. (error
  3823. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3824. (defun org-add-to-diary-list (&rest args)
  3825. (if (fboundp 'diary-add-to-list)
  3826. (apply 'diary-add-to-list args)
  3827. (apply 'add-to-diary-list args)))
  3828. (defvar org-diary-last-run-time nil)
  3829. ;;;###autoload
  3830. (defun org-diary (&rest args)
  3831. "Return diary information from org-files.
  3832. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3833. It accesses org files and extracts information from those files to be
  3834. listed in the diary. The function accepts arguments specifying what
  3835. items should be listed. For a list of arguments allowed here, see the
  3836. variable `org-agenda-entry-types'.
  3837. The call in the diary file should look like this:
  3838. &%%(org-diary) ~/path/to/some/orgfile.org
  3839. Use a separate line for each org file to check. Or, if you omit the file name,
  3840. all files listed in `org-agenda-files' will be checked automatically:
  3841. &%%(org-diary)
  3842. If you don't give any arguments (as in the example above), the default
  3843. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3844. So the example above may also be written as
  3845. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3846. The function expects the lisp variables `entry' and `date' to be provided
  3847. by the caller, because this is how the calendar works. Don't use this
  3848. function from a program - use `org-agenda-get-day-entries' instead."
  3849. (when (> (- (org-float-time)
  3850. org-agenda-last-marker-time)
  3851. 5)
  3852. (org-agenda-reset-markers))
  3853. (org-compile-prefix-format 'agenda)
  3854. (org-set-sorting-strategy 'agenda)
  3855. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3856. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3857. (list entry)
  3858. (org-agenda-files t)))
  3859. (time (org-float-time))
  3860. file rtn results)
  3861. (when (or (not org-diary-last-run-time)
  3862. (> (- time
  3863. org-diary-last-run-time)
  3864. 3))
  3865. (org-prepare-agenda-buffers files))
  3866. (setq org-diary-last-run-time time)
  3867. ;; If this is called during org-agenda, don't return any entries to
  3868. ;; the calendar. Org Agenda will list these entries itself.
  3869. (if org-disable-agenda-to-diary (setq files nil))
  3870. (while (setq file (pop files))
  3871. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3872. (setq results (append results rtn)))
  3873. (if results
  3874. (concat (org-finalize-agenda-entries results) "\n"))))
  3875. ;;; Agenda entry finders
  3876. (defun org-agenda-get-day-entries (file date &rest args)
  3877. "Does the work for `org-diary' and `org-agenda'.
  3878. FILE is the path to a file to be checked for entries. DATE is date like
  3879. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3880. which kind of entries should be extracted. For details about these, see
  3881. the documentation of `org-diary'."
  3882. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3883. (let* ((org-startup-folded nil)
  3884. (org-startup-align-all-tables nil)
  3885. (buffer (if (file-exists-p file)
  3886. (org-get-agenda-file-buffer file)
  3887. (error "No such file %s" file)))
  3888. arg results rtn deadline-results)
  3889. (if (not buffer)
  3890. ;; If file does not exist, make sure an error message ends up in diary
  3891. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3892. (with-current-buffer buffer
  3893. (unless (org-mode-p)
  3894. (error "Agenda file %s is not in `org-mode'" file))
  3895. (let ((case-fold-search nil))
  3896. (save-excursion
  3897. (save-restriction
  3898. (if org-agenda-restrict
  3899. (narrow-to-region org-agenda-restrict-begin
  3900. org-agenda-restrict-end)
  3901. (widen))
  3902. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3903. (while (setq arg (pop args))
  3904. (cond
  3905. ((and (eq arg :todo)
  3906. (equal date (calendar-current-date)))
  3907. (setq rtn (org-agenda-get-todos))
  3908. (setq results (append results rtn)))
  3909. ((eq arg :timestamp)
  3910. (setq rtn (org-agenda-get-blocks))
  3911. (setq results (append results rtn))
  3912. (setq rtn (org-agenda-get-timestamps))
  3913. (setq results (append results rtn)))
  3914. ((eq arg :sexp)
  3915. (setq rtn (org-agenda-get-sexps))
  3916. (setq results (append results rtn)))
  3917. ((eq arg :scheduled)
  3918. (setq rtn (org-agenda-get-scheduled deadline-results))
  3919. (setq results (append results rtn)))
  3920. ((eq arg :closed)
  3921. (setq rtn (org-agenda-get-progress))
  3922. (setq results (append results rtn)))
  3923. ((eq arg :deadline)
  3924. (setq rtn (org-agenda-get-deadlines))
  3925. (setq deadline-results (copy-sequence rtn))
  3926. (setq results (append results rtn))))))))
  3927. results))))
  3928. (defun org-agenda-get-todos ()
  3929. "Return the TODO information for agenda display."
  3930. (let* ((props (list 'face nil
  3931. 'done-face 'org-agenda-done
  3932. 'org-not-done-regexp org-not-done-regexp
  3933. 'org-todo-regexp org-todo-regexp
  3934. 'org-complex-heading-regexp org-complex-heading-regexp
  3935. 'mouse-face 'highlight
  3936. 'help-echo
  3937. (format "mouse-2 or RET jump to org file %s"
  3938. (abbreviate-file-name buffer-file-name))))
  3939. (regexp (concat "^\\*+[ \t]+\\("
  3940. (if org-select-this-todo-keyword
  3941. (if (equal org-select-this-todo-keyword "*")
  3942. org-todo-regexp
  3943. (concat "\\<\\("
  3944. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3945. "\\)\\>"))
  3946. org-not-done-regexp)
  3947. "[^\n\r]*\\)"))
  3948. marker priority category tags todo-state
  3949. ee txt beg end)
  3950. (goto-char (point-min))
  3951. (while (re-search-forward regexp nil t)
  3952. (catch :skip
  3953. (save-match-data
  3954. (beginning-of-line)
  3955. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3956. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3957. (goto-char (1+ beg))
  3958. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3959. (throw :skip nil)))
  3960. (goto-char beg)
  3961. (org-agenda-skip)
  3962. (goto-char (match-beginning 1))
  3963. (setq marker (org-agenda-new-marker (match-beginning 0))
  3964. category (org-get-category)
  3965. txt (match-string 1)
  3966. tags (org-get-tags-at (point))
  3967. txt (org-format-agenda-item "" txt category tags)
  3968. priority (1+ (org-get-priority txt))
  3969. todo-state (org-get-todo-state))
  3970. (org-add-props txt props
  3971. 'org-marker marker 'org-hd-marker marker
  3972. 'priority priority 'org-category category
  3973. 'type "todo" 'todo-state todo-state)
  3974. (push txt ee)
  3975. (if org-agenda-todo-list-sublevels
  3976. (goto-char (match-end 1))
  3977. (org-end-of-subtree 'invisible))))
  3978. (nreverse ee)))
  3979. ;;;###autoload
  3980. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  3981. (&optional end)
  3982. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  3983. (when (or org-agenda-todo-ignore-with-date
  3984. org-agenda-todo-ignore-scheduled
  3985. org-agenda-todo-ignore-deadlines)
  3986. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3987. (save-excursion
  3988. (or (and org-agenda-todo-ignore-with-date
  3989. (re-search-forward org-ts-regexp end t))
  3990. (and org-agenda-todo-ignore-scheduled
  3991. (re-search-forward org-scheduled-time-regexp end t)
  3992. (cond
  3993. ((eq org-agenda-todo-ignore-scheduled 'future)
  3994. (> (org-days-to-time (match-string 1)) 0))
  3995. ((eq org-agenda-todo-ignore-scheduled 'past)
  3996. (<= (org-days-to-time (match-string 1)) 0))
  3997. (t)))
  3998. (and org-agenda-todo-ignore-deadlines
  3999. (re-search-forward org-deadline-time-regexp end t)
  4000. (cond
  4001. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4002. ((eq org-agenda-todo-ignore-deadlines 'far)
  4003. (not (org-deadline-close (match-string 1))))
  4004. ((eq org-agenda-todo-ignore-deadlines 'future)
  4005. (> (org-days-to-time (match-string 1)) 0))
  4006. ((eq org-agenda-todo-ignore-deadlines 'past)
  4007. (<= (org-days-to-time (match-string 1)) 0))
  4008. (t (org-deadline-close (match-string 1)))))))))
  4009. (defconst org-agenda-no-heading-message
  4010. "No heading for this item in buffer or region.")
  4011. (defun org-agenda-get-timestamps ()
  4012. "Return the date stamp information for agenda display."
  4013. (let* ((props (list 'face nil
  4014. 'org-not-done-regexp org-not-done-regexp
  4015. 'org-todo-regexp org-todo-regexp
  4016. 'org-complex-heading-regexp org-complex-heading-regexp
  4017. 'mouse-face 'highlight
  4018. 'help-echo
  4019. (format "mouse-2 or RET jump to org file %s"
  4020. (abbreviate-file-name buffer-file-name))))
  4021. (d1 (calendar-absolute-from-gregorian date))
  4022. (remove-re
  4023. (concat
  4024. (regexp-quote
  4025. (format-time-string
  4026. "<%Y-%m-%d"
  4027. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4028. ".*?>"))
  4029. (regexp
  4030. (concat
  4031. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4032. (regexp-quote
  4033. (substring
  4034. (format-time-string
  4035. (car org-time-stamp-formats)
  4036. (apply 'encode-time ; DATE bound by calendar
  4037. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4038. 1 11))
  4039. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4040. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4041. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4042. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4043. todo-state end-of-match)
  4044. (goto-char (point-min))
  4045. (while (setq end-of-match (re-search-forward regexp nil t))
  4046. (setq b0 (match-beginning 0)
  4047. b3 (match-beginning 3) e3 (match-end 3))
  4048. (catch :skip
  4049. (and (org-at-date-range-p) (throw :skip nil))
  4050. (org-agenda-skip)
  4051. (if (and (match-end 1)
  4052. (not (= d1 (org-time-string-to-absolute
  4053. (match-string 1) d1 nil
  4054. org-agenda-repeating-timestamp-show-all))))
  4055. (throw :skip nil))
  4056. (if (and e3
  4057. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4058. (throw :skip nil))
  4059. (setq tmp (buffer-substring (max (point-min)
  4060. (- b0 org-ds-keyword-length))
  4061. b0)
  4062. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4063. inactivep (= (char-after b0) ?\[)
  4064. deadlinep (string-match org-deadline-regexp tmp)
  4065. scheduledp (string-match org-scheduled-regexp tmp)
  4066. closedp (and org-agenda-include-inactive-timestamps
  4067. (string-match org-closed-string tmp))
  4068. clockp (and org-agenda-include-inactive-timestamps
  4069. (or (string-match org-clock-string tmp)
  4070. (string-match "]-+\\'" tmp)))
  4071. todo-state (ignore-errors (org-get-todo-state))
  4072. donep (member todo-state org-done-keywords))
  4073. (if (or scheduledp deadlinep closedp clockp
  4074. (and donep org-agenda-skip-timestamp-if-done))
  4075. (throw :skip t))
  4076. (if (string-match ">" timestr)
  4077. ;; substring should only run to end of time stamp
  4078. (setq timestr (substring timestr 0 (match-end 0))))
  4079. (setq marker (org-agenda-new-marker b0)
  4080. category (org-get-category b0))
  4081. (save-excursion
  4082. (if (not (re-search-backward "^\\*+ " nil t))
  4083. (setq txt org-agenda-no-heading-message)
  4084. (goto-char (match-beginning 0))
  4085. (setq hdmarker (org-agenda-new-marker)
  4086. tags (org-get-tags-at))
  4087. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4088. (setq head (match-string 1))
  4089. (setq txt (org-format-agenda-item
  4090. (if inactivep org-agenda-inactive-leader nil)
  4091. head category tags timestr nil
  4092. remove-re)))
  4093. (setq priority (org-get-priority txt))
  4094. (org-add-props txt props
  4095. 'org-marker marker 'org-hd-marker hdmarker)
  4096. (org-add-props txt nil 'priority priority
  4097. 'org-category category 'date date
  4098. 'todo-state todo-state
  4099. 'type "timestamp")
  4100. (push txt ee))
  4101. (if org-agenda-skip-additional-timestamps-same-entry
  4102. (outline-next-heading)
  4103. (goto-char end-of-match))))
  4104. (nreverse ee)))
  4105. (defun org-agenda-get-sexps ()
  4106. "Return the sexp information for agenda display."
  4107. (require 'diary-lib)
  4108. (let* ((props (list 'face nil
  4109. 'mouse-face 'highlight
  4110. 'help-echo
  4111. (format "mouse-2 or RET jump to org file %s"
  4112. (abbreviate-file-name buffer-file-name))))
  4113. (regexp "^&?%%(")
  4114. marker category ee txt tags entry result beg b sexp sexp-entry
  4115. todo-state)
  4116. (goto-char (point-min))
  4117. (while (re-search-forward regexp nil t)
  4118. (catch :skip
  4119. (org-agenda-skip)
  4120. (setq beg (match-beginning 0))
  4121. (goto-char (1- (match-end 0)))
  4122. (setq b (point))
  4123. (forward-sexp 1)
  4124. (setq sexp (buffer-substring b (point)))
  4125. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4126. (org-trim (match-string 1))
  4127. ""))
  4128. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4129. (when result
  4130. (setq marker (org-agenda-new-marker beg)
  4131. category (org-get-category beg)
  4132. todo-state (org-get-todo-state))
  4133. (if (string-match "\\S-" result)
  4134. (setq txt result)
  4135. (setq txt "SEXP entry returned empty string"))
  4136. (setq txt (org-format-agenda-item
  4137. "" txt category tags 'time))
  4138. (org-add-props txt props 'org-marker marker)
  4139. (org-add-props txt nil
  4140. 'org-category category 'date date 'todo-state todo-state
  4141. 'type "sexp")
  4142. (push txt ee))))
  4143. (nreverse ee)))
  4144. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4145. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4146. The order of the first 2 times 3 arguments depends on the variable
  4147. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4148. So for American calendars, give this as MONTH DAY YEAR, for European as
  4149. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4150. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4151. is any number of ISO weeks in the block period for which the item should
  4152. be skipped."
  4153. (let* ((date1 (calendar-absolute-from-gregorian
  4154. (org-order-calendar-date-args m1 d1 y1)))
  4155. (date2 (calendar-absolute-from-gregorian
  4156. (org-order-calendar-date-args m2 d2 y2)))
  4157. (d (calendar-absolute-from-gregorian date)))
  4158. (and
  4159. (<= date1 d)
  4160. (<= d date2)
  4161. (= (calendar-day-of-week date) dayname)
  4162. (or (not skip-weeks)
  4163. (progn
  4164. (require 'cal-iso)
  4165. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4166. entry)))
  4167. (defalias 'org-get-closed 'org-agenda-get-progress)
  4168. (defun org-agenda-get-progress ()
  4169. "Return the logged TODO entries for agenda display."
  4170. (let* ((props (list 'mouse-face 'highlight
  4171. 'org-not-done-regexp org-not-done-regexp
  4172. 'org-todo-regexp org-todo-regexp
  4173. 'org-complex-heading-regexp org-complex-heading-regexp
  4174. 'help-echo
  4175. (format "mouse-2 or RET jump to org file %s"
  4176. (abbreviate-file-name buffer-file-name))))
  4177. (items (if (consp org-agenda-show-log)
  4178. org-agenda-show-log
  4179. org-agenda-log-mode-items))
  4180. (parts
  4181. (delq nil
  4182. (list
  4183. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4184. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4185. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4186. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4187. (error "`org-agenda-log-mode-items' is empty")))
  4188. (regexp (concat
  4189. "\\(" parts-re "\\)"
  4190. " *\\["
  4191. (regexp-quote
  4192. (substring
  4193. (format-time-string
  4194. (car org-time-stamp-formats)
  4195. (apply 'encode-time ; DATE bound by calendar
  4196. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4197. 1 11))))
  4198. (org-agenda-search-headline-for-time nil)
  4199. marker hdmarker priority category tags closedp statep clockp state
  4200. ee txt extra timestr rest clocked)
  4201. (goto-char (point-min))
  4202. (while (re-search-forward regexp nil t)
  4203. (catch :skip
  4204. (org-agenda-skip)
  4205. (setq marker (org-agenda-new-marker (match-beginning 0))
  4206. closedp (equal (match-string 1) org-closed-string)
  4207. statep (equal (string-to-char (match-string 1)) ?-)
  4208. clockp (not (or closedp statep))
  4209. state (and statep (match-string 2))
  4210. category (org-get-category (match-beginning 0))
  4211. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4212. )
  4213. (when (string-match "\\]" timestr)
  4214. ;; substring should only run to end of time stamp
  4215. (setq rest (substring timestr (match-end 0))
  4216. timestr (substring timestr 0 (match-end 0)))
  4217. (if (and (not closedp) (not statep)
  4218. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4219. (progn (setq timestr (concat (substring timestr 0 -1)
  4220. "-" (match-string 1 rest) "]"))
  4221. (setq clocked (match-string 2 rest)))
  4222. (setq clocked "-")))
  4223. (save-excursion
  4224. (setq extra nil)
  4225. (cond
  4226. ((not org-agenda-log-mode-add-notes))
  4227. (statep
  4228. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4229. (setq extra (match-string 1))))
  4230. (clockp
  4231. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4232. (setq extra (match-string 1)))))
  4233. (if (not (re-search-backward "^\\*+ " nil t))
  4234. (setq txt org-agenda-no-heading-message)
  4235. (goto-char (match-beginning 0))
  4236. (setq hdmarker (org-agenda-new-marker)
  4237. tags (org-get-tags-at))
  4238. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4239. (setq txt (match-string 1))
  4240. (when extra
  4241. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4242. (setq txt (concat (substring txt 0 (match-beginning 1))
  4243. " - " extra " " (match-string 2 txt)))
  4244. (setq txt (concat txt " - " extra))))
  4245. (setq txt (org-format-agenda-item
  4246. (cond
  4247. (closedp "Closed: ")
  4248. (statep (concat "State: (" state ")"))
  4249. (t (concat "Clocked: (" clocked ")")))
  4250. txt category tags timestr)))
  4251. (setq priority 100000)
  4252. (org-add-props txt props
  4253. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4254. 'priority priority 'org-category category
  4255. 'type "closed" 'date date
  4256. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4257. (push txt ee))
  4258. (goto-char (point-at-eol))))
  4259. (nreverse ee)))
  4260. (defun org-agenda-get-deadlines ()
  4261. "Return the deadline information for agenda display."
  4262. (let* ((props (list 'mouse-face 'highlight
  4263. 'org-not-done-regexp org-not-done-regexp
  4264. 'org-todo-regexp org-todo-regexp
  4265. 'org-complex-heading-regexp org-complex-heading-regexp
  4266. 'help-echo
  4267. (format "mouse-2 or RET jump to org file %s"
  4268. (abbreviate-file-name buffer-file-name))))
  4269. (regexp org-deadline-time-regexp)
  4270. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4271. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4272. d2 diff dfrac wdays pos pos1 category tags
  4273. suppress-prewarning
  4274. ee txt head face s todo-state upcomingp donep timestr)
  4275. (goto-char (point-min))
  4276. (while (re-search-forward regexp nil t)
  4277. (setq suppress-prewarning nil)
  4278. (catch :skip
  4279. (org-agenda-skip)
  4280. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4281. (save-match-data
  4282. (string-match org-scheduled-time-regexp
  4283. (buffer-substring (point-at-bol)
  4284. (point-at-eol)))))
  4285. (setq suppress-prewarning
  4286. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4287. org-agenda-skip-deadline-prewarning-if-scheduled
  4288. 0)))
  4289. (setq s (match-string 1)
  4290. txt nil
  4291. pos (1- (match-beginning 1))
  4292. d2 (org-time-string-to-absolute
  4293. (match-string 1) d1 'past
  4294. org-agenda-repeating-timestamp-show-all)
  4295. diff (- d2 d1)
  4296. wdays (if suppress-prewarning
  4297. (let ((org-deadline-warning-days suppress-prewarning))
  4298. (org-get-wdays s))
  4299. (org-get-wdays s))
  4300. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4301. upcomingp (and todayp (> diff 0)))
  4302. ;; When to show a deadline in the calendar:
  4303. ;; If the expiration is within wdays warning time.
  4304. ;; Past-due deadlines are only shown on the current date
  4305. (if (and (or (and (<= diff wdays)
  4306. (and todayp (not org-agenda-only-exact-dates)))
  4307. (= diff 0)))
  4308. (save-excursion
  4309. (setq todo-state (org-get-todo-state))
  4310. (setq donep (member todo-state org-done-keywords))
  4311. (if (and donep
  4312. (or org-agenda-skip-deadline-if-done
  4313. (not (= diff 0))))
  4314. (setq txt nil)
  4315. (setq category (org-get-category))
  4316. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4317. (setq txt org-agenda-no-heading-message)
  4318. (goto-char (match-end 0))
  4319. (setq pos1 (match-beginning 0))
  4320. (setq tags (org-get-tags-at pos1))
  4321. (setq head (buffer-substring-no-properties
  4322. (point)
  4323. (progn (skip-chars-forward "^\r\n")
  4324. (point))))
  4325. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4326. (setq timestr
  4327. (concat (substring s (match-beginning 1)) " "))
  4328. (setq timestr 'time))
  4329. (setq txt (org-format-agenda-item
  4330. (if (= diff 0)
  4331. (car org-agenda-deadline-leaders)
  4332. (if (functionp
  4333. (nth 1 org-agenda-deadline-leaders))
  4334. (funcall
  4335. (nth 1 org-agenda-deadline-leaders)
  4336. diff date)
  4337. (format (nth 1 org-agenda-deadline-leaders)
  4338. diff)))
  4339. head category tags
  4340. (if (not (= diff 0)) nil timestr)))))
  4341. (when txt
  4342. (setq face (org-agenda-deadline-face dfrac wdays))
  4343. (org-add-props txt props
  4344. 'org-marker (org-agenda-new-marker pos)
  4345. 'org-hd-marker (org-agenda-new-marker pos1)
  4346. 'priority (+ (- diff)
  4347. (org-get-priority txt))
  4348. 'org-category category
  4349. 'todo-state todo-state
  4350. 'type (if upcomingp "upcoming-deadline" "deadline")
  4351. 'date (if upcomingp date d2)
  4352. 'face (if donep 'org-agenda-done face)
  4353. 'undone-face face 'done-face 'org-agenda-done)
  4354. (push txt ee))))))
  4355. (nreverse ee)))
  4356. (defun org-agenda-deadline-face (fraction &optional wdays)
  4357. "Return the face to displaying a deadline item.
  4358. FRACTION is what fraction of the head-warning time has passed."
  4359. (if (equal wdays 0) (setq fraction 1.))
  4360. (let ((faces org-agenda-deadline-faces) f)
  4361. (catch 'exit
  4362. (while (setq f (pop faces))
  4363. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4364. (defun org-agenda-get-scheduled (&optional deadline-results)
  4365. "Return the scheduled information for agenda display."
  4366. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4367. 'org-todo-regexp org-todo-regexp
  4368. 'org-complex-heading-regexp org-complex-heading-regexp
  4369. 'done-face 'org-agenda-done
  4370. 'mouse-face 'highlight
  4371. 'help-echo
  4372. (format "mouse-2 or RET jump to org file %s"
  4373. (abbreviate-file-name buffer-file-name))))
  4374. (regexp org-scheduled-time-regexp)
  4375. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4376. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4377. mm
  4378. (deadline-position-alist
  4379. (mapcar (lambda (a) (and (setq mm (get-text-property
  4380. 0 'org-hd-marker a))
  4381. (cons (marker-position mm) a)))
  4382. deadline-results))
  4383. d2 diff pos pos1 category tags donep
  4384. ee txt head pastschedp todo-state face timestr s habitp)
  4385. (goto-char (point-min))
  4386. (while (re-search-forward regexp nil t)
  4387. (catch :skip
  4388. (org-agenda-skip)
  4389. (setq s (match-string 1)
  4390. txt nil
  4391. pos (1- (match-beginning 1))
  4392. d2 (org-time-string-to-absolute
  4393. (match-string 1) d1 'past
  4394. org-agenda-repeating-timestamp-show-all)
  4395. diff (- d2 d1))
  4396. (setq pastschedp (and todayp (< diff 0)))
  4397. ;; When to show a scheduled item in the calendar:
  4398. ;; If it is on or past the date.
  4399. (when (or (and (< diff 0)
  4400. (< (abs diff) org-scheduled-past-days)
  4401. (and todayp (not org-agenda-only-exact-dates)))
  4402. (= diff 0))
  4403. (save-excursion
  4404. (setq todo-state (org-get-todo-state))
  4405. (setq donep (member todo-state org-done-keywords))
  4406. (setq habitp (and (functionp 'org-is-habit-p)
  4407. (org-is-habit-p)))
  4408. (if (and donep
  4409. (or habitp org-agenda-skip-scheduled-if-done
  4410. (not (= diff 0))))
  4411. (setq txt nil)
  4412. (setq category (org-get-category))
  4413. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4414. (setq txt org-agenda-no-heading-message)
  4415. (goto-char (match-end 0))
  4416. (setq pos1 (match-beginning 0))
  4417. (if habitp
  4418. (if (or (not org-habit-show-habits)
  4419. (and (not todayp)
  4420. org-habit-show-habits-only-for-today))
  4421. (throw :skip nil))
  4422. (if (and
  4423. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4424. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4425. pastschedp))
  4426. (setq mm (assoc pos1 deadline-position-alist)))
  4427. (throw :skip nil)))
  4428. (setq tags (org-get-tags-at))
  4429. (setq head (buffer-substring-no-properties
  4430. (point)
  4431. (progn (skip-chars-forward "^\r\n") (point))))
  4432. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4433. (setq timestr
  4434. (concat (substring s (match-beginning 1)) " "))
  4435. (setq timestr 'time))
  4436. (setq txt (org-format-agenda-item
  4437. (if (= diff 0)
  4438. (car org-agenda-scheduled-leaders)
  4439. (format (nth 1 org-agenda-scheduled-leaders)
  4440. (- 1 diff)))
  4441. head category tags
  4442. (if (not (= diff 0)) nil timestr)
  4443. nil nil habitp))))
  4444. (when txt
  4445. (setq face
  4446. (cond
  4447. ((and (not habitp) pastschedp)
  4448. 'org-scheduled-previously)
  4449. (todayp 'org-scheduled-today)
  4450. (t 'org-scheduled))
  4451. habitp (and habitp (org-habit-parse-todo)))
  4452. (org-add-props txt props
  4453. 'undone-face face
  4454. 'face (if donep 'org-agenda-done face)
  4455. 'org-marker (org-agenda-new-marker pos)
  4456. 'org-hd-marker (org-agenda-new-marker pos1)
  4457. 'type (if pastschedp "past-scheduled" "scheduled")
  4458. 'date (if pastschedp d2 date)
  4459. 'priority (if habitp
  4460. (org-habit-get-priority habitp)
  4461. (+ 94 (- 5 diff) (org-get-priority txt)))
  4462. 'org-category category
  4463. 'org-habit-p habitp
  4464. 'todo-state todo-state)
  4465. (push txt ee))))))
  4466. (nreverse ee)))
  4467. (defun org-agenda-get-blocks ()
  4468. "Return the date-range information for agenda display."
  4469. (let* ((props (list 'face nil
  4470. 'org-not-done-regexp org-not-done-regexp
  4471. 'org-todo-regexp org-todo-regexp
  4472. 'org-complex-heading-regexp org-complex-heading-regexp
  4473. 'mouse-face 'highlight
  4474. 'help-echo
  4475. (format "mouse-2 or RET jump to org file %s"
  4476. (abbreviate-file-name buffer-file-name))))
  4477. (regexp org-tr-regexp)
  4478. (d0 (calendar-absolute-from-gregorian date))
  4479. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4480. head donep)
  4481. (goto-char (point-min))
  4482. (while (re-search-forward regexp nil t)
  4483. (catch :skip
  4484. (org-agenda-skip)
  4485. (setq pos (point))
  4486. (setq timestr (match-string 0)
  4487. s1 (match-string 1)
  4488. s2 (match-string 2)
  4489. d1 (time-to-days (org-time-string-to-time s1))
  4490. d2 (time-to-days (org-time-string-to-time s2)))
  4491. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4492. ;; Only allow days between the limits, because the normal
  4493. ;; date stamps will catch the limits.
  4494. (save-excursion
  4495. (setq todo-state (org-get-todo-state))
  4496. (setq donep (member todo-state org-done-keywords))
  4497. (if (and donep org-agenda-skip-timestamp-if-done)
  4498. (throw :skip t))
  4499. (setq marker (org-agenda-new-marker (point)))
  4500. (setq category (org-get-category))
  4501. (if (not (re-search-backward "^\\*+ " nil t))
  4502. (setq txt org-agenda-no-heading-message)
  4503. (goto-char (match-beginning 0))
  4504. (setq hdmarker (org-agenda-new-marker (point)))
  4505. (setq tags (org-get-tags-at))
  4506. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4507. (setq head (match-string 1))
  4508. (let ((remove-re
  4509. (if org-agenda-remove-timeranges-from-blocks
  4510. (concat
  4511. "<" (regexp-quote s1) ".*?>"
  4512. "--"
  4513. "<" (regexp-quote s2) ".*?>")
  4514. nil)))
  4515. (setq txt (org-format-agenda-item
  4516. (format
  4517. (nth (if (= d1 d2) 0 1)
  4518. org-agenda-timerange-leaders)
  4519. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4520. head category tags
  4521. timestr nil remove-re))))
  4522. (org-add-props txt props
  4523. 'org-marker marker 'org-hd-marker hdmarker
  4524. 'type "block" 'date date
  4525. 'todo-state todo-state
  4526. 'priority (org-get-priority txt) 'org-category category)
  4527. (push txt ee)))
  4528. (goto-char pos)))
  4529. ;; Sort the entries by expiration date.
  4530. (nreverse ee)))
  4531. ;;; Agenda presentation and sorting
  4532. (defvar org-prefix-has-time nil
  4533. "A flag, set by `org-compile-prefix-format'.
  4534. The flag is set if the currently compiled format contains a `%t'.")
  4535. (defvar org-prefix-has-tag nil
  4536. "A flag, set by `org-compile-prefix-format'.
  4537. The flag is set if the currently compiled format contains a `%T'.")
  4538. (defvar org-prefix-has-effort nil
  4539. "A flag, set by `org-compile-prefix-format'.
  4540. The flag is set if the currently compiled format contains a `%e'.")
  4541. (defvar org-prefix-category-length nil
  4542. "Used by `org-compile-prefix-format' to remember the category field width.")
  4543. (defvar org-prefix-category-max-length nil
  4544. "Used by `org-compile-prefix-format' to remember the category field width.")
  4545. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4546. noprefix remove-re habitp)
  4547. "Format TXT to be inserted into the agenda buffer.
  4548. In particular, it adds the prefix and corresponding text properties. EXTRA
  4549. must be a string and replaces the `%s' specifier in the prefix format.
  4550. CATEGORY (string, symbol or nil) may be used to overrule the default
  4551. category taken from local variable or file name. It will replace the `%c'
  4552. specifier in the format. DOTIME, when non-nil, indicates that a
  4553. time-of-day should be extracted from TXT for sorting of this entry, and for
  4554. the `%t' specifier in the format. When DOTIME is a string, this string is
  4555. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4556. only the correctly processes TXT should be returned - this is used by
  4557. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4558. Any match of REMOVE-RE will be removed from TXT."
  4559. (save-match-data
  4560. ;; Diary entries sometimes have extra whitespace at the beginning
  4561. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4562. ;; Fix the tags part in txt
  4563. (setq txt (org-agenda-fix-displayed-tags
  4564. txt tags
  4565. org-agenda-show-inherited-tags
  4566. org-agenda-hide-tags-regexp))
  4567. (let* ((category (or category
  4568. org-category
  4569. (if buffer-file-name
  4570. (file-name-sans-extension
  4571. (file-name-nondirectory buffer-file-name))
  4572. "")))
  4573. ;; time, tag, effort are needed for the eval of the prefix format
  4574. (tag (if tags (nth (1- (length tags)) tags) ""))
  4575. time effort neffort
  4576. (ts (if dotime (concat
  4577. (if (stringp dotime) dotime "")
  4578. (and org-agenda-search-headline-for-time txt))))
  4579. (time-of-day (and dotime (org-get-time-of-day ts)))
  4580. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4581. duration thecategory)
  4582. (and (org-mode-p) buffer-file-name
  4583. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4584. (when (and dotime time-of-day)
  4585. ;; Extract starting and ending time and move them to prefix
  4586. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4587. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4588. (setq s0 (match-string 0 ts)
  4589. srp (and stamp (match-end 3))
  4590. s1 (match-string (if plain 1 2) ts)
  4591. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4592. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4593. ;; them, we might want to remove them there to avoid duplication.
  4594. ;; The user can turn this off with a variable.
  4595. (if (and org-prefix-has-time
  4596. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4597. (string-match (concat (regexp-quote s0) " *") txt)
  4598. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4599. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4600. (= (match-beginning 0) 0)
  4601. t))
  4602. (setq txt (replace-match "" nil nil txt))))
  4603. ;; Normalize the time(s) to 24 hour
  4604. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4605. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4606. ;; Compute the duration
  4607. (when s1
  4608. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4609. (string-to-number (substring s1 3)))
  4610. t2 (cond
  4611. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4612. (string-to-number (substring s2 3))))
  4613. (org-agenda-default-appointment-duration
  4614. (+ t1 org-agenda-default-appointment-duration))
  4615. (t nil)))
  4616. (setq duration (if t2 (- t2 t1)))))
  4617. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4618. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4619. (let ((m (+ (string-to-number (match-string 2 s1))
  4620. (* 60 (string-to-number (match-string 1 s1)))
  4621. org-agenda-default-appointment-duration))
  4622. h)
  4623. (setq h (/ m 60) m (- m (* h 60)))
  4624. (setq s2 (format "%02d:%02d" h m))))
  4625. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4626. txt)
  4627. ;; Tags are in the string
  4628. (if (or (eq org-agenda-remove-tags t)
  4629. (and org-agenda-remove-tags
  4630. org-prefix-has-tag))
  4631. (setq txt (replace-match "" t t txt))
  4632. (setq txt (replace-match
  4633. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4634. (match-string 2 txt))
  4635. t t txt))))
  4636. (when (org-mode-p)
  4637. (setq effort
  4638. (condition-case nil
  4639. (org-get-effort
  4640. (or (get-text-property 0 'org-hd-marker txt)
  4641. (get-text-property 0 'org-marker txt)))
  4642. (error nil)))
  4643. (when effort
  4644. (setq neffort (org-hh:mm-string-to-minutes effort)
  4645. effort (setq effort (concat "[" effort "]" )))))
  4646. (when remove-re
  4647. (while (string-match remove-re txt)
  4648. (setq txt (replace-match "" t t txt))))
  4649. ;; Create the final string
  4650. (if noprefix
  4651. (setq rtn txt)
  4652. ;; Prepare the variables needed in the eval of the compiled format
  4653. (setq time (cond (s2 (concat s1 "-" s2))
  4654. (s1 (concat s1 "......"))
  4655. (t ""))
  4656. extra (or (and (not habitp) extra) "")
  4657. category (if (symbolp category) (symbol-name category) category)
  4658. thecategory (copy-sequence category))
  4659. (if (string-match org-bracket-link-regexp category)
  4660. (progn
  4661. (setq l (if (match-end 3)
  4662. (- (match-end 3) (match-beginning 3))
  4663. (- (match-end 1) (match-beginning 1))))
  4664. (when (< l (or org-prefix-category-length 0))
  4665. (setq category (copy-sequence category))
  4666. (org-add-props category nil
  4667. 'extra-space (make-string
  4668. (- org-prefix-category-length l 1) ?\ ))))
  4669. (if (and org-prefix-category-max-length
  4670. (>= (length category) org-prefix-category-max-length))
  4671. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4672. ;; Evaluate the compiled format
  4673. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4674. ;; And finally add the text properties
  4675. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4676. (org-add-props rtn nil
  4677. 'org-category (if thecategory (downcase thecategory) category)
  4678. 'tags (mapcar 'org-downcase-keep-props tags)
  4679. 'org-highest-priority org-highest-priority
  4680. 'org-lowest-priority org-lowest-priority
  4681. 'prefix-length (- (length rtn) (length txt))
  4682. 'time-of-day time-of-day
  4683. 'duration duration
  4684. 'effort effort
  4685. 'effort-minutes neffort
  4686. 'txt txt
  4687. 'time time
  4688. 'extra extra
  4689. 'dotime dotime))))
  4690. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4691. "Remove tags string from TXT, and add a modified list of tags.
  4692. The modified list may contain inherited tags, and tags matched by
  4693. `org-agenda-hide-tags-regexp' will be removed."
  4694. (when (or add-inherited hide-re)
  4695. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4696. (setq txt (substring txt 0 (match-beginning 0))))
  4697. (setq tags
  4698. (delq nil
  4699. (mapcar (lambda (tg)
  4700. (if (or (and hide-re (string-match hide-re tg))
  4701. (and (not add-inherited)
  4702. (get-text-property 0 'inherited tg)))
  4703. nil
  4704. tg))
  4705. tags)))
  4706. (when tags
  4707. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4708. i)
  4709. (setq txt (concat txt " :"
  4710. (mapconcat
  4711. (lambda (x)
  4712. (setq i (get-text-property 0 'inherited x))
  4713. (if (and have-i (not i))
  4714. (progn
  4715. (setq have-i nil)
  4716. (concat ":" x))
  4717. x))
  4718. tags ":")
  4719. (if have-i "::" ":"))))))
  4720. txt)
  4721. (defun org-downcase-keep-props (s)
  4722. (let ((props (text-properties-at 0 s)))
  4723. (setq s (downcase s))
  4724. (add-text-properties 0 (length s) props s)
  4725. s))
  4726. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4727. (defvar org-agenda-sorting-strategy-selected nil)
  4728. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4729. (catch 'exit
  4730. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4731. ((and todayp (member 'today (car org-agenda-time-grid))))
  4732. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4733. ((member 'weekly (car org-agenda-time-grid)))
  4734. (t (throw 'exit list)))
  4735. (let* ((have (delq nil (mapcar
  4736. (lambda (x) (get-text-property 1 'time-of-day x))
  4737. list)))
  4738. (string (nth 1 org-agenda-time-grid))
  4739. (gridtimes (nth 2 org-agenda-time-grid))
  4740. (req (car org-agenda-time-grid))
  4741. (remove (member 'remove-match req))
  4742. new time)
  4743. (if (and (member 'require-timed req) (not have))
  4744. ;; don't show empty grid
  4745. (throw 'exit list))
  4746. (while (setq time (pop gridtimes))
  4747. (unless (and remove (member time have))
  4748. (setq time (int-to-string time))
  4749. (push (org-format-agenda-item
  4750. nil string "" nil
  4751. (concat (substring time 0 -2) ":" (substring time -2)))
  4752. new)
  4753. (put-text-property
  4754. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4755. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4756. (append new list)
  4757. (append list new)))))
  4758. (defun org-compile-prefix-format (key)
  4759. "Compile the prefix format into a Lisp form that can be evaluated.
  4760. The resulting form is returned and stored in the variable
  4761. `org-prefix-format-compiled'."
  4762. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4763. org-prefix-category-length nil org-prefix-has-effort nil)
  4764. (let ((s (cond
  4765. ((stringp org-agenda-prefix-format)
  4766. org-agenda-prefix-format)
  4767. ((assq key org-agenda-prefix-format)
  4768. (cdr (assq key org-agenda-prefix-format)))
  4769. (t " %-12:c%?-12t% s")))
  4770. (start 0)
  4771. varform vars var e c f opt)
  4772. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4773. s start)
  4774. (setq var (cdr (assoc (match-string 4 s)
  4775. '(("c" . category) ("t" . time) ("s" . extra)
  4776. ("T" . tag) ("e" . effort))))
  4777. c (or (match-string 3 s) "")
  4778. opt (match-beginning 1)
  4779. start (1+ (match-beginning 0)))
  4780. (if (equal var 'time) (setq org-prefix-has-time t))
  4781. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4782. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4783. (setq f (concat "%" (match-string 2 s) "s"))
  4784. (when (equal var 'category)
  4785. (setq org-prefix-category-length
  4786. (floor (abs (string-to-number (match-string 2 s)))))
  4787. (setq org-prefix-category-max-length
  4788. (let ((x (match-string 2 s)))
  4789. (save-match-data
  4790. (if (string-match "\\.[0-9]+" x)
  4791. (string-to-number (substring (match-string 0 x) 1)))))))
  4792. (if opt
  4793. (setq varform
  4794. `(if (equal "" ,var)
  4795. ""
  4796. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4797. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4798. (setq s (replace-match "%s" t nil s))
  4799. (push varform vars))
  4800. (setq vars (nreverse vars))
  4801. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4802. (defun org-set-sorting-strategy (key)
  4803. (if (symbolp (car org-agenda-sorting-strategy))
  4804. ;; the old format
  4805. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4806. (setq org-agenda-sorting-strategy-selected
  4807. (or (cdr (assq key org-agenda-sorting-strategy))
  4808. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4809. '(time-up category-keep priority-down)))))
  4810. (defun org-get-time-of-day (s &optional string mod24)
  4811. "Check string S for a time of day.
  4812. If found, return it as a military time number between 0 and 2400.
  4813. If not found, return nil.
  4814. The optional STRING argument forces conversion into a 5 character wide string
  4815. HH:MM."
  4816. (save-match-data
  4817. (when
  4818. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4819. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4820. (let* ((h (string-to-number (match-string 1 s)))
  4821. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4822. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4823. (am-p (equal ampm "am"))
  4824. (h1 (cond ((not ampm) h)
  4825. ((= h 12) (if am-p 0 12))
  4826. (t (+ h (if am-p 0 12)))))
  4827. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4828. (mod h1 24) h1))
  4829. (t0 (+ (* 100 h2) m))
  4830. (t1 (concat (if (>= h1 24) "+" " ")
  4831. (if (and org-agenda-time-leading-zero
  4832. (< t0 1000)) "0" "")
  4833. (if (< t0 100) "0" "")
  4834. (if (< t0 10) "0" "")
  4835. (int-to-string t0))))
  4836. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4837. (defun org-finalize-agenda-entries (list &optional nosort)
  4838. "Sort and concatenate the agenda items."
  4839. (setq list (mapcar 'org-agenda-highlight-todo list))
  4840. (if nosort
  4841. list
  4842. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4843. (defun org-agenda-highlight-todo (x)
  4844. (let ((org-done-keywords org-done-keywords-for-agenda)
  4845. (case-fold-search nil)
  4846. re pl)
  4847. (if (eq x 'line)
  4848. (save-excursion
  4849. (beginning-of-line 1)
  4850. (setq re (org-get-at-bol 'org-todo-regexp))
  4851. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4852. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4853. (add-text-properties (match-beginning 0) (match-end 1)
  4854. (list 'face (org-get-todo-face 1)))
  4855. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4856. (delete-region (match-beginning 1) (1- (match-end 0)))
  4857. (goto-char (match-beginning 1))
  4858. (insert (format org-agenda-todo-keyword-format s)))))
  4859. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4860. pl (get-text-property 0 'prefix-length x))
  4861. (when (and re
  4862. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4863. x (or pl 0)) pl))
  4864. (add-text-properties
  4865. (or (match-end 1) (match-end 0)) (match-end 0)
  4866. (list 'face (org-get-todo-face (match-string 2 x)))
  4867. x)
  4868. (when (match-end 1)
  4869. (setq x (concat (substring x 0 (match-end 1))
  4870. (format org-agenda-todo-keyword-format
  4871. (match-string 2 x))
  4872. (org-add-props " " (text-properties-at 0 x))
  4873. (substring x (match-end 3))))))
  4874. x)))
  4875. (defsubst org-cmp-priority (a b)
  4876. "Compare the priorities of string A and B."
  4877. (let ((pa (or (get-text-property 1 'priority a) 0))
  4878. (pb (or (get-text-property 1 'priority b) 0)))
  4879. (cond ((> pa pb) +1)
  4880. ((< pa pb) -1)
  4881. (t nil))))
  4882. (defsubst org-cmp-effort (a b)
  4883. "Compare the priorities of string A and B."
  4884. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4885. (ea (or (get-text-property 1 'effort-minutes a) def))
  4886. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4887. (cond ((> ea eb) +1)
  4888. ((< ea eb) -1)
  4889. (t nil))))
  4890. (defsubst org-cmp-category (a b)
  4891. "Compare the string values of categories of strings A and B."
  4892. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4893. (cb (or (get-text-property 1 'org-category b) "")))
  4894. (cond ((string-lessp ca cb) -1)
  4895. ((string-lessp cb ca) +1)
  4896. (t nil))))
  4897. (defsubst org-cmp-todo-state (a b)
  4898. "Compare the todo states of strings A and B."
  4899. (let* ((ma (or (get-text-property 1 'org-marker a)
  4900. (get-text-property 1 'org-hd-marker a)))
  4901. (mb (or (get-text-property 1 'org-marker b)
  4902. (get-text-property 1 'org-hd-marker b)))
  4903. (fa (and ma (marker-buffer ma)))
  4904. (fb (and mb (marker-buffer mb)))
  4905. (todo-kwds
  4906. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4907. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4908. (ta (or (get-text-property 1 'todo-state a) ""))
  4909. (tb (or (get-text-property 1 'todo-state b) ""))
  4910. (la (- (length (member ta todo-kwds))))
  4911. (lb (- (length (member tb todo-kwds))))
  4912. (donepa (member ta org-done-keywords-for-agenda))
  4913. (donepb (member tb org-done-keywords-for-agenda)))
  4914. (cond ((and donepa (not donepb)) -1)
  4915. ((and (not donepa) donepb) +1)
  4916. ((< la lb) -1)
  4917. ((< lb la) +1)
  4918. (t nil))))
  4919. (defsubst org-cmp-alpha (a b)
  4920. "Compare the headlines, alphabetically."
  4921. (let* ((pla (get-text-property 0 'prefix-length a))
  4922. (plb (get-text-property 0 'prefix-length b))
  4923. (ta (and pla (substring a pla)))
  4924. (tb (and plb (substring b plb))))
  4925. (when pla
  4926. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  4927. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  4928. (setq ta (substring ta (match-end 0))))
  4929. (setq ta (downcase ta)))
  4930. (when plb
  4931. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  4932. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  4933. (setq tb (substring tb (match-end 0))))
  4934. (setq tb (downcase tb)))
  4935. (cond ((not ta) +1)
  4936. ((not tb) -1)
  4937. ((string-lessp ta tb) -1)
  4938. ((string-lessp tb ta) +1)
  4939. (t nil))))
  4940. (defsubst org-cmp-tag (a b)
  4941. "Compare the string values of the first tags of A and B."
  4942. (let ((ta (car (last (get-text-property 1 'tags a))))
  4943. (tb (car (last (get-text-property 1 'tags b)))))
  4944. (cond ((not ta) +1)
  4945. ((not tb) -1)
  4946. ((string-lessp ta tb) -1)
  4947. ((string-lessp tb ta) +1)
  4948. (t nil))))
  4949. (defsubst org-cmp-time (a b)
  4950. "Compare the time-of-day values of strings A and B."
  4951. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4952. (ta (or (get-text-property 1 'time-of-day a) def))
  4953. (tb (or (get-text-property 1 'time-of-day b) def)))
  4954. (cond ((< ta tb) -1)
  4955. ((< tb ta) +1)
  4956. (t nil))))
  4957. (defsubst org-cmp-habit-p (a b)
  4958. "Compare the todo states of strings A and B."
  4959. (let ((ha (get-text-property 1 'org-habit-p a))
  4960. (hb (get-text-property 1 'org-habit-p b)))
  4961. (cond ((and ha (not hb)) -1)
  4962. ((and (not ha) hb) +1)
  4963. (t nil))))
  4964. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  4965. (defun org-entries-lessp (a b)
  4966. "Predicate for sorting agenda entries."
  4967. ;; The following variables will be used when the form is evaluated.
  4968. ;; So even though the compiler complains, keep them.
  4969. (let* ((ss org-agenda-sorting-strategy-selected)
  4970. (time-up (and (org-em 'time-up 'time-down ss)
  4971. (org-cmp-time a b)))
  4972. (time-down (if time-up (- time-up) nil))
  4973. (priority-up (and (org-em 'priority-up 'priority-down ss)
  4974. (org-cmp-priority a b)))
  4975. (priority-down (if priority-up (- priority-up) nil))
  4976. (effort-up (and (org-em 'effort-up 'effort-down ss)
  4977. (org-cmp-effort a b)))
  4978. (effort-down (if effort-up (- effort-up) nil))
  4979. (category-up (and (or (org-em 'category-up 'category-down ss)
  4980. (memq 'category-keep ss))
  4981. (org-cmp-category a b)))
  4982. (category-down (if category-up (- category-up) nil))
  4983. (category-keep (if category-up +1 nil))
  4984. (tag-up (and (org-em 'tag-up 'tag-down ss)
  4985. (org-cmp-tag a b)))
  4986. (tag-down (if tag-up (- tag-up) nil))
  4987. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  4988. (org-cmp-todo-state a b)))
  4989. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4990. (habit-up (and (org-em 'habit-up 'habit-down ss)
  4991. (org-cmp-habit-p a b)))
  4992. (habit-down (if habit-up (- habit-up) nil))
  4993. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  4994. (org-cmp-alpha a b)))
  4995. (alpha-down (if alpha-up (- alpha-up) nil))
  4996. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  4997. user-defined-up user-defined-down)
  4998. (if (and need-user-cmp org-agenda-cmp-user-defined
  4999. (functionp org-agenda-cmp-user-defined))
  5000. (setq user-defined-up
  5001. (funcall org-agenda-cmp-user-defined a b)
  5002. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5003. (cdr (assoc
  5004. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5005. '((-1 . t) (1 . nil) (nil . nil))))))
  5006. ;;; Agenda restriction lock
  5007. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5008. "Overlay to mark the headline to which agenda commands are restricted.")
  5009. (overlay-put org-agenda-restriction-lock-overlay
  5010. 'face 'org-agenda-restriction-lock)
  5011. (overlay-put org-agenda-restriction-lock-overlay
  5012. 'help-echo "Agendas are currently limited to this subtree.")
  5013. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5014. (defun org-agenda-set-restriction-lock (&optional type)
  5015. "Set restriction lock for agenda, to current subtree or file.
  5016. Restriction will be the file if TYPE is `file', or if type is the
  5017. universal prefix '(4), or if the cursor is before the first headline
  5018. in the file. Otherwise, restriction will be to the current subtree."
  5019. (interactive "P")
  5020. (and (equal type '(4)) (setq type 'file))
  5021. (setq type (cond
  5022. (type type)
  5023. ((org-at-heading-p) 'subtree)
  5024. ((condition-case nil (org-back-to-heading t) (error nil))
  5025. 'subtree)
  5026. (t 'file)))
  5027. (if (eq type 'subtree)
  5028. (progn
  5029. (setq org-agenda-restrict t)
  5030. (setq org-agenda-overriding-restriction 'subtree)
  5031. (put 'org-agenda-files 'org-restrict
  5032. (list (buffer-file-name (buffer-base-buffer))))
  5033. (org-back-to-heading t)
  5034. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5035. (move-marker org-agenda-restrict-begin (point))
  5036. (move-marker org-agenda-restrict-end
  5037. (save-excursion (org-end-of-subtree t)))
  5038. (message "Locking agenda restriction to subtree"))
  5039. (put 'org-agenda-files 'org-restrict
  5040. (list (buffer-file-name (buffer-base-buffer))))
  5041. (setq org-agenda-restrict nil)
  5042. (setq org-agenda-overriding-restriction 'file)
  5043. (move-marker org-agenda-restrict-begin nil)
  5044. (move-marker org-agenda-restrict-end nil)
  5045. (message "Locking agenda restriction to file"))
  5046. (setq current-prefix-arg nil)
  5047. (org-agenda-maybe-redo))
  5048. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5049. "Remove the agenda restriction lock."
  5050. (interactive "P")
  5051. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5052. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5053. (setq org-agenda-overriding-restriction nil)
  5054. (setq org-agenda-restrict nil)
  5055. (put 'org-agenda-files 'org-restrict nil)
  5056. (move-marker org-agenda-restrict-begin nil)
  5057. (move-marker org-agenda-restrict-end nil)
  5058. (setq current-prefix-arg nil)
  5059. (message "Agenda restriction lock removed")
  5060. (or noupdate (org-agenda-maybe-redo)))
  5061. (defun org-agenda-maybe-redo ()
  5062. "If there is any window showing the agenda view, update it."
  5063. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5064. (w0 (selected-window)))
  5065. (when w
  5066. (select-window w)
  5067. (org-agenda-redo)
  5068. (select-window w0)
  5069. (if org-agenda-overriding-restriction
  5070. (message "Agenda view shifted to new %s restriction"
  5071. org-agenda-overriding-restriction)
  5072. (message "Agenda restriction lock removed")))))
  5073. ;;; Agenda commands
  5074. (defun org-agenda-check-type (error &rest types)
  5075. "Check if agenda buffer is of allowed type.
  5076. If ERROR is non-nil, throw an error, otherwise just return nil."
  5077. (if (memq org-agenda-type types)
  5078. t
  5079. (if error
  5080. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5081. nil)))
  5082. (defun org-agenda-quit ()
  5083. "Exit agenda by removing the window or the buffer."
  5084. (interactive)
  5085. (if org-agenda-columns-active
  5086. (org-columns-quit)
  5087. (let ((buf (current-buffer)))
  5088. (if (eq org-agenda-window-setup 'other-frame)
  5089. (progn
  5090. (kill-buffer buf)
  5091. (org-agenda-reset-markers)
  5092. (org-columns-remove-overlays)
  5093. (setq org-agenda-archives-mode nil)
  5094. (delete-frame))
  5095. (and (not (eq org-agenda-window-setup 'current-window))
  5096. (not (one-window-p))
  5097. (delete-window))
  5098. (kill-buffer buf)
  5099. (org-agenda-reset-markers)
  5100. (org-columns-remove-overlays)
  5101. (setq org-agenda-archives-mode nil)))
  5102. ;; Maybe restore the pre-agenda window configuration.
  5103. (and org-agenda-restore-windows-after-quit
  5104. (not (eq org-agenda-window-setup 'other-frame))
  5105. org-pre-agenda-window-conf
  5106. (set-window-configuration org-pre-agenda-window-conf))))
  5107. (defun org-agenda-exit ()
  5108. "Exit agenda by removing the window or the buffer.
  5109. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5110. Org-mode buffers visited directly by the user will not be touched."
  5111. (interactive)
  5112. (org-release-buffers org-agenda-new-buffers)
  5113. (setq org-agenda-new-buffers nil)
  5114. (org-agenda-quit))
  5115. (defun org-agenda-execute (arg)
  5116. "Execute another agenda command, keeping same window.
  5117. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5118. in the agenda."
  5119. (interactive "P")
  5120. (let ((org-agenda-window-setup 'current-window))
  5121. (org-agenda arg)))
  5122. (defun org-agenda-redo ()
  5123. "Rebuild Agenda.
  5124. When this is the global TODO list, a prefix argument will be interpreted."
  5125. (interactive)
  5126. (let* ((org-agenda-keep-modes t)
  5127. (filter org-agenda-filter)
  5128. (preset (get 'org-agenda-filter :preset-filter))
  5129. (cols org-agenda-columns-active)
  5130. (line (org-current-line))
  5131. (window-line (- line (org-current-line (window-start))))
  5132. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5133. (put 'org-agenda-filter :preset-filter nil)
  5134. (and cols (org-columns-quit))
  5135. (message "Rebuilding agenda buffer...")
  5136. (org-let lprops '(eval org-agenda-redo-command))
  5137. (setq org-agenda-undo-list nil
  5138. org-agenda-pending-undo-list nil)
  5139. (message "Rebuilding agenda buffer...done")
  5140. (put 'org-agenda-filter :preset-filter preset)
  5141. (and (or filter preset) (org-agenda-filter-apply filter))
  5142. (and cols (interactive-p) (org-agenda-columns))
  5143. (org-goto-line line)
  5144. (recenter window-line)))
  5145. (defvar org-global-tags-completion-table nil)
  5146. (defvar org-agenda-filter-form nil)
  5147. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5148. "Keep only those lines in the agenda buffer that have a specific tag.
  5149. The tag is selected with its fast selection letter, as configured.
  5150. With prefix argument STRIP, remove all lines that do have the tag.
  5151. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5152. used to narrow the search - the interactive user can also press `-' or `+'
  5153. to switch to narrowing."
  5154. (interactive "P")
  5155. (let* ((alist org-tag-alist-for-agenda)
  5156. (tag-chars (mapconcat
  5157. (lambda (x) (if (and (not (symbolp (car x)))
  5158. (cdr x))
  5159. (char-to-string (cdr x))
  5160. ""))
  5161. alist ""))
  5162. (efforts (org-split-string
  5163. (or (cdr (assoc (concat org-effort-property "_ALL")
  5164. org-global-properties))
  5165. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5166. (effort-op org-agenda-filter-effort-default-operator)
  5167. (effort-prompt "")
  5168. (inhibit-read-only t)
  5169. (current org-agenda-filter)
  5170. a n tag)
  5171. (unless char
  5172. (message
  5173. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5174. (if narrow "Narrow" "Filter") tag-chars
  5175. (if org-agenda-auto-exclude-function "[RET], " ""))
  5176. (setq char (read-char)))
  5177. (when (member char '(?+ ?-))
  5178. ;; Narrowing down
  5179. (cond ((equal char ?-) (setq strip t narrow t))
  5180. ((equal char ?+) (setq strip nil narrow t)))
  5181. (message
  5182. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5183. (setq char (read-char)))
  5184. (when (member char '(?< ?> ?= ??))
  5185. ;; An effort operator
  5186. (setq effort-op (char-to-string char))
  5187. (setq alist nil) ; to make sure it will be interpreted as effort.
  5188. (unless (equal char ??)
  5189. (loop for i from 0 to 9 do
  5190. (setq effort-prompt
  5191. (concat
  5192. effort-prompt " ["
  5193. (if (= i 9) "0" (int-to-string (1+ i)))
  5194. "]" (nth i efforts))))
  5195. (message "Effort%s: %s " effort-op effort-prompt)
  5196. (setq char (read-char))
  5197. (when (or (< char ?0) (> char ?9))
  5198. (error "Need 1-9,0 to select effort" ))))
  5199. (when (equal char ?\t)
  5200. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5201. (org-set-local 'org-global-tags-completion-table
  5202. (org-global-tags-completion-table)))
  5203. (let ((completion-ignore-case t))
  5204. (setq tag (org-icompleting-read
  5205. "Tag: " org-global-tags-completion-table))))
  5206. (cond
  5207. ((equal char ?\r)
  5208. (org-agenda-filter-by-tag-show-all)
  5209. (when org-agenda-auto-exclude-function
  5210. (setq org-agenda-filter '())
  5211. (dolist (tag (org-agenda-get-represented-tags))
  5212. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5213. (if modifier
  5214. (push modifier org-agenda-filter))))
  5215. (if (not (null org-agenda-filter))
  5216. (org-agenda-filter-apply org-agenda-filter))))
  5217. ((equal char ?/)
  5218. (org-agenda-filter-by-tag-show-all)
  5219. (when (get 'org-agenda-filter :preset-filter)
  5220. (org-agenda-filter-apply org-agenda-filter)))
  5221. ((or (equal char ?\ )
  5222. (setq a (rassoc char alist))
  5223. (and (>= char ?0) (<= char ?9)
  5224. (setq n (if (= char ?0) 9 (- char ?0 1))
  5225. tag (concat effort-op (nth n efforts))
  5226. a (cons tag nil)))
  5227. (and (= char ??)
  5228. (setq tag "?eff")
  5229. a (cons tag nil))
  5230. (and tag (setq a (cons tag nil))))
  5231. (org-agenda-filter-by-tag-show-all)
  5232. (setq tag (car a))
  5233. (setq org-agenda-filter
  5234. (cons (concat (if strip "-" "+") tag)
  5235. (if narrow current nil)))
  5236. (org-agenda-filter-apply org-agenda-filter))
  5237. (t (error "Invalid tag selection character %c" char)))))
  5238. (defun org-agenda-get-represented-tags ()
  5239. "Get a list of all tags currently represented in the agenda."
  5240. (let (p tags)
  5241. (save-excursion
  5242. (goto-char (point-min))
  5243. (while (setq p (next-single-property-change (point) 'tags))
  5244. (goto-char p)
  5245. (mapc (lambda (x) (add-to-list 'tags x))
  5246. (get-text-property (point) 'tags))))
  5247. tags))
  5248. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5249. "Refine the current filter. See `org-agenda-filter-by-tag."
  5250. (interactive "P")
  5251. (org-agenda-filter-by-tag strip char 'refine))
  5252. (defun org-agenda-filter-make-matcher ()
  5253. "Create the form that tests a line for the agenda filter."
  5254. (let (f f1)
  5255. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5256. org-agenda-filter))
  5257. (if (member x '("-" "+"))
  5258. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5259. (if (string-match "[<=>?]" x)
  5260. (setq f1 (org-agenda-filter-effort-form x))
  5261. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5262. (if (equal (string-to-char x) ?-)
  5263. (setq f1 (list 'not f1))))
  5264. (push f1 f))
  5265. (cons 'and (nreverse f))))
  5266. (defun org-agenda-filter-effort-form (e)
  5267. "Return the form to compare the effort of the current line with what E says.
  5268. E looks like \"+<2:25\"."
  5269. (let (op)
  5270. (setq e (substring e 1))
  5271. (setq op (string-to-char e) e (substring e 1))
  5272. (setq op (cond ((equal op ?<) '<=)
  5273. ((equal op ?>) '>=)
  5274. ((equal op ??) op)
  5275. (t '=)))
  5276. (list 'org-agenda-compare-effort (list 'quote op)
  5277. (org-hh:mm-string-to-minutes e))))
  5278. (defun org-agenda-compare-effort (op value)
  5279. "Compare the effort of the current line with VALUE, using OP.
  5280. If the line does not have an effort defined, return nil."
  5281. (let ((eff (org-get-at-bol 'effort-minutes)))
  5282. (if (equal op ??)
  5283. (not eff)
  5284. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5285. value))))
  5286. (defun org-agenda-filter-apply (filter)
  5287. "Set FILTER as the new agenda filter and apply it."
  5288. (let (tags)
  5289. (setq org-agenda-filter filter
  5290. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5291. (org-agenda-set-mode-name)
  5292. (save-excursion
  5293. (goto-char (point-min))
  5294. (while (not (eobp))
  5295. (if (org-get-at-bol 'org-marker)
  5296. (progn
  5297. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5298. (if (not (eval org-agenda-filter-form))
  5299. (org-agenda-filter-by-tag-hide-line))
  5300. (beginning-of-line 2))
  5301. (beginning-of-line 2))))))
  5302. (defun org-agenda-filter-by-tag-hide-line ()
  5303. (let (ov)
  5304. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5305. (point-at-eol)))
  5306. (overlay-put ov 'invisible t)
  5307. (overlay-put ov 'type 'tags-filter)
  5308. (push ov org-agenda-filter-overlays)))
  5309. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5310. (setq pos (or pos (point)))
  5311. (save-excursion
  5312. (dolist (ov (overlays-at pos))
  5313. (when (and (overlay-get ov 'invisible)
  5314. (eq (overlay-get ov 'type) 'tags-filter))
  5315. (goto-char pos)
  5316. (if (< (overlay-start ov) (point-at-eol))
  5317. (move-overlay ov (point-at-eol)
  5318. (overlay-end ov)))))))
  5319. (defun org-agenda-filter-by-tag-show-all ()
  5320. (mapc 'delete-overlay org-agenda-filter-overlays)
  5321. (setq org-agenda-filter-overlays nil)
  5322. (setq org-agenda-filter nil)
  5323. (setq org-agenda-filter-form nil)
  5324. (org-agenda-set-mode-name))
  5325. (defun org-agenda-manipulate-query-add ()
  5326. "Manipulate the query by adding a search term with positive selection.
  5327. Positive selection means the term must be matched for selection of an entry."
  5328. (interactive)
  5329. (org-agenda-manipulate-query ?\[))
  5330. (defun org-agenda-manipulate-query-subtract ()
  5331. "Manipulate the query by adding a search term with negative selection.
  5332. Negative selection means term must not be matched for selection of an entry."
  5333. (interactive)
  5334. (org-agenda-manipulate-query ?\]))
  5335. (defun org-agenda-manipulate-query-add-re ()
  5336. "Manipulate the query by adding a search regexp with positive selection.
  5337. Positive selection means the regexp must match for selection of an entry."
  5338. (interactive)
  5339. (org-agenda-manipulate-query ?\{))
  5340. (defun org-agenda-manipulate-query-subtract-re ()
  5341. "Manipulate the query by adding a search regexp with negative selection.
  5342. Negative selection means regexp must not match for selection of an entry."
  5343. (interactive)
  5344. (org-agenda-manipulate-query ?\}))
  5345. (defun org-agenda-manipulate-query (char)
  5346. (cond
  5347. ((memq org-agenda-type '(timeline agenda))
  5348. (let ((org-agenda-include-inactive-timestamps t))
  5349. (org-agenda-redo))
  5350. (message "Display now includes inactive timestamps as well"))
  5351. ((eq org-agenda-type 'search)
  5352. (org-add-to-string
  5353. 'org-agenda-query-string
  5354. (if org-agenda-last-search-view-search-was-boolean
  5355. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5356. (?\{ . " +{}") (?\} . " -{}"))))
  5357. " "))
  5358. (setq org-agenda-redo-command
  5359. (list 'org-search-view
  5360. org-todo-only
  5361. org-agenda-query-string
  5362. (+ (length org-agenda-query-string)
  5363. (if (member char '(?\{ ?\})) 0 1))))
  5364. (set-register org-agenda-query-register org-agenda-query-string)
  5365. (org-agenda-redo))
  5366. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5367. org-agenda-type))))
  5368. (defun org-add-to-string (var string)
  5369. (set var (concat (symbol-value var) string)))
  5370. (defun org-agenda-goto-date (date)
  5371. "Jump to DATE in agenda."
  5372. (interactive (list (org-read-date)))
  5373. (org-agenda-list nil date))
  5374. (defun org-agenda-goto-today ()
  5375. "Go to today."
  5376. (interactive)
  5377. (org-agenda-check-type t 'timeline 'agenda)
  5378. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5379. (cond
  5380. (tdpos (goto-char tdpos))
  5381. ((eq org-agenda-type 'agenda)
  5382. (let* ((sd (time-to-days
  5383. (time-subtract (current-time)
  5384. (list 0 (* 3600 org-extend-today-until) 0))))
  5385. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5386. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5387. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5388. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5389. (org-agenda-redo)
  5390. (org-agenda-find-same-or-today-or-agenda)))
  5391. (t (error "Cannot find today")))))
  5392. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5393. (goto-char
  5394. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5395. (text-property-any (point-min) (point-max) 'org-today t)
  5396. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5397. (point-min))))
  5398. (defun org-agenda-later (arg)
  5399. "Go forward in time by thee current span.
  5400. With prefix ARG, go forward that many times the current span."
  5401. (interactive "p")
  5402. (org-agenda-check-type t 'agenda)
  5403. (let* ((span org-agenda-span)
  5404. (sd org-starting-day)
  5405. (greg (calendar-gregorian-from-absolute sd))
  5406. (cnt (org-get-at-bol 'org-day-cnt))
  5407. greg2 nd)
  5408. (cond
  5409. ((eq span 'day)
  5410. (setq sd (+ arg sd) nd 1))
  5411. ((eq span 'week)
  5412. (setq sd (+ (* 7 arg) sd) nd 7))
  5413. ((eq span 'month)
  5414. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5415. sd (calendar-absolute-from-gregorian greg2))
  5416. (setcar greg2 (1+ (car greg2)))
  5417. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5418. ((eq span 'year)
  5419. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5420. sd (calendar-absolute-from-gregorian greg2))
  5421. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5422. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5423. (let ((org-agenda-overriding-arguments
  5424. (list (car org-agenda-last-arguments) sd nd t)))
  5425. (org-agenda-redo)
  5426. (org-agenda-find-same-or-today-or-agenda cnt))))
  5427. (defun org-agenda-earlier (arg)
  5428. "Go backward in time by the current span.
  5429. With prefix ARG, go backward that many times the current span."
  5430. (interactive "p")
  5431. (org-agenda-later (- arg)))
  5432. (defun org-agenda-view-mode-dispatch ()
  5433. "Call one of the view mode commands."
  5434. (interactive)
  5435. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5436. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5437. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5438. (let ((a (read-char-exclusive)))
  5439. (case a
  5440. (?d (call-interactively 'org-agenda-day-view))
  5441. (?w (call-interactively 'org-agenda-week-view))
  5442. (?m (call-interactively 'org-agenda-month-view))
  5443. (?y (call-interactively 'org-agenda-year-view))
  5444. (?l (call-interactively 'org-agenda-log-mode))
  5445. (?L (org-agenda-log-mode '(4)))
  5446. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5447. (?a (call-interactively 'org-agenda-archives-mode))
  5448. (?A (org-agenda-archives-mode 'files))
  5449. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5450. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5451. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5452. (?D (call-interactively 'org-agenda-toggle-diary))
  5453. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5454. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5455. (org-agenda-check-type t 'timeline 'agenda)
  5456. (org-agenda-redo))
  5457. (message "Display now includes inactive timestamps as well"))
  5458. (?q (message "Abort"))
  5459. (otherwise (error "Invalid key" )))))
  5460. (defun org-agenda-day-view (&optional day-of-year)
  5461. "Switch to daily view for agenda.
  5462. With argument DAY-OF-YEAR, switch to that day of the year."
  5463. (interactive "P")
  5464. (setq org-agenda-ndays 1)
  5465. (org-agenda-change-time-span 'day day-of-year))
  5466. (defun org-agenda-week-view (&optional iso-week)
  5467. "Switch to daily view for agenda.
  5468. With argument ISO-WEEK, switch to the corresponding ISO week.
  5469. If ISO-WEEK has more then 2 digits, only the last two encode the
  5470. week. Any digits before this encode a year. So 200712 means
  5471. week 12 of year 2007. Years in the range 1938-2037 can also be
  5472. written as 2-digit years."
  5473. (interactive "P")
  5474. (setq org-agenda-ndays 7)
  5475. (org-agenda-change-time-span 'week iso-week))
  5476. (defun org-agenda-month-view (&optional month)
  5477. "Switch to monthly view for agenda.
  5478. With argument MONTH, switch to that month."
  5479. (interactive "P")
  5480. (org-agenda-change-time-span 'month month))
  5481. (defun org-agenda-year-view (&optional year)
  5482. "Switch to yearly view for agenda.
  5483. With argument YEAR, switch to that year.
  5484. If MONTH has more then 2 digits, only the last two encode the
  5485. month. Any digits before this encode a year. So 200712 means
  5486. December year 2007. Years in the range 1938-2037 can also be
  5487. written as 2-digit years."
  5488. (interactive "P")
  5489. (when year
  5490. (setq year (org-small-year-to-year year)))
  5491. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5492. (org-agenda-change-time-span 'year year)
  5493. (error "Abort")))
  5494. (defun org-agenda-change-time-span (span &optional n)
  5495. "Change the agenda view to SPAN.
  5496. SPAN may be `day', `week', `month', `year'."
  5497. (org-agenda-check-type t 'agenda)
  5498. (if (and (not n) (equal org-agenda-span span))
  5499. (error "Viewing span is already \"%s\"" span))
  5500. (let* ((sd (or (org-get-at-bol 'day)
  5501. org-starting-day))
  5502. (computed (org-agenda-compute-time-span sd span n))
  5503. (org-agenda-overriding-arguments
  5504. (list (car org-agenda-last-arguments)
  5505. (car computed) (cdr computed) t)))
  5506. (org-agenda-redo)
  5507. (org-agenda-find-same-or-today-or-agenda))
  5508. (org-agenda-set-mode-name)
  5509. (message "Switched to %s view" span))
  5510. (defun org-agenda-compute-time-span (sd span &optional n)
  5511. "Compute starting date and number of days for agenda.
  5512. SPAN may be `day', `week', `month', `year'. The return value
  5513. is a cons cell with the starting date and the number of days,
  5514. so that the date SD will be in that range."
  5515. (let* ((greg (calendar-gregorian-from-absolute sd))
  5516. (dg (nth 1 greg))
  5517. (mg (car greg))
  5518. (yg (nth 2 greg))
  5519. nd w1 y1 m1 thisweek)
  5520. (cond
  5521. ((eq span 'day)
  5522. (when n
  5523. (setq sd (+ (calendar-absolute-from-gregorian
  5524. (list mg 1 yg))
  5525. n -1)))
  5526. (setq nd 1))
  5527. ((eq span 'week)
  5528. (let* ((nt (calendar-day-of-week
  5529. (calendar-gregorian-from-absolute sd)))
  5530. (d (if org-agenda-start-on-weekday
  5531. (- nt org-agenda-start-on-weekday)
  5532. 0)))
  5533. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5534. (when n
  5535. (require 'cal-iso)
  5536. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5537. (when (> n 99)
  5538. (setq y1 (org-small-year-to-year (/ n 100))
  5539. n (mod n 100)))
  5540. (setq sd
  5541. (calendar-absolute-from-iso
  5542. (list n 1
  5543. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5544. (setq nd 7)))
  5545. ((eq span 'month)
  5546. (when (and n (> n 99))
  5547. (setq y1 (org-small-year-to-year (/ n 100))
  5548. n (mod n 100)))
  5549. (setq sd (calendar-absolute-from-gregorian
  5550. (list (or n mg) 1 (or y1 yg)))
  5551. nd (- (calendar-absolute-from-gregorian
  5552. (list (1+ (or n mg)) 1 (or y1 yg)))
  5553. sd)))
  5554. ((eq span 'year)
  5555. (setq sd (calendar-absolute-from-gregorian
  5556. (list 1 1 (or n yg)))
  5557. nd (- (calendar-absolute-from-gregorian
  5558. (list 1 1 (1+ (or n yg))))
  5559. sd))))
  5560. (cons sd nd)))
  5561. (defun org-agenda-next-date-line (&optional arg)
  5562. "Jump to the next line indicating a date in agenda buffer."
  5563. (interactive "p")
  5564. (org-agenda-check-type t 'agenda 'timeline)
  5565. (beginning-of-line 1)
  5566. ;; This does not work if user makes date format that starts with a blank
  5567. (if (looking-at "^\\S-") (forward-char 1))
  5568. (if (not (re-search-forward "^\\S-" nil t arg))
  5569. (progn
  5570. (backward-char 1)
  5571. (error "No next date after this line in this buffer")))
  5572. (goto-char (match-beginning 0)))
  5573. (defun org-agenda-previous-date-line (&optional arg)
  5574. "Jump to the previous line indicating a date in agenda buffer."
  5575. (interactive "p")
  5576. (org-agenda-check-type t 'agenda 'timeline)
  5577. (beginning-of-line 1)
  5578. (if (not (re-search-backward "^\\S-" nil t arg))
  5579. (error "No previous date before this line in this buffer")))
  5580. ;; Initialize the highlight
  5581. (defvar org-hl (make-overlay 1 1))
  5582. (overlay-put org-hl 'face 'highlight)
  5583. (defun org-highlight (begin end &optional buffer)
  5584. "Highlight a region with overlay."
  5585. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5586. (defun org-unhighlight ()
  5587. "Detach overlay INDEX."
  5588. (org-detach-overlay org-hl))
  5589. ;; FIXME this is currently not used.
  5590. (defun org-highlight-until-next-command (beg end &optional buffer)
  5591. "Move the highlight overlay to BEG/END, remove it before the next command."
  5592. (org-highlight beg end buffer)
  5593. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5594. (defun org-unhighlight-once ()
  5595. "Remove the highlight from its position, and this function from the hook."
  5596. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5597. (org-unhighlight))
  5598. (defun org-agenda-follow-mode ()
  5599. "Toggle follow mode in an agenda buffer."
  5600. (interactive)
  5601. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5602. (org-agenda-set-mode-name)
  5603. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5604. (org-agenda-show))
  5605. (message "Follow mode is %s"
  5606. (if org-agenda-follow-mode "on" "off")))
  5607. (defun org-agenda-entry-text-mode (&optional arg)
  5608. "Toggle entry text mode in an agenda buffer."
  5609. (interactive "P")
  5610. (setq org-agenda-entry-text-mode (or (integerp arg)
  5611. (not org-agenda-entry-text-mode)))
  5612. (org-agenda-entry-text-hide)
  5613. (and org-agenda-entry-text-mode
  5614. (let ((org-agenda-entry-text-maxlines
  5615. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5616. (org-agenda-entry-text-show)))
  5617. (org-agenda-set-mode-name)
  5618. (message "Entry text mode is %s. Maximum number of lines is %d"
  5619. (if org-agenda-entry-text-mode "on" "off")
  5620. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5621. (defun org-agenda-clockreport-mode ()
  5622. "Toggle clocktable mode in an agenda buffer."
  5623. (interactive)
  5624. (org-agenda-check-type t 'agenda)
  5625. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5626. (org-agenda-set-mode-name)
  5627. (org-agenda-redo)
  5628. (message "Clocktable mode is %s"
  5629. (if org-agenda-clockreport-mode "on" "off")))
  5630. (defun org-agenda-log-mode (&optional special)
  5631. "Toggle log mode in an agenda buffer.
  5632. With argument SPECIAL, show all possible log items, not only the ones
  5633. configured in `org-agenda-log-mode-items'.
  5634. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5635. (interactive "P")
  5636. (org-agenda-check-type t 'agenda 'timeline)
  5637. (setq org-agenda-show-log
  5638. (if (equal special '(16))
  5639. 'only
  5640. (if special '(closed clock state)
  5641. (not org-agenda-show-log))))
  5642. (org-agenda-set-mode-name)
  5643. (org-agenda-redo)
  5644. (message "Log mode is %s"
  5645. (if org-agenda-show-log "on" "off")))
  5646. (defun org-agenda-archives-mode (&optional with-files)
  5647. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5648. When called with a prefix argument, include all archive files as well."
  5649. (interactive "P")
  5650. (setq org-agenda-archives-mode
  5651. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5652. (org-agenda-set-mode-name)
  5653. (org-agenda-redo)
  5654. (message
  5655. "%s"
  5656. (cond
  5657. ((eq org-agenda-archives-mode nil)
  5658. "No archives are included")
  5659. ((eq org-agenda-archives-mode 'trees)
  5660. (format "Trees with :%s: tag are included" org-archive-tag))
  5661. ((eq org-agenda-archives-mode t)
  5662. (format "Trees with :%s: tag and all active archive files are included"
  5663. org-archive-tag)))))
  5664. (defun org-agenda-toggle-diary ()
  5665. "Toggle diary inclusion in an agenda buffer."
  5666. (interactive)
  5667. (org-agenda-check-type t 'agenda)
  5668. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5669. (org-agenda-redo)
  5670. (org-agenda-set-mode-name)
  5671. (message "Diary inclusion turned %s"
  5672. (if org-agenda-include-diary "on" "off")))
  5673. (defun org-agenda-toggle-deadlines ()
  5674. "Toggle diary inclusion in an agenda buffer."
  5675. (interactive)
  5676. (org-agenda-check-type t 'agenda)
  5677. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5678. (org-agenda-redo)
  5679. (org-agenda-set-mode-name)
  5680. (message "Deadlines inclusion turned %s"
  5681. (if org-agenda-include-deadlines "on" "off")))
  5682. (defun org-agenda-toggle-time-grid ()
  5683. "Toggle time grid in an agenda buffer."
  5684. (interactive)
  5685. (org-agenda-check-type t 'agenda)
  5686. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5687. (org-agenda-redo)
  5688. (org-agenda-set-mode-name)
  5689. (message "Time-grid turned %s"
  5690. (if org-agenda-use-time-grid "on" "off")))
  5691. (defun org-agenda-set-mode-name ()
  5692. "Set the mode name to indicate all the small mode settings."
  5693. (setq mode-name
  5694. (concat "Org-Agenda"
  5695. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5696. (if (equal org-agenda-ndays 1) " Day" "")
  5697. (if (equal org-agenda-ndays 7) " Week" "")
  5698. (if org-agenda-follow-mode " Follow" "")
  5699. (if org-agenda-entry-text-mode " ETxt" "")
  5700. (if org-agenda-include-diary " Diary" "")
  5701. (if org-agenda-include-deadlines " Ddl" "")
  5702. (if org-agenda-use-time-grid " Grid" "")
  5703. (if (and (boundp 'org-habit-show-habits)
  5704. org-habit-show-habits) " Habit" "")
  5705. (if (consp org-agenda-show-log) " LogAll"
  5706. (if org-agenda-show-log " Log" ""))
  5707. (if (or org-agenda-filter (get 'org-agenda-filter
  5708. :preset-filter))
  5709. (concat " {" (mapconcat
  5710. 'identity
  5711. (append (get 'org-agenda-filter
  5712. :preset-filter)
  5713. org-agenda-filter) "") "}")
  5714. "")
  5715. (if org-agenda-archives-mode
  5716. (if (eq org-agenda-archives-mode t)
  5717. " Archives"
  5718. (format " :%s:" org-archive-tag))
  5719. "")
  5720. (if org-agenda-clockreport-mode " Clock" "")))
  5721. (force-mode-line-update))
  5722. (defun org-agenda-post-command-hook ()
  5723. (setq org-agenda-type
  5724. (or (get-text-property (point) 'org-agenda-type)
  5725. (get-text-property (max (point-min) (1- (point)))
  5726. 'org-agenda-type))))
  5727. (defun org-agenda-next-line ()
  5728. "Move cursor to the next line, and show if follow mode is active."
  5729. (interactive)
  5730. (call-interactively 'next-line)
  5731. (org-agenda-do-context-action))
  5732. (defun org-agenda-previous-line ()
  5733. "Move cursor to the previous line, and show if follow-mode is active."
  5734. (interactive)
  5735. (call-interactively 'previous-line)
  5736. (org-agenda-do-context-action))
  5737. (defun org-agenda-do-context-action ()
  5738. "Show outline path and, maybe, follow mode window."
  5739. (let ((m (org-get-at-bol 'org-marker)))
  5740. (if (and org-agenda-follow-mode m)
  5741. (org-agenda-show))
  5742. (if (and m org-agenda-show-outline-path)
  5743. (org-with-point-at m
  5744. (org-display-outline-path t)))))
  5745. (defun org-agenda-show-priority ()
  5746. "Show the priority of the current item.
  5747. This priority is composed of the main priority given with the [#A] cookies,
  5748. and by additional input from the age of a schedules or deadline entry."
  5749. (interactive)
  5750. (let* ((pri (org-get-at-bol 'priority)))
  5751. (message "Priority is %d" (if pri pri -1000))))
  5752. (defun org-agenda-show-tags ()
  5753. "Show the tags applicable to the current item."
  5754. (interactive)
  5755. (let* ((tags (org-get-at-bol 'tags)))
  5756. (if tags
  5757. (message "Tags are :%s:"
  5758. (org-no-properties (mapconcat 'identity tags ":")))
  5759. (message "No tags associated with this line"))))
  5760. (defun org-agenda-goto (&optional highlight)
  5761. "Go to the Org-mode file which contains the item at point."
  5762. (interactive)
  5763. (let* ((marker (or (org-get-at-bol 'org-marker)
  5764. (org-agenda-error)))
  5765. (buffer (marker-buffer marker))
  5766. (pos (marker-position marker)))
  5767. (switch-to-buffer-other-window buffer)
  5768. (widen)
  5769. (push-mark)
  5770. (goto-char pos)
  5771. (when (org-mode-p)
  5772. (org-show-context 'agenda)
  5773. (save-excursion
  5774. (and (outline-next-heading)
  5775. (org-flag-heading nil)))) ; show the next heading
  5776. (recenter (/ (window-height) 2))
  5777. (run-hooks 'org-agenda-after-show-hook)
  5778. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5779. (defvar org-agenda-after-show-hook nil
  5780. "Normal hook run after an item has been shown from the agenda.
  5781. Point is in the buffer where the item originated.")
  5782. (defun org-agenda-kill ()
  5783. "Kill the entry or subtree belonging to the current agenda entry."
  5784. (interactive)
  5785. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5786. (let* ((marker (or (org-get-at-bol 'org-marker)
  5787. (org-agenda-error)))
  5788. (buffer (marker-buffer marker))
  5789. (pos (marker-position marker))
  5790. (type (org-get-at-bol 'type))
  5791. dbeg dend (n 0) conf)
  5792. (org-with-remote-undo buffer
  5793. (with-current-buffer buffer
  5794. (save-excursion
  5795. (goto-char pos)
  5796. (if (and (org-mode-p) (not (member type '("sexp"))))
  5797. (setq dbeg (progn (org-back-to-heading t) (point))
  5798. dend (org-end-of-subtree t t))
  5799. (setq dbeg (point-at-bol)
  5800. dend (min (point-max) (1+ (point-at-eol)))))
  5801. (goto-char dbeg)
  5802. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5803. (setq conf (or (eq t org-agenda-confirm-kill)
  5804. (and (numberp org-agenda-confirm-kill)
  5805. (> n org-agenda-confirm-kill))))
  5806. (and conf
  5807. (not (y-or-n-p
  5808. (format "Delete entry with %d lines in buffer \"%s\"? "
  5809. n (buffer-name buffer))))
  5810. (error "Abort"))
  5811. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5812. (with-current-buffer buffer (delete-region dbeg dend))
  5813. (message "Agenda item and source killed"))))
  5814. (defvar org-archive-default-command)
  5815. (defun org-agenda-archive-default ()
  5816. "Archive the entry or subtree belonging to the current agenda entry."
  5817. (interactive)
  5818. (require 'org-archive)
  5819. (org-agenda-archive-with org-archive-default-command))
  5820. (defun org-agenda-archive-default-with-confirmation ()
  5821. "Archive the entry or subtree belonging to the current agenda entry."
  5822. (interactive)
  5823. (require 'org-archive)
  5824. (org-agenda-archive-with org-archive-default-command 'confirm))
  5825. (defun org-agenda-archive ()
  5826. "Archive the entry or subtree belonging to the current agenda entry."
  5827. (interactive)
  5828. (org-agenda-archive-with 'org-archive-subtree))
  5829. (defun org-agenda-archive-to-archive-sibling ()
  5830. "Move the entry to the archive sibling."
  5831. (interactive)
  5832. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5833. (defun org-agenda-archive-with (cmd &optional confirm)
  5834. "Move the entry to the archive sibling."
  5835. (interactive)
  5836. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5837. (let* ((marker (or (org-get-at-bol 'org-marker)
  5838. (org-agenda-error)))
  5839. (buffer (marker-buffer marker))
  5840. (pos (marker-position marker)))
  5841. (org-with-remote-undo buffer
  5842. (with-current-buffer buffer
  5843. (if (org-mode-p)
  5844. (if (and confirm
  5845. (not (y-or-n-p "Archive this subtree or entry? ")))
  5846. (error "Abort")
  5847. (save-excursion
  5848. (goto-char pos)
  5849. (org-remove-subtree-entries-from-agenda)
  5850. (org-back-to-heading t)
  5851. (funcall cmd)))
  5852. (error "Archiving works only in Org-mode files"))))))
  5853. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5854. "Remove all lines in the agenda that correspond to a given subtree.
  5855. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5856. If this information is not given, the function uses the tree at point."
  5857. (let ((buf (or buf (current-buffer))) m p)
  5858. (save-excursion
  5859. (unless (and beg end)
  5860. (org-back-to-heading t)
  5861. (setq beg (point))
  5862. (org-end-of-subtree t)
  5863. (setq end (point)))
  5864. (set-buffer (get-buffer org-agenda-buffer-name))
  5865. (save-excursion
  5866. (goto-char (point-max))
  5867. (beginning-of-line 1)
  5868. (while (not (bobp))
  5869. (when (and (setq m (org-get-at-bol 'org-marker))
  5870. (equal buf (marker-buffer m))
  5871. (setq p (marker-position m))
  5872. (>= p beg)
  5873. (< p end))
  5874. (let ((inhibit-read-only t))
  5875. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5876. (beginning-of-line 0))))))
  5877. (defun org-agenda-refile (&optional goto rfloc no-update)
  5878. "Refile the item at point."
  5879. (interactive "P")
  5880. (if (equal goto '(16))
  5881. (org-refile-goto-last-stored)
  5882. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5883. (org-agenda-error)))
  5884. (buffer (marker-buffer marker))
  5885. (pos (marker-position marker))
  5886. (rfloc (or rfloc
  5887. (org-refile-get-location
  5888. (if goto "Goto: " "Refile to: ") buffer
  5889. org-refile-allow-creating-parent-nodes))))
  5890. (with-current-buffer buffer
  5891. (save-excursion
  5892. (save-restriction
  5893. (widen)
  5894. (goto-char marker)
  5895. (org-remove-subtree-entries-from-agenda)
  5896. (org-refile goto buffer rfloc)))))
  5897. (unless no-update (org-agenda-redo))))
  5898. (defun org-agenda-open-link (&optional arg)
  5899. "Follow the link in the current line, if any.
  5900. This looks for a link in the displayed line in the agenda. It also looks
  5901. at the text of the entry itself."
  5902. (interactive "P")
  5903. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5904. (org-get-at-bol 'org-marker)))
  5905. (buffer (and marker (marker-buffer marker)))
  5906. (prefix (buffer-substring
  5907. (point-at-bol)
  5908. (+ (point-at-bol)
  5909. (or (org-get-at-bol 'prefix-length) 0)))))
  5910. (cond
  5911. (buffer
  5912. (with-current-buffer buffer
  5913. (save-excursion
  5914. (save-restriction
  5915. (widen)
  5916. (goto-char marker)
  5917. (org-offer-links-in-entry arg prefix)))))
  5918. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5919. (save-excursion
  5920. (beginning-of-line 1)
  5921. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5922. (org-open-link-from-string (match-string 1)))
  5923. (t (error "No link to open here")))))
  5924. (defun org-agenda-copy-local-variable (var)
  5925. "Get a variable from a referenced buffer and install it here."
  5926. (let ((m (org-get-at-bol 'org-marker)))
  5927. (when (and m (buffer-live-p (marker-buffer m)))
  5928. (org-set-local var (with-current-buffer (marker-buffer m)
  5929. (symbol-value var))))))
  5930. (defun org-agenda-switch-to (&optional delete-other-windows)
  5931. "Go to the Org-mode file which contains the item at point."
  5932. (interactive)
  5933. (if (and org-return-follows-link
  5934. (not (org-get-at-bol 'org-marker))
  5935. (org-in-regexp org-bracket-link-regexp))
  5936. (org-open-link-from-string (match-string 0))
  5937. (let* ((marker (or (org-get-at-bol 'org-marker)
  5938. (org-agenda-error)))
  5939. (buffer (marker-buffer marker))
  5940. (pos (marker-position marker)))
  5941. (switch-to-buffer buffer)
  5942. (and delete-other-windows (delete-other-windows))
  5943. (widen)
  5944. (goto-char pos)
  5945. (when (org-mode-p)
  5946. (org-show-context 'agenda)
  5947. (save-excursion
  5948. (and (outline-next-heading)
  5949. (org-flag-heading nil))))))) ; show the next heading
  5950. (defun org-agenda-goto-mouse (ev)
  5951. "Go to the Org-mode file which contains the item at the mouse click."
  5952. (interactive "e")
  5953. (mouse-set-point ev)
  5954. (org-agenda-goto))
  5955. (defun org-agenda-show (&optional full-entry)
  5956. "Display the Org-mode file which contains the item at point.
  5957. With prefix argument FULL-ENTRY, make the entire entry visible
  5958. if it was hidden in the outline."
  5959. (interactive "P")
  5960. (let ((win (selected-window)))
  5961. (if full-entry
  5962. (let ((org-show-entry-below t))
  5963. (org-agenda-goto t))
  5964. (org-agenda-goto t))
  5965. (select-window win)))
  5966. (defvar org-agenda-show-window nil)
  5967. (defun org-agenda-show-and-scroll-up ()
  5968. "Display the Org-mode file which contains the item at point.
  5969. When called repeatedly, scroll the window that is displaying the buffer."
  5970. (interactive)
  5971. (let ((win (selected-window)))
  5972. (if (and (window-live-p org-agenda-show-window)
  5973. (eq this-command last-command))
  5974. (progn
  5975. (select-window org-agenda-show-window)
  5976. (ignore-errors (scroll-up)))
  5977. (org-agenda-goto t)
  5978. (show-subtree)
  5979. (setq org-agenda-show-window (selected-window)))
  5980. (select-window win)))
  5981. (defun org-agenda-show-scroll-down ()
  5982. "Scroll down the window showing the agenda."
  5983. (interactive)
  5984. (let ((win (selected-window)))
  5985. (when (window-live-p org-agenda-show-window)
  5986. (select-window org-agenda-show-window)
  5987. (ignore-errors (scroll-down))
  5988. (select-window win))))
  5989. (defun org-agenda-show-1 (&optional more)
  5990. "Display the Org-mode file which contains the item at point.
  5991. The prefix arg selects the amount of information to display:
  5992. 0 hide the subtree
  5993. 1 just show the entry according to defaults.
  5994. 2 show the children view
  5995. 3 show the subtree view
  5996. 4 show the entire subtree and any LOGBOOK drawers
  5997. 5 show the entire subtree and any drawers
  5998. With prefix argument FULL-ENTRY, make the entire entry visible
  5999. if it was hidden in the outline."
  6000. (interactive "p")
  6001. (let ((win (selected-window)))
  6002. (org-agenda-goto t)
  6003. (org-recenter-heading 1)
  6004. (cond
  6005. ((= more 0)
  6006. (hide-subtree)
  6007. (save-excursion
  6008. (org-back-to-heading)
  6009. (run-hook-with-args 'org-cycle-hook 'folded))
  6010. (message "Remote: FOLDED"))
  6011. ((and (interactive-p) (= more 1))
  6012. (message "Remote: show with default settings"))
  6013. ((= more 2)
  6014. (show-entry)
  6015. (show-children)
  6016. (save-excursion
  6017. (org-back-to-heading)
  6018. (run-hook-with-args 'org-cycle-hook 'children))
  6019. (message "Remote: CHILDREN"))
  6020. ((= more 3)
  6021. (show-subtree)
  6022. (save-excursion
  6023. (org-back-to-heading)
  6024. (run-hook-with-args 'org-cycle-hook 'subtree))
  6025. (message "Remote: SUBTREE"))
  6026. ((= more 4)
  6027. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6028. (org-drawer-regexp
  6029. (concat "^[ \t]*:\\("
  6030. (mapconcat 'regexp-quote org-drawers "\\|")
  6031. "\\):[ \t]*$")))
  6032. (show-subtree)
  6033. (save-excursion
  6034. (org-back-to-heading)
  6035. (org-cycle-hide-drawers 'subtree)))
  6036. (message "Remote: SUBTREE AND LOGBOOK"))
  6037. ((> more 4)
  6038. (show-subtree)
  6039. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6040. (select-window win)))
  6041. (defun org-recenter-heading (n)
  6042. (save-excursion
  6043. (org-back-to-heading)
  6044. (recenter n)))
  6045. (defvar org-agenda-cycle-counter nil)
  6046. (defun org-agenda-cycle-show (&optional n)
  6047. "Show the current entry in another window, with default settings.
  6048. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6049. When use repeatedly in immediate succession, the remote entry will cycle
  6050. through visibility
  6051. children -> subtree -> folded
  6052. When called with a numeric prefix arg, that arg will be passed through to
  6053. `org-agenda-show-1'. For the interpretation of that argument, see the
  6054. docstring of `org-agenda-show-1'."
  6055. (interactive "P")
  6056. (if (integerp n)
  6057. (setq org-agenda-cycle-counter n)
  6058. (if (not (eq last-command this-command))
  6059. (setq org-agenda-cycle-counter 1)
  6060. (if (equal org-agenda-cycle-counter 0)
  6061. (setq org-agenda-cycle-counter 2)
  6062. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6063. (if (> org-agenda-cycle-counter 3)
  6064. (setq org-agenda-cycle-counter 0)))))
  6065. (org-agenda-show-1 org-agenda-cycle-counter))
  6066. (defun org-agenda-recenter (arg)
  6067. "Display the Org-mode file which contains the item at point and recenter."
  6068. (interactive "P")
  6069. (let ((win (selected-window)))
  6070. (org-agenda-goto t)
  6071. (recenter arg)
  6072. (select-window win)))
  6073. (defun org-agenda-show-mouse (ev)
  6074. "Display the Org-mode file which contains the item at the mouse click."
  6075. (interactive "e")
  6076. (mouse-set-point ev)
  6077. (org-agenda-show))
  6078. (defun org-agenda-check-no-diary ()
  6079. "Check if the entry is a diary link and abort if yes."
  6080. (if (org-get-at-bol 'org-agenda-diary-link)
  6081. (org-agenda-error)))
  6082. (defun org-agenda-error ()
  6083. (error "Command not allowed in this line"))
  6084. (defun org-agenda-tree-to-indirect-buffer ()
  6085. "Show the subtree corresponding to the current entry in an indirect buffer.
  6086. This calls the command `org-tree-to-indirect-buffer' from the original
  6087. Org-mode buffer.
  6088. With numerical prefix arg ARG, go up to this level and then take that tree.
  6089. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6090. use the dedicated frame)."
  6091. (interactive)
  6092. (org-agenda-check-no-diary)
  6093. (let* ((marker (or (org-get-at-bol 'org-marker)
  6094. (org-agenda-error)))
  6095. (buffer (marker-buffer marker))
  6096. (pos (marker-position marker)))
  6097. (with-current-buffer buffer
  6098. (save-excursion
  6099. (goto-char pos)
  6100. (call-interactively 'org-tree-to-indirect-buffer)))))
  6101. (defvar org-last-heading-marker (make-marker)
  6102. "Marker pointing to the headline that last changed its TODO state
  6103. by a remote command from the agenda.")
  6104. (defun org-agenda-todo-nextset ()
  6105. "Switch TODO entry to next sequence."
  6106. (interactive)
  6107. (org-agenda-todo 'nextset))
  6108. (defun org-agenda-todo-previousset ()
  6109. "Switch TODO entry to previous sequence."
  6110. (interactive)
  6111. (org-agenda-todo 'previousset))
  6112. (defun org-agenda-todo (&optional arg)
  6113. "Cycle TODO state of line at point, also in Org-mode file.
  6114. This changes the line at point, all other lines in the agenda referring to
  6115. the same tree node, and the headline of the tree node in the Org-mode file."
  6116. (interactive "P")
  6117. (org-agenda-check-no-diary)
  6118. (let* ((col (current-column))
  6119. (marker (or (org-get-at-bol 'org-marker)
  6120. (org-agenda-error)))
  6121. (buffer (marker-buffer marker))
  6122. (pos (marker-position marker))
  6123. (hdmarker (org-get-at-bol 'org-hd-marker))
  6124. (todayp (equal (org-get-at-bol 'day)
  6125. (time-to-days (current-time))))
  6126. (inhibit-read-only t)
  6127. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6128. (org-with-remote-undo buffer
  6129. (with-current-buffer buffer
  6130. (widen)
  6131. (goto-char pos)
  6132. (org-show-context 'agenda)
  6133. (save-excursion
  6134. (and (outline-next-heading)
  6135. (org-flag-heading nil))) ; show the next heading
  6136. (let ((current-prefix-arg arg))
  6137. (call-interactively 'org-todo))
  6138. (and (bolp) (forward-char 1))
  6139. (setq newhead (org-get-heading))
  6140. (when (and (org-bound-and-true-p
  6141. org-agenda-headline-snapshot-before-repeat)
  6142. (not (equal org-agenda-headline-snapshot-before-repeat
  6143. newhead))
  6144. todayp)
  6145. (setq newhead org-agenda-headline-snapshot-before-repeat
  6146. just-one t))
  6147. (save-excursion
  6148. (org-back-to-heading)
  6149. (move-marker org-last-heading-marker (point))))
  6150. (beginning-of-line 1)
  6151. (save-excursion
  6152. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6153. (org-move-to-column col))))
  6154. (defun org-agenda-add-note (&optional arg)
  6155. "Add a time-stamped note to the entry at point."
  6156. (interactive "P")
  6157. (org-agenda-check-no-diary)
  6158. (let* ((marker (or (org-get-at-bol 'org-marker)
  6159. (org-agenda-error)))
  6160. (buffer (marker-buffer marker))
  6161. (pos (marker-position marker))
  6162. (hdmarker (org-get-at-bol 'org-hd-marker))
  6163. (inhibit-read-only t))
  6164. (with-current-buffer buffer
  6165. (widen)
  6166. (goto-char pos)
  6167. (org-show-context 'agenda)
  6168. (save-excursion
  6169. (and (outline-next-heading)
  6170. (org-flag-heading nil))) ; show the next heading
  6171. (org-add-note))))
  6172. (defun org-agenda-change-all-lines (newhead hdmarker
  6173. &optional fixface just-this)
  6174. "Change all lines in the agenda buffer which match HDMARKER.
  6175. The new content of the line will be NEWHEAD (as modified by
  6176. `org-format-agenda-item'). HDMARKER is checked with
  6177. `equal' against all `org-hd-marker' text properties in the file.
  6178. If FIXFACE is non-nil, the face of each item is modified according to
  6179. the new TODO state.
  6180. If JUST-THIS is non-nil, change just the current line, not all.
  6181. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6182. (let* ((inhibit-read-only t)
  6183. (line (org-current-line))
  6184. (thetags (with-current-buffer (marker-buffer hdmarker)
  6185. (save-excursion (save-restriction (widen)
  6186. (goto-char hdmarker)
  6187. (org-get-tags-at)))))
  6188. props m pl undone-face done-face finish new dotime cat tags)
  6189. (save-excursion
  6190. (goto-char (point-max))
  6191. (beginning-of-line 1)
  6192. (while (not finish)
  6193. (setq finish (bobp))
  6194. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6195. (or (not just-this) (= (org-current-line) line))
  6196. (equal m hdmarker))
  6197. (setq props (text-properties-at (point))
  6198. dotime (org-get-at-bol 'dotime)
  6199. cat (org-get-at-bol 'org-category)
  6200. tags thetags
  6201. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6202. pl (org-get-at-bol 'prefix-length)
  6203. undone-face (org-get-at-bol 'undone-face)
  6204. done-face (org-get-at-bol 'done-face))
  6205. (goto-char (+ (point) pl))
  6206. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6207. (cond
  6208. ((equal new "")
  6209. (beginning-of-line 1)
  6210. (and (looking-at ".*\n?") (replace-match "")))
  6211. ((looking-at ".*")
  6212. (replace-match new t t)
  6213. (beginning-of-line 1)
  6214. (add-text-properties (point-at-bol) (point-at-eol) props)
  6215. (when fixface
  6216. (add-text-properties
  6217. (point-at-bol) (point-at-eol)
  6218. (list 'face
  6219. (if org-last-todo-state-is-todo
  6220. undone-face done-face))))
  6221. (org-agenda-highlight-todo 'line)
  6222. (beginning-of-line 1))
  6223. (t (error "Line update did not work"))))
  6224. (beginning-of-line 0)))
  6225. (org-finalize-agenda)))
  6226. (defun org-agenda-align-tags (&optional line)
  6227. "Align all tags in agenda items to `org-agenda-tags-column'."
  6228. (let ((inhibit-read-only t) l c)
  6229. (save-excursion
  6230. (goto-char (if line (point-at-bol) (point-min)))
  6231. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  6232. (if line (point-at-eol) nil) t)
  6233. (add-text-properties
  6234. (match-beginning 2) (match-end 2)
  6235. (list 'face (delq nil (let ((prop (get-text-property
  6236. (match-beginning 2) 'face)))
  6237. (or (listp prop) (setq prop (list prop)))
  6238. (if (memq 'org-tag prop)
  6239. prop
  6240. (cons 'org-tag prop))))))
  6241. (setq l (- (match-end 2) (match-beginning 2))
  6242. c (if (< org-agenda-tags-column 0)
  6243. (- (abs org-agenda-tags-column) l)
  6244. org-agenda-tags-column))
  6245. (delete-region (match-beginning 1) (match-end 1))
  6246. (goto-char (match-beginning 1))
  6247. (insert (org-add-props
  6248. (make-string (max 1 (- c (current-column))) ?\ )
  6249. (plist-put (copy-sequence (text-properties-at (point)))
  6250. 'face nil))))
  6251. (goto-char (point-min))
  6252. (org-font-lock-add-tag-faces (point-max)))))
  6253. (defun org-agenda-priority-up ()
  6254. "Increase the priority of line at point, also in Org-mode file."
  6255. (interactive)
  6256. (org-agenda-priority 'up))
  6257. (defun org-agenda-priority-down ()
  6258. "Decrease the priority of line at point, also in Org-mode file."
  6259. (interactive)
  6260. (org-agenda-priority 'down))
  6261. (defun org-agenda-priority (&optional force-direction)
  6262. "Set the priority of line at point, also in Org-mode file.
  6263. This changes the line at point, all other lines in the agenda referring to
  6264. the same tree node, and the headline of the tree node in the Org-mode file."
  6265. (interactive)
  6266. (unless org-enable-priority-commands
  6267. (error "Priority commands are disabled"))
  6268. (org-agenda-check-no-diary)
  6269. (let* ((marker (or (org-get-at-bol 'org-marker)
  6270. (org-agenda-error)))
  6271. (hdmarker (org-get-at-bol 'org-hd-marker))
  6272. (buffer (marker-buffer hdmarker))
  6273. (pos (marker-position hdmarker))
  6274. (inhibit-read-only t)
  6275. newhead)
  6276. (org-with-remote-undo buffer
  6277. (with-current-buffer buffer
  6278. (widen)
  6279. (goto-char pos)
  6280. (org-show-context 'agenda)
  6281. (save-excursion
  6282. (and (outline-next-heading)
  6283. (org-flag-heading nil))) ; show the next heading
  6284. (funcall 'org-priority force-direction)
  6285. (end-of-line 1)
  6286. (setq newhead (org-get-heading)))
  6287. (org-agenda-change-all-lines newhead hdmarker)
  6288. (beginning-of-line 1))))
  6289. ;; FIXME: should fix the tags property of the agenda line.
  6290. (defun org-agenda-set-tags (&optional tag onoff)
  6291. "Set tags for the current headline."
  6292. (interactive)
  6293. (org-agenda-check-no-diary)
  6294. (if (and (org-region-active-p) (interactive-p))
  6295. (call-interactively 'org-change-tag-in-region)
  6296. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6297. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6298. (org-agenda-error)))
  6299. (buffer (marker-buffer hdmarker))
  6300. (pos (marker-position hdmarker))
  6301. (inhibit-read-only t)
  6302. newhead)
  6303. (org-with-remote-undo buffer
  6304. (with-current-buffer buffer
  6305. (widen)
  6306. (goto-char pos)
  6307. (save-excursion
  6308. (org-show-context 'agenda))
  6309. (save-excursion
  6310. (and (outline-next-heading)
  6311. (org-flag-heading nil))) ; show the next heading
  6312. (goto-char pos)
  6313. (if tag
  6314. (org-toggle-tag tag onoff)
  6315. (call-interactively 'org-set-tags))
  6316. (end-of-line 1)
  6317. (setq newhead (org-get-heading)))
  6318. (org-agenda-change-all-lines newhead hdmarker)
  6319. (beginning-of-line 1)))))
  6320. (defun org-agenda-set-property ()
  6321. "Set a property for the current headline."
  6322. (interactive)
  6323. (org-agenda-check-no-diary)
  6324. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6325. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6326. (org-agenda-error)))
  6327. (buffer (marker-buffer hdmarker))
  6328. (pos (marker-position hdmarker))
  6329. (inhibit-read-only t)
  6330. newhead)
  6331. (org-with-remote-undo buffer
  6332. (with-current-buffer buffer
  6333. (widen)
  6334. (goto-char pos)
  6335. (save-excursion
  6336. (org-show-context 'agenda))
  6337. (save-excursion
  6338. (and (outline-next-heading)
  6339. (org-flag-heading nil))) ; show the next heading
  6340. (goto-char pos)
  6341. (call-interactively 'org-set-property)))))
  6342. (defun org-agenda-set-effort ()
  6343. "Set the effort property for the current headline."
  6344. (interactive)
  6345. (org-agenda-check-no-diary)
  6346. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6347. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6348. (org-agenda-error)))
  6349. (buffer (marker-buffer hdmarker))
  6350. (pos (marker-position hdmarker))
  6351. (inhibit-read-only t)
  6352. newhead)
  6353. (org-with-remote-undo buffer
  6354. (with-current-buffer buffer
  6355. (widen)
  6356. (goto-char pos)
  6357. (save-excursion
  6358. (org-show-context 'agenda))
  6359. (save-excursion
  6360. (and (outline-next-heading)
  6361. (org-flag-heading nil))) ; show the next heading
  6362. (goto-char pos)
  6363. (call-interactively 'org-set-effort)
  6364. (end-of-line 1)))))
  6365. (defun org-agenda-toggle-archive-tag ()
  6366. "Toggle the archive tag for the current entry."
  6367. (interactive)
  6368. (org-agenda-check-no-diary)
  6369. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6370. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6371. (org-agenda-error)))
  6372. (buffer (marker-buffer hdmarker))
  6373. (pos (marker-position hdmarker))
  6374. (inhibit-read-only t)
  6375. newhead)
  6376. (org-with-remote-undo buffer
  6377. (with-current-buffer buffer
  6378. (widen)
  6379. (goto-char pos)
  6380. (org-show-context 'agenda)
  6381. (save-excursion
  6382. (and (outline-next-heading)
  6383. (org-flag-heading nil))) ; show the next heading
  6384. (call-interactively 'org-toggle-archive-tag)
  6385. (end-of-line 1)
  6386. (setq newhead (org-get-heading)))
  6387. (org-agenda-change-all-lines newhead hdmarker)
  6388. (beginning-of-line 1))))
  6389. (defun org-agenda-do-date-later (arg)
  6390. (interactive "P")
  6391. (cond
  6392. ((or (equal arg '(16))
  6393. (memq last-command
  6394. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6395. (setq this-command 'org-agenda-date-later-minutes)
  6396. (org-agenda-date-later-minutes 1))
  6397. ((or (equal arg '(4))
  6398. (memq last-command
  6399. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6400. (setq this-command 'org-agenda-date-later-hours)
  6401. (org-agenda-date-later-hours 1))
  6402. (t
  6403. (org-agenda-date-later (prefix-numeric-value arg)))))
  6404. (defun org-agenda-do-date-earlier (arg)
  6405. (interactive "P")
  6406. (cond
  6407. ((or (equal arg '(16))
  6408. (memq last-command
  6409. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6410. (setq this-command 'org-agenda-date-earlier-minutes)
  6411. (org-agenda-date-earlier-minutes 1))
  6412. ((or (equal arg '(4))
  6413. (memq last-command
  6414. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6415. (setq this-command 'org-agenda-date-earlier-hours)
  6416. (org-agenda-date-earlier-hours 1))
  6417. (t
  6418. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6419. (defun org-agenda-date-later (arg &optional what)
  6420. "Change the date of this item to one day later."
  6421. (interactive "p")
  6422. (org-agenda-check-type t 'agenda 'timeline)
  6423. (org-agenda-check-no-diary)
  6424. (let* ((marker (or (org-get-at-bol 'org-marker)
  6425. (org-agenda-error)))
  6426. (buffer (marker-buffer marker))
  6427. (pos (marker-position marker)))
  6428. (org-with-remote-undo buffer
  6429. (with-current-buffer buffer
  6430. (widen)
  6431. (goto-char pos)
  6432. (if (not (org-at-timestamp-p))
  6433. (error "Cannot find time stamp"))
  6434. (org-timestamp-change arg (or what 'day)))
  6435. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6436. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6437. (defun org-agenda-date-earlier (arg &optional what)
  6438. "Change the date of this item to one day earlier."
  6439. (interactive "p")
  6440. (org-agenda-date-later (- arg) what))
  6441. (defun org-agenda-date-later-minutes (arg)
  6442. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6443. (interactive "p")
  6444. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6445. (org-agenda-date-later arg 'minute))
  6446. (defun org-agenda-date-earlier-minutes (arg)
  6447. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6448. (interactive "p")
  6449. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6450. (org-agenda-date-earlier arg 'minute))
  6451. (defun org-agenda-date-later-hours (arg)
  6452. "Change the time of this item, in hour steps."
  6453. (interactive "p")
  6454. (org-agenda-date-later arg 'hour))
  6455. (defun org-agenda-date-earlier-hours (arg)
  6456. "Change the time of this item, in hour steps."
  6457. (interactive "p")
  6458. (org-agenda-date-earlier arg 'hour))
  6459. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6460. "Show new date stamp via text properties."
  6461. ;; We use text properties to make this undoable
  6462. (let ((inhibit-read-only t)
  6463. (buffer-invisibility-spec))
  6464. (setq stamp (concat " " prefix " => " stamp))
  6465. (save-excursion
  6466. (goto-char (point-max))
  6467. (while (not (bobp))
  6468. (when (equal marker (org-get-at-bol 'org-marker))
  6469. (org-move-to-column (- (window-width) (length stamp)) t)
  6470. (org-agenda-fix-tags-filter-overlays-at (point))
  6471. (if (featurep 'xemacs)
  6472. ;; Use `duplicable' property to trigger undo recording
  6473. (let ((ex (make-extent nil nil))
  6474. (gl (make-glyph stamp)))
  6475. (set-glyph-face gl 'secondary-selection)
  6476. (set-extent-properties
  6477. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6478. (insert-extent ex (1- (point)) (point-at-eol)))
  6479. (add-text-properties
  6480. (1- (point)) (point-at-eol)
  6481. (list 'display (org-add-props stamp nil
  6482. 'face 'secondary-selection))))
  6483. (beginning-of-line 1))
  6484. (beginning-of-line 0)))))
  6485. (defun org-agenda-date-prompt (arg)
  6486. "Change the date of this item. Date is prompted for, with default today.
  6487. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6488. be used to request time specification in the time stamp."
  6489. (interactive "P")
  6490. (org-agenda-check-type t 'agenda 'timeline)
  6491. (org-agenda-check-no-diary)
  6492. (let* ((marker (or (org-get-at-bol 'org-marker)
  6493. (org-agenda-error)))
  6494. (buffer (marker-buffer marker))
  6495. (pos (marker-position marker)))
  6496. (org-with-remote-undo buffer
  6497. (with-current-buffer buffer
  6498. (widen)
  6499. (goto-char pos)
  6500. (if (not (org-at-timestamp-p t))
  6501. (error "Cannot find time stamp"))
  6502. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6503. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6504. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6505. (defun org-agenda-schedule (arg)
  6506. "Schedule the item at point.
  6507. Arg is passed through to `org-schedule'."
  6508. (interactive "P")
  6509. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6510. (org-agenda-check-no-diary)
  6511. (let* ((marker (or (org-get-at-bol 'org-marker)
  6512. (org-agenda-error)))
  6513. (type (marker-insertion-type marker))
  6514. (buffer (marker-buffer marker))
  6515. (pos (marker-position marker))
  6516. (org-insert-labeled-timestamps-at-point nil)
  6517. ts)
  6518. (set-marker-insertion-type marker t)
  6519. (org-with-remote-undo buffer
  6520. (with-current-buffer buffer
  6521. (widen)
  6522. (goto-char pos)
  6523. (setq ts (org-schedule arg)))
  6524. (org-agenda-show-new-time marker ts "S"))
  6525. (message "Item scheduled for %s" ts)))
  6526. (defun org-agenda-deadline (arg)
  6527. "Schedule the item at point.
  6528. Arg is passed through to `org-deadline'."
  6529. (interactive "P")
  6530. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6531. (org-agenda-check-no-diary)
  6532. (let* ((marker (or (org-get-at-bol 'org-marker)
  6533. (org-agenda-error)))
  6534. (buffer (marker-buffer marker))
  6535. (pos (marker-position marker))
  6536. (org-insert-labeled-timestamps-at-point nil)
  6537. ts)
  6538. (org-with-remote-undo buffer
  6539. (with-current-buffer buffer
  6540. (widen)
  6541. (goto-char pos)
  6542. (setq ts (org-deadline arg)))
  6543. (org-agenda-show-new-time marker ts "D"))
  6544. (message "Deadline for this item set to %s" ts)))
  6545. (defun org-agenda-action ()
  6546. "Select entry for agenda action, or execute an agenda action.
  6547. This command prompts for another letter. Valid inputs are:
  6548. m Mark the entry at point for an agenda action
  6549. s Schedule the marked entry to the date at the cursor
  6550. d Set the deadline of the marked entry to the date at the cursor
  6551. r Call `org-remember' with cursor date as the default date
  6552. c Call `org-capture' with cursor date as the default date
  6553. SPC Show marked entry in other window
  6554. TAB Visit marked entry in other window
  6555. The cursor may be at a date in the calendar, or in the Org agenda."
  6556. (interactive)
  6557. (let (ans)
  6558. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6559. (setq ans (read-char-exclusive))
  6560. (cond
  6561. ((equal ans ?m)
  6562. ;; Mark this entry
  6563. (if (eq major-mode 'org-agenda-mode)
  6564. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6565. (org-get-at-bol 'org-marker))))
  6566. (if m
  6567. (progn
  6568. (move-marker org-agenda-action-marker
  6569. (marker-position m) (marker-buffer m))
  6570. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6571. (error "Don't know which entry to mark")))
  6572. (error "This command works only in the agenda")))
  6573. ((equal ans ?s)
  6574. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6575. ((equal ans ?d)
  6576. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6577. ((equal ans ?r)
  6578. (org-agenda-do-action '(org-remember) t))
  6579. ((equal ans ?c)
  6580. (org-agenda-do-action '(org-capture) t))
  6581. ((equal ans ?\ )
  6582. (let ((cw (selected-window)))
  6583. (org-switch-to-buffer-other-window
  6584. (marker-buffer org-agenda-action-marker))
  6585. (goto-char org-agenda-action-marker)
  6586. (org-show-context 'agenda)
  6587. (select-window cw)))
  6588. ((equal ans ?\C-i)
  6589. (org-switch-to-buffer-other-window
  6590. (marker-buffer org-agenda-action-marker))
  6591. (goto-char org-agenda-action-marker)
  6592. (org-show-context 'agenda))
  6593. (t (error "Invalid agenda action %c" ans)))))
  6594. (defun org-agenda-do-action (form &optional current-buffer)
  6595. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6596. (let ((org-overriding-default-time (org-get-cursor-date)))
  6597. (if current-buffer
  6598. (eval form)
  6599. (if (not (marker-buffer org-agenda-action-marker))
  6600. (error "No entry has been selected for agenda action")
  6601. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6602. (save-excursion
  6603. (save-restriction
  6604. (widen)
  6605. (goto-char org-agenda-action-marker)
  6606. (eval form))))))))
  6607. (defun org-agenda-clock-in (&optional arg)
  6608. "Start the clock on the currently selected item."
  6609. (interactive "P")
  6610. (org-agenda-check-no-diary)
  6611. (if (equal arg '(4))
  6612. (org-clock-in arg)
  6613. (let* ((marker (or (org-get-at-bol 'org-marker)
  6614. (org-agenda-error)))
  6615. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6616. marker))
  6617. (pos (marker-position marker))
  6618. newhead)
  6619. (org-with-remote-undo (marker-buffer marker)
  6620. (with-current-buffer (marker-buffer marker)
  6621. (widen)
  6622. (goto-char pos)
  6623. (org-show-context 'agenda)
  6624. (org-show-entry)
  6625. (org-cycle-hide-drawers 'children)
  6626. (org-clock-in arg)
  6627. (setq newhead (org-get-heading)))
  6628. (org-agenda-change-all-lines newhead hdmarker)))))
  6629. (defun org-agenda-clock-out (&optional arg)
  6630. "Stop the currently running clock."
  6631. (interactive "P")
  6632. (unless (marker-buffer org-clock-marker)
  6633. (error "No running clock"))
  6634. (let ((marker (make-marker)) newhead)
  6635. (org-with-remote-undo (marker-buffer org-clock-marker)
  6636. (with-current-buffer (marker-buffer org-clock-marker)
  6637. (save-excursion
  6638. (save-restriction
  6639. (widen)
  6640. (goto-char org-clock-marker)
  6641. (org-back-to-heading t)
  6642. (move-marker marker (point))
  6643. (org-clock-out)
  6644. (setq newhead (org-get-heading))))))
  6645. (org-agenda-change-all-lines newhead marker)
  6646. (move-marker marker nil)))
  6647. (defun org-agenda-clock-cancel (&optional arg)
  6648. "Cancel the currently running clock."
  6649. (interactive "P")
  6650. (unless (marker-buffer org-clock-marker)
  6651. (error "No running clock"))
  6652. (org-with-remote-undo (marker-buffer org-clock-marker)
  6653. (org-clock-cancel)))
  6654. (defun org-agenda-clock-goto ()
  6655. "Jump to the currently clocked in task within the agenda.
  6656. If the currently clocked in task is not listed in the agenda
  6657. buffer, display it in another window."
  6658. (interactive)
  6659. (let (pos)
  6660. (mapc (lambda (o)
  6661. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6662. (setq pos (overlay-start o))))
  6663. (overlays-in (point-min) (point-max)))
  6664. (cond (pos (goto-char pos))
  6665. ;; If the currently clocked entry is not in the agenda
  6666. ;; buffer, we visit it in another window:
  6667. (org-clock-current-task
  6668. (org-switch-to-buffer-other-window (org-clock-goto)))
  6669. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6670. (defun org-agenda-diary-entry-in-org-file ()
  6671. "Make a diary entry in the file `org-agenda-diary-file'."
  6672. (let (d1 d2 char (text "") dp1 dp2)
  6673. (if (equal (buffer-name) "*Calendar*")
  6674. (setq d1 (calendar-cursor-to-date t)
  6675. d2 (car calendar-mark-ring))
  6676. (setq dp1 (get-text-property (point-at-bol) 'day))
  6677. (unless dp1 (error "No date defined in current line"))
  6678. (setq d1 (calendar-gregorian-from-absolute dp1)
  6679. d2 (and (ignore-errors (mark))
  6680. (save-excursion
  6681. (goto-char (mark))
  6682. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6683. (calendar-gregorian-from-absolute dp2))))
  6684. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6685. (setq char (read-char-exclusive))
  6686. (cond
  6687. ((equal char ?d)
  6688. (setq text (read-string "Day entry: "))
  6689. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6690. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6691. ((equal char ?a)
  6692. (setq d1 (list (car d1) (nth 1 d1)
  6693. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6694. (nth 2 d1))))
  6695. (setq text (read-string "Anniversary (use %d to show years): "))
  6696. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6697. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6698. ((equal char ?b)
  6699. (setq text (read-string "Block entry: "))
  6700. (unless (and d1 d2 (not (equal d1 d2)))
  6701. (error "No block of days selected"))
  6702. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6703. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6704. ((equal char ?j)
  6705. (org-switch-to-buffer-other-window
  6706. (find-file-noselect org-agenda-diary-file))
  6707. (require 'org-datetree)
  6708. (org-datetree-find-date-create d1)
  6709. (org-reveal t))
  6710. (t (error "Invalid selection character `%c'" char)))))
  6711. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6712. "Where in `org-agenda-diary-file' should new entries be added?
  6713. Valid values:
  6714. date-tree in the date tree, as child of the date
  6715. top-level as top-level entries at the end of the file."
  6716. :group 'org-agenda
  6717. :type '(choice
  6718. (const :tag "in a date tree" date-tree)
  6719. (const :tag "as top level at end of file" top-level)))
  6720. (defcustom org-agenda-insert-diary-extract-time nil
  6721. "Non-nil means extract any time specification from the diary entry."
  6722. :group 'org-agenda
  6723. :type 'boolean)
  6724. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6725. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6726. If TEXT is not empty, it will become the headline of the new entry, and
  6727. the resulting entry will not be shown. When TEXT is empty, switch to
  6728. `org-agenda-diary-file' and let the user finish the entry there."
  6729. (let ((cw (current-window-configuration)))
  6730. (org-switch-to-buffer-other-window
  6731. (find-file-noselect org-agenda-diary-file))
  6732. (widen)
  6733. (goto-char (point-min))
  6734. (cond
  6735. ((eq type 'anniversary)
  6736. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6737. (progn
  6738. (or (org-on-heading-p t)
  6739. (progn
  6740. (outline-next-heading)
  6741. (insert "* Anniversaries\n\n")
  6742. (beginning-of-line -1)))))
  6743. (outline-next-heading)
  6744. (org-back-over-empty-lines)
  6745. (backward-char 1)
  6746. (insert "\n")
  6747. (require 'diary-lib)
  6748. (let ((calendar-date-display-form
  6749. (if (if (boundp 'calendar-date-style)
  6750. (eq calendar-date-style 'european)
  6751. (org-bound-and-true-p european-calendar-style)) ; Emacs 22
  6752. '(day " " month " " year)
  6753. '(month " " day " " year))))
  6754. (insert (format "%%%%(diary-anniversary %s) %s"
  6755. (calendar-date-string d1 nil t) text))))
  6756. ((eq type 'day)
  6757. (let ((org-prefix-has-time t)
  6758. (org-agenda-time-leading-zero t)
  6759. fmt time time2)
  6760. (if org-agenda-insert-diary-extract-time
  6761. ;; Use org-format-agenda-item to parse text for a time-range and
  6762. ;; remove it. FIXME: This is a hack, we should refactor
  6763. ;; that function to make time extraction available separately
  6764. (setq fmt (org-format-agenda-item nil text nil nil t)
  6765. time (get-text-property 0 'time fmt)
  6766. time2 (if (> (length time) 0)
  6767. ;; split-string removes trailing ...... if
  6768. ;; no end time given. First space
  6769. ;; separates time from date.
  6770. (concat " " (car (split-string time "\\.")))
  6771. nil)
  6772. text (get-text-property 0 'txt fmt)))
  6773. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6774. (org-agenda-insert-diary-as-top-level text)
  6775. (require 'org-datetree)
  6776. (org-datetree-find-date-create d1)
  6777. (org-agenda-insert-diary-make-new-entry text))
  6778. (org-insert-time-stamp (org-time-from-absolute
  6779. (calendar-absolute-from-gregorian d1))
  6780. nil nil nil nil time2))
  6781. (end-of-line 0))
  6782. ((eq type 'block)
  6783. (if (> (calendar-absolute-from-gregorian d1)
  6784. (calendar-absolute-from-gregorian d2))
  6785. (setq d1 (prog1 d2 (setq d2 d1))))
  6786. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6787. (org-agenda-insert-diary-as-top-level text)
  6788. (require 'org-datetree)
  6789. (org-datetree-find-date-create d1)
  6790. (org-agenda-insert-diary-make-new-entry text))
  6791. (org-insert-time-stamp (org-time-from-absolute
  6792. (calendar-absolute-from-gregorian d1)))
  6793. (insert "--")
  6794. (org-insert-time-stamp (org-time-from-absolute
  6795. (calendar-absolute-from-gregorian d2)))
  6796. (end-of-line 0)))
  6797. (if (string-match "\\S-" text)
  6798. (progn
  6799. (set-window-configuration cw)
  6800. (message "%s entry added to %s"
  6801. (capitalize (symbol-name type))
  6802. (abbreviate-file-name org-agenda-diary-file)))
  6803. (org-reveal t)
  6804. (message "Please finish entry here"))))
  6805. (defun org-agenda-insert-diary-as-top-level (text)
  6806. "Make new entry as a top-level entry at the end of the file.
  6807. Add TEXT as headline, and position the cursor in the second line so that
  6808. a timestamp can be added there."
  6809. (widen)
  6810. (goto-char (point-max))
  6811. (or (bolp) (insert "\n"))
  6812. (insert "* " text "\n")
  6813. (if org-adapt-indentation (org-indent-to-column 2)))
  6814. (defun org-agenda-insert-diary-make-new-entry (text)
  6815. "Make new entry as last child of current entry.
  6816. Add TEXT as headline, and position the cursor in the second line so that
  6817. a timestamp can be added there."
  6818. (let ((org-show-following-heading t)
  6819. (org-show-siblings t)
  6820. (org-show-hierarchy-above t)
  6821. (org-show-entry-below t)
  6822. col)
  6823. (outline-next-heading)
  6824. (org-back-over-empty-lines)
  6825. (or (looking-at "[ \t]*$")
  6826. (progn (insert "\n") (backward-char 1)))
  6827. (org-insert-heading nil t)
  6828. (org-do-demote)
  6829. (setq col (current-column))
  6830. (insert text "\n")
  6831. (if org-adapt-indentation (org-indent-to-column col))
  6832. (let ((org-show-following-heading t)
  6833. (org-show-siblings t)
  6834. (org-show-hierarchy-above t)
  6835. (org-show-entry-below t))
  6836. (org-show-context))))
  6837. (defun org-agenda-diary-entry ()
  6838. "Make a diary entry, like the `i' command from the calendar.
  6839. All the standard commands work: block, weekly etc.
  6840. When `org-agenda-diary-file' points to a file,
  6841. `org-agenda-diary-entry-in-org-file' is called instead to create
  6842. entries in that Org-mode file."
  6843. (interactive)
  6844. (org-agenda-check-type t 'agenda 'timeline)
  6845. (if (not (eq org-agenda-diary-file 'diary-file))
  6846. (org-agenda-diary-entry-in-org-file)
  6847. (require 'diary-lib)
  6848. (let* ((char (progn
  6849. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6850. (read-char-exclusive)))
  6851. (cmd (cdr (assoc char
  6852. '((?d . insert-diary-entry)
  6853. (?w . insert-weekly-diary-entry)
  6854. (?m . insert-monthly-diary-entry)
  6855. (?y . insert-yearly-diary-entry)
  6856. (?a . insert-anniversary-diary-entry)
  6857. (?b . insert-block-diary-entry)
  6858. (?c . insert-cyclic-diary-entry)))))
  6859. (oldf (symbol-function 'calendar-cursor-to-date))
  6860. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6861. (point (point))
  6862. (mark (or (mark t) (point))))
  6863. (unless cmd
  6864. (error "No command associated with <%c>" char))
  6865. (unless (and (get-text-property point 'day)
  6866. (or (not (equal ?b char))
  6867. (get-text-property mark 'day)))
  6868. (error "Don't know which date to use for diary entry"))
  6869. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6870. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6871. (let ((calendar-mark-ring
  6872. (list (calendar-gregorian-from-absolute
  6873. (or (get-text-property mark 'day)
  6874. (get-text-property point 'day))))))
  6875. (unwind-protect
  6876. (progn
  6877. (fset 'calendar-cursor-to-date
  6878. (lambda (&optional error dummy)
  6879. (calendar-gregorian-from-absolute
  6880. (get-text-property point 'day))))
  6881. (call-interactively cmd))
  6882. (fset 'calendar-cursor-to-date oldf))))))
  6883. (defun org-agenda-execute-calendar-command (cmd)
  6884. "Execute a calendar command from the agenda, with the date associated to
  6885. the cursor position."
  6886. (org-agenda-check-type t 'agenda 'timeline)
  6887. (require 'diary-lib)
  6888. (unless (get-text-property (point) 'day)
  6889. (error "Don't know which date to use for calendar command"))
  6890. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6891. (point (point))
  6892. (date (calendar-gregorian-from-absolute
  6893. (get-text-property point 'day)))
  6894. ;; the following 2 vars are needed in the calendar
  6895. (displayed-month (car date))
  6896. (displayed-year (nth 2 date)))
  6897. (unwind-protect
  6898. (progn
  6899. (fset 'calendar-cursor-to-date
  6900. (lambda (&optional error dummy)
  6901. (calendar-gregorian-from-absolute
  6902. (get-text-property point 'day))))
  6903. (call-interactively cmd))
  6904. (fset 'calendar-cursor-to-date oldf))))
  6905. (defun org-agenda-phases-of-moon ()
  6906. "Display the phases of the moon for the 3 months around the cursor date."
  6907. (interactive)
  6908. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6909. (defun org-agenda-holidays ()
  6910. "Display the holidays for the 3 months around the cursor date."
  6911. (interactive)
  6912. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6913. (defvar calendar-longitude)
  6914. (defvar calendar-latitude)
  6915. (defvar calendar-location-name)
  6916. (defun org-agenda-sunrise-sunset (arg)
  6917. "Display sunrise and sunset for the cursor date.
  6918. Latitude and longitude can be specified with the variables
  6919. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6920. argument, latitude and longitude will be prompted for."
  6921. (interactive "P")
  6922. (require 'solar)
  6923. (let ((calendar-longitude (if arg nil calendar-longitude))
  6924. (calendar-latitude (if arg nil calendar-latitude))
  6925. (calendar-location-name
  6926. (if arg "the given coordinates" calendar-location-name)))
  6927. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6928. (defun org-agenda-goto-calendar ()
  6929. "Open the Emacs calendar with the date at the cursor."
  6930. (interactive)
  6931. (org-agenda-check-type t 'agenda 'timeline)
  6932. (let* ((day (or (get-text-property (point) 'day)
  6933. (error "Don't know which date to open in calendar")))
  6934. (date (calendar-gregorian-from-absolute day))
  6935. (calendar-move-hook nil)
  6936. (calendar-view-holidays-initially-flag nil)
  6937. (calendar-view-diary-initially-flag nil))
  6938. (calendar)
  6939. (calendar-goto-date date)))
  6940. ;;;###autoload
  6941. (defun org-calendar-goto-agenda ()
  6942. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6943. This is a command that has to be installed in `calendar-mode-map'."
  6944. (interactive)
  6945. (org-agenda-list nil (calendar-absolute-from-gregorian
  6946. (calendar-cursor-to-date))
  6947. nil))
  6948. (defun org-agenda-convert-date ()
  6949. (interactive)
  6950. (org-agenda-check-type t 'agenda 'timeline)
  6951. (let ((day (get-text-property (point) 'day))
  6952. date s)
  6953. (unless day
  6954. (error "Don't know which date to convert"))
  6955. (setq date (calendar-gregorian-from-absolute day))
  6956. (setq s (concat
  6957. "Gregorian: " (calendar-date-string date) "\n"
  6958. "ISO: " (calendar-iso-date-string date) "\n"
  6959. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6960. "Julian: " (calendar-julian-date-string date) "\n"
  6961. "Astron. JD: " (calendar-astro-date-string date)
  6962. " (Julian date number at noon UTC)\n"
  6963. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6964. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6965. "French: " (calendar-french-date-string date) "\n"
  6966. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6967. "Mayan: " (calendar-mayan-date-string date) "\n"
  6968. "Coptic: " (calendar-coptic-date-string date) "\n"
  6969. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6970. "Persian: " (calendar-persian-date-string date) "\n"
  6971. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6972. (with-output-to-temp-buffer "*Dates*"
  6973. (princ s))
  6974. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6975. ;;; Bulk commands
  6976. (defvar org-agenda-bulk-marked-entries nil
  6977. "List of markers that refer to marked entries in the agenda.")
  6978. (defun org-agenda-bulk-marked-p ()
  6979. (eq (get-char-property (point-at-bol) 'type)
  6980. 'org-marked-entry-overlay))
  6981. (defun org-agenda-bulk-mark ()
  6982. "Mark the entry at point for future bulk action."
  6983. (interactive)
  6984. (org-agenda-check-no-diary)
  6985. (let* ((m (org-get-at-bol 'org-hd-marker))
  6986. ov)
  6987. (unless (org-agenda-bulk-marked-p)
  6988. (unless m (error "Nothing to mark at point"))
  6989. (push m org-agenda-bulk-marked-entries)
  6990. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  6991. (org-overlay-display ov "> "
  6992. (org-get-todo-face "TODO")
  6993. 'evaporate)
  6994. (overlay-put ov 'type 'org-marked-entry-overlay))
  6995. (beginning-of-line 2)
  6996. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6997. (beginning-of-line 2))
  6998. (message "%d entries marked for bulk action"
  6999. (length org-agenda-bulk-marked-entries))))
  7000. (defun org-agenda-bulk-unmark ()
  7001. "Unmark the entry at point for future bulk action."
  7002. (interactive)
  7003. (when (org-agenda-bulk-marked-p)
  7004. (org-agenda-bulk-remove-overlays
  7005. (point-at-bol) (+ 2 (point-at-bol)))
  7006. (setq org-agenda-bulk-marked-entries
  7007. (delete (org-get-at-bol 'org-hd-marker)
  7008. org-agenda-bulk-marked-entries)))
  7009. (beginning-of-line 2)
  7010. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7011. (beginning-of-line 2))
  7012. (message "%d entries marked for bulk action"
  7013. (length org-agenda-bulk-marked-entries)))
  7014. (defun org-agenda-bulk-toggle ()
  7015. "Toggle marking the entry at point for bulk action."
  7016. (interactive)
  7017. (if (org-agenda-bulk-marked-p)
  7018. (org-agenda-bulk-unmark)
  7019. (org-agenda-bulk-mark)))
  7020. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7021. "Remove the mark overlays between BEG and END in the agenda buffer.
  7022. BEG and END default to the buffer limits.
  7023. This only removes the overlays, it does not remove the markers
  7024. from the list in `org-agenda-bulk-marked-entries'."
  7025. (interactive)
  7026. (mapc (lambda (ov)
  7027. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7028. (delete-overlay ov)))
  7029. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7030. (defun org-agenda-bulk-remove-all-marks ()
  7031. "Remove all marks in the agenda buffer.
  7032. This will remove the markers, and the overlays."
  7033. (interactive)
  7034. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7035. (setq org-agenda-bulk-marked-entries nil)
  7036. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7037. (defun org-agenda-bulk-action (&optional arg)
  7038. "Execute an remote-editing action on all marked entries.
  7039. The prefix arg is passed through to the command if possible."
  7040. (interactive "P")
  7041. (unless org-agenda-bulk-marked-entries
  7042. (error "No entries are marked"))
  7043. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7044. (let* ((action (read-char-exclusive))
  7045. (org-log-refile (if org-log-refile 'time nil))
  7046. (entries (reverse org-agenda-bulk-marked-entries))
  7047. redo-at-end
  7048. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7049. (cond
  7050. ((equal action ?$)
  7051. (setq cmd '(org-agenda-archive)))
  7052. ((equal action ?A)
  7053. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7054. ((member action '(?r ?w))
  7055. (setq rfloc (org-refile-get-location
  7056. "Refile to: "
  7057. (marker-buffer (car org-agenda-bulk-marked-entries))
  7058. org-refile-allow-creating-parent-nodes))
  7059. (if (nth 3 rfloc)
  7060. (setcar (nthcdr 3 rfloc)
  7061. (move-marker (make-marker) (nth 3 rfloc)
  7062. (or (get-file-buffer (nth 1 rfloc))
  7063. (find-buffer-visiting (nth 1 rfloc))
  7064. (error "This should not happen")))))
  7065. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7066. redo-at-end t))
  7067. ((equal action ?t)
  7068. (setq state (org-icompleting-read
  7069. "Todo state: "
  7070. (with-current-buffer (marker-buffer (car entries))
  7071. (mapcar 'list org-todo-keywords-1))))
  7072. (setq cmd `(let ((org-inhibit-blocking t)
  7073. (org-inhibit-logging 'note))
  7074. (org-agenda-todo ,state))))
  7075. ((memq action '(?- ?+))
  7076. (setq tag (org-icompleting-read
  7077. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7078. (with-current-buffer (marker-buffer (car entries))
  7079. (delq nil
  7080. (mapcar (lambda (x)
  7081. (if (stringp (car x)) x)) org-tag-alist)))))
  7082. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7083. ((memq action '(?s ?d))
  7084. (let* ((date (unless arg
  7085. (org-read-date
  7086. nil nil nil
  7087. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7088. (ans (if arg nil org-read-date-final-answer))
  7089. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7090. (setq cmd `(let* ((bound (fboundp 'read-string))
  7091. (old (and bound (symbol-function 'read-string))))
  7092. (unwind-protect
  7093. (progn
  7094. (fset 'read-string (lambda (&rest ignore) ,ans))
  7095. (eval '(,c1 arg)))
  7096. (if bound
  7097. (fset 'read-string old)
  7098. (fmakunbound 'read-string)))))))
  7099. (t (error "Invalid bulk action")))
  7100. ;; Sort the markers, to make sure that parents are handled before children
  7101. (setq entries (sort entries
  7102. (lambda (a b)
  7103. (cond
  7104. ((equal (marker-buffer a) (marker-buffer b))
  7105. (< (marker-position a) (marker-position b)))
  7106. (t
  7107. (string< (buffer-name (marker-buffer a))
  7108. (buffer-name (marker-buffer b))))))))
  7109. ;; Now loop over all markers and apply cmd
  7110. (while (setq e (pop entries))
  7111. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7112. (if (not pos)
  7113. (progn (message "Skipping removed entry at %s" e)
  7114. (setq cntskip (1+ cntskip)))
  7115. (goto-char pos)
  7116. (eval cmd)
  7117. (setq org-agenda-bulk-marked-entries
  7118. (delete e org-agenda-bulk-marked-entries))
  7119. (setq cnt (1+ cnt))))
  7120. (setq org-agenda-bulk-marked-entries nil)
  7121. (org-agenda-bulk-remove-all-marks)
  7122. (when redo-at-end (org-agenda-redo))
  7123. (message "Acted on %d entries%s"
  7124. cnt
  7125. (if (= cntskip 0)
  7126. ""
  7127. (format ", skipped %d (disappeared before their turn)"
  7128. cntskip)))))
  7129. ;;; Flagging notes
  7130. (defun org-agenda-show-the-flagging-note ()
  7131. "Display the flagging note in the other window.
  7132. When called a second time in direct sequence, offer to remove the FLAGGING
  7133. tag and (if present) the flagging note."
  7134. (interactive)
  7135. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7136. (win (selected-window))
  7137. note heading newhead)
  7138. (unless hdmarker
  7139. (error "No linked entry at point"))
  7140. (if (and (eq this-command last-command)
  7141. (y-or-n-p "Unflag and remove any flagging note? "))
  7142. (progn
  7143. (org-agenda-remove-flag hdmarker)
  7144. (let ((win (get-buffer-window "*Flagging Note*")))
  7145. (and win (delete-window win)))
  7146. (message "Entry unflaged"))
  7147. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7148. (unless note
  7149. (error "No flagging note"))
  7150. (org-kill-new note)
  7151. (org-switch-to-buffer-other-window "*Flagging Note*")
  7152. (erase-buffer)
  7153. (insert note)
  7154. (goto-char (point-min))
  7155. (while (re-search-forward "\\\\n" nil t)
  7156. (replace-match "\n" t t))
  7157. (goto-char (point-min))
  7158. (select-window win)
  7159. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7160. (defun org-agenda-remove-flag (marker)
  7161. "Remove the FLAGGED tag and any flagging note in the entry."
  7162. (let (newhead)
  7163. (org-with-point-at marker
  7164. (org-toggle-tag "FLAGGED" 'off)
  7165. (org-entry-delete nil "THEFLAGGINGNOTE")
  7166. (setq newhead (org-get-heading)))
  7167. (org-agenda-change-all-lines newhead marker)
  7168. (message "Entry unflaged")))
  7169. (defun org-agenda-get-any-marker (&optional pos)
  7170. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7171. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7172. ;;; Appointment reminders
  7173. (defvar appt-time-msg-list)
  7174. ;;;###autoload
  7175. (defun org-agenda-to-appt (&optional refresh filter)
  7176. "Activate appointments found in `org-agenda-files'.
  7177. With a \\[universal-argument] prefix, refresh the list of
  7178. appointments.
  7179. If FILTER is t, interactively prompt the user for a regular
  7180. expression, and filter out entries that don't match it.
  7181. If FILTER is a string, use this string as a regular expression
  7182. for filtering entries out.
  7183. FILTER can also be an alist with the car of each cell being
  7184. either 'headline or 'category. For example:
  7185. '((headline \"IMPORTANT\")
  7186. (category \"Work\"))
  7187. will only add headlines containing IMPORTANT or headlines
  7188. belonging to the \"Work\" category."
  7189. (interactive "P")
  7190. (if refresh (setq appt-time-msg-list nil))
  7191. (if (eq filter t)
  7192. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7193. (let* ((cnt 0) ; count added events
  7194. (org-agenda-new-buffers nil)
  7195. (org-deadline-warning-days 0)
  7196. (today (org-date-to-gregorian
  7197. (time-to-days (current-time))))
  7198. (org-agenda-restrict nil)
  7199. (files (org-agenda-files 'unrestricted)) entries file)
  7200. ;; Get all entries which may contain an appt
  7201. (org-prepare-agenda-buffers files)
  7202. (while (setq file (pop files))
  7203. (setq entries
  7204. (append entries
  7205. (org-agenda-get-day-entries
  7206. file today :timestamp :scheduled :deadline))))
  7207. (setq entries (delq nil entries))
  7208. ;; Map thru entries and find if we should filter them out
  7209. (mapc
  7210. (lambda(x)
  7211. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7212. (cat (get-text-property 1 'org-category x))
  7213. (tod (get-text-property 1 'time-of-day x))
  7214. (ok (or (null filter)
  7215. (and (stringp filter) (string-match filter evt))
  7216. (and (listp filter)
  7217. (or (string-match
  7218. (cadr (assoc 'category filter)) cat)
  7219. (string-match
  7220. (cadr (assoc 'headline filter)) evt))))))
  7221. ;; FIXME: Shall we remove text-properties for the appt text?
  7222. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7223. (when (and ok tod)
  7224. (setq tod (concat "00" (number-to-string tod))
  7225. tod (when (string-match
  7226. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7227. (concat (match-string 1 tod) ":"
  7228. (match-string 2 tod))))
  7229. (appt-add tod evt)
  7230. (setq cnt (1+ cnt))))) entries)
  7231. (org-release-buffers org-agenda-new-buffers)
  7232. (if (eq cnt 0)
  7233. (message "No event to add")
  7234. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7235. (defun org-agenda-todayp (date)
  7236. "Does DATE mean today, when considering `org-extend-today-until'?"
  7237. (let (today h)
  7238. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7239. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7240. (setq h (nth 2 (decode-time (current-time))))
  7241. (or (and (>= h org-extend-today-until)
  7242. (= date today))
  7243. (and (< h org-extend-today-until)
  7244. (= date (1- today))))))
  7245. (provide 'org-agenda)
  7246. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7247. ;;; org-agenda.el ends here