org-agenda.el 398 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2016 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-iso-to-absolute "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)
  80. (defvar org-clock-current-task)
  81. (defvar org-current-tag-alist)
  82. (defvar org-mobile-force-id-on-agenda-items)
  83. (defvar org-habit-show-habits)
  84. (defvar org-habit-show-habits-only-for-today)
  85. (defvar org-habit-show-all-today)
  86. ;; Defined somewhere in this file, but used before definition.
  87. (defvar org-agenda-buffer-name "*Org Agenda*")
  88. (defvar org-agenda-overriding-header nil)
  89. (defvar org-agenda-title-append nil)
  90. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  91. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  92. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  93. (defvar org-agenda-undo-list nil
  94. "List of undoable operations in the agenda since last refresh.")
  95. (defvar org-agenda-pending-undo-list nil
  96. "In a series of undo commands, this is the list of remaining undo items.")
  97. (defcustom org-agenda-confirm-kill 1
  98. "When set, remote killing from the agenda buffer needs confirmation.
  99. When t, a confirmation is always needed. When a number N, confirmation is
  100. only needed when the text to be killed contains more than N non-white lines."
  101. :group 'org-agenda
  102. :type '(choice
  103. (const :tag "Never" nil)
  104. (const :tag "Always" t)
  105. (integer :tag "When more than N lines")))
  106. (defcustom org-agenda-compact-blocks nil
  107. "Non-nil means make the block agenda more compact.
  108. This is done globally by leaving out lines like the agenda span
  109. name and week number or the separator lines."
  110. :group 'org-agenda
  111. :type 'boolean)
  112. (defcustom org-agenda-block-separator ?=
  113. "The separator between blocks in the agenda.
  114. If this is a string, it will be used as the separator, with a newline added.
  115. If it is a character, it will be repeated to fill the window width.
  116. If nil the separator is disabled. In `org-agenda-custom-commands' this
  117. addresses the separator between the current and the previous block."
  118. :group 'org-agenda
  119. :type '(choice
  120. (const :tag "Disabled" nil)
  121. (character)
  122. (string)))
  123. (defgroup org-agenda-export nil
  124. "Options concerning exporting agenda views in Org-mode."
  125. :tag "Org Agenda Export"
  126. :group 'org-agenda)
  127. (defcustom org-agenda-with-colors t
  128. "Non-nil means use colors in agenda views."
  129. :group 'org-agenda-export
  130. :type 'boolean)
  131. (defcustom org-agenda-exporter-settings nil
  132. "Alist of variable/value pairs that should be active during agenda export.
  133. This is a good place to set options for ps-print and for htmlize.
  134. Note that the way this is implemented, the values will be evaluated
  135. before assigned to the variables. So make sure to quote values you do
  136. *not* want evaluated, for example
  137. (setq org-agenda-exporter-settings
  138. \\='((ps-print-color-p \\='black-white)))"
  139. :group 'org-agenda-export
  140. :type '(repeat
  141. (list
  142. (variable)
  143. (sexp :tag "Value"))))
  144. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  145. "Hook run in a temporary buffer before writing the agenda to an export file.
  146. A useful function for this hook is `org-agenda-add-entry-text'."
  147. :group 'org-agenda-export
  148. :type 'hook
  149. :options '(org-agenda-add-entry-text))
  150. (defcustom org-agenda-add-entry-text-maxlines 0
  151. "Maximum number of entry text lines to be added to agenda.
  152. This is only relevant when `org-agenda-add-entry-text' is part of
  153. `org-agenda-before-write-hook', which is the default.
  154. When this is 0, nothing will happen. When it is greater than 0, it
  155. specifies the maximum number of lines that will be added for each entry
  156. that is listed in the agenda view.
  157. Note that this variable is not used during display, only when exporting
  158. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  159. and `org-agenda-entry-text-maxlines'."
  160. :group 'org-agenda
  161. :type 'integer)
  162. (defcustom org-agenda-add-entry-text-descriptive-links t
  163. "Non-nil means export org-links as descriptive links in agenda added text.
  164. This variable applies to the text added to the agenda when
  165. `org-agenda-add-entry-text-maxlines' is larger than 0.
  166. When this variable nil, the URL will (also) be shown."
  167. :group 'org-agenda
  168. :type 'boolean)
  169. (defcustom org-agenda-export-html-style nil
  170. "The style specification for exported HTML Agenda files.
  171. If this variable contains a string, it will replace the default <style>
  172. section as produced by `htmlize'.
  173. Since there are different ways of setting style information, this variable
  174. needs to contain the full HTML structure to provide a style, including the
  175. surrounding HTML tags. The style specifications should include definitions
  176. the fonts used by the agenda, here is an example:
  177. <style type=\"text/css\">
  178. p { font-weight: normal; color: gray; }
  179. .org-agenda-structure {
  180. font-size: 110%;
  181. color: #003399;
  182. font-weight: 600;
  183. }
  184. .org-todo {
  185. color: #cc6666;
  186. font-weight: bold;
  187. }
  188. .org-agenda-done {
  189. color: #339933;
  190. }
  191. .org-done {
  192. color: #339933;
  193. }
  194. .title { text-align: center; }
  195. .todo, .deadline { color: red; }
  196. .done { color: green; }
  197. </style>
  198. or, if you want to keep the style in a file,
  199. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  200. As the value of this option simply gets inserted into the HTML <head> header,
  201. you can \"misuse\" it to also add other text to the header."
  202. :group 'org-agenda-export
  203. :group 'org-export-html
  204. :type '(choice
  205. (const nil)
  206. (string)))
  207. (defcustom org-agenda-persistent-filter nil
  208. "When set, keep filters from one agenda view to the next."
  209. :group 'org-agenda
  210. :type 'boolean)
  211. (defgroup org-agenda-custom-commands nil
  212. "Options concerning agenda views in Org-mode."
  213. :tag "Org Agenda Custom Commands"
  214. :group 'org-agenda)
  215. (defconst org-sorting-choice
  216. '(choice
  217. (const time-up) (const time-down)
  218. (const timestamp-up) (const timestamp-down)
  219. (const scheduled-up) (const scheduled-down)
  220. (const deadline-up) (const deadline-down)
  221. (const ts-up) (const ts-down)
  222. (const tsia-up) (const tsia-down)
  223. (const category-keep) (const category-up) (const category-down)
  224. (const tag-down) (const tag-up)
  225. (const priority-up) (const priority-down)
  226. (const todo-state-up) (const todo-state-down)
  227. (const effort-up) (const effort-down)
  228. (const habit-up) (const habit-down)
  229. (const alpha-up) (const alpha-down)
  230. (const user-defined-up) (const user-defined-down))
  231. "Sorting choices.")
  232. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  233. ;; the new variable `org-agenda-tag-filter-preset'.
  234. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  235. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  236. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  237. "List of types searched for when creating the daily/weekly agenda.
  238. This variable is a list of symbols that controls the types of
  239. items that appear in the daily/weekly agenda. Allowed symbols in this
  240. list are are
  241. :timestamp List items containing a date stamp or date range matching
  242. the selected date. This includes sexp entries in angular
  243. brackets.
  244. :sexp List entries resulting from plain diary-like sexps.
  245. :deadline List deadline due on that date. When the date is today,
  246. also list any deadlines past due, or due within
  247. `org-deadline-warning-days'. `:deadline' must appear before
  248. `:scheduled' if the setting of
  249. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  250. any effect.
  251. :deadline* Same as above, but only include the deadline if it has an
  252. hour specification as [h]h:mm.
  253. :scheduled List all items which are scheduled for the given date.
  254. The diary for *today* also contains items which were
  255. scheduled earlier and are not yet marked DONE.
  256. :scheduled* Same as above, but only include the scheduled item if it
  257. has an hour specification as [h]h:mm.
  258. By default, all four non-starred types are turned on.
  259. When :scheduled* or :deadline* are included, :schedule or :deadline
  260. will be ignored.
  261. Never set this variable globally using `setq', because then it
  262. will apply to all future agenda commands. Instead, bind it with
  263. `let' to scope it dynamically into the agenda-constructing
  264. command. A good way to set it is through options in
  265. `org-agenda-custom-commands'. For a more flexible (though
  266. somewhat less efficient) way of determining what is included in
  267. the daily/weekly agenda, see `org-agenda-skip-function'.")
  268. (defconst org-agenda-custom-commands-local-options
  269. `(repeat :tag "Local settings for this command. Remember to quote values"
  270. (choice :tag "Setting"
  271. (list :tag "Heading for this block"
  272. (const org-agenda-overriding-header)
  273. (string :tag "Headline"))
  274. (list :tag "Files to be searched"
  275. (const org-agenda-files)
  276. (list
  277. (const :format "" quote)
  278. (repeat (file))))
  279. (list :tag "Sorting strategy"
  280. (const org-agenda-sorting-strategy)
  281. (list
  282. (const :format "" quote)
  283. (repeat
  284. ,org-sorting-choice)))
  285. (list :tag "Prefix format"
  286. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  287. (string))
  288. (list :tag "Number of days in agenda"
  289. (const org-agenda-span)
  290. (choice (const :tag "Day" day)
  291. (const :tag "Week" week)
  292. (const :tag "Fortnight" fortnight)
  293. (const :tag "Month" month)
  294. (const :tag "Year" year)
  295. (integer :tag "Custom")))
  296. (list :tag "Fixed starting date"
  297. (const org-agenda-start-day)
  298. (string :value "2007-11-01"))
  299. (list :tag "Start on day of week"
  300. (const org-agenda-start-on-weekday)
  301. (choice :value 1
  302. (const :tag "Today" nil)
  303. (integer :tag "Weekday No.")))
  304. (list :tag "Include data from diary"
  305. (const org-agenda-include-diary)
  306. (boolean))
  307. (list :tag "Deadline Warning days"
  308. (const org-deadline-warning-days)
  309. (integer :value 1))
  310. (list :tag "Category filter preset"
  311. (const org-agenda-category-filter-preset)
  312. (list
  313. (const :format "" quote)
  314. (repeat
  315. (string :tag "+category or -category"))))
  316. (list :tag "Tags filter preset"
  317. (const org-agenda-tag-filter-preset)
  318. (list
  319. (const :format "" quote)
  320. (repeat
  321. (string :tag "+tag or -tag"))))
  322. (list :tag "Effort filter preset"
  323. (const org-agenda-effort-filter-preset)
  324. (list
  325. (const :format "" quote)
  326. (repeat
  327. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  328. (list :tag "Regexp filter preset"
  329. (const org-agenda-regexp-filter-preset)
  330. (list
  331. (const :format "" quote)
  332. (repeat
  333. (string :tag "+regexp or -regexp"))))
  334. (list :tag "Set daily/weekly entry types"
  335. (const org-agenda-entry-types)
  336. (list
  337. (const :format "" quote)
  338. (set :greedy t :value ,org-agenda-entry-types
  339. (const :deadline)
  340. (const :scheduled)
  341. (const :deadline*)
  342. (const :scheduled*)
  343. (const :timestamp)
  344. (const :sexp))))
  345. (list :tag "Standard skipping condition"
  346. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  347. (const org-agenda-skip-function)
  348. (list
  349. (const :format "" quote)
  350. (list
  351. (choice
  352. :tag "Skipping range"
  353. (const :tag "Skip entry" org-agenda-skip-entry-if)
  354. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  355. (repeat :inline t :tag "Conditions for skipping"
  356. (choice
  357. :tag "Condition type"
  358. (list :tag "Regexp matches" :inline t
  359. (const :format "" 'regexp)
  360. (regexp))
  361. (list :tag "Regexp does not match" :inline t
  362. (const :format "" 'notregexp)
  363. (regexp))
  364. (list :tag "TODO state is" :inline t
  365. (const 'todo)
  366. (choice
  367. (const :tag "Any not-done state" 'todo)
  368. (const :tag "Any done state" 'done)
  369. (const :tag "Any state" 'any)
  370. (list :tag "Keyword list"
  371. (const :format "" quote)
  372. (repeat (string :tag "Keyword")))))
  373. (list :tag "TODO state is not" :inline t
  374. (const 'nottodo)
  375. (choice
  376. (const :tag "Any not-done state" 'todo)
  377. (const :tag "Any done state" 'done)
  378. (const :tag "Any state" 'any)
  379. (list :tag "Keyword list"
  380. (const :format "" quote)
  381. (repeat (string :tag "Keyword")))))
  382. (const :tag "scheduled" 'scheduled)
  383. (const :tag "not scheduled" 'notscheduled)
  384. (const :tag "deadline" 'deadline)
  385. (const :tag "no deadline" 'notdeadline)
  386. (const :tag "timestamp" 'timestamp)
  387. (const :tag "no timestamp" 'nottimestamp))))))
  388. (list :tag "Non-standard skipping condition"
  389. :value (org-agenda-skip-function)
  390. (const org-agenda-skip-function)
  391. (sexp :tag "Function or form (quoted!)"))
  392. (list :tag "Any variable"
  393. (variable :tag "Variable")
  394. (sexp :tag "Value (sexp)"))))
  395. "Selection of examples for agenda command settings.
  396. This will be spliced into the custom type of
  397. `org-agenda-custom-commands'.")
  398. (defcustom org-agenda-custom-commands
  399. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  400. "Custom commands for the agenda.
  401. These commands will be offered on the splash screen displayed by the
  402. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  403. (key desc type match settings files)
  404. key The key (one or more characters as a string) to be associated
  405. with the command.
  406. desc A description of the command, when omitted or nil, a default
  407. description is built using MATCH.
  408. type The command type, any of the following symbols:
  409. agenda The daily/weekly agenda.
  410. todo Entries with a specific TODO keyword, in all agenda files.
  411. search Entries containing search words entry or headline.
  412. tags Tags/Property/TODO match in all agenda files.
  413. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  414. todo-tree Sparse tree of specific TODO keyword in *current* file.
  415. tags-tree Sparse tree with all tags matches in *current* file.
  416. occur-tree Occur sparse tree for *current* file.
  417. ... A user-defined function.
  418. match What to search for:
  419. - a single keyword for TODO keyword searches
  420. - a tags match expression for tags searches
  421. - a word search expression for text searches.
  422. - a regular expression for occur searches
  423. For all other commands, this should be the empty string.
  424. settings A list of option settings, similar to that in a let form, so like
  425. this: ((opt1 val1) (opt2 val2) ...). The values will be
  426. evaluated at the moment of execution, so quote them when needed.
  427. files A list of files file to write the produced agenda buffer to
  428. with the command `org-store-agenda-views'.
  429. If a file name ends in \".html\", an HTML version of the buffer
  430. is written out. If it ends in \".ps\", a postscript version is
  431. produced. Otherwise, only the plain text is written to the file.
  432. You can also define a set of commands, to create a composite agenda buffer.
  433. In this case, an entry looks like this:
  434. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  435. where
  436. desc A description string to be displayed in the dispatcher menu.
  437. cmd An agenda command, similar to the above. However, tree commands
  438. are not allowed, but instead you can get agenda and global todo list.
  439. So valid commands for a set are:
  440. (agenda \"\" settings)
  441. (alltodo \"\" settings)
  442. (stuck \"\" settings)
  443. (todo \"match\" settings files)
  444. (search \"match\" settings files)
  445. (tags \"match\" settings files)
  446. (tags-todo \"match\" settings files)
  447. Each command can carry a list of options, and another set of options can be
  448. given for the whole set of commands. Individual command options take
  449. precedence over the general options.
  450. When using several characters as key to a command, the first characters
  451. are prefix commands. For the dispatcher to display useful information, you
  452. should provide a description for the prefix, like
  453. (setq org-agenda-custom-commands
  454. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  455. (\"hl\" tags \"+HOME+Lisa\")
  456. (\"hp\" tags \"+HOME+Peter\")
  457. (\"hk\" tags \"+HOME+Kim\")))"
  458. :group 'org-agenda-custom-commands
  459. :type `(repeat
  460. (choice :value ("x" "Describe command here" tags "" nil)
  461. (list :tag "Single command"
  462. (string :tag "Access Key(s) ")
  463. (option (string :tag "Description"))
  464. (choice
  465. (const :tag "Agenda" agenda)
  466. (const :tag "TODO list" alltodo)
  467. (const :tag "Search words" search)
  468. (const :tag "Stuck projects" stuck)
  469. (const :tag "Tags/Property match (all agenda files)" tags)
  470. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  471. (const :tag "TODO keyword search (all agenda files)" todo)
  472. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  473. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  474. (const :tag "Occur tree (current buffer)" occur-tree)
  475. (sexp :tag "Other, user-defined function"))
  476. (string :tag "Match (only for some commands)")
  477. ,org-agenda-custom-commands-local-options
  478. (option (repeat :tag "Export" (file :tag "Export to"))))
  479. (list :tag "Command series, all agenda files"
  480. (string :tag "Access Key(s)")
  481. (string :tag "Description ")
  482. (repeat :tag "Component"
  483. (choice
  484. (list :tag "Agenda"
  485. (const :format "" agenda)
  486. (const :tag "" :format "" "")
  487. ,org-agenda-custom-commands-local-options)
  488. (list :tag "TODO list (all keywords)"
  489. (const :format "" alltodo)
  490. (const :tag "" :format "" "")
  491. ,org-agenda-custom-commands-local-options)
  492. (list :tag "Search words"
  493. (const :format "" search)
  494. (string :tag "Match")
  495. ,org-agenda-custom-commands-local-options)
  496. (list :tag "Stuck projects"
  497. (const :format "" stuck)
  498. (const :tag "" :format "" "")
  499. ,org-agenda-custom-commands-local-options)
  500. (list :tag "Tags search"
  501. (const :format "" tags)
  502. (string :tag "Match")
  503. ,org-agenda-custom-commands-local-options)
  504. (list :tag "Tags search, TODO entries only"
  505. (const :format "" tags-todo)
  506. (string :tag "Match")
  507. ,org-agenda-custom-commands-local-options)
  508. (list :tag "TODO keyword search"
  509. (const :format "" todo)
  510. (string :tag "Match")
  511. ,org-agenda-custom-commands-local-options)
  512. (list :tag "Other, user-defined function"
  513. (symbol :tag "function")
  514. (string :tag "Match")
  515. ,org-agenda-custom-commands-local-options)))
  516. (repeat :tag "Settings for entire command set"
  517. (list (variable :tag "Any variable")
  518. (sexp :tag "Value")))
  519. (option (repeat :tag "Export" (file :tag "Export to"))))
  520. (cons :tag "Prefix key documentation"
  521. (string :tag "Access Key(s)")
  522. (string :tag "Description ")))))
  523. (defcustom org-agenda-query-register ?o
  524. "The register holding the current query string.
  525. The purpose of this is that if you construct a query string interactively,
  526. you can then use it to define a custom command."
  527. :group 'org-agenda-custom-commands
  528. :type 'character)
  529. (defcustom org-stuck-projects
  530. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  531. "How to identify stuck projects.
  532. This is a list of four items:
  533. 1. A tags/todo/property matcher string that is used to identify a project.
  534. See the manual for a description of tag and property searches.
  535. The entire tree below a headline matched by this is considered one project.
  536. 2. A list of TODO keywords identifying non-stuck projects.
  537. If the project subtree contains any headline with one of these todo
  538. keywords, the project is considered to be not stuck. If you specify
  539. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  540. 3. A list of tags identifying non-stuck projects.
  541. If the project subtree contains any headline with one of these tags,
  542. the project is considered to be not stuck. If you specify \"*\" as
  543. a tag, any tag will mark the project unstuck. Note that this is about
  544. the explicit presence of a tag somewhere in the subtree, inherited
  545. tags do not count here. If inherited tags make a project not stuck,
  546. use \"-TAG\" in the tags part of the matcher under (1.) above.
  547. 4. An arbitrary regular expression matching non-stuck projects.
  548. If the project turns out to be not stuck, search continues also in the
  549. subtree to see if any of the subtasks have project status.
  550. See also the variable `org-tags-match-list-sublevels' which applies
  551. to projects matched by this search as well.
  552. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  553. or `C-c a #' to produce the list."
  554. :group 'org-agenda-custom-commands
  555. :type '(list
  556. (string :tag "Tags/TODO match to identify a project")
  557. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  558. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  559. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  560. (defgroup org-agenda-skip nil
  561. "Options concerning skipping parts of agenda files."
  562. :tag "Org Agenda Skip"
  563. :group 'org-agenda)
  564. (defcustom org-agenda-skip-function-global nil
  565. "Function to be called at each match during agenda construction.
  566. If this function returns nil, the current match should not be skipped.
  567. If the function decided to skip an agenda match, is must return the
  568. buffer position from which the search should be continued.
  569. This may also be a Lisp form, which will be evaluated.
  570. This variable will be applied to every agenda match, including
  571. tags/property searches and TODO lists. So try to make the test function
  572. do its checking as efficiently as possible. To implement a skipping
  573. condition just for specific agenda commands, use the variable
  574. `org-agenda-skip-function' which can be set in the options section
  575. of custom agenda commands."
  576. :group 'org-agenda-skip
  577. :type 'sexp)
  578. (defgroup org-agenda-daily/weekly nil
  579. "Options concerning the daily/weekly agenda."
  580. :tag "Org Agenda Daily/Weekly"
  581. :group 'org-agenda)
  582. (defgroup org-agenda-todo-list nil
  583. "Options concerning the global todo list agenda view."
  584. :tag "Org Agenda Todo List"
  585. :group 'org-agenda)
  586. (defgroup org-agenda-match-view nil
  587. "Options concerning the general tags/property/todo match agenda view."
  588. :tag "Org Agenda Match View"
  589. :group 'org-agenda)
  590. (defgroup org-agenda-search-view nil
  591. "Options concerning the search agenda view."
  592. :tag "Org Agenda Search View"
  593. :group 'org-agenda)
  594. (defvar org-agenda-archives-mode nil
  595. "Non-nil means the agenda will include archived items.
  596. If this is the symbol `trees', trees in the selected agenda scope
  597. that are marked with the ARCHIVE tag will be included anyway. When this is
  598. t, also all archive files associated with the current selection of agenda
  599. files will be included.")
  600. (defcustom org-agenda-restriction-lock-highlight-subtree t
  601. "Non-nil means highlight the whole subtree when restriction is active.
  602. Otherwise only highlight the headline. Highlighting the whole subtree is
  603. useful to ensure no edits happen beyond the restricted region."
  604. :group 'org-agenda
  605. :type 'boolean)
  606. (defcustom org-agenda-skip-comment-trees t
  607. "Non-nil means skip trees that start with the COMMENT keyword.
  608. When nil, these trees are also scanned by agenda commands."
  609. :group 'org-agenda-skip
  610. :type 'boolean)
  611. (defcustom org-agenda-todo-list-sublevels t
  612. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  613. When nil, the sublevels of a TODO entry are not checked, resulting in
  614. potentially much shorter TODO lists."
  615. :group 'org-agenda-skip
  616. :group 'org-agenda-todo-list
  617. :type 'boolean)
  618. (defcustom org-agenda-todo-ignore-with-date nil
  619. "Non-nil means don't show entries with a date in the global todo list.
  620. You can use this if you prefer to mark mere appointments with a TODO keyword,
  621. but don't want them to show up in the TODO list.
  622. When this is set, it also covers deadlines and scheduled items, the settings
  623. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  624. will be ignored.
  625. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  626. :group 'org-agenda-skip
  627. :group 'org-agenda-todo-list
  628. :type 'boolean)
  629. (defcustom org-agenda-todo-ignore-timestamp nil
  630. "Non-nil means don't show entries with a timestamp.
  631. This applies when creating the global todo list.
  632. Valid values are:
  633. past Don't show entries for today or in the past.
  634. future Don't show entries with a timestamp in the future.
  635. The idea behind this is that if it has a future
  636. timestamp, you don't want to think about it until the
  637. date.
  638. all Don't show any entries with a timestamp in the global todo list.
  639. The idea behind this is that by setting a timestamp, you
  640. have already \"taken care\" of this item.
  641. This variable can also have an integer as a value. If positive (N),
  642. todos with a timestamp N or more days in the future will be ignored. If
  643. negative (-N), todos with a timestamp N or more days in the past will be
  644. ignored. If 0, todos with a timestamp either today or in the future will
  645. be ignored. For example, a value of -1 will exclude todos with a
  646. timestamp in the past (yesterday or earlier), while a value of 7 will
  647. exclude todos with a timestamp a week or more in the future.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :version "24.1"
  654. :type '(choice
  655. (const :tag "Ignore future timestamp todos" future)
  656. (const :tag "Ignore past or present timestamp todos" past)
  657. (const :tag "Ignore all timestamp todos" all)
  658. (const :tag "Show timestamp todos" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-scheduled nil
  661. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  662. This applies when creating the global todo list.
  663. Valid values are:
  664. past Don't show entries scheduled today or in the past.
  665. future Don't show entries scheduled in the future.
  666. The idea behind this is that by scheduling it, you don't want to
  667. think about it until the scheduled date.
  668. all Don't show any scheduled entries in the global todo list.
  669. The idea behind this is that by scheduling it, you have already
  670. \"taken care\" of this item.
  671. t Same as `all', for backward compatibility.
  672. This variable can also have an integer as a value. See
  673. `org-agenda-todo-ignore-timestamp' for more details.
  674. See also `org-agenda-todo-ignore-with-date'.
  675. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  676. to make his option also apply to the tags-todo list."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-todo-list
  679. :type '(choice
  680. (const :tag "Ignore future-scheduled todos" future)
  681. (const :tag "Ignore past- or present-scheduled todos" past)
  682. (const :tag "Ignore all scheduled todos" all)
  683. (const :tag "Ignore all scheduled todos (compatibility)" t)
  684. (const :tag "Show scheduled todos" nil)
  685. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  686. (defcustom org-agenda-todo-ignore-deadlines nil
  687. "Non-nil means ignore some deadline TODO items when making TODO list.
  688. There are different motivations for using different values, please think
  689. carefully when configuring this variable.
  690. This applies when creating the global todo list.
  691. Valid values are:
  692. near Don't show near deadline entries. A deadline is near when it is
  693. closer than `org-deadline-warning-days' days. The idea behind this
  694. is that such items will appear in the agenda anyway.
  695. far Don't show TODO entries where a deadline has been defined, but
  696. the deadline is not near. This is useful if you don't want to
  697. use the todo list to figure out what to do now.
  698. past Don't show entries with a deadline timestamp for today or in the past.
  699. future Don't show entries with a deadline timestamp in the future, not even
  700. when they become `near' ones. Use it with caution.
  701. all Ignore all TODO entries that do have a deadline.
  702. t Same as `near', for backward compatibility.
  703. This variable can also have an integer as a value. See
  704. `org-agenda-todo-ignore-timestamp' for more details.
  705. See also `org-agenda-todo-ignore-with-date'.
  706. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  707. to make his option also apply to the tags-todo list."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Ignore near deadlines" near)
  712. (const :tag "Ignore near deadlines (compatibility)" t)
  713. (const :tag "Ignore far deadlines" far)
  714. (const :tag "Ignore all TODOs with a deadlines" all)
  715. (const :tag "Show all TODOs, even if they have a deadline" nil)
  716. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  717. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  718. "Time unit to use when possibly ignoring an agenda item.
  719. See the docstring of various `org-agenda-todo-ignore-*' options.
  720. The default is to compare time stamps using days. An item is thus
  721. considered to be in the future if it is at least one day after today.
  722. Non-nil means to compare time stamps using seconds. An item is then
  723. considered future if it has a time value later than current time."
  724. :group 'org-agenda-skip
  725. :group 'org-agenda-todo-list
  726. :version "24.4"
  727. :package-version '(Org . "8.0")
  728. :type '(choice
  729. (const :tag "Compare time with days" nil)
  730. (const :tag "Compare time with seconds" t)))
  731. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  732. "Non-nil means honor todo-list ignores options also in tags-todo search.
  733. The variables
  734. `org-agenda-todo-ignore-with-date',
  735. `org-agenda-todo-ignore-timestamp',
  736. `org-agenda-todo-ignore-scheduled',
  737. `org-agenda-todo-ignore-deadlines'
  738. make the global TODO list skip entries that have time stamps of certain
  739. kinds. If this option is set, the same options will also apply for the
  740. tags-todo search, which is the general tags/property matcher
  741. restricted to unfinished TODO entries only."
  742. :group 'org-agenda-skip
  743. :group 'org-agenda-todo-list
  744. :group 'org-agenda-match-view
  745. :type 'boolean)
  746. (defcustom org-agenda-skip-scheduled-if-done nil
  747. "Non-nil means don't show scheduled items in agenda when they are done.
  748. This is relevant for the daily/weekly agenda, not for the TODO list. And
  749. it applies only to the actual date of the scheduling. Warnings about
  750. an item with a past scheduling dates are always turned off when the item
  751. is DONE."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-daily/weekly
  754. :type 'boolean)
  755. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  756. "Non-nil means skip scheduling line if same entry shows because of deadline.
  757. In the agenda of today, an entry can show up multiple times
  758. because it is both scheduled and has a nearby deadline, and maybe
  759. a plain time stamp as well.
  760. When this variable is nil, the entry will be shown several times.
  761. When set to t, then only the deadline is shown and the fact that
  762. the entry is scheduled today or was scheduled previously is not
  763. shown.
  764. When set to the symbol `not-today', skip scheduled previously,
  765. but not scheduled today.
  766. When set to the symbol `repeated-after-deadline', skip scheduled
  767. items if they are repeated beyond the current deadline."
  768. :group 'org-agenda-skip
  769. :group 'org-agenda-daily/weekly
  770. :type '(choice
  771. (const :tag "Never" nil)
  772. (const :tag "Always" t)
  773. (const :tag "Not when scheduled today" not-today)
  774. (const :tag "When repeated past deadline" repeated-after-deadline)))
  775. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  776. "Non-nil means skip timestamp line if same entry shows because of deadline.
  777. In the agenda of today, an entry can show up multiple times
  778. because it has both a plain timestamp and has a nearby deadline.
  779. When this variable is t, then only the deadline is shown and the
  780. fact that the entry has a timestamp for or including today is not
  781. shown. When this variable is nil, the entry will be shown
  782. several times."
  783. :group 'org-agenda-skip
  784. :group 'org-agenda-daily/weekly
  785. :version "24.1"
  786. :type '(choice
  787. (const :tag "Never" nil)
  788. (const :tag "Always" t)))
  789. (defcustom org-agenda-skip-deadline-if-done nil
  790. "Non-nil means don't show deadlines when the corresponding item is done.
  791. When nil, the deadline is still shown and should give you a happy feeling.
  792. This is relevant for the daily/weekly agenda. And it applied only to the
  793. actually date of the deadline. Warnings about approaching and past-due
  794. deadlines are always turned off when the item is DONE."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :type 'boolean)
  798. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  799. "Non-nil means skip deadline prewarning when entry is also scheduled.
  800. This will apply on all days where a prewarning for the deadline would
  801. be shown, but not at the day when the entry is actually due. On that day,
  802. the deadline will be shown anyway.
  803. This variable may be set to nil, t, the symbol `pre-scheduled',
  804. or a number which will then give the number of days before the actual
  805. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  806. eliminates the deadline prewarning only prior to the scheduled date.
  807. This can be used in a workflow where the first showing of the deadline will
  808. trigger you to schedule it, and then you don't want to be reminded of it
  809. because you will take care of it on the day when scheduled."
  810. :group 'org-agenda-skip
  811. :group 'org-agenda-daily/weekly
  812. :version "24.1"
  813. :type '(choice
  814. (const :tag "Always show prewarning" nil)
  815. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  816. (const :tag "Remove prewarning if entry is scheduled" t)
  817. (integer :tag "Restart prewarning N days before deadline")))
  818. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  819. "Non-nil means skip scheduled delay when entry also has a deadline.
  820. This variable may be set to nil, t, the symbol `post-deadline',
  821. or a number which will then give the number of days after the actual
  822. scheduled date when the delay should expire. The symbol `post-deadline'
  823. eliminates the schedule delay when the date is posterior to the deadline."
  824. :group 'org-agenda-skip
  825. :group 'org-agenda-daily/weekly
  826. :version "24.4"
  827. :package-version '(Org . "8.0")
  828. :type '(choice
  829. (const :tag "Always honor delay" nil)
  830. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  831. (const :tag "Ignore delay if entry has a deadline" t)
  832. (integer :tag "Honor delay up until N days after the scheduled date")))
  833. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  834. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  835. When non-nil, after the search for timestamps has matched once in an
  836. entry, the rest of the entry will not be searched."
  837. :group 'org-agenda-skip
  838. :type 'boolean)
  839. (defcustom org-agenda-skip-timestamp-if-done nil
  840. "Non-nil means don't select item by timestamp or -range if it is DONE."
  841. :group 'org-agenda-skip
  842. :group 'org-agenda-daily/weekly
  843. :type 'boolean)
  844. (defcustom org-agenda-dim-blocked-tasks t
  845. "Non-nil means dim blocked tasks in the agenda display.
  846. This causes some overhead during agenda construction, but if you
  847. have turned on `org-enforce-todo-dependencies',
  848. `org-enforce-todo-checkbox-dependencies', or any other blocking
  849. mechanism, this will create useful feedback in the agenda.
  850. Instead of t, this variable can also have the value `invisible'.
  851. Then blocked tasks will be invisible and only become visible when
  852. they become unblocked. An exemption to this behavior is when a task is
  853. blocked because of unchecked checkboxes below it. Since checkboxes do
  854. not show up in the agenda views, making this task invisible you remove any
  855. trace from agenda views that there is something to do. Therefore, a task
  856. that is blocked because of checkboxes will never be made invisible, it
  857. will only be dimmed."
  858. :group 'org-agenda-daily/weekly
  859. :group 'org-agenda-todo-list
  860. :version "24.3"
  861. :type '(choice
  862. (const :tag "Do not dim" nil)
  863. (const :tag "Dim to a gray face" t)
  864. (const :tag "Make invisible" invisible)))
  865. (defcustom org-timeline-show-empty-dates 3
  866. "Non-nil means `org-timeline' also shows dates without an entry.
  867. When nil, only the days which actually have entries are shown.
  868. When t, all days between the first and the last date are shown.
  869. When an integer, show also empty dates, but if there is a gap of more than
  870. N days, just insert a special line indicating the size of the gap."
  871. :group 'org-agenda-skip
  872. :type '(choice
  873. (const :tag "None" nil)
  874. (const :tag "All" t)
  875. (integer :tag "at most")))
  876. (defgroup org-agenda-startup nil
  877. "Options concerning initial settings in the Agenda in Org Mode."
  878. :tag "Org Agenda Startup"
  879. :group 'org-agenda)
  880. (defcustom org-agenda-menu-show-matcher t
  881. "Non-nil means show the match string in the agenda dispatcher menu.
  882. When nil, the matcher string is not shown, but is put into the help-echo
  883. property so than moving the mouse over the command shows it.
  884. Setting it to nil is good if matcher strings are very long and/or if
  885. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  886. :group 'org-agenda
  887. :version "24.1"
  888. :type 'boolean)
  889. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  890. (defcustom org-agenda-menu-two-columns nil
  891. "Non-nil means, use two columns to show custom commands in the dispatcher.
  892. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  893. to nil."
  894. :group 'org-agenda
  895. :version "24.1"
  896. :type 'boolean)
  897. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  898. (defcustom org-agenda-finalize-hook nil
  899. "Hook run just before displaying an agenda buffer.
  900. The buffer is still writable when the hook is called.
  901. You can modify some of the buffer substrings but you should be
  902. extra careful not to modify the text properties of the agenda
  903. headlines as the agenda display heavily relies on them."
  904. :group 'org-agenda-startup
  905. :type 'hook)
  906. (defcustom org-agenda-mouse-1-follows-link nil
  907. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  908. A longer mouse click will still set point. Does not work on XEmacs.
  909. Needs to be set before org.el is loaded."
  910. :group 'org-agenda-startup
  911. :type 'boolean)
  912. (defcustom org-agenda-start-with-follow-mode nil
  913. "The initial value of follow mode in a newly created agenda window."
  914. :group 'org-agenda-startup
  915. :type 'boolean)
  916. (defcustom org-agenda-follow-indirect nil
  917. "Non-nil means `org-agenda-follow-mode' displays only the
  918. current item's tree, in an indirect buffer."
  919. :group 'org-agenda
  920. :version "24.1"
  921. :type 'boolean)
  922. (defcustom org-agenda-show-outline-path t
  923. "Non-nil means show outline path in echo area after line motion."
  924. :group 'org-agenda-startup
  925. :type 'boolean)
  926. (defcustom org-agenda-start-with-entry-text-mode nil
  927. "The initial value of entry-text-mode in a newly created agenda window."
  928. :group 'org-agenda-startup
  929. :type 'boolean)
  930. (defcustom org-agenda-entry-text-maxlines 5
  931. "Number of text lines to be added when `E' is pressed in the agenda.
  932. Note that this variable only used during agenda display. Add add entry text
  933. when exporting the agenda, configure the variable
  934. `org-agenda-add-entry-ext-maxlines'."
  935. :group 'org-agenda
  936. :type 'integer)
  937. (defcustom org-agenda-entry-text-exclude-regexps nil
  938. "List of regular expressions to clean up entry text.
  939. The complete matches of all regular expressions in this list will be
  940. removed from entry text before it is shown in the agenda."
  941. :group 'org-agenda
  942. :type '(repeat (regexp)))
  943. (defcustom org-agenda-entry-text-leaders " > "
  944. "Text prepended to the entry text in agenda buffers."
  945. :version "24.4"
  946. :package-version '(Org . "8.0")
  947. :group 'org-agenda
  948. :type 'string)
  949. (defvar org-agenda-entry-text-cleanup-hook nil
  950. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  951. This cleanup is done in a temporary buffer, so the function may inspect and
  952. change the entire buffer.
  953. Some default stuff like drawers and scheduling/deadline dates will already
  954. have been removed when this is called, as will any matches for regular
  955. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  956. (defvar org-agenda-include-inactive-timestamps nil
  957. "Non-nil means include inactive time stamps in agenda and timeline.
  958. Dynamically scoped.")
  959. (defgroup org-agenda-windows nil
  960. "Options concerning the windows used by the Agenda in Org Mode."
  961. :tag "Org Agenda Windows"
  962. :group 'org-agenda)
  963. (defcustom org-agenda-window-setup 'reorganize-frame
  964. "How the agenda buffer should be displayed.
  965. Possible values for this option are:
  966. current-window Show agenda in the current window, keeping all other windows.
  967. other-window Use `switch-to-buffer-other-window' to display agenda.
  968. only-window Show agenda, deleting all other windows.
  969. reorganize-frame Show only two windows on the current frame, the current
  970. window and the agenda.
  971. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  972. Also, when exiting the agenda, kill that frame.
  973. See also the variable `org-agenda-restore-windows-after-quit'."
  974. :group 'org-agenda-windows
  975. :type '(choice
  976. (const current-window)
  977. (const other-frame)
  978. (const other-window)
  979. (const only-window)
  980. (const reorganize-frame)))
  981. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  982. "The min and max height of the agenda window as a fraction of frame height.
  983. The value of the variable is a cons cell with two numbers between 0 and 1.
  984. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  985. :group 'org-agenda-windows
  986. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  987. (defcustom org-agenda-restore-windows-after-quit nil
  988. "Non-nil means restore window configuration upon exiting agenda.
  989. Before the window configuration is changed for displaying the agenda,
  990. the current status is recorded. When the agenda is exited with
  991. `q' or `x' and this option is set, the old state is restored. If
  992. `org-agenda-window-setup' is `other-frame', the value of this
  993. option will be ignored."
  994. :group 'org-agenda-windows
  995. :type 'boolean)
  996. (defcustom org-agenda-ndays nil
  997. "Number of days to include in overview display.
  998. Should be 1 or 7.
  999. Obsolete, see `org-agenda-span'."
  1000. :group 'org-agenda-daily/weekly
  1001. :type '(choice (const nil)
  1002. (integer)))
  1003. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  1004. (defcustom org-agenda-span 'week
  1005. "Number of days to include in overview display.
  1006. Can be day, week, month, year, or any number of days.
  1007. Custom commands can set this variable in the options section."
  1008. :group 'org-agenda-daily/weekly
  1009. :type '(choice (const :tag "Day" day)
  1010. (const :tag "Week" week)
  1011. (const :tag "Fortnight" fortnight)
  1012. (const :tag "Month" month)
  1013. (const :tag "Year" year)
  1014. (integer :tag "Custom")))
  1015. (defcustom org-agenda-start-on-weekday 1
  1016. "Non-nil means start the overview always on the specified weekday.
  1017. 0 denotes Sunday, 1 denotes Monday, etc.
  1018. When nil, always start on the current day.
  1019. Custom commands can set this variable in the options section."
  1020. :group 'org-agenda-daily/weekly
  1021. :type '(choice (const :tag "Today" nil)
  1022. (integer :tag "Weekday No.")))
  1023. (defcustom org-agenda-show-all-dates t
  1024. "Non-nil means `org-agenda' shows every day in the selected range.
  1025. When nil, only the days which actually have entries are shown."
  1026. :group 'org-agenda-daily/weekly
  1027. :type 'boolean)
  1028. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1029. "Format string for displaying dates in the agenda.
  1030. Used by the daily/weekly agenda and by the timeline. This should be
  1031. a format string understood by `format-time-string', or a function returning
  1032. the formatted date as a string. The function must take a single argument,
  1033. a calendar-style date list like (month day year)."
  1034. :group 'org-agenda-daily/weekly
  1035. :type '(choice
  1036. (string :tag "Format string")
  1037. (function :tag "Function")))
  1038. (defun org-agenda-format-date-aligned (date)
  1039. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1040. This function makes sure that dates are aligned for easy reading."
  1041. (require 'cal-iso)
  1042. (let* ((dayname (calendar-day-name date))
  1043. (day (cadr date))
  1044. (day-of-week (calendar-day-of-week date))
  1045. (month (car date))
  1046. (monthname (calendar-month-name month))
  1047. (year (nth 2 date))
  1048. (iso-week (org-days-to-iso-week
  1049. (calendar-absolute-from-gregorian date)))
  1050. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1051. (1- year))
  1052. ((and (= month 12) (<= iso-week 1))
  1053. (1+ year))
  1054. (t year)))
  1055. (weekstring (if (= day-of-week 1)
  1056. (format " W%02d" iso-week)
  1057. "")))
  1058. (format "%-10s %2d %s %4d%s"
  1059. dayname day monthname year weekstring)))
  1060. (defcustom org-agenda-time-leading-zero nil
  1061. "Non-nil means use leading zero for military times in agenda.
  1062. For example, 9:30am would become 09:30 rather than 9:30."
  1063. :group 'org-agenda-daily/weekly
  1064. :version "24.1"
  1065. :type 'boolean)
  1066. (defcustom org-agenda-timegrid-use-ampm nil
  1067. "When set, show AM/PM style timestamps on the timegrid."
  1068. :group 'org-agenda
  1069. :version "24.1"
  1070. :type 'boolean)
  1071. (defun org-agenda-time-of-day-to-ampm (time)
  1072. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1073. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1074. (minute (substring time -2))
  1075. (ampm "am"))
  1076. (cond
  1077. ((equal hour-number 12)
  1078. (setq ampm "pm"))
  1079. ((> hour-number 12)
  1080. (setq ampm "pm")
  1081. (setq hour-number (- hour-number 12))))
  1082. (concat
  1083. (if org-agenda-time-leading-zero
  1084. (format "%02d" hour-number)
  1085. (format "%02s" (number-to-string hour-number)))
  1086. ":" minute ampm)))
  1087. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1088. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1089. (if org-agenda-timegrid-use-ampm
  1090. (org-agenda-time-of-day-to-ampm time)
  1091. time))
  1092. (defcustom org-agenda-weekend-days '(6 0)
  1093. "Which days are weekend?
  1094. These days get the special face `org-agenda-date-weekend' in the agenda
  1095. and timeline buffers."
  1096. :group 'org-agenda-daily/weekly
  1097. :type '(set :greedy t
  1098. (const :tag "Monday" 1)
  1099. (const :tag "Tuesday" 2)
  1100. (const :tag "Wednesday" 3)
  1101. (const :tag "Thursday" 4)
  1102. (const :tag "Friday" 5)
  1103. (const :tag "Saturday" 6)
  1104. (const :tag "Sunday" 0)))
  1105. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1106. "Non-nil means jump to today when moving a past date forward in time.
  1107. When using S-right in the agenda to move a a date forward, and the date
  1108. stamp currently points to the past, the first key press will move it
  1109. to today. WHen nil, just move one day forward even if the date stays
  1110. in the past."
  1111. :group 'org-agenda-daily/weekly
  1112. :version "24.1"
  1113. :type 'boolean)
  1114. (defcustom org-agenda-include-diary nil
  1115. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1116. Custom commands can set this variable in the options section."
  1117. :group 'org-agenda-daily/weekly
  1118. :type 'boolean)
  1119. (defcustom org-agenda-include-deadlines t
  1120. "If non-nil, include entries within their deadline warning period.
  1121. Custom commands can set this variable in the options section."
  1122. :group 'org-agenda-daily/weekly
  1123. :version "24.1"
  1124. :type 'boolean)
  1125. (defcustom org-agenda-repeating-timestamp-show-all t
  1126. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1127. When set to a list of strings, only show occurrences of repeating
  1128. stamps for these TODO keywords. When nil, only one occurrence is
  1129. shown, either today or the nearest into the future."
  1130. :group 'org-agenda-daily/weekly
  1131. :type '(choice
  1132. (const :tag "Show repeating stamps" t)
  1133. (repeat :tag "Show repeating stamps for these TODO keywords"
  1134. (string :tag "TODO Keyword"))
  1135. (const :tag "Don't show repeating stamps" nil)))
  1136. (defcustom org-scheduled-past-days 10000
  1137. "Number of days to continue listing scheduled items not marked DONE.
  1138. When an item is scheduled on a date, it shows up in the agenda on
  1139. this day and will be listed until it is marked done or for the
  1140. number of days given here."
  1141. :group 'org-agenda-daily/weekly
  1142. :type 'integer)
  1143. (defcustom org-agenda-log-mode-items '(closed clock)
  1144. "List of items that should be shown in agenda log mode.
  1145. \\<org-agenda-mode-map>\
  1146. This list may contain the following symbols:
  1147. closed Show entries that have been closed on that day.
  1148. clock Show entries that have received clocked time on that day.
  1149. state Show all logged state changes.
  1150. Note that instead of changing this variable, you can also press \
  1151. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1152. the agenda to display all available LOG items temporarily."
  1153. :group 'org-agenda-daily/weekly
  1154. :type '(set :greedy t (const closed) (const clock) (const state)))
  1155. (defcustom org-agenda-clock-consistency-checks
  1156. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1157. :gap-ok-around ("4:00")
  1158. :default-face ((:background "DarkRed") (:foreground "white"))
  1159. :overlap-face nil :gap-face nil :no-end-time-face nil
  1160. :long-face nil :short-face nil)
  1161. "This is a property list, with the following keys:
  1162. :max-duration Mark clocking chunks that are longer than this time.
  1163. This is a time string like \"HH:MM\", or the number
  1164. of minutes as an integer.
  1165. :min-duration Mark clocking chunks that are shorter that this.
  1166. This is a time string like \"HH:MM\", or the number
  1167. of minutes as an integer.
  1168. :max-gap Mark gaps between clocking chunks that are longer than
  1169. this duration. A number of minutes, or a string
  1170. like \"HH:MM\".
  1171. :gap-ok-around List of times during the day which are usually not working
  1172. times. When a gap is detected, but the gap contains any
  1173. of these times, the gap is *not* reported. For example,
  1174. if this is (\"4:00\" \"13:00\") then gaps that contain
  1175. 4:00 in the morning (i.e. the night) and 13:00
  1176. (i.e. a typical lunch time) do not cause a warning.
  1177. You should have at least one time during the night in this
  1178. list, or otherwise the first task each morning will trigger
  1179. a warning because it follows a long gap.
  1180. Furthermore, the following properties can be used to define faces for
  1181. issue display.
  1182. :default-face the default face, if the specific face is undefined
  1183. :overlap-face face for overlapping clocks
  1184. :gap-face face for gaps between clocks
  1185. :no-end-time-face face for incomplete clocks
  1186. :long-face face for clock intervals that are too long
  1187. :short-face face for clock intervals that are too short"
  1188. :group 'org-agenda-daily/weekly
  1189. :group 'org-clock
  1190. :version "24.1"
  1191. :type 'plist)
  1192. (defcustom org-agenda-log-mode-add-notes t
  1193. "Non-nil means add first line of notes to log entries in agenda views.
  1194. If a log item like a state change or a clock entry is associated with
  1195. notes, the first line of these notes will be added to the entry in the
  1196. agenda display."
  1197. :group 'org-agenda-daily/weekly
  1198. :type 'boolean)
  1199. (defcustom org-agenda-start-with-log-mode nil
  1200. "The initial value of log-mode in a newly created agenda window.
  1201. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1202. explanations on the possible values."
  1203. :group 'org-agenda-startup
  1204. :group 'org-agenda-daily/weekly
  1205. :type '(choice (const :tag "Don't show log items" nil)
  1206. (const :tag "Show only log items" only)
  1207. (const :tag "Show all possible log items" clockcheck)
  1208. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1209. (choice (const :tag "Show closed log items" closed)
  1210. (const :tag "Show clocked log items" clock)
  1211. (const :tag "Show all logged state changes" state)))))
  1212. (defcustom org-agenda-start-with-clockreport-mode nil
  1213. "The initial value of clockreport-mode in a newly created agenda window."
  1214. :group 'org-agenda-startup
  1215. :group 'org-agenda-daily/weekly
  1216. :type 'boolean)
  1217. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1218. "Property list with parameters for the clocktable in clockreport mode.
  1219. This is the display mode that shows a clock table in the daily/weekly
  1220. agenda, the properties for this dynamic block can be set here.
  1221. The usual clocktable parameters are allowed here, but you cannot set
  1222. the properties :name, :tstart, :tend, :block, and :scope - these will
  1223. be overwritten to make sure the content accurately reflects the
  1224. current display in the agenda."
  1225. :group 'org-agenda-daily/weekly
  1226. :type 'plist)
  1227. (defcustom org-agenda-search-view-always-boolean nil
  1228. "Non-nil means the search string is interpreted as individual parts.
  1229. The search string for search view can either be interpreted as a phrase,
  1230. or as a list of snippets that define a boolean search for a number of
  1231. strings.
  1232. When this is non-nil, the string will be split on whitespace, and each
  1233. snippet will be searched individually, and all must match in order to
  1234. select an entry. A snippet is then a single string of non-white
  1235. characters, or a string in double quotes, or a regexp in {} braces.
  1236. If a snippet is preceded by \"-\", the snippet must *not* match.
  1237. \"+\" is syntactic sugar for positive selection. Each snippet may
  1238. be found as a full word or a partial word, but see the variable
  1239. `org-agenda-search-view-force-full-words'.
  1240. When this is nil, search will look for the entire search phrase as one,
  1241. with each space character matching any amount of whitespace, including
  1242. line breaks.
  1243. Even when this is nil, you can still switch to Boolean search dynamically
  1244. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1245. is a regexp marked with braces like \"{abc}\", this will also switch to
  1246. boolean search."
  1247. :group 'org-agenda-search-view
  1248. :version "24.1"
  1249. :type 'boolean)
  1250. (org-defvaralias 'org-agenda-search-view-search-words-only
  1251. 'org-agenda-search-view-always-boolean)
  1252. (defcustom org-agenda-search-view-force-full-words nil
  1253. "Non-nil means, search words must be matches as complete words.
  1254. When nil, they may also match part of a word."
  1255. :group 'org-agenda-search-view
  1256. :version "24.1"
  1257. :type 'boolean)
  1258. (defcustom org-agenda-search-view-max-outline-level 0
  1259. "Maximum outline level to display in search view.
  1260. E.g. when this is set to 1, the search view will only
  1261. show headlines of level 1. When set to 0, the default
  1262. value, don't limit agenda view by outline level."
  1263. :group 'org-agenda-search-view
  1264. :version "24.4"
  1265. :package-version '(Org . "8.3")
  1266. :type 'integer)
  1267. (defgroup org-agenda-time-grid nil
  1268. "Options concerning the time grid in the Org-mode Agenda."
  1269. :tag "Org Agenda Time Grid"
  1270. :group 'org-agenda)
  1271. (defcustom org-agenda-search-headline-for-time t
  1272. "Non-nil means search headline for a time-of-day.
  1273. If the headline contains a time-of-day in one format or another, it will
  1274. be used to sort the entry into the time sequence of items for a day.
  1275. Some people have time stamps in the headline that refer to the creation
  1276. time or so, and then this produces an unwanted side effect. If this is
  1277. the case for your, use this variable to turn off searching the headline
  1278. for a time."
  1279. :group 'org-agenda-time-grid
  1280. :type 'boolean)
  1281. (defcustom org-agenda-use-time-grid t
  1282. "Non-nil means show a time grid in the agenda schedule.
  1283. A time grid is a set of lines for specific times (like every two hours between
  1284. 8:00 and 20:00). The items scheduled for a day at specific times are
  1285. sorted in between these lines.
  1286. For details about when the grid will be shown, and what it will look like, see
  1287. the variable `org-agenda-time-grid'."
  1288. :group 'org-agenda-time-grid
  1289. :type 'boolean)
  1290. (defcustom org-agenda-time-grid
  1291. '((daily today require-timed)
  1292. "----------------"
  1293. (800 1000 1200 1400 1600 1800 2000))
  1294. "The settings for time grid for agenda display.
  1295. This is a list of three items. The first item is again a list. It contains
  1296. symbols specifying conditions when the grid should be displayed:
  1297. daily if the agenda shows a single day
  1298. weekly if the agenda shows an entire week
  1299. today show grid on current date, independent of daily/weekly display
  1300. require-timed show grid only if at least one item has a time specification
  1301. remove-match skip grid times already present in an entry
  1302. The second item is a string which will be placed behind the grid time.
  1303. The third item is a list of integers, indicating the times that should have
  1304. a grid line."
  1305. :group 'org-agenda-time-grid
  1306. :type
  1307. '(list
  1308. (set :greedy t :tag "Grid Display Options"
  1309. (const :tag "Show grid in single day agenda display" daily)
  1310. (const :tag "Show grid in weekly agenda display" weekly)
  1311. (const :tag "Always show grid for today" today)
  1312. (const :tag "Show grid only if any timed entries are present"
  1313. require-timed)
  1314. (const :tag "Skip grid times already present in an entry"
  1315. remove-match))
  1316. (string :tag "Grid String")
  1317. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1318. (defcustom org-agenda-show-current-time-in-grid t
  1319. "Non-nil means show the current time in the time grid."
  1320. :group 'org-agenda-time-grid
  1321. :version "24.1"
  1322. :type 'boolean)
  1323. (defcustom org-agenda-current-time-string
  1324. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1325. "The string for the current time marker in the agenda."
  1326. :group 'org-agenda-time-grid
  1327. :version "24.1"
  1328. :type 'string)
  1329. (defgroup org-agenda-sorting nil
  1330. "Options concerning sorting in the Org-mode Agenda."
  1331. :tag "Org Agenda Sorting"
  1332. :group 'org-agenda)
  1333. (defcustom org-agenda-sorting-strategy
  1334. '((agenda habit-down time-up priority-down category-keep)
  1335. (todo priority-down category-keep)
  1336. (tags priority-down category-keep)
  1337. (search category-keep))
  1338. "Sorting structure for the agenda items of a single day.
  1339. This is a list of symbols which will be used in sequence to determine
  1340. if an entry should be listed before another entry. The following
  1341. symbols are recognized:
  1342. time-up Put entries with time-of-day indications first, early first
  1343. time-down Put entries with time-of-day indications first, late first
  1344. timestamp-up Sort by any timestamp, early first
  1345. timestamp-down Sort by any timestamp, late first
  1346. scheduled-up Sort by scheduled timestamp, early first
  1347. scheduled-down Sort by scheduled timestamp, late first
  1348. deadline-up Sort by deadline timestamp, early first
  1349. deadline-down Sort by deadline timestamp, late first
  1350. ts-up Sort by active timestamp, early first
  1351. ts-down Sort by active timestamp, late first
  1352. tsia-up Sort by inactive timestamp, early first
  1353. tsia-down Sort by inactive timestamp, late first
  1354. category-keep Keep the default order of categories, corresponding to the
  1355. sequence in `org-agenda-files'.
  1356. category-up Sort alphabetically by category, A-Z.
  1357. category-down Sort alphabetically by category, Z-A.
  1358. tag-up Sort alphabetically by last tag, A-Z.
  1359. tag-down Sort alphabetically by last tag, Z-A.
  1360. priority-up Sort numerically by priority, high priority last.
  1361. priority-down Sort numerically by priority, high priority first.
  1362. todo-state-up Sort by todo state, tasks that are done last.
  1363. todo-state-down Sort by todo state, tasks that are done first.
  1364. effort-up Sort numerically by estimated effort, high effort last.
  1365. effort-down Sort numerically by estimated effort, high effort first.
  1366. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1367. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1368. habit-up Put entries that are habits first
  1369. habit-down Put entries that are habits last
  1370. alpha-up Sort headlines alphabetically
  1371. alpha-down Sort headlines alphabetically, reversed
  1372. The different possibilities will be tried in sequence, and testing stops
  1373. if one comparison returns a \"not-equal\". For example, the default
  1374. '(time-up category-keep priority-down)
  1375. means: Pull out all entries having a specified time of day and sort them,
  1376. in order to make a time schedule for the current day the first thing in the
  1377. agenda listing for the day. Of the entries without a time indication, keep
  1378. the grouped in categories, don't sort the categories, but keep them in
  1379. the sequence given in `org-agenda-files'. Within each category sort by
  1380. priority.
  1381. Leaving out `category-keep' would mean that items will be sorted across
  1382. categories by priority.
  1383. Instead of a single list, this can also be a set of list for specific
  1384. contents, with a context symbol in the car of the list, any of
  1385. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1386. Custom commands can bind this variable in the options section."
  1387. :group 'org-agenda-sorting
  1388. :type `(choice
  1389. (repeat :tag "General" ,org-sorting-choice)
  1390. (list :tag "Individually"
  1391. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1392. (repeat ,org-sorting-choice))
  1393. (cons (const :tag "Strategy for TODO lists" todo)
  1394. (repeat ,org-sorting-choice))
  1395. (cons (const :tag "Strategy for Tags matches" tags)
  1396. (repeat ,org-sorting-choice))
  1397. (cons (const :tag "Strategy for search matches" search)
  1398. (repeat ,org-sorting-choice)))))
  1399. (defcustom org-agenda-cmp-user-defined nil
  1400. "A function to define the comparison `user-defined'.
  1401. This function must receive two arguments, agenda entry a and b.
  1402. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1403. the user comparison, return nil.
  1404. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1405. part of an agenda sorting strategy."
  1406. :group 'org-agenda-sorting
  1407. :type 'symbol)
  1408. (defcustom org-sort-agenda-notime-is-late t
  1409. "Non-nil means items without time are considered late.
  1410. This is only relevant for sorting. When t, items which have no explicit
  1411. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1412. do have a time. When nil, the default time is before 0:00. You can use this
  1413. option to decide if the schedule for today should come before or after timeless
  1414. agenda entries."
  1415. :group 'org-agenda-sorting
  1416. :type 'boolean)
  1417. (defcustom org-sort-agenda-noeffort-is-high t
  1418. "Non-nil means items without effort estimate are sorted as high effort.
  1419. This also applies when filtering an agenda view with respect to the
  1420. < or > effort operator. Then, tasks with no effort defined will be treated
  1421. as tasks with high effort.
  1422. When nil, such items are sorted as 0 minutes effort."
  1423. :group 'org-agenda-sorting
  1424. :type 'boolean)
  1425. (defgroup org-agenda-line-format nil
  1426. "Options concerning the entry prefix in the Org-mode agenda display."
  1427. :tag "Org Agenda Line Format"
  1428. :group 'org-agenda)
  1429. (defcustom org-agenda-prefix-format
  1430. '((agenda . " %i %-12:c%?-12t% s")
  1431. (timeline . " % s")
  1432. (todo . " %i %-12:c")
  1433. (tags . " %i %-12:c")
  1434. (search . " %i %-12:c"))
  1435. "Format specifications for the prefix of items in the agenda views.
  1436. An alist with five entries, each for the different agenda types. The
  1437. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1438. The values are format strings.
  1439. This format works similar to a printf format, with the following meaning:
  1440. %c the category of the item, \"Diary\" for entries from the diary,
  1441. or as given by the CATEGORY keyword or derived from the file name
  1442. %e the effort required by the item
  1443. %l the level of the item (insert X space(s) if item is of level X)
  1444. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1445. %T the last tag of the item (ignore inherited tags, which come first)
  1446. %t the HH:MM time-of-day specification if one applies to the entry
  1447. %s Scheduling/Deadline information, a short string
  1448. %b show breadcrumbs, i.e., the names of the higher levels
  1449. %(expression) Eval EXPRESSION and replace the control string
  1450. by the result
  1451. All specifiers work basically like the standard `%s' of printf, but may
  1452. contain two additional characters: a question mark just after the `%'
  1453. and a whitespace/punctuation character just before the final letter.
  1454. If the first character after `%' is a question mark, the entire field
  1455. will only be included if the corresponding value applies to the current
  1456. entry. This is useful for fields which should have fixed width when
  1457. present, but zero width when absent. For example, \"%?-12t\" will
  1458. result in a 12 character time field if a time of the day is specified,
  1459. but will completely disappear in entries which do not contain a time.
  1460. If there is punctuation or whitespace character just before the
  1461. final format letter, this character will be appended to the field
  1462. value if the value is not empty. For example, the format
  1463. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1464. the category is empty, no additional colon is inserted.
  1465. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1466. which means:
  1467. - Indent the line with two space characters
  1468. - Give the category a 12 chars wide field, padded with whitespace on
  1469. the right (because of `-'). Append a colon if there is a category
  1470. (because of `:').
  1471. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1472. time, don't put in an empty field, just skip it (because of '?').
  1473. - Finally, put the scheduling information.
  1474. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1475. `org-agenda-remove-tags'.
  1476. Custom commands can set this variable in the options section."
  1477. :type '(choice
  1478. (string :tag "General format")
  1479. (list :greedy t :tag "View dependent"
  1480. (cons (const agenda) (string :tag "Format"))
  1481. (cons (const timeline) (string :tag "Format"))
  1482. (cons (const todo) (string :tag "Format"))
  1483. (cons (const tags) (string :tag "Format"))
  1484. (cons (const search) (string :tag "Format"))))
  1485. :group 'org-agenda-line-format)
  1486. (defvar org-prefix-format-compiled nil
  1487. "The compiled prefix format and associated variables.
  1488. This is a list where first element is a list of variable bindings, and second
  1489. element is the compiled format expression. See the variable
  1490. `org-agenda-prefix-format'.")
  1491. (defcustom org-agenda-todo-keyword-format "%-1s"
  1492. "Format for the TODO keyword in agenda lines.
  1493. Set this to something like \"%-12s\" if you want all TODO keywords
  1494. to occupy a fixed space in the agenda display."
  1495. :group 'org-agenda-line-format
  1496. :type 'string)
  1497. (defcustom org-agenda-diary-sexp-prefix nil
  1498. "A regexp that matches part of a diary sexp entry
  1499. which should be treated as scheduling/deadline information in
  1500. `org-agenda'.
  1501. For example, you can use this to extract the `diary-remind-message' from
  1502. `diary-remind' entries."
  1503. :group 'org-agenda-line-format
  1504. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1505. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1506. "Text preceding timerange entries in the agenda view.
  1507. This is a list with two strings. The first applies when the range
  1508. is entirely on one day. The second applies if the range spans several days.
  1509. The strings may have two \"%d\" format specifiers which will be filled
  1510. with the sequence number of the days, and the total number of days in the
  1511. range, respectively."
  1512. :group 'org-agenda-line-format
  1513. :type '(list
  1514. (string :tag "Deadline today ")
  1515. (choice :tag "Deadline relative"
  1516. (string :tag "Format string")
  1517. (function))))
  1518. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1519. "Text preceding scheduled items in the agenda view.
  1520. This is a list with two strings. The first applies when the item is
  1521. scheduled on the current day. The second applies when it has been scheduled
  1522. previously, it may contain a %d indicating that this is the nth time that
  1523. this item is scheduled, due to automatic rescheduling of unfinished items
  1524. for the following day. So this number is one larger than the number of days
  1525. that passed since this item was scheduled first."
  1526. :group 'org-agenda-line-format
  1527. :version "24.4"
  1528. :package-version '(Org . "8.0")
  1529. :type '(list
  1530. (string :tag "Scheduled today ")
  1531. (string :tag "Scheduled previously")))
  1532. (defcustom org-agenda-inactive-leader "["
  1533. "Text preceding item pulled into the agenda by inactive time stamps.
  1534. These entries are added to the agenda when pressing \"[\"."
  1535. :group 'org-agenda-line-format
  1536. :version "24.1"
  1537. :type 'string)
  1538. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1539. "Text preceding deadline items in the agenda view.
  1540. This is a list with three strings. The first applies when the item has its
  1541. deadline on the current day. The second applies when the deadline is in the
  1542. future, the third one when it is in the past. The strings may contain %d
  1543. to capture the number of days."
  1544. :group 'org-agenda-line-format
  1545. :version "24.4"
  1546. :package-version '(Org . "8.0")
  1547. :type '(list
  1548. (string :tag "Deadline today ")
  1549. (string :tag "Deadline in the future ")
  1550. (string :tag "Deadline in the past ")))
  1551. (defcustom org-agenda-remove-times-when-in-prefix t
  1552. "Non-nil means remove duplicate time specifications in agenda items.
  1553. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1554. time-of-day specification in a headline or diary entry is extracted and
  1555. placed into the prefix. If this option is non-nil, the original specification
  1556. \(a timestamp or -range, or just a plain time(range) specification like
  1557. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1558. cluttered.
  1559. The option can be t or nil. It may also be the symbol `beg', indicating
  1560. that the time should only be removed when it is located at the beginning of
  1561. the headline/diary entry."
  1562. :group 'org-agenda-line-format
  1563. :type '(choice
  1564. (const :tag "Always" t)
  1565. (const :tag "Never" nil)
  1566. (const :tag "When at beginning of entry" beg)))
  1567. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1568. "Non-nil means remove time ranges specifications in agenda
  1569. items that span on several days."
  1570. :group 'org-agenda-line-format
  1571. :version "24.1"
  1572. :type 'boolean)
  1573. (defcustom org-agenda-default-appointment-duration nil
  1574. "Default duration for appointments that only have a starting time.
  1575. When nil, no duration is specified in such cases.
  1576. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1577. :group 'org-agenda-line-format
  1578. :type '(choice
  1579. (integer :tag "Minutes")
  1580. (const :tag "No default duration")))
  1581. (defcustom org-agenda-show-inherited-tags t
  1582. "Non-nil means show inherited tags in each agenda line.
  1583. When this option is set to `always', it take precedences over
  1584. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1585. in every agenda.
  1586. When this option is set to t (the default), inherited tags are
  1587. shown when they are available, i.e. when the value of
  1588. `org-agenda-use-tag-inheritance' has been taken into account.
  1589. This can be set to a list of agenda types in which the agenda
  1590. must display the inherited tags. Available types are `todo',
  1591. `agenda', `search' and `timeline'.
  1592. When set to nil, never show inherited tags in agenda lines."
  1593. :group 'org-agenda-line-format
  1594. :group 'org-agenda
  1595. :version "24.3"
  1596. :type '(choice
  1597. (const :tag "Show inherited tags when available" t)
  1598. (const :tag "Always show inherited tags" always)
  1599. (repeat :tag "Show inherited tags only in selected agenda types"
  1600. (symbol :tag "Agenda type"))))
  1601. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1602. "List of agenda view types where to use tag inheritance.
  1603. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1604. controlled by `org-use-tag-inheritance'. In other agenda types,
  1605. `org-use-tag-inheritance' is not used for the selection of the
  1606. agenda entries. Still, you may want the agenda to be aware of
  1607. the inherited tags anyway, e.g. for later tag filtering.
  1608. Allowed value are `todo', `search', `timeline' and `agenda'.
  1609. This variable has no effect if `org-agenda-show-inherited-tags'
  1610. is set to `always'. In that case, the agenda is aware of those
  1611. tags.
  1612. The default value sets tags in every agenda type. Setting this
  1613. option to nil will speed up non-tags agenda view a lot."
  1614. :group 'org-agenda
  1615. :version "24.3"
  1616. :type '(choice
  1617. (const :tag "Use tag inheritance in all agenda types" t)
  1618. (repeat :tag "Use tag inheritance in selected agenda types"
  1619. (symbol :tag "Agenda type"))))
  1620. (defcustom org-agenda-hide-tags-regexp nil
  1621. "Regular expression used to filter away specific tags in agenda views.
  1622. This means that these tags will be present, but not be shown in the agenda
  1623. line. Secondary filtering will still work on the hidden tags.
  1624. Nil means don't hide any tags."
  1625. :group 'org-agenda-line-format
  1626. :type '(choice
  1627. (const :tag "Hide none" nil)
  1628. (string :tag "Regexp ")))
  1629. (defcustom org-agenda-remove-tags nil
  1630. "Non-nil means remove the tags from the headline copy in the agenda.
  1631. When this is the symbol `prefix', only remove tags when
  1632. `org-agenda-prefix-format' contains a `%T' specifier."
  1633. :group 'org-agenda-line-format
  1634. :type '(choice
  1635. (const :tag "Always" t)
  1636. (const :tag "Never" nil)
  1637. (const :tag "When prefix format contains %T" prefix)))
  1638. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1639. 'org-agenda-remove-tags)
  1640. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1641. "Shift tags in agenda items to this column.
  1642. If this number is positive, it specifies the column. If it is negative,
  1643. it means that the tags should be flushright to that column. For example,
  1644. -80 works well for a normal 80 character screen."
  1645. :group 'org-agenda-line-format
  1646. :type 'integer)
  1647. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1648. (defcustom org-agenda-fontify-priorities 'cookies
  1649. "Non-nil means highlight low and high priorities in agenda.
  1650. When t, the highest priority entries are bold, lowest priority italic.
  1651. However, settings in `org-priority-faces' will overrule these faces.
  1652. When this variable is the symbol `cookies', only fontify the
  1653. cookies, not the entire task.
  1654. This may also be an association list of priority faces, whose
  1655. keys are the character values of `org-highest-priority',
  1656. `org-default-priority', and `org-lowest-priority' (the default values
  1657. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1658. color as a string, or a list like `(:background \"Red\")'.
  1659. If it is a color, the variable `org-faces-easy-properties'
  1660. determines if it is a foreground or a background color."
  1661. :group 'org-agenda-line-format
  1662. :type '(choice
  1663. (const :tag "Never" nil)
  1664. (const :tag "Defaults" t)
  1665. (const :tag "Cookies only" cookies)
  1666. (repeat :tag "Specify"
  1667. (list (character :tag "Priority" :value ?A)
  1668. (choice :tag "Face "
  1669. (string :tag "Color")
  1670. (sexp :tag "Face"))))))
  1671. (defcustom org-agenda-day-face-function nil
  1672. "Function called to determine what face should be used to display a day.
  1673. The only argument passed to that function is the day. It should
  1674. returns a face, or nil if does not want to specify a face and let
  1675. the normal rules apply."
  1676. :group 'org-agenda-line-format
  1677. :version "24.1"
  1678. :type '(choice (const nil) (function)))
  1679. (defcustom org-agenda-category-icon-alist nil
  1680. "Alist of category icon to be displayed in agenda views.
  1681. Each entry should have the following format:
  1682. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1683. Where CATEGORY-REGEXP is a regexp matching the categories where
  1684. the icon should be displayed.
  1685. FILE-OR-DATA either a file path or a string containing image data.
  1686. The other fields can be omitted safely if not needed:
  1687. TYPE indicates the image type.
  1688. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1689. image data.
  1690. PROPS are additional image attributes to assign to the image,
  1691. like, e.g. `:ascent center'.
  1692. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1693. If you want to set the display properties yourself, just put a
  1694. list as second element:
  1695. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1696. For example, to display a 16px horizontal space for Emacs
  1697. category, you can use:
  1698. (\"Emacs\" \\='(space . (:width (16))))"
  1699. :group 'org-agenda-line-format
  1700. :version "24.1"
  1701. :type '(alist :key-type (string :tag "Regexp matching category")
  1702. :value-type (choice (list :tag "Icon"
  1703. (string :tag "File or data")
  1704. (symbol :tag "Type")
  1705. (boolean :tag "Data?")
  1706. (repeat :tag "Extra image properties" :inline t symbol))
  1707. (list :tag "Display properties" sexp))))
  1708. (defgroup org-agenda-column-view nil
  1709. "Options concerning column view in the agenda."
  1710. :tag "Org Agenda Column View"
  1711. :group 'org-agenda)
  1712. (defcustom org-agenda-view-columns-initially nil
  1713. "When non-nil, switch to columns view right after creating the agenda."
  1714. :group 'org-agenda-column-view
  1715. :type 'boolean
  1716. :version "25.1"
  1717. :package-version '(Org . "9.0")
  1718. :safe #'booleanp)
  1719. (defcustom org-agenda-columns-show-summaries t
  1720. "Non-nil means show summaries for columns displayed in the agenda view."
  1721. :group 'org-agenda-column-view
  1722. :type 'boolean)
  1723. (defcustom org-agenda-columns-compute-summary-properties t
  1724. "Non-nil means recompute all summary properties before column view.
  1725. When column view in the agenda is listing properties that have a summary
  1726. operator, it can go to all relevant buffers and recompute the summaries
  1727. there. This can mean overhead for the agenda column view, but is necessary
  1728. to have thing up to date.
  1729. As a special case, a CLOCKSUM property also makes sure that the clock
  1730. computations are current."
  1731. :group 'org-agenda-column-view
  1732. :type 'boolean)
  1733. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1734. "Non-nil means the duration of an appointment will add to day effort.
  1735. The property to which appointment durations will be added is the one given
  1736. in the option `org-effort-property'. If an appointment does not have
  1737. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1738. is not set, an appointment without end time will not contribute to the time
  1739. estimate."
  1740. :group 'org-agenda-column-view
  1741. :type 'boolean)
  1742. (defcustom org-agenda-auto-exclude-function nil
  1743. "A function called with a tag to decide if it is filtered on \
  1744. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1745. The sole argument to the function, which is called once for each
  1746. possible tag, is a string giving the name of the tag. The
  1747. function should return either nil if the tag should be included
  1748. as normal, or \"-<TAG>\" to exclude the tag.
  1749. Note that for the purpose of tag filtering, only the lower-case version of
  1750. all tags will be considered, so that this function will only ever see
  1751. the lower-case version of all tags."
  1752. :group 'org-agenda
  1753. :type '(choice (const nil) (function)))
  1754. (defcustom org-agenda-bulk-custom-functions nil
  1755. "Alist of characters and custom functions for bulk actions.
  1756. For example, this value makes those two functions available:
  1757. \\='((?R set-category)
  1758. (?C bulk-cut))
  1759. With selected entries in an agenda buffer, `B R' will call
  1760. the custom function `set-category' on the selected entries.
  1761. Note that functions in this alist don't need to be quoted."
  1762. :type 'alist
  1763. :version "24.1"
  1764. :group 'org-agenda)
  1765. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1766. "Execute BODY with point at location given by `org-hd-marker' property.
  1767. If STRING is non-nil, the text property will be fetched from position 0
  1768. in that string. If STRING is nil, it will be fetched from the beginning
  1769. of the current line."
  1770. (org-with-gensyms (marker)
  1771. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1772. 'org-hd-marker ,string)))
  1773. (with-current-buffer (marker-buffer ,marker)
  1774. (save-excursion
  1775. (goto-char ,marker)
  1776. ,@body)))))
  1777. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1778. (defun org-add-agenda-custom-command (entry)
  1779. "Replace or add a command in `org-agenda-custom-commands'.
  1780. This is mostly for hacking and trying a new command - once the command
  1781. works you probably want to add it to `org-agenda-custom-commands' for good."
  1782. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1783. (if ass
  1784. (setcdr ass (cdr entry))
  1785. (push entry org-agenda-custom-commands))))
  1786. ;;; Define the org-agenda-mode
  1787. (defvar org-agenda-mode-map (make-sparse-keymap)
  1788. "Keymap for `org-agenda-mode'.")
  1789. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1790. (defvar org-agenda-menu) ; defined later in this file.
  1791. (defvar org-agenda-restrict nil) ; defined later in this file.
  1792. (defvar org-agenda-follow-mode nil)
  1793. (defvar org-agenda-entry-text-mode nil)
  1794. (defvar org-agenda-clockreport-mode nil)
  1795. (defvar org-agenda-show-log nil)
  1796. (defvar org-agenda-redo-command nil)
  1797. (defvar org-agenda-query-string nil)
  1798. (defvar org-agenda-mode-hook nil
  1799. "Hook run after `org-agenda-mode' is turned on.
  1800. The buffer is still writable when this hook is called.")
  1801. (defvar org-agenda-type nil)
  1802. (defvar org-agenda-force-single-file nil)
  1803. (defvar org-agenda-bulk-marked-entries nil
  1804. "List of markers that refer to marked entries in the agenda.")
  1805. (defvar org-agenda-current-date nil
  1806. "Active date when building the agenda.")
  1807. ;;; Multiple agenda buffers support
  1808. (defcustom org-agenda-sticky nil
  1809. "Non-nil means agenda q key will bury agenda buffers.
  1810. Agenda commands will then show existing buffer instead of generating new ones.
  1811. When nil, `q' will kill the single agenda buffer."
  1812. :group 'org-agenda
  1813. :version "24.3"
  1814. :type 'boolean)
  1815. ;;;###autoload
  1816. (defun org-toggle-sticky-agenda (&optional arg)
  1817. "Toggle `org-agenda-sticky'."
  1818. (interactive "P")
  1819. (let ((new-value (if arg
  1820. (> (prefix-numeric-value arg) 0)
  1821. (not org-agenda-sticky))))
  1822. (if (equal new-value org-agenda-sticky)
  1823. (and (org-called-interactively-p 'interactive)
  1824. (message "Sticky agenda was already %s"
  1825. (if org-agenda-sticky "enabled" "disabled")))
  1826. (setq org-agenda-sticky new-value)
  1827. (org-agenda-kill-all-agenda-buffers)
  1828. (and (org-called-interactively-p 'interactive)
  1829. (message "Sticky agenda %s"
  1830. (if org-agenda-sticky "enabled" "disabled"))))))
  1831. (defvar org-agenda-buffer nil
  1832. "Agenda buffer currently being generated.")
  1833. (defvar org-agenda-last-prefix-arg nil)
  1834. (defvar org-agenda-this-buffer-name nil)
  1835. (defvar org-agenda-doing-sticky-redo nil)
  1836. (defvar org-agenda-this-buffer-is-sticky nil)
  1837. (defvar org-agenda-last-indirect-buffer nil
  1838. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1839. (defconst org-agenda-local-vars
  1840. '(org-agenda-this-buffer-name
  1841. org-agenda-undo-list
  1842. org-agenda-pending-undo-list
  1843. org-agenda-follow-mode
  1844. org-agenda-entry-text-mode
  1845. org-agenda-clockreport-mode
  1846. org-agenda-show-log
  1847. org-agenda-redo-command
  1848. org-agenda-query-string
  1849. org-agenda-type
  1850. org-agenda-bulk-marked-entries
  1851. org-agenda-undo-has-started-in
  1852. org-agenda-info
  1853. org-agenda-pre-window-conf
  1854. org-agenda-columns-active
  1855. org-agenda-tag-filter
  1856. org-agenda-category-filter
  1857. org-agenda-top-headline-filter
  1858. org-agenda-regexp-filter
  1859. org-agenda-effort-filter
  1860. org-agenda-markers
  1861. org-agenda-last-search-view-search-was-boolean
  1862. org-agenda-last-indirect-buffer
  1863. org-agenda-filtered-by-category
  1864. org-agenda-filter-form
  1865. org-agenda-cycle-counter
  1866. org-agenda-last-prefix-arg)
  1867. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1868. (defun org-agenda-mode ()
  1869. "Mode for time-sorted view on action items in Org-mode files.
  1870. The following commands are available:
  1871. \\{org-agenda-mode-map}"
  1872. (interactive)
  1873. (cond (org-agenda-doing-sticky-redo
  1874. ;; Refreshing sticky agenda-buffer
  1875. ;;
  1876. ;; Preserve the value of `org-agenda-local-vars' variables,
  1877. ;; while letting `kill-all-local-variables' kill the rest
  1878. (let ((save (buffer-local-variables)))
  1879. (kill-all-local-variables)
  1880. (mapc 'make-local-variable org-agenda-local-vars)
  1881. (dolist (elem save)
  1882. (let ((var (car elem))
  1883. (val (cdr elem)))
  1884. (when (and val
  1885. (member var org-agenda-local-vars))
  1886. (set var val)))))
  1887. (setq-local org-agenda-this-buffer-is-sticky t))
  1888. (org-agenda-sticky
  1889. ;; Creating a sticky Agenda buffer for the first time
  1890. (kill-all-local-variables)
  1891. (mapc 'make-local-variable org-agenda-local-vars)
  1892. (setq-local org-agenda-this-buffer-is-sticky t))
  1893. (t
  1894. ;; Creating a non-sticky agenda buffer
  1895. (kill-all-local-variables)
  1896. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1897. (setq org-agenda-undo-list nil
  1898. org-agenda-pending-undo-list nil
  1899. org-agenda-bulk-marked-entries nil)
  1900. (setq major-mode 'org-agenda-mode)
  1901. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1902. (setq-local font-lock-global-modes (list 'not major-mode))
  1903. (setq mode-name "Org-Agenda")
  1904. (setq indent-tabs-mode nil)
  1905. (use-local-map org-agenda-mode-map)
  1906. (easy-menu-add org-agenda-menu)
  1907. (if org-startup-truncated (setq truncate-lines t))
  1908. (setq-local line-move-visual nil)
  1909. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1910. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1911. ;; Make sure properties are removed when copying text
  1912. (org-add-hook 'filter-buffer-substring-functions
  1913. (lambda (fun start end delete)
  1914. (substring-no-properties (funcall fun start end delete)))
  1915. nil t)
  1916. (unless org-agenda-keep-modes
  1917. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1918. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1919. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1920. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1921. (add-to-invisibility-spec '(org-filtered))
  1922. (add-to-invisibility-spec '(org-link))
  1923. (easy-menu-change
  1924. '("Agenda") "Agenda Files"
  1925. (append
  1926. (list
  1927. (vector
  1928. (if (get 'org-agenda-files 'org-restrict)
  1929. "Restricted to single file"
  1930. "Edit File List")
  1931. '(org-edit-agenda-file-list)
  1932. (not (get 'org-agenda-files 'org-restrict)))
  1933. "--")
  1934. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1935. (org-agenda-set-mode-name)
  1936. (apply
  1937. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1938. (list 'org-agenda-mode-hook)))
  1939. (substitute-key-definition 'undo 'org-agenda-undo
  1940. org-agenda-mode-map global-map)
  1941. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1942. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1943. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1944. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1945. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1946. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1947. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1948. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1949. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1950. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1951. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1952. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1953. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1954. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1955. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1956. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1957. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1958. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1959. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1960. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1961. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1962. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1963. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1964. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1965. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1966. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1967. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1968. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1969. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1970. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1971. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1972. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1973. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1974. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1975. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1976. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1977. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1978. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1979. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1980. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1981. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1982. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1983. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1984. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1985. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1986. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1987. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1988. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1989. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1990. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1991. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1992. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1993. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1994. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1995. (while l (org-defkey org-agenda-mode-map
  1996. (int-to-string (pop l)) 'digit-argument)))
  1997. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1998. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1999. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2000. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2001. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2002. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2003. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2004. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2005. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2006. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  2007. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2008. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2009. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2010. 'org-clock-modify-effort-estimate)
  2011. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2012. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2013. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2014. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2015. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2016. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2017. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2018. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2019. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2020. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2021. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2022. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2023. (substitute-key-definition 'next-line 'org-agenda-next-line
  2024. org-agenda-mode-map global-map)
  2025. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2026. org-agenda-mode-map global-map)
  2027. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2028. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2029. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2030. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2031. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2032. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2033. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2034. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2035. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2036. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2037. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2038. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2039. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2040. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2041. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2042. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2043. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2044. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2045. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2046. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2047. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2048. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2049. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2050. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2051. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2052. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2053. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2054. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2055. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2056. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2057. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2058. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2059. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2060. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2061. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2062. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2063. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2064. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2065. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2066. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2067. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2068. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2069. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2070. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2071. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2072. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2073. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2074. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2075. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2076. (when org-agenda-mouse-1-follows-link
  2077. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2078. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2079. '("Agenda"
  2080. ("Agenda Files")
  2081. "--"
  2082. ("Agenda Dates"
  2083. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2084. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2085. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2086. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2087. "--"
  2088. ("View"
  2089. ["Day View" org-agenda-day-view
  2090. :active (org-agenda-check-type nil 'agenda)
  2091. :style radio :selected (eq org-agenda-current-span 'day)
  2092. :keys "v d (or just d)"]
  2093. ["Week View" org-agenda-week-view
  2094. :active (org-agenda-check-type nil 'agenda)
  2095. :style radio :selected (eq org-agenda-current-span 'week)
  2096. :keys "v w"]
  2097. ["Fortnight View" org-agenda-fortnight-view
  2098. :active (org-agenda-check-type nil 'agenda)
  2099. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2100. :keys "v f"]
  2101. ["Month View" org-agenda-month-view
  2102. :active (org-agenda-check-type nil 'agenda)
  2103. :style radio :selected (eq org-agenda-current-span 'month)
  2104. :keys "v m"]
  2105. ["Year View" org-agenda-year-view
  2106. :active (org-agenda-check-type nil 'agenda)
  2107. :style radio :selected (eq org-agenda-current-span 'year)
  2108. :keys "v y"]
  2109. "--"
  2110. ["Include Diary" org-agenda-toggle-diary
  2111. :style toggle :selected org-agenda-include-diary
  2112. :active (org-agenda-check-type nil 'agenda)]
  2113. ["Include Deadlines" org-agenda-toggle-deadlines
  2114. :style toggle :selected org-agenda-include-deadlines
  2115. :active (org-agenda-check-type nil 'agenda)]
  2116. ["Use Time Grid" org-agenda-toggle-time-grid
  2117. :style toggle :selected org-agenda-use-time-grid
  2118. :active (org-agenda-check-type nil 'agenda)]
  2119. "--"
  2120. ["Show clock report" org-agenda-clockreport-mode
  2121. :style toggle :selected org-agenda-clockreport-mode
  2122. :active (org-agenda-check-type nil 'agenda)]
  2123. ["Show some entry text" org-agenda-entry-text-mode
  2124. :style toggle :selected org-agenda-entry-text-mode
  2125. :active t]
  2126. "--"
  2127. ["Show Logbook entries" org-agenda-log-mode
  2128. :style toggle :selected org-agenda-show-log
  2129. :active (org-agenda-check-type nil 'agenda 'timeline)
  2130. :keys "v l (or just l)"]
  2131. ["Include archived trees" org-agenda-archives-mode
  2132. :style toggle :selected org-agenda-archives-mode :active t
  2133. :keys "v a"]
  2134. ["Include archive files" (org-agenda-archives-mode t)
  2135. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2136. :keys "v A"]
  2137. "--"
  2138. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2139. ["Write view to file" org-agenda-write t]
  2140. ["Rebuild buffer" org-agenda-redo t]
  2141. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2142. "--"
  2143. ["Show original entry" org-agenda-show t]
  2144. ["Go To (other window)" org-agenda-goto t]
  2145. ["Go To (this window)" org-agenda-switch-to t]
  2146. ["Capture with cursor date" org-agenda-capture t]
  2147. ["Follow Mode" org-agenda-follow-mode
  2148. :style toggle :selected org-agenda-follow-mode :active t]
  2149. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2150. "--"
  2151. ("TODO"
  2152. ["Cycle TODO" org-agenda-todo t]
  2153. ["Next TODO set" org-agenda-todo-nextset t]
  2154. ["Previous TODO set" org-agenda-todo-previousset t]
  2155. ["Add note" org-agenda-add-note t])
  2156. ("Archive/Refile/Delete"
  2157. ["Archive default" org-agenda-archive-default t]
  2158. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2159. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2160. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2161. ["Archive subtree" org-agenda-archive t]
  2162. "--"
  2163. ["Refile" org-agenda-refile t]
  2164. "--"
  2165. ["Delete subtree" org-agenda-kill t])
  2166. ("Bulk action"
  2167. ["Mark entry" org-agenda-bulk-mark t]
  2168. ["Mark all" org-agenda-bulk-mark-all t]
  2169. ["Unmark entry" org-agenda-bulk-unmark t]
  2170. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2171. ["Toggle mark" org-agenda-bulk-toggle t]
  2172. ["Toggle all" org-agenda-bulk-toggle-all t]
  2173. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2174. ["Act on all marked" org-agenda-bulk-action t]
  2175. "--"
  2176. ("Tags and Properties"
  2177. ["Show all Tags" org-agenda-show-tags t]
  2178. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2179. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2180. "--"
  2181. ["Column View" org-columns t])
  2182. ("Deadline/Schedule"
  2183. ["Schedule" org-agenda-schedule t]
  2184. ["Set Deadline" org-agenda-deadline t]
  2185. "--"
  2186. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2188. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2189. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2190. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2191. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2192. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2193. ("Clock and Effort"
  2194. ["Clock in" org-agenda-clock-in t]
  2195. ["Clock out" org-agenda-clock-out t]
  2196. ["Clock cancel" org-agenda-clock-cancel t]
  2197. ["Goto running clock" org-clock-goto t]
  2198. "--"
  2199. ["Set Effort" org-agenda-set-effort t]
  2200. ["Change clocked effort" org-clock-modify-effort-estimate
  2201. (org-clock-is-active)])
  2202. ("Priority"
  2203. ["Set Priority" org-agenda-priority t]
  2204. ["Increase Priority" org-agenda-priority-up t]
  2205. ["Decrease Priority" org-agenda-priority-down t]
  2206. ["Show Priority" org-show-priority t])
  2207. ("Calendar/Diary"
  2208. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2209. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2210. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2211. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2212. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2213. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2214. "--"
  2215. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2216. "--"
  2217. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2218. "--"
  2219. ("MobileOrg"
  2220. ["Push Files and Views" org-mobile-push t]
  2221. ["Get Captured and Flagged" org-mobile-pull t]
  2222. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2223. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2224. "--"
  2225. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2226. "--"
  2227. ["Quit" org-agenda-quit t]
  2228. ["Exit and Release Buffers" org-agenda-exit t]
  2229. ))
  2230. ;;; Agenda undo
  2231. (defvar org-agenda-allow-remote-undo t
  2232. "Non-nil means allow remote undo from the agenda buffer.")
  2233. (defvar org-agenda-undo-has-started-in nil
  2234. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2235. (defun org-agenda-undo ()
  2236. "Undo a remote editing step in the agenda.
  2237. This undoes changes both in the agenda buffer and in the remote buffer
  2238. that have been changed along."
  2239. (interactive)
  2240. (or org-agenda-allow-remote-undo
  2241. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2242. (if (not (eq this-command last-command))
  2243. (setq org-agenda-undo-has-started-in nil
  2244. org-agenda-pending-undo-list org-agenda-undo-list))
  2245. (if (not org-agenda-pending-undo-list)
  2246. (user-error "No further undo information"))
  2247. (let* ((entry (pop org-agenda-pending-undo-list))
  2248. buf line cmd rembuf)
  2249. (setq cmd (pop entry) line (pop entry))
  2250. (setq rembuf (nth 2 entry))
  2251. (org-with-remote-undo rembuf
  2252. (while (bufferp (setq buf (pop entry)))
  2253. (if (pop entry)
  2254. (with-current-buffer buf
  2255. (let ((last-undo-buffer buf)
  2256. (inhibit-read-only t))
  2257. (unless (memq buf org-agenda-undo-has-started-in)
  2258. (push buf org-agenda-undo-has-started-in)
  2259. (make-local-variable 'pending-undo-list)
  2260. (undo-start))
  2261. (while (and pending-undo-list
  2262. (listp pending-undo-list)
  2263. (not (car pending-undo-list)))
  2264. (pop pending-undo-list))
  2265. (undo-more 1))))))
  2266. (org-goto-line line)
  2267. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2268. (defun org-verify-change-for-undo (l1 l2)
  2269. "Verify that a real change occurred between the undo lists L1 and L2."
  2270. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2271. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2272. (not (eq l1 l2)))
  2273. ;;; Agenda dispatch
  2274. (defvar org-agenda-restrict-begin (make-marker))
  2275. (defvar org-agenda-restrict-end (make-marker))
  2276. (defvar org-agenda-last-dispatch-buffer nil)
  2277. (defvar org-agenda-overriding-restriction nil)
  2278. (defcustom org-agenda-custom-commands-contexts nil
  2279. "Alist of custom agenda keys and contextual rules.
  2280. For example, if you have a custom agenda command \"p\" and you
  2281. want this command to be accessible only from plain text files,
  2282. use this:
  2283. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2284. Here are the available contexts definitions:
  2285. in-file: command displayed only in matching files
  2286. in-mode: command displayed only in matching modes
  2287. not-in-file: command not displayed in matching files
  2288. not-in-mode: command not displayed in matching modes
  2289. in-buffer: command displayed only in matching buffers
  2290. not-in-buffer: command not displayed in matching buffers
  2291. [function]: a custom function taking no argument
  2292. If you define several checks, the agenda command will be
  2293. accessible if there is at least one valid check.
  2294. You can also bind a key to another agenda custom command
  2295. depending on contextual rules.
  2296. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2297. Here it means: in .txt files, use \"p\" as the key for the
  2298. agenda command otherwise associated with \"q\". (The command
  2299. originally associated with \"q\" is not displayed to avoid
  2300. duplicates.)"
  2301. :version "24.3"
  2302. :group 'org-agenda-custom-commands
  2303. :type '(repeat (list :tag "Rule"
  2304. (string :tag " Agenda key")
  2305. (string :tag "Replace by command")
  2306. (repeat :tag "Available when"
  2307. (choice
  2308. (cons :tag "Condition"
  2309. (choice
  2310. (const :tag "In file" in-file)
  2311. (const :tag "Not in file" not-in-file)
  2312. (const :tag "In buffer" in-buffer)
  2313. (const :tag "Not in buffer" not-in-buffer)
  2314. (const :tag "In mode" in-mode)
  2315. (const :tag "Not in mode" not-in-mode))
  2316. (regexp))
  2317. (function :tag "Custom function"))))))
  2318. (defcustom org-agenda-max-entries nil
  2319. "Maximum number of entries 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 entries")
  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 entries")))))
  2336. (defcustom org-agenda-max-todos nil
  2337. "Maximum number of TODOs 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 TODOs")
  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 TODOs")))))
  2354. (defcustom org-agenda-max-tags nil
  2355. "Maximum number of tagged entries to display in an agenda.
  2356. This can be nil (no limit) or an integer or an alist of agenda
  2357. types with an associated number of entries to display in this
  2358. 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 tagged entries")
  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 tagged entries")))))
  2372. (defcustom org-agenda-max-effort nil
  2373. "Maximum cumulated effort duration for the agenda.
  2374. This can be nil (no limit) or a number of minutes (as an integer)
  2375. or an alist of agenda types with an associated number of minutes
  2376. to limit entries to in this type."
  2377. :version "24.4"
  2378. :package-version '(Org . "8.0")
  2379. :group 'org-agenda-custom-commands
  2380. :type '(choice (symbol :tag "No limit" nil)
  2381. (integer :tag "Max number of minutes")
  2382. (repeat
  2383. (cons (choice :tag "Agenda type"
  2384. (const agenda)
  2385. (const todo)
  2386. (const tags)
  2387. (const search)
  2388. (const timeline))
  2389. (integer :tag "Max number of minutes")))))
  2390. (defvar org-keys nil)
  2391. (defvar org-match nil)
  2392. ;;;###autoload
  2393. (defun org-agenda (&optional arg org-keys restriction)
  2394. "Dispatch agenda commands to collect entries to the agenda buffer.
  2395. Prompts for a command to execute. Any prefix arg will be passed
  2396. on to the selected command. The default selections are:
  2397. a Call `org-agenda-list' to display the agenda for current day or week.
  2398. t Call `org-todo-list' to display the global todo list.
  2399. T Call `org-todo-list' to display the global todo list, select only
  2400. entries with a specific TODO keyword (the user gets a prompt).
  2401. m Call `org-tags-view' to display headlines with tags matching
  2402. a condition (the user is prompted for the condition).
  2403. M Like `m', but select only TODO entries, no ordinary headlines.
  2404. L Create a timeline for the current buffer.
  2405. e Export views to associated files.
  2406. s Search entries for keywords.
  2407. S Search entries for keywords, only with TODO keywords.
  2408. / Multi occur across all agenda files and also files listed
  2409. in `org-agenda-text-search-extra-files'.
  2410. < Restrict agenda commands to buffer, subtree, or region.
  2411. Press several times to get the desired effect.
  2412. > Remove a previous restriction.
  2413. # List \"stuck\" projects.
  2414. ! Configure what \"stuck\" means.
  2415. C Configure custom agenda commands.
  2416. More commands can be added by configuring the variable
  2417. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2418. searches can be pre-defined in this way.
  2419. If the current buffer is in Org-mode and visiting a file, you can also
  2420. first press `<' once to indicate that the agenda should be temporarily
  2421. \(until the next use of \\[org-agenda]) restricted to the current file.
  2422. Pressing `<' twice means to restrict to the current subtree or region
  2423. \(if active)."
  2424. (interactive "P")
  2425. (catch 'exit
  2426. (let* ((prefix-descriptions nil)
  2427. (org-agenda-buffer-name org-agenda-buffer-name)
  2428. (org-agenda-window-setup (if (equal (buffer-name)
  2429. org-agenda-buffer-name)
  2430. 'current-window
  2431. org-agenda-window-setup))
  2432. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2433. (org-agenda-custom-commands
  2434. ;; normalize different versions
  2435. (delq nil
  2436. (mapcar
  2437. (lambda (x)
  2438. (cond ((stringp (cdr x))
  2439. (push x prefix-descriptions)
  2440. nil)
  2441. ((stringp (nth 1 x)) x)
  2442. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2443. (t (cons (car x) (cons "" (cdr x))))))
  2444. org-agenda-custom-commands)))
  2445. (org-agenda-custom-commands
  2446. (org-contextualize-keys
  2447. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2448. (buf (current-buffer))
  2449. (bfn (buffer-file-name (buffer-base-buffer)))
  2450. entry key type org-match lprops ans)
  2451. ;; Turn off restriction unless there is an overriding one,
  2452. (unless org-agenda-overriding-restriction
  2453. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2454. ;; There is a request to keep the file list in place
  2455. (put 'org-agenda-files 'org-restrict nil))
  2456. (setq org-agenda-restrict nil)
  2457. (move-marker org-agenda-restrict-begin nil)
  2458. (move-marker org-agenda-restrict-end nil))
  2459. ;; Delete old local properties
  2460. (put 'org-agenda-redo-command 'org-lprops nil)
  2461. ;; Delete previously set last-arguments
  2462. (put 'org-agenda-redo-command 'last-args nil)
  2463. ;; Remember where this call originated
  2464. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2465. (unless org-keys
  2466. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2467. org-keys (car ans)
  2468. restriction (cdr ans)))
  2469. ;; If we have sticky agenda buffers, set a name for the buffer,
  2470. ;; depending on the invoking keys. The user may still set this
  2471. ;; as a command option, which will overwrite what we do here.
  2472. (if org-agenda-sticky
  2473. (setq org-agenda-buffer-name
  2474. (format "*Org Agenda(%s)*" org-keys)))
  2475. ;; Establish the restriction, if any
  2476. (when (and (not org-agenda-overriding-restriction) restriction)
  2477. (put 'org-agenda-files 'org-restrict (list bfn))
  2478. (cond
  2479. ((eq restriction 'region)
  2480. (setq org-agenda-restrict (current-buffer))
  2481. (move-marker org-agenda-restrict-begin (region-beginning))
  2482. (move-marker org-agenda-restrict-end (region-end)))
  2483. ((eq restriction 'subtree)
  2484. (save-excursion
  2485. (setq org-agenda-restrict (current-buffer))
  2486. (org-back-to-heading t)
  2487. (move-marker org-agenda-restrict-begin (point))
  2488. (move-marker org-agenda-restrict-end
  2489. (progn (org-end-of-subtree t)))))))
  2490. ;; For example the todo list should not need it (but does...)
  2491. (cond
  2492. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2493. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2494. (progn
  2495. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2496. lprops (nth 4 entry))
  2497. (if org-agenda-sticky
  2498. (setq org-agenda-buffer-name
  2499. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2500. (format "*Org Agenda(%s)*" org-keys))))
  2501. (put 'org-agenda-redo-command 'org-lprops lprops)
  2502. (cond
  2503. ((eq type 'agenda)
  2504. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2505. ((eq type 'agenda*)
  2506. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2507. ((eq type 'alltodo)
  2508. (org-let lprops '(org-todo-list current-prefix-arg)))
  2509. ((eq type 'search)
  2510. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2511. ((eq type 'stuck)
  2512. (org-let lprops '(org-agenda-list-stuck-projects
  2513. current-prefix-arg)))
  2514. ((eq type 'tags)
  2515. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2516. ((eq type 'tags-todo)
  2517. (org-let lprops '(org-tags-view '(4) org-match)))
  2518. ((eq type 'todo)
  2519. (org-let lprops '(org-todo-list org-match)))
  2520. ((eq type 'tags-tree)
  2521. (org-check-for-org-mode)
  2522. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2523. ((eq type 'todo-tree)
  2524. (org-check-for-org-mode)
  2525. (org-let lprops
  2526. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2527. (regexp-quote org-match) "\\>"))))
  2528. ((eq type 'occur-tree)
  2529. (org-check-for-org-mode)
  2530. (org-let lprops '(org-occur org-match)))
  2531. ((functionp type)
  2532. (org-let lprops '(funcall type org-match)))
  2533. ((fboundp type)
  2534. (org-let lprops '(funcall type org-match)))
  2535. (t (user-error "Invalid custom agenda command type %s" type))))
  2536. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2537. ((equal org-keys "C")
  2538. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2539. (customize-variable 'org-agenda-custom-commands))
  2540. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2541. ((equal org-keys "s") (call-interactively 'org-search-view))
  2542. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2543. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2544. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2545. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2546. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2547. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2548. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2549. (org-add-hook
  2550. 'post-command-hook
  2551. (lambda ()
  2552. (unless (current-message)
  2553. (let* ((m (org-agenda-get-any-marker))
  2554. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2555. (when note
  2556. (message (concat
  2557. "FLAGGING-NOTE ([?] for more info): "
  2558. (org-add-props
  2559. (replace-regexp-in-string
  2560. "\\\\n" "//"
  2561. (copy-sequence note))
  2562. nil 'face 'org-warning)))))))
  2563. t t))
  2564. ((equal org-keys "L")
  2565. (unless (derived-mode-p 'org-mode)
  2566. (user-error "This is not an Org-mode file"))
  2567. (unless restriction
  2568. (put 'org-agenda-files 'org-restrict (list bfn))
  2569. (org-call-with-arg 'org-timeline arg)))
  2570. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2571. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2572. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2573. (t (user-error "Invalid agenda key"))))))
  2574. (defvar org-agenda-multi)
  2575. (defun org-agenda-append-agenda ()
  2576. "Append another agenda view to the current one.
  2577. This function allows interactive building of block agendas.
  2578. Agenda views are separated by `org-agenda-block-separator'."
  2579. (interactive)
  2580. (unless (derived-mode-p 'org-agenda-mode)
  2581. (user-error "Can only append from within agenda buffer"))
  2582. (let ((org-agenda-multi t))
  2583. (org-agenda)
  2584. (widen)
  2585. (org-agenda-finalize)
  2586. (setq buffer-read-only t)
  2587. (org-agenda-fit-window-to-buffer)))
  2588. (defun org-agenda-normalize-custom-commands (cmds)
  2589. "Normalize custom commands CMDS."
  2590. (delq nil
  2591. (mapcar
  2592. (lambda (x)
  2593. (cond ((stringp (cdr x)) nil)
  2594. ((stringp (nth 1 x)) x)
  2595. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2596. (t (cons (car x) (cons "" (cdr x))))))
  2597. cmds)))
  2598. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2599. "The user interface for selecting an agenda command."
  2600. (catch 'exit
  2601. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2602. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2603. (region-p (org-region-active-p))
  2604. (custom org-agenda-custom-commands)
  2605. (selstring "")
  2606. restriction second-time
  2607. c entry key type match prefixes rmheader header-end custom1 desc
  2608. line lines left right n n1)
  2609. (save-window-excursion
  2610. (delete-other-windows)
  2611. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2612. (erase-buffer)
  2613. (insert (eval-when-compile
  2614. (let ((header
  2615. "Press key for an agenda command: < Buffer, subtree/region restriction
  2616. -------------------------------- > Remove restriction
  2617. a Agenda for current week or day e Export agenda views
  2618. t List of all TODO entries T Entries with special TODO kwd
  2619. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2620. s Search for keywords S Like s, but only TODO entries
  2621. L Timeline for current buffer # List stuck projects (!=configure)
  2622. / Multi-occur C Configure custom agenda commands
  2623. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2624. ")
  2625. (start 0))
  2626. (while (string-match
  2627. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2628. header start)
  2629. (setq start (match-end 0))
  2630. (add-text-properties (match-beginning 2) (match-end 2)
  2631. '(face bold) header))
  2632. header)))
  2633. (setq header-end (point-marker))
  2634. (while t
  2635. (setq custom1 custom)
  2636. (when (eq rmheader t)
  2637. (org-goto-line 1)
  2638. (re-search-forward ":" nil t)
  2639. (delete-region (match-end 0) (point-at-eol))
  2640. (forward-char 1)
  2641. (looking-at "-+")
  2642. (delete-region (match-end 0) (point-at-eol))
  2643. (move-marker header-end (match-end 0)))
  2644. (goto-char header-end)
  2645. (delete-region (point) (point-max))
  2646. ;; Produce all the lines that describe custom commands and prefixes
  2647. (setq lines nil)
  2648. (while (setq entry (pop custom1))
  2649. (setq key (car entry) desc (nth 1 entry)
  2650. type (nth 2 entry)
  2651. match (nth 3 entry))
  2652. (if (> (length key) 1)
  2653. (add-to-list 'prefixes (string-to-char key))
  2654. (setq line
  2655. (format
  2656. "%-4s%-14s"
  2657. (org-add-props (copy-sequence key)
  2658. '(face bold))
  2659. (cond
  2660. ((string-match "\\S-" desc) desc)
  2661. ((eq type 'agenda) "Agenda for current week or day")
  2662. ((eq type 'agenda*) "Appointments for current week or day")
  2663. ((eq type 'alltodo) "List of all TODO entries")
  2664. ((eq type 'search) "Word search")
  2665. ((eq type 'stuck) "List of stuck projects")
  2666. ((eq type 'todo) "TODO keyword")
  2667. ((eq type 'tags) "Tags query")
  2668. ((eq type 'tags-todo) "Tags (TODO)")
  2669. ((eq type 'tags-tree) "Tags tree")
  2670. ((eq type 'todo-tree) "TODO kwd tree")
  2671. ((eq type 'occur-tree) "Occur tree")
  2672. ((functionp type) (if (symbolp type)
  2673. (symbol-name type)
  2674. "Lambda expression"))
  2675. (t "???"))))
  2676. (if org-agenda-menu-show-matcher
  2677. (setq line
  2678. (concat line ": "
  2679. (cond
  2680. ((stringp match)
  2681. (setq match (copy-sequence match))
  2682. (org-add-props match nil 'face 'org-warning))
  2683. ((listp type)
  2684. (format "set of %d commands" (length type))))))
  2685. (if (org-string-nw-p match)
  2686. (add-text-properties
  2687. 0 (length line) (list 'help-echo
  2688. (concat "Matcher: " match)) line)))
  2689. (push line lines)))
  2690. (setq lines (nreverse lines))
  2691. (when prefixes
  2692. (mapc (lambda (x)
  2693. (push
  2694. (format "%s %s"
  2695. (org-add-props (char-to-string x)
  2696. nil 'face 'bold)
  2697. (or (cdr (assoc (concat selstring
  2698. (char-to-string x))
  2699. prefix-descriptions))
  2700. "Prefix key"))
  2701. lines))
  2702. prefixes))
  2703. ;; Check if we should display in two columns
  2704. (if org-agenda-menu-two-columns
  2705. (progn
  2706. (setq n (length lines)
  2707. n1 (+ (/ n 2) (mod n 2))
  2708. right (nthcdr n1 lines)
  2709. left (copy-sequence lines))
  2710. (setcdr (nthcdr (1- n1) left) nil))
  2711. (setq left lines right nil))
  2712. (while left
  2713. (insert "\n" (pop left))
  2714. (when right
  2715. (if (< (current-column) 40)
  2716. (move-to-column 40 t)
  2717. (insert " "))
  2718. (insert (pop right))))
  2719. ;; Make the window the right size
  2720. (goto-char (point-min))
  2721. (if second-time
  2722. (if (not (pos-visible-in-window-p (point-max)))
  2723. (org-fit-window-to-buffer))
  2724. (setq second-time t)
  2725. (org-fit-window-to-buffer))
  2726. ;; Ask for selection
  2727. (message "Press key for agenda command%s:"
  2728. (if (or restrict-ok org-agenda-overriding-restriction)
  2729. (if org-agenda-overriding-restriction
  2730. " (restriction lock active)"
  2731. (if restriction
  2732. (format " (restricted to %s)" restriction)
  2733. " (unrestricted)"))
  2734. ""))
  2735. (setq c (read-char-exclusive))
  2736. (message "")
  2737. (cond
  2738. ((assoc (char-to-string c) custom)
  2739. (setq selstring (concat selstring (char-to-string c)))
  2740. (throw 'exit (cons selstring restriction)))
  2741. ((memq c prefixes)
  2742. (setq selstring (concat selstring (char-to-string c))
  2743. prefixes nil
  2744. rmheader (or rmheader t)
  2745. custom (delq nil (mapcar
  2746. (lambda (x)
  2747. (if (or (= (length (car x)) 1)
  2748. (/= (string-to-char (car x)) c))
  2749. nil
  2750. (cons (substring (car x) 1) (cdr x))))
  2751. custom))))
  2752. ((eq c ?*)
  2753. (call-interactively 'org-toggle-sticky-agenda)
  2754. (sit-for 2))
  2755. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2756. (message "Restriction is only possible in Org-mode buffers")
  2757. (ding) (sit-for 1))
  2758. ((eq c ?1)
  2759. (org-agenda-remove-restriction-lock 'noupdate)
  2760. (setq restriction 'buffer))
  2761. ((eq c ?0)
  2762. (org-agenda-remove-restriction-lock 'noupdate)
  2763. (setq restriction (if region-p 'region 'subtree)))
  2764. ((eq c ?<)
  2765. (org-agenda-remove-restriction-lock 'noupdate)
  2766. (setq restriction
  2767. (cond
  2768. ((eq restriction 'buffer)
  2769. (if region-p 'region 'subtree))
  2770. ((memq restriction '(subtree region))
  2771. nil)
  2772. (t 'buffer))))
  2773. ((eq c ?>)
  2774. (org-agenda-remove-restriction-lock 'noupdate)
  2775. (setq restriction nil))
  2776. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2777. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2778. ((and (> (length selstring) 0) (eq c ?\d))
  2779. (delete-window)
  2780. (org-agenda-get-restriction-and-command prefix-descriptions))
  2781. ((equal c ?q) (error "Abort"))
  2782. (t (user-error "Invalid key %c" c))))))))
  2783. (defun org-agenda-fit-window-to-buffer ()
  2784. "Fit the window to the buffer size."
  2785. (and (memq org-agenda-window-setup '(reorganize-frame))
  2786. (fboundp 'fit-window-to-buffer)
  2787. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2788. (= (car org-agenda-window-frame-fractions) 1.0))
  2789. (delete-other-windows)
  2790. (org-fit-window-to-buffer
  2791. nil
  2792. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2793. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2794. (defvar org-cmd nil)
  2795. (defvar org-agenda-overriding-cmd nil)
  2796. (defvar org-agenda-overriding-arguments nil)
  2797. (defvar org-agenda-overriding-cmd-arguments nil)
  2798. (defun org-agenda-run-series (name series)
  2799. "Run agenda NAME as a SERIES of agenda commands."
  2800. (org-let (nth 1 series) '(org-agenda-prepare name))
  2801. ;; We need to reset agenda markers here, because when constructing a
  2802. ;; block agenda, the individual blocks do not do that.
  2803. (org-agenda-reset-markers)
  2804. (let* ((org-agenda-multi t)
  2805. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2806. (cmds (car series))
  2807. (gprops (nth 1 series))
  2808. match ;; The byte compiler incorrectly complains about this. Keep it!
  2809. org-cmd type lprops)
  2810. (while (setq org-cmd (pop cmds))
  2811. (setq type (car org-cmd)
  2812. match (eval (nth 1 org-cmd))
  2813. lprops (nth 2 org-cmd))
  2814. (let ((org-agenda-overriding-arguments
  2815. (if (eq org-agenda-overriding-cmd org-cmd)
  2816. (or org-agenda-overriding-arguments
  2817. org-agenda-overriding-cmd-arguments))))
  2818. (cond
  2819. ((eq type 'agenda)
  2820. (org-let2 gprops lprops
  2821. '(call-interactively 'org-agenda-list)))
  2822. ((eq type 'agenda*)
  2823. (org-let2 gprops lprops
  2824. '(funcall 'org-agenda-list nil nil t)))
  2825. ((eq type 'alltodo)
  2826. (org-let2 gprops lprops
  2827. '(call-interactively 'org-todo-list)))
  2828. ((eq type 'search)
  2829. (org-let2 gprops lprops
  2830. '(org-search-view current-prefix-arg match nil)))
  2831. ((eq type 'stuck)
  2832. (org-let2 gprops lprops
  2833. '(call-interactively 'org-agenda-list-stuck-projects)))
  2834. ((eq type 'tags)
  2835. (org-let2 gprops lprops
  2836. '(org-tags-view current-prefix-arg match)))
  2837. ((eq type 'tags-todo)
  2838. (org-let2 gprops lprops
  2839. '(org-tags-view '(4) match)))
  2840. ((eq type 'todo)
  2841. (org-let2 gprops lprops
  2842. '(org-todo-list match)))
  2843. ((fboundp type)
  2844. (org-let2 gprops lprops
  2845. '(funcall type match)))
  2846. (t (error "Invalid type in command series")))))
  2847. (widen)
  2848. (let ((inhibit-read-only t))
  2849. (add-text-properties (point-min) (point-max)
  2850. `(org-series t org-series-redo-cmd ,redo)))
  2851. (setq org-agenda-redo-command redo)
  2852. (goto-char (point-min)))
  2853. (org-agenda-fit-window-to-buffer)
  2854. (org-let (nth 1 series) '(org-agenda-finalize)))
  2855. ;;;###autoload
  2856. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2857. "Run an agenda command in batch mode and send the result to STDOUT.
  2858. If CMD-KEY is a string of length 1, it is used as a key in
  2859. `org-agenda-custom-commands' and triggers this command. If it is a
  2860. longer string it is used as a tags/todo match string.
  2861. Parameters are alternating variable names and values that will be bound
  2862. before running the agenda command."
  2863. (org-eval-in-environment (org-make-parameter-alist parameters)
  2864. (let (org-agenda-sticky)
  2865. (if (> (length cmd-key) 1)
  2866. (org-tags-view nil cmd-key)
  2867. (org-agenda nil cmd-key))))
  2868. (set-buffer org-agenda-buffer-name)
  2869. (princ (buffer-string)))
  2870. (defvar org-agenda-info nil)
  2871. ;;;###autoload
  2872. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2873. "Run an agenda command in batch mode and send the result to STDOUT.
  2874. If CMD-KEY is a string of length 1, it is used as a key in
  2875. `org-agenda-custom-commands' and triggers this command. If it is a
  2876. longer string it is used as a tags/todo match string.
  2877. Parameters are alternating variable names and values that will be bound
  2878. before running the agenda command.
  2879. The output gives a line for each selected agenda item. Each
  2880. item is a list of comma-separated values, like this:
  2881. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2882. category The category of the item
  2883. head The headline, without TODO kwd, TAGS and PRIORITY
  2884. type The type of the agenda entry, can be
  2885. todo selected in TODO match
  2886. tagsmatch selected in tags match
  2887. diary imported from diary
  2888. deadline a deadline on given date
  2889. scheduled scheduled on given date
  2890. timestamp entry has timestamp on given date
  2891. closed entry was closed on given date
  2892. upcoming-deadline warning about deadline
  2893. past-scheduled forwarded scheduled item
  2894. block entry has date block including g. date
  2895. todo The todo keyword, if any
  2896. tags All tags including inherited ones, separated by colons
  2897. date The relevant date, like 2007-2-14
  2898. time The time, like 15:00-16:50
  2899. extra Sting with extra planning info
  2900. priority-l The priority letter if any was given
  2901. priority-n The computed numerical priority
  2902. agenda-day The day in the agenda where this is listed"
  2903. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2904. (org-make-parameter-alist parameters))
  2905. (if (> (length cmd-key) 2)
  2906. (org-tags-view nil cmd-key)
  2907. (org-agenda nil cmd-key)))
  2908. (set-buffer org-agenda-buffer-name)
  2909. (let* ((lines (org-split-string (buffer-string) "\n"))
  2910. line)
  2911. (while (setq line (pop lines))
  2912. (catch 'next
  2913. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2914. (setq org-agenda-info
  2915. (org-fix-agenda-info (text-properties-at 0 line)))
  2916. (princ
  2917. (mapconcat 'org-agenda-export-csv-mapper
  2918. '(org-category txt type todo tags date time extra
  2919. priority-letter priority agenda-day)
  2920. ","))
  2921. (princ "\n")))))
  2922. (defun org-fix-agenda-info (props)
  2923. "Make sure all properties on an agenda item have a canonical form.
  2924. This ensures the export commands can easily use it."
  2925. (let (tmp re)
  2926. (when (setq tmp (plist-get props 'tags))
  2927. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2928. (when (setq tmp (plist-get props 'date))
  2929. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2930. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2931. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2932. (setq tmp (calendar-date-string tmp)))
  2933. (setq props (plist-put props 'date tmp)))
  2934. (when (setq tmp (plist-get props 'day))
  2935. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2936. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2937. (setq tmp (calendar-date-string tmp)))
  2938. (setq props (plist-put props 'day tmp))
  2939. (setq props (plist-put props 'agenda-day tmp)))
  2940. (when (setq tmp (plist-get props 'txt))
  2941. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2942. (plist-put props 'priority-letter (match-string 1 tmp))
  2943. (setq tmp (replace-match "" t t tmp)))
  2944. (when (and (setq re (plist-get props 'org-todo-regexp))
  2945. (setq re (concat "\\`\\.*" re " ?"))
  2946. (string-match re tmp))
  2947. (plist-put props 'todo (match-string 1 tmp))
  2948. (setq tmp (replace-match "" t t tmp)))
  2949. (plist-put props 'txt tmp)))
  2950. props)
  2951. (defun org-agenda-export-csv-mapper (prop)
  2952. (let ((res (plist-get org-agenda-info prop)))
  2953. (setq res
  2954. (cond
  2955. ((not res) "")
  2956. ((stringp res) res)
  2957. (t (prin1-to-string res))))
  2958. (while (string-match "," res)
  2959. (setq res (replace-match ";" t t res)))
  2960. (org-trim res)))
  2961. ;;;###autoload
  2962. (defun org-store-agenda-views (&rest parameters)
  2963. "Store agenda views."
  2964. (interactive)
  2965. (eval (list 'org-batch-store-agenda-views)))
  2966. ;;;###autoload
  2967. (defmacro org-batch-store-agenda-views (&rest parameters)
  2968. "Run all custom agenda commands that have a file argument."
  2969. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2970. (pop-up-frames nil)
  2971. (dir default-directory)
  2972. (pars (org-make-parameter-alist parameters))
  2973. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2974. (save-window-excursion
  2975. (while cmds
  2976. (setq cmd (pop cmds)
  2977. thiscmdkey (car cmd)
  2978. thiscmdcmd (cdr cmd)
  2979. match (nth 2 thiscmdcmd)
  2980. bufname (if org-agenda-sticky
  2981. (or (and (stringp match)
  2982. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2983. (format "*Org Agenda(%s)*" thiscmdkey))
  2984. org-agenda-buffer-name)
  2985. cmd-or-set (nth 2 cmd)
  2986. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2987. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2988. (if (stringp files) (setq files (list files)))
  2989. (when files
  2990. (org-eval-in-environment (append org-agenda-exporter-settings
  2991. opts pars)
  2992. (org-agenda nil thiscmdkey))
  2993. (set-buffer bufname)
  2994. (while files
  2995. (org-eval-in-environment (append org-agenda-exporter-settings
  2996. opts pars)
  2997. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2998. (and (get-buffer bufname)
  2999. (kill-buffer bufname)))))))
  3000. (defvar org-agenda-current-span nil
  3001. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3002. (defun org-agenda-mark-header-line (pos)
  3003. "Mark the line at POS as an agenda structure header."
  3004. (save-excursion
  3005. (goto-char pos)
  3006. (put-text-property (point-at-bol) (point-at-eol)
  3007. 'org-agenda-structural-header t)
  3008. (when org-agenda-title-append
  3009. (put-text-property (point-at-bol) (point-at-eol)
  3010. 'org-agenda-title-append org-agenda-title-append))))
  3011. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3012. (defvar org-agenda-write-buffer-name "Agenda View")
  3013. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3014. "Write the current buffer (an agenda view) as a file.
  3015. Depending on the extension of the file name, plain text (.txt),
  3016. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3017. If the extension is .ics, translate visible agenda into iCalendar
  3018. format. If the extension is .org, collect all subtrees
  3019. corresponding to the agenda entries and add them in an .org file.
  3020. With prefix argument OPEN, open the new file immediately. If
  3021. NOSETTINGS is given, do not scope the settings of
  3022. `org-agenda-exporter-settings' into the export commands. This is
  3023. used when the settings have already been scoped and we do not
  3024. wish to overrule other, higher priority settings. If
  3025. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3026. the agenda to write."
  3027. (interactive "FWrite agenda to file: \nP")
  3028. (if (or (not (file-writable-p file))
  3029. (and (file-exists-p file)
  3030. (if (org-called-interactively-p 'any)
  3031. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3032. (user-error "Cannot write agenda to file %s" file))
  3033. (org-let (if nosettings nil org-agenda-exporter-settings)
  3034. '(save-excursion
  3035. (save-window-excursion
  3036. (let ((bs (copy-sequence (buffer-string))) beg content)
  3037. (with-temp-buffer
  3038. (rename-buffer org-agenda-write-buffer-name t)
  3039. (set-buffer-modified-p nil)
  3040. (insert bs)
  3041. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3042. (run-hooks 'org-agenda-before-write-hook)
  3043. (cond
  3044. ((org-bound-and-true-p org-mobile-creating-agendas)
  3045. (org-mobile-write-agenda-for-mobile file))
  3046. ((string-match "\\.org\\'" file)
  3047. (let (content p m message-log-max)
  3048. (goto-char (point-min))
  3049. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3050. (goto-char p)
  3051. (setq m (get-text-property (point) 'org-hd-marker))
  3052. (when m
  3053. (push (save-excursion
  3054. (set-buffer (marker-buffer m))
  3055. (goto-char m)
  3056. (org-copy-subtree 1 nil t t)
  3057. org-subtree-clip)
  3058. content)))
  3059. (find-file file)
  3060. (erase-buffer)
  3061. (dolist (s content) (org-paste-subtree 1 s))
  3062. (write-file file)
  3063. (kill-buffer (current-buffer))
  3064. (message "Org file written to %s" file)))
  3065. ((string-match "\\.html?\\'" file)
  3066. (require 'htmlize)
  3067. (set-buffer (htmlize-buffer (current-buffer)))
  3068. (when org-agenda-export-html-style
  3069. ;; replace <style> section with org-agenda-export-html-style
  3070. (goto-char (point-min))
  3071. (kill-region (- (search-forward "<style") 6)
  3072. (search-forward "</style>"))
  3073. (insert org-agenda-export-html-style))
  3074. (write-file file)
  3075. (kill-buffer (current-buffer))
  3076. (message "HTML written to %s" file))
  3077. ((string-match "\\.ps\\'" file)
  3078. (require 'ps-print)
  3079. (ps-print-buffer-with-faces file)
  3080. (message "Postscript written to %s" file))
  3081. ((string-match "\\.pdf\\'" file)
  3082. (require 'ps-print)
  3083. (ps-print-buffer-with-faces
  3084. (concat (file-name-sans-extension file) ".ps"))
  3085. (call-process "ps2pdf" nil nil nil
  3086. (expand-file-name
  3087. (concat (file-name-sans-extension file) ".ps"))
  3088. (expand-file-name file))
  3089. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3090. (message "PDF written to %s" file))
  3091. ((string-match "\\.ics\\'" file)
  3092. (require 'ox-icalendar)
  3093. (org-icalendar-export-current-agenda (expand-file-name file)))
  3094. (t
  3095. (let ((bs (buffer-string)))
  3096. (find-file file)
  3097. (erase-buffer)
  3098. (insert bs)
  3099. (save-buffer 0)
  3100. (kill-buffer (current-buffer))
  3101. (message "Plain text written to %s" file))))))))
  3102. (set-buffer (or agenda-bufname
  3103. (and (org-called-interactively-p 'any) (buffer-name))
  3104. org-agenda-buffer-name)))
  3105. (when open (org-open-file file)))
  3106. (defun org-agenda-remove-marked-text (property &optional value)
  3107. "Delete all text marked with VALUE of PROPERTY.
  3108. VALUE defaults to t."
  3109. (let (beg)
  3110. (setq value (or value t))
  3111. (while (setq beg (text-property-any (point-min) (point-max)
  3112. property value))
  3113. (delete-region
  3114. beg (or (next-single-property-change beg property)
  3115. (point-max))))))
  3116. (defun org-agenda-add-entry-text ()
  3117. "Add entry text to agenda lines.
  3118. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3119. entry text following headings shown in the agenda.
  3120. Drawers will be excluded, also the line with scheduling/deadline info."
  3121. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3122. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3123. (let (m txt)
  3124. (goto-char (point-min))
  3125. (while (not (eobp))
  3126. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3127. (beginning-of-line 2)
  3128. (setq txt (org-agenda-get-some-entry-text
  3129. m org-agenda-add-entry-text-maxlines " > "))
  3130. (end-of-line 1)
  3131. (if (string-match "\\S-" txt)
  3132. (insert "\n" txt)
  3133. (or (eobp) (forward-char 1))))))))
  3134. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3135. &rest keep)
  3136. "Extract entry text from MARKER, at most N-LINES lines.
  3137. This will ignore drawers etc, just get the text.
  3138. If INDENT is given, prefix every line with this string. If KEEP is
  3139. given, it is a list of symbols, defining stuff that should not be
  3140. removed from the entry content. Currently only `planning' is allowed here."
  3141. (let (txt drawer-re kwd-time-re ind)
  3142. (save-excursion
  3143. (with-current-buffer (marker-buffer marker)
  3144. (if (not (derived-mode-p 'org-mode))
  3145. (setq txt "")
  3146. (save-excursion
  3147. (save-restriction
  3148. (widen)
  3149. (goto-char marker)
  3150. (end-of-line 1)
  3151. (setq txt (buffer-substring
  3152. (min (1+ (point)) (point-max))
  3153. (progn (outline-next-heading) (point)))
  3154. drawer-re org-drawer-regexp
  3155. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3156. ".*\n?"))
  3157. (with-temp-buffer
  3158. (insert txt)
  3159. (when org-agenda-add-entry-text-descriptive-links
  3160. (goto-char (point-min))
  3161. (while (org-activate-bracket-links (point-max))
  3162. (add-text-properties (match-beginning 0) (match-end 0)
  3163. '(face org-link))))
  3164. (goto-char (point-min))
  3165. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3166. (set-text-properties (match-beginning 0) (match-end 0)
  3167. nil))
  3168. (goto-char (point-min))
  3169. (while (re-search-forward drawer-re nil t)
  3170. (delete-region
  3171. (match-beginning 0)
  3172. (progn (re-search-forward
  3173. "^[ \t]*:END:.*\n?" nil 'move)
  3174. (point))))
  3175. (unless (member 'planning keep)
  3176. (goto-char (point-min))
  3177. (while (re-search-forward kwd-time-re nil t)
  3178. (replace-match "")))
  3179. (goto-char (point-min))
  3180. (when org-agenda-entry-text-exclude-regexps
  3181. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3182. (while (setq re (pop re-list))
  3183. (goto-char (point-min))
  3184. (while (re-search-forward re nil t)
  3185. (replace-match "")))))
  3186. (goto-char (point-max))
  3187. (skip-chars-backward " \t\n")
  3188. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3189. ;; find and remove min common indentation
  3190. (goto-char (point-min))
  3191. (untabify (point-min) (point-max))
  3192. (setq ind (org-get-indentation))
  3193. (while (not (eobp))
  3194. (unless (looking-at "[ \t]*$")
  3195. (setq ind (min ind (org-get-indentation))))
  3196. (beginning-of-line 2))
  3197. (goto-char (point-min))
  3198. (while (not (eobp))
  3199. (unless (looking-at "[ \t]*$")
  3200. (move-to-column ind)
  3201. (delete-region (point-at-bol) (point)))
  3202. (beginning-of-line 2))
  3203. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3204. (goto-char (point-min))
  3205. (when indent
  3206. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3207. (replace-match indent t t)))
  3208. (goto-char (point-min))
  3209. (while (looking-at "[ \t]*\n") (replace-match ""))
  3210. (goto-char (point-max))
  3211. (when (> (org-current-line)
  3212. n-lines)
  3213. (org-goto-line (1+ n-lines))
  3214. (backward-char 1))
  3215. (setq txt (buffer-substring (point-min) (point)))))))))
  3216. txt))
  3217. (defun org-check-for-org-mode ()
  3218. "Make sure current buffer is in org-mode. Error if not."
  3219. (or (derived-mode-p 'org-mode)
  3220. (error "Cannot execute org-mode agenda command on buffer in %s"
  3221. major-mode)))
  3222. ;;; Agenda prepare and finalize
  3223. (defvar org-agenda-multi nil) ; dynamically scoped
  3224. (defvar org-agenda-pre-window-conf nil)
  3225. (defvar org-agenda-columns-active nil)
  3226. (defvar org-agenda-name nil)
  3227. (defvar org-agenda-tag-filter nil)
  3228. (defvar org-agenda-category-filter nil)
  3229. (defvar org-agenda-regexp-filter nil)
  3230. (defvar org-agenda-effort-filter nil)
  3231. (defvar org-agenda-top-headline-filter nil)
  3232. (defvar org-agenda-tag-filter-preset nil
  3233. "A preset of the tags filter used for secondary agenda filtering.
  3234. This must be a list of strings, each string must be a single tag preceded
  3235. by \"+\" or \"-\".
  3236. This variable should not be set directly, but agenda custom commands can
  3237. bind it in the options section. The preset filter is a global property of
  3238. the entire agenda view. In a block agenda, it will not work reliably to
  3239. define a filter for one of the individual blocks. You need to set it in
  3240. the global options and expect it to be applied to the entire view.")
  3241. (defvar org-agenda-category-filter-preset nil
  3242. "A preset of the category filter used for secondary agenda filtering.
  3243. This must be a list of strings, each string must be a single category
  3244. preceded by \"+\" or \"-\".
  3245. This variable should not be set directly, but agenda custom commands can
  3246. bind it in the options section. The preset filter is a global property of
  3247. the entire agenda view. In a block agenda, it will not work reliably to
  3248. define a filter for one of the individual blocks. You need to set it in
  3249. the global options and expect it to be applied to the entire view.")
  3250. (defvar org-agenda-regexp-filter-preset nil
  3251. "A preset of the regexp filter used for secondary agenda filtering.
  3252. This must be a list of strings, each string must be a single regexp
  3253. preceded by \"+\" or \"-\".
  3254. This variable should not be set directly, but agenda custom commands can
  3255. bind it in the options section. The preset filter is a global property of
  3256. the entire agenda view. In a block agenda, it will not work reliably to
  3257. define a filter for one of the individual blocks. You need to set it in
  3258. the global options and expect it to be applied to the entire view.")
  3259. (defvar org-agenda-effort-filter-preset nil
  3260. "A preset of the effort condition used for secondary agenda filtering.
  3261. This must be a list of strings, each string must be a single regexp
  3262. preceded by \"+\" or \"-\".
  3263. This variable should not be set directly, but agenda custom commands can
  3264. bind it in the options section. The preset filter is a global property of
  3265. the entire agenda view. In a block agenda, it will not work reliably to
  3266. define a filter for one of the individual blocks. You need to set it in
  3267. the global options and expect it to be applied to the entire view.")
  3268. (defun org-agenda-use-sticky-p ()
  3269. "Return non-nil if an agenda buffer named
  3270. `org-agenda-buffer-name' exists and should be shown instead of
  3271. generating a new one."
  3272. (and
  3273. ;; turned off by user
  3274. org-agenda-sticky
  3275. ;; For multi-agenda buffer already exists
  3276. (not org-agenda-multi)
  3277. ;; buffer found
  3278. (get-buffer org-agenda-buffer-name)
  3279. ;; C-u parameter is same as last call
  3280. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3281. (and
  3282. (equal current-prefix-arg
  3283. org-agenda-last-prefix-arg)
  3284. ;; In case user turned stickiness on, while having existing
  3285. ;; Agenda buffer active, don't reuse that buffer, because it
  3286. ;; does not have org variables local
  3287. org-agenda-this-buffer-is-sticky))))
  3288. (defun org-agenda-prepare-window (abuf filter-alist)
  3289. "Setup agenda buffer in the window.
  3290. ABUF is the buffer for the agenda window.
  3291. FILTER-ALIST is an alist of filters we need to apply when
  3292. `org-agenda-persistent-filter' is non-nil."
  3293. (let* ((awin (get-buffer-window abuf)) wconf)
  3294. (cond
  3295. ((equal (current-buffer) abuf) nil)
  3296. (awin (select-window awin))
  3297. ((not (setq wconf (current-window-configuration))))
  3298. ((equal org-agenda-window-setup 'current-window)
  3299. (org-pop-to-buffer-same-window abuf))
  3300. ((equal org-agenda-window-setup 'other-window)
  3301. (org-switch-to-buffer-other-window abuf))
  3302. ((equal org-agenda-window-setup 'other-frame)
  3303. (switch-to-buffer-other-frame abuf))
  3304. ((eq org-agenda-window-setup 'only-window)
  3305. (delete-other-windows)
  3306. (org-pop-to-buffer-same-window abuf))
  3307. ((equal org-agenda-window-setup 'reorganize-frame)
  3308. (delete-other-windows)
  3309. (org-switch-to-buffer-other-window abuf)))
  3310. (setq org-agenda-tag-filter (cdr (assoc 'tag filter-alist)))
  3311. (setq org-agenda-category-filter (cdr (assoc 'cat filter-alist)))
  3312. (setq org-agenda-effort-filter (cdr (assoc 'effort filter-alist)))
  3313. (setq org-agenda-regexp-filter (cdr (assoc 're filter-alist)))
  3314. ;; Additional test in case agenda is invoked from within agenda
  3315. ;; buffer via elisp link.
  3316. (unless (equal (current-buffer) abuf)
  3317. (org-pop-to-buffer-same-window abuf))
  3318. (setq org-agenda-pre-window-conf
  3319. (or wconf org-agenda-pre-window-conf))))
  3320. (defun org-agenda-prepare (&optional name)
  3321. (let ((filter-alist (if org-agenda-persistent-filter
  3322. (with-current-buffer
  3323. (get-buffer-create org-agenda-buffer-name)
  3324. (list `(tag . ,org-agenda-tag-filter)
  3325. `(re . ,org-agenda-regexp-filter)
  3326. `(effort . ,org-agenda-effort-filter)
  3327. `(cat . ,org-agenda-category-filter))))))
  3328. (if (org-agenda-use-sticky-p)
  3329. (progn
  3330. (put 'org-agenda-tag-filter :preset-filter nil)
  3331. (put 'org-agenda-category-filter :preset-filter nil)
  3332. (put 'org-agenda-regexp-filter :preset-filter nil)
  3333. ;; Popup existing buffer
  3334. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3335. filter-alist)
  3336. (message "Sticky Agenda buffer, use `r' to refresh")
  3337. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3338. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3339. (setq org-todo-keywords-for-agenda nil)
  3340. (put 'org-agenda-tag-filter :preset-filter
  3341. org-agenda-tag-filter-preset)
  3342. (put 'org-agenda-category-filter :preset-filter
  3343. org-agenda-category-filter-preset)
  3344. (put 'org-agenda-regexp-filter :preset-filter
  3345. org-agenda-regexp-filter-preset)
  3346. (put 'org-agenda-effort-filter :preset-filter
  3347. org-agenda-effort-filter-preset)
  3348. (if org-agenda-multi
  3349. (progn
  3350. (setq buffer-read-only nil)
  3351. (goto-char (point-max))
  3352. (unless (or (bobp) org-agenda-compact-blocks
  3353. (not org-agenda-block-separator))
  3354. (insert "\n"
  3355. (if (stringp org-agenda-block-separator)
  3356. org-agenda-block-separator
  3357. (make-string (window-width) org-agenda-block-separator))
  3358. "\n"))
  3359. (narrow-to-region (point) (point-max)))
  3360. (setq org-done-keywords-for-agenda nil)
  3361. ;; Setting any org variables that are in org-agenda-local-vars
  3362. ;; list need to be done after the prepare call
  3363. (org-agenda-prepare-window
  3364. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3365. (setq buffer-read-only nil)
  3366. (org-agenda-reset-markers)
  3367. (let ((inhibit-read-only t)) (erase-buffer))
  3368. (org-agenda-mode)
  3369. (setq org-agenda-buffer (current-buffer))
  3370. (setq org-agenda-contributing-files nil)
  3371. (setq org-agenda-columns-active nil)
  3372. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3373. (setq org-todo-keywords-for-agenda
  3374. (org-uniquify org-todo-keywords-for-agenda))
  3375. (setq org-done-keywords-for-agenda
  3376. (org-uniquify org-done-keywords-for-agenda))
  3377. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3378. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3379. (and name (not org-agenda-name)
  3380. (setq-local org-agenda-name name)))
  3381. (setq buffer-read-only nil))))
  3382. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3383. (defun org-agenda-finalize ()
  3384. "Finishing touch for the agenda buffer, called just before displaying it."
  3385. (unless org-agenda-multi
  3386. (save-excursion
  3387. (let ((inhibit-read-only t))
  3388. (goto-char (point-min))
  3389. (save-excursion
  3390. (while (org-activate-bracket-links (point-max))
  3391. (add-text-properties (match-beginning 0) (match-end 0)
  3392. '(face org-link))))
  3393. (save-excursion
  3394. (while (org-activate-plain-links (point-max))
  3395. (add-text-properties (match-beginning 0) (match-end 0)
  3396. '(face org-link))))
  3397. (unless (eq org-agenda-remove-tags t)
  3398. (org-agenda-align-tags))
  3399. (unless org-agenda-with-colors
  3400. (remove-text-properties (point-min) (point-max) '(face nil)))
  3401. (if (and (boundp 'org-agenda-overriding-columns-format)
  3402. org-agenda-overriding-columns-format)
  3403. (setq-local org-agenda-overriding-columns-format
  3404. org-agenda-overriding-columns-format))
  3405. (if (and (boundp 'org-agenda-view-columns-initially)
  3406. org-agenda-view-columns-initially)
  3407. (org-agenda-columns))
  3408. (when org-agenda-fontify-priorities
  3409. (org-agenda-fontify-priorities))
  3410. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3411. (org-agenda-dim-blocked-tasks))
  3412. (org-agenda-mark-clocking-task)
  3413. (when org-agenda-entry-text-mode
  3414. (org-agenda-entry-text-hide)
  3415. (org-agenda-entry-text-show))
  3416. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3417. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3418. (org-habit-insert-consistency-graphs))
  3419. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3420. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3421. (and (listp org-agenda-show-inherited-tags)
  3422. (memq org-agenda-type org-agenda-show-inherited-tags))
  3423. (and (eq org-agenda-show-inherited-tags t)
  3424. (or (eq org-agenda-use-tag-inheritance t)
  3425. (and (listp org-agenda-use-tag-inheritance)
  3426. (not (memq org-agenda-type
  3427. org-agenda-use-tag-inheritance))))))
  3428. (let (mrk)
  3429. (save-excursion
  3430. (goto-char (point-min))
  3431. (while (equal (forward-line) 0)
  3432. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3433. (put-text-property (point-at-bol) (point-at-eol)
  3434. 'tags (org-with-point-at mrk
  3435. (delete-dups
  3436. (mapcar 'downcase (org-get-tags-at))))))))))
  3437. (run-hooks 'org-agenda-finalize-hook)
  3438. (when org-agenda-top-headline-filter
  3439. (org-agenda-filter-top-headline-apply
  3440. org-agenda-top-headline-filter))
  3441. (when org-agenda-tag-filter
  3442. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3443. (when (get 'org-agenda-tag-filter :preset-filter)
  3444. (org-agenda-filter-apply
  3445. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3446. (when org-agenda-category-filter
  3447. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3448. (when (get 'org-agenda-category-filter :preset-filter)
  3449. (org-agenda-filter-apply
  3450. (get 'org-agenda-category-filter :preset-filter) 'category))
  3451. (when org-agenda-regexp-filter
  3452. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3453. (when (get 'org-agenda-regexp-filter :preset-filter)
  3454. (org-agenda-filter-apply
  3455. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3456. (when org-agenda-effort-filter
  3457. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3458. (when (get 'org-agenda-effort-filter :preset-filter)
  3459. (org-agenda-filter-apply
  3460. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3461. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3462. (defun org-agenda-mark-clocking-task ()
  3463. "Mark the current clock entry in the agenda if it is present."
  3464. ;; We need to widen when `org-agenda-finalize' is called from
  3465. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3466. (when org-clock-current-task
  3467. (save-restriction
  3468. (widen)
  3469. (org-agenda-unmark-clocking-task)
  3470. (when (marker-buffer org-clock-hd-marker)
  3471. (save-excursion
  3472. (goto-char (point-min))
  3473. (let (s ov)
  3474. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3475. (goto-char s)
  3476. (when (equal (org-get-at-bol 'org-hd-marker)
  3477. org-clock-hd-marker)
  3478. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3479. (overlay-put ov 'type 'org-agenda-clocking)
  3480. (overlay-put ov 'face 'org-agenda-clocking)
  3481. (overlay-put ov 'help-echo
  3482. "The clock is running in this item")))))))))
  3483. (defun org-agenda-unmark-clocking-task ()
  3484. "Unmark the current clocking task."
  3485. (mapc (lambda (o)
  3486. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3487. (delete-overlay o)))
  3488. (overlays-in (point-min) (point-max))))
  3489. (defun org-agenda-fontify-priorities ()
  3490. "Make highest priority lines bold, and lowest italic."
  3491. (interactive)
  3492. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3493. (delete-overlay o)))
  3494. (overlays-in (point-min) (point-max)))
  3495. (save-excursion
  3496. (let (b e p ov h l)
  3497. (goto-char (point-min))
  3498. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3499. (setq h (or (get-char-property (point) 'org-highest-priority)
  3500. org-highest-priority)
  3501. l (or (get-char-property (point) 'org-lowest-priority)
  3502. org-lowest-priority)
  3503. p (string-to-char (match-string 1))
  3504. b (match-beginning 0)
  3505. e (if (eq org-agenda-fontify-priorities 'cookies)
  3506. (match-end 0)
  3507. (point-at-eol))
  3508. ov (make-overlay b e))
  3509. (overlay-put
  3510. ov 'face
  3511. (let ((special-face
  3512. (cond ((org-face-from-face-or-color
  3513. 'priority nil
  3514. (cdr (assoc p org-priority-faces))))
  3515. ((and (listp org-agenda-fontify-priorities)
  3516. (org-face-from-face-or-color
  3517. 'priority nil
  3518. (cdr (assoc p org-agenda-fontify-priorities)))))
  3519. ((equal p l) 'italic)
  3520. ((equal p h) 'bold))))
  3521. (if special-face (list special-face 'org-priority) 'org-priority)))
  3522. (overlay-put ov 'org-type 'org-priority)))))
  3523. (defvar org-depend-tag-blocked)
  3524. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3525. "Dim currently blocked TODOs in the agenda display.
  3526. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3527. dimming them."
  3528. (interactive "P")
  3529. (when (org-called-interactively-p 'interactive)
  3530. (message "Dim or hide blocked tasks..."))
  3531. (dolist (o (overlays-in (point-min) (point-max)))
  3532. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3533. (delete-overlay o)))
  3534. (save-excursion
  3535. (let ((inhibit-read-only t)
  3536. (org-depend-tag-blocked nil)
  3537. org-blocked-by-checkboxes)
  3538. (goto-char (point-min))
  3539. (while (let ((pos (text-property-not-all
  3540. (point) (point-max) 'todo-state nil)))
  3541. (when pos (goto-char pos)))
  3542. (setq org-blocked-by-checkboxes nil)
  3543. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3544. (when (and (markerp marker)
  3545. (with-current-buffer (marker-buffer marker)
  3546. (save-excursion (goto-char marker)
  3547. (org-entry-blocked-p))))
  3548. ;; Entries blocked by checkboxes cannot be made invisible.
  3549. ;; See `org-agenda-dim-blocked-tasks' for details.
  3550. (let* ((really-invisible
  3551. (and (not org-blocked-by-checkboxes)
  3552. (or invisible (eq org-agenda-dim-blocked-tasks
  3553. 'invisible))))
  3554. (ov (make-overlay (if really-invisible (line-end-position 0)
  3555. (line-beginning-position))
  3556. (line-end-position))))
  3557. (if really-invisible (overlay-put ov 'invisible t)
  3558. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3559. (overlay-put ov 'org-type 'org-blocked-todo))))
  3560. (forward-line))))
  3561. (when (org-called-interactively-p 'interactive)
  3562. (message "Dim or hide blocked tasks...done")))
  3563. (defvar org-agenda-skip-function nil
  3564. "Function to be called at each match during agenda construction.
  3565. If this function returns nil, the current match should not be skipped.
  3566. Otherwise, the function must return a position from where the search
  3567. should be continued.
  3568. This may also be a Lisp form, it will be evaluated.
  3569. Never set this variable using `setq' or so, because then it will apply
  3570. to all future agenda commands. If you do want a global skipping condition,
  3571. use the option `org-agenda-skip-function-global' instead.
  3572. The correct usage for `org-agenda-skip-function' is to bind it with
  3573. `let' to scope it dynamically into the agenda-constructing command.
  3574. A good way to set it is through options in `org-agenda-custom-commands'.")
  3575. (defun org-agenda-skip ()
  3576. "Throw to `:skip' in places that should be skipped.
  3577. Also moves point to the end of the skipped region, so that search can
  3578. continue from there."
  3579. (let ((p (point-at-bol)) to)
  3580. (when (or
  3581. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3582. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3583. (get-text-property p :org-archived)
  3584. (org-end-of-subtree t))
  3585. (and org-agenda-skip-comment-trees
  3586. (get-text-property p :org-comment)
  3587. (org-end-of-subtree t))
  3588. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3589. (org-agenda-skip-eval org-agenda-skip-function)))
  3590. (goto-char to))
  3591. (org-in-src-block-p t))
  3592. (throw :skip t))))
  3593. (defun org-agenda-skip-eval (form)
  3594. "If FORM is a function or a list, call (or eval) it and return the result.
  3595. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3596. and match data are returned to the previous state no matter what these
  3597. functions do."
  3598. (let (fp)
  3599. (and form
  3600. (or (setq fp (functionp form))
  3601. (consp form))
  3602. (save-excursion
  3603. (save-match-data
  3604. (if fp
  3605. (funcall form)
  3606. (eval form)))))))
  3607. (defvar org-agenda-markers nil
  3608. "List of all currently active markers created by `org-agenda'.")
  3609. (defvar org-agenda-last-marker-time (org-float-time)
  3610. "Creation time of the last agenda marker.")
  3611. (defun org-agenda-new-marker (&optional pos)
  3612. "Return a new agenda marker.
  3613. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3614. these markers and resets them when they are no longer in use."
  3615. (let ((m (copy-marker (or pos (point)) t)))
  3616. (setq org-agenda-last-marker-time (org-float-time))
  3617. (if org-agenda-buffer
  3618. (with-current-buffer org-agenda-buffer
  3619. (push m org-agenda-markers))
  3620. (push m org-agenda-markers))
  3621. m))
  3622. (defun org-agenda-reset-markers ()
  3623. "Reset markers created by `org-agenda'."
  3624. (while org-agenda-markers
  3625. (move-marker (pop org-agenda-markers) nil)))
  3626. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3627. "Save relative positions of markers in region.
  3628. This check for agenda markers in all agenda buffers currently active."
  3629. (dolist (buf (buffer-list))
  3630. (with-current-buffer buf
  3631. (when (eq major-mode 'org-agenda-mode)
  3632. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3633. org-agenda-markers)))))
  3634. ;;; Entry text mode
  3635. (defun org-agenda-entry-text-show-here ()
  3636. "Add some text from the entry as context to the current line."
  3637. (let (m txt o)
  3638. (setq m (org-get-at-bol 'org-hd-marker))
  3639. (unless (marker-buffer m)
  3640. (error "No marker points to an entry here"))
  3641. (setq txt (concat "\n" (org-no-properties
  3642. (org-agenda-get-some-entry-text
  3643. m org-agenda-entry-text-maxlines
  3644. org-agenda-entry-text-leaders))))
  3645. (when (string-match "\\S-" txt)
  3646. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3647. (overlay-put o 'evaporate t)
  3648. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3649. (overlay-put o 'after-string txt))))
  3650. (defun org-agenda-entry-text-show ()
  3651. "Add entry context for all agenda lines."
  3652. (interactive)
  3653. (save-excursion
  3654. (goto-char (point-max))
  3655. (beginning-of-line 1)
  3656. (while (not (bobp))
  3657. (when (org-get-at-bol 'org-hd-marker)
  3658. (org-agenda-entry-text-show-here))
  3659. (beginning-of-line 0))))
  3660. (defun org-agenda-entry-text-hide ()
  3661. "Remove any shown entry context."
  3662. (delq nil
  3663. (mapcar (lambda (o)
  3664. (if (eq (overlay-get o 'org-overlay-type)
  3665. 'agenda-entry-content)
  3666. (progn (delete-overlay o) t)))
  3667. (overlays-in (point-min) (point-max)))))
  3668. (defun org-agenda-get-day-face (date)
  3669. "Return the face DATE should be displayed with."
  3670. (cond ((and (functionp org-agenda-day-face-function)
  3671. (funcall org-agenda-day-face-function date)))
  3672. ((org-agenda-today-p date) 'org-agenda-date-today)
  3673. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3674. 'org-agenda-date-weekend)
  3675. (t 'org-agenda-date)))
  3676. ;;; Agenda timeline
  3677. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3678. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3679. (defun org-timeline (&optional dotodo)
  3680. "Show a time-sorted view of the entries in the current org file.
  3681. Only entries with a time stamp of today or later will be listed. With
  3682. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3683. under the current date.
  3684. If the buffer contains an active region, only check the region for
  3685. dates."
  3686. (interactive "P")
  3687. (let* ((dopast t)
  3688. (org-agenda-show-log-scoped org-agenda-show-log)
  3689. (org-agenda-show-log org-agenda-show-log-scoped)
  3690. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3691. (current-buffer))))
  3692. (date (calendar-current-date))
  3693. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3694. (end (if (org-region-active-p) (region-end) (point-max)))
  3695. (day-numbers (org-get-all-dates
  3696. beg end 'no-ranges
  3697. t org-agenda-show-log-scoped ; always include today
  3698. org-timeline-show-empty-dates))
  3699. (org-deadline-warning-days 0)
  3700. (org-agenda-only-exact-dates t)
  3701. (today (org-today))
  3702. (past t)
  3703. args
  3704. s e rtn d emptyp)
  3705. (setq org-agenda-redo-command
  3706. (list 'let
  3707. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3708. (list 'org-switch-to-buffer-other-window (current-buffer))
  3709. (list 'org-timeline (list 'quote dotodo))))
  3710. (put 'org-agenda-redo-command 'org-lprops nil)
  3711. (if (not dopast)
  3712. ;; Remove past dates from the list of dates.
  3713. (setq day-numbers (delq nil (mapcar (lambda(x)
  3714. (if (>= x today) x nil))
  3715. day-numbers))))
  3716. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3717. (org-compile-prefix-format 'timeline)
  3718. (org-set-sorting-strategy 'timeline)
  3719. (if org-agenda-show-log-scoped (push :closed args))
  3720. (push :timestamp args)
  3721. (push :deadline args)
  3722. (push :scheduled args)
  3723. (push :sexp args)
  3724. (if dotodo (push :todo args))
  3725. (insert "Timeline of file " entry "\n")
  3726. (add-text-properties (point-min) (point)
  3727. (list 'face 'org-agenda-structure))
  3728. (org-agenda-mark-header-line (point-min))
  3729. (while (setq d (pop day-numbers))
  3730. (if (and (listp d) (eq (car d) :omitted))
  3731. (progn
  3732. (setq s (point))
  3733. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3734. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3735. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3736. (if (and (>= d today)
  3737. dopast
  3738. past)
  3739. (progn
  3740. (setq past nil)
  3741. (insert (make-string 79 ?-) "\n")))
  3742. (setq date (calendar-gregorian-from-absolute d))
  3743. (setq s (point))
  3744. (setq rtn (and (not emptyp)
  3745. (apply 'org-agenda-get-day-entries entry
  3746. date args)))
  3747. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3748. (progn
  3749. (insert
  3750. (if (stringp org-agenda-format-date)
  3751. (format-time-string org-agenda-format-date
  3752. (org-time-from-absolute date))
  3753. (funcall org-agenda-format-date date))
  3754. "\n")
  3755. (put-text-property s (1- (point)) 'face
  3756. (org-agenda-get-day-face date))
  3757. (put-text-property s (1- (point)) 'org-date-line t)
  3758. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3759. (if (equal d today)
  3760. (put-text-property s (1- (point)) 'org-today t))
  3761. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3762. (put-text-property s (1- (point)) 'day d)))))
  3763. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3764. (point-min)))
  3765. (add-text-properties
  3766. (point-min) (point-max)
  3767. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3768. (org-agenda-finalize)
  3769. (setq buffer-read-only t)))
  3770. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3771. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3772. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3773. not every single day in the range. If FORCE-TODAY is non-nil, make
  3774. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3775. inactive time stamps (those in square brackets) are included.
  3776. When EMPTY is non-nil, also include days without any entries."
  3777. (let ((re (concat
  3778. (if pre-re pre-re "")
  3779. (if inactive org-ts-regexp-both org-ts-regexp)))
  3780. dates dates1 date day day1 day2 ts1 ts2 pos)
  3781. (if force-today
  3782. (setq dates (list (org-today))))
  3783. (save-excursion
  3784. (goto-char beg)
  3785. (while (re-search-forward re end t)
  3786. (setq day (time-to-days (org-time-string-to-time
  3787. (substring (match-string 1) 0 10)
  3788. (current-buffer) (match-beginning 0))))
  3789. (or (memq day dates) (push day dates)))
  3790. (unless no-ranges
  3791. (goto-char beg)
  3792. (while (re-search-forward org-tr-regexp end t)
  3793. (setq pos (match-beginning 0))
  3794. (setq ts1 (substring (match-string 1) 0 10)
  3795. ts2 (substring (match-string 2) 0 10)
  3796. day1 (time-to-days (org-time-string-to-time
  3797. ts1 (current-buffer) pos))
  3798. day2 (time-to-days (org-time-string-to-time
  3799. ts2 (current-buffer) pos)))
  3800. (while (< (setq day1 (1+ day1)) day2)
  3801. (or (memq day1 dates) (push day1 dates)))))
  3802. (setq dates (sort dates '<))
  3803. (when empty
  3804. (while (setq day (pop dates))
  3805. (setq day2 (car dates))
  3806. (push day dates1)
  3807. (when (and day2 empty)
  3808. (if (or (eq empty t)
  3809. (and (numberp empty) (<= (- day2 day) empty)))
  3810. (while (< (setq day (1+ day)) day2)
  3811. (push (list day) dates1))
  3812. (push (cons :omitted (- day2 day)) dates1))))
  3813. (setq dates (nreverse dates1)))
  3814. dates)))
  3815. ;;; Agenda Daily/Weekly
  3816. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3817. "Start day for the agenda view.
  3818. Custom commands can set this variable in the options section.
  3819. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3820. input allowed when reading a date through the Org calendar.
  3821. See the docstring of `org-read-date' for details.")
  3822. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3823. (defvar org-arg-loc nil) ; local variable
  3824. (defvar org-agenda-buffer-tmp-name nil)
  3825. ;;;###autoload
  3826. (defun org-agenda-list (&optional arg start-day span with-hour)
  3827. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3828. The view will be for the current day or week, but from the overview buffer
  3829. you will be able to go to other days/weeks.
  3830. With a numeric prefix argument in an interactive call, the agenda will
  3831. span ARG days. Lisp programs should instead specify SPAN to change
  3832. the number of days. SPAN defaults to `org-agenda-span'.
  3833. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3834. given in `org-agenda-start-on-weekday'.
  3835. When WITH-HOUR is non-nil, only include scheduled and deadline
  3836. items if they have an hour specification like [h]h:mm."
  3837. (interactive "P")
  3838. (if org-agenda-overriding-arguments
  3839. (setq arg (car org-agenda-overriding-arguments)
  3840. start-day (nth 1 org-agenda-overriding-arguments)
  3841. span (nth 2 org-agenda-overriding-arguments)))
  3842. (if (and (integerp arg) (> arg 0))
  3843. (setq span arg arg nil))
  3844. (catch 'exit
  3845. (setq org-agenda-buffer-name
  3846. (or org-agenda-buffer-tmp-name
  3847. (if org-agenda-sticky
  3848. (cond ((and org-keys (stringp org-match))
  3849. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3850. (org-keys
  3851. (format "*Org Agenda(%s)*" org-keys))
  3852. (t "*Org Agenda(a)*")))
  3853. org-agenda-buffer-name))
  3854. (org-agenda-prepare "Day/Week")
  3855. (setq start-day (or start-day org-agenda-start-day))
  3856. (if (stringp start-day)
  3857. ;; Convert to an absolute day number
  3858. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3859. (org-compile-prefix-format 'agenda)
  3860. (org-set-sorting-strategy 'agenda)
  3861. (let* ((span (org-agenda-ndays-to-span
  3862. (or span org-agenda-ndays org-agenda-span)))
  3863. (today (org-today))
  3864. (sd (or start-day today))
  3865. (ndays (org-agenda-span-to-ndays span sd))
  3866. (org-agenda-start-on-weekday
  3867. (if (or (eq ndays 7) (eq ndays 14))
  3868. org-agenda-start-on-weekday))
  3869. (thefiles (org-agenda-files nil 'ifmode))
  3870. (files thefiles)
  3871. (start (if (or (null org-agenda-start-on-weekday)
  3872. (< ndays 7))
  3873. sd
  3874. (let* ((nt (calendar-day-of-week
  3875. (calendar-gregorian-from-absolute sd)))
  3876. (n1 org-agenda-start-on-weekday)
  3877. (d (- nt n1)))
  3878. (- sd (+ (if (< d 0) 7 0) d)))))
  3879. (day-numbers (list start))
  3880. (day-cnt 0)
  3881. (inhibit-redisplay (not debug-on-error))
  3882. (org-agenda-show-log-scoped org-agenda-show-log)
  3883. s e rtn rtnall file date d start-pos end-pos todayp
  3884. clocktable-start clocktable-end filter)
  3885. (setq org-agenda-redo-command
  3886. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3887. (dotimes (n (1- ndays))
  3888. (push (1+ (car day-numbers)) day-numbers))
  3889. (setq day-numbers (nreverse day-numbers))
  3890. (setq clocktable-start (car day-numbers)
  3891. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3892. (setq-local org-starting-day (car day-numbers))
  3893. (setq-local org-arg-loc arg)
  3894. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3895. (unless org-agenda-compact-blocks
  3896. (let* ((d1 (car day-numbers))
  3897. (d2 (org-last day-numbers))
  3898. (w1 (org-days-to-iso-week d1))
  3899. (w2 (org-days-to-iso-week d2)))
  3900. (setq s (point))
  3901. (if org-agenda-overriding-header
  3902. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3903. nil 'face 'org-agenda-structure) "\n")
  3904. (insert (org-agenda-span-name span)
  3905. "-agenda"
  3906. (if (< (- d2 d1) 350)
  3907. (if (= w1 w2)
  3908. (format " (W%02d)" w1)
  3909. (format " (W%02d-W%02d)" w1 w2))
  3910. "")
  3911. ":\n")))
  3912. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3913. 'org-date-line t))
  3914. (org-agenda-mark-header-line s))
  3915. (while (setq d (pop day-numbers))
  3916. (setq date (calendar-gregorian-from-absolute d)
  3917. s (point))
  3918. (if (or (setq todayp (= d today))
  3919. (and (not start-pos) (= d sd)))
  3920. (setq start-pos (point))
  3921. (if (and start-pos (not end-pos))
  3922. (setq end-pos (point))))
  3923. (setq files thefiles
  3924. rtnall nil)
  3925. (while (setq file (pop files))
  3926. (catch 'nextfile
  3927. (org-check-agenda-file file)
  3928. (let ((org-agenda-entry-types org-agenda-entry-types))
  3929. ;; Starred types override non-starred equivalents
  3930. (when (member :deadline* org-agenda-entry-types)
  3931. (setq org-agenda-entry-types
  3932. (delq :deadline org-agenda-entry-types)))
  3933. (when (member :scheduled* org-agenda-entry-types)
  3934. (setq org-agenda-entry-types
  3935. (delq :scheduled org-agenda-entry-types)))
  3936. ;; Honor with-hour
  3937. (when with-hour
  3938. (when (member :deadline org-agenda-entry-types)
  3939. (setq org-agenda-entry-types
  3940. (delq :deadline org-agenda-entry-types))
  3941. (push :deadline* org-agenda-entry-types))
  3942. (when (member :scheduled org-agenda-entry-types)
  3943. (setq org-agenda-entry-types
  3944. (delq :scheduled org-agenda-entry-types))
  3945. (push :scheduled* org-agenda-entry-types)))
  3946. (unless org-agenda-include-deadlines
  3947. (setq org-agenda-entry-types
  3948. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3949. (cond
  3950. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3951. (setq rtn (org-agenda-get-day-entries
  3952. file date :closed)))
  3953. (org-agenda-show-log-scoped
  3954. (setq rtn (apply 'org-agenda-get-day-entries
  3955. file date
  3956. (append '(:closed) org-agenda-entry-types))))
  3957. (t
  3958. (setq rtn (apply 'org-agenda-get-day-entries
  3959. file date
  3960. org-agenda-entry-types)))))
  3961. (setq rtnall (append rtnall rtn)))) ;; all entries
  3962. (if org-agenda-include-diary
  3963. (let ((org-agenda-search-headline-for-time t))
  3964. (require 'diary-lib)
  3965. (setq rtn (org-get-entries-from-diary date))
  3966. (setq rtnall (append rtnall rtn))))
  3967. (if (or rtnall org-agenda-show-all-dates)
  3968. (progn
  3969. (setq day-cnt (1+ day-cnt))
  3970. (insert
  3971. (if (stringp org-agenda-format-date)
  3972. (format-time-string org-agenda-format-date
  3973. (org-time-from-absolute date))
  3974. (funcall org-agenda-format-date date))
  3975. "\n")
  3976. (put-text-property s (1- (point)) 'face
  3977. (org-agenda-get-day-face date))
  3978. (put-text-property s (1- (point)) 'org-date-line t)
  3979. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3980. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3981. (when todayp
  3982. (put-text-property s (1- (point)) 'org-today t))
  3983. (setq rtnall
  3984. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3985. (if rtnall (insert ;; all entries
  3986. (org-agenda-finalize-entries rtnall 'agenda)
  3987. "\n"))
  3988. (put-text-property s (1- (point)) 'day d)
  3989. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3990. (when (and org-agenda-clockreport-mode clocktable-start)
  3991. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3992. ;; the above line is to ensure the restricted range!
  3993. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3994. tbl)
  3995. (setq p (org-plist-delete p :block))
  3996. (setq p (plist-put p :tstart clocktable-start))
  3997. (setq p (plist-put p :tend clocktable-end))
  3998. (setq p (plist-put p :scope 'agenda))
  3999. (setq tbl (apply 'org-clock-get-clocktable p))
  4000. (insert tbl)))
  4001. (goto-char (point-min))
  4002. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4003. (unless (and (pos-visible-in-window-p (point-min))
  4004. (pos-visible-in-window-p (point-max)))
  4005. (goto-char (1- (point-max)))
  4006. (recenter -1)
  4007. (if (not (pos-visible-in-window-p (or start-pos 1)))
  4008. (progn
  4009. (goto-char (or start-pos 1))
  4010. (recenter 1))))
  4011. (goto-char (or start-pos 1))
  4012. (add-text-properties (point-min) (point-max)
  4013. `(org-agenda-type agenda
  4014. org-last-args (,arg ,start-day ,span)
  4015. org-redo-cmd ,org-agenda-redo-command
  4016. org-series-cmd ,org-cmd))
  4017. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4018. (org-agenda-show-clocking-issues))
  4019. (org-agenda-finalize)
  4020. (setq buffer-read-only t)
  4021. (message ""))))
  4022. (defun org-agenda-ndays-to-span (n)
  4023. "Return a span symbol for a span of N days, or N if none matches."
  4024. (cond ((symbolp n) n)
  4025. ((= n 1) 'day)
  4026. ((= n 7) 'week)
  4027. ((= n 14) 'fortnight)
  4028. (t n)))
  4029. (defun org-agenda-span-to-ndays (span &optional start-day)
  4030. "Return ndays from SPAN, possibly starting at START-DAY.
  4031. START-DAY is an absolute time value."
  4032. (cond ((numberp span) span)
  4033. ((eq span 'day) 1)
  4034. ((eq span 'week) 7)
  4035. ((eq span 'fortnight) 14)
  4036. ((eq span 'month)
  4037. (let ((date (calendar-gregorian-from-absolute start-day)))
  4038. (calendar-last-day-of-month (car date) (caddr date))))
  4039. ((eq span 'year)
  4040. (let ((date (calendar-gregorian-from-absolute start-day)))
  4041. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  4042. (defun org-agenda-span-name (span)
  4043. "Return a SPAN name."
  4044. (if (null span)
  4045. ""
  4046. (if (symbolp span)
  4047. (capitalize (symbol-name span))
  4048. (format "%d days" span))))
  4049. ;;; Agenda word search
  4050. (defvar org-agenda-search-history nil)
  4051. (defvar org-search-syntax-table nil
  4052. "Special syntax table for org-mode search.
  4053. In this table, we have single quotes not as word constituents, to
  4054. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4055. (defvar org-mode-syntax-table) ; From org.el
  4056. (defun org-search-syntax-table ()
  4057. (unless org-search-syntax-table
  4058. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4059. (modify-syntax-entry ?' "." org-search-syntax-table)
  4060. (modify-syntax-entry ?` "." org-search-syntax-table))
  4061. org-search-syntax-table)
  4062. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4063. ;;;###autoload
  4064. (defun org-search-view (&optional todo-only string edit-at)
  4065. "Show all entries that contain a phrase or words or regular expressions.
  4066. With optional prefix argument TODO-ONLY, only consider entries that are
  4067. TODO entries. The argument STRING can be used to pass a default search
  4068. string into this function. If EDIT-AT is non-nil, it means that the
  4069. user should get a chance to edit this string, with cursor at position
  4070. EDIT-AT.
  4071. The search string can be viewed either as a phrase that should be found as
  4072. is, or it can be broken into a number of snippets, each of which must match
  4073. in a Boolean way to select an entry. The default depends on the variable
  4074. `org-agenda-search-view-always-boolean'.
  4075. Even if this is turned off (the default) you can always switch to
  4076. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4077. The default is a direct search of the whole phrase, where each space in
  4078. the search string can expand to an arbitrary amount of whitespace,
  4079. including newlines.
  4080. If using a Boolean search, the search string is split on whitespace and
  4081. each snippet is searched separately, with logical AND to select an entry.
  4082. Words prefixed with a minus must *not* occur in the entry. Words without
  4083. a prefix or prefixed with a plus must occur in the entry. Matching is
  4084. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4085. match whole words, not parts of a word) if
  4086. `org-agenda-search-view-force-full-words' is set (default is nil).
  4087. Boolean search snippets enclosed by curly braces are interpreted as
  4088. regular expressions that must or (when preceded with \"-\") must not
  4089. match in the entry. Snippets enclosed into double quotes will be taken
  4090. as a whole, to include whitespace.
  4091. - If the search string starts with an asterisk, search only in headlines.
  4092. - If (possibly after the leading star) the search string starts with an
  4093. exclamation mark, this also means to look at TODO entries only, an effect
  4094. that can also be achieved with a prefix argument.
  4095. - If (possibly after star and exclamation mark) the search string starts
  4096. with a colon, this will mean that the (non-regexp) snippets of the
  4097. Boolean search must match as full words.
  4098. This command searches the agenda files, and in addition the files listed
  4099. in `org-agenda-text-search-extra-files'."
  4100. (interactive "P")
  4101. (if org-agenda-overriding-arguments
  4102. (setq todo-only (car org-agenda-overriding-arguments)
  4103. string (nth 1 org-agenda-overriding-arguments)
  4104. edit-at (nth 2 org-agenda-overriding-arguments)))
  4105. (let* ((props (list 'face nil
  4106. 'done-face 'org-agenda-done
  4107. 'org-not-done-regexp org-not-done-regexp
  4108. 'org-todo-regexp org-todo-regexp
  4109. 'org-complex-heading-regexp org-complex-heading-regexp
  4110. 'mouse-face 'highlight
  4111. 'help-echo (format "mouse-2 or RET jump to location")))
  4112. (full-words org-agenda-search-view-force-full-words)
  4113. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4114. regexp rtn rtnall files file pos inherited-tags
  4115. marker category level tags c neg re boolean
  4116. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4117. (unless (and (not edit-at)
  4118. (stringp string)
  4119. (string-match "\\S-" string))
  4120. (setq string (read-string
  4121. (if org-agenda-search-view-always-boolean
  4122. "[+-]Word/{Regexp} ...: "
  4123. "Phrase or [+-]Word/{Regexp} ...: ")
  4124. (cond
  4125. ((integerp edit-at) (cons string edit-at))
  4126. (edit-at string))
  4127. 'org-agenda-search-history)))
  4128. (catch 'exit
  4129. (if org-agenda-sticky
  4130. (setq org-agenda-buffer-name
  4131. (if (stringp string)
  4132. (format "*Org Agenda(%s:%s)*"
  4133. (or org-keys (or (and todo-only "S") "s")) string)
  4134. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4135. (org-agenda-prepare "SEARCH")
  4136. (org-compile-prefix-format 'search)
  4137. (org-set-sorting-strategy 'search)
  4138. (setq org-agenda-redo-command
  4139. (list 'org-search-view (if todo-only t nil)
  4140. (list 'if 'current-prefix-arg nil string)))
  4141. (setq org-agenda-query-string string)
  4142. (if (equal (string-to-char string) ?*)
  4143. (setq hdl-only t
  4144. words (substring string 1))
  4145. (setq words string))
  4146. (when (equal (string-to-char words) ?!)
  4147. (setq todo-only t
  4148. words (substring words 1)))
  4149. (when (equal (string-to-char words) ?:)
  4150. (setq full-words t
  4151. words (substring words 1)))
  4152. (if (or org-agenda-search-view-always-boolean
  4153. (member (string-to-char words) '(?- ?+ ?\{)))
  4154. (setq boolean t))
  4155. (setq words (org-split-string words))
  4156. (let (www w)
  4157. (while (setq w (pop words))
  4158. (while (and (string-match "\\\\\\'" w) words)
  4159. (setq w (concat (substring w 0 -1) " " (pop words))))
  4160. (push w www))
  4161. (setq words (nreverse www) www nil)
  4162. (while (setq w (pop words))
  4163. (when (and (string-match "\\`[-+]?{" w)
  4164. (not (string-match "}\\'" w)))
  4165. (while (and words (not (string-match "}\\'" (car words))))
  4166. (setq w (concat w " " (pop words))))
  4167. (setq w (concat w " " (pop words))))
  4168. (push w www))
  4169. (setq words (nreverse www)))
  4170. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4171. (when boolean
  4172. (let (wds w)
  4173. (while (setq w (pop words))
  4174. (if (or (equal (substring w 0 1) "\"")
  4175. (and (> (length w) 1)
  4176. (member (substring w 0 1) '("+" "-"))
  4177. (equal (substring w 1 2) "\"")))
  4178. (while (and words (not (equal (substring w -1) "\"")))
  4179. (setq w (concat w " " (pop words)))))
  4180. (and (string-match "\\`\\([-+]?\\)\"" w)
  4181. (setq w (replace-match "\\1" nil nil w)))
  4182. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4183. (push w wds))
  4184. (setq words (nreverse wds))))
  4185. (if boolean
  4186. (mapc (lambda (w)
  4187. (setq c (string-to-char w))
  4188. (if (equal c ?-)
  4189. (setq neg t w (substring w 1))
  4190. (if (equal c ?+)
  4191. (setq neg nil w (substring w 1))
  4192. (setq neg nil)))
  4193. (if (string-match "\\`{.*}\\'" w)
  4194. (setq re (substring w 1 -1))
  4195. (if full-words
  4196. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4197. (setq re (regexp-quote (downcase w)))))
  4198. (if neg (push re regexps-) (push re regexps+)))
  4199. words)
  4200. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4201. regexps+))
  4202. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4203. (if (not regexps+)
  4204. (setq regexp org-outline-regexp-bol)
  4205. (setq regexp (pop regexps+))
  4206. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4207. regexp))))
  4208. (setq files (org-agenda-files nil 'ifmode))
  4209. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4210. (pop org-agenda-text-search-extra-files)
  4211. (setq files (org-add-archive-files files)))
  4212. (setq files (append files org-agenda-text-search-extra-files)
  4213. rtnall nil)
  4214. (while (setq file (pop files))
  4215. (setq ee nil)
  4216. (catch 'nextfile
  4217. (org-check-agenda-file file)
  4218. (setq buffer (if (file-exists-p file)
  4219. (org-get-agenda-file-buffer file)
  4220. (error "No such file %s" file)))
  4221. (if (not buffer)
  4222. ;; If file does not exist, make sure an error message is sent
  4223. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4224. file))))
  4225. (with-current-buffer buffer
  4226. (with-syntax-table (org-search-syntax-table)
  4227. (unless (derived-mode-p 'org-mode)
  4228. (error "Agenda file %s is not in `org-mode'" file))
  4229. (let ((case-fold-search t))
  4230. (save-excursion
  4231. (save-restriction
  4232. (if (eq buffer org-agenda-restrict)
  4233. (narrow-to-region org-agenda-restrict-begin
  4234. org-agenda-restrict-end)
  4235. (widen))
  4236. (goto-char (point-min))
  4237. (unless (or (org-at-heading-p)
  4238. (outline-next-heading))
  4239. (throw 'nextfile t))
  4240. (goto-char (max (point-min) (1- (point))))
  4241. (while (re-search-forward regexp nil t)
  4242. (org-back-to-heading t)
  4243. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4244. (> (org-reduced-level (org-outline-level))
  4245. org-agenda-search-view-max-outline-level)
  4246. (forward-line -1)
  4247. (org-back-to-heading t)))
  4248. (skip-chars-forward "* ")
  4249. (setq beg (point-at-bol)
  4250. beg1 (point)
  4251. end (progn
  4252. (outline-next-heading)
  4253. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4254. (> (org-reduced-level (org-outline-level))
  4255. org-agenda-search-view-max-outline-level)
  4256. (forward-line 1)
  4257. (outline-next-heading)))
  4258. (point)))
  4259. (catch :skip
  4260. (goto-char beg)
  4261. (org-agenda-skip)
  4262. (setq str (buffer-substring-no-properties
  4263. (point-at-bol)
  4264. (if hdl-only (point-at-eol) end)))
  4265. (mapc (lambda (wr) (when (string-match wr str)
  4266. (goto-char (1- end))
  4267. (throw :skip t)))
  4268. regexps-)
  4269. (mapc (lambda (wr) (unless (string-match wr str)
  4270. (goto-char (1- end))
  4271. (throw :skip t)))
  4272. (if todo-only
  4273. (cons (concat "^\\*+[ \t]+"
  4274. org-not-done-regexp)
  4275. regexps+)
  4276. regexps+))
  4277. (goto-char beg)
  4278. (setq marker (org-agenda-new-marker (point))
  4279. category (org-get-category)
  4280. level (make-string (org-reduced-level (org-outline-level)) ? )
  4281. inherited-tags
  4282. (or (eq org-agenda-show-inherited-tags 'always)
  4283. (and (listp org-agenda-show-inherited-tags)
  4284. (memq 'todo org-agenda-show-inherited-tags))
  4285. (and (eq org-agenda-show-inherited-tags t)
  4286. (or (eq org-agenda-use-tag-inheritance t)
  4287. (memq 'todo org-agenda-use-tag-inheritance))))
  4288. tags (org-get-tags-at nil (not inherited-tags))
  4289. txt (org-agenda-format-item
  4290. ""
  4291. (buffer-substring-no-properties
  4292. beg1 (point-at-eol))
  4293. level category tags t))
  4294. (org-add-props txt props
  4295. 'org-marker marker 'org-hd-marker marker
  4296. 'org-todo-regexp org-todo-regexp
  4297. 'level level
  4298. 'org-complex-heading-regexp org-complex-heading-regexp
  4299. 'priority 1000
  4300. 'type "search")
  4301. (push txt ee)
  4302. (goto-char (1- end))))))))))
  4303. (setq rtn (nreverse ee))
  4304. (setq rtnall (append rtnall rtn)))
  4305. (if org-agenda-overriding-header
  4306. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4307. nil 'face 'org-agenda-structure) "\n")
  4308. (insert "Search words: ")
  4309. (add-text-properties (point-min) (1- (point))
  4310. (list 'face 'org-agenda-structure))
  4311. (setq pos (point))
  4312. (insert string "\n")
  4313. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4314. (setq pos (point))
  4315. (unless org-agenda-multi
  4316. (insert (substitute-command-keys "\
  4317. Press `\\[org-agenda-manipulate-query-add]', \
  4318. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4319. `\\[org-agenda-manipulate-query-add-re]', \
  4320. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4321. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4322. (add-text-properties pos (1- (point))
  4323. (list 'face 'org-agenda-structure))))
  4324. (org-agenda-mark-header-line (point-min))
  4325. (when rtnall
  4326. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4327. (goto-char (point-min))
  4328. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4329. (add-text-properties (point-min) (point-max)
  4330. `(org-agenda-type search
  4331. org-last-args (,todo-only ,string ,edit-at)
  4332. org-redo-cmd ,org-agenda-redo-command
  4333. org-series-cmd ,org-cmd))
  4334. (org-agenda-finalize)
  4335. (setq buffer-read-only t))))
  4336. ;;; Agenda TODO list
  4337. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4338. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4339. (concat
  4340. (if (or (equal keywords "ALL") (not keywords))
  4341. (propertize "ALL" 'face 'warning)
  4342. (mapconcat
  4343. (lambda (kw)
  4344. (propertize kw 'face (org-get-todo-face kw)))
  4345. (org-split-string keywords "|")
  4346. "|"))
  4347. "\n"))
  4348. (defvar org-select-this-todo-keyword nil)
  4349. (defvar org-last-arg nil)
  4350. ;;;###autoload
  4351. (defun org-todo-list (&optional arg)
  4352. "Show all (not done) TODO entries from all agenda file in a single list.
  4353. The prefix arg can be used to select a specific TODO keyword and limit
  4354. the list to these. When using \\[universal-argument], you will be prompted
  4355. for a keyword. A numeric prefix directly selects the Nth keyword in
  4356. `org-todo-keywords-1'."
  4357. (interactive "P")
  4358. (if org-agenda-overriding-arguments
  4359. (setq arg org-agenda-overriding-arguments))
  4360. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4361. (let* ((today (org-today))
  4362. (date (calendar-gregorian-from-absolute today))
  4363. (kwds org-todo-keywords-for-agenda)
  4364. (completion-ignore-case t)
  4365. (org-select-this-todo-keyword
  4366. (if (stringp arg) arg
  4367. (and arg (integerp arg) (> arg 0)
  4368. (nth (1- arg) kwds))))
  4369. rtn rtnall files file pos)
  4370. (when (equal arg '(4))
  4371. (setq org-select-this-todo-keyword
  4372. (completing-read "Keyword (or KWD1|K2D2|...): "
  4373. (mapcar #'list kwds) nil nil)))
  4374. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4375. (catch 'exit
  4376. (if org-agenda-sticky
  4377. (setq org-agenda-buffer-name
  4378. (if (stringp org-select-this-todo-keyword)
  4379. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4380. org-select-this-todo-keyword)
  4381. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4382. (org-agenda-prepare "TODO")
  4383. (org-compile-prefix-format 'todo)
  4384. (org-set-sorting-strategy 'todo)
  4385. (setq org-agenda-redo-command
  4386. `(org-todo-list (or (and (numberp current-prefix-arg)
  4387. current-prefix-arg)
  4388. ,org-select-this-todo-keyword
  4389. current-prefix-arg ,arg)))
  4390. (setq files (org-agenda-files nil 'ifmode)
  4391. rtnall nil)
  4392. (while (setq file (pop files))
  4393. (catch 'nextfile
  4394. (org-check-agenda-file file)
  4395. (setq rtn (org-agenda-get-day-entries file date :todo))
  4396. (setq rtnall (append rtnall rtn))))
  4397. (if org-agenda-overriding-header
  4398. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4399. nil 'face 'org-agenda-structure) "\n")
  4400. (insert "Global list of TODO items of type: ")
  4401. (add-text-properties (point-min) (1- (point))
  4402. (list 'face 'org-agenda-structure
  4403. 'short-heading
  4404. (concat "ToDo: "
  4405. (or org-select-this-todo-keyword "ALL"))))
  4406. (org-agenda-mark-header-line (point-min))
  4407. (insert (org-agenda-propertize-selected-todo-keywords
  4408. org-select-this-todo-keyword))
  4409. (setq pos (point))
  4410. (unless org-agenda-multi
  4411. (insert (substitute-command-keys "Available with \
  4412. `N \\[org-agenda-redo]': (0)[ALL]"))
  4413. (let ((n 0) s)
  4414. (mapc (lambda (x)
  4415. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4416. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4417. (insert "\n "))
  4418. (insert " " s))
  4419. kwds))
  4420. (insert "\n"))
  4421. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4422. (org-agenda-mark-header-line (point-min))
  4423. (when rtnall
  4424. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4425. (goto-char (point-min))
  4426. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4427. (add-text-properties (point-min) (point-max)
  4428. `(org-agenda-type todo
  4429. org-last-args ,arg
  4430. org-redo-cmd ,org-agenda-redo-command
  4431. org-series-cmd ,org-cmd))
  4432. (org-agenda-finalize)
  4433. (setq buffer-read-only t))))
  4434. ;;; Agenda tags match
  4435. ;;;###autoload
  4436. (defun org-tags-view (&optional todo-only match)
  4437. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4438. The prefix arg TODO-ONLY limits the search to TODO entries."
  4439. (interactive "P")
  4440. (if org-agenda-overriding-arguments
  4441. (setq todo-only (car org-agenda-overriding-arguments)
  4442. match (nth 1 org-agenda-overriding-arguments)))
  4443. (let* ((org-tags-match-list-sublevels
  4444. org-tags-match-list-sublevels)
  4445. (completion-ignore-case t)
  4446. rtn rtnall files file pos matcher
  4447. buffer)
  4448. (when (and (stringp match) (not (string-match "\\S-" match)))
  4449. (setq match nil))
  4450. (catch 'exit
  4451. (if org-agenda-sticky
  4452. (setq org-agenda-buffer-name
  4453. (if (stringp match)
  4454. (format "*Org Agenda(%s:%s)*"
  4455. (or org-keys (or (and todo-only "M") "m")) match)
  4456. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4457. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4458. ;; expanding tags within `org-make-tags-matcher'
  4459. (org-agenda-prepare (concat "TAGS " match))
  4460. (setq org--matcher-tags-todo-only todo-only
  4461. matcher (org-make-tags-matcher match)
  4462. match (car matcher)
  4463. matcher (cdr matcher))
  4464. (org-compile-prefix-format 'tags)
  4465. (org-set-sorting-strategy 'tags)
  4466. (setq org-agenda-query-string match)
  4467. (setq org-agenda-redo-command
  4468. (list 'org-tags-view
  4469. `(quote ,org--matcher-tags-todo-only)
  4470. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4471. (setq files (org-agenda-files nil 'ifmode)
  4472. rtnall nil)
  4473. (while (setq file (pop files))
  4474. (catch 'nextfile
  4475. (org-check-agenda-file file)
  4476. (setq buffer (if (file-exists-p file)
  4477. (org-get-agenda-file-buffer file)
  4478. (error "No such file %s" file)))
  4479. (if (not buffer)
  4480. ;; If file does not exist, error message to agenda
  4481. (setq rtn (list
  4482. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4483. rtnall (append rtnall rtn))
  4484. (with-current-buffer buffer
  4485. (unless (derived-mode-p 'org-mode)
  4486. (error "Agenda file %s is not in `org-mode'" file))
  4487. (save-excursion
  4488. (save-restriction
  4489. (if (eq buffer org-agenda-restrict)
  4490. (narrow-to-region org-agenda-restrict-begin
  4491. org-agenda-restrict-end)
  4492. (widen))
  4493. (setq rtn (org-scan-tags 'agenda
  4494. matcher
  4495. org--matcher-tags-todo-only))
  4496. (setq rtnall (append rtnall rtn))))))))
  4497. (if org-agenda-overriding-header
  4498. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4499. nil 'face 'org-agenda-structure) "\n")
  4500. (insert "Headlines with TAGS match: ")
  4501. (add-text-properties (point-min) (1- (point))
  4502. (list 'face 'org-agenda-structure
  4503. 'short-heading
  4504. (concat "Match: " match)))
  4505. (setq pos (point))
  4506. (insert match "\n")
  4507. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4508. (setq pos (point))
  4509. (unless org-agenda-multi
  4510. (insert (substitute-command-keys
  4511. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4512. to search again with new search string\n")))
  4513. (add-text-properties pos (1- (point))
  4514. (list 'face 'org-agenda-structure)))
  4515. (org-agenda-mark-header-line (point-min))
  4516. (when rtnall
  4517. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4518. (goto-char (point-min))
  4519. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4520. (add-text-properties
  4521. (point-min) (point-max)
  4522. `(org-agenda-type tags
  4523. org-last-args (,org--matcher-tags-todo-only ,match)
  4524. org-redo-cmd ,org-agenda-redo-command
  4525. org-series-cmd ,org-cmd))
  4526. (org-agenda-finalize)
  4527. (setq buffer-read-only t))))
  4528. ;;; Agenda Finding stuck projects
  4529. (defvar org-agenda-skip-regexp nil
  4530. "Regular expression used in skipping subtrees for the agenda.
  4531. This is basically a temporary global variable that can be set and then
  4532. used by user-defined selections using `org-agenda-skip-function'.")
  4533. (defvar org-agenda-overriding-header nil
  4534. "When set during agenda, todo and tags searches it replaces the header.
  4535. This variable should not be set directly, but custom commands can bind it
  4536. in the options section.")
  4537. (defun org-agenda-skip-entry-when-regexp-matches ()
  4538. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4539. If yes, it returns the end position of this entry, causing agenda commands
  4540. to skip the entry but continuing the search in the subtree. This is a
  4541. function that can be put into `org-agenda-skip-function' for the duration
  4542. of a command."
  4543. (let ((end (save-excursion (org-end-of-subtree t)))
  4544. skip)
  4545. (save-excursion
  4546. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4547. (and skip end)))
  4548. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4549. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4550. If yes, it returns the end position of this tree, causing agenda commands
  4551. to skip this subtree. This is a function that can be put into
  4552. `org-agenda-skip-function' for the duration of a command."
  4553. (let ((end (save-excursion (org-end-of-subtree t)))
  4554. skip)
  4555. (save-excursion
  4556. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4557. (and skip end)))
  4558. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4559. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4560. If yes, it returns the end position of the current entry (NOT the tree),
  4561. causing agenda commands to skip the entry but continuing the search in
  4562. the subtree. This is a function that can be put into
  4563. `org-agenda-skip-function' for the duration of a command. An important
  4564. use of this function is for the stuck project list."
  4565. (let ((end (save-excursion (org-end-of-subtree t)))
  4566. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4567. skip)
  4568. (save-excursion
  4569. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4570. (and skip entry-end)))
  4571. (defun org-agenda-skip-entry-if (&rest conditions)
  4572. "Skip entry if any of CONDITIONS is true.
  4573. See `org-agenda-skip-if' for details."
  4574. (org-agenda-skip-if nil conditions))
  4575. (defun org-agenda-skip-subtree-if (&rest conditions)
  4576. "Skip subtree if any of CONDITIONS is true.
  4577. See `org-agenda-skip-if' for details."
  4578. (org-agenda-skip-if t conditions))
  4579. (defun org-agenda-skip-if (subtree conditions)
  4580. "Checks current entity for CONDITIONS.
  4581. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4582. the entry (i.e. the text before the next heading) is checked.
  4583. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4584. from different tests. Valid conditions are:
  4585. scheduled Check if there is a scheduled cookie
  4586. notscheduled Check if there is no scheduled cookie
  4587. deadline Check if there is a deadline
  4588. notdeadline Check if there is no deadline
  4589. timestamp Check if there is a timestamp (also deadline or scheduled)
  4590. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4591. regexp Check if regexp matches
  4592. notregexp Check if regexp does not match.
  4593. todo Check if TODO keyword matches
  4594. nottodo Check if TODO keyword does not match
  4595. The regexp is taken from the conditions list, it must come right after
  4596. the `regexp' or `notregexp' element.
  4597. `todo' and `nottodo' accept as an argument a list of todo
  4598. keywords, which may include \"*\" to match any todo keyword.
  4599. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4600. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4601. Instead of a list, a keyword class may be given. For example:
  4602. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4603. would skip entries that haven't been marked with any of \"DONE\"
  4604. keywords. Possible classes are: `todo', `done', `any'.
  4605. If any of these conditions is met, this function returns the end point of
  4606. the entity, causing the search to continue from there. This is a function
  4607. that can be put into `org-agenda-skip-function' for the duration of a command."
  4608. (let (beg end m)
  4609. (org-back-to-heading t)
  4610. (setq beg (point)
  4611. end (if subtree
  4612. (progn (org-end-of-subtree t) (point))
  4613. (progn (outline-next-heading) (1- (point)))))
  4614. (goto-char beg)
  4615. (and
  4616. (or
  4617. (and (memq 'scheduled conditions)
  4618. (re-search-forward org-scheduled-time-regexp end t))
  4619. (and (memq 'notscheduled conditions)
  4620. (not (re-search-forward org-scheduled-time-regexp end t)))
  4621. (and (memq 'deadline conditions)
  4622. (re-search-forward org-deadline-time-regexp end t))
  4623. (and (memq 'notdeadline conditions)
  4624. (not (re-search-forward org-deadline-time-regexp end t)))
  4625. (and (memq 'timestamp conditions)
  4626. (re-search-forward org-ts-regexp end t))
  4627. (and (memq 'nottimestamp conditions)
  4628. (not (re-search-forward org-ts-regexp end t)))
  4629. (and (setq m (memq 'regexp conditions))
  4630. (stringp (nth 1 m))
  4631. (re-search-forward (nth 1 m) end t))
  4632. (and (setq m (memq 'notregexp conditions))
  4633. (stringp (nth 1 m))
  4634. (not (re-search-forward (nth 1 m) end t)))
  4635. (and (or
  4636. (setq m (memq 'nottodo conditions))
  4637. (setq m (memq 'todo-unblocked conditions))
  4638. (setq m (memq 'nottodo-unblocked conditions))
  4639. (setq m (memq 'todo conditions)))
  4640. (org-agenda-skip-if-todo m end)))
  4641. end)))
  4642. (defun org-agenda-skip-if-todo (args end)
  4643. "Helper function for `org-agenda-skip-if', do not use it directly.
  4644. ARGS is a list with first element either `todo', `nottodo',
  4645. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4646. a list of TODO keywords, or a state symbol `todo' or `done' or
  4647. `any'."
  4648. (let ((kw (car args))
  4649. (arg (cadr args))
  4650. todo-wds todo-re)
  4651. (setq todo-wds
  4652. (org-uniquify
  4653. (cond
  4654. ((listp arg) ;; list of keywords
  4655. (if (member "*" arg)
  4656. (mapcar 'substring-no-properties org-todo-keywords-1)
  4657. arg))
  4658. ((symbolp arg) ;; keyword class name
  4659. (cond
  4660. ((eq arg 'todo)
  4661. (org-delete-all org-done-keywords
  4662. (mapcar 'substring-no-properties
  4663. org-todo-keywords-1)))
  4664. ((eq arg 'done) org-done-keywords)
  4665. ((eq arg 'any)
  4666. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4667. (setq todo-re
  4668. (concat "^\\*+[ \t]+\\<\\("
  4669. (mapconcat 'identity todo-wds "\\|")
  4670. "\\)\\>"))
  4671. (cond
  4672. ((eq kw 'todo) (re-search-forward todo-re end t))
  4673. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4674. ((eq kw 'todo-unblocked)
  4675. (catch 'unblocked
  4676. (while (re-search-forward todo-re end t)
  4677. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4678. nil))
  4679. ((eq kw 'nottodo-unblocked)
  4680. (catch 'unblocked
  4681. (while (re-search-forward todo-re end t)
  4682. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4683. t))
  4684. )))
  4685. ;;;###autoload
  4686. (defun org-agenda-list-stuck-projects (&rest ignore)
  4687. "Create agenda view for projects that are stuck.
  4688. Stuck projects are project that have no next actions. For the definitions
  4689. of what a project is and how to check if it stuck, customize the variable
  4690. `org-stuck-projects'."
  4691. (interactive)
  4692. (let* ((org-agenda-skip-function
  4693. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4694. ;; We could have used org-agenda-skip-if here.
  4695. (org-agenda-overriding-header
  4696. (or org-agenda-overriding-header "List of stuck projects: "))
  4697. (matcher (nth 0 org-stuck-projects))
  4698. (todo (nth 1 org-stuck-projects))
  4699. (todo-wds (if (member "*" todo)
  4700. (progn
  4701. (org-agenda-prepare-buffers (org-agenda-files
  4702. nil 'ifmode))
  4703. (org-delete-all
  4704. org-done-keywords-for-agenda
  4705. (copy-sequence org-todo-keywords-for-agenda)))
  4706. todo))
  4707. (todo-re (concat "^\\*+[ \t]+\\("
  4708. (mapconcat 'identity todo-wds "\\|")
  4709. "\\)\\>"))
  4710. (tags (nth 2 org-stuck-projects))
  4711. (tags-re (if (member "*" tags)
  4712. (concat org-outline-regexp-bol
  4713. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4714. (if tags
  4715. (concat org-outline-regexp-bol
  4716. ".*:\\("
  4717. (mapconcat 'identity tags "\\|")
  4718. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4719. (gen-re (nth 3 org-stuck-projects))
  4720. (re-list
  4721. (delq nil
  4722. (list
  4723. (if todo todo-re)
  4724. (if tags tags-re)
  4725. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4726. gen-re)))))
  4727. (setq org-agenda-skip-regexp
  4728. (if re-list
  4729. (mapconcat 'identity re-list "\\|")
  4730. (error "No information how to identify unstuck projects")))
  4731. (org-tags-view nil matcher)
  4732. (setq org-agenda-buffer-name (buffer-name))
  4733. (with-current-buffer org-agenda-buffer-name
  4734. (setq org-agenda-redo-command
  4735. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4736. ;;; Diary integration
  4737. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4738. (defvar diary-list-entries-hook)
  4739. (defvar diary-time-regexp)
  4740. (defun org-get-entries-from-diary (date)
  4741. "Get the (Emacs Calendar) diary entries for DATE."
  4742. (require 'diary-lib)
  4743. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4744. (diary-display-function 'diary-fancy-display)
  4745. (pop-up-frames nil)
  4746. (diary-list-entries-hook
  4747. (cons 'org-diary-default-entry diary-list-entries-hook))
  4748. (diary-file-name-prefix nil) ; turn this feature off
  4749. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4750. entries
  4751. (org-disable-agenda-to-diary t))
  4752. (save-excursion
  4753. (save-window-excursion
  4754. (funcall (if (fboundp 'diary-list-entries)
  4755. 'diary-list-entries 'list-diary-entries)
  4756. date 1)))
  4757. (if (not (get-buffer diary-fancy-buffer))
  4758. (setq entries nil)
  4759. (with-current-buffer diary-fancy-buffer
  4760. (setq buffer-read-only nil)
  4761. (if (zerop (buffer-size))
  4762. ;; No entries
  4763. (setq entries nil)
  4764. ;; Omit the date and other unnecessary stuff
  4765. (org-agenda-cleanup-fancy-diary)
  4766. ;; Add prefix to each line and extend the text properties
  4767. (if (zerop (buffer-size))
  4768. (setq entries nil)
  4769. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4770. (setq entries
  4771. (with-temp-buffer
  4772. (insert entries) (goto-char (point-min))
  4773. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4774. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4775. (replace-match (concat "; " (match-string 1)))))
  4776. (buffer-string)))))
  4777. (set-buffer-modified-p nil)
  4778. (kill-buffer diary-fancy-buffer)))
  4779. (when entries
  4780. (setq entries (org-split-string entries "\n"))
  4781. (setq entries
  4782. (mapcar
  4783. (lambda (x)
  4784. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4785. ;; Extend the text properties to the beginning of the line
  4786. (org-add-props x (text-properties-at (1- (length x)) x)
  4787. 'type "diary" 'date date 'face 'org-agenda-diary))
  4788. entries)))))
  4789. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4790. "Hook run when the fancy diary buffer is cleaned up.")
  4791. (defun org-agenda-cleanup-fancy-diary ()
  4792. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4793. This gets rid of the date, the underline under the date, and
  4794. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4795. date. It also removes lines that contain only whitespace."
  4796. (goto-char (point-min))
  4797. (if (looking-at ".*?:[ \t]*")
  4798. (progn
  4799. (replace-match "")
  4800. (re-search-forward "\n=+$" nil t)
  4801. (replace-match "")
  4802. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4803. (re-search-forward "\n=+$" nil t)
  4804. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4805. (goto-char (point-min))
  4806. (while (re-search-forward "^ +\n" nil t)
  4807. (replace-match ""))
  4808. (goto-char (point-min))
  4809. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4810. (replace-match ""))
  4811. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4812. ;; Make sure entries from the diary have the right text properties.
  4813. (eval-after-load "diary-lib"
  4814. '(if (boundp 'diary-modify-entry-list-string-function)
  4815. ;; We can rely on the hook, nothing to do
  4816. nil
  4817. ;; Hook not available, must use advice to make this work
  4818. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4819. "Make the position visible."
  4820. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4821. (stringp string)
  4822. buffer-file-name)
  4823. (setq string (org-modify-diary-entry-string string))))))
  4824. (defun org-modify-diary-entry-string (string)
  4825. "Add text properties to string, allowing org-mode to act on it."
  4826. (org-add-props string nil
  4827. 'mouse-face 'highlight
  4828. 'help-echo (if buffer-file-name
  4829. (format "mouse-2 or RET jump to diary file %s"
  4830. (abbreviate-file-name buffer-file-name))
  4831. "")
  4832. 'org-agenda-diary-link t
  4833. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4834. (defun org-diary-default-entry ()
  4835. "Add a dummy entry to the diary.
  4836. Needed to avoid empty dates which mess up holiday display."
  4837. ;; Catch the error if dealing with the new add-to-diary-alist
  4838. (when org-disable-agenda-to-diary
  4839. (condition-case nil
  4840. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4841. (error
  4842. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4843. (defun org-add-to-diary-list (&rest args)
  4844. (if (fboundp 'diary-add-to-list)
  4845. (apply 'diary-add-to-list args)
  4846. (apply 'add-to-diary-list args)))
  4847. (defvar org-diary-last-run-time nil)
  4848. ;;;###autoload
  4849. (defun org-diary (&rest args)
  4850. "Return diary information from org files.
  4851. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4852. It accesses org files and extracts information from those files to be
  4853. listed in the diary. The function accepts arguments specifying what
  4854. items should be listed. For a list of arguments allowed here, see the
  4855. variable `org-agenda-entry-types'.
  4856. The call in the diary file should look like this:
  4857. &%%(org-diary) ~/path/to/some/orgfile.org
  4858. Use a separate line for each org file to check. Or, if you omit the file name,
  4859. all files listed in `org-agenda-files' will be checked automatically:
  4860. &%%(org-diary)
  4861. If you don't give any arguments (as in the example above), the default value
  4862. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4863. So the example above may also be written as
  4864. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4865. The function expects the lisp variables `entry' and `date' to be provided
  4866. by the caller, because this is how the calendar works. Don't use this
  4867. function from a program - use `org-agenda-get-day-entries' instead."
  4868. (when (> (- (org-float-time)
  4869. org-agenda-last-marker-time)
  4870. 5)
  4871. ;; I am not sure if this works with sticky agendas, because the marker
  4872. ;; list is then no longer a global variable.
  4873. (org-agenda-reset-markers))
  4874. (org-compile-prefix-format 'agenda)
  4875. (org-set-sorting-strategy 'agenda)
  4876. (setq args (or args org-agenda-entry-types))
  4877. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4878. (list entry)
  4879. (org-agenda-files t)))
  4880. (time (org-float-time))
  4881. file rtn results)
  4882. (when (or (not org-diary-last-run-time)
  4883. (> (- time
  4884. org-diary-last-run-time)
  4885. 3))
  4886. (org-agenda-prepare-buffers files))
  4887. (setq org-diary-last-run-time time)
  4888. ;; If this is called during org-agenda, don't return any entries to
  4889. ;; the calendar. Org Agenda will list these entries itself.
  4890. (if org-disable-agenda-to-diary (setq files nil))
  4891. (while (setq file (pop files))
  4892. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4893. (setq results (append results rtn)))
  4894. (when results
  4895. (setq results
  4896. (mapcar (lambda (i) (replace-regexp-in-string
  4897. org-bracket-link-regexp "\\3" i)) results))
  4898. (concat (org-agenda-finalize-entries results) "\n"))))
  4899. ;;; Agenda entry finders
  4900. (defun org-agenda--timestamp-to-absolute (&rest args)
  4901. "Call `org-time-string-to-absolute' with ARGS.
  4902. However, throw `:skip' whenever an error is raised."
  4903. (condition-case e
  4904. (apply #'org-time-string-to-absolute args)
  4905. (org-diary-sexp-no-match (throw :skip nil))
  4906. (error
  4907. (message "%s; Skipping entry" (error-message-string e))
  4908. (throw :skip nil))))
  4909. (defun org-agenda-get-day-entries (file date &rest args)
  4910. "Does the work for `org-diary' and `org-agenda'.
  4911. FILE is the path to a file to be checked for entries. DATE is date like
  4912. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4913. which kind of entries should be extracted. For details about these, see
  4914. the documentation of `org-diary'."
  4915. (let* ((org-startup-folded nil)
  4916. (org-startup-align-all-tables nil)
  4917. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4918. (error "No such file %s" file))))
  4919. (if (not buffer)
  4920. ;; If file does not exist, signal it in diary nonetheless.
  4921. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4922. (with-current-buffer buffer
  4923. (unless (derived-mode-p 'org-mode)
  4924. (error "Agenda file %s is not in `org-mode'" file))
  4925. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4926. (setf org-agenda-current-date date)
  4927. (save-excursion
  4928. (save-restriction
  4929. (if (eq buffer org-agenda-restrict)
  4930. (narrow-to-region org-agenda-restrict-begin
  4931. org-agenda-restrict-end)
  4932. (widen))
  4933. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4934. ;; first in order to populate DEADLINES before passing it.
  4935. ;;
  4936. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4937. ;; guarding us from modifying `org-agenda-entry-types'.
  4938. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4939. (when (and (memq :scheduled args) (memq :scheduled* args))
  4940. (setf args (delq :scheduled* args)))
  4941. (cond
  4942. ((memq :deadline args)
  4943. (setf args (cons :deadline
  4944. (delq :deadline (delq :deadline* args)))))
  4945. ((memq :deadline* args)
  4946. (setf args (cons :deadline* (delq :deadline* args)))))
  4947. ;; Collect list of headlines. Return them flattened.
  4948. (let ((case-fold-search nil) results deadlines)
  4949. (dolist (arg args (apply #'nconc (nreverse results)))
  4950. (pcase arg
  4951. ((and :todo (guard (org-agenda-today-p date)))
  4952. (push (org-agenda-get-todos) results))
  4953. (:timestamp
  4954. (push (org-agenda-get-blocks) results)
  4955. (push (org-agenda-get-timestamps deadlines) results))
  4956. (:sexp
  4957. (push (org-agenda-get-sexps) results))
  4958. (:scheduled
  4959. (push (org-agenda-get-scheduled deadlines) results))
  4960. (:scheduled*
  4961. (push (org-agenda-get-scheduled deadlines t) results))
  4962. (:closed
  4963. (push (org-agenda-get-progress) results))
  4964. (:deadline
  4965. (setf deadlines (org-agenda-get-deadlines))
  4966. (push deadlines results))
  4967. (:deadline*
  4968. (setf deadlines (org-agenda-get-deadlines t))
  4969. (push deadlines results)))))))))))
  4970. (defsubst org-em (x y list)
  4971. "Is X or Y a member of LIST?"
  4972. (or (memq x list) (memq y list)))
  4973. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4974. (defvar org-agenda-sorting-strategy-selected nil)
  4975. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4976. "Retrieve timestamp information for sorting agenda views.
  4977. Given a point or marker POM, returns a cons cell of the timestamp
  4978. and the timestamp type relevant for the sorting strategy in
  4979. `org-agenda-sorting-strategy-selected'."
  4980. (let (ts ts-date-type)
  4981. (save-match-data
  4982. (cond ((org-em 'scheduled-up 'scheduled-down
  4983. org-agenda-sorting-strategy-selected)
  4984. (setq ts (org-entry-get pom "SCHEDULED")
  4985. ts-date-type " scheduled"))
  4986. ((org-em 'deadline-up 'deadline-down
  4987. org-agenda-sorting-strategy-selected)
  4988. (setq ts (org-entry-get pom "DEADLINE")
  4989. ts-date-type " deadline"))
  4990. ((org-em 'ts-up 'ts-down
  4991. org-agenda-sorting-strategy-selected)
  4992. (setq ts (org-entry-get pom "TIMESTAMP")
  4993. ts-date-type " timestamp"))
  4994. ((org-em 'tsia-up 'tsia-down
  4995. org-agenda-sorting-strategy-selected)
  4996. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4997. ts-date-type " timestamp_ia"))
  4998. ((org-em 'timestamp-up 'timestamp-down
  4999. org-agenda-sorting-strategy-selected)
  5000. (setq ts (or (org-entry-get pom "SCHEDULED")
  5001. (org-entry-get pom "DEADLINE")
  5002. (org-entry-get pom "TIMESTAMP")
  5003. (org-entry-get pom "TIMESTAMP_IA"))
  5004. ts-date-type ""))
  5005. (t (setq ts-date-type "")))
  5006. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5007. ts-date-type))))
  5008. (defun org-agenda-get-todos ()
  5009. "Return the TODO information for agenda display."
  5010. (let* ((props (list 'face nil
  5011. 'done-face 'org-agenda-done
  5012. 'org-not-done-regexp org-not-done-regexp
  5013. 'org-todo-regexp org-todo-regexp
  5014. 'org-complex-heading-regexp org-complex-heading-regexp
  5015. 'mouse-face 'highlight
  5016. 'help-echo
  5017. (format "mouse-2 or RET jump to org file %s"
  5018. (abbreviate-file-name buffer-file-name))))
  5019. (regexp (format org-heading-keyword-regexp-format
  5020. (cond
  5021. ((and org-select-this-todo-keyword
  5022. (equal org-select-this-todo-keyword "*"))
  5023. org-todo-regexp)
  5024. (org-select-this-todo-keyword
  5025. (concat "\\("
  5026. (mapconcat 'identity
  5027. (org-split-string
  5028. org-select-this-todo-keyword
  5029. "|")
  5030. "\\|") "\\)"))
  5031. (t org-not-done-regexp))))
  5032. marker priority category level tags todo-state
  5033. ts-date ts-date-type ts-date-pair
  5034. ee txt beg end inherited-tags todo-state-end-pos)
  5035. (goto-char (point-min))
  5036. (while (re-search-forward regexp nil t)
  5037. (catch :skip
  5038. (save-match-data
  5039. (beginning-of-line)
  5040. (org-agenda-skip)
  5041. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5042. (unless (and (setq todo-state (org-get-todo-state))
  5043. (setq todo-state-end-pos (match-end 2)))
  5044. (goto-char end)
  5045. (throw :skip nil))
  5046. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5047. (goto-char (1+ beg))
  5048. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5049. (throw :skip nil)))
  5050. (goto-char (match-beginning 2))
  5051. (setq marker (org-agenda-new-marker (match-beginning 0))
  5052. category (org-get-category)
  5053. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5054. ts-date (car ts-date-pair)
  5055. ts-date-type (cdr ts-date-pair)
  5056. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5057. inherited-tags
  5058. (or (eq org-agenda-show-inherited-tags 'always)
  5059. (and (listp org-agenda-show-inherited-tags)
  5060. (memq 'todo org-agenda-show-inherited-tags))
  5061. (and (eq org-agenda-show-inherited-tags t)
  5062. (or (eq org-agenda-use-tag-inheritance t)
  5063. (memq 'todo org-agenda-use-tag-inheritance))))
  5064. tags (org-get-tags-at nil (not inherited-tags))
  5065. level (make-string (org-reduced-level (org-outline-level)) ? )
  5066. txt (org-agenda-format-item "" txt level category tags t)
  5067. priority (1+ (org-get-priority txt)))
  5068. (org-add-props txt props
  5069. 'org-marker marker 'org-hd-marker marker
  5070. 'priority priority
  5071. 'level level
  5072. 'ts-date ts-date
  5073. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5074. (push txt ee)
  5075. (if org-agenda-todo-list-sublevels
  5076. (goto-char todo-state-end-pos)
  5077. (org-end-of-subtree 'invisible))))
  5078. (nreverse ee)))
  5079. (defun org-agenda-todo-custom-ignore-p (time n)
  5080. "Check whether timestamp is farther away than n number of days.
  5081. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5082. `org-agenda-todo-ignore-scheduled' or
  5083. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5084. (let ((days (org-time-stamp-to-now
  5085. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5086. (if (>= n 0)
  5087. (>= days n)
  5088. (<= days n))))
  5089. ;;;###autoload
  5090. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5091. (&optional end)
  5092. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5093. (when (or org-agenda-todo-ignore-with-date
  5094. org-agenda-todo-ignore-scheduled
  5095. org-agenda-todo-ignore-deadlines
  5096. org-agenda-todo-ignore-timestamp)
  5097. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5098. (save-excursion
  5099. (or (and org-agenda-todo-ignore-with-date
  5100. (re-search-forward org-ts-regexp end t))
  5101. (and org-agenda-todo-ignore-scheduled
  5102. (re-search-forward org-scheduled-time-regexp end t)
  5103. (cond
  5104. ((eq org-agenda-todo-ignore-scheduled 'future)
  5105. (> (org-time-stamp-to-now
  5106. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5107. ((eq org-agenda-todo-ignore-scheduled 'past)
  5108. (<= (org-time-stamp-to-now
  5109. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5110. ((numberp org-agenda-todo-ignore-scheduled)
  5111. (org-agenda-todo-custom-ignore-p
  5112. (match-string 1) org-agenda-todo-ignore-scheduled))
  5113. (t)))
  5114. (and org-agenda-todo-ignore-deadlines
  5115. (re-search-forward org-deadline-time-regexp end t)
  5116. (cond
  5117. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5118. ((eq org-agenda-todo-ignore-deadlines 'far)
  5119. (not (org-deadline-close (match-string 1))))
  5120. ((eq org-agenda-todo-ignore-deadlines 'future)
  5121. (> (org-time-stamp-to-now
  5122. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5123. ((eq org-agenda-todo-ignore-deadlines 'past)
  5124. (<= (org-time-stamp-to-now
  5125. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5126. ((numberp org-agenda-todo-ignore-deadlines)
  5127. (org-agenda-todo-custom-ignore-p
  5128. (match-string 1) org-agenda-todo-ignore-deadlines))
  5129. (t (org-deadline-close (match-string 1)))))
  5130. (and org-agenda-todo-ignore-timestamp
  5131. (let ((buffer (current-buffer))
  5132. (regexp
  5133. (concat
  5134. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5135. (start (point)))
  5136. ;; Copy current buffer into a temporary one
  5137. (with-temp-buffer
  5138. (insert-buffer-substring buffer start end)
  5139. (goto-char (point-min))
  5140. ;; Delete SCHEDULED and DEADLINE items
  5141. (while (re-search-forward regexp end t)
  5142. (delete-region (match-beginning 0) (match-end 0)))
  5143. (goto-char (point-min))
  5144. ;; No search for timestamp left
  5145. (when (re-search-forward org-ts-regexp nil t)
  5146. (cond
  5147. ((eq org-agenda-todo-ignore-timestamp 'future)
  5148. (> (org-time-stamp-to-now
  5149. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5150. ((eq org-agenda-todo-ignore-timestamp 'past)
  5151. (<= (org-time-stamp-to-now
  5152. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5153. ((numberp org-agenda-todo-ignore-timestamp)
  5154. (org-agenda-todo-custom-ignore-p
  5155. (match-string 1) org-agenda-todo-ignore-timestamp))
  5156. (t))))))))))
  5157. (defun org-agenda-get-timestamps (&optional deadline-results)
  5158. "Return the date stamp information for agenda display."
  5159. (let* ((props (list 'face 'org-agenda-calendar-event
  5160. 'org-not-done-regexp org-not-done-regexp
  5161. 'org-todo-regexp org-todo-regexp
  5162. 'org-complex-heading-regexp org-complex-heading-regexp
  5163. 'mouse-face 'highlight
  5164. 'help-echo
  5165. (format "mouse-2 or RET jump to org file %s"
  5166. (abbreviate-file-name buffer-file-name))))
  5167. (d1 (calendar-absolute-from-gregorian date))
  5168. mm
  5169. (deadline-position-alist
  5170. (mapcar (lambda (a) (and (setq mm (get-text-property
  5171. 0 'org-hd-marker a))
  5172. (cons (marker-position mm) a)))
  5173. deadline-results))
  5174. (remove-re org-ts-regexp)
  5175. (regexp
  5176. (concat
  5177. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5178. (regexp-quote
  5179. (substring
  5180. (format-time-string
  5181. (car org-time-stamp-formats)
  5182. (apply 'encode-time ; DATE bound by calendar
  5183. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5184. 1 11))
  5185. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5186. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5187. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5188. donep tmp priority category level ee txt timestr tags
  5189. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5190. inherited-tags ts-date)
  5191. (goto-char (point-min))
  5192. (while (setq end-of-match (re-search-forward regexp nil t))
  5193. (setq b0 (match-beginning 0)
  5194. b3 (match-beginning 3) e3 (match-end 3)
  5195. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5196. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5197. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5198. (member todo-state
  5199. org-agenda-repeating-timestamp-show-all)))
  5200. (catch :skip
  5201. (and (org-at-date-range-p) (throw :skip nil))
  5202. (org-agenda-skip)
  5203. (if (and (match-end 1)
  5204. (not (= d1 (org-agenda--timestamp-to-absolute
  5205. (match-string 1) d1 nil show-all
  5206. (current-buffer) b0))))
  5207. (throw :skip nil))
  5208. (if (and e3
  5209. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5210. (throw :skip nil))
  5211. (setq tmp (buffer-substring (max (point-min)
  5212. (- b0 org-ds-keyword-length))
  5213. b0)
  5214. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5215. inactivep (= (char-after b0) ?\[)
  5216. deadlinep (string-match org-deadline-regexp tmp)
  5217. scheduledp (string-match org-scheduled-regexp tmp)
  5218. closedp (and org-agenda-include-inactive-timestamps
  5219. (string-match org-closed-string tmp))
  5220. clockp (and org-agenda-include-inactive-timestamps
  5221. (or (string-match org-clock-string tmp)
  5222. (string-match "]-+\\'" tmp)))
  5223. warntime (get-text-property (point) 'org-appt-warntime)
  5224. donep (member todo-state org-done-keywords))
  5225. (if (or scheduledp deadlinep closedp clockp
  5226. (and donep org-agenda-skip-timestamp-if-done))
  5227. (throw :skip t))
  5228. (if (string-match ">" timestr)
  5229. ;; substring should only run to end of time stamp
  5230. (setq timestr (substring timestr 0 (match-end 0))))
  5231. (setq marker (org-agenda-new-marker b0)
  5232. category (org-get-category b0))
  5233. (save-excursion
  5234. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5235. (throw :skip nil)
  5236. (goto-char (match-beginning 0))
  5237. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5238. (assoc (point) deadline-position-alist))
  5239. (throw :skip nil))
  5240. (setq hdmarker (org-agenda-new-marker)
  5241. inherited-tags
  5242. (or (eq org-agenda-show-inherited-tags 'always)
  5243. (and (listp org-agenda-show-inherited-tags)
  5244. (memq 'agenda org-agenda-show-inherited-tags))
  5245. (and (eq org-agenda-show-inherited-tags t)
  5246. (or (eq org-agenda-use-tag-inheritance t)
  5247. (memq 'agenda org-agenda-use-tag-inheritance))))
  5248. tags (org-get-tags-at nil (not inherited-tags))
  5249. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5250. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5251. (setq head (or (match-string 1) ""))
  5252. (setq txt (org-agenda-format-item
  5253. (if inactivep org-agenda-inactive-leader nil)
  5254. head level category tags timestr
  5255. remove-re habitp)))
  5256. (setq priority (org-get-priority txt))
  5257. (org-add-props txt props 'priority priority
  5258. 'org-marker marker 'org-hd-marker hdmarker
  5259. 'date date
  5260. 'level level
  5261. 'ts-date
  5262. (ignore-errors (org-time-string-to-absolute timestr))
  5263. 'todo-state todo-state
  5264. 'warntime warntime
  5265. 'type "timestamp")
  5266. (push txt ee))
  5267. (if org-agenda-skip-additional-timestamps-same-entry
  5268. (outline-next-heading)
  5269. (goto-char end-of-match))))
  5270. (nreverse ee)))
  5271. (defun org-agenda-get-sexps ()
  5272. "Return the sexp information for agenda display."
  5273. (require 'diary-lib)
  5274. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5275. 'mouse-face 'highlight
  5276. 'help-echo
  5277. (format "mouse-2 or RET jump to org file %s"
  5278. (abbreviate-file-name buffer-file-name))))
  5279. (regexp "^&?%%(")
  5280. marker category extra level ee txt tags entry
  5281. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5282. (goto-char (point-min))
  5283. (while (re-search-forward regexp nil t)
  5284. (catch :skip
  5285. (org-agenda-skip)
  5286. (setq beg (match-beginning 0))
  5287. (goto-char (1- (match-end 0)))
  5288. (setq b (point))
  5289. (forward-sexp 1)
  5290. (setq sexp (buffer-substring b (point)))
  5291. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5292. (org-trim (match-string 1))
  5293. ""))
  5294. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5295. (when result
  5296. (setq marker (org-agenda-new-marker beg)
  5297. level (make-string (org-reduced-level (org-outline-level)) ? )
  5298. category (org-get-category beg)
  5299. inherited-tags
  5300. (or (eq org-agenda-show-inherited-tags 'always)
  5301. (and (listp org-agenda-show-inherited-tags)
  5302. (memq 'agenda org-agenda-show-inherited-tags))
  5303. (and (eq org-agenda-show-inherited-tags t)
  5304. (or (eq org-agenda-use-tag-inheritance t)
  5305. (memq 'agenda org-agenda-use-tag-inheritance))))
  5306. tags (org-get-tags-at nil (not inherited-tags))
  5307. todo-state (org-get-todo-state)
  5308. warntime (get-text-property (point) 'org-appt-warntime)
  5309. extra nil)
  5310. (dolist (r (if (stringp result)
  5311. (list result)
  5312. result)) ;; we expect a list here
  5313. (when (and org-agenda-diary-sexp-prefix
  5314. (string-match org-agenda-diary-sexp-prefix r))
  5315. (setq extra (match-string 0 r)
  5316. r (replace-match "" nil nil r)))
  5317. (if (string-match "\\S-" r)
  5318. (setq txt r)
  5319. (setq txt "SEXP entry returned empty string"))
  5320. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5321. (org-add-props txt props 'org-marker marker
  5322. 'date date 'todo-state todo-state
  5323. 'level level 'type "sexp" 'warntime warntime)
  5324. (push txt ee)))))
  5325. (nreverse ee)))
  5326. ;; Calendar sanity: define some functions that are independent of
  5327. ;; `calendar-date-style'.
  5328. ;; Normally I would like to use ISO format when calling the diary functions,
  5329. ;; but to make sure we still have Emacs 22 compatibility we bind
  5330. ;; also `european-calendar-style' and use european format
  5331. (defun org-anniversary (year month day &optional mark)
  5332. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5333. (org-no-warnings
  5334. (let ((calendar-date-style 'european) (european-calendar-style t))
  5335. (diary-anniversary day month year mark))))
  5336. (defun org-cyclic (N year month day &optional mark)
  5337. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5338. (org-no-warnings
  5339. (let ((calendar-date-style 'european) (european-calendar-style t))
  5340. (diary-cyclic N day month year mark))))
  5341. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5342. "Like `diary-block', but with fixed (ISO) order of arguments."
  5343. (org-no-warnings
  5344. (let ((calendar-date-style 'european) (european-calendar-style t))
  5345. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5346. (defun org-date (year month day &optional mark)
  5347. "Like `diary-date', but with fixed (ISO) order of arguments."
  5348. (org-no-warnings
  5349. (let ((calendar-date-style 'european) (european-calendar-style t))
  5350. (diary-date day month year mark))))
  5351. ;; Define the `org-class' function
  5352. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5353. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5354. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5355. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5356. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5357. `holidays', then any date that is known by the Emacs calendar to be a
  5358. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5359. then those holidays will be skipped."
  5360. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5361. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5362. (d (calendar-absolute-from-gregorian date))
  5363. (h (when skip-weeks (calendar-check-holidays date))))
  5364. (and
  5365. (<= date1 d)
  5366. (<= d date2)
  5367. (= (calendar-day-of-week date) dayname)
  5368. (or (not skip-weeks)
  5369. (progn
  5370. (require 'cal-iso)
  5371. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5372. (not (or (and h (memq 'holidays skip-weeks))
  5373. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5374. entry)))
  5375. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5376. "Like `org-class', but honor `calendar-date-style'.
  5377. The order of the first 2 times 3 arguments depends on the variable
  5378. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5379. So for American calendars, give this as MONTH DAY YEAR, for European as
  5380. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5381. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5382. is any number of ISO weeks in the block period for which the item should
  5383. be skipped.
  5384. This function is here only for backward compatibility and it is deprecated,
  5385. please use `org-class' instead."
  5386. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5387. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5388. (org-class
  5389. (nth 2 date1) (car date1) (nth 1 date1)
  5390. (nth 2 date2) (car date2) (nth 1 date2)
  5391. dayname skip-weeks)))
  5392. (make-obsolete 'org-diary-class 'org-class "")
  5393. (defalias 'org-get-closed 'org-agenda-get-progress)
  5394. (defun org-agenda-get-progress ()
  5395. "Return the logged TODO entries for agenda display."
  5396. (let* ((props (list 'mouse-face 'highlight
  5397. 'org-not-done-regexp org-not-done-regexp
  5398. 'org-todo-regexp org-todo-regexp
  5399. 'org-complex-heading-regexp org-complex-heading-regexp
  5400. 'help-echo
  5401. (format "mouse-2 or RET jump to org file %s"
  5402. (abbreviate-file-name buffer-file-name))))
  5403. (items (if (consp org-agenda-show-log-scoped)
  5404. org-agenda-show-log-scoped
  5405. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5406. '(clock)
  5407. org-agenda-log-mode-items)))
  5408. (parts
  5409. (delq nil
  5410. (list
  5411. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5412. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5413. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5414. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5415. (error "`org-agenda-log-mode-items' is empty")))
  5416. (regexp (concat
  5417. "\\(" parts-re "\\)"
  5418. " *\\["
  5419. (regexp-quote
  5420. (substring
  5421. (format-time-string
  5422. (car org-time-stamp-formats)
  5423. (apply 'encode-time ; DATE bound by calendar
  5424. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5425. 1 11))))
  5426. (org-agenda-search-headline-for-time nil)
  5427. marker hdmarker priority category level tags closedp
  5428. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5429. (goto-char (point-min))
  5430. (while (re-search-forward regexp nil t)
  5431. (catch :skip
  5432. (org-agenda-skip)
  5433. (setq marker (org-agenda-new-marker (match-beginning 0))
  5434. closedp (equal (match-string 1) org-closed-string)
  5435. statep (equal (string-to-char (match-string 1)) ?-)
  5436. clockp (not (or closedp statep))
  5437. state (and statep (match-string 2))
  5438. category (org-get-category (match-beginning 0))
  5439. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5440. (when (string-match "\\]" timestr)
  5441. ;; substring should only run to end of time stamp
  5442. (setq rest (substring timestr (match-end 0))
  5443. timestr (substring timestr 0 (match-end 0)))
  5444. (if (and (not closedp) (not statep)
  5445. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5446. rest))
  5447. (progn (setq timestr (concat (substring timestr 0 -1)
  5448. "-" (match-string 1 rest) "]"))
  5449. (setq clocked (match-string 2 rest)))
  5450. (setq clocked "-")))
  5451. (save-excursion
  5452. (setq extra
  5453. (cond
  5454. ((not org-agenda-log-mode-add-notes) nil)
  5455. (statep
  5456. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5457. (match-string 1)))
  5458. (clockp
  5459. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5460. (match-string 1)))))
  5461. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5462. (throw :skip nil)
  5463. (goto-char (match-beginning 0))
  5464. (setq hdmarker (org-agenda-new-marker)
  5465. inherited-tags
  5466. (or (eq org-agenda-show-inherited-tags 'always)
  5467. (and (listp org-agenda-show-inherited-tags)
  5468. (memq 'todo org-agenda-show-inherited-tags))
  5469. (and (eq org-agenda-show-inherited-tags t)
  5470. (or (eq org-agenda-use-tag-inheritance t)
  5471. (memq 'todo org-agenda-use-tag-inheritance))))
  5472. tags (org-get-tags-at nil (not inherited-tags))
  5473. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5474. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5475. (setq txt (match-string 1))
  5476. (when extra
  5477. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5478. (setq txt (concat (substring txt 0 (match-beginning 1))
  5479. " - " extra " " (match-string 2 txt)))
  5480. (setq txt (concat txt " - " extra))))
  5481. (setq txt (org-agenda-format-item
  5482. (cond
  5483. (closedp "Closed: ")
  5484. (statep (concat "State: (" state ")"))
  5485. (t (concat "Clocked: (" clocked ")")))
  5486. txt level category tags timestr)))
  5487. (setq priority 100000)
  5488. (org-add-props txt props
  5489. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5490. 'priority priority 'level level
  5491. 'type "closed" 'date date
  5492. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5493. (push txt ee))
  5494. (goto-char (point-at-eol))))
  5495. (nreverse ee)))
  5496. (defun org-agenda-show-clocking-issues ()
  5497. "Add overlays, showing issues with clocking.
  5498. See also the user option `org-agenda-clock-consistency-checks'."
  5499. (interactive)
  5500. (let* ((org-time-clocksum-use-effort-durations nil)
  5501. (pl org-agenda-clock-consistency-checks)
  5502. (re (concat "^[ \t]*"
  5503. org-clock-string
  5504. "[ \t]+"
  5505. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5506. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5507. (tlstart 0.)
  5508. (tlend 0.)
  5509. (maxtime (org-hh:mm-string-to-minutes
  5510. (or (plist-get pl :max-duration) "24:00")))
  5511. (mintime (org-hh:mm-string-to-minutes
  5512. (or (plist-get pl :min-duration) 0)))
  5513. (maxgap (org-hh:mm-string-to-minutes
  5514. ;; default 30:00 means never complain
  5515. (or (plist-get pl :max-gap) "30:00")))
  5516. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5517. (plist-get pl :gap-ok-around)))
  5518. (def-face (or (plist-get pl :default-face)
  5519. '((:background "DarkRed") (:foreground "white"))))
  5520. issue face m te ts dt ov)
  5521. (goto-char (point-min))
  5522. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5523. (setq issue nil face def-face)
  5524. (catch 'next
  5525. (setq m (org-get-at-bol 'org-marker)
  5526. te nil ts nil)
  5527. (unless (and m (markerp m))
  5528. (setq issue "No valid clock line") (throw 'next t))
  5529. (org-with-point-at m
  5530. (save-excursion
  5531. (goto-char (point-at-bol))
  5532. (unless (looking-at re)
  5533. (error "No valid Clock line")
  5534. (throw 'next t))
  5535. (unless (match-end 3)
  5536. (setq issue "No end time"
  5537. face (or (plist-get pl :no-end-time-face) face))
  5538. (throw 'next t))
  5539. (setq ts (match-string 1)
  5540. te (match-string 3)
  5541. ts (org-float-time
  5542. (apply 'encode-time (org-parse-time-string ts)))
  5543. te (org-float-time
  5544. (apply 'encode-time (org-parse-time-string te)))
  5545. dt (- te ts))))
  5546. (cond
  5547. ((> dt (* 60 maxtime))
  5548. ;; a very long clocking chunk
  5549. (setq issue (format "Clocking interval is very long: %s"
  5550. (org-minutes-to-clocksum-string
  5551. (floor (/ (float dt) 60.))))
  5552. face (or (plist-get pl :long-face) face)))
  5553. ((< dt (* 60 mintime))
  5554. ;; a very short clocking chunk
  5555. (setq issue (format "Clocking interval is very short: %s"
  5556. (org-minutes-to-clocksum-string
  5557. (floor (/ (float dt) 60.))))
  5558. face (or (plist-get pl :short-face) face)))
  5559. ((and (> tlend 0) (< ts tlend))
  5560. ;; Two clock entries are overlapping
  5561. (setq issue (format "Clocking overlap: %d minutes"
  5562. (/ (- tlend ts) 60))
  5563. face (or (plist-get pl :overlap-face) face)))
  5564. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5565. ;; There is a gap, lets see if we need to report it
  5566. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5567. (setq issue (format "Clocking gap: %d minutes"
  5568. (/ (- ts tlend) 60))
  5569. face (or (plist-get pl :gap-face) face))))
  5570. (t nil)))
  5571. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5572. (when issue
  5573. ;; OK, there was some issue, add an overlay to show the issue
  5574. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5575. (overlay-put ov 'before-string
  5576. (concat
  5577. (org-add-props
  5578. (format "%-43s" (concat " " issue))
  5579. nil
  5580. 'face face)
  5581. "\n"))
  5582. (overlay-put ov 'evaporate t)))))
  5583. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5584. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5585. (catch 'exit
  5586. (unless ok-list
  5587. ;; there are no OK times for gaps...
  5588. (throw 'exit nil))
  5589. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5590. ;; This is more than 24 hours, so it is OK.
  5591. ;; because we have at least one OK time, that must be in the
  5592. ;; 24 hour interval.
  5593. (throw 'exit t))
  5594. ;; We have a shorter gap.
  5595. ;; Now we have to get the minute of the day when these times are
  5596. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5597. (t2dec (decode-time (seconds-to-time t2)))
  5598. ;; compute the minute on the day
  5599. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5600. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5601. (when (< min2 min1)
  5602. ;; if min2 is smaller than min1, this means it is on the next day.
  5603. ;; Wrap it to after midnight.
  5604. (setq min2 (+ min2 1440)))
  5605. ;; Now check if any of the OK times is in the gap
  5606. (mapc (lambda (x)
  5607. ;; Wrap the time to after midnight if necessary
  5608. (if (< x min1) (setq x (+ x 1440)))
  5609. ;; Check if in interval
  5610. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5611. ok-list)
  5612. ;; Nope, this gap is not OK
  5613. nil)))
  5614. (defun org-agenda-get-deadlines (&optional with-hour)
  5615. "Return the deadline information for agenda display.
  5616. When WITH-HOUR is non-nil, only return deadlines with an hour
  5617. specification like [h]h:mm."
  5618. (let* ((props (list 'mouse-face 'highlight
  5619. 'org-not-done-regexp org-not-done-regexp
  5620. 'org-todo-regexp org-todo-regexp
  5621. 'org-complex-heading-regexp org-complex-heading-regexp
  5622. 'help-echo
  5623. (format "mouse-2 or RET jump to org file %s"
  5624. (abbreviate-file-name buffer-file-name))))
  5625. (regexp (if with-hour
  5626. org-deadline-time-hour-regexp
  5627. org-deadline-time-regexp))
  5628. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5629. (current (calendar-absolute-from-gregorian date))
  5630. deadline-items)
  5631. (goto-char (point-min))
  5632. (while (re-search-forward regexp nil t)
  5633. (catch :skip
  5634. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5635. (org-agenda-skip)
  5636. (let* ((s (match-string 1))
  5637. (pos (1- (match-beginning 1)))
  5638. (todo-state (save-match-data (org-get-todo-state)))
  5639. (donep (member todo-state org-done-keywords))
  5640. (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5641. (member todo-state
  5642. org-agenda-repeating-timestamp-show-all)))
  5643. ;; DEADLINE is the current scheduled date. When it
  5644. ;; contains a repeater and SHOW-ALL is non-nil,
  5645. ;; LAST-REPEAT is the repeat closest to CURRENT.
  5646. ;; Otherwise, LAST-REPEAT is equal to DEADLINE.
  5647. (last-repeat (org-agenda--timestamp-to-absolute
  5648. s current 'past show-all (current-buffer) pos))
  5649. (deadline (org-agenda--timestamp-to-absolute s current))
  5650. (diff (- last-repeat current))
  5651. (suppress-prewarning
  5652. (let ((scheduled
  5653. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5654. (org-entry-get nil "SCHEDULED"))))
  5655. (cond
  5656. ((not scheduled) nil)
  5657. ;; The current item has a scheduled date, so
  5658. ;; evaluate its prewarning lead time.
  5659. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5660. ;; Use global prewarning-restart lead time.
  5661. org-agenda-skip-deadline-prewarning-if-scheduled)
  5662. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5663. 'pre-scheduled)
  5664. ;; Set pre-warning to no earlier than SCHEDULED.
  5665. (min (- last-repeat
  5666. (org-agenda--timestamp-to-absolute
  5667. scheduled current 'past show-all
  5668. (current-buffer)
  5669. (save-excursion
  5670. (beginning-of-line)
  5671. (1+ (search-forward org-deadline-string)))))
  5672. org-deadline-warning-days))
  5673. ;; Set pre-warning to deadline.
  5674. (t 0))))
  5675. (wdays (if suppress-prewarning
  5676. (let ((org-deadline-warning-days suppress-prewarning))
  5677. (org-get-wdays s))
  5678. (org-get-wdays s))))
  5679. ;; When to show a deadline in the calendar: if the
  5680. ;; expiration is within WDAYS warning time. Past-due
  5681. ;; deadlines are only shown on the current date
  5682. (unless (or (and (<= diff wdays)
  5683. (and todayp (not org-agenda-only-exact-dates)))
  5684. (= diff 0))
  5685. (throw :skip nil))
  5686. ;; Skip done tasks if `org-agenda-skip-deadline-if-done' is
  5687. ;; non-nil or if it isn't applicable to CURRENT deadline.
  5688. (when (and donep
  5689. (or org-agenda-skip-deadline-if-done
  5690. (/= deadline current)))
  5691. (throw :skip nil))
  5692. (save-excursion
  5693. (re-search-backward "^\\*+[ \t]+" nil t)
  5694. (goto-char (match-end 0))
  5695. (let* ((category (org-get-category))
  5696. (level
  5697. (make-string (org-reduced-level (org-outline-level)) ?\s))
  5698. (head (buffer-substring (point) (line-end-position)))
  5699. (inherited-tags
  5700. (or (eq org-agenda-show-inherited-tags 'always)
  5701. (and (listp org-agenda-show-inherited-tags)
  5702. (memq 'agenda org-agenda-show-inherited-tags))
  5703. (and (eq org-agenda-show-inherited-tags t)
  5704. (or (eq org-agenda-use-tag-inheritance t)
  5705. (memq 'agenda
  5706. org-agenda-use-tag-inheritance)))))
  5707. (tags (org-get-tags-at nil (not inherited-tags)))
  5708. (timestr
  5709. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5710. (concat (substring s (match-beginning 1)) " ")
  5711. 'time))
  5712. (item
  5713. (org-agenda-format-item
  5714. ;; For past deadlines, make sure to report time
  5715. ;; difference since date S, not since closest
  5716. ;; repeater.
  5717. (let ((diff (if (< (org-today) current) diff
  5718. (- deadline current))))
  5719. (if (= diff 0) (car org-agenda-deadline-leaders)
  5720. (let ((future (nth 1 org-agenda-deadline-leaders))
  5721. (past (nth 2 org-agenda-deadline-leaders)))
  5722. (cond ((> diff 0) (format future diff))
  5723. ((string= future past) (format past diff))
  5724. (t (format past (abs diff)))))))
  5725. head level category tags
  5726. (and (= diff 0) timestr)))
  5727. (face (org-agenda-deadline-face
  5728. (- 1 (/ (float (- deadline current)) (max wdays 1)))))
  5729. (upcomingp (and todayp (> diff 0)))
  5730. (warntime (get-text-property (point) 'org-appt-warntime)))
  5731. (org-add-props item props
  5732. 'org-marker (org-agenda-new-marker pos)
  5733. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5734. 'warntime warntime
  5735. 'level level
  5736. 'ts-date deadline
  5737. 'priority (- (org-get-priority item) diff)
  5738. 'todo-state todo-state
  5739. 'type (if upcomingp "upcoming-deadline" "deadline")
  5740. 'date (if upcomingp date deadline)
  5741. 'face (if donep 'org-agenda-done face)
  5742. 'undone-face face
  5743. 'done-face 'org-agenda-done)
  5744. (push item deadline-items))))))
  5745. (nreverse deadline-items)))
  5746. (defun org-agenda-deadline-face (fraction)
  5747. "Return the face to displaying a deadline item.
  5748. FRACTION is what fraction of the head-warning time has passed."
  5749. (let ((faces org-agenda-deadline-faces) f)
  5750. (catch 'exit
  5751. (while (setq f (pop faces))
  5752. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5753. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5754. "Return the scheduled information for agenda display.
  5755. Optional argument DEADLINES is a list of deadline items to be
  5756. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5757. scheduled items with an hour specification like [h]h:mm."
  5758. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5759. 'org-todo-regexp org-todo-regexp
  5760. 'org-complex-heading-regexp org-complex-heading-regexp
  5761. 'done-face 'org-agenda-done
  5762. 'mouse-face 'highlight
  5763. 'help-echo
  5764. (format "mouse-2 or RET jump to org file %s"
  5765. (abbreviate-file-name buffer-file-name))))
  5766. (regexp (if with-hour
  5767. org-scheduled-time-hour-regexp
  5768. org-scheduled-time-regexp))
  5769. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5770. (current (calendar-absolute-from-gregorian date))
  5771. (deadline-pos
  5772. (mapcar (lambda (d)
  5773. (let ((m (get-text-property 0 'org-hd-marker d)))
  5774. (and m (marker-position m))))
  5775. deadlines))
  5776. scheduled-items)
  5777. (goto-char (point-min))
  5778. (while (re-search-forward regexp nil t)
  5779. (catch :skip
  5780. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5781. (org-agenda-skip)
  5782. (let* ((s (match-string 1))
  5783. (pos (1- (match-beginning 1)))
  5784. (todo-state (save-match-data (org-get-todo-state)))
  5785. (donep (member todo-state org-done-keywords))
  5786. (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5787. (member todo-state
  5788. org-agenda-repeating-timestamp-show-all)))
  5789. ;; SCHEDULE is the current scheduled date. When it
  5790. ;; contains a repeater and SHOW-ALL is non-nil,
  5791. ;; LAST-REPEAT is the repeat closest to CURRENT.
  5792. ;; Otherwise, LAST-REPEAT is equal to SCHEDULE.
  5793. (last-repeat (org-agenda--timestamp-to-absolute
  5794. s current 'past show-all (current-buffer) pos))
  5795. (schedule (org-agenda--timestamp-to-absolute s current))
  5796. (diff (- last-repeat current))
  5797. (warntime (get-text-property (point) 'org-appt-warntime))
  5798. (pastschedp (< schedule (org-today)))
  5799. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5800. (suppress-delay
  5801. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5802. (org-entry-get nil "DEADLINE"))))
  5803. (cond
  5804. ((not deadline) nil)
  5805. ;; The current item has a deadline date, so
  5806. ;; evaluate its delay time.
  5807. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5808. ;; Use global delay time.
  5809. (- org-agenda-skip-scheduled-delay-if-deadline))
  5810. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5811. 'post-deadline)
  5812. ;; Set delay to no later than DEADLINE. If
  5813. ;; DEADLINE has a repeater, compare last schedule
  5814. ;; repeat and last deadline repeat.
  5815. (min (- last-repeat
  5816. (org-agenda--timestamp-to-absolute
  5817. deadline current 'past show-all
  5818. (current-buffer)
  5819. (save-excursion
  5820. (beginning-of-line)
  5821. (1+ (search-forward org-deadline-string)))))
  5822. org-scheduled-delay-days))
  5823. (t 0))))
  5824. (ddays
  5825. (cond
  5826. ;; Nullify delay when a repeater triggered already
  5827. ;; and the delay is of the form --Xd.
  5828. ((and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5829. (/= schedule last-repeat))
  5830. 0)
  5831. (suppress-delay
  5832. (let ((org-scheduled-delay-days suppress-delay))
  5833. (org-get-wdays s t t)))
  5834. (t (org-get-wdays s t)))))
  5835. ;; Only show a scheduled item in the calendar if it is on or
  5836. ;; past the current date. Skip it if it has been displayed
  5837. ;; for more than `org-scheduled-past-days'.
  5838. (unless (or (and (>= ddays 0) (= diff (- ddays)))
  5839. (and (< (+ diff ddays) 0)
  5840. (< (abs diff) org-scheduled-past-days)
  5841. (and todayp (not org-agenda-only-exact-dates)))
  5842. (and todayp
  5843. habitp
  5844. (bound-and-true-p org-habit-show-all-today)))
  5845. (throw :skip nil))
  5846. ;; Skip done habits, or tasks if
  5847. ;; `org-agenda-skip-deadline-if-done' is non-nil or if it
  5848. ;; was scheduled in the past anyway.
  5849. (when (and donep
  5850. (or org-agenda-skip-scheduled-if-done
  5851. (/= schedule current)
  5852. habitp))
  5853. (throw :skip nil))
  5854. ;; Skip entry if it already appears as a deadline, per
  5855. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5856. ;; doesn't apply to habits.
  5857. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5858. ((guard
  5859. (or (not (assq (line-beginning-position 0) deadline-pos))
  5860. habitp))
  5861. nil)
  5862. (`repeated-after-deadline
  5863. (>= last-repeat
  5864. (time-to-days (org-get-deadline-time (point)))))
  5865. (`not-today pastschedp)
  5866. (`t t)
  5867. (_ nil))
  5868. (throw :skip nil))
  5869. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5870. ;; only show them for today.
  5871. (when (and habitp
  5872. (or (not (bound-and-true-p org-habit-show-habits))
  5873. (and (not todayp)
  5874. (bound-and-true-p
  5875. org-habit-show-habits-only-for-today))))
  5876. (throw :skip nil))
  5877. (save-excursion
  5878. (re-search-backward "^\\*+[ \t]+" nil t)
  5879. (goto-char (match-end 0))
  5880. (let* ((category (org-get-category))
  5881. (inherited-tags
  5882. (or (eq org-agenda-show-inherited-tags 'always)
  5883. (and (listp org-agenda-show-inherited-tags)
  5884. (memq 'agenda org-agenda-show-inherited-tags))
  5885. (and (eq org-agenda-show-inherited-tags t)
  5886. (or (eq org-agenda-use-tag-inheritance t)
  5887. (memq 'agenda
  5888. org-agenda-use-tag-inheritance)))))
  5889. (tags (org-get-tags-at nil (not inherited-tags)))
  5890. (level
  5891. (make-string (org-reduced-level (org-outline-level)) ?\s))
  5892. (head (buffer-substring (point) (line-end-position)))
  5893. (timestr
  5894. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5895. (concat (substring s (match-beginning 1)) " ")
  5896. 'time))
  5897. (item (org-agenda-format-item
  5898. ;; For past scheduled dates, make sure to
  5899. ;; report time difference since SCHEDULE,
  5900. ;; not since closest repeater.
  5901. (let ((diff (if (< (org-today) current) diff
  5902. (- schedule current))))
  5903. (if (= diff 0) (car org-agenda-scheduled-leaders)
  5904. (format (nth 1 org-agenda-scheduled-leaders)
  5905. (- 1 diff))))
  5906. head level category tags
  5907. (and (= diff 0) timestr)
  5908. nil habitp))
  5909. (face (cond ((and (not habitp) pastschedp)
  5910. 'org-scheduled-previously)
  5911. (todayp 'org-scheduled-today)
  5912. (t 'org-scheduled)))
  5913. (habitp (and habitp (org-habit-parse-todo))))
  5914. (org-add-props item props
  5915. 'undone-face face
  5916. 'face (if donep 'org-agenda-done face)
  5917. 'org-marker (org-agenda-new-marker pos)
  5918. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5919. 'type (if pastschedp "past-scheduled" "scheduled")
  5920. 'date (if pastschedp schedule date)
  5921. 'ts-date schedule
  5922. 'warntime warntime
  5923. 'level level
  5924. 'priority (if habitp (org-habit-get-priority habitp)
  5925. (+ 94 (- 5 diff) (org-get-priority item)))
  5926. 'org-habit-p habitp
  5927. 'todo-state todo-state)
  5928. (push item scheduled-items))))))
  5929. (nreverse scheduled-items)))
  5930. (defun org-agenda-get-blocks ()
  5931. "Return the date-range information for agenda display."
  5932. (let* ((props (list 'face nil
  5933. 'org-not-done-regexp org-not-done-regexp
  5934. 'org-todo-regexp org-todo-regexp
  5935. 'org-complex-heading-regexp org-complex-heading-regexp
  5936. 'mouse-face 'highlight
  5937. 'help-echo
  5938. (format "mouse-2 or RET jump to org file %s"
  5939. (abbreviate-file-name buffer-file-name))))
  5940. (regexp org-tr-regexp)
  5941. (d0 (calendar-absolute-from-gregorian date))
  5942. marker hdmarker ee txt d1 d2 s1 s2 category
  5943. level todo-state tags pos head donep inherited-tags)
  5944. (goto-char (point-min))
  5945. (while (re-search-forward regexp nil t)
  5946. (catch :skip
  5947. (org-agenda-skip)
  5948. (setq pos (point))
  5949. (let ((start-time (match-string 1))
  5950. (end-time (match-string 2)))
  5951. (setq s1 (match-string 1)
  5952. s2 (match-string 2)
  5953. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5954. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5955. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5956. ;; Only allow days between the limits, because the normal
  5957. ;; date stamps will catch the limits.
  5958. (save-excursion
  5959. (setq todo-state (org-get-todo-state))
  5960. (setq donep (member todo-state org-done-keywords))
  5961. (if (and donep org-agenda-skip-timestamp-if-done)
  5962. (throw :skip t))
  5963. (setq marker (org-agenda-new-marker (point))
  5964. category (org-get-category))
  5965. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5966. (throw :skip nil)
  5967. (goto-char (match-beginning 0))
  5968. (setq hdmarker (org-agenda-new-marker (point))
  5969. inherited-tags
  5970. (or (eq org-agenda-show-inherited-tags 'always)
  5971. (and (listp org-agenda-show-inherited-tags)
  5972. (memq 'agenda org-agenda-show-inherited-tags))
  5973. (and (eq org-agenda-show-inherited-tags t)
  5974. (or (eq org-agenda-use-tag-inheritance t)
  5975. (memq 'agenda org-agenda-use-tag-inheritance))))
  5976. tags (org-get-tags-at nil (not inherited-tags)))
  5977. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5978. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5979. (setq head (match-string 1))
  5980. (let ((remove-re
  5981. (if org-agenda-remove-timeranges-from-blocks
  5982. (concat
  5983. "<" (regexp-quote s1) ".*?>"
  5984. "--"
  5985. "<" (regexp-quote s2) ".*?>")
  5986. nil)))
  5987. (setq txt (org-agenda-format-item
  5988. (format
  5989. (nth (if (= d1 d2) 0 1)
  5990. org-agenda-timerange-leaders)
  5991. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5992. head level category tags
  5993. (cond ((and (= d1 d0) (= d2 d0))
  5994. (concat "<" start-time ">--<" end-time ">"))
  5995. ((= d1 d0)
  5996. (concat "<" start-time ">"))
  5997. ((= d2 d0)
  5998. (concat "<" end-time ">")))
  5999. remove-re))))
  6000. (org-add-props txt props
  6001. 'org-marker marker 'org-hd-marker hdmarker
  6002. 'type "block" 'date date
  6003. 'level level
  6004. 'todo-state todo-state
  6005. 'priority (org-get-priority txt))
  6006. (push txt ee))))
  6007. (goto-char pos)))
  6008. ;; Sort the entries by expiration date.
  6009. (nreverse ee)))
  6010. ;;; Agenda presentation and sorting
  6011. (defvar org-prefix-has-time nil
  6012. "A flag, set by `org-compile-prefix-format'.
  6013. The flag is set if the currently compiled format contains a `%t'.")
  6014. (defvar org-prefix-has-tag nil
  6015. "A flag, set by `org-compile-prefix-format'.
  6016. The flag is set if the currently compiled format contains a `%T'.")
  6017. (defvar org-prefix-has-effort nil
  6018. "A flag, set by `org-compile-prefix-format'.
  6019. The flag is set if the currently compiled format contains a `%e'.")
  6020. (defvar org-prefix-has-breadcrumbs nil
  6021. "A flag, set by `org-compile-prefix-format'.
  6022. The flag is set if the currently compiled format contains a `%b'.")
  6023. (defvar org-prefix-category-length nil
  6024. "Used by `org-compile-prefix-format' to remember the category field width.")
  6025. (defvar org-prefix-category-max-length nil
  6026. "Used by `org-compile-prefix-format' to remember the category field width.")
  6027. (defun org-agenda-get-category-icon (category)
  6028. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6029. (dolist (entry org-agenda-category-icon-alist)
  6030. (when (org-string-match-p (car entry) category)
  6031. (if (listp (cadr entry))
  6032. (return (cadr entry))
  6033. (return (apply 'create-image (cdr entry)))))))
  6034. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  6035. remove-re habitp)
  6036. "Format TXT to be inserted into the agenda buffer.
  6037. In particular, add the prefix and corresponding text properties.
  6038. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6039. LEVEL may be a string to replace the `%l' specifier.
  6040. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6041. category taken from local variable or file name. It will replace the `%c'
  6042. specifier in the format.
  6043. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6044. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6045. When DOTIME is a string, this string is searched for a time before TXT is.
  6046. TAGS can be the tags of the headline.
  6047. Any match of REMOVE-RE will be removed from TXT."
  6048. ;; We keep the org-prefix-* variable values along with a compiled
  6049. ;; formatter, so that multiple agendas existing at the same time do
  6050. ;; not step on each other toes.
  6051. ;;
  6052. ;; It was inconvenient to make these variables buffer local in
  6053. ;; Agenda buffers, because this function expects to be called with
  6054. ;; the buffer where item comes from being current, and not agenda
  6055. ;; buffer
  6056. (let* ((bindings (car org-prefix-format-compiled))
  6057. (formatter (cadr org-prefix-format-compiled)))
  6058. (loop for (var value) in bindings
  6059. do (set var value))
  6060. (save-match-data
  6061. ;; Diary entries sometimes have extra whitespace at the beginning
  6062. (setq txt (org-trim txt))
  6063. ;; Fix the tags part in txt
  6064. (setq txt (org-agenda-fix-displayed-tags
  6065. txt tags
  6066. org-agenda-show-inherited-tags
  6067. org-agenda-hide-tags-regexp))
  6068. (let* ((category (or category
  6069. (if buffer-file-name
  6070. (file-name-sans-extension
  6071. (file-name-nondirectory buffer-file-name))
  6072. "")))
  6073. (category-icon (org-agenda-get-category-icon category))
  6074. (category-icon (if category-icon
  6075. (propertize " " 'display category-icon)
  6076. ""))
  6077. (effort (and (not (string= txt ""))
  6078. (get-text-property 1 'effort txt)))
  6079. ;; time, tag, effort are needed for the eval of the prefix format
  6080. (tag (if tags (nth (1- (length tags)) tags) ""))
  6081. time
  6082. (ts (if dotime (concat
  6083. (if (stringp dotime) dotime "")
  6084. (and org-agenda-search-headline-for-time txt))))
  6085. (time-of-day (and dotime (org-get-time-of-day ts)))
  6086. stamp plain s0 s1 s2 rtn srp l
  6087. duration breadcrumbs)
  6088. (and (derived-mode-p 'org-mode) buffer-file-name
  6089. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6090. (when (and dotime time-of-day)
  6091. ;; Extract starting and ending time and move them to prefix
  6092. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6093. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6094. (setq s0 (match-string 0 ts)
  6095. srp (and stamp (match-end 3))
  6096. s1 (match-string (if plain 1 2) ts)
  6097. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6098. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6099. ;; them, we might want to remove them there to avoid duplication.
  6100. ;; The user can turn this off with a variable.
  6101. (if (and org-prefix-has-time
  6102. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6103. (string-match (concat (regexp-quote s0) " *") txt)
  6104. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6105. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6106. (= (match-beginning 0) 0)
  6107. t))
  6108. (setq txt (replace-match "" nil nil txt))))
  6109. ;; Normalize the time(s) to 24 hour
  6110. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6111. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6112. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6113. (let (org-time-clocksum-use-effort-durations)
  6114. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6115. (setq s2
  6116. (org-minutes-to-clocksum-string
  6117. (+ (org-hh:mm-string-to-minutes s1)
  6118. org-agenda-default-appointment-duration)))))
  6119. ;; Compute the duration
  6120. (when s2
  6121. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6122. (org-hh:mm-string-to-minutes s1)))))
  6123. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6124. txt)
  6125. ;; Tags are in the string
  6126. (if (or (eq org-agenda-remove-tags t)
  6127. (and org-agenda-remove-tags
  6128. org-prefix-has-tag))
  6129. (setq txt (replace-match "" t t txt))
  6130. (setq txt (replace-match
  6131. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6132. (match-string 2 txt))
  6133. t t txt))))
  6134. (when remove-re
  6135. (while (string-match remove-re txt)
  6136. (setq txt (replace-match "" t t txt))))
  6137. ;; Set org-heading property on `txt' to mark the start of the
  6138. ;; heading.
  6139. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6140. ;; Prepare the variables needed in the eval of the compiled format
  6141. (if org-prefix-has-breadcrumbs
  6142. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6143. (let ((s (org-display-outline-path nil nil "->" t)))
  6144. (if (eq "" s) "" (concat s "->"))))))
  6145. (setq time (cond (s2 (concat
  6146. (org-agenda-time-of-day-to-ampm-maybe s1)
  6147. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6148. (if org-agenda-timegrid-use-ampm " ")))
  6149. (s1 (concat
  6150. (org-agenda-time-of-day-to-ampm-maybe s1)
  6151. (if org-agenda-timegrid-use-ampm
  6152. "........ "
  6153. "......")))
  6154. (t ""))
  6155. extra (or (and (not habitp) extra) "")
  6156. category (if (symbolp category) (symbol-name category) category)
  6157. level (or level ""))
  6158. (if (string-match org-bracket-link-regexp category)
  6159. (progn
  6160. (setq l (if (match-end 3)
  6161. (- (match-end 3) (match-beginning 3))
  6162. (- (match-end 1) (match-beginning 1))))
  6163. (when (< l (or org-prefix-category-length 0))
  6164. (setq category (copy-sequence category))
  6165. (org-add-props category nil
  6166. 'extra-space (make-string
  6167. (- org-prefix-category-length l 1) ?\ ))))
  6168. (if (and org-prefix-category-max-length
  6169. (>= (length category) org-prefix-category-max-length))
  6170. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6171. ;; Evaluate the compiled format
  6172. (setq rtn (concat (eval formatter) txt))
  6173. ;; And finally add the text properties
  6174. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6175. (org-add-props rtn nil
  6176. 'org-category category
  6177. 'tags (mapcar 'org-downcase-keep-props tags)
  6178. 'org-highest-priority org-highest-priority
  6179. 'org-lowest-priority org-lowest-priority
  6180. 'time-of-day time-of-day
  6181. 'duration duration
  6182. 'breadcrumbs breadcrumbs
  6183. 'txt txt
  6184. 'level level
  6185. 'time time
  6186. 'extra extra
  6187. 'format org-prefix-format-compiled
  6188. 'dotime dotime)))))
  6189. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6190. "Remove tags string from TXT, and add a modified list of tags.
  6191. The modified list may contain inherited tags, and tags matched by
  6192. `org-agenda-hide-tags-regexp' will be removed."
  6193. (when (or add-inherited hide-re)
  6194. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6195. (setq txt (substring txt 0 (match-beginning 0))))
  6196. (setq tags
  6197. (delq nil
  6198. (mapcar (lambda (tg)
  6199. (if (or (and hide-re (string-match hide-re tg))
  6200. (and (not add-inherited)
  6201. (get-text-property 0 'inherited tg)))
  6202. nil
  6203. tg))
  6204. tags)))
  6205. (when tags
  6206. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6207. i)
  6208. (setq txt (concat txt " :"
  6209. (mapconcat
  6210. (lambda (x)
  6211. (setq i (get-text-property 0 'inherited x))
  6212. (if (and have-i (not i))
  6213. (progn
  6214. (setq have-i nil)
  6215. (concat ":" x))
  6216. x))
  6217. tags ":")
  6218. (if have-i "::" ":"))))))
  6219. txt)
  6220. (defun org-downcase-keep-props (s)
  6221. (let ((props (text-properties-at 0 s)))
  6222. (setq s (downcase s))
  6223. (add-text-properties 0 (length s) props s)
  6224. s))
  6225. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6226. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6227. "Add a time-grid for agenda items which need it.
  6228. LIST is the list of agenda items formatted by `org-agenda-list'.
  6229. NDAYS is the span of the current agenda view.
  6230. TODAYP is t when the current agenda view is on today."
  6231. (catch 'exit
  6232. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6233. ((and todayp (member 'today (car org-agenda-time-grid))))
  6234. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6235. ((member 'weekly (car org-agenda-time-grid)))
  6236. (t (throw 'exit list)))
  6237. (let* ((have (delq nil (mapcar
  6238. (lambda (x) (get-text-property 1 'time-of-day x))
  6239. list)))
  6240. (string (nth 1 org-agenda-time-grid))
  6241. (gridtimes (nth 2 org-agenda-time-grid))
  6242. (req (car org-agenda-time-grid))
  6243. (remove (member 'remove-match req))
  6244. new time)
  6245. (if (and (member 'require-timed req) (not have))
  6246. ;; don't show empty grid
  6247. (throw 'exit list))
  6248. (while (setq time (pop gridtimes))
  6249. (unless (and remove (member time have))
  6250. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6251. (push (org-agenda-format-item
  6252. nil string nil "" nil
  6253. (concat (substring time 0 -2) ":" (substring time -2)))
  6254. new)
  6255. (put-text-property
  6256. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6257. (when (and todayp org-agenda-show-current-time-in-grid)
  6258. (push (org-agenda-format-item
  6259. nil org-agenda-current-time-string nil "" nil
  6260. (format-time-string "%H:%M "))
  6261. new)
  6262. (put-text-property
  6263. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6264. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6265. (append new list)
  6266. (append list new)))))
  6267. (defun org-compile-prefix-format (key)
  6268. "Compile the prefix format into a Lisp form that can be evaluated.
  6269. The resulting form and associated variable bindings is returned
  6270. and stored in the variable `org-prefix-format-compiled'."
  6271. (setq org-prefix-has-time nil
  6272. org-prefix-has-tag nil
  6273. org-prefix-category-length nil
  6274. org-prefix-has-effort nil
  6275. org-prefix-has-breadcrumbs nil)
  6276. (let ((s (cond
  6277. ((stringp org-agenda-prefix-format)
  6278. org-agenda-prefix-format)
  6279. ((assq key org-agenda-prefix-format)
  6280. (cdr (assq key org-agenda-prefix-format)))
  6281. (t " %-12:c%?-12t% s")))
  6282. (start 0)
  6283. varform vars var e c f opt)
  6284. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6285. s start)
  6286. (setq var (or (cdr (assoc (match-string 4 s)
  6287. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6288. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6289. 'eval)
  6290. c (or (match-string 3 s) "")
  6291. opt (match-beginning 1)
  6292. start (1+ (match-beginning 0)))
  6293. (if (equal var 'time) (setq org-prefix-has-time t))
  6294. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6295. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6296. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6297. (setq f (concat "%" (match-string 2 s) "s"))
  6298. (when (equal var 'category)
  6299. (setq org-prefix-category-length
  6300. (floor (abs (string-to-number (match-string 2 s)))))
  6301. (setq org-prefix-category-max-length
  6302. (let ((x (match-string 2 s)))
  6303. (save-match-data
  6304. (if (string-match "\\.[0-9]+" x)
  6305. (string-to-number (substring (match-string 0 x) 1)))))))
  6306. (if (eq var 'eval)
  6307. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6308. (if opt
  6309. (setq varform
  6310. `(if (or (equal "" ,var) (equal nil ,var))
  6311. ""
  6312. (format ,f (concat ,var ,c))))
  6313. (setq varform
  6314. `(format ,f (if (or (equal ,var "")
  6315. (equal ,var nil)) ""
  6316. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6317. (setq s (replace-match "%s" t nil s))
  6318. (push varform vars))
  6319. (setq vars (nreverse vars))
  6320. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6321. (setq org-prefix-format-compiled
  6322. (list
  6323. `((org-prefix-has-time ,org-prefix-has-time)
  6324. (org-prefix-has-tag ,org-prefix-has-tag)
  6325. (org-prefix-category-length ,org-prefix-category-length)
  6326. (org-prefix-has-effort ,org-prefix-has-effort)
  6327. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6328. `(format ,s ,@vars))))))
  6329. (defun org-set-sorting-strategy (key)
  6330. (if (symbolp (car org-agenda-sorting-strategy))
  6331. ;; the old format
  6332. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6333. (setq org-agenda-sorting-strategy-selected
  6334. (or (cdr (assq key org-agenda-sorting-strategy))
  6335. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6336. '(time-up category-keep priority-down)))))
  6337. (defun org-get-time-of-day (s &optional string mod24)
  6338. "Check string S for a time of day.
  6339. If found, return it as a military time number between 0 and 2400.
  6340. If not found, return nil.
  6341. The optional STRING argument forces conversion into a 5 character wide string
  6342. HH:MM."
  6343. (save-match-data
  6344. (when
  6345. (and
  6346. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6347. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6348. (not (eq (get-text-property 1 'face s) 'org-link)))
  6349. (let* ((h (string-to-number (match-string 1 s)))
  6350. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6351. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6352. (am-p (equal ampm "am"))
  6353. (h1 (cond ((not ampm) h)
  6354. ((= h 12) (if am-p 0 12))
  6355. (t (+ h (if am-p 0 12)))))
  6356. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6357. (mod h1 24) h1))
  6358. (t0 (+ (* 100 h2) m))
  6359. (t1 (concat (if (>= h1 24) "+" " ")
  6360. (if (and org-agenda-time-leading-zero
  6361. (< t0 1000)) "0" "")
  6362. (if (< t0 100) "0" "")
  6363. (if (< t0 10) "0" "")
  6364. (int-to-string t0))))
  6365. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6366. (defvar org-agenda-before-sorting-filter-function nil
  6367. "Function to be applied to agenda items prior to sorting.
  6368. Prior to sorting also means just before they are inserted into the agenda.
  6369. To aid sorting, you may revisit the original entries and add more text
  6370. properties which will later be used by the sorting functions.
  6371. The function should take a string argument, an agenda line.
  6372. It has access to the text properties in that line, which contain among
  6373. other things, the property `org-hd-marker' that points to the entry
  6374. where the line comes from. Note that not all lines going into the agenda
  6375. have this property, only most.
  6376. The function should return the modified string. It is probably best
  6377. to ONLY change text properties.
  6378. You can also use this function as a filter, by returning nil for lines
  6379. you don't want to have in the agenda at all. For this application, you
  6380. could bind the variable in the options section of a custom command.")
  6381. (defun org-agenda-finalize-entries (list &optional type)
  6382. "Sort, limit and concatenate the LIST of agenda items.
  6383. The optional argument TYPE tells the agenda type."
  6384. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6385. (cdr (assoc type org-agenda-max-effort)))
  6386. (t org-agenda-max-effort)))
  6387. (max-todo (cond ((listp org-agenda-max-todos)
  6388. (cdr (assoc type org-agenda-max-todos)))
  6389. (t org-agenda-max-todos)))
  6390. (max-tags (cond ((listp org-agenda-max-tags)
  6391. (cdr (assoc type org-agenda-max-tags)))
  6392. (t org-agenda-max-tags)))
  6393. (max-entries (cond ((listp org-agenda-max-entries)
  6394. (cdr (assoc type org-agenda-max-entries)))
  6395. (t org-agenda-max-entries))))
  6396. (when org-agenda-before-sorting-filter-function
  6397. (setq list
  6398. (delq nil
  6399. (mapcar
  6400. org-agenda-before-sorting-filter-function list))))
  6401. (setq list (mapcar 'org-agenda-highlight-todo list)
  6402. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6403. (when max-effort
  6404. (setq list (org-agenda-limit-entries
  6405. list 'effort-minutes max-effort
  6406. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6407. 32767 -1))))))
  6408. (when max-todo
  6409. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6410. (when max-tags
  6411. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6412. (when max-entries
  6413. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6414. (mapconcat 'identity list "\n")))
  6415. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6416. "Limit the number of agenda entries."
  6417. (let ((include (and limit (< limit 0))))
  6418. (if limit
  6419. (let ((fun (or fn (lambda (p) (if p 1))))
  6420. (lim 0))
  6421. (delq nil
  6422. (mapcar
  6423. (lambda (e)
  6424. (let ((pval (funcall
  6425. fun (get-text-property (1- (length e))
  6426. prop e))))
  6427. (if pval (setq lim (+ lim pval)))
  6428. (cond ((and pval (<= lim (abs limit))) e)
  6429. ((and include (not pval)) e))))
  6430. list)))
  6431. list)))
  6432. (defun org-agenda-limit-interactively (remove)
  6433. "In agenda, interactively limit entries to various maximums."
  6434. (interactive "P")
  6435. (if remove
  6436. (progn (setq org-agenda-max-entries nil
  6437. org-agenda-max-todos nil
  6438. org-agenda-max-tags nil
  6439. org-agenda-max-effort nil)
  6440. (org-agenda-redo))
  6441. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6442. (msg (cond ((= max ?E) "How many minutes? ")
  6443. ((= max ?e) "How many entries? ")
  6444. ((= max ?t) "How many TODO entries? ")
  6445. ((= max ?T) "How many tagged entries? ")
  6446. (t (user-error "Wrong input"))))
  6447. (num (string-to-number (read-from-minibuffer msg))))
  6448. (cond ((equal max ?e)
  6449. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6450. ((equal max ?t)
  6451. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6452. ((equal max ?T)
  6453. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6454. ((equal max ?E)
  6455. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6456. (org-agenda-fit-window-to-buffer))
  6457. (defun org-agenda-highlight-todo (x)
  6458. (let ((org-done-keywords org-done-keywords-for-agenda)
  6459. (case-fold-search nil)
  6460. re)
  6461. (if (eq x 'line)
  6462. (save-excursion
  6463. (beginning-of-line 1)
  6464. (setq re (org-get-at-bol 'org-todo-regexp))
  6465. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6466. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6467. (add-text-properties (match-beginning 0) (match-end 1)
  6468. (list 'face (org-get-todo-face 1)))
  6469. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6470. (delete-region (match-beginning 1) (1- (match-end 0)))
  6471. (goto-char (match-beginning 1))
  6472. (insert (format org-agenda-todo-keyword-format s)))))
  6473. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6474. (setq re (get-text-property 0 'org-todo-regexp x))
  6475. (when (and re
  6476. ;; Test `pl' because if there's no heading content,
  6477. ;; there's no point matching to highlight. Note
  6478. ;; that if we didn't test `pl' first, and there
  6479. ;; happened to be no keyword from `org-todo-regexp'
  6480. ;; on this heading line, then the `equal' comparison
  6481. ;; afterwards would spuriously succeed in the case
  6482. ;; where `pl' is nil -- causing an args-out-of-range
  6483. ;; error when we try to add text properties to text
  6484. ;; that isn't there.
  6485. pl
  6486. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6487. x pl) pl))
  6488. (add-text-properties
  6489. (or (match-end 1) (match-end 0)) (match-end 0)
  6490. (list 'face (org-get-todo-face (match-string 2 x)))
  6491. x)
  6492. (when (match-end 1)
  6493. (setq x (concat (substring x 0 (match-end 1))
  6494. (format org-agenda-todo-keyword-format
  6495. (match-string 2 x))
  6496. (org-add-props " " (text-properties-at 0 x))
  6497. (substring x (match-end 3)))))))
  6498. x)))
  6499. (defsubst org-cmp-values (a b property)
  6500. "Compare the numeric value of text PROPERTY for string A and B."
  6501. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6502. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6503. (cond ((> pa pb) +1)
  6504. ((< pa pb) -1))))
  6505. (defsubst org-cmp-effort (a b)
  6506. "Compare the effort values of string A and B."
  6507. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6508. (ea (or (get-text-property (1- (length a)) 'effort-minutes a) def))
  6509. (eb (or (get-text-property (1- (length b)) 'effort-minutes b) def)))
  6510. (cond ((> ea eb) +1)
  6511. ((< ea eb) -1))))
  6512. (defsubst org-cmp-category (a b)
  6513. "Compare the string values of categories of strings A and B."
  6514. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6515. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6516. (cond ((string-lessp ca cb) -1)
  6517. ((string-lessp cb ca) +1))))
  6518. (defsubst org-cmp-todo-state (a b)
  6519. "Compare the todo states of strings A and B."
  6520. (let* ((ma (or (get-text-property 1 'org-marker a)
  6521. (get-text-property 1 'org-hd-marker a)))
  6522. (mb (or (get-text-property 1 'org-marker b)
  6523. (get-text-property 1 'org-hd-marker b)))
  6524. (fa (and ma (marker-buffer ma)))
  6525. (fb (and mb (marker-buffer mb)))
  6526. (todo-kwds
  6527. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6528. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6529. (ta (or (get-text-property 1 'todo-state a) ""))
  6530. (tb (or (get-text-property 1 'todo-state b) ""))
  6531. (la (- (length (member ta todo-kwds))))
  6532. (lb (- (length (member tb todo-kwds))))
  6533. (donepa (member ta org-done-keywords-for-agenda))
  6534. (donepb (member tb org-done-keywords-for-agenda)))
  6535. (cond ((and donepa (not donepb)) -1)
  6536. ((and (not donepa) donepb) +1)
  6537. ((< la lb) -1)
  6538. ((< lb la) +1))))
  6539. (defsubst org-cmp-alpha (a b)
  6540. "Compare the headlines, alphabetically."
  6541. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6542. (plb (text-property-any 0 (length b) 'org-heading t b))
  6543. (ta (and pla (substring a pla)))
  6544. (tb (and plb (substring b plb))))
  6545. (when pla
  6546. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6547. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6548. (setq ta (substring ta (match-end 0))))
  6549. (setq ta (downcase ta)))
  6550. (when plb
  6551. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6552. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6553. (setq tb (substring tb (match-end 0))))
  6554. (setq tb (downcase tb)))
  6555. (cond ((not ta) +1)
  6556. ((not tb) -1)
  6557. ((string-lessp ta tb) -1)
  6558. ((string-lessp tb ta) +1))))
  6559. (defsubst org-cmp-tag (a b)
  6560. "Compare the string values of the first tags of A and B."
  6561. (let ((ta (car (last (get-text-property 1 'tags a))))
  6562. (tb (car (last (get-text-property 1 'tags b)))))
  6563. (cond ((not ta) +1)
  6564. ((not tb) -1)
  6565. ((string-lessp ta tb) -1)
  6566. ((string-lessp tb ta) +1))))
  6567. (defsubst org-cmp-time (a b)
  6568. "Compare the time-of-day values of strings A and B."
  6569. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6570. (ta (or (get-text-property 1 'time-of-day a) def))
  6571. (tb (or (get-text-property 1 'time-of-day b) def)))
  6572. (cond ((< ta tb) -1)
  6573. ((< tb ta) +1))))
  6574. (defsubst org-cmp-ts (a b type)
  6575. "Compare the timestamps values of entries A and B.
  6576. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6577. \"timestamp_ia\", compare within each of these type. When TYPE
  6578. is the empty string, compare all timestamps without respect of
  6579. their type."
  6580. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6581. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6582. (get-text-property 1 'ts-date a))
  6583. def))
  6584. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6585. (get-text-property 1 'ts-date b))
  6586. def)))
  6587. (cond ((< ta tb) -1)
  6588. ((< tb ta) +1))))
  6589. (defsubst org-cmp-habit-p (a b)
  6590. "Compare the todo states of strings A and B."
  6591. (let ((ha (get-text-property 1 'org-habit-p a))
  6592. (hb (get-text-property 1 'org-habit-p b)))
  6593. (cond ((and ha (not hb)) -1)
  6594. ((and (not ha) hb) +1))))
  6595. (defun org-entries-lessp (a b)
  6596. "Predicate for sorting agenda entries."
  6597. ;; The following variables will be used when the form is evaluated.
  6598. ;; So even though the compiler complains, keep them.
  6599. (let* ((ss org-agenda-sorting-strategy-selected)
  6600. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6601. (org-cmp-ts a b "")))
  6602. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6603. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6604. (org-cmp-ts a b "scheduled")))
  6605. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6606. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6607. (org-cmp-ts a b "deadline")))
  6608. (deadline-down (if deadline-up (- deadline-up) nil))
  6609. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6610. (org-cmp-ts a b "timestamp_ia")))
  6611. (tsia-down (if tsia-up (- tsia-up) nil))
  6612. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6613. (org-cmp-ts a b "timestamp")))
  6614. (ts-down (if ts-up (- ts-up) nil))
  6615. (time-up (and (org-em 'time-up 'time-down ss)
  6616. (org-cmp-time a b)))
  6617. (time-down (if time-up (- time-up) nil))
  6618. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6619. (org-cmp-values a b 'org-stats)))
  6620. (stats-down (if stats-up (- stats-up) nil))
  6621. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6622. (org-cmp-values a b 'priority)))
  6623. (priority-down (if priority-up (- priority-up) nil))
  6624. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6625. (org-cmp-effort a b)))
  6626. (effort-down (if effort-up (- effort-up) nil))
  6627. (category-up (and (or (org-em 'category-up 'category-down ss)
  6628. (memq 'category-keep ss))
  6629. (org-cmp-category a b)))
  6630. (category-down (if category-up (- category-up) nil))
  6631. (category-keep (if category-up +1 nil))
  6632. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6633. (org-cmp-tag a b)))
  6634. (tag-down (if tag-up (- tag-up) nil))
  6635. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6636. (org-cmp-todo-state a b)))
  6637. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6638. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6639. (org-cmp-habit-p a b)))
  6640. (habit-down (if habit-up (- habit-up) nil))
  6641. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6642. (org-cmp-alpha a b)))
  6643. (alpha-down (if alpha-up (- alpha-up) nil))
  6644. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6645. user-defined-up user-defined-down)
  6646. (if (and need-user-cmp org-agenda-cmp-user-defined
  6647. (functionp org-agenda-cmp-user-defined))
  6648. (setq user-defined-up
  6649. (funcall org-agenda-cmp-user-defined a b)
  6650. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6651. (cdr (assoc
  6652. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6653. '((-1 . t) (1 . nil) (nil . nil))))))
  6654. ;;; Agenda restriction lock
  6655. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6656. "Overlay to mark the headline to which agenda commands are restricted.")
  6657. (overlay-put org-agenda-restriction-lock-overlay
  6658. 'face 'org-agenda-restriction-lock)
  6659. (overlay-put org-agenda-restriction-lock-overlay
  6660. 'help-echo "Agendas are currently limited to this subtree.")
  6661. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6662. ;;;###autoload
  6663. (defun org-agenda-set-restriction-lock (&optional type)
  6664. "Set restriction lock for agenda, to current subtree or file.
  6665. Restriction will be the file if TYPE is `file', or if type is the
  6666. universal prefix \\='(4), or if the cursor is before the first headline
  6667. in the file. Otherwise, restriction will be to the current subtree."
  6668. (interactive "P")
  6669. (org-agenda-remove-restriction-lock 'noupdate)
  6670. (and (equal type '(4)) (setq type 'file))
  6671. (setq type (cond
  6672. (type type)
  6673. ((org-at-heading-p) 'subtree)
  6674. ((condition-case nil (org-back-to-heading t) (error nil))
  6675. 'subtree)
  6676. (t 'file)))
  6677. (if (eq type 'subtree)
  6678. (progn
  6679. (setq org-agenda-restrict (current-buffer))
  6680. (setq org-agenda-overriding-restriction 'subtree)
  6681. (put 'org-agenda-files 'org-restrict
  6682. (list (buffer-file-name (buffer-base-buffer))))
  6683. (org-back-to-heading t)
  6684. (move-overlay org-agenda-restriction-lock-overlay
  6685. (point)
  6686. (if org-agenda-restriction-lock-highlight-subtree
  6687. (save-excursion (org-end-of-subtree t t) (point))
  6688. (point-at-eol)))
  6689. (move-marker org-agenda-restrict-begin (point))
  6690. (move-marker org-agenda-restrict-end
  6691. (save-excursion (org-end-of-subtree t t)))
  6692. (message "Locking agenda restriction to subtree"))
  6693. (put 'org-agenda-files 'org-restrict
  6694. (list (buffer-file-name (buffer-base-buffer))))
  6695. (setq org-agenda-restrict nil)
  6696. (setq org-agenda-overriding-restriction 'file)
  6697. (move-marker org-agenda-restrict-begin nil)
  6698. (move-marker org-agenda-restrict-end nil)
  6699. (message "Locking agenda restriction to file"))
  6700. (setq current-prefix-arg nil)
  6701. (org-agenda-maybe-redo))
  6702. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6703. "Remove the agenda restriction lock."
  6704. (interactive "P")
  6705. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6706. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6707. (setq org-agenda-overriding-restriction nil)
  6708. (setq org-agenda-restrict nil)
  6709. (put 'org-agenda-files 'org-restrict nil)
  6710. (move-marker org-agenda-restrict-begin nil)
  6711. (move-marker org-agenda-restrict-end nil)
  6712. (setq current-prefix-arg nil)
  6713. (message "Agenda restriction lock removed")
  6714. (or noupdate (org-agenda-maybe-redo)))
  6715. (defun org-agenda-maybe-redo ()
  6716. "If there is any window showing the agenda view, update it."
  6717. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6718. org-agenda-buffer-name)
  6719. t))
  6720. (w0 (selected-window)))
  6721. (when w
  6722. (select-window w)
  6723. (org-agenda-redo)
  6724. (select-window w0)
  6725. (if org-agenda-overriding-restriction
  6726. (message "Agenda view shifted to new %s restriction"
  6727. org-agenda-overriding-restriction)
  6728. (message "Agenda restriction lock removed")))))
  6729. ;;; Agenda commands
  6730. (defun org-agenda-check-type (error &rest types)
  6731. "Check if agenda buffer is of allowed type.
  6732. If ERROR is non-nil, throw an error, otherwise just return nil.
  6733. Allowed types are `agenda' `timeline' `todo' `tags' `search'."
  6734. (if (not org-agenda-type)
  6735. (error "No Org agenda currently displayed")
  6736. (if (memq org-agenda-type types)
  6737. t
  6738. (if error
  6739. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6740. nil))))
  6741. (defun org-agenda-Quit ()
  6742. "Exit the agenda, killing the agenda buffer.
  6743. Like `org-agenda-quit', but kill the buffer even when
  6744. `org-agenda-sticky' is non-nil."
  6745. (interactive)
  6746. (org-agenda--quit))
  6747. (defun org-agenda-quit ()
  6748. "Exit the agenda.
  6749. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6750. instead of killing it.
  6751. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6752. the pre-agenda window configuration.
  6753. When column view is active, exit column view instead of the
  6754. agenda."
  6755. (interactive)
  6756. (org-agenda--quit org-agenda-sticky))
  6757. (defun org-agenda--quit (&optional bury)
  6758. (if org-agenda-columns-active
  6759. (org-columns-quit)
  6760. (let ((wconf org-agenda-pre-window-conf)
  6761. (buf (current-buffer))
  6762. (org-agenda-last-indirect-window
  6763. (and (eq org-indirect-buffer-display 'other-window)
  6764. org-agenda-last-indirect-buffer
  6765. (get-buffer-window org-agenda-last-indirect-buffer))))
  6766. (cond
  6767. ((eq org-agenda-window-setup 'other-frame)
  6768. (delete-frame))
  6769. ((and org-agenda-restore-windows-after-quit
  6770. wconf)
  6771. ;; Maybe restore the pre-agenda window configuration. Reset
  6772. ;; `org-agenda-pre-window-conf' before running
  6773. ;; `set-window-configuration', which loses the current buffer.
  6774. (setq org-agenda-pre-window-conf nil)
  6775. (set-window-configuration wconf))
  6776. (t
  6777. (when org-agenda-last-indirect-window
  6778. (delete-window org-agenda-last-indirect-window))
  6779. (and (not (eq org-agenda-window-setup 'current-window))
  6780. (not (one-window-p))
  6781. (delete-window))))
  6782. (if bury
  6783. ;; Set the agenda buffer as the current buffer instead of
  6784. ;; passing it as an argument to `bury-buffer' so that
  6785. ;; `bury-buffer' removes it from the window.
  6786. (with-current-buffer buf
  6787. (bury-buffer))
  6788. (kill-buffer buf)
  6789. (setq org-agenda-archives-mode nil
  6790. org-agenda-buffer nil)))))
  6791. (defun org-agenda-exit ()
  6792. "Exit the agenda, killing Org buffers loaded by the agenda.
  6793. Like `org-agenda-Quit', but kill any buffers that were created by
  6794. the agenda. Org buffers visited directly by the user will not be
  6795. touched. Also, exit the agenda even if it is in column view."
  6796. (interactive)
  6797. (when org-agenda-columns-active
  6798. (org-columns-quit))
  6799. (org-release-buffers org-agenda-new-buffers)
  6800. (setq org-agenda-new-buffers nil)
  6801. (org-agenda-Quit))
  6802. (defun org-agenda-kill-all-agenda-buffers ()
  6803. "Kill all buffers in `org-agenda-mode'.
  6804. This is used when toggling sticky agendas."
  6805. (interactive)
  6806. (let (blist)
  6807. (dolist (buf (buffer-list))
  6808. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6809. (push buf blist)))
  6810. (mapc 'kill-buffer blist)))
  6811. (defun org-agenda-execute (arg)
  6812. "Execute another agenda command, keeping same window.
  6813. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6814. in the agenda."
  6815. (interactive "P")
  6816. (let ((org-agenda-window-setup 'current-window))
  6817. (org-agenda arg)))
  6818. (defun org-agenda-redo (&optional all)
  6819. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6820. (interactive "P")
  6821. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6822. (cpa (unless (eq all t) current-prefix-arg))
  6823. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6824. (org-agenda-sticky nil)
  6825. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6826. org-agenda-buffer-name))
  6827. (org-agenda-keep-modes t)
  6828. (tag-filter org-agenda-tag-filter)
  6829. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6830. (top-hl-filter org-agenda-top-headline-filter)
  6831. (cat-filter org-agenda-category-filter)
  6832. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6833. (re-filter org-agenda-regexp-filter)
  6834. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6835. (effort-filter org-agenda-effort-filter)
  6836. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6837. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6838. (cols org-agenda-columns-active)
  6839. (line (org-current-line))
  6840. (window-line (- line (org-current-line (window-start))))
  6841. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6842. (redo-cmd (get-text-property p 'org-redo-cmd))
  6843. (last-args (get-text-property p 'org-last-args))
  6844. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6845. (org-agenda-overriding-cmd-arguments
  6846. (unless (eq all t)
  6847. (cond ((listp last-args)
  6848. (cons (or cpa (car last-args)) (cdr last-args)))
  6849. ((stringp last-args)
  6850. last-args))))
  6851. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6852. (put 'org-agenda-tag-filter :preset-filter nil)
  6853. (put 'org-agenda-category-filter :preset-filter nil)
  6854. (put 'org-agenda-regexp-filter :preset-filter nil)
  6855. (put 'org-agenda-effort-filter :preset-filter nil)
  6856. (and cols (org-columns-quit))
  6857. (message "Rebuilding agenda buffer...")
  6858. (if series-redo-cmd
  6859. (eval series-redo-cmd)
  6860. (org-let lprops redo-cmd))
  6861. (setq org-agenda-undo-list nil
  6862. org-agenda-pending-undo-list nil
  6863. org-agenda-tag-filter tag-filter
  6864. org-agenda-category-filter cat-filter
  6865. org-agenda-regexp-filter re-filter
  6866. org-agenda-effort-filter effort-filter
  6867. org-agenda-top-headline-filter top-hl-filter)
  6868. (message "Rebuilding agenda buffer...done")
  6869. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6870. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6871. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6872. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6873. (let ((tag (or tag-filter tag-preset))
  6874. (cat (or cat-filter cat-preset))
  6875. (effort (or effort-filter effort-preset))
  6876. (re (or re-filter re-preset)))
  6877. (when tag (org-agenda-filter-apply tag 'tag t))
  6878. (when cat (org-agenda-filter-apply cat 'category))
  6879. (when effort (org-agenda-filter-apply effort 'effort))
  6880. (when re (org-agenda-filter-apply re 'regexp)))
  6881. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6882. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6883. (org-goto-line line)
  6884. (recenter window-line)))
  6885. (defvar org-global-tags-completion-table nil)
  6886. (defvar org-agenda-filter-form nil)
  6887. (defvar org-agenda-filtered-by-category nil)
  6888. (defun org-agenda-filter-by-category (strip)
  6889. "Filter lines in the agenda buffer that have a specific category.
  6890. The category is that of the current line.
  6891. Without prefix argument, keep only the lines of that category.
  6892. With a prefix argument, exclude the lines of that category.
  6893. "
  6894. (interactive "P")
  6895. (if (and org-agenda-filtered-by-category
  6896. org-agenda-category-filter)
  6897. (org-agenda-filter-show-all-cat)
  6898. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6899. (cond
  6900. ((and cat strip)
  6901. (org-agenda-filter-apply
  6902. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6903. (cat
  6904. (org-agenda-filter-apply
  6905. (setq org-agenda-category-filter
  6906. (list (concat "+" cat))) 'category))
  6907. (t (error "No category at point"))))))
  6908. (defun org-find-top-headline (&optional pos)
  6909. "Find the topmost parent headline and return it."
  6910. (save-excursion
  6911. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6912. (if pos (goto-char pos))
  6913. ;; Skip up to the topmost parent
  6914. (while (ignore-errors (outline-up-heading 1) t))
  6915. (ignore-errors
  6916. (nth 4 (org-heading-components))))))
  6917. (defvar org-agenda-filtered-by-top-headline nil)
  6918. (defun org-agenda-filter-by-top-headline (strip)
  6919. "Keep only those lines that are descendants from the same top headline.
  6920. The top headline is that of the current line."
  6921. (interactive "P")
  6922. (if org-agenda-filtered-by-top-headline
  6923. (progn
  6924. (setq org-agenda-filtered-by-top-headline nil
  6925. org-agenda-top-headline-filter nil)
  6926. (org-agenda-filter-show-all-top-filter))
  6927. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6928. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6929. (error "No top-level headline at point")))))
  6930. (defvar org-agenda-regexp-filter nil)
  6931. (defun org-agenda-filter-by-regexp (strip)
  6932. "Filter agenda entries by a regular expression.
  6933. Regexp filters are cumulative.
  6934. With no prefix argument, keep entries matching the regexp.
  6935. With one prefix argument, filter out entries matching the regexp.
  6936. With two prefix arguments, remove the regexp filters."
  6937. (interactive "P")
  6938. (if (not (equal strip '(16)))
  6939. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6940. (read-from-minibuffer
  6941. (if (equal strip '(4))
  6942. "Filter out entries matching regexp: "
  6943. "Narrow to entries matching regexp: ")))))
  6944. (push flt org-agenda-regexp-filter)
  6945. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6946. (org-agenda-filter-show-all-re)
  6947. (message "Regexp filter removed")))
  6948. (defvar org-agenda-effort-filter nil)
  6949. (defun org-agenda-filter-by-effort (strip)
  6950. "Filter agenda entries by effort.
  6951. With no prefix argument, keep entries matching the effort condition.
  6952. With one prefix argument, filter out entries matching the condition.
  6953. With two prefix arguments, remove the effort filters."
  6954. (interactive "P")
  6955. (cond ((member strip '(nil 4))
  6956. (let ((efforts (org-split-string
  6957. (or (cdr (assoc (concat org-effort-property "_ALL")
  6958. org-global-properties))
  6959. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6960. "")))
  6961. (eff -1)
  6962. effort-prompt op)
  6963. (while (not (member op '(?< ?> ?=)))
  6964. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6965. (loop for i from 0 to 9 do
  6966. (setq effort-prompt
  6967. (concat
  6968. effort-prompt " ["
  6969. (if (= i 9) "0" (int-to-string (1+ i)))
  6970. "]" (nth i efforts))))
  6971. (message "Effort %s%s" (char-to-string op) effort-prompt)
  6972. (while (or (< eff 0) (> eff 9))
  6973. (setq eff (string-to-number (char-to-string (read-char-exclusive)))))
  6974. (setq org-agenda-effort-filter
  6975. (list (concat (if strip "-" "+")
  6976. (char-to-string op) (nth (1- eff) efforts))))
  6977. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6978. (t (org-agenda-filter-show-all-effort)
  6979. (message "Effort filter removed"))))
  6980. (defun org-agenda-filter-remove-all ()
  6981. "Remove all filters from the current agenda buffer."
  6982. (interactive)
  6983. (when org-agenda-tag-filter
  6984. (org-agenda-filter-show-all-tag))
  6985. (when org-agenda-category-filter
  6986. (org-agenda-filter-show-all-cat))
  6987. (when org-agenda-regexp-filter
  6988. (org-agenda-filter-show-all-re))
  6989. (when org-agenda-top-headline-filter
  6990. (org-agenda-filter-show-all-top-filter))
  6991. (when org-agenda-effort-filter
  6992. (org-agenda-filter-show-all-effort))
  6993. (org-agenda-finalize))
  6994. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  6995. "Keep only those lines in the agenda buffer that have a specific tag.
  6996. The tag is selected with its fast selection letter, as
  6997. configured. With a single \\[universal-argument] prefix ARG,
  6998. exclude the agenda search. With a double \\[universal-argument]
  6999. prefix ARG, filter the literal tag. I.e. don't filter on all its
  7000. group members.
  7001. A lisp caller can specify CHAR. EXCLUDE means that the new tag should be
  7002. used to exclude the search - the interactive user can also press `-' or `+'
  7003. to switch between filtering and excluding."
  7004. (interactive "P")
  7005. (let* ((alist org-tag-alist-for-agenda)
  7006. (tag-chars (mapconcat
  7007. (lambda (x) (if (and (not (symbolp (car x)))
  7008. (cdr x))
  7009. (char-to-string (cdr x))
  7010. ""))
  7011. org-tag-alist-for-agenda ""))
  7012. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  7013. (string-to-list tag-chars)))
  7014. (exclude (or exclude (equal arg '(4))))
  7015. (expand (not (equal arg '(16))))
  7016. (inhibit-read-only t)
  7017. (current org-agenda-tag-filter)
  7018. a n tag)
  7019. (unless char
  7020. (while (not (memq char valid-char-list))
  7021. (message
  7022. "%s by tag [%s ], [TAB], %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  7023. (if exclude "Exclude" "Filter") tag-chars
  7024. (if org-agenda-auto-exclude-function "[RET], " "")
  7025. (if expand "" ", no grouptag expand"))
  7026. (setq char (read-char-exclusive))
  7027. ;; Excluding or filtering down
  7028. (cond ((eq char ?-) (setq exclude t))
  7029. ((eq char ?+) (setq exclude nil)))))
  7030. (when (eq char ?\t)
  7031. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  7032. (setq-local org-global-tags-completion-table
  7033. (org-global-tags-completion-table)))
  7034. (let ((completion-ignore-case t))
  7035. (setq tag (completing-read
  7036. "Tag: " org-global-tags-completion-table))))
  7037. (cond
  7038. ((eq char ?\r)
  7039. (org-agenda-filter-show-all-tag)
  7040. (when org-agenda-auto-exclude-function
  7041. (setq org-agenda-tag-filter nil)
  7042. (dolist (tag (org-agenda-get-represented-tags))
  7043. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7044. (if modifier
  7045. (push modifier org-agenda-tag-filter))))
  7046. (if (not (null org-agenda-tag-filter))
  7047. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7048. ((eq char ?/)
  7049. (org-agenda-filter-show-all-tag)
  7050. (when (get 'org-agenda-tag-filter :preset-filter)
  7051. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7052. ((eq char ?.)
  7053. (setq org-agenda-tag-filter
  7054. (mapcar (lambda(tag) (concat "+" tag))
  7055. (org-get-at-bol 'tags)))
  7056. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7057. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7058. ((or (eq char ?\s)
  7059. (setq a (rassoc char alist))
  7060. (and tag (setq a (cons tag nil))))
  7061. (org-agenda-filter-show-all-tag)
  7062. (setq tag (car a))
  7063. (setq org-agenda-tag-filter
  7064. (cons (concat (if exclude "-" "+") tag)
  7065. current))
  7066. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7067. (t (error "Invalid tag selection character %c" char)))))
  7068. (defun org-agenda-get-represented-tags ()
  7069. "Get a list of all tags currently represented in the agenda."
  7070. (let (p tags)
  7071. (save-excursion
  7072. (goto-char (point-min))
  7073. (while (setq p (next-single-property-change (point) 'tags))
  7074. (goto-char p)
  7075. (mapc (lambda (x) (add-to-list 'tags x))
  7076. (get-text-property (point) 'tags))))
  7077. tags))
  7078. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7079. "Create the form that tests a line for agenda filter. Optional
  7080. argument EXPAND can be used for the TYPE tag and will expand the
  7081. tags in the FILTER if any of the tags in FILTER are grouptags."
  7082. (let (f f1)
  7083. (cond
  7084. ;; Tag filter
  7085. ((eq type 'tag)
  7086. (setq filter
  7087. (delete-dups
  7088. (append (get 'org-agenda-tag-filter :preset-filter)
  7089. filter)))
  7090. (dolist (x filter)
  7091. (let ((op (string-to-char x)))
  7092. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7093. (setq x (list x)))
  7094. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7095. (push f1 f))))
  7096. ;; Category filter
  7097. ((eq type 'category)
  7098. (setq filter
  7099. (delete-dups
  7100. (append (get 'org-agenda-category-filter :preset-filter)
  7101. filter)))
  7102. (dolist (x filter)
  7103. (if (equal "-" (substring x 0 1))
  7104. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7105. (setq f1 (list 'equal (substring x 1) 'cat)))
  7106. (push f1 f)))
  7107. ;; Regexp filter
  7108. ((eq type 'regexp)
  7109. (setq filter
  7110. (delete-dups
  7111. (append (get 'org-agenda-regexp-filter :preset-filter)
  7112. filter)))
  7113. (dolist (x filter)
  7114. (if (equal "-" (substring x 0 1))
  7115. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7116. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7117. (push f1 f)))
  7118. ;; Effort filter
  7119. ((eq type 'effort)
  7120. (setq filter
  7121. (delete-dups
  7122. (append (get 'org-agenda-effort-filter :preset-filter)
  7123. filter)))
  7124. (dolist (x filter)
  7125. (push (org-agenda-filter-effort-form x) f))))
  7126. (cons 'and (nreverse f))))
  7127. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7128. "Return a form associated to tag-expression TAGS.
  7129. Build a form testing a line for agenda filter for
  7130. tag-expressions. OP is an operator of type CHAR that allows the
  7131. function to set the right switches in the returned form."
  7132. (let (form)
  7133. ;; Any of the expressions can match if OP is +, all must match if
  7134. ;; the operator is -.
  7135. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7136. (let* ((tag (substring x 1))
  7137. (f (cond
  7138. ((string= "" tag) '(not tags))
  7139. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7140. ;; TAG is a regexp.
  7141. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7142. (t (list 'member (downcase tag) 'tags)))))
  7143. (push (if (eq op ?-) (list 'not f) f) form)))))
  7144. (defun org-agenda-filter-effort-form (e)
  7145. "Return the form to compare the effort of the current line with what E says.
  7146. E looks like \"+<2:25\"."
  7147. (let (op)
  7148. (setq e (substring e 1))
  7149. (setq op (string-to-char e) e (substring e 1))
  7150. (setq op (cond ((equal op ?<) '<=)
  7151. ((equal op ?>) '>=)
  7152. ((equal op ??) op)
  7153. (t '=)))
  7154. (list 'org-agenda-compare-effort (list 'quote op)
  7155. (org-duration-string-to-minutes e))))
  7156. (defun org-agenda-compare-effort (op value)
  7157. "Compare the effort of the current line with VALUE, using OP.
  7158. If the line does not have an effort defined, return nil."
  7159. (let ((eff (org-get-at-eol 'effort-minutes 1)))
  7160. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 -1))
  7161. value)))
  7162. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7163. "Expand group tags in FILTER for the agenda.
  7164. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7165. (if org-group-tags
  7166. (let ((case-fold-search t) rtn)
  7167. (mapc
  7168. (lambda (f)
  7169. (let (f0 dir)
  7170. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7171. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7172. (setq dir (if no-operator "" "+") f0 f))
  7173. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7174. (org-tags-expand f0 t t))
  7175. rtn))))
  7176. filter)
  7177. (reverse rtn))
  7178. filter))
  7179. (defun org-agenda-filter-apply (filter type &optional expand)
  7180. "Set FILTER as the new agenda filter and apply it. Optional
  7181. argument EXPAND can be used for the TYPE tag and will expand the
  7182. tags in the FILTER if any of the tags in FILTER are grouptags."
  7183. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7184. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7185. (let (tags cat txt)
  7186. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7187. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7188. ;; category is used as the filter:
  7189. (setq org-agenda-filtered-by-category
  7190. (and (eq type 'category)
  7191. (not (equal (substring (car filter) 0 1) "-"))))
  7192. (org-agenda-set-mode-name)
  7193. (save-excursion
  7194. (goto-char (point-min))
  7195. (while (not (eobp))
  7196. (if (org-get-at-bol 'org-marker)
  7197. (progn
  7198. (setq tags (org-get-at-bol 'tags)
  7199. cat (org-get-at-eol 'org-category 1)
  7200. txt (org-get-at-bol 'txt))
  7201. (if (not (eval org-agenda-filter-form))
  7202. (org-agenda-filter-hide-line type))
  7203. (beginning-of-line 2))
  7204. (beginning-of-line 2))))
  7205. (if (get-char-property (point) 'invisible)
  7206. (ignore-errors (org-agenda-previous-line)))))
  7207. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7208. "Filter by top headline HL."
  7209. (org-agenda-set-mode-name)
  7210. (save-excursion
  7211. (goto-char (point-min))
  7212. (while (not (eobp))
  7213. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7214. (tophl (and pos (org-find-top-headline pos))))
  7215. (if (and tophl (funcall (if negative 'identity 'not)
  7216. (string= hl tophl)))
  7217. (org-agenda-filter-hide-line 'top-headline)))
  7218. (beginning-of-line 2)))
  7219. (if (get-char-property (point) 'invisible)
  7220. (org-agenda-previous-line))
  7221. (setq org-agenda-top-headline-filter hl
  7222. org-agenda-filtered-by-top-headline t))
  7223. (defun org-agenda-filter-hide-line (type)
  7224. "Hide lines with TYPE in the agenda buffer."
  7225. (let* ((b (max (point-min) (1- (point-at-bol))))
  7226. (e (point-at-eol)))
  7227. (let ((inhibit-read-only t))
  7228. (add-text-properties
  7229. b e `(invisible org-filtered org-filter-type ,type)))))
  7230. (defun org-agenda-remove-filter (type)
  7231. (interactive)
  7232. "Remove filter of type TYPE from the agenda buffer."
  7233. (save-excursion
  7234. (goto-char (point-min))
  7235. (let ((inhibit-read-only t) pos)
  7236. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7237. (goto-char pos)
  7238. (remove-text-properties
  7239. (point) (next-single-property-change (point) 'org-filter-type)
  7240. `(invisible org-filtered org-filter-type ,type))))
  7241. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7242. (setq org-agenda-filter-form nil)
  7243. (org-agenda-set-mode-name)
  7244. (org-agenda-finalize)))
  7245. (defun org-agenda-filter-show-all-tag nil
  7246. (org-agenda-remove-filter 'tag))
  7247. (defun org-agenda-filter-show-all-re nil
  7248. (org-agenda-remove-filter 'regexp))
  7249. (defun org-agenda-filter-show-all-effort nil
  7250. (org-agenda-remove-filter 'effort))
  7251. (defun org-agenda-filter-show-all-cat nil
  7252. (org-agenda-remove-filter 'category))
  7253. (defun org-agenda-filter-show-all-top-filter nil
  7254. (org-agenda-remove-filter 'top-headline))
  7255. (defun org-agenda-manipulate-query-add ()
  7256. "Manipulate the query by adding a search term with positive selection.
  7257. Positive selection means the term must be matched for selection of an entry."
  7258. (interactive)
  7259. (org-agenda-manipulate-query ?\[))
  7260. (defun org-agenda-manipulate-query-subtract ()
  7261. "Manipulate the query by adding a search term with negative selection.
  7262. Negative selection means term must not be matched for selection of an entry."
  7263. (interactive)
  7264. (org-agenda-manipulate-query ?\]))
  7265. (defun org-agenda-manipulate-query-add-re ()
  7266. "Manipulate the query by adding a search regexp with positive selection.
  7267. Positive selection means the regexp must match for selection of an entry."
  7268. (interactive)
  7269. (org-agenda-manipulate-query ?\{))
  7270. (defun org-agenda-manipulate-query-subtract-re ()
  7271. "Manipulate the query by adding a search regexp with negative selection.
  7272. Negative selection means regexp must not match for selection of an entry."
  7273. (interactive)
  7274. (org-agenda-manipulate-query ?\}))
  7275. (defun org-agenda-manipulate-query (char)
  7276. (cond
  7277. ((memq org-agenda-type '(timeline agenda))
  7278. (let ((org-agenda-include-inactive-timestamps t))
  7279. (org-agenda-redo))
  7280. (message "Display now includes inactive timestamps as well"))
  7281. ((eq org-agenda-type 'search)
  7282. (org-add-to-string
  7283. 'org-agenda-query-string
  7284. (if org-agenda-last-search-view-search-was-boolean
  7285. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7286. (?\{ . " +{}") (?\} . " -{}"))))
  7287. " "))
  7288. (setq org-agenda-redo-command
  7289. (list 'org-search-view
  7290. (car (get-text-property (min (1- (point-max)) (point))
  7291. 'org-last-args))
  7292. org-agenda-query-string
  7293. (+ (length org-agenda-query-string)
  7294. (if (member char '(?\{ ?\})) 0 1))))
  7295. (set-register org-agenda-query-register org-agenda-query-string)
  7296. (let ((org-agenda-overriding-arguments
  7297. (cdr org-agenda-redo-command)))
  7298. (org-agenda-redo)))
  7299. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7300. org-agenda-type))))
  7301. (defun org-add-to-string (var string)
  7302. (set var (concat (symbol-value var) string)))
  7303. (defun org-agenda-goto-date (span)
  7304. "Jump to DATE in agenda."
  7305. (interactive "P")
  7306. (let* ((org-read-date-prefer-future
  7307. (eval org-agenda-jump-prefer-future))
  7308. (date (org-read-date))
  7309. (day (time-to-days (org-time-string-to-time date)))
  7310. (org-agenda-sticky-orig org-agenda-sticky)
  7311. (org-agenda-buffer-tmp-name (buffer-name))
  7312. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7313. (0-arg (or current-prefix-arg (car args)))
  7314. (2-arg (nth 2 args))
  7315. (with-hour-p (nth 4 org-agenda-redo-command))
  7316. (newcmd (list 'org-agenda-list 0-arg date
  7317. (org-agenda-span-to-ndays
  7318. 2-arg (org-time-string-to-absolute date))
  7319. with-hour-p))
  7320. (newargs (cdr newcmd))
  7321. (inhibit-read-only t)
  7322. org-agenda-sticky)
  7323. (if (not (org-agenda-check-type t 'agenda))
  7324. (error "Not available in non-agenda views")
  7325. (add-text-properties (point-min) (point-max)
  7326. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7327. (org-agenda-redo)
  7328. (goto-char (point-min))
  7329. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7330. (save-excursion (move-beginning-of-line 2) (eobp))))
  7331. (move-beginning-of-line 2))
  7332. (setq org-agenda-sticky org-agenda-sticky-orig
  7333. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7334. (defun org-agenda-goto-today ()
  7335. "Go to today."
  7336. (interactive)
  7337. (org-agenda-check-type t 'timeline 'agenda)
  7338. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7339. (curspan (nth 2 args))
  7340. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7341. (cond
  7342. (tdpos (goto-char tdpos))
  7343. ((eq org-agenda-type 'agenda)
  7344. (let* ((sd (org-agenda-compute-starting-span
  7345. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7346. (org-agenda-overriding-arguments args))
  7347. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7348. (org-agenda-redo)
  7349. (org-agenda-find-same-or-today-or-agenda)))
  7350. (t (error "Cannot find today")))))
  7351. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7352. (goto-char
  7353. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7354. (text-property-any (point-min) (point-max) 'org-today t)
  7355. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7356. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7357. (org-agenda-backward-block))
  7358. (point-min))))
  7359. (defun org-agenda-backward-block ()
  7360. "Move backward by one agenda block."
  7361. (interactive)
  7362. (org-agenda-forward-block 'backward))
  7363. (defun org-agenda-forward-block (&optional backward)
  7364. "Move forward by one agenda block.
  7365. When optional argument BACKWARD is set, go backward"
  7366. (interactive)
  7367. (cond ((not (derived-mode-p 'org-agenda-mode))
  7368. (user-error
  7369. "Cannot execute this command outside of org-agenda-mode buffers"))
  7370. ((looking-at (if backward "\\`" "\\'"))
  7371. (message "Already at the %s block" (if backward "first" "last")))
  7372. (t (let ((pos (prog1 (point)
  7373. (ignore-errors (if backward (backward-char 1)
  7374. (move-end-of-line 1)))))
  7375. (f (if backward
  7376. 'previous-single-property-change
  7377. 'next-single-property-change))
  7378. moved dest)
  7379. (while (and (setq dest (funcall
  7380. f (point) 'org-agenda-structural-header))
  7381. (not (get-text-property
  7382. (point) 'org-agenda-structural-header)))
  7383. (setq moved t)
  7384. (goto-char dest))
  7385. (if moved (move-beginning-of-line 1)
  7386. (goto-char (if backward (point-min) (point-max)))
  7387. (move-beginning-of-line 1)
  7388. (message "No %s block" (if backward "previous" "further")))))))
  7389. (defun org-agenda-later (arg)
  7390. "Go forward in time by the current span.
  7391. With prefix ARG, go forward that many times the current span."
  7392. (interactive "p")
  7393. (org-agenda-check-type t 'agenda)
  7394. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7395. (span (or (nth 2 args) org-agenda-current-span))
  7396. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7397. (greg (calendar-gregorian-from-absolute sd))
  7398. (cnt (org-get-at-bol 'org-day-cnt))
  7399. greg2)
  7400. (cond
  7401. ((numberp span)
  7402. (setq sd (+ (* span arg) sd)))
  7403. ((eq span 'day)
  7404. (setq sd (+ arg sd)))
  7405. ((eq span 'week)
  7406. (setq sd (+ (* 7 arg) sd)))
  7407. ((eq span 'fortnight)
  7408. (setq sd (+ (* 14 arg) sd)))
  7409. ((eq span 'month)
  7410. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7411. sd (calendar-absolute-from-gregorian greg2))
  7412. (setcar greg2 (1+ (car greg2))))
  7413. ((eq span 'year)
  7414. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7415. sd (calendar-absolute-from-gregorian greg2))
  7416. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7417. (t
  7418. (setq sd (+ (* span arg) sd))))
  7419. (let ((org-agenda-overriding-cmd
  7420. ;; `cmd' may have been set by `org-agenda-run-series' which
  7421. ;; uses `org-agenda-overriding-cmd' to decide whether
  7422. ;; overriding is allowed for `cmd'
  7423. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7424. (org-agenda-overriding-arguments
  7425. (list (car args) sd span)))
  7426. (org-agenda-redo)
  7427. (org-agenda-find-same-or-today-or-agenda cnt))))
  7428. (defun org-agenda-earlier (arg)
  7429. "Go backward in time by the current span.
  7430. With prefix ARG, go backward that many times the current span."
  7431. (interactive "p")
  7432. (org-agenda-later (- arg)))
  7433. (defun org-agenda-view-mode-dispatch ()
  7434. "Call one of the view mode commands."
  7435. (interactive)
  7436. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7437. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7438. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7439. (let ((a (read-char-exclusive)))
  7440. (case a
  7441. (?\ (call-interactively 'org-agenda-reset-view))
  7442. (?d (call-interactively 'org-agenda-day-view))
  7443. (?w (call-interactively 'org-agenda-week-view))
  7444. (?t (call-interactively 'org-agenda-fortnight-view))
  7445. (?m (call-interactively 'org-agenda-month-view))
  7446. (?y (call-interactively 'org-agenda-year-view))
  7447. (?l (call-interactively 'org-agenda-log-mode))
  7448. (?L (org-agenda-log-mode '(4)))
  7449. (?c (org-agenda-log-mode 'clockcheck))
  7450. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7451. (?a (call-interactively 'org-agenda-archives-mode))
  7452. (?A (org-agenda-archives-mode 'files))
  7453. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7454. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7455. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7456. (?D (call-interactively 'org-agenda-toggle-diary))
  7457. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7458. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7459. (org-agenda-check-type t 'timeline 'agenda)
  7460. (org-agenda-redo))
  7461. (message "Display now includes inactive timestamps as well"))
  7462. (?q (message "Abort"))
  7463. (otherwise (error "Invalid key" )))))
  7464. (defun org-agenda-reset-view ()
  7465. "Switch to default view for agenda."
  7466. (interactive)
  7467. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7468. (defun org-agenda-day-view (&optional day-of-month)
  7469. "Switch to daily view for agenda.
  7470. With argument DAY-OF-MONTH, switch to that day of the month."
  7471. (interactive "P")
  7472. (org-agenda-change-time-span 'day day-of-month))
  7473. (defun org-agenda-week-view (&optional iso-week)
  7474. "Switch to daily view for agenda.
  7475. With argument ISO-WEEK, switch to the corresponding ISO week.
  7476. If ISO-WEEK has more then 2 digits, only the last two encode the
  7477. week. Any digits before this encode a year. So 200712 means
  7478. week 12 of year 2007. Years in the range 1938-2037 can also be
  7479. written as 2-digit years."
  7480. (interactive "P")
  7481. (org-agenda-change-time-span 'week iso-week))
  7482. (defun org-agenda-fortnight-view (&optional iso-week)
  7483. "Switch to daily view for agenda.
  7484. With argument ISO-WEEK, switch to the corresponding ISO week.
  7485. If ISO-WEEK has more then 2 digits, only the last two encode the
  7486. week. Any digits before this encode a year. So 200712 means
  7487. week 12 of year 2007. Years in the range 1938-2037 can also be
  7488. written as 2-digit years."
  7489. (interactive "P")
  7490. (org-agenda-change-time-span 'fortnight iso-week))
  7491. (defun org-agenda-month-view (&optional month)
  7492. "Switch to monthly view for agenda.
  7493. With argument MONTH, switch to that month."
  7494. (interactive "P")
  7495. (org-agenda-change-time-span 'month month))
  7496. (defun org-agenda-year-view (&optional year)
  7497. "Switch to yearly view for agenda.
  7498. With argument YEAR, switch to that year.
  7499. If MONTH has more then 2 digits, only the last two encode the
  7500. month. Any digits before this encode a year. So 200712 means
  7501. December year 2007. Years in the range 1938-2037 can also be
  7502. written as 2-digit years."
  7503. (interactive "P")
  7504. (when year
  7505. (setq year (org-small-year-to-year year)))
  7506. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7507. (org-agenda-change-time-span 'year year)
  7508. (error "Abort")))
  7509. (defun org-agenda-change-time-span (span &optional n)
  7510. "Change the agenda view to SPAN.
  7511. SPAN may be `day', `week', `fortnight', `month', `year'."
  7512. (org-agenda-check-type t 'agenda)
  7513. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7514. (curspan (nth 2 args)))
  7515. (if (and (not n) (equal curspan span))
  7516. (error "Viewing span is already \"%s\"" span))
  7517. (let* ((sd (or (org-get-at-bol 'day)
  7518. (nth 1 args)
  7519. org-starting-day))
  7520. (sd (org-agenda-compute-starting-span sd span n))
  7521. (org-agenda-overriding-cmd
  7522. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7523. (org-agenda-overriding-arguments
  7524. (list (car args) sd span)))
  7525. (org-agenda-redo)
  7526. (org-agenda-find-same-or-today-or-agenda))
  7527. (org-agenda-set-mode-name)
  7528. (message "Switched to %s view" span)))
  7529. (defun org-agenda-compute-starting-span (sd span &optional n)
  7530. "Compute starting date for agenda.
  7531. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7532. is a cons cell with the starting date and the number of days,
  7533. so that the date SD will be in that range."
  7534. (let* ((greg (calendar-gregorian-from-absolute sd))
  7535. (dg (nth 1 greg))
  7536. (mg (car greg))
  7537. (yg (nth 2 greg)))
  7538. (cond
  7539. ((eq span 'day)
  7540. (when n
  7541. (setq sd (+ (calendar-absolute-from-gregorian
  7542. (list mg 1 yg))
  7543. n -1))))
  7544. ((or (eq span 'week) (eq span 'fortnight))
  7545. (let* ((nt (calendar-day-of-week
  7546. (calendar-gregorian-from-absolute sd)))
  7547. (d (if org-agenda-start-on-weekday
  7548. (- nt org-agenda-start-on-weekday)
  7549. 0))
  7550. y1)
  7551. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7552. (when n
  7553. (require 'cal-iso)
  7554. (when (> n 99)
  7555. (setq y1 (org-small-year-to-year (/ n 100))
  7556. n (mod n 100)))
  7557. (setq sd
  7558. (calendar-iso-to-absolute
  7559. (list n 1
  7560. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7561. ((eq span 'month)
  7562. (let (y1)
  7563. (when (and n (> n 99))
  7564. (setq y1 (org-small-year-to-year (/ n 100))
  7565. n (mod n 100)))
  7566. (setq sd (calendar-absolute-from-gregorian
  7567. (list (or n mg) 1 (or y1 yg))))))
  7568. ((eq span 'year)
  7569. (setq sd (calendar-absolute-from-gregorian
  7570. (list 1 1 (or n yg))))))
  7571. sd))
  7572. (defun org-agenda-next-date-line (&optional arg)
  7573. "Jump to the next line indicating a date in agenda buffer."
  7574. (interactive "p")
  7575. (org-agenda-check-type t 'agenda 'timeline)
  7576. (beginning-of-line 1)
  7577. ;; This does not work if user makes date format that starts with a blank
  7578. (if (looking-at "^\\S-") (forward-char 1))
  7579. (if (not (re-search-forward "^\\S-" nil t arg))
  7580. (progn
  7581. (backward-char 1)
  7582. (error "No next date after this line in this buffer")))
  7583. (goto-char (match-beginning 0)))
  7584. (defun org-agenda-previous-date-line (&optional arg)
  7585. "Jump to the previous line indicating a date in agenda buffer."
  7586. (interactive "p")
  7587. (org-agenda-check-type t 'agenda 'timeline)
  7588. (beginning-of-line 1)
  7589. (if (not (re-search-backward "^\\S-" nil t arg))
  7590. (error "No previous date before this line in this buffer")))
  7591. ;; Initialize the highlight
  7592. (defvar org-hl (make-overlay 1 1))
  7593. (overlay-put org-hl 'face 'highlight)
  7594. (defun org-highlight (begin end &optional buffer)
  7595. "Highlight a region with overlay."
  7596. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7597. (defun org-unhighlight ()
  7598. "Detach overlay INDEX."
  7599. (org-detach-overlay org-hl))
  7600. (defun org-unhighlight-once ()
  7601. "Remove the highlight from its position, and this function from the hook."
  7602. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7603. (org-unhighlight))
  7604. (defvar org-agenda-pre-follow-window-conf nil)
  7605. (defun org-agenda-follow-mode ()
  7606. "Toggle follow mode in an agenda buffer."
  7607. (interactive)
  7608. (unless org-agenda-follow-mode
  7609. (setq org-agenda-pre-follow-window-conf
  7610. (current-window-configuration)))
  7611. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7612. (unless org-agenda-follow-mode
  7613. (set-window-configuration org-agenda-pre-follow-window-conf))
  7614. (org-agenda-set-mode-name)
  7615. (org-agenda-do-context-action)
  7616. (message "Follow mode is %s"
  7617. (if org-agenda-follow-mode "on" "off")))
  7618. (defun org-agenda-entry-text-mode (&optional arg)
  7619. "Toggle entry text mode in an agenda buffer."
  7620. (interactive "P")
  7621. (if (or org-agenda-tag-filter
  7622. org-agenda-category-filter
  7623. org-agenda-regexp-filter
  7624. org-agenda-top-headline-filter)
  7625. (user-error "Can't show entry text in filtered views")
  7626. (setq org-agenda-entry-text-mode (or (integerp arg)
  7627. (not org-agenda-entry-text-mode)))
  7628. (org-agenda-entry-text-hide)
  7629. (and org-agenda-entry-text-mode
  7630. (let ((org-agenda-entry-text-maxlines
  7631. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7632. (org-agenda-entry-text-show)))
  7633. (org-agenda-set-mode-name)
  7634. (message "Entry text mode is %s%s"
  7635. (if org-agenda-entry-text-mode "on" "off")
  7636. (if (not org-agenda-entry-text-mode) ""
  7637. (format " (maximum number of lines is %d)"
  7638. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7639. (defun org-agenda-clockreport-mode ()
  7640. "Toggle clocktable mode in an agenda buffer."
  7641. (interactive)
  7642. (org-agenda-check-type t 'agenda)
  7643. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7644. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7645. (org-agenda-set-mode-name)
  7646. (org-agenda-redo)
  7647. (message "Clocktable mode is %s"
  7648. (if org-agenda-clockreport-mode "on" "off")))
  7649. (defun org-agenda-log-mode (&optional special)
  7650. "Toggle log mode in an agenda buffer.
  7651. With argument SPECIAL, show all possible log items, not only the ones
  7652. configured in `org-agenda-log-mode-items'.
  7653. With a double \\[universal-argument] prefix arg, show *only* \
  7654. log items, nothing else."
  7655. (interactive "P")
  7656. (org-agenda-check-type t 'agenda 'timeline)
  7657. (setq org-agenda-show-log
  7658. (cond
  7659. ((equal special '(16)) 'only)
  7660. ((eq special 'clockcheck)
  7661. (if (eq org-agenda-show-log 'clockcheck)
  7662. nil 'clockcheck))
  7663. (special '(closed clock state))
  7664. (t (not org-agenda-show-log))))
  7665. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7666. (org-agenda-set-mode-name)
  7667. (org-agenda-redo)
  7668. (message "Log mode is %s"
  7669. (if org-agenda-show-log "on" "off")))
  7670. (defun org-agenda-archives-mode (&optional with-files)
  7671. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7672. When called with a prefix argument, include all archive files as well."
  7673. (interactive "P")
  7674. (setq org-agenda-archives-mode
  7675. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7676. (org-agenda-set-mode-name)
  7677. (org-agenda-redo)
  7678. (message
  7679. "%s"
  7680. (cond
  7681. ((eq org-agenda-archives-mode nil)
  7682. "No archives are included")
  7683. ((eq org-agenda-archives-mode 'trees)
  7684. (format "Trees with :%s: tag are included" org-archive-tag))
  7685. ((eq org-agenda-archives-mode t)
  7686. (format "Trees with :%s: tag and all active archive files are included"
  7687. org-archive-tag)))))
  7688. (defun org-agenda-toggle-diary ()
  7689. "Toggle diary inclusion in an agenda buffer."
  7690. (interactive)
  7691. (org-agenda-check-type t 'agenda)
  7692. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7693. (org-agenda-redo)
  7694. (org-agenda-set-mode-name)
  7695. (message "Diary inclusion turned %s"
  7696. (if org-agenda-include-diary "on" "off")))
  7697. (defun org-agenda-toggle-deadlines ()
  7698. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7699. (interactive)
  7700. (org-agenda-check-type t 'agenda)
  7701. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7702. (org-agenda-redo)
  7703. (org-agenda-set-mode-name)
  7704. (message "Deadlines inclusion turned %s"
  7705. (if org-agenda-include-deadlines "on" "off")))
  7706. (defun org-agenda-toggle-time-grid ()
  7707. "Toggle time grid in an agenda buffer."
  7708. (interactive)
  7709. (org-agenda-check-type t 'agenda)
  7710. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7711. (org-agenda-redo)
  7712. (org-agenda-set-mode-name)
  7713. (message "Time-grid turned %s"
  7714. (if org-agenda-use-time-grid "on" "off")))
  7715. (defun org-agenda-set-mode-name ()
  7716. "Set the mode name to indicate all the small mode settings."
  7717. (setq mode-name
  7718. (list "Org-Agenda"
  7719. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7720. " "
  7721. '(:eval (org-agenda-span-name org-agenda-current-span))
  7722. (if org-agenda-follow-mode " Follow" "")
  7723. (if org-agenda-entry-text-mode " ETxt" "")
  7724. (if org-agenda-include-diary " Diary" "")
  7725. (if org-agenda-include-deadlines " Ddl" "")
  7726. (if org-agenda-use-time-grid " Grid" "")
  7727. (if (and (boundp 'org-habit-show-habits)
  7728. org-habit-show-habits) " Habit" "")
  7729. (cond
  7730. ((consp org-agenda-show-log) " LogAll")
  7731. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7732. (org-agenda-show-log " Log")
  7733. (t ""))
  7734. (if (or org-agenda-category-filter
  7735. (get 'org-agenda-category-filter :preset-filter))
  7736. '(:eval (org-propertize
  7737. (concat " <"
  7738. (mapconcat
  7739. 'identity
  7740. (append
  7741. (get 'org-agenda-category-filter :preset-filter)
  7742. org-agenda-category-filter)
  7743. "")
  7744. ">")
  7745. 'face 'org-agenda-filter-category
  7746. 'help-echo "Category used in filtering")) "")
  7747. (if (or org-agenda-tag-filter
  7748. (get 'org-agenda-tag-filter :preset-filter))
  7749. '(:eval (org-propertize
  7750. (concat " {"
  7751. (mapconcat
  7752. 'identity
  7753. (append
  7754. (get 'org-agenda-tag-filter :preset-filter)
  7755. org-agenda-tag-filter)
  7756. "")
  7757. "}")
  7758. 'face 'org-agenda-filter-tags
  7759. 'help-echo "Tags used in filtering")) "")
  7760. (if (or org-agenda-effort-filter
  7761. (get 'org-agenda-effort-filter :preset-filter))
  7762. '(:eval (org-propertize
  7763. (concat " {"
  7764. (mapconcat
  7765. 'identity
  7766. (append
  7767. (get 'org-agenda-effort-filter :preset-filter)
  7768. org-agenda-effort-filter)
  7769. "")
  7770. "}")
  7771. 'face 'org-agenda-filter-effort
  7772. 'help-echo "Effort conditions used in filtering")) "")
  7773. (if (or org-agenda-regexp-filter
  7774. (get 'org-agenda-regexp-filter :preset-filter))
  7775. '(:eval (org-propertize
  7776. (concat " ["
  7777. (mapconcat
  7778. 'identity
  7779. (append
  7780. (get 'org-agenda-regexp-filter :preset-filter)
  7781. org-agenda-regexp-filter)
  7782. "")
  7783. "]")
  7784. 'face 'org-agenda-filter-regexp
  7785. 'help-echo "Regexp used in filtering")) "")
  7786. (if org-agenda-archives-mode
  7787. (if (eq org-agenda-archives-mode t)
  7788. " Archives"
  7789. (format " :%s:" org-archive-tag))
  7790. "")
  7791. (if org-agenda-clockreport-mode " Clock" "")))
  7792. (force-mode-line-update))
  7793. (define-obsolete-function-alias
  7794. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7795. (defun org-agenda-update-agenda-type ()
  7796. "Update the agenda type after each command."
  7797. (setq org-agenda-type
  7798. (or (get-text-property (point) 'org-agenda-type)
  7799. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7800. (defun org-agenda-next-line ()
  7801. "Move cursor to the next line, and show if follow mode is active."
  7802. (interactive)
  7803. (call-interactively 'next-line)
  7804. (org-agenda-do-context-action))
  7805. (defun org-agenda-previous-line ()
  7806. "Move cursor to the previous line, and show if follow-mode is active."
  7807. (interactive)
  7808. (call-interactively 'previous-line)
  7809. (org-agenda-do-context-action))
  7810. (defun org-agenda-next-item (n)
  7811. "Move cursor to next agenda item."
  7812. (interactive "p")
  7813. (let ((col (current-column)))
  7814. (dotimes (c n)
  7815. (when (next-single-property-change (point-at-eol) 'org-marker)
  7816. (move-end-of-line 1)
  7817. (goto-char (next-single-property-change (point) 'org-marker))))
  7818. (org-move-to-column col))
  7819. (org-agenda-do-context-action))
  7820. (defun org-agenda-previous-item (n)
  7821. "Move cursor to next agenda item."
  7822. (interactive "p")
  7823. (dotimes (c n)
  7824. (let ((col (current-column))
  7825. (goto (save-excursion
  7826. (move-end-of-line 0)
  7827. (previous-single-property-change (point) 'org-marker))))
  7828. (if goto (goto-char goto))
  7829. (org-move-to-column col)))
  7830. (org-agenda-do-context-action))
  7831. (defun org-agenda-do-context-action ()
  7832. "Show outline path and, maybe, follow mode window."
  7833. (let ((m (org-get-at-bol 'org-marker)))
  7834. (when (and (markerp m) (marker-buffer m))
  7835. (and org-agenda-follow-mode
  7836. (if org-agenda-follow-indirect
  7837. (org-agenda-tree-to-indirect-buffer nil)
  7838. (org-agenda-show)))
  7839. (and org-agenda-show-outline-path
  7840. (org-with-point-at m (org-display-outline-path t))))))
  7841. (defun org-agenda-show-tags ()
  7842. "Show the tags applicable to the current item."
  7843. (interactive)
  7844. (let* ((tags (org-get-at-bol 'tags)))
  7845. (if tags
  7846. (message "Tags are :%s:"
  7847. (org-no-properties (mapconcat 'identity tags ":")))
  7848. (message "No tags associated with this line"))))
  7849. (defun org-agenda-goto (&optional highlight)
  7850. "Go to the entry at point in the corresponding Org-mode file."
  7851. (interactive)
  7852. (let* ((marker (or (org-get-at-bol 'org-marker)
  7853. (org-agenda-error)))
  7854. (buffer (marker-buffer marker))
  7855. (pos (marker-position marker)))
  7856. (switch-to-buffer-other-window buffer)
  7857. (widen)
  7858. (push-mark)
  7859. (goto-char pos)
  7860. (when (derived-mode-p 'org-mode)
  7861. (org-show-context 'agenda)
  7862. (save-excursion
  7863. (and (outline-next-heading)
  7864. (org-flag-heading nil))) ; show the next heading
  7865. (when (outline-invisible-p)
  7866. (outline-show-entry)) ; display invisible text
  7867. (recenter (/ (window-height) 2))
  7868. (org-back-to-heading t)
  7869. (if (re-search-forward org-complex-heading-regexp nil t)
  7870. (goto-char (match-beginning 4))))
  7871. (run-hooks 'org-agenda-after-show-hook)
  7872. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7873. (defvar org-agenda-after-show-hook nil
  7874. "Normal hook run after an item has been shown from the agenda.
  7875. Point is in the buffer where the item originated.")
  7876. (defun org-agenda-kill ()
  7877. "Kill the entry or subtree belonging to the current agenda entry."
  7878. (interactive)
  7879. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7880. (let* ((bufname-orig (buffer-name))
  7881. (marker (or (org-get-at-bol 'org-marker)
  7882. (org-agenda-error)))
  7883. (buffer (marker-buffer marker))
  7884. (pos (marker-position marker))
  7885. (type (org-get-at-bol 'type))
  7886. dbeg dend (n 0) conf)
  7887. (org-with-remote-undo buffer
  7888. (with-current-buffer buffer
  7889. (save-excursion
  7890. (goto-char pos)
  7891. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7892. (setq dbeg (progn (org-back-to-heading t) (point))
  7893. dend (org-end-of-subtree t t))
  7894. (setq dbeg (point-at-bol)
  7895. dend (min (point-max) (1+ (point-at-eol)))))
  7896. (goto-char dbeg)
  7897. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7898. (setq conf (or (eq t org-agenda-confirm-kill)
  7899. (and (numberp org-agenda-confirm-kill)
  7900. (> n org-agenda-confirm-kill))))
  7901. (and conf
  7902. (not (y-or-n-p
  7903. (format "Delete entry with %d lines in buffer \"%s\"? "
  7904. n (buffer-name buffer))))
  7905. (error "Abort"))
  7906. (let ((org-agenda-buffer-name bufname-orig))
  7907. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7908. (with-current-buffer buffer (delete-region dbeg dend))
  7909. (message "Agenda item and source killed"))))
  7910. (defvar org-archive-default-command) ; defined in org-archive.el
  7911. (defun org-agenda-archive-default ()
  7912. "Archive the entry or subtree belonging to the current agenda entry."
  7913. (interactive)
  7914. (require 'org-archive)
  7915. (org-agenda-archive-with org-archive-default-command))
  7916. (defun org-agenda-archive-default-with-confirmation ()
  7917. "Archive the entry or subtree belonging to the current agenda entry."
  7918. (interactive)
  7919. (require 'org-archive)
  7920. (org-agenda-archive-with org-archive-default-command 'confirm))
  7921. (defun org-agenda-archive ()
  7922. "Archive the entry or subtree belonging to the current agenda entry."
  7923. (interactive)
  7924. (org-agenda-archive-with 'org-archive-subtree))
  7925. (defun org-agenda-archive-to-archive-sibling ()
  7926. "Move the entry to the archive sibling."
  7927. (interactive)
  7928. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7929. (defun org-agenda-archive-with (cmd &optional confirm)
  7930. "Move the entry to the archive sibling."
  7931. (interactive)
  7932. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7933. (let* ((bufname-orig (buffer-name))
  7934. (marker (or (org-get-at-bol 'org-marker)
  7935. (org-agenda-error)))
  7936. (buffer (marker-buffer marker))
  7937. (pos (marker-position marker)))
  7938. (org-with-remote-undo buffer
  7939. (with-current-buffer buffer
  7940. (if (derived-mode-p 'org-mode)
  7941. (if (and confirm
  7942. (not (y-or-n-p "Archive this subtree or entry? ")))
  7943. (error "Abort")
  7944. (save-window-excursion
  7945. (goto-char pos)
  7946. (let ((org-agenda-buffer-name bufname-orig))
  7947. (org-remove-subtree-entries-from-agenda))
  7948. (org-back-to-heading t)
  7949. (funcall cmd)))
  7950. (error "Archiving works only in Org-mode files"))))))
  7951. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7952. "Remove all lines in the agenda that correspond to a given subtree.
  7953. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7954. If this information is not given, the function uses the tree at point."
  7955. (let ((buf (or buf (current-buffer))) m p)
  7956. (save-excursion
  7957. (unless (and beg end)
  7958. (org-back-to-heading t)
  7959. (setq beg (point))
  7960. (org-end-of-subtree t)
  7961. (setq end (point)))
  7962. (set-buffer (get-buffer org-agenda-buffer-name))
  7963. (save-excursion
  7964. (goto-char (point-max))
  7965. (beginning-of-line 1)
  7966. (while (not (bobp))
  7967. (when (and (setq m (org-get-at-bol 'org-marker))
  7968. (equal buf (marker-buffer m))
  7969. (setq p (marker-position m))
  7970. (>= p beg)
  7971. (< p end))
  7972. (let ((inhibit-read-only t))
  7973. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7974. (beginning-of-line 0))))))
  7975. (defun org-agenda-refile (&optional goto rfloc no-update)
  7976. "Refile the item at point.
  7977. When GOTO is 0 or \\='(64) or a triple \\[universal-argument] prefix argument,
  7978. clear the refile cache.
  7979. When GOTO is \\='(16) or a double \\[universal-argument] prefix argument,
  7980. go to the location of the last refiled item.
  7981. RFLOC can be a refile location obtained in a different way.
  7982. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7983. (interactive "P")
  7984. (cond
  7985. ((member goto '(0 (64)))
  7986. (org-refile-cache-clear))
  7987. ((equal goto '(16))
  7988. (org-refile-goto-last-stored))
  7989. (t
  7990. (let* ((buffer-orig (buffer-name))
  7991. (marker (or (org-get-at-bol 'org-hd-marker)
  7992. (org-agenda-error)))
  7993. (buffer (marker-buffer marker))
  7994. (pos (marker-position marker))
  7995. (rfloc (or rfloc
  7996. (org-refile-get-location
  7997. (if goto "Goto" "Refile to") buffer
  7998. org-refile-allow-creating-parent-nodes))))
  7999. (with-current-buffer buffer
  8000. (save-excursion
  8001. (save-restriction
  8002. (widen)
  8003. (goto-char marker)
  8004. (let ((org-agenda-buffer-name buffer-orig))
  8005. (org-remove-subtree-entries-from-agenda))
  8006. (org-refile goto buffer rfloc)))))
  8007. (unless no-update (org-agenda-redo)))))
  8008. (defun org-agenda-open-link (&optional arg)
  8009. "Open the link(s) in the current entry, if any.
  8010. This looks for a link in the displayed line in the agenda.
  8011. It also looks at the text of the entry itself."
  8012. (interactive "P")
  8013. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8014. (org-get-at-bol 'org-marker)))
  8015. (buffer (and marker (marker-buffer marker)))
  8016. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8017. (lkall (and buffer (org-offer-links-in-entry
  8018. buffer marker arg prefix)))
  8019. (lk0 (car lkall))
  8020. (lk (if (stringp lk0) (list lk0) lk0))
  8021. (lkend (cdr lkall))
  8022. trg)
  8023. (cond
  8024. ((and buffer lk)
  8025. (mapcar (lambda(l)
  8026. (with-current-buffer buffer
  8027. (setq trg (and (string-match org-bracket-link-regexp l)
  8028. (match-string 1 l)))
  8029. (if (or (not trg) (string-match org-any-link-re trg))
  8030. (save-excursion
  8031. (save-restriction
  8032. (widen)
  8033. (goto-char marker)
  8034. (when (search-forward l nil lkend)
  8035. (goto-char (match-beginning 0))
  8036. (org-open-at-point))))
  8037. ;; This is an internal link, widen the buffer
  8038. (switch-to-buffer-other-window buffer)
  8039. (widen)
  8040. (goto-char marker)
  8041. (when (search-forward l nil lkend)
  8042. (goto-char (match-beginning 0))
  8043. (org-open-at-point)))))
  8044. lk))
  8045. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  8046. (save-excursion
  8047. (beginning-of-line 1)
  8048. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  8049. (org-open-link-from-string (match-string 1)))
  8050. (t (message "No link to open here")))))
  8051. (defun org-agenda-copy-local-variable (var)
  8052. "Get a variable from a referenced buffer and install it here."
  8053. (let ((m (org-get-at-bol 'org-marker)))
  8054. (when (and m (buffer-live-p (marker-buffer m)))
  8055. (set (make-local-variable var)
  8056. (with-current-buffer (marker-buffer m)
  8057. (symbol-value var))))))
  8058. (defun org-agenda-switch-to (&optional delete-other-windows)
  8059. "Go to the Org mode file which contains the item at point.
  8060. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8061. displayed Org file fills the frame."
  8062. (interactive)
  8063. (if (and org-return-follows-link
  8064. (not (org-get-at-bol 'org-marker))
  8065. (org-in-regexp org-bracket-link-regexp))
  8066. (org-open-link-from-string (match-string 0))
  8067. (let* ((marker (or (org-get-at-bol 'org-marker)
  8068. (org-agenda-error)))
  8069. (buffer (marker-buffer marker))
  8070. (pos (marker-position marker)))
  8071. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8072. (org-pop-to-buffer-same-window buffer)
  8073. (when delete-other-windows (delete-other-windows))
  8074. (widen)
  8075. (goto-char pos)
  8076. (when (derived-mode-p 'org-mode)
  8077. (org-show-context 'agenda)
  8078. (run-hooks 'org-agenda-after-show-hook)))))
  8079. (defun org-agenda-goto-mouse (ev)
  8080. "Go to the Org-mode file which contains the item at the mouse click."
  8081. (interactive "e")
  8082. (mouse-set-point ev)
  8083. (org-agenda-goto))
  8084. (defun org-agenda-show (&optional full-entry)
  8085. "Display the Org-mode file which contains the item at point.
  8086. With prefix argument FULL-ENTRY, make the entire entry visible
  8087. if it was hidden in the outline."
  8088. (interactive "P")
  8089. (let ((win (selected-window)))
  8090. (org-agenda-goto t)
  8091. (when full-entry (org-show-entry))
  8092. (select-window win)))
  8093. (defvar org-agenda-show-window nil)
  8094. (defun org-agenda-show-and-scroll-up (&optional arg)
  8095. "Display the Org-mode file which contains the item at point.
  8096. When called repeatedly, scroll the window that is displaying the buffer.
  8097. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  8098. `show-subtree' to display the item, so that drawers and logbooks stay
  8099. folded."
  8100. (interactive "P")
  8101. (let ((win (selected-window)))
  8102. (if (and (window-live-p org-agenda-show-window)
  8103. (eq this-command last-command))
  8104. (progn
  8105. (select-window org-agenda-show-window)
  8106. (ignore-errors (scroll-up)))
  8107. (org-agenda-goto t)
  8108. (if arg (org-show-entry) (outline-show-subtree))
  8109. (setq org-agenda-show-window (selected-window)))
  8110. (select-window win)))
  8111. (defun org-agenda-show-scroll-down ()
  8112. "Scroll down the window showing the agenda."
  8113. (interactive)
  8114. (let ((win (selected-window)))
  8115. (when (window-live-p org-agenda-show-window)
  8116. (select-window org-agenda-show-window)
  8117. (ignore-errors (scroll-down))
  8118. (select-window win))))
  8119. (defun org-agenda-show-1 (&optional more)
  8120. "Display the Org-mode file which contains the item at point.
  8121. The prefix arg selects the amount of information to display:
  8122. 0 hide the subtree
  8123. 1 just show the entry according to defaults.
  8124. 2 show the children view
  8125. 3 show the subtree view
  8126. 4 show the entire subtree and any LOGBOOK drawers
  8127. 5 show the entire subtree and any drawers
  8128. With prefix argument FULL-ENTRY, make the entire entry visible
  8129. if it was hidden in the outline."
  8130. (interactive "p")
  8131. (let ((win (selected-window)))
  8132. (org-agenda-goto t)
  8133. (org-back-to-heading)
  8134. (set-window-start (selected-window) (point-at-bol))
  8135. (cond
  8136. ((= more 0)
  8137. (outline-hide-subtree)
  8138. (save-excursion
  8139. (org-back-to-heading)
  8140. (run-hook-with-args 'org-cycle-hook 'folded))
  8141. (message "Remote: FOLDED"))
  8142. ((and (org-called-interactively-p 'any) (= more 1))
  8143. (message "Remote: show with default settings"))
  8144. ((= more 2)
  8145. (outline-show-entry)
  8146. (org-show-children)
  8147. (save-excursion
  8148. (org-back-to-heading)
  8149. (run-hook-with-args 'org-cycle-hook 'children))
  8150. (message "Remote: CHILDREN"))
  8151. ((= more 3)
  8152. (outline-show-subtree)
  8153. (save-excursion
  8154. (org-back-to-heading)
  8155. (run-hook-with-args 'org-cycle-hook 'subtree))
  8156. (message "Remote: SUBTREE"))
  8157. ((= more 4)
  8158. (outline-show-subtree)
  8159. (save-excursion
  8160. (org-back-to-heading)
  8161. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8162. (message "Remote: SUBTREE AND LOGBOOK"))
  8163. ((> more 4)
  8164. (outline-show-subtree)
  8165. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8166. (select-window win)))
  8167. (defvar org-agenda-cycle-counter nil)
  8168. (defun org-agenda-cycle-show (&optional n)
  8169. "Show the current entry in another window, with default settings.
  8170. Default settings are taken from `org-show-context-detail'. When
  8171. use repeatedly in immediate succession, the remote entry will
  8172. cycle through visibility
  8173. children -> subtree -> folded
  8174. When called with a numeric prefix arg, that arg will be passed through to
  8175. `org-agenda-show-1'. For the interpretation of that argument, see the
  8176. docstring of `org-agenda-show-1'."
  8177. (interactive "P")
  8178. (if (integerp n)
  8179. (setq org-agenda-cycle-counter n)
  8180. (if (not (eq last-command this-command))
  8181. (setq org-agenda-cycle-counter 1)
  8182. (if (equal org-agenda-cycle-counter 0)
  8183. (setq org-agenda-cycle-counter 2)
  8184. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8185. (if (> org-agenda-cycle-counter 3)
  8186. (setq org-agenda-cycle-counter 0)))))
  8187. (org-agenda-show-1 org-agenda-cycle-counter))
  8188. (defun org-agenda-recenter (arg)
  8189. "Display the Org-mode file which contains the item at point and recenter."
  8190. (interactive "P")
  8191. (let ((win (selected-window)))
  8192. (org-agenda-goto t)
  8193. (recenter arg)
  8194. (select-window win)))
  8195. (defun org-agenda-show-mouse (ev)
  8196. "Display the Org-mode file which contains the item at the mouse click."
  8197. (interactive "e")
  8198. (mouse-set-point ev)
  8199. (org-agenda-show))
  8200. (defun org-agenda-check-no-diary ()
  8201. "Check if the entry is a diary link and abort if yes."
  8202. (if (org-get-at-bol 'org-agenda-diary-link)
  8203. (org-agenda-error)))
  8204. (defun org-agenda-error ()
  8205. "Throw an error when a command is not allowed in the agenda."
  8206. (user-error "Command not allowed in this line"))
  8207. (defun org-agenda-tree-to-indirect-buffer (arg)
  8208. "Show the subtree corresponding to the current entry in an indirect buffer.
  8209. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8210. With a numerical prefix ARG, go up to this level and then take that tree.
  8211. With a negative numeric ARG, go up by this number of levels.
  8212. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8213. use the dedicated frame)."
  8214. (interactive "P")
  8215. (if current-prefix-arg
  8216. (org-agenda-do-tree-to-indirect-buffer arg)
  8217. (let ((agenda-buffer (buffer-name))
  8218. (agenda-window (selected-window))
  8219. (indirect-window
  8220. (and org-last-indirect-buffer
  8221. (get-buffer-window org-last-indirect-buffer))))
  8222. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8223. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8224. (eq org-indirect-buffer-display 'dedicated-frame))
  8225. (unwind-protect
  8226. (unless (and indirect-window (window-live-p indirect-window))
  8227. (setq indirect-window (split-window agenda-window)))
  8228. (and indirect-window (select-window indirect-window))
  8229. (switch-to-buffer org-last-indirect-buffer :norecord)
  8230. (fit-window-to-buffer indirect-window)))
  8231. (select-window (get-buffer-window agenda-buffer))
  8232. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8233. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8234. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8235. (org-agenda-check-no-diary)
  8236. (let* ((marker (or (org-get-at-bol 'org-marker)
  8237. (org-agenda-error)))
  8238. (buffer (marker-buffer marker))
  8239. (pos (marker-position marker)))
  8240. (with-current-buffer buffer
  8241. (save-excursion
  8242. (goto-char pos)
  8243. (funcall 'org-tree-to-indirect-buffer arg)))))
  8244. (defvar org-last-heading-marker (make-marker)
  8245. "Marker pointing to the headline that last changed its TODO state
  8246. by a remote command from the agenda.")
  8247. (defun org-agenda-todo-nextset ()
  8248. "Switch TODO entry to next sequence."
  8249. (interactive)
  8250. (org-agenda-todo 'nextset))
  8251. (defun org-agenda-todo-previousset ()
  8252. "Switch TODO entry to previous sequence."
  8253. (interactive)
  8254. (org-agenda-todo 'previousset))
  8255. (defun org-agenda-todo (&optional arg)
  8256. "Cycle TODO state of line at point, also in Org-mode file.
  8257. This changes the line at point, all other lines in the agenda referring to
  8258. the same tree node, and the headline of the tree node in the Org-mode file."
  8259. (interactive "P")
  8260. (org-agenda-check-no-diary)
  8261. (let* ((col (current-column))
  8262. (marker (or (org-get-at-bol 'org-marker)
  8263. (org-agenda-error)))
  8264. (buffer (marker-buffer marker))
  8265. (pos (marker-position marker))
  8266. (hdmarker (org-get-at-bol 'org-hd-marker))
  8267. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8268. (inhibit-read-only t)
  8269. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8270. (org-with-remote-undo buffer
  8271. (with-current-buffer buffer
  8272. (widen)
  8273. (goto-char pos)
  8274. (org-show-context 'agenda)
  8275. (save-excursion
  8276. (and (outline-next-heading)
  8277. (org-flag-heading nil))) ; show the next heading
  8278. (let ((current-prefix-arg arg))
  8279. (call-interactively 'org-todo))
  8280. (and (bolp) (forward-char 1))
  8281. (setq newhead (org-get-heading))
  8282. (when (and (org-bound-and-true-p
  8283. org-agenda-headline-snapshot-before-repeat)
  8284. (not (equal org-agenda-headline-snapshot-before-repeat
  8285. newhead))
  8286. todayp)
  8287. (setq newhead org-agenda-headline-snapshot-before-repeat
  8288. just-one t))
  8289. (save-excursion
  8290. (org-back-to-heading)
  8291. (move-marker org-last-heading-marker (point))))
  8292. (beginning-of-line 1)
  8293. (save-window-excursion
  8294. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8295. (when (org-bound-and-true-p org-clock-out-when-done)
  8296. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8297. newhead)
  8298. (org-agenda-unmark-clocking-task))
  8299. (org-move-to-column col)
  8300. (org-agenda-mark-clocking-task))))
  8301. (defun org-agenda-add-note (&optional arg)
  8302. "Add a time-stamped note to the entry at point."
  8303. (interactive "P")
  8304. (org-agenda-check-no-diary)
  8305. (let* ((marker (or (org-get-at-bol 'org-marker)
  8306. (org-agenda-error)))
  8307. (buffer (marker-buffer marker))
  8308. (pos (marker-position marker))
  8309. (hdmarker (org-get-at-bol 'org-hd-marker))
  8310. (inhibit-read-only t))
  8311. (with-current-buffer buffer
  8312. (widen)
  8313. (goto-char pos)
  8314. (org-show-context 'agenda)
  8315. (save-excursion
  8316. (and (outline-next-heading)
  8317. (org-flag-heading nil))) ; show the next heading
  8318. (org-add-note))))
  8319. (defun org-agenda-change-all-lines (newhead hdmarker
  8320. &optional fixface just-this)
  8321. "Change all lines in the agenda buffer which match HDMARKER.
  8322. The new content of the line will be NEWHEAD (as modified by
  8323. `org-agenda-format-item'). HDMARKER is checked with
  8324. `equal' against all `org-hd-marker' text properties in the file.
  8325. If FIXFACE is non-nil, the face of each item is modified according to
  8326. the new TODO state.
  8327. If JUST-THIS is non-nil, change just the current line, not all.
  8328. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8329. (let* ((inhibit-read-only t)
  8330. (line (org-current-line))
  8331. (org-agenda-buffer (current-buffer))
  8332. (thetags (with-current-buffer (marker-buffer hdmarker)
  8333. (save-excursion (save-restriction (widen)
  8334. (goto-char hdmarker)
  8335. (org-get-tags-at)))))
  8336. props m pl undone-face done-face finish new dotime level cat tags)
  8337. (save-excursion
  8338. (goto-char (point-max))
  8339. (beginning-of-line 1)
  8340. (while (not finish)
  8341. (setq finish (bobp))
  8342. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8343. (or (not just-this) (= (org-current-line) line))
  8344. (equal m hdmarker))
  8345. (setq props (text-properties-at (point))
  8346. dotime (org-get-at-bol 'dotime)
  8347. cat (org-get-at-eol 'org-category 1)
  8348. level (org-get-at-bol 'level)
  8349. tags thetags
  8350. new
  8351. (let ((org-prefix-format-compiled
  8352. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8353. org-prefix-format-compiled))
  8354. (extra (org-get-at-bol 'extra)))
  8355. (with-current-buffer (marker-buffer hdmarker)
  8356. (save-excursion
  8357. (save-restriction
  8358. (widen)
  8359. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8360. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8361. undone-face (org-get-at-bol 'undone-face)
  8362. done-face (org-get-at-bol 'done-face))
  8363. (beginning-of-line 1)
  8364. (cond
  8365. ((equal new "")
  8366. (and (looking-at ".*\n?") (replace-match "")))
  8367. ((looking-at ".*")
  8368. (replace-match new t t)
  8369. (beginning-of-line 1)
  8370. (add-text-properties (point-at-bol) (point-at-eol) props)
  8371. (when fixface
  8372. (add-text-properties
  8373. (point-at-bol) (point-at-eol)
  8374. (list 'face
  8375. (if org-last-todo-state-is-todo
  8376. undone-face done-face))))
  8377. (org-agenda-highlight-todo 'line)
  8378. (beginning-of-line 1))
  8379. (t (error "Line update did not work")))
  8380. (save-restriction
  8381. (narrow-to-region (point-at-bol) (point-at-eol))
  8382. (org-agenda-finalize)))
  8383. (beginning-of-line 0)))))
  8384. (defun org-agenda-align-tags (&optional line)
  8385. "Align all tags in agenda items to `org-agenda-tags-column'."
  8386. (let ((inhibit-read-only t) l c)
  8387. (save-excursion
  8388. (goto-char (if line (point-at-bol) (point-min)))
  8389. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8390. (if line (point-at-eol) nil) t)
  8391. (add-text-properties
  8392. (match-beginning 2) (match-end 2)
  8393. (list 'face (delq nil (let ((prop (get-text-property
  8394. (match-beginning 2) 'face)))
  8395. (or (listp prop) (setq prop (list prop)))
  8396. (if (memq 'org-tag prop)
  8397. prop
  8398. (cons 'org-tag prop))))))
  8399. (setq l (- (match-end 2) (match-beginning 2))
  8400. c (if (< org-agenda-tags-column 0)
  8401. (- (abs org-agenda-tags-column) l)
  8402. org-agenda-tags-column))
  8403. (delete-region (match-beginning 1) (match-end 1))
  8404. (goto-char (match-beginning 1))
  8405. (insert (org-add-props
  8406. (make-string (max 1 (- c (current-column))) ?\ )
  8407. (plist-put (copy-sequence (text-properties-at (point)))
  8408. 'face nil))))
  8409. (goto-char (point-min))
  8410. (org-font-lock-add-tag-faces (point-max)))))
  8411. (defun org-agenda-priority-up ()
  8412. "Increase the priority of line at point, also in Org-mode file."
  8413. (interactive)
  8414. (org-agenda-priority 'up))
  8415. (defun org-agenda-priority-down ()
  8416. "Decrease the priority of line at point, also in Org-mode file."
  8417. (interactive)
  8418. (org-agenda-priority 'down))
  8419. (defun org-agenda-priority (&optional force-direction)
  8420. "Set the priority of line at point, also in Org-mode file.
  8421. This changes the line at point, all other lines in the agenda referring to
  8422. the same tree node, and the headline of the tree node in the Org-mode file.
  8423. Called with a universal prefix arg, show the priority instead of setting it."
  8424. (interactive "P")
  8425. (if (equal force-direction '(4))
  8426. (org-show-priority)
  8427. (unless org-enable-priority-commands
  8428. (error "Priority commands are disabled"))
  8429. (org-agenda-check-no-diary)
  8430. (let* ((col (current-column))
  8431. (marker (or (org-get-at-bol 'org-marker)
  8432. (org-agenda-error)))
  8433. (hdmarker (org-get-at-bol 'org-hd-marker))
  8434. (buffer (marker-buffer hdmarker))
  8435. (pos (marker-position hdmarker))
  8436. (inhibit-read-only t)
  8437. newhead)
  8438. (org-with-remote-undo buffer
  8439. (with-current-buffer buffer
  8440. (widen)
  8441. (goto-char pos)
  8442. (org-show-context 'agenda)
  8443. (save-excursion
  8444. (and (outline-next-heading)
  8445. (org-flag-heading nil))) ; show the next heading
  8446. (funcall 'org-priority force-direction)
  8447. (end-of-line 1)
  8448. (setq newhead (org-get-heading)))
  8449. (org-agenda-change-all-lines newhead hdmarker)
  8450. (org-move-to-column col)))))
  8451. ;; FIXME: should fix the tags property of the agenda line.
  8452. (defun org-agenda-set-tags (&optional tag onoff)
  8453. "Set tags for the current headline."
  8454. (interactive)
  8455. (org-agenda-check-no-diary)
  8456. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8457. (call-interactively 'org-change-tag-in-region)
  8458. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8459. (org-agenda-error)))
  8460. (buffer (marker-buffer hdmarker))
  8461. (pos (marker-position hdmarker))
  8462. (inhibit-read-only t)
  8463. newhead)
  8464. (org-with-remote-undo buffer
  8465. (with-current-buffer buffer
  8466. (widen)
  8467. (goto-char pos)
  8468. (save-excursion
  8469. (org-show-context 'agenda))
  8470. (save-excursion
  8471. (and (outline-next-heading)
  8472. (org-flag-heading nil))) ; show the next heading
  8473. (goto-char pos)
  8474. (if tag
  8475. (org-toggle-tag tag onoff)
  8476. (call-interactively 'org-set-tags))
  8477. (end-of-line 1)
  8478. (setq newhead (org-get-heading)))
  8479. (org-agenda-change-all-lines newhead hdmarker)
  8480. (beginning-of-line 1)))))
  8481. (defun org-agenda-set-property ()
  8482. "Set a property for the current headline."
  8483. (interactive)
  8484. (org-agenda-check-no-diary)
  8485. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8486. (org-agenda-error)))
  8487. (buffer (marker-buffer hdmarker))
  8488. (pos (marker-position hdmarker))
  8489. (inhibit-read-only t)
  8490. newhead)
  8491. (org-with-remote-undo buffer
  8492. (with-current-buffer buffer
  8493. (widen)
  8494. (goto-char pos)
  8495. (save-excursion
  8496. (org-show-context 'agenda))
  8497. (save-excursion
  8498. (and (outline-next-heading)
  8499. (org-flag-heading nil))) ; show the next heading
  8500. (goto-char pos)
  8501. (call-interactively 'org-set-property)))))
  8502. (defun org-agenda-set-effort ()
  8503. "Set the effort property for the current headline."
  8504. (interactive)
  8505. (org-agenda-check-no-diary)
  8506. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8507. (org-agenda-error)))
  8508. (buffer (marker-buffer hdmarker))
  8509. (pos (marker-position hdmarker))
  8510. (inhibit-read-only t)
  8511. newhead)
  8512. (org-with-remote-undo buffer
  8513. (with-current-buffer buffer
  8514. (widen)
  8515. (goto-char pos)
  8516. (save-excursion
  8517. (org-show-context 'agenda))
  8518. (save-excursion
  8519. (and (outline-next-heading)
  8520. (org-flag-heading nil))) ; show the next heading
  8521. (goto-char pos)
  8522. (call-interactively 'org-set-effort)
  8523. (end-of-line 1)
  8524. (setq newhead (org-get-heading)))
  8525. (org-agenda-change-all-lines newhead hdmarker))))
  8526. (defun org-agenda-toggle-archive-tag ()
  8527. "Toggle the archive tag for the current entry."
  8528. (interactive)
  8529. (org-agenda-check-no-diary)
  8530. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8531. (org-agenda-error)))
  8532. (buffer (marker-buffer hdmarker))
  8533. (pos (marker-position hdmarker))
  8534. (inhibit-read-only t)
  8535. newhead)
  8536. (org-with-remote-undo buffer
  8537. (with-current-buffer buffer
  8538. (widen)
  8539. (goto-char pos)
  8540. (org-show-context 'agenda)
  8541. (save-excursion
  8542. (and (outline-next-heading)
  8543. (org-flag-heading nil))) ; show the next heading
  8544. (call-interactively 'org-toggle-archive-tag)
  8545. (end-of-line 1)
  8546. (setq newhead (org-get-heading)))
  8547. (org-agenda-change-all-lines newhead hdmarker)
  8548. (beginning-of-line 1))))
  8549. (defun org-agenda-do-date-later (arg)
  8550. (interactive "P")
  8551. (cond
  8552. ((or (equal arg '(16))
  8553. (memq last-command
  8554. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8555. (setq this-command 'org-agenda-date-later-minutes)
  8556. (org-agenda-date-later-minutes 1))
  8557. ((or (equal arg '(4))
  8558. (memq last-command
  8559. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8560. (setq this-command 'org-agenda-date-later-hours)
  8561. (org-agenda-date-later-hours 1))
  8562. (t
  8563. (org-agenda-date-later (prefix-numeric-value arg)))))
  8564. (defun org-agenda-do-date-earlier (arg)
  8565. (interactive "P")
  8566. (cond
  8567. ((or (equal arg '(16))
  8568. (memq last-command
  8569. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8570. (setq this-command 'org-agenda-date-earlier-minutes)
  8571. (org-agenda-date-earlier-minutes 1))
  8572. ((or (equal arg '(4))
  8573. (memq last-command
  8574. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8575. (setq this-command 'org-agenda-date-earlier-hours)
  8576. (org-agenda-date-earlier-hours 1))
  8577. (t
  8578. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8579. (defun org-agenda-date-later (arg &optional what)
  8580. "Change the date of this item to ARG day(s) later."
  8581. (interactive "p")
  8582. (org-agenda-check-type t 'agenda 'timeline)
  8583. (org-agenda-check-no-diary)
  8584. (let* ((marker (or (org-get-at-bol 'org-marker)
  8585. (org-agenda-error)))
  8586. (buffer (marker-buffer marker))
  8587. (pos (marker-position marker))
  8588. cdate today)
  8589. (org-with-remote-undo buffer
  8590. (with-current-buffer buffer
  8591. (widen)
  8592. (goto-char pos)
  8593. (if (not (org-at-timestamp-p))
  8594. (error "Cannot find time stamp"))
  8595. (when (and org-agenda-move-date-from-past-immediately-to-today
  8596. (equal arg 1)
  8597. (or (not what) (eq what 'day))
  8598. (not (save-match-data (org-at-date-range-p))))
  8599. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8600. cdate (calendar-absolute-from-gregorian
  8601. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8602. today (org-today))
  8603. (if (> today cdate)
  8604. ;; immediately shift to today
  8605. (setq arg (- today cdate))))
  8606. (org-timestamp-change arg (or what 'day))
  8607. (when (and (org-at-date-range-p)
  8608. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8609. (let ((end org-last-changed-timestamp))
  8610. (org-timestamp-change arg (or what 'day))
  8611. (setq org-last-changed-timestamp
  8612. (concat org-last-changed-timestamp "--" end)))))
  8613. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8614. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8615. (defun org-agenda-date-earlier (arg &optional what)
  8616. "Change the date of this item to ARG day(s) earlier."
  8617. (interactive "p")
  8618. (org-agenda-date-later (- arg) what))
  8619. (defun org-agenda-date-later-minutes (arg)
  8620. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8621. (interactive "p")
  8622. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8623. (org-agenda-date-later arg 'minute))
  8624. (defun org-agenda-date-earlier-minutes (arg)
  8625. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8626. (interactive "p")
  8627. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8628. (org-agenda-date-earlier arg 'minute))
  8629. (defun org-agenda-date-later-hours (arg)
  8630. "Change the time of this item, in hour steps."
  8631. (interactive "p")
  8632. (org-agenda-date-later arg 'hour))
  8633. (defun org-agenda-date-earlier-hours (arg)
  8634. "Change the time of this item, in hour steps."
  8635. (interactive "p")
  8636. (org-agenda-date-earlier arg 'hour))
  8637. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8638. "Show new date stamp via text properties."
  8639. ;; We use text properties to make this undoable
  8640. (let ((inhibit-read-only t))
  8641. (setq stamp (concat prefix " => " stamp " "))
  8642. (save-excursion
  8643. (goto-char (point-max))
  8644. (while (not (bobp))
  8645. (when (equal marker (org-get-at-bol 'org-marker))
  8646. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8647. (org-move-to-column (- (window-width) (length stamp)) t)
  8648. (if (featurep 'xemacs)
  8649. ;; Use `duplicable' property to trigger undo recording
  8650. (let ((ex (make-extent nil nil))
  8651. (gl (make-glyph stamp)))
  8652. (set-glyph-face gl 'secondary-selection)
  8653. (set-extent-properties
  8654. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8655. (insert-extent ex (1- (point)) (point-at-eol)))
  8656. (add-text-properties
  8657. (1- (point)) (point-at-eol)
  8658. (list 'display (org-add-props stamp nil
  8659. 'face '(secondary-selection default)))))
  8660. (beginning-of-line 1))
  8661. (beginning-of-line 0)))))
  8662. (defun org-agenda-date-prompt (arg)
  8663. "Change the date of this item. Date is prompted for, with default today.
  8664. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8665. be used to request time specification in the time stamp."
  8666. (interactive "P")
  8667. (org-agenda-check-type t 'agenda 'timeline)
  8668. (org-agenda-check-no-diary)
  8669. (let* ((marker (or (org-get-at-bol 'org-marker)
  8670. (org-agenda-error)))
  8671. (buffer (marker-buffer marker))
  8672. (pos (marker-position marker)))
  8673. (org-with-remote-undo buffer
  8674. (with-current-buffer buffer
  8675. (widen)
  8676. (goto-char pos)
  8677. (if (not (org-at-timestamp-p t))
  8678. (error "Cannot find time stamp"))
  8679. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8680. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8681. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8682. (defun org-agenda-schedule (arg &optional time)
  8683. "Schedule the item at point.
  8684. ARG is passed through to `org-schedule'."
  8685. (interactive "P")
  8686. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8687. (org-agenda-check-no-diary)
  8688. (let* ((marker (or (org-get-at-bol 'org-marker)
  8689. (org-agenda-error)))
  8690. (type (marker-insertion-type marker))
  8691. (buffer (marker-buffer marker))
  8692. (pos (marker-position marker))
  8693. ts)
  8694. (set-marker-insertion-type marker t)
  8695. (org-with-remote-undo buffer
  8696. (with-current-buffer buffer
  8697. (widen)
  8698. (goto-char pos)
  8699. (setq ts (org-schedule arg time)))
  8700. (org-agenda-show-new-time marker ts " S"))
  8701. (message "%s" ts)))
  8702. (defun org-agenda-deadline (arg &optional time)
  8703. "Schedule the item at point.
  8704. ARG is passed through to `org-deadline'."
  8705. (interactive "P")
  8706. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8707. (org-agenda-check-no-diary)
  8708. (let* ((marker (or (org-get-at-bol 'org-marker)
  8709. (org-agenda-error)))
  8710. (buffer (marker-buffer marker))
  8711. (pos (marker-position marker))
  8712. ts)
  8713. (org-with-remote-undo buffer
  8714. (with-current-buffer buffer
  8715. (widen)
  8716. (goto-char pos)
  8717. (setq ts (org-deadline arg time)))
  8718. (org-agenda-show-new-time marker ts " D"))
  8719. (message "%s" ts)))
  8720. (defun org-agenda-clock-in (&optional arg)
  8721. "Start the clock on the currently selected item."
  8722. (interactive "P")
  8723. (org-agenda-check-no-diary)
  8724. (if (equal arg '(4))
  8725. (org-clock-in arg)
  8726. (let* ((marker (or (org-get-at-bol 'org-marker)
  8727. (org-agenda-error)))
  8728. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8729. (pos (marker-position marker))
  8730. (col (current-column))
  8731. newhead)
  8732. (org-with-remote-undo (marker-buffer marker)
  8733. (with-current-buffer (marker-buffer marker)
  8734. (widen)
  8735. (goto-char pos)
  8736. (org-show-context 'agenda)
  8737. (org-show-entry)
  8738. (org-cycle-hide-drawers 'children)
  8739. (org-clock-in arg)
  8740. (setq newhead (org-get-heading)))
  8741. (org-agenda-change-all-lines newhead hdmarker))
  8742. (org-move-to-column col))))
  8743. (defun org-agenda-clock-out ()
  8744. "Stop the currently running clock."
  8745. (interactive)
  8746. (unless (marker-buffer org-clock-marker)
  8747. (error "No running clock"))
  8748. (let ((marker (make-marker)) (col (current-column)) newhead)
  8749. (org-with-remote-undo (marker-buffer org-clock-marker)
  8750. (with-current-buffer (marker-buffer org-clock-marker)
  8751. (save-excursion
  8752. (save-restriction
  8753. (widen)
  8754. (goto-char org-clock-marker)
  8755. (org-back-to-heading t)
  8756. (move-marker marker (point))
  8757. (org-clock-out)
  8758. (setq newhead (org-get-heading))))))
  8759. (org-agenda-change-all-lines newhead marker)
  8760. (move-marker marker nil)
  8761. (org-move-to-column col)
  8762. (org-agenda-unmark-clocking-task)))
  8763. (defun org-agenda-clock-cancel (&optional arg)
  8764. "Cancel the currently running clock."
  8765. (interactive "P")
  8766. (unless (marker-buffer org-clock-marker)
  8767. (user-error "No running clock"))
  8768. (org-with-remote-undo (marker-buffer org-clock-marker)
  8769. (org-clock-cancel)))
  8770. (defun org-agenda-clock-goto ()
  8771. "Jump to the currently clocked in task within the agenda.
  8772. If the currently clocked in task is not listed in the agenda
  8773. buffer, display it in another window."
  8774. (interactive)
  8775. (let (pos)
  8776. (mapc (lambda (o)
  8777. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8778. (setq pos (overlay-start o))))
  8779. (overlays-in (point-min) (point-max)))
  8780. (cond (pos (goto-char pos))
  8781. ;; If the currently clocked entry is not in the agenda
  8782. ;; buffer, we visit it in another window:
  8783. (org-clock-current-task
  8784. (org-switch-to-buffer-other-window (org-clock-goto)))
  8785. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8786. (defun org-agenda-diary-entry-in-org-file ()
  8787. "Make a diary entry in the file `org-agenda-diary-file'."
  8788. (let (d1 d2 char (text "") dp1 dp2)
  8789. (if (equal (buffer-name) "*Calendar*")
  8790. (setq d1 (calendar-cursor-to-date t)
  8791. d2 (car calendar-mark-ring))
  8792. (setq dp1 (get-text-property (point-at-bol) 'day))
  8793. (unless dp1 (user-error "No date defined in current line"))
  8794. (setq d1 (calendar-gregorian-from-absolute dp1)
  8795. d2 (and (ignore-errors (mark))
  8796. (save-excursion
  8797. (goto-char (mark))
  8798. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8799. (calendar-gregorian-from-absolute dp2))))
  8800. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8801. (setq char (read-char-exclusive))
  8802. (cond
  8803. ((equal char ?d)
  8804. (setq text (read-string "Day entry: "))
  8805. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8806. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8807. ((equal char ?a)
  8808. (setq d1 (list (car d1) (nth 1 d1)
  8809. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8810. (nth 2 d1))))
  8811. (setq text (read-string "Anniversary (use %d to show years): "))
  8812. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8813. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8814. ((equal char ?b)
  8815. (setq text (read-string "Block entry: "))
  8816. (unless (and d1 d2 (not (equal d1 d2)))
  8817. (user-error "No block of days selected"))
  8818. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8819. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8820. ((equal char ?j)
  8821. (org-switch-to-buffer-other-window
  8822. (find-file-noselect org-agenda-diary-file))
  8823. (require 'org-datetree)
  8824. (org-datetree-find-date-create d1)
  8825. (org-reveal t))
  8826. (t (user-error "Invalid selection character `%c'" char)))))
  8827. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8828. "Where in `org-agenda-diary-file' should new entries be added?
  8829. Valid values:
  8830. date-tree in the date tree, as first child of the date
  8831. date-tree-last in the date tree, as last child of the date
  8832. top-level as top-level entries at the end of the file."
  8833. :group 'org-agenda
  8834. :type '(choice
  8835. (const :tag "first in a date tree" date-tree)
  8836. (const :tag "last in a date tree" date-tree-last)
  8837. (const :tag "as top level at end of file" top-level)))
  8838. (defcustom org-agenda-insert-diary-extract-time nil
  8839. "Non-nil means extract any time specification from the diary entry."
  8840. :group 'org-agenda
  8841. :version "24.1"
  8842. :type 'boolean)
  8843. (defcustom org-agenda-bulk-mark-char ">"
  8844. "A single-character string to be used as the bulk mark."
  8845. :group 'org-agenda
  8846. :version "24.1"
  8847. :type 'string)
  8848. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8849. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8850. If TEXT is not empty, it will become the headline of the new entry, and
  8851. the resulting entry will not be shown. When TEXT is empty, switch to
  8852. `org-agenda-diary-file' and let the user finish the entry there."
  8853. (let ((cw (current-window-configuration)))
  8854. (org-switch-to-buffer-other-window
  8855. (find-file-noselect org-agenda-diary-file))
  8856. (widen)
  8857. (goto-char (point-min))
  8858. (cond
  8859. ((eq type 'anniversary)
  8860. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8861. (progn
  8862. (or (org-at-heading-p t)
  8863. (progn
  8864. (outline-next-heading)
  8865. (insert "* Anniversaries\n\n")
  8866. (beginning-of-line -1)))))
  8867. (outline-next-heading)
  8868. (org-back-over-empty-lines)
  8869. (backward-char 1)
  8870. (insert "\n")
  8871. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8872. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8873. ((eq type 'day)
  8874. (let ((org-prefix-has-time t)
  8875. (org-agenda-time-leading-zero t)
  8876. fmt time time2)
  8877. (if org-agenda-insert-diary-extract-time
  8878. ;; Use org-agenda-format-item to parse text for a time-range and
  8879. ;; remove it. FIXME: This is a hack, we should refactor
  8880. ;; that function to make time extraction available separately
  8881. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8882. time (get-text-property 0 'time fmt)
  8883. time2 (if (> (length time) 0)
  8884. ;; split-string removes trailing ...... if
  8885. ;; no end time given. First space
  8886. ;; separates time from date.
  8887. (concat " " (car (split-string time "\\.")))
  8888. nil)
  8889. text (get-text-property 0 'txt fmt)))
  8890. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8891. (org-agenda-insert-diary-as-top-level text)
  8892. (require 'org-datetree)
  8893. (org-datetree-find-date-create d1)
  8894. (org-agenda-insert-diary-make-new-entry text))
  8895. (org-insert-time-stamp (org-time-from-absolute
  8896. (calendar-absolute-from-gregorian d1))
  8897. nil nil nil nil time2))
  8898. (end-of-line 0))
  8899. ((eq type 'block)
  8900. (if (> (calendar-absolute-from-gregorian d1)
  8901. (calendar-absolute-from-gregorian d2))
  8902. (setq d1 (prog1 d2 (setq d2 d1))))
  8903. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8904. (org-agenda-insert-diary-as-top-level text)
  8905. (require 'org-datetree)
  8906. (org-datetree-find-date-create d1)
  8907. (org-agenda-insert-diary-make-new-entry text))
  8908. (org-insert-time-stamp (org-time-from-absolute
  8909. (calendar-absolute-from-gregorian d1)))
  8910. (insert "--")
  8911. (org-insert-time-stamp (org-time-from-absolute
  8912. (calendar-absolute-from-gregorian d2)))
  8913. (end-of-line 0)))
  8914. (if (string-match "\\S-" text)
  8915. (progn
  8916. (set-window-configuration cw)
  8917. (message "%s entry added to %s"
  8918. (capitalize (symbol-name type))
  8919. (abbreviate-file-name org-agenda-diary-file)))
  8920. (org-reveal t)
  8921. (message "Please finish entry here"))))
  8922. (defun org-agenda-insert-diary-as-top-level (text)
  8923. "Make new entry as a top-level entry at the end of the file.
  8924. Add TEXT as headline, and position the cursor in the second line so that
  8925. a timestamp can be added there."
  8926. (widen)
  8927. (goto-char (point-max))
  8928. (unless (bolp) (insert "\n"))
  8929. (org-insert-heading nil t t)
  8930. (insert text)
  8931. (org-end-of-meta-data)
  8932. (unless (bolp) (insert "\n"))
  8933. (when org-adapt-indentation (org-indent-to-column 2)))
  8934. (defun org-agenda-insert-diary-make-new-entry (text)
  8935. "Make a new entry with TEXT as a child of the current subtree.
  8936. Position the point in the heading's first body line so that
  8937. a timestamp can be added there."
  8938. (cond
  8939. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  8940. (end-of-line)
  8941. (org-insert-heading '(4) t)
  8942. (org-do-demote))
  8943. (t
  8944. (outline-next-heading)
  8945. (org-back-over-empty-lines)
  8946. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  8947. (org-insert-heading nil t)
  8948. (org-do-demote)))
  8949. (let ((col (current-column)))
  8950. (insert text)
  8951. (org-end-of-meta-data)
  8952. ;; Ensure point is left on a blank line, at proper indentation.
  8953. (unless (bolp) (insert "\n"))
  8954. (unless (org-looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  8955. (when org-adapt-indentation (org-indent-to-column col)))
  8956. (org-show-set-visibility 'lineage))
  8957. (defun org-agenda-diary-entry ()
  8958. "Make a diary entry, like the `i' command from the calendar.
  8959. All the standard commands work: block, weekly etc.
  8960. When `org-agenda-diary-file' points to a file,
  8961. `org-agenda-diary-entry-in-org-file' is called instead to create
  8962. entries in that Org-mode file."
  8963. (interactive)
  8964. (if (not (eq org-agenda-diary-file 'diary-file))
  8965. (org-agenda-diary-entry-in-org-file)
  8966. (require 'diary-lib)
  8967. (let* ((char (progn
  8968. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8969. (read-char-exclusive)))
  8970. (cmd (cdr (assoc char
  8971. '((?d . diary-insert-entry)
  8972. (?w . diary-insert-weekly-entry)
  8973. (?m . diary-insert-monthly-entry)
  8974. (?y . diary-insert-yearly-entry)
  8975. (?a . diary-insert-anniversary-entry)
  8976. (?b . diary-insert-block-entry)
  8977. (?c . diary-insert-cyclic-entry)))))
  8978. (oldf (symbol-function 'calendar-cursor-to-date))
  8979. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8980. (point (point))
  8981. (mark (or (mark t) (point))))
  8982. (unless cmd
  8983. (user-error "No command associated with <%c>" char))
  8984. (unless (and (get-text-property point 'day)
  8985. (or (not (equal ?b char))
  8986. (get-text-property mark 'day)))
  8987. (user-error "Don't know which date to use for diary entry"))
  8988. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8989. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8990. (let ((calendar-mark-ring
  8991. (list (calendar-gregorian-from-absolute
  8992. (or (get-text-property mark 'day)
  8993. (get-text-property point 'day))))))
  8994. (unwind-protect
  8995. (progn
  8996. (fset 'calendar-cursor-to-date
  8997. (lambda (&optional error dummy)
  8998. (calendar-gregorian-from-absolute
  8999. (get-text-property point 'day))))
  9000. (call-interactively cmd))
  9001. (fset 'calendar-cursor-to-date oldf))))))
  9002. (defun org-agenda-execute-calendar-command (cmd)
  9003. "Execute a calendar command from the agenda with date from cursor."
  9004. (org-agenda-check-type t 'agenda 'timeline)
  9005. (require 'diary-lib)
  9006. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  9007. (user-error "Don't know which date to use for the calendar command"))
  9008. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  9009. (point (point))
  9010. (date (calendar-gregorian-from-absolute
  9011. (get-text-property point 'day)))
  9012. ;; the following 2 vars are needed in the calendar
  9013. (displayed-month (car date))
  9014. (displayed-year (nth 2 date)))
  9015. (unwind-protect
  9016. (progn
  9017. (fset 'calendar-cursor-to-date
  9018. (lambda (&optional error dummy)
  9019. (calendar-gregorian-from-absolute
  9020. (get-text-property point 'day))))
  9021. (call-interactively cmd))
  9022. (fset 'calendar-cursor-to-date oldf))))
  9023. (defun org-agenda-phases-of-moon ()
  9024. "Display the phases of the moon for the 3 months around the cursor date."
  9025. (interactive)
  9026. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  9027. (defun org-agenda-holidays ()
  9028. "Display the holidays for the 3 months around the cursor date."
  9029. (interactive)
  9030. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  9031. (defvar calendar-longitude) ; defined in calendar.el
  9032. (defvar calendar-latitude) ; defined in calendar.el
  9033. (defvar calendar-location-name) ; defined in calendar.el
  9034. (defun org-agenda-sunrise-sunset (arg)
  9035. "Display sunrise and sunset for the cursor date.
  9036. Latitude and longitude can be specified with the variables
  9037. `calendar-latitude' and `calendar-longitude'. When called with prefix
  9038. argument, latitude and longitude will be prompted for."
  9039. (interactive "P")
  9040. (require 'solar)
  9041. (let ((calendar-longitude (if arg nil calendar-longitude))
  9042. (calendar-latitude (if arg nil calendar-latitude))
  9043. (calendar-location-name
  9044. (if arg "the given coordinates" calendar-location-name)))
  9045. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  9046. (defun org-agenda-goto-calendar ()
  9047. "Open the Emacs calendar with the date at the cursor."
  9048. (interactive)
  9049. (org-agenda-check-type t 'agenda 'timeline)
  9050. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  9051. (user-error "Don't know which date to open in calendar")))
  9052. (date (calendar-gregorian-from-absolute day))
  9053. (calendar-move-hook nil)
  9054. (calendar-view-holidays-initially-flag nil)
  9055. (calendar-view-diary-initially-flag nil))
  9056. (calendar)
  9057. (calendar-goto-date date)))
  9058. ;;;###autoload
  9059. (defun org-calendar-goto-agenda ()
  9060. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  9061. This is a command that has to be installed in `calendar-mode-map'."
  9062. (interactive)
  9063. ;; Temporarily disable sticky agenda since user clearly wants to
  9064. ;; refresh view anyway.
  9065. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  9066. (org-agenda-sticky nil))
  9067. (org-agenda-list nil (calendar-absolute-from-gregorian
  9068. (calendar-cursor-to-date))
  9069. nil)))
  9070. (defun org-agenda-convert-date ()
  9071. (interactive)
  9072. (org-agenda-check-type t 'agenda 'timeline)
  9073. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9074. date s)
  9075. (unless day
  9076. (user-error "Don't know which date to convert"))
  9077. (setq date (calendar-gregorian-from-absolute day))
  9078. (setq s (concat
  9079. "Gregorian: " (calendar-date-string date) "\n"
  9080. "ISO: " (calendar-iso-date-string date) "\n"
  9081. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9082. "Julian: " (calendar-julian-date-string date) "\n"
  9083. "Astron. JD: " (calendar-astro-date-string date)
  9084. " (Julian date number at noon UTC)\n"
  9085. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9086. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9087. "French: " (calendar-french-date-string date) "\n"
  9088. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9089. "Mayan: " (calendar-mayan-date-string date) "\n"
  9090. "Coptic: " (calendar-coptic-date-string date) "\n"
  9091. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9092. "Persian: " (calendar-persian-date-string date) "\n"
  9093. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9094. (with-output-to-temp-buffer "*Dates*"
  9095. (princ s))
  9096. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9097. ;;; Bulk commands
  9098. (defun org-agenda-bulk-marked-p ()
  9099. (eq (get-char-property (point-at-bol) 'type)
  9100. 'org-marked-entry-overlay))
  9101. (defun org-agenda-bulk-mark (&optional arg)
  9102. "Mark the entry at point for future bulk action."
  9103. (interactive "p")
  9104. (dotimes (i (or arg 1))
  9105. (unless (org-get-at-bol 'org-agenda-diary-link)
  9106. (let* ((m (org-get-at-bol 'org-hd-marker))
  9107. ov)
  9108. (unless (org-agenda-bulk-marked-p)
  9109. (unless m (user-error "Nothing to mark at point"))
  9110. (push m org-agenda-bulk-marked-entries)
  9111. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9112. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9113. (org-get-todo-face "TODO")
  9114. 'evaporate)
  9115. (overlay-put ov 'type 'org-marked-entry-overlay))
  9116. (end-of-line 1)
  9117. (or (ignore-errors
  9118. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9119. (beginning-of-line 2))
  9120. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9121. (beginning-of-line 2))
  9122. (message "%d entries marked for bulk action"
  9123. (length org-agenda-bulk-marked-entries))))))
  9124. (defun org-agenda-bulk-mark-all ()
  9125. "Mark all entries for future agenda bulk action."
  9126. (interactive)
  9127. (org-agenda-bulk-mark-regexp "."))
  9128. (defun org-agenda-bulk-mark-regexp (regexp)
  9129. "Mark entries matching REGEXP for future agenda bulk action."
  9130. (interactive "sMark entries matching regexp: ")
  9131. (let ((entries-marked 0) txt-at-point)
  9132. (save-excursion
  9133. (goto-char (point-min))
  9134. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9135. (while (and (re-search-forward regexp nil t)
  9136. (setq txt-at-point (get-text-property (point) 'txt)))
  9137. (when (string-match regexp txt-at-point)
  9138. (setq entries-marked (1+ entries-marked))
  9139. (call-interactively 'org-agenda-bulk-mark))))
  9140. (if (not entries-marked)
  9141. (message "No entry matching this regexp."))))
  9142. (defun org-agenda-bulk-unmark (&optional arg)
  9143. "Unmark the entry at point for future bulk action."
  9144. (interactive "P")
  9145. (if arg
  9146. (org-agenda-bulk-unmark-all)
  9147. (cond ((org-agenda-bulk-marked-p)
  9148. (org-agenda-bulk-remove-overlays
  9149. (point-at-bol) (+ 2 (point-at-bol)))
  9150. (setq org-agenda-bulk-marked-entries
  9151. (delete (org-get-at-bol 'org-hd-marker)
  9152. org-agenda-bulk-marked-entries))
  9153. (end-of-line 1)
  9154. (or (ignore-errors
  9155. (goto-char (next-single-property-change (point) 'txt)))
  9156. (beginning-of-line 2))
  9157. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9158. (beginning-of-line 2))
  9159. (message "%d entries left marked for bulk action"
  9160. (length org-agenda-bulk-marked-entries)))
  9161. (t (message "No entry to unmark here")))))
  9162. (defun org-agenda-bulk-toggle-all ()
  9163. "Toggle all marks for bulk action."
  9164. (interactive)
  9165. (save-excursion
  9166. (goto-char (point-min))
  9167. (while (ignore-errors
  9168. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9169. (org-agenda-bulk-toggle))))
  9170. (defun org-agenda-bulk-toggle ()
  9171. "Toggle the mark at point for bulk action."
  9172. (interactive)
  9173. (if (org-agenda-bulk-marked-p)
  9174. (org-agenda-bulk-unmark)
  9175. (org-agenda-bulk-mark)))
  9176. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9177. "Remove the mark overlays between BEG and END in the agenda buffer.
  9178. BEG and END default to the buffer limits.
  9179. This only removes the overlays, it does not remove the markers
  9180. from the list in `org-agenda-bulk-marked-entries'."
  9181. (interactive)
  9182. (mapc (lambda (ov)
  9183. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9184. (delete-overlay ov)))
  9185. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9186. (defun org-agenda-bulk-unmark-all ()
  9187. "Remove all marks in the agenda buffer.
  9188. This will remove the markers and the overlays."
  9189. (interactive)
  9190. (if (null org-agenda-bulk-marked-entries)
  9191. (message "No entry to unmark")
  9192. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9193. (setq org-agenda-bulk-marked-entries nil)
  9194. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9195. (defcustom org-agenda-persistent-marks nil
  9196. "Non-nil means marked items will stay marked after a bulk action.
  9197. You can toggle this interactively by typing `p' when prompted for a
  9198. bulk action."
  9199. :group 'org-agenda
  9200. :version "24.1"
  9201. :type 'boolean)
  9202. (defun org-agenda-bulk-action (&optional arg)
  9203. "Execute an remote-editing action on all marked entries.
  9204. The prefix arg is passed through to the command if possible."
  9205. (interactive "P")
  9206. ;; Make sure we have markers, and only valid ones
  9207. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9208. (mapc
  9209. (lambda (m)
  9210. (unless (and (markerp m)
  9211. (marker-buffer m)
  9212. (buffer-live-p (marker-buffer m))
  9213. (marker-position m))
  9214. (user-error "Marker %s for bulk command is invalid" m)))
  9215. org-agenda-bulk-marked-entries)
  9216. ;; Prompt for the bulk command
  9217. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9218. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9219. "[S]catter [f]unction "
  9220. (when org-agenda-bulk-custom-functions
  9221. (concat " Custom: ["
  9222. (mapconcat (lambda(f) (char-to-string (car f)))
  9223. org-agenda-bulk-custom-functions "")
  9224. "]"))))
  9225. (catch 'exit
  9226. (let* ((action (read-char-exclusive))
  9227. (org-log-refile (if org-log-refile 'time nil))
  9228. (entries (reverse org-agenda-bulk-marked-entries))
  9229. (org-overriding-default-time
  9230. (if (get-text-property (point) 'org-agenda-date-header)
  9231. (org-get-cursor-date)))
  9232. redo-at-end
  9233. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9234. (cond
  9235. ((equal action ?p)
  9236. (let ((org-agenda-persistent-marks
  9237. (not org-agenda-persistent-marks)))
  9238. (org-agenda-bulk-action)
  9239. (throw 'exit nil)))
  9240. ((equal action ?$)
  9241. (setq cmd '(org-agenda-archive)))
  9242. ((equal action ?A)
  9243. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9244. ((member action '(?r ?w))
  9245. (setq rfloc (org-refile-get-location
  9246. "Refile to"
  9247. (marker-buffer (car entries))
  9248. org-refile-allow-creating-parent-nodes))
  9249. (if (nth 3 rfloc)
  9250. (setcar (nthcdr 3 rfloc)
  9251. (move-marker (make-marker) (nth 3 rfloc)
  9252. (or (get-file-buffer (nth 1 rfloc))
  9253. (find-buffer-visiting (nth 1 rfloc))
  9254. (error "This should not happen")))))
  9255. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9256. redo-at-end t))
  9257. ((equal action ?t)
  9258. (setq state (completing-read
  9259. "Todo state: "
  9260. (with-current-buffer (marker-buffer (car entries))
  9261. (mapcar #'list org-todo-keywords-1))))
  9262. (setq cmd `(let ((org-inhibit-blocking t)
  9263. (org-inhibit-logging 'note))
  9264. (org-agenda-todo ,state))))
  9265. ((memq action '(?- ?+))
  9266. (setq tag (completing-read
  9267. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9268. (with-current-buffer (marker-buffer (car entries))
  9269. (delq nil
  9270. (mapcar (lambda (x) (and (stringp (car x)) x))
  9271. org-current-tag-alist)))))
  9272. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9273. ((memq action '(?s ?d))
  9274. (let* ((time
  9275. (unless arg
  9276. (org-read-date
  9277. nil nil nil
  9278. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9279. org-overriding-default-time)))
  9280. (c1 (if (eq action ?s) 'org-agenda-schedule
  9281. 'org-agenda-deadline)))
  9282. ;; Make sure to not prompt for a note when bulk
  9283. ;; rescheduling as Org cannot cope with simultaneous Org.
  9284. ;; Besides, it could be annoying depending on the number
  9285. ;; of items re-scheduled.
  9286. (setq cmd `(eval '(let ((org-log-reschedule
  9287. (and org-log-reschedule 'time)))
  9288. (,c1 arg ,time))))))
  9289. ((equal action ?S)
  9290. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9291. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9292. (let ((days (read-number
  9293. (format "Scatter tasks across how many %sdays: "
  9294. (if arg "week" "")) 7)))
  9295. (setq cmd
  9296. `(let ((distance (1+ (random ,days))))
  9297. (if arg
  9298. (let ((dist distance)
  9299. (day-of-week
  9300. (calendar-day-of-week
  9301. (calendar-gregorian-from-absolute (org-today)))))
  9302. (dotimes (i (1+ dist))
  9303. (while (member day-of-week org-agenda-weekend-days)
  9304. (incf distance)
  9305. (incf day-of-week)
  9306. (if (= day-of-week 7)
  9307. (setq day-of-week 0)))
  9308. (incf day-of-week)
  9309. (if (= day-of-week 7)
  9310. (setq day-of-week 0)))))
  9311. ;; silently fail when try to replan a sexp entry
  9312. (condition-case nil
  9313. (let* ((date (calendar-gregorian-from-absolute
  9314. (+ (org-today) distance)))
  9315. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9316. (nth 2 date))))
  9317. (org-agenda-schedule nil time))
  9318. (error nil)))))))
  9319. ((assoc action org-agenda-bulk-custom-functions)
  9320. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9321. redo-at-end t))
  9322. ((equal action ?f)
  9323. (setq cmd (list (intern
  9324. (completing-read "Function: "
  9325. obarray 'fboundp t nil nil)))))
  9326. (t (user-error "Invalid bulk action")))
  9327. ;; Sort the markers, to make sure that parents are handled before children
  9328. (setq entries (sort entries
  9329. (lambda (a b)
  9330. (cond
  9331. ((equal (marker-buffer a) (marker-buffer b))
  9332. (< (marker-position a) (marker-position b)))
  9333. (t
  9334. (string< (buffer-name (marker-buffer a))
  9335. (buffer-name (marker-buffer b))))))))
  9336. ;; Now loop over all markers and apply cmd
  9337. (while (setq e (pop entries))
  9338. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9339. (if (not pos)
  9340. (progn (message "Skipping removed entry at %s" e)
  9341. (setq cntskip (1+ cntskip)))
  9342. (goto-char pos)
  9343. (let (org-loop-over-headlines-in-active-region)
  9344. (eval cmd))
  9345. ;; `post-command-hook' is not run yet. We make sure any
  9346. ;; pending log note is processed.
  9347. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9348. (memq 'org-add-log-note post-command-hook))
  9349. (org-add-log-note))
  9350. (setq cnt (1+ cnt))))
  9351. (when redo-at-end (org-agenda-redo))
  9352. (unless org-agenda-persistent-marks
  9353. (org-agenda-bulk-unmark-all))
  9354. (message "Acted on %d entries%s%s"
  9355. cnt
  9356. (if (= cntskip 0)
  9357. ""
  9358. (format ", skipped %d (disappeared before their turn)"
  9359. cntskip))
  9360. (if (not org-agenda-persistent-marks)
  9361. "" " (kept marked)"))))))
  9362. (defun org-agenda-capture (&optional with-time)
  9363. "Call `org-capture' with the date at point.
  9364. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9365. current HH:MM time."
  9366. (interactive "P")
  9367. (if (not (eq major-mode 'org-agenda-mode))
  9368. (user-error "You cannot do this outside of agenda buffers")
  9369. (let ((org-overriding-default-time
  9370. (org-get-cursor-date (equal with-time 1))))
  9371. (call-interactively 'org-capture))))
  9372. ;;; Dragging agenda lines forward/backward
  9373. (defun org-agenda-reapply-filters ()
  9374. "Re-apply all agenda filters."
  9375. (mapcar
  9376. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9377. `((,org-agenda-tag-filter tag)
  9378. (,org-agenda-category-filter category)
  9379. (,org-agenda-regexp-filter regexp)
  9380. (,org-agenda-effort-filter effort)
  9381. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9382. (,(get 'org-agenda-category-filter :preset-filter) category)
  9383. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9384. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9385. (defun org-agenda-drag-line-forward (arg &optional backward)
  9386. "Drag an agenda line forward by ARG lines.
  9387. When the optional argument `backward' is non-nil, move backward."
  9388. (interactive "p")
  9389. (let ((inhibit-read-only t) lst line)
  9390. (if (or (not (get-text-property (point) 'txt))
  9391. (save-excursion
  9392. (dotimes (n arg)
  9393. (move-beginning-of-line (if backward 0 2))
  9394. (push (not (get-text-property (point) 'txt)) lst))
  9395. (delq nil lst)))
  9396. (message "Cannot move line forward")
  9397. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9398. (move-beginning-of-line 1)
  9399. (setq line (buffer-substring (point) end))
  9400. (delete-region (point) end)
  9401. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9402. (insert line)
  9403. (org-agenda-reapply-filters)
  9404. (org-agenda-mark-clocking-task)
  9405. (move-beginning-of-line 0)))))
  9406. (defun org-agenda-drag-line-backward (arg)
  9407. "Drag an agenda line backward by ARG lines."
  9408. (interactive "p")
  9409. (org-agenda-drag-line-forward arg t))
  9410. ;;; Flagging notes
  9411. (defun org-agenda-show-the-flagging-note ()
  9412. "Display the flagging note in the other window.
  9413. When called a second time in direct sequence, offer to remove the FLAGGING
  9414. tag and (if present) the flagging note."
  9415. (interactive)
  9416. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9417. (win (selected-window))
  9418. note heading newhead)
  9419. (unless hdmarker
  9420. (user-error "No linked entry at point"))
  9421. (if (and (eq this-command last-command)
  9422. (y-or-n-p "Unflag and remove any flagging note? "))
  9423. (progn
  9424. (org-agenda-remove-flag hdmarker)
  9425. (let ((win (get-buffer-window "*Flagging Note*")))
  9426. (and win (delete-window win)))
  9427. (message "Entry unflagged"))
  9428. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9429. (unless note
  9430. (user-error "No flagging note"))
  9431. (org-kill-new note)
  9432. (org-switch-to-buffer-other-window "*Flagging Note*")
  9433. (erase-buffer)
  9434. (insert note)
  9435. (goto-char (point-min))
  9436. (while (re-search-forward "\\\\n" nil t)
  9437. (replace-match "\n" t t))
  9438. (goto-char (point-min))
  9439. (select-window win)
  9440. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9441. kill ring. Press \\[org-agenda-show-the-flagging-note] again to remove \
  9442. tag and note")))))
  9443. (defun org-agenda-remove-flag (marker)
  9444. "Remove the FLAGGED tag and any flagging note in the entry."
  9445. (let (newhead)
  9446. (org-with-point-at marker
  9447. (org-toggle-tag "FLAGGED" 'off)
  9448. (org-entry-delete nil "THEFLAGGINGNOTE")
  9449. (setq newhead (org-get-heading)))
  9450. (org-agenda-change-all-lines newhead marker)
  9451. (message "Entry unflagged")))
  9452. (defun org-agenda-get-any-marker (&optional pos)
  9453. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9454. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9455. ;;; Appointment reminders
  9456. (defvar appt-time-msg-list) ; defined in appt.el
  9457. ;;;###autoload
  9458. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9459. "Activate appointments found in `org-agenda-files'.
  9460. With a \\[universal-argument] prefix, refresh the list of
  9461. appointments.
  9462. If FILTER is t, interactively prompt the user for a regular
  9463. expression, and filter out entries that don't match it.
  9464. If FILTER is a string, use this string as a regular expression
  9465. for filtering entries out.
  9466. If FILTER is a function, filter out entries against which
  9467. calling the function returns nil. This function takes one
  9468. argument: an entry from `org-agenda-get-day-entries'.
  9469. FILTER can also be an alist with the car of each cell being
  9470. either `headline' or `category'. For example:
  9471. \\='((headline \"IMPORTANT\")
  9472. (category \"Work\"))
  9473. will only add headlines containing IMPORTANT or headlines
  9474. belonging to the \"Work\" category.
  9475. ARGS are symbols indicating what kind of entries to consider.
  9476. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9477. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9478. and :timestamp entries. See the docstring of `org-diary' for
  9479. details and examples.
  9480. If an entry has a APPT_WARNTIME property, its value will be used
  9481. to override `appt-message-warning-time'."
  9482. (interactive "P")
  9483. (if refresh (setq appt-time-msg-list nil))
  9484. (if (eq filter t)
  9485. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9486. (let* ((cnt 0) ; count added events
  9487. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9488. (org-agenda-new-buffers nil)
  9489. (org-deadline-warning-days 0)
  9490. ;; Do not use `org-today' here because appt only takes
  9491. ;; time and without date as argument, so it may pass wrong
  9492. ;; information otherwise
  9493. (today (org-date-to-gregorian
  9494. (time-to-days (current-time))))
  9495. (org-agenda-restrict nil)
  9496. (files (org-agenda-files 'unrestricted)) entries file
  9497. (org-agenda-buffer nil))
  9498. ;; Get all entries which may contain an appt
  9499. (org-agenda-prepare-buffers files)
  9500. (while (setq file (pop files))
  9501. (setq entries
  9502. (delq nil
  9503. (append entries
  9504. (apply 'org-agenda-get-day-entries
  9505. file today scope)))))
  9506. ;; Map thru entries and find if we should filter them out
  9507. (mapc
  9508. (lambda (x)
  9509. (let* ((evt (org-trim
  9510. (replace-regexp-in-string
  9511. org-bracket-link-regexp "\\3"
  9512. (or (get-text-property 1 'txt x) ""))))
  9513. (cat (get-text-property (1- (length x)) 'org-category x))
  9514. (tod (get-text-property 1 'time-of-day x))
  9515. (ok (or (null filter)
  9516. (and (stringp filter) (string-match filter evt))
  9517. (and (functionp filter) (funcall filter x))
  9518. (and (listp filter)
  9519. (let ((cat-filter (cadr (assoc 'category filter)))
  9520. (evt-filter (cadr (assoc 'headline filter))))
  9521. (or (and (stringp cat-filter)
  9522. (string-match cat-filter cat))
  9523. (and (stringp evt-filter)
  9524. (string-match evt-filter evt)))))))
  9525. (wrn (get-text-property 1 'warntime x)))
  9526. ;; FIXME: Shall we remove text-properties for the appt text?
  9527. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9528. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9529. (setq tod (concat "00" (number-to-string tod)))
  9530. (setq tod (when (string-match
  9531. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9532. (concat (match-string 1 tod) ":"
  9533. (match-string 2 tod))))
  9534. (when (if (version< emacs-version "23.3")
  9535. (appt-add tod evt)
  9536. (appt-add tod evt wrn))
  9537. (setq cnt (1+ cnt))))))
  9538. entries)
  9539. (org-release-buffers org-agenda-new-buffers)
  9540. (if (eq cnt 0)
  9541. (message "No event to add")
  9542. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9543. (defun org-agenda-today-p (date)
  9544. "Non nil when DATE means today.
  9545. DATE is either a list of the form (month day year) or a number of
  9546. days as returned by `calendar-absolute-from-gregorian' or
  9547. `org-today'. This function considers `org-extend-today-until'
  9548. when defining today."
  9549. (eq (org-today)
  9550. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9551. (define-obsolete-function-alias 'org-agenda-todayp 'org-agenda-today-p "25.1")
  9552. (defun org-agenda-todo-yesterday (&optional arg)
  9553. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9554. (interactive "P")
  9555. (let* ((org-use-effective-time t)
  9556. (hour (third (decode-time
  9557. (org-current-time))))
  9558. (org-extend-today-until (1+ hour)))
  9559. (org-agenda-todo arg)))
  9560. (provide 'org-agenda)
  9561. ;;; org-agenda.el ends here