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