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 (defvaralias 'org-agenda-filter-preset
'org-agenda-tag-filter-preset
)
252 (defconst org-agenda-custom-commands-local-options
253 `(repeat :tag
"Local settings for this command. Remember to quote values"
254 (choice :tag
"Setting"
255 (list :tag
"Heading for this block"
256 (const org-agenda-overriding-header
)
257 (string :tag
"Headline"))
258 (list :tag
"Files to be searched"
259 (const org-agenda-files
)
261 (const :format
"" quote
)
263 (list :tag
"Sorting strategy"
264 (const org-agenda-sorting-strategy
)
266 (const :format
"" quote
)
268 ,org-sorting-choice
)))
269 (list :tag
"Prefix format"
270 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
272 (list :tag
"Number of days in agenda"
273 (const org-agenda-span
)
274 (choice (const :tag
"Day" 'day
)
275 (const :tag
"Week" 'week
)
276 (const :tag
"Month" 'month
)
277 (const :tag
"Year" 'year
)
278 (integer :tag
"Custom")))
279 (list :tag
"Fixed starting date"
280 (const org-agenda-start-day
)
281 (string :value
"2007-11-01"))
282 (list :tag
"Start on day of week"
283 (const org-agenda-start-on-weekday
)
285 (const :tag
"Today" nil
)
286 (integer :tag
"Weekday No.")))
287 (list :tag
"Include data from diary"
288 (const org-agenda-include-diary
)
290 (list :tag
"Deadline Warning days"
291 (const org-deadline-warning-days
)
293 (list :tag
"Category filter preset"
294 (const org-agenda-category-filter-preset
)
296 (const :format
"" quote
)
298 (string :tag
"+category or -category"))))
299 (list :tag
"Tags filter preset"
300 (const org-agenda-tag-filter-preset
)
302 (const :format
"" quote
)
304 (string :tag
"+tag or -tag"))))
305 (list :tag
"Set daily/weekly entry types"
306 (const org-agenda-entry-types
)
308 (const :format
"" quote
)
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
653 (const :tag
"Ignore future timestamp todos" future
)
654 (const :tag
"Ignore past or present timestamp todos" past
)
655 (const :tag
"Ignore all timestamp todos" all
)
656 (const :tag
"Show timestamp todos" nil
)
657 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
659 (defcustom org-agenda-todo-ignore-scheduled nil
660 "Non-nil means, ignore some scheduled TODO items when making TODO list.
661 This applies when creating the global todo list.
664 past Don't show entries scheduled today or in the past.
666 future Don't show entries scheduled in the future.
667 The idea behind this is that by scheduling it, you don't want to
668 think about it until the scheduled date.
670 all Don't show any scheduled entries in the global todo list.
671 The idea behind this is that by scheduling it, you have already
672 \"taken care\" of this item.
674 t Same as `all', for backward compatibility.
676 This variable can also have an integer as a value. See
677 `org-agenda-todo-ignore-timestamp' for more details.
679 See also `org-agenda-todo-ignore-with-date'.
680 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
681 to make his option also apply to the tags-todo list."
682 :group
'org-agenda-skip
683 :group
'org-agenda-todo-list
685 (const :tag
"Ignore future-scheduled todos" future
)
686 (const :tag
"Ignore past- or present-scheduled todos" past
)
687 (const :tag
"Ignore all scheduled todos" all
)
688 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
689 (const :tag
"Show scheduled todos" nil
)
690 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
692 (defcustom org-agenda-todo-ignore-deadlines nil
693 "Non-nil means ignore some deadlined TODO items when making TODO list.
694 There are different motivations for using different values, please think
695 carefully when configuring this variable.
697 This applies when creating the global todo list.
700 near Don't show near deadline entries. A deadline is near when it is
701 closer than `org-deadline-warning-days' days. The idea behind this
702 is that such items will appear in the agenda anyway.
704 far Don't show TODO entries where a deadline has been defined, but
705 the deadline is not near. This is useful if you don't want to
706 use the todo list to figure out what to do now.
708 past Don't show entries with a deadline timestamp for today or in the past.
710 future Don't show entries with a deadline timestamp in the future, not even
711 when they become `near' ones. Use it with caution.
713 all Ignore all TODO entries that do have a deadline.
715 t Same as `near', for backward compatibility.
717 This variable can also have an integer as a value. See
718 `org-agenda-todo-ignore-timestamp' for more details.
720 See also `org-agenda-todo-ignore-with-date'.
721 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
722 to make his option also apply to the tags-todo list."
723 :group
'org-agenda-skip
724 :group
'org-agenda-todo-list
726 (const :tag
"Ignore near deadlines" near
)
727 (const :tag
"Ignore near deadlines (compatibility)" t
)
728 (const :tag
"Ignore far deadlines" far
)
729 (const :tag
"Ignore all TODOs with a deadlines" all
)
730 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
731 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
733 (defcustom org-agenda-tags-todo-honor-ignore-options nil
734 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
736 `org-agenda-todo-ignore-with-date',
737 `org-agenda-todo-ignore-timestamp',
738 `org-agenda-todo-ignore-scheduled',
739 `org-agenda-todo-ignore-deadlines'
740 make the global TODO list skip entries that have time stamps of certain
741 kinds. If this option is set, the same options will also apply for the
742 tags-todo search, which is the general tags/property matcher
743 restricted to unfinished TODO entries only."
744 :group
'org-agenda-skip
745 :group
'org-agenda-todo-list
746 :group
'org-agenda-match-view
749 (defcustom org-agenda-skip-scheduled-if-done nil
750 "Non-nil means don't show scheduled items in agenda when they are done.
751 This is relevant for the daily/weekly agenda, not for the TODO list. And
752 it applies only to the actual date of the scheduling. Warnings about
753 an item with a past scheduling dates are always turned off when the item
755 :group
'org-agenda-skip
756 :group
'org-agenda-daily
/weekly
759 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
760 "Non-nil means skip scheduling line if same entry shows because of deadline.
761 In the agenda of today, an entry can show up multiple times because
762 it is both scheduled and has a nearby deadline, and maybe a plain time
764 When this variable is t, then only the deadline is shown and the fact that
765 the entry is scheduled today or was scheduled previously is not shown.
766 When this variable is nil, the entry will be shown several times. When
767 the variable is the symbol `not-today', then skip scheduled previously,
768 but not scheduled today."
769 :group
'org-agenda-skip
770 :group
'org-agenda-daily
/weekly
772 (const :tag
"Never" nil
)
773 (const :tag
"Always" t
)
774 (const :tag
"Not when scheduled today" not-today
)))
776 (defcustom org-agenda-skip-deadline-if-done nil
777 "Non-nil means don't show deadlines when the corresponding item is done.
778 When nil, the deadline is still shown and should give you a happy feeling.
779 This is relevant for the daily/weekly agenda. And it applied only to the
780 actually date of the deadline. Warnings about approaching and past-due
781 deadlines are always turned off when the item is DONE."
782 :group
'org-agenda-skip
783 :group
'org-agenda-daily
/weekly
786 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
787 "Non-nil means skip deadline prewarning when entry is also scheduled.
788 This will apply on all days where a prewarning for the deadline would
789 be shown, but not at the day when the entry is actually due. On that day,
790 the deadline will be shown anyway.
791 This variable may be set to nil, t, or a number which will then give
792 the number of days before the actual deadline when the prewarnings
794 This can be used in a workflow where the first showing of the deadline will
795 trigger you to schedule it, and then you don't want to be reminded of it
796 because you will take care of it on the day when scheduled."
797 :group
'org-agenda-skip
798 :group
'org-agenda-daily
/weekly
800 (const :tag
"Alwas show prewarning" nil
)
801 (const :tag
"Remove prewarning if entry is scheduled" t
)
802 (integer :tag
"Restart prewarning N days before deadline")))
804 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
805 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
806 When non-nil, after the search for timestamps has matched once in an
807 entry, the rest of the entry will not be searched."
808 :group
'org-agenda-skip
811 (defcustom org-agenda-skip-timestamp-if-done nil
812 "Non-nil means don't select item by timestamp or -range if it is DONE."
813 :group
'org-agenda-skip
814 :group
'org-agenda-daily
/weekly
817 (defcustom org-agenda-dim-blocked-tasks t
818 "Non-nil means dim blocked tasks in the agenda display.
819 This causes some overhead during agenda construction, but if you
820 have turned on `org-enforce-todo-dependencies',
821 `org-enforce-todo-checkbox-dependencies', or any other blocking
822 mechanism, this will create useful feedback in the agenda.
824 Instead of t, this variable can also have the value `invisible'.
825 Then blocked tasks will be invisible and only become visible when
826 they become unblocked. An exemption to this behavior is when a task is
827 blocked because of unchecked checkboxes below it. Since checkboxes do
828 not show up in the agenda views, making this task invisible you remove any
829 trace from agenda views that there is something to do. Therefore, a task
830 that is blocked because of checkboxes will never be made invisible, it
831 will only be dimmed."
832 :group
'org-agenda-daily
/weekly
833 :group
'org-agenda-todo-list
835 (const :tag
"Do not dim" nil
)
836 (const :tag
"Dim to a gray face" t
)
837 (const :tag
"Make invisible" invisible
)))
839 (defcustom org-timeline-show-empty-dates
3
840 "Non-nil means `org-timeline' also shows dates without an entry.
841 When nil, only the days which actually have entries are shown.
842 When t, all days between the first and the last date are shown.
843 When an integer, show also empty dates, but if there is a gap of more than
844 N days, just insert a special line indicating the size of the gap."
845 :group
'org-agenda-skip
847 (const :tag
"None" nil
)
849 (integer :tag
"at most")))
851 (defgroup org-agenda-startup nil
852 "Options concerning initial settings in the Agenda in Org Mode."
853 :tag
"Org Agenda Startup"
856 (defcustom org-agenda-menu-show-matcher t
857 "Non-nil means show the match string in the agenda dispatcher menu.
858 When nil, the matcher string is not shown, but is put into the help-echo
859 property so than moving the mouse over the command shows it.
860 Setting it to nil is good if matcher strings are very long and/or if
861 you want to use two-column display (see `org-agenda-menu-two-column')."
865 (defcustom org-agenda-menu-two-column nil
866 "Non-nil means, use two columns to show custom commands in the dispatcher.
867 If you use this, you probably want to set `org-agenda-menu-show-matcher'
872 (defcustom org-finalize-agenda-hook nil
873 "Hook run just before displaying an agenda buffer."
874 :group
'org-agenda-startup
877 (defcustom org-agenda-mouse-1-follows-link nil
878 "Non-nil means mouse-1 on a link will follow the link in the agenda.
879 A longer mouse click will still set point. Does not work on XEmacs.
880 Needs to be set before org.el is loaded."
881 :group
'org-agenda-startup
884 (defcustom org-agenda-start-with-follow-mode nil
885 "The initial value of follow mode in a newly created agenda window."
886 :group
'org-agenda-startup
889 (defcustom org-agenda-follow-indirect nil
890 "Non-nil means `org-agenda-follow-mode' displays only the
891 current item's tree, in an indirect buffer."
895 (defcustom org-agenda-show-outline-path t
896 "Non-nil means show outline path in echo area after line motion."
897 :group
'org-agenda-startup
900 (defcustom org-agenda-start-with-entry-text-mode nil
901 "The initial value of entry-text-mode in a newly created agenda window."
902 :group
'org-agenda-startup
905 (defcustom org-agenda-entry-text-maxlines
5
906 "Number of text lines to be added when `E' is pressed in the agenda.
908 Note that this variable only used during agenda display. Add add entry text
909 when exporting the agenda, configure the variable
910 `org-agenda-add-entry-ext-maxlines'."
914 (defcustom org-agenda-entry-text-exclude-regexps nil
915 "List of regular expressions to clean up entry text.
916 The complete matches of all regular expressions in this list will be
917 removed from entry text before it is shown in the agenda."
919 :type
'(repeat (regexp)))
921 (defvar org-agenda-entry-text-cleanup-hook nil
922 "Hook that is run after basic cleanup of entry text to be shown in agenda.
923 This cleanup is done in a temporary buffer, so the function may inspect and
924 change the entire buffer.
925 Some default stuff like drawers and scheduling/deadline dates will already
926 have been removed when this is called, as will any matches for regular
927 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
929 (defvar org-agenda-include-inactive-timestamps nil
930 "Non-nil means include inactive time stamps in agenda and timeline.")
932 (defgroup org-agenda-windows nil
933 "Options concerning the windows used by the Agenda in Org Mode."
934 :tag
"Org Agenda Windows"
937 (defcustom org-agenda-window-setup
'reorganize-frame
938 "How the agenda buffer should be displayed.
939 Possible values for this option are:
941 current-window Show agenda in the current window, keeping all other windows.
942 other-window Use `switch-to-buffer-other-window' to display agenda.
943 reorganize-frame Show only two windows on the current frame, the current
944 window and the agenda.
945 other-frame Use `switch-to-buffer-other-frame' to display agenda.
946 Also, when exiting the agenda, kill that frame.
947 See also the variable `org-agenda-restore-windows-after-quit'."
948 :group
'org-agenda-windows
950 (const current-window
)
953 (const reorganize-frame
)))
955 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
956 "The min and max height of the agenda window as a fraction of frame height.
957 The value of the variable is a cons cell with two numbers between 0 and 1.
958 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
959 :group
'org-agenda-windows
960 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
962 (defcustom org-agenda-restore-windows-after-quit nil
963 "Non-nil means restore window configuration upon exiting agenda.
964 Before the window configuration is changed for displaying the agenda,
965 the current status is recorded. When the agenda is exited with
966 `q' or `x' and this option is set, the old state is restored. If
967 `org-agenda-window-setup' is `other-frame', the value of this
968 option will be ignored."
969 :group
'org-agenda-windows
972 (defcustom org-agenda-ndays nil
973 "Number of days to include in overview display.
975 Obsolete, see `org-agenda-span'."
976 :group
'org-agenda-daily
/weekly
979 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
981 (defcustom org-agenda-span
'week
982 "Number of days to include in overview display.
983 Can be day, week, month, year, or any number of days.
984 Custom commands can set this variable in the options section."
985 :group
'org-agenda-daily
/weekly
986 :type
'(choice (const :tag
"Day" day
)
987 (const :tag
"Week" week
)
988 (const :tag
"Month" month
)
989 (const :tag
"Year" year
)
990 (integer :tag
"Custom")))
992 (defcustom org-agenda-start-on-weekday
1
993 "Non-nil means start the overview always on the specified weekday.
994 0 denotes Sunday, 1 denotes Monday etc.
995 When nil, always start on the current day.
996 Custom commands can set this variable in the options section."
997 :group
'org-agenda-daily
/weekly
998 :type
'(choice (const :tag
"Today" nil
)
999 (integer :tag
"Weekday No.")))
1001 (defcustom org-agenda-show-all-dates t
1002 "Non-nil means `org-agenda' shows every day in the selected range.
1003 When nil, only the days which actually have entries are shown."
1004 :group
'org-agenda-daily
/weekly
1007 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1008 "Format string for displaying dates in the agenda.
1009 Used by the daily/weekly agenda and by the timeline. This should be
1010 a format string understood by `format-time-string', or a function returning
1011 the formatted date as a string. The function must take a single argument,
1012 a calendar-style date list like (month day year)."
1013 :group
'org-agenda-daily
/weekly
1015 (string :tag
"Format string")
1016 (function :tag
"Function")))
1018 (defun org-agenda-format-date-aligned (date)
1019 "Format a date string for display in the daily/weekly agenda, or timeline.
1020 This function makes sure that dates are aligned for easy reading."
1022 (let* ((dayname (calendar-day-name date
))
1024 (day-of-week (calendar-day-of-week date
))
1026 (monthname (calendar-month-name month
))
1028 (iso-week (org-days-to-iso-week
1029 (calendar-absolute-from-gregorian date
)))
1030 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1032 ((and (= month
12) (<= iso-week
1))
1035 (weekstring (if (= day-of-week
1)
1036 (format " W%02d" iso-week
)
1038 (format "%-10s %2d %s %4d%s"
1039 dayname day monthname year weekstring
)))
1041 (defcustom org-agenda-time-leading-zero nil
1042 "Non-nil means use leading zero for military times in agenda.
1043 For example, 9:30am would become 09:30 rather than 9:30."
1044 :group
'org-agenda-daily
/weekly
1047 (defcustom org-agenda-timegrid-use-ampm nil
1048 "When set, show AM/PM style timestamps on the timegrid."
1052 (defun org-agenda-time-of-day-to-ampm (time)
1053 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1054 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1055 (minute (substring time -
2))
1058 ((equal hour-number
12)
1062 (setq hour-number
(- hour-number
12))))
1064 (if org-agenda-time-leading-zero
1065 (format "%02d" hour-number
)
1066 (format "%02s" (number-to-string hour-number
)))
1069 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1070 "Conditionally convert TIME to AM/PM format
1071 based on `org-agenda-timegrid-use-ampm'"
1072 (if org-agenda-timegrid-use-ampm
1073 (org-agenda-time-of-day-to-ampm time
)
1076 (defcustom org-agenda-weekend-days
'(6 0)
1077 "Which days are weekend?
1078 These days get the special face `org-agenda-date-weekend' in the agenda
1079 and timeline buffers."
1080 :group
'org-agenda-daily
/weekly
1081 :type
'(set :greedy t
1082 (const :tag
"Monday" 1)
1083 (const :tag
"Tuesday" 2)
1084 (const :tag
"Wednesday" 3)
1085 (const :tag
"Thursday" 4)
1086 (const :tag
"Friday" 5)
1087 (const :tag
"Saturday" 6)
1088 (const :tag
"Sunday" 0)))
1090 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1091 "Non-nil means jump to today when moving a past date forward in time.
1092 When using S-right in the agenda to move a a date forward, and the date
1093 stamp currently points to the past, the first key press will move it
1094 to today. WHen nil, just move one day forward even if the date stays
1096 :group
'org-agenda-daily
/weekly
1099 (defcustom org-agenda-include-diary nil
1100 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1101 Custom commands can set this variable in the options section."
1102 :group
'org-agenda-daily
/weekly
1105 (defcustom org-agenda-include-deadlines t
1106 "If non-nil, include entries within their deadline warning period.
1107 Custom commands can set this variable in the options section."
1108 :group
'org-agenda-daily
/weekly
1111 (defcustom org-agenda-repeating-timestamp-show-all t
1112 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1113 When set to a list of strings, only show occurrences of repeating
1114 stamps for these TODO keywords. When nil, only one occurrence is
1115 shown, either today or the nearest into the future."
1116 :group
'org-agenda-daily
/weekly
1118 (const :tag
"Show repeating stamps" t
)
1119 (repeat :tag
"Show repeating stamps for these TODO keywords"
1120 (string :tag
"TODO Keyword"))
1121 (const :tag
"Don't show repeating stamps" nil
)))
1123 (defcustom org-scheduled-past-days
10000
1124 "No. of days to continue listing scheduled items that are not marked DONE.
1125 When an item is scheduled on a date, it shows up in the agenda on this
1126 day and will be listed until it is marked done for the number of days
1128 :group
'org-agenda-daily
/weekly
1131 (defcustom org-agenda-log-mode-items
'(closed clock
)
1132 "List of items that should be shown in agenda log mode.
1133 This list may contain the following symbols:
1135 closed Show entries that have been closed on that day.
1136 clock Show entries that have received clocked time on that day.
1137 state Show all logged state changes.
1138 Note that instead of changing this variable, you can also press `C-u l' in
1139 the agenda to display all available LOG items temporarily."
1140 :group
'org-agenda-daily
/weekly
1141 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1143 (defcustom org-agenda-clock-consistency-checks
1144 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1145 :gap-ok-around
("4:00")
1146 :default-face
((:background
"DarkRed") (:foreground
"white"))
1147 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1148 :long-face nil
:short-face nil
)
1149 "This is a property list, with the following keys:
1151 :max-duration Mark clocking chunks that are longer than this time.
1152 This is a time string like \"HH:MM\", or the number
1153 of minutes as an integer.
1155 :min-duration Mark clocking chunks that are shorter that this.
1156 This is a time string like \"HH:MM\", or the number
1157 of minutes as an integer.
1159 :max-gap Mark gaps between clocking chunks that are longer than
1160 this duration. A number of minutes, or a string
1163 :gap-ok-around List of times during the day which are usually not working
1164 times. When a gap is detected, but the gap contains any
1165 of these times, the gap is *not* reported. For example,
1166 if this is (\"4:00\" \"13:00\") then gaps that contain
1167 4:00 in the morning (i.e. the night) and 13:00
1168 (i.e. a typical lunch time) do not cause a warning.
1169 You should have at least one time during the night in this
1170 list, or otherwise the first task each morning will trigger
1171 a warning because it follows a long gap.
1173 Furthermore, the following properties can be used to define faces for
1176 :default-face the default face, if the specific face is undefined
1177 :overlap-face face for overlapping clocks
1178 :gap-face face for gaps between clocks
1179 :no-end-time-face face for incomplete clocks
1180 :long-face face for clock intervals that are too long
1181 :short-face face for clock intervals that are too short"
1182 :group
'org-agenda-daily
/weekly
1186 (defcustom org-agenda-log-mode-add-notes t
1187 "Non-nil means add first line of notes to log entries in agenda views.
1188 If a log item like a state change or a clock entry is associated with
1189 notes, the first line of these notes will be added to the entry in the
1191 :group
'org-agenda-daily
/weekly
1194 (defcustom org-agenda-start-with-log-mode nil
1195 "The initial value of log-mode in a newly created agenda window."
1196 :group
'org-agenda-startup
1197 :group
'org-agenda-daily
/weekly
1200 (defcustom org-agenda-start-with-clockreport-mode nil
1201 "The initial value of clockreport-mode in a newly created agenda window."
1202 :group
'org-agenda-startup
1203 :group
'org-agenda-daily
/weekly
1206 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1207 "Property list with parameters for the clocktable in clockreport mode.
1208 This is the display mode that shows a clock table in the daily/weekly
1209 agenda, the properties for this dynamic block can be set here.
1210 The usual clocktable parameters are allowed here, but you cannot set
1211 the properties :name, :tstart, :tend, :block, and :scope - these will
1212 be overwritten to make sure the content accurately reflects the
1213 current display in the agenda."
1214 :group
'org-agenda-daily
/weekly
1217 (defcustom org-agenda-search-view-always-boolean nil
1218 "Non-nil means the search string is interpreted as individual parts.
1220 The search string for search view can either be interpreted as a phrase,
1221 or as a list of snippets that define a boolean search for a number of
1224 When this is non-nil, the string will be split on whitespace, and each
1225 snippet will be searched individually, and all must match in order to
1226 select an entry. A snippet is then a single string of non-white
1227 characters, or a string in double quotes, or a regexp in {} braces.
1228 If a snippet is preceded by \"-\", the snippet must *not* match.
1229 \"+\" is syntactic sugar for positive selection. Each snippet may
1230 be found as a full word or a partial word, but see the variable
1231 `org-agenda-search-view-force-full-words'.
1233 When this is nil, search will look for the entire search phrase as one,
1234 with each space character matching any amount of whitespace, including
1237 Even when this is nil, you can still switch to Boolean search dynamically
1238 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1239 is a regexp marked with braces like \"{abc}\", this will also switch to
1241 :group
'org-agenda-search-view
1244 (if (fboundp 'defvaralias
)
1245 (defvaralias 'org-agenda-search-view-search-words-only
1246 'org-agenda-search-view-always-boolean
))
1248 (defcustom org-agenda-search-view-force-full-words nil
1249 "Non-nil means, search words must be matches as complete words.
1250 When nil, they may also match part of a word."
1251 :group
'org-agenda-search-view
1254 (defgroup org-agenda-time-grid nil
1255 "Options concerning the time grid in the Org-mode Agenda."
1256 :tag
"Org Agenda Time Grid"
1259 (defcustom org-agenda-search-headline-for-time t
1260 "Non-nil means search headline for a time-of-day.
1261 If the headline contains a time-of-day in one format or another, it will
1262 be used to sort the entry into the time sequence of items for a day.
1263 Some people have time stamps in the headline that refer to the creation
1264 time or so, and then this produces an unwanted side effect. If this is
1265 the case for your, use this variable to turn off searching the headline
1267 :group
'org-agenda-time-grid
1270 (defcustom org-agenda-use-time-grid t
1271 "Non-nil means show a time grid in the agenda schedule.
1272 A time grid is a set of lines for specific times (like every two hours between
1273 8:00 and 20:00). The items scheduled for a day at specific times are
1274 sorted in between these lines.
1275 For details about when the grid will be shown, and what it will look like, see
1276 the variable `org-agenda-time-grid'."
1277 :group
'org-agenda-time-grid
1280 (defcustom org-agenda-time-grid
1281 '((daily today require-timed
)
1283 (800 1000 1200 1400 1600 1800 2000))
1285 "The settings for time grid for agenda display.
1286 This is a list of three items. The first item is again a list. It contains
1287 symbols specifying conditions when the grid should be displayed:
1289 daily if the agenda shows a single day
1290 weekly if the agenda shows an entire week
1291 today show grid on current date, independent of daily/weekly display
1292 require-timed show grid only if at least one item has a time specification
1294 The second item is a string which will be placed behind the grid time.
1296 The third item is a list of integers, indicating the times that should have
1298 :group
'org-agenda-time-grid
1301 (set :greedy t
:tag
"Grid Display Options"
1302 (const :tag
"Show grid in single day agenda display" daily
)
1303 (const :tag
"Show grid in weekly agenda display" weekly
)
1304 (const :tag
"Always show grid for today" today
)
1305 (const :tag
"Show grid only if any timed entries are present"
1307 (const :tag
"Skip grid times already present in an entry"
1309 (string :tag
"Grid String")
1310 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1312 (defcustom org-agenda-show-current-time-in-grid t
1313 "Non-nil means show the current time in the time grid."
1314 :group
'org-agenda-time-grid
1317 (defcustom org-agenda-current-time-string
1318 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1319 "The string for the current time marker in the agenda."
1320 :group
'org-agenda-time-grid
1323 (defgroup org-agenda-sorting nil
1324 "Options concerning sorting in the Org-mode Agenda."
1325 :tag
"Org Agenda Sorting"
1328 (defcustom org-agenda-sorting-strategy
1329 '((agenda habit-down time-up priority-down category-keep
)
1330 (todo priority-down category-keep
)
1331 (tags priority-down category-keep
)
1332 (search category-keep
))
1333 "Sorting structure for the agenda items of a single day.
1334 This is a list of symbols which will be used in sequence to determine
1335 if an entry should be listed before another entry. The following
1336 symbols are recognized:
1338 time-up Put entries with time-of-day indications first, early first
1339 time-down Put entries with time-of-day indications first, late first
1340 category-keep Keep the default order of categories, corresponding to the
1341 sequence in `org-agenda-files'.
1342 category-up Sort alphabetically by category, A-Z.
1343 category-down Sort alphabetically by category, Z-A.
1344 tag-up Sort alphabetically by last tag, A-Z.
1345 tag-down Sort alphabetically by last tag, Z-A.
1346 priority-up Sort numerically by priority, high priority last.
1347 priority-down Sort numerically by priority, high priority first.
1348 todo-state-up Sort by todo state, tasks that are done last.
1349 todo-state-down Sort by todo state, tasks that are done first.
1350 effort-up Sort numerically by estimated effort, high effort last.
1351 effort-down Sort numerically by estimated effort, high effort first.
1352 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1353 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1354 habit-up Put entries that are habits first
1355 habit-down Put entries that are habits last
1356 alpha-up Sort headlines alphabetically
1357 alpha-down Sort headlines alphabetically, reversed
1359 The different possibilities will be tried in sequence, and testing stops
1360 if one comparison returns a \"not-equal\". For example, the default
1361 '(time-up category-keep priority-down)
1362 means: Pull out all entries having a specified time of day and sort them,
1363 in order to make a time schedule for the current day the first thing in the
1364 agenda listing for the day. Of the entries without a time indication, keep
1365 the grouped in categories, don't sort the categories, but keep them in
1366 the sequence given in `org-agenda-files'. Within each category sort by
1369 Leaving out `category-keep' would mean that items will be sorted across
1370 categories by priority.
1372 Instead of a single list, this can also be a set of list for specific
1373 contents, with a context symbol in the car of the list, any of
1374 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1376 Custom commands can bind this variable in the options section."
1377 :group
'org-agenda-sorting
1379 (repeat :tag
"General" ,org-sorting-choice
)
1380 (list :tag
"Individually"
1381 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1382 (repeat ,org-sorting-choice
))
1383 (cons (const :tag
"Strategy for TODO lists" todo
)
1384 (repeat ,org-sorting-choice
))
1385 (cons (const :tag
"Strategy for Tags matches" tags
)
1386 (repeat ,org-sorting-choice
))
1387 (cons (const :tag
"Strategy for search matches" search
)
1388 (repeat ,org-sorting-choice
)))))
1390 (defcustom org-agenda-cmp-user-defined nil
1391 "A function to define the comparison `user-defined'.
1392 This function must receive two arguments, agenda entry a and b.
1393 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1394 the user comparison, return nil.
1395 When this is defined, you can make `user-defined-up' and `user-defined-down'
1396 part of an agenda sorting strategy."
1397 :group
'org-agenda-sorting
1400 (defcustom org-sort-agenda-notime-is-late t
1401 "Non-nil means items without time are considered late.
1402 This is only relevant for sorting. When t, items which have no explicit
1403 time like 15:30 will be considered as 99:01, i.e. later than any items which
1404 do have a time. When nil, the default time is before 0:00. You can use this
1405 option to decide if the schedule for today should come before or after timeless
1407 :group
'org-agenda-sorting
1410 (defcustom org-sort-agenda-noeffort-is-high t
1411 "Non-nil means items without effort estimate are sorted as high effort.
1412 This also applies when filtering an agenda view with respect to the
1413 < or > effort operator. Then, tasks with no effort defined will be treated
1414 as tasks with high effort.
1415 When nil, such items are sorted as 0 minutes effort."
1416 :group
'org-agenda-sorting
1419 (defgroup org-agenda-line-format nil
1420 "Options concerning the entry prefix in the Org-mode agenda display."
1421 :tag
"Org Agenda Line Format"
1424 (defcustom org-agenda-prefix-format
1425 '((agenda .
" %i %-12:c%?-12t% s")
1427 (todo .
" %i %-12:c")
1428 (tags .
" %i %-12:c")
1429 (search .
" %i %-12:c"))
1430 "Format specifications for the prefix of items in the agenda views.
1431 An alist with five entries, each for the different agenda types. The
1432 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1433 The values are format strings.
1435 This format works similar to a printf format, with the following meaning:
1437 %c the category of the item, \"Diary\" for entries from the diary,
1438 or as given by the CATEGORY keyword or derived from the file name
1439 %e the effort required by the item
1440 %i the icon category of the item, see `org-agenda-category-icon-alist'
1441 %T the last tag of the item (ignore inherited tags, which come first)
1442 %t the HH:MM time-of-day specification if one applies to the entry
1443 %s Scheduling/Deadline information, a short string
1444 %(expression) Eval EXPRESSION and replace the control string
1447 All specifiers work basically like the standard `%s' of printf, but may
1448 contain two additional characters: a question mark just after the `%'
1449 and a whitespace/punctuation character just before the final letter.
1451 If the first character after `%' is a question mark, the entire field
1452 will only be included if the corresponding value applies to the current
1453 entry. This is useful for fields which should have fixed width when
1454 present, but zero width when absent. For example, \"%?-12t\" will
1455 result in a 12 character time field if a time of the day is specified,
1456 but will completely disappear in entries which do not contain a time.
1458 If there is punctuation or whitespace character just before the final
1459 format letter, this character will be appended to the field value if
1460 the value is not empty. For example, the format \"%-12:c\" leads to
1461 \"Diary: \" if the category is \"Diary\". If the category were be
1462 empty, no additional colon would be inserted.
1464 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1467 - Indent the line with two space characters
1468 - Give the category a 12 chars wide field, padded with whitespace on
1469 the right (because of `-'). Append a colon if there is a category
1471 - If there is a time-of-day, put it into a 12 chars wide field. If no
1472 time, don't put in an empty field, just skip it (because of '?').
1473 - Finally, put the scheduling information.
1475 See also the variables `org-agenda-remove-times-when-in-prefix' and
1476 `org-agenda-remove-tags'.
1478 Custom commands can set this variable in the options section."
1480 (string :tag
"General format")
1481 (list :greedy t
:tag
"View dependent"
1482 (cons (const agenda
) (string :tag
"Format"))
1483 (cons (const timeline
) (string :tag
"Format"))
1484 (cons (const todo
) (string :tag
"Format"))
1485 (cons (const tags
) (string :tag
"Format"))
1486 (cons (const search
) (string :tag
"Format"))))
1487 :group
'org-agenda-line-format
)
1489 (defvar org-prefix-format-compiled nil
1490 "The compiled version of the most recently used prefix format.
1491 See the variable `org-agenda-prefix-format'.")
1493 (defcustom org-agenda-todo-keyword-format
"%-1s"
1494 "Format for the TODO keyword in agenda lines.
1495 Set this to something like \"%-12s\" if you want all TODO keywords
1496 to occupy a fixed space in the agenda display."
1497 :group
'org-agenda-line-format
1500 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1501 "Text preceding timerange entries in the agenda view.
1502 This is a list with two strings. The first applies when the range
1503 is entirely on one day. The second applies if the range spans several days.
1504 The strings may have two \"%d\" format specifiers which will be filled
1505 with the sequence number of the days, and the total number of days in the
1506 range, respectively."
1507 :group
'org-agenda-line-format
1509 (string :tag
"Deadline today ")
1510 (choice :tag
"Deadline relative"
1511 (string :tag
"Format string")
1514 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1515 "Text preceding scheduled items in the agenda view.
1516 This is a list with two strings. The first applies when the item is
1517 scheduled on the current day. The second applies when it has been scheduled
1518 previously, it may contain a %d indicating that this is the nth time that
1519 this item is scheduled, due to automatic rescheduling of unfinished items
1520 for the following day. So this number is one larger than the number of days
1521 that passed since this item was scheduled first."
1522 :group
'org-agenda-line-format
1524 (string :tag
"Scheduled today ")
1525 (string :tag
"Scheduled previously")))
1527 (defcustom org-agenda-inactive-leader
"["
1528 "Text preceding item pulled into the agenda by inactive time stamps.
1529 These entries are added to the agenda when pressing \"[\"."
1530 :group
'org-agenda-line-format
1532 (string :tag
"Scheduled today ")
1533 (string :tag
"Scheduled previously")))
1535 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1536 "Text preceding deadline items in the agenda view.
1537 This is a list with two strings. The first applies when the item has its
1538 deadline on the current day. The second applies when it is in the past or
1539 in the future, it may contain %d to capture how many days away the deadline
1541 :group
'org-agenda-line-format
1543 (string :tag
"Deadline today ")
1544 (choice :tag
"Deadline relative"
1545 (string :tag
"Format string")
1548 (defcustom org-agenda-remove-times-when-in-prefix t
1549 "Non-nil means remove duplicate time specifications in agenda items.
1550 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1551 time-of-day specification in a headline or diary entry is extracted and
1552 placed into the prefix. If this option is non-nil, the original specification
1553 \(a timestamp or -range, or just a plain time(range) specification like
1554 11:30-4pm) will be removed for agenda display. This makes the agenda less
1556 The option can be t or nil. It may also be the symbol `beg', indicating
1557 that the time should only be removed when it is located at the beginning of
1558 the headline/diary entry."
1559 :group
'org-agenda-line-format
1561 (const :tag
"Always" t
)
1562 (const :tag
"Never" nil
)
1563 (const :tag
"When at beginning of entry" beg
)))
1565 (defcustom org-agenda-remove-timeranges-from-blocks nil
1566 "Non-nil means remove time ranges specifications in agenda
1567 items that span on several days."
1568 :group
'org-agenda-line-format
1571 (defcustom org-agenda-default-appointment-duration nil
1572 "Default duration for appointments that only have a starting time.
1573 When nil, no duration is specified in such cases.
1574 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1575 :group
'org-agenda-line-format
1577 (integer :tag
"Minutes")
1578 (const :tag
"No default duration")))
1580 (defcustom org-agenda-show-inherited-tags t
1581 "Non-nil means show inherited tags in each agenda line."
1582 :group
'org-agenda-line-format
1585 (defcustom org-agenda-hide-tags-regexp nil
1586 "Regular expression used to filter away specific tags in agenda views.
1587 This means that these tags will be present, but not be shown in the agenda
1588 line. Secondary filtering will still work on the hidden tags.
1589 Nil means don't hide any tags."
1590 :group
'org-agenda-line-format
1592 (const :tag
"Hide none" nil
)
1593 (string :tag
"Regexp ")))
1595 (defcustom org-agenda-remove-tags nil
1596 "Non-nil means remove the tags from the headline copy in the agenda.
1597 When this is the symbol `prefix', only remove tags when
1598 `org-agenda-prefix-format' contains a `%T' specifier."
1599 :group
'org-agenda-line-format
1601 (const :tag
"Always" t
)
1602 (const :tag
"Never" nil
)
1603 (const :tag
"When prefix format contains %T" prefix
)))
1605 (if (fboundp 'defvaralias
)
1606 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1607 'org-agenda-remove-tags
))
1609 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1610 "Shift tags in agenda items to this column.
1611 If this number is positive, it specifies the column. If it is negative,
1612 it means that the tags should be flushright to that column. For example,
1613 -80 works well for a normal 80 character screen."
1614 :group
'org-agenda-line-format
1617 (if (fboundp 'defvaralias
)
1618 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1620 (defcustom org-agenda-fontify-priorities
'cookies
1621 "Non-nil means highlight low and high priorities in agenda.
1622 When t, the highest priority entries are bold, lowest priority italic.
1623 However, settings in `org-priority-faces' will overrule these faces.
1624 When this variable is the symbol `cookies', only fontify the
1625 cookies, not the entire task.
1626 This may also be an association list of priority faces, whose
1627 keys are the character values of `org-highest-priority',
1628 `org-default-priority', and `org-lowest-priority' (the default values
1629 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1630 color as a string, or a list like `(:background \"Red\")'.
1631 If it is a color, the variable `org-faces-easy-properties'
1632 determines if it is a foreground or a background color."
1633 :group
'org-agenda-line-format
1635 (const :tag
"Never" nil
)
1636 (const :tag
"Defaults" t
)
1637 (const :tag
"Cookies only" cookies
)
1638 (repeat :tag
"Specify"
1639 (list (character :tag
"Priority" :value ?A
)
1640 (choice :tag
"Face "
1641 (string :tag
"Color")
1642 (sexp :tag
"Face"))))))
1644 (defcustom org-agenda-day-face-function nil
1645 "Function called to determine what face should be used to display a day.
1646 The only argument passed to that function is the day. It should
1647 returns a face, or nil if does not want to specify a face and let
1648 the normal rules apply."
1649 :group
'org-agenda-line-format
1652 (defcustom org-agenda-category-icon-alist nil
1653 "Alist of category icon to be displayed in agenda views.
1655 Each entry should have the following format:
1657 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1659 Where CATEGORY-REGEXP is a regexp matching the categories where
1660 the icon should be displayed.
1661 FILE-OR-DATA either a file path or a string containing image data.
1663 The other fields can be omitted safely if not needed:
1664 TYPE indicates the image type.
1665 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1667 PROPS are additional image attributes to assign to the image,
1668 like, e.g. `:ascent center'.
1670 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1672 If you want to set the display properties yourself, just put a
1673 list as second element:
1675 (CATEGORY-REGEXP (MY PROPERTY LIST))
1677 For example, to display a 16px horizontal space for Emacs
1678 category, you can use:
1680 (\"Emacs\" '(space . (:width (16))))"
1681 :group
'org-agenda-line-format
1682 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1683 :value-type
(choice (list :tag
"Icon"
1684 (string :tag
"File or data")
1685 (symbol :tag
"Type")
1686 (boolean :tag
"Data?")
1687 (repeat :tag
"Extra image properties" :inline t symbol
))
1688 (list :tag
"Display properties" sexp
))))
1690 (defgroup org-agenda-column-view nil
1691 "Options concerning column view in the agenda."
1692 :tag
"Org Agenda Column View"
1695 (defcustom org-agenda-columns-show-summaries t
1696 "Non-nil means show summaries for columns displayed in the agenda view."
1697 :group
'org-agenda-column-view
1700 (defcustom org-agenda-columns-compute-summary-properties t
1701 "Non-nil means recompute all summary properties before column view.
1702 When column view in the agenda is listing properties that have a summary
1703 operator, it can go to all relevant buffers and recompute the summaries
1704 there. This can mean overhead for the agenda column view, but is necessary
1705 to have thing up to date.
1706 As a special case, a CLOCKSUM property also makes sure that the clock
1707 computations are current."
1708 :group
'org-agenda-column-view
1711 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1712 "Non-nil means the duration of an appointment will add to day effort.
1713 The property to which appointment durations will be added is the one given
1714 in the option `org-effort-property'. If an appointment does not have
1715 an end time, `org-agenda-default-appointment-duration' will be used. If that
1716 is not set, an appointment without end time will not contribute to the time
1718 :group
'org-agenda-column-view
1721 (defcustom org-agenda-auto-exclude-function nil
1722 "A function called with a tag to decide if it is filtered on '/ RET'.
1723 The sole argument to the function, which is called once for each
1724 possible tag, is a string giving the name of the tag. The
1725 function should return either nil if the tag should be included
1726 as normal, or \"-<TAG>\" to exclude the tag.
1727 Note that for the purpose of tag filtering, only the lower-case version of
1728 all tags will be considered, so that this function will only ever see
1729 the lower-case version of all tags."
1733 (defcustom org-agenda-bulk-custom-functions nil
1734 "Alist of characters and custom functions for bulk actions.
1735 For example, this value makes those two functions available:
1740 With selected entries in an agenda buffer, `B R' will call
1741 the custom function `set-category' on the selected entries.
1742 Note that functions in this alist don't need to be quoted."
1750 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
1751 "Execute BODY with point at location given by `org-hd-marker' property.
1752 If STRING is non-nil, the text property will be fetched from position 0
1753 in that string. If STRING is nil, it will be fetched from the beginning
1754 of the current line."
1755 (org-with-gensyms (marker)
1756 `(let ((,marker
(get-text-property (if string
0 (point-at-bol))
1757 'org-hd-marker
,string
)))
1758 (with-current-buffer (marker-buffer ,marker
)
1762 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
1764 (defun org-add-agenda-custom-command (entry)
1765 "Replace or add a command in `org-agenda-custom-commands'.
1766 This is mostly for hacking and trying a new command - once the command
1767 works you probably want to add it to `org-agenda-custom-commands' for good."
1768 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1770 (setcdr ass
(cdr entry
))
1771 (push entry org-agenda-custom-commands
))))
1773 ;;; Define the Org-agenda-mode
1775 (defvar org-agenda-mode-map
(make-sparse-keymap)
1776 "Keymap for `org-agenda-mode'.")
1777 (if (fboundp 'defvaralias
)
1778 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1780 (defvar org-agenda-menu
) ; defined later in this file.
1781 (defvar org-agenda-restrict
) ; defined later in this file.
1782 (defvar org-agenda-follow-mode nil
)
1783 (defvar org-agenda-entry-text-mode nil
)
1784 (defvar org-agenda-clockreport-mode nil
)
1785 (defvar org-agenda-show-log nil
)
1786 (defvar org-agenda-redo-command nil
)
1787 (defvar org-agenda-query-string nil
)
1788 (defvar org-agenda-mode-hook nil
1789 "Hook for `org-agenda-mode', run after the mode is turned on.")
1790 (defvar org-agenda-type nil
)
1791 (defvar org-agenda-force-single-file nil
)
1792 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1794 (defun org-agenda-mode ()
1795 "Mode for time-sorted view on action items in Org-mode files.
1797 The following commands are available:
1799 \\{org-agenda-mode-map}"
1801 (kill-all-local-variables)
1802 (setq org-agenda-undo-list nil
1803 org-agenda-pending-undo-list nil
1804 org-agenda-bulk-marked-entries nil
)
1805 (setq major-mode
'org-agenda-mode
)
1806 ;; Keep global-font-lock-mode from turning on font-lock-mode
1807 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1808 (setq mode-name
"Org-Agenda")
1809 (use-local-map org-agenda-mode-map
)
1810 (easy-menu-add org-agenda-menu
)
1811 (if org-startup-truncated
(setq truncate-lines t
))
1812 (org-set-local 'line-move-visual nil
)
1813 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1814 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1815 ;; Make sure properties are removed when copying text
1816 (when (boundp 'buffer-substring-filters
)
1817 (org-set-local 'buffer-substring-filters
1819 (set-text-properties 0 (length x
) nil x
) x
)
1820 buffer-substring-filters
)))
1821 (unless org-agenda-keep-modes
1822 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1823 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1824 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1825 org-agenda-show-log org-agenda-start-with-log-mode
))
1828 '("Agenda") "Agenda Files"
1832 (if (get 'org-agenda-files
'org-restrict
)
1833 "Restricted to single file"
1835 '(org-edit-agenda-file-list)
1836 (not (get 'org-agenda-files
'org-restrict
)))
1838 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1839 (org-agenda-set-mode-name)
1841 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1842 (list 'org-agenda-mode-hook
)))
1844 (substitute-key-definition 'undo
'org-agenda-undo
1845 org-agenda-mode-map global-map
)
1846 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1847 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1848 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1849 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1850 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1851 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1852 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
1853 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1854 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1855 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
1856 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1857 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1858 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1859 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1860 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1861 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1862 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1863 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1864 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1865 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1866 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1867 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1868 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1869 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1870 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1871 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1872 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1873 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1874 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1875 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1876 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1877 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1878 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1879 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1880 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1881 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1882 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1883 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1884 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1885 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1886 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1887 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1888 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1889 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1890 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1892 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1893 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1894 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1895 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1896 (while l (org-defkey org-agenda-mode-map
1897 (int-to-string (pop l)) 'digit-argument)))
1899 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1900 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1901 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1902 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1903 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1904 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1905 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1906 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1907 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1908 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1909 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1910 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1911 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1912 'org-clock-modify-effort-estimate)
1913 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1914 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1915 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1916 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
1917 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1918 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1919 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1920 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1921 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1922 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1923 (substitute-key-definition 'next-line 'org-agenda-next-line
1924 org-agenda-mode-map global-map)
1925 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1926 org-agenda-mode-map global-map)
1927 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1928 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1929 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1930 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1931 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1932 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1933 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1934 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1935 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1936 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1937 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1938 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1939 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1940 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1941 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1942 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1943 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1944 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1945 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1946 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1947 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1948 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1949 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1950 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1951 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1952 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1953 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1954 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1955 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1956 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1958 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1959 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1960 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1961 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1962 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1963 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1964 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
1965 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1966 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1967 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1968 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1970 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1971 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1972 (when org-agenda-mouse-1-follows-link
1973 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1974 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1979 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1980 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1981 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1982 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1985 ["Day View" org-agenda-day-view
1986 :active (org-agenda-check-type nil 'agenda)
1987 :style radio :selected (eq org-agenda-current-span 'day)
1988 :keys "v d (or just d)"]
1989 ["Week View" org-agenda-week-view
1990 :active (org-agenda-check-type nil 'agenda)
1991 :style radio :selected (eq org-agenda-current-span 'week)
1992 :keys "v w (or just w)"]
1993 ["Month View" org-agenda-month-view
1994 :active (org-agenda-check-type nil 'agenda)
1995 :style radio :selected (eq org-agenda-current-span 'month)
1997 ["Year View" org-agenda-year-view
1998 :active (org-agenda-check-type nil 'agenda)
1999 :style radio :selected (eq org-agenda-current-span 'year)
2002 ["Include Diary" org-agenda-toggle-diary
2003 :style toggle :selected org-agenda-include-diary
2004 :active (org-agenda-check-type nil 'agenda)]
2005 ["Include Deadlines" org-agenda-toggle-deadlines
2006 :style toggle :selected org-agenda-include-deadlines
2007 :active (org-agenda-check-type nil 'agenda)]
2008 ["Use Time Grid" org-agenda-toggle-time-grid
2009 :style toggle :selected org-agenda-use-time-grid
2010 :active (org-agenda-check-type nil 'agenda)]
2012 ["Show clock report" org-agenda-clockreport-mode
2013 :style toggle :selected org-agenda-clockreport-mode
2014 :active (org-agenda-check-type nil 'agenda)]
2015 ["Show some entry text" org-agenda-entry-text-mode
2016 :style toggle :selected org-agenda-entry-text-mode
2019 ["Show Logbook entries" org-agenda-log-mode
2020 :style toggle :selected org-agenda-show-log
2021 :active (org-agenda-check-type nil 'agenda 'timeline)
2022 :keys "v l (or just l)"]
2023 ["Include archived trees" org-agenda-archives-mode
2024 :style toggle :selected org-agenda-archives-mode :active t
2026 ["Include archive files" (org-agenda-archives-mode t)
2027 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2030 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2031 ["Write view to file" org-agenda-write t]
2032 ["Rebuild buffer" org-agenda-redo t]
2033 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2035 ["Show original entry" org-agenda-show t]
2036 ["Go To (other window)" org-agenda-goto t]
2037 ["Go To (this window)" org-agenda-switch-to t]
2038 ["Follow Mode" org-agenda-follow-mode
2039 :style toggle :selected org-agenda-follow-mode :active t]
2040 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2043 ["Cycle TODO" org-agenda-todo t]
2044 ["Next TODO set" org-agenda-todo-nextset t]
2045 ["Previous TODO set" org-agenda-todo-previousset t]
2046 ["Add note" org-agenda-add-note t])
2047 ("Archive/Refile/Delete"
2048 ["Archive default" org-agenda-archive-default t]
2049 ["Archive default" org-agenda-archive-default-with-confirmation t]
2050 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2051 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2052 ["Archive subtree" org-agenda-archive t]
2054 ["Refile" org-agenda-refile t]
2056 ["Delete subtree" org-agenda-kill t])
2058 ["Mark entry" org-agenda-bulk-mark t]
2059 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2060 ["Unmark entry" org-agenda-bulk-unmark t]
2061 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2062 ["Act on all marked" org-agenda-bulk-action t]
2064 ("Tags and Properties"
2065 ["Show all Tags" org-agenda-show-tags t]
2066 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2067 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2069 ["Column View" org-columns t])
2070 ("Deadline/Schedule"
2071 ["Schedule" org-agenda-schedule t]
2072 ["Set Deadline" org-agenda-deadline t]
2074 ["Mark item" org-agenda-action :active t :keys "k m"]
2075 ["Show mark item" org-agenda-action :active t :keys "k v"]
2076 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2077 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2079 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2080 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2081 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2082 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2083 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2084 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2085 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2087 ["Clock in" org-agenda-clock-in t]
2088 ["Clock out" org-agenda-clock-out t]
2089 ["Clock cancel" org-agenda-clock-cancel t]
2090 ["Goto running clock" org-clock-goto t]
2092 ["Set Effort" org-agenda-set-effort t]
2093 ["Change clocked effort" org-clock-modify-effort-estimate
2094 (org-clock-is-active)])
2096 ["Set Priority" org-agenda-priority t]
2097 ["Increase Priority" org-agenda-priority-up t]
2098 ["Decrease Priority" org-agenda-priority-down t]
2099 ["Show Priority" org-agenda-show-priority t])
2101 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2102 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2103 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2104 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2105 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2106 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2108 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2110 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2113 ["Push Files and Views" org-mobile-push t]
2114 ["Get Captured and Flagged" org-mobile-pull t]
2115 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2116 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2118 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2120 ["Quit" org-agenda-quit t]
2121 ["Exit and Release Buffers" org-agenda-exit t]
2126 (defvar org-agenda-allow-remote-undo t
2127 "Non-nil means allow remote undo from the agenda buffer.")
2128 (defvar org-agenda-undo-list nil
2129 "List of undoable operations in the agenda since last refresh.")
2130 (defvar org-agenda-undo-has-started-in nil
2131 "Buffers that have already seen `undo-start' in the current undo sequence.")
2132 (defvar org-agenda-pending-undo-list nil
2133 "In a series of undo commands, this is the list of remaining undo items.")
2135 (defun org-agenda-undo ()
2136 "Undo a remote editing step in the agenda.
2137 This undoes changes both in the agenda buffer and in the remote buffer
2138 that have been changed along."
2140 (or org-agenda-allow-remote-undo
2141 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2142 (if (not (eq this-command last-command))
2143 (setq org-agenda-undo-has-started-in nil
2144 org-agenda-pending-undo-list org-agenda-undo-list))
2145 (if (not org-agenda-pending-undo-list)
2146 (error "No further undo information"))
2147 (let* ((entry (pop org-agenda-pending-undo-list))
2148 buf line cmd rembuf)
2149 (setq cmd (pop entry) line (pop entry))
2150 (setq rembuf (nth 2 entry))
2151 (org-with-remote-undo rembuf
2152 (while (bufferp (setq buf (pop entry)))
2154 (with-current-buffer buf
2155 (let ((last-undo-buffer buf)
2156 (inhibit-read-only t))
2157 (unless (memq buf org-agenda-undo-has-started-in)
2158 (push buf org-agenda-undo-has-started-in)
2159 (make-local-variable 'pending-undo-list)
2161 (while (and pending-undo-list
2162 (listp pending-undo-list)
2163 (not (car pending-undo-list)))
2164 (pop pending-undo-list))
2166 (org-goto-line line)
2167 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2169 (defun org-verify-change-for-undo (l1 l2)
2170 "Verify that a real change occurred between the undo lists L1 and L2."
2171 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2172 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2177 (defvar org-agenda-restrict nil)
2178 (defvar org-agenda-restrict-begin (make-marker))
2179 (defvar org-agenda-restrict-end (make-marker))
2180 (defvar org-agenda-last-dispatch-buffer nil)
2181 (defvar org-agenda-overriding-restriction nil)
2184 (defun org-agenda (&optional arg keys restriction)
2185 "Dispatch agenda commands to collect entries to the agenda buffer.
2186 Prompts for a command to execute. Any prefix arg will be passed
2187 on to the selected command. The default selections are:
2189 a Call `org-agenda-list' to display the agenda for current day or week.
2190 t Call `org-todo-list' to display the global todo list.
2191 T Call `org-todo-list' to display the global todo list, select only
2192 entries with a specific TODO keyword (the user gets a prompt).
2193 m Call `org-tags-view' to display headlines with tags matching
2194 a condition (the user is prompted for the condition).
2195 M Like `m', but select only TODO entries, no ordinary headlines.
2196 L Create a timeline for the current buffer.
2197 e Export views to associated files.
2198 s Search entries for keywords.
2199 / Multi occur across all agenda files and also files listed
2200 in `org-agenda-text-search-extra-files'.
2201 < Restrict agenda commands to buffer, subtree, or region.
2202 Press several times to get the desired effect.
2203 > Remove a previous restriction.
2204 # List \"stuck\" projects.
2205 ! Configure what \"stuck\" means.
2206 C Configure custom agenda commands.
2208 More commands can be added by configuring the variable
2209 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2210 searches can be pre-defined in this way.
2212 If the current buffer is in Org-mode and visiting a file, you can also
2213 first press `<' once to indicate that the agenda should be temporarily
2214 \(until the next use of \\[org-agenda]) restricted to the current file.
2215 Pressing `<' twice means to restrict to the current subtree or region
2219 (let* ((prefix-descriptions nil)
2220 (org-agenda-window-setup (if (equal (buffer-name)
2221 org-agenda-buffer-name)
2223 org-agenda-window-setup))
2224 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2225 (org-agenda-custom-commands
2226 ;; normalize different versions
2230 (cond ((stringp (cdr x))
2231 (push x prefix-descriptions)
2233 ((stringp (nth 1 x)) x)
2234 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2235 (t (cons (car x) (cons "" (cdr x))))))
2236 org-agenda-custom-commands)))
2237 (buf (current-buffer))
2238 (bfn (buffer-file-name (buffer-base-buffer)))
2239 entry key type match lprops ans)
2240 ;; Turn off restriction unless there is an overriding one,
2241 (unless org-agenda-overriding-restriction
2242 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2243 ;; There is a request to keep the file list in place
2244 (put 'org-agenda-files 'org-restrict nil))
2245 (setq org-agenda-restrict nil)
2246 (move-marker org-agenda-restrict-begin nil)
2247 (move-marker org-agenda-restrict-end nil))
2248 ;; Delete old local properties
2249 (put 'org-agenda-redo-command 'org-lprops nil)
2250 ;; Delete previously set last-arguments
2251 (put 'org-agenda-redo-command 'last-args nil)
2252 ;; Remember where this call originated
2253 (setq org-agenda-last-dispatch-buffer (current-buffer))
2255 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2257 restriction (cdr ans)))
2258 ;; Establish the restriction, if any
2259 (when (and (not org-agenda-overriding-restriction) restriction)
2260 (put 'org-agenda-files 'org-restrict (list bfn))
2262 ((eq restriction 'region)
2263 (setq org-agenda-restrict t)
2264 (move-marker org-agenda-restrict-begin (region-beginning))
2265 (move-marker org-agenda-restrict-end (region-end)))
2266 ((eq restriction 'subtree)
2268 (setq org-agenda-restrict t)
2269 (org-back-to-heading t)
2270 (move-marker org-agenda-restrict-begin (point))
2271 (move-marker org-agenda-restrict-end
2272 (progn (org-end-of-subtree t)))))))
2274 ;; For example the todo list should not need it (but does...)
2276 ((setq entry (assoc keys org-agenda-custom-commands))
2277 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2279 (setq type (nth 2 entry) match (eval (nth 3 entry))
2280 lprops (nth 4 entry))
2281 (put 'org-agenda-redo-command 'org-lprops lprops)
2284 (org-let lprops '(org-agenda-list current-prefix-arg)))
2286 (org-let lprops '(org-todo-list current-prefix-arg)))
2288 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2290 (org-let lprops '(org-agenda-list-stuck-projects
2291 current-prefix-arg)))
2293 (org-let lprops '(org-tags-view current-prefix-arg match)))
2294 ((eq type 'tags-todo)
2295 (org-let lprops '(org-tags-view '(4) match)))
2297 (org-let lprops '(org-todo-list match)))
2298 ((eq type 'tags-tree)
2299 (org-check-for-org-mode)
2300 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2301 ((eq type 'todo-tree)
2302 (org-check-for-org-mode)
2304 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2305 (regexp-quote match) "\\>"))))
2306 ((eq type 'occur-tree)
2307 (org-check-for-org-mode)
2308 (org-let lprops '(org-occur match)))
2310 (org-let lprops '(funcall type match)))
2312 (org-let lprops '(funcall type match)))
2313 (t (error "Invalid custom agenda command type %s" type))))
2314 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2316 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2317 (customize-variable 'org-agenda-custom-commands))
2318 ((equal keys "a") (call-interactively 'org-agenda-list))
2319 ((equal keys "s") (call-interactively 'org-search-view))
2320 ((equal keys "t") (call-interactively 'org-todo-list))
2321 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2322 ((equal keys "m") (call-interactively 'org-tags-view))
2323 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2324 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2325 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2329 (unless (current-message)
2330 (let* ((m (org-agenda-get-any-marker))
2331 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2334 "FLAGGING-NOTE ([?] for more info): "
2336 (replace-regexp-in-string
2338 (copy-sequence note))
2339 nil 'face 'org-warning)))))))
2342 (unless (eq major-mode 'org-mode)
2343 (error "This is not an Org-mode file"))
2345 (put 'org-agenda-files 'org-restrict (list bfn))
2346 (org-call-with-arg 'org-timeline arg)))
2347 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2348 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2349 ((equal keys "!") (customize-variable 'org-stuck-projects))
2350 (t (error "Invalid agenda key"))))))
2352 (defun org-agenda-append-agenda ()
2353 "Append another agenda view to the current one.
2354 This function allows interactive building of block agendas.
2355 Agenda views are separated by `org-agenda-block-separator'."
2357 (unless (string= (buffer-name) org-agenda-buffer-name)
2358 (error "Can only append from within agenda buffer"))
2359 (let ((org-agenda-multi t))
2363 (defun org-agenda-normalize-custom-commands (cmds)
2367 (cond ((stringp (cdr x)) nil)
2368 ((stringp (nth 1 x)) x)
2369 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2370 (t (cons (car x) (cons "" (cdr x))))))
2373 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2374 "The user interface for selecting an agenda command."
2376 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2377 (restrict-ok (and bfn (eq major-mode 'org-mode)))
2378 (region-p (org-region-active-p))
2379 (custom org-agenda-custom-commands)
2381 restriction second-time
2382 c entry key type match prefixes rmheader header-end custom1 desc
2383 line lines left right n n1)
2384 (save-window-excursion
2385 (delete-other-windows)
2386 (org-switch-to-buffer-other-window " *Agenda Commands*")
2388 (insert (eval-when-compile
2391 Press key for an agenda command: < Buffer, subtree/region restriction
2392 -------------------------------- > Remove restriction
2393 a Agenda for current week or day e Export agenda views
2394 t List of all TODO entries T Entries with special TODO kwd
2395 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2396 L Timeline for current buffer # List stuck projects (!=configure)
2397 s Search for keywords C Configure custom agenda commands
2398 / Multi-occur ? Find :FLAGGED: entries
2401 (while (string-match
2402 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2404 (setq start (match-end 0))
2405 (add-text-properties (match-beginning 2) (match-end 2)
2406 '(face bold) header))
2408 (setq header-end (move-marker (make-marker) (point)))
2410 (setq custom1 custom)
2411 (when (eq rmheader t)
2413 (re-search-forward ":" nil t)
2414 (delete-region (match-end 0) (point-at-eol))
2417 (delete-region (match-end 0) (point-at-eol))
2418 (move-marker header-end (match-end 0)))
2419 (goto-char header-end)
2420 (delete-region (point) (point-max))
2422 ;; Produce all the lines that describe custom commands and prefixes
2424 (while (setq entry (pop custom1))
2425 (setq key (car entry) desc (nth 1 entry)
2427 match (nth 3 entry))
2428 (if (> (length key) 1)
2429 (add-to-list 'prefixes (string-to-char key))
2433 (org-add-props (copy-sequence key)
2436 ((string-match "\\S-" desc) desc)
2437 ((eq type 'agenda) "Agenda for current week or day")
2438 ((eq type 'alltodo) "List of all TODO entries")
2439 ((eq type 'search) "Word search")
2440 ((eq type 'stuck) "List of stuck projects")
2441 ((eq type 'todo) "TODO keyword")
2442 ((eq type 'tags) "Tags query")
2443 ((eq type 'tags-todo) "Tags (TODO)")
2444 ((eq type 'tags-tree) "Tags tree")
2445 ((eq type 'todo-tree) "TODO kwd tree")
2446 ((eq type 'occur-tree) "Occur tree")
2447 ((functionp type) (if (symbolp type)
2449 "Lambda expression"))
2451 (if org-agenda-menu-show-matcher
2456 (setq match (copy-sequence match))
2457 (org-add-props match nil 'face 'org-warning))
2459 (format "set of %d commands" (length match)))
2461 (if (org-string-nw-p match)
2462 (add-text-properties
2463 0 (length line) (list 'help-echo
2464 (concat "Matcher: "match)) line)))
2466 (setq lines (nreverse lines))
2471 (org-add-props (char-to-string x)
2473 (or (cdr (assoc (concat selstring
2475 prefix-descriptions))
2480 ;; Check if we should display in two columns
2481 (if org-agenda-menu-two-column
2483 (setq n (length lines)
2484 n1 (+ (/ n 2) (mod n 2))
2485 right (nthcdr n1 lines)
2486 left (copy-sequence lines))
2487 (setcdr (nthcdr (1- n1) left) nil))
2488 (setq left lines right nil))
2490 (insert "\n" (pop left))
2492 (if (< (current-column) 40)
2493 (move-to-column 40 t)
2495 (insert (pop right))))
2497 ;; Make the window the right size
2498 (goto-char (point-min))
2500 (if (not (pos-visible-in-window-p (point-max)))
2501 (org-fit-window-to-buffer))
2502 (setq second-time t)
2503 (org-fit-window-to-buffer))
2505 ;; Ask for selection
2506 (message "Press key for agenda command%s:"
2507 (if (or restrict-ok org-agenda-overriding-restriction)
2508 (if org-agenda-overriding-restriction
2509 " (restriction lock active)"
2511 (format " (restricted to %s)" restriction)
2514 (setq c (read-char-exclusive))
2517 ((assoc (char-to-string c) custom)
2518 (setq selstring (concat selstring (char-to-string c)))
2519 (throw 'exit (cons selstring restriction)))
2521 (setq selstring (concat selstring (char-to-string c))
2523 rmheader (or rmheader t)
2524 custom (delq nil (mapcar
2526 (if (or (= (length (car x)) 1)
2527 (/= (string-to-char (car x)) c))
2529 (cons (substring (car x) 1) (cdr x))))
2531 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2532 (message "Restriction is only possible in Org-mode buffers")
2535 (org-agenda-remove-restriction-lock 'noupdate)
2536 (setq restriction 'buffer))
2538 (org-agenda-remove-restriction-lock 'noupdate)
2539 (setq restriction (if region-p 'region 'subtree)))
2541 (org-agenda-remove-restriction-lock 'noupdate)
2544 ((eq restriction 'buffer)
2545 (if region-p 'region 'subtree))
2546 ((memq restriction '(subtree region))
2550 (org-agenda-remove-restriction-lock 'noupdate)
2551 (setq restriction nil))
2552 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2553 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2554 ((and (> (length selstring) 0) (eq c ?\d))
2556 (org-agenda-get-restriction-and-command prefix-descriptions))
2558 ((equal c ?q) (error "Abort"))
2559 (t (error "Invalid key %c" c))))))))
2561 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2562 (defvar org-agenda-last-arguments nil
2563 "The arguments of the previous call to `org-agenda'.")
2564 (defun org-agenda-run-series (name series)
2565 (org-let (nth 1 series) '(org-prepare-agenda name))
2566 (let* ((org-agenda-multi t)
2567 (redo (list 'org-agenda-run-series name (list 'quote series)))
2568 (org-agenda-overriding-arguments
2569 (or org-agenda-overriding-arguments
2570 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2571 (get 'org-agenda-redo-command 'last-args))))
2573 (gprops (nth 1 series))
2574 match ;; The byte compiler incorrectly complains about this. Keep it!
2576 (while (setq cmd (pop cmds))
2577 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2580 (org-let2 gprops lprops
2581 '(call-interactively 'org-agenda-list)))
2583 (org-let2 gprops lprops
2584 '(call-interactively 'org-todo-list)))
2586 (org-let2 gprops lprops
2587 '(org-search-view current-prefix-arg match nil)))
2589 (org-let2 gprops lprops
2590 '(call-interactively 'org-agenda-list-stuck-projects)))
2592 (org-let2 gprops lprops
2593 '(org-tags-view current-prefix-arg match)))
2594 ((eq type 'tags-todo)
2595 (org-let2 gprops lprops
2596 '(org-tags-view '(4) match)))
2598 (org-let2 gprops lprops
2599 '(org-todo-list match)))
2601 (org-let2 gprops lprops
2602 '(funcall type match)))
2603 (t (error "Invalid type in command series"))))
2605 (setq org-agenda-redo-command redo)
2606 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2607 (goto-char (point-min)))
2608 (org-fit-agenda-window)
2609 (org-let (nth 1 series) '(org-finalize-agenda)))
2612 (defmacro org-batch-agenda (cmd-key &rest parameters)
2613 "Run an agenda command in batch mode and send the result to STDOUT.
2614 If CMD-KEY is a string of length 1, it is used as a key in
2615 `org-agenda-custom-commands' and triggers this command. If it is a
2616 longer string it is used as a tags/todo match string.
2617 Parameters are alternating variable names and values that will be bound
2618 before running the agenda command."
2619 (org-eval-in-environment (org-make-parameter-alist parameters)
2620 (if (> (length cmd-key) 2)
2621 (org-tags-view nil cmd-key)
2622 (org-agenda nil cmd-key)))
2623 (set-buffer org-agenda-buffer-name)
2624 (princ (buffer-string)))
2625 (def-edebug-spec org-batch-agenda (form &rest sexp))
2627 (defvar org-agenda-info nil)
2630 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2631 "Run an agenda command in batch mode and send the result to STDOUT.
2632 If CMD-KEY is a string of length 1, it is used as a key in
2633 `org-agenda-custom-commands' and triggers this command. If it is a
2634 longer string it is used as a tags/todo match string.
2635 Parameters are alternating variable names and values that will be bound
2636 before running the agenda command.
2638 The output gives a line for each selected agenda item. Each
2639 item is a list of comma-separated values, like this:
2641 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2643 category The category of the item
2644 head The headline, without TODO kwd, TAGS and PRIORITY
2645 type The type of the agenda entry, can be
2646 todo selected in TODO match
2647 tagsmatch selected in tags match
2648 diary imported from diary
2649 deadline a deadline on given date
2650 scheduled scheduled on given date
2651 timestamp entry has timestamp on given date
2652 closed entry was closed on given date
2653 upcoming-deadline warning about deadline
2654 past-scheduled forwarded scheduled item
2655 block entry has date block including g. date
2656 todo The todo keyword, if any
2657 tags All tags including inherited ones, separated by colons
2658 date The relevant date, like 2007-2-14
2659 time The time, like 15:00-16:50
2660 extra Sting with extra planning info
2661 priority-l The priority letter if any was given
2662 priority-n The computed numerical priority
2663 agenda-day The day in the agenda where this is listed"
2664 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2665 (org-make-parameter-alist parameters))
2666 (if (> (length cmd-key) 2)
2667 (org-tags-view nil cmd-key)
2668 (org-agenda nil cmd-key)))
2669 (set-buffer org-agenda-buffer-name)
2670 (let* ((lines (org-split-string (buffer-string) "\n"))
2672 (while (setq line (pop lines))
2674 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2675 (setq org-agenda-info
2676 (org-fix-agenda-info (text-properties-at 0 line)))
2678 (mapconcat 'org-agenda-export-csv-mapper
2679 '(org-category txt type todo tags date time extra
2680 priority-letter priority agenda-day)
2683 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2685 (defun org-fix-agenda-info (props)
2686 "Make sure all properties on an agenda item have a canonical form.
2687 This ensures the export commands can easily use it."
2689 (when (setq tmp (plist-get props 'tags))
2690 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2691 (when (setq tmp (plist-get props 'date))
2692 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2693 (let ((calendar-date-display-form '(year "-" month "-" day)))
2694 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2696 (setq tmp (calendar-date-string tmp)))
2697 (setq props (plist-put props 'date tmp)))
2698 (when (setq tmp (plist-get props 'day))
2699 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2700 (let ((calendar-date-display-form '(year "-" month "-" day)))
2701 (setq tmp (calendar-date-string tmp)))
2702 (setq props (plist-put props 'day tmp))
2703 (setq props (plist-put props 'agenda-day tmp)))
2704 (when (setq tmp (plist-get props 'txt))
2705 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2706 (plist-put props 'priority-letter (match-string 1 tmp))
2707 (setq tmp (replace-match "" t t tmp)))
2708 (when (and (setq re (plist-get props 'org-todo-regexp))
2709 (setq re (concat "\\`\\.*" re " ?"))
2710 (string-match re tmp))
2711 (plist-put props 'todo (match-string 1 tmp))
2712 (setq tmp (replace-match "" t t tmp)))
2713 (plist-put props 'txt tmp)))
2716 (defun org-agenda-export-csv-mapper (prop)
2717 (let ((res (plist-get org-agenda-info prop)))
2722 (t (prin1-to-string res))))
2723 (while (string-match "," res)
2724 (setq res (replace-match ";" t t res)))
2729 (defun org-store-agenda-views (&rest parameters)
2731 (eval (list 'org-batch-store-agenda-views)))
2734 (defmacro org-batch-store-agenda-views (&rest parameters)
2735 "Run all custom agenda commands that have a file argument."
2736 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2738 (dir default-directory)
2739 (pars (org-make-parameter-alist parameters))
2740 cmd thiscmdkey files opts cmd-or-set)
2741 (save-window-excursion
2743 (setq cmd (pop cmds)
2744 thiscmdkey (car cmd)
2745 cmd-or-set (nth 2 cmd)
2746 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2747 files (nth (if (listp cmd-or-set) 4 5) cmd))
2748 (if (stringp files) (setq files (list files)))
2750 (org-eval-in-environment (append org-agenda-exporter-settings
2752 (org-agenda nil thiscmdkey))
2753 (set-buffer org-agenda-buffer-name)
2755 (org-eval-in-environment (append org-agenda-exporter-settings
2757 (org-agenda-write (expand-file-name (pop files) dir) nil t)))
2758 (and (get-buffer org-agenda-buffer-name)
2759 (kill-buffer org-agenda-buffer-name)))))))
2760 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2762 (defun org-agenda-mark-header-line (pos)
2763 "Mark the line at POS as an agenda structure header."
2766 (put-text-property (point-at-bol) (point-at-eol)
2767 'org-agenda-structural-header t)
2768 (when org-agenda-title-append
2769 (put-text-property (point-at-bol) (point-at-eol)
2770 'org-agenda-title-append org-agenda-title-append))))
2772 (defvar org-mobile-creating-agendas)
2773 (defvar org-agenda-write-buffer-name "Agenda View")
2774 (defun org-agenda-write (file &optional open nosettings)
2775 "Write the current buffer (an agenda view) as a file.
2776 Depending on the extension of the file name, plain text (.txt),
2777 HTML (.html or .htm) or Postscript (.ps) is produced.
2778 If the extension is .ics, run icalendar export over all files used
2779 to construct the agenda and limit the export to entries listed in the
2781 With prefix argument OPEN, open the new file immediately.
2782 If NOSETTINGS is given, do not scope the settings of
2783 `org-agenda-exporter-settings' into the export commands. This is used when
2784 the settings have already been scoped and we do not wish to overrule other,
2785 higher priority settings."
2786 (interactive "FWrite agenda to file: \nP")
2787 (if (not (file-writable-p file))
2788 (error "Cannot write agenda to file %s" file))
2789 (org-let (if nosettings nil org-agenda-exporter-settings)
2791 (save-window-excursion
2792 (org-agenda-mark-filtered-text)
2793 (let ((bs (copy-sequence (buffer-string))) beg)
2794 (org-agenda-unmark-filtered-text)
2796 (rename-buffer org-agenda-write-buffer-name t)
2797 (set-buffer-modified-p nil)
2799 (org-agenda-remove-marked-text 'org-filtered)
2800 (while (setq beg (text-property-any (point-min) (point-max)
2803 beg (or (next-single-property-change beg 'org-filtered)
2805 (run-hooks 'org-agenda-before-write-hook)
2807 ((org-bound-and-true-p org-mobile-creating-agendas)
2808 (org-mobile-write-agenda-for-mobile file))
2809 ((string-match "\\.html?\\'" file)
2811 (set-buffer (htmlize-buffer (current-buffer)))
2813 (when (and org-agenda-export-html-style
2814 (string-match "<style>" org-agenda-export-html-style))
2815 ;; replace <style> section with org-agenda-export-html-style
2816 (goto-char (point-min))
2817 (kill-region (- (search-forward "<style") 6)
2818 (search-forward "</style>"))
2819 (insert org-agenda-export-html-style))
2821 (kill-buffer (current-buffer))
2822 (message "HTML written to %s" file))
2823 ((string-match "\\.ps\\'" file)
2825 (ps-print-buffer-with-faces file)
2826 (message "Postscript written to %s" file))
2827 ((string-match "\\.pdf\\'" file)
2829 (ps-print-buffer-with-faces
2830 (concat (file-name-sans-extension file) ".ps"))
2831 (call-process "ps2pdf" nil nil nil
2833 (concat (file-name-sans-extension file) ".ps"))
2834 (expand-file-name file))
2835 (delete-file (concat (file-name-sans-extension file) ".ps"))
2836 (message "PDF written to %s" file))
2837 ((string-match "\\.ics\\'" file)
2838 (require 'org-icalendar)
2839 (let ((org-agenda-marker-table
2840 (org-create-marker-find-array
2841 (org-agenda-collect-markers)))
2842 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2843 (org-combined-agenda-icalendar-file file))
2844 (apply 'org-export-icalendar 'combine
2845 (org-agenda-files nil 'ifmode))))
2847 (let ((bs (buffer-string)))
2852 (kill-buffer (current-buffer))
2853 (message "Plain text written to %s" file))))))))
2854 (set-buffer org-agenda-buffer-name))
2855 (when open (org-open-file file)))
2857 (defvar org-agenda-tag-filter-overlays nil)
2858 (defvar org-agenda-cat-filter-overlays nil)
2860 (defun org-agenda-mark-filtered-text ()
2861 "Mark all text hidden by filtering with a text property."
2862 (let ((inhibit-read-only t))
2865 (when (equal (overlay-buffer o) (current-buffer))
2867 (overlay-start o) (overlay-end o)
2869 (append org-agenda-tag-filter-overlays
2870 org-agenda-cat-filter-overlays))))
2872 (defun org-agenda-unmark-filtered-text ()
2873 "Remove the filtering text property."
2874 (let ((inhibit-read-only t))
2875 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2877 (defun org-agenda-remove-marked-text (property &optional value)
2878 "Delete all text marked with VALUE of PROPERTY.
2879 VALUE defaults to t."
2881 (setq value (or value t))
2882 (while (setq beg (text-property-any (point-min) (point-max)
2885 beg (or (next-single-property-change beg 'org-filtered)
2888 (defun org-agenda-add-entry-text ()
2889 "Add entry text to agenda lines.
2890 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2891 entry text following headings shown in the agenda.
2892 Drawers will be excluded, also the line with scheduling/deadline info."
2893 (when (and (> org-agenda-add-entry-text-maxlines 0)
2894 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2896 (goto-char (point-min))
2898 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2899 (beginning-of-line 2)
2900 (setq txt (org-agenda-get-some-entry-text
2901 m org-agenda-add-entry-text-maxlines " > "))
2903 (if (string-match "\\S-" txt)
2905 (or (eobp) (forward-char 1))))))))
2907 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2909 "Extract entry text from MARKER, at most N-LINES lines.
2910 This will ignore drawers etc, just get the text.
2911 If INDENT is given, prefix every line with this string. If KEEP is
2912 given, it is a list of symbols, defining stuff that should not be
2913 removed from the entry content. Currently only `planning' is allowed here."
2914 (let (txt drawer-re kwd-time-re ind)
2916 (with-current-buffer (marker-buffer marker)
2917 (if (not (eq major-mode 'org-mode))
2924 (setq txt (buffer-substring
2925 (min (1+ (point)) (point-max))
2926 (progn (outline-next-heading) (point)))
2927 drawer-re org-drawer-regexp
2928 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2932 (when org-agenda-add-entry-text-descriptive-links
2933 (goto-char (point-min))
2934 (while (org-activate-bracket-links (point-max))
2935 (add-text-properties (match-beginning 0) (match-end 0)
2937 (goto-char (point-min))
2938 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2939 (set-text-properties (match-beginning 0) (match-end 0)
2941 (goto-char (point-min))
2942 (while (re-search-forward drawer-re nil t)
2945 (progn (re-search-forward
2946 "^[ \t]*:END:.*\n?" nil 'move)
2948 (unless (member 'planning keep)
2949 (goto-char (point-min))
2950 (while (re-search-forward kwd-time-re nil t)
2951 (replace-match "")))
2952 (goto-char (point-min))
2953 (when org-agenda-entry-text-exclude-regexps
2954 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2955 (while (setq re (pop re-list))
2956 (goto-char (point-min))
2957 (while (re-search-forward re nil t)
2958 (replace-match "")))))
2959 (goto-char (point-max))
2960 (skip-chars-backward " \t\n")
2961 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2963 ;; find and remove min common indentation
2964 (goto-char (point-min))
2965 (untabify (point-min) (point-max))
2966 (setq ind (org-get-indentation))
2968 (unless (looking-at "[ \t]*$")
2969 (setq ind (min ind (org-get-indentation))))
2970 (beginning-of-line 2))
2971 (goto-char (point-min))
2973 (unless (looking-at "[ \t]*$")
2974 (move-to-column ind)
2975 (delete-region (point-at-bol) (point)))
2976 (beginning-of-line 2))
2978 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2980 (goto-char (point-min))
2982 (while (and (not (eobp)) (re-search-forward "^" nil t))
2983 (replace-match indent t t)))
2984 (goto-char (point-min))
2985 (while (looking-at "[ \t]*\n") (replace-match ""))
2986 (goto-char (point-max))
2987 (when (> (org-current-line)
2989 (org-goto-line (1+ n-lines))
2991 (setq txt (buffer-substring (point-min) (point)))))))))
2994 (defun org-agenda-collect-markers ()
2995 "Collect the markers pointing to entries in the agenda buffer."
2998 (goto-char (point-min))
3000 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3001 (org-get-at-bol 'org-marker)))
3003 (beginning-of-line 2)))
3004 (nreverse markers)))
3006 (defun org-create-marker-find-array (marker-list)
3007 "Create a alist of files names with all marker positions in that file."
3009 (while (setq m (pop marker-list))
3010 (setq p (marker-position m)
3011 f (buffer-file-name (or (buffer-base-buffer
3013 (marker-buffer m))))
3014 (if (setq a (assoc f tbl))
3015 (push (marker-position m) (cdr a))
3016 (push (list f p) tbl)))
3017 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3020 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3021 (defun org-check-agenda-marker-table ()
3022 "Check of the current entry is on the marker list."
3023 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3025 (and (setq a (assoc file org-agenda-marker-table))
3028 (org-back-to-heading t)
3029 (member (point) (cdr a)))))))
3031 (defun org-check-for-org-mode ()
3032 "Make sure current buffer is in org-mode. Error if not."
3033 (or (eq major-mode 'org-mode)
3034 (error "Cannot execute org-mode agenda command on buffer in %s"
3037 (defun org-fit-agenda-window ()
3038 "Fit the window to the buffer size."
3039 (and (memq org-agenda-window-setup '(reorganize-frame))
3040 (fboundp 'fit-window-to-buffer)
3041 (org-fit-window-to-buffer
3043 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3044 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3046 ;;; Agenda prepare and finalize
3048 (defvar org-agenda-multi nil) ; dynamically scoped
3049 (defvar org-agenda-buffer-name "*Org Agenda*")
3050 (defvar org-pre-agenda-window-conf nil)
3051 (defvar org-agenda-columns-active nil)
3052 (defvar org-agenda-name nil)
3053 (defvar org-agenda-tag-filter nil)
3054 (defvar org-agenda-category-filter nil)
3055 (defvar org-agenda-tag-filter-while-redo nil)
3056 (defvar org-agenda-tag-filter-preset nil
3057 "A preset of the tags filter used for secondary agenda filtering.
3058 This must be a list of strings, each string must be a single tag preceded
3060 This variable should not be set directly, but agenda custom commands can
3061 bind it in the options section. The preset filter is a global property of
3062 the entire agenda view. In a block agenda, it will not work reliably to
3063 define a filter for one of the individual blocks. You need to set it in
3064 the global options and expect it to be applied to the entire view.")
3066 (defvar org-agenda-category-filter-preset nil
3067 "A preset of the category filter used for secondary agenda filtering.
3068 This must be a list of strings, each string must be a single category
3069 preceded by \"+\" or \"-\".
3070 This variable should not be set directly, but agenda custom commands can
3071 bind it in the options section. The preset filter is a global property of
3072 the entire agenda view. In a block agenda, it will not work reliably to
3073 define a filter for one of the individual blocks. You need to set it in
3074 the global options and expect it to be applied to the entire view.")
3076 (defun org-prepare-agenda (&optional name)
3077 (setq org-todo-keywords-for-agenda nil)
3078 (setq org-drawers-for-agenda nil)
3079 (unless org-agenda-persistent-filter
3080 (setq org-agenda-tag-filter nil
3081 org-agenda-category-filter nil))
3082 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3083 (put 'org-agenda-category-filter :preset-filter org-agenda-category-filter-preset)
3084 (if org-agenda-multi
3086 (setq buffer-read-only nil)
3087 (goto-char (point-max))
3088 (unless (or (bobp) org-agenda-compact-blocks
3089 (not org-agenda-block-separator))
3091 (if (stringp org-agenda-block-separator)
3092 org-agenda-block-separator
3093 (make-string (window-width) org-agenda-block-separator))
3095 (narrow-to-region (point) (point-max)))
3096 (setq org-done-keywords-for-agenda nil)
3097 (org-agenda-reset-markers)
3098 (setq org-agenda-contributing-files nil)
3099 (setq org-agenda-columns-active nil)
3100 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3101 (setq org-todo-keywords-for-agenda
3102 (org-uniquify org-todo-keywords-for-agenda))
3103 (setq org-done-keywords-for-agenda
3104 (org-uniquify org-done-keywords-for-agenda))
3105 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3106 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
3107 (awin (get-buffer-window abuf)))
3109 ((equal (current-buffer) abuf) nil)
3110 (awin (select-window awin))
3111 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3112 ((equal org-agenda-window-setup 'current-window)
3113 (org-pop-to-buffer-same-window abuf))
3114 ((equal org-agenda-window-setup 'other-window)
3115 (org-switch-to-buffer-other-window abuf))
3116 ((equal org-agenda-window-setup 'other-frame)
3117 (switch-to-buffer-other-frame abuf))
3118 ((equal org-agenda-window-setup 'reorganize-frame)
3119 (delete-other-windows)
3120 (org-switch-to-buffer-other-window abuf)))
3121 ;; additional test in case agenda is invoked from within agenda
3122 ;; buffer via elisp link
3123 (unless (equal (current-buffer) abuf)
3124 (org-pop-to-buffer-same-window abuf)))
3125 (setq buffer-read-only nil)
3126 (let ((inhibit-read-only t)) (erase-buffer))
3128 (and name (not org-agenda-name)
3129 (org-set-local 'org-agenda-name name)))
3130 (setq buffer-read-only nil))
3132 (defun org-finalize-agenda ()
3133 "Finishing touch for the agenda buffer, called just before displaying it."
3134 (unless org-agenda-multi
3136 (let ((inhibit-read-only t))
3137 (goto-char (point-min))
3138 (while (org-activate-bracket-links (point-max))
3139 (add-text-properties (match-beginning 0) (match-end 0)
3141 (org-agenda-align-tags)
3142 (unless org-agenda-with-colors
3143 (remove-text-properties (point-min) (point-max) '(face nil))))
3144 (if (and (boundp 'org-agenda-overriding-columns-format)
3145 org-agenda-overriding-columns-format)
3146 (org-set-local 'org-agenda-overriding-columns-format
3147 org-agenda-overriding-columns-format))
3148 (if (and (boundp 'org-agenda-view-columns-initially)
3149 org-agenda-view-columns-initially)
3150 (org-agenda-columns))
3151 (when org-agenda-fontify-priorities
3152 (org-agenda-fontify-priorities))
3153 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3154 (org-agenda-dim-blocked-tasks))
3155 (org-agenda-mark-clocking-task)
3156 (when org-agenda-entry-text-mode
3157 (org-agenda-entry-text-hide)
3158 (org-agenda-entry-text-show))
3159 (if (functionp 'org-habit-insert-consistency-graphs)
3160 (org-habit-insert-consistency-graphs))
3161 (run-hooks 'org-finalize-agenda-hook)
3162 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3163 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3164 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3165 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3166 (org-agenda-filter-apply org-agenda-category-filter 'category))
3169 (defun org-agenda-mark-clocking-task ()
3170 "Mark the current clock entry in the agenda if it is present."
3172 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3173 (delete-overlay o)))
3174 (overlays-in (point-min) (point-max)))
3175 (when (marker-buffer org-clock-hd-marker)
3177 (goto-char (point-min))
3179 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3181 (when (equal (org-get-at-bol 'org-hd-marker)
3182 org-clock-hd-marker)
3183 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3184 (overlay-put ov 'type 'org-agenda-clocking)
3185 (overlay-put ov 'face 'org-agenda-clocking)
3186 (overlay-put ov 'help-echo
3187 "The clock is running in this item")))))))
3189 (defun org-agenda-fontify-priorities ()
3190 "Make highest priority lines bold, and lowest italic."
3192 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3193 (delete-overlay o)))
3194 (overlays-in (point-min) (point-max)))
3196 (let ((inhibit-read-only t)
3198 (goto-char (point-min))
3199 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3200 (setq h (or (get-char-property (point) 'org-highest-priority)
3201 org-highest-priority)
3202 l (or (get-char-property (point) 'org-lowest-priority)
3203 org-lowest-priority)
3204 p (string-to-char (match-string 1))
3205 b (match-beginning 0)
3206 e (if (eq org-agenda-fontify-priorities 'cookies)
3209 ov (make-overlay b e))
3212 (cond ((org-face-from-face-or-color
3214 (cdr (assoc p org-priority-faces))))
3215 ((and (listp org-agenda-fontify-priorities)
3216 (org-face-from-face-or-color
3218 (cdr (assoc p org-agenda-fontify-priorities)))))
3219 ((equal p l) 'italic)
3220 ((equal p h) 'bold)))
3221 (overlay-put ov 'org-type 'org-priority)))))
3223 (defun org-agenda-dim-blocked-tasks ()
3224 "Dim currently blocked TODO's in the agenda display."
3225 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3226 (delete-overlay o)))
3227 (overlays-in (point-min) (point-max)))
3229 (let ((inhibit-read-only t)
3230 (org-depend-tag-blocked nil)
3231 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3232 org-blocked-by-checkboxes
3233 invis1 b e p ov h l)
3234 (goto-char (point-min))
3235 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3236 (and pos (goto-char (1+ pos))))
3237 (setq org-blocked-by-checkboxes nil invis1 invis)
3238 (let ((marker (org-get-at-bol 'org-hd-marker)))
3240 (with-current-buffer (marker-buffer marker)
3241 (save-excursion (goto-char marker)
3242 (org-entry-blocked-p))))
3243 (if org-blocked-by-checkboxes (setq invis1 nil))
3245 (max (point-min) (1- (point-at-bol)))
3248 ov (make-overlay b e))
3250 (overlay-put ov 'invisible t)
3251 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3252 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3254 (defvar org-agenda-skip-function nil
3255 "Function to be called at each match during agenda construction.
3256 If this function returns nil, the current match should not be skipped.
3257 Otherwise, the function must return a position from where the search
3258 should be continued.
3259 This may also be a Lisp form, it will be evaluated.
3260 Never set this variable using `setq' or so, because then it will apply
3261 to all future agenda commands. If you do want a global skipping condition,
3262 use the option `org-agenda-skip-function-global' instead.
3263 The correct usage for `org-agenda-skip-function' is to bind it with
3264 `let' to scope it dynamically into the agenda-constructing command.
3265 A good way to set it is through options in `org-agenda-custom-commands'.")
3267 (defun org-agenda-skip ()
3268 "Throw to `:skip' in places that should be skipped.
3269 Also moves point to the end of the skipped region, so that search can
3270 continue from there."
3271 (let ((p (point-at-bol)) to)
3272 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3273 (get-text-property p :org-archived)
3274 (org-end-of-subtree t)
3276 (and org-agenda-skip-comment-trees
3277 (get-text-property p :org-comment)
3278 (org-end-of-subtree t)
3280 (if (equal (char-after p) ?#) (throw :skip t))
3281 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3282 (org-agenda-skip-eval org-agenda-skip-function)))
3286 (defun org-agenda-skip-eval (form)
3287 "If FORM is a function or a list, call (or eval) is and return result.
3288 `save-excursion' and `save-match-data' are wrapped around the call, so point
3289 and match data are returned to the previous state no matter what these
3293 (or (setq fp (functionp form))
3301 (defvar org-agenda-markers nil
3302 "List of all currently active markers created by `org-agenda'.")
3303 (defvar org-agenda-last-marker-time (org-float-time)
3304 "Creation time of the last agenda marker.")
3306 (defun org-agenda-new-marker (&optional pos)
3307 "Return a new agenda marker.
3308 Org-mode keeps a list of these markers and resets them when they are
3310 (let ((m (copy-marker (or pos (point)))))
3311 (setq org-agenda-last-marker-time (org-float-time))
3312 (push m org-agenda-markers)
3315 (defun org-agenda-reset-markers ()
3316 "Reset markers created by `org-agenda'."
3317 (while org-agenda-markers
3318 (move-marker (pop org-agenda-markers) nil)))
3320 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3321 "Save relative positions of markers in region."
3322 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3323 org-agenda-markers))
3327 (defun org-agenda-entry-text-show-here ()
3328 "Add some text from the entry as context to the current line."
3330 (setq m (org-get-at-bol 'org-hd-marker))
3331 (unless (marker-buffer m)
3332 (error "No marker points to an entry here"))
3333 (setq txt (concat "\n" (org-no-properties
3334 (org-agenda-get-some-entry-text
3335 m org-agenda-entry-text-maxlines " > "))))
3336 (when (string-match "\\S-" txt)
3337 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3338 (overlay-put o 'evaporate t)
3339 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3340 (overlay-put o 'after-string txt))))
3342 (defun org-agenda-entry-text-show ()
3343 "Add entry context for all agenda lines."
3346 (goto-char (point-max))
3347 (beginning-of-line 1)
3349 (when (org-get-at-bol 'org-hd-marker)
3350 (org-agenda-entry-text-show-here))
3351 (beginning-of-line 0))))
3353 (defun org-agenda-entry-text-hide ()
3354 "Remove any shown entry context."
3357 (if (eq (overlay-get o 'org-overlay-type)
3358 'agenda-entry-content)
3359 (progn (delete-overlay o) t)))
3360 (overlays-in (point-min) (point-max)))))
3362 (defun org-agenda-get-day-face (date)
3363 "Return the face DATE should be displayed with."
3364 (or (and (functionp org-agenda-day-face-function)
3365 (funcall org-agenda-day-face-function date))
3366 (cond ((org-agenda-todayp date)
3367 'org-agenda-date-today)
3368 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3369 'org-agenda-date-weekend)
3370 (t 'org-agenda-date))))
3374 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3376 (defun org-timeline (&optional dotodo)
3377 "Show a time-sorted view of the entries in the current org file.
3378 Only entries with a time stamp of today or later will be listed. With
3379 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3380 under the current date.
3381 If the buffer contains an active region, only check the region for
3384 (org-compile-prefix-format 'timeline)
3385 (org-set-sorting-strategy 'timeline)
3387 (doclosed org-agenda-show-log)
3388 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3390 (date (calendar-current-date))
3391 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3392 (end (if (org-region-active-p) (region-end) (point-max)))
3393 (day-numbers (org-get-all-dates beg end 'no-ranges
3394 t doclosed ; always include today
3395 org-timeline-show-empty-dates))
3396 (org-deadline-warning-days 0)
3397 (org-agenda-only-exact-dates t)
3402 (setq org-agenda-redo-command
3404 (list 'org-switch-to-buffer-other-window (current-buffer))
3405 (list 'org-timeline (list 'quote dotodo))))
3407 ;; Remove past dates from the list of dates.
3408 (setq day-numbers (delq nil (mapcar (lambda(x)
3409 (if (>= x today) x nil))
3411 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3412 (if doclosed (push :closed args))
3413 (push :timestamp args)
3414 (push :deadline args)
3415 (push :scheduled args)
3417 (if dotodo (push :todo args))
3418 (insert "Timeline of file " entry "\n")
3419 (add-text-properties (point-min) (point)
3420 (list 'face 'org-agenda-structure))
3421 (org-agenda-mark-header-line (point-min))
3422 (while (setq d (pop day-numbers))
3423 (if (and (listp d) (eq (car d) :omitted))
3426 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3427 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3428 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3429 (if (and (>= d today)
3434 (insert (make-string 79 ?-) "\n")))
3435 (setq date (calendar-gregorian-from-absolute d))
3437 (setq rtn (and (not emptyp)
3438 (apply 'org-agenda-get-day-entries entry
3440 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3443 (if (stringp org-agenda-format-date)
3444 (format-time-string org-agenda-format-date
3445 (org-time-from-absolute date))
3446 (funcall org-agenda-format-date date))
3448 (put-text-property s (1- (point)) 'face
3449 (org-agenda-get-day-face date))
3450 (put-text-property s (1- (point)) 'org-date-line t)
3451 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3453 (put-text-property s (1- (point)) 'org-today t))
3454 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3455 (put-text-property s (1- (point)) 'day d)))))
3456 (goto-char (point-min))
3457 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3459 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3460 (org-finalize-agenda)
3461 (setq buffer-read-only t)))
3463 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3464 "Return a list of all relevant day numbers from BEG to END buffer positions.
3465 If NO-RANGES is non-nil, include only the start and end dates of a range,
3466 not every single day in the range. If FORCE-TODAY is non-nil, make
3467 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3468 inactive time stamps (those in square brackets) are included.
3469 When EMPTY is non-nil, also include days without any entries."
3471 (if pre-re pre-re "")
3472 (if inactive org-ts-regexp-both org-ts-regexp)))
3473 dates dates1 date day day1 day2 ts1 ts2 pos)
3475 (setq dates (list (org-today))))
3478 (while (re-search-forward re end t)
3479 (setq day (time-to-days (org-time-string-to-time
3480 (substring (match-string 1) 0 10)
3481 (current-buffer) (match-beginning 0))))
3482 (or (memq day dates) (push day dates)))
3485 (while (re-search-forward org-tr-regexp end t)
3486 (setq pos (match-beginning 0))
3487 (setq ts1 (substring (match-string 1) 0 10)
3488 ts2 (substring (match-string 2) 0 10)
3489 day1 (time-to-days (org-time-string-to-time
3490 ts1 (current-buffer) pos))
3491 day2 (time-to-days (org-time-string-to-time
3492 ts2 (current-buffer) pos)))
3493 (while (< (setq day1 (1+ day1)) day2)
3494 (or (memq day1 dates) (push day1 dates)))))
3495 (setq dates (sort dates '<))
3497 (while (setq day (pop dates))
3498 (setq day2 (car dates))
3500 (when (and day2 empty)
3501 (if (or (eq empty t)
3502 (and (numberp empty) (<= (- day2 day) empty)))
3503 (while (< (setq day (1+ day)) day2)
3504 (push (list day) dates1))
3505 (push (cons :omitted (- day2 day)) dates1))))
3506 (setq dates (nreverse dates1)))
3509 ;;; Agenda Daily/Weekly
3511 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3512 "Start day for the agenda view.
3513 Custom commands can set this variable in the options section.")
3514 (defvar org-starting-day nil) ; local variable in the agenda buffer
3515 (defvar org-agenda-current-span nil
3516 "The current span used in the agenda view.") ; local variable in the agenda buffer
3517 (defvar org-arg-loc nil) ; local variable
3519 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3520 "List of types searched for when creating the daily/weekly agenda.
3521 This variable is a list of symbols that controls the types of
3522 items that appear in the daily/weekly agenda. Allowed symbols in this
3525 :timestamp List items containing a date stamp or date range matching
3526 the selected date. This includes sexp entries in
3529 :sexp List entries resulting from plain diary-like sexps.
3531 :deadline List deadline due on that date. When the date is today,
3532 also list any deadlines past due, or due within
3533 `org-deadline-warning-days'. `:deadline' must appear before
3534 `:scheduled' if the setting of
3535 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3538 :scheduled List all items which are scheduled for the given date.
3539 The diary for *today* also contains items which were
3540 scheduled earlier and are not yet marked DONE.
3542 By default, all four types are turned on.
3544 Never set this variable globally using `setq', because then it
3545 will apply to all future agenda commands. Instead, bind it with
3546 `let' to scope it dynamically into the agenda-constructing
3547 command. A good way to set it is through options in
3548 `org-agenda-custom-commands'. For a more flexible (though
3549 somewhat less efficient) way of determining what is included in
3550 the daily/weekly agenda, see `org-agenda-skip-function'.")
3553 (defun org-agenda-list (&optional arg start-day span)
3554 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3555 The view will be for the current day or week, but from the overview buffer
3556 you will be able to go to other days/weeks.
3558 With a numeric prefix argument in an interactive call, the agenda will
3559 span ARG days. Lisp programs should instead specify SPAN to change
3560 the number of days. SPAN defaults to `org-agenda-span'.
3562 START-DAY defaults to TODAY, or to the most recent match for the weekday
3563 given in `org-agenda-start-on-weekday'."
3565 (if (and (integerp arg) (> arg 0))
3566 (setq span arg arg nil))
3567 (setq start-day (or start-day org-agenda-start-day))
3568 (if org-agenda-overriding-arguments
3569 (setq arg (car org-agenda-overriding-arguments)
3570 start-day (nth 1 org-agenda-overriding-arguments)
3571 span (nth 2 org-agenda-overriding-arguments)))
3572 (if (stringp start-day)
3573 ;; Convert to an absolute day number
3574 (setq start-day (time-to-days (org-read-date nil t start-day))))
3575 (setq org-agenda-last-arguments (list arg start-day span))
3576 (org-compile-prefix-format 'agenda)
3577 (org-set-sorting-strategy 'agenda)
3578 (let* ((span (org-agenda-ndays-to-span
3579 (or span org-agenda-ndays org-agenda-span)))
3581 (sd (or start-day today))
3582 (ndays (org-agenda-span-to-ndays span sd))
3583 (org-agenda-start-on-weekday
3585 org-agenda-start-on-weekday))
3586 (thefiles (org-agenda-files nil 'ifmode))
3588 (start (if (or (null org-agenda-start-on-weekday)
3591 (let* ((nt (calendar-day-of-week
3592 (calendar-gregorian-from-absolute sd)))
3593 (n1 org-agenda-start-on-weekday)
3595 (- sd (+ (if (< d 0) 7 0) d)))))
3596 (day-numbers (list start))
3598 (inhibit-redisplay (not debug-on-error))
3599 s e rtn rtnall file date d start-pos end-pos todayp
3600 clocktable-start clocktable-end filter)
3601 (setq org-agenda-redo-command
3602 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3603 (dotimes (n (1- ndays))
3604 (push (1+ (car day-numbers)) day-numbers))
3605 (setq day-numbers (nreverse day-numbers))
3606 (setq clocktable-start (car day-numbers)
3607 clocktable-end (1+ (or (org-last day-numbers) 0)))
3608 (org-prepare-agenda "Day/Week")
3609 (org-set-local 'org-starting-day (car day-numbers))
3610 (org-set-local 'org-arg-loc arg)
3611 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3612 (unless org-agenda-compact-blocks
3613 (let* ((d1 (car day-numbers))
3614 (d2 (org-last day-numbers))
3615 (w1 (org-days-to-iso-week d1))
3616 (w2 (org-days-to-iso-week d2)))
3618 (if org-agenda-overriding-header
3619 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3620 nil 'face 'org-agenda-structure) "\n")
3621 (insert (org-agenda-span-name span)
3623 (if (< (- d2 d1) 350)
3625 (format " (W%02d)" w1)
3626 (format " (W%02d-W%02d)" w1 w2))
3629 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3631 (org-agenda-mark-header-line s))
3632 (while (setq d (pop day-numbers))
3633 (setq date (calendar-gregorian-from-absolute d)
3635 (if (or (setq todayp (= d today))
3636 (and (not start-pos) (= d sd)))
3637 (setq start-pos (point))
3638 (if (and start-pos (not end-pos))
3639 (setq end-pos (point))))
3640 (setq files thefiles
3642 (while (setq file (pop files))
3644 (org-check-agenda-file file)
3645 (let ((org-agenda-entry-types org-agenda-entry-types))
3646 (unless org-agenda-include-deadlines
3647 (setq org-agenda-entry-types
3648 (delq :deadline org-agenda-entry-types)))
3650 ((memq org-agenda-show-log '(only clockcheck))
3651 (setq rtn (org-agenda-get-day-entries
3652 file date :closed)))
3653 (org-agenda-show-log
3654 (setq rtn (apply 'org-agenda-get-day-entries
3656 (append '(:closed) org-agenda-entry-types))))
3658 (setq rtn (apply 'org-agenda-get-day-entries
3660 org-agenda-entry-types)))))
3661 (setq rtnall (append rtnall rtn)))) ;; all entries
3662 (if org-agenda-include-diary
3663 (let ((org-agenda-search-headline-for-time t))
3664 (require 'diary-lib)
3665 (setq rtn (org-get-entries-from-diary date))
3666 (setq rtnall (append rtnall rtn))))
3667 (if (or rtnall org-agenda-show-all-dates)
3669 (setq day-cnt (1+ day-cnt))
3671 (if (stringp org-agenda-format-date)
3672 (format-time-string org-agenda-format-date
3673 (org-time-from-absolute date))
3674 (funcall org-agenda-format-date date))
3676 (put-text-property s (1- (point)) 'face
3677 (org-agenda-get-day-face date))
3678 (put-text-property s (1- (point)) 'org-date-line t)
3679 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3680 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3682 (put-text-property s (1- (point)) 'org-today t))
3683 (if rtnall (insert ;; all entries
3684 (org-finalize-agenda-entries
3685 (org-agenda-add-time-grid-maybe
3686 rtnall ndays todayp))
3688 (put-text-property s (1- (point)) 'day d)
3689 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3690 (when (and org-agenda-clockreport-mode clocktable-start)
3691 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3692 ;; the above line is to ensure the restricted range!
3693 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3695 (setq p (org-plist-delete p :block))
3696 (setq p (plist-put p :tstart clocktable-start))
3697 (setq p (plist-put p :tend clocktable-end))
3698 (setq p (plist-put p :scope 'agenda))
3699 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3700 (setq filter (or org-agenda-tag-filter-while-redo
3701 (get 'org-agenda-tag-filter :preset-filter))))
3702 (setq p (plist-put p :tags (mapconcat (lambda (x)
3703 (if (string-match "[<>=]" x)
3707 (setq tbl (apply 'org-get-clocktable p))
3709 (goto-char (point-min))
3710 (or org-agenda-multi (org-fit-agenda-window))
3711 (unless (and (pos-visible-in-window-p (point-min))
3712 (pos-visible-in-window-p (point-max)))
3713 (goto-char (1- (point-max)))
3715 (if (not (pos-visible-in-window-p (or start-pos 1)))
3717 (goto-char (or start-pos 1))
3719 (goto-char (or start-pos 1))
3720 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3721 (if (eq org-agenda-show-log 'clockcheck)
3722 (org-agenda-show-clocking-issues))
3723 (org-finalize-agenda)
3724 (setq buffer-read-only t)
3727 (defun org-agenda-ndays-to-span (n)
3728 "Return a span symbol for a span of N days, or N if none matches."
3729 (cond ((symbolp n) n)
3734 (defun org-agenda-span-to-ndays (span start-day)
3735 "Return ndays from SPAN starting at START-DAY."
3736 (cond ((numberp span) span)
3740 (let ((date (calendar-gregorian-from-absolute start-day)))
3741 (calendar-last-day-of-month (car date) (caddr date))))
3743 (let ((date (calendar-gregorian-from-absolute start-day)))
3744 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3746 (defun org-agenda-span-name (span)
3747 "Return a SPAN name."
3751 (capitalize (symbol-name span))
3752 (format "%d days" span))))
3754 ;;; Agenda word search
3756 (defvar org-agenda-search-history nil)
3757 (defvar org-todo-only nil)
3759 (defvar org-search-syntax-table nil
3760 "Special syntax table for org-mode search.
3761 In this table, we have single quotes not as word constituents, to
3762 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3764 (defun org-search-syntax-table ()
3765 (unless org-search-syntax-table
3766 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3767 (modify-syntax-entry ?' "." org-search-syntax-table)
3768 (modify-syntax-entry ?` "." org-search-syntax-table))
3769 org-search-syntax-table)
3771 (defvar org-agenda-last-search-view-search-was-boolean nil)
3774 (defun org-search-view (&optional todo-only string edit-at)
3775 "Show all entries that contain a phrase or words or regular expressions.
3777 With optional prefix argument TODO-ONLY, only consider entries that are
3778 TODO entries. The argument STRING can be used to pass a default search
3779 string into this function. If EDIT-AT is non-nil, it means that the
3780 user should get a chance to edit this string, with cursor at position
3783 The search string can be viewed either as a phrase that should be found as
3784 is, or it can be broken into a number of snippets, each of which must match
3785 in a Boolean way to select an entry. The default depends on the variable
3786 `org-agenda-search-view-always-boolean'.
3787 Even if this is turned off (the default) you can always switch to
3788 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3790 The default is a direct search of the whole phrase, where each space in
3791 the search string can expand to an arbitrary amount of whitespace,
3794 If using a Boolean search, the search string is split on whitespace and
3795 each snippet is searched separately, with logical AND to select an entry.
3796 Words prefixed with a minus must *not* occur in the entry. Words without
3797 a prefix or prefixed with a plus must occur in the entry. Matching is
3798 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3799 match whole words, not parts of a word) if
3800 `org-agenda-search-view-force-full-words' is set (default is nil).
3802 Boolean search snippets enclosed by curly braces are interpreted as
3803 regular expressions that must or (when preceded with \"-\") must not
3804 match in the entry. Snippets enclosed into double quotes will be taken
3805 as a whole, to include whitespace.
3807 - If the search string starts with an asterisk, search only in headlines.
3808 - If (possibly after the leading star) the search string starts with an
3809 exclamation mark, this also means to look at TODO entries only, an effect
3810 that can also be achieved with a prefix argument.
3811 - If (possibly after star and exclamation mark) the search string starts
3812 with a colon, this will mean that the (non-regexp) snippets of the
3813 Boolean search must match as full words.
3815 This command searches the agenda files, and in addition the files listed
3816 in `org-agenda-text-search-extra-files'."
3818 (org-compile-prefix-format 'search)
3819 (org-set-sorting-strategy 'search)
3820 (org-prepare-agenda "SEARCH")
3821 (let* ((props (list 'face nil
3822 'done-face 'org-agenda-done
3823 'org-not-done-regexp org-not-done-regexp
3824 'org-todo-regexp org-todo-regexp
3825 'org-complex-heading-regexp org-complex-heading-regexp
3826 'mouse-face 'highlight
3827 'help-echo (format "mouse-2 or RET jump to location")))
3828 (full-words org-agenda-search-view-force-full-words)
3829 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3830 regexp rtn rtnall files file pos
3831 marker category org-category-pos tags c neg re boolean
3832 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3833 (unless (and (not edit-at)
3835 (string-match "\\S-" string))
3836 (setq string (read-string
3837 (if org-agenda-search-view-always-boolean
3838 "[+-]Word/{Regexp} ...: "
3839 "Phrase, or [+-]Word/{Regexp} ...: ")
3841 ((integerp edit-at) (cons string edit-at))
3843 'org-agenda-search-history)))
3844 (org-set-local 'org-todo-only todo-only)
3845 (setq org-agenda-redo-command
3846 (list 'org-search-view (if todo-only t nil) string
3847 '(if current-prefix-arg 1 nil)))
3848 (setq org-agenda-query-string string)
3850 (if (equal (string-to-char string) ?*)
3852 words (substring string 1))
3853 (setq words string))
3854 (when (equal (string-to-char words) ?!)
3856 words (substring words 1)))
3857 (when (equal (string-to-char words) ?:)
3859 words (substring words 1)))
3860 (if (or org-agenda-search-view-always-boolean
3861 (member (string-to-char words) '(?- ?+ ?\{)))
3863 (setq words (org-split-string words))
3865 (while (setq w (pop words))
3866 (while (and (string-match "\\\\\\'" w) words)
3867 (setq w (concat (substring w 0 -1) " " (pop words))))
3869 (setq words (nreverse www) www nil)
3870 (while (setq w (pop words))
3871 (when (and (string-match "\\`[-+]?{" w)
3872 (not (string-match "}\\'" w)))
3873 (while (and words (not (string-match "}\\'" (car words))))
3874 (setq w (concat w " " (pop words))))
3875 (setq w (concat w " " (pop words))))
3877 (setq words (nreverse www)))
3878 (setq org-agenda-last-search-view-search-was-boolean boolean)
3881 (while (setq w (pop words))
3882 (if (or (equal (substring w 0 1) "\"")
3883 (and (> (length w) 1)
3884 (member (substring w 0 1) '("+" "-"))
3885 (equal (substring w 1 2) "\"")))
3886 (while (and words (not (equal (substring w -1) "\"")))
3887 (setq w (concat w " " (pop words)))))
3888 (and (string-match "\\`\\([-+]?\\)\"" w)
3889 (setq w (replace-match "\\1" nil nil w)))
3890 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3892 (setq words (nreverse wds))))
3895 (setq c (string-to-char w))
3897 (setq neg t w (substring w 1))
3899 (setq neg nil w (substring w 1))
3901 (if (string-match "\\`{.*}\\'" w)
3902 (setq re (substring w 1 -1))
3904 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3905 (setq re (regexp-quote (downcase w)))))
3906 (if neg (push re regexps-) (push re regexps+)))
3908 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3910 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3912 (setq regexp org-outline-regexp-bol)
3913 (setq regexp (pop regexps+))
3914 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
3916 (setq files (org-agenda-files nil 'ifmode))
3917 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3918 (pop org-agenda-text-search-extra-files)
3919 (setq files (org-add-archive-files files)))
3920 (setq files (append files org-agenda-text-search-extra-files)
3922 (while (setq file (pop files))
3925 (org-check-agenda-file file)
3926 (setq buffer (if (file-exists-p file)
3927 (org-get-agenda-file-buffer file)
3928 (error "No such file %s" file)))
3930 ;; If file does not exist, make sure an error message is sent
3931 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3933 (with-current-buffer buffer
3934 (with-syntax-table (org-search-syntax-table)
3935 (unless (eq major-mode 'org-mode)
3936 (error "Agenda file %s is not in `org-mode'" file))
3937 (let ((case-fold-search t))
3940 (if org-agenda-restrict
3941 (narrow-to-region org-agenda-restrict-begin
3942 org-agenda-restrict-end)
3944 (goto-char (point-min))
3945 (unless (or (org-at-heading-p)
3946 (outline-next-heading))
3947 (throw 'nextfile t))
3948 (goto-char (max (point-min) (1- (point))))
3949 (while (re-search-forward regexp nil t)
3950 (org-back-to-heading t)
3951 (skip-chars-forward "* ")
3952 (setq beg (point-at-bol)
3954 end (progn (outline-next-heading) (point)))
3958 (setq str (buffer-substring-no-properties
3960 (if hdl-only (point-at-eol) end)))
3961 (mapc (lambda (wr) (when (string-match wr str)
3962 (goto-char (1- end))
3965 (mapc (lambda (wr) (unless (string-match wr str)
3966 (goto-char (1- end))
3969 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3973 (setq marker (org-agenda-new-marker (point))
3974 category (org-get-category)
3975 org-category-pos (get-text-property (point) 'org-category-position)
3976 tags (org-get-tags-at (point))
3977 txt (org-agenda-format-item
3979 (buffer-substring-no-properties
3980 beg1 (point-at-eol))
3982 (org-add-props txt props
3983 'org-marker marker 'org-hd-marker marker
3984 'org-todo-regexp org-todo-regexp
3985 'org-complex-heading-regexp org-complex-heading-regexp
3986 'priority 1000 'org-category category
3987 'org-category-position org-category-pos
3990 (goto-char (1- end))))))))))
3991 (setq rtn (nreverse ee))
3992 (setq rtnall (append rtnall rtn)))
3993 (if org-agenda-overriding-header
3994 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3995 nil 'face 'org-agenda-structure) "\n")
3996 (insert "Search words: ")
3997 (add-text-properties (point-min) (1- (point))
3998 (list 'face 'org-agenda-structure))
4000 (insert string "\n")
4001 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4003 (unless org-agenda-multi
4004 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4005 (add-text-properties pos (1- (point))
4006 (list 'face 'org-agenda-structure))))
4007 (org-agenda-mark-header-line (point-min))
4009 (insert (org-finalize-agenda-entries rtnall) "\n"))
4010 (goto-char (point-min))
4011 (or org-agenda-multi (org-fit-agenda-window))
4012 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4013 (org-finalize-agenda)
4014 (setq buffer-read-only t)))
4016 ;;; Agenda TODO list
4018 (defvar org-select-this-todo-keyword nil)
4019 (defvar org-last-arg nil)
4022 (defun org-todo-list (arg)
4023 "Show all (not done) TODO entries from all agenda file in a single list.
4024 The prefix arg can be used to select a specific TODO keyword and limit
4025 the list to these. When using \\[universal-argument], you will be prompted
4026 for a keyword. A numeric prefix directly selects the Nth keyword in
4027 `org-todo-keywords-1'."
4029 (org-compile-prefix-format 'todo)
4030 (org-set-sorting-strategy 'todo)
4031 (org-prepare-agenda "TODO")
4032 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4033 (let* ((today (org-today))
4034 (date (calendar-gregorian-from-absolute today))
4035 (kwds org-todo-keywords-for-agenda)
4036 (completion-ignore-case t)
4037 (org-select-this-todo-keyword
4038 (if (stringp arg) arg
4039 (and arg (integerp arg) (> arg 0)
4040 (nth (1- arg) kwds))))
4041 rtn rtnall files file pos)
4042 (when (equal arg '(4))
4043 (setq org-select-this-todo-keyword
4044 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4045 (mapcar 'list kwds) nil nil)))
4046 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4047 (org-set-local 'org-last-arg arg)
4048 (setq org-agenda-redo-command
4049 '(org-todo-list (or current-prefix-arg org-last-arg)))
4050 (setq files (org-agenda-files nil 'ifmode)
4052 (while (setq file (pop files))
4054 (org-check-agenda-file file)
4055 (setq rtn (org-agenda-get-day-entries file date :todo))
4056 (setq rtnall (append rtnall rtn))))
4057 (if org-agenda-overriding-header
4058 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4059 nil 'face 'org-agenda-structure) "\n")
4060 (insert "Global list of TODO items of type: ")
4061 (add-text-properties (point-min) (1- (point))
4062 (list 'face 'org-agenda-structure
4065 (or org-select-this-todo-keyword "ALL"))))
4066 (org-agenda-mark-header-line (point-min))
4068 (insert (or org-select-this-todo-keyword "ALL") "\n")
4069 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4071 (unless org-agenda-multi
4072 (insert "Available with `N r': (0)ALL")
4075 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4076 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4081 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4082 (org-agenda-mark-header-line (point-min))
4084 (insert (org-finalize-agenda-entries rtnall) "\n"))
4085 (goto-char (point-min))
4086 (or org-agenda-multi (org-fit-agenda-window))
4087 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4088 (org-finalize-agenda)
4089 (setq buffer-read-only t)))
4091 ;;; Agenda tags match
4094 (defun org-tags-view (&optional todo-only match)
4095 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4096 The prefix arg TODO-ONLY limits the search to TODO entries."
4098 (org-compile-prefix-format 'tags)
4099 (org-set-sorting-strategy 'tags)
4100 (let* ((org-tags-match-list-sublevels
4101 org-tags-match-list-sublevels)
4102 (completion-ignore-case t)
4103 rtn rtnall files file pos matcher
4105 (when (and (stringp match) (not (string-match "\\S-" match)))
4107 (setq matcher (org-make-tags-matcher match)
4108 match (car matcher) matcher (cdr matcher))
4109 (org-prepare-agenda (concat "TAGS " match))
4110 (setq org-agenda-query-string match)
4111 (setq org-agenda-redo-command
4112 (list 'org-tags-view (list 'quote todo-only)
4113 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4114 (setq files (org-agenda-files nil 'ifmode)
4116 (while (setq file (pop files))
4118 (org-check-agenda-file file)
4119 (setq buffer (if (file-exists-p file)
4120 (org-get-agenda-file-buffer file)
4121 (error "No such file %s" file)))
4123 ;; If file does not exist, error message to agenda
4125 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4126 rtnall (append rtnall rtn))
4127 (with-current-buffer buffer
4128 (unless (eq major-mode 'org-mode)
4129 (error "Agenda file %s is not in `org-mode'" file))
4132 (if org-agenda-restrict
4133 (narrow-to-region org-agenda-restrict-begin
4134 org-agenda-restrict-end)
4136 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4137 (setq rtnall (append rtnall rtn))))))))
4138 (if org-agenda-overriding-header
4139 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4140 nil 'face 'org-agenda-structure) "\n")
4141 (insert "Headlines with TAGS match: ")
4142 (add-text-properties (point-min) (1- (point))
4143 (list 'face 'org-agenda-structure
4145 (concat "Match: " match)))
4148 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4150 (unless org-agenda-multi
4151 (insert "Press `C-u r' to search again with new search string\n"))
4152 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4153 (org-agenda-mark-header-line (point-min))
4155 (insert (org-finalize-agenda-entries rtnall) "\n"))
4156 (goto-char (point-min))
4157 (or org-agenda-multi (org-fit-agenda-window))
4158 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4159 (org-finalize-agenda)
4160 (setq buffer-read-only t)))
4162 ;;; Agenda Finding stuck projects
4164 (defvar org-agenda-skip-regexp nil
4165 "Regular expression used in skipping subtrees for the agenda.
4166 This is basically a temporary global variable that can be set and then
4167 used by user-defined selections using `org-agenda-skip-function'.")
4169 (defvar org-agenda-overriding-header nil
4170 "When set during agenda, todo and tags searches it replaces the header.
4171 This variable should not be set directly, but custom commands can bind it
4172 in the options section.")
4174 (defun org-agenda-skip-entry-when-regexp-matches ()
4175 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4176 If yes, it returns the end position of this entry, causing agenda commands
4177 to skip the entry but continuing the search in the subtree. This is a
4178 function that can be put into `org-agenda-skip-function' for the duration
4180 (let ((end (save-excursion (org-end-of-subtree t)))
4183 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4186 (defun org-agenda-skip-subtree-when-regexp-matches ()
4187 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4188 If yes, it returns the end position of this tree, causing agenda commands
4189 to skip this subtree. This is a function that can be put into
4190 `org-agenda-skip-function' for the duration of a command."
4191 (let ((end (save-excursion (org-end-of-subtree t)))
4194 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4197 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4198 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4199 If yes, it returns the end position of the current entry (NOT the tree),
4200 causing agenda commands to skip the entry but continuing the search in
4201 the subtree. This is a function that can be put into
4202 `org-agenda-skip-function' for the duration of a command. An important
4203 use of this function is for the stuck project list."
4204 (let ((end (save-excursion (org-end-of-subtree t)))
4205 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4208 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4209 (and skip entry-end)))
4211 (defun org-agenda-skip-entry-if (&rest conditions)
4212 "Skip entry if any of CONDITIONS is true.
4213 See `org-agenda-skip-if' for details."
4214 (org-agenda-skip-if nil conditions))
4216 (defun org-agenda-skip-subtree-if (&rest conditions)
4217 "Skip entry if any of CONDITIONS is true.
4218 See `org-agenda-skip-if' for details."
4219 (org-agenda-skip-if t conditions))
4221 (defun org-agenda-skip-if (subtree conditions)
4222 "Checks current entity for CONDITIONS.
4223 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4224 the entry (i.e. the text before the next heading) is checked.
4226 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4227 from different tests. Valid conditions are:
4229 scheduled Check if there is a scheduled cookie
4230 notscheduled Check if there is no scheduled cookie
4231 deadline Check if there is a deadline
4232 notdeadline Check if there is no deadline
4233 timestamp Check if there is a timestamp (also deadline or scheduled)
4234 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4235 regexp Check if regexp matches
4236 notregexp Check if regexp does not match.
4237 todo Check if TODO keyword matches
4238 nottodo Check if TODO keyword does not match
4240 The regexp is taken from the conditions list, it must come right after
4241 the `regexp' or `notregexp' element.
4243 `todo' and `nottodo' accept as an argument a list of todo
4244 keywords, which may include \"*\" to match any todo keyword.
4246 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4248 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4250 Instead of a list, a keyword class may be given. For example:
4252 (org-agenda-skip-entry-if 'nottodo 'done)
4254 would skip entries that haven't been marked with any of \"DONE\"
4255 keywords. Possible classes are: `todo', `done', `any'.
4257 If any of these conditions is met, this function returns the end point of
4258 the entity, causing the search to continue from there. This is a function
4259 that can be put into `org-agenda-skip-function' for the duration of a command."
4261 (org-back-to-heading t)
4264 (progn (org-end-of-subtree t) (point))
4265 (progn (outline-next-heading) (1- (point)))))
4269 (and (memq 'scheduled conditions)
4270 (re-search-forward org-scheduled-time-regexp end t))
4271 (and (memq 'notscheduled conditions)
4272 (not (re-search-forward org-scheduled-time-regexp end t)))
4273 (and (memq 'deadline conditions)
4274 (re-search-forward org-deadline-time-regexp end t))
4275 (and (memq 'notdeadline conditions)
4276 (not (re-search-forward org-deadline-time-regexp end t)))
4277 (and (memq 'timestamp conditions)
4278 (re-search-forward org-ts-regexp end t))
4279 (and (memq 'nottimestamp conditions)
4280 (not (re-search-forward org-ts-regexp end t)))
4281 (and (setq m (memq 'regexp conditions))
4283 (re-search-forward (nth 1 m) end t))
4284 (and (setq m (memq 'notregexp conditions))
4286 (not (re-search-forward (nth 1 m) end t)))
4288 (setq m (memq 'nottodo conditions))
4289 (setq m (memq 'todo conditions)))
4290 (org-agenda-skip-if-todo m end)))
4293 (defun org-agenda-skip-if-todo (args end)
4294 "Helper function for `org-agenda-skip-if', do not use it directly.
4295 ARGS is a list with first element either `todo' or `nottodo'.
4296 The remainder is either a list of TODO keywords, or a state symbol
4297 `todo' or `done' or `any'."
4298 (let ((kw (car args))
4304 ((listp arg) ;; list of keywords
4305 (if (member "*" arg)
4306 (mapcar 'substring-no-properties org-todo-keywords-1)
4308 ((symbolp arg) ;; keyword class name
4311 (org-delete-all org-done-keywords
4312 (mapcar 'substring-no-properties
4313 org-todo-keywords-1)))
4314 ((eq arg 'done) org-done-keywords)
4316 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4318 (concat "^\\*+[ \t]+\\<\\("
4319 (mapconcat 'identity todo-wds "\\|")
4322 (re-search-forward todo-re end t)
4323 (not (re-search-forward todo-re end t)))))
4326 (defun org-agenda-list-stuck-projects (&rest ignore)
4327 "Create agenda view for projects that are stuck.
4328 Stuck projects are project that have no next actions. For the definitions
4329 of what a project is and how to check if it stuck, customize the variable
4330 `org-stuck-projects'."
4332 (let* ((org-agenda-skip-function
4333 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4334 ;; We could have used org-agenda-skip-if here.
4335 (org-agenda-overriding-header
4336 (or org-agenda-overriding-header "List of stuck projects: "))
4337 (matcher (nth 0 org-stuck-projects))
4338 (todo (nth 1 org-stuck-projects))
4339 (todo-wds (if (member "*" todo)
4341 (org-prepare-agenda-buffers (org-agenda-files
4344 org-done-keywords-for-agenda
4345 (copy-sequence org-todo-keywords-for-agenda)))
4347 (todo-re (concat "^\\*+[ \t]+\\("
4348 (mapconcat 'identity todo-wds "\\|")
4350 (tags (nth 2 org-stuck-projects))
4351 (tags-re (if (member "*" tags)
4352 (concat org-outline-regexp-bol
4353 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4355 (concat org-outline-regexp-bol
4357 (mapconcat 'identity tags "\\|")
4358 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4359 (gen-re (nth 3 org-stuck-projects))
4365 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4367 (setq org-agenda-skip-regexp
4369 (mapconcat 'identity re-list "\\|")
4370 (error "No information how to identify unstuck projects")))
4371 (org-tags-view nil matcher)
4372 (with-current-buffer org-agenda-buffer-name
4373 (setq org-agenda-redo-command
4374 '(org-agenda-list-stuck-projects
4375 (or current-prefix-arg org-last-arg))))))
4377 ;;; Diary integration
4379 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4380 (defvar list-diary-entries-hook)
4381 (defvar diary-time-regexp)
4382 (defun org-get-entries-from-diary (date)
4383 "Get the (Emacs Calendar) diary entries for DATE."
4384 (require 'diary-lib)
4385 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4386 (diary-display-hook '(fancy-diary-display))
4387 (diary-display-function 'fancy-diary-display)
4389 (list-diary-entries-hook
4390 (cons 'org-diary-default-entry list-diary-entries-hook))
4391 (diary-file-name-prefix-function nil) ; turn this feature off
4392 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4394 (org-disable-agenda-to-diary t))
4396 (save-window-excursion
4397 (funcall (if (fboundp 'diary-list-entries)
4398 'diary-list-entries 'list-diary-entries)
4400 (if (not (get-buffer diary-fancy-buffer))
4402 (with-current-buffer diary-fancy-buffer
4403 (setq buffer-read-only nil)
4404 (if (zerop (buffer-size))
4407 ;; Omit the date and other unnecessary stuff
4408 (org-agenda-cleanup-fancy-diary)
4409 ;; Add prefix to each line and extend the text properties
4410 (if (zerop (buffer-size))
4412 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4415 (insert entries) (goto-char (point-min))
4416 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4417 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4418 (replace-match (concat "; " (match-string 1)))))
4420 (set-buffer-modified-p nil)
4421 (kill-buffer diary-fancy-buffer)))
4423 (setq entries (org-split-string entries "\n"))
4427 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4428 ;; Extend the text properties to the beginning of the line
4429 (org-add-props x (text-properties-at (1- (length x)) x)
4430 'type "diary" 'date date 'face 'org-agenda-diary))
4433 (defvar org-agenda-cleanup-fancy-diary-hook nil
4434 "Hook run when the fancy diary buffer is cleaned up.")
4436 (defun org-agenda-cleanup-fancy-diary ()
4437 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4438 This gets rid of the date, the underline under the date, and
4439 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4440 date. It also removes lines that contain only whitespace."
4441 (goto-char (point-min))
4442 (if (looking-at ".*?:[ \t]*")
4445 (re-search-forward "\n=+$" nil t)
4447 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4448 (re-search-forward "\n=+$" nil t)
4449 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4450 (goto-char (point-min))
4451 (while (re-search-forward "^ +\n" nil t)
4453 (goto-char (point-min))
4454 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4456 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4458 ;; Make sure entries from the diary have the right text properties.
4459 (eval-after-load "diary-lib"
4460 '(if (boundp 'diary-modify-entry-list-string-function)
4461 ;; We can rely on the hook, nothing to do
4463 ;; Hook not available, must use advice to make this work
4464 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4465 "Make the position visible."
4466 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4469 (setq string (org-modify-diary-entry-string string))))))
4471 (defun org-modify-diary-entry-string (string)
4472 "Add text properties to string, allowing org-mode to act on it."
4473 (org-add-props string nil
4474 'mouse-face 'highlight
4475 'help-echo (if buffer-file-name
4476 (format "mouse-2 or RET jump to diary file %s"
4477 (abbreviate-file-name buffer-file-name))
4479 'org-agenda-diary-link t
4480 'org-marker (org-agenda-new-marker (point-at-bol))))
4482 (defun org-diary-default-entry ()
4483 "Add a dummy entry to the diary.
4484 Needed to avoid empty dates which mess up holiday display."
4485 ;; Catch the error if dealing with the new add-to-diary-alist
4486 (when org-disable-agenda-to-diary
4488 (org-add-to-diary-list original-date "Org-mode dummy" "")
4490 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4492 (defun org-add-to-diary-list (&rest args)
4493 (if (fboundp 'diary-add-to-list)
4494 (apply 'diary-add-to-list args)
4495 (apply 'add-to-diary-list args)))
4497 (defvar org-diary-last-run-time nil)
4500 (defun org-diary (&rest args)
4501 "Return diary information from org-files.
4502 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4503 It accesses org files and extracts information from those files to be
4504 listed in the diary. The function accepts arguments specifying what
4505 items should be listed. For a list of arguments allowed here, see the
4506 variable `org-agenda-entry-types'.
4508 The call in the diary file should look like this:
4510 &%%(org-diary) ~/path/to/some/orgfile.org
4512 Use a separate line for each org file to check. Or, if you omit the file name,
4513 all files listed in `org-agenda-files' will be checked automatically:
4517 If you don't give any arguments (as in the example above), the default
4518 arguments (:deadline :scheduled :timestamp :sexp) are used.
4519 So the example above may also be written as
4521 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4523 The function expects the lisp variables `entry' and `date' to be provided
4524 by the caller, because this is how the calendar works. Don't use this
4525 function from a program - use `org-agenda-get-day-entries' instead."
4526 (when (> (- (org-float-time)
4527 org-agenda-last-marker-time)
4529 (org-agenda-reset-markers))
4530 (org-compile-prefix-format 'agenda)
4531 (org-set-sorting-strategy 'agenda)
4532 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4533 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4535 (org-agenda-files t)))
4536 (time (org-float-time))
4538 (when (or (not org-diary-last-run-time)
4540 org-diary-last-run-time)
4542 (org-prepare-agenda-buffers files))
4543 (setq org-diary-last-run-time time)
4544 ;; If this is called during org-agenda, don't return any entries to
4545 ;; the calendar. Org Agenda will list these entries itself.
4546 (if org-disable-agenda-to-diary (setq files nil))
4547 (while (setq file (pop files))
4548 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4549 (setq results (append results rtn)))
4551 (concat (org-finalize-agenda-entries results) "\n"))))
4553 ;;; Agenda entry finders
4555 (defun org-agenda-get-day-entries (file date &rest args)
4556 "Does the work for `org-diary' and `org-agenda'.
4557 FILE is the path to a file to be checked for entries. DATE is date like
4558 the one returned by `calendar-current-date'. ARGS are symbols indicating
4559 which kind of entries should be extracted. For details about these, see
4560 the documentation of `org-diary'."
4561 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4562 (let* ((org-startup-folded nil)
4563 (org-startup-align-all-tables nil)
4564 (buffer (if (file-exists-p file)
4565 (org-get-agenda-file-buffer file)
4566 (error "No such file %s" file)))
4567 arg results rtn deadline-results)
4569 ;; If file does not exist, make sure an error message ends up in diary
4570 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4571 (with-current-buffer buffer
4572 (unless (eq major-mode 'org-mode)
4573 (error "Agenda file %s is not in `org-mode'" file))
4574 (let ((case-fold-search nil))
4577 (if org-agenda-restrict
4578 (narrow-to-region org-agenda-restrict-begin
4579 org-agenda-restrict-end)
4581 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4582 (while (setq arg (pop args))
4584 ((and (eq arg :todo)
4585 (equal date (calendar-gregorian-from-absolute
4587 (setq rtn (org-agenda-get-todos))
4588 (setq results (append results rtn)))
4589 ((eq arg :timestamp)
4590 (setq rtn (org-agenda-get-blocks))
4591 (setq results (append results rtn))
4592 (setq rtn (org-agenda-get-timestamps))
4593 (setq results (append results rtn)))
4595 (setq rtn (org-agenda-get-sexps))
4596 (setq results (append results rtn)))
4597 ((eq arg :scheduled)
4598 (setq rtn (org-agenda-get-scheduled deadline-results))
4599 (setq results (append results rtn)))
4601 (setq rtn (org-agenda-get-progress))
4602 (setq results (append results rtn)))
4604 (setq rtn (org-agenda-get-deadlines))
4605 (setq deadline-results (copy-sequence rtn))
4606 (setq results (append results rtn))))))))
4609 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4610 (defun org-agenda-get-todos ()
4611 "Return the TODO information for agenda display."
4612 (let* ((props (list 'face nil
4613 'done-face 'org-agenda-done
4614 'org-not-done-regexp org-not-done-regexp
4615 'org-todo-regexp org-todo-regexp
4616 'org-complex-heading-regexp org-complex-heading-regexp
4617 'mouse-face 'highlight
4619 (format "mouse-2 or RET jump to org file %s"
4620 (abbreviate-file-name buffer-file-name))))
4621 (regexp (format org-heading-keyword-regexp-format
4623 ((and org-select-this-todo-keyword
4624 (equal org-select-this-todo-keyword "*"))
4626 (org-select-this-todo-keyword
4628 (mapconcat 'identity
4630 org-select-this-todo-keyword
4633 (t org-not-done-regexp))))
4634 marker priority category org-category-pos tags todo-state
4636 (goto-char (point-min))
4637 (while (re-search-forward regexp nil t)
4642 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4643 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4644 (goto-char (1+ beg))
4645 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4647 (goto-char (match-beginning 2))
4648 (setq marker (org-agenda-new-marker (match-beginning 0))
4649 category (org-get-category)
4650 org-category-pos (get-text-property (point) 'org-category-position)
4652 (buffer-substring (match-beginning 2) (match-end 0)))
4653 tags (org-get-tags-at (point))
4654 txt (org-agenda-format-item "" txt category tags)
4655 priority (1+ (org-get-priority txt))
4656 todo-state (org-get-todo-state))
4657 (org-add-props txt props
4658 'org-marker marker 'org-hd-marker marker
4659 'priority priority 'org-category category
4660 'org-category-position org-category-pos
4661 'type "todo" 'todo-state todo-state)
4663 (if org-agenda-todo-list-sublevels
4664 (goto-char (match-end 2))
4665 (org-end-of-subtree 'invisible))))
4668 (defun org-agenda-todo-custom-ignore-p (time n)
4669 "Check whether timestamp is farther away then n number of days.
4670 This function is invoked if `org-agenda-todo-ignore-deadlines',
4671 `org-agenda-todo-ignore-scheduled' or
4672 `org-agenda-todo-ignore-timestamp' is set to an integer."
4673 (let ((days (org-days-to-time time)))
4679 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4681 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4682 (when (or org-agenda-todo-ignore-with-date
4683 org-agenda-todo-ignore-scheduled
4684 org-agenda-todo-ignore-deadlines
4685 org-agenda-todo-ignore-timestamp)
4686 (setq end (or end (save-excursion (outline-next-heading) (point))))
4688 (or (and org-agenda-todo-ignore-with-date
4689 (re-search-forward org-ts-regexp end t))
4690 (and org-agenda-todo-ignore-scheduled
4691 (re-search-forward org-scheduled-time-regexp end t)
4693 ((eq org-agenda-todo-ignore-scheduled 'future)
4694 (> (org-days-to-time (match-string 1)) 0))
4695 ((eq org-agenda-todo-ignore-scheduled 'past)
4696 (<= (org-days-to-time (match-string 1)) 0))
4697 ((numberp org-agenda-todo-ignore-scheduled)
4698 (org-agenda-todo-custom-ignore-p
4699 (match-string 1) org-agenda-todo-ignore-scheduled))
4701 (and org-agenda-todo-ignore-deadlines
4702 (re-search-forward org-deadline-time-regexp end t)
4704 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4705 ((eq org-agenda-todo-ignore-deadlines 'far)
4706 (not (org-deadline-close (match-string 1))))
4707 ((eq org-agenda-todo-ignore-deadlines 'future)
4708 (> (org-days-to-time (match-string 1)) 0))
4709 ((eq org-agenda-todo-ignore-deadlines 'past)
4710 (<= (org-days-to-time (match-string 1)) 0))
4711 ((numberp org-agenda-todo-ignore-deadlines)
4712 (org-agenda-todo-custom-ignore-p
4713 (match-string 1) org-agenda-todo-ignore-deadlines))
4714 (t (org-deadline-close (match-string 1)))))
4715 (and org-agenda-todo-ignore-timestamp
4716 (let ((buffer (current-buffer))
4719 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4721 ;; Copy current buffer into a temporary one
4723 (insert-buffer-substring buffer start end)
4724 (goto-char (point-min))
4725 ;; Delete SCHEDULED and DEADLINE items
4726 (while (re-search-forward regexp end t)
4727 (delete-region (match-beginning 0) (match-end 0)))
4728 (goto-char (point-min))
4729 ;; No search for timestamp left
4730 (when (re-search-forward org-ts-regexp nil t)
4732 ((eq org-agenda-todo-ignore-timestamp 'future)
4733 (> (org-days-to-time (match-string 1)) 0))
4734 ((eq org-agenda-todo-ignore-timestamp 'past)
4735 (<= (org-days-to-time (match-string 1)) 0))
4736 ((numberp org-agenda-todo-ignore-timestamp)
4737 (org-agenda-todo-custom-ignore-p
4738 (match-string 1) org-agenda-todo-ignore-timestamp))
4741 (defconst org-agenda-no-heading-message
4742 "No heading for this item in buffer or region.")
4744 (defun org-agenda-get-timestamps ()
4745 "Return the date stamp information for agenda display."
4746 (let* ((props (list 'face 'org-agenda-calendar-event
4747 'org-not-done-regexp org-not-done-regexp
4748 'org-todo-regexp org-todo-regexp
4749 'org-complex-heading-regexp org-complex-heading-regexp
4750 'mouse-face 'highlight
4752 (format "mouse-2 or RET jump to org file %s"
4753 (abbreviate-file-name buffer-file-name))))
4754 (d1 (calendar-absolute-from-gregorian date))
4760 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4764 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4768 (car org-time-stamp-formats)
4769 (apply 'encode-time ; DATE bound by calendar
4770 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4772 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4773 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4774 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4775 donep tmp priority category org-category-pos ee txt timestr tags
4776 b0 b3 e3 head todo-state end-of-match show-all)
4777 (goto-char (point-min))
4778 (while (setq end-of-match (re-search-forward regexp nil t))
4779 (setq b0 (match-beginning 0)
4780 b3 (match-beginning 3) e3 (match-end 3)
4781 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4782 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4784 org-agenda-repeating-timestamp-show-all)))
4786 (and (org-at-date-range-p) (throw :skip nil))
4788 (if (and (match-end 1)
4789 (not (= d1 (org-time-string-to-absolute
4790 (match-string 1) d1 nil show-all
4791 (current-buffer) b0))))
4794 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4796 (setq tmp (buffer-substring (max (point-min)
4797 (- b0 org-ds-keyword-length))
4799 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4800 inactivep (= (char-after b0) ?\[)
4801 deadlinep (string-match org-deadline-regexp tmp)
4802 scheduledp (string-match org-scheduled-regexp tmp)
4803 closedp (and org-agenda-include-inactive-timestamps
4804 (string-match org-closed-string tmp))
4805 clockp (and org-agenda-include-inactive-timestamps
4806 (or (string-match org-clock-string tmp)
4807 (string-match "]-+\\'" tmp)))
4808 donep (member todo-state org-done-keywords))
4809 (if (or scheduledp deadlinep closedp clockp
4810 (and donep org-agenda-skip-timestamp-if-done))
4812 (if (string-match ">" timestr)
4813 ;; substring should only run to end of time stamp
4814 (setq timestr (substring timestr 0 (match-end 0))))
4815 (setq marker (org-agenda-new-marker b0)
4816 category (org-get-category b0)
4817 org-category-pos (get-text-property b0 'org-category-position))
4819 (if (not (re-search-backward org-outline-regexp-bol nil t))
4820 (setq txt org-agenda-no-heading-message)
4821 (goto-char (match-beginning 0))
4822 (setq hdmarker (org-agenda-new-marker)
4823 tags (org-get-tags-at))
4824 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4825 (setq head (or (match-string 1) ""))
4826 (setq txt (org-agenda-format-item
4827 (if inactivep org-agenda-inactive-leader nil)
4828 head category tags timestr
4830 (setq priority (org-get-priority txt))
4831 (org-add-props txt props
4832 'org-marker marker 'org-hd-marker hdmarker)
4833 (org-add-props txt nil 'priority priority
4834 'org-category category 'date date
4835 'org-category-position org-category-pos
4836 'todo-state todo-state
4839 (if org-agenda-skip-additional-timestamps-same-entry
4840 (outline-next-heading)
4841 (goto-char end-of-match))))
4844 (defun org-agenda-get-sexps ()
4845 "Return the sexp information for agenda display."
4846 (require 'diary-lib)
4847 (let* ((props (list 'face 'org-agenda-calendar-sexp
4848 'mouse-face 'highlight
4850 (format "mouse-2 or RET jump to org file %s"
4851 (abbreviate-file-name buffer-file-name))))
4853 marker category org-category-pos ee txt tags entry
4854 result beg b sexp sexp-entry todo-state)
4855 (goto-char (point-min))
4856 (while (re-search-forward regexp nil t)
4859 (setq beg (match-beginning 0))
4860 (goto-char (1- (match-end 0)))
4863 (setq sexp (buffer-substring b (point)))
4864 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4865 (org-trim (match-string 1))
4867 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4869 (setq marker (org-agenda-new-marker beg)
4870 category (org-get-category beg)
4871 org-category-pos (get-text-property beg 'org-category-position)
4872 todo-state (org-get-todo-state))
4874 (dolist (r (if (stringp result)
4876 result)) ;; we expect a list here
4877 (if (string-match "\\S-" r)
4879 (setq txt "SEXP entry returned empty string"))
4881 (setq txt (org-agenda-format-item
4882 "" txt category tags 'time))
4883 (org-add-props txt props 'org-marker marker)
4884 (org-add-props txt nil
4885 'org-category category 'date date 'todo-state todo-state
4886 'org-category-position org-category-pos
4891 ;; Calendar sanity: define some functions that are independent of
4892 ;; `calendar-date-style'.
4893 ;; Normally I would like to use ISO format when calling the diary functions,
4894 ;; but to make sure we still have Emacs 22 compatibility we bind
4895 ;; also `european-calendar-style' and use european format
4896 (defun org-anniversary (year month day &optional mark)
4897 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
4899 (let ((calendar-date-style 'european) (european-calendar-style t))
4900 (diary-anniversary day month year mark))))
4901 (defun org-cyclic (N year month day &optional mark)
4902 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
4904 (let ((calendar-date-style 'european) (european-calendar-style t))
4905 (diary-cyclic N day month year mark))))
4906 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
4907 "Like `diary-block', but with fixed (ISO) order of arguments."
4909 (let ((calendar-date-style 'european) (european-calendar-style t))
4910 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
4911 (defun org-date (year month day &optional mark)
4912 "Like `diary-date', but with fixed (ISO) order of arguments."
4914 (let ((calendar-date-style 'european) (european-calendar-style t))
4915 (diary-date day month year mark))))
4916 (defalias 'org-float 'diary-float)
4918 ;; Define the` org-class' function
4919 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
4920 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4921 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
4922 SKIP-WEEKS is any number of ISO weeks in the block period for which the
4923 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
4924 `holidays', then any date that is known by the Emacs calendar to be a
4925 holiday will also be skipped."
4926 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
4927 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
4928 (d (calendar-absolute-from-gregorian date)))
4932 (= (calendar-day-of-week date) dayname)
4933 (or (not skip-weeks)
4936 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4937 (not (and (memq 'holidays skip-weeks)
4938 (calendar-check-holidays date)))
4941 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4942 "Like `org-class', but honor `calendar-date-style'.
4943 The order of the first 2 times 3 arguments depends on the variable
4944 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4945 So for American calendars, give this as MONTH DAY YEAR, for European as
4946 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4947 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4948 is any number of ISO weeks in the block period for which the item should
4951 This function is here only for backward compatibility and it is deprecated,
4952 please use `org-class' instead."
4953 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
4954 (date2 (org-order-calendar-date-args m2 d2 y2)))
4956 (nth 2 date1) (car date1) (nth 1 date1)
4957 (nth 2 date2) (car date2) (nth 1 date2)
4958 dayname skip-weeks)))
4959 (make-obsolete 'org-diary-class 'org-class "")
4961 (defalias 'org-get-closed 'org-agenda-get-progress)
4962 (defun org-agenda-get-progress ()
4963 "Return the logged TODO entries for agenda display."
4964 (let* ((props (list 'mouse-face 'highlight
4965 'org-not-done-regexp org-not-done-regexp
4966 'org-todo-regexp org-todo-regexp
4967 'org-complex-heading-regexp org-complex-heading-regexp
4969 (format "mouse-2 or RET jump to org file %s"
4970 (abbreviate-file-name buffer-file-name))))
4971 (items (if (consp org-agenda-show-log)
4973 (if (eq org-agenda-show-log 'clockcheck)
4975 org-agenda-log-mode-items)))
4979 (if (memq 'closed items) (concat "\\<" org-closed-string))
4980 (if (memq 'clock items) (concat "\\<" org-clock-string))
4981 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4982 (parts-re (if parts (mapconcat 'identity parts "\\|")
4983 (error "`org-agenda-log-mode-items' is empty")))
4985 "\\(" parts-re "\\)"
4990 (car org-time-stamp-formats)
4991 (apply 'encode-time ; DATE bound by calendar
4992 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4994 (org-agenda-search-headline-for-time nil)
4995 marker hdmarker priority category org-category-pos tags closedp
4996 statep clockp state ee txt extra timestr rest clocked)
4997 (goto-char (point-min))
4998 (while (re-search-forward regexp nil t)
5001 (setq marker (org-agenda-new-marker (match-beginning 0))
5002 closedp (equal (match-string 1) org-closed-string)
5003 statep (equal (string-to-char (match-string 1)) ?-)
5004 clockp (not (or closedp statep))
5005 state (and statep (match-string 2))
5006 category (org-get-category (match-beginning 0))
5007 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5008 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5009 (when (string-match "\\]" timestr)
5010 ;; substring should only run to end of time stamp
5011 (setq rest (substring timestr (match-end 0))
5012 timestr (substring timestr 0 (match-end 0)))
5013 (if (and (not closedp) (not statep)
5014 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5016 (progn (setq timestr (concat (substring timestr 0 -1)
5017 "-" (match-string 1 rest) "]"))
5018 (setq clocked (match-string 2 rest)))
5019 (setq clocked "-")))
5023 ((not org-agenda-log-mode-add-notes) nil)
5025 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5028 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5029 (match-string 1)))))
5030 (if (not (re-search-backward org-outline-regexp-bol nil t))
5031 (setq txt org-agenda-no-heading-message)
5032 (goto-char (match-beginning 0))
5033 (setq hdmarker (org-agenda-new-marker)
5034 tags (org-get-tags-at))
5035 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5036 (setq txt (match-string 1))
5038 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5039 (setq txt (concat (substring txt 0 (match-beginning 1))
5040 " - " extra " " (match-string 2 txt)))
5041 (setq txt (concat txt " - " extra))))
5042 (setq txt (org-agenda-format-item
5044 (closedp "Closed: ")
5045 (statep (concat "State: (" state ")"))
5046 (t (concat "Clocked: (" clocked ")")))
5047 txt category tags timestr)))
5048 (setq priority 100000)
5049 (org-add-props txt props
5050 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5051 'priority priority 'org-category category
5052 'org-category-position org-category-pos
5053 'type "closed" 'date date
5054 'undone-face 'org-warning 'done-face 'org-agenda-done)
5056 (goto-char (point-at-eol))))
5059 (defun org-agenda-show-clocking-issues ()
5060 "Add overlays, showing issues with clocking.
5061 See also the user option `org-agenda-clock-consistency-checks'."
5063 (let* ((pl org-agenda-clock-consistency-checks)
5064 (re (concat "^[ \t]*"
5067 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5068 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5071 (maxtime (org-hh:mm-string-to-minutes
5072 (or (plist-get pl :max-duration) "24:00")))
5073 (mintime (org-hh:mm-string-to-minutes
5074 (or (plist-get pl :min-duration) 0)))
5075 (maxgap (org-hh:mm-string-to-minutes
5076 ;; default 30:00 means never complain
5077 (or (plist-get pl :max-gap) "30:00")))
5078 (gapok (mapcar 'org-hh:mm-string-to-minutes
5079 (plist-get pl :gap-ok-around)))
5080 (def-face (or (plist-get pl :default-face)
5081 '((:background "DarkRed") (:foreground "white"))))
5082 issue face m te ts dt ov)
5083 (goto-char (point-min))
5084 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5085 (setq issue nil face def-face)
5087 (setq m (org-get-at-bol 'org-marker)
5089 (unless (and m (markerp m))
5090 (setq issue "No valid clock line") (throw 'next t))
5091 (org-with-point-at m
5093 (goto-char (point-at-bol))
5094 (unless (looking-at re)
5095 (error "No valid Clock line")
5097 (unless (match-end 3)
5098 (setq issue "No end time"
5099 face (or (plist-get pl :no-end-time-face) face))
5101 (setq ts (match-string 1)
5104 (apply 'encode-time (org-parse-time-string ts)))
5106 (apply 'encode-time (org-parse-time-string te)))
5109 ((> dt (* 60 maxtime))
5110 ;; a very long clocking chunk
5111 (setq issue (format "Clocking interval is very long: %s"
5112 (org-minutes-to-hh:mm-string
5113 (floor (/ (float dt) 60.))))
5114 face (or (plist-get pl :long-face) face)))
5115 ((< dt (* 60 mintime))
5116 ;; a very short clocking chunk
5117 (setq issue (format "Clocking interval is very short: %s"
5118 (org-minutes-to-hh:mm-string
5119 (floor (/ (float dt) 60.))))
5120 face (or (plist-get pl :short-face) face)))
5121 ((and (> tlend 0) (< ts tlend))
5122 ;; Two clock entries are overlapping
5123 (setq issue (format "Clocking overlap: %d minutes"
5124 (/ (- tlend ts) 60))
5125 face (or (plist-get pl :overlap-face) face)))
5126 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5127 ;; There is a gap, lets see if we need to report it
5128 (unless (org-agenda-check-clock-gap tlend ts gapok)
5129 (setq issue (format "Clocking gap: %d minutes"
5130 (/ (- ts tlend) 60))
5131 face (or (plist-get pl :gap-face) face))))
5133 (setq tlend (or te tlend) tlstart (or ts tlstart))
5135 ;; OK, there was some issue, add an overlay to show the issue
5136 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5137 (overlay-put ov 'before-string
5140 (format "%-43s" (concat " " issue))
5144 (overlay-put ov 'evaporate t)))))
5146 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5147 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5150 ;; there are no OK times for gaps...
5152 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5153 ;; This is more than 24 hours, so it is OK.
5154 ;; because we have at least one OK time, that must be in the
5155 ;; 24 hour interval.
5157 ;; We have a shorter gap.
5158 ;; Now we have to get the minute of the day when these times are
5159 (let* ((t1dec (decode-time (seconds-to-time t1)))
5160 (t2dec (decode-time (seconds-to-time t2)))
5161 ;; compute the minute on the day
5162 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5163 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5165 ;; if min2 is smaller than min1, this means it is on the next day.
5166 ;; Wrap it to after midnight.
5167 (setq min2 (+ min2 1440)))
5168 ;; Now check if any of the OK times is in the gap
5170 ;; Wrap the time to after midnight if necessary
5171 (if (< x min1) (setq x (+ x 1440)))
5172 ;; Check if in interval
5173 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5175 ;; Nope, this gap is not OK
5178 (defun org-agenda-get-deadlines ()
5179 "Return the deadline information for agenda display."
5180 (let* ((props (list 'mouse-face 'highlight
5181 'org-not-done-regexp org-not-done-regexp
5182 'org-todo-regexp org-todo-regexp
5183 'org-complex-heading-regexp org-complex-heading-regexp
5185 (format "mouse-2 or RET jump to org file %s"
5186 (abbreviate-file-name buffer-file-name))))
5187 (regexp org-deadline-time-regexp)
5188 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5189 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5190 d2 diff dfrac wdays pos pos1 category org-category-pos
5191 tags suppress-prewarning ee txt head face s todo-state
5192 show-all upcomingp donep timestr)
5193 (goto-char (point-min))
5194 (while (re-search-forward regexp nil t)
5195 (setq suppress-prewarning nil)
5198 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5200 (string-match org-scheduled-time-regexp
5201 (buffer-substring (point-at-bol)
5203 (setq suppress-prewarning
5204 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5205 org-agenda-skip-deadline-prewarning-if-scheduled
5207 (setq s (match-string 1)
5209 pos (1- (match-beginning 1))
5210 todo-state (save-match-data (org-get-todo-state))
5211 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5213 org-agenda-repeating-timestamp-show-all))
5214 d2 (org-time-string-to-absolute
5215 (match-string 1) d1 'past show-all
5216 (current-buffer) pos)
5218 wdays (if suppress-prewarning
5219 (let ((org-deadline-warning-days suppress-prewarning))
5222 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5223 upcomingp (and todayp (> diff 0)))
5224 ;; When to show a deadline in the calendar:
5225 ;; If the expiration is within wdays warning time.
5226 ;; Past-due deadlines are only shown on the current date
5227 (if (and (or (and (<= diff wdays)
5228 (and todayp (not org-agenda-only-exact-dates)))
5231 ;; (setq todo-state (org-get-todo-state))
5232 (setq donep (member todo-state org-done-keywords))
5234 (or org-agenda-skip-deadline-if-done
5237 (setq category (org-get-category)
5238 org-category-pos (get-text-property (point) 'org-category-position))
5239 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5240 (setq txt org-agenda-no-heading-message)
5241 (goto-char (match-end 0))
5242 (setq pos1 (match-beginning 0))
5243 (setq tags (org-get-tags-at pos1))
5244 (setq head (buffer-substring-no-properties
5246 (progn (skip-chars-forward "^\r\n")
5248 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5250 (concat (substring s (match-beginning 1)) " "))
5251 (setq timestr 'time))
5252 (setq txt (org-agenda-format-item
5254 (car org-agenda-deadline-leaders)
5256 (nth 1 org-agenda-deadline-leaders))
5258 (nth 1 org-agenda-deadline-leaders)
5260 (format (nth 1 org-agenda-deadline-leaders)
5263 (if (not (= diff 0)) nil timestr)))))
5265 (setq face (org-agenda-deadline-face dfrac))
5266 (org-add-props txt props
5267 'org-marker (org-agenda-new-marker pos)
5268 'org-hd-marker (org-agenda-new-marker pos1)
5269 'priority (+ (- diff)
5270 (org-get-priority txt))
5271 'org-category category
5272 'org-category-position org-category-pos
5273 'todo-state todo-state
5274 'type (if upcomingp "upcoming-deadline" "deadline")
5275 'date (if upcomingp date d2)
5276 'face (if donep 'org-agenda-done face)
5277 'undone-face face 'done-face 'org-agenda-done)
5281 (defun org-agenda-deadline-face (fraction)
5282 "Return the face to displaying a deadline item.
5283 FRACTION is what fraction of the head-warning time has passed."
5284 (let ((faces org-agenda-deadline-faces) f)
5286 (while (setq f (pop faces))
5287 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5289 (defun org-agenda-get-scheduled (&optional deadline-results)
5290 "Return the scheduled information for agenda display."
5291 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5292 'org-todo-regexp org-todo-regexp
5293 'org-complex-heading-regexp org-complex-heading-regexp
5294 'done-face 'org-agenda-done
5295 'mouse-face 'highlight
5297 (format "mouse-2 or RET jump to org file %s"
5298 (abbreviate-file-name buffer-file-name))))
5299 (regexp org-scheduled-time-regexp)
5300 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5301 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5303 (deadline-position-alist
5304 (mapcar (lambda (a) (and (setq mm (get-text-property
5305 0 'org-hd-marker a))
5306 (cons (marker-position mm) a)))
5308 d2 diff pos pos1 category org-category-pos tags donep
5309 ee txt head pastschedp todo-state face timestr s habitp show-all)
5310 (goto-char (point-min))
5311 (while (re-search-forward regexp nil t)
5314 (setq s (match-string 1)
5316 pos (1- (match-beginning 1))
5317 todo-state (save-match-data (org-get-todo-state))
5318 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5320 org-agenda-repeating-timestamp-show-all))
5321 d2 (org-time-string-to-absolute
5322 (match-string 1) d1 'past show-all
5323 (current-buffer) pos)
5325 (setq pastschedp (and todayp (< diff 0)))
5326 ;; When to show a scheduled item in the calendar:
5327 ;; If it is on or past the date.
5328 (when (or (and (< diff 0)
5329 (< (abs diff) org-scheduled-past-days)
5330 (and todayp (not org-agenda-only-exact-dates)))
5333 (setq donep (member todo-state org-done-keywords))
5335 (or org-agenda-skip-scheduled-if-done
5337 (and (functionp 'org-is-habit-p)
5340 (setq habitp (and (functionp 'org-is-habit-p)
5342 (setq category (org-get-category)
5343 org-category-pos (get-text-property (point) 'org-category-position))
5344 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5345 (setq txt org-agenda-no-heading-message)
5346 (goto-char (match-end 0))
5347 (setq pos1 (match-beginning 0))
5349 (if (or (not org-habit-show-habits)
5351 org-habit-show-habits-only-for-today))
5354 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5355 (and org-agenda-skip-scheduled-if-deadline-is-shown
5357 (setq mm (assoc pos1 deadline-position-alist)))
5359 (setq tags (org-get-tags-at))
5360 (setq head (buffer-substring-no-properties
5362 (progn (skip-chars-forward "^\r\n") (point))))
5363 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5365 (concat (substring s (match-beginning 1)) " "))
5366 (setq timestr 'time))
5367 (setq txt (org-agenda-format-item
5369 (car org-agenda-scheduled-leaders)
5370 (format (nth 1 org-agenda-scheduled-leaders)
5373 (if (not (= diff 0)) nil timestr)
5378 ((and (not habitp) pastschedp)
5379 'org-scheduled-previously)
5380 (todayp 'org-scheduled-today)
5382 habitp (and habitp (org-habit-parse-todo)))
5383 (org-add-props txt props
5385 'face (if donep 'org-agenda-done face)
5386 'org-marker (org-agenda-new-marker pos)
5387 'org-hd-marker (org-agenda-new-marker pos1)
5388 'type (if pastschedp "past-scheduled" "scheduled")
5389 'date (if pastschedp d2 date)
5390 'priority (if habitp
5391 (org-habit-get-priority habitp)
5392 (+ 94 (- 5 diff) (org-get-priority txt)))
5393 'org-category category
5394 'org-category-position org-category-pos
5396 'todo-state todo-state)
5400 (defun org-agenda-get-blocks ()
5401 "Return the date-range information for agenda display."
5402 (let* ((props (list 'face nil
5403 'org-not-done-regexp org-not-done-regexp
5404 'org-todo-regexp org-todo-regexp
5405 'org-complex-heading-regexp org-complex-heading-regexp
5406 'mouse-face 'highlight
5408 (format "mouse-2 or RET jump to org file %s"
5409 (abbreviate-file-name buffer-file-name))))
5410 (regexp org-tr-regexp)
5411 (d0 (calendar-absolute-from-gregorian date))
5412 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5413 todo-state tags pos head donep)
5414 (goto-char (point-min))
5415 (while (re-search-forward regexp nil t)
5419 (let ((start-time (match-string 1))
5420 (end-time (match-string 2)))
5421 (setq s1 (match-string 1)
5423 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5424 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5425 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5426 ;; Only allow days between the limits, because the normal
5427 ;; date stamps will catch the limits.
5429 (setq todo-state (org-get-todo-state))
5430 (setq donep (member todo-state org-done-keywords))
5431 (if (and donep org-agenda-skip-timestamp-if-done)
5433 (setq marker (org-agenda-new-marker (point)))
5434 (setq category (org-get-category)
5435 org-category-pos (get-text-property (point) 'org-category-position))
5436 (if (not (re-search-backward org-outline-regexp-bol nil t))
5437 (setq txt org-agenda-no-heading-message)
5438 (goto-char (match-beginning 0))
5439 (setq hdmarker (org-agenda-new-marker (point)))
5440 (setq tags (org-get-tags-at))
5441 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5442 (setq head (match-string 1))
5444 (if org-agenda-remove-timeranges-from-blocks
5446 "<" (regexp-quote s1) ".*?>"
5448 "<" (regexp-quote s2) ".*?>")
5450 (setq txt (org-agenda-format-item
5452 (nth (if (= d1 d2) 0 1)
5453 org-agenda-timerange-leaders)
5454 (1+ (- d0 d1)) (1+ (- d2 d1)))
5456 (cond ((and (= d1 d0) (= d2 d0))
5457 (concat "<" start-time ">--<" end-time ">"))
5459 (concat "<" start-time ">"))
5461 (concat "<" end-time ">"))
5464 (org-add-props txt props
5465 'org-marker marker 'org-hd-marker hdmarker
5466 'type "block" 'date date
5467 'todo-state todo-state
5468 'priority (org-get-priority txt) 'org-category category
5469 'org-category-position org-category-pos)
5472 ;; Sort the entries by expiration date.
5475 ;;; Agenda presentation and sorting
5477 (defvar org-prefix-has-time nil
5478 "A flag, set by `org-compile-prefix-format'.
5479 The flag is set if the currently compiled format contains a `%t'.")
5480 (defvar org-prefix-has-tag nil
5481 "A flag, set by `org-compile-prefix-format'.
5482 The flag is set if the currently compiled format contains a `%T'.")
5483 (defvar org-prefix-has-effort nil
5484 "A flag, set by `org-compile-prefix-format'.
5485 The flag is set if the currently compiled format contains a `%e'.")
5486 (defvar org-prefix-category-length nil
5487 "Used by `org-compile-prefix-format' to remember the category field width.")
5488 (defvar org-prefix-category-max-length nil
5489 "Used by `org-compile-prefix-format' to remember the category field width.")
5491 (defun org-agenda-get-category-icon (category)
5492 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5493 (dolist (entry org-agenda-category-icon-alist)
5494 (when (org-string-match-p (car entry) category)
5495 (if (listp (cadr entry))
5496 (return (cadr entry))
5497 (return (apply 'create-image (cdr entry)))))))
5499 (defun org-agenda-format-item (extra txt &optional category tags dotime
5501 "Format TXT to be inserted into the agenda buffer.
5502 In particular, it adds the prefix and corresponding text properties. EXTRA
5503 must be a string and replaces the `%s' specifier in the prefix format.
5504 CATEGORY (string, symbol or nil) may be used to overrule the default
5505 category taken from local variable or file name. It will replace the `%c'
5506 specifier in the format. DOTIME, when non-nil, indicates that a
5507 time-of-day should be extracted from TXT for sorting of this entry, and for
5508 the `%t' specifier in the format. When DOTIME is a string, this string is
5509 searched for a time before TXT is. TAGS can be the tags of the headline.
5510 Any match of REMOVE-RE will be removed from TXT."
5512 ;; Diary entries sometimes have extra whitespace at the beginning
5513 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5515 ;; Fix the tags part in txt
5516 (setq txt (org-agenda-fix-displayed-tags
5518 org-agenda-show-inherited-tags
5519 org-agenda-hide-tags-regexp))
5520 (let* ((category (or category
5521 (if (stringp org-category)
5523 (and org-category (symbol-name org-category)))
5524 (if buffer-file-name
5525 (file-name-sans-extension
5526 (file-name-nondirectory buffer-file-name))
5528 (category-icon (org-agenda-get-category-icon category))
5529 (category-icon (if category-icon
5530 (propertize " " 'display category-icon)
5532 ;; time, tag, effort are needed for the eval of the prefix format
5533 (tag (if tags (nth (1- (length tags)) tags) ""))
5535 (ts (if dotime (concat
5536 (if (stringp dotime) dotime "")
5537 (and org-agenda-search-headline-for-time txt))))
5538 (time-of-day (and dotime (org-get-time-of-day ts)))
5539 stamp plain s0 s1 s2 rtn srp l
5540 duration thecategory)
5541 (and (eq major-mode 'org-mode) buffer-file-name
5542 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5543 (when (and dotime time-of-day)
5544 ;; Extract starting and ending time and move them to prefix
5545 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5546 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5547 (setq s0 (match-string 0 ts)
5548 srp (and stamp (match-end 3))
5549 s1 (match-string (if plain 1 2) ts)
5550 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5552 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5553 ;; them, we might want to remove them there to avoid duplication.
5554 ;; The user can turn this off with a variable.
5555 (if (and org-prefix-has-time
5556 org-agenda-remove-times-when-in-prefix (or stamp plain)
5557 (string-match (concat (regexp-quote s0) " *") txt)
5558 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5559 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5560 (= (match-beginning 0) 0)
5562 (setq txt (replace-match "" nil nil txt))))
5563 ;; Normalize the time(s) to 24 hour
5564 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5565 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5567 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5568 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5570 (org-minutes-to-hh:mm-string
5571 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5573 ;; Compute the duration
5575 (setq duration (- (org-hh:mm-string-to-minutes s2)
5576 (org-hh:mm-string-to-minutes s1)))))
5578 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5580 ;; Tags are in the string
5581 (if (or (eq org-agenda-remove-tags t)
5582 (and org-agenda-remove-tags
5583 org-prefix-has-tag))
5584 (setq txt (replace-match "" t t txt))
5585 (setq txt (replace-match
5586 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5587 (match-string 2 txt))
5589 (when (eq major-mode 'org-mode)
5593 (or (get-text-property 0 'org-hd-marker txt)
5594 (get-text-property 0 'org-marker txt)))
5597 (setq neffort (org-duration-string-to-minutes effort)
5598 effort (setq effort (concat "[" effort "]")))))
5599 ;; prevent erroring out with %e format when there is no effort
5600 (or effort (setq effort ""))
5603 (while (string-match remove-re txt)
5604 (setq txt (replace-match "" t t txt))))
5606 ;; Set org-heading property on `txt' to mark the start of the
5608 (add-text-properties 0 (length txt) '(org-heading t) txt)
5610 ;; Prepare the variables needed in the eval of the compiled format
5611 (setq time (cond (s2 (concat
5612 (org-agenda-time-of-day-to-ampm-maybe s1)
5613 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5614 (if org-agenda-timegrid-use-ampm " ")))
5616 (org-agenda-time-of-day-to-ampm-maybe s1)
5617 (if org-agenda-timegrid-use-ampm
5621 extra (or (and (not habitp) extra) "")
5622 category (if (symbolp category) (symbol-name category) category)
5623 thecategory (copy-sequence category))
5624 (if (string-match org-bracket-link-regexp category)
5626 (setq l (if (match-end 3)
5627 (- (match-end 3) (match-beginning 3))
5628 (- (match-end 1) (match-beginning 1))))
5629 (when (< l (or org-prefix-category-length 0))
5630 (setq category (copy-sequence category))
5631 (org-add-props category nil
5632 'extra-space (make-string
5633 (- org-prefix-category-length l 1) ?\ ))))
5634 (if (and org-prefix-category-max-length
5635 (>= (length category) org-prefix-category-max-length))
5636 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5637 ;; Evaluate the compiled format
5638 (setq rtn (concat (eval org-prefix-format-compiled) txt))
5640 ;; And finally add the text properties
5641 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5642 (org-add-props rtn nil
5643 'org-category (if thecategory (downcase thecategory) category)
5644 'tags (mapcar 'org-downcase-keep-props tags)
5645 'org-highest-priority org-highest-priority
5646 'org-lowest-priority org-lowest-priority
5647 'time-of-day time-of-day
5650 'effort-minutes neffort
5654 'format org-prefix-format-compiled
5657 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5658 "Remove tags string from TXT, and add a modified list of tags.
5659 The modified list may contain inherited tags, and tags matched by
5660 `org-agenda-hide-tags-regexp' will be removed."
5661 (when (or add-inherited hide-re)
5662 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5663 (setq txt (substring txt 0 (match-beginning 0))))
5666 (mapcar (lambda (tg)
5667 (if (or (and hide-re (string-match hide-re tg))
5668 (and (not add-inherited)
5669 (get-text-property 0 'inherited tg)))
5674 (let ((have-i (get-text-property 0 'inherited (car tags)))
5676 (setq txt (concat txt " :"
5679 (setq i (get-text-property 0 'inherited x))
5680 (if (and have-i (not i))
5686 (if have-i "::" ":"))))))
5689 (defun org-downcase-keep-props (s)
5690 (let ((props (text-properties-at 0 s)))
5691 (setq s (downcase s))
5692 (add-text-properties 0 (length s) props s)
5695 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5696 (defvar org-agenda-sorting-strategy-selected nil)
5698 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5700 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5701 ((and todayp (member 'today (car org-agenda-time-grid))))
5702 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5703 ((member 'weekly (car org-agenda-time-grid)))
5704 (t (throw 'exit list)))
5705 (let* ((have (delq nil (mapcar
5706 (lambda (x) (get-text-property 1 'time-of-day x))
5708 (string (nth 1 org-agenda-time-grid))
5709 (gridtimes (nth 2 org-agenda-time-grid))
5710 (req (car org-agenda-time-grid))
5711 (remove (member 'remove-match req))
5713 (if (and (member 'require-timed req) (not have))
5714 ;; don't show empty grid
5716 (while (setq time (pop gridtimes))
5717 (unless (and remove (member time have))
5718 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5719 (push (org-agenda-format-item
5721 (concat (substring time 0 -2) ":" (substring time -2)))
5724 2 (length (car new)) 'face 'org-time-grid (car new))))
5725 (when (and todayp org-agenda-show-current-time-in-grid)
5726 (push (org-agenda-format-item
5728 org-agenda-current-time-string
5730 (format-time-string "%H:%M "))
5733 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5735 (if (member 'time-up org-agenda-sorting-strategy-selected)
5737 (append list new)))))
5739 (defun org-compile-prefix-format (key)
5740 "Compile the prefix format into a Lisp form that can be evaluated.
5741 The resulting form is returned and stored in the variable
5742 `org-prefix-format-compiled'."
5743 (setq org-prefix-has-time nil org-prefix-has-tag nil
5744 org-prefix-category-length nil
5745 org-prefix-has-effort nil)
5747 ((stringp org-agenda-prefix-format)
5748 org-agenda-prefix-format)
5749 ((assq key org-agenda-prefix-format)
5750 (cdr (assq key org-agenda-prefix-format)))
5751 (t " %-12:c%?-12t% s")))
5753 varform vars var e c f opt)
5754 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5756 (setq var (or (cdr (assoc (match-string 4 s)
5757 '(("c" . category) ("t" . time) ("s" . extra)
5758 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5760 c (or (match-string 3 s) "")
5761 opt (match-beginning 1)
5762 start (1+ (match-beginning 0)))
5763 (if (equal var 'time) (setq org-prefix-has-time t))
5764 (if (equal var 'tag) (setq org-prefix-has-tag t))
5765 (if (equal var 'effort) (setq org-prefix-has-effort t))
5766 (setq f (concat "%" (match-string 2 s) "s"))
5767 (when (equal var 'category)
5768 (setq org-prefix-category-length
5769 (floor (abs (string-to-number (match-string 2 s)))))
5770 (setq org-prefix-category-max-length
5771 (let ((x (match-string 2 s)))
5773 (if (string-match "\\.[0-9]+" x)
5774 (string-to-number (substring (match-string 0 x) 1)))))))
5776 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5779 `(if (equal "" ,var)
5781 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5782 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5783 (setq s (replace-match "%s" t nil s))
5784 (push varform vars))
5785 (setq vars (nreverse vars))
5786 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5788 (defun org-set-sorting-strategy (key)
5789 (if (symbolp (car org-agenda-sorting-strategy))
5791 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5792 (setq org-agenda-sorting-strategy-selected
5793 (or (cdr (assq key org-agenda-sorting-strategy))
5794 (cdr (assq 'agenda org-agenda-sorting-strategy))
5795 '(time-up category-keep priority-down)))))
5797 (defun org-get-time-of-day (s &optional string mod24)
5798 "Check string S for a time of day.
5799 If found, return it as a military time number between 0 and 2400.
5800 If not found, return nil.
5801 The optional STRING argument forces conversion into a 5 character wide string
5805 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5806 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5807 (let* ((h (string-to-number (match-string 1 s)))
5808 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5809 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5810 (am-p (equal ampm "am"))
5811 (h1 (cond ((not ampm) h)
5812 ((= h 12) (if am-p 0 12))
5813 (t (+ h (if am-p 0 12)))))
5814 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5816 (t0 (+ (* 100 h2) m))
5817 (t1 (concat (if (>= h1 24) "+" " ")
5818 (if (and org-agenda-time-leading-zero
5819 (< t0 1000)) "0" "")
5820 (if (< t0 100) "0" "")
5821 (if (< t0 10) "0" "")
5822 (int-to-string t0))))
5823 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5825 (defvar org-agenda-before-sorting-filter-function nil
5826 "Function to be applied to agenda items prior to sorting.
5827 Prior to sorting also means just before they are inserted into the agenda.
5829 To aid sorting, you may revisit the original entries and add more text
5830 properties which will later be used by the sorting functions.
5832 The function should take a string argument, an agenda line.
5833 It has access to the text properties in that line, which contain among
5834 other things, the property `org-hd-marker' that points to the entry
5835 where the line comes from. Note that not all lines going into the agenda
5836 have this property, only most.
5838 The function should return the modified string. It is probably best
5839 to ONLY change text properties.
5841 You can also use this function as a filter, by returning nil for lines
5842 you don't want to have in the agenda at all. For this application, you
5843 could bind the variable in the options section of a custom command.")
5845 (defun org-finalize-agenda-entries (list &optional nosort)
5846 "Sort and concatenate the agenda items."
5847 (setq list (mapcar 'org-agenda-highlight-todo list))
5850 (when org-agenda-before-sorting-filter-function
5851 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5852 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5854 (defun org-agenda-highlight-todo (x)
5855 (let ((org-done-keywords org-done-keywords-for-agenda)
5856 (case-fold-search nil)
5860 (beginning-of-line 1)
5861 (setq re (org-get-at-bol 'org-todo-regexp))
5862 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
5863 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5864 (add-text-properties (match-beginning 0) (match-end 1)
5865 (list 'face (org-get-todo-face 1)))
5866 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5867 (delete-region (match-beginning 1) (1- (match-end 0)))
5868 (goto-char (match-beginning 1))
5869 (insert (format org-agenda-todo-keyword-format s)))))
5870 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
5871 (setq re (get-text-property 0 'org-todo-regexp x))
5873 ;; Test `pl' because if there's no heading content,
5874 ;; there's no point matching to highlight. Note
5875 ;; that if we didn't test `pl' first, and there
5876 ;; happened to be no keyword from `org-todo-regexp'
5877 ;; on this heading line, then the `equal' comparison
5878 ;; afterwards would spuriously succeed in the case
5879 ;; where `pl' is nil -- causing an args-out-of-range
5880 ;; error when we try to add text properties to text
5881 ;; that isn't there.
5883 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5885 (add-text-properties
5886 (or (match-end 1) (match-end 0)) (match-end 0)
5887 (list 'face (org-get-todo-face (match-string 2 x)))
5890 (setq x (concat (substring x 0 (match-end 1))
5891 (format org-agenda-todo-keyword-format
5893 (org-add-props " " (text-properties-at 0 x))
5894 (substring x (match-end 3)))))))
5897 (defsubst org-cmp-priority (a b)
5898 "Compare the priorities of string A and B."
5899 (let ((pa (or (get-text-property 1 'priority a) 0))
5900 (pb (or (get-text-property 1 'priority b) 0)))
5901 (cond ((> pa pb) +1)
5905 (defsubst org-cmp-effort (a b)
5906 "Compare the effort values of string A and B."
5907 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5908 (ea (or (get-text-property 1 'effort-minutes a) def))
5909 (eb (or (get-text-property 1 'effort-minutes b) def)))
5910 (cond ((> ea eb) +1)
5914 (defsubst org-cmp-category (a b)
5915 "Compare the string values of categories of strings A and B."
5916 (let ((ca (or (get-text-property 1 'org-category a) ""))
5917 (cb (or (get-text-property 1 'org-category b) "")))
5918 (cond ((string-lessp ca cb) -1)
5919 ((string-lessp cb ca) +1)
5922 (defsubst org-cmp-todo-state (a b)
5923 "Compare the todo states of strings A and B."
5924 (let* ((ma (or (get-text-property 1 'org-marker a)
5925 (get-text-property 1 'org-hd-marker a)))
5926 (mb (or (get-text-property 1 'org-marker b)
5927 (get-text-property 1 'org-hd-marker b)))
5928 (fa (and ma (marker-buffer ma)))
5929 (fb (and mb (marker-buffer mb)))
5931 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5932 (and fb (with-current-buffer fb org-todo-keywords-1))))
5933 (ta (or (get-text-property 1 'todo-state a) ""))
5934 (tb (or (get-text-property 1 'todo-state b) ""))
5935 (la (- (length (member ta todo-kwds))))
5936 (lb (- (length (member tb todo-kwds))))
5937 (donepa (member ta org-done-keywords-for-agenda))
5938 (donepb (member tb org-done-keywords-for-agenda)))
5939 (cond ((and donepa (not donepb)) -1)
5940 ((and (not donepa) donepb) +1)
5945 (defsubst org-cmp-alpha (a b)
5946 "Compare the headlines, alphabetically."
5947 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
5948 (plb (text-property-any 0 (length b) 'org-heading t b))
5949 (ta (and pla (substring a pla)))
5950 (tb (and plb (substring b plb))))
5952 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5953 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5954 (setq ta (substring ta (match-end 0))))
5955 (setq ta (downcase ta)))
5957 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5958 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5959 (setq tb (substring tb (match-end 0))))
5960 (setq tb (downcase tb)))
5963 ((string-lessp ta tb) -1)
5964 ((string-lessp tb ta) +1)
5967 (defsubst org-cmp-tag (a b)
5968 "Compare the string values of the first tags of A and B."
5969 (let ((ta (car (last (get-text-property 1 'tags a))))
5970 (tb (car (last (get-text-property 1 'tags b)))))
5973 ((string-lessp ta tb) -1)
5974 ((string-lessp tb ta) +1)
5977 (defsubst org-cmp-time (a b)
5978 "Compare the time-of-day values of strings A and B."
5979 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5980 (ta (or (get-text-property 1 'time-of-day a) def))
5981 (tb (or (get-text-property 1 'time-of-day b) def)))
5982 (cond ((< ta tb) -1)
5986 (defsubst org-cmp-habit-p (a b)
5987 "Compare the todo states of strings A and B."
5988 (let ((ha (get-text-property 1 'org-habit-p a))
5989 (hb (get-text-property 1 'org-habit-p b)))
5990 (cond ((and ha (not hb)) -1)
5991 ((and (not ha) hb) +1)
5994 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5996 (defun org-entries-lessp (a b)
5997 "Predicate for sorting agenda entries."
5998 ;; The following variables will be used when the form is evaluated.
5999 ;; So even though the compiler complains, keep them.
6000 (let* ((ss org-agenda-sorting-strategy-selected)
6001 (time-up (and (org-em 'time-up 'time-down ss)
6002 (org-cmp-time a b)))
6003 (time-down (if time-up (- time-up) nil))
6004 (priority-up (and (org-em 'priority-up 'priority-down ss)
6005 (org-cmp-priority a b)))
6006 (priority-down (if priority-up (- priority-up) nil))
6007 (effort-up (and (org-em 'effort-up 'effort-down ss)
6008 (org-cmp-effort a b)))
6009 (effort-down (if effort-up (- effort-up) nil))
6010 (category-up (and (or (org-em 'category-up 'category-down ss)
6011 (memq 'category-keep ss))
6012 (org-cmp-category a b)))
6013 (category-down (if category-up (- category-up) nil))
6014 (category-keep (if category-up +1 nil))
6015 (tag-up (and (org-em 'tag-up 'tag-down ss)
6017 (tag-down (if tag-up (- tag-up) nil))
6018 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6019 (org-cmp-todo-state a b)))
6020 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6021 (habit-up (and (org-em 'habit-up 'habit-down ss)
6022 (org-cmp-habit-p a b)))
6023 (habit-down (if habit-up (- habit-up) nil))
6024 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6025 (org-cmp-alpha a b)))
6026 (alpha-down (if alpha-up (- alpha-up) nil))
6027 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6028 user-defined-up user-defined-down)
6029 (if (and need-user-cmp org-agenda-cmp-user-defined
6030 (functionp org-agenda-cmp-user-defined))
6031 (setq user-defined-up
6032 (funcall org-agenda-cmp-user-defined a b)
6033 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6035 (eval (cons 'or org-agenda-sorting-strategy-selected))
6036 '((-1 . t) (1 . nil) (nil . nil))))))
6038 ;;; Agenda restriction lock
6040 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6041 "Overlay to mark the headline to which agenda commands are restricted.")
6042 (overlay-put org-agenda-restriction-lock-overlay
6043 'face 'org-agenda-restriction-lock)
6044 (overlay-put org-agenda-restriction-lock-overlay
6045 'help-echo "Agendas are currently limited to this subtree.")
6046 (org-detach-overlay org-agenda-restriction-lock-overlay)
6048 (defun org-agenda-set-restriction-lock (&optional type)
6049 "Set restriction lock for agenda, to current subtree or file.
6050 Restriction will be the file if TYPE is `file', or if type is the
6051 universal prefix '(4), or if the cursor is before the first headline
6052 in the file. Otherwise, restriction will be to the current subtree."
6054 (and (equal type '(4)) (setq type 'file))
6057 ((org-at-heading-p) 'subtree)
6058 ((condition-case nil (org-back-to-heading t) (error nil))
6061 (if (eq type 'subtree)
6063 (setq org-agenda-restrict t)
6064 (setq org-agenda-overriding-restriction 'subtree)
6065 (put 'org-agenda-files 'org-restrict
6066 (list (buffer-file-name (buffer-base-buffer))))
6067 (org-back-to-heading t)
6068 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6069 (move-marker org-agenda-restrict-begin (point))
6070 (move-marker org-agenda-restrict-end
6071 (save-excursion (org-end-of-subtree t)))
6072 (message "Locking agenda restriction to subtree"))
6073 (put 'org-agenda-files 'org-restrict
6074 (list (buffer-file-name (buffer-base-buffer))))
6075 (setq org-agenda-restrict nil)
6076 (setq org-agenda-overriding-restriction 'file)
6077 (move-marker org-agenda-restrict-begin nil)
6078 (move-marker org-agenda-restrict-end nil)
6079 (message "Locking agenda restriction to file"))
6080 (setq current-prefix-arg nil)
6081 (org-agenda-maybe-redo))
6083 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6084 "Remove the agenda restriction lock."
6086 (org-detach-overlay org-agenda-restriction-lock-overlay)
6087 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6088 (setq org-agenda-overriding-restriction nil)
6089 (setq org-agenda-restrict nil)
6090 (put 'org-agenda-files 'org-restrict nil)
6091 (move-marker org-agenda-restrict-begin nil)
6092 (move-marker org-agenda-restrict-end nil)
6093 (setq current-prefix-arg nil)
6094 (message "Agenda restriction lock removed")
6095 (or noupdate (org-agenda-maybe-redo)))
6097 (defun org-agenda-maybe-redo ()
6098 "If there is any window showing the agenda view, update it."
6099 (let ((w (get-buffer-window org-agenda-buffer-name t))
6100 (w0 (selected-window)))
6105 (if org-agenda-overriding-restriction
6106 (message "Agenda view shifted to new %s restriction"
6107 org-agenda-overriding-restriction)
6108 (message "Agenda restriction lock removed")))))
6112 (defun org-agenda-check-type (error &rest types)
6113 "Check if agenda buffer is of allowed type.
6114 If ERROR is non-nil, throw an error, otherwise just return nil."
6115 (if (memq org-agenda-type types)
6118 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6121 (defun org-agenda-quit ()
6122 "Exit agenda by removing the window or the buffer."
6124 (if org-agenda-columns-active
6126 (let ((buf (current-buffer)))
6127 (if (eq org-agenda-window-setup 'other-frame)
6130 (org-agenda-reset-markers)
6131 (org-columns-remove-overlays)
6132 (setq org-agenda-archives-mode nil)
6134 (and (not (eq org-agenda-window-setup 'current-window))
6135 (not (one-window-p))
6138 (org-agenda-reset-markers)
6139 (org-columns-remove-overlays)
6140 (setq org-agenda-archives-mode nil)))
6141 ;; Maybe restore the pre-agenda window configuration.
6142 (and org-agenda-restore-windows-after-quit
6143 (not (eq org-agenda-window-setup 'other-frame))
6144 org-pre-agenda-window-conf
6145 (set-window-configuration org-pre-agenda-window-conf))))
6147 (defun org-agenda-exit ()
6148 "Exit agenda by removing the window or the buffer.
6149 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6150 Org-mode buffers visited directly by the user will not be touched."
6152 (org-release-buffers org-agenda-new-buffers)
6153 (setq org-agenda-new-buffers nil)
6156 (defun org-agenda-execute (arg)
6157 "Execute another agenda command, keeping same window.
6158 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6161 (let ((org-agenda-window-setup 'current-window))
6164 (defun org-agenda-redo ()
6166 When this is the global TODO list, a prefix argument will be interpreted."
6168 (let* ((org-agenda-keep-modes t)
6169 (tag-filter org-agenda-tag-filter)
6170 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6171 (cat-filter org-agenda-category-filter)
6172 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6173 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6174 (cols org-agenda-columns-active)
6175 (line (org-current-line))
6176 (window-line (- line (org-current-line (window-start))))
6177 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6178 (put 'org-agenda-tag-filter :preset-filter nil)
6179 (put 'org-agenda-category-filter :preset-filter nil)
6180 (and cols (org-columns-quit))
6181 (message "Rebuilding agenda buffer...")
6182 (org-let lprops '(eval org-agenda-redo-command))
6183 (setq org-agenda-undo-list nil
6184 org-agenda-pending-undo-list nil)
6185 (message "Rebuilding agenda buffer...done")
6186 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6187 (put 'org-agenda-category-filter :preset-filter cat-preset)
6188 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6189 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6190 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6191 (org-goto-line line)
6192 (recenter window-line)))
6194 (defvar org-global-tags-completion-table nil)
6195 (defvar org-agenda-filter-form nil)
6196 (defvar org-agenda-filtered-by-category nil)
6198 (defun org-agenda-filter-by-category (strip)
6199 "Keep only those lines in the agenda buffer that have a specific category.
6200 The category is that of the current line."
6202 (if org-agenda-filtered-by-category
6203 (org-agenda-filter-show-all-cat)
6204 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6205 (if cat (org-agenda-filter-apply
6206 (list (concat (if strip "-" "+") cat)) 'category)
6207 (error "No category at point")))))
6209 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6210 "Keep only those lines in the agenda buffer that have a specific tag.
6211 The tag is selected with its fast selection letter, as configured.
6212 With prefix argument STRIP, remove all lines that do have the tag.
6213 A lisp caller can specify CHAR. NARROW means that the new tag should be
6214 used to narrow the search - the interactive user can also press `-' or `+'
6215 to switch to narrowing."
6217 (let* ((alist org-tag-alist-for-agenda)
6218 (tag-chars (mapconcat
6219 (lambda (x) (if (and (not (symbolp (car x)))
6221 (char-to-string (cdr x))
6224 (efforts (org-split-string
6225 (or (cdr (assoc (concat org-effort-property "_ALL")
6226 org-global-properties))
6227 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6229 (effort-op org-agenda-filter-effort-default-operator)
6231 (inhibit-read-only t)
6232 (current org-agenda-tag-filter)
6233 maybe-refresh a n tag)
6236 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6237 (if narrow "Narrow" "Filter") tag-chars
6238 (if org-agenda-auto-exclude-function "[RET], " ""))
6239 (setq char (read-char-exclusive)))
6240 (when (member char '(?+ ?-))
6242 (cond ((equal char ?-) (setq strip t narrow t))
6243 ((equal char ?+) (setq strip nil narrow t)))
6245 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6246 (setq char (read-char-exclusive)))
6247 (when (member char '(?< ?> ?= ??))
6248 ;; An effort operator
6249 (setq effort-op (char-to-string char))
6250 (setq alist nil) ; to make sure it will be interpreted as effort.
6251 (unless (equal char ??)
6252 (loop for i from 0 to 9 do
6256 (if (= i 9) "0" (int-to-string (1+ i)))
6257 "]" (nth i efforts))))
6258 (message "Effort%s: %s " effort-op effort-prompt)
6259 (setq char (read-char-exclusive))
6260 (when (or (< char ?0) (> char ?9))
6261 (error "Need 1-9,0 to select effort" ))))
6262 (when (equal char ?\t)
6263 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6264 (org-set-local 'org-global-tags-completion-table
6265 (org-global-tags-completion-table)))
6266 (let ((completion-ignore-case t))
6267 (setq tag (org-icompleting-read
6268 "Tag: " org-global-tags-completion-table))))
6271 (org-agenda-filter-show-all-tag)
6272 (when org-agenda-auto-exclude-function
6273 (setq org-agenda-tag-filter '())
6274 (dolist (tag (org-agenda-get-represented-tags))
6275 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6277 (push modifier org-agenda-tag-filter))))
6278 (if (not (null org-agenda-tag-filter))
6279 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6280 (setq maybe-refresh t))
6282 (org-agenda-filter-show-all-tag)
6283 (when (get 'org-agenda-tag-filter :preset-filter)
6284 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6285 (setq maybe-refresh t))
6287 (setq org-agenda-tag-filter
6288 (mapcar (lambda(tag) (concat "+" tag))
6289 (org-get-at-bol 'tags)))
6290 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6291 (setq maybe-refresh t))
6292 ((or (equal char ?\ )
6293 (setq a (rassoc char alist))
6294 (and (>= char ?0) (<= char ?9)
6295 (setq n (if (= char ?0) 9 (- char ?0 1))
6296 tag (concat effort-op (nth n efforts))
6301 (and tag (setq a (cons tag nil))))
6302 (org-agenda-filter-show-all-tag)
6304 (setq org-agenda-tag-filter
6305 (cons (concat (if strip "-" "+") tag)
6306 (if narrow current nil)))
6307 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6308 (setq maybe-refresh t))
6309 (t (error "Invalid tag selection character %c" char)))
6310 (when (and maybe-refresh
6311 (eq org-agenda-clockreport-mode 'with-filter))
6312 (org-agenda-redo))))
6314 (defun org-agenda-get-represented-tags ()
6315 "Get a list of all tags currently represented in the agenda."
6318 (goto-char (point-min))
6319 (while (setq p (next-single-property-change (point) 'tags))
6321 (mapc (lambda (x) (add-to-list 'tags x))
6322 (get-text-property (point) 'tags))))
6325 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6326 "Refine the current filter. See `org-agenda-filter-by-tag'."
6328 (org-agenda-filter-by-tag strip char 'refine))
6330 (defun org-agenda-filter-make-matcher ()
6331 "Create the form that tests a line for agenda filter."
6333 ;; first compute the tag-filter matcher
6334 (dolist (x (delete-dups
6335 (append (get 'org-agenda-tag-filter
6336 :preset-filter) org-agenda-tag-filter)))
6337 (if (member x '("-" "+"))
6338 (setq f1 (if (equal x "-") 'tags '(not tags)))
6339 (if (string-match "[<=>?]" x)
6340 (setq f1 (org-agenda-filter-effort-form x))
6341 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6342 (if (equal (string-to-char x) ?-)
6343 (setq f1 (list 'not f1))))
6345 ;; then compute the category-filter matcher
6346 (dolist (x (delete-dups
6347 (append (get 'org-agenda-category-filter
6348 :preset-filter) org-agenda-category-filter)))
6349 (setq f1 (list 'equal (substring x 1) 'cat))
6351 (cons 'and (nreverse f))))
6353 (defun org-agenda-filter-effort-form (e)
6354 "Return the form to compare the effort of the current line with what E says.
6355 E looks like \"+<2:25\"."
6357 (setq e (substring e 1))
6358 (setq op (string-to-char e) e (substring e 1))
6359 (setq op (cond ((equal op ?<) '<=)
6363 (list 'org-agenda-compare-effort (list 'quote op)
6364 (org-duration-string-to-minutes e))))
6366 (defun org-agenda-compare-effort (op value)
6367 "Compare the effort of the current line with VALUE, using OP.
6368 If the line does not have an effort defined, return nil."
6369 (let ((eff (org-get-at-bol 'effort-minutes)))
6372 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6375 (defun org-agenda-filter-apply (filter type)
6376 "Set FILTER as the new agenda filter and apply it."
6379 (setq org-agenda-tag-filter filter)
6380 (setq org-agenda-category-filter filter
6381 org-agenda-filtered-by-category t))
6382 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6383 (org-agenda-set-mode-name)
6385 (goto-char (point-min))
6387 (if (org-get-at-bol 'org-marker)
6389 (setq tags (org-get-at-bol 'tags) ; used in eval
6390 cat (get-text-property (point) 'org-category))
6391 (if (not (eval org-agenda-filter-form))
6392 (org-agenda-filter-hide-line type))
6393 (beginning-of-line 2))
6394 (beginning-of-line 2))))
6395 (if (get-char-property (point) 'invisible)
6396 (org-agenda-previous-line))))
6398 (defun org-agenda-filter-hide-line (type)
6400 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6402 (overlay-put ov 'invisible t)
6403 (overlay-put ov 'type type)
6405 (push ov org-agenda-tag-filter-overlays)
6406 (push ov org-agenda-cat-filter-overlays))))
6408 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6409 (setq pos (or pos (point)))
6411 (dolist (ov (overlays-at pos))
6412 (when (and (overlay-get ov 'invisible)
6413 (eq (overlay-get ov 'type) 'tag))
6415 (if (< (overlay-start ov) (point-at-eol))
6416 (move-overlay ov (point-at-eol)
6417 (overlay-end ov)))))))
6419 (defun org-agenda-filter-show-all-tag nil
6420 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6421 (setq org-agenda-tag-filter-overlays nil
6422 org-agenda-tag-filter nil
6423 org-agenda-filter-form nil)
6424 (org-agenda-set-mode-name))
6426 (defun org-agenda-filter-show-all-cat nil
6427 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6428 (setq org-agenda-cat-filter-overlays nil
6429 org-agenda-filtered-by-category nil
6430 org-agenda-category-filter nil
6431 org-agenda-filter-form nil)
6432 (org-agenda-set-mode-name))
6434 (defun org-agenda-manipulate-query-add ()
6435 "Manipulate the query by adding a search term with positive selection.
6436 Positive selection means the term must be matched for selection of an entry."
6438 (org-agenda-manipulate-query ?\[))
6439 (defun org-agenda-manipulate-query-subtract ()
6440 "Manipulate the query by adding a search term with negative selection.
6441 Negative selection means term must not be matched for selection of an entry."
6443 (org-agenda-manipulate-query ?\]))
6444 (defun org-agenda-manipulate-query-add-re ()
6445 "Manipulate the query by adding a search regexp with positive selection.
6446 Positive selection means the regexp must match for selection of an entry."
6448 (org-agenda-manipulate-query ?\{))
6449 (defun org-agenda-manipulate-query-subtract-re ()
6450 "Manipulate the query by adding a search regexp with negative selection.
6451 Negative selection means regexp must not match for selection of an entry."
6453 (org-agenda-manipulate-query ?\}))
6454 (defun org-agenda-manipulate-query (char)
6456 ((memq org-agenda-type '(timeline agenda))
6457 (let ((org-agenda-include-inactive-timestamps t))
6459 (message "Display now includes inactive timestamps as well"))
6460 ((eq org-agenda-type 'search)
6462 'org-agenda-query-string
6463 (if org-agenda-last-search-view-search-was-boolean
6464 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6465 (?\{ . " +{}") (?\} . " -{}"))))
6467 (setq org-agenda-redo-command
6468 (list 'org-search-view
6470 org-agenda-query-string
6471 (+ (length org-agenda-query-string)
6472 (if (member char '(?\{ ?\})) 0 1))))
6473 (set-register org-agenda-query-register org-agenda-query-string)
6475 (t (error "Cannot manipulate query for %s-type agenda buffers"
6478 (defun org-add-to-string (var string)
6479 (set var (concat (symbol-value var) string)))
6481 (defun org-agenda-goto-date (date)
6482 "Jump to DATE in agenda."
6483 (interactive (list (let ((org-read-date-prefer-future
6484 (eval org-agenda-jump-prefer-future)))
6486 (org-agenda-list nil date))
6488 (defun org-agenda-goto-today ()
6491 (org-agenda-check-type t 'timeline 'agenda)
6492 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6494 (tdpos (goto-char tdpos))
6495 ((eq org-agenda-type 'agenda)
6496 (let* ((sd (org-agenda-compute-starting-span
6497 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6498 (org-agenda-overriding-arguments org-agenda-last-arguments))
6499 (setf (nth 1 org-agenda-overriding-arguments) sd)
6501 (org-agenda-find-same-or-today-or-agenda)))
6502 (t (error "Cannot find today")))))
6504 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6506 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6507 (text-property-any (point-min) (point-max) 'org-today t)
6508 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6511 (defun org-agenda-later (arg)
6512 "Go forward in time by thee current span.
6513 With prefix ARG, go forward that many times the current span."
6515 (org-agenda-check-type t 'agenda)
6516 (let* ((span org-agenda-current-span)
6517 (sd org-starting-day)
6518 (greg (calendar-gregorian-from-absolute sd))
6519 (cnt (org-get-at-bol 'org-day-cnt))
6523 (setq sd (+ arg sd)))
6525 (setq sd (+ (* 7 arg) sd)))
6527 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6528 sd (calendar-absolute-from-gregorian greg2))
6529 (setcar greg2 (1+ (car greg2))))
6531 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6532 sd (calendar-absolute-from-gregorian greg2))
6533 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6535 (setq sd (+ (* span arg) sd))))
6536 (let ((org-agenda-overriding-arguments
6537 (list (car org-agenda-last-arguments) sd span t)))
6539 (org-agenda-find-same-or-today-or-agenda cnt))))
6541 (defun org-agenda-earlier (arg)
6542 "Go backward in time by the current span.
6543 With prefix ARG, go backward that many times the current span."
6545 (org-agenda-later (- arg)))
6547 (defun org-agenda-view-mode-dispatch ()
6548 "Call one of the view mode commands."
6550 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6551 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6552 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6554 (let ((a (read-char-exclusive)))
6556 (?\ (call-interactively 'org-agenda-reset-view))
6557 (?d (call-interactively 'org-agenda-day-view))
6558 (?w (call-interactively 'org-agenda-week-view))
6559 (?m (call-interactively 'org-agenda-month-view))
6560 (?y (call-interactively 'org-agenda-year-view))
6561 (?l (call-interactively 'org-agenda-log-mode))
6562 (?L (org-agenda-log-mode '(4)))
6563 (?c (org-agenda-log-mode 'clockcheck))
6564 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6565 (?a (call-interactively 'org-agenda-archives-mode))
6566 (?A (org-agenda-archives-mode 'files))
6567 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6568 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6569 (?G (call-interactively 'org-agenda-toggle-time-grid))
6570 (?D (call-interactively 'org-agenda-toggle-diary))
6571 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6572 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6573 (org-agenda-check-type t 'timeline 'agenda)
6575 (message "Display now includes inactive timestamps as well"))
6576 (?q (message "Abort"))
6577 (otherwise (error "Invalid key" )))))
6579 (defun org-agenda-reset-view ()
6580 "Switch to default view for agenda."
6582 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6583 (defun org-agenda-day-view (&optional day-of-year)
6584 "Switch to daily view for agenda.
6585 With argument DAY-OF-YEAR, switch to that day of the year."
6587 (org-agenda-change-time-span 'day day-of-year))
6588 (defun org-agenda-week-view (&optional iso-week)
6589 "Switch to daily view for agenda.
6590 With argument ISO-WEEK, switch to the corresponding ISO week.
6591 If ISO-WEEK has more then 2 digits, only the last two encode the
6592 week. Any digits before this encode a year. So 200712 means
6593 week 12 of year 2007. Years in the range 1938-2037 can also be
6594 written as 2-digit years."
6596 (org-agenda-change-time-span 'week iso-week))
6597 (defun org-agenda-month-view (&optional month)
6598 "Switch to monthly view for agenda.
6599 With argument MONTH, switch to that month."
6601 (org-agenda-change-time-span 'month month))
6602 (defun org-agenda-year-view (&optional year)
6603 "Switch to yearly view for agenda.
6604 With argument YEAR, switch to that year.
6605 If MONTH has more then 2 digits, only the last two encode the
6606 month. Any digits before this encode a year. So 200712 means
6607 December year 2007. Years in the range 1938-2037 can also be
6608 written as 2-digit years."
6611 (setq year (org-small-year-to-year year)))
6612 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6613 (org-agenda-change-time-span 'year year)
6616 (defun org-agenda-change-time-span (span &optional n)
6617 "Change the agenda view to SPAN.
6618 SPAN may be `day', `week', `month', `year'."
6619 (org-agenda-check-type t 'agenda)
6620 (if (and (not n) (equal org-agenda-current-span span))
6621 (error "Viewing span is already \"%s\"" span))
6622 (let* ((sd (or (org-get-at-bol 'day)
6624 (sd (org-agenda-compute-starting-span sd span n))
6625 (org-agenda-overriding-arguments
6626 (or org-agenda-overriding-arguments
6627 (list (car org-agenda-last-arguments) sd span t))))
6629 (org-agenda-find-same-or-today-or-agenda))
6630 (org-agenda-set-mode-name)
6631 (message "Switched to %s view" span))
6633 (defun org-agenda-compute-starting-span (sd span &optional n)
6634 "Compute starting date for agenda.
6635 SPAN may be `day', `week', `month', `year'. The return value
6636 is a cons cell with the starting date and the number of days,
6637 so that the date SD will be in that range."
6638 (let* ((greg (calendar-gregorian-from-absolute sd))
6645 (setq sd (+ (calendar-absolute-from-gregorian
6649 (let* ((nt (calendar-day-of-week
6650 (calendar-gregorian-from-absolute sd)))
6651 (d (if org-agenda-start-on-weekday
6652 (- nt org-agenda-start-on-weekday)
6655 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6659 (setq y1 (org-small-year-to-year (/ n 100))
6662 (calendar-absolute-from-iso
6664 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6667 (when (and n (> n 99))
6668 (setq y1 (org-small-year-to-year (/ n 100))
6670 (setq sd (calendar-absolute-from-gregorian
6671 (list (or n mg) 1 (or y1 yg))))))
6673 (setq sd (calendar-absolute-from-gregorian
6674 (list 1 1 (or n yg))))))
6677 (defun org-agenda-next-date-line (&optional arg)
6678 "Jump to the next line indicating a date in agenda buffer."
6680 (org-agenda-check-type t 'agenda 'timeline)
6681 (beginning-of-line 1)
6682 ;; This does not work if user makes date format that starts with a blank
6683 (if (looking-at "^\\S-") (forward-char 1))
6684 (if (not (re-search-forward "^\\S-" nil t arg))
6687 (error "No next date after this line in this buffer")))
6688 (goto-char (match-beginning 0)))
6690 (defun org-agenda-previous-date-line (&optional arg)
6691 "Jump to the previous line indicating a date in agenda buffer."
6693 (org-agenda-check-type t 'agenda 'timeline)
6694 (beginning-of-line 1)
6695 (if (not (re-search-backward "^\\S-" nil t arg))
6696 (error "No previous date before this line in this buffer")))
6698 ;; Initialize the highlight
6699 (defvar org-hl (make-overlay 1 1))
6700 (overlay-put org-hl 'face 'highlight)
6702 (defun org-highlight (begin end &optional buffer)
6703 "Highlight a region with overlay."
6704 (move-overlay org-hl begin end (or buffer (current-buffer))))
6706 (defun org-unhighlight ()
6707 "Detach overlay INDEX."
6708 (org-detach-overlay org-hl))
6710 ;; FIXME this is currently not used.
6711 (defun org-highlight-until-next-command (beg end &optional buffer)
6712 "Move the highlight overlay to BEG/END, remove it before the next command."
6713 (org-highlight beg end buffer)
6714 (add-hook 'pre-command-hook 'org-unhighlight-once))
6715 (defun org-unhighlight-once ()
6716 "Remove the highlight from its position, and this function from the hook."
6717 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6720 (defun org-agenda-follow-mode ()
6721 "Toggle follow mode in an agenda buffer."
6723 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6724 (org-agenda-set-mode-name)
6725 (org-agenda-do-context-action)
6726 (message "Follow mode is %s"
6727 (if org-agenda-follow-mode "on" "off")))
6729 (defun org-agenda-entry-text-mode (&optional arg)
6730 "Toggle entry text mode in an agenda buffer."
6732 (setq org-agenda-entry-text-mode (or (integerp arg)
6733 (not org-agenda-entry-text-mode)))
6734 (org-agenda-entry-text-hide)
6735 (and org-agenda-entry-text-mode
6736 (let ((org-agenda-entry-text-maxlines
6737 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6738 (org-agenda-entry-text-show)))
6739 (org-agenda-set-mode-name)
6740 (message "Entry text mode is %s. Maximum number of lines is %d"
6741 (if org-agenda-entry-text-mode "on" "off")
6742 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6744 (defun org-agenda-clockreport-mode (&optional with-filter)
6745 "Toggle clocktable mode in an agenda buffer.
6746 With prefix arg WITH-FILTER, make the clocktable respect the current
6749 (org-agenda-check-type t 'agenda)
6751 (setq org-agenda-clockreport-mode 'with-filter)
6752 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6753 (org-agenda-set-mode-name)
6755 (message "Clocktable mode is %s"
6756 (if org-agenda-clockreport-mode "on" "off")))
6758 (defun org-agenda-log-mode (&optional special)
6759 "Toggle log mode in an agenda buffer.
6760 With argument SPECIAL, show all possible log items, not only the ones
6761 configured in `org-agenda-log-mode-items'.
6762 With a double `C-u' prefix arg, show *only* log items, nothing else."
6764 (org-agenda-check-type t 'agenda 'timeline)
6765 (setq org-agenda-show-log
6767 ((equal special '(16)) 'only)
6768 ((eq special 'clockcheck)
6769 (if (eq org-agenda-show-log 'clockcheck)
6771 (special '(closed clock state))
6772 (t (not org-agenda-show-log))))
6773 (org-agenda-set-mode-name)
6775 (message "Log mode is %s"
6776 (if org-agenda-show-log "on" "off")))
6778 (defun org-agenda-archives-mode (&optional with-files)
6779 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6780 When called with a prefix argument, include all archive files as well."
6782 (setq org-agenda-archives-mode
6783 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6784 (org-agenda-set-mode-name)
6789 ((eq org-agenda-archives-mode nil)
6790 "No archives are included")
6791 ((eq org-agenda-archives-mode 'trees)
6792 (format "Trees with :%s: tag are included" org-archive-tag))
6793 ((eq org-agenda-archives-mode t)
6794 (format "Trees with :%s: tag and all active archive files are included"
6795 org-archive-tag)))))
6797 (defun org-agenda-toggle-diary ()
6798 "Toggle diary inclusion in an agenda buffer."
6800 (org-agenda-check-type t 'agenda)
6801 (setq org-agenda-include-diary (not org-agenda-include-diary))
6803 (org-agenda-set-mode-name)
6804 (message "Diary inclusion turned %s"
6805 (if org-agenda-include-diary "on" "off")))
6807 (defun org-agenda-toggle-deadlines ()
6808 "Toggle inclusion of entries with a deadline in an agenda buffer."
6810 (org-agenda-check-type t 'agenda)
6811 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6813 (org-agenda-set-mode-name)
6814 (message "Deadlines inclusion turned %s"
6815 (if org-agenda-include-deadlines "on" "off")))
6817 (defun org-agenda-toggle-time-grid ()
6818 "Toggle time grid in an agenda buffer."
6820 (org-agenda-check-type t 'agenda)
6821 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6823 (org-agenda-set-mode-name)
6824 (message "Time-grid turned %s"
6825 (if org-agenda-use-time-grid "on" "off")))
6827 (defun org-agenda-set-mode-name ()
6828 "Set the mode name to indicate all the small mode settings."
6831 (if (get 'org-agenda-files 'org-restrict) " []" "")
6833 '(:eval (org-agenda-span-name org-agenda-current-span))
6834 (if org-agenda-follow-mode " Follow" "")
6835 (if org-agenda-entry-text-mode " ETxt" "")
6836 (if org-agenda-include-diary " Diary" "")
6837 (if org-agenda-include-deadlines " Ddl" "")
6838 (if org-agenda-use-time-grid " Grid" "")
6839 (if (and (boundp 'org-habit-show-habits)
6840 org-habit-show-habits) " Habit" "")
6842 ((consp org-agenda-show-log) " LogAll")
6843 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
6844 (org-agenda-show-log " Log")
6846 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
6848 '(:eval (org-propertize
6853 (get 'org-agenda-category-filter :preset-filter)
6854 org-agenda-category-filter)
6857 'face 'org-agenda-filter-category
6858 'help-echo "Category used in filtering"))
6860 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
6862 '(:eval (org-propertize
6867 (get 'org-agenda-tag-filter :preset-filter)
6868 org-agenda-tag-filter)
6871 'face 'org-agenda-filter-tags
6872 'help-echo "Tags used in filtering"))
6874 (if org-agenda-archives-mode
6875 (if (eq org-agenda-archives-mode t)
6877 (format " :%s:" org-archive-tag))
6879 (if org-agenda-clockreport-mode
6880 (if (eq org-agenda-clockreport-mode 'with-filter)
6881 " Clock{}" " Clock")
6883 (force-mode-line-update))
6885 (defun org-agenda-post-command-hook ()
6886 (setq org-agenda-type
6887 (or (get-text-property (point) 'org-agenda-type)
6888 (get-text-property (max (point-min) (1- (point)))
6889 'org-agenda-type))))
6891 (defun org-agenda-next-line ()
6892 "Move cursor to the next line, and show if follow mode is active."
6894 (call-interactively 'next-line)
6895 (org-agenda-do-context-action))
6897 (defun org-agenda-previous-line ()
6898 "Move cursor to the previous line, and show if follow-mode is active."
6900 (call-interactively 'previous-line)
6901 (org-agenda-do-context-action))
6903 (defun org-agenda-do-context-action ()
6904 "Show outline path and, maybe, follow mode window."
6905 (let ((m (org-get-at-bol 'org-marker)))
6906 (when (and (markerp m) (marker-buffer m))
6907 (and org-agenda-follow-mode
6908 (if org-agenda-follow-indirect
6909 (org-agenda-tree-to-indirect-buffer)
6911 (and org-agenda-show-outline-path
6912 (org-with-point-at m (org-display-outline-path t))))))
6914 (defun org-agenda-show-priority ()
6915 "Show the priority of the current item.
6916 This priority is composed of the main priority given with the [#A] cookies,
6917 and by additional input from the age of a schedules or deadline entry."
6919 (let* ((pri (org-get-at-bol 'priority)))
6920 (message "Priority is %d" (if pri pri -1000))))
6922 (defun org-agenda-show-tags ()
6923 "Show the tags applicable to the current item."
6925 (let* ((tags (org-get-at-bol 'tags)))
6927 (message "Tags are :%s:"
6928 (org-no-properties (mapconcat 'identity tags ":")))
6929 (message "No tags associated with this line"))))
6931 (defun org-agenda-goto (&optional highlight)
6932 "Go to the Org-mode file which contains the item at point."
6934 (let* ((marker (or (org-get-at-bol 'org-marker)
6935 (org-agenda-error)))
6936 (buffer (marker-buffer marker))
6937 (pos (marker-position marker)))
6938 (switch-to-buffer-other-window buffer)
6942 (when (eq major-mode 'org-mode)
6943 (org-show-context 'agenda)
6945 (and (outline-next-heading)
6946 (org-flag-heading nil)))) ; show the next heading
6947 (when (outline-invisible-p)
6948 (show-entry)) ; display invisible text
6949 (recenter (/ (window-height) 2))
6950 (run-hooks 'org-agenda-after-show-hook)
6951 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6953 (defvar org-agenda-after-show-hook nil
6954 "Normal hook run after an item has been shown from the agenda.
6955 Point is in the buffer where the item originated.")
6957 (defun org-agenda-kill ()
6958 "Kill the entry or subtree belonging to the current agenda entry."
6960 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6961 (let* ((marker (or (org-get-at-bol 'org-marker)
6962 (org-agenda-error)))
6963 (buffer (marker-buffer marker))
6964 (pos (marker-position marker))
6965 (type (org-get-at-bol 'type))
6966 dbeg dend (n 0) conf)
6967 (org-with-remote-undo buffer
6968 (with-current-buffer buffer
6971 (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
6972 (setq dbeg (progn (org-back-to-heading t) (point))
6973 dend (org-end-of-subtree t t))
6974 (setq dbeg (point-at-bol)
6975 dend (min (point-max) (1+ (point-at-eol)))))
6977 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6978 (setq conf (or (eq t org-agenda-confirm-kill)
6979 (and (numberp org-agenda-confirm-kill)
6980 (> n org-agenda-confirm-kill))))
6983 (format "Delete entry with %d lines in buffer \"%s\"? "
6984 n (buffer-name buffer))))
6986 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6987 (with-current-buffer buffer (delete-region dbeg dend))
6988 (message "Agenda item and source killed"))))
6990 (defvar org-archive-default-command)
6991 (defun org-agenda-archive-default ()
6992 "Archive the entry or subtree belonging to the current agenda entry."
6994 (require 'org-archive)
6995 (org-agenda-archive-with org-archive-default-command))
6997 (defun org-agenda-archive-default-with-confirmation ()
6998 "Archive the entry or subtree belonging to the current agenda entry."
7000 (require 'org-archive)
7001 (org-agenda-archive-with org-archive-default-command 'confirm))
7003 (defun org-agenda-archive ()
7004 "Archive the entry or subtree belonging to the current agenda entry."
7006 (org-agenda-archive-with 'org-archive-subtree))
7008 (defun org-agenda-archive-to-archive-sibling ()
7009 "Move the entry to the archive sibling."
7011 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7013 (defun org-agenda-archive-with (cmd &optional confirm)
7014 "Move the entry to the archive sibling."
7016 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7017 (let* ((marker (or (org-get-at-bol 'org-marker)
7018 (org-agenda-error)))
7019 (buffer (marker-buffer marker))
7020 (pos (marker-position marker)))
7021 (org-with-remote-undo buffer
7022 (with-current-buffer buffer
7023 (if (eq major-mode 'org-mode)
7025 (not (y-or-n-p "Archive this subtree or entry? ")))
7029 (org-remove-subtree-entries-from-agenda)
7030 (org-back-to-heading t)
7032 (error "Archiving works only in Org-mode files"))))))
7034 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7035 "Remove all lines in the agenda that correspond to a given subtree.
7036 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7037 If this information is not given, the function uses the tree at point."
7038 (let ((buf (or buf (current-buffer))) m p)
7040 (unless (and beg end)
7041 (org-back-to-heading t)
7043 (org-end-of-subtree t)
7045 (set-buffer (get-buffer org-agenda-buffer-name))
7047 (goto-char (point-max))
7048 (beginning-of-line 1)
7050 (when (and (setq m (org-get-at-bol 'org-marker))
7051 (equal buf (marker-buffer m))
7052 (setq p (marker-position m))
7055 (let ((inhibit-read-only t))
7056 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7057 (beginning-of-line 0))))))
7059 (defun org-agenda-refile (&optional goto rfloc no-update)
7060 "Refile the item at point."
7062 (if (equal goto '(16))
7063 (org-refile-goto-last-stored)
7064 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7065 (org-agenda-error)))
7066 (buffer (marker-buffer marker))
7067 (pos (marker-position marker))
7069 (org-refile-get-location
7070 (if goto "Goto" "Refile to") buffer
7071 org-refile-allow-creating-parent-nodes))))
7072 (with-current-buffer buffer
7077 (org-remove-subtree-entries-from-agenda)
7078 (org-refile goto buffer rfloc)))))
7079 (unless no-update (org-agenda-redo))))
7081 (defun org-agenda-open-link (&optional arg)
7082 "Follow the link in the current line, if any.
7083 This looks for a link in the displayed line in the agenda. It also looks
7084 at the text of the entry itself."
7086 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7087 (org-get-at-bol 'org-marker)))
7088 (buffer (and marker (marker-buffer marker)))
7089 (prefix (buffer-substring
7090 (point-at-bol) (point-at-eol))))
7093 (with-current-buffer buffer
7098 (org-offer-links-in-entry arg prefix)))))
7099 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7101 (beginning-of-line 1)
7102 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7103 (org-open-link-from-string (match-string 1)))
7104 (t (error "No link to open here")))))
7106 (defun org-agenda-copy-local-variable (var)
7107 "Get a variable from a referenced buffer and install it here."
7108 (let ((m (org-get-at-bol 'org-marker)))
7109 (when (and m (buffer-live-p (marker-buffer m)))
7110 (org-set-local var (with-current-buffer (marker-buffer m)
7111 (symbol-value var))))))
7113 (defun org-agenda-switch-to (&optional delete-other-windows)
7114 "Go to the Org-mode file which contains the item at point."
7116 (if (and org-return-follows-link
7117 (not (org-get-at-bol 'org-marker))
7118 (org-in-regexp org-bracket-link-regexp))
7119 (org-open-link-from-string (match-string 0))
7120 (let* ((marker (or (org-get-at-bol 'org-marker)
7121 (org-agenda-error)))
7122 (buffer (marker-buffer marker))
7123 (pos (marker-position marker)))
7124 (org-pop-to-buffer-same-window buffer)
7125 (and delete-other-windows (delete-other-windows))
7128 (when (eq major-mode 'org-mode)
7129 (org-show-context 'agenda)
7131 (and (outline-next-heading)
7132 (org-flag-heading nil))) ; show the next heading
7133 (when (outline-invisible-p)
7134 (show-entry)))))) ; display invisible text
7136 (defun org-agenda-goto-mouse (ev)
7137 "Go to the Org-mode file which contains the item at the mouse click."
7139 (mouse-set-point ev)
7142 (defun org-agenda-show (&optional full-entry)
7143 "Display the Org-mode file which contains the item at point.
7144 With prefix argument FULL-ENTRY, make the entire entry visible
7145 if it was hidden in the outline."
7147 (let ((win (selected-window)))
7149 (let ((org-show-entry-below t))
7150 (org-agenda-goto t))
7151 (org-agenda-goto t))
7152 (select-window win)))
7154 (defvar org-agenda-show-window nil)
7155 (defun org-agenda-show-and-scroll-up ()
7156 "Display the Org-mode file which contains the item at point.
7157 When called repeatedly, scroll the window that is displaying the buffer."
7159 (let ((win (selected-window)))
7160 (if (and (window-live-p org-agenda-show-window)
7161 (eq this-command last-command))
7163 (select-window org-agenda-show-window)
7164 (ignore-errors (scroll-up)))
7167 (setq org-agenda-show-window (selected-window)))
7168 (select-window win)))
7170 (defun org-agenda-show-scroll-down ()
7171 "Scroll down the window showing the agenda."
7173 (let ((win (selected-window)))
7174 (when (window-live-p org-agenda-show-window)
7175 (select-window org-agenda-show-window)
7176 (ignore-errors (scroll-down))
7177 (select-window win))))
7179 (defun org-agenda-show-1 (&optional more)
7180 "Display the Org-mode file which contains the item at point.
7181 The prefix arg selects the amount of information to display:
7184 1 just show the entry according to defaults.
7185 2 show the children view
7186 3 show the subtree view
7187 4 show the entire subtree and any LOGBOOK drawers
7188 5 show the entire subtree and any drawers
7189 With prefix argument FULL-ENTRY, make the entire entry visible
7190 if it was hidden in the outline."
7192 (let ((win (selected-window)))
7194 (org-recenter-heading 1)
7199 (org-back-to-heading)
7200 (run-hook-with-args 'org-cycle-hook 'folded))
7201 (message "Remote: FOLDED"))
7202 ((and (org-called-interactively-p 'any) (= more 1))
7203 (message "Remote: show with default settings"))
7208 (org-back-to-heading)
7209 (run-hook-with-args 'org-cycle-hook 'children))
7210 (message "Remote: CHILDREN"))
7214 (org-back-to-heading)
7215 (run-hook-with-args 'org-cycle-hook 'subtree))
7216 (message "Remote: SUBTREE"))
7218 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7220 (concat "^[ \t]*:\\("
7221 (mapconcat 'regexp-quote org-drawers "\\|")
7225 (org-back-to-heading)
7226 (org-cycle-hide-drawers 'subtree)))
7227 (message "Remote: SUBTREE AND LOGBOOK"))
7230 (message "Remote: SUBTREE AND ALL DRAWERS")))
7231 (select-window win)))
7233 (defun org-recenter-heading (n)
7235 (org-back-to-heading)
7238 (defvar org-agenda-cycle-counter nil)
7239 (defun org-agenda-cycle-show (&optional n)
7240 "Show the current entry in another window, with default settings.
7241 Default settings are taken from `org-show-hierarchy-above' and siblings.
7242 When use repeatedly in immediate succession, the remote entry will cycle
7245 children -> subtree -> folded
7247 When called with a numeric prefix arg, that arg will be passed through to
7248 `org-agenda-show-1'. For the interpretation of that argument, see the
7249 docstring of `org-agenda-show-1'."
7252 (setq org-agenda-cycle-counter n)
7253 (if (not (eq last-command this-command))
7254 (setq org-agenda-cycle-counter 1)
7255 (if (equal org-agenda-cycle-counter 0)
7256 (setq org-agenda-cycle-counter 2)
7257 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7258 (if (> org-agenda-cycle-counter 3)
7259 (setq org-agenda-cycle-counter 0)))))
7260 (org-agenda-show-1 org-agenda-cycle-counter))
7262 (defun org-agenda-recenter (arg)
7263 "Display the Org-mode file which contains the item at point and recenter."
7265 (let ((win (selected-window)))
7268 (select-window win)))
7270 (defun org-agenda-show-mouse (ev)
7271 "Display the Org-mode file which contains the item at the mouse click."
7273 (mouse-set-point ev)
7276 (defun org-agenda-check-no-diary ()
7277 "Check if the entry is a diary link and abort if yes."
7278 (if (org-get-at-bol 'org-agenda-diary-link)
7279 (org-agenda-error)))
7281 (defun org-agenda-error ()
7282 (error "Command not allowed in this line"))
7284 (defun org-agenda-tree-to-indirect-buffer ()
7285 "Show the subtree corresponding to the current entry in an indirect buffer.
7286 This calls the command `org-tree-to-indirect-buffer' from the original
7288 With numerical prefix arg ARG, go up to this level and then take that tree.
7289 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7290 use the dedicated frame)."
7292 (if (and current-prefix-arg (listp current-prefix-arg))
7293 (org-agenda-do-tree-to-indirect-buffer)
7294 (let ((agenda-window (selected-window))
7296 (and org-last-indirect-buffer
7297 (get-buffer-window org-last-indirect-buffer))))
7298 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7301 (unless (and indirect-window (window-live-p indirect-window))
7302 (setq indirect-window (split-window agenda-window)))
7303 (select-window indirect-window)
7304 (switch-to-buffer org-last-indirect-buffer :norecord)
7305 (fit-window-to-buffer indirect-window))
7306 (select-window (get-buffer-window org-agenda-buffer-name))))))
7308 (defun org-agenda-do-tree-to-indirect-buffer ()
7309 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7310 (org-agenda-check-no-diary)
7311 (let* ((marker (or (org-get-at-bol 'org-marker)
7312 (org-agenda-error)))
7313 (buffer (marker-buffer marker))
7314 (pos (marker-position marker)))
7315 (with-current-buffer buffer
7318 (call-interactively 'org-tree-to-indirect-buffer)))))
7320 (defvar org-last-heading-marker (make-marker)
7321 "Marker pointing to the headline that last changed its TODO state
7322 by a remote command from the agenda.")
7324 (defun org-agenda-todo-nextset ()
7325 "Switch TODO entry to next sequence."
7327 (org-agenda-todo 'nextset))
7329 (defun org-agenda-todo-previousset ()
7330 "Switch TODO entry to previous sequence."
7332 (org-agenda-todo 'previousset))
7334 (defun org-agenda-todo (&optional arg)
7335 "Cycle TODO state of line at point, also in Org-mode file.
7336 This changes the line at point, all other lines in the agenda referring to
7337 the same tree node, and the headline of the tree node in the Org-mode file."
7339 (org-agenda-check-no-diary)
7340 (let* ((col (current-column))
7341 (marker (or (org-get-at-bol 'org-marker)
7342 (org-agenda-error)))
7343 (buffer (marker-buffer marker))
7344 (pos (marker-position marker))
7345 (hdmarker (org-get-at-bol 'org-hd-marker))
7346 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7347 (inhibit-read-only t)
7348 org-agenda-headline-snapshot-before-repeat newhead just-one)
7349 (org-with-remote-undo buffer
7350 (with-current-buffer buffer
7353 (org-show-context 'agenda)
7355 (and (outline-next-heading)
7356 (org-flag-heading nil))) ; show the next heading
7357 (let ((current-prefix-arg arg))
7358 (call-interactively 'org-todo))
7359 (and (bolp) (forward-char 1))
7360 (setq newhead (org-get-heading))
7361 (when (and (org-bound-and-true-p
7362 org-agenda-headline-snapshot-before-repeat)
7363 (not (equal org-agenda-headline-snapshot-before-repeat
7366 (setq newhead org-agenda-headline-snapshot-before-repeat
7369 (org-back-to-heading)
7370 (move-marker org-last-heading-marker (point))))
7371 (beginning-of-line 1)
7373 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7374 (org-move-to-column col))))
7376 (defun org-agenda-add-note (&optional arg)
7377 "Add a time-stamped note to the entry at point."
7379 (org-agenda-check-no-diary)
7380 (let* ((marker (or (org-get-at-bol 'org-marker)
7381 (org-agenda-error)))
7382 (buffer (marker-buffer marker))
7383 (pos (marker-position marker))
7384 (hdmarker (org-get-at-bol 'org-hd-marker))
7385 (inhibit-read-only t))
7386 (with-current-buffer buffer
7389 (org-show-context 'agenda)
7391 (and (outline-next-heading)
7392 (org-flag-heading nil))) ; show the next heading
7395 (defun org-agenda-change-all-lines (newhead hdmarker
7396 &optional fixface just-this)
7397 "Change all lines in the agenda buffer which match HDMARKER.
7398 The new content of the line will be NEWHEAD (as modified by
7399 `org-agenda-format-item'). HDMARKER is checked with
7400 `equal' against all `org-hd-marker' text properties in the file.
7401 If FIXFACE is non-nil, the face of each item is modified according to
7403 If JUST-THIS is non-nil, change just the current line, not all.
7404 If FORCE-TAGS is non nil, the car of it returns the new tags."
7405 (let* ((inhibit-read-only t)
7406 (line (org-current-line))
7407 (thetags (with-current-buffer (marker-buffer hdmarker)
7408 (save-excursion (save-restriction (widen)
7409 (goto-char hdmarker)
7410 (org-get-tags-at)))))
7411 props m pl undone-face done-face finish new dotime cat tags)
7413 (goto-char (point-max))
7414 (beginning-of-line 1)
7416 (setq finish (bobp))
7417 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7418 (or (not just-this) (= (org-current-line) line))
7420 (setq props (text-properties-at (point))
7421 dotime (org-get-at-bol 'dotime)
7422 cat (org-get-at-bol 'org-category)
7425 (let ((org-prefix-format-compiled
7426 (or (get-text-property (point) 'format)
7427 org-prefix-format-compiled)))
7428 (with-current-buffer (marker-buffer hdmarker)
7432 (org-agenda-format-item (org-get-at-bol 'extra)
7433 newhead cat tags dotime)))))
7434 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7435 undone-face (org-get-at-bol 'undone-face)
7436 done-face (org-get-at-bol 'done-face))
7437 (beginning-of-line 1)
7440 (and (looking-at ".*\n?") (replace-match "")))
7442 (replace-match new t t)
7443 (beginning-of-line 1)
7444 (add-text-properties (point-at-bol) (point-at-eol) props)
7446 (add-text-properties
7447 (point-at-bol) (point-at-eol)
7449 (if org-last-todo-state-is-todo
7450 undone-face done-face))))
7451 (org-agenda-highlight-todo 'line)
7452 (beginning-of-line 1))
7453 (t (error "Line update did not work"))))
7454 (beginning-of-line 0)))
7455 (org-finalize-agenda)))
7457 (defun org-agenda-align-tags (&optional line)
7458 "Align all tags in agenda items to `org-agenda-tags-column'."
7459 (let ((inhibit-read-only t) l c)
7461 (goto-char (if line (point-at-bol) (point-min)))
7462 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7463 (if line (point-at-eol) nil) t)
7464 (add-text-properties
7465 (match-beginning 2) (match-end 2)
7466 (list 'face (delq nil (let ((prop (get-text-property
7467 (match-beginning 2) 'face)))
7468 (or (listp prop) (setq prop (list prop)))
7469 (if (memq 'org-tag prop)
7471 (cons 'org-tag prop))))))
7472 (setq l (- (match-end 2) (match-beginning 2))
7473 c (if (< org-agenda-tags-column 0)
7474 (- (abs org-agenda-tags-column) l)
7475 org-agenda-tags-column))
7476 (delete-region (match-beginning 1) (match-end 1))
7477 (goto-char (match-beginning 1))
7478 (insert (org-add-props
7479 (make-string (max 1 (- c (current-column))) ?\ )
7480 (plist-put (copy-sequence (text-properties-at (point)))
7482 (goto-char (point-min))
7483 (org-font-lock-add-tag-faces (point-max)))))
7485 (defun org-agenda-priority-up ()
7486 "Increase the priority of line at point, also in Org-mode file."
7488 (org-agenda-priority 'up))
7490 (defun org-agenda-priority-down ()
7491 "Decrease the priority of line at point, also in Org-mode file."
7493 (org-agenda-priority 'down))
7495 (defun org-agenda-priority (&optional force-direction)
7496 "Set the priority of line at point, also in Org-mode file.
7497 This changes the line at point, all other lines in the agenda referring to
7498 the same tree node, and the headline of the tree node in the Org-mode file."
7500 (unless org-enable-priority-commands
7501 (error "Priority commands are disabled"))
7502 (org-agenda-check-no-diary)
7503 (let* ((marker (or (org-get-at-bol 'org-marker)
7504 (org-agenda-error)))
7505 (hdmarker (org-get-at-bol 'org-hd-marker))
7506 (buffer (marker-buffer hdmarker))
7507 (pos (marker-position hdmarker))
7508 (inhibit-read-only t)
7510 (org-with-remote-undo buffer
7511 (with-current-buffer buffer
7514 (org-show-context 'agenda)
7516 (and (outline-next-heading)
7517 (org-flag-heading nil))) ; show the next heading
7518 (funcall 'org-priority force-direction)
7520 (setq newhead (org-get-heading)))
7521 (org-agenda-change-all-lines newhead hdmarker)
7522 (beginning-of-line 1))))
7524 ;; FIXME: should fix the tags property of the agenda line.
7525 (defun org-agenda-set-tags (&optional tag onoff)
7526 "Set tags for the current headline."
7528 (org-agenda-check-no-diary)
7529 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7530 (call-interactively 'org-change-tag-in-region)
7531 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7532 (org-agenda-error)))
7533 (buffer (marker-buffer hdmarker))
7534 (pos (marker-position hdmarker))
7535 (inhibit-read-only t)
7537 (org-with-remote-undo buffer
7538 (with-current-buffer buffer
7542 (org-show-context 'agenda))
7544 (and (outline-next-heading)
7545 (org-flag-heading nil))) ; show the next heading
7548 (org-toggle-tag tag onoff)
7549 (call-interactively 'org-set-tags))
7551 (setq newhead (org-get-heading)))
7552 (org-agenda-change-all-lines newhead hdmarker)
7553 (beginning-of-line 1)))))
7555 (defun org-agenda-set-property ()
7556 "Set a property for the current headline."
7558 (org-agenda-check-no-diary)
7559 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7560 (org-agenda-error)))
7561 (buffer (marker-buffer hdmarker))
7562 (pos (marker-position hdmarker))
7563 (inhibit-read-only t)
7565 (org-with-remote-undo buffer
7566 (with-current-buffer buffer
7570 (org-show-context 'agenda))
7572 (and (outline-next-heading)
7573 (org-flag-heading nil))) ; show the next heading
7575 (call-interactively 'org-set-property)))))
7577 (defun org-agenda-set-effort ()
7578 "Set the effort property for the current headline."
7580 (org-agenda-check-no-diary)
7581 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7582 (org-agenda-error)))
7583 (buffer (marker-buffer hdmarker))
7584 (pos (marker-position hdmarker))
7585 (inhibit-read-only t)
7587 (org-with-remote-undo buffer
7588 (with-current-buffer buffer
7592 (org-show-context 'agenda))
7594 (and (outline-next-heading)
7595 (org-flag-heading nil))) ; show the next heading
7597 (call-interactively 'org-set-effort)
7599 (setq newhead (org-get-heading)))
7600 (org-agenda-change-all-lines newhead hdmarker))))
7602 (defun org-agenda-toggle-archive-tag ()
7603 "Toggle the archive tag for the current entry."
7605 (org-agenda-check-no-diary)
7606 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7607 (org-agenda-error)))
7608 (buffer (marker-buffer hdmarker))
7609 (pos (marker-position hdmarker))
7610 (inhibit-read-only t)
7612 (org-with-remote-undo buffer
7613 (with-current-buffer buffer
7616 (org-show-context 'agenda)
7618 (and (outline-next-heading)
7619 (org-flag-heading nil))) ; show the next heading
7620 (call-interactively 'org-toggle-archive-tag)
7622 (setq newhead (org-get-heading)))
7623 (org-agenda-change-all-lines newhead hdmarker)
7624 (beginning-of-line 1))))
7626 (defun org-agenda-do-date-later (arg)
7629 ((or (equal arg '(16))
7631 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7632 (setq this-command 'org-agenda-date-later-minutes)
7633 (org-agenda-date-later-minutes 1))
7634 ((or (equal arg '(4))
7636 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7637 (setq this-command 'org-agenda-date-later-hours)
7638 (org-agenda-date-later-hours 1))
7640 (org-agenda-date-later (prefix-numeric-value arg)))))
7642 (defun org-agenda-do-date-earlier (arg)
7645 ((or (equal arg '(16))
7647 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7648 (setq this-command 'org-agenda-date-earlier-minutes)
7649 (org-agenda-date-earlier-minutes 1))
7650 ((or (equal arg '(4))
7652 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7653 (setq this-command 'org-agenda-date-earlier-hours)
7654 (org-agenda-date-earlier-hours 1))
7656 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7658 (defun org-agenda-date-later (arg &optional what)
7659 "Change the date of this item to ARG day(s) later."
7661 (org-agenda-check-type t 'agenda 'timeline)
7662 (org-agenda-check-no-diary)
7663 (let* ((marker (or (org-get-at-bol 'org-marker)
7664 (org-agenda-error)))
7665 (buffer (marker-buffer marker))
7666 (pos (marker-position marker))
7668 (org-with-remote-undo buffer
7669 (with-current-buffer buffer
7672 (if (not (org-at-timestamp-p))
7673 (error "Cannot find time stamp"))
7674 (when (and org-agenda-move-date-from-past-immediately-to-today
7676 (or (not what) (eq what 'day))
7677 (not (save-match-data (org-at-date-range-p))))
7678 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
7679 cdate (calendar-absolute-from-gregorian
7680 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
7683 ;; immediately shift to today
7684 (setq arg (- today cdate))))
7685 (org-timestamp-change arg (or what 'day))
7686 (when (and (org-at-date-range-p)
7687 (re-search-backward org-tr-regexp-both (point-at-bol)))
7688 (let ((end org-last-changed-timestamp))
7689 (org-timestamp-change arg (or what 'day))
7690 (setq org-last-changed-timestamp
7691 (concat org-last-changed-timestamp "--" end)))))
7692 (org-agenda-show-new-time marker org-last-changed-timestamp))
7693 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7695 (defun org-agenda-date-earlier (arg &optional what)
7696 "Change the date of this item to ARG day(s) earlier."
7698 (org-agenda-date-later (- arg) what))
7700 (defun org-agenda-date-later-minutes (arg)
7701 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7703 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7704 (org-agenda-date-later arg 'minute))
7706 (defun org-agenda-date-earlier-minutes (arg)
7707 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7709 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7710 (org-agenda-date-earlier arg 'minute))
7712 (defun org-agenda-date-later-hours (arg)
7713 "Change the time of this item, in hour steps."
7715 (org-agenda-date-later arg 'hour))
7717 (defun org-agenda-date-earlier-hours (arg)
7718 "Change the time of this item, in hour steps."
7720 (org-agenda-date-earlier arg 'hour))
7722 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7723 "Show new date stamp via text properties."
7724 ;; We use text properties to make this undoable
7725 (let ((inhibit-read-only t)
7726 (buffer-invisibility-spec))
7727 (setq stamp (concat " " prefix " => " stamp))
7729 (goto-char (point-max))
7731 (when (equal marker (org-get-at-bol 'org-marker))
7732 (org-move-to-column (- (window-width) (length stamp)) t)
7733 (org-agenda-fix-tags-filter-overlays-at (point))
7734 (if (featurep 'xemacs)
7735 ;; Use `duplicable' property to trigger undo recording
7736 (let ((ex (make-extent nil nil))
7737 (gl (make-glyph stamp)))
7738 (set-glyph-face gl 'secondary-selection)
7739 (set-extent-properties
7740 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7741 (insert-extent ex (1- (point)) (point-at-eol)))
7742 (add-text-properties
7743 (1- (point)) (point-at-eol)
7744 (list 'display (org-add-props stamp nil
7745 'face 'secondary-selection))))
7746 (beginning-of-line 1))
7747 (beginning-of-line 0)))))
7749 (defun org-agenda-date-prompt (arg)
7750 "Change the date of this item. Date is prompted for, with default today.
7751 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7752 be used to request time specification in the time stamp."
7754 (org-agenda-check-type t 'agenda 'timeline)
7755 (org-agenda-check-no-diary)
7756 (let* ((marker (or (org-get-at-bol 'org-marker)
7757 (org-agenda-error)))
7758 (buffer (marker-buffer marker))
7759 (pos (marker-position marker)))
7760 (org-with-remote-undo buffer
7761 (with-current-buffer buffer
7764 (if (not (org-at-timestamp-p t))
7765 (error "Cannot find time stamp"))
7766 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7767 (org-agenda-show-new-time marker org-last-changed-timestamp))
7768 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7770 (defun org-agenda-schedule (arg &optional time)
7771 "Schedule the item at point.
7772 ARG is passed through to `org-schedule'."
7774 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7775 (org-agenda-check-no-diary)
7776 (let* ((marker (or (org-get-at-bol 'org-marker)
7777 (org-agenda-error)))
7778 (type (marker-insertion-type marker))
7779 (buffer (marker-buffer marker))
7780 (pos (marker-position marker))
7781 (org-insert-labeled-timestamps-at-point nil)
7783 (set-marker-insertion-type marker t)
7784 (org-with-remote-undo buffer
7785 (with-current-buffer buffer
7788 (setq ts (org-schedule arg time)))
7789 (org-agenda-show-new-time marker ts "S"))
7790 (message "Item scheduled for %s" ts)))
7792 (defun org-agenda-deadline (arg &optional time)
7793 "Schedule the item at point.
7794 ARG is passed through to `org-deadline'."
7796 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7797 (org-agenda-check-no-diary)
7798 (let* ((marker (or (org-get-at-bol 'org-marker)
7799 (org-agenda-error)))
7800 (buffer (marker-buffer marker))
7801 (pos (marker-position marker))
7802 (org-insert-labeled-timestamps-at-point nil)
7804 (org-with-remote-undo buffer
7805 (with-current-buffer buffer
7808 (setq ts (org-deadline arg time)))
7809 (org-agenda-show-new-time marker ts "D"))
7810 (message "Deadline for this item set to %s" ts)))
7812 (defun org-agenda-action ()
7813 "Select entry for agenda action, or execute an agenda action.
7814 This command prompts for another letter. Valid inputs are:
7816 m Mark the entry at point for an agenda action
7817 s Schedule the marked entry to the date at the cursor
7818 d Set the deadline of the marked entry to the date at the cursor
7819 r Call `org-remember' with cursor date as the default date
7820 c Call `org-capture' with cursor date as the default date
7821 SPC Show marked entry in other window
7822 TAB Visit marked entry in other window
7824 The cursor may be at a date in the calendar, or in the Org agenda."
7827 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7828 (setq ans (read-char-exclusive))
7832 (if (eq major-mode 'org-agenda-mode)
7833 (let ((m (or (org-get-at-bol 'org-hd-marker)
7834 (org-get-at-bol 'org-marker))))
7837 (move-marker org-agenda-action-marker
7838 (marker-position m) (marker-buffer m))
7839 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7840 (error "Don't know which entry to mark")))
7841 (error "This command works only in the agenda")))
7843 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7845 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7847 (org-agenda-do-action '(org-remember) t))
7849 (org-agenda-do-action '(org-capture) t))
7851 (let ((cw (selected-window)))
7852 (org-switch-to-buffer-other-window
7853 (marker-buffer org-agenda-action-marker))
7854 (goto-char org-agenda-action-marker)
7855 (org-show-context 'agenda)
7856 (select-window cw)))
7858 (org-switch-to-buffer-other-window
7859 (marker-buffer org-agenda-action-marker))
7860 (goto-char org-agenda-action-marker)
7861 (org-show-context 'agenda))
7862 (t (error "Invalid agenda action %c" ans)))))
7864 (defun org-agenda-do-action (form &optional current-buffer)
7865 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7866 (let ((org-overriding-default-time (org-get-cursor-date)))
7869 (if (not (marker-buffer org-agenda-action-marker))
7870 (error "No entry has been selected for agenda action")
7871 (with-current-buffer (marker-buffer org-agenda-action-marker)
7875 (goto-char org-agenda-action-marker)
7878 (defun org-agenda-clock-in (&optional arg)
7879 "Start the clock on the currently selected item."
7881 (org-agenda-check-no-diary)
7882 (if (equal arg '(4))
7884 (let* ((marker (or (org-get-at-bol 'org-marker)
7885 (org-agenda-error)))
7886 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7888 (pos (marker-position marker))
7890 (org-with-remote-undo (marker-buffer marker)
7891 (with-current-buffer (marker-buffer marker)
7894 (org-show-context 'agenda)
7896 (org-cycle-hide-drawers 'children)
7898 (setq newhead (org-get-heading)))
7899 (org-agenda-change-all-lines newhead hdmarker)))))
7901 (defun org-agenda-clock-out ()
7902 "Stop the currently running clock."
7904 (unless (marker-buffer org-clock-marker)
7905 (error "No running clock"))
7906 (let ((marker (make-marker)) newhead)
7907 (org-with-remote-undo (marker-buffer org-clock-marker)
7908 (with-current-buffer (marker-buffer org-clock-marker)
7912 (goto-char org-clock-marker)
7913 (org-back-to-heading t)
7914 (move-marker marker (point))
7916 (setq newhead (org-get-heading))))))
7917 (org-agenda-change-all-lines newhead marker)
7918 (move-marker marker nil)))
7920 (defun org-agenda-clock-cancel (&optional arg)
7921 "Cancel the currently running clock."
7923 (unless (marker-buffer org-clock-marker)
7924 (error "No running clock"))
7925 (org-with-remote-undo (marker-buffer org-clock-marker)
7926 (org-clock-cancel)))
7928 (defun org-agenda-clock-goto ()
7929 "Jump to the currently clocked in task within the agenda.
7930 If the currently clocked in task is not listed in the agenda
7931 buffer, display it in another window."
7935 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7936 (setq pos (overlay-start o))))
7937 (overlays-in (point-min) (point-max)))
7938 (cond (pos (goto-char pos))
7939 ;; If the currently clocked entry is not in the agenda
7940 ;; buffer, we visit it in another window:
7941 (org-clock-current-task
7942 (org-switch-to-buffer-other-window (org-clock-goto)))
7943 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7945 (defun org-agenda-diary-entry-in-org-file ()
7946 "Make a diary entry in the file `org-agenda-diary-file'."
7947 (let (d1 d2 char (text "") dp1 dp2)
7948 (if (equal (buffer-name) "*Calendar*")
7949 (setq d1 (calendar-cursor-to-date t)
7950 d2 (car calendar-mark-ring))
7951 (setq dp1 (get-text-property (point-at-bol) 'day))
7952 (unless dp1 (error "No date defined in current line"))
7953 (setq d1 (calendar-gregorian-from-absolute dp1)
7954 d2 (and (ignore-errors (mark))
7957 (setq dp2 (get-text-property (point-at-bol) 'day)))
7958 (calendar-gregorian-from-absolute dp2))))
7959 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7960 (setq char (read-char-exclusive))
7963 (setq text (read-string "Day entry: "))
7964 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7965 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7967 (setq d1 (list (car d1) (nth 1 d1)
7968 (read-number (format "Reference year [%d]: " (nth 2 d1))
7970 (setq text (read-string "Anniversary (use %d to show years): "))
7971 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7972 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7974 (setq text (read-string "Block entry: "))
7975 (unless (and d1 d2 (not (equal d1 d2)))
7976 (error "No block of days selected"))
7977 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7978 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7980 (org-switch-to-buffer-other-window
7981 (find-file-noselect org-agenda-diary-file))
7982 (require 'org-datetree)
7983 (org-datetree-find-date-create d1)
7985 (t (error "Invalid selection character `%c'" char)))))
7987 (defcustom org-agenda-insert-diary-strategy 'date-tree
7988 "Where in `org-agenda-diary-file' should new entries be added?
7991 date-tree in the date tree, as child of the date
7992 top-level as top-level entries at the end of the file."
7995 (const :tag "in a date tree" date-tree)
7996 (const :tag "as top level at end of file" top-level)))
7998 (defcustom org-agenda-insert-diary-extract-time nil
7999 "Non-nil means extract any time specification from the diary entry."
8003 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8004 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8005 If TEXT is not empty, it will become the headline of the new entry, and
8006 the resulting entry will not be shown. When TEXT is empty, switch to
8007 `org-agenda-diary-file' and let the user finish the entry there."
8008 (let ((cw (current-window-configuration)))
8009 (org-switch-to-buffer-other-window
8010 (find-file-noselect org-agenda-diary-file))
8012 (goto-char (point-min))
8014 ((eq type 'anniversary)
8015 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8017 (or (org-at-heading-p t)
8019 (outline-next-heading)
8020 (insert "* Anniversaries\n\n")
8021 (beginning-of-line -1)))))
8022 (outline-next-heading)
8023 (org-back-over-empty-lines)
8026 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8027 (nth 2 d1) (car d1) (nth 1 d1) text)))
8029 (let ((org-prefix-has-time t)
8030 (org-agenda-time-leading-zero t)
8032 (if org-agenda-insert-diary-extract-time
8033 ;; Use org-agenda-format-item to parse text for a time-range and
8034 ;; remove it. FIXME: This is a hack, we should refactor
8035 ;; that function to make time extraction available separately
8036 (setq fmt (org-agenda-format-item nil text nil nil t)
8037 time (get-text-property 0 'time fmt)
8038 time2 (if (> (length time) 0)
8039 ;; split-string removes trailing ...... if
8040 ;; no end time given. First space
8041 ;; separates time from date.
8042 (concat " " (car (split-string time "\\.")))
8044 text (get-text-property 0 'txt fmt)))
8045 (if (eq org-agenda-insert-diary-strategy 'top-level)
8046 (org-agenda-insert-diary-as-top-level text)
8047 (require 'org-datetree)
8048 (org-datetree-find-date-create d1)
8049 (org-agenda-insert-diary-make-new-entry text))
8050 (org-insert-time-stamp (org-time-from-absolute
8051 (calendar-absolute-from-gregorian d1))
8052 nil nil nil nil time2))
8055 (if (> (calendar-absolute-from-gregorian d1)
8056 (calendar-absolute-from-gregorian d2))
8057 (setq d1 (prog1 d2 (setq d2 d1))))
8058 (if (eq org-agenda-insert-diary-strategy 'top-level)
8059 (org-agenda-insert-diary-as-top-level text)
8060 (require 'org-datetree)
8061 (org-datetree-find-date-create d1)
8062 (org-agenda-insert-diary-make-new-entry text))
8063 (org-insert-time-stamp (org-time-from-absolute
8064 (calendar-absolute-from-gregorian d1)))
8066 (org-insert-time-stamp (org-time-from-absolute
8067 (calendar-absolute-from-gregorian d2)))
8069 (if (string-match "\\S-" text)
8071 (set-window-configuration cw)
8072 (message "%s entry added to %s"
8073 (capitalize (symbol-name type))
8074 (abbreviate-file-name org-agenda-diary-file)))
8076 (message "Please finish entry here"))))
8078 (defun org-agenda-insert-diary-as-top-level (text)
8079 "Make new entry as a top-level entry at the end of the file.
8080 Add TEXT as headline, and position the cursor in the second line so that
8081 a timestamp can be added there."
8083 (goto-char (point-max))
8084 (or (bolp) (insert "\n"))
8085 (insert "* " text "\n")
8086 (if org-adapt-indentation (org-indent-to-column 2)))
8088 (defun org-agenda-insert-diary-make-new-entry (text)
8089 "Make new entry as last child of current entry.
8090 Add TEXT as headline, and position the cursor in the second line so that
8091 a timestamp can be added there."
8092 (let ((org-show-following-heading t)
8093 (org-show-siblings t)
8094 (org-show-hierarchy-above t)
8095 (org-show-entry-below t)
8097 (outline-next-heading)
8098 (org-back-over-empty-lines)
8099 (or (looking-at "[ \t]*$")
8100 (progn (insert "\n") (backward-char 1)))
8101 (org-insert-heading nil t)
8103 (setq col (current-column))
8105 (if org-adapt-indentation (org-indent-to-column col))
8106 (let ((org-show-following-heading t)
8107 (org-show-siblings t)
8108 (org-show-hierarchy-above t)
8109 (org-show-entry-below t))
8110 (org-show-context))))
8112 (defun org-agenda-diary-entry ()
8113 "Make a diary entry, like the `i' command from the calendar.
8114 All the standard commands work: block, weekly etc.
8115 When `org-agenda-diary-file' points to a file,
8116 `org-agenda-diary-entry-in-org-file' is called instead to create
8117 entries in that Org-mode file."
8119 (org-agenda-check-type t 'agenda 'timeline)
8120 (if (not (eq org-agenda-diary-file 'diary-file))
8121 (org-agenda-diary-entry-in-org-file)
8122 (require 'diary-lib)
8124 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8125 (read-char-exclusive)))
8126 (cmd (cdr (assoc char
8127 '((?d . insert-diary-entry)
8128 (?w . insert-weekly-diary-entry)
8129 (?m . insert-monthly-diary-entry)
8130 (?y . insert-yearly-diary-entry)
8131 (?a . insert-anniversary-diary-entry)
8132 (?b . insert-block-diary-entry)
8133 (?c . insert-cyclic-diary-entry)))))
8134 (oldf (symbol-function 'calendar-cursor-to-date))
8135 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8137 (mark (or (mark t) (point))))
8139 (error "No command associated with <%c>" char))
8140 (unless (and (get-text-property point 'day)
8141 (or (not (equal ?b char))
8142 (get-text-property mark 'day)))
8143 (error "Don't know which date to use for diary entry"))
8144 ;; We implement this by hacking the `calendar-cursor-to-date' function
8145 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8146 (let ((calendar-mark-ring
8147 (list (calendar-gregorian-from-absolute
8148 (or (get-text-property mark 'day)
8149 (get-text-property point 'day))))))
8152 (fset 'calendar-cursor-to-date
8153 (lambda (&optional error dummy)
8154 (calendar-gregorian-from-absolute
8155 (get-text-property point 'day))))
8156 (call-interactively cmd))
8157 (fset 'calendar-cursor-to-date oldf))))))
8159 (defun org-agenda-execute-calendar-command (cmd)
8160 "Execute a calendar command from the agenda, with the date associated to
8161 the cursor position."
8162 (org-agenda-check-type t 'agenda 'timeline)
8163 (require 'diary-lib)
8164 (unless (get-text-property (point) 'day)
8165 (error "Don't know which date to use for calendar command"))
8166 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8168 (date (calendar-gregorian-from-absolute
8169 (get-text-property point 'day)))
8170 ;; the following 2 vars are needed in the calendar
8171 (displayed-month (car date))
8172 (displayed-year (nth 2 date)))
8175 (fset 'calendar-cursor-to-date
8176 (lambda (&optional error dummy)
8177 (calendar-gregorian-from-absolute
8178 (get-text-property point 'day))))
8179 (call-interactively cmd))
8180 (fset 'calendar-cursor-to-date oldf))))
8182 (defun org-agenda-phases-of-moon ()
8183 "Display the phases of the moon for the 3 months around the cursor date."
8185 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8187 (defun org-agenda-holidays ()
8188 "Display the holidays for the 3 months around the cursor date."
8190 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8192 (defvar calendar-longitude)
8193 (defvar calendar-latitude)
8194 (defvar calendar-location-name)
8196 (defun org-agenda-sunrise-sunset (arg)
8197 "Display sunrise and sunset for the cursor date.
8198 Latitude and longitude can be specified with the variables
8199 `calendar-latitude' and `calendar-longitude'. When called with prefix
8200 argument, latitude and longitude will be prompted for."
8203 (let ((calendar-longitude (if arg nil calendar-longitude))
8204 (calendar-latitude (if arg nil calendar-latitude))
8205 (calendar-location-name
8206 (if arg "the given coordinates" calendar-location-name)))
8207 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8209 (defun org-agenda-goto-calendar ()
8210 "Open the Emacs calendar with the date at the cursor."
8212 (org-agenda-check-type t 'agenda 'timeline)
8213 (let* ((day (or (get-text-property (point) 'day)
8214 (error "Don't know which date to open in calendar")))
8215 (date (calendar-gregorian-from-absolute day))
8216 (calendar-move-hook nil)
8217 (calendar-view-holidays-initially-flag nil)
8218 (calendar-view-diary-initially-flag nil))
8220 (calendar-goto-date date)))
8223 (defun org-calendar-goto-agenda ()
8224 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8225 This is a command that has to be installed in `calendar-mode-map'."
8227 (org-agenda-list nil (calendar-absolute-from-gregorian
8228 (calendar-cursor-to-date))
8231 (defun org-agenda-convert-date ()
8233 (org-agenda-check-type t 'agenda 'timeline)
8234 (let ((day (get-text-property (point) 'day))
8237 (error "Don't know which date to convert"))
8238 (setq date (calendar-gregorian-from-absolute day))
8240 "Gregorian: " (calendar-date-string date) "\n"
8241 "ISO: " (calendar-iso-date-string date) "\n"
8242 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8243 "Julian: " (calendar-julian-date-string date) "\n"
8244 "Astron. JD: " (calendar-astro-date-string date)
8245 " (Julian date number at noon UTC)\n"
8246 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8247 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8248 "French: " (calendar-french-date-string date) "\n"
8249 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8250 "Mayan: " (calendar-mayan-date-string date) "\n"
8251 "Coptic: " (calendar-coptic-date-string date) "\n"
8252 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8253 "Persian: " (calendar-persian-date-string date) "\n"
8254 "Chinese: " (calendar-chinese-date-string date) "\n"))
8255 (with-output-to-temp-buffer "*Dates*"
8257 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8261 (defvar org-agenda-bulk-marked-entries nil
8262 "List of markers that refer to marked entries in the agenda.")
8264 (defun org-agenda-bulk-marked-p ()
8265 (eq (get-char-property (point-at-bol) 'type)
8266 'org-marked-entry-overlay))
8268 (defun org-agenda-bulk-mark (&optional arg)
8269 "Mark the entry at point for future bulk action."
8271 (dotimes (i (max arg 1))
8272 (unless (org-get-at-bol 'org-agenda-diary-link)
8273 (let* ((m (org-get-at-bol 'org-hd-marker))
8275 (unless (org-agenda-bulk-marked-p)
8276 (unless m (error "Nothing to mark at point"))
8277 (push m org-agenda-bulk-marked-entries)
8278 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8279 (org-overlay-display ov "> "
8280 (org-get-todo-face "TODO")
8282 (overlay-put ov 'type 'org-marked-entry-overlay))
8283 (beginning-of-line 2)
8284 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8285 (beginning-of-line 2))
8286 (message "%d entries marked for bulk action"
8287 (length org-agenda-bulk-marked-entries))))))
8289 (defun org-agenda-bulk-mark-regexp (regexp)
8290 "Mark entries match REGEXP."
8291 (interactive "sMark entries matching regexp: ")
8292 (let (entries-marked)
8294 (goto-char (point-min))
8295 (goto-char (next-single-property-change (point) 'txt))
8296 (while (re-search-forward regexp nil t)
8297 (when (string-match regexp (get-text-property (point) 'txt))
8298 (setq entries-marked (+ entries-marked 1))
8299 (call-interactively 'org-agenda-bulk-mark))))
8300 (if (not entries-marked)
8301 (message "No entry matching this regexp."))))
8303 (defun org-agenda-bulk-unmark ()
8304 "Unmark the entry at point for future bulk action."
8306 (when (org-agenda-bulk-marked-p)
8307 (org-agenda-bulk-remove-overlays
8308 (point-at-bol) (+ 2 (point-at-bol)))
8309 (setq org-agenda-bulk-marked-entries
8310 (delete (org-get-at-bol 'org-hd-marker)
8311 org-agenda-bulk-marked-entries)))
8312 (beginning-of-line 2)
8313 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8314 (beginning-of-line 2))
8315 (message "%d entries marked for bulk action"
8316 (length org-agenda-bulk-marked-entries)))
8318 (defun org-agenda-bulk-toggle ()
8319 "Toggle marking the entry at point for bulk action."
8321 (if (org-agenda-bulk-marked-p)
8322 (org-agenda-bulk-unmark)
8323 (org-agenda-bulk-mark)))
8325 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8326 "Remove the mark overlays between BEG and END in the agenda buffer.
8327 BEG and END default to the buffer limits.
8329 This only removes the overlays, it does not remove the markers
8330 from the list in `org-agenda-bulk-marked-entries'."
8333 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8334 (delete-overlay ov)))
8335 (overlays-in (or beg (point-min)) (or end (point-max)))))
8337 (defun org-agenda-bulk-remove-all-marks ()
8338 "Remove all marks in the agenda buffer.
8339 This will remove the markers, and the overlays."
8341 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8342 (setq org-agenda-bulk-marked-entries nil)
8343 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8345 (defun org-agenda-bulk-action (&optional arg)
8346 "Execute an remote-editing action on all marked entries.
8347 The prefix arg is passed through to the command if possible."
8349 ;; Make sure we have markers, and only valid ones
8350 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8353 (unless (and (markerp m)
8355 (buffer-live-p (marker-buffer m))
8356 (marker-position m))
8357 (error "Marker %s for bulk command is invalid" m)))
8358 org-agenda-bulk-marked-entries)
8360 ;; Prompt for the bulk command
8361 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8362 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8363 (when org-agenda-bulk-custom-functions
8364 (concat " Custom: ["
8365 (mapconcat (lambda(f) (char-to-string (car f)))
8366 org-agenda-bulk-custom-functions "")
8368 (let* ((action (read-char-exclusive))
8369 (org-log-refile (if org-log-refile 'time nil))
8370 (entries (reverse org-agenda-bulk-marked-entries))
8372 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8375 (setq cmd '(org-agenda-archive)))
8378 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8380 ((member action '(?r ?w))
8381 (setq rfloc (org-refile-get-location
8383 (marker-buffer (car org-agenda-bulk-marked-entries))
8384 org-refile-allow-creating-parent-nodes))
8386 (setcar (nthcdr 3 rfloc)
8387 (move-marker (make-marker) (nth 3 rfloc)
8388 (or (get-file-buffer (nth 1 rfloc))
8389 (find-buffer-visiting (nth 1 rfloc))
8390 (error "This should not happen")))))
8392 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8396 (setq state (org-icompleting-read
8398 (with-current-buffer (marker-buffer (car entries))
8399 (mapcar 'list org-todo-keywords-1))))
8400 (setq cmd `(let ((org-inhibit-blocking t)
8401 (org-inhibit-logging 'note))
8402 (org-agenda-todo ,state))))
8404 ((memq action '(?- ?+))
8405 (setq tag (org-icompleting-read
8406 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8407 (with-current-buffer (marker-buffer (car entries))
8410 (if (stringp (car x)) x)) org-tag-alist)))))
8411 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8413 ((memq action '(?s ?d))
8414 (let* ((date (unless arg
8417 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8418 (ans (if arg nil org-read-date-final-answer))
8419 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8420 (setq cmd `(let* ((bound (fboundp 'read-string))
8421 (old (and bound (symbol-function 'read-string))))
8424 (fset 'read-string (lambda (&rest ignore) ,ans))
8427 (fset 'read-string old)
8428 (fmakunbound 'read-string)))))))
8431 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8432 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8433 (let ((days (read-number
8434 (format "Scatter tasks across how many %sdays: "
8435 (if arg "week" "")) 7)))
8437 `(let ((distance (1+ (random ,days))))
8439 (let ((dist distance)
8441 (calendar-day-of-week
8442 (calendar-gregorian-from-absolute (org-today)))))
8443 (dotimes (i (1+ dist))
8444 (while (member day-of-week org-agenda-weekend-days)
8447 (if (= day-of-week 7)
8448 (setq day-of-week 0)))
8450 (if (= day-of-week 7)
8451 (setq day-of-week 0)))))
8452 ;; silently fail when try to replan a sexp entry
8454 (let* ((date (calendar-gregorian-from-absolute
8455 (+ (org-today) distance)))
8456 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8458 (org-agenda-schedule nil time))
8461 ((assoc action org-agenda-bulk-custom-functions)
8462 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8466 (setq cmd (list (intern
8467 (org-icompleting-read "Function: "
8468 obarray 'fboundp t nil nil)))))
8470 (t (error "Invalid bulk action")))
8472 ;; Sort the markers, to make sure that parents are handled before children
8473 (setq entries (sort entries
8476 ((equal (marker-buffer a) (marker-buffer b))
8477 (< (marker-position a) (marker-position b)))
8479 (string< (buffer-name (marker-buffer a))
8480 (buffer-name (marker-buffer b))))))))
8482 ;; Now loop over all markers and apply cmd
8483 (while (setq e (pop entries))
8484 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8486 (progn (message "Skipping removed entry at %s" e)
8487 (setq cntskip (1+ cntskip)))
8489 (let (org-loop-over-headlines-in-active-region)
8491 (setq org-agenda-bulk-marked-entries
8492 (delete e org-agenda-bulk-marked-entries))
8493 (setq cnt (1+ cnt))))
8494 (setq org-agenda-bulk-marked-entries nil)
8495 (org-agenda-bulk-remove-all-marks)
8496 (when redo-at-end (org-agenda-redo))
8497 (message "Acted on %d entries%s"
8501 (format ", skipped %d (disappeared before their turn)"
8506 (defun org-agenda-show-the-flagging-note ()
8507 "Display the flagging note in the other window.
8508 When called a second time in direct sequence, offer to remove the FLAGGING
8509 tag and (if present) the flagging note."
8511 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8512 (win (selected-window))
8513 note heading newhead)
8515 (error "No linked entry at point"))
8516 (if (and (eq this-command last-command)
8517 (y-or-n-p "Unflag and remove any flagging note? "))
8519 (org-agenda-remove-flag hdmarker)
8520 (let ((win (get-buffer-window "*Flagging Note*")))
8521 (and win (delete-window win)))
8522 (message "Entry unflagged"))
8523 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8525 (error "No flagging note"))
8527 (org-switch-to-buffer-other-window "*Flagging Note*")
8530 (goto-char (point-min))
8531 (while (re-search-forward "\\\\n" nil t)
8532 (replace-match "\n" t t))
8533 (goto-char (point-min))
8535 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8537 (defun org-agenda-remove-flag (marker)
8538 "Remove the FLAGGED tag and any flagging note in the entry."
8540 (org-with-point-at marker
8541 (org-toggle-tag "FLAGGED" 'off)
8542 (org-entry-delete nil "THEFLAGGINGNOTE")
8543 (setq newhead (org-get-heading)))
8544 (org-agenda-change-all-lines newhead marker)
8545 (message "Entry unflagged")))
8547 (defun org-agenda-get-any-marker (&optional pos)
8548 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8549 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8551 ;;; Appointment reminders
8553 (defvar appt-time-msg-list)
8556 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8557 "Activate appointments found in `org-agenda-files'.
8558 With a \\[universal-argument] prefix, refresh the list of
8561 If FILTER is t, interactively prompt the user for a regular
8562 expression, and filter out entries that don't match it.
8564 If FILTER is a string, use this string as a regular expression
8565 for filtering entries out.
8567 If FILTER is a function, filter out entries against which
8568 calling the function returns nil. This function takes one
8569 argument: an entry from `org-agenda-get-day-entries'.
8571 FILTER can also be an alist with the car of each cell being
8572 either 'headline or 'category. For example:
8574 '((headline \"IMPORTANT\")
8575 (category \"Work\"))
8577 will only add headlines containing IMPORTANT or headlines
8578 belonging to the \"Work\" category.
8580 ARGS are symbols indicating what kind of entries to consider.
8581 By default `org-agenda-to-appt' will use :deadline, :scheduled
8582 and :timestamp entries. See the docstring of `org-diary' for
8583 details and examples."
8585 (if refresh (setq appt-time-msg-list nil))
8587 (setq filter (read-from-minibuffer "Regexp filter: ")))
8588 (let* ((cnt 0) ; count added events
8589 (scope (or args '(:deadline :scheduled :timestamp)))
8590 (org-agenda-new-buffers nil)
8591 (org-deadline-warning-days 0)
8592 ;; Do not use `org-today' here because appt only takes
8593 ;; time and without date as argument, so it may pass wrong
8594 ;; information otherwise
8595 (today (org-date-to-gregorian
8596 (time-to-days (current-time))))
8597 (org-agenda-restrict nil)
8598 (files (org-agenda-files 'unrestricted)) entries file)
8599 ;; Get all entries which may contain an appt
8600 (org-prepare-agenda-buffers files)
8601 (while (setq file (pop files))
8605 (apply 'org-agenda-get-day-entries
8606 file today scope)))))
8607 ;; Map thru entries and find if we should filter them out
8610 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8611 (cat (get-text-property 1 'org-category x))
8612 (tod (get-text-property 1 'time-of-day x))
8613 (ok (or (null filter)
8614 (and (stringp filter) (string-match filter evt))
8615 (and (functionp filter) (funcall filter x))
8617 (let ((cat-filter (cadr (assoc 'category filter)))
8618 (evt-filter (cadr (assoc 'headline filter))))
8619 (or (and (stringp cat-filter)
8620 (string-match cat-filter cat))
8621 (and (stringp evt-filter)
8622 (string-match evt-filter evt))))))))
8623 ;; FIXME: Shall we remove text-properties for the appt text?
8624 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8626 (setq tod (concat "00" (number-to-string tod))
8627 tod (when (string-match
8628 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8629 (concat (match-string 1 tod) ":"
8630 (match-string 2 tod))))
8632 (setq cnt (1+ cnt))))) entries)
8633 (org-release-buffers org-agenda-new-buffers)
8635 (message "No event to add")
8636 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8638 (defun org-agenda-todayp (date)
8639 "Does DATE mean today, when considering `org-extend-today-until'?"
8640 (let ((today (org-today))
8641 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8645 (defun org-agenda-todo-yesterday (&optional arg)
8646 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
8648 (let* ((hour (third (decode-time
8649 (org-current-time))))
8650 (org-extend-today-until (1+ hour)))
8651 (org-agenda-todo arg)))
8653 (provide 'org-agenda)
8655 ;;; org-agenda.el ends here