org-agenda.el 264 KB

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