1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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.
37 (declare-function diary-add-to-list
"diary-lib"
38 (date string specifier
&optional marker globcolor literal
))
39 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
40 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
41 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
42 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
43 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
44 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
45 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
46 (declare-function calendar-goto-date
"cal-move" (date))
47 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
48 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
49 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
50 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
51 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
52 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
53 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
54 (declare-function org-datetree-find-date-create
"org-datetree"
55 (date &optional keep-restriction
))
56 (declare-function org-columns-quit
"org-colview" ())
57 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
58 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line
))
61 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
62 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
63 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
64 (defvar calendar-mode-map
)
65 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
66 (defvar org-habit-show-habits
)
67 (defvar org-habit-show-habits-only-for-today
)
69 ;; Defined somewhere in this file, but used before definition.
70 (defvar org-agenda-buffer-name
)
71 (defvar org-agenda-overriding-header
)
72 (defvar org-agenda-title-append nil
)
75 (defvar org-agenda-undo-list
)
76 (defvar org-agenda-pending-undo-list
)
77 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
79 (defcustom org-agenda-confirm-kill
1
80 "When set, remote killing from the agenda buffer needs confirmation.
81 When t, a confirmation is always needed. When a number N, confirmation is
82 only needed when the text to be killed contains more than N non-white lines."
85 (const :tag
"Never" nil
)
86 (const :tag
"Always" t
)
87 (integer :tag
"When more than N lines")))
89 (defcustom org-agenda-compact-blocks nil
90 "Non-nil means make the block agenda more compact.
91 This is done by leaving out unnecessary lines."
95 (defcustom org-agenda-block-separator ?
=
96 "The separator between blocks in the agenda.
97 If this is a string, it will be used as the separator, with a newline added.
98 If it is a character, it will be repeated to fill the window width."
104 (defgroup org-agenda-export nil
105 "Options concerning exporting agenda views in Org-mode."
106 :tag
"Org Agenda Export"
109 (defcustom org-agenda-with-colors t
110 "Non-nil means use colors in agenda views."
111 :group
'org-agenda-export
114 (defcustom org-agenda-exporter-settings nil
115 "Alist of variable/value pairs that should be active during agenda export.
116 This is a good place to set options for ps-print and for htmlize.
117 Note that the way this is implemented, the values will be evaluated
118 before assigned to the variables. So make sure to quote values you do
119 *not* want evaluated, for example
121 (setq org-agenda-exporter-settings
122 '((ps-print-color-p 'black-white)))"
123 :group
'org-agenda-export
127 (sexp :tag
"Value"))))
129 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
130 "Hook run in temporary buffer before writing it to an export file.
131 A useful function is `org-agenda-add-entry-text'."
132 :group
'org-agenda-export
134 :options
'(org-agenda-add-entry-text))
136 (defcustom org-agenda-add-entry-text-maxlines
0
137 "Maximum number of entry text lines to be added to agenda.
138 This is only relevant when `org-agenda-add-entry-text' is part of
139 `org-agenda-before-write-hook', which it is by default.
140 When this is 0, nothing will happen. When it is greater than 0, it
141 specifies the maximum number of lines that will be added for each entry
142 that is listed in the agenda view.
144 Note that this variable is not used during display, only when exporting
145 the agenda. For agenda display, see org-agenda-entry-text-mode and the
146 variable `org-agenda-entry-text-maxlines'."
150 (defcustom org-agenda-add-entry-text-descriptive-links t
151 "Non-nil means export org-links as descriptive links in agenda added text.
152 This variable applies to the text added to the agenda when
153 `org-agenda-add-entry-text-maxlines' is larger than 0.
154 When this variable nil, the URL will (also) be shown."
158 (defcustom org-agenda-export-html-style
""
159 "The style specification for exported HTML Agenda files.
160 If this variable contains a string, it will replace the default <style>
161 section as produced by `htmlize'.
162 Since there are different ways of setting style information, this variable
163 needs to contain the full HTML structure to provide a style, including the
164 surrounding HTML tags. The style specifications should include definitions
165 the fonts used by the agenda, here is an example:
167 <style type=\"text/css\">
168 p { font-weight: normal; color: gray; }
169 .org-agenda-structure {
184 .title { text-align: center; }
185 .todo, .deadline { color: red; }
186 .done { color: green; }
189 or, if you want to keep the style in a file,
191 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
193 As the value of this option simply gets inserted into the HTML <head> header,
194 you can \"misuse\" it to also add other text to the header. However,
195 <style>...</style> is required, if not present the variable will be ignored."
196 :group
'org-agenda-export
197 :group
'org-export-html
200 (defgroup org-agenda-custom-commands nil
201 "Options concerning agenda views in Org-mode."
202 :tag
"Org Agenda Custom Commands"
205 (defconst org-sorting-choice
207 (const time-up
) (const time-down
)
208 (const category-keep
) (const category-up
) (const category-down
)
209 (const tag-down
) (const tag-up
)
210 (const priority-up
) (const priority-down
)
211 (const todo-state-up
) (const todo-state-down
)
212 (const effort-up
) (const effort-down
)
213 (const habit-up
) (const habit-down
)
214 (const user-defined-up
) (const user-defined-down
))
217 (defconst org-agenda-custom-commands-local-options
218 `(repeat :tag
"Local settings for this command. Remember to quote values"
219 (choice :tag
"Setting"
220 (list :tag
"Heading for this block"
221 (const org-agenda-overriding-header
)
222 (string :tag
"Headline"))
223 (list :tag
"Files to be searched"
224 (const org-agenda-files
)
226 (const :format
"" quote
)
228 (list :tag
"Sorting strategy"
229 (const org-agenda-sorting-strategy
)
231 (const :format
"" quote
)
233 ,org-sorting-choice
)))
234 (list :tag
"Prefix format"
235 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
237 (list :tag
"Number of days in agenda"
238 (const org-agenda-ndays
)
240 (list :tag
"Fixed starting date"
241 (const org-agenda-start-day
)
242 (string :value
"2007-11-01"))
243 (list :tag
"Start on day of week"
244 (const org-agenda-start-on-weekday
)
246 (const :tag
"Today" nil
)
247 (integer :tag
"Weekday No.")))
248 (list :tag
"Include data from diary"
249 (const org-agenda-include-diary
)
251 (list :tag
"Deadline Warning days"
252 (const org-deadline-warning-days
)
254 (list :tag
"Tags filter preset"
255 (const org-agenda-filter-preset
)
257 (const :format
"" quote
)
259 (string :tag
"+tag or -tag"))))
260 (list :tag
"Set daily/weekly entry types"
261 (const org-agenda-entry-types
)
262 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
267 (list :tag
"Standard skipping condition"
268 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
269 (const org-agenda-skip-function
)
271 (const :format
"" quote
)
274 :tag
"Skipping range"
275 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
276 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
277 (repeat :inline t
:tag
"Conditions for skipping"
279 :tag
"Condition type"
280 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
281 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
282 (list :tag
"TODO state is" :inline t
285 (const :tag
"any not-done state" 'todo
)
286 (const :tag
"any done state" 'done
)
287 (const :tag
"any state" 'any
)
288 (list :tag
"Keyword list"
289 (const :format
"" quote
)
290 (repeat (string :tag
"Keyword")))))
291 (list :tag
"TODO state is not" :inline t
294 (const :tag
"any not-done state" 'todo
)
295 (const :tag
"any done state" 'done
)
296 (const :tag
"any state" 'any
)
297 (list :tag
"Keyword list"
298 (const :format
"" quote
)
299 (repeat (string :tag
"Keyword")))))
300 (const :tag
"scheduled" 'scheduled
)
301 (const :tag
"not scheduled" 'notscheduled
)
302 (const :tag
"deadline" 'deadline
)
303 (const :tag
"no deadline" 'notdeadline
)
304 (const :tag
"timestamp" 'timestamp
)
305 (const :tag
"no timestamp" 'nottimestamp
))))))
306 (list :tag
"Non-standard skipping condition"
307 :value
(org-agenda-skip-function)
308 (const org-agenda-skip-function
)
309 (sexp :tag
"Function or form (quoted!)"))
310 (list :tag
"Any variable"
311 (variable :tag
"Variable")
312 (sexp :tag
"Value (sexp)"))))
313 "Selection of examples for agenda command settings.
314 This will be spliced into the custom type of
315 `org-agenda-custom-commands'.")
318 (defcustom org-agenda-custom-commands nil
319 "Custom commands for the agenda.
320 These commands will be offered on the splash screen displayed by the
321 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
323 (key desc type match settings files)
325 key The key (one or more characters as a string) to be associated
327 desc A description of the command, when omitted or nil, a default
328 description is built using MATCH.
329 type The command type, any of the following symbols:
330 agenda The daily/weekly agenda.
331 todo Entries with a specific TODO keyword, in all agenda files.
332 search Entries containing search words entry or headline.
333 tags Tags/Property/TODO match in all agenda files.
334 tags-todo Tags/P/T match in all agenda files, TODO entries only.
335 todo-tree Sparse tree of specific TODO keyword in *current* file.
336 tags-tree Sparse tree with all tags matches in *current* file.
337 occur-tree Occur sparse tree for *current* file.
338 ... A user-defined function.
339 match What to search for:
340 - a single keyword for TODO keyword searches
341 - a tags match expression for tags searches
342 - a word search expression for text searches.
343 - a regular expression for occur searches
344 For all other commands, this should be the empty string.
345 settings A list of option settings, similar to that in a let form, so like
346 this: ((opt1 val1) (opt2 val2) ...). The values will be
347 evaluated at the moment of execution, so quote them when needed.
348 files A list of files file to write the produced agenda buffer to
349 with the command `org-store-agenda-views'.
350 If a file name ends in \".html\", an HTML version of the buffer
351 is written out. If it ends in \".ps\", a postscript version is
352 produced. Otherwise, only the plain text is written to the file.
354 You can also define a set of commands, to create a composite agenda buffer.
355 In this case, an entry looks like this:
357 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
361 desc A description string to be displayed in the dispatcher menu.
362 cmd An agenda command, similar to the above. However, tree commands
363 are no allowed, but instead you can get agenda and global todo list.
364 So valid commands for a set are:
365 (agenda \"\" settings)
366 (alltodo \"\" settings)
367 (stuck \"\" settings)
368 (todo \"match\" settings files)
369 (search \"match\" settings files)
370 (tags \"match\" settings files)
371 (tags-todo \"match\" settings files)
373 Each command can carry a list of options, and another set of options can be
374 given for the whole set of commands. Individual command options take
375 precedence over the general options.
377 When using several characters as key to a command, the first characters
378 are prefix commands. For the dispatcher to display useful information, you
379 should provide a description for the prefix, like
381 (setq org-agenda-custom-commands
382 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
383 (\"hl\" tags \"+HOME+Lisa\")
384 (\"hp\" tags \"+HOME+Peter\")
385 (\"hk\" tags \"+HOME+Kim\")))"
386 :group
'org-agenda-custom-commands
388 (choice :value
("x" "Describe command here" tags
"" nil
)
389 (list :tag
"Single command"
390 (string :tag
"Access Key(s) ")
391 (option (string :tag
"Description"))
393 (const :tag
"Agenda" agenda
)
394 (const :tag
"TODO list" alltodo
)
395 (const :tag
"Search words" search
)
396 (const :tag
"Stuck projects" stuck
)
397 (const :tag
"Tags/Property match (all agenda files)" tags
)
398 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
399 (const :tag
"TODO keyword search (all agenda files)" todo
)
400 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
401 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
402 (const :tag
"Occur tree (current buffer)" occur-tree
)
403 (sexp :tag
"Other, user-defined function"))
404 (string :tag
"Match (only for some commands)")
405 ,org-agenda-custom-commands-local-options
406 (option (repeat :tag
"Export" (file :tag
"Export to"))))
407 (list :tag
"Command series, all agenda files"
408 (string :tag
"Access Key(s)")
409 (string :tag
"Description ")
410 (repeat :tag
"Component"
413 (const :format
"" agenda
)
414 (const :tag
"" :format
"" "")
415 ,org-agenda-custom-commands-local-options
)
416 (list :tag
"TODO list (all keywords)"
417 (const :format
"" alltodo
)
418 (const :tag
"" :format
"" "")
419 ,org-agenda-custom-commands-local-options
)
420 (list :tag
"Search words"
421 (const :format
"" search
)
422 (string :tag
"Match")
423 ,org-agenda-custom-commands-local-options
)
424 (list :tag
"Stuck projects"
425 (const :format
"" stuck
)
426 (const :tag
"" :format
"" "")
427 ,org-agenda-custom-commands-local-options
)
428 (list :tag
"Tags search"
429 (const :format
"" tags
)
430 (string :tag
"Match")
431 ,org-agenda-custom-commands-local-options
)
432 (list :tag
"Tags search, TODO entries only"
433 (const :format
"" tags-todo
)
434 (string :tag
"Match")
435 ,org-agenda-custom-commands-local-options
)
436 (list :tag
"TODO keyword search"
437 (const :format
"" todo
)
438 (string :tag
"Match")
439 ,org-agenda-custom-commands-local-options
)
440 (list :tag
"Other, user-defined function"
441 (symbol :tag
"function")
442 (string :tag
"Match")
443 ,org-agenda-custom-commands-local-options
)))
445 (repeat :tag
"Settings for entire command set"
446 (list (variable :tag
"Any variable")
447 (sexp :tag
"Value")))
448 (option (repeat :tag
"Export" (file :tag
"Export to"))))
449 (cons :tag
"Prefix key documentation"
450 (string :tag
"Access Key(s)")
451 (string :tag
"Description ")))))
453 (defcustom org-agenda-query-register ?o
454 "The register holding the current query string.
455 The purpose of this is that if you construct a query string interactively,
456 you can then use it to define a custom command."
457 :group
'org-agenda-custom-commands
460 (defcustom org-stuck-projects
461 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
462 "How to identify stuck projects.
463 This is a list of four items:
464 1. A tags/todo/property matcher string that is used to identify a project.
465 See the manual for a description of tag and property searches.
466 The entire tree below a headline matched by this is considered one project.
467 2. A list of TODO keywords identifying non-stuck projects.
468 If the project subtree contains any headline with one of these todo
469 keywords, the project is considered to be not stuck. If you specify
470 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
471 3. A list of tags identifying non-stuck projects.
472 If the project subtree contains any headline with one of these tags,
473 the project is considered to be not stuck. If you specify \"*\" as
474 a tag, any tag will mark the project unstuck. Note that this is about
475 the explicit presence of a tag somewhere in the subtree, inherited
476 tags to not count here. If inherited tags make a project not stuck,
477 use \"-TAG\" in the tags part of the matcher under (1.) above.
478 4. An arbitrary regular expression matching non-stuck projects.
480 If the project turns out to be not stuck, search continues also in the
481 subtree to see if any of the subtasks have project status.
483 See also the variable `org-tags-match-list-sublevels' which applies
484 to projects matched by this search as well.
486 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
487 or `C-c a #' to produce the list."
488 :group
'org-agenda-custom-commands
490 (string :tag
"Tags/TODO match to identify a project")
491 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
492 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
493 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
495 (defcustom org-agenda-filter-effort-default-operator
"<"
496 "The default operator for effort estimate filtering.
497 If you select an effort estimate limit without first pressing an operator,
498 this one will be used."
499 :group
'org-agenda-custom-commands
500 :type
'(choice (const :tag
"less or equal" "<")
501 (const :tag
"greater or equal"">")
502 (const :tag
"equal" "=")))
504 (defgroup org-agenda-skip nil
505 "Options concerning skipping parts of agenda files."
506 :tag
"Org Agenda Skip"
508 (defgroup org-agenda-daily
/weekly nil
509 "Options concerning the daily/weekly agenda."
510 :tag
"Org Agenda Daily/Weekly"
512 (defgroup org-agenda-todo-list nil
513 "Options concerning the global todo list agenda view."
514 :tag
"Org Agenda Todo List"
516 (defgroup org-agenda-match-view nil
517 "Options concerning the general tags/property/todo match agenda view."
518 :tag
"Org Agenda Match View"
520 (defgroup org-agenda-search-view nil
521 "Options concerning the general tags/property/todo match agenda view."
522 :tag
"Org Agenda Match View"
525 (defvar org-agenda-archives-mode nil
526 "Non-nil means the agenda will include archived items.
527 If this is the symbol `trees', trees in the selected agenda scope
528 that are marked with the ARCHIVE tag will be included anyway. When this is
529 t, also all archive files associated with the current selection of agenda
530 files will be included.")
532 (defcustom org-agenda-skip-comment-trees t
533 "Non-nil means skip trees that start with the COMMENT keyword.
534 When nil, these trees are also scanned by agenda commands."
535 :group
'org-agenda-skip
538 (defcustom org-agenda-todo-list-sublevels t
539 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
540 When nil, the sublevels of a TODO entry are not checked, resulting in
541 potentially much shorter TODO lists."
542 :group
'org-agenda-skip
543 :group
'org-agenda-todo-list
546 (defcustom org-agenda-todo-ignore-with-date nil
547 "Non-nil means don't show entries with a date in the global todo list.
548 You can use this if you prefer to mark mere appointments with a TODO keyword,
549 but don't want them to show up in the TODO list.
550 When this is set, it also covers deadlines and scheduled items, the settings
551 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
553 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
554 :group
'org-agenda-skip
555 :group
'org-agenda-todo-list
558 (defcustom org-agenda-todo-ignore-scheduled nil
559 "Non-nil means, ignore some scheduled TODO items when making TODO list.
560 This applies when creating the global todo list.
563 past Don't show entries scheduled today or in the past.
565 future Don't show entries scheduled in the future.
566 The idea behind this is that by scheduling it, you don't want to
567 think about it until the scheduled date.
569 all Don't show any scheduled entries in the global todo list.
570 The idea behind this is that by scheduling it, you have already
571 \"taken care\" of this item.
573 t Same as `all', for backward compatibility.
575 See also `org-agenda-todo-ignore-with-date'.
576 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
577 to make his option also apply to the tags-todo list."
578 :group
'org-agenda-skip
579 :group
'org-agenda-todo-list
581 (const :tag
"Ignore future-scheduled todos" future
)
582 (const :tag
"Ignore past- or present-scheduled todos" past
)
583 (const :tag
"Ignore all scheduled todos" all
)
584 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
585 (const :tag
"Show scheduled todos" nil
)))
587 (defcustom org-agenda-todo-ignore-deadlines nil
588 "Non-nil means ignore some deadlined TODO items when making TODO list.
589 There are different motivations for using different values, please think
590 carefully when configuring this variable.
592 This applie when creating the global todo list.
595 near Don't show near deadline entries. A deadline is near when it is
596 closer than `org-deadline-warning-days' days. The idea behind this
597 is that such items will appear in the agenda anyway.
599 far Don't show TODO entries where a deadline has been defined, but
600 the deadline is not near. This is useful if you don't want to
601 use the todo list to figure out what to do now.
603 past Don't show entries with a deadline timestamp for today or in the past.
605 future Don't show entries with a deadline timestamp in the future, not even
606 when they become `near' ones. Use it with caution.
608 all Ignore all TODO entries that do have a deadline.
610 t Same as `near', for backward compatibility.
612 See also `org-agenda-todo-ignore-with-date'.
613 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
614 to make his option also apply to the tags-todo list."
615 :group
'org-agenda-skip
616 :group
'org-agenda-todo-list
618 (const :tag
"Ignore near deadlines" near
)
619 (const :tag
"Ignore near deadlines (compatibility)" t
)
620 (const :tag
"Ignore far deadlines" far
)
621 (const :tag
"Ignore all TODOs with a deadlines" all
)
622 (const :tag
"Show all TODOs, even if they have a deadline" nil
)))
624 (defcustom org-agenda-tags-todo-honor-ignore-options nil
625 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
627 `org-agenda-todo-ignore-with-date',
628 `org-agenda-todo-ignore-scheduled'
629 `org-agenda-todo-ignore-deadlines'
630 make the global TODO list skip entries that have time stamps of certain
631 kinds. If this option is set, the same options will also apply for the
632 tags-todo search, which is the general tags/property matcher
633 restricted to unfinished TODO entries only."
634 :group
'org-agenda-skip
635 :group
'org-agenda-todo-list
636 :group
'org-agenda-match-view
639 (defcustom org-agenda-skip-scheduled-if-done nil
640 "Non-nil means don't show scheduled items in agenda when they are done.
641 This is relevant for the daily/weekly agenda, not for the TODO list. And
642 it applies only to the actual date of the scheduling. Warnings about
643 an item with a past scheduling dates are always turned off when the item
645 :group
'org-agenda-skip
646 :group
'org-agenda-daily
/weekly
649 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
650 "Non-nil means skip scheduling line if same entry shows because of deadline.
651 In the agenda of today, an entry can show up multiple times because
652 it is both scheduled and has a nearby deadline, and maybe a plain time
654 When this variable is t, then only the deadline is shown and the fact that
655 the entry is scheduled today or was scheduled previously is not shown.
656 When this variable is nil, the entry will be shown several times. When
657 the variable is the symbol `not-today', then skip scheduled previously,
658 but not scheduled today."
659 :group
'org-agenda-skip
660 :group
'org-agenda-daily
/weekly
662 (const :tag
"Never" nil
)
663 (const :tag
"Always" t
)
664 (const :tag
"Not when scheduled today" not-today
)))
666 (defcustom org-agenda-skip-deadline-if-done nil
667 "Non-nil means don't show deadlines when the corresponding item is done.
668 When nil, the deadline is still shown and should give you a happy feeling.
669 This is relevant for the daily/weekly agenda. And it applied only to the
670 actually date of the deadline. Warnings about approaching and past-due
671 deadlines are always turned off when the item is DONE."
672 :group
'org-agenda-skip
673 :group
'org-agenda-daily
/weekly
676 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
677 "Non-nil means skip deadline prewarning when entry is also scheduled.
678 This will apply on all days where a prewarning for the deadline would
679 be shown, but not at the day when the entry is actually due. On that day,
680 the deadline will be shown anyway.
681 This variable may be set to nil, t, or a number which will then give
682 the number of days before the actual deadline when the prewarnings
684 This can be used in a workflow where the first showing of the deadline will
685 trigger you to schedule it, and then you don't want to be reminded of it
686 because you will take care of it on the day when scheduled."
687 :group
'org-agenda-skip
688 :group
'org-agenda-daily
/weekly
690 (const :tag
"Alwas show prewarning" nil
)
691 (const :tag
"Remove prewarning if entry is scheduled" t
)
692 (integer :tag
"Restart prewarning N days before deadline")))
694 (defcustom org-agenda-skip-additional-timestamps-same-entry t
695 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
696 When non-nil, after the search for timestamps has matched once in an
697 entry, the rest of the entry will not be searched."
698 :group
'org-agenda-skip
701 (defcustom org-agenda-skip-timestamp-if-done nil
702 "Non-nil means don't select item by timestamp or -range if it is DONE."
703 :group
'org-agenda-skip
704 :group
'org-agenda-daily
/weekly
707 (defcustom org-agenda-dim-blocked-tasks t
708 "Non-nil means dim blocked tasks in the agenda display.
709 This causes some overhead during agenda construction, but if you
710 have turned on `org-enforce-todo-dependencies',
711 `org-enforce-todo-checkbox-dependencies', or any other blocking
712 mechanism, this will create useful feedback in the agenda.
714 Instead of t, this variable can also have the value `invisible'.
715 Then blocked tasks will be invisible and only become visible when
716 they become unblocked. An exemption to this behavior is when a task is
717 blocked because of unchecked checkboxes below it. Since checkboxes do
718 not show up in the agenda views, making this task invisible you remove any
719 trace from agenda views that there is something to do. Therefore, a task
720 that is blocked because of checkboxes will never be made invisible, it
721 will only be dimmed."
722 :group
'org-agenda-daily
/weekly
723 :group
'org-agenda-todo-list
725 (const :tag
"Do not dim" nil
)
726 (const :tag
"Dim to a grey face" t
)
727 (const :tag
"Make invisible" invisible
)))
729 (defcustom org-timeline-show-empty-dates
3
730 "Non-nil means `org-timeline' also shows dates without an entry.
731 When nil, only the days which actually have entries are shown.
732 When t, all days between the first and the last date are shown.
733 When an integer, show also empty dates, but if there is a gap of more than
734 N days, just insert a special line indicating the size of the gap."
735 :group
'org-agenda-skip
737 (const :tag
"None" nil
)
739 (integer :tag
"at most")))
741 (defgroup org-agenda-startup nil
742 "Options concerning initial settings in the Agenda in Org Mode."
743 :tag
"Org Agenda Startup"
746 (defcustom org-finalize-agenda-hook nil
747 "Hook run just before displaying an agenda buffer."
748 :group
'org-agenda-startup
751 (defcustom org-agenda-mouse-1-follows-link nil
752 "Non-nil means mouse-1 on a link will follow the link in the agenda.
753 A longer mouse click will still set point. Does not work on XEmacs.
754 Needs to be set before org.el is loaded."
755 :group
'org-agenda-startup
758 (defcustom org-agenda-start-with-follow-mode nil
759 "The initial value of follow-mode in a newly created agenda window."
760 :group
'org-agenda-startup
763 (defcustom org-agenda-show-outline-path t
764 "Non-nil means show outline path in echo area after line motion."
765 :group
'org-agenda-startup
768 (defcustom org-agenda-start-with-entry-text-mode nil
769 "The initial value of entry-text-mode in a newly created agenda window."
770 :group
'org-agenda-startup
773 (defcustom org-agenda-entry-text-maxlines
5
774 "Number of text lines to be added when `E' is pressed in the agenda.
776 Note that this variable only used during agenda display. Add add entry text
777 when exporting the agenda, configure the variable
778 `org-agenda-add-entry-ext-maxlines'."
782 (defcustom org-agenda-entry-text-exclude-regexps nil
783 "List of regular expressions to clean up entry text.
784 The complete matches of all regular expressions in this list will be
785 removed from entry text before it is shown in the agenda."
787 :type
'(repeat (regexp)))
789 (defvar org-agenda-entry-text-cleanup-hook nil
790 "Hook that is run after basic cleanup of entry text to be shown in agenda.
791 This cleanup is done in a temporary buffer, so the function may inspect and
792 change the entire buffer.
793 Some default stuff like drawers and scheduling/deadline dates will already
794 have been removed when this is called, as will any matches for regular
795 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
797 (defvar org-agenda-include-inactive-timestamps nil
798 "Non-nil means include inactive time stamps in agenda and timeline.")
800 (defgroup org-agenda-windows nil
801 "Options concerning the windows used by the Agenda in Org Mode."
802 :tag
"Org Agenda Windows"
805 (defcustom org-agenda-window-setup
'reorganize-frame
806 "How the agenda buffer should be displayed.
807 Possible values for this option are:
809 current-window Show agenda in the current window, keeping all other windows.
810 other-window Use `switch-to-buffer-other-window' to display agenda.
811 reorganize-frame Show only two windows on the current frame, the current
812 window and the agenda.
813 other-frame Use `switch-to-buffer-other-frame' to display agenda.
814 Also, when exiting the agenda, kill that frame.
815 See also the variable `org-agenda-restore-windows-after-quit'."
816 :group
'org-agenda-windows
818 (const current-window
)
821 (const reorganize-frame
)))
823 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
824 "The min and max height of the agenda window as a fraction of frame height.
825 The value of the variable is a cons cell with two numbers between 0 and 1.
826 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
827 :group
'org-agenda-windows
828 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
830 (defcustom org-agenda-restore-windows-after-quit nil
831 "Non-nil means restore window configuration open exiting agenda.
832 Before the window configuration is changed for displaying the agenda,
833 the current status is recorded. When the agenda is exited with
834 `q' or `x' and this option is set, the old state is restored. If
835 `org-agenda-window-setup' is `other-frame', the value of this
836 option will be ignored."
837 :group
'org-agenda-windows
840 (defcustom org-agenda-ndays
7
841 "Number of days to include in overview display.
843 Custom commands can set this variable in the options section."
844 :group
'org-agenda-daily
/weekly
847 (defcustom org-agenda-start-on-weekday
1
848 "Non-nil means start the overview always on the specified weekday.
849 0 denotes Sunday, 1 denotes Monday etc.
850 When nil, always start on the current day.
851 Custom commands can set this variable in the options section."
852 :group
'org-agenda-daily
/weekly
853 :type
'(choice (const :tag
"Today" nil
)
854 (integer :tag
"Weekday No.")))
856 (defcustom org-agenda-show-all-dates t
857 "Non-nil means `org-agenda' shows every day in the selected range.
858 When nil, only the days which actually have entries are shown."
859 :group
'org-agenda-daily
/weekly
862 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
863 "Format string for displaying dates in the agenda.
864 Used by the daily/weekly agenda and by the timeline. This should be
865 a format string understood by `format-time-string', or a function returning
866 the formatted date as a string. The function must take a single argument,
867 a calendar-style date list like (month day year)."
868 :group
'org-agenda-daily
/weekly
870 (string :tag
"Format string")
871 (function :tag
"Function")))
873 (defun org-agenda-format-date-aligned (date)
874 "Format a date string for display in the daily/weekly agenda, or timeline.
875 This function makes sure that dates are aligned for easy reading."
877 (let* ((dayname (calendar-day-name date
))
879 (day-of-week (calendar-day-of-week date
))
881 (monthname (calendar-month-name month
))
883 (iso-week (org-days-to-iso-week
884 (calendar-absolute-from-gregorian date
)))
885 (weekyear (cond ((and (= month
1) (>= iso-week
52))
887 ((and (= month
12) (<= iso-week
1))
890 (weekstring (if (= day-of-week
1)
891 (format " W%02d" iso-week
)
893 (format "%-10s %2d %s %4d%s"
894 dayname day monthname year weekstring
)))
896 (defcustom org-agenda-time-leading-zero nil
897 "Non-nil means use leading zero for military times in agenda.
898 For example, 9:30am would become 09:30 rather than 9:30."
899 :group
'org-agenda-daily
/weekly
902 (defcustom org-agenda-weekend-days
'(6 0)
903 "Which days are weekend?
904 These days get the special face `org-agenda-date-weekend' in the agenda
905 and timeline buffers."
906 :group
'org-agenda-daily
/weekly
907 :type
'(set :greedy t
908 (const :tag
"Monday" 1)
909 (const :tag
"Tuesday" 2)
910 (const :tag
"Wednesday" 3)
911 (const :tag
"Thursday" 4)
912 (const :tag
"Friday" 5)
913 (const :tag
"Saturday" 6)
914 (const :tag
"Sunday" 0)))
916 (defcustom org-agenda-include-diary nil
917 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
918 Custom commands can set this variable in the options section."
919 :group
'org-agenda-daily
/weekly
922 (defcustom org-agenda-include-deadlines t
923 "If non-nil, include entries within their deadline warning period.
924 Custom commands can set this variable in the options section."
925 :group
'org-agenda-daily
/weekly
928 (defcustom org-agenda-include-all-todo nil
929 "Set means weekly/daily agenda will always contain all TODO entries.
930 The TODO entries will be listed at the top of the agenda, before
931 the entries for specific days.
932 This option is deprecated, it is better to define a block agenda instead."
933 :group
'org-agenda-daily
/weekly
936 (defcustom org-agenda-repeating-timestamp-show-all t
937 "Non-nil means show all occurrences of a repeating stamp in the agenda.
938 When nil, only one occurrence is shown, either today or the
939 nearest into the future."
940 :group
'org-agenda-daily
/weekly
943 (defcustom org-scheduled-past-days
10000
944 "No. of days to continue listing scheduled items that are not marked DONE.
945 When an item is scheduled on a date, it shows up in the agenda on this
946 day and will be listed until it is marked done for the number of days
948 :group
'org-agenda-daily
/weekly
951 (defcustom org-agenda-log-mode-items
'(closed clock
)
952 "List of items that should be shown in agenda log mode.
953 This list may contain the following symbols:
955 closed Show entries that have been closed on that day.
956 clock Show entries that have received clocked time on that day.
957 state Show all logged state changes.
958 Note that instead of changing this variable, you can also press `C-u l' in
959 the agenda to display all available LOG items temporarily."
960 :group
'org-agenda-daily
/weekly
961 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
963 (defcustom org-agenda-log-mode-add-notes t
964 "Non-nil means add first line of notes to log entries in agenda views.
965 If a log item like a state change or a clock entry is associated with
966 notes, the first line of these notes will be added to the entry in the
968 :group
'org-agenda-daily
/weekly
971 (defcustom org-agenda-start-with-log-mode nil
972 "The initial value of log-mode in a newly created agenda window."
973 :group
'org-agenda-startup
974 :group
'org-agenda-daily
/weekly
977 (defcustom org-agenda-start-with-clockreport-mode nil
978 "The initial value of clockreport-mode in a newly created agenda window."
979 :group
'org-agenda-startup
980 :group
'org-agenda-daily
/weekly
983 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
984 "Property list with parameters for the clocktable in clockreport mode.
985 This is the display mode that shows a clock table in the daily/weekly
986 agenda, the properties for this dynamic block can be set here.
987 The usual clocktable parameters are allowed here, but you cannot set
988 the properties :name, :tstart, :tend, :block, and :scope - these will
989 be overwritten to make sure the content accurately reflects the
990 current display in the agenda."
991 :group
'org-agenda-daily
/weekly
994 (defcustom org-agenda-search-view-always-boolean nil
995 "Non-nil means the search string is interpreted as individual parts.
997 The search string for search view can either be interpreted as a phrase,
998 or as a list of snippets that define a boolean search for a number of
1001 When this is non-nil, the string will be split on whitespace, and each
1002 snippet will be searched individually, and all must match in order to
1003 select an entry. A snippet is then a single string of non-white
1004 characters, or a string in double quotes, or a regexp in {} braces.
1005 If a snippet is preceeded by \"-\", the snippet must *not* match.
1006 \"+\" is syntactic sugar for positive selection. Each snippet may
1007 be found as a full word or a partial word, but see the variable
1008 `org-agenda-search-view-force-full-words'.
1010 When this is nil, search will look for the entire search phrase as one,
1011 with each space character matching any amount of whitespace, including
1014 Even when this is nil, you can still switch to Boolean search dynamically
1015 by preceeding the first snippet with \"+\" or \"-\". If the first snippet
1016 is a regexp marked with braces like \"{abc}\", this will also switch to
1018 :group
'org-agenda-search-view
1021 (if (fboundp 'defvaralias
)
1022 (defvaralias 'org-agenda-search-view-search-words-only
1023 'org-agenda-search-view-always-boolean
))
1025 (defcustom org-agenda-search-view-force-full-words nil
1027 ans, search words must be matches as complete words.
1028 When nil, they may also match part of a word."
1029 :group
'org-agenda-search-view
1032 (defgroup org-agenda-time-grid nil
1033 "Options concerning the time grid in the Org-mode Agenda."
1034 :tag
"Org Agenda Time Grid"
1037 (defcustom org-agenda-search-headline-for-time t
1038 "Non-nil means search headline for a time-of-day.
1039 If the headline contains a time-of-day in one format or another, it will
1040 be used to sort the entry into the time sequence of items for a day.
1041 Some people have time stamps in the headline that refer to the creation
1042 time or so, and then this produces an unwanted side effect. If this is
1043 the case for your, use this variable to turn off searching the headline
1045 :group
'org-agenda-time-grid
1048 (defcustom org-agenda-use-time-grid t
1049 "Non-nil means show a time grid in the agenda schedule.
1050 A time grid is a set of lines for specific times (like every two hours between
1051 8:00 and 20:00). The items scheduled for a day at specific times are
1052 sorted in between these lines.
1053 For details about when the grid will be shown, and what it will look like, see
1054 the variable `org-agenda-time-grid'."
1055 :group
'org-agenda-time-grid
1058 (defcustom org-agenda-time-grid
1059 '((daily today require-timed
)
1061 (800 1000 1200 1400 1600 1800 2000))
1063 "The settings for time grid for agenda display.
1064 This is a list of three items. The first item is again a list. It contains
1065 symbols specifying conditions when the grid should be displayed:
1067 daily if the agenda shows a single day
1068 weekly if the agenda shows an entire week
1069 today show grid on current date, independent of daily/weekly display
1070 require-timed show grid only if at least one item has a time specification
1072 The second item is a string which will be placed behind the grid time.
1074 The third item is a list of integers, indicating the times that should have
1076 :group
'org-agenda-time-grid
1079 (set :greedy t
:tag
"Grid Display Options"
1080 (const :tag
"Show grid in single day agenda display" daily
)
1081 (const :tag
"Show grid in weekly agenda display" weekly
)
1082 (const :tag
"Always show grid for today" today
)
1083 (const :tag
"Show grid only if any timed entries are present"
1085 (const :tag
"Skip grid times already present in an entry"
1087 (string :tag
"Grid String")
1088 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1090 (defgroup org-agenda-sorting nil
1091 "Options concerning sorting in the Org-mode Agenda."
1092 :tag
"Org Agenda Sorting"
1095 (defcustom org-agenda-sorting-strategy
1096 '((agenda habit-down time-up priority-down category-keep
)
1097 (todo priority-down category-keep
)
1098 (tags priority-down category-keep
)
1099 (search category-keep
))
1100 "Sorting structure for the agenda items of a single day.
1101 This is a list of symbols which will be used in sequence to determine
1102 if an entry should be listed before another entry. The following
1103 symbols are recognized:
1105 time-up Put entries with time-of-day indications first, early first
1106 time-down Put entries with time-of-day indications first, late first
1107 category-keep Keep the default order of categories, corresponding to the
1108 sequence in `org-agenda-files'.
1109 category-up Sort alphabetically by category, A-Z.
1110 category-down Sort alphabetically by category, Z-A.
1111 tag-up Sort alphabetically by last tag, A-Z.
1112 tag-down Sort alphabetically by last tag, Z-A.
1113 priority-up Sort numerically by priority, high priority last.
1114 priority-down Sort numerically by priority, high priority first.
1115 todo-state-up Sort by todo state, tasks that are done last.
1116 todo-state-down Sort by todo state, tasks that are done first.
1117 effort-up Sort numerically by estimated effort, high effort last.
1118 effort-down Sort numerically by estimated effort, high effort first.
1119 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1120 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1121 habit-up Put entries that are habits first
1122 habit-down Put entries that are habits last
1124 The different possibilities will be tried in sequence, and testing stops
1125 if one comparison returns a \"not-equal\". For example, the default
1126 '(time-up category-keep priority-down)
1127 means: Pull out all entries having a specified time of day and sort them,
1128 in order to make a time schedule for the current day the first thing in the
1129 agenda listing for the day. Of the entries without a time indication, keep
1130 the grouped in categories, don't sort the categories, but keep them in
1131 the sequence given in `org-agenda-files'. Within each category sort by
1134 Leaving out `category-keep' would mean that items will be sorted across
1135 categories by priority.
1137 Instead of a single list, this can also be a set of list for specific
1138 contents, with a context symbol in the car of the list, any of
1139 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1141 Custom commands can bind this variable in the options section."
1142 :group
'org-agenda-sorting
1144 (repeat :tag
"General" ,org-sorting-choice
)
1145 (list :tag
"Individually"
1146 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1147 (repeat ,org-sorting-choice
))
1148 (cons (const :tag
"Strategy for TODO lists" todo
)
1149 (repeat ,org-sorting-choice
))
1150 (cons (const :tag
"Strategy for Tags matches" tags
)
1151 (repeat ,org-sorting-choice
))
1152 (cons (const :tag
"Strategy for search matches" search
)
1153 (repeat ,org-sorting-choice
)))))
1155 (defcustom org-agenda-cmp-user-defined nil
1156 "A function to define the comparison `user-defined'.
1157 This function must receive two arguments, agenda entry a and b.
1158 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1159 the user comparison, return nil.
1160 When this is defined, you can make `user-defined-up' and `user-defined-down'
1161 part of an agenda sorting strategy."
1162 :group
'org-agenda-sorting
1165 (defcustom org-sort-agenda-notime-is-late t
1166 "Non-nil means items without time are considered late.
1167 This is only relevant for sorting. When t, items which have no explicit
1168 time like 15:30 will be considered as 99:01, i.e. later than any items which
1169 do have a time. When nil, the default time is before 0:00. You can use this
1170 option to decide if the schedule for today should come before or after timeless
1172 :group
'org-agenda-sorting
1175 (defcustom org-sort-agenda-noeffort-is-high t
1176 "Non-nil means items without effort estimate are sorted as high effort.
1177 This also applies when filtering an agenda view with respect to the
1178 < or > effort operator. Then, tasks with no effort defined will be treated
1179 as tasks with high effort.
1180 When nil, such items are sorted as 0 minutes effort."
1181 :group
'org-agenda-sorting
1184 (defgroup org-agenda-line-format nil
1185 "Options concerning the entry prefix in the Org-mode agenda display."
1186 :tag
"Org Agenda Line Format"
1189 (defcustom org-agenda-prefix-format
1190 '((agenda .
" %-12:c%?-12t% s")
1194 (search .
" %-12:c"))
1195 "Format specifications for the prefix of items in the agenda views.
1196 An alist with four entries, for the different agenda types. The keys to the
1197 sublists are `agenda', `timeline', `todo', and `tags'. The values
1199 This format works similar to a printf format, with the following meaning:
1201 %c the category of the item, \"Diary\" for entries from the diary, or
1202 as given by the CATEGORY keyword or derived from the file name.
1203 %T the *last* tag of the item. Last because inherited tags come
1205 %t the time-of-day specification if one applies to the entry, in the
1207 %s Scheduling/Deadline information, a short string
1209 All specifiers work basically like the standard `%s' of printf, but may
1210 contain two additional characters: A question mark just after the `%' and
1211 a whitespace/punctuation character just before the final letter.
1213 If the first character after `%' is a question mark, the entire field
1214 will only be included if the corresponding value applies to the
1215 current entry. This is useful for fields which should have fixed
1216 width when present, but zero width when absent. For example,
1217 \"%?-12t\" will result in a 12 character time field if a time of the
1218 day is specified, but will completely disappear in entries which do
1221 If there is punctuation or whitespace character just before the final
1222 format letter, this character will be appended to the field value if
1223 the value is not empty. For example, the format \"%-12:c\" leads to
1224 \"Diary: \" if the category is \"Diary\". If the category were be
1225 empty, no additional colon would be inserted.
1227 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1228 - Indent the line with two space characters
1229 - Give the category in a 12 chars wide field, padded with whitespace on
1230 the right (because of `-'). Append a colon if there is a category
1232 - If there is a time-of-day, put it into a 12 chars wide field. If no
1233 time, don't put in an empty field, just skip it (because of '?').
1234 - Finally, put the scheduling information and append a whitespace.
1236 As another example, if you don't want the time-of-day of entries in
1237 the prefix, you could use:
1239 (setq org-agenda-prefix-format \" %-11:c% s\")
1241 See also the variables `org-agenda-remove-times-when-in-prefix' and
1242 `org-agenda-remove-tags'.
1244 Custom commands can set this variable in the options section."
1246 (string :tag
"General format")
1247 (list :greedy t
:tag
"View dependent"
1248 (cons (const agenda
) (string :tag
"Format"))
1249 (cons (const timeline
) (string :tag
"Format"))
1250 (cons (const todo
) (string :tag
"Format"))
1251 (cons (const tags
) (string :tag
"Format"))
1252 (cons (const search
) (string :tag
"Format"))))
1253 :group
'org-agenda-line-format
)
1255 (defvar org-prefix-format-compiled nil
1256 "The compiled version of the most recently used prefix format.
1257 See the variable `org-agenda-prefix-format'.")
1259 (defcustom org-agenda-todo-keyword-format
"%-1s"
1260 "Format for the TODO keyword in agenda lines.
1261 Set this to something like \"%-12s\" if you want all TODO keywords
1262 to occupy a fixed space in the agenda display."
1263 :group
'org-agenda-line-format
1266 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1267 "Text preceding timerange entries in the agenda view.
1268 This is a list with two strings. The first applies when the range
1269 is entirely on one day. The second applies if the range spans several days.
1270 The strings may have two \"%d\" format specifiers which will be filled
1271 with the sequence number of the days, and the total number of days in the
1272 range, respectively."
1273 :group
'org-agenda-line-format
1275 (string :tag
"Deadline today ")
1276 (choice :tag
"Deadline relative"
1277 (string :tag
"Format string")
1280 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1281 "Text preceeding scheduled items in the agenda view.
1282 This is a list with two strings. The first applies when the item is
1283 scheduled on the current day. The second applies when it has been scheduled
1284 previously, it may contain a %d indicating that this is the nth time that
1285 this item is scheduled, due to automatic rescheduling of unfinished items
1286 for the following day. So this number is one larger than the number of days
1287 that passed since this item was scheduled first."
1288 :group
'org-agenda-line-format
1290 (string :tag
"Scheduled today ")
1291 (string :tag
"Scheduled previously")))
1293 (defcustom org-agenda-inactive-leader
"["
1294 "Text preceeding item pulled into the agenda by inactive time stamps.
1295 These entries are added to the agenda when pressing \"[\"."
1296 :group
'org-agenda-line-format
1298 (string :tag
"Scheduled today ")
1299 (string :tag
"Scheduled previously")))
1301 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1302 "Text preceeding deadline items in the agenda view.
1303 This is a list with two strings. The first applies when the item has its
1304 deadline on the current day. The second applies when it is in the past or
1305 in the future, it may contain %d to capture how many days away the deadline
1307 :group
'org-agenda-line-format
1309 (string :tag
"Deadline today ")
1310 (choice :tag
"Deadline relative"
1311 (string :tag
"Format string")
1314 (defcustom org-agenda-remove-times-when-in-prefix t
1315 "Non-nil means remove duplicate time specifications in agenda items.
1316 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1317 time-of-day specification in a headline or diary entry is extracted and
1318 placed into the prefix. If this option is non-nil, the original specification
1319 \(a timestamp or -range, or just a plain time(range) specification like
1320 11:30-4pm) will be removed for agenda display. This makes the agenda less
1322 The option can be t or nil. It may also be the symbol `beg', indicating
1323 that the time should only be removed when it is located at the beginning of
1324 the headline/diary entry."
1325 :group
'org-agenda-line-format
1327 (const :tag
"Always" t
)
1328 (const :tag
"Never" nil
)
1329 (const :tag
"When at beginning of entry" beg
)))
1332 (defcustom org-agenda-default-appointment-duration nil
1333 "Default duration for appointments that only have a starting time.
1334 When nil, no duration is specified in such cases.
1335 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1336 :group
'org-agenda-line-format
1338 (integer :tag
"Minutes")
1339 (const :tag
"No default duration")))
1341 (defcustom org-agenda-show-inherited-tags t
1342 "Non-nil means show inherited tags in each agenda line."
1343 :group
'org-agenda-line-format
1346 (defcustom org-agenda-hide-tags-regexp nil
1347 "Regular expression used to filter away specific tags in agenda views.
1348 This means that these tags will be present, but not be shown in the agenda
1349 line. Secondayt filltering will still work on the hidden tags.
1350 Nil means don't hide any tags."
1351 :group
'org-agenda-line-format
1353 (const :tag
"Hide none" nil
)
1354 (string :tag
"Regexp ")))
1356 (defcustom org-agenda-remove-tags nil
1357 "Non-nil means remove the tags from the headline copy in the agenda.
1358 When this is the symbol `prefix', only remove tags when
1359 `org-agenda-prefix-format' contains a `%T' specifier."
1360 :group
'org-agenda-line-format
1362 (const :tag
"Always" t
)
1363 (const :tag
"Never" nil
)
1364 (const :tag
"When prefix format contains %T" prefix
)))
1366 (if (fboundp 'defvaralias
)
1367 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1368 'org-agenda-remove-tags
))
1370 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1371 "Shift tags in agenda items to this column.
1372 If this number is positive, it specifies the column. If it is negative,
1373 it means that the tags should be flushright to that column. For example,
1374 -80 works well for a normal 80 character screen."
1375 :group
'org-agenda-line-format
1378 (if (fboundp 'defvaralias
)
1379 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1381 (defcustom org-agenda-fontify-priorities
'cookies
1382 "Non-nil means highlight low and high priorities in agenda.
1383 When t, the highest priority entries are bold, lowest priority italic.
1384 However, settings in org-priority-faces will overrule these faces.
1385 When this variable is the symbol `cookies', only fontify the
1386 cookies, not the entire task.
1387 This may also be an association list of priority faces, whose
1388 keys are the character values of `org-highest-priority',
1389 `org-default-priority', and `org-lowest-priority' (the default values
1390 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1391 color as a string, or a list like `(:background \"Red\")'.
1392 If it is a color, the variable `org-faces-easy-properties'
1393 determines if it is a foreground or a background color."
1394 :group
'org-agenda-line-format
1396 (const :tag
"Never" nil
)
1397 (const :tag
"Defaults" t
)
1398 (const :tag
"Cookies only" cookies
)
1399 (repeat :tag
"Specify"
1400 (list (character :tag
"Priority" :value ?A
)
1401 (choice :tag
"Face "
1402 (string :tag
"Color")
1403 (sexp :tag
"Face"))))))
1405 (defgroup org-agenda-column-view nil
1406 "Options concerning column view in the agenda."
1407 :tag
"Org Agenda Column View"
1410 (defcustom org-agenda-columns-show-summaries t
1411 "Non-nil means show summaries for columns displayed in the agenda view."
1412 :group
'org-agenda-column-view
1415 (defcustom org-agenda-columns-remove-prefix-from-item t
1416 "Non-nil means remove the prefix from a headline for agenda column view.
1417 The special ITEM field in the columns format contains the current line, with
1418 all information shown in other columns (like the TODO state or a tag).
1419 When this variable is non-nil, also the agenda prefix will be removed from
1420 the content of the ITEM field, to make sure as much as possible of the
1421 headline can be shown in the limited width of the field."
1425 (defcustom org-agenda-columns-compute-summary-properties t
1426 "Non-nil means recompute all summary properties before column view.
1427 When column view in the agenda is listing properties that have a summary
1428 operator, it can go to all relevant buffers and recompute the summaries
1429 there. This can mean overhead for the agenda column view, but is necessary
1430 to have thing up to date.
1431 As a special case, a CLOCKSUM property also makes sure that the clock
1432 computations are current."
1433 :group
'org-agenda-column-view
1436 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1437 "Non-nil means the duration of an appointment will add to day effort.
1438 The property to which appointment durations will be added is the one given
1439 in the option `org-effort-property'. If an appointment does not have
1440 an end time, `org-agenda-default-appointment-duration' will be used. If that
1441 is not set, an appointment without end time will not contribute to the time
1443 :group
'org-agenda-column-view
1446 (defcustom org-agenda-auto-exclude-function nil
1447 "A function called with a tag to decide if it is filtered on '/ RET'.
1448 The sole argument to the function, which is called once for each
1449 possible tag, is a string giving the name of the tag. The
1450 function should return either nil if the tag should be included
1451 as normal, or \"-<TAG>\" to exclude the tag.
1452 Note that for the purpose of tag filtering, only the lower-case version of
1453 all tags will be considered, so that this function will only ever see
1454 the lower-case version of all tags."
1462 (defun org-add-agenda-custom-command (entry)
1463 "Replace or add a command in `org-agenda-custom-commands'.
1464 This is mostly for hacking and trying a new command - once the command
1465 works you probably want to add it to `org-agenda-custom-commands' for good."
1466 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1468 (setcdr ass
(cdr entry
))
1469 (push entry org-agenda-custom-commands
))))
1471 ;;; Define the Org-agenda-mode
1473 (defvar org-agenda-mode-map
(make-sparse-keymap)
1474 "Keymap for `org-agenda-mode'.")
1475 (if (fboundp 'defvaralias
)
1476 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1478 (defvar org-agenda-menu
) ; defined later in this file.
1479 (defvar org-agenda-restrict
) ; defined later in this file.
1480 (defvar org-agenda-follow-mode nil
)
1481 (defvar org-agenda-entry-text-mode nil
)
1482 (defvar org-agenda-clockreport-mode nil
)
1483 (defvar org-agenda-show-log nil
)
1484 (defvar org-agenda-redo-command nil
)
1485 (defvar org-agenda-query-string nil
)
1486 (defvar org-agenda-mode-hook nil
1487 "Hook for org-agenda-mode, run after the mode is turned on.")
1488 (defvar org-agenda-type nil
)
1489 (defvar org-agenda-force-single-file nil
)
1490 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1492 (defun org-agenda-mode ()
1493 "Mode for time-sorted view on action items in Org-mode files.
1495 The following commands are available:
1497 \\{org-agenda-mode-map}"
1499 (kill-all-local-variables)
1500 (setq org-agenda-undo-list nil
1501 org-agenda-pending-undo-list nil
1502 org-agenda-bulk-marked-entries nil
)
1503 (setq major-mode
'org-agenda-mode
)
1504 ;; Keep global-font-lock-mode from turning on font-lock-mode
1505 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1506 (setq mode-name
"Org-Agenda")
1507 (use-local-map org-agenda-mode-map
)
1508 (easy-menu-add org-agenda-menu
)
1509 (if org-startup-truncated
(setq truncate-lines t
))
1510 (org-set-local 'line-move-visual nil
)
1511 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1512 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1513 ;; Make sure properties are removed when copying text
1514 (when (boundp 'buffer-substring-filters
)
1515 (org-set-local 'buffer-substring-filters
1517 (set-text-properties 0 (length x
) nil x
) x
)
1518 buffer-substring-filters
)))
1519 (unless org-agenda-keep-modes
1520 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1521 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1522 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1523 org-agenda-show-log org-agenda-start-with-log-mode
))
1526 '("Agenda") "Agenda Files"
1530 (if (get 'org-agenda-files
'org-restrict
)
1531 "Restricted to single file"
1533 '(org-edit-agenda-file-list)
1534 (not (get 'org-agenda-files
'org-restrict
)))
1536 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1537 (org-agenda-set-mode-name)
1539 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1540 (list 'org-agenda-mode-hook
)))
1542 (substitute-key-definition 'undo
'org-agenda-undo
1543 org-agenda-mode-map global-map
)
1544 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1545 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1546 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1547 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1548 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1549 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1550 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1551 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1552 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1553 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1554 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1555 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1556 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1557 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1558 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1559 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1560 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1561 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1562 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1563 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1564 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1565 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1566 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1567 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1568 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1569 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1570 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1571 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1572 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1573 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1574 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1575 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1576 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1577 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1578 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1579 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1580 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1581 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1582 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1583 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1584 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1585 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1586 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1588 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1589 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1590 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1591 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1592 (while l (org-defkey org-agenda-mode-map
1593 (int-to-string (pop l)) 'digit-argument)))
1595 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1596 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1597 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1598 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1599 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1600 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1601 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1602 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1603 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1604 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1605 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1606 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1607 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1608 'org-clock-modify-effort-estimate)
1609 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1610 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1611 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1612 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1613 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1614 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1615 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1616 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1617 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1618 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1619 (substitute-key-definition 'next-line 'org-agenda-next-line
1620 org-agenda-mode-map global-map)
1621 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1622 org-agenda-mode-map global-map)
1623 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1624 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1625 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1626 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1627 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1628 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1629 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1630 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1631 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1632 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1633 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1634 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1635 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1636 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1637 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1638 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1639 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1640 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1641 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1642 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1643 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1644 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1645 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1646 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1647 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1648 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1649 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1650 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1651 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1652 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1654 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1655 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1656 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1657 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1658 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1659 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1660 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1661 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1662 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1663 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1665 (org-defkey org-agenda-mode-map
1666 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1667 (org-defkey org-agenda-mode-map
1668 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1669 (when org-agenda-mouse-1-follows-link
1670 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1671 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1676 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1677 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1678 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1679 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1682 ["Day View" org-agenda-day-view
1683 :active (org-agenda-check-type nil 'agenda)
1684 :style radio :selected (equal org-agenda-ndays 1)
1685 :keys "v d (or just d)"]
1686 ["Week View" org-agenda-week-view
1687 :active (org-agenda-check-type nil 'agenda)
1688 :style radio :selected (equal org-agenda-ndays 7)
1689 :keys "v w (or just w)"]
1690 ["Month View" org-agenda-month-view
1691 :active (org-agenda-check-type nil 'agenda)
1692 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1694 ["Year View" org-agenda-year-view
1695 :active (org-agenda-check-type nil 'agenda)
1696 :style radio :selected (member org-agenda-ndays '(365 366))
1699 ["Include Diary" org-agenda-toggle-diary
1700 :style toggle :selected org-agenda-include-diary
1701 :active (org-agenda-check-type nil 'agenda)]
1702 ["Include Deadlines" org-agenda-toggle-deadlines
1703 :style toggle :selected org-agenda-include-deadlines
1704 :active (org-agenda-check-type nil 'agenda)]
1705 ["Use Time Grid" org-agenda-toggle-time-grid
1706 :style toggle :selected org-agenda-use-time-grid
1707 :active (org-agenda-check-type nil 'agenda)]
1709 ["Show clock report" org-agenda-clockreport-mode
1710 :style toggle :selected org-agenda-clockreport-mode
1711 :active (org-agenda-check-type nil 'agenda)]
1712 ["Show some entry text" org-agenda-entry-text-mode
1713 :style toggle :selected org-agenda-entry-text-mode
1716 ["Show Logbook entries" org-agenda-log-mode
1717 :style toggle :selected org-agenda-show-log
1718 :active (org-agenda-check-type nil 'agenda 'timeline)
1719 :keys "v l (or just l)"]
1720 ["Include archived trees" org-agenda-archives-mode
1721 :style toggle :selected org-agenda-archives-mode :active t
1723 ["Include archive files" (org-agenda-archives-mode t)
1724 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1727 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1728 ["Write view to file" org-write-agenda t]
1729 ["Rebuild buffer" org-agenda-redo t]
1730 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1732 ["Show original entry" org-agenda-show t]
1733 ["Go To (other window)" org-agenda-goto t]
1734 ["Go To (this window)" org-agenda-switch-to t]
1735 ["Follow Mode" org-agenda-follow-mode
1736 :style toggle :selected org-agenda-follow-mode :active t]
1737 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1740 ["Cycle TODO" org-agenda-todo t]
1741 ["Next TODO set" org-agenda-todo-nextset t]
1742 ["Previous TODO set" org-agenda-todo-previousset t]
1743 ["Add note" org-agenda-add-note t])
1744 ("Archive/Refile/Delete"
1745 ["Archive default" org-agenda-archive-default t]
1746 ["Archive default" org-agenda-archive-default-with-confirmation t]
1747 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1748 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1749 ["Archive subtree" org-agenda-archive t]
1751 ["Refile" org-agenda-refile t]
1753 ["Delete subtree" org-agenda-kill t])
1755 ["Mark entry" org-agenda-bulk-mark t]
1756 ["Unmark entry" org-agenda-bulk-unmark t]
1757 ["Act on all marked" org-agenda-bulk-action t]
1758 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1760 ("Tags and Properties"
1761 ["Show all Tags" org-agenda-show-tags t]
1762 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1763 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1765 ["Column View" org-columns t])
1766 ("Deadline/Schedule"
1767 ["Schedule" org-agenda-schedule t]
1768 ["Set Deadline" org-agenda-deadline t]
1770 ["Mark item" org-agenda-action :active t :keys "k m"]
1771 ["Show mark item" org-agenda-action :active t :keys "k v"]
1772 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1773 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1775 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1776 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1777 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1778 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1779 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1780 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1781 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1783 ["Clock in" org-agenda-clock-in t]
1784 ["Clock out" org-agenda-clock-out t]
1785 ["Clock cancel" org-agenda-clock-cancel t]
1786 ["Goto running clock" org-clock-goto t]
1788 ["Set Effort" org-agenda-set-effort t]
1789 ["Change clocked effort" org-clock-modify-effort-estimate
1790 (org-clock-is-active)])
1792 ["Set Priority" org-agenda-priority t]
1793 ["Increase Priority" org-agenda-priority-up t]
1794 ["Decrease Priority" org-agenda-priority-down t]
1795 ["Show Priority" org-agenda-show-priority t])
1797 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1798 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1799 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1800 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1801 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1802 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1804 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1806 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1809 ["Push Files and Views" org-mobile-push t]
1810 ["Get Captured and Flagged" org-mobile-pull t]
1811 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1812 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1814 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1816 ["Quit" org-agenda-quit t]
1817 ["Exit and Release Buffers" org-agenda-exit t]
1822 (defvar org-agenda-allow-remote-undo t
1823 "Non-nil means allow remote undo from the agenda buffer.")
1824 (defvar org-agenda-undo-list nil
1825 "List of undoable operations in the agenda since last refresh.")
1826 (defvar org-agenda-undo-has-started-in nil
1827 "Buffers that have already seen `undo-start' in the current undo sequence.")
1828 (defvar org-agenda-pending-undo-list nil
1829 "In a series of undo commands, this is the list of remaining undo items.")
1832 (defun org-agenda-undo ()
1833 "Undo a remote editing step in the agenda.
1834 This undoes changes both in the agenda buffer and in the remote buffer
1835 that have been changed along."
1837 (or org-agenda-allow-remote-undo
1838 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1839 (if (not (eq this-command last-command))
1840 (setq org-agenda-undo-has-started-in nil
1841 org-agenda-pending-undo-list org-agenda-undo-list))
1842 (if (not org-agenda-pending-undo-list)
1843 (error "No further undo information"))
1844 (let* ((entry (pop org-agenda-pending-undo-list))
1845 buf line cmd rembuf)
1846 (setq cmd (pop entry) line (pop entry))
1847 (setq rembuf (nth 2 entry))
1848 (org-with-remote-undo rembuf
1849 (while (bufferp (setq buf (pop entry)))
1851 (with-current-buffer buf
1852 (let ((last-undo-buffer buf)
1853 (inhibit-read-only t))
1854 (unless (memq buf org-agenda-undo-has-started-in)
1855 (push buf org-agenda-undo-has-started-in)
1856 (make-local-variable 'pending-undo-list)
1858 (while (and pending-undo-list
1859 (listp pending-undo-list)
1860 (not (car pending-undo-list)))
1861 (pop pending-undo-list))
1863 (org-goto-line line)
1864 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1866 (defun org-verify-change-for-undo (l1 l2)
1867 "Verify that a real change occurred between the undo lists L1 and L2."
1868 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1869 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1874 (defvar org-agenda-restrict nil)
1875 (defvar org-agenda-restrict-begin (make-marker))
1876 (defvar org-agenda-restrict-end (make-marker))
1877 (defvar org-agenda-last-dispatch-buffer nil)
1878 (defvar org-agenda-overriding-restriction nil)
1881 (defun org-agenda (&optional arg keys restriction)
1882 "Dispatch agenda commands to collect entries to the agenda buffer.
1883 Prompts for a command to execute. Any prefix arg will be passed
1884 on to the selected command. The default selections are:
1886 a Call `org-agenda-list' to display the agenda for current day or week.
1887 t Call `org-todo-list' to display the global todo list.
1888 T Call `org-todo-list' to display the global todo list, select only
1889 entries with a specific TODO keyword (the user gets a prompt).
1890 m Call `org-tags-view' to display headlines with tags matching
1891 a condition (the user is prompted for the condition).
1892 M Like `m', but select only TODO entries, no ordinary headlines.
1893 L Create a timeline for the current buffer.
1894 e Export views to associated files.
1895 s Search entries for keywords.
1896 / Multi occur across all agenda files and also files listed
1897 in `org-agenda-text-search-extra-files'.
1898 < Restrict agenda commands to buffer, subtree, or region.
1899 Press several times to get the desired effect.
1900 > Remove a previous restriction.
1901 # List \"stuck\" projects.
1902 ! Configure what \"stuck\" means.
1903 C Configure custom agenda commands.
1905 More commands can be added by configuring the variable
1906 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1907 searches can be pre-defined in this way.
1909 If the current buffer is in Org-mode and visiting a file, you can also
1910 first press `<' once to indicate that the agenda should be temporarily
1911 \(until the next use of \\[org-agenda]) restricted to the current file.
1912 Pressing `<' twice means to restrict to the current subtree or region
1916 (let* ((prefix-descriptions nil)
1917 (org-agenda-window-setup (if (equal (buffer-name)
1918 org-agenda-buffer-name)
1920 org-agenda-window-setup))
1921 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1922 (org-agenda-custom-commands
1923 ;; normalize different versions
1927 (cond ((stringp (cdr x))
1928 (push x prefix-descriptions)
1930 ((stringp (nth 1 x)) x)
1931 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1932 (t (cons (car x) (cons "" (cdr x))))))
1933 org-agenda-custom-commands)))
1934 (buf (current-buffer))
1935 (bfn (buffer-file-name (buffer-base-buffer)))
1936 entry key type match lprops ans)
1937 ;; Turn off restriction unless there is an overriding one,
1938 (unless org-agenda-overriding-restriction
1939 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
1940 ;; There is a request to keep the file list in place
1941 (put 'org-agenda-files 'org-restrict nil))
1942 (setq org-agenda-restrict nil)
1943 (move-marker org-agenda-restrict-begin nil)
1944 (move-marker org-agenda-restrict-end nil))
1945 ;; Delete old local properties
1946 (put 'org-agenda-redo-command 'org-lprops nil)
1947 ;; Remember where this call originated
1948 (setq org-agenda-last-dispatch-buffer (current-buffer))
1950 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1952 restriction (cdr ans)))
1953 ;; Establish the restriction, if any
1954 (when (and (not org-agenda-overriding-restriction) restriction)
1955 (put 'org-agenda-files 'org-restrict (list bfn))
1957 ((eq restriction 'region)
1958 (setq org-agenda-restrict t)
1959 (move-marker org-agenda-restrict-begin (region-beginning))
1960 (move-marker org-agenda-restrict-end (region-end)))
1961 ((eq restriction 'subtree)
1963 (setq org-agenda-restrict t)
1964 (org-back-to-heading t)
1965 (move-marker org-agenda-restrict-begin (point))
1966 (move-marker org-agenda-restrict-end
1967 (progn (org-end-of-subtree t)))))))
1969 ;; For example the todo list should not need it (but does...)
1971 ((setq entry (assoc keys org-agenda-custom-commands))
1972 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1974 (setq type (nth 2 entry) match (eval (nth 3 entry))
1975 lprops (nth 4 entry))
1976 (put 'org-agenda-redo-command 'org-lprops lprops)
1979 (org-let lprops '(org-agenda-list current-prefix-arg)))
1981 (org-let lprops '(org-todo-list current-prefix-arg)))
1983 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1985 (org-let lprops '(org-agenda-list-stuck-projects
1986 current-prefix-arg)))
1988 (org-let lprops '(org-tags-view current-prefix-arg match)))
1989 ((eq type 'tags-todo)
1990 (org-let lprops '(org-tags-view '(4) match)))
1992 (org-let lprops '(org-todo-list match)))
1993 ((eq type 'tags-tree)
1994 (org-check-for-org-mode)
1995 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1996 ((eq type 'todo-tree)
1997 (org-check-for-org-mode)
1999 '(org-occur (concat "^" outline-regexp "[ \t]*"
2000 (regexp-quote match) "\\>"))))
2001 ((eq type 'occur-tree)
2002 (org-check-for-org-mode)
2003 (org-let lprops '(org-occur match)))
2005 (org-let lprops '(funcall type match)))
2007 (org-let lprops '(funcall type match)))
2008 (t (error "Invalid custom agenda command type %s" type))))
2009 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2011 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2012 (customize-variable 'org-agenda-custom-commands))
2013 ((equal keys "a") (call-interactively 'org-agenda-list))
2014 ((equal keys "s") (call-interactively 'org-search-view))
2015 ((equal keys "t") (call-interactively 'org-todo-list))
2016 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2017 ((equal keys "m") (call-interactively 'org-tags-view))
2018 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2019 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2020 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2024 (unless (current-message)
2025 (let* ((m (org-agenda-get-any-marker))
2026 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2029 "FLAGGING-NOTE ([?] for more info): "
2031 (replace-regexp-in-string
2033 (copy-sequence note))
2034 nil 'face 'org-warning)))))))
2037 (unless (org-mode-p)
2038 (error "This is not an Org-mode file"))
2040 (put 'org-agenda-files 'org-restrict (list bfn))
2041 (org-call-with-arg 'org-timeline arg)))
2042 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2043 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2044 ((equal keys "!") (customize-variable 'org-stuck-projects))
2045 (t (error "Invalid agenda key"))))))
2047 (defun org-agenda-normalize-custom-commands (cmds)
2051 (cond ((stringp (cdr x)) nil)
2052 ((stringp (nth 1 x)) x)
2053 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2054 (t (cons (car x) (cons "" (cdr x))))))
2057 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2058 "The user interface for selecting an agenda command."
2060 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2061 (restrict-ok (and bfn (org-mode-p)))
2062 (region-p (org-region-active-p))
2063 (custom org-agenda-custom-commands)
2065 restriction second-time
2066 c entry key type match prefixes rmheader header-end custom1 desc)
2067 (save-window-excursion
2068 (delete-other-windows)
2069 (org-switch-to-buffer-other-window " *Agenda Commands*")
2071 (insert (eval-when-compile
2074 Press key for an agenda command: < Buffer, subtree/region restriction
2075 -------------------------------- > Remove restriction
2076 a Agenda for current week or day e Export agenda views
2077 t List of all TODO entries T Entries with special TODO kwd
2078 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2079 L Timeline for current buffer # List stuck projects (!=configure)
2080 s Search for keywords C Configure custom agenda commands
2081 / Multi-occur ? Find :FLAGGED: entries
2084 (while (string-match
2085 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2087 (setq start (match-end 0))
2088 (add-text-properties (match-beginning 2) (match-end 2)
2089 '(face bold) header))
2091 (setq header-end (move-marker (make-marker) (point)))
2093 (setq custom1 custom)
2094 (when (eq rmheader t)
2096 (re-search-forward ":" nil t)
2097 (delete-region (match-end 0) (point-at-eol))
2100 (delete-region (match-end 0) (point-at-eol))
2101 (move-marker header-end (match-end 0)))
2102 (goto-char header-end)
2103 (delete-region (point) (point-max))
2104 (while (setq entry (pop custom1))
2105 (setq key (car entry) desc (nth 1 entry)
2107 match (nth 3 entry))
2108 (if (> (length key) 1)
2109 (add-to-list 'prefixes (string-to-char key))
2113 (org-add-props (copy-sequence key)
2116 ((string-match "\\S-" desc) desc)
2117 ((eq type 'agenda) "Agenda for current week or day")
2118 ((eq type 'alltodo) "List of all TODO entries")
2119 ((eq type 'search) "Word search")
2120 ((eq type 'stuck) "List of stuck projects")
2121 ((eq type 'todo) "TODO keyword")
2122 ((eq type 'tags) "Tags query")
2123 ((eq type 'tags-todo) "Tags (TODO)")
2124 ((eq type 'tags-tree) "Tags tree")
2125 ((eq type 'todo-tree) "TODO kwd tree")
2126 ((eq type 'occur-tree) "Occur tree")
2127 ((functionp type) (if (symbolp type)
2129 "Lambda expression"))
2133 (setq match (copy-sequence match))
2134 (org-add-props match nil 'face 'org-warning))
2136 (format "set of %d commands" (length match)))
2142 (org-add-props (char-to-string x)
2144 (or (cdr (assoc (concat selstring (char-to-string x))
2145 prefix-descriptions))
2148 (goto-char (point-min))
2150 (if (not (pos-visible-in-window-p (point-max)))
2151 (org-fit-window-to-buffer))
2152 (setq second-time t)
2153 (org-fit-window-to-buffer))
2154 (message "Press key for agenda command%s:"
2155 (if (or restrict-ok org-agenda-overriding-restriction)
2156 (if org-agenda-overriding-restriction
2157 " (restriction lock active)"
2159 (format " (restricted to %s)" restriction)
2162 (setq c (read-char-exclusive))
2165 ((assoc (char-to-string c) custom)
2166 (setq selstring (concat selstring (char-to-string c)))
2167 (throw 'exit (cons selstring restriction)))
2169 (setq selstring (concat selstring (char-to-string c))
2171 rmheader (or rmheader t)
2172 custom (delq nil (mapcar
2174 (if (or (= (length (car x)) 1)
2175 (/= (string-to-char (car x)) c))
2177 (cons (substring (car x) 1) (cdr x))))
2179 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2180 (message "Restriction is only possible in Org-mode buffers")
2183 (org-agenda-remove-restriction-lock 'noupdate)
2184 (setq restriction 'buffer))
2186 (org-agenda-remove-restriction-lock 'noupdate)
2187 (setq restriction (if region-p 'region 'subtree)))
2189 (org-agenda-remove-restriction-lock 'noupdate)
2192 ((eq restriction 'buffer)
2193 (if region-p 'region 'subtree))
2194 ((memq restriction '(subtree region))
2198 (org-agenda-remove-restriction-lock 'noupdate)
2199 (setq restriction nil))
2200 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2201 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2202 ((and (> (length selstring) 0) (eq c ?\d))
2204 (org-agenda-get-restriction-and-command prefix-descriptions))
2206 ((equal c ?q) (error "Abort"))
2207 (t (error "Invalid key %c" c))))))))
2209 (defun org-run-agenda-series (name series)
2210 (org-let (nth 1 series) '(org-prepare-agenda name))
2211 (let* ((org-agenda-multi t)
2212 (redo (list 'org-run-agenda-series name (list 'quote series)))
2214 (gprops (nth 1 series))
2215 match ;; The byte compiler incorrectly complains about this. Keep it!
2217 (while (setq cmd (pop cmds))
2218 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2221 (org-let2 gprops lprops
2222 '(call-interactively 'org-agenda-list)))
2224 (org-let2 gprops lprops
2225 '(call-interactively 'org-todo-list)))
2227 (org-let2 gprops lprops
2228 '(org-search-view current-prefix-arg match nil)))
2230 (org-let2 gprops lprops
2231 '(call-interactively 'org-agenda-list-stuck-projects)))
2233 (org-let2 gprops lprops
2234 '(org-tags-view current-prefix-arg match)))
2235 ((eq type 'tags-todo)
2236 (org-let2 gprops lprops
2237 '(org-tags-view '(4) match)))
2239 (org-let2 gprops lprops
2240 '(org-todo-list match)))
2242 (org-let2 gprops lprops
2243 '(funcall type match)))
2244 (t (error "Invalid type in command series"))))
2246 (setq org-agenda-redo-command redo)
2247 (goto-char (point-min)))
2248 (org-fit-agenda-window)
2249 (org-let (nth 1 series) '(org-finalize-agenda)))
2252 (defmacro org-batch-agenda (cmd-key &rest parameters)
2253 "Run an agenda command in batch mode and send the result to STDOUT.
2254 If CMD-KEY is a string of length 1, it is used as a key in
2255 `org-agenda-custom-commands' and triggers this command. If it is a
2256 longer string it is used as a tags/todo match string.
2257 Paramters are alternating variable names and values that will be bound
2258 before running the agenda command."
2261 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2262 (if (> (length cmd-key) 2)
2263 (eval (list 'let (nreverse pars)
2264 (list 'org-tags-view nil cmd-key)))
2265 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2266 (set-buffer org-agenda-buffer-name)
2267 (princ (org-encode-for-stdout (buffer-string)))))
2269 ;(defun org-encode-for-stdout (string)
2270 ; (if (fboundp 'encode-coding-string)
2271 ; (encode-coding-string string buffer-file-coding-system)
2274 (defun org-encode-for-stdout (string)
2277 (defvar org-agenda-info nil)
2280 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2281 "Run an agenda command in batch mode and send the result to STDOUT.
2282 If CMD-KEY is a string of length 1, it is used as a key in
2283 `org-agenda-custom-commands' and triggers this command. If it is a
2284 longer string it is used as a tags/todo match string.
2285 Paramters are alternating variable names and values that will be bound
2286 before running the agenda command.
2288 The output gives a line for each selected agenda item. Each
2289 item is a list of comma-separated values, like this:
2291 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2293 category The category of the item
2294 head The headline, without TODO kwd, TAGS and PRIORITY
2295 type The type of the agenda entry, can be
2296 todo selected in TODO match
2297 tagsmatch selected in tags match
2298 diary imported from diary
2299 deadline a deadline on given date
2300 scheduled scheduled on given date
2301 timestamp entry has timestamp on given date
2302 closed entry was closed on given date
2303 upcoming-deadline warning about deadline
2304 past-scheduled forwarded scheduled item
2305 block entry has date block including g. date
2306 todo The todo keyword, if any
2307 tags All tags including inherited ones, separated by colons
2308 date The relevant date, like 2007-2-14
2309 time The time, like 15:00-16:50
2310 extra Sting with extra planning info
2311 priority-l The priority letter if any was given
2312 priority-n The computed numerical priority
2313 agenda-day The day in the agenda where this is listed"
2317 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2318 (push (list 'org-agenda-remove-tags t) pars)
2319 (if (> (length cmd-key) 2)
2320 (eval (list 'let (nreverse pars)
2321 (list 'org-tags-view nil cmd-key)))
2322 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2323 (set-buffer org-agenda-buffer-name)
2324 (let* ((lines (org-split-string (buffer-string) "\n"))
2326 (while (setq line (pop lines))
2328 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2329 (setq org-agenda-info
2330 (org-fix-agenda-info (text-properties-at 0 line)))
2332 (org-encode-for-stdout
2333 (mapconcat 'org-agenda-export-csv-mapper
2334 '(org-category txt type todo tags date time extra
2335 priority-letter priority agenda-day)
2339 (defun org-fix-agenda-info (props)
2340 "Make sure all properties on an agenda item have a canonical form,
2341 so the export commands can easily use it."
2343 (when (setq tmp (plist-get props 'tags))
2344 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2345 (when (setq tmp (plist-get props 'date))
2346 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2347 (let ((calendar-date-display-form '(year "-" month "-" day)))
2348 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2350 (setq tmp (calendar-date-string tmp)))
2351 (setq props (plist-put props 'date tmp)))
2352 (when (setq tmp (plist-get props 'day))
2353 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2354 (let ((calendar-date-display-form '(year "-" month "-" day)))
2355 (setq tmp (calendar-date-string tmp)))
2356 (setq props (plist-put props 'day tmp))
2357 (setq props (plist-put props 'agenda-day tmp)))
2358 (when (setq tmp (plist-get props 'txt))
2359 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2360 (plist-put props 'priority-letter (match-string 1 tmp))
2361 (setq tmp (replace-match "" t t tmp)))
2362 (when (and (setq re (plist-get props 'org-todo-regexp))
2363 (setq re (concat "\\`\\.*" re " ?"))
2364 (string-match re tmp))
2365 (plist-put props 'todo (match-string 1 tmp))
2366 (setq tmp (replace-match "" t t tmp)))
2367 (plist-put props 'txt tmp)))
2370 (defun org-agenda-export-csv-mapper (prop)
2371 (let ((res (plist-get org-agenda-info prop)))
2376 (t (prin1-to-string res))))
2377 (while (string-match "," res)
2378 (setq res (replace-match ";" t t res)))
2383 (defun org-store-agenda-views (&rest parameters)
2385 (eval (list 'org-batch-store-agenda-views)))
2387 ;; FIXME, why is this a macro?????
2389 (defmacro org-batch-store-agenda-views (&rest parameters)
2390 "Run all custom agenda commands that have a file argument."
2391 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2393 (dir default-directory)
2394 pars cmd thiscmdkey files opts cmd-or-set)
2396 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2397 (setq pars (reverse pars))
2398 (save-window-excursion
2400 (setq cmd (pop cmds)
2401 thiscmdkey (car cmd)
2402 cmd-or-set (nth 2 cmd)
2403 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2404 files (nth (if (listp cmd-or-set) 4 5) cmd))
2405 (if (stringp files) (setq files (list files)))
2407 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2408 (list 'org-agenda nil thiscmdkey)))
2409 (set-buffer org-agenda-buffer-name)
2411 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2412 (list 'org-write-agenda
2413 (expand-file-name (pop files) dir) nil t))))
2414 (and (get-buffer org-agenda-buffer-name)
2415 (kill-buffer org-agenda-buffer-name)))))))
2417 (defun org-agenda-mark-header-line (pos)
2418 "Mark the line at POS as an agenda structure header."
2421 (put-text-property (point-at-bol) (point-at-eol)
2422 'org-agenda-structural-header t)
2423 (when org-agenda-title-append
2424 (put-text-property (point-at-bol) (point-at-eol)
2425 'org-agenda-title-append org-agenda-title-append))))
2427 (defvar org-mobile-creating-agendas)
2428 (defun org-write-agenda (file &optional open nosettings)
2429 "Write the current buffer (an agenda view) as a file.
2430 Depending on the extension of the file name, plain text (.txt),
2431 HTML (.html or .htm) or Postscript (.ps) is produced.
2432 If the extension is .ics, run icalendar export over all files used
2433 to construct the agenda and limit the export to entries listed in the
2435 With prefix argument OPEN, open the new file immediately.
2436 If NOSETTINGS is given, do not scope the settings of
2437 `org-agenda-exporter-settings' into the export commands. This is used when
2438 the settings have already been scoped and we do not wish to overrule other,
2439 higher priority settings."
2440 (interactive "FWrite agenda to file: \nP")
2441 (if (not (file-writable-p file))
2442 (error "Cannot write agenda to file %s" file))
2444 ((string-match "\\.html?\\'" file) (require 'htmlize))
2445 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2446 (org-let (if nosettings nil org-agenda-exporter-settings)
2448 (save-window-excursion
2449 (org-agenda-mark-filtered-text)
2450 (let ((bs (copy-sequence (buffer-string))) beg)
2451 (org-agenda-unmark-filtered-text)
2454 (org-agenda-remove-marked-text 'org-filtered)
2455 (while (setq beg (text-property-any (point-min) (point-max)
2458 beg (or (next-single-property-change beg 'org-filtered)
2460 (run-hooks 'org-agenda-before-write-hook)
2462 ((org-bound-and-true-p org-mobile-creating-agendas)
2463 (org-mobile-write-agenda-for-mobile file))
2464 ((string-match "\\.html?\\'" file)
2465 (set-buffer (htmlize-buffer (current-buffer)))
2467 (when (and org-agenda-export-html-style
2468 (string-match "<style>" org-agenda-export-html-style))
2469 ;; replace <style> section with org-agenda-export-html-style
2470 (goto-char (point-min))
2471 (kill-region (- (search-forward "<style") 6)
2472 (search-forward "</style>"))
2473 (insert org-agenda-export-html-style))
2475 (kill-buffer (current-buffer))
2476 (message "HTML written to %s" file))
2477 ((string-match "\\.ps\\'" file)
2479 (flet ((ps-get-buffer-name () "Agenda View"))
2480 (ps-print-buffer-with-faces file))
2481 (message "Postscript written to %s" file))
2482 ((string-match "\\.pdf\\'" file)
2484 (flet ((ps-get-buffer-name () "Agenda View"))
2485 (ps-print-buffer-with-faces
2486 (concat (file-name-sans-extension file) ".ps")))
2487 (call-process "ps2pdf" nil nil nil
2489 (concat (file-name-sans-extension file) ".ps"))
2490 (expand-file-name file))
2491 (message "PDF written to %s" file))
2492 ((string-match "\\.ics\\'" file)
2493 (require 'org-icalendar)
2494 (let ((org-agenda-marker-table
2495 (org-create-marker-find-array
2496 (org-agenda-collect-markers)))
2497 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2498 (org-combined-agenda-icalendar-file file))
2499 (apply 'org-export-icalendar 'combine
2500 (org-agenda-files nil 'ifmode))))
2502 (let ((bs (buffer-string)))
2507 (kill-buffer (current-buffer))
2508 (message "Plain text written to %s" file))))))))
2509 (set-buffer org-agenda-buffer-name))
2510 (when open (org-open-file file)))
2512 (defvar org-agenda-filter-overlays nil)
2514 (defun org-agenda-mark-filtered-text ()
2515 "Mark all text hidden by filtering with a text property."
2516 (let ((inhibit-read-only t))
2519 (when (equal (overlay-buffer o) (current-buffer))
2521 (overlay-start o) (overlay-end o)
2523 org-agenda-filter-overlays)))
2525 (defun org-agenda-unmark-filtered-text ()
2526 "Remove the filtering text property."
2527 (let ((inhibit-read-only t))
2528 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2530 (defun org-agenda-remove-marked-text (property &optional value)
2531 "Delete all text marked with VALUE of PROPERTY.
2532 VALUE defaults to t."
2534 (setq value (or value t))
2535 (while (setq beg (text-property-any (point-min) (point-max)
2538 beg (or (next-single-property-change beg 'org-filtered)
2541 (defun org-agenda-add-entry-text ()
2542 "Add entry text to agenda lines.
2543 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2544 entry text following headings shown in the agenda.
2545 Drawers will be excluded, also the line with scheduling/deadline info."
2546 (when (and (> org-agenda-add-entry-text-maxlines 0)
2547 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2549 (goto-char (point-min))
2551 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2552 (beginning-of-line 2)
2553 (setq txt (org-agenda-get-some-entry-text
2554 m org-agenda-add-entry-text-maxlines " > "))
2556 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2558 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2560 "Extract entry text from MARKER, at most N-LINES lines.
2561 This will ignore drawers etc, just get the text.
2562 If INDENT is given, prefix every line with this string. If KEEP is
2563 given, it is a list of symbols, defining stuff that should not be
2564 removed from the entry content. Currently only `planning' is allowed here."
2565 (let (txt drawer-re kwd-time-re ind)
2567 (with-current-buffer (marker-buffer marker)
2568 (if (not (org-mode-p))
2575 (setq txt (buffer-substring
2576 (min (1+ (point)) (point-max))
2577 (progn (outline-next-heading) (point)))
2578 drawer-re org-drawer-regexp
2579 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2583 (when org-agenda-add-entry-text-descriptive-links
2584 (goto-char (point-min))
2585 (while (org-activate-bracket-links (point-max))
2586 (add-text-properties (match-beginning 0) (match-end 0)
2588 (goto-char (point-min))
2589 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2590 (set-text-properties (match-beginning 0) (match-end 0)
2592 (goto-char (point-min))
2593 (while (re-search-forward drawer-re nil t)
2596 (progn (re-search-forward
2597 "^[ \t]*:END:.*\n?" nil 'move)
2599 (unless (member 'planning keep)
2600 (goto-char (point-min))
2601 (while (re-search-forward kwd-time-re nil t)
2602 (replace-match "")))
2603 (goto-char (point-min))
2604 (when org-agenda-entry-text-exclude-regexps
2605 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2606 (while (setq re (pop re-list))
2607 (goto-char (point-min))
2608 (while (re-search-forward re nil t)
2609 (replace-match "")))))
2610 (goto-char (point-max))
2611 (skip-chars-backward " \t\n")
2612 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2614 ;; find and remove min common indentation
2615 (goto-char (point-min))
2616 (untabify (point-min) (point-max))
2617 (setq ind (org-get-indentation))
2619 (unless (looking-at "[ \t]*$")
2620 (setq ind (min ind (org-get-indentation))))
2621 (beginning-of-line 2))
2622 (goto-char (point-min))
2624 (unless (looking-at "[ \t]*$")
2625 (move-to-column ind)
2626 (delete-region (point-at-bol) (point)))
2627 (beginning-of-line 2))
2629 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2631 (goto-char (point-min))
2633 (while (and (not (eobp)) (re-search-forward "^" nil t))
2634 (replace-match indent t t)))
2635 (goto-char (point-min))
2636 (while (looking-at "[ \t]*\n") (replace-match ""))
2637 (goto-char (point-max))
2638 (when (> (org-current-line)
2640 (org-goto-line (1+ n-lines))
2642 (setq txt (buffer-substring (point-min) (point)))))))))
2645 (defun org-agenda-collect-markers ()
2646 "Collect the markers pointing to entries in the agenda buffer."
2649 (goto-char (point-min))
2651 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2652 (org-get-at-bol 'org-marker)))
2654 (beginning-of-line 2)))
2655 (nreverse markers)))
2657 (defun org-create-marker-find-array (marker-list)
2658 "Create a alist of files names with all marker positions in that file."
2660 (while (setq m (pop marker-list))
2661 (setq p (marker-position m)
2662 f (buffer-file-name (or (buffer-base-buffer
2664 (marker-buffer m))))
2665 (if (setq a (assoc f tbl))
2666 (push (marker-position m) (cdr a))
2667 (push (list f p) tbl)))
2668 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2671 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2672 (defun org-check-agenda-marker-table ()
2673 "Check of the current entry is on the marker list."
2674 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2676 (and (setq a (assoc file org-agenda-marker-table))
2679 (org-back-to-heading t)
2680 (member (point) (cdr a)))))))
2682 (defun org-check-for-org-mode ()
2683 "Make sure current buffer is in org-mode. Error if not."
2685 (error "Cannot execute org-mode agenda command on buffer in %s"
2688 (defun org-fit-agenda-window ()
2689 "Fit the window to the buffer size."
2690 (and (memq org-agenda-window-setup '(reorganize-frame))
2691 (fboundp 'fit-window-to-buffer)
2692 (org-fit-window-to-buffer
2694 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2695 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2697 ;;; Agenda prepare and finalize
2699 (defvar org-agenda-multi nil) ; dynamically scoped
2700 (defvar org-agenda-buffer-name "*Org Agenda*")
2701 (defvar org-pre-agenda-window-conf nil)
2702 (defvar org-agenda-columns-active nil)
2703 (defvar org-agenda-name nil)
2704 (defvar org-agenda-filter nil)
2705 (defvar org-agenda-filter-preset nil
2706 "A preset of the tags filter used for secondary agenda filtering.
2707 This must be a list of strings, each string must be a single tag preceeded
2709 This variable should not be set directly, but agenda custom commands can
2710 bind it in the options section.")
2712 (defun org-prepare-agenda (&optional name)
2713 (setq org-todo-keywords-for-agenda nil)
2714 (setq org-done-keywords-for-agenda nil)
2715 (setq org-drawers-for-agenda nil)
2716 (setq org-agenda-filter nil)
2717 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2718 (if org-agenda-multi
2720 (setq buffer-read-only nil)
2721 (goto-char (point-max))
2722 (unless (or (bobp) org-agenda-compact-blocks)
2724 (if (stringp org-agenda-block-separator)
2725 org-agenda-block-separator
2726 (make-string (window-width) org-agenda-block-separator))
2728 (narrow-to-region (point) (point-max)))
2729 (org-agenda-reset-markers)
2730 (setq org-agenda-contributing-files nil)
2731 (setq org-agenda-columns-active nil)
2732 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2733 (setq org-todo-keywords-for-agenda
2734 (org-uniquify org-todo-keywords-for-agenda))
2735 (setq org-done-keywords-for-agenda
2736 (org-uniquify org-done-keywords-for-agenda))
2737 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2738 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2739 (awin (get-buffer-window abuf)))
2741 ((equal (current-buffer) abuf) nil)
2742 (awin (select-window awin))
2743 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2744 ((equal org-agenda-window-setup 'current-window)
2745 (switch-to-buffer abuf))
2746 ((equal org-agenda-window-setup 'other-window)
2747 (org-switch-to-buffer-other-window abuf))
2748 ((equal org-agenda-window-setup 'other-frame)
2749 (switch-to-buffer-other-frame abuf))
2750 ((equal org-agenda-window-setup 'reorganize-frame)
2751 (delete-other-windows)
2752 (org-switch-to-buffer-other-window abuf))))
2753 (setq buffer-read-only nil)
2754 (let ((inhibit-read-only t)) (erase-buffer))
2756 (and name (not org-agenda-name)
2757 (org-set-local 'org-agenda-name name)))
2758 (setq buffer-read-only nil))
2760 (defun org-finalize-agenda ()
2761 "Finishing touch for the agenda buffer, called just before displaying it."
2762 (unless org-agenda-multi
2764 (let ((inhibit-read-only t))
2765 (goto-char (point-min))
2766 (while (org-activate-bracket-links (point-max))
2767 (add-text-properties (match-beginning 0) (match-end 0)
2769 (org-agenda-align-tags)
2770 (unless org-agenda-with-colors
2771 (remove-text-properties (point-min) (point-max) '(face nil))))
2772 (if (and (boundp 'org-agenda-overriding-columns-format)
2773 org-agenda-overriding-columns-format)
2774 (org-set-local 'org-agenda-overriding-columns-format
2775 org-agenda-overriding-columns-format))
2776 (if (and (boundp 'org-agenda-view-columns-initially)
2777 org-agenda-view-columns-initially)
2778 (org-agenda-columns))
2779 (when org-agenda-fontify-priorities
2780 (org-agenda-fontify-priorities))
2781 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2782 (org-agenda-dim-blocked-tasks))
2783 (org-agenda-mark-clocking-task)
2784 (when org-agenda-entry-text-mode
2785 (org-agenda-entry-text-hide)
2786 (org-agenda-entry-text-show))
2787 (if (functionp 'org-habit-insert-consistency-graphs)
2788 (org-habit-insert-consistency-graphs))
2789 (run-hooks 'org-finalize-agenda-hook)
2790 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2791 (when (get 'org-agenda-filter :preset-filter)
2792 (org-agenda-filter-apply org-agenda-filter))
2795 (defun org-agenda-mark-clocking-task ()
2796 "Mark the current clock entry in the agenda if it is present."
2798 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
2799 (delete-overlay o)))
2800 (overlays-in (point-min) (point-max)))
2801 (when (marker-buffer org-clock-hd-marker)
2803 (goto-char (point-min))
2805 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2807 (when (equal (org-get-at-bol 'org-hd-marker)
2808 org-clock-hd-marker)
2809 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
2810 (overlay-put ov 'type 'org-agenda-clocking)
2811 (overlay-put ov 'face 'org-agenda-clocking)
2812 (overlay-put ov 'help-echo
2813 "The clock is running in this item")))))))
2815 (defun org-agenda-fontify-priorities ()
2816 "Make highest priority lines bold, and lowest italic."
2818 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
2819 (delete-overlay o)))
2820 (overlays-in (point-min) (point-max)))
2822 (let ((inhibit-read-only t)
2824 (goto-char (point-min))
2825 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2826 (setq h (or (get-char-property (point) 'org-highest-priority)
2827 org-highest-priority)
2828 l (or (get-char-property (point) 'org-lowest-priority)
2829 org-lowest-priority)
2830 p (string-to-char (match-string 1))
2831 b (match-beginning 0)
2832 e (if (eq org-agenda-fontify-priorities 'cookies)
2835 ov (make-overlay b e))
2838 (cond ((org-face-from-face-or-color
2840 (cdr (assoc p org-priority-faces))))
2841 ((and (listp org-agenda-fontify-priorities)
2842 (org-face-from-face-or-color
2844 (cdr (assoc p org-agenda-fontify-priorities)))))
2845 ((equal p l) 'italic)
2846 ((equal p h) 'bold)))
2847 (overlay-put ov 'org-type 'org-priority)))))
2849 (defun org-agenda-dim-blocked-tasks ()
2850 "Dim currently blocked TODO's in the agenda display."
2851 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
2852 (delete-overlay o)))
2853 (overlays-in (point-min) (point-max)))
2855 (let ((inhibit-read-only t)
2856 (org-depend-tag-blocked nil)
2857 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2858 org-blocked-by-checkboxes
2859 invis1 b e p ov h l)
2860 (goto-char (point-min))
2861 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2862 (and pos (goto-char (1+ pos))))
2863 (setq org-blocked-by-checkboxes nil invis1 invis)
2864 (let ((marker (org-get-at-bol 'org-hd-marker)))
2866 (not (with-current-buffer (marker-buffer marker)
2869 (if (org-entry-get nil "NOBLOCKING")
2870 t ;; Never block this entry
2871 (run-hook-with-args-until-failure
2873 (list :type 'todo-state-change
2877 (if org-blocked-by-checkboxes (setq invis1 nil))
2879 (max (point-min) (1- (point-at-bol)))
2882 ov (make-overlay b e))
2884 (overlay-put ov 'invisible t)
2885 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2886 (overlay-put ov 'org-type 'org-blocked-todo)))))))
2888 (defvar org-agenda-skip-function nil
2889 "Function to be called at each match during agenda construction.
2890 If this function returns nil, the current match should not be skipped.
2891 Otherwise, the function must return a position from where the search
2892 should be continued.
2893 This may also be a Lisp form, it will be evaluated.
2894 Never set this variable using `setq' or so, because then it will apply
2895 to all future agenda commands. Instead, bind it with `let' to scope
2896 it dynamically into the agenda-constructing command. A good way to set
2897 it is through options in org-agenda-custom-commands.")
2899 (defun org-agenda-skip ()
2900 "Throw to `:skip' in places that should be skipped.
2901 Also moves point to the end of the skipped region, so that search can
2902 continue from there."
2903 (let ((p (point-at-bol)) to fp)
2904 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2905 (get-text-property p :org-archived)
2906 (org-end-of-subtree t)
2908 (and org-agenda-skip-comment-trees
2909 (get-text-property p :org-comment)
2910 (org-end-of-subtree t)
2912 (if (equal (char-after p) ?#) (throw :skip t))
2913 (when (and (or (setq fp (functionp org-agenda-skip-function))
2914 (consp org-agenda-skip-function))
2915 (setq to (save-excursion
2918 (funcall org-agenda-skip-function)
2919 (eval org-agenda-skip-function))))))
2923 (defvar org-agenda-markers nil
2924 "List of all currently active markers created by `org-agenda'.")
2925 (defvar org-agenda-last-marker-time (org-float-time)
2926 "Creation time of the last agenda marker.")
2928 (defun org-agenda-new-marker (&optional pos)
2929 "Return a new agenda marker.
2930 Org-mode keeps a list of these markers and resets them when they are
2932 (let ((m (copy-marker (or pos (point)))))
2933 (setq org-agenda-last-marker-time (org-float-time))
2934 (push m org-agenda-markers)
2937 (defun org-agenda-reset-markers ()
2938 "Reset markers created by `org-agenda'."
2939 (while org-agenda-markers
2940 (move-marker (pop org-agenda-markers) nil)))
2942 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2943 "Save relative positions of markers in region."
2944 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2945 org-agenda-markers))
2949 (defun org-agenda-entry-text-show-here ()
2950 "Add some text from the entry as context to the current line."
2952 (setq m (org-get-at-bol 'org-hd-marker))
2953 (unless (marker-buffer m)
2954 (error "No marker points to an entry here"))
2955 (setq txt (concat "\n" (org-no-properties
2956 (org-agenda-get-some-entry-text
2957 m org-agenda-entry-text-maxlines " > "))))
2958 (when (string-match "\\S-" txt)
2959 (setq o (make-overlay (point-at-bol) (point-at-eol)))
2960 (overlay-put o 'evaporate t)
2961 (overlay-put o 'org-overlay-type 'agenda-entry-content)
2962 (overlay-put o 'after-string txt))))
2964 (defun org-agenda-entry-text-show ()
2965 "Add entry context for all agenda lines."
2968 (goto-char (point-max))
2969 (beginning-of-line 1)
2971 (when (org-get-at-bol 'org-hd-marker)
2972 (org-agenda-entry-text-show-here))
2973 (beginning-of-line 0))))
2975 (defun org-agenda-entry-text-hide ()
2976 "Remove any shown entry context."
2979 (if (eq (overlay-get o 'org-overlay-type)
2980 'agenda-entry-content)
2981 (progn (delete-overlay o) t)))
2982 (overlays-in (point-min) (point-max)))))
2986 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2988 (defun org-timeline (&optional include-all)
2989 "Show a time-sorted view of the entries in the current org file.
2990 Only entries with a time stamp of today or later will be listed. With
2991 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2992 under the current date.
2993 If the buffer contains an active region, only check the region for
2996 (org-compile-prefix-format 'timeline)
2997 (org-set-sorting-strategy 'timeline)
2999 (dotodo include-all)
3000 (doclosed org-agenda-show-log)
3001 (entry buffer-file-name)
3002 (date (calendar-current-date))
3003 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3004 (end (if (org-region-active-p) (region-end) (point-max)))
3005 (day-numbers (org-get-all-dates beg end 'no-ranges
3006 t doclosed ; always include today
3007 org-timeline-show-empty-dates))
3008 (org-deadline-warning-days 0)
3009 (org-agenda-only-exact-dates t)
3010 (today (time-to-days (current-time)))
3013 s e rtn d emptyp wd)
3014 (setq org-agenda-redo-command
3016 (list 'org-switch-to-buffer-other-window (current-buffer))
3017 (list 'org-timeline (list 'quote include-all))))
3019 ;; Remove past dates from the list of dates.
3020 (setq day-numbers (delq nil (mapcar (lambda(x)
3021 (if (>= x today) x nil))
3023 (org-prepare-agenda (concat "Timeline "
3024 (file-name-nondirectory buffer-file-name)))
3025 (if doclosed (push :closed args))
3026 (push :timestamp args)
3027 (push :deadline args)
3028 (push :scheduled args)
3030 (if dotodo (push :todo args))
3031 (insert "Timeline of file " entry "\n")
3032 (add-text-properties (point-min) (point)
3033 (list 'face 'org-agenda-structure))
3034 (org-agenda-mark-header-line (point-min))
3035 (while (setq d (pop day-numbers))
3036 (if (and (listp d) (eq (car d) :omitted))
3039 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3040 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3041 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3042 (if (and (>= d today)
3047 (insert (make-string 79 ?-) "\n")))
3048 (setq date (calendar-gregorian-from-absolute d)
3049 wd (calendar-day-of-week date))
3051 (setq rtn (and (not emptyp)
3052 (apply 'org-agenda-get-day-entries entry
3054 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3057 (if (stringp org-agenda-format-date)
3058 (format-time-string org-agenda-format-date
3059 (org-time-from-absolute date))
3060 (funcall org-agenda-format-date date))
3062 (put-text-property s (1- (point)) 'face
3063 (if (member wd org-agenda-weekend-days)
3064 'org-agenda-date-weekend
3066 (put-text-property s (1- (point)) 'org-date-line t)
3067 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3069 (put-text-property s (1- (point)) 'org-today t))
3070 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3071 (put-text-property s (1- (point)) 'day d)))))
3072 (goto-char (point-min))
3073 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3075 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3076 (org-finalize-agenda)
3077 (setq buffer-read-only t)))
3079 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3080 "Return a list of all relevant day numbers from BEG to END buffer positions.
3081 If NO-RANGES is non-nil, include only the start and end dates of a range,
3082 not every single day in the range. If FORCE-TODAY is non-nil, make
3083 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3084 inactive time stamps (those in square brackets) are included.
3085 When EMPTY is non-nil, also include days without any entries."
3087 (if pre-re pre-re "")
3088 (if inactive org-ts-regexp-both org-ts-regexp)))
3089 dates dates1 date day day1 day2 ts1 ts2)
3091 (setq dates (list (time-to-days (current-time)))))
3094 (while (re-search-forward re end t)
3095 (setq day (time-to-days (org-time-string-to-time
3096 (substring (match-string 1) 0 10))))
3097 (or (memq day dates) (push day dates)))
3100 (while (re-search-forward org-tr-regexp end t)
3101 (setq ts1 (substring (match-string 1) 0 10)
3102 ts2 (substring (match-string 2) 0 10)
3103 day1 (time-to-days (org-time-string-to-time ts1))
3104 day2 (time-to-days (org-time-string-to-time ts2)))
3105 (while (< (setq day1 (1+ day1)) day2)
3106 (or (memq day1 dates) (push day1 dates)))))
3107 (setq dates (sort dates '<))
3109 (while (setq day (pop dates))
3110 (setq day2 (car dates))
3112 (when (and day2 empty)
3113 (if (or (eq empty t)
3114 (and (numberp empty) (<= (- day2 day) empty)))
3115 (while (< (setq day (1+ day)) day2)
3116 (push (list day) dates1))
3117 (push (cons :omitted (- day2 day)) dates1))))
3118 (setq dates (nreverse dates1)))
3121 ;;; Agenda Daily/Weekly
3123 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3124 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3125 "Custom commands can set this variable in the options section.")
3126 (defvar org-agenda-last-arguments nil
3127 "The arguments of the previous call to org-agenda")
3128 (defvar org-starting-day nil) ; local variable in the agenda buffer
3129 (defvar org-agenda-span nil) ; local variable in the agenda buffer
3130 (defvar org-include-all-loc nil) ; local variable
3132 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3133 "List of types searched for when creating the daily/weekly agenda.
3134 This variable is a list of symbols that controls the types of
3135 items that appear in the daily/weekly agenda. Allowed symbols in this
3138 :timestamp List items containing a date stamp or date range matching
3139 the selected date. This includes sexp entries in
3142 :sexp List entries resulting from plain diary-like sexps.
3144 :deadline List deadline due on that date. When the date is today,
3145 also list any deadlines past due, or due within
3146 `org-deadline-warning-days'. `:deadline' must appear before
3147 `:scheduled' if the setting of
3148 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3151 :scheduled List all items which are scheduled for the given date.
3152 The diary for *today* also contains items which were
3153 scheduled earlier and are not yet marked DONE.
3155 By default, all four types are turned on.
3157 Never set this variable globally using `setq', because then it
3158 will apply to all future agenda commands. Instead, bind it with
3159 `let' to scope it dynamically into the the agenda-constructing
3160 command. A good way to set it is through options in
3161 `org-agenda-custom-commands'. For a more flexible (though
3162 somewhat less efficient) way of determining what is included in
3163 the daily/weekly agenda, see `org-agenda-skip-function'.")
3166 (defun org-agenda-list (&optional include-all start-day ndays)
3167 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3168 The view will be for the current day or week, but from the overview buffer
3169 you will be able to go to other days/weeks.
3171 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3172 all unfinished TODO items will also be shown, before the agenda.
3173 This feature is considered obsolete, please use the TODO list or a block
3176 With a numeric prefix argument in an interactive call, the agenda will
3177 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3178 the number of days. NDAYS defaults to `org-agenda-ndays'.
3180 START-DAY defaults to TODAY, or to the most recent match for the weekday
3181 given in `org-agenda-start-on-weekday'."
3183 (if (and (integerp include-all) (> include-all 0))
3184 (setq ndays include-all include-all nil))
3185 (setq ndays (or ndays org-agenda-ndays)
3186 start-day (or start-day org-agenda-start-day))
3187 (if org-agenda-overriding-arguments
3188 (setq include-all (car org-agenda-overriding-arguments)
3189 start-day (nth 1 org-agenda-overriding-arguments)
3190 ndays (nth 2 org-agenda-overriding-arguments)))
3191 (if (stringp start-day)
3192 ;; Convert to an absolute day number
3193 (setq start-day (time-to-days (org-read-date nil t start-day))))
3194 (setq org-agenda-last-arguments (list include-all start-day ndays))
3195 (org-compile-prefix-format 'agenda)
3196 (org-set-sorting-strategy 'agenda)
3197 (let* ((org-agenda-start-on-weekday
3198 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3199 org-agenda-start-on-weekday nil))
3200 (thefiles (org-agenda-files nil 'ifmode))
3202 (today (time-to-days
3203 (time-subtract (current-time)
3204 (list 0 (* 3600 org-extend-today-until) 0))))
3205 (sd (or start-day today))
3206 (start (if (or (null org-agenda-start-on-weekday)
3207 (< org-agenda-ndays 7))
3209 (let* ((nt (calendar-day-of-week
3210 (calendar-gregorian-from-absolute sd)))
3211 (n1 org-agenda-start-on-weekday)
3213 (- sd (+ (if (< d 0) 7 0) d)))))
3214 (day-numbers (list start))
3216 (inhibit-redisplay (not debug-on-error))
3217 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3218 clocktable-start clocktable-end)
3219 (setq org-agenda-redo-command
3220 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3221 ;; Make the list of days
3222 (setq ndays (or ndays org-agenda-ndays)
3225 (push (1+ (car day-numbers)) day-numbers)
3226 (setq ndays (1- ndays)))
3227 (setq day-numbers (nreverse day-numbers))
3228 (setq clocktable-start (car day-numbers)
3229 clocktable-end (1+ (or (org-last day-numbers) 0)))
3230 (org-prepare-agenda "Day/Week")
3231 (org-set-local 'org-starting-day (car day-numbers))
3232 (org-set-local 'org-include-all-loc include-all)
3233 (org-set-local 'org-agenda-span
3234 (org-agenda-ndays-to-span nd))
3235 (when (and (or include-all org-agenda-include-all-todo)
3236 (member today day-numbers))
3237 (setq files thefiles
3239 (while (setq file (pop files))
3241 (org-check-agenda-file file)
3242 (setq date (calendar-gregorian-from-absolute today)
3243 rtn (org-agenda-get-day-entries
3245 (setq rtnall (append rtnall rtn))))
3247 (insert "All currently open TODO items:\n")
3248 (add-text-properties (point-min) (1- (point))
3249 (list 'face 'org-agenda-structure
3250 'short-heading "All TODO items"))
3251 (org-agenda-mark-header-line (point-min))
3252 (insert (org-finalize-agenda-entries rtnall) "\n")))
3253 (unless org-agenda-compact-blocks
3254 (let* ((d1 (car day-numbers))
3255 (d2 (org-last day-numbers))
3256 (w1 (org-days-to-iso-week d1))
3257 (w2 (org-days-to-iso-week d2)))
3259 (if org-agenda-overriding-header
3260 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3261 nil 'face 'org-agenda-structure) "\n")
3262 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3264 (if (< (- d2 d1) 350)
3266 (format " (W%02d)" w1)
3267 (format " (W%02d-W%02d)" w1 w2))
3270 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3272 (org-agenda-mark-header-line s))
3273 (while (setq d (pop day-numbers))
3274 (setq date (calendar-gregorian-from-absolute d)
3275 wd (calendar-day-of-week date)
3277 (if (or (setq todayp (= d today))
3278 (and (not start-pos) (= d sd)))
3279 (setq start-pos (point))
3280 (if (and start-pos (not end-pos))
3281 (setq end-pos (point))))
3282 (setq files thefiles
3284 (while (setq file (pop files))
3286 (org-check-agenda-file file)
3287 (let ((org-agenda-entry-types org-agenda-entry-types))
3288 (unless org-agenda-include-deadlines
3289 (setq org-agenda-entry-types
3290 (delq :deadline org-agenda-entry-types)))
3292 ((eq org-agenda-show-log 'only)
3293 (setq rtn (org-agenda-get-day-entries
3294 file date :closed)))
3295 (org-agenda-show-log
3296 (setq rtn (apply 'org-agenda-get-day-entries
3298 (append '(:closed) org-agenda-entry-types))))
3300 (setq rtn (apply 'org-agenda-get-day-entries
3302 org-agenda-entry-types)))))
3303 (setq rtnall (append rtnall rtn))))
3304 (if org-agenda-include-diary
3305 (let ((org-agenda-search-headline-for-time t))
3306 (require 'diary-lib)
3307 (setq rtn (org-get-entries-from-diary date))
3308 (setq rtnall (append rtnall rtn))))
3309 (if (or rtnall org-agenda-show-all-dates)
3311 (setq day-cnt (1+ day-cnt))
3313 (if (stringp org-agenda-format-date)
3314 (format-time-string org-agenda-format-date
3315 (org-time-from-absolute date))
3316 (funcall org-agenda-format-date date))
3318 (put-text-property s (1- (point)) 'face
3319 (if (member wd org-agenda-weekend-days)
3320 'org-agenda-date-weekend
3322 (put-text-property s (1- (point)) 'org-date-line t)
3323 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3324 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3326 (put-text-property s (1- (point)) 'org-today t)
3327 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3329 (org-finalize-agenda-entries
3330 (org-agenda-add-time-grid-maybe
3333 (put-text-property s (1- (point)) 'day d)
3334 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3335 (when (and org-agenda-clockreport-mode clocktable-start)
3336 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3337 ;; the above line is to ensure the restricted range!
3338 (p org-agenda-clockreport-parameter-plist)
3340 (setq p (org-plist-delete p :block))
3341 (setq p (plist-put p :tstart clocktable-start))
3342 (setq p (plist-put p :tend clocktable-end))
3343 (setq p (plist-put p :scope 'agenda))
3344 (setq tbl (apply 'org-get-clocktable p))
3346 (goto-char (point-min))
3347 (or org-agenda-multi (org-fit-agenda-window))
3348 (unless (and (pos-visible-in-window-p (point-min))
3349 (pos-visible-in-window-p (point-max)))
3350 (goto-char (1- (point-max)))
3352 (if (not (pos-visible-in-window-p (or start-pos 1)))
3354 (goto-char (or start-pos 1))
3356 (goto-char (or start-pos 1))
3357 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3358 (org-finalize-agenda)
3359 (setq buffer-read-only t)
3362 (defun org-agenda-ndays-to-span (n)
3363 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3365 ;;; Agenda word search
3367 (defvar org-agenda-search-history nil)
3368 (defvar org-todo-only nil)
3370 (defvar org-search-syntax-table nil
3371 "Special syntax table for org-mode search.
3372 In this table, we have single quotes not as word constituents, to
3373 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3375 (defun org-search-syntax-table ()
3376 (unless org-search-syntax-table
3377 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3378 (modify-syntax-entry ?' "." org-search-syntax-table)
3379 (modify-syntax-entry ?` "." org-search-syntax-table))
3380 org-search-syntax-table)
3382 (defvar org-agenda-last-search-view-search-was-boolean nil)
3385 (defun org-search-view (&optional todo-only string edit-at)
3386 "Show all entries that contain a phrase or words or regular expressions.
3388 With optional prefix argument TODO-ONLY, only consider entries that are
3389 TODO entries. The argument STRING can be used to pass a default search
3390 string into this function. If EDIT-AT is non-nil, it means that the
3391 user should get a chance to edit this string, with cursor at position
3394 The search string can be viewed either as a phrase that should be found as
3395 is, or it can be broken into a number of snippets, each of which must match
3396 in a Boolean way to select an entry. The default depends on the variable
3397 `org-agenda-search-view-always-boolean'.
3398 Even if this is turned off (the default) you can always switch to
3399 Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
3401 The default is a direct search of the whole phrase, where each space in
3402 the search string can expand to an arbitrary amount of whitespace,
3405 If using a Boolean search, the search string is split on whitespace and
3406 each snippet is searched separately, with logical AND to select an entry.
3407 Words prefixed with a minus must *not* occur in the entry. Words without
3408 a prefix or prefixed with a plus must occur in the entry. Matching is
3409 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3410 match whole words, not parts of a word) if
3411 `org-agenda-search-view-force-full-words' is set (default is nil).
3413 Boolean search snippets enclosed by curly braces are interpreted as
3414 regular expressions that must or (when preceeded with \"-\") must not
3415 match in the entry. Snippets enclosed into double quotes will be taken
3416 as a whole, to incude whitespace.
3418 - If the search string starts with an asterisk, search only in headlines.
3419 - If (possibly after the leading star) the search string starts with an
3420 exclamation mark, this also means to look at TODO entries only, an effect
3421 that can also be achieved with a prefix argument.
3422 - If (possibly after star and exclamation mark) the search string starts
3423 with a colon, this will mean that the (non-regexp) snippets of the
3424 Boolean search must match as full words.
3426 This command searches the agenda files, and in addition the files listed
3427 in `org-agenda-text-search-extra-files'."
3429 (org-compile-prefix-format 'search)
3430 (org-set-sorting-strategy 'search)
3431 (org-prepare-agenda "SEARCH")
3432 (let* ((props (list 'face nil
3433 'done-face 'org-agenda-done
3434 'org-not-done-regexp org-not-done-regexp
3435 'org-todo-regexp org-todo-regexp
3436 'org-complex-heading-regexp org-complex-heading-regexp
3437 'mouse-face 'highlight
3438 'help-echo (format "mouse-2 or RET jump to location")))
3439 (full-words org-agenda-search-view-force-full-words)
3440 regexp rtn rtnall files file pos
3441 marker category tags c neg re boolean
3442 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3443 (unless (and (not edit-at)
3445 (string-match "\\S-" string))
3446 (setq string (read-string
3447 (if org-agenda-search-view-always-boolean
3448 "[+-]Word/{Regexp} ...: "
3449 "Phrase, or [+-]Word/{Regexp} ...: ")
3451 ((integerp edit-at) (cons string edit-at))
3453 'org-agenda-search-history)))
3454 (org-set-local 'org-todo-only todo-only)
3455 (setq org-agenda-redo-command
3456 (list 'org-search-view (if todo-only t nil) string
3457 '(if current-prefix-arg 1 nil)))
3458 (setq org-agenda-query-string string)
3460 (if (equal (string-to-char string) ?*)
3462 words (substring string 1))
3463 (setq words string))
3464 (when (equal (string-to-char words) ?!)
3466 words (substring words 1)))
3467 (when (equal (string-to-char words) ?:)
3469 words (substring words 1)))
3470 (if (or org-agenda-search-view-always-boolean
3471 (member (string-to-char words) '(?- ?+ ?\{)))
3473 (setq words (org-split-string words))
3474 (setq org-agenda-last-search-view-search-was-boolean boolean)
3477 (while (setq w (pop words))
3478 (if (or (equal (substring w 0 1) "\"")
3479 (and (> (length w) 1)
3480 (member (substring w 0 1) '("+" "-"))
3481 (equal (substring w 1 2) "\"")))
3482 (while (and words (not (equal (substring w -1) "\"")))
3483 (setq w (concat w " " (pop words)))))
3484 (and (string-match "\\`\\([-+]?\\)\"" w)
3485 (setq w (replace-match "\\1" nil nil w)))
3486 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3488 (setq words (nreverse wds))))
3491 (setq c (string-to-char w))
3493 (setq neg t w (substring w 1))
3495 (setq neg nil w (substring w 1))
3497 (if (string-match "\\`{.*}\\'" w)
3498 (setq re (substring w 1 -1))
3500 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3501 (setq re (regexp-quote (downcase w)))))
3502 (if neg (push re regexps-) (push re regexps+)))
3504 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3506 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3508 (setq regexp (concat "^" org-outline-regexp))
3509 (setq regexp (pop regexps+))
3510 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3512 (setq files (org-agenda-files nil 'ifmode))
3513 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3514 (pop org-agenda-text-search-extra-files)
3515 (setq files (org-add-archive-files files)))
3516 (setq files (append files org-agenda-text-search-extra-files)
3518 (while (setq file (pop files))
3521 (org-check-agenda-file file)
3522 (setq buffer (if (file-exists-p file)
3523 (org-get-agenda-file-buffer file)
3524 (error "No such file %s" file)))
3526 ;; If file does not exist, make sure an error message is sent
3527 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3529 (with-current-buffer buffer
3530 (with-syntax-table (org-search-syntax-table)
3531 (unless (org-mode-p)
3532 (error "Agenda file %s is not in `org-mode'" file))
3533 (let ((case-fold-search t))
3536 (if org-agenda-restrict
3537 (narrow-to-region org-agenda-restrict-begin
3538 org-agenda-restrict-end)
3540 (goto-char (point-min))
3541 (unless (or (org-on-heading-p)
3542 (outline-next-heading))
3543 (throw 'nextfile t))
3544 (goto-char (max (point-min) (1- (point))))
3545 (while (re-search-forward regexp nil t)
3546 (org-back-to-heading t)
3547 (skip-chars-forward "* ")
3548 (setq beg (point-at-bol)
3550 end (progn (outline-next-heading) (point)))
3554 (setq str (buffer-substring-no-properties
3556 (if hdl-only (point-at-eol) end)))
3557 (mapc (lambda (wr) (when (string-match wr str)
3558 (goto-char (1- end))
3561 (mapc (lambda (wr) (unless (string-match wr str)
3562 (goto-char (1- end))
3565 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3569 (setq marker (org-agenda-new-marker (point))
3570 category (org-get-category)
3571 tags (org-get-tags-at (point))
3572 txt (org-format-agenda-item
3574 (buffer-substring-no-properties
3575 beg1 (point-at-eol))
3577 (org-add-props txt props
3578 'org-marker marker 'org-hd-marker marker
3579 'org-todo-regexp org-todo-regexp
3580 'org-complex-heading-regexp org-complex-heading-regexp
3581 'priority 1000 'org-category category
3584 (goto-char (1- end))))))))))
3585 (setq rtn (nreverse ee))
3586 (setq rtnall (append rtnall rtn)))
3587 (if org-agenda-overriding-header
3588 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3589 nil 'face 'org-agenda-structure) "\n")
3590 (insert "Search words: ")
3591 (add-text-properties (point-min) (1- (point))
3592 (list 'face 'org-agenda-structure))
3594 (insert string "\n")
3595 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3597 (unless org-agenda-multi
3598 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3599 (add-text-properties pos (1- (point))
3600 (list 'face 'org-agenda-structure))))
3601 (org-agenda-mark-header-line (point-min))
3603 (insert (org-finalize-agenda-entries rtnall) "\n"))
3604 (goto-char (point-min))
3605 (or org-agenda-multi (org-fit-agenda-window))
3606 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3607 (org-finalize-agenda)
3608 (setq buffer-read-only t)))
3610 ;;; Agenda TODO list
3612 (defvar org-select-this-todo-keyword nil)
3613 (defvar org-last-arg nil)
3616 (defun org-todo-list (arg)
3617 "Show all TODO entries from all agenda file in a single list.
3618 The prefix arg can be used to select a specific TODO keyword and limit
3619 the list to these. When using \\[universal-argument], you will be prompted
3620 for a keyword. A numeric prefix directly selects the Nth keyword in
3621 `org-todo-keywords-1'."
3623 (org-compile-prefix-format 'todo)
3624 (org-set-sorting-strategy 'todo)
3625 (org-prepare-agenda "TODO")
3626 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3627 (let* ((today (time-to-days (current-time)))
3628 (date (calendar-gregorian-from-absolute today))
3629 (kwds org-todo-keywords-for-agenda)
3630 (completion-ignore-case t)
3631 (org-select-this-todo-keyword
3632 (if (stringp arg) arg
3633 (and arg (integerp arg) (> arg 0)
3634 (nth (1- arg) kwds))))
3635 rtn rtnall files file pos)
3636 (when (equal arg '(4))
3637 (setq org-select-this-todo-keyword
3638 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3639 (mapcar 'list kwds) nil nil)))
3640 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3641 (org-set-local 'org-last-arg arg)
3642 (setq org-agenda-redo-command
3643 '(org-todo-list (or current-prefix-arg org-last-arg)))
3644 (setq files (org-agenda-files nil 'ifmode)
3646 (while (setq file (pop files))
3648 (org-check-agenda-file file)
3649 (setq rtn (org-agenda-get-day-entries file date :todo))
3650 (setq rtnall (append rtnall rtn))))
3651 (if org-agenda-overriding-header
3652 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3653 nil 'face 'org-agenda-structure) "\n")
3654 (insert "Global list of TODO items of type: ")
3655 (add-text-properties (point-min) (1- (point))
3656 (list 'face 'org-agenda-structure
3659 (or org-select-this-todo-keyword "ALL"))))
3660 (org-agenda-mark-header-line (point-min))
3662 (insert (or org-select-this-todo-keyword "ALL") "\n")
3663 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3665 (unless org-agenda-multi
3666 (insert "Available with `N r': (0)ALL")
3669 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3670 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3675 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3676 (org-agenda-mark-header-line (point-min))
3678 (insert (org-finalize-agenda-entries rtnall) "\n"))
3679 (goto-char (point-min))
3680 (or org-agenda-multi (org-fit-agenda-window))
3681 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3682 (org-finalize-agenda)
3683 (setq buffer-read-only t)))
3685 ;;; Agenda tags match
3688 (defun org-tags-view (&optional todo-only match)
3689 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3690 The prefix arg TODO-ONLY limits the search to TODO entries."
3692 (org-compile-prefix-format 'tags)
3693 (org-set-sorting-strategy 'tags)
3694 (let* ((org-tags-match-list-sublevels
3695 org-tags-match-list-sublevels)
3696 (completion-ignore-case t)
3697 rtn rtnall files file pos matcher
3699 (when (and (stringp match) (not (string-match "\\S-" match)))
3701 (setq matcher (org-make-tags-matcher match)
3702 match (car matcher) matcher (cdr matcher))
3703 (org-prepare-agenda (concat "TAGS " match))
3704 (setq org-agenda-query-string match)
3705 (setq org-agenda-redo-command
3706 (list 'org-tags-view (list 'quote todo-only)
3707 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3708 (setq files (org-agenda-files nil 'ifmode)
3710 (while (setq file (pop files))
3712 (org-check-agenda-file file)
3713 (setq buffer (if (file-exists-p file)
3714 (org-get-agenda-file-buffer file)
3715 (error "No such file %s" file)))
3717 ;; If file does not exist, error message to agenda
3719 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3720 rtnall (append rtnall rtn))
3721 (with-current-buffer buffer
3722 (unless (org-mode-p)
3723 (error "Agenda file %s is not in `org-mode'" file))
3726 (if org-agenda-restrict
3727 (narrow-to-region org-agenda-restrict-begin
3728 org-agenda-restrict-end)
3730 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3731 (setq rtnall (append rtnall rtn))))))))
3732 (if org-agenda-overriding-header
3733 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3734 nil 'face 'org-agenda-structure) "\n")
3735 (insert "Headlines with TAGS match: ")
3736 (add-text-properties (point-min) (1- (point))
3737 (list 'face 'org-agenda-structure
3739 (concat "Match: " match)))
3742 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3744 (unless org-agenda-multi
3745 (insert "Press `C-u r' to search again with new search string\n"))
3746 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3747 (org-agenda-mark-header-line (point-min))
3749 (insert (org-finalize-agenda-entries rtnall) "\n"))
3750 (goto-char (point-min))
3751 (or org-agenda-multi (org-fit-agenda-window))
3752 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3753 (org-finalize-agenda)
3754 (setq buffer-read-only t)))
3756 ;;; Agenda Finding stuck projects
3758 (defvar org-agenda-skip-regexp nil
3759 "Regular expression used in skipping subtrees for the agenda.
3760 This is basically a temporary global variable that can be set and then
3761 used by user-defined selections using `org-agenda-skip-function'.")
3763 (defvar org-agenda-overriding-header nil
3764 "When this is set during todo and tags searches, will replace header.
3765 This variable should not be set directly, but custom commands can bind it
3766 in the options section.")
3768 (defun org-agenda-skip-entry-when-regexp-matches ()
3769 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3770 If yes, it returns the end position of this entry, causing agenda commands
3771 to skip the entry but continuing the search in the subtree. This is a
3772 function that can be put into `org-agenda-skip-function' for the duration
3774 (let ((end (save-excursion (org-end-of-subtree t)))
3777 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3780 (defun org-agenda-skip-subtree-when-regexp-matches ()
3781 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3782 If yes, it returns the end position of this tree, causing agenda commands
3783 to skip this subtree. This is a function that can be put into
3784 `org-agenda-skip-function' for the duration of a command."
3785 (let ((end (save-excursion (org-end-of-subtree t)))
3788 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3791 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3792 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3793 If yes, it returns the end position of the current entry (NOT the tree),
3794 causing agenda commands to skip the entry but continuing the search in
3795 the subtree. This is a function that can be put into
3796 `org-agenda-skip-function' for the duration of a command. An important
3797 use of this function is for the stuck project list."
3798 (let ((end (save-excursion (org-end-of-subtree t)))
3799 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3802 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3803 (and skip entry-end)))
3805 (defun org-agenda-skip-entry-if (&rest conditions)
3806 "Skip entry if any of CONDITIONS is true.
3807 See `org-agenda-skip-if' for details."
3808 (org-agenda-skip-if nil conditions))
3810 (defun org-agenda-skip-subtree-if (&rest conditions)
3811 "Skip entry if any of CONDITIONS is true.
3812 See `org-agenda-skip-if' for details."
3813 (org-agenda-skip-if t conditions))
3815 (defun org-agenda-skip-if (subtree conditions)
3816 "Checks current entity for CONDITIONS.
3817 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3818 the entry, i.e. the text before the next heading is checked.
3820 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3821 from different tests. Valid conditions are:
3823 scheduled Check if there is a scheduled cookie
3824 notscheduled Check if there is no scheduled cookie
3825 deadline Check if there is a deadline
3826 notdeadline Check if there is no deadline
3827 timestamp Check if there is a timestamp (also deadline or scheduled)
3828 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3829 regexp Check if regexp matches
3830 notregexp Check if regexp does not match.
3831 todo Check if TODO keyword matches
3832 nottodo Check if TODO keyword does not match
3834 The regexp is taken from the conditions list, it must come right after
3835 the `regexp' or `notregexp' element.
3837 `todo' and `nottodo' accept as an argument a list of todo
3838 keywords, which may include \"*\" to match any todo keyword.
3840 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
3842 would skip all entries with \"TODO\" or \"WAITING\" keywords.
3844 Instead of a list a keyword class may be given
3846 (org-agenda-skip-entry-if 'nottodo 'done)
3848 would skip entries that haven't been marked with any of \"DONE\"
3849 keywords. Possible classes are: `todo', `done', `any'.
3851 If any of these conditions is met, this function returns the end point of
3852 the entity, causing the search to continue from there. This is a function
3853 that can be put into `org-agenda-skip-function' for the duration of a command."
3855 (org-back-to-heading t)
3858 (progn (org-end-of-subtree t) (point))
3859 (progn (outline-next-heading) (1- (point)))))
3863 (and (memq 'scheduled conditions)
3864 (re-search-forward org-scheduled-time-regexp end t))
3865 (and (memq 'notscheduled conditions)
3866 (not (re-search-forward org-scheduled-time-regexp end t)))
3867 (and (memq 'deadline conditions)
3868 (re-search-forward org-deadline-time-regexp end t))
3869 (and (memq 'notdeadline conditions)
3870 (not (re-search-forward org-deadline-time-regexp end t)))
3871 (and (memq 'timestamp conditions)
3872 (re-search-forward org-ts-regexp end t))
3873 (and (memq 'nottimestamp conditions)
3874 (not (re-search-forward org-ts-regexp end t)))
3875 (and (setq m (memq 'regexp conditions))
3877 (re-search-forward (nth 1 m) end t))
3878 (and (setq m (memq 'notregexp conditions))
3880 (not (re-search-forward (nth 1 m) end t)))
3882 (setq m (memq 'todo conditions))
3883 (setq m (memq 'nottodo conditions)))
3884 (org-agenda-skip-if-todo m end)))
3887 (defun org-agenda-skip-if-todo (args end)
3888 "Helper function for `org-agenda-skip-if', do not use it directly.
3889 ARGS is a list with first element either `todo' or `nottodo'.
3890 The remainder is either a list of TODO keywords, or a state symbol
3891 `todo' or `done' or `any'."
3892 (let ((kw (car args))
3898 ((listp arg) ;; list of keywords
3899 (if (member "*" arg)
3900 (mapcar 'substring-no-properties org-todo-keywords-1)
3902 ((symbolp arg) ;; keyword class name
3905 (org-delete-all org-done-keywords
3906 (mapcar 'substring-no-properties
3907 org-todo-keywords-1)))
3908 ((eq arg 'done) org-done-keywords)
3910 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
3912 (concat "^\\*+[ \t]+\\<\\("
3913 (mapconcat 'identity todo-wds "\\|")
3916 (re-search-forward todo-re end t)
3917 (not (re-search-forward todo-re end t)))))
3920 (defun org-agenda-list-stuck-projects (&rest ignore)
3921 "Create agenda view for projects that are stuck.
3922 Stuck projects are project that have no next actions. For the definitions
3923 of what a project is and how to check if it stuck, customize the variable
3924 `org-stuck-projects'.
3925 MATCH is being ignored."
3927 (let* ((org-agenda-skip-function
3928 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3929 ;; We could have used org-agenda-skip-if here.
3930 (org-agenda-overriding-header
3931 (or org-agenda-overriding-header "List of stuck projects: "))
3932 (matcher (nth 0 org-stuck-projects))
3933 (todo (nth 1 org-stuck-projects))
3934 (todo-wds (if (member "*" todo)
3936 (org-prepare-agenda-buffers (org-agenda-files
3939 org-done-keywords-for-agenda
3940 (copy-sequence org-todo-keywords-for-agenda)))
3942 (todo-re (concat "^\\*+[ \t]+\\("
3943 (mapconcat 'identity todo-wds "\\|")
3945 (tags (nth 2 org-stuck-projects))
3946 (tags-re (if (member "*" tags)
3947 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3949 (concat "^\\*+ .*:\\("
3950 (mapconcat 'identity tags "\\|")
3951 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3952 (gen-re (nth 3 org-stuck-projects))
3958 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3960 (setq org-agenda-skip-regexp
3962 (mapconcat 'identity re-list "\\|")
3963 (error "No information how to identify unstuck projects")))
3964 (org-tags-view nil matcher)
3965 (with-current-buffer org-agenda-buffer-name
3966 (setq org-agenda-redo-command
3967 '(org-agenda-list-stuck-projects
3968 (or current-prefix-arg org-last-arg))))))
3970 ;;; Diary integration
3972 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3973 (defvar list-diary-entries-hook)
3975 (defun org-get-entries-from-diary (date)
3976 "Get the (Emacs Calendar) diary entries for DATE."
3977 (require 'diary-lib)
3978 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3979 (diary-display-hook '(fancy-diary-display))
3980 (diary-display-function 'fancy-diary-display)
3982 (list-diary-entries-hook
3983 (cons 'org-diary-default-entry list-diary-entries-hook))
3984 (diary-file-name-prefix-function nil) ; turn this feature off
3985 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3987 (org-disable-agenda-to-diary t))
3989 (save-window-excursion
3990 (funcall (if (fboundp 'diary-list-entries)
3991 'diary-list-entries 'list-diary-entries)
3993 (if (not (get-buffer diary-fancy-buffer))
3995 (with-current-buffer diary-fancy-buffer
3996 (setq buffer-read-only nil)
3997 (if (zerop (buffer-size))
4000 ;; Omit the date and other unnecessary stuff
4001 (org-agenda-cleanup-fancy-diary)
4002 ;; Add prefix to each line and extend the text properties
4003 (if (zerop (buffer-size))
4005 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
4006 (set-buffer-modified-p nil)
4007 (kill-buffer diary-fancy-buffer)))
4009 (setq entries (org-split-string entries "\n"))
4013 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4014 ;; Extend the text properties to the beginning of the line
4015 (org-add-props x (text-properties-at (1- (length x)) x)
4016 'type "diary" 'date date 'face 'org-agenda-diary))
4019 (defvar org-agenda-cleanup-fancy-diary-hook nil
4020 "Hook run when the fancy diary buffer is cleaned up.")
4022 (defun org-agenda-cleanup-fancy-diary ()
4023 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4024 This gets rid of the date, the underline under the date, and
4025 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4026 date. It also removes lines that contain only whitespace."
4027 (goto-char (point-min))
4028 (if (looking-at ".*?:[ \t]*")
4031 (re-search-forward "\n=+$" nil t)
4033 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4034 (re-search-forward "\n=+$" nil t)
4035 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4036 (goto-char (point-min))
4037 (while (re-search-forward "^ +\n" nil t)
4039 (goto-char (point-min))
4040 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4042 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4044 ;; Make sure entries from the diary have the right text properties.
4045 (eval-after-load "diary-lib"
4046 '(if (boundp 'diary-modify-entry-list-string-function)
4047 ;; We can rely on the hook, nothing to do
4049 ;; Hook not available, must use advice to make this work
4050 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4051 "Make the position visible."
4052 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4055 (setq string (org-modify-diary-entry-string string))))))
4057 (defun org-modify-diary-entry-string (string)
4058 "Add text properties to string, allowing org-mode to act on it."
4059 (org-add-props string nil
4060 'mouse-face 'highlight
4061 'help-echo (if buffer-file-name
4062 (format "mouse-2 or RET jump to diary file %s"
4063 (abbreviate-file-name buffer-file-name))
4065 'org-agenda-diary-link t
4066 'org-marker (org-agenda-new-marker (point-at-bol))))
4068 (defun org-diary-default-entry ()
4069 "Add a dummy entry to the diary.
4070 Needed to avoid empty dates which mess up holiday display."
4071 ;; Catch the error if dealing with the new add-to-diary-alist
4072 (when org-disable-agenda-to-diary
4074 (org-add-to-diary-list original-date "Org-mode dummy" "")
4076 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4078 (defun org-add-to-diary-list (&rest args)
4079 (if (fboundp 'diary-add-to-list)
4080 (apply 'diary-add-to-list args)
4081 (apply 'add-to-diary-list args)))
4083 (defvar org-diary-last-run-time nil)
4086 (defun org-diary (&rest args)
4087 "Return diary information from org-files.
4088 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4089 It accesses org files and extracts information from those files to be
4090 listed in the diary. The function accepts arguments specifying what
4091 items should be listed. For a list of arguments allowed here, see the
4092 variable `org-agenda-entry-types'.
4094 The call in the diary file should look like this:
4096 &%%(org-diary) ~/path/to/some/orgfile.org
4098 Use a separate line for each org file to check. Or, if you omit the file name,
4099 all files listed in `org-agenda-files' will be checked automatically:
4103 If you don't give any arguments (as in the example above), the default
4104 arguments (:deadline :scheduled :timestamp :sexp) are used.
4105 So the example above may also be written as
4107 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4109 The function expects the lisp variables `entry' and `date' to be provided
4110 by the caller, because this is how the calendar works. Don't use this
4111 function from a program - use `org-agenda-get-day-entries' instead."
4112 (when (> (- (org-float-time)
4113 org-agenda-last-marker-time)
4115 (org-agenda-reset-markers))
4116 (org-compile-prefix-format 'agenda)
4117 (org-set-sorting-strategy 'agenda)
4118 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4119 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4121 (org-agenda-files t)))
4122 (time (org-float-time))
4124 (when (or (not org-diary-last-run-time)
4126 org-diary-last-run-time)
4128 (org-prepare-agenda-buffers files))
4129 (setq org-diary-last-run-time time)
4130 ;; If this is called during org-agenda, don't return any entries to
4131 ;; the calendar. Org Agenda will list these entries itself.
4132 (if org-disable-agenda-to-diary (setq files nil))
4133 (while (setq file (pop files))
4134 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4135 (setq results (append results rtn)))
4137 (concat (org-finalize-agenda-entries results) "\n"))))
4139 ;;; Agenda entry finders
4141 (defun org-agenda-get-day-entries (file date &rest args)
4142 "Does the work for `org-diary' and `org-agenda'.
4143 FILE is the path to a file to be checked for entries. DATE is date like
4144 the one returned by `calendar-current-date'. ARGS are symbols indicating
4145 which kind of entries should be extracted. For details about these, see
4146 the documentation of `org-diary'."
4147 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4148 (let* ((org-startup-folded nil)
4149 (org-startup-align-all-tables nil)
4150 (buffer (if (file-exists-p file)
4151 (org-get-agenda-file-buffer file)
4152 (error "No such file %s" file)))
4153 arg results rtn deadline-results)
4155 ;; If file does not exist, make sure an error message ends up in diary
4156 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4157 (with-current-buffer buffer
4158 (unless (org-mode-p)
4159 (error "Agenda file %s is not in `org-mode'" file))
4160 (let ((case-fold-search nil))
4163 (if org-agenda-restrict
4164 (narrow-to-region org-agenda-restrict-begin
4165 org-agenda-restrict-end)
4167 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4168 (while (setq arg (pop args))
4170 ((and (eq arg :todo)
4171 (equal date (calendar-current-date)))
4172 (setq rtn (org-agenda-get-todos))
4173 (setq results (append results rtn)))
4174 ((eq arg :timestamp)
4175 (setq rtn (org-agenda-get-blocks))
4176 (setq results (append results rtn))
4177 (setq rtn (org-agenda-get-timestamps))
4178 (setq results (append results rtn)))
4180 (setq rtn (org-agenda-get-sexps))
4181 (setq results (append results rtn)))
4182 ((eq arg :scheduled)
4183 (setq rtn (org-agenda-get-scheduled deadline-results))
4184 (setq results (append results rtn)))
4186 (setq rtn (org-agenda-get-progress))
4187 (setq results (append results rtn)))
4189 (setq rtn (org-agenda-get-deadlines))
4190 (setq deadline-results (copy-sequence rtn))
4191 (setq results (append results rtn))))))))
4194 (defun org-agenda-get-todos ()
4195 "Return the TODO information for agenda display."
4196 (let* ((props (list 'face nil
4197 'done-face 'org-agenda-done
4198 'org-not-done-regexp org-not-done-regexp
4199 'org-todo-regexp org-todo-regexp
4200 'org-complex-heading-regexp org-complex-heading-regexp
4201 'mouse-face 'highlight
4203 (format "mouse-2 or RET jump to org file %s"
4204 (abbreviate-file-name buffer-file-name))))
4205 (regexp (concat "^\\*+[ \t]+\\("
4206 (if org-select-this-todo-keyword
4207 (if (equal org-select-this-todo-keyword "*")
4210 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4212 org-not-done-regexp)
4214 marker priority category tags todo-state
4216 (goto-char (point-min))
4217 (while (re-search-forward regexp nil t)
4221 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4222 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4223 (goto-char (1+ beg))
4224 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4228 (goto-char (match-beginning 1))
4229 (setq marker (org-agenda-new-marker (match-beginning 0))
4230 category (org-get-category)
4231 txt (match-string 1)
4232 tags (org-get-tags-at (point))
4233 txt (org-format-agenda-item "" txt category tags)
4234 priority (1+ (org-get-priority txt))
4235 todo-state (org-get-todo-state))
4236 (org-add-props txt props
4237 'org-marker marker 'org-hd-marker marker
4238 'priority priority 'org-category category
4239 'type "todo" 'todo-state todo-state)
4241 (if org-agenda-todo-list-sublevels
4242 (goto-char (match-end 1))
4243 (org-end-of-subtree 'invisible))))
4247 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4249 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4250 (when (or org-agenda-todo-ignore-with-date
4251 org-agenda-todo-ignore-scheduled
4252 org-agenda-todo-ignore-deadlines)
4253 (setq end (or end (save-excursion (outline-next-heading) (point))))
4255 (or (and org-agenda-todo-ignore-with-date
4256 (re-search-forward org-ts-regexp end t))
4257 (and org-agenda-todo-ignore-scheduled
4258 (re-search-forward org-scheduled-time-regexp end t)
4260 ((eq org-agenda-todo-ignore-scheduled 'future)
4261 (> (org-days-to-time (match-string 1)) 0))
4262 ((eq org-agenda-todo-ignore-scheduled 'past)
4263 (<= (org-days-to-time (match-string 1)) 0))
4265 (and org-agenda-todo-ignore-deadlines
4266 (re-search-forward org-deadline-time-regexp end t)
4268 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4269 ((eq org-agenda-todo-ignore-deadlines 'far)
4270 (not (org-deadline-close (match-string 1))))
4271 ((eq org-agenda-todo-ignore-deadlines 'future)
4272 (> (org-days-to-time (match-string 1)) 0))
4273 ((eq org-agenda-todo-ignore-deadlines 'past)
4274 (<= (org-days-to-time (match-string 1)) 0))
4275 (t (org-deadline-close (match-string 1)))))))))
4277 (defconst org-agenda-no-heading-message
4278 "No heading for this item in buffer or region.")
4280 (defun org-agenda-get-timestamps ()
4281 "Return the date stamp information for agenda display."
4282 (let* ((props (list 'face nil
4283 'org-not-done-regexp org-not-done-regexp
4284 'org-todo-regexp org-todo-regexp
4285 'org-complex-heading-regexp org-complex-heading-regexp
4286 'mouse-face 'highlight
4288 (format "mouse-2 or RET jump to org file %s"
4289 (abbreviate-file-name buffer-file-name))))
4290 (d1 (calendar-absolute-from-gregorian date))
4296 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4300 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4304 (car org-time-stamp-formats)
4305 (apply 'encode-time ; DATE bound by calendar
4306 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4308 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4309 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4310 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4311 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4312 todo-state end-of-match)
4313 (goto-char (point-min))
4314 (while (setq end-of-match (re-search-forward regexp nil t))
4315 (setq b0 (match-beginning 0)
4316 b3 (match-beginning 3) e3 (match-end 3))
4318 (and (org-at-date-range-p) (throw :skip nil))
4320 (if (and (match-end 1)
4321 (not (= d1 (org-time-string-to-absolute
4322 (match-string 1) d1 nil
4323 org-agenda-repeating-timestamp-show-all))))
4326 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4328 (setq tmp (buffer-substring (max (point-min)
4329 (- b0 org-ds-keyword-length))
4331 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4332 inactivep (= (char-after b0) ?\[)
4333 deadlinep (string-match org-deadline-regexp tmp)
4334 scheduledp (string-match org-scheduled-regexp tmp)
4335 closedp (and org-agenda-include-inactive-timestamps
4336 (string-match org-closed-string tmp))
4337 clockp (and org-agenda-include-inactive-timestamps
4338 (or (string-match org-clock-string tmp)
4339 (string-match "]-+\\'" tmp)))
4340 todo-state (org-get-todo-state)
4341 donep (member todo-state org-done-keywords))
4342 (if (or scheduledp deadlinep closedp clockp
4343 (and donep org-agenda-skip-timestamp-if-done))
4345 (if (string-match ">" timestr)
4346 ;; substring should only run to end of time stamp
4347 (setq timestr (substring timestr 0 (match-end 0))))
4348 (setq marker (org-agenda-new-marker b0)
4349 category (org-get-category b0))
4351 (if (not (re-search-backward "^\\*+ " nil t))
4352 (setq txt org-agenda-no-heading-message)
4353 (goto-char (match-beginning 0))
4354 (setq hdmarker (org-agenda-new-marker)
4355 tags (org-get-tags-at))
4356 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4357 (setq head (match-string 1))
4358 (setq txt (org-format-agenda-item
4359 (if inactivep org-agenda-inactive-leader nil)
4360 head category tags timestr nil
4362 (setq priority (org-get-priority txt))
4363 (org-add-props txt props
4364 'org-marker marker 'org-hd-marker hdmarker)
4365 (org-add-props txt nil 'priority priority
4366 'org-category category 'date date
4367 'todo-state todo-state
4370 (if org-agenda-skip-additional-timestamps-same-entry
4371 (outline-next-heading)
4372 (goto-char end-of-match))))
4375 (defun org-agenda-get-sexps ()
4376 "Return the sexp information for agenda display."
4377 (require 'diary-lib)
4378 (let* ((props (list 'face nil
4379 'mouse-face 'highlight
4381 (format "mouse-2 or RET jump to org file %s"
4382 (abbreviate-file-name buffer-file-name))))
4384 marker category ee txt tags entry result beg b sexp sexp-entry
4386 (goto-char (point-min))
4387 (while (re-search-forward regexp nil t)
4390 (setq beg (match-beginning 0))
4391 (goto-char (1- (match-end 0)))
4394 (setq sexp (buffer-substring b (point)))
4395 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4396 (org-trim (match-string 1))
4398 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4400 (setq marker (org-agenda-new-marker beg)
4401 category (org-get-category beg)
4402 todo-state (org-get-todo-state))
4404 (if (string-match "\\S-" result)
4406 (setq txt "SEXP entry returned empty string"))
4408 (setq txt (org-format-agenda-item
4409 "" txt category tags 'time))
4410 (org-add-props txt props 'org-marker marker)
4411 (org-add-props txt nil
4412 'org-category category 'date date 'todo-state todo-state
4417 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4418 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4419 The order of the first 2 times 3 arguments depends on the variable
4420 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4421 So for american calendars, give this as MONTH DAY YEAR, for european as
4422 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4423 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4424 is any number of ISO weeks in the block period for which the item should
4426 (let* ((date1 (calendar-absolute-from-gregorian
4427 (org-order-calendar-date-args m1 d1 y1)))
4428 (date2 (calendar-absolute-from-gregorian
4429 (org-order-calendar-date-args m2 d2 y2)))
4430 (d (calendar-absolute-from-gregorian date)))
4434 (= (calendar-day-of-week date) dayname)
4435 (or (not skip-weeks)
4438 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4441 (defalias 'org-get-closed 'org-agenda-get-progress)
4442 (defun org-agenda-get-progress ()
4443 "Return the logged TODO entries for agenda display."
4444 (let* ((props (list 'mouse-face 'highlight
4445 'org-not-done-regexp org-not-done-regexp
4446 'org-todo-regexp org-todo-regexp
4447 'org-complex-heading-regexp org-complex-heading-regexp
4449 (format "mouse-2 or RET jump to org file %s"
4450 (abbreviate-file-name buffer-file-name))))
4451 (items (if (consp org-agenda-show-log)
4453 org-agenda-log-mode-items))
4457 (if (memq 'closed items) (concat "\\<" org-closed-string))
4458 (if (memq 'clock items) (concat "\\<" org-clock-string))
4459 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4460 (parts-re (if parts (mapconcat 'identity parts "\\|")
4461 (error "`org-agenda-log-mode-items' is empty")))
4463 "\\(" parts-re "\\)"
4468 (car org-time-stamp-formats)
4469 (apply 'encode-time ; DATE bound by calendar
4470 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4472 (org-agenda-search-headline-for-time nil)
4473 marker hdmarker priority category tags closedp statep clockp state
4474 ee txt extra timestr rest clocked)
4475 (goto-char (point-min))
4476 (while (re-search-forward regexp nil t)
4479 (setq marker (org-agenda-new-marker (match-beginning 0))
4480 closedp (equal (match-string 1) org-closed-string)
4481 statep (equal (string-to-char (match-string 1)) ?-)
4482 clockp (not (or closedp statep))
4483 state (and statep (match-string 2))
4484 category (org-get-category (match-beginning 0))
4485 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4487 (when (string-match "\\]" timestr)
4488 ;; substring should only run to end of time stamp
4489 (setq rest (substring timestr (match-end 0))
4490 timestr (substring timestr 0 (match-end 0)))
4491 (if (and (not closedp) (not statep)
4492 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4493 (progn (setq timestr (concat (substring timestr 0 -1)
4494 "-" (match-string 1 rest) "]"))
4495 (setq clocked (match-string 2 rest)))
4496 (setq clocked "-")))
4499 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4501 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4502 (setq extra (match-string 1))))
4504 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4505 (setq extra (match-string 1))))
4506 (t (setq extra nil)))
4507 (if (not (re-search-backward "^\\*+ " nil t))
4508 (setq txt org-agenda-no-heading-message)
4509 (goto-char (match-beginning 0))
4510 (setq hdmarker (org-agenda-new-marker)
4511 tags (org-get-tags-at))
4512 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4513 (setq txt (match-string 1))
4515 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4516 (setq txt (concat (substring txt 0 (match-beginning 1))
4517 " - " extra " " (match-string 2 txt)))
4518 (setq txt (concat txt " - " extra))))
4519 (setq txt (org-format-agenda-item
4521 (closedp "Closed: ")
4522 (statep (concat "State: (" state ")"))
4523 (t (concat "Clocked: (" clocked ")")))
4524 txt category tags timestr)))
4525 (setq priority 100000)
4526 (org-add-props txt props
4527 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4528 'priority priority 'org-category category
4529 'type "closed" 'date date
4530 'undone-face 'org-warning 'done-face 'org-agenda-done)
4532 (goto-char (point-at-eol))))
4535 (defun org-agenda-get-deadlines ()
4536 "Return the deadline information for agenda display."
4537 (let* ((props (list 'mouse-face 'highlight
4538 'org-not-done-regexp org-not-done-regexp
4539 'org-todo-regexp org-todo-regexp
4540 'org-complex-heading-regexp org-complex-heading-regexp
4542 (format "mouse-2 or RET jump to org file %s"
4543 (abbreviate-file-name buffer-file-name))))
4544 (regexp org-deadline-time-regexp)
4545 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4546 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4547 d2 diff dfrac wdays pos pos1 category tags
4549 ee txt head face s todo-state upcomingp donep timestr)
4550 (goto-char (point-min))
4551 (while (re-search-forward regexp nil t)
4552 (setq suppress-prewarning nil)
4555 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4557 (string-match org-scheduled-time-regexp
4558 (buffer-substring (point-at-bol)
4560 (setq suppress-prewarning
4561 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4562 org-agenda-skip-deadline-prewarning-if-scheduled
4564 (setq s (match-string 1)
4566 pos (1- (match-beginning 1))
4567 d2 (org-time-string-to-absolute
4568 (match-string 1) d1 'past
4569 org-agenda-repeating-timestamp-show-all)
4571 wdays (if suppress-prewarning
4572 (let ((org-deadline-warning-days suppress-prewarning))
4575 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4576 upcomingp (and todayp (> diff 0)))
4577 ;; When to show a deadline in the calendar:
4578 ;; If the expiration is within wdays warning time.
4579 ;; Past-due deadlines are only shown on the current date
4580 (if (and (or (and (<= diff wdays)
4581 (and todayp (not org-agenda-only-exact-dates)))
4584 (setq todo-state (org-get-todo-state))
4585 (setq donep (member todo-state org-done-keywords))
4587 (or org-agenda-skip-deadline-if-done
4590 (setq category (org-get-category))
4591 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4592 (setq txt org-agenda-no-heading-message)
4593 (goto-char (match-end 0))
4594 (setq pos1 (match-beginning 0))
4595 (setq tags (org-get-tags-at pos1))
4596 (setq head (buffer-substring-no-properties
4598 (progn (skip-chars-forward "^\r\n")
4600 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4602 (concat (substring s (match-beginning 1)) " "))
4603 (setq timestr 'time))
4604 (setq txt (org-format-agenda-item
4606 (car org-agenda-deadline-leaders)
4608 (nth 1 org-agenda-deadline-leaders))
4610 (nth 1 org-agenda-deadline-leaders)
4612 (format (nth 1 org-agenda-deadline-leaders)
4615 (if (not (= diff 0)) nil timestr)))))
4617 (setq face (org-agenda-deadline-face dfrac wdays))
4618 (org-add-props txt props
4619 'org-marker (org-agenda-new-marker pos)
4620 'org-hd-marker (org-agenda-new-marker pos1)
4621 'priority (+ (- diff)
4622 (org-get-priority txt))
4623 'org-category category
4624 'todo-state todo-state
4625 'type (if upcomingp "upcoming-deadline" "deadline")
4626 'date (if upcomingp date d2)
4627 'face (if donep 'org-agenda-done face)
4628 'undone-face face 'done-face 'org-agenda-done)
4632 (defun org-agenda-deadline-face (fraction &optional wdays)
4633 "Return the face to displaying a deadline item.
4634 FRACTION is what fraction of the head-warning time has passed."
4635 (if (equal wdays 0) (setq fraction 1.))
4636 (let ((faces org-agenda-deadline-faces) f)
4638 (while (setq f (pop faces))
4639 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4641 (defun org-agenda-get-scheduled (&optional deadline-results)
4642 "Return the scheduled information for agenda display."
4643 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4644 'org-todo-regexp org-todo-regexp
4645 'org-complex-heading-regexp org-complex-heading-regexp
4646 'done-face 'org-agenda-done
4647 'mouse-face 'highlight
4649 (format "mouse-2 or RET jump to org file %s"
4650 (abbreviate-file-name buffer-file-name))))
4651 (regexp org-scheduled-time-regexp)
4652 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4653 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4655 (deadline-position-alist
4656 (mapcar (lambda (a) (and (setq mm (get-text-property
4657 0 'org-hd-marker a))
4658 (cons (marker-position mm) a)))
4660 d2 diff pos pos1 category tags donep
4661 ee txt head pastschedp todo-state face timestr s habitp)
4662 (goto-char (point-min))
4663 (while (re-search-forward regexp nil t)
4666 (setq s (match-string 1)
4668 pos (1- (match-beginning 1))
4669 d2 (org-time-string-to-absolute
4670 (match-string 1) d1 'past
4671 org-agenda-repeating-timestamp-show-all)
4673 (setq pastschedp (and todayp (< diff 0)))
4674 ;; When to show a scheduled item in the calendar:
4675 ;; If it is on or past the date.
4676 (when (or (and (< diff 0)
4677 (< (abs diff) org-scheduled-past-days)
4678 (and todayp (not org-agenda-only-exact-dates)))
4681 (setq todo-state (org-get-todo-state))
4682 (setq donep (member todo-state org-done-keywords))
4683 (setq habitp (and (functionp 'org-is-habit-p)
4686 (or habitp org-agenda-skip-scheduled-if-done
4689 (setq category (org-get-category))
4690 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4691 (setq txt org-agenda-no-heading-message)
4692 (goto-char (match-end 0))
4693 (setq pos1 (match-beginning 0))
4695 (if (or (not org-habit-show-habits)
4697 org-habit-show-habits-only-for-today))
4700 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4701 (and org-agenda-skip-scheduled-if-deadline-is-shown
4703 (setq mm (assoc pos1 deadline-position-alist)))
4705 (setq tags (org-get-tags-at))
4706 (setq head (buffer-substring-no-properties
4708 (progn (skip-chars-forward "^\r\n") (point))))
4709 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4711 (concat (substring s (match-beginning 1)) " "))
4712 (setq timestr 'time))
4713 (setq txt (org-format-agenda-item
4715 (car org-agenda-scheduled-leaders)
4716 (format (nth 1 org-agenda-scheduled-leaders)
4719 (if (not (= diff 0)) nil timestr)
4724 ((and (not habitp) pastschedp)
4725 'org-scheduled-previously)
4726 (todayp 'org-scheduled-today)
4728 habitp (and habitp (org-habit-parse-todo)))
4729 (org-add-props txt props
4731 'face (if donep 'org-agenda-done face)
4732 'org-marker (org-agenda-new-marker pos)
4733 'org-hd-marker (org-agenda-new-marker pos1)
4734 'type (if pastschedp "past-scheduled" "scheduled")
4735 'date (if pastschedp d2 date)
4736 'priority (if habitp
4737 (org-habit-get-priority habitp)
4738 (+ 94 (- 5 diff) (org-get-priority txt)))
4739 'org-category category
4741 'todo-state todo-state)
4745 (defun org-agenda-get-blocks ()
4746 "Return the date-range information for agenda display."
4747 (let* ((props (list 'face nil
4748 'org-not-done-regexp org-not-done-regexp
4749 'org-todo-regexp org-todo-regexp
4750 'org-complex-heading-regexp org-complex-heading-regexp
4751 'mouse-face 'highlight
4753 (format "mouse-2 or RET jump to org file %s"
4754 (abbreviate-file-name buffer-file-name))))
4755 (regexp org-tr-regexp)
4756 (d0 (calendar-absolute-from-gregorian date))
4757 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4759 (goto-char (point-min))
4760 (while (re-search-forward regexp nil t)
4764 (setq timestr (match-string 0)
4767 d1 (time-to-days (org-time-string-to-time s1))
4768 d2 (time-to-days (org-time-string-to-time s2)))
4769 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4770 ;; Only allow days between the limits, because the normal
4771 ;; date stamps will catch the limits.
4773 (setq todo-state (org-get-todo-state))
4774 (setq donep (member todo-state org-done-keywords))
4775 (if (and donep org-agenda-skip-timestamp-if-done)
4777 (setq marker (org-agenda-new-marker (point)))
4778 (setq category (org-get-category))
4779 (if (not (re-search-backward "^\\*+ " nil t))
4780 (setq txt org-agenda-no-heading-message)
4781 (goto-char (match-beginning 0))
4782 (setq hdmarker (org-agenda-new-marker (point)))
4783 (setq tags (org-get-tags-at))
4784 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4785 (setq head (match-string 1))
4786 (setq txt (org-format-agenda-item
4788 (nth (if (= d1 d2) 0 1)
4789 org-agenda-timerange-leaders)
4790 (1+ (- d0 d1)) (1+ (- d2 d1)))
4793 (org-add-props txt props
4794 'org-marker marker 'org-hd-marker hdmarker
4795 'type "block" 'date date
4796 'todo-state todo-state
4797 'priority (org-get-priority txt) 'org-category category)
4800 ;; Sort the entries by expiration date.
4803 ;;; Agenda presentation and sorting
4805 (defvar org-prefix-has-time nil
4806 "A flag, set by `org-compile-prefix-format'.
4807 The flag is set if the currently compiled format contains a `%t'.")
4808 (defvar org-prefix-has-tag nil
4809 "A flag, set by `org-compile-prefix-format'.
4810 The flag is set if the currently compiled format contains a `%T'.")
4811 (defvar org-prefix-has-effort nil
4812 "A flag, set by `org-compile-prefix-format'.
4813 The flag is set if the currently compiled format contains a `%e'.")
4814 (defvar org-prefix-category-length nil
4815 "Used by `org-compile-prefix-format' to remember the category field widh.")
4816 (defvar org-prefix-category-max-length nil
4817 "Used by `org-compile-prefix-format' to remember the category field widh.")
4819 (defun org-format-agenda-item (extra txt &optional category tags dotime
4820 noprefix remove-re habitp)
4821 "Format TXT to be inserted into the agenda buffer.
4822 In particular, it adds the prefix and corresponding text properties. EXTRA
4823 must be a string and replaces the `%s' specifier in the prefix format.
4824 CATEGORY (string, symbol or nil) may be used to overrule the default
4825 category taken from local variable or file name. It will replace the `%c'
4826 specifier in the format. DOTIME, when non-nil, indicates that a
4827 time-of-day should be extracted from TXT for sorting of this entry, and for
4828 the `%t' specifier in the format. When DOTIME is a string, this string is
4829 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4830 only the correctly processes TXT should be returned - this is used by
4831 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4832 Any match of REMOVE-RE will be removed from TXT."
4834 ;; Diary entries sometimes have extra whitespace at the beginning
4835 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4837 ;; Fix the tags part in txt
4838 (setq txt (org-agenda-fix-displayed-tags
4840 org-agenda-show-inherited-tags
4841 org-agenda-hide-tags-regexp))
4842 (let* ((category (or category
4844 (if buffer-file-name
4845 (file-name-sans-extension
4846 (file-name-nondirectory buffer-file-name))
4848 ;; time, tag, effort are needed for the eval of the prefix format
4849 (tag (if tags (nth (1- (length tags)) tags) ""))
4851 (ts (if dotime (concat
4852 (if (stringp dotime) dotime "")
4853 (and org-agenda-search-headline-for-time txt))))
4854 (time-of-day (and dotime (org-get-time-of-day ts)))
4855 stamp plain s0 s1 s2 t1 t2 rtn srp l
4856 duration thecategory)
4857 (and (org-mode-p) buffer-file-name
4858 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4859 (when (and dotime time-of-day)
4860 ;; Extract starting and ending time and move them to prefix
4861 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4862 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4863 (setq s0 (match-string 0 ts)
4864 srp (and stamp (match-end 3))
4865 s1 (match-string (if plain 1 2) ts)
4866 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4868 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4869 ;; them, we might want to remove them there to avoid duplication.
4870 ;; The user can turn this off with a variable.
4871 (if (and org-prefix-has-time
4872 org-agenda-remove-times-when-in-prefix (or stamp plain)
4873 (string-match (concat (regexp-quote s0) " *") txt)
4874 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4875 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4876 (= (match-beginning 0) 0)
4878 (setq txt (replace-match "" nil nil txt))))
4879 ;; Normalize the time(s) to 24 hour
4880 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4881 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4882 ;; Compute the duration
4884 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4885 (string-to-number (substring s1 3)))
4887 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4888 (string-to-number (substring s2 3))))
4889 (org-agenda-default-appointment-duration
4890 (+ t1 org-agenda-default-appointment-duration))
4892 (setq duration (if t2 (- t2 t1)))))
4894 (when (and s1 (not s2) org-agenda-default-appointment-duration
4895 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4896 (let ((m (+ (string-to-number (match-string 2 s1))
4897 (* 60 (string-to-number (match-string 1 s1)))
4898 org-agenda-default-appointment-duration))
4900 (setq h (/ m 60) m (- m (* h 60)))
4901 (setq s2 (format "%02d:%02d" h m))))
4903 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4905 ;; Tags are in the string
4906 (if (or (eq org-agenda-remove-tags t)
4907 (and org-agenda-remove-tags
4908 org-prefix-has-tag))
4909 (setq txt (replace-match "" t t txt))
4910 (setq txt (replace-match
4911 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4912 (match-string 2 txt))
4918 (or (get-text-property 0 'org-hd-marker txt)
4919 (get-text-property 0 'org-marker txt)))
4922 (setq neffort (org-hh:mm-string-to-minutes effort)
4923 effort (setq effort (concat "[" effort "]" )))))
4926 (while (string-match remove-re txt)
4927 (setq txt (replace-match "" t t txt))))
4929 ;; Create the final string
4932 ;; Prepare the variables needed in the eval of the compiled format
4933 (setq time (cond (s2 (concat s1 "-" s2))
4934 (s1 (concat s1 "......"))
4936 extra (or (and (not habitp) extra) "")
4937 category (if (symbolp category) (symbol-name category) category)
4938 thecategory (copy-sequence category))
4939 (if (string-match org-bracket-link-regexp category)
4941 (setq l (if (match-end 3)
4942 (- (match-end 3) (match-beginning 3))
4943 (- (match-end 1) (match-beginning 1))))
4944 (when (< l (or org-prefix-category-length 0))
4945 (setq category (copy-sequence category))
4946 (org-add-props category nil
4947 'extra-space (make-string
4948 (- org-prefix-category-length l 1) ?\ ))))
4949 (if (and org-prefix-category-max-length
4950 (>= (length category) org-prefix-category-max-length))
4951 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4952 ;; Evaluate the compiled format
4953 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4955 ;; And finally add the text properties
4956 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4957 (org-add-props rtn nil
4958 'org-category (if thecategory (downcase thecategory) category)
4959 'tags (mapcar 'org-downcase-keep-props tags)
4960 'org-highest-priority org-highest-priority
4961 'org-lowest-priority org-lowest-priority
4962 'prefix-length (- (length rtn) (length txt))
4963 'time-of-day time-of-day
4966 'effort-minutes neffort
4972 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
4973 "Remove tags string from TXT, and add a modified list of tags.
4974 The modified list may contain inherited tags, and tags matched by
4975 `org-agenda-hide-tags-regexp' will be removed."
4976 (when (or add-inherited hide-re)
4977 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4978 (setq txt (substring txt 0 (match-beginning 0))))
4981 (mapcar (lambda (tg)
4982 (if (or (and hide-re (string-match hide-re tg))
4983 (and (not add-inherited)
4984 (get-text-property 0 'inherited tg)))
4989 (let ((have-i (get-text-property 0 'inherited (car tags)))
4991 (setq txt (concat txt " :"
4994 (setq i (get-text-property 0 'inherited x))
4995 (if (and have-i (not i))
5001 (if have-i "::" ":"))))))
5004 (defun org-downcase-keep-props (s)
5005 (let ((props (text-properties-at 0 s)))
5006 (setq s (downcase s))
5007 (add-text-properties 0 (length s) props s)
5010 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5011 (defvar org-agenda-sorting-strategy-selected nil)
5013 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5015 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5016 ((and todayp (member 'today (car org-agenda-time-grid))))
5017 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5018 ((member 'weekly (car org-agenda-time-grid)))
5019 (t (throw 'exit list)))
5020 (let* ((have (delq nil (mapcar
5021 (lambda (x) (get-text-property 1 'time-of-day x))
5023 (string (nth 1 org-agenda-time-grid))
5024 (gridtimes (nth 2 org-agenda-time-grid))
5025 (req (car org-agenda-time-grid))
5026 (remove (member 'remove-match req))
5028 (if (and (member 'require-timed req) (not have))
5029 ;; don't show empty grid
5031 (while (setq time (pop gridtimes))
5032 (unless (and remove (member time have))
5033 (setq time (int-to-string time))
5034 (push (org-format-agenda-item
5036 (concat (substring time 0 -2) ":" (substring time -2)))
5039 1 (length (car new)) 'face 'org-time-grid (car new))))
5040 (if (member 'time-up org-agenda-sorting-strategy-selected)
5042 (append list new)))))
5044 (defun org-compile-prefix-format (key)
5045 "Compile the prefix format into a Lisp form that can be evaluated.
5046 The resulting form is returned and stored in the variable
5047 `org-prefix-format-compiled'."
5048 (setq org-prefix-has-time nil org-prefix-has-tag nil
5049 org-prefix-category-length nil org-prefix-has-effort nil)
5051 ((stringp org-agenda-prefix-format)
5052 org-agenda-prefix-format)
5053 ((assq key org-agenda-prefix-format)
5054 (cdr (assq key org-agenda-prefix-format)))
5055 (t " %-12:c%?-12t% s")))
5057 varform vars var e c f opt)
5058 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
5060 (setq var (cdr (assoc (match-string 4 s)
5061 '(("c" . category) ("t" . time) ("s" . extra)
5062 ("T" . tag) ("e" . effort))))
5063 c (or (match-string 3 s) "")
5064 opt (match-beginning 1)
5065 start (1+ (match-beginning 0)))
5066 (if (equal var 'time) (setq org-prefix-has-time t))
5067 (if (equal var 'tag) (setq org-prefix-has-tag t))
5068 (if (equal var 'effort) (setq org-prefix-has-effort t))
5069 (setq f (concat "%" (match-string 2 s) "s"))
5070 (when (equal var 'category)
5071 (setq org-prefix-category-length
5072 (floor (abs (string-to-number (match-string 2 s)))))
5073 (setq org-prefix-category-max-length
5074 (let ((x (match-string 2 s)))
5076 (if (string-match "\\.[0-9]+" x)
5077 (string-to-number (substring (match-string 0 x) 1)))))))
5080 `(if (equal "" ,var)
5082 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5083 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
5084 (setq s (replace-match "%s" t nil s))
5085 (push varform vars))
5086 (setq vars (nreverse vars))
5087 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5089 (defun org-set-sorting-strategy (key)
5090 (if (symbolp (car org-agenda-sorting-strategy))
5092 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5093 (setq org-agenda-sorting-strategy-selected
5094 (or (cdr (assq key org-agenda-sorting-strategy))
5095 (cdr (assq 'agenda org-agenda-sorting-strategy))
5096 '(time-up category-keep priority-down)))))
5098 (defun org-get-time-of-day (s &optional string mod24)
5099 "Check string S for a time of day.
5100 If found, return it as a military time number between 0 and 2400.
5101 If not found, return nil.
5102 The optional STRING argument forces conversion into a 5 character wide string
5106 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5107 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5108 (let* ((h (string-to-number (match-string 1 s)))
5109 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5110 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5111 (am-p (equal ampm "am"))
5112 (h1 (cond ((not ampm) h)
5113 ((= h 12) (if am-p 0 12))
5114 (t (+ h (if am-p 0 12)))))
5115 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5117 (t0 (+ (* 100 h2) m))
5118 (t1 (concat (if (>= h1 24) "+" " ")
5119 (if (and org-agenda-time-leading-zero
5120 (< t0 1000)) "0" "")
5121 (if (< t0 100) "0" "")
5122 (if (< t0 10) "0" "")
5123 (int-to-string t0))))
5124 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5126 (defun org-finalize-agenda-entries (list &optional nosort)
5127 "Sort and concatenate the agenda items."
5128 (setq list (mapcar 'org-agenda-highlight-todo list))
5131 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5133 (defun org-agenda-highlight-todo (x)
5134 (let ((org-done-keywords org-done-keywords-for-agenda)
5135 (case-fold-search nil)
5139 (beginning-of-line 1)
5140 (setq re (org-get-at-bol 'org-todo-regexp))
5141 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5142 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5143 (add-text-properties (match-beginning 0) (match-end 1)
5144 (list 'face (org-get-todo-face 1)))
5145 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5146 (delete-region (match-beginning 1) (1- (match-end 0)))
5147 (goto-char (match-beginning 1))
5148 (insert (format org-agenda-todo-keyword-format s)))))
5149 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5150 pl (get-text-property 0 'prefix-length x))
5152 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5154 (add-text-properties
5155 (or (match-end 1) (match-end 0)) (match-end 0)
5156 (list 'face (org-get-todo-face (match-string 2 x)))
5158 (setq x (concat (substring x 0 (match-end 1))
5159 (format org-agenda-todo-keyword-format
5161 (org-add-props " " (text-properties-at 0 x))
5162 (substring x (match-end 3)))))
5165 (defsubst org-cmp-priority (a b)
5166 "Compare the priorities of string A and B."
5167 (let ((pa (or (get-text-property 1 'priority a) 0))
5168 (pb (or (get-text-property 1 'priority b) 0)))
5169 (cond ((> pa pb) +1)
5173 (defsubst org-cmp-effort (a b)
5174 "Compare the priorities of string A and B."
5175 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5176 (ea (or (get-text-property 1 'effort-minutes a) def))
5177 (eb (or (get-text-property 1 'effort-minutes b) def)))
5178 (cond ((> ea eb) +1)
5182 (defsubst org-cmp-category (a b)
5183 "Compare the string values of categories of strings A and B."
5184 (let ((ca (or (get-text-property 1 'org-category a) ""))
5185 (cb (or (get-text-property 1 'org-category b) "")))
5186 (cond ((string-lessp ca cb) -1)
5187 ((string-lessp cb ca) +1)
5190 (defsubst org-cmp-todo-state (a b)
5191 "Compare the todo states of strings A and B."
5192 (let* ((ma (or (get-text-property 1 'org-marker a)
5193 (get-text-property 1 'org-hd-marker a)))
5194 (mb (or (get-text-property 1 'org-marker b)
5195 (get-text-property 1 'org-hd-marker b)))
5196 (fa (and ma (marker-buffer ma)))
5197 (fb (and mb (marker-buffer mb)))
5199 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5200 (and fb (with-current-buffer fb org-todo-keywords-1))))
5201 (ta (or (get-text-property 1 'todo-state a) ""))
5202 (tb (or (get-text-property 1 'todo-state b) ""))
5203 (la (- (length (member ta todo-kwds))))
5204 (lb (- (length (member tb todo-kwds))))
5205 (donepa (member ta org-done-keywords-for-agenda))
5206 (donepb (member tb org-done-keywords-for-agenda)))
5207 (cond ((and donepa (not donepb)) -1)
5208 ((and (not donepa) donepb) +1)
5213 (defsubst org-cmp-tag (a b)
5214 "Compare the string values of the first tags of A and B."
5215 (let ((ta (car (last (get-text-property 1 'tags a))))
5216 (tb (car (last (get-text-property 1 'tags b)))))
5219 ((string-lessp ta tb) -1)
5220 ((string-lessp tb ta) +1)
5223 (defsubst org-cmp-time (a b)
5224 "Compare the time-of-day values of strings A and B."
5225 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5226 (ta (or (get-text-property 1 'time-of-day a) def))
5227 (tb (or (get-text-property 1 'time-of-day b) def)))
5228 (cond ((< ta tb) -1)
5232 (defsubst org-cmp-habit-p (a b)
5233 "Compare the todo states of strings A and B."
5234 (let ((ha (get-text-property 1 'org-habit-p a))
5235 (hb (get-text-property 1 'org-habit-p b)))
5236 (cond ((and ha (not hb)) -1)
5237 ((and (not ha) hb) +1)
5240 (defun org-entries-lessp (a b)
5241 "Predicate for sorting agenda entries."
5242 ;; The following variables will be used when the form is evaluated.
5243 ;; So even though the compiler complains, keep them.
5244 (let* ((time-up (org-cmp-time a b))
5245 (time-down (if time-up (- time-up) nil))
5246 (priority-up (org-cmp-priority a b))
5247 (priority-down (if priority-up (- priority-up) nil))
5248 (effort-up (org-cmp-effort a b))
5249 (effort-down (if effort-up (- effort-up) nil))
5250 (category-up (org-cmp-category a b))
5251 (category-down (if category-up (- category-up) nil))
5252 (category-keep (if category-up +1 nil))
5253 (tag-up (org-cmp-tag a b))
5254 (tag-down (if tag-up (- tag-up) nil))
5255 (todo-state-up (org-cmp-todo-state a b))
5256 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5257 (habit-up (org-cmp-habit-p a b))
5258 (habit-down (if habit-up (- habit-up) nil))
5259 user-defined-up user-defined-down)
5260 (if (and org-agenda-cmp-user-defined
5261 (functionp org-agenda-cmp-user-defined))
5262 (setq user-defined-up
5263 (funcall org-agenda-cmp-user-defined a b)
5264 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5266 (eval (cons 'or org-agenda-sorting-strategy-selected))
5267 '((-1 . t) (1 . nil) (nil . nil))))))
5269 ;;; Agenda restriction lock
5271 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5272 "Overlay to mark the headline to which agenda commands are restricted.")
5273 (overlay-put org-agenda-restriction-lock-overlay
5274 'face 'org-agenda-restriction-lock)
5275 (overlay-put org-agenda-restriction-lock-overlay
5276 'help-echo "Agendas are currently limited to this subtree.")
5277 (org-detach-overlay org-agenda-restriction-lock-overlay)
5279 (defun org-agenda-set-restriction-lock (&optional type)
5280 "Set restriction lock for agenda, to current subtree or file.
5281 Restriction will be the file if TYPE is `file', or if type is the
5282 universal prefix '(4), or if the cursor is before the first headline
5283 in the file. Otherwise, restriction will be to the current subtree."
5285 (and (equal type '(4)) (setq type 'file))
5288 ((org-at-heading-p) 'subtree)
5289 ((condition-case nil (org-back-to-heading t) (error nil))
5292 (if (eq type 'subtree)
5294 (setq org-agenda-restrict t)
5295 (setq org-agenda-overriding-restriction 'subtree)
5296 (put 'org-agenda-files 'org-restrict
5297 (list (buffer-file-name (buffer-base-buffer))))
5298 (org-back-to-heading t)
5299 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5300 (move-marker org-agenda-restrict-begin (point))
5301 (move-marker org-agenda-restrict-end
5302 (save-excursion (org-end-of-subtree t)))
5303 (message "Locking agenda restriction to subtree"))
5304 (put 'org-agenda-files 'org-restrict
5305 (list (buffer-file-name (buffer-base-buffer))))
5306 (setq org-agenda-restrict nil)
5307 (setq org-agenda-overriding-restriction 'file)
5308 (move-marker org-agenda-restrict-begin nil)
5309 (move-marker org-agenda-restrict-end nil)
5310 (message "Locking agenda restriction to file"))
5311 (setq current-prefix-arg nil)
5312 (org-agenda-maybe-redo))
5314 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5315 "Remove the agenda restriction lock."
5317 (org-detach-overlay org-agenda-restriction-lock-overlay)
5318 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5319 (setq org-agenda-overriding-restriction nil)
5320 (setq org-agenda-restrict nil)
5321 (put 'org-agenda-files 'org-restrict nil)
5322 (move-marker org-agenda-restrict-begin nil)
5323 (move-marker org-agenda-restrict-end nil)
5324 (setq current-prefix-arg nil)
5325 (message "Agenda restriction lock removed")
5326 (or noupdate (org-agenda-maybe-redo)))
5328 (defun org-agenda-maybe-redo ()
5329 "If there is any window showing the agenda view, update it."
5330 (let ((w (get-buffer-window org-agenda-buffer-name t))
5331 (w0 (selected-window)))
5336 (if org-agenda-overriding-restriction
5337 (message "Agenda view shifted to new %s restriction"
5338 org-agenda-overriding-restriction)
5339 (message "Agenda restriction lock removed")))))
5343 (defun org-agenda-check-type (error &rest types)
5344 "Check if agenda buffer is of allowed type.
5345 If ERROR is non-nil, throw an error, otherwise just return nil."
5346 (if (memq org-agenda-type types)
5349 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5352 (defun org-agenda-quit ()
5353 "Exit agenda by removing the window or the buffer."
5355 (if org-agenda-columns-active
5357 (let ((buf (current-buffer)))
5358 (if (eq org-agenda-window-setup 'other-frame)
5361 (org-agenda-reset-markers)
5362 (org-columns-remove-overlays)
5363 (setq org-agenda-archives-mode nil)
5365 (and (not (eq org-agenda-window-setup 'current-window))
5366 (not (one-window-p))
5369 (org-agenda-reset-markers)
5370 (org-columns-remove-overlays)
5371 (setq org-agenda-archives-mode nil)))
5372 ;; Maybe restore the pre-agenda window configuration.
5373 (and org-agenda-restore-windows-after-quit
5374 (not (eq org-agenda-window-setup 'other-frame))
5375 org-pre-agenda-window-conf
5376 (set-window-configuration org-pre-agenda-window-conf))))
5378 (defun org-agenda-exit ()
5379 "Exit agenda by removing the window or the buffer.
5380 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5381 Org-mode buffers visited directly by the user will not be touched."
5383 (org-release-buffers org-agenda-new-buffers)
5384 (setq org-agenda-new-buffers nil)
5387 (defun org-agenda-execute (arg)
5388 "Execute another agenda command, keeping same window.\\<global-map>
5389 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5391 (let ((org-agenda-window-setup 'current-window))
5394 (defun org-agenda-redo ()
5396 When this is the global TODO list, a prefix argument will be interpreted."
5398 (let* ((org-agenda-keep-modes t)
5399 (filter org-agenda-filter)
5400 (preset (get 'org-agenda-filter :preset-filter))
5401 (cols org-agenda-columns-active)
5402 (line (org-current-line))
5403 (window-line (- line (org-current-line (window-start))))
5404 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5405 (put 'org-agenda-filter :preset-filter nil)
5406 (and cols (org-columns-quit))
5407 (message "Rebuilding agenda buffer...")
5408 (org-let lprops '(eval org-agenda-redo-command))
5409 (setq org-agenda-undo-list nil
5410 org-agenda-pending-undo-list nil)
5411 (message "Rebuilding agenda buffer...done")
5412 (put 'org-agenda-filter :preset-filter preset)
5413 (and (or filter preset) (org-agenda-filter-apply filter))
5414 (and cols (interactive-p) (org-agenda-columns))
5415 (org-goto-line line)
5416 (recenter window-line)))
5419 (defvar org-global-tags-completion-table nil)
5420 (defvar org-agenda-filter-form nil)
5421 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5422 "Keep only those lines in the agenda buffer that have a specific tag.
5423 The tag is selected with its fast selection letter, as configured.
5424 With prefix argument STRIP, remove all lines that do have the tag.
5425 A lisp caller can specify CHAR. NARROW means that the new tag should be
5426 used to narrow the search - the interactive user can also press `-' or `+'
5427 to switch to narrowing."
5429 (let* ((alist org-tag-alist-for-agenda)
5430 (tag-chars (mapconcat
5431 (lambda (x) (if (and (not (symbolp (car x)))
5433 (char-to-string (cdr x))
5436 (efforts (org-split-string
5437 (or (cdr (assoc (concat org-effort-property "_ALL")
5438 org-global-properties))
5439 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5440 (effort-op org-agenda-filter-effort-default-operator)
5442 (inhibit-read-only t)
5443 (current org-agenda-filter)
5447 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5448 (if narrow "Narrow" "Filter") tag-chars
5449 (if org-agenda-auto-exclude-function "[RET], " ""))
5450 (setq char (read-char)))
5451 (when (member char '(?+ ?-))
5453 (cond ((equal char ?-) (setq strip t narrow t))
5454 ((equal char ?+) (setq strip nil narrow t)))
5456 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5457 (setq char (read-char)))
5458 (when (member char '(?< ?> ?= ??))
5459 ;; An effort operator
5460 (setq effort-op (char-to-string char))
5461 (setq alist nil) ; to make sure it will be interpreted as effort.
5462 (unless (equal char ??)
5463 (loop for i from 0 to 9 do
5467 (if (= i 9) "0" (int-to-string (1+ i)))
5468 "]" (nth i efforts))))
5469 (message "Effort%s: %s " effort-op effort-prompt)
5470 (setq char (read-char))
5471 (when (or (< char ?0) (> char ?9))
5472 (error "Need 1-9,0 to select effort" ))))
5473 (when (equal char ?\t)
5474 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5475 (org-set-local 'org-global-tags-completion-table
5476 (org-global-tags-completion-table)))
5477 (let ((completion-ignore-case t))
5478 (setq tag (org-icompleting-read
5479 "Tag: " org-global-tags-completion-table))))
5482 (org-agenda-filter-by-tag-show-all)
5483 (when org-agenda-auto-exclude-function
5484 (setq org-agenda-filter '())
5485 (dolist (tag (org-agenda-get-represented-tags))
5486 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5488 (push modifier org-agenda-filter))))
5489 (if (not (null org-agenda-filter))
5490 (org-agenda-filter-apply org-agenda-filter))))
5492 (org-agenda-filter-by-tag-show-all)
5493 (when (get 'org-agenda-filter :preset-filter)
5494 (org-agenda-filter-apply org-agenda-filter)))
5495 ((or (equal char ?\ )
5496 (setq a (rassoc char alist))
5497 (and (>= char ?0) (<= char ?9)
5498 (setq n (if (= char ?0) 9 (- char ?0 1))
5499 tag (concat effort-op (nth n efforts))
5504 (and tag (setq a (cons tag nil))))
5505 (org-agenda-filter-by-tag-show-all)
5507 (setq org-agenda-filter
5508 (cons (concat (if strip "-" "+") tag)
5509 (if narrow current nil)))
5510 (org-agenda-filter-apply org-agenda-filter))
5511 (t (error "Invalid tag selection character %c" char)))))
5513 (defun org-agenda-get-represented-tags ()
5514 "Get a list of all tags currently represented in the agenda."
5517 (goto-char (point-min))
5518 (while (setq p (next-single-property-change (point) 'tags))
5520 (mapc (lambda (x) (add-to-list 'tags x))
5521 (get-text-property (point) 'tags))))
5524 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5525 "Refine the current filter. See `org-agenda-filter-by-tag."
5527 (org-agenda-filter-by-tag strip char 'refine))
5529 (defun org-agenda-filter-make-matcher ()
5530 "Create the form that tests a line for the agenda filter."
5532 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5534 (if (member x '("-" "+"))
5535 (setq f1 (if (equal x "-") 'tags '(not tags)))
5536 (if (string-match "[<=>?]" x)
5537 (setq f1 (org-agenda-filter-effort-form x))
5538 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5539 (if (equal (string-to-char x) ?-)
5540 (setq f1 (list 'not f1))))
5542 (cons 'and (nreverse f))))
5544 (defun org-agenda-filter-effort-form (e)
5545 "Return the form to compare the effort of the current line with what E says.
5546 E looks line \"+<2:25\"."
5548 (setq e (substring e 1))
5549 (setq op (string-to-char e) e (substring e 1))
5550 (setq op (cond ((equal op ?<) '<=)
5554 (list 'org-agenda-compare-effort (list 'quote op)
5555 (org-hh:mm-string-to-minutes e))))
5557 (defun org-agenda-compare-effort (op value)
5558 "Compare the effort of the current line with VALUE, using OP.
5559 If the line does not have an effort defined, return nil."
5560 (let ((eff (org-get-at-bol 'effort-minutes)))
5563 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5566 (defun org-agenda-filter-apply (filter)
5567 "Set FILTER as the new agenda filter and apply it."
5569 (setq org-agenda-filter filter
5570 org-agenda-filter-form (org-agenda-filter-make-matcher))
5571 (org-agenda-set-mode-name)
5573 (goto-char (point-min))
5575 (if (org-get-at-bol 'org-marker)
5577 (setq tags (org-get-at-bol 'tags)) ; used in eval
5578 (if (not (eval org-agenda-filter-form))
5579 (org-agenda-filter-by-tag-hide-line))
5580 (beginning-of-line 2))
5581 (beginning-of-line 2))))))
5583 (defun org-agenda-filter-by-tag-hide-line ()
5585 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
5587 (overlay-put ov 'invisible t)
5588 (overlay-put ov 'type 'tags-filter)
5589 (push ov org-agenda-filter-overlays)))
5591 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5592 (setq pos (or pos (point)))
5594 (dolist (ov (overlays-at pos))
5595 (when (and (overlay-get ov 'invisible)
5596 (eq (overlay-get ov 'type) 'tags-filter))
5598 (if (< (overlay-start ov) (point-at-eol))
5599 (move-overlay ov (point-at-eol)
5600 (overlay-end ov)))))))
5602 (defun org-agenda-filter-by-tag-show-all ()
5603 (mapc 'delete-overlay org-agenda-filter-overlays)
5604 (setq org-agenda-filter-overlays nil)
5605 (setq org-agenda-filter nil)
5606 (setq org-agenda-filter-form nil)
5607 (org-agenda-set-mode-name))
5609 (defun org-agenda-manipulate-query-add ()
5610 "Manipulate the query by adding a search term with positive selection.
5611 Positive selection means the term must be matched for selection of an entry."
5613 (org-agenda-manipulate-query ?\[))
5614 (defun org-agenda-manipulate-query-subtract ()
5615 "Manipulate the query by adding a search term with negative selection.
5616 Negative selection means term must not be matched for selection of an entry."
5618 (org-agenda-manipulate-query ?\]))
5619 (defun org-agenda-manipulate-query-add-re ()
5620 "Manipulate the query by adding a search regexp with positive selection.
5621 Positive selection means the regexp must match for selection of an entry."
5623 (org-agenda-manipulate-query ?\{))
5624 (defun org-agenda-manipulate-query-subtract-re ()
5625 "Manipulate the query by adding a search regexp with negative selection.
5626 Negative selection means regexp must not match for selection of an entry."
5628 (org-agenda-manipulate-query ?\}))
5629 (defun org-agenda-manipulate-query (char)
5631 ((memq org-agenda-type '(timeline agenda))
5632 (let ((org-agenda-include-inactive-timestamps t))
5634 (message "Display now includes inactive timestamps as well"))
5635 ((eq org-agenda-type 'search)
5637 'org-agenda-query-string
5638 (if org-agenda-last-search-view-search-was-boolean
5639 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5640 (?\{ . " +{}") (?\} . " -{}"))))
5642 (setq org-agenda-redo-command
5643 (list 'org-search-view
5645 org-agenda-query-string
5646 (+ (length org-agenda-query-string)
5647 (if (member char '(?\{ ?\})) 0 1))))
5648 (set-register org-agenda-query-register org-agenda-query-string)
5650 (t (error "Cannot manipulate query for %s-type agenda buffers"
5653 (defun org-add-to-string (var string)
5654 (set var (concat (symbol-value var) string)))
5656 (defun org-agenda-goto-date (date)
5657 "Jump to DATE in agenda."
5658 (interactive (list (org-read-date)))
5659 (org-agenda-list nil date))
5661 (defun org-agenda-goto-today ()
5664 (org-agenda-check-type t 'timeline 'agenda)
5665 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5667 (tdpos (goto-char tdpos))
5668 ((eq org-agenda-type 'agenda)
5669 (let* ((sd (time-to-days
5670 (time-subtract (current-time)
5671 (list 0 (* 3600 org-extend-today-until) 0))))
5672 (comp (org-agenda-compute-time-span sd org-agenda-span))
5673 (org-agenda-overriding-arguments org-agenda-last-arguments))
5674 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5675 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5677 (org-agenda-find-same-or-today-or-agenda)))
5678 (t (error "Cannot find today")))))
5680 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5682 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5683 (text-property-any (point-min) (point-max) 'org-today t)
5684 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5687 (defun org-agenda-later (arg)
5688 "Go forward in time by thee current span.
5689 With prefix ARG, go forward that many times the current span."
5691 (org-agenda-check-type t 'agenda)
5692 (let* ((span org-agenda-span)
5693 (sd org-starting-day)
5694 (greg (calendar-gregorian-from-absolute sd))
5695 (cnt (org-get-at-bol 'org-day-cnt))
5699 (setq sd (+ arg sd) nd 1))
5701 (setq sd (+ (* 7 arg) sd) nd 7))
5703 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5704 sd (calendar-absolute-from-gregorian greg2))
5705 (setcar greg2 (1+ (car greg2)))
5706 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5708 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5709 sd (calendar-absolute-from-gregorian greg2))
5710 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5711 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5712 (let ((org-agenda-overriding-arguments
5713 (list (car org-agenda-last-arguments) sd nd t)))
5715 (org-agenda-find-same-or-today-or-agenda cnt))))
5717 (defun org-agenda-earlier (arg)
5718 "Go backward in time by the current span.
5719 With prefix ARG, go backward that many times the current span."
5721 (org-agenda-later (- arg)))
5723 (defun org-agenda-view-mode-dispatch ()
5724 "Call one of the view mode commands."
5726 (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
5727 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
5728 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
5729 (let ((a (read-char-exclusive)))
5731 (?d (call-interactively 'org-agenda-day-view))
5732 (?w (call-interactively 'org-agenda-week-view))
5733 (?m (call-interactively 'org-agenda-month-view))
5734 (?y (call-interactively 'org-agenda-year-view))
5735 (?l (call-interactively 'org-agenda-log-mode))
5736 (?L (org-agenda-log-mode '(4)))
5737 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5738 (?a (call-interactively 'org-agenda-archives-mode))
5739 (?A (org-agenda-archives-mode 'files))
5740 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5741 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5742 (?G (call-interactively 'org-agenda-toggle-time-grid))
5743 (?D (call-interactively 'org-agenda-toggle-diary))
5744 (?\! (call-interactively 'org-agenda-toggle-deadlines))
5745 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5746 (org-agenda-check-type t 'timeline 'agenda)
5748 (message "Display now includes inactive timestamps as well"))
5749 (?q (message "Abort"))
5750 (otherwise (error "Invalid key" )))))
5752 (defun org-agenda-day-view (&optional day-of-year)
5753 "Switch to daily view for agenda.
5754 With argument DAY-OF-YEAR, switch to that day of the year."
5756 (setq org-agenda-ndays 1)
5757 (org-agenda-change-time-span 'day day-of-year))
5758 (defun org-agenda-week-view (&optional iso-week)
5759 "Switch to daily view for agenda.
5760 With argument ISO-WEEK, switch to the corresponding ISO week.
5761 If ISO-WEEK has more then 2 digits, only the last two encode the
5762 week. Any digits before this encode a year. So 200712 means
5763 week 12 of year 2007. Years in the range 1938-2037 can also be
5764 written as 2-digit years."
5766 (setq org-agenda-ndays 7)
5767 (org-agenda-change-time-span 'week iso-week))
5768 (defun org-agenda-month-view (&optional month)
5769 "Switch to monthly view for agenda.
5770 With argument MONTH, switch to that month."
5772 (org-agenda-change-time-span 'month month))
5773 (defun org-agenda-year-view (&optional year)
5774 "Switch to yearly view for agenda.
5775 With argument YEAR, switch to that year.
5776 If MONTH has more then 2 digits, only the last two encode the
5777 month. Any digits before this encode a year. So 200712 means
5778 December year 2007. Years in the range 1938-2037 can also be
5779 written as 2-digit years."
5782 (setq year (org-small-year-to-year year)))
5783 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5784 (org-agenda-change-time-span 'year year)
5787 (defun org-agenda-change-time-span (span &optional n)
5788 "Change the agenda view to SPAN.
5789 SPAN may be `day', `week', `month', `year'."
5790 (org-agenda-check-type t 'agenda)
5791 (if (and (not n) (equal org-agenda-span span))
5792 (error "Viewing span is already \"%s\"" span))
5793 (let* ((sd (or (org-get-at-bol 'day)
5795 (computed (org-agenda-compute-time-span sd span n))
5796 (org-agenda-overriding-arguments
5797 (list (car org-agenda-last-arguments)
5798 (car computed) (cdr computed) t)))
5800 (org-agenda-find-same-or-today-or-agenda))
5801 (org-agenda-set-mode-name)
5802 (message "Switched to %s view" span))
5804 (defun org-agenda-compute-time-span (sd span &optional n)
5805 "Compute starting date and number of days for agenda.
5806 SPAN may be `day', `week', `month', `year'. The return value
5807 is a cons cell with the starting date and the number of days,
5808 so that the date SD will be in that range."
5809 (let* ((greg (calendar-gregorian-from-absolute sd))
5813 nd w1 y1 m1 thisweek)
5817 (setq sd (+ (calendar-absolute-from-gregorian
5822 (let* ((nt (calendar-day-of-week
5823 (calendar-gregorian-from-absolute sd)))
5824 (d (if org-agenda-start-on-weekday
5825 (- nt org-agenda-start-on-weekday)
5827 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5830 (setq thisweek (car (calendar-iso-from-absolute sd)))
5832 (setq y1 (org-small-year-to-year (/ n 100))
5835 (calendar-absolute-from-iso
5837 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5840 (when (and n (> n 99))
5841 (setq y1 (org-small-year-to-year (/ n 100))
5843 (setq sd (calendar-absolute-from-gregorian
5844 (list (or n mg) 1 (or y1 yg)))
5845 nd (- (calendar-absolute-from-gregorian
5846 (list (1+ (or n mg)) 1 (or y1 yg)))
5849 (setq sd (calendar-absolute-from-gregorian
5850 (list 1 1 (or n yg)))
5851 nd (- (calendar-absolute-from-gregorian
5852 (list 1 1 (1+ (or n yg))))
5856 (defun org-agenda-next-date-line (&optional arg)
5857 "Jump to the next line indicating a date in agenda buffer."
5859 (org-agenda-check-type t 'agenda 'timeline)
5860 (beginning-of-line 1)
5861 ;; This does not work if user makes date format that starts with a blank
5862 (if (looking-at "^\\S-") (forward-char 1))
5863 (if (not (re-search-forward "^\\S-" nil t arg))
5866 (error "No next date after this line in this buffer")))
5867 (goto-char (match-beginning 0)))
5869 (defun org-agenda-previous-date-line (&optional arg)
5870 "Jump to the previous line indicating a date in agenda buffer."
5872 (org-agenda-check-type t 'agenda 'timeline)
5873 (beginning-of-line 1)
5874 (if (not (re-search-backward "^\\S-" nil t arg))
5875 (error "No previous date before this line in this buffer")))
5877 ;; Initialize the highlight
5878 (defvar org-hl (make-overlay 1 1))
5879 (overlay-put org-hl 'face 'highlight)
5881 (defun org-highlight (begin end &optional buffer)
5882 "Highlight a region with overlay."
5883 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5884 org-hl begin end (or buffer (current-buffer))))
5886 (defun org-unhighlight ()
5887 "Detach overlay INDEX."
5888 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5890 ;; FIXME this is currently not used.
5891 (defun org-highlight-until-next-command (beg end &optional buffer)
5892 "Move the highlight overlay to BEG/END, remove it before the next command."
5893 (org-highlight beg end buffer)
5894 (add-hook 'pre-command-hook 'org-unhighlight-once))
5895 (defun org-unhighlight-once ()
5896 "Remove the highlight from its position, and this function from the hook."
5897 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5900 (defun org-agenda-follow-mode ()
5901 "Toggle follow mode in an agenda buffer."
5903 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5904 (org-agenda-set-mode-name)
5905 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5907 (message "Follow mode is %s"
5908 (if org-agenda-follow-mode "on" "off")))
5910 (defun org-agenda-entry-text-mode (&optional arg)
5911 "Toggle entry text mode in an agenda buffer."
5914 (setq org-agenda-entry-text-mode t)
5915 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5916 (org-agenda-entry-text-hide)
5917 (and org-agenda-entry-text-mode
5918 (let ((org-agenda-entry-text-maxlines
5919 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5920 (org-agenda-entry-text-show)))
5921 (org-agenda-set-mode-name)
5922 (message "Entry text mode is %s. Maximum number of lines is %d"
5923 (if org-agenda-entry-text-mode "on" "off")
5924 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5926 (defun org-agenda-clockreport-mode ()
5927 "Toggle clocktable mode in an agenda buffer."
5929 (org-agenda-check-type t 'agenda)
5930 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5931 (org-agenda-set-mode-name)
5933 (message "Clocktable mode is %s"
5934 (if org-agenda-clockreport-mode "on" "off")))
5936 (defun org-agenda-log-mode (&optional special)
5937 "Toggle log mode in an agenda buffer.
5938 With argument SPECIAL, show all possible log items, not only the ones
5939 configured in `org-agenda-log-mode-items'.
5940 With a double `C-u' prefix arg, show *only* log items, nothing else."
5942 (org-agenda-check-type t 'agenda 'timeline)
5943 (setq org-agenda-show-log
5944 (if (equal special '(16))
5946 (if special '(closed clock state)
5947 (not org-agenda-show-log))))
5948 (org-agenda-set-mode-name)
5950 (message "Log mode is %s"
5951 (if org-agenda-show-log "on" "off")))
5953 (defun org-agenda-archives-mode (&optional with-files)
5954 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5955 When called with a prefix argument, include all archive files as well."
5957 (setq org-agenda-archives-mode
5958 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5959 (org-agenda-set-mode-name)
5964 ((eq org-agenda-archives-mode nil)
5965 "No archives are included")
5966 ((eq org-agenda-archives-mode 'trees)
5967 (format "Trees with :%s: tag are included" org-archive-tag))
5968 ((eq org-agenda-archives-mode t)
5969 (format "Trees with :%s: tag and all active archive files are included"
5970 org-archive-tag)))))
5972 (defun org-agenda-toggle-diary ()
5973 "Toggle diary inclusion in an agenda buffer."
5975 (org-agenda-check-type t 'agenda)
5976 (setq org-agenda-include-diary (not org-agenda-include-diary))
5978 (org-agenda-set-mode-name)
5979 (message "Diary inclusion turned %s"
5980 (if org-agenda-include-diary "on" "off")))
5982 (defun org-agenda-toggle-deadlines ()
5983 "Toggle diary inclusion in an agenda buffer."
5985 (org-agenda-check-type t 'agenda)
5986 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
5988 (org-agenda-set-mode-name)
5989 (message "Deadlines inclusion turned %s"
5990 (if org-agenda-include-deadlines "on" "off")))
5992 (defun org-agenda-toggle-time-grid ()
5993 "Toggle time grid in an agenda buffer."
5995 (org-agenda-check-type t 'agenda)
5996 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5998 (org-agenda-set-mode-name)
5999 (message "Time-grid turned %s"
6000 (if org-agenda-use-time-grid "on" "off")))
6002 (defun org-agenda-set-mode-name ()
6003 "Set the mode name to indicate all the small mode settings."
6005 (concat "Org-Agenda"
6006 (if (get 'org-agenda-files 'org-restrict) " []" "")
6007 (if (equal org-agenda-ndays 1) " Day" "")
6008 (if (equal org-agenda-ndays 7) " Week" "")
6009 (if org-agenda-follow-mode " Follow" "")
6010 (if org-agenda-entry-text-mode " ETxt" "")
6011 (if org-agenda-include-diary " Diary" "")
6012 (if org-agenda-include-deadlines " Ddl" "")
6013 (if org-agenda-use-time-grid " Grid" "")
6014 (if (and (boundp 'org-habit-show-habits)
6015 org-habit-show-habits) " Habit" "")
6016 (if (consp org-agenda-show-log) " LogAll"
6017 (if org-agenda-show-log " Log" ""))
6018 (if (or org-agenda-filter (get 'org-agenda-filter
6020 (concat " {" (mapconcat
6022 (append (get 'org-agenda-filter
6024 org-agenda-filter) "") "}")
6026 (if org-agenda-archives-mode
6027 (if (eq org-agenda-archives-mode t)
6029 (format " :%s:" org-archive-tag))
6031 (if org-agenda-clockreport-mode " Clock" "")))
6032 (force-mode-line-update))
6034 (defun org-agenda-post-command-hook ()
6035 (setq org-agenda-type
6036 (or (get-text-property (point) 'org-agenda-type)
6037 (get-text-property (max (point-min) (1- (point)))
6038 'org-agenda-type))))
6040 (defun org-agenda-next-line ()
6041 "Move cursor to the next line, and show if follow-mode is active."
6043 (call-interactively 'next-line)
6044 (org-agenda-do-context-action))
6046 (defun org-agenda-previous-line ()
6047 "Move cursor to the previous line, and show if follow-mode is active."
6050 (call-interactively 'previous-line)
6051 (org-agenda-do-context-action))
6053 (defun org-agenda-do-context-action ()
6054 "Show outline path and, maybe, follow-mode window."
6055 (let ((m (org-get-at-bol 'org-marker)))
6056 (if (and org-agenda-follow-mode m)
6058 (if (and m org-agenda-show-outline-path)
6059 (org-with-point-at m
6060 (org-display-outline-path t)))))
6062 (defun org-agenda-show-priority ()
6063 "Show the priority of the current item.
6064 This priority is composed of the main priority given with the [#A] cookies,
6065 and by additional input from the age of a schedules or deadline entry."
6067 (let* ((pri (org-get-at-bol 'priority)))
6068 (message "Priority is %d" (if pri pri -1000))))
6070 (defun org-agenda-show-tags ()
6071 "Show the tags applicable to the current item."
6073 (let* ((tags (org-get-at-bol 'tags)))
6075 (message "Tags are :%s:"
6076 (org-no-properties (mapconcat 'identity tags ":")))
6077 (message "No tags associated with this line"))))
6079 (defun org-agenda-goto (&optional highlight)
6080 "Go to the Org-mode file which contains the item at point."
6082 (let* ((marker (or (org-get-at-bol 'org-marker)
6083 (org-agenda-error)))
6084 (buffer (marker-buffer marker))
6085 (pos (marker-position marker)))
6086 (switch-to-buffer-other-window buffer)
6090 (org-show-context 'agenda)
6092 (and (outline-next-heading)
6093 (org-flag-heading nil)))) ; show the next heading
6094 (recenter (/ (window-height) 2))
6095 (run-hooks 'org-agenda-after-show-hook)
6096 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6098 (defvar org-agenda-after-show-hook nil
6099 "Normal hook run after an item has been shown from the agenda.
6100 Point is in the buffer where the item originated.")
6102 (defun org-agenda-kill ()
6103 "Kill the entry or subtree belonging to the current agenda entry."
6105 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6106 (let* ((marker (or (org-get-at-bol 'org-marker)
6107 (org-agenda-error)))
6108 (buffer (marker-buffer marker))
6109 (pos (marker-position marker))
6110 (type (org-get-at-bol 'type))
6111 dbeg dend (n 0) conf)
6112 (org-with-remote-undo buffer
6113 (with-current-buffer buffer
6116 (if (and (org-mode-p) (not (member type '("sexp"))))
6117 (setq dbeg (progn (org-back-to-heading t) (point))
6118 dend (org-end-of-subtree t t))
6119 (setq dbeg (point-at-bol)
6120 dend (min (point-max) (1+ (point-at-eol)))))
6122 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6123 (setq conf (or (eq t org-agenda-confirm-kill)
6124 (and (numberp org-agenda-confirm-kill)
6125 (> n org-agenda-confirm-kill))))
6128 (format "Delete entry with %d lines in buffer \"%s\"? "
6129 n (buffer-name buffer))))
6131 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6132 (with-current-buffer buffer (delete-region dbeg dend))
6133 (message "Agenda item and source killed"))))
6135 (defvar org-archive-default-command)
6136 (defun org-agenda-archive-default ()
6137 "Archive the entry or subtree belonging to the current agenda entry."
6139 (require 'org-archive)
6140 (org-agenda-archive-with org-archive-default-command))
6142 (defun org-agenda-archive-default-with-confirmation ()
6143 "Archive the entry or subtree belonging to the current agenda entry."
6145 (require 'org-archive)
6146 (org-agenda-archive-with org-archive-default-command 'confirm))
6148 (defun org-agenda-archive ()
6149 "Archive the entry or subtree belonging to the current agenda entry."
6151 (org-agenda-archive-with 'org-archive-subtree))
6153 (defun org-agenda-archive-to-archive-sibling ()
6154 "Move the entry to the archive sibling."
6156 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6158 (defun org-agenda-archive-with (cmd &optional confirm)
6159 "Move the entry to the archive sibling."
6161 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6162 (let* ((marker (or (org-get-at-bol 'org-marker)
6163 (org-agenda-error)))
6164 (buffer (marker-buffer marker))
6165 (pos (marker-position marker)))
6166 (org-with-remote-undo buffer
6167 (with-current-buffer buffer
6170 (not (y-or-n-p "Archive this subtree or entry? ")))
6174 (org-remove-subtree-entries-from-agenda)
6175 (org-back-to-heading t)
6177 (error "Archiving works only in Org-mode files"))))))
6179 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6180 "Remove all lines in the agenda that correspond to a given subtree.
6181 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6182 If this information is not given, the function uses the tree at point."
6183 (let ((buf (or buf (current-buffer))) m p)
6185 (unless (and beg end)
6186 (org-back-to-heading t)
6188 (org-end-of-subtree t)
6190 (set-buffer (get-buffer org-agenda-buffer-name))
6192 (goto-char (point-max))
6193 (beginning-of-line 1)
6195 (when (and (setq m (org-get-at-bol 'org-marker))
6196 (equal buf (marker-buffer m))
6197 (setq p (marker-position m))
6200 (let ((inhibit-read-only t))
6201 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6202 (beginning-of-line 0))))))
6204 (defun org-agenda-refile (&optional goto rfloc)
6205 "Refile the item at point."
6207 (if (equal goto '(16))
6208 (org-refile-goto-last-stored)
6209 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6210 (org-agenda-error)))
6211 (buffer (marker-buffer marker))
6212 (pos (marker-position marker))
6214 (org-refile-get-location
6215 (if goto "Goto: " "Refile to: ") buffer
6216 org-refile-allow-creating-parent-nodes))))
6217 (with-current-buffer buffer
6222 (org-remove-subtree-entries-from-agenda)
6223 (org-refile goto buffer rfloc)))))))
6225 (defun org-agenda-open-link (&optional arg)
6226 "Follow the link in the current line, if any.
6227 This looks for a link in the displayed line in the agenda. It also looks
6228 at the text of the entry itself."
6230 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6231 (org-get-at-bol 'org-marker)))
6232 (buffer (and marker (marker-buffer marker)))
6233 (prefix (buffer-substring
6236 (or (org-get-at-bol 'prefix-length) 0)))))
6239 (with-current-buffer buffer
6244 (org-offer-links-in-entry arg prefix)))))
6245 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6247 (beginning-of-line 1)
6248 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6249 (org-open-link-from-string (match-string 1)))
6250 (t (error "No link to open here")))))
6252 (defun org-agenda-copy-local-variable (var)
6253 "Get a variable from a referenced buffer and install it here."
6254 (let ((m (org-get-at-bol 'org-marker)))
6255 (when (and m (buffer-live-p (marker-buffer m)))
6256 (org-set-local var (with-current-buffer (marker-buffer m)
6257 (symbol-value var))))))
6259 (defun org-agenda-switch-to (&optional delete-other-windows)
6260 "Go to the Org-mode file which contains the item at point."
6262 (if (and org-return-follows-link
6263 (not (org-get-at-bol 'org-marker))
6264 (org-in-regexp org-bracket-link-regexp))
6265 (org-open-link-from-string (match-string 0))
6266 (let* ((marker (or (org-get-at-bol 'org-marker)
6267 (org-agenda-error)))
6268 (buffer (marker-buffer marker))
6269 (pos (marker-position marker)))
6270 (switch-to-buffer buffer)
6271 (and delete-other-windows (delete-other-windows))
6275 (org-show-context 'agenda)
6277 (and (outline-next-heading)
6278 (org-flag-heading nil))))))) ; show the next heading
6280 (defun org-agenda-goto-mouse (ev)
6281 "Go to the Org-mode file which contains the item at the mouse click."
6283 (mouse-set-point ev)
6286 (defun org-agenda-show (&optional full-entry)
6287 "Display the Org-mode file which contains the item at point.
6288 With prefix argument FULL-ENTRY, make the entire entry visible
6289 if it was hidden in the outline."
6291 (let ((win (selected-window)))
6293 (let ((org-show-entry-below t))
6294 (org-agenda-goto t))
6295 (org-agenda-goto t))
6296 (select-window win)))
6298 (defvar org-agenda-show-window nil)
6299 (defun org-agenda-show-and-scroll-up ()
6300 "Display the Org-mode file which contains the item at point.
6301 When called repeatedly, scroll the window that is displaying the buffer."
6303 (let ((win (selected-window)))
6304 (if (and (window-live-p org-agenda-show-window)
6305 (eq this-command last-command))
6307 (select-window org-agenda-show-window)
6308 (ignore-errors (scroll-up)))
6311 (setq org-agenda-show-window (selected-window)))
6312 (select-window win)))
6314 (defun org-agenda-show-scroll-down ()
6315 "Scroll down the window showing the agenda."
6317 (let ((win (selected-window)))
6318 (when (window-live-p org-agenda-show-window)
6319 (select-window org-agenda-show-window)
6320 (ignore-errors (scroll-down))
6321 (select-window win))))
6323 (defun org-agenda-show-1 (&optional more)
6324 "Display the Org-mode file which contains the item at point.
6325 The prefix arg selects the amount of information to display:
6328 1 just show the entry according to defaults.
6329 2 show the children view
6330 3 show the subtree view
6331 4 show the entire subtree and any LOGBOOK drawers
6332 5 show the entire subtree and any drawers
6333 With prefix argument FULL-ENTRY, make the entire entry visible
6334 if it was hidden in the outline."
6336 (let ((win (selected-window)))
6338 (org-recenter-heading 1)
6343 (org-back-to-heading)
6344 (run-hook-with-args 'org-cycle-hook 'folded))
6345 (message "Remote: FOLDED"))
6346 ((and (interactive-p) (= more 1))
6347 (message "Remote: show with default settings"))
6352 (org-back-to-heading)
6353 (run-hook-with-args 'org-cycle-hook 'children))
6354 (message "Remote: CHILDREN"))
6358 (org-back-to-heading)
6359 (run-hook-with-args 'org-cycle-hook 'subtree))
6360 (message "Remote: SUBTREE"))
6362 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6364 (concat "^[ \t]*:\\("
6365 (mapconcat 'regexp-quote org-drawers "\\|")
6369 (org-back-to-heading)
6370 (org-cycle-hide-drawers 'subtree)))
6371 (message "Remote: SUBTREE AND LOGBOOK"))
6374 (message "Remote: SUBTREE AND ALL DRAWERS")))
6375 (select-window win)))
6377 (defun org-recenter-heading (n)
6379 (org-back-to-heading)
6382 (defvar org-agenda-cycle-counter nil)
6383 (defun org-agenda-cycle-show (&optional n)
6384 "Show the current entry in another window, with default settings.
6385 Default settings are taken from `org-show-hierarchy-above' and siblings.
6386 When use repeatedly in immediate succession, the remote entry will cycle
6389 children -> subtree -> folded
6391 When called with a numeric prefix arg, that arg will be passed through to
6392 `org-agenda-show-1'. For the interpretation of that argument, see the
6393 docstring of `org-agenda-show-1'."
6396 (setq org-agenda-cycle-counter n)
6397 (if (not (eq last-command this-command))
6398 (setq org-agenda-cycle-counter 1)
6399 (if (equal org-agenda-cycle-counter 0)
6400 (setq org-agenda-cycle-counter 2)
6401 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6402 (if (> org-agenda-cycle-counter 3)
6403 (setq org-agenda-cycle-counter 0)))))
6404 (org-agenda-show-1 org-agenda-cycle-counter))
6406 (defun org-agenda-recenter (arg)
6407 "Display the Org-mode file which contains the item at point and recenter."
6409 (let ((win (selected-window)))
6412 (select-window win)))
6414 (defun org-agenda-show-mouse (ev)
6415 "Display the Org-mode file which contains the item at the mouse click."
6417 (mouse-set-point ev)
6420 (defun org-agenda-check-no-diary ()
6421 "Check if the entry is a diary link and abort if yes."
6422 (if (org-get-at-bol 'org-agenda-diary-link)
6423 (org-agenda-error)))
6425 (defun org-agenda-error ()
6426 (error "Command not allowed in this line"))
6428 (defun org-agenda-tree-to-indirect-buffer ()
6429 "Show the subtree corresponding to the current entry in an indirect buffer.
6430 This calls the command `org-tree-to-indirect-buffer' from the original
6432 With numerical prefix arg ARG, go up to this level and then take that tree.
6433 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6436 (org-agenda-check-no-diary)
6437 (let* ((marker (or (org-get-at-bol 'org-marker)
6438 (org-agenda-error)))
6439 (buffer (marker-buffer marker))
6440 (pos (marker-position marker)))
6441 (with-current-buffer buffer
6444 (call-interactively 'org-tree-to-indirect-buffer)))))
6446 (defvar org-last-heading-marker (make-marker)
6447 "Marker pointing to the headline that last changed its TODO state
6448 by a remote command from the agenda.")
6450 (defun org-agenda-todo-nextset ()
6451 "Switch TODO entry to next sequence."
6453 (org-agenda-todo 'nextset))
6455 (defun org-agenda-todo-previousset ()
6456 "Switch TODO entry to previous sequence."
6458 (org-agenda-todo 'previousset))
6460 (defun org-agenda-todo (&optional arg)
6461 "Cycle TODO state of line at point, also in Org-mode file.
6462 This changes the line at point, all other lines in the agenda referring to
6463 the same tree node, and the headline of the tree node in the Org-mode file."
6465 (org-agenda-check-no-diary)
6466 (let* ((col (current-column))
6467 (marker (or (org-get-at-bol 'org-marker)
6468 (org-agenda-error)))
6469 (buffer (marker-buffer marker))
6470 (pos (marker-position marker))
6471 (hdmarker (org-get-at-bol 'org-hd-marker))
6472 (todayp (equal (org-get-at-bol 'day)
6473 (time-to-days (current-time))))
6474 (inhibit-read-only t)
6475 org-agenda-headline-snapshot-before-repeat newhead just-one)
6476 (org-with-remote-undo buffer
6477 (with-current-buffer buffer
6480 (org-show-context 'agenda)
6482 (and (outline-next-heading)
6483 (org-flag-heading nil))) ; show the next heading
6484 (let ((current-prefix-arg arg))
6485 (call-interactively 'org-todo))
6486 (and (bolp) (forward-char 1))
6487 (setq newhead (org-get-heading))
6488 (when (and (org-bound-and-true-p
6489 org-agenda-headline-snapshot-before-repeat)
6490 (not (equal org-agenda-headline-snapshot-before-repeat
6493 (setq newhead org-agenda-headline-snapshot-before-repeat
6496 (org-back-to-heading)
6497 (move-marker org-last-heading-marker (point))))
6498 (beginning-of-line 1)
6500 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6501 (org-move-to-column col))))
6503 (defun org-agenda-add-note (&optional arg)
6504 "Add a time-stamped note to the entry at point."
6506 (org-agenda-check-no-diary)
6507 (let* ((marker (or (org-get-at-bol 'org-marker)
6508 (org-agenda-error)))
6509 (buffer (marker-buffer marker))
6510 (pos (marker-position marker))
6511 (hdmarker (org-get-at-bol 'org-hd-marker))
6512 (inhibit-read-only t))
6513 (with-current-buffer buffer
6516 (org-show-context 'agenda)
6518 (and (outline-next-heading)
6519 (org-flag-heading nil))) ; show the next heading
6522 (defun org-agenda-change-all-lines (newhead hdmarker
6523 &optional fixface just-this)
6524 "Change all lines in the agenda buffer which match HDMARKER.
6525 The new content of the line will be NEWHEAD (as modified by
6526 `org-format-agenda-item'). HDMARKER is checked with
6527 `equal' against all `org-hd-marker' text properties in the file.
6528 If FIXFACE is non-nil, the face of each item is modified according to
6530 If JUST-THIS is non-nil, change just the current line, not all.
6531 If FORCE-TAGS is non nil, the car of it returns the new tags."
6532 (let* ((inhibit-read-only t)
6533 (line (org-current-line))
6534 (thetags (with-current-buffer (marker-buffer hdmarker)
6535 (save-excursion (save-restriction (widen)
6536 (goto-char hdmarker)
6537 (org-get-tags-at)))))
6538 props m pl undone-face done-face finish new dotime cat tags)
6540 (goto-char (point-max))
6541 (beginning-of-line 1)
6543 (setq finish (bobp))
6544 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6545 (or (not just-this) (= (org-current-line) line))
6547 (setq props (text-properties-at (point))
6548 dotime (org-get-at-bol 'dotime)
6549 cat (org-get-at-bol 'org-category)
6551 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6552 pl (org-get-at-bol 'prefix-length)
6553 undone-face (org-get-at-bol 'undone-face)
6554 done-face (org-get-at-bol 'done-face))
6555 (goto-char (+ (point) pl))
6556 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6559 (beginning-of-line 1)
6560 (and (looking-at ".*\n?") (replace-match "")))
6562 (replace-match new t t)
6563 (beginning-of-line 1)
6564 (add-text-properties (point-at-bol) (point-at-eol) props)
6566 (add-text-properties
6567 (point-at-bol) (point-at-eol)
6569 (if org-last-todo-state-is-todo
6570 undone-face done-face))))
6571 (org-agenda-highlight-todo 'line)
6572 (beginning-of-line 1))
6573 (t (error "Line update did not work"))))
6574 (beginning-of-line 0)))
6575 (org-finalize-agenda)))
6577 (defun org-agenda-align-tags (&optional line)
6578 "Align all tags in agenda items to `org-agenda-tags-column'."
6579 (let ((inhibit-read-only t) l c)
6581 (goto-char (if line (point-at-bol) (point-min)))
6582 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6583 (if line (point-at-eol) nil) t)
6584 (add-text-properties
6585 (match-beginning 2) (match-end 2)
6586 (list 'face (delq nil (let ((prop (get-text-property
6587 (match-beginning 2) 'face)))
6588 (or (listp prop) (setq prop (list prop)))
6589 (if (memq 'org-tag prop)
6591 (cons 'org-tag prop))))))
6592 (setq l (- (match-end 2) (match-beginning 2))
6593 c (if (< org-agenda-tags-column 0)
6594 (- (abs org-agenda-tags-column) l)
6595 org-agenda-tags-column))
6596 (delete-region (match-beginning 1) (match-end 1))
6597 (goto-char (match-beginning 1))
6598 (insert (org-add-props
6599 (make-string (max 1 (- c (current-column))) ?\ )
6600 (plist-put (copy-sequence (text-properties-at (point)))
6602 (goto-char (point-min))
6603 (org-font-lock-add-tag-faces (point-max)))))
6605 (defun org-agenda-priority-up ()
6606 "Increase the priority of line at point, also in Org-mode file."
6608 (org-agenda-priority 'up))
6610 (defun org-agenda-priority-down ()
6611 "Decrease the priority of line at point, also in Org-mode file."
6613 (org-agenda-priority 'down))
6615 (defun org-agenda-priority (&optional force-direction)
6616 "Set the priority of line at point, also in Org-mode file.
6617 This changes the line at point, all other lines in the agenda referring to
6618 the same tree node, and the headline of the tree node in the Org-mode file."
6620 (unless org-enable-priority-commands
6621 (error "Priority commands are disabled"))
6622 (org-agenda-check-no-diary)
6623 (let* ((marker (or (org-get-at-bol 'org-marker)
6624 (org-agenda-error)))
6625 (hdmarker (org-get-at-bol 'org-hd-marker))
6626 (buffer (marker-buffer hdmarker))
6627 (pos (marker-position hdmarker))
6628 (inhibit-read-only t)
6630 (org-with-remote-undo buffer
6631 (with-current-buffer buffer
6634 (org-show-context 'agenda)
6636 (and (outline-next-heading)
6637 (org-flag-heading nil))) ; show the next heading
6638 (funcall 'org-priority force-direction)
6640 (setq newhead (org-get-heading)))
6641 (org-agenda-change-all-lines newhead hdmarker)
6642 (beginning-of-line 1))))
6644 ;; FIXME: should fix the tags property of the agenda line.
6645 (defun org-agenda-set-tags (&optional tag onoff)
6646 "Set tags for the current headline."
6648 (org-agenda-check-no-diary)
6649 (if (and (org-region-active-p) (interactive-p))
6650 (call-interactively 'org-change-tag-in-region)
6651 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6652 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6653 (org-agenda-error)))
6654 (buffer (marker-buffer hdmarker))
6655 (pos (marker-position hdmarker))
6656 (inhibit-read-only t)
6658 (org-with-remote-undo buffer
6659 (with-current-buffer buffer
6663 (org-show-context 'agenda))
6665 (and (outline-next-heading)
6666 (org-flag-heading nil))) ; show the next heading
6669 (org-toggle-tag tag onoff)
6670 (call-interactively 'org-set-tags))
6672 (setq newhead (org-get-heading)))
6673 (org-agenda-change-all-lines newhead hdmarker)
6674 (beginning-of-line 1)))))
6676 (defun org-agenda-set-property ()
6677 "Set a property for the current headline."
6679 (org-agenda-check-no-diary)
6680 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6681 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6682 (org-agenda-error)))
6683 (buffer (marker-buffer hdmarker))
6684 (pos (marker-position hdmarker))
6685 (inhibit-read-only t)
6687 (org-with-remote-undo buffer
6688 (with-current-buffer buffer
6692 (org-show-context 'agenda))
6694 (and (outline-next-heading)
6695 (org-flag-heading nil))) ; show the next heading
6697 (call-interactively 'org-set-property)))))
6699 (defun org-agenda-set-effort ()
6700 "Set the effort property for the current headline."
6702 (org-agenda-check-no-diary)
6703 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6704 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6705 (org-agenda-error)))
6706 (buffer (marker-buffer hdmarker))
6707 (pos (marker-position hdmarker))
6708 (inhibit-read-only t)
6710 (org-with-remote-undo buffer
6711 (with-current-buffer buffer
6715 (org-show-context 'agenda))
6717 (and (outline-next-heading)
6718 (org-flag-heading nil))) ; show the next heading
6720 (call-interactively 'org-set-effort)
6723 (defun org-agenda-toggle-archive-tag ()
6724 "Toggle the archive tag for the current entry."
6726 (org-agenda-check-no-diary)
6727 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6728 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6729 (org-agenda-error)))
6730 (buffer (marker-buffer hdmarker))
6731 (pos (marker-position hdmarker))
6732 (inhibit-read-only t)
6734 (org-with-remote-undo buffer
6735 (with-current-buffer buffer
6738 (org-show-context 'agenda)
6740 (and (outline-next-heading)
6741 (org-flag-heading nil))) ; show the next heading
6742 (call-interactively 'org-toggle-archive-tag)
6744 (setq newhead (org-get-heading)))
6745 (org-agenda-change-all-lines newhead hdmarker)
6746 (beginning-of-line 1))))
6748 (defun org-agenda-do-date-later (arg)
6751 ((or (equal arg '(16))
6753 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6754 (setq this-command 'org-agenda-date-later-minutes)
6755 (org-agenda-date-later-minutes 1))
6756 ((or (equal arg '(4))
6758 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6759 (setq this-command 'org-agenda-date-later-hours)
6760 (org-agenda-date-later-hours 1))
6762 (org-agenda-date-later (prefix-numeric-value arg)))))
6764 (defun org-agenda-do-date-earlier (arg)
6767 ((or (equal arg '(16))
6769 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6770 (setq this-command 'org-agenda-date-earlier-minutes)
6771 (org-agenda-date-earlier-minutes 1))
6772 ((or (equal arg '(4))
6774 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6775 (setq this-command 'org-agenda-date-earlier-hours)
6776 (org-agenda-date-earlier-hours 1))
6778 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6780 (defun org-agenda-date-later (arg &optional what)
6781 "Change the date of this item to one day later."
6783 (org-agenda-check-type t 'agenda 'timeline)
6784 (org-agenda-check-no-diary)
6785 (let* ((marker (or (org-get-at-bol 'org-marker)
6786 (org-agenda-error)))
6787 (buffer (marker-buffer marker))
6788 (pos (marker-position marker)))
6789 (org-with-remote-undo buffer
6790 (with-current-buffer buffer
6793 (if (not (org-at-timestamp-p))
6794 (error "Cannot find time stamp"))
6795 (org-timestamp-change arg (or what 'day)))
6796 (org-agenda-show-new-time marker org-last-changed-timestamp))
6797 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6799 (defun org-agenda-date-earlier (arg &optional what)
6800 "Change the date of this item to one day earlier."
6802 (org-agenda-date-later (- arg) what))
6804 (defun org-agenda-date-later-minutes (arg)
6805 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6807 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6808 (org-agenda-date-later arg 'minute))
6810 (defun org-agenda-date-earlier-minutes (arg)
6811 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6813 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6814 (org-agenda-date-earlier arg 'minute))
6816 (defun org-agenda-date-later-hours (arg)
6817 "Change the time of this item, in hour steps."
6819 (org-agenda-date-later arg 'hour))
6821 (defun org-agenda-date-earlier-hours (arg)
6822 "Change the time of this item, in hour steps."
6824 (org-agenda-date-earlier arg 'hour))
6826 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6827 "Show new date stamp via text properties."
6828 ;; We use text properties to make this undoable
6829 (let ((inhibit-read-only t)
6830 (buffer-invisibility-spec))
6831 (setq stamp (concat " " prefix " => " stamp))
6833 (goto-char (point-max))
6835 (when (equal marker (org-get-at-bol 'org-marker))
6836 (org-move-to-column (- (window-width) (length stamp)) t)
6837 (org-agenda-fix-tags-filter-overlays-at (point))
6838 (if (featurep 'xemacs)
6839 ;; Use `duplicable' property to trigger undo recording
6840 (let ((ex (make-extent nil nil))
6841 (gl (make-glyph stamp)))
6842 (set-glyph-face gl 'secondary-selection)
6843 (set-extent-properties
6844 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6845 (insert-extent ex (1- (point)) (point-at-eol)))
6846 (add-text-properties
6847 (1- (point)) (point-at-eol)
6848 (list 'display (org-add-props stamp nil
6849 'face 'secondary-selection))))
6850 (beginning-of-line 1))
6851 (beginning-of-line 0)))))
6853 (defun org-agenda-date-prompt (arg)
6854 "Change the date of this item. Date is prompted for, with default today.
6855 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6856 be used to request time specification in the time stamp."
6858 (org-agenda-check-type t 'agenda 'timeline)
6859 (org-agenda-check-no-diary)
6860 (let* ((marker (or (org-get-at-bol 'org-marker)
6861 (org-agenda-error)))
6862 (buffer (marker-buffer marker))
6863 (pos (marker-position marker)))
6864 (org-with-remote-undo buffer
6865 (with-current-buffer buffer
6868 (if (not (org-at-timestamp-p t))
6869 (error "Cannot find time stamp"))
6870 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
6871 (org-agenda-show-new-time marker org-last-changed-timestamp))
6872 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6874 (defun org-agenda-schedule (arg)
6875 "Schedule the item at point.
6876 Arg is passed through to `org-schedule'."
6878 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6879 (org-agenda-check-no-diary)
6880 (let* ((marker (or (org-get-at-bol 'org-marker)
6881 (org-agenda-error)))
6882 (type (marker-insertion-type marker))
6883 (buffer (marker-buffer marker))
6884 (pos (marker-position marker))
6885 (org-insert-labeled-timestamps-at-point nil)
6887 (set-marker-insertion-type marker t)
6888 (org-with-remote-undo buffer
6889 (with-current-buffer buffer
6892 (setq ts (org-schedule arg)))
6893 (org-agenda-show-new-time marker ts "S"))
6894 (message "Item scheduled for %s" ts)))
6896 (defun org-agenda-deadline (arg)
6897 "Schedule the item at point.
6898 Arg is passed through to `org-deadline'."
6900 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6901 (org-agenda-check-no-diary)
6902 (let* ((marker (or (org-get-at-bol 'org-marker)
6903 (org-agenda-error)))
6904 (buffer (marker-buffer marker))
6905 (pos (marker-position marker))
6906 (org-insert-labeled-timestamps-at-point nil)
6908 (org-with-remote-undo buffer
6909 (with-current-buffer buffer
6912 (setq ts (org-deadline arg)))
6913 (org-agenda-show-new-time marker ts "D"))
6914 (message "Deadline for this item set to %s" ts)))
6916 (defun org-agenda-action ()
6917 "Select entry for agenda action, or execute an agenda action.
6918 This command prompts for another letter. Valid inputs are:
6920 m Mark the entry at point for an agenda action
6921 s Schedule the marked entry to the date at the cursor
6922 d Set the deadline of the marked entry to the date at the cursor
6923 r Call `org-remember' with cursor date as the default date
6924 SPC Show marked entry in other window
6925 TAB Visit marked entry in other window
6927 The cursor may be at a date in the calendar, or in the Org agenda."
6930 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6931 (setq ans (read-char-exclusive))
6935 (if (eq major-mode 'org-agenda-mode)
6936 (let ((m (or (org-get-at-bol 'org-hd-marker)
6937 (org-get-at-bol 'org-marker))))
6940 (move-marker org-agenda-action-marker
6941 (marker-position m) (marker-buffer m))
6942 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6943 (error "Don't know which entry to mark")))
6944 (error "This command works only in the agenda")))
6946 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6948 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6950 (org-agenda-do-action '(org-remember) t))
6952 (let ((cw (selected-window)))
6953 (org-switch-to-buffer-other-window
6954 (marker-buffer org-agenda-action-marker))
6955 (goto-char org-agenda-action-marker)
6956 (org-show-context 'agenda)
6957 (select-window cw)))
6959 (org-switch-to-buffer-other-window
6960 (marker-buffer org-agenda-action-marker))
6961 (goto-char org-agenda-action-marker)
6962 (org-show-context 'agenda))
6963 (t (error "Invalid agenda action %c" ans)))))
6965 (defun org-agenda-do-action (form &optional current-buffer)
6966 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6967 (let ((org-overriding-default-time (org-get-cursor-date)))
6970 (if (not (marker-buffer org-agenda-action-marker))
6971 (error "No entry has been selected for agenda action")
6972 (with-current-buffer (marker-buffer org-agenda-action-marker)
6976 (goto-char org-agenda-action-marker)
6979 (defun org-agenda-clock-in (&optional arg)
6980 "Start the clock on the currently selected item."
6982 (org-agenda-check-no-diary)
6983 (if (equal arg '(4))
6985 (let* ((marker (or (org-get-at-bol 'org-marker)
6986 (org-agenda-error)))
6987 (hdmarker (or (org-get-at-bol 'org-hd-marker)
6989 (pos (marker-position marker))
6991 (org-with-remote-undo (marker-buffer marker)
6992 (with-current-buffer (marker-buffer marker)
6995 (org-show-context 'agenda)
6997 (org-cycle-hide-drawers 'children)
6999 (setq newhead (org-get-heading)))
7000 (org-agenda-change-all-lines newhead hdmarker)))))
7002 (defun org-agenda-clock-out (&optional arg)
7003 "Stop the currently running clock."
7005 (unless (marker-buffer org-clock-marker)
7006 (error "No running clock"))
7007 (let ((marker (make-marker)) newhead)
7008 (org-with-remote-undo (marker-buffer org-clock-marker)
7009 (with-current-buffer (marker-buffer org-clock-marker)
7013 (goto-char org-clock-marker)
7014 (org-back-to-heading t)
7015 (move-marker marker (point))
7017 (setq newhead (org-get-heading))))))
7018 (org-agenda-change-all-lines newhead marker)
7019 (move-marker marker nil)))
7021 (defun org-agenda-clock-cancel (&optional arg)
7022 "Cancel the currently running clock."
7024 (unless (marker-buffer org-clock-marker)
7025 (error "No running clock"))
7026 (org-with-remote-undo (marker-buffer org-clock-marker)
7027 (org-clock-cancel)))
7029 (defun org-agenda-diary-entry-in-org-file ()
7030 "Make a diary entry in the file `org-agenda-diary-file'."
7031 (let (d1 d2 char (text "") dp1 dp2)
7032 (if (equal (buffer-name) "*Calendar*")
7033 (setq d1 (calendar-cursor-to-date t)
7034 d2 (car calendar-mark-ring))
7035 (setq dp1 (get-text-property (point-at-bol) 'day))
7036 (unless dp1 (error "No date defined in current line"))
7037 (setq d1 (calendar-gregorian-from-absolute dp1)
7038 d2 (and (ignore-errors (mark))
7041 (setq dp2 (get-text-property (point-at-bol) 'day)))
7042 (calendar-gregorian-from-absolute dp2))))
7043 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7044 (setq char (read-char-exclusive))
7047 (setq text (read-string "Day entry: "))
7048 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7049 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7051 (setq d1 (list (car d1) (nth 1 d1)
7052 (read-number (format "Reference year [%d]: " (nth 2 d1))
7054 (setq text (read-string "Anniversary (use %d to show years): "))
7055 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7056 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7058 (setq text (read-string "Block entry: "))
7059 (unless (and d1 d2 (not (equal d1 d2)))
7060 (error "No block of days selected"))
7061 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7062 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7064 (org-switch-to-buffer-other-window
7065 (find-file-noselect org-agenda-diary-file))
7066 (require 'org-datetree)
7067 (org-datetree-find-date-create d1)
7069 (t (error "Invalid selection character `%c'" char)))))
7071 (defcustom org-agenda-insert-diary-strategy 'date-tree
7072 "Where in `org-agenda-diary-file' should new entries be added?
7075 date-tree in the date tree, as child of the date
7076 top-level as top-level entries at the end of the file."
7079 (const :tag "in a date tree" date-tree)
7080 (const :tag "as top level at end of file" top-level)))
7082 (defcustom org-agenda-insert-diary-extract-time nil
7083 "Non-nil means extract any time specification from the diary entry."
7087 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7088 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7089 If TEXT is not empty, it will become the headline of the new entry, and
7090 the resulting entry will not be shown. When TEXT is empty, switch to
7091 `org-agenda-diary-file' and let the user finish the entry there."
7092 (let ((cw (current-window-configuration)))
7093 (org-switch-to-buffer-other-window
7094 (find-file-noselect org-agenda-diary-file))
7096 (goto-char (point-min))
7098 ((eq type 'anniversary)
7099 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7101 (or (org-on-heading-p t)
7103 (outline-next-heading)
7104 (insert "* Anniversaries\n\n")
7105 (beginning-of-line -1)))))
7106 (outline-next-heading)
7107 (org-back-over-empty-lines)
7110 (require 'diary-lib)
7111 (let ((calendar-date-display-form
7112 (if (if (boundp 'calendar-date-style)
7113 (eq calendar-date-style 'european)
7114 (org-bound-and-true-p european-calendar-style)) ; Emacs 22
7115 '(day " " month " " year)
7116 '(month " " day " " year))))
7118 (insert (format "%%%%(diary-anniversary %s) %s"
7119 (calendar-date-string d1 nil t) text))))
7121 (let ((org-prefix-has-time t)
7122 (org-agenda-time-leading-zero t)
7124 (if org-agenda-insert-diary-extract-time
7125 ;; Use org-format-agenda-item to parse text for a time-range and
7126 ;; remove it. FIXME: This is a hack, we should refactor
7127 ;; that function to make time extraction available separately
7128 (setq fmt (org-format-agenda-item nil text nil nil t)
7129 time (get-text-property 0 'time fmt)
7130 time2 (if (> (length time) 0)
7131 ;; split-string removes trailing ...... if
7132 ;; no end time given. First space
7133 ;; separates time from date.
7134 (concat " " (car (split-string time "\\.")))
7136 text (get-text-property 0 'txt fmt)))
7137 (if (eq org-agenda-insert-diary-strategy 'top-level)
7138 (org-agenda-insert-diary-as-top-level text)
7139 (require 'org-datetree)
7140 (org-datetree-find-date-create d1)
7141 (org-agenda-insert-diary-make-new-entry text))
7142 (org-insert-time-stamp (org-time-from-absolute
7143 (calendar-absolute-from-gregorian d1))
7144 nil nil nil nil time2))
7147 (if (> (calendar-absolute-from-gregorian d1)
7148 (calendar-absolute-from-gregorian d2))
7149 (setq d1 (prog1 d2 (setq d2 d1))))
7150 (if (eq org-agenda-insert-diary-strategy 'top-level)
7151 (org-agenda-insert-diary-as-top-level text)
7152 (require 'org-datetree)
7153 (org-datetree-find-date-create d1)
7154 (org-agenda-insert-diary-make-new-entry text))
7155 (org-insert-time-stamp (org-time-from-absolute
7156 (calendar-absolute-from-gregorian d1)))
7158 (org-insert-time-stamp (org-time-from-absolute
7159 (calendar-absolute-from-gregorian d2)))
7161 (if (string-match "\\S-" text)
7163 (set-window-configuration cw)
7164 (message "%s entry added to %s"
7165 (capitalize (symbol-name type))
7166 (abbreviate-file-name org-agenda-diary-file)))
7168 (message "Please finish entry here"))))
7170 (defun org-agenda-insert-diary-as-top-level (text)
7171 "Make new entry as a top-level entry at the end of the file.
7172 Add TEXT as headline, and position the cursor in the second line so that
7173 a timestamp can be added there."
7175 (goto-char (point-max))
7176 (or (bolp) (insert "\n"))
7177 (insert "* " text "\n")
7178 (if org-adapt-indentation (org-indent-to-column 2)))
7180 (defun org-agenda-insert-diary-make-new-entry (text)
7181 "Make new entry as last child of current entry.
7182 Add TEXT as headline, and position the cursor in the second line so that
7183 a timestamp can be added there."
7184 (let ((org-show-following-heading t)
7185 (org-show-siblings t)
7186 (org-show-hierarchy-above t)
7187 (org-show-entry-below t)
7189 (outline-next-heading)
7190 (org-back-over-empty-lines)
7191 (or (looking-at "[ \t]*$")
7192 (progn (insert "\n") (backward-char 1)))
7193 (org-insert-heading nil t)
7195 (setq col (current-column))
7197 (if org-adapt-indentation (org-indent-to-column col))
7198 (let ((org-show-following-heading t)
7199 (org-show-siblings t)
7200 (org-show-hierarchy-above t)
7201 (org-show-entry-below t))
7202 (org-show-context))))
7204 (defun org-agenda-diary-entry ()
7205 "Make a diary entry, like the `i' command from the calendar.
7206 All the standard commands work: block, weekly etc.
7207 When `org-agenda-diary-file' points to a file,
7208 `org-agenda-diary-entry-in-org-file' is called instead to create
7209 entries in that Org-mode file."
7211 (org-agenda-check-type t 'agenda 'timeline)
7212 (if (not (eq org-agenda-diary-file 'diary-file))
7213 (org-agenda-diary-entry-in-org-file)
7214 (require 'diary-lib)
7216 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7217 (read-char-exclusive)))
7218 (cmd (cdr (assoc char
7219 '((?d . insert-diary-entry)
7220 (?w . insert-weekly-diary-entry)
7221 (?m . insert-monthly-diary-entry)
7222 (?y . insert-yearly-diary-entry)
7223 (?a . insert-anniversary-diary-entry)
7224 (?b . insert-block-diary-entry)
7225 (?c . insert-cyclic-diary-entry)))))
7226 (oldf (symbol-function 'calendar-cursor-to-date))
7227 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7229 (mark (or (mark t) (point))))
7231 (error "No command associated with <%c>" char))
7232 (unless (and (get-text-property point 'day)
7233 (or (not (equal ?b char))
7234 (get-text-property mark 'day)))
7235 (error "Don't know which date to use for diary entry"))
7236 ;; We implement this by hacking the `calendar-cursor-to-date' function
7237 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7238 (let ((calendar-mark-ring
7239 (list (calendar-gregorian-from-absolute
7240 (or (get-text-property mark 'day)
7241 (get-text-property point 'day))))))
7244 (fset 'calendar-cursor-to-date
7245 (lambda (&optional error dummy)
7246 (calendar-gregorian-from-absolute
7247 (get-text-property point 'day))))
7248 (call-interactively cmd))
7249 (fset 'calendar-cursor-to-date oldf))))))
7251 (defun org-agenda-execute-calendar-command (cmd)
7252 "Execute a calendar command from the agenda, with the date associated to
7253 the cursor position."
7254 (org-agenda-check-type t 'agenda 'timeline)
7255 (require 'diary-lib)
7256 (unless (get-text-property (point) 'day)
7257 (error "Don't know which date to use for calendar command"))
7258 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7260 (date (calendar-gregorian-from-absolute
7261 (get-text-property point 'day)))
7262 ;; the following 2 vars are needed in the calendar
7263 (displayed-month (car date))
7264 (displayed-year (nth 2 date)))
7267 (fset 'calendar-cursor-to-date
7268 (lambda (&optional error dummy)
7269 (calendar-gregorian-from-absolute
7270 (get-text-property point 'day))))
7271 (call-interactively cmd))
7272 (fset 'calendar-cursor-to-date oldf))))
7274 (defun org-agenda-phases-of-moon ()
7275 "Display the phases of the moon for the 3 months around the cursor date."
7277 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7279 (defun org-agenda-holidays ()
7280 "Display the holidays for the 3 months around the cursor date."
7282 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7284 (defvar calendar-longitude)
7285 (defvar calendar-latitude)
7286 (defvar calendar-location-name)
7288 (defun org-agenda-sunrise-sunset (arg)
7289 "Display sunrise and sunset for the cursor date.
7290 Latitude and longitude can be specified with the variables
7291 `calendar-latitude' and `calendar-longitude'. When called with prefix
7292 argument, latitude and longitude will be prompted for."
7295 (let ((calendar-longitude (if arg nil calendar-longitude))
7296 (calendar-latitude (if arg nil calendar-latitude))
7297 (calendar-location-name
7298 (if arg "the given coordinates" calendar-location-name)))
7299 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7301 (defun org-agenda-goto-calendar ()
7302 "Open the Emacs calendar with the date at the cursor."
7304 (org-agenda-check-type t 'agenda 'timeline)
7305 (let* ((day (or (get-text-property (point) 'day)
7306 (error "Don't know which date to open in calendar")))
7307 (date (calendar-gregorian-from-absolute day))
7308 (calendar-move-hook nil)
7309 (calendar-view-holidays-initially-flag nil)
7310 (calendar-view-diary-initially-flag nil))
7312 (calendar-goto-date date)))
7315 (defun org-calendar-goto-agenda ()
7316 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7317 This is a command that has to be installed in `calendar-mode-map'."
7319 (org-agenda-list nil (calendar-absolute-from-gregorian
7320 (calendar-cursor-to-date))
7323 (defun org-agenda-convert-date ()
7325 (org-agenda-check-type t 'agenda 'timeline)
7326 (let ((day (get-text-property (point) 'day))
7329 (error "Don't know which date to convert"))
7330 (setq date (calendar-gregorian-from-absolute day))
7332 "Gregorian: " (calendar-date-string date) "\n"
7333 "ISO: " (calendar-iso-date-string date) "\n"
7334 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7335 "Julian: " (calendar-julian-date-string date) "\n"
7336 "Astron. JD: " (calendar-astro-date-string date)
7337 " (Julian date number at noon UTC)\n"
7338 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7339 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7340 "French: " (calendar-french-date-string date) "\n"
7341 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7342 "Mayan: " (calendar-mayan-date-string date) "\n"
7343 "Coptic: " (calendar-coptic-date-string date) "\n"
7344 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7345 "Persian: " (calendar-persian-date-string date) "\n"
7346 "Chinese: " (calendar-chinese-date-string date) "\n"))
7347 (with-output-to-temp-buffer "*Dates*"
7349 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7353 (defvar org-agenda-bulk-marked-entries nil
7354 "List of markers that refer to marked entries in the agenda.")
7356 (defun org-agenda-bulk-marked-p ()
7357 (eq (get-char-property (point-at-bol) 'type)
7358 'org-marked-entry-overlay))
7360 (defun org-agenda-bulk-mark ()
7361 "Mark the entry at point for future bulk action."
7363 (org-agenda-check-no-diary)
7364 (let* ((m (org-get-at-bol 'org-hd-marker))
7366 (unless (org-agenda-bulk-marked-p)
7367 (unless m (error "Nothing to mark at point"))
7368 (push m org-agenda-bulk-marked-entries)
7369 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7370 (org-overlay-display ov "> "
7371 (org-get-todo-face "TODO")
7373 (overlay-put ov 'type 'org-marked-entry-overlay))
7374 (beginning-of-line 2)
7375 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7376 (beginning-of-line 2))
7377 (message "%d entries marked for bulk action"
7378 (length org-agenda-bulk-marked-entries))))
7380 (defun org-agenda-bulk-unmark ()
7381 "Unmark the entry at point for future bulk action."
7383 (when (org-agenda-bulk-marked-p)
7384 (org-agenda-bulk-remove-overlays
7385 (point-at-bol) (+ 2 (point-at-bol)))
7386 (setq org-agenda-bulk-marked-entries
7387 (delete (org-get-at-bol 'org-hd-marker)
7388 org-agenda-bulk-marked-entries)))
7389 (beginning-of-line 2)
7390 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7391 (beginning-of-line 2))
7392 (message "%d entries marked for bulk action"
7393 (length org-agenda-bulk-marked-entries)))
7395 (defun org-agenda-bulk-toggle ()
7396 "Toggle marking the entry at point for bulk action."
7398 (if (org-agenda-bulk-marked-p)
7399 (org-agenda-bulk-unmark)
7400 (org-agenda-bulk-mark)))
7402 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7403 "Remove the mark overlays between BEG and END in the agenda buffer.
7404 BEG and END default to the buffer limits.
7406 This only removes the overlays, it does not remove the markers
7407 from the list in `org-agenda-bulk-marked-entries'."
7410 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7411 (delete-overlay ov)))
7412 (overlays-in (or beg (point-min)) (or end (point-max)))))
7414 (defun org-agenda-bulk-remove-all-marks ()
7415 "Remove all marks in the agenda buffer.
7416 This will remove the markers, and the overlays."
7418 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7419 (setq org-agenda-bulk-marked-entries nil)
7420 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7422 (defun org-agenda-bulk-action (&optional arg)
7423 "Execute an remote-editing action on all marked entries.
7424 The prefix arg is passed through to the command if possible."
7426 (unless org-agenda-bulk-marked-entries
7427 (error "No entries are marked"))
7428 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7429 (let* ((action (read-char-exclusive))
7430 (org-log-refile (if org-log-refile 'time nil))
7431 (entries (reverse org-agenda-bulk-marked-entries))
7432 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7435 (setq cmd '(org-agenda-archive)))
7438 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7440 ((member action '(?r ?w))
7441 (setq rfloc (org-refile-get-location
7443 (marker-buffer (car org-agenda-bulk-marked-entries))
7444 org-refile-allow-creating-parent-nodes))
7445 (setcar (nthcdr 3 rfloc)
7446 (move-marker (make-marker) (nth 3 rfloc)
7447 (or (get-file-buffer (nth 1 rfloc))
7448 (find-buffer-visiting (nth 1 rfloc))
7449 (error "This should not happen"))))
7451 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
7454 (setq state (org-icompleting-read
7456 (with-current-buffer (marker-buffer (car entries))
7457 (mapcar 'list org-todo-keywords-1))))
7458 (setq cmd `(let ((org-inhibit-blocking t)
7459 (org-inhibit-logging 'note))
7460 (org-agenda-todo ,state))))
7462 ((memq action '(?- ?+))
7463 (setq tag (org-icompleting-read
7464 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7465 (with-current-buffer (marker-buffer (car entries))
7468 (if (stringp (car x)) x)) org-tag-alist)))))
7469 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7471 ((memq action '(?s ?d))
7472 (let* ((date (unless arg
7475 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7476 (ans (if arg nil org-read-date-final-answer))
7477 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7478 (setq cmd `(let* ((bound (fboundp 'read-string))
7479 (old (and bound (symbol-function 'read-string))))
7482 (fset 'read-string (lambda (&rest ignore) ,ans))
7485 (fset 'read-string old)
7486 (fmakunbound 'read-string)))))))
7487 (t (error "Invalid bulk action")))
7489 ;; Sort the markers, to make sure that parents are handled before children
7490 (setq entries (sort entries
7493 ((equal (marker-buffer a) (marker-buffer b))
7494 (< (marker-position a) (marker-position b)))
7496 (string< (buffer-name (marker-buffer a))
7497 (buffer-name (marker-buffer b))))))))
7499 ;; Now loop over all markers and apply cmd
7500 (while (setq e (pop entries))
7501 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7503 (progn (message "Skipping removed entry at %s" e)
7504 (setq cntskip (1+ cntskip)))
7507 (setq org-agenda-bulk-marked-entries
7508 (delete e org-agenda-bulk-marked-entries))
7509 (setq cnt (1+ cnt))))
7510 (setq org-agenda-bulk-marked-entries nil)
7511 (org-agenda-bulk-remove-all-marks)
7512 (message "Acted on %d entries%s"
7516 (format ", skipped %d (disappeared before their turn)"
7521 (defun org-agenda-show-the-flagging-note ()
7522 "Display the flagging note in the other window.
7523 When called a second time in direct sequence, offer to remove the FLAGGING
7524 tag and (if present) the flagging note."
7526 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7527 (win (selected-window))
7528 note heading newhead)
7530 (error "No linked entry at point"))
7531 (if (and (eq this-command last-command)
7532 (y-or-n-p "Unflag and remove any flagging note? "))
7534 (org-agenda-remove-flag hdmarker)
7535 (let ((win (get-buffer-window "*Flagging Note*")))
7536 (and win (delete-window win)))
7537 (message "Entry unflaged"))
7538 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7540 (error "No flagging note"))
7542 (org-switch-to-buffer-other-window "*Flagging Note*")
7545 (goto-char (point-min))
7546 (while (re-search-forward "\\\\n" nil t)
7547 (replace-match "\n" t t))
7548 (goto-char (point-min))
7550 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7552 (defun org-agenda-remove-flag (marker)
7553 "Remove the FLAGGED tag and any flagging note in the entry."
7555 (org-with-point-at marker
7556 (org-toggle-tag "FLAGGED" 'off)
7557 (org-entry-delete nil "THEFLAGGINGNOTE")
7558 (setq newhead (org-get-heading)))
7559 (org-agenda-change-all-lines newhead marker)
7560 (message "Entry unflaged")))
7562 (defun org-agenda-get-any-marker (&optional pos)
7563 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7564 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7566 ;;; Appointment reminders
7568 (defvar appt-time-msg-list)
7571 (defun org-agenda-to-appt (&optional refresh filter)
7572 "Activate appointments found in `org-agenda-files'.
7573 With a \\[universal-argument] prefix, refresh the list of
7576 If FILTER is t, interactively prompt the user for a regular
7577 expression, and filter out entries that don't match it.
7579 If FILTER is a string, use this string as a regular expression
7580 for filtering entries out.
7582 FILTER can also be an alist with the car of each cell being
7583 either 'headline or 'category. For example:
7585 '((headline \"IMPORTANT\")
7586 (category \"Work\"))
7588 will only add headlines containing IMPORTANT or headlines
7589 belonging to the \"Work\" category."
7591 (if refresh (setq appt-time-msg-list nil))
7593 (setq filter (read-from-minibuffer "Regexp filter: ")))
7594 (let* ((cnt 0) ; count added events
7595 (org-agenda-new-buffers nil)
7596 (org-deadline-warning-days 0)
7597 (today (org-date-to-gregorian
7598 (time-to-days (current-time))))
7599 (org-agenda-restrict nil)
7600 (files (org-agenda-files 'unrestricted)) entries file)
7601 ;; Get all entries which may contain an appt
7602 (org-prepare-agenda-buffers files)
7603 (while (setq file (pop files))
7606 (org-agenda-get-day-entries
7607 file today :timestamp :scheduled :deadline))))
7608 (setq entries (delq nil entries))
7609 ;; Map thru entries and find if we should filter them out
7612 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7613 (cat (get-text-property 1 'org-category x))
7614 (tod (get-text-property 1 'time-of-day x))
7615 (ok (or (null filter)
7616 (and (stringp filter) (string-match filter evt))
7619 (cadr (assoc 'category filter)) cat)
7621 (cadr (assoc 'headline filter)) evt))))))
7622 ;; FIXME: Shall we remove text-properties for the appt text?
7623 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7625 (setq tod (concat "00" (number-to-string tod))
7626 tod (when (string-match
7627 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7628 (concat (match-string 1 tod) ":"
7629 (match-string 2 tod))))
7631 (setq cnt (1+ cnt))))) entries)
7632 (org-release-buffers org-agenda-new-buffers)
7634 (message "No event to add")
7635 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7637 (defun org-agenda-todayp (date)
7638 "Does DATE mean today, when considering `org-extend-today-until'?"
7640 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7641 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7642 (setq h (nth 2 (decode-time (current-time))))
7643 (or (and (>= h org-extend-today-until)
7645 (and (< h org-extend-today-until)
7646 (= date (1- today))))))
7648 (provide 'org-agenda)
7650 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7652 ;;; org-agenda.el ends here