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-clock-current-task
) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
67 (defvar org-habit-show-habits
)
68 (defvar org-habit-show-habits-only-for-today
)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name
)
72 (defvar org-agenda-overriding-header
)
73 (defvar org-agenda-title-append nil
)
76 (defvar org-agenda-undo-list
)
77 (defvar org-agenda-pending-undo-list
)
78 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill
1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
86 (const :tag
"Never" nil
)
87 (const :tag
"Always" t
)
88 (integer :tag
"When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
96 (defcustom org-agenda-block-separator ?
=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag
"Org Agenda Export"
110 (defcustom org-agenda-with-colors t
111 "Non-nil means use colors in agenda views."
112 :group
'org-agenda-export
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group
'org-agenda-export
128 (sexp :tag
"Value"))))
130 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group
'org-agenda-export
135 :options
'(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines
0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
147 and `org-agenda-entry-text-maxlines'."
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
159 (defcustom org-agenda-export-html-style
""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group
'org-agenda-export
198 :group
'org-export-html
201 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag
"Org Agenda Custom Commands"
211 (defconst org-sorting-choice
213 (const time-up
) (const time-down
)
214 (const category-keep
) (const category-up
) (const category-down
)
215 (const tag-down
) (const tag-up
)
216 (const priority-up
) (const priority-down
)
217 (const todo-state-up
) (const todo-state-down
)
218 (const effort-up
) (const effort-down
)
219 (const habit-up
) (const habit-down
)
220 (const alpha-up
) (const alpha-down
)
221 (const user-defined-up
) (const user-defined-down
))
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag
"Local settings for this command. Remember to quote values"
226 (choice :tag
"Setting"
227 (list :tag
"Heading for this block"
228 (const org-agenda-overriding-header
)
229 (string :tag
"Headline"))
230 (list :tag
"Files to be searched"
231 (const org-agenda-files
)
233 (const :format
"" quote
)
235 (list :tag
"Sorting strategy"
236 (const org-agenda-sorting-strategy
)
238 (const :format
"" quote
)
240 ,org-sorting-choice
)))
241 (list :tag
"Prefix format"
242 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
244 (list :tag
"Number of days in agenda"
245 (const org-agenda-ndays
)
247 (list :tag
"Fixed starting date"
248 (const org-agenda-start-day
)
249 (string :value
"2007-11-01"))
250 (list :tag
"Start on day of week"
251 (const org-agenda-start-on-weekday
)
253 (const :tag
"Today" nil
)
254 (integer :tag
"Weekday No.")))
255 (list :tag
"Include data from diary"
256 (const org-agenda-include-diary
)
258 (list :tag
"Deadline Warning days"
259 (const org-deadline-warning-days
)
261 (list :tag
"Tags filter preset"
262 (const org-agenda-filter-preset
)
264 (const :format
"" quote
)
266 (string :tag
"+tag or -tag"))))
267 (list :tag
"Set daily/weekly entry types"
268 (const org-agenda-entry-types
)
269 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
274 (list :tag
"Standard skipping condition"
275 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
276 (const org-agenda-skip-function
)
278 (const :format
"" quote
)
281 :tag
"Skipping range"
282 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
283 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
284 (repeat :inline t
:tag
"Conditions for skipping"
286 :tag
"Condition type"
287 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
288 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
289 (list :tag
"TODO state is" :inline t
292 (const :tag
"any not-done state" 'todo
)
293 (const :tag
"any done state" 'done
)
294 (const :tag
"any state" 'any
)
295 (list :tag
"Keyword list"
296 (const :format
"" quote
)
297 (repeat (string :tag
"Keyword")))))
298 (list :tag
"TODO state is not" :inline t
301 (const :tag
"any not-done state" 'todo
)
302 (const :tag
"any done state" 'done
)
303 (const :tag
"any state" 'any
)
304 (list :tag
"Keyword list"
305 (const :format
"" quote
)
306 (repeat (string :tag
"Keyword")))))
307 (const :tag
"scheduled" 'scheduled
)
308 (const :tag
"not scheduled" 'notscheduled
)
309 (const :tag
"deadline" 'deadline
)
310 (const :tag
"no deadline" 'notdeadline
)
311 (const :tag
"timestamp" 'timestamp
)
312 (const :tag
"no timestamp" 'nottimestamp
))))))
313 (list :tag
"Non-standard skipping condition"
314 :value
(org-agenda-skip-function)
315 (const org-agenda-skip-function
)
316 (sexp :tag
"Function or form (quoted!)"))
317 (list :tag
"Any variable"
318 (variable :tag
"Variable")
319 (sexp :tag
"Value (sexp)"))))
320 "Selection of examples for agenda command settings.
321 This will be spliced into the custom type of
322 `org-agenda-custom-commands'.")
325 (defcustom org-agenda-custom-commands nil
326 "Custom commands for the agenda.
327 These commands will be offered on the splash screen displayed by the
328 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
330 (key desc type match settings files)
332 key The key (one or more characters as a string) to be associated
334 desc A description of the command, when omitted or nil, a default
335 description is built using MATCH.
336 type The command type, any of the following symbols:
337 agenda The daily/weekly agenda.
338 todo Entries with a specific TODO keyword, in all agenda files.
339 search Entries containing search words entry or headline.
340 tags Tags/Property/TODO match in all agenda files.
341 tags-todo Tags/P/T match in all agenda files, TODO entries only.
342 todo-tree Sparse tree of specific TODO keyword in *current* file.
343 tags-tree Sparse tree with all tags matches in *current* file.
344 occur-tree Occur sparse tree for *current* file.
345 ... A user-defined function.
346 match What to search for:
347 - a single keyword for TODO keyword searches
348 - a tags match expression for tags searches
349 - a word search expression for text searches.
350 - a regular expression for occur searches
351 For all other commands, this should be the empty string.
352 settings A list of option settings, similar to that in a let form, so like
353 this: ((opt1 val1) (opt2 val2) ...). The values will be
354 evaluated at the moment of execution, so quote them when needed.
355 files A list of files file to write the produced agenda buffer to
356 with the command `org-store-agenda-views'.
357 If a file name ends in \".html\", an HTML version of the buffer
358 is written out. If it ends in \".ps\", a postscript version is
359 produced. Otherwise, only the plain text is written to the file.
361 You can also define a set of commands, to create a composite agenda buffer.
362 In this case, an entry looks like this:
364 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
368 desc A description string to be displayed in the dispatcher menu.
369 cmd An agenda command, similar to the above. However, tree commands
370 are no allowed, but instead you can get agenda and global todo list.
371 So valid commands for a set are:
372 (agenda \"\" settings)
373 (alltodo \"\" settings)
374 (stuck \"\" settings)
375 (todo \"match\" settings files)
376 (search \"match\" settings files)
377 (tags \"match\" settings files)
378 (tags-todo \"match\" settings files)
380 Each command can carry a list of options, and another set of options can be
381 given for the whole set of commands. Individual command options take
382 precedence over the general options.
384 When using several characters as key to a command, the first characters
385 are prefix commands. For the dispatcher to display useful information, you
386 should provide a description for the prefix, like
388 (setq org-agenda-custom-commands
389 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
390 (\"hl\" tags \"+HOME+Lisa\")
391 (\"hp\" tags \"+HOME+Peter\")
392 (\"hk\" tags \"+HOME+Kim\")))"
393 :group
'org-agenda-custom-commands
395 (choice :value
("x" "Describe command here" tags
"" nil
)
396 (list :tag
"Single command"
397 (string :tag
"Access Key(s) ")
398 (option (string :tag
"Description"))
400 (const :tag
"Agenda" agenda
)
401 (const :tag
"TODO list" alltodo
)
402 (const :tag
"Search words" search
)
403 (const :tag
"Stuck projects" stuck
)
404 (const :tag
"Tags/Property match (all agenda files)" tags
)
405 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
406 (const :tag
"TODO keyword search (all agenda files)" todo
)
407 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
408 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
409 (const :tag
"Occur tree (current buffer)" occur-tree
)
410 (sexp :tag
"Other, user-defined function"))
411 (string :tag
"Match (only for some commands)")
412 ,org-agenda-custom-commands-local-options
413 (option (repeat :tag
"Export" (file :tag
"Export to"))))
414 (list :tag
"Command series, all agenda files"
415 (string :tag
"Access Key(s)")
416 (string :tag
"Description ")
417 (repeat :tag
"Component"
420 (const :format
"" agenda
)
421 (const :tag
"" :format
"" "")
422 ,org-agenda-custom-commands-local-options
)
423 (list :tag
"TODO list (all keywords)"
424 (const :format
"" alltodo
)
425 (const :tag
"" :format
"" "")
426 ,org-agenda-custom-commands-local-options
)
427 (list :tag
"Search words"
428 (const :format
"" search
)
429 (string :tag
"Match")
430 ,org-agenda-custom-commands-local-options
)
431 (list :tag
"Stuck projects"
432 (const :format
"" stuck
)
433 (const :tag
"" :format
"" "")
434 ,org-agenda-custom-commands-local-options
)
435 (list :tag
"Tags search"
436 (const :format
"" tags
)
437 (string :tag
"Match")
438 ,org-agenda-custom-commands-local-options
)
439 (list :tag
"Tags search, TODO entries only"
440 (const :format
"" tags-todo
)
441 (string :tag
"Match")
442 ,org-agenda-custom-commands-local-options
)
443 (list :tag
"TODO keyword search"
444 (const :format
"" todo
)
445 (string :tag
"Match")
446 ,org-agenda-custom-commands-local-options
)
447 (list :tag
"Other, user-defined function"
448 (symbol :tag
"function")
449 (string :tag
"Match")
450 ,org-agenda-custom-commands-local-options
)))
452 (repeat :tag
"Settings for entire command set"
453 (list (variable :tag
"Any variable")
454 (sexp :tag
"Value")))
455 (option (repeat :tag
"Export" (file :tag
"Export to"))))
456 (cons :tag
"Prefix key documentation"
457 (string :tag
"Access Key(s)")
458 (string :tag
"Description ")))))
460 (defcustom org-agenda-query-register ?o
461 "The register holding the current query string.
462 The purpose of this is that if you construct a query string interactively,
463 you can then use it to define a custom command."
464 :group
'org-agenda-custom-commands
467 (defcustom org-stuck-projects
468 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
469 "How to identify stuck projects.
470 This is a list of four items:
471 1. A tags/todo/property matcher string that is used to identify a project.
472 See the manual for a description of tag and property searches.
473 The entire tree below a headline matched by this is considered one project.
474 2. A list of TODO keywords identifying non-stuck projects.
475 If the project subtree contains any headline with one of these todo
476 keywords, the project is considered to be not stuck. If you specify
477 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
478 3. A list of tags identifying non-stuck projects.
479 If the project subtree contains any headline with one of these tags,
480 the project is considered to be not stuck. If you specify \"*\" as
481 a tag, any tag will mark the project unstuck. Note that this is about
482 the explicit presence of a tag somewhere in the subtree, inherited
483 tags to not count here. If inherited tags make a project not stuck,
484 use \"-TAG\" in the tags part of the matcher under (1.) above.
485 4. An arbitrary regular expression matching non-stuck projects.
487 If the project turns out to be not stuck, search continues also in the
488 subtree to see if any of the subtasks have project status.
490 See also the variable `org-tags-match-list-sublevels' which applies
491 to projects matched by this search as well.
493 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
494 or `C-c a #' to produce the list."
495 :group
'org-agenda-custom-commands
497 (string :tag
"Tags/TODO match to identify a project")
498 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
499 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
500 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
502 (defcustom org-agenda-filter-effort-default-operator
"<"
503 "The default operator for effort estimate filtering.
504 If you select an effort estimate limit without first pressing an operator,
505 this one will be used."
506 :group
'org-agenda-custom-commands
507 :type
'(choice (const :tag
"less or equal" "<")
508 (const :tag
"greater or equal"">")
509 (const :tag
"equal" "=")))
511 (defgroup org-agenda-skip nil
512 "Options concerning skipping parts of agenda files."
513 :tag
"Org Agenda Skip"
515 (defgroup org-agenda-daily
/weekly nil
516 "Options concerning the daily/weekly agenda."
517 :tag
"Org Agenda Daily/Weekly"
519 (defgroup org-agenda-todo-list nil
520 "Options concerning the global todo list agenda view."
521 :tag
"Org Agenda Todo List"
523 (defgroup org-agenda-match-view nil
524 "Options concerning the general tags/property/todo match agenda view."
525 :tag
"Org Agenda Match View"
527 (defgroup org-agenda-search-view nil
528 "Options concerning the general tags/property/todo match agenda view."
529 :tag
"Org Agenda Match View"
532 (defvar org-agenda-archives-mode nil
533 "Non-nil means the agenda will include archived items.
534 If this is the symbol `trees', trees in the selected agenda scope
535 that are marked with the ARCHIVE tag will be included anyway. When this is
536 t, also all archive files associated with the current selection of agenda
537 files will be included.")
539 (defcustom org-agenda-skip-comment-trees t
540 "Non-nil means skip trees that start with the COMMENT keyword.
541 When nil, these trees are also scanned by agenda commands."
542 :group
'org-agenda-skip
545 (defcustom org-agenda-todo-list-sublevels t
546 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
547 When nil, the sublevels of a TODO entry are not checked, resulting in
548 potentially much shorter TODO lists."
549 :group
'org-agenda-skip
550 :group
'org-agenda-todo-list
553 (defcustom org-agenda-todo-ignore-with-date nil
554 "Non-nil means don't show entries with a date in the global todo list.
555 You can use this if you prefer to mark mere appointments with a TODO keyword,
556 but don't want them to show up in the TODO list.
557 When this is set, it also covers deadlines and scheduled items, the settings
558 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
560 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
561 :group
'org-agenda-skip
562 :group
'org-agenda-todo-list
565 (defcustom org-agenda-todo-ignore-scheduled nil
566 "Non-nil means, ignore some scheduled TODO items when making TODO list.
567 This applies when creating the global todo list.
570 past Don't show entries scheduled today or in the past.
572 future Don't show entries scheduled in the future.
573 The idea behind this is that by scheduling it, you don't want to
574 think about it until the scheduled date.
576 all Don't show any scheduled entries in the global todo list.
577 The idea behind this is that by scheduling it, you have already
578 \"taken care\" of this item.
580 t Same as `all', for backward compatibility.
582 See also `org-agenda-todo-ignore-with-date'.
583 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
584 to make his option also apply to the tags-todo list."
585 :group
'org-agenda-skip
586 :group
'org-agenda-todo-list
588 (const :tag
"Ignore future-scheduled todos" future
)
589 (const :tag
"Ignore past- or present-scheduled todos" past
)
590 (const :tag
"Ignore all scheduled todos" all
)
591 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
592 (const :tag
"Show scheduled todos" nil
)))
594 (defcustom org-agenda-todo-ignore-deadlines nil
595 "Non-nil means ignore some deadlined TODO items when making TODO list.
596 There are different motivations for using different values, please think
597 carefully when configuring this variable.
599 This applies when creating the global todo list.
602 near Don't show near deadline entries. A deadline is near when it is
603 closer than `org-deadline-warning-days' days. The idea behind this
604 is that such items will appear in the agenda anyway.
606 far Don't show TODO entries where a deadline has been defined, but
607 the deadline is not near. This is useful if you don't want to
608 use the todo list to figure out what to do now.
610 past Don't show entries with a deadline timestamp for today or in the past.
612 future Don't show entries with a deadline timestamp in the future, not even
613 when they become `near' ones. Use it with caution.
615 all Ignore all TODO entries that do have a deadline.
617 t Same as `near', for backward compatibility.
619 See also `org-agenda-todo-ignore-with-date'.
620 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
621 to make his option also apply to the tags-todo list."
622 :group
'org-agenda-skip
623 :group
'org-agenda-todo-list
625 (const :tag
"Ignore near deadlines" near
)
626 (const :tag
"Ignore near deadlines (compatibility)" t
)
627 (const :tag
"Ignore far deadlines" far
)
628 (const :tag
"Ignore all TODOs with a deadlines" all
)
629 (const :tag
"Show all TODOs, even if they have a deadline" nil
)))
631 (defcustom org-agenda-tags-todo-honor-ignore-options nil
632 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
634 `org-agenda-todo-ignore-with-date',
635 `org-agenda-todo-ignore-scheduled'
636 `org-agenda-todo-ignore-deadlines'
637 make the global TODO list skip entries that have time stamps of certain
638 kinds. If this option is set, the same options will also apply for the
639 tags-todo search, which is the general tags/property matcher
640 restricted to unfinished TODO entries only."
641 :group
'org-agenda-skip
642 :group
'org-agenda-todo-list
643 :group
'org-agenda-match-view
646 (defcustom org-agenda-skip-scheduled-if-done nil
647 "Non-nil means don't show scheduled items in agenda when they are done.
648 This is relevant for the daily/weekly agenda, not for the TODO list. And
649 it applies only to the actual date of the scheduling. Warnings about
650 an item with a past scheduling dates are always turned off when the item
652 :group
'org-agenda-skip
653 :group
'org-agenda-daily
/weekly
656 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
657 "Non-nil means skip scheduling line if same entry shows because of deadline.
658 In the agenda of today, an entry can show up multiple times because
659 it is both scheduled and has a nearby deadline, and maybe a plain time
661 When this variable is t, then only the deadline is shown and the fact that
662 the entry is scheduled today or was scheduled previously is not shown.
663 When this variable is nil, the entry will be shown several times. When
664 the variable is the symbol `not-today', then skip scheduled previously,
665 but not scheduled today."
666 :group
'org-agenda-skip
667 :group
'org-agenda-daily
/weekly
669 (const :tag
"Never" nil
)
670 (const :tag
"Always" t
)
671 (const :tag
"Not when scheduled today" not-today
)))
673 (defcustom org-agenda-skip-deadline-if-done nil
674 "Non-nil means don't show deadlines when the corresponding item is done.
675 When nil, the deadline is still shown and should give you a happy feeling.
676 This is relevant for the daily/weekly agenda. And it applied only to the
677 actually date of the deadline. Warnings about approaching and past-due
678 deadlines are always turned off when the item is DONE."
679 :group
'org-agenda-skip
680 :group
'org-agenda-daily
/weekly
683 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
684 "Non-nil means skip deadline prewarning when entry is also scheduled.
685 This will apply on all days where a prewarning for the deadline would
686 be shown, but not at the day when the entry is actually due. On that day,
687 the deadline will be shown anyway.
688 This variable may be set to nil, t, or a number which will then give
689 the number of days before the actual deadline when the prewarnings
691 This can be used in a workflow where the first showing of the deadline will
692 trigger you to schedule it, and then you don't want to be reminded of it
693 because you will take care of it on the day when scheduled."
694 :group
'org-agenda-skip
695 :group
'org-agenda-daily
/weekly
697 (const :tag
"Alwas show prewarning" nil
)
698 (const :tag
"Remove prewarning if entry is scheduled" t
)
699 (integer :tag
"Restart prewarning N days before deadline")))
701 (defcustom org-agenda-skip-additional-timestamps-same-entry t
702 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
703 When non-nil, after the search for timestamps has matched once in an
704 entry, the rest of the entry will not be searched."
705 :group
'org-agenda-skip
708 (defcustom org-agenda-skip-timestamp-if-done nil
709 "Non-nil means don't select item by timestamp or -range if it is DONE."
710 :group
'org-agenda-skip
711 :group
'org-agenda-daily
/weekly
714 (defcustom org-agenda-dim-blocked-tasks t
715 "Non-nil means dim blocked tasks in the agenda display.
716 This causes some overhead during agenda construction, but if you
717 have turned on `org-enforce-todo-dependencies',
718 `org-enforce-todo-checkbox-dependencies', or any other blocking
719 mechanism, this will create useful feedback in the agenda.
721 Instead of t, this variable can also have the value `invisible'.
722 Then blocked tasks will be invisible and only become visible when
723 they become unblocked. An exemption to this behavior is when a task is
724 blocked because of unchecked checkboxes below it. Since checkboxes do
725 not show up in the agenda views, making this task invisible you remove any
726 trace from agenda views that there is something to do. Therefore, a task
727 that is blocked because of checkboxes will never be made invisible, it
728 will only be dimmed."
729 :group
'org-agenda-daily
/weekly
730 :group
'org-agenda-todo-list
732 (const :tag
"Do not dim" nil
)
733 (const :tag
"Dim to a grey face" t
)
734 (const :tag
"Make invisible" invisible
)))
736 (defcustom org-timeline-show-empty-dates
3
737 "Non-nil means `org-timeline' also shows dates without an entry.
738 When nil, only the days which actually have entries are shown.
739 When t, all days between the first and the last date are shown.
740 When an integer, show also empty dates, but if there is a gap of more than
741 N days, just insert a special line indicating the size of the gap."
742 :group
'org-agenda-skip
744 (const :tag
"None" nil
)
746 (integer :tag
"at most")))
748 (defgroup org-agenda-startup nil
749 "Options concerning initial settings in the Agenda in Org Mode."
750 :tag
"Org Agenda Startup"
753 (defcustom org-agenda-menu-show-matcher t
754 "Non-nil menas show the match string in the agenda dispatcher menu.
755 When nil, the matcher string is not shown, but is put into the help-echo
756 property so than moving the mouse over the command shows it.
757 Setting it to nil is good if matcher strings are very long and/or if
758 you wnat to use two-column display (see `org-agenda-menu-two-column')."
762 (defcustom org-agenda-menu-two-column nil
763 "Non-nil means, use two columns to show custom commands in the dispatcher.
764 If you use this, you probably want to set `org-agenda-menu-show-matcher'
769 (defcustom org-finalize-agenda-hook nil
770 "Hook run just before displaying an agenda buffer."
771 :group
'org-agenda-startup
774 (defcustom org-agenda-mouse-1-follows-link nil
775 "Non-nil means mouse-1 on a link will follow the link in the agenda.
776 A longer mouse click will still set point. Does not work on XEmacs.
777 Needs to be set before org.el is loaded."
778 :group
'org-agenda-startup
781 (defcustom org-agenda-start-with-follow-mode nil
782 "The initial value of follow mode in a newly created agenda window."
783 :group
'org-agenda-startup
786 (defcustom org-agenda-show-outline-path t
787 "Non-nil means show outline path in echo area after line motion."
788 :group
'org-agenda-startup
791 (defcustom org-agenda-start-with-entry-text-mode nil
792 "The initial value of entry-text-mode in a newly created agenda window."
793 :group
'org-agenda-startup
796 (defcustom org-agenda-entry-text-maxlines
5
797 "Number of text lines to be added when `E' is pressed in the agenda.
799 Note that this variable only used during agenda display. Add add entry text
800 when exporting the agenda, configure the variable
801 `org-agenda-add-entry-ext-maxlines'."
805 (defcustom org-agenda-entry-text-exclude-regexps nil
806 "List of regular expressions to clean up entry text.
807 The complete matches of all regular expressions in this list will be
808 removed from entry text before it is shown in the agenda."
810 :type
'(repeat (regexp)))
812 (defvar org-agenda-entry-text-cleanup-hook nil
813 "Hook that is run after basic cleanup of entry text to be shown in agenda.
814 This cleanup is done in a temporary buffer, so the function may inspect and
815 change the entire buffer.
816 Some default stuff like drawers and scheduling/deadline dates will already
817 have been removed when this is called, as will any matches for regular
818 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
820 (defvar org-agenda-include-inactive-timestamps nil
821 "Non-nil means include inactive time stamps in agenda and timeline.")
823 (defgroup org-agenda-windows nil
824 "Options concerning the windows used by the Agenda in Org Mode."
825 :tag
"Org Agenda Windows"
828 (defcustom org-agenda-window-setup
'reorganize-frame
829 "How the agenda buffer should be displayed.
830 Possible values for this option are:
832 current-window Show agenda in the current window, keeping all other windows.
833 other-window Use `switch-to-buffer-other-window' to display agenda.
834 reorganize-frame Show only two windows on the current frame, the current
835 window and the agenda.
836 other-frame Use `switch-to-buffer-other-frame' to display agenda.
837 Also, when exiting the agenda, kill that frame.
838 See also the variable `org-agenda-restore-windows-after-quit'."
839 :group
'org-agenda-windows
841 (const current-window
)
844 (const reorganize-frame
)))
846 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
847 "The min and max height of the agenda window as a fraction of frame height.
848 The value of the variable is a cons cell with two numbers between 0 and 1.
849 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
850 :group
'org-agenda-windows
851 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
853 (defcustom org-agenda-restore-windows-after-quit nil
854 "Non-nil means restore window configuration open exiting agenda.
855 Before the window configuration is changed for displaying the agenda,
856 the current status is recorded. When the agenda is exited with
857 `q' or `x' and this option is set, the old state is restored. If
858 `org-agenda-window-setup' is `other-frame', the value of this
859 option will be ignored."
860 :group
'org-agenda-windows
863 (defcustom org-agenda-ndays
7
864 "Number of days to include in overview display.
866 Custom commands can set this variable in the options section."
867 :group
'org-agenda-daily
/weekly
870 (defcustom org-agenda-start-on-weekday
1
871 "Non-nil means start the overview always on the specified weekday.
872 0 denotes Sunday, 1 denotes Monday etc.
873 When nil, always start on the current day.
874 Custom commands can set this variable in the options section."
875 :group
'org-agenda-daily
/weekly
876 :type
'(choice (const :tag
"Today" nil
)
877 (integer :tag
"Weekday No.")))
879 (defcustom org-agenda-show-all-dates t
880 "Non-nil means `org-agenda' shows every day in the selected range.
881 When nil, only the days which actually have entries are shown."
882 :group
'org-agenda-daily
/weekly
885 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
886 "Format string for displaying dates in the agenda.
887 Used by the daily/weekly agenda and by the timeline. This should be
888 a format string understood by `format-time-string', or a function returning
889 the formatted date as a string. The function must take a single argument,
890 a calendar-style date list like (month day year)."
891 :group
'org-agenda-daily
/weekly
893 (string :tag
"Format string")
894 (function :tag
"Function")))
896 (defun org-agenda-format-date-aligned (date)
897 "Format a date string for display in the daily/weekly agenda, or timeline.
898 This function makes sure that dates are aligned for easy reading."
900 (let* ((dayname (calendar-day-name date
))
902 (day-of-week (calendar-day-of-week date
))
904 (monthname (calendar-month-name month
))
906 (iso-week (org-days-to-iso-week
907 (calendar-absolute-from-gregorian date
)))
908 (weekyear (cond ((and (= month
1) (>= iso-week
52))
910 ((and (= month
12) (<= iso-week
1))
913 (weekstring (if (= day-of-week
1)
914 (format " W%02d" iso-week
)
916 (format "%-10s %2d %s %4d%s"
917 dayname day monthname year weekstring
)))
919 (defcustom org-agenda-time-leading-zero nil
920 "Non-nil means use leading zero for military times in agenda.
921 For example, 9:30am would become 09:30 rather than 9:30."
922 :group
'org-agenda-daily
/weekly
925 (defcustom org-agenda-weekend-days
'(6 0)
926 "Which days are weekend?
927 These days get the special face `org-agenda-date-weekend' in the agenda
928 and timeline buffers."
929 :group
'org-agenda-daily
/weekly
930 :type
'(set :greedy t
931 (const :tag
"Monday" 1)
932 (const :tag
"Tuesday" 2)
933 (const :tag
"Wednesday" 3)
934 (const :tag
"Thursday" 4)
935 (const :tag
"Friday" 5)
936 (const :tag
"Saturday" 6)
937 (const :tag
"Sunday" 0)))
939 (defcustom org-agenda-include-diary nil
940 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
941 Custom commands can set this variable in the options section."
942 :group
'org-agenda-daily
/weekly
945 (defcustom org-agenda-include-deadlines t
946 "If non-nil, include entries within their deadline warning period.
947 Custom commands can set this variable in the options section."
948 :group
'org-agenda-daily
/weekly
951 (defcustom org-agenda-include-all-todo nil
952 "Set means weekly/daily agenda will always contain all TODO entries.
953 The TODO entries will be listed at the top of the agenda, before
954 the entries for specific days.
955 This option is deprecated, it is better to define a block agenda instead."
956 :group
'org-agenda-daily
/weekly
959 (defcustom org-agenda-repeating-timestamp-show-all t
960 "Non-nil means show all occurrences of a repeating stamp in the agenda.
961 When nil, only one occurrence is shown, either today or the
962 nearest into the future."
963 :group
'org-agenda-daily
/weekly
966 (defcustom org-scheduled-past-days
10000
967 "No. of days to continue listing scheduled items that are not marked DONE.
968 When an item is scheduled on a date, it shows up in the agenda on this
969 day and will be listed until it is marked done for the number of days
971 :group
'org-agenda-daily
/weekly
974 (defcustom org-agenda-log-mode-items
'(closed clock
)
975 "List of items that should be shown in agenda log mode.
976 This list may contain the following symbols:
978 closed Show entries that have been closed on that day.
979 clock Show entries that have received clocked time on that day.
980 state Show all logged state changes.
981 Note that instead of changing this variable, you can also press `C-u l' in
982 the agenda to display all available LOG items temporarily."
983 :group
'org-agenda-daily
/weekly
984 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
986 (defcustom org-agenda-log-mode-add-notes t
987 "Non-nil means add first line of notes to log entries in agenda views.
988 If a log item like a state change or a clock entry is associated with
989 notes, the first line of these notes will be added to the entry in the
991 :group
'org-agenda-daily
/weekly
994 (defcustom org-agenda-start-with-log-mode nil
995 "The initial value of log-mode in a newly created agenda window."
996 :group
'org-agenda-startup
997 :group
'org-agenda-daily
/weekly
1000 (defcustom org-agenda-start-with-clockreport-mode nil
1001 "The initial value of clockreport-mode in a newly created agenda window."
1002 :group
'org-agenda-startup
1003 :group
'org-agenda-daily
/weekly
1006 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1007 "Property list with parameters for the clocktable in clockreport mode.
1008 This is the display mode that shows a clock table in the daily/weekly
1009 agenda, the properties for this dynamic block can be set here.
1010 The usual clocktable parameters are allowed here, but you cannot set
1011 the properties :name, :tstart, :tend, :block, and :scope - these will
1012 be overwritten to make sure the content accurately reflects the
1013 current display in the agenda."
1014 :group
'org-agenda-daily
/weekly
1017 (defcustom org-agenda-search-view-always-boolean nil
1018 "Non-nil means the search string is interpreted as individual parts.
1020 The search string for search view can either be interpreted as a phrase,
1021 or as a list of snippets that define a boolean search for a number of
1024 When this is non-nil, the string will be split on whitespace, and each
1025 snippet will be searched individually, and all must match in order to
1026 select an entry. A snippet is then a single string of non-white
1027 characters, or a string in double quotes, or a regexp in {} braces.
1028 If a snippet is preceded by \"-\", the snippet must *not* match.
1029 \"+\" is syntactic sugar for positive selection. Each snippet may
1030 be found as a full word or a partial word, but see the variable
1031 `org-agenda-search-view-force-full-words'.
1033 When this is nil, search will look for the entire search phrase as one,
1034 with each space character matching any amount of whitespace, including
1037 Even when this is nil, you can still switch to Boolean search dynamically
1038 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1039 is a regexp marked with braces like \"{abc}\", this will also switch to
1041 :group
'org-agenda-search-view
1044 (if (fboundp 'defvaralias
)
1045 (defvaralias 'org-agenda-search-view-search-words-only
1046 'org-agenda-search-view-always-boolean
))
1048 (defcustom org-agenda-search-view-force-full-words nil
1049 "Non-nil means, search words must be matches as complete words.
1050 When nil, they may also match part of a word."
1051 :group
'org-agenda-search-view
1054 (defgroup org-agenda-time-grid nil
1055 "Options concerning the time grid in the Org-mode Agenda."
1056 :tag
"Org Agenda Time Grid"
1059 (defcustom org-agenda-search-headline-for-time t
1060 "Non-nil means search headline for a time-of-day.
1061 If the headline contains a time-of-day in one format or another, it will
1062 be used to sort the entry into the time sequence of items for a day.
1063 Some people have time stamps in the headline that refer to the creation
1064 time or so, and then this produces an unwanted side effect. If this is
1065 the case for your, use this variable to turn off searching the headline
1067 :group
'org-agenda-time-grid
1070 (defcustom org-agenda-use-time-grid t
1071 "Non-nil means show a time grid in the agenda schedule.
1072 A time grid is a set of lines for specific times (like every two hours between
1073 8:00 and 20:00). The items scheduled for a day at specific times are
1074 sorted in between these lines.
1075 For details about when the grid will be shown, and what it will look like, see
1076 the variable `org-agenda-time-grid'."
1077 :group
'org-agenda-time-grid
1080 (defcustom org-agenda-time-grid
1081 '((daily today require-timed
)
1083 (800 1000 1200 1400 1600 1800 2000))
1085 "The settings for time grid for agenda display.
1086 This is a list of three items. The first item is again a list. It contains
1087 symbols specifying conditions when the grid should be displayed:
1089 daily if the agenda shows a single day
1090 weekly if the agenda shows an entire week
1091 today show grid on current date, independent of daily/weekly display
1092 require-timed show grid only if at least one item has a time specification
1094 The second item is a string which will be placed behind the grid time.
1096 The third item is a list of integers, indicating the times that should have
1098 :group
'org-agenda-time-grid
1101 (set :greedy t
:tag
"Grid Display Options"
1102 (const :tag
"Show grid in single day agenda display" daily
)
1103 (const :tag
"Show grid in weekly agenda display" weekly
)
1104 (const :tag
"Always show grid for today" today
)
1105 (const :tag
"Show grid only if any timed entries are present"
1107 (const :tag
"Skip grid times already present in an entry"
1109 (string :tag
"Grid String")
1110 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1112 (defgroup org-agenda-sorting nil
1113 "Options concerning sorting in the Org-mode Agenda."
1114 :tag
"Org Agenda Sorting"
1117 (defcustom org-agenda-sorting-strategy
1118 '((agenda habit-down time-up priority-down category-keep
)
1119 (todo priority-down category-keep
)
1120 (tags priority-down category-keep
)
1121 (search category-keep
))
1122 "Sorting structure for the agenda items of a single day.
1123 This is a list of symbols which will be used in sequence to determine
1124 if an entry should be listed before another entry. The following
1125 symbols are recognized:
1127 time-up Put entries with time-of-day indications first, early first
1128 time-down Put entries with time-of-day indications first, late first
1129 category-keep Keep the default order of categories, corresponding to the
1130 sequence in `org-agenda-files'.
1131 category-up Sort alphabetically by category, A-Z.
1132 category-down Sort alphabetically by category, Z-A.
1133 tag-up Sort alphabetically by last tag, A-Z.
1134 tag-down Sort alphabetically by last tag, Z-A.
1135 priority-up Sort numerically by priority, high priority last.
1136 priority-down Sort numerically by priority, high priority first.
1137 todo-state-up Sort by todo state, tasks that are done last.
1138 todo-state-down Sort by todo state, tasks that are done first.
1139 effort-up Sort numerically by estimated effort, high effort last.
1140 effort-down Sort numerically by estimated effort, high effort first.
1141 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1142 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1143 habit-up Put entries that are habits first
1144 habit-down Put entries that are habits last
1145 alpha-up Sort headlines alphabetically
1146 alpha-down Sort headlines alphabetically, reversed
1148 The different possibilities will be tried in sequence, and testing stops
1149 if one comparison returns a \"not-equal\". For example, the default
1150 '(time-up category-keep priority-down)
1151 means: Pull out all entries having a specified time of day and sort them,
1152 in order to make a time schedule for the current day the first thing in the
1153 agenda listing for the day. Of the entries without a time indication, keep
1154 the grouped in categories, don't sort the categories, but keep them in
1155 the sequence given in `org-agenda-files'. Within each category sort by
1158 Leaving out `category-keep' would mean that items will be sorted across
1159 categories by priority.
1161 Instead of a single list, this can also be a set of list for specific
1162 contents, with a context symbol in the car of the list, any of
1163 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1165 Custom commands can bind this variable in the options section."
1166 :group
'org-agenda-sorting
1168 (repeat :tag
"General" ,org-sorting-choice
)
1169 (list :tag
"Individually"
1170 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1171 (repeat ,org-sorting-choice
))
1172 (cons (const :tag
"Strategy for TODO lists" todo
)
1173 (repeat ,org-sorting-choice
))
1174 (cons (const :tag
"Strategy for Tags matches" tags
)
1175 (repeat ,org-sorting-choice
))
1176 (cons (const :tag
"Strategy for search matches" search
)
1177 (repeat ,org-sorting-choice
)))))
1179 (defcustom org-agenda-cmp-user-defined nil
1180 "A function to define the comparison `user-defined'.
1181 This function must receive two arguments, agenda entry a and b.
1182 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1183 the user comparison, return nil.
1184 When this is defined, you can make `user-defined-up' and `user-defined-down'
1185 part of an agenda sorting strategy."
1186 :group
'org-agenda-sorting
1189 (defcustom org-sort-agenda-notime-is-late t
1190 "Non-nil means items without time are considered late.
1191 This is only relevant for sorting. When t, items which have no explicit
1192 time like 15:30 will be considered as 99:01, i.e. later than any items which
1193 do have a time. When nil, the default time is before 0:00. You can use this
1194 option to decide if the schedule for today should come before or after timeless
1196 :group
'org-agenda-sorting
1199 (defcustom org-sort-agenda-noeffort-is-high t
1200 "Non-nil means items without effort estimate are sorted as high effort.
1201 This also applies when filtering an agenda view with respect to the
1202 < or > effort operator. Then, tasks with no effort defined will be treated
1203 as tasks with high effort.
1204 When nil, such items are sorted as 0 minutes effort."
1205 :group
'org-agenda-sorting
1208 (defgroup org-agenda-line-format nil
1209 "Options concerning the entry prefix in the Org-mode agenda display."
1210 :tag
"Org Agenda Line Format"
1213 (defcustom org-agenda-prefix-format
1214 '((agenda .
" %-12:c%?-12t% s")
1218 (search .
" %-12:c"))
1219 "Format specifications for the prefix of items in the agenda views.
1220 An alist with four entries, for the different agenda types. The keys to the
1221 sublists are `agenda', `timeline', `todo', and `tags'. The values
1223 This format works similar to a printf format, with the following meaning:
1225 %c the category of the item, \"Diary\" for entries from the diary, or
1226 as given by the CATEGORY keyword or derived from the file name.
1227 %T the *last* tag of the item. Last because inherited tags come
1229 %t the time-of-day specification if one applies to the entry, in the
1231 %s Scheduling/Deadline information, a short string
1233 All specifiers work basically like the standard `%s' of printf, but may
1234 contain two additional characters: A question mark just after the `%' and
1235 a whitespace/punctuation character just before the final letter.
1237 If the first character after `%' is a question mark, the entire field
1238 will only be included if the corresponding value applies to the
1239 current entry. This is useful for fields which should have fixed
1240 width when present, but zero width when absent. For example,
1241 \"%?-12t\" will result in a 12 character time field if a time of the
1242 day is specified, but will completely disappear in entries which do
1245 If there is punctuation or whitespace character just before the final
1246 format letter, this character will be appended to the field value if
1247 the value is not empty. For example, the format \"%-12:c\" leads to
1248 \"Diary: \" if the category is \"Diary\". If the category were be
1249 empty, no additional colon would be inserted.
1251 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1252 - Indent the line with two space characters
1253 - Give the category in a 12 chars wide field, padded with whitespace on
1254 the right (because of `-'). Append a colon if there is a category
1256 - If there is a time-of-day, put it into a 12 chars wide field. If no
1257 time, don't put in an empty field, just skip it (because of '?').
1258 - Finally, put the scheduling information and append a whitespace.
1260 As another example, if you don't want the time-of-day of entries in
1261 the prefix, you could use:
1263 (setq org-agenda-prefix-format \" %-11:c% s\")
1265 See also the variables `org-agenda-remove-times-when-in-prefix' and
1266 `org-agenda-remove-tags'.
1268 Custom commands can set this variable in the options section."
1270 (string :tag
"General format")
1271 (list :greedy t
:tag
"View dependent"
1272 (cons (const agenda
) (string :tag
"Format"))
1273 (cons (const timeline
) (string :tag
"Format"))
1274 (cons (const todo
) (string :tag
"Format"))
1275 (cons (const tags
) (string :tag
"Format"))
1276 (cons (const search
) (string :tag
"Format"))))
1277 :group
'org-agenda-line-format
)
1279 (defvar org-prefix-format-compiled nil
1280 "The compiled version of the most recently used prefix format.
1281 See the variable `org-agenda-prefix-format'.")
1283 (defcustom org-agenda-todo-keyword-format
"%-1s"
1284 "Format for the TODO keyword in agenda lines.
1285 Set this to something like \"%-12s\" if you want all TODO keywords
1286 to occupy a fixed space in the agenda display."
1287 :group
'org-agenda-line-format
1290 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1291 "Text preceding timerange entries in the agenda view.
1292 This is a list with two strings. The first applies when the range
1293 is entirely on one day. The second applies if the range spans several days.
1294 The strings may have two \"%d\" format specifiers which will be filled
1295 with the sequence number of the days, and the total number of days in the
1296 range, respectively."
1297 :group
'org-agenda-line-format
1299 (string :tag
"Deadline today ")
1300 (choice :tag
"Deadline relative"
1301 (string :tag
"Format string")
1304 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1305 "Text preceding scheduled items in the agenda view.
1306 This is a list with two strings. The first applies when the item is
1307 scheduled on the current day. The second applies when it has been scheduled
1308 previously, it may contain a %d indicating that this is the nth time that
1309 this item is scheduled, due to automatic rescheduling of unfinished items
1310 for the following day. So this number is one larger than the number of days
1311 that passed since this item was scheduled first."
1312 :group
'org-agenda-line-format
1314 (string :tag
"Scheduled today ")
1315 (string :tag
"Scheduled previously")))
1317 (defcustom org-agenda-inactive-leader
"["
1318 "Text preceding item pulled into the agenda by inactive time stamps.
1319 These entries are added to the agenda when pressing \"[\"."
1320 :group
'org-agenda-line-format
1322 (string :tag
"Scheduled today ")
1323 (string :tag
"Scheduled previously")))
1325 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1326 "Text preceding deadline items in the agenda view.
1327 This is a list with two strings. The first applies when the item has its
1328 deadline on the current day. The second applies when it is in the past or
1329 in the future, it may contain %d to capture how many days away the deadline
1331 :group
'org-agenda-line-format
1333 (string :tag
"Deadline today ")
1334 (choice :tag
"Deadline relative"
1335 (string :tag
"Format string")
1338 (defcustom org-agenda-remove-times-when-in-prefix t
1339 "Non-nil means remove duplicate time specifications in agenda items.
1340 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1341 time-of-day specification in a headline or diary entry is extracted and
1342 placed into the prefix. If this option is non-nil, the original specification
1343 \(a timestamp or -range, or just a plain time(range) specification like
1344 11:30-4pm) will be removed for agenda display. This makes the agenda less
1346 The option can be t or nil. It may also be the symbol `beg', indicating
1347 that the time should only be removed when it is located at the beginning of
1348 the headline/diary entry."
1349 :group
'org-agenda-line-format
1351 (const :tag
"Always" t
)
1352 (const :tag
"Never" nil
)
1353 (const :tag
"When at beginning of entry" beg
)))
1355 (defcustom org-agenda-remove-timeranges-from-blocks nil
1356 "Non-nil means remove time ranges specifications in agenda
1357 items that span on several days."
1358 :group
'org-agenda-line-format
1361 (defcustom org-agenda-default-appointment-duration nil
1362 "Default duration for appointments that only have a starting time.
1363 When nil, no duration is specified in such cases.
1364 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1365 :group
'org-agenda-line-format
1367 (integer :tag
"Minutes")
1368 (const :tag
"No default duration")))
1370 (defcustom org-agenda-show-inherited-tags t
1371 "Non-nil means show inherited tags in each agenda line."
1372 :group
'org-agenda-line-format
1375 (defcustom org-agenda-hide-tags-regexp nil
1376 "Regular expression used to filter away specific tags in agenda views.
1377 This means that these tags will be present, but not be shown in the agenda
1378 line. Secondary filtering will still work on the hidden tags.
1379 Nil means don't hide any tags."
1380 :group
'org-agenda-line-format
1382 (const :tag
"Hide none" nil
)
1383 (string :tag
"Regexp ")))
1385 (defcustom org-agenda-remove-tags nil
1386 "Non-nil means remove the tags from the headline copy in the agenda.
1387 When this is the symbol `prefix', only remove tags when
1388 `org-agenda-prefix-format' contains a `%T' specifier."
1389 :group
'org-agenda-line-format
1391 (const :tag
"Always" t
)
1392 (const :tag
"Never" nil
)
1393 (const :tag
"When prefix format contains %T" prefix
)))
1395 (if (fboundp 'defvaralias
)
1396 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1397 'org-agenda-remove-tags
))
1399 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1400 "Shift tags in agenda items to this column.
1401 If this number is positive, it specifies the column. If it is negative,
1402 it means that the tags should be flushright to that column. For example,
1403 -80 works well for a normal 80 character screen."
1404 :group
'org-agenda-line-format
1407 (if (fboundp 'defvaralias
)
1408 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1410 (defcustom org-agenda-fontify-priorities
'cookies
1411 "Non-nil means highlight low and high priorities in agenda.
1412 When t, the highest priority entries are bold, lowest priority italic.
1413 However, settings in `org-priority-faces' will overrule these faces.
1414 When this variable is the symbol `cookies', only fontify the
1415 cookies, not the entire task.
1416 This may also be an association list of priority faces, whose
1417 keys are the character values of `org-highest-priority',
1418 `org-default-priority', and `org-lowest-priority' (the default values
1419 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1420 color as a string, or a list like `(:background \"Red\")'.
1421 If it is a color, the variable `org-faces-easy-properties'
1422 determines if it is a foreground or a background color."
1423 :group
'org-agenda-line-format
1425 (const :tag
"Never" nil
)
1426 (const :tag
"Defaults" t
)
1427 (const :tag
"Cookies only" cookies
)
1428 (repeat :tag
"Specify"
1429 (list (character :tag
"Priority" :value ?A
)
1430 (choice :tag
"Face "
1431 (string :tag
"Color")
1432 (sexp :tag
"Face"))))))
1434 (defgroup org-agenda-column-view nil
1435 "Options concerning column view in the agenda."
1436 :tag
"Org Agenda Column View"
1439 (defcustom org-agenda-columns-show-summaries t
1440 "Non-nil means show summaries for columns displayed in the agenda view."
1441 :group
'org-agenda-column-view
1444 (defcustom org-agenda-columns-remove-prefix-from-item t
1445 "Non-nil means remove the prefix from a headline for agenda column view.
1446 The special ITEM field in the columns format contains the current line, with
1447 all information shown in other columns (like the TODO state or a tag).
1448 When this variable is non-nil, also the agenda prefix will be removed from
1449 the content of the ITEM field, to make sure as much as possible of the
1450 headline can be shown in the limited width of the field."
1454 (defcustom org-agenda-columns-compute-summary-properties t
1455 "Non-nil means recompute all summary properties before column view.
1456 When column view in the agenda is listing properties that have a summary
1457 operator, it can go to all relevant buffers and recompute the summaries
1458 there. This can mean overhead for the agenda column view, but is necessary
1459 to have thing up to date.
1460 As a special case, a CLOCKSUM property also makes sure that the clock
1461 computations are current."
1462 :group
'org-agenda-column-view
1465 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1466 "Non-nil means the duration of an appointment will add to day effort.
1467 The property to which appointment durations will be added is the one given
1468 in the option `org-effort-property'. If an appointment does not have
1469 an end time, `org-agenda-default-appointment-duration' will be used. If that
1470 is not set, an appointment without end time will not contribute to the time
1472 :group
'org-agenda-column-view
1475 (defcustom org-agenda-auto-exclude-function nil
1476 "A function called with a tag to decide if it is filtered on '/ RET'.
1477 The sole argument to the function, which is called once for each
1478 possible tag, is a string giving the name of the tag. The
1479 function should return either nil if the tag should be included
1480 as normal, or \"-<TAG>\" to exclude the tag.
1481 Note that for the purpose of tag filtering, only the lower-case version of
1482 all tags will be considered, so that this function will only ever see
1483 the lower-case version of all tags."
1491 (defun org-add-agenda-custom-command (entry)
1492 "Replace or add a command in `org-agenda-custom-commands'.
1493 This is mostly for hacking and trying a new command - once the command
1494 works you probably want to add it to `org-agenda-custom-commands' for good."
1495 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1497 (setcdr ass
(cdr entry
))
1498 (push entry org-agenda-custom-commands
))))
1500 ;;; Define the Org-agenda-mode
1502 (defvar org-agenda-mode-map
(make-sparse-keymap)
1503 "Keymap for `org-agenda-mode'.")
1504 (if (fboundp 'defvaralias
)
1505 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1507 (defvar org-agenda-menu
) ; defined later in this file.
1508 (defvar org-agenda-restrict
) ; defined later in this file.
1509 (defvar org-agenda-follow-mode nil
)
1510 (defvar org-agenda-entry-text-mode nil
)
1511 (defvar org-agenda-clockreport-mode nil
)
1512 (defvar org-agenda-show-log nil
)
1513 (defvar org-agenda-redo-command nil
)
1514 (defvar org-agenda-query-string nil
)
1515 (defvar org-agenda-mode-hook nil
1516 "Hook for `org-agenda-mode', run after the mode is turned on.")
1517 (defvar org-agenda-type nil
)
1518 (defvar org-agenda-force-single-file nil
)
1519 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1521 (defun org-agenda-mode ()
1522 "Mode for time-sorted view on action items in Org-mode files.
1524 The following commands are available:
1526 \\{org-agenda-mode-map}"
1528 (kill-all-local-variables)
1529 (setq org-agenda-undo-list nil
1530 org-agenda-pending-undo-list nil
1531 org-agenda-bulk-marked-entries nil
)
1532 (setq major-mode
'org-agenda-mode
)
1533 ;; Keep global-font-lock-mode from turning on font-lock-mode
1534 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1535 (setq mode-name
"Org-Agenda")
1536 (use-local-map org-agenda-mode-map
)
1537 (easy-menu-add org-agenda-menu
)
1538 (if org-startup-truncated
(setq truncate-lines t
))
1539 (org-set-local 'line-move-visual nil
)
1540 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1541 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1542 ;; Make sure properties are removed when copying text
1543 (when (boundp 'buffer-substring-filters
)
1544 (org-set-local 'buffer-substring-filters
1546 (set-text-properties 0 (length x
) nil x
) x
)
1547 buffer-substring-filters
)))
1548 (unless org-agenda-keep-modes
1549 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1550 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1551 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1552 org-agenda-show-log org-agenda-start-with-log-mode
))
1555 '("Agenda") "Agenda Files"
1559 (if (get 'org-agenda-files
'org-restrict
)
1560 "Restricted to single file"
1562 '(org-edit-agenda-file-list)
1563 (not (get 'org-agenda-files
'org-restrict
)))
1565 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1566 (org-agenda-set-mode-name)
1568 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1569 (list 'org-agenda-mode-hook
)))
1571 (substitute-key-definition 'undo
'org-agenda-undo
1572 org-agenda-mode-map global-map
)
1573 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1574 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1575 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1576 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1577 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1578 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1579 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1580 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1581 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1582 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1583 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1584 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1585 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1586 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1587 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1588 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1589 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1590 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1591 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1592 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1593 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1594 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1595 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1596 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1597 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1598 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1599 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1600 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1601 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1602 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1603 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1604 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1605 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1606 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1607 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1608 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1609 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1610 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1611 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1612 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1613 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1614 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1615 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1617 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1618 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1619 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1620 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1621 (while l (org-defkey org-agenda-mode-map
1622 (int-to-string (pop l)) 'digit-argument)))
1624 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1625 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1626 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1627 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1628 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1629 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1630 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1631 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1632 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1633 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1634 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1635 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1636 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1637 'org-clock-modify-effort-estimate)
1638 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1639 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1640 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1641 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1642 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1643 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1644 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1645 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1646 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1647 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1648 (substitute-key-definition 'next-line 'org-agenda-next-line
1649 org-agenda-mode-map global-map)
1650 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1651 org-agenda-mode-map global-map)
1652 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1653 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1654 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1655 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1656 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1657 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1658 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1659 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1660 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1661 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1662 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1663 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1664 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1665 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1666 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1667 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1668 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1669 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1670 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1671 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1672 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1673 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1674 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1675 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1676 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1677 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1678 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1679 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1680 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1681 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1683 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1684 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1685 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1686 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1687 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1688 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1689 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1690 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1691 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1692 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1694 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1695 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1696 (when org-agenda-mouse-1-follows-link
1697 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1698 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1703 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1704 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1705 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1706 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1709 ["Day View" org-agenda-day-view
1710 :active (org-agenda-check-type nil 'agenda)
1711 :style radio :selected (equal org-agenda-ndays 1)
1712 :keys "v d (or just d)"]
1713 ["Week View" org-agenda-week-view
1714 :active (org-agenda-check-type nil 'agenda)
1715 :style radio :selected (equal org-agenda-ndays 7)
1716 :keys "v w (or just w)"]
1717 ["Month View" org-agenda-month-view
1718 :active (org-agenda-check-type nil 'agenda)
1719 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1721 ["Year View" org-agenda-year-view
1722 :active (org-agenda-check-type nil 'agenda)
1723 :style radio :selected (member org-agenda-ndays '(365 366))
1726 ["Include Diary" org-agenda-toggle-diary
1727 :style toggle :selected org-agenda-include-diary
1728 :active (org-agenda-check-type nil 'agenda)]
1729 ["Include Deadlines" org-agenda-toggle-deadlines
1730 :style toggle :selected org-agenda-include-deadlines
1731 :active (org-agenda-check-type nil 'agenda)]
1732 ["Use Time Grid" org-agenda-toggle-time-grid
1733 :style toggle :selected org-agenda-use-time-grid
1734 :active (org-agenda-check-type nil 'agenda)]
1736 ["Show clock report" org-agenda-clockreport-mode
1737 :style toggle :selected org-agenda-clockreport-mode
1738 :active (org-agenda-check-type nil 'agenda)]
1739 ["Show some entry text" org-agenda-entry-text-mode
1740 :style toggle :selected org-agenda-entry-text-mode
1743 ["Show Logbook entries" org-agenda-log-mode
1744 :style toggle :selected org-agenda-show-log
1745 :active (org-agenda-check-type nil 'agenda 'timeline)
1746 :keys "v l (or just l)"]
1747 ["Include archived trees" org-agenda-archives-mode
1748 :style toggle :selected org-agenda-archives-mode :active t
1750 ["Include archive files" (org-agenda-archives-mode t)
1751 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1754 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1755 ["Write view to file" org-write-agenda t]
1756 ["Rebuild buffer" org-agenda-redo t]
1757 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1759 ["Show original entry" org-agenda-show t]
1760 ["Go To (other window)" org-agenda-goto t]
1761 ["Go To (this window)" org-agenda-switch-to t]
1762 ["Follow Mode" org-agenda-follow-mode
1763 :style toggle :selected org-agenda-follow-mode :active t]
1764 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1767 ["Cycle TODO" org-agenda-todo t]
1768 ["Next TODO set" org-agenda-todo-nextset t]
1769 ["Previous TODO set" org-agenda-todo-previousset t]
1770 ["Add note" org-agenda-add-note t])
1771 ("Archive/Refile/Delete"
1772 ["Archive default" org-agenda-archive-default t]
1773 ["Archive default" org-agenda-archive-default-with-confirmation t]
1774 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1775 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1776 ["Archive subtree" org-agenda-archive t]
1778 ["Refile" org-agenda-refile t]
1780 ["Delete subtree" org-agenda-kill t])
1782 ["Mark entry" org-agenda-bulk-mark t]
1783 ["Unmark entry" org-agenda-bulk-unmark t]
1784 ["Act on all marked" org-agenda-bulk-action t]
1785 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1787 ("Tags and Properties"
1788 ["Show all Tags" org-agenda-show-tags t]
1789 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1790 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1792 ["Column View" org-columns t])
1793 ("Deadline/Schedule"
1794 ["Schedule" org-agenda-schedule t]
1795 ["Set Deadline" org-agenda-deadline t]
1797 ["Mark item" org-agenda-action :active t :keys "k m"]
1798 ["Show mark item" org-agenda-action :active t :keys "k v"]
1799 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1800 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1802 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1803 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1804 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1805 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1806 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1807 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1808 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1810 ["Clock in" org-agenda-clock-in t]
1811 ["Clock out" org-agenda-clock-out t]
1812 ["Clock cancel" org-agenda-clock-cancel t]
1813 ["Goto running clock" org-clock-goto t]
1815 ["Set Effort" org-agenda-set-effort t]
1816 ["Change clocked effort" org-clock-modify-effort-estimate
1817 (org-clock-is-active)])
1819 ["Set Priority" org-agenda-priority t]
1820 ["Increase Priority" org-agenda-priority-up t]
1821 ["Decrease Priority" org-agenda-priority-down t]
1822 ["Show Priority" org-agenda-show-priority t])
1824 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1825 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1826 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1827 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1828 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1829 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1831 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1833 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1836 ["Push Files and Views" org-mobile-push t]
1837 ["Get Captured and Flagged" org-mobile-pull t]
1838 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1839 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1841 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1843 ["Quit" org-agenda-quit t]
1844 ["Exit and Release Buffers" org-agenda-exit t]
1849 (defvar org-agenda-allow-remote-undo t
1850 "Non-nil means allow remote undo from the agenda buffer.")
1851 (defvar org-agenda-undo-list nil
1852 "List of undoable operations in the agenda since last refresh.")
1853 (defvar org-agenda-undo-has-started-in nil
1854 "Buffers that have already seen `undo-start' in the current undo sequence.")
1855 (defvar org-agenda-pending-undo-list nil
1856 "In a series of undo commands, this is the list of remaining undo items.")
1859 (defun org-agenda-undo ()
1860 "Undo a remote editing step in the agenda.
1861 This undoes changes both in the agenda buffer and in the remote buffer
1862 that have been changed along."
1864 (or org-agenda-allow-remote-undo
1865 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1866 (if (not (eq this-command last-command))
1867 (setq org-agenda-undo-has-started-in nil
1868 org-agenda-pending-undo-list org-agenda-undo-list))
1869 (if (not org-agenda-pending-undo-list)
1870 (error "No further undo information"))
1871 (let* ((entry (pop org-agenda-pending-undo-list))
1872 buf line cmd rembuf)
1873 (setq cmd (pop entry) line (pop entry))
1874 (setq rembuf (nth 2 entry))
1875 (org-with-remote-undo rembuf
1876 (while (bufferp (setq buf (pop entry)))
1878 (with-current-buffer buf
1879 (let ((last-undo-buffer buf)
1880 (inhibit-read-only t))
1881 (unless (memq buf org-agenda-undo-has-started-in)
1882 (push buf org-agenda-undo-has-started-in)
1883 (make-local-variable 'pending-undo-list)
1885 (while (and pending-undo-list
1886 (listp pending-undo-list)
1887 (not (car pending-undo-list)))
1888 (pop pending-undo-list))
1890 (org-goto-line line)
1891 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1893 (defun org-verify-change-for-undo (l1 l2)
1894 "Verify that a real change occurred between the undo lists L1 and L2."
1895 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1896 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1901 (defvar org-agenda-restrict nil)
1902 (defvar org-agenda-restrict-begin (make-marker))
1903 (defvar org-agenda-restrict-end (make-marker))
1904 (defvar org-agenda-last-dispatch-buffer nil)
1905 (defvar org-agenda-overriding-restriction nil)
1908 (defun org-agenda (&optional arg keys restriction)
1909 "Dispatch agenda commands to collect entries to the agenda buffer.
1910 Prompts for a command to execute. Any prefix arg will be passed
1911 on to the selected command. The default selections are:
1913 a Call `org-agenda-list' to display the agenda for current day or week.
1914 t Call `org-todo-list' to display the global todo list.
1915 T Call `org-todo-list' to display the global todo list, select only
1916 entries with a specific TODO keyword (the user gets a prompt).
1917 m Call `org-tags-view' to display headlines with tags matching
1918 a condition (the user is prompted for the condition).
1919 M Like `m', but select only TODO entries, no ordinary headlines.
1920 L Create a timeline for the current buffer.
1921 e Export views to associated files.
1922 s Search entries for keywords.
1923 / Multi occur across all agenda files and also files listed
1924 in `org-agenda-text-search-extra-files'.
1925 < Restrict agenda commands to buffer, subtree, or region.
1926 Press several times to get the desired effect.
1927 > Remove a previous restriction.
1928 # List \"stuck\" projects.
1929 ! Configure what \"stuck\" means.
1930 C Configure custom agenda commands.
1932 More commands can be added by configuring the variable
1933 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1934 searches can be pre-defined in this way.
1936 If the current buffer is in Org-mode and visiting a file, you can also
1937 first press `<' once to indicate that the agenda should be temporarily
1938 \(until the next use of \\[org-agenda]) restricted to the current file.
1939 Pressing `<' twice means to restrict to the current subtree or region
1943 (let* ((prefix-descriptions nil)
1944 (org-agenda-window-setup (if (equal (buffer-name)
1945 org-agenda-buffer-name)
1947 org-agenda-window-setup))
1948 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1949 (org-agenda-custom-commands
1950 ;; normalize different versions
1954 (cond ((stringp (cdr x))
1955 (push x prefix-descriptions)
1957 ((stringp (nth 1 x)) x)
1958 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1959 (t (cons (car x) (cons "" (cdr x))))))
1960 org-agenda-custom-commands)))
1961 (buf (current-buffer))
1962 (bfn (buffer-file-name (buffer-base-buffer)))
1963 entry key type match lprops ans)
1964 ;; Turn off restriction unless there is an overriding one,
1965 (unless org-agenda-overriding-restriction
1966 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
1967 ;; There is a request to keep the file list in place
1968 (put 'org-agenda-files 'org-restrict nil))
1969 (setq org-agenda-restrict nil)
1970 (move-marker org-agenda-restrict-begin nil)
1971 (move-marker org-agenda-restrict-end nil))
1972 ;; Delete old local properties
1973 (put 'org-agenda-redo-command 'org-lprops nil)
1974 ;; Remember where this call originated
1975 (setq org-agenda-last-dispatch-buffer (current-buffer))
1977 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1979 restriction (cdr ans)))
1980 ;; Establish the restriction, if any
1981 (when (and (not org-agenda-overriding-restriction) restriction)
1982 (put 'org-agenda-files 'org-restrict (list bfn))
1984 ((eq restriction 'region)
1985 (setq org-agenda-restrict t)
1986 (move-marker org-agenda-restrict-begin (region-beginning))
1987 (move-marker org-agenda-restrict-end (region-end)))
1988 ((eq restriction 'subtree)
1990 (setq org-agenda-restrict t)
1991 (org-back-to-heading t)
1992 (move-marker org-agenda-restrict-begin (point))
1993 (move-marker org-agenda-restrict-end
1994 (progn (org-end-of-subtree t)))))))
1996 ;; For example the todo list should not need it (but does...)
1998 ((setq entry (assoc keys org-agenda-custom-commands))
1999 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2001 (setq type (nth 2 entry) match (eval (nth 3 entry))
2002 lprops (nth 4 entry))
2003 (put 'org-agenda-redo-command 'org-lprops lprops)
2006 (org-let lprops '(org-agenda-list current-prefix-arg)))
2008 (org-let lprops '(org-todo-list current-prefix-arg)))
2010 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2012 (org-let lprops '(org-agenda-list-stuck-projects
2013 current-prefix-arg)))
2015 (org-let lprops '(org-tags-view current-prefix-arg match)))
2016 ((eq type 'tags-todo)
2017 (org-let lprops '(org-tags-view '(4) match)))
2019 (org-let lprops '(org-todo-list match)))
2020 ((eq type 'tags-tree)
2021 (org-check-for-org-mode)
2022 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2023 ((eq type 'todo-tree)
2024 (org-check-for-org-mode)
2026 '(org-occur (concat "^" outline-regexp "[ \t]*"
2027 (regexp-quote match) "\\>"))))
2028 ((eq type 'occur-tree)
2029 (org-check-for-org-mode)
2030 (org-let lprops '(org-occur match)))
2032 (org-let lprops '(funcall type match)))
2034 (org-let lprops '(funcall type match)))
2035 (t (error "Invalid custom agenda command type %s" type))))
2036 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2038 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2039 (customize-variable 'org-agenda-custom-commands))
2040 ((equal keys "a") (call-interactively 'org-agenda-list))
2041 ((equal keys "s") (call-interactively 'org-search-view))
2042 ((equal keys "t") (call-interactively 'org-todo-list))
2043 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2044 ((equal keys "m") (call-interactively 'org-tags-view))
2045 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2046 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2047 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2051 (unless (current-message)
2052 (let* ((m (org-agenda-get-any-marker))
2053 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2056 "FLAGGING-NOTE ([?] for more info): "
2058 (replace-regexp-in-string
2060 (copy-sequence note))
2061 nil 'face 'org-warning)))))))
2064 (unless (org-mode-p)
2065 (error "This is not an Org-mode file"))
2067 (put 'org-agenda-files 'org-restrict (list bfn))
2068 (org-call-with-arg 'org-timeline arg)))
2069 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2070 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2071 ((equal keys "!") (customize-variable 'org-stuck-projects))
2072 (t (error "Invalid agenda key"))))))
2074 (defun org-agenda-normalize-custom-commands (cmds)
2078 (cond ((stringp (cdr x)) nil)
2079 ((stringp (nth 1 x)) x)
2080 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2081 (t (cons (car x) (cons "" (cdr x))))))
2084 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2085 "The user interface for selecting an agenda command."
2087 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2088 (restrict-ok (and bfn (org-mode-p)))
2089 (region-p (org-region-active-p))
2090 (custom org-agenda-custom-commands)
2092 restriction second-time
2093 c entry key type match prefixes rmheader header-end custom1 desc
2094 line lines left right n n1)
2095 (save-window-excursion
2096 (delete-other-windows)
2097 (org-switch-to-buffer-other-window " *Agenda Commands*")
2099 (insert (eval-when-compile
2102 Press key for an agenda command: < Buffer, subtree/region restriction
2103 -------------------------------- > Remove restriction
2104 a Agenda for current week or day e Export agenda views
2105 t List of all TODO entries T Entries with special TODO kwd
2106 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2107 L Timeline for current buffer # List stuck projects (!=configure)
2108 s Search for keywords C Configure custom agenda commands
2109 / Multi-occur ? Find :FLAGGED: entries
2112 (while (string-match
2113 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2115 (setq start (match-end 0))
2116 (add-text-properties (match-beginning 2) (match-end 2)
2117 '(face bold) header))
2119 (setq header-end (move-marker (make-marker) (point)))
2121 (setq custom1 custom)
2122 (when (eq rmheader t)
2124 (re-search-forward ":" nil t)
2125 (delete-region (match-end 0) (point-at-eol))
2128 (delete-region (match-end 0) (point-at-eol))
2129 (move-marker header-end (match-end 0)))
2130 (goto-char header-end)
2131 (delete-region (point) (point-max))
2133 ;; Produce all the lines that describe custom commands and prefixes
2135 (while (setq entry (pop custom1))
2136 (setq key (car entry) desc (nth 1 entry)
2138 match (nth 3 entry))
2139 (if (> (length key) 1)
2140 (add-to-list 'prefixes (string-to-char key))
2144 (org-add-props (copy-sequence key)
2147 ((string-match "\\S-" desc) desc)
2148 ((eq type 'agenda) "Agenda for current week or day")
2149 ((eq type 'alltodo) "List of all TODO entries")
2150 ((eq type 'search) "Word search")
2151 ((eq type 'stuck) "List of stuck projects")
2152 ((eq type 'todo) "TODO keyword")
2153 ((eq type 'tags) "Tags query")
2154 ((eq type 'tags-todo) "Tags (TODO)")
2155 ((eq type 'tags-tree) "Tags tree")
2156 ((eq type 'todo-tree) "TODO kwd tree")
2157 ((eq type 'occur-tree) "Occur tree")
2158 ((functionp type) (if (symbolp type)
2160 "Lambda expression"))
2162 (if org-agenda-menu-show-matcher
2167 (setq match (copy-sequence match))
2168 (org-add-props match nil 'face 'org-warning))
2170 (format "set of %d commands" (length match)))
2172 (if (org-string-nw-p match)
2173 (add-text-properties
2174 0 (length line) (list 'help-echo
2175 (concat "Matcher: "match)) line)))
2177 (setq lines (nreverse lines))
2182 (org-add-props (char-to-string x)
2184 (or (cdr (assoc (concat selstring
2186 prefix-descriptions))
2191 ;; Check if we should display in two columns
2192 (if org-agenda-menu-two-column
2194 (setq n (length lines)
2195 n1 (+ (/ n 2) (mod n 2))
2196 right (nthcdr n1 lines)
2197 left (copy-sequence lines))
2198 (setcdr (nthcdr (1- n1) left) nil))
2199 (setq left lines right nil))
2201 (insert "\n" (pop left))
2203 (if (< (current-column) 40)
2204 (move-to-column 40 t)
2206 (insert (pop right))))
2208 ;; Make the window the right size
2209 (goto-char (point-min))
2211 (if (not (pos-visible-in-window-p (point-max)))
2212 (org-fit-window-to-buffer))
2213 (setq second-time t)
2214 (org-fit-window-to-buffer))
2216 ;; Ask for selection
2217 (message "Press key for agenda command%s:"
2218 (if (or restrict-ok org-agenda-overriding-restriction)
2219 (if org-agenda-overriding-restriction
2220 " (restriction lock active)"
2222 (format " (restricted to %s)" restriction)
2225 (setq c (read-char-exclusive))
2228 ((assoc (char-to-string c) custom)
2229 (setq selstring (concat selstring (char-to-string c)))
2230 (throw 'exit (cons selstring restriction)))
2232 (setq selstring (concat selstring (char-to-string c))
2234 rmheader (or rmheader t)
2235 custom (delq nil (mapcar
2237 (if (or (= (length (car x)) 1)
2238 (/= (string-to-char (car x)) c))
2240 (cons (substring (car x) 1) (cdr x))))
2242 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2243 (message "Restriction is only possible in Org-mode buffers")
2246 (org-agenda-remove-restriction-lock 'noupdate)
2247 (setq restriction 'buffer))
2249 (org-agenda-remove-restriction-lock 'noupdate)
2250 (setq restriction (if region-p 'region 'subtree)))
2252 (org-agenda-remove-restriction-lock 'noupdate)
2255 ((eq restriction 'buffer)
2256 (if region-p 'region 'subtree))
2257 ((memq restriction '(subtree region))
2261 (org-agenda-remove-restriction-lock 'noupdate)
2262 (setq restriction nil))
2263 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2264 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2265 ((and (> (length selstring) 0) (eq c ?\d))
2267 (org-agenda-get-restriction-and-command prefix-descriptions))
2269 ((equal c ?q) (error "Abort"))
2270 (t (error "Invalid key %c" c))))))))
2272 (defun org-run-agenda-series (name series)
2273 (org-let (nth 1 series) '(org-prepare-agenda name))
2274 (let* ((org-agenda-multi t)
2275 (redo (list 'org-run-agenda-series name (list 'quote series)))
2277 (gprops (nth 1 series))
2278 match ;; The byte compiler incorrectly complains about this. Keep it!
2280 (while (setq cmd (pop cmds))
2281 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2284 (org-let2 gprops lprops
2285 '(call-interactively 'org-agenda-list)))
2287 (org-let2 gprops lprops
2288 '(call-interactively 'org-todo-list)))
2290 (org-let2 gprops lprops
2291 '(org-search-view current-prefix-arg match nil)))
2293 (org-let2 gprops lprops
2294 '(call-interactively 'org-agenda-list-stuck-projects)))
2296 (org-let2 gprops lprops
2297 '(org-tags-view current-prefix-arg match)))
2298 ((eq type 'tags-todo)
2299 (org-let2 gprops lprops
2300 '(org-tags-view '(4) match)))
2302 (org-let2 gprops lprops
2303 '(org-todo-list match)))
2305 (org-let2 gprops lprops
2306 '(funcall type match)))
2307 (t (error "Invalid type in command series"))))
2309 (setq org-agenda-redo-command redo)
2310 (goto-char (point-min)))
2311 (org-fit-agenda-window)
2312 (org-let (nth 1 series) '(org-finalize-agenda)))
2315 (defmacro org-batch-agenda (cmd-key &rest parameters)
2316 "Run an agenda command in batch mode and send the result to STDOUT.
2317 If CMD-KEY is a string of length 1, it is used as a key in
2318 `org-agenda-custom-commands' and triggers this command. If it is a
2319 longer string it is used as a tags/todo match string.
2320 Parameters are alternating variable names and values that will be bound
2321 before running the agenda command."
2324 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2325 (if (> (length cmd-key) 2)
2326 (eval (list 'let (nreverse pars)
2327 (list 'org-tags-view nil cmd-key)))
2328 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2329 (set-buffer org-agenda-buffer-name)
2330 (princ (org-encode-for-stdout (buffer-string)))))
2332 ;(defun org-encode-for-stdout (string)
2333 ; (if (fboundp 'encode-coding-string)
2334 ; (encode-coding-string string buffer-file-coding-system)
2337 (defun org-encode-for-stdout (string)
2340 (defvar org-agenda-info nil)
2343 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2344 "Run an agenda command in batch mode and send the result to STDOUT.
2345 If CMD-KEY is a string of length 1, it is used as a key in
2346 `org-agenda-custom-commands' and triggers this command. If it is a
2347 longer string it is used as a tags/todo match string.
2348 Parameters are alternating variable names and values that will be bound
2349 before running the agenda command.
2351 The output gives a line for each selected agenda item. Each
2352 item is a list of comma-separated values, like this:
2354 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2356 category The category of the item
2357 head The headline, without TODO kwd, TAGS and PRIORITY
2358 type The type of the agenda entry, can be
2359 todo selected in TODO match
2360 tagsmatch selected in tags match
2361 diary imported from diary
2362 deadline a deadline on given date
2363 scheduled scheduled on given date
2364 timestamp entry has timestamp on given date
2365 closed entry was closed on given date
2366 upcoming-deadline warning about deadline
2367 past-scheduled forwarded scheduled item
2368 block entry has date block including g. date
2369 todo The todo keyword, if any
2370 tags All tags including inherited ones, separated by colons
2371 date The relevant date, like 2007-2-14
2372 time The time, like 15:00-16:50
2373 extra Sting with extra planning info
2374 priority-l The priority letter if any was given
2375 priority-n The computed numerical priority
2376 agenda-day The day in the agenda where this is listed"
2380 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2381 (push (list 'org-agenda-remove-tags t) pars)
2382 (if (> (length cmd-key) 2)
2383 (eval (list 'let (nreverse pars)
2384 (list 'org-tags-view nil cmd-key)))
2385 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2386 (set-buffer org-agenda-buffer-name)
2387 (let* ((lines (org-split-string (buffer-string) "\n"))
2389 (while (setq line (pop lines))
2391 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2392 (setq org-agenda-info
2393 (org-fix-agenda-info (text-properties-at 0 line)))
2395 (org-encode-for-stdout
2396 (mapconcat 'org-agenda-export-csv-mapper
2397 '(org-category txt type todo tags date time extra
2398 priority-letter priority agenda-day)
2402 (defun org-fix-agenda-info (props)
2403 "Make sure all properties on an agenda item have a canonical form.
2404 This ensures the export commands can easily use it."
2406 (when (setq tmp (plist-get props 'tags))
2407 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2408 (when (setq tmp (plist-get props 'date))
2409 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2410 (let ((calendar-date-display-form '(year "-" month "-" day)))
2411 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2413 (setq tmp (calendar-date-string tmp)))
2414 (setq props (plist-put props 'date tmp)))
2415 (when (setq tmp (plist-get props 'day))
2416 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2417 (let ((calendar-date-display-form '(year "-" month "-" day)))
2418 (setq tmp (calendar-date-string tmp)))
2419 (setq props (plist-put props 'day tmp))
2420 (setq props (plist-put props 'agenda-day tmp)))
2421 (when (setq tmp (plist-get props 'txt))
2422 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2423 (plist-put props 'priority-letter (match-string 1 tmp))
2424 (setq tmp (replace-match "" t t tmp)))
2425 (when (and (setq re (plist-get props 'org-todo-regexp))
2426 (setq re (concat "\\`\\.*" re " ?"))
2427 (string-match re tmp))
2428 (plist-put props 'todo (match-string 1 tmp))
2429 (setq tmp (replace-match "" t t tmp)))
2430 (plist-put props 'txt tmp)))
2433 (defun org-agenda-export-csv-mapper (prop)
2434 (let ((res (plist-get org-agenda-info prop)))
2439 (t (prin1-to-string res))))
2440 (while (string-match "," res)
2441 (setq res (replace-match ";" t t res)))
2446 (defun org-store-agenda-views (&rest parameters)
2448 (eval (list 'org-batch-store-agenda-views)))
2450 ;; FIXME, why is this a macro?????
2452 (defmacro org-batch-store-agenda-views (&rest parameters)
2453 "Run all custom agenda commands that have a file argument."
2454 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2456 (dir default-directory)
2457 pars cmd thiscmdkey files opts cmd-or-set)
2459 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2460 (setq pars (reverse pars))
2461 (save-window-excursion
2463 (setq cmd (pop cmds)
2464 thiscmdkey (car cmd)
2465 cmd-or-set (nth 2 cmd)
2466 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2467 files (nth (if (listp cmd-or-set) 4 5) cmd))
2468 (if (stringp files) (setq files (list files)))
2470 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2471 (list 'org-agenda nil thiscmdkey)))
2472 (set-buffer org-agenda-buffer-name)
2474 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2475 (list 'org-write-agenda
2476 (expand-file-name (pop files) dir) nil t))))
2477 (and (get-buffer org-agenda-buffer-name)
2478 (kill-buffer org-agenda-buffer-name)))))))
2480 (defun org-agenda-mark-header-line (pos)
2481 "Mark the line at POS as an agenda structure header."
2484 (put-text-property (point-at-bol) (point-at-eol)
2485 'org-agenda-structural-header t)
2486 (when org-agenda-title-append
2487 (put-text-property (point-at-bol) (point-at-eol)
2488 'org-agenda-title-append org-agenda-title-append))))
2490 (defvar org-mobile-creating-agendas)
2491 (defun org-write-agenda (file &optional open nosettings)
2492 "Write the current buffer (an agenda view) as a file.
2493 Depending on the extension of the file name, plain text (.txt),
2494 HTML (.html or .htm) or Postscript (.ps) is produced.
2495 If the extension is .ics, run icalendar export over all files used
2496 to construct the agenda and limit the export to entries listed in the
2498 With prefix argument OPEN, open the new file immediately.
2499 If NOSETTINGS is given, do not scope the settings of
2500 `org-agenda-exporter-settings' into the export commands. This is used when
2501 the settings have already been scoped and we do not wish to overrule other,
2502 higher priority settings."
2503 (interactive "FWrite agenda to file: \nP")
2504 (if (not (file-writable-p file))
2505 (error "Cannot write agenda to file %s" file))
2506 (org-let (if nosettings nil org-agenda-exporter-settings)
2508 (save-window-excursion
2509 (org-agenda-mark-filtered-text)
2510 (let ((bs (copy-sequence (buffer-string))) beg)
2511 (org-agenda-unmark-filtered-text)
2513 (rename-buffer "Agenda View" t)
2514 (set-buffer-modified-p nil)
2516 (org-agenda-remove-marked-text 'org-filtered)
2517 (while (setq beg (text-property-any (point-min) (point-max)
2520 beg (or (next-single-property-change beg 'org-filtered)
2522 (run-hooks 'org-agenda-before-write-hook)
2524 ((org-bound-and-true-p org-mobile-creating-agendas)
2525 (org-mobile-write-agenda-for-mobile file))
2526 ((string-match "\\.html?\\'" file)
2528 (set-buffer (htmlize-buffer (current-buffer)))
2530 (when (and org-agenda-export-html-style
2531 (string-match "<style>" org-agenda-export-html-style))
2532 ;; replace <style> section with org-agenda-export-html-style
2533 (goto-char (point-min))
2534 (kill-region (- (search-forward "<style") 6)
2535 (search-forward "</style>"))
2536 (insert org-agenda-export-html-style))
2538 (kill-buffer (current-buffer))
2539 (message "HTML written to %s" file))
2540 ((string-match "\\.ps\\'" file)
2542 (ps-print-buffer-with-faces file)
2543 (message "Postscript written to %s" file))
2544 ((string-match "\\.pdf\\'" file)
2546 (ps-print-buffer-with-faces
2547 (concat (file-name-sans-extension file) ".ps"))
2548 (call-process "ps2pdf" nil nil nil
2550 (concat (file-name-sans-extension file) ".ps"))
2551 (expand-file-name file))
2552 (delete-file (concat (file-name-sans-extension file) ".ps"))
2553 (message "PDF written to %s" file))
2554 ((string-match "\\.ics\\'" file)
2555 (require 'org-icalendar)
2556 (let ((org-agenda-marker-table
2557 (org-create-marker-find-array
2558 (org-agenda-collect-markers)))
2559 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2560 (org-combined-agenda-icalendar-file file))
2561 (apply 'org-export-icalendar 'combine
2562 (org-agenda-files nil 'ifmode))))
2564 (let ((bs (buffer-string)))
2569 (kill-buffer (current-buffer))
2570 (message "Plain text written to %s" file))))))))
2571 (set-buffer org-agenda-buffer-name))
2572 (when open (org-open-file file)))
2574 (defvar org-agenda-filter-overlays nil)
2576 (defun org-agenda-mark-filtered-text ()
2577 "Mark all text hidden by filtering with a text property."
2578 (let ((inhibit-read-only t))
2581 (when (equal (overlay-buffer o) (current-buffer))
2583 (overlay-start o) (overlay-end o)
2585 org-agenda-filter-overlays)))
2587 (defun org-agenda-unmark-filtered-text ()
2588 "Remove the filtering text property."
2589 (let ((inhibit-read-only t))
2590 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2592 (defun org-agenda-remove-marked-text (property &optional value)
2593 "Delete all text marked with VALUE of PROPERTY.
2594 VALUE defaults to t."
2596 (setq value (or value t))
2597 (while (setq beg (text-property-any (point-min) (point-max)
2600 beg (or (next-single-property-change beg 'org-filtered)
2603 (defun org-agenda-add-entry-text ()
2604 "Add entry text to agenda lines.
2605 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2606 entry text following headings shown in the agenda.
2607 Drawers will be excluded, also the line with scheduling/deadline info."
2608 (when (and (> org-agenda-add-entry-text-maxlines 0)
2609 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2611 (goto-char (point-min))
2613 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2614 (beginning-of-line 2)
2615 (setq txt (org-agenda-get-some-entry-text
2616 m org-agenda-add-entry-text-maxlines " > "))
2618 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2620 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2622 "Extract entry text from MARKER, at most N-LINES lines.
2623 This will ignore drawers etc, just get the text.
2624 If INDENT is given, prefix every line with this string. If KEEP is
2625 given, it is a list of symbols, defining stuff that should not be
2626 removed from the entry content. Currently only `planning' is allowed here."
2627 (let (txt drawer-re kwd-time-re ind)
2629 (with-current-buffer (marker-buffer marker)
2630 (if (not (org-mode-p))
2637 (setq txt (buffer-substring
2638 (min (1+ (point)) (point-max))
2639 (progn (outline-next-heading) (point)))
2640 drawer-re org-drawer-regexp
2641 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2645 (when org-agenda-add-entry-text-descriptive-links
2646 (goto-char (point-min))
2647 (while (org-activate-bracket-links (point-max))
2648 (add-text-properties (match-beginning 0) (match-end 0)
2650 (goto-char (point-min))
2651 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2652 (set-text-properties (match-beginning 0) (match-end 0)
2654 (goto-char (point-min))
2655 (while (re-search-forward drawer-re nil t)
2658 (progn (re-search-forward
2659 "^[ \t]*:END:.*\n?" nil 'move)
2661 (unless (member 'planning keep)
2662 (goto-char (point-min))
2663 (while (re-search-forward kwd-time-re nil t)
2664 (replace-match "")))
2665 (goto-char (point-min))
2666 (when org-agenda-entry-text-exclude-regexps
2667 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2668 (while (setq re (pop re-list))
2669 (goto-char (point-min))
2670 (while (re-search-forward re nil t)
2671 (replace-match "")))))
2672 (goto-char (point-max))
2673 (skip-chars-backward " \t\n")
2674 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2676 ;; find and remove min common indentation
2677 (goto-char (point-min))
2678 (untabify (point-min) (point-max))
2679 (setq ind (org-get-indentation))
2681 (unless (looking-at "[ \t]*$")
2682 (setq ind (min ind (org-get-indentation))))
2683 (beginning-of-line 2))
2684 (goto-char (point-min))
2686 (unless (looking-at "[ \t]*$")
2687 (move-to-column ind)
2688 (delete-region (point-at-bol) (point)))
2689 (beginning-of-line 2))
2691 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2693 (goto-char (point-min))
2695 (while (and (not (eobp)) (re-search-forward "^" nil t))
2696 (replace-match indent t t)))
2697 (goto-char (point-min))
2698 (while (looking-at "[ \t]*\n") (replace-match ""))
2699 (goto-char (point-max))
2700 (when (> (org-current-line)
2702 (org-goto-line (1+ n-lines))
2704 (setq txt (buffer-substring (point-min) (point)))))))))
2707 (defun org-agenda-collect-markers ()
2708 "Collect the markers pointing to entries in the agenda buffer."
2711 (goto-char (point-min))
2713 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2714 (org-get-at-bol 'org-marker)))
2716 (beginning-of-line 2)))
2717 (nreverse markers)))
2719 (defun org-create-marker-find-array (marker-list)
2720 "Create a alist of files names with all marker positions in that file."
2722 (while (setq m (pop marker-list))
2723 (setq p (marker-position m)
2724 f (buffer-file-name (or (buffer-base-buffer
2726 (marker-buffer m))))
2727 (if (setq a (assoc f tbl))
2728 (push (marker-position m) (cdr a))
2729 (push (list f p) tbl)))
2730 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2733 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2734 (defun org-check-agenda-marker-table ()
2735 "Check of the current entry is on the marker list."
2736 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2738 (and (setq a (assoc file org-agenda-marker-table))
2741 (org-back-to-heading t)
2742 (member (point) (cdr a)))))))
2744 (defun org-check-for-org-mode ()
2745 "Make sure current buffer is in org-mode. Error if not."
2747 (error "Cannot execute org-mode agenda command on buffer in %s"
2750 (defun org-fit-agenda-window ()
2751 "Fit the window to the buffer size."
2752 (and (memq org-agenda-window-setup '(reorganize-frame))
2753 (fboundp 'fit-window-to-buffer)
2754 (org-fit-window-to-buffer
2756 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2757 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2759 ;;; Agenda prepare and finalize
2761 (defvar org-agenda-multi nil) ; dynamically scoped
2762 (defvar org-agenda-buffer-name "*Org Agenda*")
2763 (defvar org-pre-agenda-window-conf nil)
2764 (defvar org-agenda-columns-active nil)
2765 (defvar org-agenda-name nil)
2766 (defvar org-agenda-filter nil)
2767 (defvar org-agenda-filter-preset nil
2768 "A preset of the tags filter used for secondary agenda filtering.
2769 This must be a list of strings, each string must be a single tag preceded
2771 This variable should not be set directly, but agenda custom commands can
2772 bind it in the options section. The preset filter is a global property of
2773 the entire agenda view. In a block agenda, it will not work reliably to
2774 define a filter for one of the individual blocks. You need to set it in
2775 the global options and expect it to be applied to the entire view.")
2777 (defun org-prepare-agenda (&optional name)
2778 (setq org-todo-keywords-for-agenda nil)
2779 (setq org-done-keywords-for-agenda nil)
2780 (setq org-drawers-for-agenda nil)
2781 (unless org-agenda-persistent-filter
2782 (setq org-agenda-filter nil))
2783 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2784 (if org-agenda-multi
2786 (setq buffer-read-only nil)
2787 (goto-char (point-max))
2788 (unless (or (bobp) org-agenda-compact-blocks)
2790 (if (stringp org-agenda-block-separator)
2791 org-agenda-block-separator
2792 (make-string (window-width) org-agenda-block-separator))
2794 (narrow-to-region (point) (point-max)))
2795 (org-agenda-reset-markers)
2796 (setq org-agenda-contributing-files nil)
2797 (setq org-agenda-columns-active nil)
2798 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2799 (setq org-todo-keywords-for-agenda
2800 (org-uniquify org-todo-keywords-for-agenda))
2801 (setq org-done-keywords-for-agenda
2802 (org-uniquify org-done-keywords-for-agenda))
2803 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2804 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2805 (awin (get-buffer-window abuf)))
2807 ((equal (current-buffer) abuf) nil)
2808 (awin (select-window awin))
2809 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2810 ((equal org-agenda-window-setup 'current-window)
2811 (switch-to-buffer abuf))
2812 ((equal org-agenda-window-setup 'other-window)
2813 (org-switch-to-buffer-other-window abuf))
2814 ((equal org-agenda-window-setup 'other-frame)
2815 (switch-to-buffer-other-frame abuf))
2816 ((equal org-agenda-window-setup 'reorganize-frame)
2817 (delete-other-windows)
2818 (org-switch-to-buffer-other-window abuf))))
2819 (setq buffer-read-only nil)
2820 (let ((inhibit-read-only t)) (erase-buffer))
2822 (and name (not org-agenda-name)
2823 (org-set-local 'org-agenda-name name)))
2824 (setq buffer-read-only nil))
2826 (defun org-finalize-agenda ()
2827 "Finishing touch for the agenda buffer, called just before displaying it."
2828 (unless org-agenda-multi
2830 (let ((inhibit-read-only t))
2831 (goto-char (point-min))
2832 (while (org-activate-bracket-links (point-max))
2833 (add-text-properties (match-beginning 0) (match-end 0)
2835 (org-agenda-align-tags)
2836 (unless org-agenda-with-colors
2837 (remove-text-properties (point-min) (point-max) '(face nil))))
2838 (if (and (boundp 'org-agenda-overriding-columns-format)
2839 org-agenda-overriding-columns-format)
2840 (org-set-local 'org-agenda-overriding-columns-format
2841 org-agenda-overriding-columns-format))
2842 (if (and (boundp 'org-agenda-view-columns-initially)
2843 org-agenda-view-columns-initially)
2844 (org-agenda-columns))
2845 (when org-agenda-fontify-priorities
2846 (org-agenda-fontify-priorities))
2847 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2848 (org-agenda-dim-blocked-tasks))
2849 (org-agenda-mark-clocking-task)
2850 (when org-agenda-entry-text-mode
2851 (org-agenda-entry-text-hide)
2852 (org-agenda-entry-text-show))
2853 (if (functionp 'org-habit-insert-consistency-graphs)
2854 (org-habit-insert-consistency-graphs))
2855 (run-hooks 'org-finalize-agenda-hook)
2856 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2857 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
2858 (org-agenda-filter-apply org-agenda-filter))
2861 (defun org-agenda-mark-clocking-task ()
2862 "Mark the current clock entry in the agenda if it is present."
2864 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
2865 (delete-overlay o)))
2866 (overlays-in (point-min) (point-max)))
2867 (when (marker-buffer org-clock-hd-marker)
2869 (goto-char (point-min))
2871 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2873 (when (equal (org-get-at-bol 'org-hd-marker)
2874 org-clock-hd-marker)
2875 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
2876 (overlay-put ov 'type 'org-agenda-clocking)
2877 (overlay-put ov 'face 'org-agenda-clocking)
2878 (overlay-put ov 'help-echo
2879 "The clock is running in this item")))))))
2881 (defun org-agenda-fontify-priorities ()
2882 "Make highest priority lines bold, and lowest italic."
2884 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
2885 (delete-overlay o)))
2886 (overlays-in (point-min) (point-max)))
2888 (let ((inhibit-read-only t)
2890 (goto-char (point-min))
2891 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2892 (setq h (or (get-char-property (point) 'org-highest-priority)
2893 org-highest-priority)
2894 l (or (get-char-property (point) 'org-lowest-priority)
2895 org-lowest-priority)
2896 p (string-to-char (match-string 1))
2897 b (match-beginning 0)
2898 e (if (eq org-agenda-fontify-priorities 'cookies)
2901 ov (make-overlay b e))
2904 (cond ((org-face-from-face-or-color
2906 (cdr (assoc p org-priority-faces))))
2907 ((and (listp org-agenda-fontify-priorities)
2908 (org-face-from-face-or-color
2910 (cdr (assoc p org-agenda-fontify-priorities)))))
2911 ((equal p l) 'italic)
2912 ((equal p h) 'bold)))
2913 (overlay-put ov 'org-type 'org-priority)))))
2915 (defun org-agenda-dim-blocked-tasks ()
2916 "Dim currently blocked TODO's in the agenda display."
2917 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
2918 (delete-overlay o)))
2919 (overlays-in (point-min) (point-max)))
2921 (let ((inhibit-read-only t)
2922 (org-depend-tag-blocked nil)
2923 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2924 org-blocked-by-checkboxes
2925 invis1 b e p ov h l)
2926 (goto-char (point-min))
2927 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2928 (and pos (goto-char (1+ pos))))
2929 (setq org-blocked-by-checkboxes nil invis1 invis)
2930 (let ((marker (org-get-at-bol 'org-hd-marker)))
2932 (not (with-current-buffer (marker-buffer marker)
2935 (if (org-entry-get nil "NOBLOCKING")
2936 t ;; Never block this entry
2937 (run-hook-with-args-until-failure
2939 (list :type 'todo-state-change
2943 (if org-blocked-by-checkboxes (setq invis1 nil))
2945 (max (point-min) (1- (point-at-bol)))
2948 ov (make-overlay b e))
2950 (overlay-put ov 'invisible t)
2951 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2952 (overlay-put ov 'org-type 'org-blocked-todo)))))))
2954 (defvar org-agenda-skip-function nil
2955 "Function to be called at each match during agenda construction.
2956 If this function returns nil, the current match should not be skipped.
2957 Otherwise, the function must return a position from where the search
2958 should be continued.
2959 This may also be a Lisp form, it will be evaluated.
2960 Never set this variable using `setq' or so, because then it will apply
2961 to all future agenda commands. Instead, bind it with `let' to scope
2962 it dynamically into the agenda-constructing command. A good way to set
2963 it is through options in `org-agenda-custom-commands'.")
2965 (defun org-agenda-skip ()
2966 "Throw to `:skip' in places that should be skipped.
2967 Also moves point to the end of the skipped region, so that search can
2968 continue from there."
2969 (let ((p (point-at-bol)) to fp)
2970 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2971 (get-text-property p :org-archived)
2972 (org-end-of-subtree t)
2974 (and org-agenda-skip-comment-trees
2975 (get-text-property p :org-comment)
2976 (org-end-of-subtree t)
2978 (if (equal (char-after p) ?#) (throw :skip t))
2979 (when (and (or (setq fp (functionp org-agenda-skip-function))
2980 (consp org-agenda-skip-function))
2981 (setq to (save-excursion
2984 (funcall org-agenda-skip-function)
2985 (eval org-agenda-skip-function))))))
2989 (defvar org-agenda-markers nil
2990 "List of all currently active markers created by `org-agenda'.")
2991 (defvar org-agenda-last-marker-time (org-float-time)
2992 "Creation time of the last agenda marker.")
2994 (defun org-agenda-new-marker (&optional pos)
2995 "Return a new agenda marker.
2996 Org-mode keeps a list of these markers and resets them when they are
2998 (let ((m (copy-marker (or pos (point)))))
2999 (setq org-agenda-last-marker-time (org-float-time))
3000 (push m org-agenda-markers)
3003 (defun org-agenda-reset-markers ()
3004 "Reset markers created by `org-agenda'."
3005 (while org-agenda-markers
3006 (move-marker (pop org-agenda-markers) nil)))
3008 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3009 "Save relative positions of markers in region."
3010 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3011 org-agenda-markers))
3015 (defun org-agenda-entry-text-show-here ()
3016 "Add some text from the entry as context to the current line."
3018 (setq m (org-get-at-bol 'org-hd-marker))
3019 (unless (marker-buffer m)
3020 (error "No marker points to an entry here"))
3021 (setq txt (concat "\n" (org-no-properties
3022 (org-agenda-get-some-entry-text
3023 m org-agenda-entry-text-maxlines " > "))))
3024 (when (string-match "\\S-" txt)
3025 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3026 (overlay-put o 'evaporate t)
3027 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3028 (overlay-put o 'after-string txt))))
3030 (defun org-agenda-entry-text-show ()
3031 "Add entry context for all agenda lines."
3034 (goto-char (point-max))
3035 (beginning-of-line 1)
3037 (when (org-get-at-bol 'org-hd-marker)
3038 (org-agenda-entry-text-show-here))
3039 (beginning-of-line 0))))
3041 (defun org-agenda-entry-text-hide ()
3042 "Remove any shown entry context."
3045 (if (eq (overlay-get o 'org-overlay-type)
3046 'agenda-entry-content)
3047 (progn (delete-overlay o) t)))
3048 (overlays-in (point-min) (point-max)))))
3052 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3054 (defun org-timeline (&optional include-all)
3055 "Show a time-sorted view of the entries in the current org file.
3056 Only entries with a time stamp of today or later will be listed. With
3057 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3058 under the current date.
3059 If the buffer contains an active region, only check the region for
3062 (org-compile-prefix-format 'timeline)
3063 (org-set-sorting-strategy 'timeline)
3065 (dotodo include-all)
3066 (doclosed org-agenda-show-log)
3067 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3069 (date (calendar-current-date))
3070 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3071 (end (if (org-region-active-p) (region-end) (point-max)))
3072 (day-numbers (org-get-all-dates beg end 'no-ranges
3073 t doclosed ; always include today
3074 org-timeline-show-empty-dates))
3075 (org-deadline-warning-days 0)
3076 (org-agenda-only-exact-dates t)
3077 (today (time-to-days (current-time)))
3080 s e rtn d emptyp wd)
3081 (setq org-agenda-redo-command
3083 (list 'org-switch-to-buffer-other-window (current-buffer))
3084 (list 'org-timeline (list 'quote include-all))))
3086 ;; Remove past dates from the list of dates.
3087 (setq day-numbers (delq nil (mapcar (lambda(x)
3088 (if (>= x today) x nil))
3090 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3091 (if doclosed (push :closed args))
3092 (push :timestamp args)
3093 (push :deadline args)
3094 (push :scheduled args)
3096 (if dotodo (push :todo args))
3097 (insert "Timeline of file " entry "\n")
3098 (add-text-properties (point-min) (point)
3099 (list 'face 'org-agenda-structure))
3100 (org-agenda-mark-header-line (point-min))
3101 (while (setq d (pop day-numbers))
3102 (if (and (listp d) (eq (car d) :omitted))
3105 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3106 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3107 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3108 (if (and (>= d today)
3113 (insert (make-string 79 ?-) "\n")))
3114 (setq date (calendar-gregorian-from-absolute d)
3115 wd (calendar-day-of-week date))
3117 (setq rtn (and (not emptyp)
3118 (apply 'org-agenda-get-day-entries entry
3120 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3123 (if (stringp org-agenda-format-date)
3124 (format-time-string org-agenda-format-date
3125 (org-time-from-absolute date))
3126 (funcall org-agenda-format-date date))
3128 (put-text-property s (1- (point)) 'face
3129 (if (member wd org-agenda-weekend-days)
3130 'org-agenda-date-weekend
3132 (put-text-property s (1- (point)) 'org-date-line t)
3133 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3135 (put-text-property s (1- (point)) 'org-today t))
3136 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3137 (put-text-property s (1- (point)) 'day d)))))
3138 (goto-char (point-min))
3139 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3141 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3142 (org-finalize-agenda)
3143 (setq buffer-read-only t)))
3145 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3146 "Return a list of all relevant day numbers from BEG to END buffer positions.
3147 If NO-RANGES is non-nil, include only the start and end dates of a range,
3148 not every single day in the range. If FORCE-TODAY is non-nil, make
3149 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3150 inactive time stamps (those in square brackets) are included.
3151 When EMPTY is non-nil, also include days without any entries."
3153 (if pre-re pre-re "")
3154 (if inactive org-ts-regexp-both org-ts-regexp)))
3155 dates dates1 date day day1 day2 ts1 ts2)
3157 (setq dates (list (time-to-days (current-time)))))
3160 (while (re-search-forward re end t)
3161 (setq day (time-to-days (org-time-string-to-time
3162 (substring (match-string 1) 0 10))))
3163 (or (memq day dates) (push day dates)))
3166 (while (re-search-forward org-tr-regexp end t)
3167 (setq ts1 (substring (match-string 1) 0 10)
3168 ts2 (substring (match-string 2) 0 10)
3169 day1 (time-to-days (org-time-string-to-time ts1))
3170 day2 (time-to-days (org-time-string-to-time ts2)))
3171 (while (< (setq day1 (1+ day1)) day2)
3172 (or (memq day1 dates) (push day1 dates)))))
3173 (setq dates (sort dates '<))
3175 (while (setq day (pop dates))
3176 (setq day2 (car dates))
3178 (when (and day2 empty)
3179 (if (or (eq empty t)
3180 (and (numberp empty) (<= (- day2 day) empty)))
3181 (while (< (setq day (1+ day)) day2)
3182 (push (list day) dates1))
3183 (push (cons :omitted (- day2 day)) dates1))))
3184 (setq dates (nreverse dates1)))
3187 ;;; Agenda Daily/Weekly
3189 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3190 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3191 "Custom commands can set this variable in the options section.")
3192 (defvar org-agenda-last-arguments nil
3193 "The arguments of the previous call to `org-agenda'.")
3194 (defvar org-starting-day nil) ; local variable in the agenda buffer
3195 (defvar org-agenda-span nil) ; local variable in the agenda buffer
3196 (defvar org-include-all-loc nil) ; local variable
3198 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3199 "List of types searched for when creating the daily/weekly agenda.
3200 This variable is a list of symbols that controls the types of
3201 items that appear in the daily/weekly agenda. Allowed symbols in this
3204 :timestamp List items containing a date stamp or date range matching
3205 the selected date. This includes sexp entries in
3208 :sexp List entries resulting from plain diary-like sexps.
3210 :deadline List deadline due on that date. When the date is today,
3211 also list any deadlines past due, or due within
3212 `org-deadline-warning-days'. `:deadline' must appear before
3213 `:scheduled' if the setting of
3214 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3217 :scheduled List all items which are scheduled for the given date.
3218 The diary for *today* also contains items which were
3219 scheduled earlier and are not yet marked DONE.
3221 By default, all four types are turned on.
3223 Never set this variable globally using `setq', because then it
3224 will apply to all future agenda commands. Instead, bind it with
3225 `let' to scope it dynamically into the the agenda-constructing
3226 command. A good way to set it is through options in
3227 `org-agenda-custom-commands'. For a more flexible (though
3228 somewhat less efficient) way of determining what is included in
3229 the daily/weekly agenda, see `org-agenda-skip-function'.")
3232 (defun org-agenda-list (&optional include-all start-day ndays)
3233 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3234 The view will be for the current day or week, but from the overview buffer
3235 you will be able to go to other days/weeks.
3237 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3238 all unfinished TODO items will also be shown, before the agenda.
3239 This feature is considered obsolete, please use the TODO list or a block
3242 With a numeric prefix argument in an interactive call, the agenda will
3243 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3244 the number of days. NDAYS defaults to `org-agenda-ndays'.
3246 START-DAY defaults to TODAY, or to the most recent match for the weekday
3247 given in `org-agenda-start-on-weekday'."
3249 (if (and (integerp include-all) (> include-all 0))
3250 (setq ndays include-all include-all nil))
3251 (setq ndays (or ndays org-agenda-ndays)
3252 start-day (or start-day org-agenda-start-day))
3253 (if org-agenda-overriding-arguments
3254 (setq include-all (car org-agenda-overriding-arguments)
3255 start-day (nth 1 org-agenda-overriding-arguments)
3256 ndays (nth 2 org-agenda-overriding-arguments)))
3257 (if (stringp start-day)
3258 ;; Convert to an absolute day number
3259 (setq start-day (time-to-days (org-read-date nil t start-day))))
3260 (setq org-agenda-last-arguments (list include-all start-day ndays))
3261 (org-compile-prefix-format 'agenda)
3262 (org-set-sorting-strategy 'agenda)
3263 (let* ((org-agenda-start-on-weekday
3264 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3265 org-agenda-start-on-weekday nil))
3266 (thefiles (org-agenda-files nil 'ifmode))
3268 (today (time-to-days
3269 (time-subtract (current-time)
3270 (list 0 (* 3600 org-extend-today-until) 0))))
3271 (sd (or start-day today))
3272 (start (if (or (null org-agenda-start-on-weekday)
3273 (< org-agenda-ndays 7))
3275 (let* ((nt (calendar-day-of-week
3276 (calendar-gregorian-from-absolute sd)))
3277 (n1 org-agenda-start-on-weekday)
3279 (- sd (+ (if (< d 0) 7 0) d)))))
3280 (day-numbers (list start))
3282 (inhibit-redisplay (not debug-on-error))
3283 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3284 clocktable-start clocktable-end)
3285 (setq org-agenda-redo-command
3286 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3287 ;; Make the list of days
3288 (setq ndays (or ndays org-agenda-ndays)
3291 (push (1+ (car day-numbers)) day-numbers)
3292 (setq ndays (1- ndays)))
3293 (setq day-numbers (nreverse day-numbers))
3294 (setq clocktable-start (car day-numbers)
3295 clocktable-end (1+ (or (org-last day-numbers) 0)))
3296 (org-prepare-agenda "Day/Week")
3297 (org-set-local 'org-starting-day (car day-numbers))
3298 (org-set-local 'org-include-all-loc include-all)
3299 (org-set-local 'org-agenda-span
3300 (org-agenda-ndays-to-span nd))
3301 (when (and (or include-all org-agenda-include-all-todo)
3302 (member today day-numbers))
3303 (setq files thefiles
3305 (while (setq file (pop files))
3307 (org-check-agenda-file file)
3308 (setq date (calendar-gregorian-from-absolute today)
3309 rtn (org-agenda-get-day-entries
3311 (setq rtnall (append rtnall rtn))))
3313 (insert "All currently open TODO items:\n")
3314 (add-text-properties (point-min) (1- (point))
3315 (list 'face 'org-agenda-structure
3316 'short-heading "All TODO items"))
3317 (org-agenda-mark-header-line (point-min))
3318 (insert (org-finalize-agenda-entries rtnall) "\n")))
3319 (unless org-agenda-compact-blocks
3320 (let* ((d1 (car day-numbers))
3321 (d2 (org-last day-numbers))
3322 (w1 (org-days-to-iso-week d1))
3323 (w2 (org-days-to-iso-week d2)))
3325 (if org-agenda-overriding-header
3326 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3327 nil 'face 'org-agenda-structure) "\n")
3328 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3330 (if (< (- d2 d1) 350)
3332 (format " (W%02d)" w1)
3333 (format " (W%02d-W%02d)" w1 w2))
3336 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3338 (org-agenda-mark-header-line s))
3339 (while (setq d (pop day-numbers))
3340 (setq date (calendar-gregorian-from-absolute d)
3341 wd (calendar-day-of-week date)
3343 (if (or (setq todayp (= d today))
3344 (and (not start-pos) (= d sd)))
3345 (setq start-pos (point))
3346 (if (and start-pos (not end-pos))
3347 (setq end-pos (point))))
3348 (setq files thefiles
3350 (while (setq file (pop files))
3352 (org-check-agenda-file file)
3353 (let ((org-agenda-entry-types org-agenda-entry-types))
3354 (unless org-agenda-include-deadlines
3355 (setq org-agenda-entry-types
3356 (delq :deadline org-agenda-entry-types)))
3358 ((eq org-agenda-show-log 'only)
3359 (setq rtn (org-agenda-get-day-entries
3360 file date :closed)))
3361 (org-agenda-show-log
3362 (setq rtn (apply 'org-agenda-get-day-entries
3364 (append '(:closed) org-agenda-entry-types))))
3366 (setq rtn (apply 'org-agenda-get-day-entries
3368 org-agenda-entry-types)))))
3369 (setq rtnall (append rtnall rtn))))
3370 (if org-agenda-include-diary
3371 (let ((org-agenda-search-headline-for-time t))
3372 (require 'diary-lib)
3373 (setq rtn (org-get-entries-from-diary date))
3374 (setq rtnall (append rtnall rtn))))
3375 (if (or rtnall org-agenda-show-all-dates)
3377 (setq day-cnt (1+ day-cnt))
3379 (if (stringp org-agenda-format-date)
3380 (format-time-string org-agenda-format-date
3381 (org-time-from-absolute date))
3382 (funcall org-agenda-format-date date))
3384 (put-text-property s (1- (point)) 'face
3385 (if (member wd org-agenda-weekend-days)
3386 'org-agenda-date-weekend
3388 (put-text-property s (1- (point)) 'org-date-line t)
3389 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3390 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3392 (put-text-property s (1- (point)) 'org-today t)
3393 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3395 (org-finalize-agenda-entries
3396 (org-agenda-add-time-grid-maybe
3399 (put-text-property s (1- (point)) 'day d)
3400 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3401 (when (and org-agenda-clockreport-mode clocktable-start)
3402 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3403 ;; the above line is to ensure the restricted range!
3404 (p org-agenda-clockreport-parameter-plist)
3406 (setq p (org-plist-delete p :block))
3407 (setq p (plist-put p :tstart clocktable-start))
3408 (setq p (plist-put p :tend clocktable-end))
3409 (setq p (plist-put p :scope 'agenda))
3410 (setq tbl (apply 'org-get-clocktable p))
3412 (goto-char (point-min))
3413 (or org-agenda-multi (org-fit-agenda-window))
3414 (unless (and (pos-visible-in-window-p (point-min))
3415 (pos-visible-in-window-p (point-max)))
3416 (goto-char (1- (point-max)))
3418 (if (not (pos-visible-in-window-p (or start-pos 1)))
3420 (goto-char (or start-pos 1))
3422 (goto-char (or start-pos 1))
3423 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3424 (org-finalize-agenda)
3425 (setq buffer-read-only t)
3428 (defun org-agenda-ndays-to-span (n)
3429 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3431 ;;; Agenda word search
3433 (defvar org-agenda-search-history nil)
3434 (defvar org-todo-only nil)
3436 (defvar org-search-syntax-table nil
3437 "Special syntax table for org-mode search.
3438 In this table, we have single quotes not as word constituents, to
3439 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3441 (defun org-search-syntax-table ()
3442 (unless org-search-syntax-table
3443 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3444 (modify-syntax-entry ?' "." org-search-syntax-table)
3445 (modify-syntax-entry ?` "." org-search-syntax-table))
3446 org-search-syntax-table)
3448 (defvar org-agenda-last-search-view-search-was-boolean nil)
3451 (defun org-search-view (&optional todo-only string edit-at)
3452 "Show all entries that contain a phrase or words or regular expressions.
3454 With optional prefix argument TODO-ONLY, only consider entries that are
3455 TODO entries. The argument STRING can be used to pass a default search
3456 string into this function. If EDIT-AT is non-nil, it means that the
3457 user should get a chance to edit this string, with cursor at position
3460 The search string can be viewed either as a phrase that should be found as
3461 is, or it can be broken into a number of snippets, each of which must match
3462 in a Boolean way to select an entry. The default depends on the variable
3463 `org-agenda-search-view-always-boolean'.
3464 Even if this is turned off (the default) you can always switch to
3465 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3467 The default is a direct search of the whole phrase, where each space in
3468 the search string can expand to an arbitrary amount of whitespace,
3471 If using a Boolean search, the search string is split on whitespace and
3472 each snippet is searched separately, with logical AND to select an entry.
3473 Words prefixed with a minus must *not* occur in the entry. Words without
3474 a prefix or prefixed with a plus must occur in the entry. Matching is
3475 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3476 match whole words, not parts of a word) if
3477 `org-agenda-search-view-force-full-words' is set (default is nil).
3479 Boolean search snippets enclosed by curly braces are interpreted as
3480 regular expressions that must or (when preceded with \"-\") must not
3481 match in the entry. Snippets enclosed into double quotes will be taken
3482 as a whole, to include whitespace.
3484 - If the search string starts with an asterisk, search only in headlines.
3485 - If (possibly after the leading star) the search string starts with an
3486 exclamation mark, this also means to look at TODO entries only, an effect
3487 that can also be achieved with a prefix argument.
3488 - If (possibly after star and exclamation mark) the search string starts
3489 with a colon, this will mean that the (non-regexp) snippets of the
3490 Boolean search must match as full words.
3492 This command searches the agenda files, and in addition the files listed
3493 in `org-agenda-text-search-extra-files'."
3495 (org-compile-prefix-format 'search)
3496 (org-set-sorting-strategy 'search)
3497 (org-prepare-agenda "SEARCH")
3498 (let* ((props (list 'face nil
3499 'done-face 'org-agenda-done
3500 'org-not-done-regexp org-not-done-regexp
3501 'org-todo-regexp org-todo-regexp
3502 'org-complex-heading-regexp org-complex-heading-regexp
3503 'mouse-face 'highlight
3504 'help-echo (format "mouse-2 or RET jump to location")))
3505 (full-words org-agenda-search-view-force-full-words)
3506 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3507 regexp rtn rtnall files file pos
3508 marker category tags c neg re boolean
3509 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3510 (unless (and (not edit-at)
3512 (string-match "\\S-" string))
3513 (setq string (read-string
3514 (if org-agenda-search-view-always-boolean
3515 "[+-]Word/{Regexp} ...: "
3516 "Phrase, or [+-]Word/{Regexp} ...: ")
3518 ((integerp edit-at) (cons string edit-at))
3520 'org-agenda-search-history)))
3521 (org-set-local 'org-todo-only todo-only)
3522 (setq org-agenda-redo-command
3523 (list 'org-search-view (if todo-only t nil) string
3524 '(if current-prefix-arg 1 nil)))
3525 (setq org-agenda-query-string string)
3527 (if (equal (string-to-char string) ?*)
3529 words (substring string 1))
3530 (setq words string))
3531 (when (equal (string-to-char words) ?!)
3533 words (substring words 1)))
3534 (when (equal (string-to-char words) ?:)
3536 words (substring words 1)))
3537 (if (or org-agenda-search-view-always-boolean
3538 (member (string-to-char words) '(?- ?+ ?\{)))
3540 (setq words (org-split-string words))
3541 (setq org-agenda-last-search-view-search-was-boolean boolean)
3544 (while (setq w (pop words))
3545 (if (or (equal (substring w 0 1) "\"")
3546 (and (> (length w) 1)
3547 (member (substring w 0 1) '("+" "-"))
3548 (equal (substring w 1 2) "\"")))
3549 (while (and words (not (equal (substring w -1) "\"")))
3550 (setq w (concat w " " (pop words)))))
3551 (and (string-match "\\`\\([-+]?\\)\"" w)
3552 (setq w (replace-match "\\1" nil nil w)))
3553 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3555 (setq words (nreverse wds))))
3558 (setq c (string-to-char w))
3560 (setq neg t w (substring w 1))
3562 (setq neg nil w (substring w 1))
3564 (if (string-match "\\`{.*}\\'" w)
3565 (setq re (substring w 1 -1))
3567 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3568 (setq re (regexp-quote (downcase w)))))
3569 (if neg (push re regexps-) (push re regexps+)))
3571 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3573 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3575 (setq regexp (concat "^" org-outline-regexp))
3576 (setq regexp (pop regexps+))
3577 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3579 (setq files (org-agenda-files nil 'ifmode))
3580 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3581 (pop org-agenda-text-search-extra-files)
3582 (setq files (org-add-archive-files files)))
3583 (setq files (append files org-agenda-text-search-extra-files)
3585 (while (setq file (pop files))
3588 (org-check-agenda-file file)
3589 (setq buffer (if (file-exists-p file)
3590 (org-get-agenda-file-buffer file)
3591 (error "No such file %s" file)))
3593 ;; If file does not exist, make sure an error message is sent
3594 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3596 (with-current-buffer buffer
3597 (with-syntax-table (org-search-syntax-table)
3598 (unless (org-mode-p)
3599 (error "Agenda file %s is not in `org-mode'" file))
3600 (let ((case-fold-search t))
3603 (if org-agenda-restrict
3604 (narrow-to-region org-agenda-restrict-begin
3605 org-agenda-restrict-end)
3607 (goto-char (point-min))
3608 (unless (or (org-on-heading-p)
3609 (outline-next-heading))
3610 (throw 'nextfile t))
3611 (goto-char (max (point-min) (1- (point))))
3612 (while (re-search-forward regexp nil t)
3613 (org-back-to-heading t)
3614 (skip-chars-forward "* ")
3615 (setq beg (point-at-bol)
3617 end (progn (outline-next-heading) (point)))
3621 (setq str (buffer-substring-no-properties
3623 (if hdl-only (point-at-eol) end)))
3624 (mapc (lambda (wr) (when (string-match wr str)
3625 (goto-char (1- end))
3628 (mapc (lambda (wr) (unless (string-match wr str)
3629 (goto-char (1- end))
3632 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3636 (setq marker (org-agenda-new-marker (point))
3637 category (org-get-category)
3638 tags (org-get-tags-at (point))
3639 txt (org-format-agenda-item
3641 (buffer-substring-no-properties
3642 beg1 (point-at-eol))
3644 (org-add-props txt props
3645 'org-marker marker 'org-hd-marker marker
3646 'org-todo-regexp org-todo-regexp
3647 'org-complex-heading-regexp org-complex-heading-regexp
3648 'priority 1000 'org-category category
3651 (goto-char (1- end))))))))))
3652 (setq rtn (nreverse ee))
3653 (setq rtnall (append rtnall rtn)))
3654 (if org-agenda-overriding-header
3655 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3656 nil 'face 'org-agenda-structure) "\n")
3657 (insert "Search words: ")
3658 (add-text-properties (point-min) (1- (point))
3659 (list 'face 'org-agenda-structure))
3661 (insert string "\n")
3662 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3664 (unless org-agenda-multi
3665 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3666 (add-text-properties pos (1- (point))
3667 (list 'face 'org-agenda-structure))))
3668 (org-agenda-mark-header-line (point-min))
3670 (insert (org-finalize-agenda-entries rtnall) "\n"))
3671 (goto-char (point-min))
3672 (or org-agenda-multi (org-fit-agenda-window))
3673 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3674 (org-finalize-agenda)
3675 (setq buffer-read-only t)))
3677 ;;; Agenda TODO list
3679 (defvar org-select-this-todo-keyword nil)
3680 (defvar org-last-arg nil)
3683 (defun org-todo-list (arg)
3684 "Show all (not done) TODO entries from all agenda file in a single list.
3685 The prefix arg can be used to select a specific TODO keyword and limit
3686 the list to these. When using \\[universal-argument], you will be prompted
3687 for a keyword. A numeric prefix directly selects the Nth keyword in
3688 `org-todo-keywords-1'."
3690 (org-compile-prefix-format 'todo)
3691 (org-set-sorting-strategy 'todo)
3692 (org-prepare-agenda "TODO")
3693 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3694 (let* ((today (time-to-days (current-time)))
3695 (date (calendar-gregorian-from-absolute today))
3696 (kwds org-todo-keywords-for-agenda)
3697 (completion-ignore-case t)
3698 (org-select-this-todo-keyword
3699 (if (stringp arg) arg
3700 (and arg (integerp arg) (> arg 0)
3701 (nth (1- arg) kwds))))
3702 rtn rtnall files file pos)
3703 (when (equal arg '(4))
3704 (setq org-select-this-todo-keyword
3705 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3706 (mapcar 'list kwds) nil nil)))
3707 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3708 (org-set-local 'org-last-arg arg)
3709 (setq org-agenda-redo-command
3710 '(org-todo-list (or current-prefix-arg org-last-arg)))
3711 (setq files (org-agenda-files nil 'ifmode)
3713 (while (setq file (pop files))
3715 (org-check-agenda-file file)
3716 (setq rtn (org-agenda-get-day-entries file date :todo))
3717 (setq rtnall (append rtnall rtn))))
3718 (if org-agenda-overriding-header
3719 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3720 nil 'face 'org-agenda-structure) "\n")
3721 (insert "Global list of TODO items of type: ")
3722 (add-text-properties (point-min) (1- (point))
3723 (list 'face 'org-agenda-structure
3726 (or org-select-this-todo-keyword "ALL"))))
3727 (org-agenda-mark-header-line (point-min))
3729 (insert (or org-select-this-todo-keyword "ALL") "\n")
3730 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3732 (unless org-agenda-multi
3733 (insert "Available with `N r': (0)ALL")
3736 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3737 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3742 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3743 (org-agenda-mark-header-line (point-min))
3745 (insert (org-finalize-agenda-entries rtnall) "\n"))
3746 (goto-char (point-min))
3747 (or org-agenda-multi (org-fit-agenda-window))
3748 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3749 (org-finalize-agenda)
3750 (setq buffer-read-only t)))
3752 ;;; Agenda tags match
3755 (defun org-tags-view (&optional todo-only match)
3756 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3757 The prefix arg TODO-ONLY limits the search to TODO entries."
3759 (org-compile-prefix-format 'tags)
3760 (org-set-sorting-strategy 'tags)
3761 (let* ((org-tags-match-list-sublevels
3762 org-tags-match-list-sublevels)
3763 (completion-ignore-case t)
3764 rtn rtnall files file pos matcher
3766 (when (and (stringp match) (not (string-match "\\S-" match)))
3768 (setq matcher (org-make-tags-matcher match)
3769 match (car matcher) matcher (cdr matcher))
3770 (org-prepare-agenda (concat "TAGS " match))
3771 (setq org-agenda-query-string match)
3772 (setq org-agenda-redo-command
3773 (list 'org-tags-view (list 'quote todo-only)
3774 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3775 (setq files (org-agenda-files nil 'ifmode)
3777 (while (setq file (pop files))
3779 (org-check-agenda-file file)
3780 (setq buffer (if (file-exists-p file)
3781 (org-get-agenda-file-buffer file)
3782 (error "No such file %s" file)))
3784 ;; If file does not exist, error message to agenda
3786 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3787 rtnall (append rtnall rtn))
3788 (with-current-buffer buffer
3789 (unless (org-mode-p)
3790 (error "Agenda file %s is not in `org-mode'" file))
3793 (if org-agenda-restrict
3794 (narrow-to-region org-agenda-restrict-begin
3795 org-agenda-restrict-end)
3797 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3798 (setq rtnall (append rtnall rtn))))))))
3799 (if org-agenda-overriding-header
3800 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3801 nil 'face 'org-agenda-structure) "\n")
3802 (insert "Headlines with TAGS match: ")
3803 (add-text-properties (point-min) (1- (point))
3804 (list 'face 'org-agenda-structure
3806 (concat "Match: " match)))
3809 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3811 (unless org-agenda-multi
3812 (insert "Press `C-u r' to search again with new search string\n"))
3813 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3814 (org-agenda-mark-header-line (point-min))
3816 (insert (org-finalize-agenda-entries rtnall) "\n"))
3817 (goto-char (point-min))
3818 (or org-agenda-multi (org-fit-agenda-window))
3819 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3820 (org-finalize-agenda)
3821 (setq buffer-read-only t)))
3823 ;;; Agenda Finding stuck projects
3825 (defvar org-agenda-skip-regexp nil
3826 "Regular expression used in skipping subtrees for the agenda.
3827 This is basically a temporary global variable that can be set and then
3828 used by user-defined selections using `org-agenda-skip-function'.")
3830 (defvar org-agenda-overriding-header nil
3831 "When this is set during todo and tags searches, will replace header.
3832 This variable should not be set directly, but custom commands can bind it
3833 in the options section.")
3835 (defun org-agenda-skip-entry-when-regexp-matches ()
3836 "Check if the current entry contains match for `org-agenda-skip-regexp'.
3837 If yes, it returns the end position of this entry, causing agenda commands
3838 to skip the entry but continuing the search in the subtree. This is a
3839 function that can be put into `org-agenda-skip-function' for the duration
3841 (let ((end (save-excursion (org-end-of-subtree t)))
3844 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3847 (defun org-agenda-skip-subtree-when-regexp-matches ()
3848 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3849 If yes, it returns the end position of this tree, causing agenda commands
3850 to skip this subtree. This is a function that can be put into
3851 `org-agenda-skip-function' for the duration of a command."
3852 (let ((end (save-excursion (org-end-of-subtree t)))
3855 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3858 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3859 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3860 If yes, it returns the end position of the current entry (NOT the tree),
3861 causing agenda commands to skip the entry but continuing the search in
3862 the subtree. This is a function that can be put into
3863 `org-agenda-skip-function' for the duration of a command. An important
3864 use of this function is for the stuck project list."
3865 (let ((end (save-excursion (org-end-of-subtree t)))
3866 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3869 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3870 (and skip entry-end)))
3872 (defun org-agenda-skip-entry-if (&rest conditions)
3873 "Skip entry if any of CONDITIONS is true.
3874 See `org-agenda-skip-if' for details."
3875 (org-agenda-skip-if nil conditions))
3877 (defun org-agenda-skip-subtree-if (&rest conditions)
3878 "Skip entry if any of CONDITIONS is true.
3879 See `org-agenda-skip-if' for details."
3880 (org-agenda-skip-if t conditions))
3882 (defun org-agenda-skip-if (subtree conditions)
3883 "Checks current entity for CONDITIONS.
3884 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3885 the entry, i.e. the text before the next heading is checked.
3887 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3888 from different tests. Valid conditions are:
3890 scheduled Check if there is a scheduled cookie
3891 notscheduled Check if there is no scheduled cookie
3892 deadline Check if there is a deadline
3893 notdeadline Check if there is no deadline
3894 timestamp Check if there is a timestamp (also deadline or scheduled)
3895 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3896 regexp Check if regexp matches
3897 notregexp Check if regexp does not match.
3898 todo Check if TODO keyword matches
3899 nottodo Check if TODO keyword does not match
3901 The regexp is taken from the conditions list, it must come right after
3902 the `regexp' or `notregexp' element.
3904 `todo' and `nottodo' accept as an argument a list of todo
3905 keywords, which may include \"*\" to match any todo keyword.
3907 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
3909 would skip all entries with \"TODO\" or \"WAITING\" keywords.
3911 Instead of a list a keyword class may be given
3913 (org-agenda-skip-entry-if 'nottodo 'done)
3915 would skip entries that haven't been marked with any of \"DONE\"
3916 keywords. Possible classes are: `todo', `done', `any'.
3918 If any of these conditions is met, this function returns the end point of
3919 the entity, causing the search to continue from there. This is a function
3920 that can be put into `org-agenda-skip-function' for the duration of a command."
3922 (org-back-to-heading t)
3925 (progn (org-end-of-subtree t) (point))
3926 (progn (outline-next-heading) (1- (point)))))
3930 (and (memq 'scheduled conditions)
3931 (re-search-forward org-scheduled-time-regexp end t))
3932 (and (memq 'notscheduled conditions)
3933 (not (re-search-forward org-scheduled-time-regexp end t)))
3934 (and (memq 'deadline conditions)
3935 (re-search-forward org-deadline-time-regexp end t))
3936 (and (memq 'notdeadline conditions)
3937 (not (re-search-forward org-deadline-time-regexp end t)))
3938 (and (memq 'timestamp conditions)
3939 (re-search-forward org-ts-regexp end t))
3940 (and (memq 'nottimestamp conditions)
3941 (not (re-search-forward org-ts-regexp end t)))
3942 (and (setq m (memq 'regexp conditions))
3944 (re-search-forward (nth 1 m) end t))
3945 (and (setq m (memq 'notregexp conditions))
3947 (not (re-search-forward (nth 1 m) end t)))
3949 (setq m (memq 'todo conditions))
3950 (setq m (memq 'nottodo conditions)))
3951 (org-agenda-skip-if-todo m end)))
3954 (defun org-agenda-skip-if-todo (args end)
3955 "Helper function for `org-agenda-skip-if', do not use it directly.
3956 ARGS is a list with first element either `todo' or `nottodo'.
3957 The remainder is either a list of TODO keywords, or a state symbol
3958 `todo' or `done' or `any'."
3959 (let ((kw (car args))
3965 ((listp arg) ;; list of keywords
3966 (if (member "*" arg)
3967 (mapcar 'substring-no-properties org-todo-keywords-1)
3969 ((symbolp arg) ;; keyword class name
3972 (org-delete-all org-done-keywords
3973 (mapcar 'substring-no-properties
3974 org-todo-keywords-1)))
3975 ((eq arg 'done) org-done-keywords)
3977 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
3979 (concat "^\\*+[ \t]+\\<\\("
3980 (mapconcat 'identity todo-wds "\\|")
3983 (re-search-forward todo-re end t)
3984 (not (re-search-forward todo-re end t)))))
3987 (defun org-agenda-list-stuck-projects (&rest ignore)
3988 "Create agenda view for projects that are stuck.
3989 Stuck projects are project that have no next actions. For the definitions
3990 of what a project is and how to check if it stuck, customize the variable
3991 `org-stuck-projects'.
3992 MATCH is being ignored."
3994 (let* ((org-agenda-skip-function
3995 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3996 ;; We could have used org-agenda-skip-if here.
3997 (org-agenda-overriding-header
3998 (or org-agenda-overriding-header "List of stuck projects: "))
3999 (matcher (nth 0 org-stuck-projects))
4000 (todo (nth 1 org-stuck-projects))
4001 (todo-wds (if (member "*" todo)
4003 (org-prepare-agenda-buffers (org-agenda-files
4006 org-done-keywords-for-agenda
4007 (copy-sequence org-todo-keywords-for-agenda)))
4009 (todo-re (concat "^\\*+[ \t]+\\("
4010 (mapconcat 'identity todo-wds "\\|")
4012 (tags (nth 2 org-stuck-projects))
4013 (tags-re (if (member "*" tags)
4014 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
4016 (concat "^\\*+ .*:\\("
4017 (mapconcat 'identity tags "\\|")
4018 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
4019 (gen-re (nth 3 org-stuck-projects))
4025 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4027 (setq org-agenda-skip-regexp
4029 (mapconcat 'identity re-list "\\|")
4030 (error "No information how to identify unstuck projects")))
4031 (org-tags-view nil matcher)
4032 (with-current-buffer org-agenda-buffer-name
4033 (setq org-agenda-redo-command
4034 '(org-agenda-list-stuck-projects
4035 (or current-prefix-arg org-last-arg))))))
4037 ;;; Diary integration
4039 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4040 (defvar list-diary-entries-hook)
4042 (defun org-get-entries-from-diary (date)
4043 "Get the (Emacs Calendar) diary entries for DATE."
4044 (require 'diary-lib)
4045 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4046 (diary-display-hook '(fancy-diary-display))
4047 (diary-display-function 'fancy-diary-display)
4049 (list-diary-entries-hook
4050 (cons 'org-diary-default-entry list-diary-entries-hook))
4051 (diary-file-name-prefix-function nil) ; turn this feature off
4052 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4054 (org-disable-agenda-to-diary t))
4056 (save-window-excursion
4057 (funcall (if (fboundp 'diary-list-entries)
4058 'diary-list-entries 'list-diary-entries)
4060 (if (not (get-buffer diary-fancy-buffer))
4062 (with-current-buffer diary-fancy-buffer
4063 (setq buffer-read-only nil)
4064 (if (zerop (buffer-size))
4067 ;; Omit the date and other unnecessary stuff
4068 (org-agenda-cleanup-fancy-diary)
4069 ;; Add prefix to each line and extend the text properties
4070 (if (zerop (buffer-size))
4072 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
4073 (set-buffer-modified-p nil)
4074 (kill-buffer diary-fancy-buffer)))
4076 (setq entries (org-split-string entries "\n"))
4080 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4081 ;; Extend the text properties to the beginning of the line
4082 (org-add-props x (text-properties-at (1- (length x)) x)
4083 'type "diary" 'date date 'face 'org-agenda-diary))
4086 (defvar org-agenda-cleanup-fancy-diary-hook nil
4087 "Hook run when the fancy diary buffer is cleaned up.")
4089 (defun org-agenda-cleanup-fancy-diary ()
4090 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4091 This gets rid of the date, the underline under the date, and
4092 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4093 date. It also removes lines that contain only whitespace."
4094 (goto-char (point-min))
4095 (if (looking-at ".*?:[ \t]*")
4098 (re-search-forward "\n=+$" nil t)
4100 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4101 (re-search-forward "\n=+$" nil t)
4102 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4103 (goto-char (point-min))
4104 (while (re-search-forward "^ +\n" nil t)
4106 (goto-char (point-min))
4107 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4109 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4111 ;; Make sure entries from the diary have the right text properties.
4112 (eval-after-load "diary-lib"
4113 '(if (boundp 'diary-modify-entry-list-string-function)
4114 ;; We can rely on the hook, nothing to do
4116 ;; Hook not available, must use advice to make this work
4117 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4118 "Make the position visible."
4119 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4122 (setq string (org-modify-diary-entry-string string))))))
4124 (defun org-modify-diary-entry-string (string)
4125 "Add text properties to string, allowing org-mode to act on it."
4126 (org-add-props string nil
4127 'mouse-face 'highlight
4128 'help-echo (if buffer-file-name
4129 (format "mouse-2 or RET jump to diary file %s"
4130 (abbreviate-file-name buffer-file-name))
4132 'org-agenda-diary-link t
4133 'org-marker (org-agenda-new-marker (point-at-bol))))
4135 (defun org-diary-default-entry ()
4136 "Add a dummy entry to the diary.
4137 Needed to avoid empty dates which mess up holiday display."
4138 ;; Catch the error if dealing with the new add-to-diary-alist
4139 (when org-disable-agenda-to-diary
4141 (org-add-to-diary-list original-date "Org-mode dummy" "")
4143 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4145 (defun org-add-to-diary-list (&rest args)
4146 (if (fboundp 'diary-add-to-list)
4147 (apply 'diary-add-to-list args)
4148 (apply 'add-to-diary-list args)))
4150 (defvar org-diary-last-run-time nil)
4153 (defun org-diary (&rest args)
4154 "Return diary information from org-files.
4155 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4156 It accesses org files and extracts information from those files to be
4157 listed in the diary. The function accepts arguments specifying what
4158 items should be listed. For a list of arguments allowed here, see the
4159 variable `org-agenda-entry-types'.
4161 The call in the diary file should look like this:
4163 &%%(org-diary) ~/path/to/some/orgfile.org
4165 Use a separate line for each org file to check. Or, if you omit the file name,
4166 all files listed in `org-agenda-files' will be checked automatically:
4170 If you don't give any arguments (as in the example above), the default
4171 arguments (:deadline :scheduled :timestamp :sexp) are used.
4172 So the example above may also be written as
4174 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4176 The function expects the lisp variables `entry' and `date' to be provided
4177 by the caller, because this is how the calendar works. Don't use this
4178 function from a program - use `org-agenda-get-day-entries' instead."
4179 (when (> (- (org-float-time)
4180 org-agenda-last-marker-time)
4182 (org-agenda-reset-markers))
4183 (org-compile-prefix-format 'agenda)
4184 (org-set-sorting-strategy 'agenda)
4185 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4186 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4188 (org-agenda-files t)))
4189 (time (org-float-time))
4191 (when (or (not org-diary-last-run-time)
4193 org-diary-last-run-time)
4195 (org-prepare-agenda-buffers files))
4196 (setq org-diary-last-run-time time)
4197 ;; If this is called during org-agenda, don't return any entries to
4198 ;; the calendar. Org Agenda will list these entries itself.
4199 (if org-disable-agenda-to-diary (setq files nil))
4200 (while (setq file (pop files))
4201 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4202 (setq results (append results rtn)))
4204 (concat (org-finalize-agenda-entries results) "\n"))))
4206 ;;; Agenda entry finders
4208 (defun org-agenda-get-day-entries (file date &rest args)
4209 "Does the work for `org-diary' and `org-agenda'.
4210 FILE is the path to a file to be checked for entries. DATE is date like
4211 the one returned by `calendar-current-date'. ARGS are symbols indicating
4212 which kind of entries should be extracted. For details about these, see
4213 the documentation of `org-diary'."
4214 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4215 (let* ((org-startup-folded nil)
4216 (org-startup-align-all-tables nil)
4217 (buffer (if (file-exists-p file)
4218 (org-get-agenda-file-buffer file)
4219 (error "No such file %s" file)))
4220 arg results rtn deadline-results)
4222 ;; If file does not exist, make sure an error message ends up in diary
4223 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4224 (with-current-buffer buffer
4225 (unless (org-mode-p)
4226 (error "Agenda file %s is not in `org-mode'" file))
4227 (let ((case-fold-search nil))
4230 (if org-agenda-restrict
4231 (narrow-to-region org-agenda-restrict-begin
4232 org-agenda-restrict-end)
4234 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4235 (while (setq arg (pop args))
4237 ((and (eq arg :todo)
4238 (equal date (calendar-current-date)))
4239 (setq rtn (org-agenda-get-todos))
4240 (setq results (append results rtn)))
4241 ((eq arg :timestamp)
4242 (setq rtn (org-agenda-get-blocks))
4243 (setq results (append results rtn))
4244 (setq rtn (org-agenda-get-timestamps))
4245 (setq results (append results rtn)))
4247 (setq rtn (org-agenda-get-sexps))
4248 (setq results (append results rtn)))
4249 ((eq arg :scheduled)
4250 (setq rtn (org-agenda-get-scheduled deadline-results))
4251 (setq results (append results rtn)))
4253 (setq rtn (org-agenda-get-progress))
4254 (setq results (append results rtn)))
4256 (setq rtn (org-agenda-get-deadlines))
4257 (setq deadline-results (copy-sequence rtn))
4258 (setq results (append results rtn))))))))
4261 (defun org-agenda-get-todos ()
4262 "Return the TODO information for agenda display."
4263 (let* ((props (list 'face nil
4264 'done-face 'org-agenda-done
4265 'org-not-done-regexp org-not-done-regexp
4266 'org-todo-regexp org-todo-regexp
4267 'org-complex-heading-regexp org-complex-heading-regexp
4268 'mouse-face 'highlight
4270 (format "mouse-2 or RET jump to org file %s"
4271 (abbreviate-file-name buffer-file-name))))
4272 (regexp (concat "^\\*+[ \t]+\\("
4273 (if org-select-this-todo-keyword
4274 (if (equal org-select-this-todo-keyword "*")
4277 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4279 org-not-done-regexp)
4281 marker priority category tags todo-state
4283 (goto-char (point-min))
4284 (while (re-search-forward regexp nil t)
4288 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4289 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4290 (goto-char (1+ beg))
4291 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4295 (goto-char (match-beginning 1))
4296 (setq marker (org-agenda-new-marker (match-beginning 0))
4297 category (org-get-category)
4298 txt (match-string 1)
4299 tags (org-get-tags-at (point))
4300 txt (org-format-agenda-item "" txt category tags)
4301 priority (1+ (org-get-priority txt))
4302 todo-state (org-get-todo-state))
4303 (org-add-props txt props
4304 'org-marker marker 'org-hd-marker marker
4305 'priority priority 'org-category category
4306 'type "todo" 'todo-state todo-state)
4308 (if org-agenda-todo-list-sublevels
4309 (goto-char (match-end 1))
4310 (org-end-of-subtree 'invisible))))
4314 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4316 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4317 (when (or org-agenda-todo-ignore-with-date
4318 org-agenda-todo-ignore-scheduled
4319 org-agenda-todo-ignore-deadlines)
4320 (setq end (or end (save-excursion (outline-next-heading) (point))))
4322 (or (and org-agenda-todo-ignore-with-date
4323 (re-search-forward org-ts-regexp end t))
4324 (and org-agenda-todo-ignore-scheduled
4325 (re-search-forward org-scheduled-time-regexp end t)
4327 ((eq org-agenda-todo-ignore-scheduled 'future)
4328 (> (org-days-to-time (match-string 1)) 0))
4329 ((eq org-agenda-todo-ignore-scheduled 'past)
4330 (<= (org-days-to-time (match-string 1)) 0))
4332 (and org-agenda-todo-ignore-deadlines
4333 (re-search-forward org-deadline-time-regexp end t)
4335 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4336 ((eq org-agenda-todo-ignore-deadlines 'far)
4337 (not (org-deadline-close (match-string 1))))
4338 ((eq org-agenda-todo-ignore-deadlines 'future)
4339 (> (org-days-to-time (match-string 1)) 0))
4340 ((eq org-agenda-todo-ignore-deadlines 'past)
4341 (<= (org-days-to-time (match-string 1)) 0))
4342 (t (org-deadline-close (match-string 1)))))))))
4344 (defconst org-agenda-no-heading-message
4345 "No heading for this item in buffer or region.")
4347 (defun org-agenda-get-timestamps ()
4348 "Return the date stamp information for agenda display."
4349 (let* ((props (list 'face nil
4350 'org-not-done-regexp org-not-done-regexp
4351 'org-todo-regexp org-todo-regexp
4352 'org-complex-heading-regexp org-complex-heading-regexp
4353 'mouse-face 'highlight
4355 (format "mouse-2 or RET jump to org file %s"
4356 (abbreviate-file-name buffer-file-name))))
4357 (d1 (calendar-absolute-from-gregorian date))
4363 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4367 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4371 (car org-time-stamp-formats)
4372 (apply 'encode-time ; DATE bound by calendar
4373 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4375 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4376 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4377 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4378 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4379 todo-state end-of-match)
4380 (goto-char (point-min))
4381 (while (setq end-of-match (re-search-forward regexp nil t))
4382 (setq b0 (match-beginning 0)
4383 b3 (match-beginning 3) e3 (match-end 3))
4385 (and (org-at-date-range-p) (throw :skip nil))
4387 (if (and (match-end 1)
4388 (not (= d1 (org-time-string-to-absolute
4389 (match-string 1) d1 nil
4390 org-agenda-repeating-timestamp-show-all))))
4393 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4395 (setq tmp (buffer-substring (max (point-min)
4396 (- b0 org-ds-keyword-length))
4398 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4399 inactivep (= (char-after b0) ?\[)
4400 deadlinep (string-match org-deadline-regexp tmp)
4401 scheduledp (string-match org-scheduled-regexp tmp)
4402 closedp (and org-agenda-include-inactive-timestamps
4403 (string-match org-closed-string tmp))
4404 clockp (and org-agenda-include-inactive-timestamps
4405 (or (string-match org-clock-string tmp)
4406 (string-match "]-+\\'" tmp)))
4407 todo-state (ignore-errors (org-get-todo-state))
4408 donep (member todo-state org-done-keywords))
4409 (if (or scheduledp deadlinep closedp clockp
4410 (and donep org-agenda-skip-timestamp-if-done))
4412 (if (string-match ">" timestr)
4413 ;; substring should only run to end of time stamp
4414 (setq timestr (substring timestr 0 (match-end 0))))
4415 (setq marker (org-agenda-new-marker b0)
4416 category (org-get-category b0))
4418 (if (not (re-search-backward "^\\*+ " nil t))
4419 (setq txt org-agenda-no-heading-message)
4420 (goto-char (match-beginning 0))
4421 (setq hdmarker (org-agenda-new-marker)
4422 tags (org-get-tags-at))
4423 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4424 (setq head (match-string 1))
4425 (setq txt (org-format-agenda-item
4426 (if inactivep org-agenda-inactive-leader nil)
4427 head category tags timestr nil
4429 (setq priority (org-get-priority txt))
4430 (org-add-props txt props
4431 'org-marker marker 'org-hd-marker hdmarker)
4432 (org-add-props txt nil 'priority priority
4433 'org-category category 'date date
4434 'todo-state todo-state
4437 (if org-agenda-skip-additional-timestamps-same-entry
4438 (outline-next-heading)
4439 (goto-char end-of-match))))
4442 (defun org-agenda-get-sexps ()
4443 "Return the sexp information for agenda display."
4444 (require 'diary-lib)
4445 (let* ((props (list 'face nil
4446 'mouse-face 'highlight
4448 (format "mouse-2 or RET jump to org file %s"
4449 (abbreviate-file-name buffer-file-name))))
4451 marker category ee txt tags entry result beg b sexp sexp-entry
4453 (goto-char (point-min))
4454 (while (re-search-forward regexp nil t)
4457 (setq beg (match-beginning 0))
4458 (goto-char (1- (match-end 0)))
4461 (setq sexp (buffer-substring b (point)))
4462 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4463 (org-trim (match-string 1))
4465 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4467 (setq marker (org-agenda-new-marker beg)
4468 category (org-get-category beg)
4469 todo-state (org-get-todo-state))
4471 (if (string-match "\\S-" result)
4473 (setq txt "SEXP entry returned empty string"))
4475 (setq txt (org-format-agenda-item
4476 "" txt category tags 'time))
4477 (org-add-props txt props 'org-marker marker)
4478 (org-add-props txt nil
4479 'org-category category 'date date 'todo-state todo-state
4484 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4485 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4486 The order of the first 2 times 3 arguments depends on the variable
4487 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4488 So for American calendars, give this as MONTH DAY YEAR, for European as
4489 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4490 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4491 is any number of ISO weeks in the block period for which the item should
4493 (let* ((date1 (calendar-absolute-from-gregorian
4494 (org-order-calendar-date-args m1 d1 y1)))
4495 (date2 (calendar-absolute-from-gregorian
4496 (org-order-calendar-date-args m2 d2 y2)))
4497 (d (calendar-absolute-from-gregorian date)))
4501 (= (calendar-day-of-week date) dayname)
4502 (or (not skip-weeks)
4505 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4508 (defalias 'org-get-closed 'org-agenda-get-progress)
4509 (defun org-agenda-get-progress ()
4510 "Return the logged TODO entries for agenda display."
4511 (let* ((props (list 'mouse-face 'highlight
4512 'org-not-done-regexp org-not-done-regexp
4513 'org-todo-regexp org-todo-regexp
4514 'org-complex-heading-regexp org-complex-heading-regexp
4516 (format "mouse-2 or RET jump to org file %s"
4517 (abbreviate-file-name buffer-file-name))))
4518 (items (if (consp org-agenda-show-log)
4520 org-agenda-log-mode-items))
4524 (if (memq 'closed items) (concat "\\<" org-closed-string))
4525 (if (memq 'clock items) (concat "\\<" org-clock-string))
4526 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4527 (parts-re (if parts (mapconcat 'identity parts "\\|")
4528 (error "`org-agenda-log-mode-items' is empty")))
4530 "\\(" parts-re "\\)"
4535 (car org-time-stamp-formats)
4536 (apply 'encode-time ; DATE bound by calendar
4537 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4539 (org-agenda-search-headline-for-time nil)
4540 marker hdmarker priority category tags closedp statep clockp state
4541 ee txt extra timestr rest clocked)
4542 (goto-char (point-min))
4543 (while (re-search-forward regexp nil t)
4546 (setq marker (org-agenda-new-marker (match-beginning 0))
4547 closedp (equal (match-string 1) org-closed-string)
4548 statep (equal (string-to-char (match-string 1)) ?-)
4549 clockp (not (or closedp statep))
4550 state (and statep (match-string 2))
4551 category (org-get-category (match-beginning 0))
4552 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4554 (when (string-match "\\]" timestr)
4555 ;; substring should only run to end of time stamp
4556 (setq rest (substring timestr (match-end 0))
4557 timestr (substring timestr 0 (match-end 0)))
4558 (if (and (not closedp) (not statep)
4559 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4560 (progn (setq timestr (concat (substring timestr 0 -1)
4561 "-" (match-string 1 rest) "]"))
4562 (setq clocked (match-string 2 rest)))
4563 (setq clocked "-")))
4567 ((not org-agenda-log-mode-add-notes))
4569 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4570 (setq extra (match-string 1))))
4572 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4573 (setq extra (match-string 1)))))
4574 (if (not (re-search-backward "^\\*+ " nil t))
4575 (setq txt org-agenda-no-heading-message)
4576 (goto-char (match-beginning 0))
4577 (setq hdmarker (org-agenda-new-marker)
4578 tags (org-get-tags-at))
4579 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4580 (setq txt (match-string 1))
4582 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4583 (setq txt (concat (substring txt 0 (match-beginning 1))
4584 " - " extra " " (match-string 2 txt)))
4585 (setq txt (concat txt " - " extra))))
4586 (setq txt (org-format-agenda-item
4588 (closedp "Closed: ")
4589 (statep (concat "State: (" state ")"))
4590 (t (concat "Clocked: (" clocked ")")))
4591 txt category tags timestr)))
4592 (setq priority 100000)
4593 (org-add-props txt props
4594 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4595 'priority priority 'org-category category
4596 'type "closed" 'date date
4597 'undone-face 'org-warning 'done-face 'org-agenda-done)
4599 (goto-char (point-at-eol))))
4602 (defun org-agenda-get-deadlines ()
4603 "Return the deadline information for agenda display."
4604 (let* ((props (list 'mouse-face 'highlight
4605 'org-not-done-regexp org-not-done-regexp
4606 'org-todo-regexp org-todo-regexp
4607 'org-complex-heading-regexp org-complex-heading-regexp
4609 (format "mouse-2 or RET jump to org file %s"
4610 (abbreviate-file-name buffer-file-name))))
4611 (regexp org-deadline-time-regexp)
4612 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4613 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4614 d2 diff dfrac wdays pos pos1 category tags
4616 ee txt head face s todo-state upcomingp donep timestr)
4617 (goto-char (point-min))
4618 (while (re-search-forward regexp nil t)
4619 (setq suppress-prewarning nil)
4622 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4624 (string-match org-scheduled-time-regexp
4625 (buffer-substring (point-at-bol)
4627 (setq suppress-prewarning
4628 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4629 org-agenda-skip-deadline-prewarning-if-scheduled
4631 (setq s (match-string 1)
4633 pos (1- (match-beginning 1))
4634 d2 (org-time-string-to-absolute
4635 (match-string 1) d1 'past
4636 org-agenda-repeating-timestamp-show-all)
4638 wdays (if suppress-prewarning
4639 (let ((org-deadline-warning-days suppress-prewarning))
4642 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4643 upcomingp (and todayp (> diff 0)))
4644 ;; When to show a deadline in the calendar:
4645 ;; If the expiration is within wdays warning time.
4646 ;; Past-due deadlines are only shown on the current date
4647 (if (and (or (and (<= diff wdays)
4648 (and todayp (not org-agenda-only-exact-dates)))
4651 (setq todo-state (org-get-todo-state))
4652 (setq donep (member todo-state org-done-keywords))
4654 (or org-agenda-skip-deadline-if-done
4657 (setq category (org-get-category))
4658 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4659 (setq txt org-agenda-no-heading-message)
4660 (goto-char (match-end 0))
4661 (setq pos1 (match-beginning 0))
4662 (setq tags (org-get-tags-at pos1))
4663 (setq head (buffer-substring-no-properties
4665 (progn (skip-chars-forward "^\r\n")
4667 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4669 (concat (substring s (match-beginning 1)) " "))
4670 (setq timestr 'time))
4671 (setq txt (org-format-agenda-item
4673 (car org-agenda-deadline-leaders)
4675 (nth 1 org-agenda-deadline-leaders))
4677 (nth 1 org-agenda-deadline-leaders)
4679 (format (nth 1 org-agenda-deadline-leaders)
4682 (if (not (= diff 0)) nil timestr)))))
4684 (setq face (org-agenda-deadline-face dfrac wdays))
4685 (org-add-props txt props
4686 'org-marker (org-agenda-new-marker pos)
4687 'org-hd-marker (org-agenda-new-marker pos1)
4688 'priority (+ (- diff)
4689 (org-get-priority txt))
4690 'org-category category
4691 'todo-state todo-state
4692 'type (if upcomingp "upcoming-deadline" "deadline")
4693 'date (if upcomingp date d2)
4694 'face (if donep 'org-agenda-done face)
4695 'undone-face face 'done-face 'org-agenda-done)
4699 (defun org-agenda-deadline-face (fraction &optional wdays)
4700 "Return the face to displaying a deadline item.
4701 FRACTION is what fraction of the head-warning time has passed."
4702 (if (equal wdays 0) (setq fraction 1.))
4703 (let ((faces org-agenda-deadline-faces) f)
4705 (while (setq f (pop faces))
4706 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4708 (defun org-agenda-get-scheduled (&optional deadline-results)
4709 "Return the scheduled information for agenda display."
4710 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4711 'org-todo-regexp org-todo-regexp
4712 'org-complex-heading-regexp org-complex-heading-regexp
4713 'done-face 'org-agenda-done
4714 'mouse-face 'highlight
4716 (format "mouse-2 or RET jump to org file %s"
4717 (abbreviate-file-name buffer-file-name))))
4718 (regexp org-scheduled-time-regexp)
4719 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4720 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4722 (deadline-position-alist
4723 (mapcar (lambda (a) (and (setq mm (get-text-property
4724 0 'org-hd-marker a))
4725 (cons (marker-position mm) a)))
4727 d2 diff pos pos1 category tags donep
4728 ee txt head pastschedp todo-state face timestr s habitp)
4729 (goto-char (point-min))
4730 (while (re-search-forward regexp nil t)
4733 (setq s (match-string 1)
4735 pos (1- (match-beginning 1))
4736 d2 (org-time-string-to-absolute
4737 (match-string 1) d1 'past
4738 org-agenda-repeating-timestamp-show-all)
4740 (setq pastschedp (and todayp (< diff 0)))
4741 ;; When to show a scheduled item in the calendar:
4742 ;; If it is on or past the date.
4743 (when (or (and (< diff 0)
4744 (< (abs diff) org-scheduled-past-days)
4745 (and todayp (not org-agenda-only-exact-dates)))
4748 (setq todo-state (org-get-todo-state))
4749 (setq donep (member todo-state org-done-keywords))
4750 (setq habitp (and (functionp 'org-is-habit-p)
4753 (or habitp org-agenda-skip-scheduled-if-done
4756 (setq category (org-get-category))
4757 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4758 (setq txt org-agenda-no-heading-message)
4759 (goto-char (match-end 0))
4760 (setq pos1 (match-beginning 0))
4762 (if (or (not org-habit-show-habits)
4764 org-habit-show-habits-only-for-today))
4767 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4768 (and org-agenda-skip-scheduled-if-deadline-is-shown
4770 (setq mm (assoc pos1 deadline-position-alist)))
4772 (setq tags (org-get-tags-at))
4773 (setq head (buffer-substring-no-properties
4775 (progn (skip-chars-forward "^\r\n") (point))))
4776 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4778 (concat (substring s (match-beginning 1)) " "))
4779 (setq timestr 'time))
4780 (setq txt (org-format-agenda-item
4782 (car org-agenda-scheduled-leaders)
4783 (format (nth 1 org-agenda-scheduled-leaders)
4786 (if (not (= diff 0)) nil timestr)
4791 ((and (not habitp) pastschedp)
4792 'org-scheduled-previously)
4793 (todayp 'org-scheduled-today)
4795 habitp (and habitp (org-habit-parse-todo)))
4796 (org-add-props txt props
4798 'face (if donep 'org-agenda-done face)
4799 'org-marker (org-agenda-new-marker pos)
4800 'org-hd-marker (org-agenda-new-marker pos1)
4801 'type (if pastschedp "past-scheduled" "scheduled")
4802 'date (if pastschedp d2 date)
4803 'priority (if habitp
4804 (org-habit-get-priority habitp)
4805 (+ 94 (- 5 diff) (org-get-priority txt)))
4806 'org-category category
4808 'todo-state todo-state)
4812 (defun org-agenda-get-blocks ()
4813 "Return the date-range information for agenda display."
4814 (let* ((props (list 'face nil
4815 'org-not-done-regexp org-not-done-regexp
4816 'org-todo-regexp org-todo-regexp
4817 'org-complex-heading-regexp org-complex-heading-regexp
4818 'mouse-face 'highlight
4820 (format "mouse-2 or RET jump to org file %s"
4821 (abbreviate-file-name buffer-file-name))))
4822 (regexp org-tr-regexp)
4823 (d0 (calendar-absolute-from-gregorian date))
4824 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4826 (goto-char (point-min))
4827 (while (re-search-forward regexp nil t)
4831 (setq timestr (match-string 0)
4834 d1 (time-to-days (org-time-string-to-time s1))
4835 d2 (time-to-days (org-time-string-to-time s2)))
4836 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4837 ;; Only allow days between the limits, because the normal
4838 ;; date stamps will catch the limits.
4840 (setq todo-state (org-get-todo-state))
4841 (setq donep (member todo-state org-done-keywords))
4842 (if (and donep org-agenda-skip-timestamp-if-done)
4844 (setq marker (org-agenda-new-marker (point)))
4845 (setq category (org-get-category))
4846 (if (not (re-search-backward "^\\*+ " nil t))
4847 (setq txt org-agenda-no-heading-message)
4848 (goto-char (match-beginning 0))
4849 (setq hdmarker (org-agenda-new-marker (point)))
4850 (setq tags (org-get-tags-at))
4851 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4852 (setq head (match-string 1))
4854 (if org-agenda-remove-timeranges-from-blocks
4856 "<" (regexp-quote s1) ".*?>"
4858 "<" (regexp-quote s2) ".*?>")
4860 (setq txt (org-format-agenda-item
4862 (nth (if (= d1 d2) 0 1)
4863 org-agenda-timerange-leaders)
4864 (1+ (- d0 d1)) (1+ (- d2 d1)))
4866 timestr nil remove-re))))
4867 (org-add-props txt props
4868 'org-marker marker 'org-hd-marker hdmarker
4869 'type "block" 'date date
4870 'todo-state todo-state
4871 'priority (org-get-priority txt) 'org-category category)
4874 ;; Sort the entries by expiration date.
4877 ;;; Agenda presentation and sorting
4879 (defvar org-prefix-has-time nil
4880 "A flag, set by `org-compile-prefix-format'.
4881 The flag is set if the currently compiled format contains a `%t'.")
4882 (defvar org-prefix-has-tag nil
4883 "A flag, set by `org-compile-prefix-format'.
4884 The flag is set if the currently compiled format contains a `%T'.")
4885 (defvar org-prefix-has-effort nil
4886 "A flag, set by `org-compile-prefix-format'.
4887 The flag is set if the currently compiled format contains a `%e'.")
4888 (defvar org-prefix-category-length nil
4889 "Used by `org-compile-prefix-format' to remember the category field width.")
4890 (defvar org-prefix-category-max-length nil
4891 "Used by `org-compile-prefix-format' to remember the category field width.")
4893 (defun org-format-agenda-item (extra txt &optional category tags dotime
4894 noprefix remove-re habitp)
4895 "Format TXT to be inserted into the agenda buffer.
4896 In particular, it adds the prefix and corresponding text properties. EXTRA
4897 must be a string and replaces the `%s' specifier in the prefix format.
4898 CATEGORY (string, symbol or nil) may be used to overrule the default
4899 category taken from local variable or file name. It will replace the `%c'
4900 specifier in the format. DOTIME, when non-nil, indicates that a
4901 time-of-day should be extracted from TXT for sorting of this entry, and for
4902 the `%t' specifier in the format. When DOTIME is a string, this string is
4903 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4904 only the correctly processes TXT should be returned - this is used by
4905 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4906 Any match of REMOVE-RE will be removed from TXT."
4908 ;; Diary entries sometimes have extra whitespace at the beginning
4909 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4911 ;; Fix the tags part in txt
4912 (setq txt (org-agenda-fix-displayed-tags
4914 org-agenda-show-inherited-tags
4915 org-agenda-hide-tags-regexp))
4916 (let* ((category (or category
4918 (if buffer-file-name
4919 (file-name-sans-extension
4920 (file-name-nondirectory buffer-file-name))
4922 ;; time, tag, effort are needed for the eval of the prefix format
4923 (tag (if tags (nth (1- (length tags)) tags) ""))
4925 (ts (if dotime (concat
4926 (if (stringp dotime) dotime "")
4927 (and org-agenda-search-headline-for-time txt))))
4928 (time-of-day (and dotime (org-get-time-of-day ts)))
4929 stamp plain s0 s1 s2 t1 t2 rtn srp l
4930 duration thecategory)
4931 (and (org-mode-p) buffer-file-name
4932 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4933 (when (and dotime time-of-day)
4934 ;; Extract starting and ending time and move them to prefix
4935 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4936 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4937 (setq s0 (match-string 0 ts)
4938 srp (and stamp (match-end 3))
4939 s1 (match-string (if plain 1 2) ts)
4940 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4942 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4943 ;; them, we might want to remove them there to avoid duplication.
4944 ;; The user can turn this off with a variable.
4945 (if (and org-prefix-has-time
4946 org-agenda-remove-times-when-in-prefix (or stamp plain)
4947 (string-match (concat (regexp-quote s0) " *") txt)
4948 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4949 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4950 (= (match-beginning 0) 0)
4952 (setq txt (replace-match "" nil nil txt))))
4953 ;; Normalize the time(s) to 24 hour
4954 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4955 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4956 ;; Compute the duration
4958 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4959 (string-to-number (substring s1 3)))
4961 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4962 (string-to-number (substring s2 3))))
4963 (org-agenda-default-appointment-duration
4964 (+ t1 org-agenda-default-appointment-duration))
4966 (setq duration (if t2 (- t2 t1)))))
4968 (when (and s1 (not s2) org-agenda-default-appointment-duration
4969 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4970 (let ((m (+ (string-to-number (match-string 2 s1))
4971 (* 60 (string-to-number (match-string 1 s1)))
4972 org-agenda-default-appointment-duration))
4974 (setq h (/ m 60) m (- m (* h 60)))
4975 (setq s2 (format "%02d:%02d" h m))))
4977 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4979 ;; Tags are in the string
4980 (if (or (eq org-agenda-remove-tags t)
4981 (and org-agenda-remove-tags
4982 org-prefix-has-tag))
4983 (setq txt (replace-match "" t t txt))
4984 (setq txt (replace-match
4985 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4986 (match-string 2 txt))
4992 (or (get-text-property 0 'org-hd-marker txt)
4993 (get-text-property 0 'org-marker txt)))
4996 (setq neffort (org-hh:mm-string-to-minutes effort)
4997 effort (setq effort (concat "[" effort "]" )))))
5000 (while (string-match remove-re txt)
5001 (setq txt (replace-match "" t t txt))))
5003 ;; Create the final string
5006 ;; Prepare the variables needed in the eval of the compiled format
5007 (setq time (cond (s2 (concat s1 "-" s2))
5008 (s1 (concat s1 "......"))
5010 extra (or (and (not habitp) extra) "")
5011 category (if (symbolp category) (symbol-name category) category)
5012 thecategory (copy-sequence category))
5013 (if (string-match org-bracket-link-regexp category)
5015 (setq l (if (match-end 3)
5016 (- (match-end 3) (match-beginning 3))
5017 (- (match-end 1) (match-beginning 1))))
5018 (when (< l (or org-prefix-category-length 0))
5019 (setq category (copy-sequence category))
5020 (org-add-props category nil
5021 'extra-space (make-string
5022 (- org-prefix-category-length l 1) ?\ ))))
5023 (if (and org-prefix-category-max-length
5024 (>= (length category) org-prefix-category-max-length))
5025 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5026 ;; Evaluate the compiled format
5027 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5029 ;; And finally add the text properties
5030 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5031 (org-add-props rtn nil
5032 'org-category (if thecategory (downcase thecategory) category)
5033 'tags (mapcar 'org-downcase-keep-props tags)
5034 'org-highest-priority org-highest-priority
5035 'org-lowest-priority org-lowest-priority
5036 'prefix-length (- (length rtn) (length txt))
5037 'time-of-day time-of-day
5040 'effort-minutes neffort
5046 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5047 "Remove tags string from TXT, and add a modified list of tags.
5048 The modified list may contain inherited tags, and tags matched by
5049 `org-agenda-hide-tags-regexp' will be removed."
5050 (when (or add-inherited hide-re)
5051 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
5052 (setq txt (substring txt 0 (match-beginning 0))))
5055 (mapcar (lambda (tg)
5056 (if (or (and hide-re (string-match hide-re tg))
5057 (and (not add-inherited)
5058 (get-text-property 0 'inherited tg)))
5063 (let ((have-i (get-text-property 0 'inherited (car tags)))
5065 (setq txt (concat txt " :"
5068 (setq i (get-text-property 0 'inherited x))
5069 (if (and have-i (not i))
5075 (if have-i "::" ":"))))))
5078 (defun org-downcase-keep-props (s)
5079 (let ((props (text-properties-at 0 s)))
5080 (setq s (downcase s))
5081 (add-text-properties 0 (length s) props s)
5084 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5085 (defvar org-agenda-sorting-strategy-selected nil)
5087 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5089 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5090 ((and todayp (member 'today (car org-agenda-time-grid))))
5091 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5092 ((member 'weekly (car org-agenda-time-grid)))
5093 (t (throw 'exit list)))
5094 (let* ((have (delq nil (mapcar
5095 (lambda (x) (get-text-property 1 'time-of-day x))
5097 (string (nth 1 org-agenda-time-grid))
5098 (gridtimes (nth 2 org-agenda-time-grid))
5099 (req (car org-agenda-time-grid))
5100 (remove (member 'remove-match req))
5102 (if (and (member 'require-timed req) (not have))
5103 ;; don't show empty grid
5105 (while (setq time (pop gridtimes))
5106 (unless (and remove (member time have))
5107 (setq time (int-to-string time))
5108 (push (org-format-agenda-item
5110 (concat (substring time 0 -2) ":" (substring time -2)))
5113 1 (length (car new)) 'face 'org-time-grid (car new))))
5114 (if (member 'time-up org-agenda-sorting-strategy-selected)
5116 (append list new)))))
5118 (defun org-compile-prefix-format (key)
5119 "Compile the prefix format into a Lisp form that can be evaluated.
5120 The resulting form is returned and stored in the variable
5121 `org-prefix-format-compiled'."
5122 (setq org-prefix-has-time nil org-prefix-has-tag nil
5123 org-prefix-category-length nil org-prefix-has-effort nil)
5125 ((stringp org-agenda-prefix-format)
5126 org-agenda-prefix-format)
5127 ((assq key org-agenda-prefix-format)
5128 (cdr (assq key org-agenda-prefix-format)))
5129 (t " %-12:c%?-12t% s")))
5131 varform vars var e c f opt)
5132 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
5134 (setq var (cdr (assoc (match-string 4 s)
5135 '(("c" . category) ("t" . time) ("s" . extra)
5136 ("T" . tag) ("e" . effort))))
5137 c (or (match-string 3 s) "")
5138 opt (match-beginning 1)
5139 start (1+ (match-beginning 0)))
5140 (if (equal var 'time) (setq org-prefix-has-time t))
5141 (if (equal var 'tag) (setq org-prefix-has-tag t))
5142 (if (equal var 'effort) (setq org-prefix-has-effort t))
5143 (setq f (concat "%" (match-string 2 s) "s"))
5144 (when (equal var 'category)
5145 (setq org-prefix-category-length
5146 (floor (abs (string-to-number (match-string 2 s)))))
5147 (setq org-prefix-category-max-length
5148 (let ((x (match-string 2 s)))
5150 (if (string-match "\\.[0-9]+" x)
5151 (string-to-number (substring (match-string 0 x) 1)))))))
5154 `(if (equal "" ,var)
5156 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5157 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
5158 (setq s (replace-match "%s" t nil s))
5159 (push varform vars))
5160 (setq vars (nreverse vars))
5161 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5163 (defun org-set-sorting-strategy (key)
5164 (if (symbolp (car org-agenda-sorting-strategy))
5166 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5167 (setq org-agenda-sorting-strategy-selected
5168 (or (cdr (assq key org-agenda-sorting-strategy))
5169 (cdr (assq 'agenda org-agenda-sorting-strategy))
5170 '(time-up category-keep priority-down)))))
5172 (defun org-get-time-of-day (s &optional string mod24)
5173 "Check string S for a time of day.
5174 If found, return it as a military time number between 0 and 2400.
5175 If not found, return nil.
5176 The optional STRING argument forces conversion into a 5 character wide string
5180 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5181 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5182 (let* ((h (string-to-number (match-string 1 s)))
5183 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5184 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5185 (am-p (equal ampm "am"))
5186 (h1 (cond ((not ampm) h)
5187 ((= h 12) (if am-p 0 12))
5188 (t (+ h (if am-p 0 12)))))
5189 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5191 (t0 (+ (* 100 h2) m))
5192 (t1 (concat (if (>= h1 24) "+" " ")
5193 (if (and org-agenda-time-leading-zero
5194 (< t0 1000)) "0" "")
5195 (if (< t0 100) "0" "")
5196 (if (< t0 10) "0" "")
5197 (int-to-string t0))))
5198 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5200 (defvar org-agenda-before-sorting-filter-function nil
5201 "Function to be applied to agenda items prior to sorting.
5202 Prior to sorting also means just before they are inserted into the agenda.
5204 To aid sorting, you may revisit the original entries and add more text
5205 properties which will later be used by the sorting functions.
5207 The function should take a string argument, an agenda line.
5208 It has access to the text properties in that line, which contain among
5209 other things, the property `org-hd-marker' that points to the entry
5210 where the line comes from. Note that not all lines going into the agenda
5211 have this property, only most.
5213 The function should return the modified string. It is probably best
5214 to ONLY change text properties.
5216 You can also use this function as a filter, by returning nil for lines
5217 you don't want to have in the agenda at all. For this application, you
5218 could bind the variable in the options section of a custom command.")
5220 (defun org-finalize-agenda-entries (list &optional nosort)
5221 "Sort and concatenate the agenda items."
5222 (setq list (mapcar 'org-agenda-highlight-todo list))
5225 (when org-agenda-before-sorting-filter-function
5226 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5227 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5229 (defun org-agenda-highlight-todo (x)
5230 (let ((org-done-keywords org-done-keywords-for-agenda)
5231 (case-fold-search nil)
5235 (beginning-of-line 1)
5236 (setq re (org-get-at-bol 'org-todo-regexp))
5237 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5238 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5239 (add-text-properties (match-beginning 0) (match-end 1)
5240 (list 'face (org-get-todo-face 1)))
5241 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5242 (delete-region (match-beginning 1) (1- (match-end 0)))
5243 (goto-char (match-beginning 1))
5244 (insert (format org-agenda-todo-keyword-format s)))))
5245 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5246 pl (get-text-property 0 'prefix-length x))
5248 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5250 (add-text-properties
5251 (or (match-end 1) (match-end 0)) (match-end 0)
5252 (list 'face (org-get-todo-face (match-string 2 x)))
5255 (setq x (concat (substring x 0 (match-end 1))
5256 (format org-agenda-todo-keyword-format
5258 (org-add-props " " (text-properties-at 0 x))
5259 (substring x (match-end 3))))))
5262 (defsubst org-cmp-priority (a b)
5263 "Compare the priorities of string A and B."
5264 (let ((pa (or (get-text-property 1 'priority a) 0))
5265 (pb (or (get-text-property 1 'priority b) 0)))
5266 (cond ((> pa pb) +1)
5270 (defsubst org-cmp-effort (a b)
5271 "Compare the priorities of string A and B."
5272 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5273 (ea (or (get-text-property 1 'effort-minutes a) def))
5274 (eb (or (get-text-property 1 'effort-minutes b) def)))
5275 (cond ((> ea eb) +1)
5279 (defsubst org-cmp-category (a b)
5280 "Compare the string values of categories of strings A and B."
5281 (let ((ca (or (get-text-property 1 'org-category a) ""))
5282 (cb (or (get-text-property 1 'org-category b) "")))
5283 (cond ((string-lessp ca cb) -1)
5284 ((string-lessp cb ca) +1)
5287 (defsubst org-cmp-todo-state (a b)
5288 "Compare the todo states of strings A and B."
5289 (let* ((ma (or (get-text-property 1 'org-marker a)
5290 (get-text-property 1 'org-hd-marker a)))
5291 (mb (or (get-text-property 1 'org-marker b)
5292 (get-text-property 1 'org-hd-marker b)))
5293 (fa (and ma (marker-buffer ma)))
5294 (fb (and mb (marker-buffer mb)))
5296 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5297 (and fb (with-current-buffer fb org-todo-keywords-1))))
5298 (ta (or (get-text-property 1 'todo-state a) ""))
5299 (tb (or (get-text-property 1 'todo-state b) ""))
5300 (la (- (length (member ta todo-kwds))))
5301 (lb (- (length (member tb todo-kwds))))
5302 (donepa (member ta org-done-keywords-for-agenda))
5303 (donepb (member tb org-done-keywords-for-agenda)))
5304 (cond ((and donepa (not donepb)) -1)
5305 ((and (not donepa) donepb) +1)
5310 (defsubst org-cmp-alpha (a b)
5311 "Compare the headlines, alphabetically."
5312 (let* ((pla (get-text-property 0 'prefix-length a))
5313 (plb (get-text-property 0 'prefix-length b))
5314 (ta (and pla (substring a pla)))
5315 (tb (and plb (substring b plb))))
5317 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5318 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5319 (setq ta (substring ta (match-end 0))))
5320 (setq ta (downcase ta)))
5322 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5323 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5324 (setq tb (substring tb (match-end 0))))
5325 (setq tb (downcase tb)))
5328 ((string-lessp ta tb) -1)
5329 ((string-lessp tb ta) +1)
5332 (defsubst org-cmp-tag (a b)
5333 "Compare the string values of the first tags of A and B."
5334 (let ((ta (car (last (get-text-property 1 'tags a))))
5335 (tb (car (last (get-text-property 1 'tags b)))))
5338 ((string-lessp ta tb) -1)
5339 ((string-lessp tb ta) +1)
5342 (defsubst org-cmp-time (a b)
5343 "Compare the time-of-day values of strings A and B."
5344 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5345 (ta (or (get-text-property 1 'time-of-day a) def))
5346 (tb (or (get-text-property 1 'time-of-day b) def)))
5347 (cond ((< ta tb) -1)
5351 (defsubst org-cmp-habit-p (a b)
5352 "Compare the todo states of strings A and B."
5353 (let ((ha (get-text-property 1 'org-habit-p a))
5354 (hb (get-text-property 1 'org-habit-p b)))
5355 (cond ((and ha (not hb)) -1)
5356 ((and (not ha) hb) +1)
5359 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5361 (defun org-entries-lessp (a b)
5362 "Predicate for sorting agenda entries."
5363 ;; The following variables will be used when the form is evaluated.
5364 ;; So even though the compiler complains, keep them.
5365 (let* ((ss org-agenda-sorting-strategy-selected)
5366 (time-up (and (org-em 'time-up 'time-down ss)
5367 (org-cmp-time a b)))
5368 (time-down (if time-up (- time-up) nil))
5369 (priority-up (and (org-em 'priority-up 'priority-down ss)
5370 (org-cmp-priority a b)))
5371 (priority-down (if priority-up (- priority-up) nil))
5372 (effort-up (and (org-em 'effort-up 'effort-down ss)
5373 (org-cmp-effort a b)))
5374 (effort-down (if effort-up (- effort-up) nil))
5375 (category-up (and (or (org-em 'category-up 'category-down ss)
5376 (memq 'category-keep ss))
5377 (org-cmp-category a b)))
5378 (category-down (if category-up (- category-up) nil))
5379 (category-keep (if category-up +1 nil))
5380 (tag-up (and (org-em 'tag-up 'tag-down ss)
5382 (tag-down (if tag-up (- tag-up) nil))
5383 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5384 (org-cmp-todo-state a b)))
5385 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5386 (habit-up (and (org-em 'habit-up 'habit-down ss)
5387 (org-cmp-habit-p a b)))
5388 (habit-down (if habit-up (- habit-up) nil))
5389 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5390 (org-cmp-alpha a b)))
5391 (alpha-down (if alpha-up (- alpha-up) nil))
5392 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5393 user-defined-up user-defined-down)
5394 (if (and need-user-cmp org-agenda-cmp-user-defined
5395 (functionp org-agenda-cmp-user-defined))
5396 (setq user-defined-up
5397 (funcall org-agenda-cmp-user-defined a b)
5398 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5400 (eval (cons 'or org-agenda-sorting-strategy-selected))
5401 '((-1 . t) (1 . nil) (nil . nil))))))
5403 ;;; Agenda restriction lock
5405 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5406 "Overlay to mark the headline to which agenda commands are restricted.")
5407 (overlay-put org-agenda-restriction-lock-overlay
5408 'face 'org-agenda-restriction-lock)
5409 (overlay-put org-agenda-restriction-lock-overlay
5410 'help-echo "Agendas are currently limited to this subtree.")
5411 (org-detach-overlay org-agenda-restriction-lock-overlay)
5413 (defun org-agenda-set-restriction-lock (&optional type)
5414 "Set restriction lock for agenda, to current subtree or file.
5415 Restriction will be the file if TYPE is `file', or if type is the
5416 universal prefix '(4), or if the cursor is before the first headline
5417 in the file. Otherwise, restriction will be to the current subtree."
5419 (and (equal type '(4)) (setq type 'file))
5422 ((org-at-heading-p) 'subtree)
5423 ((condition-case nil (org-back-to-heading t) (error nil))
5426 (if (eq type 'subtree)
5428 (setq org-agenda-restrict t)
5429 (setq org-agenda-overriding-restriction 'subtree)
5430 (put 'org-agenda-files 'org-restrict
5431 (list (buffer-file-name (buffer-base-buffer))))
5432 (org-back-to-heading t)
5433 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5434 (move-marker org-agenda-restrict-begin (point))
5435 (move-marker org-agenda-restrict-end
5436 (save-excursion (org-end-of-subtree t)))
5437 (message "Locking agenda restriction to subtree"))
5438 (put 'org-agenda-files 'org-restrict
5439 (list (buffer-file-name (buffer-base-buffer))))
5440 (setq org-agenda-restrict nil)
5441 (setq org-agenda-overriding-restriction 'file)
5442 (move-marker org-agenda-restrict-begin nil)
5443 (move-marker org-agenda-restrict-end nil)
5444 (message "Locking agenda restriction to file"))
5445 (setq current-prefix-arg nil)
5446 (org-agenda-maybe-redo))
5448 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5449 "Remove the agenda restriction lock."
5451 (org-detach-overlay org-agenda-restriction-lock-overlay)
5452 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5453 (setq org-agenda-overriding-restriction nil)
5454 (setq org-agenda-restrict nil)
5455 (put 'org-agenda-files 'org-restrict nil)
5456 (move-marker org-agenda-restrict-begin nil)
5457 (move-marker org-agenda-restrict-end nil)
5458 (setq current-prefix-arg nil)
5459 (message "Agenda restriction lock removed")
5460 (or noupdate (org-agenda-maybe-redo)))
5462 (defun org-agenda-maybe-redo ()
5463 "If there is any window showing the agenda view, update it."
5464 (let ((w (get-buffer-window org-agenda-buffer-name t))
5465 (w0 (selected-window)))
5470 (if org-agenda-overriding-restriction
5471 (message "Agenda view shifted to new %s restriction"
5472 org-agenda-overriding-restriction)
5473 (message "Agenda restriction lock removed")))))
5477 (defun org-agenda-check-type (error &rest types)
5478 "Check if agenda buffer is of allowed type.
5479 If ERROR is non-nil, throw an error, otherwise just return nil."
5480 (if (memq org-agenda-type types)
5483 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5486 (defun org-agenda-quit ()
5487 "Exit agenda by removing the window or the buffer."
5489 (if org-agenda-columns-active
5491 (let ((buf (current-buffer)))
5492 (if (eq org-agenda-window-setup 'other-frame)
5495 (org-agenda-reset-markers)
5496 (org-columns-remove-overlays)
5497 (setq org-agenda-archives-mode nil)
5499 (and (not (eq org-agenda-window-setup 'current-window))
5500 (not (one-window-p))
5503 (org-agenda-reset-markers)
5504 (org-columns-remove-overlays)
5505 (setq org-agenda-archives-mode nil)))
5506 ;; Maybe restore the pre-agenda window configuration.
5507 (and org-agenda-restore-windows-after-quit
5508 (not (eq org-agenda-window-setup 'other-frame))
5509 org-pre-agenda-window-conf
5510 (set-window-configuration org-pre-agenda-window-conf))))
5512 (defun org-agenda-exit ()
5513 "Exit agenda by removing the window or the buffer.
5514 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5515 Org-mode buffers visited directly by the user will not be touched."
5517 (org-release-buffers org-agenda-new-buffers)
5518 (setq org-agenda-new-buffers nil)
5521 (defun org-agenda-execute (arg)
5522 "Execute another agenda command, keeping same window.
5523 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5526 (let ((org-agenda-window-setup 'current-window))
5529 (defun org-agenda-redo ()
5531 When this is the global TODO list, a prefix argument will be interpreted."
5533 (let* ((org-agenda-keep-modes t)
5534 (filter org-agenda-filter)
5535 (preset (get 'org-agenda-filter :preset-filter))
5536 (cols org-agenda-columns-active)
5537 (line (org-current-line))
5538 (window-line (- line (org-current-line (window-start))))
5539 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5540 (put 'org-agenda-filter :preset-filter nil)
5541 (and cols (org-columns-quit))
5542 (message "Rebuilding agenda buffer...")
5543 (org-let lprops '(eval org-agenda-redo-command))
5544 (setq org-agenda-undo-list nil
5545 org-agenda-pending-undo-list nil)
5546 (message "Rebuilding agenda buffer...done")
5547 (put 'org-agenda-filter :preset-filter preset)
5548 (and (or filter preset) (org-agenda-filter-apply filter))
5549 (and cols (interactive-p) (org-agenda-columns))
5550 (org-goto-line line)
5551 (recenter window-line)))
5554 (defvar org-global-tags-completion-table nil)
5555 (defvar org-agenda-filter-form nil)
5556 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5557 "Keep only those lines in the agenda buffer that have a specific tag.
5558 The tag is selected with its fast selection letter, as configured.
5559 With prefix argument STRIP, remove all lines that do have the tag.
5560 A lisp caller can specify CHAR. NARROW means that the new tag should be
5561 used to narrow the search - the interactive user can also press `-' or `+'
5562 to switch to narrowing."
5564 (let* ((alist org-tag-alist-for-agenda)
5565 (tag-chars (mapconcat
5566 (lambda (x) (if (and (not (symbolp (car x)))
5568 (char-to-string (cdr x))
5571 (efforts (org-split-string
5572 (or (cdr (assoc (concat org-effort-property "_ALL")
5573 org-global-properties))
5574 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5575 (effort-op org-agenda-filter-effort-default-operator)
5577 (inhibit-read-only t)
5578 (current org-agenda-filter)
5582 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5583 (if narrow "Narrow" "Filter") tag-chars
5584 (if org-agenda-auto-exclude-function "[RET], " ""))
5585 (setq char (read-char)))
5586 (when (member char '(?+ ?-))
5588 (cond ((equal char ?-) (setq strip t narrow t))
5589 ((equal char ?+) (setq strip nil narrow t)))
5591 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5592 (setq char (read-char)))
5593 (when (member char '(?< ?> ?= ??))
5594 ;; An effort operator
5595 (setq effort-op (char-to-string char))
5596 (setq alist nil) ; to make sure it will be interpreted as effort.
5597 (unless (equal char ??)
5598 (loop for i from 0 to 9 do
5602 (if (= i 9) "0" (int-to-string (1+ i)))
5603 "]" (nth i efforts))))
5604 (message "Effort%s: %s " effort-op effort-prompt)
5605 (setq char (read-char))
5606 (when (or (< char ?0) (> char ?9))
5607 (error "Need 1-9,0 to select effort" ))))
5608 (when (equal char ?\t)
5609 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5610 (org-set-local 'org-global-tags-completion-table
5611 (org-global-tags-completion-table)))
5612 (let ((completion-ignore-case t))
5613 (setq tag (org-icompleting-read
5614 "Tag: " org-global-tags-completion-table))))
5617 (org-agenda-filter-by-tag-show-all)
5618 (when org-agenda-auto-exclude-function
5619 (setq org-agenda-filter '())
5620 (dolist (tag (org-agenda-get-represented-tags))
5621 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5623 (push modifier org-agenda-filter))))
5624 (if (not (null org-agenda-filter))
5625 (org-agenda-filter-apply org-agenda-filter))))
5627 (org-agenda-filter-by-tag-show-all)
5628 (when (get 'org-agenda-filter :preset-filter)
5629 (org-agenda-filter-apply org-agenda-filter)))
5630 ((or (equal char ?\ )
5631 (setq a (rassoc char alist))
5632 (and (>= char ?0) (<= char ?9)
5633 (setq n (if (= char ?0) 9 (- char ?0 1))
5634 tag (concat effort-op (nth n efforts))
5639 (and tag (setq a (cons tag nil))))
5640 (org-agenda-filter-by-tag-show-all)
5642 (setq org-agenda-filter
5643 (cons (concat (if strip "-" "+") tag)
5644 (if narrow current nil)))
5645 (org-agenda-filter-apply org-agenda-filter))
5646 (t (error "Invalid tag selection character %c" char)))))
5648 (defun org-agenda-get-represented-tags ()
5649 "Get a list of all tags currently represented in the agenda."
5652 (goto-char (point-min))
5653 (while (setq p (next-single-property-change (point) 'tags))
5655 (mapc (lambda (x) (add-to-list 'tags x))
5656 (get-text-property (point) 'tags))))
5659 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5660 "Refine the current filter. See `org-agenda-filter-by-tag."
5662 (org-agenda-filter-by-tag strip char 'refine))
5664 (defun org-agenda-filter-make-matcher ()
5665 "Create the form that tests a line for the agenda filter."
5667 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5669 (if (member x '("-" "+"))
5670 (setq f1 (if (equal x "-") 'tags '(not tags)))
5671 (if (string-match "[<=>?]" x)
5672 (setq f1 (org-agenda-filter-effort-form x))
5673 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5674 (if (equal (string-to-char x) ?-)
5675 (setq f1 (list 'not f1))))
5677 (cons 'and (nreverse f))))
5679 (defun org-agenda-filter-effort-form (e)
5680 "Return the form to compare the effort of the current line with what E says.
5681 E looks like \"+<2:25\"."
5683 (setq e (substring e 1))
5684 (setq op (string-to-char e) e (substring e 1))
5685 (setq op (cond ((equal op ?<) '<=)
5689 (list 'org-agenda-compare-effort (list 'quote op)
5690 (org-hh:mm-string-to-minutes e))))
5692 (defun org-agenda-compare-effort (op value)
5693 "Compare the effort of the current line with VALUE, using OP.
5694 If the line does not have an effort defined, return nil."
5695 (let ((eff (org-get-at-bol 'effort-minutes)))
5698 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5701 (defun org-agenda-filter-apply (filter)
5702 "Set FILTER as the new agenda filter and apply it."
5704 (setq org-agenda-filter filter
5705 org-agenda-filter-form (org-agenda-filter-make-matcher))
5706 (org-agenda-set-mode-name)
5708 (goto-char (point-min))
5710 (if (org-get-at-bol 'org-marker)
5712 (setq tags (org-get-at-bol 'tags)) ; used in eval
5713 (if (not (eval org-agenda-filter-form))
5714 (org-agenda-filter-by-tag-hide-line))
5715 (beginning-of-line 2))
5716 (beginning-of-line 2))))))
5718 (defun org-agenda-filter-by-tag-hide-line ()
5720 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
5722 (overlay-put ov 'invisible t)
5723 (overlay-put ov 'type 'tags-filter)
5724 (push ov org-agenda-filter-overlays)))
5726 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5727 (setq pos (or pos (point)))
5729 (dolist (ov (overlays-at pos))
5730 (when (and (overlay-get ov 'invisible)
5731 (eq (overlay-get ov 'type) 'tags-filter))
5733 (if (< (overlay-start ov) (point-at-eol))
5734 (move-overlay ov (point-at-eol)
5735 (overlay-end ov)))))))
5737 (defun org-agenda-filter-by-tag-show-all ()
5738 (mapc 'delete-overlay org-agenda-filter-overlays)
5739 (setq org-agenda-filter-overlays nil)
5740 (setq org-agenda-filter nil)
5741 (setq org-agenda-filter-form nil)
5742 (org-agenda-set-mode-name))
5744 (defun org-agenda-manipulate-query-add ()
5745 "Manipulate the query by adding a search term with positive selection.
5746 Positive selection means the term must be matched for selection of an entry."
5748 (org-agenda-manipulate-query ?\[))
5749 (defun org-agenda-manipulate-query-subtract ()
5750 "Manipulate the query by adding a search term with negative selection.
5751 Negative selection means term must not be matched for selection of an entry."
5753 (org-agenda-manipulate-query ?\]))
5754 (defun org-agenda-manipulate-query-add-re ()
5755 "Manipulate the query by adding a search regexp with positive selection.
5756 Positive selection means the regexp must match for selection of an entry."
5758 (org-agenda-manipulate-query ?\{))
5759 (defun org-agenda-manipulate-query-subtract-re ()
5760 "Manipulate the query by adding a search regexp with negative selection.
5761 Negative selection means regexp must not match for selection of an entry."
5763 (org-agenda-manipulate-query ?\}))
5764 (defun org-agenda-manipulate-query (char)
5766 ((memq org-agenda-type '(timeline agenda))
5767 (let ((org-agenda-include-inactive-timestamps t))
5769 (message "Display now includes inactive timestamps as well"))
5770 ((eq org-agenda-type 'search)
5772 'org-agenda-query-string
5773 (if org-agenda-last-search-view-search-was-boolean
5774 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5775 (?\{ . " +{}") (?\} . " -{}"))))
5777 (setq org-agenda-redo-command
5778 (list 'org-search-view
5780 org-agenda-query-string
5781 (+ (length org-agenda-query-string)
5782 (if (member char '(?\{ ?\})) 0 1))))
5783 (set-register org-agenda-query-register org-agenda-query-string)
5785 (t (error "Cannot manipulate query for %s-type agenda buffers"
5788 (defun org-add-to-string (var string)
5789 (set var (concat (symbol-value var) string)))
5791 (defun org-agenda-goto-date (date)
5792 "Jump to DATE in agenda."
5793 (interactive (list (org-read-date)))
5794 (org-agenda-list nil date))
5796 (defun org-agenda-goto-today ()
5799 (org-agenda-check-type t 'timeline 'agenda)
5800 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5802 (tdpos (goto-char tdpos))
5803 ((eq org-agenda-type 'agenda)
5804 (let* ((sd (time-to-days
5805 (time-subtract (current-time)
5806 (list 0 (* 3600 org-extend-today-until) 0))))
5807 (comp (org-agenda-compute-time-span sd org-agenda-span))
5808 (org-agenda-overriding-arguments org-agenda-last-arguments))
5809 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5810 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5812 (org-agenda-find-same-or-today-or-agenda)))
5813 (t (error "Cannot find today")))))
5815 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5817 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5818 (text-property-any (point-min) (point-max) 'org-today t)
5819 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5822 (defun org-agenda-later (arg)
5823 "Go forward in time by thee current span.
5824 With prefix ARG, go forward that many times the current span."
5826 (org-agenda-check-type t 'agenda)
5827 (let* ((span org-agenda-span)
5828 (sd org-starting-day)
5829 (greg (calendar-gregorian-from-absolute sd))
5830 (cnt (org-get-at-bol 'org-day-cnt))
5834 (setq sd (+ arg sd) nd 1))
5836 (setq sd (+ (* 7 arg) sd) nd 7))
5838 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5839 sd (calendar-absolute-from-gregorian greg2))
5840 (setcar greg2 (1+ (car greg2)))
5841 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5843 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5844 sd (calendar-absolute-from-gregorian greg2))
5845 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5846 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5847 (let ((org-agenda-overriding-arguments
5848 (list (car org-agenda-last-arguments) sd nd t)))
5850 (org-agenda-find-same-or-today-or-agenda cnt))))
5852 (defun org-agenda-earlier (arg)
5853 "Go backward in time by the current span.
5854 With prefix ARG, go backward that many times the current span."
5856 (org-agenda-later (- arg)))
5858 (defun org-agenda-view-mode-dispatch ()
5859 "Call one of the view mode commands."
5861 (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
5862 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
5863 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
5864 (let ((a (read-char-exclusive)))
5866 (?d (call-interactively 'org-agenda-day-view))
5867 (?w (call-interactively 'org-agenda-week-view))
5868 (?m (call-interactively 'org-agenda-month-view))
5869 (?y (call-interactively 'org-agenda-year-view))
5870 (?l (call-interactively 'org-agenda-log-mode))
5871 (?L (org-agenda-log-mode '(4)))
5872 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5873 (?a (call-interactively 'org-agenda-archives-mode))
5874 (?A (org-agenda-archives-mode 'files))
5875 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5876 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5877 (?G (call-interactively 'org-agenda-toggle-time-grid))
5878 (?D (call-interactively 'org-agenda-toggle-diary))
5879 (?\! (call-interactively 'org-agenda-toggle-deadlines))
5880 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5881 (org-agenda-check-type t 'timeline 'agenda)
5883 (message "Display now includes inactive timestamps as well"))
5884 (?q (message "Abort"))
5885 (otherwise (error "Invalid key" )))))
5887 (defun org-agenda-day-view (&optional day-of-year)
5888 "Switch to daily view for agenda.
5889 With argument DAY-OF-YEAR, switch to that day of the year."
5891 (setq org-agenda-ndays 1)
5892 (org-agenda-change-time-span 'day day-of-year))
5893 (defun org-agenda-week-view (&optional iso-week)
5894 "Switch to daily view for agenda.
5895 With argument ISO-WEEK, switch to the corresponding ISO week.
5896 If ISO-WEEK has more then 2 digits, only the last two encode the
5897 week. Any digits before this encode a year. So 200712 means
5898 week 12 of year 2007. Years in the range 1938-2037 can also be
5899 written as 2-digit years."
5901 (setq org-agenda-ndays 7)
5902 (org-agenda-change-time-span 'week iso-week))
5903 (defun org-agenda-month-view (&optional month)
5904 "Switch to monthly view for agenda.
5905 With argument MONTH, switch to that month."
5907 (org-agenda-change-time-span 'month month))
5908 (defun org-agenda-year-view (&optional year)
5909 "Switch to yearly view for agenda.
5910 With argument YEAR, switch to that year.
5911 If MONTH has more then 2 digits, only the last two encode the
5912 month. Any digits before this encode a year. So 200712 means
5913 December year 2007. Years in the range 1938-2037 can also be
5914 written as 2-digit years."
5917 (setq year (org-small-year-to-year year)))
5918 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5919 (org-agenda-change-time-span 'year year)
5922 (defun org-agenda-change-time-span (span &optional n)
5923 "Change the agenda view to SPAN.
5924 SPAN may be `day', `week', `month', `year'."
5925 (org-agenda-check-type t 'agenda)
5926 (if (and (not n) (equal org-agenda-span span))
5927 (error "Viewing span is already \"%s\"" span))
5928 (let* ((sd (or (org-get-at-bol 'day)
5930 (computed (org-agenda-compute-time-span sd span n))
5931 (org-agenda-overriding-arguments
5932 (list (car org-agenda-last-arguments)
5933 (car computed) (cdr computed) t)))
5935 (org-agenda-find-same-or-today-or-agenda))
5936 (org-agenda-set-mode-name)
5937 (message "Switched to %s view" span))
5939 (defun org-agenda-compute-time-span (sd span &optional n)
5940 "Compute starting date and number of days for agenda.
5941 SPAN may be `day', `week', `month', `year'. The return value
5942 is a cons cell with the starting date and the number of days,
5943 so that the date SD will be in that range."
5944 (let* ((greg (calendar-gregorian-from-absolute sd))
5948 nd w1 y1 m1 thisweek)
5952 (setq sd (+ (calendar-absolute-from-gregorian
5957 (let* ((nt (calendar-day-of-week
5958 (calendar-gregorian-from-absolute sd)))
5959 (d (if org-agenda-start-on-weekday
5960 (- nt org-agenda-start-on-weekday)
5962 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5965 (setq thisweek (car (calendar-iso-from-absolute sd)))
5967 (setq y1 (org-small-year-to-year (/ n 100))
5970 (calendar-absolute-from-iso
5972 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5975 (when (and n (> n 99))
5976 (setq y1 (org-small-year-to-year (/ n 100))
5978 (setq sd (calendar-absolute-from-gregorian
5979 (list (or n mg) 1 (or y1 yg)))
5980 nd (- (calendar-absolute-from-gregorian
5981 (list (1+ (or n mg)) 1 (or y1 yg)))
5984 (setq sd (calendar-absolute-from-gregorian
5985 (list 1 1 (or n yg)))
5986 nd (- (calendar-absolute-from-gregorian
5987 (list 1 1 (1+ (or n yg))))
5991 (defun org-agenda-next-date-line (&optional arg)
5992 "Jump to the next line indicating a date in agenda buffer."
5994 (org-agenda-check-type t 'agenda 'timeline)
5995 (beginning-of-line 1)
5996 ;; This does not work if user makes date format that starts with a blank
5997 (if (looking-at "^\\S-") (forward-char 1))
5998 (if (not (re-search-forward "^\\S-" nil t arg))
6001 (error "No next date after this line in this buffer")))
6002 (goto-char (match-beginning 0)))
6004 (defun org-agenda-previous-date-line (&optional arg)
6005 "Jump to the previous line indicating a date in agenda buffer."
6007 (org-agenda-check-type t 'agenda 'timeline)
6008 (beginning-of-line 1)
6009 (if (not (re-search-backward "^\\S-" nil t arg))
6010 (error "No previous date before this line in this buffer")))
6012 ;; Initialize the highlight
6013 (defvar org-hl (make-overlay 1 1))
6014 (overlay-put org-hl 'face 'highlight)
6016 (defun org-highlight (begin end &optional buffer)
6017 "Highlight a region with overlay."
6018 (move-overlay org-hl begin end (or buffer (current-buffer))))
6020 (defun org-unhighlight ()
6021 "Detach overlay INDEX."
6022 (org-detach-overlay org-hl))
6024 ;; FIXME this is currently not used.
6025 (defun org-highlight-until-next-command (beg end &optional buffer)
6026 "Move the highlight overlay to BEG/END, remove it before the next command."
6027 (org-highlight beg end buffer)
6028 (add-hook 'pre-command-hook 'org-unhighlight-once))
6029 (defun org-unhighlight-once ()
6030 "Remove the highlight from its position, and this function from the hook."
6031 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6034 (defun org-agenda-follow-mode ()
6035 "Toggle follow mode in an agenda buffer."
6037 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6038 (org-agenda-set-mode-name)
6039 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6041 (message "Follow mode is %s"
6042 (if org-agenda-follow-mode "on" "off")))
6044 (defun org-agenda-entry-text-mode (&optional arg)
6045 "Toggle entry text mode in an agenda buffer."
6047 (setq org-agenda-entry-text-mode (or (integerp arg)
6048 (not org-agenda-entry-text-mode)))
6049 (org-agenda-entry-text-hide)
6050 (and org-agenda-entry-text-mode
6051 (let ((org-agenda-entry-text-maxlines
6052 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6053 (org-agenda-entry-text-show)))
6054 (org-agenda-set-mode-name)
6055 (message "Entry text mode is %s. Maximum number of lines is %d"
6056 (if org-agenda-entry-text-mode "on" "off")
6057 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6059 (defun org-agenda-clockreport-mode ()
6060 "Toggle clocktable mode in an agenda buffer."
6062 (org-agenda-check-type t 'agenda)
6063 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
6064 (org-agenda-set-mode-name)
6066 (message "Clocktable mode is %s"
6067 (if org-agenda-clockreport-mode "on" "off")))
6069 (defun org-agenda-log-mode (&optional special)
6070 "Toggle log mode in an agenda buffer.
6071 With argument SPECIAL, show all possible log items, not only the ones
6072 configured in `org-agenda-log-mode-items'.
6073 With a double `C-u' prefix arg, show *only* log items, nothing else."
6075 (org-agenda-check-type t 'agenda 'timeline)
6076 (setq org-agenda-show-log
6077 (if (equal special '(16))
6079 (if special '(closed clock state)
6080 (not org-agenda-show-log))))
6081 (org-agenda-set-mode-name)
6083 (message "Log mode is %s"
6084 (if org-agenda-show-log "on" "off")))
6086 (defun org-agenda-archives-mode (&optional with-files)
6087 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6088 When called with a prefix argument, include all archive files as well."
6090 (setq org-agenda-archives-mode
6091 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6092 (org-agenda-set-mode-name)
6097 ((eq org-agenda-archives-mode nil)
6098 "No archives are included")
6099 ((eq org-agenda-archives-mode 'trees)
6100 (format "Trees with :%s: tag are included" org-archive-tag))
6101 ((eq org-agenda-archives-mode t)
6102 (format "Trees with :%s: tag and all active archive files are included"
6103 org-archive-tag)))))
6105 (defun org-agenda-toggle-diary ()
6106 "Toggle diary inclusion in an agenda buffer."
6108 (org-agenda-check-type t 'agenda)
6109 (setq org-agenda-include-diary (not org-agenda-include-diary))
6111 (org-agenda-set-mode-name)
6112 (message "Diary inclusion turned %s"
6113 (if org-agenda-include-diary "on" "off")))
6115 (defun org-agenda-toggle-deadlines ()
6116 "Toggle diary inclusion in an agenda buffer."
6118 (org-agenda-check-type t 'agenda)
6119 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6121 (org-agenda-set-mode-name)
6122 (message "Deadlines inclusion turned %s"
6123 (if org-agenda-include-deadlines "on" "off")))
6125 (defun org-agenda-toggle-time-grid ()
6126 "Toggle time grid in an agenda buffer."
6128 (org-agenda-check-type t 'agenda)
6129 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6131 (org-agenda-set-mode-name)
6132 (message "Time-grid turned %s"
6133 (if org-agenda-use-time-grid "on" "off")))
6135 (defun org-agenda-set-mode-name ()
6136 "Set the mode name to indicate all the small mode settings."
6138 (concat "Org-Agenda"
6139 (if (get 'org-agenda-files 'org-restrict) " []" "")
6140 (if (equal org-agenda-ndays 1) " Day" "")
6141 (if (equal org-agenda-ndays 7) " Week" "")
6142 (if org-agenda-follow-mode " Follow" "")
6143 (if org-agenda-entry-text-mode " ETxt" "")
6144 (if org-agenda-include-diary " Diary" "")
6145 (if org-agenda-include-deadlines " Ddl" "")
6146 (if org-agenda-use-time-grid " Grid" "")
6147 (if (and (boundp 'org-habit-show-habits)
6148 org-habit-show-habits) " Habit" "")
6149 (if (consp org-agenda-show-log) " LogAll"
6150 (if org-agenda-show-log " Log" ""))
6151 (if (or org-agenda-filter (get 'org-agenda-filter
6153 (concat " {" (mapconcat
6155 (append (get 'org-agenda-filter
6157 org-agenda-filter) "") "}")
6159 (if org-agenda-archives-mode
6160 (if (eq org-agenda-archives-mode t)
6162 (format " :%s:" org-archive-tag))
6164 (if org-agenda-clockreport-mode " Clock" "")))
6165 (force-mode-line-update))
6167 (defun org-agenda-post-command-hook ()
6168 (setq org-agenda-type
6169 (or (get-text-property (point) 'org-agenda-type)
6170 (get-text-property (max (point-min) (1- (point)))
6171 'org-agenda-type))))
6173 (defun org-agenda-next-line ()
6174 "Move cursor to the next line, and show if follow mode is active."
6176 (call-interactively 'next-line)
6177 (org-agenda-do-context-action))
6179 (defun org-agenda-previous-line ()
6180 "Move cursor to the previous line, and show if follow-mode is active."
6183 (call-interactively 'previous-line)
6184 (org-agenda-do-context-action))
6186 (defun org-agenda-do-context-action ()
6187 "Show outline path and, maybe, follow mode window."
6188 (let ((m (org-get-at-bol 'org-marker)))
6189 (if (and org-agenda-follow-mode m)
6191 (if (and m org-agenda-show-outline-path)
6192 (org-with-point-at m
6193 (org-display-outline-path t)))))
6195 (defun org-agenda-show-priority ()
6196 "Show the priority of the current item.
6197 This priority is composed of the main priority given with the [#A] cookies,
6198 and by additional input from the age of a schedules or deadline entry."
6200 (let* ((pri (org-get-at-bol 'priority)))
6201 (message "Priority is %d" (if pri pri -1000))))
6203 (defun org-agenda-show-tags ()
6204 "Show the tags applicable to the current item."
6206 (let* ((tags (org-get-at-bol 'tags)))
6208 (message "Tags are :%s:"
6209 (org-no-properties (mapconcat 'identity tags ":")))
6210 (message "No tags associated with this line"))))
6212 (defun org-agenda-goto (&optional highlight)
6213 "Go to the Org-mode file which contains the item at point."
6215 (let* ((marker (or (org-get-at-bol 'org-marker)
6216 (org-agenda-error)))
6217 (buffer (marker-buffer marker))
6218 (pos (marker-position marker)))
6219 (switch-to-buffer-other-window buffer)
6224 (org-show-context 'agenda)
6226 (and (outline-next-heading)
6227 (org-flag-heading nil)))) ; show the next heading
6228 (recenter (/ (window-height) 2))
6229 (run-hooks 'org-agenda-after-show-hook)
6230 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6232 (defvar org-agenda-after-show-hook nil
6233 "Normal hook run after an item has been shown from the agenda.
6234 Point is in the buffer where the item originated.")
6236 (defun org-agenda-kill ()
6237 "Kill the entry or subtree belonging to the current agenda entry."
6239 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6240 (let* ((marker (or (org-get-at-bol 'org-marker)
6241 (org-agenda-error)))
6242 (buffer (marker-buffer marker))
6243 (pos (marker-position marker))
6244 (type (org-get-at-bol 'type))
6245 dbeg dend (n 0) conf)
6246 (org-with-remote-undo buffer
6247 (with-current-buffer buffer
6250 (if (and (org-mode-p) (not (member type '("sexp"))))
6251 (setq dbeg (progn (org-back-to-heading t) (point))
6252 dend (org-end-of-subtree t t))
6253 (setq dbeg (point-at-bol)
6254 dend (min (point-max) (1+ (point-at-eol)))))
6256 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6257 (setq conf (or (eq t org-agenda-confirm-kill)
6258 (and (numberp org-agenda-confirm-kill)
6259 (> n org-agenda-confirm-kill))))
6262 (format "Delete entry with %d lines in buffer \"%s\"? "
6263 n (buffer-name buffer))))
6265 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6266 (with-current-buffer buffer (delete-region dbeg dend))
6267 (message "Agenda item and source killed"))))
6269 (defvar org-archive-default-command)
6270 (defun org-agenda-archive-default ()
6271 "Archive the entry or subtree belonging to the current agenda entry."
6273 (require 'org-archive)
6274 (org-agenda-archive-with org-archive-default-command))
6276 (defun org-agenda-archive-default-with-confirmation ()
6277 "Archive the entry or subtree belonging to the current agenda entry."
6279 (require 'org-archive)
6280 (org-agenda-archive-with org-archive-default-command 'confirm))
6282 (defun org-agenda-archive ()
6283 "Archive the entry or subtree belonging to the current agenda entry."
6285 (org-agenda-archive-with 'org-archive-subtree))
6287 (defun org-agenda-archive-to-archive-sibling ()
6288 "Move the entry to the archive sibling."
6290 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6292 (defun org-agenda-archive-with (cmd &optional confirm)
6293 "Move the entry to the archive sibling."
6295 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6296 (let* ((marker (or (org-get-at-bol 'org-marker)
6297 (org-agenda-error)))
6298 (buffer (marker-buffer marker))
6299 (pos (marker-position marker)))
6300 (org-with-remote-undo buffer
6301 (with-current-buffer buffer
6304 (not (y-or-n-p "Archive this subtree or entry? ")))
6308 (org-remove-subtree-entries-from-agenda)
6309 (org-back-to-heading t)
6311 (error "Archiving works only in Org-mode files"))))))
6313 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6314 "Remove all lines in the agenda that correspond to a given subtree.
6315 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6316 If this information is not given, the function uses the tree at point."
6317 (let ((buf (or buf (current-buffer))) m p)
6319 (unless (and beg end)
6320 (org-back-to-heading t)
6322 (org-end-of-subtree t)
6324 (set-buffer (get-buffer org-agenda-buffer-name))
6326 (goto-char (point-max))
6327 (beginning-of-line 1)
6329 (when (and (setq m (org-get-at-bol 'org-marker))
6330 (equal buf (marker-buffer m))
6331 (setq p (marker-position m))
6334 (let ((inhibit-read-only t))
6335 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6336 (beginning-of-line 0))))))
6338 (defun org-agenda-refile (&optional goto rfloc no-update)
6339 "Refile the item at point."
6341 (if (equal goto '(16))
6342 (org-refile-goto-last-stored)
6343 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6344 (org-agenda-error)))
6345 (buffer (marker-buffer marker))
6346 (pos (marker-position marker))
6348 (org-refile-get-location
6349 (if goto "Goto: " "Refile to: ") buffer
6350 org-refile-allow-creating-parent-nodes))))
6351 (with-current-buffer buffer
6356 (org-remove-subtree-entries-from-agenda)
6357 (org-refile goto buffer rfloc)))))
6358 (unless no-update (org-agenda-redo))))
6360 (defun org-agenda-open-link (&optional arg)
6361 "Follow the link in the current line, if any.
6362 This looks for a link in the displayed line in the agenda. It also looks
6363 at the text of the entry itself."
6365 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6366 (org-get-at-bol 'org-marker)))
6367 (buffer (and marker (marker-buffer marker)))
6368 (prefix (buffer-substring
6371 (or (org-get-at-bol 'prefix-length) 0)))))
6374 (with-current-buffer buffer
6379 (org-offer-links-in-entry arg prefix)))))
6380 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6382 (beginning-of-line 1)
6383 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6384 (org-open-link-from-string (match-string 1)))
6385 (t (error "No link to open here")))))
6387 (defun org-agenda-copy-local-variable (var)
6388 "Get a variable from a referenced buffer and install it here."
6389 (let ((m (org-get-at-bol 'org-marker)))
6390 (when (and m (buffer-live-p (marker-buffer m)))
6391 (org-set-local var (with-current-buffer (marker-buffer m)
6392 (symbol-value var))))))
6394 (defun org-agenda-switch-to (&optional delete-other-windows)
6395 "Go to the Org-mode file which contains the item at point."
6397 (if (and org-return-follows-link
6398 (not (org-get-at-bol 'org-marker))
6399 (org-in-regexp org-bracket-link-regexp))
6400 (org-open-link-from-string (match-string 0))
6401 (let* ((marker (or (org-get-at-bol 'org-marker)
6402 (org-agenda-error)))
6403 (buffer (marker-buffer marker))
6404 (pos (marker-position marker)))
6405 (switch-to-buffer buffer)
6406 (and delete-other-windows (delete-other-windows))
6410 (org-show-context 'agenda)
6412 (and (outline-next-heading)
6413 (org-flag-heading nil))))))) ; show the next heading
6415 (defun org-agenda-goto-mouse (ev)
6416 "Go to the Org-mode file which contains the item at the mouse click."
6418 (mouse-set-point ev)
6421 (defun org-agenda-show (&optional full-entry)
6422 "Display the Org-mode file which contains the item at point.
6423 With prefix argument FULL-ENTRY, make the entire entry visible
6424 if it was hidden in the outline."
6426 (let ((win (selected-window)))
6428 (let ((org-show-entry-below t))
6429 (org-agenda-goto t))
6430 (org-agenda-goto t))
6431 (select-window win)))
6433 (defvar org-agenda-show-window nil)
6434 (defun org-agenda-show-and-scroll-up ()
6435 "Display the Org-mode file which contains the item at point.
6436 When called repeatedly, scroll the window that is displaying the buffer."
6438 (let ((win (selected-window)))
6439 (if (and (window-live-p org-agenda-show-window)
6440 (eq this-command last-command))
6442 (select-window org-agenda-show-window)
6443 (ignore-errors (scroll-up)))
6446 (setq org-agenda-show-window (selected-window)))
6447 (select-window win)))
6449 (defun org-agenda-show-scroll-down ()
6450 "Scroll down the window showing the agenda."
6452 (let ((win (selected-window)))
6453 (when (window-live-p org-agenda-show-window)
6454 (select-window org-agenda-show-window)
6455 (ignore-errors (scroll-down))
6456 (select-window win))))
6458 (defun org-agenda-show-1 (&optional more)
6459 "Display the Org-mode file which contains the item at point.
6460 The prefix arg selects the amount of information to display:
6463 1 just show the entry according to defaults.
6464 2 show the children view
6465 3 show the subtree view
6466 4 show the entire subtree and any LOGBOOK drawers
6467 5 show the entire subtree and any drawers
6468 With prefix argument FULL-ENTRY, make the entire entry visible
6469 if it was hidden in the outline."
6471 (let ((win (selected-window)))
6473 (org-recenter-heading 1)
6478 (org-back-to-heading)
6479 (run-hook-with-args 'org-cycle-hook 'folded))
6480 (message "Remote: FOLDED"))
6481 ((and (interactive-p) (= more 1))
6482 (message "Remote: show with default settings"))
6487 (org-back-to-heading)
6488 (run-hook-with-args 'org-cycle-hook 'children))
6489 (message "Remote: CHILDREN"))
6493 (org-back-to-heading)
6494 (run-hook-with-args 'org-cycle-hook 'subtree))
6495 (message "Remote: SUBTREE"))
6497 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6499 (concat "^[ \t]*:\\("
6500 (mapconcat 'regexp-quote org-drawers "\\|")
6504 (org-back-to-heading)
6505 (org-cycle-hide-drawers 'subtree)))
6506 (message "Remote: SUBTREE AND LOGBOOK"))
6509 (message "Remote: SUBTREE AND ALL DRAWERS")))
6510 (select-window win)))
6512 (defun org-recenter-heading (n)
6514 (org-back-to-heading)
6517 (defvar org-agenda-cycle-counter nil)
6518 (defun org-agenda-cycle-show (&optional n)
6519 "Show the current entry in another window, with default settings.
6520 Default settings are taken from `org-show-hierarchy-above' and siblings.
6521 When use repeatedly in immediate succession, the remote entry will cycle
6524 children -> subtree -> folded
6526 When called with a numeric prefix arg, that arg will be passed through to
6527 `org-agenda-show-1'. For the interpretation of that argument, see the
6528 docstring of `org-agenda-show-1'."
6531 (setq org-agenda-cycle-counter n)
6532 (if (not (eq last-command this-command))
6533 (setq org-agenda-cycle-counter 1)
6534 (if (equal org-agenda-cycle-counter 0)
6535 (setq org-agenda-cycle-counter 2)
6536 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6537 (if (> org-agenda-cycle-counter 3)
6538 (setq org-agenda-cycle-counter 0)))))
6539 (org-agenda-show-1 org-agenda-cycle-counter))
6541 (defun org-agenda-recenter (arg)
6542 "Display the Org-mode file which contains the item at point and recenter."
6544 (let ((win (selected-window)))
6547 (select-window win)))
6549 (defun org-agenda-show-mouse (ev)
6550 "Display the Org-mode file which contains the item at the mouse click."
6552 (mouse-set-point ev)
6555 (defun org-agenda-check-no-diary ()
6556 "Check if the entry is a diary link and abort if yes."
6557 (if (org-get-at-bol 'org-agenda-diary-link)
6558 (org-agenda-error)))
6560 (defun org-agenda-error ()
6561 (error "Command not allowed in this line"))
6563 (defun org-agenda-tree-to-indirect-buffer ()
6564 "Show the subtree corresponding to the current entry in an indirect buffer.
6565 This calls the command `org-tree-to-indirect-buffer' from the original
6567 With numerical prefix arg ARG, go up to this level and then take that tree.
6568 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6569 use the dedicated frame)."
6571 (org-agenda-check-no-diary)
6572 (let* ((marker (or (org-get-at-bol 'org-marker)
6573 (org-agenda-error)))
6574 (buffer (marker-buffer marker))
6575 (pos (marker-position marker)))
6576 (with-current-buffer buffer
6579 (call-interactively 'org-tree-to-indirect-buffer)))))
6581 (defvar org-last-heading-marker (make-marker)
6582 "Marker pointing to the headline that last changed its TODO state
6583 by a remote command from the agenda.")
6585 (defun org-agenda-todo-nextset ()
6586 "Switch TODO entry to next sequence."
6588 (org-agenda-todo 'nextset))
6590 (defun org-agenda-todo-previousset ()
6591 "Switch TODO entry to previous sequence."
6593 (org-agenda-todo 'previousset))
6595 (defun org-agenda-todo (&optional arg)
6596 "Cycle TODO state of line at point, also in Org-mode file.
6597 This changes the line at point, all other lines in the agenda referring to
6598 the same tree node, and the headline of the tree node in the Org-mode file."
6600 (org-agenda-check-no-diary)
6601 (let* ((col (current-column))
6602 (marker (or (org-get-at-bol 'org-marker)
6603 (org-agenda-error)))
6604 (buffer (marker-buffer marker))
6605 (pos (marker-position marker))
6606 (hdmarker (org-get-at-bol 'org-hd-marker))
6607 (todayp (equal (org-get-at-bol 'day)
6608 (time-to-days (current-time))))
6609 (inhibit-read-only t)
6610 org-agenda-headline-snapshot-before-repeat newhead just-one)
6611 (org-with-remote-undo buffer
6612 (with-current-buffer buffer
6615 (org-show-context 'agenda)
6617 (and (outline-next-heading)
6618 (org-flag-heading nil))) ; show the next heading
6619 (let ((current-prefix-arg arg))
6620 (call-interactively 'org-todo))
6621 (and (bolp) (forward-char 1))
6622 (setq newhead (org-get-heading))
6623 (when (and (org-bound-and-true-p
6624 org-agenda-headline-snapshot-before-repeat)
6625 (not (equal org-agenda-headline-snapshot-before-repeat
6628 (setq newhead org-agenda-headline-snapshot-before-repeat
6631 (org-back-to-heading)
6632 (move-marker org-last-heading-marker (point))))
6633 (beginning-of-line 1)
6635 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6636 (org-move-to-column col))))
6638 (defun org-agenda-add-note (&optional arg)
6639 "Add a time-stamped note to the entry at point."
6641 (org-agenda-check-no-diary)
6642 (let* ((marker (or (org-get-at-bol 'org-marker)
6643 (org-agenda-error)))
6644 (buffer (marker-buffer marker))
6645 (pos (marker-position marker))
6646 (hdmarker (org-get-at-bol 'org-hd-marker))
6647 (inhibit-read-only t))
6648 (with-current-buffer buffer
6651 (org-show-context 'agenda)
6653 (and (outline-next-heading)
6654 (org-flag-heading nil))) ; show the next heading
6657 (defun org-agenda-change-all-lines (newhead hdmarker
6658 &optional fixface just-this)
6659 "Change all lines in the agenda buffer which match HDMARKER.
6660 The new content of the line will be NEWHEAD (as modified by
6661 `org-format-agenda-item'). HDMARKER is checked with
6662 `equal' against all `org-hd-marker' text properties in the file.
6663 If FIXFACE is non-nil, the face of each item is modified according to
6665 If JUST-THIS is non-nil, change just the current line, not all.
6666 If FORCE-TAGS is non nil, the car of it returns the new tags."
6667 (let* ((inhibit-read-only t)
6668 (line (org-current-line))
6669 (thetags (with-current-buffer (marker-buffer hdmarker)
6670 (save-excursion (save-restriction (widen)
6671 (goto-char hdmarker)
6672 (org-get-tags-at)))))
6673 props m pl undone-face done-face finish new dotime cat tags)
6675 (goto-char (point-max))
6676 (beginning-of-line 1)
6678 (setq finish (bobp))
6679 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6680 (or (not just-this) (= (org-current-line) line))
6682 (setq props (text-properties-at (point))
6683 dotime (org-get-at-bol 'dotime)
6684 cat (org-get-at-bol 'org-category)
6686 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6687 pl (org-get-at-bol 'prefix-length)
6688 undone-face (org-get-at-bol 'undone-face)
6689 done-face (org-get-at-bol 'done-face))
6690 (goto-char (+ (point) pl))
6691 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6694 (beginning-of-line 1)
6695 (and (looking-at ".*\n?") (replace-match "")))
6697 (replace-match new t t)
6698 (beginning-of-line 1)
6699 (add-text-properties (point-at-bol) (point-at-eol) props)
6701 (add-text-properties
6702 (point-at-bol) (point-at-eol)
6704 (if org-last-todo-state-is-todo
6705 undone-face done-face))))
6706 (org-agenda-highlight-todo 'line)
6707 (beginning-of-line 1))
6708 (t (error "Line update did not work"))))
6709 (beginning-of-line 0)))
6710 (org-finalize-agenda)))
6712 (defun org-agenda-align-tags (&optional line)
6713 "Align all tags in agenda items to `org-agenda-tags-column'."
6714 (let ((inhibit-read-only t) l c)
6716 (goto-char (if line (point-at-bol) (point-min)))
6717 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6718 (if line (point-at-eol) nil) t)
6719 (add-text-properties
6720 (match-beginning 2) (match-end 2)
6721 (list 'face (delq nil (let ((prop (get-text-property
6722 (match-beginning 2) 'face)))
6723 (or (listp prop) (setq prop (list prop)))
6724 (if (memq 'org-tag prop)
6726 (cons 'org-tag prop))))))
6727 (setq l (- (match-end 2) (match-beginning 2))
6728 c (if (< org-agenda-tags-column 0)
6729 (- (abs org-agenda-tags-column) l)
6730 org-agenda-tags-column))
6731 (delete-region (match-beginning 1) (match-end 1))
6732 (goto-char (match-beginning 1))
6733 (insert (org-add-props
6734 (make-string (max 1 (- c (current-column))) ?\ )
6735 (plist-put (copy-sequence (text-properties-at (point)))
6737 (goto-char (point-min))
6738 (org-font-lock-add-tag-faces (point-max)))))
6740 (defun org-agenda-priority-up ()
6741 "Increase the priority of line at point, also in Org-mode file."
6743 (org-agenda-priority 'up))
6745 (defun org-agenda-priority-down ()
6746 "Decrease the priority of line at point, also in Org-mode file."
6748 (org-agenda-priority 'down))
6750 (defun org-agenda-priority (&optional force-direction)
6751 "Set the priority of line at point, also in Org-mode file.
6752 This changes the line at point, all other lines in the agenda referring to
6753 the same tree node, and the headline of the tree node in the Org-mode file."
6755 (unless org-enable-priority-commands
6756 (error "Priority commands are disabled"))
6757 (org-agenda-check-no-diary)
6758 (let* ((marker (or (org-get-at-bol 'org-marker)
6759 (org-agenda-error)))
6760 (hdmarker (org-get-at-bol 'org-hd-marker))
6761 (buffer (marker-buffer hdmarker))
6762 (pos (marker-position hdmarker))
6763 (inhibit-read-only t)
6765 (org-with-remote-undo buffer
6766 (with-current-buffer buffer
6769 (org-show-context 'agenda)
6771 (and (outline-next-heading)
6772 (org-flag-heading nil))) ; show the next heading
6773 (funcall 'org-priority force-direction)
6775 (setq newhead (org-get-heading)))
6776 (org-agenda-change-all-lines newhead hdmarker)
6777 (beginning-of-line 1))))
6779 ;; FIXME: should fix the tags property of the agenda line.
6780 (defun org-agenda-set-tags (&optional tag onoff)
6781 "Set tags for the current headline."
6783 (org-agenda-check-no-diary)
6784 (if (and (org-region-active-p) (interactive-p))
6785 (call-interactively 'org-change-tag-in-region)
6786 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6787 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6788 (org-agenda-error)))
6789 (buffer (marker-buffer hdmarker))
6790 (pos (marker-position hdmarker))
6791 (inhibit-read-only t)
6793 (org-with-remote-undo buffer
6794 (with-current-buffer buffer
6798 (org-show-context 'agenda))
6800 (and (outline-next-heading)
6801 (org-flag-heading nil))) ; show the next heading
6804 (org-toggle-tag tag onoff)
6805 (call-interactively 'org-set-tags))
6807 (setq newhead (org-get-heading)))
6808 (org-agenda-change-all-lines newhead hdmarker)
6809 (beginning-of-line 1)))))
6811 (defun org-agenda-set-property ()
6812 "Set a property for the current headline."
6814 (org-agenda-check-no-diary)
6815 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6816 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6817 (org-agenda-error)))
6818 (buffer (marker-buffer hdmarker))
6819 (pos (marker-position hdmarker))
6820 (inhibit-read-only t)
6822 (org-with-remote-undo buffer
6823 (with-current-buffer buffer
6827 (org-show-context 'agenda))
6829 (and (outline-next-heading)
6830 (org-flag-heading nil))) ; show the next heading
6832 (call-interactively 'org-set-property)))))
6834 (defun org-agenda-set-effort ()
6835 "Set the effort property for the current headline."
6837 (org-agenda-check-no-diary)
6838 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6839 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6840 (org-agenda-error)))
6841 (buffer (marker-buffer hdmarker))
6842 (pos (marker-position hdmarker))
6843 (inhibit-read-only t)
6845 (org-with-remote-undo buffer
6846 (with-current-buffer buffer
6850 (org-show-context 'agenda))
6852 (and (outline-next-heading)
6853 (org-flag-heading nil))) ; show the next heading
6855 (call-interactively 'org-set-effort)
6858 (defun org-agenda-toggle-archive-tag ()
6859 "Toggle the archive tag for the current entry."
6861 (org-agenda-check-no-diary)
6862 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6863 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6864 (org-agenda-error)))
6865 (buffer (marker-buffer hdmarker))
6866 (pos (marker-position hdmarker))
6867 (inhibit-read-only t)
6869 (org-with-remote-undo buffer
6870 (with-current-buffer buffer
6873 (org-show-context 'agenda)
6875 (and (outline-next-heading)
6876 (org-flag-heading nil))) ; show the next heading
6877 (call-interactively 'org-toggle-archive-tag)
6879 (setq newhead (org-get-heading)))
6880 (org-agenda-change-all-lines newhead hdmarker)
6881 (beginning-of-line 1))))
6883 (defun org-agenda-do-date-later (arg)
6886 ((or (equal arg '(16))
6888 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6889 (setq this-command 'org-agenda-date-later-minutes)
6890 (org-agenda-date-later-minutes 1))
6891 ((or (equal arg '(4))
6893 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6894 (setq this-command 'org-agenda-date-later-hours)
6895 (org-agenda-date-later-hours 1))
6897 (org-agenda-date-later (prefix-numeric-value arg)))))
6899 (defun org-agenda-do-date-earlier (arg)
6902 ((or (equal arg '(16))
6904 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6905 (setq this-command 'org-agenda-date-earlier-minutes)
6906 (org-agenda-date-earlier-minutes 1))
6907 ((or (equal arg '(4))
6909 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6910 (setq this-command 'org-agenda-date-earlier-hours)
6911 (org-agenda-date-earlier-hours 1))
6913 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6915 (defun org-agenda-date-later (arg &optional what)
6916 "Change the date of this item to one day later."
6918 (org-agenda-check-type t 'agenda 'timeline)
6919 (org-agenda-check-no-diary)
6920 (let* ((marker (or (org-get-at-bol 'org-marker)
6921 (org-agenda-error)))
6922 (buffer (marker-buffer marker))
6923 (pos (marker-position marker)))
6924 (org-with-remote-undo buffer
6925 (with-current-buffer buffer
6928 (if (not (org-at-timestamp-p))
6929 (error "Cannot find time stamp"))
6930 (org-timestamp-change arg (or what 'day)))
6931 (org-agenda-show-new-time marker org-last-changed-timestamp))
6932 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6934 (defun org-agenda-date-earlier (arg &optional what)
6935 "Change the date of this item to one day earlier."
6937 (org-agenda-date-later (- arg) what))
6939 (defun org-agenda-date-later-minutes (arg)
6940 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6942 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6943 (org-agenda-date-later arg 'minute))
6945 (defun org-agenda-date-earlier-minutes (arg)
6946 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6948 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6949 (org-agenda-date-earlier arg 'minute))
6951 (defun org-agenda-date-later-hours (arg)
6952 "Change the time of this item, in hour steps."
6954 (org-agenda-date-later arg 'hour))
6956 (defun org-agenda-date-earlier-hours (arg)
6957 "Change the time of this item, in hour steps."
6959 (org-agenda-date-earlier arg 'hour))
6961 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6962 "Show new date stamp via text properties."
6963 ;; We use text properties to make this undoable
6964 (let ((inhibit-read-only t)
6965 (buffer-invisibility-spec))
6966 (setq stamp (concat " " prefix " => " stamp))
6968 (goto-char (point-max))
6970 (when (equal marker (org-get-at-bol 'org-marker))
6971 (org-move-to-column (- (window-width) (length stamp)) t)
6972 (org-agenda-fix-tags-filter-overlays-at (point))
6973 (if (featurep 'xemacs)
6974 ;; Use `duplicable' property to trigger undo recording
6975 (let ((ex (make-extent nil nil))
6976 (gl (make-glyph stamp)))
6977 (set-glyph-face gl 'secondary-selection)
6978 (set-extent-properties
6979 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6980 (insert-extent ex (1- (point)) (point-at-eol)))
6981 (add-text-properties
6982 (1- (point)) (point-at-eol)
6983 (list 'display (org-add-props stamp nil
6984 'face 'secondary-selection))))
6985 (beginning-of-line 1))
6986 (beginning-of-line 0)))))
6988 (defun org-agenda-date-prompt (arg)
6989 "Change the date of this item. Date is prompted for, with default today.
6990 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6991 be used to request time specification in the time stamp."
6993 (org-agenda-check-type t 'agenda 'timeline)
6994 (org-agenda-check-no-diary)
6995 (let* ((marker (or (org-get-at-bol 'org-marker)
6996 (org-agenda-error)))
6997 (buffer (marker-buffer marker))
6998 (pos (marker-position marker)))
6999 (org-with-remote-undo buffer
7000 (with-current-buffer buffer
7003 (if (not (org-at-timestamp-p t))
7004 (error "Cannot find time stamp"))
7005 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7006 (org-agenda-show-new-time marker org-last-changed-timestamp))
7007 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7009 (defun org-agenda-schedule (arg)
7010 "Schedule the item at point.
7011 Arg is passed through to `org-schedule'."
7013 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7014 (org-agenda-check-no-diary)
7015 (let* ((marker (or (org-get-at-bol 'org-marker)
7016 (org-agenda-error)))
7017 (type (marker-insertion-type marker))
7018 (buffer (marker-buffer marker))
7019 (pos (marker-position marker))
7020 (org-insert-labeled-timestamps-at-point nil)
7022 (set-marker-insertion-type marker t)
7023 (org-with-remote-undo buffer
7024 (with-current-buffer buffer
7027 (setq ts (org-schedule arg)))
7028 (org-agenda-show-new-time marker ts "S"))
7029 (message "Item scheduled for %s" ts)))
7031 (defun org-agenda-deadline (arg)
7032 "Schedule the item at point.
7033 Arg is passed through to `org-deadline'."
7035 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7036 (org-agenda-check-no-diary)
7037 (let* ((marker (or (org-get-at-bol 'org-marker)
7038 (org-agenda-error)))
7039 (buffer (marker-buffer marker))
7040 (pos (marker-position marker))
7041 (org-insert-labeled-timestamps-at-point nil)
7043 (org-with-remote-undo buffer
7044 (with-current-buffer buffer
7047 (setq ts (org-deadline arg)))
7048 (org-agenda-show-new-time marker ts "D"))
7049 (message "Deadline for this item set to %s" ts)))
7051 (defun org-agenda-action ()
7052 "Select entry for agenda action, or execute an agenda action.
7053 This command prompts for another letter. Valid inputs are:
7055 m Mark the entry at point for an agenda action
7056 s Schedule the marked entry to the date at the cursor
7057 d Set the deadline of the marked entry to the date at the cursor
7058 r Call `org-remember' with cursor date as the default date
7059 c Call `org-capture' with cursor date as the default date
7060 SPC Show marked entry in other window
7061 TAB Visit marked entry in other window
7063 The cursor may be at a date in the calendar, or in the Org agenda."
7066 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7067 (setq ans (read-char-exclusive))
7071 (if (eq major-mode 'org-agenda-mode)
7072 (let ((m (or (org-get-at-bol 'org-hd-marker)
7073 (org-get-at-bol 'org-marker))))
7076 (move-marker org-agenda-action-marker
7077 (marker-position m) (marker-buffer m))
7078 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7079 (error "Don't know which entry to mark")))
7080 (error "This command works only in the agenda")))
7082 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7084 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7086 (org-agenda-do-action '(org-remember) t))
7088 (org-agenda-do-action '(org-capture) t))
7090 (let ((cw (selected-window)))
7091 (org-switch-to-buffer-other-window
7092 (marker-buffer org-agenda-action-marker))
7093 (goto-char org-agenda-action-marker)
7094 (org-show-context 'agenda)
7095 (select-window cw)))
7097 (org-switch-to-buffer-other-window
7098 (marker-buffer org-agenda-action-marker))
7099 (goto-char org-agenda-action-marker)
7100 (org-show-context 'agenda))
7101 (t (error "Invalid agenda action %c" ans)))))
7103 (defun org-agenda-do-action (form &optional current-buffer)
7104 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7105 (let ((org-overriding-default-time (org-get-cursor-date)))
7108 (if (not (marker-buffer org-agenda-action-marker))
7109 (error "No entry has been selected for agenda action")
7110 (with-current-buffer (marker-buffer org-agenda-action-marker)
7114 (goto-char org-agenda-action-marker)
7117 (defun org-agenda-clock-in (&optional arg)
7118 "Start the clock on the currently selected item."
7120 (org-agenda-check-no-diary)
7121 (if (equal arg '(4))
7123 (let* ((marker (or (org-get-at-bol 'org-marker)
7124 (org-agenda-error)))
7125 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7127 (pos (marker-position marker))
7129 (org-with-remote-undo (marker-buffer marker)
7130 (with-current-buffer (marker-buffer marker)
7133 (org-show-context 'agenda)
7135 (org-cycle-hide-drawers 'children)
7137 (setq newhead (org-get-heading)))
7138 (org-agenda-change-all-lines newhead hdmarker)))))
7140 (defun org-agenda-clock-out ()
7141 "Stop the currently running clock."
7143 (unless (marker-buffer org-clock-marker)
7144 (error "No running clock"))
7145 (let ((marker (make-marker)) newhead)
7146 (org-with-remote-undo (marker-buffer org-clock-marker)
7147 (with-current-buffer (marker-buffer org-clock-marker)
7151 (goto-char org-clock-marker)
7152 (org-back-to-heading t)
7153 (move-marker marker (point))
7155 (setq newhead (org-get-heading))))))
7156 (org-agenda-change-all-lines newhead marker)
7157 (move-marker marker nil)))
7159 (defun org-agenda-clock-cancel (&optional arg)
7160 "Cancel the currently running clock."
7162 (unless (marker-buffer org-clock-marker)
7163 (error "No running clock"))
7164 (org-with-remote-undo (marker-buffer org-clock-marker)
7165 (org-clock-cancel)))
7167 (defun org-agenda-clock-goto ()
7168 "Jump to the currently clocked in task within the agenda.
7169 If the currently clocked in task is not listed in the agenda
7170 buffer, display it in another window."
7174 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7175 (setq pos (overlay-start o))))
7176 (overlays-in (point-min) (point-max)))
7177 (cond (pos (goto-char pos))
7178 ;; If the currently clocked entry is not in the agenda
7179 ;; buffer, we visit it in another window:
7180 (org-clock-current-task
7181 (org-switch-to-buffer-other-window (org-clock-goto)))
7182 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7184 (defun org-agenda-diary-entry-in-org-file ()
7185 "Make a diary entry in the file `org-agenda-diary-file'."
7186 (let (d1 d2 char (text "") dp1 dp2)
7187 (if (equal (buffer-name) "*Calendar*")
7188 (setq d1 (calendar-cursor-to-date t)
7189 d2 (car calendar-mark-ring))
7190 (setq dp1 (get-text-property (point-at-bol) 'day))
7191 (unless dp1 (error "No date defined in current line"))
7192 (setq d1 (calendar-gregorian-from-absolute dp1)
7193 d2 (and (ignore-errors (mark))
7196 (setq dp2 (get-text-property (point-at-bol) 'day)))
7197 (calendar-gregorian-from-absolute dp2))))
7198 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7199 (setq char (read-char-exclusive))
7202 (setq text (read-string "Day entry: "))
7203 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7204 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7206 (setq d1 (list (car d1) (nth 1 d1)
7207 (read-number (format "Reference year [%d]: " (nth 2 d1))
7209 (setq text (read-string "Anniversary (use %d to show years): "))
7210 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7211 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7213 (setq text (read-string "Block entry: "))
7214 (unless (and d1 d2 (not (equal d1 d2)))
7215 (error "No block of days selected"))
7216 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7217 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7219 (org-switch-to-buffer-other-window
7220 (find-file-noselect org-agenda-diary-file))
7221 (require 'org-datetree)
7222 (org-datetree-find-date-create d1)
7224 (t (error "Invalid selection character `%c'" char)))))
7226 (defcustom org-agenda-insert-diary-strategy 'date-tree
7227 "Where in `org-agenda-diary-file' should new entries be added?
7230 date-tree in the date tree, as child of the date
7231 top-level as top-level entries at the end of the file."
7234 (const :tag "in a date tree" date-tree)
7235 (const :tag "as top level at end of file" top-level)))
7237 (defcustom org-agenda-insert-diary-extract-time nil
7238 "Non-nil means extract any time specification from the diary entry."
7242 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7243 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7244 If TEXT is not empty, it will become the headline of the new entry, and
7245 the resulting entry will not be shown. When TEXT is empty, switch to
7246 `org-agenda-diary-file' and let the user finish the entry there."
7247 (let ((cw (current-window-configuration)))
7248 (org-switch-to-buffer-other-window
7249 (find-file-noselect org-agenda-diary-file))
7251 (goto-char (point-min))
7253 ((eq type 'anniversary)
7254 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7256 (or (org-on-heading-p t)
7258 (outline-next-heading)
7259 (insert "* Anniversaries\n\n")
7260 (beginning-of-line -1)))))
7261 (outline-next-heading)
7262 (org-back-over-empty-lines)
7265 (require 'diary-lib)
7266 (let ((calendar-date-display-form
7267 (if (if (boundp 'calendar-date-style)
7268 (eq calendar-date-style 'european)
7269 (org-bound-and-true-p european-calendar-style)) ; Emacs 22
7270 '(day " " month " " year)
7271 '(month " " day " " year))))
7273 (insert (format "%%%%(diary-anniversary %s) %s"
7274 (calendar-date-string d1 nil t) text))))
7276 (let ((org-prefix-has-time t)
7277 (org-agenda-time-leading-zero t)
7279 (if org-agenda-insert-diary-extract-time
7280 ;; Use org-format-agenda-item to parse text for a time-range and
7281 ;; remove it. FIXME: This is a hack, we should refactor
7282 ;; that function to make time extraction available separately
7283 (setq fmt (org-format-agenda-item nil text nil nil t)
7284 time (get-text-property 0 'time fmt)
7285 time2 (if (> (length time) 0)
7286 ;; split-string removes trailing ...... if
7287 ;; no end time given. First space
7288 ;; separates time from date.
7289 (concat " " (car (split-string time "\\.")))
7291 text (get-text-property 0 'txt fmt)))
7292 (if (eq org-agenda-insert-diary-strategy 'top-level)
7293 (org-agenda-insert-diary-as-top-level text)
7294 (require 'org-datetree)
7295 (org-datetree-find-date-create d1)
7296 (org-agenda-insert-diary-make-new-entry text))
7297 (org-insert-time-stamp (org-time-from-absolute
7298 (calendar-absolute-from-gregorian d1))
7299 nil nil nil nil time2))
7302 (if (> (calendar-absolute-from-gregorian d1)
7303 (calendar-absolute-from-gregorian d2))
7304 (setq d1 (prog1 d2 (setq d2 d1))))
7305 (if (eq org-agenda-insert-diary-strategy 'top-level)
7306 (org-agenda-insert-diary-as-top-level text)
7307 (require 'org-datetree)
7308 (org-datetree-find-date-create d1)
7309 (org-agenda-insert-diary-make-new-entry text))
7310 (org-insert-time-stamp (org-time-from-absolute
7311 (calendar-absolute-from-gregorian d1)))
7313 (org-insert-time-stamp (org-time-from-absolute
7314 (calendar-absolute-from-gregorian d2)))
7316 (if (string-match "\\S-" text)
7318 (set-window-configuration cw)
7319 (message "%s entry added to %s"
7320 (capitalize (symbol-name type))
7321 (abbreviate-file-name org-agenda-diary-file)))
7323 (message "Please finish entry here"))))
7325 (defun org-agenda-insert-diary-as-top-level (text)
7326 "Make new entry as a top-level entry at the end of the file.
7327 Add TEXT as headline, and position the cursor in the second line so that
7328 a timestamp can be added there."
7330 (goto-char (point-max))
7331 (or (bolp) (insert "\n"))
7332 (insert "* " text "\n")
7333 (if org-adapt-indentation (org-indent-to-column 2)))
7335 (defun org-agenda-insert-diary-make-new-entry (text)
7336 "Make new entry as last child of current entry.
7337 Add TEXT as headline, and position the cursor in the second line so that
7338 a timestamp can be added there."
7339 (let ((org-show-following-heading t)
7340 (org-show-siblings t)
7341 (org-show-hierarchy-above t)
7342 (org-show-entry-below t)
7344 (outline-next-heading)
7345 (org-back-over-empty-lines)
7346 (or (looking-at "[ \t]*$")
7347 (progn (insert "\n") (backward-char 1)))
7348 (org-insert-heading nil t)
7350 (setq col (current-column))
7352 (if org-adapt-indentation (org-indent-to-column col))
7353 (let ((org-show-following-heading t)
7354 (org-show-siblings t)
7355 (org-show-hierarchy-above t)
7356 (org-show-entry-below t))
7357 (org-show-context))))
7359 (defun org-agenda-diary-entry ()
7360 "Make a diary entry, like the `i' command from the calendar.
7361 All the standard commands work: block, weekly etc.
7362 When `org-agenda-diary-file' points to a file,
7363 `org-agenda-diary-entry-in-org-file' is called instead to create
7364 entries in that Org-mode file."
7366 (org-agenda-check-type t 'agenda 'timeline)
7367 (if (not (eq org-agenda-diary-file 'diary-file))
7368 (org-agenda-diary-entry-in-org-file)
7369 (require 'diary-lib)
7371 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7372 (read-char-exclusive)))
7373 (cmd (cdr (assoc char
7374 '((?d . insert-diary-entry)
7375 (?w . insert-weekly-diary-entry)
7376 (?m . insert-monthly-diary-entry)
7377 (?y . insert-yearly-diary-entry)
7378 (?a . insert-anniversary-diary-entry)
7379 (?b . insert-block-diary-entry)
7380 (?c . insert-cyclic-diary-entry)))))
7381 (oldf (symbol-function 'calendar-cursor-to-date))
7382 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7384 (mark (or (mark t) (point))))
7386 (error "No command associated with <%c>" char))
7387 (unless (and (get-text-property point 'day)
7388 (or (not (equal ?b char))
7389 (get-text-property mark 'day)))
7390 (error "Don't know which date to use for diary entry"))
7391 ;; We implement this by hacking the `calendar-cursor-to-date' function
7392 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7393 (let ((calendar-mark-ring
7394 (list (calendar-gregorian-from-absolute
7395 (or (get-text-property mark 'day)
7396 (get-text-property point 'day))))))
7399 (fset 'calendar-cursor-to-date
7400 (lambda (&optional error dummy)
7401 (calendar-gregorian-from-absolute
7402 (get-text-property point 'day))))
7403 (call-interactively cmd))
7404 (fset 'calendar-cursor-to-date oldf))))))
7406 (defun org-agenda-execute-calendar-command (cmd)
7407 "Execute a calendar command from the agenda, with the date associated to
7408 the cursor position."
7409 (org-agenda-check-type t 'agenda 'timeline)
7410 (require 'diary-lib)
7411 (unless (get-text-property (point) 'day)
7412 (error "Don't know which date to use for calendar command"))
7413 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7415 (date (calendar-gregorian-from-absolute
7416 (get-text-property point 'day)))
7417 ;; the following 2 vars are needed in the calendar
7418 (displayed-month (car date))
7419 (displayed-year (nth 2 date)))
7422 (fset 'calendar-cursor-to-date
7423 (lambda (&optional error dummy)
7424 (calendar-gregorian-from-absolute
7425 (get-text-property point 'day))))
7426 (call-interactively cmd))
7427 (fset 'calendar-cursor-to-date oldf))))
7429 (defun org-agenda-phases-of-moon ()
7430 "Display the phases of the moon for the 3 months around the cursor date."
7432 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7434 (defun org-agenda-holidays ()
7435 "Display the holidays for the 3 months around the cursor date."
7437 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7439 (defvar calendar-longitude)
7440 (defvar calendar-latitude)
7441 (defvar calendar-location-name)
7443 (defun org-agenda-sunrise-sunset (arg)
7444 "Display sunrise and sunset for the cursor date.
7445 Latitude and longitude can be specified with the variables
7446 `calendar-latitude' and `calendar-longitude'. When called with prefix
7447 argument, latitude and longitude will be prompted for."
7450 (let ((calendar-longitude (if arg nil calendar-longitude))
7451 (calendar-latitude (if arg nil calendar-latitude))
7452 (calendar-location-name
7453 (if arg "the given coordinates" calendar-location-name)))
7454 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7456 (defun org-agenda-goto-calendar ()
7457 "Open the Emacs calendar with the date at the cursor."
7459 (org-agenda-check-type t 'agenda 'timeline)
7460 (let* ((day (or (get-text-property (point) 'day)
7461 (error "Don't know which date to open in calendar")))
7462 (date (calendar-gregorian-from-absolute day))
7463 (calendar-move-hook nil)
7464 (calendar-view-holidays-initially-flag nil)
7465 (calendar-view-diary-initially-flag nil))
7467 (calendar-goto-date date)))
7470 (defun org-calendar-goto-agenda ()
7471 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7472 This is a command that has to be installed in `calendar-mode-map'."
7474 (org-agenda-list nil (calendar-absolute-from-gregorian
7475 (calendar-cursor-to-date))
7478 (defun org-agenda-convert-date ()
7480 (org-agenda-check-type t 'agenda 'timeline)
7481 (let ((day (get-text-property (point) 'day))
7484 (error "Don't know which date to convert"))
7485 (setq date (calendar-gregorian-from-absolute day))
7487 "Gregorian: " (calendar-date-string date) "\n"
7488 "ISO: " (calendar-iso-date-string date) "\n"
7489 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7490 "Julian: " (calendar-julian-date-string date) "\n"
7491 "Astron. JD: " (calendar-astro-date-string date)
7492 " (Julian date number at noon UTC)\n"
7493 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7494 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7495 "French: " (calendar-french-date-string date) "\n"
7496 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7497 "Mayan: " (calendar-mayan-date-string date) "\n"
7498 "Coptic: " (calendar-coptic-date-string date) "\n"
7499 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7500 "Persian: " (calendar-persian-date-string date) "\n"
7501 "Chinese: " (calendar-chinese-date-string date) "\n"))
7502 (with-output-to-temp-buffer "*Dates*"
7504 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7508 (defvar org-agenda-bulk-marked-entries nil
7509 "List of markers that refer to marked entries in the agenda.")
7511 (defun org-agenda-bulk-marked-p ()
7512 (eq (get-char-property (point-at-bol) 'type)
7513 'org-marked-entry-overlay))
7515 (defun org-agenda-bulk-mark ()
7516 "Mark the entry at point for future bulk action."
7518 (org-agenda-check-no-diary)
7519 (let* ((m (org-get-at-bol 'org-hd-marker))
7521 (unless (org-agenda-bulk-marked-p)
7522 (unless m (error "Nothing to mark at point"))
7523 (push m org-agenda-bulk-marked-entries)
7524 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7525 (org-overlay-display ov "> "
7526 (org-get-todo-face "TODO")
7528 (overlay-put ov 'type 'org-marked-entry-overlay))
7529 (beginning-of-line 2)
7530 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7531 (beginning-of-line 2))
7532 (message "%d entries marked for bulk action"
7533 (length org-agenda-bulk-marked-entries))))
7535 (defun org-agenda-bulk-unmark ()
7536 "Unmark the entry at point for future bulk action."
7538 (when (org-agenda-bulk-marked-p)
7539 (org-agenda-bulk-remove-overlays
7540 (point-at-bol) (+ 2 (point-at-bol)))
7541 (setq org-agenda-bulk-marked-entries
7542 (delete (org-get-at-bol 'org-hd-marker)
7543 org-agenda-bulk-marked-entries)))
7544 (beginning-of-line 2)
7545 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7546 (beginning-of-line 2))
7547 (message "%d entries marked for bulk action"
7548 (length org-agenda-bulk-marked-entries)))
7550 (defun org-agenda-bulk-toggle ()
7551 "Toggle marking the entry at point for bulk action."
7553 (if (org-agenda-bulk-marked-p)
7554 (org-agenda-bulk-unmark)
7555 (org-agenda-bulk-mark)))
7557 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7558 "Remove the mark overlays between BEG and END in the agenda buffer.
7559 BEG and END default to the buffer limits.
7561 This only removes the overlays, it does not remove the markers
7562 from the list in `org-agenda-bulk-marked-entries'."
7565 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7566 (delete-overlay ov)))
7567 (overlays-in (or beg (point-min)) (or end (point-max)))))
7569 (defun org-agenda-bulk-remove-all-marks ()
7570 "Remove all marks in the agenda buffer.
7571 This will remove the markers, and the overlays."
7573 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7574 (setq org-agenda-bulk-marked-entries nil)
7575 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7577 (defun org-agenda-bulk-action (&optional arg)
7578 "Execute an remote-editing action on all marked entries.
7579 The prefix arg is passed through to the command if possible."
7581 (unless org-agenda-bulk-marked-entries
7582 (error "No entries are marked"))
7583 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7584 (let* ((action (read-char-exclusive))
7585 (org-log-refile (if org-log-refile 'time nil))
7586 (entries (reverse org-agenda-bulk-marked-entries))
7588 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7591 (setq cmd '(org-agenda-archive)))
7594 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7596 ((member action '(?r ?w))
7597 (setq rfloc (org-refile-get-location
7599 (marker-buffer (car org-agenda-bulk-marked-entries))
7600 org-refile-allow-creating-parent-nodes))
7602 (setcar (nthcdr 3 rfloc)
7603 (move-marker (make-marker) (nth 3 rfloc)
7604 (or (get-file-buffer (nth 1 rfloc))
7605 (find-buffer-visiting (nth 1 rfloc))
7606 (error "This should not happen")))))
7608 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7612 (setq state (org-icompleting-read
7614 (with-current-buffer (marker-buffer (car entries))
7615 (mapcar 'list org-todo-keywords-1))))
7616 (setq cmd `(let ((org-inhibit-blocking t)
7617 (org-inhibit-logging 'note))
7618 (org-agenda-todo ,state))))
7620 ((memq action '(?- ?+))
7621 (setq tag (org-icompleting-read
7622 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7623 (with-current-buffer (marker-buffer (car entries))
7626 (if (stringp (car x)) x)) org-tag-alist)))))
7627 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7629 ((memq action '(?s ?d))
7630 (let* ((date (unless arg
7633 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7634 (ans (if arg nil org-read-date-final-answer))
7635 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7636 (setq cmd `(let* ((bound (fboundp 'read-string))
7637 (old (and bound (symbol-function 'read-string))))
7640 (fset 'read-string (lambda (&rest ignore) ,ans))
7643 (fset 'read-string old)
7644 (fmakunbound 'read-string)))))))
7645 (t (error "Invalid bulk action")))
7647 ;; Sort the markers, to make sure that parents are handled before children
7648 (setq entries (sort entries
7651 ((equal (marker-buffer a) (marker-buffer b))
7652 (< (marker-position a) (marker-position b)))
7654 (string< (buffer-name (marker-buffer a))
7655 (buffer-name (marker-buffer b))))))))
7657 ;; Now loop over all markers and apply cmd
7658 (while (setq e (pop entries))
7659 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7661 (progn (message "Skipping removed entry at %s" e)
7662 (setq cntskip (1+ cntskip)))
7665 (setq org-agenda-bulk-marked-entries
7666 (delete e org-agenda-bulk-marked-entries))
7667 (setq cnt (1+ cnt))))
7668 (setq org-agenda-bulk-marked-entries nil)
7669 (org-agenda-bulk-remove-all-marks)
7670 (when redo-at-end (org-agenda-redo))
7671 (message "Acted on %d entries%s"
7675 (format ", skipped %d (disappeared before their turn)"
7680 (defun org-agenda-show-the-flagging-note ()
7681 "Display the flagging note in the other window.
7682 When called a second time in direct sequence, offer to remove the FLAGGING
7683 tag and (if present) the flagging note."
7685 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7686 (win (selected-window))
7687 note heading newhead)
7689 (error "No linked entry at point"))
7690 (if (and (eq this-command last-command)
7691 (y-or-n-p "Unflag and remove any flagging note? "))
7693 (org-agenda-remove-flag hdmarker)
7694 (let ((win (get-buffer-window "*Flagging Note*")))
7695 (and win (delete-window win)))
7696 (message "Entry unflaged"))
7697 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7699 (error "No flagging note"))
7701 (org-switch-to-buffer-other-window "*Flagging Note*")
7704 (goto-char (point-min))
7705 (while (re-search-forward "\\\\n" nil t)
7706 (replace-match "\n" t t))
7707 (goto-char (point-min))
7709 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7711 (defun org-agenda-remove-flag (marker)
7712 "Remove the FLAGGED tag and any flagging note in the entry."
7714 (org-with-point-at marker
7715 (org-toggle-tag "FLAGGED" 'off)
7716 (org-entry-delete nil "THEFLAGGINGNOTE")
7717 (setq newhead (org-get-heading)))
7718 (org-agenda-change-all-lines newhead marker)
7719 (message "Entry unflaged")))
7721 (defun org-agenda-get-any-marker (&optional pos)
7722 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7723 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7725 ;;; Appointment reminders
7727 (defvar appt-time-msg-list)
7730 (defun org-agenda-to-appt (&optional refresh filter)
7731 "Activate appointments found in `org-agenda-files'.
7732 With a \\[universal-argument] prefix, refresh the list of
7735 If FILTER is t, interactively prompt the user for a regular
7736 expression, and filter out entries that don't match it.
7738 If FILTER is a string, use this string as a regular expression
7739 for filtering entries out.
7741 FILTER can also be an alist with the car of each cell being
7742 either 'headline or 'category. For example:
7744 '((headline \"IMPORTANT\")
7745 (category \"Work\"))
7747 will only add headlines containing IMPORTANT or headlines
7748 belonging to the \"Work\" category."
7750 (if refresh (setq appt-time-msg-list nil))
7752 (setq filter (read-from-minibuffer "Regexp filter: ")))
7753 (let* ((cnt 0) ; count added events
7754 (org-agenda-new-buffers nil)
7755 (org-deadline-warning-days 0)
7756 (today (org-date-to-gregorian
7757 (time-to-days (current-time))))
7758 (org-agenda-restrict nil)
7759 (files (org-agenda-files 'unrestricted)) entries file)
7760 ;; Get all entries which may contain an appt
7761 (org-prepare-agenda-buffers files)
7762 (while (setq file (pop files))
7765 (org-agenda-get-day-entries
7766 file today :timestamp :scheduled :deadline))))
7767 (setq entries (delq nil entries))
7768 ;; Map thru entries and find if we should filter them out
7771 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7772 (cat (get-text-property 1 'org-category x))
7773 (tod (get-text-property 1 'time-of-day x))
7774 (ok (or (null filter)
7775 (and (stringp filter) (string-match filter evt))
7778 (cadr (assoc 'category filter)) cat)
7780 (cadr (assoc 'headline filter)) evt))))))
7781 ;; FIXME: Shall we remove text-properties for the appt text?
7782 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7784 (setq tod (concat "00" (number-to-string tod))
7785 tod (when (string-match
7786 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7787 (concat (match-string 1 tod) ":"
7788 (match-string 2 tod))))
7790 (setq cnt (1+ cnt))))) entries)
7791 (org-release-buffers org-agenda-new-buffers)
7793 (message "No event to add")
7794 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7796 (defun org-agenda-todayp (date)
7797 "Does DATE mean today, when considering `org-extend-today-until'?"
7799 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7800 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7801 (setq h (nth 2 (decode-time (current-time))))
7802 (or (and (>= h org-extend-today-until)
7804 (and (< h org-extend-today-until)
7805 (= date (1- today))))))
7807 (provide 'org-agenda)
7809 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7811 ;;; org-agenda.el ends here