1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
52 (declare-function diary-add-to-list
"diary-lib"
53 (date string specifier
&optional marker globcolor literal
))
54 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
55 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
56 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
57 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
58 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
59 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
60 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
61 (declare-function calendar-goto-date
"cal-move" (date))
62 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
63 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
64 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
65 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
66 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
67 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
68 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
69 (declare-function calendar-check-holidays
"holidays" (date))
71 (declare-function org-datetree-find-date-create
"org-datetree"
72 (date &optional keep-restriction
))
73 (declare-function org-columns-quit
"org-colview" ())
74 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
75 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
76 (declare-function org-habit-insert-consistency-graphs
77 "org-habit" (&optional line
))
78 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
79 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
80 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
81 (declare-function org-pop-to-buffer-same-window
"org-compat"
82 (&optional buffer-or-name norecord label
))
84 (defvar calendar-mode-map
)
85 (defvar org-clock-current-task
) ; defined in org-clock.el
86 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
87 (defvar org-habit-show-habits
)
88 (defvar org-habit-show-habits-only-for-today
)
89 (defvar org-habit-show-all-today nil
)
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
)
95 (org-no-warnings (defvar entry
)) ;; unprefixed, from calendar.el
96 (org-no-warnings (defvar date
)) ;; unprefixed, from calendar.el
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 ;; Keep custom values for `org-agenda-filter-preset' compatible with
250 ;; the new variable `org-agenda-tag-filter-preset'.
251 (if (fboundp 'defvaralias
)
252 (defvaralias 'org-agenda-filter-preset
'org-agenda-tag-filter-preset
)
253 (defvaralias 'org-agenda-filter
'org-agenda-tag-filter
))
255 (defconst org-agenda-custom-commands-local-options
256 `(repeat :tag
"Local settings for this command. Remember to quote values"
257 (choice :tag
"Setting"
258 (list :tag
"Heading for this block"
259 (const org-agenda-overriding-header
)
260 (string :tag
"Headline"))
261 (list :tag
"Files to be searched"
262 (const org-agenda-files
)
264 (const :format
"" quote
)
266 (list :tag
"Sorting strategy"
267 (const org-agenda-sorting-strategy
)
269 (const :format
"" quote
)
271 ,org-sorting-choice
)))
272 (list :tag
"Prefix format"
273 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
275 (list :tag
"Number of days in agenda"
276 (const org-agenda-span
)
277 (choice (const :tag
"Day" 'day
)
278 (const :tag
"Week" 'week
)
279 (const :tag
"Month" 'month
)
280 (const :tag
"Year" 'year
)
281 (integer :tag
"Custom")))
282 (list :tag
"Fixed starting date"
283 (const org-agenda-start-day
)
284 (string :value
"2007-11-01"))
285 (list :tag
"Start on day of week"
286 (const org-agenda-start-on-weekday
)
288 (const :tag
"Today" nil
)
289 (integer :tag
"Weekday No.")))
290 (list :tag
"Include data from diary"
291 (const org-agenda-include-diary
)
293 (list :tag
"Deadline Warning days"
294 (const org-deadline-warning-days
)
296 (list :tag
"Category filter preset"
297 (const org-agenda-category-filter-preset
)
299 (const :format
"" quote
)
301 (string :tag
"+category or -category"))))
302 (list :tag
"Tags filter preset"
303 (const org-agenda-tag-filter-preset
)
305 (const :format
"" quote
)
307 (string :tag
"+tag or -tag"))))
308 (list :tag
"Set daily/weekly entry types"
309 (const org-agenda-entry-types
)
311 (const :format
"" quote
)
312 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
317 (list :tag
"Standard skipping condition"
318 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
319 (const org-agenda-skip-function
)
321 (const :format
"" quote
)
324 :tag
"Skipping range"
325 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
326 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
327 (repeat :inline t
:tag
"Conditions for skipping"
329 :tag
"Condition type"
330 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
331 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
332 (list :tag
"TODO state is" :inline t
335 (const :tag
"any not-done state" 'todo
)
336 (const :tag
"any done state" 'done
)
337 (const :tag
"any state" 'any
)
338 (list :tag
"Keyword list"
339 (const :format
"" quote
)
340 (repeat (string :tag
"Keyword")))))
341 (list :tag
"TODO state is not" :inline t
344 (const :tag
"any not-done state" 'todo
)
345 (const :tag
"any done state" 'done
)
346 (const :tag
"any state" 'any
)
347 (list :tag
"Keyword list"
348 (const :format
"" quote
)
349 (repeat (string :tag
"Keyword")))))
350 (const :tag
"scheduled" 'scheduled
)
351 (const :tag
"not scheduled" 'notscheduled
)
352 (const :tag
"deadline" 'deadline
)
353 (const :tag
"no deadline" 'notdeadline
)
354 (const :tag
"timestamp" 'timestamp
)
355 (const :tag
"no timestamp" 'nottimestamp
))))))
356 (list :tag
"Non-standard skipping condition"
357 :value
(org-agenda-skip-function)
358 (const org-agenda-skip-function
)
359 (sexp :tag
"Function or form (quoted!)"))
360 (list :tag
"Any variable"
361 (variable :tag
"Variable")
362 (sexp :tag
"Value (sexp)"))))
363 "Selection of examples for agenda command settings.
364 This will be spliced into the custom type of
365 `org-agenda-custom-commands'.")
368 (defcustom org-agenda-custom-commands
'(("n" "Agenda and all TODO's"
369 ((agenda "") (alltodo))))
370 "Custom commands for the agenda.
371 These commands will be offered on the splash screen displayed by the
372 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
374 (key desc type match settings files)
376 key The key (one or more characters as a string) to be associated
378 desc A description of the command, when omitted or nil, a default
379 description is built using MATCH.
380 type The command type, any of the following symbols:
381 agenda The daily/weekly agenda.
382 todo Entries with a specific TODO keyword, in all agenda files.
383 search Entries containing search words entry or headline.
384 tags Tags/Property/TODO match in all agenda files.
385 tags-todo Tags/P/T match in all agenda files, TODO entries only.
386 todo-tree Sparse tree of specific TODO keyword in *current* file.
387 tags-tree Sparse tree with all tags matches in *current* file.
388 occur-tree Occur sparse tree for *current* file.
389 ... A user-defined function.
390 match What to search for:
391 - a single keyword for TODO keyword searches
392 - a tags match expression for tags searches
393 - a word search expression for text searches.
394 - a regular expression for occur searches
395 For all other commands, this should be the empty string.
396 settings A list of option settings, similar to that in a let form, so like
397 this: ((opt1 val1) (opt2 val2) ...). The values will be
398 evaluated at the moment of execution, so quote them when needed.
399 files A list of files file to write the produced agenda buffer to
400 with the command `org-store-agenda-views'.
401 If a file name ends in \".html\", an HTML version of the buffer
402 is written out. If it ends in \".ps\", a postscript version is
403 produced. Otherwise, only the plain text is written to the file.
405 You can also define a set of commands, to create a composite agenda buffer.
406 In this case, an entry looks like this:
408 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
412 desc A description string to be displayed in the dispatcher menu.
413 cmd An agenda command, similar to the above. However, tree commands
414 are not allowed, but instead you can get agenda and global todo list.
415 So valid commands for a set are:
416 (agenda \"\" settings)
417 (alltodo \"\" settings)
418 (stuck \"\" settings)
419 (todo \"match\" settings files)
420 (search \"match\" settings files)
421 (tags \"match\" settings files)
422 (tags-todo \"match\" settings files)
424 Each command can carry a list of options, and another set of options can be
425 given for the whole set of commands. Individual command options take
426 precedence over the general options.
428 When using several characters as key to a command, the first characters
429 are prefix commands. For the dispatcher to display useful information, you
430 should provide a description for the prefix, like
432 (setq org-agenda-custom-commands
433 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
434 (\"hl\" tags \"+HOME+Lisa\")
435 (\"hp\" tags \"+HOME+Peter\")
436 (\"hk\" tags \"+HOME+Kim\")))"
437 :group
'org-agenda-custom-commands
439 (choice :value
("x" "Describe command here" tags
"" nil
)
440 (list :tag
"Single command"
441 (string :tag
"Access Key(s) ")
442 (option (string :tag
"Description"))
444 (const :tag
"Agenda" agenda
)
445 (const :tag
"TODO list" alltodo
)
446 (const :tag
"Search words" search
)
447 (const :tag
"Stuck projects" stuck
)
448 (const :tag
"Tags/Property match (all agenda files)" tags
)
449 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
450 (const :tag
"TODO keyword search (all agenda files)" todo
)
451 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
452 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
453 (const :tag
"Occur tree (current buffer)" occur-tree
)
454 (sexp :tag
"Other, user-defined function"))
455 (string :tag
"Match (only for some commands)")
456 ,org-agenda-custom-commands-local-options
457 (option (repeat :tag
"Export" (file :tag
"Export to"))))
458 (list :tag
"Command series, all agenda files"
459 (string :tag
"Access Key(s)")
460 (string :tag
"Description ")
461 (repeat :tag
"Component"
464 (const :format
"" agenda
)
465 (const :tag
"" :format
"" "")
466 ,org-agenda-custom-commands-local-options
)
467 (list :tag
"TODO list (all keywords)"
468 (const :format
"" alltodo
)
469 (const :tag
"" :format
"" "")
470 ,org-agenda-custom-commands-local-options
)
471 (list :tag
"Search words"
472 (const :format
"" search
)
473 (string :tag
"Match")
474 ,org-agenda-custom-commands-local-options
)
475 (list :tag
"Stuck projects"
476 (const :format
"" stuck
)
477 (const :tag
"" :format
"" "")
478 ,org-agenda-custom-commands-local-options
)
479 (list :tag
"Tags search"
480 (const :format
"" tags
)
481 (string :tag
"Match")
482 ,org-agenda-custom-commands-local-options
)
483 (list :tag
"Tags search, TODO entries only"
484 (const :format
"" tags-todo
)
485 (string :tag
"Match")
486 ,org-agenda-custom-commands-local-options
)
487 (list :tag
"TODO keyword search"
488 (const :format
"" todo
)
489 (string :tag
"Match")
490 ,org-agenda-custom-commands-local-options
)
491 (list :tag
"Other, user-defined function"
492 (symbol :tag
"function")
493 (string :tag
"Match")
494 ,org-agenda-custom-commands-local-options
)))
496 (repeat :tag
"Settings for entire command set"
497 (list (variable :tag
"Any variable")
498 (sexp :tag
"Value")))
499 (option (repeat :tag
"Export" (file :tag
"Export to"))))
500 (cons :tag
"Prefix key documentation"
501 (string :tag
"Access Key(s)")
502 (string :tag
"Description ")))))
504 (defcustom org-agenda-query-register ?o
505 "The register holding the current query string.
506 The purpose of this is that if you construct a query string interactively,
507 you can then use it to define a custom command."
508 :group
'org-agenda-custom-commands
511 (defcustom org-stuck-projects
512 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
513 "How to identify stuck projects.
514 This is a list of four items:
515 1. A tags/todo/property matcher string that is used to identify a project.
516 See the manual for a description of tag and property searches.
517 The entire tree below a headline matched by this is considered one project.
518 2. A list of TODO keywords identifying non-stuck projects.
519 If the project subtree contains any headline with one of these todo
520 keywords, the project is considered to be not stuck. If you specify
521 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
522 3. A list of tags identifying non-stuck projects.
523 If the project subtree contains any headline with one of these tags,
524 the project is considered to be not stuck. If you specify \"*\" as
525 a tag, any tag will mark the project unstuck. Note that this is about
526 the explicit presence of a tag somewhere in the subtree, inherited
527 tags to not count here. If inherited tags make a project not stuck,
528 use \"-TAG\" in the tags part of the matcher under (1.) above.
529 4. An arbitrary regular expression matching non-stuck projects.
531 If the project turns out to be not stuck, search continues also in the
532 subtree to see if any of the subtasks have project status.
534 See also the variable `org-tags-match-list-sublevels' which applies
535 to projects matched by this search as well.
537 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
538 or `C-c a #' to produce the list."
539 :group
'org-agenda-custom-commands
541 (string :tag
"Tags/TODO match to identify a project")
542 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
543 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
544 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
546 (defcustom org-agenda-filter-effort-default-operator
"<"
547 "The default operator for effort estimate filtering.
548 If you select an effort estimate limit without first pressing an operator,
549 this one will be used."
550 :group
'org-agenda-custom-commands
551 :type
'(choice (const :tag
"less or equal" "<")
552 (const :tag
"greater or equal"">")
553 (const :tag
"equal" "=")))
555 (defgroup org-agenda-skip nil
556 "Options concerning skipping parts of agenda files."
557 :tag
"Org Agenda Skip"
560 (defcustom org-agenda-skip-function-global nil
561 "Function to be called at each match during agenda construction.
562 If this function returns nil, the current match should not be skipped.
563 If the function decided to skip an agenda match, is must return the
564 buffer position from which the search should be continued.
565 This may also be a Lisp form, which will be evaluated.
567 This variable will be applied to every agenda match, including
568 tags/property searches and TODO lists. So try to make the test function
569 do its checking as efficiently as possible. To implement a skipping
570 condition just for specific agenda commands, use the variable
571 `org-agenda-skip-function' which can be set in the options section
572 of custom agenda commands."
573 :group
'org-agenda-skip
576 (defgroup org-agenda-daily
/weekly nil
577 "Options concerning the daily/weekly agenda."
578 :tag
"Org Agenda Daily/Weekly"
580 (defgroup org-agenda-todo-list nil
581 "Options concerning the global todo list agenda view."
582 :tag
"Org Agenda Todo List"
584 (defgroup org-agenda-match-view nil
585 "Options concerning the general tags/property/todo match agenda view."
586 :tag
"Org Agenda Match View"
588 (defgroup org-agenda-search-view nil
589 "Options concerning the general tags/property/todo match agenda view."
590 :tag
"Org Agenda Match View"
593 (defvar org-agenda-archives-mode nil
594 "Non-nil means the agenda will include archived items.
595 If this is the symbol `trees', trees in the selected agenda scope
596 that are marked with the ARCHIVE tag will be included anyway. When this is
597 t, also all archive files associated with the current selection of agenda
598 files will be included.")
600 (defcustom org-agenda-skip-comment-trees t
601 "Non-nil means skip trees that start with the COMMENT keyword.
602 When nil, these trees are also scanned by agenda commands."
603 :group
'org-agenda-skip
606 (defcustom org-agenda-todo-list-sublevels t
607 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
608 When nil, the sublevels of a TODO entry are not checked, resulting in
609 potentially much shorter TODO lists."
610 :group
'org-agenda-skip
611 :group
'org-agenda-todo-list
614 (defcustom org-agenda-todo-ignore-with-date nil
615 "Non-nil means don't show entries with a date in the global todo list.
616 You can use this if you prefer to mark mere appointments with a TODO keyword,
617 but don't want them to show up in the TODO list.
618 When this is set, it also covers deadlines and scheduled items, the settings
619 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
621 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
622 :group
'org-agenda-skip
623 :group
'org-agenda-todo-list
626 (defcustom org-agenda-todo-ignore-timestamp nil
627 "Non-nil means don't show entries with a timestamp.
628 This applies when creating the global todo list.
631 past Don't show entries for today or in the past.
633 future Don't show entries with a timestamp in the future.
634 The idea behind this is that if it has a future
635 timestamp, you don't want to think about it until the
638 all Don't show any entries with a timestamp in the global todo list.
639 The idea behind this is that by setting a timestamp, you
640 have already \"taken care\" of this item.
642 This variable can also have an integer as a value. If positive (N),
643 todos with a timestamp N or more days in the future will be ignored. If
644 negative (-N), todos with a timestamp N or more days in the past will be
645 ignored. If 0, todos with a timestamp either today or in the future will
646 be ignored. For example, a value of -1 will exclude todos with a
647 timestamp in the past (yesterday or earlier), while a value of 7 will
648 exclude todos with a timestamp a week or more in the future.
650 See also `org-agenda-todo-ignore-with-date'.
651 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
652 to make his option also apply to the tags-todo list."
653 :group
'org-agenda-skip
654 :group
'org-agenda-todo-list
657 (const :tag
"Ignore future timestamp todos" future
)
658 (const :tag
"Ignore past or present timestamp todos" past
)
659 (const :tag
"Ignore all timestamp todos" all
)
660 (const :tag
"Show timestamp todos" nil
)
661 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
663 (defcustom org-agenda-todo-ignore-scheduled nil
664 "Non-nil means, ignore some scheduled TODO items when making TODO list.
665 This applies when creating the global todo list.
668 past Don't show entries scheduled today or in the past.
670 future Don't show entries scheduled in the future.
671 The idea behind this is that by scheduling it, you don't want to
672 think about it until the scheduled date.
674 all Don't show any scheduled entries in the global todo list.
675 The idea behind this is that by scheduling it, you have already
676 \"taken care\" of this item.
678 t Same as `all', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group
'org-agenda-skip
687 :group
'org-agenda-todo-list
689 (const :tag
"Ignore future-scheduled todos" future
)
690 (const :tag
"Ignore past- or present-scheduled todos" past
)
691 (const :tag
"Ignore all scheduled todos" all
)
692 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
693 (const :tag
"Show scheduled todos" nil
)
694 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-todo-ignore-deadlines nil
697 "Non-nil means ignore some deadlined TODO items when making TODO list.
698 There are different motivations for using different values, please think
699 carefully when configuring this variable.
701 This applies when creating the global todo list.
704 near Don't show near deadline entries. A deadline is near when it is
705 closer than `org-deadline-warning-days' days. The idea behind this
706 is that such items will appear in the agenda anyway.
708 far Don't show TODO entries where a deadline has been defined, but
709 the deadline is not near. This is useful if you don't want to
710 use the todo list to figure out what to do now.
712 past Don't show entries with a deadline timestamp for today or in the past.
714 future Don't show entries with a deadline timestamp in the future, not even
715 when they become `near' ones. Use it with caution.
717 all Ignore all TODO entries that do have a deadline.
719 t Same as `near', for backward compatibility.
721 This variable can also have an integer as a value. See
722 `org-agenda-todo-ignore-timestamp' for more details.
724 See also `org-agenda-todo-ignore-with-date'.
725 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
726 to make his option also apply to the tags-todo list."
727 :group
'org-agenda-skip
728 :group
'org-agenda-todo-list
730 (const :tag
"Ignore near deadlines" near
)
731 (const :tag
"Ignore near deadlines (compatibility)" t
)
732 (const :tag
"Ignore far deadlines" far
)
733 (const :tag
"Ignore all TODOs with a deadlines" all
)
734 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
735 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
737 (defcustom org-agenda-tags-todo-honor-ignore-options nil
738 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
740 `org-agenda-todo-ignore-with-date',
741 `org-agenda-todo-ignore-timestamp',
742 `org-agenda-todo-ignore-scheduled',
743 `org-agenda-todo-ignore-deadlines'
744 make the global TODO list skip entries that have time stamps of certain
745 kinds. If this option is set, the same options will also apply for the
746 tags-todo search, which is the general tags/property matcher
747 restricted to unfinished TODO entries only."
748 :group
'org-agenda-skip
749 :group
'org-agenda-todo-list
750 :group
'org-agenda-match-view
753 (defcustom org-agenda-skip-scheduled-if-done nil
754 "Non-nil means don't show scheduled items in agenda when they are done.
755 This is relevant for the daily/weekly agenda, not for the TODO list. And
756 it applies only to the actual date of the scheduling. Warnings about
757 an item with a past scheduling dates are always turned off when the item
759 :group
'org-agenda-skip
760 :group
'org-agenda-daily
/weekly
763 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
764 "Non-nil means skip scheduling line if same entry shows because of deadline.
765 In the agenda of today, an entry can show up multiple times because
766 it is both scheduled and has a nearby deadline, and maybe a plain time
768 When this variable is t, then only the deadline is shown and the fact that
769 the entry is scheduled today or was scheduled previously is not shown.
770 When this variable is nil, the entry will be shown several times. When
771 the variable is the symbol `not-today', then skip scheduled previously,
772 but not scheduled today."
773 :group
'org-agenda-skip
774 :group
'org-agenda-daily
/weekly
776 (const :tag
"Never" nil
)
777 (const :tag
"Always" t
)
778 (const :tag
"Not when scheduled today" not-today
)))
780 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
781 "Non-nil means skip timestamp line if same entry shows because of deadline.
782 In the agenda of today, an entry can show up multiple times
783 because it has both a plain timestamp and has a nearby deadline.
784 When this variable is t, then only the deadline is shown and the
785 fact that the entry has a timestamp for or including today is not
786 shown. When this variable is nil, the entry will be shown
788 :group
'org-agenda-skip
789 :group
'org-agenda-daily
/weekly
792 (const :tag
"Never" nil
)
793 (const :tag
"Always" t
)))
795 (defcustom org-agenda-skip-deadline-if-done nil
796 "Non-nil means don't show deadlines when the corresponding item is done.
797 When nil, the deadline is still shown and should give you a happy feeling.
798 This is relevant for the daily/weekly agenda. And it applied only to the
799 actually date of the deadline. Warnings about approaching and past-due
800 deadlines are always turned off when the item is DONE."
801 :group
'org-agenda-skip
802 :group
'org-agenda-daily
/weekly
805 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
806 "Non-nil means skip deadline prewarning when entry is also scheduled.
807 This will apply on all days where a prewarning for the deadline would
808 be shown, but not at the day when the entry is actually due. On that day,
809 the deadline will be shown anyway.
810 This variable may be set to nil, t, or a number which will then give
811 the number of days before the actual deadline when the prewarnings
813 This can be used in a workflow where the first showing of the deadline will
814 trigger you to schedule it, and then you don't want to be reminded of it
815 because you will take care of it on the day when scheduled."
816 :group
'org-agenda-skip
817 :group
'org-agenda-daily
/weekly
820 (const :tag
"Alwas show prewarning" nil
)
821 (const :tag
"Remove prewarning if entry is scheduled" t
)
822 (integer :tag
"Restart prewarning N days before deadline")))
824 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
825 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
826 When non-nil, after the search for timestamps has matched once in an
827 entry, the rest of the entry will not be searched."
828 :group
'org-agenda-skip
831 (defcustom org-agenda-skip-timestamp-if-done nil
832 "Non-nil means don't select item by timestamp or -range if it is DONE."
833 :group
'org-agenda-skip
834 :group
'org-agenda-daily
/weekly
837 (defcustom org-agenda-dim-blocked-tasks t
838 "Non-nil means dim blocked tasks in the agenda display.
839 This causes some overhead during agenda construction, but if you
840 have turned on `org-enforce-todo-dependencies',
841 `org-enforce-todo-checkbox-dependencies', or any other blocking
842 mechanism, this will create useful feedback in the agenda.
844 Instead of t, this variable can also have the value `invisible'.
845 Then blocked tasks will be invisible and only become visible when
846 they become unblocked. An exemption to this behavior is when a task is
847 blocked because of unchecked checkboxes below it. Since checkboxes do
848 not show up in the agenda views, making this task invisible you remove any
849 trace from agenda views that there is something to do. Therefore, a task
850 that is blocked because of checkboxes will never be made invisible, it
851 will only be dimmed."
852 :group
'org-agenda-daily
/weekly
853 :group
'org-agenda-todo-list
855 (const :tag
"Do not dim" nil
)
856 (const :tag
"Dim to a gray face" t
)
857 (const :tag
"Make invisible" invisible
)))
859 (defcustom org-timeline-show-empty-dates
3
860 "Non-nil means `org-timeline' also shows dates without an entry.
861 When nil, only the days which actually have entries are shown.
862 When t, all days between the first and the last date are shown.
863 When an integer, show also empty dates, but if there is a gap of more than
864 N days, just insert a special line indicating the size of the gap."
865 :group
'org-agenda-skip
867 (const :tag
"None" nil
)
869 (integer :tag
"at most")))
871 (defgroup org-agenda-startup nil
872 "Options concerning initial settings in the Agenda in Org Mode."
873 :tag
"Org Agenda Startup"
876 (defcustom org-agenda-menu-show-matcher t
877 "Non-nil means show the match string in the agenda dispatcher menu.
878 When nil, the matcher string is not shown, but is put into the help-echo
879 property so than moving the mouse over the command shows it.
880 Setting it to nil is good if matcher strings are very long and/or if
881 you want to use two-column display (see `org-agenda-menu-two-column')."
886 (defcustom org-agenda-menu-two-column nil
887 "Non-nil means, use two columns to show custom commands in the dispatcher.
888 If you use this, you probably want to set `org-agenda-menu-show-matcher'
894 (defcustom org-finalize-agenda-hook nil
895 "Hook run just before displaying an agenda buffer."
896 :group
'org-agenda-startup
899 (defcustom org-agenda-mouse-1-follows-link nil
900 "Non-nil means mouse-1 on a link will follow the link in the agenda.
901 A longer mouse click will still set point. Does not work on XEmacs.
902 Needs to be set before org.el is loaded."
903 :group
'org-agenda-startup
906 (defcustom org-agenda-start-with-follow-mode nil
907 "The initial value of follow mode in a newly created agenda window."
908 :group
'org-agenda-startup
911 (defcustom org-agenda-follow-indirect nil
912 "Non-nil means `org-agenda-follow-mode' displays only the
913 current item's tree, in an indirect buffer."
918 (defcustom org-agenda-show-outline-path t
919 "Non-nil means show outline path in echo area after line motion."
920 :group
'org-agenda-startup
923 (defcustom org-agenda-start-with-entry-text-mode nil
924 "The initial value of entry-text-mode in a newly created agenda window."
925 :group
'org-agenda-startup
928 (defcustom org-agenda-entry-text-maxlines
5
929 "Number of text lines to be added when `E' is pressed in the agenda.
931 Note that this variable only used during agenda display. Add add entry text
932 when exporting the agenda, configure the variable
933 `org-agenda-add-entry-ext-maxlines'."
937 (defcustom org-agenda-entry-text-exclude-regexps nil
938 "List of regular expressions to clean up entry text.
939 The complete matches of all regular expressions in this list will be
940 removed from entry text before it is shown in the agenda."
942 :type
'(repeat (regexp)))
944 (defvar org-agenda-entry-text-cleanup-hook nil
945 "Hook that is run after basic cleanup of entry text to be shown in agenda.
946 This cleanup is done in a temporary buffer, so the function may inspect and
947 change the entire buffer.
948 Some default stuff like drawers and scheduling/deadline dates will already
949 have been removed when this is called, as will any matches for regular
950 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
952 (defvar org-agenda-include-inactive-timestamps nil
953 "Non-nil means include inactive time stamps in agenda and timeline.
954 Dynamically scoped.")
956 (defgroup org-agenda-windows nil
957 "Options concerning the windows used by the Agenda in Org Mode."
958 :tag
"Org Agenda Windows"
961 (defcustom org-agenda-window-setup
'reorganize-frame
962 "How the agenda buffer should be displayed.
963 Possible values for this option are:
965 current-window Show agenda in the current window, keeping all other windows.
966 other-window Use `switch-to-buffer-other-window' to display agenda.
967 reorganize-frame Show only two windows on the current frame, the current
968 window and the agenda.
969 other-frame Use `switch-to-buffer-other-frame' to display agenda.
970 Also, when exiting the agenda, kill that frame.
971 See also the variable `org-agenda-restore-windows-after-quit'."
972 :group
'org-agenda-windows
974 (const current-window
)
977 (const reorganize-frame
)))
979 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
980 "The min and max height of the agenda window as a fraction of frame height.
981 The value of the variable is a cons cell with two numbers between 0 and 1.
982 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
983 :group
'org-agenda-windows
984 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
986 (defcustom org-agenda-restore-windows-after-quit nil
987 "Non-nil means restore window configuration upon exiting agenda.
988 Before the window configuration is changed for displaying the agenda,
989 the current status is recorded. When the agenda is exited with
990 `q' or `x' and this option is set, the old state is restored. If
991 `org-agenda-window-setup' is `other-frame', the value of this
992 option will be ignored."
993 :group
'org-agenda-windows
996 (defcustom org-agenda-ndays nil
997 "Number of days to include in overview display.
999 Obsolete, see `org-agenda-span'."
1000 :group
'org-agenda-daily
/weekly
1003 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
1005 (defcustom org-agenda-span
'week
1006 "Number of days to include in overview display.
1007 Can be day, week, month, year, or any number of days.
1008 Custom commands can set this variable in the options section."
1009 :group
'org-agenda-daily
/weekly
1010 :type
'(choice (const :tag
"Day" day
)
1011 (const :tag
"Week" week
)
1012 (const :tag
"Month" month
)
1013 (const :tag
"Year" year
)
1014 (integer :tag
"Custom")))
1016 (defcustom org-agenda-start-on-weekday
1
1017 "Non-nil means start the overview always on the specified weekday.
1018 0 denotes Sunday, 1 denotes Monday etc.
1019 When nil, always start on the current day.
1020 Custom commands can set this variable in the options section."
1021 :group
'org-agenda-daily
/weekly
1022 :type
'(choice (const :tag
"Today" nil
)
1023 (integer :tag
"Weekday No.")))
1025 (defcustom org-agenda-show-all-dates t
1026 "Non-nil means `org-agenda' shows every day in the selected range.
1027 When nil, only the days which actually have entries are shown."
1028 :group
'org-agenda-daily
/weekly
1031 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1032 "Format string for displaying dates in the agenda.
1033 Used by the daily/weekly agenda and by the timeline. This should be
1034 a format string understood by `format-time-string', or a function returning
1035 the formatted date as a string. The function must take a single argument,
1036 a calendar-style date list like (month day year)."
1037 :group
'org-agenda-daily
/weekly
1039 (string :tag
"Format string")
1040 (function :tag
"Function")))
1042 (defun org-agenda-format-date-aligned (date)
1043 "Format a date string for display in the daily/weekly agenda, or timeline.
1044 This function makes sure that dates are aligned for easy reading."
1046 (let* ((dayname (calendar-day-name date
))
1048 (day-of-week (calendar-day-of-week date
))
1050 (monthname (calendar-month-name month
))
1052 (iso-week (org-days-to-iso-week
1053 (calendar-absolute-from-gregorian date
)))
1054 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1056 ((and (= month
12) (<= iso-week
1))
1059 (weekstring (if (= day-of-week
1)
1060 (format " W%02d" iso-week
)
1062 (format "%-10s %2d %s %4d%s"
1063 dayname day monthname year weekstring
)))
1065 (defcustom org-agenda-time-leading-zero nil
1066 "Non-nil means use leading zero for military times in agenda.
1067 For example, 9:30am would become 09:30 rather than 9:30."
1068 :group
'org-agenda-daily
/weekly
1072 (defcustom org-agenda-timegrid-use-ampm nil
1073 "When set, show AM/PM style timestamps on the timegrid."
1078 (defun org-agenda-time-of-day-to-ampm (time)
1079 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1080 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1081 (minute (substring time -
2))
1084 ((equal hour-number
12)
1088 (setq hour-number
(- hour-number
12))))
1090 (if org-agenda-time-leading-zero
1091 (format "%02d" hour-number
)
1092 (format "%02s" (number-to-string hour-number
)))
1095 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1096 "Conditionally convert TIME to AM/PM format
1097 based on `org-agenda-timegrid-use-ampm'"
1098 (if org-agenda-timegrid-use-ampm
1099 (org-agenda-time-of-day-to-ampm time
)
1102 (defcustom org-agenda-weekend-days
'(6 0)
1103 "Which days are weekend?
1104 These days get the special face `org-agenda-date-weekend' in the agenda
1105 and timeline buffers."
1106 :group
'org-agenda-daily
/weekly
1107 :type
'(set :greedy t
1108 (const :tag
"Monday" 1)
1109 (const :tag
"Tuesday" 2)
1110 (const :tag
"Wednesday" 3)
1111 (const :tag
"Thursday" 4)
1112 (const :tag
"Friday" 5)
1113 (const :tag
"Saturday" 6)
1114 (const :tag
"Sunday" 0)))
1116 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1117 "Non-nil means jump to today when moving a past date forward in time.
1118 When using S-right in the agenda to move a a date forward, and the date
1119 stamp currently points to the past, the first key press will move it
1120 to today. WHen nil, just move one day forward even if the date stays
1122 :group
'org-agenda-daily
/weekly
1126 (defcustom org-agenda-include-diary nil
1127 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1128 Custom commands can set this variable in the options section."
1129 :group
'org-agenda-daily
/weekly
1132 (defcustom org-agenda-include-deadlines t
1133 "If non-nil, include entries within their deadline warning period.
1134 Custom commands can set this variable in the options section."
1135 :group
'org-agenda-daily
/weekly
1139 (defcustom org-agenda-repeating-timestamp-show-all t
1140 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1141 When set to a list of strings, only show occurrences of repeating
1142 stamps for these TODO keywords. When nil, only one occurrence is
1143 shown, either today or the nearest into the future."
1144 :group
'org-agenda-daily
/weekly
1146 (const :tag
"Show repeating stamps" t
)
1147 (repeat :tag
"Show repeating stamps for these TODO keywords"
1148 (string :tag
"TODO Keyword"))
1149 (const :tag
"Don't show repeating stamps" nil
)))
1151 (defcustom org-scheduled-past-days
10000
1152 "No. of days to continue listing scheduled items that are not marked DONE.
1153 When an item is scheduled on a date, it shows up in the agenda on this
1154 day and will be listed until it is marked done for the number of days
1156 :group
'org-agenda-daily
/weekly
1159 (defcustom org-agenda-log-mode-items
'(closed clock
)
1160 "List of items that should be shown in agenda log mode.
1161 This list may contain the following symbols:
1163 closed Show entries that have been closed on that day.
1164 clock Show entries that have received clocked time on that day.
1165 state Show all logged state changes.
1166 Note that instead of changing this variable, you can also press `C-u l' in
1167 the agenda to display all available LOG items temporarily."
1168 :group
'org-agenda-daily
/weekly
1169 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1171 (defcustom org-agenda-clock-consistency-checks
1172 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1173 :gap-ok-around
("4:00")
1174 :default-face
((:background
"DarkRed") (:foreground
"white"))
1175 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1176 :long-face nil
:short-face nil
)
1177 "This is a property list, with the following keys:
1179 :max-duration Mark clocking chunks that are longer than this time.
1180 This is a time string like \"HH:MM\", or the number
1181 of minutes as an integer.
1183 :min-duration Mark clocking chunks that are shorter that this.
1184 This is a time string like \"HH:MM\", or the number
1185 of minutes as an integer.
1187 :max-gap Mark gaps between clocking chunks that are longer than
1188 this duration. A number of minutes, or a string
1191 :gap-ok-around List of times during the day which are usually not working
1192 times. When a gap is detected, but the gap contains any
1193 of these times, the gap is *not* reported. For example,
1194 if this is (\"4:00\" \"13:00\") then gaps that contain
1195 4:00 in the morning (i.e. the night) and 13:00
1196 (i.e. a typical lunch time) do not cause a warning.
1197 You should have at least one time during the night in this
1198 list, or otherwise the first task each morning will trigger
1199 a warning because it follows a long gap.
1201 Furthermore, the following properties can be used to define faces for
1204 :default-face the default face, if the specific face is undefined
1205 :overlap-face face for overlapping clocks
1206 :gap-face face for gaps between clocks
1207 :no-end-time-face face for incomplete clocks
1208 :long-face face for clock intervals that are too long
1209 :short-face face for clock intervals that are too short"
1210 :group
'org-agenda-daily
/weekly
1215 (defcustom org-agenda-log-mode-add-notes t
1216 "Non-nil means add first line of notes to log entries in agenda views.
1217 If a log item like a state change or a clock entry is associated with
1218 notes, the first line of these notes will be added to the entry in the
1220 :group
'org-agenda-daily
/weekly
1223 (defcustom org-agenda-start-with-log-mode nil
1224 "The initial value of log-mode in a newly created agenda window.
1225 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1226 explanations on the possible values."
1227 :group
'org-agenda-startup
1228 :group
'org-agenda-daily
/weekly
1229 :type
'(choice (const :tag
"Don't show log items" nil
)
1230 (const :tag
"Show only log items" 'only
)
1231 (const :tag
"Show all possible log items" 'clockcheck
)
1232 (repeat :tag
"Choose among possible values for `org-agenda-log-mode-items'"
1233 (choice (const :tag
"Show closed log items" 'closed
)
1234 (const :tag
"Show clocked log items" 'clock
)
1235 (const :tag
"Show all logged state changes" 'state
)))))
1237 (defcustom org-agenda-start-with-clockreport-mode nil
1238 "The initial value of clockreport-mode in a newly created agenda window."
1239 :group
'org-agenda-startup
1240 :group
'org-agenda-daily
/weekly
1243 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1244 "Property list with parameters for the clocktable in clockreport mode.
1245 This is the display mode that shows a clock table in the daily/weekly
1246 agenda, the properties for this dynamic block can be set here.
1247 The usual clocktable parameters are allowed here, but you cannot set
1248 the properties :name, :tstart, :tend, :block, and :scope - these will
1249 be overwritten to make sure the content accurately reflects the
1250 current display in the agenda."
1251 :group
'org-agenda-daily
/weekly
1254 (defcustom org-agenda-search-view-always-boolean nil
1255 "Non-nil means the search string is interpreted as individual parts.
1257 The search string for search view can either be interpreted as a phrase,
1258 or as a list of snippets that define a boolean search for a number of
1261 When this is non-nil, the string will be split on whitespace, and each
1262 snippet will be searched individually, and all must match in order to
1263 select an entry. A snippet is then a single string of non-white
1264 characters, or a string in double quotes, or a regexp in {} braces.
1265 If a snippet is preceded by \"-\", the snippet must *not* match.
1266 \"+\" is syntactic sugar for positive selection. Each snippet may
1267 be found as a full word or a partial word, but see the variable
1268 `org-agenda-search-view-force-full-words'.
1270 When this is nil, search will look for the entire search phrase as one,
1271 with each space character matching any amount of whitespace, including
1274 Even when this is nil, you can still switch to Boolean search dynamically
1275 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1276 is a regexp marked with braces like \"{abc}\", this will also switch to
1278 :group
'org-agenda-search-view
1282 (if (fboundp 'defvaralias
)
1283 (defvaralias 'org-agenda-search-view-search-words-only
1284 'org-agenda-search-view-always-boolean
))
1286 (defcustom org-agenda-search-view-force-full-words nil
1287 "Non-nil means, search words must be matches as complete words.
1288 When nil, they may also match part of a word."
1289 :group
'org-agenda-search-view
1293 (defgroup org-agenda-time-grid nil
1294 "Options concerning the time grid in the Org-mode Agenda."
1295 :tag
"Org Agenda Time Grid"
1298 (defcustom org-agenda-search-headline-for-time t
1299 "Non-nil means search headline for a time-of-day.
1300 If the headline contains a time-of-day in one format or another, it will
1301 be used to sort the entry into the time sequence of items for a day.
1302 Some people have time stamps in the headline that refer to the creation
1303 time or so, and then this produces an unwanted side effect. If this is
1304 the case for your, use this variable to turn off searching the headline
1306 :group
'org-agenda-time-grid
1309 (defcustom org-agenda-use-time-grid t
1310 "Non-nil means show a time grid in the agenda schedule.
1311 A time grid is a set of lines for specific times (like every two hours between
1312 8:00 and 20:00). The items scheduled for a day at specific times are
1313 sorted in between these lines.
1314 For details about when the grid will be shown, and what it will look like, see
1315 the variable `org-agenda-time-grid'."
1316 :group
'org-agenda-time-grid
1319 (defcustom org-agenda-time-grid
1320 '((daily today require-timed
)
1322 (800 1000 1200 1400 1600 1800 2000))
1324 "The settings for time grid for agenda display.
1325 This is a list of three items. The first item is again a list. It contains
1326 symbols specifying conditions when the grid should be displayed:
1328 daily if the agenda shows a single day
1329 weekly if the agenda shows an entire week
1330 today show grid on current date, independent of daily/weekly display
1331 require-timed show grid only if at least one item has a time specification
1333 The second item is a string which will be placed behind the grid time.
1335 The third item is a list of integers, indicating the times that should have
1337 :group
'org-agenda-time-grid
1340 (set :greedy t
:tag
"Grid Display Options"
1341 (const :tag
"Show grid in single day agenda display" daily
)
1342 (const :tag
"Show grid in weekly agenda display" weekly
)
1343 (const :tag
"Always show grid for today" today
)
1344 (const :tag
"Show grid only if any timed entries are present"
1346 (const :tag
"Skip grid times already present in an entry"
1348 (string :tag
"Grid String")
1349 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1351 (defcustom org-agenda-show-current-time-in-grid t
1352 "Non-nil means show the current time in the time grid."
1353 :group
'org-agenda-time-grid
1357 (defcustom org-agenda-current-time-string
1358 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1359 "The string for the current time marker in the agenda."
1360 :group
'org-agenda-time-grid
1364 (defgroup org-agenda-sorting nil
1365 "Options concerning sorting in the Org-mode Agenda."
1366 :tag
"Org Agenda Sorting"
1369 (defcustom org-agenda-sorting-strategy
1370 '((agenda habit-down time-up priority-down category-keep
)
1371 (todo priority-down category-keep
)
1372 (tags priority-down category-keep
)
1373 (search category-keep
))
1374 "Sorting structure for the agenda items of a single day.
1375 This is a list of symbols which will be used in sequence to determine
1376 if an entry should be listed before another entry. The following
1377 symbols are recognized:
1379 time-up Put entries with time-of-day indications first, early first
1380 time-down Put entries with time-of-day indications first, late first
1381 category-keep Keep the default order of categories, corresponding to the
1382 sequence in `org-agenda-files'.
1383 category-up Sort alphabetically by category, A-Z.
1384 category-down Sort alphabetically by category, Z-A.
1385 tag-up Sort alphabetically by last tag, A-Z.
1386 tag-down Sort alphabetically by last tag, Z-A.
1387 priority-up Sort numerically by priority, high priority last.
1388 priority-down Sort numerically by priority, high priority first.
1389 todo-state-up Sort by todo state, tasks that are done last.
1390 todo-state-down Sort by todo state, tasks that are done first.
1391 effort-up Sort numerically by estimated effort, high effort last.
1392 effort-down Sort numerically by estimated effort, high effort first.
1393 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1394 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1395 habit-up Put entries that are habits first
1396 habit-down Put entries that are habits last
1397 alpha-up Sort headlines alphabetically
1398 alpha-down Sort headlines alphabetically, reversed
1400 The different possibilities will be tried in sequence, and testing stops
1401 if one comparison returns a \"not-equal\". For example, the default
1402 '(time-up category-keep priority-down)
1403 means: Pull out all entries having a specified time of day and sort them,
1404 in order to make a time schedule for the current day the first thing in the
1405 agenda listing for the day. Of the entries without a time indication, keep
1406 the grouped in categories, don't sort the categories, but keep them in
1407 the sequence given in `org-agenda-files'. Within each category sort by
1410 Leaving out `category-keep' would mean that items will be sorted across
1411 categories by priority.
1413 Instead of a single list, this can also be a set of list for specific
1414 contents, with a context symbol in the car of the list, any of
1415 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1417 Custom commands can bind this variable in the options section."
1418 :group
'org-agenda-sorting
1420 (repeat :tag
"General" ,org-sorting-choice
)
1421 (list :tag
"Individually"
1422 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1423 (repeat ,org-sorting-choice
))
1424 (cons (const :tag
"Strategy for TODO lists" todo
)
1425 (repeat ,org-sorting-choice
))
1426 (cons (const :tag
"Strategy for Tags matches" tags
)
1427 (repeat ,org-sorting-choice
))
1428 (cons (const :tag
"Strategy for search matches" search
)
1429 (repeat ,org-sorting-choice
)))))
1431 (defcustom org-agenda-cmp-user-defined nil
1432 "A function to define the comparison `user-defined'.
1433 This function must receive two arguments, agenda entry a and b.
1434 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1435 the user comparison, return nil.
1436 When this is defined, you can make `user-defined-up' and `user-defined-down'
1437 part of an agenda sorting strategy."
1438 :group
'org-agenda-sorting
1441 (defcustom org-sort-agenda-notime-is-late t
1442 "Non-nil means items without time are considered late.
1443 This is only relevant for sorting. When t, items which have no explicit
1444 time like 15:30 will be considered as 99:01, i.e. later than any items which
1445 do have a time. When nil, the default time is before 0:00. You can use this
1446 option to decide if the schedule for today should come before or after timeless
1448 :group
'org-agenda-sorting
1451 (defcustom org-sort-agenda-noeffort-is-high t
1452 "Non-nil means items without effort estimate are sorted as high effort.
1453 This also applies when filtering an agenda view with respect to the
1454 < or > effort operator. Then, tasks with no effort defined will be treated
1455 as tasks with high effort.
1456 When nil, such items are sorted as 0 minutes effort."
1457 :group
'org-agenda-sorting
1460 (defgroup org-agenda-line-format nil
1461 "Options concerning the entry prefix in the Org-mode agenda display."
1462 :tag
"Org Agenda Line Format"
1465 (defcustom org-agenda-prefix-format
1466 '((agenda .
" %i %-12:c%?-12t% s")
1468 (todo .
" %i %-12:c")
1469 (tags .
" %i %-12:c")
1470 (search .
" %i %-12:c"))
1471 "Format specifications for the prefix of items in the agenda views.
1472 An alist with five entries, each for the different agenda types. The
1473 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1474 The values are format strings.
1476 This format works similar to a printf format, with the following meaning:
1478 %c the category of the item, \"Diary\" for entries from the diary,
1479 or as given by the CATEGORY keyword or derived from the file name
1480 %e the effort required by the item
1481 %i the icon category of the item, see `org-agenda-category-icon-alist'
1482 %T the last tag of the item (ignore inherited tags, which come first)
1483 %t the HH:MM time-of-day specification if one applies to the entry
1484 %s Scheduling/Deadline information, a short string
1485 %(expression) Eval EXPRESSION and replace the control string
1488 All specifiers work basically like the standard `%s' of printf, but may
1489 contain two additional characters: a question mark just after the `%'
1490 and a whitespace/punctuation character just before the final letter.
1492 If the first character after `%' is a question mark, the entire field
1493 will only be included if the corresponding value applies to the current
1494 entry. This is useful for fields which should have fixed width when
1495 present, but zero width when absent. For example, \"%?-12t\" will
1496 result in a 12 character time field if a time of the day is specified,
1497 but will completely disappear in entries which do not contain a time.
1499 If there is punctuation or whitespace character just before the final
1500 format letter, this character will be appended to the field value if
1501 the value is not empty. For example, the format \"%-12:c\" leads to
1502 \"Diary: \" if the category is \"Diary\". If the category were be
1503 empty, no additional colon would be inserted.
1505 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1508 - Indent the line with two space characters
1509 - Give the category a 12 chars wide field, padded with whitespace on
1510 the right (because of `-'). Append a colon if there is a category
1512 - If there is a time-of-day, put it into a 12 chars wide field. If no
1513 time, don't put in an empty field, just skip it (because of '?').
1514 - Finally, put the scheduling information.
1516 See also the variables `org-agenda-remove-times-when-in-prefix' and
1517 `org-agenda-remove-tags'.
1519 Custom commands can set this variable in the options section."
1521 (string :tag
"General format")
1522 (list :greedy t
:tag
"View dependent"
1523 (cons (const agenda
) (string :tag
"Format"))
1524 (cons (const timeline
) (string :tag
"Format"))
1525 (cons (const todo
) (string :tag
"Format"))
1526 (cons (const tags
) (string :tag
"Format"))
1527 (cons (const search
) (string :tag
"Format"))))
1528 :group
'org-agenda-line-format
)
1530 (defvar org-prefix-format-compiled nil
1531 "The compiled prefix format and associated variables.
1532 This is a list where first element is a list of variable bindings, and second
1533 element is the compiled format expression. See the variable
1534 `org-agenda-prefix-format'.")
1536 (defcustom org-agenda-todo-keyword-format
"%-1s"
1537 "Format for the TODO keyword in agenda lines.
1538 Set this to something like \"%-12s\" if you want all TODO keywords
1539 to occupy a fixed space in the agenda display."
1540 :group
'org-agenda-line-format
1543 (defcustom org-agenda-diary-sexp-prefix nil
1544 "A regexp that matches part of a diary sexp entry
1545 which should be treated as scheduling/deadline information in
1548 For example, you can use this to extract the `diary-remind-message' from
1549 `diary-remind' entries."
1550 :group
'org-agenda-line-format
1551 :type
'(choice (const :tag
"None" nil
) (regexp :tag
"Regexp")))
1553 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1554 "Text preceding timerange entries in the agenda view.
1555 This is a list with two strings. The first applies when the range
1556 is entirely on one day. The second applies if the range spans several days.
1557 The strings may have two \"%d\" format specifiers which will be filled
1558 with the sequence number of the days, and the total number of days in the
1559 range, respectively."
1560 :group
'org-agenda-line-format
1562 (string :tag
"Deadline today ")
1563 (choice :tag
"Deadline relative"
1564 (string :tag
"Format string")
1567 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1568 "Text preceding scheduled items in the agenda view.
1569 This is a list with two strings. The first applies when the item is
1570 scheduled on the current day. The second applies when it has been scheduled
1571 previously, it may contain a %d indicating that this is the nth time that
1572 this item is scheduled, due to automatic rescheduling of unfinished items
1573 for the following day. So this number is one larger than the number of days
1574 that passed since this item was scheduled first."
1575 :group
'org-agenda-line-format
1577 (string :tag
"Scheduled today ")
1578 (string :tag
"Scheduled previously")))
1580 (defcustom org-agenda-inactive-leader
"["
1581 "Text preceding item pulled into the agenda by inactive time stamps.
1582 These entries are added to the agenda when pressing \"[\"."
1583 :group
'org-agenda-line-format
1586 (string :tag
"Scheduled today ")
1587 (string :tag
"Scheduled previously")))
1589 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1590 "Text preceding deadline items in the agenda view.
1591 This is a list with two strings. The first applies when the item has its
1592 deadline on the current day. The second applies when it is in the past or
1593 in the future, it may contain %d to capture how many days away the deadline
1595 :group
'org-agenda-line-format
1597 (string :tag
"Deadline today ")
1598 (choice :tag
"Deadline relative"
1599 (string :tag
"Format string")
1602 (defcustom org-agenda-remove-times-when-in-prefix t
1603 "Non-nil means remove duplicate time specifications in agenda items.
1604 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1605 time-of-day specification in a headline or diary entry is extracted and
1606 placed into the prefix. If this option is non-nil, the original specification
1607 \(a timestamp or -range, or just a plain time(range) specification like
1608 11:30-4pm) will be removed for agenda display. This makes the agenda less
1610 The option can be t or nil. It may also be the symbol `beg', indicating
1611 that the time should only be removed when it is located at the beginning of
1612 the headline/diary entry."
1613 :group
'org-agenda-line-format
1615 (const :tag
"Always" t
)
1616 (const :tag
"Never" nil
)
1617 (const :tag
"When at beginning of entry" beg
)))
1619 (defcustom org-agenda-remove-timeranges-from-blocks nil
1620 "Non-nil means remove time ranges specifications in agenda
1621 items that span on several days."
1622 :group
'org-agenda-line-format
1626 (defcustom org-agenda-default-appointment-duration nil
1627 "Default duration for appointments that only have a starting time.
1628 When nil, no duration is specified in such cases.
1629 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1630 :group
'org-agenda-line-format
1632 (integer :tag
"Minutes")
1633 (const :tag
"No default duration")))
1635 (defcustom org-agenda-show-inherited-tags t
1636 "Non-nil means show inherited tags in each agenda line."
1637 :group
'org-agenda-line-format
1640 (defcustom org-agenda-hide-tags-regexp nil
1641 "Regular expression used to filter away specific tags in agenda views.
1642 This means that these tags will be present, but not be shown in the agenda
1643 line. Secondary filtering will still work on the hidden tags.
1644 Nil means don't hide any tags."
1645 :group
'org-agenda-line-format
1647 (const :tag
"Hide none" nil
)
1648 (string :tag
"Regexp ")))
1650 (defcustom org-agenda-remove-tags nil
1651 "Non-nil means remove the tags from the headline copy in the agenda.
1652 When this is the symbol `prefix', only remove tags when
1653 `org-agenda-prefix-format' contains a `%T' specifier."
1654 :group
'org-agenda-line-format
1656 (const :tag
"Always" t
)
1657 (const :tag
"Never" nil
)
1658 (const :tag
"When prefix format contains %T" prefix
)))
1660 (if (fboundp 'defvaralias
)
1661 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1662 'org-agenda-remove-tags
))
1664 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1665 "Shift tags in agenda items to this column.
1666 If this number is positive, it specifies the column. If it is negative,
1667 it means that the tags should be flushright to that column. For example,
1668 -80 works well for a normal 80 character screen."
1669 :group
'org-agenda-line-format
1672 (if (fboundp 'defvaralias
)
1673 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1675 (defcustom org-agenda-fontify-priorities
'cookies
1676 "Non-nil means highlight low and high priorities in agenda.
1677 When t, the highest priority entries are bold, lowest priority italic.
1678 However, settings in `org-priority-faces' will overrule these faces.
1679 When this variable is the symbol `cookies', only fontify the
1680 cookies, not the entire task.
1681 This may also be an association list of priority faces, whose
1682 keys are the character values of `org-highest-priority',
1683 `org-default-priority', and `org-lowest-priority' (the default values
1684 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1685 color as a string, or a list like `(:background \"Red\")'.
1686 If it is a color, the variable `org-faces-easy-properties'
1687 determines if it is a foreground or a background color."
1688 :group
'org-agenda-line-format
1690 (const :tag
"Never" nil
)
1691 (const :tag
"Defaults" t
)
1692 (const :tag
"Cookies only" cookies
)
1693 (repeat :tag
"Specify"
1694 (list (character :tag
"Priority" :value ?A
)
1695 (choice :tag
"Face "
1696 (string :tag
"Color")
1697 (sexp :tag
"Face"))))))
1699 (defcustom org-agenda-day-face-function nil
1700 "Function called to determine what face should be used to display a day.
1701 The only argument passed to that function is the day. It should
1702 returns a face, or nil if does not want to specify a face and let
1703 the normal rules apply."
1704 :group
'org-agenda-line-format
1708 (defcustom org-agenda-category-icon-alist nil
1709 "Alist of category icon to be displayed in agenda views.
1711 Each entry should have the following format:
1713 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1715 Where CATEGORY-REGEXP is a regexp matching the categories where
1716 the icon should be displayed.
1717 FILE-OR-DATA either a file path or a string containing image data.
1719 The other fields can be omitted safely if not needed:
1720 TYPE indicates the image type.
1721 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1723 PROPS are additional image attributes to assign to the image,
1724 like, e.g. `:ascent center'.
1726 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1728 If you want to set the display properties yourself, just put a
1729 list as second element:
1731 (CATEGORY-REGEXP (MY PROPERTY LIST))
1733 For example, to display a 16px horizontal space for Emacs
1734 category, you can use:
1736 (\"Emacs\" '(space . (:width (16))))"
1737 :group
'org-agenda-line-format
1739 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1740 :value-type
(choice (list :tag
"Icon"
1741 (string :tag
"File or data")
1742 (symbol :tag
"Type")
1743 (boolean :tag
"Data?")
1744 (repeat :tag
"Extra image properties" :inline t symbol
))
1745 (list :tag
"Display properties" sexp
))))
1747 (defgroup org-agenda-column-view nil
1748 "Options concerning column view in the agenda."
1749 :tag
"Org Agenda Column View"
1752 (defcustom org-agenda-columns-show-summaries t
1753 "Non-nil means show summaries for columns displayed in the agenda view."
1754 :group
'org-agenda-column-view
1757 (defcustom org-agenda-columns-compute-summary-properties t
1758 "Non-nil means recompute all summary properties before column view.
1759 When column view in the agenda is listing properties that have a summary
1760 operator, it can go to all relevant buffers and recompute the summaries
1761 there. This can mean overhead for the agenda column view, but is necessary
1762 to have thing up to date.
1763 As a special case, a CLOCKSUM property also makes sure that the clock
1764 computations are current."
1765 :group
'org-agenda-column-view
1768 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1769 "Non-nil means the duration of an appointment will add to day effort.
1770 The property to which appointment durations will be added is the one given
1771 in the option `org-effort-property'. If an appointment does not have
1772 an end time, `org-agenda-default-appointment-duration' will be used. If that
1773 is not set, an appointment without end time will not contribute to the time
1775 :group
'org-agenda-column-view
1778 (defcustom org-agenda-auto-exclude-function nil
1779 "A function called with a tag to decide if it is filtered on '/ RET'.
1780 The sole argument to the function, which is called once for each
1781 possible tag, is a string giving the name of the tag. The
1782 function should return either nil if the tag should be included
1783 as normal, or \"-<TAG>\" to exclude the tag.
1784 Note that for the purpose of tag filtering, only the lower-case version of
1785 all tags will be considered, so that this function will only ever see
1786 the lower-case version of all tags."
1790 (defcustom org-agenda-bulk-custom-functions nil
1791 "Alist of characters and custom functions for bulk actions.
1792 For example, this value makes those two functions available:
1797 With selected entries in an agenda buffer, `B R' will call
1798 the custom function `set-category' on the selected entries.
1799 Note that functions in this alist don't need to be quoted."
1804 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
1805 "Execute BODY with point at location given by `org-hd-marker' property.
1806 If STRING is non-nil, the text property will be fetched from position 0
1807 in that string. If STRING is nil, it will be fetched from the beginning
1808 of the current line."
1809 (org-with-gensyms (marker)
1810 `(let ((,marker
(get-text-property (if string
0 (point-at-bol))
1811 'org-hd-marker
,string
)))
1812 (with-current-buffer (marker-buffer ,marker
)
1816 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
1818 (defun org-add-agenda-custom-command (entry)
1819 "Replace or add a command in `org-agenda-custom-commands'.
1820 This is mostly for hacking and trying a new command - once the command
1821 works you probably want to add it to `org-agenda-custom-commands' for good."
1822 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1824 (setcdr ass
(cdr entry
))
1825 (push entry org-agenda-custom-commands
))))
1827 ;;; Define the org-agenda-mode
1829 (defvar org-agenda-mode-map
(make-sparse-keymap)
1830 "Keymap for `org-agenda-mode'.")
1831 (if (fboundp 'defvaralias
)
1832 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1834 (defvar org-agenda-menu
) ; defined later in this file.
1835 (defvar org-agenda-restrict
) ; defined later in this file.
1836 (defvar org-agenda-follow-mode nil
)
1837 (defvar org-agenda-entry-text-mode nil
)
1838 (defvar org-agenda-clockreport-mode nil
)
1839 (defvar org-agenda-show-log nil
)
1840 (defvar org-agenda-redo-command nil
)
1841 (defvar org-agenda-query-string nil
)
1842 (defvar org-agenda-mode-hook nil
1843 "Hook for `org-agenda-mode', run after the mode is turned on.")
1844 (defvar org-agenda-type nil
)
1845 (defvar org-agenda-force-single-file nil
)
1846 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1849 ;;; Multiple agenda buffers support
1851 (defcustom org-agenda-sticky nil
1852 "Non-nil means agenda q key will bury agenda buffers.
1853 Agenda commands will then show existing buffer instead of generating new ones.
1854 When nil, `q' will kill the single agenda buffer."
1857 :set
(lambda (var val
)
1859 (org-toggle-sticky-agenda (if val
1 0))
1862 (defun org-toggle-sticky-agenda (&optional arg
)
1863 "Toggle `org-agenda-sticky'."
1865 (let ((new-value (if arg
1866 (> (prefix-numeric-value arg
) 0)
1867 (not org-agenda-sticky
))))
1868 (if (equal new-value org-agenda-sticky
)
1869 (and (org-called-interactively-p 'interactive
)
1870 (message "Sticky agenda was already %s"
1871 (if org-agenda-sticky
"enabled" "disabled")))
1872 (setq org-agenda-sticky new-value
)
1873 (org-agenda-kill-all-agenda-buffers)
1874 (and (org-called-interactively-p 'interactive
)
1875 (message "Sticky agenda was %s"
1876 (if org-agenda-sticky
"enabled" "disabled"))))))
1878 (defvar org-agenda-buffer nil
1879 "Agenda buffer currently being generated.")
1881 (defvar org-agenda-last-prefix-arg nil
)
1882 (defvar org-agenda-this-buffer-name nil
)
1883 (defvar org-agenda-doing-sticky-redo nil
)
1884 (defvar org-agenda-this-buffer-is-sticky nil
)
1886 (defconst org-agenda-local-vars
1887 '(org-agenda-this-buffer-name
1888 org-agenda-undo-list
1889 org-agenda-pending-undo-list
1890 org-agenda-follow-mode
1891 org-agenda-entry-text-mode
1892 org-agenda-clockreport-mode
1894 org-agenda-redo-command
1895 org-agenda-query-string
1897 org-agenda-bulk-marked-entries
1898 org-agenda-undo-has-started-in
1899 org-agenda-last-arguments
1901 org-agenda-tag-filter-overlays
1902 org-agenda-cat-filter-overlays
1903 org-pre-agenda-window-conf
1904 org-agenda-columns-active
1905 org-agenda-tag-filter
1906 org-agenda-category-filter
1908 org-agenda-last-search-view-search-was-boolean
1909 org-agenda-filtered-by-category
1910 org-agenda-filter-form
1911 org-agenda-show-window
1912 org-agenda-cycle-counter
1913 org-agenda-last-prefix-arg
)
1914 "Variables that must be local in agenda buffers to allow multiple buffers.")
1916 (defun org-agenda-mode ()
1917 "Mode for time-sorted view on action items in Org-mode files.
1919 The following commands are available:
1921 \\{org-agenda-mode-map}"
1923 (cond (org-agenda-doing-sticky-redo
1924 ;; Refreshing sticky agenda-buffer
1926 ;; Preserve the value of `org-agenda-local-vars' variables,
1927 ;; while letting `kill-all-local-variables' kill the rest
1928 (let ((save (buffer-local-variables)))
1929 (kill-all-local-variables)
1930 (mapc 'make-local-variable org-agenda-local-vars
)
1932 (let ((var (car elem
))
1935 (member var org-agenda-local-vars
))
1937 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
1939 ;; Creating a sticky Agenda buffer for the first time
1940 (kill-all-local-variables)
1941 (mapc 'make-local-variable org-agenda-local-vars
)
1942 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
1944 ;; Creating a non-sticky agenda buffer
1945 (kill-all-local-variables)
1946 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) nil
)))
1947 (setq org-agenda-undo-list nil
1948 org-agenda-pending-undo-list nil
1949 org-agenda-bulk-marked-entries nil
)
1950 (setq major-mode
'org-agenda-mode
)
1951 ;; Keep global-font-lock-mode from turning on font-lock-mode
1952 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1953 (setq mode-name
"Org-Agenda")
1954 (use-local-map org-agenda-mode-map
)
1955 (easy-menu-add org-agenda-menu
)
1956 (if org-startup-truncated
(setq truncate-lines t
))
1957 (org-set-local 'line-move-visual nil
)
1958 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1959 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1960 ;; Make sure properties are removed when copying text
1961 (make-local-variable 'filter-buffer-substring-functions
)
1962 (add-hook 'filter-buffer-substring-functions
1963 (lambda (fun start end delete
)
1964 (substring-no-properties (funcall fun start end delete
))))
1965 (unless org-agenda-keep-modes
1966 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1967 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1968 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1969 org-agenda-show-log org-agenda-start-with-log-mode
))
1972 '("Agenda") "Agenda Files"
1976 (if (get 'org-agenda-files
'org-restrict
)
1977 "Restricted to single file"
1979 '(org-edit-agenda-file-list)
1980 (not (get 'org-agenda-files
'org-restrict
)))
1982 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1983 (org-agenda-set-mode-name)
1985 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1986 (list 'org-agenda-mode-hook
)))
1988 (substitute-key-definition 'undo
'org-agenda-undo
1989 org-agenda-mode-map global-map
)
1990 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1991 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1992 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1993 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1994 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1995 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1996 (org-defkey org-agenda-mode-map
"*" 'org-agenda-bulk-mark-all
)
1997 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
1998 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1999 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-unmark-all
)
2000 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
2001 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
2002 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
2003 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
2004 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
2005 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
2006 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
2007 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
2008 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
2009 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
2010 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
2011 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
2012 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2013 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2014 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2015 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2016 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2017 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2018 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2019 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2020 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2021 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2022 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2023 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2024 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2025 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2026 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2027 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2028 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2029 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2030 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2031 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2032 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2033 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2034 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2035 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2037 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2038 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2039 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2040 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2041 (while l (org-defkey org-agenda-mode-map
2042 (int-to-string (pop l)) 'digit-argument)))
2044 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2045 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2046 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2047 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2048 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2049 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2050 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2051 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2052 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2053 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2054 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2055 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2056 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2057 'org-clock-modify-effort-estimate)
2058 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2059 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2060 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2061 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2062 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2063 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2064 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2065 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
2066 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2067 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2068 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2069 (substitute-key-definition 'next-line 'org-agenda-next-line
2070 org-agenda-mode-map global-map)
2071 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2072 org-agenda-mode-map global-map)
2073 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2074 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2075 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2076 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2077 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2078 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2079 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2080 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2081 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2082 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2083 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2084 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2085 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2086 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2087 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2088 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2089 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2090 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2091 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2092 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2093 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2094 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2095 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2096 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2097 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2098 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2099 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2100 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2101 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2102 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2104 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2105 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2106 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2107 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2108 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2109 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2110 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2111 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2112 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2113 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2114 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2115 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2117 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2118 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2119 (when org-agenda-mouse-1-follows-link
2120 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2121 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2126 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2127 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2128 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2129 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2132 ["Day View" org-agenda-day-view
2133 :active (org-agenda-check-type nil 'agenda)
2134 :style radio :selected (eq org-agenda-current-span 'day)
2135 :keys "v d (or just d)"]
2136 ["Week View" org-agenda-week-view
2137 :active (org-agenda-check-type nil 'agenda)
2138 :style radio :selected (eq org-agenda-current-span 'week)
2139 :keys "v w (or just w)"]
2140 ["Month View" org-agenda-month-view
2141 :active (org-agenda-check-type nil 'agenda)
2142 :style radio :selected (eq org-agenda-current-span 'month)
2144 ["Year View" org-agenda-year-view
2145 :active (org-agenda-check-type nil 'agenda)
2146 :style radio :selected (eq org-agenda-current-span 'year)
2149 ["Include Diary" org-agenda-toggle-diary
2150 :style toggle :selected org-agenda-include-diary
2151 :active (org-agenda-check-type nil 'agenda)]
2152 ["Include Deadlines" org-agenda-toggle-deadlines
2153 :style toggle :selected org-agenda-include-deadlines
2154 :active (org-agenda-check-type nil 'agenda)]
2155 ["Use Time Grid" org-agenda-toggle-time-grid
2156 :style toggle :selected org-agenda-use-time-grid
2157 :active (org-agenda-check-type nil 'agenda)]
2159 ["Show clock report" org-agenda-clockreport-mode
2160 :style toggle :selected org-agenda-clockreport-mode
2161 :active (org-agenda-check-type nil 'agenda)]
2162 ["Show some entry text" org-agenda-entry-text-mode
2163 :style toggle :selected org-agenda-entry-text-mode
2166 ["Show Logbook entries" org-agenda-log-mode
2167 :style toggle :selected org-agenda-show-log
2168 :active (org-agenda-check-type nil 'agenda 'timeline)
2169 :keys "v l (or just l)"]
2170 ["Include archived trees" org-agenda-archives-mode
2171 :style toggle :selected org-agenda-archives-mode :active t
2173 ["Include archive files" (org-agenda-archives-mode t)
2174 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2177 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2178 ["Write view to file" org-agenda-write t]
2179 ["Rebuild buffer" org-agenda-redo t]
2180 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2182 ["Show original entry" org-agenda-show t]
2183 ["Go To (other window)" org-agenda-goto t]
2184 ["Go To (this window)" org-agenda-switch-to t]
2185 ["Follow Mode" org-agenda-follow-mode
2186 :style toggle :selected org-agenda-follow-mode :active t]
2187 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2190 ["Cycle TODO" org-agenda-todo t]
2191 ["Next TODO set" org-agenda-todo-nextset t]
2192 ["Previous TODO set" org-agenda-todo-previousset t]
2193 ["Add note" org-agenda-add-note t])
2194 ("Archive/Refile/Delete"
2195 ["Archive default" org-agenda-archive-default t]
2196 ["Archive default" org-agenda-archive-default-with-confirmation t]
2197 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2198 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2199 ["Archive subtree" org-agenda-archive t]
2201 ["Refile" org-agenda-refile t]
2203 ["Delete subtree" org-agenda-kill t])
2205 ["Mark entry" org-agenda-bulk-mark t]
2206 ["Mark all" org-agenda-bulk-mark-all t]
2207 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2208 ["Unmark entry" org-agenda-bulk-unmark t]
2209 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
2210 ["Act on all marked" org-agenda-bulk-action t]
2212 ("Tags and Properties"
2213 ["Show all Tags" org-agenda-show-tags t]
2214 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2215 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2217 ["Column View" org-columns t])
2218 ("Deadline/Schedule"
2219 ["Schedule" org-agenda-schedule t]
2220 ["Set Deadline" org-agenda-deadline t]
2222 ["Mark item" org-agenda-action :active t :keys "k m"]
2223 ["Show mark item" org-agenda-action :active t :keys "k v"]
2224 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2225 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2227 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2228 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2229 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2230 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2231 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2232 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2233 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2235 ["Clock in" org-agenda-clock-in t]
2236 ["Clock out" org-agenda-clock-out t]
2237 ["Clock cancel" org-agenda-clock-cancel t]
2238 ["Goto running clock" org-clock-goto t]
2240 ["Set Effort" org-agenda-set-effort t]
2241 ["Change clocked effort" org-clock-modify-effort-estimate
2242 (org-clock-is-active)])
2244 ["Set Priority" org-agenda-priority t]
2245 ["Increase Priority" org-agenda-priority-up t]
2246 ["Decrease Priority" org-agenda-priority-down t]
2247 ["Show Priority" org-agenda-show-priority t])
2249 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2250 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2251 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2252 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2253 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2254 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2256 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2258 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2261 ["Push Files and Views" org-mobile-push t]
2262 ["Get Captured and Flagged" org-mobile-pull t]
2263 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2264 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2266 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2268 ["Quit" org-agenda-quit t]
2269 ["Exit and Release Buffers" org-agenda-exit t]
2274 (defvar org-agenda-allow-remote-undo t
2275 "Non-nil means allow remote undo from the agenda buffer.")
2276 (defvar org-agenda-undo-list nil
2277 "List of undoable operations in the agenda since last refresh.")
2278 (defvar org-agenda-undo-has-started-in nil
2279 "Buffers that have already seen `undo-start' in the current undo sequence.")
2280 (defvar org-agenda-pending-undo-list nil
2281 "In a series of undo commands, this is the list of remaining undo items.")
2283 (defun org-agenda-undo ()
2284 "Undo a remote editing step in the agenda.
2285 This undoes changes both in the agenda buffer and in the remote buffer
2286 that have been changed along."
2288 (or org-agenda-allow-remote-undo
2289 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2290 (if (not (eq this-command last-command))
2291 (setq org-agenda-undo-has-started-in nil
2292 org-agenda-pending-undo-list org-agenda-undo-list))
2293 (if (not org-agenda-pending-undo-list)
2294 (error "No further undo information"))
2295 (let* ((entry (pop org-agenda-pending-undo-list))
2296 buf line cmd rembuf)
2297 (setq cmd (pop entry) line (pop entry))
2298 (setq rembuf (nth 2 entry))
2299 (org-with-remote-undo rembuf
2300 (while (bufferp (setq buf (pop entry)))
2302 (with-current-buffer buf
2303 (let ((last-undo-buffer buf)
2304 (inhibit-read-only t))
2305 (unless (memq buf org-agenda-undo-has-started-in)
2306 (push buf org-agenda-undo-has-started-in)
2307 (make-local-variable 'pending-undo-list)
2309 (while (and pending-undo-list
2310 (listp pending-undo-list)
2311 (not (car pending-undo-list)))
2312 (pop pending-undo-list))
2314 (org-goto-line line)
2315 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2317 (defun org-verify-change-for-undo (l1 l2)
2318 "Verify that a real change occurred between the undo lists L1 and L2."
2319 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2320 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2325 (defvar org-agenda-restrict nil)
2326 (defvar org-agenda-restrict-begin (make-marker))
2327 (defvar org-agenda-restrict-end (make-marker))
2328 (defvar org-agenda-last-dispatch-buffer nil)
2329 (defvar org-agenda-overriding-restriction nil)
2332 (defun org-agenda (&optional arg keys restriction)
2333 "Dispatch agenda commands to collect entries to the agenda buffer.
2334 Prompts for a command to execute. Any prefix arg will be passed
2335 on to the selected command. The default selections are:
2337 a Call `org-agenda-list' to display the agenda for current day or week.
2338 t Call `org-todo-list' to display the global todo list.
2339 T Call `org-todo-list' to display the global todo list, select only
2340 entries with a specific TODO keyword (the user gets a prompt).
2341 m Call `org-tags-view' to display headlines with tags matching
2342 a condition (the user is prompted for the condition).
2343 M Like `m', but select only TODO entries, no ordinary headlines.
2344 L Create a timeline for the current buffer.
2345 e Export views to associated files.
2346 s Search entries for keywords.
2347 / Multi occur across all agenda files and also files listed
2348 in `org-agenda-text-search-extra-files'.
2349 < Restrict agenda commands to buffer, subtree, or region.
2350 Press several times to get the desired effect.
2351 > Remove a previous restriction.
2352 # List \"stuck\" projects.
2353 ! Configure what \"stuck\" means.
2354 C Configure custom agenda commands.
2356 More commands can be added by configuring the variable
2357 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2358 searches can be pre-defined in this way.
2360 If the current buffer is in Org-mode and visiting a file, you can also
2361 first press `<' once to indicate that the agenda should be temporarily
2362 \(until the next use of \\[org-agenda]) restricted to the current file.
2363 Pressing `<' twice means to restrict to the current subtree or region
2367 (let* ((prefix-descriptions nil)
2368 (org-agenda-buffer-name org-agenda-buffer-name)
2369 (org-agenda-window-setup (if (equal (buffer-name)
2370 org-agenda-buffer-name)
2372 org-agenda-window-setup))
2373 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2374 (org-agenda-custom-commands
2375 ;; normalize different versions
2379 (cond ((stringp (cdr x))
2380 (push x prefix-descriptions)
2382 ((stringp (nth 1 x)) x)
2383 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2384 (t (cons (car x) (cons "" (cdr x))))))
2385 org-agenda-custom-commands)))
2386 (buf (current-buffer))
2387 (bfn (buffer-file-name (buffer-base-buffer)))
2388 entry key type match lprops ans)
2389 ;; Turn off restriction unless there is an overriding one,
2390 (unless org-agenda-overriding-restriction
2391 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2392 ;; There is a request to keep the file list in place
2393 (put 'org-agenda-files 'org-restrict nil))
2394 (setq org-agenda-restrict nil)
2395 (move-marker org-agenda-restrict-begin nil)
2396 (move-marker org-agenda-restrict-end nil))
2397 ;; Delete old local properties
2398 (put 'org-agenda-redo-command 'org-lprops nil)
2399 ;; Delete previously set last-arguments
2400 (put 'org-agenda-redo-command 'last-args nil)
2401 ;; Remember where this call originated
2402 (setq org-agenda-last-dispatch-buffer (current-buffer))
2404 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2406 restriction (cdr ans)))
2407 ;; If we have sticky agenda buffers, set a name for the buffer,
2408 ;; depending on the invoking keys. The user may still set this
2409 ;; as a command option, which will overwrite what we do here.
2410 (if org-agenda-sticky
2411 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2412 ;; Establish the restriction, if any
2413 (when (and (not org-agenda-overriding-restriction) restriction)
2414 (put 'org-agenda-files 'org-restrict (list bfn))
2416 ((eq restriction 'region)
2417 (setq org-agenda-restrict t)
2418 (move-marker org-agenda-restrict-begin (region-beginning))
2419 (move-marker org-agenda-restrict-end (region-end)))
2420 ((eq restriction 'subtree)
2422 (setq org-agenda-restrict t)
2423 (org-back-to-heading t)
2424 (move-marker org-agenda-restrict-begin (point))
2425 (move-marker org-agenda-restrict-end
2426 (progn (org-end-of-subtree t)))))))
2428 ;; For example the todo list should not need it (but does...)
2430 ((setq entry (assoc keys org-agenda-custom-commands))
2431 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2433 (setq type (nth 2 entry) match (eval (nth 3 entry))
2434 lprops (nth 4 entry))
2435 (put 'org-agenda-redo-command 'org-lprops lprops)
2438 (org-let lprops '(org-agenda-list current-prefix-arg)))
2440 (org-let lprops '(org-todo-list current-prefix-arg)))
2442 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2444 (org-let lprops '(org-agenda-list-stuck-projects
2445 current-prefix-arg)))
2447 (org-let lprops '(org-tags-view current-prefix-arg match)))
2448 ((eq type 'tags-todo)
2449 (org-let lprops '(org-tags-view '(4) match)))
2451 (org-let lprops '(org-todo-list match)))
2452 ((eq type 'tags-tree)
2453 (org-check-for-org-mode)
2454 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2455 ((eq type 'todo-tree)
2456 (org-check-for-org-mode)
2458 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2459 (regexp-quote match) "\\>"))))
2460 ((eq type 'occur-tree)
2461 (org-check-for-org-mode)
2462 (org-let lprops '(org-occur match)))
2464 (org-let lprops '(funcall type match)))
2466 (org-let lprops '(funcall type match)))
2467 (t (error "Invalid custom agenda command type %s" type))))
2468 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2470 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2471 (customize-variable 'org-agenda-custom-commands))
2472 ((equal keys "a") (call-interactively 'org-agenda-list))
2473 ((equal keys "s") (call-interactively 'org-search-view))
2474 ((equal keys "t") (call-interactively 'org-todo-list))
2475 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2476 ((equal keys "m") (call-interactively 'org-tags-view))
2477 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2478 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2479 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2483 (unless (current-message)
2484 (let* ((m (org-agenda-get-any-marker))
2485 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2488 "FLAGGING-NOTE ([?] for more info): "
2490 (replace-regexp-in-string
2492 (copy-sequence note))
2493 nil 'face 'org-warning)))))))
2496 (unless (derived-mode-p 'org-mode)
2497 (error "This is not an Org-mode file"))
2499 (put 'org-agenda-files 'org-restrict (list bfn))
2500 (org-call-with-arg 'org-timeline arg)))
2501 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2502 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2503 ((equal keys "!") (customize-variable 'org-stuck-projects))
2504 (t (error "Invalid agenda key"))))))
2506 (defun org-agenda-append-agenda ()
2507 "Append another agenda view to the current one.
2508 This function allows interactive building of block agendas.
2509 Agenda views are separated by `org-agenda-block-separator'."
2511 (unless (string= (buffer-name) org-agenda-buffer-name)
2512 (error "Can only append from within agenda buffer"))
2513 (let ((org-agenda-multi t))
2517 (defun org-agenda-normalize-custom-commands (cmds)
2521 (cond ((stringp (cdr x)) nil)
2522 ((stringp (nth 1 x)) x)
2523 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2524 (t (cons (car x) (cons "" (cdr x))))))
2527 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2528 "The user interface for selecting an agenda command."
2530 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2531 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2532 (region-p (org-region-active-p))
2533 (custom org-agenda-custom-commands)
2535 restriction second-time
2536 c entry key type match prefixes rmheader header-end custom1 desc
2537 line lines left right n n1)
2538 (save-window-excursion
2539 (delete-other-windows)
2540 (org-switch-to-buffer-other-window " *Agenda Commands*")
2542 (insert (eval-when-compile
2544 "Press key for an agenda command: < Buffer, subtree/region restriction
2545 -------------------------------- > Remove restriction
2546 a Agenda for current week or day e Export agenda views
2547 t List of all TODO entries T Entries with special TODO kwd
2548 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2549 L Timeline for current buffer # List stuck projects (!=configure)
2550 s Search for keywords * Toggle sticky agenda views
2551 / Multi-occur ? Find :FLAGGED: entries
2552 C Configure custom agenda commands
2555 (while (string-match
2556 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2558 (setq start (match-end 0))
2559 (add-text-properties (match-beginning 2) (match-end 2)
2560 '(face bold) header))
2562 (setq header-end (move-marker (make-marker) (point)))
2564 (setq custom1 custom)
2565 (when (eq rmheader t)
2567 (re-search-forward ":" nil t)
2568 (delete-region (match-end 0) (point-at-eol))
2571 (delete-region (match-end 0) (point-at-eol))
2572 (move-marker header-end (match-end 0)))
2573 (goto-char header-end)
2574 (delete-region (point) (point-max))
2576 ;; Produce all the lines that describe custom commands and prefixes
2578 (while (setq entry (pop custom1))
2579 (setq key (car entry) desc (nth 1 entry)
2581 match (nth 3 entry))
2582 (if (> (length key) 1)
2583 (add-to-list 'prefixes (string-to-char key))
2587 (org-add-props (copy-sequence key)
2590 ((string-match "\\S-" desc) desc)
2591 ((eq type 'agenda) "Agenda for current week or day")
2592 ((eq type 'alltodo) "List of all TODO entries")
2593 ((eq type 'search) "Word search")
2594 ((eq type 'stuck) "List of stuck projects")
2595 ((eq type 'todo) "TODO keyword")
2596 ((eq type 'tags) "Tags query")
2597 ((eq type 'tags-todo) "Tags (TODO)")
2598 ((eq type 'tags-tree) "Tags tree")
2599 ((eq type 'todo-tree) "TODO kwd tree")
2600 ((eq type 'occur-tree) "Occur tree")
2601 ((functionp type) (if (symbolp type)
2603 "Lambda expression"))
2605 (if org-agenda-menu-show-matcher
2610 (setq match (copy-sequence match))
2611 (org-add-props match nil 'face 'org-warning))
2613 (format "set of %d commands" (length match)))
2615 (if (org-string-nw-p match)
2616 (add-text-properties
2617 0 (length line) (list 'help-echo
2618 (concat "Matcher: "match)) line)))
2620 (setq lines (nreverse lines))
2625 (org-add-props (char-to-string x)
2627 (or (cdr (assoc (concat selstring
2629 prefix-descriptions))
2634 ;; Check if we should display in two columns
2635 (if org-agenda-menu-two-column
2637 (setq n (length lines)
2638 n1 (+ (/ n 2) (mod n 2))
2639 right (nthcdr n1 lines)
2640 left (copy-sequence lines))
2641 (setcdr (nthcdr (1- n1) left) nil))
2642 (setq left lines right nil))
2644 (insert "\n" (pop left))
2646 (if (< (current-column) 40)
2647 (move-to-column 40 t)
2649 (insert (pop right))))
2651 ;; Make the window the right size
2652 (goto-char (point-min))
2654 (if (not (pos-visible-in-window-p (point-max)))
2655 (org-fit-window-to-buffer))
2656 (setq second-time t)
2657 (org-fit-window-to-buffer))
2659 ;; Ask for selection
2660 (message "Press key for agenda command%s:"
2661 (if (or restrict-ok org-agenda-overriding-restriction)
2662 (if org-agenda-overriding-restriction
2663 " (restriction lock active)"
2665 (format " (restricted to %s)" restriction)
2668 (setq c (read-char-exclusive))
2671 ((assoc (char-to-string c) custom)
2672 (setq selstring (concat selstring (char-to-string c)))
2673 (throw 'exit (cons selstring restriction)))
2675 (setq selstring (concat selstring (char-to-string c))
2677 rmheader (or rmheader t)
2678 custom (delq nil (mapcar
2680 (if (or (= (length (car x)) 1)
2681 (/= (string-to-char (car x)) c))
2683 (cons (substring (car x) 1) (cdr x))))
2686 (call-interactively 'org-toggle-sticky-agenda)
2688 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2689 (message "Restriction is only possible in Org-mode buffers")
2692 (org-agenda-remove-restriction-lock 'noupdate)
2693 (setq restriction 'buffer))
2695 (org-agenda-remove-restriction-lock 'noupdate)
2696 (setq restriction (if region-p 'region 'subtree)))
2698 (org-agenda-remove-restriction-lock 'noupdate)
2701 ((eq restriction 'buffer)
2702 (if region-p 'region 'subtree))
2703 ((memq restriction '(subtree region))
2707 (org-agenda-remove-restriction-lock 'noupdate)
2708 (setq restriction nil))
2709 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2710 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2711 ((and (> (length selstring) 0) (eq c ?\d))
2713 (org-agenda-get-restriction-and-command prefix-descriptions))
2715 ((equal c ?q) (error "Abort"))
2716 (t (error "Invalid key %c" c))))))))
2718 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2719 (defvar org-agenda-last-arguments nil
2720 "The arguments of the previous call to `org-agenda'.")
2721 (defun org-agenda-run-series (name series)
2722 (org-let (nth 1 series) '(org-prepare-agenda name))
2723 ;; We need to reset agenda markers here, because when constructing a
2724 ;; block agenda, the individual blocks do not do that.
2725 (org-agenda-reset-markers)
2726 (let* ((org-agenda-multi t)
2727 (redo (list 'org-agenda-run-series name (list 'quote series)))
2728 (org-agenda-overriding-arguments
2729 (or org-agenda-overriding-arguments
2730 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2731 (get 'org-agenda-redo-command 'last-args))))
2733 (gprops (nth 1 series))
2734 match ;; The byte compiler incorrectly complains about this. Keep it!
2736 (while (setq cmd (pop cmds))
2737 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2740 (org-let2 gprops lprops
2741 '(call-interactively 'org-agenda-list)))
2743 (org-let2 gprops lprops
2744 '(call-interactively 'org-todo-list)))
2746 (org-let2 gprops lprops
2747 '(org-search-view current-prefix-arg match nil)))
2749 (org-let2 gprops lprops
2750 '(call-interactively 'org-agenda-list-stuck-projects)))
2752 (org-let2 gprops lprops
2753 '(org-tags-view current-prefix-arg match)))
2754 ((eq type 'tags-todo)
2755 (org-let2 gprops lprops
2756 '(org-tags-view '(4) match)))
2758 (org-let2 gprops lprops
2759 '(org-todo-list match)))
2761 (org-let2 gprops lprops
2762 '(funcall type match)))
2763 (t (error "Invalid type in command series"))))
2765 (setq org-agenda-redo-command redo)
2766 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2767 (goto-char (point-min)))
2768 (org-fit-agenda-window)
2769 (org-let (nth 1 series) '(org-finalize-agenda)))
2772 (defmacro org-batch-agenda (cmd-key &rest parameters)
2773 "Run an agenda command in batch mode and send the result to STDOUT.
2774 If CMD-KEY is a string of length 1, it is used as a key in
2775 `org-agenda-custom-commands' and triggers this command. If it is a
2776 longer string it is used as a tags/todo match string.
2777 Parameters are alternating variable names and values that will be bound
2778 before running the agenda command."
2779 (org-eval-in-environment (org-make-parameter-alist parameters)
2780 (if (> (length cmd-key) 2)
2781 (org-tags-view nil cmd-key)
2782 (org-agenda nil cmd-key)))
2783 (set-buffer org-agenda-buffer-name)
2784 (princ (buffer-string)))
2785 (def-edebug-spec org-batch-agenda (form &rest sexp))
2787 (defvar org-agenda-info nil)
2790 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2791 "Run an agenda command in batch mode and send the result to STDOUT.
2792 If CMD-KEY is a string of length 1, it is used as a key in
2793 `org-agenda-custom-commands' and triggers this command. If it is a
2794 longer string it is used as a tags/todo match string.
2795 Parameters are alternating variable names and values that will be bound
2796 before running the agenda command.
2798 The output gives a line for each selected agenda item. Each
2799 item is a list of comma-separated values, like this:
2801 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2803 category The category of the item
2804 head The headline, without TODO kwd, TAGS and PRIORITY
2805 type The type of the agenda entry, can be
2806 todo selected in TODO match
2807 tagsmatch selected in tags match
2808 diary imported from diary
2809 deadline a deadline on given date
2810 scheduled scheduled on given date
2811 timestamp entry has timestamp on given date
2812 closed entry was closed on given date
2813 upcoming-deadline warning about deadline
2814 past-scheduled forwarded scheduled item
2815 block entry has date block including g. date
2816 todo The todo keyword, if any
2817 tags All tags including inherited ones, separated by colons
2818 date The relevant date, like 2007-2-14
2819 time The time, like 15:00-16:50
2820 extra Sting with extra planning info
2821 priority-l The priority letter if any was given
2822 priority-n The computed numerical priority
2823 agenda-day The day in the agenda where this is listed"
2824 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2825 (org-make-parameter-alist parameters))
2826 (if (> (length cmd-key) 2)
2827 (org-tags-view nil cmd-key)
2828 (org-agenda nil cmd-key)))
2829 (set-buffer org-agenda-buffer-name)
2830 (let* ((lines (org-split-string (buffer-string) "\n"))
2832 (while (setq line (pop lines))
2834 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2835 (setq org-agenda-info
2836 (org-fix-agenda-info (text-properties-at 0 line)))
2838 (mapconcat 'org-agenda-export-csv-mapper
2839 '(org-category txt type todo tags date time extra
2840 priority-letter priority agenda-day)
2843 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2845 (defun org-fix-agenda-info (props)
2846 "Make sure all properties on an agenda item have a canonical form.
2847 This ensures the export commands can easily use it."
2849 (when (setq tmp (plist-get props 'tags))
2850 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2851 (when (setq tmp (plist-get props 'date))
2852 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2853 (let ((calendar-date-display-form '(year "-" month "-" day)))
2854 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2856 (setq tmp (calendar-date-string tmp)))
2857 (setq props (plist-put props 'date tmp)))
2858 (when (setq tmp (plist-get props 'day))
2859 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2860 (let ((calendar-date-display-form '(year "-" month "-" day)))
2861 (setq tmp (calendar-date-string tmp)))
2862 (setq props (plist-put props 'day tmp))
2863 (setq props (plist-put props 'agenda-day tmp)))
2864 (when (setq tmp (plist-get props 'txt))
2865 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2866 (plist-put props 'priority-letter (match-string 1 tmp))
2867 (setq tmp (replace-match "" t t tmp)))
2868 (when (and (setq re (plist-get props 'org-todo-regexp))
2869 (setq re (concat "\\`\\.*" re " ?"))
2870 (string-match re tmp))
2871 (plist-put props 'todo (match-string 1 tmp))
2872 (setq tmp (replace-match "" t t tmp)))
2873 (plist-put props 'txt tmp)))
2876 (defun org-agenda-export-csv-mapper (prop)
2877 (let ((res (plist-get org-agenda-info prop)))
2882 (t (prin1-to-string res))))
2883 (while (string-match "," res)
2884 (setq res (replace-match ";" t t res)))
2889 (defun org-store-agenda-views (&rest parameters)
2891 (eval (list 'org-batch-store-agenda-views)))
2894 (defmacro org-batch-store-agenda-views (&rest parameters)
2895 "Run all custom agenda commands that have a file argument."
2896 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2898 (dir default-directory)
2899 (pars (org-make-parameter-alist parameters))
2900 cmd thiscmdkey files opts cmd-or-set)
2901 (save-window-excursion
2903 (setq cmd (pop cmds)
2904 thiscmdkey (car cmd)
2905 cmd-or-set (nth 2 cmd)
2906 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2907 files (nth (if (listp cmd-or-set) 4 5) cmd))
2908 (if (stringp files) (setq files (list files)))
2910 (org-eval-in-environment (append org-agenda-exporter-settings
2912 (org-agenda nil thiscmdkey))
2913 (set-buffer org-agenda-buffer-name)
2915 (org-eval-in-environment (append org-agenda-exporter-settings
2917 (org-agenda-write (expand-file-name (pop files) dir) nil t)))
2918 (and (get-buffer org-agenda-buffer-name)
2919 (kill-buffer org-agenda-buffer-name)))))))
2920 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2922 (defun org-agenda-mark-header-line (pos)
2923 "Mark the line at POS as an agenda structure header."
2926 (put-text-property (point-at-bol) (point-at-eol)
2927 'org-agenda-structural-header t)
2928 (when org-agenda-title-append
2929 (put-text-property (point-at-bol) (point-at-eol)
2930 'org-agenda-title-append org-agenda-title-append))))
2932 (defvar org-mobile-creating-agendas)
2933 (defvar org-agenda-write-buffer-name "Agenda View")
2934 (defun org-agenda-write (file &optional open nosettings)
2935 "Write the current buffer (an agenda view) as a file.
2936 Depending on the extension of the file name, plain text (.txt),
2937 HTML (.html or .htm) or Postscript (.ps) is produced.
2938 If the extension is .ics, run icalendar export over all files used
2939 to construct the agenda and limit the export to entries listed in the
2941 With prefix argument OPEN, open the new file immediately.
2942 If NOSETTINGS is given, do not scope the settings of
2943 `org-agenda-exporter-settings' into the export commands. This is used when
2944 the settings have already been scoped and we do not wish to overrule other,
2945 higher priority settings."
2946 (interactive "FWrite agenda to file: \nP")
2947 (if (not (file-writable-p file))
2948 (error "Cannot write agenda to file %s" file))
2949 (org-let (if nosettings nil org-agenda-exporter-settings)
2951 (save-window-excursion
2952 (org-agenda-mark-filtered-text)
2953 (let ((bs (copy-sequence (buffer-string))) beg)
2954 (org-agenda-unmark-filtered-text)
2956 (rename-buffer org-agenda-write-buffer-name t)
2957 (set-buffer-modified-p nil)
2959 (org-agenda-remove-marked-text 'org-filtered)
2960 (while (setq beg (text-property-any (point-min) (point-max)
2963 beg (or (next-single-property-change beg 'org-filtered)
2965 (run-hooks 'org-agenda-before-write-hook)
2967 ((org-bound-and-true-p org-mobile-creating-agendas)
2968 (org-mobile-write-agenda-for-mobile file))
2969 ((string-match "\\.html?\\'" file)
2971 (set-buffer (htmlize-buffer (current-buffer)))
2973 (when (and org-agenda-export-html-style
2974 (string-match "<style>" org-agenda-export-html-style))
2975 ;; replace <style> section with org-agenda-export-html-style
2976 (goto-char (point-min))
2977 (kill-region (- (search-forward "<style") 6)
2978 (search-forward "</style>"))
2979 (insert org-agenda-export-html-style))
2981 (kill-buffer (current-buffer))
2982 (message "HTML written to %s" file))
2983 ((string-match "\\.ps\\'" file)
2985 (ps-print-buffer-with-faces file)
2986 (message "Postscript written to %s" file))
2987 ((string-match "\\.pdf\\'" file)
2989 (ps-print-buffer-with-faces
2990 (concat (file-name-sans-extension file) ".ps"))
2991 (call-process "ps2pdf" nil nil nil
2993 (concat (file-name-sans-extension file) ".ps"))
2994 (expand-file-name file))
2995 (delete-file (concat (file-name-sans-extension file) ".ps"))
2996 (message "PDF written to %s" file))
2997 ((string-match "\\.ics\\'" file)
2998 (require 'org-icalendar)
2999 (let ((org-agenda-marker-table
3000 (org-create-marker-find-array
3001 (org-agenda-collect-markers)))
3002 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3003 (org-combined-agenda-icalendar-file file))
3004 (apply 'org-export-icalendar 'combine
3005 (org-agenda-files nil 'ifmode))))
3007 (let ((bs (buffer-string)))
3012 (kill-buffer (current-buffer))
3013 (message "Plain text written to %s" file))))))))
3014 (set-buffer org-agenda-buffer-name))
3015 (when open (org-open-file file)))
3017 (defvar org-agenda-tag-filter-overlays nil)
3018 (defvar org-agenda-cat-filter-overlays nil)
3020 (defun org-agenda-mark-filtered-text ()
3021 "Mark all text hidden by filtering with a text property."
3022 (let ((inhibit-read-only t))
3025 (when (equal (overlay-buffer o) (current-buffer))
3027 (overlay-start o) (overlay-end o)
3029 (append org-agenda-tag-filter-overlays
3030 org-agenda-cat-filter-overlays))))
3032 (defun org-agenda-unmark-filtered-text ()
3033 "Remove the filtering text property."
3034 (let ((inhibit-read-only t))
3035 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3037 (defun org-agenda-remove-marked-text (property &optional value)
3038 "Delete all text marked with VALUE of PROPERTY.
3039 VALUE defaults to t."
3041 (setq value (or value t))
3042 (while (setq beg (text-property-any (point-min) (point-max)
3045 beg (or (next-single-property-change beg 'org-filtered)
3048 (defun org-agenda-add-entry-text ()
3049 "Add entry text to agenda lines.
3050 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3051 entry text following headings shown in the agenda.
3052 Drawers will be excluded, also the line with scheduling/deadline info."
3053 (when (and (> org-agenda-add-entry-text-maxlines 0)
3054 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3056 (goto-char (point-min))
3058 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3059 (beginning-of-line 2)
3060 (setq txt (org-agenda-get-some-entry-text
3061 m org-agenda-add-entry-text-maxlines " > "))
3063 (if (string-match "\\S-" txt)
3065 (or (eobp) (forward-char 1))))))))
3067 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3069 "Extract entry text from MARKER, at most N-LINES lines.
3070 This will ignore drawers etc, just get the text.
3071 If INDENT is given, prefix every line with this string. If KEEP is
3072 given, it is a list of symbols, defining stuff that should not be
3073 removed from the entry content. Currently only `planning' is allowed here."
3074 (let (txt drawer-re kwd-time-re ind)
3076 (with-current-buffer (marker-buffer marker)
3077 (if (not (derived-mode-p 'org-mode))
3084 (setq txt (buffer-substring
3085 (min (1+ (point)) (point-max))
3086 (progn (outline-next-heading) (point)))
3087 drawer-re org-drawer-regexp
3088 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3092 (when org-agenda-add-entry-text-descriptive-links
3093 (goto-char (point-min))
3094 (while (org-activate-bracket-links (point-max))
3095 (add-text-properties (match-beginning 0) (match-end 0)
3097 (goto-char (point-min))
3098 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3099 (set-text-properties (match-beginning 0) (match-end 0)
3101 (goto-char (point-min))
3102 (while (re-search-forward drawer-re nil t)
3105 (progn (re-search-forward
3106 "^[ \t]*:END:.*\n?" nil 'move)
3108 (unless (member 'planning keep)
3109 (goto-char (point-min))
3110 (while (re-search-forward kwd-time-re nil t)
3111 (replace-match "")))
3112 (goto-char (point-min))
3113 (when org-agenda-entry-text-exclude-regexps
3114 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3115 (while (setq re (pop re-list))
3116 (goto-char (point-min))
3117 (while (re-search-forward re nil t)
3118 (replace-match "")))))
3119 (goto-char (point-max))
3120 (skip-chars-backward " \t\n")
3121 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3123 ;; find and remove min common indentation
3124 (goto-char (point-min))
3125 (untabify (point-min) (point-max))
3126 (setq ind (org-get-indentation))
3128 (unless (looking-at "[ \t]*$")
3129 (setq ind (min ind (org-get-indentation))))
3130 (beginning-of-line 2))
3131 (goto-char (point-min))
3133 (unless (looking-at "[ \t]*$")
3134 (move-to-column ind)
3135 (delete-region (point-at-bol) (point)))
3136 (beginning-of-line 2))
3138 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3140 (goto-char (point-min))
3142 (while (and (not (eobp)) (re-search-forward "^" nil t))
3143 (replace-match indent t t)))
3144 (goto-char (point-min))
3145 (while (looking-at "[ \t]*\n") (replace-match ""))
3146 (goto-char (point-max))
3147 (when (> (org-current-line)
3149 (org-goto-line (1+ n-lines))
3151 (setq txt (buffer-substring (point-min) (point)))))))))
3154 (defun org-agenda-collect-markers ()
3155 "Collect the markers pointing to entries in the agenda buffer."
3158 (goto-char (point-min))
3160 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3161 (org-get-at-bol 'org-marker)))
3163 (beginning-of-line 2)))
3164 (nreverse markers)))
3166 (defun org-create-marker-find-array (marker-list)
3167 "Create a alist of files names with all marker positions in that file."
3169 (while (setq m (pop marker-list))
3170 (setq p (marker-position m)
3171 f (buffer-file-name (or (buffer-base-buffer
3173 (marker-buffer m))))
3174 (if (setq a (assoc f tbl))
3175 (push (marker-position m) (cdr a))
3176 (push (list f p) tbl)))
3177 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3180 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3181 (defun org-check-agenda-marker-table ()
3182 "Check of the current entry is on the marker list."
3183 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3185 (and (setq a (assoc file org-agenda-marker-table))
3188 (org-back-to-heading t)
3189 (member (point) (cdr a)))))))
3191 (defun org-check-for-org-mode ()
3192 "Make sure current buffer is in org-mode. Error if not."
3193 (or (derived-mode-p 'org-mode)
3194 (error "Cannot execute org-mode agenda command on buffer in %s"
3197 (defun org-fit-agenda-window ()
3198 "Fit the window to the buffer size."
3199 (and (memq org-agenda-window-setup '(reorganize-frame))
3200 (fboundp 'fit-window-to-buffer)
3201 (org-fit-window-to-buffer
3203 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3204 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3206 ;;; Agenda prepare and finalize
3208 (defvar org-agenda-multi nil) ; dynamically scoped
3209 (defvar org-agenda-buffer-name "*Org Agenda*")
3210 (defvar org-pre-agenda-window-conf nil)
3211 (defvar org-agenda-columns-active nil)
3212 (defvar org-agenda-name nil)
3213 (defvar org-agenda-tag-filter nil)
3214 (defvar org-agenda-category-filter nil)
3215 (defvar org-agenda-top-category-filter nil)
3216 (defvar org-agenda-tag-filter-while-redo nil)
3217 (defvar org-agenda-tag-filter-preset nil
3218 "A preset of the tags filter used for secondary agenda filtering.
3219 This must be a list of strings, each string must be a single tag preceded
3221 This variable should not be set directly, but agenda custom commands can
3222 bind it in the options section. The preset filter is a global property of
3223 the entire agenda view. In a block agenda, it will not work reliably to
3224 define a filter for one of the individual blocks. You need to set it in
3225 the global options and expect it to be applied to the entire view.")
3227 (defvar org-agenda-category-filter-preset nil
3228 "A preset of the category filter used for secondary agenda filtering.
3229 This must be a list of strings, each string must be a single category
3230 preceded by \"+\" or \"-\".
3231 This variable should not be set directly, but agenda custom commands can
3232 bind it in the options section. The preset filter is a global property of
3233 the entire agenda view. In a block agenda, it will not work reliably to
3234 define a filter for one of the individual blocks. You need to set it in
3235 the global options and expect it to be applied to the entire view.")
3238 (defun org-agenda-use-sticky-p ()
3239 "Return non-nil if an agenda buffer named
3240 `org-agenda-buffer-name' exists and should be shown instead of
3241 generating a new one."
3243 ;; turned off by user
3245 ;; For multi-agenda buffer already exists
3246 (not org-agenda-multi)
3248 (get-buffer org-agenda-buffer-name)
3249 ;; C-u parameter is same as last call
3250 (with-current-buffer (get-buffer org-agenda-buffer-name)
3252 (equal current-prefix-arg
3253 org-agenda-last-prefix-arg)
3254 ;; In case user turned stickiness on, while having existing
3255 ;; Agenda buffer active, don't reuse that buffer, because it
3256 ;; does not have org variables local
3257 org-agenda-this-buffer-is-sticky))))
3259 (defun org-prepare-agenda-window (abuf)
3260 "Setup agenda buffer in the window."
3261 (let* ((awin (get-buffer-window abuf))
3264 ((equal (current-buffer) abuf) nil)
3265 (awin (select-window awin))
3266 ((not (setq wconf (current-window-configuration))))
3267 ((equal org-agenda-window-setup 'current-window)
3268 (org-pop-to-buffer-same-window abuf))
3269 ((equal org-agenda-window-setup 'other-window)
3270 (org-switch-to-buffer-other-window abuf))
3271 ((equal org-agenda-window-setup 'other-frame)
3272 (switch-to-buffer-other-frame abuf))
3273 ((equal org-agenda-window-setup 'reorganize-frame)
3274 (delete-other-windows)
3275 (org-switch-to-buffer-other-window abuf)))
3276 ;; additional test in case agenda is invoked from within agenda
3277 ;; buffer via elisp link
3278 (unless (equal (current-buffer) abuf)
3279 (org-pop-to-buffer-same-window abuf))
3280 (setq org-pre-agenda-window-conf wconf)))
3282 (defun org-prepare-agenda (&optional name)
3283 (if (org-agenda-use-sticky-p)
3285 ;; Popup existing buffer
3286 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3287 (message "Sticky Agenda buffer, use `r' to refresh")
3289 (setq org-todo-keywords-for-agenda nil)
3290 (setq org-drawers-for-agenda nil)
3291 (unless org-agenda-persistent-filter
3292 (setq org-agenda-tag-filter nil
3293 org-agenda-category-filter nil))
3294 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3295 (put 'org-agenda-category-filter :preset-filter
3296 org-agenda-category-filter-preset)
3297 (if org-agenda-multi
3299 (setq buffer-read-only nil)
3300 (goto-char (point-max))
3301 (unless (or (bobp) org-agenda-compact-blocks
3302 (not org-agenda-block-separator))
3304 (if (stringp org-agenda-block-separator)
3305 org-agenda-block-separator
3306 (make-string (window-width) org-agenda-block-separator))
3308 (narrow-to-region (point) (point-max)))
3309 (setq org-done-keywords-for-agenda nil)
3311 ;; Setting any org variables that are in org-agenda-local-vars
3312 ;; list need to be done after the prepare call
3313 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3314 (setq buffer-read-only nil)
3315 (org-agenda-reset-markers)
3316 (let ((inhibit-read-only t)) (erase-buffer))
3318 (setq org-agenda-buffer (current-buffer))
3319 (setq org-agenda-contributing-files nil)
3320 (setq org-agenda-columns-active nil)
3321 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3322 (setq org-todo-keywords-for-agenda
3323 (org-uniquify org-todo-keywords-for-agenda))
3324 (setq org-done-keywords-for-agenda
3325 (org-uniquify org-done-keywords-for-agenda))
3326 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3327 (setq org-agenda-last-prefix-arg current-prefix-arg)
3328 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3329 (and name (not org-agenda-name)
3330 (org-set-local 'org-agenda-name name)))
3331 (setq buffer-read-only nil)))
3333 (defun org-finalize-agenda ()
3334 "Finishing touch for the agenda buffer, called just before displaying it."
3335 (unless org-agenda-multi
3337 (let ((inhibit-read-only t))
3338 (goto-char (point-min))
3339 (while (org-activate-bracket-links (point-max))
3340 (add-text-properties (match-beginning 0) (match-end 0)
3342 (org-agenda-align-tags)
3343 (unless org-agenda-with-colors
3344 (remove-text-properties (point-min) (point-max) '(face nil))))
3345 (if (and (boundp 'org-agenda-overriding-columns-format)
3346 org-agenda-overriding-columns-format)
3347 (org-set-local 'org-agenda-overriding-columns-format
3348 org-agenda-overriding-columns-format))
3349 (if (and (boundp 'org-agenda-view-columns-initially)
3350 org-agenda-view-columns-initially)
3351 (org-agenda-columns))
3352 (when org-agenda-fontify-priorities
3353 (org-agenda-fontify-priorities))
3354 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3355 (org-agenda-dim-blocked-tasks))
3356 (org-agenda-mark-clocking-task)
3357 (when org-agenda-entry-text-mode
3358 (org-agenda-entry-text-hide)
3359 (org-agenda-entry-text-show))
3360 (if (functionp 'org-habit-insert-consistency-graphs)
3361 (org-habit-insert-consistency-graphs))
3362 (run-hooks 'org-finalize-agenda-hook)
3363 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3364 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3365 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3366 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3367 (org-agenda-filter-apply org-agenda-category-filter 'category))
3368 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3371 (defun org-agenda-mark-clocking-task ()
3372 "Mark the current clock entry in the agenda if it is present."
3374 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3375 (delete-overlay o)))
3376 (overlays-in (point-min) (point-max)))
3377 (when (marker-buffer org-clock-hd-marker)
3379 (goto-char (point-min))
3381 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3383 (when (equal (org-get-at-bol 'org-hd-marker)
3384 org-clock-hd-marker)
3385 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3386 (overlay-put ov 'type 'org-agenda-clocking)
3387 (overlay-put ov 'face 'org-agenda-clocking)
3388 (overlay-put ov 'help-echo
3389 "The clock is running in this item")))))))
3391 (defun org-agenda-fontify-priorities ()
3392 "Make highest priority lines bold, and lowest italic."
3394 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3395 (delete-overlay o)))
3396 (overlays-in (point-min) (point-max)))
3398 (let ((inhibit-read-only t)
3400 (goto-char (point-min))
3401 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3402 (setq h (or (get-char-property (point) 'org-highest-priority)
3403 org-highest-priority)
3404 l (or (get-char-property (point) 'org-lowest-priority)
3405 org-lowest-priority)
3406 p (string-to-char (match-string 1))
3407 b (match-beginning 0)
3408 e (if (eq org-agenda-fontify-priorities 'cookies)
3411 ov (make-overlay b e))
3414 (cond ((org-face-from-face-or-color
3416 (cdr (assoc p org-priority-faces))))
3417 ((and (listp org-agenda-fontify-priorities)
3418 (org-face-from-face-or-color
3420 (cdr (assoc p org-agenda-fontify-priorities)))))
3421 ((equal p l) 'italic)
3422 ((equal p h) 'bold)))
3423 (overlay-put ov 'org-type 'org-priority)))))
3425 (defun org-agenda-dim-blocked-tasks ()
3426 "Dim currently blocked TODO's in the agenda display."
3427 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3428 (delete-overlay o)))
3429 (overlays-in (point-min) (point-max)))
3431 (let ((inhibit-read-only t)
3432 (org-depend-tag-blocked nil)
3433 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3434 org-blocked-by-checkboxes
3435 invis1 b e p ov h l)
3436 (goto-char (point-min))
3437 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3438 (and pos (goto-char (1+ pos))))
3439 (setq org-blocked-by-checkboxes nil invis1 invis)
3440 (let ((marker (org-get-at-bol 'org-hd-marker)))
3442 (with-current-buffer (marker-buffer marker)
3443 (save-excursion (goto-char marker)
3444 (org-entry-blocked-p))))
3445 (if org-blocked-by-checkboxes (setq invis1 nil))
3447 (max (point-min) (1- (point-at-bol)))
3450 ov (make-overlay b e))
3452 (overlay-put ov 'invisible t)
3453 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3454 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3456 (defvar org-agenda-skip-function nil
3457 "Function to be called at each match during agenda construction.
3458 If this function returns nil, the current match should not be skipped.
3459 Otherwise, the function must return a position from where the search
3460 should be continued.
3461 This may also be a Lisp form, it will be evaluated.
3462 Never set this variable using `setq' or so, because then it will apply
3463 to all future agenda commands. If you do want a global skipping condition,
3464 use the option `org-agenda-skip-function-global' instead.
3465 The correct usage for `org-agenda-skip-function' is to bind it with
3466 `let' to scope it dynamically into the agenda-constructing command.
3467 A good way to set it is through options in `org-agenda-custom-commands'.")
3469 (defun org-agenda-skip ()
3470 "Throw to `:skip' in places that should be skipped.
3471 Also moves point to the end of the skipped region, so that search can
3472 continue from there."
3473 (let ((p (point-at-bol)) to)
3474 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3475 (get-text-property p :org-archived)
3476 (org-end-of-subtree t)
3478 (and org-agenda-skip-comment-trees
3479 (get-text-property p :org-comment)
3480 (org-end-of-subtree t)
3482 (if (equal (char-after p) ?#) (throw :skip t))
3483 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3484 (org-agenda-skip-eval org-agenda-skip-function)))
3488 (defun org-agenda-skip-eval (form)
3489 "If FORM is a function or a list, call (or eval) is and return result.
3490 `save-excursion' and `save-match-data' are wrapped around the call, so point
3491 and match data are returned to the previous state no matter what these
3495 (or (setq fp (functionp form))
3503 (defvar org-agenda-markers nil
3504 "List of all currently active markers created by `org-agenda'.")
3505 (defvar org-agenda-last-marker-time (org-float-time)
3506 "Creation time of the last agenda marker.")
3508 (defun org-agenda-new-marker (&optional pos)
3509 "Return a new agenda marker.
3510 Org-mode keeps a list of these markers and resets them when they are
3512 (let ((m (copy-marker (or pos (point)))))
3513 (setq org-agenda-last-marker-time (org-float-time))
3514 (if org-agenda-buffer
3515 (with-current-buffer org-agenda-buffer
3516 (push m org-agenda-markers))
3517 (push m org-agenda-markers))
3520 (defun org-agenda-reset-markers ()
3521 "Reset markers created by `org-agenda'."
3522 (while org-agenda-markers
3523 (move-marker (pop org-agenda-markers) nil)))
3525 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3526 "Save relative positions of markers in region.
3527 This check for agenda markers in all agenda buffers currently active."
3528 (dolist (buf (buffer-list))
3529 (with-current-buffer buf
3530 (when (eq major-mode 'org-agenda-mode)
3531 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3532 org-agenda-markers)))))
3536 (defun org-agenda-entry-text-show-here ()
3537 "Add some text from the entry as context to the current line."
3539 (setq m (org-get-at-bol 'org-hd-marker))
3540 (unless (marker-buffer m)
3541 (error "No marker points to an entry here"))
3542 (setq txt (concat "\n" (org-no-properties
3543 (org-agenda-get-some-entry-text
3544 m org-agenda-entry-text-maxlines " > "))))
3545 (when (string-match "\\S-" txt)
3546 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3547 (overlay-put o 'evaporate t)
3548 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3549 (overlay-put o 'after-string txt))))
3551 (defun org-agenda-entry-text-show ()
3552 "Add entry context for all agenda lines."
3555 (goto-char (point-max))
3556 (beginning-of-line 1)
3558 (when (org-get-at-bol 'org-hd-marker)
3559 (org-agenda-entry-text-show-here))
3560 (beginning-of-line 0))))
3562 (defun org-agenda-entry-text-hide ()
3563 "Remove any shown entry context."
3566 (if (eq (overlay-get o 'org-overlay-type)
3567 'agenda-entry-content)
3568 (progn (delete-overlay o) t)))
3569 (overlays-in (point-min) (point-max)))))
3571 (defun org-agenda-get-day-face (date)
3572 "Return the face DATE should be displayed with."
3573 (or (and (functionp org-agenda-day-face-function)
3574 (funcall org-agenda-day-face-function date))
3575 (cond ((org-agenda-todayp date)
3576 'org-agenda-date-today)
3577 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3578 'org-agenda-date-weekend)
3579 (t 'org-agenda-date))))
3583 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3585 (defun org-timeline (&optional dotodo)
3586 "Show a time-sorted view of the entries in the current org file.
3587 Only entries with a time stamp of today or later will be listed. With
3588 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3589 under the current date.
3590 If the buffer contains an active region, only check the region for
3594 (org-agenda-show-log-scoped org-agenda-show-log)
3595 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3597 (date (calendar-current-date))
3598 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3599 (end (if (org-region-active-p) (region-end) (point-max)))
3600 (day-numbers (org-get-all-dates
3602 t org-agenda-show-log-scoped ; always include today
3603 org-timeline-show-empty-dates))
3604 (org-deadline-warning-days 0)
3605 (org-agenda-only-exact-dates t)
3610 (setq org-agenda-redo-command
3612 (list 'org-switch-to-buffer-other-window (current-buffer))
3613 (list 'org-timeline (list 'quote dotodo))))
3615 ;; Remove past dates from the list of dates.
3616 (setq day-numbers (delq nil (mapcar (lambda(x)
3617 (if (>= x today) x nil))
3619 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3620 (org-compile-prefix-format 'timeline)
3621 (org-set-sorting-strategy 'timeline)
3622 (if org-agenda-show-log-scoped (push :closed args))
3623 (push :timestamp args)
3624 (push :deadline args)
3625 (push :scheduled args)
3627 (if dotodo (push :todo args))
3628 (insert "Timeline of file " entry "\n")
3629 (add-text-properties (point-min) (point)
3630 (list 'face 'org-agenda-structure))
3631 (org-agenda-mark-header-line (point-min))
3632 (while (setq d (pop day-numbers))
3633 (if (and (listp d) (eq (car d) :omitted))
3636 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3637 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3638 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3639 (if (and (>= d today)
3644 (insert (make-string 79 ?-) "\n")))
3645 (setq date (calendar-gregorian-from-absolute d))
3647 (setq rtn (and (not emptyp)
3648 (apply 'org-agenda-get-day-entries entry
3650 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3653 (if (stringp org-agenda-format-date)
3654 (format-time-string org-agenda-format-date
3655 (org-time-from-absolute date))
3656 (funcall org-agenda-format-date date))
3658 (put-text-property s (1- (point)) 'face
3659 (org-agenda-get-day-face date))
3660 (put-text-property s (1- (point)) 'org-date-line t)
3661 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3663 (put-text-property s (1- (point)) 'org-today t))
3664 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3665 (put-text-property s (1- (point)) 'day d)))))
3666 (goto-char (point-min))
3667 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3669 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3670 (org-finalize-agenda)
3671 (setq buffer-read-only t)))
3673 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3674 "Return a list of all relevant day numbers from BEG to END buffer positions.
3675 If NO-RANGES is non-nil, include only the start and end dates of a range,
3676 not every single day in the range. If FORCE-TODAY is non-nil, make
3677 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3678 inactive time stamps (those in square brackets) are included.
3679 When EMPTY is non-nil, also include days without any entries."
3681 (if pre-re pre-re "")
3682 (if inactive org-ts-regexp-both org-ts-regexp)))
3683 dates dates1 date day day1 day2 ts1 ts2 pos)
3685 (setq dates (list (org-today))))
3688 (while (re-search-forward re end t)
3689 (setq day (time-to-days (org-time-string-to-time
3690 (substring (match-string 1) 0 10)
3691 (current-buffer) (match-beginning 0))))
3692 (or (memq day dates) (push day dates)))
3695 (while (re-search-forward org-tr-regexp end t)
3696 (setq pos (match-beginning 0))
3697 (setq ts1 (substring (match-string 1) 0 10)
3698 ts2 (substring (match-string 2) 0 10)
3699 day1 (time-to-days (org-time-string-to-time
3700 ts1 (current-buffer) pos))
3701 day2 (time-to-days (org-time-string-to-time
3702 ts2 (current-buffer) pos)))
3703 (while (< (setq day1 (1+ day1)) day2)
3704 (or (memq day1 dates) (push day1 dates)))))
3705 (setq dates (sort dates '<))
3707 (while (setq day (pop dates))
3708 (setq day2 (car dates))
3710 (when (and day2 empty)
3711 (if (or (eq empty t)
3712 (and (numberp empty) (<= (- day2 day) empty)))
3713 (while (< (setq day (1+ day)) day2)
3714 (push (list day) dates1))
3715 (push (cons :omitted (- day2 day)) dates1))))
3716 (setq dates (nreverse dates1)))
3719 ;;; Agenda Daily/Weekly
3721 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3722 "Start day for the agenda view.
3723 Custom commands can set this variable in the options section.")
3724 (defvar org-starting-day nil) ; local variable in the agenda buffer
3725 (defvar org-agenda-current-span nil
3726 "The current span used in the agenda view.") ; local variable in the agenda buffer
3727 (defvar org-arg-loc nil) ; local variable
3729 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3730 "List of types searched for when creating the daily/weekly agenda.
3731 This variable is a list of symbols that controls the types of
3732 items that appear in the daily/weekly agenda. Allowed symbols in this
3735 :timestamp List items containing a date stamp or date range matching
3736 the selected date. This includes sexp entries in
3739 :sexp List entries resulting from plain diary-like sexps.
3741 :deadline List deadline due on that date. When the date is today,
3742 also list any deadlines past due, or due within
3743 `org-deadline-warning-days'. `:deadline' must appear before
3744 `:scheduled' if the setting of
3745 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3748 :scheduled List all items which are scheduled for the given date.
3749 The diary for *today* also contains items which were
3750 scheduled earlier and are not yet marked DONE.
3752 By default, all four types are turned on.
3754 Never set this variable globally using `setq', because then it
3755 will apply to all future agenda commands. Instead, bind it with
3756 `let' to scope it dynamically into the agenda-constructing
3757 command. A good way to set it is through options in
3758 `org-agenda-custom-commands'. For a more flexible (though
3759 somewhat less efficient) way of determining what is included in
3760 the daily/weekly agenda, see `org-agenda-skip-function'.")
3763 (defun org-agenda-list (&optional arg start-day span)
3764 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3765 The view will be for the current day or week, but from the overview buffer
3766 you will be able to go to other days/weeks.
3768 With a numeric prefix argument in an interactive call, the agenda will
3769 span ARG days. Lisp programs should instead specify SPAN to change
3770 the number of days. SPAN defaults to `org-agenda-span'.
3772 START-DAY defaults to TODAY, or to the most recent match for the weekday
3773 given in `org-agenda-start-on-weekday'."
3775 (if (and (integerp arg) (> arg 0))
3776 (setq span arg arg nil))
3777 (org-prepare-agenda "Day/Week")
3778 (setq start-day (or start-day org-agenda-start-day))
3779 (if org-agenda-overriding-arguments
3780 (setq arg (car org-agenda-overriding-arguments)
3781 start-day (nth 1 org-agenda-overriding-arguments)
3782 span (nth 2 org-agenda-overriding-arguments)))
3783 (if (stringp start-day)
3784 ;; Convert to an absolute day number
3785 (setq start-day (time-to-days (org-read-date nil t start-day))))
3786 (setq org-agenda-last-arguments (list arg start-day span))
3787 (org-compile-prefix-format 'agenda)
3788 (org-set-sorting-strategy 'agenda)
3789 (let* ((span (org-agenda-ndays-to-span
3790 (or span org-agenda-ndays org-agenda-span)))
3792 (sd (or start-day today))
3793 (ndays (org-agenda-span-to-ndays span sd))
3794 (org-agenda-start-on-weekday
3796 org-agenda-start-on-weekday))
3797 (thefiles (org-agenda-files nil 'ifmode))
3799 (start (if (or (null org-agenda-start-on-weekday)
3802 (let* ((nt (calendar-day-of-week
3803 (calendar-gregorian-from-absolute sd)))
3804 (n1 org-agenda-start-on-weekday)
3806 (- sd (+ (if (< d 0) 7 0) d)))))
3807 (day-numbers (list start))
3809 (inhibit-redisplay (not debug-on-error))
3810 (org-agenda-show-log-scoped org-agenda-show-log)
3811 s e rtn rtnall file date d start-pos end-pos todayp
3812 clocktable-start clocktable-end filter)
3813 (setq org-agenda-redo-command
3814 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3815 (dotimes (n (1- ndays))
3816 (push (1+ (car day-numbers)) day-numbers))
3817 (setq day-numbers (nreverse day-numbers))
3818 (setq clocktable-start (car day-numbers)
3819 clocktable-end (1+ (or (org-last day-numbers) 0)))
3820 (org-set-local 'org-starting-day (car day-numbers))
3821 (org-set-local 'org-arg-loc arg)
3822 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3823 (unless org-agenda-compact-blocks
3824 (let* ((d1 (car day-numbers))
3825 (d2 (org-last day-numbers))
3826 (w1 (org-days-to-iso-week d1))
3827 (w2 (org-days-to-iso-week d2)))
3829 (if org-agenda-overriding-header
3830 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3831 nil 'face 'org-agenda-structure) "\n")
3832 (insert (org-agenda-span-name span)
3834 (if (< (- d2 d1) 350)
3836 (format " (W%02d)" w1)
3837 (format " (W%02d-W%02d)" w1 w2))
3840 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3842 (org-agenda-mark-header-line s))
3843 (while (setq d (pop day-numbers))
3844 (setq date (calendar-gregorian-from-absolute d)
3846 (if (or (setq todayp (= d today))
3847 (and (not start-pos) (= d sd)))
3848 (setq start-pos (point))
3849 (if (and start-pos (not end-pos))
3850 (setq end-pos (point))))
3851 (setq files thefiles
3853 (while (setq file (pop files))
3855 (org-check-agenda-file file)
3856 (let ((org-agenda-entry-types org-agenda-entry-types))
3857 (unless org-agenda-include-deadlines
3858 (setq org-agenda-entry-types
3859 (delq :deadline org-agenda-entry-types)))
3861 ((memq org-agenda-show-log-scoped '(only clockcheck))
3862 (setq rtn (org-agenda-get-day-entries
3863 file date :closed)))
3864 (org-agenda-show-log-scoped
3865 (setq rtn (apply 'org-agenda-get-day-entries
3867 (append '(:closed) org-agenda-entry-types))))
3869 (setq rtn (apply 'org-agenda-get-day-entries
3871 org-agenda-entry-types)))))
3872 (setq rtnall (append rtnall rtn)))) ;; all entries
3873 (if org-agenda-include-diary
3874 (let ((org-agenda-search-headline-for-time t))
3875 (require 'diary-lib)
3876 (setq rtn (org-get-entries-from-diary date))
3877 (setq rtnall (append rtnall rtn))))
3878 (if (or rtnall org-agenda-show-all-dates)
3880 (setq day-cnt (1+ day-cnt))
3882 (if (stringp org-agenda-format-date)
3883 (format-time-string org-agenda-format-date
3884 (org-time-from-absolute date))
3885 (funcall org-agenda-format-date date))
3887 (put-text-property s (1- (point)) 'face
3888 (org-agenda-get-day-face date))
3889 (put-text-property s (1- (point)) 'org-date-line t)
3890 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3891 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3893 (put-text-property s (1- (point)) 'org-today t))
3894 (if rtnall (insert ;; all entries
3895 (org-finalize-agenda-entries
3896 (org-agenda-add-time-grid-maybe
3897 rtnall ndays todayp))
3899 (put-text-property s (1- (point)) 'day d)
3900 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3901 (when (and org-agenda-clockreport-mode clocktable-start)
3902 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3903 ;; the above line is to ensure the restricted range!
3904 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3906 (setq p (org-plist-delete p :block))
3907 (setq p (plist-put p :tstart clocktable-start))
3908 (setq p (plist-put p :tend clocktable-end))
3909 (setq p (plist-put p :scope 'agenda))
3910 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3911 (setq filter (or org-agenda-tag-filter-while-redo
3912 (get 'org-agenda-tag-filter :preset-filter))))
3913 (setq p (plist-put p :tags (mapconcat (lambda (x)
3914 (if (string-match "[<>=]" x)
3918 (setq tbl (apply 'org-get-clocktable p))
3920 (goto-char (point-min))
3921 (or org-agenda-multi (org-fit-agenda-window))
3922 (unless (and (pos-visible-in-window-p (point-min))
3923 (pos-visible-in-window-p (point-max)))
3924 (goto-char (1- (point-max)))
3926 (if (not (pos-visible-in-window-p (or start-pos 1)))
3928 (goto-char (or start-pos 1))
3930 (goto-char (or start-pos 1))
3931 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3932 (if (eq org-agenda-show-log-scoped 'clockcheck)
3933 (org-agenda-show-clocking-issues))
3934 (org-finalize-agenda)
3935 (setq buffer-read-only t)
3938 (defun org-agenda-ndays-to-span (n)
3939 "Return a span symbol for a span of N days, or N if none matches."
3940 (cond ((symbolp n) n)
3945 (defun org-agenda-span-to-ndays (span start-day)
3946 "Return ndays from SPAN starting at START-DAY."
3947 (cond ((numberp span) span)
3951 (let ((date (calendar-gregorian-from-absolute start-day)))
3952 (calendar-last-day-of-month (car date) (caddr date))))
3954 (let ((date (calendar-gregorian-from-absolute start-day)))
3955 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3957 (defun org-agenda-span-name (span)
3958 "Return a SPAN name."
3962 (capitalize (symbol-name span))
3963 (format "%d days" span))))
3965 ;;; Agenda word search
3967 (defvar org-agenda-search-history nil)
3968 (defvar org-todo-only nil)
3970 (defvar org-search-syntax-table nil
3971 "Special syntax table for org-mode search.
3972 In this table, we have single quotes not as word constituents, to
3973 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3975 (defun org-search-syntax-table ()
3976 (unless org-search-syntax-table
3977 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3978 (modify-syntax-entry ?' "." org-search-syntax-table)
3979 (modify-syntax-entry ?` "." org-search-syntax-table))
3980 org-search-syntax-table)
3982 (defvar org-agenda-last-search-view-search-was-boolean nil)
3985 (defun org-search-view (&optional todo-only string edit-at)
3986 "Show all entries that contain a phrase or words or regular expressions.
3988 With optional prefix argument TODO-ONLY, only consider entries that are
3989 TODO entries. The argument STRING can be used to pass a default search
3990 string into this function. If EDIT-AT is non-nil, it means that the
3991 user should get a chance to edit this string, with cursor at position
3994 The search string can be viewed either as a phrase that should be found as
3995 is, or it can be broken into a number of snippets, each of which must match
3996 in a Boolean way to select an entry. The default depends on the variable
3997 `org-agenda-search-view-always-boolean'.
3998 Even if this is turned off (the default) you can always switch to
3999 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4001 The default is a direct search of the whole phrase, where each space in
4002 the search string can expand to an arbitrary amount of whitespace,
4005 If using a Boolean search, the search string is split on whitespace and
4006 each snippet is searched separately, with logical AND to select an entry.
4007 Words prefixed with a minus must *not* occur in the entry. Words without
4008 a prefix or prefixed with a plus must occur in the entry. Matching is
4009 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4010 match whole words, not parts of a word) if
4011 `org-agenda-search-view-force-full-words' is set (default is nil).
4013 Boolean search snippets enclosed by curly braces are interpreted as
4014 regular expressions that must or (when preceded with \"-\") must not
4015 match in the entry. Snippets enclosed into double quotes will be taken
4016 as a whole, to include whitespace.
4018 - If the search string starts with an asterisk, search only in headlines.
4019 - If (possibly after the leading star) the search string starts with an
4020 exclamation mark, this also means to look at TODO entries only, an effect
4021 that can also be achieved with a prefix argument.
4022 - If (possibly after star and exclamation mark) the search string starts
4023 with a colon, this will mean that the (non-regexp) snippets of the
4024 Boolean search must match as full words.
4026 This command searches the agenda files, and in addition the files listed
4027 in `org-agenda-text-search-extra-files'."
4029 (org-prepare-agenda "SEARCH")
4030 (org-compile-prefix-format 'search)
4031 (org-set-sorting-strategy 'search)
4032 (let* ((props (list 'face nil
4033 'done-face 'org-agenda-done
4034 'org-not-done-regexp org-not-done-regexp
4035 'org-todo-regexp org-todo-regexp
4036 'org-complex-heading-regexp org-complex-heading-regexp
4037 'mouse-face 'highlight
4038 'help-echo (format "mouse-2 or RET jump to location")))
4039 (full-words org-agenda-search-view-force-full-words)
4040 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4041 regexp rtn rtnall files file pos
4042 marker category org-category-pos tags c neg re boolean
4043 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4044 (unless (and (not edit-at)
4046 (string-match "\\S-" string))
4047 (setq string (read-string
4048 (if org-agenda-search-view-always-boolean
4049 "[+-]Word/{Regexp} ...: "
4050 "Phrase, or [+-]Word/{Regexp} ...: ")
4052 ((integerp edit-at) (cons string edit-at))
4054 'org-agenda-search-history)))
4055 (org-set-local 'org-todo-only todo-only)
4056 (setq org-agenda-redo-command
4057 (list 'org-search-view (if todo-only t nil) string
4058 '(if current-prefix-arg 1 nil)))
4059 (setq org-agenda-query-string string)
4061 (if (equal (string-to-char string) ?*)
4063 words (substring string 1))
4064 (setq words string))
4065 (when (equal (string-to-char words) ?!)
4067 words (substring words 1)))
4068 (when (equal (string-to-char words) ?:)
4070 words (substring words 1)))
4071 (if (or org-agenda-search-view-always-boolean
4072 (member (string-to-char words) '(?- ?+ ?\{)))
4074 (setq words (org-split-string words))
4076 (while (setq w (pop words))
4077 (while (and (string-match "\\\\\\'" w) words)
4078 (setq w (concat (substring w 0 -1) " " (pop words))))
4080 (setq words (nreverse www) www nil)
4081 (while (setq w (pop words))
4082 (when (and (string-match "\\`[-+]?{" w)
4083 (not (string-match "}\\'" w)))
4084 (while (and words (not (string-match "}\\'" (car words))))
4085 (setq w (concat w " " (pop words))))
4086 (setq w (concat w " " (pop words))))
4088 (setq words (nreverse www)))
4089 (setq org-agenda-last-search-view-search-was-boolean boolean)
4092 (while (setq w (pop words))
4093 (if (or (equal (substring w 0 1) "\"")
4094 (and (> (length w) 1)
4095 (member (substring w 0 1) '("+" "-"))
4096 (equal (substring w 1 2) "\"")))
4097 (while (and words (not (equal (substring w -1) "\"")))
4098 (setq w (concat w " " (pop words)))))
4099 (and (string-match "\\`\\([-+]?\\)\"" w)
4100 (setq w (replace-match "\\1" nil nil w)))
4101 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4103 (setq words (nreverse wds))))
4106 (setq c (string-to-char w))
4108 (setq neg t w (substring w 1))
4110 (setq neg nil w (substring w 1))
4112 (if (string-match "\\`{.*}\\'" w)
4113 (setq re (substring w 1 -1))
4115 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4116 (setq re (regexp-quote (downcase w)))))
4117 (if neg (push re regexps-) (push re regexps+)))
4119 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4121 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4123 (setq regexp org-outline-regexp-bol)
4124 (setq regexp (pop regexps+))
4125 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4127 (setq files (org-agenda-files nil 'ifmode))
4128 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4129 (pop org-agenda-text-search-extra-files)
4130 (setq files (org-add-archive-files files)))
4131 (setq files (append files org-agenda-text-search-extra-files)
4133 (while (setq file (pop files))
4136 (org-check-agenda-file file)
4137 (setq buffer (if (file-exists-p file)
4138 (org-get-agenda-file-buffer file)
4139 (error "No such file %s" file)))
4141 ;; If file does not exist, make sure an error message is sent
4142 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4144 (with-current-buffer buffer
4145 (with-syntax-table (org-search-syntax-table)
4146 (unless (derived-mode-p 'org-mode)
4147 (error "Agenda file %s is not in `org-mode'" file))
4148 (let ((case-fold-search t))
4151 (if org-agenda-restrict
4152 (narrow-to-region org-agenda-restrict-begin
4153 org-agenda-restrict-end)
4155 (goto-char (point-min))
4156 (unless (or (org-at-heading-p)
4157 (outline-next-heading))
4158 (throw 'nextfile t))
4159 (goto-char (max (point-min) (1- (point))))
4160 (while (re-search-forward regexp nil t)
4161 (org-back-to-heading t)
4162 (skip-chars-forward "* ")
4163 (setq beg (point-at-bol)
4165 end (progn (outline-next-heading) (point)))
4169 (setq str (buffer-substring-no-properties
4171 (if hdl-only (point-at-eol) end)))
4172 (mapc (lambda (wr) (when (string-match wr str)
4173 (goto-char (1- end))
4176 (mapc (lambda (wr) (unless (string-match wr str)
4177 (goto-char (1- end))
4180 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4184 (setq marker (org-agenda-new-marker (point))
4185 category (org-get-category)
4186 org-category-pos (get-text-property (point) 'org-category-position)
4187 tags (org-get-tags-at (point))
4188 txt (org-agenda-format-item
4190 (buffer-substring-no-properties
4191 beg1 (point-at-eol))
4193 (org-add-props txt props
4194 'org-marker marker 'org-hd-marker marker
4195 'org-todo-regexp org-todo-regexp
4196 'org-complex-heading-regexp org-complex-heading-regexp
4197 'priority 1000 'org-category category
4198 'org-category-position org-category-pos
4201 (goto-char (1- end))))))))))
4202 (setq rtn (nreverse ee))
4203 (setq rtnall (append rtnall rtn)))
4204 (if org-agenda-overriding-header
4205 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4206 nil 'face 'org-agenda-structure) "\n")
4207 (insert "Search words: ")
4208 (add-text-properties (point-min) (1- (point))
4209 (list 'face 'org-agenda-structure))
4211 (insert string "\n")
4212 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4214 (unless org-agenda-multi
4215 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4216 (add-text-properties pos (1- (point))
4217 (list 'face 'org-agenda-structure))))
4218 (org-agenda-mark-header-line (point-min))
4220 (insert (org-finalize-agenda-entries rtnall) "\n"))
4221 (goto-char (point-min))
4222 (or org-agenda-multi (org-fit-agenda-window))
4223 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4224 (org-finalize-agenda)
4225 (setq buffer-read-only t)))
4227 ;;; Agenda TODO list
4229 (defvar org-select-this-todo-keyword nil)
4230 (defvar org-last-arg nil)
4233 (defun org-todo-list (arg)
4234 "Show all (not done) TODO entries from all agenda file in a single list.
4235 The prefix arg can be used to select a specific TODO keyword and limit
4236 the list to these. When using \\[universal-argument], you will be prompted
4237 for a keyword. A numeric prefix directly selects the Nth keyword in
4238 `org-todo-keywords-1'."
4240 (org-prepare-agenda "TODO")
4241 (org-compile-prefix-format 'todo)
4242 (org-set-sorting-strategy 'todo)
4243 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4244 (let* ((today (org-today))
4245 (date (calendar-gregorian-from-absolute today))
4246 (kwds org-todo-keywords-for-agenda)
4247 (completion-ignore-case t)
4248 (org-select-this-todo-keyword
4249 (if (stringp arg) arg
4250 (and arg (integerp arg) (> arg 0)
4251 (nth (1- arg) kwds))))
4252 rtn rtnall files file pos)
4253 (when (equal arg '(4))
4254 (setq org-select-this-todo-keyword
4255 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4256 (mapcar 'list kwds) nil nil)))
4257 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4258 (org-set-local 'org-last-arg arg)
4259 (setq org-agenda-redo-command
4260 '(org-todo-list (or current-prefix-arg org-last-arg)))
4261 (setq files (org-agenda-files nil 'ifmode)
4263 (while (setq file (pop files))
4265 (org-check-agenda-file file)
4266 (setq rtn (org-agenda-get-day-entries file date :todo))
4267 (setq rtnall (append rtnall rtn))))
4268 (if org-agenda-overriding-header
4269 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4270 nil 'face 'org-agenda-structure) "\n")
4271 (insert "Global list of TODO items of type: ")
4272 (add-text-properties (point-min) (1- (point))
4273 (list 'face 'org-agenda-structure
4276 (or org-select-this-todo-keyword "ALL"))))
4277 (org-agenda-mark-header-line (point-min))
4279 (insert (or org-select-this-todo-keyword "ALL") "\n")
4280 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4282 (unless org-agenda-multi
4283 (insert "Available with `N r': (0)ALL")
4286 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4287 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4292 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4293 (org-agenda-mark-header-line (point-min))
4295 (insert (org-finalize-agenda-entries rtnall) "\n"))
4296 (goto-char (point-min))
4297 (or org-agenda-multi (org-fit-agenda-window))
4298 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4299 (org-finalize-agenda)
4300 (setq buffer-read-only t)))
4302 ;;; Agenda tags match
4305 (defun org-tags-view (&optional todo-only match)
4306 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4307 The prefix arg TODO-ONLY limits the search to TODO entries."
4309 (let* ((org-tags-match-list-sublevels
4310 org-tags-match-list-sublevels)
4311 (completion-ignore-case t)
4312 rtn rtnall files file pos matcher
4314 (when (and (stringp match) (not (string-match "\\S-" match)))
4316 (setq matcher (org-make-tags-matcher match)
4317 match (car matcher) matcher (cdr matcher))
4318 (org-prepare-agenda (concat "TAGS " match))
4319 (org-compile-prefix-format 'tags)
4320 (org-set-sorting-strategy 'tags)
4321 (setq org-agenda-query-string match)
4322 (setq org-agenda-redo-command
4323 (list 'org-tags-view (list 'quote todo-only)
4324 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4325 (setq files (org-agenda-files nil 'ifmode)
4327 (while (setq file (pop files))
4329 (org-check-agenda-file file)
4330 (setq buffer (if (file-exists-p file)
4331 (org-get-agenda-file-buffer file)
4332 (error "No such file %s" file)))
4334 ;; If file does not exist, error message to agenda
4336 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4337 rtnall (append rtnall rtn))
4338 (with-current-buffer buffer
4339 (unless (derived-mode-p 'org-mode)
4340 (error "Agenda file %s is not in `org-mode'" file))
4343 (if org-agenda-restrict
4344 (narrow-to-region org-agenda-restrict-begin
4345 org-agenda-restrict-end)
4347 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4348 (setq rtnall (append rtnall rtn))))))))
4349 (if org-agenda-overriding-header
4350 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4351 nil 'face 'org-agenda-structure) "\n")
4352 (insert "Headlines with TAGS match: ")
4353 (add-text-properties (point-min) (1- (point))
4354 (list 'face 'org-agenda-structure
4356 (concat "Match: " match)))
4359 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4361 (unless org-agenda-multi
4362 (insert "Press `C-u r' to search again with new search string\n"))
4363 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4364 (org-agenda-mark-header-line (point-min))
4366 (insert (org-finalize-agenda-entries rtnall) "\n"))
4367 (goto-char (point-min))
4368 (or org-agenda-multi (org-fit-agenda-window))
4369 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4370 (org-finalize-agenda)
4371 (setq buffer-read-only t)))
4373 ;;; Agenda Finding stuck projects
4375 (defvar org-agenda-skip-regexp nil
4376 "Regular expression used in skipping subtrees for the agenda.
4377 This is basically a temporary global variable that can be set and then
4378 used by user-defined selections using `org-agenda-skip-function'.")
4380 (defvar org-agenda-overriding-header nil
4381 "When set during agenda, todo and tags searches it replaces the header.
4382 This variable should not be set directly, but custom commands can bind it
4383 in the options section.")
4385 (defun org-agenda-skip-entry-when-regexp-matches ()
4386 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4387 If yes, it returns the end position of this entry, causing agenda commands
4388 to skip the entry but continuing the search in the subtree. This is a
4389 function that can be put into `org-agenda-skip-function' for the duration
4391 (let ((end (save-excursion (org-end-of-subtree t)))
4394 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4397 (defun org-agenda-skip-subtree-when-regexp-matches ()
4398 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4399 If yes, it returns the end position of this tree, causing agenda commands
4400 to skip this subtree. This is a function that can be put into
4401 `org-agenda-skip-function' for the duration of a command."
4402 (let ((end (save-excursion (org-end-of-subtree t)))
4405 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4408 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4409 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4410 If yes, it returns the end position of the current entry (NOT the tree),
4411 causing agenda commands to skip the entry but continuing the search in
4412 the subtree. This is a function that can be put into
4413 `org-agenda-skip-function' for the duration of a command. An important
4414 use of this function is for the stuck project list."
4415 (let ((end (save-excursion (org-end-of-subtree t)))
4416 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4419 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4420 (and skip entry-end)))
4422 (defun org-agenda-skip-entry-if (&rest conditions)
4423 "Skip entry if any of CONDITIONS is true.
4424 See `org-agenda-skip-if' for details."
4425 (org-agenda-skip-if nil conditions))
4427 (defun org-agenda-skip-subtree-if (&rest conditions)
4428 "Skip entry if any of CONDITIONS is true.
4429 See `org-agenda-skip-if' for details."
4430 (org-agenda-skip-if t conditions))
4432 (defun org-agenda-skip-if (subtree conditions)
4433 "Checks current entity for CONDITIONS.
4434 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4435 the entry (i.e. the text before the next heading) is checked.
4437 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4438 from different tests. Valid conditions are:
4440 scheduled Check if there is a scheduled cookie
4441 notscheduled Check if there is no scheduled cookie
4442 deadline Check if there is a deadline
4443 notdeadline Check if there is no deadline
4444 timestamp Check if there is a timestamp (also deadline or scheduled)
4445 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4446 regexp Check if regexp matches
4447 notregexp Check if regexp does not match.
4448 todo Check if TODO keyword matches
4449 nottodo Check if TODO keyword does not match
4451 The regexp is taken from the conditions list, it must come right after
4452 the `regexp' or `notregexp' element.
4454 `todo' and `nottodo' accept as an argument a list of todo
4455 keywords, which may include \"*\" to match any todo keyword.
4457 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4459 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4461 Instead of a list, a keyword class may be given. For example:
4463 (org-agenda-skip-entry-if 'nottodo 'done)
4465 would skip entries that haven't been marked with any of \"DONE\"
4466 keywords. Possible classes are: `todo', `done', `any'.
4468 If any of these conditions is met, this function returns the end point of
4469 the entity, causing the search to continue from there. This is a function
4470 that can be put into `org-agenda-skip-function' for the duration of a command."
4472 (org-back-to-heading t)
4475 (progn (org-end-of-subtree t) (point))
4476 (progn (outline-next-heading) (1- (point)))))
4480 (and (memq 'scheduled conditions)
4481 (re-search-forward org-scheduled-time-regexp end t))
4482 (and (memq 'notscheduled conditions)
4483 (not (re-search-forward org-scheduled-time-regexp end t)))
4484 (and (memq 'deadline conditions)
4485 (re-search-forward org-deadline-time-regexp end t))
4486 (and (memq 'notdeadline conditions)
4487 (not (re-search-forward org-deadline-time-regexp end t)))
4488 (and (memq 'timestamp conditions)
4489 (re-search-forward org-ts-regexp end t))
4490 (and (memq 'nottimestamp conditions)
4491 (not (re-search-forward org-ts-regexp end t)))
4492 (and (setq m (memq 'regexp conditions))
4494 (re-search-forward (nth 1 m) end t))
4495 (and (setq m (memq 'notregexp conditions))
4497 (not (re-search-forward (nth 1 m) end t)))
4499 (setq m (memq 'nottodo conditions))
4500 (setq m (memq 'todo-unblocked conditions))
4501 (setq m (memq 'nottodo-unblocked conditions))
4502 (setq m (memq 'todo conditions)))
4503 (org-agenda-skip-if-todo m end)))
4506 (defun org-agenda-skip-if-todo (args end)
4507 "Helper function for `org-agenda-skip-if', do not use it directly.
4508 ARGS is a list with first element either `todo', `nottodo',
4509 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4510 a list of TODO keywords, or a state symbol `todo' or `done' or
4512 (let ((kw (car args))
4518 ((listp arg) ;; list of keywords
4519 (if (member "*" arg)
4520 (mapcar 'substring-no-properties org-todo-keywords-1)
4522 ((symbolp arg) ;; keyword class name
4525 (org-delete-all org-done-keywords
4526 (mapcar 'substring-no-properties
4527 org-todo-keywords-1)))
4528 ((eq arg 'done) org-done-keywords)
4530 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4532 (concat "^\\*+[ \t]+\\<\\("
4533 (mapconcat 'identity todo-wds "\\|")
4536 ((eq kw 'todo) (re-search-forward todo-re end t))
4537 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4538 ((eq kw 'todo-unblocked)
4540 (while (re-search-forward todo-re end t)
4541 (or (org-entry-blocked-p) (throw 'unblocked t)))
4543 ((eq kw 'nottodo-unblocked)
4545 (while (re-search-forward todo-re end t)
4546 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4551 (defun org-agenda-list-stuck-projects (&rest ignore)
4552 "Create agenda view for projects that are stuck.
4553 Stuck projects are project that have no next actions. For the definitions
4554 of what a project is and how to check if it stuck, customize the variable
4555 `org-stuck-projects'."
4557 (let* ((org-agenda-skip-function
4558 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4559 ;; We could have used org-agenda-skip-if here.
4560 (org-agenda-overriding-header
4561 (or org-agenda-overriding-header "List of stuck projects: "))
4562 (matcher (nth 0 org-stuck-projects))
4563 (todo (nth 1 org-stuck-projects))
4564 (todo-wds (if (member "*" todo)
4566 (org-prepare-agenda-buffers (org-agenda-files
4569 org-done-keywords-for-agenda
4570 (copy-sequence org-todo-keywords-for-agenda)))
4572 (todo-re (concat "^\\*+[ \t]+\\("
4573 (mapconcat 'identity todo-wds "\\|")
4575 (tags (nth 2 org-stuck-projects))
4576 (tags-re (if (member "*" tags)
4577 (concat org-outline-regexp-bol
4578 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4580 (concat org-outline-regexp-bol
4582 (mapconcat 'identity tags "\\|")
4583 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4584 (gen-re (nth 3 org-stuck-projects))
4590 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4592 (setq org-agenda-skip-regexp
4594 (mapconcat 'identity re-list "\\|")
4595 (error "No information how to identify unstuck projects")))
4596 (org-tags-view nil matcher)
4597 (with-current-buffer org-agenda-buffer-name
4598 (setq org-agenda-redo-command
4599 '(org-agenda-list-stuck-projects
4600 (or current-prefix-arg org-last-arg))))))
4602 ;;; Diary integration
4604 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4605 (defvar diary-list-entries-hook)
4606 (defvar diary-time-regexp)
4607 (defun org-get-entries-from-diary (date)
4608 "Get the (Emacs Calendar) diary entries for DATE."
4609 (require 'diary-lib)
4610 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4611 (diary-display-hook '(fancy-diary-display))
4612 (diary-display-function 'fancy-diary-display)
4614 (diary-list-entries-hook
4615 (cons 'org-diary-default-entry diary-list-entries-hook))
4616 (diary-file-name-prefix-function nil) ; turn this feature off
4617 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4619 (org-disable-agenda-to-diary t))
4621 (save-window-excursion
4622 (funcall (if (fboundp 'diary-list-entries)
4623 'diary-list-entries 'list-diary-entries)
4625 (if (not (get-buffer diary-fancy-buffer))
4627 (with-current-buffer diary-fancy-buffer
4628 (setq buffer-read-only nil)
4629 (if (zerop (buffer-size))
4632 ;; Omit the date and other unnecessary stuff
4633 (org-agenda-cleanup-fancy-diary)
4634 ;; Add prefix to each line and extend the text properties
4635 (if (zerop (buffer-size))
4637 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4640 (insert entries) (goto-char (point-min))
4641 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4642 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4643 (replace-match (concat "; " (match-string 1)))))
4645 (set-buffer-modified-p nil)
4646 (kill-buffer diary-fancy-buffer)))
4648 (setq entries (org-split-string entries "\n"))
4652 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4653 ;; Extend the text properties to the beginning of the line
4654 (org-add-props x (text-properties-at (1- (length x)) x)
4655 'type "diary" 'date date 'face 'org-agenda-diary))
4658 (defvar org-agenda-cleanup-fancy-diary-hook nil
4659 "Hook run when the fancy diary buffer is cleaned up.")
4661 (defun org-agenda-cleanup-fancy-diary ()
4662 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4663 This gets rid of the date, the underline under the date, and
4664 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4665 date. It also removes lines that contain only whitespace."
4666 (goto-char (point-min))
4667 (if (looking-at ".*?:[ \t]*")
4670 (re-search-forward "\n=+$" nil t)
4672 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4673 (re-search-forward "\n=+$" nil t)
4674 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4675 (goto-char (point-min))
4676 (while (re-search-forward "^ +\n" nil t)
4678 (goto-char (point-min))
4679 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4681 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4683 ;; Make sure entries from the diary have the right text properties.
4684 (eval-after-load "diary-lib"
4685 '(if (boundp 'diary-modify-entry-list-string-function)
4686 ;; We can rely on the hook, nothing to do
4688 ;; Hook not available, must use advice to make this work
4689 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4690 "Make the position visible."
4691 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4694 (setq string (org-modify-diary-entry-string string))))))
4696 (defun org-modify-diary-entry-string (string)
4697 "Add text properties to string, allowing org-mode to act on it."
4698 (org-add-props string nil
4699 'mouse-face 'highlight
4700 'help-echo (if buffer-file-name
4701 (format "mouse-2 or RET jump to diary file %s"
4702 (abbreviate-file-name buffer-file-name))
4704 'org-agenda-diary-link t
4705 'org-marker (org-agenda-new-marker (point-at-bol))))
4707 (defun org-diary-default-entry ()
4708 "Add a dummy entry to the diary.
4709 Needed to avoid empty dates which mess up holiday display."
4710 ;; Catch the error if dealing with the new add-to-diary-alist
4711 (when org-disable-agenda-to-diary
4713 (org-add-to-diary-list original-date "Org-mode dummy" "")
4715 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4717 (defun org-add-to-diary-list (&rest args)
4718 (if (fboundp 'diary-add-to-list)
4719 (apply 'diary-add-to-list args)
4720 (apply 'add-to-diary-list args)))
4722 (defvar org-diary-last-run-time nil)
4725 (defun org-diary (&rest args)
4726 "Return diary information from org-files.
4727 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4728 It accesses org files and extracts information from those files to be
4729 listed in the diary. The function accepts arguments specifying what
4730 items should be listed. For a list of arguments allowed here, see the
4731 variable `org-agenda-entry-types'.
4733 The call in the diary file should look like this:
4735 &%%(org-diary) ~/path/to/some/orgfile.org
4737 Use a separate line for each org file to check. Or, if you omit the file name,
4738 all files listed in `org-agenda-files' will be checked automatically:
4742 If you don't give any arguments (as in the example above), the default
4743 arguments (:deadline :scheduled :timestamp :sexp) are used.
4744 So the example above may also be written as
4746 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4748 The function expects the lisp variables `entry' and `date' to be provided
4749 by the caller, because this is how the calendar works. Don't use this
4750 function from a program - use `org-agenda-get-day-entries' instead."
4751 (when (> (- (org-float-time)
4752 org-agenda-last-marker-time)
4754 ;; I am not sure if this works with sticky agendas, because the marker
4755 ;; list is then no longer a global variable.
4756 (org-agenda-reset-markers))
4757 ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
4758 (when (buffer-live-p org-agenda-buffer)
4759 (org-compile-prefix-format 'agenda))
4760 (org-set-sorting-strategy 'agenda)
4761 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4762 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4764 (org-agenda-files t)))
4765 (time (org-float-time))
4767 (when (or (not org-diary-last-run-time)
4769 org-diary-last-run-time)
4771 (org-prepare-agenda-buffers files))
4772 (setq org-diary-last-run-time time)
4773 ;; If this is called during org-agenda, don't return any entries to
4774 ;; the calendar. Org Agenda will list these entries itself.
4775 (if org-disable-agenda-to-diary (setq files nil))
4776 (while (setq file (pop files))
4777 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4778 (setq results (append results rtn)))
4780 (concat (org-finalize-agenda-entries results) "\n"))))
4782 ;;; Agenda entry finders
4784 (defun org-agenda-get-day-entries (file date &rest args)
4785 "Does the work for `org-diary' and `org-agenda'.
4786 FILE is the path to a file to be checked for entries. DATE is date like
4787 the one returned by `calendar-current-date'. ARGS are symbols indicating
4788 which kind of entries should be extracted. For details about these, see
4789 the documentation of `org-diary'."
4790 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4791 (let* ((org-startup-folded nil)
4792 (org-startup-align-all-tables nil)
4793 (buffer (if (file-exists-p file)
4794 (org-get-agenda-file-buffer file)
4795 (error "No such file %s" file)))
4796 arg results rtn deadline-results)
4798 ;; If file does not exist, make sure an error message ends up in diary
4799 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4800 (with-current-buffer buffer
4801 (unless (derived-mode-p 'org-mode)
4802 (error "Agenda file %s is not in `org-mode'" file))
4803 (let ((case-fold-search nil))
4806 (if org-agenda-restrict
4807 (narrow-to-region org-agenda-restrict-begin
4808 org-agenda-restrict-end)
4810 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4811 (while (setq arg (pop args))
4813 ((and (eq arg :todo)
4814 (equal date (calendar-gregorian-from-absolute
4816 (setq rtn (org-agenda-get-todos))
4817 (setq results (append results rtn)))
4818 ((eq arg :timestamp)
4819 (setq rtn (org-agenda-get-blocks))
4820 (setq results (append results rtn))
4821 (setq rtn (org-agenda-get-timestamps deadline-results))
4822 (setq results (append results rtn)))
4824 (setq rtn (org-agenda-get-sexps))
4825 (setq results (append results rtn)))
4826 ((eq arg :scheduled)
4827 (setq rtn (org-agenda-get-scheduled deadline-results))
4828 (setq results (append results rtn)))
4830 (setq rtn (org-agenda-get-progress))
4831 (setq results (append results rtn)))
4833 (setq rtn (org-agenda-get-deadlines))
4834 (setq deadline-results (copy-sequence rtn))
4835 (setq results (append results rtn))))))))
4838 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4839 (defun org-agenda-get-todos ()
4840 "Return the TODO information for agenda display."
4841 (let* ((props (list 'face nil
4842 'done-face 'org-agenda-done
4843 'org-not-done-regexp org-not-done-regexp
4844 'org-todo-regexp org-todo-regexp
4845 'org-complex-heading-regexp org-complex-heading-regexp
4846 'mouse-face 'highlight
4848 (format "mouse-2 or RET jump to org file %s"
4849 (abbreviate-file-name buffer-file-name))))
4850 (regexp (format org-heading-keyword-regexp-format
4852 ((and org-select-this-todo-keyword
4853 (equal org-select-this-todo-keyword "*"))
4855 (org-select-this-todo-keyword
4857 (mapconcat 'identity
4859 org-select-this-todo-keyword
4862 (t org-not-done-regexp))))
4863 marker priority category org-category-pos tags todo-state
4865 (goto-char (point-min))
4866 (while (re-search-forward regexp nil t)
4871 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4872 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4873 (goto-char (1+ beg))
4874 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4876 (goto-char (match-beginning 2))
4877 (setq marker (org-agenda-new-marker (match-beginning 0))
4878 category (org-get-category)
4879 org-category-pos (get-text-property (point) 'org-category-position)
4881 (buffer-substring (match-beginning 2) (match-end 0)))
4882 tags (org-get-tags-at (point))
4883 txt (org-agenda-format-item "" txt category tags)
4884 priority (1+ (org-get-priority txt))
4885 todo-state (org-get-todo-state))
4886 (org-add-props txt props
4887 'org-marker marker 'org-hd-marker marker
4888 'priority priority 'org-category category
4889 'org-category-position org-category-pos
4890 'type "todo" 'todo-state todo-state)
4892 (if org-agenda-todo-list-sublevels
4893 (goto-char (match-end 2))
4894 (org-end-of-subtree 'invisible))))
4897 (defun org-agenda-todo-custom-ignore-p (time n)
4898 "Check whether timestamp is farther away then n number of days.
4899 This function is invoked if `org-agenda-todo-ignore-deadlines',
4900 `org-agenda-todo-ignore-scheduled' or
4901 `org-agenda-todo-ignore-timestamp' is set to an integer."
4902 (let ((days (org-days-to-time time)))
4908 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4910 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4911 (when (or org-agenda-todo-ignore-with-date
4912 org-agenda-todo-ignore-scheduled
4913 org-agenda-todo-ignore-deadlines
4914 org-agenda-todo-ignore-timestamp)
4915 (setq end (or end (save-excursion (outline-next-heading) (point))))
4917 (or (and org-agenda-todo-ignore-with-date
4918 (re-search-forward org-ts-regexp end t))
4919 (and org-agenda-todo-ignore-scheduled
4920 (re-search-forward org-scheduled-time-regexp end t)
4922 ((eq org-agenda-todo-ignore-scheduled 'future)
4923 (> (org-days-to-time (match-string 1)) 0))
4924 ((eq org-agenda-todo-ignore-scheduled 'past)
4925 (<= (org-days-to-time (match-string 1)) 0))
4926 ((numberp org-agenda-todo-ignore-scheduled)
4927 (org-agenda-todo-custom-ignore-p
4928 (match-string 1) org-agenda-todo-ignore-scheduled))
4930 (and org-agenda-todo-ignore-deadlines
4931 (re-search-forward org-deadline-time-regexp end t)
4933 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4934 ((eq org-agenda-todo-ignore-deadlines 'far)
4935 (not (org-deadline-close (match-string 1))))
4936 ((eq org-agenda-todo-ignore-deadlines 'future)
4937 (> (org-days-to-time (match-string 1)) 0))
4938 ((eq org-agenda-todo-ignore-deadlines 'past)
4939 (<= (org-days-to-time (match-string 1)) 0))
4940 ((numberp org-agenda-todo-ignore-deadlines)
4941 (org-agenda-todo-custom-ignore-p
4942 (match-string 1) org-agenda-todo-ignore-deadlines))
4943 (t (org-deadline-close (match-string 1)))))
4944 (and org-agenda-todo-ignore-timestamp
4945 (let ((buffer (current-buffer))
4948 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4950 ;; Copy current buffer into a temporary one
4952 (insert-buffer-substring buffer start end)
4953 (goto-char (point-min))
4954 ;; Delete SCHEDULED and DEADLINE items
4955 (while (re-search-forward regexp end t)
4956 (delete-region (match-beginning 0) (match-end 0)))
4957 (goto-char (point-min))
4958 ;; No search for timestamp left
4959 (when (re-search-forward org-ts-regexp nil t)
4961 ((eq org-agenda-todo-ignore-timestamp 'future)
4962 (> (org-days-to-time (match-string 1)) 0))
4963 ((eq org-agenda-todo-ignore-timestamp 'past)
4964 (<= (org-days-to-time (match-string 1)) 0))
4965 ((numberp org-agenda-todo-ignore-timestamp)
4966 (org-agenda-todo-custom-ignore-p
4967 (match-string 1) org-agenda-todo-ignore-timestamp))
4970 (defconst org-agenda-no-heading-message
4971 "No heading for this item in buffer or region.")
4973 (defun org-agenda-get-timestamps (&optional deadline-results)
4974 "Return the date stamp information for agenda display."
4975 (let* ((props (list 'face 'org-agenda-calendar-event
4976 'org-not-done-regexp org-not-done-regexp
4977 'org-todo-regexp org-todo-regexp
4978 'org-complex-heading-regexp org-complex-heading-regexp
4979 'mouse-face 'highlight
4981 (format "mouse-2 or RET jump to org file %s"
4982 (abbreviate-file-name buffer-file-name))))
4983 (d1 (calendar-absolute-from-gregorian date))
4985 (deadline-position-alist
4986 (mapcar (lambda (a) (and (setq mm (get-text-property
4987 0 'org-hd-marker a))
4988 (cons (marker-position mm) a)))
4990 (remove-re org-ts-regexp)
4993 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4997 (car org-time-stamp-formats)
4998 (apply 'encode-time ; DATE bound by calendar
4999 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5001 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5002 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5003 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5004 donep tmp priority category org-category-pos ee txt timestr tags
5005 b0 b3 e3 head todo-state end-of-match show-all)
5006 (goto-char (point-min))
5007 (while (setq end-of-match (re-search-forward regexp nil t))
5008 (setq b0 (match-beginning 0)
5009 b3 (match-beginning 3) e3 (match-end 3)
5010 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5011 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5013 org-agenda-repeating-timestamp-show-all)))
5015 (and (org-at-date-range-p) (throw :skip nil))
5017 (if (and (match-end 1)
5018 (not (= d1 (org-time-string-to-absolute
5019 (match-string 1) d1 nil show-all
5020 (current-buffer) b0))))
5023 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5025 (setq tmp (buffer-substring (max (point-min)
5026 (- b0 org-ds-keyword-length))
5028 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5029 inactivep (= (char-after b0) ?\[)
5030 deadlinep (string-match org-deadline-regexp tmp)
5031 scheduledp (string-match org-scheduled-regexp tmp)
5032 closedp (and org-agenda-include-inactive-timestamps
5033 (string-match org-closed-string tmp))
5034 clockp (and org-agenda-include-inactive-timestamps
5035 (or (string-match org-clock-string tmp)
5036 (string-match "]-+\\'" tmp)))
5037 donep (member todo-state org-done-keywords))
5038 (if (or scheduledp deadlinep closedp clockp
5039 (and donep org-agenda-skip-timestamp-if-done))
5041 (if (string-match ">" timestr)
5042 ;; substring should only run to end of time stamp
5043 (setq timestr (substring timestr 0 (match-end 0))))
5044 (setq marker (org-agenda-new-marker b0)
5045 category (org-get-category b0)
5046 org-category-pos (get-text-property b0 'org-category-position))
5048 (if (not (re-search-backward org-outline-regexp-bol nil t))
5049 (setq txt org-agenda-no-heading-message)
5050 (goto-char (match-beginning 0))
5051 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5052 (assoc (point) deadline-position-alist))
5054 (setq hdmarker (org-agenda-new-marker)
5055 tags (org-get-tags-at))
5056 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5057 (setq head (or (match-string 1) ""))
5058 (setq txt (org-agenda-format-item
5059 (if inactivep org-agenda-inactive-leader nil)
5060 head category tags timestr
5062 (setq priority (org-get-priority txt))
5063 (org-add-props txt props
5064 'org-marker marker 'org-hd-marker hdmarker)
5065 (org-add-props txt nil 'priority priority
5066 'org-category category 'date date
5067 'org-category-position org-category-pos
5068 'todo-state todo-state
5071 (if org-agenda-skip-additional-timestamps-same-entry
5072 (outline-next-heading)
5073 (goto-char end-of-match))))
5076 (defun org-agenda-get-sexps ()
5077 "Return the sexp information for agenda display."
5078 (require 'diary-lib)
5079 (let* ((props (list 'face 'org-agenda-calendar-sexp
5080 'mouse-face 'highlight
5082 (format "mouse-2 or RET jump to org file %s"
5083 (abbreviate-file-name buffer-file-name))))
5085 marker category extra org-category-pos ee txt tags entry
5086 result beg b sexp sexp-entry todo-state)
5087 (goto-char (point-min))
5088 (while (re-search-forward regexp nil t)
5091 (setq beg (match-beginning 0))
5092 (goto-char (1- (match-end 0)))
5095 (setq sexp (buffer-substring b (point)))
5096 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5097 (org-trim (match-string 1))
5099 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5101 (setq marker (org-agenda-new-marker beg)
5102 category (org-get-category beg)
5103 org-category-pos (get-text-property beg 'org-category-position)
5104 todo-state (org-get-todo-state))
5106 (dolist (r (if (stringp result)
5108 result)) ;; we expect a list here
5109 (when (and org-agenda-diary-sexp-prefix
5110 (string-match org-agenda-diary-sexp-prefix r))
5111 (setq extra (match-string 0 r)
5112 r (replace-match "" nil nil r)))
5113 (if (string-match "\\S-" r)
5115 (setq txt "SEXP entry returned empty string"))
5117 (setq txt (org-agenda-format-item
5118 extra txt category tags 'time))
5119 (org-add-props txt props 'org-marker marker)
5120 (org-add-props txt nil
5121 'org-category category 'date date 'todo-state todo-state
5122 'org-category-position org-category-pos
5127 ;; Calendar sanity: define some functions that are independent of
5128 ;; `calendar-date-style'.
5129 ;; Normally I would like to use ISO format when calling the diary functions,
5130 ;; but to make sure we still have Emacs 22 compatibility we bind
5131 ;; also `european-calendar-style' and use european format
5132 (defun org-anniversary (year month day &optional mark)
5133 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5135 (let ((calendar-date-style 'european) (european-calendar-style t))
5136 (diary-anniversary day month year mark))))
5137 (defun org-cyclic (N year month day &optional mark)
5138 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5140 (let ((calendar-date-style 'european) (european-calendar-style t))
5141 (diary-cyclic N day month year mark))))
5142 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5143 "Like `diary-block', but with fixed (ISO) order of arguments."
5145 (let ((calendar-date-style 'european) (european-calendar-style t))
5146 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5147 (defun org-date (year month day &optional mark)
5148 "Like `diary-date', but with fixed (ISO) order of arguments."
5150 (let ((calendar-date-style 'european) (european-calendar-style t))
5151 (diary-date day month year mark))))
5152 (defalias 'org-float 'diary-float)
5154 ;; Define the` org-class' function
5155 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5156 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5157 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5158 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5159 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5160 `holidays', then any date that is known by the Emacs calendar to be a
5161 holiday will also be skipped."
5162 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5163 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5164 (d (calendar-absolute-from-gregorian date)))
5168 (= (calendar-day-of-week date) dayname)
5169 (or (not skip-weeks)
5172 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5173 (not (and (memq 'holidays skip-weeks)
5174 (calendar-check-holidays date)))
5177 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5178 "Like `org-class', but honor `calendar-date-style'.
5179 The order of the first 2 times 3 arguments depends on the variable
5180 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5181 So for American calendars, give this as MONTH DAY YEAR, for European as
5182 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5183 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5184 is any number of ISO weeks in the block period for which the item should
5187 This function is here only for backward compatibility and it is deprecated,
5188 please use `org-class' instead."
5189 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5190 (date2 (org-order-calendar-date-args m2 d2 y2)))
5192 (nth 2 date1) (car date1) (nth 1 date1)
5193 (nth 2 date2) (car date2) (nth 1 date2)
5194 dayname skip-weeks)))
5195 (make-obsolete 'org-diary-class 'org-class "")
5197 (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
5198 (defalias 'org-get-closed 'org-agenda-get-progress)
5199 (defun org-agenda-get-progress ()
5200 "Return the logged TODO entries for agenda display."
5201 (let* ((props (list 'mouse-face 'highlight
5202 'org-not-done-regexp org-not-done-regexp
5203 'org-todo-regexp org-todo-regexp
5204 'org-complex-heading-regexp org-complex-heading-regexp
5206 (format "mouse-2 or RET jump to org file %s"
5207 (abbreviate-file-name buffer-file-name))))
5208 (items (if (consp org-agenda-show-log-scoped)
5209 org-agenda-show-log-scoped
5210 (if (eq org-agenda-show-log-scoped 'clockcheck)
5212 org-agenda-log-mode-items)))
5216 (if (memq 'closed items) (concat "\\<" org-closed-string))
5217 (if (memq 'clock items) (concat "\\<" org-clock-string))
5218 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5219 (parts-re (if parts (mapconcat 'identity parts "\\|")
5220 (error "`org-agenda-log-mode-items' is empty")))
5222 "\\(" parts-re "\\)"
5227 (car org-time-stamp-formats)
5228 (apply 'encode-time ; DATE bound by calendar
5229 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5231 (org-agenda-search-headline-for-time nil)
5232 marker hdmarker priority category org-category-pos tags closedp
5233 statep clockp state ee txt extra timestr rest clocked)
5234 (goto-char (point-min))
5235 (while (re-search-forward regexp nil t)
5238 (setq marker (org-agenda-new-marker (match-beginning 0))
5239 closedp (equal (match-string 1) org-closed-string)
5240 statep (equal (string-to-char (match-string 1)) ?-)
5241 clockp (not (or closedp statep))
5242 state (and statep (match-string 2))
5243 category (org-get-category (match-beginning 0))
5244 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5245 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5246 (when (string-match "\\]" timestr)
5247 ;; substring should only run to end of time stamp
5248 (setq rest (substring timestr (match-end 0))
5249 timestr (substring timestr 0 (match-end 0)))
5250 (if (and (not closedp) (not statep)
5251 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5253 (progn (setq timestr (concat (substring timestr 0 -1)
5254 "-" (match-string 1 rest) "]"))
5255 (setq clocked (match-string 2 rest)))
5256 (setq clocked "-")))
5260 ((not org-agenda-log-mode-add-notes) nil)
5262 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5265 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5266 (match-string 1)))))
5267 (if (not (re-search-backward org-outline-regexp-bol nil t))
5268 (setq txt org-agenda-no-heading-message)
5269 (goto-char (match-beginning 0))
5270 (setq hdmarker (org-agenda-new-marker)
5271 tags (org-get-tags-at))
5272 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5273 (setq txt (match-string 1))
5275 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5276 (setq txt (concat (substring txt 0 (match-beginning 1))
5277 " - " extra " " (match-string 2 txt)))
5278 (setq txt (concat txt " - " extra))))
5279 (setq txt (org-agenda-format-item
5281 (closedp "Closed: ")
5282 (statep (concat "State: (" state ")"))
5283 (t (concat "Clocked: (" clocked ")")))
5284 txt category tags timestr)))
5285 (setq priority 100000)
5286 (org-add-props txt props
5287 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5288 'priority priority 'org-category category
5289 'org-category-position org-category-pos
5290 'type "closed" 'date date
5291 'undone-face 'org-warning 'done-face 'org-agenda-done)
5293 (goto-char (point-at-eol))))
5296 (defun org-agenda-show-clocking-issues ()
5297 "Add overlays, showing issues with clocking.
5298 See also the user option `org-agenda-clock-consistency-checks'."
5300 (let* ((pl org-agenda-clock-consistency-checks)
5301 (re (concat "^[ \t]*"
5304 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5305 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5308 (maxtime (org-hh:mm-string-to-minutes
5309 (or (plist-get pl :max-duration) "24:00")))
5310 (mintime (org-hh:mm-string-to-minutes
5311 (or (plist-get pl :min-duration) 0)))
5312 (maxgap (org-hh:mm-string-to-minutes
5313 ;; default 30:00 means never complain
5314 (or (plist-get pl :max-gap) "30:00")))
5315 (gapok (mapcar 'org-hh:mm-string-to-minutes
5316 (plist-get pl :gap-ok-around)))
5317 (def-face (or (plist-get pl :default-face)
5318 '((:background "DarkRed") (:foreground "white"))))
5319 issue face m te ts dt ov)
5320 (goto-char (point-min))
5321 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5322 (setq issue nil face def-face)
5324 (setq m (org-get-at-bol 'org-marker)
5326 (unless (and m (markerp m))
5327 (setq issue "No valid clock line") (throw 'next t))
5328 (org-with-point-at m
5330 (goto-char (point-at-bol))
5331 (unless (looking-at re)
5332 (error "No valid Clock line")
5334 (unless (match-end 3)
5335 (setq issue "No end time"
5336 face (or (plist-get pl :no-end-time-face) face))
5338 (setq ts (match-string 1)
5341 (apply 'encode-time (org-parse-time-string ts)))
5343 (apply 'encode-time (org-parse-time-string te)))
5346 ((> dt (* 60 maxtime))
5347 ;; a very long clocking chunk
5348 (setq issue (format "Clocking interval is very long: %s"
5349 (org-minutes-to-hh:mm-string
5350 (floor (/ (float dt) 60.))))
5351 face (or (plist-get pl :long-face) face)))
5352 ((< dt (* 60 mintime))
5353 ;; a very short clocking chunk
5354 (setq issue (format "Clocking interval is very short: %s"
5355 (org-minutes-to-hh:mm-string
5356 (floor (/ (float dt) 60.))))
5357 face (or (plist-get pl :short-face) face)))
5358 ((and (> tlend 0) (< ts tlend))
5359 ;; Two clock entries are overlapping
5360 (setq issue (format "Clocking overlap: %d minutes"
5361 (/ (- tlend ts) 60))
5362 face (or (plist-get pl :overlap-face) face)))
5363 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5364 ;; There is a gap, lets see if we need to report it
5365 (unless (org-agenda-check-clock-gap tlend ts gapok)
5366 (setq issue (format "Clocking gap: %d minutes"
5367 (/ (- ts tlend) 60))
5368 face (or (plist-get pl :gap-face) face))))
5370 (setq tlend (or te tlend) tlstart (or ts tlstart))
5372 ;; OK, there was some issue, add an overlay to show the issue
5373 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5374 (overlay-put ov 'before-string
5377 (format "%-43s" (concat " " issue))
5381 (overlay-put ov 'evaporate t)))))
5383 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5384 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5387 ;; there are no OK times for gaps...
5389 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5390 ;; This is more than 24 hours, so it is OK.
5391 ;; because we have at least one OK time, that must be in the
5392 ;; 24 hour interval.
5394 ;; We have a shorter gap.
5395 ;; Now we have to get the minute of the day when these times are
5396 (let* ((t1dec (decode-time (seconds-to-time t1)))
5397 (t2dec (decode-time (seconds-to-time t2)))
5398 ;; compute the minute on the day
5399 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5400 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5402 ;; if min2 is smaller than min1, this means it is on the next day.
5403 ;; Wrap it to after midnight.
5404 (setq min2 (+ min2 1440)))
5405 ;; Now check if any of the OK times is in the gap
5407 ;; Wrap the time to after midnight if necessary
5408 (if (< x min1) (setq x (+ x 1440)))
5409 ;; Check if in interval
5410 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5412 ;; Nope, this gap is not OK
5415 (defun org-agenda-get-deadlines ()
5416 "Return the deadline information for agenda display."
5417 (let* ((props (list 'mouse-face 'highlight
5418 'org-not-done-regexp org-not-done-regexp
5419 'org-todo-regexp org-todo-regexp
5420 'org-complex-heading-regexp org-complex-heading-regexp
5422 (format "mouse-2 or RET jump to org file %s"
5423 (abbreviate-file-name buffer-file-name))))
5424 (regexp org-deadline-time-regexp)
5425 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5426 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5427 d2 diff dfrac wdays pos pos1 category org-category-pos
5428 tags suppress-prewarning ee txt head face s todo-state
5429 show-all upcomingp donep timestr)
5430 (goto-char (point-min))
5431 (while (re-search-forward regexp nil t)
5432 (setq suppress-prewarning nil)
5435 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5437 (string-match org-scheduled-time-regexp
5438 (buffer-substring (point-at-bol)
5440 (setq suppress-prewarning
5441 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5442 org-agenda-skip-deadline-prewarning-if-scheduled
5444 (setq s (match-string 1)
5446 pos (1- (match-beginning 1))
5447 todo-state (save-match-data (org-get-todo-state))
5448 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5450 org-agenda-repeating-timestamp-show-all))
5451 d2 (org-time-string-to-absolute
5452 (match-string 1) d1 'past show-all
5453 (current-buffer) pos)
5455 wdays (if suppress-prewarning
5456 (let ((org-deadline-warning-days suppress-prewarning))
5459 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5460 upcomingp (and todayp (> diff 0)))
5461 ;; When to show a deadline in the calendar:
5462 ;; If the expiration is within wdays warning time.
5463 ;; Past-due deadlines are only shown on the current date
5464 (if (and (or (and (<= diff wdays)
5465 (and todayp (not org-agenda-only-exact-dates)))
5468 ;; (setq todo-state (org-get-todo-state))
5469 (setq donep (member todo-state org-done-keywords))
5471 (or org-agenda-skip-deadline-if-done
5474 (setq category (org-get-category)
5475 org-category-pos (get-text-property (point) 'org-category-position))
5476 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5477 (setq txt org-agenda-no-heading-message)
5478 (goto-char (match-end 0))
5479 (setq pos1 (match-beginning 0))
5480 (setq tags (org-get-tags-at pos1))
5481 (setq head (buffer-substring-no-properties
5483 (progn (skip-chars-forward "^\r\n")
5485 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5487 (concat (substring s (match-beginning 1)) " "))
5488 (setq timestr 'time))
5489 (setq txt (org-agenda-format-item
5491 (car org-agenda-deadline-leaders)
5493 (nth 1 org-agenda-deadline-leaders))
5495 (nth 1 org-agenda-deadline-leaders)
5497 (format (nth 1 org-agenda-deadline-leaders)
5500 (if (not (= diff 0)) nil timestr)))))
5502 (setq face (org-agenda-deadline-face dfrac))
5503 (org-add-props txt props
5504 'org-marker (org-agenda-new-marker pos)
5505 'org-hd-marker (org-agenda-new-marker pos1)
5506 'priority (+ (- diff)
5507 (org-get-priority txt))
5508 'org-category category
5509 'org-category-position org-category-pos
5510 'todo-state todo-state
5511 'type (if upcomingp "upcoming-deadline" "deadline")
5512 'date (if upcomingp date d2)
5513 'face (if donep 'org-agenda-done face)
5514 'undone-face face 'done-face 'org-agenda-done)
5518 (defun org-agenda-deadline-face (fraction)
5519 "Return the face to displaying a deadline item.
5520 FRACTION is what fraction of the head-warning time has passed."
5521 (let ((faces org-agenda-deadline-faces) f)
5523 (while (setq f (pop faces))
5524 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5526 (defun org-agenda-get-scheduled (&optional deadline-results)
5527 "Return the scheduled information for agenda display."
5528 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5529 'org-todo-regexp org-todo-regexp
5530 'org-complex-heading-regexp org-complex-heading-regexp
5531 'done-face 'org-agenda-done
5532 'mouse-face 'highlight
5534 (format "mouse-2 or RET jump to org file %s"
5535 (abbreviate-file-name buffer-file-name))))
5536 (regexp org-scheduled-time-regexp)
5537 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5538 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5540 (deadline-position-alist
5541 (mapcar (lambda (a) (and (setq mm (get-text-property
5542 0 'org-hd-marker a))
5543 (cons (marker-position mm) a)))
5545 d2 diff pos pos1 category org-category-pos tags donep
5546 ee txt head pastschedp todo-state face timestr s habitp show-all
5548 (goto-char (point-min))
5549 (while (re-search-forward regexp nil t)
5552 (setq s (match-string 1)
5554 pos (1- (match-beginning 1))
5555 todo-state (save-match-data (org-get-todo-state))
5556 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5558 org-agenda-repeating-timestamp-show-all))
5559 d2 (org-time-string-to-absolute
5560 (match-string 1) d1 'past show-all
5561 (current-buffer) pos)
5563 (setq pastschedp (and todayp (< diff 0)))
5564 (setq did-habit-check-p nil)
5565 ;; When to show a scheduled item in the calendar:
5566 ;; If it is on or past the date.
5567 (when (or (and (< diff 0)
5568 (< (abs diff) org-scheduled-past-days)
5569 (and todayp (not org-agenda-only-exact-dates)))
5571 ;; org-is-habit-p uses org-entry-get, which is expansive
5572 ;; so we go extra mile to only call it once
5574 org-habit-show-all-today
5575 (setq did-habit-check-p t)
5576 (setq habitp (and (functionp 'org-is-habit-p)
5577 (org-is-habit-p)))))
5579 (setq donep (member todo-state org-done-keywords))
5581 (or org-agenda-skip-scheduled-if-done
5583 (and (functionp 'org-is-habit-p)
5586 (setq habitp (if did-habit-check-p habitp
5587 (and (functionp 'org-is-habit-p)
5589 (setq category (org-get-category)
5590 org-category-pos (get-text-property (point) 'org-category-position))
5591 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5592 (setq txt org-agenda-no-heading-message)
5593 (goto-char (match-end 0))
5594 (setq pos1 (match-beginning 0))
5596 (if (or (not org-habit-show-habits)
5598 org-habit-show-habits-only-for-today))
5601 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5602 (and org-agenda-skip-scheduled-if-deadline-is-shown
5604 (setq mm (assoc pos1 deadline-position-alist)))
5606 (setq tags (org-get-tags-at))
5607 (setq head (buffer-substring-no-properties
5609 (progn (skip-chars-forward "^\r\n") (point))))
5610 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5612 (concat (substring s (match-beginning 1)) " "))
5613 (setq timestr 'time))
5614 (setq txt (org-agenda-format-item
5616 (car org-agenda-scheduled-leaders)
5617 (format (nth 1 org-agenda-scheduled-leaders)
5620 (if (not (= diff 0)) nil timestr)
5625 ((and (not habitp) pastschedp)
5626 'org-scheduled-previously)
5627 (todayp 'org-scheduled-today)
5629 habitp (and habitp (org-habit-parse-todo)))
5630 (org-add-props txt props
5632 'face (if donep 'org-agenda-done face)
5633 'org-marker (org-agenda-new-marker pos)
5634 'org-hd-marker (org-agenda-new-marker pos1)
5635 'type (if pastschedp "past-scheduled" "scheduled")
5636 'date (if pastschedp d2 date)
5637 'priority (if habitp
5638 (org-habit-get-priority habitp)
5639 (+ 94 (- 5 diff) (org-get-priority txt)))
5640 'org-category category
5641 'org-category-position org-category-pos
5643 'todo-state todo-state)
5647 (defun org-agenda-get-blocks ()
5648 "Return the date-range information for agenda display."
5649 (let* ((props (list 'face nil
5650 'org-not-done-regexp org-not-done-regexp
5651 'org-todo-regexp org-todo-regexp
5652 'org-complex-heading-regexp org-complex-heading-regexp
5653 'mouse-face 'highlight
5655 (format "mouse-2 or RET jump to org file %s"
5656 (abbreviate-file-name buffer-file-name))))
5657 (regexp org-tr-regexp)
5658 (d0 (calendar-absolute-from-gregorian date))
5659 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5660 todo-state tags pos head donep)
5661 (goto-char (point-min))
5662 (while (re-search-forward regexp nil t)
5666 (let ((start-time (match-string 1))
5667 (end-time (match-string 2)))
5668 (setq s1 (match-string 1)
5670 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5671 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5672 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5673 ;; Only allow days between the limits, because the normal
5674 ;; date stamps will catch the limits.
5676 (setq todo-state (org-get-todo-state))
5677 (setq donep (member todo-state org-done-keywords))
5678 (if (and donep org-agenda-skip-timestamp-if-done)
5680 (setq marker (org-agenda-new-marker (point)))
5681 (setq category (org-get-category)
5682 org-category-pos (get-text-property (point) 'org-category-position))
5683 (if (not (re-search-backward org-outline-regexp-bol nil t))
5684 (setq txt org-agenda-no-heading-message)
5685 (goto-char (match-beginning 0))
5686 (setq hdmarker (org-agenda-new-marker (point)))
5687 (setq tags (org-get-tags-at))
5688 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5689 (setq head (match-string 1))
5691 (if org-agenda-remove-timeranges-from-blocks
5693 "<" (regexp-quote s1) ".*?>"
5695 "<" (regexp-quote s2) ".*?>")
5697 (setq txt (org-agenda-format-item
5699 (nth (if (= d1 d2) 0 1)
5700 org-agenda-timerange-leaders)
5701 (1+ (- d0 d1)) (1+ (- d2 d1)))
5703 (cond ((and (= d1 d0) (= d2 d0))
5704 (concat "<" start-time ">--<" end-time ">"))
5706 (concat "<" start-time ">"))
5708 (concat "<" end-time ">"))
5711 (org-add-props txt props
5712 'org-marker marker 'org-hd-marker hdmarker
5713 'type "block" 'date date
5714 'todo-state todo-state
5715 'priority (org-get-priority txt) 'org-category category
5716 'org-category-position org-category-pos)
5719 ;; Sort the entries by expiration date.
5722 ;;; Agenda presentation and sorting
5724 (defvar org-prefix-has-time nil
5725 "A flag, set by `org-compile-prefix-format'.
5726 The flag is set if the currently compiled format contains a `%t'.")
5727 (defvar org-prefix-has-tag nil
5728 "A flag, set by `org-compile-prefix-format'.
5729 The flag is set if the currently compiled format contains a `%T'.")
5730 (defvar org-prefix-has-effort nil
5731 "A flag, set by `org-compile-prefix-format'.
5732 The flag is set if the currently compiled format contains a `%e'.")
5733 (defvar org-prefix-category-length nil
5734 "Used by `org-compile-prefix-format' to remember the category field width.")
5735 (defvar org-prefix-category-max-length nil
5736 "Used by `org-compile-prefix-format' to remember the category field width.")
5738 (defun org-agenda-get-category-icon (category)
5739 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5740 (dolist (entry org-agenda-category-icon-alist)
5741 (when (org-string-match-p (car entry) category)
5742 (if (listp (cadr entry))
5743 (return (cadr entry))
5744 (return (apply 'create-image (cdr entry)))))))
5746 (defun org-agenda-format-item (extra txt &optional category tags dotime
5748 "Format TXT to be inserted into the agenda buffer.
5749 In particular, it adds the prefix and corresponding text properties. EXTRA
5750 must be a string and replaces the `%s' specifier in the prefix format.
5751 CATEGORY (string, symbol or nil) may be used to overrule the default
5752 category taken from local variable or file name. It will replace the `%c'
5753 specifier in the format. DOTIME, when non-nil, indicates that a
5754 time-of-day should be extracted from TXT for sorting of this entry, and for
5755 the `%t' specifier in the format. When DOTIME is a string, this string is
5756 searched for a time before TXT is. TAGS can be the tags of the headline.
5757 Any match of REMOVE-RE will be removed from TXT."
5758 ;; We keep the org-prefix-* variable values along with a compiled
5759 ;; formatter, so that multiple agendas existing at the same time, do
5760 ;; not step on each other toes.
5762 ;; It was inconvenient to make these variables buffer local in
5763 ;; Agenda buffers, because this function expects to be called with
5764 ;; the buffer where item comes from being current, and not agenda
5766 (let* ((bindings (car org-prefix-format-compiled))
5767 (formatter (cadr org-prefix-format-compiled)))
5768 (loop for (var value) in bindings
5771 ;; Diary entries sometimes have extra whitespace at the beginning
5772 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5774 ;; Fix the tags part in txt
5775 (setq txt (org-agenda-fix-displayed-tags
5777 org-agenda-show-inherited-tags
5778 org-agenda-hide-tags-regexp))
5779 (let* ((category (or category
5780 (if (stringp org-category)
5782 (and org-category (symbol-name org-category)))
5783 (if buffer-file-name
5784 (file-name-sans-extension
5785 (file-name-nondirectory buffer-file-name))
5787 (category-icon (org-agenda-get-category-icon category))
5788 (category-icon (if category-icon
5789 (propertize " " 'display category-icon)
5791 ;; time, tag, effort are needed for the eval of the prefix format
5792 (tag (if tags (nth (1- (length tags)) tags) ""))
5794 (ts (if dotime (concat
5795 (if (stringp dotime) dotime "")
5796 (and org-agenda-search-headline-for-time txt))))
5797 (time-of-day (and dotime (org-get-time-of-day ts)))
5798 stamp plain s0 s1 s2 rtn srp l
5799 duration thecategory)
5800 (and (derived-mode-p 'org-mode) buffer-file-name
5801 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5802 (when (and dotime time-of-day)
5803 ;; Extract starting and ending time and move them to prefix
5804 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5805 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5806 (setq s0 (match-string 0 ts)
5807 srp (and stamp (match-end 3))
5808 s1 (match-string (if plain 1 2) ts)
5809 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5811 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5812 ;; them, we might want to remove them there to avoid duplication.
5813 ;; The user can turn this off with a variable.
5814 (if (and org-prefix-has-time
5815 org-agenda-remove-times-when-in-prefix (or stamp plain)
5816 (string-match (concat (regexp-quote s0) " *") txt)
5817 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5818 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5819 (= (match-beginning 0) 0)
5821 (setq txt (replace-match "" nil nil txt))))
5822 ;; Normalize the time(s) to 24 hour
5823 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5824 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5826 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5827 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5829 (org-minutes-to-hh:mm-string
5830 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5832 ;; Compute the duration
5834 (setq duration (- (org-hh:mm-string-to-minutes s2)
5835 (org-hh:mm-string-to-minutes s1)))))
5837 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5839 ;; Tags are in the string
5840 (if (or (eq org-agenda-remove-tags t)
5841 (and org-agenda-remove-tags
5842 org-prefix-has-tag))
5843 (setq txt (replace-match "" t t txt))
5844 (setq txt (replace-match
5845 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5846 (match-string 2 txt))
5848 (when (derived-mode-p 'org-mode)
5852 (or (get-text-property 0 'org-hd-marker txt)
5853 (get-text-property 0 'org-marker txt)))
5856 (setq neffort (org-duration-string-to-minutes effort)
5857 effort (setq effort (concat "[" effort "]")))))
5858 ;; prevent erroring out with %e format when there is no effort
5859 (or effort (setq effort ""))
5862 (while (string-match remove-re txt)
5863 (setq txt (replace-match "" t t txt))))
5865 ;; Set org-heading property on `txt' to mark the start of the
5867 (add-text-properties 0 (length txt) '(org-heading t) txt)
5869 ;; Prepare the variables needed in the eval of the compiled format
5870 (setq time (cond (s2 (concat
5871 (org-agenda-time-of-day-to-ampm-maybe s1)
5872 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5873 (if org-agenda-timegrid-use-ampm " ")))
5875 (org-agenda-time-of-day-to-ampm-maybe s1)
5876 (if org-agenda-timegrid-use-ampm
5880 extra (or (and (not habitp) extra) "")
5881 category (if (symbolp category) (symbol-name category) category)
5882 thecategory (copy-sequence category))
5883 (if (string-match org-bracket-link-regexp category)
5885 (setq l (if (match-end 3)
5886 (- (match-end 3) (match-beginning 3))
5887 (- (match-end 1) (match-beginning 1))))
5888 (when (< l (or org-prefix-category-length 0))
5889 (setq category (copy-sequence category))
5890 (org-add-props category nil
5891 'extra-space (make-string
5892 (- org-prefix-category-length l 1) ?\ ))))
5893 (if (and org-prefix-category-max-length
5894 (>= (length category) org-prefix-category-max-length))
5895 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5896 ;; Evaluate the compiled format
5897 (setq rtn (concat (eval formatter) txt))
5899 ;; And finally add the text properties
5900 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5901 (org-add-props rtn nil
5902 'org-category (if thecategory (downcase thecategory) category)
5903 'tags (mapcar 'org-downcase-keep-props tags)
5904 'org-highest-priority org-highest-priority
5905 'org-lowest-priority org-lowest-priority
5906 'time-of-day time-of-day
5909 'effort-minutes neffort
5913 'format org-prefix-format-compiled
5916 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5917 "Remove tags string from TXT, and add a modified list of tags.
5918 The modified list may contain inherited tags, and tags matched by
5919 `org-agenda-hide-tags-regexp' will be removed."
5920 (when (or add-inherited hide-re)
5921 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5922 (setq txt (substring txt 0 (match-beginning 0))))
5925 (mapcar (lambda (tg)
5926 (if (or (and hide-re (string-match hide-re tg))
5927 (and (not add-inherited)
5928 (get-text-property 0 'inherited tg)))
5933 (let ((have-i (get-text-property 0 'inherited (car tags)))
5935 (setq txt (concat txt " :"
5938 (setq i (get-text-property 0 'inherited x))
5939 (if (and have-i (not i))
5945 (if have-i "::" ":"))))))
5948 (defun org-downcase-keep-props (s)
5949 (let ((props (text-properties-at 0 s)))
5950 (setq s (downcase s))
5951 (add-text-properties 0 (length s) props s)
5954 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5955 (defvar org-agenda-sorting-strategy-selected nil)
5957 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5959 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5960 ((and todayp (member 'today (car org-agenda-time-grid))))
5961 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5962 ((member 'weekly (car org-agenda-time-grid)))
5963 (t (throw 'exit list)))
5964 (let* ((have (delq nil (mapcar
5965 (lambda (x) (get-text-property 1 'time-of-day x))
5967 (string (nth 1 org-agenda-time-grid))
5968 (gridtimes (nth 2 org-agenda-time-grid))
5969 (req (car org-agenda-time-grid))
5970 (remove (member 'remove-match req))
5972 (if (and (member 'require-timed req) (not have))
5973 ;; don't show empty grid
5975 (while (setq time (pop gridtimes))
5976 (unless (and remove (member time have))
5977 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5978 (push (org-agenda-format-item
5980 (concat (substring time 0 -2) ":" (substring time -2)))
5983 2 (length (car new)) 'face 'org-time-grid (car new))))
5984 (when (and todayp org-agenda-show-current-time-in-grid)
5985 (push (org-agenda-format-item
5987 org-agenda-current-time-string
5989 (format-time-string "%H:%M "))
5992 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5994 (if (member 'time-up org-agenda-sorting-strategy-selected)
5996 (append list new)))))
5998 (defun org-compile-prefix-format (key)
5999 "Compile the prefix format into a Lisp form that can be evaluated.
6000 The resulting form and associated variable bindings is returned
6001 and stored in the variable `org-prefix-format-compiled'."
6002 (setq org-prefix-has-time nil org-prefix-has-tag nil
6003 org-prefix-category-length nil
6004 org-prefix-has-effort nil)
6006 ((stringp org-agenda-prefix-format)
6007 org-agenda-prefix-format)
6008 ((assq key org-agenda-prefix-format)
6009 (cdr (assq key org-agenda-prefix-format)))
6010 (t " %-12:c%?-12t% s")))
6012 varform vars var e c f opt)
6013 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6015 (setq var (or (cdr (assoc (match-string 4 s)
6016 '(("c" . category) ("t" . time) ("s" . extra)
6017 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6019 c (or (match-string 3 s) "")
6020 opt (match-beginning 1)
6021 start (1+ (match-beginning 0)))
6022 (if (equal var 'time) (setq org-prefix-has-time t))
6023 (if (equal var 'tag) (setq org-prefix-has-tag t))
6024 (if (equal var 'effort) (setq org-prefix-has-effort t))
6025 (setq f (concat "%" (match-string 2 s) "s"))
6026 (when (equal var 'category)
6027 (setq org-prefix-category-length
6028 (floor (abs (string-to-number (match-string 2 s)))))
6029 (setq org-prefix-category-max-length
6030 (let ((x (match-string 2 s)))
6032 (if (string-match "\\.[0-9]+" x)
6033 (string-to-number (substring (match-string 0 x) 1)))))))
6035 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6038 `(if (equal "" ,var)
6040 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6041 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6042 (setq s (replace-match "%s" t nil s))
6043 (push varform vars))
6044 (setq vars (nreverse vars))
6045 (with-current-buffer org-agenda-buffer
6046 (setq org-prefix-format-compiled
6048 `((org-prefix-has-time ,org-prefix-has-time)
6049 (org-prefix-has-tag ,org-prefix-has-tag)
6050 (org-prefix-category-length ,org-prefix-category-length)
6051 (org-prefix-has-effort ,org-prefix-has-effort))
6052 `(format ,s ,@vars))))))
6054 (defun org-set-sorting-strategy (key)
6055 (if (symbolp (car org-agenda-sorting-strategy))
6057 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6058 (setq org-agenda-sorting-strategy-selected
6059 (or (cdr (assq key org-agenda-sorting-strategy))
6060 (cdr (assq 'agenda org-agenda-sorting-strategy))
6061 '(time-up category-keep priority-down)))))
6063 (defun org-get-time-of-day (s &optional string mod24)
6064 "Check string S for a time of day.
6065 If found, return it as a military time number between 0 and 2400.
6066 If not found, return nil.
6067 The optional STRING argument forces conversion into a 5 character wide string
6071 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6072 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6073 (let* ((h (string-to-number (match-string 1 s)))
6074 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6075 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6076 (am-p (equal ampm "am"))
6077 (h1 (cond ((not ampm) h)
6078 ((= h 12) (if am-p 0 12))
6079 (t (+ h (if am-p 0 12)))))
6080 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6082 (t0 (+ (* 100 h2) m))
6083 (t1 (concat (if (>= h1 24) "+" " ")
6084 (if (and org-agenda-time-leading-zero
6085 (< t0 1000)) "0" "")
6086 (if (< t0 100) "0" "")
6087 (if (< t0 10) "0" "")
6088 (int-to-string t0))))
6089 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6091 (defvar org-agenda-before-sorting-filter-function nil
6092 "Function to be applied to agenda items prior to sorting.
6093 Prior to sorting also means just before they are inserted into the agenda.
6095 To aid sorting, you may revisit the original entries and add more text
6096 properties which will later be used by the sorting functions.
6098 The function should take a string argument, an agenda line.
6099 It has access to the text properties in that line, which contain among
6100 other things, the property `org-hd-marker' that points to the entry
6101 where the line comes from. Note that not all lines going into the agenda
6102 have this property, only most.
6104 The function should return the modified string. It is probably best
6105 to ONLY change text properties.
6107 You can also use this function as a filter, by returning nil for lines
6108 you don't want to have in the agenda at all. For this application, you
6109 could bind the variable in the options section of a custom command.")
6111 (defun org-finalize-agenda-entries (list &optional nosort)
6112 "Sort and concatenate the agenda items."
6113 (setq list (mapcar 'org-agenda-highlight-todo list))
6116 (when org-agenda-before-sorting-filter-function
6117 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6118 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6120 (defun org-agenda-highlight-todo (x)
6121 (let ((org-done-keywords org-done-keywords-for-agenda)
6122 (case-fold-search nil)
6126 (beginning-of-line 1)
6127 (setq re (org-get-at-bol 'org-todo-regexp))
6128 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6129 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6130 (add-text-properties (match-beginning 0) (match-end 1)
6131 (list 'face (org-get-todo-face 1)))
6132 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6133 (delete-region (match-beginning 1) (1- (match-end 0)))
6134 (goto-char (match-beginning 1))
6135 (insert (format org-agenda-todo-keyword-format s)))))
6136 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6137 (setq re (get-text-property 0 'org-todo-regexp x))
6139 ;; Test `pl' because if there's no heading content,
6140 ;; there's no point matching to highlight. Note
6141 ;; that if we didn't test `pl' first, and there
6142 ;; happened to be no keyword from `org-todo-regexp'
6143 ;; on this heading line, then the `equal' comparison
6144 ;; afterwards would spuriously succeed in the case
6145 ;; where `pl' is nil -- causing an args-out-of-range
6146 ;; error when we try to add text properties to text
6147 ;; that isn't there.
6149 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6151 (add-text-properties
6152 (or (match-end 1) (match-end 0)) (match-end 0)
6153 (list 'face (org-get-todo-face (match-string 2 x)))
6156 (setq x (concat (substring x 0 (match-end 1))
6157 (format org-agenda-todo-keyword-format
6159 (org-add-props " " (text-properties-at 0 x))
6160 (substring x (match-end 3)))))))
6163 (defsubst org-cmp-priority (a b)
6164 "Compare the priorities of string A and B."
6165 (let ((pa (or (get-text-property 1 'priority a) 0))
6166 (pb (or (get-text-property 1 'priority b) 0)))
6167 (cond ((> pa pb) +1)
6171 (defsubst org-cmp-effort (a b)
6172 "Compare the effort values of string A and B."
6173 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6174 (ea (or (get-text-property 1 'effort-minutes a) def))
6175 (eb (or (get-text-property 1 'effort-minutes b) def)))
6176 (cond ((> ea eb) +1)
6180 (defsubst org-cmp-category (a b)
6181 "Compare the string values of categories of strings A and B."
6182 (let ((ca (or (get-text-property 1 'org-category a) ""))
6183 (cb (or (get-text-property 1 'org-category b) "")))
6184 (cond ((string-lessp ca cb) -1)
6185 ((string-lessp cb ca) +1)
6188 (defsubst org-cmp-todo-state (a b)
6189 "Compare the todo states of strings A and B."
6190 (let* ((ma (or (get-text-property 1 'org-marker a)
6191 (get-text-property 1 'org-hd-marker a)))
6192 (mb (or (get-text-property 1 'org-marker b)
6193 (get-text-property 1 'org-hd-marker b)))
6194 (fa (and ma (marker-buffer ma)))
6195 (fb (and mb (marker-buffer mb)))
6197 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6198 (and fb (with-current-buffer fb org-todo-keywords-1))))
6199 (ta (or (get-text-property 1 'todo-state a) ""))
6200 (tb (or (get-text-property 1 'todo-state b) ""))
6201 (la (- (length (member ta todo-kwds))))
6202 (lb (- (length (member tb todo-kwds))))
6203 (donepa (member ta org-done-keywords-for-agenda))
6204 (donepb (member tb org-done-keywords-for-agenda)))
6205 (cond ((and donepa (not donepb)) -1)
6206 ((and (not donepa) donepb) +1)
6211 (defsubst org-cmp-alpha (a b)
6212 "Compare the headlines, alphabetically."
6213 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6214 (plb (text-property-any 0 (length b) 'org-heading t b))
6215 (ta (and pla (substring a pla)))
6216 (tb (and plb (substring b plb))))
6218 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6219 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6220 (setq ta (substring ta (match-end 0))))
6221 (setq ta (downcase ta)))
6223 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6224 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6225 (setq tb (substring tb (match-end 0))))
6226 (setq tb (downcase tb)))
6229 ((string-lessp ta tb) -1)
6230 ((string-lessp tb ta) +1)
6233 (defsubst org-cmp-tag (a b)
6234 "Compare the string values of the first tags of A and B."
6235 (let ((ta (car (last (get-text-property 1 'tags a))))
6236 (tb (car (last (get-text-property 1 'tags b)))))
6239 ((string-lessp ta tb) -1)
6240 ((string-lessp tb ta) +1)
6243 (defsubst org-cmp-time (a b)
6244 "Compare the time-of-day values of strings A and B."
6245 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6246 (ta (or (get-text-property 1 'time-of-day a) def))
6247 (tb (or (get-text-property 1 'time-of-day b) def)))
6248 (cond ((< ta tb) -1)
6252 (defsubst org-cmp-habit-p (a b)
6253 "Compare the todo states of strings A and B."
6254 (let ((ha (get-text-property 1 'org-habit-p a))
6255 (hb (get-text-property 1 'org-habit-p b)))
6256 (cond ((and ha (not hb)) -1)
6257 ((and (not ha) hb) +1)
6260 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6262 (defun org-entries-lessp (a b)
6263 "Predicate for sorting agenda entries."
6264 ;; The following variables will be used when the form is evaluated.
6265 ;; So even though the compiler complains, keep them.
6266 (let* ((ss org-agenda-sorting-strategy-selected)
6267 (time-up (and (org-em 'time-up 'time-down ss)
6268 (org-cmp-time a b)))
6269 (time-down (if time-up (- time-up) nil))
6270 (priority-up (and (org-em 'priority-up 'priority-down ss)
6271 (org-cmp-priority a b)))
6272 (priority-down (if priority-up (- priority-up) nil))
6273 (effort-up (and (org-em 'effort-up 'effort-down ss)
6274 (org-cmp-effort a b)))
6275 (effort-down (if effort-up (- effort-up) nil))
6276 (category-up (and (or (org-em 'category-up 'category-down ss)
6277 (memq 'category-keep ss))
6278 (org-cmp-category a b)))
6279 (category-down (if category-up (- category-up) nil))
6280 (category-keep (if category-up +1 nil))
6281 (tag-up (and (org-em 'tag-up 'tag-down ss)
6283 (tag-down (if tag-up (- tag-up) nil))
6284 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6285 (org-cmp-todo-state a b)))
6286 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6287 (habit-up (and (org-em 'habit-up 'habit-down ss)
6288 (org-cmp-habit-p a b)))
6289 (habit-down (if habit-up (- habit-up) nil))
6290 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6291 (org-cmp-alpha a b)))
6292 (alpha-down (if alpha-up (- alpha-up) nil))
6293 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6294 user-defined-up user-defined-down)
6295 (if (and need-user-cmp org-agenda-cmp-user-defined
6296 (functionp org-agenda-cmp-user-defined))
6297 (setq user-defined-up
6298 (funcall org-agenda-cmp-user-defined a b)
6299 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6301 (eval (cons 'or org-agenda-sorting-strategy-selected))
6302 '((-1 . t) (1 . nil) (nil . nil))))))
6304 ;;; Agenda restriction lock
6306 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6307 "Overlay to mark the headline to which agenda commands are restricted.")
6308 (overlay-put org-agenda-restriction-lock-overlay
6309 'face 'org-agenda-restriction-lock)
6310 (overlay-put org-agenda-restriction-lock-overlay
6311 'help-echo "Agendas are currently limited to this subtree.")
6312 (org-detach-overlay org-agenda-restriction-lock-overlay)
6314 (defun org-agenda-set-restriction-lock (&optional type)
6315 "Set restriction lock for agenda, to current subtree or file.
6316 Restriction will be the file if TYPE is `file', or if type is the
6317 universal prefix '(4), or if the cursor is before the first headline
6318 in the file. Otherwise, restriction will be to the current subtree."
6320 (and (equal type '(4)) (setq type 'file))
6323 ((org-at-heading-p) 'subtree)
6324 ((condition-case nil (org-back-to-heading t) (error nil))
6327 (if (eq type 'subtree)
6329 (setq org-agenda-restrict t)
6330 (setq org-agenda-overriding-restriction 'subtree)
6331 (put 'org-agenda-files 'org-restrict
6332 (list (buffer-file-name (buffer-base-buffer))))
6333 (org-back-to-heading t)
6334 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6335 (move-marker org-agenda-restrict-begin (point))
6336 (move-marker org-agenda-restrict-end
6337 (save-excursion (org-end-of-subtree t)))
6338 (message "Locking agenda restriction to subtree"))
6339 (put 'org-agenda-files 'org-restrict
6340 (list (buffer-file-name (buffer-base-buffer))))
6341 (setq org-agenda-restrict nil)
6342 (setq org-agenda-overriding-restriction 'file)
6343 (move-marker org-agenda-restrict-begin nil)
6344 (move-marker org-agenda-restrict-end nil)
6345 (message "Locking agenda restriction to file"))
6346 (setq current-prefix-arg nil)
6347 (org-agenda-maybe-redo))
6349 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6350 "Remove the agenda restriction lock."
6352 (org-detach-overlay org-agenda-restriction-lock-overlay)
6353 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6354 (setq org-agenda-overriding-restriction nil)
6355 (setq org-agenda-restrict nil)
6356 (put 'org-agenda-files 'org-restrict nil)
6357 (move-marker org-agenda-restrict-begin nil)
6358 (move-marker org-agenda-restrict-end nil)
6359 (setq current-prefix-arg nil)
6360 (message "Agenda restriction lock removed")
6361 (or noupdate (org-agenda-maybe-redo)))
6363 (defun org-agenda-maybe-redo ()
6364 "If there is any window showing the agenda view, update it."
6365 (let ((w (get-buffer-window org-agenda-buffer-name t))
6366 (w0 (selected-window)))
6371 (if org-agenda-overriding-restriction
6372 (message "Agenda view shifted to new %s restriction"
6373 org-agenda-overriding-restriction)
6374 (message "Agenda restriction lock removed")))))
6378 (defun org-agenda-check-type (error &rest types)
6379 "Check if agenda buffer is of allowed type.
6380 If ERROR is non-nil, throw an error, otherwise just return nil."
6381 (if (memq org-agenda-type types)
6384 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6387 (defun org-agenda-Quit (&optional arg)
6388 "Exit agenda by removing the window or the buffer."
6390 (if org-agenda-columns-active
6392 (let ((buf (current-buffer)))
6393 (if (eq org-agenda-window-setup 'other-frame)
6395 (org-agenda-reset-markers)
6397 (org-columns-remove-overlays)
6398 (setq org-agenda-archives-mode nil)
6400 (and (not (eq org-agenda-window-setup 'current-window))
6401 (not (one-window-p))
6403 (org-agenda-reset-markers)
6405 (org-columns-remove-overlays)
6406 (setq org-agenda-archives-mode nil)))
6407 ;; Maybe restore the pre-agenda window configuration.
6408 (and org-agenda-restore-windows-after-quit
6409 (not (eq org-agenda-window-setup 'other-frame))
6410 org-pre-agenda-window-conf
6411 (set-window-configuration org-pre-agenda-window-conf))))
6413 (defun org-agenda-quit ()
6414 "Exit agenda by killing agenda buffer or burying it when
6415 `org-agenda-sticky' is non-NIL"
6417 (if org-agenda-columns-active
6419 (if org-agenda-sticky
6420 (let ((buf (current-buffer)))
6421 (if (eq org-agenda-window-setup 'other-frame)
6424 (and (not (eq org-agenda-window-setup 'current-window))
6425 (not (one-window-p))
6427 (with-current-buffer buf
6429 ;; Maybe restore the pre-agenda window configuration.
6430 (and org-agenda-restore-windows-after-quit
6431 (not (eq org-agenda-window-setup 'other-frame))
6432 org-pre-agenda-window-conf
6433 (set-window-configuration org-pre-agenda-window-conf))))
6434 (org-agenda-Quit))))
6436 (defun org-agenda-exit ()
6437 "Exit agenda by removing the window or the buffer.
6438 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6439 Org-mode buffers visited directly by the user will not be touched."
6441 (org-release-buffers org-agenda-new-buffers)
6442 (setq org-agenda-new-buffers nil)
6445 (defun org-agenda-kill-all-agenda-buffers ()
6446 "Kill all buffers in `org-agena-mode'.
6447 This is used when toggling sticky agendas. You can also explicitly invoke it
6451 (dolist (buf (buffer-list))
6452 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6454 (mapc 'kill-buffer blist)))
6456 (defun org-agenda-execute (arg)
6457 "Execute another agenda command, keeping same window.
6458 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6461 (let ((org-agenda-window-setup 'current-window))
6464 (defun org-agenda-redo ()
6466 When this is the global TODO list, a prefix argument will be interpreted."
6468 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6469 (org-agenda-sticky nil)
6470 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6471 org-agenda-buffer-name))
6472 (org-agenda-keep-modes t)
6473 (tag-filter org-agenda-tag-filter)
6474 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6475 (top-cat-filter org-agenda-top-category-filter)
6476 (cat-filter org-agenda-category-filter)
6477 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6478 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6479 (cols org-agenda-columns-active)
6480 (line (org-current-line))
6481 (window-line (- line (org-current-line (window-start))))
6482 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6483 (put 'org-agenda-tag-filter :preset-filter nil)
6484 (put 'org-agenda-category-filter :preset-filter nil)
6485 (and cols (org-columns-quit))
6486 (message "Rebuilding agenda buffer...")
6487 (org-let lprops '(eval org-agenda-redo-command))
6488 (setq org-agenda-undo-list nil
6489 org-agenda-pending-undo-list nil)
6490 (message "Rebuilding agenda buffer...done")
6491 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6492 (put 'org-agenda-category-filter :preset-filter cat-preset)
6493 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6494 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6495 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6496 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6497 (org-goto-line line)
6498 (recenter window-line)))
6500 (defvar org-global-tags-completion-table nil)
6501 (defvar org-agenda-filter-form nil)
6502 (defvar org-agenda-filtered-by-category nil)
6504 (defun org-agenda-filter-by-category (strip)
6505 "Keep only those lines in the agenda buffer that have a specific category.
6506 The category is that of the current line."
6508 (if org-agenda-filtered-by-category
6509 (org-agenda-filter-show-all-cat)
6510 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6511 (if cat (org-agenda-filter-apply
6512 (list (concat (if strip "-" "+") cat)) 'category)
6513 (error "No category at point")))))
6515 (defun org-find-top-category (&optional pos)
6517 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6518 (if pos (goto-char pos))
6519 ;; Skip up to the topmost parent
6520 (while (ignore-errors (outline-up-heading 1) t))
6522 (nth 4 (org-heading-components))))))
6524 (defvar org-agenda-filtered-by-top-category nil)
6526 (defun org-agenda-filter-by-top-category (strip)
6527 "Keep only those lines in the agenda buffer that have a specific category.
6528 The category is that of the current line."
6530 (if org-agenda-filtered-by-top-category
6532 (setq org-agenda-filtered-by-top-category nil
6533 org-agenda-top-category-filter nil)
6534 (org-agenda-filter-show-all-cat))
6535 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6536 (if cat (org-agenda-filter-top-category-apply cat strip)
6537 (error "No top-level category at point")))))
6539 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6540 "Keep only those lines in the agenda buffer that have a specific tag.
6541 The tag is selected with its fast selection letter, as configured.
6542 With prefix argument STRIP, remove all lines that do have the tag.
6543 A lisp caller can specify CHAR. NARROW means that the new tag should be
6544 used to narrow the search - the interactive user can also press `-' or `+'
6545 to switch to narrowing."
6547 (let* ((alist org-tag-alist-for-agenda)
6548 (tag-chars (mapconcat
6549 (lambda (x) (if (and (not (symbolp (car x)))
6551 (char-to-string (cdr x))
6554 (efforts (org-split-string
6555 (or (cdr (assoc (concat org-effort-property "_ALL")
6556 org-global-properties))
6557 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6559 (effort-op org-agenda-filter-effort-default-operator)
6561 (inhibit-read-only t)
6562 (current org-agenda-tag-filter)
6563 maybe-refresh a n tag)
6566 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6567 (if narrow "Narrow" "Filter") tag-chars
6568 (if org-agenda-auto-exclude-function "[RET], " ""))
6569 (setq char (read-char-exclusive)))
6570 (when (member char '(?+ ?-))
6572 (cond ((equal char ?-) (setq strip t narrow t))
6573 ((equal char ?+) (setq strip nil narrow t)))
6575 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6576 (setq char (read-char-exclusive)))
6577 (when (member char '(?< ?> ?= ??))
6578 ;; An effort operator
6579 (setq effort-op (char-to-string char))
6580 (setq alist nil) ; to make sure it will be interpreted as effort.
6581 (unless (equal char ??)
6582 (loop for i from 0 to 9 do
6586 (if (= i 9) "0" (int-to-string (1+ i)))
6587 "]" (nth i efforts))))
6588 (message "Effort%s: %s " effort-op effort-prompt)
6589 (setq char (read-char-exclusive))
6590 (when (or (< char ?0) (> char ?9))
6591 (error "Need 1-9,0 to select effort"))))
6592 (when (equal char ?\t)
6593 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6594 (org-set-local 'org-global-tags-completion-table
6595 (org-global-tags-completion-table)))
6596 (let ((completion-ignore-case t))
6597 (setq tag (org-icompleting-read
6598 "Tag: " org-global-tags-completion-table))))
6601 (org-agenda-filter-show-all-tag)
6602 (when org-agenda-auto-exclude-function
6603 (setq org-agenda-tag-filter '())
6604 (dolist (tag (org-agenda-get-represented-tags))
6605 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6607 (push modifier org-agenda-tag-filter))))
6608 (if (not (null org-agenda-tag-filter))
6609 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6610 (setq maybe-refresh t))
6612 (org-agenda-filter-show-all-tag)
6613 (when (get 'org-agenda-tag-filter :preset-filter)
6614 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6615 (setq maybe-refresh t))
6617 (setq org-agenda-tag-filter
6618 (mapcar (lambda(tag) (concat "+" tag))
6619 (org-get-at-bol 'tags)))
6620 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6621 (setq maybe-refresh t))
6622 ((or (equal char ?\ )
6623 (setq a (rassoc char alist))
6624 (and (>= char ?0) (<= char ?9)
6625 (setq n (if (= char ?0) 9 (- char ?0 1))
6626 tag (concat effort-op (nth n efforts))
6631 (and tag (setq a (cons tag nil))))
6632 (org-agenda-filter-show-all-tag)
6634 (setq org-agenda-tag-filter
6635 (cons (concat (if strip "-" "+") tag)
6636 (if narrow current nil)))
6637 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6638 (setq maybe-refresh t))
6639 (t (error "Invalid tag selection character %c" char)))
6640 (when (and maybe-refresh
6641 (eq org-agenda-clockreport-mode 'with-filter))
6642 (org-agenda-redo))))
6644 (defun org-agenda-get-represented-tags ()
6645 "Get a list of all tags currently represented in the agenda."
6648 (goto-char (point-min))
6649 (while (setq p (next-single-property-change (point) 'tags))
6651 (mapc (lambda (x) (add-to-list 'tags x))
6652 (get-text-property (point) 'tags))))
6655 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6656 "Refine the current filter. See `org-agenda-filter-by-tag'."
6658 (org-agenda-filter-by-tag strip char 'refine))
6660 (defun org-agenda-filter-make-matcher ()
6661 "Create the form that tests a line for agenda filter."
6663 ;; first compute the tag-filter matcher
6664 (dolist (x (delete-dups
6665 (append (get 'org-agenda-tag-filter
6666 :preset-filter) org-agenda-tag-filter)))
6667 (if (member x '("-" "+"))
6668 (setq f1 (if (equal x "-") 'tags '(not tags)))
6669 (if (string-match "[<=>?]" x)
6670 (setq f1 (org-agenda-filter-effort-form x))
6671 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6672 (if (equal (string-to-char x) ?-)
6673 (setq f1 (list 'not f1))))
6675 ;; then compute the category-filter matcher
6676 (dolist (x (delete-dups
6677 (append (get 'org-agenda-category-filter
6678 :preset-filter) org-agenda-category-filter)))
6679 (if (equal "-" (substring x 0 1))
6680 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6681 (setq f1 (list 'equal (substring x 1) 'cat)))
6683 (cons 'and (nreverse f))))
6685 (defun org-agenda-filter-effort-form (e)
6686 "Return the form to compare the effort of the current line with what E says.
6687 E looks like \"+<2:25\"."
6689 (setq e (substring e 1))
6690 (setq op (string-to-char e) e (substring e 1))
6691 (setq op (cond ((equal op ?<) '<=)
6695 (list 'org-agenda-compare-effort (list 'quote op)
6696 (org-duration-string-to-minutes e))))
6698 (defun org-agenda-compare-effort (op value)
6699 "Compare the effort of the current line with VALUE, using OP.
6700 If the line does not have an effort defined, return nil."
6701 (let ((eff (org-get-at-bol 'effort-minutes)))
6704 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6707 (defun org-agenda-filter-apply (filter type)
6708 "Set FILTER as the new agenda filter and apply it."
6711 (setq org-agenda-tag-filter filter)
6712 (setq org-agenda-category-filter filter))
6713 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6714 (if (and (eq type 'category)
6715 (not (equal (substring (car filter) 0 1) "-")))
6716 ;; Only set `org-agenda-filtered-by-category' to t
6717 ;; when a unique category is used as the filter
6718 (setq org-agenda-filtered-by-category t))
6719 (org-agenda-set-mode-name)
6721 (goto-char (point-min))
6723 (if (org-get-at-bol 'org-marker)
6725 (setq tags (org-get-at-bol 'tags) ; used in eval
6726 cat (get-text-property (point) 'org-category))
6727 (if (not (eval org-agenda-filter-form))
6728 (org-agenda-filter-hide-line type))
6729 (beginning-of-line 2))
6730 (beginning-of-line 2))))
6731 (if (get-char-property (point) 'invisible)
6732 (ignore-errors (org-agenda-previous-line)))))
6734 (defun org-agenda-filter-top-category-apply (category &optional negative)
6735 "Set FILTER as the new agenda filter and apply it."
6736 (org-agenda-set-mode-name)
6738 (goto-char (point-min))
6740 (let* ((pos (org-get-at-bol 'org-hd-marker))
6741 (topcat (and pos (org-find-top-category pos))))
6742 (if (and topcat (funcall (if negative 'identity 'not)
6743 (string= category topcat)))
6744 (org-agenda-filter-hide-line 'category)))
6745 (beginning-of-line 2)))
6746 (if (get-char-property (point) 'invisible)
6747 (org-agenda-previous-line))
6748 (setq org-agenda-top-category-filter category
6749 org-agenda-filtered-by-top-category t))
6751 (defun org-agenda-filter-hide-line (type)
6753 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6755 (overlay-put ov 'invisible t)
6756 (overlay-put ov 'type type)
6758 (push ov org-agenda-tag-filter-overlays)
6759 (push ov org-agenda-cat-filter-overlays))))
6761 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6762 (setq pos (or pos (point)))
6764 (dolist (ov (overlays-at pos))
6765 (when (and (overlay-get ov 'invisible)
6766 (eq (overlay-get ov 'type) 'tag))
6768 (if (< (overlay-start ov) (point-at-eol))
6769 (move-overlay ov (point-at-eol)
6770 (overlay-end ov)))))))
6772 (defun org-agenda-filter-show-all-tag nil
6773 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6774 (setq org-agenda-tag-filter-overlays nil
6775 org-agenda-tag-filter nil
6776 org-agenda-filter-form nil)
6777 (org-agenda-set-mode-name))
6779 (defun org-agenda-filter-show-all-cat nil
6780 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6781 (setq org-agenda-cat-filter-overlays nil
6782 org-agenda-filtered-by-category nil
6783 org-agenda-category-filter nil
6784 org-agenda-filter-form nil)
6785 (org-agenda-set-mode-name))
6787 (defun org-agenda-manipulate-query-add ()
6788 "Manipulate the query by adding a search term with positive selection.
6789 Positive selection means the term must be matched for selection of an entry."
6791 (org-agenda-manipulate-query ?\[))
6792 (defun org-agenda-manipulate-query-subtract ()
6793 "Manipulate the query by adding a search term with negative selection.
6794 Negative selection means term must not be matched for selection of an entry."
6796 (org-agenda-manipulate-query ?\]))
6797 (defun org-agenda-manipulate-query-add-re ()
6798 "Manipulate the query by adding a search regexp with positive selection.
6799 Positive selection means the regexp must match for selection of an entry."
6801 (org-agenda-manipulate-query ?\{))
6802 (defun org-agenda-manipulate-query-subtract-re ()
6803 "Manipulate the query by adding a search regexp with negative selection.
6804 Negative selection means regexp must not match for selection of an entry."
6806 (org-agenda-manipulate-query ?\}))
6807 (defun org-agenda-manipulate-query (char)
6809 ((memq org-agenda-type '(timeline agenda))
6810 (let ((org-agenda-include-inactive-timestamps t))
6812 (message "Display now includes inactive timestamps as well"))
6813 ((eq org-agenda-type 'search)
6815 'org-agenda-query-string
6816 (if org-agenda-last-search-view-search-was-boolean
6817 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6818 (?\{ . " +{}") (?\} . " -{}"))))
6820 (setq org-agenda-redo-command
6821 (list 'org-search-view
6823 org-agenda-query-string
6824 (+ (length org-agenda-query-string)
6825 (if (member char '(?\{ ?\})) 0 1))))
6826 (set-register org-agenda-query-register org-agenda-query-string)
6828 (t (error "Cannot manipulate query for %s-type agenda buffers"
6831 (defun org-add-to-string (var string)
6832 (set var (concat (symbol-value var) string)))
6834 (defun org-agenda-goto-date (date)
6835 "Jump to DATE in agenda."
6836 (interactive (list (let ((org-read-date-prefer-future
6837 (eval org-agenda-jump-prefer-future)))
6839 (org-agenda-list nil date))
6841 (defun org-agenda-goto-today ()
6844 (org-agenda-check-type t 'timeline 'agenda)
6845 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6847 (tdpos (goto-char tdpos))
6848 ((eq org-agenda-type 'agenda)
6849 (let* ((sd (org-agenda-compute-starting-span
6850 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6851 (org-agenda-overriding-arguments org-agenda-last-arguments))
6852 (setf (nth 1 org-agenda-overriding-arguments) sd)
6854 (org-agenda-find-same-or-today-or-agenda)))
6855 (t (error "Cannot find today")))))
6857 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6859 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6860 (text-property-any (point-min) (point-max) 'org-today t)
6861 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6864 (defun org-agenda-later (arg)
6865 "Go forward in time by thee current span.
6866 With prefix ARG, go forward that many times the current span."
6868 (org-agenda-check-type t 'agenda)
6869 (let* ((span org-agenda-current-span)
6870 (sd org-starting-day)
6871 (greg (calendar-gregorian-from-absolute sd))
6872 (cnt (org-get-at-bol 'org-day-cnt))
6876 (setq sd (+ arg sd)))
6878 (setq sd (+ (* 7 arg) sd)))
6880 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6881 sd (calendar-absolute-from-gregorian greg2))
6882 (setcar greg2 (1+ (car greg2))))
6884 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6885 sd (calendar-absolute-from-gregorian greg2))
6886 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6888 (setq sd (+ (* span arg) sd))))
6889 (let ((org-agenda-overriding-arguments
6890 (list (car org-agenda-last-arguments) sd span t)))
6892 (org-agenda-find-same-or-today-or-agenda cnt))))
6894 (defun org-agenda-earlier (arg)
6895 "Go backward in time by the current span.
6896 With prefix ARG, go backward that many times the current span."
6898 (org-agenda-later (- arg)))
6900 (defun org-agenda-view-mode-dispatch ()
6901 "Call one of the view mode commands."
6903 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6904 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6905 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
6906 (let ((a (read-char-exclusive)))
6908 (?\ (call-interactively 'org-agenda-reset-view))
6909 (?d (call-interactively 'org-agenda-day-view))
6910 (?w (call-interactively 'org-agenda-week-view))
6911 (?m (call-interactively 'org-agenda-month-view))
6912 (?y (call-interactively 'org-agenda-year-view))
6913 (?l (call-interactively 'org-agenda-log-mode))
6914 (?L (org-agenda-log-mode '(4)))
6915 (?c (org-agenda-log-mode 'clockcheck))
6916 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6917 (?a (call-interactively 'org-agenda-archives-mode))
6918 (?A (org-agenda-archives-mode 'files))
6919 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6920 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6921 (?G (call-interactively 'org-agenda-toggle-time-grid))
6922 (?D (call-interactively 'org-agenda-toggle-diary))
6923 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6924 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6925 (org-agenda-check-type t 'timeline 'agenda)
6927 (message "Display now includes inactive timestamps as well"))
6928 (?q (message "Abort"))
6929 (otherwise (error "Invalid key" )))))
6931 (defun org-agenda-reset-view ()
6932 "Switch to default view for agenda."
6934 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6935 (defun org-agenda-day-view (&optional day-of-year)
6936 "Switch to daily view for agenda.
6937 With argument DAY-OF-YEAR, switch to that day of the year."
6939 (org-agenda-change-time-span 'day day-of-year))
6940 (defun org-agenda-week-view (&optional iso-week)
6941 "Switch to daily view for agenda.
6942 With argument ISO-WEEK, switch to the corresponding ISO week.
6943 If ISO-WEEK has more then 2 digits, only the last two encode the
6944 week. Any digits before this encode a year. So 200712 means
6945 week 12 of year 2007. Years in the range 1938-2037 can also be
6946 written as 2-digit years."
6948 (org-agenda-change-time-span 'week iso-week))
6949 (defun org-agenda-month-view (&optional month)
6950 "Switch to monthly view for agenda.
6951 With argument MONTH, switch to that month."
6953 (org-agenda-change-time-span 'month month))
6954 (defun org-agenda-year-view (&optional year)
6955 "Switch to yearly view for agenda.
6956 With argument YEAR, switch to that year.
6957 If MONTH has more then 2 digits, only the last two encode the
6958 month. Any digits before this encode a year. So 200712 means
6959 December year 2007. Years in the range 1938-2037 can also be
6960 written as 2-digit years."
6963 (setq year (org-small-year-to-year year)))
6964 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6965 (org-agenda-change-time-span 'year year)
6968 (defun org-agenda-change-time-span (span &optional n)
6969 "Change the agenda view to SPAN.
6970 SPAN may be `day', `week', `month', `year'."
6971 (org-agenda-check-type t 'agenda)
6972 (if (and (not n) (equal org-agenda-current-span span))
6973 (error "Viewing span is already \"%s\"" span))
6974 (let* ((sd (or (org-get-at-bol 'day)
6976 (sd (org-agenda-compute-starting-span sd span n))
6977 (org-agenda-overriding-arguments
6978 (or org-agenda-overriding-arguments
6979 (list (car org-agenda-last-arguments) sd span t))))
6981 (org-agenda-find-same-or-today-or-agenda))
6982 (org-agenda-set-mode-name)
6983 (message "Switched to %s view" span))
6985 (defun org-agenda-compute-starting-span (sd span &optional n)
6986 "Compute starting date for agenda.
6987 SPAN may be `day', `week', `month', `year'. The return value
6988 is a cons cell with the starting date and the number of days,
6989 so that the date SD will be in that range."
6990 (let* ((greg (calendar-gregorian-from-absolute sd))
6997 (setq sd (+ (calendar-absolute-from-gregorian
7001 (let* ((nt (calendar-day-of-week
7002 (calendar-gregorian-from-absolute sd)))
7003 (d (if org-agenda-start-on-weekday
7004 (- nt org-agenda-start-on-weekday)
7007 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7011 (setq y1 (org-small-year-to-year (/ n 100))
7014 (calendar-absolute-from-iso
7016 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7019 (when (and n (> n 99))
7020 (setq y1 (org-small-year-to-year (/ n 100))
7022 (setq sd (calendar-absolute-from-gregorian
7023 (list (or n mg) 1 (or y1 yg))))))
7025 (setq sd (calendar-absolute-from-gregorian
7026 (list 1 1 (or n yg))))))
7029 (defun org-agenda-next-date-line (&optional arg)
7030 "Jump to the next line indicating a date in agenda buffer."
7032 (org-agenda-check-type t 'agenda 'timeline)
7033 (beginning-of-line 1)
7034 ;; This does not work if user makes date format that starts with a blank
7035 (if (looking-at "^\\S-") (forward-char 1))
7036 (if (not (re-search-forward "^\\S-" nil t arg))
7039 (error "No next date after this line in this buffer")))
7040 (goto-char (match-beginning 0)))
7042 (defun org-agenda-previous-date-line (&optional arg)
7043 "Jump to the previous line indicating a date in agenda buffer."
7045 (org-agenda-check-type t 'agenda 'timeline)
7046 (beginning-of-line 1)
7047 (if (not (re-search-backward "^\\S-" nil t arg))
7048 (error "No previous date before this line in this buffer")))
7050 ;; Initialize the highlight
7051 (defvar org-hl (make-overlay 1 1))
7052 (overlay-put org-hl 'face 'highlight)
7054 (defun org-highlight (begin end &optional buffer)
7055 "Highlight a region with overlay."
7056 (move-overlay org-hl begin end (or buffer (current-buffer))))
7058 (defun org-unhighlight ()
7059 "Detach overlay INDEX."
7060 (org-detach-overlay org-hl))
7062 ;; FIXME this is currently not used.
7063 (defun org-highlight-until-next-command (beg end &optional buffer)
7064 "Move the highlight overlay to BEG/END, remove it before the next command."
7065 (org-highlight beg end buffer)
7066 (add-hook 'pre-command-hook 'org-unhighlight-once))
7067 (defun org-unhighlight-once ()
7068 "Remove the highlight from its position, and this function from the hook."
7069 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7072 (defun org-agenda-follow-mode ()
7073 "Toggle follow mode in an agenda buffer."
7075 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7076 (org-agenda-set-mode-name)
7077 (org-agenda-do-context-action)
7078 (message "Follow mode is %s"
7079 (if org-agenda-follow-mode "on" "off")))
7081 (defun org-agenda-entry-text-mode (&optional arg)
7082 "Toggle entry text mode in an agenda buffer."
7084 (setq org-agenda-entry-text-mode (or (integerp arg)
7085 (not org-agenda-entry-text-mode)))
7086 (org-agenda-entry-text-hide)
7087 (and org-agenda-entry-text-mode
7088 (let ((org-agenda-entry-text-maxlines
7089 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7090 (org-agenda-entry-text-show)))
7091 (org-agenda-set-mode-name)
7092 (message "Entry text mode is %s. Maximum number of lines is %d"
7093 (if org-agenda-entry-text-mode "on" "off")
7094 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7096 (defun org-agenda-clockreport-mode (&optional with-filter)
7097 "Toggle clocktable mode in an agenda buffer.
7098 With prefix arg WITH-FILTER, make the clocktable respect the current
7101 (org-agenda-check-type t 'agenda)
7103 (setq org-agenda-clockreport-mode 'with-filter)
7104 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7105 (org-agenda-set-mode-name)
7107 (message "Clocktable mode is %s"
7108 (if org-agenda-clockreport-mode "on" "off")))
7110 (defun org-agenda-log-mode (&optional special)
7111 "Toggle log mode in an agenda buffer.
7112 With argument SPECIAL, show all possible log items, not only the ones
7113 configured in `org-agenda-log-mode-items'.
7114 With a double `C-u' prefix arg, show *only* log items, nothing else."
7116 (org-agenda-check-type t 'agenda 'timeline)
7117 (setq org-agenda-show-log
7119 ((equal special '(16)) 'only)
7120 ((eq special 'clockcheck)
7121 (if (eq org-agenda-show-log 'clockcheck)
7123 (special '(closed clock state))
7124 (t (not org-agenda-show-log))))
7125 (org-agenda-set-mode-name)
7127 (message "Log mode is %s"
7128 (if org-agenda-show-log "on" "off")))
7130 (defun org-agenda-archives-mode (&optional with-files)
7131 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7132 When called with a prefix argument, include all archive files as well."
7134 (setq org-agenda-archives-mode
7135 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7136 (org-agenda-set-mode-name)
7141 ((eq org-agenda-archives-mode nil)
7142 "No archives are included")
7143 ((eq org-agenda-archives-mode 'trees)
7144 (format "Trees with :%s: tag are included" org-archive-tag))
7145 ((eq org-agenda-archives-mode t)
7146 (format "Trees with :%s: tag and all active archive files are included"
7147 org-archive-tag)))))
7149 (defun org-agenda-toggle-diary ()
7150 "Toggle diary inclusion in an agenda buffer."
7152 (org-agenda-check-type t 'agenda)
7153 (setq org-agenda-include-diary (not org-agenda-include-diary))
7155 (org-agenda-set-mode-name)
7156 (message "Diary inclusion turned %s"
7157 (if org-agenda-include-diary "on" "off")))
7159 (defun org-agenda-toggle-deadlines ()
7160 "Toggle inclusion of entries with a deadline in an agenda buffer."
7162 (org-agenda-check-type t 'agenda)
7163 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7165 (org-agenda-set-mode-name)
7166 (message "Deadlines inclusion turned %s"
7167 (if org-agenda-include-deadlines "on" "off")))
7169 (defun org-agenda-toggle-time-grid ()
7170 "Toggle time grid in an agenda buffer."
7172 (org-agenda-check-type t 'agenda)
7173 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7175 (org-agenda-set-mode-name)
7176 (message "Time-grid turned %s"
7177 (if org-agenda-use-time-grid "on" "off")))
7179 (defun org-agenda-set-mode-name ()
7180 "Set the mode name to indicate all the small mode settings."
7183 (if (get 'org-agenda-files 'org-restrict) " []" "")
7185 '(:eval (org-agenda-span-name org-agenda-current-span))
7186 (if org-agenda-follow-mode " Follow" "")
7187 (if org-agenda-entry-text-mode " ETxt" "")
7188 (if org-agenda-include-diary " Diary" "")
7189 (if org-agenda-include-deadlines " Ddl" "")
7190 (if org-agenda-use-time-grid " Grid" "")
7191 (if (and (boundp 'org-habit-show-habits)
7192 org-habit-show-habits) " Habit" "")
7194 ((consp org-agenda-show-log) " LogAll")
7195 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7196 (org-agenda-show-log " Log")
7198 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7200 '(:eval (org-propertize
7205 (get 'org-agenda-category-filter :preset-filter)
7206 org-agenda-category-filter)
7209 'face 'org-agenda-filter-category
7210 'help-echo "Category used in filtering"))
7212 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7214 '(:eval (org-propertize
7219 (get 'org-agenda-tag-filter :preset-filter)
7220 org-agenda-tag-filter)
7223 'face 'org-agenda-filter-tags
7224 'help-echo "Tags used in filtering"))
7226 (if org-agenda-archives-mode
7227 (if (eq org-agenda-archives-mode t)
7229 (format " :%s:" org-archive-tag))
7231 (if org-agenda-clockreport-mode
7232 (if (eq org-agenda-clockreport-mode 'with-filter)
7233 " Clock{}" " Clock")
7235 (force-mode-line-update))
7237 (defun org-agenda-post-command-hook ()
7238 (setq org-agenda-type
7239 (or (get-text-property (point) 'org-agenda-type)
7240 (get-text-property (max (point-min) (1- (point)))
7241 'org-agenda-type))))
7243 (defun org-agenda-next-line ()
7244 "Move cursor to the next line, and show if follow mode is active."
7246 (call-interactively 'next-line)
7247 (org-agenda-do-context-action))
7249 (defun org-agenda-previous-line ()
7250 "Move cursor to the previous line, and show if follow-mode is active."
7252 (call-interactively 'previous-line)
7253 (org-agenda-do-context-action))
7255 (defun org-agenda-do-context-action ()
7256 "Show outline path and, maybe, follow mode window."
7257 (let ((m (org-get-at-bol 'org-marker)))
7258 (when (and (markerp m) (marker-buffer m))
7259 (and org-agenda-follow-mode
7260 (if org-agenda-follow-indirect
7261 (org-agenda-tree-to-indirect-buffer)
7263 (and org-agenda-show-outline-path
7264 (org-with-point-at m (org-display-outline-path t))))))
7266 (defun org-agenda-show-priority ()
7267 "Show the priority of the current item.
7268 This priority is composed of the main priority given with the [#A] cookies,
7269 and by additional input from the age of a schedules or deadline entry."
7271 (let* ((pri (org-get-at-bol 'priority)))
7272 (message "Priority is %d" (if pri pri -1000))))
7274 (defun org-agenda-show-tags ()
7275 "Show the tags applicable to the current item."
7277 (let* ((tags (org-get-at-bol 'tags)))
7279 (message "Tags are :%s:"
7280 (org-no-properties (mapconcat 'identity tags ":")))
7281 (message "No tags associated with this line"))))
7283 (defun org-agenda-goto (&optional highlight)
7284 "Go to the Org-mode file which contains the item at point."
7286 (let* ((marker (or (org-get-at-bol 'org-marker)
7287 (org-agenda-error)))
7288 (buffer (marker-buffer marker))
7289 (pos (marker-position marker)))
7290 (switch-to-buffer-other-window buffer)
7294 (when (derived-mode-p 'org-mode)
7295 (org-show-context 'agenda)
7297 (and (outline-next-heading)
7298 (org-flag-heading nil)))) ; show the next heading
7299 (when (outline-invisible-p)
7300 (show-entry)) ; display invisible text
7301 (recenter (/ (window-height) 2))
7302 (run-hooks 'org-agenda-after-show-hook)
7303 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7305 (defvar org-agenda-after-show-hook nil
7306 "Normal hook run after an item has been shown from the agenda.
7307 Point is in the buffer where the item originated.")
7309 (defun org-agenda-kill ()
7310 "Kill the entry or subtree belonging to the current agenda entry."
7312 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7313 (let* ((marker (or (org-get-at-bol 'org-marker)
7314 (org-agenda-error)))
7315 (buffer (marker-buffer marker))
7316 (pos (marker-position marker))
7317 (type (org-get-at-bol 'type))
7318 dbeg dend (n 0) conf)
7319 (org-with-remote-undo buffer
7320 (with-current-buffer buffer
7323 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7324 (setq dbeg (progn (org-back-to-heading t) (point))
7325 dend (org-end-of-subtree t t))
7326 (setq dbeg (point-at-bol)
7327 dend (min (point-max) (1+ (point-at-eol)))))
7329 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7330 (setq conf (or (eq t org-agenda-confirm-kill)
7331 (and (numberp org-agenda-confirm-kill)
7332 (> n org-agenda-confirm-kill))))
7335 (format "Delete entry with %d lines in buffer \"%s\"? "
7336 n (buffer-name buffer))))
7338 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7339 (with-current-buffer buffer (delete-region dbeg dend))
7340 (message "Agenda item and source killed"))))
7342 (defvar org-archive-default-command)
7343 (defun org-agenda-archive-default ()
7344 "Archive the entry or subtree belonging to the current agenda entry."
7346 (require 'org-archive)
7347 (org-agenda-archive-with org-archive-default-command))
7349 (defun org-agenda-archive-default-with-confirmation ()
7350 "Archive the entry or subtree belonging to the current agenda entry."
7352 (require 'org-archive)
7353 (org-agenda-archive-with org-archive-default-command 'confirm))
7355 (defun org-agenda-archive ()
7356 "Archive the entry or subtree belonging to the current agenda entry."
7358 (org-agenda-archive-with 'org-archive-subtree))
7360 (defun org-agenda-archive-to-archive-sibling ()
7361 "Move the entry to the archive sibling."
7363 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7365 (defun org-agenda-archive-with (cmd &optional confirm)
7366 "Move the entry to the archive sibling."
7368 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7369 (let* ((marker (or (org-get-at-bol 'org-marker)
7370 (org-agenda-error)))
7371 (buffer (marker-buffer marker))
7372 (pos (marker-position marker)))
7373 (org-with-remote-undo buffer
7374 (with-current-buffer buffer
7375 (if (derived-mode-p 'org-mode)
7377 (not (y-or-n-p "Archive this subtree or entry? ")))
7381 (org-remove-subtree-entries-from-agenda)
7382 (org-back-to-heading t)
7384 (error "Archiving works only in Org-mode files"))))))
7386 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7387 "Remove all lines in the agenda that correspond to a given subtree.
7388 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7389 If this information is not given, the function uses the tree at point."
7390 (let ((buf (or buf (current-buffer))) m p)
7392 (unless (and beg end)
7393 (org-back-to-heading t)
7395 (org-end-of-subtree t)
7397 (set-buffer (get-buffer org-agenda-buffer-name))
7399 (goto-char (point-max))
7400 (beginning-of-line 1)
7402 (when (and (setq m (org-get-at-bol 'org-marker))
7403 (equal buf (marker-buffer m))
7404 (setq p (marker-position m))
7407 (let ((inhibit-read-only t))
7408 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7409 (beginning-of-line 0))))))
7411 (defun org-agenda-refile (&optional goto rfloc no-update)
7412 "Refile the item at point."
7414 (if (equal goto '(16))
7415 (org-refile-goto-last-stored)
7416 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7417 (org-agenda-error)))
7418 (buffer (marker-buffer marker))
7419 (pos (marker-position marker))
7421 (org-refile-get-location
7422 (if goto "Goto" "Refile to") buffer
7423 org-refile-allow-creating-parent-nodes))))
7424 (with-current-buffer buffer
7429 (org-remove-subtree-entries-from-agenda)
7430 (org-refile goto buffer rfloc)))))
7431 (unless no-update (org-agenda-redo))))
7433 (defun org-agenda-open-link (&optional arg)
7434 "Follow the link in the current line, if any.
7435 This looks for a link in the displayed line in the agenda. It also looks
7436 at the text of the entry itself."
7438 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7439 (org-get-at-bol 'org-marker)))
7440 (buffer (and marker (marker-buffer marker)))
7441 (prefix (buffer-substring
7442 (point-at-bol) (point-at-eol))))
7445 (with-current-buffer buffer
7450 (org-offer-links-in-entry arg prefix)))))
7451 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7453 (beginning-of-line 1)
7454 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7455 (org-open-link-from-string (match-string 1)))
7456 (t (error "No link to open here")))))
7458 (defun org-agenda-copy-local-variable (var)
7459 "Get a variable from a referenced buffer and install it here."
7460 (let ((m (org-get-at-bol 'org-marker)))
7461 (when (and m (buffer-live-p (marker-buffer m)))
7462 (org-set-local var (with-current-buffer (marker-buffer m)
7463 (symbol-value var))))))
7465 (defun org-agenda-switch-to (&optional delete-other-windows)
7466 "Go to the Org-mode file which contains the item at point."
7468 (if (and org-return-follows-link
7469 (not (org-get-at-bol 'org-marker))
7470 (org-in-regexp org-bracket-link-regexp))
7471 (org-open-link-from-string (match-string 0))
7472 (let* ((marker (or (org-get-at-bol 'org-marker)
7473 (org-agenda-error)))
7474 (buffer (marker-buffer marker))
7475 (pos (marker-position marker)))
7476 (org-pop-to-buffer-same-window buffer)
7477 (and delete-other-windows (delete-other-windows))
7480 (when (derived-mode-p 'org-mode)
7481 (org-show-context 'agenda)
7483 (and (outline-next-heading)
7484 (org-flag-heading nil))) ; show the next heading
7485 (when (outline-invisible-p)
7486 (show-entry)))))) ; display invisible text
7488 (defun org-agenda-goto-mouse (ev)
7489 "Go to the Org-mode file which contains the item at the mouse click."
7491 (mouse-set-point ev)
7494 (defun org-agenda-show (&optional full-entry)
7495 "Display the Org-mode file which contains the item at point.
7496 With prefix argument FULL-ENTRY, make the entire entry visible
7497 if it was hidden in the outline."
7499 (let ((win (selected-window)))
7501 (let ((org-show-entry-below t))
7502 (org-agenda-goto t))
7503 (org-agenda-goto t))
7504 (select-window win)))
7506 (defvar org-agenda-show-window nil)
7507 (defun org-agenda-show-and-scroll-up (&optional arg)
7508 "Display the Org-mode file which contains the item at point.
7509 When called repeatedly, scroll the window that is displaying the buffer.
7510 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7511 `show-subtree' to display the item, so that drawers and logbooks stay
7514 (let ((win (selected-window)))
7515 (if (and (window-live-p org-agenda-show-window)
7516 (eq this-command last-command))
7518 (select-window org-agenda-show-window)
7519 (ignore-errors (scroll-up)))
7521 (if arg (org-show-entry) (show-subtree))
7522 (setq org-agenda-show-window (selected-window)))
7523 (select-window win)))
7525 (defun org-agenda-show-scroll-down ()
7526 "Scroll down the window showing the agenda."
7528 (let ((win (selected-window)))
7529 (when (window-live-p org-agenda-show-window)
7530 (select-window org-agenda-show-window)
7531 (ignore-errors (scroll-down))
7532 (select-window win))))
7534 (defun org-agenda-show-1 (&optional more)
7535 "Display the Org-mode file which contains the item at point.
7536 The prefix arg selects the amount of information to display:
7539 1 just show the entry according to defaults.
7540 2 show the children view
7541 3 show the subtree view
7542 4 show the entire subtree and any LOGBOOK drawers
7543 5 show the entire subtree and any drawers
7544 With prefix argument FULL-ENTRY, make the entire entry visible
7545 if it was hidden in the outline."
7547 (let ((win (selected-window)))
7549 (org-recenter-heading 1)
7554 (org-back-to-heading)
7555 (run-hook-with-args 'org-cycle-hook 'folded))
7556 (message "Remote: FOLDED"))
7557 ((and (org-called-interactively-p 'any) (= more 1))
7558 (message "Remote: show with default settings"))
7563 (org-back-to-heading)
7564 (run-hook-with-args 'org-cycle-hook 'children))
7565 (message "Remote: CHILDREN"))
7569 (org-back-to-heading)
7570 (run-hook-with-args 'org-cycle-hook 'subtree))
7571 (message "Remote: SUBTREE"))
7573 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7575 (concat "^[ \t]*:\\("
7576 (mapconcat 'regexp-quote org-drawers "\\|")
7580 (org-back-to-heading)
7581 (org-cycle-hide-drawers 'subtree)))
7582 (message "Remote: SUBTREE AND LOGBOOK"))
7585 (message "Remote: SUBTREE AND ALL DRAWERS")))
7586 (select-window win)))
7588 (defun org-recenter-heading (n)
7590 (org-back-to-heading)
7593 (defvar org-agenda-cycle-counter nil)
7594 (defun org-agenda-cycle-show (&optional n)
7595 "Show the current entry in another window, with default settings.
7596 Default settings are taken from `org-show-hierarchy-above' and siblings.
7597 When use repeatedly in immediate succession, the remote entry will cycle
7600 children -> subtree -> folded
7602 When called with a numeric prefix arg, that arg will be passed through to
7603 `org-agenda-show-1'. For the interpretation of that argument, see the
7604 docstring of `org-agenda-show-1'."
7607 (setq org-agenda-cycle-counter n)
7608 (if (not (eq last-command this-command))
7609 (setq org-agenda-cycle-counter 1)
7610 (if (equal org-agenda-cycle-counter 0)
7611 (setq org-agenda-cycle-counter 2)
7612 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7613 (if (> org-agenda-cycle-counter 3)
7614 (setq org-agenda-cycle-counter 0)))))
7615 (org-agenda-show-1 org-agenda-cycle-counter))
7617 (defun org-agenda-recenter (arg)
7618 "Display the Org-mode file which contains the item at point and recenter."
7620 (let ((win (selected-window)))
7623 (select-window win)))
7625 (defun org-agenda-show-mouse (ev)
7626 "Display the Org-mode file which contains the item at the mouse click."
7628 (mouse-set-point ev)
7631 (defun org-agenda-check-no-diary ()
7632 "Check if the entry is a diary link and abort if yes."
7633 (if (org-get-at-bol 'org-agenda-diary-link)
7634 (org-agenda-error)))
7636 (defun org-agenda-error ()
7637 (error "Command not allowed in this line"))
7639 (defun org-agenda-tree-to-indirect-buffer ()
7640 "Show the subtree corresponding to the current entry in an indirect buffer.
7641 This calls the command `org-tree-to-indirect-buffer' from the original
7643 With numerical prefix arg ARG, go up to this level and then take that tree.
7644 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7645 use the dedicated frame)."
7647 (if (and current-prefix-arg (listp current-prefix-arg))
7648 (org-agenda-do-tree-to-indirect-buffer)
7649 (let ((agenda-window (selected-window))
7651 (and org-last-indirect-buffer
7652 (get-buffer-window org-last-indirect-buffer))))
7653 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7656 (unless (and indirect-window (window-live-p indirect-window))
7657 (setq indirect-window (split-window agenda-window)))
7658 (select-window indirect-window)
7659 (switch-to-buffer org-last-indirect-buffer :norecord)
7660 (fit-window-to-buffer indirect-window))
7661 (select-window (get-buffer-window org-agenda-buffer-name))))))
7663 (defun org-agenda-do-tree-to-indirect-buffer ()
7664 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7665 (org-agenda-check-no-diary)
7666 (let* ((marker (or (org-get-at-bol 'org-marker)
7667 (org-agenda-error)))
7668 (buffer (marker-buffer marker))
7669 (pos (marker-position marker)))
7670 (with-current-buffer buffer
7673 (call-interactively 'org-tree-to-indirect-buffer)))))
7675 (defvar org-last-heading-marker (make-marker)
7676 "Marker pointing to the headline that last changed its TODO state
7677 by a remote command from the agenda.")
7679 (defun org-agenda-todo-nextset ()
7680 "Switch TODO entry to next sequence."
7682 (org-agenda-todo 'nextset))
7684 (defun org-agenda-todo-previousset ()
7685 "Switch TODO entry to previous sequence."
7687 (org-agenda-todo 'previousset))
7689 (defun org-agenda-todo (&optional arg)
7690 "Cycle TODO state of line at point, also in Org-mode file.
7691 This changes the line at point, all other lines in the agenda referring to
7692 the same tree node, and the headline of the tree node in the Org-mode file."
7694 (org-agenda-check-no-diary)
7695 (let* ((col (current-column))
7696 (marker (or (org-get-at-bol 'org-marker)
7697 (org-agenda-error)))
7698 (buffer (marker-buffer marker))
7699 (pos (marker-position marker))
7700 (hdmarker (org-get-at-bol 'org-hd-marker))
7701 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7702 (inhibit-read-only t)
7703 org-agenda-headline-snapshot-before-repeat newhead just-one)
7704 (org-with-remote-undo buffer
7705 (with-current-buffer buffer
7708 (org-show-context 'agenda)
7710 (and (outline-next-heading)
7711 (org-flag-heading nil))) ; show the next heading
7712 (let ((current-prefix-arg arg))
7713 (call-interactively 'org-todo))
7714 (and (bolp) (forward-char 1))
7715 (setq newhead (org-get-heading))
7716 (when (and (org-bound-and-true-p
7717 org-agenda-headline-snapshot-before-repeat)
7718 (not (equal org-agenda-headline-snapshot-before-repeat
7721 (setq newhead org-agenda-headline-snapshot-before-repeat
7724 (org-back-to-heading)
7725 (move-marker org-last-heading-marker (point))))
7726 (beginning-of-line 1)
7728 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7729 (org-move-to-column col))))
7731 (defun org-agenda-add-note (&optional arg)
7732 "Add a time-stamped note to the entry at point."
7734 (org-agenda-check-no-diary)
7735 (let* ((marker (or (org-get-at-bol 'org-marker)
7736 (org-agenda-error)))
7737 (buffer (marker-buffer marker))
7738 (pos (marker-position marker))
7739 (hdmarker (org-get-at-bol 'org-hd-marker))
7740 (inhibit-read-only t))
7741 (with-current-buffer buffer
7744 (org-show-context 'agenda)
7746 (and (outline-next-heading)
7747 (org-flag-heading nil))) ; show the next heading
7750 (defun org-agenda-change-all-lines (newhead hdmarker
7751 &optional fixface just-this)
7752 "Change all lines in the agenda buffer which match HDMARKER.
7753 The new content of the line will be NEWHEAD (as modified by
7754 `org-agenda-format-item'). HDMARKER is checked with
7755 `equal' against all `org-hd-marker' text properties in the file.
7756 If FIXFACE is non-nil, the face of each item is modified according to
7758 If JUST-THIS is non-nil, change just the current line, not all.
7759 If FORCE-TAGS is non nil, the car of it returns the new tags."
7760 (let* ((inhibit-read-only t)
7761 (line (org-current-line))
7762 (org-agenda-buffer (current-buffer))
7763 (thetags (with-current-buffer (marker-buffer hdmarker)
7764 (save-excursion (save-restriction (widen)
7765 (goto-char hdmarker)
7766 (org-get-tags-at)))))
7767 props m pl undone-face done-face finish new dotime cat tags)
7769 (goto-char (point-max))
7770 (beginning-of-line 1)
7772 (setq finish (bobp))
7773 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7774 (or (not just-this) (= (org-current-line) line))
7776 (setq props (text-properties-at (point))
7777 dotime (org-get-at-bol 'dotime)
7778 cat (org-get-at-bol 'org-category)
7781 (let ((org-prefix-format-compiled
7782 (or (get-text-property (point) 'format)
7783 org-prefix-format-compiled))
7784 (extra (org-get-at-bol 'extra)))
7785 (with-current-buffer (marker-buffer hdmarker)
7789 (org-agenda-format-item extra newhead cat tags dotime)))))
7790 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7791 undone-face (org-get-at-bol 'undone-face)
7792 done-face (org-get-at-bol 'done-face))
7793 (beginning-of-line 1)
7796 (and (looking-at ".*\n?") (replace-match "")))
7798 (replace-match new t t)
7799 (beginning-of-line 1)
7800 (add-text-properties (point-at-bol) (point-at-eol) props)
7802 (add-text-properties
7803 (point-at-bol) (point-at-eol)
7805 (if org-last-todo-state-is-todo
7806 undone-face done-face))))
7807 (org-agenda-highlight-todo 'line)
7808 (beginning-of-line 1))
7809 (t (error "Line update did not work"))))
7810 (beginning-of-line 0)))
7811 (org-finalize-agenda)))
7813 (defun org-agenda-align-tags (&optional line)
7814 "Align all tags in agenda items to `org-agenda-tags-column'."
7815 (let ((inhibit-read-only t) l c)
7817 (goto-char (if line (point-at-bol) (point-min)))
7818 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7819 (if line (point-at-eol) nil) t)
7820 (add-text-properties
7821 (match-beginning 2) (match-end 2)
7822 (list 'face (delq nil (let ((prop (get-text-property
7823 (match-beginning 2) 'face)))
7824 (or (listp prop) (setq prop (list prop)))
7825 (if (memq 'org-tag prop)
7827 (cons 'org-tag prop))))))
7828 (setq l (- (match-end 2) (match-beginning 2))
7829 c (if (< org-agenda-tags-column 0)
7830 (- (abs org-agenda-tags-column) l)
7831 org-agenda-tags-column))
7832 (delete-region (match-beginning 1) (match-end 1))
7833 (goto-char (match-beginning 1))
7834 (insert (org-add-props
7835 (make-string (max 1 (- c (current-column))) ?\ )
7836 (plist-put (copy-sequence (text-properties-at (point)))
7838 (goto-char (point-min))
7839 (org-font-lock-add-tag-faces (point-max)))))
7841 (defun org-agenda-priority-up ()
7842 "Increase the priority of line at point, also in Org-mode file."
7844 (org-agenda-priority 'up))
7846 (defun org-agenda-priority-down ()
7847 "Decrease the priority of line at point, also in Org-mode file."
7849 (org-agenda-priority 'down))
7851 (defun org-agenda-priority (&optional force-direction)
7852 "Set the priority of line at point, also in Org-mode file.
7853 This changes the line at point, all other lines in the agenda referring to
7854 the same tree node, and the headline of the tree node in the Org-mode file."
7856 (unless org-enable-priority-commands
7857 (error "Priority commands are disabled"))
7858 (org-agenda-check-no-diary)
7859 (let* ((marker (or (org-get-at-bol 'org-marker)
7860 (org-agenda-error)))
7861 (hdmarker (org-get-at-bol 'org-hd-marker))
7862 (buffer (marker-buffer hdmarker))
7863 (pos (marker-position hdmarker))
7864 (inhibit-read-only t)
7866 (org-with-remote-undo buffer
7867 (with-current-buffer buffer
7870 (org-show-context 'agenda)
7872 (and (outline-next-heading)
7873 (org-flag-heading nil))) ; show the next heading
7874 (funcall 'org-priority force-direction)
7876 (setq newhead (org-get-heading)))
7877 (org-agenda-change-all-lines newhead hdmarker)
7878 (beginning-of-line 1))))
7880 ;; FIXME: should fix the tags property of the agenda line.
7881 (defun org-agenda-set-tags (&optional tag onoff)
7882 "Set tags for the current headline."
7884 (org-agenda-check-no-diary)
7885 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7886 (call-interactively 'org-change-tag-in-region)
7887 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7888 (org-agenda-error)))
7889 (buffer (marker-buffer hdmarker))
7890 (pos (marker-position hdmarker))
7891 (inhibit-read-only t)
7893 (org-with-remote-undo buffer
7894 (with-current-buffer buffer
7898 (org-show-context 'agenda))
7900 (and (outline-next-heading)
7901 (org-flag-heading nil))) ; show the next heading
7904 (org-toggle-tag tag onoff)
7905 (call-interactively 'org-set-tags))
7907 (setq newhead (org-get-heading)))
7908 (org-agenda-change-all-lines newhead hdmarker)
7909 (beginning-of-line 1)))))
7911 (defun org-agenda-set-property ()
7912 "Set a property for the current headline."
7914 (org-agenda-check-no-diary)
7915 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7916 (org-agenda-error)))
7917 (buffer (marker-buffer hdmarker))
7918 (pos (marker-position hdmarker))
7919 (inhibit-read-only t)
7921 (org-with-remote-undo buffer
7922 (with-current-buffer buffer
7926 (org-show-context 'agenda))
7928 (and (outline-next-heading)
7929 (org-flag-heading nil))) ; show the next heading
7931 (call-interactively 'org-set-property)))))
7933 (defun org-agenda-set-effort ()
7934 "Set the effort property for the current headline."
7936 (org-agenda-check-no-diary)
7937 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7938 (org-agenda-error)))
7939 (buffer (marker-buffer hdmarker))
7940 (pos (marker-position hdmarker))
7941 (inhibit-read-only t)
7943 (org-with-remote-undo buffer
7944 (with-current-buffer buffer
7948 (org-show-context 'agenda))
7950 (and (outline-next-heading)
7951 (org-flag-heading nil))) ; show the next heading
7953 (call-interactively 'org-set-effort)
7955 (setq newhead (org-get-heading)))
7956 (org-agenda-change-all-lines newhead hdmarker))))
7958 (defun org-agenda-toggle-archive-tag ()
7959 "Toggle the archive tag for the current entry."
7961 (org-agenda-check-no-diary)
7962 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7963 (org-agenda-error)))
7964 (buffer (marker-buffer hdmarker))
7965 (pos (marker-position hdmarker))
7966 (inhibit-read-only t)
7968 (org-with-remote-undo buffer
7969 (with-current-buffer buffer
7972 (org-show-context 'agenda)
7974 (and (outline-next-heading)
7975 (org-flag-heading nil))) ; show the next heading
7976 (call-interactively 'org-toggle-archive-tag)
7978 (setq newhead (org-get-heading)))
7979 (org-agenda-change-all-lines newhead hdmarker)
7980 (beginning-of-line 1))))
7982 (defun org-agenda-do-date-later (arg)
7985 ((or (equal arg '(16))
7987 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7988 (setq this-command 'org-agenda-date-later-minutes)
7989 (org-agenda-date-later-minutes 1))
7990 ((or (equal arg '(4))
7992 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7993 (setq this-command 'org-agenda-date-later-hours)
7994 (org-agenda-date-later-hours 1))
7996 (org-agenda-date-later (prefix-numeric-value arg)))))
7998 (defun org-agenda-do-date-earlier (arg)
8001 ((or (equal arg '(16))
8003 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8004 (setq this-command 'org-agenda-date-earlier-minutes)
8005 (org-agenda-date-earlier-minutes 1))
8006 ((or (equal arg '(4))
8008 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8009 (setq this-command 'org-agenda-date-earlier-hours)
8010 (org-agenda-date-earlier-hours 1))
8012 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8014 (defun org-agenda-date-later (arg &optional what)
8015 "Change the date of this item to ARG day(s) later."
8017 (org-agenda-check-type t 'agenda 'timeline)
8018 (org-agenda-check-no-diary)
8019 (let* ((marker (or (org-get-at-bol 'org-marker)
8020 (org-agenda-error)))
8021 (buffer (marker-buffer marker))
8022 (pos (marker-position marker))
8024 (org-with-remote-undo buffer
8025 (with-current-buffer buffer
8028 (if (not (org-at-timestamp-p))
8029 (error "Cannot find time stamp"))
8030 (when (and org-agenda-move-date-from-past-immediately-to-today
8032 (or (not what) (eq what 'day))
8033 (not (save-match-data (org-at-date-range-p))))
8034 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8035 cdate (calendar-absolute-from-gregorian
8036 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8039 ;; immediately shift to today
8040 (setq arg (- today cdate))))
8041 (org-timestamp-change arg (or what 'day))
8042 (when (and (org-at-date-range-p)
8043 (re-search-backward org-tr-regexp-both (point-at-bol)))
8044 (let ((end org-last-changed-timestamp))
8045 (org-timestamp-change arg (or what 'day))
8046 (setq org-last-changed-timestamp
8047 (concat org-last-changed-timestamp "--" end)))))
8048 (org-agenda-show-new-time marker org-last-changed-timestamp))
8049 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8051 (defun org-agenda-date-earlier (arg &optional what)
8052 "Change the date of this item to ARG day(s) earlier."
8054 (org-agenda-date-later (- arg) what))
8056 (defun org-agenda-date-later-minutes (arg)
8057 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8059 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8060 (org-agenda-date-later arg 'minute))
8062 (defun org-agenda-date-earlier-minutes (arg)
8063 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8065 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8066 (org-agenda-date-earlier arg 'minute))
8068 (defun org-agenda-date-later-hours (arg)
8069 "Change the time of this item, in hour steps."
8071 (org-agenda-date-later arg 'hour))
8073 (defun org-agenda-date-earlier-hours (arg)
8074 "Change the time of this item, in hour steps."
8076 (org-agenda-date-earlier arg 'hour))
8078 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8079 "Show new date stamp via text properties."
8080 ;; We use text properties to make this undoable
8081 (let ((inhibit-read-only t)
8082 (buffer-invisibility-spec))
8083 (setq stamp (concat " " prefix " => " stamp))
8085 (goto-char (point-max))
8087 (when (equal marker (org-get-at-bol 'org-marker))
8088 (org-move-to-column (- (window-width) (length stamp)) t)
8089 (org-agenda-fix-tags-filter-overlays-at (point))
8090 (if (featurep 'xemacs)
8091 ;; Use `duplicable' property to trigger undo recording
8092 (let ((ex (make-extent nil nil))
8093 (gl (make-glyph stamp)))
8094 (set-glyph-face gl 'secondary-selection)
8095 (set-extent-properties
8096 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8097 (insert-extent ex (1- (point)) (point-at-eol)))
8098 (add-text-properties
8099 (1- (point)) (point-at-eol)
8100 (list 'display (org-add-props stamp nil
8101 'face 'secondary-selection))))
8102 (beginning-of-line 1))
8103 (beginning-of-line 0)))))
8105 (defun org-agenda-date-prompt (arg)
8106 "Change the date of this item. Date is prompted for, with default today.
8107 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8108 be used to request time specification in the time stamp."
8110 (org-agenda-check-type t 'agenda 'timeline)
8111 (org-agenda-check-no-diary)
8112 (let* ((marker (or (org-get-at-bol 'org-marker)
8113 (org-agenda-error)))
8114 (buffer (marker-buffer marker))
8115 (pos (marker-position marker)))
8116 (org-with-remote-undo buffer
8117 (with-current-buffer buffer
8120 (if (not (org-at-timestamp-p t))
8121 (error "Cannot find time stamp"))
8122 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8123 (org-agenda-show-new-time marker org-last-changed-timestamp))
8124 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8126 (defun org-agenda-schedule (arg &optional time)
8127 "Schedule the item at point.
8128 ARG is passed through to `org-schedule'."
8130 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8131 (org-agenda-check-no-diary)
8132 (let* ((marker (or (org-get-at-bol 'org-marker)
8133 (org-agenda-error)))
8134 (type (marker-insertion-type marker))
8135 (buffer (marker-buffer marker))
8136 (pos (marker-position marker))
8137 (org-insert-labeled-timestamps-at-point nil)
8139 (set-marker-insertion-type marker t)
8140 (org-with-remote-undo buffer
8141 (with-current-buffer buffer
8144 (setq ts (org-schedule arg time)))
8145 (org-agenda-show-new-time marker ts "S"))
8146 (message "Item scheduled for %s" ts)))
8148 (defun org-agenda-deadline (arg &optional time)
8149 "Schedule the item at point.
8150 ARG is passed through to `org-deadline'."
8152 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8153 (org-agenda-check-no-diary)
8154 (let* ((marker (or (org-get-at-bol 'org-marker)
8155 (org-agenda-error)))
8156 (buffer (marker-buffer marker))
8157 (pos (marker-position marker))
8158 (org-insert-labeled-timestamps-at-point nil)
8160 (org-with-remote-undo buffer
8161 (with-current-buffer buffer
8164 (setq ts (org-deadline arg time)))
8165 (org-agenda-show-new-time marker ts "D"))
8166 (message "Deadline for this item set to %s" ts)))
8168 (defun org-agenda-action ()
8169 "Select entry for agenda action, or execute an agenda action.
8170 This command prompts for another letter. Valid inputs are:
8172 m Mark the entry at point for an agenda action
8173 s Schedule the marked entry to the date at the cursor
8174 d Set the deadline of the marked entry to the date at the cursor
8175 r Call `org-remember' with cursor date as the default date
8176 c Call `org-capture' with cursor date as the default date
8177 SPC Show marked entry in other window
8178 TAB Visit marked entry in other window
8180 The cursor may be at a date in the calendar, or in the Org agenda."
8183 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8184 (setq ans (read-char-exclusive))
8188 (if (eq major-mode 'org-agenda-mode)
8189 (let ((m (or (org-get-at-bol 'org-hd-marker)
8190 (org-get-at-bol 'org-marker))))
8193 (move-marker org-agenda-action-marker
8194 (marker-position m) (marker-buffer m))
8195 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8196 (error "Don't know which entry to mark")))
8197 (error "This command works only in the agenda")))
8199 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8201 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8203 (org-agenda-do-action '(org-remember) t))
8205 (org-agenda-do-action '(org-capture) t))
8207 (let ((cw (selected-window)))
8208 (org-switch-to-buffer-other-window
8209 (marker-buffer org-agenda-action-marker))
8210 (goto-char org-agenda-action-marker)
8211 (org-show-context 'agenda)
8212 (select-window cw)))
8214 (org-switch-to-buffer-other-window
8215 (marker-buffer org-agenda-action-marker))
8216 (goto-char org-agenda-action-marker)
8217 (org-show-context 'agenda))
8218 (t (error "Invalid agenda action %c" ans)))))
8220 (defun org-agenda-do-action (form &optional current-buffer)
8221 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8222 (let ((org-overriding-default-time (org-get-cursor-date)))
8225 (if (not (marker-buffer org-agenda-action-marker))
8226 (error "No entry has been selected for agenda action")
8227 (with-current-buffer (marker-buffer org-agenda-action-marker)
8231 (goto-char org-agenda-action-marker)
8234 (defun org-agenda-clock-in (&optional arg)
8235 "Start the clock on the currently selected item."
8237 (org-agenda-check-no-diary)
8238 (if (equal arg '(4))
8240 (let* ((marker (or (org-get-at-bol 'org-marker)
8241 (org-agenda-error)))
8242 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8244 (pos (marker-position marker))
8246 (org-with-remote-undo (marker-buffer marker)
8247 (with-current-buffer (marker-buffer marker)
8250 (org-show-context 'agenda)
8252 (org-cycle-hide-drawers 'children)
8254 (setq newhead (org-get-heading)))
8255 (org-agenda-change-all-lines newhead hdmarker)))))
8257 (defun org-agenda-clock-out ()
8258 "Stop the currently running clock."
8260 (unless (marker-buffer org-clock-marker)
8261 (error "No running clock"))
8262 (let ((marker (make-marker)) newhead)
8263 (org-with-remote-undo (marker-buffer org-clock-marker)
8264 (with-current-buffer (marker-buffer org-clock-marker)
8268 (goto-char org-clock-marker)
8269 (org-back-to-heading t)
8270 (move-marker marker (point))
8272 (setq newhead (org-get-heading))))))
8273 (org-agenda-change-all-lines newhead marker)
8274 (move-marker marker nil)))
8276 (defun org-agenda-clock-cancel (&optional arg)
8277 "Cancel the currently running clock."
8279 (unless (marker-buffer org-clock-marker)
8280 (error "No running clock"))
8281 (org-with-remote-undo (marker-buffer org-clock-marker)
8282 (org-clock-cancel)))
8284 (defun org-agenda-clock-goto ()
8285 "Jump to the currently clocked in task within the agenda.
8286 If the currently clocked in task is not listed in the agenda
8287 buffer, display it in another window."
8291 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8292 (setq pos (overlay-start o))))
8293 (overlays-in (point-min) (point-max)))
8294 (cond (pos (goto-char pos))
8295 ;; If the currently clocked entry is not in the agenda
8296 ;; buffer, we visit it in another window:
8297 (org-clock-current-task
8298 (org-switch-to-buffer-other-window (org-clock-goto)))
8299 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8301 (defun org-agenda-diary-entry-in-org-file ()
8302 "Make a diary entry in the file `org-agenda-diary-file'."
8303 (let (d1 d2 char (text "") dp1 dp2)
8304 (if (equal (buffer-name) "*Calendar*")
8305 (setq d1 (calendar-cursor-to-date t)
8306 d2 (car calendar-mark-ring))
8307 (setq dp1 (get-text-property (point-at-bol) 'day))
8308 (unless dp1 (error "No date defined in current line"))
8309 (setq d1 (calendar-gregorian-from-absolute dp1)
8310 d2 (and (ignore-errors (mark))
8313 (setq dp2 (get-text-property (point-at-bol) 'day)))
8314 (calendar-gregorian-from-absolute dp2))))
8315 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8316 (setq char (read-char-exclusive))
8319 (setq text (read-string "Day entry: "))
8320 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8321 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8323 (setq d1 (list (car d1) (nth 1 d1)
8324 (read-number (format "Reference year [%d]: " (nth 2 d1))
8326 (setq text (read-string "Anniversary (use %d to show years): "))
8327 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8328 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8330 (setq text (read-string "Block entry: "))
8331 (unless (and d1 d2 (not (equal d1 d2)))
8332 (error "No block of days selected"))
8333 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8334 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8336 (org-switch-to-buffer-other-window
8337 (find-file-noselect org-agenda-diary-file))
8338 (require 'org-datetree)
8339 (org-datetree-find-date-create d1)
8341 (t (error "Invalid selection character `%c'" char)))))
8343 (defcustom org-agenda-insert-diary-strategy 'date-tree
8344 "Where in `org-agenda-diary-file' should new entries be added?
8347 date-tree in the date tree, as child of the date
8348 top-level as top-level entries at the end of the file."
8351 (const :tag "in a date tree" date-tree)
8352 (const :tag "as top level at end of file" top-level)))
8354 (defcustom org-agenda-insert-diary-extract-time nil
8355 "Non-nil means extract any time specification from the diary entry."
8360 (defcustom org-agenda-bulk-mark-char ">"
8361 "A single-character string to be used as the bulk mark."
8366 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8367 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8368 If TEXT is not empty, it will become the headline of the new entry, and
8369 the resulting entry will not be shown. When TEXT is empty, switch to
8370 `org-agenda-diary-file' and let the user finish the entry there."
8371 (let ((cw (current-window-configuration)))
8372 (org-switch-to-buffer-other-window
8373 (find-file-noselect org-agenda-diary-file))
8375 (goto-char (point-min))
8377 ((eq type 'anniversary)
8378 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8380 (or (org-at-heading-p t)
8382 (outline-next-heading)
8383 (insert "* Anniversaries\n\n")
8384 (beginning-of-line -1)))))
8385 (outline-next-heading)
8386 (org-back-over-empty-lines)
8389 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8390 (nth 2 d1) (car d1) (nth 1 d1) text)))
8392 (let ((org-prefix-has-time t)
8393 (org-agenda-time-leading-zero t)
8395 (if org-agenda-insert-diary-extract-time
8396 ;; Use org-agenda-format-item to parse text for a time-range and
8397 ;; remove it. FIXME: This is a hack, we should refactor
8398 ;; that function to make time extraction available separately
8399 (setq fmt (org-agenda-format-item nil text nil nil t)
8400 time (get-text-property 0 'time fmt)
8401 time2 (if (> (length time) 0)
8402 ;; split-string removes trailing ...... if
8403 ;; no end time given. First space
8404 ;; separates time from date.
8405 (concat " " (car (split-string time "\\.")))
8407 text (get-text-property 0 'txt fmt)))
8408 (if (eq org-agenda-insert-diary-strategy 'top-level)
8409 (org-agenda-insert-diary-as-top-level text)
8410 (require 'org-datetree)
8411 (org-datetree-find-date-create d1)
8412 (org-agenda-insert-diary-make-new-entry text))
8413 (org-insert-time-stamp (org-time-from-absolute
8414 (calendar-absolute-from-gregorian d1))
8415 nil nil nil nil time2))
8418 (if (> (calendar-absolute-from-gregorian d1)
8419 (calendar-absolute-from-gregorian d2))
8420 (setq d1 (prog1 d2 (setq d2 d1))))
8421 (if (eq org-agenda-insert-diary-strategy 'top-level)
8422 (org-agenda-insert-diary-as-top-level text)
8423 (require 'org-datetree)
8424 (org-datetree-find-date-create d1)
8425 (org-agenda-insert-diary-make-new-entry text))
8426 (org-insert-time-stamp (org-time-from-absolute
8427 (calendar-absolute-from-gregorian d1)))
8429 (org-insert-time-stamp (org-time-from-absolute
8430 (calendar-absolute-from-gregorian d2)))
8432 (if (string-match "\\S-" text)
8434 (set-window-configuration cw)
8435 (message "%s entry added to %s"
8436 (capitalize (symbol-name type))
8437 (abbreviate-file-name org-agenda-diary-file)))
8439 (message "Please finish entry here"))))
8441 (defun org-agenda-insert-diary-as-top-level (text)
8442 "Make new entry as a top-level entry at the end of the file.
8443 Add TEXT as headline, and position the cursor in the second line so that
8444 a timestamp can be added there."
8446 (goto-char (point-max))
8447 (or (bolp) (insert "\n"))
8448 (insert "* " text "\n")
8449 (if org-adapt-indentation (org-indent-to-column 2)))
8451 (defun org-agenda-insert-diary-make-new-entry (text)
8452 "Make new entry as last child of current entry.
8453 Add TEXT as headline, and position the cursor in the second line so that
8454 a timestamp can be added there."
8455 (let ((org-show-following-heading t)
8456 (org-show-siblings t)
8457 (org-show-hierarchy-above t)
8458 (org-show-entry-below t)
8460 (outline-next-heading)
8461 (org-back-over-empty-lines)
8462 (or (looking-at "[ \t]*$")
8463 (progn (insert "\n") (backward-char 1)))
8464 (org-insert-heading nil t)
8466 (setq col (current-column))
8468 (if org-adapt-indentation (org-indent-to-column col))
8469 (let ((org-show-following-heading t)
8470 (org-show-siblings t)
8471 (org-show-hierarchy-above t)
8472 (org-show-entry-below t))
8473 (org-show-context))))
8475 (defun org-agenda-diary-entry ()
8476 "Make a diary entry, like the `i' command from the calendar.
8477 All the standard commands work: block, weekly etc.
8478 When `org-agenda-diary-file' points to a file,
8479 `org-agenda-diary-entry-in-org-file' is called instead to create
8480 entries in that Org-mode file."
8482 (org-agenda-check-type t 'agenda 'timeline)
8483 (if (not (eq org-agenda-diary-file 'diary-file))
8484 (org-agenda-diary-entry-in-org-file)
8485 (require 'diary-lib)
8487 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8488 (read-char-exclusive)))
8489 (cmd (cdr (assoc char
8490 '((?d . insert-diary-entry)
8491 (?w . insert-weekly-diary-entry)
8492 (?m . insert-monthly-diary-entry)
8493 (?y . insert-yearly-diary-entry)
8494 (?a . insert-anniversary-diary-entry)
8495 (?b . insert-block-diary-entry)
8496 (?c . insert-cyclic-diary-entry)))))
8497 (oldf (symbol-function 'calendar-cursor-to-date))
8498 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8500 (mark (or (mark t) (point))))
8502 (error "No command associated with <%c>" char))
8503 (unless (and (get-text-property point 'day)
8504 (or (not (equal ?b char))
8505 (get-text-property mark 'day)))
8506 (error "Don't know which date to use for diary entry"))
8507 ;; We implement this by hacking the `calendar-cursor-to-date' function
8508 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8509 (let ((calendar-mark-ring
8510 (list (calendar-gregorian-from-absolute
8511 (or (get-text-property mark 'day)
8512 (get-text-property point 'day))))))
8515 (fset 'calendar-cursor-to-date
8516 (lambda (&optional error dummy)
8517 (calendar-gregorian-from-absolute
8518 (get-text-property point 'day))))
8519 (call-interactively cmd))
8520 (fset 'calendar-cursor-to-date oldf))))))
8522 (defun org-agenda-execute-calendar-command (cmd)
8523 "Execute a calendar command from the agenda, with the date associated to
8524 the cursor position."
8525 (org-agenda-check-type t 'agenda 'timeline)
8526 (require 'diary-lib)
8527 (unless (get-text-property (point) 'day)
8528 (error "Don't know which date to use for calendar command"))
8529 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8531 (date (calendar-gregorian-from-absolute
8532 (get-text-property point 'day)))
8533 ;; the following 2 vars are needed in the calendar
8534 (displayed-month (car date))
8535 (displayed-year (nth 2 date)))
8538 (fset 'calendar-cursor-to-date
8539 (lambda (&optional error dummy)
8540 (calendar-gregorian-from-absolute
8541 (get-text-property point 'day))))
8542 (call-interactively cmd))
8543 (fset 'calendar-cursor-to-date oldf))))
8545 (defun org-agenda-phases-of-moon ()
8546 "Display the phases of the moon for the 3 months around the cursor date."
8548 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8550 (defun org-agenda-holidays ()
8551 "Display the holidays for the 3 months around the cursor date."
8553 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8555 (defvar calendar-longitude)
8556 (defvar calendar-latitude)
8557 (defvar calendar-location-name)
8559 (defun org-agenda-sunrise-sunset (arg)
8560 "Display sunrise and sunset for the cursor date.
8561 Latitude and longitude can be specified with the variables
8562 `calendar-latitude' and `calendar-longitude'. When called with prefix
8563 argument, latitude and longitude will be prompted for."
8566 (let ((calendar-longitude (if arg nil calendar-longitude))
8567 (calendar-latitude (if arg nil calendar-latitude))
8568 (calendar-location-name
8569 (if arg "the given coordinates" calendar-location-name)))
8570 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8572 (defun org-agenda-goto-calendar ()
8573 "Open the Emacs calendar with the date at the cursor."
8575 (org-agenda-check-type t 'agenda 'timeline)
8576 (let* ((day (or (get-text-property (point) 'day)
8577 (error "Don't know which date to open in calendar")))
8578 (date (calendar-gregorian-from-absolute day))
8579 (calendar-move-hook nil)
8580 (calendar-view-holidays-initially-flag nil)
8581 (calendar-view-diary-initially-flag nil))
8583 (calendar-goto-date date)))
8586 (defun org-calendar-goto-agenda ()
8587 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8588 This is a command that has to be installed in `calendar-mode-map'."
8590 (org-agenda-list nil (calendar-absolute-from-gregorian
8591 (calendar-cursor-to-date))
8594 (defun org-agenda-convert-date ()
8596 (org-agenda-check-type t 'agenda 'timeline)
8597 (let ((day (get-text-property (point) 'day))
8600 (error "Don't know which date to convert"))
8601 (setq date (calendar-gregorian-from-absolute day))
8603 "Gregorian: " (calendar-date-string date) "\n"
8604 "ISO: " (calendar-iso-date-string date) "\n"
8605 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8606 "Julian: " (calendar-julian-date-string date) "\n"
8607 "Astron. JD: " (calendar-astro-date-string date)
8608 " (Julian date number at noon UTC)\n"
8609 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8610 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8611 "French: " (calendar-french-date-string date) "\n"
8612 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8613 "Mayan: " (calendar-mayan-date-string date) "\n"
8614 "Coptic: " (calendar-coptic-date-string date) "\n"
8615 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8616 "Persian: " (calendar-persian-date-string date) "\n"
8617 "Chinese: " (calendar-chinese-date-string date) "\n"))
8618 (with-output-to-temp-buffer "*Dates*"
8620 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8624 (defvar org-agenda-bulk-marked-entries nil
8625 "List of markers that refer to marked entries in the agenda.")
8627 (defun org-agenda-bulk-marked-p ()
8628 (eq (get-char-property (point-at-bol) 'type)
8629 'org-marked-entry-overlay))
8631 (defun org-agenda-bulk-mark (&optional arg)
8632 "Mark the entry at point for future bulk action."
8634 (dotimes (i (or arg 1))
8635 (unless (org-get-at-bol 'org-agenda-diary-link)
8636 (let* ((m (org-get-at-bol 'org-hd-marker))
8638 (unless (org-agenda-bulk-marked-p)
8639 (unless m (error "Nothing to mark at point"))
8640 (push m org-agenda-bulk-marked-entries)
8641 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8642 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8643 (org-get-todo-face "TODO")
8645 (overlay-put ov 'type 'org-marked-entry-overlay))
8646 (beginning-of-line 2)
8647 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8648 (beginning-of-line 2))
8649 (message "%d entries marked for bulk action"
8650 (length org-agenda-bulk-marked-entries))))))
8652 (defun org-agenda-bulk-mark-all ()
8653 "Mark all entries for future agenda bulk action."
8655 (org-agenda-bulk-mark-regexp "."))
8657 (defun org-agenda-bulk-mark-regexp (regexp)
8658 "Mark entries matching REGEXP for future agenda bulk action."
8659 (interactive "sMark entries matching regexp: ")
8660 (let ((entries-marked 0))
8662 (goto-char (point-min))
8663 (goto-char (next-single-property-change (point) 'txt))
8664 (while (re-search-forward regexp nil t)
8665 (when (string-match regexp (get-text-property (point) 'txt))
8666 (setq entries-marked (1+ entries-marked))
8667 (call-interactively 'org-agenda-bulk-mark))))
8668 (if (not entries-marked)
8669 (message "No entry matching this regexp."))))
8671 (defun org-agenda-bulk-unmark (&optional arg)
8672 "Unmark the entry at point for future bulk action."
8675 (org-agenda-bulk-unmark-all)
8676 (cond ((org-agenda-bulk-marked-p)
8677 (org-agenda-bulk-remove-overlays
8678 (point-at-bol) (+ 2 (point-at-bol)))
8679 (setq org-agenda-bulk-marked-entries
8680 (delete (org-get-at-bol 'org-hd-marker)
8681 org-agenda-bulk-marked-entries))
8682 (beginning-of-line 2)
8683 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8684 (beginning-of-line 2))
8685 (message "%d entries left marked for bulk action"
8686 (length org-agenda-bulk-marked-entries)))
8687 (t (message "No entry to unmark here")))))
8689 (defun org-agenda-bulk-toggle ()
8690 "Toggle marking the entry at point for bulk action."
8692 (if (org-agenda-bulk-marked-p)
8693 (org-agenda-bulk-unmark)
8694 (org-agenda-bulk-mark)))
8696 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8697 "Remove the mark overlays between BEG and END in the agenda buffer.
8698 BEG and END default to the buffer limits.
8700 This only removes the overlays, it does not remove the markers
8701 from the list in `org-agenda-bulk-marked-entries'."
8704 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8705 (delete-overlay ov)))
8706 (overlays-in (or beg (point-min)) (or end (point-max)))))
8708 (defun org-agenda-bulk-unmark-all ()
8709 "Remove all marks in the agenda buffer.
8710 This will remove the markers and the overlays."
8712 (if (null org-agenda-bulk-marked-entries)
8713 (message "No entry to unmark")
8714 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8715 (setq org-agenda-bulk-marked-entries nil)
8716 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8718 (defcustom org-agenda-persistent-marks nil
8719 "Non-nil means marked items will stay marked after a bulk action.
8720 You can interactively and temporarily toggle by typing `p' when you
8721 are prompted for a bulk action."
8726 (defun org-agenda-bulk-action (&optional arg)
8727 "Execute an remote-editing action on all marked entries.
8728 The prefix arg is passed through to the command if possible."
8730 ;; Make sure we have markers, and only valid ones
8731 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8734 (unless (and (markerp m)
8736 (buffer-live-p (marker-buffer m))
8737 (marker-position m))
8738 (error "Marker %s for bulk command is invalid" m)))
8739 org-agenda-bulk-marked-entries)
8741 ;; Prompt for the bulk command
8742 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8743 (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
8744 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
8745 (when org-agenda-bulk-custom-functions
8746 (concat " Custom: ["
8747 (mapconcat (lambda(f) (char-to-string (car f)))
8748 org-agenda-bulk-custom-functions "")
8751 (let* ((action (read-char-exclusive))
8752 (org-log-refile (if org-log-refile 'time nil))
8753 (entries (reverse org-agenda-bulk-marked-entries))
8755 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8758 (let ((org-agenda-persistent-marks
8759 (not org-agenda-persistent-marks)))
8760 (org-agenda-bulk-action)
8764 (setq cmd '(org-agenda-archive)))
8767 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8769 ((member action '(?r ?w))
8770 (setq rfloc (org-refile-get-location
8772 (marker-buffer (car org-agenda-bulk-marked-entries))
8773 org-refile-allow-creating-parent-nodes))
8775 (setcar (nthcdr 3 rfloc)
8776 (move-marker (make-marker) (nth 3 rfloc)
8777 (or (get-file-buffer (nth 1 rfloc))
8778 (find-buffer-visiting (nth 1 rfloc))
8779 (error "This should not happen")))))
8781 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8785 (setq state (org-icompleting-read
8787 (with-current-buffer (marker-buffer (car entries))
8788 (mapcar 'list org-todo-keywords-1))))
8789 (setq cmd `(let ((org-inhibit-blocking t)
8790 (org-inhibit-logging 'note))
8791 (org-agenda-todo ,state))))
8793 ((memq action '(?- ?+))
8794 (setq tag (org-icompleting-read
8795 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8796 (with-current-buffer (marker-buffer (car entries))
8799 (if (stringp (car x)) x)) org-tag-alist)))))
8800 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8802 ((memq action '(?s ?d))
8803 (let* ((date (unless arg
8806 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8807 (ans (if arg nil org-read-date-final-answer))
8808 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8809 (setq cmd `(let* ((bound (fboundp 'read-string))
8810 (old (and bound (symbol-function 'read-string))))
8813 (fset 'read-string (lambda (&rest ignore) ,ans))
8816 (fset 'read-string old)
8817 (fmakunbound 'read-string)))))))
8820 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8821 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8822 (let ((days (read-number
8823 (format "Scatter tasks across how many %sdays: "
8824 (if arg "week" "")) 7)))
8826 `(let ((distance (1+ (random ,days))))
8828 (let ((dist distance)
8830 (calendar-day-of-week
8831 (calendar-gregorian-from-absolute (org-today)))))
8832 (dotimes (i (1+ dist))
8833 (while (member day-of-week org-agenda-weekend-days)
8836 (if (= day-of-week 7)
8837 (setq day-of-week 0)))
8839 (if (= day-of-week 7)
8840 (setq day-of-week 0)))))
8841 ;; silently fail when try to replan a sexp entry
8843 (let* ((date (calendar-gregorian-from-absolute
8844 (+ (org-today) distance)))
8845 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8847 (org-agenda-schedule nil time))
8850 ((assoc action org-agenda-bulk-custom-functions)
8851 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8855 (setq cmd (list (intern
8856 (org-icompleting-read "Function: "
8857 obarray 'fboundp t nil nil)))))
8859 (t (error "Invalid bulk action")))
8861 ;; Sort the markers, to make sure that parents are handled before children
8862 (setq entries (sort entries
8865 ((equal (marker-buffer a) (marker-buffer b))
8866 (< (marker-position a) (marker-position b)))
8868 (string< (buffer-name (marker-buffer a))
8869 (buffer-name (marker-buffer b))))))))
8871 ;; Now loop over all markers and apply cmd
8872 (while (setq e (pop entries))
8873 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8875 (progn (message "Skipping removed entry at %s" e)
8876 (setq cntskip (1+ cntskip)))
8878 (let (org-loop-over-headlines-in-active-region)
8880 (when (not org-agenda-persistent-marks)
8881 (setq org-agenda-bulk-marked-entries
8882 (delete e org-agenda-bulk-marked-entries)))
8883 (setq cnt (1+ cnt))))
8884 (when (not org-agenda-persistent-marks)
8885 (org-agenda-bulk-unmark-all))
8886 (when redo-at-end (org-agenda-redo))
8887 (message "Acted on %d entries%s%s"
8891 (format ", skipped %d (disappeared before their turn)"
8893 (if (not org-agenda-persistent-marks)
8894 "" " (kept marked)"))))))
8898 (defun org-agenda-show-the-flagging-note ()
8899 "Display the flagging note in the other window.
8900 When called a second time in direct sequence, offer to remove the FLAGGING
8901 tag and (if present) the flagging note."
8903 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8904 (win (selected-window))
8905 note heading newhead)
8907 (error "No linked entry at point"))
8908 (if (and (eq this-command last-command)
8909 (y-or-n-p "Unflag and remove any flagging note? "))
8911 (org-agenda-remove-flag hdmarker)
8912 (let ((win (get-buffer-window "*Flagging Note*")))
8913 (and win (delete-window win)))
8914 (message "Entry unflagged"))
8915 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8917 (error "No flagging note"))
8919 (org-switch-to-buffer-other-window "*Flagging Note*")
8922 (goto-char (point-min))
8923 (while (re-search-forward "\\\\n" nil t)
8924 (replace-match "\n" t t))
8925 (goto-char (point-min))
8927 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8929 (defun org-agenda-remove-flag (marker)
8930 "Remove the FLAGGED tag and any flagging note in the entry."
8932 (org-with-point-at marker
8933 (org-toggle-tag "FLAGGED" 'off)
8934 (org-entry-delete nil "THEFLAGGINGNOTE")
8935 (setq newhead (org-get-heading)))
8936 (org-agenda-change-all-lines newhead marker)
8937 (message "Entry unflagged")))
8939 (defun org-agenda-get-any-marker (&optional pos)
8940 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8941 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8943 ;;; Appointment reminders
8945 (defvar appt-time-msg-list)
8948 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8949 "Activate appointments found in `org-agenda-files'.
8950 With a \\[universal-argument] prefix, refresh the list of
8953 If FILTER is t, interactively prompt the user for a regular
8954 expression, and filter out entries that don't match it.
8956 If FILTER is a string, use this string as a regular expression
8957 for filtering entries out.
8959 If FILTER is a function, filter out entries against which
8960 calling the function returns nil. This function takes one
8961 argument: an entry from `org-agenda-get-day-entries'.
8963 FILTER can also be an alist with the car of each cell being
8964 either 'headline or 'category. For example:
8966 '((headline \"IMPORTANT\")
8967 (category \"Work\"))
8969 will only add headlines containing IMPORTANT or headlines
8970 belonging to the \"Work\" category.
8972 ARGS are symbols indicating what kind of entries to consider.
8973 By default `org-agenda-to-appt' will use :deadline, :scheduled
8974 and :timestamp entries. See the docstring of `org-diary' for
8975 details and examples."
8977 (if refresh (setq appt-time-msg-list nil))
8979 (setq filter (read-from-minibuffer "Regexp filter: ")))
8980 (let* ((cnt 0) ; count added events
8981 (scope (or args '(:deadline :scheduled :timestamp)))
8982 (org-agenda-new-buffers nil)
8983 (org-deadline-warning-days 0)
8984 ;; Do not use `org-today' here because appt only takes
8985 ;; time and without date as argument, so it may pass wrong
8986 ;; information otherwise
8987 (today (org-date-to-gregorian
8988 (time-to-days (current-time))))
8989 (org-agenda-restrict nil)
8990 (files (org-agenda-files 'unrestricted)) entries file
8991 (org-agenda-buffer nil))
8992 ;; Get all entries which may contain an appt
8993 (org-prepare-agenda-buffers files)
8994 (while (setq file (pop files))
8998 (apply 'org-agenda-get-day-entries
8999 file today scope)))))
9000 ;; Map thru entries and find if we should filter them out
9003 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9004 (cat (get-text-property 1 'org-category x))
9005 (tod (get-text-property 1 'time-of-day x))
9006 (ok (or (null filter)
9007 (and (stringp filter) (string-match filter evt))
9008 (and (functionp filter) (funcall filter x))
9010 (let ((cat-filter (cadr (assoc 'category filter)))
9011 (evt-filter (cadr (assoc 'headline filter))))
9012 (or (and (stringp cat-filter)
9013 (string-match cat-filter cat))
9014 (and (stringp evt-filter)
9015 (string-match evt-filter evt))))))))
9016 ;; FIXME: Shall we remove text-properties for the appt text?
9017 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9019 (setq tod (concat "00" (number-to-string tod))
9020 tod (when (string-match
9021 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9022 (concat (match-string 1 tod) ":"
9023 (match-string 2 tod))))
9025 (setq cnt (1+ cnt))))) entries)
9026 (org-release-buffers org-agenda-new-buffers)
9028 (message "No event to add")
9029 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9031 (defun org-agenda-todayp (date)
9032 "Does DATE mean today, when considering `org-extend-today-until'?"
9033 (let ((today (org-today))
9034 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9038 (defun org-agenda-todo-yesterday (&optional arg)
9039 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9041 (let* ((hour (third (decode-time
9042 (org-current-time))))
9043 (org-extend-today-until (1+ hour)))
9044 (org-agenda-todo arg)))
9046 (provide 'org-agenda)
9048 ;;; org-agenda.el ends here