org-agenda.el 214 KB

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