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
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
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-columns-quit
"org-colview" ())
56 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
57 (declare-function org-habit-insert-consistency-graphs
58 "org-habit" (&optional line
))
59 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
60 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
61 (declare-function org-habit-get-priority
"org-habit" (habit))
62 (defvar calendar-mode-map
)
63 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
64 (defvar org-habit-show-habits
)
65 (defvar org-habit-show-habits-only-for-today
)
67 ;; Defined somewhere in this file, but used before definition.
68 (defvar org-agenda-buffer-name
)
69 (defvar org-agenda-overriding-header
)
70 (defvar org-agenda-title-append nil
)
73 (defvar org-agenda-undo-list
)
74 (defvar org-agenda-pending-undo-list
)
75 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
77 (defcustom org-agenda-confirm-kill
1
78 "When set, remote killing from the agenda buffer needs confirmation.
79 When t, a confirmation is always needed. When a number N, confirmation is
80 only needed when the text to be killed contains more than N non-white lines."
83 (const :tag
"Never" nil
)
84 (const :tag
"Always" t
)
85 (integer :tag
"When more than N lines")))
87 (defcustom org-agenda-compact-blocks nil
88 "Non-nil means, make the block agenda more compact.
89 This is done by leaving out unnecessary lines."
93 (defcustom org-agenda-block-separator ?
=
94 "The separator between blocks in the agenda.
95 If this is a string, it will be used as the separator, with a newline added.
96 If it is a character, it will be repeated to fill the window width."
102 (defgroup org-agenda-export nil
103 "Options concerning exporting agenda views in Org-mode."
104 :tag
"Org Agenda Export"
107 (defcustom org-agenda-with-colors t
108 "Non-nil means, use colors in agenda views."
109 :group
'org-agenda-export
112 (defcustom org-agenda-exporter-settings nil
113 "Alist of variable/value pairs that should be active during agenda export.
114 This is a good place to set options for ps-print and for htmlize.
115 Note that the way this is implemented, the values will be evaluated
116 before assigned to the variables. So make sure to quote values you do
117 *not* want evaluated, for example
119 (setq org-agenda-exporter-settings
120 '((ps-print-color-p 'black-white)))"
121 :group
'org-agenda-export
125 (sexp :tag
"Value"))))
127 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
128 "Hook run in temporary buffer before writing it to an export file.
129 A useful function is `org-agenda-add-entry-text'."
130 :group
'org-agenda-export
132 :options
'(org-agenda-add-entry-text))
134 (defcustom org-agenda-add-entry-text-maxlines
0
135 "Maximum number of entry text lines to be added to agenda.
136 This is only relevant when `org-agenda-add-entry-text' is part of
137 `org-agenda-before-write-hook', which it is by default.
138 When this is 0, nothing will happen. When it is greater than 0, it
139 specifies the maximum number of lines that will be added for each entry
140 that is listed in the agenda view.
142 Note that this variable is not used during display, only when exporting
143 the agenda. For agenda display, see org-agenda-entry-text-mode and the
144 variable `org-agenda-entry-text-maxlines'."
148 (defcustom org-agenda-add-entry-text-descriptive-links t
149 "Non-nil means, export org-links as descriptive links in agenda added text.
150 This variable applies to the text added to the agenda when
151 `org-agenda-add-entry-text-maxlines' is larger than 0.
152 When this variable nil, the URL will (also) be shown."
156 (defcustom org-agenda-export-html-style
""
157 "The style specification for exported HTML Agenda files.
158 If this variable contains a string, it will replace the default <style>
159 section as produced by `htmlize'.
160 Since there are different ways of setting style information, this variable
161 needs to contain the full HTML structure to provide a style, including the
162 surrounding HTML tags. The style specifications should include definitions
163 the fonts used by the agenda, here is an example:
165 <style type=\"text/css\">
166 p { font-weight: normal; color: gray; }
167 .org-agenda-structure {
182 .title { text-align: center; }
183 .todo, .deadline { color: red; }
184 .done { color: green; }
187 or, if you want to keep the style in a file,
189 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
191 As the value of this option simply gets inserted into the HTML <head> header,
192 you can \"misuse\" it to also add other text to the header. However,
193 <style>...</style> is required, if not present the variable will be ignored."
194 :group
'org-agenda-export
195 :group
'org-export-html
198 (defgroup org-agenda-custom-commands nil
199 "Options concerning agenda views in Org-mode."
200 :tag
"Org Agenda Custom Commands"
203 (defconst org-sorting-choice
205 (const time-up
) (const time-down
)
206 (const category-keep
) (const category-up
) (const category-down
)
207 (const tag-down
) (const tag-up
)
208 (const priority-up
) (const priority-down
)
209 (const todo-state-up
) (const todo-state-down
)
210 (const effort-up
) (const effort-down
)
211 (const habit-up
) (const habit-down
)
212 (const user-defined-up
) (const user-defined-down
))
215 (defconst org-agenda-custom-commands-local-options
216 `(repeat :tag
"Local settings for this command. Remember to quote values"
217 (choice :tag
"Setting"
218 (list :tag
"Heading for this block"
219 (const org-agenda-overriding-header
)
220 (string :tag
"Headline"))
221 (list :tag
"Files to be searched"
222 (const org-agenda-files
)
224 (const :format
"" quote
)
226 (list :tag
"Sorting strategy"
227 (const org-agenda-sorting-strategy
)
229 (const :format
"" quote
)
231 ,org-sorting-choice
)))
232 (list :tag
"Prefix format"
233 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
235 (list :tag
"Number of days in agenda"
236 (const org-agenda-ndays
)
238 (list :tag
"Fixed starting date"
239 (const org-agenda-start-day
)
240 (string :value
"2007-11-01"))
241 (list :tag
"Start on day of week"
242 (const org-agenda-start-on-weekday
)
244 (const :tag
"Today" nil
)
245 (integer :tag
"Weekday No.")))
246 (list :tag
"Include data from diary"
247 (const org-agenda-include-diary
)
249 (list :tag
"Deadline Warning days"
250 (const org-deadline-warning-days
)
252 (list :tag
"Tags filter preset"
253 (const org-agenda-filter-preset
)
255 (const :format
"" quote
)
257 (string :tag
"+tag or -tag"))))
258 (list :tag
"Standard skipping condition"
259 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
260 (const org-agenda-skip-function
)
262 (const :format
"" quote
)
265 :tag
"Skipping range"
266 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
267 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
268 (repeat :inline t
:tag
"Conditions for skipping"
270 :tag
"Condition type"
271 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
272 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
273 (const :tag
"scheduled" 'scheduled
)
274 (const :tag
"not scheduled" 'notscheduled
)
275 (const :tag
"deadline" 'deadline
)
276 (const :tag
"no deadline" 'notdeadline
)
277 (const :tag
"timestamp" 'timestamp
)
278 (const :tag
"no timestamp" 'nottimestamp
))))))
279 (list :tag
"Non-standard skipping condition"
280 :value
(org-agenda-skip-function)
281 (const org-agenda-skip-function
)
282 (sexp :tag
"Function or form (quoted!)"))
283 (list :tag
"Any variable"
284 (variable :tag
"Variable")
285 (sexp :tag
"Value (sexp)"))))
286 "Selection of examples for agenda command settings.
287 This will be spliced into the custom type of
288 `org-agenda-custom-commands'.")
291 (defcustom org-agenda-custom-commands nil
292 "Custom commands for the agenda.
293 These commands will be offered on the splash screen displayed by the
294 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
296 (key desc type match settings files)
298 key The key (one or more characters as a string) to be associated
300 desc A description of the command, when omitted or nil, a default
301 description is built using MATCH.
302 type The command type, any of the following symbols:
303 agenda The daily/weekly agenda.
304 todo Entries with a specific TODO keyword, in all agenda files.
305 search Entries containing search words entry or headline.
306 tags Tags/Property/TODO match in all agenda files.
307 tags-todo Tags/P/T match in all agenda files, TODO entries only.
308 todo-tree Sparse tree of specific TODO keyword in *current* file.
309 tags-tree Sparse tree with all tags matches in *current* file.
310 occur-tree Occur sparse tree for *current* file.
311 ... A user-defined function.
312 match What to search for:
313 - a single keyword for TODO keyword searches
314 - a tags match expression for tags searches
315 - a word search expression for text searches.
316 - a regular expression for occur searches
317 For all other commands, this should be the empty string.
318 settings A list of option settings, similar to that in a let form, so like
319 this: ((opt1 val1) (opt2 val2) ...). The values will be
320 evaluated at the moment of execution, so quote them when needed.
321 files A list of files file to write the produced agenda buffer to
322 with the command `org-store-agenda-views'.
323 If a file name ends in \".html\", an HTML version of the buffer
324 is written out. If it ends in \".ps\", a postscript version is
325 produced. Otherwise, only the plain text is written to the file.
327 You can also define a set of commands, to create a composite agenda buffer.
328 In this case, an entry looks like this:
330 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
334 desc A description string to be displayed in the dispatcher menu.
335 cmd An agenda command, similar to the above. However, tree commands
336 are no allowed, but instead you can get agenda and global todo list.
337 So valid commands for a set are:
338 (agenda \"\" settings)
339 (alltodo \"\" settings)
340 (stuck \"\" settings)
341 (todo \"match\" settings files)
342 (search \"match\" settings files)
343 (tags \"match\" settings files)
344 (tags-todo \"match\" settings files)
346 Each command can carry a list of options, and another set of options can be
347 given for the whole set of commands. Individual command options take
348 precedence over the general options.
350 When using several characters as key to a command, the first characters
351 are prefix commands. For the dispatcher to display useful information, you
352 should provide a description for the prefix, like
354 (setq org-agenda-custom-commands
355 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
356 (\"hl\" tags \"+HOME+Lisa\")
357 (\"hp\" tags \"+HOME+Peter\")
358 (\"hk\" tags \"+HOME+Kim\")))"
359 :group
'org-agenda-custom-commands
361 (choice :value
("x" "Describe command here" tags
"" nil
)
362 (list :tag
"Single command"
363 (string :tag
"Access Key(s) ")
364 (option (string :tag
"Description"))
366 (const :tag
"Agenda" agenda
)
367 (const :tag
"TODO list" alltodo
)
368 (const :tag
"Search words" search
)
369 (const :tag
"Stuck projects" stuck
)
370 (const :tag
"Tags/Property match (all agenda files)" tags
)
371 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
372 (const :tag
"TODO keyword search (all agenda files)" todo
)
373 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
374 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
375 (const :tag
"Occur tree (current buffer)" occur-tree
)
376 (sexp :tag
"Other, user-defined function"))
377 (string :tag
"Match (only for some commands)")
378 ,org-agenda-custom-commands-local-options
379 (option (repeat :tag
"Export" (file :tag
"Export to"))))
380 (list :tag
"Command series, all agenda files"
381 (string :tag
"Access Key(s)")
382 (string :tag
"Description ")
383 (repeat :tag
"Component"
386 (const :format
"" agenda
)
387 (const :tag
"" :format
"" "")
388 ,org-agenda-custom-commands-local-options
)
389 (list :tag
"TODO list (all keywords)"
390 (const :format
"" alltodo
)
391 (const :tag
"" :format
"" "")
392 ,org-agenda-custom-commands-local-options
)
393 (list :tag
"Search words"
394 (const :format
"" search
)
395 (string :tag
"Match")
396 ,org-agenda-custom-commands-local-options
)
397 (list :tag
"Stuck projects"
398 (const :format
"" stuck
)
399 (const :tag
"" :format
"" "")
400 ,org-agenda-custom-commands-local-options
)
401 (list :tag
"Tags search"
402 (const :format
"" tags
)
403 (string :tag
"Match")
404 ,org-agenda-custom-commands-local-options
)
405 (list :tag
"Tags search, TODO entries only"
406 (const :format
"" tags-todo
)
407 (string :tag
"Match")
408 ,org-agenda-custom-commands-local-options
)
409 (list :tag
"TODO keyword search"
410 (const :format
"" todo
)
411 (string :tag
"Match")
412 ,org-agenda-custom-commands-local-options
)
413 (list :tag
"Other, user-defined function"
414 (symbol :tag
"function")
415 (string :tag
"Match")
416 ,org-agenda-custom-commands-local-options
)))
418 (repeat :tag
"Settings for entire command set"
419 (list (variable :tag
"Any variable")
420 (sexp :tag
"Value")))
421 (option (repeat :tag
"Export" (file :tag
"Export to"))))
422 (cons :tag
"Prefix key documentation"
423 (string :tag
"Access Key(s)")
424 (string :tag
"Description ")))))
426 (defcustom org-agenda-query-register ?o
427 "The register holding the current query string.
428 The purpose of this is that if you construct a query string interactively,
429 you can then use it to define a custom command."
430 :group
'org-agenda-custom-commands
433 (defcustom org-stuck-projects
434 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
435 "How to identify stuck projects.
436 This is a list of four items:
437 1. A tags/todo/property matcher string that is used to identify a project.
438 See the manual for a description of tag and property searches.
439 The entire tree below a headline matched by this is considered one project.
440 2. A list of TODO keywords identifying non-stuck projects.
441 If the project subtree contains any headline with one of these todo
442 keywords, the project is considered to be not stuck. If you specify
443 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
444 3. A list of tags identifying non-stuck projects.
445 If the project subtree contains any headline with one of these tags,
446 the project is considered to be not stuck. If you specify \"*\" as
447 a tag, any tag will mark the project unstuck. Note that this is about
448 the explicit presence of a tag somewhere in the subtree, inherited
449 tags to not count here. If inherited tags make a project not stuck,
450 use \"-TAG\" in the tags part of the matcher under (1.) above.
451 4. An arbitrary regular expression matching non-stuck projects.
453 If the project turns out to be not stuck, search continues also in the
454 subtree to see if any of the subtasks have project status.
456 See also the variable `org-tags-match-list-sublevels' which applies
457 to projects matched by this search as well.
459 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
460 or `C-c a #' to produce the list."
461 :group
'org-agenda-custom-commands
463 (string :tag
"Tags/TODO match to identify a project")
464 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
465 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
466 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
468 (defcustom org-agenda-filter-effort-default-operator
"<"
469 "The default operator for effort estimate filtering.
470 If you select an effort estimate limit without first pressing an operator,
471 this one will be used."
472 :group
'org-agenda-custom-commands
473 :type
'(choice (const :tag
"less or equal" "<")
474 (const :tag
"greater or equal"">")
475 (const :tag
"equal" "=")))
477 (defgroup org-agenda-skip nil
478 "Options concerning skipping parts of agenda files."
479 :tag
"Org Agenda Skip"
481 (defgroup org-agenda-daily
/weekly nil
482 "Options concerning the daily/weekly agenda."
483 :tag
"Org Agenda Daily/Weekly"
485 (defgroup org-agenda-todo-list nil
486 "Options concerning the global todo list agenda view."
487 :tag
"Org Agenda Todo List"
489 (defgroup org-agenda-match-view nil
490 "Options concerning the general tags/property/todo match agenda view."
491 :tag
"Org Agenda Match View"
493 (defgroup org-agenda-search-view nil
494 "Options concerning the general tags/property/todo match agenda view."
495 :tag
"Org Agenda Match View"
498 (defvar org-agenda-archives-mode nil
499 "Non-nil means, the agenda will include archived items.
500 If this is the symbol `trees', trees in the selected agenda scope
501 that are marked with the ARCHIVE tag will be included anyway. When this is
502 t, also all archive files associated with the current selection of agenda
503 files will be included.")
505 (defcustom org-agenda-skip-comment-trees t
506 "Non-nil means, skip trees that start with the COMMENT keyword.
507 When nil, these trees are also scanned by agenda commands."
508 :group
'org-agenda-skip
511 (defcustom org-agenda-todo-list-sublevels t
512 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
513 When nil, the sublevels of a TODO entry are not checked, resulting in
514 potentially much shorter TODO lists."
515 :group
'org-agenda-skip
516 :group
'org-agenda-todo-list
519 (defcustom org-agenda-todo-ignore-with-date nil
520 "Non-nil means, don't show entries with a date in the global todo list.
521 You can use this if you prefer to mark mere appointments with a TODO keyword,
522 but don't want them to show up in the TODO list.
523 When this is set, it also covers deadlines and scheduled items, the settings
524 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
526 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
527 :group
'org-agenda-skip
528 :group
'org-agenda-todo-list
531 (defcustom org-agenda-todo-ignore-scheduled nil
532 "Non-nil means, don't show scheduled entries in the global todo list.
533 The idea behind this is that by scheduling it, you have already taken care
535 See also `org-agenda-todo-ignore-with-date'.
536 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
537 :group
'org-agenda-skip
538 :group
'org-agenda-todo-list
541 (defcustom org-agenda-todo-ignore-deadlines nil
542 "Non-nil means, don't show near deadline entries in the global todo list.
543 Near means closer than `org-deadline-warning-days' days.
544 The idea behind this is that such items will appear in the agenda anyway.
545 See also `org-agenda-todo-ignore-with-date'.
546 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
547 :group
'org-agenda-skip
548 :group
'org-agenda-todo-list
551 (defcustom org-agenda-tags-todo-honor-ignore-options nil
552 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
554 `org-agenda-todo-ignore-with-date',
555 `org-agenda-todo-ignore-scheduled'
556 `org-agenda-todo-ignore-deadlines'
557 make the global TODO list skip entries that have time stamps of certain
558 kinds. If this option is set, the same options will also apply for the
559 tags-todo search, which is the general tags/property matcher
560 restricted to unfinished TODO entries only."
561 :group
'org-agenda-skip
562 :group
'org-agenda-todo-list
563 :group
'org-agenda-match-view
566 (defcustom org-agenda-skip-scheduled-if-done nil
567 "Non-nil means don't show scheduled items in agenda when they are done.
568 This is relevant for the daily/weekly agenda, not for the TODO list. And
569 it applies only to the actual date of the scheduling. Warnings about
570 an item with a past scheduling dates are always turned off when the item
572 :group
'org-agenda-skip
573 :group
'org-agenda-daily
/weekly
576 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
577 "Non-nil means skip scheduling line if same entry shows because of deadline.
578 In the agenda of today, an entry can show up multiple times because
579 it is both scheduled and has a nearby deadline, and maybe a plain time
581 When this variable is t, then only the deadline is shown and the fact that
582 the entry is scheduled today or was scheduled previously is not shown.
583 When this variable is nil, the entry will be shown several times. When
584 the variable is the symbol `not-today', then skip scheduled previously,
585 but not scheduled today."
586 :group
'org-agenda-skip
587 :group
'org-agenda-daily
/weekly
589 (const :tag
"Never" nil
)
590 (const :tag
"Always" t
)
591 (const :tag
"Not when scheduled today" not-today
)))
593 (defcustom org-agenda-skip-deadline-if-done nil
594 "Non-nil means don't show deadlines when the corresponding item is done.
595 When nil, the deadline is still shown and should give you a happy feeling.
596 This is relevant for the daily/weekly agenda. And it applied only to the
597 actually date of the deadline. Warnings about approaching and past-due
598 deadlines are always turned off when the item is DONE."
599 :group
'org-agenda-skip
600 :group
'org-agenda-daily
/weekly
603 (defcustom org-agenda-skip-additional-timestamps-same-entry t
604 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
605 When non-nil, after the search for timestamps has matched once in an
606 entry, the rest of the entry will not be searched."
607 :group
'org-agenda-skip
610 (defcustom org-agenda-skip-timestamp-if-done nil
611 "Non-nil means don't select item by timestamp or -range if it is DONE."
612 :group
'org-agenda-skip
613 :group
'org-agenda-daily
/weekly
616 (defcustom org-agenda-dim-blocked-tasks t
617 "Non-nil means, dim blocked tasks in the agenda display.
618 This causes some overhead during agenda construction, but if you
619 have turned on `org-enforce-todo-dependencies',
620 `org-enforce-todo-checkbox-dependencies', or any other blocking
621 mechanism, this will create useful feedback in the agenda.
623 Instead ot t, this variable can also have the value `invisible'.
624 Then blocked tasks will be invisible and only become visible when
625 they become unblocked. An exemption to this behavior is when a task is
626 blocked because of unchecked checkboxes below it. Since checkboxes do
627 not show up in the agenda views, making this task invisible you remove any
628 trace from agenda views that there is something to do. Therefore, a task
629 that is blocked because of checkboxes will never be made invisible, it
630 will only be dimmed."
631 :group
'org-agenda-daily
/weekly
632 :group
'org-agenda-todo-list
634 (const :tag
"Do not dim" nil
)
635 (const :tag
"Dim to a grey face" t
)
636 (const :tag
"Make invisibe" invisible
)))
638 (defcustom org-timeline-show-empty-dates
3
639 "Non-nil means, `org-timeline' also shows dates without an entry.
640 When nil, only the days which actually have entries are shown.
641 When t, all days between the first and the last date are shown.
642 When an integer, show also empty dates, but if there is a gap of more than
643 N days, just insert a special line indicating the size of the gap."
644 :group
'org-agenda-skip
646 (const :tag
"None" nil
)
648 (integer :tag
"at most")))
650 (defgroup org-agenda-startup nil
651 "Options concerning initial settings in the Agenda in Org Mode."
652 :tag
"Org Agenda Startup"
655 (defcustom org-finalize-agenda-hook nil
656 "Hook run just before displaying an agenda buffer."
657 :group
'org-agenda-startup
660 (defcustom org-agenda-mouse-1-follows-link nil
661 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
662 A longer mouse click will still set point. Does not work on XEmacs.
663 Needs to be set before org.el is loaded."
664 :group
'org-agenda-startup
667 (defcustom org-agenda-start-with-follow-mode nil
668 "The initial value of follow-mode in a newly created agenda window."
669 :group
'org-agenda-startup
672 (defcustom org-agenda-start-with-entry-text-mode nil
673 "The initial value of entry-text-mode in a newly created agenda window."
674 :group
'org-agenda-startup
677 (defcustom org-agenda-entry-text-maxlines
5
678 "Number of text lines to be added when `E' is presed in the agenda.
680 Note that this variable only used during agenda display. Add add entry text
681 when exporting the agenda, configure the variable
682 `org-agenda-add-entry-ext-maxlines'."
686 (defcustom org-agenda-entry-text-exclude-regexps nil
687 "List of regular expressions to clean up entry text.
688 The complete matches of all regular expressions in this list will be
689 removed from entry text before it is shown in the agenda."
691 :type
'(repeat (regexp)))
693 (defvar org-agenda-entry-text-cleanup-hook nil
694 "Hook that is run after basic cleanup of entry text to be shown in agenda.
695 This cleanup is done in a temporary buffer, so the function may inspect and
696 change the entire buffer.
697 Some default stuff like drawers and scheduling/deadline dates will already
698 have been removed when this is called, as will any matches for regular
699 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
701 (defvar org-agenda-include-inactive-timestamps nil
702 "Non-nil means, include inactive time stamps in agenda and timeline.")
704 (defgroup org-agenda-windows nil
705 "Options concerning the windows used by the Agenda in Org Mode."
706 :tag
"Org Agenda Windows"
709 (defcustom org-agenda-window-setup
'reorganize-frame
710 "How the agenda buffer should be displayed.
711 Possible values for this option are:
713 current-window Show agenda in the current window, keeping all other windows.
714 other-window Use `switch-to-buffer-other-window' to display agenda.
715 reorganize-frame Show only two windows on the current frame, the current
716 window and the agenda.
717 other-frame Use `switch-to-buffer-other-frame' to display agenda.
718 Also, when exiting the agenda, kill that frame.
719 See also the variable `org-agenda-restore-windows-after-quit'."
720 :group
'org-agenda-windows
722 (const current-window
)
725 (const reorganize-frame
)))
727 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
728 "The min and max height of the agenda window as a fraction of frame height.
729 The value of the variable is a cons cell with two numbers between 0 and 1.
730 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
731 :group
'org-agenda-windows
732 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
734 (defcustom org-agenda-restore-windows-after-quit nil
735 "Non-nil means, restore window configuration open exiting agenda.
736 Before the window configuration is changed for displaying the agenda,
737 the current status is recorded. When the agenda is exited with
738 `q' or `x' and this option is set, the old state is restored. If
739 `org-agenda-window-setup' is `other-frame', the value of this
740 option will be ignored."
741 :group
'org-agenda-windows
744 (defcustom org-agenda-ndays
7
745 "Number of days to include in overview display.
747 Custom commands can set this variable in the options section."
748 :group
'org-agenda-daily
/weekly
751 (defcustom org-agenda-start-on-weekday
1
752 "Non-nil means, start the overview always on the specified weekday.
753 0 denotes Sunday, 1 denotes Monday etc.
754 When nil, always start on the current day.
755 Custom commands can set this variable in the options section."
756 :group
'org-agenda-daily
/weekly
757 :type
'(choice (const :tag
"Today" nil
)
758 (integer :tag
"Weekday No.")))
760 (defcustom org-agenda-show-all-dates t
761 "Non-nil means, `org-agenda' shows every day in the selected range.
762 When nil, only the days which actually have entries are shown."
763 :group
'org-agenda-daily
/weekly
766 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
767 "Format string for displaying dates in the agenda.
768 Used by the daily/weekly agenda and by the timeline. This should be
769 a format string understood by `format-time-string', or a function returning
770 the formatted date as a string. The function must take a single argument,
771 a calendar-style date list like (month day year)."
772 :group
'org-agenda-daily
/weekly
774 (string :tag
"Format string")
775 (function :tag
"Function")))
777 (defun org-agenda-format-date-aligned (date)
778 "Format a date string for display in the daily/weekly agenda, or timeline.
779 This function makes sure that dates are aligned for easy reading."
781 (let* ((dayname (calendar-day-name date
))
783 (day-of-week (calendar-day-of-week date
))
785 (monthname (calendar-month-name month
))
787 (iso-week (org-days-to-iso-week
788 (calendar-absolute-from-gregorian date
)))
789 (weekyear (cond ((and (= month
1) (>= iso-week
52))
791 ((and (= month
12) (<= iso-week
1))
794 (weekstring (if (= day-of-week
1)
795 (format " W%02d" iso-week
)
797 (format "%-10s %2d %s %4d%s"
798 dayname day monthname year weekstring
)))
800 (defcustom org-agenda-weekend-days
'(6 0)
801 "Which days are weekend?
802 These days get the special face `org-agenda-date-weekend' in the agenda
803 and timeline buffers."
804 :group
'org-agenda-daily
/weekly
805 :type
'(set :greedy t
806 (const :tag
"Monday" 1)
807 (const :tag
"Tuesday" 2)
808 (const :tag
"Wednesday" 3)
809 (const :tag
"Thursday" 4)
810 (const :tag
"Friday" 5)
811 (const :tag
"Saturday" 6)
812 (const :tag
"Sunday" 0)))
814 (defcustom org-agenda-include-diary nil
815 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
816 Custom commands can set this variable in the options section."
817 :group
'org-agenda-daily
/weekly
820 (defcustom org-agenda-include-all-todo nil
821 "Set means weekly/daily agenda will always contain all TODO entries.
822 The TODO entries will be listed at the top of the agenda, before
823 the entries for specific days.
824 This option is deprecated, it is better to define a block agenda instead."
825 :group
'org-agenda-daily
/weekly
828 (defcustom org-agenda-repeating-timestamp-show-all t
829 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
830 When nil, only one occurrence is shown, either today or the
831 nearest into the future."
832 :group
'org-agenda-daily
/weekly
835 (defcustom org-scheduled-past-days
10000
836 "No. of days to continue listing scheduled items that are not marked DONE.
837 When an item is scheduled on a date, it shows up in the agenda on this
838 day and will be listed until it is marked done for the number of days
840 :group
'org-agenda-daily
/weekly
843 (defcustom org-agenda-log-mode-items
'(closed clock
)
844 "List of items that should be shown in agenda log mode.
845 This list may contain the following symbols:
847 closed Show entries that have been closed on that day.
848 clock Show entries that have received clocked time on that day.
849 state Show all logged state changes.
850 Note that instead of changing this variable, you can also press `C-u l' in
851 the agenda to display all available LOG items temporarily."
852 :group
'org-agenda-daily
/weekly
853 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
855 (defcustom org-agenda-log-mode-add-notes t
856 "Non-nil means, add first line of notes to log entries in agenda views.
857 If a log item like a state change or a clock entry is associated with
858 notes, the first line of these notes will be added to the entry in the
860 :group
'org-agenda-daily
/weekly
863 (defcustom org-agenda-start-with-log-mode nil
864 "The initial value of log-mode in a newly created agenda window."
865 :group
'org-agenda-startup
866 :group
'org-agenda-daily
/weekly
869 (defcustom org-agenda-start-with-clockreport-mode nil
870 "The initial value of clockreport-mode in a newly created agenda window."
871 :group
'org-agenda-startup
872 :group
'org-agenda-daily
/weekly
875 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
876 "Property list with parameters for the clocktable in clockreport mode.
877 This is the display mode that shows a clock table in the daily/weekly
878 agenda, the properties for this dynamic block can be set here.
879 The usual clocktable parameters are allowed here, but you cannot set
880 the properties :name, :tstart, :tend, :block, and :scope - these will
881 be overwritten to make sure the content accurately reflects the
882 current display in the agenda."
883 :group
'org-agenda-daily
/weekly
886 (defcustom org-agenda-search-view-search-words-only nil
887 "Non-nil means, the search string is interpreted as individual words
888 The search then looks for each word separately in each entry and
889 selects entries that have matches for all words.
890 When nil, matching as loose words will only take place if the first
891 word is preceded by + or -. If that is not the case, the search
892 string will just be matched as a substring in the entry, but with
893 each space character allowing for any whitespace, including newlines."
894 :group
'org-agenda-search-view
897 (defgroup org-agenda-time-grid nil
898 "Options concerning the time grid in the Org-mode Agenda."
899 :tag
"Org Agenda Time Grid"
902 (defcustom org-agenda-search-headline-for-time t
903 "Non-nil means, search headline for a time-of-day.
904 If the headline contains a time-of-day in one format or another, it will
905 be used to sort the entry into the time sequence of items for a day.
906 Some people have time stamps in the headline that refer to the creation
907 time or so, and then this produces an unwanted side effect. If this is
908 the case for your, use this variable to turn off searching the headline
910 :group
'org-agenda-time-grid
913 (defcustom org-agenda-use-time-grid t
914 "Non-nil means, show a time grid in the agenda schedule.
915 A time grid is a set of lines for specific times (like every two hours between
916 8:00 and 20:00). The items scheduled for a day at specific times are
917 sorted in between these lines.
918 For details about when the grid will be shown, and what it will look like, see
919 the variable `org-agenda-time-grid'."
920 :group
'org-agenda-time-grid
923 (defcustom org-agenda-time-grid
924 '((daily today require-timed
)
926 (800 1000 1200 1400 1600 1800 2000))
928 "The settings for time grid for agenda display.
929 This is a list of three items. The first item is again a list. It contains
930 symbols specifying conditions when the grid should be displayed:
932 daily if the agenda shows a single day
933 weekly if the agenda shows an entire week
934 today show grid on current date, independent of daily/weekly display
935 require-timed show grid only if at least one item has a time specification
937 The second item is a string which will be placed behind the grid time.
939 The third item is a list of integers, indicating the times that should have
941 :group
'org-agenda-time-grid
944 (set :greedy t
:tag
"Grid Display Options"
945 (const :tag
"Show grid in single day agenda display" daily
)
946 (const :tag
"Show grid in weekly agenda display" weekly
)
947 (const :tag
"Always show grid for today" today
)
948 (const :tag
"Show grid only if any timed entries are present"
950 (const :tag
"Skip grid times already present in an entry"
952 (string :tag
"Grid String")
953 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
955 (defgroup org-agenda-sorting nil
956 "Options concerning sorting in the Org-mode Agenda."
957 :tag
"Org Agenda Sorting"
960 (defcustom org-agenda-sorting-strategy
961 '((agenda habit-down time-up priority-down category-keep
)
962 (todo priority-down category-keep
)
963 (tags priority-down category-keep
)
964 (search category-keep
))
965 "Sorting structure for the agenda items of a single day.
966 This is a list of symbols which will be used in sequence to determine
967 if an entry should be listed before another entry. The following
968 symbols are recognized:
970 time-up Put entries with time-of-day indications first, early first
971 time-down Put entries with time-of-day indications first, late first
972 category-keep Keep the default order of categories, corresponding to the
973 sequence in `org-agenda-files'.
974 category-up Sort alphabetically by category, A-Z.
975 category-down Sort alphabetically by category, Z-A.
976 tag-up Sort alphabetically by last tag, A-Z.
977 tag-down Sort alphabetically by last tag, Z-A.
978 priority-up Sort numerically by priority, high priority last.
979 priority-down Sort numerically by priority, high priority first.
980 todo-state-up Sort by todo state, tasks that are done last.
981 todo-state-down Sort by todo state, tasks that are done first.
982 effort-up Sort numerically by estimated effort, high effort last.
983 effort-down Sort numerically by estimated effort, high effort first.
984 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
985 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
986 habit-up Put entries that are habits first
987 habit-down Put entries that are habits last
989 The different possibilities will be tried in sequence, and testing stops
990 if one comparison returns a \"not-equal\". For example, the default
991 '(time-up category-keep priority-down)
992 means: Pull out all entries having a specified time of day and sort them,
993 in order to make a time schedule for the current day the first thing in the
994 agenda listing for the day. Of the entries without a time indication, keep
995 the grouped in categories, don't sort the categories, but keep them in
996 the sequence given in `org-agenda-files'. Within each category sort by
999 Leaving out `category-keep' would mean that items will be sorted across
1000 categories by priority.
1002 Instead of a single list, this can also be a set of list for specific
1003 contents, with a context symbol in the car of the list, any of
1004 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1006 Custom commands can bind this variable in the options section."
1007 :group
'org-agenda-sorting
1009 (repeat :tag
"General" ,org-sorting-choice
)
1010 (list :tag
"Individually"
1011 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1012 (repeat ,org-sorting-choice
))
1013 (cons (const :tag
"Strategy for TODO lists" todo
)
1014 (repeat ,org-sorting-choice
))
1015 (cons (const :tag
"Strategy for Tags matches" tags
)
1016 (repeat ,org-sorting-choice
))
1017 (cons (const :tag
"Strategy for search matches" search
)
1018 (repeat ,org-sorting-choice
)))))
1020 (defcustom org-agenda-cmp-user-defined nil
1021 "A function to define the comparison `user-defined'.
1022 This function must receive two arguments, agenda entry a and b.
1023 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1024 the user comparison, return nil.
1025 When this is defined, you can make `user-defined-up' and `user-defined-down'
1026 part of an agenda sorting strategy."
1027 :group
'org-agenda-sorting
1030 (defcustom org-sort-agenda-notime-is-late t
1031 "Non-nil means, items without time are considered late.
1032 This is only relevant for sorting. When t, items which have no explicit
1033 time like 15:30 will be considered as 99:01, i.e. later than any items which
1034 do have a time. When nil, the default time is before 0:00. You can use this
1035 option to decide if the schedule for today should come before or after timeless
1037 :group
'org-agenda-sorting
1040 (defcustom org-sort-agenda-noeffort-is-high t
1041 "Non-nil means, items without effort estimate are sorted as high effort.
1042 This also applies when filtering an agenda view with respect to the
1043 < or > effort operator. Then, tasks with no effort defined will be treated
1044 as tasks with high effort.
1045 When nil, such items are sorted as 0 minutes effort."
1046 :group
'org-agenda-sorting
1049 (defgroup org-agenda-line-format nil
1050 "Options concerning the entry prefix in the Org-mode agenda display."
1051 :tag
"Org Agenda Line Format"
1054 (defcustom org-agenda-prefix-format
1055 '((agenda .
" %-12:c%?-12t% s")
1059 (search .
" %-12:c"))
1060 "Format specifications for the prefix of items in the agenda views.
1061 An alist with four entries, for the different agenda types. The keys to the
1062 sublists are `agenda', `timeline', `todo', and `tags'. The values
1064 This format works similar to a printf format, with the following meaning:
1066 %c the category of the item, \"Diary\" for entries from the diary, or
1067 as given by the CATEGORY keyword or derived from the file name.
1068 %T the *last* tag of the item. Last because inherited tags come
1070 %t the time-of-day specification if one applies to the entry, in the
1072 %s Scheduling/Deadline information, a short string
1074 All specifiers work basically like the standard `%s' of printf, but may
1075 contain two additional characters: A question mark just after the `%' and
1076 a whitespace/punctuation character just before the final letter.
1078 If the first character after `%' is a question mark, the entire field
1079 will only be included if the corresponding value applies to the
1080 current entry. This is useful for fields which should have fixed
1081 width when present, but zero width when absent. For example,
1082 \"%?-12t\" will result in a 12 character time field if a time of the
1083 day is specified, but will completely disappear in entries which do
1086 If there is punctuation or whitespace character just before the final
1087 format letter, this character will be appended to the field value if
1088 the value is not empty. For example, the format \"%-12:c\" leads to
1089 \"Diary: \" if the category is \"Diary\". If the category were be
1090 empty, no additional colon would be interted.
1092 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1093 - Indent the line with two space characters
1094 - Give the category in a 12 chars wide field, padded with whitespace on
1095 the right (because of `-'). Append a colon if there is a category
1097 - If there is a time-of-day, put it into a 12 chars wide field. If no
1098 time, don't put in an empty field, just skip it (because of '?').
1099 - Finally, put the scheduling information and append a whitespace.
1101 As another example, if you don't want the time-of-day of entries in
1102 the prefix, you could use:
1104 (setq org-agenda-prefix-format \" %-11:c% s\")
1106 See also the variables `org-agenda-remove-times-when-in-prefix' and
1107 `org-agenda-remove-tags'.
1109 Custom commands can set this variable in the options section."
1111 (string :tag
"General format")
1112 (list :greedy t
:tag
"View dependent"
1113 (cons (const agenda
) (string :tag
"Format"))
1114 (cons (const timeline
) (string :tag
"Format"))
1115 (cons (const todo
) (string :tag
"Format"))
1116 (cons (const tags
) (string :tag
"Format"))
1117 (cons (const search
) (string :tag
"Format"))))
1118 :group
'org-agenda-line-format
)
1120 (defvar org-prefix-format-compiled nil
1121 "The compiled version of the most recently used prefix format.
1122 See the variable `org-agenda-prefix-format'.")
1124 (defcustom org-agenda-todo-keyword-format
"%-1s"
1125 "Format for the TODO keyword in agenda lines.
1126 Set this to something like \"%-12s\" if you want all TODO keywords
1127 to occupy a fixed space in the agenda display."
1128 :group
'org-agenda-line-format
1131 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1132 "Text preceding timerange entries in the agenda view.
1133 This is a list with two strings. The first applies when the range
1134 is entirely on one day. The second applies if the range spans several days.
1135 The strings may have two \"%d\" format specifiers which will be filled
1136 with the sequence number of the days, and the total number of days in the
1137 range, respectively."
1138 :group
'org-agenda-line-format
1140 (string :tag
"Deadline today ")
1141 (choice :tag
"Deadline relative"
1142 (string :tag
"Format string")
1145 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1146 "Text preceeding scheduled items in the agenda view.
1147 This is a list with two strings. The first applies when the item is
1148 scheduled on the current day. The second applies when it has been scheduled
1149 previously, it may contain a %d indicating that this is the nth time that
1150 this item is scheduled, due to automatic rescheduling of unfinished items
1151 for the following day. So this number is one larger than the number of days
1152 that passed since this item was scheduled first."
1153 :group
'org-agenda-line-format
1155 (string :tag
"Scheduled today ")
1156 (string :tag
"Scheduled previously")))
1158 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1159 "Text preceeding deadline items in the agenda view.
1160 This is a list with two strings. The first applies when the item has its
1161 deadline on the current day. The second applies when it is in the past or
1162 in the future, it may contain %d to capture how many days away the deadline
1164 :group
'org-agenda-line-format
1166 (string :tag
"Deadline today ")
1167 (choice :tag
"Deadline relative"
1168 (string :tag
"Format string")
1171 (defcustom org-agenda-remove-times-when-in-prefix t
1172 "Non-nil means, remove duplicate time specifications in agenda items.
1173 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1174 time-of-day specification in a headline or diary entry is extracted and
1175 placed into the prefix. If this option is non-nil, the original specification
1176 \(a timestamp or -range, or just a plain time(range) specification like
1177 11:30-4pm) will be removed for agenda display. This makes the agenda less
1179 The option can be t or nil. It may also be the symbol `beg', indicating
1180 that the time should only be removed what it is located at the beginning of
1181 the headline/diary entry."
1182 :group
'org-agenda-line-format
1184 (const :tag
"Always" t
)
1185 (const :tag
"Never" nil
)
1186 (const :tag
"When at beginning of entry" beg
)))
1189 (defcustom org-agenda-default-appointment-duration nil
1190 "Default duration for appointments that only have a starting time.
1191 When nil, no duration is specified in such cases.
1192 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1193 :group
'org-agenda-line-format
1195 (integer :tag
"Minutes")
1196 (const :tag
"No default duration")))
1198 (defcustom org-agenda-show-inherited-tags t
1199 "Non-nil means, show inherited tags in each agenda line."
1200 :group
'org-agenda-line-format
1203 (defcustom org-agenda-remove-tags nil
1204 "Non-nil means, remove the tags from the headline copy in the agenda.
1205 When this is the symbol `prefix', only remove tags when
1206 `org-agenda-prefix-format' contains a `%T' specifier."
1207 :group
'org-agenda-line-format
1209 (const :tag
"Always" t
)
1210 (const :tag
"Never" nil
)
1211 (const :tag
"When prefix format contains %T" prefix
)))
1213 (if (fboundp 'defvaralias
)
1214 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1215 'org-agenda-remove-tags
))
1217 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1218 "Shift tags in agenda items to this column.
1219 If this number is positive, it specifies the column. If it is negative,
1220 it means that the tags should be flushright to that column. For example,
1221 -80 works well for a normal 80 character screen."
1222 :group
'org-agenda-line-format
1225 (if (fboundp 'defvaralias
)
1226 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1228 (defcustom org-agenda-fontify-priorities
'cookies
1229 "Non-nil means, highlight low and high priorities in agenda.
1230 When t, the highest priority entries are bold, lowest priority italic.
1231 However, settings in org-priority-faces will overrule these faces.
1232 When this variable is the symbol `cookies', only fontify the
1233 cookies, not the entire task.
1234 This may also be an association list of priority faces, whose
1235 keys are the character values of `org-highest-priority',
1236 `org-default-priority', and `org-lowest-priority' (the default values
1237 are ?A, ?B, and ?C, respectively). The face may be a named face,
1238 or a list like `(:background \"Red\")'."
1239 :group
'org-agenda-line-format
1241 (const :tag
"Never" nil
)
1242 (const :tag
"Defaults" t
)
1243 (const :tag
"Cookies only" cookies
)
1244 (repeat :tag
"Specify"
1245 (list (character :tag
"Priority" :value ?A
)
1246 (sexp :tag
"face")))))
1248 (defgroup org-agenda-column-view nil
1249 "Options concerning column view in the agenda."
1250 :tag
"Org Agenda Column View"
1253 (defcustom org-agenda-columns-show-summaries t
1254 "Non-nil means, show summaries for columns displayed in the agenda view."
1255 :group
'org-agenda-column-view
1258 (defcustom org-agenda-columns-remove-prefix-from-item t
1259 "Non-nil means, remove the prefix from a headline for agenda column view.
1260 The special ITEM field in the columns format contains the current line, with
1261 all information shown in other columns (like the TODO state or a tag).
1262 When this variable is non-nil, also the agenda prefix will be removed from
1263 the content of the ITEM field, to make sure as much as possible of the
1264 headline can be shown in the limited width of the field."
1268 (defcustom org-agenda-columns-compute-summary-properties t
1269 "Non-nil means, recompute all summary properties before column view.
1270 When column view in the agenda is listing properties that have a summary
1271 operator, it can go to all relevant buffers and recompute the summaries
1272 there. This can mean overhead for the agenda column view, but is necessary
1273 to have thing up to date.
1274 As a special case, a CLOCKSUM property also makes sure that the clock
1275 computations are current."
1276 :group
'org-agenda-column-view
1279 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1280 "Non-nil means, the duration of an appointment will add to day effort.
1281 The property to which appointment durations will be added is the one given
1282 in the option `org-effort-property'. If an appointment does not have
1283 an end time, `org-agenda-default-appointment-duration' will be used. If that
1284 is not set, an appointment without end time will not contribute to the time
1286 :group
'org-agenda-column-view
1289 (defcustom org-agenda-auto-exclude-function nil
1290 "A function called with a tag to decide if it is filtered on '/ RET'.
1291 The sole argument to the function, which is called once for each
1292 possible tag, is a string giving the name of the tag. The
1293 function should return either nil if the tag should be included
1294 as normal, or \"-<TAG>\" to exclude the tag."
1302 (defun org-add-agenda-custom-command (entry)
1303 "Replace or add a command in `org-agenda-custom-commands'.
1304 This is mostly for hacking and trying a new command - once the command
1305 works you probably want to add it to `org-agenda-custom-commands' for good."
1306 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1308 (setcdr ass
(cdr entry
))
1309 (push entry org-agenda-custom-commands
))))
1311 ;;; Define the Org-agenda-mode
1313 (defvar org-agenda-mode-map
(make-sparse-keymap)
1314 "Keymap for `org-agenda-mode'.")
1316 (defvar org-agenda-menu
) ; defined later in this file.
1317 (defvar org-agenda-restrict
) ; defined later in this file.
1318 (defvar org-agenda-follow-mode nil
)
1319 (defvar org-agenda-entry-text-mode nil
)
1320 (defvar org-agenda-clockreport-mode nil
)
1321 (defvar org-agenda-show-log nil
)
1322 (defvar org-agenda-redo-command nil
)
1323 (defvar org-agenda-query-string nil
)
1324 (defvar org-agenda-mode-hook nil
1325 "Hook for org-agenda-mode, run after the mode is turned on.")
1326 (defvar org-agenda-type nil
)
1327 (defvar org-agenda-force-single-file nil
)
1328 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1330 (defun org-agenda-mode ()
1331 "Mode for time-sorted view on action items in Org-mode files.
1333 The following commands are available:
1335 \\{org-agenda-mode-map}"
1337 (kill-all-local-variables)
1338 (setq org-agenda-undo-list nil
1339 org-agenda-pending-undo-list nil
1340 org-agenda-bulk-marked-entries nil
)
1341 (setq major-mode
'org-agenda-mode
)
1342 ;; Keep global-font-lock-mode from turning on font-lock-mode
1343 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1344 (setq mode-name
"Org-Agenda")
1345 (use-local-map org-agenda-mode-map
)
1346 (easy-menu-add org-agenda-menu
)
1347 (if org-startup-truncated
(setq truncate-lines t
))
1348 (org-set-local 'line-move-visual nil
)
1349 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1350 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1351 ;; Make sure properties are removed when copying text
1352 (when (boundp 'buffer-substring-filters
)
1353 (org-set-local 'buffer-substring-filters
1355 (set-text-properties 0 (length x
) nil x
) x
)
1356 buffer-substring-filters
)))
1357 (unless org-agenda-keep-modes
1358 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1359 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1360 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1361 org-agenda-show-log org-agenda-start-with-log-mode
))
1364 '("Agenda") "Agenda Files"
1368 (if (get 'org-agenda-files
'org-restrict
)
1369 "Restricted to single file"
1371 '(org-edit-agenda-file-list)
1372 (not (get 'org-agenda-files
'org-restrict
)))
1374 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1375 (org-agenda-set-mode-name)
1377 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1378 (list 'org-agenda-mode-hook
)))
1380 (substitute-key-definition 'undo
'org-agenda-undo
1381 org-agenda-mode-map global-map
)
1382 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1383 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1384 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1385 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1386 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1387 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1388 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1389 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1390 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1391 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1392 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1393 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1394 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1395 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1396 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1397 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1398 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1399 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1400 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1401 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1402 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1403 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1404 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1405 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1406 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1407 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1408 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1409 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1410 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1411 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1412 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1413 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1414 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1415 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1416 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1417 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1418 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1419 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1420 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1421 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1422 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1423 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1424 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1426 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1427 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1428 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1429 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1430 (while l (org-defkey org-agenda-mode-map
1431 (int-to-string (pop l)) 'digit-argument)))
1433 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1434 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1435 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1436 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1437 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1438 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1439 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1440 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1441 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1442 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1443 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1444 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1445 'org-clock-modify-effort-estimate)
1446 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1447 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1448 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1449 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1450 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1451 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1452 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1453 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1454 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1455 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1456 (substitute-key-definition 'next-line 'org-agenda-next-line
1457 org-agenda-mode-map global-map)
1458 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1459 org-agenda-mode-map global-map)
1460 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1461 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1462 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1463 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1464 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1465 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1466 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1467 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1468 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1469 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1470 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1471 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1472 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1473 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1474 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1475 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1476 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1477 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1478 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1479 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1480 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1481 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1482 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1483 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1484 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1485 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1486 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1487 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1488 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1489 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1491 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1492 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1493 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1494 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1495 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1496 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1497 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1498 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1499 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1500 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1502 (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
1503 "Local keymap for agenda entries from Org-mode.")
1505 (org-defkey org-agenda-keymap
1506 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1507 (org-defkey org-agenda-keymap
1508 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1509 (when org-agenda-mouse-1-follows-link
1510 (org-defkey org-agenda-keymap [follow-link] 'mouse-face))
1511 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1516 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1517 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1518 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1519 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1522 ["Day View" org-agenda-day-view
1523 :active (org-agenda-check-type nil 'agenda)
1524 :style radio :selected (equal org-agenda-ndays 1)
1525 :keys "v d (or just d)"]
1526 ["Week View" org-agenda-week-view
1527 :active (org-agenda-check-type nil 'agenda)
1528 :style radio :selected (equal org-agenda-ndays 7)
1529 :keys "v w (or just w)"]
1530 ["Month View" org-agenda-month-view
1531 :active (org-agenda-check-type nil 'agenda)
1532 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1534 ["Year View" org-agenda-year-view
1535 :active (org-agenda-check-type nil 'agenda)
1536 :style radio :selected (member org-agenda-ndays '(365 366))
1539 ["Include Diary" org-agenda-toggle-diary
1540 :style toggle :selected org-agenda-include-diary
1541 :active (org-agenda-check-type nil 'agenda)]
1542 ["Use Time Grid" org-agenda-toggle-time-grid
1543 :style toggle :selected org-agenda-use-time-grid
1544 :active (org-agenda-check-type nil 'agenda)]
1546 ["Show clock report" org-agenda-clockreport-mode
1547 :style toggle :selected org-agenda-clockreport-mode
1548 :active (org-agenda-check-type nil 'agenda)]
1549 ["Show some entry text" org-agenda-entry-text-mode
1550 :style toggle :selected org-agenda-entry-text-mode
1553 ["Show Logbook entries" org-agenda-log-mode
1554 :style toggle :selected org-agenda-show-log
1555 :active (org-agenda-check-type nil 'agenda 'timeline)
1556 :keys "v l (or just l)"]
1557 ["Include archived trees" org-agenda-archives-mode
1558 :style toggle :selected org-agenda-archives-mode :active t
1560 ["Include archive files" (org-agenda-archives-mode t)
1561 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1564 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1565 ["Write view to file" org-write-agenda t]
1566 ["Rebuild buffer" org-agenda-redo t]
1567 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1569 ["Show original entry" org-agenda-show t]
1570 ["Go To (other window)" org-agenda-goto t]
1571 ["Go To (this window)" org-agenda-switch-to t]
1572 ["Follow Mode" org-agenda-follow-mode
1573 :style toggle :selected org-agenda-follow-mode :active t]
1574 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1577 ["Cycle TODO" org-agenda-todo t]
1578 ["Next TODO set" org-agenda-todo-nextset t]
1579 ["Previous TODO set" org-agenda-todo-previousset t]
1580 ["Add note" org-agenda-add-note t])
1581 ("Archive/Refile/Delete"
1582 ["Archive default" org-agenda-archive-default t]
1583 ["Archive default" org-agenda-archive-default-with-confirmation t]
1584 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1585 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1586 ["Archive subtree" org-agenda-archive t]
1588 ["Refile" org-agenda-refile t]
1590 ["Delete subtree" org-agenda-kill t])
1592 ["Mark entry" org-agenda-bulk-mark t]
1593 ["Unmark entry" org-agenda-bulk-unmark t]
1594 ["Act on all marked" org-agenda-bulk-action t]
1595 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1597 ("Tags and Properties"
1598 ["Show all Tags" org-agenda-show-tags t]
1599 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1600 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1602 ["Column View" org-columns t])
1603 ("Deadline/Schedule"
1604 ["Schedule" org-agenda-schedule t]
1605 ["Set Deadline" org-agenda-deadline t]
1607 ["Mark item" org-agenda-action :active t :keys "k m"]
1608 ["Show mark item" org-agenda-action :active t :keys "k v"]
1609 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1610 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1612 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1613 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1614 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1615 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1616 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1617 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1618 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1620 ["Clock in" org-agenda-clock-in t]
1621 ["Clock out" org-agenda-clock-out t]
1622 ["Clock cancel" org-agenda-clock-cancel t]
1623 ["Goto running clock" org-clock-goto t]
1625 ["Set Effort" org-agenda-set-effort t]
1626 ["Change clocked effort" org-clock-modify-effort-estimate
1627 (org-clock-is-active)])
1629 ["Set Priority" org-agenda-priority t]
1630 ["Increase Priority" org-agenda-priority-up t]
1631 ["Decrease Priority" org-agenda-priority-down t]
1632 ["Show Priority" org-agenda-show-priority t])
1634 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1635 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1636 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1637 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1638 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1639 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1641 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1643 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1646 ["Push Files and Views" org-mobile-push t]
1647 ["Get Captured and Flagged" org-mobile-pull t]
1648 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1649 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1651 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1653 ["Quit" org-agenda-quit t]
1654 ["Exit and Release Buffers" org-agenda-exit t]
1659 (defvar org-agenda-allow-remote-undo t
1660 "Non-nil means, allow remote undo from the agenda buffer.")
1661 (defvar org-agenda-undo-list nil
1662 "List of undoable operations in the agenda since last refresh.")
1663 (defvar org-agenda-undo-has-started-in nil
1664 "Buffers that have already seen `undo-start' in the current undo sequence.")
1665 (defvar org-agenda-pending-undo-list nil
1666 "In a series of undo commands, this is the list of remaining undo items.")
1669 (defun org-agenda-undo ()
1670 "Undo a remote editing step in the agenda.
1671 This undoes changes both in the agenda buffer and in the remote buffer
1672 that have been changed along."
1674 (or org-agenda-allow-remote-undo
1675 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1676 (if (not (eq this-command last-command))
1677 (setq org-agenda-undo-has-started-in nil
1678 org-agenda-pending-undo-list org-agenda-undo-list))
1679 (if (not org-agenda-pending-undo-list)
1680 (error "No further undo information"))
1681 (let* ((entry (pop org-agenda-pending-undo-list))
1682 buf line cmd rembuf)
1683 (setq cmd (pop entry) line (pop entry))
1684 (setq rembuf (nth 2 entry))
1685 (org-with-remote-undo rembuf
1686 (while (bufferp (setq buf (pop entry)))
1688 (with-current-buffer buf
1689 (let ((last-undo-buffer buf)
1690 (inhibit-read-only t))
1691 (unless (memq buf org-agenda-undo-has-started-in)
1692 (push buf org-agenda-undo-has-started-in)
1693 (make-local-variable 'pending-undo-list)
1695 (while (and pending-undo-list
1696 (listp pending-undo-list)
1697 (not (car pending-undo-list)))
1698 (pop pending-undo-list))
1700 (org-goto-line line)
1701 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1703 (defun org-verify-change-for-undo (l1 l2)
1704 "Verify that a real change occurred between the undo lists L1 and L2."
1705 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1706 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1711 (defvar org-agenda-restrict nil)
1712 (defvar org-agenda-restrict-begin (make-marker))
1713 (defvar org-agenda-restrict-end (make-marker))
1714 (defvar org-agenda-last-dispatch-buffer nil)
1715 (defvar org-agenda-overriding-restriction nil)
1718 (defun org-agenda (&optional arg keys restriction)
1719 "Dispatch agenda commands to collect entries to the agenda buffer.
1720 Prompts for a command to execute. Any prefix arg will be passed
1721 on to the selected command. The default selections are:
1723 a Call `org-agenda-list' to display the agenda for current day or week.
1724 t Call `org-todo-list' to display the global todo list.
1725 T Call `org-todo-list' to display the global todo list, select only
1726 entries with a specific TODO keyword (the user gets a prompt).
1727 m Call `org-tags-view' to display headlines with tags matching
1728 a condition (the user is prompted for the condition).
1729 M Like `m', but select only TODO entries, no ordinary headlines.
1730 L Create a timeline for the current buffer.
1731 e Export views to associated files.
1732 s Search entries for keywords.
1733 / Multi occur across all agenda files and also files listed
1734 in `org-agenda-text-search-extra-files'.
1735 < Restrict agenda commands to buffer, subtree, or region.
1736 Press several times to get the desired effect.
1737 > Remove a previous restriction.
1738 # List \"stuck\" projects.
1739 ! Configure what \"stuck\" means.
1740 C Configure custom agenda commands.
1742 More commands can be added by configuring the variable
1743 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1744 searches can be pre-defined in this way.
1746 If the current buffer is in Org-mode and visiting a file, you can also
1747 first press `<' once to indicate that the agenda should be temporarily
1748 \(until the next use of \\[org-agenda]) restricted to the current file.
1749 Pressing `<' twice means to restrict to the current subtree or region
1753 (let* ((prefix-descriptions nil)
1754 (org-agenda-window-setup (if (equal (buffer-name)
1755 org-agenda-buffer-name)
1757 org-agenda-window-setup))
1758 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1759 (org-agenda-custom-commands
1760 ;; normalize different versions
1764 (cond ((stringp (cdr x))
1765 (push x prefix-descriptions)
1767 ((stringp (nth 1 x)) x)
1768 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1769 (t (cons (car x) (cons "" (cdr x))))))
1770 org-agenda-custom-commands)))
1771 (buf (current-buffer))
1772 (bfn (buffer-file-name (buffer-base-buffer)))
1773 entry key type match lprops ans)
1774 ;; Turn off restriction unless there is an overriding one,
1775 (unless org-agenda-overriding-restriction
1776 (unless (org-bound-and-true-p org-agenda-keep-restriced-file-list)
1777 ;; There is a request to keep the file list in place
1778 (put 'org-agenda-files 'org-restrict nil))
1779 (setq org-agenda-restrict nil)
1780 (move-marker org-agenda-restrict-begin nil)
1781 (move-marker org-agenda-restrict-end nil))
1782 ;; Delete old local properties
1783 (put 'org-agenda-redo-command 'org-lprops nil)
1784 ;; Remember where this call originated
1785 (setq org-agenda-last-dispatch-buffer (current-buffer))
1787 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1789 restriction (cdr ans)))
1790 ;; Estabish the restriction, if any
1791 (when (and (not org-agenda-overriding-restriction) restriction)
1792 (put 'org-agenda-files 'org-restrict (list bfn))
1794 ((eq restriction 'region)
1795 (setq org-agenda-restrict t)
1796 (move-marker org-agenda-restrict-begin (region-beginning))
1797 (move-marker org-agenda-restrict-end (region-end)))
1798 ((eq restriction 'subtree)
1800 (setq org-agenda-restrict t)
1801 (org-back-to-heading t)
1802 (move-marker org-agenda-restrict-begin (point))
1803 (move-marker org-agenda-restrict-end
1804 (progn (org-end-of-subtree t)))))))
1806 (require 'calendar) ; FIXME: can we avoid this for some commands?
1807 ;; For example the todo list should not need it (but does...)
1809 ((setq entry (assoc keys org-agenda-custom-commands))
1810 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1812 (setq type (nth 2 entry) match (eval (nth 3 entry))
1813 lprops (nth 4 entry))
1814 (put 'org-agenda-redo-command 'org-lprops lprops)
1817 (org-let lprops '(org-agenda-list current-prefix-arg)))
1819 (org-let lprops '(org-todo-list current-prefix-arg)))
1821 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1823 (org-let lprops '(org-agenda-list-stuck-projects
1824 current-prefix-arg)))
1826 (org-let lprops '(org-tags-view current-prefix-arg match)))
1827 ((eq type 'tags-todo)
1828 (org-let lprops '(org-tags-view '(4) match)))
1830 (org-let lprops '(org-todo-list match)))
1831 ((eq type 'tags-tree)
1832 (org-check-for-org-mode)
1833 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1834 ((eq type 'todo-tree)
1835 (org-check-for-org-mode)
1837 '(org-occur (concat "^" outline-regexp "[ \t]*"
1838 (regexp-quote match) "\\>"))))
1839 ((eq type 'occur-tree)
1840 (org-check-for-org-mode)
1841 (org-let lprops '(org-occur match)))
1843 (org-let lprops '(funcall type match)))
1845 (org-let lprops '(funcall type match)))
1846 (t (error "Invalid custom agenda command type %s" type))))
1847 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1849 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1850 (customize-variable 'org-agenda-custom-commands))
1851 ((equal keys "a") (call-interactively 'org-agenda-list))
1852 ((equal keys "s") (call-interactively 'org-search-view))
1853 ((equal keys "t") (call-interactively 'org-todo-list))
1854 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1855 ((equal keys "m") (call-interactively 'org-tags-view))
1856 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1857 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1858 ((equal keys "?") (org-tags-view nil "+FLAGGED")
1862 (unless (current-message)
1863 (let* ((m (org-agenda-get-any-marker))
1864 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
1867 "FLAGGING-NOTE ([?] for more info): "
1869 (replace-regexp-in-string
1871 (copy-sequence note))
1872 nil 'face 'org-warning)))))))
1875 (unless (org-mode-p)
1876 (error "This is not an Org-mode file"))
1878 (put 'org-agenda-files 'org-restrict (list bfn))
1879 (org-call-with-arg 'org-timeline arg)))
1880 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1881 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1882 ((equal keys "!") (customize-variable 'org-stuck-projects))
1883 (t (error "Invalid agenda key"))))))
1885 (defun org-agenda-normalize-custom-commands (cmds)
1889 (cond ((stringp (cdr x)) nil)
1890 ((stringp (nth 1 x)) x)
1891 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1892 (t (cons (car x) (cons "" (cdr x))))))
1895 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1896 "The user interface for selecting an agenda command."
1898 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1899 (restrict-ok (and bfn (org-mode-p)))
1900 (region-p (org-region-active-p))
1901 (custom org-agenda-custom-commands)
1903 restriction second-time
1904 c entry key type match prefixes rmheader header-end custom1 desc)
1905 (save-window-excursion
1906 (delete-other-windows)
1907 (org-switch-to-buffer-other-window " *Agenda Commands*")
1909 (insert (eval-when-compile
1912 Press key for an agenda command: < Buffer, subtree/region restriction
1913 -------------------------------- > Remove restriction
1914 a Agenda for current week or day e Export agenda views
1915 t List of all TODO entries T Entries with special TODO kwd
1916 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1917 L Timeline for current buffer # List stuck projects (!=configure)
1918 s Search for keywords C Configure custom agenda commands
1919 / Multi-occur ? Find :FLAGGED: entries
1922 (while (string-match
1923 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1925 (setq start (match-end 0))
1926 (add-text-properties (match-beginning 2) (match-end 2)
1927 '(face bold) header))
1929 (setq header-end (move-marker (make-marker) (point)))
1931 (setq custom1 custom)
1932 (when (eq rmheader t)
1934 (re-search-forward ":" nil t)
1935 (delete-region (match-end 0) (point-at-eol))
1938 (delete-region (match-end 0) (point-at-eol))
1939 (move-marker header-end (match-end 0)))
1940 (goto-char header-end)
1941 (delete-region (point) (point-max))
1942 (while (setq entry (pop custom1))
1943 (setq key (car entry) desc (nth 1 entry)
1945 match (nth 3 entry))
1946 (if (> (length key) 1)
1947 (add-to-list 'prefixes (string-to-char key))
1951 (org-add-props (copy-sequence key)
1954 ((string-match "\\S-" desc) desc)
1955 ((eq type 'agenda) "Agenda for current week or day")
1956 ((eq type 'alltodo) "List of all TODO entries")
1957 ((eq type 'search) "Word search")
1958 ((eq type 'stuck) "List of stuck projects")
1959 ((eq type 'todo) "TODO keyword")
1960 ((eq type 'tags) "Tags query")
1961 ((eq type 'tags-todo) "Tags (TODO)")
1962 ((eq type 'tags-tree) "Tags tree")
1963 ((eq type 'todo-tree) "TODO kwd tree")
1964 ((eq type 'occur-tree) "Occur tree")
1965 ((functionp type) (if (symbolp type)
1967 "Lambda expression"))
1971 (setq match (copy-sequence match))
1972 (org-add-props match nil 'face 'org-warning))
1974 (format "set of %d commands" (length match)))
1980 (org-add-props (char-to-string x)
1982 (or (cdr (assoc (concat selstring (char-to-string x))
1983 prefix-descriptions))
1986 (goto-char (point-min))
1988 (if (not (pos-visible-in-window-p (point-max)))
1989 (org-fit-window-to-buffer))
1990 (setq second-time t)
1991 (org-fit-window-to-buffer))
1992 (message "Press key for agenda command%s:"
1993 (if (or restrict-ok org-agenda-overriding-restriction)
1994 (if org-agenda-overriding-restriction
1995 " (restriction lock active)"
1997 (format " (restricted to %s)" restriction)
2000 (setq c (read-char-exclusive))
2003 ((assoc (char-to-string c) custom)
2004 (setq selstring (concat selstring (char-to-string c)))
2005 (throw 'exit (cons selstring restriction)))
2007 (setq selstring (concat selstring (char-to-string c))
2009 rmheader (or rmheader t)
2010 custom (delq nil (mapcar
2012 (if (or (= (length (car x)) 1)
2013 (/= (string-to-char (car x)) c))
2015 (cons (substring (car x) 1) (cdr x))))
2017 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2018 (message "Restriction is only possible in Org-mode buffers")
2021 (org-agenda-remove-restriction-lock 'noupdate)
2022 (setq restriction 'buffer))
2024 (org-agenda-remove-restriction-lock 'noupdate)
2025 (setq restriction (if region-p 'region 'subtree)))
2027 (org-agenda-remove-restriction-lock 'noupdate)
2030 ((eq restriction 'buffer)
2031 (if region-p 'region 'subtree))
2032 ((memq restriction '(subtree region))
2036 (org-agenda-remove-restriction-lock 'noupdate)
2037 (setq restriction nil))
2038 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2039 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2040 ((and (> (length selstring) 0) (eq c ?\d))
2042 (org-agenda-get-restriction-and-command prefix-descriptions))
2044 ((equal c ?q) (error "Abort"))
2045 (t (error "Invalid key %c" c))))))))
2047 (defun org-run-agenda-series (name series)
2048 (org-let (nth 1 series) '(org-prepare-agenda name))
2049 (let* ((org-agenda-multi t)
2050 (redo (list 'org-run-agenda-series name (list 'quote series)))
2052 (gprops (nth 1 series))
2053 match ;; The byte compiler incorrectly complains about this. Keep it!
2055 (while (setq cmd (pop cmds))
2056 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2059 (org-let2 gprops lprops
2060 '(call-interactively 'org-agenda-list)))
2062 (org-let2 gprops lprops
2063 '(call-interactively 'org-todo-list)))
2065 (org-let2 gprops lprops
2066 '(org-search-view current-prefix-arg match nil)))
2068 (org-let2 gprops lprops
2069 '(call-interactively 'org-agenda-list-stuck-projects)))
2071 (org-let2 gprops lprops
2072 '(org-tags-view current-prefix-arg match)))
2073 ((eq type 'tags-todo)
2074 (org-let2 gprops lprops
2075 '(org-tags-view '(4) match)))
2077 (org-let2 gprops lprops
2078 '(org-todo-list match)))
2080 (org-let2 gprops lprops
2081 '(funcall type match)))
2082 (t (error "Invalid type in command series"))))
2084 (setq org-agenda-redo-command redo)
2085 (goto-char (point-min)))
2086 (org-fit-agenda-window)
2087 (org-let (nth 1 series) '(org-finalize-agenda)))
2090 (defmacro org-batch-agenda (cmd-key &rest parameters)
2091 "Run an agenda command in batch mode and send the result to STDOUT.
2092 If CMD-KEY is a string of length 1, it is used as a key in
2093 `org-agenda-custom-commands' and triggers this command. If it is a
2094 longer string it is used as a tags/todo match string.
2095 Paramters are alternating variable names and values that will be bound
2096 before running the agenda command."
2099 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2100 (if (> (length cmd-key) 2)
2101 (eval (list 'let (nreverse pars)
2102 (list 'org-tags-view nil cmd-key)))
2103 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2104 (set-buffer org-agenda-buffer-name)
2105 (princ (org-encode-for-stdout (buffer-string)))))
2107 ;(defun org-encode-for-stdout (string)
2108 ; (if (fboundp 'encode-coding-string)
2109 ; (encode-coding-string string buffer-file-coding-system)
2112 (defun org-encode-for-stdout (string)
2115 (defvar org-agenda-info nil)
2118 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2119 "Run an agenda command in batch mode and send the result to STDOUT.
2120 If CMD-KEY is a string of length 1, it is used as a key in
2121 `org-agenda-custom-commands' and triggers this command. If it is a
2122 longer string it is used as a tags/todo match string.
2123 Paramters are alternating variable names and values that will be bound
2124 before running the agenda command.
2126 The output gives a line for each selected agenda item. Each
2127 item is a list of comma-separated values, like this:
2129 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2131 category The category of the item
2132 head The headline, without TODO kwd, TAGS and PRIORITY
2133 type The type of the agenda entry, can be
2134 todo selected in TODO match
2135 tagsmatch selected in tags match
2136 diary imported from diary
2137 deadline a deadline on given date
2138 scheduled scheduled on given date
2139 timestamp entry has timestamp on given date
2140 closed entry was closed on given date
2141 upcoming-deadline warning about deadline
2142 past-scheduled forwarded scheduled item
2143 block entry has date block including g. date
2144 todo The todo keyword, if any
2145 tags All tags including inherited ones, separated by colons
2146 date The relevant date, like 2007-2-14
2147 time The time, like 15:00-16:50
2148 extra Sting with extra planning info
2149 priority-l The priority letter if any was given
2150 priority-n The computed numerical priority
2151 agenda-day The day in the agenda where this is listed"
2155 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2156 (push (list 'org-agenda-remove-tags t) pars)
2157 (if (> (length cmd-key) 2)
2158 (eval (list 'let (nreverse pars)
2159 (list 'org-tags-view nil cmd-key)))
2160 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2161 (set-buffer org-agenda-buffer-name)
2162 (let* ((lines (org-split-string (buffer-string) "\n"))
2164 (while (setq line (pop lines))
2166 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2167 (setq org-agenda-info
2168 (org-fix-agenda-info (text-properties-at 0 line)))
2170 (org-encode-for-stdout
2171 (mapconcat 'org-agenda-export-csv-mapper
2172 '(org-category txt type todo tags date time-of-day extra
2173 priority-letter priority agenda-day)
2177 (defun org-fix-agenda-info (props)
2178 "Make sure all properties on an agenda item have a canonical form,
2179 so the export commands can easily use it."
2181 (when (setq tmp (plist-get props 'tags))
2182 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2183 (when (setq tmp (plist-get props 'date))
2184 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2185 (let ((calendar-date-display-form '(year "-" month "-" day)))
2186 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2188 (setq tmp (calendar-date-string tmp)))
2189 (setq props (plist-put props 'date tmp)))
2190 (when (setq tmp (plist-get props 'day))
2191 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2192 (let ((calendar-date-display-form '(year "-" month "-" day)))
2193 (setq tmp (calendar-date-string tmp)))
2194 (setq props (plist-put props 'day tmp))
2195 (setq props (plist-put props 'agenda-day tmp)))
2196 (when (setq tmp (plist-get props 'txt))
2197 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2198 (plist-put props 'priority-letter (match-string 1 tmp))
2199 (setq tmp (replace-match "" t t tmp)))
2200 (when (and (setq re (plist-get props 'org-todo-regexp))
2201 (setq re (concat "\\`\\.*" re " ?"))
2202 (string-match re tmp))
2203 (plist-put props 'todo (match-string 1 tmp))
2204 (setq tmp (replace-match "" t t tmp)))
2205 (plist-put props 'txt tmp)))
2208 (defun org-agenda-export-csv-mapper (prop)
2209 (let ((res (plist-get org-agenda-info prop)))
2214 (t (prin1-to-string res))))
2215 (while (string-match "," res)
2216 (setq res (replace-match ";" t t res)))
2221 (defun org-store-agenda-views (&rest parameters)
2223 (eval (list 'org-batch-store-agenda-views)))
2225 ;; FIXME, why is this a macro?????
2227 (defmacro org-batch-store-agenda-views (&rest parameters)
2228 "Run all custom agenda commands that have a file argument."
2229 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2231 (dir default-directory)
2232 pars cmd thiscmdkey files opts cmd-or-set)
2234 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2235 (setq pars (reverse pars))
2236 (save-window-excursion
2238 (setq cmd (pop cmds)
2239 thiscmdkey (car cmd)
2240 cmd-or-set (nth 2 cmd)
2241 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2242 files (nth (if (listp cmd-or-set) 4 5) cmd))
2243 (if (stringp files) (setq files (list files)))
2245 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2246 (list 'org-agenda nil thiscmdkey)))
2247 (set-buffer org-agenda-buffer-name)
2249 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2250 (list 'org-write-agenda
2251 (expand-file-name (pop files) dir) nil t))))
2252 (and (get-buffer org-agenda-buffer-name)
2253 (kill-buffer org-agenda-buffer-name)))))))
2255 (defun org-agenda-mark-header-line (pos)
2256 "Mark the line at POS as an agenda structure header."
2259 (put-text-property (point-at-bol) (point-at-eol)
2260 'org-agenda-structural-header t)
2261 (when org-agenda-title-append
2262 (put-text-property (point-at-bol) (point-at-eol)
2263 'org-agenda-title-append org-agenda-title-append))))
2265 (defvar org-mobile-creating-agendas)
2266 (defun org-write-agenda (file &optional open nosettings)
2267 "Write the current buffer (an agenda view) as a file.
2268 Depending on the extension of the file name, plain text (.txt),
2269 HTML (.html or .htm) or Postscript (.ps) is produced.
2270 If the extension is .ics, run icalendar export over all files used
2271 to construct the agenda and limit the export to entries listed in the
2273 With prefic argument OPEN, open the new file immediately.
2274 If NOSETTINGS is given, do not scope the settings of
2275 `org-agenda-exporter-settings' into the export commands. This is used when
2276 the settings have already been scoped and we do not wish to overrule other,
2277 higher priority settings."
2278 (interactive "FWrite agenda to file: \nP")
2279 (if (not (file-writable-p file))
2280 (error "Cannot write agenda to file %s" file))
2282 ((string-match "\\.html?\\'" file) (require 'htmlize))
2283 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2284 (org-let (if nosettings nil org-agenda-exporter-settings)
2286 (save-window-excursion
2287 (org-agenda-mark-filtered-text)
2288 (let ((bs (copy-sequence (buffer-string))) beg)
2289 (org-agenda-unmark-filtered-text)
2292 (org-agenda-remove-marked-text 'org-filtered)
2293 (while (setq beg (text-property-any (point-min) (point-max)
2296 beg (or (next-single-property-change beg 'org-filtered)
2298 (run-hooks 'org-agenda-before-write-hook)
2300 ((org-bound-and-true-p org-mobile-creating-agendas)
2301 (org-mobile-write-agenda-for-mobile file))
2302 ((string-match "\\.html?\\'" file)
2303 (set-buffer (htmlize-buffer (current-buffer)))
2305 (when (and org-agenda-export-html-style
2306 (string-match "<style>" org-agenda-export-html-style))
2307 ;; replace <style> section with org-agenda-export-html-style
2308 (goto-char (point-min))
2309 (kill-region (- (search-forward "<style") 6)
2310 (search-forward "</style>"))
2311 (insert org-agenda-export-html-style))
2313 (kill-buffer (current-buffer))
2314 (message "HTML written to %s" file))
2315 ((string-match "\\.ps\\'" file)
2317 (flet ((ps-get-buffer-name () "Agenda View"))
2318 (ps-print-buffer-with-faces file))
2319 (message "Postscript written to %s" file))
2320 ((string-match "\\.pdf\\'" file)
2322 (flet ((ps-get-buffer-name () "Agenda View"))
2323 (ps-print-buffer-with-faces
2324 (concat (file-name-sans-extension file) ".ps")))
2325 (call-process "ps2pdf" nil nil nil
2327 (concat (file-name-sans-extension file) ".ps"))
2328 (expand-file-name file))
2329 (message "PDF written to %s" file))
2330 ((string-match "\\.ics\\'" file)
2331 (require 'org-icalendar)
2332 (let ((org-agenda-marker-table
2333 (org-create-marker-find-array
2334 (org-agenda-collect-markers)))
2335 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2336 (org-combined-agenda-icalendar-file file))
2337 (apply 'org-export-icalendar 'combine
2338 (org-agenda-files nil 'ifmode))))
2340 (let ((bs (buffer-string)))
2345 (kill-buffer (current-buffer))
2346 (message "Plain text written to %s" file))))))))
2347 (set-buffer org-agenda-buffer-name))
2348 (when open (org-open-file file)))
2350 (defvar org-agenda-filter-overlays nil)
2352 (defun org-agenda-mark-filtered-text ()
2353 "Mark all text hidden by filtering with a text property."
2354 (let ((inhibit-read-only t))
2357 (when (equal (org-overlay-buffer o) (current-buffer))
2359 (org-overlay-start o) (org-overlay-end o)
2361 org-agenda-filter-overlays)))
2363 (defun org-agenda-unmark-filtered-text ()
2364 "Remove the filtering text property."
2365 (let ((inhibit-read-only t))
2366 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2368 (defun org-agenda-remove-marked-text (property &optional value)
2369 "Delete all text marked with VALUE of PROPERTY.
2370 VALUE defaults to t."
2372 (setq value (or value t))
2373 (while (setq beg (text-property-any (point-min) (point-max)
2376 beg (or (next-single-property-change beg 'org-filtered)
2379 (defun org-agenda-add-entry-text ()
2380 "Add entry text to agenda lines.
2381 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2382 entry text following headings shown in the agenda.
2383 Drawers will be excluded, also the line with scheduling/deadline info."
2384 (when (and (> org-agenda-add-entry-text-maxlines 0)
2385 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2387 (goto-char (point-min))
2389 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2390 (beginning-of-line 2)
2391 (setq txt (org-agenda-get-some-entry-text
2392 m org-agenda-add-entry-text-maxlines " > "))
2394 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2396 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2398 "Extract entry text from MARKER, at most N-LINES lines.
2399 This will ignore drawers etc, just get the text.
2400 If INDENT is given, prefix every line with this string. If KEEP is
2401 given, it is a list of symbols, defining stuff that hould not be
2402 removed from the entry content. Currently only `planning' is allowed here."
2403 (let (txt drawer-re kwd-time-re ind)
2405 (with-current-buffer (marker-buffer marker)
2406 (if (not (org-mode-p))
2413 (setq txt (buffer-substring
2414 (min (1+ (point)) (point-max))
2415 (progn (outline-next-heading) (point)))
2416 drawer-re org-drawer-regexp
2417 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2421 (when org-agenda-add-entry-text-descriptive-links
2422 (goto-char (point-min))
2423 (while (org-activate-bracket-links (point-max))
2424 (add-text-properties (match-beginning 0) (match-end 0)
2426 (goto-char (point-min))
2427 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2428 (set-text-properties (match-beginning 0) (match-end 0)
2430 (goto-char (point-min))
2431 (while (re-search-forward drawer-re nil t)
2434 (progn (re-search-forward
2435 "^[ \t]*:END:.*\n?" nil 'move)
2437 (unless (member 'planning keep)
2438 (goto-char (point-min))
2439 (while (re-search-forward kwd-time-re nil t)
2440 (replace-match "")))
2441 (goto-char (point-min))
2442 (when org-agenda-entry-text-exclude-regexps
2443 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2444 (while (setq re (pop re-list))
2445 (goto-char (point-min))
2446 (while (re-search-forward re nil t)
2447 (replace-match "")))))
2448 (goto-char (point-max))
2449 (skip-chars-backward " \t\n")
2450 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2452 ;; find and remove min common indentation
2453 (goto-char (point-min))
2454 (untabify (point-min) (point-max))
2455 (setq ind (org-get-indentation))
2457 (unless (looking-at "[ \t]*$")
2458 (setq ind (min ind (org-get-indentation))))
2459 (beginning-of-line 2))
2460 (goto-char (point-min))
2462 (unless (looking-at "[ \t]*$")
2463 (move-to-column ind)
2464 (delete-region (point-at-bol) (point)))
2465 (beginning-of-line 2))
2467 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2469 (goto-char (point-min))
2471 (while (and (not (eobp)) (re-search-forward "^" nil t))
2472 (replace-match indent t t)))
2473 (goto-char (point-min))
2474 (while (looking-at "[ \t]*\n") (replace-match ""))
2475 (goto-char (point-max))
2476 (when (> (org-current-line)
2478 (org-goto-line (1+ n-lines))
2480 (setq txt (buffer-substring (point-min) (point)))))))))
2483 (defun org-agenda-collect-markers ()
2484 "Collect the markers pointing to entries in the agenda buffer."
2487 (goto-char (point-min))
2489 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2490 (org-get-at-bol 'org-marker)))
2492 (beginning-of-line 2)))
2493 (nreverse markers)))
2495 (defun org-create-marker-find-array (marker-list)
2496 "Create a alist of files names with all marker positions in that file."
2498 (while (setq m (pop marker-list))
2499 (setq p (marker-position m)
2500 f (buffer-file-name (or (buffer-base-buffer
2502 (marker-buffer m))))
2503 (if (setq a (assoc f tbl))
2504 (push (marker-position m) (cdr a))
2505 (push (list f p) tbl)))
2506 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2509 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2510 (defun org-check-agenda-marker-table ()
2511 "Check of the current entry is on the marker list."
2512 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2514 (and (setq a (assoc file org-agenda-marker-table))
2517 (org-back-to-heading t)
2518 (member (point) (cdr a)))))))
2520 (defun org-check-for-org-mode ()
2521 "Make sure current buffer is in org-mode. Error if not."
2523 (error "Cannot execute org-mode agenda command on buffer in %s"
2526 (defun org-fit-agenda-window ()
2527 "Fit the window to the buffer size."
2528 (and (memq org-agenda-window-setup '(reorganize-frame))
2529 (fboundp 'fit-window-to-buffer)
2530 (org-fit-window-to-buffer
2532 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2533 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2535 ;;; Agenda prepare and finalize
2537 (defvar org-agenda-multi nil) ; dynamically scoped
2538 (defvar org-agenda-buffer-name "*Org Agenda*")
2539 (defvar org-pre-agenda-window-conf nil)
2540 (defvar org-agenda-columns-active nil)
2541 (defvar org-agenda-name nil)
2542 (defvar org-agenda-filter nil)
2543 (defvar org-agenda-filter-preset nil
2544 "A preset of the tags filter used for secondary agenda filtering.
2545 This must be a list of strings, each string must be a single tag preceeded
2547 This variable should not be set directly, but agenda custom commands can
2548 bind it in the options section.")
2550 (defun org-prepare-agenda (&optional name)
2551 (setq org-todo-keywords-for-agenda nil)
2552 (setq org-done-keywords-for-agenda nil)
2553 (setq org-drawers-for-agenda nil)
2554 (setq org-agenda-filter nil)
2555 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2556 (if org-agenda-multi
2558 (setq buffer-read-only nil)
2559 (goto-char (point-max))
2560 (unless (or (bobp) org-agenda-compact-blocks)
2562 (if (stringp org-agenda-block-separator)
2563 org-agenda-block-separator
2564 (make-string (window-width) org-agenda-block-separator))
2566 (narrow-to-region (point) (point-max)))
2567 (org-agenda-reset-markers)
2568 (setq org-agenda-contributing-files nil)
2569 (setq org-agenda-columns-active nil)
2570 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2571 (setq org-todo-keywords-for-agenda
2572 (org-uniquify org-todo-keywords-for-agenda))
2573 (setq org-done-keywords-for-agenda
2574 (org-uniquify org-done-keywords-for-agenda))
2575 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2576 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2577 (awin (get-buffer-window abuf)))
2579 ((equal (current-buffer) abuf) nil)
2580 (awin (select-window awin))
2581 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2582 ((equal org-agenda-window-setup 'current-window)
2583 (switch-to-buffer abuf))
2584 ((equal org-agenda-window-setup 'other-window)
2585 (org-switch-to-buffer-other-window abuf))
2586 ((equal org-agenda-window-setup 'other-frame)
2587 (switch-to-buffer-other-frame abuf))
2588 ((equal org-agenda-window-setup 'reorganize-frame)
2589 (delete-other-windows)
2590 (org-switch-to-buffer-other-window abuf))))
2591 (setq buffer-read-only nil)
2592 (let ((inhibit-read-only t)) (erase-buffer))
2594 (and name (not org-agenda-name)
2595 (org-set-local 'org-agenda-name name)))
2596 (setq buffer-read-only nil))
2598 (defun org-finalize-agenda ()
2599 "Finishing touch for the agenda buffer, called just before displaying it."
2600 (unless org-agenda-multi
2602 (let ((inhibit-read-only t))
2603 (goto-char (point-min))
2604 (while (org-activate-bracket-links (point-max))
2605 (add-text-properties (match-beginning 0) (match-end 0)
2607 (org-agenda-align-tags)
2608 (unless org-agenda-with-colors
2609 (remove-text-properties (point-min) (point-max) '(face nil))))
2610 (if (and (boundp 'org-agenda-overriding-columns-format)
2611 org-agenda-overriding-columns-format)
2612 (org-set-local 'org-agenda-overriding-columns-format
2613 org-agenda-overriding-columns-format))
2614 (if (and (boundp 'org-agenda-view-columns-initially)
2615 org-agenda-view-columns-initially)
2616 (org-agenda-columns))
2617 (when org-agenda-fontify-priorities
2618 (org-agenda-fontify-priorities))
2619 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2620 (org-agenda-dim-blocked-tasks))
2621 (org-agenda-mark-clocking-task)
2622 (when org-agenda-entry-text-mode
2623 (org-agenda-entry-text-hide)
2624 (org-agenda-entry-text-show))
2625 (if (functionp 'org-habit-insert-consistency-graphs)
2626 (org-habit-insert-consistency-graphs))
2627 (run-hooks 'org-finalize-agenda-hook)
2628 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2629 (when (get 'org-agenda-filter :preset-filter)
2630 (org-agenda-filter-apply org-agenda-filter))
2633 (defun org-agenda-mark-clocking-task ()
2634 "Mark the current clock entry in the agenda if it is present."
2636 (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
2637 (org-delete-overlay o)))
2638 (org-overlays-in (point-min) (point-max)))
2639 (when (marker-buffer org-clock-hd-marker)
2641 (goto-char (point-min))
2643 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2645 (when (equal (org-get-at-bol 'org-hd-marker)
2646 org-clock-hd-marker)
2647 (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2648 (org-overlay-put ov 'type 'org-agenda-clocking)
2649 (org-overlay-put ov 'face 'org-agenda-clocking)
2650 (org-overlay-put ov 'help-echo
2651 "The clock is running in this item")))))))
2653 (defun org-agenda-fontify-priorities ()
2654 "Make highest priority lines bold, and lowest italic."
2656 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
2657 (org-delete-overlay o)))
2658 (org-overlays-in (point-min) (point-max)))
2660 (let ((inhibit-read-only t)
2662 (goto-char (point-min))
2663 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2664 (setq h (or (get-char-property (point) 'org-highest-priority)
2665 org-highest-priority)
2666 l (or (get-char-property (point) 'org-lowest-priority)
2667 org-lowest-priority)
2668 p (string-to-char (match-string 1))
2669 b (match-beginning 0)
2670 e (if (eq org-agenda-fontify-priorities 'cookies)
2673 ov (org-make-overlay b e))
2676 (cond ((cdr (assoc p org-priority-faces)))
2677 ((and (listp org-agenda-fontify-priorities)
2678 (cdr (assoc p org-agenda-fontify-priorities))))
2679 ((equal p l) 'italic)
2680 ((equal p h) 'bold)))
2681 (org-overlay-put ov 'org-type 'org-priority)))))
2683 (defun org-agenda-dim-blocked-tasks ()
2684 "Dim currently blocked TODO's in the agenda display."
2685 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
2686 (org-delete-overlay o)))
2687 (org-overlays-in (point-min) (point-max)))
2689 (let ((inhibit-read-only t)
2690 (org-depend-tag-blocked nil)
2691 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2692 org-blocked-by-checkboxes
2693 invis1 b e p ov h l)
2694 (goto-char (point-min))
2695 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2696 (and pos (goto-char (1+ pos))))
2697 (setq org-blocked-by-checkboxes nil invis1 invis)
2698 (let ((marker (org-get-at-bol 'org-hd-marker)))
2700 (not (with-current-buffer (marker-buffer marker)
2703 (if (org-entry-get nil "NOBLOCKING")
2704 t ;; Never block this entry
2705 (run-hook-with-args-until-failure
2707 (list :type 'todo-state-change
2711 (if org-blocked-by-checkboxes (setq invis1 nil))
2713 (max (point-min) (1- (point-at-bol)))
2716 ov (org-make-overlay b e))
2718 (org-overlay-put ov 'invisible t)
2719 (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2720 (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
2722 (defvar org-agenda-skip-function nil
2723 "Function to be called at each match during agenda construction.
2724 If this function returns nil, the current match should not be skipped.
2725 Otherwise, the function must return a position from where the search
2726 should be continued.
2727 This may also be a Lisp form, it will be evaluated.
2728 Never set this variable using `setq' or so, because then it will apply
2729 to all future agenda commands. Instead, bind it with `let' to scope
2730 it dynamically into the agenda-constructing command. A good way to set
2731 it is through options in org-agenda-custom-commands.")
2733 (defun org-agenda-skip ()
2734 "Throw to `:skip' in places that should be skipped.
2735 Also moves point to the end of the skipped region, so that search can
2736 continue from there."
2737 (let ((p (point-at-bol)) to fp)
2738 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2739 (get-text-property p :org-archived)
2740 (org-end-of-subtree t)
2742 (and org-agenda-skip-comment-trees
2743 (get-text-property p :org-comment)
2744 (org-end-of-subtree t)
2746 (if (equal (char-after p) ?#) (throw :skip t))
2747 (when (and (or (setq fp (functionp org-agenda-skip-function))
2748 (consp org-agenda-skip-function))
2749 (setq to (save-excursion
2752 (funcall org-agenda-skip-function)
2753 (eval org-agenda-skip-function))))))
2757 (defvar org-agenda-markers nil
2758 "List of all currently active markers created by `org-agenda'.")
2759 (defvar org-agenda-last-marker-time (org-float-time)
2760 "Creation time of the last agenda marker.")
2762 (defun org-agenda-new-marker (&optional pos)
2763 "Return a new agenda marker.
2764 Org-mode keeps a list of these markers and resets them when they are
2766 (let ((m (copy-marker (or pos (point)))))
2767 (setq org-agenda-last-marker-time (org-float-time))
2768 (push m org-agenda-markers)
2771 (defun org-agenda-reset-markers ()
2772 "Reset markers created by `org-agenda'."
2773 (while org-agenda-markers
2774 (move-marker (pop org-agenda-markers) nil)))
2776 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2777 "Save relative positions of markers in region."
2778 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2779 org-agenda-markers))
2783 (defun org-agenda-entry-text-show-here ()
2784 "Add some text from te entry as context to the current line."
2786 (setq m (org-get-at-bol 'org-hd-marker))
2787 (unless (marker-buffer m)
2788 (error "No marker points to an entry here"))
2789 (setq txt (concat "\n" (org-no-properties
2790 (org-agenda-get-some-entry-text
2791 m org-agenda-entry-text-maxlines " > "))))
2792 (when (string-match "\\S-" txt)
2793 (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
2794 (org-overlay-put o 'evaporate t)
2795 (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
2796 (org-overlay-put o 'after-string txt))))
2798 (defun org-agenda-entry-text-show ()
2799 "Add entry context for all agenda lines."
2802 (goto-char (point-max))
2803 (beginning-of-line 1)
2805 (when (org-get-at-bol 'org-hd-marker)
2806 (org-agenda-entry-text-show-here))
2807 (beginning-of-line 0))))
2809 (defun org-agenda-entry-text-hide ()
2810 "Remove any shown entry context."
2813 (if (eq (org-overlay-get o 'org-overlay-type)
2814 'agenda-entry-content)
2815 (progn (org-delete-overlay o) t)))
2816 (org-overlays-in (point-min) (point-max)))))
2820 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2822 (defun org-timeline (&optional include-all)
2823 "Show a time-sorted view of the entries in the current org file.
2824 Only entries with a time stamp of today or later will be listed. With
2825 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2826 under the current date.
2827 If the buffer contains an active region, only check the region for
2831 (org-compile-prefix-format 'timeline)
2832 (org-set-sorting-strategy 'timeline)
2834 (dotodo include-all)
2835 (doclosed org-agenda-show-log)
2836 (entry buffer-file-name)
2837 (date (calendar-current-date))
2838 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2839 (end (if (org-region-active-p) (region-end) (point-max)))
2840 (day-numbers (org-get-all-dates beg end 'no-ranges
2841 t doclosed ; always include today
2842 org-timeline-show-empty-dates))
2843 (org-deadline-warning-days 0)
2844 (org-agenda-only-exact-dates t)
2845 (today (time-to-days (current-time)))
2848 s e rtn d emptyp wd)
2849 (setq org-agenda-redo-command
2851 (list 'org-switch-to-buffer-other-window (current-buffer))
2852 (list 'org-timeline (list 'quote include-all))))
2854 ;; Remove past dates from the list of dates.
2855 (setq day-numbers (delq nil (mapcar (lambda(x)
2856 (if (>= x today) x nil))
2858 (org-prepare-agenda (concat "Timeline "
2859 (file-name-nondirectory buffer-file-name)))
2860 (if doclosed (push :closed args))
2861 (push :timestamp args)
2862 (push :deadline args)
2863 (push :scheduled args)
2865 (if dotodo (push :todo args))
2866 (insert "Timeline of file " entry "\n")
2867 (add-text-properties (point-min) (point)
2868 (list 'face 'org-agenda-structure))
2869 (org-agenda-mark-header-line (point-min))
2870 (while (setq d (pop day-numbers))
2871 (if (and (listp d) (eq (car d) :omitted))
2874 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2875 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2876 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2877 (if (and (>= d today)
2882 (insert (make-string 79 ?-) "\n")))
2883 (setq date (calendar-gregorian-from-absolute d)
2884 wd (calendar-day-of-week date))
2886 (setq rtn (and (not emptyp)
2887 (apply 'org-agenda-get-day-entries entry
2889 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2892 (if (stringp org-agenda-format-date)
2893 (format-time-string org-agenda-format-date
2894 (org-time-from-absolute date))
2895 (funcall org-agenda-format-date date))
2897 (put-text-property s (1- (point)) 'face
2898 (if (member wd org-agenda-weekend-days)
2899 'org-agenda-date-weekend
2901 (put-text-property s (1- (point)) 'org-date-line t)
2902 (put-text-property s (1- (point)) 'org-agenda-date-header t)
2904 (put-text-property s (1- (point)) 'org-today t))
2905 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2906 (put-text-property s (1- (point)) 'day d)))))
2907 (goto-char (point-min))
2908 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2910 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2911 (org-finalize-agenda)
2912 (setq buffer-read-only t)))
2914 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2915 "Return a list of all relevant day numbers from BEG to END buffer positions.
2916 If NO-RANGES is non-nil, include only the start and end dates of a range,
2917 not every single day in the range. If FORCE-TODAY is non-nil, make
2918 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2919 inactive time stamps (those in square brackets) are included.
2920 When EMPTY is non-nil, also include days without any entries."
2922 (if pre-re pre-re "")
2923 (if inactive org-ts-regexp-both org-ts-regexp)))
2924 dates dates1 date day day1 day2 ts1 ts2)
2926 (setq dates (list (time-to-days (current-time)))))
2929 (while (re-search-forward re end t)
2930 (setq day (time-to-days (org-time-string-to-time
2931 (substring (match-string 1) 0 10))))
2932 (or (memq day dates) (push day dates)))
2935 (while (re-search-forward org-tr-regexp end t)
2936 (setq ts1 (substring (match-string 1) 0 10)
2937 ts2 (substring (match-string 2) 0 10)
2938 day1 (time-to-days (org-time-string-to-time ts1))
2939 day2 (time-to-days (org-time-string-to-time ts2)))
2940 (while (< (setq day1 (1+ day1)) day2)
2941 (or (memq day1 dates) (push day1 dates)))))
2942 (setq dates (sort dates '<))
2944 (while (setq day (pop dates))
2945 (setq day2 (car dates))
2947 (when (and day2 empty)
2948 (if (or (eq empty t)
2949 (and (numberp empty) (<= (- day2 day) empty)))
2950 (while (< (setq day (1+ day)) day2)
2951 (push (list day) dates1))
2952 (push (cons :omitted (- day2 day)) dates1))))
2953 (setq dates (nreverse dates1)))
2956 ;;; Agenda Daily/Weekly
2958 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2959 (defvar org-agenda-start-day nil ; dynamically scoped parameter
2960 "Custom commands can set this variable in the options section.")
2961 (defvar org-agenda-last-arguments nil
2962 "The arguments of the previous call to org-agenda")
2963 (defvar org-starting-day nil) ; local variable in the agenda buffer
2964 (defvar org-agenda-span nil) ; local variable in the agenda buffer
2965 (defvar org-include-all-loc nil) ; local variable
2966 (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
2969 (defun org-agenda-list (&optional include-all start-day ndays)
2970 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2971 The view will be for the current day or week, but from the overview buffer
2972 you will be able to go to other days/weeks.
2974 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2975 all unfinished TODO items will also be shown, before the agenda.
2976 This feature is considered obsolete, please use the TODO list or a block
2979 With a numeric prefix argument in an interactive call, the agenda will
2980 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2981 the number of days. NDAYS defaults to `org-agenda-ndays'.
2983 START-DAY defaults to TODAY, or to the most recent match for the weekday
2984 given in `org-agenda-start-on-weekday'."
2986 (if (and (integerp include-all) (> include-all 0))
2987 (setq ndays include-all include-all nil))
2988 (setq ndays (or ndays org-agenda-ndays)
2989 start-day (or start-day org-agenda-start-day))
2990 (if org-agenda-overriding-arguments
2991 (setq include-all (car org-agenda-overriding-arguments)
2992 start-day (nth 1 org-agenda-overriding-arguments)
2993 ndays (nth 2 org-agenda-overriding-arguments)))
2994 (if (stringp start-day)
2995 ;; Convert to an absolute day number
2996 (setq start-day (time-to-days (org-read-date nil t start-day))))
2997 (setq org-agenda-last-arguments (list include-all start-day ndays))
2998 (org-compile-prefix-format 'agenda)
2999 (org-set-sorting-strategy 'agenda)
3001 (let* ((org-agenda-start-on-weekday
3002 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3003 org-agenda-start-on-weekday nil))
3004 (thefiles (org-agenda-files nil 'ifmode))
3006 (today (time-to-days
3007 (time-subtract (current-time)
3008 (list 0 (* 3600 org-extend-today-until) 0))))
3009 (sd (or start-day today))
3010 (start (if (or (null org-agenda-start-on-weekday)
3011 (< org-agenda-ndays 7))
3013 (let* ((nt (calendar-day-of-week
3014 (calendar-gregorian-from-absolute sd)))
3015 (n1 org-agenda-start-on-weekday)
3017 (- sd (+ (if (< d 0) 7 0) d)))))
3018 (day-numbers (list start))
3020 (inhibit-redisplay (not debug-on-error))
3021 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3022 clocktable-start clocktable-end)
3023 (setq org-agenda-redo-command
3024 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3025 ;; Make the list of days
3026 (setq ndays (or ndays org-agenda-ndays)
3029 (push (1+ (car day-numbers)) day-numbers)
3030 (setq ndays (1- ndays)))
3031 (setq day-numbers (nreverse day-numbers))
3032 (setq clocktable-start (car day-numbers)
3033 clocktable-end (1+ (or (org-last day-numbers) 0)))
3034 (org-prepare-agenda "Day/Week")
3035 (org-set-local 'org-starting-day (car day-numbers))
3036 (org-set-local 'org-include-all-loc include-all)
3037 (org-set-local 'org-agenda-span
3038 (org-agenda-ndays-to-span nd))
3039 (when (and (or include-all org-agenda-include-all-todo)
3040 (member today day-numbers))
3041 (setq files thefiles
3043 (while (setq file (pop files))
3045 (org-check-agenda-file file)
3046 (setq date (calendar-gregorian-from-absolute today)
3047 rtn (org-agenda-get-day-entries
3049 (setq rtnall (append rtnall rtn))))
3051 (insert "All currently open TODO items:\n")
3052 (add-text-properties (point-min) (1- (point))
3053 (list 'face 'org-agenda-structure
3054 'short-heading "All TODO items"))
3055 (org-agenda-mark-header-line (point-min))
3056 (insert (org-finalize-agenda-entries rtnall) "\n")))
3057 (unless org-agenda-compact-blocks
3058 (let* ((d1 (car day-numbers))
3059 (d2 (org-last day-numbers))
3060 (w1 (org-days-to-iso-week d1))
3061 (w2 (org-days-to-iso-week d2)))
3063 (if org-agenda-overriding-header
3064 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3065 nil 'face 'org-agenda-structure) "\n")
3066 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3068 (if (< (- d2 d1) 350)
3070 (format " (W%02d)" w1)
3071 (format " (W%02d-W%02d)" w1 w2))
3074 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3076 (org-agenda-mark-header-line s))
3077 (while (setq d (pop day-numbers))
3078 (setq date (calendar-gregorian-from-absolute d)
3079 wd (calendar-day-of-week date)
3081 (if (or (setq todayp (= d today))
3082 (and (not start-pos) (= d sd)))
3083 (setq start-pos (point))
3084 (if (and start-pos (not end-pos))
3085 (setq end-pos (point))))
3086 (setq files thefiles
3088 (while (setq file (pop files))
3090 (org-check-agenda-file file)
3092 ((eq org-agenda-show-log 'only)
3093 (setq rtn (org-agenda-get-day-entries
3094 file date :closed)))
3095 (org-agenda-show-log
3096 (setq rtn (org-agenda-get-day-entries
3098 :deadline :scheduled :timestamp :sexp :closed)))
3100 (setq rtn (org-agenda-get-day-entries
3102 :deadline :scheduled :sexp :timestamp))))
3103 (setq rtnall (append rtnall rtn))))
3104 (if org-agenda-include-diary
3105 (let ((org-agenda-search-headline-for-time t))
3106 (require 'diary-lib)
3107 (setq rtn (org-get-entries-from-diary date))
3108 (setq rtnall (append rtnall rtn))))
3109 (if (or rtnall org-agenda-show-all-dates)
3111 (setq day-cnt (1+ day-cnt))
3113 (if (stringp org-agenda-format-date)
3114 (format-time-string org-agenda-format-date
3115 (org-time-from-absolute date))
3116 (funcall org-agenda-format-date date))
3118 (put-text-property s (1- (point)) 'face
3119 (if (member wd org-agenda-weekend-days)
3120 'org-agenda-date-weekend
3122 (put-text-property s (1- (point)) 'org-date-line t)
3123 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3124 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3126 (put-text-property s (1- (point)) 'org-today t)
3127 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3129 (org-finalize-agenda-entries
3130 (org-agenda-add-time-grid-maybe
3133 (put-text-property s (1- (point)) 'day d)
3134 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3135 (when (and org-agenda-clockreport-mode clocktable-start)
3136 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3137 ;; the above line is to ensure the restricted range!
3138 (p org-agenda-clockreport-parameter-plist)
3140 (setq p (org-plist-delete p :block))
3141 (setq p (plist-put p :tstart clocktable-start))
3142 (setq p (plist-put p :tend clocktable-end))
3143 (setq p (plist-put p :scope 'agenda))
3144 (setq tbl (apply 'org-get-clocktable p))
3146 (goto-char (point-min))
3147 (or org-agenda-multi (org-fit-agenda-window))
3148 (unless (and (pos-visible-in-window-p (point-min))
3149 (pos-visible-in-window-p (point-max)))
3150 (goto-char (1- (point-max)))
3152 (if (not (pos-visible-in-window-p (or start-pos 1)))
3154 (goto-char (or start-pos 1))
3156 (goto-char (or start-pos 1))
3157 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3158 (org-finalize-agenda)
3159 (setq buffer-read-only t)
3162 (defun org-agenda-ndays-to-span (n)
3163 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3165 ;;; Agenda word search
3167 (defvar org-agenda-search-history nil)
3168 (defvar org-todo-only nil)
3170 (defvar org-search-syntax-table nil
3171 "Special syntax table for org-mode search.
3172 In this table, we have single quotes not as word constituents, to
3173 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3175 (defun org-search-syntax-table ()
3176 (unless org-search-syntax-table
3177 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3178 (modify-syntax-entry ?' "." org-search-syntax-table)
3179 (modify-syntax-entry ?` "." org-search-syntax-table))
3180 org-search-syntax-table)
3183 (defun org-search-view (&optional todo-only string edit-at)
3184 "Show all entries that contain words or regular expressions.
3185 If the first character of the search string is an asterisks,
3186 search only the headlines.
3188 With optional prefix argument TODO-ONLY, only consider entries that are
3189 TODO entries. The argument STRING can be used to pass a default search
3190 string into this function. If EDIT-AT is non-nil, it means that the
3191 user should get a chance to edit this string, with cursor at position
3194 The search string is broken into \"words\" by splitting at whitespace.
3195 Depending on the variable `org-agenda-search-view-search-words-only'
3196 and on wether the first character in the search string is \"+\" or \"-\",
3197 The string is then interpreted either as a substrig with variable amounts
3198 of whitespace, or as a list or individual words that should be matched.
3200 The default is a substring match, where each space in the search string
3201 can expand to an arbitrary amount of whitespace, including newlines.
3203 If matching individual words, these words are then interpreted as a
3204 boolean expression with logical AND. Words prefixed with a minus must
3205 not occur in the entry. Words without a prefix or prefixed with a plus
3206 must occur in the entry. Matching is case-insensitive and the words
3207 are enclosed by word delimiters.
3209 Words enclosed by curly braces are interpreted as regular expressions
3210 that must or must not match in the entry.
3212 If the search string starts with an asterisk, search only in headlines.
3213 If (possibly after the leading star) the search string starts with an
3214 exclamation mark, this also means to look at TODO entries only, an effect
3215 that can also be achieved with a prefix argument.
3217 This command searches the agenda files, and in addition the files listed
3218 in `org-agenda-text-search-extra-files'."
3220 (org-compile-prefix-format 'search)
3221 (org-set-sorting-strategy 'search)
3222 (org-prepare-agenda "SEARCH")
3223 (let* ((props (list 'face nil
3224 'done-face 'org-agenda-done
3225 'org-not-done-regexp org-not-done-regexp
3226 'org-todo-regexp org-todo-regexp
3227 'org-complex-heading-regexp org-complex-heading-regexp
3228 'mouse-face 'highlight
3229 'keymap org-agenda-keymap
3230 'help-echo (format "mouse-2 or RET jump to location")))
3231 regexp rtn rtnall files file pos
3232 marker category tags c neg re as-words
3233 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3234 (unless (and (not edit-at)
3236 (string-match "\\S-" string))
3237 (setq string (read-string "[+-]Word/{Regexp} ...: "
3239 ((integerp edit-at) (cons string edit-at))
3241 'org-agenda-search-history)))
3242 (org-set-local 'org-todo-only todo-only)
3243 (setq org-agenda-redo-command
3244 (list 'org-search-view (if todo-only t nil) string
3245 '(if current-prefix-arg 1 nil)))
3246 (setq org-agenda-query-string string)
3248 (if (equal (string-to-char string) ?*)
3250 words (substring string 1))
3251 (setq words string))
3252 (when (equal (string-to-char words) ?!)
3254 words (substring words 1)))
3255 (if (or org-agenda-search-view-search-words-only
3256 (member (string-to-char string) '(?- ?+)))
3258 (setq words (org-split-string words))
3261 (setq c (string-to-char w))
3263 (setq neg t w (substring w 1))
3265 (setq neg nil w (substring w 1))
3267 (if (string-match "\\`{.*}\\'" w)
3268 (setq re (substring w 1 -1))
3269 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
3270 (if neg (push re regexps-) (push re regexps+)))
3272 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3274 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3276 (setq regexp (concat "^" org-outline-regexp))
3277 (setq regexp (pop regexps+))
3278 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3280 (setq files (org-agenda-files nil 'ifmode))
3281 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3282 (pop org-agenda-text-search-extra-files)
3283 (setq files (org-add-archive-files files)))
3284 (setq files (append files org-agenda-text-search-extra-files)
3286 (while (setq file (pop files))
3289 (org-check-agenda-file file)
3290 (setq buffer (if (file-exists-p file)
3291 (org-get-agenda-file-buffer file)
3292 (error "No such file %s" file)))
3294 ;; If file does not exist, make sure an error message is sent
3295 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3297 (with-current-buffer buffer
3298 (with-syntax-table (org-search-syntax-table)
3299 (unless (org-mode-p)
3300 (error "Agenda file %s is not in `org-mode'" file))
3301 (let ((case-fold-search t))
3304 (if org-agenda-restrict
3305 (narrow-to-region org-agenda-restrict-begin
3306 org-agenda-restrict-end)
3308 (goto-char (point-min))
3309 (unless (or (org-on-heading-p)
3310 (outline-next-heading))
3311 (throw 'nextfile t))
3312 (goto-char (max (point-min) (1- (point))))
3313 (while (re-search-forward regexp nil t)
3314 (org-back-to-heading t)
3315 (skip-chars-forward "* ")
3316 (setq beg (point-at-bol)
3318 end (progn (outline-next-heading) (point)))
3322 (setq str (buffer-substring-no-properties
3324 (if hdl-only (point-at-eol) end)))
3325 (mapc (lambda (wr) (when (string-match wr str)
3326 (goto-char (1- end))
3329 (mapc (lambda (wr) (unless (string-match wr str)
3330 (goto-char (1- end))
3333 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3337 (setq marker (org-agenda-new-marker (point))
3338 category (org-get-category)
3339 tags (org-get-tags-at (point))
3340 txt (org-format-agenda-item
3342 (buffer-substring-no-properties
3343 beg1 (point-at-eol))
3345 (org-add-props txt props
3346 'org-marker marker 'org-hd-marker marker
3347 'org-todo-regexp org-todo-regexp
3348 'org-complex-heading-regexp org-complex-heading-regexp
3349 'priority 1000 'org-category category
3352 (goto-char (1- end))))))))))
3353 (setq rtn (nreverse ee))
3354 (setq rtnall (append rtnall rtn)))
3355 (if org-agenda-overriding-header
3356 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3357 nil 'face 'org-agenda-structure) "\n")
3358 (insert "Search words: ")
3359 (add-text-properties (point-min) (1- (point))
3360 (list 'face 'org-agenda-structure))
3362 (insert string "\n")
3363 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3365 (unless org-agenda-multi
3366 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3367 (add-text-properties pos (1- (point))
3368 (list 'face 'org-agenda-structure))))
3369 (org-agenda-mark-header-line (point-min))
3371 (insert (org-finalize-agenda-entries rtnall) "\n"))
3372 (goto-char (point-min))
3373 (or org-agenda-multi (org-fit-agenda-window))
3374 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3375 (org-finalize-agenda)
3376 (setq buffer-read-only t)))
3378 ;;; Agenda TODO list
3380 (defvar org-select-this-todo-keyword nil)
3381 (defvar org-last-arg nil)
3384 (defun org-todo-list (arg)
3385 "Show all TODO entries from all agenda file in a single list.
3386 The prefix arg can be used to select a specific TODO keyword and limit
3387 the list to these. When using \\[universal-argument], you will be prompted
3388 for a keyword. A numeric prefix directly selects the Nth keyword in
3389 `org-todo-keywords-1'."
3392 (org-compile-prefix-format 'todo)
3393 (org-set-sorting-strategy 'todo)
3394 (org-prepare-agenda "TODO")
3395 (let* ((today (time-to-days (current-time)))
3396 (date (calendar-gregorian-from-absolute today))
3397 (kwds org-todo-keywords-for-agenda)
3398 (completion-ignore-case t)
3399 (org-select-this-todo-keyword
3400 (if (stringp arg) arg
3401 (and arg (integerp arg) (> arg 0)
3402 (nth (1- arg) kwds))))
3403 rtn rtnall files file pos)
3404 (when (equal arg '(4))
3405 (setq org-select-this-todo-keyword
3406 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3407 (mapcar 'list kwds) nil nil)))
3408 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3409 (org-set-local 'org-last-arg arg)
3410 (setq org-agenda-redo-command
3411 '(org-todo-list (or current-prefix-arg org-last-arg)))
3412 (setq files (org-agenda-files nil 'ifmode)
3414 (while (setq file (pop files))
3416 (org-check-agenda-file file)
3417 (setq rtn (org-agenda-get-day-entries file date :todo))
3418 (setq rtnall (append rtnall rtn))))
3419 (if org-agenda-overriding-header
3420 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3421 nil 'face 'org-agenda-structure) "\n")
3422 (insert "Global list of TODO items of type: ")
3423 (add-text-properties (point-min) (1- (point))
3424 (list 'face 'org-agenda-structure
3427 (or org-select-this-todo-keyword "ALL"))))
3428 (org-agenda-mark-header-line (point-min))
3430 (insert (or org-select-this-todo-keyword "ALL") "\n")
3431 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3433 (unless org-agenda-multi
3434 (insert "Available with `N r': (0)ALL")
3437 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3438 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3443 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3444 (org-agenda-mark-header-line (point-min))
3446 (insert (org-finalize-agenda-entries rtnall) "\n"))
3447 (goto-char (point-min))
3448 (or org-agenda-multi (org-fit-agenda-window))
3449 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3450 (org-finalize-agenda)
3451 (setq buffer-read-only t)))
3453 ;;; Agenda tags match
3456 (defun org-tags-view (&optional todo-only match)
3457 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3458 The prefix arg TODO-ONLY limits the search to TODO entries."
3460 (org-compile-prefix-format 'tags)
3461 (org-set-sorting-strategy 'tags)
3462 (let* ((org-tags-match-list-sublevels
3463 ;?????? (if todo-only t org-tags-match-list-sublevels))
3464 org-tags-match-list-sublevels)
3465 (completion-ignore-case t)
3466 rtn rtnall files file pos matcher
3468 (setq matcher (org-make-tags-matcher match)
3469 match (car matcher) matcher (cdr matcher))
3470 (org-prepare-agenda (concat "TAGS " match))
3471 (setq org-agenda-query-string match)
3472 (setq org-agenda-redo-command
3473 (list 'org-tags-view (list 'quote todo-only)
3474 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3475 (setq files (org-agenda-files nil 'ifmode)
3477 (while (setq file (pop files))
3479 (org-check-agenda-file file)
3480 (setq buffer (if (file-exists-p file)
3481 (org-get-agenda-file-buffer file)
3482 (error "No such file %s" file)))
3484 ;; If file does not exist, error message to agenda
3486 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3487 rtnall (append rtnall rtn))
3488 (with-current-buffer buffer
3489 (unless (org-mode-p)
3490 (error "Agenda file %s is not in `org-mode'" file))
3493 (if org-agenda-restrict
3494 (narrow-to-region org-agenda-restrict-begin
3495 org-agenda-restrict-end)
3497 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3498 (setq rtnall (append rtnall rtn))))))))
3499 (if org-agenda-overriding-header
3500 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3501 nil 'face 'org-agenda-structure) "\n")
3502 (insert "Headlines with TAGS match: ")
3503 (add-text-properties (point-min) (1- (point))
3504 (list 'face 'org-agenda-structure
3506 (concat "Match: " match)))
3509 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3511 (unless org-agenda-multi
3512 (insert "Press `C-u r' to search again with new search string\n"))
3513 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3514 (org-agenda-mark-header-line (point-min))
3516 (insert (org-finalize-agenda-entries rtnall) "\n"))
3517 (goto-char (point-min))
3518 (or org-agenda-multi (org-fit-agenda-window))
3519 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3520 (org-finalize-agenda)
3521 (setq buffer-read-only t)))
3523 ;;; Agenda Finding stuck projects
3525 (defvar org-agenda-skip-regexp nil
3526 "Regular expression used in skipping subtrees for the agenda.
3527 This is basically a temporary global variable that can be set and then
3528 used by user-defined selections using `org-agenda-skip-function'.")
3530 (defvar org-agenda-overriding-header nil
3531 "When this is set during todo and tags searches, will replace header.
3532 This variable should not be set directly, but custom commands can bind it
3533 in the options section.")
3535 (defun org-agenda-skip-entry-when-regexp-matches ()
3536 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3537 If yes, it returns the end position of this entry, causing agenda commands
3538 to skip the entry but continuing the search in the subtree. This is a
3539 function that can be put into `org-agenda-skip-function' for the duration
3541 (let ((end (save-excursion (org-end-of-subtree t)))
3544 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3547 (defun org-agenda-skip-subtree-when-regexp-matches ()
3548 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3549 If yes, it returns the end position of this tree, causing agenda commands
3550 to skip this subtree. This is a function that can be put into
3551 `org-agenda-skip-function' for the duration of a command."
3552 (let ((end (save-excursion (org-end-of-subtree t)))
3555 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3558 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3559 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3560 If yes, it returns the end position of the current entry (NOT the tree),
3561 causing agenda commands to skip the entry but continuing the search in
3562 the subtree. This is a function that can be put into
3563 `org-agenda-skip-function' for the duration of a command. An important
3564 use of this function is for the stuck project list."
3565 (let ((end (save-excursion (org-end-of-subtree t)))
3566 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3569 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3570 (and skip entry-end)))
3572 (defun org-agenda-skip-entry-if (&rest conditions)
3573 "Skip entry if any of CONDITIONS is true.
3574 See `org-agenda-skip-if' for details."
3575 (org-agenda-skip-if nil conditions))
3577 (defun org-agenda-skip-subtree-if (&rest conditions)
3578 "Skip entry if any of CONDITIONS is true.
3579 See `org-agenda-skip-if' for details."
3580 (org-agenda-skip-if t conditions))
3582 (defun org-agenda-skip-if (subtree conditions)
3583 "Checks current entity for CONDITIONS.
3584 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3585 the entry, i.e. the text before the next heading is checked.
3587 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3588 from different tests. Valid conditions are:
3590 scheduled Check if there is a scheduled cookie
3591 notscheduled Check if there is no scheduled cookie
3592 deadline Check if there is a deadline
3593 notdeadline Check if there is no deadline
3594 timestamp Check if there is a timestamp (also deadline or scheduled)
3595 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3596 regexp Check if regexp matches
3597 notregexp Check if regexp does not match.
3599 The regexp is taken from the conditions list, it must come right after
3600 the `regexp' or `notregexp' element.
3602 If any of these conditions is met, this function returns the end point of
3603 the entity, causing the search to continue from there. This is a function
3604 that can be put into `org-agenda-skip-function' for the duration of a command."
3606 (org-back-to-heading t)
3609 (progn (org-end-of-subtree t) (point))
3610 (progn (outline-next-heading) (1- (point)))))
3614 (and (memq 'scheduled conditions)
3615 (re-search-forward org-scheduled-time-regexp end t))
3616 (and (memq 'notscheduled conditions)
3617 (not (re-search-forward org-scheduled-time-regexp end t)))
3618 (and (memq 'deadline conditions)
3619 (re-search-forward org-deadline-time-regexp end t))
3620 (and (memq 'notdeadline conditions)
3621 (not (re-search-forward org-deadline-time-regexp end t)))
3622 (and (memq 'timestamp conditions)
3623 (re-search-forward org-ts-regexp end t))
3624 (and (memq 'nottimestamp conditions)
3625 (not (re-search-forward org-ts-regexp end t)))
3626 (and (setq m (memq 'regexp conditions))
3628 (re-search-forward (nth 1 m) end t))
3629 (and (setq m (memq 'notregexp conditions))
3631 (not (re-search-forward (nth 1 m) end t))))
3635 (defun org-agenda-list-stuck-projects (&rest ignore)
3636 "Create agenda view for projects that are stuck.
3637 Stuck projects are project that have no next actions. For the definitions
3638 of what a project is and how to check if it stuck, customize the variable
3639 `org-stuck-projects'.
3640 MATCH is being ignored."
3642 (let* ((org-agenda-skip-function
3643 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3644 ;; We could have used org-agenda-skip-if here.
3645 (org-agenda-overriding-header
3646 (or org-agenda-overriding-header "List of stuck projects: "))
3647 (matcher (nth 0 org-stuck-projects))
3648 (todo (nth 1 org-stuck-projects))
3649 (todo-wds (if (member "*" todo)
3651 (org-prepare-agenda-buffers (org-agenda-files
3654 org-done-keywords-for-agenda
3655 (copy-sequence org-todo-keywords-for-agenda)))
3657 (todo-re (concat "^\\*+[ \t]+\\("
3658 (mapconcat 'identity todo-wds "\\|")
3660 (tags (nth 2 org-stuck-projects))
3661 (tags-re (if (member "*" tags)
3662 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3664 (concat "^\\*+ .*:\\("
3665 (mapconcat 'identity tags "\\|")
3666 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3667 (gen-re (nth 3 org-stuck-projects))
3673 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3675 (setq org-agenda-skip-regexp
3677 (mapconcat 'identity re-list "\\|")
3678 (error "No information how to identify unstuck projects")))
3679 (org-tags-view nil matcher)
3680 (with-current-buffer org-agenda-buffer-name
3681 (setq org-agenda-redo-command
3682 '(org-agenda-list-stuck-projects
3683 (or current-prefix-arg org-last-arg))))))
3685 ;;; Diary integration
3687 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3688 (defvar list-diary-entries-hook)
3690 (defun org-get-entries-from-diary (date)
3691 "Get the (Emacs Calendar) diary entries for DATE."
3692 (require 'diary-lib)
3693 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3694 (fancy-diary-buffer diary-fancy-buffer)
3695 (diary-display-hook '(fancy-diary-display))
3696 (diary-display-function 'fancy-diary-display)
3698 (list-diary-entries-hook
3699 (cons 'org-diary-default-entry list-diary-entries-hook))
3700 (diary-file-name-prefix-function nil) ; turn this feature off
3701 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3703 (org-disable-agenda-to-diary t))
3705 (save-window-excursion
3706 (funcall (if (fboundp 'diary-list-entries)
3707 'diary-list-entries 'list-diary-entries)
3709 (if (not (get-buffer diary-fancy-buffer))
3711 (with-current-buffer diary-fancy-buffer
3712 (setq buffer-read-only nil)
3713 (if (zerop (buffer-size))
3716 ;; Omit the date and other unnecessary stuff
3717 (org-agenda-cleanup-fancy-diary)
3718 ;; Add prefix to each line and extend the text properties
3719 (if (zerop (buffer-size))
3721 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
3722 (set-buffer-modified-p nil)
3723 (kill-buffer diary-fancy-buffer)))
3725 (setq entries (org-split-string entries "\n"))
3729 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
3730 ;; Extend the text properties to the beginning of the line
3731 (org-add-props x (text-properties-at (1- (length x)) x)
3732 'type "diary" 'date date))
3735 (defvar org-agenda-cleanup-fancy-diary-hook nil
3736 "Hook run when the fancy diary buffer is cleaned up.")
3738 (defun org-agenda-cleanup-fancy-diary ()
3739 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3740 This gets rid of the date, the underline under the date, and
3741 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3742 date. It also removes lines that contain only whitespace."
3743 (goto-char (point-min))
3744 (if (looking-at ".*?:[ \t]*")
3747 (re-search-forward "\n=+$" nil t)
3749 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
3750 (re-search-forward "\n=+$" nil t)
3751 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3752 (goto-char (point-min))
3753 (while (re-search-forward "^ +\n" nil t)
3755 (goto-char (point-min))
3756 (if (re-search-forward "^Org-mode dummy\n?" nil t)
3758 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
3760 ;; Make sure entries from the diary have the right text properties.
3761 (eval-after-load "diary-lib"
3762 '(if (boundp 'diary-modify-entry-list-string-function)
3763 ;; We can rely on the hook, nothing to do
3765 ;; Hook not available, must use advice to make this work
3766 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
3767 "Make the position visible."
3768 (if (and org-disable-agenda-to-diary ;; called from org-agenda
3771 (setq string (org-modify-diary-entry-string string))))))
3773 (defun org-modify-diary-entry-string (string)
3774 "Add text properties to string, allowing org-mode to act on it."
3775 (org-add-props string nil
3776 'mouse-face 'highlight
3777 'keymap org-agenda-keymap
3778 'help-echo (if buffer-file-name
3779 (format "mouse-2 or RET jump to diary file %s"
3780 (abbreviate-file-name buffer-file-name))
3782 'org-agenda-diary-link t
3783 'org-marker (org-agenda-new-marker (point-at-bol))))
3785 (defun org-diary-default-entry ()
3786 "Add a dummy entry to the diary.
3787 Needed to avoid empty dates which mess up holiday display."
3788 ;; Catch the error if dealing with the new add-to-diary-alist
3789 (when org-disable-agenda-to-diary
3791 (org-add-to-diary-list original-date "Org-mode dummy" "")
3793 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
3795 (defun org-add-to-diary-list (&rest args)
3796 (if (fboundp 'diary-add-to-list)
3797 (apply 'diary-add-to-list args)
3798 (apply 'add-to-diary-list args)))
3801 (defun org-diary (&rest args)
3802 "Return diary information from org-files.
3803 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3804 It accesses org files and extracts information from those files to be
3805 listed in the diary. The function accepts arguments specifying what
3806 items should be listed. The following arguments are allowed:
3808 :timestamp List the headlines of items containing a date stamp or
3809 date range matching the selected date. Deadlines will
3810 also be listed, on the expiration day.
3812 :sexp List entries resulting from diary-like sexps.
3814 :deadline List any deadlines past due, or due within
3815 `org-deadline-warning-days'. The listing occurs only
3816 in the diary for *today*, not at any other date. If
3817 an entry is marked DONE, it is no longer listed.
3819 :scheduled List all items which are scheduled for the given date.
3820 The diary for *today* also contains items which were
3821 scheduled earlier and are not yet marked DONE.
3823 :todo List all TODO items from the org-file. This may be a
3824 long list - so this is not turned on by default.
3825 Like deadlines, these entries only show up in the
3826 diary for *today*, not at any other date.
3828 The call in the diary file should look like this:
3830 &%%(org-diary) ~/path/to/some/orgfile.org
3832 Use a separate line for each org file to check. Or, if you omit the file name,
3833 all files listed in `org-agenda-files' will be checked automatically:
3837 If you don't give any arguments (as in the example above), the default
3838 arguments (:deadline :scheduled :timestamp :sexp) are used.
3839 So the example above may also be written as
3841 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3843 The function expects the lisp variables `entry' and `date' to be provided
3844 by the caller, because this is how the calendar works. Don't use this
3845 function from a program - use `org-agenda-get-day-entries' instead."
3846 (when (> (- (org-float-time)
3847 org-agenda-last-marker-time)
3849 (org-agenda-reset-markers))
3850 (org-compile-prefix-format 'agenda)
3851 (org-set-sorting-strategy 'agenda)
3852 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3853 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
3855 (org-agenda-files t)))
3857 (org-prepare-agenda-buffers files)
3858 ;; If this is called during org-agenda, don't return any entries to
3859 ;; the calendar. Org Agenda will list these entries itself.
3860 (if org-disable-agenda-to-diary (setq files nil))
3861 (while (setq file (pop files))
3862 (setq rtn (apply 'org-agenda-get-day-entries file date args))
3863 (setq results (append results rtn)))
3865 (concat (org-finalize-agenda-entries results) "\n"))))
3867 ;;; Agenda entry finders
3869 (defun org-agenda-get-day-entries (file date &rest args)
3870 "Does the work for `org-diary' and `org-agenda'.
3871 FILE is the path to a file to be checked for entries. DATE is date like
3872 the one returned by `calendar-current-date'. ARGS are symbols indicating
3873 which kind of entries should be extracted. For details about these, see
3874 the documentation of `org-diary'."
3875 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3876 (let* ((org-startup-folded nil)
3877 (org-startup-align-all-tables nil)
3878 (buffer (if (file-exists-p file)
3879 (org-get-agenda-file-buffer file)
3880 (error "No such file %s" file)))
3881 arg results rtn deadline-results)
3883 ;; If file does not exist, make sure an error message ends up in diary
3884 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3885 (with-current-buffer buffer
3886 (unless (org-mode-p)
3887 (error "Agenda file %s is not in `org-mode'" file))
3888 (let ((case-fold-search nil))
3891 (if org-agenda-restrict
3892 (narrow-to-region org-agenda-restrict-begin
3893 org-agenda-restrict-end)
3895 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3896 (while (setq arg (pop args))
3898 ((and (eq arg :todo)
3899 (equal date (calendar-current-date)))
3900 (setq rtn (org-agenda-get-todos))
3901 (setq results (append results rtn)))
3902 ((eq arg :timestamp)
3903 (setq rtn (org-agenda-get-blocks))
3904 (setq results (append results rtn))
3905 (setq rtn (org-agenda-get-timestamps))
3906 (setq results (append results rtn)))
3908 (setq rtn (org-agenda-get-sexps))
3909 (setq results (append results rtn)))
3910 ((eq arg :scheduled)
3911 (setq rtn (org-agenda-get-scheduled deadline-results))
3912 (setq results (append results rtn)))
3914 (setq rtn (org-agenda-get-progress))
3915 (setq results (append results rtn)))
3917 (setq rtn (org-agenda-get-deadlines))
3918 (setq deadline-results (copy-sequence rtn))
3919 (setq results (append results rtn))))))))
3922 (defun org-agenda-get-todos ()
3923 "Return the TODO information for agenda display."
3924 (let* ((props (list 'face nil
3925 'done-face 'org-agenda-done
3926 'org-not-done-regexp org-not-done-regexp
3927 'org-todo-regexp org-todo-regexp
3928 'org-complex-heading-regexp org-complex-heading-regexp
3929 'mouse-face 'highlight
3930 'keymap org-agenda-keymap
3932 (format "mouse-2 or RET jump to org file %s"
3933 (abbreviate-file-name buffer-file-name))))
3934 (regexp (concat "^\\*+[ \t]+\\("
3935 (if org-select-this-todo-keyword
3936 (if (equal org-select-this-todo-keyword "*")
3939 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
3941 org-not-done-regexp)
3943 marker priority category tags todo-state
3945 (goto-char (point-min))
3946 (while (re-search-forward regexp nil t)
3950 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
3951 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
3952 (goto-char (1+ beg))
3953 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
3957 (goto-char (match-beginning 1))
3958 (setq marker (org-agenda-new-marker (match-beginning 0))
3959 category (org-get-category)
3960 txt (match-string 1)
3961 tags (org-get-tags-at (point))
3962 txt (org-format-agenda-item "" txt category tags)
3963 priority (1+ (org-get-priority txt))
3964 todo-state (org-get-todo-state))
3965 (org-add-props txt props
3966 'org-marker marker 'org-hd-marker marker
3967 'priority priority 'org-category category
3968 'type "todo" 'todo-state todo-state)
3970 (if org-agenda-todo-list-sublevels
3971 (goto-char (match-end 1))
3972 (org-end-of-subtree 'invisible))))
3976 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
3977 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3978 (when (or org-agenda-todo-ignore-with-date
3979 org-agenda-todo-ignore-scheduled
3980 org-agenda-todo-ignore-deadlines)
3981 (setq end (or end (save-excursion (outline-next-heading) (point))))
3983 (or (and org-agenda-todo-ignore-with-date
3984 (re-search-forward org-ts-regexp end t))
3985 (and org-agenda-todo-ignore-scheduled
3986 (re-search-forward org-scheduled-time-regexp end t))
3987 (and org-agenda-todo-ignore-deadlines
3988 (re-search-forward org-deadline-time-regexp end t)
3989 (org-deadline-close (match-string 1)))))))
3991 (defconst org-agenda-no-heading-message
3992 "No heading for this item in buffer or region.")
3994 (defun org-agenda-get-timestamps ()
3995 "Return the date stamp information for agenda display."
3996 (let* ((props (list 'face nil
3997 'org-not-done-regexp org-not-done-regexp
3998 'org-todo-regexp org-todo-regexp
3999 'org-complex-heading-regexp org-complex-heading-regexp
4000 'mouse-face 'highlight
4001 'keymap org-agenda-keymap
4003 (format "mouse-2 or RET jump to org file %s"
4004 (abbreviate-file-name buffer-file-name))))
4005 (d1 (calendar-absolute-from-gregorian date))
4011 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4015 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4019 (car org-time-stamp-formats)
4020 (apply 'encode-time ; DATE bound by calendar
4021 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4023 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4024 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4025 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4026 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4027 todo-state end-of-match)
4028 (goto-char (point-min))
4029 (while (setq end-of-match (re-search-forward regexp nil t))
4030 (setq b0 (match-beginning 0)
4031 b3 (match-beginning 3) e3 (match-end 3))
4033 (and (org-at-date-range-p) (throw :skip nil))
4035 (if (and (match-end 1)
4036 (not (= d1 (org-time-string-to-absolute
4037 (match-string 1) d1 nil
4038 org-agenda-repeating-timestamp-show-all))))
4041 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4043 (setq tmp (buffer-substring (max (point-min)
4044 (- b0 org-ds-keyword-length))
4046 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4047 inactivep (= (char-after b0) ?\[)
4048 deadlinep (string-match org-deadline-regexp tmp)
4049 scheduledp (string-match org-scheduled-regexp tmp)
4050 closedp (and org-agenda-include-inactive-timestamps
4051 (string-match org-closed-string tmp))
4052 clockp (and org-agenda-include-inactive-timestamps
4053 (or (string-match org-clock-string tmp)
4054 (string-match "]-+\\'" tmp)))
4055 todo-state (org-get-todo-state)
4056 donep (member todo-state org-done-keywords))
4057 (if (or scheduledp deadlinep closedp clockp
4058 (and donep org-agenda-skip-timestamp-if-done))
4060 (if (string-match ">" timestr)
4061 ;; substring should only run to end of time stamp
4062 (setq timestr (substring timestr 0 (match-end 0))))
4063 (setq marker (org-agenda-new-marker b0)
4064 category (org-get-category b0))
4066 (if (not (re-search-backward "^\\*+ " nil t))
4067 (setq txt org-agenda-no-heading-message)
4068 (goto-char (match-beginning 0))
4069 (setq hdmarker (org-agenda-new-marker)
4070 tags (org-get-tags-at))
4071 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4072 (setq head (match-string 1))
4073 (setq txt (org-format-agenda-item
4074 (if inactivep "[" nil)
4075 head category tags timestr nil
4077 (setq priority (org-get-priority txt))
4078 (org-add-props txt props
4079 'org-marker marker 'org-hd-marker hdmarker)
4080 (org-add-props txt nil 'priority priority
4081 'org-category category 'date date
4082 'todo-state todo-state
4085 (if org-agenda-skip-additional-timestamps-same-entry
4086 (outline-next-heading)
4087 (goto-char end-of-match))))
4090 (defun org-agenda-get-sexps ()
4091 "Return the sexp information for agenda display."
4092 (require 'diary-lib)
4093 (let* ((props (list 'face nil
4094 'mouse-face 'highlight
4095 'keymap org-agenda-keymap
4097 (format "mouse-2 or RET jump to org file %s"
4098 (abbreviate-file-name buffer-file-name))))
4100 marker category ee txt tags entry result beg b sexp sexp-entry
4102 (goto-char (point-min))
4103 (while (re-search-forward regexp nil t)
4106 (setq beg (match-beginning 0))
4107 (goto-char (1- (match-end 0)))
4110 (setq sexp (buffer-substring b (point)))
4111 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4112 (org-trim (match-string 1))
4114 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4116 (setq marker (org-agenda-new-marker beg)
4117 category (org-get-category beg)
4118 todo-state (org-get-todo-state))
4120 (if (string-match "\\S-" result)
4122 (setq txt "SEXP entry returned empty string"))
4124 (setq txt (org-format-agenda-item
4125 "" txt category tags 'time))
4126 (org-add-props txt props 'org-marker marker)
4127 (org-add-props txt nil
4128 'org-category category 'date date 'todo-state todo-state
4133 (defalias 'org-get-closed 'org-agenda-get-progress)
4134 (defun org-agenda-get-progress ()
4135 "Return the logged TODO entries for agenda display."
4136 (let* ((props (list 'mouse-face 'highlight
4137 'org-not-done-regexp org-not-done-regexp
4138 'org-todo-regexp org-todo-regexp
4139 'org-complex-heading-regexp org-complex-heading-regexp
4140 'keymap org-agenda-keymap
4142 (format "mouse-2 or RET jump to org file %s"
4143 (abbreviate-file-name buffer-file-name))))
4144 (items (if (consp org-agenda-show-log)
4146 org-agenda-log-mode-items))
4150 (if (memq 'closed items) (concat "\\<" org-closed-string))
4151 (if (memq 'clock items) (concat "\\<" org-clock-string))
4152 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4153 (parts-re (if parts (mapconcat 'identity parts "\\|")
4154 (error "`org-agenda-log-mode-items' is empty")))
4156 "\\(" parts-re "\\)"
4161 (car org-time-stamp-formats)
4162 (apply 'encode-time ; DATE bound by calendar
4163 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4165 (org-agenda-search-headline-for-time nil)
4166 marker hdmarker priority category tags closedp statep clockp state
4167 ee txt extra timestr rest clocked)
4168 (goto-char (point-min))
4169 (while (re-search-forward regexp nil t)
4172 (setq marker (org-agenda-new-marker (match-beginning 0))
4173 closedp (equal (match-string 1) org-closed-string)
4174 statep (equal (string-to-char (match-string 1)) ?-)
4175 clockp (not (or closedp statep))
4176 state (and statep (match-string 2))
4177 category (org-get-category (match-beginning 0))
4178 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4180 (when (string-match "\\]" timestr)
4181 ;; substring should only run to end of time stamp
4182 (setq rest (substring timestr (match-end 0))
4183 timestr (substring timestr 0 (match-end 0)))
4184 (if (and (not closedp) (not statep)
4185 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4186 (progn (setq timestr (concat (substring timestr 0 -1)
4187 "-" (match-string 1 rest) "]"))
4188 (setq clocked (match-string 2 rest)))
4189 (setq clocked "-")))
4192 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4194 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4195 (setq extra (match-string 1))))
4197 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4198 (setq extra (match-string 1))))
4199 (t (setq extra nil)))
4200 (if (not (re-search-backward "^\\*+ " nil t))
4201 (setq txt org-agenda-no-heading-message)
4202 (goto-char (match-beginning 0))
4203 (setq hdmarker (org-agenda-new-marker)
4204 tags (org-get-tags-at))
4205 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4206 (setq txt (match-string 1))
4208 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4209 (setq txt (concat (substring txt 0 (match-beginning 1))
4210 " - " extra " " (match-string 2 txt)))
4211 (setq txt (concat txt " - " extra))))
4212 (setq txt (org-format-agenda-item
4214 (closedp "Closed: ")
4215 (statep (concat "State: (" state ")"))
4216 (t (concat "Clocked: (" clocked ")")))
4217 txt category tags timestr)))
4218 (setq priority 100000)
4219 (org-add-props txt props
4220 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4221 'priority priority 'org-category category
4222 'type "closed" 'date date
4223 'undone-face 'org-warning 'done-face 'org-agenda-done)
4225 (goto-char (point-at-eol))))
4228 (defun org-agenda-get-deadlines ()
4229 "Return the deadline information for agenda display."
4230 (let* ((props (list 'mouse-face 'highlight
4231 'org-not-done-regexp org-not-done-regexp
4232 'org-todo-regexp org-todo-regexp
4233 'org-complex-heading-regexp org-complex-heading-regexp
4234 'keymap org-agenda-keymap
4236 (format "mouse-2 or RET jump to org file %s"
4237 (abbreviate-file-name buffer-file-name))))
4238 (regexp org-deadline-time-regexp)
4239 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4240 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4241 d2 diff dfrac wdays pos pos1 category tags
4242 ee txt head face s todo-state upcomingp donep timestr)
4243 (goto-char (point-min))
4244 (while (re-search-forward regexp nil t)
4247 (setq s (match-string 1)
4249 pos (1- (match-beginning 1))
4250 d2 (org-time-string-to-absolute
4251 (match-string 1) d1 'past
4252 org-agenda-repeating-timestamp-show-all)
4254 wdays (org-get-wdays s)
4255 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4256 upcomingp (and todayp (> diff 0)))
4257 ;; When to show a deadline in the calendar:
4258 ;; If the expiration is within wdays warning time.
4259 ;; Past-due deadlines are only shown on the current date
4260 (if (and (or (and (<= diff wdays)
4261 (and todayp (not org-agenda-only-exact-dates)))
4264 (setq todo-state (org-get-todo-state))
4265 (setq donep (member todo-state org-done-keywords))
4267 (or org-agenda-skip-deadline-if-done
4270 (setq category (org-get-category))
4271 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4272 (setq txt org-agenda-no-heading-message)
4273 (goto-char (match-end 0))
4274 (setq pos1 (match-beginning 0))
4275 (setq tags (org-get-tags-at pos1))
4276 (setq head (buffer-substring-no-properties
4278 (progn (skip-chars-forward "^\r\n")
4280 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4282 (concat (substring s (match-beginning 1)) " "))
4283 (setq timestr 'time))
4284 (setq txt (org-format-agenda-item
4286 (car org-agenda-deadline-leaders)
4288 (nth 1 org-agenda-deadline-leaders))
4290 (nth 1 org-agenda-deadline-leaders)
4292 (format (nth 1 org-agenda-deadline-leaders)
4295 (if (not (= diff 0)) nil timestr)))))
4297 (setq face (org-agenda-deadline-face dfrac wdays))
4298 (org-add-props txt props
4299 'org-marker (org-agenda-new-marker pos)
4300 'org-hd-marker (org-agenda-new-marker pos1)
4301 'priority (+ (- diff)
4302 (org-get-priority txt))
4303 'org-category category
4304 'todo-state todo-state
4305 'type (if upcomingp "upcoming-deadline" "deadline")
4306 'date (if upcomingp date d2)
4307 'face (if donep 'org-agenda-done face)
4308 'undone-face face 'done-face 'org-agenda-done)
4312 (defun org-agenda-deadline-face (fraction &optional wdays)
4313 "Return the face to displaying a deadline item.
4314 FRACTION is what fraction of the head-warning time has passed."
4315 (if (equal wdays 0) (setq fraction 1.))
4316 (let ((faces org-agenda-deadline-faces) f)
4318 (while (setq f (pop faces))
4319 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4321 (defun org-agenda-get-scheduled (&optional deadline-results)
4322 "Return the scheduled information for agenda display."
4323 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4324 'org-todo-regexp org-todo-regexp
4325 'org-complex-heading-regexp org-complex-heading-regexp
4326 'done-face 'org-agenda-done
4327 'mouse-face 'highlight
4328 'keymap org-agenda-keymap
4330 (format "mouse-2 or RET jump to org file %s"
4331 (abbreviate-file-name buffer-file-name))))
4332 (regexp org-scheduled-time-regexp)
4333 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4334 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4336 (deadline-position-alist
4337 (mapcar (lambda (a) (and (setq mm (get-text-property
4338 0 'org-hd-marker a))
4339 (cons (marker-position mm) a)))
4341 d2 diff pos pos1 category tags donep
4342 ee txt head pastschedp todo-state face timestr s habitp)
4343 (goto-char (point-min))
4344 (while (re-search-forward regexp nil t)
4347 (setq s (match-string 1)
4349 pos (1- (match-beginning 1))
4350 d2 (org-time-string-to-absolute
4351 (match-string 1) d1 'past
4352 org-agenda-repeating-timestamp-show-all)
4354 (setq pastschedp (and todayp (< diff 0)))
4355 ;; When to show a scheduled item in the calendar:
4356 ;; If it is on or past the date.
4357 (when (or (and (< diff 0)
4358 (< (abs diff) org-scheduled-past-days)
4359 (and todayp (not org-agenda-only-exact-dates)))
4362 (setq todo-state (org-get-todo-state))
4363 (setq donep (member todo-state org-done-keywords))
4364 (setq habitp (and (functionp 'org-is-habit-p)
4367 (or habitp org-agenda-skip-scheduled-if-done
4370 (setq category (org-get-category))
4371 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4372 (setq txt org-agenda-no-heading-message)
4373 (goto-char (match-end 0))
4374 (setq pos1 (match-beginning 0))
4376 (if (or (not org-habit-show-habits)
4378 org-habit-show-habits-only-for-today))
4381 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4382 (and org-agenda-skip-scheduled-if-deadline-is-shown
4384 (setq mm (assoc pos1 deadline-position-alist)))
4386 (setq tags (org-get-tags-at))
4387 (setq head (buffer-substring-no-properties
4389 (progn (skip-chars-forward "^\r\n") (point))))
4390 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4392 (concat (substring s (match-beginning 1)) " "))
4393 (setq timestr 'time))
4394 (setq txt (org-format-agenda-item
4396 (car org-agenda-scheduled-leaders)
4397 (format (nth 1 org-agenda-scheduled-leaders)
4400 (if (not (= diff 0)) nil timestr)
4405 ((and (not habitp) pastschedp)
4406 'org-scheduled-previously)
4407 (todayp 'org-scheduled-today)
4409 habitp (and habitp (org-habit-parse-todo)))
4410 (org-add-props txt props
4412 'face (if donep 'org-agenda-done face)
4413 'org-marker (org-agenda-new-marker pos)
4414 'org-hd-marker (org-agenda-new-marker pos1)
4415 'type (if pastschedp "past-scheduled" "scheduled")
4416 'date (if pastschedp d2 date)
4417 'priority (if habitp
4418 (org-habit-get-priority habitp)
4419 (+ 94 (- 5 diff) (org-get-priority txt)))
4420 'org-category category
4422 'todo-state todo-state)
4426 (defun org-agenda-get-blocks ()
4427 "Return the date-range information for agenda display."
4428 (let* ((props (list 'face nil
4429 'org-not-done-regexp org-not-done-regexp
4430 'org-todo-regexp org-todo-regexp
4431 'org-complex-heading-regexp org-complex-heading-regexp
4432 'mouse-face 'highlight
4433 'keymap org-agenda-keymap
4435 (format "mouse-2 or RET jump to org file %s"
4436 (abbreviate-file-name buffer-file-name))))
4437 (regexp org-tr-regexp)
4438 (d0 (calendar-absolute-from-gregorian date))
4439 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4441 (goto-char (point-min))
4442 (while (re-search-forward regexp nil t)
4446 (setq timestr (match-string 0)
4449 d1 (time-to-days (org-time-string-to-time s1))
4450 d2 (time-to-days (org-time-string-to-time s2)))
4451 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4452 ;; Only allow days between the limits, because the normal
4453 ;; date stamps will catch the limits.
4455 (setq todo-state (org-get-todo-state))
4456 (setq donep (member todo-state org-done-keywords))
4457 (if (and donep org-agenda-skip-timestamp-if-done)
4459 (setq marker (org-agenda-new-marker (point)))
4460 (setq category (org-get-category))
4461 (if (not (re-search-backward "^\\*+ " nil t))
4462 (setq txt org-agenda-no-heading-message)
4463 (goto-char (match-beginning 0))
4464 (setq hdmarker (org-agenda-new-marker (point)))
4465 (setq tags (org-get-tags-at))
4466 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4467 (setq head (match-string 1))
4468 (setq txt (org-format-agenda-item
4470 (nth (if (= d1 d2) 0 1)
4471 org-agenda-timerange-leaders)
4472 (1+ (- d0 d1)) (1+ (- d2 d1)))
4474 (if (= d0 d1) timestr))))
4475 (org-add-props txt props
4476 'org-marker marker 'org-hd-marker hdmarker
4477 'type "block" 'date date
4478 'todo-state todo-state
4479 'priority (org-get-priority txt) 'org-category category)
4482 ;; Sort the entries by expiration date.
4485 ;;; Agenda presentation and sorting
4487 (defvar org-prefix-has-time nil
4488 "A flag, set by `org-compile-prefix-format'.
4489 The flag is set if the currently compiled format contains a `%t'.")
4490 (defvar org-prefix-has-tag nil
4491 "A flag, set by `org-compile-prefix-format'.
4492 The flag is set if the currently compiled format contains a `%T'.")
4493 (defvar org-prefix-has-effort nil
4494 "A flag, set by `org-compile-prefix-format'.
4495 The flag is set if the currently compiled format contains a `%e'.")
4496 (defvar org-prefix-category-length nil
4497 "Used by `org-compile-prefix-format' to remember the category field widh.")
4498 (defvar org-prefix-category-max-length nil
4499 "Used by `org-compile-prefix-format' to remember the category field widh.")
4501 (defun org-format-agenda-item (extra txt &optional category tags dotime
4502 noprefix remove-re habitp)
4503 "Format TXT to be inserted into the agenda buffer.
4504 In particular, it adds the prefix and corresponding text properties. EXTRA
4505 must be a string and replaces the `%s' specifier in the prefix format.
4506 CATEGORY (string, symbol or nil) may be used to overrule the default
4507 category taken from local variable or file name. It will replace the `%c'
4508 specifier in the format. DOTIME, when non-nil, indicates that a
4509 time-of-day should be extracted from TXT for sorting of this entry, and for
4510 the `%t' specifier in the format. When DOTIME is a string, this string is
4511 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4512 only the correctly processes TXT should be returned - this is used by
4513 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4514 Any match of REMOVE-RE will be removed from TXT."
4516 ;; Diary entries sometimes have extra whitespace at the beginning
4517 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4518 (when org-agenda-show-inherited-tags
4519 ;; Fix the tags part in txt
4520 (setq txt (org-agenda-add-inherited-tags txt tags)))
4521 (let* ((category (or category
4523 (if buffer-file-name
4524 (file-name-sans-extension
4525 (file-name-nondirectory buffer-file-name))
4527 ;; time, tag, effort are needed for the eval of the prefix format
4528 (tag (if tags (nth (1- (length tags)) tags) ""))
4530 (ts (if dotime (concat
4531 (if (stringp dotime) dotime "")
4532 (and org-agenda-search-headline-for-time txt))))
4533 (time-of-day (and dotime (org-get-time-of-day ts)))
4534 stamp plain s0 s1 s2 t1 t2 rtn srp l
4535 duration thecategory)
4536 (and (org-mode-p) buffer-file-name
4537 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4538 (when (and dotime time-of-day)
4539 ;; Extract starting and ending time and move them to prefix
4540 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4541 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4542 (setq s0 (match-string 0 ts)
4543 srp (and stamp (match-end 3))
4544 s1 (match-string (if plain 1 2) ts)
4545 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4547 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4548 ;; them, we might want to remove them there to avoid duplication.
4549 ;; The user can turn this off with a variable.
4550 (if (and org-prefix-has-time
4551 org-agenda-remove-times-when-in-prefix (or stamp plain)
4552 (string-match (concat (regexp-quote s0) " *") txt)
4553 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4554 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4555 (= (match-beginning 0) 0)
4557 (setq txt (replace-match "" nil nil txt))))
4558 ;; Normalize the time(s) to 24 hour
4559 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4560 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4561 ;; Compute the duration
4563 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4564 (string-to-number (substring s1 3)))
4566 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4567 (string-to-number (substring s2 3))))
4568 (org-agenda-default-appointment-duration
4569 (+ t1 org-agenda-default-appointment-duration))
4571 (setq duration (if t2 (- t2 t1)))))
4573 (when (and s1 (not s2) org-agenda-default-appointment-duration
4574 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4575 (let ((m (+ (string-to-number (match-string 2 s1))
4576 (* 60 (string-to-number (match-string 1 s1)))
4577 org-agenda-default-appointment-duration))
4579 (setq h (/ m 60) m (- m (* h 60)))
4580 (setq s2 (format "%02d:%02d" h m))))
4582 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4584 ;; Tags are in the string
4585 (if (or (eq org-agenda-remove-tags t)
4586 (and org-agenda-remove-tags
4587 org-prefix-has-tag))
4588 (setq txt (replace-match "" t t txt))
4589 (setq txt (replace-match
4590 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4591 (match-string 2 txt))
4597 (or (get-text-property 0 'org-hd-marker txt)
4598 (get-text-property 0 'org-marker txt)))
4601 (setq neffort (org-hh:mm-string-to-minutes effort)
4602 effort (setq effort (concat "[" effort "]" )))))
4605 (while (string-match remove-re txt)
4606 (setq txt (replace-match "" t t txt))))
4608 ;; Create the final string
4611 ;; Prepare the variables needed in the eval of the compiled format
4612 (setq time (cond (s2 (concat s1 "-" s2))
4613 (s1 (concat s1 "......"))
4615 extra (or (and (not habitp) extra) "")
4616 category (if (symbolp category) (symbol-name category) category)
4617 thecategory (copy-sequence category))
4618 (if (string-match org-bracket-link-regexp category)
4620 (setq l (if (match-end 3)
4621 (- (match-end 3) (match-beginning 3))
4622 (- (match-end 1) (match-beginning 1))))
4623 (when (< l (or org-prefix-category-length 0))
4624 (setq category (copy-sequence category))
4625 (org-add-props category nil
4626 'extra-space (make-string
4627 (- org-prefix-category-length l 1) ?\ ))))
4628 (if (and org-prefix-category-max-length
4629 (>= (length category) org-prefix-category-max-length))
4630 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4631 ;; Evaluate the compiled format
4632 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4634 ;; And finally add the text properties
4635 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4636 (org-add-props rtn nil
4637 'org-category (if thecategory (downcase thecategory) category)
4638 'tags (mapcar 'org-downcase-keep-props tags)
4639 'org-highest-priority org-highest-priority
4640 'org-lowest-priority org-lowest-priority
4641 'prefix-length (- (length rtn) (length txt))
4642 'time-of-day time-of-day
4645 'effort-minutes neffort
4651 (defun org-agenda-add-inherited-tags (txt tags)
4652 "Remove tags string from TXT, and add complete list of tags.
4653 The new list includes inherited tags. If any inherited tags are present,
4654 a double colon separates inherited tags from local tags."
4655 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4656 (setq txt (substring txt 0 (match-beginning 0))))
4658 (let ((have-i (get-text-property 0 'inherited (car tags)))
4660 (setq txt (concat txt " :"
4663 (setq i (get-text-property 0 'inherited x))
4664 (if (and have-i (not i))
4670 (if have-i "::" ":")))))
4673 (defun org-downcase-keep-props (s)
4674 (let ((props (text-properties-at 0 s)))
4675 (setq s (downcase s))
4676 (add-text-properties 0 (length s) props s)
4679 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
4680 (defvar org-agenda-sorting-strategy-selected nil)
4682 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
4684 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
4685 ((and todayp (member 'today (car org-agenda-time-grid))))
4686 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
4687 ((member 'weekly (car org-agenda-time-grid)))
4688 (t (throw 'exit list)))
4689 (let* ((have (delq nil (mapcar
4690 (lambda (x) (get-text-property 1 'time-of-day x))
4692 (string (nth 1 org-agenda-time-grid))
4693 (gridtimes (nth 2 org-agenda-time-grid))
4694 (req (car org-agenda-time-grid))
4695 (remove (member 'remove-match req))
4697 (if (and (member 'require-timed req) (not have))
4698 ;; don't show empty grid
4700 (while (setq time (pop gridtimes))
4701 (unless (and remove (member time have))
4702 (setq time (int-to-string time))
4703 (push (org-format-agenda-item
4705 (concat (substring time 0 -2) ":" (substring time -2)))
4708 1 (length (car new)) 'face 'org-time-grid (car new))))
4709 (if (member 'time-up org-agenda-sorting-strategy-selected)
4711 (append list new)))))
4713 (defun org-compile-prefix-format (key)
4714 "Compile the prefix format into a Lisp form that can be evaluated.
4715 The resulting form is returned and stored in the variable
4716 `org-prefix-format-compiled'."
4717 (setq org-prefix-has-time nil org-prefix-has-tag nil
4718 org-prefix-category-length nil org-prefix-has-effort nil)
4720 ((stringp org-agenda-prefix-format)
4721 org-agenda-prefix-format)
4722 ((assq key org-agenda-prefix-format)
4723 (cdr (assq key org-agenda-prefix-format)))
4724 (t " %-12:c%?-12t% s")))
4726 varform vars var e c f opt)
4727 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4729 (setq var (cdr (assoc (match-string 4 s)
4730 '(("c" . category) ("t" . time) ("s" . extra)
4731 ("T" . tag) ("e" . effort))))
4732 c (or (match-string 3 s) "")
4733 opt (match-beginning 1)
4734 start (1+ (match-beginning 0)))
4735 (if (equal var 'time) (setq org-prefix-has-time t))
4736 (if (equal var 'tag) (setq org-prefix-has-tag t))
4737 (if (equal var 'effort) (setq org-prefix-has-effort t))
4738 (setq f (concat "%" (match-string 2 s) "s"))
4739 (when (equal var 'category)
4740 (setq org-prefix-category-length
4741 (floor (abs (string-to-number (match-string 2 s)))))
4742 (setq org-prefix-category-max-length
4743 (let ((x (match-string 2 s)))
4745 (if (string-match "\\.[0-9]+" x)
4746 (string-to-number (substring (match-string 0 x) 1)))))))
4749 `(if (equal "" ,var)
4751 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
4752 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
4753 (setq s (replace-match "%s" t nil s))
4754 (push varform vars))
4755 (setq vars (nreverse vars))
4756 (setq org-prefix-format-compiled `(format ,s ,@vars))))
4758 (defun org-set-sorting-strategy (key)
4759 (if (symbolp (car org-agenda-sorting-strategy))
4761 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
4762 (setq org-agenda-sorting-strategy-selected
4763 (or (cdr (assq key org-agenda-sorting-strategy))
4764 (cdr (assq 'agenda org-agenda-sorting-strategy))
4765 '(time-up category-keep priority-down)))))
4767 (defun org-get-time-of-day (s &optional string mod24)
4768 "Check string S for a time of day.
4769 If found, return it as a military time number between 0 and 2400.
4770 If not found, return nil.
4771 The optional STRING argument forces conversion into a 5 character wide string
4775 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
4776 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
4777 (let* ((h (string-to-number (match-string 1 s)))
4778 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
4779 (ampm (if (match-end 4) (downcase (match-string 4 s))))
4780 (am-p (equal ampm "am"))
4781 (h1 (cond ((not ampm) h)
4782 ((= h 12) (if am-p 0 12))
4783 (t (+ h (if am-p 0 12)))))
4784 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
4786 (t0 (+ (* 100 h2) m))
4787 (t1 (concat (if (>= h1 24) "+" " ")
4788 (if (< t0 100) "0" "")
4789 (if (< t0 10) "0" "")
4790 (int-to-string t0))))
4791 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
4793 (defun org-finalize-agenda-entries (list &optional nosort)
4794 "Sort and concatenate the agenda items."
4795 (setq list (mapcar 'org-agenda-highlight-todo list))
4798 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
4800 (defun org-agenda-highlight-todo (x)
4801 (let ((org-done-keywords org-done-keywords-for-agenda)
4805 (beginning-of-line 1)
4806 (setq re (org-get-at-bol 'org-todo-regexp))
4807 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
4808 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
4809 (add-text-properties (match-beginning 0) (match-end 1)
4810 (list 'face (org-get-todo-face 1)))
4811 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4812 (delete-region (match-beginning 1) (1- (match-end 0)))
4813 (goto-char (match-beginning 1))
4814 (insert (format org-agenda-todo-keyword-format s)))))
4815 (setq re (concat (get-text-property 0 'org-todo-regexp x))
4816 pl (get-text-property 0 'prefix-length x))
4818 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
4820 (add-text-properties
4821 (or (match-end 1) (match-end 0)) (match-end 0)
4822 (list 'face (org-get-todo-face (match-string 2 x)))
4824 (setq x (concat (substring x 0 (match-end 1))
4825 (format org-agenda-todo-keyword-format
4827 (org-add-props " " (text-properties-at 0 x))
4828 (substring x (match-end 3)))))
4831 (defsubst org-cmp-priority (a b)
4832 "Compare the priorities of string A and B."
4833 (let ((pa (or (get-text-property 1 'priority a) 0))
4834 (pb (or (get-text-property 1 'priority b) 0)))
4835 (cond ((> pa pb) +1)
4839 (defsubst org-cmp-effort (a b)
4840 "Compare the priorities of string A and B."
4841 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
4842 (ea (or (get-text-property 1 'effort-minutes a) def))
4843 (eb (or (get-text-property 1 'effort-minutes b) def)))
4844 (cond ((> ea eb) +1)
4848 (defsubst org-cmp-category (a b)
4849 "Compare the string values of categories of strings A and B."
4850 (let ((ca (or (get-text-property 1 'org-category a) ""))
4851 (cb (or (get-text-property 1 'org-category b) "")))
4852 (cond ((string-lessp ca cb) -1)
4853 ((string-lessp cb ca) +1)
4856 (defsubst org-cmp-todo-state (a b)
4857 "Compare the todo states of strings A and B."
4858 (let* ((ma (or (get-text-property 1 'org-marker a)
4859 (get-text-property 1 'org-hd-marker a)))
4860 (mb (or (get-text-property 1 'org-marker b)
4861 (get-text-property 1 'org-hd-marker b)))
4862 (fa (and ma (marker-buffer ma)))
4863 (fb (and mb (marker-buffer mb)))
4865 (or (and fa (with-current-buffer fa org-todo-keywords-1))
4866 (and fb (with-current-buffer fb org-todo-keywords-1))))
4867 (ta (or (get-text-property 1 'todo-state a) ""))
4868 (tb (or (get-text-property 1 'todo-state b) ""))
4869 (la (- (length (member ta todo-kwds))))
4870 (lb (- (length (member tb todo-kwds))))
4871 (donepa (member ta org-done-keywords-for-agenda))
4872 (donepb (member tb org-done-keywords-for-agenda)))
4873 (cond ((and donepa (not donepb)) -1)
4874 ((and (not donepa) donepb) +1)
4879 (defsubst org-cmp-tag (a b)
4880 "Compare the string values of the first tags of A and B."
4881 (let ((ta (car (last (get-text-property 1 'tags a))))
4882 (tb (car (last (get-text-property 1 'tags b)))))
4885 ((string-lessp ta tb) -1)
4886 ((string-lessp tb ta) +1)
4889 (defsubst org-cmp-time (a b)
4890 "Compare the time-of-day values of strings A and B."
4891 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
4892 (ta (or (get-text-property 1 'time-of-day a) def))
4893 (tb (or (get-text-property 1 'time-of-day b) def)))
4894 (cond ((< ta tb) -1)
4898 (defsubst org-cmp-habit-p (a b)
4899 "Compare the todo states of strings A and B."
4900 (let ((ha (get-text-property 1 'org-habit-p a))
4901 (hb (get-text-property 1 'org-habit-p b)))
4902 (cond ((and ha (not hb)) -1)
4903 ((and (not ha) hb) +1)
4906 (defun org-entries-lessp (a b)
4907 "Predicate for sorting agenda entries."
4908 ;; The following variables will be used when the form is evaluated.
4909 ;; So even though the compiler complains, keep them.
4910 (let* ((time-up (org-cmp-time a b))
4911 (time-down (if time-up (- time-up) nil))
4912 (priority-up (org-cmp-priority a b))
4913 (priority-down (if priority-up (- priority-up) nil))
4914 (effort-up (org-cmp-effort a b))
4915 (effort-down (if effort-up (- effort-up) nil))
4916 (category-up (org-cmp-category a b))
4917 (category-down (if category-up (- category-up) nil))
4918 (category-keep (if category-up +1 nil))
4919 (tag-up (org-cmp-tag a b))
4920 (tag-down (if tag-up (- tag-up) nil))
4921 (todo-state-up (org-cmp-todo-state a b))
4922 (todo-state-down (if todo-state-up (- todo-state-up) nil))
4923 (habit-up (org-cmp-habit-p a b))
4924 (habit-down (if habit-up (- habit-up) nil))
4925 user-defined-up user-defined-down)
4926 (if (and org-agenda-cmp-user-defined
4927 (functionp org-agenda-cmp-user-defined))
4928 (setq user-defined-up
4929 (funcall org-agenda-cmp-user-defined a b)
4930 user-defined-down (if user-defined-up (- user-defined-up) nil)))
4932 (eval (cons 'or org-agenda-sorting-strategy-selected))
4933 '((-1 . t) (1 . nil) (nil . nil))))))
4935 ;;; Agenda restriction lock
4937 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
4938 "Overlay to mark the headline to which arenda commands are restricted.")
4939 (org-overlay-put org-agenda-restriction-lock-overlay
4940 'face 'org-agenda-restriction-lock)
4941 (org-overlay-put org-agenda-restriction-lock-overlay
4942 'help-echo "Agendas are currently limited to this subtree.")
4943 (org-detach-overlay org-agenda-restriction-lock-overlay)
4945 (defun org-agenda-set-restriction-lock (&optional type)
4946 "Set restriction lock for agenda, to current subtree or file.
4947 Restriction will be the file if TYPE is `file', or if type is the
4948 universal prefix '(4), or if the cursor is before the first headline
4949 in the file. Otherwise, restriction will be to the current subtree."
4951 (and (equal type '(4)) (setq type 'file))
4954 ((org-at-heading-p) 'subtree)
4955 ((condition-case nil (org-back-to-heading t) (error nil))
4958 (if (eq type 'subtree)
4960 (setq org-agenda-restrict t)
4961 (setq org-agenda-overriding-restriction 'subtree)
4962 (put 'org-agenda-files 'org-restrict
4963 (list (buffer-file-name (buffer-base-buffer))))
4964 (org-back-to-heading t)
4965 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
4966 (move-marker org-agenda-restrict-begin (point))
4967 (move-marker org-agenda-restrict-end
4968 (save-excursion (org-end-of-subtree t)))
4969 (message "Locking agenda restriction to subtree"))
4970 (put 'org-agenda-files 'org-restrict
4971 (list (buffer-file-name (buffer-base-buffer))))
4972 (setq org-agenda-restrict nil)
4973 (setq org-agenda-overriding-restriction 'file)
4974 (move-marker org-agenda-restrict-begin nil)
4975 (move-marker org-agenda-restrict-end nil)
4976 (message "Locking agenda restriction to file"))
4977 (setq current-prefix-arg nil)
4978 (org-agenda-maybe-redo))
4980 (defun org-agenda-remove-restriction-lock (&optional noupdate)
4981 "Remove the agenda restriction lock."
4983 (org-detach-overlay org-agenda-restriction-lock-overlay)
4984 (org-detach-overlay org-speedbar-restriction-lock-overlay)
4985 (setq org-agenda-overriding-restriction nil)
4986 (setq org-agenda-restrict nil)
4987 (put 'org-agenda-files 'org-restrict nil)
4988 (move-marker org-agenda-restrict-begin nil)
4989 (move-marker org-agenda-restrict-end nil)
4990 (setq current-prefix-arg nil)
4991 (message "Agenda restriction lock removed")
4992 (or noupdate (org-agenda-maybe-redo)))
4994 (defun org-agenda-maybe-redo ()
4995 "If there is any window showing the agenda view, update it."
4996 (let ((w (get-buffer-window org-agenda-buffer-name t))
4997 (w0 (selected-window)))
5002 (if org-agenda-overriding-restriction
5003 (message "Agenda view shifted to new %s restriction"
5004 org-agenda-overriding-restriction)
5005 (message "Agenda restriction lock removed")))))
5009 (defun org-agenda-check-type (error &rest types)
5010 "Check if agenda buffer is of allowed type.
5011 If ERROR is non-nil, throw an error, otherwise just return nil."
5012 (if (memq org-agenda-type types)
5015 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5018 (defun org-agenda-quit ()
5019 "Exit agenda by removing the window or the buffer."
5021 (if org-agenda-columns-active
5023 (let ((buf (current-buffer)))
5024 (if (eq org-agenda-window-setup 'other-frame)
5027 (org-agenda-reset-markers)
5028 (org-columns-remove-overlays)
5029 (setq org-agenda-archives-mode nil)
5031 (and (not (eq org-agenda-window-setup 'current-window))
5032 (not (one-window-p))
5035 (org-agenda-reset-markers)
5036 (org-columns-remove-overlays)
5037 (setq org-agenda-archives-mode nil)))
5038 ;; Maybe restore the pre-agenda window configuration.
5039 (and org-agenda-restore-windows-after-quit
5040 (not (eq org-agenda-window-setup 'other-frame))
5041 org-pre-agenda-window-conf
5042 (set-window-configuration org-pre-agenda-window-conf))))
5044 (defun org-agenda-exit ()
5045 "Exit agenda by removing the window or the buffer.
5046 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5047 Org-mode buffers visited directly by the user will not be touched."
5049 (org-release-buffers org-agenda-new-buffers)
5050 (setq org-agenda-new-buffers nil)
5053 (defun org-agenda-execute (arg)
5054 "Execute another agenda command, keeping same window.\\<global-map>
5055 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5057 (let ((org-agenda-window-setup 'current-window))
5060 (defun org-agenda-redo ()
5062 When this is the global TODO list, a prefix argument will be interpreted."
5064 (let* ((org-agenda-keep-modes t)
5065 (filter org-agenda-filter)
5066 (preset (get 'org-agenda-filter :preset-filter))
5067 (cols org-agenda-columns-active)
5068 (line (org-current-line))
5069 (window-line (- line (org-current-line (window-start))))
5070 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5071 (put 'org-agenda-filter :preset-filter nil)
5072 (and cols (org-columns-quit))
5073 (message "Rebuilding agenda buffer...")
5074 (org-let lprops '(eval org-agenda-redo-command))
5075 (setq org-agenda-undo-list nil
5076 org-agenda-pending-undo-list nil)
5077 (message "Rebuilding agenda buffer...done")
5078 (put 'org-agenda-filter :preset-filter preset)
5079 (and (or filter preset) (org-agenda-filter-apply filter))
5080 (and cols (interactive-p) (org-agenda-columns))
5081 (org-goto-line line)
5082 (recenter window-line)))
5085 (defvar org-global-tags-completion-table nil)
5086 (defvar org-agenda-filter-form nil)
5087 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5088 "Keep only those lines in the agenda buffer that have a specific tag.
5089 The tag is selected with its fast selection letter, as configured.
5090 With prefix argument STRIP, remove all lines that do have the tag.
5091 A lisp caller can specify CHAR. NARROW means that the new tag should be
5092 used to narrow the search - the interactive user can also press `-' or `+'
5093 to switch to narrowing."
5095 (let* ((alist org-tag-alist-for-agenda)
5096 (tag-chars (mapconcat
5097 (lambda (x) (if (and (not (symbolp (car x)))
5099 (char-to-string (cdr x))
5102 (efforts (org-split-string
5103 (or (cdr (assoc (concat org-effort-property "_ALL")
5104 org-global-properties))
5105 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5106 (effort-op org-agenda-filter-effort-default-operator)
5108 (inhibit-read-only t)
5109 (current org-agenda-filter)
5113 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5114 (if narrow "Narrow" "Filter") tag-chars
5115 (if org-agenda-auto-exclude-function "[RET], " ""))
5116 (setq char (read-char)))
5117 (when (member char '(?+ ?-))
5119 (cond ((equal char ?-) (setq strip t narrow t))
5120 ((equal char ?+) (setq strip nil narrow t)))
5122 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5123 (setq char (read-char)))
5124 (when (member char '(?< ?> ?= ??))
5125 ;; An effort operator
5126 (setq effort-op (char-to-string char))
5127 (setq alist nil) ; to make sure it will be interpreted as effort.
5128 (unless (equal char ??)
5129 (loop for i from 0 to 9 do
5133 (if (= i 9) "0" (int-to-string (1+ i)))
5134 "]" (nth i efforts))))
5135 (message "Effort%s: %s " effort-op effort-prompt)
5136 (setq char (read-char))
5137 (when (or (< char ?0) (> char ?9))
5138 (error "Need 1-9,0 to select effort" ))))
5139 (when (equal char ?\t)
5140 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5141 (org-set-local 'org-global-tags-completion-table
5142 (org-global-tags-completion-table)))
5143 (let ((completion-ignore-case t))
5144 (setq tag (org-icompleting-read
5145 "Tag: " org-global-tags-completion-table))))
5148 (org-agenda-filter-by-tag-show-all)
5149 (when org-agenda-auto-exclude-function
5150 (setq org-agenda-filter '())
5151 (dolist (tag org-tag-alist-for-agenda)
5152 (let ((modifier (funcall org-agenda-auto-exclude-function
5155 (push modifier org-agenda-filter))))
5156 (if (not (null org-agenda-filter))
5157 (org-agenda-filter-apply org-agenda-filter))))
5159 (org-agenda-filter-by-tag-show-all)
5160 (when (get 'org-agenda-filter :preset-filter)
5161 (org-agenda-filter-apply org-agenda-filter)))
5162 ((or (equal char ?\ )
5163 (setq a (rassoc char alist))
5164 (and (>= char ?0) (<= char ?9)
5165 (setq n (if (= char ?0) 9 (- char ?0 1))
5166 tag (concat effort-op (nth n efforts))
5171 (and tag (setq a (cons tag nil))))
5172 (org-agenda-filter-by-tag-show-all)
5174 (setq org-agenda-filter
5175 (cons (concat (if strip "-" "+") tag)
5176 (if narrow current nil)))
5177 (org-agenda-filter-apply org-agenda-filter))
5178 (t (error "Invalid tag selection character %c" char)))))
5180 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5181 "Refine the current filter. See `org-agenda-filter-by-tag."
5183 (org-agenda-filter-by-tag strip char 'refine))
5185 (defun org-agenda-filter-make-matcher ()
5186 "Create the form that tests a line for the agenda filter."
5188 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5190 (if (member x '("-" "+"))
5191 (setq f1 (if (equal x "-") 'tags '(not tags)))
5192 (if (string-match "[<=>?]" x)
5193 (setq f1 (org-agenda-filter-effort-form x))
5194 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5195 (if (equal (string-to-char x) ?-)
5196 (setq f1 (list 'not f1))))
5198 (cons 'and (nreverse f))))
5200 (defun org-agenda-filter-effort-form (e)
5201 "Return the form to compare the effort of the current line with what E says.
5202 E looks line \"+<2:25\"."
5204 (setq e (substring e 1))
5205 (setq op (string-to-char e) e (substring e 1))
5206 (setq op (cond ((equal op ?<) '<=)
5210 (list 'org-agenda-compare-effort (list 'quote op)
5211 (org-hh:mm-string-to-minutes e))))
5213 (defun org-agenda-compare-effort (op value)
5214 "Compare the effort of the current line with VALUE, using OP.
5215 If the line does not have an effort defined, return nil."
5216 (let ((eff (org-get-at-bol 'effort-minutes)))
5219 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5222 (defun org-agenda-filter-apply (filter)
5223 "Set FILTER as the new agenda filter and apply it."
5225 (setq org-agenda-filter filter
5226 org-agenda-filter-form (org-agenda-filter-make-matcher))
5227 (org-agenda-set-mode-name)
5229 (goto-char (point-min))
5231 (if (org-get-at-bol 'org-marker)
5233 (setq tags (org-get-at-bol 'tags)) ; used in eval
5234 (if (not (eval org-agenda-filter-form))
5235 (org-agenda-filter-by-tag-hide-line))
5236 (beginning-of-line 2))
5237 (beginning-of-line 2))))))
5239 (defun org-agenda-filter-by-tag-hide-line ()
5241 (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
5243 (org-overlay-put ov 'invisible t)
5244 (org-overlay-put ov 'type 'tags-filter)
5245 (push ov org-agenda-filter-overlays)))
5247 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5248 (setq pos (or pos (point)))
5250 (dolist (ov (org-overlays-at pos))
5251 (when (and (org-overlay-get ov 'invisible)
5252 (eq (org-overlay-get ov 'type) 'tags-filter))
5254 (if (< (org-overlay-start ov) (point-at-eol))
5255 (org-move-overlay ov (point-at-eol)
5256 (org-overlay-end ov)))))))
5258 (defun org-agenda-filter-by-tag-show-all ()
5259 (mapc 'org-delete-overlay org-agenda-filter-overlays)
5260 (setq org-agenda-filter-overlays nil)
5261 (setq org-agenda-filter nil)
5262 (setq org-agenda-filter-form nil)
5263 (org-agenda-set-mode-name))
5265 (defun org-agenda-manipulate-query-add ()
5266 "Manipulate the query by adding a search term with positive selection.
5267 Positive selection means, the term must be matched for selection of an entry."
5269 (org-agenda-manipulate-query ?\[))
5270 (defun org-agenda-manipulate-query-subtract ()
5271 "Manipulate the query by adding a search term with negative selection.
5272 Negative selection means, term must not be matched for selection of an entry."
5274 (org-agenda-manipulate-query ?\]))
5275 (defun org-agenda-manipulate-query-add-re ()
5276 "Manipulate the query by adding a search regexp with positive selection.
5277 Positive selection means, the regexp must match for selection of an entry."
5279 (org-agenda-manipulate-query ?\{))
5280 (defun org-agenda-manipulate-query-subtract-re ()
5281 "Manipulate the query by adding a search regexp with negative selection.
5282 Negative selection means, regexp must not match for selection of an entry."
5284 (org-agenda-manipulate-query ?\}))
5285 (defun org-agenda-manipulate-query (char)
5287 ((memq org-agenda-type '(timeline agenda))
5288 (let ((org-agenda-include-inactive-timestamps t))
5290 (message "Display now includes inactive timestamps as well"))
5291 ((eq org-agenda-type 'search)
5293 'org-agenda-query-string
5294 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5295 (?\{ . " +{}") (?\} . " -{}")))))
5296 (setq org-agenda-redo-command
5297 (list 'org-search-view
5299 org-agenda-query-string
5300 (+ (length org-agenda-query-string)
5301 (if (member char '(?\{ ?\})) 0 1))))
5302 (set-register org-agenda-query-register org-agenda-query-string)
5304 (t (error "Cannot manipulate query for %s-type agenda buffers"
5307 (defun org-add-to-string (var string)
5308 (set var (concat (symbol-value var) string)))
5310 (defun org-agenda-goto-date (date)
5311 "Jump to DATE in agenda."
5312 (interactive (list (org-read-date)))
5313 (org-agenda-list nil date))
5315 (defun org-agenda-goto-today ()
5318 (org-agenda-check-type t 'timeline 'agenda)
5319 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5321 (tdpos (goto-char tdpos))
5322 ((eq org-agenda-type 'agenda)
5323 (let* ((sd (time-to-days
5324 (time-subtract (current-time)
5325 (list 0 (* 3600 org-extend-today-until) 0))))
5326 (comp (org-agenda-compute-time-span sd org-agenda-span))
5327 (org-agenda-overriding-arguments org-agenda-last-arguments))
5328 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5329 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5331 (org-agenda-find-same-or-today-or-agenda)))
5332 (t (error "Cannot find today")))))
5334 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5336 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5337 (text-property-any (point-min) (point-max) 'org-today t)
5338 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5341 (defun org-agenda-later (arg)
5342 "Go forward in time by thee current span.
5343 With prefix ARG, go forward that many times the current span."
5345 (org-agenda-check-type t 'agenda)
5346 (let* ((span org-agenda-span)
5347 (sd org-starting-day)
5348 (greg (calendar-gregorian-from-absolute sd))
5349 (cnt (org-get-at-bol 'org-day-cnt))
5353 (setq sd (+ arg sd) nd 1))
5355 (setq sd (+ (* 7 arg) sd) nd 7))
5357 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5358 sd (calendar-absolute-from-gregorian greg2))
5359 (setcar greg2 (1+ (car greg2)))
5360 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5362 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5363 sd (calendar-absolute-from-gregorian greg2))
5364 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5365 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5366 (let ((org-agenda-overriding-arguments
5367 (list (car org-agenda-last-arguments) sd nd t)))
5369 (org-agenda-find-same-or-today-or-agenda cnt))))
5371 (defun org-agenda-earlier (arg)
5372 "Go backward in time by the current span.
5373 With prefix ARG, go backward that many times the current span."
5375 (org-agenda-later (- arg)))
5377 (defun org-agenda-view-mode-dispatch ()
5378 "Call one of the view mode commands."
5380 (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
5381 clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
5382 (let ((a (read-char-exclusive)))
5384 (?d (call-interactively 'org-agenda-day-view))
5385 (?w (call-interactively 'org-agenda-week-view))
5386 (?m (call-interactively 'org-agenda-month-view))
5387 (?y (call-interactively 'org-agenda-year-view))
5388 (?l (call-interactively 'org-agenda-log-mode))
5389 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5390 (?a (call-interactively 'org-agenda-archives-mode))
5391 (?A (org-agenda-archives-mode 'files))
5392 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5393 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5394 (?G (call-interactively 'org-agenda-toggle-time-grid))
5395 (?D (call-interactively 'org-agenda-toggle-diary))
5396 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5397 (org-agenda-check-type t 'timeline 'agenda)
5399 (message "Display now includes inactive timestamps as well"))
5400 (?q (message "Abort"))
5401 (otherwise (error "Invalid key" )))))
5403 (defun org-agenda-day-view (&optional day-of-year)
5404 "Switch to daily view for agenda.
5405 With argument DAY-OF-YEAR, switch to that day of the year."
5407 (setq org-agenda-ndays 1)
5408 (org-agenda-change-time-span 'day day-of-year))
5409 (defun org-agenda-week-view (&optional iso-week)
5410 "Switch to daily view for agenda.
5411 With argument ISO-WEEK, switch to the corresponding ISO week.
5412 If ISO-WEEK has more then 2 digits, only the last two encode the
5413 week. Any digits before this encode a year. So 200712 means
5414 week 12 of year 2007. Years in the range 1938-2037 can also be
5415 written as 2-digit years."
5417 (setq org-agenda-ndays 7)
5418 (org-agenda-change-time-span 'week iso-week))
5419 (defun org-agenda-month-view (&optional month)
5420 "Switch to monthly view for agenda.
5421 With argument MONTH, switch to that month."
5423 (org-agenda-change-time-span 'month month))
5424 (defun org-agenda-year-view (&optional year)
5425 "Switch to yearly view for agenda.
5426 With argument YEAR, switch to that year.
5427 If MONTH has more then 2 digits, only the last two encode the
5428 month. Any digits before this encode a year. So 200712 means
5429 December year 2007. Years in the range 1938-2037 can also be
5430 written as 2-digit years."
5433 (setq year (org-small-year-to-year year)))
5434 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5435 (org-agenda-change-time-span 'year year)
5438 (defun org-agenda-change-time-span (span &optional n)
5439 "Change the agenda view to SPAN.
5440 SPAN may be `day', `week', `month', `year'."
5441 (org-agenda-check-type t 'agenda)
5442 (if (and (not n) (equal org-agenda-span span))
5443 (error "Viewing span is already \"%s\"" span))
5444 (let* ((sd (or (org-get-at-bol 'day)
5446 (computed (org-agenda-compute-time-span sd span n))
5447 (org-agenda-overriding-arguments
5448 (list (car org-agenda-last-arguments)
5449 (car computed) (cdr computed) t)))
5451 (org-agenda-find-same-or-today-or-agenda))
5452 (org-agenda-set-mode-name)
5453 (message "Switched to %s view" span))
5455 (defun org-agenda-compute-time-span (sd span &optional n)
5456 "Compute starting date and number of days for agenda.
5457 SPAN may be `day', `week', `month', `year'. The return value
5458 is a cons cell with the starting date and the number of days,
5459 so that the date SD will be in that range."
5460 (let* ((greg (calendar-gregorian-from-absolute sd))
5464 nd w1 y1 m1 thisweek)
5468 (setq sd (+ (calendar-absolute-from-gregorian
5473 (let* ((nt (calendar-day-of-week
5474 (calendar-gregorian-from-absolute sd)))
5475 (d (if org-agenda-start-on-weekday
5476 (- nt org-agenda-start-on-weekday)
5478 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5481 (setq thisweek (car (calendar-iso-from-absolute sd)))
5483 (setq y1 (org-small-year-to-year (/ n 100))
5486 (calendar-absolute-from-iso
5488 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5491 (when (and n (> n 99))
5492 (setq y1 (org-small-year-to-year (/ n 100))
5494 (setq sd (calendar-absolute-from-gregorian
5495 (list (or n mg) 1 (or y1 yg)))
5496 nd (- (calendar-absolute-from-gregorian
5497 (list (1+ (or n mg)) 1 (or y1 yg)))
5500 (setq sd (calendar-absolute-from-gregorian
5501 (list 1 1 (or n yg)))
5502 nd (- (calendar-absolute-from-gregorian
5503 (list 1 1 (1+ (or n yg))))
5507 (defun org-agenda-next-date-line (&optional arg)
5508 "Jump to the next line indicating a date in agenda buffer."
5510 (org-agenda-check-type t 'agenda 'timeline)
5511 (beginning-of-line 1)
5512 ;; This does not work if user makes date format that starts with a blank
5513 (if (looking-at "^\\S-") (forward-char 1))
5514 (if (not (re-search-forward "^\\S-" nil t arg))
5517 (error "No next date after this line in this buffer")))
5518 (goto-char (match-beginning 0)))
5520 (defun org-agenda-previous-date-line (&optional arg)
5521 "Jump to the previous line indicating a date in agenda buffer."
5523 (org-agenda-check-type t 'agenda 'timeline)
5524 (beginning-of-line 1)
5525 (if (not (re-search-backward "^\\S-" nil t arg))
5526 (error "No previous date before this line in this buffer")))
5528 ;; Initialize the highlight
5529 (defvar org-hl (org-make-overlay 1 1))
5530 (org-overlay-put org-hl 'face 'highlight)
5532 (defun org-highlight (begin end &optional buffer)
5533 "Highlight a region with overlay."
5534 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5535 org-hl begin end (or buffer (current-buffer))))
5537 (defun org-unhighlight ()
5538 "Detach overlay INDEX."
5539 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5541 ;; FIXME this is currently not used.
5542 (defun org-highlight-until-next-command (beg end &optional buffer)
5543 "Move the highlight overlay to BEG/END, remove it before the next command."
5544 (org-highlight beg end buffer)
5545 (add-hook 'pre-command-hook 'org-unhighlight-once))
5546 (defun org-unhighlight-once ()
5547 "Remove the highlight from its position, and this function from the hook."
5548 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5551 (defun org-agenda-follow-mode ()
5552 "Toggle follow mode in an agenda buffer."
5554 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5555 (org-agenda-set-mode-name)
5556 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5558 (message "Follow mode is %s"
5559 (if org-agenda-follow-mode "on" "off")))
5561 (defun org-agenda-entry-text-mode (&optional arg)
5562 "Toggle entry text mode in an agenda buffer."
5565 (setq org-agenda-entry-text-mode t)
5566 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5567 (org-agenda-entry-text-hide)
5568 (and org-agenda-entry-text-mode
5569 (let ((org-agenda-entry-text-maxlines
5570 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5571 (org-agenda-entry-text-show)))
5572 (org-agenda-set-mode-name)
5573 (message "Entry text mode is %s. Maximum number of lines is %d"
5574 (if org-agenda-entry-text-mode "on" "off")
5575 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5577 (defun org-agenda-clockreport-mode ()
5578 "Toggle clocktable mode in an agenda buffer."
5580 (org-agenda-check-type t 'agenda)
5581 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5582 (org-agenda-set-mode-name)
5584 (message "Clocktable mode is %s"
5585 (if org-agenda-clockreport-mode "on" "off")))
5587 (defun org-agenda-log-mode (&optional special)
5588 "Toggle log mode in an agenda buffer.
5589 With argument SPECIAL, show all possible log items, not only the ones
5590 configured in `org-agenda-log-mode-items'.
5591 With a double `C-u' prefix arg, show *only* log items, nothing else."
5593 (org-agenda-check-type t 'agenda 'timeline)
5594 (setq org-agenda-show-log
5595 (if (equal special '(16))
5597 (if special '(closed clock state)
5598 (not org-agenda-show-log))))
5599 (org-agenda-set-mode-name)
5601 (message "Log mode is %s"
5602 (if org-agenda-show-log "on" "off")))
5604 (defun org-agenda-archives-mode (&optional with-files)
5605 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5606 When called with a prefix argument, include all archive files as well."
5608 (setq org-agenda-archives-mode
5609 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5610 (org-agenda-set-mode-name)
5615 ((eq org-agenda-archives-mode nil)
5616 "No archives are included")
5617 ((eq org-agenda-archives-mode 'trees)
5618 (format "Trees with :%s: tag are included" org-archive-tag))
5619 ((eq org-agenda-archives-mode t)
5620 (format "Trees with :%s: tag and all active archive files are included"
5621 org-archive-tag)))))
5623 (defun org-agenda-toggle-diary ()
5624 "Toggle diary inclusion in an agenda buffer."
5626 (org-agenda-check-type t 'agenda)
5627 (setq org-agenda-include-diary (not org-agenda-include-diary))
5629 (org-agenda-set-mode-name)
5630 (message "Diary inclusion turned %s"
5631 (if org-agenda-include-diary "on" "off")))
5633 (defun org-agenda-toggle-time-grid ()
5634 "Toggle time grid in an agenda buffer."
5636 (org-agenda-check-type t 'agenda)
5637 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5639 (org-agenda-set-mode-name)
5640 (message "Time-grid turned %s"
5641 (if org-agenda-use-time-grid "on" "off")))
5643 (defun org-agenda-set-mode-name ()
5644 "Set the mode name to indicate all the small mode settings."
5646 (concat "Org-Agenda"
5647 (if (equal org-agenda-ndays 1) " Day" "")
5648 (if (equal org-agenda-ndays 7) " Week" "")
5649 (if org-agenda-follow-mode " Follow" "")
5650 (if org-agenda-entry-text-mode " ETxt" "")
5651 (if org-agenda-include-diary " Diary" "")
5652 (if org-agenda-use-time-grid " Grid" "")
5653 (if (and (boundp 'org-habit-show-habits)
5654 org-habit-show-habits) " Habit" "")
5655 (if (consp org-agenda-show-log) " LogAll"
5656 (if org-agenda-show-log " Log" ""))
5657 (if (or org-agenda-filter (get 'org-agenda-filter
5659 (concat " {" (mapconcat
5661 (append (get 'org-agenda-filter
5663 org-agenda-filter) "") "}")
5665 (if org-agenda-archives-mode
5666 (if (eq org-agenda-archives-mode t)
5668 (format " :%s:" org-archive-tag))
5670 (if org-agenda-clockreport-mode " Clock" "")))
5671 (force-mode-line-update))
5673 (defun org-agenda-post-command-hook ()
5674 (setq org-agenda-type
5675 (or (get-text-property (point) 'org-agenda-type)
5676 (get-text-property (max (point-min) (1- (point)))
5677 'org-agenda-type))))
5679 (defun org-agenda-next-line ()
5680 "Move cursor to the next line, and show if follow-mode is active."
5682 (call-interactively 'next-line)
5683 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5685 (defun org-agenda-previous-line ()
5686 "Move cursor to the previous line, and show if follow-mode is active."
5689 (call-interactively 'previous-line)
5690 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5693 (defun org-agenda-show-priority ()
5694 "Show the priority of the current item.
5695 This priority is composed of the main priority given with the [#A] cookies,
5696 and by additional input from the age of a schedules or deadline entry."
5698 (let* ((pri (org-get-at-bol 'priority)))
5699 (message "Priority is %d" (if pri pri -1000))))
5701 (defun org-agenda-show-tags ()
5702 "Show the tags applicable to the current item."
5704 (let* ((tags (org-get-at-bol 'tags)))
5706 (message "Tags are :%s:"
5707 (org-no-properties (mapconcat 'identity tags ":")))
5708 (message "No tags associated with this line"))))
5710 (defun org-agenda-goto (&optional highlight)
5711 "Go to the Org-mode file which contains the item at point."
5713 (let* ((marker (or (org-get-at-bol 'org-marker)
5714 (org-agenda-error)))
5715 (buffer (marker-buffer marker))
5716 (pos (marker-position marker)))
5717 (switch-to-buffer-other-window buffer)
5721 (org-show-context 'agenda)
5723 (and (outline-next-heading)
5724 (org-flag-heading nil)))) ; show the next heading
5725 (recenter (/ (window-height) 2))
5726 (run-hooks 'org-agenda-after-show-hook)
5727 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
5729 (defvar org-agenda-after-show-hook nil
5730 "Normal hook run after an item has been shown from the agenda.
5731 Point is in the buffer where the item originated.")
5733 (defun org-agenda-kill ()
5734 "Kill the entry or subtree belonging to the current agenda entry."
5736 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5737 (let* ((marker (or (org-get-at-bol 'org-marker)
5738 (org-agenda-error)))
5739 (buffer (marker-buffer marker))
5740 (pos (marker-position marker))
5741 (type (org-get-at-bol 'type))
5742 dbeg dend (n 0) conf)
5743 (org-with-remote-undo buffer
5744 (with-current-buffer buffer
5747 (if (and (org-mode-p) (not (member type '("sexp"))))
5748 (setq dbeg (progn (org-back-to-heading t) (point))
5749 dend (org-end-of-subtree t t))
5750 (setq dbeg (point-at-bol)
5751 dend (min (point-max) (1+ (point-at-eol)))))
5753 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
5754 (setq conf (or (eq t org-agenda-confirm-kill)
5755 (and (numberp org-agenda-confirm-kill)
5756 (> n org-agenda-confirm-kill))))
5759 (format "Delete entry with %d lines in buffer \"%s\"? "
5760 n (buffer-name buffer))))
5762 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
5763 (with-current-buffer buffer (delete-region dbeg dend))
5764 (message "Agenda item and source killed"))))
5766 (defvar org-archive-default-command)
5767 (defun org-agenda-archive-default ()
5768 "Archive the entry or subtree belonging to the current agenda entry."
5770 (require 'org-archive)
5771 (org-agenda-archive-with org-archive-default-command))
5773 (defun org-agenda-archive-default-with-confirmation ()
5774 "Archive the entry or subtree belonging to the current agenda entry."
5776 (require 'org-archive)
5777 (org-agenda-archive-with org-archive-default-command 'confirm))
5779 (defun org-agenda-archive ()
5780 "Archive the entry or subtree belonging to the current agenda entry."
5782 (org-agenda-archive-with 'org-archive-subtree))
5784 (defun org-agenda-archive-to-archive-sibling ()
5785 "Move the entry to the archive sibling."
5787 (org-agenda-archive-with 'org-archive-to-archive-sibling))
5789 (defun org-agenda-archive-with (cmd &optional confirm)
5790 "Move the entry to the archive sibling."
5792 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5793 (let* ((marker (or (org-get-at-bol 'org-marker)
5794 (org-agenda-error)))
5795 (buffer (marker-buffer marker))
5796 (pos (marker-position marker)))
5797 (org-with-remote-undo buffer
5798 (with-current-buffer buffer
5801 (not (y-or-n-p "Archive this subtree or entry? ")))
5805 (org-remove-subtree-entries-from-agenda)
5806 (org-back-to-heading t)
5808 (error "Archiving works only in Org-mode files"))))))
5810 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
5811 "Remove all lines in the agenda that correspond to a given subtree.
5812 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5813 If this information is not given, the function uses the tree at point."
5814 (let ((buf (or buf (current-buffer))) m p)
5816 (unless (and beg end)
5817 (org-back-to-heading t)
5819 (org-end-of-subtree t)
5821 (set-buffer (get-buffer org-agenda-buffer-name))
5823 (goto-char (point-max))
5824 (beginning-of-line 1)
5826 (when (and (setq m (org-get-at-bol 'org-marker))
5827 (equal buf (marker-buffer m))
5828 (setq p (marker-position m))
5831 (let ((inhibit-read-only t))
5832 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5833 (beginning-of-line 0))))))
5835 (defun org-agenda-refile (&optional goto rfloc)
5836 "Refile the item at point."
5838 (if (equal goto '(16))
5839 (org-refile-goto-last-stored)
5840 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5841 (org-agenda-error)))
5842 (buffer (marker-buffer marker))
5843 (pos (marker-position marker))
5845 (org-refile-get-location
5846 (if goto "Goto: " "Refile to: ") buffer
5847 org-refile-allow-creating-parent-nodes))))
5848 (with-current-buffer buffer
5853 (org-remove-subtree-entries-from-agenda)
5854 (org-refile goto buffer rfloc)))))))
5856 (defun org-agenda-open-link (&optional arg)
5857 "Follow the link in the current line, if any.
5858 This looks for a link in the displayed line in the agenda. It also looks
5859 at the text of the entry itself."
5861 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5862 (org-get-at-bol 'org-marker)))
5863 (buffer (and marker (marker-buffer marker)))
5864 (prefix (buffer-substring
5867 (or (org-get-at-bol 'prefix-length) 0)))))
5870 (with-current-buffer buffer
5875 (org-offer-links-in-entry arg prefix)))))
5876 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
5878 (beginning-of-line 1)
5879 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
5880 (org-open-link-from-string (match-string 1)))
5881 (t (error "No link to open here")))))
5883 (defun org-agenda-copy-local-variable (var)
5884 "Get a variable from a referenced buffer and install it here."
5885 (let ((m (org-get-at-bol 'org-marker)))
5886 (when (and m (buffer-live-p (marker-buffer m)))
5887 (org-set-local var (with-current-buffer (marker-buffer m)
5888 (symbol-value var))))))
5890 (defun org-agenda-switch-to (&optional delete-other-windows)
5891 "Go to the Org-mode file which contains the item at point."
5893 (if (and org-return-follows-link
5894 (not (org-get-at-bol 'org-marker))
5895 (org-in-regexp org-bracket-link-regexp))
5896 (org-open-link-from-string (match-string 0))
5897 (let* ((marker (or (org-get-at-bol 'org-marker)
5898 (org-agenda-error)))
5899 (buffer (marker-buffer marker))
5900 (pos (marker-position marker)))
5901 (switch-to-buffer buffer)
5902 (and delete-other-windows (delete-other-windows))
5906 (org-show-context 'agenda)
5908 (and (outline-next-heading)
5909 (org-flag-heading nil))))))) ; show the next heading
5911 (defun org-agenda-goto-mouse (ev)
5912 "Go to the Org-mode file which contains the item at the mouse click."
5914 (mouse-set-point ev)
5917 (defun org-agenda-show (&optional full-entry)
5918 "Display the Org-mode file which contains the item at point.
5919 With prefix argument FULL-ENTRY, make the entire entry visible
5920 if it was hidden in the outline."
5922 (let ((win (selected-window)))
5924 (let ((org-show-entry-below t))
5925 (org-agenda-goto t))
5926 (org-agenda-goto t))
5927 (select-window win)))
5929 (defvar org-agenda-show-window nil)
5930 (defun org-agenda-show-and-scroll-up ()
5931 "Display the Org-mode file which contains the item at point.
5932 When called repeatedly, scroll the window that is displaying the buffer."
5934 (let ((win (selected-window)))
5935 (if (and (window-live-p org-agenda-show-window)
5936 (eq this-command last-command))
5938 (select-window org-agenda-show-window)
5939 (ignore-errors (scroll-up)))
5942 (setq org-agenda-show-window (selected-window)))
5943 (select-window win)))
5945 (defun org-agenda-show-scroll-down ()
5946 "Scroll down the window showing the agenda."
5948 (let ((win (selected-window)))
5949 (when (window-live-p org-agenda-show-window)
5950 (select-window org-agenda-show-window)
5951 (ignore-errors (scroll-down))
5952 (select-window win))))
5954 (defun org-agenda-show-1 (&optional more)
5955 "Display the Org-mode file which contains the item at point.
5956 The prefix arg causes further revieling:
5959 1 just show the entry according to defaults.
5960 2 show the children view
5961 3 show the subtree view
5962 4 show the entire subtree and any LOGBOOK drawers
5963 5 show the entire subtree and any drawers
5964 With prefix argument FULL-ENTRY, make the entire entry visible
5965 if it was hidden in the outline."
5967 (let ((win (selected-window)))
5969 (org-recenter-heading 1)
5974 (org-back-to-heading)
5975 (run-hook-with-args 'org-cycle-hook 'folded))
5976 (message "Remote: FOLDED"))
5977 ((and (interactive-p) (= more 1))
5978 (message "Remote: show with default settings"))
5983 (org-back-to-heading)
5984 (run-hook-with-args 'org-cycle-hook 'children))
5985 (message "Remote: CHILDREN"))
5989 (org-back-to-heading)
5990 (run-hook-with-args 'org-cycle-hook 'subtree))
5991 (message "Remote: SUBTREE"))
5993 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
5995 (concat "^[ \t]*:\\("
5996 (mapconcat 'regexp-quote org-drawers "\\|")
6000 (org-back-to-heading)
6001 (org-cycle-hide-drawers 'subtree)))
6002 (message "Remote: SUBTREE AND LOGBOOK"))
6005 (message "Remote: SUBTREE AND ALL DRAWERS")))
6006 (select-window win)))
6008 (defun org-recenter-heading (n)
6010 (org-back-to-heading)
6013 (defvar org-agenda-cycle-counter nil)
6014 (defun org-agenda-cycle-show (&optional n)
6015 "Show the current entry in another window, with default settings.
6016 Default settings are taken from `org-show-hierarchy-above' and siblings.
6017 When use repeatedly in immediate succession, the remote entry will cycle
6020 children -> subtree -> folded
6022 When called with a numeric prefix arg, that arg will be passed through to
6023 `org-agenda-show-1'. For the interpretation of that argument, see the
6024 docstring of `org-agenda-show-1'."
6027 (setq org-agenda-cycle-counter n)
6028 (if (not (eq last-command this-command))
6029 (setq org-agenda-cycle-counter 1)
6030 (if (equal org-agenda-cycle-counter 0)
6031 (setq org-agenda-cycle-counter 2)
6032 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6033 (if (> org-agenda-cycle-counter 3)
6034 (setq org-agenda-cycle-counter 0)))))
6035 (org-agenda-show-1 org-agenda-cycle-counter))
6037 (defun org-agenda-recenter (arg)
6038 "Display the Org-mode file which contains the item at point and recenter."
6040 (let ((win (selected-window)))
6043 (select-window win)))
6045 (defun org-agenda-show-mouse (ev)
6046 "Display the Org-mode file which contains the item at the mouse click."
6048 (mouse-set-point ev)
6051 (defun org-agenda-check-no-diary ()
6052 "Check if the entry is a diary link and abort if yes."
6053 (if (org-get-at-bol 'org-agenda-diary-link)
6054 (org-agenda-error)))
6056 (defun org-agenda-error ()
6057 (error "Command not allowed in this line"))
6059 (defun org-agenda-tree-to-indirect-buffer ()
6060 "Show the subtree corresponding to the current entry in an indirect buffer.
6061 This calls the command `org-tree-to-indirect-buffer' from the original
6063 With numerical prefix arg ARG, go up to this level and then take that tree.
6064 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6067 (org-agenda-check-no-diary)
6068 (let* ((marker (or (org-get-at-bol 'org-marker)
6069 (org-agenda-error)))
6070 (buffer (marker-buffer marker))
6071 (pos (marker-position marker)))
6072 (with-current-buffer buffer
6075 (call-interactively 'org-tree-to-indirect-buffer)))))
6077 (defvar org-last-heading-marker (make-marker)
6078 "Marker pointing to the headline that last changed its TODO state
6079 by a remote command from the agenda.")
6081 (defun org-agenda-todo-nextset ()
6082 "Switch TODO entry to next sequence."
6084 (org-agenda-todo 'nextset))
6086 (defun org-agenda-todo-previousset ()
6087 "Switch TODO entry to previous sequence."
6089 (org-agenda-todo 'previousset))
6091 (defun org-agenda-todo (&optional arg)
6092 "Cycle TODO state of line at point, also in Org-mode file.
6093 This changes the line at point, all other lines in the agenda referring to
6094 the same tree node, and the headline of the tree node in the Org-mode file."
6096 (org-agenda-check-no-diary)
6097 (let* ((col (current-column))
6098 (marker (or (org-get-at-bol 'org-marker)
6099 (org-agenda-error)))
6100 (buffer (marker-buffer marker))
6101 (pos (marker-position marker))
6102 (hdmarker (org-get-at-bol 'org-hd-marker))
6103 (todayp (equal (org-get-at-bol 'day)
6104 (time-to-days (current-time))))
6105 (inhibit-read-only t)
6106 org-agenda-headline-snapshot-before-repeat newhead just-one)
6107 (org-with-remote-undo buffer
6108 (with-current-buffer buffer
6111 (org-show-context 'agenda)
6113 (and (outline-next-heading)
6114 (org-flag-heading nil))) ; show the next heading
6115 (let ((current-prefix-arg arg))
6116 (call-interactively 'org-todo))
6117 (and (bolp) (forward-char 1))
6118 (setq newhead (org-get-heading))
6119 (when (and (org-bound-and-true-p
6120 org-agenda-headline-snapshot-before-repeat)
6121 (not (equal org-agenda-headline-snapshot-before-repeat
6124 (setq newhead org-agenda-headline-snapshot-before-repeat
6127 (org-back-to-heading)
6128 (move-marker org-last-heading-marker (point))))
6129 (beginning-of-line 1)
6131 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6132 (org-move-to-column col))))
6134 (defun org-agenda-add-note (&optional arg)
6135 "Add a time-stamped note to the entry at point."
6137 (org-agenda-check-no-diary)
6138 (let* ((marker (or (org-get-at-bol 'org-marker)
6139 (org-agenda-error)))
6140 (buffer (marker-buffer marker))
6141 (pos (marker-position marker))
6142 (hdmarker (org-get-at-bol 'org-hd-marker))
6143 (inhibit-read-only t))
6144 (with-current-buffer buffer
6147 (org-show-context 'agenda)
6149 (and (outline-next-heading)
6150 (org-flag-heading nil))) ; show the next heading
6153 (defun org-agenda-change-all-lines (newhead hdmarker
6154 &optional fixface just-this)
6155 "Change all lines in the agenda buffer which match HDMARKER.
6156 The new content of the line will be NEWHEAD (as modified by
6157 `org-format-agenda-item'). HDMARKER is checked with
6158 `equal' against all `org-hd-marker' text properties in the file.
6159 If FIXFACE is non-nil, the face of each item is modified according to
6161 If JUST-THIS is non-nil, change just the current line, not all.
6162 If FORCE-TAGS is non nil, the car of it returns the new tags."
6163 (let* ((inhibit-read-only t)
6164 (line (org-current-line))
6165 (thetags (with-current-buffer (marker-buffer hdmarker)
6166 (save-excursion (save-restriction (widen)
6167 (goto-char hdmarker)
6168 (org-get-tags-at)))))
6169 props m pl undone-face done-face finish new dotime cat tags)
6171 (goto-char (point-max))
6172 (beginning-of-line 1)
6174 (setq finish (bobp))
6175 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6176 (or (not just-this) (= (org-current-line) line))
6178 (setq props (text-properties-at (point))
6179 dotime (org-get-at-bol 'dotime)
6180 cat (org-get-at-bol 'org-category)
6182 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6183 pl (org-get-at-bol 'prefix-length)
6184 undone-face (org-get-at-bol 'undone-face)
6185 done-face (org-get-at-bol 'done-face))
6186 (goto-char (+ (point) pl))
6187 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6190 (beginning-of-line 1)
6191 (and (looking-at ".*\n?") (replace-match "")))
6193 (replace-match new t t)
6194 (beginning-of-line 1)
6195 (add-text-properties (point-at-bol) (point-at-eol) props)
6197 (add-text-properties
6198 (point-at-bol) (point-at-eol)
6200 (if org-last-todo-state-is-todo
6201 undone-face done-face))))
6202 (org-agenda-highlight-todo 'line)
6203 (beginning-of-line 1))
6204 (t (error "Line update did not work"))))
6205 (beginning-of-line 0)))
6206 (org-finalize-agenda)))
6208 (defun org-agenda-align-tags (&optional line)
6209 "Align all tags in agenda items to `org-agenda-tags-column'."
6210 (let ((inhibit-read-only t) l c)
6212 (goto-char (if line (point-at-bol) (point-min)))
6213 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6214 (if line (point-at-eol) nil) t)
6215 (add-text-properties
6216 (match-beginning 2) (match-end 2)
6217 (list 'face (delq nil (let ((prop (get-text-property
6218 (match-beginning 2) 'face)))
6219 (or (listp prop) (setq prop (list prop)))
6220 (if (memq 'org-tag prop)
6222 (cons 'org-tag prop))))))
6223 (setq l (- (match-end 2) (match-beginning 2))
6224 c (if (< org-agenda-tags-column 0)
6225 (- (abs org-agenda-tags-column) l)
6226 org-agenda-tags-column))
6227 (delete-region (match-beginning 1) (match-end 1))
6228 (goto-char (match-beginning 1))
6229 (insert (org-add-props
6230 (make-string (max 1 (- c (current-column))) ?\ )
6231 (text-properties-at (point)))))
6232 (goto-char (point-min))
6233 (org-font-lock-add-tag-faces (point-max)))))
6235 (defun org-agenda-priority-up ()
6236 "Increase the priority of line at point, also in Org-mode file."
6238 (org-agenda-priority 'up))
6240 (defun org-agenda-priority-down ()
6241 "Decrease the priority of line at point, also in Org-mode file."
6243 (org-agenda-priority 'down))
6245 (defun org-agenda-priority (&optional force-direction)
6246 "Set the priority of line at point, also in Org-mode file.
6247 This changes the line at point, all other lines in the agenda referring to
6248 the same tree node, and the headline of the tree node in the Org-mode file."
6250 (unless org-enable-priority-commands
6251 (error "Priority commands are disabled"))
6252 (org-agenda-check-no-diary)
6253 (let* ((marker (or (org-get-at-bol 'org-marker)
6254 (org-agenda-error)))
6255 (hdmarker (org-get-at-bol 'org-hd-marker))
6256 (buffer (marker-buffer hdmarker))
6257 (pos (marker-position hdmarker))
6258 (inhibit-read-only t)
6260 (org-with-remote-undo buffer
6261 (with-current-buffer buffer
6264 (org-show-context 'agenda)
6266 (and (outline-next-heading)
6267 (org-flag-heading nil))) ; show the next heading
6268 (funcall 'org-priority force-direction)
6270 (setq newhead (org-get-heading)))
6271 (org-agenda-change-all-lines newhead hdmarker)
6272 (beginning-of-line 1))))
6274 ;; FIXME: should fix the tags property of the agenda line.
6275 (defun org-agenda-set-tags (&optional tag onoff)
6276 "Set tags for the current headline."
6278 (org-agenda-check-no-diary)
6279 (if (and (org-region-active-p) (interactive-p))
6280 (call-interactively 'org-change-tag-in-region)
6281 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6282 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6283 (org-agenda-error)))
6284 (buffer (marker-buffer hdmarker))
6285 (pos (marker-position hdmarker))
6286 (inhibit-read-only t)
6288 (org-with-remote-undo buffer
6289 (with-current-buffer buffer
6293 (org-show-context 'agenda))
6295 (and (outline-next-heading)
6296 (org-flag-heading nil))) ; show the next heading
6299 (org-toggle-tag tag onoff)
6300 (call-interactively 'org-set-tags))
6302 (setq newhead (org-get-heading)))
6303 (org-agenda-change-all-lines newhead hdmarker)
6304 (beginning-of-line 1)))))
6306 (defun org-agenda-set-property ()
6307 "Set a property for the current headline."
6309 (org-agenda-check-no-diary)
6310 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6311 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6312 (org-agenda-error)))
6313 (buffer (marker-buffer hdmarker))
6314 (pos (marker-position hdmarker))
6315 (inhibit-read-only t)
6317 (org-with-remote-undo buffer
6318 (with-current-buffer buffer
6322 (org-show-context 'agenda))
6324 (and (outline-next-heading)
6325 (org-flag-heading nil))) ; show the next heading
6327 (call-interactively 'org-set-property)))))
6329 (defun org-agenda-set-effort ()
6330 "Set the effort property for the current headline."
6332 (org-agenda-check-no-diary)
6333 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6334 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6335 (org-agenda-error)))
6336 (buffer (marker-buffer hdmarker))
6337 (pos (marker-position hdmarker))
6338 (inhibit-read-only t)
6340 (org-with-remote-undo buffer
6341 (with-current-buffer buffer
6345 (org-show-context 'agenda))
6347 (and (outline-next-heading)
6348 (org-flag-heading nil))) ; show the next heading
6350 (call-interactively 'org-set-effort)
6353 (defun org-agenda-toggle-archive-tag ()
6354 "Toggle the archive tag for the current entry."
6356 (org-agenda-check-no-diary)
6357 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6358 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6359 (org-agenda-error)))
6360 (buffer (marker-buffer hdmarker))
6361 (pos (marker-position hdmarker))
6362 (inhibit-read-only t)
6364 (org-with-remote-undo buffer
6365 (with-current-buffer buffer
6368 (org-show-context 'agenda)
6370 (and (outline-next-heading)
6371 (org-flag-heading nil))) ; show the next heading
6372 (call-interactively 'org-toggle-archive-tag)
6374 (setq newhead (org-get-heading)))
6375 (org-agenda-change-all-lines newhead hdmarker)
6376 (beginning-of-line 1))))
6378 (defun org-agenda-do-date-later (arg)
6381 ((or (equal arg '(16))
6383 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6384 (setq this-command 'org-agenda-date-later-minutes)
6385 (org-agenda-date-later-minutes 1))
6386 ((or (equal arg '(4))
6388 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6389 (setq this-command 'org-agenda-date-later-hours)
6390 (org-agenda-date-later-hours 1))
6392 (org-agenda-date-later (prefix-numeric-value arg)))))
6394 (defun org-agenda-do-date-earlier (arg)
6397 ((or (equal arg '(16))
6399 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6400 (setq this-command 'org-agenda-date-earlier-minutes)
6401 (org-agenda-date-earlier-minutes 1))
6402 ((or (equal arg '(4))
6404 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6405 (setq this-command 'org-agenda-date-earlier-hours)
6406 (org-agenda-date-earlier-hours 1))
6408 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6410 (defun org-agenda-date-later (arg &optional what)
6411 "Change the date of this item to one day later."
6413 (org-agenda-check-type t 'agenda 'timeline)
6414 (org-agenda-check-no-diary)
6415 (let* ((marker (or (org-get-at-bol 'org-marker)
6416 (org-agenda-error)))
6417 (buffer (marker-buffer marker))
6418 (pos (marker-position marker)))
6419 (org-with-remote-undo buffer
6420 (with-current-buffer buffer
6423 (if (not (org-at-timestamp-p))
6424 (error "Cannot find time stamp"))
6425 (org-timestamp-change arg (or what 'day)))
6426 (org-agenda-show-new-time marker org-last-changed-timestamp))
6427 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6429 (defun org-agenda-date-earlier (arg &optional what)
6430 "Change the date of this item to one day earlier."
6432 (org-agenda-date-later (- arg) what))
6434 (defun org-agenda-date-later-minutes (arg)
6435 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6437 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6438 (org-agenda-date-later arg 'minute))
6440 (defun org-agenda-date-earlier-minutes (arg)
6441 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6443 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6444 (org-agenda-date-earlier arg 'minute))
6446 (defun org-agenda-date-later-hours (arg)
6447 "Change the time of this item, in hour steps."
6449 (org-agenda-date-later arg 'hour))
6451 (defun org-agenda-date-earlier-hours (arg)
6452 "Change the time of this item, in hour steps."
6454 (org-agenda-date-earlier arg 'hour))
6456 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6457 "Show new date stamp via text properties."
6458 ;; We use text properties to make this undoable
6459 (let ((inhibit-read-only t)
6460 (buffer-invisibility-spec))
6461 (setq stamp (concat " " prefix " => " stamp))
6463 (goto-char (point-max))
6465 (when (equal marker (org-get-at-bol 'org-marker))
6466 (org-move-to-column (- (window-width) (length stamp)) t)
6467 (org-agenda-fix-tags-filter-overlays-at (point))
6468 (if (featurep 'xemacs)
6469 ;; Use `duplicable' property to trigger undo recording
6470 (let ((ex (make-extent nil nil))
6471 (gl (make-glyph stamp)))
6472 (set-glyph-face gl 'secondary-selection)
6473 (set-extent-properties
6474 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6475 (insert-extent ex (1- (point)) (point-at-eol)))
6476 (add-text-properties
6477 (1- (point)) (point-at-eol)
6478 (list 'display (org-add-props stamp nil
6479 'face 'secondary-selection))))
6480 (beginning-of-line 1))
6481 (beginning-of-line 0)))))
6483 (defun org-agenda-date-prompt (arg)
6484 "Change the date of this item. Date is prompted for, with default today.
6485 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6486 be used to request time specification in the time stamp."
6488 (org-agenda-check-type t 'agenda 'timeline)
6489 (org-agenda-check-no-diary)
6490 (let* ((marker (or (org-get-at-bol 'org-marker)
6491 (org-agenda-error)))
6492 (buffer (marker-buffer marker))
6493 (pos (marker-position marker)))
6494 (org-with-remote-undo buffer
6495 (with-current-buffer buffer
6498 (if (not (org-at-timestamp-p))
6499 (error "Cannot find time stamp"))
6500 (org-time-stamp arg))
6501 (org-agenda-show-new-time marker org-last-changed-timestamp))
6502 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6504 (defun org-agenda-schedule (arg)
6505 "Schedule the item at point."
6507 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6508 (org-agenda-check-no-diary)
6509 (let* ((marker (or (org-get-at-bol 'org-marker)
6510 (org-agenda-error)))
6511 (type (marker-insertion-type marker))
6512 (buffer (marker-buffer marker))
6513 (pos (marker-position marker))
6514 (org-insert-labeled-timestamps-at-point nil)
6516 (set-marker-insertion-type marker t)
6517 (org-with-remote-undo buffer
6518 (with-current-buffer buffer
6521 (setq ts (org-schedule arg)))
6522 (org-agenda-show-new-time marker ts "S"))
6523 (message "Item scheduled for %s" ts)))
6525 (defun org-agenda-deadline (arg)
6526 "Schedule the item at point."
6528 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6529 (org-agenda-check-no-diary)
6530 (let* ((marker (or (org-get-at-bol 'org-marker)
6531 (org-agenda-error)))
6532 (buffer (marker-buffer marker))
6533 (pos (marker-position marker))
6534 (org-insert-labeled-timestamps-at-point nil)
6536 (org-with-remote-undo buffer
6537 (with-current-buffer buffer
6540 (setq ts (org-deadline arg)))
6541 (org-agenda-show-new-time marker ts "D"))
6542 (message "Deadline for this item set to %s" ts)))
6544 (defun org-agenda-action ()
6545 "Select entry for agenda action, or execute an agenda action.
6546 This command prompts for another letter. Valid inputs are:
6548 m Mark the entry at point for an agenda action
6549 s Schedule the marked entry to the date at the cursor
6550 d Set the deadline of the marked entry to the date at the cursor
6551 r Call `org-remember' with cursor date as the default date
6552 SPC Show marked entry in other window
6553 TAB Visit marked entry in other window
6555 The cursor may be at a date in the calendar, or in the Org agenda."
6558 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6559 (setq ans (read-char-exclusive))
6563 (if (eq major-mode 'org-agenda-mode)
6564 (let ((m (or (org-get-at-bol 'org-hd-marker)
6565 (org-get-at-bol 'org-marker))))
6568 (move-marker org-agenda-action-marker
6569 (marker-position m) (marker-buffer m))
6570 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6571 (error "Don't know which entry to mark")))
6572 (error "This command works only in the agenda")))
6574 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6576 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6578 (org-agenda-do-action '(org-remember) t))
6580 (let ((cw (selected-window)))
6581 (org-switch-to-buffer-other-window
6582 (marker-buffer org-agenda-action-marker))
6583 (goto-char org-agenda-action-marker)
6584 (org-show-context 'agenda)
6585 (select-window cw)))
6587 (org-switch-to-buffer-other-window
6588 (marker-buffer org-agenda-action-marker))
6589 (goto-char org-agenda-action-marker)
6590 (org-show-context 'agenda))
6591 (t (error "Invalid agenda action %c" ans)))))
6593 (defun org-agenda-do-action (form &optional current-buffer)
6594 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6595 (let ((org-overriding-default-time (org-get-cursor-date)))
6598 (if (not (marker-buffer org-agenda-action-marker))
6599 (error "No entry has been selected for agenda action")
6600 (with-current-buffer (marker-buffer org-agenda-action-marker)
6604 (goto-char org-agenda-action-marker)
6607 (defun org-agenda-clock-in (&optional arg)
6608 "Start the clock on the currently selected item."
6610 (org-agenda-check-no-diary)
6611 (if (equal arg '(4))
6613 (let* ((marker (or (org-get-at-bol 'org-marker)
6614 (org-agenda-error)))
6615 (hdmarker (or (org-get-at-bol 'org-hd-marker)
6617 (pos (marker-position marker))
6619 (org-with-remote-undo (marker-buffer marker)
6620 (with-current-buffer (marker-buffer marker)
6623 (org-show-context 'agenda)
6625 (org-cycle-hide-drawers 'children)
6627 (setq newhead (org-get-heading)))
6628 (org-agenda-change-all-lines newhead hdmarker)))))
6630 (defun org-agenda-clock-out (&optional arg)
6631 "Stop the currently running clock."
6633 (unless (marker-buffer org-clock-marker)
6634 (error "No running clock"))
6635 (let ((marker (make-marker)) newhead)
6636 (org-with-remote-undo (marker-buffer org-clock-marker)
6637 (with-current-buffer (marker-buffer org-clock-marker)
6641 (goto-char org-clock-marker)
6642 (org-back-to-heading t)
6643 (move-marker marker (point))
6645 (setq newhead (org-get-heading))))))
6646 (org-agenda-change-all-lines newhead marker)
6647 (move-marker marker nil)))
6649 (defun org-agenda-clock-cancel (&optional arg)
6650 "Cancel the currently running clock."
6652 (unless (marker-buffer org-clock-marker)
6653 (error "No running clock"))
6654 (org-with-remote-undo (marker-buffer org-clock-marker)
6655 (org-clock-cancel)))
6657 (defun org-agenda-diary-entry ()
6658 "Make a diary entry, like the `i' command from the calendar.
6659 All the standard commands work: block, weekly etc."
6661 (org-agenda-check-type t 'agenda 'timeline)
6662 (require 'diary-lib)
6664 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6665 (read-char-exclusive)))
6666 (cmd (cdr (assoc char
6667 '((?d . insert-diary-entry)
6668 (?w . insert-weekly-diary-entry)
6669 (?m . insert-monthly-diary-entry)
6670 (?y . insert-yearly-diary-entry)
6671 (?a . insert-anniversary-diary-entry)
6672 (?b . insert-block-diary-entry)
6673 (?c . insert-cyclic-diary-entry)))))
6674 (oldf (symbol-function 'calendar-cursor-to-date))
6675 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6677 (mark (or (mark t) (point))))
6679 (error "No command associated with <%c>" char))
6680 (unless (and (get-text-property point 'day)
6681 (or (not (equal ?b char))
6682 (get-text-property mark 'day)))
6683 (error "Don't know which date to use for diary entry"))
6684 ;; We implement this by hacking the `calendar-cursor-to-date' function
6685 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6686 (let ((calendar-mark-ring
6687 (list (calendar-gregorian-from-absolute
6688 (or (get-text-property mark 'day)
6689 (get-text-property point 'day))))))
6692 (fset 'calendar-cursor-to-date
6693 (lambda (&optional error dummy)
6694 (calendar-gregorian-from-absolute
6695 (get-text-property point 'day))))
6696 (call-interactively cmd))
6697 (fset 'calendar-cursor-to-date oldf)))))
6699 (defun org-agenda-execute-calendar-command (cmd)
6700 "Execute a calendar command from the agenda, with the date associated to
6701 the cursor position."
6702 (org-agenda-check-type t 'agenda 'timeline)
6703 (require 'diary-lib)
6704 (unless (get-text-property (point) 'day)
6705 (error "Don't know which date to use for calendar command"))
6706 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
6708 (date (calendar-gregorian-from-absolute
6709 (get-text-property point 'day)))
6710 ;; the following 2 vars are needed in the calendar
6711 (displayed-month (car date))
6712 (displayed-year (nth 2 date)))
6715 (fset 'calendar-cursor-to-date
6716 (lambda (&optional error dummy)
6717 (calendar-gregorian-from-absolute
6718 (get-text-property point 'day))))
6719 (call-interactively cmd))
6720 (fset 'calendar-cursor-to-date oldf))))
6722 (defun org-agenda-phases-of-moon ()
6723 "Display the phases of the moon for the 3 months around the cursor date."
6725 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
6727 (defun org-agenda-holidays ()
6728 "Display the holidays for the 3 months around the cursor date."
6730 (org-agenda-execute-calendar-command 'list-calendar-holidays))
6732 (defvar calendar-longitude)
6733 (defvar calendar-latitude)
6734 (defvar calendar-location-name)
6736 (defun org-agenda-sunrise-sunset (arg)
6737 "Display sunrise and sunset for the cursor date.
6738 Latitude and longitude can be specified with the variables
6739 `calendar-latitude' and `calendar-longitude'. When called with prefix
6740 argument, latitude and longitude will be prompted for."
6743 (let ((calendar-longitude (if arg nil calendar-longitude))
6744 (calendar-latitude (if arg nil calendar-latitude))
6745 (calendar-location-name
6746 (if arg "the given coordinates" calendar-location-name)))
6747 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
6749 (defun org-agenda-goto-calendar ()
6750 "Open the Emacs calendar with the date at the cursor."
6752 (org-agenda-check-type t 'agenda 'timeline)
6753 (let* ((day (or (get-text-property (point) 'day)
6754 (error "Don't know which date to open in calendar")))
6755 (date (calendar-gregorian-from-absolute day))
6756 (calendar-move-hook nil)
6757 (calendar-view-holidays-initially-flag nil)
6758 (calendar-view-diary-initially-flag nil)
6759 (view-calendar-holidays-initially nil)
6760 (view-diary-entries-initially nil))
6762 (calendar-goto-date date)))
6765 (defun org-calendar-goto-agenda ()
6766 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6767 This is a command that has to be installed in `calendar-mode-map'."
6769 (org-agenda-list nil (calendar-absolute-from-gregorian
6770 (calendar-cursor-to-date))
6773 (defun org-agenda-convert-date ()
6775 (org-agenda-check-type t 'agenda 'timeline)
6776 (let ((day (get-text-property (point) 'day))
6779 (error "Don't know which date to convert"))
6780 (setq date (calendar-gregorian-from-absolute day))
6782 "Gregorian: " (calendar-date-string date) "\n"
6783 "ISO: " (calendar-iso-date-string date) "\n"
6784 "Day of Yr: " (calendar-day-of-year-string date) "\n"
6785 "Julian: " (calendar-julian-date-string date) "\n"
6786 "Astron. JD: " (calendar-astro-date-string date)
6787 " (Julian date number at noon UTC)\n"
6788 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
6789 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
6790 "French: " (calendar-french-date-string date) "\n"
6791 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
6792 "Mayan: " (calendar-mayan-date-string date) "\n"
6793 "Coptic: " (calendar-coptic-date-string date) "\n"
6794 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
6795 "Persian: " (calendar-persian-date-string date) "\n"
6796 "Chinese: " (calendar-chinese-date-string date) "\n"))
6797 (with-output-to-temp-buffer "*Dates*"
6799 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6803 (defvar org-agenda-bulk-marked-entries nil
6804 "List of markers that refer to marked entries in the agenda.")
6806 (defun org-agenda-bulk-marked-p ()
6807 (eq (get-char-property (point-at-bol) 'type)
6808 'org-marked-entry-overlay))
6810 (defun org-agenda-bulk-mark ()
6811 "Mark the entry at point for future bulk action."
6813 (org-agenda-check-no-diary)
6814 (let* ((m (org-get-at-bol 'org-hd-marker))
6816 (unless (org-agenda-bulk-marked-p)
6817 (unless m (error "Nothing to mark at point"))
6818 (push m org-agenda-bulk-marked-entries)
6819 (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
6820 (org-overlay-display ov "> "
6821 (org-get-todo-face "TODO")
6823 (org-overlay-put ov 'type 'org-marked-entry-overlay))
6824 (beginning-of-line 2)
6825 (message "%d entries marked for bulk action"
6826 (length org-agenda-bulk-marked-entries))))
6828 (defun org-agenda-bulk-unmark ()
6829 "Unmark the entry at point for future bulk action."
6831 (when (org-agenda-bulk-marked-p)
6832 (org-agenda-bulk-remove-overlays
6833 (point-at-bol) (+ 2 (point-at-bol)))
6834 (setq org-agenda-bulk-marked-entries
6835 (delete (org-get-at-bol 'org-hd-marker)
6836 org-agenda-bulk-marked-entries)))
6837 (beginning-of-line 2)
6838 (message "%d entries marked for bulk action"
6839 (length org-agenda-bulk-marked-entries)))
6841 (defun org-agenda-bulk-toggle ()
6842 "Toggle marking the entry at point for bulk action."
6844 (if (org-agenda-bulk-marked-p)
6845 (org-agenda-bulk-unmark)
6846 (org-agenda-bulk-mark)))
6848 (defun org-agenda-bulk-remove-overlays (&optional beg end)
6849 "Remove the mark overlays between BEG and END in the agenda buffer.
6850 BEG and END default to the buffer limits.
6852 This only removes the overlays, it does not remove the markers
6853 from the list in `org-agenda-bulk-marked-entries'."
6856 (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
6857 (org-delete-overlay ov)))
6858 (org-overlays-in (or beg (point-min)) (or end (point-max)))))
6860 (defun org-agenda-bulk-remove-all-marks ()
6861 "Remove all marks in the agenda buffer.
6862 This will remove the markers, and the overlays."
6864 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
6865 (setq org-agenda-bulk-marked-entries nil)
6866 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
6868 (defun org-agenda-bulk-action ()
6869 "Execute an remote-editing action on all marked entries."
6871 (unless org-agenda-bulk-marked-entries
6872 (error "No entries are marked"))
6873 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
6874 (let* ((action (read-char-exclusive))
6875 (entries (reverse org-agenda-bulk-marked-entries))
6876 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
6879 (setq cmd '(org-agenda-archive)))
6882 (setq cmd '(org-agenda-archive-to-archive-sibling)))
6884 ((member action '(?r ?w))
6885 (setq rfloc (org-refile-get-location
6887 (marker-buffer (car org-agenda-bulk-marked-entries))
6888 org-refile-allow-creating-parent-nodes))
6889 (setcar (nthcdr 3 rfloc)
6890 (move-marker (make-marker) (nth 3 rfloc)
6891 (or (get-file-buffer (nth 1 rfloc))
6892 (find-buffer-visiting (nth 1 rfloc))
6893 (error "This should not happen"))))
6895 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
6898 (setq state (org-icompleting-read
6900 (with-current-buffer (marker-buffer (car entries))
6901 (mapcar 'list org-todo-keywords-1))))
6902 (setq cmd `(let ((org-inhibit-blocking t)
6903 (org-inhibit-logging 'note))
6904 (org-agenda-todo ,state))))
6906 ((memq action '(?- ?+))
6907 (setq tag (org-icompleting-read
6908 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
6909 (with-current-buffer (marker-buffer (car entries))
6912 (if (stringp (car x)) x)) org-tag-alist)))))
6913 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
6915 ((memq action '(?s ?d))
6916 (let* ((date (org-read-date
6918 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
6919 (ans org-read-date-final-answer)
6920 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
6921 (setq cmd `(let* ((bound (fboundp 'read-string))
6922 (old (and bound (symbol-function 'read-string))))
6925 (fset 'read-string (lambda (&rest ignore) ,ans))
6926 (call-interactively ',c1))
6928 (fset 'read-string old)
6929 (fmakunbound 'read-string)))))))
6930 (t (error "Invalid bulk action")))
6932 ;; Sort the markers, to make sure that parents are handled before children
6933 (setq entries (sort entries
6936 ((equal (marker-buffer a) (marker-buffer b))
6937 (< (marker-position a) (marker-position b)))
6939 (string< (buffer-name (marker-buffer a))
6940 (buffer-name (marker-buffer b))))))))
6942 ;; Now loop over all markers and apply cmd
6943 (while (setq e (pop entries))
6944 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
6946 (progn (message "Skipping removed entry at %s" e)
6947 (setq cntskip (1+ cntskip)))
6950 (setq org-agenda-bulk-marked-entries
6951 (delete e org-agenda-bulk-marked-entries))
6952 (setq cnt (1+ cnt))))
6953 (setq org-agenda-bulk-marked-entries nil)
6954 (org-agenda-bulk-remove-all-marks)
6955 (message "Acted on %d entries%s"
6959 (format ", skipped %d (disappeared before their turn)"
6964 (defun org-agenda-show-the-flagging-note ()
6965 "Display the flagging note in the other window.
6966 When called a second time in direct sequence, offer to remove the FLAGGING
6967 tag and (if present) the flagging note."
6969 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
6970 (win (selected-window))
6971 note heading newhead)
6973 (error "No linked entry at point"))
6974 (if (and (eq this-command last-command)
6975 (y-or-n-p "Unflag and remove any flagging note? "))
6977 (org-agenda-remove-flag hdmarker)
6978 (let ((win (get-buffer-window "*Flagging Note*")))
6979 (and win (delete-window win)))
6980 (message "Entry unflaged"))
6981 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
6983 (error "No flagging note"))
6985 (org-switch-to-buffer-other-window "*Flagging Note*")
6988 (goto-char (point-min))
6989 (while (re-search-forward "\\\\n" nil t)
6990 (replace-match "\n" t t))
6991 (goto-char (point-min))
6993 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
6995 (defun org-agenda-remove-flag (marker)
6996 "Remove the FLAGGED tag and any flaging note in the entry."
6998 (org-with-point-at marker
6999 (org-toggle-tag "FLAGGED" 'off)
7000 (org-entry-delete nil "THEFLAGGINGNOTE")
7001 (setq newhead (org-get-heading)))
7002 (org-agenda-change-all-lines newhead marker)
7003 (message "Entry unflaged")))
7005 (defun org-agenda-get-any-marker (&optional pos)
7006 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7007 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7009 ;;; Appointment reminders
7011 (defvar appt-time-msg-list)
7014 (defun org-agenda-to-appt (&optional refresh filter)
7015 "Activate appointments found in `org-agenda-files'.
7016 With a \\[universal-argument] prefix, refresh the list of
7019 If FILTER is t, interactively prompt the user for a regular
7020 expression, and filter out entries that don't match it.
7022 If FILTER is a string, use this string as a regular expression
7023 for filtering entries out.
7025 FILTER can also be an alist with the car of each cell being
7026 either 'headline or 'category. For example:
7028 '((headline \"IMPORTANT\")
7029 (category \"Work\"))
7031 will only add headlines containing IMPORTANT or headlines
7032 belonging to the \"Work\" category."
7035 (if refresh (setq appt-time-msg-list nil))
7037 (setq filter (read-from-minibuffer "Regexp filter: ")))
7038 (let* ((cnt 0) ; count added events
7039 (org-agenda-new-buffers nil)
7040 (org-deadline-warning-days 0)
7041 (today (org-date-to-gregorian
7042 (time-to-days (current-time))))
7043 (org-agenda-restrict nil)
7044 (files (org-agenda-files 'unrestricted)) entries file)
7045 ;; Get all entries which may contain an appt
7046 (org-prepare-agenda-buffers files)
7047 (while (setq file (pop files))
7050 (org-agenda-get-day-entries
7051 file today :timestamp :scheduled :deadline))))
7052 (setq entries (delq nil entries))
7053 ;; Map thru entries and find if we should filter them out
7056 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7057 (cat (get-text-property 1 'org-category x))
7058 (tod (get-text-property 1 'time-of-day x))
7059 (ok (or (null filter)
7060 (and (stringp filter) (string-match filter evt))
7063 (cadr (assoc 'category filter)) cat)
7065 (cadr (assoc 'headline filter)) evt))))))
7066 ;; FIXME: Shall we remove text-properties for the appt text?
7067 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7069 (setq tod (concat "00" (number-to-string tod))
7070 tod (when (string-match
7071 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7072 (concat (match-string 1 tod) ":"
7073 (match-string 2 tod))))
7075 (setq cnt (1+ cnt))))) entries)
7076 (org-release-buffers org-agenda-new-buffers)
7078 (message "No event to add")
7079 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7081 (defun org-agenda-todayp (date)
7082 "Does DATE mean today, when considering `org-extend-today-until'?"
7084 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7085 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7086 (setq h (nth 2 (decode-time (current-time))))
7087 (or (and (>= h org-extend-today-until)
7089 (and (< h org-extend-today-until)
7090 (= date (1- today))))))
7092 (provide 'org-agenda)
7094 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7096 ;;; org-agenda.el ends here