1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2011 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
)
307 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
312 (list :tag
"Standard skipping condition"
313 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
314 (const org-agenda-skip-function
)
316 (const :format
"" quote
)
319 :tag
"Skipping range"
320 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
321 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
322 (repeat :inline t
:tag
"Conditions for skipping"
324 :tag
"Condition type"
325 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
326 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
327 (list :tag
"TODO state is" :inline t
330 (const :tag
"any not-done state" 'todo
)
331 (const :tag
"any done state" 'done
)
332 (const :tag
"any state" 'any
)
333 (list :tag
"Keyword list"
334 (const :format
"" quote
)
335 (repeat (string :tag
"Keyword")))))
336 (list :tag
"TODO state is not" :inline t
339 (const :tag
"any not-done state" 'todo
)
340 (const :tag
"any done state" 'done
)
341 (const :tag
"any state" 'any
)
342 (list :tag
"Keyword list"
343 (const :format
"" quote
)
344 (repeat (string :tag
"Keyword")))))
345 (const :tag
"scheduled" 'scheduled
)
346 (const :tag
"not scheduled" 'notscheduled
)
347 (const :tag
"deadline" 'deadline
)
348 (const :tag
"no deadline" 'notdeadline
)
349 (const :tag
"timestamp" 'timestamp
)
350 (const :tag
"no timestamp" 'nottimestamp
))))))
351 (list :tag
"Non-standard skipping condition"
352 :value
(org-agenda-skip-function)
353 (const org-agenda-skip-function
)
354 (sexp :tag
"Function or form (quoted!)"))
355 (list :tag
"Any variable"
356 (variable :tag
"Variable")
357 (sexp :tag
"Value (sexp)"))))
358 "Selection of examples for agenda command settings.
359 This will be spliced into the custom type of
360 `org-agenda-custom-commands'.")
363 (defcustom org-agenda-custom-commands
'(("n" "Agenda and all TODO's"
364 ((agenda "") (alltodo))))
365 "Custom commands for the agenda.
366 These commands will be offered on the splash screen displayed by the
367 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
369 (key desc type match settings files)
371 key The key (one or more characters as a string) to be associated
373 desc A description of the command, when omitted or nil, a default
374 description is built using MATCH.
375 type The command type, any of the following symbols:
376 agenda The daily/weekly agenda.
377 todo Entries with a specific TODO keyword, in all agenda files.
378 search Entries containing search words entry or headline.
379 tags Tags/Property/TODO match in all agenda files.
380 tags-todo Tags/P/T match in all agenda files, TODO entries only.
381 todo-tree Sparse tree of specific TODO keyword in *current* file.
382 tags-tree Sparse tree with all tags matches in *current* file.
383 occur-tree Occur sparse tree for *current* file.
384 ... A user-defined function.
385 match What to search for:
386 - a single keyword for TODO keyword searches
387 - a tags match expression for tags searches
388 - a word search expression for text searches.
389 - a regular expression for occur searches
390 For all other commands, this should be the empty string.
391 settings A list of option settings, similar to that in a let form, so like
392 this: ((opt1 val1) (opt2 val2) ...). The values will be
393 evaluated at the moment of execution, so quote them when needed.
394 files A list of files file to write the produced agenda buffer to
395 with the command `org-store-agenda-views'.
396 If a file name ends in \".html\", an HTML version of the buffer
397 is written out. If it ends in \".ps\", a postscript version is
398 produced. Otherwise, only the plain text is written to the file.
400 You can also define a set of commands, to create a composite agenda buffer.
401 In this case, an entry looks like this:
403 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
407 desc A description string to be displayed in the dispatcher menu.
408 cmd An agenda command, similar to the above. However, tree commands
409 are no allowed, but instead you can get agenda and global todo list.
410 So valid commands for a set are:
411 (agenda \"\" settings)
412 (alltodo \"\" settings)
413 (stuck \"\" settings)
414 (todo \"match\" settings files)
415 (search \"match\" settings files)
416 (tags \"match\" settings files)
417 (tags-todo \"match\" settings files)
419 Each command can carry a list of options, and another set of options can be
420 given for the whole set of commands. Individual command options take
421 precedence over the general options.
423 When using several characters as key to a command, the first characters
424 are prefix commands. For the dispatcher to display useful information, you
425 should provide a description for the prefix, like
427 (setq org-agenda-custom-commands
428 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
429 (\"hl\" tags \"+HOME+Lisa\")
430 (\"hp\" tags \"+HOME+Peter\")
431 (\"hk\" tags \"+HOME+Kim\")))"
432 :group
'org-agenda-custom-commands
434 (choice :value
("x" "Describe command here" tags
"" nil
)
435 (list :tag
"Single command"
436 (string :tag
"Access Key(s) ")
437 (option (string :tag
"Description"))
439 (const :tag
"Agenda" agenda
)
440 (const :tag
"TODO list" alltodo
)
441 (const :tag
"Search words" search
)
442 (const :tag
"Stuck projects" stuck
)
443 (const :tag
"Tags/Property match (all agenda files)" tags
)
444 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
445 (const :tag
"TODO keyword search (all agenda files)" todo
)
446 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
447 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
448 (const :tag
"Occur tree (current buffer)" occur-tree
)
449 (sexp :tag
"Other, user-defined function"))
450 (string :tag
"Match (only for some commands)")
451 ,org-agenda-custom-commands-local-options
452 (option (repeat :tag
"Export" (file :tag
"Export to"))))
453 (list :tag
"Command series, all agenda files"
454 (string :tag
"Access Key(s)")
455 (string :tag
"Description ")
456 (repeat :tag
"Component"
459 (const :format
"" agenda
)
460 (const :tag
"" :format
"" "")
461 ,org-agenda-custom-commands-local-options
)
462 (list :tag
"TODO list (all keywords)"
463 (const :format
"" alltodo
)
464 (const :tag
"" :format
"" "")
465 ,org-agenda-custom-commands-local-options
)
466 (list :tag
"Search words"
467 (const :format
"" search
)
468 (string :tag
"Match")
469 ,org-agenda-custom-commands-local-options
)
470 (list :tag
"Stuck projects"
471 (const :format
"" stuck
)
472 (const :tag
"" :format
"" "")
473 ,org-agenda-custom-commands-local-options
)
474 (list :tag
"Tags search"
475 (const :format
"" tags
)
476 (string :tag
"Match")
477 ,org-agenda-custom-commands-local-options
)
478 (list :tag
"Tags search, TODO entries only"
479 (const :format
"" tags-todo
)
480 (string :tag
"Match")
481 ,org-agenda-custom-commands-local-options
)
482 (list :tag
"TODO keyword search"
483 (const :format
"" todo
)
484 (string :tag
"Match")
485 ,org-agenda-custom-commands-local-options
)
486 (list :tag
"Other, user-defined function"
487 (symbol :tag
"function")
488 (string :tag
"Match")
489 ,org-agenda-custom-commands-local-options
)))
491 (repeat :tag
"Settings for entire command set"
492 (list (variable :tag
"Any variable")
493 (sexp :tag
"Value")))
494 (option (repeat :tag
"Export" (file :tag
"Export to"))))
495 (cons :tag
"Prefix key documentation"
496 (string :tag
"Access Key(s)")
497 (string :tag
"Description ")))))
499 (defcustom org-agenda-query-register ?o
500 "The register holding the current query string.
501 The purpose of this is that if you construct a query string interactively,
502 you can then use it to define a custom command."
503 :group
'org-agenda-custom-commands
506 (defcustom org-stuck-projects
507 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
508 "How to identify stuck projects.
509 This is a list of four items:
510 1. A tags/todo/property matcher string that is used to identify a project.
511 See the manual for a description of tag and property searches.
512 The entire tree below a headline matched by this is considered one project.
513 2. A list of TODO keywords identifying non-stuck projects.
514 If the project subtree contains any headline with one of these todo
515 keywords, the project is considered to be not stuck. If you specify
516 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
517 3. A list of tags identifying non-stuck projects.
518 If the project subtree contains any headline with one of these tags,
519 the project is considered to be not stuck. If you specify \"*\" as
520 a tag, any tag will mark the project unstuck. Note that this is about
521 the explicit presence of a tag somewhere in the subtree, inherited
522 tags to not count here. If inherited tags make a project not stuck,
523 use \"-TAG\" in the tags part of the matcher under (1.) above.
524 4. An arbitrary regular expression matching non-stuck projects.
526 If the project turns out to be not stuck, search continues also in the
527 subtree to see if any of the subtasks have project status.
529 See also the variable `org-tags-match-list-sublevels' which applies
530 to projects matched by this search as well.
532 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
533 or `C-c a #' to produce the list."
534 :group
'org-agenda-custom-commands
536 (string :tag
"Tags/TODO match to identify a project")
537 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
538 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
539 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
541 (defcustom org-agenda-filter-effort-default-operator
"<"
542 "The default operator for effort estimate filtering.
543 If you select an effort estimate limit without first pressing an operator,
544 this one will be used."
545 :group
'org-agenda-custom-commands
546 :type
'(choice (const :tag
"less or equal" "<")
547 (const :tag
"greater or equal"">")
548 (const :tag
"equal" "=")))
550 (defgroup org-agenda-skip nil
551 "Options concerning skipping parts of agenda files."
552 :tag
"Org Agenda Skip"
555 (defcustom org-agenda-skip-function-global nil
556 "Function to be called at each match during agenda construction.
557 If this function returns nil, the current match should not be skipped.
558 If the function decided to skip an agenda match, is must return the
559 buffer position from which the search should be continued.
560 This may also be a Lisp form, which will be evaluated.
562 This variable will be applied to every agenda match, including
563 tags/property searches and TODO lists. So try to make the test function
564 do its checking as efficiently as possible. To implement a skipping
565 condition just for specific agenda commands, use the variable
566 `org-agenda-skip-function' which can be set in the options section
567 of custom agenda commands."
568 :group
'org-agenda-skip
571 (defgroup org-agenda-daily
/weekly nil
572 "Options concerning the daily/weekly agenda."
573 :tag
"Org Agenda Daily/Weekly"
575 (defgroup org-agenda-todo-list nil
576 "Options concerning the global todo list agenda view."
577 :tag
"Org Agenda Todo List"
579 (defgroup org-agenda-match-view nil
580 "Options concerning the general tags/property/todo match agenda view."
581 :tag
"Org Agenda Match View"
583 (defgroup org-agenda-search-view nil
584 "Options concerning the general tags/property/todo match agenda view."
585 :tag
"Org Agenda Match View"
588 (defvar org-agenda-archives-mode nil
589 "Non-nil means the agenda will include archived items.
590 If this is the symbol `trees', trees in the selected agenda scope
591 that are marked with the ARCHIVE tag will be included anyway. When this is
592 t, also all archive files associated with the current selection of agenda
593 files will be included.")
595 (defcustom org-agenda-skip-comment-trees t
596 "Non-nil means skip trees that start with the COMMENT keyword.
597 When nil, these trees are also scanned by agenda commands."
598 :group
'org-agenda-skip
601 (defcustom org-agenda-todo-list-sublevels t
602 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
603 When nil, the sublevels of a TODO entry are not checked, resulting in
604 potentially much shorter TODO lists."
605 :group
'org-agenda-skip
606 :group
'org-agenda-todo-list
609 (defcustom org-agenda-todo-ignore-with-date nil
610 "Non-nil means don't show entries with a date in the global todo list.
611 You can use this if you prefer to mark mere appointments with a TODO keyword,
612 but don't want them to show up in the TODO list.
613 When this is set, it also covers deadlines and scheduled items, the settings
614 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
616 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
617 :group
'org-agenda-skip
618 :group
'org-agenda-todo-list
621 (defcustom org-agenda-todo-ignore-timestamp nil
622 "Non-nil means don't show entries with a timestamp.
623 This applies when creating the global todo list.
626 past Don't show entries for today or in the past.
628 future Don't show entries with a timestamp in the future.
629 The idea behind this is that if it has a future
630 timestamp, you don't want to think about it until the
633 all Don't show any entries with a timestamp in the global todo list.
634 The idea behind this is that by setting a timestamp, you
635 have already \"taken care\" of this item.
637 This variable can also have an integer as a value. If positive (N),
638 todos with a timestamp N or more days in the future will be ignored. If
639 negative (-N), todos with a timestamp N or more days in the past will be
640 ignored. If 0, todos with a timestamp either today or in the future will
641 be ignored. For example, a value of -1 will exclude todos with a
642 timestamp in the past (yesterday or earlier), while a value of 7 will
643 exclude todos with a timestamp a week or more in the future.
645 See also `org-agenda-todo-ignore-with-date'.
646 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
647 to make his option also apply to the tags-todo list."
648 :group
'org-agenda-skip
649 :group
'org-agenda-todo-list
651 (const :tag
"Ignore future timestamp todos" future
)
652 (const :tag
"Ignore past or present timestamp todos" past
)
653 (const :tag
"Ignore all timestamp todos" all
)
654 (const :tag
"Show timestamp todos" nil
)
655 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
657 (defcustom org-agenda-todo-ignore-scheduled nil
658 "Non-nil means, ignore some scheduled TODO items when making TODO list.
659 This applies when creating the global todo list.
662 past Don't show entries scheduled today or in the past.
664 future Don't show entries scheduled in the future.
665 The idea behind this is that by scheduling it, you don't want to
666 think about it until the scheduled date.
668 all Don't show any scheduled entries in the global todo list.
669 The idea behind this is that by scheduling it, you have already
670 \"taken care\" of this item.
672 t Same as `all', for backward compatibility.
674 This variable can also have an integer as a value. See
675 `org-agenda-todo-ignore-timestamp' for more details.
677 See also `org-agenda-todo-ignore-with-date'.
678 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
679 to make his option also apply to the tags-todo list."
680 :group
'org-agenda-skip
681 :group
'org-agenda-todo-list
683 (const :tag
"Ignore future-scheduled todos" future
)
684 (const :tag
"Ignore past- or present-scheduled todos" past
)
685 (const :tag
"Ignore all scheduled todos" all
)
686 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
687 (const :tag
"Show scheduled todos" nil
)
688 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
690 (defcustom org-agenda-todo-ignore-deadlines nil
691 "Non-nil means ignore some deadlined TODO items when making TODO list.
692 There are different motivations for using different values, please think
693 carefully when configuring this variable.
695 This applies when creating the global todo list.
698 near Don't show near deadline entries. A deadline is near when it is
699 closer than `org-deadline-warning-days' days. The idea behind this
700 is that such items will appear in the agenda anyway.
702 far Don't show TODO entries where a deadline has been defined, but
703 the deadline is not near. This is useful if you don't want to
704 use the todo list to figure out what to do now.
706 past Don't show entries with a deadline timestamp for today or in the past.
708 future Don't show entries with a deadline timestamp in the future, not even
709 when they become `near' ones. Use it with caution.
711 all Ignore all TODO entries that do have a deadline.
713 t Same as `near', for backward compatibility.
715 This variable can also have an integer as a value. See
716 `org-agenda-todo-ignore-timestamp' for more details.
718 See also `org-agenda-todo-ignore-with-date'.
719 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
720 to make his option also apply to the tags-todo list."
721 :group
'org-agenda-skip
722 :group
'org-agenda-todo-list
724 (const :tag
"Ignore near deadlines" near
)
725 (const :tag
"Ignore near deadlines (compatibility)" t
)
726 (const :tag
"Ignore far deadlines" far
)
727 (const :tag
"Ignore all TODOs with a deadlines" all
)
728 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
729 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
731 (defcustom org-agenda-tags-todo-honor-ignore-options nil
732 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
734 `org-agenda-todo-ignore-with-date',
735 `org-agenda-todo-ignore-timestamp',
736 `org-agenda-todo-ignore-scheduled',
737 `org-agenda-todo-ignore-deadlines'
738 make the global TODO list skip entries that have time stamps of certain
739 kinds. If this option is set, the same options will also apply for the
740 tags-todo search, which is the general tags/property matcher
741 restricted to unfinished TODO entries only."
742 :group
'org-agenda-skip
743 :group
'org-agenda-todo-list
744 :group
'org-agenda-match-view
747 (defcustom org-agenda-skip-scheduled-if-done nil
748 "Non-nil means don't show scheduled items in agenda when they are done.
749 This is relevant for the daily/weekly agenda, not for the TODO list. And
750 it applies only to the actual date of the scheduling. Warnings about
751 an item with a past scheduling dates are always turned off when the item
753 :group
'org-agenda-skip
754 :group
'org-agenda-daily
/weekly
757 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
758 "Non-nil means skip scheduling line if same entry shows because of deadline.
759 In the agenda of today, an entry can show up multiple times because
760 it is both scheduled and has a nearby deadline, and maybe a plain time
762 When this variable is t, then only the deadline is shown and the fact that
763 the entry is scheduled today or was scheduled previously is not shown.
764 When this variable is nil, the entry will be shown several times. When
765 the variable is the symbol `not-today', then skip scheduled previously,
766 but not scheduled today."
767 :group
'org-agenda-skip
768 :group
'org-agenda-daily
/weekly
770 (const :tag
"Never" nil
)
771 (const :tag
"Always" t
)
772 (const :tag
"Not when scheduled today" not-today
)))
774 (defcustom org-agenda-skip-deadline-if-done nil
775 "Non-nil means don't show deadlines when the corresponding item is done.
776 When nil, the deadline is still shown and should give you a happy feeling.
777 This is relevant for the daily/weekly agenda. And it applied only to the
778 actually date of the deadline. Warnings about approaching and past-due
779 deadlines are always turned off when the item is DONE."
780 :group
'org-agenda-skip
781 :group
'org-agenda-daily
/weekly
784 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
785 "Non-nil means skip deadline prewarning when entry is also scheduled.
786 This will apply on all days where a prewarning for the deadline would
787 be shown, but not at the day when the entry is actually due. On that day,
788 the deadline will be shown anyway.
789 This variable may be set to nil, t, or a number which will then give
790 the number of days before the actual deadline when the prewarnings
792 This can be used in a workflow where the first showing of the deadline will
793 trigger you to schedule it, and then you don't want to be reminded of it
794 because you will take care of it on the day when scheduled."
795 :group
'org-agenda-skip
796 :group
'org-agenda-daily
/weekly
798 (const :tag
"Alwas show prewarning" nil
)
799 (const :tag
"Remove prewarning if entry is scheduled" t
)
800 (integer :tag
"Restart prewarning N days before deadline")))
802 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
803 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
804 When non-nil, after the search for timestamps has matched once in an
805 entry, the rest of the entry will not be searched."
806 :group
'org-agenda-skip
809 (defcustom org-agenda-skip-timestamp-if-done nil
810 "Non-nil means don't select item by timestamp or -range if it is DONE."
811 :group
'org-agenda-skip
812 :group
'org-agenda-daily
/weekly
815 (defcustom org-agenda-dim-blocked-tasks t
816 "Non-nil means dim blocked tasks in the agenda display.
817 This causes some overhead during agenda construction, but if you
818 have turned on `org-enforce-todo-dependencies',
819 `org-enforce-todo-checkbox-dependencies', or any other blocking
820 mechanism, this will create useful feedback in the agenda.
822 Instead of t, this variable can also have the value `invisible'.
823 Then blocked tasks will be invisible and only become visible when
824 they become unblocked. An exemption to this behavior is when a task is
825 blocked because of unchecked checkboxes below it. Since checkboxes do
826 not show up in the agenda views, making this task invisible you remove any
827 trace from agenda views that there is something to do. Therefore, a task
828 that is blocked because of checkboxes will never be made invisible, it
829 will only be dimmed."
830 :group
'org-agenda-daily
/weekly
831 :group
'org-agenda-todo-list
833 (const :tag
"Do not dim" nil
)
834 (const :tag
"Dim to a gray face" t
)
835 (const :tag
"Make invisible" invisible
)))
837 (defcustom org-timeline-show-empty-dates
3
838 "Non-nil means `org-timeline' also shows dates without an entry.
839 When nil, only the days which actually have entries are shown.
840 When t, all days between the first and the last date are shown.
841 When an integer, show also empty dates, but if there is a gap of more than
842 N days, just insert a special line indicating the size of the gap."
843 :group
'org-agenda-skip
845 (const :tag
"None" nil
)
847 (integer :tag
"at most")))
849 (defgroup org-agenda-startup nil
850 "Options concerning initial settings in the Agenda in Org Mode."
851 :tag
"Org Agenda Startup"
854 (defcustom org-agenda-menu-show-matcher t
855 "Non-nil means show the match string in the agenda dispatcher menu.
856 When nil, the matcher string is not shown, but is put into the help-echo
857 property so than moving the mouse over the command shows it.
858 Setting it to nil is good if matcher strings are very long and/or if
859 you want to use two-column display (see `org-agenda-menu-two-column')."
863 (defcustom org-agenda-menu-two-column nil
864 "Non-nil means, use two columns to show custom commands in the dispatcher.
865 If you use this, you probably want to set `org-agenda-menu-show-matcher'
870 (defcustom org-finalize-agenda-hook nil
871 "Hook run just before displaying an agenda buffer."
872 :group
'org-agenda-startup
875 (defcustom org-agenda-mouse-1-follows-link nil
876 "Non-nil means mouse-1 on a link will follow the link in the agenda.
877 A longer mouse click will still set point. Does not work on XEmacs.
878 Needs to be set before org.el is loaded."
879 :group
'org-agenda-startup
882 (defcustom org-agenda-start-with-follow-mode nil
883 "The initial value of follow mode in a newly created agenda window."
884 :group
'org-agenda-startup
887 (defcustom org-agenda-follow-indirect nil
888 "Non-nil means `org-agenda-follow-mode' displays only the
889 current item's tree, in an indirect buffer."
893 (defcustom org-agenda-show-outline-path t
894 "Non-nil means show outline path in echo area after line motion."
895 :group
'org-agenda-startup
898 (defcustom org-agenda-start-with-entry-text-mode nil
899 "The initial value of entry-text-mode in a newly created agenda window."
900 :group
'org-agenda-startup
903 (defcustom org-agenda-entry-text-maxlines
5
904 "Number of text lines to be added when `E' is pressed in the agenda.
906 Note that this variable only used during agenda display. Add add entry text
907 when exporting the agenda, configure the variable
908 `org-agenda-add-entry-ext-maxlines'."
912 (defcustom org-agenda-entry-text-exclude-regexps nil
913 "List of regular expressions to clean up entry text.
914 The complete matches of all regular expressions in this list will be
915 removed from entry text before it is shown in the agenda."
917 :type
'(repeat (regexp)))
919 (defvar org-agenda-entry-text-cleanup-hook nil
920 "Hook that is run after basic cleanup of entry text to be shown in agenda.
921 This cleanup is done in a temporary buffer, so the function may inspect and
922 change the entire buffer.
923 Some default stuff like drawers and scheduling/deadline dates will already
924 have been removed when this is called, as will any matches for regular
925 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
927 (defvar org-agenda-include-inactive-timestamps nil
928 "Non-nil means include inactive time stamps in agenda and timeline.")
930 (defgroup org-agenda-windows nil
931 "Options concerning the windows used by the Agenda in Org Mode."
932 :tag
"Org Agenda Windows"
935 (defcustom org-agenda-window-setup
'reorganize-frame
936 "How the agenda buffer should be displayed.
937 Possible values for this option are:
939 current-window Show agenda in the current window, keeping all other windows.
940 other-window Use `switch-to-buffer-other-window' to display agenda.
941 reorganize-frame Show only two windows on the current frame, the current
942 window and the agenda.
943 other-frame Use `switch-to-buffer-other-frame' to display agenda.
944 Also, when exiting the agenda, kill that frame.
945 See also the variable `org-agenda-restore-windows-after-quit'."
946 :group
'org-agenda-windows
948 (const current-window
)
951 (const reorganize-frame
)))
953 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
954 "The min and max height of the agenda window as a fraction of frame height.
955 The value of the variable is a cons cell with two numbers between 0 and 1.
956 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
957 :group
'org-agenda-windows
958 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
960 (defcustom org-agenda-restore-windows-after-quit nil
961 "Non-nil means restore window configuration upon exiting agenda.
962 Before the window configuration is changed for displaying the agenda,
963 the current status is recorded. When the agenda is exited with
964 `q' or `x' and this option is set, the old state is restored. If
965 `org-agenda-window-setup' is `other-frame', the value of this
966 option will be ignored."
967 :group
'org-agenda-windows
970 (defcustom org-agenda-ndays nil
971 "Number of days to include in overview display.
973 Obsolete, see `org-agenda-span'."
974 :group
'org-agenda-daily
/weekly
977 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
979 (defcustom org-agenda-span
'week
980 "Number of days to include in overview display.
981 Can be day, week, month, year, or any number of days.
982 Custom commands can set this variable in the options section."
983 :group
'org-agenda-daily
/weekly
984 :type
'(choice (const :tag
"Day" day
)
985 (const :tag
"Week" week
)
986 (const :tag
"Month" month
)
987 (const :tag
"Year" year
)
988 (integer :tag
"Custom")))
990 (defcustom org-agenda-start-on-weekday
1
991 "Non-nil means start the overview always on the specified weekday.
992 0 denotes Sunday, 1 denotes Monday etc.
993 When nil, always start on the current day.
994 Custom commands can set this variable in the options section."
995 :group
'org-agenda-daily
/weekly
996 :type
'(choice (const :tag
"Today" nil
)
997 (integer :tag
"Weekday No.")))
999 (defcustom org-agenda-show-all-dates t
1000 "Non-nil means `org-agenda' shows every day in the selected range.
1001 When nil, only the days which actually have entries are shown."
1002 :group
'org-agenda-daily
/weekly
1005 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1006 "Format string for displaying dates in the agenda.
1007 Used by the daily/weekly agenda and by the timeline. This should be
1008 a format string understood by `format-time-string', or a function returning
1009 the formatted date as a string. The function must take a single argument,
1010 a calendar-style date list like (month day year)."
1011 :group
'org-agenda-daily
/weekly
1013 (string :tag
"Format string")
1014 (function :tag
"Function")))
1016 (defun org-agenda-format-date-aligned (date)
1017 "Format a date string for display in the daily/weekly agenda, or timeline.
1018 This function makes sure that dates are aligned for easy reading."
1020 (let* ((dayname (calendar-day-name date
))
1022 (day-of-week (calendar-day-of-week date
))
1024 (monthname (calendar-month-name month
))
1026 (iso-week (org-days-to-iso-week
1027 (calendar-absolute-from-gregorian date
)))
1028 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1030 ((and (= month
12) (<= iso-week
1))
1033 (weekstring (if (= day-of-week
1)
1034 (format " W%02d" iso-week
)
1036 (format "%-10s %2d %s %4d%s"
1037 dayname day monthname year weekstring
)))
1039 (defcustom org-agenda-time-leading-zero nil
1040 "Non-nil means use leading zero for military times in agenda.
1041 For example, 9:30am would become 09:30 rather than 9:30."
1042 :group
'org-agenda-daily
/weekly
1045 (defcustom org-agenda-timegrid-use-ampm nil
1046 "When set, show AM/PM style timestamps on the timegrid."
1050 (defun org-agenda-time-of-day-to-ampm (time)
1051 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1052 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1053 (minute (substring time -
2))
1056 ((equal hour-number
12)
1060 (setq hour-number
(- hour-number
12))))
1062 (if org-agenda-time-leading-zero
1063 (format "%02d" hour-number
)
1064 (format "%02s" (number-to-string hour-number
)))
1067 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1068 "Conditionally convert TIME to AM/PM format
1069 based on `org-agenda-timegrid-use-ampm'"
1070 (if org-agenda-timegrid-use-ampm
1071 (org-agenda-time-of-day-to-ampm time
)
1074 (defcustom org-agenda-weekend-days
'(6 0)
1075 "Which days are weekend?
1076 These days get the special face `org-agenda-date-weekend' in the agenda
1077 and timeline buffers."
1078 :group
'org-agenda-daily
/weekly
1079 :type
'(set :greedy t
1080 (const :tag
"Monday" 1)
1081 (const :tag
"Tuesday" 2)
1082 (const :tag
"Wednesday" 3)
1083 (const :tag
"Thursday" 4)
1084 (const :tag
"Friday" 5)
1085 (const :tag
"Saturday" 6)
1086 (const :tag
"Sunday" 0)))
1088 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1089 "Non-nil means jump to today when moving a past date forward in time.
1090 When using S-right in the agenda to move a a date forward, and the date
1091 stamp currently points to the past, the first key press will move it
1092 to today. WHen nil, just move one day forward even if the date stays
1094 :group
'org-agenda-daily
/weekly
1097 (defcustom org-agenda-include-diary nil
1098 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1099 Custom commands can set this variable in the options section."
1100 :group
'org-agenda-daily
/weekly
1103 (defcustom org-agenda-include-deadlines t
1104 "If non-nil, include entries within their deadline warning period.
1105 Custom commands can set this variable in the options section."
1106 :group
'org-agenda-daily
/weekly
1109 (defcustom org-agenda-repeating-timestamp-show-all t
1110 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1111 When set to a list of strings, only show occurrences of repeating
1112 stamps for these TODO keywords. When nil, only one occurrence is
1113 shown, either today or the nearest into the future."
1114 :group
'org-agenda-daily
/weekly
1116 (const :tag
"Show repeating stamps" t
)
1117 (repeat :tag
"Show repeating stamps for these TODO keywords"
1118 (string :tag
"TODO Keyword"))
1119 (const :tag
"Don't show repeating stamps" nil
)))
1121 (defcustom org-scheduled-past-days
10000
1122 "No. of days to continue listing scheduled items that are not marked DONE.
1123 When an item is scheduled on a date, it shows up in the agenda on this
1124 day and will be listed until it is marked done for the number of days
1126 :group
'org-agenda-daily
/weekly
1129 (defcustom org-agenda-log-mode-items
'(closed clock
)
1130 "List of items that should be shown in agenda log mode.
1131 This list may contain the following symbols:
1133 closed Show entries that have been closed on that day.
1134 clock Show entries that have received clocked time on that day.
1135 state Show all logged state changes.
1136 Note that instead of changing this variable, you can also press `C-u l' in
1137 the agenda to display all available LOG items temporarily."
1138 :group
'org-agenda-daily
/weekly
1139 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1141 (defcustom org-agenda-clock-consistency-checks
1142 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1143 :gap-ok-around
("4:00")
1144 :default-face
((:background
"DarkRed") (:foreground
"white"))
1145 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1146 :long-face nil
:short-face nil
)
1147 "This is a property list, with the following keys:
1149 :max-duration Mark clocking chunks that are longer than this time.
1150 This is a time string like \"HH:MM\", or the number
1151 of minutes as an integer.
1153 :min-duration Mark clocking chunks that are shorter that this.
1154 This is a time string like \"HH:MM\", or the number
1155 of minutes as an integer.
1157 :max-gap Mark gaps between clocking chunks that are longer than
1158 this duration. A number of minutes, or a string
1161 :gap-ok-around List of times during the day which are usually not working
1162 times. When a gap is detected, but the gap contains any
1163 of these times, the gap is *not* reported. For example,
1164 if this is (\"4:00\" \"13:00\") then gaps that contain
1165 4:00 in the morning (i.e. the night) and 13:00
1166 (i.e. a typical lunch time) do not cause a warning.
1167 You should have at least one time during the night in this
1168 list, or otherwise the first task each morning will trigger
1169 a warning because it follows a long gap.
1171 Furthermore, the following properties can be used to define faces for
1174 :default-face the default face, if the specific face is undefined
1175 :overlap-face face for overlapping clocks
1176 :gap-face face for gaps between clocks
1177 :no-end-time-face face for incomplete clocks
1178 :long-face face for clock intervals that are too long
1179 :short-face face for clock intervals that are too short"
1180 :group
'org-agenda-daily
/weekly
1184 (defcustom org-agenda-log-mode-add-notes t
1185 "Non-nil means add first line of notes to log entries in agenda views.
1186 If a log item like a state change or a clock entry is associated with
1187 notes, the first line of these notes will be added to the entry in the
1189 :group
'org-agenda-daily
/weekly
1192 (defcustom org-agenda-start-with-log-mode nil
1193 "The initial value of log-mode in a newly created agenda window."
1194 :group
'org-agenda-startup
1195 :group
'org-agenda-daily
/weekly
1198 (defcustom org-agenda-start-with-clockreport-mode nil
1199 "The initial value of clockreport-mode in a newly created agenda window."
1200 :group
'org-agenda-startup
1201 :group
'org-agenda-daily
/weekly
1204 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1205 "Property list with parameters for the clocktable in clockreport mode.
1206 This is the display mode that shows a clock table in the daily/weekly
1207 agenda, the properties for this dynamic block can be set here.
1208 The usual clocktable parameters are allowed here, but you cannot set
1209 the properties :name, :tstart, :tend, :block, and :scope - these will
1210 be overwritten to make sure the content accurately reflects the
1211 current display in the agenda."
1212 :group
'org-agenda-daily
/weekly
1215 (defcustom org-agenda-search-view-always-boolean nil
1216 "Non-nil means the search string is interpreted as individual parts.
1218 The search string for search view can either be interpreted as a phrase,
1219 or as a list of snippets that define a boolean search for a number of
1222 When this is non-nil, the string will be split on whitespace, and each
1223 snippet will be searched individually, and all must match in order to
1224 select an entry. A snippet is then a single string of non-white
1225 characters, or a string in double quotes, or a regexp in {} braces.
1226 If a snippet is preceded by \"-\", the snippet must *not* match.
1227 \"+\" is syntactic sugar for positive selection. Each snippet may
1228 be found as a full word or a partial word, but see the variable
1229 `org-agenda-search-view-force-full-words'.
1231 When this is nil, search will look for the entire search phrase as one,
1232 with each space character matching any amount of whitespace, including
1235 Even when this is nil, you can still switch to Boolean search dynamically
1236 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1237 is a regexp marked with braces like \"{abc}\", this will also switch to
1239 :group
'org-agenda-search-view
1242 (if (fboundp 'defvaralias
)
1243 (defvaralias 'org-agenda-search-view-search-words-only
1244 'org-agenda-search-view-always-boolean
))
1246 (defcustom org-agenda-search-view-force-full-words nil
1247 "Non-nil means, search words must be matches as complete words.
1248 When nil, they may also match part of a word."
1249 :group
'org-agenda-search-view
1252 (defgroup org-agenda-time-grid nil
1253 "Options concerning the time grid in the Org-mode Agenda."
1254 :tag
"Org Agenda Time Grid"
1257 (defcustom org-agenda-search-headline-for-time t
1258 "Non-nil means search headline for a time-of-day.
1259 If the headline contains a time-of-day in one format or another, it will
1260 be used to sort the entry into the time sequence of items for a day.
1261 Some people have time stamps in the headline that refer to the creation
1262 time or so, and then this produces an unwanted side effect. If this is
1263 the case for your, use this variable to turn off searching the headline
1265 :group
'org-agenda-time-grid
1268 (defcustom org-agenda-use-time-grid t
1269 "Non-nil means show a time grid in the agenda schedule.
1270 A time grid is a set of lines for specific times (like every two hours between
1271 8:00 and 20:00). The items scheduled for a day at specific times are
1272 sorted in between these lines.
1273 For details about when the grid will be shown, and what it will look like, see
1274 the variable `org-agenda-time-grid'."
1275 :group
'org-agenda-time-grid
1278 (defcustom org-agenda-time-grid
1279 '((daily today require-timed
)
1281 (800 1000 1200 1400 1600 1800 2000))
1283 "The settings for time grid for agenda display.
1284 This is a list of three items. The first item is again a list. It contains
1285 symbols specifying conditions when the grid should be displayed:
1287 daily if the agenda shows a single day
1288 weekly if the agenda shows an entire week
1289 today show grid on current date, independent of daily/weekly display
1290 require-timed show grid only if at least one item has a time specification
1292 The second item is a string which will be placed behind the grid time.
1294 The third item is a list of integers, indicating the times that should have
1296 :group
'org-agenda-time-grid
1299 (set :greedy t
:tag
"Grid Display Options"
1300 (const :tag
"Show grid in single day agenda display" daily
)
1301 (const :tag
"Show grid in weekly agenda display" weekly
)
1302 (const :tag
"Always show grid for today" today
)
1303 (const :tag
"Show grid only if any timed entries are present"
1305 (const :tag
"Skip grid times already present in an entry"
1307 (string :tag
"Grid String")
1308 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1310 (defcustom org-agenda-show-current-time-in-grid t
1311 "Non-nil means show the current time in the time grid."
1312 :group
'org-agenda-time-grid
1315 (defcustom org-agenda-current-time-string
1316 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1317 "The string for the current time marker in the agenda."
1318 :group
'org-agenda-time-grid
1321 (defgroup org-agenda-sorting nil
1322 "Options concerning sorting in the Org-mode Agenda."
1323 :tag
"Org Agenda Sorting"
1326 (defcustom org-agenda-sorting-strategy
1327 '((agenda habit-down time-up priority-down category-keep
)
1328 (todo priority-down category-keep
)
1329 (tags priority-down category-keep
)
1330 (search category-keep
))
1331 "Sorting structure for the agenda items of a single day.
1332 This is a list of symbols which will be used in sequence to determine
1333 if an entry should be listed before another entry. The following
1334 symbols are recognized:
1336 time-up Put entries with time-of-day indications first, early first
1337 time-down Put entries with time-of-day indications first, late first
1338 category-keep Keep the default order of categories, corresponding to the
1339 sequence in `org-agenda-files'.
1340 category-up Sort alphabetically by category, A-Z.
1341 category-down Sort alphabetically by category, Z-A.
1342 tag-up Sort alphabetically by last tag, A-Z.
1343 tag-down Sort alphabetically by last tag, Z-A.
1344 priority-up Sort numerically by priority, high priority last.
1345 priority-down Sort numerically by priority, high priority first.
1346 todo-state-up Sort by todo state, tasks that are done last.
1347 todo-state-down Sort by todo state, tasks that are done first.
1348 effort-up Sort numerically by estimated effort, high effort last.
1349 effort-down Sort numerically by estimated effort, high effort first.
1350 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1351 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1352 habit-up Put entries that are habits first
1353 habit-down Put entries that are habits last
1354 alpha-up Sort headlines alphabetically
1355 alpha-down Sort headlines alphabetically, reversed
1357 The different possibilities will be tried in sequence, and testing stops
1358 if one comparison returns a \"not-equal\". For example, the default
1359 '(time-up category-keep priority-down)
1360 means: Pull out all entries having a specified time of day and sort them,
1361 in order to make a time schedule for the current day the first thing in the
1362 agenda listing for the day. Of the entries without a time indication, keep
1363 the grouped in categories, don't sort the categories, but keep them in
1364 the sequence given in `org-agenda-files'. Within each category sort by
1367 Leaving out `category-keep' would mean that items will be sorted across
1368 categories by priority.
1370 Instead of a single list, this can also be a set of list for specific
1371 contents, with a context symbol in the car of the list, any of
1372 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1374 Custom commands can bind this variable in the options section."
1375 :group
'org-agenda-sorting
1377 (repeat :tag
"General" ,org-sorting-choice
)
1378 (list :tag
"Individually"
1379 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1380 (repeat ,org-sorting-choice
))
1381 (cons (const :tag
"Strategy for TODO lists" todo
)
1382 (repeat ,org-sorting-choice
))
1383 (cons (const :tag
"Strategy for Tags matches" tags
)
1384 (repeat ,org-sorting-choice
))
1385 (cons (const :tag
"Strategy for search matches" search
)
1386 (repeat ,org-sorting-choice
)))))
1388 (defcustom org-agenda-cmp-user-defined nil
1389 "A function to define the comparison `user-defined'.
1390 This function must receive two arguments, agenda entry a and b.
1391 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1392 the user comparison, return nil.
1393 When this is defined, you can make `user-defined-up' and `user-defined-down'
1394 part of an agenda sorting strategy."
1395 :group
'org-agenda-sorting
1398 (defcustom org-sort-agenda-notime-is-late t
1399 "Non-nil means items without time are considered late.
1400 This is only relevant for sorting. When t, items which have no explicit
1401 time like 15:30 will be considered as 99:01, i.e. later than any items which
1402 do have a time. When nil, the default time is before 0:00. You can use this
1403 option to decide if the schedule for today should come before or after timeless
1405 :group
'org-agenda-sorting
1408 (defcustom org-sort-agenda-noeffort-is-high t
1409 "Non-nil means items without effort estimate are sorted as high effort.
1410 This also applies when filtering an agenda view with respect to the
1411 < or > effort operator. Then, tasks with no effort defined will be treated
1412 as tasks with high effort.
1413 When nil, such items are sorted as 0 minutes effort."
1414 :group
'org-agenda-sorting
1417 (defgroup org-agenda-line-format nil
1418 "Options concerning the entry prefix in the Org-mode agenda display."
1419 :tag
"Org Agenda Line Format"
1422 (defcustom org-agenda-prefix-format
1423 '((agenda .
" %i %-12:c%?-12t% s")
1425 (todo .
" %i %-12:c")
1426 (tags .
" %i %-12:c")
1427 (search .
" %i %-12:c"))
1428 "Format specifications for the prefix of items in the agenda views.
1429 An alist with five entries, each for the different agenda types. The
1430 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1431 The values are format strings.
1433 This format works similar to a printf format, with the following meaning:
1435 %c the category of the item, \"Diary\" for entries from the diary,
1436 or as given by the CATEGORY keyword or derived from the file name
1437 %e the effort required by the item
1438 %i the icon category of the item, see `org-agenda-category-icon-alist'
1439 %T the last tag of the item (ignore inherited tags, which come first)
1440 %t the HH:MM time-of-day specification if one applies to the entry
1441 %s Scheduling/Deadline information, a short string
1442 %(expression) Eval EXPRESSION and replace the control string
1445 All specifiers work basically like the standard `%s' of printf, but may
1446 contain two additional characters: a question mark just after the `%'
1447 and a whitespace/punctuation character just before the final letter.
1449 If the first character after `%' is a question mark, the entire field
1450 will only be included if the corresponding value applies to the current
1451 entry. This is useful for fields which should have fixed width when
1452 present, but zero width when absent. For example, \"%?-12t\" will
1453 result in a 12 character time field if a time of the day is specified,
1454 but will completely disappear in entries which do not contain a time.
1456 If there is punctuation or whitespace character just before the final
1457 format letter, this character will be appended to the field value if
1458 the value is not empty. For example, the format \"%-12:c\" leads to
1459 \"Diary: \" if the category is \"Diary\". If the category were be
1460 empty, no additional colon would be inserted.
1462 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1465 - Indent the line with two space characters
1466 - Give the category a 12 chars wide field, padded with whitespace on
1467 the right (because of `-'). Append a colon if there is a category
1469 - If there is a time-of-day, put it into a 12 chars wide field. If no
1470 time, don't put in an empty field, just skip it (because of '?').
1471 - Finally, put the scheduling information.
1473 See also the variables `org-agenda-remove-times-when-in-prefix' and
1474 `org-agenda-remove-tags'.
1476 Custom commands can set this variable in the options section."
1478 (string :tag
"General format")
1479 (list :greedy t
:tag
"View dependent"
1480 (cons (const agenda
) (string :tag
"Format"))
1481 (cons (const timeline
) (string :tag
"Format"))
1482 (cons (const todo
) (string :tag
"Format"))
1483 (cons (const tags
) (string :tag
"Format"))
1484 (cons (const search
) (string :tag
"Format"))))
1485 :group
'org-agenda-line-format
)
1487 (defvar org-prefix-format-compiled nil
1488 "The compiled version of the most recently used prefix format.
1489 See the variable `org-agenda-prefix-format'.")
1491 (defcustom org-agenda-todo-keyword-format
"%-1s"
1492 "Format for the TODO keyword in agenda lines.
1493 Set this to something like \"%-12s\" if you want all TODO keywords
1494 to occupy a fixed space in the agenda display."
1495 :group
'org-agenda-line-format
1498 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1499 "Text preceding timerange entries in the agenda view.
1500 This is a list with two strings. The first applies when the range
1501 is entirely on one day. The second applies if the range spans several days.
1502 The strings may have two \"%d\" format specifiers which will be filled
1503 with the sequence number of the days, and the total number of days in the
1504 range, respectively."
1505 :group
'org-agenda-line-format
1507 (string :tag
"Deadline today ")
1508 (choice :tag
"Deadline relative"
1509 (string :tag
"Format string")
1512 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1513 "Text preceding scheduled items in the agenda view.
1514 This is a list with two strings. The first applies when the item is
1515 scheduled on the current day. The second applies when it has been scheduled
1516 previously, it may contain a %d indicating that this is the nth time that
1517 this item is scheduled, due to automatic rescheduling of unfinished items
1518 for the following day. So this number is one larger than the number of days
1519 that passed since this item was scheduled first."
1520 :group
'org-agenda-line-format
1522 (string :tag
"Scheduled today ")
1523 (string :tag
"Scheduled previously")))
1525 (defcustom org-agenda-inactive-leader
"["
1526 "Text preceding item pulled into the agenda by inactive time stamps.
1527 These entries are added to the agenda when pressing \"[\"."
1528 :group
'org-agenda-line-format
1530 (string :tag
"Scheduled today ")
1531 (string :tag
"Scheduled previously")))
1533 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1534 "Text preceding deadline items in the agenda view.
1535 This is a list with two strings. The first applies when the item has its
1536 deadline on the current day. The second applies when it is in the past or
1537 in the future, it may contain %d to capture how many days away the deadline
1539 :group
'org-agenda-line-format
1541 (string :tag
"Deadline today ")
1542 (choice :tag
"Deadline relative"
1543 (string :tag
"Format string")
1546 (defcustom org-agenda-remove-times-when-in-prefix t
1547 "Non-nil means remove duplicate time specifications in agenda items.
1548 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1549 time-of-day specification in a headline or diary entry is extracted and
1550 placed into the prefix. If this option is non-nil, the original specification
1551 \(a timestamp or -range, or just a plain time(range) specification like
1552 11:30-4pm) will be removed for agenda display. This makes the agenda less
1554 The option can be t or nil. It may also be the symbol `beg', indicating
1555 that the time should only be removed when it is located at the beginning of
1556 the headline/diary entry."
1557 :group
'org-agenda-line-format
1559 (const :tag
"Always" t
)
1560 (const :tag
"Never" nil
)
1561 (const :tag
"When at beginning of entry" beg
)))
1563 (defcustom org-agenda-remove-timeranges-from-blocks nil
1564 "Non-nil means remove time ranges specifications in agenda
1565 items that span on several days."
1566 :group
'org-agenda-line-format
1569 (defcustom org-agenda-default-appointment-duration nil
1570 "Default duration for appointments that only have a starting time.
1571 When nil, no duration is specified in such cases.
1572 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1573 :group
'org-agenda-line-format
1575 (integer :tag
"Minutes")
1576 (const :tag
"No default duration")))
1578 (defcustom org-agenda-show-inherited-tags t
1579 "Non-nil means show inherited tags in each agenda line."
1580 :group
'org-agenda-line-format
1583 (defcustom org-agenda-hide-tags-regexp nil
1584 "Regular expression used to filter away specific tags in agenda views.
1585 This means that these tags will be present, but not be shown in the agenda
1586 line. Secondary filtering will still work on the hidden tags.
1587 Nil means don't hide any tags."
1588 :group
'org-agenda-line-format
1590 (const :tag
"Hide none" nil
)
1591 (string :tag
"Regexp ")))
1593 (defcustom org-agenda-remove-tags nil
1594 "Non-nil means remove the tags from the headline copy in the agenda.
1595 When this is the symbol `prefix', only remove tags when
1596 `org-agenda-prefix-format' contains a `%T' specifier."
1597 :group
'org-agenda-line-format
1599 (const :tag
"Always" t
)
1600 (const :tag
"Never" nil
)
1601 (const :tag
"When prefix format contains %T" prefix
)))
1603 (if (fboundp 'defvaralias
)
1604 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1605 'org-agenda-remove-tags
))
1607 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1608 "Shift tags in agenda items to this column.
1609 If this number is positive, it specifies the column. If it is negative,
1610 it means that the tags should be flushright to that column. For example,
1611 -80 works well for a normal 80 character screen."
1612 :group
'org-agenda-line-format
1615 (if (fboundp 'defvaralias
)
1616 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1618 (defcustom org-agenda-fontify-priorities
'cookies
1619 "Non-nil means highlight low and high priorities in agenda.
1620 When t, the highest priority entries are bold, lowest priority italic.
1621 However, settings in `org-priority-faces' will overrule these faces.
1622 When this variable is the symbol `cookies', only fontify the
1623 cookies, not the entire task.
1624 This may also be an association list of priority faces, whose
1625 keys are the character values of `org-highest-priority',
1626 `org-default-priority', and `org-lowest-priority' (the default values
1627 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1628 color as a string, or a list like `(:background \"Red\")'.
1629 If it is a color, the variable `org-faces-easy-properties'
1630 determines if it is a foreground or a background color."
1631 :group
'org-agenda-line-format
1633 (const :tag
"Never" nil
)
1634 (const :tag
"Defaults" t
)
1635 (const :tag
"Cookies only" cookies
)
1636 (repeat :tag
"Specify"
1637 (list (character :tag
"Priority" :value ?A
)
1638 (choice :tag
"Face "
1639 (string :tag
"Color")
1640 (sexp :tag
"Face"))))))
1642 (defcustom org-agenda-day-face-function nil
1643 "Function called to determine what face should be used to display a day.
1644 The only argument passed to that function is the day. It should
1645 returns a face, or nil if does not want to specify a face and let
1646 the normal rules apply."
1647 :group
'org-agenda-line-format
1650 (defcustom org-agenda-category-icon-alist nil
1651 "Alist of category icon to be displayed in agenda views.
1653 Each entry should have the following format:
1655 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1657 Where CATEGORY-REGEXP is a regexp matching the categories where
1658 the icon should be displayed.
1659 FILE-OR-DATA either a file path or a string containing image data.
1661 The other fields can be omitted safely if not needed:
1662 TYPE indicates the image type.
1663 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1665 PROPS are additional image attributes to assign to the image,
1666 like, e.g. `:ascent center'.
1668 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1670 If you want to set the display properties yourself, just put a
1671 list as second element:
1673 (CATEGORY-REGEXP (MY PROPERTY LIST))
1675 For example, to display a 16px horizontal space for Emacs
1676 category, you can use:
1678 (\"Emacs\" '(space . (:width (16))))"
1679 :group
'org-agenda-line-format
1680 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1681 :value-type
(choice (list :tag
"Icon"
1682 (string :tag
"File or data")
1683 (symbol :tag
"Type")
1684 (boolean :tag
"Data?")
1685 (repeat :tag
"Extra image properties" :inline t symbol
))
1686 (list :tag
"Display properties" sexp
))))
1688 (defgroup org-agenda-column-view nil
1689 "Options concerning column view in the agenda."
1690 :tag
"Org Agenda Column View"
1693 (defcustom org-agenda-columns-show-summaries t
1694 "Non-nil means show summaries for columns displayed in the agenda view."
1695 :group
'org-agenda-column-view
1698 (defcustom org-agenda-columns-compute-summary-properties t
1699 "Non-nil means recompute all summary properties before column view.
1700 When column view in the agenda is listing properties that have a summary
1701 operator, it can go to all relevant buffers and recompute the summaries
1702 there. This can mean overhead for the agenda column view, but is necessary
1703 to have thing up to date.
1704 As a special case, a CLOCKSUM property also makes sure that the clock
1705 computations are current."
1706 :group
'org-agenda-column-view
1709 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1710 "Non-nil means the duration of an appointment will add to day effort.
1711 The property to which appointment durations will be added is the one given
1712 in the option `org-effort-property'. If an appointment does not have
1713 an end time, `org-agenda-default-appointment-duration' will be used. If that
1714 is not set, an appointment without end time will not contribute to the time
1716 :group
'org-agenda-column-view
1719 (defcustom org-agenda-auto-exclude-function nil
1720 "A function called with a tag to decide if it is filtered on '/ RET'.
1721 The sole argument to the function, which is called once for each
1722 possible tag, is a string giving the name of the tag. The
1723 function should return either nil if the tag should be included
1724 as normal, or \"-<TAG>\" to exclude the tag.
1725 Note that for the purpose of tag filtering, only the lower-case version of
1726 all tags will be considered, so that this function will only ever see
1727 the lower-case version of all tags."
1731 (defcustom org-agenda-bulk-custom-functions nil
1732 "Alist of characters and custom functions for bulk actions.
1733 For example, this value makes those two functions available:
1738 With selected entries in an agenda buffer, `B R' will call
1739 the custom function `set-category' on the selected entries.
1740 Note that functions in this alist don't need to be quoted."
1748 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
1749 "Execute BODY with point at location given by `org-hd-marker' property.
1750 If STRING is non-nil, the text property will be fetched from position 0
1751 in that string. If STRING is nil, it will be fetched from the beginning
1752 of the current line."
1753 (org-with-gensyms (marker)
1754 `(let ((,marker
(get-text-property (if string
0 (point-at-bol))
1755 'org-hd-marker
,string
)))
1756 (with-current-buffer (marker-buffer ,marker
)
1760 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
1762 (defun org-add-agenda-custom-command (entry)
1763 "Replace or add a command in `org-agenda-custom-commands'.
1764 This is mostly for hacking and trying a new command - once the command
1765 works you probably want to add it to `org-agenda-custom-commands' for good."
1766 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1768 (setcdr ass
(cdr entry
))
1769 (push entry org-agenda-custom-commands
))))
1771 ;;; Define the Org-agenda-mode
1773 (defvar org-agenda-mode-map
(make-sparse-keymap)
1774 "Keymap for `org-agenda-mode'.")
1775 (if (fboundp 'defvaralias
)
1776 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1778 (defvar org-agenda-menu
) ; defined later in this file.
1779 (defvar org-agenda-restrict
) ; defined later in this file.
1780 (defvar org-agenda-follow-mode nil
)
1781 (defvar org-agenda-entry-text-mode nil
)
1782 (defvar org-agenda-clockreport-mode nil
)
1783 (defvar org-agenda-show-log nil
)
1784 (defvar org-agenda-redo-command nil
)
1785 (defvar org-agenda-query-string nil
)
1786 (defvar org-agenda-mode-hook nil
1787 "Hook for `org-agenda-mode', run after the mode is turned on.")
1788 (defvar org-agenda-type nil
)
1789 (defvar org-agenda-force-single-file nil
)
1790 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1792 (defun org-agenda-mode ()
1793 "Mode for time-sorted view on action items in Org-mode files.
1795 The following commands are available:
1797 \\{org-agenda-mode-map}"
1799 (kill-all-local-variables)
1800 (setq org-agenda-undo-list nil
1801 org-agenda-pending-undo-list nil
1802 org-agenda-bulk-marked-entries nil
)
1803 (setq major-mode
'org-agenda-mode
)
1804 ;; Keep global-font-lock-mode from turning on font-lock-mode
1805 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1806 (setq mode-name
"Org-Agenda")
1807 (use-local-map org-agenda-mode-map
)
1808 (easy-menu-add org-agenda-menu
)
1809 (if org-startup-truncated
(setq truncate-lines t
))
1810 (org-set-local 'line-move-visual nil
)
1811 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1812 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1813 ;; Make sure properties are removed when copying text
1814 (when (boundp 'buffer-substring-filters
)
1815 (org-set-local 'buffer-substring-filters
1817 (set-text-properties 0 (length x
) nil x
) x
)
1818 buffer-substring-filters
)))
1819 (unless org-agenda-keep-modes
1820 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1821 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1822 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1823 org-agenda-show-log org-agenda-start-with-log-mode
))
1826 '("Agenda") "Agenda Files"
1830 (if (get 'org-agenda-files
'org-restrict
)
1831 "Restricted to single file"
1833 '(org-edit-agenda-file-list)
1834 (not (get 'org-agenda-files
'org-restrict
)))
1836 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1837 (org-agenda-set-mode-name)
1839 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1840 (list 'org-agenda-mode-hook
)))
1842 (substitute-key-definition 'undo
'org-agenda-undo
1843 org-agenda-mode-map global-map
)
1844 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1845 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1846 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1847 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1848 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1849 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1850 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
1851 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1852 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1853 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
1854 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1855 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1856 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1857 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1858 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1859 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1860 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1861 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1862 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1863 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1864 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1865 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1866 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1867 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1868 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1869 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1870 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1871 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1872 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1873 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1874 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1875 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1876 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1877 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1878 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1879 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1880 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1881 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1882 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1883 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1884 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1885 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1886 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1887 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1888 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1890 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1891 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1892 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1893 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1894 (while l (org-defkey org-agenda-mode-map
1895 (int-to-string (pop l)) 'digit-argument)))
1897 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1898 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1899 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1900 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1901 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1902 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1903 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1904 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1905 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1906 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1907 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1908 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1909 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1910 'org-clock-modify-effort-estimate)
1911 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1912 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1913 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1914 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
1915 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1916 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1917 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1918 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1919 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1920 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1921 (substitute-key-definition 'next-line 'org-agenda-next-line
1922 org-agenda-mode-map global-map)
1923 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1924 org-agenda-mode-map global-map)
1925 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1926 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1927 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1928 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1929 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1930 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1931 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1932 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1933 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1934 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1935 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1936 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1937 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1938 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1939 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1940 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1941 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1942 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1943 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1944 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1945 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1946 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1947 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1948 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1949 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1950 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1951 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1952 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1953 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1954 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1956 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1957 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1958 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1959 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1960 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1961 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1962 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
1963 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1964 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1965 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1966 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1968 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1969 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1970 (when org-agenda-mouse-1-follows-link
1971 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1972 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1977 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1978 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1979 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1980 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1983 ["Day View" org-agenda-day-view
1984 :active (org-agenda-check-type nil 'agenda)
1985 :style radio :selected (eq org-agenda-current-span 'day)
1986 :keys "v d (or just d)"]
1987 ["Week View" org-agenda-week-view
1988 :active (org-agenda-check-type nil 'agenda)
1989 :style radio :selected (eq org-agenda-current-span 'week)
1990 :keys "v w (or just w)"]
1991 ["Month View" org-agenda-month-view
1992 :active (org-agenda-check-type nil 'agenda)
1993 :style radio :selected (eq org-agenda-current-span 'month)
1995 ["Year View" org-agenda-year-view
1996 :active (org-agenda-check-type nil 'agenda)
1997 :style radio :selected (eq org-agenda-current-span 'year)
2000 ["Include Diary" org-agenda-toggle-diary
2001 :style toggle :selected org-agenda-include-diary
2002 :active (org-agenda-check-type nil 'agenda)]
2003 ["Include Deadlines" org-agenda-toggle-deadlines
2004 :style toggle :selected org-agenda-include-deadlines
2005 :active (org-agenda-check-type nil 'agenda)]
2006 ["Use Time Grid" org-agenda-toggle-time-grid
2007 :style toggle :selected org-agenda-use-time-grid
2008 :active (org-agenda-check-type nil 'agenda)]
2010 ["Show clock report" org-agenda-clockreport-mode
2011 :style toggle :selected org-agenda-clockreport-mode
2012 :active (org-agenda-check-type nil 'agenda)]
2013 ["Show some entry text" org-agenda-entry-text-mode
2014 :style toggle :selected org-agenda-entry-text-mode
2017 ["Show Logbook entries" org-agenda-log-mode
2018 :style toggle :selected org-agenda-show-log
2019 :active (org-agenda-check-type nil 'agenda 'timeline)
2020 :keys "v l (or just l)"]
2021 ["Include archived trees" org-agenda-archives-mode
2022 :style toggle :selected org-agenda-archives-mode :active t
2024 ["Include archive files" (org-agenda-archives-mode t)
2025 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2028 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2029 ["Write view to file" org-agenda-write t]
2030 ["Rebuild buffer" org-agenda-redo t]
2031 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2033 ["Show original entry" org-agenda-show t]
2034 ["Go To (other window)" org-agenda-goto t]
2035 ["Go To (this window)" org-agenda-switch-to t]
2036 ["Follow Mode" org-agenda-follow-mode
2037 :style toggle :selected org-agenda-follow-mode :active t]
2038 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2041 ["Cycle TODO" org-agenda-todo t]
2042 ["Next TODO set" org-agenda-todo-nextset t]
2043 ["Previous TODO set" org-agenda-todo-previousset t]
2044 ["Add note" org-agenda-add-note t])
2045 ("Archive/Refile/Delete"
2046 ["Archive default" org-agenda-archive-default t]
2047 ["Archive default" org-agenda-archive-default-with-confirmation t]
2048 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2049 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2050 ["Archive subtree" org-agenda-archive t]
2052 ["Refile" org-agenda-refile t]
2054 ["Delete subtree" org-agenda-kill t])
2056 ["Mark entry" org-agenda-bulk-mark t]
2057 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2058 ["Unmark entry" org-agenda-bulk-unmark t]
2059 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2060 ["Act on all marked" org-agenda-bulk-action t]
2062 ("Tags and Properties"
2063 ["Show all Tags" org-agenda-show-tags t]
2064 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2065 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2067 ["Column View" org-columns t])
2068 ("Deadline/Schedule"
2069 ["Schedule" org-agenda-schedule t]
2070 ["Set Deadline" org-agenda-deadline t]
2072 ["Mark item" org-agenda-action :active t :keys "k m"]
2073 ["Show mark item" org-agenda-action :active t :keys "k v"]
2074 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2075 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2077 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2078 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2079 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2080 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2081 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2082 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2083 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2085 ["Clock in" org-agenda-clock-in t]
2086 ["Clock out" org-agenda-clock-out t]
2087 ["Clock cancel" org-agenda-clock-cancel t]
2088 ["Goto running clock" org-clock-goto t]
2090 ["Set Effort" org-agenda-set-effort t]
2091 ["Change clocked effort" org-clock-modify-effort-estimate
2092 (org-clock-is-active)])
2094 ["Set Priority" org-agenda-priority t]
2095 ["Increase Priority" org-agenda-priority-up t]
2096 ["Decrease Priority" org-agenda-priority-down t]
2097 ["Show Priority" org-agenda-show-priority t])
2099 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2100 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2101 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2102 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2103 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2104 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2106 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2108 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2111 ["Push Files and Views" org-mobile-push t]
2112 ["Get Captured and Flagged" org-mobile-pull t]
2113 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2114 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2116 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2118 ["Quit" org-agenda-quit t]
2119 ["Exit and Release Buffers" org-agenda-exit t]
2124 (defvar org-agenda-allow-remote-undo t
2125 "Non-nil means allow remote undo from the agenda buffer.")
2126 (defvar org-agenda-undo-list nil
2127 "List of undoable operations in the agenda since last refresh.")
2128 (defvar org-agenda-undo-has-started-in nil
2129 "Buffers that have already seen `undo-start' in the current undo sequence.")
2130 (defvar org-agenda-pending-undo-list nil
2131 "In a series of undo commands, this is the list of remaining undo items.")
2133 (defun org-agenda-undo ()
2134 "Undo a remote editing step in the agenda.
2135 This undoes changes both in the agenda buffer and in the remote buffer
2136 that have been changed along."
2138 (or org-agenda-allow-remote-undo
2139 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2140 (if (not (eq this-command last-command))
2141 (setq org-agenda-undo-has-started-in nil
2142 org-agenda-pending-undo-list org-agenda-undo-list))
2143 (if (not org-agenda-pending-undo-list)
2144 (error "No further undo information"))
2145 (let* ((entry (pop org-agenda-pending-undo-list))
2146 buf line cmd rembuf)
2147 (setq cmd (pop entry) line (pop entry))
2148 (setq rembuf (nth 2 entry))
2149 (org-with-remote-undo rembuf
2150 (while (bufferp (setq buf (pop entry)))
2152 (with-current-buffer buf
2153 (let ((last-undo-buffer buf)
2154 (inhibit-read-only t))
2155 (unless (memq buf org-agenda-undo-has-started-in)
2156 (push buf org-agenda-undo-has-started-in)
2157 (make-local-variable 'pending-undo-list)
2159 (while (and pending-undo-list
2160 (listp pending-undo-list)
2161 (not (car pending-undo-list)))
2162 (pop pending-undo-list))
2164 (org-goto-line line)
2165 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2167 (defun org-verify-change-for-undo (l1 l2)
2168 "Verify that a real change occurred between the undo lists L1 and L2."
2169 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2170 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2175 (defvar org-agenda-restrict nil)
2176 (defvar org-agenda-restrict-begin (make-marker))
2177 (defvar org-agenda-restrict-end (make-marker))
2178 (defvar org-agenda-last-dispatch-buffer nil)
2179 (defvar org-agenda-overriding-restriction nil)
2182 (defun org-agenda (&optional arg keys restriction)
2183 "Dispatch agenda commands to collect entries to the agenda buffer.
2184 Prompts for a command to execute. Any prefix arg will be passed
2185 on to the selected command. The default selections are:
2187 a Call `org-agenda-list' to display the agenda for current day or week.
2188 t Call `org-todo-list' to display the global todo list.
2189 T Call `org-todo-list' to display the global todo list, select only
2190 entries with a specific TODO keyword (the user gets a prompt).
2191 m Call `org-tags-view' to display headlines with tags matching
2192 a condition (the user is prompted for the condition).
2193 M Like `m', but select only TODO entries, no ordinary headlines.
2194 L Create a timeline for the current buffer.
2195 e Export views to associated files.
2196 s Search entries for keywords.
2197 / Multi occur across all agenda files and also files listed
2198 in `org-agenda-text-search-extra-files'.
2199 < Restrict agenda commands to buffer, subtree, or region.
2200 Press several times to get the desired effect.
2201 > Remove a previous restriction.
2202 # List \"stuck\" projects.
2203 ! Configure what \"stuck\" means.
2204 C Configure custom agenda commands.
2206 More commands can be added by configuring the variable
2207 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2208 searches can be pre-defined in this way.
2210 If the current buffer is in Org-mode and visiting a file, you can also
2211 first press `<' once to indicate that the agenda should be temporarily
2212 \(until the next use of \\[org-agenda]) restricted to the current file.
2213 Pressing `<' twice means to restrict to the current subtree or region
2217 (let* ((prefix-descriptions nil)
2218 (org-agenda-window-setup (if (equal (buffer-name)
2219 org-agenda-buffer-name)
2221 org-agenda-window-setup))
2222 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2223 (org-agenda-custom-commands
2224 ;; normalize different versions
2228 (cond ((stringp (cdr x))
2229 (push x prefix-descriptions)
2231 ((stringp (nth 1 x)) x)
2232 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2233 (t (cons (car x) (cons "" (cdr x))))))
2234 org-agenda-custom-commands)))
2235 (buf (current-buffer))
2236 (bfn (buffer-file-name (buffer-base-buffer)))
2237 entry key type match lprops ans)
2238 ;; Turn off restriction unless there is an overriding one,
2239 (unless org-agenda-overriding-restriction
2240 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2241 ;; There is a request to keep the file list in place
2242 (put 'org-agenda-files 'org-restrict nil))
2243 (setq org-agenda-restrict nil)
2244 (move-marker org-agenda-restrict-begin nil)
2245 (move-marker org-agenda-restrict-end nil))
2246 ;; Delete old local properties
2247 (put 'org-agenda-redo-command 'org-lprops nil)
2248 ;; Delete previously set last-arguments
2249 (put 'org-agenda-redo-command 'last-args nil)
2250 ;; Remember where this call originated
2251 (setq org-agenda-last-dispatch-buffer (current-buffer))
2253 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2255 restriction (cdr ans)))
2256 ;; Establish the restriction, if any
2257 (when (and (not org-agenda-overriding-restriction) restriction)
2258 (put 'org-agenda-files 'org-restrict (list bfn))
2260 ((eq restriction 'region)
2261 (setq org-agenda-restrict t)
2262 (move-marker org-agenda-restrict-begin (region-beginning))
2263 (move-marker org-agenda-restrict-end (region-end)))
2264 ((eq restriction 'subtree)
2266 (setq org-agenda-restrict t)
2267 (org-back-to-heading t)
2268 (move-marker org-agenda-restrict-begin (point))
2269 (move-marker org-agenda-restrict-end
2270 (progn (org-end-of-subtree t)))))))
2272 ;; For example the todo list should not need it (but does...)
2274 ((setq entry (assoc keys org-agenda-custom-commands))
2275 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2277 (setq type (nth 2 entry) match (eval (nth 3 entry))
2278 lprops (nth 4 entry))
2279 (put 'org-agenda-redo-command 'org-lprops lprops)
2282 (org-let lprops '(org-agenda-list current-prefix-arg)))
2284 (org-let lprops '(org-todo-list current-prefix-arg)))
2286 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2288 (org-let lprops '(org-agenda-list-stuck-projects
2289 current-prefix-arg)))
2291 (org-let lprops '(org-tags-view current-prefix-arg match)))
2292 ((eq type 'tags-todo)
2293 (org-let lprops '(org-tags-view '(4) match)))
2295 (org-let lprops '(org-todo-list match)))
2296 ((eq type 'tags-tree)
2297 (org-check-for-org-mode)
2298 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2299 ((eq type 'todo-tree)
2300 (org-check-for-org-mode)
2302 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2303 (regexp-quote match) "\\>"))))
2304 ((eq type 'occur-tree)
2305 (org-check-for-org-mode)
2306 (org-let lprops '(org-occur match)))
2308 (org-let lprops '(funcall type match)))
2310 (org-let lprops '(funcall type match)))
2311 (t (error "Invalid custom agenda command type %s" type))))
2312 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2314 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2315 (customize-variable 'org-agenda-custom-commands))
2316 ((equal keys "a") (call-interactively 'org-agenda-list))
2317 ((equal keys "s") (call-interactively 'org-search-view))
2318 ((equal keys "t") (call-interactively 'org-todo-list))
2319 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2320 ((equal keys "m") (call-interactively 'org-tags-view))
2321 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2322 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2323 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2327 (unless (current-message)
2328 (let* ((m (org-agenda-get-any-marker))
2329 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2332 "FLAGGING-NOTE ([?] for more info): "
2334 (replace-regexp-in-string
2336 (copy-sequence note))
2337 nil 'face 'org-warning)))))))
2340 (unless (eq major-mode 'org-mode)
2341 (error "This is not an Org-mode file"))
2343 (put 'org-agenda-files 'org-restrict (list bfn))
2344 (org-call-with-arg 'org-timeline arg)))
2345 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2346 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2347 ((equal keys "!") (customize-variable 'org-stuck-projects))
2348 (t (error "Invalid agenda key"))))))
2350 (defun org-agenda-append-agenda ()
2351 "Append another agenda view to the current one.
2352 This function allows interactive building of block agendas.
2353 Agenda views are separated by `org-agenda-block-separator'."
2355 (unless (string= (buffer-name) org-agenda-buffer-name)
2356 (error "Can only append from within agenda buffer"))
2357 (let ((org-agenda-multi t))
2361 (defun org-agenda-normalize-custom-commands (cmds)
2365 (cond ((stringp (cdr x)) nil)
2366 ((stringp (nth 1 x)) x)
2367 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2368 (t (cons (car x) (cons "" (cdr x))))))
2371 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2372 "The user interface for selecting an agenda command."
2374 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2375 (restrict-ok (and bfn (eq major-mode 'org-mode)))
2376 (region-p (org-region-active-p))
2377 (custom org-agenda-custom-commands)
2379 restriction second-time
2380 c entry key type match prefixes rmheader header-end custom1 desc
2381 line lines left right n n1)
2382 (save-window-excursion
2383 (delete-other-windows)
2384 (org-switch-to-buffer-other-window " *Agenda Commands*")
2386 (insert (eval-when-compile
2389 Press key for an agenda command: < Buffer, subtree/region restriction
2390 -------------------------------- > Remove restriction
2391 a Agenda for current week or day e Export agenda views
2392 t List of all TODO entries T Entries with special TODO kwd
2393 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2394 L Timeline for current buffer # List stuck projects (!=configure)
2395 s Search for keywords C Configure custom agenda commands
2396 / Multi-occur ? Find :FLAGGED: entries
2399 (while (string-match
2400 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2402 (setq start (match-end 0))
2403 (add-text-properties (match-beginning 2) (match-end 2)
2404 '(face bold) header))
2406 (setq header-end (move-marker (make-marker) (point)))
2408 (setq custom1 custom)
2409 (when (eq rmheader t)
2411 (re-search-forward ":" nil t)
2412 (delete-region (match-end 0) (point-at-eol))
2415 (delete-region (match-end 0) (point-at-eol))
2416 (move-marker header-end (match-end 0)))
2417 (goto-char header-end)
2418 (delete-region (point) (point-max))
2420 ;; Produce all the lines that describe custom commands and prefixes
2422 (while (setq entry (pop custom1))
2423 (setq key (car entry) desc (nth 1 entry)
2425 match (nth 3 entry))
2426 (if (> (length key) 1)
2427 (add-to-list 'prefixes (string-to-char key))
2431 (org-add-props (copy-sequence key)
2434 ((string-match "\\S-" desc) desc)
2435 ((eq type 'agenda) "Agenda for current week or day")
2436 ((eq type 'alltodo) "List of all TODO entries")
2437 ((eq type 'search) "Word search")
2438 ((eq type 'stuck) "List of stuck projects")
2439 ((eq type 'todo) "TODO keyword")
2440 ((eq type 'tags) "Tags query")
2441 ((eq type 'tags-todo) "Tags (TODO)")
2442 ((eq type 'tags-tree) "Tags tree")
2443 ((eq type 'todo-tree) "TODO kwd tree")
2444 ((eq type 'occur-tree) "Occur tree")
2445 ((functionp type) (if (symbolp type)
2447 "Lambda expression"))
2449 (if org-agenda-menu-show-matcher
2454 (setq match (copy-sequence match))
2455 (org-add-props match nil 'face 'org-warning))
2457 (format "set of %d commands" (length match)))
2459 (if (org-string-nw-p match)
2460 (add-text-properties
2461 0 (length line) (list 'help-echo
2462 (concat "Matcher: "match)) line)))
2464 (setq lines (nreverse lines))
2469 (org-add-props (char-to-string x)
2471 (or (cdr (assoc (concat selstring
2473 prefix-descriptions))
2478 ;; Check if we should display in two columns
2479 (if org-agenda-menu-two-column
2481 (setq n (length lines)
2482 n1 (+ (/ n 2) (mod n 2))
2483 right (nthcdr n1 lines)
2484 left (copy-sequence lines))
2485 (setcdr (nthcdr (1- n1) left) nil))
2486 (setq left lines right nil))
2488 (insert "\n" (pop left))
2490 (if (< (current-column) 40)
2491 (move-to-column 40 t)
2493 (insert (pop right))))
2495 ;; Make the window the right size
2496 (goto-char (point-min))
2498 (if (not (pos-visible-in-window-p (point-max)))
2499 (org-fit-window-to-buffer))
2500 (setq second-time t)
2501 (org-fit-window-to-buffer))
2503 ;; Ask for selection
2504 (message "Press key for agenda command%s:"
2505 (if (or restrict-ok org-agenda-overriding-restriction)
2506 (if org-agenda-overriding-restriction
2507 " (restriction lock active)"
2509 (format " (restricted to %s)" restriction)
2512 (setq c (read-char-exclusive))
2515 ((assoc (char-to-string c) custom)
2516 (setq selstring (concat selstring (char-to-string c)))
2517 (throw 'exit (cons selstring restriction)))
2519 (setq selstring (concat selstring (char-to-string c))
2521 rmheader (or rmheader t)
2522 custom (delq nil (mapcar
2524 (if (or (= (length (car x)) 1)
2525 (/= (string-to-char (car x)) c))
2527 (cons (substring (car x) 1) (cdr x))))
2529 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2530 (message "Restriction is only possible in Org-mode buffers")
2533 (org-agenda-remove-restriction-lock 'noupdate)
2534 (setq restriction 'buffer))
2536 (org-agenda-remove-restriction-lock 'noupdate)
2537 (setq restriction (if region-p 'region 'subtree)))
2539 (org-agenda-remove-restriction-lock 'noupdate)
2542 ((eq restriction 'buffer)
2543 (if region-p 'region 'subtree))
2544 ((memq restriction '(subtree region))
2548 (org-agenda-remove-restriction-lock 'noupdate)
2549 (setq restriction nil))
2550 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2551 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2552 ((and (> (length selstring) 0) (eq c ?\d))
2554 (org-agenda-get-restriction-and-command prefix-descriptions))
2556 ((equal c ?q) (error "Abort"))
2557 (t (error "Invalid key %c" c))))))))
2559 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2560 (defvar org-agenda-last-arguments nil
2561 "The arguments of the previous call to `org-agenda'.")
2562 (defun org-agenda-run-series (name series)
2563 (org-let (nth 1 series) '(org-prepare-agenda name))
2564 (let* ((org-agenda-multi t)
2565 (redo (list 'org-agenda-run-series name (list 'quote series)))
2566 (org-agenda-overriding-arguments
2567 (or org-agenda-overriding-arguments
2568 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2569 (get 'org-agenda-redo-command 'last-args))))
2571 (gprops (nth 1 series))
2572 match ;; The byte compiler incorrectly complains about this. Keep it!
2574 (while (setq cmd (pop cmds))
2575 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2578 (org-let2 gprops lprops
2579 '(call-interactively 'org-agenda-list)))
2581 (org-let2 gprops lprops
2582 '(call-interactively 'org-todo-list)))
2584 (org-let2 gprops lprops
2585 '(org-search-view current-prefix-arg match nil)))
2587 (org-let2 gprops lprops
2588 '(call-interactively 'org-agenda-list-stuck-projects)))
2590 (org-let2 gprops lprops
2591 '(org-tags-view current-prefix-arg match)))
2592 ((eq type 'tags-todo)
2593 (org-let2 gprops lprops
2594 '(org-tags-view '(4) match)))
2596 (org-let2 gprops lprops
2597 '(org-todo-list match)))
2599 (org-let2 gprops lprops
2600 '(funcall type match)))
2601 (t (error "Invalid type in command series"))))
2603 (setq org-agenda-redo-command redo)
2604 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2605 (goto-char (point-min)))
2606 (org-fit-agenda-window)
2607 (org-let (nth 1 series) '(org-finalize-agenda)))
2610 (defmacro org-batch-agenda (cmd-key &rest parameters)
2611 "Run an agenda command in batch mode and send the result to STDOUT.
2612 If CMD-KEY is a string of length 1, it is used as a key in
2613 `org-agenda-custom-commands' and triggers this command. If it is a
2614 longer string it is used as a tags/todo match string.
2615 Parameters are alternating variable names and values that will be bound
2616 before running the agenda command."
2617 (org-eval-in-environment (org-make-parameter-alist parameters)
2618 (if (> (length cmd-key) 2)
2619 (org-tags-view nil cmd-key)
2620 (org-agenda nil cmd-key)))
2621 (set-buffer org-agenda-buffer-name)
2622 (princ (buffer-string)))
2623 (def-edebug-spec org-batch-agenda (form &rest sexp))
2625 (defvar org-agenda-info nil)
2628 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2629 "Run an agenda command in batch mode and send the result to STDOUT.
2630 If CMD-KEY is a string of length 1, it is used as a key in
2631 `org-agenda-custom-commands' and triggers this command. If it is a
2632 longer string it is used as a tags/todo match string.
2633 Parameters are alternating variable names and values that will be bound
2634 before running the agenda command.
2636 The output gives a line for each selected agenda item. Each
2637 item is a list of comma-separated values, like this:
2639 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2641 category The category of the item
2642 head The headline, without TODO kwd, TAGS and PRIORITY
2643 type The type of the agenda entry, can be
2644 todo selected in TODO match
2645 tagsmatch selected in tags match
2646 diary imported from diary
2647 deadline a deadline on given date
2648 scheduled scheduled on given date
2649 timestamp entry has timestamp on given date
2650 closed entry was closed on given date
2651 upcoming-deadline warning about deadline
2652 past-scheduled forwarded scheduled item
2653 block entry has date block including g. date
2654 todo The todo keyword, if any
2655 tags All tags including inherited ones, separated by colons
2656 date The relevant date, like 2007-2-14
2657 time The time, like 15:00-16:50
2658 extra Sting with extra planning info
2659 priority-l The priority letter if any was given
2660 priority-n The computed numerical priority
2661 agenda-day The day in the agenda where this is listed"
2662 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2663 (org-make-parameter-alist parameters))
2664 (if (> (length cmd-key) 2)
2665 (org-tags-view nil cmd-key)
2666 (org-agenda nil cmd-key)))
2667 (set-buffer org-agenda-buffer-name)
2668 (let* ((lines (org-split-string (buffer-string) "\n"))
2670 (while (setq line (pop lines))
2672 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2673 (setq org-agenda-info
2674 (org-fix-agenda-info (text-properties-at 0 line)))
2676 (mapconcat 'org-agenda-export-csv-mapper
2677 '(org-category txt type todo tags date time extra
2678 priority-letter priority agenda-day)
2681 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2683 (defun org-fix-agenda-info (props)
2684 "Make sure all properties on an agenda item have a canonical form.
2685 This ensures the export commands can easily use it."
2687 (when (setq tmp (plist-get props 'tags))
2688 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2689 (when (setq tmp (plist-get props 'date))
2690 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2691 (let ((calendar-date-display-form '(year "-" month "-" day)))
2692 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2694 (setq tmp (calendar-date-string tmp)))
2695 (setq props (plist-put props 'date tmp)))
2696 (when (setq tmp (plist-get props 'day))
2697 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2698 (let ((calendar-date-display-form '(year "-" month "-" day)))
2699 (setq tmp (calendar-date-string tmp)))
2700 (setq props (plist-put props 'day tmp))
2701 (setq props (plist-put props 'agenda-day tmp)))
2702 (when (setq tmp (plist-get props 'txt))
2703 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2704 (plist-put props 'priority-letter (match-string 1 tmp))
2705 (setq tmp (replace-match "" t t tmp)))
2706 (when (and (setq re (plist-get props 'org-todo-regexp))
2707 (setq re (concat "\\`\\.*" re " ?"))
2708 (string-match re tmp))
2709 (plist-put props 'todo (match-string 1 tmp))
2710 (setq tmp (replace-match "" t t tmp)))
2711 (plist-put props 'txt tmp)))
2714 (defun org-agenda-export-csv-mapper (prop)
2715 (let ((res (plist-get org-agenda-info prop)))
2720 (t (prin1-to-string res))))
2721 (while (string-match "," res)
2722 (setq res (replace-match ";" t t res)))
2727 (defun org-store-agenda-views (&rest parameters)
2729 (eval (list 'org-batch-store-agenda-views)))
2732 (defmacro org-batch-store-agenda-views (&rest parameters)
2733 "Run all custom agenda commands that have a file argument."
2734 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2736 (dir default-directory)
2737 (pars (org-make-parameter-alist parameters))
2738 cmd thiscmdkey files opts cmd-or-set)
2739 (save-window-excursion
2741 (setq cmd (pop cmds)
2742 thiscmdkey (car cmd)
2743 cmd-or-set (nth 2 cmd)
2744 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2745 files (nth (if (listp cmd-or-set) 4 5) cmd))
2746 (if (stringp files) (setq files (list files)))
2748 (org-eval-in-environment (append org-agenda-exporter-settings
2750 (org-agenda nil thiscmdkey))
2751 (set-buffer org-agenda-buffer-name)
2753 (org-eval-in-environment (append org-agenda-exporter-settings
2755 (org-agenda-write (expand-file-name (pop files) dir) nil t)))
2756 (and (get-buffer org-agenda-buffer-name)
2757 (kill-buffer org-agenda-buffer-name)))))))
2758 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2760 (defun org-agenda-mark-header-line (pos)
2761 "Mark the line at POS as an agenda structure header."
2764 (put-text-property (point-at-bol) (point-at-eol)
2765 'org-agenda-structural-header t)
2766 (when org-agenda-title-append
2767 (put-text-property (point-at-bol) (point-at-eol)
2768 'org-agenda-title-append org-agenda-title-append))))
2770 (defvar org-mobile-creating-agendas)
2771 (defvar org-agenda-write-buffer-name "Agenda View")
2772 (defun org-agenda-write (file &optional open nosettings)
2773 "Write the current buffer (an agenda view) as a file.
2774 Depending on the extension of the file name, plain text (.txt),
2775 HTML (.html or .htm) or Postscript (.ps) is produced.
2776 If the extension is .ics, run icalendar export over all files used
2777 to construct the agenda and limit the export to entries listed in the
2779 With prefix argument OPEN, open the new file immediately.
2780 If NOSETTINGS is given, do not scope the settings of
2781 `org-agenda-exporter-settings' into the export commands. This is used when
2782 the settings have already been scoped and we do not wish to overrule other,
2783 higher priority settings."
2784 (interactive "FWrite agenda to file: \nP")
2785 (if (not (file-writable-p file))
2786 (error "Cannot write agenda to file %s" file))
2787 (org-let (if nosettings nil org-agenda-exporter-settings)
2789 (save-window-excursion
2790 (org-agenda-mark-filtered-text)
2791 (let ((bs (copy-sequence (buffer-string))) beg)
2792 (org-agenda-unmark-filtered-text)
2794 (rename-buffer org-agenda-write-buffer-name t)
2795 (set-buffer-modified-p nil)
2797 (org-agenda-remove-marked-text 'org-filtered)
2798 (while (setq beg (text-property-any (point-min) (point-max)
2801 beg (or (next-single-property-change beg 'org-filtered)
2803 (run-hooks 'org-agenda-before-write-hook)
2805 ((org-bound-and-true-p org-mobile-creating-agendas)
2806 (org-mobile-write-agenda-for-mobile file))
2807 ((string-match "\\.html?\\'" file)
2809 (set-buffer (htmlize-buffer (current-buffer)))
2811 (when (and org-agenda-export-html-style
2812 (string-match "<style>" org-agenda-export-html-style))
2813 ;; replace <style> section with org-agenda-export-html-style
2814 (goto-char (point-min))
2815 (kill-region (- (search-forward "<style") 6)
2816 (search-forward "</style>"))
2817 (insert org-agenda-export-html-style))
2819 (kill-buffer (current-buffer))
2820 (message "HTML written to %s" file))
2821 ((string-match "\\.ps\\'" file)
2823 (ps-print-buffer-with-faces file)
2824 (message "Postscript written to %s" file))
2825 ((string-match "\\.pdf\\'" file)
2827 (ps-print-buffer-with-faces
2828 (concat (file-name-sans-extension file) ".ps"))
2829 (call-process "ps2pdf" nil nil nil
2831 (concat (file-name-sans-extension file) ".ps"))
2832 (expand-file-name file))
2833 (delete-file (concat (file-name-sans-extension file) ".ps"))
2834 (message "PDF written to %s" file))
2835 ((string-match "\\.ics\\'" file)
2836 (require 'org-icalendar)
2837 (let ((org-agenda-marker-table
2838 (org-create-marker-find-array
2839 (org-agenda-collect-markers)))
2840 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2841 (org-combined-agenda-icalendar-file file))
2842 (apply 'org-export-icalendar 'combine
2843 (org-agenda-files nil 'ifmode))))
2845 (let ((bs (buffer-string)))
2850 (kill-buffer (current-buffer))
2851 (message "Plain text written to %s" file))))))))
2852 (set-buffer org-agenda-buffer-name))
2853 (when open (org-open-file file)))
2855 (defvar org-agenda-tag-filter-overlays nil)
2856 (defvar org-agenda-cat-filter-overlays nil)
2858 (defun org-agenda-mark-filtered-text ()
2859 "Mark all text hidden by filtering with a text property."
2860 (let ((inhibit-read-only t))
2863 (when (equal (overlay-buffer o) (current-buffer))
2865 (overlay-start o) (overlay-end o)
2867 (append org-agenda-tag-filter-overlays
2868 org-agenda-cat-filter-overlays))))
2870 (defun org-agenda-unmark-filtered-text ()
2871 "Remove the filtering text property."
2872 (let ((inhibit-read-only t))
2873 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2875 (defun org-agenda-remove-marked-text (property &optional value)
2876 "Delete all text marked with VALUE of PROPERTY.
2877 VALUE defaults to t."
2879 (setq value (or value t))
2880 (while (setq beg (text-property-any (point-min) (point-max)
2883 beg (or (next-single-property-change beg 'org-filtered)
2886 (defun org-agenda-add-entry-text ()
2887 "Add entry text to agenda lines.
2888 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2889 entry text following headings shown in the agenda.
2890 Drawers will be excluded, also the line with scheduling/deadline info."
2891 (when (and (> org-agenda-add-entry-text-maxlines 0)
2892 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2894 (goto-char (point-min))
2896 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2897 (beginning-of-line 2)
2898 (setq txt (org-agenda-get-some-entry-text
2899 m org-agenda-add-entry-text-maxlines " > "))
2901 (if (string-match "\\S-" txt)
2903 (or (eobp) (forward-char 1))))))))
2905 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2907 "Extract entry text from MARKER, at most N-LINES lines.
2908 This will ignore drawers etc, just get the text.
2909 If INDENT is given, prefix every line with this string. If KEEP is
2910 given, it is a list of symbols, defining stuff that should not be
2911 removed from the entry content. Currently only `planning' is allowed here."
2912 (let (txt drawer-re kwd-time-re ind)
2914 (with-current-buffer (marker-buffer marker)
2915 (if (not (eq major-mode 'org-mode))
2922 (setq txt (buffer-substring
2923 (min (1+ (point)) (point-max))
2924 (progn (outline-next-heading) (point)))
2925 drawer-re org-drawer-regexp
2926 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2930 (when org-agenda-add-entry-text-descriptive-links
2931 (goto-char (point-min))
2932 (while (org-activate-bracket-links (point-max))
2933 (add-text-properties (match-beginning 0) (match-end 0)
2935 (goto-char (point-min))
2936 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2937 (set-text-properties (match-beginning 0) (match-end 0)
2939 (goto-char (point-min))
2940 (while (re-search-forward drawer-re nil t)
2943 (progn (re-search-forward
2944 "^[ \t]*:END:.*\n?" nil 'move)
2946 (unless (member 'planning keep)
2947 (goto-char (point-min))
2948 (while (re-search-forward kwd-time-re nil t)
2949 (replace-match "")))
2950 (goto-char (point-min))
2951 (when org-agenda-entry-text-exclude-regexps
2952 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2953 (while (setq re (pop re-list))
2954 (goto-char (point-min))
2955 (while (re-search-forward re nil t)
2956 (replace-match "")))))
2957 (goto-char (point-max))
2958 (skip-chars-backward " \t\n")
2959 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2961 ;; find and remove min common indentation
2962 (goto-char (point-min))
2963 (untabify (point-min) (point-max))
2964 (setq ind (org-get-indentation))
2966 (unless (looking-at "[ \t]*$")
2967 (setq ind (min ind (org-get-indentation))))
2968 (beginning-of-line 2))
2969 (goto-char (point-min))
2971 (unless (looking-at "[ \t]*$")
2972 (move-to-column ind)
2973 (delete-region (point-at-bol) (point)))
2974 (beginning-of-line 2))
2976 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2978 (goto-char (point-min))
2980 (while (and (not (eobp)) (re-search-forward "^" nil t))
2981 (replace-match indent t t)))
2982 (goto-char (point-min))
2983 (while (looking-at "[ \t]*\n") (replace-match ""))
2984 (goto-char (point-max))
2985 (when (> (org-current-line)
2987 (org-goto-line (1+ n-lines))
2989 (setq txt (buffer-substring (point-min) (point)))))))))
2992 (defun org-agenda-collect-markers ()
2993 "Collect the markers pointing to entries in the agenda buffer."
2996 (goto-char (point-min))
2998 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2999 (org-get-at-bol 'org-marker)))
3001 (beginning-of-line 2)))
3002 (nreverse markers)))
3004 (defun org-create-marker-find-array (marker-list)
3005 "Create a alist of files names with all marker positions in that file."
3007 (while (setq m (pop marker-list))
3008 (setq p (marker-position m)
3009 f (buffer-file-name (or (buffer-base-buffer
3011 (marker-buffer m))))
3012 (if (setq a (assoc f tbl))
3013 (push (marker-position m) (cdr a))
3014 (push (list f p) tbl)))
3015 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3018 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3019 (defun org-check-agenda-marker-table ()
3020 "Check of the current entry is on the marker list."
3021 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3023 (and (setq a (assoc file org-agenda-marker-table))
3026 (org-back-to-heading t)
3027 (member (point) (cdr a)))))))
3029 (defun org-check-for-org-mode ()
3030 "Make sure current buffer is in org-mode. Error if not."
3031 (or (eq major-mode 'org-mode)
3032 (error "Cannot execute org-mode agenda command on buffer in %s"
3035 (defun org-fit-agenda-window ()
3036 "Fit the window to the buffer size."
3037 (and (memq org-agenda-window-setup '(reorganize-frame))
3038 (fboundp 'fit-window-to-buffer)
3039 (org-fit-window-to-buffer
3041 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3042 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3044 ;;; Agenda prepare and finalize
3046 (defvar org-agenda-multi nil) ; dynamically scoped
3047 (defvar org-agenda-buffer-name "*Org Agenda*")
3048 (defvar org-pre-agenda-window-conf nil)
3049 (defvar org-agenda-columns-active nil)
3050 (defvar org-agenda-name nil)
3051 (defvar org-agenda-tag-filter nil)
3052 (defvar org-agenda-category-filter nil)
3053 (defvar org-agenda-tag-filter-while-redo nil)
3054 (defvar org-agenda-tag-filter-preset nil
3055 "A preset of the tags filter used for secondary agenda filtering.
3056 This must be a list of strings, each string must be a single tag preceded
3058 This variable should not be set directly, but agenda custom commands can
3059 bind it in the options section. The preset filter is a global property of
3060 the entire agenda view. In a block agenda, it will not work reliably to
3061 define a filter for one of the individual blocks. You need to set it in
3062 the global options and expect it to be applied to the entire view.")
3064 (defvar org-agenda-category-filter-preset nil
3065 "A preset of the category filter used for secondary agenda filtering.
3066 This must be a list of strings, each string must be a single category
3067 preceded by \"+\" or \"-\".
3068 This variable should not be set directly, but agenda custom commands can
3069 bind it in the options section. The preset filter is a global property of
3070 the entire agenda view. In a block agenda, it will not work reliably to
3071 define a filter for one of the individual blocks. You need to set it in
3072 the global options and expect it to be applied to the entire view.")
3074 (defun org-prepare-agenda (&optional name)
3075 (setq org-todo-keywords-for-agenda nil)
3076 (setq org-done-keywords-for-agenda nil)
3077 (setq org-drawers-for-agenda nil)
3078 (unless org-agenda-persistent-filter
3079 (setq org-agenda-tag-filter nil
3080 org-agenda-category-filter nil))
3081 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3082 (put 'org-agenda-category-filter :preset-filter org-agenda-category-filter-preset)
3083 (if org-agenda-multi
3085 (setq buffer-read-only nil)
3086 (goto-char (point-max))
3087 (unless (or (bobp) org-agenda-compact-blocks
3088 (not org-agenda-block-separator))
3090 (if (stringp org-agenda-block-separator)
3091 org-agenda-block-separator
3092 (make-string (window-width) org-agenda-block-separator))
3094 (narrow-to-region (point) (point-max)))
3095 (org-agenda-reset-markers)
3096 (setq org-agenda-contributing-files nil)
3097 (setq org-agenda-columns-active nil)
3098 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3099 (setq org-todo-keywords-for-agenda
3100 (org-uniquify org-todo-keywords-for-agenda))
3101 (setq org-done-keywords-for-agenda
3102 (org-uniquify org-done-keywords-for-agenda))
3103 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3104 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
3105 (awin (get-buffer-window abuf)))
3107 ((equal (current-buffer) abuf) nil)
3108 (awin (select-window awin))
3109 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3110 ((equal org-agenda-window-setup 'current-window)
3111 (org-pop-to-buffer-same-window abuf))
3112 ((equal org-agenda-window-setup 'other-window)
3113 (org-switch-to-buffer-other-window abuf))
3114 ((equal org-agenda-window-setup 'other-frame)
3115 (switch-to-buffer-other-frame abuf))
3116 ((equal org-agenda-window-setup 'reorganize-frame)
3117 (delete-other-windows)
3118 (org-switch-to-buffer-other-window abuf)))
3119 ;; additional test in case agenda is invoked from within agenda
3120 ;; buffer via elisp link
3121 (unless (equal (current-buffer) abuf)
3122 (org-pop-to-buffer-same-window abuf)))
3123 (setq buffer-read-only nil)
3124 (let ((inhibit-read-only t)) (erase-buffer))
3126 (and name (not org-agenda-name)
3127 (org-set-local 'org-agenda-name name)))
3128 (setq buffer-read-only nil))
3130 (defun org-finalize-agenda ()
3131 "Finishing touch for the agenda buffer, called just before displaying it."
3132 (unless org-agenda-multi
3134 (let ((inhibit-read-only t))
3135 (goto-char (point-min))
3136 (while (org-activate-bracket-links (point-max))
3137 (add-text-properties (match-beginning 0) (match-end 0)
3139 (org-agenda-align-tags)
3140 (unless org-agenda-with-colors
3141 (remove-text-properties (point-min) (point-max) '(face nil))))
3142 (if (and (boundp 'org-agenda-overriding-columns-format)
3143 org-agenda-overriding-columns-format)
3144 (org-set-local 'org-agenda-overriding-columns-format
3145 org-agenda-overriding-columns-format))
3146 (if (and (boundp 'org-agenda-view-columns-initially)
3147 org-agenda-view-columns-initially)
3148 (org-agenda-columns))
3149 (when org-agenda-fontify-priorities
3150 (org-agenda-fontify-priorities))
3151 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3152 (org-agenda-dim-blocked-tasks))
3153 (org-agenda-mark-clocking-task)
3154 (when org-agenda-entry-text-mode
3155 (org-agenda-entry-text-hide)
3156 (org-agenda-entry-text-show))
3157 (if (functionp 'org-habit-insert-consistency-graphs)
3158 (org-habit-insert-consistency-graphs))
3159 (run-hooks 'org-finalize-agenda-hook)
3160 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3161 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3162 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3163 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3164 (org-agenda-filter-apply org-agenda-category-filter 'category))
3167 (defun org-agenda-mark-clocking-task ()
3168 "Mark the current clock entry in the agenda if it is present."
3170 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3171 (delete-overlay o)))
3172 (overlays-in (point-min) (point-max)))
3173 (when (marker-buffer org-clock-hd-marker)
3175 (goto-char (point-min))
3177 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3179 (when (equal (org-get-at-bol 'org-hd-marker)
3180 org-clock-hd-marker)
3181 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3182 (overlay-put ov 'type 'org-agenda-clocking)
3183 (overlay-put ov 'face 'org-agenda-clocking)
3184 (overlay-put ov 'help-echo
3185 "The clock is running in this item")))))))
3187 (defun org-agenda-fontify-priorities ()
3188 "Make highest priority lines bold, and lowest italic."
3190 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3191 (delete-overlay o)))
3192 (overlays-in (point-min) (point-max)))
3194 (let ((inhibit-read-only t)
3196 (goto-char (point-min))
3197 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3198 (setq h (or (get-char-property (point) 'org-highest-priority)
3199 org-highest-priority)
3200 l (or (get-char-property (point) 'org-lowest-priority)
3201 org-lowest-priority)
3202 p (string-to-char (match-string 1))
3203 b (match-beginning 0)
3204 e (if (eq org-agenda-fontify-priorities 'cookies)
3207 ov (make-overlay b e))
3210 (cond ((org-face-from-face-or-color
3212 (cdr (assoc p org-priority-faces))))
3213 ((and (listp org-agenda-fontify-priorities)
3214 (org-face-from-face-or-color
3216 (cdr (assoc p org-agenda-fontify-priorities)))))
3217 ((equal p l) 'italic)
3218 ((equal p h) 'bold)))
3219 (overlay-put ov 'org-type 'org-priority)))))
3221 (defun org-agenda-dim-blocked-tasks ()
3222 "Dim currently blocked TODO's in the agenda display."
3223 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3224 (delete-overlay o)))
3225 (overlays-in (point-min) (point-max)))
3227 (let ((inhibit-read-only t)
3228 (org-depend-tag-blocked nil)
3229 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3230 org-blocked-by-checkboxes
3231 invis1 b e p ov h l)
3232 (goto-char (point-min))
3233 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3234 (and pos (goto-char (1+ pos))))
3235 (setq org-blocked-by-checkboxes nil invis1 invis)
3236 (let ((marker (org-get-at-bol 'org-hd-marker)))
3238 (with-current-buffer (marker-buffer marker)
3239 (save-excursion (goto-char marker)
3240 (org-entry-blocked-p))))
3241 (if org-blocked-by-checkboxes (setq invis1 nil))
3243 (max (point-min) (1- (point-at-bol)))
3246 ov (make-overlay b e))
3248 (overlay-put ov 'invisible t)
3249 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3250 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3252 (defvar org-agenda-skip-function nil
3253 "Function to be called at each match during agenda construction.
3254 If this function returns nil, the current match should not be skipped.
3255 Otherwise, the function must return a position from where the search
3256 should be continued.
3257 This may also be a Lisp form, it will be evaluated.
3258 Never set this variable using `setq' or so, because then it will apply
3259 to all future agenda commands. If you do want a global skipping condition,
3260 use the option `org-agenda-skip-function-global' instead.
3261 The correct usage for `org-agenda-skip-function' is to bind it with
3262 `let' to scope it dynamically into the agenda-constructing command.
3263 A good way to set it is through options in `org-agenda-custom-commands'.")
3265 (defun org-agenda-skip ()
3266 "Throw to `:skip' in places that should be skipped.
3267 Also moves point to the end of the skipped region, so that search can
3268 continue from there."
3269 (let ((p (point-at-bol)) to)
3270 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3271 (get-text-property p :org-archived)
3272 (org-end-of-subtree t)
3274 (and org-agenda-skip-comment-trees
3275 (get-text-property p :org-comment)
3276 (org-end-of-subtree t)
3278 (if (equal (char-after p) ?#) (throw :skip t))
3279 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3280 (org-agenda-skip-eval org-agenda-skip-function)))
3284 (defun org-agenda-skip-eval (form)
3285 "If FORM is a function or a list, call (or eval) is and return result.
3286 `save-excursion' and `save-match-data' are wrapped around the call, so point
3287 and match data are returned to the previous state no matter what these
3291 (or (setq fp (functionp form))
3299 (defvar org-agenda-markers nil
3300 "List of all currently active markers created by `org-agenda'.")
3301 (defvar org-agenda-last-marker-time (org-float-time)
3302 "Creation time of the last agenda marker.")
3304 (defun org-agenda-new-marker (&optional pos)
3305 "Return a new agenda marker.
3306 Org-mode keeps a list of these markers and resets them when they are
3308 (let ((m (copy-marker (or pos (point)))))
3309 (setq org-agenda-last-marker-time (org-float-time))
3310 (push m org-agenda-markers)
3313 (defun org-agenda-reset-markers ()
3314 "Reset markers created by `org-agenda'."
3315 (while org-agenda-markers
3316 (move-marker (pop org-agenda-markers) nil)))
3318 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3319 "Save relative positions of markers in region."
3320 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3321 org-agenda-markers))
3325 (defun org-agenda-entry-text-show-here ()
3326 "Add some text from the entry as context to the current line."
3328 (setq m (org-get-at-bol 'org-hd-marker))
3329 (unless (marker-buffer m)
3330 (error "No marker points to an entry here"))
3331 (setq txt (concat "\n" (org-no-properties
3332 (org-agenda-get-some-entry-text
3333 m org-agenda-entry-text-maxlines " > "))))
3334 (when (string-match "\\S-" txt)
3335 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3336 (overlay-put o 'evaporate t)
3337 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3338 (overlay-put o 'after-string txt))))
3340 (defun org-agenda-entry-text-show ()
3341 "Add entry context for all agenda lines."
3344 (goto-char (point-max))
3345 (beginning-of-line 1)
3347 (when (org-get-at-bol 'org-hd-marker)
3348 (org-agenda-entry-text-show-here))
3349 (beginning-of-line 0))))
3351 (defun org-agenda-entry-text-hide ()
3352 "Remove any shown entry context."
3355 (if (eq (overlay-get o 'org-overlay-type)
3356 'agenda-entry-content)
3357 (progn (delete-overlay o) t)))
3358 (overlays-in (point-min) (point-max)))))
3360 (defun org-agenda-get-day-face (date)
3361 "Return the face DATE should be displayed with."
3362 (or (and (functionp org-agenda-day-face-function)
3363 (funcall org-agenda-day-face-function date))
3364 (cond ((org-agenda-todayp date)
3365 'org-agenda-date-today)
3366 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3367 'org-agenda-date-weekend)
3368 (t 'org-agenda-date))))
3372 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3374 (defun org-timeline (&optional dotodo)
3375 "Show a time-sorted view of the entries in the current org file.
3376 Only entries with a time stamp of today or later will be listed. With
3377 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3378 under the current date.
3379 If the buffer contains an active region, only check the region for
3382 (org-compile-prefix-format 'timeline)
3383 (org-set-sorting-strategy 'timeline)
3385 (doclosed org-agenda-show-log)
3386 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3388 (date (calendar-current-date))
3389 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3390 (end (if (org-region-active-p) (region-end) (point-max)))
3391 (day-numbers (org-get-all-dates beg end 'no-ranges
3392 t doclosed ; always include today
3393 org-timeline-show-empty-dates))
3394 (org-deadline-warning-days 0)
3395 (org-agenda-only-exact-dates t)
3400 (setq org-agenda-redo-command
3402 (list 'org-switch-to-buffer-other-window (current-buffer))
3403 (list 'org-timeline (list 'quote dotodo))))
3405 ;; Remove past dates from the list of dates.
3406 (setq day-numbers (delq nil (mapcar (lambda(x)
3407 (if (>= x today) x nil))
3409 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3410 (if doclosed (push :closed args))
3411 (push :timestamp args)
3412 (push :deadline args)
3413 (push :scheduled args)
3415 (if dotodo (push :todo args))
3416 (insert "Timeline of file " entry "\n")
3417 (add-text-properties (point-min) (point)
3418 (list 'face 'org-agenda-structure))
3419 (org-agenda-mark-header-line (point-min))
3420 (while (setq d (pop day-numbers))
3421 (if (and (listp d) (eq (car d) :omitted))
3424 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3425 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3426 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3427 (if (and (>= d today)
3432 (insert (make-string 79 ?-) "\n")))
3433 (setq date (calendar-gregorian-from-absolute d))
3435 (setq rtn (and (not emptyp)
3436 (apply 'org-agenda-get-day-entries entry
3438 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3441 (if (stringp org-agenda-format-date)
3442 (format-time-string org-agenda-format-date
3443 (org-time-from-absolute date))
3444 (funcall org-agenda-format-date date))
3446 (put-text-property s (1- (point)) 'face
3447 (org-agenda-get-day-face date))
3448 (put-text-property s (1- (point)) 'org-date-line t)
3449 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3451 (put-text-property s (1- (point)) 'org-today t))
3452 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3453 (put-text-property s (1- (point)) 'day d)))))
3454 (goto-char (point-min))
3455 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3457 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3458 (org-finalize-agenda)
3459 (setq buffer-read-only t)))
3461 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3462 "Return a list of all relevant day numbers from BEG to END buffer positions.
3463 If NO-RANGES is non-nil, include only the start and end dates of a range,
3464 not every single day in the range. If FORCE-TODAY is non-nil, make
3465 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3466 inactive time stamps (those in square brackets) are included.
3467 When EMPTY is non-nil, also include days without any entries."
3469 (if pre-re pre-re "")
3470 (if inactive org-ts-regexp-both org-ts-regexp)))
3471 dates dates1 date day day1 day2 ts1 ts2 pos)
3473 (setq dates (list (org-today))))
3476 (while (re-search-forward re end t)
3477 (setq day (time-to-days (org-time-string-to-time
3478 (substring (match-string 1) 0 10)
3479 (current-buffer) (match-beginning 0))))
3480 (or (memq day dates) (push day dates)))
3483 (while (re-search-forward org-tr-regexp end t)
3484 (setq pos (match-beginning 0))
3485 (setq ts1 (substring (match-string 1) 0 10)
3486 ts2 (substring (match-string 2) 0 10)
3487 day1 (time-to-days (org-time-string-to-time
3488 ts1 (current-buffer) pos))
3489 day2 (time-to-days (org-time-string-to-time
3490 ts2 (current-buffer) pos)))
3491 (while (< (setq day1 (1+ day1)) day2)
3492 (or (memq day1 dates) (push day1 dates)))))
3493 (setq dates (sort dates '<))
3495 (while (setq day (pop dates))
3496 (setq day2 (car dates))
3498 (when (and day2 empty)
3499 (if (or (eq empty t)
3500 (and (numberp empty) (<= (- day2 day) empty)))
3501 (while (< (setq day (1+ day)) day2)
3502 (push (list day) dates1))
3503 (push (cons :omitted (- day2 day)) dates1))))
3504 (setq dates (nreverse dates1)))
3507 ;;; Agenda Daily/Weekly
3509 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3510 "Start day for the agenda view.
3511 Custom commands can set this variable in the options section.")
3512 (defvar org-starting-day nil) ; local variable in the agenda buffer
3513 (defvar org-agenda-current-span nil
3514 "The current span used in the agenda view.") ; local variable in the agenda buffer
3515 (defvar org-arg-loc nil) ; local variable
3517 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3518 "List of types searched for when creating the daily/weekly agenda.
3519 This variable is a list of symbols that controls the types of
3520 items that appear in the daily/weekly agenda. Allowed symbols in this
3523 :timestamp List items containing a date stamp or date range matching
3524 the selected date. This includes sexp entries in
3527 :sexp List entries resulting from plain diary-like sexps.
3529 :deadline List deadline due on that date. When the date is today,
3530 also list any deadlines past due, or due within
3531 `org-deadline-warning-days'. `:deadline' must appear before
3532 `:scheduled' if the setting of
3533 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3536 :scheduled List all items which are scheduled for the given date.
3537 The diary for *today* also contains items which were
3538 scheduled earlier and are not yet marked DONE.
3540 By default, all four types are turned on.
3542 Never set this variable globally using `setq', because then it
3543 will apply to all future agenda commands. Instead, bind it with
3544 `let' to scope it dynamically into the agenda-constructing
3545 command. A good way to set it is through options in
3546 `org-agenda-custom-commands'. For a more flexible (though
3547 somewhat less efficient) way of determining what is included in
3548 the daily/weekly agenda, see `org-agenda-skip-function'.")
3551 (defun org-agenda-list (&optional arg start-day span)
3552 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3553 The view will be for the current day or week, but from the overview buffer
3554 you will be able to go to other days/weeks.
3556 With a numeric prefix argument in an interactive call, the agenda will
3557 span ARG days. Lisp programs should instead specify SPAN to change
3558 the number of days. SPAN defaults to `org-agenda-span'.
3560 START-DAY defaults to TODAY, or to the most recent match for the weekday
3561 given in `org-agenda-start-on-weekday'."
3563 (if (and (integerp arg) (> arg 0))
3564 (setq span arg arg nil))
3565 (setq start-day (or start-day org-agenda-start-day))
3566 (if org-agenda-overriding-arguments
3567 (setq arg (car org-agenda-overriding-arguments)
3568 start-day (nth 1 org-agenda-overriding-arguments)
3569 span (nth 2 org-agenda-overriding-arguments)))
3570 (if (stringp start-day)
3571 ;; Convert to an absolute day number
3572 (setq start-day (time-to-days (org-read-date nil t start-day))))
3573 (setq org-agenda-last-arguments (list arg start-day span))
3574 (org-compile-prefix-format 'agenda)
3575 (org-set-sorting-strategy 'agenda)
3576 (let* ((span (org-agenda-ndays-to-span
3577 (or span org-agenda-ndays org-agenda-span)))
3579 (sd (or start-day today))
3580 (ndays (org-agenda-span-to-ndays span sd))
3581 (org-agenda-start-on-weekday
3583 org-agenda-start-on-weekday))
3584 (thefiles (org-agenda-files nil 'ifmode))
3586 (start (if (or (null org-agenda-start-on-weekday)
3589 (let* ((nt (calendar-day-of-week
3590 (calendar-gregorian-from-absolute sd)))
3591 (n1 org-agenda-start-on-weekday)
3593 (- sd (+ (if (< d 0) 7 0) d)))))
3594 (day-numbers (list start))
3596 (inhibit-redisplay (not debug-on-error))
3597 s e rtn rtnall file date d start-pos end-pos todayp
3598 clocktable-start clocktable-end filter)
3599 (setq org-agenda-redo-command
3600 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3601 (dotimes (n (1- ndays))
3602 (push (1+ (car day-numbers)) day-numbers))
3603 (setq day-numbers (nreverse day-numbers))
3604 (setq clocktable-start (car day-numbers)
3605 clocktable-end (1+ (or (org-last day-numbers) 0)))
3606 (org-prepare-agenda "Day/Week")
3607 (org-set-local 'org-starting-day (car day-numbers))
3608 (org-set-local 'org-arg-loc arg)
3609 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3610 (unless org-agenda-compact-blocks
3611 (let* ((d1 (car day-numbers))
3612 (d2 (org-last day-numbers))
3613 (w1 (org-days-to-iso-week d1))
3614 (w2 (org-days-to-iso-week d2)))
3616 (if org-agenda-overriding-header
3617 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3618 nil 'face 'org-agenda-structure) "\n")
3619 (insert (org-agenda-span-name span)
3621 (if (< (- d2 d1) 350)
3623 (format " (W%02d)" w1)
3624 (format " (W%02d-W%02d)" w1 w2))
3627 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3629 (org-agenda-mark-header-line s))
3630 (while (setq d (pop day-numbers))
3631 (setq date (calendar-gregorian-from-absolute d)
3633 (if (or (setq todayp (= d today))
3634 (and (not start-pos) (= d sd)))
3635 (setq start-pos (point))
3636 (if (and start-pos (not end-pos))
3637 (setq end-pos (point))))
3638 (setq files thefiles
3640 (while (setq file (pop files))
3642 (org-check-agenda-file file)
3643 (let ((org-agenda-entry-types org-agenda-entry-types))
3644 (unless org-agenda-include-deadlines
3645 (setq org-agenda-entry-types
3646 (delq :deadline org-agenda-entry-types)))
3648 ((memq org-agenda-show-log '(only clockcheck))
3649 (setq rtn (org-agenda-get-day-entries
3650 file date :closed)))
3651 (org-agenda-show-log
3652 (setq rtn (apply 'org-agenda-get-day-entries
3654 (append '(:closed) org-agenda-entry-types))))
3656 (setq rtn (apply 'org-agenda-get-day-entries
3658 org-agenda-entry-types)))))
3659 (setq rtnall (append rtnall rtn)))) ;; all entries
3660 (if org-agenda-include-diary
3661 (let ((org-agenda-search-headline-for-time t))
3662 (require 'diary-lib)
3663 (setq rtn (org-get-entries-from-diary date))
3664 (setq rtnall (append rtnall rtn))))
3665 (if (or rtnall org-agenda-show-all-dates)
3667 (setq day-cnt (1+ day-cnt))
3669 (if (stringp org-agenda-format-date)
3670 (format-time-string org-agenda-format-date
3671 (org-time-from-absolute date))
3672 (funcall org-agenda-format-date date))
3674 (put-text-property s (1- (point)) 'face
3675 (org-agenda-get-day-face date))
3676 (put-text-property s (1- (point)) 'org-date-line t)
3677 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3678 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3680 (put-text-property s (1- (point)) 'org-today t))
3681 (if rtnall (insert ;; all entries
3682 (org-finalize-agenda-entries
3683 (org-agenda-add-time-grid-maybe
3684 rtnall ndays todayp))
3686 (put-text-property s (1- (point)) 'day d)
3687 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3688 (when (and org-agenda-clockreport-mode clocktable-start)
3689 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3690 ;; the above line is to ensure the restricted range!
3691 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3693 (setq p (org-plist-delete p :block))
3694 (setq p (plist-put p :tstart clocktable-start))
3695 (setq p (plist-put p :tend clocktable-end))
3696 (setq p (plist-put p :scope 'agenda))
3697 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3698 (setq filter (or org-agenda-tag-filter-while-redo
3699 (get 'org-agenda-tag-filter :preset-filter))))
3700 (setq p (plist-put p :tags (mapconcat (lambda (x)
3701 (if (string-match "[<>=]" x)
3705 (setq tbl (apply 'org-get-clocktable p))
3707 (goto-char (point-min))
3708 (or org-agenda-multi (org-fit-agenda-window))
3709 (unless (and (pos-visible-in-window-p (point-min))
3710 (pos-visible-in-window-p (point-max)))
3711 (goto-char (1- (point-max)))
3713 (if (not (pos-visible-in-window-p (or start-pos 1)))
3715 (goto-char (or start-pos 1))
3717 (goto-char (or start-pos 1))
3718 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3719 (if (eq org-agenda-show-log 'clockcheck)
3720 (org-agenda-show-clocking-issues))
3721 (org-finalize-agenda)
3722 (setq buffer-read-only t)
3725 (defun org-agenda-ndays-to-span (n)
3726 "Return a span symbol for a span of N days, or N if none matches."
3727 (cond ((symbolp n) n)
3732 (defun org-agenda-span-to-ndays (span start-day)
3733 "Return ndays from SPAN starting at START-DAY."
3734 (cond ((numberp span) span)
3738 (let ((date (calendar-gregorian-from-absolute start-day)))
3739 (calendar-last-day-of-month (car date) (caddr date))))
3741 (let ((date (calendar-gregorian-from-absolute start-day)))
3742 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3744 (defun org-agenda-span-name (span)
3745 "Return a SPAN name."
3749 (capitalize (symbol-name span))
3750 (format "%d days" span))))
3752 ;;; Agenda word search
3754 (defvar org-agenda-search-history nil)
3755 (defvar org-todo-only nil)
3757 (defvar org-search-syntax-table nil
3758 "Special syntax table for org-mode search.
3759 In this table, we have single quotes not as word constituents, to
3760 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3762 (defun org-search-syntax-table ()
3763 (unless org-search-syntax-table
3764 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3765 (modify-syntax-entry ?' "." org-search-syntax-table)
3766 (modify-syntax-entry ?` "." org-search-syntax-table))
3767 org-search-syntax-table)
3769 (defvar org-agenda-last-search-view-search-was-boolean nil)
3772 (defun org-search-view (&optional todo-only string edit-at)
3773 "Show all entries that contain a phrase or words or regular expressions.
3775 With optional prefix argument TODO-ONLY, only consider entries that are
3776 TODO entries. The argument STRING can be used to pass a default search
3777 string into this function. If EDIT-AT is non-nil, it means that the
3778 user should get a chance to edit this string, with cursor at position
3781 The search string can be viewed either as a phrase that should be found as
3782 is, or it can be broken into a number of snippets, each of which must match
3783 in a Boolean way to select an entry. The default depends on the variable
3784 `org-agenda-search-view-always-boolean'.
3785 Even if this is turned off (the default) you can always switch to
3786 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3788 The default is a direct search of the whole phrase, where each space in
3789 the search string can expand to an arbitrary amount of whitespace,
3792 If using a Boolean search, the search string is split on whitespace and
3793 each snippet is searched separately, with logical AND to select an entry.
3794 Words prefixed with a minus must *not* occur in the entry. Words without
3795 a prefix or prefixed with a plus must occur in the entry. Matching is
3796 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3797 match whole words, not parts of a word) if
3798 `org-agenda-search-view-force-full-words' is set (default is nil).
3800 Boolean search snippets enclosed by curly braces are interpreted as
3801 regular expressions that must or (when preceded with \"-\") must not
3802 match in the entry. Snippets enclosed into double quotes will be taken
3803 as a whole, to include whitespace.
3805 - If the search string starts with an asterisk, search only in headlines.
3806 - If (possibly after the leading star) the search string starts with an
3807 exclamation mark, this also means to look at TODO entries only, an effect
3808 that can also be achieved with a prefix argument.
3809 - If (possibly after star and exclamation mark) the search string starts
3810 with a colon, this will mean that the (non-regexp) snippets of the
3811 Boolean search must match as full words.
3813 This command searches the agenda files, and in addition the files listed
3814 in `org-agenda-text-search-extra-files'."
3816 (org-compile-prefix-format 'search)
3817 (org-set-sorting-strategy 'search)
3818 (org-prepare-agenda "SEARCH")
3819 (let* ((props (list 'face nil
3820 'done-face 'org-agenda-done
3821 'org-not-done-regexp org-not-done-regexp
3822 'org-todo-regexp org-todo-regexp
3823 'org-complex-heading-regexp org-complex-heading-regexp
3824 'mouse-face 'highlight
3825 'help-echo (format "mouse-2 or RET jump to location")))
3826 (full-words org-agenda-search-view-force-full-words)
3827 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3828 regexp rtn rtnall files file pos
3829 marker category org-category-pos tags c neg re boolean
3830 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3831 (unless (and (not edit-at)
3833 (string-match "\\S-" string))
3834 (setq string (read-string
3835 (if org-agenda-search-view-always-boolean
3836 "[+-]Word/{Regexp} ...: "
3837 "Phrase, or [+-]Word/{Regexp} ...: ")
3839 ((integerp edit-at) (cons string edit-at))
3841 'org-agenda-search-history)))
3842 (org-set-local 'org-todo-only todo-only)
3843 (setq org-agenda-redo-command
3844 (list 'org-search-view (if todo-only t nil) string
3845 '(if current-prefix-arg 1 nil)))
3846 (setq org-agenda-query-string string)
3848 (if (equal (string-to-char string) ?*)
3850 words (substring string 1))
3851 (setq words string))
3852 (when (equal (string-to-char words) ?!)
3854 words (substring words 1)))
3855 (when (equal (string-to-char words) ?:)
3857 words (substring words 1)))
3858 (if (or org-agenda-search-view-always-boolean
3859 (member (string-to-char words) '(?- ?+ ?\{)))
3861 (setq words (org-split-string words))
3863 (while (setq w (pop words))
3864 (while (and (string-match "\\\\\\'" w) words)
3865 (setq w (concat (substring w 0 -1) " " (pop words))))
3867 (setq words (nreverse www) www nil)
3868 (while (setq w (pop words))
3869 (when (and (string-match "\\`[-+]?{" w)
3870 (not (string-match "}\\'" w)))
3871 (while (and words (not (string-match "}\\'" (car words))))
3872 (setq w (concat w " " (pop words))))
3873 (setq w (concat w " " (pop words))))
3875 (setq words (nreverse www)))
3876 (setq org-agenda-last-search-view-search-was-boolean boolean)
3879 (while (setq w (pop words))
3880 (if (or (equal (substring w 0 1) "\"")
3881 (and (> (length w) 1)
3882 (member (substring w 0 1) '("+" "-"))
3883 (equal (substring w 1 2) "\"")))
3884 (while (and words (not (equal (substring w -1) "\"")))
3885 (setq w (concat w " " (pop words)))))
3886 (and (string-match "\\`\\([-+]?\\)\"" w)
3887 (setq w (replace-match "\\1" nil nil w)))
3888 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3890 (setq words (nreverse wds))))
3893 (setq c (string-to-char w))
3895 (setq neg t w (substring w 1))
3897 (setq neg nil w (substring w 1))
3899 (if (string-match "\\`{.*}\\'" w)
3900 (setq re (substring w 1 -1))
3902 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3903 (setq re (regexp-quote (downcase w)))))
3904 (if neg (push re regexps-) (push re regexps+)))
3906 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3908 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3910 (setq regexp org-outline-regexp-bol)
3911 (setq regexp (pop regexps+))
3912 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
3914 (setq files (org-agenda-files nil 'ifmode))
3915 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3916 (pop org-agenda-text-search-extra-files)
3917 (setq files (org-add-archive-files files)))
3918 (setq files (append files org-agenda-text-search-extra-files)
3920 (while (setq file (pop files))
3923 (org-check-agenda-file file)
3924 (setq buffer (if (file-exists-p file)
3925 (org-get-agenda-file-buffer file)
3926 (error "No such file %s" file)))
3928 ;; If file does not exist, make sure an error message is sent
3929 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3931 (with-current-buffer buffer
3932 (with-syntax-table (org-search-syntax-table)
3933 (unless (eq major-mode 'org-mode)
3934 (error "Agenda file %s is not in `org-mode'" file))
3935 (let ((case-fold-search t))
3938 (if org-agenda-restrict
3939 (narrow-to-region org-agenda-restrict-begin
3940 org-agenda-restrict-end)
3942 (goto-char (point-min))
3943 (unless (or (org-at-heading-p)
3944 (outline-next-heading))
3945 (throw 'nextfile t))
3946 (goto-char (max (point-min) (1- (point))))
3947 (while (re-search-forward regexp nil t)
3948 (org-back-to-heading t)
3949 (skip-chars-forward "* ")
3950 (setq beg (point-at-bol)
3952 end (progn (outline-next-heading) (point)))
3956 (setq str (buffer-substring-no-properties
3958 (if hdl-only (point-at-eol) end)))
3959 (mapc (lambda (wr) (when (string-match wr str)
3960 (goto-char (1- end))
3963 (mapc (lambda (wr) (unless (string-match wr str)
3964 (goto-char (1- end))
3967 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3971 (setq marker (org-agenda-new-marker (point))
3972 category (org-get-category)
3973 org-category-pos (get-text-property (point) 'org-category-position)
3974 tags (org-get-tags-at (point))
3975 txt (org-agenda-format-item
3977 (buffer-substring-no-properties
3978 beg1 (point-at-eol))
3980 (org-add-props txt props
3981 'org-marker marker 'org-hd-marker marker
3982 'org-todo-regexp org-todo-regexp
3983 'org-complex-heading-regexp org-complex-heading-regexp
3984 'priority 1000 'org-category category
3985 'org-category-position org-category-pos
3988 (goto-char (1- end))))))))))
3989 (setq rtn (nreverse ee))
3990 (setq rtnall (append rtnall rtn)))
3991 (if org-agenda-overriding-header
3992 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3993 nil 'face 'org-agenda-structure) "\n")
3994 (insert "Search words: ")
3995 (add-text-properties (point-min) (1- (point))
3996 (list 'face 'org-agenda-structure))
3998 (insert string "\n")
3999 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4001 (unless org-agenda-multi
4002 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4003 (add-text-properties pos (1- (point))
4004 (list 'face 'org-agenda-structure))))
4005 (org-agenda-mark-header-line (point-min))
4007 (insert (org-finalize-agenda-entries rtnall) "\n"))
4008 (goto-char (point-min))
4009 (or org-agenda-multi (org-fit-agenda-window))
4010 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4011 (org-finalize-agenda)
4012 (setq buffer-read-only t)))
4014 ;;; Agenda TODO list
4016 (defvar org-select-this-todo-keyword nil)
4017 (defvar org-last-arg nil)
4020 (defun org-todo-list (arg)
4021 "Show all (not done) TODO entries from all agenda file in a single list.
4022 The prefix arg can be used to select a specific TODO keyword and limit
4023 the list to these. When using \\[universal-argument], you will be prompted
4024 for a keyword. A numeric prefix directly selects the Nth keyword in
4025 `org-todo-keywords-1'."
4027 (org-compile-prefix-format 'todo)
4028 (org-set-sorting-strategy 'todo)
4029 (org-prepare-agenda "TODO")
4030 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4031 (let* ((today (org-today))
4032 (date (calendar-gregorian-from-absolute today))
4033 (kwds org-todo-keywords-for-agenda)
4034 (completion-ignore-case t)
4035 (org-select-this-todo-keyword
4036 (if (stringp arg) arg
4037 (and arg (integerp arg) (> arg 0)
4038 (nth (1- arg) kwds))))
4039 rtn rtnall files file pos)
4040 (when (equal arg '(4))
4041 (setq org-select-this-todo-keyword
4042 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4043 (mapcar 'list kwds) nil nil)))
4044 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4045 (org-set-local 'org-last-arg arg)
4046 (setq org-agenda-redo-command
4047 '(org-todo-list (or current-prefix-arg org-last-arg)))
4048 (setq files (org-agenda-files nil 'ifmode)
4050 (while (setq file (pop files))
4052 (org-check-agenda-file file)
4053 (setq rtn (org-agenda-get-day-entries file date :todo))
4054 (setq rtnall (append rtnall rtn))))
4055 (if org-agenda-overriding-header
4056 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4057 nil 'face 'org-agenda-structure) "\n")
4058 (insert "Global list of TODO items of type: ")
4059 (add-text-properties (point-min) (1- (point))
4060 (list 'face 'org-agenda-structure
4063 (or org-select-this-todo-keyword "ALL"))))
4064 (org-agenda-mark-header-line (point-min))
4066 (insert (or org-select-this-todo-keyword "ALL") "\n")
4067 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4069 (unless org-agenda-multi
4070 (insert "Available with `N r': (0)ALL")
4073 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4074 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4079 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4080 (org-agenda-mark-header-line (point-min))
4082 (insert (org-finalize-agenda-entries rtnall) "\n"))
4083 (goto-char (point-min))
4084 (or org-agenda-multi (org-fit-agenda-window))
4085 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4086 (org-finalize-agenda)
4087 (setq buffer-read-only t)))
4089 ;;; Agenda tags match
4092 (defun org-tags-view (&optional todo-only match)
4093 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4094 The prefix arg TODO-ONLY limits the search to TODO entries."
4096 (org-compile-prefix-format 'tags)
4097 (org-set-sorting-strategy 'tags)
4098 (let* ((org-tags-match-list-sublevels
4099 org-tags-match-list-sublevels)
4100 (completion-ignore-case t)
4101 rtn rtnall files file pos matcher
4103 (when (and (stringp match) (not (string-match "\\S-" match)))
4105 (setq matcher (org-make-tags-matcher match)
4106 match (car matcher) matcher (cdr matcher))
4107 (org-prepare-agenda (concat "TAGS " match))
4108 (setq org-agenda-query-string match)
4109 (setq org-agenda-redo-command
4110 (list 'org-tags-view (list 'quote todo-only)
4111 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4112 (setq files (org-agenda-files nil 'ifmode)
4114 (while (setq file (pop files))
4116 (org-check-agenda-file file)
4117 (setq buffer (if (file-exists-p file)
4118 (org-get-agenda-file-buffer file)
4119 (error "No such file %s" file)))
4121 ;; If file does not exist, error message to agenda
4123 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4124 rtnall (append rtnall rtn))
4125 (with-current-buffer buffer
4126 (unless (eq major-mode 'org-mode)
4127 (error "Agenda file %s is not in `org-mode'" file))
4130 (if org-agenda-restrict
4131 (narrow-to-region org-agenda-restrict-begin
4132 org-agenda-restrict-end)
4134 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4135 (setq rtnall (append rtnall rtn))))))))
4136 (if org-agenda-overriding-header
4137 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4138 nil 'face 'org-agenda-structure) "\n")
4139 (insert "Headlines with TAGS match: ")
4140 (add-text-properties (point-min) (1- (point))
4141 (list 'face 'org-agenda-structure
4143 (concat "Match: " match)))
4146 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4148 (unless org-agenda-multi
4149 (insert "Press `C-u r' to search again with new search string\n"))
4150 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4151 (org-agenda-mark-header-line (point-min))
4153 (insert (org-finalize-agenda-entries rtnall) "\n"))
4154 (goto-char (point-min))
4155 (or org-agenda-multi (org-fit-agenda-window))
4156 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4157 (org-finalize-agenda)
4158 (setq buffer-read-only t)))
4160 ;;; Agenda Finding stuck projects
4162 (defvar org-agenda-skip-regexp nil
4163 "Regular expression used in skipping subtrees for the agenda.
4164 This is basically a temporary global variable that can be set and then
4165 used by user-defined selections using `org-agenda-skip-function'.")
4167 (defvar org-agenda-overriding-header nil
4168 "When set during agenda, todo and tags searches it replaces the header.
4169 This variable should not be set directly, but custom commands can bind it
4170 in the options section.")
4172 (defun org-agenda-skip-entry-when-regexp-matches ()
4173 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4174 If yes, it returns the end position of this entry, causing agenda commands
4175 to skip the entry but continuing the search in the subtree. This is a
4176 function that can be put into `org-agenda-skip-function' for the duration
4178 (let ((end (save-excursion (org-end-of-subtree t)))
4181 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4184 (defun org-agenda-skip-subtree-when-regexp-matches ()
4185 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4186 If yes, it returns the end position of this tree, causing agenda commands
4187 to skip this subtree. This is a function that can be put into
4188 `org-agenda-skip-function' for the duration of a command."
4189 (let ((end (save-excursion (org-end-of-subtree t)))
4192 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4195 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4196 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4197 If yes, it returns the end position of the current entry (NOT the tree),
4198 causing agenda commands to skip the entry but continuing the search in
4199 the subtree. This is a function that can be put into
4200 `org-agenda-skip-function' for the duration of a command. An important
4201 use of this function is for the stuck project list."
4202 (let ((end (save-excursion (org-end-of-subtree t)))
4203 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4206 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4207 (and skip entry-end)))
4209 (defun org-agenda-skip-entry-if (&rest conditions)
4210 "Skip entry if any of CONDITIONS is true.
4211 See `org-agenda-skip-if' for details."
4212 (org-agenda-skip-if nil conditions))
4214 (defun org-agenda-skip-subtree-if (&rest conditions)
4215 "Skip entry if any of CONDITIONS is true.
4216 See `org-agenda-skip-if' for details."
4217 (org-agenda-skip-if t conditions))
4219 (defun org-agenda-skip-if (subtree conditions)
4220 "Checks current entity for CONDITIONS.
4221 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4222 the entry, i.e. the text before the next heading is checked.
4224 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4225 from different tests. Valid conditions are:
4227 scheduled Check if there is a scheduled cookie
4228 notscheduled Check if there is no scheduled cookie
4229 deadline Check if there is a deadline
4230 notdeadline Check if there is no deadline
4231 timestamp Check if there is a timestamp (also deadline or scheduled)
4232 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4233 regexp Check if regexp matches
4234 notregexp Check if regexp does not match.
4235 todo Check if TODO keyword matches
4236 nottodo Check if TODO keyword does not match
4238 The regexp is taken from the conditions list, it must come right after
4239 the `regexp' or `notregexp' element.
4241 `todo' and `nottodo' accept as an argument a list of todo
4242 keywords, which may include \"*\" to match any todo keyword.
4244 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4246 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4248 Instead of a list a keyword class may be given
4250 (org-agenda-skip-entry-if 'nottodo 'done)
4252 would skip entries that haven't been marked with any of \"DONE\"
4253 keywords. Possible classes are: `todo', `done', `any'.
4255 If any of these conditions is met, this function returns the end point of
4256 the entity, causing the search to continue from there. This is a function
4257 that can be put into `org-agenda-skip-function' for the duration of a command."
4259 (org-back-to-heading t)
4262 (progn (org-end-of-subtree t) (point))
4263 (progn (outline-next-heading) (1- (point)))))
4267 (and (memq 'scheduled conditions)
4268 (re-search-forward org-scheduled-time-regexp end t))
4269 (and (memq 'notscheduled conditions)
4270 (not (re-search-forward org-scheduled-time-regexp end t)))
4271 (and (memq 'deadline conditions)
4272 (re-search-forward org-deadline-time-regexp end t))
4273 (and (memq 'notdeadline conditions)
4274 (not (re-search-forward org-deadline-time-regexp end t)))
4275 (and (memq 'timestamp conditions)
4276 (re-search-forward org-ts-regexp end t))
4277 (and (memq 'nottimestamp conditions)
4278 (not (re-search-forward org-ts-regexp end t)))
4279 (and (setq m (memq 'regexp conditions))
4281 (re-search-forward (nth 1 m) end t))
4282 (and (setq m (memq 'notregexp conditions))
4284 (not (re-search-forward (nth 1 m) end t)))
4286 (setq m (memq 'todo conditions))
4287 (setq m (memq 'nottodo conditions)))
4288 (org-agenda-skip-if-todo m end)))
4291 (defun org-agenda-skip-if-todo (args end)
4292 "Helper function for `org-agenda-skip-if', do not use it directly.
4293 ARGS is a list with first element either `todo' or `nottodo'.
4294 The remainder is either a list of TODO keywords, or a state symbol
4295 `todo' or `done' or `any'."
4296 (let ((kw (car args))
4302 ((listp arg) ;; list of keywords
4303 (if (member "*" arg)
4304 (mapcar 'substring-no-properties org-todo-keywords-1)
4306 ((symbolp arg) ;; keyword class name
4309 (org-delete-all org-done-keywords
4310 (mapcar 'substring-no-properties
4311 org-todo-keywords-1)))
4312 ((eq arg 'done) org-done-keywords)
4314 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4316 (concat "^\\*+[ \t]+\\<\\("
4317 (mapconcat 'identity todo-wds "\\|")
4320 (re-search-forward todo-re end t)
4321 (not (re-search-forward todo-re end t)))))
4324 (defun org-agenda-list-stuck-projects (&rest ignore)
4325 "Create agenda view for projects that are stuck.
4326 Stuck projects are project that have no next actions. For the definitions
4327 of what a project is and how to check if it stuck, customize the variable
4328 `org-stuck-projects'."
4330 (let* ((org-agenda-skip-function
4331 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4332 ;; We could have used org-agenda-skip-if here.
4333 (org-agenda-overriding-header
4334 (or org-agenda-overriding-header "List of stuck projects: "))
4335 (matcher (nth 0 org-stuck-projects))
4336 (todo (nth 1 org-stuck-projects))
4337 (todo-wds (if (member "*" todo)
4339 (org-prepare-agenda-buffers (org-agenda-files
4342 org-done-keywords-for-agenda
4343 (copy-sequence org-todo-keywords-for-agenda)))
4345 (todo-re (concat "^\\*+[ \t]+\\("
4346 (mapconcat 'identity todo-wds "\\|")
4348 (tags (nth 2 org-stuck-projects))
4349 (tags-re (if (member "*" tags)
4350 (concat org-outline-regexp-bol
4351 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4353 (concat org-outline-regexp-bol
4355 (mapconcat 'identity tags "\\|")
4356 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4357 (gen-re (nth 3 org-stuck-projects))
4363 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4365 (setq org-agenda-skip-regexp
4367 (mapconcat 'identity re-list "\\|")
4368 (error "No information how to identify unstuck projects")))
4369 (org-tags-view nil matcher)
4370 (with-current-buffer org-agenda-buffer-name
4371 (setq org-agenda-redo-command
4372 '(org-agenda-list-stuck-projects
4373 (or current-prefix-arg org-last-arg))))))
4375 ;;; Diary integration
4377 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4378 (defvar list-diary-entries-hook)
4379 (defvar diary-time-regexp)
4380 (defun org-get-entries-from-diary (date)
4381 "Get the (Emacs Calendar) diary entries for DATE."
4382 (require 'diary-lib)
4383 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4384 (diary-display-hook '(fancy-diary-display))
4385 (diary-display-function 'fancy-diary-display)
4387 (list-diary-entries-hook
4388 (cons 'org-diary-default-entry list-diary-entries-hook))
4389 (diary-file-name-prefix-function nil) ; turn this feature off
4390 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4392 (org-disable-agenda-to-diary t))
4394 (save-window-excursion
4395 (funcall (if (fboundp 'diary-list-entries)
4396 'diary-list-entries 'list-diary-entries)
4398 (if (not (get-buffer diary-fancy-buffer))
4400 (with-current-buffer diary-fancy-buffer
4401 (setq buffer-read-only nil)
4402 (if (zerop (buffer-size))
4405 ;; Omit the date and other unnecessary stuff
4406 (org-agenda-cleanup-fancy-diary)
4407 ;; Add prefix to each line and extend the text properties
4408 (if (zerop (buffer-size))
4410 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4413 (insert entries) (goto-char (point-min))
4414 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4415 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4416 (replace-match (concat "; " (match-string 1)))))
4418 (set-buffer-modified-p nil)
4419 (kill-buffer diary-fancy-buffer)))
4421 (setq entries (org-split-string entries "\n"))
4425 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4426 ;; Extend the text properties to the beginning of the line
4427 (org-add-props x (text-properties-at (1- (length x)) x)
4428 'type "diary" 'date date 'face 'org-agenda-diary))
4431 (defvar org-agenda-cleanup-fancy-diary-hook nil
4432 "Hook run when the fancy diary buffer is cleaned up.")
4434 (defun org-agenda-cleanup-fancy-diary ()
4435 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4436 This gets rid of the date, the underline under the date, and
4437 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4438 date. It also removes lines that contain only whitespace."
4439 (goto-char (point-min))
4440 (if (looking-at ".*?:[ \t]*")
4443 (re-search-forward "\n=+$" nil t)
4445 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4446 (re-search-forward "\n=+$" nil t)
4447 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4448 (goto-char (point-min))
4449 (while (re-search-forward "^ +\n" nil t)
4451 (goto-char (point-min))
4452 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4454 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4456 ;; Make sure entries from the diary have the right text properties.
4457 (eval-after-load "diary-lib"
4458 '(if (boundp 'diary-modify-entry-list-string-function)
4459 ;; We can rely on the hook, nothing to do
4461 ;; Hook not available, must use advice to make this work
4462 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4463 "Make the position visible."
4464 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4467 (setq string (org-modify-diary-entry-string string))))))
4469 (defun org-modify-diary-entry-string (string)
4470 "Add text properties to string, allowing org-mode to act on it."
4471 (org-add-props string nil
4472 'mouse-face 'highlight
4473 'help-echo (if buffer-file-name
4474 (format "mouse-2 or RET jump to diary file %s"
4475 (abbreviate-file-name buffer-file-name))
4477 'org-agenda-diary-link t
4478 'org-marker (org-agenda-new-marker (point-at-bol))))
4480 (defun org-diary-default-entry ()
4481 "Add a dummy entry to the diary.
4482 Needed to avoid empty dates which mess up holiday display."
4483 ;; Catch the error if dealing with the new add-to-diary-alist
4484 (when org-disable-agenda-to-diary
4486 (org-add-to-diary-list original-date "Org-mode dummy" "")
4488 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4490 (defun org-add-to-diary-list (&rest args)
4491 (if (fboundp 'diary-add-to-list)
4492 (apply 'diary-add-to-list args)
4493 (apply 'add-to-diary-list args)))
4495 (defvar org-diary-last-run-time nil)
4498 (defun org-diary (&rest args)
4499 "Return diary information from org-files.
4500 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4501 It accesses org files and extracts information from those files to be
4502 listed in the diary. The function accepts arguments specifying what
4503 items should be listed. For a list of arguments allowed here, see the
4504 variable `org-agenda-entry-types'.
4506 The call in the diary file should look like this:
4508 &%%(org-diary) ~/path/to/some/orgfile.org
4510 Use a separate line for each org file to check. Or, if you omit the file name,
4511 all files listed in `org-agenda-files' will be checked automatically:
4515 If you don't give any arguments (as in the example above), the default
4516 arguments (:deadline :scheduled :timestamp :sexp) are used.
4517 So the example above may also be written as
4519 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4521 The function expects the lisp variables `entry' and `date' to be provided
4522 by the caller, because this is how the calendar works. Don't use this
4523 function from a program - use `org-agenda-get-day-entries' instead."
4524 (when (> (- (org-float-time)
4525 org-agenda-last-marker-time)
4527 (org-agenda-reset-markers))
4528 (org-compile-prefix-format 'agenda)
4529 (org-set-sorting-strategy 'agenda)
4530 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4531 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4533 (org-agenda-files t)))
4534 (time (org-float-time))
4536 (when (or (not org-diary-last-run-time)
4538 org-diary-last-run-time)
4540 (org-prepare-agenda-buffers files))
4541 (setq org-diary-last-run-time time)
4542 ;; If this is called during org-agenda, don't return any entries to
4543 ;; the calendar. Org Agenda will list these entries itself.
4544 (if org-disable-agenda-to-diary (setq files nil))
4545 (while (setq file (pop files))
4546 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4547 (setq results (append results rtn)))
4549 (concat (org-finalize-agenda-entries results) "\n"))))
4551 ;;; Agenda entry finders
4553 (defun org-agenda-get-day-entries (file date &rest args)
4554 "Does the work for `org-diary' and `org-agenda'.
4555 FILE is the path to a file to be checked for entries. DATE is date like
4556 the one returned by `calendar-current-date'. ARGS are symbols indicating
4557 which kind of entries should be extracted. For details about these, see
4558 the documentation of `org-diary'."
4559 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4560 (let* ((org-startup-folded nil)
4561 (org-startup-align-all-tables nil)
4562 (buffer (if (file-exists-p file)
4563 (org-get-agenda-file-buffer file)
4564 (error "No such file %s" file)))
4565 arg results rtn deadline-results)
4567 ;; If file does not exist, make sure an error message ends up in diary
4568 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4569 (with-current-buffer buffer
4570 (unless (eq major-mode 'org-mode)
4571 (error "Agenda file %s is not in `org-mode'" file))
4572 (let ((case-fold-search nil))
4575 (if org-agenda-restrict
4576 (narrow-to-region org-agenda-restrict-begin
4577 org-agenda-restrict-end)
4579 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4580 (while (setq arg (pop args))
4582 ((and (eq arg :todo)
4583 (equal date (calendar-gregorian-from-absolute
4585 (setq rtn (org-agenda-get-todos))
4586 (setq results (append results rtn)))
4587 ((eq arg :timestamp)
4588 (setq rtn (org-agenda-get-blocks))
4589 (setq results (append results rtn))
4590 (setq rtn (org-agenda-get-timestamps))
4591 (setq results (append results rtn)))
4593 (setq rtn (org-agenda-get-sexps))
4594 (setq results (append results rtn)))
4595 ((eq arg :scheduled)
4596 (setq rtn (org-agenda-get-scheduled deadline-results))
4597 (setq results (append results rtn)))
4599 (setq rtn (org-agenda-get-progress))
4600 (setq results (append results rtn)))
4602 (setq rtn (org-agenda-get-deadlines))
4603 (setq deadline-results (copy-sequence rtn))
4604 (setq results (append results rtn))))))))
4607 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4608 (defun org-agenda-get-todos ()
4609 "Return the TODO information for agenda display."
4610 (let* ((props (list 'face nil
4611 'done-face 'org-agenda-done
4612 'org-not-done-regexp org-not-done-regexp
4613 'org-todo-regexp org-todo-regexp
4614 'org-complex-heading-regexp org-complex-heading-regexp
4615 'mouse-face 'highlight
4617 (format "mouse-2 or RET jump to org file %s"
4618 (abbreviate-file-name buffer-file-name))))
4619 (regexp (format org-heading-keyword-regexp-format
4621 ((and org-select-this-todo-keyword
4622 (equal org-select-this-todo-keyword "*"))
4624 (org-select-this-todo-keyword
4626 (mapconcat 'identity
4628 org-select-this-todo-keyword
4631 (t org-not-done-regexp))))
4632 marker priority category org-category-pos tags todo-state
4634 (goto-char (point-min))
4635 (while (re-search-forward regexp nil t)
4640 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4641 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4642 (goto-char (1+ beg))
4643 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4645 (goto-char (match-beginning 2))
4646 (setq marker (org-agenda-new-marker (match-beginning 0))
4647 category (org-get-category)
4648 org-category-pos (get-text-property (point) 'org-category-position)
4650 (buffer-substring (match-beginning 2) (match-end 0)))
4651 tags (org-get-tags-at (point))
4652 txt (org-agenda-format-item "" txt category tags)
4653 priority (1+ (org-get-priority txt))
4654 todo-state (org-get-todo-state))
4655 (org-add-props txt props
4656 'org-marker marker 'org-hd-marker marker
4657 'priority priority 'org-category category
4658 'org-category-position org-category-pos
4659 'type "todo" 'todo-state todo-state)
4661 (if org-agenda-todo-list-sublevels
4662 (goto-char (match-end 2))
4663 (org-end-of-subtree 'invisible))))
4666 (defun org-agenda-todo-custom-ignore-p (time n)
4667 "Check whether timestamp is farther away then n number of days.
4668 This function is invoked if `org-agenda-todo-ignore-deadlines',
4669 `org-agenda-todo-ignore-scheduled' or
4670 `org-agenda-todo-ignore-timestamp' is set to an integer."
4671 (let ((days (org-days-to-time time)))
4677 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4679 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4680 (when (or org-agenda-todo-ignore-with-date
4681 org-agenda-todo-ignore-scheduled
4682 org-agenda-todo-ignore-deadlines
4683 org-agenda-todo-ignore-timestamp)
4684 (setq end (or end (save-excursion (outline-next-heading) (point))))
4686 (or (and org-agenda-todo-ignore-with-date
4687 (re-search-forward org-ts-regexp end t))
4688 (and org-agenda-todo-ignore-scheduled
4689 (re-search-forward org-scheduled-time-regexp end t)
4691 ((eq org-agenda-todo-ignore-scheduled 'future)
4692 (> (org-days-to-time (match-string 1)) 0))
4693 ((eq org-agenda-todo-ignore-scheduled 'past)
4694 (<= (org-days-to-time (match-string 1)) 0))
4695 ((numberp org-agenda-todo-ignore-scheduled)
4696 (org-agenda-todo-custom-ignore-p
4697 (match-string 1) org-agenda-todo-ignore-scheduled))
4699 (and org-agenda-todo-ignore-deadlines
4700 (re-search-forward org-deadline-time-regexp end t)
4702 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4703 ((eq org-agenda-todo-ignore-deadlines 'far)
4704 (not (org-deadline-close (match-string 1))))
4705 ((eq org-agenda-todo-ignore-deadlines 'future)
4706 (> (org-days-to-time (match-string 1)) 0))
4707 ((eq org-agenda-todo-ignore-deadlines 'past)
4708 (<= (org-days-to-time (match-string 1)) 0))
4709 ((numberp org-agenda-todo-ignore-deadlines)
4710 (org-agenda-todo-custom-ignore-p
4711 (match-string 1) org-agenda-todo-ignore-deadlines))
4712 (t (org-deadline-close (match-string 1)))))
4713 (and org-agenda-todo-ignore-timestamp
4714 (let ((buffer (current-buffer))
4717 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4719 ;; Copy current buffer into a temporary one
4721 (insert-buffer-substring buffer start end)
4722 (goto-char (point-min))
4723 ;; Delete SCHEDULED and DEADLINE items
4724 (while (re-search-forward regexp end t)
4725 (delete-region (match-beginning 0) (match-end 0)))
4726 (goto-char (point-min))
4727 ;; No search for timestamp left
4728 (when (re-search-forward org-ts-regexp nil t)
4730 ((eq org-agenda-todo-ignore-timestamp 'future)
4731 (> (org-days-to-time (match-string 1)) 0))
4732 ((eq org-agenda-todo-ignore-timestamp 'past)
4733 (<= (org-days-to-time (match-string 1)) 0))
4734 ((numberp org-agenda-todo-ignore-timestamp)
4735 (org-agenda-todo-custom-ignore-p
4736 (match-string 1) org-agenda-todo-ignore-timestamp))
4739 (defconst org-agenda-no-heading-message
4740 "No heading for this item in buffer or region.")
4742 (defun org-agenda-get-timestamps ()
4743 "Return the date stamp information for agenda display."
4744 (let* ((props (list 'face 'org-agenda-calendar-event
4745 'org-not-done-regexp org-not-done-regexp
4746 'org-todo-regexp org-todo-regexp
4747 'org-complex-heading-regexp org-complex-heading-regexp
4748 'mouse-face 'highlight
4750 (format "mouse-2 or RET jump to org file %s"
4751 (abbreviate-file-name buffer-file-name))))
4752 (d1 (calendar-absolute-from-gregorian date))
4758 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4762 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4766 (car org-time-stamp-formats)
4767 (apply 'encode-time ; DATE bound by calendar
4768 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4770 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4771 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4772 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4773 donep tmp priority category org-category-pos ee txt timestr tags
4774 b0 b3 e3 head todo-state end-of-match show-all)
4775 (goto-char (point-min))
4776 (while (setq end-of-match (re-search-forward regexp nil t))
4777 (setq b0 (match-beginning 0)
4778 b3 (match-beginning 3) e3 (match-end 3)
4779 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4780 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4782 org-agenda-repeating-timestamp-show-all)))
4784 (and (org-at-date-range-p) (throw :skip nil))
4786 (if (and (match-end 1)
4787 (not (= d1 (org-time-string-to-absolute
4788 (match-string 1) d1 nil show-all
4789 (current-buffer) b0))))
4792 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4794 (setq tmp (buffer-substring (max (point-min)
4795 (- b0 org-ds-keyword-length))
4797 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4798 inactivep (= (char-after b0) ?\[)
4799 deadlinep (string-match org-deadline-regexp tmp)
4800 scheduledp (string-match org-scheduled-regexp tmp)
4801 closedp (and org-agenda-include-inactive-timestamps
4802 (string-match org-closed-string tmp))
4803 clockp (and org-agenda-include-inactive-timestamps
4804 (or (string-match org-clock-string tmp)
4805 (string-match "]-+\\'" tmp)))
4806 donep (member todo-state org-done-keywords))
4807 (if (or scheduledp deadlinep closedp clockp
4808 (and donep org-agenda-skip-timestamp-if-done))
4810 (if (string-match ">" timestr)
4811 ;; substring should only run to end of time stamp
4812 (setq timestr (substring timestr 0 (match-end 0))))
4813 (setq marker (org-agenda-new-marker b0)
4814 category (org-get-category b0)
4815 org-category-pos (get-text-property b0 'org-category-position))
4817 (if (not (re-search-backward org-outline-regexp-bol nil t))
4818 (setq txt org-agenda-no-heading-message)
4819 (goto-char (match-beginning 0))
4820 (setq hdmarker (org-agenda-new-marker)
4821 tags (org-get-tags-at))
4822 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4823 (setq head (or (match-string 1) ""))
4824 (setq txt (org-agenda-format-item
4825 (if inactivep org-agenda-inactive-leader nil)
4826 head category tags timestr
4828 (setq priority (org-get-priority txt))
4829 (org-add-props txt props
4830 'org-marker marker 'org-hd-marker hdmarker)
4831 (org-add-props txt nil 'priority priority
4832 'org-category category 'date date
4833 'org-category-position org-category-pos
4834 'todo-state todo-state
4837 (if org-agenda-skip-additional-timestamps-same-entry
4838 (outline-next-heading)
4839 (goto-char end-of-match))))
4842 (defun org-agenda-get-sexps ()
4843 "Return the sexp information for agenda display."
4844 (require 'diary-lib)
4845 (let* ((props (list 'face 'org-agenda-calendar-sexp
4846 'mouse-face 'highlight
4848 (format "mouse-2 or RET jump to org file %s"
4849 (abbreviate-file-name buffer-file-name))))
4851 marker category org-category-pos ee txt tags entry
4852 result beg b sexp sexp-entry todo-state)
4853 (goto-char (point-min))
4854 (while (re-search-forward regexp nil t)
4857 (setq beg (match-beginning 0))
4858 (goto-char (1- (match-end 0)))
4861 (setq sexp (buffer-substring b (point)))
4862 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4863 (org-trim (match-string 1))
4865 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4867 (setq marker (org-agenda-new-marker beg)
4868 category (org-get-category beg)
4869 org-category-pos (get-text-property beg 'org-category-position)
4870 todo-state (org-get-todo-state))
4872 (dolist (r (if (stringp result)
4874 result)) ;; we expect a list here
4875 (if (string-match "\\S-" r)
4877 (setq txt "SEXP entry returned empty string"))
4879 (setq txt (org-agenda-format-item
4880 "" txt category tags 'time))
4881 (org-add-props txt props 'org-marker marker)
4882 (org-add-props txt nil
4883 'org-category category 'date date 'todo-state todo-state
4884 'org-category-position org-category-pos
4889 ;; Calendar sanity: define some functions that are independent of
4890 ;; `calendar-date-style'.
4891 ;; Normally I would like to use ISO format when calling the diary functions,
4892 ;; but to make sure we still have Emacs 22 compatibility we bind
4893 ;; also `european-calendar-style' and use european format
4894 (defun org-anniversary (year month day &optional mark)
4895 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
4897 (let ((calendar-date-style 'european) (european-calendar-style t))
4898 (diary-anniversary day month year mark))))
4899 (defun org-cyclic (N year month day &optional mark)
4900 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
4902 (let ((calendar-date-style 'european) (european-calendar-style t))
4903 (diary-cyclic N day month year mark))))
4904 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
4905 "Like `diary-block', but with fixed (ISO) order of arguments."
4907 (let ((calendar-date-style 'european) (european-calendar-style t))
4908 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
4909 (defun org-date (year month day &optional mark)
4910 "Like `diary-date', but with fixed (ISO) order of arguments."
4912 (let ((calendar-date-style 'european) (european-calendar-style t))
4913 (diary-date day month year mark))))
4914 (defalias 'org-float 'diary-float)
4916 ;; Define the` org-class' function
4917 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
4918 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4919 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
4920 SKIP-WEEKS is any number of ISO weeks in the block period for which the
4921 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
4922 `holidays', then any date that is known by the Emacs calendar to be a
4923 holiday will also be skipped."
4924 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
4925 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
4926 (d (calendar-absolute-from-gregorian date)))
4930 (= (calendar-day-of-week date) dayname)
4931 (or (not skip-weeks)
4934 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4935 (not (and (memq 'holidays skip-weeks)
4936 (calendar-check-holidays date)))
4939 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4940 "Like `org-class', but honor `calendar-date-style'.
4941 The order of the first 2 times 3 arguments depends on the variable
4942 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4943 So for American calendars, give this as MONTH DAY YEAR, for European as
4944 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4945 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4946 is any number of ISO weeks in the block period for which the item should
4949 This function is here only for backward compatibility and it is deprecated,
4950 please use `org-class' instead."
4951 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
4952 (date2 (org-order-calendar-date-args m2 d2 y2)))
4954 (nth 2 date1) (car date1) (nth 1 date1)
4955 (nth 2 date2) (car date2) (nth 1 date2)
4956 dayname skip-weeks)))
4957 (make-obsolete 'org-diary-class 'org-class "")
4959 (defalias 'org-get-closed 'org-agenda-get-progress)
4960 (defun org-agenda-get-progress ()
4961 "Return the logged TODO entries for agenda display."
4962 (let* ((props (list 'mouse-face 'highlight
4963 'org-not-done-regexp org-not-done-regexp
4964 'org-todo-regexp org-todo-regexp
4965 'org-complex-heading-regexp org-complex-heading-regexp
4967 (format "mouse-2 or RET jump to org file %s"
4968 (abbreviate-file-name buffer-file-name))))
4969 (items (if (consp org-agenda-show-log)
4971 (if (eq org-agenda-show-log 'clockcheck)
4973 org-agenda-log-mode-items)))
4977 (if (memq 'closed items) (concat "\\<" org-closed-string))
4978 (if (memq 'clock items) (concat "\\<" org-clock-string))
4979 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4980 (parts-re (if parts (mapconcat 'identity parts "\\|")
4981 (error "`org-agenda-log-mode-items' is empty")))
4983 "\\(" parts-re "\\)"
4988 (car org-time-stamp-formats)
4989 (apply 'encode-time ; DATE bound by calendar
4990 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4992 (org-agenda-search-headline-for-time nil)
4993 marker hdmarker priority category org-category-pos tags closedp
4994 statep clockp state ee txt extra timestr rest clocked)
4995 (goto-char (point-min))
4996 (while (re-search-forward regexp nil t)
4999 (setq marker (org-agenda-new-marker (match-beginning 0))
5000 closedp (equal (match-string 1) org-closed-string)
5001 statep (equal (string-to-char (match-string 1)) ?-)
5002 clockp (not (or closedp statep))
5003 state (and statep (match-string 2))
5004 category (org-get-category (match-beginning 0))
5005 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5006 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5007 (when (string-match "\\]" timestr)
5008 ;; substring should only run to end of time stamp
5009 (setq rest (substring timestr (match-end 0))
5010 timestr (substring timestr 0 (match-end 0)))
5011 (if (and (not closedp) (not statep)
5012 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5014 (progn (setq timestr (concat (substring timestr 0 -1)
5015 "-" (match-string 1 rest) "]"))
5016 (setq clocked (match-string 2 rest)))
5017 (setq clocked "-")))
5021 ((not org-agenda-log-mode-add-notes) nil)
5023 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5026 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5027 (match-string 1)))))
5028 (if (not (re-search-backward org-outline-regexp-bol nil t))
5029 (setq txt org-agenda-no-heading-message)
5030 (goto-char (match-beginning 0))
5031 (setq hdmarker (org-agenda-new-marker)
5032 tags (org-get-tags-at))
5033 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5034 (setq txt (match-string 1))
5036 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5037 (setq txt (concat (substring txt 0 (match-beginning 1))
5038 " - " extra " " (match-string 2 txt)))
5039 (setq txt (concat txt " - " extra))))
5040 (setq txt (org-agenda-format-item
5042 (closedp "Closed: ")
5043 (statep (concat "State: (" state ")"))
5044 (t (concat "Clocked: (" clocked ")")))
5045 txt category tags timestr)))
5046 (setq priority 100000)
5047 (org-add-props txt props
5048 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5049 'priority priority 'org-category category
5050 'org-category-position org-category-pos
5051 'type "closed" 'date date
5052 'undone-face 'org-warning 'done-face 'org-agenda-done)
5054 (goto-char (point-at-eol))))
5057 (defun org-agenda-show-clocking-issues ()
5058 "Add overlays, showing issues with clocking.
5059 See also the user option `org-agenda-clock-consistency-checks'."
5061 (let* ((pl org-agenda-clock-consistency-checks)
5062 (re (concat "^[ \t]*"
5065 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5066 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5069 (maxtime (org-hh:mm-string-to-minutes
5070 (or (plist-get pl :max-duration) "24:00")))
5071 (mintime (org-hh:mm-string-to-minutes
5072 (or (plist-get pl :min-duration) 0)))
5073 (maxgap (org-hh:mm-string-to-minutes
5074 ;; default 30:00 means never complain
5075 (or (plist-get pl :max-gap) "30:00")))
5076 (gapok (mapcar 'org-hh:mm-string-to-minutes
5077 (plist-get pl :gap-ok-around)))
5078 (def-face (or (plist-get pl :default-face)
5079 '((:background "DarkRed") (:foreground "white"))))
5080 issue face m te ts dt ov)
5081 (goto-char (point-min))
5082 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5083 (setq issue nil face def-face)
5085 (setq m (org-get-at-bol 'org-marker)
5087 (unless (and m (markerp m))
5088 (setq issue "No valid clock line") (throw 'next t))
5089 (org-with-point-at m
5091 (goto-char (point-at-bol))
5092 (unless (looking-at re)
5093 (error "No valid Clock line")
5095 (unless (match-end 3)
5096 (setq issue "No end time"
5097 face (or (plist-get pl :no-end-time-face) face))
5099 (setq ts (match-string 1)
5102 (apply 'encode-time (org-parse-time-string ts)))
5104 (apply 'encode-time (org-parse-time-string te)))
5107 ((> dt (* 60 maxtime))
5108 ;; a very long clocking chunk
5109 (setq issue (format "Clocking interval is very long: %s"
5110 (org-minutes-to-hh:mm-string
5111 (floor (/ (float dt) 60.))))
5112 face (or (plist-get pl :long-face) face)))
5113 ((< dt (* 60 mintime))
5114 ;; a very short clocking chunk
5115 (setq issue (format "Clocking interval is very short: %s"
5116 (org-minutes-to-hh:mm-string
5117 (floor (/ (float dt) 60.))))
5118 face (or (plist-get pl :short-face) face)))
5119 ((and (> tlend 0) (< ts tlend))
5120 ;; Two clock entries are overlapping
5121 (setq issue (format "Clocking overlap: %d minutes"
5122 (/ (- tlend ts) 60))
5123 face (or (plist-get pl :overlap-face) face)))
5124 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5125 ;; There is a gap, lets see if we need to report it
5126 (unless (org-agenda-check-clock-gap tlend ts gapok)
5127 (setq issue (format "Clocking gap: %d minutes"
5128 (/ (- ts tlend) 60))
5129 face (or (plist-get pl :gap-face) face))))
5131 (setq tlend (or te tlend) tlstart (or ts tlstart))
5133 ;; OK, there was some issue, add an overlay to show the issue
5134 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5135 (overlay-put ov 'before-string
5138 (format "%-43s" (concat " " issue))
5142 (overlay-put ov 'evaporate t)))))
5144 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5145 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5148 ;; there are no OK times for gaps...
5150 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5151 ;; This is more than 24 hours, so it is OK.
5152 ;; because we have at least one OK time, that must be in the
5153 ;; 24 hour interval.
5155 ;; We have a shorter gap.
5156 ;; Now we have to get the minute of the day when these times are
5157 (let* ((t1dec (decode-time (seconds-to-time t1)))
5158 (t2dec (decode-time (seconds-to-time t2)))
5159 ;; compute the minute on the day
5160 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5161 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5163 ;; if min2 is smaller than min1, this means it is on the next day.
5164 ;; Wrap it to after midnight.
5165 (setq min2 (+ min2 1440)))
5166 ;; Now check if any of the OK times is in the gap
5168 ;; Wrap the time to after midnight if necessary
5169 (if (< x min1) (setq x (+ x 1440)))
5170 ;; Check if in interval
5171 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5173 ;; Nope, this gap is not OK
5176 (defun org-agenda-get-deadlines ()
5177 "Return the deadline information for agenda display."
5178 (let* ((props (list 'mouse-face 'highlight
5179 'org-not-done-regexp org-not-done-regexp
5180 'org-todo-regexp org-todo-regexp
5181 'org-complex-heading-regexp org-complex-heading-regexp
5183 (format "mouse-2 or RET jump to org file %s"
5184 (abbreviate-file-name buffer-file-name))))
5185 (regexp org-deadline-time-regexp)
5186 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5187 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5188 d2 diff dfrac wdays pos pos1 category org-category-pos
5189 tags suppress-prewarning ee txt head face s todo-state
5190 show-all upcomingp donep timestr)
5191 (goto-char (point-min))
5192 (while (re-search-forward regexp nil t)
5193 (setq suppress-prewarning nil)
5196 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5198 (string-match org-scheduled-time-regexp
5199 (buffer-substring (point-at-bol)
5201 (setq suppress-prewarning
5202 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5203 org-agenda-skip-deadline-prewarning-if-scheduled
5205 (setq s (match-string 1)
5207 pos (1- (match-beginning 1))
5208 todo-state (save-match-data (org-get-todo-state))
5209 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5211 org-agenda-repeating-timestamp-show-all))
5212 d2 (org-time-string-to-absolute
5213 (match-string 1) d1 'past show-all
5214 (current-buffer) pos)
5216 wdays (if suppress-prewarning
5217 (let ((org-deadline-warning-days suppress-prewarning))
5220 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5221 upcomingp (and todayp (> diff 0)))
5222 ;; When to show a deadline in the calendar:
5223 ;; If the expiration is within wdays warning time.
5224 ;; Past-due deadlines are only shown on the current date
5225 (if (and (or (and (<= diff wdays)
5226 (and todayp (not org-agenda-only-exact-dates)))
5229 ;; (setq todo-state (org-get-todo-state))
5230 (setq donep (member todo-state org-done-keywords))
5232 (or org-agenda-skip-deadline-if-done
5235 (setq category (org-get-category)
5236 org-category-pos (get-text-property (point) 'org-category-position))
5237 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5238 (setq txt org-agenda-no-heading-message)
5239 (goto-char (match-end 0))
5240 (setq pos1 (match-beginning 0))
5241 (setq tags (org-get-tags-at pos1))
5242 (setq head (buffer-substring-no-properties
5244 (progn (skip-chars-forward "^\r\n")
5246 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5248 (concat (substring s (match-beginning 1)) " "))
5249 (setq timestr 'time))
5250 (setq txt (org-agenda-format-item
5252 (car org-agenda-deadline-leaders)
5254 (nth 1 org-agenda-deadline-leaders))
5256 (nth 1 org-agenda-deadline-leaders)
5258 (format (nth 1 org-agenda-deadline-leaders)
5261 (if (not (= diff 0)) nil timestr)))))
5263 (setq face (org-agenda-deadline-face dfrac))
5264 (org-add-props txt props
5265 'org-marker (org-agenda-new-marker pos)
5266 'org-hd-marker (org-agenda-new-marker pos1)
5267 'priority (+ (- diff)
5268 (org-get-priority txt))
5269 'org-category category
5270 'org-category-position org-category-pos
5271 'todo-state todo-state
5272 'type (if upcomingp "upcoming-deadline" "deadline")
5273 'date (if upcomingp date d2)
5274 'face (if donep 'org-agenda-done face)
5275 'undone-face face 'done-face 'org-agenda-done)
5279 (defun org-agenda-deadline-face (fraction)
5280 "Return the face to displaying a deadline item.
5281 FRACTION is what fraction of the head-warning time has passed."
5282 (let ((faces org-agenda-deadline-faces) f)
5284 (while (setq f (pop faces))
5285 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5287 (defun org-agenda-get-scheduled (&optional deadline-results)
5288 "Return the scheduled information for agenda display."
5289 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5290 'org-todo-regexp org-todo-regexp
5291 'org-complex-heading-regexp org-complex-heading-regexp
5292 'done-face 'org-agenda-done
5293 'mouse-face 'highlight
5295 (format "mouse-2 or RET jump to org file %s"
5296 (abbreviate-file-name buffer-file-name))))
5297 (regexp org-scheduled-time-regexp)
5298 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5299 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5301 (deadline-position-alist
5302 (mapcar (lambda (a) (and (setq mm (get-text-property
5303 0 'org-hd-marker a))
5304 (cons (marker-position mm) a)))
5306 d2 diff pos pos1 category org-category-pos tags donep
5307 ee txt head pastschedp todo-state face timestr s habitp show-all)
5308 (goto-char (point-min))
5309 (while (re-search-forward regexp nil t)
5312 (setq s (match-string 1)
5314 pos (1- (match-beginning 1))
5315 todo-state (save-match-data (org-get-todo-state))
5316 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5318 org-agenda-repeating-timestamp-show-all))
5319 d2 (org-time-string-to-absolute
5320 (match-string 1) d1 'past show-all
5321 (current-buffer) pos)
5323 (setq pastschedp (and todayp (< diff 0)))
5324 ;; When to show a scheduled item in the calendar:
5325 ;; If it is on or past the date.
5326 (when (or (and (< diff 0)
5327 (< (abs diff) org-scheduled-past-days)
5328 (and todayp (not org-agenda-only-exact-dates)))
5331 (setq donep (member todo-state org-done-keywords))
5333 (or org-agenda-skip-scheduled-if-done
5335 (and (functionp 'org-is-habit-p)
5338 (setq habitp (and (functionp 'org-is-habit-p)
5340 (setq category (org-get-category)
5341 org-category-pos (get-text-property (point) 'org-category-position))
5342 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5343 (setq txt org-agenda-no-heading-message)
5344 (goto-char (match-end 0))
5345 (setq pos1 (match-beginning 0))
5347 (if (or (not org-habit-show-habits)
5349 org-habit-show-habits-only-for-today))
5352 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5353 (and org-agenda-skip-scheduled-if-deadline-is-shown
5355 (setq mm (assoc pos1 deadline-position-alist)))
5357 (setq tags (org-get-tags-at))
5358 (setq head (buffer-substring-no-properties
5360 (progn (skip-chars-forward "^\r\n") (point))))
5361 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5363 (concat (substring s (match-beginning 1)) " "))
5364 (setq timestr 'time))
5365 (setq txt (org-agenda-format-item
5367 (car org-agenda-scheduled-leaders)
5368 (format (nth 1 org-agenda-scheduled-leaders)
5371 (if (not (= diff 0)) nil timestr)
5376 ((and (not habitp) pastschedp)
5377 'org-scheduled-previously)
5378 (todayp 'org-scheduled-today)
5380 habitp (and habitp (org-habit-parse-todo)))
5381 (org-add-props txt props
5383 'face (if donep 'org-agenda-done face)
5384 'org-marker (org-agenda-new-marker pos)
5385 'org-hd-marker (org-agenda-new-marker pos1)
5386 'type (if pastschedp "past-scheduled" "scheduled")
5387 'date (if pastschedp d2 date)
5388 'priority (if habitp
5389 (org-habit-get-priority habitp)
5390 (+ 94 (- 5 diff) (org-get-priority txt)))
5391 'org-category category
5392 'org-category-position org-category-pos
5394 'todo-state todo-state)
5398 (defun org-agenda-get-blocks ()
5399 "Return the date-range information for agenda display."
5400 (let* ((props (list 'face nil
5401 'org-not-done-regexp org-not-done-regexp
5402 'org-todo-regexp org-todo-regexp
5403 'org-complex-heading-regexp org-complex-heading-regexp
5404 'mouse-face 'highlight
5406 (format "mouse-2 or RET jump to org file %s"
5407 (abbreviate-file-name buffer-file-name))))
5408 (regexp org-tr-regexp)
5409 (d0 (calendar-absolute-from-gregorian date))
5410 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5411 todo-state tags pos head donep)
5412 (goto-char (point-min))
5413 (while (re-search-forward regexp nil t)
5417 (let ((start-time (match-string 1))
5418 (end-time (match-string 2)))
5419 (setq s1 (match-string 1)
5421 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5422 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5423 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5424 ;; Only allow days between the limits, because the normal
5425 ;; date stamps will catch the limits.
5427 (setq todo-state (org-get-todo-state))
5428 (setq donep (member todo-state org-done-keywords))
5429 (if (and donep org-agenda-skip-timestamp-if-done)
5431 (setq marker (org-agenda-new-marker (point)))
5432 (setq category (org-get-category)
5433 org-category-pos (get-text-property (point) 'org-category-position))
5434 (if (not (re-search-backward org-outline-regexp-bol nil t))
5435 (setq txt org-agenda-no-heading-message)
5436 (goto-char (match-beginning 0))
5437 (setq hdmarker (org-agenda-new-marker (point)))
5438 (setq tags (org-get-tags-at))
5439 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5440 (setq head (match-string 1))
5442 (if org-agenda-remove-timeranges-from-blocks
5444 "<" (regexp-quote s1) ".*?>"
5446 "<" (regexp-quote s2) ".*?>")
5448 (setq txt (org-agenda-format-item
5450 (nth (if (= d1 d2) 0 1)
5451 org-agenda-timerange-leaders)
5452 (1+ (- d0 d1)) (1+ (- d2 d1)))
5454 (cond ((and (= d1 d0) (= d2 d0))
5455 (concat "<" start-time ">--<" end-time ">"))
5457 (concat "<" start-time ">"))
5459 (concat "<" end-time ">"))
5462 (org-add-props txt props
5463 'org-marker marker 'org-hd-marker hdmarker
5464 'type "block" 'date date
5465 'todo-state todo-state
5466 'priority (org-get-priority txt) 'org-category category
5467 'org-category-position org-category-pos)
5470 ;; Sort the entries by expiration date.
5473 ;;; Agenda presentation and sorting
5475 (defvar org-prefix-has-time nil
5476 "A flag, set by `org-compile-prefix-format'.
5477 The flag is set if the currently compiled format contains a `%t'.")
5478 (defvar org-prefix-has-tag nil
5479 "A flag, set by `org-compile-prefix-format'.
5480 The flag is set if the currently compiled format contains a `%T'.")
5481 (defvar org-prefix-has-effort nil
5482 "A flag, set by `org-compile-prefix-format'.
5483 The flag is set if the currently compiled format contains a `%e'.")
5484 (defvar org-prefix-category-length nil
5485 "Used by `org-compile-prefix-format' to remember the category field width.")
5486 (defvar org-prefix-category-max-length nil
5487 "Used by `org-compile-prefix-format' to remember the category field width.")
5489 (defun org-agenda-get-category-icon (category)
5490 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5491 (dolist (entry org-agenda-category-icon-alist)
5492 (when (org-string-match-p (car entry) category)
5493 (if (listp (cadr entry))
5494 (return (cadr entry))
5495 (return (apply 'create-image (cdr entry)))))))
5497 (defun org-agenda-format-item (extra txt &optional category tags dotime
5499 "Format TXT to be inserted into the agenda buffer.
5500 In particular, it adds the prefix and corresponding text properties. EXTRA
5501 must be a string and replaces the `%s' specifier in the prefix format.
5502 CATEGORY (string, symbol or nil) may be used to overrule the default
5503 category taken from local variable or file name. It will replace the `%c'
5504 specifier in the format. DOTIME, when non-nil, indicates that a
5505 time-of-day should be extracted from TXT for sorting of this entry, and for
5506 the `%t' specifier in the format. When DOTIME is a string, this string is
5507 searched for a time before TXT is. TAGS can be the tags of the headline.
5508 Any match of REMOVE-RE will be removed from TXT."
5510 ;; Diary entries sometimes have extra whitespace at the beginning
5511 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5513 ;; Fix the tags part in txt
5514 (setq txt (org-agenda-fix-displayed-tags
5516 org-agenda-show-inherited-tags
5517 org-agenda-hide-tags-regexp))
5518 (let* ((category (or category
5519 (if (stringp org-category)
5521 (and org-category (symbol-name org-category)))
5522 (if buffer-file-name
5523 (file-name-sans-extension
5524 (file-name-nondirectory buffer-file-name))
5526 (category-icon (org-agenda-get-category-icon category))
5527 (category-icon (if category-icon
5528 (propertize " " 'display category-icon)
5530 ;; time, tag, effort are needed for the eval of the prefix format
5531 (tag (if tags (nth (1- (length tags)) tags) ""))
5533 (ts (if dotime (concat
5534 (if (stringp dotime) dotime "")
5535 (and org-agenda-search-headline-for-time txt))))
5536 (time-of-day (and dotime (org-get-time-of-day ts)))
5537 stamp plain s0 s1 s2 rtn srp l
5538 duration thecategory)
5539 (and (eq major-mode 'org-mode) buffer-file-name
5540 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5541 (when (and dotime time-of-day)
5542 ;; Extract starting and ending time and move them to prefix
5543 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5544 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5545 (setq s0 (match-string 0 ts)
5546 srp (and stamp (match-end 3))
5547 s1 (match-string (if plain 1 2) ts)
5548 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5550 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5551 ;; them, we might want to remove them there to avoid duplication.
5552 ;; The user can turn this off with a variable.
5553 (if (and org-prefix-has-time
5554 org-agenda-remove-times-when-in-prefix (or stamp plain)
5555 (string-match (concat (regexp-quote s0) " *") txt)
5556 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5557 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5558 (= (match-beginning 0) 0)
5560 (setq txt (replace-match "" nil nil txt))))
5561 ;; Normalize the time(s) to 24 hour
5562 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5563 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5565 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5566 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5568 (org-minutes-to-hh:mm-string
5569 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5571 ;; Compute the duration
5573 (setq duration (- (org-hh:mm-string-to-minutes s2)
5574 (org-hh:mm-string-to-minutes s1)))))
5576 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5578 ;; Tags are in the string
5579 (if (or (eq org-agenda-remove-tags t)
5580 (and org-agenda-remove-tags
5581 org-prefix-has-tag))
5582 (setq txt (replace-match "" t t txt))
5583 (setq txt (replace-match
5584 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5585 (match-string 2 txt))
5587 (when (eq major-mode 'org-mode)
5591 (or (get-text-property 0 'org-hd-marker txt)
5592 (get-text-property 0 'org-marker txt)))
5595 (setq neffort (org-duration-string-to-minutes effort)
5596 effort (setq effort (concat "[" effort "]")))))
5597 ;; prevent erroring out with %e format when there is no effort
5598 (or effort (setq effort ""))
5601 (while (string-match remove-re txt)
5602 (setq txt (replace-match "" t t txt))))
5604 ;; Set org-heading property on `txt' to mark the start of the
5606 (add-text-properties 0 (length txt) '(org-heading t) txt)
5608 ;; Prepare the variables needed in the eval of the compiled format
5609 (setq time (cond (s2 (concat
5610 (org-agenda-time-of-day-to-ampm-maybe s1)
5611 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5612 (if org-agenda-timegrid-use-ampm " ")))
5614 (org-agenda-time-of-day-to-ampm-maybe s1)
5615 (if org-agenda-timegrid-use-ampm
5619 extra (or (and (not habitp) extra) "")
5620 category (if (symbolp category) (symbol-name category) category)
5621 thecategory (copy-sequence category))
5622 (if (string-match org-bracket-link-regexp category)
5624 (setq l (if (match-end 3)
5625 (- (match-end 3) (match-beginning 3))
5626 (- (match-end 1) (match-beginning 1))))
5627 (when (< l (or org-prefix-category-length 0))
5628 (setq category (copy-sequence category))
5629 (org-add-props category nil
5630 'extra-space (make-string
5631 (- org-prefix-category-length l 1) ?\ ))))
5632 (if (and org-prefix-category-max-length
5633 (>= (length category) org-prefix-category-max-length))
5634 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5635 ;; Evaluate the compiled format
5636 (setq rtn (concat (eval org-prefix-format-compiled) txt))
5638 ;; And finally add the text properties
5639 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5640 (org-add-props rtn nil
5641 'org-category (if thecategory (downcase thecategory) category)
5642 'tags (mapcar 'org-downcase-keep-props tags)
5643 'org-highest-priority org-highest-priority
5644 'org-lowest-priority org-lowest-priority
5645 'time-of-day time-of-day
5648 'effort-minutes neffort
5652 'format org-prefix-format-compiled
5655 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5656 "Remove tags string from TXT, and add a modified list of tags.
5657 The modified list may contain inherited tags, and tags matched by
5658 `org-agenda-hide-tags-regexp' will be removed."
5659 (when (or add-inherited hide-re)
5660 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5661 (setq txt (substring txt 0 (match-beginning 0))))
5664 (mapcar (lambda (tg)
5665 (if (or (and hide-re (string-match hide-re tg))
5666 (and (not add-inherited)
5667 (get-text-property 0 'inherited tg)))
5672 (let ((have-i (get-text-property 0 'inherited (car tags)))
5674 (setq txt (concat txt " :"
5677 (setq i (get-text-property 0 'inherited x))
5678 (if (and have-i (not i))
5684 (if have-i "::" ":"))))))
5687 (defun org-downcase-keep-props (s)
5688 (let ((props (text-properties-at 0 s)))
5689 (setq s (downcase s))
5690 (add-text-properties 0 (length s) props s)
5693 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5694 (defvar org-agenda-sorting-strategy-selected nil)
5696 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5698 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5699 ((and todayp (member 'today (car org-agenda-time-grid))))
5700 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5701 ((member 'weekly (car org-agenda-time-grid)))
5702 (t (throw 'exit list)))
5703 (let* ((have (delq nil (mapcar
5704 (lambda (x) (get-text-property 1 'time-of-day x))
5706 (string (nth 1 org-agenda-time-grid))
5707 (gridtimes (nth 2 org-agenda-time-grid))
5708 (req (car org-agenda-time-grid))
5709 (remove (member 'remove-match req))
5711 (if (and (member 'require-timed req) (not have))
5712 ;; don't show empty grid
5714 (while (setq time (pop gridtimes))
5715 (unless (and remove (member time have))
5716 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5717 (push (org-agenda-format-item
5719 (concat (substring time 0 -2) ":" (substring time -2)))
5722 2 (length (car new)) 'face 'org-time-grid (car new))))
5723 (when (and todayp org-agenda-show-current-time-in-grid)
5724 (push (org-agenda-format-item
5726 org-agenda-current-time-string
5728 (format-time-string "%H:%M "))
5731 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5733 (if (member 'time-up org-agenda-sorting-strategy-selected)
5735 (append list new)))))
5737 (defun org-compile-prefix-format (key)
5738 "Compile the prefix format into a Lisp form that can be evaluated.
5739 The resulting form is returned and stored in the variable
5740 `org-prefix-format-compiled'."
5741 (setq org-prefix-has-time nil org-prefix-has-tag nil
5742 org-prefix-category-length nil
5743 org-prefix-has-effort nil)
5745 ((stringp org-agenda-prefix-format)
5746 org-agenda-prefix-format)
5747 ((assq key org-agenda-prefix-format)
5748 (cdr (assq key org-agenda-prefix-format)))
5749 (t " %-12:c%?-12t% s")))
5751 varform vars var e c f opt)
5752 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5754 (setq var (or (cdr (assoc (match-string 4 s)
5755 '(("c" . category) ("t" . time) ("s" . extra)
5756 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5758 c (or (match-string 3 s) "")
5759 opt (match-beginning 1)
5760 start (1+ (match-beginning 0)))
5761 (if (equal var 'time) (setq org-prefix-has-time t))
5762 (if (equal var 'tag) (setq org-prefix-has-tag t))
5763 (if (equal var 'effort) (setq org-prefix-has-effort t))
5764 (setq f (concat "%" (match-string 2 s) "s"))
5765 (when (equal var 'category)
5766 (setq org-prefix-category-length
5767 (floor (abs (string-to-number (match-string 2 s)))))
5768 (setq org-prefix-category-max-length
5769 (let ((x (match-string 2 s)))
5771 (if (string-match "\\.[0-9]+" x)
5772 (string-to-number (substring (match-string 0 x) 1)))))))
5774 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5777 `(if (equal "" ,var)
5779 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5780 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5781 (setq s (replace-match "%s" t nil s))
5782 (push varform vars))
5783 (setq vars (nreverse vars))
5784 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5786 (defun org-set-sorting-strategy (key)
5787 (if (symbolp (car org-agenda-sorting-strategy))
5789 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5790 (setq org-agenda-sorting-strategy-selected
5791 (or (cdr (assq key org-agenda-sorting-strategy))
5792 (cdr (assq 'agenda org-agenda-sorting-strategy))
5793 '(time-up category-keep priority-down)))))
5795 (defun org-get-time-of-day (s &optional string mod24)
5796 "Check string S for a time of day.
5797 If found, return it as a military time number between 0 and 2400.
5798 If not found, return nil.
5799 The optional STRING argument forces conversion into a 5 character wide string
5803 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5804 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5805 (let* ((h (string-to-number (match-string 1 s)))
5806 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5807 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5808 (am-p (equal ampm "am"))
5809 (h1 (cond ((not ampm) h)
5810 ((= h 12) (if am-p 0 12))
5811 (t (+ h (if am-p 0 12)))))
5812 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5814 (t0 (+ (* 100 h2) m))
5815 (t1 (concat (if (>= h1 24) "+" " ")
5816 (if (and org-agenda-time-leading-zero
5817 (< t0 1000)) "0" "")
5818 (if (< t0 100) "0" "")
5819 (if (< t0 10) "0" "")
5820 (int-to-string t0))))
5821 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5823 (defvar org-agenda-before-sorting-filter-function nil
5824 "Function to be applied to agenda items prior to sorting.
5825 Prior to sorting also means just before they are inserted into the agenda.
5827 To aid sorting, you may revisit the original entries and add more text
5828 properties which will later be used by the sorting functions.
5830 The function should take a string argument, an agenda line.
5831 It has access to the text properties in that line, which contain among
5832 other things, the property `org-hd-marker' that points to the entry
5833 where the line comes from. Note that not all lines going into the agenda
5834 have this property, only most.
5836 The function should return the modified string. It is probably best
5837 to ONLY change text properties.
5839 You can also use this function as a filter, by returning nil for lines
5840 you don't want to have in the agenda at all. For this application, you
5841 could bind the variable in the options section of a custom command.")
5843 (defun org-finalize-agenda-entries (list &optional nosort)
5844 "Sort and concatenate the agenda items."
5845 (setq list (mapcar 'org-agenda-highlight-todo list))
5848 (when org-agenda-before-sorting-filter-function
5849 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5850 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5852 (defun org-agenda-highlight-todo (x)
5853 (let ((org-done-keywords org-done-keywords-for-agenda)
5854 (case-fold-search nil)
5858 (beginning-of-line 1)
5859 (setq re (org-get-at-bol 'org-todo-regexp))
5860 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
5861 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5862 (add-text-properties (match-beginning 0) (match-end 1)
5863 (list 'face (org-get-todo-face 1)))
5864 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5865 (delete-region (match-beginning 1) (1- (match-end 0)))
5866 (goto-char (match-beginning 1))
5867 (insert (format org-agenda-todo-keyword-format s)))))
5868 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
5869 (setq re (get-text-property 0 'org-todo-regexp x))
5871 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5873 (add-text-properties
5874 (or (match-end 1) (match-end 0)) (match-end 0)
5875 (list 'face (org-get-todo-face (match-string 2 x)))
5878 (setq x (concat (substring x 0 (match-end 1))
5879 (format org-agenda-todo-keyword-format
5881 (org-add-props " " (text-properties-at 0 x))
5882 (substring x (match-end 3)))))))
5885 (defsubst org-cmp-priority (a b)
5886 "Compare the priorities of string A and B."
5887 (let ((pa (or (get-text-property 1 'priority a) 0))
5888 (pb (or (get-text-property 1 'priority b) 0)))
5889 (cond ((> pa pb) +1)
5893 (defsubst org-cmp-effort (a b)
5894 "Compare the effort values of string A and B."
5895 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5896 (ea (or (get-text-property 1 'effort-minutes a) def))
5897 (eb (or (get-text-property 1 'effort-minutes b) def)))
5898 (cond ((> ea eb) +1)
5902 (defsubst org-cmp-category (a b)
5903 "Compare the string values of categories of strings A and B."
5904 (let ((ca (or (get-text-property 1 'org-category a) ""))
5905 (cb (or (get-text-property 1 'org-category b) "")))
5906 (cond ((string-lessp ca cb) -1)
5907 ((string-lessp cb ca) +1)
5910 (defsubst org-cmp-todo-state (a b)
5911 "Compare the todo states of strings A and B."
5912 (let* ((ma (or (get-text-property 1 'org-marker a)
5913 (get-text-property 1 'org-hd-marker a)))
5914 (mb (or (get-text-property 1 'org-marker b)
5915 (get-text-property 1 'org-hd-marker b)))
5916 (fa (and ma (marker-buffer ma)))
5917 (fb (and mb (marker-buffer mb)))
5919 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5920 (and fb (with-current-buffer fb org-todo-keywords-1))))
5921 (ta (or (get-text-property 1 'todo-state a) ""))
5922 (tb (or (get-text-property 1 'todo-state b) ""))
5923 (la (- (length (member ta todo-kwds))))
5924 (lb (- (length (member tb todo-kwds))))
5925 (donepa (member ta org-done-keywords-for-agenda))
5926 (donepb (member tb org-done-keywords-for-agenda)))
5927 (cond ((and donepa (not donepb)) -1)
5928 ((and (not donepa) donepb) +1)
5933 (defsubst org-cmp-alpha (a b)
5934 "Compare the headlines, alphabetically."
5935 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
5936 (plb (text-property-any 0 (length b) 'org-heading t b))
5937 (ta (and pla (substring a pla)))
5938 (tb (and plb (substring b plb))))
5940 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5941 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5942 (setq ta (substring ta (match-end 0))))
5943 (setq ta (downcase ta)))
5945 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5946 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5947 (setq tb (substring tb (match-end 0))))
5948 (setq tb (downcase tb)))
5951 ((string-lessp ta tb) -1)
5952 ((string-lessp tb ta) +1)
5955 (defsubst org-cmp-tag (a b)
5956 "Compare the string values of the first tags of A and B."
5957 (let ((ta (car (last (get-text-property 1 'tags a))))
5958 (tb (car (last (get-text-property 1 'tags b)))))
5961 ((string-lessp ta tb) -1)
5962 ((string-lessp tb ta) +1)
5965 (defsubst org-cmp-time (a b)
5966 "Compare the time-of-day values of strings A and B."
5967 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5968 (ta (or (get-text-property 1 'time-of-day a) def))
5969 (tb (or (get-text-property 1 'time-of-day b) def)))
5970 (cond ((< ta tb) -1)
5974 (defsubst org-cmp-habit-p (a b)
5975 "Compare the todo states of strings A and B."
5976 (let ((ha (get-text-property 1 'org-habit-p a))
5977 (hb (get-text-property 1 'org-habit-p b)))
5978 (cond ((and ha (not hb)) -1)
5979 ((and (not ha) hb) +1)
5982 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5984 (defun org-entries-lessp (a b)
5985 "Predicate for sorting agenda entries."
5986 ;; The following variables will be used when the form is evaluated.
5987 ;; So even though the compiler complains, keep them.
5988 (let* ((ss org-agenda-sorting-strategy-selected)
5989 (time-up (and (org-em 'time-up 'time-down ss)
5990 (org-cmp-time a b)))
5991 (time-down (if time-up (- time-up) nil))
5992 (priority-up (and (org-em 'priority-up 'priority-down ss)
5993 (org-cmp-priority a b)))
5994 (priority-down (if priority-up (- priority-up) nil))
5995 (effort-up (and (org-em 'effort-up 'effort-down ss)
5996 (org-cmp-effort a b)))
5997 (effort-down (if effort-up (- effort-up) nil))
5998 (category-up (and (or (org-em 'category-up 'category-down ss)
5999 (memq 'category-keep ss))
6000 (org-cmp-category a b)))
6001 (category-down (if category-up (- category-up) nil))
6002 (category-keep (if category-up +1 nil))
6003 (tag-up (and (org-em 'tag-up 'tag-down ss)
6005 (tag-down (if tag-up (- tag-up) nil))
6006 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6007 (org-cmp-todo-state a b)))
6008 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6009 (habit-up (and (org-em 'habit-up 'habit-down ss)
6010 (org-cmp-habit-p a b)))
6011 (habit-down (if habit-up (- habit-up) nil))
6012 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6013 (org-cmp-alpha a b)))
6014 (alpha-down (if alpha-up (- alpha-up) nil))
6015 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6016 user-defined-up user-defined-down)
6017 (if (and need-user-cmp org-agenda-cmp-user-defined
6018 (functionp org-agenda-cmp-user-defined))
6019 (setq user-defined-up
6020 (funcall org-agenda-cmp-user-defined a b)
6021 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6023 (eval (cons 'or org-agenda-sorting-strategy-selected))
6024 '((-1 . t) (1 . nil) (nil . nil))))))
6026 ;;; Agenda restriction lock
6028 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6029 "Overlay to mark the headline to which agenda commands are restricted.")
6030 (overlay-put org-agenda-restriction-lock-overlay
6031 'face 'org-agenda-restriction-lock)
6032 (overlay-put org-agenda-restriction-lock-overlay
6033 'help-echo "Agendas are currently limited to this subtree.")
6034 (org-detach-overlay org-agenda-restriction-lock-overlay)
6036 (defun org-agenda-set-restriction-lock (&optional type)
6037 "Set restriction lock for agenda, to current subtree or file.
6038 Restriction will be the file if TYPE is `file', or if type is the
6039 universal prefix '(4), or if the cursor is before the first headline
6040 in the file. Otherwise, restriction will be to the current subtree."
6042 (and (equal type '(4)) (setq type 'file))
6045 ((org-at-heading-p) 'subtree)
6046 ((condition-case nil (org-back-to-heading t) (error nil))
6049 (if (eq type 'subtree)
6051 (setq org-agenda-restrict t)
6052 (setq org-agenda-overriding-restriction 'subtree)
6053 (put 'org-agenda-files 'org-restrict
6054 (list (buffer-file-name (buffer-base-buffer))))
6055 (org-back-to-heading t)
6056 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6057 (move-marker org-agenda-restrict-begin (point))
6058 (move-marker org-agenda-restrict-end
6059 (save-excursion (org-end-of-subtree t)))
6060 (message "Locking agenda restriction to subtree"))
6061 (put 'org-agenda-files 'org-restrict
6062 (list (buffer-file-name (buffer-base-buffer))))
6063 (setq org-agenda-restrict nil)
6064 (setq org-agenda-overriding-restriction 'file)
6065 (move-marker org-agenda-restrict-begin nil)
6066 (move-marker org-agenda-restrict-end nil)
6067 (message "Locking agenda restriction to file"))
6068 (setq current-prefix-arg nil)
6069 (org-agenda-maybe-redo))
6071 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6072 "Remove the agenda restriction lock."
6074 (org-detach-overlay org-agenda-restriction-lock-overlay)
6075 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6076 (setq org-agenda-overriding-restriction nil)
6077 (setq org-agenda-restrict nil)
6078 (put 'org-agenda-files 'org-restrict nil)
6079 (move-marker org-agenda-restrict-begin nil)
6080 (move-marker org-agenda-restrict-end nil)
6081 (setq current-prefix-arg nil)
6082 (message "Agenda restriction lock removed")
6083 (or noupdate (org-agenda-maybe-redo)))
6085 (defun org-agenda-maybe-redo ()
6086 "If there is any window showing the agenda view, update it."
6087 (let ((w (get-buffer-window org-agenda-buffer-name t))
6088 (w0 (selected-window)))
6093 (if org-agenda-overriding-restriction
6094 (message "Agenda view shifted to new %s restriction"
6095 org-agenda-overriding-restriction)
6096 (message "Agenda restriction lock removed")))))
6100 (defun org-agenda-check-type (error &rest types)
6101 "Check if agenda buffer is of allowed type.
6102 If ERROR is non-nil, throw an error, otherwise just return nil."
6103 (if (memq org-agenda-type types)
6106 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6109 (defun org-agenda-quit ()
6110 "Exit agenda by removing the window or the buffer."
6112 (if org-agenda-columns-active
6114 (let ((buf (current-buffer)))
6115 (if (eq org-agenda-window-setup 'other-frame)
6118 (org-agenda-reset-markers)
6119 (org-columns-remove-overlays)
6120 (setq org-agenda-archives-mode nil)
6122 (and (not (eq org-agenda-window-setup 'current-window))
6123 (not (one-window-p))
6126 (org-agenda-reset-markers)
6127 (org-columns-remove-overlays)
6128 (setq org-agenda-archives-mode nil)))
6129 ;; Maybe restore the pre-agenda window configuration.
6130 (and org-agenda-restore-windows-after-quit
6131 (not (eq org-agenda-window-setup 'other-frame))
6132 org-pre-agenda-window-conf
6133 (set-window-configuration org-pre-agenda-window-conf))))
6135 (defun org-agenda-exit ()
6136 "Exit agenda by removing the window or the buffer.
6137 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6138 Org-mode buffers visited directly by the user will not be touched."
6140 (org-release-buffers org-agenda-new-buffers)
6141 (setq org-agenda-new-buffers nil)
6144 (defun org-agenda-execute (arg)
6145 "Execute another agenda command, keeping same window.
6146 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6149 (let ((org-agenda-window-setup 'current-window))
6152 (defun org-agenda-redo ()
6154 When this is the global TODO list, a prefix argument will be interpreted."
6156 (let* ((org-agenda-keep-modes t)
6157 (tag-filter org-agenda-tag-filter)
6158 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6159 (cat-filter org-agenda-category-filter)
6160 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6161 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6162 (cols org-agenda-columns-active)
6163 (line (org-current-line))
6164 (window-line (- line (org-current-line (window-start))))
6165 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6166 (put 'org-agenda-tag-filter :preset-filter nil)
6167 (put 'org-agenda-category-filter :preset-filter nil)
6168 (and cols (org-columns-quit))
6169 (message "Rebuilding agenda buffer...")
6170 (org-let lprops '(eval org-agenda-redo-command))
6171 (setq org-agenda-undo-list nil
6172 org-agenda-pending-undo-list nil)
6173 (message "Rebuilding agenda buffer...done")
6174 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6175 (put 'org-agenda-category-filter :preset-filter cat-preset)
6176 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6177 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6178 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6179 (org-goto-line line)
6180 (recenter window-line)))
6182 (defvar org-global-tags-completion-table nil)
6183 (defvar org-agenda-filter-form nil)
6185 (defun org-agenda-filter-by-category (strip)
6186 "Keep only those lines in the agenda buffer that have a specific category.
6187 The category is that of the current line."
6189 (if org-agenda-filtered-by-category
6190 (org-agenda-filter-show-all-cat)
6191 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6192 (if cat (org-agenda-filter-apply
6193 (list (concat (if strip "-" "+") cat)) 'category)
6194 (error "No category at point")))))
6196 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6197 "Keep only those lines in the agenda buffer that have a specific tag.
6198 The tag is selected with its fast selection letter, as configured.
6199 With prefix argument STRIP, remove all lines that do have the tag.
6200 A lisp caller can specify CHAR. NARROW means that the new tag should be
6201 used to narrow the search - the interactive user can also press `-' or `+'
6202 to switch to narrowing."
6204 (let* ((alist org-tag-alist-for-agenda)
6205 (tag-chars (mapconcat
6206 (lambda (x) (if (and (not (symbolp (car x)))
6208 (char-to-string (cdr x))
6211 (efforts (org-split-string
6212 (or (cdr (assoc (concat org-effort-property "_ALL")
6213 org-global-properties))
6214 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6216 (effort-op org-agenda-filter-effort-default-operator)
6218 (inhibit-read-only t)
6219 (current org-agenda-tag-filter)
6220 maybe-refresh a n tag)
6223 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6224 (if narrow "Narrow" "Filter") tag-chars
6225 (if org-agenda-auto-exclude-function "[RET], " ""))
6226 (setq char (read-char-exclusive)))
6227 (when (member char '(?+ ?-))
6229 (cond ((equal char ?-) (setq strip t narrow t))
6230 ((equal char ?+) (setq strip nil narrow t)))
6232 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6233 (setq char (read-char-exclusive)))
6234 (when (member char '(?< ?> ?= ??))
6235 ;; An effort operator
6236 (setq effort-op (char-to-string char))
6237 (setq alist nil) ; to make sure it will be interpreted as effort.
6238 (unless (equal char ??)
6239 (loop for i from 0 to 9 do
6243 (if (= i 9) "0" (int-to-string (1+ i)))
6244 "]" (nth i efforts))))
6245 (message "Effort%s: %s " effort-op effort-prompt)
6246 (setq char (read-char-exclusive))
6247 (when (or (< char ?0) (> char ?9))
6248 (error "Need 1-9,0 to select effort" ))))
6249 (when (equal char ?\t)
6250 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6251 (org-set-local 'org-global-tags-completion-table
6252 (org-global-tags-completion-table)))
6253 (let ((completion-ignore-case t))
6254 (setq tag (org-icompleting-read
6255 "Tag: " org-global-tags-completion-table))))
6258 (org-agenda-filter-show-all-tag)
6259 (when org-agenda-auto-exclude-function
6260 (setq org-agenda-tag-filter '())
6261 (dolist (tag (org-agenda-get-represented-tags))
6262 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6264 (push modifier org-agenda-tag-filter))))
6265 (if (not (null org-agenda-tag-filter))
6266 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6267 (setq maybe-refresh t))
6269 (org-agenda-filter-show-all-tag)
6270 (when (get 'org-agenda-tag-filter :preset-filter)
6271 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6272 (setq maybe-refresh t))
6274 (setq org-agenda-tag-filter
6275 (mapcar (lambda(tag) (concat "+" tag))
6276 (org-get-at-bol 'tags)))
6277 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6278 (setq maybe-refresh t))
6279 ((or (equal char ?\ )
6280 (setq a (rassoc char alist))
6281 (and (>= char ?0) (<= char ?9)
6282 (setq n (if (= char ?0) 9 (- char ?0 1))
6283 tag (concat effort-op (nth n efforts))
6288 (and tag (setq a (cons tag nil))))
6289 (org-agenda-filter-show-all-tag)
6291 (setq org-agenda-tag-filter
6292 (cons (concat (if strip "-" "+") tag)
6293 (if narrow current nil)))
6294 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6295 (setq maybe-refresh t))
6296 (t (error "Invalid tag selection character %c" char)))
6297 (when (and maybe-refresh
6298 (eq org-agenda-clockreport-mode 'with-filter))
6299 (org-agenda-redo))))
6301 (defun org-agenda-get-represented-tags ()
6302 "Get a list of all tags currently represented in the agenda."
6305 (goto-char (point-min))
6306 (while (setq p (next-single-property-change (point) 'tags))
6308 (mapc (lambda (x) (add-to-list 'tags x))
6309 (get-text-property (point) 'tags))))
6312 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6313 "Refine the current filter. See `org-agenda-filter-by-tag'."
6315 (org-agenda-filter-by-tag strip char 'refine))
6317 (defun org-agenda-filter-make-matcher ()
6318 "Create the form that tests a line for agenda filter."
6320 ;; first compute the tag-filter matcher
6321 (dolist (x (delete-dups
6322 (append (get 'org-agenda-tag-filter
6323 :preset-filter) org-agenda-tag-filter)))
6324 (if (member x '("-" "+"))
6325 (setq f1 (if (equal x "-") 'tags '(not tags)))
6326 (if (string-match "[<=>?]" x)
6327 (setq f1 (org-agenda-filter-effort-form x))
6328 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6329 (if (equal (string-to-char x) ?-)
6330 (setq f1 (list 'not f1))))
6332 ;; then compute the category-filter matcher
6333 (dolist (x (delete-dups
6334 (append (get 'org-agenda-category-filter
6335 :preset-filter) org-agenda-category-filter)))
6336 (setq f1 (list 'equal (substring x 1) 'cat))
6338 (cons 'and (nreverse f))))
6340 (defun org-agenda-filter-effort-form (e)
6341 "Return the form to compare the effort of the current line with what E says.
6342 E looks like \"+<2:25\"."
6344 (setq e (substring e 1))
6345 (setq op (string-to-char e) e (substring e 1))
6346 (setq op (cond ((equal op ?<) '<=)
6350 (list 'org-agenda-compare-effort (list 'quote op)
6351 (org-duration-string-to-minutes e))))
6353 (defun org-agenda-compare-effort (op value)
6354 "Compare the effort of the current line with VALUE, using OP.
6355 If the line does not have an effort defined, return nil."
6356 (let ((eff (org-get-at-bol 'effort-minutes)))
6359 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6362 (defvar org-agenda-filtered-by-category nil)
6363 (defun org-agenda-filter-apply (filter type)
6364 "Set FILTER as the new agenda filter and apply it."
6367 (setq org-agenda-tag-filter filter)
6368 (setq org-agenda-category-filter filter
6369 org-agenda-filtered-by-category t))
6370 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6371 (org-agenda-set-mode-name)
6373 (goto-char (point-min))
6375 (if (org-get-at-bol 'org-marker)
6377 (setq tags (org-get-at-bol 'tags) ; used in eval
6378 cat (get-text-property (point) 'org-category))
6379 (if (not (eval org-agenda-filter-form))
6380 (org-agenda-filter-hide-line type))
6381 (beginning-of-line 2))
6382 (beginning-of-line 2))))
6383 (if (get-char-property (point) 'invisible)
6384 (org-agenda-previous-line))))
6386 (defun org-agenda-filter-hide-line (type)
6388 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6390 (overlay-put ov 'invisible t)
6391 (overlay-put ov 'type type)
6393 (push ov org-agenda-tag-filter-overlays)
6394 (push ov org-agenda-cat-filter-overlays))))
6396 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6397 (setq pos (or pos (point)))
6399 (dolist (ov (overlays-at pos))
6400 (when (and (overlay-get ov 'invisible)
6401 (eq (overlay-get ov 'type) 'tag))
6403 (if (< (overlay-start ov) (point-at-eol))
6404 (move-overlay ov (point-at-eol)
6405 (overlay-end ov)))))))
6407 (defun org-agenda-filter-show-all-tag nil
6408 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6409 (setq org-agenda-tag-filter-overlays nil
6410 org-agenda-tag-filter nil
6411 org-agenda-filter-form nil)
6412 (org-agenda-set-mode-name))
6414 (defun org-agenda-filter-show-all-cat nil
6415 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6416 (setq org-agenda-cat-filter-overlays nil
6417 org-agenda-filtered-by-category nil
6418 org-agenda-category-filter nil
6419 org-agenda-filter-form nil)
6420 (org-agenda-set-mode-name))
6422 (defun org-agenda-manipulate-query-add ()
6423 "Manipulate the query by adding a search term with positive selection.
6424 Positive selection means the term must be matched for selection of an entry."
6426 (org-agenda-manipulate-query ?\[))
6427 (defun org-agenda-manipulate-query-subtract ()
6428 "Manipulate the query by adding a search term with negative selection.
6429 Negative selection means term must not be matched for selection of an entry."
6431 (org-agenda-manipulate-query ?\]))
6432 (defun org-agenda-manipulate-query-add-re ()
6433 "Manipulate the query by adding a search regexp with positive selection.
6434 Positive selection means the regexp must match for selection of an entry."
6436 (org-agenda-manipulate-query ?\{))
6437 (defun org-agenda-manipulate-query-subtract-re ()
6438 "Manipulate the query by adding a search regexp with negative selection.
6439 Negative selection means regexp must not match for selection of an entry."
6441 (org-agenda-manipulate-query ?\}))
6442 (defun org-agenda-manipulate-query (char)
6444 ((memq org-agenda-type '(timeline agenda))
6445 (let ((org-agenda-include-inactive-timestamps t))
6447 (message "Display now includes inactive timestamps as well"))
6448 ((eq org-agenda-type 'search)
6450 'org-agenda-query-string
6451 (if org-agenda-last-search-view-search-was-boolean
6452 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6453 (?\{ . " +{}") (?\} . " -{}"))))
6455 (setq org-agenda-redo-command
6456 (list 'org-search-view
6458 org-agenda-query-string
6459 (+ (length org-agenda-query-string)
6460 (if (member char '(?\{ ?\})) 0 1))))
6461 (set-register org-agenda-query-register org-agenda-query-string)
6463 (t (error "Cannot manipulate query for %s-type agenda buffers"
6466 (defun org-add-to-string (var string)
6467 (set var (concat (symbol-value var) string)))
6469 (defun org-agenda-goto-date (date)
6470 "Jump to DATE in agenda."
6471 (interactive (list (let ((org-read-date-prefer-future
6472 (eval org-agenda-jump-prefer-future)))
6474 (org-agenda-list nil date))
6476 (defun org-agenda-goto-today ()
6479 (org-agenda-check-type t 'timeline 'agenda)
6480 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6482 (tdpos (goto-char tdpos))
6483 ((eq org-agenda-type 'agenda)
6484 (let* ((sd (org-agenda-compute-starting-span
6485 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6486 (org-agenda-overriding-arguments org-agenda-last-arguments))
6487 (setf (nth 1 org-agenda-overriding-arguments) sd)
6489 (org-agenda-find-same-or-today-or-agenda)))
6490 (t (error "Cannot find today")))))
6492 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6494 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6495 (text-property-any (point-min) (point-max) 'org-today t)
6496 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6499 (defun org-agenda-later (arg)
6500 "Go forward in time by thee current span.
6501 With prefix ARG, go forward that many times the current span."
6503 (org-agenda-check-type t 'agenda)
6504 (let* ((span org-agenda-current-span)
6505 (sd org-starting-day)
6506 (greg (calendar-gregorian-from-absolute sd))
6507 (cnt (org-get-at-bol 'org-day-cnt))
6511 (setq sd (+ arg sd)))
6513 (setq sd (+ (* 7 arg) sd)))
6515 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6516 sd (calendar-absolute-from-gregorian greg2))
6517 (setcar greg2 (1+ (car greg2))))
6519 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6520 sd (calendar-absolute-from-gregorian greg2))
6521 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6523 (setq sd (+ (* span arg) sd))))
6524 (let ((org-agenda-overriding-arguments
6525 (list (car org-agenda-last-arguments) sd span t)))
6527 (org-agenda-find-same-or-today-or-agenda cnt))))
6529 (defun org-agenda-earlier (arg)
6530 "Go backward in time by the current span.
6531 With prefix ARG, go backward that many times the current span."
6533 (org-agenda-later (- arg)))
6535 (defun org-agenda-view-mode-dispatch ()
6536 "Call one of the view mode commands."
6538 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6539 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6540 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6542 (let ((a (read-char-exclusive)))
6544 (?\ (call-interactively 'org-agenda-reset-view))
6545 (?d (call-interactively 'org-agenda-day-view))
6546 (?w (call-interactively 'org-agenda-week-view))
6547 (?m (call-interactively 'org-agenda-month-view))
6548 (?y (call-interactively 'org-agenda-year-view))
6549 (?l (call-interactively 'org-agenda-log-mode))
6550 (?L (org-agenda-log-mode '(4)))
6551 (?c (org-agenda-log-mode 'clockcheck))
6552 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6553 (?a (call-interactively 'org-agenda-archives-mode))
6554 (?A (org-agenda-archives-mode 'files))
6555 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6556 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6557 (?G (call-interactively 'org-agenda-toggle-time-grid))
6558 (?D (call-interactively 'org-agenda-toggle-diary))
6559 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6560 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6561 (org-agenda-check-type t 'timeline 'agenda)
6563 (message "Display now includes inactive timestamps as well"))
6564 (?q (message "Abort"))
6565 (otherwise (error "Invalid key" )))))
6567 (defun org-agenda-reset-view ()
6568 "Switch to default view for agenda."
6570 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6571 (defun org-agenda-day-view (&optional day-of-year)
6572 "Switch to daily view for agenda.
6573 With argument DAY-OF-YEAR, switch to that day of the year."
6575 (org-agenda-change-time-span 'day day-of-year))
6576 (defun org-agenda-week-view (&optional iso-week)
6577 "Switch to daily view for agenda.
6578 With argument ISO-WEEK, switch to the corresponding ISO week.
6579 If ISO-WEEK has more then 2 digits, only the last two encode the
6580 week. Any digits before this encode a year. So 200712 means
6581 week 12 of year 2007. Years in the range 1938-2037 can also be
6582 written as 2-digit years."
6584 (org-agenda-change-time-span 'week iso-week))
6585 (defun org-agenda-month-view (&optional month)
6586 "Switch to monthly view for agenda.
6587 With argument MONTH, switch to that month."
6589 (org-agenda-change-time-span 'month month))
6590 (defun org-agenda-year-view (&optional year)
6591 "Switch to yearly view for agenda.
6592 With argument YEAR, switch to that year.
6593 If MONTH has more then 2 digits, only the last two encode the
6594 month. Any digits before this encode a year. So 200712 means
6595 December year 2007. Years in the range 1938-2037 can also be
6596 written as 2-digit years."
6599 (setq year (org-small-year-to-year year)))
6600 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6601 (org-agenda-change-time-span 'year year)
6604 (defun org-agenda-change-time-span (span &optional n)
6605 "Change the agenda view to SPAN.
6606 SPAN may be `day', `week', `month', `year'."
6607 (org-agenda-check-type t 'agenda)
6608 (if (and (not n) (equal org-agenda-current-span span))
6609 (error "Viewing span is already \"%s\"" span))
6610 (let* ((sd (or (org-get-at-bol 'day)
6612 (sd (org-agenda-compute-starting-span sd span n))
6613 (org-agenda-overriding-arguments
6614 (or org-agenda-overriding-arguments
6615 (list (car org-agenda-last-arguments) sd span t))))
6617 (org-agenda-find-same-or-today-or-agenda))
6618 (org-agenda-set-mode-name)
6619 (message "Switched to %s view" span))
6621 (defun org-agenda-compute-starting-span (sd span &optional n)
6622 "Compute starting date for agenda.
6623 SPAN may be `day', `week', `month', `year'. The return value
6624 is a cons cell with the starting date and the number of days,
6625 so that the date SD will be in that range."
6626 (let* ((greg (calendar-gregorian-from-absolute sd))
6633 (setq sd (+ (calendar-absolute-from-gregorian
6637 (let* ((nt (calendar-day-of-week
6638 (calendar-gregorian-from-absolute sd)))
6639 (d (if org-agenda-start-on-weekday
6640 (- nt org-agenda-start-on-weekday)
6643 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6647 (setq y1 (org-small-year-to-year (/ n 100))
6650 (calendar-absolute-from-iso
6652 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6655 (when (and n (> n 99))
6656 (setq y1 (org-small-year-to-year (/ n 100))
6658 (setq sd (calendar-absolute-from-gregorian
6659 (list (or n mg) 1 (or y1 yg))))))
6661 (setq sd (calendar-absolute-from-gregorian
6662 (list 1 1 (or n yg))))))
6665 (defun org-agenda-next-date-line (&optional arg)
6666 "Jump to the next line indicating a date in agenda buffer."
6668 (org-agenda-check-type t 'agenda 'timeline)
6669 (beginning-of-line 1)
6670 ;; This does not work if user makes date format that starts with a blank
6671 (if (looking-at "^\\S-") (forward-char 1))
6672 (if (not (re-search-forward "^\\S-" nil t arg))
6675 (error "No next date after this line in this buffer")))
6676 (goto-char (match-beginning 0)))
6678 (defun org-agenda-previous-date-line (&optional arg)
6679 "Jump to the previous line indicating a date in agenda buffer."
6681 (org-agenda-check-type t 'agenda 'timeline)
6682 (beginning-of-line 1)
6683 (if (not (re-search-backward "^\\S-" nil t arg))
6684 (error "No previous date before this line in this buffer")))
6686 ;; Initialize the highlight
6687 (defvar org-hl (make-overlay 1 1))
6688 (overlay-put org-hl 'face 'highlight)
6690 (defun org-highlight (begin end &optional buffer)
6691 "Highlight a region with overlay."
6692 (move-overlay org-hl begin end (or buffer (current-buffer))))
6694 (defun org-unhighlight ()
6695 "Detach overlay INDEX."
6696 (org-detach-overlay org-hl))
6698 ;; FIXME this is currently not used.
6699 (defun org-highlight-until-next-command (beg end &optional buffer)
6700 "Move the highlight overlay to BEG/END, remove it before the next command."
6701 (org-highlight beg end buffer)
6702 (add-hook 'pre-command-hook 'org-unhighlight-once))
6703 (defun org-unhighlight-once ()
6704 "Remove the highlight from its position, and this function from the hook."
6705 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6708 (defun org-agenda-follow-mode ()
6709 "Toggle follow mode in an agenda buffer."
6711 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6712 (org-agenda-set-mode-name)
6713 (org-agenda-do-context-action)
6714 (message "Follow mode is %s"
6715 (if org-agenda-follow-mode "on" "off")))
6717 (defun org-agenda-entry-text-mode (&optional arg)
6718 "Toggle entry text mode in an agenda buffer."
6720 (setq org-agenda-entry-text-mode (or (integerp arg)
6721 (not org-agenda-entry-text-mode)))
6722 (org-agenda-entry-text-hide)
6723 (and org-agenda-entry-text-mode
6724 (let ((org-agenda-entry-text-maxlines
6725 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6726 (org-agenda-entry-text-show)))
6727 (org-agenda-set-mode-name)
6728 (message "Entry text mode is %s. Maximum number of lines is %d"
6729 (if org-agenda-entry-text-mode "on" "off")
6730 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6732 (defun org-agenda-clockreport-mode (&optional with-filter)
6733 "Toggle clocktable mode in an agenda buffer.
6734 With prefix arg WITH-FILTER, make the clocktable respect the current
6737 (org-agenda-check-type t 'agenda)
6739 (setq org-agenda-clockreport-mode 'with-filter)
6740 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6741 (org-agenda-set-mode-name)
6743 (message "Clocktable mode is %s"
6744 (if org-agenda-clockreport-mode "on" "off")))
6746 (defun org-agenda-log-mode (&optional special)
6747 "Toggle log mode in an agenda buffer.
6748 With argument SPECIAL, show all possible log items, not only the ones
6749 configured in `org-agenda-log-mode-items'.
6750 With a double `C-u' prefix arg, show *only* log items, nothing else."
6752 (org-agenda-check-type t 'agenda 'timeline)
6753 (setq org-agenda-show-log
6755 ((equal special '(16)) 'only)
6756 ((eq special 'clockcheck)
6757 (if (eq org-agenda-show-log 'clockcheck)
6759 (special '(closed clock state))
6760 (t (not org-agenda-show-log))))
6761 (org-agenda-set-mode-name)
6763 (message "Log mode is %s"
6764 (if org-agenda-show-log "on" "off")))
6766 (defun org-agenda-archives-mode (&optional with-files)
6767 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6768 When called with a prefix argument, include all archive files as well."
6770 (setq org-agenda-archives-mode
6771 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6772 (org-agenda-set-mode-name)
6777 ((eq org-agenda-archives-mode nil)
6778 "No archives are included")
6779 ((eq org-agenda-archives-mode 'trees)
6780 (format "Trees with :%s: tag are included" org-archive-tag))
6781 ((eq org-agenda-archives-mode t)
6782 (format "Trees with :%s: tag and all active archive files are included"
6783 org-archive-tag)))))
6785 (defun org-agenda-toggle-diary ()
6786 "Toggle diary inclusion in an agenda buffer."
6788 (org-agenda-check-type t 'agenda)
6789 (setq org-agenda-include-diary (not org-agenda-include-diary))
6791 (org-agenda-set-mode-name)
6792 (message "Diary inclusion turned %s"
6793 (if org-agenda-include-diary "on" "off")))
6795 (defun org-agenda-toggle-deadlines ()
6796 "Toggle inclusion of entries with a deadline in an agenda buffer."
6798 (org-agenda-check-type t 'agenda)
6799 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6801 (org-agenda-set-mode-name)
6802 (message "Deadlines inclusion turned %s"
6803 (if org-agenda-include-deadlines "on" "off")))
6805 (defun org-agenda-toggle-time-grid ()
6806 "Toggle time grid in an agenda buffer."
6808 (org-agenda-check-type t 'agenda)
6809 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6811 (org-agenda-set-mode-name)
6812 (message "Time-grid turned %s"
6813 (if org-agenda-use-time-grid "on" "off")))
6815 (defun org-agenda-set-mode-name ()
6816 "Set the mode name to indicate all the small mode settings."
6819 (if (get 'org-agenda-files 'org-restrict) " []" "")
6821 '(:eval (org-agenda-span-name org-agenda-current-span))
6822 (if org-agenda-follow-mode " Follow" "")
6823 (if org-agenda-entry-text-mode " ETxt" "")
6824 (if org-agenda-include-diary " Diary" "")
6825 (if org-agenda-include-deadlines " Ddl" "")
6826 (if org-agenda-use-time-grid " Grid" "")
6827 (if (and (boundp 'org-habit-show-habits)
6828 org-habit-show-habits) " Habit" "")
6830 ((consp org-agenda-show-log) " LogAll")
6831 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
6832 (org-agenda-show-log " Log")
6834 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
6836 '(:eval (org-propertize
6841 (get 'org-agenda-category-filter :preset-filter)
6842 org-agenda-category-filter)
6845 'face 'org-agenda-filter-category
6846 'help-echo "Category used in filtering"))
6848 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
6850 '(:eval (org-propertize
6855 (get 'org-agenda-tag-filter :preset-filter)
6856 org-agenda-tag-filter)
6859 'face 'org-agenda-filter-tags
6860 'help-echo "Tags used in filtering"))
6862 (if org-agenda-archives-mode
6863 (if (eq org-agenda-archives-mode t)
6865 (format " :%s:" org-archive-tag))
6867 (if org-agenda-clockreport-mode
6868 (if (eq org-agenda-clockreport-mode 'with-filter)
6869 " Clock{}" " Clock")
6871 (force-mode-line-update))
6873 (defun org-agenda-post-command-hook ()
6874 (setq org-agenda-type
6875 (or (get-text-property (point) 'org-agenda-type)
6876 (get-text-property (max (point-min) (1- (point)))
6877 'org-agenda-type))))
6879 (defun org-agenda-next-line ()
6880 "Move cursor to the next line, and show if follow mode is active."
6882 (call-interactively 'next-line)
6883 (org-agenda-do-context-action))
6885 (defun org-agenda-previous-line ()
6886 "Move cursor to the previous line, and show if follow-mode is active."
6888 (call-interactively 'previous-line)
6889 (org-agenda-do-context-action))
6891 (defun org-agenda-do-context-action ()
6892 "Show outline path and, maybe, follow mode window."
6893 (let ((m (org-get-at-bol 'org-marker)))
6894 (when (and (markerp m) (marker-buffer m))
6895 (and org-agenda-follow-mode
6896 (if org-agenda-follow-indirect
6897 (org-agenda-tree-to-indirect-buffer)
6899 (and org-agenda-show-outline-path
6900 (org-with-point-at m (org-display-outline-path t))))))
6902 (defun org-agenda-show-priority ()
6903 "Show the priority of the current item.
6904 This priority is composed of the main priority given with the [#A] cookies,
6905 and by additional input from the age of a schedules or deadline entry."
6907 (let* ((pri (org-get-at-bol 'priority)))
6908 (message "Priority is %d" (if pri pri -1000))))
6910 (defun org-agenda-show-tags ()
6911 "Show the tags applicable to the current item."
6913 (let* ((tags (org-get-at-bol 'tags)))
6915 (message "Tags are :%s:"
6916 (org-no-properties (mapconcat 'identity tags ":")))
6917 (message "No tags associated with this line"))))
6919 (defun org-agenda-goto (&optional highlight)
6920 "Go to the Org-mode file which contains the item at point."
6922 (let* ((marker (or (org-get-at-bol 'org-marker)
6923 (org-agenda-error)))
6924 (buffer (marker-buffer marker))
6925 (pos (marker-position marker)))
6926 (switch-to-buffer-other-window buffer)
6930 (when (eq major-mode 'org-mode)
6931 (org-show-context 'agenda)
6933 (and (outline-next-heading)
6934 (org-flag-heading nil)))) ; show the next heading
6935 (when (outline-invisible-p)
6936 (show-entry)) ; display invisible text
6937 (recenter (/ (window-height) 2))
6938 (run-hooks 'org-agenda-after-show-hook)
6939 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6941 (defvar org-agenda-after-show-hook nil
6942 "Normal hook run after an item has been shown from the agenda.
6943 Point is in the buffer where the item originated.")
6945 (defun org-agenda-kill ()
6946 "Kill the entry or subtree belonging to the current agenda entry."
6948 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6949 (let* ((marker (or (org-get-at-bol 'org-marker)
6950 (org-agenda-error)))
6951 (buffer (marker-buffer marker))
6952 (pos (marker-position marker))
6953 (type (org-get-at-bol 'type))
6954 dbeg dend (n 0) conf)
6955 (org-with-remote-undo buffer
6956 (with-current-buffer buffer
6959 (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
6960 (setq dbeg (progn (org-back-to-heading t) (point))
6961 dend (org-end-of-subtree t t))
6962 (setq dbeg (point-at-bol)
6963 dend (min (point-max) (1+ (point-at-eol)))))
6965 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6966 (setq conf (or (eq t org-agenda-confirm-kill)
6967 (and (numberp org-agenda-confirm-kill)
6968 (> n org-agenda-confirm-kill))))
6971 (format "Delete entry with %d lines in buffer \"%s\"? "
6972 n (buffer-name buffer))))
6974 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6975 (with-current-buffer buffer (delete-region dbeg dend))
6976 (message "Agenda item and source killed"))))
6978 (defvar org-archive-default-command)
6979 (defun org-agenda-archive-default ()
6980 "Archive the entry or subtree belonging to the current agenda entry."
6982 (require 'org-archive)
6983 (org-agenda-archive-with org-archive-default-command))
6985 (defun org-agenda-archive-default-with-confirmation ()
6986 "Archive the entry or subtree belonging to the current agenda entry."
6988 (require 'org-archive)
6989 (org-agenda-archive-with org-archive-default-command 'confirm))
6991 (defun org-agenda-archive ()
6992 "Archive the entry or subtree belonging to the current agenda entry."
6994 (org-agenda-archive-with 'org-archive-subtree))
6996 (defun org-agenda-archive-to-archive-sibling ()
6997 "Move the entry to the archive sibling."
6999 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7001 (defun org-agenda-archive-with (cmd &optional confirm)
7002 "Move the entry to the archive sibling."
7004 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7005 (let* ((marker (or (org-get-at-bol 'org-marker)
7006 (org-agenda-error)))
7007 (buffer (marker-buffer marker))
7008 (pos (marker-position marker)))
7009 (org-with-remote-undo buffer
7010 (with-current-buffer buffer
7011 (if (eq major-mode 'org-mode)
7013 (not (y-or-n-p "Archive this subtree or entry? ")))
7017 (org-remove-subtree-entries-from-agenda)
7018 (org-back-to-heading t)
7020 (error "Archiving works only in Org-mode files"))))))
7022 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7023 "Remove all lines in the agenda that correspond to a given subtree.
7024 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7025 If this information is not given, the function uses the tree at point."
7026 (let ((buf (or buf (current-buffer))) m p)
7028 (unless (and beg end)
7029 (org-back-to-heading t)
7031 (org-end-of-subtree t)
7033 (set-buffer (get-buffer org-agenda-buffer-name))
7035 (goto-char (point-max))
7036 (beginning-of-line 1)
7038 (when (and (setq m (org-get-at-bol 'org-marker))
7039 (equal buf (marker-buffer m))
7040 (setq p (marker-position m))
7043 (let ((inhibit-read-only t))
7044 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7045 (beginning-of-line 0))))))
7047 (defun org-agenda-refile (&optional goto rfloc no-update)
7048 "Refile the item at point."
7050 (if (equal goto '(16))
7051 (org-refile-goto-last-stored)
7052 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7053 (org-agenda-error)))
7054 (buffer (marker-buffer marker))
7055 (pos (marker-position marker))
7057 (org-refile-get-location
7058 (if goto "Goto" "Refile to") buffer
7059 org-refile-allow-creating-parent-nodes))))
7060 (with-current-buffer buffer
7065 (org-remove-subtree-entries-from-agenda)
7066 (org-refile goto buffer rfloc)))))
7067 (unless no-update (org-agenda-redo))))
7069 (defun org-agenda-open-link (&optional arg)
7070 "Follow the link in the current line, if any.
7071 This looks for a link in the displayed line in the agenda. It also looks
7072 at the text of the entry itself."
7074 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7075 (org-get-at-bol 'org-marker)))
7076 (buffer (and marker (marker-buffer marker)))
7077 (prefix (buffer-substring
7078 (point-at-bol) (point-at-eol))))
7081 (with-current-buffer buffer
7086 (org-offer-links-in-entry arg prefix)))))
7087 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7089 (beginning-of-line 1)
7090 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7091 (org-open-link-from-string (match-string 1)))
7092 (t (error "No link to open here")))))
7094 (defun org-agenda-copy-local-variable (var)
7095 "Get a variable from a referenced buffer and install it here."
7096 (let ((m (org-get-at-bol 'org-marker)))
7097 (when (and m (buffer-live-p (marker-buffer m)))
7098 (org-set-local var (with-current-buffer (marker-buffer m)
7099 (symbol-value var))))))
7101 (defun org-agenda-switch-to (&optional delete-other-windows)
7102 "Go to the Org-mode file which contains the item at point."
7104 (if (and org-return-follows-link
7105 (not (org-get-at-bol 'org-marker))
7106 (org-in-regexp org-bracket-link-regexp))
7107 (org-open-link-from-string (match-string 0))
7108 (let* ((marker (or (org-get-at-bol 'org-marker)
7109 (org-agenda-error)))
7110 (buffer (marker-buffer marker))
7111 (pos (marker-position marker)))
7112 (org-pop-to-buffer-same-window buffer)
7113 (and delete-other-windows (delete-other-windows))
7116 (when (eq major-mode 'org-mode)
7117 (org-show-context 'agenda)
7119 (and (outline-next-heading)
7120 (org-flag-heading nil))) ; show the next heading
7121 (when (outline-invisible-p)
7122 (show-entry)))))) ; display invisible text
7124 (defun org-agenda-goto-mouse (ev)
7125 "Go to the Org-mode file which contains the item at the mouse click."
7127 (mouse-set-point ev)
7130 (defun org-agenda-show (&optional full-entry)
7131 "Display the Org-mode file which contains the item at point.
7132 With prefix argument FULL-ENTRY, make the entire entry visible
7133 if it was hidden in the outline."
7135 (let ((win (selected-window)))
7137 (let ((org-show-entry-below t))
7138 (org-agenda-goto t))
7139 (org-agenda-goto t))
7140 (select-window win)))
7142 (defvar org-agenda-show-window nil)
7143 (defun org-agenda-show-and-scroll-up ()
7144 "Display the Org-mode file which contains the item at point.
7145 When called repeatedly, scroll the window that is displaying the buffer."
7147 (let ((win (selected-window)))
7148 (if (and (window-live-p org-agenda-show-window)
7149 (eq this-command last-command))
7151 (select-window org-agenda-show-window)
7152 (ignore-errors (scroll-up)))
7155 (setq org-agenda-show-window (selected-window)))
7156 (select-window win)))
7158 (defun org-agenda-show-scroll-down ()
7159 "Scroll down the window showing the agenda."
7161 (let ((win (selected-window)))
7162 (when (window-live-p org-agenda-show-window)
7163 (select-window org-agenda-show-window)
7164 (ignore-errors (scroll-down))
7165 (select-window win))))
7167 (defun org-agenda-show-1 (&optional more)
7168 "Display the Org-mode file which contains the item at point.
7169 The prefix arg selects the amount of information to display:
7172 1 just show the entry according to defaults.
7173 2 show the children view
7174 3 show the subtree view
7175 4 show the entire subtree and any LOGBOOK drawers
7176 5 show the entire subtree and any drawers
7177 With prefix argument FULL-ENTRY, make the entire entry visible
7178 if it was hidden in the outline."
7180 (let ((win (selected-window)))
7182 (org-recenter-heading 1)
7187 (org-back-to-heading)
7188 (run-hook-with-args 'org-cycle-hook 'folded))
7189 (message "Remote: FOLDED"))
7190 ((and (org-called-interactively-p 'any) (= more 1))
7191 (message "Remote: show with default settings"))
7196 (org-back-to-heading)
7197 (run-hook-with-args 'org-cycle-hook 'children))
7198 (message "Remote: CHILDREN"))
7202 (org-back-to-heading)
7203 (run-hook-with-args 'org-cycle-hook 'subtree))
7204 (message "Remote: SUBTREE"))
7206 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7208 (concat "^[ \t]*:\\("
7209 (mapconcat 'regexp-quote org-drawers "\\|")
7213 (org-back-to-heading)
7214 (org-cycle-hide-drawers 'subtree)))
7215 (message "Remote: SUBTREE AND LOGBOOK"))
7218 (message "Remote: SUBTREE AND ALL DRAWERS")))
7219 (select-window win)))
7221 (defun org-recenter-heading (n)
7223 (org-back-to-heading)
7226 (defvar org-agenda-cycle-counter nil)
7227 (defun org-agenda-cycle-show (&optional n)
7228 "Show the current entry in another window, with default settings.
7229 Default settings are taken from `org-show-hierarchy-above' and siblings.
7230 When use repeatedly in immediate succession, the remote entry will cycle
7233 children -> subtree -> folded
7235 When called with a numeric prefix arg, that arg will be passed through to
7236 `org-agenda-show-1'. For the interpretation of that argument, see the
7237 docstring of `org-agenda-show-1'."
7240 (setq org-agenda-cycle-counter n)
7241 (if (not (eq last-command this-command))
7242 (setq org-agenda-cycle-counter 1)
7243 (if (equal org-agenda-cycle-counter 0)
7244 (setq org-agenda-cycle-counter 2)
7245 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7246 (if (> org-agenda-cycle-counter 3)
7247 (setq org-agenda-cycle-counter 0)))))
7248 (org-agenda-show-1 org-agenda-cycle-counter))
7250 (defun org-agenda-recenter (arg)
7251 "Display the Org-mode file which contains the item at point and recenter."
7253 (let ((win (selected-window)))
7256 (select-window win)))
7258 (defun org-agenda-show-mouse (ev)
7259 "Display the Org-mode file which contains the item at the mouse click."
7261 (mouse-set-point ev)
7264 (defun org-agenda-check-no-diary ()
7265 "Check if the entry is a diary link and abort if yes."
7266 (if (org-get-at-bol 'org-agenda-diary-link)
7267 (org-agenda-error)))
7269 (defun org-agenda-error ()
7270 (error "Command not allowed in this line"))
7272 (defun org-agenda-tree-to-indirect-buffer ()
7273 "Show the subtree corresponding to the current entry in an indirect buffer.
7274 This calls the command `org-tree-to-indirect-buffer' from the original
7276 With numerical prefix arg ARG, go up to this level and then take that tree.
7277 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7278 use the dedicated frame)."
7280 (if (and current-prefix-arg (listp current-prefix-arg))
7281 (org-agenda-do-tree-to-indirect-buffer)
7282 (let ((agenda-window (selected-window))
7283 (indirect-window (and org-last-indirect-buffer (get-buffer-window org-last-indirect-buffer))))
7284 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7287 (unless (and indirect-window (window-live-p indirect-window))
7288 (setq indirect-window (split-window agenda-window)))
7289 (select-window indirect-window)
7290 (switch-to-buffer org-last-indirect-buffer :norecord)
7291 (fit-window-to-buffer indirect-window))
7292 (select-window agenda-window)))))
7294 (defun org-agenda-do-tree-to-indirect-buffer ()
7295 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7296 (org-agenda-check-no-diary)
7297 (let* ((marker (or (org-get-at-bol 'org-marker)
7298 (org-agenda-error)))
7299 (buffer (marker-buffer marker))
7300 (pos (marker-position marker)))
7301 (with-current-buffer buffer
7304 (call-interactively 'org-tree-to-indirect-buffer)))))
7306 (defvar org-last-heading-marker (make-marker)
7307 "Marker pointing to the headline that last changed its TODO state
7308 by a remote command from the agenda.")
7310 (defun org-agenda-todo-nextset ()
7311 "Switch TODO entry to next sequence."
7313 (org-agenda-todo 'nextset))
7315 (defun org-agenda-todo-previousset ()
7316 "Switch TODO entry to previous sequence."
7318 (org-agenda-todo 'previousset))
7320 (defun org-agenda-todo (&optional arg)
7321 "Cycle TODO state of line at point, also in Org-mode file.
7322 This changes the line at point, all other lines in the agenda referring to
7323 the same tree node, and the headline of the tree node in the Org-mode file."
7325 (org-agenda-check-no-diary)
7326 (let* ((col (current-column))
7327 (marker (or (org-get-at-bol 'org-marker)
7328 (org-agenda-error)))
7329 (buffer (marker-buffer marker))
7330 (pos (marker-position marker))
7331 (hdmarker (org-get-at-bol 'org-hd-marker))
7332 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7333 (inhibit-read-only t)
7334 org-agenda-headline-snapshot-before-repeat newhead just-one)
7335 (org-with-remote-undo buffer
7336 (with-current-buffer buffer
7339 (org-show-context 'agenda)
7341 (and (outline-next-heading)
7342 (org-flag-heading nil))) ; show the next heading
7343 (let ((current-prefix-arg arg))
7344 (call-interactively 'org-todo))
7345 (and (bolp) (forward-char 1))
7346 (setq newhead (org-get-heading))
7347 (when (and (org-bound-and-true-p
7348 org-agenda-headline-snapshot-before-repeat)
7349 (not (equal org-agenda-headline-snapshot-before-repeat
7352 (setq newhead org-agenda-headline-snapshot-before-repeat
7355 (org-back-to-heading)
7356 (move-marker org-last-heading-marker (point))))
7357 (beginning-of-line 1)
7359 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7360 (org-move-to-column col))))
7362 (defun org-agenda-add-note (&optional arg)
7363 "Add a time-stamped note to the entry at point."
7365 (org-agenda-check-no-diary)
7366 (let* ((marker (or (org-get-at-bol 'org-marker)
7367 (org-agenda-error)))
7368 (buffer (marker-buffer marker))
7369 (pos (marker-position marker))
7370 (hdmarker (org-get-at-bol 'org-hd-marker))
7371 (inhibit-read-only t))
7372 (with-current-buffer buffer
7375 (org-show-context 'agenda)
7377 (and (outline-next-heading)
7378 (org-flag-heading nil))) ; show the next heading
7381 (defun org-agenda-change-all-lines (newhead hdmarker
7382 &optional fixface just-this)
7383 "Change all lines in the agenda buffer which match HDMARKER.
7384 The new content of the line will be NEWHEAD (as modified by
7385 `org-agenda-format-item'). HDMARKER is checked with
7386 `equal' against all `org-hd-marker' text properties in the file.
7387 If FIXFACE is non-nil, the face of each item is modified according to
7389 If JUST-THIS is non-nil, change just the current line, not all.
7390 If FORCE-TAGS is non nil, the car of it returns the new tags."
7391 (let* ((inhibit-read-only t)
7392 (line (org-current-line))
7393 (thetags (with-current-buffer (marker-buffer hdmarker)
7394 (save-excursion (save-restriction (widen)
7395 (goto-char hdmarker)
7396 (org-get-tags-at)))))
7397 props m pl undone-face done-face finish new dotime cat tags)
7399 (goto-char (point-max))
7400 (beginning-of-line 1)
7402 (setq finish (bobp))
7403 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7404 (or (not just-this) (= (org-current-line) line))
7406 (setq props (text-properties-at (point))
7407 dotime (org-get-at-bol 'dotime)
7408 cat (org-get-at-bol 'org-category)
7411 (let ((org-prefix-format-compiled
7412 (or (get-text-property (point) 'format)
7413 org-prefix-format-compiled)))
7414 (with-current-buffer (marker-buffer hdmarker)
7418 (org-agenda-format-item (org-get-at-bol 'extra)
7419 newhead cat tags dotime)))))
7420 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7421 undone-face (org-get-at-bol 'undone-face)
7422 done-face (org-get-at-bol 'done-face))
7423 (beginning-of-line 1)
7426 (and (looking-at ".*\n?") (replace-match "")))
7428 (replace-match new t t)
7429 (beginning-of-line 1)
7430 (add-text-properties (point-at-bol) (point-at-eol) props)
7432 (add-text-properties
7433 (point-at-bol) (point-at-eol)
7435 (if org-last-todo-state-is-todo
7436 undone-face done-face))))
7437 (org-agenda-highlight-todo 'line)
7438 (beginning-of-line 1))
7439 (t (error "Line update did not work"))))
7440 (beginning-of-line 0)))
7441 (org-finalize-agenda)))
7443 (defun org-agenda-align-tags (&optional line)
7444 "Align all tags in agenda items to `org-agenda-tags-column'."
7445 (let ((inhibit-read-only t) l c)
7447 (goto-char (if line (point-at-bol) (point-min)))
7448 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7449 (if line (point-at-eol) nil) t)
7450 (add-text-properties
7451 (match-beginning 2) (match-end 2)
7452 (list 'face (delq nil (let ((prop (get-text-property
7453 (match-beginning 2) 'face)))
7454 (or (listp prop) (setq prop (list prop)))
7455 (if (memq 'org-tag prop)
7457 (cons 'org-tag prop))))))
7458 (setq l (- (match-end 2) (match-beginning 2))
7459 c (if (< org-agenda-tags-column 0)
7460 (- (abs org-agenda-tags-column) l)
7461 org-agenda-tags-column))
7462 (delete-region (match-beginning 1) (match-end 1))
7463 (goto-char (match-beginning 1))
7464 (insert (org-add-props
7465 (make-string (max 1 (- c (current-column))) ?\ )
7466 (plist-put (copy-sequence (text-properties-at (point)))
7468 (goto-char (point-min))
7469 (org-font-lock-add-tag-faces (point-max)))))
7471 (defun org-agenda-priority-up ()
7472 "Increase the priority of line at point, also in Org-mode file."
7474 (org-agenda-priority 'up))
7476 (defun org-agenda-priority-down ()
7477 "Decrease the priority of line at point, also in Org-mode file."
7479 (org-agenda-priority 'down))
7481 (defun org-agenda-priority (&optional force-direction)
7482 "Set the priority of line at point, also in Org-mode file.
7483 This changes the line at point, all other lines in the agenda referring to
7484 the same tree node, and the headline of the tree node in the Org-mode file."
7486 (unless org-enable-priority-commands
7487 (error "Priority commands are disabled"))
7488 (org-agenda-check-no-diary)
7489 (let* ((marker (or (org-get-at-bol 'org-marker)
7490 (org-agenda-error)))
7491 (hdmarker (org-get-at-bol 'org-hd-marker))
7492 (buffer (marker-buffer hdmarker))
7493 (pos (marker-position hdmarker))
7494 (inhibit-read-only t)
7496 (org-with-remote-undo buffer
7497 (with-current-buffer buffer
7500 (org-show-context 'agenda)
7502 (and (outline-next-heading)
7503 (org-flag-heading nil))) ; show the next heading
7504 (funcall 'org-priority force-direction)
7506 (setq newhead (org-get-heading)))
7507 (org-agenda-change-all-lines newhead hdmarker)
7508 (beginning-of-line 1))))
7510 ;; FIXME: should fix the tags property of the agenda line.
7511 (defun org-agenda-set-tags (&optional tag onoff)
7512 "Set tags for the current headline."
7514 (org-agenda-check-no-diary)
7515 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7516 (call-interactively 'org-change-tag-in-region)
7517 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7518 (org-agenda-error)))
7519 (buffer (marker-buffer hdmarker))
7520 (pos (marker-position hdmarker))
7521 (inhibit-read-only t)
7523 (org-with-remote-undo buffer
7524 (with-current-buffer buffer
7528 (org-show-context 'agenda))
7530 (and (outline-next-heading)
7531 (org-flag-heading nil))) ; show the next heading
7534 (org-toggle-tag tag onoff)
7535 (call-interactively 'org-set-tags))
7537 (setq newhead (org-get-heading)))
7538 (org-agenda-change-all-lines newhead hdmarker)
7539 (beginning-of-line 1)))))
7541 (defun org-agenda-set-property ()
7542 "Set a property for the current headline."
7544 (org-agenda-check-no-diary)
7545 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7546 (org-agenda-error)))
7547 (buffer (marker-buffer hdmarker))
7548 (pos (marker-position hdmarker))
7549 (inhibit-read-only t)
7551 (org-with-remote-undo buffer
7552 (with-current-buffer buffer
7556 (org-show-context 'agenda))
7558 (and (outline-next-heading)
7559 (org-flag-heading nil))) ; show the next heading
7561 (call-interactively 'org-set-property)))))
7563 (defun org-agenda-set-effort ()
7564 "Set the effort property for the current headline."
7566 (org-agenda-check-no-diary)
7567 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7568 (org-agenda-error)))
7569 (buffer (marker-buffer hdmarker))
7570 (pos (marker-position hdmarker))
7571 (inhibit-read-only t)
7573 (org-with-remote-undo buffer
7574 (with-current-buffer buffer
7578 (org-show-context 'agenda))
7580 (and (outline-next-heading)
7581 (org-flag-heading nil))) ; show the next heading
7583 (call-interactively 'org-set-effort)
7585 (setq newhead (org-get-heading)))
7586 (org-agenda-change-all-lines newhead hdmarker))))
7588 (defun org-agenda-toggle-archive-tag ()
7589 "Toggle the archive tag for the current entry."
7591 (org-agenda-check-no-diary)
7592 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7593 (org-agenda-error)))
7594 (buffer (marker-buffer hdmarker))
7595 (pos (marker-position hdmarker))
7596 (inhibit-read-only t)
7598 (org-with-remote-undo buffer
7599 (with-current-buffer buffer
7602 (org-show-context 'agenda)
7604 (and (outline-next-heading)
7605 (org-flag-heading nil))) ; show the next heading
7606 (call-interactively 'org-toggle-archive-tag)
7608 (setq newhead (org-get-heading)))
7609 (org-agenda-change-all-lines newhead hdmarker)
7610 (beginning-of-line 1))))
7612 (defun org-agenda-do-date-later (arg)
7615 ((or (equal arg '(16))
7617 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7618 (setq this-command 'org-agenda-date-later-minutes)
7619 (org-agenda-date-later-minutes 1))
7620 ((or (equal arg '(4))
7622 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7623 (setq this-command 'org-agenda-date-later-hours)
7624 (org-agenda-date-later-hours 1))
7626 (org-agenda-date-later (prefix-numeric-value arg)))))
7628 (defun org-agenda-do-date-earlier (arg)
7631 ((or (equal arg '(16))
7633 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7634 (setq this-command 'org-agenda-date-earlier-minutes)
7635 (org-agenda-date-earlier-minutes 1))
7636 ((or (equal arg '(4))
7638 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7639 (setq this-command 'org-agenda-date-earlier-hours)
7640 (org-agenda-date-earlier-hours 1))
7642 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7644 (defun org-agenda-date-later (arg &optional what)
7645 "Change the date of this item to ARG day(s) later."
7647 (org-agenda-check-type t 'agenda 'timeline)
7648 (org-agenda-check-no-diary)
7649 (let* ((marker (or (org-get-at-bol 'org-marker)
7650 (org-agenda-error)))
7651 (buffer (marker-buffer marker))
7652 (pos (marker-position marker))
7654 (org-with-remote-undo buffer
7655 (with-current-buffer buffer
7658 (if (not (org-at-timestamp-p))
7659 (error "Cannot find time stamp"))
7660 (when (and org-agenda-move-date-from-past-immediately-to-today
7662 (or (not what) (eq what 'day))
7663 (not (save-match-data (org-at-date-range-p))))
7664 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
7665 cdate (calendar-absolute-from-gregorian
7666 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
7669 ;; immediately shift to today
7670 (setq arg (- today cdate))))
7671 (org-timestamp-change arg (or what 'day))
7672 (when (and (org-at-date-range-p)
7673 (re-search-backward org-tr-regexp-both (point-at-bol)))
7674 (let ((end org-last-changed-timestamp))
7675 (org-timestamp-change arg (or what 'day))
7676 (setq org-last-changed-timestamp
7677 (concat org-last-changed-timestamp "--" end)))))
7678 (org-agenda-show-new-time marker org-last-changed-timestamp))
7679 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7681 (defun org-agenda-date-earlier (arg &optional what)
7682 "Change the date of this item to ARG day(s) earlier."
7684 (org-agenda-date-later (- arg) what))
7686 (defun org-agenda-date-later-minutes (arg)
7687 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7689 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7690 (org-agenda-date-later arg 'minute))
7692 (defun org-agenda-date-earlier-minutes (arg)
7693 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7695 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7696 (org-agenda-date-earlier arg 'minute))
7698 (defun org-agenda-date-later-hours (arg)
7699 "Change the time of this item, in hour steps."
7701 (org-agenda-date-later arg 'hour))
7703 (defun org-agenda-date-earlier-hours (arg)
7704 "Change the time of this item, in hour steps."
7706 (org-agenda-date-earlier arg 'hour))
7708 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7709 "Show new date stamp via text properties."
7710 ;; We use text properties to make this undoable
7711 (let ((inhibit-read-only t)
7712 (buffer-invisibility-spec))
7713 (setq stamp (concat " " prefix " => " stamp))
7715 (goto-char (point-max))
7717 (when (equal marker (org-get-at-bol 'org-marker))
7718 (org-move-to-column (- (window-width) (length stamp)) t)
7719 (org-agenda-fix-tags-filter-overlays-at (point))
7720 (if (featurep 'xemacs)
7721 ;; Use `duplicable' property to trigger undo recording
7722 (let ((ex (make-extent nil nil))
7723 (gl (make-glyph stamp)))
7724 (set-glyph-face gl 'secondary-selection)
7725 (set-extent-properties
7726 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7727 (insert-extent ex (1- (point)) (point-at-eol)))
7728 (add-text-properties
7729 (1- (point)) (point-at-eol)
7730 (list 'display (org-add-props stamp nil
7731 'face 'secondary-selection))))
7732 (beginning-of-line 1))
7733 (beginning-of-line 0)))))
7735 (defun org-agenda-date-prompt (arg)
7736 "Change the date of this item. Date is prompted for, with default today.
7737 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7738 be used to request time specification in the time stamp."
7740 (org-agenda-check-type t 'agenda 'timeline)
7741 (org-agenda-check-no-diary)
7742 (let* ((marker (or (org-get-at-bol 'org-marker)
7743 (org-agenda-error)))
7744 (buffer (marker-buffer marker))
7745 (pos (marker-position marker)))
7746 (org-with-remote-undo buffer
7747 (with-current-buffer buffer
7750 (if (not (org-at-timestamp-p t))
7751 (error "Cannot find time stamp"))
7752 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7753 (org-agenda-show-new-time marker org-last-changed-timestamp))
7754 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7756 (defun org-agenda-schedule (arg &optional time)
7757 "Schedule the item at point.
7758 ARG is passed through to `org-schedule'."
7760 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7761 (org-agenda-check-no-diary)
7762 (let* ((marker (or (org-get-at-bol 'org-marker)
7763 (org-agenda-error)))
7764 (type (marker-insertion-type marker))
7765 (buffer (marker-buffer marker))
7766 (pos (marker-position marker))
7767 (org-insert-labeled-timestamps-at-point nil)
7769 (set-marker-insertion-type marker t)
7770 (org-with-remote-undo buffer
7771 (with-current-buffer buffer
7774 (setq ts (org-schedule arg time)))
7775 (org-agenda-show-new-time marker ts "S"))
7776 (message "Item scheduled for %s" ts)))
7778 (defun org-agenda-deadline (arg &optional time)
7779 "Schedule the item at point.
7780 ARG is passed through to `org-deadline'."
7782 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7783 (org-agenda-check-no-diary)
7784 (let* ((marker (or (org-get-at-bol 'org-marker)
7785 (org-agenda-error)))
7786 (buffer (marker-buffer marker))
7787 (pos (marker-position marker))
7788 (org-insert-labeled-timestamps-at-point nil)
7790 (org-with-remote-undo buffer
7791 (with-current-buffer buffer
7794 (setq ts (org-deadline arg time)))
7795 (org-agenda-show-new-time marker ts "D"))
7796 (message "Deadline for this item set to %s" ts)))
7798 (defun org-agenda-action ()
7799 "Select entry for agenda action, or execute an agenda action.
7800 This command prompts for another letter. Valid inputs are:
7802 m Mark the entry at point for an agenda action
7803 s Schedule the marked entry to the date at the cursor
7804 d Set the deadline of the marked entry to the date at the cursor
7805 r Call `org-remember' with cursor date as the default date
7806 c Call `org-capture' with cursor date as the default date
7807 SPC Show marked entry in other window
7808 TAB Visit marked entry in other window
7810 The cursor may be at a date in the calendar, or in the Org agenda."
7813 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7814 (setq ans (read-char-exclusive))
7818 (if (eq major-mode 'org-agenda-mode)
7819 (let ((m (or (org-get-at-bol 'org-hd-marker)
7820 (org-get-at-bol 'org-marker))))
7823 (move-marker org-agenda-action-marker
7824 (marker-position m) (marker-buffer m))
7825 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7826 (error "Don't know which entry to mark")))
7827 (error "This command works only in the agenda")))
7829 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7831 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7833 (org-agenda-do-action '(org-remember) t))
7835 (org-agenda-do-action '(org-capture) t))
7837 (let ((cw (selected-window)))
7838 (org-switch-to-buffer-other-window
7839 (marker-buffer org-agenda-action-marker))
7840 (goto-char org-agenda-action-marker)
7841 (org-show-context 'agenda)
7842 (select-window cw)))
7844 (org-switch-to-buffer-other-window
7845 (marker-buffer org-agenda-action-marker))
7846 (goto-char org-agenda-action-marker)
7847 (org-show-context 'agenda))
7848 (t (error "Invalid agenda action %c" ans)))))
7850 (defun org-agenda-do-action (form &optional current-buffer)
7851 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7852 (let ((org-overriding-default-time (org-get-cursor-date)))
7855 (if (not (marker-buffer org-agenda-action-marker))
7856 (error "No entry has been selected for agenda action")
7857 (with-current-buffer (marker-buffer org-agenda-action-marker)
7861 (goto-char org-agenda-action-marker)
7864 (defun org-agenda-clock-in (&optional arg)
7865 "Start the clock on the currently selected item."
7867 (org-agenda-check-no-diary)
7868 (if (equal arg '(4))
7870 (let* ((marker (or (org-get-at-bol 'org-marker)
7871 (org-agenda-error)))
7872 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7874 (pos (marker-position marker))
7876 (org-with-remote-undo (marker-buffer marker)
7877 (with-current-buffer (marker-buffer marker)
7880 (org-show-context 'agenda)
7882 (org-cycle-hide-drawers 'children)
7884 (setq newhead (org-get-heading)))
7885 (org-agenda-change-all-lines newhead hdmarker)))))
7887 (defun org-agenda-clock-out ()
7888 "Stop the currently running clock."
7890 (unless (marker-buffer org-clock-marker)
7891 (error "No running clock"))
7892 (let ((marker (make-marker)) newhead)
7893 (org-with-remote-undo (marker-buffer org-clock-marker)
7894 (with-current-buffer (marker-buffer org-clock-marker)
7898 (goto-char org-clock-marker)
7899 (org-back-to-heading t)
7900 (move-marker marker (point))
7902 (setq newhead (org-get-heading))))))
7903 (org-agenda-change-all-lines newhead marker)
7904 (move-marker marker nil)))
7906 (defun org-agenda-clock-cancel (&optional arg)
7907 "Cancel the currently running clock."
7909 (unless (marker-buffer org-clock-marker)
7910 (error "No running clock"))
7911 (org-with-remote-undo (marker-buffer org-clock-marker)
7912 (org-clock-cancel)))
7914 (defun org-agenda-clock-goto ()
7915 "Jump to the currently clocked in task within the agenda.
7916 If the currently clocked in task is not listed in the agenda
7917 buffer, display it in another window."
7921 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7922 (setq pos (overlay-start o))))
7923 (overlays-in (point-min) (point-max)))
7924 (cond (pos (goto-char pos))
7925 ;; If the currently clocked entry is not in the agenda
7926 ;; buffer, we visit it in another window:
7927 (org-clock-current-task
7928 (org-switch-to-buffer-other-window (org-clock-goto)))
7929 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7931 (defun org-agenda-diary-entry-in-org-file ()
7932 "Make a diary entry in the file `org-agenda-diary-file'."
7933 (let (d1 d2 char (text "") dp1 dp2)
7934 (if (equal (buffer-name) "*Calendar*")
7935 (setq d1 (calendar-cursor-to-date t)
7936 d2 (car calendar-mark-ring))
7937 (setq dp1 (get-text-property (point-at-bol) 'day))
7938 (unless dp1 (error "No date defined in current line"))
7939 (setq d1 (calendar-gregorian-from-absolute dp1)
7940 d2 (and (ignore-errors (mark))
7943 (setq dp2 (get-text-property (point-at-bol) 'day)))
7944 (calendar-gregorian-from-absolute dp2))))
7945 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7946 (setq char (read-char-exclusive))
7949 (setq text (read-string "Day entry: "))
7950 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7951 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7953 (setq d1 (list (car d1) (nth 1 d1)
7954 (read-number (format "Reference year [%d]: " (nth 2 d1))
7956 (setq text (read-string "Anniversary (use %d to show years): "))
7957 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7958 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7960 (setq text (read-string "Block entry: "))
7961 (unless (and d1 d2 (not (equal d1 d2)))
7962 (error "No block of days selected"))
7963 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7964 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7966 (org-switch-to-buffer-other-window
7967 (find-file-noselect org-agenda-diary-file))
7968 (require 'org-datetree)
7969 (org-datetree-find-date-create d1)
7971 (t (error "Invalid selection character `%c'" char)))))
7973 (defcustom org-agenda-insert-diary-strategy 'date-tree
7974 "Where in `org-agenda-diary-file' should new entries be added?
7977 date-tree in the date tree, as child of the date
7978 top-level as top-level entries at the end of the file."
7981 (const :tag "in a date tree" date-tree)
7982 (const :tag "as top level at end of file" top-level)))
7984 (defcustom org-agenda-insert-diary-extract-time nil
7985 "Non-nil means extract any time specification from the diary entry."
7989 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7990 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7991 If TEXT is not empty, it will become the headline of the new entry, and
7992 the resulting entry will not be shown. When TEXT is empty, switch to
7993 `org-agenda-diary-file' and let the user finish the entry there."
7994 (let ((cw (current-window-configuration)))
7995 (org-switch-to-buffer-other-window
7996 (find-file-noselect org-agenda-diary-file))
7998 (goto-char (point-min))
8000 ((eq type 'anniversary)
8001 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8003 (or (org-at-heading-p t)
8005 (outline-next-heading)
8006 (insert "* Anniversaries\n\n")
8007 (beginning-of-line -1)))))
8008 (outline-next-heading)
8009 (org-back-over-empty-lines)
8012 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8013 (nth 2 d1) (car d1) (nth 1 d1) text)))
8015 (let ((org-prefix-has-time t)
8016 (org-agenda-time-leading-zero t)
8018 (if org-agenda-insert-diary-extract-time
8019 ;; Use org-agenda-format-item to parse text for a time-range and
8020 ;; remove it. FIXME: This is a hack, we should refactor
8021 ;; that function to make time extraction available separately
8022 (setq fmt (org-agenda-format-item nil text nil nil t)
8023 time (get-text-property 0 'time fmt)
8024 time2 (if (> (length time) 0)
8025 ;; split-string removes trailing ...... if
8026 ;; no end time given. First space
8027 ;; separates time from date.
8028 (concat " " (car (split-string time "\\.")))
8030 text (get-text-property 0 'txt fmt)))
8031 (if (eq org-agenda-insert-diary-strategy 'top-level)
8032 (org-agenda-insert-diary-as-top-level text)
8033 (require 'org-datetree)
8034 (org-datetree-find-date-create d1)
8035 (org-agenda-insert-diary-make-new-entry text))
8036 (org-insert-time-stamp (org-time-from-absolute
8037 (calendar-absolute-from-gregorian d1))
8038 nil nil nil nil time2))
8041 (if (> (calendar-absolute-from-gregorian d1)
8042 (calendar-absolute-from-gregorian d2))
8043 (setq d1 (prog1 d2 (setq d2 d1))))
8044 (if (eq org-agenda-insert-diary-strategy 'top-level)
8045 (org-agenda-insert-diary-as-top-level text)
8046 (require 'org-datetree)
8047 (org-datetree-find-date-create d1)
8048 (org-agenda-insert-diary-make-new-entry text))
8049 (org-insert-time-stamp (org-time-from-absolute
8050 (calendar-absolute-from-gregorian d1)))
8052 (org-insert-time-stamp (org-time-from-absolute
8053 (calendar-absolute-from-gregorian d2)))
8055 (if (string-match "\\S-" text)
8057 (set-window-configuration cw)
8058 (message "%s entry added to %s"
8059 (capitalize (symbol-name type))
8060 (abbreviate-file-name org-agenda-diary-file)))
8062 (message "Please finish entry here"))))
8064 (defun org-agenda-insert-diary-as-top-level (text)
8065 "Make new entry as a top-level entry at the end of the file.
8066 Add TEXT as headline, and position the cursor in the second line so that
8067 a timestamp can be added there."
8069 (goto-char (point-max))
8070 (or (bolp) (insert "\n"))
8071 (insert "* " text "\n")
8072 (if org-adapt-indentation (org-indent-to-column 2)))
8074 (defun org-agenda-insert-diary-make-new-entry (text)
8075 "Make new entry as last child of current entry.
8076 Add TEXT as headline, and position the cursor in the second line so that
8077 a timestamp can be added there."
8078 (let ((org-show-following-heading t)
8079 (org-show-siblings t)
8080 (org-show-hierarchy-above t)
8081 (org-show-entry-below t)
8083 (outline-next-heading)
8084 (org-back-over-empty-lines)
8085 (or (looking-at "[ \t]*$")
8086 (progn (insert "\n") (backward-char 1)))
8087 (org-insert-heading nil t)
8089 (setq col (current-column))
8091 (if org-adapt-indentation (org-indent-to-column col))
8092 (let ((org-show-following-heading t)
8093 (org-show-siblings t)
8094 (org-show-hierarchy-above t)
8095 (org-show-entry-below t))
8096 (org-show-context))))
8098 (defun org-agenda-diary-entry ()
8099 "Make a diary entry, like the `i' command from the calendar.
8100 All the standard commands work: block, weekly etc.
8101 When `org-agenda-diary-file' points to a file,
8102 `org-agenda-diary-entry-in-org-file' is called instead to create
8103 entries in that Org-mode file."
8105 (org-agenda-check-type t 'agenda 'timeline)
8106 (if (not (eq org-agenda-diary-file 'diary-file))
8107 (org-agenda-diary-entry-in-org-file)
8108 (require 'diary-lib)
8110 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8111 (read-char-exclusive)))
8112 (cmd (cdr (assoc char
8113 '((?d . insert-diary-entry)
8114 (?w . insert-weekly-diary-entry)
8115 (?m . insert-monthly-diary-entry)
8116 (?y . insert-yearly-diary-entry)
8117 (?a . insert-anniversary-diary-entry)
8118 (?b . insert-block-diary-entry)
8119 (?c . insert-cyclic-diary-entry)))))
8120 (oldf (symbol-function 'calendar-cursor-to-date))
8121 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8123 (mark (or (mark t) (point))))
8125 (error "No command associated with <%c>" char))
8126 (unless (and (get-text-property point 'day)
8127 (or (not (equal ?b char))
8128 (get-text-property mark 'day)))
8129 (error "Don't know which date to use for diary entry"))
8130 ;; We implement this by hacking the `calendar-cursor-to-date' function
8131 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8132 (let ((calendar-mark-ring
8133 (list (calendar-gregorian-from-absolute
8134 (or (get-text-property mark 'day)
8135 (get-text-property point 'day))))))
8138 (fset 'calendar-cursor-to-date
8139 (lambda (&optional error dummy)
8140 (calendar-gregorian-from-absolute
8141 (get-text-property point 'day))))
8142 (call-interactively cmd))
8143 (fset 'calendar-cursor-to-date oldf))))))
8145 (defun org-agenda-execute-calendar-command (cmd)
8146 "Execute a calendar command from the agenda, with the date associated to
8147 the cursor position."
8148 (org-agenda-check-type t 'agenda 'timeline)
8149 (require 'diary-lib)
8150 (unless (get-text-property (point) 'day)
8151 (error "Don't know which date to use for calendar command"))
8152 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8154 (date (calendar-gregorian-from-absolute
8155 (get-text-property point 'day)))
8156 ;; the following 2 vars are needed in the calendar
8157 (displayed-month (car date))
8158 (displayed-year (nth 2 date)))
8161 (fset 'calendar-cursor-to-date
8162 (lambda (&optional error dummy)
8163 (calendar-gregorian-from-absolute
8164 (get-text-property point 'day))))
8165 (call-interactively cmd))
8166 (fset 'calendar-cursor-to-date oldf))))
8168 (defun org-agenda-phases-of-moon ()
8169 "Display the phases of the moon for the 3 months around the cursor date."
8171 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8173 (defun org-agenda-holidays ()
8174 "Display the holidays for the 3 months around the cursor date."
8176 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8178 (defvar calendar-longitude)
8179 (defvar calendar-latitude)
8180 (defvar calendar-location-name)
8182 (defun org-agenda-sunrise-sunset (arg)
8183 "Display sunrise and sunset for the cursor date.
8184 Latitude and longitude can be specified with the variables
8185 `calendar-latitude' and `calendar-longitude'. When called with prefix
8186 argument, latitude and longitude will be prompted for."
8189 (let ((calendar-longitude (if arg nil calendar-longitude))
8190 (calendar-latitude (if arg nil calendar-latitude))
8191 (calendar-location-name
8192 (if arg "the given coordinates" calendar-location-name)))
8193 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8195 (defun org-agenda-goto-calendar ()
8196 "Open the Emacs calendar with the date at the cursor."
8198 (org-agenda-check-type t 'agenda 'timeline)
8199 (let* ((day (or (get-text-property (point) 'day)
8200 (error "Don't know which date to open in calendar")))
8201 (date (calendar-gregorian-from-absolute day))
8202 (calendar-move-hook nil)
8203 (calendar-view-holidays-initially-flag nil)
8204 (calendar-view-diary-initially-flag nil))
8206 (calendar-goto-date date)))
8209 (defun org-calendar-goto-agenda ()
8210 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8211 This is a command that has to be installed in `calendar-mode-map'."
8213 (org-agenda-list nil (calendar-absolute-from-gregorian
8214 (calendar-cursor-to-date))
8217 (defun org-agenda-convert-date ()
8219 (org-agenda-check-type t 'agenda 'timeline)
8220 (let ((day (get-text-property (point) 'day))
8223 (error "Don't know which date to convert"))
8224 (setq date (calendar-gregorian-from-absolute day))
8226 "Gregorian: " (calendar-date-string date) "\n"
8227 "ISO: " (calendar-iso-date-string date) "\n"
8228 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8229 "Julian: " (calendar-julian-date-string date) "\n"
8230 "Astron. JD: " (calendar-astro-date-string date)
8231 " (Julian date number at noon UTC)\n"
8232 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8233 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8234 "French: " (calendar-french-date-string date) "\n"
8235 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8236 "Mayan: " (calendar-mayan-date-string date) "\n"
8237 "Coptic: " (calendar-coptic-date-string date) "\n"
8238 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8239 "Persian: " (calendar-persian-date-string date) "\n"
8240 "Chinese: " (calendar-chinese-date-string date) "\n"))
8241 (with-output-to-temp-buffer "*Dates*"
8243 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8247 (defvar org-agenda-bulk-marked-entries nil
8248 "List of markers that refer to marked entries in the agenda.")
8250 (defun org-agenda-bulk-marked-p ()
8251 (eq (get-char-property (point-at-bol) 'type)
8252 'org-marked-entry-overlay))
8254 (defun org-agenda-bulk-mark (&optional arg)
8255 "Mark the entry at point for future bulk action."
8257 (dotimes (i (max arg 1))
8258 (unless (org-get-at-bol 'org-agenda-diary-link)
8259 (let* ((m (org-get-at-bol 'org-hd-marker))
8261 (unless (org-agenda-bulk-marked-p)
8262 (unless m (error "Nothing to mark at point"))
8263 (push m org-agenda-bulk-marked-entries)
8264 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8265 (org-overlay-display ov "> "
8266 (org-get-todo-face "TODO")
8268 (overlay-put ov 'type 'org-marked-entry-overlay))
8269 (beginning-of-line 2)
8270 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8271 (beginning-of-line 2))
8272 (message "%d entries marked for bulk action"
8273 (length org-agenda-bulk-marked-entries))))))
8275 (defun org-agenda-bulk-mark-regexp (regexp)
8276 "Mark entries match REGEXP."
8277 (interactive "sMark entries matching regexp: ")
8278 (let (entries-marked)
8280 (goto-char (point-min))
8281 (goto-char (next-single-property-change (point) 'txt))
8282 (while (re-search-forward regexp nil t)
8283 (when (string-match regexp (get-text-property (point) 'txt))
8284 (setq entries-marked (+ entries-marked 1))
8285 (call-interactively 'org-agenda-bulk-mark))))
8286 (if (not entries-marked)
8287 (message "No entry matching this regexp."))))
8289 (defun org-agenda-bulk-unmark ()
8290 "Unmark the entry at point for future bulk action."
8292 (when (org-agenda-bulk-marked-p)
8293 (org-agenda-bulk-remove-overlays
8294 (point-at-bol) (+ 2 (point-at-bol)))
8295 (setq org-agenda-bulk-marked-entries
8296 (delete (org-get-at-bol 'org-hd-marker)
8297 org-agenda-bulk-marked-entries)))
8298 (beginning-of-line 2)
8299 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8300 (beginning-of-line 2))
8301 (message "%d entries marked for bulk action"
8302 (length org-agenda-bulk-marked-entries)))
8304 (defun org-agenda-bulk-toggle ()
8305 "Toggle marking the entry at point for bulk action."
8307 (if (org-agenda-bulk-marked-p)
8308 (org-agenda-bulk-unmark)
8309 (org-agenda-bulk-mark)))
8311 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8312 "Remove the mark overlays between BEG and END in the agenda buffer.
8313 BEG and END default to the buffer limits.
8315 This only removes the overlays, it does not remove the markers
8316 from the list in `org-agenda-bulk-marked-entries'."
8319 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8320 (delete-overlay ov)))
8321 (overlays-in (or beg (point-min)) (or end (point-max)))))
8323 (defun org-agenda-bulk-remove-all-marks ()
8324 "Remove all marks in the agenda buffer.
8325 This will remove the markers, and the overlays."
8327 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8328 (setq org-agenda-bulk-marked-entries nil)
8329 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8331 (defun org-agenda-bulk-action (&optional arg)
8332 "Execute an remote-editing action on all marked entries.
8333 The prefix arg is passed through to the command if possible."
8335 ;; Make sure we have markers, and only valid ones
8336 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8339 (unless (and (markerp m)
8341 (buffer-live-p (marker-buffer m))
8342 (marker-position m))
8343 (error "Marker %s for bulk command is invalid" m)))
8344 org-agenda-bulk-marked-entries)
8346 ;; Prompt for the bulk command
8347 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8348 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8349 (when org-agenda-bulk-custom-functions
8350 (concat " Custom: ["
8351 (mapconcat (lambda(f) (char-to-string (car f)))
8352 org-agenda-bulk-custom-functions "")
8354 (let* ((action (read-char-exclusive))
8355 (org-log-refile (if org-log-refile 'time nil))
8356 (entries (reverse org-agenda-bulk-marked-entries))
8358 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8361 (setq cmd '(org-agenda-archive)))
8364 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8366 ((member action '(?r ?w))
8367 (setq rfloc (org-refile-get-location
8369 (marker-buffer (car org-agenda-bulk-marked-entries))
8370 org-refile-allow-creating-parent-nodes))
8372 (setcar (nthcdr 3 rfloc)
8373 (move-marker (make-marker) (nth 3 rfloc)
8374 (or (get-file-buffer (nth 1 rfloc))
8375 (find-buffer-visiting (nth 1 rfloc))
8376 (error "This should not happen")))))
8378 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8382 (setq state (org-icompleting-read
8384 (with-current-buffer (marker-buffer (car entries))
8385 (mapcar 'list org-todo-keywords-1))))
8386 (setq cmd `(let ((org-inhibit-blocking t)
8387 (org-inhibit-logging 'note))
8388 (org-agenda-todo ,state))))
8390 ((memq action '(?- ?+))
8391 (setq tag (org-icompleting-read
8392 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8393 (with-current-buffer (marker-buffer (car entries))
8396 (if (stringp (car x)) x)) org-tag-alist)))))
8397 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8399 ((memq action '(?s ?d))
8400 (let* ((date (unless arg
8403 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8404 (ans (if arg nil org-read-date-final-answer))
8405 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8406 (setq cmd `(let* ((bound (fboundp 'read-string))
8407 (old (and bound (symbol-function 'read-string))))
8410 (fset 'read-string (lambda (&rest ignore) ,ans))
8413 (fset 'read-string old)
8414 (fmakunbound 'read-string)))))))
8417 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8418 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8419 (let ((days (read-number
8420 (format "Scatter tasks across how many %sdays: "
8421 (if arg "week" "")) 7)))
8423 `(let ((distance (1+ (random ,days))))
8425 (let ((dist distance)
8427 (calendar-day-of-week
8428 (calendar-gregorian-from-absolute (org-today)))))
8429 (dotimes (i (1+ dist))
8430 (while (member day-of-week org-agenda-weekend-days)
8433 (if (= day-of-week 7)
8434 (setq day-of-week 0)))
8436 (if (= day-of-week 7)
8437 (setq day-of-week 0)))))
8438 ;; silently fail when try to replan a sexp entry
8440 (let* ((date (calendar-gregorian-from-absolute
8441 (+ (org-today) distance)))
8442 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8444 (org-agenda-schedule nil time))
8447 ((assoc action org-agenda-bulk-custom-functions)
8448 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8452 (setq cmd (list (intern
8453 (org-icompleting-read "Function: "
8454 obarray 'fboundp t nil nil)))))
8456 (t (error "Invalid bulk action")))
8458 ;; Sort the markers, to make sure that parents are handled before children
8459 (setq entries (sort entries
8462 ((equal (marker-buffer a) (marker-buffer b))
8463 (< (marker-position a) (marker-position b)))
8465 (string< (buffer-name (marker-buffer a))
8466 (buffer-name (marker-buffer b))))))))
8468 ;; Now loop over all markers and apply cmd
8469 (while (setq e (pop entries))
8470 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8472 (progn (message "Skipping removed entry at %s" e)
8473 (setq cntskip (1+ cntskip)))
8475 (let (org-loop-over-headlines-in-active-region)
8477 (setq org-agenda-bulk-marked-entries
8478 (delete e org-agenda-bulk-marked-entries))
8479 (setq cnt (1+ cnt))))
8480 (setq org-agenda-bulk-marked-entries nil)
8481 (org-agenda-bulk-remove-all-marks)
8482 (when redo-at-end (org-agenda-redo))
8483 (message "Acted on %d entries%s"
8487 (format ", skipped %d (disappeared before their turn)"
8492 (defun org-agenda-show-the-flagging-note ()
8493 "Display the flagging note in the other window.
8494 When called a second time in direct sequence, offer to remove the FLAGGING
8495 tag and (if present) the flagging note."
8497 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8498 (win (selected-window))
8499 note heading newhead)
8501 (error "No linked entry at point"))
8502 (if (and (eq this-command last-command)
8503 (y-or-n-p "Unflag and remove any flagging note? "))
8505 (org-agenda-remove-flag hdmarker)
8506 (let ((win (get-buffer-window "*Flagging Note*")))
8507 (and win (delete-window win)))
8508 (message "Entry unflagged"))
8509 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8511 (error "No flagging note"))
8513 (org-switch-to-buffer-other-window "*Flagging Note*")
8516 (goto-char (point-min))
8517 (while (re-search-forward "\\\\n" nil t)
8518 (replace-match "\n" t t))
8519 (goto-char (point-min))
8521 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8523 (defun org-agenda-remove-flag (marker)
8524 "Remove the FLAGGED tag and any flagging note in the entry."
8526 (org-with-point-at marker
8527 (org-toggle-tag "FLAGGED" 'off)
8528 (org-entry-delete nil "THEFLAGGINGNOTE")
8529 (setq newhead (org-get-heading)))
8530 (org-agenda-change-all-lines newhead marker)
8531 (message "Entry unflagged")))
8533 (defun org-agenda-get-any-marker (&optional pos)
8534 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8535 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8537 ;;; Appointment reminders
8539 (defvar appt-time-msg-list)
8542 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8543 "Activate appointments found in `org-agenda-files'.
8544 With a \\[universal-argument] prefix, refresh the list of
8547 If FILTER is t, interactively prompt the user for a regular
8548 expression, and filter out entries that don't match it.
8550 If FILTER is a string, use this string as a regular expression
8551 for filtering entries out.
8553 If FILTER is a function, filter out entries against which
8554 calling the function returns nil. This function takes one
8555 argument: an entry from `org-agenda-get-day-entries'.
8557 FILTER can also be an alist with the car of each cell being
8558 either 'headline or 'category. For example:
8560 '((headline \"IMPORTANT\")
8561 (category \"Work\"))
8563 will only add headlines containing IMPORTANT or headlines
8564 belonging to the \"Work\" category.
8566 ARGS are symbols indicating what kind of entries to consider.
8567 By default `org-agenda-to-appt' will use :deadline, :scheduled
8568 and :timestamp entries. See the docstring of `org-diary' for
8569 details and examples."
8571 (if refresh (setq appt-time-msg-list nil))
8573 (setq filter (read-from-minibuffer "Regexp filter: ")))
8574 (let* ((cnt 0) ; count added events
8575 (scope (or args '(:deadline :scheduled :timestamp)))
8576 (org-agenda-new-buffers nil)
8577 (org-deadline-warning-days 0)
8578 ;; Do not use `org-today' here because appt only takes
8579 ;; time and without date as argument, so it may pass wrong
8580 ;; information otherwise
8581 (today (org-date-to-gregorian
8582 (time-to-days (current-time))))
8583 (org-agenda-restrict nil)
8584 (files (org-agenda-files 'unrestricted)) entries file)
8585 ;; Get all entries which may contain an appt
8586 (org-prepare-agenda-buffers files)
8587 (while (setq file (pop files))
8591 (apply 'org-agenda-get-day-entries
8592 file today scope)))))
8593 ;; Map thru entries and find if we should filter them out
8596 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8597 (cat (get-text-property 1 'org-category x))
8598 (tod (get-text-property 1 'time-of-day x))
8599 (ok (or (null filter)
8600 (and (stringp filter) (string-match filter evt))
8601 (and (functionp filter) (funcall filter x))
8603 (let ((cat-filter (cadr (assoc 'category filter)))
8604 (evt-filter (cadr (assoc 'headline filter))))
8605 (or (and (stringp cat-filter)
8606 (string-match cat-filter cat))
8607 (and (stringp evt-filter)
8608 (string-match evt-filter evt))))))))
8609 ;; FIXME: Shall we remove text-properties for the appt text?
8610 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8612 (setq tod (concat "00" (number-to-string tod))
8613 tod (when (string-match
8614 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8615 (concat (match-string 1 tod) ":"
8616 (match-string 2 tod))))
8618 (setq cnt (1+ cnt))))) entries)
8619 (org-release-buffers org-agenda-new-buffers)
8621 (message "No event to add")
8622 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8624 (defun org-agenda-todayp (date)
8625 "Does DATE mean today, when considering `org-extend-today-until'?"
8626 (let ((today (org-today))
8627 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8631 (defun org-agenda-todo-yesterday (&optional arg)
8632 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
8634 (let* ((hour (third (decode-time
8635 (org-current-time))))
8636 (org-extend-today-until (1+ hour)))
8637 (org-agenda-todo arg)))
8639 (provide 'org-agenda)
8641 ;;; org-agenda.el ends here