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 conveniant 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 org-datetree-find-date-create
"org-datetree"
70 (date &optional keep-restriction
))
71 (declare-function org-columns-quit
"org-colview" ())
72 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
73 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
74 (declare-function org-habit-insert-consistency-graphs
75 "org-habit" (&optional line
))
76 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
77 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
78 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
79 (declare-function org-pop-to-buffer-same-window
"org-compat"
80 (&optional buffer-or-name norecord label
))
81 (declare-function org-duration-string-to-minutes
"org-clock" (s))
82 (declare-function org-hh
:mm-string-to-minutes
"org-clock" (s))
83 (declare-function org-minutes-to-hh
:mm-string
"org-clock" (m))
85 (defvar calendar-mode-map
)
86 (defvar org-clock-current-task
) ; defined in org-clock.el
87 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
88 (defvar org-habit-show-habits
)
89 (defvar org-habit-show-habits-only-for-today
)
91 ;; Defined somewhere in this file, but used before definition.
92 (defvar org-agenda-buffer-name
)
93 (defvar org-agenda-overriding-header
)
94 (defvar org-agenda-title-append nil
)
97 (defvar org-agenda-undo-list
)
98 (defvar org-agenda-pending-undo-list
)
99 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
101 (defcustom org-agenda-confirm-kill
1
102 "When set, remote killing from the agenda buffer needs confirmation.
103 When t, a confirmation is always needed. When a number N, confirmation is
104 only needed when the text to be killed contains more than N non-white lines."
107 (const :tag
"Never" nil
)
108 (const :tag
"Always" t
)
109 (integer :tag
"When more than N lines")))
111 (defcustom org-agenda-compact-blocks nil
112 "Non-nil means make the block agenda more compact.
113 This is done globally by leaving out lines like the agenda span
114 name and week number or the separator lines."
118 (defcustom org-agenda-block-separator ?
=
119 "The separator between blocks in the agenda.
120 If this is a string, it will be used as the separator, with a newline added.
121 If it is a character, it will be repeated to fill the window width.
122 If nil the separator is disabled. In `org-agenda-custom-commands' this
123 addresses the separator between the current and the previous block."
126 (const :tag
"Disabled" nil
)
130 (defgroup org-agenda-export nil
131 "Options concerning exporting agenda views in Org-mode."
132 :tag
"Org Agenda Export"
135 (defcustom org-agenda-with-colors t
136 "Non-nil means use colors in agenda views."
137 :group
'org-agenda-export
140 (defcustom org-agenda-exporter-settings nil
141 "Alist of variable/value pairs that should be active during agenda export.
142 This is a good place to set options for ps-print and for htmlize.
143 Note that the way this is implemented, the values will be evaluated
144 before assigned to the variables. So make sure to quote values you do
145 *not* want evaluated, for example
147 (setq org-agenda-exporter-settings
148 '((ps-print-color-p 'black-white)))"
149 :group
'org-agenda-export
153 (sexp :tag
"Value"))))
155 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
156 "Hook run in temporary buffer before writing it to an export file.
157 A useful function is `org-agenda-add-entry-text'."
158 :group
'org-agenda-export
160 :options
'(org-agenda-add-entry-text))
162 (defcustom org-agenda-add-entry-text-maxlines
0
163 "Maximum number of entry text lines to be added to agenda.
164 This is only relevant when `org-agenda-add-entry-text' is part of
165 `org-agenda-before-write-hook', which it is by default.
166 When this is 0, nothing will happen. When it is greater than 0, it
167 specifies the maximum number of lines that will be added for each entry
168 that is listed in the agenda view.
170 Note that this variable is not used during display, only when exporting
171 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
172 and `org-agenda-entry-text-maxlines'."
176 (defcustom org-agenda-add-entry-text-descriptive-links t
177 "Non-nil means export org-links as descriptive links in agenda added text.
178 This variable applies to the text added to the agenda when
179 `org-agenda-add-entry-text-maxlines' is larger than 0.
180 When this variable nil, the URL will (also) be shown."
184 (defcustom org-agenda-export-html-style
""
185 "The style specification for exported HTML Agenda files.
186 If this variable contains a string, it will replace the default <style>
187 section as produced by `htmlize'.
188 Since there are different ways of setting style information, this variable
189 needs to contain the full HTML structure to provide a style, including the
190 surrounding HTML tags. The style specifications should include definitions
191 the fonts used by the agenda, here is an example:
193 <style type=\"text/css\">
194 p { font-weight: normal; color: gray; }
195 .org-agenda-structure {
210 .title { text-align: center; }
211 .todo, .deadline { color: red; }
212 .done { color: green; }
215 or, if you want to keep the style in a file,
217 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
219 As the value of this option simply gets inserted into the HTML <head> header,
220 you can \"misuse\" it to also add other text to the header. However,
221 <style>...</style> is required, if not present the variable will be ignored."
222 :group
'org-agenda-export
223 :group
'org-export-html
226 (defcustom org-agenda-persistent-filter nil
227 "When set, keep filters from one agenda view to the next."
231 (defgroup org-agenda-custom-commands nil
232 "Options concerning agenda views in Org-mode."
233 :tag
"Org Agenda Custom Commands"
236 (defconst org-sorting-choice
238 (const time-up
) (const time-down
)
239 (const category-keep
) (const category-up
) (const category-down
)
240 (const tag-down
) (const tag-up
)
241 (const priority-up
) (const priority-down
)
242 (const todo-state-up
) (const todo-state-down
)
243 (const effort-up
) (const effort-down
)
244 (const habit-up
) (const habit-down
)
245 (const alpha-up
) (const alpha-down
)
246 (const user-defined-up
) (const user-defined-down
))
249 (defconst org-agenda-custom-commands-local-options
250 `(repeat :tag
"Local settings for this command. Remember to quote values"
251 (choice :tag
"Setting"
252 (list :tag
"Heading for this block"
253 (const org-agenda-overriding-header
)
254 (string :tag
"Headline"))
255 (list :tag
"Files to be searched"
256 (const org-agenda-files
)
258 (const :format
"" quote
)
260 (list :tag
"Sorting strategy"
261 (const org-agenda-sorting-strategy
)
263 (const :format
"" quote
)
265 ,org-sorting-choice
)))
266 (list :tag
"Prefix format"
267 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
269 (list :tag
"Number of days in agenda"
270 (const org-agenda-span
)
271 (choice (const :tag
"Day" 'day
)
272 (const :tag
"Week" 'week
)
273 (const :tag
"Month" 'month
)
274 (const :tag
"Year" 'year
)
275 (integer :tag
"Custom")))
276 (list :tag
"Fixed starting date"
277 (const org-agenda-start-day
)
278 (string :value
"2007-11-01"))
279 (list :tag
"Start on day of week"
280 (const org-agenda-start-on-weekday
)
282 (const :tag
"Today" nil
)
283 (integer :tag
"Weekday No.")))
284 (list :tag
"Include data from diary"
285 (const org-agenda-include-diary
)
287 (list :tag
"Deadline Warning days"
288 (const org-deadline-warning-days
)
290 (list :tag
"Tags filter preset"
291 (const org-agenda-filter-preset
)
293 (const :format
"" quote
)
295 (string :tag
"+tag or -tag"))))
296 (list :tag
"Set daily/weekly entry types"
297 (const org-agenda-entry-types
)
298 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
303 (list :tag
"Standard skipping condition"
304 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
305 (const org-agenda-skip-function
)
307 (const :format
"" quote
)
310 :tag
"Skipping range"
311 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
312 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
313 (repeat :inline t
:tag
"Conditions for skipping"
315 :tag
"Condition type"
316 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
317 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
318 (list :tag
"TODO state is" :inline t
321 (const :tag
"any not-done state" 'todo
)
322 (const :tag
"any done state" 'done
)
323 (const :tag
"any state" 'any
)
324 (list :tag
"Keyword list"
325 (const :format
"" quote
)
326 (repeat (string :tag
"Keyword")))))
327 (list :tag
"TODO state is not" :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 (const :tag
"scheduled" 'scheduled
)
337 (const :tag
"not scheduled" 'notscheduled
)
338 (const :tag
"deadline" 'deadline
)
339 (const :tag
"no deadline" 'notdeadline
)
340 (const :tag
"timestamp" 'timestamp
)
341 (const :tag
"no timestamp" 'nottimestamp
))))))
342 (list :tag
"Non-standard skipping condition"
343 :value
(org-agenda-skip-function)
344 (const org-agenda-skip-function
)
345 (sexp :tag
"Function or form (quoted!)"))
346 (list :tag
"Any variable"
347 (variable :tag
"Variable")
348 (sexp :tag
"Value (sexp)"))))
349 "Selection of examples for agenda command settings.
350 This will be spliced into the custom type of
351 `org-agenda-custom-commands'.")
354 (defcustom org-agenda-custom-commands
'(("n" "Agenda and all TODO's"
355 ((agenda "") (alltodo))))
356 "Custom commands for the agenda.
357 These commands will be offered on the splash screen displayed by the
358 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
360 (key desc type match settings files)
362 key The key (one or more characters as a string) to be associated
364 desc A description of the command, when omitted or nil, a default
365 description is built using MATCH.
366 type The command type, any of the following symbols:
367 agenda The daily/weekly agenda.
368 todo Entries with a specific TODO keyword, in all agenda files.
369 search Entries containing search words entry or headline.
370 tags Tags/Property/TODO match in all agenda files.
371 tags-todo Tags/P/T match in all agenda files, TODO entries only.
372 todo-tree Sparse tree of specific TODO keyword in *current* file.
373 tags-tree Sparse tree with all tags matches in *current* file.
374 occur-tree Occur sparse tree for *current* file.
375 ... A user-defined function.
376 match What to search for:
377 - a single keyword for TODO keyword searches
378 - a tags match expression for tags searches
379 - a word search expression for text searches.
380 - a regular expression for occur searches
381 For all other commands, this should be the empty string.
382 settings A list of option settings, similar to that in a let form, so like
383 this: ((opt1 val1) (opt2 val2) ...). The values will be
384 evaluated at the moment of execution, so quote them when needed.
385 files A list of files file to write the produced agenda buffer to
386 with the command `org-store-agenda-views'.
387 If a file name ends in \".html\", an HTML version of the buffer
388 is written out. If it ends in \".ps\", a postscript version is
389 produced. Otherwise, only the plain text is written to the file.
391 You can also define a set of commands, to create a composite agenda buffer.
392 In this case, an entry looks like this:
394 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
398 desc A description string to be displayed in the dispatcher menu.
399 cmd An agenda command, similar to the above. However, tree commands
400 are no allowed, but instead you can get agenda and global todo list.
401 So valid commands for a set are:
402 (agenda \"\" settings)
403 (alltodo \"\" settings)
404 (stuck \"\" settings)
405 (todo \"match\" settings files)
406 (search \"match\" settings files)
407 (tags \"match\" settings files)
408 (tags-todo \"match\" settings files)
410 Each command can carry a list of options, and another set of options can be
411 given for the whole set of commands. Individual command options take
412 precedence over the general options.
414 When using several characters as key to a command, the first characters
415 are prefix commands. For the dispatcher to display useful information, you
416 should provide a description for the prefix, like
418 (setq org-agenda-custom-commands
419 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
420 (\"hl\" tags \"+HOME+Lisa\")
421 (\"hp\" tags \"+HOME+Peter\")
422 (\"hk\" tags \"+HOME+Kim\")))"
423 :group
'org-agenda-custom-commands
425 (choice :value
("x" "Describe command here" tags
"" nil
)
426 (list :tag
"Single command"
427 (string :tag
"Access Key(s) ")
428 (option (string :tag
"Description"))
430 (const :tag
"Agenda" agenda
)
431 (const :tag
"TODO list" alltodo
)
432 (const :tag
"Search words" search
)
433 (const :tag
"Stuck projects" stuck
)
434 (const :tag
"Tags/Property match (all agenda files)" tags
)
435 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
436 (const :tag
"TODO keyword search (all agenda files)" todo
)
437 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
438 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
439 (const :tag
"Occur tree (current buffer)" occur-tree
)
440 (sexp :tag
"Other, user-defined function"))
441 (string :tag
"Match (only for some commands)")
442 ,org-agenda-custom-commands-local-options
443 (option (repeat :tag
"Export" (file :tag
"Export to"))))
444 (list :tag
"Command series, all agenda files"
445 (string :tag
"Access Key(s)")
446 (string :tag
"Description ")
447 (repeat :tag
"Component"
450 (const :format
"" agenda
)
451 (const :tag
"" :format
"" "")
452 ,org-agenda-custom-commands-local-options
)
453 (list :tag
"TODO list (all keywords)"
454 (const :format
"" alltodo
)
455 (const :tag
"" :format
"" "")
456 ,org-agenda-custom-commands-local-options
)
457 (list :tag
"Search words"
458 (const :format
"" search
)
459 (string :tag
"Match")
460 ,org-agenda-custom-commands-local-options
)
461 (list :tag
"Stuck projects"
462 (const :format
"" stuck
)
463 (const :tag
"" :format
"" "")
464 ,org-agenda-custom-commands-local-options
)
465 (list :tag
"Tags search"
466 (const :format
"" tags
)
467 (string :tag
"Match")
468 ,org-agenda-custom-commands-local-options
)
469 (list :tag
"Tags search, TODO entries only"
470 (const :format
"" tags-todo
)
471 (string :tag
"Match")
472 ,org-agenda-custom-commands-local-options
)
473 (list :tag
"TODO keyword search"
474 (const :format
"" todo
)
475 (string :tag
"Match")
476 ,org-agenda-custom-commands-local-options
)
477 (list :tag
"Other, user-defined function"
478 (symbol :tag
"function")
479 (string :tag
"Match")
480 ,org-agenda-custom-commands-local-options
)))
482 (repeat :tag
"Settings for entire command set"
483 (list (variable :tag
"Any variable")
484 (sexp :tag
"Value")))
485 (option (repeat :tag
"Export" (file :tag
"Export to"))))
486 (cons :tag
"Prefix key documentation"
487 (string :tag
"Access Key(s)")
488 (string :tag
"Description ")))))
490 (defcustom org-agenda-query-register ?o
491 "The register holding the current query string.
492 The purpose of this is that if you construct a query string interactively,
493 you can then use it to define a custom command."
494 :group
'org-agenda-custom-commands
497 (defcustom org-stuck-projects
498 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
499 "How to identify stuck projects.
500 This is a list of four items:
501 1. A tags/todo/property matcher string that is used to identify a project.
502 See the manual for a description of tag and property searches.
503 The entire tree below a headline matched by this is considered one project.
504 2. A list of TODO keywords identifying non-stuck projects.
505 If the project subtree contains any headline with one of these todo
506 keywords, the project is considered to be not stuck. If you specify
507 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
508 3. A list of tags identifying non-stuck projects.
509 If the project subtree contains any headline with one of these tags,
510 the project is considered to be not stuck. If you specify \"*\" as
511 a tag, any tag will mark the project unstuck. Note that this is about
512 the explicit presence of a tag somewhere in the subtree, inherited
513 tags to not count here. If inherited tags make a project not stuck,
514 use \"-TAG\" in the tags part of the matcher under (1.) above.
515 4. An arbitrary regular expression matching non-stuck projects.
517 If the project turns out to be not stuck, search continues also in the
518 subtree to see if any of the subtasks have project status.
520 See also the variable `org-tags-match-list-sublevels' which applies
521 to projects matched by this search as well.
523 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
524 or `C-c a #' to produce the list."
525 :group
'org-agenda-custom-commands
527 (string :tag
"Tags/TODO match to identify a project")
528 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
529 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
530 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
532 (defcustom org-agenda-filter-effort-default-operator
"<"
533 "The default operator for effort estimate filtering.
534 If you select an effort estimate limit without first pressing an operator,
535 this one will be used."
536 :group
'org-agenda-custom-commands
537 :type
'(choice (const :tag
"less or equal" "<")
538 (const :tag
"greater or equal"">")
539 (const :tag
"equal" "=")))
541 (defgroup org-agenda-skip nil
542 "Options concerning skipping parts of agenda files."
543 :tag
"Org Agenda Skip"
546 (defcustom org-agenda-skip-function-global nil
547 "Function to be called at each match during agenda construction.
548 If this function returns nil, the current match should not be skipped.
549 If the function decided to skip an agenda match, is must return the
550 buffer position from which the search should be continued.
551 This may also be a Lisp form, which will be evaluated.
553 This variable will be applied to every agenda match, including
554 tags/property searches and TODO lists. So try to make the test function
555 do its checking as efficiently as possible. To implement a skipping
556 condition just for specific agenda commands, use the variable
557 `org-agenda-skip-function' which can be set in the options section
558 of custom agenda commands."
559 :group
'org-agenda-skip
562 (defgroup org-agenda-daily
/weekly nil
563 "Options concerning the daily/weekly agenda."
564 :tag
"Org Agenda Daily/Weekly"
566 (defgroup org-agenda-todo-list nil
567 "Options concerning the global todo list agenda view."
568 :tag
"Org Agenda Todo List"
570 (defgroup org-agenda-match-view nil
571 "Options concerning the general tags/property/todo match agenda view."
572 :tag
"Org Agenda Match View"
574 (defgroup org-agenda-search-view nil
575 "Options concerning the general tags/property/todo match agenda view."
576 :tag
"Org Agenda Match View"
579 (defvar org-agenda-archives-mode nil
580 "Non-nil means the agenda will include archived items.
581 If this is the symbol `trees', trees in the selected agenda scope
582 that are marked with the ARCHIVE tag will be included anyway. When this is
583 t, also all archive files associated with the current selection of agenda
584 files will be included.")
586 (defcustom org-agenda-skip-comment-trees t
587 "Non-nil means skip trees that start with the COMMENT keyword.
588 When nil, these trees are also scanned by agenda commands."
589 :group
'org-agenda-skip
592 (defcustom org-agenda-todo-list-sublevels t
593 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
594 When nil, the sublevels of a TODO entry are not checked, resulting in
595 potentially much shorter TODO lists."
596 :group
'org-agenda-skip
597 :group
'org-agenda-todo-list
600 (defcustom org-agenda-todo-ignore-with-date nil
601 "Non-nil means don't show entries with a date in the global todo list.
602 You can use this if you prefer to mark mere appointments with a TODO keyword,
603 but don't want them to show up in the TODO list.
604 When this is set, it also covers deadlines and scheduled items, the settings
605 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
607 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
608 :group
'org-agenda-skip
609 :group
'org-agenda-todo-list
612 (defcustom org-agenda-todo-ignore-timestamp nil
613 "Non-nil means don't show entries with a timestamp.
614 This applies when creating the global todo list.
617 past Don't show entries for today or in the past.
619 future Don't show entries with a timestamp in the future.
620 The idea behind this is that if it has a future
621 timestamp, you don't want to think about it until the
624 all Don't show any entries with a timestamp in the global todo list.
625 The idea behind this is that by setting a timestamp, you
626 have already \"taken care\" of this item.
628 This variable can also have an integer as a value. If positive (N),
629 todos with a timestamp N or more days in the future will be ignored. If
630 negative (-N), todos with a timestamp N or more days in the past will be
631 ignored. If 0, todos with a timestamp either today or in the future will
632 be ignored. For example, a value of -1 will exclude todos with a
633 timestamp in the past (yesterday or earlier), while a value of 7 will
634 exclude todos with a timestamp a week or more in the future.
636 See also `org-agenda-todo-ignore-with-date'.
637 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
638 to make his option also apply to the tags-todo list."
639 :group
'org-agenda-skip
640 :group
'org-agenda-todo-list
642 (const :tag
"Ignore future timestamp todos" future
)
643 (const :tag
"Ignore past or present timestamp todos" past
)
644 (const :tag
"Ignore all timestamp todos" all
)
645 (const :tag
"Show timestamp todos" nil
)
646 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
648 (defcustom org-agenda-todo-ignore-scheduled nil
649 "Non-nil means, ignore some scheduled TODO items when making TODO list.
650 This applies when creating the global todo list.
653 past Don't show entries scheduled today or in the past.
655 future Don't show entries scheduled in the future.
656 The idea behind this is that by scheduling it, you don't want to
657 think about it until the scheduled date.
659 all Don't show any scheduled entries in the global todo list.
660 The idea behind this is that by scheduling it, you have already
661 \"taken care\" of this item.
663 t Same as `all', for backward compatibility.
665 This variable can also have an integer as a value. See
666 `org-agenda-todo-ignore-timestamp' for more details.
668 See also `org-agenda-todo-ignore-with-date'.
669 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
670 to make his option also apply to the tags-todo list."
671 :group
'org-agenda-skip
672 :group
'org-agenda-todo-list
674 (const :tag
"Ignore future-scheduled todos" future
)
675 (const :tag
"Ignore past- or present-scheduled todos" past
)
676 (const :tag
"Ignore all scheduled todos" all
)
677 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
678 (const :tag
"Show scheduled todos" nil
)
679 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
681 (defcustom org-agenda-todo-ignore-deadlines nil
682 "Non-nil means ignore some deadlined TODO items when making TODO list.
683 There are different motivations for using different values, please think
684 carefully when configuring this variable.
686 This applies when creating the global todo list.
689 near Don't show near deadline entries. A deadline is near when it is
690 closer than `org-deadline-warning-days' days. The idea behind this
691 is that such items will appear in the agenda anyway.
693 far Don't show TODO entries where a deadline has been defined, but
694 the deadline is not near. This is useful if you don't want to
695 use the todo list to figure out what to do now.
697 past Don't show entries with a deadline timestamp for today or in the past.
699 future Don't show entries with a deadline timestamp in the future, not even
700 when they become `near' ones. Use it with caution.
702 all Ignore all TODO entries that do have a deadline.
704 t Same as `near', for backward compatibility.
706 This variable can also have an integer as a value. See
707 `org-agenda-todo-ignore-timestamp' for more details.
709 See also `org-agenda-todo-ignore-with-date'.
710 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
711 to make his option also apply to the tags-todo list."
712 :group
'org-agenda-skip
713 :group
'org-agenda-todo-list
715 (const :tag
"Ignore near deadlines" near
)
716 (const :tag
"Ignore near deadlines (compatibility)" t
)
717 (const :tag
"Ignore far deadlines" far
)
718 (const :tag
"Ignore all TODOs with a deadlines" all
)
719 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
720 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
722 (defcustom org-agenda-tags-todo-honor-ignore-options nil
723 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
725 `org-agenda-todo-ignore-with-date',
726 `org-agenda-todo-ignore-timestamp',
727 `org-agenda-todo-ignore-scheduled',
728 `org-agenda-todo-ignore-deadlines'
729 make the global TODO list skip entries that have time stamps of certain
730 kinds. If this option is set, the same options will also apply for the
731 tags-todo search, which is the general tags/property matcher
732 restricted to unfinished TODO entries only."
733 :group
'org-agenda-skip
734 :group
'org-agenda-todo-list
735 :group
'org-agenda-match-view
738 (defcustom org-agenda-skip-scheduled-if-done nil
739 "Non-nil means don't show scheduled items in agenda when they are done.
740 This is relevant for the daily/weekly agenda, not for the TODO list. And
741 it applies only to the actual date of the scheduling. Warnings about
742 an item with a past scheduling dates are always turned off when the item
744 :group
'org-agenda-skip
745 :group
'org-agenda-daily
/weekly
748 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
749 "Non-nil means skip scheduling line if same entry shows because of deadline.
750 In the agenda of today, an entry can show up multiple times because
751 it is both scheduled and has a nearby deadline, and maybe a plain time
753 When this variable is t, then only the deadline is shown and the fact that
754 the entry is scheduled today or was scheduled previously is not shown.
755 When this variable is nil, the entry will be shown several times. When
756 the variable is the symbol `not-today', then skip scheduled previously,
757 but not scheduled today."
758 :group
'org-agenda-skip
759 :group
'org-agenda-daily
/weekly
761 (const :tag
"Never" nil
)
762 (const :tag
"Always" t
)
763 (const :tag
"Not when scheduled today" not-today
)))
765 (defcustom org-agenda-skip-deadline-if-done nil
766 "Non-nil means don't show deadlines when the corresponding item is done.
767 When nil, the deadline is still shown and should give you a happy feeling.
768 This is relevant for the daily/weekly agenda. And it applied only to the
769 actually date of the deadline. Warnings about approaching and past-due
770 deadlines are always turned off when the item is DONE."
771 :group
'org-agenda-skip
772 :group
'org-agenda-daily
/weekly
775 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
776 "Non-nil means skip deadline prewarning when entry is also scheduled.
777 This will apply on all days where a prewarning for the deadline would
778 be shown, but not at the day when the entry is actually due. On that day,
779 the deadline will be shown anyway.
780 This variable may be set to nil, t, or a number which will then give
781 the number of days before the actual deadline when the prewarnings
783 This can be used in a workflow where the first showing of the deadline will
784 trigger you to schedule it, and then you don't want to be reminded of it
785 because you will take care of it on the day when scheduled."
786 :group
'org-agenda-skip
787 :group
'org-agenda-daily
/weekly
789 (const :tag
"Alwas show prewarning" nil
)
790 (const :tag
"Remove prewarning if entry is scheduled" t
)
791 (integer :tag
"Restart prewarning N days before deadline")))
793 (defcustom org-agenda-skip-additional-timestamps-same-entry t
794 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
795 When non-nil, after the search for timestamps has matched once in an
796 entry, the rest of the entry will not be searched."
797 :group
'org-agenda-skip
800 (defcustom org-agenda-skip-timestamp-if-done nil
801 "Non-nil means don't select item by timestamp or -range if it is DONE."
802 :group
'org-agenda-skip
803 :group
'org-agenda-daily
/weekly
806 (defcustom org-agenda-dim-blocked-tasks t
807 "Non-nil means dim blocked tasks in the agenda display.
808 This causes some overhead during agenda construction, but if you
809 have turned on `org-enforce-todo-dependencies',
810 `org-enforce-todo-checkbox-dependencies', or any other blocking
811 mechanism, this will create useful feedback in the agenda.
813 Instead of t, this variable can also have the value `invisible'.
814 Then blocked tasks will be invisible and only become visible when
815 they become unblocked. An exemption to this behavior is when a task is
816 blocked because of unchecked checkboxes below it. Since checkboxes do
817 not show up in the agenda views, making this task invisible you remove any
818 trace from agenda views that there is something to do. Therefore, a task
819 that is blocked because of checkboxes will never be made invisible, it
820 will only be dimmed."
821 :group
'org-agenda-daily
/weekly
822 :group
'org-agenda-todo-list
824 (const :tag
"Do not dim" nil
)
825 (const :tag
"Dim to a grey face" t
)
826 (const :tag
"Make invisible" invisible
)))
828 (defcustom org-timeline-show-empty-dates
3
829 "Non-nil means `org-timeline' also shows dates without an entry.
830 When nil, only the days which actually have entries are shown.
831 When t, all days between the first and the last date are shown.
832 When an integer, show also empty dates, but if there is a gap of more than
833 N days, just insert a special line indicating the size of the gap."
834 :group
'org-agenda-skip
836 (const :tag
"None" nil
)
838 (integer :tag
"at most")))
840 (defgroup org-agenda-startup nil
841 "Options concerning initial settings in the Agenda in Org Mode."
842 :tag
"Org Agenda Startup"
845 (defcustom org-agenda-menu-show-matcher t
846 "Non-nil means show the match string in the agenda dispatcher menu.
847 When nil, the matcher string is not shown, but is put into the help-echo
848 property so than moving the mouse over the command shows it.
849 Setting it to nil is good if matcher strings are very long and/or if
850 you want to use two-column display (see `org-agenda-menu-two-column')."
854 (defcustom org-agenda-menu-two-column nil
855 "Non-nil means, use two columns to show custom commands in the dispatcher.
856 If you use this, you probably want to set `org-agenda-menu-show-matcher'
861 (defcustom org-finalize-agenda-hook nil
862 "Hook run just before displaying an agenda buffer."
863 :group
'org-agenda-startup
866 (defcustom org-agenda-mouse-1-follows-link nil
867 "Non-nil means mouse-1 on a link will follow the link in the agenda.
868 A longer mouse click will still set point. Does not work on XEmacs.
869 Needs to be set before org.el is loaded."
870 :group
'org-agenda-startup
873 (defcustom org-agenda-start-with-follow-mode nil
874 "The initial value of follow mode in a newly created agenda window."
875 :group
'org-agenda-startup
878 (defcustom org-agenda-show-outline-path t
879 "Non-nil means show outline path in echo area after line motion."
880 :group
'org-agenda-startup
883 (defcustom org-agenda-start-with-entry-text-mode nil
884 "The initial value of entry-text-mode in a newly created agenda window."
885 :group
'org-agenda-startup
888 (defcustom org-agenda-entry-text-maxlines
5
889 "Number of text lines to be added when `E' is pressed in the agenda.
891 Note that this variable only used during agenda display. Add add entry text
892 when exporting the agenda, configure the variable
893 `org-agenda-add-entry-ext-maxlines'."
897 (defcustom org-agenda-entry-text-exclude-regexps nil
898 "List of regular expressions to clean up entry text.
899 The complete matches of all regular expressions in this list will be
900 removed from entry text before it is shown in the agenda."
902 :type
'(repeat (regexp)))
904 (defvar org-agenda-entry-text-cleanup-hook nil
905 "Hook that is run after basic cleanup of entry text to be shown in agenda.
906 This cleanup is done in a temporary buffer, so the function may inspect and
907 change the entire buffer.
908 Some default stuff like drawers and scheduling/deadline dates will already
909 have been removed when this is called, as will any matches for regular
910 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
912 (defvar org-agenda-include-inactive-timestamps nil
913 "Non-nil means include inactive time stamps in agenda and timeline.")
915 (defgroup org-agenda-windows nil
916 "Options concerning the windows used by the Agenda in Org Mode."
917 :tag
"Org Agenda Windows"
920 (defcustom org-agenda-window-setup
'reorganize-frame
921 "How the agenda buffer should be displayed.
922 Possible values for this option are:
924 current-window Show agenda in the current window, keeping all other windows.
925 other-window Use `switch-to-buffer-other-window' to display agenda.
926 reorganize-frame Show only two windows on the current frame, the current
927 window and the agenda.
928 other-frame Use `switch-to-buffer-other-frame' to display agenda.
929 Also, when exiting the agenda, kill that frame.
930 See also the variable `org-agenda-restore-windows-after-quit'."
931 :group
'org-agenda-windows
933 (const current-window
)
936 (const reorganize-frame
)))
938 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
939 "The min and max height of the agenda window as a fraction of frame height.
940 The value of the variable is a cons cell with two numbers between 0 and 1.
941 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
942 :group
'org-agenda-windows
943 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
945 (defcustom org-agenda-restore-windows-after-quit nil
946 "Non-nil means restore window configuration upon exiting agenda.
947 Before the window configuration is changed for displaying the agenda,
948 the current status is recorded. When the agenda is exited with
949 `q' or `x' and this option is set, the old state is restored. If
950 `org-agenda-window-setup' is `other-frame', the value of this
951 option will be ignored."
952 :group
'org-agenda-windows
955 (defcustom org-agenda-ndays nil
956 "Number of days to include in overview display.
958 Obsolete, see `org-agenda-span'."
959 :group
'org-agenda-daily
/weekly
962 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
964 (defcustom org-agenda-span
'week
965 "Number of days to include in overview display.
966 Can be day, week, month, year, or any number of days.
967 Custom commands can set this variable in the options section."
968 :group
'org-agenda-daily
/weekly
969 :type
'(choice (const :tag
"Day" day
)
970 (const :tag
"Week" week
)
971 (const :tag
"Month" month
)
972 (const :tag
"Year" year
)
973 (integer :tag
"Custom")))
975 (defcustom org-agenda-start-on-weekday
1
976 "Non-nil means start the overview always on the specified weekday.
977 0 denotes Sunday, 1 denotes Monday etc.
978 When nil, always start on the current day.
979 Custom commands can set this variable in the options section."
980 :group
'org-agenda-daily
/weekly
981 :type
'(choice (const :tag
"Today" nil
)
982 (integer :tag
"Weekday No.")))
984 (defcustom org-agenda-show-all-dates t
985 "Non-nil means `org-agenda' shows every day in the selected range.
986 When nil, only the days which actually have entries are shown."
987 :group
'org-agenda-daily
/weekly
990 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
991 "Format string for displaying dates in the agenda.
992 Used by the daily/weekly agenda and by the timeline. This should be
993 a format string understood by `format-time-string', or a function returning
994 the formatted date as a string. The function must take a single argument,
995 a calendar-style date list like (month day year)."
996 :group
'org-agenda-daily
/weekly
998 (string :tag
"Format string")
999 (function :tag
"Function")))
1001 (defun org-agenda-format-date-aligned (date)
1002 "Format a date string for display in the daily/weekly agenda, or timeline.
1003 This function makes sure that dates are aligned for easy reading."
1005 (let* ((dayname (calendar-day-name date
))
1007 (day-of-week (calendar-day-of-week date
))
1009 (monthname (calendar-month-name month
))
1011 (iso-week (org-days-to-iso-week
1012 (calendar-absolute-from-gregorian date
)))
1013 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1015 ((and (= month
12) (<= iso-week
1))
1018 (weekstring (if (= day-of-week
1)
1019 (format " W%02d" iso-week
)
1021 (format "%-10s %2d %s %4d%s"
1022 dayname day monthname year weekstring
)))
1024 (defcustom org-agenda-time-leading-zero nil
1025 "Non-nil means use leading zero for military times in agenda.
1026 For example, 9:30am would become 09:30 rather than 9:30."
1027 :group
'org-agenda-daily
/weekly
1030 (defcustom org-agenda-timegrid-use-ampm nil
1031 "When set, show AM/PM style timestamps on the timegrid."
1035 (defun org-agenda-time-of-day-to-ampm (time)
1036 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1037 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1038 (minute (substring time -
2))
1041 ((equal hour-number
12)
1045 (setq hour-number
(- hour-number
12))))
1047 (if org-agenda-time-leading-zero
1048 (format "%02d" hour-number
)
1049 (format "%02s" (number-to-string hour-number
)))
1052 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1053 "Conditionally convert TIME to AM/PM format
1054 based on `org-agenda-timegrid-use-ampm'"
1055 (if org-agenda-timegrid-use-ampm
1056 (org-agenda-time-of-day-to-ampm time
)
1059 (defcustom org-agenda-weekend-days
'(6 0)
1060 "Which days are weekend?
1061 These days get the special face `org-agenda-date-weekend' in the agenda
1062 and timeline buffers."
1063 :group
'org-agenda-daily
/weekly
1064 :type
'(set :greedy t
1065 (const :tag
"Monday" 1)
1066 (const :tag
"Tuesday" 2)
1067 (const :tag
"Wednesday" 3)
1068 (const :tag
"Thursday" 4)
1069 (const :tag
"Friday" 5)
1070 (const :tag
"Saturday" 6)
1071 (const :tag
"Sunday" 0)))
1073 (defcustom org-agenda-include-diary nil
1074 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1075 Custom commands can set this variable in the options section."
1076 :group
'org-agenda-daily
/weekly
1079 (defcustom org-agenda-include-deadlines t
1080 "If non-nil, include entries within their deadline warning period.
1081 Custom commands can set this variable in the options section."
1082 :group
'org-agenda-daily
/weekly
1085 (defcustom org-agenda-repeating-timestamp-show-all t
1086 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1087 When set to a list of strings, only show occurrences of repeating
1088 stamps for these TODO keywords. When nil, only one occurrence is
1089 shown, either today or the nearest into the future."
1090 :group
'org-agenda-daily
/weekly
1092 (const :tag
"Show repeating stamps" t
)
1093 (repeat :tag
"Show repeating stamps for these TODO keywords"
1094 (string :tag
"TODO Keyword"))
1095 (const :tag
"Don't show repeating stamps" nil
)))
1097 (defcustom org-scheduled-past-days
10000
1098 "No. of days to continue listing scheduled items that are not marked DONE.
1099 When an item is scheduled on a date, it shows up in the agenda on this
1100 day and will be listed until it is marked done for the number of days
1102 :group
'org-agenda-daily
/weekly
1105 (defcustom org-agenda-log-mode-items
'(closed clock
)
1106 "List of items that should be shown in agenda log mode.
1107 This list may contain the following symbols:
1109 closed Show entries that have been closed on that day.
1110 clock Show entries that have received clocked time on that day.
1111 state Show all logged state changes.
1112 Note that instead of changing this variable, you can also press `C-u l' in
1113 the agenda to display all available LOG items temporarily."
1114 :group
'org-agenda-daily
/weekly
1115 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1117 (defcustom org-agenda-clock-consistency-checks
1118 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1119 :gap-ok-around
("4:00")
1120 :default-face
((:background
"DarkRed") (:foreground
"white"))
1121 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1122 :long-face nil
:short-face nil
)
1123 "This is a property list, with the following keys:
1125 :max-duration Mark clocking chunks that are longer than this time.
1126 This is a time string like \"HH:MM\", or the number
1127 of minutes as an integer.
1129 :min-duration Mark clocking chunks that are shorter that this.
1130 This is a time string like \"HH:MM\", or the number
1131 of minutes as an integer.
1133 :max-gap Mark gaps between clocking chunks that are longer than
1134 this duration. A number of minutes, or a string
1137 :gap-ok-around List of times during the day which are usually not working
1138 times. When a gap is detected, but the gap contains any
1139 of these times, the gap is *not* reported. For example,
1140 if this is (\"4:00\" \"13:00\") then gaps that contain
1141 4:00 in the morning (i.e. the night) and 13:00
1142 (i.e. a typical lunch time) do not cause a warning.
1143 You should have at least one time during the night in this
1144 list, or otherwise the first task each morning will trigger
1145 a warning because it follows a long gap.
1147 Furthermore, the following properties can be used to define faces for
1150 :default-face the default face, if the specific face is undefined
1151 :overlap-face face for overlapping clocks
1152 :gap-face face for gaps between clocks
1153 :no-end-time-face face for incomplete clocks
1154 :long-face face for clock intervals that are too long
1155 :short-face face for clock intervals that are too short"
1156 :group
'org-agenda-daily
/weekly
1160 (defcustom org-agenda-log-mode-add-notes t
1161 "Non-nil means add first line of notes to log entries in agenda views.
1162 If a log item like a state change or a clock entry is associated with
1163 notes, the first line of these notes will be added to the entry in the
1165 :group
'org-agenda-daily
/weekly
1168 (defcustom org-agenda-start-with-log-mode nil
1169 "The initial value of log-mode in a newly created agenda window."
1170 :group
'org-agenda-startup
1171 :group
'org-agenda-daily
/weekly
1174 (defcustom org-agenda-start-with-clockreport-mode nil
1175 "The initial value of clockreport-mode in a newly created agenda window."
1176 :group
'org-agenda-startup
1177 :group
'org-agenda-daily
/weekly
1180 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1181 "Property list with parameters for the clocktable in clockreport mode.
1182 This is the display mode that shows a clock table in the daily/weekly
1183 agenda, the properties for this dynamic block can be set here.
1184 The usual clocktable parameters are allowed here, but you cannot set
1185 the properties :name, :tstart, :tend, :block, and :scope - these will
1186 be overwritten to make sure the content accurately reflects the
1187 current display in the agenda."
1188 :group
'org-agenda-daily
/weekly
1191 (defcustom org-agenda-search-view-always-boolean nil
1192 "Non-nil means the search string is interpreted as individual parts.
1194 The search string for search view can either be interpreted as a phrase,
1195 or as a list of snippets that define a boolean search for a number of
1198 When this is non-nil, the string will be split on whitespace, and each
1199 snippet will be searched individually, and all must match in order to
1200 select an entry. A snippet is then a single string of non-white
1201 characters, or a string in double quotes, or a regexp in {} braces.
1202 If a snippet is preceded by \"-\", the snippet must *not* match.
1203 \"+\" is syntactic sugar for positive selection. Each snippet may
1204 be found as a full word or a partial word, but see the variable
1205 `org-agenda-search-view-force-full-words'.
1207 When this is nil, search will look for the entire search phrase as one,
1208 with each space character matching any amount of whitespace, including
1211 Even when this is nil, you can still switch to Boolean search dynamically
1212 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1213 is a regexp marked with braces like \"{abc}\", this will also switch to
1215 :group
'org-agenda-search-view
1218 (if (fboundp 'defvaralias
)
1219 (defvaralias 'org-agenda-search-view-search-words-only
1220 'org-agenda-search-view-always-boolean
))
1222 (defcustom org-agenda-search-view-force-full-words nil
1223 "Non-nil means, search words must be matches as complete words.
1224 When nil, they may also match part of a word."
1225 :group
'org-agenda-search-view
1228 (defgroup org-agenda-time-grid nil
1229 "Options concerning the time grid in the Org-mode Agenda."
1230 :tag
"Org Agenda Time Grid"
1233 (defcustom org-agenda-search-headline-for-time t
1234 "Non-nil means search headline for a time-of-day.
1235 If the headline contains a time-of-day in one format or another, it will
1236 be used to sort the entry into the time sequence of items for a day.
1237 Some people have time stamps in the headline that refer to the creation
1238 time or so, and then this produces an unwanted side effect. If this is
1239 the case for your, use this variable to turn off searching the headline
1241 :group
'org-agenda-time-grid
1244 (defcustom org-agenda-use-time-grid t
1245 "Non-nil means show a time grid in the agenda schedule.
1246 A time grid is a set of lines for specific times (like every two hours between
1247 8:00 and 20:00). The items scheduled for a day at specific times are
1248 sorted in between these lines.
1249 For details about when the grid will be shown, and what it will look like, see
1250 the variable `org-agenda-time-grid'."
1251 :group
'org-agenda-time-grid
1254 (defcustom org-agenda-time-grid
1255 '((daily today require-timed
)
1257 (800 1000 1200 1400 1600 1800 2000))
1259 "The settings for time grid for agenda display.
1260 This is a list of three items. The first item is again a list. It contains
1261 symbols specifying conditions when the grid should be displayed:
1263 daily if the agenda shows a single day
1264 weekly if the agenda shows an entire week
1265 today show grid on current date, independent of daily/weekly display
1266 require-timed show grid only if at least one item has a time specification
1268 The second item is a string which will be placed behind the grid time.
1270 The third item is a list of integers, indicating the times that should have
1272 :group
'org-agenda-time-grid
1275 (set :greedy t
:tag
"Grid Display Options"
1276 (const :tag
"Show grid in single day agenda display" daily
)
1277 (const :tag
"Show grid in weekly agenda display" weekly
)
1278 (const :tag
"Always show grid for today" today
)
1279 (const :tag
"Show grid only if any timed entries are present"
1281 (const :tag
"Skip grid times already present in an entry"
1283 (string :tag
"Grid String")
1284 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1286 (defcustom org-agenda-show-current-time-in-grid t
1287 "Non-nil means show the current time in the time grid."
1288 :group
'org-agenda-time-grid
1291 (defcustom org-agenda-current-time-string
1292 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1293 "The string for the current time marker in the agenda."
1294 :group
'org-agenda-time-grid
1297 (defgroup org-agenda-sorting nil
1298 "Options concerning sorting in the Org-mode Agenda."
1299 :tag
"Org Agenda Sorting"
1302 (defcustom org-agenda-sorting-strategy
1303 '((agenda habit-down time-up priority-down category-keep
)
1304 (todo priority-down category-keep
)
1305 (tags priority-down category-keep
)
1306 (search category-keep
))
1307 "Sorting structure for the agenda items of a single day.
1308 This is a list of symbols which will be used in sequence to determine
1309 if an entry should be listed before another entry. The following
1310 symbols are recognized:
1312 time-up Put entries with time-of-day indications first, early first
1313 time-down Put entries with time-of-day indications first, late first
1314 category-keep Keep the default order of categories, corresponding to the
1315 sequence in `org-agenda-files'.
1316 category-up Sort alphabetically by category, A-Z.
1317 category-down Sort alphabetically by category, Z-A.
1318 tag-up Sort alphabetically by last tag, A-Z.
1319 tag-down Sort alphabetically by last tag, Z-A.
1320 priority-up Sort numerically by priority, high priority last.
1321 priority-down Sort numerically by priority, high priority first.
1322 todo-state-up Sort by todo state, tasks that are done last.
1323 todo-state-down Sort by todo state, tasks that are done first.
1324 effort-up Sort numerically by estimated effort, high effort last.
1325 effort-down Sort numerically by estimated effort, high effort first.
1326 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1327 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1328 habit-up Put entries that are habits first
1329 habit-down Put entries that are habits last
1330 alpha-up Sort headlines alphabetically
1331 alpha-down Sort headlines alphabetically, reversed
1333 The different possibilities will be tried in sequence, and testing stops
1334 if one comparison returns a \"not-equal\". For example, the default
1335 '(time-up category-keep priority-down)
1336 means: Pull out all entries having a specified time of day and sort them,
1337 in order to make a time schedule for the current day the first thing in the
1338 agenda listing for the day. Of the entries without a time indication, keep
1339 the grouped in categories, don't sort the categories, but keep them in
1340 the sequence given in `org-agenda-files'. Within each category sort by
1343 Leaving out `category-keep' would mean that items will be sorted across
1344 categories by priority.
1346 Instead of a single list, this can also be a set of list for specific
1347 contents, with a context symbol in the car of the list, any of
1348 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1350 Custom commands can bind this variable in the options section."
1351 :group
'org-agenda-sorting
1353 (repeat :tag
"General" ,org-sorting-choice
)
1354 (list :tag
"Individually"
1355 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1356 (repeat ,org-sorting-choice
))
1357 (cons (const :tag
"Strategy for TODO lists" todo
)
1358 (repeat ,org-sorting-choice
))
1359 (cons (const :tag
"Strategy for Tags matches" tags
)
1360 (repeat ,org-sorting-choice
))
1361 (cons (const :tag
"Strategy for search matches" search
)
1362 (repeat ,org-sorting-choice
)))))
1364 (defcustom org-agenda-cmp-user-defined nil
1365 "A function to define the comparison `user-defined'.
1366 This function must receive two arguments, agenda entry a and b.
1367 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1368 the user comparison, return nil.
1369 When this is defined, you can make `user-defined-up' and `user-defined-down'
1370 part of an agenda sorting strategy."
1371 :group
'org-agenda-sorting
1374 (defcustom org-sort-agenda-notime-is-late t
1375 "Non-nil means items without time are considered late.
1376 This is only relevant for sorting. When t, items which have no explicit
1377 time like 15:30 will be considered as 99:01, i.e. later than any items which
1378 do have a time. When nil, the default time is before 0:00. You can use this
1379 option to decide if the schedule for today should come before or after timeless
1381 :group
'org-agenda-sorting
1384 (defcustom org-sort-agenda-noeffort-is-high t
1385 "Non-nil means items without effort estimate are sorted as high effort.
1386 This also applies when filtering an agenda view with respect to the
1387 < or > effort operator. Then, tasks with no effort defined will be treated
1388 as tasks with high effort.
1389 When nil, such items are sorted as 0 minutes effort."
1390 :group
'org-agenda-sorting
1393 (defgroup org-agenda-line-format nil
1394 "Options concerning the entry prefix in the Org-mode agenda display."
1395 :tag
"Org Agenda Line Format"
1398 (defcustom org-agenda-prefix-format
1399 '((agenda .
" %i %-12:c%?-12t% s")
1401 (todo .
" %i %-12:c")
1402 (tags .
" %i %-12:c")
1403 (search .
" %i %-12:c"))
1404 "Format specifications for the prefix of items in the agenda views.
1405 An alist with five entries, each for the different agenda types. The
1406 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1407 The values are format strings.
1409 This format works similar to a printf format, with the following meaning:
1411 %c the category of the item, \"Diary\" for entries from the diary,
1412 or as given by the CATEGORY keyword or derived from the file name
1413 %i the icon category of the item, see `org-agenda-category-icon-alist'
1414 %T the last tag of the item (ignore inherited tags, which come first)
1415 %t the HH:MM time-of-day specification if one applies to the entry
1416 %s Scheduling/Deadline information, a short string
1417 %(expression) Eval EXPRESSION and replace the control string
1420 All specifiers work basically like the standard `%s' of printf, but may
1421 contain two additional characters: a question mark just after the `%'
1422 and a whitespace/punctuation character just before the final letter.
1424 If the first character after `%' is a question mark, the entire field
1425 will only be included if the corresponding value applies to the current
1426 entry. This is useful for fields which should have fixed width when
1427 present, but zero width when absent. For example, \"%?-12t\" will
1428 result in a 12 character time field if a time of the day is specified,
1429 but will completely disappear in entries which do not contain a time.
1431 If there is punctuation or whitespace character just before the final
1432 format letter, this character will be appended to the field value if
1433 the value is not empty. For example, the format \"%-12:c\" leads to
1434 \"Diary: \" if the category is \"Diary\". If the category were be
1435 empty, no additional colon would be inserted.
1437 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1440 - Indent the line with two space characters
1441 - Give the category a 12 chars wide field, padded with whitespace on
1442 the right (because of `-'). Append a colon if there is a category
1444 - If there is a time-of-day, put it into a 12 chars wide field. If no
1445 time, don't put in an empty field, just skip it (because of '?').
1446 - Finally, put the scheduling information.
1448 See also the variables `org-agenda-remove-times-when-in-prefix' and
1449 `org-agenda-remove-tags'.
1451 Custom commands can set this variable in the options section."
1453 (string :tag
"General format")
1454 (list :greedy t
:tag
"View dependent"
1455 (cons (const agenda
) (string :tag
"Format"))
1456 (cons (const timeline
) (string :tag
"Format"))
1457 (cons (const todo
) (string :tag
"Format"))
1458 (cons (const tags
) (string :tag
"Format"))
1459 (cons (const search
) (string :tag
"Format"))))
1460 :group
'org-agenda-line-format
)
1462 (defvar org-prefix-format-compiled nil
1463 "The compiled version of the most recently used prefix format.
1464 See the variable `org-agenda-prefix-format'.")
1466 (defcustom org-agenda-todo-keyword-format
"%-1s"
1467 "Format for the TODO keyword in agenda lines.
1468 Set this to something like \"%-12s\" if you want all TODO keywords
1469 to occupy a fixed space in the agenda display."
1470 :group
'org-agenda-line-format
1473 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1474 "Text preceding timerange entries in the agenda view.
1475 This is a list with two strings. The first applies when the range
1476 is entirely on one day. The second applies if the range spans several days.
1477 The strings may have two \"%d\" format specifiers which will be filled
1478 with the sequence number of the days, and the total number of days in the
1479 range, respectively."
1480 :group
'org-agenda-line-format
1482 (string :tag
"Deadline today ")
1483 (choice :tag
"Deadline relative"
1484 (string :tag
"Format string")
1487 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1488 "Text preceding scheduled items in the agenda view.
1489 This is a list with two strings. The first applies when the item is
1490 scheduled on the current day. The second applies when it has been scheduled
1491 previously, it may contain a %d indicating that this is the nth time that
1492 this item is scheduled, due to automatic rescheduling of unfinished items
1493 for the following day. So this number is one larger than the number of days
1494 that passed since this item was scheduled first."
1495 :group
'org-agenda-line-format
1497 (string :tag
"Scheduled today ")
1498 (string :tag
"Scheduled previously")))
1500 (defcustom org-agenda-inactive-leader
"["
1501 "Text preceding item pulled into the agenda by inactive time stamps.
1502 These entries are added to the agenda when pressing \"[\"."
1503 :group
'org-agenda-line-format
1505 (string :tag
"Scheduled today ")
1506 (string :tag
"Scheduled previously")))
1508 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1509 "Text preceding deadline items in the agenda view.
1510 This is a list with two strings. The first applies when the item has its
1511 deadline on the current day. The second applies when it is in the past or
1512 in the future, it may contain %d to capture how many days away the deadline
1514 :group
'org-agenda-line-format
1516 (string :tag
"Deadline today ")
1517 (choice :tag
"Deadline relative"
1518 (string :tag
"Format string")
1521 (defcustom org-agenda-remove-times-when-in-prefix t
1522 "Non-nil means remove duplicate time specifications in agenda items.
1523 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1524 time-of-day specification in a headline or diary entry is extracted and
1525 placed into the prefix. If this option is non-nil, the original specification
1526 \(a timestamp or -range, or just a plain time(range) specification like
1527 11:30-4pm) will be removed for agenda display. This makes the agenda less
1529 The option can be t or nil. It may also be the symbol `beg', indicating
1530 that the time should only be removed when it is located at the beginning of
1531 the headline/diary entry."
1532 :group
'org-agenda-line-format
1534 (const :tag
"Always" t
)
1535 (const :tag
"Never" nil
)
1536 (const :tag
"When at beginning of entry" beg
)))
1538 (defcustom org-agenda-remove-timeranges-from-blocks nil
1539 "Non-nil means remove time ranges specifications in agenda
1540 items that span on several days."
1541 :group
'org-agenda-line-format
1544 (defcustom org-agenda-default-appointment-duration nil
1545 "Default duration for appointments that only have a starting time.
1546 When nil, no duration is specified in such cases.
1547 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1548 :group
'org-agenda-line-format
1550 (integer :tag
"Minutes")
1551 (const :tag
"No default duration")))
1553 (defcustom org-agenda-show-inherited-tags t
1554 "Non-nil means show inherited tags in each agenda line."
1555 :group
'org-agenda-line-format
1558 (defcustom org-agenda-hide-tags-regexp nil
1559 "Regular expression used to filter away specific tags in agenda views.
1560 This means that these tags will be present, but not be shown in the agenda
1561 line. Secondary filtering will still work on the hidden tags.
1562 Nil means don't hide any tags."
1563 :group
'org-agenda-line-format
1565 (const :tag
"Hide none" nil
)
1566 (string :tag
"Regexp ")))
1568 (defcustom org-agenda-remove-tags nil
1569 "Non-nil means remove the tags from the headline copy in the agenda.
1570 When this is the symbol `prefix', only remove tags when
1571 `org-agenda-prefix-format' contains a `%T' specifier."
1572 :group
'org-agenda-line-format
1574 (const :tag
"Always" t
)
1575 (const :tag
"Never" nil
)
1576 (const :tag
"When prefix format contains %T" prefix
)))
1578 (if (fboundp 'defvaralias
)
1579 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1580 'org-agenda-remove-tags
))
1582 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1583 "Shift tags in agenda items to this column.
1584 If this number is positive, it specifies the column. If it is negative,
1585 it means that the tags should be flushright to that column. For example,
1586 -80 works well for a normal 80 character screen."
1587 :group
'org-agenda-line-format
1590 (if (fboundp 'defvaralias
)
1591 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1593 (defcustom org-agenda-fontify-priorities
'cookies
1594 "Non-nil means highlight low and high priorities in agenda.
1595 When t, the highest priority entries are bold, lowest priority italic.
1596 However, settings in `org-priority-faces' will overrule these faces.
1597 When this variable is the symbol `cookies', only fontify the
1598 cookies, not the entire task.
1599 This may also be an association list of priority faces, whose
1600 keys are the character values of `org-highest-priority',
1601 `org-default-priority', and `org-lowest-priority' (the default values
1602 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1603 color as a string, or a list like `(:background \"Red\")'.
1604 If it is a color, the variable `org-faces-easy-properties'
1605 determines if it is a foreground or a background color."
1606 :group
'org-agenda-line-format
1608 (const :tag
"Never" nil
)
1609 (const :tag
"Defaults" t
)
1610 (const :tag
"Cookies only" cookies
)
1611 (repeat :tag
"Specify"
1612 (list (character :tag
"Priority" :value ?A
)
1613 (choice :tag
"Face "
1614 (string :tag
"Color")
1615 (sexp :tag
"Face"))))))
1617 (defcustom org-agenda-day-face-function nil
1618 "Function called to determine what face should be used to display a day.
1619 The only argument passed to that function is the day. It should
1620 returns a face, or nil if does not want to specify a face and let
1621 the normal rules apply."
1622 :group
'org-agenda-line-format
1625 (defcustom org-agenda-category-icon-alist nil
1626 "Alist of category icon to be displayed in agenda views.
1628 Each entry should have the following format:
1630 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1632 Where CATEGORY-REGEXP is a regexp matching the categories where
1633 the icon should be displayed.
1634 FILE-OR-DATA either a file path or a string containing image data.
1636 The other fields can be omited safely if not needed:
1637 TYPE indicates the image type.
1638 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1640 PROPS are additional image attributes to assign to the image,
1641 like, e.g. `:ascent center'.
1643 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1645 If you want to set the display properties yourself, just put a
1646 list as second element:
1648 (CATEGORY-REGEXP (MY PROPERTY LIST))
1650 For example, to display a 16px horizontal space for Emacs
1651 category, you can use:
1653 (\"Emacs\" '(space . (:width (16))))"
1654 :group
'org-agenda-line-format
1655 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1656 :value-type
(choice (list :tag
"Icon"
1657 (string :tag
"File or data")
1658 (symbol :tag
"Type")
1659 (boolean :tag
"Data?")
1660 (repeat :tag
"Extra image properties" :inline t symbol
))
1661 (list :tag
"Display properties" sexp
))))
1663 (defgroup org-agenda-column-view nil
1664 "Options concerning column view in the agenda."
1665 :tag
"Org Agenda Column View"
1668 (defcustom org-agenda-columns-show-summaries t
1669 "Non-nil means show summaries for columns displayed in the agenda view."
1670 :group
'org-agenda-column-view
1673 (defcustom org-agenda-columns-compute-summary-properties t
1674 "Non-nil means recompute all summary properties before column view.
1675 When column view in the agenda is listing properties that have a summary
1676 operator, it can go to all relevant buffers and recompute the summaries
1677 there. This can mean overhead for the agenda column view, but is necessary
1678 to have thing up to date.
1679 As a special case, a CLOCKSUM property also makes sure that the clock
1680 computations are current."
1681 :group
'org-agenda-column-view
1684 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1685 "Non-nil means the duration of an appointment will add to day effort.
1686 The property to which appointment durations will be added is the one given
1687 in the option `org-effort-property'. If an appointment does not have
1688 an end time, `org-agenda-default-appointment-duration' will be used. If that
1689 is not set, an appointment without end time will not contribute to the time
1691 :group
'org-agenda-column-view
1694 (defcustom org-agenda-auto-exclude-function nil
1695 "A function called with a tag to decide if it is filtered on '/ RET'.
1696 The sole argument to the function, which is called once for each
1697 possible tag, is a string giving the name of the tag. The
1698 function should return either nil if the tag should be included
1699 as normal, or \"-<TAG>\" to exclude the tag.
1700 Note that for the purpose of tag filtering, only the lower-case version of
1701 all tags will be considered, so that this function will only ever see
1702 the lower-case version of all tags."
1706 (defcustom org-agenda-bulk-custom-functions nil
1707 "Alist of characters and custom functions for bulk actions.
1708 For example, this value makes those two functions available:
1713 With selected entries in an agenda buffer, `B R' will call
1714 the custom function `set-category' on the selected entries.
1715 Note that functions in this alist don't need to be quoted."
1723 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
1724 "Execute BODY with point at location given by `org-hd-marker' property.
1725 If STRING is non-nil, the text property will be fetched from position 0
1726 in that string. If STRING is nil, it will be fetched from the beginning
1727 of the current line."
1728 (org-with-gensyms (marker)
1729 `(let ((,marker
(get-text-property (if string
0 (point-at-bol))
1730 'org-hd-marker string
)))
1731 (with-current-buffer (marker-buffer ,marker
)
1735 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
1737 (defun org-add-agenda-custom-command (entry)
1738 "Replace or add a command in `org-agenda-custom-commands'.
1739 This is mostly for hacking and trying a new command - once the command
1740 works you probably want to add it to `org-agenda-custom-commands' for good."
1741 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1743 (setcdr ass
(cdr entry
))
1744 (push entry org-agenda-custom-commands
))))
1746 ;;; Define the Org-agenda-mode
1748 (defvar org-agenda-mode-map
(make-sparse-keymap)
1749 "Keymap for `org-agenda-mode'.")
1750 (if (fboundp 'defvaralias
)
1751 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1753 (defvar org-agenda-menu
) ; defined later in this file.
1754 (defvar org-agenda-restrict
) ; defined later in this file.
1755 (defvar org-agenda-follow-mode nil
)
1756 (defvar org-agenda-entry-text-mode nil
)
1757 (defvar org-agenda-clockreport-mode nil
)
1758 (defvar org-agenda-show-log nil
)
1759 (defvar org-agenda-redo-command nil
)
1760 (defvar org-agenda-query-string nil
)
1761 (defvar org-agenda-mode-hook nil
1762 "Hook for `org-agenda-mode', run after the mode is turned on.")
1763 (defvar org-agenda-type nil
)
1764 (defvar org-agenda-force-single-file nil
)
1765 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1767 (defun org-agenda-mode ()
1768 "Mode for time-sorted view on action items in Org-mode files.
1770 The following commands are available:
1772 \\{org-agenda-mode-map}"
1774 (kill-all-local-variables)
1775 (setq org-agenda-undo-list nil
1776 org-agenda-pending-undo-list nil
1777 org-agenda-bulk-marked-entries nil
)
1778 (setq major-mode
'org-agenda-mode
)
1779 ;; Keep global-font-lock-mode from turning on font-lock-mode
1780 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1781 (setq mode-name
"Org-Agenda")
1782 (use-local-map org-agenda-mode-map
)
1783 (easy-menu-add org-agenda-menu
)
1784 (if org-startup-truncated
(setq truncate-lines t
))
1785 (org-set-local 'line-move-visual nil
)
1786 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1787 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1788 ;; Make sure properties are removed when copying text
1789 (when (boundp 'buffer-substring-filters
)
1790 (org-set-local 'buffer-substring-filters
1792 (set-text-properties 0 (length x
) nil x
) x
)
1793 buffer-substring-filters
)))
1794 (unless org-agenda-keep-modes
1795 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1796 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1797 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1798 org-agenda-show-log org-agenda-start-with-log-mode
))
1801 '("Agenda") "Agenda Files"
1805 (if (get 'org-agenda-files
'org-restrict
)
1806 "Restricted to single file"
1808 '(org-edit-agenda-file-list)
1809 (not (get 'org-agenda-files
'org-restrict
)))
1811 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1812 (org-agenda-set-mode-name)
1814 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1815 (list 'org-agenda-mode-hook
)))
1817 (substitute-key-definition 'undo
'org-agenda-undo
1818 org-agenda-mode-map global-map
)
1819 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1820 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1821 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1822 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1823 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1824 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1825 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
1826 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1827 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1828 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
1829 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1830 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1831 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1832 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1833 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1834 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1835 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1836 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1837 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1838 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1839 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1840 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1841 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1842 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1843 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1844 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1845 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1846 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1847 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1848 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1849 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1850 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1851 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1852 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1853 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1854 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1855 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1856 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1857 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1858 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1859 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1860 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1861 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1862 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1863 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1865 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1866 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1867 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1868 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1869 (while l (org-defkey org-agenda-mode-map
1870 (int-to-string (pop l)) 'digit-argument)))
1872 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1873 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1874 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1875 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1876 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1877 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1878 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1879 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1880 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1881 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1882 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1883 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1884 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1885 'org-clock-modify-effort-estimate)
1886 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1887 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1888 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1889 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1890 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1891 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1892 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1893 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1894 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1895 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1896 (substitute-key-definition 'next-line 'org-agenda-next-line
1897 org-agenda-mode-map global-map)
1898 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1899 org-agenda-mode-map global-map)
1900 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1901 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1902 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1903 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1904 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1905 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1906 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1907 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1908 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1909 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1910 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1911 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1912 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1913 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1914 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1915 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1916 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1917 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1918 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1919 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1920 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1921 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1922 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1923 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1924 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1925 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1926 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1927 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1928 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1929 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1931 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1932 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1933 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1934 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1935 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1936 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1937 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1938 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1939 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1940 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1942 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1943 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1944 (when org-agenda-mouse-1-follows-link
1945 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1946 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1951 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1952 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1953 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1954 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1957 ["Day View" org-agenda-day-view
1958 :active (org-agenda-check-type nil 'agenda)
1959 :style radio :selected (eq org-agenda-current-span 'day)
1960 :keys "v d (or just d)"]
1961 ["Week View" org-agenda-week-view
1962 :active (org-agenda-check-type nil 'agenda)
1963 :style radio :selected (eq org-agenda-current-span 'week)
1964 :keys "v w (or just w)"]
1965 ["Month View" org-agenda-month-view
1966 :active (org-agenda-check-type nil 'agenda)
1967 :style radio :selected (eq org-agenda-current-span 'month)
1969 ["Year View" org-agenda-year-view
1970 :active (org-agenda-check-type nil 'agenda)
1971 :style radio :selected (eq org-agenda-current-span 'year)
1974 ["Include Diary" org-agenda-toggle-diary
1975 :style toggle :selected org-agenda-include-diary
1976 :active (org-agenda-check-type nil 'agenda)]
1977 ["Include Deadlines" org-agenda-toggle-deadlines
1978 :style toggle :selected org-agenda-include-deadlines
1979 :active (org-agenda-check-type nil 'agenda)]
1980 ["Use Time Grid" org-agenda-toggle-time-grid
1981 :style toggle :selected org-agenda-use-time-grid
1982 :active (org-agenda-check-type nil 'agenda)]
1984 ["Show clock report" org-agenda-clockreport-mode
1985 :style toggle :selected org-agenda-clockreport-mode
1986 :active (org-agenda-check-type nil 'agenda)]
1987 ["Show some entry text" org-agenda-entry-text-mode
1988 :style toggle :selected org-agenda-entry-text-mode
1991 ["Show Logbook entries" org-agenda-log-mode
1992 :style toggle :selected org-agenda-show-log
1993 :active (org-agenda-check-type nil 'agenda 'timeline)
1994 :keys "v l (or just l)"]
1995 ["Include archived trees" org-agenda-archives-mode
1996 :style toggle :selected org-agenda-archives-mode :active t
1998 ["Include archive files" (org-agenda-archives-mode t)
1999 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2002 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2003 ["Write view to file" org-write-agenda t]
2004 ["Rebuild buffer" org-agenda-redo t]
2005 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2007 ["Show original entry" org-agenda-show t]
2008 ["Go To (other window)" org-agenda-goto t]
2009 ["Go To (this window)" org-agenda-switch-to t]
2010 ["Follow Mode" org-agenda-follow-mode
2011 :style toggle :selected org-agenda-follow-mode :active t]
2012 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2015 ["Cycle TODO" org-agenda-todo t]
2016 ["Next TODO set" org-agenda-todo-nextset t]
2017 ["Previous TODO set" org-agenda-todo-previousset t]
2018 ["Add note" org-agenda-add-note t])
2019 ("Archive/Refile/Delete"
2020 ["Archive default" org-agenda-archive-default t]
2021 ["Archive default" org-agenda-archive-default-with-confirmation t]
2022 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2023 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2024 ["Archive subtree" org-agenda-archive t]
2026 ["Refile" org-agenda-refile t]
2028 ["Delete subtree" org-agenda-kill t])
2030 ["Mark entry" org-agenda-bulk-mark t]
2031 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2032 ["Unmark entry" org-agenda-bulk-unmark t]
2033 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2034 ["Act on all marked" org-agenda-bulk-action t]
2036 ("Tags and Properties"
2037 ["Show all Tags" org-agenda-show-tags t]
2038 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2039 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2041 ["Column View" org-columns t])
2042 ("Deadline/Schedule"
2043 ["Schedule" org-agenda-schedule t]
2044 ["Set Deadline" org-agenda-deadline t]
2046 ["Mark item" org-agenda-action :active t :keys "k m"]
2047 ["Show mark item" org-agenda-action :active t :keys "k v"]
2048 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2049 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2051 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2052 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2053 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2054 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2055 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2056 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2057 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2059 ["Clock in" org-agenda-clock-in t]
2060 ["Clock out" org-agenda-clock-out t]
2061 ["Clock cancel" org-agenda-clock-cancel t]
2062 ["Goto running clock" org-clock-goto t]
2064 ["Set Effort" org-agenda-set-effort t]
2065 ["Change clocked effort" org-clock-modify-effort-estimate
2066 (org-clock-is-active)])
2068 ["Set Priority" org-agenda-priority t]
2069 ["Increase Priority" org-agenda-priority-up t]
2070 ["Decrease Priority" org-agenda-priority-down t]
2071 ["Show Priority" org-agenda-show-priority t])
2073 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2074 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2075 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2076 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2077 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2078 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2080 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2082 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2085 ["Push Files and Views" org-mobile-push t]
2086 ["Get Captured and Flagged" org-mobile-pull t]
2087 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2088 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2090 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2092 ["Quit" org-agenda-quit t]
2093 ["Exit and Release Buffers" org-agenda-exit t]
2098 (defvar org-agenda-allow-remote-undo t
2099 "Non-nil means allow remote undo from the agenda buffer.")
2100 (defvar org-agenda-undo-list nil
2101 "List of undoable operations in the agenda since last refresh.")
2102 (defvar org-agenda-undo-has-started-in nil
2103 "Buffers that have already seen `undo-start' in the current undo sequence.")
2104 (defvar org-agenda-pending-undo-list nil
2105 "In a series of undo commands, this is the list of remaining undo items.")
2107 (defun org-agenda-undo ()
2108 "Undo a remote editing step in the agenda.
2109 This undoes changes both in the agenda buffer and in the remote buffer
2110 that have been changed along."
2112 (or org-agenda-allow-remote-undo
2113 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2114 (if (not (eq this-command last-command))
2115 (setq org-agenda-undo-has-started-in nil
2116 org-agenda-pending-undo-list org-agenda-undo-list))
2117 (if (not org-agenda-pending-undo-list)
2118 (error "No further undo information"))
2119 (let* ((entry (pop org-agenda-pending-undo-list))
2120 buf line cmd rembuf)
2121 (setq cmd (pop entry) line (pop entry))
2122 (setq rembuf (nth 2 entry))
2123 (org-with-remote-undo rembuf
2124 (while (bufferp (setq buf (pop entry)))
2126 (with-current-buffer buf
2127 (let ((last-undo-buffer buf)
2128 (inhibit-read-only t))
2129 (unless (memq buf org-agenda-undo-has-started-in)
2130 (push buf org-agenda-undo-has-started-in)
2131 (make-local-variable 'pending-undo-list)
2133 (while (and pending-undo-list
2134 (listp pending-undo-list)
2135 (not (car pending-undo-list)))
2136 (pop pending-undo-list))
2138 (org-goto-line line)
2139 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2141 (defun org-verify-change-for-undo (l1 l2)
2142 "Verify that a real change occurred between the undo lists L1 and L2."
2143 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2144 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2149 (defvar org-agenda-restrict nil)
2150 (defvar org-agenda-restrict-begin (make-marker))
2151 (defvar org-agenda-restrict-end (make-marker))
2152 (defvar org-agenda-last-dispatch-buffer nil)
2153 (defvar org-agenda-overriding-restriction nil)
2156 (defun org-agenda (&optional arg keys restriction)
2157 "Dispatch agenda commands to collect entries to the agenda buffer.
2158 Prompts for a command to execute. Any prefix arg will be passed
2159 on to the selected command. The default selections are:
2161 a Call `org-agenda-list' to display the agenda for current day or week.
2162 t Call `org-todo-list' to display the global todo list.
2163 T Call `org-todo-list' to display the global todo list, select only
2164 entries with a specific TODO keyword (the user gets a prompt).
2165 m Call `org-tags-view' to display headlines with tags matching
2166 a condition (the user is prompted for the condition).
2167 M Like `m', but select only TODO entries, no ordinary headlines.
2168 L Create a timeline for the current buffer.
2169 e Export views to associated files.
2170 s Search entries for keywords.
2171 / Multi occur across all agenda files and also files listed
2172 in `org-agenda-text-search-extra-files'.
2173 < Restrict agenda commands to buffer, subtree, or region.
2174 Press several times to get the desired effect.
2175 > Remove a previous restriction.
2176 # List \"stuck\" projects.
2177 ! Configure what \"stuck\" means.
2178 C Configure custom agenda commands.
2180 More commands can be added by configuring the variable
2181 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2182 searches can be pre-defined in this way.
2184 If the current buffer is in Org-mode and visiting a file, you can also
2185 first press `<' once to indicate that the agenda should be temporarily
2186 \(until the next use of \\[org-agenda]) restricted to the current file.
2187 Pressing `<' twice means to restrict to the current subtree or region
2191 (let* ((prefix-descriptions nil)
2192 (org-agenda-window-setup (if (equal (buffer-name)
2193 org-agenda-buffer-name)
2195 org-agenda-window-setup))
2196 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2197 (org-agenda-custom-commands
2198 ;; normalize different versions
2202 (cond ((stringp (cdr x))
2203 (push x prefix-descriptions)
2205 ((stringp (nth 1 x)) x)
2206 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2207 (t (cons (car x) (cons "" (cdr x))))))
2208 org-agenda-custom-commands)))
2209 (buf (current-buffer))
2210 (bfn (buffer-file-name (buffer-base-buffer)))
2211 entry key type match lprops ans)
2212 ;; Turn off restriction unless there is an overriding one,
2213 (unless org-agenda-overriding-restriction
2214 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2215 ;; There is a request to keep the file list in place
2216 (put 'org-agenda-files 'org-restrict nil))
2217 (setq org-agenda-restrict nil)
2218 (move-marker org-agenda-restrict-begin nil)
2219 (move-marker org-agenda-restrict-end nil))
2220 ;; Delete old local properties
2221 (put 'org-agenda-redo-command 'org-lprops nil)
2222 ;; Delete previously set last-arguments
2223 (put 'org-agenda-redo-command 'last-args nil)
2224 ;; Remember where this call originated
2225 (setq org-agenda-last-dispatch-buffer (current-buffer))
2227 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2229 restriction (cdr ans)))
2230 ;; Establish the restriction, if any
2231 (when (and (not org-agenda-overriding-restriction) restriction)
2232 (put 'org-agenda-files 'org-restrict (list bfn))
2234 ((eq restriction 'region)
2235 (setq org-agenda-restrict t)
2236 (move-marker org-agenda-restrict-begin (region-beginning))
2237 (move-marker org-agenda-restrict-end (region-end)))
2238 ((eq restriction 'subtree)
2240 (setq org-agenda-restrict t)
2241 (org-back-to-heading t)
2242 (move-marker org-agenda-restrict-begin (point))
2243 (move-marker org-agenda-restrict-end
2244 (progn (org-end-of-subtree t)))))))
2246 ;; For example the todo list should not need it (but does...)
2248 ((setq entry (assoc keys org-agenda-custom-commands))
2249 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2251 (setq type (nth 2 entry) match (eval (nth 3 entry))
2252 lprops (nth 4 entry))
2253 (put 'org-agenda-redo-command 'org-lprops lprops)
2256 (org-let lprops '(org-agenda-list current-prefix-arg)))
2258 (org-let lprops '(org-todo-list current-prefix-arg)))
2260 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2262 (org-let lprops '(org-agenda-list-stuck-projects
2263 current-prefix-arg)))
2265 (org-let lprops '(org-tags-view current-prefix-arg match)))
2266 ((eq type 'tags-todo)
2267 (org-let lprops '(org-tags-view '(4) match)))
2269 (org-let lprops '(org-todo-list match)))
2270 ((eq type 'tags-tree)
2271 (org-check-for-org-mode)
2272 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2273 ((eq type 'todo-tree)
2274 (org-check-for-org-mode)
2276 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2277 (regexp-quote match) "\\>"))))
2278 ((eq type 'occur-tree)
2279 (org-check-for-org-mode)
2280 (org-let lprops '(org-occur match)))
2282 (org-let lprops '(funcall type match)))
2284 (org-let lprops '(funcall type match)))
2285 (t (error "Invalid custom agenda command type %s" type))))
2286 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2288 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2289 (customize-variable 'org-agenda-custom-commands))
2290 ((equal keys "a") (call-interactively 'org-agenda-list))
2291 ((equal keys "s") (call-interactively 'org-search-view))
2292 ((equal keys "t") (call-interactively 'org-todo-list))
2293 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2294 ((equal keys "m") (call-interactively 'org-tags-view))
2295 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2296 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2297 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2301 (unless (current-message)
2302 (let* ((m (org-agenda-get-any-marker))
2303 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2306 "FLAGGING-NOTE ([?] for more info): "
2308 (replace-regexp-in-string
2310 (copy-sequence note))
2311 nil 'face 'org-warning)))))))
2314 (unless (org-mode-p)
2315 (error "This is not an Org-mode file"))
2317 (put 'org-agenda-files 'org-restrict (list bfn))
2318 (org-call-with-arg 'org-timeline arg)))
2319 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2320 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2321 ((equal keys "!") (customize-variable 'org-stuck-projects))
2322 (t (error "Invalid agenda key"))))))
2324 (defun org-agenda-append-agenda ()
2325 "Append another agenda view to the current one.
2326 This function allows interactive building of block agendas.
2327 Agenda views are separated by `org-agenda-block-separator'."
2329 (unless (string= (buffer-name) org-agenda-buffer-name)
2330 (error "Can only append from within agenda buffer"))
2331 (let ((org-agenda-multi t))
2335 (defun org-agenda-normalize-custom-commands (cmds)
2339 (cond ((stringp (cdr x)) nil)
2340 ((stringp (nth 1 x)) x)
2341 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2342 (t (cons (car x) (cons "" (cdr x))))))
2345 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2346 "The user interface for selecting an agenda command."
2348 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2349 (restrict-ok (and bfn (org-mode-p)))
2350 (region-p (org-region-active-p))
2351 (custom org-agenda-custom-commands)
2353 restriction second-time
2354 c entry key type match prefixes rmheader header-end custom1 desc
2355 line lines left right n n1)
2356 (save-window-excursion
2357 (delete-other-windows)
2358 (org-switch-to-buffer-other-window " *Agenda Commands*")
2360 (insert (eval-when-compile
2363 Press key for an agenda command: < Buffer, subtree/region restriction
2364 -------------------------------- > Remove restriction
2365 a Agenda for current week or day e Export agenda views
2366 t List of all TODO entries T Entries with special TODO kwd
2367 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2368 L Timeline for current buffer # List stuck projects (!=configure)
2369 s Search for keywords C Configure custom agenda commands
2370 / Multi-occur ? Find :FLAGGED: entries
2373 (while (string-match
2374 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2376 (setq start (match-end 0))
2377 (add-text-properties (match-beginning 2) (match-end 2)
2378 '(face bold) header))
2380 (setq header-end (move-marker (make-marker) (point)))
2382 (setq custom1 custom)
2383 (when (eq rmheader t)
2385 (re-search-forward ":" nil t)
2386 (delete-region (match-end 0) (point-at-eol))
2389 (delete-region (match-end 0) (point-at-eol))
2390 (move-marker header-end (match-end 0)))
2391 (goto-char header-end)
2392 (delete-region (point) (point-max))
2394 ;; Produce all the lines that describe custom commands and prefixes
2396 (while (setq entry (pop custom1))
2397 (setq key (car entry) desc (nth 1 entry)
2399 match (nth 3 entry))
2400 (if (> (length key) 1)
2401 (add-to-list 'prefixes (string-to-char key))
2405 (org-add-props (copy-sequence key)
2408 ((string-match "\\S-" desc) desc)
2409 ((eq type 'agenda) "Agenda for current week or day")
2410 ((eq type 'alltodo) "List of all TODO entries")
2411 ((eq type 'search) "Word search")
2412 ((eq type 'stuck) "List of stuck projects")
2413 ((eq type 'todo) "TODO keyword")
2414 ((eq type 'tags) "Tags query")
2415 ((eq type 'tags-todo) "Tags (TODO)")
2416 ((eq type 'tags-tree) "Tags tree")
2417 ((eq type 'todo-tree) "TODO kwd tree")
2418 ((eq type 'occur-tree) "Occur tree")
2419 ((functionp type) (if (symbolp type)
2421 "Lambda expression"))
2423 (if org-agenda-menu-show-matcher
2428 (setq match (copy-sequence match))
2429 (org-add-props match nil 'face 'org-warning))
2431 (format "set of %d commands" (length match)))
2433 (if (org-string-nw-p match)
2434 (add-text-properties
2435 0 (length line) (list 'help-echo
2436 (concat "Matcher: "match)) line)))
2438 (setq lines (nreverse lines))
2443 (org-add-props (char-to-string x)
2445 (or (cdr (assoc (concat selstring
2447 prefix-descriptions))
2452 ;; Check if we should display in two columns
2453 (if org-agenda-menu-two-column
2455 (setq n (length lines)
2456 n1 (+ (/ n 2) (mod n 2))
2457 right (nthcdr n1 lines)
2458 left (copy-sequence lines))
2459 (setcdr (nthcdr (1- n1) left) nil))
2460 (setq left lines right nil))
2462 (insert "\n" (pop left))
2464 (if (< (current-column) 40)
2465 (move-to-column 40 t)
2467 (insert (pop right))))
2469 ;; Make the window the right size
2470 (goto-char (point-min))
2472 (if (not (pos-visible-in-window-p (point-max)))
2473 (org-fit-window-to-buffer))
2474 (setq second-time t)
2475 (org-fit-window-to-buffer))
2477 ;; Ask for selection
2478 (message "Press key for agenda command%s:"
2479 (if (or restrict-ok org-agenda-overriding-restriction)
2480 (if org-agenda-overriding-restriction
2481 " (restriction lock active)"
2483 (format " (restricted to %s)" restriction)
2486 (setq c (read-char-exclusive))
2489 ((assoc (char-to-string c) custom)
2490 (setq selstring (concat selstring (char-to-string c)))
2491 (throw 'exit (cons selstring restriction)))
2493 (setq selstring (concat selstring (char-to-string c))
2495 rmheader (or rmheader t)
2496 custom (delq nil (mapcar
2498 (if (or (= (length (car x)) 1)
2499 (/= (string-to-char (car x)) c))
2501 (cons (substring (car x) 1) (cdr x))))
2503 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2504 (message "Restriction is only possible in Org-mode buffers")
2507 (org-agenda-remove-restriction-lock 'noupdate)
2508 (setq restriction 'buffer))
2510 (org-agenda-remove-restriction-lock 'noupdate)
2511 (setq restriction (if region-p 'region 'subtree)))
2513 (org-agenda-remove-restriction-lock 'noupdate)
2516 ((eq restriction 'buffer)
2517 (if region-p 'region 'subtree))
2518 ((memq restriction '(subtree region))
2522 (org-agenda-remove-restriction-lock 'noupdate)
2523 (setq restriction nil))
2524 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2525 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2526 ((and (> (length selstring) 0) (eq c ?\d))
2528 (org-agenda-get-restriction-and-command prefix-descriptions))
2530 ((equal c ?q) (error "Abort"))
2531 (t (error "Invalid key %c" c))))))))
2533 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2534 (defvar org-agenda-last-arguments nil
2535 "The arguments of the previous call to `org-agenda'.")
2536 (defun org-agenda-run-series (name series)
2537 (org-let (nth 1 series) '(org-prepare-agenda name))
2538 (let* ((org-agenda-multi t)
2539 (redo (list 'org-agenda-run-series name (list 'quote series)))
2540 (org-agenda-overriding-arguments
2541 (or org-agenda-overriding-arguments
2542 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2543 (get 'org-agenda-redo-command 'last-args))))
2545 (gprops (nth 1 series))
2546 match ;; The byte compiler incorrectly complains about this. Keep it!
2548 (while (setq cmd (pop cmds))
2549 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2552 (org-let2 gprops lprops
2553 '(call-interactively 'org-agenda-list)))
2555 (org-let2 gprops lprops
2556 '(call-interactively 'org-todo-list)))
2558 (org-let2 gprops lprops
2559 '(org-search-view current-prefix-arg match nil)))
2561 (org-let2 gprops lprops
2562 '(call-interactively 'org-agenda-list-stuck-projects)))
2564 (org-let2 gprops lprops
2565 '(org-tags-view current-prefix-arg match)))
2566 ((eq type 'tags-todo)
2567 (org-let2 gprops lprops
2568 '(org-tags-view '(4) match)))
2570 (org-let2 gprops lprops
2571 '(org-todo-list match)))
2573 (org-let2 gprops lprops
2574 '(funcall type match)))
2575 (t (error "Invalid type in command series"))))
2577 (setq org-agenda-redo-command redo)
2578 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2579 (goto-char (point-min)))
2580 (org-fit-agenda-window)
2581 (org-let (nth 1 series) '(org-finalize-agenda)))
2584 (defmacro org-batch-agenda (cmd-key &rest parameters)
2585 "Run an agenda command in batch mode and send the result to STDOUT.
2586 If CMD-KEY is a string of length 1, it is used as a key in
2587 `org-agenda-custom-commands' and triggers this command. If it is a
2588 longer string it is used as a tags/todo match string.
2589 Parameters are alternating variable names and values that will be bound
2590 before running the agenda command."
2591 (org-eval-in-environment (org-make-parameter-alist parameters)
2592 (if (> (length cmd-key) 2)
2593 (org-tags-view nil cmd-key)
2594 (org-agenda nil cmd-key)))
2595 (set-buffer org-agenda-buffer-name)
2596 (princ (org-encode-for-stdout (buffer-string))))
2597 (def-edebug-spec org-batch-agenda (form &rest sexp))
2599 ;(defun org-encode-for-stdout (string)
2600 ; (if (fboundp 'encode-coding-string)
2601 ; (encode-coding-string string buffer-file-coding-system)
2604 (defun org-encode-for-stdout (string)
2607 (defvar org-agenda-info nil)
2610 (defmacro org-batch-agenda-csv (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.
2618 The output gives a line for each selected agenda item. Each
2619 item is a list of comma-separated values, like this:
2621 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2623 category The category of the item
2624 head The headline, without TODO kwd, TAGS and PRIORITY
2625 type The type of the agenda entry, can be
2626 todo selected in TODO match
2627 tagsmatch selected in tags match
2628 diary imported from diary
2629 deadline a deadline on given date
2630 scheduled scheduled on given date
2631 timestamp entry has timestamp on given date
2632 closed entry was closed on given date
2633 upcoming-deadline warning about deadline
2634 past-scheduled forwarded scheduled item
2635 block entry has date block including g. date
2636 todo The todo keyword, if any
2637 tags All tags including inherited ones, separated by colons
2638 date The relevant date, like 2007-2-14
2639 time The time, like 15:00-16:50
2640 extra Sting with extra planning info
2641 priority-l The priority letter if any was given
2642 priority-n The computed numerical priority
2643 agenda-day The day in the agenda where this is listed"
2644 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2645 (org-make-parameter-alist parameters))
2646 (if (> (length cmd-key) 2)
2647 (org-tags-view nil cmd-key)
2648 (org-agenda nil cmd-key)))
2649 (set-buffer org-agenda-buffer-name)
2650 (let* ((lines (org-split-string (buffer-string) "\n"))
2652 (while (setq line (pop lines))
2654 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2655 (setq org-agenda-info
2656 (org-fix-agenda-info (text-properties-at 0 line)))
2658 (org-encode-for-stdout
2659 (mapconcat 'org-agenda-export-csv-mapper
2660 '(org-category txt type todo tags date time extra
2661 priority-letter priority agenda-day)
2664 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2666 (defun org-fix-agenda-info (props)
2667 "Make sure all properties on an agenda item have a canonical form.
2668 This ensures the export commands can easily use it."
2670 (when (setq tmp (plist-get props 'tags))
2671 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2672 (when (setq tmp (plist-get props 'date))
2673 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2674 (let ((calendar-date-display-form '(year "-" month "-" day)))
2675 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2677 (setq tmp (calendar-date-string tmp)))
2678 (setq props (plist-put props 'date tmp)))
2679 (when (setq tmp (plist-get props 'day))
2680 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2681 (let ((calendar-date-display-form '(year "-" month "-" day)))
2682 (setq tmp (calendar-date-string tmp)))
2683 (setq props (plist-put props 'day tmp))
2684 (setq props (plist-put props 'agenda-day tmp)))
2685 (when (setq tmp (plist-get props 'txt))
2686 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2687 (plist-put props 'priority-letter (match-string 1 tmp))
2688 (setq tmp (replace-match "" t t tmp)))
2689 (when (and (setq re (plist-get props 'org-todo-regexp))
2690 (setq re (concat "\\`\\.*" re " ?"))
2691 (string-match re tmp))
2692 (plist-put props 'todo (match-string 1 tmp))
2693 (setq tmp (replace-match "" t t tmp)))
2694 (plist-put props 'txt tmp)))
2697 (defun org-agenda-export-csv-mapper (prop)
2698 (let ((res (plist-get org-agenda-info prop)))
2703 (t (prin1-to-string res))))
2704 (while (string-match "," res)
2705 (setq res (replace-match ";" t t res)))
2710 (defun org-store-agenda-views (&rest parameters)
2712 (eval (list 'org-batch-store-agenda-views)))
2715 (defmacro org-batch-store-agenda-views (&rest parameters)
2716 "Run all custom agenda commands that have a file argument."
2717 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2719 (dir default-directory)
2720 (pars (org-make-parameter-alist parameters))
2721 cmd thiscmdkey files opts cmd-or-set)
2722 (save-window-excursion
2724 (setq cmd (pop cmds)
2725 thiscmdkey (car cmd)
2726 cmd-or-set (nth 2 cmd)
2727 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2728 files (nth (if (listp cmd-or-set) 4 5) cmd))
2729 (if (stringp files) (setq files (list files)))
2731 (org-eval-in-environment (append org-agenda-exporter-settings
2733 (org-agenda nil thiscmdkey))
2734 (set-buffer org-agenda-buffer-name)
2736 (org-eval-in-environment (append org-agenda-exporter-settings
2738 (org-write-agenda (expand-file-name (pop files) dir) nil t)))
2739 (and (get-buffer org-agenda-buffer-name)
2740 (kill-buffer org-agenda-buffer-name)))))))
2741 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2743 (defun org-agenda-mark-header-line (pos)
2744 "Mark the line at POS as an agenda structure header."
2747 (put-text-property (point-at-bol) (point-at-eol)
2748 'org-agenda-structural-header t)
2749 (when org-agenda-title-append
2750 (put-text-property (point-at-bol) (point-at-eol)
2751 'org-agenda-title-append org-agenda-title-append))))
2753 (defvar org-mobile-creating-agendas)
2754 (defun org-write-agenda (file &optional open nosettings)
2755 "Write the current buffer (an agenda view) as a file.
2756 Depending on the extension of the file name, plain text (.txt),
2757 HTML (.html or .htm) or Postscript (.ps) is produced.
2758 If the extension is .ics, run icalendar export over all files used
2759 to construct the agenda and limit the export to entries listed in the
2761 With prefix argument OPEN, open the new file immediately.
2762 If NOSETTINGS is given, do not scope the settings of
2763 `org-agenda-exporter-settings' into the export commands. This is used when
2764 the settings have already been scoped and we do not wish to overrule other,
2765 higher priority settings."
2766 (interactive "FWrite agenda to file: \nP")
2767 (if (not (file-writable-p file))
2768 (error "Cannot write agenda to file %s" file))
2769 (org-let (if nosettings nil org-agenda-exporter-settings)
2771 (save-window-excursion
2772 (org-agenda-mark-filtered-text)
2773 (let ((bs (copy-sequence (buffer-string))) beg)
2774 (org-agenda-unmark-filtered-text)
2776 (rename-buffer "Agenda View" t)
2777 (set-buffer-modified-p nil)
2779 (org-agenda-remove-marked-text 'org-filtered)
2780 (while (setq beg (text-property-any (point-min) (point-max)
2783 beg (or (next-single-property-change beg 'org-filtered)
2785 (run-hooks 'org-agenda-before-write-hook)
2787 ((org-bound-and-true-p org-mobile-creating-agendas)
2788 (org-mobile-write-agenda-for-mobile file))
2789 ((string-match "\\.html?\\'" file)
2791 (set-buffer (htmlize-buffer (current-buffer)))
2793 (when (and org-agenda-export-html-style
2794 (string-match "<style>" org-agenda-export-html-style))
2795 ;; replace <style> section with org-agenda-export-html-style
2796 (goto-char (point-min))
2797 (kill-region (- (search-forward "<style") 6)
2798 (search-forward "</style>"))
2799 (insert org-agenda-export-html-style))
2801 (kill-buffer (current-buffer))
2802 (message "HTML written to %s" file))
2803 ((string-match "\\.ps\\'" file)
2805 (ps-print-buffer-with-faces file)
2806 (message "Postscript written to %s" file))
2807 ((string-match "\\.pdf\\'" file)
2809 (ps-print-buffer-with-faces
2810 (concat (file-name-sans-extension file) ".ps"))
2811 (call-process "ps2pdf" nil nil nil
2813 (concat (file-name-sans-extension file) ".ps"))
2814 (expand-file-name file))
2815 (delete-file (concat (file-name-sans-extension file) ".ps"))
2816 (message "PDF written to %s" file))
2817 ((string-match "\\.ics\\'" file)
2818 (require 'org-icalendar)
2819 (let ((org-agenda-marker-table
2820 (org-create-marker-find-array
2821 (org-agenda-collect-markers)))
2822 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2823 (org-combined-agenda-icalendar-file file))
2824 (apply 'org-export-icalendar 'combine
2825 (org-agenda-files nil 'ifmode))))
2827 (let ((bs (buffer-string)))
2832 (kill-buffer (current-buffer))
2833 (message "Plain text written to %s" file))))))))
2834 (set-buffer org-agenda-buffer-name))
2835 (when open (org-open-file file)))
2837 (defvar org-agenda-filter-overlays nil)
2839 (defun org-agenda-mark-filtered-text ()
2840 "Mark all text hidden by filtering with a text property."
2841 (let ((inhibit-read-only t))
2844 (when (equal (overlay-buffer o) (current-buffer))
2846 (overlay-start o) (overlay-end o)
2848 org-agenda-filter-overlays)))
2850 (defun org-agenda-unmark-filtered-text ()
2851 "Remove the filtering text property."
2852 (let ((inhibit-read-only t))
2853 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2855 (defun org-agenda-remove-marked-text (property &optional value)
2856 "Delete all text marked with VALUE of PROPERTY.
2857 VALUE defaults to t."
2859 (setq value (or value t))
2860 (while (setq beg (text-property-any (point-min) (point-max)
2863 beg (or (next-single-property-change beg 'org-filtered)
2866 (defun org-agenda-add-entry-text ()
2867 "Add entry text to agenda lines.
2868 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2869 entry text following headings shown in the agenda.
2870 Drawers will be excluded, also the line with scheduling/deadline info."
2871 (when (and (> org-agenda-add-entry-text-maxlines 0)
2872 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2874 (goto-char (point-min))
2876 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2877 (beginning-of-line 2)
2878 (setq txt (org-agenda-get-some-entry-text
2879 m org-agenda-add-entry-text-maxlines " > "))
2881 (if (string-match "\\S-" txt)
2883 (or (eobp) (forward-char 1))))))))
2885 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2887 "Extract entry text from MARKER, at most N-LINES lines.
2888 This will ignore drawers etc, just get the text.
2889 If INDENT is given, prefix every line with this string. If KEEP is
2890 given, it is a list of symbols, defining stuff that should not be
2891 removed from the entry content. Currently only `planning' is allowed here."
2892 (let (txt drawer-re kwd-time-re ind)
2894 (with-current-buffer (marker-buffer marker)
2895 (if (not (org-mode-p))
2902 (setq txt (buffer-substring
2903 (min (1+ (point)) (point-max))
2904 (progn (outline-next-heading) (point)))
2905 drawer-re org-drawer-regexp
2906 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2910 (when org-agenda-add-entry-text-descriptive-links
2911 (goto-char (point-min))
2912 (while (org-activate-bracket-links (point-max))
2913 (add-text-properties (match-beginning 0) (match-end 0)
2915 (goto-char (point-min))
2916 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2917 (set-text-properties (match-beginning 0) (match-end 0)
2919 (goto-char (point-min))
2920 (while (re-search-forward drawer-re nil t)
2923 (progn (re-search-forward
2924 "^[ \t]*:END:.*\n?" nil 'move)
2926 (unless (member 'planning keep)
2927 (goto-char (point-min))
2928 (while (re-search-forward kwd-time-re nil t)
2929 (replace-match "")))
2930 (goto-char (point-min))
2931 (when org-agenda-entry-text-exclude-regexps
2932 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2933 (while (setq re (pop re-list))
2934 (goto-char (point-min))
2935 (while (re-search-forward re nil t)
2936 (replace-match "")))))
2937 (goto-char (point-max))
2938 (skip-chars-backward " \t\n")
2939 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2941 ;; find and remove min common indentation
2942 (goto-char (point-min))
2943 (untabify (point-min) (point-max))
2944 (setq ind (org-get-indentation))
2946 (unless (looking-at "[ \t]*$")
2947 (setq ind (min ind (org-get-indentation))))
2948 (beginning-of-line 2))
2949 (goto-char (point-min))
2951 (unless (looking-at "[ \t]*$")
2952 (move-to-column ind)
2953 (delete-region (point-at-bol) (point)))
2954 (beginning-of-line 2))
2956 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2958 (goto-char (point-min))
2960 (while (and (not (eobp)) (re-search-forward "^" nil t))
2961 (replace-match indent t t)))
2962 (goto-char (point-min))
2963 (while (looking-at "[ \t]*\n") (replace-match ""))
2964 (goto-char (point-max))
2965 (when (> (org-current-line)
2967 (org-goto-line (1+ n-lines))
2969 (setq txt (buffer-substring (point-min) (point)))))))))
2972 (defun org-agenda-collect-markers ()
2973 "Collect the markers pointing to entries in the agenda buffer."
2976 (goto-char (point-min))
2978 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2979 (org-get-at-bol 'org-marker)))
2981 (beginning-of-line 2)))
2982 (nreverse markers)))
2984 (defun org-create-marker-find-array (marker-list)
2985 "Create a alist of files names with all marker positions in that file."
2987 (while (setq m (pop marker-list))
2988 (setq p (marker-position m)
2989 f (buffer-file-name (or (buffer-base-buffer
2991 (marker-buffer m))))
2992 (if (setq a (assoc f tbl))
2993 (push (marker-position m) (cdr a))
2994 (push (list f p) tbl)))
2995 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2998 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2999 (defun org-check-agenda-marker-table ()
3000 "Check of the current entry is on the marker list."
3001 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3003 (and (setq a (assoc file org-agenda-marker-table))
3006 (org-back-to-heading t)
3007 (member (point) (cdr a)))))))
3009 (defun org-check-for-org-mode ()
3010 "Make sure current buffer is in org-mode. Error if not."
3012 (error "Cannot execute org-mode agenda command on buffer in %s"
3015 (defun org-fit-agenda-window ()
3016 "Fit the window to the buffer size."
3017 (and (memq org-agenda-window-setup '(reorganize-frame))
3018 (fboundp 'fit-window-to-buffer)
3019 (org-fit-window-to-buffer
3021 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3022 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3024 ;;; Agenda prepare and finalize
3026 (defvar org-agenda-multi nil) ; dynamically scoped
3027 (defvar org-agenda-buffer-name "*Org Agenda*")
3028 (defvar org-pre-agenda-window-conf nil)
3029 (defvar org-agenda-columns-active nil)
3030 (defvar org-agenda-name nil)
3031 (defvar org-agenda-filter nil)
3032 (defvar org-agenda-filter-while-redo nil)
3033 (defvar org-agenda-filter-preset nil
3034 "A preset of the tags filter used for secondary agenda filtering.
3035 This must be a list of strings, each string must be a single tag preceded
3037 This variable should not be set directly, but agenda custom commands can
3038 bind it in the options section. The preset filter is a global property of
3039 the entire agenda view. In a block agenda, it will not work reliably to
3040 define a filter for one of the individual blocks. You need to set it in
3041 the global options and expect it to be applied to the entire view.")
3043 (defun org-prepare-agenda (&optional name)
3044 (setq org-todo-keywords-for-agenda nil)
3045 (setq org-done-keywords-for-agenda nil)
3046 (setq org-drawers-for-agenda nil)
3047 (unless org-agenda-persistent-filter
3048 (setq org-agenda-filter nil))
3049 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
3050 (if org-agenda-multi
3052 (setq buffer-read-only nil)
3053 (goto-char (point-max))
3054 (unless (or (bobp) org-agenda-compact-blocks
3055 (not org-agenda-block-separator))
3057 (if (stringp org-agenda-block-separator)
3058 org-agenda-block-separator
3059 (make-string (window-width) org-agenda-block-separator))
3061 (narrow-to-region (point) (point-max)))
3062 (org-agenda-reset-markers)
3063 (setq org-agenda-contributing-files nil)
3064 (setq org-agenda-columns-active nil)
3065 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3066 (setq org-todo-keywords-for-agenda
3067 (org-uniquify org-todo-keywords-for-agenda))
3068 (setq org-done-keywords-for-agenda
3069 (org-uniquify org-done-keywords-for-agenda))
3070 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3071 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
3072 (awin (get-buffer-window abuf)))
3074 ((equal (current-buffer) abuf) nil)
3075 (awin (select-window awin))
3076 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3077 ((equal org-agenda-window-setup 'current-window)
3078 (org-pop-to-buffer-same-window abuf))
3079 ((equal org-agenda-window-setup 'other-window)
3080 (org-switch-to-buffer-other-window abuf))
3081 ((equal org-agenda-window-setup 'other-frame)
3082 (switch-to-buffer-other-frame abuf))
3083 ((equal org-agenda-window-setup 'reorganize-frame)
3084 (delete-other-windows)
3085 (org-switch-to-buffer-other-window abuf)))
3086 ;; additional test in case agenda is invoked from within agenda
3087 ;; buffer via elisp link
3088 (unless (equal (current-buffer) abuf)
3089 (org-pop-to-buffer-same-window abuf)))
3090 (setq buffer-read-only nil)
3091 (let ((inhibit-read-only t)) (erase-buffer))
3093 (and name (not org-agenda-name)
3094 (org-set-local 'org-agenda-name name)))
3095 (setq buffer-read-only nil))
3097 (defun org-finalize-agenda ()
3098 "Finishing touch for the agenda buffer, called just before displaying it."
3099 (unless org-agenda-multi
3101 (let ((inhibit-read-only t))
3102 (goto-char (point-min))
3103 (while (org-activate-bracket-links (point-max))
3104 (add-text-properties (match-beginning 0) (match-end 0)
3106 (org-agenda-align-tags)
3107 (unless org-agenda-with-colors
3108 (remove-text-properties (point-min) (point-max) '(face nil))))
3109 (if (and (boundp 'org-agenda-overriding-columns-format)
3110 org-agenda-overriding-columns-format)
3111 (org-set-local 'org-agenda-overriding-columns-format
3112 org-agenda-overriding-columns-format))
3113 (if (and (boundp 'org-agenda-view-columns-initially)
3114 org-agenda-view-columns-initially)
3115 (org-agenda-columns))
3116 (when org-agenda-fontify-priorities
3117 (org-agenda-fontify-priorities))
3118 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3119 (org-agenda-dim-blocked-tasks))
3120 (org-agenda-mark-clocking-task)
3121 (when org-agenda-entry-text-mode
3122 (org-agenda-entry-text-hide)
3123 (org-agenda-entry-text-show))
3124 (if (functionp 'org-habit-insert-consistency-graphs)
3125 (org-habit-insert-consistency-graphs))
3126 (run-hooks 'org-finalize-agenda-hook)
3127 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3128 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
3129 (org-agenda-filter-apply org-agenda-filter))
3132 (defun org-agenda-mark-clocking-task ()
3133 "Mark the current clock entry in the agenda if it is present."
3135 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3136 (delete-overlay o)))
3137 (overlays-in (point-min) (point-max)))
3138 (when (marker-buffer org-clock-hd-marker)
3140 (goto-char (point-min))
3142 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3144 (when (equal (org-get-at-bol 'org-hd-marker)
3145 org-clock-hd-marker)
3146 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3147 (overlay-put ov 'type 'org-agenda-clocking)
3148 (overlay-put ov 'face 'org-agenda-clocking)
3149 (overlay-put ov 'help-echo
3150 "The clock is running in this item")))))))
3152 (defun org-agenda-fontify-priorities ()
3153 "Make highest priority lines bold, and lowest italic."
3155 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3156 (delete-overlay o)))
3157 (overlays-in (point-min) (point-max)))
3159 (let ((inhibit-read-only t)
3161 (goto-char (point-min))
3162 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3163 (setq h (or (get-char-property (point) 'org-highest-priority)
3164 org-highest-priority)
3165 l (or (get-char-property (point) 'org-lowest-priority)
3166 org-lowest-priority)
3167 p (string-to-char (match-string 1))
3168 b (match-beginning 0)
3169 e (if (eq org-agenda-fontify-priorities 'cookies)
3172 ov (make-overlay b e))
3175 (cond ((org-face-from-face-or-color
3177 (cdr (assoc p org-priority-faces))))
3178 ((and (listp org-agenda-fontify-priorities)
3179 (org-face-from-face-or-color
3181 (cdr (assoc p org-agenda-fontify-priorities)))))
3182 ((equal p l) 'italic)
3183 ((equal p h) 'bold)))
3184 (overlay-put ov 'org-type 'org-priority)))))
3186 (defun org-agenda-dim-blocked-tasks ()
3187 "Dim currently blocked TODO's in the agenda display."
3188 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3189 (delete-overlay o)))
3190 (overlays-in (point-min) (point-max)))
3192 (let ((inhibit-read-only t)
3193 (org-depend-tag-blocked nil)
3194 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3195 org-blocked-by-checkboxes
3196 invis1 b e p ov h l)
3197 (goto-char (point-min))
3198 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3199 (and pos (goto-char (1+ pos))))
3200 (setq org-blocked-by-checkboxes nil invis1 invis)
3201 (let ((marker (org-get-at-bol 'org-hd-marker)))
3203 (not (with-current-buffer (marker-buffer marker)
3206 (if (org-entry-get nil "NOBLOCKING")
3207 t ;; Never block this entry
3208 (run-hook-with-args-until-failure
3210 (list :type 'todo-state-change
3214 (if org-blocked-by-checkboxes (setq invis1 nil))
3216 (max (point-min) (1- (point-at-bol)))
3219 ov (make-overlay b e))
3221 (overlay-put ov 'invisible t)
3222 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3223 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3225 (defvar org-agenda-skip-function nil
3226 "Function to be called at each match during agenda construction.
3227 If this function returns nil, the current match should not be skipped.
3228 Otherwise, the function must return a position from where the search
3229 should be continued.
3230 This may also be a Lisp form, it will be evaluated.
3231 Never set this variable using `setq' or so, because then it will apply
3232 to all future agenda commands. If you do want a global skipping condition,
3233 use the option `org-agenda-skip-function-global' instead.
3234 The correct usage for `org-agenda-skip-function' is to bind it with
3235 `let' to scope it dynamically into the agenda-constructing command.
3236 A good way to set it is through options in `org-agenda-custom-commands'.")
3238 (defun org-agenda-skip ()
3239 "Throw to `:skip' in places that should be skipped.
3240 Also moves point to the end of the skipped region, so that search can
3241 continue from there."
3242 (let ((p (point-at-bol)) to)
3243 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3244 (get-text-property p :org-archived)
3245 (org-end-of-subtree t)
3247 (and org-agenda-skip-comment-trees
3248 (get-text-property p :org-comment)
3249 (org-end-of-subtree t)
3251 (if (equal (char-after p) ?#) (throw :skip t))
3252 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3253 (org-agenda-skip-eval org-agenda-skip-function)))
3257 (defun org-agenda-skip-eval (form)
3258 "If FORM is a function or a list, call (or eval) is and return result.
3259 `save-excursion' and `save-match-data' are wrapped around the call, so point
3260 and match data are returned to the previous state no matter what these
3264 (or (setq fp (functionp form))
3272 (defvar org-agenda-markers nil
3273 "List of all currently active markers created by `org-agenda'.")
3274 (defvar org-agenda-last-marker-time (org-float-time)
3275 "Creation time of the last agenda marker.")
3277 (defun org-agenda-new-marker (&optional pos)
3278 "Return a new agenda marker.
3279 Org-mode keeps a list of these markers and resets them when they are
3281 (let ((m (copy-marker (or pos (point)))))
3282 (setq org-agenda-last-marker-time (org-float-time))
3283 (push m org-agenda-markers)
3286 (defun org-agenda-reset-markers ()
3287 "Reset markers created by `org-agenda'."
3288 (while org-agenda-markers
3289 (move-marker (pop org-agenda-markers) nil)))
3291 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3292 "Save relative positions of markers in region."
3293 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3294 org-agenda-markers))
3298 (defun org-agenda-entry-text-show-here ()
3299 "Add some text from the entry as context to the current line."
3301 (setq m (org-get-at-bol 'org-hd-marker))
3302 (unless (marker-buffer m)
3303 (error "No marker points to an entry here"))
3304 (setq txt (concat "\n" (org-no-properties
3305 (org-agenda-get-some-entry-text
3306 m org-agenda-entry-text-maxlines " > "))))
3307 (when (string-match "\\S-" txt)
3308 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3309 (overlay-put o 'evaporate t)
3310 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3311 (overlay-put o 'after-string txt))))
3313 (defun org-agenda-entry-text-show ()
3314 "Add entry context for all agenda lines."
3317 (goto-char (point-max))
3318 (beginning-of-line 1)
3320 (when (org-get-at-bol 'org-hd-marker)
3321 (org-agenda-entry-text-show-here))
3322 (beginning-of-line 0))))
3324 (defun org-agenda-entry-text-hide ()
3325 "Remove any shown entry context."
3328 (if (eq (overlay-get o 'org-overlay-type)
3329 'agenda-entry-content)
3330 (progn (delete-overlay o) t)))
3331 (overlays-in (point-min) (point-max)))))
3333 (defun org-agenda-get-day-face (date)
3334 "Return the face DATE should be displayed with."
3335 (or (and (functionp org-agenda-day-face-function)
3336 (funcall org-agenda-day-face-function date))
3337 (cond ((org-agenda-todayp date)
3338 'org-agenda-date-today)
3339 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3340 'org-agenda-date-weekend)
3341 (t 'org-agenda-date))))
3345 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3347 (defun org-timeline (&optional dotodo)
3348 "Show a time-sorted view of the entries in the current org file.
3349 Only entries with a time stamp of today or later will be listed. With
3350 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3351 under the current date.
3352 If the buffer contains an active region, only check the region for
3355 (org-compile-prefix-format 'timeline)
3356 (org-set-sorting-strategy 'timeline)
3358 (doclosed org-agenda-show-log)
3359 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3361 (date (calendar-current-date))
3362 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3363 (end (if (org-region-active-p) (region-end) (point-max)))
3364 (day-numbers (org-get-all-dates beg end 'no-ranges
3365 t doclosed ; always include today
3366 org-timeline-show-empty-dates))
3367 (org-deadline-warning-days 0)
3368 (org-agenda-only-exact-dates t)
3373 (setq org-agenda-redo-command
3375 (list 'org-switch-to-buffer-other-window (current-buffer))
3376 (list 'org-timeline (list 'quote dotodo))))
3378 ;; Remove past dates from the list of dates.
3379 (setq day-numbers (delq nil (mapcar (lambda(x)
3380 (if (>= x today) x nil))
3382 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3383 (if doclosed (push :closed args))
3384 (push :timestamp args)
3385 (push :deadline args)
3386 (push :scheduled args)
3388 (if dotodo (push :todo args))
3389 (insert "Timeline of file " entry "\n")
3390 (add-text-properties (point-min) (point)
3391 (list 'face 'org-agenda-structure))
3392 (org-agenda-mark-header-line (point-min))
3393 (while (setq d (pop day-numbers))
3394 (if (and (listp d) (eq (car d) :omitted))
3397 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3398 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3399 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3400 (if (and (>= d today)
3405 (insert (make-string 79 ?-) "\n")))
3406 (setq date (calendar-gregorian-from-absolute d))
3408 (setq rtn (and (not emptyp)
3409 (apply 'org-agenda-get-day-entries entry
3411 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3414 (if (stringp org-agenda-format-date)
3415 (format-time-string org-agenda-format-date
3416 (org-time-from-absolute date))
3417 (funcall org-agenda-format-date date))
3419 (put-text-property s (1- (point)) 'face
3420 (org-agenda-get-day-face date))
3421 (put-text-property s (1- (point)) 'org-date-line t)
3422 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3424 (put-text-property s (1- (point)) 'org-today t))
3425 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3426 (put-text-property s (1- (point)) 'day d)))))
3427 (goto-char (point-min))
3428 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3430 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3431 (org-finalize-agenda)
3432 (setq buffer-read-only t)))
3434 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3435 "Return a list of all relevant day numbers from BEG to END buffer positions.
3436 If NO-RANGES is non-nil, include only the start and end dates of a range,
3437 not every single day in the range. If FORCE-TODAY is non-nil, make
3438 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3439 inactive time stamps (those in square brackets) are included.
3440 When EMPTY is non-nil, also include days without any entries."
3442 (if pre-re pre-re "")
3443 (if inactive org-ts-regexp-both org-ts-regexp)))
3444 dates dates1 date day day1 day2 ts1 ts2)
3446 (setq dates (list (org-today))))
3449 (while (re-search-forward re end t)
3450 (setq day (time-to-days (org-time-string-to-time
3451 (substring (match-string 1) 0 10))))
3452 (or (memq day dates) (push day dates)))
3455 (while (re-search-forward org-tr-regexp end t)
3456 (setq ts1 (substring (match-string 1) 0 10)
3457 ts2 (substring (match-string 2) 0 10)
3458 day1 (time-to-days (org-time-string-to-time ts1))
3459 day2 (time-to-days (org-time-string-to-time ts2)))
3460 (while (< (setq day1 (1+ day1)) day2)
3461 (or (memq day1 dates) (push day1 dates)))))
3462 (setq dates (sort dates '<))
3464 (while (setq day (pop dates))
3465 (setq day2 (car dates))
3467 (when (and day2 empty)
3468 (if (or (eq empty t)
3469 (and (numberp empty) (<= (- day2 day) empty)))
3470 (while (< (setq day (1+ day)) day2)
3471 (push (list day) dates1))
3472 (push (cons :omitted (- day2 day)) dates1))))
3473 (setq dates (nreverse dates1)))
3476 ;;; Agenda Daily/Weekly
3478 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3479 "Start day for the agenda view.
3480 Custom commands can set this variable in the options section.")
3481 (defvar org-starting-day nil) ; local variable in the agenda buffer
3482 (defvar org-agenda-current-span nil
3483 "The current span used in the agenda view.") ; local variable in the agenda buffer
3484 (defvar org-arg-loc nil) ; local variable
3486 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3487 "List of types searched for when creating the daily/weekly agenda.
3488 This variable is a list of symbols that controls the types of
3489 items that appear in the daily/weekly agenda. Allowed symbols in this
3492 :timestamp List items containing a date stamp or date range matching
3493 the selected date. This includes sexp entries in
3496 :sexp List entries resulting from plain diary-like sexps.
3498 :deadline List deadline due on that date. When the date is today,
3499 also list any deadlines past due, or due within
3500 `org-deadline-warning-days'. `:deadline' must appear before
3501 `:scheduled' if the setting of
3502 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3505 :scheduled List all items which are scheduled for the given date.
3506 The diary for *today* also contains items which were
3507 scheduled earlier and are not yet marked DONE.
3509 By default, all four types are turned on.
3511 Never set this variable globally using `setq', because then it
3512 will apply to all future agenda commands. Instead, bind it with
3513 `let' to scope it dynamically into the agenda-constructing
3514 command. A good way to set it is through options in
3515 `org-agenda-custom-commands'. For a more flexible (though
3516 somewhat less efficient) way of determining what is included in
3517 the daily/weekly agenda, see `org-agenda-skip-function'.")
3520 (defun org-agenda-list (&optional arg start-day span)
3521 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3522 The view will be for the current day or week, but from the overview buffer
3523 you will be able to go to other days/weeks.
3525 With a numeric prefix argument in an interactive call, the agenda will
3526 span ARG days. Lisp programs should instead specify SPAN to change
3527 the number of days. SPAN defaults to `org-agenda-span'.
3529 START-DAY defaults to TODAY, or to the most recent match for the weekday
3530 given in `org-agenda-start-on-weekday'."
3532 (if (and (integerp arg) (> arg 0))
3533 (setq span arg arg nil))
3534 (setq start-day (or start-day org-agenda-start-day))
3535 (if org-agenda-overriding-arguments
3536 (setq arg (car org-agenda-overriding-arguments)
3537 start-day (nth 1 org-agenda-overriding-arguments)
3538 span (nth 2 org-agenda-overriding-arguments)))
3539 (if (stringp start-day)
3540 ;; Convert to an absolute day number
3541 (setq start-day (time-to-days (org-read-date nil t start-day))))
3542 (setq org-agenda-last-arguments (list arg start-day span))
3543 (org-compile-prefix-format 'agenda)
3544 (org-set-sorting-strategy 'agenda)
3545 (let* ((span (org-agenda-ndays-to-span
3546 (or span org-agenda-ndays org-agenda-span)))
3548 (sd (or start-day today))
3549 (ndays (org-agenda-span-to-ndays span sd))
3550 (org-agenda-start-on-weekday
3552 org-agenda-start-on-weekday))
3553 (thefiles (org-agenda-files nil 'ifmode))
3555 (start (if (or (null org-agenda-start-on-weekday)
3558 (let* ((nt (calendar-day-of-week
3559 (calendar-gregorian-from-absolute sd)))
3560 (n1 org-agenda-start-on-weekday)
3562 (- sd (+ (if (< d 0) 7 0) d)))))
3563 (day-numbers (list start))
3565 (inhibit-redisplay (not debug-on-error))
3566 s e rtn rtnall file date d start-pos end-pos todayp
3567 clocktable-start clocktable-end filter)
3568 (setq org-agenda-redo-command
3569 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3570 (dotimes (n (1- ndays))
3571 (push (1+ (car day-numbers)) day-numbers))
3572 (setq day-numbers (nreverse day-numbers))
3573 (setq clocktable-start (car day-numbers)
3574 clocktable-end (1+ (or (org-last day-numbers) 0)))
3575 (org-prepare-agenda "Day/Week")
3576 (org-set-local 'org-starting-day (car day-numbers))
3577 (org-set-local 'org-arg-loc arg)
3578 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3579 (unless org-agenda-compact-blocks
3580 (let* ((d1 (car day-numbers))
3581 (d2 (org-last day-numbers))
3582 (w1 (org-days-to-iso-week d1))
3583 (w2 (org-days-to-iso-week d2)))
3585 (if org-agenda-overriding-header
3586 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3587 nil 'face 'org-agenda-structure) "\n")
3588 (insert (org-agenda-span-name span)
3590 (if (< (- d2 d1) 350)
3592 (format " (W%02d)" w1)
3593 (format " (W%02d-W%02d)" w1 w2))
3596 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3598 (org-agenda-mark-header-line s))
3599 (while (setq d (pop day-numbers))
3600 (setq date (calendar-gregorian-from-absolute d)
3602 (if (or (setq todayp (= d today))
3603 (and (not start-pos) (= d sd)))
3604 (setq start-pos (point))
3605 (if (and start-pos (not end-pos))
3606 (setq end-pos (point))))
3607 (setq files thefiles
3609 (while (setq file (pop files))
3611 (org-check-agenda-file file)
3612 (let ((org-agenda-entry-types org-agenda-entry-types))
3613 (unless org-agenda-include-deadlines
3614 (setq org-agenda-entry-types
3615 (delq :deadline org-agenda-entry-types)))
3617 ((memq org-agenda-show-log '(only clockcheck))
3618 (setq rtn (org-agenda-get-day-entries
3619 file date :closed)))
3620 (org-agenda-show-log
3621 (setq rtn (apply 'org-agenda-get-day-entries
3623 (append '(:closed) org-agenda-entry-types))))
3625 (setq rtn (apply 'org-agenda-get-day-entries
3627 org-agenda-entry-types)))))
3628 (setq rtnall (append rtnall rtn))))
3629 (if org-agenda-include-diary
3630 (let ((org-agenda-search-headline-for-time t))
3631 (require 'diary-lib)
3632 (setq rtn (org-get-entries-from-diary date))
3633 (setq rtnall (append rtnall rtn))))
3634 (if (or rtnall org-agenda-show-all-dates)
3636 (setq day-cnt (1+ day-cnt))
3638 (if (stringp org-agenda-format-date)
3639 (format-time-string org-agenda-format-date
3640 (org-time-from-absolute date))
3641 (funcall org-agenda-format-date date))
3643 (put-text-property s (1- (point)) 'face
3644 (org-agenda-get-day-face date))
3645 (put-text-property s (1- (point)) 'org-date-line t)
3646 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3647 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3649 (put-text-property s (1- (point)) 'org-today t))
3651 (org-finalize-agenda-entries
3652 (org-agenda-add-time-grid-maybe
3653 rtnall ndays todayp))
3655 (put-text-property s (1- (point)) 'day d)
3656 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3657 (when (and org-agenda-clockreport-mode clocktable-start)
3658 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3659 ;; the above line is to ensure the restricted range!
3660 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3662 (setq p (org-plist-delete p :block))
3663 (setq p (plist-put p :tstart clocktable-start))
3664 (setq p (plist-put p :tend clocktable-end))
3665 (setq p (plist-put p :scope 'agenda))
3666 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3667 (setq filter (or org-agenda-filter-while-redo
3668 (get 'org-agenda-filter :preset-filter))))
3669 (setq p (plist-put p :tags (mapconcat (lambda (x)
3670 (if (string-match "[<>=]" x)
3674 (setq tbl (apply 'org-get-clocktable p))
3676 (goto-char (point-min))
3677 (or org-agenda-multi (org-fit-agenda-window))
3678 (unless (and (pos-visible-in-window-p (point-min))
3679 (pos-visible-in-window-p (point-max)))
3680 (goto-char (1- (point-max)))
3682 (if (not (pos-visible-in-window-p (or start-pos 1)))
3684 (goto-char (or start-pos 1))
3686 (goto-char (or start-pos 1))
3687 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3688 (if (eq org-agenda-show-log 'clockcheck)
3689 (org-agenda-show-clocking-issues))
3690 (org-finalize-agenda)
3691 (setq buffer-read-only t)
3694 (defun org-agenda-ndays-to-span (n)
3695 "Return a span symbol for a span of N days, or N if none matches."
3696 (cond ((symbolp n) n)
3701 (defun org-agenda-span-to-ndays (span start-day)
3702 "Return ndays from SPAN starting at START-DAY."
3703 (cond ((numberp span) span)
3707 (let ((date (calendar-gregorian-from-absolute start-day)))
3708 (calendar-last-day-of-month (car date) (caddr date))))
3710 (let ((date (calendar-gregorian-from-absolute start-day)))
3711 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3713 (defun org-agenda-span-name (span)
3714 "Return a SPAN name."
3718 (capitalize (symbol-name span))
3719 (format "%d days" span))))
3721 ;;; Agenda word search
3723 (defvar org-agenda-search-history nil)
3724 (defvar org-todo-only nil)
3726 (defvar org-search-syntax-table nil
3727 "Special syntax table for org-mode search.
3728 In this table, we have single quotes not as word constituents, to
3729 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3731 (defun org-search-syntax-table ()
3732 (unless org-search-syntax-table
3733 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3734 (modify-syntax-entry ?' "." org-search-syntax-table)
3735 (modify-syntax-entry ?` "." org-search-syntax-table))
3736 org-search-syntax-table)
3738 (defvar org-agenda-last-search-view-search-was-boolean nil)
3741 (defun org-search-view (&optional todo-only string edit-at)
3742 "Show all entries that contain a phrase or words or regular expressions.
3744 With optional prefix argument TODO-ONLY, only consider entries that are
3745 TODO entries. The argument STRING can be used to pass a default search
3746 string into this function. If EDIT-AT is non-nil, it means that the
3747 user should get a chance to edit this string, with cursor at position
3750 The search string can be viewed either as a phrase that should be found as
3751 is, or it can be broken into a number of snippets, each of which must match
3752 in a Boolean way to select an entry. The default depends on the variable
3753 `org-agenda-search-view-always-boolean'.
3754 Even if this is turned off (the default) you can always switch to
3755 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3757 The default is a direct search of the whole phrase, where each space in
3758 the search string can expand to an arbitrary amount of whitespace,
3761 If using a Boolean search, the search string is split on whitespace and
3762 each snippet is searched separately, with logical AND to select an entry.
3763 Words prefixed with a minus must *not* occur in the entry. Words without
3764 a prefix or prefixed with a plus must occur in the entry. Matching is
3765 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3766 match whole words, not parts of a word) if
3767 `org-agenda-search-view-force-full-words' is set (default is nil).
3769 Boolean search snippets enclosed by curly braces are interpreted as
3770 regular expressions that must or (when preceded with \"-\") must not
3771 match in the entry. Snippets enclosed into double quotes will be taken
3772 as a whole, to include whitespace.
3774 - If the search string starts with an asterisk, search only in headlines.
3775 - If (possibly after the leading star) the search string starts with an
3776 exclamation mark, this also means to look at TODO entries only, an effect
3777 that can also be achieved with a prefix argument.
3778 - If (possibly after star and exclamation mark) the search string starts
3779 with a colon, this will mean that the (non-regexp) snippets of the
3780 Boolean search must match as full words.
3782 This command searches the agenda files, and in addition the files listed
3783 in `org-agenda-text-search-extra-files'."
3785 (org-compile-prefix-format 'search)
3786 (org-set-sorting-strategy 'search)
3787 (org-prepare-agenda "SEARCH")
3788 (let* ((props (list 'face nil
3789 'done-face 'org-agenda-done
3790 'org-not-done-regexp org-not-done-regexp
3791 'org-todo-regexp org-todo-regexp
3792 'org-complex-heading-regexp org-complex-heading-regexp
3793 'mouse-face 'highlight
3794 'help-echo (format "mouse-2 or RET jump to location")))
3795 (full-words org-agenda-search-view-force-full-words)
3796 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3797 regexp rtn rtnall files file pos
3798 marker category tags c neg re boolean
3799 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3800 (unless (and (not edit-at)
3802 (string-match "\\S-" string))
3803 (setq string (read-string
3804 (if org-agenda-search-view-always-boolean
3805 "[+-]Word/{Regexp} ...: "
3806 "Phrase, or [+-]Word/{Regexp} ...: ")
3808 ((integerp edit-at) (cons string edit-at))
3810 'org-agenda-search-history)))
3811 (org-set-local 'org-todo-only todo-only)
3812 (setq org-agenda-redo-command
3813 (list 'org-search-view (if todo-only t nil) string
3814 '(if current-prefix-arg 1 nil)))
3815 (setq org-agenda-query-string string)
3817 (if (equal (string-to-char string) ?*)
3819 words (substring string 1))
3820 (setq words string))
3821 (when (equal (string-to-char words) ?!)
3823 words (substring words 1)))
3824 (when (equal (string-to-char words) ?:)
3826 words (substring words 1)))
3827 (if (or org-agenda-search-view-always-boolean
3828 (member (string-to-char words) '(?- ?+ ?\{)))
3830 (setq words (org-split-string words))
3832 (while (setq w (pop words))
3833 (while (and (string-match "\\\\\\'" w) words)
3834 (setq w (concat (substring w 0 -1) " " (pop words))))
3836 (setq words (nreverse www) www nil)
3837 (while (setq w (pop words))
3838 (when (and (string-match "\\`[-+]?{" w)
3839 (not (string-match "}\\'" w)))
3840 (while (and words (not (string-match "}\\'" (car words))))
3841 (setq w (concat w " " (pop words))))
3842 (setq w (concat w " " (pop words))))
3844 (setq words (nreverse www)))
3845 (setq org-agenda-last-search-view-search-was-boolean boolean)
3848 (while (setq w (pop words))
3849 (if (or (equal (substring w 0 1) "\"")
3850 (and (> (length w) 1)
3851 (member (substring w 0 1) '("+" "-"))
3852 (equal (substring w 1 2) "\"")))
3853 (while (and words (not (equal (substring w -1) "\"")))
3854 (setq w (concat w " " (pop words)))))
3855 (and (string-match "\\`\\([-+]?\\)\"" w)
3856 (setq w (replace-match "\\1" nil nil w)))
3857 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3859 (setq words (nreverse wds))))
3862 (setq c (string-to-char w))
3864 (setq neg t w (substring w 1))
3866 (setq neg nil w (substring w 1))
3868 (if (string-match "\\`{.*}\\'" w)
3869 (setq re (substring w 1 -1))
3871 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3872 (setq re (regexp-quote (downcase w)))))
3873 (if neg (push re regexps-) (push re regexps+)))
3875 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3877 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3879 (setq regexp org-outline-regexp-bol)
3880 (setq regexp (pop regexps+))
3881 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3883 (setq files (org-agenda-files nil 'ifmode))
3884 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3885 (pop org-agenda-text-search-extra-files)
3886 (setq files (org-add-archive-files files)))
3887 (setq files (append files org-agenda-text-search-extra-files)
3889 (while (setq file (pop files))
3892 (org-check-agenda-file file)
3893 (setq buffer (if (file-exists-p file)
3894 (org-get-agenda-file-buffer file)
3895 (error "No such file %s" file)))
3897 ;; If file does not exist, make sure an error message is sent
3898 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3900 (with-current-buffer buffer
3901 (with-syntax-table (org-search-syntax-table)
3902 (unless (org-mode-p)
3903 (error "Agenda file %s is not in `org-mode'" file))
3904 (let ((case-fold-search t))
3907 (if org-agenda-restrict
3908 (narrow-to-region org-agenda-restrict-begin
3909 org-agenda-restrict-end)
3911 (goto-char (point-min))
3912 (unless (or (org-on-heading-p)
3913 (outline-next-heading))
3914 (throw 'nextfile t))
3915 (goto-char (max (point-min) (1- (point))))
3916 (while (re-search-forward regexp nil t)
3917 (org-back-to-heading t)
3918 (skip-chars-forward "* ")
3919 (setq beg (point-at-bol)
3921 end (progn (outline-next-heading) (point)))
3925 (setq str (buffer-substring-no-properties
3927 (if hdl-only (point-at-eol) end)))
3928 (mapc (lambda (wr) (when (string-match wr str)
3929 (goto-char (1- end))
3932 (mapc (lambda (wr) (unless (string-match wr str)
3933 (goto-char (1- end))
3936 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3940 (setq marker (org-agenda-new-marker (point))
3941 category (org-get-category)
3942 tags (org-get-tags-at (point))
3943 txt (org-format-agenda-item
3945 (buffer-substring-no-properties
3946 beg1 (point-at-eol))
3948 (org-add-props txt props
3949 'org-marker marker 'org-hd-marker marker
3950 'org-todo-regexp org-todo-regexp
3951 'org-complex-heading-regexp org-complex-heading-regexp
3952 'priority 1000 'org-category category
3955 (goto-char (1- end))))))))))
3956 (setq rtn (nreverse ee))
3957 (setq rtnall (append rtnall rtn)))
3958 (if org-agenda-overriding-header
3959 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3960 nil 'face 'org-agenda-structure) "\n")
3961 (insert "Search words: ")
3962 (add-text-properties (point-min) (1- (point))
3963 (list 'face 'org-agenda-structure))
3965 (insert string "\n")
3966 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3968 (unless org-agenda-multi
3969 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3970 (add-text-properties pos (1- (point))
3971 (list 'face 'org-agenda-structure))))
3972 (org-agenda-mark-header-line (point-min))
3974 (insert (org-finalize-agenda-entries rtnall) "\n"))
3975 (goto-char (point-min))
3976 (or org-agenda-multi (org-fit-agenda-window))
3977 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3978 (org-finalize-agenda)
3979 (setq buffer-read-only t)))
3981 ;;; Agenda TODO list
3983 (defvar org-select-this-todo-keyword nil)
3984 (defvar org-last-arg nil)
3987 (defun org-todo-list (arg)
3988 "Show all (not done) TODO entries from all agenda file in a single list.
3989 The prefix arg can be used to select a specific TODO keyword and limit
3990 the list to these. When using \\[universal-argument], you will be prompted
3991 for a keyword. A numeric prefix directly selects the Nth keyword in
3992 `org-todo-keywords-1'."
3994 (org-compile-prefix-format 'todo)
3995 (org-set-sorting-strategy 'todo)
3996 (org-prepare-agenda "TODO")
3997 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3998 (let* ((today (org-today))
3999 (date (calendar-gregorian-from-absolute today))
4000 (kwds org-todo-keywords-for-agenda)
4001 (completion-ignore-case t)
4002 (org-select-this-todo-keyword
4003 (if (stringp arg) arg
4004 (and arg (integerp arg) (> arg 0)
4005 (nth (1- arg) kwds))))
4006 rtn rtnall files file pos)
4007 (when (equal arg '(4))
4008 (setq org-select-this-todo-keyword
4009 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4010 (mapcar 'list kwds) nil nil)))
4011 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4012 (org-set-local 'org-last-arg arg)
4013 (setq org-agenda-redo-command
4014 '(org-todo-list (or current-prefix-arg org-last-arg)))
4015 (setq files (org-agenda-files nil 'ifmode)
4017 (while (setq file (pop files))
4019 (org-check-agenda-file file)
4020 (setq rtn (org-agenda-get-day-entries file date :todo))
4021 (setq rtnall (append rtnall rtn))))
4022 (if org-agenda-overriding-header
4023 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4024 nil 'face 'org-agenda-structure) "\n")
4025 (insert "Global list of TODO items of type: ")
4026 (add-text-properties (point-min) (1- (point))
4027 (list 'face 'org-agenda-structure
4030 (or org-select-this-todo-keyword "ALL"))))
4031 (org-agenda-mark-header-line (point-min))
4033 (insert (or org-select-this-todo-keyword "ALL") "\n")
4034 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4036 (unless org-agenda-multi
4037 (insert "Available with `N r': (0)ALL")
4040 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4041 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4046 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4047 (org-agenda-mark-header-line (point-min))
4049 (insert (org-finalize-agenda-entries rtnall) "\n"))
4050 (goto-char (point-min))
4051 (or org-agenda-multi (org-fit-agenda-window))
4052 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4053 (org-finalize-agenda)
4054 (setq buffer-read-only t)))
4056 ;;; Agenda tags match
4059 (defun org-tags-view (&optional todo-only match)
4060 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4061 The prefix arg TODO-ONLY limits the search to TODO entries."
4063 (org-compile-prefix-format 'tags)
4064 (org-set-sorting-strategy 'tags)
4065 (let* ((org-tags-match-list-sublevels
4066 org-tags-match-list-sublevels)
4067 (completion-ignore-case t)
4068 rtn rtnall files file pos matcher
4070 (when (and (stringp match) (not (string-match "\\S-" match)))
4072 (setq matcher (org-make-tags-matcher match)
4073 match (car matcher) matcher (cdr matcher))
4074 (org-prepare-agenda (concat "TAGS " match))
4075 (setq org-agenda-query-string match)
4076 (setq org-agenda-redo-command
4077 (list 'org-tags-view (list 'quote todo-only)
4078 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4079 (setq files (org-agenda-files nil 'ifmode)
4081 (while (setq file (pop files))
4083 (org-check-agenda-file file)
4084 (setq buffer (if (file-exists-p file)
4085 (org-get-agenda-file-buffer file)
4086 (error "No such file %s" file)))
4088 ;; If file does not exist, error message to agenda
4090 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4091 rtnall (append rtnall rtn))
4092 (with-current-buffer buffer
4093 (unless (org-mode-p)
4094 (error "Agenda file %s is not in `org-mode'" file))
4097 (if org-agenda-restrict
4098 (narrow-to-region org-agenda-restrict-begin
4099 org-agenda-restrict-end)
4101 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4102 (setq rtnall (append rtnall rtn))))))))
4103 (if org-agenda-overriding-header
4104 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4105 nil 'face 'org-agenda-structure) "\n")
4106 (insert "Headlines with TAGS match: ")
4107 (add-text-properties (point-min) (1- (point))
4108 (list 'face 'org-agenda-structure
4110 (concat "Match: " match)))
4113 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4115 (unless org-agenda-multi
4116 (insert "Press `C-u r' to search again with new search string\n"))
4117 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4118 (org-agenda-mark-header-line (point-min))
4120 (insert (org-finalize-agenda-entries rtnall) "\n"))
4121 (goto-char (point-min))
4122 (or org-agenda-multi (org-fit-agenda-window))
4123 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4124 (org-finalize-agenda)
4125 (setq buffer-read-only t)))
4127 ;;; Agenda Finding stuck projects
4129 (defvar org-agenda-skip-regexp nil
4130 "Regular expression used in skipping subtrees for the agenda.
4131 This is basically a temporary global variable that can be set and then
4132 used by user-defined selections using `org-agenda-skip-function'.")
4134 (defvar org-agenda-overriding-header nil
4135 "When set during agenda, todo and tags searches it replaces the header.
4136 This variable should not be set directly, but custom commands can bind it
4137 in the options section.")
4139 (defun org-agenda-skip-entry-when-regexp-matches ()
4140 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4141 If yes, it returns the end position of this entry, causing agenda commands
4142 to skip the entry but continuing the search in the subtree. This is a
4143 function that can be put into `org-agenda-skip-function' for the duration
4145 (let ((end (save-excursion (org-end-of-subtree t)))
4148 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4151 (defun org-agenda-skip-subtree-when-regexp-matches ()
4152 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4153 If yes, it returns the end position of this tree, causing agenda commands
4154 to skip this subtree. This is a function that can be put into
4155 `org-agenda-skip-function' for the duration of a command."
4156 (let ((end (save-excursion (org-end-of-subtree t)))
4159 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4162 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4163 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4164 If yes, it returns the end position of the current entry (NOT the tree),
4165 causing agenda commands to skip the entry but continuing the search in
4166 the subtree. This is a function that can be put into
4167 `org-agenda-skip-function' for the duration of a command. An important
4168 use of this function is for the stuck project list."
4169 (let ((end (save-excursion (org-end-of-subtree t)))
4170 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4173 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4174 (and skip entry-end)))
4176 (defun org-agenda-skip-entry-if (&rest conditions)
4177 "Skip entry if any of CONDITIONS is true.
4178 See `org-agenda-skip-if' for details."
4179 (org-agenda-skip-if nil conditions))
4181 (defun org-agenda-skip-subtree-if (&rest conditions)
4182 "Skip entry if any of CONDITIONS is true.
4183 See `org-agenda-skip-if' for details."
4184 (org-agenda-skip-if t conditions))
4186 (defun org-agenda-skip-if (subtree conditions)
4187 "Checks current entity for CONDITIONS.
4188 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4189 the entry, i.e. the text before the next heading is checked.
4191 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4192 from different tests. Valid conditions are:
4194 scheduled Check if there is a scheduled cookie
4195 notscheduled Check if there is no scheduled cookie
4196 deadline Check if there is a deadline
4197 notdeadline Check if there is no deadline
4198 timestamp Check if there is a timestamp (also deadline or scheduled)
4199 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4200 regexp Check if regexp matches
4201 notregexp Check if regexp does not match.
4202 todo Check if TODO keyword matches
4203 nottodo Check if TODO keyword does not match
4205 The regexp is taken from the conditions list, it must come right after
4206 the `regexp' or `notregexp' element.
4208 `todo' and `nottodo' accept as an argument a list of todo
4209 keywords, which may include \"*\" to match any todo keyword.
4211 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4213 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4215 Instead of a list a keyword class may be given
4217 (org-agenda-skip-entry-if 'nottodo 'done)
4219 would skip entries that haven't been marked with any of \"DONE\"
4220 keywords. Possible classes are: `todo', `done', `any'.
4222 If any of these conditions is met, this function returns the end point of
4223 the entity, causing the search to continue from there. This is a function
4224 that can be put into `org-agenda-skip-function' for the duration of a command."
4226 (org-back-to-heading t)
4229 (progn (org-end-of-subtree t) (point))
4230 (progn (outline-next-heading) (1- (point)))))
4234 (and (memq 'scheduled conditions)
4235 (re-search-forward org-scheduled-time-regexp end t))
4236 (and (memq 'notscheduled conditions)
4237 (not (re-search-forward org-scheduled-time-regexp end t)))
4238 (and (memq 'deadline conditions)
4239 (re-search-forward org-deadline-time-regexp end t))
4240 (and (memq 'notdeadline conditions)
4241 (not (re-search-forward org-deadline-time-regexp end t)))
4242 (and (memq 'timestamp conditions)
4243 (re-search-forward org-ts-regexp end t))
4244 (and (memq 'nottimestamp conditions)
4245 (not (re-search-forward org-ts-regexp end t)))
4246 (and (setq m (memq 'regexp conditions))
4248 (re-search-forward (nth 1 m) end t))
4249 (and (setq m (memq 'notregexp conditions))
4251 (not (re-search-forward (nth 1 m) end t)))
4253 (setq m (memq 'todo conditions))
4254 (setq m (memq 'nottodo conditions)))
4255 (org-agenda-skip-if-todo m end)))
4258 (defun org-agenda-skip-if-todo (args end)
4259 "Helper function for `org-agenda-skip-if', do not use it directly.
4260 ARGS is a list with first element either `todo' or `nottodo'.
4261 The remainder is either a list of TODO keywords, or a state symbol
4262 `todo' or `done' or `any'."
4263 (let ((kw (car args))
4269 ((listp arg) ;; list of keywords
4270 (if (member "*" arg)
4271 (mapcar 'substring-no-properties org-todo-keywords-1)
4273 ((symbolp arg) ;; keyword class name
4276 (org-delete-all org-done-keywords
4277 (mapcar 'substring-no-properties
4278 org-todo-keywords-1)))
4279 ((eq arg 'done) org-done-keywords)
4281 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4283 (concat "^\\*+[ \t]+\\<\\("
4284 (mapconcat 'identity todo-wds "\\|")
4287 (re-search-forward todo-re end t)
4288 (not (re-search-forward todo-re end t)))))
4291 (defun org-agenda-list-stuck-projects (&rest ignore)
4292 "Create agenda view for projects that are stuck.
4293 Stuck projects are project that have no next actions. For the definitions
4294 of what a project is and how to check if it stuck, customize the variable
4295 `org-stuck-projects'."
4297 (let* ((org-agenda-skip-function
4298 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4299 ;; We could have used org-agenda-skip-if here.
4300 (org-agenda-overriding-header
4301 (or org-agenda-overriding-header "List of stuck projects: "))
4302 (matcher (nth 0 org-stuck-projects))
4303 (todo (nth 1 org-stuck-projects))
4304 (todo-wds (if (member "*" todo)
4306 (org-prepare-agenda-buffers (org-agenda-files
4309 org-done-keywords-for-agenda
4310 (copy-sequence org-todo-keywords-for-agenda)))
4312 (todo-re (concat "^\\*+[ \t]+\\("
4313 (mapconcat 'identity todo-wds "\\|")
4315 (tags (nth 2 org-stuck-projects))
4316 (tags-re (if (member "*" tags)
4317 (org-re (concat org-outline-regexp-bol
4318 ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4320 (concat org-outline-regexp-bol
4322 (mapconcat 'identity tags "\\|")
4323 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4324 (gen-re (nth 3 org-stuck-projects))
4330 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4332 (setq org-agenda-skip-regexp
4334 (mapconcat 'identity re-list "\\|")
4335 (error "No information how to identify unstuck projects")))
4336 (org-tags-view nil matcher)
4337 (with-current-buffer org-agenda-buffer-name
4338 (setq org-agenda-redo-command
4339 '(org-agenda-list-stuck-projects
4340 (or current-prefix-arg org-last-arg))))))
4342 ;;; Diary integration
4344 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4345 (defvar list-diary-entries-hook)
4346 (defvar diary-time-regexp)
4347 (defun org-get-entries-from-diary (date)
4348 "Get the (Emacs Calendar) diary entries for DATE."
4349 (require 'diary-lib)
4350 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4351 (diary-display-hook '(fancy-diary-display))
4352 (diary-display-function 'fancy-diary-display)
4354 (list-diary-entries-hook
4355 (cons 'org-diary-default-entry list-diary-entries-hook))
4356 (diary-file-name-prefix-function nil) ; turn this feature off
4357 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4359 (org-disable-agenda-to-diary t))
4361 (save-window-excursion
4362 (funcall (if (fboundp 'diary-list-entries)
4363 'diary-list-entries 'list-diary-entries)
4365 (if (not (get-buffer diary-fancy-buffer))
4367 (with-current-buffer diary-fancy-buffer
4368 (setq buffer-read-only nil)
4369 (if (zerop (buffer-size))
4372 ;; Omit the date and other unnecessary stuff
4373 (org-agenda-cleanup-fancy-diary)
4374 ;; Add prefix to each line and extend the text properties
4375 (if (zerop (buffer-size))
4377 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4380 (insert entries) (goto-char (point-min))
4381 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4382 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4383 (replace-match (concat "; " (match-string 1)))))
4385 (set-buffer-modified-p nil)
4386 (kill-buffer diary-fancy-buffer)))
4388 (setq entries (org-split-string entries "\n"))
4392 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4393 ;; Extend the text properties to the beginning of the line
4394 (org-add-props x (text-properties-at (1- (length x)) x)
4395 'type "diary" 'date date 'face 'org-agenda-diary))
4398 (defvar org-agenda-cleanup-fancy-diary-hook nil
4399 "Hook run when the fancy diary buffer is cleaned up.")
4401 (defun org-agenda-cleanup-fancy-diary ()
4402 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4403 This gets rid of the date, the underline under the date, and
4404 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4405 date. It also removes lines that contain only whitespace."
4406 (goto-char (point-min))
4407 (if (looking-at ".*?:[ \t]*")
4410 (re-search-forward "\n=+$" nil t)
4412 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4413 (re-search-forward "\n=+$" nil t)
4414 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4415 (goto-char (point-min))
4416 (while (re-search-forward "^ +\n" nil t)
4418 (goto-char (point-min))
4419 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4421 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4423 ;; Make sure entries from the diary have the right text properties.
4424 (eval-after-load "diary-lib"
4425 '(if (boundp 'diary-modify-entry-list-string-function)
4426 ;; We can rely on the hook, nothing to do
4428 ;; Hook not available, must use advice to make this work
4429 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4430 "Make the position visible."
4431 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4434 (setq string (org-modify-diary-entry-string string))))))
4436 (defun org-modify-diary-entry-string (string)
4437 "Add text properties to string, allowing org-mode to act on it."
4438 (org-add-props string nil
4439 'mouse-face 'highlight
4440 'help-echo (if buffer-file-name
4441 (format "mouse-2 or RET jump to diary file %s"
4442 (abbreviate-file-name buffer-file-name))
4444 'org-agenda-diary-link t
4445 'org-marker (org-agenda-new-marker (point-at-bol))))
4447 (defun org-diary-default-entry ()
4448 "Add a dummy entry to the diary.
4449 Needed to avoid empty dates which mess up holiday display."
4450 ;; Catch the error if dealing with the new add-to-diary-alist
4451 (when org-disable-agenda-to-diary
4453 (org-add-to-diary-list original-date "Org-mode dummy" "")
4455 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4457 (defun org-add-to-diary-list (&rest args)
4458 (if (fboundp 'diary-add-to-list)
4459 (apply 'diary-add-to-list args)
4460 (apply 'add-to-diary-list args)))
4462 (defvar org-diary-last-run-time nil)
4465 (defun org-diary (&rest args)
4466 "Return diary information from org-files.
4467 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4468 It accesses org files and extracts information from those files to be
4469 listed in the diary. The function accepts arguments specifying what
4470 items should be listed. For a list of arguments allowed here, see the
4471 variable `org-agenda-entry-types'.
4473 The call in the diary file should look like this:
4475 &%%(org-diary) ~/path/to/some/orgfile.org
4477 Use a separate line for each org file to check. Or, if you omit the file name,
4478 all files listed in `org-agenda-files' will be checked automatically:
4482 If you don't give any arguments (as in the example above), the default
4483 arguments (:deadline :scheduled :timestamp :sexp) are used.
4484 So the example above may also be written as
4486 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4488 The function expects the lisp variables `entry' and `date' to be provided
4489 by the caller, because this is how the calendar works. Don't use this
4490 function from a program - use `org-agenda-get-day-entries' instead."
4491 (when (> (- (org-float-time)
4492 org-agenda-last-marker-time)
4494 (org-agenda-reset-markers))
4495 (org-compile-prefix-format 'agenda)
4496 (org-set-sorting-strategy 'agenda)
4497 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4498 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4500 (org-agenda-files t)))
4501 (time (org-float-time))
4503 (when (or (not org-diary-last-run-time)
4505 org-diary-last-run-time)
4507 (org-prepare-agenda-buffers files))
4508 (setq org-diary-last-run-time time)
4509 ;; If this is called during org-agenda, don't return any entries to
4510 ;; the calendar. Org Agenda will list these entries itself.
4511 (if org-disable-agenda-to-diary (setq files nil))
4512 (while (setq file (pop files))
4513 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4514 (setq results (append results rtn)))
4516 (concat (org-finalize-agenda-entries results) "\n"))))
4518 ;;; Agenda entry finders
4520 (defun org-agenda-get-day-entries (file date &rest args)
4521 "Does the work for `org-diary' and `org-agenda'.
4522 FILE is the path to a file to be checked for entries. DATE is date like
4523 the one returned by `calendar-current-date'. ARGS are symbols indicating
4524 which kind of entries should be extracted. For details about these, see
4525 the documentation of `org-diary'."
4526 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4527 (let* ((org-startup-folded nil)
4528 (org-startup-align-all-tables nil)
4529 (buffer (if (file-exists-p file)
4530 (org-get-agenda-file-buffer file)
4531 (error "No such file %s" file)))
4532 arg results rtn deadline-results)
4534 ;; If file does not exist, make sure an error message ends up in diary
4535 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4536 (with-current-buffer buffer
4537 (unless (org-mode-p)
4538 (error "Agenda file %s is not in `org-mode'" file))
4539 (let ((case-fold-search nil))
4542 (if org-agenda-restrict
4543 (narrow-to-region org-agenda-restrict-begin
4544 org-agenda-restrict-end)
4546 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4547 (while (setq arg (pop args))
4549 ((and (eq arg :todo)
4550 (equal date (calendar-gregorian-from-absolute
4552 (setq rtn (org-agenda-get-todos))
4553 (setq results (append results rtn)))
4554 ((eq arg :timestamp)
4555 (setq rtn (org-agenda-get-blocks))
4556 (setq results (append results rtn))
4557 (setq rtn (org-agenda-get-timestamps))
4558 (setq results (append results rtn)))
4560 (setq rtn (org-agenda-get-sexps))
4561 (setq results (append results rtn)))
4562 ((eq arg :scheduled)
4563 (setq rtn (org-agenda-get-scheduled deadline-results))
4564 (setq results (append results rtn)))
4566 (setq rtn (org-agenda-get-progress))
4567 (setq results (append results rtn)))
4569 (setq rtn (org-agenda-get-deadlines))
4570 (setq deadline-results (copy-sequence rtn))
4571 (setq results (append results rtn))))))))
4574 (defun org-agenda-get-todos ()
4575 "Return the TODO information for agenda display."
4576 (let* ((props (list 'face nil
4577 'done-face 'org-agenda-done
4578 'org-not-done-regexp org-not-done-regexp
4579 'org-todo-regexp org-todo-regexp
4580 'org-complex-heading-regexp org-complex-heading-regexp
4581 'mouse-face 'highlight
4583 (format "mouse-2 or RET jump to org file %s"
4584 (abbreviate-file-name buffer-file-name))))
4585 (regexp (concat "^\\*+[ \t]+\\("
4586 (if org-select-this-todo-keyword
4587 (if (equal org-select-this-todo-keyword "*")
4590 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4592 org-not-done-regexp)
4594 marker priority category tags todo-state
4596 (goto-char (point-min))
4597 (while (re-search-forward regexp nil t)
4602 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4603 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4604 (goto-char (1+ beg))
4605 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4607 (goto-char (match-beginning 1))
4608 (setq marker (org-agenda-new-marker (match-beginning 0))
4609 category (org-get-category)
4610 txt (match-string 1)
4611 tags (org-get-tags-at (point))
4612 txt (org-format-agenda-item "" txt category tags)
4613 priority (1+ (org-get-priority txt))
4614 todo-state (org-get-todo-state))
4615 (org-add-props txt props
4616 'org-marker marker 'org-hd-marker marker
4617 'priority priority 'org-category category
4618 'type "todo" 'todo-state todo-state)
4620 (if org-agenda-todo-list-sublevels
4621 (goto-char (match-end 1))
4622 (org-end-of-subtree 'invisible))))
4625 (defun org-agenda-todo-custom-ignore-p (time n)
4626 "Check whether timestamp is farther away then n number of days.
4627 This function is invoked if `org-agenda-todo-ignore-deadlines',
4628 `org-agenda-todo-ignore-scheduled' or
4629 `org-agenda-todo-ignore-timestamp' is set to an integer."
4630 (let ((days (org-days-to-time time)))
4636 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4638 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4639 (when (or org-agenda-todo-ignore-with-date
4640 org-agenda-todo-ignore-scheduled
4641 org-agenda-todo-ignore-deadlines
4642 org-agenda-todo-ignore-timestamp)
4643 (setq end (or end (save-excursion (outline-next-heading) (point))))
4645 (or (and org-agenda-todo-ignore-with-date
4646 (re-search-forward org-ts-regexp end t))
4647 (and org-agenda-todo-ignore-scheduled
4648 (re-search-forward org-scheduled-time-regexp end t)
4650 ((eq org-agenda-todo-ignore-scheduled 'future)
4651 (> (org-days-to-time (match-string 1)) 0))
4652 ((eq org-agenda-todo-ignore-scheduled 'past)
4653 (<= (org-days-to-time (match-string 1)) 0))
4654 ((numberp org-agenda-todo-ignore-scheduled)
4655 (org-agenda-todo-custom-ignore-p
4656 (match-string 1) org-agenda-todo-ignore-scheduled))
4658 (and org-agenda-todo-ignore-deadlines
4659 (re-search-forward org-deadline-time-regexp end t)
4661 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4662 ((eq org-agenda-todo-ignore-deadlines 'far)
4663 (not (org-deadline-close (match-string 1))))
4664 ((eq org-agenda-todo-ignore-deadlines 'future)
4665 (> (org-days-to-time (match-string 1)) 0))
4666 ((eq org-agenda-todo-ignore-deadlines 'past)
4667 (<= (org-days-to-time (match-string 1)) 0))
4668 ((numberp org-agenda-todo-ignore-deadlines)
4669 (org-agenda-todo-custom-ignore-p
4670 (match-string 1) org-agenda-todo-ignore-deadlines))
4671 (t (org-deadline-close (match-string 1)))))
4672 (and org-agenda-todo-ignore-timestamp
4673 (let ((buffer (current-buffer))
4676 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4678 ;; Copy current buffer into a temporary one
4680 (insert-buffer-substring buffer start end)
4681 (goto-char (point-min))
4682 ;; Delete SCHEDULED and DEADLINE items
4683 (while (re-search-forward regexp end t)
4684 (delete-region (match-beginning 0) (match-end 0)))
4685 (goto-char (point-min))
4686 ;; No search for timestamp left
4687 (when (re-search-forward org-ts-regexp nil t)
4689 ((eq org-agenda-todo-ignore-timestamp 'future)
4690 (> (org-days-to-time (match-string 1)) 0))
4691 ((eq org-agenda-todo-ignore-timestamp 'past)
4692 (<= (org-days-to-time (match-string 1)) 0))
4693 ((numberp org-agenda-todo-ignore-timestamp)
4694 (org-agenda-todo-custom-ignore-p
4695 (match-string 1) org-agenda-todo-ignore-timestamp))
4698 (defconst org-agenda-no-heading-message
4699 "No heading for this item in buffer or region.")
4701 (defun org-agenda-get-timestamps ()
4702 "Return the date stamp information for agenda display."
4703 (let* ((props (list 'face nil
4704 'org-not-done-regexp org-not-done-regexp
4705 'org-todo-regexp org-todo-regexp
4706 'org-complex-heading-regexp org-complex-heading-regexp
4707 'mouse-face 'highlight
4709 (format "mouse-2 or RET jump to org file %s"
4710 (abbreviate-file-name buffer-file-name))))
4711 (d1 (calendar-absolute-from-gregorian date))
4717 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4721 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4725 (car org-time-stamp-formats)
4726 (apply 'encode-time ; DATE bound by calendar
4727 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4729 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4730 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4731 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4732 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4733 todo-state end-of-match show-all)
4734 (goto-char (point-min))
4735 (while (setq end-of-match (re-search-forward regexp nil t))
4736 (setq b0 (match-beginning 0)
4737 b3 (match-beginning 3) e3 (match-end 3)
4738 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4739 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4741 org-agenda-repeating-timestamp-show-all)))
4743 (and (org-at-date-range-p) (throw :skip nil))
4745 (if (and (match-end 1)
4746 (not (= d1 (org-time-string-to-absolute
4747 (match-string 1) d1 nil show-all))))
4750 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4752 (setq tmp (buffer-substring (max (point-min)
4753 (- b0 org-ds-keyword-length))
4755 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4756 inactivep (= (char-after b0) ?\[)
4757 deadlinep (string-match org-deadline-regexp tmp)
4758 scheduledp (string-match org-scheduled-regexp tmp)
4759 closedp (and org-agenda-include-inactive-timestamps
4760 (string-match org-closed-string tmp))
4761 clockp (and org-agenda-include-inactive-timestamps
4762 (or (string-match org-clock-string tmp)
4763 (string-match "]-+\\'" tmp)))
4764 donep (member todo-state org-done-keywords))
4765 (if (or scheduledp deadlinep closedp clockp
4766 (and donep org-agenda-skip-timestamp-if-done))
4768 (if (string-match ">" timestr)
4769 ;; substring should only run to end of time stamp
4770 (setq timestr (substring timestr 0 (match-end 0))))
4771 (setq marker (org-agenda-new-marker b0)
4772 category (org-get-category b0))
4774 (if (not (re-search-backward org-outline-regexp-bol nil t))
4775 (setq txt org-agenda-no-heading-message)
4776 (goto-char (match-beginning 0))
4777 (setq hdmarker (org-agenda-new-marker)
4778 tags (org-get-tags-at))
4779 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4780 (setq head (or (match-string 1) ""))
4781 (setq txt (org-format-agenda-item
4782 (if inactivep org-agenda-inactive-leader nil)
4783 head category tags timestr
4785 (setq priority (org-get-priority txt))
4786 (org-add-props txt props
4787 'org-marker marker 'org-hd-marker hdmarker)
4788 (org-add-props txt nil 'priority priority
4789 'org-category category 'date date
4790 'todo-state todo-state
4793 (if org-agenda-skip-additional-timestamps-same-entry
4794 (outline-next-heading)
4795 (goto-char end-of-match))))
4798 (defun org-agenda-get-sexps ()
4799 "Return the sexp information for agenda display."
4800 (require 'diary-lib)
4801 (let* ((props (list 'mouse-face 'highlight
4803 (format "mouse-2 or RET jump to org file %s"
4804 (abbreviate-file-name buffer-file-name))))
4806 marker category ee txt tags entry result beg b sexp sexp-entry
4808 (goto-char (point-min))
4809 (while (re-search-forward regexp nil t)
4812 (setq beg (match-beginning 0))
4813 (goto-char (1- (match-end 0)))
4816 (setq sexp (buffer-substring b (point)))
4817 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4818 (org-trim (match-string 1))
4820 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4822 (setq marker (org-agenda-new-marker beg)
4823 category (org-get-category beg)
4824 todo-state (org-get-todo-state))
4826 (dolist (r (if (stringp result)
4828 result)) ;; we expect a list here
4829 (if (string-match "\\S-" r)
4831 (setq txt "SEXP entry returned empty string"))
4833 (setq txt (org-format-agenda-item
4834 "" txt category tags 'time))
4835 (org-add-props txt props 'org-marker marker)
4836 (org-add-props txt nil
4837 'org-category category 'date date 'todo-state todo-state
4842 ;; Calendar sanity: define some functions that are independent of
4843 ;; `calendar-date-style'.
4844 ;; Normally I would like to use ISO format when calling the diary functions,
4845 ;; but to make sure we still have Emacs 22 compatibility we bind
4846 ;; also `european-calendar-style' and use european format
4847 (defun org-anniversary (year month day &optional mark)
4848 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
4850 (let ((calendar-date-style 'european) (european-calendar-style t))
4851 (diary-anniversary day month year mark))))
4852 (defun org-cyclic (N year month day &optional mark)
4853 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
4855 (let ((calendar-date-style 'european) (european-calendar-style t))
4856 (diary-cyclic N day month year mark))))
4857 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
4858 "Like `diary-block', but with fixed (ISO) order of arguments."
4860 (let ((calendar-date-style 'european) (european-calendar-style t))
4861 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
4862 (defun org-date (year month day &optional mark)
4863 "Like `diary-date', but with fixed (ISO) order of arguments."
4865 (let ((calendar-date-style 'european) (european-calendar-style t))
4866 (diary-date day month year mark))))
4867 (defalias 'org-float 'diary-float)
4869 ;; Define the` org-class' function
4870 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
4871 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4872 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4873 is any number of ISO weeks in the block period for which the item should
4875 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
4876 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
4877 (d (calendar-absolute-from-gregorian date)))
4881 (= (calendar-day-of-week date) dayname)
4882 (or (not skip-weeks)
4885 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4888 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4889 "Like `org-class', but honor `calendar-date-style'.
4890 The order of the first 2 times 3 arguments depends on the variable
4891 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4892 So for American calendars, give this as MONTH DAY YEAR, for European as
4893 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4894 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4895 is any number of ISO weeks in the block period for which the item should
4898 This function is here only for backward compatibility and it is deprecated,
4899 please use `org-class' instead."
4900 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
4901 (date2 (org-order-calendar-date-args m2 d2 y2)))
4903 (nth 2 date1) (car date1) (nth 1 date1)
4904 (nth 2 date2) (car date2) (nth 1 date2)
4905 dayname skip-weeks)))
4907 (defalias 'org-get-closed 'org-agenda-get-progress)
4908 (defun org-agenda-get-progress ()
4909 "Return the logged TODO entries for agenda display."
4910 (let* ((props (list 'mouse-face 'highlight
4911 'org-not-done-regexp org-not-done-regexp
4912 'org-todo-regexp org-todo-regexp
4913 'org-complex-heading-regexp org-complex-heading-regexp
4915 (format "mouse-2 or RET jump to org file %s"
4916 (abbreviate-file-name buffer-file-name))))
4917 (items (if (consp org-agenda-show-log)
4919 (if (eq org-agenda-show-log 'clockcheck)
4921 org-agenda-log-mode-items)))
4925 (if (memq 'closed items) (concat "\\<" org-closed-string))
4926 (if (memq 'clock items) (concat "\\<" org-clock-string))
4927 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4928 (parts-re (if parts (mapconcat 'identity parts "\\|")
4929 (error "`org-agenda-log-mode-items' is empty")))
4931 "\\(" parts-re "\\)"
4936 (car org-time-stamp-formats)
4937 (apply 'encode-time ; DATE bound by calendar
4938 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4940 (org-agenda-search-headline-for-time nil)
4941 marker hdmarker priority category tags closedp statep clockp state
4942 ee txt extra timestr rest clocked)
4943 (goto-char (point-min))
4944 (while (re-search-forward regexp nil t)
4947 (setq marker (org-agenda-new-marker (match-beginning 0))
4948 closedp (equal (match-string 1) org-closed-string)
4949 statep (equal (string-to-char (match-string 1)) ?-)
4950 clockp (not (or closedp statep))
4951 state (and statep (match-string 2))
4952 category (org-get-category (match-beginning 0))
4953 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4955 (when (string-match "\\]" timestr)
4956 ;; substring should only run to end of time stamp
4957 (setq rest (substring timestr (match-end 0))
4958 timestr (substring timestr 0 (match-end 0)))
4959 (if (and (not closedp) (not statep)
4960 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4961 (progn (setq timestr (concat (substring timestr 0 -1)
4962 "-" (match-string 1 rest) "]"))
4963 (setq clocked (match-string 2 rest)))
4964 (setq clocked "-")))
4968 ((not org-agenda-log-mode-add-notes) nil)
4970 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4973 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4974 (match-string 1)))))
4975 (if (not (re-search-backward org-outline-regexp-bol nil t))
4976 (setq txt org-agenda-no-heading-message)
4977 (goto-char (match-beginning 0))
4978 (setq hdmarker (org-agenda-new-marker)
4979 tags (org-get-tags-at))
4980 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4981 (setq txt (match-string 1))
4983 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4984 (setq txt (concat (substring txt 0 (match-beginning 1))
4985 " - " extra " " (match-string 2 txt)))
4986 (setq txt (concat txt " - " extra))))
4987 (setq txt (org-format-agenda-item
4989 (closedp "Closed: ")
4990 (statep (concat "State: (" state ")"))
4991 (t (concat "Clocked: (" clocked ")")))
4992 txt category tags timestr)))
4993 (setq priority 100000)
4994 (org-add-props txt props
4995 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4996 'priority priority 'org-category category
4997 'type "closed" 'date date
4998 'undone-face 'org-warning 'done-face 'org-agenda-done)
5000 (goto-char (point-at-eol))))
5003 (defun org-agenda-show-clocking-issues ()
5004 "Add overlays, showing issues with clocking.
5005 See also the user option `org-agenda-clock-consistency-checks'."
5007 (let* ((pl org-agenda-clock-consistency-checks)
5008 (re (concat "^[ \t]*"
5011 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5012 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5015 (maxtime (org-hh:mm-string-to-minutes
5016 (or (plist-get pl :max-duration) "24:00")))
5017 (mintime (org-hh:mm-string-to-minutes
5018 (or (plist-get pl :min-duration) 0)))
5019 (maxgap (org-hh:mm-string-to-minutes
5020 ;; default 30:00 means never complain
5021 (or (plist-get pl :max-gap) "30:00")))
5022 (gapok (mapcar 'org-hh:mm-string-to-minutes
5023 (plist-get pl :gap-ok-around)))
5024 (def-face (or (plist-get pl :default-face)
5025 '((:background "DarkRed") (:foreground "white"))))
5026 issue face m te ts dt ov)
5027 (goto-char (point-min))
5028 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5029 (setq issue nil face def-face)
5031 (setq m (org-get-at-bol 'org-marker)
5033 (unless (and m (markerp m))
5034 (setq issue "No valid clock line") (throw 'next t))
5035 (org-with-point-at m
5037 (goto-char (point-at-bol))
5038 (unless (looking-at re)
5039 (error "No valid Clock line")
5041 (unless (match-end 3)
5042 (setq issue "No end time"
5043 face (or (plist-get pl :no-end-time-face) face))
5045 (setq ts (match-string 1)
5048 (apply 'encode-time (org-parse-time-string ts)))
5050 (apply 'encode-time (org-parse-time-string te)))
5053 ((> dt (* 60 maxtime))
5054 ;; a very long clocking chunk
5055 (setq issue (format "Clocking interval is very long: %s"
5056 (org-minutes-to-hh:mm-string
5057 (floor (/ (float dt) 60.))))
5058 face (or (plist-get pl :long-face) face)))
5059 ((< dt (* 60 mintime))
5060 ;; a very short clocking chunk
5061 (setq issue (format "Clocking interval is very short: %s"
5062 (org-minutes-to-hh:mm-string
5063 (floor (/ (float dt) 60.))))
5064 face (or (plist-get pl :short-face) face)))
5065 ((and (> tlend 0) (< ts tlend))
5066 ;; Two clock entries are overlapping
5067 (setq issue (format "Clocking overlap: %d minutes"
5068 (/ (- tlend ts) 60))
5069 face (or (plist-get pl :overlap-face) face)))
5070 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5071 ;; There is a gap, lets see if we need to report it
5072 (unless (org-agenda-check-clock-gap tlend ts gapok)
5073 (setq issue (format "Clocking gap: %d minutes"
5074 (/ (- ts tlend) 60))
5075 face (or (plist-get pl :gap-face) face))))
5077 (setq tlend (or te tlend) tlstart (or ts tlstart))
5079 ;; OK, there was some issue, add an overlay to show the issue
5080 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5081 (overlay-put ov 'before-string
5084 (format "%-43s" (concat " " issue))
5088 (overlay-put ov 'evaporate t)))))
5090 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5091 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5094 ;; there are no OK times for gaps...
5096 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5097 ;; This is more than 24 hours, so it is OK.
5098 ;; because we have at least one OK time, that must be in the
5099 ;; 24 hour interval.
5101 ;; We have a shorter gap.
5102 ;; Now we have to get the minute of the day when these times are
5103 (let* ((t1dec (decode-time (seconds-to-time t1)))
5104 (t2dec (decode-time (seconds-to-time t2)))
5105 ;; compute the minute on the day
5106 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5107 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5109 ;; if min2 is smaller than min1, this means it is on the next day.
5110 ;; Wrap it to after midnight.
5111 (setq min2 (+ min2 1440)))
5112 ;; Now check if any of the OK times is in the gap
5114 ;; Wrap the time to after midnight if necessary
5115 (if (< x min1) (setq x (+ x 1440)))
5116 ;; Check if in interval
5117 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5119 ;; Nope, this gap is not OK
5122 (defun org-agenda-get-deadlines ()
5123 "Return the deadline information for agenda display."
5124 (let* ((props (list 'mouse-face 'highlight
5125 'org-not-done-regexp org-not-done-regexp
5126 'org-todo-regexp org-todo-regexp
5127 'org-complex-heading-regexp org-complex-heading-regexp
5129 (format "mouse-2 or RET jump to org file %s"
5130 (abbreviate-file-name buffer-file-name))))
5131 (regexp org-deadline-time-regexp)
5132 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5133 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5134 d2 diff dfrac wdays pos pos1 category tags
5136 ee txt head face s todo-state show-all upcomingp donep timestr)
5137 (goto-char (point-min))
5138 (while (re-search-forward regexp nil t)
5139 (setq suppress-prewarning nil)
5142 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5144 (string-match org-scheduled-time-regexp
5145 (buffer-substring (point-at-bol)
5147 (setq suppress-prewarning
5148 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5149 org-agenda-skip-deadline-prewarning-if-scheduled
5151 (setq s (match-string 1)
5153 pos (1- (match-beginning 1))
5154 todo-state (save-match-data (org-get-todo-state))
5155 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5157 org-agenda-repeating-timestamp-show-all))
5158 d2 (org-time-string-to-absolute
5159 (match-string 1) d1 'past show-all)
5161 wdays (if suppress-prewarning
5162 (let ((org-deadline-warning-days suppress-prewarning))
5165 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5166 upcomingp (and todayp (> diff 0)))
5167 ;; When to show a deadline in the calendar:
5168 ;; If the expiration is within wdays warning time.
5169 ;; Past-due deadlines are only shown on the current date
5170 (if (and (or (and (<= diff wdays)
5171 (and todayp (not org-agenda-only-exact-dates)))
5174 ;; (setq todo-state (org-get-todo-state))
5175 (setq donep (member todo-state org-done-keywords))
5177 (or org-agenda-skip-deadline-if-done
5180 (setq category (org-get-category))
5181 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5182 (setq txt org-agenda-no-heading-message)
5183 (goto-char (match-end 0))
5184 (setq pos1 (match-beginning 0))
5185 (setq tags (org-get-tags-at pos1))
5186 (setq head (buffer-substring-no-properties
5188 (progn (skip-chars-forward "^\r\n")
5190 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5192 (concat (substring s (match-beginning 1)) " "))
5193 (setq timestr 'time))
5194 (setq txt (org-format-agenda-item
5196 (car org-agenda-deadline-leaders)
5198 (nth 1 org-agenda-deadline-leaders))
5200 (nth 1 org-agenda-deadline-leaders)
5202 (format (nth 1 org-agenda-deadline-leaders)
5205 (if (not (= diff 0)) nil timestr)))))
5207 (setq face (org-agenda-deadline-face dfrac))
5208 (org-add-props txt props
5209 'org-marker (org-agenda-new-marker pos)
5210 'org-hd-marker (org-agenda-new-marker pos1)
5211 'priority (+ (- diff)
5212 (org-get-priority txt))
5213 'org-category category
5214 'todo-state todo-state
5215 'type (if upcomingp "upcoming-deadline" "deadline")
5216 'date (if upcomingp date d2)
5217 'face (if donep 'org-agenda-done face)
5218 'undone-face face 'done-face 'org-agenda-done)
5222 (defun org-agenda-deadline-face (fraction)
5223 "Return the face to displaying a deadline item.
5224 FRACTION is what fraction of the head-warning time has passed."
5225 (let ((faces org-agenda-deadline-faces) f)
5227 (while (setq f (pop faces))
5228 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5230 (defun org-agenda-get-scheduled (&optional deadline-results)
5231 "Return the scheduled information for agenda display."
5232 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5233 'org-todo-regexp org-todo-regexp
5234 'org-complex-heading-regexp org-complex-heading-regexp
5235 'done-face 'org-agenda-done
5236 'mouse-face 'highlight
5238 (format "mouse-2 or RET jump to org file %s"
5239 (abbreviate-file-name buffer-file-name))))
5240 (regexp org-scheduled-time-regexp)
5241 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5242 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5244 (deadline-position-alist
5245 (mapcar (lambda (a) (and (setq mm (get-text-property
5246 0 'org-hd-marker a))
5247 (cons (marker-position mm) a)))
5249 d2 diff pos pos1 category tags donep
5250 ee txt head pastschedp todo-state face timestr s habitp show-all)
5251 (goto-char (point-min))
5252 (while (re-search-forward regexp nil t)
5255 (setq s (match-string 1)
5257 pos (1- (match-beginning 1))
5258 todo-state (save-match-data (org-get-todo-state))
5259 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5261 org-agenda-repeating-timestamp-show-all))
5262 d2 (org-time-string-to-absolute
5263 (match-string 1) d1 'past show-all)
5265 (setq pastschedp (and todayp (< diff 0)))
5266 ;; When to show a scheduled item in the calendar:
5267 ;; If it is on or past the date.
5268 (when (or (and (< diff 0)
5269 (< (abs diff) org-scheduled-past-days)
5270 (and todayp (not org-agenda-only-exact-dates)))
5273 (setq donep (member todo-state org-done-keywords))
5275 (or org-agenda-skip-scheduled-if-done
5277 (and (functionp 'org-is-habit-p)
5280 (setq habitp (and (functionp 'org-is-habit-p)
5282 (setq category (org-get-category))
5283 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5284 (setq txt org-agenda-no-heading-message)
5285 (goto-char (match-end 0))
5286 (setq pos1 (match-beginning 0))
5288 (if (or (not org-habit-show-habits)
5290 org-habit-show-habits-only-for-today))
5293 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5294 (and org-agenda-skip-scheduled-if-deadline-is-shown
5296 (setq mm (assoc pos1 deadline-position-alist)))
5298 (setq tags (org-get-tags-at))
5299 (setq head (buffer-substring-no-properties
5301 (progn (skip-chars-forward "^\r\n") (point))))
5302 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5304 (concat (substring s (match-beginning 1)) " "))
5305 (setq timestr 'time))
5306 (setq txt (org-format-agenda-item
5308 (car org-agenda-scheduled-leaders)
5309 (format (nth 1 org-agenda-scheduled-leaders)
5312 (if (not (= diff 0)) nil timestr)
5317 ((and (not habitp) pastschedp)
5318 'org-scheduled-previously)
5319 (todayp 'org-scheduled-today)
5321 habitp (and habitp (org-habit-parse-todo)))
5322 (org-add-props txt props
5324 'face (if donep 'org-agenda-done face)
5325 'org-marker (org-agenda-new-marker pos)
5326 'org-hd-marker (org-agenda-new-marker pos1)
5327 'type (if pastschedp "past-scheduled" "scheduled")
5328 'date (if pastschedp d2 date)
5329 'priority (if habitp
5330 (org-habit-get-priority habitp)
5331 (+ 94 (- 5 diff) (org-get-priority txt)))
5332 'org-category category
5334 'todo-state todo-state)
5338 (defun org-agenda-get-blocks ()
5339 "Return the date-range information for agenda display."
5340 (let* ((props (list 'face nil
5341 'org-not-done-regexp org-not-done-regexp
5342 'org-todo-regexp org-todo-regexp
5343 'org-complex-heading-regexp org-complex-heading-regexp
5344 'mouse-face 'highlight
5346 (format "mouse-2 or RET jump to org file %s"
5347 (abbreviate-file-name buffer-file-name))))
5348 (regexp org-tr-regexp)
5349 (d0 (calendar-absolute-from-gregorian date))
5350 marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
5352 (goto-char (point-min))
5353 (while (re-search-forward regexp nil t)
5357 (let ((start-time (match-string 1))
5358 (end-time (match-string 2)))
5359 (setq s1 (match-string 1)
5361 d1 (time-to-days (org-time-string-to-time s1))
5362 d2 (time-to-days (org-time-string-to-time s2)))
5363 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5364 ;; Only allow days between the limits, because the normal
5365 ;; date stamps will catch the limits.
5367 (setq todo-state (org-get-todo-state))
5368 (setq donep (member todo-state org-done-keywords))
5369 (if (and donep org-agenda-skip-timestamp-if-done)
5371 (setq marker (org-agenda-new-marker (point)))
5372 (setq category (org-get-category))
5373 (if (not (re-search-backward org-outline-regexp-bol nil t))
5374 (setq txt org-agenda-no-heading-message)
5375 (goto-char (match-beginning 0))
5376 (setq hdmarker (org-agenda-new-marker (point)))
5377 (setq tags (org-get-tags-at))
5378 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5379 (setq head (match-string 1))
5381 (if org-agenda-remove-timeranges-from-blocks
5383 "<" (regexp-quote s1) ".*?>"
5385 "<" (regexp-quote s2) ".*?>")
5387 (setq txt (org-format-agenda-item
5389 (nth (if (= d1 d2) 0 1)
5390 org-agenda-timerange-leaders)
5391 (1+ (- d0 d1)) (1+ (- d2 d1)))
5394 (concat "<" start-time ">"))
5396 (concat "<" end-time ">"))
5399 (org-add-props txt props
5400 'org-marker marker 'org-hd-marker hdmarker
5401 'type "block" 'date date
5402 'todo-state todo-state
5403 'priority (org-get-priority txt) 'org-category category)
5406 ;; Sort the entries by expiration date.
5409 ;;; Agenda presentation and sorting
5411 (defvar org-prefix-has-time nil
5412 "A flag, set by `org-compile-prefix-format'.
5413 The flag is set if the currently compiled format contains a `%t'.")
5414 (defvar org-prefix-has-tag nil
5415 "A flag, set by `org-compile-prefix-format'.
5416 The flag is set if the currently compiled format contains a `%T'.")
5417 (defvar org-prefix-has-effort nil
5418 "A flag, set by `org-compile-prefix-format'.
5419 The flag is set if the currently compiled format contains a `%e'.")
5420 (defvar org-prefix-category-length nil
5421 "Used by `org-compile-prefix-format' to remember the category field width.")
5422 (defvar org-prefix-category-max-length nil
5423 "Used by `org-compile-prefix-format' to remember the category field width.")
5425 (defun org-agenda-get-category-icon (category)
5426 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5427 (dolist (entry org-agenda-category-icon-alist)
5428 (when (org-string-match-p (car entry) category)
5429 (if (listp (cadr entry))
5430 (return (cadr entry))
5431 (return (apply 'create-image (cdr entry)))))))
5433 (defun org-format-agenda-item (extra txt &optional category tags dotime
5435 "Format TXT to be inserted into the agenda buffer.
5436 In particular, it adds the prefix and corresponding text properties. EXTRA
5437 must be a string and replaces the `%s' specifier in the prefix format.
5438 CATEGORY (string, symbol or nil) may be used to overrule the default
5439 category taken from local variable or file name. It will replace the `%c'
5440 specifier in the format. DOTIME, when non-nil, indicates that a
5441 time-of-day should be extracted from TXT for sorting of this entry, and for
5442 the `%t' specifier in the format. When DOTIME is a string, this string is
5443 searched for a time before TXT is. TAGS can be the tags of the headline.
5444 Any match of REMOVE-RE will be removed from TXT."
5446 ;; Diary entries sometimes have extra whitespace at the beginning
5447 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5449 ;; Fix the tags part in txt
5450 (setq txt (org-agenda-fix-displayed-tags
5452 org-agenda-show-inherited-tags
5453 org-agenda-hide-tags-regexp))
5454 (let* ((category (or category
5455 (if (stringp org-category)
5457 (and org-category (symbol-name org-category)))
5458 (if buffer-file-name
5459 (file-name-sans-extension
5460 (file-name-nondirectory buffer-file-name))
5462 (category-icon (org-agenda-get-category-icon category))
5463 (category-icon (if category-icon
5464 (propertize " " 'display category-icon)
5466 ;; time, tag, effort are needed for the eval of the prefix format
5467 (tag (if tags (nth (1- (length tags)) tags) ""))
5469 (ts (if dotime (concat
5470 (if (stringp dotime) dotime "")
5471 (and org-agenda-search-headline-for-time txt))))
5472 (time-of-day (and dotime (org-get-time-of-day ts)))
5473 stamp plain s0 s1 s2 rtn srp l
5474 duration thecategory)
5475 (and (org-mode-p) buffer-file-name
5476 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5477 (when (and dotime time-of-day)
5478 ;; Extract starting and ending time and move them to prefix
5479 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5480 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5481 (setq s0 (match-string 0 ts)
5482 srp (and stamp (match-end 3))
5483 s1 (match-string (if plain 1 2) ts)
5484 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5486 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5487 ;; them, we might want to remove them there to avoid duplication.
5488 ;; The user can turn this off with a variable.
5489 (if (and org-prefix-has-time
5490 org-agenda-remove-times-when-in-prefix (or stamp plain)
5491 (string-match (concat (regexp-quote s0) " *") txt)
5492 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5493 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5494 (= (match-beginning 0) 0)
5496 (setq txt (replace-match "" nil nil txt))))
5497 ;; Normalize the time(s) to 24 hour
5498 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5499 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5501 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5502 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5504 (org-minutes-to-hh:mm-string
5505 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5507 ;; Compute the duration
5509 (setq duration (- (org-hh:mm-string-to-minutes s2)
5510 (org-hh:mm-string-to-minutes s1)))))
5512 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5514 ;; Tags are in the string
5515 (if (or (eq org-agenda-remove-tags t)
5516 (and org-agenda-remove-tags
5517 org-prefix-has-tag))
5518 (setq txt (replace-match "" t t txt))
5519 (setq txt (replace-match
5520 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5521 (match-string 2 txt))
5527 (or (get-text-property 0 'org-hd-marker txt)
5528 (get-text-property 0 'org-marker txt)))
5531 (setq neffort (org-duration-string-to-minutes effort)
5532 effort (setq effort (concat "[" effort "]")))))
5533 ;; prevent erroring out with %e format when there is no effort
5534 (or effort (setq effort ""))
5537 (while (string-match remove-re txt)
5538 (setq txt (replace-match "" t t txt))))
5540 ;; Set org-heading property on `txt' to mark the start of the
5542 (add-text-properties 0 (length txt) '(org-heading t) txt)
5544 ;; Prepare the variables needed in the eval of the compiled format
5545 (setq time (cond (s2 (concat
5546 (org-agenda-time-of-day-to-ampm-maybe s1)
5547 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5548 (if org-agenda-timegrid-use-ampm " ")))
5550 (org-agenda-time-of-day-to-ampm-maybe s1)
5551 (if org-agenda-timegrid-use-ampm
5555 extra (or (and (not habitp) extra) "")
5556 category (if (symbolp category) (symbol-name category) category)
5557 thecategory (copy-sequence category))
5558 (if (string-match org-bracket-link-regexp category)
5560 (setq l (if (match-end 3)
5561 (- (match-end 3) (match-beginning 3))
5562 (- (match-end 1) (match-beginning 1))))
5563 (when (< l (or org-prefix-category-length 0))
5564 (setq category (copy-sequence category))
5565 (org-add-props category nil
5566 'extra-space (make-string
5567 (- org-prefix-category-length l 1) ?\ ))))
5568 (if (and org-prefix-category-max-length
5569 (>= (length category) org-prefix-category-max-length))
5570 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5571 ;; Evaluate the compiled format
5572 (setq rtn (concat (eval org-prefix-format-compiled) txt))
5574 ;; And finally add the text properties
5575 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5576 (org-add-props rtn nil
5577 'org-category (if thecategory (downcase thecategory) category)
5578 'tags (mapcar 'org-downcase-keep-props tags)
5579 'org-highest-priority org-highest-priority
5580 'org-lowest-priority org-lowest-priority
5581 'time-of-day time-of-day
5584 'effort-minutes neffort
5588 'format org-prefix-format-compiled
5591 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5592 "Remove tags string from TXT, and add a modified list of tags.
5593 The modified list may contain inherited tags, and tags matched by
5594 `org-agenda-hide-tags-regexp' will be removed."
5595 (when (or add-inherited hide-re)
5596 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5597 (setq txt (substring txt 0 (match-beginning 0))))
5600 (mapcar (lambda (tg)
5601 (if (or (and hide-re (string-match hide-re tg))
5602 (and (not add-inherited)
5603 (get-text-property 0 'inherited tg)))
5608 (let ((have-i (get-text-property 0 'inherited (car tags)))
5610 (setq txt (concat txt " :"
5613 (setq i (get-text-property 0 'inherited x))
5614 (if (and have-i (not i))
5620 (if have-i "::" ":"))))))
5623 (defun org-downcase-keep-props (s)
5624 (let ((props (text-properties-at 0 s)))
5625 (setq s (downcase s))
5626 (add-text-properties 0 (length s) props s)
5629 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5630 (defvar org-agenda-sorting-strategy-selected nil)
5632 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5634 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5635 ((and todayp (member 'today (car org-agenda-time-grid))))
5636 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5637 ((member 'weekly (car org-agenda-time-grid)))
5638 (t (throw 'exit list)))
5639 (let* ((have (delq nil (mapcar
5640 (lambda (x) (get-text-property 1 'time-of-day x))
5642 (string (nth 1 org-agenda-time-grid))
5643 (gridtimes (nth 2 org-agenda-time-grid))
5644 (req (car org-agenda-time-grid))
5645 (remove (member 'remove-match req))
5647 (if (and (member 'require-timed req) (not have))
5648 ;; don't show empty grid
5650 (while (setq time (pop gridtimes))
5651 (unless (and remove (member time have))
5652 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5653 (push (org-format-agenda-item
5655 (concat (substring time 0 -2) ":" (substring time -2)))
5658 2 (length (car new)) 'face 'org-time-grid (car new))))
5659 (when (and todayp org-agenda-show-current-time-in-grid)
5660 (push (org-format-agenda-item
5662 org-agenda-current-time-string
5664 (format-time-string "%H:%M "))
5667 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5669 (if (member 'time-up org-agenda-sorting-strategy-selected)
5671 (append list new)))))
5673 (defun org-compile-prefix-format (key)
5674 "Compile the prefix format into a Lisp form that can be evaluated.
5675 The resulting form is returned and stored in the variable
5676 `org-prefix-format-compiled'."
5677 (setq org-prefix-has-time nil org-prefix-has-tag nil
5678 org-prefix-category-length nil org-prefix-has-effort nil)
5680 ((stringp org-agenda-prefix-format)
5681 org-agenda-prefix-format)
5682 ((assq key org-agenda-prefix-format)
5683 (cdr (assq key org-agenda-prefix-format)))
5684 (t " %-12:c%?-12t% s")))
5686 varform vars var e c f opt)
5687 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5689 (setq var (or (cdr (assoc (match-string 4 s)
5690 '(("c" . category) ("t" . time) ("s" . extra)
5691 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5693 c (or (match-string 3 s) "")
5694 opt (match-beginning 1)
5695 start (1+ (match-beginning 0)))
5696 (if (equal var 'time) (setq org-prefix-has-time t))
5697 (if (equal var 'tag) (setq org-prefix-has-tag t))
5698 (if (equal var 'effort) (setq org-prefix-has-effort t))
5699 (setq f (concat "%" (match-string 2 s) "s"))
5700 (when (equal var 'category)
5701 (setq org-prefix-category-length
5702 (floor (abs (string-to-number (match-string 2 s)))))
5703 (setq org-prefix-category-max-length
5704 (let ((x (match-string 2 s)))
5706 (if (string-match "\\.[0-9]+" x)
5707 (string-to-number (substring (match-string 0 x) 1)))))))
5709 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5712 `(if (equal "" ,var)
5714 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5715 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5716 (setq s (replace-match "%s" t nil s))
5717 (push varform vars))
5718 (setq vars (nreverse vars))
5719 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5721 (defun org-set-sorting-strategy (key)
5722 (if (symbolp (car org-agenda-sorting-strategy))
5724 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5725 (setq org-agenda-sorting-strategy-selected
5726 (or (cdr (assq key org-agenda-sorting-strategy))
5727 (cdr (assq 'agenda org-agenda-sorting-strategy))
5728 '(time-up category-keep priority-down)))))
5730 (defun org-get-time-of-day (s &optional string mod24)
5731 "Check string S for a time of day.
5732 If found, return it as a military time number between 0 and 2400.
5733 If not found, return nil.
5734 The optional STRING argument forces conversion into a 5 character wide string
5738 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5739 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5740 (let* ((h (string-to-number (match-string 1 s)))
5741 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5742 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5743 (am-p (equal ampm "am"))
5744 (h1 (cond ((not ampm) h)
5745 ((= h 12) (if am-p 0 12))
5746 (t (+ h (if am-p 0 12)))))
5747 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5749 (t0 (+ (* 100 h2) m))
5750 (t1 (concat (if (>= h1 24) "+" " ")
5751 (if (and org-agenda-time-leading-zero
5752 (< t0 1000)) "0" "")
5753 (if (< t0 100) "0" "")
5754 (if (< t0 10) "0" "")
5755 (int-to-string t0))))
5756 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5758 (defvar org-agenda-before-sorting-filter-function nil
5759 "Function to be applied to agenda items prior to sorting.
5760 Prior to sorting also means just before they are inserted into the agenda.
5762 To aid sorting, you may revisit the original entries and add more text
5763 properties which will later be used by the sorting functions.
5765 The function should take a string argument, an agenda line.
5766 It has access to the text properties in that line, which contain among
5767 other things, the property `org-hd-marker' that points to the entry
5768 where the line comes from. Note that not all lines going into the agenda
5769 have this property, only most.
5771 The function should return the modified string. It is probably best
5772 to ONLY change text properties.
5774 You can also use this function as a filter, by returning nil for lines
5775 you don't want to have in the agenda at all. For this application, you
5776 could bind the variable in the options section of a custom command.")
5778 (defun org-finalize-agenda-entries (list &optional nosort)
5779 "Sort and concatenate the agenda items."
5780 (setq list (mapcar 'org-agenda-highlight-todo list))
5783 (when org-agenda-before-sorting-filter-function
5784 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5785 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5787 (defun org-agenda-highlight-todo (x)
5788 (let ((org-done-keywords org-done-keywords-for-agenda)
5789 (case-fold-search nil)
5793 (beginning-of-line 1)
5794 (setq re (org-get-at-bol 'org-todo-regexp))
5795 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
5796 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5797 (add-text-properties (match-beginning 0) (match-end 1)
5798 (list 'face (org-get-todo-face 1)))
5799 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5800 (delete-region (match-beginning 1) (1- (match-end 0)))
5801 (goto-char (match-beginning 1))
5802 (insert (format org-agenda-todo-keyword-format s)))))
5803 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
5804 (setq re (get-text-property 0 'org-todo-regexp x))
5806 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5808 (add-text-properties
5809 (or (match-end 1) (match-end 0)) (match-end 0)
5810 (list 'face (org-get-todo-face (match-string 2 x)))
5813 (setq x (concat (substring x 0 (match-end 1))
5814 (format org-agenda-todo-keyword-format
5816 (org-add-props " " (text-properties-at 0 x))
5817 (substring x (match-end 3)))))))
5820 (defsubst org-cmp-priority (a b)
5821 "Compare the priorities of string A and B."
5822 (let ((pa (or (get-text-property 1 'priority a) 0))
5823 (pb (or (get-text-property 1 'priority b) 0)))
5824 (cond ((> pa pb) +1)
5828 (defsubst org-cmp-effort (a b)
5829 "Compare the effort values of string A and B."
5830 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5831 (ea (or (get-text-property 1 'effort-minutes a) def))
5832 (eb (or (get-text-property 1 'effort-minutes b) def)))
5833 (cond ((> ea eb) +1)
5837 (defsubst org-cmp-category (a b)
5838 "Compare the string values of categories of strings A and B."
5839 (let ((ca (or (get-text-property 1 'org-category a) ""))
5840 (cb (or (get-text-property 1 'org-category b) "")))
5841 (cond ((string-lessp ca cb) -1)
5842 ((string-lessp cb ca) +1)
5845 (defsubst org-cmp-todo-state (a b)
5846 "Compare the todo states of strings A and B."
5847 (let* ((ma (or (get-text-property 1 'org-marker a)
5848 (get-text-property 1 'org-hd-marker a)))
5849 (mb (or (get-text-property 1 'org-marker b)
5850 (get-text-property 1 'org-hd-marker b)))
5851 (fa (and ma (marker-buffer ma)))
5852 (fb (and mb (marker-buffer mb)))
5854 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5855 (and fb (with-current-buffer fb org-todo-keywords-1))))
5856 (ta (or (get-text-property 1 'todo-state a) ""))
5857 (tb (or (get-text-property 1 'todo-state b) ""))
5858 (la (- (length (member ta todo-kwds))))
5859 (lb (- (length (member tb todo-kwds))))
5860 (donepa (member ta org-done-keywords-for-agenda))
5861 (donepb (member tb org-done-keywords-for-agenda)))
5862 (cond ((and donepa (not donepb)) -1)
5863 ((and (not donepa) donepb) +1)
5868 (defsubst org-cmp-alpha (a b)
5869 "Compare the headlines, alphabetically."
5870 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
5871 (plb (text-property-any 0 (length b) 'org-heading t b))
5872 (ta (and pla (substring a pla)))
5873 (tb (and plb (substring b plb))))
5875 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5876 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5877 (setq ta (substring ta (match-end 0))))
5878 (setq ta (downcase ta)))
5880 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5881 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5882 (setq tb (substring tb (match-end 0))))
5883 (setq tb (downcase tb)))
5886 ((string-lessp ta tb) -1)
5887 ((string-lessp tb ta) +1)
5890 (defsubst org-cmp-tag (a b)
5891 "Compare the string values of the first tags of A and B."
5892 (let ((ta (car (last (get-text-property 1 'tags a))))
5893 (tb (car (last (get-text-property 1 'tags b)))))
5896 ((string-lessp ta tb) -1)
5897 ((string-lessp tb ta) +1)
5900 (defsubst org-cmp-time (a b)
5901 "Compare the time-of-day values of strings A and B."
5902 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5903 (ta (or (get-text-property 1 'time-of-day a) def))
5904 (tb (or (get-text-property 1 'time-of-day b) def)))
5905 (cond ((< ta tb) -1)
5909 (defsubst org-cmp-habit-p (a b)
5910 "Compare the todo states of strings A and B."
5911 (let ((ha (get-text-property 1 'org-habit-p a))
5912 (hb (get-text-property 1 'org-habit-p b)))
5913 (cond ((and ha (not hb)) -1)
5914 ((and (not ha) hb) +1)
5917 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5919 (defun org-entries-lessp (a b)
5920 "Predicate for sorting agenda entries."
5921 ;; The following variables will be used when the form is evaluated.
5922 ;; So even though the compiler complains, keep them.
5923 (let* ((ss org-agenda-sorting-strategy-selected)
5924 (time-up (and (org-em 'time-up 'time-down ss)
5925 (org-cmp-time a b)))
5926 (time-down (if time-up (- time-up) nil))
5927 (priority-up (and (org-em 'priority-up 'priority-down ss)
5928 (org-cmp-priority a b)))
5929 (priority-down (if priority-up (- priority-up) nil))
5930 (effort-up (and (org-em 'effort-up 'effort-down ss)
5931 (org-cmp-effort a b)))
5932 (effort-down (if effort-up (- effort-up) nil))
5933 (category-up (and (or (org-em 'category-up 'category-down ss)
5934 (memq 'category-keep ss))
5935 (org-cmp-category a b)))
5936 (category-down (if category-up (- category-up) nil))
5937 (category-keep (if category-up +1 nil))
5938 (tag-up (and (org-em 'tag-up 'tag-down ss)
5940 (tag-down (if tag-up (- tag-up) nil))
5941 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5942 (org-cmp-todo-state a b)))
5943 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5944 (habit-up (and (org-em 'habit-up 'habit-down ss)
5945 (org-cmp-habit-p a b)))
5946 (habit-down (if habit-up (- habit-up) nil))
5947 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5948 (org-cmp-alpha a b)))
5949 (alpha-down (if alpha-up (- alpha-up) nil))
5950 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5951 user-defined-up user-defined-down)
5952 (if (and need-user-cmp org-agenda-cmp-user-defined
5953 (functionp org-agenda-cmp-user-defined))
5954 (setq user-defined-up
5955 (funcall org-agenda-cmp-user-defined a b)
5956 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5958 (eval (cons 'or org-agenda-sorting-strategy-selected))
5959 '((-1 . t) (1 . nil) (nil . nil))))))
5961 ;;; Agenda restriction lock
5963 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5964 "Overlay to mark the headline to which agenda commands are restricted.")
5965 (overlay-put org-agenda-restriction-lock-overlay
5966 'face 'org-agenda-restriction-lock)
5967 (overlay-put org-agenda-restriction-lock-overlay
5968 'help-echo "Agendas are currently limited to this subtree.")
5969 (org-detach-overlay org-agenda-restriction-lock-overlay)
5971 (defun org-agenda-set-restriction-lock (&optional type)
5972 "Set restriction lock for agenda, to current subtree or file.
5973 Restriction will be the file if TYPE is `file', or if type is the
5974 universal prefix '(4), or if the cursor is before the first headline
5975 in the file. Otherwise, restriction will be to the current subtree."
5977 (and (equal type '(4)) (setq type 'file))
5980 ((org-at-heading-p) 'subtree)
5981 ((condition-case nil (org-back-to-heading t) (error nil))
5984 (if (eq type 'subtree)
5986 (setq org-agenda-restrict t)
5987 (setq org-agenda-overriding-restriction 'subtree)
5988 (put 'org-agenda-files 'org-restrict
5989 (list (buffer-file-name (buffer-base-buffer))))
5990 (org-back-to-heading t)
5991 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5992 (move-marker org-agenda-restrict-begin (point))
5993 (move-marker org-agenda-restrict-end
5994 (save-excursion (org-end-of-subtree t)))
5995 (message "Locking agenda restriction to subtree"))
5996 (put 'org-agenda-files 'org-restrict
5997 (list (buffer-file-name (buffer-base-buffer))))
5998 (setq org-agenda-restrict nil)
5999 (setq org-agenda-overriding-restriction 'file)
6000 (move-marker org-agenda-restrict-begin nil)
6001 (move-marker org-agenda-restrict-end nil)
6002 (message "Locking agenda restriction to file"))
6003 (setq current-prefix-arg nil)
6004 (org-agenda-maybe-redo))
6006 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6007 "Remove the agenda restriction lock."
6009 (org-detach-overlay org-agenda-restriction-lock-overlay)
6010 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6011 (setq org-agenda-overriding-restriction nil)
6012 (setq org-agenda-restrict nil)
6013 (put 'org-agenda-files 'org-restrict nil)
6014 (move-marker org-agenda-restrict-begin nil)
6015 (move-marker org-agenda-restrict-end nil)
6016 (setq current-prefix-arg nil)
6017 (message "Agenda restriction lock removed")
6018 (or noupdate (org-agenda-maybe-redo)))
6020 (defun org-agenda-maybe-redo ()
6021 "If there is any window showing the agenda view, update it."
6022 (let ((w (get-buffer-window org-agenda-buffer-name t))
6023 (w0 (selected-window)))
6028 (if org-agenda-overriding-restriction
6029 (message "Agenda view shifted to new %s restriction"
6030 org-agenda-overriding-restriction)
6031 (message "Agenda restriction lock removed")))))
6035 (defun org-agenda-check-type (error &rest types)
6036 "Check if agenda buffer is of allowed type.
6037 If ERROR is non-nil, throw an error, otherwise just return nil."
6038 (if (memq org-agenda-type types)
6041 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6044 (defun org-agenda-quit ()
6045 "Exit agenda by removing the window or the buffer."
6047 (if org-agenda-columns-active
6049 (let ((buf (current-buffer)))
6050 (if (eq org-agenda-window-setup 'other-frame)
6053 (org-agenda-reset-markers)
6054 (org-columns-remove-overlays)
6055 (setq org-agenda-archives-mode nil)
6057 (and (not (eq org-agenda-window-setup 'current-window))
6058 (not (one-window-p))
6061 (org-agenda-reset-markers)
6062 (org-columns-remove-overlays)
6063 (setq org-agenda-archives-mode nil)))
6064 ;; Maybe restore the pre-agenda window configuration.
6065 (and org-agenda-restore-windows-after-quit
6066 (not (eq org-agenda-window-setup 'other-frame))
6067 org-pre-agenda-window-conf
6068 (set-window-configuration org-pre-agenda-window-conf))))
6070 (defun org-agenda-exit ()
6071 "Exit agenda by removing the window or the buffer.
6072 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6073 Org-mode buffers visited directly by the user will not be touched."
6075 (org-release-buffers org-agenda-new-buffers)
6076 (setq org-agenda-new-buffers nil)
6079 (defun org-agenda-execute (arg)
6080 "Execute another agenda command, keeping same window.
6081 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6084 (let ((org-agenda-window-setup 'current-window))
6087 (defun org-agenda-redo ()
6089 When this is the global TODO list, a prefix argument will be interpreted."
6091 (let* ((org-agenda-keep-modes t)
6092 (filter org-agenda-filter)
6093 (preset (get 'org-agenda-filter :preset-filter))
6094 (org-agenda-filter-while-redo (or filter preset))
6095 (cols org-agenda-columns-active)
6096 (line (org-current-line))
6097 (window-line (- line (org-current-line (window-start))))
6098 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6099 (put 'org-agenda-filter :preset-filter nil)
6100 (and cols (org-columns-quit))
6101 (message "Rebuilding agenda buffer...")
6102 (org-let lprops '(eval org-agenda-redo-command))
6103 (setq org-agenda-undo-list nil
6104 org-agenda-pending-undo-list nil)
6105 (message "Rebuilding agenda buffer...done")
6106 (put 'org-agenda-filter :preset-filter preset)
6107 (and (or filter preset) (org-agenda-filter-apply filter))
6108 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6109 (org-goto-line line)
6110 (recenter window-line)))
6113 (defvar org-global-tags-completion-table nil)
6114 (defvar org-agenda-filter-form nil)
6115 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6116 "Keep only those lines in the agenda buffer that have a specific tag.
6117 The tag is selected with its fast selection letter, as configured.
6118 With prefix argument STRIP, remove all lines that do have the tag.
6119 A lisp caller can specify CHAR. NARROW means that the new tag should be
6120 used to narrow the search - the interactive user can also press `-' or `+'
6121 to switch to narrowing."
6123 (let* ((alist org-tag-alist-for-agenda)
6124 (tag-chars (mapconcat
6125 (lambda (x) (if (and (not (symbolp (car x)))
6127 (char-to-string (cdr x))
6130 (efforts (org-split-string
6131 (or (cdr (assoc (concat org-effort-property "_ALL")
6132 org-global-properties))
6133 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6135 (effort-op org-agenda-filter-effort-default-operator)
6137 (inhibit-read-only t)
6138 (current org-agenda-filter)
6139 maybe-refresh a n tag)
6142 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6143 (if narrow "Narrow" "Filter") tag-chars
6144 (if org-agenda-auto-exclude-function "[RET], " ""))
6145 (setq char (read-char)))
6146 (when (member char '(?+ ?-))
6148 (cond ((equal char ?-) (setq strip t narrow t))
6149 ((equal char ?+) (setq strip nil narrow t)))
6151 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6152 (setq char (read-char)))
6153 (when (member char '(?< ?> ?= ??))
6154 ;; An effort operator
6155 (setq effort-op (char-to-string char))
6156 (setq alist nil) ; to make sure it will be interpreted as effort.
6157 (unless (equal char ??)
6158 (loop for i from 0 to 9 do
6162 (if (= i 9) "0" (int-to-string (1+ i)))
6163 "]" (nth i efforts))))
6164 (message "Effort%s: %s " effort-op effort-prompt)
6165 (setq char (read-char))
6166 (when (or (< char ?0) (> char ?9))
6167 (error "Need 1-9,0 to select effort" ))))
6168 (when (equal char ?\t)
6169 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6170 (org-set-local 'org-global-tags-completion-table
6171 (org-global-tags-completion-table)))
6172 (let ((completion-ignore-case t))
6173 (setq tag (org-icompleting-read
6174 "Tag: " org-global-tags-completion-table))))
6177 (org-agenda-filter-by-tag-show-all)
6178 (when org-agenda-auto-exclude-function
6179 (setq org-agenda-filter '())
6180 (dolist (tag (org-agenda-get-represented-tags))
6181 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6183 (push modifier org-agenda-filter))))
6184 (if (not (null org-agenda-filter))
6185 (org-agenda-filter-apply org-agenda-filter)))
6186 (setq maybe-refresh t))
6188 (org-agenda-filter-by-tag-show-all)
6189 (when (get 'org-agenda-filter :preset-filter)
6190 (org-agenda-filter-apply org-agenda-filter))
6191 (setq maybe-refresh t))
6192 ((or (equal char ?\ )
6193 (setq a (rassoc char alist))
6194 (and (>= char ?0) (<= char ?9)
6195 (setq n (if (= char ?0) 9 (- char ?0 1))
6196 tag (concat effort-op (nth n efforts))
6201 (and tag (setq a (cons tag nil))))
6202 (org-agenda-filter-by-tag-show-all)
6204 (setq org-agenda-filter
6205 (cons (concat (if strip "-" "+") tag)
6206 (if narrow current nil)))
6207 (org-agenda-filter-apply org-agenda-filter)
6208 (setq maybe-refresh t))
6209 (t (error "Invalid tag selection character %c" char)))
6210 (when (and maybe-refresh
6211 (eq org-agenda-clockreport-mode 'with-filter))
6212 (org-agenda-redo))))
6214 (defun org-agenda-get-represented-tags ()
6215 "Get a list of all tags currently represented in the agenda."
6218 (goto-char (point-min))
6219 (while (setq p (next-single-property-change (point) 'tags))
6221 (mapc (lambda (x) (add-to-list 'tags x))
6222 (get-text-property (point) 'tags))))
6225 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6226 "Refine the current filter. See `org-agenda-filter-by-tag."
6228 (org-agenda-filter-by-tag strip char 'refine))
6230 (defun org-agenda-filter-make-matcher ()
6231 "Create the form that tests a line for the agenda filter."
6233 (dolist (x (append (get 'org-agenda-filter :preset-filter)
6235 (if (member x '("-" "+"))
6236 (setq f1 (if (equal x "-") 'tags '(not tags)))
6237 (if (string-match "[<=>?]" x)
6238 (setq f1 (org-agenda-filter-effort-form x))
6239 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6240 (if (equal (string-to-char x) ?-)
6241 (setq f1 (list 'not f1))))
6243 (cons 'and (nreverse f))))
6245 (defun org-agenda-filter-effort-form (e)
6246 "Return the form to compare the effort of the current line with what E says.
6247 E looks like \"+<2:25\"."
6249 (setq e (substring e 1))
6250 (setq op (string-to-char e) e (substring e 1))
6251 (setq op (cond ((equal op ?<) '<=)
6255 (list 'org-agenda-compare-effort (list 'quote op)
6256 (org-duration-string-to-minutes e))))
6258 (defun org-agenda-compare-effort (op value)
6259 "Compare the effort of the current line with VALUE, using OP.
6260 If the line does not have an effort defined, return nil."
6261 (let ((eff (org-get-at-bol 'effort-minutes)))
6264 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6267 (defun org-agenda-filter-apply (filter)
6268 "Set FILTER as the new agenda filter and apply it."
6270 (setq org-agenda-filter filter
6271 org-agenda-filter-form (org-agenda-filter-make-matcher))
6272 (org-agenda-set-mode-name)
6274 (goto-char (point-min))
6276 (if (org-get-at-bol 'org-marker)
6278 (setq tags (org-get-at-bol 'tags)) ; used in eval
6279 (if (not (eval org-agenda-filter-form))
6280 (org-agenda-filter-by-tag-hide-line))
6281 (beginning-of-line 2))
6282 (beginning-of-line 2))))
6283 (if (get-char-property (point) 'invisible)
6284 (org-agenda-previous-line))))
6286 (defun org-agenda-filter-by-tag-hide-line ()
6288 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6290 (overlay-put ov 'invisible t)
6291 (overlay-put ov 'type 'tags-filter)
6292 (push ov org-agenda-filter-overlays)))
6294 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6295 (setq pos (or pos (point)))
6297 (dolist (ov (overlays-at pos))
6298 (when (and (overlay-get ov 'invisible)
6299 (eq (overlay-get ov 'type) 'tags-filter))
6301 (if (< (overlay-start ov) (point-at-eol))
6302 (move-overlay ov (point-at-eol)
6303 (overlay-end ov)))))))
6305 (defun org-agenda-filter-by-tag-show-all ()
6306 (mapc 'delete-overlay org-agenda-filter-overlays)
6307 (setq org-agenda-filter-overlays nil)
6308 (setq org-agenda-filter nil)
6309 (setq org-agenda-filter-form nil)
6310 (org-agenda-set-mode-name))
6312 (defun org-agenda-manipulate-query-add ()
6313 "Manipulate the query by adding a search term with positive selection.
6314 Positive selection means the term must be matched for selection of an entry."
6316 (org-agenda-manipulate-query ?\[))
6317 (defun org-agenda-manipulate-query-subtract ()
6318 "Manipulate the query by adding a search term with negative selection.
6319 Negative selection means term must not be matched for selection of an entry."
6321 (org-agenda-manipulate-query ?\]))
6322 (defun org-agenda-manipulate-query-add-re ()
6323 "Manipulate the query by adding a search regexp with positive selection.
6324 Positive selection means the regexp must match for selection of an entry."
6326 (org-agenda-manipulate-query ?\{))
6327 (defun org-agenda-manipulate-query-subtract-re ()
6328 "Manipulate the query by adding a search regexp with negative selection.
6329 Negative selection means regexp must not match for selection of an entry."
6331 (org-agenda-manipulate-query ?\}))
6332 (defun org-agenda-manipulate-query (char)
6334 ((memq org-agenda-type '(timeline agenda))
6335 (let ((org-agenda-include-inactive-timestamps t))
6337 (message "Display now includes inactive timestamps as well"))
6338 ((eq org-agenda-type 'search)
6340 'org-agenda-query-string
6341 (if org-agenda-last-search-view-search-was-boolean
6342 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6343 (?\{ . " +{}") (?\} . " -{}"))))
6345 (setq org-agenda-redo-command
6346 (list 'org-search-view
6348 org-agenda-query-string
6349 (+ (length org-agenda-query-string)
6350 (if (member char '(?\{ ?\})) 0 1))))
6351 (set-register org-agenda-query-register org-agenda-query-string)
6353 (t (error "Cannot manipulate query for %s-type agenda buffers"
6356 (defun org-add-to-string (var string)
6357 (set var (concat (symbol-value var) string)))
6359 (defun org-agenda-goto-date (date)
6360 "Jump to DATE in agenda."
6361 (interactive (list (let ((org-read-date-prefer-future
6362 (eval org-agenda-jump-prefer-future)))
6364 (org-agenda-list nil date))
6366 (defun org-agenda-goto-today ()
6369 (org-agenda-check-type t 'timeline 'agenda)
6370 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6372 (tdpos (goto-char tdpos))
6373 ((eq org-agenda-type 'agenda)
6374 (let* ((sd (org-agenda-compute-starting-span
6375 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6376 (org-agenda-overriding-arguments org-agenda-last-arguments))
6377 (setf (nth 1 org-agenda-overriding-arguments) sd)
6379 (org-agenda-find-same-or-today-or-agenda)))
6380 (t (error "Cannot find today")))))
6382 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6384 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6385 (text-property-any (point-min) (point-max) 'org-today t)
6386 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6389 (defun org-agenda-later (arg)
6390 "Go forward in time by thee current span.
6391 With prefix ARG, go forward that many times the current span."
6393 (org-agenda-check-type t 'agenda)
6394 (let* ((span org-agenda-current-span)
6395 (sd org-starting-day)
6396 (greg (calendar-gregorian-from-absolute sd))
6397 (cnt (org-get-at-bol 'org-day-cnt))
6401 (setq sd (+ arg sd)))
6403 (setq sd (+ (* 7 arg) sd)))
6405 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6406 sd (calendar-absolute-from-gregorian greg2))
6407 (setcar greg2 (1+ (car greg2))))
6409 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6410 sd (calendar-absolute-from-gregorian greg2))
6411 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6413 (setq sd (+ (* span arg) sd))))
6414 (let ((org-agenda-overriding-arguments
6415 (list (car org-agenda-last-arguments) sd span t)))
6417 (org-agenda-find-same-or-today-or-agenda cnt))))
6419 (defun org-agenda-earlier (arg)
6420 "Go backward in time by the current span.
6421 With prefix ARG, go backward that many times the current span."
6423 (org-agenda-later (- arg)))
6425 (defun org-agenda-view-mode-dispatch ()
6426 "Call one of the view mode commands."
6428 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6429 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6430 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6432 (let ((a (read-char-exclusive)))
6434 (?\ (call-interactively 'org-agenda-reset-view))
6435 (?d (call-interactively 'org-agenda-day-view))
6436 (?w (call-interactively 'org-agenda-week-view))
6437 (?m (call-interactively 'org-agenda-month-view))
6438 (?y (call-interactively 'org-agenda-year-view))
6439 (?l (call-interactively 'org-agenda-log-mode))
6440 (?L (org-agenda-log-mode '(4)))
6441 (?c (org-agenda-log-mode 'clockcheck))
6442 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6443 (?a (call-interactively 'org-agenda-archives-mode))
6444 (?A (org-agenda-archives-mode 'files))
6445 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6446 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6447 (?G (call-interactively 'org-agenda-toggle-time-grid))
6448 (?D (call-interactively 'org-agenda-toggle-diary))
6449 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6450 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6451 (org-agenda-check-type t 'timeline 'agenda)
6453 (message "Display now includes inactive timestamps as well"))
6454 (?q (message "Abort"))
6455 (otherwise (error "Invalid key" )))))
6457 (defun org-agenda-reset-view ()
6458 "Switch to default view for agenda."
6460 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6461 (defun org-agenda-day-view (&optional day-of-year)
6462 "Switch to daily view for agenda.
6463 With argument DAY-OF-YEAR, switch to that day of the year."
6465 (org-agenda-change-time-span 'day day-of-year))
6466 (defun org-agenda-week-view (&optional iso-week)
6467 "Switch to daily view for agenda.
6468 With argument ISO-WEEK, switch to the corresponding ISO week.
6469 If ISO-WEEK has more then 2 digits, only the last two encode the
6470 week. Any digits before this encode a year. So 200712 means
6471 week 12 of year 2007. Years in the range 1938-2037 can also be
6472 written as 2-digit years."
6474 (org-agenda-change-time-span 'week iso-week))
6475 (defun org-agenda-month-view (&optional month)
6476 "Switch to monthly view for agenda.
6477 With argument MONTH, switch to that month."
6479 (org-agenda-change-time-span 'month month))
6480 (defun org-agenda-year-view (&optional year)
6481 "Switch to yearly view for agenda.
6482 With argument YEAR, switch to that year.
6483 If MONTH has more then 2 digits, only the last two encode the
6484 month. Any digits before this encode a year. So 200712 means
6485 December year 2007. Years in the range 1938-2037 can also be
6486 written as 2-digit years."
6489 (setq year (org-small-year-to-year year)))
6490 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6491 (org-agenda-change-time-span 'year year)
6494 (defun org-agenda-change-time-span (span &optional n)
6495 "Change the agenda view to SPAN.
6496 SPAN may be `day', `week', `month', `year'."
6497 (org-agenda-check-type t 'agenda)
6498 (if (and (not n) (equal org-agenda-current-span span))
6499 (error "Viewing span is already \"%s\"" span))
6500 (let* ((sd (or (org-get-at-bol 'day)
6502 (sd (org-agenda-compute-starting-span sd span n))
6503 (org-agenda-overriding-arguments
6504 (or org-agenda-overriding-arguments
6505 (list (car org-agenda-last-arguments) sd span t))))
6507 (org-agenda-find-same-or-today-or-agenda))
6508 (org-agenda-set-mode-name)
6509 (message "Switched to %s view" span))
6511 (defun org-agenda-compute-starting-span (sd span &optional n)
6512 "Compute starting date for agenda.
6513 SPAN may be `day', `week', `month', `year'. The return value
6514 is a cons cell with the starting date and the number of days,
6515 so that the date SD will be in that range."
6516 (let* ((greg (calendar-gregorian-from-absolute sd))
6523 (setq sd (+ (calendar-absolute-from-gregorian
6527 (let* ((nt (calendar-day-of-week
6528 (calendar-gregorian-from-absolute sd)))
6529 (d (if org-agenda-start-on-weekday
6530 (- nt org-agenda-start-on-weekday)
6533 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6537 (setq y1 (org-small-year-to-year (/ n 100))
6540 (calendar-absolute-from-iso
6542 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6545 (when (and n (> n 99))
6546 (setq y1 (org-small-year-to-year (/ n 100))
6548 (setq sd (calendar-absolute-from-gregorian
6549 (list (or n mg) 1 (or y1 yg))))))
6551 (setq sd (calendar-absolute-from-gregorian
6552 (list 1 1 (or n yg))))))
6555 (defun org-agenda-next-date-line (&optional arg)
6556 "Jump to the next line indicating a date in agenda buffer."
6558 (org-agenda-check-type t 'agenda 'timeline)
6559 (beginning-of-line 1)
6560 ;; This does not work if user makes date format that starts with a blank
6561 (if (looking-at "^\\S-") (forward-char 1))
6562 (if (not (re-search-forward "^\\S-" nil t arg))
6565 (error "No next date after this line in this buffer")))
6566 (goto-char (match-beginning 0)))
6568 (defun org-agenda-previous-date-line (&optional arg)
6569 "Jump to the previous line indicating a date in agenda buffer."
6571 (org-agenda-check-type t 'agenda 'timeline)
6572 (beginning-of-line 1)
6573 (if (not (re-search-backward "^\\S-" nil t arg))
6574 (error "No previous date before this line in this buffer")))
6576 ;; Initialize the highlight
6577 (defvar org-hl (make-overlay 1 1))
6578 (overlay-put org-hl 'face 'highlight)
6580 (defun org-highlight (begin end &optional buffer)
6581 "Highlight a region with overlay."
6582 (move-overlay org-hl begin end (or buffer (current-buffer))))
6584 (defun org-unhighlight ()
6585 "Detach overlay INDEX."
6586 (org-detach-overlay org-hl))
6588 ;; FIXME this is currently not used.
6589 (defun org-highlight-until-next-command (beg end &optional buffer)
6590 "Move the highlight overlay to BEG/END, remove it before the next command."
6591 (org-highlight beg end buffer)
6592 (add-hook 'pre-command-hook 'org-unhighlight-once))
6593 (defun org-unhighlight-once ()
6594 "Remove the highlight from its position, and this function from the hook."
6595 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6598 (defun org-agenda-follow-mode ()
6599 "Toggle follow mode in an agenda buffer."
6601 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6602 (org-agenda-set-mode-name)
6603 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6605 (message "Follow mode is %s"
6606 (if org-agenda-follow-mode "on" "off")))
6608 (defun org-agenda-entry-text-mode (&optional arg)
6609 "Toggle entry text mode in an agenda buffer."
6611 (setq org-agenda-entry-text-mode (or (integerp arg)
6612 (not org-agenda-entry-text-mode)))
6613 (org-agenda-entry-text-hide)
6614 (and org-agenda-entry-text-mode
6615 (let ((org-agenda-entry-text-maxlines
6616 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6617 (org-agenda-entry-text-show)))
6618 (org-agenda-set-mode-name)
6619 (message "Entry text mode is %s. Maximum number of lines is %d"
6620 (if org-agenda-entry-text-mode "on" "off")
6621 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6623 (defun org-agenda-clockreport-mode (&optional with-filter)
6624 "Toggle clocktable mode in an agenda buffer.
6625 With prefix arg WITH-FILTER, make the clocktable respect the current
6628 (org-agenda-check-type t 'agenda)
6630 (setq org-agenda-clockreport-mode 'with-filter)
6631 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6632 (org-agenda-set-mode-name)
6634 (message "Clocktable mode is %s"
6635 (if org-agenda-clockreport-mode "on" "off")))
6637 (defun org-agenda-log-mode (&optional special)
6638 "Toggle log mode in an agenda buffer.
6639 With argument SPECIAL, show all possible log items, not only the ones
6640 configured in `org-agenda-log-mode-items'.
6641 With a double `C-u' prefix arg, show *only* log items, nothing else."
6643 (org-agenda-check-type t 'agenda 'timeline)
6644 (setq org-agenda-show-log
6646 ((equal special '(16)) 'only)
6647 ((eq special 'clockcheck)
6648 (if (eq org-agenda-show-log 'clockcheck)
6650 (special '(closed clock state))
6651 (t (not org-agenda-show-log))))
6652 (org-agenda-set-mode-name)
6654 (message "Log mode is %s"
6655 (if org-agenda-show-log "on" "off")))
6657 (defun org-agenda-archives-mode (&optional with-files)
6658 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6659 When called with a prefix argument, include all archive files as well."
6661 (setq org-agenda-archives-mode
6662 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6663 (org-agenda-set-mode-name)
6668 ((eq org-agenda-archives-mode nil)
6669 "No archives are included")
6670 ((eq org-agenda-archives-mode 'trees)
6671 (format "Trees with :%s: tag are included" org-archive-tag))
6672 ((eq org-agenda-archives-mode t)
6673 (format "Trees with :%s: tag and all active archive files are included"
6674 org-archive-tag)))))
6676 (defun org-agenda-toggle-diary ()
6677 "Toggle diary inclusion in an agenda buffer."
6679 (org-agenda-check-type t 'agenda)
6680 (setq org-agenda-include-diary (not org-agenda-include-diary))
6682 (org-agenda-set-mode-name)
6683 (message "Diary inclusion turned %s"
6684 (if org-agenda-include-diary "on" "off")))
6686 (defun org-agenda-toggle-deadlines ()
6687 "Toggle inclusion of entries with a deadline in an agenda buffer."
6689 (org-agenda-check-type t 'agenda)
6690 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6692 (org-agenda-set-mode-name)
6693 (message "Deadlines inclusion turned %s"
6694 (if org-agenda-include-deadlines "on" "off")))
6696 (defun org-agenda-toggle-time-grid ()
6697 "Toggle time grid in an agenda buffer."
6699 (org-agenda-check-type t 'agenda)
6700 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6702 (org-agenda-set-mode-name)
6703 (message "Time-grid turned %s"
6704 (if org-agenda-use-time-grid "on" "off")))
6706 (defun org-agenda-set-mode-name ()
6707 "Set the mode name to indicate all the small mode settings."
6710 (if (get 'org-agenda-files 'org-restrict) " []" "")
6712 '(:eval (org-agenda-span-name org-agenda-current-span))
6713 (if org-agenda-follow-mode " Follow" "")
6714 (if org-agenda-entry-text-mode " ETxt" "")
6715 (if org-agenda-include-diary " Diary" "")
6716 (if org-agenda-include-deadlines " Ddl" "")
6717 (if org-agenda-use-time-grid " Grid" "")
6718 (if (and (boundp 'org-habit-show-habits)
6719 org-habit-show-habits) " Habit" "")
6721 ((consp org-agenda-show-log) " LogAll")
6722 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
6723 (org-agenda-show-log " Log")
6725 (if (or org-agenda-filter (get 'org-agenda-filter
6727 (concat " {" (mapconcat
6729 (append (get 'org-agenda-filter
6731 org-agenda-filter) "") "}")
6733 (if org-agenda-archives-mode
6734 (if (eq org-agenda-archives-mode t)
6736 (format " :%s:" org-archive-tag))
6738 (if org-agenda-clockreport-mode
6739 (if (eq org-agenda-clockreport-mode 'with-filter)
6740 " Clock{}" " Clock")
6742 (force-mode-line-update))
6744 (defun org-agenda-post-command-hook ()
6745 (setq org-agenda-type
6746 (or (get-text-property (point) 'org-agenda-type)
6747 (get-text-property (max (point-min) (1- (point)))
6748 'org-agenda-type))))
6750 (defun org-agenda-next-line ()
6751 "Move cursor to the next line, and show if follow mode is active."
6753 (call-interactively 'next-line)
6754 (org-agenda-do-context-action))
6756 (defun org-agenda-previous-line ()
6757 "Move cursor to the previous line, and show if follow-mode is active."
6759 (call-interactively 'previous-line)
6760 (org-agenda-do-context-action))
6762 (defun org-agenda-do-context-action ()
6763 "Show outline path and, maybe, follow mode window."
6764 (let ((m (org-get-at-bol 'org-marker)))
6765 (if (and org-agenda-follow-mode m)
6767 (if (and m org-agenda-show-outline-path)
6768 (org-with-point-at m
6769 (org-display-outline-path t)))))
6771 (defun org-agenda-show-priority ()
6772 "Show the priority of the current item.
6773 This priority is composed of the main priority given with the [#A] cookies,
6774 and by additional input from the age of a schedules or deadline entry."
6776 (let* ((pri (org-get-at-bol 'priority)))
6777 (message "Priority is %d" (if pri pri -1000))))
6779 (defun org-agenda-show-tags ()
6780 "Show the tags applicable to the current item."
6782 (let* ((tags (org-get-at-bol 'tags)))
6784 (message "Tags are :%s:"
6785 (org-no-properties (mapconcat 'identity tags ":")))
6786 (message "No tags associated with this line"))))
6788 (defun org-agenda-goto (&optional highlight)
6789 "Go to the Org-mode file which contains the item at point."
6791 (let* ((marker (or (org-get-at-bol 'org-marker)
6792 (org-agenda-error)))
6793 (buffer (marker-buffer marker))
6794 (pos (marker-position marker)))
6795 (switch-to-buffer-other-window buffer)
6800 (org-show-context 'agenda)
6802 (and (outline-next-heading)
6803 (org-flag-heading nil)))) ; show the next heading
6804 (when (outline-invisible-p)
6805 (show-entry)) ; display invisible text
6806 (recenter (/ (window-height) 2))
6807 (run-hooks 'org-agenda-after-show-hook)
6808 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6810 (defvar org-agenda-after-show-hook nil
6811 "Normal hook run after an item has been shown from the agenda.
6812 Point is in the buffer where the item originated.")
6814 (defun org-agenda-kill ()
6815 "Kill the entry or subtree belonging to the current agenda entry."
6817 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6818 (let* ((marker (or (org-get-at-bol 'org-marker)
6819 (org-agenda-error)))
6820 (buffer (marker-buffer marker))
6821 (pos (marker-position marker))
6822 (type (org-get-at-bol 'type))
6823 dbeg dend (n 0) conf)
6824 (org-with-remote-undo buffer
6825 (with-current-buffer buffer
6828 (if (and (org-mode-p) (not (member type '("sexp"))))
6829 (setq dbeg (progn (org-back-to-heading t) (point))
6830 dend (org-end-of-subtree t t))
6831 (setq dbeg (point-at-bol)
6832 dend (min (point-max) (1+ (point-at-eol)))))
6834 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6835 (setq conf (or (eq t org-agenda-confirm-kill)
6836 (and (numberp org-agenda-confirm-kill)
6837 (> n org-agenda-confirm-kill))))
6840 (format "Delete entry with %d lines in buffer \"%s\"? "
6841 n (buffer-name buffer))))
6843 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6844 (with-current-buffer buffer (delete-region dbeg dend))
6845 (message "Agenda item and source killed"))))
6847 (defvar org-archive-default-command)
6848 (defun org-agenda-archive-default ()
6849 "Archive the entry or subtree belonging to the current agenda entry."
6851 (require 'org-archive)
6852 (org-agenda-archive-with org-archive-default-command))
6854 (defun org-agenda-archive-default-with-confirmation ()
6855 "Archive the entry or subtree belonging to the current agenda entry."
6857 (require 'org-archive)
6858 (org-agenda-archive-with org-archive-default-command 'confirm))
6860 (defun org-agenda-archive ()
6861 "Archive the entry or subtree belonging to the current agenda entry."
6863 (org-agenda-archive-with 'org-archive-subtree))
6865 (defun org-agenda-archive-to-archive-sibling ()
6866 "Move the entry to the archive sibling."
6868 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6870 (defun org-agenda-archive-with (cmd &optional confirm)
6871 "Move the entry to the archive sibling."
6873 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6874 (let* ((marker (or (org-get-at-bol 'org-marker)
6875 (org-agenda-error)))
6876 (buffer (marker-buffer marker))
6877 (pos (marker-position marker)))
6878 (org-with-remote-undo buffer
6879 (with-current-buffer buffer
6882 (not (y-or-n-p "Archive this subtree or entry? ")))
6886 (org-remove-subtree-entries-from-agenda)
6887 (org-back-to-heading t)
6889 (error "Archiving works only in Org-mode files"))))))
6891 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6892 "Remove all lines in the agenda that correspond to a given subtree.
6893 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6894 If this information is not given, the function uses the tree at point."
6895 (let ((buf (or buf (current-buffer))) m p)
6897 (unless (and beg end)
6898 (org-back-to-heading t)
6900 (org-end-of-subtree t)
6902 (set-buffer (get-buffer org-agenda-buffer-name))
6904 (goto-char (point-max))
6905 (beginning-of-line 1)
6907 (when (and (setq m (org-get-at-bol 'org-marker))
6908 (equal buf (marker-buffer m))
6909 (setq p (marker-position m))
6912 (let ((inhibit-read-only t))
6913 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6914 (beginning-of-line 0))))))
6916 (defun org-agenda-refile (&optional goto rfloc no-update)
6917 "Refile the item at point."
6919 (if (equal goto '(16))
6920 (org-refile-goto-last-stored)
6921 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6922 (org-agenda-error)))
6923 (buffer (marker-buffer marker))
6924 (pos (marker-position marker))
6926 (org-refile-get-location
6927 (if goto "Goto" "Refile to") buffer
6928 org-refile-allow-creating-parent-nodes))))
6929 (with-current-buffer buffer
6934 (org-remove-subtree-entries-from-agenda)
6935 (org-refile goto buffer rfloc)))))
6936 (unless no-update (org-agenda-redo))))
6938 (defun org-agenda-open-link (&optional arg)
6939 "Follow the link in the current line, if any.
6940 This looks for a link in the displayed line in the agenda. It also looks
6941 at the text of the entry itself."
6943 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6944 (org-get-at-bol 'org-marker)))
6945 (buffer (and marker (marker-buffer marker)))
6946 (prefix (buffer-substring
6947 (point-at-bol) (point-at-eol))))
6950 (with-current-buffer buffer
6955 (org-offer-links-in-entry arg prefix)))))
6956 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6958 (beginning-of-line 1)
6959 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6960 (org-open-link-from-string (match-string 1)))
6961 (t (error "No link to open here")))))
6963 (defun org-agenda-copy-local-variable (var)
6964 "Get a variable from a referenced buffer and install it here."
6965 (let ((m (org-get-at-bol 'org-marker)))
6966 (when (and m (buffer-live-p (marker-buffer m)))
6967 (org-set-local var (with-current-buffer (marker-buffer m)
6968 (symbol-value var))))))
6970 (defun org-agenda-switch-to (&optional delete-other-windows)
6971 "Go to the Org-mode file which contains the item at point."
6973 (if (and org-return-follows-link
6974 (not (org-get-at-bol 'org-marker))
6975 (org-in-regexp org-bracket-link-regexp))
6976 (org-open-link-from-string (match-string 0))
6977 (let* ((marker (or (org-get-at-bol 'org-marker)
6978 (org-agenda-error)))
6979 (buffer (marker-buffer marker))
6980 (pos (marker-position marker)))
6981 (org-pop-to-buffer-same-window buffer)
6982 (and delete-other-windows (delete-other-windows))
6986 (org-show-context 'agenda)
6988 (and (outline-next-heading)
6989 (org-flag-heading nil))) ; show the next heading
6990 (when (outline-invisible-p)
6991 (show-entry)))))) ; display invisible text
6993 (defun org-agenda-goto-mouse (ev)
6994 "Go to the Org-mode file which contains the item at the mouse click."
6996 (mouse-set-point ev)
6999 (defun org-agenda-show (&optional full-entry)
7000 "Display the Org-mode file which contains the item at point.
7001 With prefix argument FULL-ENTRY, make the entire entry visible
7002 if it was hidden in the outline."
7004 (let ((win (selected-window)))
7006 (let ((org-show-entry-below t))
7007 (org-agenda-goto t))
7008 (org-agenda-goto t))
7009 (select-window win)))
7011 (defvar org-agenda-show-window nil)
7012 (defun org-agenda-show-and-scroll-up ()
7013 "Display the Org-mode file which contains the item at point.
7014 When called repeatedly, scroll the window that is displaying the buffer."
7016 (let ((win (selected-window)))
7017 (if (and (window-live-p org-agenda-show-window)
7018 (eq this-command last-command))
7020 (select-window org-agenda-show-window)
7021 (ignore-errors (scroll-up)))
7024 (setq org-agenda-show-window (selected-window)))
7025 (select-window win)))
7027 (defun org-agenda-show-scroll-down ()
7028 "Scroll down the window showing the agenda."
7030 (let ((win (selected-window)))
7031 (when (window-live-p org-agenda-show-window)
7032 (select-window org-agenda-show-window)
7033 (ignore-errors (scroll-down))
7034 (select-window win))))
7036 (defun org-agenda-show-1 (&optional more)
7037 "Display the Org-mode file which contains the item at point.
7038 The prefix arg selects the amount of information to display:
7041 1 just show the entry according to defaults.
7042 2 show the children view
7043 3 show the subtree view
7044 4 show the entire subtree and any LOGBOOK drawers
7045 5 show the entire subtree and any drawers
7046 With prefix argument FULL-ENTRY, make the entire entry visible
7047 if it was hidden in the outline."
7049 (let ((win (selected-window)))
7051 (org-recenter-heading 1)
7056 (org-back-to-heading)
7057 (run-hook-with-args 'org-cycle-hook 'folded))
7058 (message "Remote: FOLDED"))
7059 ((and (org-called-interactively-p 'any) (= more 1))
7060 (message "Remote: show with default settings"))
7065 (org-back-to-heading)
7066 (run-hook-with-args 'org-cycle-hook 'children))
7067 (message "Remote: CHILDREN"))
7071 (org-back-to-heading)
7072 (run-hook-with-args 'org-cycle-hook 'subtree))
7073 (message "Remote: SUBTREE"))
7075 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7077 (concat "^[ \t]*:\\("
7078 (mapconcat 'regexp-quote org-drawers "\\|")
7082 (org-back-to-heading)
7083 (org-cycle-hide-drawers 'subtree)))
7084 (message "Remote: SUBTREE AND LOGBOOK"))
7087 (message "Remote: SUBTREE AND ALL DRAWERS")))
7088 (select-window win)))
7090 (defun org-recenter-heading (n)
7092 (org-back-to-heading)
7095 (defvar org-agenda-cycle-counter nil)
7096 (defun org-agenda-cycle-show (&optional n)
7097 "Show the current entry in another window, with default settings.
7098 Default settings are taken from `org-show-hierarchy-above' and siblings.
7099 When use repeatedly in immediate succession, the remote entry will cycle
7102 children -> subtree -> folded
7104 When called with a numeric prefix arg, that arg will be passed through to
7105 `org-agenda-show-1'. For the interpretation of that argument, see the
7106 docstring of `org-agenda-show-1'."
7109 (setq org-agenda-cycle-counter n)
7110 (if (not (eq last-command this-command))
7111 (setq org-agenda-cycle-counter 1)
7112 (if (equal org-agenda-cycle-counter 0)
7113 (setq org-agenda-cycle-counter 2)
7114 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7115 (if (> org-agenda-cycle-counter 3)
7116 (setq org-agenda-cycle-counter 0)))))
7117 (org-agenda-show-1 org-agenda-cycle-counter))
7119 (defun org-agenda-recenter (arg)
7120 "Display the Org-mode file which contains the item at point and recenter."
7122 (let ((win (selected-window)))
7125 (select-window win)))
7127 (defun org-agenda-show-mouse (ev)
7128 "Display the Org-mode file which contains the item at the mouse click."
7130 (mouse-set-point ev)
7133 (defun org-agenda-check-no-diary ()
7134 "Check if the entry is a diary link and abort if yes."
7135 (if (org-get-at-bol 'org-agenda-diary-link)
7136 (org-agenda-error)))
7138 (defun org-agenda-error ()
7139 (error "Command not allowed in this line"))
7141 (defun org-agenda-tree-to-indirect-buffer ()
7142 "Show the subtree corresponding to the current entry in an indirect buffer.
7143 This calls the command `org-tree-to-indirect-buffer' from the original
7145 With numerical prefix arg ARG, go up to this level and then take that tree.
7146 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7147 use the dedicated frame)."
7149 (org-agenda-check-no-diary)
7150 (let* ((marker (or (org-get-at-bol 'org-marker)
7151 (org-agenda-error)))
7152 (buffer (marker-buffer marker))
7153 (pos (marker-position marker)))
7154 (with-current-buffer buffer
7157 (call-interactively 'org-tree-to-indirect-buffer)))))
7159 (defvar org-last-heading-marker (make-marker)
7160 "Marker pointing to the headline that last changed its TODO state
7161 by a remote command from the agenda.")
7163 (defun org-agenda-todo-nextset ()
7164 "Switch TODO entry to next sequence."
7166 (org-agenda-todo 'nextset))
7168 (defun org-agenda-todo-previousset ()
7169 "Switch TODO entry to previous sequence."
7171 (org-agenda-todo 'previousset))
7173 (defun org-agenda-todo (&optional arg)
7174 "Cycle TODO state of line at point, also in Org-mode file.
7175 This changes the line at point, all other lines in the agenda referring to
7176 the same tree node, and the headline of the tree node in the Org-mode file."
7178 (org-agenda-check-no-diary)
7179 (let* ((col (current-column))
7180 (marker (or (org-get-at-bol 'org-marker)
7181 (org-agenda-error)))
7182 (buffer (marker-buffer marker))
7183 (pos (marker-position marker))
7184 (hdmarker (org-get-at-bol 'org-hd-marker))
7185 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7186 (inhibit-read-only t)
7187 org-agenda-headline-snapshot-before-repeat newhead just-one)
7188 (org-with-remote-undo buffer
7189 (with-current-buffer buffer
7192 (org-show-context 'agenda)
7194 (and (outline-next-heading)
7195 (org-flag-heading nil))) ; show the next heading
7196 (let ((current-prefix-arg arg))
7197 (call-interactively 'org-todo))
7198 (and (bolp) (forward-char 1))
7199 (setq newhead (org-get-heading))
7200 (when (and (org-bound-and-true-p
7201 org-agenda-headline-snapshot-before-repeat)
7202 (not (equal org-agenda-headline-snapshot-before-repeat
7205 (setq newhead org-agenda-headline-snapshot-before-repeat
7208 (org-back-to-heading)
7209 (move-marker org-last-heading-marker (point))))
7210 (beginning-of-line 1)
7212 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7213 (org-move-to-column col))))
7215 (defun org-agenda-add-note (&optional arg)
7216 "Add a time-stamped note to the entry at point."
7218 (org-agenda-check-no-diary)
7219 (let* ((marker (or (org-get-at-bol 'org-marker)
7220 (org-agenda-error)))
7221 (buffer (marker-buffer marker))
7222 (pos (marker-position marker))
7223 (hdmarker (org-get-at-bol 'org-hd-marker))
7224 (inhibit-read-only t))
7225 (with-current-buffer buffer
7228 (org-show-context 'agenda)
7230 (and (outline-next-heading)
7231 (org-flag-heading nil))) ; show the next heading
7234 (defun org-agenda-change-all-lines (newhead hdmarker
7235 &optional fixface just-this)
7236 "Change all lines in the agenda buffer which match HDMARKER.
7237 The new content of the line will be NEWHEAD (as modified by
7238 `org-format-agenda-item'). HDMARKER is checked with
7239 `equal' against all `org-hd-marker' text properties in the file.
7240 If FIXFACE is non-nil, the face of each item is modified according to
7242 If JUST-THIS is non-nil, change just the current line, not all.
7243 If FORCE-TAGS is non nil, the car of it returns the new tags."
7244 (let* ((inhibit-read-only t)
7245 (line (org-current-line))
7246 (thetags (with-current-buffer (marker-buffer hdmarker)
7247 (save-excursion (save-restriction (widen)
7248 (goto-char hdmarker)
7249 (org-get-tags-at)))))
7250 props m pl undone-face done-face finish new dotime cat tags)
7252 (goto-char (point-max))
7253 (beginning-of-line 1)
7255 (setq finish (bobp))
7256 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7257 (or (not just-this) (= (org-current-line) line))
7259 (setq props (text-properties-at (point))
7260 dotime (org-get-at-bol 'dotime)
7261 cat (org-get-at-bol 'org-category)
7264 (let ((org-prefix-format-compiled
7265 (or (get-text-property (point) 'format)
7266 org-prefix-format-compiled)))
7267 (with-current-buffer (marker-buffer hdmarker)
7271 (org-format-agenda-item (org-get-at-bol 'extra)
7272 newhead cat tags dotime)))))
7273 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7274 undone-face (org-get-at-bol 'undone-face)
7275 done-face (org-get-at-bol 'done-face))
7276 (beginning-of-line 1)
7279 (and (looking-at ".*\n?") (replace-match "")))
7281 (replace-match new t t)
7282 (beginning-of-line 1)
7283 (add-text-properties (point-at-bol) (point-at-eol) props)
7285 (add-text-properties
7286 (point-at-bol) (point-at-eol)
7288 (if org-last-todo-state-is-todo
7289 undone-face done-face))))
7290 (org-agenda-highlight-todo 'line)
7291 (beginning-of-line 1))
7292 (t (error "Line update did not work"))))
7293 (beginning-of-line 0)))
7294 (org-finalize-agenda)))
7296 (defun org-agenda-align-tags (&optional line)
7297 "Align all tags in agenda items to `org-agenda-tags-column'."
7298 (let ((inhibit-read-only t) l c)
7300 (goto-char (if line (point-at-bol) (point-min)))
7301 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7302 (if line (point-at-eol) nil) t)
7303 (add-text-properties
7304 (match-beginning 2) (match-end 2)
7305 (list 'face (delq nil (let ((prop (get-text-property
7306 (match-beginning 2) 'face)))
7307 (or (listp prop) (setq prop (list prop)))
7308 (if (memq 'org-tag prop)
7310 (cons 'org-tag prop))))))
7311 (setq l (- (match-end 2) (match-beginning 2))
7312 c (if (< org-agenda-tags-column 0)
7313 (- (abs org-agenda-tags-column) l)
7314 org-agenda-tags-column))
7315 (delete-region (match-beginning 1) (match-end 1))
7316 (goto-char (match-beginning 1))
7317 (insert (org-add-props
7318 (make-string (max 1 (- c (current-column))) ?\ )
7319 (plist-put (copy-sequence (text-properties-at (point)))
7321 (goto-char (point-min))
7322 (org-font-lock-add-tag-faces (point-max)))))
7324 (defun org-agenda-priority-up ()
7325 "Increase the priority of line at point, also in Org-mode file."
7327 (org-agenda-priority 'up))
7329 (defun org-agenda-priority-down ()
7330 "Decrease the priority of line at point, also in Org-mode file."
7332 (org-agenda-priority 'down))
7334 (defun org-agenda-priority (&optional force-direction)
7335 "Set the priority of line at point, also in Org-mode file.
7336 This changes the line at point, all other lines in the agenda referring to
7337 the same tree node, and the headline of the tree node in the Org-mode file."
7339 (unless org-enable-priority-commands
7340 (error "Priority commands are disabled"))
7341 (org-agenda-check-no-diary)
7342 (let* ((marker (or (org-get-at-bol 'org-marker)
7343 (org-agenda-error)))
7344 (hdmarker (org-get-at-bol 'org-hd-marker))
7345 (buffer (marker-buffer hdmarker))
7346 (pos (marker-position hdmarker))
7347 (inhibit-read-only t)
7349 (org-with-remote-undo buffer
7350 (with-current-buffer buffer
7353 (org-show-context 'agenda)
7355 (and (outline-next-heading)
7356 (org-flag-heading nil))) ; show the next heading
7357 (funcall 'org-priority force-direction)
7359 (setq newhead (org-get-heading)))
7360 (org-agenda-change-all-lines newhead hdmarker)
7361 (beginning-of-line 1))))
7363 ;; FIXME: should fix the tags property of the agenda line.
7364 (defun org-agenda-set-tags (&optional tag onoff)
7365 "Set tags for the current headline."
7367 (org-agenda-check-no-diary)
7368 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7369 (call-interactively 'org-change-tag-in-region)
7370 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7371 (org-agenda-error)))
7372 (buffer (marker-buffer hdmarker))
7373 (pos (marker-position hdmarker))
7374 (inhibit-read-only t)
7376 (org-with-remote-undo buffer
7377 (with-current-buffer buffer
7381 (org-show-context 'agenda))
7383 (and (outline-next-heading)
7384 (org-flag-heading nil))) ; show the next heading
7387 (org-toggle-tag tag onoff)
7388 (call-interactively 'org-set-tags))
7390 (setq newhead (org-get-heading)))
7391 (org-agenda-change-all-lines newhead hdmarker)
7392 (beginning-of-line 1)))))
7394 (defun org-agenda-set-property ()
7395 "Set a property for the current headline."
7397 (org-agenda-check-no-diary)
7398 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7399 (org-agenda-error)))
7400 (buffer (marker-buffer hdmarker))
7401 (pos (marker-position hdmarker))
7402 (inhibit-read-only t)
7404 (org-with-remote-undo buffer
7405 (with-current-buffer buffer
7409 (org-show-context 'agenda))
7411 (and (outline-next-heading)
7412 (org-flag-heading nil))) ; show the next heading
7414 (call-interactively 'org-set-property)))))
7416 (defun org-agenda-set-effort ()
7417 "Set the effort property for the current headline."
7419 (org-agenda-check-no-diary)
7420 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7421 (org-agenda-error)))
7422 (buffer (marker-buffer hdmarker))
7423 (pos (marker-position hdmarker))
7424 (inhibit-read-only t)
7426 (org-with-remote-undo buffer
7427 (with-current-buffer buffer
7431 (org-show-context 'agenda))
7433 (and (outline-next-heading)
7434 (org-flag-heading nil))) ; show the next heading
7436 (call-interactively 'org-set-effort)
7438 (setq newhead (org-get-heading)))
7439 (org-agenda-change-all-lines newhead hdmarker))))
7441 (defun org-agenda-toggle-archive-tag ()
7442 "Toggle the archive tag for the current entry."
7444 (org-agenda-check-no-diary)
7445 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7446 (org-agenda-error)))
7447 (buffer (marker-buffer hdmarker))
7448 (pos (marker-position hdmarker))
7449 (inhibit-read-only t)
7451 (org-with-remote-undo buffer
7452 (with-current-buffer buffer
7455 (org-show-context 'agenda)
7457 (and (outline-next-heading)
7458 (org-flag-heading nil))) ; show the next heading
7459 (call-interactively 'org-toggle-archive-tag)
7461 (setq newhead (org-get-heading)))
7462 (org-agenda-change-all-lines newhead hdmarker)
7463 (beginning-of-line 1))))
7465 (defun org-agenda-do-date-later (arg)
7468 ((or (equal arg '(16))
7470 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7471 (setq this-command 'org-agenda-date-later-minutes)
7472 (org-agenda-date-later-minutes 1))
7473 ((or (equal arg '(4))
7475 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7476 (setq this-command 'org-agenda-date-later-hours)
7477 (org-agenda-date-later-hours 1))
7479 (org-agenda-date-later (prefix-numeric-value arg)))))
7481 (defun org-agenda-do-date-earlier (arg)
7484 ((or (equal arg '(16))
7486 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7487 (setq this-command 'org-agenda-date-earlier-minutes)
7488 (org-agenda-date-earlier-minutes 1))
7489 ((or (equal arg '(4))
7491 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7492 (setq this-command 'org-agenda-date-earlier-hours)
7493 (org-agenda-date-earlier-hours 1))
7495 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7497 (defun org-agenda-date-later (arg &optional what)
7498 "Change the date of this item to ARG day(s) later."
7500 (org-agenda-check-type t 'agenda 'timeline)
7501 (org-agenda-check-no-diary)
7502 (let* ((marker (or (org-get-at-bol 'org-marker)
7503 (org-agenda-error)))
7504 (buffer (marker-buffer marker))
7505 (pos (marker-position marker)))
7506 (org-with-remote-undo buffer
7507 (with-current-buffer buffer
7510 (if (not (org-at-timestamp-p))
7511 (error "Cannot find time stamp"))
7512 (org-timestamp-change arg (or what 'day)))
7513 (org-agenda-show-new-time marker org-last-changed-timestamp))
7514 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7516 (defun org-agenda-date-earlier (arg &optional what)
7517 "Change the date of this item to ARG day(s) earlier."
7519 (org-agenda-date-later (- arg) what))
7521 (defun org-agenda-date-later-minutes (arg)
7522 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7524 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7525 (org-agenda-date-later arg 'minute))
7527 (defun org-agenda-date-earlier-minutes (arg)
7528 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7530 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7531 (org-agenda-date-earlier arg 'minute))
7533 (defun org-agenda-date-later-hours (arg)
7534 "Change the time of this item, in hour steps."
7536 (org-agenda-date-later arg 'hour))
7538 (defun org-agenda-date-earlier-hours (arg)
7539 "Change the time of this item, in hour steps."
7541 (org-agenda-date-earlier arg 'hour))
7543 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7544 "Show new date stamp via text properties."
7545 ;; We use text properties to make this undoable
7546 (let ((inhibit-read-only t)
7547 (buffer-invisibility-spec))
7548 (setq stamp (concat " " prefix " => " stamp))
7550 (goto-char (point-max))
7552 (when (equal marker (org-get-at-bol 'org-marker))
7553 (org-move-to-column (- (window-width) (length stamp)) t)
7554 (org-agenda-fix-tags-filter-overlays-at (point))
7555 (if (featurep 'xemacs)
7556 ;; Use `duplicable' property to trigger undo recording
7557 (let ((ex (make-extent nil nil))
7558 (gl (make-glyph stamp)))
7559 (set-glyph-face gl 'secondary-selection)
7560 (set-extent-properties
7561 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7562 (insert-extent ex (1- (point)) (point-at-eol)))
7563 (add-text-properties
7564 (1- (point)) (point-at-eol)
7565 (list 'display (org-add-props stamp nil
7566 'face 'secondary-selection))))
7567 (beginning-of-line 1))
7568 (beginning-of-line 0)))))
7570 (defun org-agenda-date-prompt (arg)
7571 "Change the date of this item. Date is prompted for, with default today.
7572 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7573 be used to request time specification in the time stamp."
7575 (org-agenda-check-type t 'agenda 'timeline)
7576 (org-agenda-check-no-diary)
7577 (let* ((marker (or (org-get-at-bol 'org-marker)
7578 (org-agenda-error)))
7579 (buffer (marker-buffer marker))
7580 (pos (marker-position marker)))
7581 (org-with-remote-undo buffer
7582 (with-current-buffer buffer
7585 (if (not (org-at-timestamp-p t))
7586 (error "Cannot find time stamp"))
7587 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7588 (org-agenda-show-new-time marker org-last-changed-timestamp))
7589 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7591 (defun org-agenda-schedule (arg &optional time)
7592 "Schedule the item at point.
7593 ARG is passed through to `org-schedule'."
7595 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7596 (org-agenda-check-no-diary)
7597 (let* ((marker (or (org-get-at-bol 'org-marker)
7598 (org-agenda-error)))
7599 (type (marker-insertion-type marker))
7600 (buffer (marker-buffer marker))
7601 (pos (marker-position marker))
7602 (org-insert-labeled-timestamps-at-point nil)
7604 (set-marker-insertion-type marker t)
7605 (org-with-remote-undo buffer
7606 (with-current-buffer buffer
7609 (setq ts (org-schedule arg time)))
7610 (org-agenda-show-new-time marker ts "S"))
7611 (message "Item scheduled for %s" ts)))
7613 (defun org-agenda-deadline (arg &optional time)
7614 "Schedule the item at point.
7615 ARG is passed through to `org-deadline'."
7617 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7618 (org-agenda-check-no-diary)
7619 (let* ((marker (or (org-get-at-bol 'org-marker)
7620 (org-agenda-error)))
7621 (buffer (marker-buffer marker))
7622 (pos (marker-position marker))
7623 (org-insert-labeled-timestamps-at-point nil)
7625 (org-with-remote-undo buffer
7626 (with-current-buffer buffer
7629 (setq ts (org-deadline arg time)))
7630 (org-agenda-show-new-time marker ts "D"))
7631 (message "Deadline for this item set to %s" ts)))
7633 (defun org-agenda-action ()
7634 "Select entry for agenda action, or execute an agenda action.
7635 This command prompts for another letter. Valid inputs are:
7637 m Mark the entry at point for an agenda action
7638 s Schedule the marked entry to the date at the cursor
7639 d Set the deadline of the marked entry to the date at the cursor
7640 r Call `org-remember' with cursor date as the default date
7641 c Call `org-capture' with cursor date as the default date
7642 SPC Show marked entry in other window
7643 TAB Visit marked entry in other window
7645 The cursor may be at a date in the calendar, or in the Org agenda."
7648 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7649 (setq ans (read-char-exclusive))
7653 (if (eq major-mode 'org-agenda-mode)
7654 (let ((m (or (org-get-at-bol 'org-hd-marker)
7655 (org-get-at-bol 'org-marker))))
7658 (move-marker org-agenda-action-marker
7659 (marker-position m) (marker-buffer m))
7660 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7661 (error "Don't know which entry to mark")))
7662 (error "This command works only in the agenda")))
7664 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7666 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7668 (org-agenda-do-action '(org-remember) t))
7670 (org-agenda-do-action '(org-capture) t))
7672 (let ((cw (selected-window)))
7673 (org-switch-to-buffer-other-window
7674 (marker-buffer org-agenda-action-marker))
7675 (goto-char org-agenda-action-marker)
7676 (org-show-context 'agenda)
7677 (select-window cw)))
7679 (org-switch-to-buffer-other-window
7680 (marker-buffer org-agenda-action-marker))
7681 (goto-char org-agenda-action-marker)
7682 (org-show-context 'agenda))
7683 (t (error "Invalid agenda action %c" ans)))))
7685 (defun org-agenda-do-action (form &optional current-buffer)
7686 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7687 (let ((org-overriding-default-time (org-get-cursor-date)))
7690 (if (not (marker-buffer org-agenda-action-marker))
7691 (error "No entry has been selected for agenda action")
7692 (with-current-buffer (marker-buffer org-agenda-action-marker)
7696 (goto-char org-agenda-action-marker)
7699 (defun org-agenda-clock-in (&optional arg)
7700 "Start the clock on the currently selected item."
7702 (org-agenda-check-no-diary)
7703 (if (equal arg '(4))
7705 (let* ((marker (or (org-get-at-bol 'org-marker)
7706 (org-agenda-error)))
7707 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7709 (pos (marker-position marker))
7711 (org-with-remote-undo (marker-buffer marker)
7712 (with-current-buffer (marker-buffer marker)
7715 (org-show-context 'agenda)
7717 (org-cycle-hide-drawers 'children)
7719 (setq newhead (org-get-heading)))
7720 (org-agenda-change-all-lines newhead hdmarker)))))
7722 (defun org-agenda-clock-out ()
7723 "Stop the currently running clock."
7725 (unless (marker-buffer org-clock-marker)
7726 (error "No running clock"))
7727 (let ((marker (make-marker)) newhead)
7728 (org-with-remote-undo (marker-buffer org-clock-marker)
7729 (with-current-buffer (marker-buffer org-clock-marker)
7733 (goto-char org-clock-marker)
7734 (org-back-to-heading t)
7735 (move-marker marker (point))
7737 (setq newhead (org-get-heading))))))
7738 (org-agenda-change-all-lines newhead marker)
7739 (move-marker marker nil)))
7741 (defun org-agenda-clock-cancel (&optional arg)
7742 "Cancel the currently running clock."
7744 (unless (marker-buffer org-clock-marker)
7745 (error "No running clock"))
7746 (org-with-remote-undo (marker-buffer org-clock-marker)
7747 (org-clock-cancel)))
7749 (defun org-agenda-clock-goto ()
7750 "Jump to the currently clocked in task within the agenda.
7751 If the currently clocked in task is not listed in the agenda
7752 buffer, display it in another window."
7756 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7757 (setq pos (overlay-start o))))
7758 (overlays-in (point-min) (point-max)))
7759 (cond (pos (goto-char pos))
7760 ;; If the currently clocked entry is not in the agenda
7761 ;; buffer, we visit it in another window:
7762 (org-clock-current-task
7763 (org-switch-to-buffer-other-window (org-clock-goto)))
7764 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7766 (defun org-agenda-diary-entry-in-org-file ()
7767 "Make a diary entry in the file `org-agenda-diary-file'."
7768 (let (d1 d2 char (text "") dp1 dp2)
7769 (if (equal (buffer-name) "*Calendar*")
7770 (setq d1 (calendar-cursor-to-date t)
7771 d2 (car calendar-mark-ring))
7772 (setq dp1 (get-text-property (point-at-bol) 'day))
7773 (unless dp1 (error "No date defined in current line"))
7774 (setq d1 (calendar-gregorian-from-absolute dp1)
7775 d2 (and (ignore-errors (mark))
7778 (setq dp2 (get-text-property (point-at-bol) 'day)))
7779 (calendar-gregorian-from-absolute dp2))))
7780 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7781 (setq char (read-char-exclusive))
7784 (setq text (read-string "Day entry: "))
7785 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7786 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7788 (setq d1 (list (car d1) (nth 1 d1)
7789 (read-number (format "Reference year [%d]: " (nth 2 d1))
7791 (setq text (read-string "Anniversary (use %d to show years): "))
7792 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7793 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7795 (setq text (read-string "Block entry: "))
7796 (unless (and d1 d2 (not (equal d1 d2)))
7797 (error "No block of days selected"))
7798 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7799 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7801 (org-switch-to-buffer-other-window
7802 (find-file-noselect org-agenda-diary-file))
7803 (require 'org-datetree)
7804 (org-datetree-find-date-create d1)
7806 (t (error "Invalid selection character `%c'" char)))))
7808 (defcustom org-agenda-insert-diary-strategy 'date-tree
7809 "Where in `org-agenda-diary-file' should new entries be added?
7812 date-tree in the date tree, as child of the date
7813 top-level as top-level entries at the end of the file."
7816 (const :tag "in a date tree" date-tree)
7817 (const :tag "as top level at end of file" top-level)))
7819 (defcustom org-agenda-insert-diary-extract-time nil
7820 "Non-nil means extract any time specification from the diary entry."
7824 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7825 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7826 If TEXT is not empty, it will become the headline of the new entry, and
7827 the resulting entry will not be shown. When TEXT is empty, switch to
7828 `org-agenda-diary-file' and let the user finish the entry there."
7829 (let ((cw (current-window-configuration)))
7830 (org-switch-to-buffer-other-window
7831 (find-file-noselect org-agenda-diary-file))
7833 (goto-char (point-min))
7835 ((eq type 'anniversary)
7836 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7838 (or (org-on-heading-p t)
7840 (outline-next-heading)
7841 (insert "* Anniversaries\n\n")
7842 (beginning-of-line -1)))))
7843 (outline-next-heading)
7844 (org-back-over-empty-lines)
7847 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
7848 (nth 2 d1) (car d1) (nth 1 d1) text)))
7850 (let ((org-prefix-has-time t)
7851 (org-agenda-time-leading-zero t)
7853 (if org-agenda-insert-diary-extract-time
7854 ;; Use org-format-agenda-item to parse text for a time-range and
7855 ;; remove it. FIXME: This is a hack, we should refactor
7856 ;; that function to make time extraction available separately
7857 (setq fmt (org-format-agenda-item nil text nil nil t)
7858 time (get-text-property 0 'time fmt)
7859 time2 (if (> (length time) 0)
7860 ;; split-string removes trailing ...... if
7861 ;; no end time given. First space
7862 ;; separates time from date.
7863 (concat " " (car (split-string time "\\.")))
7865 text (get-text-property 0 'txt fmt)))
7866 (if (eq org-agenda-insert-diary-strategy 'top-level)
7867 (org-agenda-insert-diary-as-top-level text)
7868 (require 'org-datetree)
7869 (org-datetree-find-date-create d1)
7870 (org-agenda-insert-diary-make-new-entry text))
7871 (org-insert-time-stamp (org-time-from-absolute
7872 (calendar-absolute-from-gregorian d1))
7873 nil nil nil nil time2))
7876 (if (> (calendar-absolute-from-gregorian d1)
7877 (calendar-absolute-from-gregorian d2))
7878 (setq d1 (prog1 d2 (setq d2 d1))))
7879 (if (eq org-agenda-insert-diary-strategy 'top-level)
7880 (org-agenda-insert-diary-as-top-level text)
7881 (require 'org-datetree)
7882 (org-datetree-find-date-create d1)
7883 (org-agenda-insert-diary-make-new-entry text))
7884 (org-insert-time-stamp (org-time-from-absolute
7885 (calendar-absolute-from-gregorian d1)))
7887 (org-insert-time-stamp (org-time-from-absolute
7888 (calendar-absolute-from-gregorian d2)))
7890 (if (string-match "\\S-" text)
7892 (set-window-configuration cw)
7893 (message "%s entry added to %s"
7894 (capitalize (symbol-name type))
7895 (abbreviate-file-name org-agenda-diary-file)))
7897 (message "Please finish entry here"))))
7899 (defun org-agenda-insert-diary-as-top-level (text)
7900 "Make new entry as a top-level entry at the end of the file.
7901 Add TEXT as headline, and position the cursor in the second line so that
7902 a timestamp can be added there."
7904 (goto-char (point-max))
7905 (or (bolp) (insert "\n"))
7906 (insert "* " text "\n")
7907 (if org-adapt-indentation (org-indent-to-column 2)))
7909 (defun org-agenda-insert-diary-make-new-entry (text)
7910 "Make new entry as last child of current entry.
7911 Add TEXT as headline, and position the cursor in the second line so that
7912 a timestamp can be added there."
7913 (let ((org-show-following-heading t)
7914 (org-show-siblings t)
7915 (org-show-hierarchy-above t)
7916 (org-show-entry-below t)
7918 (outline-next-heading)
7919 (org-back-over-empty-lines)
7920 (or (looking-at "[ \t]*$")
7921 (progn (insert "\n") (backward-char 1)))
7922 (org-insert-heading nil t)
7924 (setq col (current-column))
7926 (if org-adapt-indentation (org-indent-to-column col))
7927 (let ((org-show-following-heading t)
7928 (org-show-siblings t)
7929 (org-show-hierarchy-above t)
7930 (org-show-entry-below t))
7931 (org-show-context))))
7933 (defun org-agenda-diary-entry ()
7934 "Make a diary entry, like the `i' command from the calendar.
7935 All the standard commands work: block, weekly etc.
7936 When `org-agenda-diary-file' points to a file,
7937 `org-agenda-diary-entry-in-org-file' is called instead to create
7938 entries in that Org-mode file."
7940 (org-agenda-check-type t 'agenda 'timeline)
7941 (if (not (eq org-agenda-diary-file 'diary-file))
7942 (org-agenda-diary-entry-in-org-file)
7943 (require 'diary-lib)
7945 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7946 (read-char-exclusive)))
7947 (cmd (cdr (assoc char
7948 '((?d . insert-diary-entry)
7949 (?w . insert-weekly-diary-entry)
7950 (?m . insert-monthly-diary-entry)
7951 (?y . insert-yearly-diary-entry)
7952 (?a . insert-anniversary-diary-entry)
7953 (?b . insert-block-diary-entry)
7954 (?c . insert-cyclic-diary-entry)))))
7955 (oldf (symbol-function 'calendar-cursor-to-date))
7956 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7958 (mark (or (mark t) (point))))
7960 (error "No command associated with <%c>" char))
7961 (unless (and (get-text-property point 'day)
7962 (or (not (equal ?b char))
7963 (get-text-property mark 'day)))
7964 (error "Don't know which date to use for diary entry"))
7965 ;; We implement this by hacking the `calendar-cursor-to-date' function
7966 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7967 (let ((calendar-mark-ring
7968 (list (calendar-gregorian-from-absolute
7969 (or (get-text-property mark 'day)
7970 (get-text-property point 'day))))))
7973 (fset 'calendar-cursor-to-date
7974 (lambda (&optional error dummy)
7975 (calendar-gregorian-from-absolute
7976 (get-text-property point 'day))))
7977 (call-interactively cmd))
7978 (fset 'calendar-cursor-to-date oldf))))))
7980 (defun org-agenda-execute-calendar-command (cmd)
7981 "Execute a calendar command from the agenda, with the date associated to
7982 the cursor position."
7983 (org-agenda-check-type t 'agenda 'timeline)
7984 (require 'diary-lib)
7985 (unless (get-text-property (point) 'day)
7986 (error "Don't know which date to use for calendar command"))
7987 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7989 (date (calendar-gregorian-from-absolute
7990 (get-text-property point 'day)))
7991 ;; the following 2 vars are needed in the calendar
7992 (displayed-month (car date))
7993 (displayed-year (nth 2 date)))
7996 (fset 'calendar-cursor-to-date
7997 (lambda (&optional error dummy)
7998 (calendar-gregorian-from-absolute
7999 (get-text-property point 'day))))
8000 (call-interactively cmd))
8001 (fset 'calendar-cursor-to-date oldf))))
8003 (defun org-agenda-phases-of-moon ()
8004 "Display the phases of the moon for the 3 months around the cursor date."
8006 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8008 (defun org-agenda-holidays ()
8009 "Display the holidays for the 3 months around the cursor date."
8011 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8013 (defvar calendar-longitude)
8014 (defvar calendar-latitude)
8015 (defvar calendar-location-name)
8017 (defun org-agenda-sunrise-sunset (arg)
8018 "Display sunrise and sunset for the cursor date.
8019 Latitude and longitude can be specified with the variables
8020 `calendar-latitude' and `calendar-longitude'. When called with prefix
8021 argument, latitude and longitude will be prompted for."
8024 (let ((calendar-longitude (if arg nil calendar-longitude))
8025 (calendar-latitude (if arg nil calendar-latitude))
8026 (calendar-location-name
8027 (if arg "the given coordinates" calendar-location-name)))
8028 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8030 (defun org-agenda-goto-calendar ()
8031 "Open the Emacs calendar with the date at the cursor."
8033 (org-agenda-check-type t 'agenda 'timeline)
8034 (let* ((day (or (get-text-property (point) 'day)
8035 (error "Don't know which date to open in calendar")))
8036 (date (calendar-gregorian-from-absolute day))
8037 (calendar-move-hook nil)
8038 (calendar-view-holidays-initially-flag nil)
8039 (calendar-view-diary-initially-flag nil))
8041 (calendar-goto-date date)))
8044 (defun org-calendar-goto-agenda ()
8045 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8046 This is a command that has to be installed in `calendar-mode-map'."
8048 (org-agenda-list nil (calendar-absolute-from-gregorian
8049 (calendar-cursor-to-date))
8052 (defun org-agenda-convert-date ()
8054 (org-agenda-check-type t 'agenda 'timeline)
8055 (let ((day (get-text-property (point) 'day))
8058 (error "Don't know which date to convert"))
8059 (setq date (calendar-gregorian-from-absolute day))
8061 "Gregorian: " (calendar-date-string date) "\n"
8062 "ISO: " (calendar-iso-date-string date) "\n"
8063 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8064 "Julian: " (calendar-julian-date-string date) "\n"
8065 "Astron. JD: " (calendar-astro-date-string date)
8066 " (Julian date number at noon UTC)\n"
8067 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8068 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8069 "French: " (calendar-french-date-string date) "\n"
8070 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8071 "Mayan: " (calendar-mayan-date-string date) "\n"
8072 "Coptic: " (calendar-coptic-date-string date) "\n"
8073 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8074 "Persian: " (calendar-persian-date-string date) "\n"
8075 "Chinese: " (calendar-chinese-date-string date) "\n"))
8076 (with-output-to-temp-buffer "*Dates*"
8078 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8082 (defvar org-agenda-bulk-marked-entries nil
8083 "List of markers that refer to marked entries in the agenda.")
8085 (defun org-agenda-bulk-marked-p ()
8086 (eq (get-char-property (point-at-bol) 'type)
8087 'org-marked-entry-overlay))
8089 (defun org-agenda-bulk-mark (&optional arg)
8090 "Mark the entry at point for future bulk action."
8092 (dotimes (i (max arg 1))
8093 (unless (org-get-at-bol 'org-agenda-diary-link)
8094 (let* ((m (org-get-at-bol 'org-hd-marker))
8096 (unless (org-agenda-bulk-marked-p)
8097 (unless m (error "Nothing to mark at point"))
8098 (push m org-agenda-bulk-marked-entries)
8099 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8100 (org-overlay-display ov "> "
8101 (org-get-todo-face "TODO")
8103 (overlay-put ov 'type 'org-marked-entry-overlay))
8104 (beginning-of-line 2)
8105 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8106 (beginning-of-line 2))
8107 (message "%d entries marked for bulk action"
8108 (length org-agenda-bulk-marked-entries))))))
8110 (defun org-agenda-bulk-mark-regexp (regexp)
8111 "Mark entries match REGEXP."
8112 (interactive "sMark entries matching regexp: ")
8113 (let (entries-marked)
8115 (goto-char (point-min))
8116 (goto-char (next-single-property-change (point) 'txt))
8117 (while (re-search-forward regexp nil t)
8118 (when (string-match regexp (get-text-property (point) 'txt))
8119 (setq entries-marked (+ entries-marked 1))
8120 (call-interactively 'org-agenda-bulk-mark))))
8121 (if (not entries-marked)
8122 (message "No entry matching this regexp."))))
8124 (defun org-agenda-bulk-unmark ()
8125 "Unmark the entry at point for future bulk action."
8127 (when (org-agenda-bulk-marked-p)
8128 (org-agenda-bulk-remove-overlays
8129 (point-at-bol) (+ 2 (point-at-bol)))
8130 (setq org-agenda-bulk-marked-entries
8131 (delete (org-get-at-bol 'org-hd-marker)
8132 org-agenda-bulk-marked-entries)))
8133 (beginning-of-line 2)
8134 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8135 (beginning-of-line 2))
8136 (message "%d entries marked for bulk action"
8137 (length org-agenda-bulk-marked-entries)))
8139 (defun org-agenda-bulk-toggle ()
8140 "Toggle marking the entry at point for bulk action."
8142 (if (org-agenda-bulk-marked-p)
8143 (org-agenda-bulk-unmark)
8144 (org-agenda-bulk-mark)))
8146 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8147 "Remove the mark overlays between BEG and END in the agenda buffer.
8148 BEG and END default to the buffer limits.
8150 This only removes the overlays, it does not remove the markers
8151 from the list in `org-agenda-bulk-marked-entries'."
8154 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8155 (delete-overlay ov)))
8156 (overlays-in (or beg (point-min)) (or end (point-max)))))
8158 (defun org-agenda-bulk-remove-all-marks ()
8159 "Remove all marks in the agenda buffer.
8160 This will remove the markers, and the overlays."
8162 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8163 (setq org-agenda-bulk-marked-entries nil)
8164 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8166 (defun org-agenda-bulk-action (&optional arg)
8167 "Execute an remote-editing action on all marked entries.
8168 The prefix arg is passed through to the command if possible."
8170 ;; Make sure we have markers, and only valid ones
8171 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8174 (unless (and (markerp m)
8176 (buffer-live-p (marker-buffer m))
8177 (marker-position m))
8178 (error "Marker %s for bulk command is invalid" m)))
8179 org-agenda-bulk-marked-entries)
8181 ;; Prompt for the bulk command
8182 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8183 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8184 (when org-agenda-bulk-custom-functions
8185 (concat " Custom: ["
8186 (mapconcat (lambda(f) (char-to-string (car f)))
8187 org-agenda-bulk-custom-functions "")
8189 (let* ((action (read-char-exclusive))
8190 (org-log-refile (if org-log-refile 'time nil))
8191 (entries (reverse org-agenda-bulk-marked-entries))
8193 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8196 (setq cmd '(org-agenda-archive)))
8199 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8201 ((member action '(?r ?w))
8202 (setq rfloc (org-refile-get-location
8204 (marker-buffer (car org-agenda-bulk-marked-entries))
8205 org-refile-allow-creating-parent-nodes))
8207 (setcar (nthcdr 3 rfloc)
8208 (move-marker (make-marker) (nth 3 rfloc)
8209 (or (get-file-buffer (nth 1 rfloc))
8210 (find-buffer-visiting (nth 1 rfloc))
8211 (error "This should not happen")))))
8213 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8217 (setq state (org-icompleting-read
8219 (with-current-buffer (marker-buffer (car entries))
8220 (mapcar 'list org-todo-keywords-1))))
8221 (setq cmd `(let ((org-inhibit-blocking t)
8222 (org-inhibit-logging 'note))
8223 (org-agenda-todo ,state))))
8225 ((memq action '(?- ?+))
8226 (setq tag (org-icompleting-read
8227 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8228 (with-current-buffer (marker-buffer (car entries))
8231 (if (stringp (car x)) x)) org-tag-alist)))))
8232 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8234 ((memq action '(?s ?d))
8235 (let* ((date (unless arg
8238 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8239 (ans (if arg nil org-read-date-final-answer))
8240 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8241 (setq cmd `(let* ((bound (fboundp 'read-string))
8242 (old (and bound (symbol-function 'read-string))))
8245 (fset 'read-string (lambda (&rest ignore) ,ans))
8248 (fset 'read-string old)
8249 (fmakunbound 'read-string)))))))
8252 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8253 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8254 (let ((days (read-number
8255 (format "Scatter tasks across how many %sdays: "
8256 (if arg "week" "")) 7)))
8258 `(let ((distance (1+ (random ,days))))
8260 (let ((dist distance)
8262 (calendar-day-of-week
8263 (calendar-gregorian-from-absolute (org-today)))))
8264 (dotimes (i (1+ dist))
8265 (while (member day-of-week org-agenda-weekend-days)
8268 (if (= day-of-week 7)
8269 (setq day-of-week 0)))
8271 (if (= day-of-week 7)
8272 (setq day-of-week 0)))))
8273 ;; silently fail when try to replan a sexp entry
8275 (let* ((date (calendar-gregorian-from-absolute
8276 (+ (org-today) distance)))
8277 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8279 (org-agenda-schedule nil time))
8282 ((assoc action org-agenda-bulk-custom-functions)
8283 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8287 (setq cmd (list (intern
8288 (org-icompleting-read "Function: "
8289 obarray 'fboundp t nil nil)))))
8291 (t (error "Invalid bulk action")))
8293 ;; Sort the markers, to make sure that parents are handled before children
8294 (setq entries (sort entries
8297 ((equal (marker-buffer a) (marker-buffer b))
8298 (< (marker-position a) (marker-position b)))
8300 (string< (buffer-name (marker-buffer a))
8301 (buffer-name (marker-buffer b))))))))
8303 ;; Now loop over all markers and apply cmd
8304 (while (setq e (pop entries))
8305 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8307 (progn (message "Skipping removed entry at %s" e)
8308 (setq cntskip (1+ cntskip)))
8311 (setq org-agenda-bulk-marked-entries
8312 (delete e org-agenda-bulk-marked-entries))
8313 (setq cnt (1+ cnt))))
8314 (setq org-agenda-bulk-marked-entries nil)
8315 (org-agenda-bulk-remove-all-marks)
8316 (when redo-at-end (org-agenda-redo))
8317 (message "Acted on %d entries%s"
8321 (format ", skipped %d (disappeared before their turn)"
8326 (defun org-agenda-show-the-flagging-note ()
8327 "Display the flagging note in the other window.
8328 When called a second time in direct sequence, offer to remove the FLAGGING
8329 tag and (if present) the flagging note."
8331 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8332 (win (selected-window))
8333 note heading newhead)
8335 (error "No linked entry at point"))
8336 (if (and (eq this-command last-command)
8337 (y-or-n-p "Unflag and remove any flagging note? "))
8339 (org-agenda-remove-flag hdmarker)
8340 (let ((win (get-buffer-window "*Flagging Note*")))
8341 (and win (delete-window win)))
8342 (message "Entry unflaged"))
8343 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8345 (error "No flagging note"))
8347 (org-switch-to-buffer-other-window "*Flagging Note*")
8350 (goto-char (point-min))
8351 (while (re-search-forward "\\\\n" nil t)
8352 (replace-match "\n" t t))
8353 (goto-char (point-min))
8355 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8357 (defun org-agenda-remove-flag (marker)
8358 "Remove the FLAGGED tag and any flagging note in the entry."
8360 (org-with-point-at marker
8361 (org-toggle-tag "FLAGGED" 'off)
8362 (org-entry-delete nil "THEFLAGGINGNOTE")
8363 (setq newhead (org-get-heading)))
8364 (org-agenda-change-all-lines newhead marker)
8365 (message "Entry unflaged")))
8367 (defun org-agenda-get-any-marker (&optional pos)
8368 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8369 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8371 ;;; Appointment reminders
8373 (defvar appt-time-msg-list)
8376 (defun org-agenda-to-appt (&optional refresh filter)
8377 "Activate appointments found in `org-agenda-files'.
8378 With a \\[universal-argument] prefix, refresh the list of
8381 If FILTER is t, interactively prompt the user for a regular
8382 expression, and filter out entries that don't match it.
8384 If FILTER is a string, use this string as a regular expression
8385 for filtering entries out.
8387 FILTER can also be an alist with the car of each cell being
8388 either 'headline or 'category. For example:
8390 '((headline \"IMPORTANT\")
8391 (category \"Work\"))
8393 will only add headlines containing IMPORTANT or headlines
8394 belonging to the \"Work\" category."
8396 (if refresh (setq appt-time-msg-list nil))
8398 (setq filter (read-from-minibuffer "Regexp filter: ")))
8399 (let* ((cnt 0) ; count added events
8400 (org-agenda-new-buffers nil)
8401 (org-deadline-warning-days 0)
8402 ;; Do not use `org-today' here because appt only takes
8403 ;; time and without date as argument, so it may pass wrong
8404 ;; information otherwise
8405 (today (org-date-to-gregorian
8406 (time-to-days (current-time))))
8407 (org-agenda-restrict nil)
8408 (files (org-agenda-files 'unrestricted)) entries file)
8409 ;; Get all entries which may contain an appt
8410 (org-prepare-agenda-buffers files)
8411 (while (setq file (pop files))
8414 (org-agenda-get-day-entries
8415 file today :timestamp :scheduled :deadline))))
8416 (setq entries (delq nil entries))
8417 ;; Map thru entries and find if we should filter them out
8420 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8421 (cat (get-text-property 1 'org-category x))
8422 (tod (get-text-property 1 'time-of-day x))
8423 (ok (or (null filter)
8424 (and (stringp filter) (string-match filter evt))
8427 (cadr (assoc 'category filter)) cat)
8429 (cadr (assoc 'headline filter)) evt))))))
8430 ;; FIXME: Shall we remove text-properties for the appt text?
8431 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8433 (setq tod (concat "00" (number-to-string tod))
8434 tod (when (string-match
8435 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8436 (concat (match-string 1 tod) ":"
8437 (match-string 2 tod))))
8439 (setq cnt (1+ cnt))))) entries)
8440 (org-release-buffers org-agenda-new-buffers)
8442 (message "No event to add")
8443 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8445 (defun org-agenda-todayp (date)
8446 "Does DATE mean today, when considering `org-extend-today-until'?"
8447 (let ((today (org-today))
8448 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8452 (defun org-agenda-todo-yesterday (&optional arg)
8453 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
8455 (let* ((hour (third (decode-time
8456 (org-current-time))))
8457 (org-extend-today-until (1+ hour)))
8458 (org-agenda-todo arg)))
8460 (provide 'org-agenda)
8462 ;;; org-agenda.el ends here