org-agenda.el 392 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2014 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-columns-remove-overlays "org-colview" ())
  64. (declare-function org-datetree-find-date-create "org-datetree"
  65. (date &optional keep-restriction))
  66. (declare-function org-columns-quit "org-colview" ())
  67. (declare-function diary-date-display-form "diary-lib" (&optional type))
  68. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  69. (declare-function org-habit-insert-consistency-graphs
  70. "org-habit" (&optional line))
  71. (declare-function org-is-habit-p "org-habit" (&optional pom))
  72. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  73. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  74. (declare-function org-pop-to-buffer-same-window "org-compat"
  75. (&optional buffer-or-name norecord label))
  76. (declare-function org-agenda-columns "org-colview" ())
  77. (declare-function org-add-archive-files "org-archive" (files))
  78. (declare-function org-capture "org-capture" (&optional goto keys))
  79. (defvar calendar-mode-map) ; defined in calendar.el
  80. (defvar org-clock-current-task nil) ; defined in org-clock.el
  81. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  82. (defvar org-habit-show-habits) ; defined in org-habit.el
  83. (defvar org-habit-show-habits-only-for-today)
  84. (defvar org-habit-show-all-today)
  85. ;; Defined somewhere in this file, but used before definition.
  86. (defvar org-agenda-buffer-name "*Org Agenda*")
  87. (defvar org-agenda-overriding-header nil)
  88. (defvar org-agenda-title-append nil)
  89. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  90. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  91. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  92. (defvar org-agenda-undo-list nil
  93. "List of undoable operations in the agenda since last refresh.")
  94. (defvar org-agenda-pending-undo-list nil
  95. "In a series of undo commands, this is the list of remaining undo items.")
  96. (defcustom org-agenda-confirm-kill 1
  97. "When set, remote killing from the agenda buffer needs confirmation.
  98. When t, a confirmation is always needed. When a number N, confirmation is
  99. only needed when the text to be killed contains more than N non-white lines."
  100. :group 'org-agenda
  101. :type '(choice
  102. (const :tag "Never" nil)
  103. (const :tag "Always" t)
  104. (integer :tag "When more than N lines")))
  105. (defcustom org-agenda-compact-blocks nil
  106. "Non-nil means make the block agenda more compact.
  107. This is done globally by leaving out lines like the agenda span
  108. name and week number or the separator lines."
  109. :group 'org-agenda
  110. :type 'boolean)
  111. (defcustom org-agenda-block-separator ?=
  112. "The separator between blocks in the agenda.
  113. If this is a string, it will be used as the separator, with a newline added.
  114. If it is a character, it will be repeated to fill the window width.
  115. If nil the separator is disabled. In `org-agenda-custom-commands' this
  116. addresses the separator between the current and the previous block."
  117. :group 'org-agenda
  118. :type '(choice
  119. (const :tag "Disabled" nil)
  120. (character)
  121. (string)))
  122. (defgroup org-agenda-export nil
  123. "Options concerning exporting agenda views in Org-mode."
  124. :tag "Org Agenda Export"
  125. :group 'org-agenda)
  126. (defcustom org-agenda-with-colors t
  127. "Non-nil means use colors in agenda views."
  128. :group 'org-agenda-export
  129. :type 'boolean)
  130. (defcustom org-agenda-exporter-settings nil
  131. "Alist of variable/value pairs that should be active during agenda export.
  132. This is a good place to set options for ps-print and for htmlize.
  133. Note that the way this is implemented, the values will be evaluated
  134. before assigned to the variables. So make sure to quote values you do
  135. *not* want evaluated, for example
  136. (setq org-agenda-exporter-settings
  137. '((ps-print-color-p 'black-white)))"
  138. :group 'org-agenda-export
  139. :type '(repeat
  140. (list
  141. (variable)
  142. (sexp :tag "Value"))))
  143. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  144. "Hook run in a temporary buffer before writing the agenda to an export file.
  145. A useful function for this hook is `org-agenda-add-entry-text'."
  146. :group 'org-agenda-export
  147. :type 'hook
  148. :options '(org-agenda-add-entry-text))
  149. (defcustom org-agenda-add-entry-text-maxlines 0
  150. "Maximum number of entry text lines to be added to agenda.
  151. This is only relevant when `org-agenda-add-entry-text' is part of
  152. `org-agenda-before-write-hook', which is the default.
  153. When this is 0, nothing will happen. When it is greater than 0, it
  154. specifies the maximum number of lines that will be added for each entry
  155. that is listed in the agenda view.
  156. Note that this variable is not used during display, only when exporting
  157. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  158. and `org-agenda-entry-text-maxlines'."
  159. :group 'org-agenda
  160. :type 'integer)
  161. (defcustom org-agenda-add-entry-text-descriptive-links t
  162. "Non-nil means export org-links as descriptive links in agenda added text.
  163. This variable applies to the text added to the agenda when
  164. `org-agenda-add-entry-text-maxlines' is larger than 0.
  165. When this variable nil, the URL will (also) be shown."
  166. :group 'org-agenda
  167. :type 'boolean)
  168. (defcustom org-agenda-export-html-style nil
  169. "The style specification for exported HTML Agenda files.
  170. If this variable contains a string, it will replace the default <style>
  171. section as produced by `htmlize'.
  172. Since there are different ways of setting style information, this variable
  173. needs to contain the full HTML structure to provide a style, including the
  174. surrounding HTML tags. The style specifications should include definitions
  175. the fonts used by the agenda, here is an example:
  176. <style type=\"text/css\">
  177. p { font-weight: normal; color: gray; }
  178. .org-agenda-structure {
  179. font-size: 110%;
  180. color: #003399;
  181. font-weight: 600;
  182. }
  183. .org-todo {
  184. color: #cc6666;
  185. font-weight: bold;
  186. }
  187. .org-agenda-done {
  188. color: #339933;
  189. }
  190. .org-done {
  191. color: #339933;
  192. }
  193. .title { text-align: center; }
  194. .todo, .deadline { color: red; }
  195. .done { color: green; }
  196. </style>
  197. or, if you want to keep the style in a file,
  198. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  199. As the value of this option simply gets inserted into the HTML <head> header,
  200. you can \"misuse\" it to also add other text to the header."
  201. :group 'org-agenda-export
  202. :group 'org-export-html
  203. :type '(choice
  204. (const nil)
  205. (string)))
  206. (defcustom org-agenda-persistent-filter nil
  207. "When set, keep filters from one agenda view to the next."
  208. :group 'org-agenda
  209. :type 'boolean)
  210. (defgroup org-agenda-custom-commands nil
  211. "Options concerning agenda views in Org-mode."
  212. :tag "Org Agenda Custom Commands"
  213. :group 'org-agenda)
  214. (defconst org-sorting-choice
  215. '(choice
  216. (const time-up) (const time-down)
  217. (const timestamp-up) (const timestamp-down)
  218. (const scheduled-up) (const scheduled-down)
  219. (const deadline-up) (const deadline-down)
  220. (const ts-up) (const ts-down)
  221. (const tsia-up) (const tsia-down)
  222. (const category-keep) (const category-up) (const category-down)
  223. (const tag-down) (const tag-up)
  224. (const priority-up) (const priority-down)
  225. (const todo-state-up) (const todo-state-down)
  226. (const effort-up) (const effort-down)
  227. (const habit-up) (const habit-down)
  228. (const alpha-up) (const alpha-down)
  229. (const user-defined-up) (const user-defined-down))
  230. "Sorting choices.")
  231. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  232. ;; the new variable `org-agenda-tag-filter-preset'.
  233. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  234. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  235. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  236. "List of types searched for when creating the daily/weekly agenda.
  237. This variable is a list of symbols that controls the types of
  238. items that appear in the daily/weekly agenda. Allowed symbols in this
  239. list are are
  240. :timestamp List items containing a date stamp or date range matching
  241. the selected date. This includes sexp entries in angular
  242. brackets.
  243. :sexp List entries resulting from plain diary-like sexps.
  244. :deadline List deadline due on that date. When the date is today,
  245. also list any deadlines past due, or due within
  246. `org-deadline-warning-days'. `:deadline' must appear before
  247. `:scheduled' if the setting of
  248. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  249. any effect.
  250. :deadline* Same as above, but only include the deadline if it has an
  251. hour specification as [h]h:mm.
  252. :scheduled List all items which are scheduled for the given date.
  253. The diary for *today* also contains items which were
  254. scheduled earlier and are not yet marked DONE.
  255. :scheduled* Same as above, but only include the scheduled item if it
  256. has an hour specification as [h]h:mm.
  257. By default, all four non-starred types are turned on.
  258. When :scheduled* or :deadline* are included, :schedule or :deadline
  259. will be ignored.
  260. Never set this variable globally using `setq', because then it
  261. will apply to all future agenda commands. Instead, bind it with
  262. `let' to scope it dynamically into the agenda-constructing
  263. command. A good way to set it is through options in
  264. `org-agenda-custom-commands'. For a more flexible (though
  265. somewhat less efficient) way of determining what is included in
  266. the daily/weekly agenda, see `org-agenda-skip-function'.")
  267. (defconst org-agenda-custom-commands-local-options
  268. `(repeat :tag "Local settings for this command. Remember to quote values"
  269. (choice :tag "Setting"
  270. (list :tag "Heading for this block"
  271. (const org-agenda-overriding-header)
  272. (string :tag "Headline"))
  273. (list :tag "Files to be searched"
  274. (const org-agenda-files)
  275. (list
  276. (const :format "" quote)
  277. (repeat (file))))
  278. (list :tag "Sorting strategy"
  279. (const org-agenda-sorting-strategy)
  280. (list
  281. (const :format "" quote)
  282. (repeat
  283. ,org-sorting-choice)))
  284. (list :tag "Prefix format"
  285. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  286. (string))
  287. (list :tag "Number of days in agenda"
  288. (const org-agenda-span)
  289. (choice (const :tag "Day" day)
  290. (const :tag "Week" week)
  291. (const :tag "Fortnight" fortnight)
  292. (const :tag "Month" month)
  293. (const :tag "Year" year)
  294. (integer :tag "Custom")))
  295. (list :tag "Fixed starting date"
  296. (const org-agenda-start-day)
  297. (string :value "2007-11-01"))
  298. (list :tag "Start on day of week"
  299. (const org-agenda-start-on-weekday)
  300. (choice :value 1
  301. (const :tag "Today" nil)
  302. (integer :tag "Weekday No.")))
  303. (list :tag "Include data from diary"
  304. (const org-agenda-include-diary)
  305. (boolean))
  306. (list :tag "Deadline Warning days"
  307. (const org-deadline-warning-days)
  308. (integer :value 1))
  309. (list :tag "Category filter preset"
  310. (const org-agenda-category-filter-preset)
  311. (list
  312. (const :format "" quote)
  313. (repeat
  314. (string :tag "+category or -category"))))
  315. (list :tag "Tags filter preset"
  316. (const org-agenda-tag-filter-preset)
  317. (list
  318. (const :format "" quote)
  319. (repeat
  320. (string :tag "+tag or -tag"))))
  321. (list :tag "Effort filter preset"
  322. (const org-agenda-effort-filter-preset)
  323. (list
  324. (const :format "" quote)
  325. (repeat
  326. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  327. (list :tag "Regexp filter preset"
  328. (const org-agenda-regexp-filter-preset)
  329. (list
  330. (const :format "" quote)
  331. (repeat
  332. (string :tag "+regexp or -regexp"))))
  333. (list :tag "Set daily/weekly entry types"
  334. (const org-agenda-entry-types)
  335. (list
  336. (const :format "" quote)
  337. (set :greedy t :value ,org-agenda-entry-types
  338. (const :deadline)
  339. (const :scheduled)
  340. (const :deadline*)
  341. (const :scheduled*)
  342. (const :timestamp)
  343. (const :sexp))))
  344. (list :tag "Standard skipping condition"
  345. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  346. (const org-agenda-skip-function)
  347. (list
  348. (const :format "" quote)
  349. (list
  350. (choice
  351. :tag "Skipping range"
  352. (const :tag "Skip entry" org-agenda-skip-entry-if)
  353. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  354. (repeat :inline t :tag "Conditions for skipping"
  355. (choice
  356. :tag "Condition type"
  357. (list :tag "Regexp matches" :inline t
  358. (const :format "" 'regexp)
  359. (regexp))
  360. (list :tag "Regexp does not match" :inline t
  361. (const :format "" 'notregexp)
  362. (regexp))
  363. (list :tag "TODO state is" :inline t
  364. (const 'todo)
  365. (choice
  366. (const :tag "Any not-done state" 'todo)
  367. (const :tag "Any done state" 'done)
  368. (const :tag "Any state" 'any)
  369. (list :tag "Keyword list"
  370. (const :format "" quote)
  371. (repeat (string :tag "Keyword")))))
  372. (list :tag "TODO state is not" :inline t
  373. (const 'nottodo)
  374. (choice
  375. (const :tag "Any not-done state" 'todo)
  376. (const :tag "Any done state" 'done)
  377. (const :tag "Any state" 'any)
  378. (list :tag "Keyword list"
  379. (const :format "" quote)
  380. (repeat (string :tag "Keyword")))))
  381. (const :tag "scheduled" 'scheduled)
  382. (const :tag "not scheduled" 'notscheduled)
  383. (const :tag "deadline" 'deadline)
  384. (const :tag "no deadline" 'notdeadline)
  385. (const :tag "timestamp" 'timestamp)
  386. (const :tag "no timestamp" 'nottimestamp))))))
  387. (list :tag "Non-standard skipping condition"
  388. :value (org-agenda-skip-function)
  389. (const org-agenda-skip-function)
  390. (sexp :tag "Function or form (quoted!)"))
  391. (list :tag "Any variable"
  392. (variable :tag "Variable")
  393. (sexp :tag "Value (sexp)"))))
  394. "Selection of examples for agenda command settings.
  395. This will be spliced into the custom type of
  396. `org-agenda-custom-commands'.")
  397. (defcustom org-agenda-custom-commands
  398. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  399. "Custom commands for the agenda.
  400. These commands will be offered on the splash screen displayed by the
  401. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  402. (key desc type match settings files)
  403. key The key (one or more characters as a string) to be associated
  404. with the command.
  405. desc A description of the command, when omitted or nil, a default
  406. description is built using MATCH.
  407. type The command type, any of the following symbols:
  408. agenda The daily/weekly agenda.
  409. todo Entries with a specific TODO keyword, in all agenda files.
  410. search Entries containing search words entry or headline.
  411. tags Tags/Property/TODO match in all agenda files.
  412. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  413. todo-tree Sparse tree of specific TODO keyword in *current* file.
  414. tags-tree Sparse tree with all tags matches in *current* file.
  415. occur-tree Occur sparse tree for *current* file.
  416. ... A user-defined function.
  417. match What to search for:
  418. - a single keyword for TODO keyword searches
  419. - a tags match expression for tags searches
  420. - a word search expression for text searches.
  421. - a regular expression for occur searches
  422. For all other commands, this should be the empty string.
  423. settings A list of option settings, similar to that in a let form, so like
  424. this: ((opt1 val1) (opt2 val2) ...). The values will be
  425. evaluated at the moment of execution, so quote them when needed.
  426. files A list of files file to write the produced agenda buffer to
  427. with the command `org-store-agenda-views'.
  428. If a file name ends in \".html\", an HTML version of the buffer
  429. is written out. If it ends in \".ps\", a postscript version is
  430. produced. Otherwise, only the plain text is written to the file.
  431. You can also define a set of commands, to create a composite agenda buffer.
  432. In this case, an entry looks like this:
  433. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  434. where
  435. desc A description string to be displayed in the dispatcher menu.
  436. cmd An agenda command, similar to the above. However, tree commands
  437. are not allowed, but instead you can get agenda and global todo list.
  438. So valid commands for a set are:
  439. (agenda \"\" settings)
  440. (alltodo \"\" settings)
  441. (stuck \"\" settings)
  442. (todo \"match\" settings files)
  443. (search \"match\" settings files)
  444. (tags \"match\" settings files)
  445. (tags-todo \"match\" settings files)
  446. Each command can carry a list of options, and another set of options can be
  447. given for the whole set of commands. Individual command options take
  448. precedence over the general options.
  449. When using several characters as key to a command, the first characters
  450. are prefix commands. For the dispatcher to display useful information, you
  451. should provide a description for the prefix, like
  452. (setq org-agenda-custom-commands
  453. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  454. (\"hl\" tags \"+HOME+Lisa\")
  455. (\"hp\" tags \"+HOME+Peter\")
  456. (\"hk\" tags \"+HOME+Kim\")))"
  457. :group 'org-agenda-custom-commands
  458. :type `(repeat
  459. (choice :value ("x" "Describe command here" tags "" nil)
  460. (list :tag "Single command"
  461. (string :tag "Access Key(s) ")
  462. (option (string :tag "Description"))
  463. (choice
  464. (const :tag "Agenda" agenda)
  465. (const :tag "TODO list" alltodo)
  466. (const :tag "Search words" search)
  467. (const :tag "Stuck projects" stuck)
  468. (const :tag "Tags/Property match (all agenda files)" tags)
  469. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  470. (const :tag "TODO keyword search (all agenda files)" todo)
  471. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  472. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  473. (const :tag "Occur tree (current buffer)" occur-tree)
  474. (sexp :tag "Other, user-defined function"))
  475. (string :tag "Match (only for some commands)")
  476. ,org-agenda-custom-commands-local-options
  477. (option (repeat :tag "Export" (file :tag "Export to"))))
  478. (list :tag "Command series, all agenda files"
  479. (string :tag "Access Key(s)")
  480. (string :tag "Description ")
  481. (repeat :tag "Component"
  482. (choice
  483. (list :tag "Agenda"
  484. (const :format "" agenda)
  485. (const :tag "" :format "" "")
  486. ,org-agenda-custom-commands-local-options)
  487. (list :tag "TODO list (all keywords)"
  488. (const :format "" alltodo)
  489. (const :tag "" :format "" "")
  490. ,org-agenda-custom-commands-local-options)
  491. (list :tag "Search words"
  492. (const :format "" search)
  493. (string :tag "Match")
  494. ,org-agenda-custom-commands-local-options)
  495. (list :tag "Stuck projects"
  496. (const :format "" stuck)
  497. (const :tag "" :format "" "")
  498. ,org-agenda-custom-commands-local-options)
  499. (list :tag "Tags search"
  500. (const :format "" tags)
  501. (string :tag "Match")
  502. ,org-agenda-custom-commands-local-options)
  503. (list :tag "Tags search, TODO entries only"
  504. (const :format "" tags-todo)
  505. (string :tag "Match")
  506. ,org-agenda-custom-commands-local-options)
  507. (list :tag "TODO keyword search"
  508. (const :format "" todo)
  509. (string :tag "Match")
  510. ,org-agenda-custom-commands-local-options)
  511. (list :tag "Other, user-defined function"
  512. (symbol :tag "function")
  513. (string :tag "Match")
  514. ,org-agenda-custom-commands-local-options)))
  515. (repeat :tag "Settings for entire command set"
  516. (list (variable :tag "Any variable")
  517. (sexp :tag "Value")))
  518. (option (repeat :tag "Export" (file :tag "Export to"))))
  519. (cons :tag "Prefix key documentation"
  520. (string :tag "Access Key(s)")
  521. (string :tag "Description ")))))
  522. (defcustom org-agenda-query-register ?o
  523. "The register holding the current query string.
  524. The purpose of this is that if you construct a query string interactively,
  525. you can then use it to define a custom command."
  526. :group 'org-agenda-custom-commands
  527. :type 'character)
  528. (defcustom org-stuck-projects
  529. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  530. "How to identify stuck projects.
  531. This is a list of four items:
  532. 1. A tags/todo/property matcher string that is used to identify a project.
  533. See the manual for a description of tag and property searches.
  534. The entire tree below a headline matched by this is considered one project.
  535. 2. A list of TODO keywords identifying non-stuck projects.
  536. If the project subtree contains any headline with one of these todo
  537. keywords, the project is considered to be not stuck. If you specify
  538. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  539. 3. A list of tags identifying non-stuck projects.
  540. If the project subtree contains any headline with one of these tags,
  541. the project is considered to be not stuck. If you specify \"*\" as
  542. a tag, any tag will mark the project unstuck. Note that this is about
  543. the explicit presence of a tag somewhere in the subtree, inherited
  544. tags do not count here. If inherited tags make a project not stuck,
  545. use \"-TAG\" in the tags part of the matcher under (1.) above.
  546. 4. An arbitrary regular expression matching non-stuck projects.
  547. If the project turns out to be not stuck, search continues also in the
  548. subtree to see if any of the subtasks have project status.
  549. See also the variable `org-tags-match-list-sublevels' which applies
  550. to projects matched by this search as well.
  551. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  552. or `C-c a #' to produce the list."
  553. :group 'org-agenda-custom-commands
  554. :type '(list
  555. (string :tag "Tags/TODO match to identify a project")
  556. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  557. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  558. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  559. (defgroup org-agenda-skip nil
  560. "Options concerning skipping parts of agenda files."
  561. :tag "Org Agenda Skip"
  562. :group 'org-agenda)
  563. (defcustom org-agenda-skip-function-global nil
  564. "Function to be called at each match during agenda construction.
  565. If this function returns nil, the current match should not be skipped.
  566. If the function decided to skip an agenda match, is must return the
  567. buffer position from which the search should be continued.
  568. This may also be a Lisp form, which will be evaluated.
  569. This variable will be applied to every agenda match, including
  570. tags/property searches and TODO lists. So try to make the test function
  571. do its checking as efficiently as possible. To implement a skipping
  572. condition just for specific agenda commands, use the variable
  573. `org-agenda-skip-function' which can be set in the options section
  574. of custom agenda commands."
  575. :group 'org-agenda-skip
  576. :type 'sexp)
  577. (defgroup org-agenda-daily/weekly nil
  578. "Options concerning the daily/weekly agenda."
  579. :tag "Org Agenda Daily/Weekly"
  580. :group 'org-agenda)
  581. (defgroup org-agenda-todo-list nil
  582. "Options concerning the global todo list agenda view."
  583. :tag "Org Agenda Todo List"
  584. :group 'org-agenda)
  585. (defgroup org-agenda-match-view nil
  586. "Options concerning the general tags/property/todo match agenda view."
  587. :tag "Org Agenda Match View"
  588. :group 'org-agenda)
  589. (defgroup org-agenda-search-view nil
  590. "Options concerning the search agenda view."
  591. :tag "Org Agenda Search View"
  592. :group 'org-agenda)
  593. (defvar org-agenda-archives-mode nil
  594. "Non-nil means the agenda will include archived items.
  595. If this is the symbol `trees', trees in the selected agenda scope
  596. that are marked with the ARCHIVE tag will be included anyway. When this is
  597. t, also all archive files associated with the current selection of agenda
  598. files will be included.")
  599. (defcustom org-agenda-restriction-lock-highlight-subtree t
  600. "Non-nil means highlight the whole subtree when restriction is active.
  601. Otherwise only highlight the headline. Highlighting the whole subtree is
  602. useful to ensure no edits happen beyond the restricted region."
  603. :group 'org-agenda
  604. :type 'boolean)
  605. (defcustom org-agenda-skip-comment-trees t
  606. "Non-nil means skip trees that start with the COMMENT keyword.
  607. When nil, these trees are also scanned by agenda commands."
  608. :group 'org-agenda-skip
  609. :type 'boolean)
  610. (defcustom org-agenda-todo-list-sublevels t
  611. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  612. When nil, the sublevels of a TODO entry are not checked, resulting in
  613. potentially much shorter TODO lists."
  614. :group 'org-agenda-skip
  615. :group 'org-agenda-todo-list
  616. :type 'boolean)
  617. (defcustom org-agenda-todo-ignore-with-date nil
  618. "Non-nil means don't show entries with a date in the global todo list.
  619. You can use this if you prefer to mark mere appointments with a TODO keyword,
  620. but don't want them to show up in the TODO list.
  621. When this is set, it also covers deadlines and scheduled items, the settings
  622. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  623. will be ignored.
  624. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  625. :group 'org-agenda-skip
  626. :group 'org-agenda-todo-list
  627. :type 'boolean)
  628. (defcustom org-agenda-todo-ignore-timestamp nil
  629. "Non-nil means don't show entries with a timestamp.
  630. This applies when creating the global todo list.
  631. Valid values are:
  632. past Don't show entries for today or in the past.
  633. future Don't show entries with a timestamp in the future.
  634. The idea behind this is that if it has a future
  635. timestamp, you don't want to think about it until the
  636. date.
  637. all Don't show any entries with a timestamp in the global todo list.
  638. The idea behind this is that by setting a timestamp, you
  639. have already \"taken care\" of this item.
  640. This variable can also have an integer as a value. If positive (N),
  641. todos with a timestamp N or more days in the future will be ignored. If
  642. negative (-N), todos with a timestamp N or more days in the past will be
  643. ignored. If 0, todos with a timestamp either today or in the future will
  644. be ignored. For example, a value of -1 will exclude todos with a
  645. timestamp in the past (yesterday or earlier), while a value of 7 will
  646. exclude todos with a timestamp a week or more in the future.
  647. See also `org-agenda-todo-ignore-with-date'.
  648. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  649. to make his option also apply to the tags-todo list."
  650. :group 'org-agenda-skip
  651. :group 'org-agenda-todo-list
  652. :version "24.1"
  653. :type '(choice
  654. (const :tag "Ignore future timestamp todos" future)
  655. (const :tag "Ignore past or present timestamp todos" past)
  656. (const :tag "Ignore all timestamp todos" all)
  657. (const :tag "Show timestamp todos" nil)
  658. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  659. (defcustom org-agenda-todo-ignore-scheduled nil
  660. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  661. This applies when creating the global todo list.
  662. Valid values are:
  663. past Don't show entries scheduled today or in the past.
  664. future Don't show entries scheduled in the future.
  665. The idea behind this is that by scheduling it, you don't want to
  666. think about it until the scheduled date.
  667. all Don't show any scheduled entries in the global todo list.
  668. The idea behind this is that by scheduling it, you have already
  669. \"taken care\" of this item.
  670. t Same as `all', for backward compatibility.
  671. This variable can also have an integer as a value. See
  672. `org-agenda-todo-ignore-timestamp' for more details.
  673. See also `org-agenda-todo-ignore-with-date'.
  674. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  675. to make his option also apply to the tags-todo list."
  676. :group 'org-agenda-skip
  677. :group 'org-agenda-todo-list
  678. :type '(choice
  679. (const :tag "Ignore future-scheduled todos" future)
  680. (const :tag "Ignore past- or present-scheduled todos" past)
  681. (const :tag "Ignore all scheduled todos" all)
  682. (const :tag "Ignore all scheduled todos (compatibility)" t)
  683. (const :tag "Show scheduled todos" nil)
  684. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  685. (defcustom org-agenda-todo-ignore-deadlines nil
  686. "Non-nil means ignore some deadline TODO items when making TODO list.
  687. There are different motivations for using different values, please think
  688. carefully when configuring this variable.
  689. This applies when creating the global todo list.
  690. Valid values are:
  691. near Don't show near deadline entries. A deadline is near when it is
  692. closer than `org-deadline-warning-days' days. The idea behind this
  693. is that such items will appear in the agenda anyway.
  694. far Don't show TODO entries where a deadline has been defined, but
  695. the deadline is not near. This is useful if you don't want to
  696. use the todo list to figure out what to do now.
  697. past Don't show entries with a deadline timestamp for today or in the past.
  698. future Don't show entries with a deadline timestamp in the future, not even
  699. when they become `near' ones. Use it with caution.
  700. all Ignore all TODO entries that do have a deadline.
  701. t Same as `near', for backward compatibility.
  702. This variable can also have an integer as a value. See
  703. `org-agenda-todo-ignore-timestamp' for more details.
  704. See also `org-agenda-todo-ignore-with-date'.
  705. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  706. to make his option also apply to the tags-todo list."
  707. :group 'org-agenda-skip
  708. :group 'org-agenda-todo-list
  709. :type '(choice
  710. (const :tag "Ignore near deadlines" near)
  711. (const :tag "Ignore near deadlines (compatibility)" t)
  712. (const :tag "Ignore far deadlines" far)
  713. (const :tag "Ignore all TODOs with a deadlines" all)
  714. (const :tag "Show all TODOs, even if they have a deadline" nil)
  715. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  716. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  717. "Time unit to use when possibly ignoring an agenda item.
  718. See the docstring of various `org-agenda-todo-ignore-*' options.
  719. The default is to compare time stamps using days. An item is thus
  720. considered to be in the future if it is at least one day after today.
  721. Non-nil means to compare time stamps using seconds. An item is then
  722. considered future if it has a time value later than current time."
  723. :group 'org-agenda-skip
  724. :group 'org-agenda-todo-list
  725. :version "24.4"
  726. :package-version '(Org . "8.0")
  727. :type '(choice
  728. (const :tag "Compare time with days" nil)
  729. (const :tag "Compare time with seconds" t)))
  730. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  731. "Non-nil means honor todo-list ignores options also in tags-todo search.
  732. The variables
  733. `org-agenda-todo-ignore-with-date',
  734. `org-agenda-todo-ignore-timestamp',
  735. `org-agenda-todo-ignore-scheduled',
  736. `org-agenda-todo-ignore-deadlines'
  737. make the global TODO list skip entries that have time stamps of certain
  738. kinds. If this option is set, the same options will also apply for the
  739. tags-todo search, which is the general tags/property matcher
  740. restricted to unfinished TODO entries only."
  741. :group 'org-agenda-skip
  742. :group 'org-agenda-todo-list
  743. :group 'org-agenda-match-view
  744. :type 'boolean)
  745. (defcustom org-agenda-skip-scheduled-if-done nil
  746. "Non-nil means don't show scheduled items in agenda when they are done.
  747. This is relevant for the daily/weekly agenda, not for the TODO list. And
  748. it applies only to the actual date of the scheduling. Warnings about
  749. an item with a past scheduling dates are always turned off when the item
  750. is DONE."
  751. :group 'org-agenda-skip
  752. :group 'org-agenda-daily/weekly
  753. :type 'boolean)
  754. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  755. "Non-nil means skip scheduling line if same entry shows because of deadline.
  756. In the agenda of today, an entry can show up multiple times
  757. because it is both scheduled and has a nearby deadline, and maybe
  758. a plain time stamp as well.
  759. When this variable is nil, the entry will be shown several times.
  760. When set to t, then only the deadline is shown and the fact that
  761. the entry is scheduled today or was scheduled previously is not
  762. shown.
  763. When set to the symbol `not-today', skip scheduled previously,
  764. but not scheduled today.
  765. When set to the symbol `repeated-after-deadline', skip scheduled
  766. items if they are repeated beyond the current deadline."
  767. :group 'org-agenda-skip
  768. :group 'org-agenda-daily/weekly
  769. :type '(choice
  770. (const :tag "Never" nil)
  771. (const :tag "Always" t)
  772. (const :tag "Not when scheduled today" not-today)
  773. (const :tag "When repeated past deadline" repeated-after-deadline)))
  774. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  775. "Non-nil means skip timestamp line if same entry shows because of deadline.
  776. In the agenda of today, an entry can show up multiple times
  777. because it has both a plain timestamp and has a nearby deadline.
  778. When this variable is t, then only the deadline is shown and the
  779. fact that the entry has a timestamp for or including today is not
  780. shown. When this variable is nil, the entry will be shown
  781. several times."
  782. :group 'org-agenda-skip
  783. :group 'org-agenda-daily/weekly
  784. :version "24.1"
  785. :type '(choice
  786. (const :tag "Never" nil)
  787. (const :tag "Always" t)))
  788. (defcustom org-agenda-skip-deadline-if-done nil
  789. "Non-nil means don't show deadlines when the corresponding item is done.
  790. When nil, the deadline is still shown and should give you a happy feeling.
  791. This is relevant for the daily/weekly agenda. And it applied only to the
  792. actually date of the deadline. Warnings about approaching and past-due
  793. deadlines are always turned off when the item is DONE."
  794. :group 'org-agenda-skip
  795. :group 'org-agenda-daily/weekly
  796. :type 'boolean)
  797. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  798. "Non-nil means skip deadline prewarning when entry is also scheduled.
  799. This will apply on all days where a prewarning for the deadline would
  800. be shown, but not at the day when the entry is actually due. On that day,
  801. the deadline will be shown anyway.
  802. This variable may be set to nil, t, the symbol `pre-scheduled',
  803. or a number which will then give the number of days before the actual
  804. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  805. eliminates the deadline prewarning only prior to the scheduled date.
  806. This can be used in a workflow where the first showing of the deadline will
  807. trigger you to schedule it, and then you don't want to be reminded of it
  808. because you will take care of it on the day when scheduled."
  809. :group 'org-agenda-skip
  810. :group 'org-agenda-daily/weekly
  811. :version "24.1"
  812. :type '(choice
  813. (const :tag "Always show prewarning" nil)
  814. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  815. (const :tag "Remove prewarning if entry is scheduled" t)
  816. (integer :tag "Restart prewarning N days before deadline")))
  817. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  818. "Non-nil means skip scheduled delay when entry also has a deadline.
  819. This variable may be set to nil, t, the symbol `post-deadline',
  820. or a number which will then give the number of days after the actual
  821. scheduled date when the delay should expire. The symbol `post-deadline'
  822. eliminates the schedule delay when the date is posterior to the deadline."
  823. :group 'org-agenda-skip
  824. :group 'org-agenda-daily/weekly
  825. :version "24.4"
  826. :package-version '(Org . "8.0")
  827. :type '(choice
  828. (const :tag "Always honor delay" nil)
  829. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  830. (const :tag "Ignore delay if entry has a deadline" t)
  831. (integer :tag "Honor delay up until N days after the scheduled date")))
  832. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  833. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  834. When non-nil, after the search for timestamps has matched once in an
  835. entry, the rest of the entry will not be searched."
  836. :group 'org-agenda-skip
  837. :type 'boolean)
  838. (defcustom org-agenda-skip-timestamp-if-done nil
  839. "Non-nil means don't select item by timestamp or -range if it is DONE."
  840. :group 'org-agenda-skip
  841. :group 'org-agenda-daily/weekly
  842. :type 'boolean)
  843. (defcustom org-agenda-dim-blocked-tasks t
  844. "Non-nil means dim blocked tasks in the agenda display.
  845. This causes some overhead during agenda construction, but if you
  846. have turned on `org-enforce-todo-dependencies',
  847. `org-enforce-todo-checkbox-dependencies', or any other blocking
  848. mechanism, this will create useful feedback in the agenda.
  849. Instead of t, this variable can also have the value `invisible'.
  850. Then blocked tasks will be invisible and only become visible when
  851. they become unblocked. An exemption to this behavior is when a task is
  852. blocked because of unchecked checkboxes below it. Since checkboxes do
  853. not show up in the agenda views, making this task invisible you remove any
  854. trace from agenda views that there is something to do. Therefore, a task
  855. that is blocked because of checkboxes will never be made invisible, it
  856. will only be dimmed."
  857. :group 'org-agenda-daily/weekly
  858. :group 'org-agenda-todo-list
  859. :version "24.3"
  860. :type '(choice
  861. (const :tag "Do not dim" nil)
  862. (const :tag "Dim to a gray face" t)
  863. (const :tag "Make invisible" invisible)))
  864. (defcustom org-timeline-show-empty-dates 3
  865. "Non-nil means `org-timeline' also shows dates without an entry.
  866. When nil, only the days which actually have entries are shown.
  867. When t, all days between the first and the last date are shown.
  868. When an integer, show also empty dates, but if there is a gap of more than
  869. N days, just insert a special line indicating the size of the gap."
  870. :group 'org-agenda-skip
  871. :type '(choice
  872. (const :tag "None" nil)
  873. (const :tag "All" t)
  874. (integer :tag "at most")))
  875. (defgroup org-agenda-startup nil
  876. "Options concerning initial settings in the Agenda in Org Mode."
  877. :tag "Org Agenda Startup"
  878. :group 'org-agenda)
  879. (defcustom org-agenda-menu-show-matcher t
  880. "Non-nil means show the match string in the agenda dispatcher menu.
  881. When nil, the matcher string is not shown, but is put into the help-echo
  882. property so than moving the mouse over the command shows it.
  883. Setting it to nil is good if matcher strings are very long and/or if
  884. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  885. :group 'org-agenda
  886. :version "24.1"
  887. :type 'boolean)
  888. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  889. (defcustom org-agenda-menu-two-columns nil
  890. "Non-nil means, use two columns to show custom commands in the dispatcher.
  891. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  892. to nil."
  893. :group 'org-agenda
  894. :version "24.1"
  895. :type 'boolean)
  896. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  897. (defcustom org-agenda-finalize-hook nil
  898. "Hook run just before displaying an agenda buffer.
  899. The buffer is still writable when the hook is called.
  900. You can modify some of the buffer substrings but you should be
  901. extra careful not to modify the text properties of the agenda
  902. headlines as the agenda display heavily relies on them."
  903. :group 'org-agenda-startup
  904. :type 'hook)
  905. (defcustom org-agenda-mouse-1-follows-link nil
  906. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  907. A longer mouse click will still set point. Does not work on XEmacs.
  908. Needs to be set before org.el is loaded."
  909. :group 'org-agenda-startup
  910. :type 'boolean)
  911. (defcustom org-agenda-start-with-follow-mode nil
  912. "The initial value of follow mode in a newly created agenda window."
  913. :group 'org-agenda-startup
  914. :type 'boolean)
  915. (defcustom org-agenda-follow-indirect nil
  916. "Non-nil means `org-agenda-follow-mode' displays only the
  917. current item's tree, in an indirect buffer."
  918. :group 'org-agenda
  919. :version "24.1"
  920. :type 'boolean)
  921. (defcustom org-agenda-show-outline-path t
  922. "Non-nil means show outline path in echo area after line motion."
  923. :group 'org-agenda-startup
  924. :type 'boolean)
  925. (defcustom org-agenda-start-with-entry-text-mode nil
  926. "The initial value of entry-text-mode in a newly created agenda window."
  927. :group 'org-agenda-startup
  928. :type 'boolean)
  929. (defcustom org-agenda-entry-text-maxlines 5
  930. "Number of text lines to be added when `E' is pressed in the agenda.
  931. Note that this variable only used during agenda display. Add add entry text
  932. when exporting the agenda, configure the variable
  933. `org-agenda-add-entry-ext-maxlines'."
  934. :group 'org-agenda
  935. :type 'integer)
  936. (defcustom org-agenda-entry-text-exclude-regexps nil
  937. "List of regular expressions to clean up entry text.
  938. The complete matches of all regular expressions in this list will be
  939. removed from entry text before it is shown in the agenda."
  940. :group 'org-agenda
  941. :type '(repeat (regexp)))
  942. (defcustom org-agenda-entry-text-leaders " > "
  943. "Text prepended to the entry text in agenda buffers."
  944. :version "24.4"
  945. :package-version '(Org . "8.0")
  946. :group 'org-agenda
  947. :type 'string)
  948. (defvar org-agenda-entry-text-cleanup-hook nil
  949. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  950. This cleanup is done in a temporary buffer, so the function may inspect and
  951. change the entire buffer.
  952. Some default stuff like drawers and scheduling/deadline dates will already
  953. have been removed when this is called, as will any matches for regular
  954. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  955. (defvar org-agenda-include-inactive-timestamps nil
  956. "Non-nil means include inactive time stamps in agenda and timeline.
  957. Dynamically scoped.")
  958. (defgroup org-agenda-windows nil
  959. "Options concerning the windows used by the Agenda in Org Mode."
  960. :tag "Org Agenda Windows"
  961. :group 'org-agenda)
  962. (defcustom org-agenda-window-setup 'reorganize-frame
  963. "How the agenda buffer should be displayed.
  964. Possible values for this option are:
  965. current-window Show agenda in the current window, keeping all other windows.
  966. other-window Use `switch-to-buffer-other-window' to display agenda.
  967. reorganize-frame Show only two windows on the current frame, the current
  968. window and the agenda.
  969. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  970. Also, when exiting the agenda, kill that frame.
  971. See also the variable `org-agenda-restore-windows-after-quit'."
  972. :group 'org-agenda-windows
  973. :type '(choice
  974. (const current-window)
  975. (const other-frame)
  976. (const other-window)
  977. (const reorganize-frame)))
  978. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  979. "The min and max height of the agenda window as a fraction of frame height.
  980. The value of the variable is a cons cell with two numbers between 0 and 1.
  981. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  982. :group 'org-agenda-windows
  983. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  984. (defcustom org-agenda-restore-windows-after-quit nil
  985. "Non-nil means restore window configuration upon exiting agenda.
  986. Before the window configuration is changed for displaying the agenda,
  987. the current status is recorded. When the agenda is exited with
  988. `q' or `x' and this option is set, the old state is restored. If
  989. `org-agenda-window-setup' is `other-frame', the value of this
  990. option will be ignored."
  991. :group 'org-agenda-windows
  992. :type 'boolean)
  993. (defcustom org-agenda-ndays nil
  994. "Number of days to include in overview display.
  995. Should be 1 or 7.
  996. Obsolete, see `org-agenda-span'."
  997. :group 'org-agenda-daily/weekly
  998. :type '(choice (const nil)
  999. (integer)))
  1000. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  1001. (defcustom org-agenda-span 'week
  1002. "Number of days to include in overview display.
  1003. Can be day, week, month, year, or any number of days.
  1004. Custom commands can set this variable in the options section."
  1005. :group 'org-agenda-daily/weekly
  1006. :type '(choice (const :tag "Day" day)
  1007. (const :tag "Week" week)
  1008. (const :tag "Fortnight" fortnight)
  1009. (const :tag "Month" month)
  1010. (const :tag "Year" year)
  1011. (integer :tag "Custom")))
  1012. (defcustom org-agenda-start-on-weekday 1
  1013. "Non-nil means start the overview always on the specified weekday.
  1014. 0 denotes Sunday, 1 denotes Monday, etc.
  1015. When nil, always start on the current day.
  1016. Custom commands can set this variable in the options section."
  1017. :group 'org-agenda-daily/weekly
  1018. :type '(choice (const :tag "Today" nil)
  1019. (integer :tag "Weekday No.")))
  1020. (defcustom org-agenda-show-all-dates t
  1021. "Non-nil means `org-agenda' shows every day in the selected range.
  1022. When nil, only the days which actually have entries are shown."
  1023. :group 'org-agenda-daily/weekly
  1024. :type 'boolean)
  1025. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1026. "Format string for displaying dates in the agenda.
  1027. Used by the daily/weekly agenda and by the timeline. This should be
  1028. a format string understood by `format-time-string', or a function returning
  1029. the formatted date as a string. The function must take a single argument,
  1030. a calendar-style date list like (month day year)."
  1031. :group 'org-agenda-daily/weekly
  1032. :type '(choice
  1033. (string :tag "Format string")
  1034. (function :tag "Function")))
  1035. (defun org-agenda-format-date-aligned (date)
  1036. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1037. This function makes sure that dates are aligned for easy reading."
  1038. (require 'cal-iso)
  1039. (let* ((dayname (calendar-day-name date))
  1040. (day (cadr date))
  1041. (day-of-week (calendar-day-of-week date))
  1042. (month (car date))
  1043. (monthname (calendar-month-name month))
  1044. (year (nth 2 date))
  1045. (iso-week (org-days-to-iso-week
  1046. (calendar-absolute-from-gregorian date)))
  1047. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1048. (1- year))
  1049. ((and (= month 12) (<= iso-week 1))
  1050. (1+ year))
  1051. (t year)))
  1052. (weekstring (if (= day-of-week 1)
  1053. (format " W%02d" iso-week)
  1054. "")))
  1055. (format "%-10s %2d %s %4d%s"
  1056. dayname day monthname year weekstring)))
  1057. (defcustom org-agenda-time-leading-zero nil
  1058. "Non-nil means use leading zero for military times in agenda.
  1059. For example, 9:30am would become 09:30 rather than 9:30."
  1060. :group 'org-agenda-daily/weekly
  1061. :version "24.1"
  1062. :type 'boolean)
  1063. (defcustom org-agenda-timegrid-use-ampm nil
  1064. "When set, show AM/PM style timestamps on the timegrid."
  1065. :group 'org-agenda
  1066. :version "24.1"
  1067. :type 'boolean)
  1068. (defun org-agenda-time-of-day-to-ampm (time)
  1069. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1070. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1071. (minute (substring time -2))
  1072. (ampm "am"))
  1073. (cond
  1074. ((equal hour-number 12)
  1075. (setq ampm "pm"))
  1076. ((> hour-number 12)
  1077. (setq ampm "pm")
  1078. (setq hour-number (- hour-number 12))))
  1079. (concat
  1080. (if org-agenda-time-leading-zero
  1081. (format "%02d" hour-number)
  1082. (format "%02s" (number-to-string hour-number)))
  1083. ":" minute ampm)))
  1084. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1085. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1086. (if org-agenda-timegrid-use-ampm
  1087. (org-agenda-time-of-day-to-ampm time)
  1088. time))
  1089. (defcustom org-agenda-weekend-days '(6 0)
  1090. "Which days are weekend?
  1091. These days get the special face `org-agenda-date-weekend' in the agenda
  1092. and timeline buffers."
  1093. :group 'org-agenda-daily/weekly
  1094. :type '(set :greedy t
  1095. (const :tag "Monday" 1)
  1096. (const :tag "Tuesday" 2)
  1097. (const :tag "Wednesday" 3)
  1098. (const :tag "Thursday" 4)
  1099. (const :tag "Friday" 5)
  1100. (const :tag "Saturday" 6)
  1101. (const :tag "Sunday" 0)))
  1102. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1103. "Non-nil means jump to today when moving a past date forward in time.
  1104. When using S-right in the agenda to move a a date forward, and the date
  1105. stamp currently points to the past, the first key press will move it
  1106. to today. WHen nil, just move one day forward even if the date stays
  1107. in the past."
  1108. :group 'org-agenda-daily/weekly
  1109. :version "24.1"
  1110. :type 'boolean)
  1111. (defcustom org-agenda-include-diary nil
  1112. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1113. Custom commands can set this variable in the options section."
  1114. :group 'org-agenda-daily/weekly
  1115. :type 'boolean)
  1116. (defcustom org-agenda-include-deadlines t
  1117. "If non-nil, include entries within their deadline warning period.
  1118. Custom commands can set this variable in the options section."
  1119. :group 'org-agenda-daily/weekly
  1120. :version "24.1"
  1121. :type 'boolean)
  1122. (defcustom org-agenda-repeating-timestamp-show-all t
  1123. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1124. When set to a list of strings, only show occurrences of repeating
  1125. stamps for these TODO keywords. When nil, only one occurrence is
  1126. shown, either today or the nearest into the future."
  1127. :group 'org-agenda-daily/weekly
  1128. :type '(choice
  1129. (const :tag "Show repeating stamps" t)
  1130. (repeat :tag "Show repeating stamps for these TODO keywords"
  1131. (string :tag "TODO Keyword"))
  1132. (const :tag "Don't show repeating stamps" nil)))
  1133. (defcustom org-scheduled-past-days 10000
  1134. "Number of days to continue listing scheduled items not marked DONE.
  1135. When an item is scheduled on a date, it shows up in the agenda on this
  1136. day and will be listed until it is marked done for the number of days
  1137. given here."
  1138. :group 'org-agenda-daily/weekly
  1139. :type 'integer)
  1140. (defcustom org-agenda-log-mode-items '(closed clock)
  1141. "List of items that should be shown in agenda log mode.
  1142. This list may contain the following symbols:
  1143. closed Show entries that have been closed on that day.
  1144. clock Show entries that have received clocked time on that day.
  1145. state Show all logged state changes.
  1146. Note that instead of changing this variable, you can also press `C-u l' in
  1147. the agenda to display all available LOG items temporarily."
  1148. :group 'org-agenda-daily/weekly
  1149. :type '(set :greedy t (const closed) (const clock) (const state)))
  1150. (defcustom org-agenda-clock-consistency-checks
  1151. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1152. :gap-ok-around ("4:00")
  1153. :default-face ((:background "DarkRed") (:foreground "white"))
  1154. :overlap-face nil :gap-face nil :no-end-time-face nil
  1155. :long-face nil :short-face nil)
  1156. "This is a property list, with the following keys:
  1157. :max-duration Mark clocking chunks that are longer than this time.
  1158. This is a time string like \"HH:MM\", or the number
  1159. of minutes as an integer.
  1160. :min-duration Mark clocking chunks that are shorter that this.
  1161. This is a time string like \"HH:MM\", or the number
  1162. of minutes as an integer.
  1163. :max-gap Mark gaps between clocking chunks that are longer than
  1164. this duration. A number of minutes, or a string
  1165. like \"HH:MM\".
  1166. :gap-ok-around List of times during the day which are usually not working
  1167. times. When a gap is detected, but the gap contains any
  1168. of these times, the gap is *not* reported. For example,
  1169. if this is (\"4:00\" \"13:00\") then gaps that contain
  1170. 4:00 in the morning (i.e. the night) and 13:00
  1171. (i.e. a typical lunch time) do not cause a warning.
  1172. You should have at least one time during the night in this
  1173. list, or otherwise the first task each morning will trigger
  1174. a warning because it follows a long gap.
  1175. Furthermore, the following properties can be used to define faces for
  1176. issue display.
  1177. :default-face the default face, if the specific face is undefined
  1178. :overlap-face face for overlapping clocks
  1179. :gap-face face for gaps between clocks
  1180. :no-end-time-face face for incomplete clocks
  1181. :long-face face for clock intervals that are too long
  1182. :short-face face for clock intervals that are too short"
  1183. :group 'org-agenda-daily/weekly
  1184. :group 'org-clock
  1185. :version "24.1"
  1186. :type 'plist)
  1187. (defcustom org-agenda-log-mode-add-notes t
  1188. "Non-nil means add first line of notes to log entries in agenda views.
  1189. If a log item like a state change or a clock entry is associated with
  1190. notes, the first line of these notes will be added to the entry in the
  1191. agenda display."
  1192. :group 'org-agenda-daily/weekly
  1193. :type 'boolean)
  1194. (defcustom org-agenda-start-with-log-mode nil
  1195. "The initial value of log-mode in a newly created agenda window.
  1196. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1197. explanations on the possible values."
  1198. :group 'org-agenda-startup
  1199. :group 'org-agenda-daily/weekly
  1200. :type '(choice (const :tag "Don't show log items" nil)
  1201. (const :tag "Show only log items" only)
  1202. (const :tag "Show all possible log items" clockcheck)
  1203. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1204. (choice (const :tag "Show closed log items" closed)
  1205. (const :tag "Show clocked log items" clock)
  1206. (const :tag "Show all logged state changes" state)))))
  1207. (defcustom org-agenda-start-with-clockreport-mode nil
  1208. "The initial value of clockreport-mode in a newly created agenda window."
  1209. :group 'org-agenda-startup
  1210. :group 'org-agenda-daily/weekly
  1211. :type 'boolean)
  1212. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1213. "Property list with parameters for the clocktable in clockreport mode.
  1214. This is the display mode that shows a clock table in the daily/weekly
  1215. agenda, the properties for this dynamic block can be set here.
  1216. The usual clocktable parameters are allowed here, but you cannot set
  1217. the properties :name, :tstart, :tend, :block, and :scope - these will
  1218. be overwritten to make sure the content accurately reflects the
  1219. current display in the agenda."
  1220. :group 'org-agenda-daily/weekly
  1221. :type 'plist)
  1222. (defcustom org-agenda-search-view-always-boolean nil
  1223. "Non-nil means the search string is interpreted as individual parts.
  1224. The search string for search view can either be interpreted as a phrase,
  1225. or as a list of snippets that define a boolean search for a number of
  1226. strings.
  1227. When this is non-nil, the string will be split on whitespace, and each
  1228. snippet will be searched individually, and all must match in order to
  1229. select an entry. A snippet is then a single string of non-white
  1230. characters, or a string in double quotes, or a regexp in {} braces.
  1231. If a snippet is preceded by \"-\", the snippet must *not* match.
  1232. \"+\" is syntactic sugar for positive selection. Each snippet may
  1233. be found as a full word or a partial word, but see the variable
  1234. `org-agenda-search-view-force-full-words'.
  1235. When this is nil, search will look for the entire search phrase as one,
  1236. with each space character matching any amount of whitespace, including
  1237. line breaks.
  1238. Even when this is nil, you can still switch to Boolean search dynamically
  1239. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1240. is a regexp marked with braces like \"{abc}\", this will also switch to
  1241. boolean search."
  1242. :group 'org-agenda-search-view
  1243. :version "24.1"
  1244. :type 'boolean)
  1245. (org-defvaralias 'org-agenda-search-view-search-words-only
  1246. 'org-agenda-search-view-always-boolean)
  1247. (defcustom org-agenda-search-view-force-full-words nil
  1248. "Non-nil means, search words must be matches as complete words.
  1249. When nil, they may also match part of a word."
  1250. :group 'org-agenda-search-view
  1251. :version "24.1"
  1252. :type 'boolean)
  1253. (defcustom org-agenda-search-view-max-outline-level 0
  1254. "Maximum outline level to display in search view.
  1255. E.g. when this is set to 1, the search view will only
  1256. show headlines of level 1. When set to 0, the default
  1257. value, don't limit agenda view by outline level."
  1258. :group 'org-agenda-search-view
  1259. :version "24.4"
  1260. :package-version '(Org . "8.3")
  1261. :type 'integer)
  1262. (defgroup org-agenda-time-grid nil
  1263. "Options concerning the time grid in the Org-mode Agenda."
  1264. :tag "Org Agenda Time Grid"
  1265. :group 'org-agenda)
  1266. (defcustom org-agenda-search-headline-for-time t
  1267. "Non-nil means search headline for a time-of-day.
  1268. If the headline contains a time-of-day in one format or another, it will
  1269. be used to sort the entry into the time sequence of items for a day.
  1270. Some people have time stamps in the headline that refer to the creation
  1271. time or so, and then this produces an unwanted side effect. If this is
  1272. the case for your, use this variable to turn off searching the headline
  1273. for a time."
  1274. :group 'org-agenda-time-grid
  1275. :type 'boolean)
  1276. (defcustom org-agenda-use-time-grid t
  1277. "Non-nil means show a time grid in the agenda schedule.
  1278. A time grid is a set of lines for specific times (like every two hours between
  1279. 8:00 and 20:00). The items scheduled for a day at specific times are
  1280. sorted in between these lines.
  1281. For details about when the grid will be shown, and what it will look like, see
  1282. the variable `org-agenda-time-grid'."
  1283. :group 'org-agenda-time-grid
  1284. :type 'boolean)
  1285. (defcustom org-agenda-time-grid
  1286. '((daily today require-timed)
  1287. "----------------"
  1288. (800 1000 1200 1400 1600 1800 2000))
  1289. "The settings for time grid for agenda display.
  1290. This is a list of three items. The first item is again a list. It contains
  1291. symbols specifying conditions when the grid should be displayed:
  1292. daily if the agenda shows a single day
  1293. weekly if the agenda shows an entire week
  1294. today show grid on current date, independent of daily/weekly display
  1295. require-timed show grid only if at least one item has a time specification
  1296. The second item is a string which will be placed behind the grid time.
  1297. The third item is a list of integers, indicating the times that should have
  1298. a grid line."
  1299. :group 'org-agenda-time-grid
  1300. :type
  1301. '(list
  1302. (set :greedy t :tag "Grid Display Options"
  1303. (const :tag "Show grid in single day agenda display" daily)
  1304. (const :tag "Show grid in weekly agenda display" weekly)
  1305. (const :tag "Always show grid for today" today)
  1306. (const :tag "Show grid only if any timed entries are present"
  1307. require-timed)
  1308. (const :tag "Skip grid times already present in an entry"
  1309. remove-match))
  1310. (string :tag "Grid String")
  1311. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1312. (defcustom org-agenda-show-current-time-in-grid t
  1313. "Non-nil means show the current time in the time grid."
  1314. :group 'org-agenda-time-grid
  1315. :version "24.1"
  1316. :type 'boolean)
  1317. (defcustom org-agenda-current-time-string
  1318. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1319. "The string for the current time marker in the agenda."
  1320. :group 'org-agenda-time-grid
  1321. :version "24.1"
  1322. :type 'string)
  1323. (defgroup org-agenda-sorting nil
  1324. "Options concerning sorting in the Org-mode Agenda."
  1325. :tag "Org Agenda Sorting"
  1326. :group 'org-agenda)
  1327. (defcustom org-agenda-sorting-strategy
  1328. '((agenda habit-down time-up priority-down category-keep)
  1329. (todo priority-down category-keep)
  1330. (tags priority-down category-keep)
  1331. (search category-keep))
  1332. "Sorting structure for the agenda items of a single day.
  1333. This is a list of symbols which will be used in sequence to determine
  1334. if an entry should be listed before another entry. The following
  1335. symbols are recognized:
  1336. time-up Put entries with time-of-day indications first, early first
  1337. time-down Put entries with time-of-day indications first, late first
  1338. timestamp-up Sort by any timestamp, early first
  1339. timestamp-down Sort by any timestamp, late first
  1340. scheduled-up Sort by scheduled timestamp, early first
  1341. scheduled-down Sort by scheduled timestamp, late first
  1342. deadline-up Sort by deadline timestamp, early first
  1343. deadline-down Sort by deadline timestamp, late first
  1344. ts-up Sort by active timestamp, early first
  1345. ts-down Sort by active timestamp, late first
  1346. tsia-up Sort by inactive timestamp, early first
  1347. tsia-down Sort by inactive timestamp, late first
  1348. category-keep Keep the default order of categories, corresponding to the
  1349. sequence in `org-agenda-files'.
  1350. category-up Sort alphabetically by category, A-Z.
  1351. category-down Sort alphabetically by category, Z-A.
  1352. tag-up Sort alphabetically by last tag, A-Z.
  1353. tag-down Sort alphabetically by last tag, Z-A.
  1354. priority-up Sort numerically by priority, high priority last.
  1355. priority-down Sort numerically by priority, high priority first.
  1356. todo-state-up Sort by todo state, tasks that are done last.
  1357. todo-state-down Sort by todo state, tasks that are done first.
  1358. effort-up Sort numerically by estimated effort, high effort last.
  1359. effort-down Sort numerically by estimated effort, high effort first.
  1360. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1361. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1362. habit-up Put entries that are habits first
  1363. habit-down Put entries that are habits last
  1364. alpha-up Sort headlines alphabetically
  1365. alpha-down Sort headlines alphabetically, reversed
  1366. The different possibilities will be tried in sequence, and testing stops
  1367. if one comparison returns a \"not-equal\". For example, the default
  1368. '(time-up category-keep priority-down)
  1369. means: Pull out all entries having a specified time of day and sort them,
  1370. in order to make a time schedule for the current day the first thing in the
  1371. agenda listing for the day. Of the entries without a time indication, keep
  1372. the grouped in categories, don't sort the categories, but keep them in
  1373. the sequence given in `org-agenda-files'. Within each category sort by
  1374. priority.
  1375. Leaving out `category-keep' would mean that items will be sorted across
  1376. categories by priority.
  1377. Instead of a single list, this can also be a set of list for specific
  1378. contents, with a context symbol in the car of the list, any of
  1379. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1380. Custom commands can bind this variable in the options section."
  1381. :group 'org-agenda-sorting
  1382. :type `(choice
  1383. (repeat :tag "General" ,org-sorting-choice)
  1384. (list :tag "Individually"
  1385. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1386. (repeat ,org-sorting-choice))
  1387. (cons (const :tag "Strategy for TODO lists" todo)
  1388. (repeat ,org-sorting-choice))
  1389. (cons (const :tag "Strategy for Tags matches" tags)
  1390. (repeat ,org-sorting-choice))
  1391. (cons (const :tag "Strategy for search matches" search)
  1392. (repeat ,org-sorting-choice)))))
  1393. (defcustom org-agenda-cmp-user-defined nil
  1394. "A function to define the comparison `user-defined'.
  1395. This function must receive two arguments, agenda entry a and b.
  1396. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1397. the user comparison, return nil.
  1398. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1399. part of an agenda sorting strategy."
  1400. :group 'org-agenda-sorting
  1401. :type 'symbol)
  1402. (defcustom org-sort-agenda-notime-is-late t
  1403. "Non-nil means items without time are considered late.
  1404. This is only relevant for sorting. When t, items which have no explicit
  1405. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1406. do have a time. When nil, the default time is before 0:00. You can use this
  1407. option to decide if the schedule for today should come before or after timeless
  1408. agenda entries."
  1409. :group 'org-agenda-sorting
  1410. :type 'boolean)
  1411. (defcustom org-sort-agenda-noeffort-is-high t
  1412. "Non-nil means items without effort estimate are sorted as high effort.
  1413. This also applies when filtering an agenda view with respect to the
  1414. < or > effort operator. Then, tasks with no effort defined will be treated
  1415. as tasks with high effort.
  1416. When nil, such items are sorted as 0 minutes effort."
  1417. :group 'org-agenda-sorting
  1418. :type 'boolean)
  1419. (defgroup org-agenda-line-format nil
  1420. "Options concerning the entry prefix in the Org-mode agenda display."
  1421. :tag "Org Agenda Line Format"
  1422. :group 'org-agenda)
  1423. (defcustom org-agenda-prefix-format
  1424. '((agenda . " %i %-12:c%?-12t% s")
  1425. (timeline . " % s")
  1426. (todo . " %i %-12:c")
  1427. (tags . " %i %-12:c")
  1428. (search . " %i %-12:c"))
  1429. "Format specifications for the prefix of items in the agenda views.
  1430. An alist with five entries, each for the different agenda types. The
  1431. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1432. The values are format strings.
  1433. This format works similar to a printf format, with the following meaning:
  1434. %c the category of the item, \"Diary\" for entries from the diary,
  1435. or as given by the CATEGORY keyword or derived from the file name
  1436. %e the effort required by the item
  1437. %l the level of the item (insert X space(s) if item is of level X)
  1438. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1439. %T the last tag of the item (ignore inherited tags, which come first)
  1440. %t the HH:MM time-of-day specification if one applies to the entry
  1441. %s Scheduling/Deadline information, a short string
  1442. %b show breadcrumbs, i.e., the names of the higher levels
  1443. %(expression) Eval EXPRESSION and replace the control string
  1444. by the result
  1445. All specifiers work basically like the standard `%s' of printf, but may
  1446. contain two additional characters: a question mark just after the `%'
  1447. and a whitespace/punctuation character just before the final letter.
  1448. If the first character after `%' is a question mark, the entire field
  1449. will only be included if the corresponding value applies to the current
  1450. entry. This is useful for fields which should have fixed width when
  1451. present, but zero width when absent. For example, \"%?-12t\" will
  1452. result in a 12 character time field if a time of the day is specified,
  1453. but will completely disappear in entries which do not contain a time.
  1454. If there is punctuation or whitespace character just before the
  1455. final format letter, this character will be appended to the field
  1456. value if the value is not empty. For example, the format
  1457. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1458. the category is empty, no additional colon is inserted.
  1459. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1460. which means:
  1461. - Indent the line with two space characters
  1462. - Give the category a 12 chars wide field, padded with whitespace on
  1463. the right (because of `-'). Append a colon if there is a category
  1464. (because of `:').
  1465. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1466. time, don't put in an empty field, just skip it (because of '?').
  1467. - Finally, put the scheduling information.
  1468. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1469. `org-agenda-remove-tags'.
  1470. Custom commands can set this variable in the options section."
  1471. :type '(choice
  1472. (string :tag "General format")
  1473. (list :greedy t :tag "View dependent"
  1474. (cons (const agenda) (string :tag "Format"))
  1475. (cons (const timeline) (string :tag "Format"))
  1476. (cons (const todo) (string :tag "Format"))
  1477. (cons (const tags) (string :tag "Format"))
  1478. (cons (const search) (string :tag "Format"))))
  1479. :group 'org-agenda-line-format)
  1480. (defvar org-prefix-format-compiled nil
  1481. "The compiled prefix format and associated variables.
  1482. This is a list where first element is a list of variable bindings, and second
  1483. element is the compiled format expression. See the variable
  1484. `org-agenda-prefix-format'.")
  1485. (defcustom org-agenda-todo-keyword-format "%-1s"
  1486. "Format for the TODO keyword in agenda lines.
  1487. Set this to something like \"%-12s\" if you want all TODO keywords
  1488. to occupy a fixed space in the agenda display."
  1489. :group 'org-agenda-line-format
  1490. :type 'string)
  1491. (defcustom org-agenda-diary-sexp-prefix nil
  1492. "A regexp that matches part of a diary sexp entry
  1493. which should be treated as scheduling/deadline information in
  1494. `org-agenda'.
  1495. For example, you can use this to extract the `diary-remind-message' from
  1496. `diary-remind' entries."
  1497. :group 'org-agenda-line-format
  1498. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1499. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1500. "Text preceding timerange entries in the agenda view.
  1501. This is a list with two strings. The first applies when the range
  1502. is entirely on one day. The second applies if the range spans several days.
  1503. The strings may have two \"%d\" format specifiers which will be filled
  1504. with the sequence number of the days, and the total number of days in the
  1505. range, respectively."
  1506. :group 'org-agenda-line-format
  1507. :type '(list
  1508. (string :tag "Deadline today ")
  1509. (choice :tag "Deadline relative"
  1510. (string :tag "Format string")
  1511. (function))))
  1512. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1513. "Text preceding scheduled items in the agenda view.
  1514. This is a list with two strings. The first applies when the item is
  1515. scheduled on the current day. The second applies when it has been scheduled
  1516. previously, it may contain a %d indicating that this is the nth time that
  1517. this item is scheduled, due to automatic rescheduling of unfinished items
  1518. for the following day. So this number is one larger than the number of days
  1519. that passed since this item was scheduled first."
  1520. :group 'org-agenda-line-format
  1521. :version "24.4"
  1522. :package-version '(Org . "8.0")
  1523. :type '(list
  1524. (string :tag "Scheduled today ")
  1525. (string :tag "Scheduled previously")))
  1526. (defcustom org-agenda-inactive-leader "["
  1527. "Text preceding item pulled into the agenda by inactive time stamps.
  1528. These entries are added to the agenda when pressing \"[\"."
  1529. :group 'org-agenda-line-format
  1530. :version "24.1"
  1531. :type 'string)
  1532. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1533. "Text preceding deadline items in the agenda view.
  1534. This is a list with three strings. The first applies when the item has its
  1535. deadline on the current day. The second applies when the deadline is in the
  1536. future, the third one when it is in the past. The strings may contain %d
  1537. to capture the number of days."
  1538. :group 'org-agenda-line-format
  1539. :version "24.4"
  1540. :package-version '(Org . "8.0")
  1541. :type '(list
  1542. (string :tag "Deadline today ")
  1543. (string :tag "Deadline in the future ")
  1544. (string :tag "Deadline in the past ")))
  1545. (defcustom org-agenda-remove-times-when-in-prefix t
  1546. "Non-nil means remove duplicate time specifications in agenda items.
  1547. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1548. time-of-day specification in a headline or diary entry is extracted and
  1549. placed into the prefix. If this option is non-nil, the original specification
  1550. \(a timestamp or -range, or just a plain time(range) specification like
  1551. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1552. cluttered.
  1553. The option can be t or nil. It may also be the symbol `beg', indicating
  1554. that the time should only be removed when it is located at the beginning of
  1555. the headline/diary entry."
  1556. :group 'org-agenda-line-format
  1557. :type '(choice
  1558. (const :tag "Always" t)
  1559. (const :tag "Never" nil)
  1560. (const :tag "When at beginning of entry" beg)))
  1561. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1562. "Non-nil means remove time ranges specifications in agenda
  1563. items that span on several days."
  1564. :group 'org-agenda-line-format
  1565. :version "24.1"
  1566. :type 'boolean)
  1567. (defcustom org-agenda-default-appointment-duration nil
  1568. "Default duration for appointments that only have a starting time.
  1569. When nil, no duration is specified in such cases.
  1570. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1571. :group 'org-agenda-line-format
  1572. :type '(choice
  1573. (integer :tag "Minutes")
  1574. (const :tag "No default duration")))
  1575. (defcustom org-agenda-show-inherited-tags t
  1576. "Non-nil means show inherited tags in each agenda line.
  1577. When this option is set to 'always, it take precedences over
  1578. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1579. in every agenda.
  1580. When this option is set to t (the default), inherited tags are
  1581. shown when they are available, i.e. when the value of
  1582. `org-agenda-use-tag-inheritance' has been taken into account.
  1583. This can be set to a list of agenda types in which the agenda
  1584. must display the inherited tags. Available types are 'todo,
  1585. 'agenda, 'search and 'timeline.
  1586. When set to nil, never show inherited tags in agenda lines."
  1587. :group 'org-agenda-line-format
  1588. :group 'org-agenda
  1589. :version "24.3"
  1590. :type '(choice
  1591. (const :tag "Show inherited tags when available" t)
  1592. (const :tag "Always show inherited tags" always)
  1593. (repeat :tag "Show inherited tags only in selected agenda types"
  1594. (symbol :tag "Agenda type"))))
  1595. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1596. "List of agenda view types where to use tag inheritance.
  1597. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1598. controlled by `org-use-tag-inheritance'. In other agenda types,
  1599. `org-use-tag-inheritance' is not used for the selection of the
  1600. agenda entries. Still, you may want the agenda to be aware of
  1601. the inherited tags anyway, e.g. for later tag filtering.
  1602. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1603. This variable has no effect if `org-agenda-show-inherited-tags'
  1604. is set to 'always. In that case, the agenda is aware of those
  1605. tags.
  1606. The default value sets tags in every agenda type. Setting this
  1607. option to nil will speed up non-tags agenda view a lot."
  1608. :group 'org-agenda
  1609. :version "24.3"
  1610. :type '(choice
  1611. (const :tag "Use tag inheritance in all agenda types" t)
  1612. (repeat :tag "Use tag inheritance in selected agenda types"
  1613. (symbol :tag "Agenda type"))))
  1614. (defcustom org-agenda-hide-tags-regexp nil
  1615. "Regular expression used to filter away specific tags in agenda views.
  1616. This means that these tags will be present, but not be shown in the agenda
  1617. line. Secondary filtering will still work on the hidden tags.
  1618. Nil means don't hide any tags."
  1619. :group 'org-agenda-line-format
  1620. :type '(choice
  1621. (const :tag "Hide none" nil)
  1622. (string :tag "Regexp ")))
  1623. (defcustom org-agenda-remove-tags nil
  1624. "Non-nil means remove the tags from the headline copy in the agenda.
  1625. When this is the symbol `prefix', only remove tags when
  1626. `org-agenda-prefix-format' contains a `%T' specifier."
  1627. :group 'org-agenda-line-format
  1628. :type '(choice
  1629. (const :tag "Always" t)
  1630. (const :tag "Never" nil)
  1631. (const :tag "When prefix format contains %T" prefix)))
  1632. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1633. 'org-agenda-remove-tags)
  1634. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1635. "Shift tags in agenda items to this column.
  1636. If this number is positive, it specifies the column. If it is negative,
  1637. it means that the tags should be flushright to that column. For example,
  1638. -80 works well for a normal 80 character screen."
  1639. :group 'org-agenda-line-format
  1640. :type 'integer)
  1641. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1642. (defcustom org-agenda-fontify-priorities 'cookies
  1643. "Non-nil means highlight low and high priorities in agenda.
  1644. When t, the highest priority entries are bold, lowest priority italic.
  1645. However, settings in `org-priority-faces' will overrule these faces.
  1646. When this variable is the symbol `cookies', only fontify the
  1647. cookies, not the entire task.
  1648. This may also be an association list of priority faces, whose
  1649. keys are the character values of `org-highest-priority',
  1650. `org-default-priority', and `org-lowest-priority' (the default values
  1651. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1652. color as a string, or a list like `(:background \"Red\")'.
  1653. If it is a color, the variable `org-faces-easy-properties'
  1654. determines if it is a foreground or a background color."
  1655. :group 'org-agenda-line-format
  1656. :type '(choice
  1657. (const :tag "Never" nil)
  1658. (const :tag "Defaults" t)
  1659. (const :tag "Cookies only" cookies)
  1660. (repeat :tag "Specify"
  1661. (list (character :tag "Priority" :value ?A)
  1662. (choice :tag "Face "
  1663. (string :tag "Color")
  1664. (sexp :tag "Face"))))))
  1665. (defcustom org-agenda-day-face-function nil
  1666. "Function called to determine what face should be used to display a day.
  1667. The only argument passed to that function is the day. It should
  1668. returns a face, or nil if does not want to specify a face and let
  1669. the normal rules apply."
  1670. :group 'org-agenda-line-format
  1671. :version "24.1"
  1672. :type '(choice (const nil) (function)))
  1673. (defcustom org-agenda-category-icon-alist nil
  1674. "Alist of category icon to be displayed in agenda views.
  1675. Each entry should have the following format:
  1676. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1677. Where CATEGORY-REGEXP is a regexp matching the categories where
  1678. the icon should be displayed.
  1679. FILE-OR-DATA either a file path or a string containing image data.
  1680. The other fields can be omitted safely if not needed:
  1681. TYPE indicates the image type.
  1682. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1683. image data.
  1684. PROPS are additional image attributes to assign to the image,
  1685. like, e.g. `:ascent center'.
  1686. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1687. If you want to set the display properties yourself, just put a
  1688. list as second element:
  1689. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1690. For example, to display a 16px horizontal space for Emacs
  1691. category, you can use:
  1692. (\"Emacs\" '(space . (:width (16))))"
  1693. :group 'org-agenda-line-format
  1694. :version "24.1"
  1695. :type '(alist :key-type (string :tag "Regexp matching category")
  1696. :value-type (choice (list :tag "Icon"
  1697. (string :tag "File or data")
  1698. (symbol :tag "Type")
  1699. (boolean :tag "Data?")
  1700. (repeat :tag "Extra image properties" :inline t symbol))
  1701. (list :tag "Display properties" sexp))))
  1702. (defgroup org-agenda-column-view nil
  1703. "Options concerning column view in the agenda."
  1704. :tag "Org Agenda Column View"
  1705. :group 'org-agenda)
  1706. (defcustom org-agenda-columns-show-summaries t
  1707. "Non-nil means show summaries for columns displayed in the agenda view."
  1708. :group 'org-agenda-column-view
  1709. :type 'boolean)
  1710. (defcustom org-agenda-columns-compute-summary-properties t
  1711. "Non-nil means recompute all summary properties before column view.
  1712. When column view in the agenda is listing properties that have a summary
  1713. operator, it can go to all relevant buffers and recompute the summaries
  1714. there. This can mean overhead for the agenda column view, but is necessary
  1715. to have thing up to date.
  1716. As a special case, a CLOCKSUM property also makes sure that the clock
  1717. computations are current."
  1718. :group 'org-agenda-column-view
  1719. :type 'boolean)
  1720. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1721. "Non-nil means the duration of an appointment will add to day effort.
  1722. The property to which appointment durations will be added is the one given
  1723. in the option `org-effort-property'. If an appointment does not have
  1724. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1725. is not set, an appointment without end time will not contribute to the time
  1726. estimate."
  1727. :group 'org-agenda-column-view
  1728. :type 'boolean)
  1729. (defcustom org-agenda-auto-exclude-function nil
  1730. "A function called with a tag to decide if it is filtered on '/ RET'.
  1731. The sole argument to the function, which is called once for each
  1732. possible tag, is a string giving the name of the tag. The
  1733. function should return either nil if the tag should be included
  1734. as normal, or \"-<TAG>\" to exclude the tag.
  1735. Note that for the purpose of tag filtering, only the lower-case version of
  1736. all tags will be considered, so that this function will only ever see
  1737. the lower-case version of all tags."
  1738. :group 'org-agenda
  1739. :type '(choice (const nil) (function)))
  1740. (defcustom org-agenda-bulk-custom-functions nil
  1741. "Alist of characters and custom functions for bulk actions.
  1742. For example, this value makes those two functions available:
  1743. '((?R set-category)
  1744. (?C bulk-cut))
  1745. With selected entries in an agenda buffer, `B R' will call
  1746. the custom function `set-category' on the selected entries.
  1747. Note that functions in this alist don't need to be quoted."
  1748. :type 'alist
  1749. :version "24.1"
  1750. :group 'org-agenda)
  1751. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1752. "Execute BODY with point at location given by `org-hd-marker' property.
  1753. If STRING is non-nil, the text property will be fetched from position 0
  1754. in that string. If STRING is nil, it will be fetched from the beginning
  1755. of the current line."
  1756. (org-with-gensyms (marker)
  1757. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1758. 'org-hd-marker ,string)))
  1759. (with-current-buffer (marker-buffer ,marker)
  1760. (save-excursion
  1761. (goto-char ,marker)
  1762. ,@body)))))
  1763. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1764. (defun org-add-agenda-custom-command (entry)
  1765. "Replace or add a command in `org-agenda-custom-commands'.
  1766. This is mostly for hacking and trying a new command - once the command
  1767. works you probably want to add it to `org-agenda-custom-commands' for good."
  1768. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1769. (if ass
  1770. (setcdr ass (cdr entry))
  1771. (push entry org-agenda-custom-commands))))
  1772. ;;; Define the org-agenda-mode
  1773. (defvar org-agenda-mode-map (make-sparse-keymap)
  1774. "Keymap for `org-agenda-mode'.")
  1775. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1776. (defvar org-agenda-menu) ; defined later in this file.
  1777. (defvar org-agenda-restrict nil) ; defined later in this file.
  1778. (defvar org-agenda-follow-mode nil)
  1779. (defvar org-agenda-entry-text-mode nil)
  1780. (defvar org-agenda-clockreport-mode nil)
  1781. (defvar org-agenda-show-log nil)
  1782. (defvar org-agenda-redo-command nil)
  1783. (defvar org-agenda-query-string nil)
  1784. (defvar org-agenda-mode-hook nil
  1785. "Hook run after `org-agenda-mode' is turned on.
  1786. The buffer is still writable when this hook is called.")
  1787. (defvar org-agenda-type nil)
  1788. (defvar org-agenda-force-single-file nil)
  1789. (defvar org-agenda-bulk-marked-entries nil
  1790. "List of markers that refer to marked entries in the agenda.")
  1791. ;;; Multiple agenda buffers support
  1792. (defcustom org-agenda-sticky nil
  1793. "Non-nil means agenda q key will bury agenda buffers.
  1794. Agenda commands will then show existing buffer instead of generating new ones.
  1795. When nil, `q' will kill the single agenda buffer."
  1796. :group 'org-agenda
  1797. :version "24.3"
  1798. :type 'boolean)
  1799. ;;;###autoload
  1800. (defun org-toggle-sticky-agenda (&optional arg)
  1801. "Toggle `org-agenda-sticky'."
  1802. (interactive "P")
  1803. (let ((new-value (if arg
  1804. (> (prefix-numeric-value arg) 0)
  1805. (not org-agenda-sticky))))
  1806. (if (equal new-value org-agenda-sticky)
  1807. (and (org-called-interactively-p 'interactive)
  1808. (message "Sticky agenda was already %s"
  1809. (if org-agenda-sticky "enabled" "disabled")))
  1810. (setq org-agenda-sticky new-value)
  1811. (org-agenda-kill-all-agenda-buffers)
  1812. (and (org-called-interactively-p 'interactive)
  1813. (message "Sticky agenda was %s"
  1814. (if org-agenda-sticky "enabled" "disabled"))))))
  1815. (defvar org-agenda-buffer nil
  1816. "Agenda buffer currently being generated.")
  1817. (defvar org-agenda-last-prefix-arg nil)
  1818. (defvar org-agenda-this-buffer-name nil)
  1819. (defvar org-agenda-doing-sticky-redo nil)
  1820. (defvar org-agenda-this-buffer-is-sticky nil)
  1821. (defconst org-agenda-local-vars
  1822. '(org-agenda-this-buffer-name
  1823. org-agenda-undo-list
  1824. org-agenda-pending-undo-list
  1825. org-agenda-follow-mode
  1826. org-agenda-entry-text-mode
  1827. org-agenda-clockreport-mode
  1828. org-agenda-show-log
  1829. org-agenda-redo-command
  1830. org-agenda-query-string
  1831. org-agenda-type
  1832. org-agenda-bulk-marked-entries
  1833. org-agenda-undo-has-started-in
  1834. org-agenda-info
  1835. org-agenda-pre-window-conf
  1836. org-agenda-columns-active
  1837. org-agenda-tag-filter
  1838. org-agenda-category-filter
  1839. org-agenda-top-headline-filter
  1840. org-agenda-regexp-filter
  1841. org-agenda-effort-filter
  1842. org-agenda-markers
  1843. org-agenda-last-search-view-search-was-boolean
  1844. org-agenda-filtered-by-category
  1845. org-agenda-filter-form
  1846. org-agenda-cycle-counter
  1847. org-agenda-last-prefix-arg)
  1848. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1849. (defun org-agenda-mode ()
  1850. "Mode for time-sorted view on action items in Org-mode files.
  1851. The following commands are available:
  1852. \\{org-agenda-mode-map}"
  1853. (interactive)
  1854. (cond (org-agenda-doing-sticky-redo
  1855. ;; Refreshing sticky agenda-buffer
  1856. ;;
  1857. ;; Preserve the value of `org-agenda-local-vars' variables,
  1858. ;; while letting `kill-all-local-variables' kill the rest
  1859. (let ((save (buffer-local-variables)))
  1860. (kill-all-local-variables)
  1861. (mapc 'make-local-variable org-agenda-local-vars)
  1862. (dolist (elem save)
  1863. (let ((var (car elem))
  1864. (val (cdr elem)))
  1865. (when (and val
  1866. (member var org-agenda-local-vars))
  1867. (set var val)))))
  1868. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1869. (org-agenda-sticky
  1870. ;; Creating a sticky Agenda buffer for the first time
  1871. (kill-all-local-variables)
  1872. (mapc 'make-local-variable org-agenda-local-vars)
  1873. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1874. (t
  1875. ;; Creating a non-sticky agenda buffer
  1876. (kill-all-local-variables)
  1877. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1878. (setq org-agenda-undo-list nil
  1879. org-agenda-pending-undo-list nil
  1880. org-agenda-bulk-marked-entries nil)
  1881. (setq major-mode 'org-agenda-mode)
  1882. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1883. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1884. (setq mode-name "Org-Agenda")
  1885. (setq indent-tabs-mode nil)
  1886. (use-local-map org-agenda-mode-map)
  1887. (easy-menu-add org-agenda-menu)
  1888. (if org-startup-truncated (setq truncate-lines t))
  1889. (org-set-local 'line-move-visual nil)
  1890. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1891. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1892. ;; Make sure properties are removed when copying text
  1893. (org-add-hook 'filter-buffer-substring-functions
  1894. (lambda (fun start end delete)
  1895. (substring-no-properties (funcall fun start end delete)))
  1896. nil t)
  1897. (unless org-agenda-keep-modes
  1898. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1899. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1900. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1901. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1902. (add-to-invisibility-spec '(org-filtered))
  1903. (add-to-invisibility-spec '(org-link))
  1904. (easy-menu-change
  1905. '("Agenda") "Agenda Files"
  1906. (append
  1907. (list
  1908. (vector
  1909. (if (get 'org-agenda-files 'org-restrict)
  1910. "Restricted to single file"
  1911. "Edit File List")
  1912. '(org-edit-agenda-file-list)
  1913. (not (get 'org-agenda-files 'org-restrict)))
  1914. "--")
  1915. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1916. (org-agenda-set-mode-name)
  1917. (apply
  1918. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1919. (list 'org-agenda-mode-hook)))
  1920. (substitute-key-definition 'undo 'org-agenda-undo
  1921. org-agenda-mode-map global-map)
  1922. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1923. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1924. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1925. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1926. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1927. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1928. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1929. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1930. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1931. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1932. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1933. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1934. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1935. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1936. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1937. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1938. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1939. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1940. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1941. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1942. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1943. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1944. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1945. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1946. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1947. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1948. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1949. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1950. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1951. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1952. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1953. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1954. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1955. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1956. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1957. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1958. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1959. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1960. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1961. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1962. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1963. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1964. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1965. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1966. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1967. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1968. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1969. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1970. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1971. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1972. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1973. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1974. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1975. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1976. (while l (org-defkey org-agenda-mode-map
  1977. (int-to-string (pop l)) 'digit-argument)))
  1978. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1979. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1980. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1981. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1982. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1983. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1984. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1985. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1986. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1987. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1988. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1989. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1990. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1991. 'org-clock-modify-effort-estimate)
  1992. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1993. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1994. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1995. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1996. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1997. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1998. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1999. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2000. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2001. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2002. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2003. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2004. (substitute-key-definition 'next-line 'org-agenda-next-line
  2005. org-agenda-mode-map global-map)
  2006. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2007. org-agenda-mode-map global-map)
  2008. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2009. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2010. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2011. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2012. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2013. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2014. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2015. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2016. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2017. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2018. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2019. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2021. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2022. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2023. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2024. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2025. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2026. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2027. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2028. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2029. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2030. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2031. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2032. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2033. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2034. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2035. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2036. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2037. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2038. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2039. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2040. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2041. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2042. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2043. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2044. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2045. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2046. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2047. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2048. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2049. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2050. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2051. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2052. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2053. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2054. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2055. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2056. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2057. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2058. (when org-agenda-mouse-1-follows-link
  2059. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2060. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2061. '("Agenda"
  2062. ("Agenda Files")
  2063. "--"
  2064. ("Agenda Dates"
  2065. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2066. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2067. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2068. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2069. "--"
  2070. ("View"
  2071. ["Day View" org-agenda-day-view
  2072. :active (org-agenda-check-type nil 'agenda)
  2073. :style radio :selected (eq org-agenda-current-span 'day)
  2074. :keys "v d (or just d)"]
  2075. ["Week View" org-agenda-week-view
  2076. :active (org-agenda-check-type nil 'agenda)
  2077. :style radio :selected (eq org-agenda-current-span 'week)
  2078. :keys "v w"]
  2079. ["Fortnight View" org-agenda-fortnight-view
  2080. :active (org-agenda-check-type nil 'agenda)
  2081. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2082. :keys "v f"]
  2083. ["Month View" org-agenda-month-view
  2084. :active (org-agenda-check-type nil 'agenda)
  2085. :style radio :selected (eq org-agenda-current-span 'month)
  2086. :keys "v m"]
  2087. ["Year View" org-agenda-year-view
  2088. :active (org-agenda-check-type nil 'agenda)
  2089. :style radio :selected (eq org-agenda-current-span 'year)
  2090. :keys "v y"]
  2091. "--"
  2092. ["Include Diary" org-agenda-toggle-diary
  2093. :style toggle :selected org-agenda-include-diary
  2094. :active (org-agenda-check-type nil 'agenda)]
  2095. ["Include Deadlines" org-agenda-toggle-deadlines
  2096. :style toggle :selected org-agenda-include-deadlines
  2097. :active (org-agenda-check-type nil 'agenda)]
  2098. ["Use Time Grid" org-agenda-toggle-time-grid
  2099. :style toggle :selected org-agenda-use-time-grid
  2100. :active (org-agenda-check-type nil 'agenda)]
  2101. "--"
  2102. ["Show clock report" org-agenda-clockreport-mode
  2103. :style toggle :selected org-agenda-clockreport-mode
  2104. :active (org-agenda-check-type nil 'agenda)]
  2105. ["Show some entry text" org-agenda-entry-text-mode
  2106. :style toggle :selected org-agenda-entry-text-mode
  2107. :active t]
  2108. "--"
  2109. ["Show Logbook entries" org-agenda-log-mode
  2110. :style toggle :selected org-agenda-show-log
  2111. :active (org-agenda-check-type nil 'agenda 'timeline)
  2112. :keys "v l (or just l)"]
  2113. ["Include archived trees" org-agenda-archives-mode
  2114. :style toggle :selected org-agenda-archives-mode :active t
  2115. :keys "v a"]
  2116. ["Include archive files" (org-agenda-archives-mode t)
  2117. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2118. :keys "v A"]
  2119. "--"
  2120. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2121. ["Write view to file" org-agenda-write t]
  2122. ["Rebuild buffer" org-agenda-redo t]
  2123. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2124. "--"
  2125. ["Show original entry" org-agenda-show t]
  2126. ["Go To (other window)" org-agenda-goto t]
  2127. ["Go To (this window)" org-agenda-switch-to t]
  2128. ["Capture with cursor date" org-agenda-capture t]
  2129. ["Follow Mode" org-agenda-follow-mode
  2130. :style toggle :selected org-agenda-follow-mode :active t]
  2131. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2132. "--"
  2133. ("TODO"
  2134. ["Cycle TODO" org-agenda-todo t]
  2135. ["Next TODO set" org-agenda-todo-nextset t]
  2136. ["Previous TODO set" org-agenda-todo-previousset t]
  2137. ["Add note" org-agenda-add-note t])
  2138. ("Archive/Refile/Delete"
  2139. ["Archive default" org-agenda-archive-default t]
  2140. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2141. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2142. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2143. ["Archive subtree" org-agenda-archive t]
  2144. "--"
  2145. ["Refile" org-agenda-refile t]
  2146. "--"
  2147. ["Delete subtree" org-agenda-kill t])
  2148. ("Bulk action"
  2149. ["Mark entry" org-agenda-bulk-mark t]
  2150. ["Mark all" org-agenda-bulk-mark-all t]
  2151. ["Unmark entry" org-agenda-bulk-unmark t]
  2152. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2153. ["Toggle mark" org-agenda-bulk-toggle t]
  2154. ["Toggle all" org-agenda-bulk-toggle-all t]
  2155. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2156. ["Act on all marked" org-agenda-bulk-action t]
  2157. "--"
  2158. ("Tags and Properties"
  2159. ["Show all Tags" org-agenda-show-tags t]
  2160. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2161. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2162. "--"
  2163. ["Column View" org-columns t])
  2164. ("Deadline/Schedule"
  2165. ["Schedule" org-agenda-schedule t]
  2166. ["Set Deadline" org-agenda-deadline t]
  2167. "--"
  2168. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2169. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2170. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2171. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2172. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2173. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2174. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2175. ("Clock and Effort"
  2176. ["Clock in" org-agenda-clock-in t]
  2177. ["Clock out" org-agenda-clock-out t]
  2178. ["Clock cancel" org-agenda-clock-cancel t]
  2179. ["Goto running clock" org-clock-goto t]
  2180. "--"
  2181. ["Set Effort" org-agenda-set-effort t]
  2182. ["Change clocked effort" org-clock-modify-effort-estimate
  2183. (org-clock-is-active)])
  2184. ("Priority"
  2185. ["Set Priority" org-agenda-priority t]
  2186. ["Increase Priority" org-agenda-priority-up t]
  2187. ["Decrease Priority" org-agenda-priority-down t]
  2188. ["Show Priority" org-show-priority t])
  2189. ("Calendar/Diary"
  2190. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2191. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2192. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2193. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2194. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2195. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2196. "--"
  2197. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2198. "--"
  2199. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2200. "--"
  2201. ("MobileOrg"
  2202. ["Push Files and Views" org-mobile-push t]
  2203. ["Get Captured and Flagged" org-mobile-pull t]
  2204. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2205. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2206. "--"
  2207. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2208. "--"
  2209. ["Quit" org-agenda-quit t]
  2210. ["Exit and Release Buffers" org-agenda-exit t]
  2211. ))
  2212. ;;; Agenda undo
  2213. (defvar org-agenda-allow-remote-undo t
  2214. "Non-nil means allow remote undo from the agenda buffer.")
  2215. (defvar org-agenda-undo-has-started-in nil
  2216. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2217. (defun org-agenda-undo ()
  2218. "Undo a remote editing step in the agenda.
  2219. This undoes changes both in the agenda buffer and in the remote buffer
  2220. that have been changed along."
  2221. (interactive)
  2222. (or org-agenda-allow-remote-undo
  2223. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2224. (if (not (eq this-command last-command))
  2225. (setq org-agenda-undo-has-started-in nil
  2226. org-agenda-pending-undo-list org-agenda-undo-list))
  2227. (if (not org-agenda-pending-undo-list)
  2228. (user-error "No further undo information"))
  2229. (let* ((entry (pop org-agenda-pending-undo-list))
  2230. buf line cmd rembuf)
  2231. (setq cmd (pop entry) line (pop entry))
  2232. (setq rembuf (nth 2 entry))
  2233. (org-with-remote-undo rembuf
  2234. (while (bufferp (setq buf (pop entry)))
  2235. (if (pop entry)
  2236. (with-current-buffer buf
  2237. (let ((last-undo-buffer buf)
  2238. (inhibit-read-only t))
  2239. (unless (memq buf org-agenda-undo-has-started-in)
  2240. (push buf org-agenda-undo-has-started-in)
  2241. (make-local-variable 'pending-undo-list)
  2242. (undo-start))
  2243. (while (and pending-undo-list
  2244. (listp pending-undo-list)
  2245. (not (car pending-undo-list)))
  2246. (pop pending-undo-list))
  2247. (undo-more 1))))))
  2248. (org-goto-line line)
  2249. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2250. (defun org-verify-change-for-undo (l1 l2)
  2251. "Verify that a real change occurred between the undo lists L1 and L2."
  2252. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2253. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2254. (not (eq l1 l2)))
  2255. ;;; Agenda dispatch
  2256. (defvar org-agenda-restrict-begin (make-marker))
  2257. (defvar org-agenda-restrict-end (make-marker))
  2258. (defvar org-agenda-last-dispatch-buffer nil)
  2259. (defvar org-agenda-overriding-restriction nil)
  2260. (defcustom org-agenda-custom-commands-contexts nil
  2261. "Alist of custom agenda keys and contextual rules.
  2262. For example, if you have a custom agenda command \"p\" and you
  2263. want this command to be accessible only from plain text files,
  2264. use this:
  2265. '((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2266. Here are the available contexts definitions:
  2267. in-file: command displayed only in matching files
  2268. in-mode: command displayed only in matching modes
  2269. not-in-file: command not displayed in matching files
  2270. not-in-mode: command not displayed in matching modes
  2271. in-buffer: command displayed only in matching buffers
  2272. not-in-buffer: command not displayed in matching buffers
  2273. [function]: a custom function taking no argument
  2274. If you define several checks, the agenda command will be
  2275. accessible if there is at least one valid check.
  2276. You can also bind a key to another agenda custom command
  2277. depending on contextual rules.
  2278. '((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2279. Here it means: in .txt files, use \"p\" as the key for the
  2280. agenda command otherwise associated with \"q\". (The command
  2281. originally associated with \"q\" is not displayed to avoid
  2282. duplicates.)"
  2283. :version "24.3"
  2284. :group 'org-agenda-custom-commands
  2285. :type '(repeat (list :tag "Rule"
  2286. (string :tag " Agenda key")
  2287. (string :tag "Replace by command")
  2288. (repeat :tag "Available when"
  2289. (choice
  2290. (cons :tag "Condition"
  2291. (choice
  2292. (const :tag "In file" in-file)
  2293. (const :tag "Not in file" not-in-file)
  2294. (const :tag "In buffer" in-buffer)
  2295. (const :tag "Not in buffer" not-in-buffer)
  2296. (const :tag "In mode" in-mode)
  2297. (const :tag "Not in mode" not-in-mode))
  2298. (regexp))
  2299. (function :tag "Custom function"))))))
  2300. (defcustom org-agenda-max-entries nil
  2301. "Maximum number of entries to display in an agenda.
  2302. This can be nil (no limit) or an integer or an alist of agenda
  2303. types with an associated number of entries to display in this
  2304. type."
  2305. :version "24.4"
  2306. :package-version '(Org . "8.0")
  2307. :group 'org-agenda-custom-commands
  2308. :type '(choice (symbol :tag "No limit" nil)
  2309. (integer :tag "Max number of entries")
  2310. (repeat
  2311. (cons (choice :tag "Agenda type"
  2312. (const agenda)
  2313. (const todo)
  2314. (const tags)
  2315. (const search)
  2316. (const timeline))
  2317. (integer :tag "Max number of entries")))))
  2318. (defcustom org-agenda-max-todos nil
  2319. "Maximum number of TODOs to display in an agenda.
  2320. This can be nil (no limit) or an integer or an alist of agenda
  2321. types with an associated number of entries to display in this
  2322. type."
  2323. :version "24.4"
  2324. :package-version '(Org . "8.0")
  2325. :group 'org-agenda-custom-commands
  2326. :type '(choice (symbol :tag "No limit" nil)
  2327. (integer :tag "Max number of TODOs")
  2328. (repeat
  2329. (cons (choice :tag "Agenda type"
  2330. (const agenda)
  2331. (const todo)
  2332. (const tags)
  2333. (const search)
  2334. (const timeline))
  2335. (integer :tag "Max number of TODOs")))))
  2336. (defcustom org-agenda-max-tags nil
  2337. "Maximum number of tagged entries to display in an agenda.
  2338. This can be nil (no limit) or an integer or an alist of agenda
  2339. types with an associated number of entries to display in this
  2340. type."
  2341. :version "24.4"
  2342. :package-version '(Org . "8.0")
  2343. :group 'org-agenda-custom-commands
  2344. :type '(choice (symbol :tag "No limit" nil)
  2345. (integer :tag "Max number of tagged entries")
  2346. (repeat
  2347. (cons (choice :tag "Agenda type"
  2348. (const agenda)
  2349. (const todo)
  2350. (const tags)
  2351. (const search)
  2352. (const timeline))
  2353. (integer :tag "Max number of tagged entries")))))
  2354. (defcustom org-agenda-max-effort nil
  2355. "Maximum cumulated effort duration for the agenda.
  2356. This can be nil (no limit) or a number of minutes (as an integer)
  2357. or an alist of agenda types with an associated number of minutes
  2358. to limit entries to in this type."
  2359. :version "24.4"
  2360. :package-version '(Org . "8.0")
  2361. :group 'org-agenda-custom-commands
  2362. :type '(choice (symbol :tag "No limit" nil)
  2363. (integer :tag "Max number of minutes")
  2364. (repeat
  2365. (cons (choice :tag "Agenda type"
  2366. (const agenda)
  2367. (const todo)
  2368. (const tags)
  2369. (const search)
  2370. (const timeline))
  2371. (integer :tag "Max number of minutes")))))
  2372. (defvar org-keys nil)
  2373. (defvar org-match nil)
  2374. ;;;###autoload
  2375. (defun org-agenda (&optional arg org-keys restriction)
  2376. "Dispatch agenda commands to collect entries to the agenda buffer.
  2377. Prompts for a command to execute. Any prefix arg will be passed
  2378. on to the selected command. The default selections are:
  2379. a Call `org-agenda-list' to display the agenda for current day or week.
  2380. t Call `org-todo-list' to display the global todo list.
  2381. T Call `org-todo-list' to display the global todo list, select only
  2382. entries with a specific TODO keyword (the user gets a prompt).
  2383. m Call `org-tags-view' to display headlines with tags matching
  2384. a condition (the user is prompted for the condition).
  2385. M Like `m', but select only TODO entries, no ordinary headlines.
  2386. L Create a timeline for the current buffer.
  2387. e Export views to associated files.
  2388. s Search entries for keywords.
  2389. S Search entries for keywords, only with TODO keywords.
  2390. / Multi occur across all agenda files and also files listed
  2391. in `org-agenda-text-search-extra-files'.
  2392. < Restrict agenda commands to buffer, subtree, or region.
  2393. Press several times to get the desired effect.
  2394. > Remove a previous restriction.
  2395. # List \"stuck\" projects.
  2396. ! Configure what \"stuck\" means.
  2397. C Configure custom agenda commands.
  2398. More commands can be added by configuring the variable
  2399. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2400. searches can be pre-defined in this way.
  2401. If the current buffer is in Org-mode and visiting a file, you can also
  2402. first press `<' once to indicate that the agenda should be temporarily
  2403. \(until the next use of \\[org-agenda]) restricted to the current file.
  2404. Pressing `<' twice means to restrict to the current subtree or region
  2405. \(if active)."
  2406. (interactive "P")
  2407. (catch 'exit
  2408. (let* ((prefix-descriptions nil)
  2409. (org-agenda-buffer-name org-agenda-buffer-name)
  2410. (org-agenda-window-setup (if (equal (buffer-name)
  2411. org-agenda-buffer-name)
  2412. 'current-window
  2413. org-agenda-window-setup))
  2414. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2415. (org-agenda-custom-commands
  2416. ;; normalize different versions
  2417. (delq nil
  2418. (mapcar
  2419. (lambda (x)
  2420. (cond ((stringp (cdr x))
  2421. (push x prefix-descriptions)
  2422. nil)
  2423. ((stringp (nth 1 x)) x)
  2424. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2425. (t (cons (car x) (cons "" (cdr x))))))
  2426. org-agenda-custom-commands)))
  2427. (org-agenda-custom-commands
  2428. (org-contextualize-keys
  2429. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2430. (buf (current-buffer))
  2431. (bfn (buffer-file-name (buffer-base-buffer)))
  2432. entry key type org-match lprops ans)
  2433. ;; Turn off restriction unless there is an overriding one,
  2434. (unless org-agenda-overriding-restriction
  2435. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2436. ;; There is a request to keep the file list in place
  2437. (put 'org-agenda-files 'org-restrict nil))
  2438. (setq org-agenda-restrict nil)
  2439. (move-marker org-agenda-restrict-begin nil)
  2440. (move-marker org-agenda-restrict-end nil))
  2441. ;; Delete old local properties
  2442. (put 'org-agenda-redo-command 'org-lprops nil)
  2443. ;; Delete previously set last-arguments
  2444. (put 'org-agenda-redo-command 'last-args nil)
  2445. ;; Remember where this call originated
  2446. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2447. (unless org-keys
  2448. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2449. org-keys (car ans)
  2450. restriction (cdr ans)))
  2451. ;; If we have sticky agenda buffers, set a name for the buffer,
  2452. ;; depending on the invoking keys. The user may still set this
  2453. ;; as a command option, which will overwrite what we do here.
  2454. (if org-agenda-sticky
  2455. (setq org-agenda-buffer-name
  2456. (format "*Org Agenda(%s)*" org-keys)))
  2457. ;; Establish the restriction, if any
  2458. (when (and (not org-agenda-overriding-restriction) restriction)
  2459. (put 'org-agenda-files 'org-restrict (list bfn))
  2460. (cond
  2461. ((eq restriction 'region)
  2462. (setq org-agenda-restrict (current-buffer))
  2463. (move-marker org-agenda-restrict-begin (region-beginning))
  2464. (move-marker org-agenda-restrict-end (region-end)))
  2465. ((eq restriction 'subtree)
  2466. (save-excursion
  2467. (setq org-agenda-restrict (current-buffer))
  2468. (org-back-to-heading t)
  2469. (move-marker org-agenda-restrict-begin (point))
  2470. (move-marker org-agenda-restrict-end
  2471. (progn (org-end-of-subtree t)))))))
  2472. ;; For example the todo list should not need it (but does...)
  2473. (cond
  2474. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2475. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2476. (progn
  2477. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2478. lprops (nth 4 entry))
  2479. (if org-agenda-sticky
  2480. (setq org-agenda-buffer-name
  2481. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2482. (format "*Org Agenda(%s)*" org-keys))))
  2483. (put 'org-agenda-redo-command 'org-lprops lprops)
  2484. (cond
  2485. ((eq type 'agenda)
  2486. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2487. ((eq type 'agenda*)
  2488. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2489. ((eq type 'alltodo)
  2490. (org-let lprops '(org-todo-list current-prefix-arg)))
  2491. ((eq type 'search)
  2492. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2493. ((eq type 'stuck)
  2494. (org-let lprops '(org-agenda-list-stuck-projects
  2495. current-prefix-arg)))
  2496. ((eq type 'tags)
  2497. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2498. ((eq type 'tags-todo)
  2499. (org-let lprops '(org-tags-view '(4) org-match)))
  2500. ((eq type 'todo)
  2501. (org-let lprops '(org-todo-list org-match)))
  2502. ((eq type 'tags-tree)
  2503. (org-check-for-org-mode)
  2504. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2505. ((eq type 'todo-tree)
  2506. (org-check-for-org-mode)
  2507. (org-let lprops
  2508. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2509. (regexp-quote org-match) "\\>"))))
  2510. ((eq type 'occur-tree)
  2511. (org-check-for-org-mode)
  2512. (org-let lprops '(org-occur org-match)))
  2513. ((functionp type)
  2514. (org-let lprops '(funcall type org-match)))
  2515. ((fboundp type)
  2516. (org-let lprops '(funcall type org-match)))
  2517. (t (user-error "Invalid custom agenda command type %s" type))))
  2518. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2519. ((equal org-keys "C")
  2520. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2521. (customize-variable 'org-agenda-custom-commands))
  2522. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2523. ((equal org-keys "s") (call-interactively 'org-search-view))
  2524. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2525. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2526. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2527. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2528. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2529. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2530. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2531. (org-add-hook
  2532. 'post-command-hook
  2533. (lambda ()
  2534. (unless (current-message)
  2535. (let* ((m (org-agenda-get-any-marker))
  2536. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2537. (when note
  2538. (message (concat
  2539. "FLAGGING-NOTE ([?] for more info): "
  2540. (org-add-props
  2541. (replace-regexp-in-string
  2542. "\\\\n" "//"
  2543. (copy-sequence note))
  2544. nil 'face 'org-warning)))))))
  2545. t t))
  2546. ((equal org-keys "L")
  2547. (unless (derived-mode-p 'org-mode)
  2548. (user-error "This is not an Org-mode file"))
  2549. (unless restriction
  2550. (put 'org-agenda-files 'org-restrict (list bfn))
  2551. (org-call-with-arg 'org-timeline arg)))
  2552. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2553. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2554. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2555. (t (user-error "Invalid agenda key"))))))
  2556. (defvar org-agenda-multi)
  2557. (defun org-agenda-append-agenda ()
  2558. "Append another agenda view to the current one.
  2559. This function allows interactive building of block agendas.
  2560. Agenda views are separated by `org-agenda-block-separator'."
  2561. (interactive)
  2562. (unless (derived-mode-p 'org-agenda-mode)
  2563. (user-error "Can only append from within agenda buffer"))
  2564. (let ((org-agenda-multi t))
  2565. (org-agenda)
  2566. (widen)
  2567. (org-agenda-finalize)
  2568. (setq buffer-read-only t)
  2569. (org-agenda-fit-window-to-buffer)))
  2570. (defun org-agenda-normalize-custom-commands (cmds)
  2571. "Normalize custom commands CMDS."
  2572. (delq nil
  2573. (mapcar
  2574. (lambda (x)
  2575. (cond ((stringp (cdr x)) nil)
  2576. ((stringp (nth 1 x)) x)
  2577. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2578. (t (cons (car x) (cons "" (cdr x))))))
  2579. cmds)))
  2580. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2581. "The user interface for selecting an agenda command."
  2582. (catch 'exit
  2583. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2584. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2585. (region-p (org-region-active-p))
  2586. (custom org-agenda-custom-commands)
  2587. (selstring "")
  2588. restriction second-time
  2589. c entry key type match prefixes rmheader header-end custom1 desc
  2590. line lines left right n n1)
  2591. (save-window-excursion
  2592. (delete-other-windows)
  2593. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2594. (erase-buffer)
  2595. (insert (eval-when-compile
  2596. (let ((header
  2597. "Press key for an agenda command: < Buffer, subtree/region restriction
  2598. -------------------------------- > Remove restriction
  2599. a Agenda for current week or day e Export agenda views
  2600. t List of all TODO entries T Entries with special TODO kwd
  2601. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2602. s Search for keywords S Like s, but only TODO entries
  2603. L Timeline for current buffer # List stuck projects (!=configure)
  2604. / Multi-occur C Configure custom agenda commands
  2605. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2606. ")
  2607. (start 0))
  2608. (while (string-match
  2609. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2610. header start)
  2611. (setq start (match-end 0))
  2612. (add-text-properties (match-beginning 2) (match-end 2)
  2613. '(face bold) header))
  2614. header)))
  2615. (setq header-end (point-marker))
  2616. (while t
  2617. (setq custom1 custom)
  2618. (when (eq rmheader t)
  2619. (org-goto-line 1)
  2620. (re-search-forward ":" nil t)
  2621. (delete-region (match-end 0) (point-at-eol))
  2622. (forward-char 1)
  2623. (looking-at "-+")
  2624. (delete-region (match-end 0) (point-at-eol))
  2625. (move-marker header-end (match-end 0)))
  2626. (goto-char header-end)
  2627. (delete-region (point) (point-max))
  2628. ;; Produce all the lines that describe custom commands and prefixes
  2629. (setq lines nil)
  2630. (while (setq entry (pop custom1))
  2631. (setq key (car entry) desc (nth 1 entry)
  2632. type (nth 2 entry)
  2633. match (nth 3 entry))
  2634. (if (> (length key) 1)
  2635. (add-to-list 'prefixes (string-to-char key))
  2636. (setq line
  2637. (format
  2638. "%-4s%-14s"
  2639. (org-add-props (copy-sequence key)
  2640. '(face bold))
  2641. (cond
  2642. ((string-match "\\S-" desc) desc)
  2643. ((eq type 'agenda) "Agenda for current week or day")
  2644. ((eq type 'agenda*) "Appointments for current week or day")
  2645. ((eq type 'alltodo) "List of all TODO entries")
  2646. ((eq type 'search) "Word search")
  2647. ((eq type 'stuck) "List of stuck projects")
  2648. ((eq type 'todo) "TODO keyword")
  2649. ((eq type 'tags) "Tags query")
  2650. ((eq type 'tags-todo) "Tags (TODO)")
  2651. ((eq type 'tags-tree) "Tags tree")
  2652. ((eq type 'todo-tree) "TODO kwd tree")
  2653. ((eq type 'occur-tree) "Occur tree")
  2654. ((functionp type) (if (symbolp type)
  2655. (symbol-name type)
  2656. "Lambda expression"))
  2657. (t "???"))))
  2658. (if org-agenda-menu-show-matcher
  2659. (setq line
  2660. (concat line ": "
  2661. (cond
  2662. ((stringp match)
  2663. (setq match (copy-sequence match))
  2664. (org-add-props match nil 'face 'org-warning))
  2665. ((listp type)
  2666. (format "set of %d commands" (length type))))))
  2667. (if (org-string-nw-p match)
  2668. (add-text-properties
  2669. 0 (length line) (list 'help-echo
  2670. (concat "Matcher: " match)) line)))
  2671. (push line lines)))
  2672. (setq lines (nreverse lines))
  2673. (when prefixes
  2674. (mapc (lambda (x)
  2675. (push
  2676. (format "%s %s"
  2677. (org-add-props (char-to-string x)
  2678. nil 'face 'bold)
  2679. (or (cdr (assoc (concat selstring
  2680. (char-to-string x))
  2681. prefix-descriptions))
  2682. "Prefix key"))
  2683. lines))
  2684. prefixes))
  2685. ;; Check if we should display in two columns
  2686. (if org-agenda-menu-two-columns
  2687. (progn
  2688. (setq n (length lines)
  2689. n1 (+ (/ n 2) (mod n 2))
  2690. right (nthcdr n1 lines)
  2691. left (copy-sequence lines))
  2692. (setcdr (nthcdr (1- n1) left) nil))
  2693. (setq left lines right nil))
  2694. (while left
  2695. (insert "\n" (pop left))
  2696. (when right
  2697. (if (< (current-column) 40)
  2698. (move-to-column 40 t)
  2699. (insert " "))
  2700. (insert (pop right))))
  2701. ;; Make the window the right size
  2702. (goto-char (point-min))
  2703. (if second-time
  2704. (if (not (pos-visible-in-window-p (point-max)))
  2705. (org-fit-window-to-buffer))
  2706. (setq second-time t)
  2707. (org-fit-window-to-buffer))
  2708. ;; Ask for selection
  2709. (message "Press key for agenda command%s:"
  2710. (if (or restrict-ok org-agenda-overriding-restriction)
  2711. (if org-agenda-overriding-restriction
  2712. " (restriction lock active)"
  2713. (if restriction
  2714. (format " (restricted to %s)" restriction)
  2715. " (unrestricted)"))
  2716. ""))
  2717. (setq c (read-char-exclusive))
  2718. (message "")
  2719. (cond
  2720. ((assoc (char-to-string c) custom)
  2721. (setq selstring (concat selstring (char-to-string c)))
  2722. (throw 'exit (cons selstring restriction)))
  2723. ((memq c prefixes)
  2724. (setq selstring (concat selstring (char-to-string c))
  2725. prefixes nil
  2726. rmheader (or rmheader t)
  2727. custom (delq nil (mapcar
  2728. (lambda (x)
  2729. (if (or (= (length (car x)) 1)
  2730. (/= (string-to-char (car x)) c))
  2731. nil
  2732. (cons (substring (car x) 1) (cdr x))))
  2733. custom))))
  2734. ((eq c ?*)
  2735. (call-interactively 'org-toggle-sticky-agenda)
  2736. (sit-for 2))
  2737. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2738. (message "Restriction is only possible in Org-mode buffers")
  2739. (ding) (sit-for 1))
  2740. ((eq c ?1)
  2741. (org-agenda-remove-restriction-lock 'noupdate)
  2742. (setq restriction 'buffer))
  2743. ((eq c ?0)
  2744. (org-agenda-remove-restriction-lock 'noupdate)
  2745. (setq restriction (if region-p 'region 'subtree)))
  2746. ((eq c ?<)
  2747. (org-agenda-remove-restriction-lock 'noupdate)
  2748. (setq restriction
  2749. (cond
  2750. ((eq restriction 'buffer)
  2751. (if region-p 'region 'subtree))
  2752. ((memq restriction '(subtree region))
  2753. nil)
  2754. (t 'buffer))))
  2755. ((eq c ?>)
  2756. (org-agenda-remove-restriction-lock 'noupdate)
  2757. (setq restriction nil))
  2758. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2759. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2760. ((and (> (length selstring) 0) (eq c ?\d))
  2761. (delete-window)
  2762. (org-agenda-get-restriction-and-command prefix-descriptions))
  2763. ((equal c ?q) (error "Abort"))
  2764. (t (user-error "Invalid key %c" c))))))))
  2765. (defun org-agenda-fit-window-to-buffer ()
  2766. "Fit the window to the buffer size."
  2767. (and (memq org-agenda-window-setup '(reorganize-frame))
  2768. (fboundp 'fit-window-to-buffer)
  2769. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2770. (= (car org-agenda-window-frame-fractions) 1.0))
  2771. (delete-other-windows)
  2772. (org-fit-window-to-buffer
  2773. nil
  2774. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2775. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2776. (defvar org-cmd nil)
  2777. (defvar org-agenda-overriding-cmd nil)
  2778. (defvar org-agenda-overriding-arguments nil)
  2779. (defvar org-agenda-overriding-cmd-arguments nil)
  2780. (defun org-agenda-run-series (name series)
  2781. "Run agenda NAME as a SERIES of agenda commands."
  2782. (org-let (nth 1 series) '(org-agenda-prepare name))
  2783. ;; We need to reset agenda markers here, because when constructing a
  2784. ;; block agenda, the individual blocks do not do that.
  2785. (org-agenda-reset-markers)
  2786. (let* ((org-agenda-multi t)
  2787. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2788. (cmds (car series))
  2789. (gprops (nth 1 series))
  2790. match ;; The byte compiler incorrectly complains about this. Keep it!
  2791. org-cmd type lprops)
  2792. (while (setq org-cmd (pop cmds))
  2793. (setq type (car org-cmd)
  2794. match (eval (nth 1 org-cmd))
  2795. lprops (nth 2 org-cmd))
  2796. (let ((org-agenda-overriding-arguments
  2797. (if (eq org-agenda-overriding-cmd org-cmd)
  2798. (or org-agenda-overriding-arguments
  2799. org-agenda-overriding-cmd-arguments))))
  2800. (cond
  2801. ((eq type 'agenda)
  2802. (org-let2 gprops lprops
  2803. '(call-interactively 'org-agenda-list)))
  2804. ((eq type 'agenda*)
  2805. (org-let2 gprops lprops
  2806. '(funcall 'org-agenda-list nil nil t)))
  2807. ((eq type 'alltodo)
  2808. (org-let2 gprops lprops
  2809. '(call-interactively 'org-todo-list)))
  2810. ((eq type 'search)
  2811. (org-let2 gprops lprops
  2812. '(org-search-view current-prefix-arg match nil)))
  2813. ((eq type 'stuck)
  2814. (org-let2 gprops lprops
  2815. '(call-interactively 'org-agenda-list-stuck-projects)))
  2816. ((eq type 'tags)
  2817. (org-let2 gprops lprops
  2818. '(org-tags-view current-prefix-arg match)))
  2819. ((eq type 'tags-todo)
  2820. (org-let2 gprops lprops
  2821. '(org-tags-view '(4) match)))
  2822. ((eq type 'todo)
  2823. (org-let2 gprops lprops
  2824. '(org-todo-list match)))
  2825. ((fboundp type)
  2826. (org-let2 gprops lprops
  2827. '(funcall type match)))
  2828. (t (error "Invalid type in command series")))))
  2829. (widen)
  2830. (let ((inhibit-read-only t))
  2831. (add-text-properties (point-min) (point-max)
  2832. `(org-series t org-series-redo-cmd ,redo)))
  2833. (setq org-agenda-redo-command redo)
  2834. (goto-char (point-min)))
  2835. (org-agenda-fit-window-to-buffer)
  2836. (org-let (nth 1 series) '(org-agenda-finalize)))
  2837. ;;;###autoload
  2838. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2839. "Run an agenda command in batch mode and send the result to STDOUT.
  2840. If CMD-KEY is a string of length 1, it is used as a key in
  2841. `org-agenda-custom-commands' and triggers this command. If it is a
  2842. longer string it is used as a tags/todo match string.
  2843. Parameters are alternating variable names and values that will be bound
  2844. before running the agenda command."
  2845. (org-eval-in-environment (org-make-parameter-alist parameters)
  2846. (let (org-agenda-sticky)
  2847. (if (> (length cmd-key) 2)
  2848. (org-tags-view nil cmd-key)
  2849. (org-agenda nil cmd-key))))
  2850. (set-buffer org-agenda-buffer-name)
  2851. (princ (buffer-string)))
  2852. (defvar org-agenda-info nil)
  2853. ;;;###autoload
  2854. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2855. "Run an agenda command in batch mode and send the result to STDOUT.
  2856. If CMD-KEY is a string of length 1, it is used as a key in
  2857. `org-agenda-custom-commands' and triggers this command. If it is a
  2858. longer string it is used as a tags/todo match string.
  2859. Parameters are alternating variable names and values that will be bound
  2860. before running the agenda command.
  2861. The output gives a line for each selected agenda item. Each
  2862. item is a list of comma-separated values, like this:
  2863. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2864. category The category of the item
  2865. head The headline, without TODO kwd, TAGS and PRIORITY
  2866. type The type of the agenda entry, can be
  2867. todo selected in TODO match
  2868. tagsmatch selected in tags match
  2869. diary imported from diary
  2870. deadline a deadline on given date
  2871. scheduled scheduled on given date
  2872. timestamp entry has timestamp on given date
  2873. closed entry was closed on given date
  2874. upcoming-deadline warning about deadline
  2875. past-scheduled forwarded scheduled item
  2876. block entry has date block including g. date
  2877. todo The todo keyword, if any
  2878. tags All tags including inherited ones, separated by colons
  2879. date The relevant date, like 2007-2-14
  2880. time The time, like 15:00-16:50
  2881. extra Sting with extra planning info
  2882. priority-l The priority letter if any was given
  2883. priority-n The computed numerical priority
  2884. agenda-day The day in the agenda where this is listed"
  2885. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2886. (org-make-parameter-alist parameters))
  2887. (if (> (length cmd-key) 2)
  2888. (org-tags-view nil cmd-key)
  2889. (org-agenda nil cmd-key)))
  2890. (set-buffer org-agenda-buffer-name)
  2891. (let* ((lines (org-split-string (buffer-string) "\n"))
  2892. line)
  2893. (while (setq line (pop lines))
  2894. (catch 'next
  2895. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2896. (setq org-agenda-info
  2897. (org-fix-agenda-info (text-properties-at 0 line)))
  2898. (princ
  2899. (mapconcat 'org-agenda-export-csv-mapper
  2900. '(org-category txt type todo tags date time extra
  2901. priority-letter priority agenda-day)
  2902. ","))
  2903. (princ "\n")))))
  2904. (defun org-fix-agenda-info (props)
  2905. "Make sure all properties on an agenda item have a canonical form.
  2906. This ensures the export commands can easily use it."
  2907. (let (tmp re)
  2908. (when (setq tmp (plist-get props 'tags))
  2909. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2910. (when (setq tmp (plist-get props 'date))
  2911. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2912. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2913. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2914. (setq tmp (calendar-date-string tmp)))
  2915. (setq props (plist-put props 'date tmp)))
  2916. (when (setq tmp (plist-get props 'day))
  2917. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2918. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2919. (setq tmp (calendar-date-string tmp)))
  2920. (setq props (plist-put props 'day tmp))
  2921. (setq props (plist-put props 'agenda-day tmp)))
  2922. (when (setq tmp (plist-get props 'txt))
  2923. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2924. (plist-put props 'priority-letter (match-string 1 tmp))
  2925. (setq tmp (replace-match "" t t tmp)))
  2926. (when (and (setq re (plist-get props 'org-todo-regexp))
  2927. (setq re (concat "\\`\\.*" re " ?"))
  2928. (string-match re tmp))
  2929. (plist-put props 'todo (match-string 1 tmp))
  2930. (setq tmp (replace-match "" t t tmp)))
  2931. (plist-put props 'txt tmp)))
  2932. props)
  2933. (defun org-agenda-export-csv-mapper (prop)
  2934. (let ((res (plist-get org-agenda-info prop)))
  2935. (setq res
  2936. (cond
  2937. ((not res) "")
  2938. ((stringp res) res)
  2939. (t (prin1-to-string res))))
  2940. (while (string-match "," res)
  2941. (setq res (replace-match ";" t t res)))
  2942. (org-trim res)))
  2943. ;;;###autoload
  2944. (defun org-store-agenda-views (&rest parameters)
  2945. "Store agenda views."
  2946. (interactive)
  2947. (eval (list 'org-batch-store-agenda-views)))
  2948. ;;;###autoload
  2949. (defmacro org-batch-store-agenda-views (&rest parameters)
  2950. "Run all custom agenda commands that have a file argument."
  2951. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2952. (pop-up-frames nil)
  2953. (dir default-directory)
  2954. (pars (org-make-parameter-alist parameters))
  2955. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2956. (save-window-excursion
  2957. (while cmds
  2958. (setq cmd (pop cmds)
  2959. thiscmdkey (car cmd)
  2960. thiscmdcmd (cdr cmd)
  2961. match (nth 2 thiscmdcmd)
  2962. bufname (if org-agenda-sticky
  2963. (or (and (stringp match)
  2964. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2965. (format "*Org Agenda(%s)*" thiscmdkey))
  2966. org-agenda-buffer-name)
  2967. cmd-or-set (nth 2 cmd)
  2968. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2969. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2970. (if (stringp files) (setq files (list files)))
  2971. (when files
  2972. (org-eval-in-environment (append org-agenda-exporter-settings
  2973. opts pars)
  2974. (org-agenda nil thiscmdkey))
  2975. (set-buffer bufname)
  2976. (while files
  2977. (org-eval-in-environment (append org-agenda-exporter-settings
  2978. opts pars)
  2979. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2980. (and (get-buffer bufname)
  2981. (kill-buffer bufname)))))))
  2982. (defvar org-agenda-current-span nil
  2983. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2984. (defun org-agenda-mark-header-line (pos)
  2985. "Mark the line at POS as an agenda structure header."
  2986. (save-excursion
  2987. (goto-char pos)
  2988. (put-text-property (point-at-bol) (point-at-eol)
  2989. 'org-agenda-structural-header t)
  2990. (when org-agenda-title-append
  2991. (put-text-property (point-at-bol) (point-at-eol)
  2992. 'org-agenda-title-append org-agenda-title-append))))
  2993. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2994. (defvar org-agenda-write-buffer-name "Agenda View")
  2995. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2996. "Write the current buffer (an agenda view) as a file.
  2997. Depending on the extension of the file name, plain text (.txt),
  2998. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2999. If the extension is .ics, run icalendar export over all files used
  3000. to construct the agenda and limit the export to entries listed in the
  3001. agenda now.
  3002. If the extension is .org, collect all subtrees corresponding to the
  3003. agenda entries and add them in an .org file.
  3004. With prefix argument OPEN, open the new file immediately.
  3005. If NOSETTINGS is given, do not scope the settings of
  3006. `org-agenda-exporter-settings' into the export commands. This is used when
  3007. the settings have already been scoped and we do not wish to overrule other,
  3008. higher priority settings.
  3009. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3010. (interactive "FWrite agenda to file: \nP")
  3011. (if (or (not (file-writable-p file))
  3012. (and (file-exists-p file)
  3013. (if (org-called-interactively-p 'any)
  3014. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3015. (user-error "Cannot write agenda to file %s" file))
  3016. (org-let (if nosettings nil org-agenda-exporter-settings)
  3017. '(save-excursion
  3018. (save-window-excursion
  3019. (let ((bs (copy-sequence (buffer-string))) beg content)
  3020. (with-temp-buffer
  3021. (rename-buffer org-agenda-write-buffer-name t)
  3022. (set-buffer-modified-p nil)
  3023. (insert bs)
  3024. (org-agenda-remove-marked-text 'org-filtered)
  3025. (run-hooks 'org-agenda-before-write-hook)
  3026. (cond
  3027. ((org-bound-and-true-p org-mobile-creating-agendas)
  3028. (org-mobile-write-agenda-for-mobile file))
  3029. ((string-match "\\.org\\'" file)
  3030. (let (content p m message-log-max)
  3031. (goto-char (point-min))
  3032. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3033. (goto-char p)
  3034. (setq m (get-text-property (point) 'org-hd-marker))
  3035. (when m
  3036. (push (save-excursion
  3037. (set-buffer (marker-buffer m))
  3038. (goto-char m)
  3039. (org-copy-subtree 1 nil t t)
  3040. org-subtree-clip)
  3041. content)))
  3042. (find-file file)
  3043. (erase-buffer)
  3044. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3045. (write-file file)
  3046. (kill-buffer (current-buffer))
  3047. (message "Org file written to %s" file)))
  3048. ((string-match "\\.html?\\'" file)
  3049. (require 'htmlize)
  3050. (set-buffer (htmlize-buffer (current-buffer)))
  3051. (when org-agenda-export-html-style
  3052. ;; replace <style> section with org-agenda-export-html-style
  3053. (goto-char (point-min))
  3054. (kill-region (- (search-forward "<style") 6)
  3055. (search-forward "</style>"))
  3056. (insert org-agenda-export-html-style))
  3057. (write-file file)
  3058. (kill-buffer (current-buffer))
  3059. (message "HTML written to %s" file))
  3060. ((string-match "\\.ps\\'" file)
  3061. (require 'ps-print)
  3062. (ps-print-buffer-with-faces file)
  3063. (message "Postscript written to %s" file))
  3064. ((string-match "\\.pdf\\'" file)
  3065. (require 'ps-print)
  3066. (ps-print-buffer-with-faces
  3067. (concat (file-name-sans-extension file) ".ps"))
  3068. (call-process "ps2pdf" nil nil nil
  3069. (expand-file-name
  3070. (concat (file-name-sans-extension file) ".ps"))
  3071. (expand-file-name file))
  3072. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3073. (message "PDF written to %s" file))
  3074. ((string-match "\\.ics\\'" file)
  3075. (require 'ox-icalendar)
  3076. (org-icalendar-export-current-agenda (expand-file-name file)))
  3077. (t
  3078. (let ((bs (buffer-string)))
  3079. (find-file file)
  3080. (erase-buffer)
  3081. (insert bs)
  3082. (save-buffer 0)
  3083. (kill-buffer (current-buffer))
  3084. (message "Plain text written to %s" file))))))))
  3085. (set-buffer (or agenda-bufname
  3086. (and (org-called-interactively-p 'any) (buffer-name))
  3087. org-agenda-buffer-name)))
  3088. (when open (org-open-file file)))
  3089. (defun org-agenda-remove-marked-text (property &optional value)
  3090. "Delete all text marked with VALUE of PROPERTY.
  3091. VALUE defaults to t."
  3092. (let (beg)
  3093. (setq value (or value t))
  3094. (while (setq beg (text-property-any (point-min) (point-max)
  3095. property value))
  3096. (delete-region
  3097. beg (or (next-single-property-change beg property)
  3098. (point-max))))))
  3099. (defun org-agenda-add-entry-text ()
  3100. "Add entry text to agenda lines.
  3101. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3102. entry text following headings shown in the agenda.
  3103. Drawers will be excluded, also the line with scheduling/deadline info."
  3104. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3105. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3106. (let (m txt)
  3107. (goto-char (point-min))
  3108. (while (not (eobp))
  3109. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3110. (beginning-of-line 2)
  3111. (setq txt (org-agenda-get-some-entry-text
  3112. m org-agenda-add-entry-text-maxlines " > "))
  3113. (end-of-line 1)
  3114. (if (string-match "\\S-" txt)
  3115. (insert "\n" txt)
  3116. (or (eobp) (forward-char 1))))))))
  3117. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3118. &rest keep)
  3119. "Extract entry text from MARKER, at most N-LINES lines.
  3120. This will ignore drawers etc, just get the text.
  3121. If INDENT is given, prefix every line with this string. If KEEP is
  3122. given, it is a list of symbols, defining stuff that should not be
  3123. removed from the entry content. Currently only `planning' is allowed here."
  3124. (let (txt drawer-re kwd-time-re ind)
  3125. (save-excursion
  3126. (with-current-buffer (marker-buffer marker)
  3127. (if (not (derived-mode-p 'org-mode))
  3128. (setq txt "")
  3129. (save-excursion
  3130. (save-restriction
  3131. (widen)
  3132. (goto-char marker)
  3133. (end-of-line 1)
  3134. (setq txt (buffer-substring
  3135. (min (1+ (point)) (point-max))
  3136. (progn (outline-next-heading) (point)))
  3137. drawer-re org-drawer-regexp
  3138. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3139. ".*\n?"))
  3140. (with-temp-buffer
  3141. (insert txt)
  3142. (when org-agenda-add-entry-text-descriptive-links
  3143. (goto-char (point-min))
  3144. (while (org-activate-bracket-links (point-max))
  3145. (add-text-properties (match-beginning 0) (match-end 0)
  3146. '(face org-link))))
  3147. (goto-char (point-min))
  3148. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3149. (set-text-properties (match-beginning 0) (match-end 0)
  3150. nil))
  3151. (goto-char (point-min))
  3152. (while (re-search-forward drawer-re nil t)
  3153. (delete-region
  3154. (match-beginning 0)
  3155. (progn (re-search-forward
  3156. "^[ \t]*:END:.*\n?" nil 'move)
  3157. (point))))
  3158. (unless (member 'planning keep)
  3159. (goto-char (point-min))
  3160. (while (re-search-forward kwd-time-re nil t)
  3161. (replace-match "")))
  3162. (goto-char (point-min))
  3163. (when org-agenda-entry-text-exclude-regexps
  3164. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3165. (while (setq re (pop re-list))
  3166. (goto-char (point-min))
  3167. (while (re-search-forward re nil t)
  3168. (replace-match "")))))
  3169. (goto-char (point-max))
  3170. (skip-chars-backward " \t\n")
  3171. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3172. ;; find and remove min common indentation
  3173. (goto-char (point-min))
  3174. (untabify (point-min) (point-max))
  3175. (setq ind (org-get-indentation))
  3176. (while (not (eobp))
  3177. (unless (looking-at "[ \t]*$")
  3178. (setq ind (min ind (org-get-indentation))))
  3179. (beginning-of-line 2))
  3180. (goto-char (point-min))
  3181. (while (not (eobp))
  3182. (unless (looking-at "[ \t]*$")
  3183. (move-to-column ind)
  3184. (delete-region (point-at-bol) (point)))
  3185. (beginning-of-line 2))
  3186. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3187. (goto-char (point-min))
  3188. (when indent
  3189. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3190. (replace-match indent t t)))
  3191. (goto-char (point-min))
  3192. (while (looking-at "[ \t]*\n") (replace-match ""))
  3193. (goto-char (point-max))
  3194. (when (> (org-current-line)
  3195. n-lines)
  3196. (org-goto-line (1+ n-lines))
  3197. (backward-char 1))
  3198. (setq txt (buffer-substring (point-min) (point)))))))))
  3199. txt))
  3200. (defun org-check-for-org-mode ()
  3201. "Make sure current buffer is in org-mode. Error if not."
  3202. (or (derived-mode-p 'org-mode)
  3203. (error "Cannot execute org-mode agenda command on buffer in %s"
  3204. major-mode)))
  3205. ;;; Agenda prepare and finalize
  3206. (defvar org-agenda-multi nil) ; dynamically scoped
  3207. (defvar org-agenda-pre-window-conf nil)
  3208. (defvar org-agenda-columns-active nil)
  3209. (defvar org-agenda-name nil)
  3210. (defvar org-agenda-tag-filter nil)
  3211. (defvar org-agenda-category-filter nil)
  3212. (defvar org-agenda-regexp-filter nil)
  3213. (defvar org-agenda-effort-filter nil)
  3214. (defvar org-agenda-top-headline-filter nil)
  3215. (defvar org-agenda-tag-filter-preset nil
  3216. "A preset of the tags filter used for secondary agenda filtering.
  3217. This must be a list of strings, each string must be a single tag preceded
  3218. by \"+\" or \"-\".
  3219. This variable should not be set directly, but agenda custom commands can
  3220. bind it in the options section. The preset filter is a global property of
  3221. the entire agenda view. In a block agenda, it will not work reliably to
  3222. define a filter for one of the individual blocks. You need to set it in
  3223. the global options and expect it to be applied to the entire view.")
  3224. (defvar org-agenda-category-filter-preset nil
  3225. "A preset of the category filter used for secondary agenda filtering.
  3226. This must be a list of strings, each string must be a single category
  3227. preceded by \"+\" or \"-\".
  3228. This variable should not be set directly, but agenda custom commands can
  3229. bind it in the options section. The preset filter is a global property of
  3230. the entire agenda view. In a block agenda, it will not work reliably to
  3231. define a filter for one of the individual blocks. You need to set it in
  3232. the global options and expect it to be applied to the entire view.")
  3233. (defvar org-agenda-regexp-filter-preset nil
  3234. "A preset of the regexp filter used for secondary agenda filtering.
  3235. This must be a list of strings, each string must be a single regexp
  3236. preceded by \"+\" or \"-\".
  3237. This variable should not be set directly, but agenda custom commands can
  3238. bind it in the options section. The preset filter is a global property of
  3239. the entire agenda view. In a block agenda, it will not work reliably to
  3240. define a filter for one of the individual blocks. You need to set it in
  3241. the global options and expect it to be applied to the entire view.")
  3242. (defvar org-agenda-effort-filter-preset nil
  3243. "A preset of the effort condition used for secondary agenda filtering.
  3244. This must be a list of strings, each string must be a single regexp
  3245. preceded by \"+\" or \"-\".
  3246. This variable should not be set directly, but agenda custom commands can
  3247. bind it in the options section. The preset filter is a global property of
  3248. the entire agenda view. In a block agenda, it will not work reliably to
  3249. define a filter for one of the individual blocks. You need to set it in
  3250. the global options and expect it to be applied to the entire view.")
  3251. (defun org-agenda-use-sticky-p ()
  3252. "Return non-nil if an agenda buffer named
  3253. `org-agenda-buffer-name' exists and should be shown instead of
  3254. generating a new one."
  3255. (and
  3256. ;; turned off by user
  3257. org-agenda-sticky
  3258. ;; For multi-agenda buffer already exists
  3259. (not org-agenda-multi)
  3260. ;; buffer found
  3261. (get-buffer org-agenda-buffer-name)
  3262. ;; C-u parameter is same as last call
  3263. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3264. (and
  3265. (equal current-prefix-arg
  3266. org-agenda-last-prefix-arg)
  3267. ;; In case user turned stickiness on, while having existing
  3268. ;; Agenda buffer active, don't reuse that buffer, because it
  3269. ;; does not have org variables local
  3270. org-agenda-this-buffer-is-sticky))))
  3271. (defun org-agenda-prepare-window (abuf filter-alist)
  3272. "Setup agenda buffer in the window.
  3273. ABUF is the buffer for the agenda window.
  3274. FILTER-ALIST is an alist of filters we need to apply when
  3275. `org-agenda-persistent-filter' is non-nil."
  3276. (let* ((awin (get-buffer-window abuf)) wconf)
  3277. (cond
  3278. ((equal (current-buffer) abuf) nil)
  3279. (awin (select-window awin))
  3280. ((not (setq wconf (current-window-configuration))))
  3281. ((equal org-agenda-window-setup 'current-window)
  3282. (org-pop-to-buffer-same-window abuf))
  3283. ((equal org-agenda-window-setup 'other-window)
  3284. (org-switch-to-buffer-other-window abuf))
  3285. ((equal org-agenda-window-setup 'other-frame)
  3286. (switch-to-buffer-other-frame abuf))
  3287. ((equal org-agenda-window-setup 'reorganize-frame)
  3288. (delete-other-windows)
  3289. (org-switch-to-buffer-other-window abuf)))
  3290. (setq org-agenda-tag-filter (cdr (assoc 'tag filter-alist)))
  3291. (setq org-agenda-category-filter (cdr (assoc 'cat filter-alist)))
  3292. (setq org-agenda-effort-filter (cdr (assoc 'effort filter-alist)))
  3293. (setq org-agenda-regexp-filter (cdr (assoc 're filter-alist)))
  3294. ;; Additional test in case agenda is invoked from within agenda
  3295. ;; buffer via elisp link.
  3296. (unless (equal (current-buffer) abuf)
  3297. (org-pop-to-buffer-same-window abuf))
  3298. (setq org-agenda-pre-window-conf
  3299. (or org-agenda-pre-window-conf wconf))))
  3300. (defun org-agenda-prepare (&optional name)
  3301. (let ((filter-alist (if org-agenda-persistent-filter
  3302. (list `(tag . ,org-agenda-tag-filter)
  3303. `(re . ,org-agenda-regexp-filter)
  3304. `(effort . ,org-agenda-effort-filter)
  3305. `(car . ,org-agenda-category-filter)))))
  3306. (if (org-agenda-use-sticky-p)
  3307. (progn
  3308. (put 'org-agenda-tag-filter :preset-filter nil)
  3309. (put 'org-agenda-category-filter :preset-filter nil)
  3310. (put 'org-agenda-regexp-filter :preset-filter nil)
  3311. ;; Popup existing buffer
  3312. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3313. filter-alist)
  3314. (message "Sticky Agenda buffer, use `r' to refresh")
  3315. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3316. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3317. (setq org-todo-keywords-for-agenda nil)
  3318. (put 'org-agenda-tag-filter :preset-filter
  3319. org-agenda-tag-filter-preset)
  3320. (put 'org-agenda-category-filter :preset-filter
  3321. org-agenda-category-filter-preset)
  3322. (put 'org-agenda-regexp-filter :preset-filter
  3323. org-agenda-regexp-filter-preset)
  3324. (put 'org-agenda-effort-filter :preset-filter
  3325. org-agenda-effort-filter-preset)
  3326. (if org-agenda-multi
  3327. (progn
  3328. (setq buffer-read-only nil)
  3329. (goto-char (point-max))
  3330. (unless (or (bobp) org-agenda-compact-blocks
  3331. (not org-agenda-block-separator))
  3332. (insert "\n"
  3333. (if (stringp org-agenda-block-separator)
  3334. org-agenda-block-separator
  3335. (make-string (window-width) org-agenda-block-separator))
  3336. "\n"))
  3337. (narrow-to-region (point) (point-max)))
  3338. (setq org-done-keywords-for-agenda nil)
  3339. ;; Setting any org variables that are in org-agenda-local-vars
  3340. ;; list need to be done after the prepare call
  3341. (org-agenda-prepare-window
  3342. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3343. (setq buffer-read-only nil)
  3344. (org-agenda-reset-markers)
  3345. (let ((inhibit-read-only t)) (erase-buffer))
  3346. (org-agenda-mode)
  3347. (setq org-agenda-buffer (current-buffer))
  3348. (setq org-agenda-contributing-files nil)
  3349. (setq org-agenda-columns-active nil)
  3350. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3351. (setq org-todo-keywords-for-agenda
  3352. (org-uniquify org-todo-keywords-for-agenda))
  3353. (setq org-done-keywords-for-agenda
  3354. (org-uniquify org-done-keywords-for-agenda))
  3355. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3356. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3357. (and name (not org-agenda-name)
  3358. (org-set-local 'org-agenda-name name)))
  3359. (setq buffer-read-only nil))))
  3360. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3361. (defun org-agenda-finalize ()
  3362. "Finishing touch for the agenda buffer, called just before displaying it."
  3363. (unless org-agenda-multi
  3364. (save-excursion
  3365. (let ((inhibit-read-only t))
  3366. (goto-char (point-min))
  3367. (save-excursion
  3368. (while (org-activate-bracket-links (point-max))
  3369. (add-text-properties (match-beginning 0) (match-end 0)
  3370. '(face org-link))))
  3371. (save-excursion
  3372. (while (org-activate-plain-links (point-max))
  3373. (add-text-properties (match-beginning 0) (match-end 0)
  3374. '(face org-link))))
  3375. (unless (eq org-agenda-remove-tags t)
  3376. (org-agenda-align-tags))
  3377. (unless org-agenda-with-colors
  3378. (remove-text-properties (point-min) (point-max) '(face nil)))
  3379. (if (and (boundp 'org-agenda-overriding-columns-format)
  3380. org-agenda-overriding-columns-format)
  3381. (org-set-local 'org-agenda-overriding-columns-format
  3382. org-agenda-overriding-columns-format))
  3383. (if (and (boundp 'org-agenda-view-columns-initially)
  3384. org-agenda-view-columns-initially)
  3385. (org-agenda-columns))
  3386. (when org-agenda-fontify-priorities
  3387. (org-agenda-fontify-priorities))
  3388. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3389. (org-agenda-dim-blocked-tasks))
  3390. (org-agenda-mark-clocking-task)
  3391. (when org-agenda-entry-text-mode
  3392. (org-agenda-entry-text-hide)
  3393. (org-agenda-entry-text-show))
  3394. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3395. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3396. (org-habit-insert-consistency-graphs))
  3397. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3398. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3399. (and (listp org-agenda-show-inherited-tags)
  3400. (memq org-agenda-type org-agenda-show-inherited-tags))
  3401. (and (eq org-agenda-show-inherited-tags t)
  3402. (or (eq org-agenda-use-tag-inheritance t)
  3403. (and (listp org-agenda-use-tag-inheritance)
  3404. (not (memq org-agenda-type
  3405. org-agenda-use-tag-inheritance))))))
  3406. (let (mrk)
  3407. (save-excursion
  3408. (goto-char (point-min))
  3409. (while (equal (forward-line) 0)
  3410. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3411. (put-text-property (point-at-bol) (point-at-eol)
  3412. 'tags (org-with-point-at mrk
  3413. (delete-dups
  3414. (mapcar 'downcase (org-get-tags-at))))))))))
  3415. (run-hooks 'org-agenda-finalize-hook)
  3416. (when org-agenda-top-headline-filter
  3417. (org-agenda-filter-top-headline-apply
  3418. org-agenda-top-headline-filter))
  3419. (when org-agenda-tag-filter
  3420. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3421. (when (get 'org-agenda-tag-filter :preset-filter)
  3422. (org-agenda-filter-apply
  3423. (get 'org-agenda-tag-filter :preset-filter) 'tag))
  3424. (when org-agenda-category-filter
  3425. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3426. (when (get 'org-agenda-category-filter :preset-filter)
  3427. (org-agenda-filter-apply
  3428. (get 'org-agenda-category-filter :preset-filter) 'category))
  3429. (when org-agenda-regexp-filter
  3430. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3431. (when (get 'org-agenda-regexp-filter :preset-filter)
  3432. (org-agenda-filter-apply
  3433. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3434. (when org-agenda-effort-filter
  3435. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3436. (when (get 'org-agenda-effort-filter :preset-filter)
  3437. (org-agenda-filter-apply
  3438. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3439. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3440. (defun org-agenda-mark-clocking-task ()
  3441. "Mark the current clock entry in the agenda if it is present."
  3442. ;; We need to widen when `org-agenda-finalize' is called from
  3443. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3444. (when org-clock-current-task
  3445. (save-restriction
  3446. (widen)
  3447. (org-agenda-unmark-clocking-task)
  3448. (when (marker-buffer org-clock-hd-marker)
  3449. (save-excursion
  3450. (goto-char (point-min))
  3451. (let (s ov)
  3452. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3453. (goto-char s)
  3454. (when (equal (org-get-at-bol 'org-hd-marker)
  3455. org-clock-hd-marker)
  3456. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3457. (overlay-put ov 'type 'org-agenda-clocking)
  3458. (overlay-put ov 'face 'org-agenda-clocking)
  3459. (overlay-put ov 'help-echo
  3460. "The clock is running in this item")))))))))
  3461. (defun org-agenda-unmark-clocking-task ()
  3462. "Unmark the current clocking task."
  3463. (mapc (lambda (o)
  3464. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3465. (delete-overlay o)))
  3466. (overlays-in (point-min) (point-max))))
  3467. (defun org-agenda-fontify-priorities ()
  3468. "Make highest priority lines bold, and lowest italic."
  3469. (interactive)
  3470. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3471. (delete-overlay o)))
  3472. (overlays-in (point-min) (point-max)))
  3473. (save-excursion
  3474. (let (b e p ov h l)
  3475. (goto-char (point-min))
  3476. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3477. (setq h (or (get-char-property (point) 'org-highest-priority)
  3478. org-highest-priority)
  3479. l (or (get-char-property (point) 'org-lowest-priority)
  3480. org-lowest-priority)
  3481. p (string-to-char (match-string 1))
  3482. b (match-beginning 0)
  3483. e (if (eq org-agenda-fontify-priorities 'cookies)
  3484. (match-end 0)
  3485. (point-at-eol))
  3486. ov (make-overlay b e))
  3487. (overlay-put
  3488. ov 'face
  3489. (cons (cond ((org-face-from-face-or-color
  3490. 'priority nil
  3491. (cdr (assoc p org-priority-faces))))
  3492. ((and (listp org-agenda-fontify-priorities)
  3493. (org-face-from-face-or-color
  3494. 'priority nil
  3495. (cdr (assoc p org-agenda-fontify-priorities)))))
  3496. ((equal p l) 'italic)
  3497. ((equal p h) 'bold))
  3498. 'org-priority))
  3499. (overlay-put ov 'org-type 'org-priority)))))
  3500. (defvar org-depend-tag-blocked)
  3501. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3502. "Dim currently blocked TODO's in the agenda display.
  3503. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3504. dimming them."
  3505. (interactive "P")
  3506. (when (org-called-interactively-p 'interactive)
  3507. (message "Dim or hide blocked tasks..."))
  3508. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3509. (delete-overlay o)))
  3510. (overlays-in (point-min) (point-max)))
  3511. (save-excursion
  3512. (let ((inhibit-read-only t)
  3513. (org-depend-tag-blocked nil)
  3514. (invis (or (not (null invisible))
  3515. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3516. org-blocked-by-checkboxes
  3517. invis1 b e p ov h l)
  3518. (goto-char (point-min))
  3519. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3520. (and pos (goto-char (1+ pos))))
  3521. (setq org-blocked-by-checkboxes nil invis1 invis)
  3522. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3523. (when (and marker
  3524. (with-current-buffer (marker-buffer marker)
  3525. (save-excursion (goto-char marker)
  3526. (org-entry-blocked-p))))
  3527. (if org-blocked-by-checkboxes (setq invis1 nil))
  3528. (setq b (if invis1
  3529. (max (point-min) (1- (point-at-bol)))
  3530. (point-at-bol))
  3531. e (point-at-eol)
  3532. ov (make-overlay b e))
  3533. (if invis1
  3534. (progn (overlay-put ov 'invisible t)
  3535. (overlay-put ov 'intangible t))
  3536. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3537. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3538. (when (org-called-interactively-p 'interactive)
  3539. (message "Dim or hide blocked tasks...done")))
  3540. (defvar org-agenda-skip-function nil
  3541. "Function to be called at each match during agenda construction.
  3542. If this function returns nil, the current match should not be skipped.
  3543. Otherwise, the function must return a position from where the search
  3544. should be continued.
  3545. This may also be a Lisp form, it will be evaluated.
  3546. Never set this variable using `setq' or so, because then it will apply
  3547. to all future agenda commands. If you do want a global skipping condition,
  3548. use the option `org-agenda-skip-function-global' instead.
  3549. The correct usage for `org-agenda-skip-function' is to bind it with
  3550. `let' to scope it dynamically into the agenda-constructing command.
  3551. A good way to set it is through options in `org-agenda-custom-commands'.")
  3552. (defun org-agenda-skip ()
  3553. "Throw to `:skip' in places that should be skipped.
  3554. Also moves point to the end of the skipped region, so that search can
  3555. continue from there."
  3556. (let ((p (point-at-bol)) to)
  3557. (when (or
  3558. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3559. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3560. (get-text-property p :org-archived)
  3561. (org-end-of-subtree t))
  3562. (and org-agenda-skip-comment-trees
  3563. (get-text-property p :org-comment)
  3564. (org-end-of-subtree t))
  3565. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3566. (org-agenda-skip-eval org-agenda-skip-function)))
  3567. (goto-char to))
  3568. (org-in-src-block-p t))
  3569. (throw :skip t))))
  3570. (defun org-agenda-skip-eval (form)
  3571. "If FORM is a function or a list, call (or eval) it and return the result.
  3572. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3573. and match data are returned to the previous state no matter what these
  3574. functions do."
  3575. (let (fp)
  3576. (and form
  3577. (or (setq fp (functionp form))
  3578. (consp form))
  3579. (save-excursion
  3580. (save-match-data
  3581. (if fp
  3582. (funcall form)
  3583. (eval form)))))))
  3584. (defvar org-agenda-markers nil
  3585. "List of all currently active markers created by `org-agenda'.")
  3586. (defvar org-agenda-last-marker-time (org-float-time)
  3587. "Creation time of the last agenda marker.")
  3588. (defun org-agenda-new-marker (&optional pos)
  3589. "Return a new agenda marker.
  3590. Org-mode keeps a list of these markers and resets them when they are
  3591. no longer in use."
  3592. (let ((m (copy-marker (or pos (point)))))
  3593. (setq org-agenda-last-marker-time (org-float-time))
  3594. (if org-agenda-buffer
  3595. (with-current-buffer org-agenda-buffer
  3596. (push m org-agenda-markers))
  3597. (push m org-agenda-markers))
  3598. m))
  3599. (defun org-agenda-reset-markers ()
  3600. "Reset markers created by `org-agenda'."
  3601. (while org-agenda-markers
  3602. (move-marker (pop org-agenda-markers) nil)))
  3603. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3604. "Save relative positions of markers in region.
  3605. This check for agenda markers in all agenda buffers currently active."
  3606. (dolist (buf (buffer-list))
  3607. (with-current-buffer buf
  3608. (when (eq major-mode 'org-agenda-mode)
  3609. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3610. org-agenda-markers)))))
  3611. ;;; Entry text mode
  3612. (defun org-agenda-entry-text-show-here ()
  3613. "Add some text from the entry as context to the current line."
  3614. (let (m txt o)
  3615. (setq m (org-get-at-bol 'org-hd-marker))
  3616. (unless (marker-buffer m)
  3617. (error "No marker points to an entry here"))
  3618. (setq txt (concat "\n" (org-no-properties
  3619. (org-agenda-get-some-entry-text
  3620. m org-agenda-entry-text-maxlines
  3621. org-agenda-entry-text-leaders))))
  3622. (when (string-match "\\S-" txt)
  3623. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3624. (overlay-put o 'evaporate t)
  3625. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3626. (overlay-put o 'after-string txt))))
  3627. (defun org-agenda-entry-text-show ()
  3628. "Add entry context for all agenda lines."
  3629. (interactive)
  3630. (save-excursion
  3631. (goto-char (point-max))
  3632. (beginning-of-line 1)
  3633. (while (not (bobp))
  3634. (when (org-get-at-bol 'org-hd-marker)
  3635. (org-agenda-entry-text-show-here))
  3636. (beginning-of-line 0))))
  3637. (defun org-agenda-entry-text-hide ()
  3638. "Remove any shown entry context."
  3639. (delq nil
  3640. (mapcar (lambda (o)
  3641. (if (eq (overlay-get o 'org-overlay-type)
  3642. 'agenda-entry-content)
  3643. (progn (delete-overlay o) t)))
  3644. (overlays-in (point-min) (point-max)))))
  3645. (defun org-agenda-get-day-face (date)
  3646. "Return the face DATE should be displayed with."
  3647. (or (and (functionp org-agenda-day-face-function)
  3648. (funcall org-agenda-day-face-function date))
  3649. (cond ((org-agenda-todayp date)
  3650. 'org-agenda-date-today)
  3651. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3652. 'org-agenda-date-weekend)
  3653. (t 'org-agenda-date))))
  3654. ;;; Agenda timeline
  3655. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3656. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3657. (defun org-timeline (&optional dotodo)
  3658. "Show a time-sorted view of the entries in the current org file.
  3659. Only entries with a time stamp of today or later will be listed. With
  3660. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3661. under the current date.
  3662. If the buffer contains an active region, only check the region for
  3663. dates."
  3664. (interactive "P")
  3665. (let* ((dopast t)
  3666. (org-agenda-show-log-scoped org-agenda-show-log)
  3667. (org-agenda-show-log org-agenda-show-log-scoped)
  3668. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3669. (current-buffer))))
  3670. (date (calendar-current-date))
  3671. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3672. (end (if (org-region-active-p) (region-end) (point-max)))
  3673. (day-numbers (org-get-all-dates
  3674. beg end 'no-ranges
  3675. t org-agenda-show-log-scoped ; always include today
  3676. org-timeline-show-empty-dates))
  3677. (org-deadline-warning-days 0)
  3678. (org-agenda-only-exact-dates t)
  3679. (today (org-today))
  3680. (past t)
  3681. args
  3682. s e rtn d emptyp)
  3683. (setq org-agenda-redo-command
  3684. (list 'let
  3685. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3686. (list 'org-switch-to-buffer-other-window (current-buffer))
  3687. (list 'org-timeline (list 'quote dotodo))))
  3688. (put 'org-agenda-redo-command 'org-lprops nil)
  3689. (if (not dopast)
  3690. ;; Remove past dates from the list of dates.
  3691. (setq day-numbers (delq nil (mapcar (lambda(x)
  3692. (if (>= x today) x nil))
  3693. day-numbers))))
  3694. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3695. (org-compile-prefix-format 'timeline)
  3696. (org-set-sorting-strategy 'timeline)
  3697. (if org-agenda-show-log-scoped (push :closed args))
  3698. (push :timestamp args)
  3699. (push :deadline args)
  3700. (push :scheduled args)
  3701. (push :sexp args)
  3702. (if dotodo (push :todo args))
  3703. (insert "Timeline of file " entry "\n")
  3704. (add-text-properties (point-min) (point)
  3705. (list 'face 'org-agenda-structure))
  3706. (org-agenda-mark-header-line (point-min))
  3707. (while (setq d (pop day-numbers))
  3708. (if (and (listp d) (eq (car d) :omitted))
  3709. (progn
  3710. (setq s (point))
  3711. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3712. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3713. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3714. (if (and (>= d today)
  3715. dopast
  3716. past)
  3717. (progn
  3718. (setq past nil)
  3719. (insert (make-string 79 ?-) "\n")))
  3720. (setq date (calendar-gregorian-from-absolute d))
  3721. (setq s (point))
  3722. (setq rtn (and (not emptyp)
  3723. (apply 'org-agenda-get-day-entries entry
  3724. date args)))
  3725. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3726. (progn
  3727. (insert
  3728. (if (stringp org-agenda-format-date)
  3729. (format-time-string org-agenda-format-date
  3730. (org-time-from-absolute date))
  3731. (funcall org-agenda-format-date date))
  3732. "\n")
  3733. (put-text-property s (1- (point)) 'face
  3734. (org-agenda-get-day-face date))
  3735. (put-text-property s (1- (point)) 'org-date-line t)
  3736. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3737. (if (equal d today)
  3738. (put-text-property s (1- (point)) 'org-today t))
  3739. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3740. (put-text-property s (1- (point)) 'day d)))))
  3741. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3742. (point-min)))
  3743. (add-text-properties
  3744. (point-min) (point-max)
  3745. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3746. (org-agenda-finalize)
  3747. (setq buffer-read-only t)))
  3748. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3749. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3750. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3751. not every single day in the range. If FORCE-TODAY is non-nil, make
  3752. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3753. inactive time stamps (those in square brackets) are included.
  3754. When EMPTY is non-nil, also include days without any entries."
  3755. (let ((re (concat
  3756. (if pre-re pre-re "")
  3757. (if inactive org-ts-regexp-both org-ts-regexp)))
  3758. dates dates1 date day day1 day2 ts1 ts2 pos)
  3759. (if force-today
  3760. (setq dates (list (org-today))))
  3761. (save-excursion
  3762. (goto-char beg)
  3763. (while (re-search-forward re end t)
  3764. (setq day (time-to-days (org-time-string-to-time
  3765. (substring (match-string 1) 0 10)
  3766. (current-buffer) (match-beginning 0))))
  3767. (or (memq day dates) (push day dates)))
  3768. (unless no-ranges
  3769. (goto-char beg)
  3770. (while (re-search-forward org-tr-regexp end t)
  3771. (setq pos (match-beginning 0))
  3772. (setq ts1 (substring (match-string 1) 0 10)
  3773. ts2 (substring (match-string 2) 0 10)
  3774. day1 (time-to-days (org-time-string-to-time
  3775. ts1 (current-buffer) pos))
  3776. day2 (time-to-days (org-time-string-to-time
  3777. ts2 (current-buffer) pos)))
  3778. (while (< (setq day1 (1+ day1)) day2)
  3779. (or (memq day1 dates) (push day1 dates)))))
  3780. (setq dates (sort dates '<))
  3781. (when empty
  3782. (while (setq day (pop dates))
  3783. (setq day2 (car dates))
  3784. (push day dates1)
  3785. (when (and day2 empty)
  3786. (if (or (eq empty t)
  3787. (and (numberp empty) (<= (- day2 day) empty)))
  3788. (while (< (setq day (1+ day)) day2)
  3789. (push (list day) dates1))
  3790. (push (cons :omitted (- day2 day)) dates1))))
  3791. (setq dates (nreverse dates1)))
  3792. dates)))
  3793. ;;; Agenda Daily/Weekly
  3794. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3795. "Start day for the agenda view.
  3796. Custom commands can set this variable in the options section.
  3797. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3798. input allowed when reading a date through the Org calendar.
  3799. See the docstring of `org-read-date' for details.")
  3800. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3801. (defvar org-arg-loc nil) ; local variable
  3802. (defvar org-agenda-buffer-tmp-name nil)
  3803. ;;;###autoload
  3804. (defun org-agenda-list (&optional arg start-day span with-hour)
  3805. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3806. The view will be for the current day or week, but from the overview buffer
  3807. you will be able to go to other days/weeks.
  3808. With a numeric prefix argument in an interactive call, the agenda will
  3809. span ARG days. Lisp programs should instead specify SPAN to change
  3810. the number of days. SPAN defaults to `org-agenda-span'.
  3811. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3812. given in `org-agenda-start-on-weekday'.
  3813. When WITH-HOUR is non-nil, only include scheduled and deadline
  3814. items if they have an hour specification like [h]h:mm."
  3815. (interactive "P")
  3816. (if org-agenda-overriding-arguments
  3817. (setq arg (car org-agenda-overriding-arguments)
  3818. start-day (nth 1 org-agenda-overriding-arguments)
  3819. span (nth 2 org-agenda-overriding-arguments)))
  3820. (if (and (integerp arg) (> arg 0))
  3821. (setq span arg arg nil))
  3822. (catch 'exit
  3823. (setq org-agenda-buffer-name
  3824. (or org-agenda-buffer-tmp-name
  3825. (if org-agenda-sticky
  3826. (cond ((and org-keys (stringp org-match))
  3827. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3828. (org-keys
  3829. (format "*Org Agenda(%s)*" org-keys))
  3830. (t "*Org Agenda(a)*")))
  3831. org-agenda-buffer-name))
  3832. (org-agenda-prepare "Day/Week")
  3833. (setq start-day (or start-day org-agenda-start-day))
  3834. (if (stringp start-day)
  3835. ;; Convert to an absolute day number
  3836. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3837. (org-compile-prefix-format 'agenda)
  3838. (org-set-sorting-strategy 'agenda)
  3839. (let* ((span (org-agenda-ndays-to-span
  3840. (or span org-agenda-ndays org-agenda-span)))
  3841. (today (org-today))
  3842. (sd (or start-day today))
  3843. (ndays (org-agenda-span-to-ndays span sd))
  3844. (org-agenda-start-on-weekday
  3845. (if (or (eq ndays 7) (eq ndays 14))
  3846. org-agenda-start-on-weekday))
  3847. (thefiles (org-agenda-files nil 'ifmode))
  3848. (files thefiles)
  3849. (start (if (or (null org-agenda-start-on-weekday)
  3850. (< ndays 7))
  3851. sd
  3852. (let* ((nt (calendar-day-of-week
  3853. (calendar-gregorian-from-absolute sd)))
  3854. (n1 org-agenda-start-on-weekday)
  3855. (d (- nt n1)))
  3856. (- sd (+ (if (< d 0) 7 0) d)))))
  3857. (day-numbers (list start))
  3858. (day-cnt 0)
  3859. (inhibit-redisplay (not debug-on-error))
  3860. (org-agenda-show-log-scoped org-agenda-show-log)
  3861. s e rtn rtnall file date d start-pos end-pos todayp
  3862. clocktable-start clocktable-end filter)
  3863. (setq org-agenda-redo-command
  3864. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3865. (dotimes (n (1- ndays))
  3866. (push (1+ (car day-numbers)) day-numbers))
  3867. (setq day-numbers (nreverse day-numbers))
  3868. (setq clocktable-start (car day-numbers)
  3869. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3870. (org-set-local 'org-starting-day (car day-numbers))
  3871. (org-set-local 'org-arg-loc arg)
  3872. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3873. (unless org-agenda-compact-blocks
  3874. (let* ((d1 (car day-numbers))
  3875. (d2 (org-last day-numbers))
  3876. (w1 (org-days-to-iso-week d1))
  3877. (w2 (org-days-to-iso-week d2)))
  3878. (setq s (point))
  3879. (if org-agenda-overriding-header
  3880. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3881. nil 'face 'org-agenda-structure) "\n")
  3882. (insert (org-agenda-span-name span)
  3883. "-agenda"
  3884. (if (< (- d2 d1) 350)
  3885. (if (= w1 w2)
  3886. (format " (W%02d)" w1)
  3887. (format " (W%02d-W%02d)" w1 w2))
  3888. "")
  3889. ":\n")))
  3890. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3891. 'org-date-line t))
  3892. (org-agenda-mark-header-line s))
  3893. (while (setq d (pop day-numbers))
  3894. (setq date (calendar-gregorian-from-absolute d)
  3895. s (point))
  3896. (if (or (setq todayp (= d today))
  3897. (and (not start-pos) (= d sd)))
  3898. (setq start-pos (point))
  3899. (if (and start-pos (not end-pos))
  3900. (setq end-pos (point))))
  3901. (setq files thefiles
  3902. rtnall nil)
  3903. (while (setq file (pop files))
  3904. (catch 'nextfile
  3905. (org-check-agenda-file file)
  3906. (let ((org-agenda-entry-types org-agenda-entry-types))
  3907. ;; Starred types override non-starred equivalents
  3908. (when (member :deadline* org-agenda-entry-types)
  3909. (setq org-agenda-entry-types
  3910. (delq :deadline org-agenda-entry-types)))
  3911. (when (member :scheduled* org-agenda-entry-types)
  3912. (setq org-agenda-entry-types
  3913. (delq :scheduled org-agenda-entry-types)))
  3914. ;; Honor with-hour
  3915. (when with-hour
  3916. (when (member :deadline org-agenda-entry-types)
  3917. (setq org-agenda-entry-types
  3918. (delq :deadline org-agenda-entry-types))
  3919. (push :deadline* org-agenda-entry-types))
  3920. (when (member :scheduled org-agenda-entry-types)
  3921. (setq org-agenda-entry-types
  3922. (delq :scheduled org-agenda-entry-types))
  3923. (push :scheduled* org-agenda-entry-types)))
  3924. (unless org-agenda-include-deadlines
  3925. (setq org-agenda-entry-types
  3926. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3927. (cond
  3928. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3929. (setq rtn (org-agenda-get-day-entries
  3930. file date :closed)))
  3931. (org-agenda-show-log-scoped
  3932. (setq rtn (apply 'org-agenda-get-day-entries
  3933. file date
  3934. (append '(:closed) org-agenda-entry-types))))
  3935. (t
  3936. (setq rtn (apply 'org-agenda-get-day-entries
  3937. file date
  3938. org-agenda-entry-types)))))
  3939. (setq rtnall (append rtnall rtn)))) ;; all entries
  3940. (if org-agenda-include-diary
  3941. (let ((org-agenda-search-headline-for-time t))
  3942. (require 'diary-lib)
  3943. (setq rtn (org-get-entries-from-diary date))
  3944. (setq rtnall (append rtnall rtn))))
  3945. (if (or rtnall org-agenda-show-all-dates)
  3946. (progn
  3947. (setq day-cnt (1+ day-cnt))
  3948. (insert
  3949. (if (stringp org-agenda-format-date)
  3950. (format-time-string org-agenda-format-date
  3951. (org-time-from-absolute date))
  3952. (funcall org-agenda-format-date date))
  3953. "\n")
  3954. (put-text-property s (1- (point)) 'face
  3955. (org-agenda-get-day-face date))
  3956. (put-text-property s (1- (point)) 'org-date-line t)
  3957. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3958. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3959. (when todayp
  3960. (put-text-property s (1- (point)) 'org-today t))
  3961. (setq rtnall
  3962. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3963. (if rtnall (insert ;; all entries
  3964. (org-agenda-finalize-entries rtnall 'agenda)
  3965. "\n"))
  3966. (put-text-property s (1- (point)) 'day d)
  3967. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3968. (when (and org-agenda-clockreport-mode clocktable-start)
  3969. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3970. ;; the above line is to ensure the restricted range!
  3971. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3972. tbl)
  3973. (setq p (org-plist-delete p :block))
  3974. (setq p (plist-put p :tstart clocktable-start))
  3975. (setq p (plist-put p :tend clocktable-end))
  3976. (setq p (plist-put p :scope 'agenda))
  3977. (setq tbl (apply 'org-clock-get-clocktable p))
  3978. (insert tbl)))
  3979. (goto-char (point-min))
  3980. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3981. (unless (and (pos-visible-in-window-p (point-min))
  3982. (pos-visible-in-window-p (point-max)))
  3983. (goto-char (1- (point-max)))
  3984. (recenter -1)
  3985. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3986. (progn
  3987. (goto-char (or start-pos 1))
  3988. (recenter 1))))
  3989. (goto-char (or start-pos 1))
  3990. (add-text-properties (point-min) (point-max)
  3991. `(org-agenda-type agenda
  3992. org-last-args (,arg ,start-day ,span)
  3993. org-redo-cmd ,org-agenda-redo-command
  3994. org-series-cmd ,org-cmd))
  3995. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3996. (org-agenda-show-clocking-issues))
  3997. (org-agenda-finalize)
  3998. (setq buffer-read-only t)
  3999. (message ""))))
  4000. (defun org-agenda-ndays-to-span (n)
  4001. "Return a span symbol for a span of N days, or N if none matches."
  4002. (cond ((symbolp n) n)
  4003. ((= n 1) 'day)
  4004. ((= n 7) 'week)
  4005. ((= n 14) 'fortnight)
  4006. (t n)))
  4007. (defun org-agenda-span-to-ndays (span &optional start-day)
  4008. "Return ndays from SPAN, possibly starting at START-DAY.
  4009. START-DAY is an absolute time value."
  4010. (cond ((numberp span) span)
  4011. ((eq span 'day) 1)
  4012. ((eq span 'week) 7)
  4013. ((eq span 'fortnight) 14)
  4014. ((eq span 'month)
  4015. (let ((date (calendar-gregorian-from-absolute start-day)))
  4016. (calendar-last-day-of-month (car date) (caddr date))))
  4017. ((eq span 'year)
  4018. (let ((date (calendar-gregorian-from-absolute start-day)))
  4019. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  4020. (defun org-agenda-span-name (span)
  4021. "Return a SPAN name."
  4022. (if (null span)
  4023. ""
  4024. (if (symbolp span)
  4025. (capitalize (symbol-name span))
  4026. (format "%d days" span))))
  4027. ;;; Agenda word search
  4028. (defvar org-agenda-search-history nil)
  4029. (defvar org-search-syntax-table nil
  4030. "Special syntax table for org-mode search.
  4031. In this table, we have single quotes not as word constituents, to
  4032. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4033. (defvar org-mode-syntax-table) ; From org.el
  4034. (defun org-search-syntax-table ()
  4035. (unless org-search-syntax-table
  4036. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4037. (modify-syntax-entry ?' "." org-search-syntax-table)
  4038. (modify-syntax-entry ?` "." org-search-syntax-table))
  4039. org-search-syntax-table)
  4040. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4041. ;;;###autoload
  4042. (defun org-search-view (&optional todo-only string edit-at)
  4043. "Show all entries that contain a phrase or words or regular expressions.
  4044. With optional prefix argument TODO-ONLY, only consider entries that are
  4045. TODO entries. The argument STRING can be used to pass a default search
  4046. string into this function. If EDIT-AT is non-nil, it means that the
  4047. user should get a chance to edit this string, with cursor at position
  4048. EDIT-AT.
  4049. The search string can be viewed either as a phrase that should be found as
  4050. is, or it can be broken into a number of snippets, each of which must match
  4051. in a Boolean way to select an entry. The default depends on the variable
  4052. `org-agenda-search-view-always-boolean'.
  4053. Even if this is turned off (the default) you can always switch to
  4054. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4055. The default is a direct search of the whole phrase, where each space in
  4056. the search string can expand to an arbitrary amount of whitespace,
  4057. including newlines.
  4058. If using a Boolean search, the search string is split on whitespace and
  4059. each snippet is searched separately, with logical AND to select an entry.
  4060. Words prefixed with a minus must *not* occur in the entry. Words without
  4061. a prefix or prefixed with a plus must occur in the entry. Matching is
  4062. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4063. match whole words, not parts of a word) if
  4064. `org-agenda-search-view-force-full-words' is set (default is nil).
  4065. Boolean search snippets enclosed by curly braces are interpreted as
  4066. regular expressions that must or (when preceded with \"-\") must not
  4067. match in the entry. Snippets enclosed into double quotes will be taken
  4068. as a whole, to include whitespace.
  4069. - If the search string starts with an asterisk, search only in headlines.
  4070. - If (possibly after the leading star) the search string starts with an
  4071. exclamation mark, this also means to look at TODO entries only, an effect
  4072. that can also be achieved with a prefix argument.
  4073. - If (possibly after star and exclamation mark) the search string starts
  4074. with a colon, this will mean that the (non-regexp) snippets of the
  4075. Boolean search must match as full words.
  4076. This command searches the agenda files, and in addition the files listed
  4077. in `org-agenda-text-search-extra-files'."
  4078. (interactive "P")
  4079. (if org-agenda-overriding-arguments
  4080. (setq todo-only (car org-agenda-overriding-arguments)
  4081. string (nth 1 org-agenda-overriding-arguments)
  4082. edit-at (nth 2 org-agenda-overriding-arguments)))
  4083. (let* ((props (list 'face nil
  4084. 'done-face 'org-agenda-done
  4085. 'org-not-done-regexp org-not-done-regexp
  4086. 'org-todo-regexp org-todo-regexp
  4087. 'org-complex-heading-regexp org-complex-heading-regexp
  4088. 'mouse-face 'highlight
  4089. 'help-echo (format "mouse-2 or RET jump to location")))
  4090. (full-words org-agenda-search-view-force-full-words)
  4091. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4092. regexp rtn rtnall files file pos inherited-tags
  4093. marker category level tags c neg re boolean
  4094. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4095. (unless (and (not edit-at)
  4096. (stringp string)
  4097. (string-match "\\S-" string))
  4098. (setq string (read-string
  4099. (if org-agenda-search-view-always-boolean
  4100. "[+-]Word/{Regexp} ...: "
  4101. "Phrase or [+-]Word/{Regexp} ...: ")
  4102. (cond
  4103. ((integerp edit-at) (cons string edit-at))
  4104. (edit-at string))
  4105. 'org-agenda-search-history)))
  4106. (catch 'exit
  4107. (if org-agenda-sticky
  4108. (setq org-agenda-buffer-name
  4109. (if (stringp string)
  4110. (format "*Org Agenda(%s:%s)*"
  4111. (or org-keys (or (and todo-only "S") "s")) string)
  4112. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4113. (org-agenda-prepare "SEARCH")
  4114. (org-compile-prefix-format 'search)
  4115. (org-set-sorting-strategy 'search)
  4116. (setq org-agenda-redo-command
  4117. (list 'org-search-view (if todo-only t nil)
  4118. (list 'if 'current-prefix-arg nil string)))
  4119. (setq org-agenda-query-string string)
  4120. (if (equal (string-to-char string) ?*)
  4121. (setq hdl-only t
  4122. words (substring string 1))
  4123. (setq words string))
  4124. (when (equal (string-to-char words) ?!)
  4125. (setq todo-only t
  4126. words (substring words 1)))
  4127. (when (equal (string-to-char words) ?:)
  4128. (setq full-words t
  4129. words (substring words 1)))
  4130. (if (or org-agenda-search-view-always-boolean
  4131. (member (string-to-char words) '(?- ?+ ?\{)))
  4132. (setq boolean t))
  4133. (setq words (org-split-string words))
  4134. (let (www w)
  4135. (while (setq w (pop words))
  4136. (while (and (string-match "\\\\\\'" w) words)
  4137. (setq w (concat (substring w 0 -1) " " (pop words))))
  4138. (push w www))
  4139. (setq words (nreverse www) www nil)
  4140. (while (setq w (pop words))
  4141. (when (and (string-match "\\`[-+]?{" w)
  4142. (not (string-match "}\\'" w)))
  4143. (while (and words (not (string-match "}\\'" (car words))))
  4144. (setq w (concat w " " (pop words))))
  4145. (setq w (concat w " " (pop words))))
  4146. (push w www))
  4147. (setq words (nreverse www)))
  4148. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4149. (when boolean
  4150. (let (wds w)
  4151. (while (setq w (pop words))
  4152. (if (or (equal (substring w 0 1) "\"")
  4153. (and (> (length w) 1)
  4154. (member (substring w 0 1) '("+" "-"))
  4155. (equal (substring w 1 2) "\"")))
  4156. (while (and words (not (equal (substring w -1) "\"")))
  4157. (setq w (concat w " " (pop words)))))
  4158. (and (string-match "\\`\\([-+]?\\)\"" w)
  4159. (setq w (replace-match "\\1" nil nil w)))
  4160. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4161. (push w wds))
  4162. (setq words (nreverse wds))))
  4163. (if boolean
  4164. (mapc (lambda (w)
  4165. (setq c (string-to-char w))
  4166. (if (equal c ?-)
  4167. (setq neg t w (substring w 1))
  4168. (if (equal c ?+)
  4169. (setq neg nil w (substring w 1))
  4170. (setq neg nil)))
  4171. (if (string-match "\\`{.*}\\'" w)
  4172. (setq re (substring w 1 -1))
  4173. (if full-words
  4174. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4175. (setq re (regexp-quote (downcase w)))))
  4176. (if neg (push re regexps-) (push re regexps+)))
  4177. words)
  4178. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4179. regexps+))
  4180. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4181. (if (not regexps+)
  4182. (setq regexp org-outline-regexp-bol)
  4183. (setq regexp (pop regexps+))
  4184. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4185. regexp))))
  4186. (setq files (org-agenda-files nil 'ifmode))
  4187. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4188. (pop org-agenda-text-search-extra-files)
  4189. (setq files (org-add-archive-files files)))
  4190. (setq files (append files org-agenda-text-search-extra-files)
  4191. rtnall nil)
  4192. (while (setq file (pop files))
  4193. (setq ee nil)
  4194. (catch 'nextfile
  4195. (org-check-agenda-file file)
  4196. (setq buffer (if (file-exists-p file)
  4197. (org-get-agenda-file-buffer file)
  4198. (error "No such file %s" file)))
  4199. (if (not buffer)
  4200. ;; If file does not exist, make sure an error message is sent
  4201. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4202. file))))
  4203. (with-current-buffer buffer
  4204. (with-syntax-table (org-search-syntax-table)
  4205. (unless (derived-mode-p 'org-mode)
  4206. (error "Agenda file %s is not in `org-mode'" file))
  4207. (let ((case-fold-search t))
  4208. (save-excursion
  4209. (save-restriction
  4210. (if (eq buffer org-agenda-restrict)
  4211. (narrow-to-region org-agenda-restrict-begin
  4212. org-agenda-restrict-end)
  4213. (widen))
  4214. (goto-char (point-min))
  4215. (unless (or (org-at-heading-p)
  4216. (outline-next-heading))
  4217. (throw 'nextfile t))
  4218. (goto-char (max (point-min) (1- (point))))
  4219. (while (re-search-forward regexp nil t)
  4220. (org-back-to-heading t)
  4221. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4222. (> (org-reduced-level (org-outline-level))
  4223. org-agenda-search-view-max-outline-level)
  4224. (forward-line -1)
  4225. (outline-back-to-heading t)))
  4226. (skip-chars-forward "* ")
  4227. (setq beg (point-at-bol)
  4228. beg1 (point)
  4229. end (progn
  4230. (outline-next-heading)
  4231. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4232. (> (org-reduced-level (org-outline-level))
  4233. org-agenda-search-view-max-outline-level)
  4234. (forward-line 1)
  4235. (outline-next-heading)))
  4236. (point)))
  4237. (catch :skip
  4238. (goto-char beg)
  4239. (org-agenda-skip)
  4240. (setq str (buffer-substring-no-properties
  4241. (point-at-bol)
  4242. (if hdl-only (point-at-eol) end)))
  4243. (mapc (lambda (wr) (when (string-match wr str)
  4244. (goto-char (1- end))
  4245. (throw :skip t)))
  4246. regexps-)
  4247. (mapc (lambda (wr) (unless (string-match wr str)
  4248. (goto-char (1- end))
  4249. (throw :skip t)))
  4250. (if todo-only
  4251. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4252. regexps+)
  4253. regexps+))
  4254. (goto-char beg)
  4255. (setq marker (org-agenda-new-marker (point))
  4256. category (org-get-category)
  4257. level (make-string (org-reduced-level (org-outline-level)) ? )
  4258. inherited-tags
  4259. (or (eq org-agenda-show-inherited-tags 'always)
  4260. (and (listp org-agenda-show-inherited-tags)
  4261. (memq 'todo org-agenda-show-inherited-tags))
  4262. (and (eq org-agenda-show-inherited-tags t)
  4263. (or (eq org-agenda-use-tag-inheritance t)
  4264. (memq 'todo org-agenda-use-tag-inheritance))))
  4265. tags (org-get-tags-at nil (not inherited-tags))
  4266. txt (org-agenda-format-item
  4267. ""
  4268. (buffer-substring-no-properties
  4269. beg1 (point-at-eol))
  4270. level category tags t))
  4271. (org-add-props txt props
  4272. 'org-marker marker 'org-hd-marker marker
  4273. 'org-todo-regexp org-todo-regexp
  4274. 'level level
  4275. 'org-complex-heading-regexp org-complex-heading-regexp
  4276. 'priority 1000
  4277. 'type "search")
  4278. (push txt ee)
  4279. (goto-char (1- end))))))))))
  4280. (setq rtn (nreverse ee))
  4281. (setq rtnall (append rtnall rtn)))
  4282. (if org-agenda-overriding-header
  4283. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4284. nil 'face 'org-agenda-structure) "\n")
  4285. (insert "Search words: ")
  4286. (add-text-properties (point-min) (1- (point))
  4287. (list 'face 'org-agenda-structure))
  4288. (setq pos (point))
  4289. (insert string "\n")
  4290. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4291. (setq pos (point))
  4292. (unless org-agenda-multi
  4293. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4294. (add-text-properties pos (1- (point))
  4295. (list 'face 'org-agenda-structure))))
  4296. (org-agenda-mark-header-line (point-min))
  4297. (when rtnall
  4298. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4299. (goto-char (point-min))
  4300. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4301. (add-text-properties (point-min) (point-max)
  4302. `(org-agenda-type search
  4303. org-last-args (,todo-only ,string ,edit-at)
  4304. org-redo-cmd ,org-agenda-redo-command
  4305. org-series-cmd ,org-cmd))
  4306. (org-agenda-finalize)
  4307. (setq buffer-read-only t))))
  4308. ;;; Agenda TODO list
  4309. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4310. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4311. (concat
  4312. (if (or (equal keywords "ALL") (not keywords))
  4313. (propertize "ALL" 'face 'warning)
  4314. (mapconcat
  4315. (lambda (kw)
  4316. (propertize kw 'face (org-get-todo-face kw)))
  4317. (org-split-string keywords "|")
  4318. "|"))
  4319. "\n"))
  4320. (defvar org-select-this-todo-keyword nil)
  4321. (defvar org-last-arg nil)
  4322. ;;;###autoload
  4323. (defun org-todo-list (&optional arg)
  4324. "Show all (not done) TODO entries from all agenda file in a single list.
  4325. The prefix arg can be used to select a specific TODO keyword and limit
  4326. the list to these. When using \\[universal-argument], you will be prompted
  4327. for a keyword. A numeric prefix directly selects the Nth keyword in
  4328. `org-todo-keywords-1'."
  4329. (interactive "P")
  4330. (if org-agenda-overriding-arguments
  4331. (setq arg org-agenda-overriding-arguments))
  4332. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4333. (let* ((today (org-today))
  4334. (date (calendar-gregorian-from-absolute today))
  4335. (kwds org-todo-keywords-for-agenda)
  4336. (completion-ignore-case t)
  4337. (org-select-this-todo-keyword
  4338. (if (stringp arg) arg
  4339. (and arg (integerp arg) (> arg 0)
  4340. (nth (1- arg) kwds))))
  4341. rtn rtnall files file pos)
  4342. (when (equal arg '(4))
  4343. (setq org-select-this-todo-keyword
  4344. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4345. (mapcar 'list kwds) nil nil)))
  4346. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4347. (catch 'exit
  4348. (if org-agenda-sticky
  4349. (setq org-agenda-buffer-name
  4350. (if (stringp org-select-this-todo-keyword)
  4351. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4352. org-select-this-todo-keyword)
  4353. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4354. (org-agenda-prepare "TODO")
  4355. (org-compile-prefix-format 'todo)
  4356. (org-set-sorting-strategy 'todo)
  4357. (setq org-agenda-redo-command
  4358. `(org-todo-list (or (and (numberp current-prefix-arg)
  4359. current-prefix-arg)
  4360. ,org-select-this-todo-keyword
  4361. current-prefix-arg ,arg)))
  4362. (setq files (org-agenda-files nil 'ifmode)
  4363. rtnall nil)
  4364. (while (setq file (pop files))
  4365. (catch 'nextfile
  4366. (org-check-agenda-file file)
  4367. (setq rtn (org-agenda-get-day-entries file date :todo))
  4368. (setq rtnall (append rtnall rtn))))
  4369. (if org-agenda-overriding-header
  4370. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4371. nil 'face 'org-agenda-structure) "\n")
  4372. (insert "Global list of TODO items of type: ")
  4373. (add-text-properties (point-min) (1- (point))
  4374. (list 'face 'org-agenda-structure
  4375. 'short-heading
  4376. (concat "ToDo: "
  4377. (or org-select-this-todo-keyword "ALL"))))
  4378. (org-agenda-mark-header-line (point-min))
  4379. (insert (org-agenda-propertize-selected-todo-keywords
  4380. org-select-this-todo-keyword))
  4381. (setq pos (point))
  4382. (unless org-agenda-multi
  4383. (insert "Available with `N r': (0)[ALL]")
  4384. (let ((n 0) s)
  4385. (mapc (lambda (x)
  4386. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4387. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4388. (insert "\n "))
  4389. (insert " " s))
  4390. kwds))
  4391. (insert "\n"))
  4392. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4393. (org-agenda-mark-header-line (point-min))
  4394. (when rtnall
  4395. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4396. (goto-char (point-min))
  4397. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4398. (add-text-properties (point-min) (point-max)
  4399. `(org-agenda-type todo
  4400. org-last-args ,arg
  4401. org-redo-cmd ,org-agenda-redo-command
  4402. org-series-cmd ,org-cmd))
  4403. (org-agenda-finalize)
  4404. (setq buffer-read-only t))))
  4405. ;;; Agenda tags match
  4406. ;;;###autoload
  4407. (defun org-tags-view (&optional todo-only match)
  4408. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4409. The prefix arg TODO-ONLY limits the search to TODO entries."
  4410. (interactive "P")
  4411. (if org-agenda-overriding-arguments
  4412. (setq todo-only (car org-agenda-overriding-arguments)
  4413. match (nth 1 org-agenda-overriding-arguments)))
  4414. (let* ((org-tags-match-list-sublevels
  4415. org-tags-match-list-sublevels)
  4416. (completion-ignore-case t)
  4417. rtn rtnall files file pos matcher
  4418. buffer)
  4419. (when (and (stringp match) (not (string-match "\\S-" match)))
  4420. (setq match nil))
  4421. (catch 'exit
  4422. (if org-agenda-sticky
  4423. (setq org-agenda-buffer-name
  4424. (if (stringp match)
  4425. (format "*Org Agenda(%s:%s)*"
  4426. (or org-keys (or (and todo-only "M") "m")) match)
  4427. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4428. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4429. ;; expanding tags within `org-make-tags-matcher'
  4430. (org-agenda-prepare (concat "TAGS " match))
  4431. (setq matcher (org-make-tags-matcher match)
  4432. match (car matcher) matcher (cdr matcher))
  4433. (org-compile-prefix-format 'tags)
  4434. (org-set-sorting-strategy 'tags)
  4435. (setq org-agenda-query-string match)
  4436. (setq org-agenda-redo-command
  4437. (list 'org-tags-view `(quote ,todo-only)
  4438. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4439. (setq files (org-agenda-files nil 'ifmode)
  4440. rtnall nil)
  4441. (while (setq file (pop files))
  4442. (catch 'nextfile
  4443. (org-check-agenda-file file)
  4444. (setq buffer (if (file-exists-p file)
  4445. (org-get-agenda-file-buffer file)
  4446. (error "No such file %s" file)))
  4447. (if (not buffer)
  4448. ;; If file does not exist, error message to agenda
  4449. (setq rtn (list
  4450. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4451. rtnall (append rtnall rtn))
  4452. (with-current-buffer buffer
  4453. (unless (derived-mode-p 'org-mode)
  4454. (error "Agenda file %s is not in `org-mode'" file))
  4455. (save-excursion
  4456. (save-restriction
  4457. (if (eq buffer org-agenda-restrict)
  4458. (narrow-to-region org-agenda-restrict-begin
  4459. org-agenda-restrict-end)
  4460. (widen))
  4461. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4462. (setq rtnall (append rtnall rtn))))))))
  4463. (if org-agenda-overriding-header
  4464. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4465. nil 'face 'org-agenda-structure) "\n")
  4466. (insert "Headlines with TAGS match: ")
  4467. (add-text-properties (point-min) (1- (point))
  4468. (list 'face 'org-agenda-structure
  4469. 'short-heading
  4470. (concat "Match: " match)))
  4471. (setq pos (point))
  4472. (insert match "\n")
  4473. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4474. (setq pos (point))
  4475. (unless org-agenda-multi
  4476. (insert "Press `C-u r' to search again with new search string\n"))
  4477. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4478. (org-agenda-mark-header-line (point-min))
  4479. (when rtnall
  4480. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4481. (goto-char (point-min))
  4482. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4483. (add-text-properties (point-min) (point-max)
  4484. `(org-agenda-type tags
  4485. org-last-args (,todo-only ,match)
  4486. org-redo-cmd ,org-agenda-redo-command
  4487. org-series-cmd ,org-cmd))
  4488. (org-agenda-finalize)
  4489. (setq buffer-read-only t))))
  4490. ;;; Agenda Finding stuck projects
  4491. (defvar org-agenda-skip-regexp nil
  4492. "Regular expression used in skipping subtrees for the agenda.
  4493. This is basically a temporary global variable that can be set and then
  4494. used by user-defined selections using `org-agenda-skip-function'.")
  4495. (defvar org-agenda-overriding-header nil
  4496. "When set during agenda, todo and tags searches it replaces the header.
  4497. This variable should not be set directly, but custom commands can bind it
  4498. in the options section.")
  4499. (defun org-agenda-skip-entry-when-regexp-matches ()
  4500. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4501. If yes, it returns the end position of this entry, causing agenda commands
  4502. to skip the entry but continuing the search in the subtree. This is a
  4503. function that can be put into `org-agenda-skip-function' for the duration
  4504. of a command."
  4505. (let ((end (save-excursion (org-end-of-subtree t)))
  4506. skip)
  4507. (save-excursion
  4508. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4509. (and skip end)))
  4510. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4511. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4512. If yes, it returns the end position of this tree, causing agenda commands
  4513. to skip this subtree. This is a function that can be put into
  4514. `org-agenda-skip-function' for the duration of a command."
  4515. (let ((end (save-excursion (org-end-of-subtree t)))
  4516. skip)
  4517. (save-excursion
  4518. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4519. (and skip end)))
  4520. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4521. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4522. If yes, it returns the end position of the current entry (NOT the tree),
  4523. causing agenda commands to skip the entry but continuing the search in
  4524. the subtree. This is a function that can be put into
  4525. `org-agenda-skip-function' for the duration of a command. An important
  4526. use of this function is for the stuck project list."
  4527. (let ((end (save-excursion (org-end-of-subtree t)))
  4528. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4529. skip)
  4530. (save-excursion
  4531. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4532. (and skip entry-end)))
  4533. (defun org-agenda-skip-entry-if (&rest conditions)
  4534. "Skip entry if any of CONDITIONS is true.
  4535. See `org-agenda-skip-if' for details."
  4536. (org-agenda-skip-if nil conditions))
  4537. (defun org-agenda-skip-subtree-if (&rest conditions)
  4538. "Skip subtree if any of CONDITIONS is true.
  4539. See `org-agenda-skip-if' for details."
  4540. (org-agenda-skip-if t conditions))
  4541. (defun org-agenda-skip-if (subtree conditions)
  4542. "Checks current entity for CONDITIONS.
  4543. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4544. the entry (i.e. the text before the next heading) is checked.
  4545. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4546. from different tests. Valid conditions are:
  4547. scheduled Check if there is a scheduled cookie
  4548. notscheduled Check if there is no scheduled cookie
  4549. deadline Check if there is a deadline
  4550. notdeadline Check if there is no deadline
  4551. timestamp Check if there is a timestamp (also deadline or scheduled)
  4552. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4553. regexp Check if regexp matches
  4554. notregexp Check if regexp does not match.
  4555. todo Check if TODO keyword matches
  4556. nottodo Check if TODO keyword does not match
  4557. The regexp is taken from the conditions list, it must come right after
  4558. the `regexp' or `notregexp' element.
  4559. `todo' and `nottodo' accept as an argument a list of todo
  4560. keywords, which may include \"*\" to match any todo keyword.
  4561. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4562. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4563. Instead of a list, a keyword class may be given. For example:
  4564. (org-agenda-skip-entry-if 'nottodo 'done)
  4565. would skip entries that haven't been marked with any of \"DONE\"
  4566. keywords. Possible classes are: `todo', `done', `any'.
  4567. If any of these conditions is met, this function returns the end point of
  4568. the entity, causing the search to continue from there. This is a function
  4569. that can be put into `org-agenda-skip-function' for the duration of a command."
  4570. (let (beg end m)
  4571. (org-back-to-heading t)
  4572. (setq beg (point)
  4573. end (if subtree
  4574. (progn (org-end-of-subtree t) (point))
  4575. (progn (outline-next-heading) (1- (point)))))
  4576. (goto-char beg)
  4577. (and
  4578. (or
  4579. (and (memq 'scheduled conditions)
  4580. (re-search-forward org-scheduled-time-regexp end t))
  4581. (and (memq 'notscheduled conditions)
  4582. (not (re-search-forward org-scheduled-time-regexp end t)))
  4583. (and (memq 'deadline conditions)
  4584. (re-search-forward org-deadline-time-regexp end t))
  4585. (and (memq 'notdeadline conditions)
  4586. (not (re-search-forward org-deadline-time-regexp end t)))
  4587. (and (memq 'timestamp conditions)
  4588. (re-search-forward org-ts-regexp end t))
  4589. (and (memq 'nottimestamp conditions)
  4590. (not (re-search-forward org-ts-regexp end t)))
  4591. (and (setq m (memq 'regexp conditions))
  4592. (stringp (nth 1 m))
  4593. (re-search-forward (nth 1 m) end t))
  4594. (and (setq m (memq 'notregexp conditions))
  4595. (stringp (nth 1 m))
  4596. (not (re-search-forward (nth 1 m) end t)))
  4597. (and (or
  4598. (setq m (memq 'nottodo conditions))
  4599. (setq m (memq 'todo-unblocked conditions))
  4600. (setq m (memq 'nottodo-unblocked conditions))
  4601. (setq m (memq 'todo conditions)))
  4602. (org-agenda-skip-if-todo m end)))
  4603. end)))
  4604. (defun org-agenda-skip-if-todo (args end)
  4605. "Helper function for `org-agenda-skip-if', do not use it directly.
  4606. ARGS is a list with first element either `todo', `nottodo',
  4607. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4608. a list of TODO keywords, or a state symbol `todo' or `done' or
  4609. `any'."
  4610. (let ((kw (car args))
  4611. (arg (cadr args))
  4612. todo-wds todo-re)
  4613. (setq todo-wds
  4614. (org-uniquify
  4615. (cond
  4616. ((listp arg) ;; list of keywords
  4617. (if (member "*" arg)
  4618. (mapcar 'substring-no-properties org-todo-keywords-1)
  4619. arg))
  4620. ((symbolp arg) ;; keyword class name
  4621. (cond
  4622. ((eq arg 'todo)
  4623. (org-delete-all org-done-keywords
  4624. (mapcar 'substring-no-properties
  4625. org-todo-keywords-1)))
  4626. ((eq arg 'done) org-done-keywords)
  4627. ((eq arg 'any)
  4628. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4629. (setq todo-re
  4630. (concat "^\\*+[ \t]+\\<\\("
  4631. (mapconcat 'identity todo-wds "\\|")
  4632. "\\)\\>"))
  4633. (cond
  4634. ((eq kw 'todo) (re-search-forward todo-re end t))
  4635. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4636. ((eq kw 'todo-unblocked)
  4637. (catch 'unblocked
  4638. (while (re-search-forward todo-re end t)
  4639. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4640. nil))
  4641. ((eq kw 'nottodo-unblocked)
  4642. (catch 'unblocked
  4643. (while (re-search-forward todo-re end t)
  4644. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4645. t))
  4646. )))
  4647. ;;;###autoload
  4648. (defun org-agenda-list-stuck-projects (&rest ignore)
  4649. "Create agenda view for projects that are stuck.
  4650. Stuck projects are project that have no next actions. For the definitions
  4651. of what a project is and how to check if it stuck, customize the variable
  4652. `org-stuck-projects'."
  4653. (interactive)
  4654. (let* ((org-agenda-skip-function
  4655. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4656. ;; We could have used org-agenda-skip-if here.
  4657. (org-agenda-overriding-header
  4658. (or org-agenda-overriding-header "List of stuck projects: "))
  4659. (matcher (nth 0 org-stuck-projects))
  4660. (todo (nth 1 org-stuck-projects))
  4661. (todo-wds (if (member "*" todo)
  4662. (progn
  4663. (org-agenda-prepare-buffers (org-agenda-files
  4664. nil 'ifmode))
  4665. (org-delete-all
  4666. org-done-keywords-for-agenda
  4667. (copy-sequence org-todo-keywords-for-agenda)))
  4668. todo))
  4669. (todo-re (concat "^\\*+[ \t]+\\("
  4670. (mapconcat 'identity todo-wds "\\|")
  4671. "\\)\\>"))
  4672. (tags (nth 2 org-stuck-projects))
  4673. (tags-re (if (member "*" tags)
  4674. (concat org-outline-regexp-bol
  4675. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4676. (if tags
  4677. (concat org-outline-regexp-bol
  4678. ".*:\\("
  4679. (mapconcat 'identity tags "\\|")
  4680. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4681. (gen-re (nth 3 org-stuck-projects))
  4682. (re-list
  4683. (delq nil
  4684. (list
  4685. (if todo todo-re)
  4686. (if tags tags-re)
  4687. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4688. gen-re)))))
  4689. (setq org-agenda-skip-regexp
  4690. (if re-list
  4691. (mapconcat 'identity re-list "\\|")
  4692. (error "No information how to identify unstuck projects")))
  4693. (org-tags-view nil matcher)
  4694. (setq org-agenda-buffer-name (buffer-name))
  4695. (with-current-buffer org-agenda-buffer-name
  4696. (setq org-agenda-redo-command
  4697. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4698. ;;; Diary integration
  4699. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4700. (defvar diary-list-entries-hook)
  4701. (defvar diary-time-regexp)
  4702. (defun org-get-entries-from-diary (date)
  4703. "Get the (Emacs Calendar) diary entries for DATE."
  4704. (require 'diary-lib)
  4705. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4706. (diary-display-hook '(fancy-diary-display))
  4707. (diary-display-function 'fancy-diary-display)
  4708. (pop-up-frames nil)
  4709. (diary-list-entries-hook
  4710. (cons 'org-diary-default-entry diary-list-entries-hook))
  4711. (diary-file-name-prefix nil) ; turn this feature off
  4712. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4713. entries
  4714. (org-disable-agenda-to-diary t))
  4715. (save-excursion
  4716. (save-window-excursion
  4717. (funcall (if (fboundp 'diary-list-entries)
  4718. 'diary-list-entries 'list-diary-entries)
  4719. date 1)))
  4720. (if (not (get-buffer diary-fancy-buffer))
  4721. (setq entries nil)
  4722. (with-current-buffer diary-fancy-buffer
  4723. (setq buffer-read-only nil)
  4724. (if (zerop (buffer-size))
  4725. ;; No entries
  4726. (setq entries nil)
  4727. ;; Omit the date and other unnecessary stuff
  4728. (org-agenda-cleanup-fancy-diary)
  4729. ;; Add prefix to each line and extend the text properties
  4730. (if (zerop (buffer-size))
  4731. (setq entries nil)
  4732. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4733. (setq entries
  4734. (with-temp-buffer
  4735. (insert entries) (goto-char (point-min))
  4736. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4737. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4738. (replace-match (concat "; " (match-string 1)))))
  4739. (buffer-string)))))
  4740. (set-buffer-modified-p nil)
  4741. (kill-buffer diary-fancy-buffer)))
  4742. (when entries
  4743. (setq entries (org-split-string entries "\n"))
  4744. (setq entries
  4745. (mapcar
  4746. (lambda (x)
  4747. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4748. ;; Extend the text properties to the beginning of the line
  4749. (org-add-props x (text-properties-at (1- (length x)) x)
  4750. 'type "diary" 'date date 'face 'org-agenda-diary))
  4751. entries)))))
  4752. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4753. "Hook run when the fancy diary buffer is cleaned up.")
  4754. (defun org-agenda-cleanup-fancy-diary ()
  4755. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4756. This gets rid of the date, the underline under the date, and
  4757. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4758. date. It also removes lines that contain only whitespace."
  4759. (goto-char (point-min))
  4760. (if (looking-at ".*?:[ \t]*")
  4761. (progn
  4762. (replace-match "")
  4763. (re-search-forward "\n=+$" nil t)
  4764. (replace-match "")
  4765. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4766. (re-search-forward "\n=+$" nil t)
  4767. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4768. (goto-char (point-min))
  4769. (while (re-search-forward "^ +\n" nil t)
  4770. (replace-match ""))
  4771. (goto-char (point-min))
  4772. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4773. (replace-match ""))
  4774. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4775. ;; Make sure entries from the diary have the right text properties.
  4776. (eval-after-load "diary-lib"
  4777. '(if (boundp 'diary-modify-entry-list-string-function)
  4778. ;; We can rely on the hook, nothing to do
  4779. nil
  4780. ;; Hook not available, must use advice to make this work
  4781. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4782. "Make the position visible."
  4783. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4784. (stringp string)
  4785. buffer-file-name)
  4786. (setq string (org-modify-diary-entry-string string))))))
  4787. (defun org-modify-diary-entry-string (string)
  4788. "Add text properties to string, allowing org-mode to act on it."
  4789. (org-add-props string nil
  4790. 'mouse-face 'highlight
  4791. 'help-echo (if buffer-file-name
  4792. (format "mouse-2 or RET jump to diary file %s"
  4793. (abbreviate-file-name buffer-file-name))
  4794. "")
  4795. 'org-agenda-diary-link t
  4796. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4797. (defun org-diary-default-entry ()
  4798. "Add a dummy entry to the diary.
  4799. Needed to avoid empty dates which mess up holiday display."
  4800. ;; Catch the error if dealing with the new add-to-diary-alist
  4801. (when org-disable-agenda-to-diary
  4802. (condition-case nil
  4803. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4804. (error
  4805. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4806. (defun org-add-to-diary-list (&rest args)
  4807. (if (fboundp 'diary-add-to-list)
  4808. (apply 'diary-add-to-list args)
  4809. (apply 'add-to-diary-list args)))
  4810. (defvar org-diary-last-run-time nil)
  4811. ;;;###autoload
  4812. (defun org-diary (&rest args)
  4813. "Return diary information from org files.
  4814. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4815. It accesses org files and extracts information from those files to be
  4816. listed in the diary. The function accepts arguments specifying what
  4817. items should be listed. For a list of arguments allowed here, see the
  4818. variable `org-agenda-entry-types'.
  4819. The call in the diary file should look like this:
  4820. &%%(org-diary) ~/path/to/some/orgfile.org
  4821. Use a separate line for each org file to check. Or, if you omit the file name,
  4822. all files listed in `org-agenda-files' will be checked automatically:
  4823. &%%(org-diary)
  4824. If you don't give any arguments (as in the example above), the default value
  4825. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4826. So the example above may also be written as
  4827. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4828. The function expects the lisp variables `entry' and `date' to be provided
  4829. by the caller, because this is how the calendar works. Don't use this
  4830. function from a program - use `org-agenda-get-day-entries' instead."
  4831. (when (> (- (org-float-time)
  4832. org-agenda-last-marker-time)
  4833. 5)
  4834. ;; I am not sure if this works with sticky agendas, because the marker
  4835. ;; list is then no longer a global variable.
  4836. (org-agenda-reset-markers))
  4837. (org-compile-prefix-format 'agenda)
  4838. (org-set-sorting-strategy 'agenda)
  4839. (setq args (or args org-agenda-entry-types))
  4840. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4841. (list entry)
  4842. (org-agenda-files t)))
  4843. (time (org-float-time))
  4844. file rtn results)
  4845. (when (or (not org-diary-last-run-time)
  4846. (> (- time
  4847. org-diary-last-run-time)
  4848. 3))
  4849. (org-agenda-prepare-buffers files))
  4850. (setq org-diary-last-run-time time)
  4851. ;; If this is called during org-agenda, don't return any entries to
  4852. ;; the calendar. Org Agenda will list these entries itself.
  4853. (if org-disable-agenda-to-diary (setq files nil))
  4854. (while (setq file (pop files))
  4855. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4856. (setq results (append results rtn)))
  4857. (when results
  4858. (setq results
  4859. (mapcar (lambda (i) (replace-regexp-in-string
  4860. org-bracket-link-regexp "\\3" i)) results))
  4861. (concat (org-agenda-finalize-entries results) "\n"))))
  4862. ;;; Agenda entry finders
  4863. (defun org-agenda-get-day-entries (file date &rest args)
  4864. "Does the work for `org-diary' and `org-agenda'.
  4865. FILE is the path to a file to be checked for entries. DATE is date like
  4866. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4867. which kind of entries should be extracted. For details about these, see
  4868. the documentation of `org-diary'."
  4869. (setq args (or args org-agenda-entry-types))
  4870. (let* ((org-startup-folded nil)
  4871. (org-startup-align-all-tables nil)
  4872. (buffer (if (file-exists-p file)
  4873. (org-get-agenda-file-buffer file)
  4874. (error "No such file %s" file)))
  4875. arg results rtn deadline-results)
  4876. (if (not buffer)
  4877. ;; If file does not exist, make sure an error message ends up in diary
  4878. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4879. (with-current-buffer buffer
  4880. (unless (derived-mode-p 'org-mode)
  4881. (error "Agenda file %s is not in `org-mode'" file))
  4882. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4883. (let ((case-fold-search nil))
  4884. (save-excursion
  4885. (save-restriction
  4886. (if (eq buffer org-agenda-restrict)
  4887. (narrow-to-region org-agenda-restrict-begin
  4888. org-agenda-restrict-end)
  4889. (widen))
  4890. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4891. (while (setq arg (pop args))
  4892. (cond
  4893. ((and (eq arg :todo)
  4894. (equal date (calendar-gregorian-from-absolute
  4895. (org-today))))
  4896. (setq rtn (org-agenda-get-todos))
  4897. (setq results (append results rtn)))
  4898. ((eq arg :timestamp)
  4899. (setq rtn (org-agenda-get-blocks))
  4900. (setq results (append results rtn))
  4901. (setq rtn (org-agenda-get-timestamps deadline-results))
  4902. (setq results (append results rtn)))
  4903. ((eq arg :sexp)
  4904. (setq rtn (org-agenda-get-sexps))
  4905. (setq results (append results rtn)))
  4906. ((eq arg :scheduled)
  4907. (setq rtn (org-agenda-get-scheduled deadline-results))
  4908. (setq results (append results rtn)))
  4909. ((eq arg :scheduled*)
  4910. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4911. (setq results (append results rtn)))
  4912. ((eq arg :closed)
  4913. (setq rtn (org-agenda-get-progress))
  4914. (setq results (append results rtn)))
  4915. ((eq arg :deadline)
  4916. (setq rtn (org-agenda-get-deadlines))
  4917. (setq deadline-results (copy-sequence rtn))
  4918. (setq results (append results rtn)))
  4919. ((eq arg :deadline*)
  4920. (setq rtn (org-agenda-get-deadlines t))
  4921. (setq deadline-results (copy-sequence rtn))
  4922. (setq results (append results rtn))))))))
  4923. results))))
  4924. (defsubst org-em (x y list)
  4925. "Is X or Y a member of LIST?"
  4926. (or (memq x list) (memq y list)))
  4927. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4928. (defvar org-agenda-sorting-strategy-selected nil)
  4929. (defun org-agenda-get-todos ()
  4930. "Return the TODO information for agenda display."
  4931. (let* ((props (list 'face nil
  4932. 'done-face 'org-agenda-done
  4933. 'org-not-done-regexp org-not-done-regexp
  4934. 'org-todo-regexp org-todo-regexp
  4935. 'org-complex-heading-regexp org-complex-heading-regexp
  4936. 'mouse-face 'highlight
  4937. 'help-echo
  4938. (format "mouse-2 or RET jump to org file %s"
  4939. (abbreviate-file-name buffer-file-name))))
  4940. (regexp (format org-heading-keyword-regexp-format
  4941. (cond
  4942. ((and org-select-this-todo-keyword
  4943. (equal org-select-this-todo-keyword "*"))
  4944. org-todo-regexp)
  4945. (org-select-this-todo-keyword
  4946. (concat "\\("
  4947. (mapconcat 'identity
  4948. (org-split-string
  4949. org-select-this-todo-keyword
  4950. "|")
  4951. "\\|") "\\)"))
  4952. (t org-not-done-regexp))))
  4953. marker priority category level tags todo-state ts-date ts-date-type
  4954. ee txt beg end inherited-tags todo-state-end-pos)
  4955. (goto-char (point-min))
  4956. (while (re-search-forward regexp nil t)
  4957. (catch :skip
  4958. (save-match-data
  4959. (beginning-of-line)
  4960. (org-agenda-skip)
  4961. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4962. (unless (and (setq todo-state (org-get-todo-state))
  4963. (setq todo-state-end-pos (match-end 2)))
  4964. (goto-char end)
  4965. (throw :skip nil))
  4966. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4967. (goto-char (1+ beg))
  4968. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4969. (throw :skip nil)))
  4970. (goto-char (match-beginning 2))
  4971. (setq marker (org-agenda-new-marker (match-beginning 0))
  4972. category (org-get-category)
  4973. ts-date (let (ts)
  4974. (save-match-data
  4975. (cond ((org-em 'scheduled-up 'scheduled-down
  4976. org-agenda-sorting-strategy-selected)
  4977. (setq ts (org-entry-get (point) "SCHEDULED")
  4978. ts-date-type " scheduled"))
  4979. ((org-em 'deadline-up 'deadline-down
  4980. org-agenda-sorting-strategy-selected)
  4981. (setq ts (org-entry-get (point) "DEADLINE")
  4982. ts-date-type " deadline"))
  4983. ((org-em 'ts-up 'ts-down
  4984. org-agenda-sorting-strategy-selected)
  4985. (setq ts (org-entry-get (point) "TIMESTAMP")
  4986. ts-date-type " timestamp"))
  4987. ((org-em 'tsia-up 'tsia-down
  4988. org-agenda-sorting-strategy-selected)
  4989. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4990. ts-date-type " timestamp_ia"))
  4991. ((org-em 'timestamp-up 'timestamp-down
  4992. org-agenda-sorting-strategy-selected)
  4993. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4994. (org-entry-get (point) "DEADLINE")
  4995. (org-entry-get (point) "TIMESTAMP")
  4996. (org-entry-get (point) "TIMESTAMP_IA"))
  4997. ts-date-type ""))
  4998. (t (setq ts-date-type "")))
  4999. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  5000. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5001. inherited-tags
  5002. (or (eq org-agenda-show-inherited-tags 'always)
  5003. (and (listp org-agenda-show-inherited-tags)
  5004. (memq 'todo org-agenda-show-inherited-tags))
  5005. (and (eq org-agenda-show-inherited-tags t)
  5006. (or (eq org-agenda-use-tag-inheritance t)
  5007. (memq 'todo org-agenda-use-tag-inheritance))))
  5008. tags (org-get-tags-at nil (not inherited-tags))
  5009. level (make-string (org-reduced-level (org-outline-level)) ? )
  5010. txt (org-agenda-format-item "" txt level category tags t)
  5011. priority (1+ (org-get-priority txt)))
  5012. (org-add-props txt props
  5013. 'org-marker marker 'org-hd-marker marker
  5014. 'priority priority
  5015. 'level level
  5016. 'ts-date ts-date
  5017. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5018. (push txt ee)
  5019. (if org-agenda-todo-list-sublevels
  5020. (goto-char todo-state-end-pos)
  5021. (org-end-of-subtree 'invisible))))
  5022. (nreverse ee)))
  5023. (defun org-agenda-todo-custom-ignore-p (time n)
  5024. "Check whether timestamp is farther away than n number of days.
  5025. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5026. `org-agenda-todo-ignore-scheduled' or
  5027. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5028. (let ((days (org-time-stamp-to-now
  5029. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5030. (if (>= n 0)
  5031. (>= days n)
  5032. (<= days n))))
  5033. ;;;###autoload
  5034. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5035. (&optional end)
  5036. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5037. (when (or org-agenda-todo-ignore-with-date
  5038. org-agenda-todo-ignore-scheduled
  5039. org-agenda-todo-ignore-deadlines
  5040. org-agenda-todo-ignore-timestamp)
  5041. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5042. (save-excursion
  5043. (or (and org-agenda-todo-ignore-with-date
  5044. (re-search-forward org-ts-regexp end t))
  5045. (and org-agenda-todo-ignore-scheduled
  5046. (re-search-forward org-scheduled-time-regexp end t)
  5047. (cond
  5048. ((eq org-agenda-todo-ignore-scheduled 'future)
  5049. (> (org-time-stamp-to-now
  5050. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5051. ((eq org-agenda-todo-ignore-scheduled 'past)
  5052. (<= (org-time-stamp-to-now
  5053. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5054. ((numberp org-agenda-todo-ignore-scheduled)
  5055. (org-agenda-todo-custom-ignore-p
  5056. (match-string 1) org-agenda-todo-ignore-scheduled))
  5057. (t)))
  5058. (and org-agenda-todo-ignore-deadlines
  5059. (re-search-forward org-deadline-time-regexp end t)
  5060. (cond
  5061. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5062. ((eq org-agenda-todo-ignore-deadlines 'far)
  5063. (not (org-deadline-close (match-string 1))))
  5064. ((eq org-agenda-todo-ignore-deadlines 'future)
  5065. (> (org-time-stamp-to-now
  5066. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5067. ((eq org-agenda-todo-ignore-deadlines 'past)
  5068. (<= (org-time-stamp-to-now
  5069. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5070. ((numberp org-agenda-todo-ignore-deadlines)
  5071. (org-agenda-todo-custom-ignore-p
  5072. (match-string 1) org-agenda-todo-ignore-deadlines))
  5073. (t (org-deadline-close (match-string 1)))))
  5074. (and org-agenda-todo-ignore-timestamp
  5075. (let ((buffer (current-buffer))
  5076. (regexp
  5077. (concat
  5078. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5079. (start (point)))
  5080. ;; Copy current buffer into a temporary one
  5081. (with-temp-buffer
  5082. (insert-buffer-substring buffer start end)
  5083. (goto-char (point-min))
  5084. ;; Delete SCHEDULED and DEADLINE items
  5085. (while (re-search-forward regexp end t)
  5086. (delete-region (match-beginning 0) (match-end 0)))
  5087. (goto-char (point-min))
  5088. ;; No search for timestamp left
  5089. (when (re-search-forward org-ts-regexp nil t)
  5090. (cond
  5091. ((eq org-agenda-todo-ignore-timestamp 'future)
  5092. (> (org-time-stamp-to-now
  5093. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5094. ((eq org-agenda-todo-ignore-timestamp 'past)
  5095. (<= (org-time-stamp-to-now
  5096. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5097. ((numberp org-agenda-todo-ignore-timestamp)
  5098. (org-agenda-todo-custom-ignore-p
  5099. (match-string 1) org-agenda-todo-ignore-timestamp))
  5100. (t))))))))))
  5101. (defun org-agenda-get-timestamps (&optional deadline-results)
  5102. "Return the date stamp information for agenda display."
  5103. (let* ((props (list 'face 'org-agenda-calendar-event
  5104. 'org-not-done-regexp org-not-done-regexp
  5105. 'org-todo-regexp org-todo-regexp
  5106. 'org-complex-heading-regexp org-complex-heading-regexp
  5107. 'mouse-face 'highlight
  5108. 'help-echo
  5109. (format "mouse-2 or RET jump to org file %s"
  5110. (abbreviate-file-name buffer-file-name))))
  5111. (d1 (calendar-absolute-from-gregorian date))
  5112. mm
  5113. (deadline-position-alist
  5114. (mapcar (lambda (a) (and (setq mm (get-text-property
  5115. 0 'org-hd-marker a))
  5116. (cons (marker-position mm) a)))
  5117. deadline-results))
  5118. (remove-re org-ts-regexp)
  5119. (regexp
  5120. (concat
  5121. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5122. (regexp-quote
  5123. (substring
  5124. (format-time-string
  5125. (car org-time-stamp-formats)
  5126. (apply 'encode-time ; DATE bound by calendar
  5127. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5128. 1 11))
  5129. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5130. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5131. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5132. donep tmp priority category level ee txt timestr tags
  5133. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5134. inherited-tags ts-date)
  5135. (goto-char (point-min))
  5136. (while (setq end-of-match (re-search-forward regexp nil t))
  5137. (setq b0 (match-beginning 0)
  5138. b3 (match-beginning 3) e3 (match-end 3)
  5139. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5140. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5141. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5142. (member todo-state
  5143. org-agenda-repeating-timestamp-show-all)))
  5144. (catch :skip
  5145. (and (org-at-date-range-p) (throw :skip nil))
  5146. (org-agenda-skip)
  5147. (if (and (match-end 1)
  5148. (not (= d1 (org-time-string-to-absolute
  5149. (match-string 1) d1 nil show-all
  5150. (current-buffer) b0))))
  5151. (throw :skip nil))
  5152. (if (and e3
  5153. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5154. (throw :skip nil))
  5155. (setq tmp (buffer-substring (max (point-min)
  5156. (- b0 org-ds-keyword-length))
  5157. b0)
  5158. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5159. inactivep (= (char-after b0) ?\[)
  5160. deadlinep (string-match org-deadline-regexp tmp)
  5161. scheduledp (string-match org-scheduled-regexp tmp)
  5162. closedp (and org-agenda-include-inactive-timestamps
  5163. (string-match org-closed-string tmp))
  5164. clockp (and org-agenda-include-inactive-timestamps
  5165. (or (string-match org-clock-string tmp)
  5166. (string-match "]-+\\'" tmp)))
  5167. warntime (get-text-property (point) 'org-appt-warntime)
  5168. donep (member todo-state org-done-keywords))
  5169. (if (or scheduledp deadlinep closedp clockp
  5170. (and donep org-agenda-skip-timestamp-if-done))
  5171. (throw :skip t))
  5172. (if (string-match ">" timestr)
  5173. ;; substring should only run to end of time stamp
  5174. (setq timestr (substring timestr 0 (match-end 0))))
  5175. (setq marker (org-agenda-new-marker b0)
  5176. category (org-get-category b0))
  5177. (save-excursion
  5178. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5179. (throw :skip nil)
  5180. (goto-char (match-beginning 0))
  5181. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5182. (assoc (point) deadline-position-alist))
  5183. (throw :skip nil))
  5184. (setq hdmarker (org-agenda-new-marker)
  5185. inherited-tags
  5186. (or (eq org-agenda-show-inherited-tags 'always)
  5187. (and (listp org-agenda-show-inherited-tags)
  5188. (memq 'agenda org-agenda-show-inherited-tags))
  5189. (and (eq org-agenda-show-inherited-tags t)
  5190. (or (eq org-agenda-use-tag-inheritance t)
  5191. (memq 'agenda org-agenda-use-tag-inheritance))))
  5192. tags (org-get-tags-at nil (not inherited-tags))
  5193. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5194. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5195. (setq head (or (match-string 1) ""))
  5196. (setq txt (org-agenda-format-item
  5197. (if inactivep org-agenda-inactive-leader nil)
  5198. head level category tags timestr
  5199. remove-re habitp)))
  5200. (setq priority (org-get-priority txt))
  5201. (org-add-props txt props 'priority priority
  5202. 'org-marker marker 'org-hd-marker hdmarker
  5203. 'date date
  5204. 'level level
  5205. 'ts-date
  5206. (ignore-errors (org-time-string-to-absolute timestr))
  5207. 'todo-state todo-state
  5208. 'warntime warntime
  5209. 'type "timestamp")
  5210. (push txt ee))
  5211. (if org-agenda-skip-additional-timestamps-same-entry
  5212. (outline-next-heading)
  5213. (goto-char end-of-match))))
  5214. (nreverse ee)))
  5215. (defun org-agenda-get-sexps ()
  5216. "Return the sexp information for agenda display."
  5217. (require 'diary-lib)
  5218. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5219. 'mouse-face 'highlight
  5220. 'help-echo
  5221. (format "mouse-2 or RET jump to org file %s"
  5222. (abbreviate-file-name buffer-file-name))))
  5223. (regexp "^&?%%(")
  5224. marker category extra level ee txt tags entry
  5225. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5226. (goto-char (point-min))
  5227. (while (re-search-forward regexp nil t)
  5228. (catch :skip
  5229. (org-agenda-skip)
  5230. (setq beg (match-beginning 0))
  5231. (goto-char (1- (match-end 0)))
  5232. (setq b (point))
  5233. (forward-sexp 1)
  5234. (setq sexp (buffer-substring b (point)))
  5235. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5236. (org-trim (match-string 1))
  5237. ""))
  5238. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5239. (when result
  5240. (setq marker (org-agenda-new-marker beg)
  5241. level (make-string (org-reduced-level (org-outline-level)) ? )
  5242. category (org-get-category beg)
  5243. inherited-tags
  5244. (or (eq org-agenda-show-inherited-tags 'always)
  5245. (and (listp org-agenda-show-inherited-tags)
  5246. (memq 'agenda org-agenda-show-inherited-tags))
  5247. (and (eq org-agenda-show-inherited-tags t)
  5248. (or (eq org-agenda-use-tag-inheritance t)
  5249. (memq 'agenda org-agenda-use-tag-inheritance))))
  5250. tags (org-get-tags-at nil (not inherited-tags))
  5251. todo-state (org-get-todo-state)
  5252. warntime (get-text-property (point) 'org-appt-warntime)
  5253. extra nil)
  5254. (dolist (r (if (stringp result)
  5255. (list result)
  5256. result)) ;; we expect a list here
  5257. (when (and org-agenda-diary-sexp-prefix
  5258. (string-match org-agenda-diary-sexp-prefix r))
  5259. (setq extra (match-string 0 r)
  5260. r (replace-match "" nil nil r)))
  5261. (if (string-match "\\S-" r)
  5262. (setq txt r)
  5263. (setq txt "SEXP entry returned empty string"))
  5264. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5265. (org-add-props txt props 'org-marker marker
  5266. 'date date 'todo-state todo-state
  5267. 'level level 'type "sexp" 'warntime warntime)
  5268. (push txt ee)))))
  5269. (nreverse ee)))
  5270. ;; Calendar sanity: define some functions that are independent of
  5271. ;; `calendar-date-style'.
  5272. ;; Normally I would like to use ISO format when calling the diary functions,
  5273. ;; but to make sure we still have Emacs 22 compatibility we bind
  5274. ;; also `european-calendar-style' and use european format
  5275. (defun org-anniversary (year month day &optional mark)
  5276. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5277. (org-no-warnings
  5278. (let ((calendar-date-style 'european) (european-calendar-style t))
  5279. (diary-anniversary day month year mark))))
  5280. (defun org-cyclic (N year month day &optional mark)
  5281. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5282. (org-no-warnings
  5283. (let ((calendar-date-style 'european) (european-calendar-style t))
  5284. (diary-cyclic N day month year mark))))
  5285. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5286. "Like `diary-block', but with fixed (ISO) order of arguments."
  5287. (org-no-warnings
  5288. (let ((calendar-date-style 'european) (european-calendar-style t))
  5289. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5290. (defun org-date (year month day &optional mark)
  5291. "Like `diary-date', but with fixed (ISO) order of arguments."
  5292. (org-no-warnings
  5293. (let ((calendar-date-style 'european) (european-calendar-style t))
  5294. (diary-date day month year mark))))
  5295. ;; Define the` org-class' function
  5296. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5297. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5298. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5299. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5300. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5301. `holidays', then any date that is known by the Emacs calendar to be a
  5302. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5303. then those holidays will be skipped."
  5304. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5305. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5306. (d (calendar-absolute-from-gregorian date))
  5307. (h (when skip-weeks (calendar-check-holidays date))))
  5308. (and
  5309. (<= date1 d)
  5310. (<= d date2)
  5311. (= (calendar-day-of-week date) dayname)
  5312. (or (not skip-weeks)
  5313. (progn
  5314. (require 'cal-iso)
  5315. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5316. (not (or (and h (memq 'holidays skip-weeks))
  5317. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5318. entry)))
  5319. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5320. "Like `org-class', but honor `calendar-date-style'.
  5321. The order of the first 2 times 3 arguments depends on the variable
  5322. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5323. So for American calendars, give this as MONTH DAY YEAR, for European as
  5324. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5325. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5326. is any number of ISO weeks in the block period for which the item should
  5327. be skipped.
  5328. This function is here only for backward compatibility and it is deprecated,
  5329. please use `org-class' instead."
  5330. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5331. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5332. (org-class
  5333. (nth 2 date1) (car date1) (nth 1 date1)
  5334. (nth 2 date2) (car date2) (nth 1 date2)
  5335. dayname skip-weeks)))
  5336. (make-obsolete 'org-diary-class 'org-class "")
  5337. (defalias 'org-get-closed 'org-agenda-get-progress)
  5338. (defun org-agenda-get-progress ()
  5339. "Return the logged TODO entries for agenda display."
  5340. (let* ((props (list 'mouse-face 'highlight
  5341. 'org-not-done-regexp org-not-done-regexp
  5342. 'org-todo-regexp org-todo-regexp
  5343. 'org-complex-heading-regexp org-complex-heading-regexp
  5344. 'help-echo
  5345. (format "mouse-2 or RET jump to org file %s"
  5346. (abbreviate-file-name buffer-file-name))))
  5347. (items (if (consp org-agenda-show-log-scoped)
  5348. org-agenda-show-log-scoped
  5349. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5350. '(clock)
  5351. org-agenda-log-mode-items)))
  5352. (parts
  5353. (delq nil
  5354. (list
  5355. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5356. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5357. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5358. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5359. (error "`org-agenda-log-mode-items' is empty")))
  5360. (regexp (concat
  5361. "\\(" parts-re "\\)"
  5362. " *\\["
  5363. (regexp-quote
  5364. (substring
  5365. (format-time-string
  5366. (car org-time-stamp-formats)
  5367. (apply 'encode-time ; DATE bound by calendar
  5368. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5369. 1 11))))
  5370. (org-agenda-search-headline-for-time nil)
  5371. marker hdmarker priority category level tags closedp
  5372. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5373. (goto-char (point-min))
  5374. (while (re-search-forward regexp nil t)
  5375. (catch :skip
  5376. (org-agenda-skip)
  5377. (setq marker (org-agenda-new-marker (match-beginning 0))
  5378. closedp (equal (match-string 1) org-closed-string)
  5379. statep (equal (string-to-char (match-string 1)) ?-)
  5380. clockp (not (or closedp statep))
  5381. state (and statep (match-string 2))
  5382. category (org-get-category (match-beginning 0))
  5383. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5384. (when (string-match "\\]" timestr)
  5385. ;; substring should only run to end of time stamp
  5386. (setq rest (substring timestr (match-end 0))
  5387. timestr (substring timestr 0 (match-end 0)))
  5388. (if (and (not closedp) (not statep)
  5389. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5390. rest))
  5391. (progn (setq timestr (concat (substring timestr 0 -1)
  5392. "-" (match-string 1 rest) "]"))
  5393. (setq clocked (match-string 2 rest)))
  5394. (setq clocked "-")))
  5395. (save-excursion
  5396. (setq extra
  5397. (cond
  5398. ((not org-agenda-log-mode-add-notes) nil)
  5399. (statep
  5400. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5401. (match-string 1)))
  5402. (clockp
  5403. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5404. (match-string 1)))))
  5405. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5406. (throw :skip nil)
  5407. (goto-char (match-beginning 0))
  5408. (setq hdmarker (org-agenda-new-marker)
  5409. inherited-tags
  5410. (or (eq org-agenda-show-inherited-tags 'always)
  5411. (and (listp org-agenda-show-inherited-tags)
  5412. (memq 'todo org-agenda-show-inherited-tags))
  5413. (and (eq org-agenda-show-inherited-tags t)
  5414. (or (eq org-agenda-use-tag-inheritance t)
  5415. (memq 'todo org-agenda-use-tag-inheritance))))
  5416. tags (org-get-tags-at nil (not inherited-tags))
  5417. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5418. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5419. (setq txt (match-string 1))
  5420. (when extra
  5421. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5422. (setq txt (concat (substring txt 0 (match-beginning 1))
  5423. " - " extra " " (match-string 2 txt)))
  5424. (setq txt (concat txt " - " extra))))
  5425. (setq txt (org-agenda-format-item
  5426. (cond
  5427. (closedp "Closed: ")
  5428. (statep (concat "State: (" state ")"))
  5429. (t (concat "Clocked: (" clocked ")")))
  5430. txt level category tags timestr)))
  5431. (setq priority 100000)
  5432. (org-add-props txt props
  5433. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5434. 'priority priority 'level level
  5435. 'type "closed" 'date date
  5436. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5437. (push txt ee))
  5438. (goto-char (point-at-eol))))
  5439. (nreverse ee)))
  5440. (defun org-agenda-show-clocking-issues ()
  5441. "Add overlays, showing issues with clocking.
  5442. See also the user option `org-agenda-clock-consistency-checks'."
  5443. (interactive)
  5444. (let* ((org-time-clocksum-use-effort-durations nil)
  5445. (pl org-agenda-clock-consistency-checks)
  5446. (re (concat "^[ \t]*"
  5447. org-clock-string
  5448. "[ \t]+"
  5449. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5450. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5451. (tlstart 0.)
  5452. (tlend 0.)
  5453. (maxtime (org-hh:mm-string-to-minutes
  5454. (or (plist-get pl :max-duration) "24:00")))
  5455. (mintime (org-hh:mm-string-to-minutes
  5456. (or (plist-get pl :min-duration) 0)))
  5457. (maxgap (org-hh:mm-string-to-minutes
  5458. ;; default 30:00 means never complain
  5459. (or (plist-get pl :max-gap) "30:00")))
  5460. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5461. (plist-get pl :gap-ok-around)))
  5462. (def-face (or (plist-get pl :default-face)
  5463. '((:background "DarkRed") (:foreground "white"))))
  5464. issue face m te ts dt ov)
  5465. (goto-char (point-min))
  5466. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5467. (setq issue nil face def-face)
  5468. (catch 'next
  5469. (setq m (org-get-at-bol 'org-marker)
  5470. te nil ts nil)
  5471. (unless (and m (markerp m))
  5472. (setq issue "No valid clock line") (throw 'next t))
  5473. (org-with-point-at m
  5474. (save-excursion
  5475. (goto-char (point-at-bol))
  5476. (unless (looking-at re)
  5477. (error "No valid Clock line")
  5478. (throw 'next t))
  5479. (unless (match-end 3)
  5480. (setq issue "No end time"
  5481. face (or (plist-get pl :no-end-time-face) face))
  5482. (throw 'next t))
  5483. (setq ts (match-string 1)
  5484. te (match-string 3)
  5485. ts (org-float-time
  5486. (apply 'encode-time (org-parse-time-string ts)))
  5487. te (org-float-time
  5488. (apply 'encode-time (org-parse-time-string te)))
  5489. dt (- te ts))))
  5490. (cond
  5491. ((> dt (* 60 maxtime))
  5492. ;; a very long clocking chunk
  5493. (setq issue (format "Clocking interval is very long: %s"
  5494. (org-minutes-to-clocksum-string
  5495. (floor (/ (float dt) 60.))))
  5496. face (or (plist-get pl :long-face) face)))
  5497. ((< dt (* 60 mintime))
  5498. ;; a very short clocking chunk
  5499. (setq issue (format "Clocking interval is very short: %s"
  5500. (org-minutes-to-clocksum-string
  5501. (floor (/ (float dt) 60.))))
  5502. face (or (plist-get pl :short-face) face)))
  5503. ((and (> tlend 0) (< ts tlend))
  5504. ;; Two clock entries are overlapping
  5505. (setq issue (format "Clocking overlap: %d minutes"
  5506. (/ (- tlend ts) 60))
  5507. face (or (plist-get pl :overlap-face) face)))
  5508. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5509. ;; There is a gap, lets see if we need to report it
  5510. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5511. (setq issue (format "Clocking gap: %d minutes"
  5512. (/ (- ts tlend) 60))
  5513. face (or (plist-get pl :gap-face) face))))
  5514. (t nil)))
  5515. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5516. (when issue
  5517. ;; OK, there was some issue, add an overlay to show the issue
  5518. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5519. (overlay-put ov 'before-string
  5520. (concat
  5521. (org-add-props
  5522. (format "%-43s" (concat " " issue))
  5523. nil
  5524. 'face face)
  5525. "\n"))
  5526. (overlay-put ov 'evaporate t)))))
  5527. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5528. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5529. (catch 'exit
  5530. (unless ok-list
  5531. ;; there are no OK times for gaps...
  5532. (throw 'exit nil))
  5533. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5534. ;; This is more than 24 hours, so it is OK.
  5535. ;; because we have at least one OK time, that must be in the
  5536. ;; 24 hour interval.
  5537. (throw 'exit t))
  5538. ;; We have a shorter gap.
  5539. ;; Now we have to get the minute of the day when these times are
  5540. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5541. (t2dec (decode-time (seconds-to-time t2)))
  5542. ;; compute the minute on the day
  5543. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5544. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5545. (when (< min2 min1)
  5546. ;; if min2 is smaller than min1, this means it is on the next day.
  5547. ;; Wrap it to after midnight.
  5548. (setq min2 (+ min2 1440)))
  5549. ;; Now check if any of the OK times is in the gap
  5550. (mapc (lambda (x)
  5551. ;; Wrap the time to after midnight if necessary
  5552. (if (< x min1) (setq x (+ x 1440)))
  5553. ;; Check if in interval
  5554. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5555. ok-list)
  5556. ;; Nope, this gap is not OK
  5557. nil)))
  5558. (defun org-agenda-get-deadlines (&optional with-hour)
  5559. "Return the deadline information for agenda display.
  5560. When WITH-HOUR is non-nil, only return deadlines with an hour
  5561. specification like [h]h:mm."
  5562. (let* ((props (list 'mouse-face 'highlight
  5563. 'org-not-done-regexp org-not-done-regexp
  5564. 'org-todo-regexp org-todo-regexp
  5565. 'org-complex-heading-regexp org-complex-heading-regexp
  5566. 'help-echo
  5567. (format "mouse-2 or RET jump to org file %s"
  5568. (abbreviate-file-name buffer-file-name))))
  5569. (regexp (if with-hour
  5570. org-deadline-time-hour-regexp
  5571. org-deadline-time-regexp))
  5572. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5573. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5574. (dl0 (car org-agenda-deadline-leaders))
  5575. (dl1 (nth 1 org-agenda-deadline-leaders))
  5576. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5577. d2 diff dfrac wdays pos pos1 category level
  5578. tags suppress-prewarning ee txt head face s todo-state
  5579. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5580. (goto-char (point-min))
  5581. (while (re-search-forward regexp nil t)
  5582. (catch :skip
  5583. (org-agenda-skip)
  5584. (setq s (match-string 1)
  5585. txt nil
  5586. pos (1- (match-beginning 1))
  5587. todo-state (save-match-data (org-get-todo-state))
  5588. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5589. (member todo-state
  5590. org-agenda-repeating-timestamp-show-all))
  5591. d2 (org-time-string-to-absolute
  5592. s d1 'past show-all (current-buffer) pos)
  5593. diff (- d2 d1))
  5594. (setq suppress-prewarning
  5595. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5596. (let ((item (buffer-substring (point-at-bol)
  5597. (point-at-eol))))
  5598. (save-match-data
  5599. (and (string-match
  5600. org-scheduled-time-regexp item)
  5601. (match-string 1 item)))))))
  5602. (cond
  5603. ((not ds) nil)
  5604. ;; The current item has a scheduled date (in ds), so
  5605. ;; evaluate its prewarning lead time.
  5606. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5607. ;; Use global prewarning-restart lead time.
  5608. org-agenda-skip-deadline-prewarning-if-scheduled)
  5609. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5610. 'pre-scheduled)
  5611. ;; Set prewarning to no earlier than scheduled.
  5612. (min (- d2 (org-time-string-to-absolute
  5613. ds d1 'past show-all (current-buffer) pos))
  5614. org-deadline-warning-days))
  5615. ;; Set prewarning to deadline.
  5616. (t 0))))
  5617. (setq wdays (if suppress-prewarning
  5618. (let ((org-deadline-warning-days suppress-prewarning))
  5619. (org-get-wdays s))
  5620. (org-get-wdays s))
  5621. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5622. upcomingp (and todayp (> diff 0)))
  5623. ;; When to show a deadline in the calendar:
  5624. ;; If the expiration is within wdays warning time.
  5625. ;; Past-due deadlines are only shown on the current date
  5626. (if (and (or (and (<= diff wdays)
  5627. (and todayp (not org-agenda-only-exact-dates)))
  5628. (= diff 0)))
  5629. (save-excursion
  5630. ;; (setq todo-state (org-get-todo-state))
  5631. (setq donep (member todo-state org-done-keywords))
  5632. (if (and donep
  5633. (or org-agenda-skip-deadline-if-done
  5634. (not (= diff 0))))
  5635. (setq txt nil)
  5636. (setq category (org-get-category)
  5637. warntime (get-text-property (point) 'org-appt-warntime))
  5638. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5639. (throw :skip nil)
  5640. (goto-char (match-end 0))
  5641. (setq pos1 (match-beginning 0))
  5642. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5643. (setq inherited-tags
  5644. (or (eq org-agenda-show-inherited-tags 'always)
  5645. (and (listp org-agenda-show-inherited-tags)
  5646. (memq 'agenda org-agenda-show-inherited-tags))
  5647. (and (eq org-agenda-show-inherited-tags t)
  5648. (or (eq org-agenda-use-tag-inheritance t)
  5649. (memq 'agenda org-agenda-use-tag-inheritance))))
  5650. tags (org-get-tags-at pos1 (not inherited-tags)))
  5651. (setq head (buffer-substring
  5652. (point)
  5653. (progn (skip-chars-forward "^\r\n")
  5654. (point))))
  5655. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5656. (setq timestr
  5657. (concat (substring s (match-beginning 1)) " "))
  5658. (setq timestr 'time))
  5659. (setq txt (org-agenda-format-item
  5660. (cond ((= diff 0) dl0)
  5661. ((> diff 0)
  5662. (if (functionp dl1)
  5663. (funcall dl1 diff date)
  5664. (format dl1 diff)))
  5665. (t
  5666. (if (functionp dl2)
  5667. (funcall dl2 diff date)
  5668. (format dl2 (if (string= dl2 dl1)
  5669. diff (abs diff))))))
  5670. head level category tags
  5671. (if (not (= diff 0)) nil timestr)))))
  5672. (when txt
  5673. (setq face (org-agenda-deadline-face dfrac))
  5674. (org-add-props txt props
  5675. 'org-marker (org-agenda-new-marker pos)
  5676. 'warntime warntime
  5677. 'level level
  5678. 'ts-date d2
  5679. 'org-hd-marker (org-agenda-new-marker pos1)
  5680. 'priority (+ (- diff)
  5681. (org-get-priority txt))
  5682. 'todo-state todo-state
  5683. 'type (if upcomingp "upcoming-deadline" "deadline")
  5684. 'date (if upcomingp date d2)
  5685. 'face (if donep 'org-agenda-done face)
  5686. 'undone-face face 'done-face 'org-agenda-done)
  5687. (push txt ee))))))
  5688. (nreverse ee)))
  5689. (defun org-agenda-deadline-face (fraction)
  5690. "Return the face to displaying a deadline item.
  5691. FRACTION is what fraction of the head-warning time has passed."
  5692. (let ((faces org-agenda-deadline-faces) f)
  5693. (catch 'exit
  5694. (while (setq f (pop faces))
  5695. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5696. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5697. "Return the scheduled information for agenda display.
  5698. When WITH-HOUR is non-nil, only return scheduled items with
  5699. an hour specification like [h]h:mm."
  5700. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5701. 'org-todo-regexp org-todo-regexp
  5702. 'org-complex-heading-regexp org-complex-heading-regexp
  5703. 'done-face 'org-agenda-done
  5704. 'mouse-face 'highlight
  5705. 'help-echo
  5706. (format "mouse-2 or RET jump to org file %s"
  5707. (abbreviate-file-name buffer-file-name))))
  5708. (regexp (if with-hour
  5709. org-scheduled-time-hour-regexp
  5710. org-scheduled-time-regexp))
  5711. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5712. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5713. mm
  5714. (deadline-position-alist
  5715. (mapcar (lambda (a) (and (setq mm (get-text-property
  5716. 0 'org-hd-marker a))
  5717. (cons (marker-position mm) a)))
  5718. deadline-results))
  5719. d2 diff pos pos1 category level tags donep
  5720. ee txt head pastschedp todo-state face timestr s habitp show-all
  5721. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5722. ddays)
  5723. (goto-char (point-min))
  5724. (while (re-search-forward regexp nil t)
  5725. (catch :skip
  5726. (org-agenda-skip)
  5727. (setq s (match-string 1)
  5728. txt nil
  5729. pos (1- (match-beginning 1))
  5730. todo-state (save-match-data (org-get-todo-state))
  5731. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5732. (member todo-state
  5733. org-agenda-repeating-timestamp-show-all))
  5734. d2 (org-time-string-to-absolute
  5735. s d1 'past show-all (current-buffer) pos)
  5736. diff (- d2 d1)
  5737. warntime (get-text-property (point) 'org-appt-warntime))
  5738. (setq pastschedp (and todayp (< diff 0)))
  5739. (setq did-habit-check-p nil)
  5740. (setq suppress-delay
  5741. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5742. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5743. (save-match-data
  5744. (and (string-match
  5745. org-deadline-time-regexp item)
  5746. (match-string 1 item)))))))
  5747. (cond
  5748. ((not ds) nil)
  5749. ;; The current item has a deadline date (in ds), so
  5750. ;; evaluate its delay time.
  5751. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5752. ;; Use global delay time.
  5753. (- org-agenda-skip-scheduled-delay-if-deadline))
  5754. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5755. 'post-deadline)
  5756. ;; Set delay to no later than deadline.
  5757. (min (- d2 (org-time-string-to-absolute
  5758. ds d1 'past show-all (current-buffer) pos))
  5759. org-scheduled-delay-days))
  5760. (t 0))))
  5761. (setq ddays (if suppress-delay
  5762. (let ((org-scheduled-delay-days suppress-delay))
  5763. (org-get-wdays s t t))
  5764. (org-get-wdays s t)))
  5765. ;; Use a delay of 0 when there is a repeater and the delay is
  5766. ;; of the form --3d
  5767. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5768. (< (org-time-string-to-absolute s)
  5769. (org-time-string-to-absolute
  5770. s d2 'past nil (current-buffer) pos)))
  5771. (setq ddays 0))
  5772. ;; When to show a scheduled item in the calendar:
  5773. ;; If it is on or past the date.
  5774. (when (or (and (> ddays 0) (= diff (- ddays)))
  5775. (and (zerop ddays) (= diff 0))
  5776. (and (< (+ diff ddays) 0)
  5777. (< (abs diff) org-scheduled-past-days)
  5778. (and todayp (not org-agenda-only-exact-dates)))
  5779. ;; org-is-habit-p uses org-entry-get, which is expansive
  5780. ;; so we go extra mile to only call it once
  5781. (and todayp
  5782. (boundp 'org-habit-show-all-today)
  5783. org-habit-show-all-today
  5784. (setq did-habit-check-p t)
  5785. (setq habitp (and (functionp 'org-is-habit-p)
  5786. (org-is-habit-p)))))
  5787. (save-excursion
  5788. (setq donep (member todo-state org-done-keywords))
  5789. (if (and donep
  5790. (or org-agenda-skip-scheduled-if-done
  5791. (not (= diff 0))
  5792. (and (functionp 'org-is-habit-p)
  5793. (org-is-habit-p))))
  5794. (setq txt nil)
  5795. (setq habitp (if did-habit-check-p habitp
  5796. (and (functionp 'org-is-habit-p)
  5797. (org-is-habit-p))))
  5798. (setq category (org-get-category))
  5799. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5800. 'repeated-after-deadline)
  5801. (org-get-deadline-time (point))
  5802. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5803. (throw :skip nil))
  5804. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5805. (throw :skip nil)
  5806. (goto-char (match-end 0))
  5807. (setq pos1 (match-beginning 0))
  5808. (if habitp
  5809. (if (or (not org-habit-show-habits)
  5810. (and (not todayp)
  5811. (boundp 'org-habit-show-habits-only-for-today)
  5812. org-habit-show-habits-only-for-today))
  5813. (throw :skip nil))
  5814. (if (and
  5815. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5816. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5817. pastschedp))
  5818. (setq mm (assoc pos1 deadline-position-alist)))
  5819. (throw :skip nil)))
  5820. (setq inherited-tags
  5821. (or (eq org-agenda-show-inherited-tags 'always)
  5822. (and (listp org-agenda-show-inherited-tags)
  5823. (memq 'agenda org-agenda-show-inherited-tags))
  5824. (and (eq org-agenda-show-inherited-tags t)
  5825. (or (eq org-agenda-use-tag-inheritance t)
  5826. (memq 'agenda org-agenda-use-tag-inheritance))))
  5827. tags (org-get-tags-at nil (not inherited-tags)))
  5828. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5829. (setq head (buffer-substring
  5830. (point)
  5831. (progn (skip-chars-forward "^\r\n") (point))))
  5832. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5833. (setq timestr
  5834. (concat (substring s (match-beginning 1)) " "))
  5835. (setq timestr 'time))
  5836. (setq txt (org-agenda-format-item
  5837. (if (= diff 0)
  5838. (car org-agenda-scheduled-leaders)
  5839. (format (nth 1 org-agenda-scheduled-leaders)
  5840. (- 1 diff)))
  5841. head level category tags
  5842. (if (not (= diff 0)) nil timestr)
  5843. nil habitp))))
  5844. (when txt
  5845. (setq face
  5846. (cond
  5847. ((and (not habitp) pastschedp)
  5848. 'org-scheduled-previously)
  5849. (todayp 'org-scheduled-today)
  5850. (t 'org-scheduled))
  5851. habitp (and habitp (org-habit-parse-todo)))
  5852. (org-add-props txt props
  5853. 'undone-face face
  5854. 'face (if donep 'org-agenda-done face)
  5855. 'org-marker (org-agenda-new-marker pos)
  5856. 'org-hd-marker (org-agenda-new-marker pos1)
  5857. 'type (if pastschedp "past-scheduled" "scheduled")
  5858. 'date (if pastschedp d2 date)
  5859. 'ts-date d2
  5860. 'warntime warntime
  5861. 'level level
  5862. 'priority (if habitp
  5863. (org-habit-get-priority habitp)
  5864. (+ 94 (- 5 diff) (org-get-priority txt)))
  5865. 'org-habit-p habitp
  5866. 'todo-state todo-state)
  5867. (push txt ee))))))
  5868. (nreverse ee)))
  5869. (defun org-agenda-get-blocks ()
  5870. "Return the date-range information for agenda display."
  5871. (let* ((props (list 'face nil
  5872. 'org-not-done-regexp org-not-done-regexp
  5873. 'org-todo-regexp org-todo-regexp
  5874. 'org-complex-heading-regexp org-complex-heading-regexp
  5875. 'mouse-face 'highlight
  5876. 'help-echo
  5877. (format "mouse-2 or RET jump to org file %s"
  5878. (abbreviate-file-name buffer-file-name))))
  5879. (regexp org-tr-regexp)
  5880. (d0 (calendar-absolute-from-gregorian date))
  5881. marker hdmarker ee txt d1 d2 s1 s2 category
  5882. level todo-state tags pos head donep inherited-tags)
  5883. (goto-char (point-min))
  5884. (while (re-search-forward regexp nil t)
  5885. (catch :skip
  5886. (org-agenda-skip)
  5887. (setq pos (point))
  5888. (let ((start-time (match-string 1))
  5889. (end-time (match-string 2)))
  5890. (setq s1 (match-string 1)
  5891. s2 (match-string 2)
  5892. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5893. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5894. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5895. ;; Only allow days between the limits, because the normal
  5896. ;; date stamps will catch the limits.
  5897. (save-excursion
  5898. (setq todo-state (org-get-todo-state))
  5899. (setq donep (member todo-state org-done-keywords))
  5900. (if (and donep org-agenda-skip-timestamp-if-done)
  5901. (throw :skip t))
  5902. (setq marker (org-agenda-new-marker (point))
  5903. category (org-get-category))
  5904. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5905. (throw :skip nil)
  5906. (goto-char (match-beginning 0))
  5907. (setq hdmarker (org-agenda-new-marker (point))
  5908. inherited-tags
  5909. (or (eq org-agenda-show-inherited-tags 'always)
  5910. (and (listp org-agenda-show-inherited-tags)
  5911. (memq 'agenda org-agenda-show-inherited-tags))
  5912. (and (eq org-agenda-show-inherited-tags t)
  5913. (or (eq org-agenda-use-tag-inheritance t)
  5914. (memq 'agenda org-agenda-use-tag-inheritance))))
  5915. tags (org-get-tags-at nil (not inherited-tags)))
  5916. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5917. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5918. (setq head (match-string 1))
  5919. (let ((remove-re
  5920. (if org-agenda-remove-timeranges-from-blocks
  5921. (concat
  5922. "<" (regexp-quote s1) ".*?>"
  5923. "--"
  5924. "<" (regexp-quote s2) ".*?>")
  5925. nil)))
  5926. (setq txt (org-agenda-format-item
  5927. (format
  5928. (nth (if (= d1 d2) 0 1)
  5929. org-agenda-timerange-leaders)
  5930. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5931. head level category tags
  5932. (cond ((and (= d1 d0) (= d2 d0))
  5933. (concat "<" start-time ">--<" end-time ">"))
  5934. ((= d1 d0)
  5935. (concat "<" start-time ">"))
  5936. ((= d2 d0)
  5937. (concat "<" end-time ">")))
  5938. remove-re))))
  5939. (org-add-props txt props
  5940. 'org-marker marker 'org-hd-marker hdmarker
  5941. 'type "block" 'date date
  5942. 'level level
  5943. 'todo-state todo-state
  5944. 'priority (org-get-priority txt))
  5945. (push txt ee))))
  5946. (goto-char pos)))
  5947. ;; Sort the entries by expiration date.
  5948. (nreverse ee)))
  5949. ;;; Agenda presentation and sorting
  5950. (defvar org-prefix-has-time nil
  5951. "A flag, set by `org-compile-prefix-format'.
  5952. The flag is set if the currently compiled format contains a `%t'.")
  5953. (defvar org-prefix-has-tag nil
  5954. "A flag, set by `org-compile-prefix-format'.
  5955. The flag is set if the currently compiled format contains a `%T'.")
  5956. (defvar org-prefix-has-effort nil
  5957. "A flag, set by `org-compile-prefix-format'.
  5958. The flag is set if the currently compiled format contains a `%e'.")
  5959. (defvar org-prefix-has-breadcrumbs nil
  5960. "A flag, set by `org-compile-prefix-format'.
  5961. The flag is set if the currently compiled format contains a `%b'.")
  5962. (defvar org-prefix-category-length nil
  5963. "Used by `org-compile-prefix-format' to remember the category field width.")
  5964. (defvar org-prefix-category-max-length nil
  5965. "Used by `org-compile-prefix-format' to remember the category field width.")
  5966. (defun org-agenda-get-category-icon (category)
  5967. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5968. (dolist (entry org-agenda-category-icon-alist)
  5969. (when (org-string-match-p (car entry) category)
  5970. (if (listp (cadr entry))
  5971. (return (cadr entry))
  5972. (return (apply 'create-image (cdr entry)))))))
  5973. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5974. remove-re habitp)
  5975. "Format TXT to be inserted into the agenda buffer.
  5976. In particular, add the prefix and corresponding text properties.
  5977. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5978. LEVEL may be a string to replace the `%l' specifier.
  5979. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5980. category taken from local variable or file name. It will replace the `%c'
  5981. specifier in the format.
  5982. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5983. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5984. When DOTIME is a string, this string is searched for a time before TXT is.
  5985. TAGS can be the tags of the headline.
  5986. Any match of REMOVE-RE will be removed from TXT."
  5987. ;; We keep the org-prefix-* variable values along with a compiled
  5988. ;; formatter, so that multiple agendas existing at the same time do
  5989. ;; not step on each other toes.
  5990. ;;
  5991. ;; It was inconvenient to make these variables buffer local in
  5992. ;; Agenda buffers, because this function expects to be called with
  5993. ;; the buffer where item comes from being current, and not agenda
  5994. ;; buffer
  5995. (let* ((bindings (car org-prefix-format-compiled))
  5996. (formatter (cadr org-prefix-format-compiled)))
  5997. (loop for (var value) in bindings
  5998. do (set var value))
  5999. (save-match-data
  6000. ;; Diary entries sometimes have extra whitespace at the beginning
  6001. (setq txt (org-trim txt))
  6002. ;; Fix the tags part in txt
  6003. (setq txt (org-agenda-fix-displayed-tags
  6004. txt tags
  6005. org-agenda-show-inherited-tags
  6006. org-agenda-hide-tags-regexp))
  6007. (let* ((category (or category
  6008. (if buffer-file-name
  6009. (file-name-sans-extension
  6010. (file-name-nondirectory buffer-file-name))
  6011. "")))
  6012. (category-icon (org-agenda-get-category-icon category))
  6013. (category-icon (if category-icon
  6014. (propertize " " 'display category-icon)
  6015. ""))
  6016. (effort (and (not (string= txt ""))
  6017. (get-text-property 1 'effort txt)))
  6018. ;; time, tag, effort are needed for the eval of the prefix format
  6019. (tag (if tags (nth (1- (length tags)) tags) ""))
  6020. time
  6021. (ts (if dotime (concat
  6022. (if (stringp dotime) dotime "")
  6023. (and org-agenda-search-headline-for-time txt))))
  6024. (time-of-day (and dotime (org-get-time-of-day ts)))
  6025. stamp plain s0 s1 s2 rtn srp l
  6026. duration breadcrumbs)
  6027. (and (derived-mode-p 'org-mode) buffer-file-name
  6028. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6029. (when (and dotime time-of-day)
  6030. ;; Extract starting and ending time and move them to prefix
  6031. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6032. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6033. (setq s0 (match-string 0 ts)
  6034. srp (and stamp (match-end 3))
  6035. s1 (match-string (if plain 1 2) ts)
  6036. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6037. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6038. ;; them, we might want to remove them there to avoid duplication.
  6039. ;; The user can turn this off with a variable.
  6040. (if (and org-prefix-has-time
  6041. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6042. (string-match (concat (regexp-quote s0) " *") txt)
  6043. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6044. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6045. (= (match-beginning 0) 0)
  6046. t))
  6047. (setq txt (replace-match "" nil nil txt))))
  6048. ;; Normalize the time(s) to 24 hour
  6049. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6050. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6051. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6052. (let (org-time-clocksum-use-effort-durations)
  6053. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6054. (setq s2
  6055. (org-minutes-to-clocksum-string
  6056. (+ (org-hh:mm-string-to-minutes s1)
  6057. org-agenda-default-appointment-duration)))))
  6058. ;; Compute the duration
  6059. (when s2
  6060. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6061. (org-hh:mm-string-to-minutes s1)))))
  6062. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6063. txt)
  6064. ;; Tags are in the string
  6065. (if (or (eq org-agenda-remove-tags t)
  6066. (and org-agenda-remove-tags
  6067. org-prefix-has-tag))
  6068. (setq txt (replace-match "" t t txt))
  6069. (setq txt (replace-match
  6070. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6071. (match-string 2 txt))
  6072. t t txt))))
  6073. (when remove-re
  6074. (while (string-match remove-re txt)
  6075. (setq txt (replace-match "" t t txt))))
  6076. ;; Set org-heading property on `txt' to mark the start of the
  6077. ;; heading.
  6078. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6079. ;; Prepare the variables needed in the eval of the compiled format
  6080. (if org-prefix-has-breadcrumbs
  6081. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6082. (let ((s (org-display-outline-path nil nil "->" t)))
  6083. (if (eq "" s) "" (concat s "->"))))))
  6084. (setq time (cond (s2 (concat
  6085. (org-agenda-time-of-day-to-ampm-maybe s1)
  6086. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6087. (if org-agenda-timegrid-use-ampm " ")))
  6088. (s1 (concat
  6089. (org-agenda-time-of-day-to-ampm-maybe s1)
  6090. (if org-agenda-timegrid-use-ampm
  6091. "........ "
  6092. "......")))
  6093. (t ""))
  6094. extra (or (and (not habitp) extra) "")
  6095. category (if (symbolp category) (symbol-name category) category)
  6096. level (or level ""))
  6097. (if (string-match org-bracket-link-regexp category)
  6098. (progn
  6099. (setq l (if (match-end 3)
  6100. (- (match-end 3) (match-beginning 3))
  6101. (- (match-end 1) (match-beginning 1))))
  6102. (when (< l (or org-prefix-category-length 0))
  6103. (setq category (copy-sequence category))
  6104. (org-add-props category nil
  6105. 'extra-space (make-string
  6106. (- org-prefix-category-length l 1) ?\ ))))
  6107. (if (and org-prefix-category-max-length
  6108. (>= (length category) org-prefix-category-max-length))
  6109. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6110. ;; Evaluate the compiled format
  6111. (setq rtn (concat (eval formatter) txt))
  6112. ;; And finally add the text properties
  6113. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6114. (org-add-props rtn nil
  6115. 'org-category category
  6116. 'tags (mapcar 'org-downcase-keep-props tags)
  6117. 'org-highest-priority org-highest-priority
  6118. 'org-lowest-priority org-lowest-priority
  6119. 'time-of-day time-of-day
  6120. 'duration duration
  6121. 'breadcrumbs breadcrumbs
  6122. 'txt txt
  6123. 'level level
  6124. 'time time
  6125. 'extra extra
  6126. 'format org-prefix-format-compiled
  6127. 'dotime dotime)))))
  6128. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6129. "Remove tags string from TXT, and add a modified list of tags.
  6130. The modified list may contain inherited tags, and tags matched by
  6131. `org-agenda-hide-tags-regexp' will be removed."
  6132. (when (or add-inherited hide-re)
  6133. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6134. (setq txt (substring txt 0 (match-beginning 0))))
  6135. (setq tags
  6136. (delq nil
  6137. (mapcar (lambda (tg)
  6138. (if (or (and hide-re (string-match hide-re tg))
  6139. (and (not add-inherited)
  6140. (get-text-property 0 'inherited tg)))
  6141. nil
  6142. tg))
  6143. tags)))
  6144. (when tags
  6145. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6146. i)
  6147. (setq txt (concat txt " :"
  6148. (mapconcat
  6149. (lambda (x)
  6150. (setq i (get-text-property 0 'inherited x))
  6151. (if (and have-i (not i))
  6152. (progn
  6153. (setq have-i nil)
  6154. (concat ":" x))
  6155. x))
  6156. tags ":")
  6157. (if have-i "::" ":"))))))
  6158. txt)
  6159. (defun org-downcase-keep-props (s)
  6160. (let ((props (text-properties-at 0 s)))
  6161. (setq s (downcase s))
  6162. (add-text-properties 0 (length s) props s)
  6163. s))
  6164. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6165. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6166. "Add a time-grid for agenda items which need it.
  6167. LIST is the list of agenda items formatted by `org-agenda-list'.
  6168. NDAYS is the span of the current agenda view.
  6169. TODAYP is `t' when the current agenda view is on today."
  6170. (catch 'exit
  6171. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6172. ((and todayp (member 'today (car org-agenda-time-grid))))
  6173. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6174. ((member 'weekly (car org-agenda-time-grid)))
  6175. (t (throw 'exit list)))
  6176. (let* ((have (delq nil (mapcar
  6177. (lambda (x) (get-text-property 1 'time-of-day x))
  6178. list)))
  6179. (string (nth 1 org-agenda-time-grid))
  6180. (gridtimes (nth 2 org-agenda-time-grid))
  6181. (req (car org-agenda-time-grid))
  6182. (remove (member 'remove-match req))
  6183. new time)
  6184. (if (and (member 'require-timed req) (not have))
  6185. ;; don't show empty grid
  6186. (throw 'exit list))
  6187. (while (setq time (pop gridtimes))
  6188. (unless (and remove (member time have))
  6189. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6190. (push (org-agenda-format-item
  6191. nil string nil "" nil
  6192. (concat (substring time 0 -2) ":" (substring time -2)))
  6193. new)
  6194. (put-text-property
  6195. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6196. (when (and todayp org-agenda-show-current-time-in-grid)
  6197. (push (org-agenda-format-item
  6198. nil org-agenda-current-time-string nil "" nil
  6199. (format-time-string "%H:%M "))
  6200. new)
  6201. (put-text-property
  6202. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6203. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6204. (append new list)
  6205. (append list new)))))
  6206. (defun org-compile-prefix-format (key)
  6207. "Compile the prefix format into a Lisp form that can be evaluated.
  6208. The resulting form and associated variable bindings is returned
  6209. and stored in the variable `org-prefix-format-compiled'."
  6210. (setq org-prefix-has-time nil
  6211. org-prefix-has-tag nil
  6212. org-prefix-category-length nil
  6213. org-prefix-has-effort nil
  6214. org-prefix-has-breadcrumbs nil)
  6215. (let ((s (cond
  6216. ((stringp org-agenda-prefix-format)
  6217. org-agenda-prefix-format)
  6218. ((assq key org-agenda-prefix-format)
  6219. (cdr (assq key org-agenda-prefix-format)))
  6220. (t " %-12:c%?-12t% s")))
  6221. (start 0)
  6222. varform vars var e c f opt)
  6223. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6224. s start)
  6225. (setq var (or (cdr (assoc (match-string 4 s)
  6226. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6227. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6228. 'eval)
  6229. c (or (match-string 3 s) "")
  6230. opt (match-beginning 1)
  6231. start (1+ (match-beginning 0)))
  6232. (if (equal var 'time) (setq org-prefix-has-time t))
  6233. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6234. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6235. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6236. (setq f (concat "%" (match-string 2 s) "s"))
  6237. (when (equal var 'category)
  6238. (setq org-prefix-category-length
  6239. (floor (abs (string-to-number (match-string 2 s)))))
  6240. (setq org-prefix-category-max-length
  6241. (let ((x (match-string 2 s)))
  6242. (save-match-data
  6243. (if (string-match "\\.[0-9]+" x)
  6244. (string-to-number (substring (match-string 0 x) 1)))))))
  6245. (if (eq var 'eval)
  6246. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6247. (if opt
  6248. (setq varform
  6249. `(if (or (equal "" ,var) (equal nil ,var))
  6250. ""
  6251. (format ,f (concat ,var ,c))))
  6252. (setq varform
  6253. `(format ,f (if (or (equal ,var "")
  6254. (equal ,var nil)) ""
  6255. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6256. (setq s (replace-match "%s" t nil s))
  6257. (push varform vars))
  6258. (setq vars (nreverse vars))
  6259. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6260. (setq org-prefix-format-compiled
  6261. (list
  6262. `((org-prefix-has-time ,org-prefix-has-time)
  6263. (org-prefix-has-tag ,org-prefix-has-tag)
  6264. (org-prefix-category-length ,org-prefix-category-length)
  6265. (org-prefix-has-effort ,org-prefix-has-effort)
  6266. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6267. `(format ,s ,@vars))))))
  6268. (defun org-set-sorting-strategy (key)
  6269. (if (symbolp (car org-agenda-sorting-strategy))
  6270. ;; the old format
  6271. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6272. (setq org-agenda-sorting-strategy-selected
  6273. (or (cdr (assq key org-agenda-sorting-strategy))
  6274. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6275. '(time-up category-keep priority-down)))))
  6276. (defun org-get-time-of-day (s &optional string mod24)
  6277. "Check string S for a time of day.
  6278. If found, return it as a military time number between 0 and 2400.
  6279. If not found, return nil.
  6280. The optional STRING argument forces conversion into a 5 character wide string
  6281. HH:MM."
  6282. (save-match-data
  6283. (when
  6284. (and
  6285. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6286. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6287. (not (eq (get-text-property 1 'face s) 'org-link)))
  6288. (let* ((h (string-to-number (match-string 1 s)))
  6289. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6290. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6291. (am-p (equal ampm "am"))
  6292. (h1 (cond ((not ampm) h)
  6293. ((= h 12) (if am-p 0 12))
  6294. (t (+ h (if am-p 0 12)))))
  6295. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6296. (mod h1 24) h1))
  6297. (t0 (+ (* 100 h2) m))
  6298. (t1 (concat (if (>= h1 24) "+" " ")
  6299. (if (and org-agenda-time-leading-zero
  6300. (< t0 1000)) "0" "")
  6301. (if (< t0 100) "0" "")
  6302. (if (< t0 10) "0" "")
  6303. (int-to-string t0))))
  6304. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6305. (defvar org-agenda-before-sorting-filter-function nil
  6306. "Function to be applied to agenda items prior to sorting.
  6307. Prior to sorting also means just before they are inserted into the agenda.
  6308. To aid sorting, you may revisit the original entries and add more text
  6309. properties which will later be used by the sorting functions.
  6310. The function should take a string argument, an agenda line.
  6311. It has access to the text properties in that line, which contain among
  6312. other things, the property `org-hd-marker' that points to the entry
  6313. where the line comes from. Note that not all lines going into the agenda
  6314. have this property, only most.
  6315. The function should return the modified string. It is probably best
  6316. to ONLY change text properties.
  6317. You can also use this function as a filter, by returning nil for lines
  6318. you don't want to have in the agenda at all. For this application, you
  6319. could bind the variable in the options section of a custom command.")
  6320. (defun org-agenda-finalize-entries (list &optional type)
  6321. "Sort, limit and concatenate the LIST of agenda items.
  6322. The optional argument TYPE tells the agenda type."
  6323. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6324. (cdr (assoc type org-agenda-max-effort)))
  6325. (t org-agenda-max-effort)))
  6326. (max-todo (cond ((listp org-agenda-max-todos)
  6327. (cdr (assoc type org-agenda-max-todos)))
  6328. (t org-agenda-max-todos)))
  6329. (max-tags (cond ((listp org-agenda-max-tags)
  6330. (cdr (assoc type org-agenda-max-tags)))
  6331. (t org-agenda-max-tags)))
  6332. (max-entries (cond ((listp org-agenda-max-entries)
  6333. (cdr (assoc type org-agenda-max-entries)))
  6334. (t org-agenda-max-entries))))
  6335. (when org-agenda-before-sorting-filter-function
  6336. (setq list
  6337. (delq nil
  6338. (mapcar
  6339. org-agenda-before-sorting-filter-function list))))
  6340. (setq list (mapcar 'org-agenda-highlight-todo list)
  6341. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6342. (when max-effort
  6343. (setq list (org-agenda-limit-entries
  6344. list 'effort-minutes max-effort
  6345. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6346. 32767 -1))))))
  6347. (when max-todo
  6348. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6349. (when max-tags
  6350. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6351. (when max-entries
  6352. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6353. (mapconcat 'identity list "\n")))
  6354. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6355. "Limit the number of agenda entries."
  6356. (let ((include (and limit (< limit 0))))
  6357. (if limit
  6358. (let ((fun (or fn (lambda (p) (if p 1))))
  6359. (lim 0))
  6360. (delq nil
  6361. (mapcar
  6362. (lambda (e)
  6363. (let ((pval (funcall
  6364. fun (get-text-property (1- (length e))
  6365. prop e))))
  6366. (if pval (setq lim (+ lim pval)))
  6367. (cond ((and pval (<= lim (abs limit))) e)
  6368. ((and include (not pval)) e))))
  6369. list)))
  6370. list)))
  6371. (defun org-agenda-limit-interactively (remove)
  6372. "In agenda, interactively limit entries to various maximums."
  6373. (interactive "P")
  6374. (if remove
  6375. (progn (setq org-agenda-max-entries nil
  6376. org-agenda-max-todos nil
  6377. org-agenda-max-tags nil
  6378. org-agenda-max-effort nil)
  6379. (org-agenda-redo))
  6380. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6381. (msg (cond ((= max ?E) "How many minutes? ")
  6382. ((= max ?e) "How many entries? ")
  6383. ((= max ?t) "How many TODO entries? ")
  6384. ((= max ?T) "How many tagged entries? ")
  6385. (t (user-error "Wrong input"))))
  6386. (num (string-to-number (read-from-minibuffer msg))))
  6387. (cond ((equal max ?e)
  6388. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6389. ((equal max ?t)
  6390. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6391. ((equal max ?T)
  6392. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6393. ((equal max ?E)
  6394. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6395. (org-agenda-fit-window-to-buffer))
  6396. (defun org-agenda-highlight-todo (x)
  6397. (let ((org-done-keywords org-done-keywords-for-agenda)
  6398. (case-fold-search nil)
  6399. re)
  6400. (if (eq x 'line)
  6401. (save-excursion
  6402. (beginning-of-line 1)
  6403. (setq re (org-get-at-bol 'org-todo-regexp))
  6404. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6405. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6406. (add-text-properties (match-beginning 0) (match-end 1)
  6407. (list 'face (org-get-todo-face 1)))
  6408. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6409. (delete-region (match-beginning 1) (1- (match-end 0)))
  6410. (goto-char (match-beginning 1))
  6411. (insert (format org-agenda-todo-keyword-format s)))))
  6412. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6413. (setq re (get-text-property 0 'org-todo-regexp x))
  6414. (when (and re
  6415. ;; Test `pl' because if there's no heading content,
  6416. ;; there's no point matching to highlight. Note
  6417. ;; that if we didn't test `pl' first, and there
  6418. ;; happened to be no keyword from `org-todo-regexp'
  6419. ;; on this heading line, then the `equal' comparison
  6420. ;; afterwards would spuriously succeed in the case
  6421. ;; where `pl' is nil -- causing an args-out-of-range
  6422. ;; error when we try to add text properties to text
  6423. ;; that isn't there.
  6424. pl
  6425. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6426. x pl) pl))
  6427. (add-text-properties
  6428. (or (match-end 1) (match-end 0)) (match-end 0)
  6429. (list 'face (org-get-todo-face (match-string 2 x)))
  6430. x)
  6431. (when (match-end 1)
  6432. (setq x (concat (substring x 0 (match-end 1))
  6433. (format org-agenda-todo-keyword-format
  6434. (match-string 2 x))
  6435. (org-add-props " " (text-properties-at 0 x))
  6436. (substring x (match-end 3)))))))
  6437. x)))
  6438. (defsubst org-cmp-values (a b property)
  6439. "Compare the numeric value of text PROPERTY for string A and B."
  6440. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6441. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6442. (cond ((> pa pb) +1)
  6443. ((< pa pb) -1))))
  6444. (defsubst org-cmp-effort (a b)
  6445. "Compare the effort values of string A and B."
  6446. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6447. (ea (or (get-text-property (1- (length a)) 'effort-minutes a) def))
  6448. (eb (or (get-text-property (1- (length b)) 'effort-minutes b) def)))
  6449. (cond ((> ea eb) +1)
  6450. ((< ea eb) -1))))
  6451. (defsubst org-cmp-category (a b)
  6452. "Compare the string values of categories of strings A and B."
  6453. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6454. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6455. (cond ((string-lessp ca cb) -1)
  6456. ((string-lessp cb ca) +1))))
  6457. (defsubst org-cmp-todo-state (a b)
  6458. "Compare the todo states of strings A and B."
  6459. (let* ((ma (or (get-text-property 1 'org-marker a)
  6460. (get-text-property 1 'org-hd-marker a)))
  6461. (mb (or (get-text-property 1 'org-marker b)
  6462. (get-text-property 1 'org-hd-marker b)))
  6463. (fa (and ma (marker-buffer ma)))
  6464. (fb (and mb (marker-buffer mb)))
  6465. (todo-kwds
  6466. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6467. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6468. (ta (or (get-text-property 1 'todo-state a) ""))
  6469. (tb (or (get-text-property 1 'todo-state b) ""))
  6470. (la (- (length (member ta todo-kwds))))
  6471. (lb (- (length (member tb todo-kwds))))
  6472. (donepa (member ta org-done-keywords-for-agenda))
  6473. (donepb (member tb org-done-keywords-for-agenda)))
  6474. (cond ((and donepa (not donepb)) -1)
  6475. ((and (not donepa) donepb) +1)
  6476. ((< la lb) -1)
  6477. ((< lb la) +1))))
  6478. (defsubst org-cmp-alpha (a b)
  6479. "Compare the headlines, alphabetically."
  6480. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6481. (plb (text-property-any 0 (length b) 'org-heading t b))
  6482. (ta (and pla (substring a pla)))
  6483. (tb (and plb (substring b plb))))
  6484. (when pla
  6485. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6486. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6487. (setq ta (substring ta (match-end 0))))
  6488. (setq ta (downcase ta)))
  6489. (when plb
  6490. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6491. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6492. (setq tb (substring tb (match-end 0))))
  6493. (setq tb (downcase tb)))
  6494. (cond ((not ta) +1)
  6495. ((not tb) -1)
  6496. ((string-lessp ta tb) -1)
  6497. ((string-lessp tb ta) +1))))
  6498. (defsubst org-cmp-tag (a b)
  6499. "Compare the string values of the first tags of A and B."
  6500. (let ((ta (car (last (get-text-property 1 'tags a))))
  6501. (tb (car (last (get-text-property 1 'tags b)))))
  6502. (cond ((not ta) +1)
  6503. ((not tb) -1)
  6504. ((string-lessp ta tb) -1)
  6505. ((string-lessp tb ta) +1))))
  6506. (defsubst org-cmp-time (a b)
  6507. "Compare the time-of-day values of strings A and B."
  6508. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6509. (ta (or (get-text-property 1 'time-of-day a) def))
  6510. (tb (or (get-text-property 1 'time-of-day b) def)))
  6511. (cond ((< ta tb) -1)
  6512. ((< tb ta) +1))))
  6513. (defsubst org-cmp-ts (a b type)
  6514. "Compare the timestamps values of entries A and B.
  6515. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6516. \"timestamp_ia\", compare within each of these type. When TYPE
  6517. is the empty string, compare all timestamps without respect of
  6518. their type."
  6519. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6520. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6521. (get-text-property 1 'ts-date a))
  6522. def))
  6523. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6524. (get-text-property 1 'ts-date b))
  6525. def)))
  6526. (cond ((< ta tb) -1)
  6527. ((< tb ta) +1))))
  6528. (defsubst org-cmp-habit-p (a b)
  6529. "Compare the todo states of strings A and B."
  6530. (let ((ha (get-text-property 1 'org-habit-p a))
  6531. (hb (get-text-property 1 'org-habit-p b)))
  6532. (cond ((and ha (not hb)) -1)
  6533. ((and (not ha) hb) +1))))
  6534. (defun org-entries-lessp (a b)
  6535. "Predicate for sorting agenda entries."
  6536. ;; The following variables will be used when the form is evaluated.
  6537. ;; So even though the compiler complains, keep them.
  6538. (let* ((ss org-agenda-sorting-strategy-selected)
  6539. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6540. (org-cmp-ts a b "")))
  6541. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6542. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6543. (org-cmp-ts a b "scheduled")))
  6544. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6545. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6546. (org-cmp-ts a b "deadline")))
  6547. (deadline-down (if deadline-up (- deadline-up) nil))
  6548. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6549. (org-cmp-ts a b "timestamp_ia")))
  6550. (tsia-down (if tsia-up (- tsia-up) nil))
  6551. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6552. (org-cmp-ts a b "timestamp")))
  6553. (ts-down (if ts-up (- ts-up) nil))
  6554. (time-up (and (org-em 'time-up 'time-down ss)
  6555. (org-cmp-time a b)))
  6556. (time-down (if time-up (- time-up) nil))
  6557. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6558. (org-cmp-values a b 'org-stats)))
  6559. (stats-down (if stats-up (- stats-up) nil))
  6560. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6561. (org-cmp-values a b 'priority)))
  6562. (priority-down (if priority-up (- priority-up) nil))
  6563. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6564. (org-cmp-effort a b)))
  6565. (effort-down (if effort-up (- effort-up) nil))
  6566. (category-up (and (or (org-em 'category-up 'category-down ss)
  6567. (memq 'category-keep ss))
  6568. (org-cmp-category a b)))
  6569. (category-down (if category-up (- category-up) nil))
  6570. (category-keep (if category-up +1 nil))
  6571. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6572. (org-cmp-tag a b)))
  6573. (tag-down (if tag-up (- tag-up) nil))
  6574. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6575. (org-cmp-todo-state a b)))
  6576. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6577. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6578. (org-cmp-habit-p a b)))
  6579. (habit-down (if habit-up (- habit-up) nil))
  6580. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6581. (org-cmp-alpha a b)))
  6582. (alpha-down (if alpha-up (- alpha-up) nil))
  6583. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6584. user-defined-up user-defined-down)
  6585. (if (and need-user-cmp org-agenda-cmp-user-defined
  6586. (functionp org-agenda-cmp-user-defined))
  6587. (setq user-defined-up
  6588. (funcall org-agenda-cmp-user-defined a b)
  6589. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6590. (cdr (assoc
  6591. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6592. '((-1 . t) (1 . nil) (nil . nil))))))
  6593. ;;; Agenda restriction lock
  6594. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6595. "Overlay to mark the headline to which agenda commands are restricted.")
  6596. (overlay-put org-agenda-restriction-lock-overlay
  6597. 'face 'org-agenda-restriction-lock)
  6598. (overlay-put org-agenda-restriction-lock-overlay
  6599. 'help-echo "Agendas are currently limited to this subtree.")
  6600. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6601. ;;;###autoload
  6602. (defun org-agenda-set-restriction-lock (&optional type)
  6603. "Set restriction lock for agenda, to current subtree or file.
  6604. Restriction will be the file if TYPE is `file', or if type is the
  6605. universal prefix '(4), or if the cursor is before the first headline
  6606. in the file. Otherwise, restriction will be to the current subtree."
  6607. (interactive "P")
  6608. (org-agenda-remove-restriction-lock 'noupdate)
  6609. (and (equal type '(4)) (setq type 'file))
  6610. (setq type (cond
  6611. (type type)
  6612. ((org-at-heading-p) 'subtree)
  6613. ((condition-case nil (org-back-to-heading t) (error nil))
  6614. 'subtree)
  6615. (t 'file)))
  6616. (if (eq type 'subtree)
  6617. (progn
  6618. (setq org-agenda-restrict (current-buffer))
  6619. (setq org-agenda-overriding-restriction 'subtree)
  6620. (put 'org-agenda-files 'org-restrict
  6621. (list (buffer-file-name (buffer-base-buffer))))
  6622. (org-back-to-heading t)
  6623. (move-overlay org-agenda-restriction-lock-overlay
  6624. (point)
  6625. (if org-agenda-restriction-lock-highlight-subtree
  6626. (save-excursion (org-end-of-subtree t t) (point))
  6627. (point-at-eol)))
  6628. (move-marker org-agenda-restrict-begin (point))
  6629. (move-marker org-agenda-restrict-end
  6630. (save-excursion (org-end-of-subtree t t)))
  6631. (message "Locking agenda restriction to subtree"))
  6632. (put 'org-agenda-files 'org-restrict
  6633. (list (buffer-file-name (buffer-base-buffer))))
  6634. (setq org-agenda-restrict nil)
  6635. (setq org-agenda-overriding-restriction 'file)
  6636. (move-marker org-agenda-restrict-begin nil)
  6637. (move-marker org-agenda-restrict-end nil)
  6638. (message "Locking agenda restriction to file"))
  6639. (setq current-prefix-arg nil)
  6640. (org-agenda-maybe-redo))
  6641. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6642. "Remove the agenda restriction lock."
  6643. (interactive "P")
  6644. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6645. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6646. (setq org-agenda-overriding-restriction nil)
  6647. (setq org-agenda-restrict nil)
  6648. (put 'org-agenda-files 'org-restrict nil)
  6649. (move-marker org-agenda-restrict-begin nil)
  6650. (move-marker org-agenda-restrict-end nil)
  6651. (setq current-prefix-arg nil)
  6652. (message "Agenda restriction lock removed")
  6653. (or noupdate (org-agenda-maybe-redo)))
  6654. (defun org-agenda-maybe-redo ()
  6655. "If there is any window showing the agenda view, update it."
  6656. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6657. (w0 (selected-window)))
  6658. (when w
  6659. (select-window w)
  6660. (org-agenda-redo)
  6661. (select-window w0)
  6662. (if org-agenda-overriding-restriction
  6663. (message "Agenda view shifted to new %s restriction"
  6664. org-agenda-overriding-restriction)
  6665. (message "Agenda restriction lock removed")))))
  6666. ;;; Agenda commands
  6667. (defun org-agenda-check-type (error &rest types)
  6668. "Check if agenda buffer is of allowed type.
  6669. If ERROR is non-nil, throw an error, otherwise just return nil.
  6670. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6671. (if (not org-agenda-type)
  6672. (error "No Org agenda currently displayed")
  6673. (if (memq org-agenda-type types)
  6674. t
  6675. (if error
  6676. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6677. nil))))
  6678. (defun org-agenda-Quit ()
  6679. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6680. Also restore the window configuration."
  6681. (interactive)
  6682. (if org-agenda-columns-active
  6683. (org-columns-quit)
  6684. (let ((buf (current-buffer)))
  6685. (if (eq org-agenda-window-setup 'other-frame)
  6686. (progn
  6687. (org-agenda-reset-markers)
  6688. (kill-buffer buf)
  6689. (org-columns-remove-overlays)
  6690. (setq org-agenda-archives-mode nil)
  6691. (delete-frame))
  6692. (and (not (eq org-agenda-window-setup 'current-window))
  6693. (not (one-window-p))
  6694. (delete-window))
  6695. (org-agenda-reset-markers)
  6696. (kill-buffer buf)
  6697. (org-columns-remove-overlays)
  6698. (setq org-agenda-archives-mode nil)))
  6699. (setq org-agenda-buffer nil)
  6700. ;; Maybe restore the pre-agenda window configuration.
  6701. (and org-agenda-restore-windows-after-quit
  6702. (not (eq org-agenda-window-setup 'other-frame))
  6703. org-agenda-pre-window-conf
  6704. (set-window-configuration org-agenda-pre-window-conf)
  6705. (setq org-agenda-pre-window-conf nil))))
  6706. (defun org-agenda-quit ()
  6707. "Exit the agenda and restore the window configuration.
  6708. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6709. (interactive)
  6710. (if (and (eq org-indirect-buffer-display 'other-window)
  6711. org-last-indirect-buffer)
  6712. (let ((org-last-indirect-window
  6713. (get-buffer-window org-last-indirect-buffer)))
  6714. (if org-last-indirect-window
  6715. (delete-window org-last-indirect-window))))
  6716. (if org-agenda-columns-active
  6717. (org-columns-quit)
  6718. (if org-agenda-sticky
  6719. (let ((buf (current-buffer)))
  6720. (if (eq org-agenda-window-setup 'other-frame)
  6721. (progn
  6722. (delete-frame))
  6723. (and (not (eq org-agenda-window-setup 'current-window))
  6724. (not (one-window-p))
  6725. (delete-window)))
  6726. (with-current-buffer buf
  6727. (bury-buffer)
  6728. ;; Maybe restore the pre-agenda window configuration.
  6729. (and org-agenda-restore-windows-after-quit
  6730. (not (eq org-agenda-window-setup 'other-frame))
  6731. org-agenda-pre-window-conf
  6732. (set-window-configuration org-agenda-pre-window-conf)
  6733. (setq org-agenda-pre-window-conf nil))))
  6734. (org-agenda-Quit))))
  6735. (defun org-agenda-exit ()
  6736. "Exit the agenda and restore the window configuration.
  6737. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6738. buffers visited directly by the user will not be touched."
  6739. (interactive)
  6740. (org-release-buffers org-agenda-new-buffers)
  6741. (setq org-agenda-new-buffers nil)
  6742. (org-agenda-Quit))
  6743. (defun org-agenda-kill-all-agenda-buffers ()
  6744. "Kill all buffers in `org-agenda-mode'.
  6745. This is used when toggling sticky agendas.
  6746. You can also explicitly invoke it with `C-c a C-k'."
  6747. (interactive)
  6748. (let (blist)
  6749. (dolist (buf (buffer-list))
  6750. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6751. (push buf blist)))
  6752. (mapc 'kill-buffer blist)))
  6753. (defun org-agenda-execute (arg)
  6754. "Execute another agenda command, keeping same window.
  6755. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6756. in the agenda."
  6757. (interactive "P")
  6758. (let ((org-agenda-window-setup 'current-window))
  6759. (org-agenda arg)))
  6760. (defun org-agenda-redo (&optional all)
  6761. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6762. (interactive "P")
  6763. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6764. (cpa (unless (eq all t) current-prefix-arg))
  6765. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6766. (org-agenda-sticky nil)
  6767. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6768. org-agenda-buffer-name))
  6769. (org-agenda-keep-modes t)
  6770. (tag-filter org-agenda-tag-filter)
  6771. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6772. (top-hl-filter org-agenda-top-headline-filter)
  6773. (cat-filter org-agenda-category-filter)
  6774. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6775. (re-filter org-agenda-regexp-filter)
  6776. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6777. (effort-filter org-agenda-effort-filter)
  6778. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6779. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6780. (cols org-agenda-columns-active)
  6781. (line (org-current-line))
  6782. (window-line (- line (org-current-line (window-start))))
  6783. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6784. (redo-cmd (get-text-property p 'org-redo-cmd))
  6785. (last-args (get-text-property p 'org-last-args))
  6786. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6787. (org-agenda-overriding-cmd-arguments
  6788. (unless (eq all t)
  6789. (cond ((listp last-args)
  6790. (cons (or cpa (car last-args)) (cdr last-args)))
  6791. ((stringp last-args)
  6792. last-args))))
  6793. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6794. (put 'org-agenda-tag-filter :preset-filter nil)
  6795. (put 'org-agenda-category-filter :preset-filter nil)
  6796. (put 'org-agenda-regexp-filter :preset-filter nil)
  6797. (put 'org-agenda-effort-filter :preset-filter nil)
  6798. (and cols (org-columns-quit))
  6799. (message "Rebuilding agenda buffer...")
  6800. (if series-redo-cmd
  6801. (eval series-redo-cmd)
  6802. (org-let lprops redo-cmd))
  6803. (setq org-agenda-undo-list nil
  6804. org-agenda-pending-undo-list nil
  6805. org-agenda-tag-filter tag-filter
  6806. org-agenda-category-filter cat-filter
  6807. org-agenda-regexp-filter re-filter
  6808. org-agenda-effort-filter effort-filter
  6809. org-agenda-top-headline-filter top-hl-filter)
  6810. (message "Rebuilding agenda buffer...done")
  6811. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6812. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6813. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6814. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6815. (let ((tag (or tag-filter tag-preset))
  6816. (cat (or cat-filter cat-preset))
  6817. (effort (or effort-filter effort-preset))
  6818. (re (or re-filter re-preset)))
  6819. (when tag (org-agenda-filter-apply tag 'tag))
  6820. (when cat (org-agenda-filter-apply cat 'category))
  6821. (when effort (org-agenda-filter-apply effort 'effort))
  6822. (when re (org-agenda-filter-apply re 'regexp)))
  6823. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6824. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6825. (org-goto-line line)
  6826. (recenter window-line)))
  6827. (defvar org-global-tags-completion-table nil)
  6828. (defvar org-agenda-filter-form nil)
  6829. (defvar org-agenda-filtered-by-category nil)
  6830. (defun org-agenda-filter-by-category (strip)
  6831. "Keep only those lines in the agenda buffer that have a specific category.
  6832. The category is that of the current line."
  6833. (interactive "P")
  6834. (if (and org-agenda-filtered-by-category
  6835. org-agenda-category-filter)
  6836. (org-agenda-filter-show-all-cat)
  6837. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6838. (cond
  6839. ((and cat strip)
  6840. (org-agenda-filter-apply
  6841. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6842. ((and cat)
  6843. (org-agenda-filter-apply
  6844. (setq org-agenda-category-filter
  6845. (list (concat "+" cat))) 'category))
  6846. (t (error "No category at point"))))))
  6847. (defun org-find-top-headline (&optional pos)
  6848. "Find the topmost parent headline and return it."
  6849. (save-excursion
  6850. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6851. (if pos (goto-char pos))
  6852. ;; Skip up to the topmost parent
  6853. (while (ignore-errors (outline-up-heading 1) t))
  6854. (ignore-errors
  6855. (nth 4 (org-heading-components))))))
  6856. (defvar org-agenda-filtered-by-top-headline nil)
  6857. (defun org-agenda-filter-by-top-headline (strip)
  6858. "Keep only those lines that are descendants from the same top headline.
  6859. The top headline is that of the current line."
  6860. (interactive "P")
  6861. (if org-agenda-filtered-by-top-headline
  6862. (progn
  6863. (setq org-agenda-filtered-by-top-headline nil
  6864. org-agenda-top-headline-filter nil)
  6865. (org-agenda-filter-show-all-top-filter))
  6866. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6867. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6868. (error "No top-level headline at point")))))
  6869. (defvar org-agenda-regexp-filter nil)
  6870. (defun org-agenda-filter-by-regexp (strip)
  6871. "Filter agenda entries by a regular expression.
  6872. Regexp filters are cumulative.
  6873. With no prefix argument, keep entries matching the regexp.
  6874. With one prefix argument, filter out entries matching the regexp.
  6875. With two prefix arguments, remove the regexp filters."
  6876. (interactive "P")
  6877. (if (not (equal strip '(16)))
  6878. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6879. (read-from-minibuffer
  6880. (if (equal strip '(4))
  6881. "Filter out entries matching regexp: "
  6882. "Narrow to entries matching regexp: ")))))
  6883. (push flt org-agenda-regexp-filter)
  6884. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6885. (org-agenda-filter-show-all-re)
  6886. (message "Regexp filter removed")))
  6887. (defvar org-agenda-effort-filter nil)
  6888. (defun org-agenda-filter-by-effort (strip)
  6889. "Filter agenda entries by effort.
  6890. With no prefix argument, keep entries matching the effort condition.
  6891. With one prefix argument, filter out entries matching the condition.
  6892. With two prefix arguments, remove the effort filters."
  6893. (interactive "P")
  6894. (cond ((member strip '(nil 4))
  6895. (let ((efforts (org-split-string
  6896. (or (cdr (assoc (concat org-effort-property "_ALL")
  6897. org-global-properties))
  6898. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6899. "")))
  6900. (eff -1)
  6901. effort-prompt op)
  6902. (while (not (member op '(?< ?> ?=)))
  6903. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6904. (loop for i from 0 to 9 do
  6905. (setq effort-prompt
  6906. (concat
  6907. effort-prompt " ["
  6908. (if (= i 9) "0" (int-to-string (1+ i)))
  6909. "]" (nth i efforts))))
  6910. (message "Effort %s%s" (char-to-string op) effort-prompt)
  6911. (while (or (< eff 0) (> eff 9))
  6912. (setq eff (string-to-number (char-to-string (read-char-exclusive)))))
  6913. (setq org-agenda-effort-filter
  6914. (list (concat (if strip "-" "+")
  6915. (char-to-string op) (nth (1- eff) efforts))))
  6916. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6917. (t (org-agenda-filter-show-all-effort)
  6918. (message "Effort filter removed"))))
  6919. (defun org-agenda-filter-remove-all ()
  6920. "Remove all filters from the current agenda buffer."
  6921. (interactive)
  6922. (when org-agenda-tag-filter
  6923. (org-agenda-filter-show-all-tag))
  6924. (when org-agenda-category-filter
  6925. (org-agenda-filter-show-all-cat))
  6926. (when org-agenda-regexp-filter
  6927. (org-agenda-filter-show-all-re))
  6928. (when org-agenda-top-headline-filter
  6929. (org-agenda-filter-show-all-top-filter))
  6930. (when org-agenda-effort-filter
  6931. (org-agenda-filter-show-all-effort))
  6932. (org-agenda-finalize))
  6933. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6934. "Keep only those lines in the agenda buffer that have a specific tag.
  6935. The tag is selected with its fast selection letter, as configured.
  6936. With prefix argument STRIP, remove all lines that do have the tag.
  6937. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6938. used to narrow the search - the interactive user can also press `-' or `+'
  6939. to switch to narrowing."
  6940. (interactive "P")
  6941. (let* ((alist org-tag-alist-for-agenda)
  6942. (tag-chars (mapconcat
  6943. (lambda (x) (if (and (not (symbolp (car x)))
  6944. (cdr x))
  6945. (char-to-string (cdr x))
  6946. ""))
  6947. alist ""))
  6948. (inhibit-read-only t)
  6949. (current org-agenda-tag-filter)
  6950. a n tag)
  6951. (unless char
  6952. (message
  6953. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow"
  6954. (if narrow "Narrow" "Filter") tag-chars
  6955. (if org-agenda-auto-exclude-function "[RET], " ""))
  6956. (setq char (read-char-exclusive)))
  6957. (when (member char '(?+ ?-))
  6958. ;; Narrowing down
  6959. (cond ((equal char ?-) (setq strip t narrow t))
  6960. ((equal char ?+) (setq strip nil narrow t)))
  6961. (message
  6962. "Narrow by tag [%s ], [TAB], [/]:off" tag-chars)
  6963. (setq char (read-char-exclusive)))
  6964. (when (equal char ?\t)
  6965. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6966. (org-set-local 'org-global-tags-completion-table
  6967. (org-global-tags-completion-table)))
  6968. (let ((completion-ignore-case t))
  6969. (setq tag (org-icompleting-read
  6970. "Tag: " org-global-tags-completion-table))))
  6971. (cond
  6972. ((equal char ?\r)
  6973. (org-agenda-filter-show-all-tag)
  6974. (when org-agenda-auto-exclude-function
  6975. (setq org-agenda-tag-filter nil)
  6976. (dolist (tag (org-agenda-get-represented-tags))
  6977. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6978. (if modifier
  6979. (push modifier org-agenda-tag-filter))))
  6980. (if (not (null org-agenda-tag-filter))
  6981. (org-agenda-filter-apply org-agenda-tag-filter 'tag))))
  6982. ((equal char ?/)
  6983. (org-agenda-filter-show-all-tag)
  6984. (when (get 'org-agenda-tag-filter :preset-filter)
  6985. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6986. ((equal char ?. )
  6987. (setq org-agenda-tag-filter
  6988. (mapcar (lambda(tag) (concat "+" tag))
  6989. (org-get-at-bol 'tags)))
  6990. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6991. ((or (equal char ?\ )
  6992. (setq a (rassoc char alist))
  6993. (and tag (setq a (cons tag nil))))
  6994. (org-agenda-filter-show-all-tag)
  6995. (setq tag (car a))
  6996. (setq org-agenda-tag-filter
  6997. (cons (concat (if strip "-" "+") tag)
  6998. (if narrow current nil)))
  6999. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  7000. (t (error "Invalid tag selection character %c" char)))))
  7001. (defun org-agenda-get-represented-tags ()
  7002. "Get a list of all tags currently represented in the agenda."
  7003. (let (p tags)
  7004. (save-excursion
  7005. (goto-char (point-min))
  7006. (while (setq p (next-single-property-change (point) 'tags))
  7007. (goto-char p)
  7008. (mapc (lambda (x) (add-to-list 'tags x))
  7009. (get-text-property (point) 'tags))))
  7010. tags))
  7011. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  7012. "Refine the current filter. See `org-agenda-filter-by-tag'."
  7013. (interactive "P")
  7014. (org-agenda-filter-by-tag strip char 'refine))
  7015. (defun org-agenda-filter-make-matcher (filter type)
  7016. "Create the form that tests a line for agenda filter."
  7017. (let (f f1)
  7018. (cond
  7019. ;; Tag filter
  7020. ((eq type 'tag)
  7021. (setq filter
  7022. (delete-dups
  7023. (append (get 'org-agenda-tag-filter :preset-filter)
  7024. filter)))
  7025. (dolist (x filter)
  7026. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  7027. (ffunc
  7028. (lambda (nf0 nf01 fltr notgroup op)
  7029. (dolist (x fltr)
  7030. (if (member x '("-" "+"))
  7031. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  7032. (setq nf01 (list 'member (downcase (substring x 1))
  7033. 'tags))
  7034. (when (equal (string-to-char x) ?-)
  7035. (setq nf01 (list 'not nf01))
  7036. (when (not notgroup) (setq op 'and))))
  7037. (push nf01 nf0))
  7038. (if notgroup
  7039. (push (cons 'and nf0) f)
  7040. (push (cons (or op 'or) nf0) f)))))
  7041. (cond ((equal filter '("+"))
  7042. (setq f (list (list 'not 'tags))))
  7043. ((equal nfilter filter)
  7044. (funcall ffunc f1 f filter t nil))
  7045. (t (funcall ffunc nf1 nf nfilter nil nil))))))
  7046. ;; Category filter
  7047. ((eq type 'category)
  7048. (setq filter
  7049. (delete-dups
  7050. (append (get 'org-agenda-category-filter :preset-filter)
  7051. filter)))
  7052. (dolist (x filter)
  7053. (if (equal "-" (substring x 0 1))
  7054. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7055. (setq f1 (list 'equal (substring x 1) 'cat)))
  7056. (push f1 f)))
  7057. ;; Regexp filter
  7058. ((eq type 'regexp)
  7059. (setq filter
  7060. (delete-dups
  7061. (append (get 'org-agenda-regexp-filter :preset-filter)
  7062. filter)))
  7063. (dolist (x filter)
  7064. (if (equal "-" (substring x 0 1))
  7065. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7066. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7067. (push f1 f)))
  7068. ;; Effort filter
  7069. ((eq type 'effort)
  7070. (setq filter
  7071. (delete-dups
  7072. (append (get 'org-agenda-effort-filter :preset-filter)
  7073. filter)))
  7074. (dolist (x filter)
  7075. (push (org-agenda-filter-effort-form x) f))))
  7076. (cons 'and (nreverse f))))
  7077. (defun org-agenda-filter-effort-form (e)
  7078. "Return the form to compare the effort of the current line with what E says.
  7079. E looks like \"+<2:25\"."
  7080. (let (op)
  7081. (setq e (substring e 1))
  7082. (setq op (string-to-char e) e (substring e 1))
  7083. (setq op (cond ((equal op ?<) '<=)
  7084. ((equal op ?>) '>=)
  7085. ((equal op ??) op)
  7086. (t '=)))
  7087. (list 'org-agenda-compare-effort (list 'quote op)
  7088. (org-duration-string-to-minutes e))))
  7089. (defun org-agenda-compare-effort (op value)
  7090. "Compare the effort of the current line with VALUE, using OP.
  7091. If the line does not have an effort defined, return nil."
  7092. (let ((eff (org-get-at-eol 'effort-minutes 1)))
  7093. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 -1))
  7094. value)))
  7095. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7096. "Expand group tags in FILTER for the agenda.
  7097. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7098. (if org-group-tags
  7099. (let ((case-fold-search t) rtn)
  7100. (mapc
  7101. (lambda (f)
  7102. (let (f0 dir)
  7103. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7104. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7105. (setq dir (if no-operator "" "+") f0 f))
  7106. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7107. (org-tags-expand f0 t t))
  7108. rtn))))
  7109. filter)
  7110. (reverse rtn))
  7111. filter))
  7112. (defun org-agenda-filter-apply (filter type)
  7113. "Set FILTER as the new agenda filter and apply it."
  7114. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7115. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7116. (let (tags cat txt)
  7117. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type))
  7118. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7119. ;; category is used as the filter:
  7120. (setq org-agenda-filtered-by-category
  7121. (and (eq type 'category)
  7122. (not (equal (substring (car filter) 0 1) "-"))))
  7123. (org-agenda-set-mode-name)
  7124. (save-excursion
  7125. (goto-char (point-min))
  7126. (while (not (eobp))
  7127. (if (org-get-at-bol 'org-marker)
  7128. (progn
  7129. (setq tags ; used in eval
  7130. (apply 'append
  7131. (mapcar (lambda (f)
  7132. (org-agenda-filter-expand-tags (list f) t))
  7133. (org-get-at-bol 'tags)))
  7134. cat (org-get-at-eol 'org-category 1)
  7135. txt (org-get-at-eol 'txt 1))
  7136. (if (not (eval org-agenda-filter-form))
  7137. (org-agenda-filter-hide-line type))
  7138. (beginning-of-line 2))
  7139. (beginning-of-line 2))))
  7140. (if (get-char-property (point) 'invisible)
  7141. (ignore-errors (org-agenda-previous-line)))))
  7142. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7143. "Filter by top headline HL."
  7144. (org-agenda-set-mode-name)
  7145. (save-excursion
  7146. (goto-char (point-min))
  7147. (while (not (eobp))
  7148. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7149. (tophl (and pos (org-find-top-headline pos))))
  7150. (if (and tophl (funcall (if negative 'identity 'not)
  7151. (string= hl tophl)))
  7152. (org-agenda-filter-hide-line 'top-headline)))
  7153. (beginning-of-line 2)))
  7154. (if (get-char-property (point) 'invisible)
  7155. (org-agenda-previous-line))
  7156. (setq org-agenda-top-headline-filter hl
  7157. org-agenda-filtered-by-top-headline t))
  7158. (defun org-agenda-filter-hide-line (type)
  7159. "Hide lines with TYPE in the agenda buffer."
  7160. (let* ((b (max (point-min) (1- (point-at-bol))))
  7161. (e (point-at-eol)))
  7162. (let ((inhibit-read-only t))
  7163. (add-text-properties
  7164. b e `(invisible org-filtered org-filter-type ,type)))))
  7165. (defun org-agenda-remove-filter (type)
  7166. (interactive)
  7167. "Remove filter of type TYPE from the agenda buffer."
  7168. (save-excursion
  7169. (goto-char (point-min))
  7170. (let ((inhibit-read-only t) pos)
  7171. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7172. (goto-char pos)
  7173. (remove-text-properties
  7174. (point) (next-single-property-change (point) 'org-filter-type)
  7175. `(invisible org-filtered org-filter-type ,type))))
  7176. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7177. (setq org-agenda-filter-form nil)
  7178. (org-agenda-set-mode-name)
  7179. (org-agenda-finalize)))
  7180. (defun org-agenda-filter-show-all-tag nil
  7181. (org-agenda-remove-filter 'tag))
  7182. (defun org-agenda-filter-show-all-re nil
  7183. (org-agenda-remove-filter 'regexp))
  7184. (defun org-agenda-filter-show-all-effort nil
  7185. (org-agenda-remove-filter 'effort))
  7186. (defun org-agenda-filter-show-all-cat nil
  7187. (org-agenda-remove-filter 'category))
  7188. (defun org-agenda-filter-show-all-top-filter nil
  7189. (org-agenda-remove-filter 'top-headline))
  7190. (defun org-agenda-manipulate-query-add ()
  7191. "Manipulate the query by adding a search term with positive selection.
  7192. Positive selection means the term must be matched for selection of an entry."
  7193. (interactive)
  7194. (org-agenda-manipulate-query ?\[))
  7195. (defun org-agenda-manipulate-query-subtract ()
  7196. "Manipulate the query by adding a search term with negative selection.
  7197. Negative selection means term must not be matched for selection of an entry."
  7198. (interactive)
  7199. (org-agenda-manipulate-query ?\]))
  7200. (defun org-agenda-manipulate-query-add-re ()
  7201. "Manipulate the query by adding a search regexp with positive selection.
  7202. Positive selection means the regexp must match for selection of an entry."
  7203. (interactive)
  7204. (org-agenda-manipulate-query ?\{))
  7205. (defun org-agenda-manipulate-query-subtract-re ()
  7206. "Manipulate the query by adding a search regexp with negative selection.
  7207. Negative selection means regexp must not match for selection of an entry."
  7208. (interactive)
  7209. (org-agenda-manipulate-query ?\}))
  7210. (defun org-agenda-manipulate-query (char)
  7211. (cond
  7212. ((memq org-agenda-type '(timeline agenda))
  7213. (let ((org-agenda-include-inactive-timestamps t))
  7214. (org-agenda-redo))
  7215. (message "Display now includes inactive timestamps as well"))
  7216. ((eq org-agenda-type 'search)
  7217. (org-add-to-string
  7218. 'org-agenda-query-string
  7219. (if org-agenda-last-search-view-search-was-boolean
  7220. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7221. (?\{ . " +{}") (?\} . " -{}"))))
  7222. " "))
  7223. (setq org-agenda-redo-command
  7224. (list 'org-search-view
  7225. (car (get-text-property (min (1- (point-max)) (point))
  7226. 'org-last-args))
  7227. org-agenda-query-string
  7228. (+ (length org-agenda-query-string)
  7229. (if (member char '(?\{ ?\})) 0 1))))
  7230. (set-register org-agenda-query-register org-agenda-query-string)
  7231. (let ((org-agenda-overriding-arguments
  7232. (cdr org-agenda-redo-command)))
  7233. (org-agenda-redo)))
  7234. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7235. org-agenda-type))))
  7236. (defun org-add-to-string (var string)
  7237. (set var (concat (symbol-value var) string)))
  7238. (defun org-agenda-goto-date (span)
  7239. "Jump to DATE in agenda."
  7240. (interactive "P")
  7241. (let* ((org-read-date-prefer-future
  7242. (eval org-agenda-jump-prefer-future))
  7243. (date (org-read-date))
  7244. (day (time-to-days (org-time-string-to-time date)))
  7245. (org-agenda-sticky-orig org-agenda-sticky)
  7246. (org-agenda-buffer-tmp-name (buffer-name))
  7247. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7248. (0-arg (or current-prefix-arg (car args)))
  7249. (2-arg (nth 2 args))
  7250. (with-hour-p (nth 4 org-agenda-redo-command))
  7251. (newcmd (list 'org-agenda-list 0-arg date
  7252. (org-agenda-span-to-ndays
  7253. 2-arg (org-time-string-to-absolute date))
  7254. with-hour-p))
  7255. (newargs (cdr newcmd))
  7256. (inhibit-read-only t)
  7257. org-agenda-sticky)
  7258. (if (not (org-agenda-check-type t 'agenda))
  7259. (error "Not available in non-agenda views")
  7260. (add-text-properties (point-min) (point-max)
  7261. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7262. (org-agenda-redo)
  7263. (goto-char (point-min))
  7264. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7265. (save-excursion (move-beginning-of-line 2) (eobp))))
  7266. (move-beginning-of-line 2))
  7267. (setq org-agenda-sticky org-agenda-sticky-orig
  7268. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7269. (defun org-agenda-goto-today ()
  7270. "Go to today."
  7271. (interactive)
  7272. (org-agenda-check-type t 'timeline 'agenda)
  7273. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7274. (curspan (nth 2 args))
  7275. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7276. (cond
  7277. (tdpos (goto-char tdpos))
  7278. ((eq org-agenda-type 'agenda)
  7279. (let* ((sd (org-agenda-compute-starting-span
  7280. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7281. (org-agenda-overriding-arguments args))
  7282. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7283. (org-agenda-redo)
  7284. (org-agenda-find-same-or-today-or-agenda)))
  7285. (t (error "Cannot find today")))))
  7286. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7287. (goto-char
  7288. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7289. (text-property-any (point-min) (point-max) 'org-today t)
  7290. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7291. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7292. (org-agenda-backward-block))
  7293. (point-min))))
  7294. (defun org-agenda-backward-block ()
  7295. "Move backward by one agenda block."
  7296. (interactive)
  7297. (org-agenda-forward-block 'backward))
  7298. (defun org-agenda-forward-block (&optional backward)
  7299. "Move forward by one agenda block.
  7300. When optional argument BACKWARD is set, go backward"
  7301. (interactive)
  7302. (cond ((not (derived-mode-p 'org-agenda-mode))
  7303. (user-error
  7304. "Cannot execute this command outside of org-agenda-mode buffers"))
  7305. ((looking-at (if backward "\\`" "\\'"))
  7306. (message "Already at the %s block" (if backward "first" "last")))
  7307. (t (let ((pos (prog1 (point)
  7308. (ignore-errors (if backward (backward-char 1)
  7309. (move-end-of-line 1)))))
  7310. (f (if backward
  7311. 'previous-single-property-change
  7312. 'next-single-property-change))
  7313. moved dest)
  7314. (while (and (setq dest (funcall
  7315. f (point) 'org-agenda-structural-header))
  7316. (not (get-text-property
  7317. (point) 'org-agenda-structural-header)))
  7318. (setq moved t)
  7319. (goto-char dest))
  7320. (if moved (move-beginning-of-line 1)
  7321. (goto-char (if backward (point-min) (point-max)))
  7322. (move-beginning-of-line 1)
  7323. (message "No %s block" (if backward "previous" "further")))))))
  7324. (defun org-agenda-later (arg)
  7325. "Go forward in time by the current span.
  7326. With prefix ARG, go forward that many times the current span."
  7327. (interactive "p")
  7328. (org-agenda-check-type t 'agenda)
  7329. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7330. (span (or (nth 2 args) org-agenda-current-span))
  7331. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7332. (greg (calendar-gregorian-from-absolute sd))
  7333. (cnt (org-get-at-bol 'org-day-cnt))
  7334. greg2)
  7335. (cond
  7336. ((numberp span)
  7337. (setq sd (+ (* span arg) sd)))
  7338. ((eq span 'day)
  7339. (setq sd (+ arg sd)))
  7340. ((eq span 'week)
  7341. (setq sd (+ (* 7 arg) sd)))
  7342. ((eq span 'fortnight)
  7343. (setq sd (+ (* 14 arg) sd)))
  7344. ((eq span 'month)
  7345. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7346. sd (calendar-absolute-from-gregorian greg2))
  7347. (setcar greg2 (1+ (car greg2))))
  7348. ((eq span 'year)
  7349. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7350. sd (calendar-absolute-from-gregorian greg2))
  7351. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7352. (t
  7353. (setq sd (+ (* span arg) sd))))
  7354. (let ((org-agenda-overriding-cmd
  7355. ;; `cmd' may have been set by `org-agenda-run-series' which
  7356. ;; uses `org-agenda-overriding-cmd' to decide whether
  7357. ;; overriding is allowed for `cmd'
  7358. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7359. (org-agenda-overriding-arguments
  7360. (list (car args) sd span)))
  7361. (org-agenda-redo)
  7362. (org-agenda-find-same-or-today-or-agenda cnt))))
  7363. (defun org-agenda-earlier (arg)
  7364. "Go backward in time by the current span.
  7365. With prefix ARG, go backward that many times the current span."
  7366. (interactive "p")
  7367. (org-agenda-later (- arg)))
  7368. (defun org-agenda-view-mode-dispatch ()
  7369. "Call one of the view mode commands."
  7370. (interactive)
  7371. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7372. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7373. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7374. (let ((a (read-char-exclusive)))
  7375. (case a
  7376. (?\ (call-interactively 'org-agenda-reset-view))
  7377. (?d (call-interactively 'org-agenda-day-view))
  7378. (?w (call-interactively 'org-agenda-week-view))
  7379. (?t (call-interactively 'org-agenda-fortnight-view))
  7380. (?m (call-interactively 'org-agenda-month-view))
  7381. (?y (call-interactively 'org-agenda-year-view))
  7382. (?l (call-interactively 'org-agenda-log-mode))
  7383. (?L (org-agenda-log-mode '(4)))
  7384. (?c (org-agenda-log-mode 'clockcheck))
  7385. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7386. (?a (call-interactively 'org-agenda-archives-mode))
  7387. (?A (org-agenda-archives-mode 'files))
  7388. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7389. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7390. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7391. (?D (call-interactively 'org-agenda-toggle-diary))
  7392. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7393. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7394. (org-agenda-check-type t 'timeline 'agenda)
  7395. (org-agenda-redo))
  7396. (message "Display now includes inactive timestamps as well"))
  7397. (?q (message "Abort"))
  7398. (otherwise (error "Invalid key" )))))
  7399. (defun org-agenda-reset-view ()
  7400. "Switch to default view for agenda."
  7401. (interactive)
  7402. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7403. (defun org-agenda-day-view (&optional day-of-month)
  7404. "Switch to daily view for agenda.
  7405. With argument DAY-OF-MONTH, switch to that day of the month."
  7406. (interactive "P")
  7407. (org-agenda-change-time-span 'day day-of-month))
  7408. (defun org-agenda-week-view (&optional iso-week)
  7409. "Switch to daily view for agenda.
  7410. With argument ISO-WEEK, switch to the corresponding ISO week.
  7411. If ISO-WEEK has more then 2 digits, only the last two encode the
  7412. week. Any digits before this encode a year. So 200712 means
  7413. week 12 of year 2007. Years in the range 1938-2037 can also be
  7414. written as 2-digit years."
  7415. (interactive "P")
  7416. (org-agenda-change-time-span 'week iso-week))
  7417. (defun org-agenda-fortnight-view (&optional iso-week)
  7418. "Switch to daily view for agenda.
  7419. With argument ISO-WEEK, switch to the corresponding ISO week.
  7420. If ISO-WEEK has more then 2 digits, only the last two encode the
  7421. week. Any digits before this encode a year. So 200712 means
  7422. week 12 of year 2007. Years in the range 1938-2037 can also be
  7423. written as 2-digit years."
  7424. (interactive "P")
  7425. (org-agenda-change-time-span 'fortnight iso-week))
  7426. (defun org-agenda-month-view (&optional month)
  7427. "Switch to monthly view for agenda.
  7428. With argument MONTH, switch to that month."
  7429. (interactive "P")
  7430. (org-agenda-change-time-span 'month month))
  7431. (defun org-agenda-year-view (&optional year)
  7432. "Switch to yearly view for agenda.
  7433. With argument YEAR, switch to that year.
  7434. If MONTH has more then 2 digits, only the last two encode the
  7435. month. Any digits before this encode a year. So 200712 means
  7436. December year 2007. Years in the range 1938-2037 can also be
  7437. written as 2-digit years."
  7438. (interactive "P")
  7439. (when year
  7440. (setq year (org-small-year-to-year year)))
  7441. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7442. (org-agenda-change-time-span 'year year)
  7443. (error "Abort")))
  7444. (defun org-agenda-change-time-span (span &optional n)
  7445. "Change the agenda view to SPAN.
  7446. SPAN may be `day', `week', `fortnight', `month', `year'."
  7447. (org-agenda-check-type t 'agenda)
  7448. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7449. (curspan (nth 2 args)))
  7450. (if (and (not n) (equal curspan span))
  7451. (error "Viewing span is already \"%s\"" span))
  7452. (let* ((sd (or (org-get-at-bol 'day)
  7453. (nth 1 args)
  7454. org-starting-day))
  7455. (sd (org-agenda-compute-starting-span sd span n))
  7456. (org-agenda-overriding-cmd
  7457. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7458. (org-agenda-overriding-arguments
  7459. (list (car args) sd span)))
  7460. (org-agenda-redo)
  7461. (org-agenda-find-same-or-today-or-agenda))
  7462. (org-agenda-set-mode-name)
  7463. (message "Switched to %s view" span)))
  7464. (defun org-agenda-compute-starting-span (sd span &optional n)
  7465. "Compute starting date for agenda.
  7466. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7467. is a cons cell with the starting date and the number of days,
  7468. so that the date SD will be in that range."
  7469. (let* ((greg (calendar-gregorian-from-absolute sd))
  7470. (dg (nth 1 greg))
  7471. (mg (car greg))
  7472. (yg (nth 2 greg)))
  7473. (cond
  7474. ((eq span 'day)
  7475. (when n
  7476. (setq sd (+ (calendar-absolute-from-gregorian
  7477. (list mg 1 yg))
  7478. n -1))))
  7479. ((or (eq span 'week) (eq span 'fortnight))
  7480. (let* ((nt (calendar-day-of-week
  7481. (calendar-gregorian-from-absolute sd)))
  7482. (d (if org-agenda-start-on-weekday
  7483. (- nt org-agenda-start-on-weekday)
  7484. 0))
  7485. y1)
  7486. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7487. (when n
  7488. (require 'cal-iso)
  7489. (when (> n 99)
  7490. (setq y1 (org-small-year-to-year (/ n 100))
  7491. n (mod n 100)))
  7492. (setq sd
  7493. (calendar-absolute-from-iso
  7494. (list n 1
  7495. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7496. ((eq span 'month)
  7497. (let (y1)
  7498. (when (and n (> n 99))
  7499. (setq y1 (org-small-year-to-year (/ n 100))
  7500. n (mod n 100)))
  7501. (setq sd (calendar-absolute-from-gregorian
  7502. (list (or n mg) 1 (or y1 yg))))))
  7503. ((eq span 'year)
  7504. (setq sd (calendar-absolute-from-gregorian
  7505. (list 1 1 (or n yg))))))
  7506. sd))
  7507. (defun org-agenda-next-date-line (&optional arg)
  7508. "Jump to the next line indicating a date in agenda buffer."
  7509. (interactive "p")
  7510. (org-agenda-check-type t 'agenda 'timeline)
  7511. (beginning-of-line 1)
  7512. ;; This does not work if user makes date format that starts with a blank
  7513. (if (looking-at "^\\S-") (forward-char 1))
  7514. (if (not (re-search-forward "^\\S-" nil t arg))
  7515. (progn
  7516. (backward-char 1)
  7517. (error "No next date after this line in this buffer")))
  7518. (goto-char (match-beginning 0)))
  7519. (defun org-agenda-previous-date-line (&optional arg)
  7520. "Jump to the previous line indicating a date in agenda buffer."
  7521. (interactive "p")
  7522. (org-agenda-check-type t 'agenda 'timeline)
  7523. (beginning-of-line 1)
  7524. (if (not (re-search-backward "^\\S-" nil t arg))
  7525. (error "No previous date before this line in this buffer")))
  7526. ;; Initialize the highlight
  7527. (defvar org-hl (make-overlay 1 1))
  7528. (overlay-put org-hl 'face 'highlight)
  7529. (defun org-highlight (begin end &optional buffer)
  7530. "Highlight a region with overlay."
  7531. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7532. (defun org-unhighlight ()
  7533. "Detach overlay INDEX."
  7534. (org-detach-overlay org-hl))
  7535. (defun org-unhighlight-once ()
  7536. "Remove the highlight from its position, and this function from the hook."
  7537. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7538. (org-unhighlight))
  7539. (defvar org-agenda-pre-follow-window-conf nil)
  7540. (defun org-agenda-follow-mode ()
  7541. "Toggle follow mode in an agenda buffer."
  7542. (interactive)
  7543. (unless org-agenda-follow-mode
  7544. (setq org-agenda-pre-follow-window-conf
  7545. (current-window-configuration)))
  7546. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7547. (unless org-agenda-follow-mode
  7548. (set-window-configuration org-agenda-pre-follow-window-conf))
  7549. (org-agenda-set-mode-name)
  7550. (org-agenda-do-context-action)
  7551. (message "Follow mode is %s"
  7552. (if org-agenda-follow-mode "on" "off")))
  7553. (defun org-agenda-entry-text-mode (&optional arg)
  7554. "Toggle entry text mode in an agenda buffer."
  7555. (interactive "P")
  7556. (if (or org-agenda-tag-filter
  7557. org-agenda-category-filter
  7558. org-agenda-regexp-filter
  7559. org-agenda-top-headline-filter)
  7560. (user-error "Can't show entry text in filtered views")
  7561. (setq org-agenda-entry-text-mode (or (integerp arg)
  7562. (not org-agenda-entry-text-mode)))
  7563. (org-agenda-entry-text-hide)
  7564. (and org-agenda-entry-text-mode
  7565. (let ((org-agenda-entry-text-maxlines
  7566. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7567. (org-agenda-entry-text-show)))
  7568. (org-agenda-set-mode-name)
  7569. (message "Entry text mode is %s%s"
  7570. (if org-agenda-entry-text-mode "on" "off")
  7571. (if (not org-agenda-entry-text-mode) ""
  7572. (format " (maximum number of lines is %d)"
  7573. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7574. (defun org-agenda-clockreport-mode ()
  7575. "Toggle clocktable mode in an agenda buffer."
  7576. (interactive)
  7577. (org-agenda-check-type t 'agenda)
  7578. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7579. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7580. (org-agenda-set-mode-name)
  7581. (org-agenda-redo)
  7582. (message "Clocktable mode is %s"
  7583. (if org-agenda-clockreport-mode "on" "off")))
  7584. (defun org-agenda-log-mode (&optional special)
  7585. "Toggle log mode in an agenda buffer.
  7586. With argument SPECIAL, show all possible log items, not only the ones
  7587. configured in `org-agenda-log-mode-items'.
  7588. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7589. (interactive "P")
  7590. (org-agenda-check-type t 'agenda 'timeline)
  7591. (setq org-agenda-show-log
  7592. (cond
  7593. ((equal special '(16)) 'only)
  7594. ((eq special 'clockcheck)
  7595. (if (eq org-agenda-show-log 'clockcheck)
  7596. nil 'clockcheck))
  7597. (special '(closed clock state))
  7598. (t (not org-agenda-show-log))))
  7599. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7600. (org-agenda-set-mode-name)
  7601. (org-agenda-redo)
  7602. (message "Log mode is %s"
  7603. (if org-agenda-show-log "on" "off")))
  7604. (defun org-agenda-archives-mode (&optional with-files)
  7605. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7606. When called with a prefix argument, include all archive files as well."
  7607. (interactive "P")
  7608. (setq org-agenda-archives-mode
  7609. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7610. (org-agenda-set-mode-name)
  7611. (org-agenda-redo)
  7612. (message
  7613. "%s"
  7614. (cond
  7615. ((eq org-agenda-archives-mode nil)
  7616. "No archives are included")
  7617. ((eq org-agenda-archives-mode 'trees)
  7618. (format "Trees with :%s: tag are included" org-archive-tag))
  7619. ((eq org-agenda-archives-mode t)
  7620. (format "Trees with :%s: tag and all active archive files are included"
  7621. org-archive-tag)))))
  7622. (defun org-agenda-toggle-diary ()
  7623. "Toggle diary inclusion in an agenda buffer."
  7624. (interactive)
  7625. (org-agenda-check-type t 'agenda)
  7626. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7627. (org-agenda-redo)
  7628. (org-agenda-set-mode-name)
  7629. (message "Diary inclusion turned %s"
  7630. (if org-agenda-include-diary "on" "off")))
  7631. (defun org-agenda-toggle-deadlines ()
  7632. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7633. (interactive)
  7634. (org-agenda-check-type t 'agenda)
  7635. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7636. (org-agenda-redo)
  7637. (org-agenda-set-mode-name)
  7638. (message "Deadlines inclusion turned %s"
  7639. (if org-agenda-include-deadlines "on" "off")))
  7640. (defun org-agenda-toggle-time-grid ()
  7641. "Toggle time grid in an agenda buffer."
  7642. (interactive)
  7643. (org-agenda-check-type t 'agenda)
  7644. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7645. (org-agenda-redo)
  7646. (org-agenda-set-mode-name)
  7647. (message "Time-grid turned %s"
  7648. (if org-agenda-use-time-grid "on" "off")))
  7649. (defun org-agenda-set-mode-name ()
  7650. "Set the mode name to indicate all the small mode settings."
  7651. (setq mode-name
  7652. (list "Org-Agenda"
  7653. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7654. " "
  7655. '(:eval (org-agenda-span-name org-agenda-current-span))
  7656. (if org-agenda-follow-mode " Follow" "")
  7657. (if org-agenda-entry-text-mode " ETxt" "")
  7658. (if org-agenda-include-diary " Diary" "")
  7659. (if org-agenda-include-deadlines " Ddl" "")
  7660. (if org-agenda-use-time-grid " Grid" "")
  7661. (if (and (boundp 'org-habit-show-habits)
  7662. org-habit-show-habits) " Habit" "")
  7663. (cond
  7664. ((consp org-agenda-show-log) " LogAll")
  7665. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7666. (org-agenda-show-log " Log")
  7667. (t ""))
  7668. (if (or org-agenda-category-filter
  7669. (get 'org-agenda-category-filter :preset-filter))
  7670. '(:eval (org-propertize
  7671. (concat " <"
  7672. (mapconcat
  7673. 'identity
  7674. (append
  7675. (get 'org-agenda-category-filter :preset-filter)
  7676. org-agenda-category-filter)
  7677. "")
  7678. ">")
  7679. 'face 'org-agenda-filter-category
  7680. 'help-echo "Category used in filtering")) "")
  7681. (if (or org-agenda-tag-filter
  7682. (get 'org-agenda-tag-filter :preset-filter))
  7683. '(:eval (org-propertize
  7684. (concat " {"
  7685. (mapconcat
  7686. 'identity
  7687. (append
  7688. (get 'org-agenda-tag-filter :preset-filter)
  7689. org-agenda-tag-filter)
  7690. "")
  7691. "}")
  7692. 'face 'org-agenda-filter-tags
  7693. 'help-echo "Tags used in filtering")) "")
  7694. (if (or org-agenda-effort-filter
  7695. (get 'org-agenda-effort-filter :preset-filter))
  7696. '(:eval (org-propertize
  7697. (concat " {"
  7698. (mapconcat
  7699. 'identity
  7700. (append
  7701. (get 'org-agenda-effort-filter :preset-filter)
  7702. org-agenda-effort-filter)
  7703. "")
  7704. "}")
  7705. 'face 'org-agenda-filter-effort
  7706. 'help-echo "Effort conditions used in filtering")) "")
  7707. (if (or org-agenda-regexp-filter
  7708. (get 'org-agenda-regexp-filter :preset-filter))
  7709. '(:eval (org-propertize
  7710. (concat " ["
  7711. (mapconcat
  7712. 'identity
  7713. (append
  7714. (get 'org-agenda-regexp-filter :preset-filter)
  7715. org-agenda-regexp-filter)
  7716. "")
  7717. "]")
  7718. 'face 'org-agenda-filter-regexp
  7719. 'help-echo "Regexp used in filtering")) "")
  7720. (if org-agenda-archives-mode
  7721. (if (eq org-agenda-archives-mode t)
  7722. " Archives"
  7723. (format " :%s:" org-archive-tag))
  7724. "")
  7725. (if org-agenda-clockreport-mode " Clock" "")))
  7726. (force-mode-line-update))
  7727. (define-obsolete-function-alias
  7728. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7729. (defun org-agenda-update-agenda-type ()
  7730. "Update the agenda type after each command."
  7731. (setq org-agenda-type
  7732. (or (get-text-property (point) 'org-agenda-type)
  7733. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7734. (defun org-agenda-next-line ()
  7735. "Move cursor to the next line, and show if follow mode is active."
  7736. (interactive)
  7737. (call-interactively 'next-line)
  7738. (org-agenda-do-context-action))
  7739. (defun org-agenda-previous-line ()
  7740. "Move cursor to the previous line, and show if follow-mode is active."
  7741. (interactive)
  7742. (call-interactively 'previous-line)
  7743. (org-agenda-do-context-action))
  7744. (defun org-agenda-next-item (n)
  7745. "Move cursor to next agenda item."
  7746. (interactive "p")
  7747. (let ((col (current-column)))
  7748. (dotimes (c n)
  7749. (when (next-single-property-change (point-at-eol) 'org-marker)
  7750. (move-end-of-line 1)
  7751. (goto-char (next-single-property-change (point) 'org-marker))))
  7752. (org-move-to-column col))
  7753. (org-agenda-do-context-action))
  7754. (defun org-agenda-previous-item (n)
  7755. "Move cursor to next agenda item."
  7756. (interactive "p")
  7757. (dotimes (c n)
  7758. (let ((col (current-column))
  7759. (goto (save-excursion
  7760. (move-end-of-line 0)
  7761. (previous-single-property-change (point) 'org-marker))))
  7762. (if goto (goto-char goto))
  7763. (org-move-to-column col)))
  7764. (org-agenda-do-context-action))
  7765. (defun org-agenda-do-context-action ()
  7766. "Show outline path and, maybe, follow mode window."
  7767. (let ((m (org-get-at-bol 'org-marker)))
  7768. (when (and (markerp m) (marker-buffer m))
  7769. (and org-agenda-follow-mode
  7770. (if org-agenda-follow-indirect
  7771. (org-agenda-tree-to-indirect-buffer nil)
  7772. (org-agenda-show)))
  7773. (and org-agenda-show-outline-path
  7774. (org-with-point-at m (org-display-outline-path t))))))
  7775. (defun org-agenda-show-tags ()
  7776. "Show the tags applicable to the current item."
  7777. (interactive)
  7778. (let* ((tags (org-get-at-bol 'tags)))
  7779. (if tags
  7780. (message "Tags are :%s:"
  7781. (org-no-properties (mapconcat 'identity tags ":")))
  7782. (message "No tags associated with this line"))))
  7783. (defun org-agenda-goto (&optional highlight)
  7784. "Go to the entry at point in the corresponding Org-mode file."
  7785. (interactive)
  7786. (let* ((marker (or (org-get-at-bol 'org-marker)
  7787. (org-agenda-error)))
  7788. (buffer (marker-buffer marker))
  7789. (pos (marker-position marker)))
  7790. (switch-to-buffer-other-window buffer)
  7791. (widen)
  7792. (push-mark)
  7793. (goto-char pos)
  7794. (when (derived-mode-p 'org-mode)
  7795. (org-show-context 'agenda)
  7796. (save-excursion
  7797. (and (outline-next-heading)
  7798. (org-flag-heading nil)))) ; show the next heading
  7799. (when (outline-invisible-p)
  7800. (show-entry)) ; display invisible text
  7801. (recenter (/ (window-height) 2))
  7802. (org-back-to-heading t)
  7803. (if (re-search-forward org-complex-heading-regexp nil t)
  7804. (goto-char (match-beginning 4)))
  7805. (run-hooks 'org-agenda-after-show-hook)
  7806. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7807. (defvar org-agenda-after-show-hook nil
  7808. "Normal hook run after an item has been shown from the agenda.
  7809. Point is in the buffer where the item originated.")
  7810. (defun org-agenda-kill ()
  7811. "Kill the entry or subtree belonging to the current agenda entry."
  7812. (interactive)
  7813. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7814. (let* ((bufname-orig (buffer-name))
  7815. (marker (or (org-get-at-bol 'org-marker)
  7816. (org-agenda-error)))
  7817. (buffer (marker-buffer marker))
  7818. (pos (marker-position marker))
  7819. (type (org-get-at-bol 'type))
  7820. dbeg dend (n 0) conf)
  7821. (org-with-remote-undo buffer
  7822. (with-current-buffer buffer
  7823. (save-excursion
  7824. (goto-char pos)
  7825. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7826. (setq dbeg (progn (org-back-to-heading t) (point))
  7827. dend (org-end-of-subtree t t))
  7828. (setq dbeg (point-at-bol)
  7829. dend (min (point-max) (1+ (point-at-eol)))))
  7830. (goto-char dbeg)
  7831. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7832. (setq conf (or (eq t org-agenda-confirm-kill)
  7833. (and (numberp org-agenda-confirm-kill)
  7834. (> n org-agenda-confirm-kill))))
  7835. (and conf
  7836. (not (y-or-n-p
  7837. (format "Delete entry with %d lines in buffer \"%s\"? "
  7838. n (buffer-name buffer))))
  7839. (error "Abort"))
  7840. (let ((org-agenda-buffer-name bufname-orig))
  7841. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7842. (with-current-buffer buffer (delete-region dbeg dend))
  7843. (message "Agenda item and source killed"))))
  7844. (defvar org-archive-default-command) ; defined in org-archive.el
  7845. (defun org-agenda-archive-default ()
  7846. "Archive the entry or subtree belonging to the current agenda entry."
  7847. (interactive)
  7848. (require 'org-archive)
  7849. (org-agenda-archive-with org-archive-default-command))
  7850. (defun org-agenda-archive-default-with-confirmation ()
  7851. "Archive the entry or subtree belonging to the current agenda entry."
  7852. (interactive)
  7853. (require 'org-archive)
  7854. (org-agenda-archive-with org-archive-default-command 'confirm))
  7855. (defun org-agenda-archive ()
  7856. "Archive the entry or subtree belonging to the current agenda entry."
  7857. (interactive)
  7858. (org-agenda-archive-with 'org-archive-subtree))
  7859. (defun org-agenda-archive-to-archive-sibling ()
  7860. "Move the entry to the archive sibling."
  7861. (interactive)
  7862. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7863. (defun org-agenda-archive-with (cmd &optional confirm)
  7864. "Move the entry to the archive sibling."
  7865. (interactive)
  7866. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7867. (let* ((bufname-orig (buffer-name))
  7868. (marker (or (org-get-at-bol 'org-marker)
  7869. (org-agenda-error)))
  7870. (buffer (marker-buffer marker))
  7871. (pos (marker-position marker)))
  7872. (org-with-remote-undo buffer
  7873. (with-current-buffer buffer
  7874. (if (derived-mode-p 'org-mode)
  7875. (if (and confirm
  7876. (not (y-or-n-p "Archive this subtree or entry? ")))
  7877. (error "Abort")
  7878. (save-window-excursion
  7879. (goto-char pos)
  7880. (let ((org-agenda-buffer-name bufname-orig))
  7881. (org-remove-subtree-entries-from-agenda))
  7882. (org-back-to-heading t)
  7883. (funcall cmd)))
  7884. (error "Archiving works only in Org-mode files"))))))
  7885. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7886. "Remove all lines in the agenda that correspond to a given subtree.
  7887. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7888. If this information is not given, the function uses the tree at point."
  7889. (let ((buf (or buf (current-buffer))) m p)
  7890. (save-excursion
  7891. (unless (and beg end)
  7892. (org-back-to-heading t)
  7893. (setq beg (point))
  7894. (org-end-of-subtree t)
  7895. (setq end (point)))
  7896. (set-buffer (get-buffer org-agenda-buffer-name))
  7897. (save-excursion
  7898. (goto-char (point-max))
  7899. (beginning-of-line 1)
  7900. (while (not (bobp))
  7901. (when (and (setq m (org-get-at-bol 'org-marker))
  7902. (equal buf (marker-buffer m))
  7903. (setq p (marker-position m))
  7904. (>= p beg)
  7905. (< p end))
  7906. (let ((inhibit-read-only t))
  7907. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7908. (beginning-of-line 0))))))
  7909. (defun org-agenda-refile (&optional goto rfloc no-update)
  7910. "Refile the item at point.
  7911. When GOTO is 0 or '(64) or \\[universal-argument] \\[universal-argument] \\[universal-argument], clear the refile cache.
  7912. When GOTO is '(16) or \\[universal-argument] \\[universal-argument], go to the location of the last refiled item.
  7913. RFLOC can be a refile location obtained in a different way.
  7914. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7915. (interactive "P")
  7916. (cond
  7917. ((member goto '(0 (64)))
  7918. (org-refile-cache-clear))
  7919. ((equal goto '(16))
  7920. (org-refile-goto-last-stored))
  7921. (t
  7922. (let* ((buffer-orig (buffer-name))
  7923. (marker (or (org-get-at-bol 'org-hd-marker)
  7924. (org-agenda-error)))
  7925. (buffer (marker-buffer marker))
  7926. (pos (marker-position marker))
  7927. (rfloc (or rfloc
  7928. (org-refile-get-location
  7929. (if goto "Goto" "Refile to") buffer
  7930. org-refile-allow-creating-parent-nodes))))
  7931. (with-current-buffer buffer
  7932. (save-excursion
  7933. (save-restriction
  7934. (widen)
  7935. (goto-char marker)
  7936. (let ((org-agenda-buffer-name buffer-orig))
  7937. (org-remove-subtree-entries-from-agenda))
  7938. (org-refile goto buffer rfloc)))))
  7939. (unless no-update (org-agenda-redo)))))
  7940. (defun org-agenda-open-link (&optional arg)
  7941. "Open the link(s) in the current entry, if any.
  7942. This looks for a link in the displayed line in the agenda.
  7943. It also looks at the text of the entry itself."
  7944. (interactive "P")
  7945. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7946. (org-get-at-bol 'org-marker)))
  7947. (buffer (and marker (marker-buffer marker)))
  7948. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7949. (lkall (and buffer (org-offer-links-in-entry
  7950. buffer marker arg prefix)))
  7951. (lk0 (car lkall))
  7952. (lk (if (stringp lk0) (list lk0) lk0))
  7953. (lkend (cdr lkall))
  7954. trg)
  7955. (cond
  7956. ((and buffer lk)
  7957. (mapcar (lambda(l)
  7958. (with-current-buffer buffer
  7959. (setq trg (and (string-match org-bracket-link-regexp l)
  7960. (match-string 1 l)))
  7961. (if (or (not trg) (string-match org-any-link-re trg))
  7962. (save-excursion
  7963. (save-restriction
  7964. (widen)
  7965. (goto-char marker)
  7966. (when (search-forward l nil lkend)
  7967. (goto-char (match-beginning 0))
  7968. (org-open-at-point))))
  7969. ;; This is an internal link, widen the buffer
  7970. (switch-to-buffer-other-window buffer)
  7971. (widen)
  7972. (goto-char marker)
  7973. (when (search-forward l nil lkend)
  7974. (goto-char (match-beginning 0))
  7975. (org-open-at-point)))))
  7976. lk))
  7977. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7978. (save-excursion
  7979. (beginning-of-line 1)
  7980. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7981. (org-open-link-from-string (match-string 1)))
  7982. (t (message "No link to open here")))))
  7983. (defun org-agenda-copy-local-variable (var)
  7984. "Get a variable from a referenced buffer and install it here."
  7985. (let ((m (org-get-at-bol 'org-marker)))
  7986. (when (and m (buffer-live-p (marker-buffer m)))
  7987. (org-set-local var (with-current-buffer (marker-buffer m)
  7988. (symbol-value var))))))
  7989. (defun org-agenda-switch-to (&optional delete-other-windows)
  7990. "Go to the Org-mode file which contains the item at point."
  7991. (interactive)
  7992. (if (and org-return-follows-link
  7993. (not (org-get-at-bol 'org-marker))
  7994. (org-in-regexp org-bracket-link-regexp))
  7995. (org-open-link-from-string (match-string 0))
  7996. (let* ((marker (or (org-get-at-bol 'org-marker)
  7997. (org-agenda-error)))
  7998. (buffer (marker-buffer marker))
  7999. (pos (marker-position marker)))
  8000. (org-pop-to-buffer-same-window buffer)
  8001. (and delete-other-windows (delete-other-windows))
  8002. (widen)
  8003. (goto-char pos)
  8004. (org-back-to-heading t)
  8005. (when (derived-mode-p 'org-mode)
  8006. (org-show-context 'agenda)
  8007. (save-excursion
  8008. (and (outline-next-heading)
  8009. (org-flag-heading nil))) ; show the next heading
  8010. (when (outline-invisible-p)
  8011. (show-entry)) ; display invisible text
  8012. (run-hooks 'org-agenda-after-show-hook)))))
  8013. (defun org-agenda-goto-mouse (ev)
  8014. "Go to the Org-mode file which contains the item at the mouse click."
  8015. (interactive "e")
  8016. (mouse-set-point ev)
  8017. (org-agenda-goto))
  8018. (defun org-agenda-show (&optional full-entry)
  8019. "Display the Org-mode file which contains the item at point.
  8020. With prefix argument FULL-ENTRY, make the entire entry visible
  8021. if it was hidden in the outline."
  8022. (interactive "P")
  8023. (let ((win (selected-window)))
  8024. (if full-entry
  8025. (let ((org-show-entry-below t))
  8026. (org-agenda-goto t))
  8027. (org-agenda-goto t))
  8028. (select-window win)))
  8029. (defvar org-agenda-show-window nil)
  8030. (defun org-agenda-show-and-scroll-up (&optional arg)
  8031. "Display the Org-mode file which contains the item at point.
  8032. When called repeatedly, scroll the window that is displaying the buffer.
  8033. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  8034. `show-subtree' to display the item, so that drawers and logbooks stay
  8035. folded."
  8036. (interactive "P")
  8037. (let ((win (selected-window)))
  8038. (if (and (window-live-p org-agenda-show-window)
  8039. (eq this-command last-command))
  8040. (progn
  8041. (select-window org-agenda-show-window)
  8042. (ignore-errors (scroll-up)))
  8043. (org-agenda-goto t)
  8044. (if arg (org-show-entry) (show-subtree))
  8045. (setq org-agenda-show-window (selected-window)))
  8046. (select-window win)))
  8047. (defun org-agenda-show-scroll-down ()
  8048. "Scroll down the window showing the agenda."
  8049. (interactive)
  8050. (let ((win (selected-window)))
  8051. (when (window-live-p org-agenda-show-window)
  8052. (select-window org-agenda-show-window)
  8053. (ignore-errors (scroll-down))
  8054. (select-window win))))
  8055. (defun org-agenda-show-1 (&optional more)
  8056. "Display the Org-mode file which contains the item at point.
  8057. The prefix arg selects the amount of information to display:
  8058. 0 hide the subtree
  8059. 1 just show the entry according to defaults.
  8060. 2 show the children view
  8061. 3 show the subtree view
  8062. 4 show the entire subtree and any LOGBOOK drawers
  8063. 5 show the entire subtree and any drawers
  8064. With prefix argument FULL-ENTRY, make the entire entry visible
  8065. if it was hidden in the outline."
  8066. (interactive "p")
  8067. (let ((win (selected-window)))
  8068. (org-agenda-goto t)
  8069. (org-back-to-heading)
  8070. (set-window-start (selected-window) (point-at-bol))
  8071. (cond
  8072. ((= more 0)
  8073. (hide-subtree)
  8074. (save-excursion
  8075. (org-back-to-heading)
  8076. (run-hook-with-args 'org-cycle-hook 'folded))
  8077. (message "Remote: FOLDED"))
  8078. ((and (org-called-interactively-p 'any) (= more 1))
  8079. (message "Remote: show with default settings"))
  8080. ((= more 2)
  8081. (show-entry)
  8082. (show-children)
  8083. (save-excursion
  8084. (org-back-to-heading)
  8085. (run-hook-with-args 'org-cycle-hook 'children))
  8086. (message "Remote: CHILDREN"))
  8087. ((= more 3)
  8088. (show-subtree)
  8089. (save-excursion
  8090. (org-back-to-heading)
  8091. (run-hook-with-args 'org-cycle-hook 'subtree))
  8092. (message "Remote: SUBTREE"))
  8093. ((= more 4)
  8094. (show-subtree)
  8095. (save-excursion
  8096. (org-back-to-heading)
  8097. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8098. (message "Remote: SUBTREE AND LOGBOOK"))
  8099. ((> more 4)
  8100. (show-subtree)
  8101. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8102. (select-window win)))
  8103. (defvar org-agenda-cycle-counter nil)
  8104. (defun org-agenda-cycle-show (&optional n)
  8105. "Show the current entry in another window, with default settings.
  8106. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8107. When use repeatedly in immediate succession, the remote entry will cycle
  8108. through visibility
  8109. children -> subtree -> folded
  8110. When called with a numeric prefix arg, that arg will be passed through to
  8111. `org-agenda-show-1'. For the interpretation of that argument, see the
  8112. docstring of `org-agenda-show-1'."
  8113. (interactive "P")
  8114. (if (integerp n)
  8115. (setq org-agenda-cycle-counter n)
  8116. (if (not (eq last-command this-command))
  8117. (setq org-agenda-cycle-counter 1)
  8118. (if (equal org-agenda-cycle-counter 0)
  8119. (setq org-agenda-cycle-counter 2)
  8120. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8121. (if (> org-agenda-cycle-counter 3)
  8122. (setq org-agenda-cycle-counter 0)))))
  8123. (org-agenda-show-1 org-agenda-cycle-counter))
  8124. (defun org-agenda-recenter (arg)
  8125. "Display the Org-mode file which contains the item at point and recenter."
  8126. (interactive "P")
  8127. (let ((win (selected-window)))
  8128. (org-agenda-goto t)
  8129. (recenter arg)
  8130. (select-window win)))
  8131. (defun org-agenda-show-mouse (ev)
  8132. "Display the Org-mode file which contains the item at the mouse click."
  8133. (interactive "e")
  8134. (mouse-set-point ev)
  8135. (org-agenda-show))
  8136. (defun org-agenda-check-no-diary ()
  8137. "Check if the entry is a diary link and abort if yes."
  8138. (if (org-get-at-bol 'org-agenda-diary-link)
  8139. (org-agenda-error)))
  8140. (defun org-agenda-error ()
  8141. "Throw an error when a command is not allowed in the agenda."
  8142. (user-error "Command not allowed in this line"))
  8143. (defun org-agenda-tree-to-indirect-buffer (arg)
  8144. "Show the subtree corresponding to the current entry in an indirect buffer.
  8145. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8146. With a numerical prefix ARG, go up to this level and then take that tree.
  8147. With a negative numeric ARG, go up by this number of levels.
  8148. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8149. use the dedicated frame)."
  8150. (interactive "P")
  8151. (if current-prefix-arg
  8152. (org-agenda-do-tree-to-indirect-buffer arg)
  8153. (let ((agenda-buffer (buffer-name))
  8154. (agenda-window (selected-window))
  8155. (indirect-window
  8156. (and org-last-indirect-buffer
  8157. (get-buffer-window org-last-indirect-buffer))))
  8158. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8159. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8160. (eq org-indirect-buffer-display 'dedicated-frame))
  8161. (unwind-protect
  8162. (unless (and indirect-window (window-live-p indirect-window))
  8163. (setq indirect-window (split-window agenda-window)))
  8164. (and indirect-window (select-window indirect-window))
  8165. (switch-to-buffer org-last-indirect-buffer :norecord)
  8166. (fit-window-to-buffer indirect-window)))
  8167. (select-window (get-buffer-window agenda-buffer)))))
  8168. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8169. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8170. (org-agenda-check-no-diary)
  8171. (let* ((marker (or (org-get-at-bol 'org-marker)
  8172. (org-agenda-error)))
  8173. (buffer (marker-buffer marker))
  8174. (pos (marker-position marker)))
  8175. (with-current-buffer buffer
  8176. (save-excursion
  8177. (goto-char pos)
  8178. (funcall 'org-tree-to-indirect-buffer arg)))))
  8179. (defvar org-last-heading-marker (make-marker)
  8180. "Marker pointing to the headline that last changed its TODO state
  8181. by a remote command from the agenda.")
  8182. (defun org-agenda-todo-nextset ()
  8183. "Switch TODO entry to next sequence."
  8184. (interactive)
  8185. (org-agenda-todo 'nextset))
  8186. (defun org-agenda-todo-previousset ()
  8187. "Switch TODO entry to previous sequence."
  8188. (interactive)
  8189. (org-agenda-todo 'previousset))
  8190. (defun org-agenda-todo (&optional arg)
  8191. "Cycle TODO state of line at point, also in Org-mode file.
  8192. This changes the line at point, all other lines in the agenda referring to
  8193. the same tree node, and the headline of the tree node in the Org-mode file."
  8194. (interactive "P")
  8195. (org-agenda-check-no-diary)
  8196. (let* ((col (current-column))
  8197. (marker (or (org-get-at-bol 'org-marker)
  8198. (org-agenda-error)))
  8199. (buffer (marker-buffer marker))
  8200. (pos (marker-position marker))
  8201. (hdmarker (org-get-at-bol 'org-hd-marker))
  8202. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8203. (inhibit-read-only t)
  8204. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8205. (org-with-remote-undo buffer
  8206. (with-current-buffer buffer
  8207. (widen)
  8208. (goto-char pos)
  8209. (org-show-context 'agenda)
  8210. (save-excursion
  8211. (and (outline-next-heading)
  8212. (org-flag-heading nil))) ; show the next heading
  8213. (let ((current-prefix-arg arg))
  8214. (call-interactively 'org-todo))
  8215. (and (bolp) (forward-char 1))
  8216. (setq newhead (org-get-heading))
  8217. (when (and (org-bound-and-true-p
  8218. org-agenda-headline-snapshot-before-repeat)
  8219. (not (equal org-agenda-headline-snapshot-before-repeat
  8220. newhead))
  8221. todayp)
  8222. (setq newhead org-agenda-headline-snapshot-before-repeat
  8223. just-one t))
  8224. (save-excursion
  8225. (org-back-to-heading)
  8226. (move-marker org-last-heading-marker (point))))
  8227. (beginning-of-line 1)
  8228. (save-window-excursion
  8229. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8230. (when (org-bound-and-true-p org-clock-out-when-done)
  8231. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8232. newhead)
  8233. (org-agenda-unmark-clocking-task))
  8234. (org-move-to-column col)
  8235. (org-agenda-mark-clocking-task))))
  8236. (defun org-agenda-add-note (&optional arg)
  8237. "Add a time-stamped note to the entry at point."
  8238. (interactive "P")
  8239. (org-agenda-check-no-diary)
  8240. (let* ((marker (or (org-get-at-bol 'org-marker)
  8241. (org-agenda-error)))
  8242. (buffer (marker-buffer marker))
  8243. (pos (marker-position marker))
  8244. (hdmarker (org-get-at-bol 'org-hd-marker))
  8245. (inhibit-read-only t))
  8246. (with-current-buffer buffer
  8247. (widen)
  8248. (goto-char pos)
  8249. (org-show-context 'agenda)
  8250. (save-excursion
  8251. (and (outline-next-heading)
  8252. (org-flag-heading nil))) ; show the next heading
  8253. (org-add-note))))
  8254. (defun org-agenda-change-all-lines (newhead hdmarker
  8255. &optional fixface just-this)
  8256. "Change all lines in the agenda buffer which match HDMARKER.
  8257. The new content of the line will be NEWHEAD (as modified by
  8258. `org-agenda-format-item'). HDMARKER is checked with
  8259. `equal' against all `org-hd-marker' text properties in the file.
  8260. If FIXFACE is non-nil, the face of each item is modified according to
  8261. the new TODO state.
  8262. If JUST-THIS is non-nil, change just the current line, not all.
  8263. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8264. (let* ((inhibit-read-only t)
  8265. (line (org-current-line))
  8266. (org-agenda-buffer (current-buffer))
  8267. (thetags (with-current-buffer (marker-buffer hdmarker)
  8268. (save-excursion (save-restriction (widen)
  8269. (goto-char hdmarker)
  8270. (org-get-tags-at)))))
  8271. props m pl undone-face done-face finish new dotime level cat tags)
  8272. (save-excursion
  8273. (goto-char (point-max))
  8274. (beginning-of-line 1)
  8275. (while (not finish)
  8276. (setq finish (bobp))
  8277. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8278. (or (not just-this) (= (org-current-line) line))
  8279. (equal m hdmarker))
  8280. (setq props (text-properties-at (point))
  8281. dotime (org-get-at-bol 'dotime)
  8282. cat (org-get-at-eol 'org-category 1)
  8283. level (org-get-at-bol 'level)
  8284. tags thetags
  8285. new
  8286. (let ((org-prefix-format-compiled
  8287. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8288. org-prefix-format-compiled))
  8289. (extra (org-get-at-bol 'extra)))
  8290. (with-current-buffer (marker-buffer hdmarker)
  8291. (save-excursion
  8292. (save-restriction
  8293. (widen)
  8294. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8295. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8296. undone-face (org-get-at-bol 'undone-face)
  8297. done-face (org-get-at-bol 'done-face))
  8298. (beginning-of-line 1)
  8299. (cond
  8300. ((equal new "")
  8301. (and (looking-at ".*\n?") (replace-match "")))
  8302. ((looking-at ".*")
  8303. (replace-match new t t)
  8304. (beginning-of-line 1)
  8305. (add-text-properties (point-at-bol) (point-at-eol) props)
  8306. (when fixface
  8307. (add-text-properties
  8308. (point-at-bol) (point-at-eol)
  8309. (list 'face
  8310. (if org-last-todo-state-is-todo
  8311. undone-face done-face))))
  8312. (org-agenda-highlight-todo 'line)
  8313. (beginning-of-line 1))
  8314. (t (error "Line update did not work")))
  8315. (save-restriction
  8316. (narrow-to-region (point-at-bol) (point-at-eol))
  8317. (org-agenda-finalize)))
  8318. (beginning-of-line 0)))))
  8319. (defun org-agenda-align-tags (&optional line)
  8320. "Align all tags in agenda items to `org-agenda-tags-column'."
  8321. (let ((inhibit-read-only t) l c)
  8322. (save-excursion
  8323. (goto-char (if line (point-at-bol) (point-min)))
  8324. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8325. (if line (point-at-eol) nil) t)
  8326. (add-text-properties
  8327. (match-beginning 2) (match-end 2)
  8328. (list 'face (delq nil (let ((prop (get-text-property
  8329. (match-beginning 2) 'face)))
  8330. (or (listp prop) (setq prop (list prop)))
  8331. (if (memq 'org-tag prop)
  8332. prop
  8333. (cons 'org-tag prop))))))
  8334. (setq l (- (match-end 2) (match-beginning 2))
  8335. c (if (< org-agenda-tags-column 0)
  8336. (- (abs org-agenda-tags-column) l)
  8337. org-agenda-tags-column))
  8338. (delete-region (match-beginning 1) (match-end 1))
  8339. (goto-char (match-beginning 1))
  8340. (insert (org-add-props
  8341. (make-string (max 1 (- c (current-column))) ?\ )
  8342. (plist-put (copy-sequence (text-properties-at (point)))
  8343. 'face nil))))
  8344. (goto-char (point-min))
  8345. (org-font-lock-add-tag-faces (point-max)))))
  8346. (defun org-agenda-priority-up ()
  8347. "Increase the priority of line at point, also in Org-mode file."
  8348. (interactive)
  8349. (org-agenda-priority 'up))
  8350. (defun org-agenda-priority-down ()
  8351. "Decrease the priority of line at point, also in Org-mode file."
  8352. (interactive)
  8353. (org-agenda-priority 'down))
  8354. (defun org-agenda-priority (&optional force-direction)
  8355. "Set the priority of line at point, also in Org-mode file.
  8356. This changes the line at point, all other lines in the agenda referring to
  8357. the same tree node, and the headline of the tree node in the Org-mode file.
  8358. Called with a universal prefix arg, show the priority instead of setting it."
  8359. (interactive "P")
  8360. (if (equal force-direction '(4))
  8361. (org-show-priority)
  8362. (unless org-enable-priority-commands
  8363. (error "Priority commands are disabled"))
  8364. (org-agenda-check-no-diary)
  8365. (let* ((col (current-column))
  8366. (marker (or (org-get-at-bol 'org-marker)
  8367. (org-agenda-error)))
  8368. (hdmarker (org-get-at-bol 'org-hd-marker))
  8369. (buffer (marker-buffer hdmarker))
  8370. (pos (marker-position hdmarker))
  8371. (inhibit-read-only t)
  8372. newhead)
  8373. (org-with-remote-undo buffer
  8374. (with-current-buffer buffer
  8375. (widen)
  8376. (goto-char pos)
  8377. (org-show-context 'agenda)
  8378. (save-excursion
  8379. (and (outline-next-heading)
  8380. (org-flag-heading nil))) ; show the next heading
  8381. (funcall 'org-priority force-direction)
  8382. (end-of-line 1)
  8383. (setq newhead (org-get-heading)))
  8384. (org-agenda-change-all-lines newhead hdmarker)
  8385. (org-move-to-column col)))))
  8386. ;; FIXME: should fix the tags property of the agenda line.
  8387. (defun org-agenda-set-tags (&optional tag onoff)
  8388. "Set tags for the current headline."
  8389. (interactive)
  8390. (org-agenda-check-no-diary)
  8391. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8392. (call-interactively 'org-change-tag-in-region)
  8393. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8394. (org-agenda-error)))
  8395. (buffer (marker-buffer hdmarker))
  8396. (pos (marker-position hdmarker))
  8397. (inhibit-read-only t)
  8398. newhead)
  8399. (org-with-remote-undo buffer
  8400. (with-current-buffer buffer
  8401. (widen)
  8402. (goto-char pos)
  8403. (save-excursion
  8404. (org-show-context 'agenda))
  8405. (save-excursion
  8406. (and (outline-next-heading)
  8407. (org-flag-heading nil))) ; show the next heading
  8408. (goto-char pos)
  8409. (if tag
  8410. (org-toggle-tag tag onoff)
  8411. (call-interactively 'org-set-tags))
  8412. (end-of-line 1)
  8413. (setq newhead (org-get-heading)))
  8414. (org-agenda-change-all-lines newhead hdmarker)
  8415. (beginning-of-line 1)))))
  8416. (defun org-agenda-set-property ()
  8417. "Set a property for the current headline."
  8418. (interactive)
  8419. (org-agenda-check-no-diary)
  8420. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8421. (org-agenda-error)))
  8422. (buffer (marker-buffer hdmarker))
  8423. (pos (marker-position hdmarker))
  8424. (inhibit-read-only t)
  8425. newhead)
  8426. (org-with-remote-undo buffer
  8427. (with-current-buffer buffer
  8428. (widen)
  8429. (goto-char pos)
  8430. (save-excursion
  8431. (org-show-context 'agenda))
  8432. (save-excursion
  8433. (and (outline-next-heading)
  8434. (org-flag-heading nil))) ; show the next heading
  8435. (goto-char pos)
  8436. (call-interactively 'org-set-property)))))
  8437. (defun org-agenda-set-effort ()
  8438. "Set the effort property for the current headline."
  8439. (interactive)
  8440. (org-agenda-check-no-diary)
  8441. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8442. (org-agenda-error)))
  8443. (buffer (marker-buffer hdmarker))
  8444. (pos (marker-position hdmarker))
  8445. (inhibit-read-only t)
  8446. newhead)
  8447. (org-with-remote-undo buffer
  8448. (with-current-buffer buffer
  8449. (widen)
  8450. (goto-char pos)
  8451. (save-excursion
  8452. (org-show-context 'agenda))
  8453. (save-excursion
  8454. (and (outline-next-heading)
  8455. (org-flag-heading nil))) ; show the next heading
  8456. (goto-char pos)
  8457. (call-interactively 'org-set-effort)
  8458. (end-of-line 1)
  8459. (setq newhead (org-get-heading)))
  8460. (org-agenda-change-all-lines newhead hdmarker))))
  8461. (defun org-agenda-toggle-archive-tag ()
  8462. "Toggle the archive tag for the current entry."
  8463. (interactive)
  8464. (org-agenda-check-no-diary)
  8465. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8466. (org-agenda-error)))
  8467. (buffer (marker-buffer hdmarker))
  8468. (pos (marker-position hdmarker))
  8469. (inhibit-read-only t)
  8470. newhead)
  8471. (org-with-remote-undo buffer
  8472. (with-current-buffer buffer
  8473. (widen)
  8474. (goto-char pos)
  8475. (org-show-context 'agenda)
  8476. (save-excursion
  8477. (and (outline-next-heading)
  8478. (org-flag-heading nil))) ; show the next heading
  8479. (call-interactively 'org-toggle-archive-tag)
  8480. (end-of-line 1)
  8481. (setq newhead (org-get-heading)))
  8482. (org-agenda-change-all-lines newhead hdmarker)
  8483. (beginning-of-line 1))))
  8484. (defun org-agenda-do-date-later (arg)
  8485. (interactive "P")
  8486. (cond
  8487. ((or (equal arg '(16))
  8488. (memq last-command
  8489. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8490. (setq this-command 'org-agenda-date-later-minutes)
  8491. (org-agenda-date-later-minutes 1))
  8492. ((or (equal arg '(4))
  8493. (memq last-command
  8494. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8495. (setq this-command 'org-agenda-date-later-hours)
  8496. (org-agenda-date-later-hours 1))
  8497. (t
  8498. (org-agenda-date-later (prefix-numeric-value arg)))))
  8499. (defun org-agenda-do-date-earlier (arg)
  8500. (interactive "P")
  8501. (cond
  8502. ((or (equal arg '(16))
  8503. (memq last-command
  8504. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8505. (setq this-command 'org-agenda-date-earlier-minutes)
  8506. (org-agenda-date-earlier-minutes 1))
  8507. ((or (equal arg '(4))
  8508. (memq last-command
  8509. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8510. (setq this-command 'org-agenda-date-earlier-hours)
  8511. (org-agenda-date-earlier-hours 1))
  8512. (t
  8513. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8514. (defun org-agenda-date-later (arg &optional what)
  8515. "Change the date of this item to ARG day(s) later."
  8516. (interactive "p")
  8517. (org-agenda-check-type t 'agenda 'timeline)
  8518. (org-agenda-check-no-diary)
  8519. (let* ((marker (or (org-get-at-bol 'org-marker)
  8520. (org-agenda-error)))
  8521. (buffer (marker-buffer marker))
  8522. (pos (marker-position marker))
  8523. cdate today)
  8524. (org-with-remote-undo buffer
  8525. (with-current-buffer buffer
  8526. (widen)
  8527. (goto-char pos)
  8528. (if (not (org-at-timestamp-p))
  8529. (error "Cannot find time stamp"))
  8530. (when (and org-agenda-move-date-from-past-immediately-to-today
  8531. (equal arg 1)
  8532. (or (not what) (eq what 'day))
  8533. (not (save-match-data (org-at-date-range-p))))
  8534. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8535. cdate (calendar-absolute-from-gregorian
  8536. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8537. today (org-today))
  8538. (if (> today cdate)
  8539. ;; immediately shift to today
  8540. (setq arg (- today cdate))))
  8541. (org-timestamp-change arg (or what 'day))
  8542. (when (and (org-at-date-range-p)
  8543. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8544. (let ((end org-last-changed-timestamp))
  8545. (org-timestamp-change arg (or what 'day))
  8546. (setq org-last-changed-timestamp
  8547. (concat org-last-changed-timestamp "--" end)))))
  8548. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8549. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8550. (defun org-agenda-date-earlier (arg &optional what)
  8551. "Change the date of this item to ARG day(s) earlier."
  8552. (interactive "p")
  8553. (org-agenda-date-later (- arg) what))
  8554. (defun org-agenda-date-later-minutes (arg)
  8555. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8556. (interactive "p")
  8557. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8558. (org-agenda-date-later arg 'minute))
  8559. (defun org-agenda-date-earlier-minutes (arg)
  8560. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8561. (interactive "p")
  8562. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8563. (org-agenda-date-earlier arg 'minute))
  8564. (defun org-agenda-date-later-hours (arg)
  8565. "Change the time of this item, in hour steps."
  8566. (interactive "p")
  8567. (org-agenda-date-later arg 'hour))
  8568. (defun org-agenda-date-earlier-hours (arg)
  8569. "Change the time of this item, in hour steps."
  8570. (interactive "p")
  8571. (org-agenda-date-earlier arg 'hour))
  8572. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8573. "Show new date stamp via text properties."
  8574. ;; We use text properties to make this undoable
  8575. (let ((inhibit-read-only t))
  8576. (setq stamp (concat prefix " => " stamp " "))
  8577. (save-excursion
  8578. (goto-char (point-max))
  8579. (while (not (bobp))
  8580. (when (equal marker (org-get-at-bol 'org-marker))
  8581. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8582. (org-move-to-column (- (window-width) (length stamp)) t)
  8583. (if (featurep 'xemacs)
  8584. ;; Use `duplicable' property to trigger undo recording
  8585. (let ((ex (make-extent nil nil))
  8586. (gl (make-glyph stamp)))
  8587. (set-glyph-face gl 'secondary-selection)
  8588. (set-extent-properties
  8589. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8590. (insert-extent ex (1- (point)) (point-at-eol)))
  8591. (add-text-properties
  8592. (1- (point)) (point-at-eol)
  8593. (list 'display (org-add-props stamp nil
  8594. 'face '(secondary-selection default)))))
  8595. (beginning-of-line 1))
  8596. (beginning-of-line 0)))))
  8597. (defun org-agenda-date-prompt (arg)
  8598. "Change the date of this item. Date is prompted for, with default today.
  8599. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8600. be used to request time specification in the time stamp."
  8601. (interactive "P")
  8602. (org-agenda-check-type t 'agenda 'timeline)
  8603. (org-agenda-check-no-diary)
  8604. (let* ((marker (or (org-get-at-bol 'org-marker)
  8605. (org-agenda-error)))
  8606. (buffer (marker-buffer marker))
  8607. (pos (marker-position marker)))
  8608. (org-with-remote-undo buffer
  8609. (with-current-buffer buffer
  8610. (widen)
  8611. (goto-char pos)
  8612. (if (not (org-at-timestamp-p t))
  8613. (error "Cannot find time stamp"))
  8614. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8615. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8616. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8617. (defun org-agenda-schedule (arg &optional time)
  8618. "Schedule the item at point.
  8619. ARG is passed through to `org-schedule'."
  8620. (interactive "P")
  8621. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8622. (org-agenda-check-no-diary)
  8623. (let* ((marker (or (org-get-at-bol 'org-marker)
  8624. (org-agenda-error)))
  8625. (type (marker-insertion-type marker))
  8626. (buffer (marker-buffer marker))
  8627. (pos (marker-position marker))
  8628. (org-insert-labeled-timestamps-at-point nil)
  8629. ts)
  8630. (set-marker-insertion-type marker t)
  8631. (org-with-remote-undo buffer
  8632. (with-current-buffer buffer
  8633. (widen)
  8634. (goto-char pos)
  8635. (setq ts (org-schedule arg time)))
  8636. (org-agenda-show-new-time marker ts " S"))
  8637. (message "%s" ts)))
  8638. (defun org-agenda-deadline (arg &optional time)
  8639. "Schedule the item at point.
  8640. ARG is passed through to `org-deadline'."
  8641. (interactive "P")
  8642. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8643. (org-agenda-check-no-diary)
  8644. (let* ((marker (or (org-get-at-bol 'org-marker)
  8645. (org-agenda-error)))
  8646. (buffer (marker-buffer marker))
  8647. (pos (marker-position marker))
  8648. (org-insert-labeled-timestamps-at-point nil)
  8649. ts)
  8650. (org-with-remote-undo buffer
  8651. (with-current-buffer buffer
  8652. (widen)
  8653. (goto-char pos)
  8654. (setq ts (org-deadline arg time)))
  8655. (org-agenda-show-new-time marker ts " D"))
  8656. (message "%s" ts)))
  8657. (defun org-agenda-clock-in (&optional arg)
  8658. "Start the clock on the currently selected item."
  8659. (interactive "P")
  8660. (org-agenda-check-no-diary)
  8661. (if (equal arg '(4))
  8662. (org-clock-in arg)
  8663. (let* ((marker (or (org-get-at-bol 'org-marker)
  8664. (org-agenda-error)))
  8665. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8666. (pos (marker-position marker))
  8667. (col (current-column))
  8668. newhead)
  8669. (org-with-remote-undo (marker-buffer marker)
  8670. (with-current-buffer (marker-buffer marker)
  8671. (widen)
  8672. (goto-char pos)
  8673. (org-show-context 'agenda)
  8674. (org-show-entry)
  8675. (org-cycle-hide-drawers 'children)
  8676. (org-clock-in arg)
  8677. (setq newhead (org-get-heading)))
  8678. (org-agenda-change-all-lines newhead hdmarker))
  8679. (org-move-to-column col))))
  8680. (defun org-agenda-clock-out ()
  8681. "Stop the currently running clock."
  8682. (interactive)
  8683. (unless (marker-buffer org-clock-marker)
  8684. (error "No running clock"))
  8685. (let ((marker (make-marker)) (col (current-column)) newhead)
  8686. (org-with-remote-undo (marker-buffer org-clock-marker)
  8687. (with-current-buffer (marker-buffer org-clock-marker)
  8688. (save-excursion
  8689. (save-restriction
  8690. (widen)
  8691. (goto-char org-clock-marker)
  8692. (org-back-to-heading t)
  8693. (move-marker marker (point))
  8694. (org-clock-out)
  8695. (setq newhead (org-get-heading))))))
  8696. (org-agenda-change-all-lines newhead marker)
  8697. (move-marker marker nil)
  8698. (org-move-to-column col)
  8699. (org-agenda-unmark-clocking-task)))
  8700. (defun org-agenda-clock-cancel (&optional arg)
  8701. "Cancel the currently running clock."
  8702. (interactive "P")
  8703. (unless (marker-buffer org-clock-marker)
  8704. (user-error "No running clock"))
  8705. (org-with-remote-undo (marker-buffer org-clock-marker)
  8706. (org-clock-cancel)))
  8707. (defun org-agenda-clock-goto ()
  8708. "Jump to the currently clocked in task within the agenda.
  8709. If the currently clocked in task is not listed in the agenda
  8710. buffer, display it in another window."
  8711. (interactive)
  8712. (let (pos)
  8713. (mapc (lambda (o)
  8714. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8715. (setq pos (overlay-start o))))
  8716. (overlays-in (point-min) (point-max)))
  8717. (cond (pos (goto-char pos))
  8718. ;; If the currently clocked entry is not in the agenda
  8719. ;; buffer, we visit it in another window:
  8720. (org-clock-current-task
  8721. (org-switch-to-buffer-other-window (org-clock-goto)))
  8722. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8723. (defun org-agenda-diary-entry-in-org-file ()
  8724. "Make a diary entry in the file `org-agenda-diary-file'."
  8725. (let (d1 d2 char (text "") dp1 dp2)
  8726. (if (equal (buffer-name) "*Calendar*")
  8727. (setq d1 (calendar-cursor-to-date t)
  8728. d2 (car calendar-mark-ring))
  8729. (setq dp1 (get-text-property (point-at-bol) 'day))
  8730. (unless dp1 (user-error "No date defined in current line"))
  8731. (setq d1 (calendar-gregorian-from-absolute dp1)
  8732. d2 (and (ignore-errors (mark))
  8733. (save-excursion
  8734. (goto-char (mark))
  8735. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8736. (calendar-gregorian-from-absolute dp2))))
  8737. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8738. (setq char (read-char-exclusive))
  8739. (cond
  8740. ((equal char ?d)
  8741. (setq text (read-string "Day entry: "))
  8742. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8743. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8744. ((equal char ?a)
  8745. (setq d1 (list (car d1) (nth 1 d1)
  8746. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8747. (nth 2 d1))))
  8748. (setq text (read-string "Anniversary (use %d to show years): "))
  8749. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8750. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8751. ((equal char ?b)
  8752. (setq text (read-string "Block entry: "))
  8753. (unless (and d1 d2 (not (equal d1 d2)))
  8754. (user-error "No block of days selected"))
  8755. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8756. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8757. ((equal char ?j)
  8758. (org-switch-to-buffer-other-window
  8759. (find-file-noselect org-agenda-diary-file))
  8760. (require 'org-datetree)
  8761. (org-datetree-find-date-create d1)
  8762. (org-reveal t))
  8763. (t (user-error "Invalid selection character `%c'" char)))))
  8764. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8765. "Where in `org-agenda-diary-file' should new entries be added?
  8766. Valid values:
  8767. date-tree in the date tree, as child of the date
  8768. top-level as top-level entries at the end of the file."
  8769. :group 'org-agenda
  8770. :type '(choice
  8771. (const :tag "in a date tree" date-tree)
  8772. (const :tag "as top level at end of file" top-level)))
  8773. (defcustom org-agenda-insert-diary-extract-time nil
  8774. "Non-nil means extract any time specification from the diary entry."
  8775. :group 'org-agenda
  8776. :version "24.1"
  8777. :type 'boolean)
  8778. (defcustom org-agenda-bulk-mark-char ">"
  8779. "A single-character string to be used as the bulk mark."
  8780. :group 'org-agenda
  8781. :version "24.1"
  8782. :type 'string)
  8783. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8784. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8785. If TEXT is not empty, it will become the headline of the new entry, and
  8786. the resulting entry will not be shown. When TEXT is empty, switch to
  8787. `org-agenda-diary-file' and let the user finish the entry there."
  8788. (let ((cw (current-window-configuration)))
  8789. (org-switch-to-buffer-other-window
  8790. (find-file-noselect org-agenda-diary-file))
  8791. (widen)
  8792. (goto-char (point-min))
  8793. (cond
  8794. ((eq type 'anniversary)
  8795. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8796. (progn
  8797. (or (org-at-heading-p t)
  8798. (progn
  8799. (outline-next-heading)
  8800. (insert "* Anniversaries\n\n")
  8801. (beginning-of-line -1)))))
  8802. (outline-next-heading)
  8803. (org-back-over-empty-lines)
  8804. (backward-char 1)
  8805. (insert "\n")
  8806. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8807. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8808. ((eq type 'day)
  8809. (let ((org-prefix-has-time t)
  8810. (org-agenda-time-leading-zero t)
  8811. fmt time time2)
  8812. (if org-agenda-insert-diary-extract-time
  8813. ;; Use org-agenda-format-item to parse text for a time-range and
  8814. ;; remove it. FIXME: This is a hack, we should refactor
  8815. ;; that function to make time extraction available separately
  8816. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8817. time (get-text-property 0 'time fmt)
  8818. time2 (if (> (length time) 0)
  8819. ;; split-string removes trailing ...... if
  8820. ;; no end time given. First space
  8821. ;; separates time from date.
  8822. (concat " " (car (split-string time "\\.")))
  8823. nil)
  8824. text (get-text-property 0 'txt fmt)))
  8825. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8826. (org-agenda-insert-diary-as-top-level text)
  8827. (require 'org-datetree)
  8828. (org-datetree-find-date-create d1)
  8829. (org-agenda-insert-diary-make-new-entry text))
  8830. (org-insert-time-stamp (org-time-from-absolute
  8831. (calendar-absolute-from-gregorian d1))
  8832. nil nil nil nil time2))
  8833. (end-of-line 0))
  8834. ((eq type 'block)
  8835. (if (> (calendar-absolute-from-gregorian d1)
  8836. (calendar-absolute-from-gregorian d2))
  8837. (setq d1 (prog1 d2 (setq d2 d1))))
  8838. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8839. (org-agenda-insert-diary-as-top-level text)
  8840. (require 'org-datetree)
  8841. (org-datetree-find-date-create d1)
  8842. (org-agenda-insert-diary-make-new-entry text))
  8843. (org-insert-time-stamp (org-time-from-absolute
  8844. (calendar-absolute-from-gregorian d1)))
  8845. (insert "--")
  8846. (org-insert-time-stamp (org-time-from-absolute
  8847. (calendar-absolute-from-gregorian d2)))
  8848. (end-of-line 0)))
  8849. (if (string-match "\\S-" text)
  8850. (progn
  8851. (set-window-configuration cw)
  8852. (message "%s entry added to %s"
  8853. (capitalize (symbol-name type))
  8854. (abbreviate-file-name org-agenda-diary-file)))
  8855. (org-reveal t)
  8856. (message "Please finish entry here"))))
  8857. (defun org-agenda-insert-diary-as-top-level (text)
  8858. "Make new entry as a top-level entry at the end of the file.
  8859. Add TEXT as headline, and position the cursor in the second line so that
  8860. a timestamp can be added there."
  8861. (widen)
  8862. (goto-char (point-max))
  8863. (or (bolp) (insert "\n"))
  8864. (insert "* " text "\n")
  8865. (if org-adapt-indentation (org-indent-to-column 2)))
  8866. (defun org-agenda-insert-diary-make-new-entry (text)
  8867. "Make a new entry with TEXT as the first child of the current subtree.
  8868. Position the point in the line right after the new heading so
  8869. that a timestamp can be added there."
  8870. (let ((org-show-following-heading t)
  8871. (org-show-siblings t)
  8872. (org-show-hierarchy-above t)
  8873. (org-show-entry-below t)
  8874. col)
  8875. (outline-next-heading)
  8876. (org-back-over-empty-lines)
  8877. (or (looking-at "[ \t]*$")
  8878. (progn (insert "\n") (backward-char 1)))
  8879. (org-insert-heading nil t)
  8880. (org-do-demote)
  8881. (setq col (current-column))
  8882. (insert text "\n")
  8883. (if org-adapt-indentation (org-indent-to-column col))
  8884. (let ((org-show-following-heading t)
  8885. (org-show-siblings t)
  8886. (org-show-hierarchy-above t)
  8887. (org-show-entry-below t))
  8888. (org-show-context))))
  8889. (defun org-agenda-diary-entry ()
  8890. "Make a diary entry, like the `i' command from the calendar.
  8891. All the standard commands work: block, weekly etc.
  8892. When `org-agenda-diary-file' points to a file,
  8893. `org-agenda-diary-entry-in-org-file' is called instead to create
  8894. entries in that Org-mode file."
  8895. (interactive)
  8896. (if (not (eq org-agenda-diary-file 'diary-file))
  8897. (org-agenda-diary-entry-in-org-file)
  8898. (require 'diary-lib)
  8899. (let* ((char (progn
  8900. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8901. (read-char-exclusive)))
  8902. (cmd (cdr (assoc char
  8903. '((?d . insert-diary-entry)
  8904. (?w . insert-weekly-diary-entry)
  8905. (?m . insert-monthly-diary-entry)
  8906. (?y . insert-yearly-diary-entry)
  8907. (?a . insert-anniversary-diary-entry)
  8908. (?b . insert-block-diary-entry)
  8909. (?c . insert-cyclic-diary-entry)))))
  8910. (oldf (symbol-function 'calendar-cursor-to-date))
  8911. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8912. (point (point))
  8913. (mark (or (mark t) (point))))
  8914. (unless cmd
  8915. (user-error "No command associated with <%c>" char))
  8916. (unless (and (get-text-property point 'day)
  8917. (or (not (equal ?b char))
  8918. (get-text-property mark 'day)))
  8919. (user-error "Don't know which date to use for diary entry"))
  8920. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8921. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8922. (let ((calendar-mark-ring
  8923. (list (calendar-gregorian-from-absolute
  8924. (or (get-text-property mark 'day)
  8925. (get-text-property point 'day))))))
  8926. (unwind-protect
  8927. (progn
  8928. (fset 'calendar-cursor-to-date
  8929. (lambda (&optional error dummy)
  8930. (calendar-gregorian-from-absolute
  8931. (get-text-property point 'day))))
  8932. (call-interactively cmd))
  8933. (fset 'calendar-cursor-to-date oldf))))))
  8934. (defun org-agenda-execute-calendar-command (cmd)
  8935. "Execute a calendar command from the agenda with date from cursor."
  8936. (org-agenda-check-type t 'agenda 'timeline)
  8937. (require 'diary-lib)
  8938. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8939. (user-error "Don't know which date to use for the calendar command"))
  8940. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8941. (point (point))
  8942. (date (calendar-gregorian-from-absolute
  8943. (get-text-property point 'day)))
  8944. ;; the following 2 vars are needed in the calendar
  8945. (displayed-month (car date))
  8946. (displayed-year (nth 2 date)))
  8947. (unwind-protect
  8948. (progn
  8949. (fset 'calendar-cursor-to-date
  8950. (lambda (&optional error dummy)
  8951. (calendar-gregorian-from-absolute
  8952. (get-text-property point 'day))))
  8953. (call-interactively cmd))
  8954. (fset 'calendar-cursor-to-date oldf))))
  8955. (defun org-agenda-phases-of-moon ()
  8956. "Display the phases of the moon for the 3 months around the cursor date."
  8957. (interactive)
  8958. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8959. (defun org-agenda-holidays ()
  8960. "Display the holidays for the 3 months around the cursor date."
  8961. (interactive)
  8962. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8963. (defvar calendar-longitude) ; defined in calendar.el
  8964. (defvar calendar-latitude) ; defined in calendar.el
  8965. (defvar calendar-location-name) ; defined in calendar.el
  8966. (defun org-agenda-sunrise-sunset (arg)
  8967. "Display sunrise and sunset for the cursor date.
  8968. Latitude and longitude can be specified with the variables
  8969. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8970. argument, latitude and longitude will be prompted for."
  8971. (interactive "P")
  8972. (require 'solar)
  8973. (let ((calendar-longitude (if arg nil calendar-longitude))
  8974. (calendar-latitude (if arg nil calendar-latitude))
  8975. (calendar-location-name
  8976. (if arg "the given coordinates" calendar-location-name)))
  8977. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8978. (defun org-agenda-goto-calendar ()
  8979. "Open the Emacs calendar with the date at the cursor."
  8980. (interactive)
  8981. (org-agenda-check-type t 'agenda 'timeline)
  8982. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8983. (user-error "Don't know which date to open in calendar")))
  8984. (date (calendar-gregorian-from-absolute day))
  8985. (calendar-move-hook nil)
  8986. (calendar-view-holidays-initially-flag nil)
  8987. (calendar-view-diary-initially-flag nil))
  8988. (calendar)
  8989. (calendar-goto-date date)))
  8990. ;;;###autoload
  8991. (defun org-calendar-goto-agenda ()
  8992. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8993. This is a command that has to be installed in `calendar-mode-map'."
  8994. (interactive)
  8995. (org-agenda-list nil (calendar-absolute-from-gregorian
  8996. (calendar-cursor-to-date))
  8997. nil))
  8998. (defun org-agenda-convert-date ()
  8999. (interactive)
  9000. (org-agenda-check-type t 'agenda 'timeline)
  9001. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9002. date s)
  9003. (unless day
  9004. (user-error "Don't know which date to convert"))
  9005. (setq date (calendar-gregorian-from-absolute day))
  9006. (setq s (concat
  9007. "Gregorian: " (calendar-date-string date) "\n"
  9008. "ISO: " (calendar-iso-date-string date) "\n"
  9009. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9010. "Julian: " (calendar-julian-date-string date) "\n"
  9011. "Astron. JD: " (calendar-astro-date-string date)
  9012. " (Julian date number at noon UTC)\n"
  9013. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9014. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9015. "French: " (calendar-french-date-string date) "\n"
  9016. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  9017. "Mayan: " (calendar-mayan-date-string date) "\n"
  9018. "Coptic: " (calendar-coptic-date-string date) "\n"
  9019. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9020. "Persian: " (calendar-persian-date-string date) "\n"
  9021. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9022. (with-output-to-temp-buffer "*Dates*"
  9023. (princ s))
  9024. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9025. ;;; Bulk commands
  9026. (defun org-agenda-bulk-marked-p ()
  9027. (eq (get-char-property (point-at-bol) 'type)
  9028. 'org-marked-entry-overlay))
  9029. (defun org-agenda-bulk-mark (&optional arg)
  9030. "Mark the entry at point for future bulk action."
  9031. (interactive "p")
  9032. (dotimes (i (or arg 1))
  9033. (unless (org-get-at-bol 'org-agenda-diary-link)
  9034. (let* ((m (org-get-at-bol 'org-hd-marker))
  9035. ov)
  9036. (unless (org-agenda-bulk-marked-p)
  9037. (unless m (user-error "Nothing to mark at point"))
  9038. (push m org-agenda-bulk-marked-entries)
  9039. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9040. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9041. (org-get-todo-face "TODO")
  9042. 'evaporate)
  9043. (overlay-put ov 'type 'org-marked-entry-overlay))
  9044. (end-of-line 1)
  9045. (or (ignore-errors
  9046. (goto-char (next-single-property-change (point) 'txt)))
  9047. (beginning-of-line 2))
  9048. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9049. (beginning-of-line 2))
  9050. (message "%d entries marked for bulk action"
  9051. (length org-agenda-bulk-marked-entries))))))
  9052. (defun org-agenda-bulk-mark-all ()
  9053. "Mark all entries for future agenda bulk action."
  9054. (interactive)
  9055. (org-agenda-bulk-mark-regexp "."))
  9056. (defun org-agenda-bulk-mark-regexp (regexp)
  9057. "Mark entries matching REGEXP for future agenda bulk action."
  9058. (interactive "sMark entries matching regexp: ")
  9059. (let ((entries-marked 0) txt-at-point)
  9060. (save-excursion
  9061. (goto-char (point-min))
  9062. (goto-char (next-single-property-change (point) 'txt))
  9063. (while (and (re-search-forward regexp nil t)
  9064. (setq txt-at-point (get-text-property (point) 'txt)))
  9065. (when (string-match regexp txt-at-point)
  9066. (setq entries-marked (1+ entries-marked))
  9067. (call-interactively 'org-agenda-bulk-mark))))
  9068. (if (not entries-marked)
  9069. (message "No entry matching this regexp."))))
  9070. (defun org-agenda-bulk-unmark (&optional arg)
  9071. "Unmark the entry at point for future bulk action."
  9072. (interactive "P")
  9073. (if arg
  9074. (org-agenda-bulk-unmark-all)
  9075. (cond ((org-agenda-bulk-marked-p)
  9076. (org-agenda-bulk-remove-overlays
  9077. (point-at-bol) (+ 2 (point-at-bol)))
  9078. (setq org-agenda-bulk-marked-entries
  9079. (delete (org-get-at-bol 'org-hd-marker)
  9080. org-agenda-bulk-marked-entries))
  9081. (end-of-line 1)
  9082. (or (ignore-errors
  9083. (goto-char (next-single-property-change (point) 'txt)))
  9084. (beginning-of-line 2))
  9085. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9086. (beginning-of-line 2))
  9087. (message "%d entries left marked for bulk action"
  9088. (length org-agenda-bulk-marked-entries)))
  9089. (t (message "No entry to unmark here")))))
  9090. (defun org-agenda-bulk-toggle-all ()
  9091. "Toggle all marks for bulk action."
  9092. (interactive)
  9093. (save-excursion
  9094. (goto-char (point-min))
  9095. (while (ignore-errors
  9096. (goto-char (next-single-property-change (point) 'txt)))
  9097. (org-agenda-bulk-toggle))))
  9098. (defun org-agenda-bulk-toggle ()
  9099. "Toggle the mark at point for bulk action."
  9100. (interactive)
  9101. (if (org-agenda-bulk-marked-p)
  9102. (org-agenda-bulk-unmark)
  9103. (org-agenda-bulk-mark)))
  9104. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9105. "Remove the mark overlays between BEG and END in the agenda buffer.
  9106. BEG and END default to the buffer limits.
  9107. This only removes the overlays, it does not remove the markers
  9108. from the list in `org-agenda-bulk-marked-entries'."
  9109. (interactive)
  9110. (mapc (lambda (ov)
  9111. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9112. (delete-overlay ov)))
  9113. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9114. (defun org-agenda-bulk-unmark-all ()
  9115. "Remove all marks in the agenda buffer.
  9116. This will remove the markers and the overlays."
  9117. (interactive)
  9118. (if (null org-agenda-bulk-marked-entries)
  9119. (message "No entry to unmark")
  9120. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9121. (setq org-agenda-bulk-marked-entries nil)
  9122. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9123. (defcustom org-agenda-persistent-marks nil
  9124. "Non-nil means marked items will stay marked after a bulk action.
  9125. You can toggle this interactively by typing `p' when prompted for a
  9126. bulk action."
  9127. :group 'org-agenda
  9128. :version "24.1"
  9129. :type 'boolean)
  9130. (defun org-agenda-bulk-action (&optional arg)
  9131. "Execute an remote-editing action on all marked entries.
  9132. The prefix arg is passed through to the command if possible."
  9133. (interactive "P")
  9134. ;; Make sure we have markers, and only valid ones
  9135. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9136. (mapc
  9137. (lambda (m)
  9138. (unless (and (markerp m)
  9139. (marker-buffer m)
  9140. (buffer-live-p (marker-buffer m))
  9141. (marker-position m))
  9142. (user-error "Marker %s for bulk command is invalid" m)))
  9143. org-agenda-bulk-marked-entries)
  9144. ;; Prompt for the bulk command
  9145. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9146. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9147. "[S]catter [f]unction "
  9148. (when org-agenda-bulk-custom-functions
  9149. (concat " Custom: ["
  9150. (mapconcat (lambda(f) (char-to-string (car f)))
  9151. org-agenda-bulk-custom-functions "")
  9152. "]"))))
  9153. (catch 'exit
  9154. (let* ((action (read-char-exclusive))
  9155. (org-log-refile (if org-log-refile 'time nil))
  9156. (entries (reverse org-agenda-bulk-marked-entries))
  9157. (org-overriding-default-time
  9158. (if (get-text-property (point) 'org-agenda-date-header)
  9159. (org-get-cursor-date)))
  9160. redo-at-end
  9161. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9162. (cond
  9163. ((equal action ?p)
  9164. (let ((org-agenda-persistent-marks
  9165. (not org-agenda-persistent-marks)))
  9166. (org-agenda-bulk-action)
  9167. (throw 'exit nil)))
  9168. ((equal action ?$)
  9169. (setq cmd '(org-agenda-archive)))
  9170. ((equal action ?A)
  9171. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9172. ((member action '(?r ?w))
  9173. (setq rfloc (org-refile-get-location
  9174. "Refile to"
  9175. (marker-buffer (car entries))
  9176. org-refile-allow-creating-parent-nodes))
  9177. (if (nth 3 rfloc)
  9178. (setcar (nthcdr 3 rfloc)
  9179. (move-marker (make-marker) (nth 3 rfloc)
  9180. (or (get-file-buffer (nth 1 rfloc))
  9181. (find-buffer-visiting (nth 1 rfloc))
  9182. (error "This should not happen")))))
  9183. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9184. redo-at-end t))
  9185. ((equal action ?t)
  9186. (setq state (org-icompleting-read
  9187. "Todo state: "
  9188. (with-current-buffer (marker-buffer (car entries))
  9189. (mapcar 'list org-todo-keywords-1))))
  9190. (setq cmd `(let ((org-inhibit-blocking t)
  9191. (org-inhibit-logging 'note))
  9192. (org-agenda-todo ,state))))
  9193. ((memq action '(?- ?+))
  9194. (setq tag (org-icompleting-read
  9195. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9196. (with-current-buffer (marker-buffer (car entries))
  9197. (delq nil
  9198. (mapcar (lambda (x)
  9199. (if (stringp (car x)) x)) org-tag-alist)))))
  9200. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9201. ((memq action '(?s ?d))
  9202. (let* ((time
  9203. (unless arg
  9204. (org-read-date
  9205. nil nil nil
  9206. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9207. org-overriding-default-time)))
  9208. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9209. (setq cmd `(eval '(,c1 arg ,time)))))
  9210. ((equal action ?S)
  9211. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9212. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9213. (let ((days (read-number
  9214. (format "Scatter tasks across how many %sdays: "
  9215. (if arg "week" "")) 7)))
  9216. (setq cmd
  9217. `(let ((distance (1+ (random ,days))))
  9218. (if arg
  9219. (let ((dist distance)
  9220. (day-of-week
  9221. (calendar-day-of-week
  9222. (calendar-gregorian-from-absolute (org-today)))))
  9223. (dotimes (i (1+ dist))
  9224. (while (member day-of-week org-agenda-weekend-days)
  9225. (incf distance)
  9226. (incf day-of-week)
  9227. (if (= day-of-week 7)
  9228. (setq day-of-week 0)))
  9229. (incf day-of-week)
  9230. (if (= day-of-week 7)
  9231. (setq day-of-week 0)))))
  9232. ;; silently fail when try to replan a sexp entry
  9233. (condition-case nil
  9234. (let* ((date (calendar-gregorian-from-absolute
  9235. (+ (org-today) distance)))
  9236. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9237. (nth 2 date))))
  9238. (org-agenda-schedule nil time))
  9239. (error nil)))))))
  9240. ((assoc action org-agenda-bulk-custom-functions)
  9241. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9242. redo-at-end t))
  9243. ((equal action ?f)
  9244. (setq cmd (list (intern
  9245. (org-icompleting-read "Function: "
  9246. obarray 'fboundp t nil nil)))))
  9247. (t (user-error "Invalid bulk action")))
  9248. ;; Sort the markers, to make sure that parents are handled before children
  9249. (setq entries (sort entries
  9250. (lambda (a b)
  9251. (cond
  9252. ((equal (marker-buffer a) (marker-buffer b))
  9253. (< (marker-position a) (marker-position b)))
  9254. (t
  9255. (string< (buffer-name (marker-buffer a))
  9256. (buffer-name (marker-buffer b))))))))
  9257. ;; Now loop over all markers and apply cmd
  9258. (while (setq e (pop entries))
  9259. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9260. (if (not pos)
  9261. (progn (message "Skipping removed entry at %s" e)
  9262. (setq cntskip (1+ cntskip)))
  9263. (goto-char pos)
  9264. (let (org-loop-over-headlines-in-active-region)
  9265. (eval cmd))
  9266. (setq cnt (1+ cnt))))
  9267. (when redo-at-end (org-agenda-redo))
  9268. (unless org-agenda-persistent-marks
  9269. (org-agenda-bulk-unmark-all))
  9270. (message "Acted on %d entries%s%s"
  9271. cnt
  9272. (if (= cntskip 0)
  9273. ""
  9274. (format ", skipped %d (disappeared before their turn)"
  9275. cntskip))
  9276. (if (not org-agenda-persistent-marks)
  9277. "" " (kept marked)"))))))
  9278. (defun org-agenda-capture (&optional with-time)
  9279. "Call `org-capture' with the date at point.
  9280. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9281. current HH:MM time."
  9282. (interactive "P")
  9283. (if (not (eq major-mode 'org-agenda-mode))
  9284. (user-error "You cannot do this outside of agenda buffers")
  9285. (let ((org-overriding-default-time
  9286. (org-get-cursor-date (equal with-time 1))))
  9287. (call-interactively 'org-capture))))
  9288. ;;; Dragging agenda lines forward/backward
  9289. (defun org-agenda-reapply-filters ()
  9290. "Re-apply all agenda filters."
  9291. (mapcar
  9292. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f))))
  9293. `((,org-agenda-tag-filter tag)
  9294. (,org-agenda-category-filter category)
  9295. (,org-agenda-regexp-filter regexp)
  9296. (,org-agenda-effort-filter effort)
  9297. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9298. (,(get 'org-agenda-category-filter :preset-filter) category)
  9299. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9300. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9301. (defun org-agenda-drag-line-forward (arg &optional backward)
  9302. "Drag an agenda line forward by ARG lines.
  9303. When the optional argument `backward' is non-nil, move backward."
  9304. (interactive "p")
  9305. (let ((inhibit-read-only t) lst line)
  9306. (if (or (not (get-text-property (point) 'txt))
  9307. (save-excursion
  9308. (dotimes (n arg)
  9309. (move-beginning-of-line (if backward 0 2))
  9310. (push (not (get-text-property (point) 'txt)) lst))
  9311. (delq nil lst)))
  9312. (message "Cannot move line forward")
  9313. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9314. (move-beginning-of-line 1)
  9315. (setq line (buffer-substring (point) end))
  9316. (delete-region (point) end)
  9317. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9318. (insert line)
  9319. (org-agenda-reapply-filters)
  9320. (org-agenda-mark-clocking-task)
  9321. (move-beginning-of-line 0)))))
  9322. (defun org-agenda-drag-line-backward (arg)
  9323. "Drag an agenda line backward by ARG lines."
  9324. (interactive "p")
  9325. (org-agenda-drag-line-forward arg t))
  9326. ;;; Flagging notes
  9327. (defun org-agenda-show-the-flagging-note ()
  9328. "Display the flagging note in the other window.
  9329. When called a second time in direct sequence, offer to remove the FLAGGING
  9330. tag and (if present) the flagging note."
  9331. (interactive)
  9332. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9333. (win (selected-window))
  9334. note heading newhead)
  9335. (unless hdmarker
  9336. (user-error "No linked entry at point"))
  9337. (if (and (eq this-command last-command)
  9338. (y-or-n-p "Unflag and remove any flagging note? "))
  9339. (progn
  9340. (org-agenda-remove-flag hdmarker)
  9341. (let ((win (get-buffer-window "*Flagging Note*")))
  9342. (and win (delete-window win)))
  9343. (message "Entry unflagged"))
  9344. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9345. (unless note
  9346. (user-error "No flagging note"))
  9347. (org-kill-new note)
  9348. (org-switch-to-buffer-other-window "*Flagging Note*")
  9349. (erase-buffer)
  9350. (insert note)
  9351. (goto-char (point-min))
  9352. (while (re-search-forward "\\\\n" nil t)
  9353. (replace-match "\n" t t))
  9354. (goto-char (point-min))
  9355. (select-window win)
  9356. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9357. (defun org-agenda-remove-flag (marker)
  9358. "Remove the FLAGGED tag and any flagging note in the entry."
  9359. (let (newhead)
  9360. (org-with-point-at marker
  9361. (org-toggle-tag "FLAGGED" 'off)
  9362. (org-entry-delete nil "THEFLAGGINGNOTE")
  9363. (setq newhead (org-get-heading)))
  9364. (org-agenda-change-all-lines newhead marker)
  9365. (message "Entry unflagged")))
  9366. (defun org-agenda-get-any-marker (&optional pos)
  9367. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9368. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9369. ;;; Appointment reminders
  9370. (defvar appt-time-msg-list) ; defined in appt.el
  9371. ;;;###autoload
  9372. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9373. "Activate appointments found in `org-agenda-files'.
  9374. With a \\[universal-argument] prefix, refresh the list of
  9375. appointments.
  9376. If FILTER is t, interactively prompt the user for a regular
  9377. expression, and filter out entries that don't match it.
  9378. If FILTER is a string, use this string as a regular expression
  9379. for filtering entries out.
  9380. If FILTER is a function, filter out entries against which
  9381. calling the function returns nil. This function takes one
  9382. argument: an entry from `org-agenda-get-day-entries'.
  9383. FILTER can also be an alist with the car of each cell being
  9384. either 'headline or 'category. For example:
  9385. '((headline \"IMPORTANT\")
  9386. (category \"Work\"))
  9387. will only add headlines containing IMPORTANT or headlines
  9388. belonging to the \"Work\" category.
  9389. ARGS are symbols indicating what kind of entries to consider.
  9390. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9391. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9392. and :timestamp entries. See the docstring of `org-diary' for
  9393. details and examples.
  9394. If an entry has a APPT_WARNTIME property, its value will be used
  9395. to override `appt-message-warning-time'."
  9396. (interactive "P")
  9397. (if refresh (setq appt-time-msg-list nil))
  9398. (if (eq filter t)
  9399. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9400. (let* ((cnt 0) ; count added events
  9401. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9402. (org-agenda-new-buffers nil)
  9403. (org-deadline-warning-days 0)
  9404. ;; Do not use `org-today' here because appt only takes
  9405. ;; time and without date as argument, so it may pass wrong
  9406. ;; information otherwise
  9407. (today (org-date-to-gregorian
  9408. (time-to-days (current-time))))
  9409. (org-agenda-restrict nil)
  9410. (files (org-agenda-files 'unrestricted)) entries file
  9411. (org-agenda-buffer nil))
  9412. ;; Get all entries which may contain an appt
  9413. (org-agenda-prepare-buffers files)
  9414. (while (setq file (pop files))
  9415. (setq entries
  9416. (delq nil
  9417. (append entries
  9418. (apply 'org-agenda-get-day-entries
  9419. file today scope)))))
  9420. ;; Map thru entries and find if we should filter them out
  9421. (mapc
  9422. (lambda(x)
  9423. (let* ((evt (org-trim
  9424. (replace-regexp-in-string
  9425. org-bracket-link-regexp "\\3"
  9426. (or (get-text-property 1 'txt x) ""))))
  9427. (cat (get-text-property (1- (length x)) 'org-category x))
  9428. (tod (get-text-property 1 'time-of-day x))
  9429. (ok (or (null filter)
  9430. (and (stringp filter) (string-match filter evt))
  9431. (and (functionp filter) (funcall filter x))
  9432. (and (listp filter)
  9433. (let ((cat-filter (cadr (assoc 'category filter)))
  9434. (evt-filter (cadr (assoc 'headline filter))))
  9435. (or (and (stringp cat-filter)
  9436. (string-match cat-filter cat))
  9437. (and (stringp evt-filter)
  9438. (string-match evt-filter evt)))))))
  9439. (wrn (get-text-property 1 'warntime x)))
  9440. ;; FIXME: Shall we remove text-properties for the appt text?
  9441. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9442. (when (and ok tod)
  9443. (setq tod (concat "00" (number-to-string tod))
  9444. tod (when (string-match
  9445. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9446. (concat (match-string 1 tod) ":"
  9447. (match-string 2 tod))))
  9448. (if (version< emacs-version "23.3")
  9449. (appt-add tod evt)
  9450. (appt-add tod evt wrn))
  9451. (setq cnt (1+ cnt))))) entries)
  9452. (org-release-buffers org-agenda-new-buffers)
  9453. (if (eq cnt 0)
  9454. (message "No event to add")
  9455. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9456. (defun org-agenda-todayp (date)
  9457. "Does DATE mean today, when considering `org-extend-today-until'?"
  9458. (let ((today (org-today))
  9459. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9460. date)))
  9461. (eq date today)))
  9462. (defun org-agenda-todo-yesterday (&optional arg)
  9463. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9464. (interactive "P")
  9465. (let* ((hour (third (decode-time
  9466. (org-current-time))))
  9467. (org-extend-today-until (1+ hour)))
  9468. (org-agenda-todo arg)))
  9469. (provide 'org-agenda)
  9470. ;;; org-agenda.el ends here