org-agenda.el 267 KB

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