1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
52 (declare-function diary-add-to-list
"diary-lib"
53 (date string specifier
&optional marker globcolor literal
))
54 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
55 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
56 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
57 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
58 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
59 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
60 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
61 (declare-function calendar-goto-date
"cal-move" (date))
62 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
63 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
64 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
65 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
66 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
67 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
68 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
69 (declare-function calendar-check-holidays
"holidays" (date))
71 (declare-function org-datetree-find-date-create
"org-datetree"
72 (date &optional keep-restriction
))
73 (declare-function org-columns-quit
"org-colview" ())
74 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
75 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
76 (declare-function org-habit-insert-consistency-graphs
77 "org-habit" (&optional line
))
78 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
79 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
80 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
81 (declare-function org-pop-to-buffer-same-window
"org-compat"
82 (&optional buffer-or-name norecord label
))
84 (defvar calendar-mode-map
)
85 (defvar org-clock-current-task
) ; defined in org-clock.el
86 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
87 (defvar org-habit-show-habits
)
88 (defvar org-habit-show-habits-only-for-today
)
90 ;; Defined somewhere in this file, but used before definition.
91 (defvar org-agenda-buffer-name
)
92 (defvar org-agenda-overriding-header
)
93 (defvar org-agenda-title-append nil
)
96 (defvar org-agenda-undo-list
)
97 (defvar org-agenda-pending-undo-list
)
98 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
100 (defcustom org-agenda-confirm-kill
1
101 "When set, remote killing from the agenda buffer needs confirmation.
102 When t, a confirmation is always needed. When a number N, confirmation is
103 only needed when the text to be killed contains more than N non-white lines."
106 (const :tag
"Never" nil
)
107 (const :tag
"Always" t
)
108 (integer :tag
"When more than N lines")))
110 (defcustom org-agenda-compact-blocks nil
111 "Non-nil means make the block agenda more compact.
112 This is done globally by leaving out lines like the agenda span
113 name and week number or the separator lines."
117 (defcustom org-agenda-block-separator ?
=
118 "The separator between blocks in the agenda.
119 If this is a string, it will be used as the separator, with a newline added.
120 If it is a character, it will be repeated to fill the window width.
121 If nil the separator is disabled. In `org-agenda-custom-commands' this
122 addresses the separator between the current and the previous block."
125 (const :tag
"Disabled" nil
)
129 (defgroup org-agenda-export nil
130 "Options concerning exporting agenda views in Org-mode."
131 :tag
"Org Agenda Export"
134 (defcustom org-agenda-with-colors t
135 "Non-nil means use colors in agenda views."
136 :group
'org-agenda-export
139 (defcustom org-agenda-exporter-settings nil
140 "Alist of variable/value pairs that should be active during agenda export.
141 This is a good place to set options for ps-print and for htmlize.
142 Note that the way this is implemented, the values will be evaluated
143 before assigned to the variables. So make sure to quote values you do
144 *not* want evaluated, for example
146 (setq org-agenda-exporter-settings
147 '((ps-print-color-p 'black-white)))"
148 :group
'org-agenda-export
152 (sexp :tag
"Value"))))
154 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
155 "Hook run in temporary buffer before writing it to an export file.
156 A useful function is `org-agenda-add-entry-text'."
157 :group
'org-agenda-export
159 :options
'(org-agenda-add-entry-text))
161 (defcustom org-agenda-add-entry-text-maxlines
0
162 "Maximum number of entry text lines to be added to agenda.
163 This is only relevant when `org-agenda-add-entry-text' is part of
164 `org-agenda-before-write-hook', which it is by default.
165 When this is 0, nothing will happen. When it is greater than 0, it
166 specifies the maximum number of lines that will be added for each entry
167 that is listed in the agenda view.
169 Note that this variable is not used during display, only when exporting
170 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
171 and `org-agenda-entry-text-maxlines'."
175 (defcustom org-agenda-add-entry-text-descriptive-links t
176 "Non-nil means export org-links as descriptive links in agenda added text.
177 This variable applies to the text added to the agenda when
178 `org-agenda-add-entry-text-maxlines' is larger than 0.
179 When this variable nil, the URL will (also) be shown."
183 (defcustom org-agenda-export-html-style
""
184 "The style specification for exported HTML Agenda files.
185 If this variable contains a string, it will replace the default <style>
186 section as produced by `htmlize'.
187 Since there are different ways of setting style information, this variable
188 needs to contain the full HTML structure to provide a style, including the
189 surrounding HTML tags. The style specifications should include definitions
190 the fonts used by the agenda, here is an example:
192 <style type=\"text/css\">
193 p { font-weight: normal; color: gray; }
194 .org-agenda-structure {
209 .title { text-align: center; }
210 .todo, .deadline { color: red; }
211 .done { color: green; }
214 or, if you want to keep the style in a file,
216 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
218 As the value of this option simply gets inserted into the HTML <head> header,
219 you can \"misuse\" it to also add other text to the header. However,
220 <style>...</style> is required, if not present the variable will be ignored."
221 :group
'org-agenda-export
222 :group
'org-export-html
225 (defcustom org-agenda-persistent-filter nil
226 "When set, keep filters from one agenda view to the next."
230 (defgroup org-agenda-custom-commands nil
231 "Options concerning agenda views in Org-mode."
232 :tag
"Org Agenda Custom Commands"
235 (defconst org-sorting-choice
237 (const time-up
) (const time-down
)
238 (const category-keep
) (const category-up
) (const category-down
)
239 (const tag-down
) (const tag-up
)
240 (const priority-up
) (const priority-down
)
241 (const todo-state-up
) (const todo-state-down
)
242 (const effort-up
) (const effort-down
)
243 (const habit-up
) (const habit-down
)
244 (const alpha-up
) (const alpha-down
)
245 (const user-defined-up
) (const user-defined-down
))
248 ;; Keep custom values for `org-agenda-filter-preset' compatible with
249 ;; the new variable `org-agenda-tag-filter-preset'.
250 (if (fboundp 'defvaralias
)
251 (defvaralias 'org-agenda-filter-preset
'org-agenda-tag-filter-preset
)
252 (defvaralias 'org-agenda-filter
'org-agenda-tag-filter
))
254 (defconst org-agenda-custom-commands-local-options
255 `(repeat :tag
"Local settings for this command. Remember to quote values"
256 (choice :tag
"Setting"
257 (list :tag
"Heading for this block"
258 (const org-agenda-overriding-header
)
259 (string :tag
"Headline"))
260 (list :tag
"Files to be searched"
261 (const org-agenda-files
)
263 (const :format
"" quote
)
265 (list :tag
"Sorting strategy"
266 (const org-agenda-sorting-strategy
)
268 (const :format
"" quote
)
270 ,org-sorting-choice
)))
271 (list :tag
"Prefix format"
272 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
274 (list :tag
"Number of days in agenda"
275 (const org-agenda-span
)
276 (choice (const :tag
"Day" 'day
)
277 (const :tag
"Week" 'week
)
278 (const :tag
"Month" 'month
)
279 (const :tag
"Year" 'year
)
280 (integer :tag
"Custom")))
281 (list :tag
"Fixed starting date"
282 (const org-agenda-start-day
)
283 (string :value
"2007-11-01"))
284 (list :tag
"Start on day of week"
285 (const org-agenda-start-on-weekday
)
287 (const :tag
"Today" nil
)
288 (integer :tag
"Weekday No.")))
289 (list :tag
"Include data from diary"
290 (const org-agenda-include-diary
)
292 (list :tag
"Deadline Warning days"
293 (const org-deadline-warning-days
)
295 (list :tag
"Category filter preset"
296 (const org-agenda-category-filter-preset
)
298 (const :format
"" quote
)
300 (string :tag
"+category or -category"))))
301 (list :tag
"Tags filter preset"
302 (const org-agenda-tag-filter-preset
)
304 (const :format
"" quote
)
306 (string :tag
"+tag or -tag"))))
307 (list :tag
"Set daily/weekly entry types"
308 (const org-agenda-entry-types
)
309 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
314 (list :tag
"Standard skipping condition"
315 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
316 (const org-agenda-skip-function
)
318 (const :format
"" quote
)
321 :tag
"Skipping range"
322 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
323 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
324 (repeat :inline t
:tag
"Conditions for skipping"
326 :tag
"Condition type"
327 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
328 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
329 (list :tag
"TODO state is" :inline t
332 (const :tag
"any not-done state" 'todo
)
333 (const :tag
"any done state" 'done
)
334 (const :tag
"any state" 'any
)
335 (list :tag
"Keyword list"
336 (const :format
"" quote
)
337 (repeat (string :tag
"Keyword")))))
338 (list :tag
"TODO state is not" :inline t
341 (const :tag
"any not-done state" 'todo
)
342 (const :tag
"any done state" 'done
)
343 (const :tag
"any state" 'any
)
344 (list :tag
"Keyword list"
345 (const :format
"" quote
)
346 (repeat (string :tag
"Keyword")))))
347 (const :tag
"scheduled" 'scheduled
)
348 (const :tag
"not scheduled" 'notscheduled
)
349 (const :tag
"deadline" 'deadline
)
350 (const :tag
"no deadline" 'notdeadline
)
351 (const :tag
"timestamp" 'timestamp
)
352 (const :tag
"no timestamp" 'nottimestamp
))))))
353 (list :tag
"Non-standard skipping condition"
354 :value
(org-agenda-skip-function)
355 (const org-agenda-skip-function
)
356 (sexp :tag
"Function or form (quoted!)"))
357 (list :tag
"Any variable"
358 (variable :tag
"Variable")
359 (sexp :tag
"Value (sexp)"))))
360 "Selection of examples for agenda command settings.
361 This will be spliced into the custom type of
362 `org-agenda-custom-commands'.")
365 (defcustom org-agenda-custom-commands
'(("n" "Agenda and all TODO's"
366 ((agenda "") (alltodo))))
367 "Custom commands for the agenda.
368 These commands will be offered on the splash screen displayed by the
369 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
371 (key desc type match settings files)
373 key The key (one or more characters as a string) to be associated
375 desc A description of the command, when omitted or nil, a default
376 description is built using MATCH.
377 type The command type, any of the following symbols:
378 agenda The daily/weekly agenda.
379 todo Entries with a specific TODO keyword, in all agenda files.
380 search Entries containing search words entry or headline.
381 tags Tags/Property/TODO match in all agenda files.
382 tags-todo Tags/P/T match in all agenda files, TODO entries only.
383 todo-tree Sparse tree of specific TODO keyword in *current* file.
384 tags-tree Sparse tree with all tags matches in *current* file.
385 occur-tree Occur sparse tree for *current* file.
386 ... A user-defined function.
387 match What to search for:
388 - a single keyword for TODO keyword searches
389 - a tags match expression for tags searches
390 - a word search expression for text searches.
391 - a regular expression for occur searches
392 For all other commands, this should be the empty string.
393 settings A list of option settings, similar to that in a let form, so like
394 this: ((opt1 val1) (opt2 val2) ...). The values will be
395 evaluated at the moment of execution, so quote them when needed.
396 files A list of files file to write the produced agenda buffer to
397 with the command `org-store-agenda-views'.
398 If a file name ends in \".html\", an HTML version of the buffer
399 is written out. If it ends in \".ps\", a postscript version is
400 produced. Otherwise, only the plain text is written to the file.
402 You can also define a set of commands, to create a composite agenda buffer.
403 In this case, an entry looks like this:
405 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
409 desc A description string to be displayed in the dispatcher menu.
410 cmd An agenda command, similar to the above. However, tree commands
411 are not allowed, but instead you can get agenda and global todo list.
412 So valid commands for a set are:
413 (agenda \"\" settings)
414 (alltodo \"\" settings)
415 (stuck \"\" settings)
416 (todo \"match\" settings files)
417 (search \"match\" settings files)
418 (tags \"match\" settings files)
419 (tags-todo \"match\" settings files)
421 Each command can carry a list of options, and another set of options can be
422 given for the whole set of commands. Individual command options take
423 precedence over the general options.
425 When using several characters as key to a command, the first characters
426 are prefix commands. For the dispatcher to display useful information, you
427 should provide a description for the prefix, like
429 (setq org-agenda-custom-commands
430 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
431 (\"hl\" tags \"+HOME+Lisa\")
432 (\"hp\" tags \"+HOME+Peter\")
433 (\"hk\" tags \"+HOME+Kim\")))"
434 :group
'org-agenda-custom-commands
436 (choice :value
("x" "Describe command here" tags
"" nil
)
437 (list :tag
"Single command"
438 (string :tag
"Access Key(s) ")
439 (option (string :tag
"Description"))
441 (const :tag
"Agenda" agenda
)
442 (const :tag
"TODO list" alltodo
)
443 (const :tag
"Search words" search
)
444 (const :tag
"Stuck projects" stuck
)
445 (const :tag
"Tags/Property match (all agenda files)" tags
)
446 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
447 (const :tag
"TODO keyword search (all agenda files)" todo
)
448 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
449 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
450 (const :tag
"Occur tree (current buffer)" occur-tree
)
451 (sexp :tag
"Other, user-defined function"))
452 (string :tag
"Match (only for some commands)")
453 ,org-agenda-custom-commands-local-options
454 (option (repeat :tag
"Export" (file :tag
"Export to"))))
455 (list :tag
"Command series, all agenda files"
456 (string :tag
"Access Key(s)")
457 (string :tag
"Description ")
458 (repeat :tag
"Component"
461 (const :format
"" agenda
)
462 (const :tag
"" :format
"" "")
463 ,org-agenda-custom-commands-local-options
)
464 (list :tag
"TODO list (all keywords)"
465 (const :format
"" alltodo
)
466 (const :tag
"" :format
"" "")
467 ,org-agenda-custom-commands-local-options
)
468 (list :tag
"Search words"
469 (const :format
"" search
)
470 (string :tag
"Match")
471 ,org-agenda-custom-commands-local-options
)
472 (list :tag
"Stuck projects"
473 (const :format
"" stuck
)
474 (const :tag
"" :format
"" "")
475 ,org-agenda-custom-commands-local-options
)
476 (list :tag
"Tags search"
477 (const :format
"" tags
)
478 (string :tag
"Match")
479 ,org-agenda-custom-commands-local-options
)
480 (list :tag
"Tags search, TODO entries only"
481 (const :format
"" tags-todo
)
482 (string :tag
"Match")
483 ,org-agenda-custom-commands-local-options
)
484 (list :tag
"TODO keyword search"
485 (const :format
"" todo
)
486 (string :tag
"Match")
487 ,org-agenda-custom-commands-local-options
)
488 (list :tag
"Other, user-defined function"
489 (symbol :tag
"function")
490 (string :tag
"Match")
491 ,org-agenda-custom-commands-local-options
)))
493 (repeat :tag
"Settings for entire command set"
494 (list (variable :tag
"Any variable")
495 (sexp :tag
"Value")))
496 (option (repeat :tag
"Export" (file :tag
"Export to"))))
497 (cons :tag
"Prefix key documentation"
498 (string :tag
"Access Key(s)")
499 (string :tag
"Description ")))))
501 (defcustom org-agenda-query-register ?o
502 "The register holding the current query string.
503 The purpose of this is that if you construct a query string interactively,
504 you can then use it to define a custom command."
505 :group
'org-agenda-custom-commands
508 (defcustom org-stuck-projects
509 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
510 "How to identify stuck projects.
511 This is a list of four items:
512 1. A tags/todo/property matcher string that is used to identify a project.
513 See the manual for a description of tag and property searches.
514 The entire tree below a headline matched by this is considered one project.
515 2. A list of TODO keywords identifying non-stuck projects.
516 If the project subtree contains any headline with one of these todo
517 keywords, the project is considered to be not stuck. If you specify
518 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
519 3. A list of tags identifying non-stuck projects.
520 If the project subtree contains any headline with one of these tags,
521 the project is considered to be not stuck. If you specify \"*\" as
522 a tag, any tag will mark the project unstuck. Note that this is about
523 the explicit presence of a tag somewhere in the subtree, inherited
524 tags to not count here. If inherited tags make a project not stuck,
525 use \"-TAG\" in the tags part of the matcher under (1.) above.
526 4. An arbitrary regular expression matching non-stuck projects.
528 If the project turns out to be not stuck, search continues also in the
529 subtree to see if any of the subtasks have project status.
531 See also the variable `org-tags-match-list-sublevels' which applies
532 to projects matched by this search as well.
534 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
535 or `C-c a #' to produce the list."
536 :group
'org-agenda-custom-commands
538 (string :tag
"Tags/TODO match to identify a project")
539 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
540 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
541 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
543 (defcustom org-agenda-filter-effort-default-operator
"<"
544 "The default operator for effort estimate filtering.
545 If you select an effort estimate limit without first pressing an operator,
546 this one will be used."
547 :group
'org-agenda-custom-commands
548 :type
'(choice (const :tag
"less or equal" "<")
549 (const :tag
"greater or equal"">")
550 (const :tag
"equal" "=")))
552 (defgroup org-agenda-skip nil
553 "Options concerning skipping parts of agenda files."
554 :tag
"Org Agenda Skip"
557 (defcustom org-agenda-skip-function-global nil
558 "Function to be called at each match during agenda construction.
559 If this function returns nil, the current match should not be skipped.
560 If the function decided to skip an agenda match, is must return the
561 buffer position from which the search should be continued.
562 This may also be a Lisp form, which will be evaluated.
564 This variable will be applied to every agenda match, including
565 tags/property searches and TODO lists. So try to make the test function
566 do its checking as efficiently as possible. To implement a skipping
567 condition just for specific agenda commands, use the variable
568 `org-agenda-skip-function' which can be set in the options section
569 of custom agenda commands."
570 :group
'org-agenda-skip
573 (defgroup org-agenda-daily
/weekly nil
574 "Options concerning the daily/weekly agenda."
575 :tag
"Org Agenda Daily/Weekly"
577 (defgroup org-agenda-todo-list nil
578 "Options concerning the global todo list agenda view."
579 :tag
"Org Agenda Todo List"
581 (defgroup org-agenda-match-view nil
582 "Options concerning the general tags/property/todo match agenda view."
583 :tag
"Org Agenda Match View"
585 (defgroup org-agenda-search-view nil
586 "Options concerning the general tags/property/todo match agenda view."
587 :tag
"Org Agenda Match View"
590 (defvar org-agenda-archives-mode nil
591 "Non-nil means the agenda will include archived items.
592 If this is the symbol `trees', trees in the selected agenda scope
593 that are marked with the ARCHIVE tag will be included anyway. When this is
594 t, also all archive files associated with the current selection of agenda
595 files will be included.")
597 (defcustom org-agenda-skip-comment-trees t
598 "Non-nil means skip trees that start with the COMMENT keyword.
599 When nil, these trees are also scanned by agenda commands."
600 :group
'org-agenda-skip
603 (defcustom org-agenda-todo-list-sublevels t
604 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
605 When nil, the sublevels of a TODO entry are not checked, resulting in
606 potentially much shorter TODO lists."
607 :group
'org-agenda-skip
608 :group
'org-agenda-todo-list
611 (defcustom org-agenda-todo-ignore-with-date nil
612 "Non-nil means don't show entries with a date in the global todo list.
613 You can use this if you prefer to mark mere appointments with a TODO keyword,
614 but don't want them to show up in the TODO list.
615 When this is set, it also covers deadlines and scheduled items, the settings
616 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
618 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
619 :group
'org-agenda-skip
620 :group
'org-agenda-todo-list
623 (defcustom org-agenda-todo-ignore-timestamp nil
624 "Non-nil means don't show entries with a timestamp.
625 This applies when creating the global todo list.
628 past Don't show entries for today or in the past.
630 future Don't show entries with a timestamp in the future.
631 The idea behind this is that if it has a future
632 timestamp, you don't want to think about it until the
635 all Don't show any entries with a timestamp in the global todo list.
636 The idea behind this is that by setting a timestamp, you
637 have already \"taken care\" of this item.
639 This variable can also have an integer as a value. If positive (N),
640 todos with a timestamp N or more days in the future will be ignored. If
641 negative (-N), todos with a timestamp N or more days in the past will be
642 ignored. If 0, todos with a timestamp either today or in the future will
643 be ignored. For example, a value of -1 will exclude todos with a
644 timestamp in the past (yesterday or earlier), while a value of 7 will
645 exclude todos with a timestamp a week or more in the future.
647 See also `org-agenda-todo-ignore-with-date'.
648 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
649 to make his option also apply to the tags-todo list."
650 :group
'org-agenda-skip
651 :group
'org-agenda-todo-list
654 (const :tag
"Ignore future timestamp todos" future
)
655 (const :tag
"Ignore past or present timestamp todos" past
)
656 (const :tag
"Ignore all timestamp todos" all
)
657 (const :tag
"Show timestamp todos" nil
)
658 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
660 (defcustom org-agenda-todo-ignore-scheduled nil
661 "Non-nil means, ignore some scheduled TODO items when making TODO list.
662 This applies when creating the global todo list.
665 past Don't show entries scheduled today or in the past.
667 future Don't show entries scheduled in the future.
668 The idea behind this is that by scheduling it, you don't want to
669 think about it until the scheduled date.
671 all Don't show any scheduled entries in the global todo list.
672 The idea behind this is that by scheduling it, you have already
673 \"taken care\" of this item.
675 t Same as `all', for backward compatibility.
677 This variable can also have an integer as a value. See
678 `org-agenda-todo-ignore-timestamp' for more details.
680 See also `org-agenda-todo-ignore-with-date'.
681 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
682 to make his option also apply to the tags-todo list."
683 :group
'org-agenda-skip
684 :group
'org-agenda-todo-list
686 (const :tag
"Ignore future-scheduled todos" future
)
687 (const :tag
"Ignore past- or present-scheduled todos" past
)
688 (const :tag
"Ignore all scheduled todos" all
)
689 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
690 (const :tag
"Show scheduled todos" nil
)
691 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
693 (defcustom org-agenda-todo-ignore-deadlines nil
694 "Non-nil means ignore some deadlined TODO items when making TODO list.
695 There are different motivations for using different values, please think
696 carefully when configuring this variable.
698 This applies when creating the global todo list.
701 near Don't show near deadline entries. A deadline is near when it is
702 closer than `org-deadline-warning-days' days. The idea behind this
703 is that such items will appear in the agenda anyway.
705 far Don't show TODO entries where a deadline has been defined, but
706 the deadline is not near. This is useful if you don't want to
707 use the todo list to figure out what to do now.
709 past Don't show entries with a deadline timestamp for today or in the past.
711 future Don't show entries with a deadline timestamp in the future, not even
712 when they become `near' ones. Use it with caution.
714 all Ignore all TODO entries that do have a deadline.
716 t Same as `near', for backward compatibility.
718 This variable can also have an integer as a value. See
719 `org-agenda-todo-ignore-timestamp' for more details.
721 See also `org-agenda-todo-ignore-with-date'.
722 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
723 to make his option also apply to the tags-todo list."
724 :group
'org-agenda-skip
725 :group
'org-agenda-todo-list
727 (const :tag
"Ignore near deadlines" near
)
728 (const :tag
"Ignore near deadlines (compatibility)" t
)
729 (const :tag
"Ignore far deadlines" far
)
730 (const :tag
"Ignore all TODOs with a deadlines" all
)
731 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
732 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
734 (defcustom org-agenda-tags-todo-honor-ignore-options nil
735 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
737 `org-agenda-todo-ignore-with-date',
738 `org-agenda-todo-ignore-timestamp',
739 `org-agenda-todo-ignore-scheduled',
740 `org-agenda-todo-ignore-deadlines'
741 make the global TODO list skip entries that have time stamps of certain
742 kinds. If this option is set, the same options will also apply for the
743 tags-todo search, which is the general tags/property matcher
744 restricted to unfinished TODO entries only."
745 :group
'org-agenda-skip
746 :group
'org-agenda-todo-list
747 :group
'org-agenda-match-view
750 (defcustom org-agenda-skip-scheduled-if-done nil
751 "Non-nil means don't show scheduled items in agenda when they are done.
752 This is relevant for the daily/weekly agenda, not for the TODO list. And
753 it applies only to the actual date of the scheduling. Warnings about
754 an item with a past scheduling dates are always turned off when the item
756 :group
'org-agenda-skip
757 :group
'org-agenda-daily
/weekly
760 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
761 "Non-nil means skip scheduling line if same entry shows because of deadline.
762 In the agenda of today, an entry can show up multiple times because
763 it is both scheduled and has a nearby deadline, and maybe a plain time
765 When this variable is t, then only the deadline is shown and the fact that
766 the entry is scheduled today or was scheduled previously is not shown.
767 When this variable is nil, the entry will be shown several times. When
768 the variable is the symbol `not-today', then skip scheduled previously,
769 but not scheduled today."
770 :group
'org-agenda-skip
771 :group
'org-agenda-daily
/weekly
773 (const :tag
"Never" nil
)
774 (const :tag
"Always" t
)
775 (const :tag
"Not when scheduled today" not-today
)))
777 (defcustom org-agenda-skip-deadline-if-done nil
778 "Non-nil means don't show deadlines when the corresponding item is done.
779 When nil, the deadline is still shown and should give you a happy feeling.
780 This is relevant for the daily/weekly agenda. And it applied only to the
781 actually date of the deadline. Warnings about approaching and past-due
782 deadlines are always turned off when the item is DONE."
783 :group
'org-agenda-skip
784 :group
'org-agenda-daily
/weekly
787 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
788 "Non-nil means skip deadline prewarning when entry is also scheduled.
789 This will apply on all days where a prewarning for the deadline would
790 be shown, but not at the day when the entry is actually due. On that day,
791 the deadline will be shown anyway.
792 This variable may be set to nil, t, or a number which will then give
793 the number of days before the actual deadline when the prewarnings
795 This can be used in a workflow where the first showing of the deadline will
796 trigger you to schedule it, and then you don't want to be reminded of it
797 because you will take care of it on the day when scheduled."
798 :group
'org-agenda-skip
799 :group
'org-agenda-daily
/weekly
802 (const :tag
"Alwas show prewarning" nil
)
803 (const :tag
"Remove prewarning if entry is scheduled" t
)
804 (integer :tag
"Restart prewarning N days before deadline")))
806 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
807 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
808 When non-nil, after the search for timestamps has matched once in an
809 entry, the rest of the entry will not be searched."
810 :group
'org-agenda-skip
813 (defcustom org-agenda-skip-timestamp-if-done nil
814 "Non-nil means don't select item by timestamp or -range if it is DONE."
815 :group
'org-agenda-skip
816 :group
'org-agenda-daily
/weekly
819 (defcustom org-agenda-dim-blocked-tasks t
820 "Non-nil means dim blocked tasks in the agenda display.
821 This causes some overhead during agenda construction, but if you
822 have turned on `org-enforce-todo-dependencies',
823 `org-enforce-todo-checkbox-dependencies', or any other blocking
824 mechanism, this will create useful feedback in the agenda.
826 Instead of t, this variable can also have the value `invisible'.
827 Then blocked tasks will be invisible and only become visible when
828 they become unblocked. An exemption to this behavior is when a task is
829 blocked because of unchecked checkboxes below it. Since checkboxes do
830 not show up in the agenda views, making this task invisible you remove any
831 trace from agenda views that there is something to do. Therefore, a task
832 that is blocked because of checkboxes will never be made invisible, it
833 will only be dimmed."
834 :group
'org-agenda-daily
/weekly
835 :group
'org-agenda-todo-list
837 (const :tag
"Do not dim" nil
)
838 (const :tag
"Dim to a gray face" t
)
839 (const :tag
"Make invisible" invisible
)))
841 (defcustom org-timeline-show-empty-dates
3
842 "Non-nil means `org-timeline' also shows dates without an entry.
843 When nil, only the days which actually have entries are shown.
844 When t, all days between the first and the last date are shown.
845 When an integer, show also empty dates, but if there is a gap of more than
846 N days, just insert a special line indicating the size of the gap."
847 :group
'org-agenda-skip
849 (const :tag
"None" nil
)
851 (integer :tag
"at most")))
853 (defgroup org-agenda-startup nil
854 "Options concerning initial settings in the Agenda in Org Mode."
855 :tag
"Org Agenda Startup"
858 (defcustom org-agenda-menu-show-matcher t
859 "Non-nil means show the match string in the agenda dispatcher menu.
860 When nil, the matcher string is not shown, but is put into the help-echo
861 property so than moving the mouse over the command shows it.
862 Setting it to nil is good if matcher strings are very long and/or if
863 you want to use two-column display (see `org-agenda-menu-two-column')."
868 (defcustom org-agenda-menu-two-column nil
869 "Non-nil means, use two columns to show custom commands in the dispatcher.
870 If you use this, you probably want to set `org-agenda-menu-show-matcher'
876 (defcustom org-finalize-agenda-hook nil
877 "Hook run just before displaying an agenda buffer."
878 :group
'org-agenda-startup
881 (defcustom org-agenda-mouse-1-follows-link nil
882 "Non-nil means mouse-1 on a link will follow the link in the agenda.
883 A longer mouse click will still set point. Does not work on XEmacs.
884 Needs to be set before org.el is loaded."
885 :group
'org-agenda-startup
888 (defcustom org-agenda-start-with-follow-mode nil
889 "The initial value of follow mode in a newly created agenda window."
890 :group
'org-agenda-startup
893 (defcustom org-agenda-follow-indirect nil
894 "Non-nil means `org-agenda-follow-mode' displays only the
895 current item's tree, in an indirect buffer."
900 (defcustom org-agenda-show-outline-path t
901 "Non-nil means show outline path in echo area after line motion."
902 :group
'org-agenda-startup
905 (defcustom org-agenda-start-with-entry-text-mode nil
906 "The initial value of entry-text-mode in a newly created agenda window."
907 :group
'org-agenda-startup
910 (defcustom org-agenda-entry-text-maxlines
5
911 "Number of text lines to be added when `E' is pressed in the agenda.
913 Note that this variable only used during agenda display. Add add entry text
914 when exporting the agenda, configure the variable
915 `org-agenda-add-entry-ext-maxlines'."
919 (defcustom org-agenda-entry-text-exclude-regexps nil
920 "List of regular expressions to clean up entry text.
921 The complete matches of all regular expressions in this list will be
922 removed from entry text before it is shown in the agenda."
924 :type
'(repeat (regexp)))
926 (defvar org-agenda-entry-text-cleanup-hook nil
927 "Hook that is run after basic cleanup of entry text to be shown in agenda.
928 This cleanup is done in a temporary buffer, so the function may inspect and
929 change the entire buffer.
930 Some default stuff like drawers and scheduling/deadline dates will already
931 have been removed when this is called, as will any matches for regular
932 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
934 (defvar org-agenda-include-inactive-timestamps nil
935 "Non-nil means include inactive time stamps in agenda and timeline.
936 Dynamically scoped.")
938 (defgroup org-agenda-windows nil
939 "Options concerning the windows used by the Agenda in Org Mode."
940 :tag
"Org Agenda Windows"
943 (defcustom org-agenda-window-setup
'reorganize-frame
944 "How the agenda buffer should be displayed.
945 Possible values for this option are:
947 current-window Show agenda in the current window, keeping all other windows.
948 other-window Use `switch-to-buffer-other-window' to display agenda.
949 reorganize-frame Show only two windows on the current frame, the current
950 window and the agenda.
951 other-frame Use `switch-to-buffer-other-frame' to display agenda.
952 Also, when exiting the agenda, kill that frame.
953 See also the variable `org-agenda-restore-windows-after-quit'."
954 :group
'org-agenda-windows
956 (const current-window
)
959 (const reorganize-frame
)))
961 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
962 "The min and max height of the agenda window as a fraction of frame height.
963 The value of the variable is a cons cell with two numbers between 0 and 1.
964 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
965 :group
'org-agenda-windows
966 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
968 (defcustom org-agenda-restore-windows-after-quit nil
969 "Non-nil means restore window configuration upon exiting agenda.
970 Before the window configuration is changed for displaying the agenda,
971 the current status is recorded. When the agenda is exited with
972 `q' or `x' and this option is set, the old state is restored. If
973 `org-agenda-window-setup' is `other-frame', the value of this
974 option will be ignored."
975 :group
'org-agenda-windows
978 (defcustom org-agenda-ndays nil
979 "Number of days to include in overview display.
981 Obsolete, see `org-agenda-span'."
982 :group
'org-agenda-daily
/weekly
985 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
987 (defcustom org-agenda-span
'week
988 "Number of days to include in overview display.
989 Can be day, week, month, year, or any number of days.
990 Custom commands can set this variable in the options section."
991 :group
'org-agenda-daily
/weekly
992 :type
'(choice (const :tag
"Day" day
)
993 (const :tag
"Week" week
)
994 (const :tag
"Month" month
)
995 (const :tag
"Year" year
)
996 (integer :tag
"Custom")))
998 (defcustom org-agenda-start-on-weekday
1
999 "Non-nil means start the overview always on the specified weekday.
1000 0 denotes Sunday, 1 denotes Monday etc.
1001 When nil, always start on the current day.
1002 Custom commands can set this variable in the options section."
1003 :group
'org-agenda-daily
/weekly
1004 :type
'(choice (const :tag
"Today" nil
)
1005 (integer :tag
"Weekday No.")))
1007 (defcustom org-agenda-show-all-dates t
1008 "Non-nil means `org-agenda' shows every day in the selected range.
1009 When nil, only the days which actually have entries are shown."
1010 :group
'org-agenda-daily
/weekly
1013 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1014 "Format string for displaying dates in the agenda.
1015 Used by the daily/weekly agenda and by the timeline. This should be
1016 a format string understood by `format-time-string', or a function returning
1017 the formatted date as a string. The function must take a single argument,
1018 a calendar-style date list like (month day year)."
1019 :group
'org-agenda-daily
/weekly
1021 (string :tag
"Format string")
1022 (function :tag
"Function")))
1024 (defun org-agenda-format-date-aligned (date)
1025 "Format a date string for display in the daily/weekly agenda, or timeline.
1026 This function makes sure that dates are aligned for easy reading."
1028 (let* ((dayname (calendar-day-name date
))
1030 (day-of-week (calendar-day-of-week date
))
1032 (monthname (calendar-month-name month
))
1034 (iso-week (org-days-to-iso-week
1035 (calendar-absolute-from-gregorian date
)))
1036 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1038 ((and (= month
12) (<= iso-week
1))
1041 (weekstring (if (= day-of-week
1)
1042 (format " W%02d" iso-week
)
1044 (format "%-10s %2d %s %4d%s"
1045 dayname day monthname year weekstring
)))
1047 (defcustom org-agenda-time-leading-zero nil
1048 "Non-nil means use leading zero for military times in agenda.
1049 For example, 9:30am would become 09:30 rather than 9:30."
1050 :group
'org-agenda-daily
/weekly
1054 (defcustom org-agenda-timegrid-use-ampm nil
1055 "When set, show AM/PM style timestamps on the timegrid."
1060 (defun org-agenda-time-of-day-to-ampm (time)
1061 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1062 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1063 (minute (substring time -
2))
1066 ((equal hour-number
12)
1070 (setq hour-number
(- hour-number
12))))
1072 (if org-agenda-time-leading-zero
1073 (format "%02d" hour-number
)
1074 (format "%02s" (number-to-string hour-number
)))
1077 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1078 "Conditionally convert TIME to AM/PM format
1079 based on `org-agenda-timegrid-use-ampm'"
1080 (if org-agenda-timegrid-use-ampm
1081 (org-agenda-time-of-day-to-ampm time
)
1084 (defcustom org-agenda-weekend-days
'(6 0)
1085 "Which days are weekend?
1086 These days get the special face `org-agenda-date-weekend' in the agenda
1087 and timeline buffers."
1088 :group
'org-agenda-daily
/weekly
1089 :type
'(set :greedy t
1090 (const :tag
"Monday" 1)
1091 (const :tag
"Tuesday" 2)
1092 (const :tag
"Wednesday" 3)
1093 (const :tag
"Thursday" 4)
1094 (const :tag
"Friday" 5)
1095 (const :tag
"Saturday" 6)
1096 (const :tag
"Sunday" 0)))
1098 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1099 "Non-nil means jump to today when moving a past date forward in time.
1100 When using S-right in the agenda to move a a date forward, and the date
1101 stamp currently points to the past, the first key press will move it
1102 to today. WHen nil, just move one day forward even if the date stays
1104 :group
'org-agenda-daily
/weekly
1108 (defcustom org-agenda-include-diary nil
1109 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1110 Custom commands can set this variable in the options section."
1111 :group
'org-agenda-daily
/weekly
1114 (defcustom org-agenda-include-deadlines t
1115 "If non-nil, include entries within their deadline warning period.
1116 Custom commands can set this variable in the options section."
1117 :group
'org-agenda-daily
/weekly
1121 (defcustom org-agenda-repeating-timestamp-show-all t
1122 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1123 When set to a list of strings, only show occurrences of repeating
1124 stamps for these TODO keywords. When nil, only one occurrence is
1125 shown, either today or the nearest into the future."
1126 :group
'org-agenda-daily
/weekly
1128 (const :tag
"Show repeating stamps" t
)
1129 (repeat :tag
"Show repeating stamps for these TODO keywords"
1130 (string :tag
"TODO Keyword"))
1131 (const :tag
"Don't show repeating stamps" nil
)))
1133 (defcustom org-scheduled-past-days
10000
1134 "No. of days to continue listing scheduled items that are not marked DONE.
1135 When an item is scheduled on a date, it shows up in the agenda on this
1136 day and will be listed until it is marked done for the number of days
1138 :group
'org-agenda-daily
/weekly
1141 (defcustom org-agenda-log-mode-items
'(closed clock
)
1142 "List of items that should be shown in agenda log mode.
1143 This list may contain the following symbols:
1145 closed Show entries that have been closed on that day.
1146 clock Show entries that have received clocked time on that day.
1147 state Show all logged state changes.
1148 Note that instead of changing this variable, you can also press `C-u l' in
1149 the agenda to display all available LOG items temporarily."
1150 :group
'org-agenda-daily
/weekly
1151 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1153 (defcustom org-agenda-clock-consistency-checks
1154 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1155 :gap-ok-around
("4:00")
1156 :default-face
((:background
"DarkRed") (:foreground
"white"))
1157 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1158 :long-face nil
:short-face nil
)
1159 "This is a property list, with the following keys:
1161 :max-duration Mark clocking chunks that are longer than this time.
1162 This is a time string like \"HH:MM\", or the number
1163 of minutes as an integer.
1165 :min-duration Mark clocking chunks that are shorter that this.
1166 This is a time string like \"HH:MM\", or the number
1167 of minutes as an integer.
1169 :max-gap Mark gaps between clocking chunks that are longer than
1170 this duration. A number of minutes, or a string
1173 :gap-ok-around List of times during the day which are usually not working
1174 times. When a gap is detected, but the gap contains any
1175 of these times, the gap is *not* reported. For example,
1176 if this is (\"4:00\" \"13:00\") then gaps that contain
1177 4:00 in the morning (i.e. the night) and 13:00
1178 (i.e. a typical lunch time) do not cause a warning.
1179 You should have at least one time during the night in this
1180 list, or otherwise the first task each morning will trigger
1181 a warning because it follows a long gap.
1183 Furthermore, the following properties can be used to define faces for
1186 :default-face the default face, if the specific face is undefined
1187 :overlap-face face for overlapping clocks
1188 :gap-face face for gaps between clocks
1189 :no-end-time-face face for incomplete clocks
1190 :long-face face for clock intervals that are too long
1191 :short-face face for clock intervals that are too short"
1192 :group
'org-agenda-daily
/weekly
1197 (defcustom org-agenda-log-mode-add-notes t
1198 "Non-nil means add first line of notes to log entries in agenda views.
1199 If a log item like a state change or a clock entry is associated with
1200 notes, the first line of these notes will be added to the entry in the
1202 :group
'org-agenda-daily
/weekly
1205 (defcustom org-agenda-start-with-log-mode nil
1206 "The initial value of log-mode in a newly created agenda window."
1207 :group
'org-agenda-startup
1208 :group
'org-agenda-daily
/weekly
1211 (defcustom org-agenda-start-with-clockreport-mode nil
1212 "The initial value of clockreport-mode in a newly created agenda window."
1213 :group
'org-agenda-startup
1214 :group
'org-agenda-daily
/weekly
1217 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1218 "Property list with parameters for the clocktable in clockreport mode.
1219 This is the display mode that shows a clock table in the daily/weekly
1220 agenda, the properties for this dynamic block can be set here.
1221 The usual clocktable parameters are allowed here, but you cannot set
1222 the properties :name, :tstart, :tend, :block, and :scope - these will
1223 be overwritten to make sure the content accurately reflects the
1224 current display in the agenda."
1225 :group
'org-agenda-daily
/weekly
1228 (defcustom org-agenda-search-view-always-boolean nil
1229 "Non-nil means the search string is interpreted as individual parts.
1231 The search string for search view can either be interpreted as a phrase,
1232 or as a list of snippets that define a boolean search for a number of
1235 When this is non-nil, the string will be split on whitespace, and each
1236 snippet will be searched individually, and all must match in order to
1237 select an entry. A snippet is then a single string of non-white
1238 characters, or a string in double quotes, or a regexp in {} braces.
1239 If a snippet is preceded by \"-\", the snippet must *not* match.
1240 \"+\" is syntactic sugar for positive selection. Each snippet may
1241 be found as a full word or a partial word, but see the variable
1242 `org-agenda-search-view-force-full-words'.
1244 When this is nil, search will look for the entire search phrase as one,
1245 with each space character matching any amount of whitespace, including
1248 Even when this is nil, you can still switch to Boolean search dynamically
1249 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1250 is a regexp marked with braces like \"{abc}\", this will also switch to
1252 :group
'org-agenda-search-view
1256 (if (fboundp 'defvaralias
)
1257 (defvaralias 'org-agenda-search-view-search-words-only
1258 'org-agenda-search-view-always-boolean
))
1260 (defcustom org-agenda-search-view-force-full-words nil
1261 "Non-nil means, search words must be matches as complete words.
1262 When nil, they may also match part of a word."
1263 :group
'org-agenda-search-view
1267 (defgroup org-agenda-time-grid nil
1268 "Options concerning the time grid in the Org-mode Agenda."
1269 :tag
"Org Agenda Time Grid"
1272 (defcustom org-agenda-search-headline-for-time t
1273 "Non-nil means search headline for a time-of-day.
1274 If the headline contains a time-of-day in one format or another, it will
1275 be used to sort the entry into the time sequence of items for a day.
1276 Some people have time stamps in the headline that refer to the creation
1277 time or so, and then this produces an unwanted side effect. If this is
1278 the case for your, use this variable to turn off searching the headline
1280 :group
'org-agenda-time-grid
1283 (defcustom org-agenda-use-time-grid t
1284 "Non-nil means show a time grid in the agenda schedule.
1285 A time grid is a set of lines for specific times (like every two hours between
1286 8:00 and 20:00). The items scheduled for a day at specific times are
1287 sorted in between these lines.
1288 For details about when the grid will be shown, and what it will look like, see
1289 the variable `org-agenda-time-grid'."
1290 :group
'org-agenda-time-grid
1293 (defcustom org-agenda-time-grid
1294 '((daily today require-timed
)
1296 (800 1000 1200 1400 1600 1800 2000))
1298 "The settings for time grid for agenda display.
1299 This is a list of three items. The first item is again a list. It contains
1300 symbols specifying conditions when the grid should be displayed:
1302 daily if the agenda shows a single day
1303 weekly if the agenda shows an entire week
1304 today show grid on current date, independent of daily/weekly display
1305 require-timed show grid only if at least one item has a time specification
1307 The second item is a string which will be placed behind the grid time.
1309 The third item is a list of integers, indicating the times that should have
1311 :group
'org-agenda-time-grid
1314 (set :greedy t
:tag
"Grid Display Options"
1315 (const :tag
"Show grid in single day agenda display" daily
)
1316 (const :tag
"Show grid in weekly agenda display" weekly
)
1317 (const :tag
"Always show grid for today" today
)
1318 (const :tag
"Show grid only if any timed entries are present"
1320 (const :tag
"Skip grid times already present in an entry"
1322 (string :tag
"Grid String")
1323 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1325 (defcustom org-agenda-show-current-time-in-grid t
1326 "Non-nil means show the current time in the time grid."
1327 :group
'org-agenda-time-grid
1331 (defcustom org-agenda-current-time-string
1332 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1333 "The string for the current time marker in the agenda."
1334 :group
'org-agenda-time-grid
1338 (defgroup org-agenda-sorting nil
1339 "Options concerning sorting in the Org-mode Agenda."
1340 :tag
"Org Agenda Sorting"
1343 (defcustom org-agenda-sorting-strategy
1344 '((agenda habit-down time-up priority-down category-keep
)
1345 (todo priority-down category-keep
)
1346 (tags priority-down category-keep
)
1347 (search category-keep
))
1348 "Sorting structure for the agenda items of a single day.
1349 This is a list of symbols which will be used in sequence to determine
1350 if an entry should be listed before another entry. The following
1351 symbols are recognized:
1353 time-up Put entries with time-of-day indications first, early first
1354 time-down Put entries with time-of-day indications first, late first
1355 category-keep Keep the default order of categories, corresponding to the
1356 sequence in `org-agenda-files'.
1357 category-up Sort alphabetically by category, A-Z.
1358 category-down Sort alphabetically by category, Z-A.
1359 tag-up Sort alphabetically by last tag, A-Z.
1360 tag-down Sort alphabetically by last tag, Z-A.
1361 priority-up Sort numerically by priority, high priority last.
1362 priority-down Sort numerically by priority, high priority first.
1363 todo-state-up Sort by todo state, tasks that are done last.
1364 todo-state-down Sort by todo state, tasks that are done first.
1365 effort-up Sort numerically by estimated effort, high effort last.
1366 effort-down Sort numerically by estimated effort, high effort first.
1367 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1368 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1369 habit-up Put entries that are habits first
1370 habit-down Put entries that are habits last
1371 alpha-up Sort headlines alphabetically
1372 alpha-down Sort headlines alphabetically, reversed
1374 The different possibilities will be tried in sequence, and testing stops
1375 if one comparison returns a \"not-equal\". For example, the default
1376 '(time-up category-keep priority-down)
1377 means: Pull out all entries having a specified time of day and sort them,
1378 in order to make a time schedule for the current day the first thing in the
1379 agenda listing for the day. Of the entries without a time indication, keep
1380 the grouped in categories, don't sort the categories, but keep them in
1381 the sequence given in `org-agenda-files'. Within each category sort by
1384 Leaving out `category-keep' would mean that items will be sorted across
1385 categories by priority.
1387 Instead of a single list, this can also be a set of list for specific
1388 contents, with a context symbol in the car of the list, any of
1389 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1391 Custom commands can bind this variable in the options section."
1392 :group
'org-agenda-sorting
1394 (repeat :tag
"General" ,org-sorting-choice
)
1395 (list :tag
"Individually"
1396 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1397 (repeat ,org-sorting-choice
))
1398 (cons (const :tag
"Strategy for TODO lists" todo
)
1399 (repeat ,org-sorting-choice
))
1400 (cons (const :tag
"Strategy for Tags matches" tags
)
1401 (repeat ,org-sorting-choice
))
1402 (cons (const :tag
"Strategy for search matches" search
)
1403 (repeat ,org-sorting-choice
)))))
1405 (defcustom org-agenda-cmp-user-defined nil
1406 "A function to define the comparison `user-defined'.
1407 This function must receive two arguments, agenda entry a and b.
1408 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1409 the user comparison, return nil.
1410 When this is defined, you can make `user-defined-up' and `user-defined-down'
1411 part of an agenda sorting strategy."
1412 :group
'org-agenda-sorting
1415 (defcustom org-sort-agenda-notime-is-late t
1416 "Non-nil means items without time are considered late.
1417 This is only relevant for sorting. When t, items which have no explicit
1418 time like 15:30 will be considered as 99:01, i.e. later than any items which
1419 do have a time. When nil, the default time is before 0:00. You can use this
1420 option to decide if the schedule for today should come before or after timeless
1422 :group
'org-agenda-sorting
1425 (defcustom org-sort-agenda-noeffort-is-high t
1426 "Non-nil means items without effort estimate are sorted as high effort.
1427 This also applies when filtering an agenda view with respect to the
1428 < or > effort operator. Then, tasks with no effort defined will be treated
1429 as tasks with high effort.
1430 When nil, such items are sorted as 0 minutes effort."
1431 :group
'org-agenda-sorting
1434 (defgroup org-agenda-line-format nil
1435 "Options concerning the entry prefix in the Org-mode agenda display."
1436 :tag
"Org Agenda Line Format"
1439 (defcustom org-agenda-prefix-format
1440 '((agenda .
" %i %-12:c%?-12t% s")
1442 (todo .
" %i %-12:c")
1443 (tags .
" %i %-12:c")
1444 (search .
" %i %-12:c"))
1445 "Format specifications for the prefix of items in the agenda views.
1446 An alist with five entries, each for the different agenda types. The
1447 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1448 The values are format strings.
1450 This format works similar to a printf format, with the following meaning:
1452 %c the category of the item, \"Diary\" for entries from the diary,
1453 or as given by the CATEGORY keyword or derived from the file name
1454 %e the effort required by the item
1455 %i the icon category of the item, see `org-agenda-category-icon-alist'
1456 %T the last tag of the item (ignore inherited tags, which come first)
1457 %t the HH:MM time-of-day specification if one applies to the entry
1458 %s Scheduling/Deadline information, a short string
1459 %(expression) Eval EXPRESSION and replace the control string
1462 All specifiers work basically like the standard `%s' of printf, but may
1463 contain two additional characters: a question mark just after the `%'
1464 and a whitespace/punctuation character just before the final letter.
1466 If the first character after `%' is a question mark, the entire field
1467 will only be included if the corresponding value applies to the current
1468 entry. This is useful for fields which should have fixed width when
1469 present, but zero width when absent. For example, \"%?-12t\" will
1470 result in a 12 character time field if a time of the day is specified,
1471 but will completely disappear in entries which do not contain a time.
1473 If there is punctuation or whitespace character just before the final
1474 format letter, this character will be appended to the field value if
1475 the value is not empty. For example, the format \"%-12:c\" leads to
1476 \"Diary: \" if the category is \"Diary\". If the category were be
1477 empty, no additional colon would be inserted.
1479 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1482 - Indent the line with two space characters
1483 - Give the category a 12 chars wide field, padded with whitespace on
1484 the right (because of `-'). Append a colon if there is a category
1486 - If there is a time-of-day, put it into a 12 chars wide field. If no
1487 time, don't put in an empty field, just skip it (because of '?').
1488 - Finally, put the scheduling information.
1490 See also the variables `org-agenda-remove-times-when-in-prefix' and
1491 `org-agenda-remove-tags'.
1493 Custom commands can set this variable in the options section."
1495 (string :tag
"General format")
1496 (list :greedy t
:tag
"View dependent"
1497 (cons (const agenda
) (string :tag
"Format"))
1498 (cons (const timeline
) (string :tag
"Format"))
1499 (cons (const todo
) (string :tag
"Format"))
1500 (cons (const tags
) (string :tag
"Format"))
1501 (cons (const search
) (string :tag
"Format"))))
1502 :group
'org-agenda-line-format
)
1504 (defvar org-prefix-format-compiled nil
1505 "The compiled prefix format and associated variables.
1506 This is a list where first element is a list of variable bindings, and second
1507 element is the compiled format expression. See the variable
1508 `org-agenda-prefix-format'.")
1510 (defcustom org-agenda-todo-keyword-format
"%-1s"
1511 "Format for the TODO keyword in agenda lines.
1512 Set this to something like \"%-12s\" if you want all TODO keywords
1513 to occupy a fixed space in the agenda display."
1514 :group
'org-agenda-line-format
1517 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1518 "Text preceding timerange entries in the agenda view.
1519 This is a list with two strings. The first applies when the range
1520 is entirely on one day. The second applies if the range spans several days.
1521 The strings may have two \"%d\" format specifiers which will be filled
1522 with the sequence number of the days, and the total number of days in the
1523 range, respectively."
1524 :group
'org-agenda-line-format
1526 (string :tag
"Deadline today ")
1527 (choice :tag
"Deadline relative"
1528 (string :tag
"Format string")
1531 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1532 "Text preceding scheduled items in the agenda view.
1533 This is a list with two strings. The first applies when the item is
1534 scheduled on the current day. The second applies when it has been scheduled
1535 previously, it may contain a %d indicating that this is the nth time that
1536 this item is scheduled, due to automatic rescheduling of unfinished items
1537 for the following day. So this number is one larger than the number of days
1538 that passed since this item was scheduled first."
1539 :group
'org-agenda-line-format
1541 (string :tag
"Scheduled today ")
1542 (string :tag
"Scheduled previously")))
1544 (defcustom org-agenda-inactive-leader
"["
1545 "Text preceding item pulled into the agenda by inactive time stamps.
1546 These entries are added to the agenda when pressing \"[\"."
1547 :group
'org-agenda-line-format
1550 (string :tag
"Scheduled today ")
1551 (string :tag
"Scheduled previously")))
1553 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1554 "Text preceding deadline items in the agenda view.
1555 This is a list with two strings. The first applies when the item has its
1556 deadline on the current day. The second applies when it is in the past or
1557 in the future, it may contain %d to capture how many days away the deadline
1559 :group
'org-agenda-line-format
1561 (string :tag
"Deadline today ")
1562 (choice :tag
"Deadline relative"
1563 (string :tag
"Format string")
1566 (defcustom org-agenda-remove-times-when-in-prefix t
1567 "Non-nil means remove duplicate time specifications in agenda items.
1568 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1569 time-of-day specification in a headline or diary entry is extracted and
1570 placed into the prefix. If this option is non-nil, the original specification
1571 \(a timestamp or -range, or just a plain time(range) specification like
1572 11:30-4pm) will be removed for agenda display. This makes the agenda less
1574 The option can be t or nil. It may also be the symbol `beg', indicating
1575 that the time should only be removed when it is located at the beginning of
1576 the headline/diary entry."
1577 :group
'org-agenda-line-format
1579 (const :tag
"Always" t
)
1580 (const :tag
"Never" nil
)
1581 (const :tag
"When at beginning of entry" beg
)))
1583 (defcustom org-agenda-remove-timeranges-from-blocks nil
1584 "Non-nil means remove time ranges specifications in agenda
1585 items that span on several days."
1586 :group
'org-agenda-line-format
1590 (defcustom org-agenda-default-appointment-duration nil
1591 "Default duration for appointments that only have a starting time.
1592 When nil, no duration is specified in such cases.
1593 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1594 :group
'org-agenda-line-format
1596 (integer :tag
"Minutes")
1597 (const :tag
"No default duration")))
1599 (defcustom org-agenda-show-inherited-tags t
1600 "Non-nil means show inherited tags in each agenda line."
1601 :group
'org-agenda-line-format
1604 (defcustom org-agenda-hide-tags-regexp nil
1605 "Regular expression used to filter away specific tags in agenda views.
1606 This means that these tags will be present, but not be shown in the agenda
1607 line. Secondary filtering will still work on the hidden tags.
1608 Nil means don't hide any tags."
1609 :group
'org-agenda-line-format
1611 (const :tag
"Hide none" nil
)
1612 (string :tag
"Regexp ")))
1614 (defcustom org-agenda-remove-tags nil
1615 "Non-nil means remove the tags from the headline copy in the agenda.
1616 When this is the symbol `prefix', only remove tags when
1617 `org-agenda-prefix-format' contains a `%T' specifier."
1618 :group
'org-agenda-line-format
1620 (const :tag
"Always" t
)
1621 (const :tag
"Never" nil
)
1622 (const :tag
"When prefix format contains %T" prefix
)))
1624 (if (fboundp 'defvaralias
)
1625 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1626 'org-agenda-remove-tags
))
1628 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1629 "Shift tags in agenda items to this column.
1630 If this number is positive, it specifies the column. If it is negative,
1631 it means that the tags should be flushright to that column. For example,
1632 -80 works well for a normal 80 character screen."
1633 :group
'org-agenda-line-format
1636 (if (fboundp 'defvaralias
)
1637 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1639 (defcustom org-agenda-fontify-priorities
'cookies
1640 "Non-nil means highlight low and high priorities in agenda.
1641 When t, the highest priority entries are bold, lowest priority italic.
1642 However, settings in `org-priority-faces' will overrule these faces.
1643 When this variable is the symbol `cookies', only fontify the
1644 cookies, not the entire task.
1645 This may also be an association list of priority faces, whose
1646 keys are the character values of `org-highest-priority',
1647 `org-default-priority', and `org-lowest-priority' (the default values
1648 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1649 color as a string, or a list like `(:background \"Red\")'.
1650 If it is a color, the variable `org-faces-easy-properties'
1651 determines if it is a foreground or a background color."
1652 :group
'org-agenda-line-format
1654 (const :tag
"Never" nil
)
1655 (const :tag
"Defaults" t
)
1656 (const :tag
"Cookies only" cookies
)
1657 (repeat :tag
"Specify"
1658 (list (character :tag
"Priority" :value ?A
)
1659 (choice :tag
"Face "
1660 (string :tag
"Color")
1661 (sexp :tag
"Face"))))))
1663 (defcustom org-agenda-day-face-function nil
1664 "Function called to determine what face should be used to display a day.
1665 The only argument passed to that function is the day. It should
1666 returns a face, or nil if does not want to specify a face and let
1667 the normal rules apply."
1668 :group
'org-agenda-line-format
1672 (defcustom org-agenda-category-icon-alist nil
1673 "Alist of category icon to be displayed in agenda views.
1675 Each entry should have the following format:
1677 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1679 Where CATEGORY-REGEXP is a regexp matching the categories where
1680 the icon should be displayed.
1681 FILE-OR-DATA either a file path or a string containing image data.
1683 The other fields can be omitted safely if not needed:
1684 TYPE indicates the image type.
1685 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1687 PROPS are additional image attributes to assign to the image,
1688 like, e.g. `:ascent center'.
1690 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1692 If you want to set the display properties yourself, just put a
1693 list as second element:
1695 (CATEGORY-REGEXP (MY PROPERTY LIST))
1697 For example, to display a 16px horizontal space for Emacs
1698 category, you can use:
1700 (\"Emacs\" '(space . (:width (16))))"
1701 :group
'org-agenda-line-format
1703 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1704 :value-type
(choice (list :tag
"Icon"
1705 (string :tag
"File or data")
1706 (symbol :tag
"Type")
1707 (boolean :tag
"Data?")
1708 (repeat :tag
"Extra image properties" :inline t symbol
))
1709 (list :tag
"Display properties" sexp
))))
1711 (defgroup org-agenda-column-view nil
1712 "Options concerning column view in the agenda."
1713 :tag
"Org Agenda Column View"
1716 (defcustom org-agenda-columns-show-summaries t
1717 "Non-nil means show summaries for columns displayed in the agenda view."
1718 :group
'org-agenda-column-view
1721 (defcustom org-agenda-columns-compute-summary-properties t
1722 "Non-nil means recompute all summary properties before column view.
1723 When column view in the agenda is listing properties that have a summary
1724 operator, it can go to all relevant buffers and recompute the summaries
1725 there. This can mean overhead for the agenda column view, but is necessary
1726 to have thing up to date.
1727 As a special case, a CLOCKSUM property also makes sure that the clock
1728 computations are current."
1729 :group
'org-agenda-column-view
1732 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1733 "Non-nil means the duration of an appointment will add to day effort.
1734 The property to which appointment durations will be added is the one given
1735 in the option `org-effort-property'. If an appointment does not have
1736 an end time, `org-agenda-default-appointment-duration' will be used. If that
1737 is not set, an appointment without end time will not contribute to the time
1739 :group
'org-agenda-column-view
1742 (defcustom org-agenda-auto-exclude-function nil
1743 "A function called with a tag to decide if it is filtered on '/ RET'.
1744 The sole argument to the function, which is called once for each
1745 possible tag, is a string giving the name of the tag. The
1746 function should return either nil if the tag should be included
1747 as normal, or \"-<TAG>\" to exclude the tag.
1748 Note that for the purpose of tag filtering, only the lower-case version of
1749 all tags will be considered, so that this function will only ever see
1750 the lower-case version of all tags."
1754 (defcustom org-agenda-bulk-custom-functions nil
1755 "Alist of characters and custom functions for bulk actions.
1756 For example, this value makes those two functions available:
1761 With selected entries in an agenda buffer, `B R' will call
1762 the custom function `set-category' on the selected entries.
1763 Note that functions in this alist don't need to be quoted."
1772 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
1773 "Execute BODY with point at location given by `org-hd-marker' property.
1774 If STRING is non-nil, the text property will be fetched from position 0
1775 in that string. If STRING is nil, it will be fetched from the beginning
1776 of the current line."
1777 (org-with-gensyms (marker)
1778 `(let ((,marker
(get-text-property (if string
0 (point-at-bol))
1779 'org-hd-marker
,string
)))
1780 (with-current-buffer (marker-buffer ,marker
)
1784 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
1786 (defun org-add-agenda-custom-command (entry)
1787 "Replace or add a command in `org-agenda-custom-commands'.
1788 This is mostly for hacking and trying a new command - once the command
1789 works you probably want to add it to `org-agenda-custom-commands' for good."
1790 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1792 (setcdr ass
(cdr entry
))
1793 (push entry org-agenda-custom-commands
))))
1795 ;;; Define the org-agenda-mode
1797 (defvar org-agenda-mode-map
(make-sparse-keymap)
1798 "Keymap for `org-agenda-mode'.")
1799 (if (fboundp 'defvaralias
)
1800 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1802 (defvar org-agenda-menu
) ; defined later in this file.
1803 (defvar org-agenda-restrict
) ; defined later in this file.
1804 (defvar org-agenda-follow-mode nil
)
1805 (defvar org-agenda-entry-text-mode nil
)
1806 (defvar org-agenda-clockreport-mode nil
)
1807 (defvar org-agenda-show-log nil
)
1808 (defvar org-agenda-redo-command nil
)
1809 (defvar org-agenda-query-string nil
)
1810 (defvar org-agenda-mode-hook nil
1811 "Hook for `org-agenda-mode', run after the mode is turned on.")
1812 (defvar org-agenda-type nil
)
1813 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1816 ;;; Multiple agenda buffers support
1818 (defcustom org-agenda-sticky nil
1819 "Non-nil means agenda q key will bury agenda buffers.
1820 Agenda commands will then show existing buffer instead of generating new ones.
1821 When nil, `q' will kill the single agenda buffer."
1825 (defvar org-agenda-buffer nil
1826 "Agenda buffer currently being generated.")
1828 (defun org-toggle-sticky-agenda (&optional arg
)
1829 "Toggle `org-agenda-sticky'."
1831 (setq org-agenda-sticky
(or arg
(not org-agenda-sticky
)))
1832 (org-agenda-kill-all-agenda-buffers)
1833 (message "Sticky agenda was %s" (if org-agenda-sticky
"enabled" "disabled")))
1835 (defvar org-agenda-last-prefix-arg nil
)
1836 (defvar org-agenda-this-buffer-name nil
)
1837 (defvar org-agenda-doing-sticky-redo nil
)
1838 (defvar org-agenda-this-buffer-is-sticky nil
)
1840 ;; below list is generating by grepping org-agenda.el for defvar
1841 (defconst org-agenda-local-vars
1842 '(;; calendar-mode-map
1843 ; org-clock-current-task ; Must be global
1844 ; org-mobile-force-id-on-agenda-items ; Must be global
1845 ; org-habit-show-habits ; Must be global
1846 ; org-habit-show-habits-only-for-today ; Must be global
1847 org-agenda-this-buffer-name
; OK with sticky buffers
1848 ; org-agenda-overriding-header ; Must be global (will be scoped)
1849 ; org-agenda-title-append ; Must be global (will be scoped)
1850 org-agenda-undo-list
; OK with sticky buffers
1851 org-agenda-pending-undo-list
; OK with sticky buffers
1852 ; org-agenda-archives-mode ;; Taken out because it is hard to make work with sticky buffers because it is used in .org buffers and maybe even elsewhere. Just leave it global for now.
1853 ; org-agenda-entry-text-cleanup-hook ; Must be global
1854 ; org-agenda-include-inactive-timestamps ; Scoped variable, should be global
1855 ; org-prefix-format-compiled ; Fine as global, the culprit was org-prefix-has-xxx vars -- Max
1856 ; org-agenda-mode-map ; Must be global
1857 ; org-agenda-menu ; Must be global
1858 org-agenda-follow-mode
; OK with sticky buffers
1859 org-agenda-entry-text-mode
; OK with sticky buffers
1860 org-agenda-clockreport-mode
; OK with sticky buffers
1861 org-agenda-show-log
; Should now be OK with sticky buffers
1862 org-agenda-redo-command
; OK with sticky buffers
1863 org-agenda-query-string
; OK with sticky buffers
1864 org-agenda-type
; OK with sticky buffers
1865 org-agenda-bulk-marked-entries
; OK with sticky buffers
1866 ; org-agenda-allow-remote-undo ; Must be global
1867 org-agenda-undo-has-started-in
; OK with sticky buffers
1868 org-agenda-restrict
; ?????????????? Does not work with sticky, maybe we need to keep this global?
1869 org-agenda-restrict-begin
; ?????????????? Does not work with sticky, maybe we need to keep this global?
1870 org-agenda-restrict-end
; ?????????????? Does not work with sticky, maybe we need to keep this global?
1871 ; org-agenda-last-dispatch-buffer ; must be global
1872 ;; org-agenda-overriding-restriction ; must be global
1873 ;; org-agenda-overriding-arguments ; must be global
1874 org-agenda-last-arguments
; OK with sticky buffers
1875 org-agenda-info
; OK with sticky buffers
1876 ; org-mobile-creating-agendas ; Must be global
1877 org-agenda-tag-filter-overlays
; OK with sticky buffers
1878 org-agenda-cat-filter-overlays
; OK with sticky buffers
1879 ; org-agenda-marker-table ; Should be global
1880 org-pre-agenda-window-conf
; OK with sticky buffers
1881 org-agenda-columns-active
; OK with sticky buffers
1882 ; org-agenda-name ; Not needed will be set locally
1883 org-agenda-tag-filter
; OK with sticky buffers
1884 org-agenda-category-filter
; OK with sticky buffers
1885 ; org-agenda-tag-filter-while-redo ; not necessary
1886 ; org-agenda-tag-filter-preset ; not necessary since scoped from options
1887 ; org-agenda-category-filter-preset ; not necessary since sciped from options
1888 org-agenda-markers
; OK with sticky buffers
1889 ; org-agenda-last-marker-time ; Must be global
1890 ; org-agenda-only-exact-dates ; Must be global
1891 ; org-agenda-start-day ; must be global
1892 ; org-starting-day ; not necessary to include
1893 ; org-agenda-current-span ; not necessary to include
1894 ; org-arg-loc ; not necessary to include
1895 ; org-agenda-entry-types ; Must be global
1896 ; org-agenda-search-history ; Must be global
1897 ; org-todo-only ; Must be global
1898 ; org-search-syntax-table ; Must be global
1899 org-agenda-last-search-view-search-was-boolean
; OK with sticky buffers
1900 ; org-last-arg ; not necessary to include
1901 ; org-agenda-skip-regexp ; Must be global (will be scoped)
1902 ; org-agenda-overriding-header ; Must be global (will be scoped)
1903 ; org-disable-agenda-to-diary ; Must be global
1904 ; diary-list-entries-hook ; Must be global
1905 ; diary-time-regexp ; Must be global
1906 ; org-agenda-cleanup-fancy-diary-hook ; Must be global
1907 ; org-diary-last-run-time ; Must be global
1908 ; org-heading-keyword-regexp-format ; Must be global
1909 ; org-agenda-sorting-strategy ; Must be global
1910 ; org-agenda-sorting-strategy-selected ; Must be global
1911 ; org-agenda-before-sorting-filter-function ; Must be global
1912 ; org-agenda-restriction-lock-overlay ; Must be global
1913 ; org-global-tags-completion-table ; Must be global
1914 org-agenda-filtered-by-category
; OK with sticky buffers
1915 org-agenda-filter-form
; OK with sticky buffers
1916 ; org-hl ; Must be global
1917 ; org-agenda-after-show-hook ; Must be global
1918 ; org-archive-default-command ; Must be global
1919 org-agenda-show-window
; not sure if needed, but probably OK
1920 org-agenda-cycle-counter
; not sure if needed, but probably OK
1921 ; org-last-heading-marker ; Must be global
1922 org-agenda-last-prefix-arg
; OK with sticky buffers
1926 (defun org-agenda-mode ()
1927 "Mode for time-sorted view on action items in Org-mode files.
1929 The following commands are available:
1931 \\{org-agenda-mode-map}"
1933 (cond (org-agenda-doing-sticky-redo
1934 ;; Refreshing sticky agenda-buffer
1936 ;; Preserve the value of `org-agenda-local-vars' variables,
1937 ;; while letting `kill-all-local-variables' kill the rest
1938 (let ((save (buffer-local-variables)))
1939 (kill-all-local-variables)
1940 (mapc 'make-local-variable org-agenda-local-vars
)
1942 (let ((var (car elem
))
1945 (member var org-agenda-local-vars
))
1947 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
1949 ;; Creating a sticky Agenda buffer for the first time
1950 (kill-all-local-variables)
1951 (mapc 'make-local-variable org-agenda-local-vars
)
1952 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
1954 ;; Creating a non-sticky agenda buffer
1955 (kill-all-local-variables)
1956 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) nil
)))
1957 (setq org-agenda-undo-list nil
1958 org-agenda-pending-undo-list nil
1959 org-agenda-bulk-marked-entries nil
)
1960 (setq major-mode
'org-agenda-mode
)
1961 ;; Keep global-font-lock-mode from turning on font-lock-mode
1962 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1963 (setq mode-name
"Org-Agenda")
1964 (use-local-map org-agenda-mode-map
)
1965 (easy-menu-add org-agenda-menu
)
1966 (if org-startup-truncated
(setq truncate-lines t
))
1967 (org-set-local 'line-move-visual nil
)
1968 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1969 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1970 ;; Make sure properties are removed when copying text
1971 (when (boundp 'buffer-substring-filters
)
1972 (org-set-local 'buffer-substring-filters
1974 (set-text-properties 0 (length x
) nil x
) x
)
1975 buffer-substring-filters
)))
1976 (unless org-agenda-keep-modes
1977 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1978 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1979 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1980 org-agenda-show-log org-agenda-start-with-log-mode
))
1983 '("Agenda") "Agenda Files"
1987 (if (get 'org-agenda-files
'org-restrict
)
1988 "Restricted to single file"
1990 '(org-edit-agenda-file-list)
1991 (not (get 'org-agenda-files
'org-restrict
)))
1993 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1994 (org-agenda-set-mode-name)
1996 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1997 (list 'org-agenda-mode-hook
)))
1999 (substitute-key-definition 'undo
'org-agenda-undo
2000 org-agenda-mode-map global-map
)
2001 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
2002 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
2003 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
2004 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
2005 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
2006 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
2007 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
2008 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
2009 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
2010 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
2011 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
2012 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
2013 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
2014 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
2015 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
2016 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
2017 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
2018 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
2019 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
2020 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
2021 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
2022 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2023 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2024 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2025 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2026 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2027 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2028 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2029 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2030 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2031 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2032 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2033 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2034 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2035 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2036 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2037 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2038 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2039 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2040 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2041 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2042 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2043 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2044 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2045 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2047 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2048 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2049 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2050 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2051 (while l (org-defkey org-agenda-mode-map
2052 (int-to-string (pop l)) 'digit-argument)))
2054 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2055 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2056 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2057 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2058 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2059 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2060 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2061 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2062 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2063 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2064 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2065 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2066 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2067 'org-clock-modify-effort-estimate)
2068 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2069 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2070 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2071 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2072 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2073 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2074 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2075 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
2076 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2077 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2078 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2079 (substitute-key-definition 'next-line 'org-agenda-next-line
2080 org-agenda-mode-map global-map)
2081 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2082 org-agenda-mode-map global-map)
2083 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2084 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2085 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2086 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2087 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2088 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2089 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2090 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2091 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2092 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2093 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2094 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2095 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2096 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2097 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2098 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2099 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2100 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2101 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2102 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2103 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2104 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2105 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2106 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2107 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2108 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2109 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2110 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2111 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2112 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2114 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2115 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2116 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2117 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2118 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2119 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2120 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2121 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2122 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2123 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2126 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2127 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2128 (when org-agenda-mouse-1-follows-link
2129 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2130 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2135 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2136 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2137 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2138 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2141 ["Day View" org-agenda-day-view
2142 :active (org-agenda-check-type nil 'agenda)
2143 :style radio :selected (eq org-agenda-current-span 'day)
2144 :keys "v d (or just d)"]
2145 ["Week View" org-agenda-week-view
2146 :active (org-agenda-check-type nil 'agenda)
2147 :style radio :selected (eq org-agenda-current-span 'week)
2148 :keys "v w (or just w)"]
2149 ["Month View" org-agenda-month-view
2150 :active (org-agenda-check-type nil 'agenda)
2151 :style radio :selected (eq org-agenda-current-span 'month)
2153 ["Year View" org-agenda-year-view
2154 :active (org-agenda-check-type nil 'agenda)
2155 :style radio :selected (eq org-agenda-current-span 'year)
2158 ["Include Diary" org-agenda-toggle-diary
2159 :style toggle :selected org-agenda-include-diary
2160 :active (org-agenda-check-type nil 'agenda)]
2161 ["Include Deadlines" org-agenda-toggle-deadlines
2162 :style toggle :selected org-agenda-include-deadlines
2163 :active (org-agenda-check-type nil 'agenda)]
2164 ["Use Time Grid" org-agenda-toggle-time-grid
2165 :style toggle :selected org-agenda-use-time-grid
2166 :active (org-agenda-check-type nil 'agenda)]
2168 ["Show clock report" org-agenda-clockreport-mode
2169 :style toggle :selected org-agenda-clockreport-mode
2170 :active (org-agenda-check-type nil 'agenda)]
2171 ["Show some entry text" org-agenda-entry-text-mode
2172 :style toggle :selected org-agenda-entry-text-mode
2175 ["Show Logbook entries" org-agenda-log-mode
2176 :style toggle :selected org-agenda-show-log
2177 :active (org-agenda-check-type nil 'agenda 'timeline)
2178 :keys "v l (or just l)"]
2179 ["Include archived trees" org-agenda-archives-mode
2180 :style toggle :selected org-agenda-archives-mode :active t
2182 ["Include archive files" (org-agenda-archives-mode t)
2183 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2186 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2187 ["Write view to file" org-agenda-write t]
2188 ["Rebuild buffer" org-agenda-redo t]
2189 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2191 ["Show original entry" org-agenda-show t]
2192 ["Go To (other window)" org-agenda-goto t]
2193 ["Go To (this window)" org-agenda-switch-to t]
2194 ["Follow Mode" org-agenda-follow-mode
2195 :style toggle :selected org-agenda-follow-mode :active t]
2196 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2199 ["Cycle TODO" org-agenda-todo t]
2200 ["Next TODO set" org-agenda-todo-nextset t]
2201 ["Previous TODO set" org-agenda-todo-previousset t]
2202 ["Add note" org-agenda-add-note t])
2203 ("Archive/Refile/Delete"
2204 ["Archive default" org-agenda-archive-default t]
2205 ["Archive default" org-agenda-archive-default-with-confirmation t]
2206 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2207 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2208 ["Archive subtree" org-agenda-archive t]
2210 ["Refile" org-agenda-refile t]
2212 ["Delete subtree" org-agenda-kill t])
2214 ["Mark entry" org-agenda-bulk-mark t]
2215 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2216 ["Unmark entry" org-agenda-bulk-unmark t]
2217 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2218 ["Act on all marked" org-agenda-bulk-action t]
2220 ("Tags and Properties"
2221 ["Show all Tags" org-agenda-show-tags t]
2222 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2223 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2225 ["Column View" org-columns t])
2226 ("Deadline/Schedule"
2227 ["Schedule" org-agenda-schedule t]
2228 ["Set Deadline" org-agenda-deadline t]
2230 ["Mark item" org-agenda-action :active t :keys "k m"]
2231 ["Show mark item" org-agenda-action :active t :keys "k v"]
2232 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2233 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2235 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2236 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2237 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2238 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2239 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2240 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2241 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2243 ["Clock in" org-agenda-clock-in t]
2244 ["Clock out" org-agenda-clock-out t]
2245 ["Clock cancel" org-agenda-clock-cancel t]
2246 ["Goto running clock" org-clock-goto t]
2248 ["Set Effort" org-agenda-set-effort t]
2249 ["Change clocked effort" org-clock-modify-effort-estimate
2250 (org-clock-is-active)])
2252 ["Set Priority" org-agenda-priority t]
2253 ["Increase Priority" org-agenda-priority-up t]
2254 ["Decrease Priority" org-agenda-priority-down t]
2255 ["Show Priority" org-agenda-show-priority t])
2257 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2258 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2259 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2260 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2261 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2262 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2264 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2266 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2269 ["Push Files and Views" org-mobile-push t]
2270 ["Get Captured and Flagged" org-mobile-pull t]
2271 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2272 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2274 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2276 ["Quit" org-agenda-quit t]
2277 ["Exit and Release Buffers" org-agenda-exit t]
2282 (defvar org-agenda-allow-remote-undo t
2283 "Non-nil means allow remote undo from the agenda buffer.")
2284 (defvar org-agenda-undo-list nil
2285 "List of undoable operations in the agenda since last refresh.")
2286 (defvar org-agenda-undo-has-started-in nil
2287 "Buffers that have already seen `undo-start' in the current undo sequence.")
2288 (defvar org-agenda-pending-undo-list nil
2289 "In a series of undo commands, this is the list of remaining undo items.")
2291 (defun org-agenda-undo ()
2292 "Undo a remote editing step in the agenda.
2293 This undoes changes both in the agenda buffer and in the remote buffer
2294 that have been changed along."
2296 (or org-agenda-allow-remote-undo
2297 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2298 (if (not (eq this-command last-command))
2299 (setq org-agenda-undo-has-started-in nil
2300 org-agenda-pending-undo-list org-agenda-undo-list))
2301 (if (not org-agenda-pending-undo-list)
2302 (error "No further undo information"))
2303 (let* ((entry (pop org-agenda-pending-undo-list))
2304 buf line cmd rembuf)
2305 (setq cmd (pop entry) line (pop entry))
2306 (setq rembuf (nth 2 entry))
2307 (org-with-remote-undo rembuf
2308 (while (bufferp (setq buf (pop entry)))
2310 (with-current-buffer buf
2311 (let ((last-undo-buffer buf)
2312 (inhibit-read-only t))
2313 (unless (memq buf org-agenda-undo-has-started-in)
2314 (push buf org-agenda-undo-has-started-in)
2315 (make-local-variable 'pending-undo-list)
2317 (while (and pending-undo-list
2318 (listp pending-undo-list)
2319 (not (car pending-undo-list)))
2320 (pop pending-undo-list))
2322 (org-goto-line line)
2323 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2325 (defun org-verify-change-for-undo (l1 l2)
2326 "Verify that a real change occurred between the undo lists L1 and L2."
2327 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2328 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2333 (defvar org-agenda-restrict nil)
2334 (defvar org-agenda-restrict-begin (make-marker))
2335 (defvar org-agenda-restrict-end (make-marker))
2336 (defvar org-agenda-last-dispatch-buffer nil)
2337 (defvar org-agenda-overriding-restriction nil)
2340 (defun org-agenda (&optional arg keys restriction)
2341 "Dispatch agenda commands to collect entries to the agenda buffer.
2342 Prompts for a command to execute. Any prefix arg will be passed
2343 on to the selected command. The default selections are:
2345 a Call `org-agenda-list' to display the agenda for current day or week.
2346 t Call `org-todo-list' to display the global todo list.
2347 T Call `org-todo-list' to display the global todo list, select only
2348 entries with a specific TODO keyword (the user gets a prompt).
2349 m Call `org-tags-view' to display headlines with tags matching
2350 a condition (the user is prompted for the condition).
2351 M Like `m', but select only TODO entries, no ordinary headlines.
2352 L Create a timeline for the current buffer.
2353 e Export views to associated files.
2354 s Search entries for keywords.
2355 / Multi occur across all agenda files and also files listed
2356 in `org-agenda-text-search-extra-files'.
2357 < Restrict agenda commands to buffer, subtree, or region.
2358 Press several times to get the desired effect.
2359 > Remove a previous restriction.
2360 # List \"stuck\" projects.
2361 ! Configure what \"stuck\" means.
2362 C Configure custom agenda commands.
2364 More commands can be added by configuring the variable
2365 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2366 searches can be pre-defined in this way.
2368 If the current buffer is in Org-mode and visiting a file, you can also
2369 first press `<' once to indicate that the agenda should be temporarily
2370 \(until the next use of \\[org-agenda]) restricted to the current file.
2371 Pressing `<' twice means to restrict to the current subtree or region
2375 (let* ((prefix-descriptions nil)
2376 (org-agenda-buffer-name org-agenda-buffer-name)
2377 (org-agenda-window-setup (if (equal (buffer-name)
2378 org-agenda-buffer-name)
2380 org-agenda-window-setup))
2381 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2382 (org-agenda-custom-commands
2383 ;; normalize different versions
2387 (cond ((stringp (cdr x))
2388 (push x prefix-descriptions)
2390 ((stringp (nth 1 x)) x)
2391 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2392 (t (cons (car x) (cons "" (cdr x))))))
2393 org-agenda-custom-commands)))
2394 (buf (current-buffer))
2395 (bfn (buffer-file-name (buffer-base-buffer)))
2396 entry key type match lprops ans)
2397 ;; Turn off restriction unless there is an overriding one,
2398 (unless org-agenda-overriding-restriction
2399 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2400 ;; There is a request to keep the file list in place
2401 (put 'org-agenda-files 'org-restrict nil))
2402 (setq org-agenda-restrict nil)
2403 (move-marker org-agenda-restrict-begin nil)
2404 (move-marker org-agenda-restrict-end nil))
2405 ;; Delete old local properties
2406 (put 'org-agenda-redo-command 'org-lprops nil)
2407 ;; Delete previously set last-arguments
2408 (put 'org-agenda-redo-command 'last-args nil)
2409 ;; Remember where this call originated
2410 (setq org-agenda-last-dispatch-buffer (current-buffer))
2412 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2414 restriction (cdr ans)))
2415 ;; If we have sticky agenda buffers, set a name for the buffer,
2416 ;; depending on the invoking keys. The user may still set this
2417 ;; as a command option, which will overwrite what we do here.
2418 (if org-agenda-sticky
2419 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2420 ;; Establish the restriction, if any
2421 (when (and (not org-agenda-overriding-restriction) restriction)
2422 (put 'org-agenda-files 'org-restrict (list bfn))
2424 ((eq restriction 'region)
2425 (setq org-agenda-restrict t)
2426 (move-marker org-agenda-restrict-begin (region-beginning))
2427 (move-marker org-agenda-restrict-end (region-end)))
2428 ((eq restriction 'subtree)
2430 (setq org-agenda-restrict t)
2431 (org-back-to-heading t)
2432 (move-marker org-agenda-restrict-begin (point))
2433 (move-marker org-agenda-restrict-end
2434 (progn (org-end-of-subtree t)))))))
2436 ;; For example the todo list should not need it (but does...)
2438 ((setq entry (assoc keys org-agenda-custom-commands))
2439 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2441 (setq type (nth 2 entry) match (eval (nth 3 entry))
2442 lprops (nth 4 entry))
2443 (put 'org-agenda-redo-command 'org-lprops lprops)
2446 (org-let lprops '(org-agenda-list current-prefix-arg)))
2448 (org-let lprops '(org-todo-list current-prefix-arg)))
2450 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2452 (org-let lprops '(org-agenda-list-stuck-projects
2453 current-prefix-arg)))
2455 (org-let lprops '(org-tags-view current-prefix-arg match)))
2456 ((eq type 'tags-todo)
2457 (org-let lprops '(org-tags-view '(4) match)))
2459 (org-let lprops '(org-todo-list match)))
2460 ((eq type 'tags-tree)
2461 (org-check-for-org-mode)
2462 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2463 ((eq type 'todo-tree)
2464 (org-check-for-org-mode)
2466 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2467 (regexp-quote match) "\\>"))))
2468 ((eq type 'occur-tree)
2469 (org-check-for-org-mode)
2470 (org-let lprops '(org-occur match)))
2472 (org-let lprops '(funcall type match)))
2474 (org-let lprops '(funcall type match)))
2475 (t (error "Invalid custom agenda command type %s" type))))
2476 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2478 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2479 (customize-variable 'org-agenda-custom-commands))
2480 ((equal keys "a") (call-interactively 'org-agenda-list))
2481 ((equal keys "s") (call-interactively 'org-search-view))
2482 ((equal keys "t") (call-interactively 'org-todo-list))
2483 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2484 ((equal keys "m") (call-interactively 'org-tags-view))
2485 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2486 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2487 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2491 (unless (current-message)
2492 (let* ((m (org-agenda-get-any-marker))
2493 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2496 "FLAGGING-NOTE ([?] for more info): "
2498 (replace-regexp-in-string
2500 (copy-sequence note))
2501 nil 'face 'org-warning)))))))
2504 (unless (eq major-mode 'org-mode)
2505 (error "This is not an Org-mode file"))
2507 (put 'org-agenda-files 'org-restrict (list bfn))
2508 (org-call-with-arg 'org-timeline arg)))
2509 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2510 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2511 ((equal keys "!") (customize-variable 'org-stuck-projects))
2512 (t (error "Invalid agenda key"))))))
2514 (defun org-agenda-append-agenda ()
2515 "Append another agenda view to the current one.
2516 This function allows interactive building of block agendas.
2517 Agenda views are separated by `org-agenda-block-separator'."
2519 (unless (string= (buffer-name) org-agenda-buffer-name)
2520 (error "Can only append from within agenda buffer"))
2521 (let ((org-agenda-multi t))
2525 (defun org-agenda-normalize-custom-commands (cmds)
2529 (cond ((stringp (cdr x)) nil)
2530 ((stringp (nth 1 x)) x)
2531 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2532 (t (cons (car x) (cons "" (cdr x))))))
2535 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2536 "The user interface for selecting an agenda command."
2538 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2539 (restrict-ok (and bfn (eq major-mode 'org-mode)))
2540 (region-p (org-region-active-p))
2541 (custom org-agenda-custom-commands)
2543 restriction second-time
2544 c entry key type match prefixes rmheader header-end custom1 desc
2545 line lines left right n n1)
2546 (save-window-excursion
2547 (delete-other-windows)
2548 (org-switch-to-buffer-other-window " *Agenda Commands*")
2550 (insert (eval-when-compile
2553 Press key for an agenda command: < Buffer, subtree/region restriction
2554 -------------------------------- > Remove restriction
2555 a Agenda for current week or day e Export agenda views
2556 t List of all TODO entries T Entries with special TODO kwd
2557 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2558 L Timeline for current buffer # List stuck projects (!=configure)
2559 s Search for keywords C Configure custom agenda commands
2560 / Multi-occur ? Find :FLAGGED: entries
2563 (while (string-match
2564 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2566 (setq start (match-end 0))
2567 (add-text-properties (match-beginning 2) (match-end 2)
2568 '(face bold) header))
2570 (setq header-end (move-marker (make-marker) (point)))
2572 (setq custom1 custom)
2573 (when (eq rmheader t)
2575 (re-search-forward ":" nil t)
2576 (delete-region (match-end 0) (point-at-eol))
2579 (delete-region (match-end 0) (point-at-eol))
2580 (move-marker header-end (match-end 0)))
2581 (goto-char header-end)
2582 (delete-region (point) (point-max))
2584 ;; Produce all the lines that describe custom commands and prefixes
2586 (while (setq entry (pop custom1))
2587 (setq key (car entry) desc (nth 1 entry)
2589 match (nth 3 entry))
2590 (if (> (length key) 1)
2591 (add-to-list 'prefixes (string-to-char key))
2595 (org-add-props (copy-sequence key)
2598 ((string-match "\\S-" desc) desc)
2599 ((eq type 'agenda) "Agenda for current week or day")
2600 ((eq type 'alltodo) "List of all TODO entries")
2601 ((eq type 'search) "Word search")
2602 ((eq type 'stuck) "List of stuck projects")
2603 ((eq type 'todo) "TODO keyword")
2604 ((eq type 'tags) "Tags query")
2605 ((eq type 'tags-todo) "Tags (TODO)")
2606 ((eq type 'tags-tree) "Tags tree")
2607 ((eq type 'todo-tree) "TODO kwd tree")
2608 ((eq type 'occur-tree) "Occur tree")
2609 ((functionp type) (if (symbolp type)
2611 "Lambda expression"))
2613 (if org-agenda-menu-show-matcher
2618 (setq match (copy-sequence match))
2619 (org-add-props match nil 'face 'org-warning))
2621 (format "set of %d commands" (length match)))
2623 (if (org-string-nw-p match)
2624 (add-text-properties
2625 0 (length line) (list 'help-echo
2626 (concat "Matcher: "match)) line)))
2628 (setq lines (nreverse lines))
2633 (org-add-props (char-to-string x)
2635 (or (cdr (assoc (concat selstring
2637 prefix-descriptions))
2642 ;; Check if we should display in two columns
2643 (if org-agenda-menu-two-column
2645 (setq n (length lines)
2646 n1 (+ (/ n 2) (mod n 2))
2647 right (nthcdr n1 lines)
2648 left (copy-sequence lines))
2649 (setcdr (nthcdr (1- n1) left) nil))
2650 (setq left lines right nil))
2652 (insert "\n" (pop left))
2654 (if (< (current-column) 40)
2655 (move-to-column 40 t)
2657 (insert (pop right))))
2659 ;; Make the window the right size
2660 (goto-char (point-min))
2662 (if (not (pos-visible-in-window-p (point-max)))
2663 (org-fit-window-to-buffer))
2664 (setq second-time t)
2665 (org-fit-window-to-buffer))
2667 ;; Ask for selection
2668 (message "Press key for agenda command%s:"
2669 (if (or restrict-ok org-agenda-overriding-restriction)
2670 (if org-agenda-overriding-restriction
2671 " (restriction lock active)"
2673 (format " (restricted to %s)" restriction)
2676 (setq c (read-char-exclusive))
2679 ((assoc (char-to-string c) custom)
2680 (setq selstring (concat selstring (char-to-string c)))
2681 (throw 'exit (cons selstring restriction)))
2683 (setq selstring (concat selstring (char-to-string c))
2685 rmheader (or rmheader t)
2686 custom (delq nil (mapcar
2688 (if (or (= (length (car x)) 1)
2689 (/= (string-to-char (car x)) c))
2691 (cons (substring (car x) 1) (cdr x))))
2694 (org-agenda-remove-restriction-lock 'noupdate)
2695 (org-agenda-kill-all-agenda-buffers)
2696 (message "All agenda buffers have been killed")
2698 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2699 (message "Restriction is only possible in Org-mode buffers")
2702 (org-agenda-remove-restriction-lock 'noupdate)
2703 (setq restriction 'buffer))
2705 (org-agenda-remove-restriction-lock 'noupdate)
2706 (setq restriction (if region-p 'region 'subtree)))
2708 (org-agenda-remove-restriction-lock 'noupdate)
2711 ((eq restriction 'buffer)
2712 (if region-p 'region 'subtree))
2713 ((memq restriction '(subtree region))
2717 (org-agenda-remove-restriction-lock 'noupdate)
2718 (setq restriction nil))
2719 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2720 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2721 ((and (> (length selstring) 0) (eq c ?\d))
2723 (org-agenda-get-restriction-and-command prefix-descriptions))
2725 ((equal c ?q) (error "Abort"))
2726 (t (error "Invalid key %c" c))))))))
2728 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2729 (defvar org-agenda-last-arguments nil
2730 "The arguments of the previous call to `org-agenda'.")
2731 (defun org-agenda-run-series (name series)
2732 (org-let (nth 1 series) '(org-prepare-agenda name))
2733 ;; We need to reset agenda markers heree, because when constructing a
2734 ;; block agenda, the individual blocks do not do that.
2735 (org-agenda-reset-markers)
2736 (let* ((org-agenda-multi t)
2737 (redo (list 'org-agenda-run-series name (list 'quote series)))
2738 (org-agenda-overriding-arguments
2739 (or org-agenda-overriding-arguments
2740 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2741 (get 'org-agenda-redo-command 'last-args))))
2743 (gprops (nth 1 series))
2744 match ;; The byte compiler incorrectly complains about this. Keep it!
2746 (while (setq cmd (pop cmds))
2747 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2750 (org-let2 gprops lprops
2751 '(call-interactively 'org-agenda-list)))
2753 (org-let2 gprops lprops
2754 '(call-interactively 'org-todo-list)))
2756 (org-let2 gprops lprops
2757 '(org-search-view current-prefix-arg match nil)))
2759 (org-let2 gprops lprops
2760 '(call-interactively 'org-agenda-list-stuck-projects)))
2762 (org-let2 gprops lprops
2763 '(org-tags-view current-prefix-arg match)))
2764 ((eq type 'tags-todo)
2765 (org-let2 gprops lprops
2766 '(org-tags-view '(4) match)))
2768 (org-let2 gprops lprops
2769 '(org-todo-list match)))
2771 (org-let2 gprops lprops
2772 '(funcall type match)))
2773 (t (error "Invalid type in command series"))))
2775 (setq org-agenda-redo-command redo)
2776 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2777 (goto-char (point-min)))
2778 (org-fit-agenda-window)
2779 (org-let (nth 1 series) '(org-finalize-agenda)))
2782 (defmacro org-batch-agenda (cmd-key &rest parameters)
2783 "Run an agenda command in batch mode and send the result to STDOUT.
2784 If CMD-KEY is a string of length 1, it is used as a key in
2785 `org-agenda-custom-commands' and triggers this command. If it is a
2786 longer string it is used as a tags/todo match string.
2787 Parameters are alternating variable names and values that will be bound
2788 before running the agenda command."
2789 (org-eval-in-environment (org-make-parameter-alist parameters)
2790 (if (> (length cmd-key) 2)
2791 (org-tags-view nil cmd-key)
2792 (org-agenda nil cmd-key)))
2793 (set-buffer org-agenda-buffer-name)
2794 (princ (buffer-string)))
2795 (def-edebug-spec org-batch-agenda (form &rest sexp))
2797 (defvar org-agenda-info nil)
2800 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2801 "Run an agenda command in batch mode and send the result to STDOUT.
2802 If CMD-KEY is a string of length 1, it is used as a key in
2803 `org-agenda-custom-commands' and triggers this command. If it is a
2804 longer string it is used as a tags/todo match string.
2805 Parameters are alternating variable names and values that will be bound
2806 before running the agenda command.
2808 The output gives a line for each selected agenda item. Each
2809 item is a list of comma-separated values, like this:
2811 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2813 category The category of the item
2814 head The headline, without TODO kwd, TAGS and PRIORITY
2815 type The type of the agenda entry, can be
2816 todo selected in TODO match
2817 tagsmatch selected in tags match
2818 diary imported from diary
2819 deadline a deadline on given date
2820 scheduled scheduled on given date
2821 timestamp entry has timestamp on given date
2822 closed entry was closed on given date
2823 upcoming-deadline warning about deadline
2824 past-scheduled forwarded scheduled item
2825 block entry has date block including g. date
2826 todo The todo keyword, if any
2827 tags All tags including inherited ones, separated by colons
2828 date The relevant date, like 2007-2-14
2829 time The time, like 15:00-16:50
2830 extra Sting with extra planning info
2831 priority-l The priority letter if any was given
2832 priority-n The computed numerical priority
2833 agenda-day The day in the agenda where this is listed"
2834 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2835 (org-make-parameter-alist parameters))
2836 (if (> (length cmd-key) 2)
2837 (org-tags-view nil cmd-key)
2838 (org-agenda nil cmd-key)))
2839 (set-buffer org-agenda-buffer-name)
2840 (let* ((lines (org-split-string (buffer-string) "\n"))
2842 (while (setq line (pop lines))
2844 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2845 (setq org-agenda-info
2846 (org-fix-agenda-info (text-properties-at 0 line)))
2848 (mapconcat 'org-agenda-export-csv-mapper
2849 '(org-category txt type todo tags date time extra
2850 priority-letter priority agenda-day)
2853 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2855 (defun org-fix-agenda-info (props)
2856 "Make sure all properties on an agenda item have a canonical form.
2857 This ensures the export commands can easily use it."
2859 (when (setq tmp (plist-get props 'tags))
2860 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2861 (when (setq tmp (plist-get props 'date))
2862 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2863 (let ((calendar-date-display-form '(year "-" month "-" day)))
2864 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2866 (setq tmp (calendar-date-string tmp)))
2867 (setq props (plist-put props 'date tmp)))
2868 (when (setq tmp (plist-get props 'day))
2869 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2870 (let ((calendar-date-display-form '(year "-" month "-" day)))
2871 (setq tmp (calendar-date-string tmp)))
2872 (setq props (plist-put props 'day tmp))
2873 (setq props (plist-put props 'agenda-day tmp)))
2874 (when (setq tmp (plist-get props 'txt))
2875 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2876 (plist-put props 'priority-letter (match-string 1 tmp))
2877 (setq tmp (replace-match "" t t tmp)))
2878 (when (and (setq re (plist-get props 'org-todo-regexp))
2879 (setq re (concat "\\`\\.*" re " ?"))
2880 (string-match re tmp))
2881 (plist-put props 'todo (match-string 1 tmp))
2882 (setq tmp (replace-match "" t t tmp)))
2883 (plist-put props 'txt tmp)))
2886 (defun org-agenda-export-csv-mapper (prop)
2887 (let ((res (plist-get org-agenda-info prop)))
2892 (t (prin1-to-string res))))
2893 (while (string-match "," res)
2894 (setq res (replace-match ";" t t res))) ;
2899 (defun org-store-agenda-views (&rest parameters)
2901 (eval (list 'org-batch-store-agenda-views)))
2904 (defmacro org-batch-store-agenda-views (&rest parameters)
2905 "Run all custom agenda commands that have a file argument."
2906 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2908 (dir default-directory)
2909 (pars (org-make-parameter-alist parameters))
2910 cmd thiscmdkey files opts cmd-or-set)
2911 (save-window-excursion
2913 (setq cmd (pop cmds)
2914 thiscmdkey (car cmd)
2915 cmd-or-set (nth 2 cmd)
2916 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2917 files (nth (if (listp cmd-or-set) 4 5) cmd))
2918 (if (stringp files) (setq files (list files)))
2920 (org-eval-in-environment (append org-agenda-exporter-settings
2922 (org-agenda nil thiscmdkey))
2923 (set-buffer org-agenda-buffer-name)
2925 (org-eval-in-environment (append org-agenda-exporter-settings
2927 (org-agenda-write (expand-file-name (pop files) dir) nil t)))
2928 (and (get-buffer org-agenda-buffer-name)
2929 (kill-buffer org-agenda-buffer-name)))))))
2930 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2932 (defun org-agenda-mark-header-line (pos)
2933 "Mark the line at POS as an agenda structure header."
2936 (put-text-property (point-at-bol) (point-at-eol)
2937 'org-agenda-structural-header t)
2938 (when org-agenda-title-append
2939 (put-text-property (point-at-bol) (point-at-eol)
2940 'org-agenda-title-append org-agenda-title-append))))
2942 (defvar org-mobile-creating-agendas)
2943 (defvar org-agenda-write-buffer-name "Agenda View")
2944 (defun org-agenda-write (file &optional open nosettings)
2945 "Write the current buffer (an agenda view) as a file.
2946 Depending on the extension of the file name, plain text (.txt),
2947 HTML (.html or .htm) or Postscript (.ps) is produced.
2948 If the extension is .ics, run icalendar export over all files used
2949 to construct the agenda and limit the export to entries listed in the
2951 With prefix argument OPEN, open the new file immediately.
2952 If NOSETTINGS is given, do not scope the settings of
2953 `org-agenda-exporter-settings' into the export commands. This is used when
2954 the settings have already been scoped and we do not wish to overrule other,
2955 higher priority settings."
2956 (interactive "FWrite agenda to file: \nP")
2957 (if (not (file-writable-p file))
2958 (error "Cannot write agenda to file %s" file))
2959 (org-let (if nosettings nil org-agenda-exporter-settings)
2961 (save-window-excursion
2962 (org-agenda-mark-filtered-text)
2963 (let ((bs (copy-sequence (buffer-string))) beg)
2964 (org-agenda-unmark-filtered-text)
2966 (rename-buffer org-agenda-write-buffer-name t)
2967 (set-buffer-modified-p nil)
2969 (org-agenda-remove-marked-text 'org-filtered)
2970 (while (setq beg (text-property-any (point-min) (point-max)
2973 beg (or (next-single-property-change beg 'org-filtered)
2975 (run-hooks 'org-agenda-before-write-hook)
2977 ((org-bound-and-true-p org-mobile-creating-agendas)
2978 (org-mobile-write-agenda-for-mobile file))
2979 ((string-match "\\.html?\\'" file)
2981 (set-buffer (htmlize-buffer (current-buffer)))
2983 (when (and org-agenda-export-html-style
2984 (string-match "<style>" org-agenda-export-html-style))
2985 ;; replace <style> section with org-agenda-export-html-style
2986 (goto-char (point-min))
2987 (kill-region (- (search-forward "<style") 6)
2988 (search-forward "</style>"))
2989 (insert org-agenda-export-html-style))
2991 (kill-buffer (current-buffer))
2992 (message "HTML written to %s" file))
2993 ((string-match "\\.ps\\'" file)
2995 (ps-print-buffer-with-faces file)
2996 (message "Postscript written to %s" file))
2997 ((string-match "\\.pdf\\'" file)
2999 (ps-print-buffer-with-faces
3000 (concat (file-name-sans-extension file) ".ps"))
3001 (call-process "ps2pdf" nil nil nil
3003 (concat (file-name-sans-extension file) ".ps"))
3004 (expand-file-name file))
3005 (delete-file (concat (file-name-sans-extension file) ".ps"))
3006 (message "PDF written to %s" file))
3007 ((string-match "\\.ics\\'" file)
3008 (require 'org-icalendar)
3009 (let ((org-agenda-marker-table
3010 (org-create-marker-find-array
3011 (org-agenda-collect-markers)))
3012 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3013 (org-combined-agenda-icalendar-file file))
3014 (apply 'org-export-icalendar 'combine
3015 (org-agenda-files nil 'ifmode))))
3017 (let ((bs (buffer-string)))
3022 (kill-buffer (current-buffer))
3023 (message "Plain text written to %s" file))))))))
3024 (set-buffer org-agenda-buffer-name))
3025 (when open (org-open-file file)))
3027 (defvar org-agenda-tag-filter-overlays nil)
3028 (defvar org-agenda-cat-filter-overlays nil)
3030 (defun org-agenda-mark-filtered-text ()
3031 "Mark all text hidden by filtering with a text property."
3032 (let ((inhibit-read-only t))
3035 (when (equal (overlay-buffer o) (current-buffer))
3037 (overlay-start o) (overlay-end o)
3039 (append org-agenda-tag-filter-overlays
3040 org-agenda-cat-filter-overlays))))
3042 (defun org-agenda-unmark-filtered-text ()
3043 "Remove the filtering text property."
3044 (let ((inhibit-read-only t))
3045 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3047 (defun org-agenda-remove-marked-text (property &optional value)
3048 "Delete all text marked with VALUE of PROPERTY.
3049 VALUE defaults to t."
3051 (setq value (or value t))
3052 (while (setq beg (text-property-any (point-min) (point-max)
3055 beg (or (next-single-property-change beg 'org-filtered)
3058 (defun org-agenda-add-entry-text ()
3059 "Add entry text to agenda lines.
3060 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3061 entry text following headings shown in the agenda.
3062 Drawers will be excluded, also the line with scheduling/deadline info."
3063 (when (and (> org-agenda-add-entry-text-maxlines 0)
3064 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3066 (goto-char (point-min))
3068 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3069 (beginning-of-line 2)
3070 (setq txt (org-agenda-get-some-entry-text
3071 m org-agenda-add-entry-text-maxlines " > "))
3073 (if (string-match "\\S-" txt)
3075 (or (eobp) (forward-char 1))))))))
3077 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3079 "Extract entry text from MARKER, at most N-LINES lines.
3080 This will ignore drawers etc, just get the text.
3081 If INDENT is given, prefix every line with this string. If KEEP is
3082 given, it is a list of symbols, defining stuff that should not be
3083 removed from the entry content. Currently only `planning' is allowed here."
3084 (let (txt drawer-re kwd-time-re ind)
3086 (with-current-buffer (marker-buffer marker)
3087 (if (not (eq major-mode 'org-mode))
3094 (setq txt (buffer-substring
3095 (min (1+ (point)) (point-max))
3096 (progn (outline-next-heading) (point)))
3097 drawer-re org-drawer-regexp
3098 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3102 (when org-agenda-add-entry-text-descriptive-links
3103 (goto-char (point-min))
3104 (while (org-activate-bracket-links (point-max))
3105 (add-text-properties (match-beginning 0) (match-end 0)
3107 (goto-char (point-min))
3108 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3109 (set-text-properties (match-beginning 0) (match-end 0)
3111 (goto-char (point-min))
3112 (while (re-search-forward drawer-re nil t)
3115 (progn (re-search-forward
3116 "^[ \t]*:END:.*\n?" nil 'move)
3118 (unless (member 'planning keep)
3119 (goto-char (point-min))
3120 (while (re-search-forward kwd-time-re nil t)
3121 (replace-match "")))
3122 (goto-char (point-min))
3123 (when org-agenda-entry-text-exclude-regexps
3124 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3125 (while (setq re (pop re-list))
3126 (goto-char (point-min))
3127 (while (re-search-forward re nil t)
3128 (replace-match "")))))
3129 (goto-char (point-max))
3130 (skip-chars-backward " \t\n")
3131 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3133 ;; find and remove min common indentation
3134 (goto-char (point-min))
3135 (untabify (point-min) (point-max))
3136 (setq ind (org-get-indentation))
3138 (unless (looking-at "[ \t]*$")
3139 (setq ind (min ind (org-get-indentation))))
3140 (beginning-of-line 2))
3141 (goto-char (point-min))
3143 (unless (looking-at "[ \t]*$")
3144 (move-to-column ind)
3145 (delete-region (point-at-bol) (point)))
3146 (beginning-of-line 2))
3148 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3150 (goto-char (point-min))
3152 (while (and (not (eobp)) (re-search-forward "^" nil t))
3153 (replace-match indent t t)))
3154 (goto-char (point-min))
3155 (while (looking-at "[ \t]*\n") (replace-match ""))
3156 (goto-char (point-max))
3157 (when (> (org-current-line)
3159 (org-goto-line (1+ n-lines))
3161 (setq txt (buffer-substring (point-min) (point)))))))))
3164 (defun org-agenda-collect-markers ()
3165 "Collect the markers pointing to entries in the agenda buffer."
3168 (goto-char (point-min))
3170 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3171 (org-get-at-bol 'org-marker)))
3173 (beginning-of-line 2)))
3174 (nreverse markers)))
3176 (defun org-create-marker-find-array (marker-list)
3177 "Create a alist of files names with all marker positions in that file."
3179 (while (setq m (pop marker-list))
3180 (setq p (marker-position m)
3181 f (buffer-file-name (or (buffer-base-buffer
3183 (marker-buffer m))))
3184 (if (setq a (assoc f tbl))
3185 (push (marker-position m) (cdr a))
3186 (push (list f p) tbl)))
3187 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3190 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3191 (defun org-check-agenda-marker-table ()
3192 "Check of the current entry is on the marker list."
3193 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3195 (and (setq a (assoc file org-agenda-marker-table))
3198 (org-back-to-heading t)
3199 (member (point) (cdr a)))))))
3201 (defun org-check-for-org-mode ()
3202 "Make sure current buffer is in org-mode. Error if not."
3203 (or (eq major-mode 'org-mode)
3204 (error "Cannot execute org-mode agenda command on buffer in %s"
3207 (defun org-fit-agenda-window ()
3208 "Fit the window to the buffer size."
3209 (and (memq org-agenda-window-setup '(reorganize-frame))
3210 (fboundp 'fit-window-to-buffer)
3211 (org-fit-window-to-buffer
3213 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3214 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3216 ;;; Agenda prepare and finalize
3218 (defvar org-agenda-multi nil) ; dynamically scoped
3219 (defvar org-agenda-buffer-name "*Org Agenda*")
3220 (defvar org-pre-agenda-window-conf nil)
3221 (defvar org-agenda-columns-active nil)
3222 (defvar org-agenda-name nil)
3223 (defvar org-agenda-tag-filter nil)
3224 (defvar org-agenda-category-filter nil)
3225 (defvar org-agenda-tag-filter-while-redo nil) ; dynamically scoped
3226 (defvar org-agenda-tag-filter-preset nil
3227 "A preset of the tags filter used for secondary agenda filtering.
3228 This must be a list of strings, each string must be a single tag preceded
3230 This variable should not be set directly, but agenda custom commands can
3231 bind it in the options section. The preset filter is a global property of
3232 the entire agenda view. In a block agenda, it will not work reliably to
3233 define a filter for one of the individual blocks. You need to set it in
3234 the global options and expect it to be applied to the entire view.")
3236 (defvar org-agenda-category-filter-preset nil
3237 "A preset of the category filter used for secondary agenda filtering.
3238 This must be a list of strings, each string must be a single category
3239 preceded by \"+\" or \"-\".
3240 This variable should not be set directly, but agenda custom commands can
3241 bind it in the options section. The preset filter is a global property of
3242 the entire agenda view. In a block agenda, it will not work reliably to
3243 define a filter for one of the individual blocks. You need to set it in
3244 the global options and expect it to be applied to the entire view.")
3247 (defun org-agenda-use-sticky-p ()
3248 "Return non-NIL if existing agenda buffer named
3249 `org-agenda-buffer-name' exists, and should be shown instead of
3250 generating a new one"
3252 ;; turned off by user
3254 ;; For multi-agenda buffer already exists
3255 (not org-agenda-multi)
3257 (get-buffer org-agenda-buffer-name)
3258 ;; C-u parameter is same as last call
3259 (with-current-buffer (get-buffer org-agenda-buffer-name)
3261 (equal current-prefix-arg
3262 org-agenda-last-prefix-arg)
3263 ;; In case user turned stickiness on, while having existing
3264 ;; Agenda buffer active, don't reuse that buffer, because it
3265 ;; does not have org variables local
3266 org-agenda-this-buffer-is-sticky))))
3268 (defun org-prepare-agenda-window (abuf)
3269 "Setup agenda buffer in the window"
3270 (let* ((awin (get-buffer-window abuf))
3273 ((equal (current-buffer) abuf) nil)
3274 (awin (select-window awin))
3275 ((not (setq wconf (current-window-configuration))))
3276 ((equal org-agenda-window-setup 'current-window)
3277 (org-pop-to-buffer-same-window abuf))
3278 ((equal org-agenda-window-setup 'other-window)
3279 (org-switch-to-buffer-other-window abuf))
3280 ((equal org-agenda-window-setup 'other-frame)
3281 (switch-to-buffer-other-frame abuf))
3282 ((equal org-agenda-window-setup 'reorganize-frame)
3283 (delete-other-windows)
3284 (org-switch-to-buffer-other-window abuf)))
3285 ;; additional test in case agenda is invoked from within agenda
3286 ;; buffer via elisp link
3287 (unless (equal (current-buffer) abuf)
3288 (org-pop-to-buffer-same-window abuf))
3289 (setq org-pre-agenda-window-conf wconf)))
3291 (defun org-prepare-agenda (&optional name)
3292 (if (org-agenda-use-sticky-p)
3294 ;; Popup existing buffer
3295 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3296 (message "Sticky Agenda buffer, use `r' to refresh")
3298 (setq org-todo-keywords-for-agenda nil)
3299 (setq org-done-keywords-for-agenda nil)
3300 (setq org-drawers-for-agenda nil)
3301 (unless org-agenda-persistent-filter
3302 (setq org-agenda-tag-filter nil
3303 org-agenda-category-filter nil))
3304 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3305 (put 'org-agenda-category-filter :preset-filter
3306 org-agenda-category-filter-preset)
3307 (if org-agenda-multi
3309 (setq buffer-read-only nil)
3310 (goto-char (point-max))
3311 (unless (or (bobp) org-agenda-compact-blocks
3312 (not org-agenda-block-separator))
3314 (if (stringp org-agenda-block-separator)
3315 org-agenda-block-separator
3316 (make-string (window-width) org-agenda-block-separator))
3318 (narrow-to-region (point) (point-max)))
3320 ;; any org variables need to be set after being in agenda buffer
3321 ;; since they are now buffer local
3322 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3323 (setq buffer-read-only nil)
3324 (org-agenda-reset-markers)
3325 (let ((inhibit-read-only t)) (erase-buffer))
3327 (setq org-agenda-buffer (current-buffer))
3328 (setq org-agenda-contributing-files nil)
3329 (setq org-agenda-columns-active nil)
3330 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3331 (setq org-todo-keywords-for-agenda
3332 (org-uniquify org-todo-keywords-for-agenda))
3333 (setq org-done-keywords-for-agenda
3334 (org-uniquify org-done-keywords-for-agenda))
3335 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3336 (setq org-agenda-last-prefix-arg current-prefix-arg)
3337 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3338 (and name (not org-agenda-name)
3339 (org-set-local 'org-agenda-name name)))
3340 (setq buffer-read-only nil)))
3342 (defun org-finalize-agenda ()
3343 "Finishing touch for the agenda buffer, called just before displaying it."
3344 (unless org-agenda-multi
3346 (let ((inhibit-read-only t))
3347 (goto-char (point-min))
3348 (while (org-activate-bracket-links (point-max))
3349 (add-text-properties (match-beginning 0) (match-end 0)
3351 (org-agenda-align-tags)
3352 (unless org-agenda-with-colors
3353 (remove-text-properties (point-min) (point-max) '(face nil))))
3354 (if (and (boundp 'org-agenda-overriding-columns-format)
3355 org-agenda-overriding-columns-format)
3356 (org-set-local 'org-agenda-overriding-columns-format
3357 org-agenda-overriding-columns-format))
3358 (if (and (boundp 'org-agenda-view-columns-initially)
3359 org-agenda-view-columns-initially)
3360 (org-agenda-columns))
3361 (when org-agenda-fontify-priorities
3362 (org-agenda-fontify-priorities))
3363 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3364 (org-agenda-dim-blocked-tasks))
3365 (org-agenda-mark-clocking-task)
3366 (when org-agenda-entry-text-mode
3367 (org-agenda-entry-text-hide)
3368 (org-agenda-entry-text-show))
3369 (if (functionp 'org-habit-insert-consistency-graphs)
3370 (org-habit-insert-consistency-graphs))
3371 (run-hooks 'org-finalize-agenda-hook)
3372 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3373 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3374 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3375 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3376 (org-agenda-filter-apply org-agenda-category-filter 'category))
3377 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3380 (defun org-agenda-mark-clocking-task ()
3381 "Mark the current clock entry in the agenda if it is present."
3383 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3384 (delete-overlay o)))
3385 (overlays-in (point-min) (point-max)))
3386 (when (marker-buffer org-clock-hd-marker)
3388 (goto-char (point-min))
3390 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3392 (when (equal (org-get-at-bol 'org-hd-marker)
3393 org-clock-hd-marker)
3394 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3395 (overlay-put ov 'type 'org-agenda-clocking)
3396 (overlay-put ov 'face 'org-agenda-clocking)
3397 (overlay-put ov 'help-echo
3398 "The clock is running in this item")))))))
3400 (defun org-agenda-fontify-priorities ()
3401 "Make highest priority lines bold, and lowest italic."
3403 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3404 (delete-overlay o)))
3405 (overlays-in (point-min) (point-max)))
3407 (let ((inhibit-read-only t)
3409 (goto-char (point-min))
3410 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3411 (setq h (or (get-char-property (point) 'org-highest-priority)
3412 org-highest-priority)
3413 l (or (get-char-property (point) 'org-lowest-priority)
3414 org-lowest-priority)
3415 p (string-to-char (match-string 1))
3416 b (match-beginning 0)
3417 e (if (eq org-agenda-fontify-priorities 'cookies)
3420 ov (make-overlay b e))
3423 (cond ((org-face-from-face-or-color
3425 (cdr (assoc p org-priority-faces))))
3426 ((and (listp org-agenda-fontify-priorities)
3427 (org-face-from-face-or-color
3429 (cdr (assoc p org-agenda-fontify-priorities)))))
3430 ((equal p l) 'italic)
3431 ((equal p h) 'bold)))
3432 (overlay-put ov 'org-type 'org-priority)))))
3434 (defun org-agenda-dim-blocked-tasks ()
3435 "Dim currently blocked TODO's in the agenda display."
3436 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3437 (delete-overlay o)))
3438 (overlays-in (point-min) (point-max)))
3440 (let ((inhibit-read-only t)
3441 (org-depend-tag-blocked nil)
3442 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3443 org-blocked-by-checkboxes
3444 invis1 b e p ov h l)
3445 (goto-char (point-min))
3446 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3447 (and pos (goto-char (1+ pos))))
3448 (setq org-blocked-by-checkboxes nil invis1 invis)
3449 (let ((marker (org-get-at-bol 'org-hd-marker)))
3451 (with-current-buffer (marker-buffer marker)
3452 (save-excursion (goto-char marker)
3453 (org-entry-blocked-p))))
3454 (if org-blocked-by-checkboxes (setq invis1 nil))
3456 (max (point-min) (1- (point-at-bol)))
3459 ov (make-overlay b e))
3461 (overlay-put ov 'invisible t)
3462 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3463 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3465 (defvar org-agenda-skip-function nil
3466 "Function to be called at each match during agenda construction.
3467 If this function returns nil, the current match should not be skipped.
3468 Otherwise, the function must return a position from where the search
3469 should be continued.
3470 This may also be a Lisp form, it will be evaluated.
3471 Never set this variable using `setq' or so, because then it will apply
3472 to all future agenda commands. If you do want a global skipping condition,
3473 use the option `org-agenda-skip-function-global' instead.
3474 The correct usage for `org-agenda-skip-function' is to bind it with
3475 `let' to scope it dynamically into the agenda-constructing command.
3476 A good way to set it is through options in `org-agenda-custom-commands'.")
3478 (defun org-agenda-skip ()
3479 "Throw to `:skip' in places that should be skipped.
3480 Also moves point to the end of the skipped region, so that search can
3481 continue from there."
3482 (let ((p (point-at-bol)) to)
3483 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3484 (get-text-property p :org-archived)
3485 (org-end-of-subtree t)
3487 (and org-agenda-skip-comment-trees
3488 (get-text-property p :org-comment)
3489 (org-end-of-subtree t)
3491 (if (equal (char-after p) ?#) (throw :skip t))
3492 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3493 (org-agenda-skip-eval org-agenda-skip-function)))
3497 (defun org-agenda-skip-eval (form)
3498 "If FORM is a function or a list, call (or eval) is and return result.
3499 `save-excursion' and `save-match-data' are wrapped around the call, so point
3500 and match data are returned to the previous state no matter what these
3504 (or (setq fp (functionp form))
3512 (defvar org-agenda-markers nil
3513 "List of all currently active markers created by `org-agenda'.")
3514 (defvar org-agenda-last-marker-time (org-float-time)
3515 "Creation time of the last agenda marker.")
3517 (defun org-agenda-new-marker (&optional pos)
3518 "Return a new agenda marker.
3519 Org-mode keeps a list of these markers and resets them when they are
3521 (let ((m (copy-marker (or pos (point)))))
3522 (setq org-agenda-last-marker-time (org-float-time))
3523 (with-current-buffer org-agenda-buffer
3524 (push m org-agenda-markers))
3527 (defun org-agenda-reset-markers ()
3528 "Reset markers created by `org-agenda'."
3529 (while org-agenda-markers
3530 (move-marker (pop org-agenda-markers) nil)))
3532 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3533 "Save relative positions of markers in region.
3534 This check for agenda markers in all agenda buffers currently active."
3535 (dolist (buf (buffer-list))
3536 (with-current-buffer buf
3537 (when (eq major-mode 'org-agenda-mode)
3538 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3539 org-agenda-markers)))))
3543 (defun org-agenda-entry-text-show-here ()
3544 "Add some text from the entry as context to the current line."
3546 (setq m (org-get-at-bol 'org-hd-marker))
3547 (unless (marker-buffer m)
3548 (error "No marker points to an entry here"))
3549 (setq txt (concat "\n" (org-no-properties
3550 (org-agenda-get-some-entry-text
3551 m org-agenda-entry-text-maxlines " > "))))
3552 (when (string-match "\\S-" txt)
3553 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3554 (overlay-put o 'evaporate t)
3555 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3556 (overlay-put o 'after-string txt))))
3558 (defun org-agenda-entry-text-show ()
3559 "Add entry context for all agenda lines."
3562 (goto-char (point-max))
3563 (beginning-of-line 1)
3565 (when (org-get-at-bol 'org-hd-marker)
3566 (org-agenda-entry-text-show-here))
3567 (beginning-of-line 0))))
3569 (defun org-agenda-entry-text-hide ()
3570 "Remove any shown entry context."
3573 (if (eq (overlay-get o 'org-overlay-type)
3574 'agenda-entry-content)
3575 (progn (delete-overlay o) t)))
3576 (overlays-in (point-min) (point-max)))))
3578 (defun org-agenda-get-day-face (date)
3579 "Return the face DATE should be displayed with."
3580 (or (and (functionp org-agenda-day-face-function)
3581 (funcall org-agenda-day-face-function date))
3582 (cond ((org-agenda-todayp date)
3583 'org-agenda-date-today)
3584 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3585 'org-agenda-date-weekend)
3586 (t 'org-agenda-date))))
3590 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3592 (defun org-timeline (&optional dotodo)
3593 "Show a time-sorted view of the entries in the current org file.
3594 Only entries with a time stamp of today or later will be listed. With
3595 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3596 under the current date.
3597 If the buffer contains an active region, only check the region for
3601 (org-agenda-show-log-scoped org-agenda-show-log)
3602 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3604 (date (calendar-current-date))
3605 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3606 (end (if (org-region-active-p) (region-end) (point-max)))
3607 (day-numbers (org-get-all-dates
3609 t org-agenda-show-log-scoped ; always include today
3610 org-timeline-show-empty-dates))
3611 (org-deadline-warning-days 0)
3612 (org-agenda-only-exact-dates t)
3617 (setq org-agenda-redo-command
3619 (list 'org-switch-to-buffer-other-window (current-buffer))
3620 (list 'org-timeline (list 'quote dotodo))))
3622 ;; Remove past dates from the list of dates.
3623 (setq day-numbers (delq nil (mapcar (lambda(x)
3624 (if (>= x today) x nil))
3626 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3627 (org-compile-prefix-format 'timeline)
3628 (org-set-sorting-strategy 'timeline)
3629 (if org-agenda-show-log-scoped (push :closed args))
3630 (push :timestamp args)
3631 (push :deadline args)
3632 (push :scheduled args)
3634 (if dotodo (push :todo args))
3635 (insert "Timeline of file " entry "\n")
3636 (add-text-properties (point-min) (point)
3637 (list 'face 'org-agenda-structure))
3638 (org-agenda-mark-header-line (point-min))
3639 (while (setq d (pop day-numbers))
3640 (if (and (listp d) (eq (car d) :omitted))
3643 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3644 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3645 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3646 (if (and (>= d today)
3651 (insert (make-string 79 ?-) "\n")))
3652 (setq date (calendar-gregorian-from-absolute d))
3654 (setq rtn (and (not emptyp)
3655 (apply 'org-agenda-get-day-entries entry
3657 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3660 (if (stringp org-agenda-format-date)
3661 (format-time-string org-agenda-format-date
3662 (org-time-from-absolute date))
3663 (funcall org-agenda-format-date date))
3665 (put-text-property s (1- (point)) 'face
3666 (org-agenda-get-day-face date))
3667 (put-text-property s (1- (point)) 'org-date-line t)
3668 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3670 (put-text-property s (1- (point)) 'org-today t))
3671 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3672 (put-text-property s (1- (point)) 'day d)))))
3673 (goto-char (point-min))
3674 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3676 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3677 (org-finalize-agenda)
3678 (setq buffer-read-only t)))
3680 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3681 "Return a list of all relevant day numbers from BEG to END buffer positions.
3682 If NO-RANGES is non-nil, include only the start and end dates of a range,
3683 not every single day in the range. If FORCE-TODAY is non-nil, make
3684 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3685 inactive time stamps (those in square brackets) are included.
3686 When EMPTY is non-nil, also include days without any entries."
3688 (if pre-re pre-re "")
3689 (if inactive org-ts-regexp-both org-ts-regexp)))
3690 dates dates1 date day day1 day2 ts1 ts2 pos)
3692 (setq dates (list (org-today))))
3695 (while (re-search-forward re end t)
3696 (setq day (time-to-days (org-time-string-to-time
3697 (substring (match-string 1) 0 10)
3698 (current-buffer) (match-beginning 0))))
3699 (or (memq day dates) (push day dates)))
3702 (while (re-search-forward org-tr-regexp end t)
3703 (setq pos (match-beginning 0))
3704 (setq ts1 (substring (match-string 1) 0 10)
3705 ts2 (substring (match-string 2) 0 10)
3706 day1 (time-to-days (org-time-string-to-time
3707 ts1 (current-buffer) pos))
3708 day2 (time-to-days (org-time-string-to-time
3709 ts2 (current-buffer) pos)))
3710 (while (< (setq day1 (1+ day1)) day2)
3711 (or (memq day1 dates) (push day1 dates)))))
3712 (setq dates (sort dates '<))
3714 (while (setq day (pop dates))
3715 (setq day2 (car dates))
3717 (when (and day2 empty)
3718 (if (or (eq empty t)
3719 (and (numberp empty) (<= (- day2 day) empty)))
3720 (while (< (setq day (1+ day)) day2)
3721 (push (list day) dates1))
3722 (push (cons :omitted (- day2 day)) dates1))))
3723 (setq dates (nreverse dates1)))
3726 ;;; Agenda Daily/Weekly
3728 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3729 "Start day for the agenda view.
3730 Custom commands can set this variable in the options section.")
3731 (defvar org-starting-day nil) ; local variable in the agenda buffer
3732 (defvar org-agenda-current-span nil
3733 "The current span used in the agenda view.") ; local variable in the agenda buffer
3734 (defvar org-arg-loc nil) ; local variable
3736 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3737 "List of types searched for when creating the daily/weekly agenda.
3738 This variable is a list of symbols that controls the types of
3739 items that appear in the daily/weekly agenda. Allowed symbols in this
3742 :timestamp List items containing a date stamp or date range matching
3743 the selected date. This includes sexp entries in
3746 :sexp List entries resulting from plain diary-like sexps.
3748 :deadline List deadline due on that date. When the date is today,
3749 also list any deadlines past due, or due within
3750 `org-deadline-warning-days'. `:deadline' must appear before
3751 `:scheduled' if the setting of
3752 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3755 :scheduled List all items which are scheduled for the given date.
3756 The diary for *today* also contains items which were
3757 scheduled earlier and are not yet marked DONE.
3759 By default, all four types are turned on.
3761 Never set this variable globally using `setq', because then it
3762 will apply to all future agenda commands. Instead, bind it with
3763 `let' to scope it dynamically into the agenda-constructing
3764 command. A good way to set it is through options in
3765 `org-agenda-custom-commands'. For a more flexible (though
3766 somewhat less efficient) way of determining what is included in
3767 the daily/weekly agenda, see `org-agenda-skip-function'.")
3770 (defun org-agenda-list (&optional arg start-day span)
3771 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3772 The view will be for the current day or week, but from the overview buffer
3773 you will be able to go to other days/weeks.
3775 With a numeric prefix argument in an interactive call, the agenda will
3776 span ARG days. Lisp programs should instead specify SPAN to change
3777 the number of days. SPAN defaults to `org-agenda-span'.
3779 START-DAY defaults to TODAY, or to the most recent match for the weekday
3780 given in `org-agenda-start-on-weekday'."
3782 (if (and (integerp arg) (> arg 0))
3783 (setq span arg arg nil))
3784 (org-prepare-agenda "Day/Week")
3785 (setq start-day (or start-day org-agenda-start-day))
3786 (if org-agenda-overriding-arguments
3787 (setq arg (car org-agenda-overriding-arguments)
3788 start-day (nth 1 org-agenda-overriding-arguments)
3789 span (nth 2 org-agenda-overriding-arguments)))
3790 (if (stringp start-day)
3791 ;; Convert to an absolute day number
3792 (setq start-day (time-to-days (org-read-date nil t start-day))))
3793 (setq org-agenda-last-arguments (list arg start-day span))
3794 (org-compile-prefix-format 'agenda)
3795 (org-set-sorting-strategy 'agenda)
3796 (let* ((span (org-agenda-ndays-to-span
3797 (or span org-agenda-ndays org-agenda-span)))
3799 (sd (or start-day today))
3800 (ndays (org-agenda-span-to-ndays span sd))
3801 (org-agenda-start-on-weekday
3803 org-agenda-start-on-weekday))
3804 (thefiles (org-agenda-files nil 'ifmode))
3806 (start (if (or (null org-agenda-start-on-weekday)
3809 (let* ((nt (calendar-day-of-week
3810 (calendar-gregorian-from-absolute sd)))
3811 (n1 org-agenda-start-on-weekday)
3813 (- sd (+ (if (< d 0) 7 0) d)))))
3814 (day-numbers (list start))
3816 (inhibit-redisplay (not debug-on-error))
3817 (org-agenda-show-log-scoped org-agenda-show-log)
3818 s e rtn rtnall file date d start-pos end-pos todayp
3819 clocktable-start clocktable-end filter)
3820 (setq org-agenda-redo-command
3821 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3822 (dotimes (n (1- ndays))
3823 (push (1+ (car day-numbers)) day-numbers))
3824 (setq day-numbers (nreverse day-numbers))
3825 (setq clocktable-start (car day-numbers)
3826 clocktable-end (1+ (or (org-last day-numbers) 0)))
3827 (org-set-local 'org-starting-day (car day-numbers))
3828 (org-set-local 'org-arg-loc arg)
3829 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3830 (unless org-agenda-compact-blocks
3831 (let* ((d1 (car day-numbers))
3832 (d2 (org-last day-numbers))
3833 (w1 (org-days-to-iso-week d1))
3834 (w2 (org-days-to-iso-week d2)))
3836 (if org-agenda-overriding-header
3837 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3838 nil 'face 'org-agenda-structure) "\n")
3839 (insert (org-agenda-span-name span)
3841 (if (< (- d2 d1) 350)
3843 (format " (W%02d)" w1)
3844 (format " (W%02d-W%02d)" w1 w2))
3847 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3849 (org-agenda-mark-header-line s))
3850 (while (setq d (pop day-numbers))
3851 (setq date (calendar-gregorian-from-absolute d)
3853 (if (or (setq todayp (= d today))
3854 (and (not start-pos) (= d sd)))
3855 (setq start-pos (point))
3856 (if (and start-pos (not end-pos))
3857 (setq end-pos (point))))
3858 (setq files thefiles
3860 (while (setq file (pop files))
3862 (org-check-agenda-file file)
3863 (let ((org-agenda-entry-types org-agenda-entry-types))
3864 (unless org-agenda-include-deadlines
3865 (setq org-agenda-entry-types
3866 (delq :deadline org-agenda-entry-types)))
3868 ((memq org-agenda-show-log-scoped '(only clockcheck))
3869 (setq rtn (org-agenda-get-day-entries
3870 file date :closed)))
3871 (org-agenda-show-log-scoped
3872 (setq rtn (apply 'org-agenda-get-day-entries
3874 (append '(:closed) org-agenda-entry-types))))
3876 (setq rtn (apply 'org-agenda-get-day-entries
3878 org-agenda-entry-types)))))
3879 (setq rtnall (append rtnall rtn)))) ;; all entries
3880 (if org-agenda-include-diary
3881 (let ((org-agenda-search-headline-for-time t))
3882 (require 'diary-lib)
3883 (setq rtn (org-get-entries-from-diary date))
3884 (setq rtnall (append rtnall rtn))))
3885 (if (or rtnall org-agenda-show-all-dates)
3887 (setq day-cnt (1+ day-cnt))
3889 (if (stringp org-agenda-format-date)
3890 (format-time-string org-agenda-format-date
3891 (org-time-from-absolute date))
3892 (funcall org-agenda-format-date date))
3894 (put-text-property s (1- (point)) 'face
3895 (org-agenda-get-day-face date))
3896 (put-text-property s (1- (point)) 'org-date-line t)
3897 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3898 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3900 (put-text-property s (1- (point)) 'org-today t))
3901 (if rtnall (insert ;; all entries
3902 (org-finalize-agenda-entries
3903 (org-agenda-add-time-grid-maybe
3904 rtnall ndays todayp))
3906 (put-text-property s (1- (point)) 'day d)
3907 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3908 (when (and org-agenda-clockreport-mode clocktable-start)
3909 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3910 ;; the above line is to ensure the restricted range!
3911 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3913 (setq p (org-plist-delete p :block))
3914 (setq p (plist-put p :tstart clocktable-start))
3915 (setq p (plist-put p :tend clocktable-end))
3916 (setq p (plist-put p :scope 'agenda))
3917 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3918 (setq filter (or org-agenda-tag-filter-while-redo
3919 (get 'org-agenda-tag-filter :preset-filter))))
3920 (setq p (plist-put p :tags (mapconcat (lambda (x)
3921 (if (string-match "[<>=]" x)
3925 (setq tbl (apply 'org-get-clocktable p))
3927 (goto-char (point-min))
3928 (or org-agenda-multi (org-fit-agenda-window))
3929 (unless (and (pos-visible-in-window-p (point-min))
3930 (pos-visible-in-window-p (point-max)))
3931 (goto-char (1- (point-max)))
3933 (if (not (pos-visible-in-window-p (or start-pos 1)))
3935 (goto-char (or start-pos 1))
3937 (goto-char (or start-pos 1))
3938 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3939 (if (eq org-agenda-show-log-scoped 'clockcheck)
3940 (org-agenda-show-clocking-issues))
3941 (org-finalize-agenda)
3942 (setq buffer-read-only t)
3945 (defun org-agenda-ndays-to-span (n)
3946 "Return a span symbol for a span of N days, or N if none matches."
3947 (cond ((symbolp n) n)
3952 (defun org-agenda-span-to-ndays (span start-day)
3953 "Return ndays from SPAN starting at START-DAY."
3954 (cond ((numberp span) span)
3958 (let ((date (calendar-gregorian-from-absolute start-day)))
3959 (calendar-last-day-of-month (car date) (caddr date))))
3961 (let ((date (calendar-gregorian-from-absolute start-day)))
3962 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3964 (defun org-agenda-span-name (span)
3965 "Return a SPAN name."
3969 (capitalize (symbol-name span))
3970 (format "%d days" span))))
3972 ;;; Agenda word search
3974 (defvar org-agenda-search-history nil)
3975 (defvar org-todo-only nil)
3977 (defvar org-search-syntax-table nil
3978 "Special syntax table for org-mode search.
3979 In this table, we have single quotes not as word constituents, to
3980 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3982 (defun org-search-syntax-table ()
3983 (unless org-search-syntax-table
3984 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3985 (modify-syntax-entry ?' "." org-search-syntax-table)
3986 (modify-syntax-entry ?` "." org-search-syntax-table))
3987 org-search-syntax-table)
3989 (defvar org-agenda-last-search-view-search-was-boolean nil)
3992 (defun org-search-view (&optional todo-only string edit-at)
3993 "Show all entries that contain a phrase or words or regular expressions.
3995 With optional prefix argument TODO-ONLY, only consider entries that are
3996 TODO entries. The argument STRING can be used to pass a default search
3997 string into this function. If EDIT-AT is non-nil, it means that the
3998 user should get a chance to edit this string, with cursor at position
4001 The search string can be viewed either as a phrase that should be found as
4002 is, or it can be broken into a number of snippets, each of which must match
4003 in a Boolean way to select an entry. The default depends on the variable
4004 `org-agenda-search-view-always-boolean'.
4005 Even if this is turned off (the default) you can always switch to
4006 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4008 The default is a direct search of the whole phrase, where each space in
4009 the search string can expand to an arbitrary amount of whitespace,
4012 If using a Boolean search, the search string is split on whitespace and
4013 each snippet is searched separately, with logical AND to select an entry.
4014 Words prefixed with a minus must *not* occur in the entry. Words without
4015 a prefix or prefixed with a plus must occur in the entry. Matching is
4016 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4017 match whole words, not parts of a word) if
4018 `org-agenda-search-view-force-full-words' is set (default is nil).
4020 Boolean search snippets enclosed by curly braces are interpreted as
4021 regular expressions that must or (when preceded with \"-\") must not
4022 match in the entry. Snippets enclosed into double quotes will be taken
4023 as a whole, to include whitespace.
4025 - If the search string starts with an asterisk, search only in headlines.
4026 - If (possibly after the leading star) the search string starts with an
4027 exclamation mark, this also means to look at TODO entries only, an effect
4028 that can also be achieved with a prefix argument.
4029 - If (possibly after star and exclamation mark) the search string starts
4030 with a colon, this will mean that the (non-regexp) snippets of the
4031 Boolean search must match as full words.
4033 This command searches the agenda files, and in addition the files listed
4034 in `org-agenda-text-search-extra-files'."
4036 (org-prepare-agenda "SEARCH")
4037 (org-compile-prefix-format 'search)
4038 (org-set-sorting-strategy 'search)
4039 (let* ((props (list 'face nil
4040 'done-face 'org-agenda-done
4041 'org-not-done-regexp org-not-done-regexp
4042 'org-todo-regexp org-todo-regexp
4043 'org-complex-heading-regexp org-complex-heading-regexp
4044 'mouse-face 'highlight
4045 'help-echo (format "mouse-2 or RET jump to location")))
4046 (full-words org-agenda-search-view-force-full-words)
4047 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4048 regexp rtn rtnall files file pos
4049 marker category org-category-pos tags c neg re boolean
4050 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4051 (unless (and (not edit-at)
4053 (string-match "\\S-" string))
4054 (setq string (read-string
4055 (if org-agenda-search-view-always-boolean
4056 "[+-]Word/{Regexp} ...: "
4057 "Phrase, or [+-]Word/{Regexp} ...: ")
4059 ((integerp edit-at) (cons string edit-at))
4061 'org-agenda-search-history)))
4062 (org-set-local 'org-todo-only todo-only)
4063 (setq org-agenda-redo-command
4064 (list 'org-search-view (if todo-only t nil) string
4065 '(if current-prefix-arg 1 nil)))
4066 (setq org-agenda-query-string string)
4068 (if (equal (string-to-char string) ?*)
4070 words (substring string 1))
4071 (setq words string))
4072 (when (equal (string-to-char words) ?!)
4074 words (substring words 1)))
4075 (when (equal (string-to-char words) ?:)
4077 words (substring words 1)))
4078 (if (or org-agenda-search-view-always-boolean
4079 (member (string-to-char words) '(?- ?+ ?\{)))
4081 (setq words (org-split-string words))
4083 (while (setq w (pop words))
4084 (while (and (string-match "\\\\\\'" w) words)
4085 (setq w (concat (substring w 0 -1) " " (pop words))))
4087 (setq words (nreverse www) www nil)
4088 (while (setq w (pop words))
4089 (when (and (string-match "\\`[-+]?{" w)
4090 (not (string-match "}\\'" w)))
4091 (while (and words (not (string-match "}\\'" (car words))))
4092 (setq w (concat w " " (pop words))))
4093 (setq w (concat w " " (pop words))))
4095 (setq words (nreverse www)))
4096 (setq org-agenda-last-search-view-search-was-boolean boolean)
4099 (while (setq w (pop words))
4100 (if (or (equal (substring w 0 1) "\"")
4101 (and (> (length w) 1)
4102 (member (substring w 0 1) '("+" "-"))
4103 (equal (substring w 1 2) "\"")))
4104 (while (and words (not (equal (substring w -1) "\"")))
4105 (setq w (concat w " " (pop words)))))
4106 (and (string-match "\\`\\([-+]?\\)\"" w)
4107 (setq w (replace-match "\\1" nil nil w)))
4108 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4110 (setq words (nreverse wds))))
4113 (setq c (string-to-char w))
4115 (setq neg t w (substring w 1))
4117 (setq neg nil w (substring w 1))
4119 (if (string-match "\\`{.*}\\'" w)
4120 (setq re (substring w 1 -1))
4122 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4123 (setq re (regexp-quote (downcase w)))))
4124 (if neg (push re regexps-) (push re regexps+)))
4126 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4128 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4130 (setq regexp org-outline-regexp-bol)
4131 (setq regexp (pop regexps+))
4132 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4134 (setq files (org-agenda-files nil 'ifmode))
4135 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4136 (pop org-agenda-text-search-extra-files)
4137 (setq files (org-add-archive-files files)))
4138 (setq files (append files org-agenda-text-search-extra-files)
4140 (while (setq file (pop files))
4143 (org-check-agenda-file file)
4144 (setq buffer (if (file-exists-p file)
4145 (org-get-agenda-file-buffer file)
4146 (error "No such file %s" file)))
4148 ;; If file does not exist, make sure an error message is sent
4149 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4151 (with-current-buffer buffer
4152 (with-syntax-table (org-search-syntax-table)
4153 (unless (eq major-mode 'org-mode)
4154 (error "Agenda file %s is not in `org-mode'" file))
4155 (let ((case-fold-search t))
4158 (if org-agenda-restrict
4159 (narrow-to-region org-agenda-restrict-begin
4160 org-agenda-restrict-end)
4162 (goto-char (point-min))
4163 (unless (or (org-at-heading-p)
4164 (outline-next-heading))
4165 (throw 'nextfile t))
4166 (goto-char (max (point-min) (1- (point))))
4167 (while (re-search-forward regexp nil t)
4168 (org-back-to-heading t)
4169 (skip-chars-forward "* ")
4170 (setq beg (point-at-bol)
4172 end (progn (outline-next-heading) (point)))
4176 (setq str (buffer-substring-no-properties
4178 (if hdl-only (point-at-eol) end)))
4179 (mapc (lambda (wr) (when (string-match wr str)
4180 (goto-char (1- end))
4183 (mapc (lambda (wr) (unless (string-match wr str)
4184 (goto-char (1- end))
4187 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4191 (setq marker (org-agenda-new-marker (point))
4192 category (org-get-category)
4193 org-category-pos (get-text-property (point) 'org-category-position)
4194 tags (org-get-tags-at (point))
4195 txt (org-agenda-format-item
4197 (buffer-substring-no-properties
4198 beg1 (point-at-eol))
4200 (org-add-props txt props
4201 'org-marker marker 'org-hd-marker marker
4202 'org-todo-regexp org-todo-regexp
4203 'org-complex-heading-regexp org-complex-heading-regexp
4204 'priority 1000 'org-category category
4205 'org-category-position org-category-pos
4208 (goto-char (1- end))))))))))
4209 (setq rtn (nreverse ee))
4210 (setq rtnall (append rtnall rtn)))
4211 (if org-agenda-overriding-header
4212 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4213 nil 'face 'org-agenda-structure) "\n")
4214 (insert "Search words: ")
4215 (add-text-properties (point-min) (1- (point))
4216 (list 'face 'org-agenda-structure))
4218 (insert string "\n")
4219 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4221 (unless org-agenda-multi
4222 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4223 (add-text-properties pos (1- (point))
4224 (list 'face 'org-agenda-structure))))
4225 (org-agenda-mark-header-line (point-min))
4227 (insert (org-finalize-agenda-entries rtnall) "\n"))
4228 (goto-char (point-min))
4229 (or org-agenda-multi (org-fit-agenda-window))
4230 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4231 (org-finalize-agenda)
4232 (setq buffer-read-only t)))
4234 ;;; Agenda TODO list
4236 (defvar org-select-this-todo-keyword nil)
4237 (defvar org-last-arg nil)
4240 (defun org-todo-list (arg)
4241 "Show all (not done) TODO entries from all agenda file in a single list.
4242 The prefix arg can be used to select a specific TODO keyword and limit
4243 the list to these. When using \\[universal-argument], you will be prompted
4244 for a keyword. A numeric prefix directly selects the Nth keyword in
4245 `org-todo-keywords-1'."
4247 (org-prepare-agenda "TODO")
4248 (org-compile-prefix-format 'todo)
4249 (org-set-sorting-strategy 'todo)
4250 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4251 (let* ((today (org-today))
4252 (date (calendar-gregorian-from-absolute today))
4253 (kwds org-todo-keywords-for-agenda)
4254 (completion-ignore-case t)
4255 (org-select-this-todo-keyword
4256 (if (stringp arg) arg
4257 (and arg (integerp arg) (> arg 0)
4258 (nth (1- arg) kwds))))
4259 rtn rtnall files file pos)
4260 (when (equal arg '(4))
4261 (setq org-select-this-todo-keyword
4262 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4263 (mapcar 'list kwds) nil nil)))
4264 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4265 (org-set-local 'org-last-arg arg)
4266 (setq org-agenda-redo-command
4267 '(org-todo-list (or current-prefix-arg org-last-arg)))
4268 (setq files (org-agenda-files nil 'ifmode)
4270 (while (setq file (pop files))
4272 (org-check-agenda-file file)
4273 (setq rtn (org-agenda-get-day-entries file date :todo))
4274 (setq rtnall (append rtnall rtn))))
4275 (if org-agenda-overriding-header
4276 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4277 nil 'face 'org-agenda-structure) "\n")
4278 (insert "Global list of TODO items of type: ")
4279 (add-text-properties (point-min) (1- (point))
4280 (list 'face 'org-agenda-structure
4283 (or org-select-this-todo-keyword "ALL"))))
4284 (org-agenda-mark-header-line (point-min))
4286 (insert (or org-select-this-todo-keyword "ALL") "\n")
4287 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4289 (unless org-agenda-multi
4290 (insert "Available with `N r': (0)ALL")
4293 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4294 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4299 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4300 (org-agenda-mark-header-line (point-min))
4302 (insert (org-finalize-agenda-entries rtnall) "\n"))
4303 (goto-char (point-min))
4304 (or org-agenda-multi (org-fit-agenda-window))
4305 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4306 (org-finalize-agenda)
4307 (setq buffer-read-only t)))
4309 ;;; Agenda tags match
4312 (defun org-tags-view (&optional todo-only match)
4313 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4314 The prefix arg TODO-ONLY limits the search to TODO entries."
4316 (let* ((org-tags-match-list-sublevels
4317 org-tags-match-list-sublevels)
4318 (completion-ignore-case t)
4319 rtn rtnall files file pos matcher
4321 (when (and (stringp match) (not (string-match "\\S-" match)))
4323 (setq matcher (org-make-tags-matcher match)
4324 match (car matcher) matcher (cdr matcher))
4325 (org-prepare-agenda (concat "TAGS " match))
4326 (org-compile-prefix-format 'tags)
4327 (org-set-sorting-strategy 'tags)
4328 (setq org-agenda-query-string match)
4329 (setq org-agenda-redo-command
4330 (list 'org-tags-view (list 'quote todo-only)
4331 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4332 (setq files (org-agenda-files nil 'ifmode)
4334 (while (setq file (pop files))
4336 (org-check-agenda-file file)
4337 (setq buffer (if (file-exists-p file)
4338 (org-get-agenda-file-buffer file)
4339 (error "No such file %s" file)))
4341 ;; If file does not exist, error message to agenda
4343 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4344 rtnall (append rtnall rtn))
4345 (with-current-buffer buffer
4346 (unless (eq major-mode 'org-mode)
4347 (error "Agenda file %s is not in `org-mode'" file))
4350 (if org-agenda-restrict
4351 (narrow-to-region org-agenda-restrict-begin
4352 org-agenda-restrict-end)
4354 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4355 (setq rtnall (append rtnall rtn))))))))
4356 (if org-agenda-overriding-header
4357 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4358 nil 'face 'org-agenda-structure) "\n")
4359 (insert "Headlines with TAGS match: ")
4360 (add-text-properties (point-min) (1- (point))
4361 (list 'face 'org-agenda-structure
4363 (concat "Match: " match)))
4366 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4368 (unless org-agenda-multi
4369 (insert "Press `C-u r' to search again with new search string\n"))
4370 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4371 (org-agenda-mark-header-line (point-min))
4373 (insert (org-finalize-agenda-entries rtnall) "\n"))
4374 (goto-char (point-min))
4375 (or org-agenda-multi (org-fit-agenda-window))
4376 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4377 (org-finalize-agenda)
4378 (setq buffer-read-only t)))
4380 ;;; Agenda Finding stuck projects
4382 (defvar org-agenda-skip-regexp nil
4383 "Regular expression used in skipping subtrees for the agenda.
4384 This is basically a temporary global variable that can be set and then
4385 used by user-defined selections using `org-agenda-skip-function'.")
4387 (defvar org-agenda-overriding-header nil
4388 "When set during agenda, todo and tags searches it replaces the header.
4389 This variable should not be set directly, but custom commands can bind it
4390 in the options section.")
4392 (defun org-agenda-skip-entry-when-regexp-matches ()
4393 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4394 If yes, it returns the end position of this entry, causing agenda commands
4395 to skip the entry but continuing the search in the subtree. This is a
4396 function that can be put into `org-agenda-skip-function' for the duration
4398 (let ((end (save-excursion (org-end-of-subtree t)))
4401 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4404 (defun org-agenda-skip-subtree-when-regexp-matches ()
4405 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4406 If yes, it returns the end position of this tree, causing agenda commands
4407 to skip this subtree. This is a function that can be put into
4408 `org-agenda-skip-function' for the duration of a command."
4409 (let ((end (save-excursion (org-end-of-subtree t)))
4412 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4415 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4416 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4417 If yes, it returns the end position of the current entry (NOT the tree),
4418 causing agenda commands to skip the entry but continuing the search in
4419 the subtree. This is a function that can be put into
4420 `org-agenda-skip-function' for the duration of a command. An important
4421 use of this function is for the stuck project list."
4422 (let ((end (save-excursion (org-end-of-subtree t)))
4423 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4426 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4427 (and skip entry-end)))
4429 (defun org-agenda-skip-entry-if (&rest conditions)
4430 "Skip entry if any of CONDITIONS is true.
4431 See `org-agenda-skip-if' for details."
4432 (org-agenda-skip-if nil conditions))
4434 (defun org-agenda-skip-subtree-if (&rest conditions)
4435 "Skip entry if any of CONDITIONS is true.
4436 See `org-agenda-skip-if' for details."
4437 (org-agenda-skip-if t conditions))
4439 (defun org-agenda-skip-if (subtree conditions)
4440 "Checks current entity for CONDITIONS.
4441 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4442 the entry, i.e. the text before the next heading is checked.
4444 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4445 from different tests. Valid conditions are:
4447 scheduled Check if there is a scheduled cookie
4448 notscheduled Check if there is no scheduled cookie
4449 deadline Check if there is a deadline
4450 notdeadline Check if there is no deadline
4451 timestamp Check if there is a timestamp (also deadline or scheduled)
4452 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4453 regexp Check if regexp matches
4454 notregexp Check if regexp does not match.
4455 todo Check if TODO keyword matches
4456 nottodo Check if TODO keyword does not match
4458 The regexp is taken from the conditions list, it must come right after
4459 the `regexp' or `notregexp' element.
4461 `todo' and `nottodo' accept as an argument a list of todo
4462 keywords, which may include \"*\" to match any todo keyword.
4464 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4466 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4468 Instead of a list a keyword class may be given
4470 (org-agenda-skip-entry-if 'nottodo 'done)
4472 would skip entries that haven't been marked with any of \"DONE\"
4473 keywords. Possible classes are: `todo', `done', `any'.
4475 If any of these conditions is met, this function returns the end point of
4476 the entity, causing the search to continue from there. This is a function
4477 that can be put into `org-agenda-skip-function' for the duration of a command."
4479 (org-back-to-heading t)
4482 (progn (org-end-of-subtree t) (point))
4483 (progn (outline-next-heading) (1- (point)))))
4487 (and (memq 'scheduled conditions)
4488 (re-search-forward org-scheduled-time-regexp end t))
4489 (and (memq 'notscheduled conditions)
4490 (not (re-search-forward org-scheduled-time-regexp end t)))
4491 (and (memq 'deadline conditions)
4492 (re-search-forward org-deadline-time-regexp end t))
4493 (and (memq 'notdeadline conditions)
4494 (not (re-search-forward org-deadline-time-regexp end t)))
4495 (and (memq 'timestamp conditions)
4496 (re-search-forward org-ts-regexp end t))
4497 (and (memq 'nottimestamp conditions)
4498 (not (re-search-forward org-ts-regexp end t)))
4499 (and (setq m (memq 'regexp conditions))
4501 (re-search-forward (nth 1 m) end t))
4502 (and (setq m (memq 'notregexp conditions))
4504 (not (re-search-forward (nth 1 m) end t)))
4506 (setq m (memq 'todo conditions))
4507 (setq m (memq 'nottodo conditions)))
4508 (org-agenda-skip-if-todo m end)))
4511 (defun org-agenda-skip-if-todo (args end)
4512 "Helper function for `org-agenda-skip-if', do not use it directly.
4513 ARGS is a list with first element either `todo' or `nottodo'.
4514 The remainder is either a list of TODO keywords, or a state symbol
4515 `todo' or `done' or `any'."
4516 (let ((kw (car args))
4522 ((listp arg) ;; list of keywords
4523 (if (member "*" arg)
4524 (mapcar 'substring-no-properties org-todo-keywords-1)
4526 ((symbolp arg) ;; keyword class name
4529 (org-delete-all org-done-keywords
4530 (mapcar 'substring-no-properties
4531 org-todo-keywords-1)))
4532 ((eq arg 'done) org-done-keywords)
4534 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4536 (concat "^\\*+[ \t]+\\<\\("
4537 (mapconcat 'identity todo-wds "\\|")
4540 (re-search-forward todo-re end t)
4541 (not (re-search-forward todo-re end t)))))
4544 (defun org-agenda-list-stuck-projects (&rest ignore)
4545 "Create agenda view for projects that are stuck.
4546 Stuck projects are project that have no next actions. For the definitions
4547 of what a project is and how to check if it stuck, customize the variable
4548 `org-stuck-projects'."
4550 (let* ((org-agenda-skip-function
4551 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4552 ;; We could have used org-agenda-skip-if here.
4553 (org-agenda-overriding-header
4554 (or org-agenda-overriding-header "List of stuck projects: "))
4555 (matcher (nth 0 org-stuck-projects))
4556 (todo (nth 1 org-stuck-projects))
4557 (todo-wds (if (member "*" todo)
4559 (org-prepare-agenda-buffers (org-agenda-files
4562 org-done-keywords-for-agenda
4563 (copy-sequence org-todo-keywords-for-agenda)))
4565 (todo-re (concat "^\\*+[ \t]+\\("
4566 (mapconcat 'identity todo-wds "\\|")
4568 (tags (nth 2 org-stuck-projects))
4569 (tags-re (if (member "*" tags)
4570 (concat org-outline-regexp-bol
4571 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4573 (concat org-outline-regexp-bol
4575 (mapconcat 'identity tags "\\|")
4576 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4577 (gen-re (nth 3 org-stuck-projects))
4583 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4585 (setq org-agenda-skip-regexp
4587 (mapconcat 'identity re-list "\\|")
4588 (error "No information how to identify unstuck projects")))
4589 (org-tags-view nil matcher)
4590 (with-current-buffer org-agenda-buffer-name
4591 (setq org-agenda-redo-command
4592 '(org-agenda-list-stuck-projects
4593 (or current-prefix-arg org-last-arg))))))
4595 ;;; Diary integration
4597 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4598 (defvar diary-list-entries-hook)
4599 (defvar diary-time-regexp)
4600 (defun org-get-entries-from-diary (date)
4601 "Get the (Emacs Calendar) diary entries for DATE."
4602 (require 'diary-lib)
4603 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4604 (diary-display-hook '(fancy-diary-display))
4605 (diary-display-function 'fancy-diary-display)
4607 (diary-list-entries-hook
4608 (cons 'org-diary-default-entry diary-list-entries-hook))
4609 (diary-file-name-prefix-function nil) ; turn this feature off
4610 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4612 (org-disable-agenda-to-diary t))
4614 (save-window-excursion
4615 (funcall (if (fboundp 'diary-list-entries)
4616 'diary-list-entries 'list-diary-entries)
4618 (if (not (get-buffer diary-fancy-buffer))
4620 (with-current-buffer diary-fancy-buffer
4621 (setq buffer-read-only nil)
4622 (if (zerop (buffer-size))
4625 ;; Omit the date and other unnecessary stuff
4626 (org-agenda-cleanup-fancy-diary)
4627 ;; Add prefix to each line and extend the text properties
4628 (if (zerop (buffer-size))
4630 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4633 (insert entries) (goto-char (point-min))
4634 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4635 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4636 (replace-match (concat "; " (match-string 1)))))
4638 (set-buffer-modified-p nil)
4639 (kill-buffer diary-fancy-buffer)))
4641 (setq entries (org-split-string entries "\n"))
4645 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4646 ;; Extend the text properties to the beginning of the line
4647 (org-add-props x (text-properties-at (1- (length x)) x)
4648 'type "diary" 'date date 'face 'org-agenda-diary))
4651 (defvar org-agenda-cleanup-fancy-diary-hook nil
4652 "Hook run when the fancy diary buffer is cleaned up.")
4654 (defun org-agenda-cleanup-fancy-diary ()
4655 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4656 This gets rid of the date, the underline under the date, and
4657 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4658 date. It also removes lines that contain only whitespace."
4659 (goto-char (point-min))
4660 (if (looking-at ".*?:[ \t]*")
4663 (re-search-forward "\n=+$" nil t)
4665 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4666 (re-search-forward "\n=+$" nil t)
4667 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4668 (goto-char (point-min))
4669 (while (re-search-forward "^ +\n" nil t)
4671 (goto-char (point-min))
4672 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4674 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4676 ;; Make sure entries from the diary have the right text properties.
4677 (eval-after-load "diary-lib"
4678 '(if (boundp 'diary-modify-entry-list-string-function)
4679 ;; We can rely on the hook, nothing to do
4681 ;; Hook not available, must use advice to make this work
4682 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4683 "Make the position visible."
4684 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4687 (setq string (org-modify-diary-entry-string string))))))
4689 (defun org-modify-diary-entry-string (string)
4690 "Add text properties to string, allowing org-mode to act on it."
4691 (org-add-props string nil
4692 'mouse-face 'highlight
4693 'help-echo (if buffer-file-name
4694 (format "mouse-2 or RET jump to diary file %s"
4695 (abbreviate-file-name buffer-file-name))
4697 'org-agenda-diary-link t
4698 'org-marker (org-agenda-new-marker (point-at-bol))))
4700 (defun org-diary-default-entry ()
4701 "Add a dummy entry to the diary.
4702 Needed to avoid empty dates which mess up holiday display."
4703 ;; Catch the error if dealing with the new add-to-diary-alist
4704 (when org-disable-agenda-to-diary
4706 (org-add-to-diary-list original-date "Org-mode dummy" "")
4708 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4710 (defun org-add-to-diary-list (&rest args)
4711 (if (fboundp 'diary-add-to-list)
4712 (apply 'diary-add-to-list args)
4713 (apply 'add-to-diary-list args)))
4715 (defvar org-diary-last-run-time nil)
4718 (defun org-diary (&rest args)
4719 "Return diary information from org-files.
4720 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4721 It accesses org files and extracts information from those files to be
4722 listed in the diary. The function accepts arguments specifying what
4723 items should be listed. For a list of arguments allowed here, see the
4724 variable `org-agenda-entry-types'.
4726 The call in the diary file should look like this:
4728 &%%(org-diary) ~/path/to/some/orgfile.org
4730 Use a separate line for each org file to check. Or, if you omit the file name,
4731 all files listed in `org-agenda-files' will be checked automatically:
4735 If you don't give any arguments (as in the example above), the default
4736 arguments (:deadline :scheduled :timestamp :sexp) are used.
4737 So the example above may also be written as
4739 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4741 The function expects the lisp variables `entry' and `date' to be provided
4742 by the caller, because this is how the calendar works. Don't use this
4743 function from a program - use `org-agenda-get-day-entries' instead."
4744 (when (> (- (org-float-time)
4745 org-agenda-last-marker-time)
4747 ;; I am not sure if this works with sticky agendas, because the marker
4748 ;; list is then no longer a global variable.
4749 (org-agenda-reset-markers))
4750 (org-compile-prefix-format 'agenda)
4751 (org-set-sorting-strategy 'agenda)
4752 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4753 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4755 (org-agenda-files t)))
4756 (time (org-float-time))
4758 (when (or (not org-diary-last-run-time)
4760 org-diary-last-run-time)
4762 (org-prepare-agenda-buffers files))
4763 (setq org-diary-last-run-time time)
4764 ;; If this is called during org-agenda, don't return any entries to
4765 ;; the calendar. Org Agenda will list these entries itself.
4766 (if org-disable-agenda-to-diary (setq files nil))
4767 (while (setq file (pop files))
4768 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4769 (setq results (append results rtn)))
4771 (concat (org-finalize-agenda-entries results) "\n"))))
4773 ;;; Agenda entry finders
4775 (defun org-agenda-get-day-entries (file date &rest args)
4776 "Does the work for `org-diary' and `org-agenda'.
4777 FILE is the path to a file to be checked for entries. DATE is date like
4778 the one returned by `calendar-current-date'. ARGS are symbols indicating
4779 which kind of entries should be extracted. For details about these, see
4780 the documentation of `org-diary'."
4781 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4782 (let* ((org-startup-folded nil)
4783 (org-startup-align-all-tables nil)
4784 (buffer (if (file-exists-p file)
4785 (org-get-agenda-file-buffer file)
4786 (error "No such file %s" file)))
4787 arg results rtn deadline-results)
4789 ;; If file does not exist, make sure an error message ends up in diary
4790 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4791 (with-current-buffer buffer
4792 (unless (eq major-mode 'org-mode)
4793 (error "Agenda file %s is not in `org-mode'" file))
4794 (let ((case-fold-search nil))
4797 (if org-agenda-restrict
4798 (narrow-to-region org-agenda-restrict-begin
4799 org-agenda-restrict-end)
4801 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4802 (while (setq arg (pop args))
4804 ((and (eq arg :todo)
4805 (equal date (calendar-gregorian-from-absolute
4807 (setq rtn (org-agenda-get-todos))
4808 (setq results (append results rtn)))
4809 ((eq arg :timestamp)
4810 (setq rtn (org-agenda-get-blocks))
4811 (setq results (append results rtn))
4812 (setq rtn (org-agenda-get-timestamps))
4813 (setq results (append results rtn)))
4815 (setq rtn (org-agenda-get-sexps))
4816 (setq results (append results rtn)))
4817 ((eq arg :scheduled)
4818 (setq rtn (org-agenda-get-scheduled deadline-results))
4819 (setq results (append results rtn)))
4821 (setq rtn (org-agenda-get-progress))
4822 (setq results (append results rtn)))
4824 (setq rtn (org-agenda-get-deadlines))
4825 (setq deadline-results (copy-sequence rtn))
4826 (setq results (append results rtn))))))))
4829 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4830 (defun org-agenda-get-todos ()
4831 "Return the TODO information for agenda display."
4832 (let* ((props (list 'face nil
4833 'done-face 'org-agenda-done
4834 'org-not-done-regexp org-not-done-regexp
4835 'org-todo-regexp org-todo-regexp
4836 'org-complex-heading-regexp org-complex-heading-regexp
4837 'mouse-face 'highlight
4839 (format "mouse-2 or RET jump to org file %s"
4840 (abbreviate-file-name buffer-file-name))))
4841 (regexp (format org-heading-keyword-regexp-format
4843 ((and org-select-this-todo-keyword
4844 (equal org-select-this-todo-keyword "*"))
4846 (org-select-this-todo-keyword
4848 (mapconcat 'identity
4850 org-select-this-todo-keyword
4853 (t org-not-done-regexp))))
4854 marker priority category org-category-pos tags todo-state
4856 (goto-char (point-min))
4857 (while (re-search-forward regexp nil t)
4862 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4863 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4864 (goto-char (1+ beg))
4865 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4867 (goto-char (match-beginning 2))
4868 (setq marker (org-agenda-new-marker (match-beginning 0))
4869 category (org-get-category)
4870 org-category-pos (get-text-property (point) 'org-category-position)
4872 (buffer-substring (match-beginning 2) (match-end 0)))
4873 tags (org-get-tags-at (point))
4874 txt (org-agenda-format-item "" txt category tags)
4875 priority (1+ (org-get-priority txt))
4876 todo-state (org-get-todo-state))
4877 (org-add-props txt props
4878 'org-marker marker 'org-hd-marker marker
4879 'priority priority 'org-category category
4880 'org-category-position org-category-pos
4881 'type "todo" 'todo-state todo-state)
4883 (if org-agenda-todo-list-sublevels
4884 (goto-char (match-end 2))
4885 (org-end-of-subtree 'invisible))))
4888 (defun org-agenda-todo-custom-ignore-p (time n)
4889 "Check whether timestamp is farther away then n number of days.
4890 This function is invoked if `org-agenda-todo-ignore-deadlines',
4891 `org-agenda-todo-ignore-scheduled' or
4892 `org-agenda-todo-ignore-timestamp' is set to an integer."
4893 (let ((days (org-days-to-time time)))
4899 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4901 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4902 (when (or org-agenda-todo-ignore-with-date
4903 org-agenda-todo-ignore-scheduled
4904 org-agenda-todo-ignore-deadlines
4905 org-agenda-todo-ignore-timestamp)
4906 (setq end (or end (save-excursion (outline-next-heading) (point))))
4908 (or (and org-agenda-todo-ignore-with-date
4909 (re-search-forward org-ts-regexp end t))
4910 (and org-agenda-todo-ignore-scheduled
4911 (re-search-forward org-scheduled-time-regexp end t)
4913 ((eq org-agenda-todo-ignore-scheduled 'future)
4914 (> (org-days-to-time (match-string 1)) 0))
4915 ((eq org-agenda-todo-ignore-scheduled 'past)
4916 (<= (org-days-to-time (match-string 1)) 0))
4917 ((numberp org-agenda-todo-ignore-scheduled)
4918 (org-agenda-todo-custom-ignore-p
4919 (match-string 1) org-agenda-todo-ignore-scheduled))
4921 (and org-agenda-todo-ignore-deadlines
4922 (re-search-forward org-deadline-time-regexp end t)
4924 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4925 ((eq org-agenda-todo-ignore-deadlines 'far)
4926 (not (org-deadline-close (match-string 1))))
4927 ((eq org-agenda-todo-ignore-deadlines 'future)
4928 (> (org-days-to-time (match-string 1)) 0))
4929 ((eq org-agenda-todo-ignore-deadlines 'past)
4930 (<= (org-days-to-time (match-string 1)) 0))
4931 ((numberp org-agenda-todo-ignore-deadlines)
4932 (org-agenda-todo-custom-ignore-p
4933 (match-string 1) org-agenda-todo-ignore-deadlines))
4934 (t (org-deadline-close (match-string 1)))))
4935 (and org-agenda-todo-ignore-timestamp
4936 (let ((buffer (current-buffer))
4939 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4941 ;; Copy current buffer into a temporary one
4943 (insert-buffer-substring buffer start end)
4944 (goto-char (point-min))
4945 ;; Delete SCHEDULED and DEADLINE items
4946 (while (re-search-forward regexp end t)
4947 (delete-region (match-beginning 0) (match-end 0)))
4948 (goto-char (point-min))
4949 ;; No search for timestamp left
4950 (when (re-search-forward org-ts-regexp nil t)
4952 ((eq org-agenda-todo-ignore-timestamp 'future)
4953 (> (org-days-to-time (match-string 1)) 0))
4954 ((eq org-agenda-todo-ignore-timestamp 'past)
4955 (<= (org-days-to-time (match-string 1)) 0))
4956 ((numberp org-agenda-todo-ignore-timestamp)
4957 (org-agenda-todo-custom-ignore-p
4958 (match-string 1) org-agenda-todo-ignore-timestamp))
4961 (defconst org-agenda-no-heading-message
4962 "No heading for this item in buffer or region.")
4964 (defun org-agenda-get-timestamps ()
4965 "Return the date stamp information for agenda display."
4966 (let* ((props (list 'face 'org-agenda-calendar-event
4967 'org-not-done-regexp org-not-done-regexp
4968 'org-todo-regexp org-todo-regexp
4969 'org-complex-heading-regexp org-complex-heading-regexp
4970 'mouse-face 'highlight
4972 (format "mouse-2 or RET jump to org file %s"
4973 (abbreviate-file-name buffer-file-name))))
4974 (d1 (calendar-absolute-from-gregorian date))
4980 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4984 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4988 (car org-time-stamp-formats)
4989 (apply 'encode-time ; DATE bound by calendar
4990 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4992 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4993 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4994 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4995 donep tmp priority category org-category-pos ee txt timestr tags
4996 b0 b3 e3 head todo-state end-of-match show-all)
4997 (goto-char (point-min))
4998 (while (setq end-of-match (re-search-forward regexp nil t))
4999 (setq b0 (match-beginning 0)
5000 b3 (match-beginning 3) e3 (match-end 3)
5001 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5002 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5004 org-agenda-repeating-timestamp-show-all)))
5006 (and (org-at-date-range-p) (throw :skip nil))
5008 (if (and (match-end 1)
5009 (not (= d1 (org-time-string-to-absolute
5010 (match-string 1) d1 nil show-all
5011 (current-buffer) b0))))
5014 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5016 (setq tmp (buffer-substring (max (point-min)
5017 (- b0 org-ds-keyword-length))
5019 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5020 inactivep (= (char-after b0) ?\[)
5021 deadlinep (string-match org-deadline-regexp tmp)
5022 scheduledp (string-match org-scheduled-regexp tmp)
5023 closedp (and org-agenda-include-inactive-timestamps
5024 (string-match org-closed-string tmp))
5025 clockp (and org-agenda-include-inactive-timestamps
5026 (or (string-match org-clock-string tmp)
5027 (string-match "]-+\\'" tmp)))
5028 donep (member todo-state org-done-keywords))
5029 (if (or scheduledp deadlinep closedp clockp
5030 (and donep org-agenda-skip-timestamp-if-done))
5032 (if (string-match ">" timestr)
5033 ;; substring should only run to end of time stamp
5034 (setq timestr (substring timestr 0 (match-end 0))))
5035 (setq marker (org-agenda-new-marker b0)
5036 category (org-get-category b0)
5037 org-category-pos (get-text-property b0 'org-category-position))
5039 (if (not (re-search-backward org-outline-regexp-bol nil t))
5040 (setq txt org-agenda-no-heading-message)
5041 (goto-char (match-beginning 0))
5042 (setq hdmarker (org-agenda-new-marker)
5043 tags (org-get-tags-at))
5044 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5045 (setq head (or (match-string 1) ""))
5046 (setq txt (org-agenda-format-item
5047 (if inactivep org-agenda-inactive-leader nil)
5048 head category tags timestr
5050 (setq priority (org-get-priority txt))
5051 (org-add-props txt props
5052 'org-marker marker 'org-hd-marker hdmarker)
5053 (org-add-props txt nil 'priority priority
5054 'org-category category 'date date
5055 'org-category-position org-category-pos
5056 'todo-state todo-state
5059 (if org-agenda-skip-additional-timestamps-same-entry
5060 (outline-next-heading)
5061 (goto-char end-of-match))))
5064 (defun org-agenda-get-sexps ()
5065 "Return the sexp information for agenda display."
5066 (require 'diary-lib)
5067 (let* ((props (list 'face 'org-agenda-calendar-sexp
5068 'mouse-face 'highlight
5070 (format "mouse-2 or RET jump to org file %s"
5071 (abbreviate-file-name buffer-file-name))))
5073 marker category org-category-pos ee txt tags entry
5074 result beg b sexp sexp-entry todo-state)
5075 (goto-char (point-min))
5076 (while (re-search-forward regexp nil t)
5079 (setq beg (match-beginning 0))
5080 (goto-char (1- (match-end 0)))
5083 (setq sexp (buffer-substring b (point)))
5084 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5085 (org-trim (match-string 1))
5087 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5089 (setq marker (org-agenda-new-marker beg)
5090 category (org-get-category beg)
5091 org-category-pos (get-text-property beg 'org-category-position)
5092 todo-state (org-get-todo-state))
5094 (dolist (r (if (stringp result)
5096 result)) ;; we expect a list here
5097 (if (string-match "\\S-" r)
5099 (setq txt "SEXP entry returned empty string"))
5101 (setq txt (org-agenda-format-item
5102 "" txt category tags 'time))
5103 (org-add-props txt props 'org-marker marker)
5104 (org-add-props txt nil
5105 'org-category category 'date date 'todo-state todo-state
5106 'org-category-position org-category-pos
5111 ;; Calendar sanity: define some functions that are independent of
5112 ;; `calendar-date-style'.
5113 ;; Normally I would like to use ISO format when calling the diary functions,
5114 ;; but to make sure we still have Emacs 22 compatibility we bind
5115 ;; also `european-calendar-style' and use european format
5116 (defun org-anniversary (year month day &optional mark)
5117 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5119 (let ((calendar-date-style 'european) (european-calendar-style t))
5120 (diary-anniversary day month year mark))))
5121 (defun org-cyclic (N year month day &optional mark)
5122 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5124 (let ((calendar-date-style 'european) (european-calendar-style t))
5125 (diary-cyclic N day month year mark))))
5126 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5127 "Like `diary-block', but with fixed (ISO) order of arguments."
5129 (let ((calendar-date-style 'european) (european-calendar-style t))
5130 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5131 (defun org-date (year month day &optional mark)
5132 "Like `diary-date', but with fixed (ISO) order of arguments."
5134 (let ((calendar-date-style 'european) (european-calendar-style t))
5135 (diary-date day month year mark))))
5136 (defalias 'org-float 'diary-float)
5138 ;; Define the` org-class' function
5139 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5140 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5141 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5142 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5143 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5144 `holidays', then any date that is known by the Emacs calendar to be a
5145 holiday will also be skipped."
5146 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5147 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5148 (d (calendar-absolute-from-gregorian date)))
5152 (= (calendar-day-of-week date) dayname)
5153 (or (not skip-weeks)
5156 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5157 (not (and (memq 'holidays skip-weeks)
5158 (calendar-check-holidays date)))
5161 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5162 "Like `org-class', but honor `calendar-date-style'.
5163 The order of the first 2 times 3 arguments depends on the variable
5164 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5165 So for American calendars, give this as MONTH DAY YEAR, for European as
5166 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5167 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5168 is any number of ISO weeks in the block period for which the item should
5171 This function is here only for backward compatibility and it is deprecated,
5172 please use `org-class' instead."
5173 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5174 (date2 (org-order-calendar-date-args m2 d2 y2)))
5176 (nth 2 date1) (car date1) (nth 1 date1)
5177 (nth 2 date2) (car date2) (nth 1 date2)
5178 dayname skip-weeks)))
5179 (make-obsolete 'org-diary-class 'org-class "")
5181 (defalias 'org-get-closed 'org-agenda-get-progress)
5182 (defun org-agenda-get-progress ()
5183 "Return the logged TODO entries for agenda display."
5184 (let* ((props (list 'mouse-face 'highlight
5185 'org-not-done-regexp org-not-done-regexp
5186 'org-todo-regexp org-todo-regexp
5187 'org-complex-heading-regexp org-complex-heading-regexp
5189 (format "mouse-2 or RET jump to org file %s"
5190 (abbreviate-file-name buffer-file-name))))
5191 (items (if (consp org-agenda-show-log-scoped)
5192 org-agenda-show-log-scoped
5193 (if (eq org-agenda-show-log-scoped 'clockcheck)
5195 org-agenda-log-mode-items)))
5199 (if (memq 'closed items) (concat "\\<" org-closed-string))
5200 (if (memq 'clock items) (concat "\\<" org-clock-string))
5201 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5202 (parts-re (if parts (mapconcat 'identity parts "\\|")
5203 (error "`org-agenda-log-mode-items' is empty")))
5205 "\\(" parts-re "\\)"
5210 (car org-time-stamp-formats)
5211 (apply 'encode-time ; DATE bound by calendar
5212 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5214 (org-agenda-search-headline-for-time nil)
5215 marker hdmarker priority category org-category-pos tags closedp
5216 statep clockp state ee txt extra timestr rest clocked)
5217 (goto-char (point-min))
5218 (while (re-search-forward regexp nil t)
5221 (setq marker (org-agenda-new-marker (match-beginning 0))
5222 closedp (equal (match-string 1) org-closed-string)
5223 statep (equal (string-to-char (match-string 1)) ?-)
5224 clockp (not (or closedp statep))
5225 state (and statep (match-string 2))
5226 category (org-get-category (match-beginning 0))
5227 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5228 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5229 (when (string-match "\\]" timestr)
5230 ;; substring should only run to end of time stamp
5231 (setq rest (substring timestr (match-end 0))
5232 timestr (substring timestr 0 (match-end 0)))
5233 (if (and (not closedp) (not statep)
5234 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5236 (progn (setq timestr (concat (substring timestr 0 -1)
5237 "-" (match-string 1 rest) "]"))
5238 (setq clocked (match-string 2 rest)))
5239 (setq clocked "-")))
5243 ((not org-agenda-log-mode-add-notes) nil)
5245 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5248 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5249 (match-string 1)))))
5250 (if (not (re-search-backward org-outline-regexp-bol nil t))
5251 (setq txt org-agenda-no-heading-message)
5252 (goto-char (match-beginning 0))
5253 (setq hdmarker (org-agenda-new-marker)
5254 tags (org-get-tags-at))
5255 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5256 (setq txt (match-string 1))
5258 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5259 (setq txt (concat (substring txt 0 (match-beginning 1))
5260 " - " extra " " (match-string 2 txt)))
5261 (setq txt (concat txt " - " extra))))
5262 (setq txt (org-agenda-format-item
5264 (closedp "Closed: ")
5265 (statep (concat "State: (" state ")"))
5266 (t (concat "Clocked: (" clocked ")")))
5267 txt category tags timestr)))
5268 (setq priority 100000)
5269 (org-add-props txt props
5270 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5271 'priority priority 'org-category category
5272 'org-category-position org-category-pos
5273 'type "closed" 'date date
5274 'undone-face 'org-warning 'done-face 'org-agenda-done)
5276 (goto-char (point-at-eol))))
5279 (defun org-agenda-show-clocking-issues ()
5280 "Add overlays, showing issues with clocking.
5281 See also the user option `org-agenda-clock-consistency-checks'."
5283 (let* ((pl org-agenda-clock-consistency-checks)
5284 (re (concat "^[ \t]*"
5287 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5288 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5291 (maxtime (org-hh:mm-string-to-minutes
5292 (or (plist-get pl :max-duration) "24:00")))
5293 (mintime (org-hh:mm-string-to-minutes
5294 (or (plist-get pl :min-duration) 0)))
5295 (maxgap (org-hh:mm-string-to-minutes
5296 ;; default 30:00 means never complain
5297 (or (plist-get pl :max-gap) "30:00")))
5298 (gapok (mapcar 'org-hh:mm-string-to-minutes
5299 (plist-get pl :gap-ok-around)))
5300 (def-face (or (plist-get pl :default-face)
5301 '((:background "DarkRed") (:foreground "white"))))
5302 issue face m te ts dt ov)
5303 (goto-char (point-min))
5304 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5305 (setq issue nil face def-face)
5307 (setq m (org-get-at-bol 'org-marker)
5309 (unless (and m (markerp m))
5310 (setq issue "No valid clock line") (throw 'next t))
5311 (org-with-point-at m
5313 (goto-char (point-at-bol))
5314 (unless (looking-at re)
5315 (error "No valid Clock line")
5317 (unless (match-end 3)
5318 (setq issue "No end time"
5319 face (or (plist-get pl :no-end-time-face) face))
5321 (setq ts (match-string 1)
5324 (apply 'encode-time (org-parse-time-string ts)))
5326 (apply 'encode-time (org-parse-time-string te)))
5329 ((> dt (* 60 maxtime))
5330 ;; a very long clocking chunk
5331 (setq issue (format "Clocking interval is very long: %s"
5332 (org-minutes-to-hh:mm-string
5333 (floor (/ (float dt) 60.))))
5334 face (or (plist-get pl :long-face) face)))
5335 ((< dt (* 60 mintime))
5336 ;; a very short clocking chunk
5337 (setq issue (format "Clocking interval is very short: %s"
5338 (org-minutes-to-hh:mm-string
5339 (floor (/ (float dt) 60.))))
5340 face (or (plist-get pl :short-face) face)))
5341 ((and (> tlend 0) (< ts tlend))
5342 ;; Two clock entries are overlapping
5343 (setq issue (format "Clocking overlap: %d minutes"
5344 (/ (- tlend ts) 60))
5345 face (or (plist-get pl :overlap-face) face)))
5346 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5347 ;; There is a gap, lets see if we need to report it
5348 (unless (org-agenda-check-clock-gap tlend ts gapok)
5349 (setq issue (format "Clocking gap: %d minutes"
5350 (/ (- ts tlend) 60))
5351 face (or (plist-get pl :gap-face) face))))
5353 (setq tlend (or te tlend) tlstart (or ts tlstart))
5355 ;; OK, there was some issue, add an overlay to show the issue
5356 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5357 (overlay-put ov 'before-string
5360 (format "%-43s" (concat " " issue))
5364 (overlay-put ov 'evaporate t)))))
5366 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5367 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5370 ;; there are no OK times for gaps...
5372 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5373 ;; This is more than 24 hours, so it is OK.
5374 ;; because we have at least one OK time, that must be in the
5375 ;; 24 hour interval.
5377 ;; We have a shorter gap.
5378 ;; Now we have to get the minute of the day when these times are
5379 (let* ((t1dec (decode-time (seconds-to-time t1)))
5380 (t2dec (decode-time (seconds-to-time t2)))
5381 ;; compute the minute on the day
5382 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5383 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5385 ;; if min2 is smaller than min1, this means it is on the next day.
5386 ;; Wrap it to after midnight.
5387 (setq min2 (+ min2 1440)))
5388 ;; Now check if any of the OK times is in the gap
5390 ;; Wrap the time to after midnight if necessary
5391 (if (< x min1) (setq x (+ x 1440)))
5392 ;; Check if in interval
5393 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5395 ;; Nope, this gap is not OK
5398 (defun org-agenda-get-deadlines ()
5399 "Return the deadline information for agenda display."
5400 (let* ((props (list 'mouse-face 'highlight
5401 'org-not-done-regexp org-not-done-regexp
5402 'org-todo-regexp org-todo-regexp
5403 'org-complex-heading-regexp org-complex-heading-regexp
5405 (format "mouse-2 or RET jump to org file %s"
5406 (abbreviate-file-name buffer-file-name))))
5407 (regexp org-deadline-time-regexp)
5408 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5409 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5410 d2 diff dfrac wdays pos pos1 category org-category-pos
5411 tags suppress-prewarning ee txt head face s todo-state
5412 show-all upcomingp donep timestr)
5413 (goto-char (point-min))
5414 (while (re-search-forward regexp nil t)
5415 (setq suppress-prewarning nil)
5418 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5420 (string-match org-scheduled-time-regexp
5421 (buffer-substring (point-at-bol)
5423 (setq suppress-prewarning
5424 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5425 org-agenda-skip-deadline-prewarning-if-scheduled
5427 (setq s (match-string 1)
5429 pos (1- (match-beginning 1))
5430 todo-state (save-match-data (org-get-todo-state))
5431 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5433 org-agenda-repeating-timestamp-show-all))
5434 d2 (org-time-string-to-absolute
5435 (match-string 1) d1 'past show-all
5436 (current-buffer) pos)
5438 wdays (if suppress-prewarning
5439 (let ((org-deadline-warning-days suppress-prewarning))
5442 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5443 upcomingp (and todayp (> diff 0)))
5444 ;; When to show a deadline in the calendar:
5445 ;; If the expiration is within wdays warning time.
5446 ;; Past-due deadlines are only shown on the current date
5447 (if (and (or (and (<= diff wdays)
5448 (and todayp (not org-agenda-only-exact-dates)))
5451 ;; (setq todo-state (org-get-todo-state))
5452 (setq donep (member todo-state org-done-keywords))
5454 (or org-agenda-skip-deadline-if-done
5457 (setq category (org-get-category)
5458 org-category-pos (get-text-property (point) 'org-category-position))
5459 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5460 (setq txt org-agenda-no-heading-message)
5461 (goto-char (match-end 0))
5462 (setq pos1 (match-beginning 0))
5463 (setq tags (org-get-tags-at pos1))
5464 (setq head (buffer-substring-no-properties
5466 (progn (skip-chars-forward "^\r\n")
5468 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5470 (concat (substring s (match-beginning 1)) " "))
5471 (setq timestr 'time))
5472 (setq txt (org-agenda-format-item
5474 (car org-agenda-deadline-leaders)
5476 (nth 1 org-agenda-deadline-leaders))
5478 (nth 1 org-agenda-deadline-leaders)
5480 (format (nth 1 org-agenda-deadline-leaders)
5483 (if (not (= diff 0)) nil timestr)))))
5485 (setq face (org-agenda-deadline-face dfrac))
5486 (org-add-props txt props
5487 'org-marker (org-agenda-new-marker pos)
5488 'org-hd-marker (org-agenda-new-marker pos1)
5489 'priority (+ (- diff)
5490 (org-get-priority txt))
5491 'org-category category
5492 'org-category-position org-category-pos
5493 'todo-state todo-state
5494 'type (if upcomingp "upcoming-deadline" "deadline")
5495 'date (if upcomingp date d2)
5496 'face (if donep 'org-agenda-done face)
5497 'undone-face face 'done-face 'org-agenda-done)
5501 (defun org-agenda-deadline-face (fraction)
5502 "Return the face to displaying a deadline item.
5503 FRACTION is what fraction of the head-warning time has passed."
5504 (let ((faces org-agenda-deadline-faces) f)
5506 (while (setq f (pop faces))
5507 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5509 (defun org-agenda-get-scheduled (&optional deadline-results)
5510 "Return the scheduled information for agenda display."
5511 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5512 'org-todo-regexp org-todo-regexp
5513 'org-complex-heading-regexp org-complex-heading-regexp
5514 'done-face 'org-agenda-done
5515 'mouse-face 'highlight
5517 (format "mouse-2 or RET jump to org file %s"
5518 (abbreviate-file-name buffer-file-name))))
5519 (regexp org-scheduled-time-regexp)
5520 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5521 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5523 (deadline-position-alist
5524 (mapcar (lambda (a) (and (setq mm (get-text-property
5525 0 'org-hd-marker a))
5526 (cons (marker-position mm) a)))
5528 d2 diff pos pos1 category org-category-pos tags donep
5529 ee txt head pastschedp todo-state face timestr s habitp show-all)
5530 (goto-char (point-min))
5531 (while (re-search-forward regexp nil t)
5534 (setq s (match-string 1)
5536 pos (1- (match-beginning 1))
5537 todo-state (save-match-data (org-get-todo-state))
5538 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5540 org-agenda-repeating-timestamp-show-all))
5541 d2 (org-time-string-to-absolute
5542 (match-string 1) d1 'past show-all
5543 (current-buffer) pos)
5545 (setq pastschedp (and todayp (< diff 0)))
5546 ;; When to show a scheduled item in the calendar:
5547 ;; If it is on or past the date.
5548 (when (or (and (< diff 0)
5549 (< (abs diff) org-scheduled-past-days)
5550 (and todayp (not org-agenda-only-exact-dates)))
5553 (setq donep (member todo-state org-done-keywords))
5555 (or org-agenda-skip-scheduled-if-done
5557 (and (functionp 'org-is-habit-p)
5560 (setq habitp (and (functionp 'org-is-habit-p)
5562 (setq category (org-get-category)
5563 org-category-pos (get-text-property (point) 'org-category-position))
5564 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5565 (setq txt org-agenda-no-heading-message)
5566 (goto-char (match-end 0))
5567 (setq pos1 (match-beginning 0))
5569 (if (or (not org-habit-show-habits)
5571 org-habit-show-habits-only-for-today))
5574 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5575 (and org-agenda-skip-scheduled-if-deadline-is-shown
5577 (setq mm (assoc pos1 deadline-position-alist)))
5579 (setq tags (org-get-tags-at))
5580 (setq head (buffer-substring-no-properties
5582 (progn (skip-chars-forward "^\r\n") (point))))
5583 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5585 (concat (substring s (match-beginning 1)) " "))
5586 (setq timestr 'time))
5587 (setq txt (org-agenda-format-item
5589 (car org-agenda-scheduled-leaders)
5590 (format (nth 1 org-agenda-scheduled-leaders)
5593 (if (not (= diff 0)) nil timestr)
5598 ((and (not habitp) pastschedp)
5599 'org-scheduled-previously)
5600 (todayp 'org-scheduled-today)
5602 habitp (and habitp (org-habit-parse-todo)))
5603 (org-add-props txt props
5605 'face (if donep 'org-agenda-done face)
5606 'org-marker (org-agenda-new-marker pos)
5607 'org-hd-marker (org-agenda-new-marker pos1)
5608 'type (if pastschedp "past-scheduled" "scheduled")
5609 'date (if pastschedp d2 date)
5610 'priority (if habitp
5611 (org-habit-get-priority habitp)
5612 (+ 94 (- 5 diff) (org-get-priority txt)))
5613 'org-category category
5614 'org-category-position org-category-pos
5616 'todo-state todo-state)
5620 (defun org-agenda-get-blocks ()
5621 "Return the date-range information for agenda display."
5622 (let* ((props (list 'face nil
5623 'org-not-done-regexp org-not-done-regexp
5624 'org-todo-regexp org-todo-regexp
5625 'org-complex-heading-regexp org-complex-heading-regexp
5626 'mouse-face 'highlight
5628 (format "mouse-2 or RET jump to org file %s"
5629 (abbreviate-file-name buffer-file-name))))
5630 (regexp org-tr-regexp)
5631 (d0 (calendar-absolute-from-gregorian date))
5632 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5633 todo-state tags pos head donep)
5634 (goto-char (point-min))
5635 (while (re-search-forward regexp nil t)
5639 (let ((start-time (match-string 1))
5640 (end-time (match-string 2)))
5641 (setq s1 (match-string 1)
5643 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5644 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5645 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5646 ;; Only allow days between the limits, because the normal
5647 ;; date stamps will catch the limits.
5649 (setq todo-state (org-get-todo-state))
5650 (setq donep (member todo-state org-done-keywords))
5651 (if (and donep org-agenda-skip-timestamp-if-done)
5653 (setq marker (org-agenda-new-marker (point)))
5654 (setq category (org-get-category)
5655 org-category-pos (get-text-property (point) 'org-category-position))
5656 (if (not (re-search-backward org-outline-regexp-bol nil t))
5657 (setq txt org-agenda-no-heading-message)
5658 (goto-char (match-beginning 0))
5659 (setq hdmarker (org-agenda-new-marker (point)))
5660 (setq tags (org-get-tags-at))
5661 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5662 (setq head (match-string 1))
5664 (if org-agenda-remove-timeranges-from-blocks
5666 "<" (regexp-quote s1) ".*?>"
5668 "<" (regexp-quote s2) ".*?>")
5670 (setq txt (org-agenda-format-item
5672 (nth (if (= d1 d2) 0 1)
5673 org-agenda-timerange-leaders)
5674 (1+ (- d0 d1)) (1+ (- d2 d1)))
5676 (cond ((and (= d1 d0) (= d2 d0))
5677 (concat "<" start-time ">--<" end-time ">"))
5679 (concat "<" start-time ">"))
5681 (concat "<" end-time ">"))
5684 (org-add-props txt props
5685 'org-marker marker 'org-hd-marker hdmarker
5686 'type "block" 'date date
5687 'todo-state todo-state
5688 'priority (org-get-priority txt) 'org-category category
5689 'org-category-position org-category-pos)
5692 ;; Sort the entries by expiration date.
5695 ;;; Agenda presentation and sorting
5697 (defvar org-prefix-has-time nil
5698 "A flag, set by `org-compile-prefix-format'.
5699 The flag is set if the currently compiled format contains a `%t'.")
5700 (defvar org-prefix-has-tag nil
5701 "A flag, set by `org-compile-prefix-format'.
5702 The flag is set if the currently compiled format contains a `%T'.")
5703 (defvar org-prefix-has-effort nil
5704 "A flag, set by `org-compile-prefix-format'.
5705 The flag is set if the currently compiled format contains a `%e'.")
5706 (defvar org-prefix-category-length nil
5707 "Used by `org-compile-prefix-format' to remember the category field width.")
5708 (defvar org-prefix-category-max-length nil
5709 "Used by `org-compile-prefix-format' to remember the category field width.")
5711 (defun org-agenda-get-category-icon (category)
5712 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5713 (dolist (entry org-agenda-category-icon-alist)
5714 (when (org-string-match-p (car entry) category)
5715 (if (listp (cadr entry))
5716 (return (cadr entry))
5717 (return (apply 'create-image (cdr entry)))))))
5719 (defun org-agenda-format-item (extra txt &optional category tags dotime
5721 "Format TXT to be inserted into the agenda buffer.
5722 In particular, it adds the prefix and corresponding text properties. EXTRA
5723 must be a string and replaces the `%s' specifier in the prefix format.
5724 CATEGORY (string, symbol or nil) may be used to overrule the default
5725 category taken from local variable or file name. It will replace the `%c'
5726 specifier in the format. DOTIME, when non-nil, indicates that a
5727 time-of-day should be extracted from TXT for sorting of this entry, and for
5728 the `%t' specifier in the format. When DOTIME is a string, this string is
5729 searched for a time before TXT is. TAGS can be the tags of the headline.
5730 Any match of REMOVE-RE will be removed from TXT."
5731 ;; We keep the org-prefix-* variable values along with a compiled
5732 ;; formatter, so that multiple agendas existing at the same time, do
5733 ;; not step on each other toes.
5735 ;; It was inconvenient to make these variables buffer local in
5736 ;; Agenda buffers, because this function expects to be called with
5737 ;; the buffer where item comes from being current, and not agenda
5739 (let* ((bindings (car org-prefix-format-compiled))
5740 (formatter (cadr org-prefix-format-compiled)))
5741 (loop for (var value) in bindings
5744 ;; Diary entries sometimes have extra whitespace at the beginning
5745 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5747 ;; Fix the tags part in txt
5748 (setq txt (org-agenda-fix-displayed-tags
5750 org-agenda-show-inherited-tags
5751 org-agenda-hide-tags-regexp))
5752 (let* ((category (or category
5753 (if (stringp org-category)
5755 (and org-category (symbol-name org-category)))
5756 (if buffer-file-name
5757 (file-name-sans-extension
5758 (file-name-nondirectory buffer-file-name))
5760 (category-icon (org-agenda-get-category-icon category))
5761 (category-icon (if category-icon
5762 (propertize " " 'display category-icon)
5764 ;; time, tag, effort are needed for the eval of the prefix format
5765 (tag (if tags (nth (1- (length tags)) tags) ""))
5767 (ts (if dotime (concat
5768 (if (stringp dotime) dotime "")
5769 (and org-agenda-search-headline-for-time txt))))
5770 (time-of-day (and dotime (org-get-time-of-day ts)))
5771 stamp plain s0 s1 s2 rtn srp l
5772 duration thecategory)
5773 (and (eq major-mode 'org-mode) buffer-file-name
5774 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5775 (when (and dotime time-of-day)
5776 ;; Extract starting and ending time and move them to prefix
5777 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5778 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5779 (setq s0 (match-string 0 ts)
5780 srp (and stamp (match-end 3))
5781 s1 (match-string (if plain 1 2) ts)
5782 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5784 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5785 ;; them, we might want to remove them there to avoid duplication.
5786 ;; The user can turn this off with a variable.
5787 (if (and org-prefix-has-time
5788 org-agenda-remove-times-when-in-prefix (or stamp plain)
5789 (string-match (concat (regexp-quote s0) " *") txt)
5790 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5791 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5792 (= (match-beginning 0) 0)
5794 (setq txt (replace-match "" nil nil txt))))
5795 ;; Normalize the time(s) to 24 hour
5796 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5797 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5799 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5800 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5802 (org-minutes-to-hh:mm-string
5803 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5805 ;; Compute the duration
5807 (setq duration (- (org-hh:mm-string-to-minutes s2)
5808 (org-hh:mm-string-to-minutes s1)))))
5810 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5812 ;; Tags are in the string
5813 (if (or (eq org-agenda-remove-tags t)
5814 (and org-agenda-remove-tags
5815 org-prefix-has-tag))
5816 (setq txt (replace-match "" t t txt))
5817 (setq txt (replace-match
5818 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5819 (match-string 2 txt))
5821 (when (eq major-mode 'org-mode)
5825 (or (get-text-property 0 'org-hd-marker txt)
5826 (get-text-property 0 'org-marker txt)))
5829 (setq neffort (org-duration-string-to-minutes effort)
5830 effort (setq effort (concat "[" effort "]")))))
5831 ;; prevent erroring out with %e format when there is no effort
5832 (or effort (setq effort ""))
5835 (while (string-match remove-re txt)
5836 (setq txt (replace-match "" t t txt))))
5838 ;; Set org-heading property on `txt' to mark the start of the
5840 (add-text-properties 0 (length txt) '(org-heading t) txt)
5842 ;; Prepare the variables needed in the eval of the compiled format
5843 (setq time (cond (s2 (concat
5844 (org-agenda-time-of-day-to-ampm-maybe s1)
5845 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5846 (if org-agenda-timegrid-use-ampm " ")))
5848 (org-agenda-time-of-day-to-ampm-maybe s1)
5849 (if org-agenda-timegrid-use-ampm
5853 extra (or (and (not habitp) extra) "")
5854 category (if (symbolp category) (symbol-name category) category)
5855 thecategory (copy-sequence category))
5856 (if (string-match org-bracket-link-regexp category)
5858 (setq l (if (match-end 3)
5859 (- (match-end 3) (match-beginning 3))
5860 (- (match-end 1) (match-beginning 1))))
5861 (when (< l (or org-prefix-category-length 0))
5862 (setq category (copy-sequence category))
5863 (org-add-props category nil
5864 'extra-space (make-string
5865 (- org-prefix-category-length l 1) ?\ ))))
5866 (if (and org-prefix-category-max-length
5867 (>= (length category) org-prefix-category-max-length))
5868 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5869 ;; Evaluate the compiled format
5870 (setq rtn (concat (eval formatter) txt))
5872 ;; And finally add the text properties
5873 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5874 (org-add-props rtn nil
5875 'org-category (if thecategory (downcase thecategory) category)
5876 'tags (mapcar 'org-downcase-keep-props tags)
5877 'org-highest-priority org-highest-priority
5878 'org-lowest-priority org-lowest-priority
5879 'time-of-day time-of-day
5882 'effort-minutes neffort
5886 'format org-prefix-format-compiled
5889 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5890 "Remove tags string from TXT, and add a modified list of tags.
5891 The modified list may contain inherited tags, and tags matched by
5892 `org-agenda-hide-tags-regexp' will be removed."
5893 (when (or add-inherited hide-re)
5894 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5895 (setq txt (substring txt 0 (match-beginning 0))))
5898 (mapcar (lambda (tg)
5899 (if (or (and hide-re (string-match hide-re tg))
5900 (and (not add-inherited)
5901 (get-text-property 0 'inherited tg)))
5906 (let ((have-i (get-text-property 0 'inherited (car tags)))
5908 (setq txt (concat txt " :"
5911 (setq i (get-text-property 0 'inherited x))
5912 (if (and have-i (not i))
5918 (if have-i "::" ":"))))))
5921 (defun org-downcase-keep-props (s)
5922 (let ((props (text-properties-at 0 s)))
5923 (setq s (downcase s))
5924 (add-text-properties 0 (length s) props s)
5927 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5928 (defvar org-agenda-sorting-strategy-selected nil)
5930 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5932 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5933 ((and todayp (member 'today (car org-agenda-time-grid))))
5934 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5935 ((member 'weekly (car org-agenda-time-grid)))
5936 (t (throw 'exit list)))
5937 (let* ((have (delq nil (mapcar
5938 (lambda (x) (get-text-property 1 'time-of-day x))
5940 (string (nth 1 org-agenda-time-grid))
5941 (gridtimes (nth 2 org-agenda-time-grid))
5942 (req (car org-agenda-time-grid))
5943 (remove (member 'remove-match req))
5945 (if (and (member 'require-timed req) (not have))
5946 ;; don't show empty grid
5948 (while (setq time (pop gridtimes))
5949 (unless (and remove (member time have))
5950 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5951 (push (org-agenda-format-item
5953 (concat (substring time 0 -2) ":" (substring time -2)))
5956 2 (length (car new)) 'face 'org-time-grid (car new))))
5957 (when (and todayp org-agenda-show-current-time-in-grid)
5958 (push (org-agenda-format-item
5960 org-agenda-current-time-string
5962 (format-time-string "%H:%M "))
5965 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5967 (if (member 'time-up org-agenda-sorting-strategy-selected)
5969 (append list new)))))
5971 (defun org-compile-prefix-format (key)
5972 "Compile the prefix format into a Lisp form that can be evaluated.
5973 The resulting form and associated variable bindings is returned
5974 and stored in the variable `org-prefix-format-compiled'."
5975 (setq org-prefix-has-time nil org-prefix-has-tag nil
5976 org-prefix-category-length nil
5977 org-prefix-has-effort nil)
5979 ((stringp org-agenda-prefix-format)
5980 org-agenda-prefix-format)
5981 ((assq key org-agenda-prefix-format)
5982 (cdr (assq key org-agenda-prefix-format)))
5983 (t " %-12:c%?-12t% s")))
5985 varform vars var e c f opt)
5986 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5988 (setq var (or (cdr (assoc (match-string 4 s)
5989 '(("c" . category) ("t" . time) ("s" . extra)
5990 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5992 c (or (match-string 3 s) "")
5993 opt (match-beginning 1)
5994 start (1+ (match-beginning 0)))
5995 (if (equal var 'time) (setq org-prefix-has-time t))
5996 (if (equal var 'tag) (setq org-prefix-has-tag t))
5997 (if (equal var 'effort) (setq org-prefix-has-effort t))
5998 (setq f (concat "%" (match-string 2 s) "s"))
5999 (when (equal var 'category)
6000 (setq org-prefix-category-length
6001 (floor (abs (string-to-number (match-string 2 s)))))
6002 (setq org-prefix-category-max-length
6003 (let ((x (match-string 2 s)))
6005 (if (string-match "\\.[0-9]+" x)
6006 (string-to-number (substring (match-string 0 x) 1)))))))
6008 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6011 `(if (equal "" ,var)
6013 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6014 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6015 (setq s (replace-match "%s" t nil s))
6016 (push varform vars))
6017 (setq vars (nreverse vars))
6018 (with-current-buffer org-agenda-buffer
6019 (setq org-prefix-format-compiled
6021 `((org-prefix-has-time ,org-prefix-has-time)
6022 (org-prefix-has-tag ,org-prefix-has-tag)
6023 (org-prefix-category-length ,org-prefix-category-length)
6024 (org-prefix-has-effort ,org-prefix-has-effort))
6025 `(format ,s ,@vars))))))
6027 (defun org-set-sorting-strategy (key)
6028 (if (symbolp (car org-agenda-sorting-strategy))
6030 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6031 (setq org-agenda-sorting-strategy-selected
6032 (or (cdr (assq key org-agenda-sorting-strategy))
6033 (cdr (assq 'agenda org-agenda-sorting-strategy))
6034 '(time-up category-keep priority-down)))))
6036 (defun org-get-time-of-day (s &optional string mod24)
6037 "Check string S for a time of day.
6038 If found, return it as a military time number between 0 and 2400.
6039 If not found, return nil.
6040 The optional STRING argument forces conversion into a 5 character wide string
6044 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6045 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6046 (let* ((h (string-to-number (match-string 1 s)))
6047 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6048 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6049 (am-p (equal ampm "am"))
6050 (h1 (cond ((not ampm) h)
6051 ((= h 12) (if am-p 0 12))
6052 (t (+ h (if am-p 0 12)))))
6053 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6055 (t0 (+ (* 100 h2) m))
6056 (t1 (concat (if (>= h1 24) "+" " ")
6057 (if (and org-agenda-time-leading-zero
6058 (< t0 1000)) "0" "")
6059 (if (< t0 100) "0" "")
6060 (if (< t0 10) "0" "")
6061 (int-to-string t0))))
6062 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6064 (defvar org-agenda-before-sorting-filter-function nil
6065 "Function to be applied to agenda items prior to sorting.
6066 Prior to sorting also means just before they are inserted into the agenda.
6068 To aid sorting, you may revisit the original entries and add more text
6069 properties which will later be used by the sorting functions.
6071 The function should take a string argument, an agenda line.
6072 It has access to the text properties in that line, which contain among
6073 other things, the property `org-hd-marker' that points to the entry
6074 where the line comes from. Note that not all lines going into the agenda
6075 have this property, only most.
6077 The function should return the modified string. It is probably best
6078 to ONLY change text properties.
6080 You can also use this function as a filter, by returning nil for lines
6081 you don't want to have in the agenda at all. For this application, you
6082 could bind the variable in the options section of a custom command.")
6084 (defun org-finalize-agenda-entries (list &optional nosort)
6085 "Sort and concatenate the agenda items."
6086 (setq list (mapcar 'org-agenda-highlight-todo list))
6089 (when org-agenda-before-sorting-filter-function
6090 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6091 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6093 (defun org-agenda-highlight-todo (x)
6094 (let ((org-done-keywords org-done-keywords-for-agenda)
6095 (case-fold-search nil)
6099 (beginning-of-line 1)
6100 (setq re (org-get-at-bol 'org-todo-regexp))
6101 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6102 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6103 (add-text-properties (match-beginning 0) (match-end 1)
6104 (list 'face (org-get-todo-face 1)))
6105 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6106 (delete-region (match-beginning 1) (1- (match-end 0)))
6107 (goto-char (match-beginning 1))
6108 (insert (format org-agenda-todo-keyword-format s)))))
6109 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6110 (setq re (get-text-property 0 'org-todo-regexp x))
6112 ;; Test `pl' because if there's no heading content,
6113 ;; there's no point matching to highlight. Note
6114 ;; that if we didn't test `pl' first, and there
6115 ;; happened to be no keyword from `org-todo-regexp'
6116 ;; on this heading line, then the `equal' comparison
6117 ;; afterwards would spuriously succeed in the case
6118 ;; where `pl' is nil -- causing an args-out-of-range
6119 ;; error when we try to add text properties to text
6120 ;; that isn't there.
6122 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6124 (add-text-properties
6125 (or (match-end 1) (match-end 0)) (match-end 0)
6126 (list 'face (org-get-todo-face (match-string 2 x)))
6129 (setq x (concat (substring x 0 (match-end 1))
6130 (format org-agenda-todo-keyword-format
6132 (org-add-props " " (text-properties-at 0 x))
6133 (substring x (match-end 3)))))))
6136 (defsubst org-cmp-priority (a b)
6137 "Compare the priorities of string A and B."
6138 (let ((pa (or (get-text-property 1 'priority a) 0))
6139 (pb (or (get-text-property 1 'priority b) 0)))
6140 (cond ((> pa pb) +1)
6144 (defsubst org-cmp-effort (a b)
6145 "Compare the effort values of string A and B."
6146 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6147 (ea (or (get-text-property 1 'effort-minutes a) def))
6148 (eb (or (get-text-property 1 'effort-minutes b) def)))
6149 (cond ((> ea eb) +1)
6153 (defsubst org-cmp-category (a b)
6154 "Compare the string values of categories of strings A and B."
6155 (let ((ca (or (get-text-property 1 'org-category a) ""))
6156 (cb (or (get-text-property 1 'org-category b) "")))
6157 (cond ((string-lessp ca cb) -1)
6158 ((string-lessp cb ca) +1)
6161 (defsubst org-cmp-todo-state (a b)
6162 "Compare the todo states of strings A and B."
6163 (let* ((ma (or (get-text-property 1 'org-marker a)
6164 (get-text-property 1 'org-hd-marker a)))
6165 (mb (or (get-text-property 1 'org-marker b)
6166 (get-text-property 1 'org-hd-marker b)))
6167 (fa (and ma (marker-buffer ma)))
6168 (fb (and mb (marker-buffer mb)))
6170 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6171 (and fb (with-current-buffer fb org-todo-keywords-1))))
6172 (ta (or (get-text-property 1 'todo-state a) ""))
6173 (tb (or (get-text-property 1 'todo-state b) ""))
6174 (la (- (length (member ta todo-kwds))))
6175 (lb (- (length (member tb todo-kwds))))
6176 (donepa (member ta org-done-keywords-for-agenda))
6177 (donepb (member tb org-done-keywords-for-agenda)))
6178 (cond ((and donepa (not donepb)) -1)
6179 ((and (not donepa) donepb) +1)
6184 (defsubst org-cmp-alpha (a b)
6185 "Compare the headlines, alphabetically."
6186 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6187 (plb (text-property-any 0 (length b) 'org-heading t b))
6188 (ta (and pla (substring a pla)))
6189 (tb (and plb (substring b plb))))
6191 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6192 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6193 (setq ta (substring ta (match-end 0))))
6194 (setq ta (downcase ta)))
6196 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6197 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6198 (setq tb (substring tb (match-end 0))))
6199 (setq tb (downcase tb)))
6202 ((string-lessp ta tb) -1)
6203 ((string-lessp tb ta) +1)
6206 (defsubst org-cmp-tag (a b)
6207 "Compare the string values of the first tags of A and B."
6208 (let ((ta (car (last (get-text-property 1 'tags a))))
6209 (tb (car (last (get-text-property 1 'tags b)))))
6212 ((string-lessp ta tb) -1)
6213 ((string-lessp tb ta) +1)
6216 (defsubst org-cmp-time (a b)
6217 "Compare the time-of-day values of strings A and B."
6218 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6219 (ta (or (get-text-property 1 'time-of-day a) def))
6220 (tb (or (get-text-property 1 'time-of-day b) def)))
6221 (cond ((< ta tb) -1)
6225 (defsubst org-cmp-habit-p (a b)
6226 "Compare the todo states of strings A and B."
6227 (let ((ha (get-text-property 1 'org-habit-p a))
6228 (hb (get-text-property 1 'org-habit-p b)))
6229 (cond ((and ha (not hb)) -1)
6230 ((and (not ha) hb) +1)
6233 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6235 (defun org-entries-lessp (a b)
6236 "Predicate for sorting agenda entries."
6237 ;; The following variables will be used when the form is evaluated.
6238 ;; So even though the compiler complains, keep them.
6239 (let* ((ss org-agenda-sorting-strategy-selected)
6240 (time-up (and (org-em 'time-up 'time-down ss)
6241 (org-cmp-time a b)))
6242 (time-down (if time-up (- time-up) nil))
6243 (priority-up (and (org-em 'priority-up 'priority-down ss)
6244 (org-cmp-priority a b)))
6245 (priority-down (if priority-up (- priority-up) nil))
6246 (effort-up (and (org-em 'effort-up 'effort-down ss)
6247 (org-cmp-effort a b)))
6248 (effort-down (if effort-up (- effort-up) nil))
6249 (category-up (and (or (org-em 'category-up 'category-down ss)
6250 (memq 'category-keep ss))
6251 (org-cmp-category a b)))
6252 (category-down (if category-up (- category-up) nil))
6253 (category-keep (if category-up +1 nil))
6254 (tag-up (and (org-em 'tag-up 'tag-down ss)
6256 (tag-down (if tag-up (- tag-up) nil))
6257 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6258 (org-cmp-todo-state a b)))
6259 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6260 (habit-up (and (org-em 'habit-up 'habit-down ss)
6261 (org-cmp-habit-p a b)))
6262 (habit-down (if habit-up (- habit-up) nil))
6263 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6264 (org-cmp-alpha a b)))
6265 (alpha-down (if alpha-up (- alpha-up) nil))
6266 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6267 user-defined-up user-defined-down)
6268 (if (and need-user-cmp org-agenda-cmp-user-defined
6269 (functionp org-agenda-cmp-user-defined))
6270 (setq user-defined-up
6271 (funcall org-agenda-cmp-user-defined a b)
6272 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6274 (eval (cons 'or org-agenda-sorting-strategy-selected))
6275 '((-1 . t) (1 . nil) (nil . nil))))))
6277 ;;; Agenda restriction lock
6279 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6280 "Overlay to mark the headline to which agenda commands are restricted.")
6281 (overlay-put org-agenda-restriction-lock-overlay
6282 'face 'org-agenda-restriction-lock)
6283 (overlay-put org-agenda-restriction-lock-overlay
6284 'help-echo "Agendas are currently limited to this subtree.")
6285 (org-detach-overlay org-agenda-restriction-lock-overlay)
6287 (defun org-agenda-set-restriction-lock (&optional type)
6288 "Set restriction lock for agenda, to current subtree or file.
6289 Restriction will be the file if TYPE is `file', or if type is the
6290 universal prefix '(4), or if the cursor is before the first headline
6291 in the file. Otherwise, restriction will be to the current subtree."
6293 (and (equal type '(4)) (setq type 'file))
6296 ((org-at-heading-p) 'subtree)
6297 ((condition-case nil (org-back-to-heading t) (error nil))
6300 (if (eq type 'subtree)
6302 (setq org-agenda-restrict t)
6303 (setq org-agenda-overriding-restriction 'subtree)
6304 (put 'org-agenda-files 'org-restrict
6305 (list (buffer-file-name (buffer-base-buffer))))
6306 (org-back-to-heading t)
6307 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6308 (move-marker org-agenda-restrict-begin (point))
6309 (move-marker org-agenda-restrict-end
6310 (save-excursion (org-end-of-subtree t)))
6311 (message "Locking agenda restriction to subtree"))
6312 (put 'org-agenda-files 'org-restrict
6313 (list (buffer-file-name (buffer-base-buffer))))
6314 (setq org-agenda-restrict nil)
6315 (setq org-agenda-overriding-restriction 'file)
6316 (move-marker org-agenda-restrict-begin nil)
6317 (move-marker org-agenda-restrict-end nil)
6318 (message "Locking agenda restriction to file"))
6319 (setq current-prefix-arg nil)
6320 (org-agenda-maybe-redo))
6322 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6323 "Remove the agenda restriction lock."
6325 (org-detach-overlay org-agenda-restriction-lock-overlay)
6326 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6327 (setq org-agenda-overriding-restriction nil)
6328 (setq org-agenda-restrict nil)
6329 (put 'org-agenda-files 'org-restrict nil)
6330 (move-marker org-agenda-restrict-begin nil)
6331 (move-marker org-agenda-restrict-end nil)
6332 (setq current-prefix-arg nil)
6333 (message "Agenda restriction lock removed")
6334 (or noupdate (org-agenda-maybe-redo)))
6336 (defun org-agenda-maybe-redo ()
6337 "If there is any window showing the agenda view, update it."
6338 (let ((w (get-buffer-window org-agenda-buffer-name t))
6339 (w0 (selected-window)))
6344 (if org-agenda-overriding-restriction
6345 (message "Agenda view shifted to new %s restriction"
6346 org-agenda-overriding-restriction)
6347 (message "Agenda restriction lock removed")))))
6351 (defun org-agenda-check-type (error &rest types)
6352 "Check if agenda buffer is of allowed type.
6353 If ERROR is non-nil, throw an error, otherwise just return nil."
6354 (if (memq org-agenda-type types)
6357 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6360 (defun org-agenda-Quit (&optional arg)
6361 "Exit agenda by removing the window or the buffer"
6363 (if org-agenda-columns-active
6365 (let ((buf (current-buffer)))
6366 (if (eq org-agenda-window-setup 'other-frame)
6368 (org-agenda-reset-markers)
6370 (org-columns-remove-overlays)
6371 (setq org-agenda-archives-mode nil)
6373 (and (not (eq org-agenda-window-setup 'current-window))
6374 (not (one-window-p))
6376 (org-agenda-reset-markers)
6378 (org-columns-remove-overlays)
6379 (setq org-agenda-archives-mode nil)))
6380 ;; Maybe restore the pre-agenda window configuration.
6381 (and org-agenda-restore-windows-after-quit
6382 (not (eq org-agenda-window-setup 'other-frame))
6383 org-pre-agenda-window-conf
6384 (set-window-configuration org-pre-agenda-window-conf))))
6386 (defun org-agenda-quit ()
6387 "Exit agenda by killing agenda buffer or burying it when
6388 `org-agenda-sticky' is non-NIL"
6390 (if org-agenda-columns-active
6392 (if org-agenda-sticky
6393 (let ((buf (current-buffer)))
6394 (if (eq org-agenda-window-setup 'other-frame)
6397 (and (not (eq org-agenda-window-setup 'current-window))
6398 (not (one-window-p))
6400 (with-current-buffer buf
6402 (org-agenda-Quit))))
6404 (defun org-agenda-exit ()
6405 "Exit agenda by removing the window or the buffer.
6406 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6407 Org-mode buffers visited directly by the user will not be touched."
6409 (org-release-buffers org-agenda-new-buffers)
6410 (setq org-agenda-new-buffers nil)
6413 (defun org-agenda-kill-all-agenda-buffers ()
6414 "Kill all buffers in `org-agena-mode'.
6415 This is used when toggling sticky agendas. You can also explicitly invoke it
6419 (dolist (buf (buffer-list))
6420 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6422 (mapc 'kill-buffer blist)))
6424 (defun org-agenda-execute (arg)
6425 "Execute another agenda command, keeping same window.
6426 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6429 (let ((org-agenda-window-setup 'current-window))
6432 (defun org-agenda-redo ()
6434 When this is the global TODO list, a prefix argument will be interpreted."
6436 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6437 (org-agenda-sticky nil)
6438 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6439 org-agenda-buffer-name))
6440 (org-agenda-keep-modes t)
6441 (tag-filter org-agenda-tag-filter)
6442 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6443 (cat-filter org-agenda-category-filter)
6444 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6445 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6446 (cols org-agenda-columns-active)
6447 (line (org-current-line))
6448 (window-line (- line (org-current-line (window-start))))
6449 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6450 (put 'org-agenda-tag-filter :preset-filter nil)
6451 (put 'org-agenda-category-filter :preset-filter nil)
6452 (and cols (org-columns-quit))
6453 (message "Rebuilding agenda buffer...")
6454 (org-let lprops '(eval org-agenda-redo-command))
6455 (setq org-agenda-undo-list nil
6456 org-agenda-pending-undo-list nil)
6457 (message "Rebuilding agenda buffer...done")
6458 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6459 (put 'org-agenda-category-filter :preset-filter cat-preset)
6460 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6461 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6462 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6463 (org-goto-line line)
6464 (recenter window-line)))
6466 (defvar org-global-tags-completion-table nil)
6467 (defvar org-agenda-filtered-by-category nil)
6468 (defvar org-agenda-filter-form nil)
6470 (defun org-agenda-filter-by-category (strip)
6471 "Keep only those lines in the agenda buffer that have a specific category.
6472 The category is that of the current line."
6474 (if org-agenda-filtered-by-category
6475 (org-agenda-filter-show-all-cat)
6476 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6477 (if cat (org-agenda-filter-apply
6478 (list (concat (if strip "-" "+") cat)) 'category)
6479 (error "No category at point")))))
6481 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6482 "Keep only those lines in the agenda buffer that have a specific tag.
6483 The tag is selected with its fast selection letter, as configured.
6484 With prefix argument STRIP, remove all lines that do have the tag.
6485 A lisp caller can specify CHAR. NARROW means that the new tag should be
6486 used to narrow the search - the interactive user can also press `-' or `+'
6487 to switch to narrowing."
6489 (let* ((alist org-tag-alist-for-agenda)
6490 (tag-chars (mapconcat
6491 (lambda (x) (if (and (not (symbolp (car x)))
6493 (char-to-string (cdr x))
6496 (efforts (org-split-string
6497 (or (cdr (assoc (concat org-effort-property "_ALL")
6498 org-global-properties))
6499 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6501 (effort-op org-agenda-filter-effort-default-operator)
6503 (inhibit-read-only t)
6504 (current org-agenda-tag-filter)
6505 maybe-refresh a n tag)
6508 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6509 (if narrow "Narrow" "Filter") tag-chars
6510 (if org-agenda-auto-exclude-function "[RET], " ""))
6511 (setq char (read-char-exclusive)))
6512 (when (member char '(?+ ?-))
6514 (cond ((equal char ?-) (setq strip t narrow t))
6515 ((equal char ?+) (setq strip nil narrow t)))
6517 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6518 (setq char (read-char-exclusive)))
6519 (when (member char '(?< ?> ?= ??))
6520 ;; An effort operator
6521 (setq effort-op (char-to-string char))
6522 (setq alist nil) ; to make sure it will be interpreted as effort.
6523 (unless (equal char ??)
6524 (loop for i from 0 to 9 do
6528 (if (= i 9) "0" (int-to-string (1+ i)))
6529 "]" (nth i efforts))))
6530 (message "Effort%s: %s " effort-op effort-prompt)
6531 (setq char (read-char-exclusive))
6532 (when (or (< char ?0) (> char ?9))
6533 (error "Need 1-9,0 to select effort"))))
6534 (when (equal char ?\t)
6535 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6536 (org-set-local 'org-global-tags-completion-table
6537 (org-global-tags-completion-table)))
6538 (let ((completion-ignore-case t))
6539 (setq tag (org-icompleting-read
6540 "Tag: " org-global-tags-completion-table))))
6543 (org-agenda-filter-show-all-tag)
6544 (when org-agenda-auto-exclude-function
6545 (setq org-agenda-tag-filter '())
6546 (dolist (tag (org-agenda-get-represented-tags))
6547 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6549 (push modifier org-agenda-tag-filter))))
6550 (if (not (null org-agenda-tag-filter))
6551 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6552 (setq maybe-refresh t))
6554 (org-agenda-filter-show-all-tag)
6555 (when (get 'org-agenda-tag-filter :preset-filter)
6556 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6557 (setq maybe-refresh t))
6559 (setq org-agenda-tag-filter
6560 (mapcar (lambda(tag) (concat "+" tag))
6561 (org-get-at-bol 'tags)))
6562 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6563 (setq maybe-refresh t))
6564 ((or (equal char ?\ )
6565 (setq a (rassoc char alist))
6566 (and (>= char ?0) (<= char ?9)
6567 (setq n (if (= char ?0) 9 (- char ?0 1))
6568 tag (concat effort-op (nth n efforts))
6573 (and tag (setq a (cons tag nil))))
6574 (org-agenda-filter-show-all-tag)
6576 (setq org-agenda-tag-filter
6577 (cons (concat (if strip "-" "+") tag)
6578 (if narrow current nil)))
6579 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6580 (setq maybe-refresh t))
6581 (t (error "Invalid tag selection character %c" char)))
6582 (when (and maybe-refresh
6583 (eq org-agenda-clockreport-mode 'with-filter))
6584 (org-agenda-redo))))
6586 (defun org-agenda-get-represented-tags ()
6587 "Get a list of all tags currently represented in the agenda."
6590 (goto-char (point-min))
6591 (while (setq p (next-single-property-change (point) 'tags))
6593 (mapc (lambda (x) (add-to-list 'tags x))
6594 (get-text-property (point) 'tags))))
6597 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6598 "Refine the current filter. See `org-agenda-filter-by-tag'."
6600 (org-agenda-filter-by-tag strip char 'refine))
6602 (defun org-agenda-filter-make-matcher ()
6603 "Create the form that tests a line for agenda filter."
6605 ;; first compute the tag-filter matcher
6606 (dolist (x (delete-dups
6607 (append (get 'org-agenda-tag-filter
6608 :preset-filter) org-agenda-tag-filter)))
6609 (if (member x '("-" "+"))
6610 (setq f1 (if (equal x "-") 'tags '(not tags)))
6611 (if (string-match "[<=>?]" x)
6612 (setq f1 (org-agenda-filter-effort-form x))
6613 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6614 (if (equal (string-to-char x) ?-)
6615 (setq f1 (list 'not f1))))
6617 ;; then compute the category-filter matcher
6618 (dolist (x (delete-dups
6619 (append (get 'org-agenda-category-filter
6620 :preset-filter) org-agenda-category-filter)))
6621 (setq f1 (list 'equal (substring x 1) 'cat))
6623 (cons 'and (nreverse f))))
6625 (defun org-agenda-filter-effort-form (e)
6626 "Return the form to compare the effort of the current line with what E says.
6627 E looks like \"+<2:25\"."
6629 (setq e (substring e 1))
6630 (setq op (string-to-char e) e (substring e 1))
6631 (setq op (cond ((equal op ?<) '<=)
6635 (list 'org-agenda-compare-effort (list 'quote op)
6636 (org-duration-string-to-minutes e))))
6638 (defun org-agenda-compare-effort (op value)
6639 "Compare the effort of the current line with VALUE, using OP.
6640 If the line does not have an effort defined, return nil."
6641 (let ((eff (org-get-at-bol 'effort-minutes)))
6644 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6647 (defun org-agenda-filter-apply (filter type)
6648 "Set FILTER as the new agenda filter and apply it."
6651 (setq org-agenda-tag-filter filter)
6652 (setq org-agenda-category-filter filter
6653 org-agenda-filtered-by-category t))
6654 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6655 (org-agenda-set-mode-name)
6657 (goto-char (point-min))
6659 (if (org-get-at-bol 'org-marker)
6661 (setq tags (org-get-at-bol 'tags) ; used in eval
6662 cat (get-text-property (point) 'org-category))
6663 (if (not (eval org-agenda-filter-form))
6664 (org-agenda-filter-hide-line type))
6665 (beginning-of-line 2))
6666 (beginning-of-line 2))))
6667 (if (get-char-property (point) 'invisible)
6668 (org-agenda-previous-line))))
6670 (defun org-agenda-filter-hide-line (type)
6672 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6674 (overlay-put ov 'invisible t)
6675 (overlay-put ov 'type type)
6677 (push ov org-agenda-tag-filter-overlays)
6678 (push ov org-agenda-cat-filter-overlays))))
6680 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6681 (setq pos (or pos (point)))
6683 (dolist (ov (overlays-at pos))
6684 (when (and (overlay-get ov 'invisible)
6685 (eq (overlay-get ov 'type) 'tag))
6687 (if (< (overlay-start ov) (point-at-eol))
6688 (move-overlay ov (point-at-eol)
6689 (overlay-end ov)))))))
6691 (defun org-agenda-filter-show-all-tag nil
6692 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6693 (setq org-agenda-tag-filter-overlays nil
6694 org-agenda-tag-filter nil
6695 org-agenda-filter-form nil)
6696 (org-agenda-set-mode-name))
6698 (defun org-agenda-filter-show-all-cat nil
6699 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6700 (setq org-agenda-cat-filter-overlays nil
6701 org-agenda-filtered-by-category nil
6702 org-agenda-category-filter nil
6703 org-agenda-filter-form nil)
6704 (org-agenda-set-mode-name))
6706 (defun org-agenda-manipulate-query-add ()
6707 "Manipulate the query by adding a search term with positive selection.
6708 Positive selection means the term must be matched for selection of an entry."
6710 (org-agenda-manipulate-query ?\[))
6711 (defun org-agenda-manipulate-query-subtract ()
6712 "Manipulate the query by adding a search term with negative selection.
6713 Negative selection means term must not be matched for selection of an entry."
6715 (org-agenda-manipulate-query ?\]))
6716 (defun org-agenda-manipulate-query-add-re ()
6717 "Manipulate the query by adding a search regexp with positive selection.
6718 Positive selection means the regexp must match for selection of an entry."
6720 (org-agenda-manipulate-query ?\{))
6721 (defun org-agenda-manipulate-query-subtract-re ()
6722 "Manipulate the query by adding a search regexp with negative selection.
6723 Negative selection means regexp must not match for selection of an entry."
6725 (org-agenda-manipulate-query ?\}))
6726 (defun org-agenda-manipulate-query (char)
6728 ((memq org-agenda-type '(timeline agenda))
6729 (let ((org-agenda-include-inactive-timestamps t))
6731 (message "Display now includes inactive timestamps as well"))
6732 ((eq org-agenda-type 'search)
6734 'org-agenda-query-string
6735 (if org-agenda-last-search-view-search-was-boolean
6736 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6737 (?\{ . " +{}") (?\} . " -{}"))))
6739 (setq org-agenda-redo-command
6740 (list 'org-search-view
6742 org-agenda-query-string
6743 (+ (length org-agenda-query-string)
6744 (if (member char '(?\{ ?\})) 0 1))))
6745 (set-register org-agenda-query-register org-agenda-query-string)
6747 (t (error "Cannot manipulate query for %s-type agenda buffers"
6750 (defun org-add-to-string (var string)
6751 (set var (concat (symbol-value var) string)))
6753 (defun org-agenda-goto-date (date)
6754 "Jump to DATE in agenda."
6755 (interactive (list (let ((org-read-date-prefer-future
6756 (eval org-agenda-jump-prefer-future)))
6758 (org-agenda-list nil date))
6760 (defun org-agenda-goto-today ()
6763 (org-agenda-check-type t 'timeline 'agenda)
6764 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6766 (tdpos (goto-char tdpos))
6767 ((eq org-agenda-type 'agenda)
6768 (let* ((sd (org-agenda-compute-starting-span
6769 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6770 (org-agenda-overriding-arguments org-agenda-last-arguments))
6771 (setf (nth 1 org-agenda-overriding-arguments) sd)
6773 (org-agenda-find-same-or-today-or-agenda)))
6774 (t (error "Cannot find today")))))
6776 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6778 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6779 (text-property-any (point-min) (point-max) 'org-today t)
6780 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6783 (defun org-agenda-later (arg)
6784 "Go forward in time by thee current span.
6785 With prefix ARG, go forward that many times the current span."
6787 (org-agenda-check-type t 'agenda)
6788 (let* ((span org-agenda-current-span)
6789 (sd org-starting-day)
6790 (greg (calendar-gregorian-from-absolute sd))
6791 (cnt (org-get-at-bol 'org-day-cnt))
6795 (setq sd (+ arg sd)))
6797 (setq sd (+ (* 7 arg) sd)))
6799 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6800 sd (calendar-absolute-from-gregorian greg2))
6801 (setcar greg2 (1+ (car greg2))))
6803 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6804 sd (calendar-absolute-from-gregorian greg2))
6805 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6807 (setq sd (+ (* span arg) sd))))
6808 (let ((org-agenda-overriding-arguments
6809 (list (car org-agenda-last-arguments) sd span t)))
6811 (org-agenda-find-same-or-today-or-agenda cnt))))
6813 (defun org-agenda-earlier (arg)
6814 "Go backward in time by the current span.
6815 With prefix ARG, go backward that many times the current span."
6817 (org-agenda-later (- arg)))
6819 (defun org-agenda-view-mode-dispatch ()
6820 "Call one of the view mode commands."
6822 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6823 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6824 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6826 (let ((a (read-char-exclusive)))
6828 (?\ (call-interactively 'org-agenda-reset-view))
6829 (?d (call-interactively 'org-agenda-day-view))
6830 (?w (call-interactively 'org-agenda-week-view))
6831 (?m (call-interactively 'org-agenda-month-view))
6832 (?y (call-interactively 'org-agenda-year-view))
6833 (?l (call-interactively 'org-agenda-log-mode))
6834 (?L (org-agenda-log-mode '(4)))
6835 (?c (org-agenda-log-mode 'clockcheck))
6836 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6837 (?a (call-interactively 'org-agenda-archives-mode))
6838 (?A (org-agenda-archives-mode 'files))
6839 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6840 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6841 (?G (call-interactively 'org-agenda-toggle-time-grid))
6842 (?D (call-interactively 'org-agenda-toggle-diary))
6843 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6844 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6845 (org-agenda-check-type t 'timeline 'agenda)
6847 (message "Display now includes inactive timestamps as well"))
6848 (?q (message "Abort"))
6849 (otherwise (error "Invalid key" )))))
6851 (defun org-agenda-reset-view ()
6852 "Switch to default view for agenda."
6854 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6855 (defun org-agenda-day-view (&optional day-of-year)
6856 "Switch to daily view for agenda.
6857 With argument DAY-OF-YEAR, switch to that day of the year."
6859 (org-agenda-change-time-span 'day day-of-year))
6860 (defun org-agenda-week-view (&optional iso-week)
6861 "Switch to daily view for agenda.
6862 With argument ISO-WEEK, switch to the corresponding ISO week.
6863 If ISO-WEEK has more then 2 digits, only the last two encode the
6864 week. Any digits before this encode a year. So 200712 means
6865 week 12 of year 2007. Years in the range 1938-2037 can also be
6866 written as 2-digit years."
6868 (org-agenda-change-time-span 'week iso-week))
6869 (defun org-agenda-month-view (&optional month)
6870 "Switch to monthly view for agenda.
6871 With argument MONTH, switch to that month."
6873 (org-agenda-change-time-span 'month month))
6874 (defun org-agenda-year-view (&optional year)
6875 "Switch to yearly view for agenda.
6876 With argument YEAR, switch to that year.
6877 If MONTH has more then 2 digits, only the last two encode the
6878 month. Any digits before this encode a year. So 200712 means
6879 December year 2007. Years in the range 1938-2037 can also be
6880 written as 2-digit years."
6883 (setq year (org-small-year-to-year year)))
6884 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6885 (org-agenda-change-time-span 'year year)
6888 (defun org-agenda-change-time-span (span &optional n)
6889 "Change the agenda view to SPAN.
6890 SPAN may be `day', `week', `month', `year'."
6891 (org-agenda-check-type t 'agenda)
6892 (if (and (not n) (equal org-agenda-current-span span))
6893 (error "Viewing span is already \"%s\"" span))
6894 (let* ((sd (or (org-get-at-bol 'day)
6896 (sd (org-agenda-compute-starting-span sd span n))
6897 (org-agenda-overriding-arguments
6898 (or org-agenda-overriding-arguments
6899 (list (car org-agenda-last-arguments) sd span t))))
6901 (org-agenda-find-same-or-today-or-agenda))
6902 (org-agenda-set-mode-name)
6903 (message "Switched to %s view" span))
6905 (defun org-agenda-compute-starting-span (sd span &optional n)
6906 "Compute starting date for agenda.
6907 SPAN may be `day', `week', `month', `year'. The return value
6908 is a cons cell with the starting date and the number of days,
6909 so that the date SD will be in that range."
6910 (let* ((greg (calendar-gregorian-from-absolute sd))
6917 (setq sd (+ (calendar-absolute-from-gregorian
6921 (let* ((nt (calendar-day-of-week
6922 (calendar-gregorian-from-absolute sd)))
6923 (d (if org-agenda-start-on-weekday
6924 (- nt org-agenda-start-on-weekday)
6927 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6931 (setq y1 (org-small-year-to-year (/ n 100))
6934 (calendar-absolute-from-iso
6936 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6939 (when (and n (> n 99))
6940 (setq y1 (org-small-year-to-year (/ n 100))
6942 (setq sd (calendar-absolute-from-gregorian
6943 (list (or n mg) 1 (or y1 yg))))))
6945 (setq sd (calendar-absolute-from-gregorian
6946 (list 1 1 (or n yg))))))
6949 (defun org-agenda-next-date-line (&optional arg)
6950 "Jump to the next line indicating a date in agenda buffer."
6952 (org-agenda-check-type t 'agenda 'timeline)
6953 (beginning-of-line 1)
6954 ;; This does not work if user makes date format that starts with a blank
6955 (if (looking-at "^\\S-") (forward-char 1))
6956 (if (not (re-search-forward "^\\S-" nil t arg))
6959 (error "No next date after this line in this buffer")))
6960 (goto-char (match-beginning 0)))
6962 (defun org-agenda-previous-date-line (&optional arg)
6963 "Jump to the previous line indicating a date in agenda buffer."
6965 (org-agenda-check-type t 'agenda 'timeline)
6966 (beginning-of-line 1)
6967 (if (not (re-search-backward "^\\S-" nil t arg))
6968 (error "No previous date before this line in this buffer")))
6970 ;; Initialize the highlight
6971 (defvar org-hl (make-overlay 1 1))
6972 (overlay-put org-hl 'face 'highlight)
6974 (defun org-highlight (begin end &optional buffer)
6975 "Highlight a region with overlay."
6976 (move-overlay org-hl begin end (or buffer (current-buffer))))
6978 (defun org-unhighlight ()
6979 "Detach overlay INDEX."
6980 (org-detach-overlay org-hl))
6982 ;; FIXME this is currently not used.
6983 (defun org-highlight-until-next-command (beg end &optional buffer)
6984 "Move the highlight overlay to BEG/END, remove it before the next command."
6985 (org-highlight beg end buffer)
6986 (add-hook 'pre-command-hook 'org-unhighlight-once))
6987 (defun org-unhighlight-once ()
6988 "Remove the highlight from its position, and this function from the hook."
6989 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6992 (defun org-agenda-follow-mode ()
6993 "Toggle follow mode in an agenda buffer."
6995 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6996 (org-agenda-set-mode-name)
6997 (org-agenda-do-context-action)
6998 (message "Follow mode is %s"
6999 (if org-agenda-follow-mode "on" "off")))
7001 (defun org-agenda-entry-text-mode (&optional arg)
7002 "Toggle entry text mode in an agenda buffer."
7004 (setq org-agenda-entry-text-mode (or (integerp arg)
7005 (not org-agenda-entry-text-mode)))
7006 (org-agenda-entry-text-hide)
7007 (and org-agenda-entry-text-mode
7008 (let ((org-agenda-entry-text-maxlines
7009 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7010 (org-agenda-entry-text-show)))
7011 (org-agenda-set-mode-name)
7012 (message "Entry text mode is %s. Maximum number of lines is %d"
7013 (if org-agenda-entry-text-mode "on" "off")
7014 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7016 (defun org-agenda-clockreport-mode (&optional with-filter)
7017 "Toggle clocktable mode in an agenda buffer.
7018 With prefix arg WITH-FILTER, make the clocktable respect the current
7021 (org-agenda-check-type t 'agenda)
7023 (setq org-agenda-clockreport-mode 'with-filter)
7024 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7025 (org-agenda-set-mode-name)
7027 (message "Clocktable mode is %s"
7028 (if org-agenda-clockreport-mode "on" "off")))
7030 (defun org-agenda-log-mode (&optional special)
7031 "Toggle log mode in an agenda buffer.
7032 With argument SPECIAL, show all possible log items, not only the ones
7033 configured in `org-agenda-log-mode-items'.
7034 With a double `C-u' prefix arg, show *only* log items, nothing else."
7036 (org-agenda-check-type t 'agenda 'timeline)
7037 (setq org-agenda-show-log
7039 ((equal special '(16)) 'only)
7040 ((eq special 'clockcheck)
7041 (if (eq org-agenda-show-log 'clockcheck)
7043 (special '(closed clock state))
7044 (t (not org-agenda-show-log))))
7045 (org-agenda-set-mode-name)
7047 (message "Log mode is %s"
7048 (if org-agenda-show-log "on" "off")))
7050 (defun org-agenda-archives-mode (&optional with-files)
7051 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7052 When called with a prefix argument, include all archive files as well."
7054 (setq org-agenda-archives-mode
7055 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7056 (org-agenda-set-mode-name)
7061 ((eq org-agenda-archives-mode nil)
7062 "No archives are included")
7063 ((eq org-agenda-archives-mode 'trees)
7064 (format "Trees with :%s: tag are included" org-archive-tag))
7065 ((eq org-agenda-archives-mode t)
7066 (format "Trees with :%s: tag and all active archive files are included"
7067 org-archive-tag)))))
7069 (defun org-agenda-toggle-diary ()
7070 "Toggle diary inclusion in an agenda buffer."
7072 (org-agenda-check-type t 'agenda)
7073 (setq org-agenda-include-diary (not org-agenda-include-diary))
7075 (org-agenda-set-mode-name)
7076 (message "Diary inclusion turned %s"
7077 (if org-agenda-include-diary "on" "off")))
7079 (defun org-agenda-toggle-deadlines ()
7080 "Toggle inclusion of entries with a deadline in an agenda buffer."
7082 (org-agenda-check-type t 'agenda)
7083 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7085 (org-agenda-set-mode-name)
7086 (message "Deadlines inclusion turned %s"
7087 (if org-agenda-include-deadlines "on" "off")))
7089 (defun org-agenda-toggle-time-grid ()
7090 "Toggle time grid in an agenda buffer."
7092 (org-agenda-check-type t 'agenda)
7093 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7095 (org-agenda-set-mode-name)
7096 (message "Time-grid turned %s"
7097 (if org-agenda-use-time-grid "on" "off")))
7099 (defun org-agenda-set-mode-name ()
7100 "Set the mode name to indicate all the small mode settings."
7103 (if (get 'org-agenda-files 'org-restrict) " []" "")
7105 '(:eval (org-agenda-span-name org-agenda-current-span))
7106 (if org-agenda-follow-mode " Follow" "")
7107 (if org-agenda-entry-text-mode " ETxt" "")
7108 (if org-agenda-include-diary " Diary" "")
7109 (if org-agenda-include-deadlines " Ddl" "")
7110 (if org-agenda-use-time-grid " Grid" "")
7111 (if (and (boundp 'org-habit-show-habits)
7112 org-habit-show-habits) " Habit" "")
7114 ((consp org-agenda-show-log) " LogAll")
7115 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7116 (org-agenda-show-log " Log")
7118 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7120 '(:eval (org-propertize
7125 (get 'org-agenda-category-filter :preset-filter)
7126 org-agenda-category-filter)
7129 'face 'org-agenda-filter-category
7130 'help-echo "Category used in filtering"))
7132 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7134 '(:eval (org-propertize
7139 (get 'org-agenda-tag-filter :preset-filter)
7140 org-agenda-tag-filter)
7143 'face 'org-agenda-filter-tags
7144 'help-echo "Tags used in filtering"))
7146 (if org-agenda-archives-mode
7147 (if (eq org-agenda-archives-mode t)
7149 (format " :%s:" org-archive-tag))
7151 (if org-agenda-clockreport-mode
7152 (if (eq org-agenda-clockreport-mode 'with-filter)
7153 " Clock{}" " Clock")
7155 (force-mode-line-update))
7157 (defun org-agenda-post-command-hook ()
7158 (setq org-agenda-type
7159 (or (get-text-property (point) 'org-agenda-type)
7160 (get-text-property (max (point-min) (1- (point)))
7161 'org-agenda-type))))
7163 (defun org-agenda-next-line ()
7164 "Move cursor to the next line, and show if follow mode is active."
7166 (call-interactively 'next-line)
7167 (org-agenda-do-context-action))
7169 (defun org-agenda-previous-line ()
7170 "Move cursor to the previous line, and show if follow-mode is active."
7172 (call-interactively 'previous-line)
7173 (org-agenda-do-context-action))
7175 (defun org-agenda-do-context-action ()
7176 "Show outline path and, maybe, follow mode window."
7177 (let ((m (org-get-at-bol 'org-marker)))
7178 (when (and (markerp m) (marker-buffer m))
7179 (and org-agenda-follow-mode
7180 (if org-agenda-follow-indirect
7181 (org-agenda-tree-to-indirect-buffer)
7183 (and org-agenda-show-outline-path
7184 (org-with-point-at m (org-display-outline-path t))))))
7186 (defun org-agenda-show-priority ()
7187 "Show the priority of the current item.
7188 This priority is composed of the main priority given with the [#A] cookies,
7189 and by additional input from the age of a schedules or deadline entry."
7191 (let* ((pri (org-get-at-bol 'priority)))
7192 (message "Priority is %d" (if pri pri -1000))))
7194 (defun org-agenda-show-tags ()
7195 "Show the tags applicable to the current item."
7197 (let* ((tags (org-get-at-bol 'tags)))
7199 (message "Tags are :%s:"
7200 (org-no-properties (mapconcat 'identity tags ":")))
7201 (message "No tags associated with this line"))))
7203 (defun org-agenda-goto (&optional highlight)
7204 "Go to the Org-mode file which contains the item at point."
7206 (let* ((marker (or (org-get-at-bol 'org-marker)
7207 (org-agenda-error)))
7208 (buffer (marker-buffer marker))
7209 (pos (marker-position marker)))
7210 (switch-to-buffer-other-window buffer)
7214 (when (eq major-mode 'org-mode)
7215 (org-show-context 'agenda)
7217 (and (outline-next-heading)
7218 (org-flag-heading nil)))) ; show the next heading
7219 (when (outline-invisible-p)
7220 (show-entry)) ; display invisible text
7221 (recenter (/ (window-height) 2))
7222 (run-hooks 'org-agenda-after-show-hook)
7223 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7225 (defvar org-agenda-after-show-hook nil
7226 "Normal hook run after an item has been shown from the agenda.
7227 Point is in the buffer where the item originated.")
7229 (defun org-agenda-kill ()
7230 "Kill the entry or subtree belonging to the current agenda entry."
7232 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7233 (let* ((marker (or (org-get-at-bol 'org-marker)
7234 (org-agenda-error)))
7235 (buffer (marker-buffer marker))
7236 (pos (marker-position marker))
7237 (type (org-get-at-bol 'type))
7238 dbeg dend (n 0) conf)
7239 (org-with-remote-undo buffer
7240 (with-current-buffer buffer
7243 (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
7244 (setq dbeg (progn (org-back-to-heading t) (point))
7245 dend (org-end-of-subtree t t))
7246 (setq dbeg (point-at-bol)
7247 dend (min (point-max) (1+ (point-at-eol)))))
7249 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7250 (setq conf (or (eq t org-agenda-confirm-kill)
7251 (and (numberp org-agenda-confirm-kill)
7252 (> n org-agenda-confirm-kill))))
7255 (format "Delete entry with %d lines in buffer \"%s\"? "
7256 n (buffer-name buffer))))
7258 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7259 (with-current-buffer buffer (delete-region dbeg dend))
7260 (message "Agenda item and source killed"))))
7262 (defvar org-archive-default-command)
7263 (defun org-agenda-archive-default ()
7264 "Archive the entry or subtree belonging to the current agenda entry."
7266 (require 'org-archive)
7267 (org-agenda-archive-with org-archive-default-command))
7269 (defun org-agenda-archive-default-with-confirmation ()
7270 "Archive the entry or subtree belonging to the current agenda entry."
7272 (require 'org-archive)
7273 (org-agenda-archive-with org-archive-default-command 'confirm))
7275 (defun org-agenda-archive ()
7276 "Archive the entry or subtree belonging to the current agenda entry."
7278 (org-agenda-archive-with 'org-archive-subtree))
7280 (defun org-agenda-archive-to-archive-sibling ()
7281 "Move the entry to the archive sibling."
7283 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7285 (defun org-agenda-archive-with (cmd &optional confirm)
7286 "Move the entry to the archive sibling."
7288 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7289 (let* ((marker (or (org-get-at-bol 'org-marker)
7290 (org-agenda-error)))
7291 (buffer (marker-buffer marker))
7292 (pos (marker-position marker)))
7293 (org-with-remote-undo buffer
7294 (with-current-buffer buffer
7295 (if (eq major-mode 'org-mode)
7297 (not (y-or-n-p "Archive this subtree or entry? ")))
7301 (org-remove-subtree-entries-from-agenda)
7302 (org-back-to-heading t)
7304 (error "Archiving works only in Org-mode files"))))))
7306 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7307 "Remove all lines in the agenda that correspond to a given subtree.
7308 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7309 If this information is not given, the function uses the tree at point."
7310 (let ((buf (or buf (current-buffer))) m p)
7312 (unless (and beg end)
7313 (org-back-to-heading t)
7315 (org-end-of-subtree t)
7317 (set-buffer (get-buffer org-agenda-buffer-name))
7319 (goto-char (point-max))
7320 (beginning-of-line 1)
7322 (when (and (setq m (org-get-at-bol 'org-marker))
7323 (equal buf (marker-buffer m))
7324 (setq p (marker-position m))
7327 (let ((inhibit-read-only t))
7328 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7329 (beginning-of-line 0))))))
7331 (defun org-agenda-refile (&optional goto rfloc no-update)
7332 "Refile the item at point."
7334 (if (equal goto '(16))
7335 (org-refile-goto-last-stored)
7336 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7337 (org-agenda-error)))
7338 (buffer (marker-buffer marker))
7339 (pos (marker-position marker))
7341 (org-refile-get-location
7342 (if goto "Goto" "Refile to") buffer
7343 org-refile-allow-creating-parent-nodes))))
7344 (with-current-buffer buffer
7349 (org-remove-subtree-entries-from-agenda)
7350 (org-refile goto buffer rfloc)))))
7351 (unless no-update (org-agenda-redo))))
7353 (defun org-agenda-open-link (&optional arg)
7354 "Follow the link in the current line, if any.
7355 This looks for a link in the displayed line in the agenda. It also looks
7356 at the text of the entry itself."
7358 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7359 (org-get-at-bol 'org-marker)))
7360 (buffer (and marker (marker-buffer marker)))
7361 (prefix (buffer-substring
7362 (point-at-bol) (point-at-eol))))
7365 (with-current-buffer buffer
7370 (org-offer-links-in-entry arg prefix)))))
7371 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7373 (beginning-of-line 1)
7374 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7375 (org-open-link-from-string (match-string 1)))
7376 (t (error "No link to open here")))))
7378 (defun org-agenda-copy-local-variable (var)
7379 "Get a variable from a referenced buffer and install it here."
7380 (let ((m (org-get-at-bol 'org-marker)))
7381 (when (and m (buffer-live-p (marker-buffer m)))
7382 (org-set-local var (with-current-buffer (marker-buffer m)
7383 (symbol-value var))))))
7385 (defun org-agenda-switch-to (&optional delete-other-windows)
7386 "Go to the Org-mode file which contains the item at point."
7388 (if (and org-return-follows-link
7389 (not (org-get-at-bol 'org-marker))
7390 (org-in-regexp org-bracket-link-regexp))
7391 (org-open-link-from-string (match-string 0))
7392 (let* ((marker (or (org-get-at-bol 'org-marker)
7393 (org-agenda-error)))
7394 (buffer (marker-buffer marker))
7395 (pos (marker-position marker)))
7396 (org-pop-to-buffer-same-window buffer)
7397 (and delete-other-windows (delete-other-windows))
7400 (when (eq major-mode 'org-mode)
7401 (org-show-context 'agenda)
7403 (and (outline-next-heading)
7404 (org-flag-heading nil))) ; show the next heading
7405 (when (outline-invisible-p)
7406 (show-entry)))))) ; display invisible text
7408 (defun org-agenda-goto-mouse (ev)
7409 "Go to the Org-mode file which contains the item at the mouse click."
7411 (mouse-set-point ev)
7414 (defun org-agenda-show (&optional full-entry)
7415 "Display the Org-mode file which contains the item at point.
7416 With prefix argument FULL-ENTRY, make the entire entry visible
7417 if it was hidden in the outline."
7419 (let ((win (selected-window)))
7421 (let ((org-show-entry-below t))
7422 (org-agenda-goto t))
7423 (org-agenda-goto t))
7424 (select-window win)))
7426 (defvar org-agenda-show-window nil)
7427 (defun org-agenda-show-and-scroll-up (&optional arg)
7428 "Display the Org-mode file which contains the item at point.
7429 When called repeatedly, scroll the window that is displaying the buffer.
7430 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7431 `show-subtree' to display the item, so that drawers and logbooks stay
7434 (let ((win (selected-window)))
7435 (if (and (window-live-p org-agenda-show-window)
7436 (eq this-command last-command))
7438 (select-window org-agenda-show-window)
7439 (ignore-errors (scroll-up)))
7441 (if arg (org-show-entry) (show-subtree))
7442 (setq org-agenda-show-window (selected-window)))
7443 (select-window win)))
7445 (defun org-agenda-show-scroll-down ()
7446 "Scroll down the window showing the agenda."
7448 (let ((win (selected-window)))
7449 (when (window-live-p org-agenda-show-window)
7450 (select-window org-agenda-show-window)
7451 (ignore-errors (scroll-down))
7452 (select-window win))))
7454 (defun org-agenda-show-1 (&optional more)
7455 "Display the Org-mode file which contains the item at point.
7456 The prefix arg selects the amount of information to display:
7459 1 just show the entry according to defaults.
7460 2 show the children view
7461 3 show the subtree view
7462 4 show the entire subtree and any LOGBOOK drawers
7463 5 show the entire subtree and any drawers
7464 With prefix argument FULL-ENTRY, make the entire entry visible
7465 if it was hidden in the outline."
7467 (let ((win (selected-window)))
7469 (org-recenter-heading 1)
7474 (org-back-to-heading)
7475 (run-hook-with-args 'org-cycle-hook 'folded))
7476 (message "Remote: FOLDED"))
7477 ((and (org-called-interactively-p 'any) (= more 1))
7478 (message "Remote: show with default settings"))
7483 (org-back-to-heading)
7484 (run-hook-with-args 'org-cycle-hook 'children))
7485 (message "Remote: CHILDREN"))
7489 (org-back-to-heading)
7490 (run-hook-with-args 'org-cycle-hook 'subtree))
7491 (message "Remote: SUBTREE"))
7493 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7495 (concat "^[ \t]*:\\("
7496 (mapconcat 'regexp-quote org-drawers "\\|")
7500 (org-back-to-heading)
7501 (org-cycle-hide-drawers 'subtree)))
7502 (message "Remote: SUBTREE AND LOGBOOK"))
7505 (message "Remote: SUBTREE AND ALL DRAWERS")))
7506 (select-window win)))
7508 (defun org-recenter-heading (n)
7510 (org-back-to-heading)
7513 (defvar org-agenda-cycle-counter nil)
7514 (defun org-agenda-cycle-show (&optional n)
7515 "Show the current entry in another window, with default settings.
7516 Default settings are taken from `org-show-hierarchy-above' and siblings.
7517 When use repeatedly in immediate succession, the remote entry will cycle
7520 children -> subtree -> folded
7522 When called with a numeric prefix arg, that arg will be passed through to
7523 `org-agenda-show-1'. For the interpretation of that argument, see the
7524 docstring of `org-agenda-show-1'."
7527 (setq org-agenda-cycle-counter n)
7528 (if (not (eq last-command this-command))
7529 (setq org-agenda-cycle-counter 1)
7530 (if (equal org-agenda-cycle-counter 0)
7531 (setq org-agenda-cycle-counter 2)
7532 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7533 (if (> org-agenda-cycle-counter 3)
7534 (setq org-agenda-cycle-counter 0)))))
7535 (org-agenda-show-1 org-agenda-cycle-counter))
7537 (defun org-agenda-recenter (arg)
7538 "Display the Org-mode file which contains the item at point and recenter."
7540 (let ((win (selected-window)))
7543 (select-window win)))
7545 (defun org-agenda-show-mouse (ev)
7546 "Display the Org-mode file which contains the item at the mouse click."
7548 (mouse-set-point ev)
7551 (defun org-agenda-check-no-diary ()
7552 "Check if the entry is a diary link and abort if yes."
7553 (if (org-get-at-bol 'org-agenda-diary-link)
7554 (org-agenda-error)))
7556 (defun org-agenda-error ()
7557 (error "Command not allowed in this line"))
7559 (defun org-agenda-tree-to-indirect-buffer ()
7560 "Show the subtree corresponding to the current entry in an indirect buffer.
7561 This calls the command `org-tree-to-indirect-buffer' from the original
7563 With numerical prefix arg ARG, go up to this level and then take that tree.
7564 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7565 use the dedicated frame)."
7567 (if (and current-prefix-arg (listp current-prefix-arg))
7568 (org-agenda-do-tree-to-indirect-buffer)
7569 (let ((agenda-window (selected-window))
7570 (indirect-window (and org-last-indirect-buffer (get-buffer-window org-last-indirect-buffer))))
7571 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7574 (unless (and indirect-window (window-live-p indirect-window))
7575 (setq indirect-window (split-window agenda-window)))
7576 (select-window indirect-window)
7577 (switch-to-buffer org-last-indirect-buffer :norecord)
7578 (fit-window-to-buffer indirect-window))
7579 (select-window agenda-window)))))
7581 (defun org-agenda-do-tree-to-indirect-buffer ()
7582 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7583 (org-agenda-check-no-diary)
7584 (let* ((marker (or (org-get-at-bol 'org-marker)
7585 (org-agenda-error)))
7586 (buffer (marker-buffer marker))
7587 (pos (marker-position marker)))
7588 (with-current-buffer buffer
7591 (call-interactively 'org-tree-to-indirect-buffer)))))
7593 (defvar org-last-heading-marker (make-marker)
7594 "Marker pointing to the headline that last changed its TODO state
7595 by a remote command from the agenda.")
7597 (defun org-agenda-todo-nextset ()
7598 "Switch TODO entry to next sequence."
7600 (org-agenda-todo 'nextset))
7602 (defun org-agenda-todo-previousset ()
7603 "Switch TODO entry to previous sequence."
7605 (org-agenda-todo 'previousset))
7607 (defun org-agenda-todo (&optional arg)
7608 "Cycle TODO state of line at point, also in Org-mode file.
7609 This changes the line at point, all other lines in the agenda referring to
7610 the same tree node, and the headline of the tree node in the Org-mode file."
7612 (org-agenda-check-no-diary)
7613 (let* ((col (current-column))
7614 (marker (or (org-get-at-bol 'org-marker)
7615 (org-agenda-error)))
7616 (buffer (marker-buffer marker))
7617 (pos (marker-position marker))
7618 (hdmarker (org-get-at-bol 'org-hd-marker))
7619 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7620 (inhibit-read-only t)
7621 org-agenda-headline-snapshot-before-repeat newhead just-one)
7622 (org-with-remote-undo buffer
7623 (with-current-buffer buffer
7626 (org-show-context 'agenda)
7628 (and (outline-next-heading)
7629 (org-flag-heading nil))) ; show the next heading
7630 (let ((current-prefix-arg arg))
7631 (call-interactively 'org-todo))
7632 (and (bolp) (forward-char 1))
7633 (setq newhead (org-get-heading))
7634 (when (and (org-bound-and-true-p
7635 org-agenda-headline-snapshot-before-repeat)
7636 (not (equal org-agenda-headline-snapshot-before-repeat
7639 (setq newhead org-agenda-headline-snapshot-before-repeat
7642 (org-back-to-heading)
7643 (move-marker org-last-heading-marker (point))))
7644 (beginning-of-line 1)
7646 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7647 (org-move-to-column col))))
7649 (defun org-agenda-add-note (&optional arg)
7650 "Add a time-stamped note to the entry at point."
7652 (org-agenda-check-no-diary)
7653 (let* ((marker (or (org-get-at-bol 'org-marker)
7654 (org-agenda-error)))
7655 (buffer (marker-buffer marker))
7656 (pos (marker-position marker))
7657 (hdmarker (org-get-at-bol 'org-hd-marker))
7658 (inhibit-read-only t))
7659 (with-current-buffer buffer
7662 (org-show-context 'agenda)
7664 (and (outline-next-heading)
7665 (org-flag-heading nil))) ; show the next heading
7668 (defun org-agenda-change-all-lines (newhead hdmarker
7669 &optional fixface just-this)
7670 "Change all lines in the agenda buffer which match HDMARKER.
7671 The new content of the line will be NEWHEAD (as modified by
7672 `org-agenda-format-item'). HDMARKER is checked with
7673 `equal' against all `org-hd-marker' text properties in the file.
7674 If FIXFACE is non-nil, the face of each item is modified according to
7676 If JUST-THIS is non-nil, change just the current line, not all.
7677 If FORCE-TAGS is non nil, the car of it returns the new tags."
7678 (let* ((inhibit-read-only t)
7679 (line (org-current-line))
7680 (org-agenda-buffer (current-buffer))
7681 (thetags (with-current-buffer (marker-buffer hdmarker)
7682 (save-excursion (save-restriction (widen)
7683 (goto-char hdmarker)
7684 (org-get-tags-at)))))
7685 props m pl undone-face done-face finish new dotime cat tags)
7687 (goto-char (point-max))
7688 (beginning-of-line 1)
7690 (setq finish (bobp))
7691 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7692 (or (not just-this) (= (org-current-line) line))
7694 (setq props (text-properties-at (point))
7695 dotime (org-get-at-bol 'dotime)
7696 cat (org-get-at-bol 'org-category)
7699 (let ((org-prefix-format-compiled
7700 (or (get-text-property (point) 'format)
7701 org-prefix-format-compiled)))
7702 (with-current-buffer (marker-buffer hdmarker)
7706 (org-agenda-format-item (org-get-at-bol 'extra)
7707 newhead cat tags dotime)))))
7708 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7709 undone-face (org-get-at-bol 'undone-face)
7710 done-face (org-get-at-bol 'done-face))
7711 (beginning-of-line 1)
7714 (and (looking-at ".*\n?") (replace-match "")))
7716 (replace-match new t t)
7717 (beginning-of-line 1)
7718 (add-text-properties (point-at-bol) (point-at-eol) props)
7720 (add-text-properties
7721 (point-at-bol) (point-at-eol)
7723 (if org-last-todo-state-is-todo
7724 undone-face done-face))))
7725 (org-agenda-highlight-todo 'line)
7726 (beginning-of-line 1))
7727 (t (error "Line update did not work"))))
7728 (beginning-of-line 0)))
7729 (org-finalize-agenda)))
7731 (defun org-agenda-align-tags (&optional line)
7732 "Align all tags in agenda items to `org-agenda-tags-column'."
7733 (let ((inhibit-read-only t) l c)
7735 (goto-char (if line (point-at-bol) (point-min)))
7736 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7737 (if line (point-at-eol) nil) t)
7738 (add-text-properties
7739 (match-beginning 2) (match-end 2)
7740 (list 'face (delq nil (let ((prop (get-text-property
7741 (match-beginning 2) 'face)))
7742 (or (listp prop) (setq prop (list prop)))
7743 (if (memq 'org-tag prop)
7745 (cons 'org-tag prop))))))
7746 (setq l (- (match-end 2) (match-beginning 2))
7747 c (if (< org-agenda-tags-column 0)
7748 (- (abs org-agenda-tags-column) l)
7749 org-agenda-tags-column))
7750 (delete-region (match-beginning 1) (match-end 1))
7751 (goto-char (match-beginning 1))
7752 (insert (org-add-props
7753 (make-string (max 1 (- c (current-column))) ?\ )
7754 (plist-put (copy-sequence (text-properties-at (point)))
7756 (goto-char (point-min))
7757 (org-font-lock-add-tag-faces (point-max)))))
7759 (defun org-agenda-priority-up ()
7760 "Increase the priority of line at point, also in Org-mode file."
7762 (org-agenda-priority 'up))
7764 (defun org-agenda-priority-down ()
7765 "Decrease the priority of line at point, also in Org-mode file."
7767 (org-agenda-priority 'down))
7769 (defun org-agenda-priority (&optional force-direction)
7770 "Set the priority of line at point, also in Org-mode file.
7771 This changes the line at point, all other lines in the agenda referring to
7772 the same tree node, and the headline of the tree node in the Org-mode file."
7774 (unless org-enable-priority-commands
7775 (error "Priority commands are disabled"))
7776 (org-agenda-check-no-diary)
7777 (let* ((marker (or (org-get-at-bol 'org-marker)
7778 (org-agenda-error)))
7779 (hdmarker (org-get-at-bol 'org-hd-marker))
7780 (buffer (marker-buffer hdmarker))
7781 (pos (marker-position hdmarker))
7782 (inhibit-read-only t)
7784 (org-with-remote-undo buffer
7785 (with-current-buffer buffer
7788 (org-show-context 'agenda)
7790 (and (outline-next-heading)
7791 (org-flag-heading nil))) ; show the next heading
7792 (funcall 'org-priority force-direction)
7794 (setq newhead (org-get-heading)))
7795 (org-agenda-change-all-lines newhead hdmarker)
7796 (beginning-of-line 1))))
7798 ;; FIXME: should fix the tags property of the agenda line.
7799 (defun org-agenda-set-tags (&optional tag onoff)
7800 "Set tags for the current headline."
7802 (org-agenda-check-no-diary)
7803 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7804 (call-interactively 'org-change-tag-in-region)
7805 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7806 (org-agenda-error)))
7807 (buffer (marker-buffer hdmarker))
7808 (pos (marker-position hdmarker))
7809 (inhibit-read-only t)
7811 (org-with-remote-undo buffer
7812 (with-current-buffer buffer
7816 (org-show-context 'agenda))
7818 (and (outline-next-heading)
7819 (org-flag-heading nil))) ; show the next heading
7822 (org-toggle-tag tag onoff)
7823 (call-interactively 'org-set-tags))
7825 (setq newhead (org-get-heading)))
7826 (org-agenda-change-all-lines newhead hdmarker)
7827 (beginning-of-line 1)))))
7829 (defun org-agenda-set-property ()
7830 "Set a property for the current headline."
7832 (org-agenda-check-no-diary)
7833 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7834 (org-agenda-error)))
7835 (buffer (marker-buffer hdmarker))
7836 (pos (marker-position hdmarker))
7837 (inhibit-read-only t)
7839 (org-with-remote-undo buffer
7840 (with-current-buffer buffer
7844 (org-show-context 'agenda))
7846 (and (outline-next-heading)
7847 (org-flag-heading nil))) ; show the next heading
7849 (call-interactively 'org-set-property)))))
7851 (defun org-agenda-set-effort ()
7852 "Set the effort property for the current headline."
7854 (org-agenda-check-no-diary)
7855 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7856 (org-agenda-error)))
7857 (buffer (marker-buffer hdmarker))
7858 (pos (marker-position hdmarker))
7859 (inhibit-read-only t)
7861 (org-with-remote-undo buffer
7862 (with-current-buffer buffer
7866 (org-show-context 'agenda))
7868 (and (outline-next-heading)
7869 (org-flag-heading nil))) ; show the next heading
7871 (call-interactively 'org-set-effort)
7873 (setq newhead (org-get-heading)))
7874 (org-agenda-change-all-lines newhead hdmarker))))
7876 (defun org-agenda-toggle-archive-tag ()
7877 "Toggle the archive tag for the current entry."
7879 (org-agenda-check-no-diary)
7880 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7881 (org-agenda-error)))
7882 (buffer (marker-buffer hdmarker))
7883 (pos (marker-position hdmarker))
7884 (inhibit-read-only t)
7886 (org-with-remote-undo buffer
7887 (with-current-buffer buffer
7890 (org-show-context 'agenda)
7892 (and (outline-next-heading)
7893 (org-flag-heading nil))) ; show the next heading
7894 (call-interactively 'org-toggle-archive-tag)
7896 (setq newhead (org-get-heading)))
7897 (org-agenda-change-all-lines newhead hdmarker)
7898 (beginning-of-line 1))))
7900 (defun org-agenda-do-date-later (arg)
7903 ((or (equal arg '(16))
7905 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7906 (setq this-command 'org-agenda-date-later-minutes)
7907 (org-agenda-date-later-minutes 1))
7908 ((or (equal arg '(4))
7910 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7911 (setq this-command 'org-agenda-date-later-hours)
7912 (org-agenda-date-later-hours 1))
7914 (org-agenda-date-later (prefix-numeric-value arg)))))
7916 (defun org-agenda-do-date-earlier (arg)
7919 ((or (equal arg '(16))
7921 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7922 (setq this-command 'org-agenda-date-earlier-minutes)
7923 (org-agenda-date-earlier-minutes 1))
7924 ((or (equal arg '(4))
7926 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7927 (setq this-command 'org-agenda-date-earlier-hours)
7928 (org-agenda-date-earlier-hours 1))
7930 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7932 (defun org-agenda-date-later (arg &optional what)
7933 "Change the date of this item to ARG day(s) later."
7935 (org-agenda-check-type t 'agenda 'timeline)
7936 (org-agenda-check-no-diary)
7937 (let* ((marker (or (org-get-at-bol 'org-marker)
7938 (org-agenda-error)))
7939 (buffer (marker-buffer marker))
7940 (pos (marker-position marker))
7942 (org-with-remote-undo buffer
7943 (with-current-buffer buffer
7946 (if (not (org-at-timestamp-p))
7947 (error "Cannot find time stamp"))
7948 (when (and org-agenda-move-date-from-past-immediately-to-today
7950 (or (not what) (eq what 'day))
7951 (not (save-match-data (org-at-date-range-p))))
7952 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
7953 cdate (calendar-absolute-from-gregorian
7954 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
7957 ;; immediately shift to today
7958 (setq arg (- today cdate))))
7959 (org-timestamp-change arg (or what 'day))
7960 (when (and (org-at-date-range-p)
7961 (re-search-backward org-tr-regexp-both (point-at-bol)))
7962 (let ((end org-last-changed-timestamp))
7963 (org-timestamp-change arg (or what 'day))
7964 (setq org-last-changed-timestamp
7965 (concat org-last-changed-timestamp "--" end)))))
7966 (org-agenda-show-new-time marker org-last-changed-timestamp))
7967 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7969 (defun org-agenda-date-earlier (arg &optional what)
7970 "Change the date of this item to ARG day(s) earlier."
7972 (org-agenda-date-later (- arg) what))
7974 (defun org-agenda-date-later-minutes (arg)
7975 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7977 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7978 (org-agenda-date-later arg 'minute))
7980 (defun org-agenda-date-earlier-minutes (arg)
7981 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7983 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7984 (org-agenda-date-earlier arg 'minute))
7986 (defun org-agenda-date-later-hours (arg)
7987 "Change the time of this item, in hour steps."
7989 (org-agenda-date-later arg 'hour))
7991 (defun org-agenda-date-earlier-hours (arg)
7992 "Change the time of this item, in hour steps."
7994 (org-agenda-date-earlier arg 'hour))
7996 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7997 "Show new date stamp via text properties."
7998 ;; We use text properties to make this undoable
7999 (let ((inhibit-read-only t)
8000 (buffer-invisibility-spec))
8001 (setq stamp (concat " " prefix " => " stamp))
8003 (goto-char (point-max))
8005 (when (equal marker (org-get-at-bol 'org-marker))
8006 (org-move-to-column (- (window-width) (length stamp)) t)
8007 (org-agenda-fix-tags-filter-overlays-at (point))
8008 (if (featurep 'xemacs)
8009 ;; Use `duplicable' property to trigger undo recording
8010 (let ((ex (make-extent nil nil))
8011 (gl (make-glyph stamp)))
8012 (set-glyph-face gl 'secondary-selection)
8013 (set-extent-properties
8014 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8015 (insert-extent ex (1- (point)) (point-at-eol)))
8016 (add-text-properties
8017 (1- (point)) (point-at-eol)
8018 (list 'display (org-add-props stamp nil
8019 'face 'secondary-selection))))
8020 (beginning-of-line 1))
8021 (beginning-of-line 0)))))
8023 (defun org-agenda-date-prompt (arg)
8024 "Change the date of this item. Date is prompted for, with default today.
8025 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8026 be used to request time specification in the time stamp."
8028 (org-agenda-check-type t 'agenda 'timeline)
8029 (org-agenda-check-no-diary)
8030 (let* ((marker (or (org-get-at-bol 'org-marker)
8031 (org-agenda-error)))
8032 (buffer (marker-buffer marker))
8033 (pos (marker-position marker)))
8034 (org-with-remote-undo buffer
8035 (with-current-buffer buffer
8038 (if (not (org-at-timestamp-p t))
8039 (error "Cannot find time stamp"))
8040 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8041 (org-agenda-show-new-time marker org-last-changed-timestamp))
8042 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8044 (defun org-agenda-schedule (arg &optional time)
8045 "Schedule the item at point.
8046 ARG is passed through to `org-schedule'."
8048 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8049 (org-agenda-check-no-diary)
8050 (let* ((marker (or (org-get-at-bol 'org-marker)
8051 (org-agenda-error)))
8052 (type (marker-insertion-type marker))
8053 (buffer (marker-buffer marker))
8054 (pos (marker-position marker))
8055 (org-insert-labeled-timestamps-at-point nil)
8057 (set-marker-insertion-type marker t)
8058 (org-with-remote-undo buffer
8059 (with-current-buffer buffer
8062 (setq ts (org-schedule arg time)))
8063 (org-agenda-show-new-time marker ts "S"))
8064 (message "Item scheduled for %s" ts)))
8066 (defun org-agenda-deadline (arg &optional time)
8067 "Schedule the item at point.
8068 ARG is passed through to `org-deadline'."
8070 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8071 (org-agenda-check-no-diary)
8072 (let* ((marker (or (org-get-at-bol 'org-marker)
8073 (org-agenda-error)))
8074 (buffer (marker-buffer marker))
8075 (pos (marker-position marker))
8076 (org-insert-labeled-timestamps-at-point nil)
8078 (org-with-remote-undo buffer
8079 (with-current-buffer buffer
8082 (setq ts (org-deadline arg time)))
8083 (org-agenda-show-new-time marker ts "D"))
8084 (message "Deadline for this item set to %s" ts)))
8086 (defun org-agenda-action ()
8087 "Select entry for agenda action, or execute an agenda action.
8088 This command prompts for another letter. Valid inputs are:
8090 m Mark the entry at point for an agenda action
8091 s Schedule the marked entry to the date at the cursor
8092 d Set the deadline of the marked entry to the date at the cursor
8093 r Call `org-remember' with cursor date as the default date
8094 c Call `org-capture' with cursor date as the default date
8095 SPC Show marked entry in other window
8096 TAB Visit marked entry in other window
8098 The cursor may be at a date in the calendar, or in the Org agenda."
8101 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8102 (setq ans (read-char-exclusive))
8106 (if (eq major-mode 'org-agenda-mode)
8107 (let ((m (or (org-get-at-bol 'org-hd-marker)
8108 (org-get-at-bol 'org-marker))))
8111 (move-marker org-agenda-action-marker
8112 (marker-position m) (marker-buffer m))
8113 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8114 (error "Don't know which entry to mark")))
8115 (error "This command works only in the agenda")))
8117 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8119 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8121 (org-agenda-do-action '(org-remember) t))
8123 (org-agenda-do-action '(org-capture) t))
8125 (let ((cw (selected-window)))
8126 (org-switch-to-buffer-other-window
8127 (marker-buffer org-agenda-action-marker))
8128 (goto-char org-agenda-action-marker)
8129 (org-show-context 'agenda)
8130 (select-window cw)))
8132 (org-switch-to-buffer-other-window
8133 (marker-buffer org-agenda-action-marker))
8134 (goto-char org-agenda-action-marker)
8135 (org-show-context 'agenda))
8136 (t (error "Invalid agenda action %c" ans)))))
8138 (defun org-agenda-do-action (form &optional current-buffer)
8139 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8140 (let ((org-overriding-default-time (org-get-cursor-date)))
8143 (if (not (marker-buffer org-agenda-action-marker))
8144 (error "No entry has been selected for agenda action")
8145 (with-current-buffer (marker-buffer org-agenda-action-marker)
8149 (goto-char org-agenda-action-marker)
8152 (defun org-agenda-clock-in (&optional arg)
8153 "Start the clock on the currently selected item."
8155 (org-agenda-check-no-diary)
8156 (if (equal arg '(4))
8158 (let* ((marker (or (org-get-at-bol 'org-marker)
8159 (org-agenda-error)))
8160 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8162 (pos (marker-position marker))
8164 (org-with-remote-undo (marker-buffer marker)
8165 (with-current-buffer (marker-buffer marker)
8168 (org-show-context 'agenda)
8170 (org-cycle-hide-drawers 'children)
8172 (setq newhead (org-get-heading)))
8173 (org-agenda-change-all-lines newhead hdmarker)))))
8175 (defun org-agenda-clock-out ()
8176 "Stop the currently running clock."
8178 (unless (marker-buffer org-clock-marker)
8179 (error "No running clock"))
8180 (let ((marker (make-marker)) newhead)
8181 (org-with-remote-undo (marker-buffer org-clock-marker)
8182 (with-current-buffer (marker-buffer org-clock-marker)
8186 (goto-char org-clock-marker)
8187 (org-back-to-heading t)
8188 (move-marker marker (point))
8190 (setq newhead (org-get-heading))))))
8191 (org-agenda-change-all-lines newhead marker)
8192 (move-marker marker nil)))
8194 (defun org-agenda-clock-cancel (&optional arg)
8195 "Cancel the currently running clock."
8197 (unless (marker-buffer org-clock-marker)
8198 (error "No running clock"))
8199 (org-with-remote-undo (marker-buffer org-clock-marker)
8200 (org-clock-cancel)))
8202 (defun org-agenda-clock-goto ()
8203 "Jump to the currently clocked in task within the agenda.
8204 If the currently clocked in task is not listed in the agenda
8205 buffer, display it in another window."
8209 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8210 (setq pos (overlay-start o))))
8211 (overlays-in (point-min) (point-max)))
8212 (cond (pos (goto-char pos))
8213 ;; If the currently clocked entry is not in the agenda
8214 ;; buffer, we visit it in another window:
8215 (org-clock-current-task
8216 (org-switch-to-buffer-other-window (org-clock-goto)))
8217 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8219 (defun org-agenda-diary-entry-in-org-file ()
8220 "Make a diary entry in the file `org-agenda-diary-file'."
8221 (let (d1 d2 char (text "") dp1 dp2)
8222 (if (equal (buffer-name) "*Calendar*")
8223 (setq d1 (calendar-cursor-to-date t)
8224 d2 (car calendar-mark-ring))
8225 (setq dp1 (get-text-property (point-at-bol) 'day))
8226 (unless dp1 (error "No date defined in current line"))
8227 (setq d1 (calendar-gregorian-from-absolute dp1)
8228 d2 (and (ignore-errors (mark))
8231 (setq dp2 (get-text-property (point-at-bol) 'day)))
8232 (calendar-gregorian-from-absolute dp2))))
8233 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8234 (setq char (read-char-exclusive))
8237 (setq text (read-string "Day entry: "))
8238 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8239 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8241 (setq d1 (list (car d1) (nth 1 d1)
8242 (read-number (format "Reference year [%d]: " (nth 2 d1))
8244 (setq text (read-string "Anniversary (use %d to show years): "))
8245 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8246 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8248 (setq text (read-string "Block entry: "))
8249 (unless (and d1 d2 (not (equal d1 d2)))
8250 (error "No block of days selected"))
8251 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8252 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8254 (org-switch-to-buffer-other-window
8255 (find-file-noselect org-agenda-diary-file))
8256 (require 'org-datetree)
8257 (org-datetree-find-date-create d1)
8259 (t (error "Invalid selection character `%c'" char)))))
8261 (defcustom org-agenda-insert-diary-strategy 'date-tree
8262 "Where in `org-agenda-diary-file' should new entries be added?
8265 date-tree in the date tree, as child of the date
8266 top-level as top-level entries at the end of the file."
8269 (const :tag "in a date tree" date-tree)
8270 (const :tag "as top level at end of file" top-level)))
8272 (defcustom org-agenda-insert-diary-extract-time nil
8273 "Non-nil means extract any time specification from the diary entry."
8278 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8279 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8280 If TEXT is not empty, it will become the headline of the new entry, and
8281 the resulting entry will not be shown. When TEXT is empty, switch to
8282 `org-agenda-diary-file' and let the user finish the entry there."
8283 (let ((cw (current-window-configuration)))
8284 (org-switch-to-buffer-other-window
8285 (find-file-noselect org-agenda-diary-file))
8287 (goto-char (point-min))
8289 ((eq type 'anniversary)
8290 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8292 (or (org-at-heading-p t)
8294 (outline-next-heading)
8295 (insert "* Anniversaries\n\n")
8296 (beginning-of-line -1)))))
8297 (outline-next-heading)
8298 (org-back-over-empty-lines)
8301 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8302 (nth 2 d1) (car d1) (nth 1 d1) text)))
8304 (let ((org-prefix-has-time t)
8305 (org-agenda-time-leading-zero t)
8307 (if org-agenda-insert-diary-extract-time
8308 ;; Use org-agenda-format-item to parse text for a time-range and
8309 ;; remove it. FIXME: This is a hack, we should refactor
8310 ;; that function to make time extraction available separately
8311 (setq fmt (org-agenda-format-item nil text nil nil t)
8312 time (get-text-property 0 'time fmt)
8313 time2 (if (> (length time) 0)
8314 ;; split-string removes trailing ...... if
8315 ;; no end time given. First space
8316 ;; separates time from date.
8317 (concat " " (car (split-string time "\\.")))
8319 text (get-text-property 0 'txt fmt)))
8320 (if (eq org-agenda-insert-diary-strategy 'top-level)
8321 (org-agenda-insert-diary-as-top-level text)
8322 (require 'org-datetree)
8323 (org-datetree-find-date-create d1)
8324 (org-agenda-insert-diary-make-new-entry text))
8325 (org-insert-time-stamp (org-time-from-absolute
8326 (calendar-absolute-from-gregorian d1))
8327 nil nil nil nil time2))
8330 (if (> (calendar-absolute-from-gregorian d1)
8331 (calendar-absolute-from-gregorian d2))
8332 (setq d1 (prog1 d2 (setq d2 d1))))
8333 (if (eq org-agenda-insert-diary-strategy 'top-level)
8334 (org-agenda-insert-diary-as-top-level text)
8335 (require 'org-datetree)
8336 (org-datetree-find-date-create d1)
8337 (org-agenda-insert-diary-make-new-entry text))
8338 (org-insert-time-stamp (org-time-from-absolute
8339 (calendar-absolute-from-gregorian d1)))
8341 (org-insert-time-stamp (org-time-from-absolute
8342 (calendar-absolute-from-gregorian d2)))
8344 (if (string-match "\\S-" text)
8346 (set-window-configuration cw)
8347 (message "%s entry added to %s"
8348 (capitalize (symbol-name type))
8349 (abbreviate-file-name org-agenda-diary-file)))
8351 (message "Please finish entry here"))))
8353 (defun org-agenda-insert-diary-as-top-level (text)
8354 "Make new entry as a top-level entry at the end of the file.
8355 Add TEXT as headline, and position the cursor in the second line so that
8356 a timestamp can be added there."
8358 (goto-char (point-max))
8359 (or (bolp) (insert "\n"))
8360 (insert "* " text "\n")
8361 (if org-adapt-indentation (org-indent-to-column 2)))
8363 (defun org-agenda-insert-diary-make-new-entry (text)
8364 "Make new entry as last child of current entry.
8365 Add TEXT as headline, and position the cursor in the second line so that
8366 a timestamp can be added there."
8367 (let ((org-show-following-heading t)
8368 (org-show-siblings t)
8369 (org-show-hierarchy-above t)
8370 (org-show-entry-below t)
8372 (outline-next-heading)
8373 (org-back-over-empty-lines)
8374 (or (looking-at "[ \t]*$")
8375 (progn (insert "\n") (backward-char 1)))
8376 (org-insert-heading nil t)
8378 (setq col (current-column))
8380 (if org-adapt-indentation (org-indent-to-column col))
8381 (let ((org-show-following-heading t)
8382 (org-show-siblings t)
8383 (org-show-hierarchy-above t)
8384 (org-show-entry-below t))
8385 (org-show-context))))
8387 (defun org-agenda-diary-entry ()
8388 "Make a diary entry, like the `i' command from the calendar.
8389 All the standard commands work: block, weekly etc.
8390 When `org-agenda-diary-file' points to a file,
8391 `org-agenda-diary-entry-in-org-file' is called instead to create
8392 entries in that Org-mode file."
8394 (org-agenda-check-type t 'agenda 'timeline)
8395 (if (not (eq org-agenda-diary-file 'diary-file))
8396 (org-agenda-diary-entry-in-org-file)
8397 (require 'diary-lib)
8399 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8400 (read-char-exclusive)))
8401 (cmd (cdr (assoc char
8402 '((?d . insert-diary-entry)
8403 (?w . insert-weekly-diary-entry)
8404 (?m . insert-monthly-diary-entry)
8405 (?y . insert-yearly-diary-entry)
8406 (?a . insert-anniversary-diary-entry)
8407 (?b . insert-block-diary-entry)
8408 (?c . insert-cyclic-diary-entry)))))
8409 (oldf (symbol-function 'calendar-cursor-to-date))
8410 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8412 (mark (or (mark t) (point))))
8414 (error "No command associated with <%c>" char))
8415 (unless (and (get-text-property point 'day)
8416 (or (not (equal ?b char))
8417 (get-text-property mark 'day)))
8418 (error "Don't know which date to use for diary entry"))
8419 ;; We implement this by hacking the `calendar-cursor-to-date' function
8420 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8421 (let ((calendar-mark-ring
8422 (list (calendar-gregorian-from-absolute
8423 (or (get-text-property mark 'day)
8424 (get-text-property point 'day))))))
8427 (fset 'calendar-cursor-to-date
8428 (lambda (&optional error dummy)
8429 (calendar-gregorian-from-absolute
8430 (get-text-property point 'day))))
8431 (call-interactively cmd))
8432 (fset 'calendar-cursor-to-date oldf))))))
8434 (defun org-agenda-execute-calendar-command (cmd)
8435 "Execute a calendar command from the agenda, with the date associated to
8436 the cursor position."
8437 (org-agenda-check-type t 'agenda 'timeline)
8438 (require 'diary-lib)
8439 (unless (get-text-property (point) 'day)
8440 (error "Don't know which date to use for calendar command"))
8441 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8443 (date (calendar-gregorian-from-absolute
8444 (get-text-property point 'day)))
8445 ;; the following 2 vars are needed in the calendar
8446 (displayed-month (car date))
8447 (displayed-year (nth 2 date)))
8450 (fset 'calendar-cursor-to-date
8451 (lambda (&optional error dummy)
8452 (calendar-gregorian-from-absolute
8453 (get-text-property point 'day))))
8454 (call-interactively cmd))
8455 (fset 'calendar-cursor-to-date oldf))))
8457 (defun org-agenda-phases-of-moon ()
8458 "Display the phases of the moon for the 3 months around the cursor date."
8460 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8462 (defun org-agenda-holidays ()
8463 "Display the holidays for the 3 months around the cursor date."
8465 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8467 (defvar calendar-longitude)
8468 (defvar calendar-latitude)
8469 (defvar calendar-location-name)
8471 (defun org-agenda-sunrise-sunset (arg)
8472 "Display sunrise and sunset for the cursor date.
8473 Latitude and longitude can be specified with the variables
8474 `calendar-latitude' and `calendar-longitude'. When called with prefix
8475 argument, latitude and longitude will be prompted for."
8478 (let ((calendar-longitude (if arg nil calendar-longitude))
8479 (calendar-latitude (if arg nil calendar-latitude))
8480 (calendar-location-name
8481 (if arg "the given coordinates" calendar-location-name)))
8482 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8484 (defun org-agenda-goto-calendar ()
8485 "Open the Emacs calendar with the date at the cursor."
8487 (org-agenda-check-type t 'agenda 'timeline)
8488 (let* ((day (or (get-text-property (point) 'day)
8489 (error "Don't know which date to open in calendar")))
8490 (date (calendar-gregorian-from-absolute day))
8491 (calendar-move-hook nil)
8492 (calendar-view-holidays-initially-flag nil)
8493 (calendar-view-diary-initially-flag nil))
8495 (calendar-goto-date date)))
8498 (defun org-calendar-goto-agenda ()
8499 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8500 This is a command that has to be installed in `calendar-mode-map'."
8502 (org-agenda-list nil (calendar-absolute-from-gregorian
8503 (calendar-cursor-to-date))
8506 (defun org-agenda-convert-date ()
8508 (org-agenda-check-type t 'agenda 'timeline)
8509 (let ((day (get-text-property (point) 'day))
8512 (error "Don't know which date to convert"))
8513 (setq date (calendar-gregorian-from-absolute day))
8515 "Gregorian: " (calendar-date-string date) "\n"
8516 "ISO: " (calendar-iso-date-string date) "\n"
8517 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8518 "Julian: " (calendar-julian-date-string date) "\n"
8519 "Astron. JD: " (calendar-astro-date-string date)
8520 " (Julian date number at noon UTC)\n"
8521 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8522 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8523 "French: " (calendar-french-date-string date) "\n"
8524 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8525 "Mayan: " (calendar-mayan-date-string date) "\n"
8526 "Coptic: " (calendar-coptic-date-string date) "\n"
8527 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8528 "Persian: " (calendar-persian-date-string date) "\n"
8529 "Chinese: " (calendar-chinese-date-string date) "\n"))
8530 (with-output-to-temp-buffer "*Dates*"
8532 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8536 (defvar org-agenda-bulk-marked-entries nil
8537 "List of markers that refer to marked entries in the agenda.")
8539 (defun org-agenda-bulk-marked-p ()
8540 (eq (get-char-property (point-at-bol) 'type)
8541 'org-marked-entry-overlay))
8543 (defun org-agenda-bulk-mark (&optional arg)
8544 "Mark the entry at point for future bulk action."
8546 (dotimes (i (max arg 1))
8547 (unless (org-get-at-bol 'org-agenda-diary-link)
8548 (let* ((m (org-get-at-bol 'org-hd-marker))
8550 (unless (org-agenda-bulk-marked-p)
8551 (unless m (error "Nothing to mark at point"))
8552 (push m org-agenda-bulk-marked-entries)
8553 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8554 (org-overlay-display ov "> "
8555 (org-get-todo-face "TODO")
8557 (overlay-put ov 'type 'org-marked-entry-overlay))
8558 (beginning-of-line 2)
8559 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8560 (beginning-of-line 2))
8561 (message "%d entries marked for bulk action"
8562 (length org-agenda-bulk-marked-entries))))))
8564 (defun org-agenda-bulk-mark-regexp (regexp)
8565 "Mark entries match REGEXP."
8566 (interactive "sMark entries matching regexp: ")
8567 (let (entries-marked)
8569 (goto-char (point-min))
8570 (goto-char (next-single-property-change (point) 'txt))
8571 (while (re-search-forward regexp nil t)
8572 (when (string-match regexp (get-text-property (point) 'txt))
8573 (setq entries-marked (+ entries-marked 1))
8574 (call-interactively 'org-agenda-bulk-mark))))
8575 (if (not entries-marked)
8576 (message "No entry matching this regexp."))))
8578 (defun org-agenda-bulk-unmark ()
8579 "Unmark the entry at point for future bulk action."
8581 (when (org-agenda-bulk-marked-p)
8582 (org-agenda-bulk-remove-overlays
8583 (point-at-bol) (+ 2 (point-at-bol)))
8584 (setq org-agenda-bulk-marked-entries
8585 (delete (org-get-at-bol 'org-hd-marker)
8586 org-agenda-bulk-marked-entries)))
8587 (beginning-of-line 2)
8588 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8589 (beginning-of-line 2))
8590 (message "%d entries marked for bulk action"
8591 (length org-agenda-bulk-marked-entries)))
8593 (defun org-agenda-bulk-toggle ()
8594 "Toggle marking the entry at point for bulk action."
8596 (if (org-agenda-bulk-marked-p)
8597 (org-agenda-bulk-unmark)
8598 (org-agenda-bulk-mark)))
8600 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8601 "Remove the mark overlays between BEG and END in the agenda buffer.
8602 BEG and END default to the buffer limits.
8604 This only removes the overlays, it does not remove the markers
8605 from the list in `org-agenda-bulk-marked-entries'."
8608 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8609 (delete-overlay ov)))
8610 (overlays-in (or beg (point-min)) (or end (point-max)))))
8612 (defun org-agenda-bulk-remove-all-marks ()
8613 "Remove all marks in the agenda buffer.
8614 This will remove the markers, and the overlays."
8616 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8617 (setq org-agenda-bulk-marked-entries nil)
8618 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8620 (defun org-agenda-bulk-action (&optional arg)
8621 "Execute an remote-editing action on all marked entries.
8622 The prefix arg is passed through to the command if possible."
8624 ;; Make sure we have markers, and only valid ones
8625 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8628 (unless (and (markerp m)
8630 (buffer-live-p (marker-buffer m))
8631 (marker-position m))
8632 (error "Marker %s for bulk command is invalid" m)))
8633 org-agenda-bulk-marked-entries)
8635 ;; Prompt for the bulk command
8636 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8637 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8638 (when org-agenda-bulk-custom-functions
8639 (concat " Custom: ["
8640 (mapconcat (lambda(f) (char-to-string (car f)))
8641 org-agenda-bulk-custom-functions "")
8643 (let* ((action (read-char-exclusive))
8644 (org-log-refile (if org-log-refile 'time nil))
8645 (entries (reverse org-agenda-bulk-marked-entries))
8647 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8650 (setq cmd '(org-agenda-archive)))
8653 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8655 ((member action '(?r ?w))
8656 (setq rfloc (org-refile-get-location
8658 (marker-buffer (car org-agenda-bulk-marked-entries))
8659 org-refile-allow-creating-parent-nodes))
8661 (setcar (nthcdr 3 rfloc)
8662 (move-marker (make-marker) (nth 3 rfloc)
8663 (or (get-file-buffer (nth 1 rfloc))
8664 (find-buffer-visiting (nth 1 rfloc))
8665 (error "This should not happen")))))
8667 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8671 (setq state (org-icompleting-read
8673 (with-current-buffer (marker-buffer (car entries))
8674 (mapcar 'list org-todo-keywords-1))))
8675 (setq cmd `(let ((org-inhibit-blocking t)
8676 (org-inhibit-logging 'note))
8677 (org-agenda-todo ,state))))
8679 ((memq action '(?- ?+))
8680 (setq tag (org-icompleting-read
8681 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8682 (with-current-buffer (marker-buffer (car entries))
8685 (if (stringp (car x)) x)) org-tag-alist)))))
8686 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8688 ((memq action '(?s ?d))
8689 (let* ((date (unless arg
8692 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8693 (ans (if arg nil org-read-date-final-answer))
8694 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8695 (setq cmd `(let* ((bound (fboundp 'read-string))
8696 (old (and bound (symbol-function 'read-string))))
8699 (fset 'read-string (lambda (&rest ignore) ,ans))
8702 (fset 'read-string old)
8703 (fmakunbound 'read-string)))))))
8706 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8707 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8708 (let ((days (read-number
8709 (format "Scatter tasks across how many %sdays: "
8710 (if arg "week" "")) 7)))
8712 `(let ((distance (1+ (random ,days))))
8714 (let ((dist distance)
8716 (calendar-day-of-week
8717 (calendar-gregorian-from-absolute (org-today)))))
8718 (dotimes (i (1+ dist))
8719 (while (member day-of-week org-agenda-weekend-days)
8722 (if (= day-of-week 7)
8723 (setq day-of-week 0)))
8725 (if (= day-of-week 7)
8726 (setq day-of-week 0)))))
8727 ;; silently fail when try to replan a sexp entry
8729 (let* ((date (calendar-gregorian-from-absolute
8730 (+ (org-today) distance)))
8731 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8733 (org-agenda-schedule nil time))
8736 ((assoc action org-agenda-bulk-custom-functions)
8737 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8741 (setq cmd (list (intern
8742 (org-icompleting-read "Function: "
8743 obarray 'fboundp t nil nil)))))
8745 (t (error "Invalid bulk action")))
8747 ;; Sort the markers, to make sure that parents are handled before children
8748 (setq entries (sort entries
8751 ((equal (marker-buffer a) (marker-buffer b))
8752 (< (marker-position a) (marker-position b)))
8754 (string< (buffer-name (marker-buffer a))
8755 (buffer-name (marker-buffer b))))))))
8757 ;; Now loop over all markers and apply cmd
8758 (while (setq e (pop entries))
8759 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8761 (progn (message "Skipping removed entry at %s" e)
8762 (setq cntskip (1+ cntskip)))
8764 (let (org-loop-over-headlines-in-active-region)
8766 (setq org-agenda-bulk-marked-entries
8767 (delete e org-agenda-bulk-marked-entries))
8768 (setq cnt (1+ cnt))))
8769 (setq org-agenda-bulk-marked-entries nil)
8770 (org-agenda-bulk-remove-all-marks)
8771 (when redo-at-end (org-agenda-redo))
8772 (message "Acted on %d entries%s"
8776 (format ", skipped %d (disappeared before their turn)"
8781 (defun org-agenda-show-the-flagging-note ()
8782 "Display the flagging note in the other window.
8783 When called a second time in direct sequence, offer to remove the FLAGGING
8784 tag and (if present) the flagging note."
8786 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8787 (win (selected-window))
8788 note heading newhead)
8790 (error "No linked entry at point"))
8791 (if (and (eq this-command last-command)
8792 (y-or-n-p "Unflag and remove any flagging note? "))
8794 (org-agenda-remove-flag hdmarker)
8795 (let ((win (get-buffer-window "*Flagging Note*")))
8796 (and win (delete-window win)))
8797 (message "Entry unflagged"))
8798 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8800 (error "No flagging note"))
8802 (org-switch-to-buffer-other-window "*Flagging Note*")
8805 (goto-char (point-min))
8806 (while (re-search-forward "\\\\n" nil t)
8807 (replace-match "\n" t t))
8808 (goto-char (point-min))
8810 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8812 (defun org-agenda-remove-flag (marker)
8813 "Remove the FLAGGED tag and any flagging note in the entry."
8815 (org-with-point-at marker
8816 (org-toggle-tag "FLAGGED" 'off)
8817 (org-entry-delete nil "THEFLAGGINGNOTE")
8818 (setq newhead (org-get-heading)))
8819 (org-agenda-change-all-lines newhead marker)
8820 (message "Entry unflagged")))
8822 (defun org-agenda-get-any-marker (&optional pos)
8823 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8824 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8826 ;;; Appointment reminders
8828 (defvar appt-time-msg-list)
8831 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8832 "Activate appointments found in `org-agenda-files'.
8833 With a \\[universal-argument] prefix, refresh the list of
8836 If FILTER is t, interactively prompt the user for a regular
8837 expression, and filter out entries that don't match it.
8839 If FILTER is a string, use this string as a regular expression
8840 for filtering entries out.
8842 If FILTER is a function, filter out entries against which
8843 calling the function returns nil. This function takes one
8844 argument: an entry from `org-agenda-get-day-entries'.
8846 FILTER can also be an alist with the car of each cell being
8847 either 'headline or 'category. For example:
8849 '((headline \"IMPORTANT\")
8850 (category \"Work\"))
8852 will only add headlines containing IMPORTANT or headlines
8853 belonging to the \"Work\" category.
8855 ARGS are symbols indicating what kind of entries to consider.
8856 By default `org-agenda-to-appt' will use :deadline, :scheduled
8857 and :timestamp entries. See the docstring of `org-diary' for
8858 details and examples."
8860 (if refresh (setq appt-time-msg-list nil))
8862 (setq filter (read-from-minibuffer "Regexp filter: ")))
8863 (let* ((cnt 0) ; count added events
8864 (scope (or args '(:deadline :scheduled :timestamp)))
8865 (org-agenda-new-buffers nil)
8866 (org-deadline-warning-days 0)
8867 ;; Do not use `org-today' here because appt only takes
8868 ;; time and without date as argument, so it may pass wrong
8869 ;; information otherwise
8870 (today (org-date-to-gregorian
8871 (time-to-days (current-time))))
8872 (org-agenda-restrict nil)
8873 (files (org-agenda-files 'unrestricted)) entries file)
8874 ;; Get all entries which may contain an appt
8875 (org-prepare-agenda-buffers files)
8876 (while (setq file (pop files))
8880 (apply 'org-agenda-get-day-entries
8881 file today scope)))))
8882 ;; Map thru entries and find if we should filter them out
8885 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8886 (cat (get-text-property 1 'org-category x))
8887 (tod (get-text-property 1 'time-of-day x))
8888 (ok (or (null filter)
8889 (and (stringp filter) (string-match filter evt))
8890 (and (functionp filter) (funcall filter x))
8892 (let ((cat-filter (cadr (assoc 'category filter)))
8893 (evt-filter (cadr (assoc 'headline filter))))
8894 (or (and (stringp cat-filter)
8895 (string-match cat-filter cat))
8896 (and (stringp evt-filter)
8897 (string-match evt-filter evt))))))))
8898 ;; FIXME: Shall we remove text-properties for the appt text?
8899 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8901 (setq tod (concat "00" (number-to-string tod))
8902 tod (when (string-match
8903 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8904 (concat (match-string 1 tod) ":"
8905 (match-string 2 tod))))
8907 (setq cnt (1+ cnt))))) entries)
8908 (org-release-buffers org-agenda-new-buffers)
8910 (message "No event to add")
8911 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8913 (defun org-agenda-todayp (date)
8914 "Does DATE mean today, when considering `org-extend-today-until'?"
8915 (let ((today (org-today))
8916 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8920 (defun org-agenda-todo-yesterday (&optional arg)
8921 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
8923 (let* ((hour (third (decode-time
8924 (org-current-time))))
8925 (org-extend-today-until (1+ hour)))
8926 (org-agenda-todo arg)))
8928 (provide 'org-agenda)
8930 ;;; org-agenda.el ends here