org-agenda.el 225 KB

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