org-agenda.el 220 KB

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