org-agenda.el 269 KB

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