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)))
2888 (defun org-store-agenda-views (&rest parameters)
2890 (eval (list 'org-batch-store-agenda-views)))
2893 (defmacro org-batch-store-agenda-views (&rest parameters)
2894 "Run all custom agenda commands that have a file argument."
2895 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2897 (dir default-directory)
2898 (pars (org-make-parameter-alist parameters))
2899 cmd thiscmdkey files opts cmd-or-set bufname)
2900 (save-window-excursion
2902 (setq cmd (pop cmds)
2903 thiscmdkey (car cmd)
2904 bufname (if org-agenda-sticky (format "*Org Agenda(%s)*" thiscmdkey)
2905 org-agenda-buffer-name)
2906 cmd-or-set (nth 2 cmd)
2907 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2908 files (nth (if (listp cmd-or-set) 4 5) cmd))
2909 (if (stringp files) (setq files (list files)))
2911 (org-eval-in-environment (append org-agenda-exporter-settings
2913 (org-agenda nil thiscmdkey))
2914 (set-buffer bufname)
2916 (org-eval-in-environment (append org-agenda-exporter-settings
2918 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
2919 (and (get-buffer bufname)
2920 (kill-buffer bufname)))))))
2921 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2923 (defun org-agenda-mark-header-line (pos)
2924 "Mark the line at POS as an agenda structure header."
2927 (put-text-property (point-at-bol) (point-at-eol)
2928 'org-agenda-structural-header t)
2929 (when org-agenda-title-append
2930 (put-text-property (point-at-bol) (point-at-eol)
2931 'org-agenda-title-append org-agenda-title-append))))
2933 (defvar org-mobile-creating-agendas)
2934 (defvar org-agenda-write-buffer-name "Agenda View")
2935 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
2936 "Write the current buffer (an agenda view) as a file.
2937 Depending on the extension of the file name, plain text (.txt),
2938 HTML (.html or .htm) or Postscript (.ps) is produced.
2939 If the extension is .ics, run icalendar export over all files used
2940 to construct the agenda and limit the export to entries listed in the
2942 With prefix argument OPEN, open the new file immediately.
2943 If NOSETTINGS is given, do not scope the settings of
2944 `org-agenda-exporter-settings' into the export commands. This is used when
2945 the settings have already been scoped and we do not wish to overrule other,
2946 higher priority settings.
2947 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
2948 (interactive "FWrite agenda to file: \nP")
2949 (if (not (file-writable-p file))
2950 (error "Cannot write agenda to file %s" file))
2951 (org-let (if nosettings nil org-agenda-exporter-settings)
2953 (save-window-excursion
2954 (org-agenda-mark-filtered-text)
2955 (let ((bs (copy-sequence (buffer-string))) beg)
2956 (org-agenda-unmark-filtered-text)
2958 (rename-buffer org-agenda-write-buffer-name t)
2959 (set-buffer-modified-p nil)
2961 (org-agenda-remove-marked-text 'org-filtered)
2962 (while (setq beg (text-property-any (point-min) (point-max)
2965 beg (or (next-single-property-change beg 'org-filtered)
2967 (run-hooks 'org-agenda-before-write-hook)
2969 ((org-bound-and-true-p org-mobile-creating-agendas)
2970 (org-mobile-write-agenda-for-mobile file))
2971 ((string-match "\\.html?\\'" file)
2973 (set-buffer (htmlize-buffer (current-buffer)))
2974 (when (and org-agenda-export-html-style
2975 (string-match "<style>" org-agenda-export-html-style))
2976 ;; replace <style> section with org-agenda-export-html-style
2977 (goto-char (point-min))
2978 (kill-region (- (search-forward "<style") 6)
2979 (search-forward "</style>"))
2980 (insert org-agenda-export-html-style))
2982 (kill-buffer (current-buffer))
2983 (message "HTML written to %s" file))
2984 ((string-match "\\.ps\\'" file)
2986 (ps-print-buffer-with-faces file)
2987 (message "Postscript written to %s" file))
2988 ((string-match "\\.pdf\\'" file)
2990 (ps-print-buffer-with-faces
2991 (concat (file-name-sans-extension file) ".ps"))
2992 (call-process "ps2pdf" nil nil nil
2994 (concat (file-name-sans-extension file) ".ps"))
2995 (expand-file-name file))
2996 (delete-file (concat (file-name-sans-extension file) ".ps"))
2997 (message "PDF written to %s" file))
2998 ((string-match "\\.ics\\'" file)
2999 (require 'org-icalendar)
3000 (let ((org-agenda-marker-table
3001 (org-create-marker-find-array
3002 (org-agenda-collect-markers)))
3003 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3004 (org-combined-agenda-icalendar-file file))
3005 (apply 'org-export-icalendar 'combine
3006 (org-agenda-files nil 'ifmode))))
3008 (let ((bs (buffer-string)))
3013 (kill-buffer (current-buffer))
3014 (message "Plain text written to %s" file))))))))
3015 (set-buffer (or agenda-bufname
3016 (and (called-interactively-p 'any) (buffer-name))
3017 org-agenda-buffer-name)))
3018 (when open (org-open-file file)))
3020 (defvar org-agenda-tag-filter-overlays nil)
3021 (defvar org-agenda-cat-filter-overlays nil)
3023 (defun org-agenda-mark-filtered-text ()
3024 "Mark all text hidden by filtering with a text property."
3025 (let ((inhibit-read-only t))
3028 (when (equal (overlay-buffer o) (current-buffer))
3030 (overlay-start o) (overlay-end o)
3032 (append org-agenda-tag-filter-overlays
3033 org-agenda-cat-filter-overlays))))
3035 (defun org-agenda-unmark-filtered-text ()
3036 "Remove the filtering text property."
3037 (let ((inhibit-read-only t))
3038 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3040 (defun org-agenda-remove-marked-text (property &optional value)
3041 "Delete all text marked with VALUE of PROPERTY.
3042 VALUE defaults to t."
3044 (setq value (or value t))
3045 (while (setq beg (text-property-any (point-min) (point-max)
3048 beg (or (next-single-property-change beg 'org-filtered)
3051 (defun org-agenda-add-entry-text ()
3052 "Add entry text to agenda lines.
3053 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3054 entry text following headings shown in the agenda.
3055 Drawers will be excluded, also the line with scheduling/deadline info."
3056 (when (and (> org-agenda-add-entry-text-maxlines 0)
3057 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3059 (goto-char (point-min))
3061 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3062 (beginning-of-line 2)
3063 (setq txt (org-agenda-get-some-entry-text
3064 m org-agenda-add-entry-text-maxlines " > "))
3066 (if (string-match "\\S-" txt)
3068 (or (eobp) (forward-char 1))))))))
3070 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3072 "Extract entry text from MARKER, at most N-LINES lines.
3073 This will ignore drawers etc, just get the text.
3074 If INDENT is given, prefix every line with this string. If KEEP is
3075 given, it is a list of symbols, defining stuff that should not be
3076 removed from the entry content. Currently only `planning' is allowed here."
3077 (let (txt drawer-re kwd-time-re ind)
3079 (with-current-buffer (marker-buffer marker)
3080 (if (not (derived-mode-p 'org-mode))
3087 (setq txt (buffer-substring
3088 (min (1+ (point)) (point-max))
3089 (progn (outline-next-heading) (point)))
3090 drawer-re org-drawer-regexp
3091 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3095 (when org-agenda-add-entry-text-descriptive-links
3096 (goto-char (point-min))
3097 (while (org-activate-bracket-links (point-max))
3098 (add-text-properties (match-beginning 0) (match-end 0)
3100 (goto-char (point-min))
3101 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3102 (set-text-properties (match-beginning 0) (match-end 0)
3104 (goto-char (point-min))
3105 (while (re-search-forward drawer-re nil t)
3108 (progn (re-search-forward
3109 "^[ \t]*:END:.*\n?" nil 'move)
3111 (unless (member 'planning keep)
3112 (goto-char (point-min))
3113 (while (re-search-forward kwd-time-re nil t)
3114 (replace-match "")))
3115 (goto-char (point-min))
3116 (when org-agenda-entry-text-exclude-regexps
3117 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3118 (while (setq re (pop re-list))
3119 (goto-char (point-min))
3120 (while (re-search-forward re nil t)
3121 (replace-match "")))))
3122 (goto-char (point-max))
3123 (skip-chars-backward " \t\n")
3124 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3126 ;; find and remove min common indentation
3127 (goto-char (point-min))
3128 (untabify (point-min) (point-max))
3129 (setq ind (org-get-indentation))
3131 (unless (looking-at "[ \t]*$")
3132 (setq ind (min ind (org-get-indentation))))
3133 (beginning-of-line 2))
3134 (goto-char (point-min))
3136 (unless (looking-at "[ \t]*$")
3137 (move-to-column ind)
3138 (delete-region (point-at-bol) (point)))
3139 (beginning-of-line 2))
3141 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3143 (goto-char (point-min))
3145 (while (and (not (eobp)) (re-search-forward "^" nil t))
3146 (replace-match indent t t)))
3147 (goto-char (point-min))
3148 (while (looking-at "[ \t]*\n") (replace-match ""))
3149 (goto-char (point-max))
3150 (when (> (org-current-line)
3152 (org-goto-line (1+ n-lines))
3154 (setq txt (buffer-substring (point-min) (point)))))))))
3157 (defun org-agenda-collect-markers ()
3158 "Collect the markers pointing to entries in the agenda buffer."
3161 (goto-char (point-min))
3163 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3164 (org-get-at-bol 'org-marker)))
3166 (beginning-of-line 2)))
3167 (nreverse markers)))
3169 (defun org-create-marker-find-array (marker-list)
3170 "Create a alist of files names with all marker positions in that file."
3172 (while (setq m (pop marker-list))
3173 (setq p (marker-position m)
3174 f (buffer-file-name (or (buffer-base-buffer
3176 (marker-buffer m))))
3177 (if (setq a (assoc f tbl))
3178 (push (marker-position m) (cdr a))
3179 (push (list f p) tbl)))
3180 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3183 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3184 (defun org-check-agenda-marker-table ()
3185 "Check of the current entry is on the marker list."
3186 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3188 (and (setq a (assoc file org-agenda-marker-table))
3191 (org-back-to-heading t)
3192 (member (point) (cdr a)))))))
3194 (defun org-check-for-org-mode ()
3195 "Make sure current buffer is in org-mode. Error if not."
3196 (or (derived-mode-p 'org-mode)
3197 (error "Cannot execute org-mode agenda command on buffer in %s"
3200 (defun org-fit-agenda-window ()
3201 "Fit the window to the buffer size."
3202 (and (memq org-agenda-window-setup '(reorganize-frame))
3203 (fboundp 'fit-window-to-buffer)
3204 (org-fit-window-to-buffer
3206 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3207 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3209 ;;; Agenda prepare and finalize
3211 (defvar org-agenda-multi nil) ; dynamically scoped
3212 (defvar org-agenda-buffer-name "*Org Agenda*")
3213 (defvar org-pre-agenda-window-conf nil)
3214 (defvar org-agenda-columns-active nil)
3215 (defvar org-agenda-name nil)
3216 (defvar org-agenda-tag-filter nil)
3217 (defvar org-agenda-category-filter nil)
3218 (defvar org-agenda-top-category-filter nil)
3219 (defvar org-agenda-tag-filter-while-redo nil)
3220 (defvar org-agenda-tag-filter-preset nil
3221 "A preset of the tags filter used for secondary agenda filtering.
3222 This must be a list of strings, each string must be a single tag preceded
3224 This variable should not be set directly, but agenda custom commands can
3225 bind it in the options section. The preset filter is a global property of
3226 the entire agenda view. In a block agenda, it will not work reliably to
3227 define a filter for one of the individual blocks. You need to set it in
3228 the global options and expect it to be applied to the entire view.")
3230 (defvar org-agenda-category-filter-preset nil
3231 "A preset of the category filter used for secondary agenda filtering.
3232 This must be a list of strings, each string must be a single category
3233 preceded by \"+\" or \"-\".
3234 This variable should not be set directly, but agenda custom commands can
3235 bind it in the options section. The preset filter is a global property of
3236 the entire agenda view. In a block agenda, it will not work reliably to
3237 define a filter for one of the individual blocks. You need to set it in
3238 the global options and expect it to be applied to the entire view.")
3241 (defun org-agenda-use-sticky-p ()
3242 "Return non-nil if an agenda buffer named
3243 `org-agenda-buffer-name' exists and should be shown instead of
3244 generating a new one."
3246 ;; turned off by user
3248 ;; For multi-agenda buffer already exists
3249 (not org-agenda-multi)
3251 (get-buffer org-agenda-buffer-name)
3252 ;; C-u parameter is same as last call
3253 (with-current-buffer (get-buffer org-agenda-buffer-name)
3255 (equal current-prefix-arg
3256 org-agenda-last-prefix-arg)
3257 ;; In case user turned stickiness on, while having existing
3258 ;; Agenda buffer active, don't reuse that buffer, because it
3259 ;; does not have org variables local
3260 org-agenda-this-buffer-is-sticky))))
3262 (defun org-prepare-agenda-window (abuf)
3263 "Setup agenda buffer in the window."
3264 (let* ((awin (get-buffer-window abuf))
3267 ((equal (current-buffer) abuf) nil)
3268 (awin (select-window awin))
3269 ((not (setq wconf (current-window-configuration))))
3270 ((equal org-agenda-window-setup 'current-window)
3271 (org-pop-to-buffer-same-window abuf))
3272 ((equal org-agenda-window-setup 'other-window)
3273 (org-switch-to-buffer-other-window abuf))
3274 ((equal org-agenda-window-setup 'other-frame)
3275 (switch-to-buffer-other-frame abuf))
3276 ((equal org-agenda-window-setup 'reorganize-frame)
3277 (delete-other-windows)
3278 (org-switch-to-buffer-other-window abuf)))
3279 ;; additional test in case agenda is invoked from within agenda
3280 ;; buffer via elisp link
3281 (unless (equal (current-buffer) abuf)
3282 (org-pop-to-buffer-same-window abuf))
3283 (setq org-pre-agenda-window-conf wconf)))
3285 (defun org-prepare-agenda (&optional name)
3286 (if (org-agenda-use-sticky-p)
3288 ;; Popup existing buffer
3289 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3290 (message "Sticky Agenda buffer, use `r' to refresh")
3292 (setq org-todo-keywords-for-agenda nil)
3293 (setq org-drawers-for-agenda nil)
3294 (unless org-agenda-persistent-filter
3295 (setq org-agenda-tag-filter nil
3296 org-agenda-category-filter nil))
3297 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3298 (put 'org-agenda-category-filter :preset-filter
3299 org-agenda-category-filter-preset)
3300 (if org-agenda-multi
3302 (setq buffer-read-only nil)
3303 (goto-char (point-max))
3304 (unless (or (bobp) org-agenda-compact-blocks
3305 (not org-agenda-block-separator))
3307 (if (stringp org-agenda-block-separator)
3308 org-agenda-block-separator
3309 (make-string (window-width) org-agenda-block-separator))
3311 (narrow-to-region (point) (point-max)))
3312 (setq org-done-keywords-for-agenda nil)
3314 ;; Setting any org variables that are in org-agenda-local-vars
3315 ;; list need to be done after the prepare call
3316 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3317 (setq buffer-read-only nil)
3318 (org-agenda-reset-markers)
3319 (let ((inhibit-read-only t)) (erase-buffer))
3321 (setq org-agenda-buffer (current-buffer))
3322 (setq org-agenda-contributing-files nil)
3323 (setq org-agenda-columns-active nil)
3324 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3325 (setq org-todo-keywords-for-agenda
3326 (org-uniquify org-todo-keywords-for-agenda))
3327 (setq org-done-keywords-for-agenda
3328 (org-uniquify org-done-keywords-for-agenda))
3329 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3330 (setq org-agenda-last-prefix-arg current-prefix-arg)
3331 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3332 (and name (not org-agenda-name)
3333 (org-set-local 'org-agenda-name name)))
3334 (setq buffer-read-only nil)))
3336 (defun org-finalize-agenda ()
3337 "Finishing touch for the agenda buffer, called just before displaying it."
3338 (unless org-agenda-multi
3340 (let ((inhibit-read-only t))
3341 (goto-char (point-min))
3342 (while (org-activate-bracket-links (point-max))
3343 (add-text-properties (match-beginning 0) (match-end 0)
3345 (org-agenda-align-tags)
3346 (unless org-agenda-with-colors
3347 (remove-text-properties (point-min) (point-max) '(face nil))))
3348 (if (and (boundp 'org-agenda-overriding-columns-format)
3349 org-agenda-overriding-columns-format)
3350 (org-set-local 'org-agenda-overriding-columns-format
3351 org-agenda-overriding-columns-format))
3352 (if (and (boundp 'org-agenda-view-columns-initially)
3353 org-agenda-view-columns-initially)
3354 (org-agenda-columns))
3355 (when org-agenda-fontify-priorities
3356 (org-agenda-fontify-priorities))
3357 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3358 (org-agenda-dim-blocked-tasks))
3359 (org-agenda-mark-clocking-task)
3360 (when org-agenda-entry-text-mode
3361 (org-agenda-entry-text-hide)
3362 (org-agenda-entry-text-show))
3363 (if (functionp 'org-habit-insert-consistency-graphs)
3364 (org-habit-insert-consistency-graphs))
3365 (run-hooks 'org-finalize-agenda-hook)
3366 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3367 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3368 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3369 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3370 (org-agenda-filter-apply org-agenda-category-filter 'category))
3371 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3374 (defun org-agenda-mark-clocking-task ()
3375 "Mark the current clock entry in the agenda if it is present."
3377 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3378 (delete-overlay o)))
3379 (overlays-in (point-min) (point-max)))
3380 (when (marker-buffer org-clock-hd-marker)
3382 (goto-char (point-min))
3384 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3386 (when (equal (org-get-at-bol 'org-hd-marker)
3387 org-clock-hd-marker)
3388 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3389 (overlay-put ov 'type 'org-agenda-clocking)
3390 (overlay-put ov 'face 'org-agenda-clocking)
3391 (overlay-put ov 'help-echo
3392 "The clock is running in this item")))))))
3394 (defun org-agenda-fontify-priorities ()
3395 "Make highest priority lines bold, and lowest italic."
3397 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3398 (delete-overlay o)))
3399 (overlays-in (point-min) (point-max)))
3401 (let ((inhibit-read-only t)
3403 (goto-char (point-min))
3404 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3405 (setq h (or (get-char-property (point) 'org-highest-priority)
3406 org-highest-priority)
3407 l (or (get-char-property (point) 'org-lowest-priority)
3408 org-lowest-priority)
3409 p (string-to-char (match-string 1))
3410 b (match-beginning 0)
3411 e (if (eq org-agenda-fontify-priorities 'cookies)
3414 ov (make-overlay b e))
3417 (cond ((org-face-from-face-or-color
3419 (cdr (assoc p org-priority-faces))))
3420 ((and (listp org-agenda-fontify-priorities)
3421 (org-face-from-face-or-color
3423 (cdr (assoc p org-agenda-fontify-priorities)))))
3424 ((equal p l) 'italic)
3425 ((equal p h) 'bold)))
3426 (overlay-put ov 'org-type 'org-priority)))))
3428 (defun org-agenda-dim-blocked-tasks ()
3429 "Dim currently blocked TODO's in the agenda display."
3430 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3431 (delete-overlay o)))
3432 (overlays-in (point-min) (point-max)))
3434 (let ((inhibit-read-only t)
3435 (org-depend-tag-blocked nil)
3436 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3437 org-blocked-by-checkboxes
3438 invis1 b e p ov h l)
3439 (goto-char (point-min))
3440 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3441 (and pos (goto-char (1+ pos))))
3442 (setq org-blocked-by-checkboxes nil invis1 invis)
3443 (let ((marker (org-get-at-bol 'org-hd-marker)))
3445 (with-current-buffer (marker-buffer marker)
3446 (save-excursion (goto-char marker)
3447 (org-entry-blocked-p))))
3448 (if org-blocked-by-checkboxes (setq invis1 nil))
3450 (max (point-min) (1- (point-at-bol)))
3453 ov (make-overlay b e))
3455 (overlay-put ov 'invisible t)
3456 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3457 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3459 (defvar org-agenda-skip-function nil
3460 "Function to be called at each match during agenda construction.
3461 If this function returns nil, the current match should not be skipped.
3462 Otherwise, the function must return a position from where the search
3463 should be continued.
3464 This may also be a Lisp form, it will be evaluated.
3465 Never set this variable using `setq' or so, because then it will apply
3466 to all future agenda commands. If you do want a global skipping condition,
3467 use the option `org-agenda-skip-function-global' instead.
3468 The correct usage for `org-agenda-skip-function' is to bind it with
3469 `let' to scope it dynamically into the agenda-constructing command.
3470 A good way to set it is through options in `org-agenda-custom-commands'.")
3472 (defun org-agenda-skip ()
3473 "Throw to `:skip' in places that should be skipped.
3474 Also moves point to the end of the skipped region, so that search can
3475 continue from there."
3476 (let ((p (point-at-bol)) to)
3477 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3478 (get-text-property p :org-archived)
3479 (org-end-of-subtree t)
3481 (and org-agenda-skip-comment-trees
3482 (get-text-property p :org-comment)
3483 (org-end-of-subtree t)
3485 (if (equal (char-after p) ?#) (throw :skip t))
3486 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3487 (org-agenda-skip-eval org-agenda-skip-function)))
3491 (defun org-agenda-skip-eval (form)
3492 "If FORM is a function or a list, call (or eval) is and return result.
3493 `save-excursion' and `save-match-data' are wrapped around the call, so point
3494 and match data are returned to the previous state no matter what these
3498 (or (setq fp (functionp form))
3506 (defvar org-agenda-markers nil
3507 "List of all currently active markers created by `org-agenda'.")
3508 (defvar org-agenda-last-marker-time (org-float-time)
3509 "Creation time of the last agenda marker.")
3511 (defun org-agenda-new-marker (&optional pos)
3512 "Return a new agenda marker.
3513 Org-mode keeps a list of these markers and resets them when they are
3515 (let ((m (copy-marker (or pos (point)))))
3516 (setq org-agenda-last-marker-time (org-float-time))
3517 (if org-agenda-buffer
3518 (with-current-buffer org-agenda-buffer
3519 (push m org-agenda-markers))
3520 (push m org-agenda-markers))
3523 (defun org-agenda-reset-markers ()
3524 "Reset markers created by `org-agenda'."
3525 (while org-agenda-markers
3526 (move-marker (pop org-agenda-markers) nil)))
3528 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3529 "Save relative positions of markers in region.
3530 This check for agenda markers in all agenda buffers currently active."
3531 (dolist (buf (buffer-list))
3532 (with-current-buffer buf
3533 (when (eq major-mode 'org-agenda-mode)
3534 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3535 org-agenda-markers)))))
3539 (defun org-agenda-entry-text-show-here ()
3540 "Add some text from the entry as context to the current line."
3542 (setq m (org-get-at-bol 'org-hd-marker))
3543 (unless (marker-buffer m)
3544 (error "No marker points to an entry here"))
3545 (setq txt (concat "\n" (org-no-properties
3546 (org-agenda-get-some-entry-text
3547 m org-agenda-entry-text-maxlines " > "))))
3548 (when (string-match "\\S-" txt)
3549 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3550 (overlay-put o 'evaporate t)
3551 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3552 (overlay-put o 'after-string txt))))
3554 (defun org-agenda-entry-text-show ()
3555 "Add entry context for all agenda lines."
3558 (goto-char (point-max))
3559 (beginning-of-line 1)
3561 (when (org-get-at-bol 'org-hd-marker)
3562 (org-agenda-entry-text-show-here))
3563 (beginning-of-line 0))))
3565 (defun org-agenda-entry-text-hide ()
3566 "Remove any shown entry context."
3569 (if (eq (overlay-get o 'org-overlay-type)
3570 'agenda-entry-content)
3571 (progn (delete-overlay o) t)))
3572 (overlays-in (point-min) (point-max)))))
3574 (defun org-agenda-get-day-face (date)
3575 "Return the face DATE should be displayed with."
3576 (or (and (functionp org-agenda-day-face-function)
3577 (funcall org-agenda-day-face-function date))
3578 (cond ((org-agenda-todayp date)
3579 'org-agenda-date-today)
3580 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3581 'org-agenda-date-weekend)
3582 (t 'org-agenda-date))))
3586 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3588 (defun org-timeline (&optional dotodo)
3589 "Show a time-sorted view of the entries in the current org file.
3590 Only entries with a time stamp of today or later will be listed. With
3591 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3592 under the current date.
3593 If the buffer contains an active region, only check the region for
3597 (org-agenda-show-log-scoped org-agenda-show-log)
3598 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3600 (date (calendar-current-date))
3601 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3602 (end (if (org-region-active-p) (region-end) (point-max)))
3603 (day-numbers (org-get-all-dates
3605 t org-agenda-show-log-scoped ; always include today
3606 org-timeline-show-empty-dates))
3607 (org-deadline-warning-days 0)
3608 (org-agenda-only-exact-dates t)
3613 (setq org-agenda-redo-command
3615 (list 'org-switch-to-buffer-other-window (current-buffer))
3616 (list 'org-timeline (list 'quote dotodo))))
3618 ;; Remove past dates from the list of dates.
3619 (setq day-numbers (delq nil (mapcar (lambda(x)
3620 (if (>= x today) x nil))
3622 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3623 (org-compile-prefix-format 'timeline)
3624 (org-set-sorting-strategy 'timeline)
3625 (if org-agenda-show-log-scoped (push :closed args))
3626 (push :timestamp args)
3627 (push :deadline args)
3628 (push :scheduled args)
3630 (if dotodo (push :todo args))
3631 (insert "Timeline of file " entry "\n")
3632 (add-text-properties (point-min) (point)
3633 (list 'face 'org-agenda-structure))
3634 (org-agenda-mark-header-line (point-min))
3635 (while (setq d (pop day-numbers))
3636 (if (and (listp d) (eq (car d) :omitted))
3639 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3640 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3641 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3642 (if (and (>= d today)
3647 (insert (make-string 79 ?-) "\n")))
3648 (setq date (calendar-gregorian-from-absolute d))
3650 (setq rtn (and (not emptyp)
3651 (apply 'org-agenda-get-day-entries entry
3653 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3656 (if (stringp org-agenda-format-date)
3657 (format-time-string org-agenda-format-date
3658 (org-time-from-absolute date))
3659 (funcall org-agenda-format-date date))
3661 (put-text-property s (1- (point)) 'face
3662 (org-agenda-get-day-face date))
3663 (put-text-property s (1- (point)) 'org-date-line t)
3664 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3666 (put-text-property s (1- (point)) 'org-today t))
3667 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3668 (put-text-property s (1- (point)) 'day d)))))
3669 (goto-char (point-min))
3670 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3672 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3673 (org-finalize-agenda)
3674 (setq buffer-read-only t)))
3676 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3677 "Return a list of all relevant day numbers from BEG to END buffer positions.
3678 If NO-RANGES is non-nil, include only the start and end dates of a range,
3679 not every single day in the range. If FORCE-TODAY is non-nil, make
3680 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3681 inactive time stamps (those in square brackets) are included.
3682 When EMPTY is non-nil, also include days without any entries."
3684 (if pre-re pre-re "")
3685 (if inactive org-ts-regexp-both org-ts-regexp)))
3686 dates dates1 date day day1 day2 ts1 ts2 pos)
3688 (setq dates (list (org-today))))
3691 (while (re-search-forward re end t)
3692 (setq day (time-to-days (org-time-string-to-time
3693 (substring (match-string 1) 0 10)
3694 (current-buffer) (match-beginning 0))))
3695 (or (memq day dates) (push day dates)))
3698 (while (re-search-forward org-tr-regexp end t)
3699 (setq pos (match-beginning 0))
3700 (setq ts1 (substring (match-string 1) 0 10)
3701 ts2 (substring (match-string 2) 0 10)
3702 day1 (time-to-days (org-time-string-to-time
3703 ts1 (current-buffer) pos))
3704 day2 (time-to-days (org-time-string-to-time
3705 ts2 (current-buffer) pos)))
3706 (while (< (setq day1 (1+ day1)) day2)
3707 (or (memq day1 dates) (push day1 dates)))))
3708 (setq dates (sort dates '<))
3710 (while (setq day (pop dates))
3711 (setq day2 (car dates))
3713 (when (and day2 empty)
3714 (if (or (eq empty t)
3715 (and (numberp empty) (<= (- day2 day) empty)))
3716 (while (< (setq day (1+ day)) day2)
3717 (push (list day) dates1))
3718 (push (cons :omitted (- day2 day)) dates1))))
3719 (setq dates (nreverse dates1)))
3722 ;;; Agenda Daily/Weekly
3724 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3725 "Start day for the agenda view.
3726 Custom commands can set this variable in the options section.")
3727 (defvar org-starting-day nil) ; local variable in the agenda buffer
3728 (defvar org-agenda-current-span nil
3729 "The current span used in the agenda view.") ; local variable in the agenda buffer
3730 (defvar org-arg-loc nil) ; local variable
3732 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3733 "List of types searched for when creating the daily/weekly agenda.
3734 This variable is a list of symbols that controls the types of
3735 items that appear in the daily/weekly agenda. Allowed symbols in this
3738 :timestamp List items containing a date stamp or date range matching
3739 the selected date. This includes sexp entries in
3742 :sexp List entries resulting from plain diary-like sexps.
3744 :deadline List deadline due on that date. When the date is today,
3745 also list any deadlines past due, or due within
3746 `org-deadline-warning-days'. `:deadline' must appear before
3747 `:scheduled' if the setting of
3748 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3751 :scheduled List all items which are scheduled for the given date.
3752 The diary for *today* also contains items which were
3753 scheduled earlier and are not yet marked DONE.
3755 By default, all four types are turned on.
3757 Never set this variable globally using `setq', because then it
3758 will apply to all future agenda commands. Instead, bind it with
3759 `let' to scope it dynamically into the agenda-constructing
3760 command. A good way to set it is through options in
3761 `org-agenda-custom-commands'. For a more flexible (though
3762 somewhat less efficient) way of determining what is included in
3763 the daily/weekly agenda, see `org-agenda-skip-function'.")
3766 (defun org-agenda-list (&optional arg start-day span)
3767 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3768 The view will be for the current day or week, but from the overview buffer
3769 you will be able to go to other days/weeks.
3771 With a numeric prefix argument in an interactive call, the agenda will
3772 span ARG days. Lisp programs should instead specify SPAN to change
3773 the number of days. SPAN defaults to `org-agenda-span'.
3775 START-DAY defaults to TODAY, or to the most recent match for the weekday
3776 given in `org-agenda-start-on-weekday'."
3778 (if (and (integerp arg) (> arg 0))
3779 (setq span arg arg nil))
3780 (org-prepare-agenda "Day/Week")
3781 (setq start-day (or start-day org-agenda-start-day))
3782 (if org-agenda-overriding-arguments
3783 (setq arg (car org-agenda-overriding-arguments)
3784 start-day (nth 1 org-agenda-overriding-arguments)
3785 span (nth 2 org-agenda-overriding-arguments)))
3786 (if (stringp start-day)
3787 ;; Convert to an absolute day number
3788 (setq start-day (time-to-days (org-read-date nil t start-day))))
3789 (setq org-agenda-last-arguments (list arg start-day span))
3790 (org-compile-prefix-format 'agenda)
3791 (org-set-sorting-strategy 'agenda)
3792 (let* ((span (org-agenda-ndays-to-span
3793 (or span org-agenda-ndays org-agenda-span)))
3795 (sd (or start-day today))
3796 (ndays (org-agenda-span-to-ndays span sd))
3797 (org-agenda-start-on-weekday
3799 org-agenda-start-on-weekday))
3800 (thefiles (org-agenda-files nil 'ifmode))
3802 (start (if (or (null org-agenda-start-on-weekday)
3805 (let* ((nt (calendar-day-of-week
3806 (calendar-gregorian-from-absolute sd)))
3807 (n1 org-agenda-start-on-weekday)
3809 (- sd (+ (if (< d 0) 7 0) d)))))
3810 (day-numbers (list start))
3812 (inhibit-redisplay (not debug-on-error))
3813 (org-agenda-show-log-scoped org-agenda-show-log)
3814 s e rtn rtnall file date d start-pos end-pos todayp
3815 clocktable-start clocktable-end filter)
3816 (setq org-agenda-redo-command
3817 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3818 (dotimes (n (1- ndays))
3819 (push (1+ (car day-numbers)) day-numbers))
3820 (setq day-numbers (nreverse day-numbers))
3821 (setq clocktable-start (car day-numbers)
3822 clocktable-end (1+ (or (org-last day-numbers) 0)))
3823 (org-set-local 'org-starting-day (car day-numbers))
3824 (org-set-local 'org-arg-loc arg)
3825 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3826 (unless org-agenda-compact-blocks
3827 (let* ((d1 (car day-numbers))
3828 (d2 (org-last day-numbers))
3829 (w1 (org-days-to-iso-week d1))
3830 (w2 (org-days-to-iso-week d2)))
3832 (if org-agenda-overriding-header
3833 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3834 nil 'face 'org-agenda-structure) "\n")
3835 (insert (org-agenda-span-name span)
3837 (if (< (- d2 d1) 350)
3839 (format " (W%02d)" w1)
3840 (format " (W%02d-W%02d)" w1 w2))
3843 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3845 (org-agenda-mark-header-line s))
3846 (while (setq d (pop day-numbers))
3847 (setq date (calendar-gregorian-from-absolute d)
3849 (if (or (setq todayp (= d today))
3850 (and (not start-pos) (= d sd)))
3851 (setq start-pos (point))
3852 (if (and start-pos (not end-pos))
3853 (setq end-pos (point))))
3854 (setq files thefiles
3856 (while (setq file (pop files))
3858 (org-check-agenda-file file)
3859 (let ((org-agenda-entry-types org-agenda-entry-types))
3860 (unless org-agenda-include-deadlines
3861 (setq org-agenda-entry-types
3862 (delq :deadline org-agenda-entry-types)))
3864 ((memq org-agenda-show-log-scoped '(only clockcheck))
3865 (setq rtn (org-agenda-get-day-entries
3866 file date :closed)))
3867 (org-agenda-show-log-scoped
3868 (setq rtn (apply 'org-agenda-get-day-entries
3870 (append '(:closed) org-agenda-entry-types))))
3872 (setq rtn (apply 'org-agenda-get-day-entries
3874 org-agenda-entry-types)))))
3875 (setq rtnall (append rtnall rtn)))) ;; all entries
3876 (if org-agenda-include-diary
3877 (let ((org-agenda-search-headline-for-time t))
3878 (require 'diary-lib)
3879 (setq rtn (org-get-entries-from-diary date))
3880 (setq rtnall (append rtnall rtn))))
3881 (if (or rtnall org-agenda-show-all-dates)
3883 (setq day-cnt (1+ day-cnt))
3885 (if (stringp org-agenda-format-date)
3886 (format-time-string org-agenda-format-date
3887 (org-time-from-absolute date))
3888 (funcall org-agenda-format-date date))
3890 (put-text-property s (1- (point)) 'face
3891 (org-agenda-get-day-face date))
3892 (put-text-property s (1- (point)) 'org-date-line t)
3893 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3894 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3896 (put-text-property s (1- (point)) 'org-today t))
3897 (if rtnall (insert ;; all entries
3898 (org-finalize-agenda-entries
3899 (org-agenda-add-time-grid-maybe
3900 rtnall ndays todayp))
3902 (put-text-property s (1- (point)) 'day d)
3903 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3904 (when (and org-agenda-clockreport-mode clocktable-start)
3905 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3906 ;; the above line is to ensure the restricted range!
3907 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3909 (setq p (org-plist-delete p :block))
3910 (setq p (plist-put p :tstart clocktable-start))
3911 (setq p (plist-put p :tend clocktable-end))
3912 (setq p (plist-put p :scope 'agenda))
3913 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3914 (setq filter (or org-agenda-tag-filter-while-redo
3915 (get 'org-agenda-tag-filter :preset-filter))))
3916 (setq p (plist-put p :tags (mapconcat (lambda (x)
3917 (if (string-match "[<>=]" x)
3921 (setq tbl (apply 'org-get-clocktable p))
3923 (goto-char (point-min))
3924 (or org-agenda-multi (org-fit-agenda-window))
3925 (unless (and (pos-visible-in-window-p (point-min))
3926 (pos-visible-in-window-p (point-max)))
3927 (goto-char (1- (point-max)))
3929 (if (not (pos-visible-in-window-p (or start-pos 1)))
3931 (goto-char (or start-pos 1))
3933 (goto-char (or start-pos 1))
3934 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3935 (if (eq org-agenda-show-log-scoped 'clockcheck)
3936 (org-agenda-show-clocking-issues))
3937 (org-finalize-agenda)
3938 (setq buffer-read-only t)
3941 (defun org-agenda-ndays-to-span (n)
3942 "Return a span symbol for a span of N days, or N if none matches."
3943 (cond ((symbolp n) n)
3948 (defun org-agenda-span-to-ndays (span start-day)
3949 "Return ndays from SPAN starting at START-DAY."
3950 (cond ((numberp span) span)
3954 (let ((date (calendar-gregorian-from-absolute start-day)))
3955 (calendar-last-day-of-month (car date) (caddr date))))
3957 (let ((date (calendar-gregorian-from-absolute start-day)))
3958 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3960 (defun org-agenda-span-name (span)
3961 "Return a SPAN name."
3965 (capitalize (symbol-name span))
3966 (format "%d days" span))))
3968 ;;; Agenda word search
3970 (defvar org-agenda-search-history nil)
3971 (defvar org-todo-only nil)
3973 (defvar org-search-syntax-table nil
3974 "Special syntax table for org-mode search.
3975 In this table, we have single quotes not as word constituents, to
3976 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3978 (defun org-search-syntax-table ()
3979 (unless org-search-syntax-table
3980 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3981 (modify-syntax-entry ?' "." org-search-syntax-table)
3982 (modify-syntax-entry ?` "." org-search-syntax-table))
3983 org-search-syntax-table)
3985 (defvar org-agenda-last-search-view-search-was-boolean nil)
3988 (defun org-search-view (&optional todo-only string edit-at)
3989 "Show all entries that contain a phrase or words or regular expressions.
3991 With optional prefix argument TODO-ONLY, only consider entries that are
3992 TODO entries. The argument STRING can be used to pass a default search
3993 string into this function. If EDIT-AT is non-nil, it means that the
3994 user should get a chance to edit this string, with cursor at position
3997 The search string can be viewed either as a phrase that should be found as
3998 is, or it can be broken into a number of snippets, each of which must match
3999 in a Boolean way to select an entry. The default depends on the variable
4000 `org-agenda-search-view-always-boolean'.
4001 Even if this is turned off (the default) you can always switch to
4002 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4004 The default is a direct search of the whole phrase, where each space in
4005 the search string can expand to an arbitrary amount of whitespace,
4008 If using a Boolean search, the search string is split on whitespace and
4009 each snippet is searched separately, with logical AND to select an entry.
4010 Words prefixed with a minus must *not* occur in the entry. Words without
4011 a prefix or prefixed with a plus must occur in the entry. Matching is
4012 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4013 match whole words, not parts of a word) if
4014 `org-agenda-search-view-force-full-words' is set (default is nil).
4016 Boolean search snippets enclosed by curly braces are interpreted as
4017 regular expressions that must or (when preceded with \"-\") must not
4018 match in the entry. Snippets enclosed into double quotes will be taken
4019 as a whole, to include whitespace.
4021 - If the search string starts with an asterisk, search only in headlines.
4022 - If (possibly after the leading star) the search string starts with an
4023 exclamation mark, this also means to look at TODO entries only, an effect
4024 that can also be achieved with a prefix argument.
4025 - If (possibly after star and exclamation mark) the search string starts
4026 with a colon, this will mean that the (non-regexp) snippets of the
4027 Boolean search must match as full words.
4029 This command searches the agenda files, and in addition the files listed
4030 in `org-agenda-text-search-extra-files'."
4032 (org-prepare-agenda "SEARCH")
4033 (org-compile-prefix-format 'search)
4034 (org-set-sorting-strategy 'search)
4035 (let* ((props (list 'face nil
4036 'done-face 'org-agenda-done
4037 'org-not-done-regexp org-not-done-regexp
4038 'org-todo-regexp org-todo-regexp
4039 'org-complex-heading-regexp org-complex-heading-regexp
4040 'mouse-face 'highlight
4041 'help-echo (format "mouse-2 or RET jump to location")))
4042 (full-words org-agenda-search-view-force-full-words)
4043 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4044 regexp rtn rtnall files file pos
4045 marker category org-category-pos tags c neg re boolean
4046 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4047 (unless (and (not edit-at)
4049 (string-match "\\S-" string))
4050 (setq string (read-string
4051 (if org-agenda-search-view-always-boolean
4052 "[+-]Word/{Regexp} ...: "
4053 "Phrase, or [+-]Word/{Regexp} ...: ")
4055 ((integerp edit-at) (cons string edit-at))
4057 'org-agenda-search-history)))
4058 (org-set-local 'org-todo-only todo-only)
4059 (setq org-agenda-redo-command
4060 (list 'org-search-view (if todo-only t nil) string
4061 '(if current-prefix-arg 1 nil)))
4062 (setq org-agenda-query-string string)
4064 (if (equal (string-to-char string) ?*)
4066 words (substring string 1))
4067 (setq words string))
4068 (when (equal (string-to-char words) ?!)
4070 words (substring words 1)))
4071 (when (equal (string-to-char words) ?:)
4073 words (substring words 1)))
4074 (if (or org-agenda-search-view-always-boolean
4075 (member (string-to-char words) '(?- ?+ ?\{)))
4077 (setq words (org-split-string words))
4079 (while (setq w (pop words))
4080 (while (and (string-match "\\\\\\'" w) words)
4081 (setq w (concat (substring w 0 -1) " " (pop words))))
4083 (setq words (nreverse www) www nil)
4084 (while (setq w (pop words))
4085 (when (and (string-match "\\`[-+]?{" w)
4086 (not (string-match "}\\'" w)))
4087 (while (and words (not (string-match "}\\'" (car words))))
4088 (setq w (concat w " " (pop words))))
4089 (setq w (concat w " " (pop words))))
4091 (setq words (nreverse www)))
4092 (setq org-agenda-last-search-view-search-was-boolean boolean)
4095 (while (setq w (pop words))
4096 (if (or (equal (substring w 0 1) "\"")
4097 (and (> (length w) 1)
4098 (member (substring w 0 1) '("+" "-"))
4099 (equal (substring w 1 2) "\"")))
4100 (while (and words (not (equal (substring w -1) "\"")))
4101 (setq w (concat w " " (pop words)))))
4102 (and (string-match "\\`\\([-+]?\\)\"" w)
4103 (setq w (replace-match "\\1" nil nil w)))
4104 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4106 (setq words (nreverse wds))))
4109 (setq c (string-to-char w))
4111 (setq neg t w (substring w 1))
4113 (setq neg nil w (substring w 1))
4115 (if (string-match "\\`{.*}\\'" w)
4116 (setq re (substring w 1 -1))
4118 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4119 (setq re (regexp-quote (downcase w)))))
4120 (if neg (push re regexps-) (push re regexps+)))
4122 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4124 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4126 (setq regexp org-outline-regexp-bol)
4127 (setq regexp (pop regexps+))
4128 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4130 (setq files (org-agenda-files nil 'ifmode))
4131 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4132 (pop org-agenda-text-search-extra-files)
4133 (setq files (org-add-archive-files files)))
4134 (setq files (append files org-agenda-text-search-extra-files)
4136 (while (setq file (pop files))
4139 (org-check-agenda-file file)
4140 (setq buffer (if (file-exists-p file)
4141 (org-get-agenda-file-buffer file)
4142 (error "No such file %s" file)))
4144 ;; If file does not exist, make sure an error message is sent
4145 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4147 (with-current-buffer buffer
4148 (with-syntax-table (org-search-syntax-table)
4149 (unless (derived-mode-p 'org-mode)
4150 (error "Agenda file %s is not in `org-mode'" file))
4151 (let ((case-fold-search t))
4154 (if org-agenda-restrict
4155 (narrow-to-region org-agenda-restrict-begin
4156 org-agenda-restrict-end)
4158 (goto-char (point-min))
4159 (unless (or (org-at-heading-p)
4160 (outline-next-heading))
4161 (throw 'nextfile t))
4162 (goto-char (max (point-min) (1- (point))))
4163 (while (re-search-forward regexp nil t)
4164 (org-back-to-heading t)
4165 (skip-chars-forward "* ")
4166 (setq beg (point-at-bol)
4168 end (progn (outline-next-heading) (point)))
4172 (setq str (buffer-substring-no-properties
4174 (if hdl-only (point-at-eol) end)))
4175 (mapc (lambda (wr) (when (string-match wr str)
4176 (goto-char (1- end))
4179 (mapc (lambda (wr) (unless (string-match wr str)
4180 (goto-char (1- end))
4183 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4187 (setq marker (org-agenda-new-marker (point))
4188 category (org-get-category)
4189 org-category-pos (get-text-property (point) 'org-category-position)
4190 tags (org-get-tags-at (point))
4191 txt (org-agenda-format-item
4193 (buffer-substring-no-properties
4194 beg1 (point-at-eol))
4196 (org-add-props txt props
4197 'org-marker marker 'org-hd-marker marker
4198 'org-todo-regexp org-todo-regexp
4199 'org-complex-heading-regexp org-complex-heading-regexp
4200 'priority 1000 'org-category category
4201 'org-category-position org-category-pos
4204 (goto-char (1- end))))))))))
4205 (setq rtn (nreverse ee))
4206 (setq rtnall (append rtnall rtn)))
4207 (if org-agenda-overriding-header
4208 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4209 nil 'face 'org-agenda-structure) "\n")
4210 (insert "Search words: ")
4211 (add-text-properties (point-min) (1- (point))
4212 (list 'face 'org-agenda-structure))
4214 (insert string "\n")
4215 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4217 (unless org-agenda-multi
4218 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4219 (add-text-properties pos (1- (point))
4220 (list 'face 'org-agenda-structure))))
4221 (org-agenda-mark-header-line (point-min))
4223 (insert (org-finalize-agenda-entries rtnall) "\n"))
4224 (goto-char (point-min))
4225 (or org-agenda-multi (org-fit-agenda-window))
4226 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4227 (org-finalize-agenda)
4228 (setq buffer-read-only t)))
4230 ;;; Agenda TODO list
4232 (defvar org-select-this-todo-keyword nil)
4233 (defvar org-last-arg nil)
4236 (defun org-todo-list (arg)
4237 "Show all (not done) TODO entries from all agenda file in a single list.
4238 The prefix arg can be used to select a specific TODO keyword and limit
4239 the list to these. When using \\[universal-argument], you will be prompted
4240 for a keyword. A numeric prefix directly selects the Nth keyword in
4241 `org-todo-keywords-1'."
4243 (org-prepare-agenda "TODO")
4244 (org-compile-prefix-format 'todo)
4245 (org-set-sorting-strategy 'todo)
4246 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4247 (let* ((today (org-today))
4248 (date (calendar-gregorian-from-absolute today))
4249 (kwds org-todo-keywords-for-agenda)
4250 (completion-ignore-case t)
4251 (org-select-this-todo-keyword
4252 (if (stringp arg) arg
4253 (and arg (integerp arg) (> arg 0)
4254 (nth (1- arg) kwds))))
4255 rtn rtnall files file pos)
4256 (when (equal arg '(4))
4257 (setq org-select-this-todo-keyword
4258 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4259 (mapcar 'list kwds) nil nil)))
4260 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4261 (org-set-local 'org-last-arg arg)
4262 (setq org-agenda-redo-command
4263 '(org-todo-list (or current-prefix-arg org-last-arg)))
4264 (setq files (org-agenda-files nil 'ifmode)
4266 (while (setq file (pop files))
4268 (org-check-agenda-file file)
4269 (setq rtn (org-agenda-get-day-entries file date :todo))
4270 (setq rtnall (append rtnall rtn))))
4271 (if org-agenda-overriding-header
4272 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4273 nil 'face 'org-agenda-structure) "\n")
4274 (insert "Global list of TODO items of type: ")
4275 (add-text-properties (point-min) (1- (point))
4276 (list 'face 'org-agenda-structure
4279 (or org-select-this-todo-keyword "ALL"))))
4280 (org-agenda-mark-header-line (point-min))
4282 (insert (or org-select-this-todo-keyword "ALL") "\n")
4283 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4285 (unless org-agenda-multi
4286 (insert "Available with `N r': (0)ALL")
4289 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4290 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4295 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4296 (org-agenda-mark-header-line (point-min))
4298 (insert (org-finalize-agenda-entries rtnall) "\n"))
4299 (goto-char (point-min))
4300 (or org-agenda-multi (org-fit-agenda-window))
4301 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4302 (org-finalize-agenda)
4303 (setq buffer-read-only t)))
4305 ;;; Agenda tags match
4308 (defun org-tags-view (&optional todo-only match)
4309 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4310 The prefix arg TODO-ONLY limits the search to TODO entries."
4312 (let* ((org-tags-match-list-sublevels
4313 org-tags-match-list-sublevels)
4314 (completion-ignore-case t)
4315 rtn rtnall files file pos matcher
4317 (when (and (stringp match) (not (string-match "\\S-" match)))
4319 (setq matcher (org-make-tags-matcher match)
4320 match (car matcher) matcher (cdr matcher))
4321 (org-prepare-agenda (concat "TAGS " match))
4322 (org-compile-prefix-format 'tags)
4323 (org-set-sorting-strategy 'tags)
4324 (setq org-agenda-query-string match)
4325 (setq org-agenda-redo-command
4326 (list 'org-tags-view (list 'quote todo-only)
4327 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4328 (setq files (org-agenda-files nil 'ifmode)
4330 (while (setq file (pop files))
4332 (org-check-agenda-file file)
4333 (setq buffer (if (file-exists-p file)
4334 (org-get-agenda-file-buffer file)
4335 (error "No such file %s" file)))
4337 ;; If file does not exist, error message to agenda
4339 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4340 rtnall (append rtnall rtn))
4341 (with-current-buffer buffer
4342 (unless (derived-mode-p 'org-mode)
4343 (error "Agenda file %s is not in `org-mode'" file))
4346 (if org-agenda-restrict
4347 (narrow-to-region org-agenda-restrict-begin
4348 org-agenda-restrict-end)
4350 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4351 (setq rtnall (append rtnall rtn))))))))
4352 (if org-agenda-overriding-header
4353 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4354 nil 'face 'org-agenda-structure) "\n")
4355 (insert "Headlines with TAGS match: ")
4356 (add-text-properties (point-min) (1- (point))
4357 (list 'face 'org-agenda-structure
4359 (concat "Match: " match)))
4362 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4364 (unless org-agenda-multi
4365 (insert "Press `C-u r' to search again with new search string\n"))
4366 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4367 (org-agenda-mark-header-line (point-min))
4369 (insert (org-finalize-agenda-entries rtnall) "\n"))
4370 (goto-char (point-min))
4371 (or org-agenda-multi (org-fit-agenda-window))
4372 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4373 (org-finalize-agenda)
4374 (setq buffer-read-only t)))
4376 ;;; Agenda Finding stuck projects
4378 (defvar org-agenda-skip-regexp nil
4379 "Regular expression used in skipping subtrees for the agenda.
4380 This is basically a temporary global variable that can be set and then
4381 used by user-defined selections using `org-agenda-skip-function'.")
4383 (defvar org-agenda-overriding-header nil
4384 "When set during agenda, todo and tags searches it replaces the header.
4385 This variable should not be set directly, but custom commands can bind it
4386 in the options section.")
4388 (defun org-agenda-skip-entry-when-regexp-matches ()
4389 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4390 If yes, it returns the end position of this entry, causing agenda commands
4391 to skip the entry but continuing the search in the subtree. This is a
4392 function that can be put into `org-agenda-skip-function' for the duration
4394 (let ((end (save-excursion (org-end-of-subtree t)))
4397 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4400 (defun org-agenda-skip-subtree-when-regexp-matches ()
4401 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4402 If yes, it returns the end position of this tree, causing agenda commands
4403 to skip this subtree. This is a function that can be put into
4404 `org-agenda-skip-function' for the duration of a command."
4405 (let ((end (save-excursion (org-end-of-subtree t)))
4408 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4411 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4412 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4413 If yes, it returns the end position of the current entry (NOT the tree),
4414 causing agenda commands to skip the entry but continuing the search in
4415 the subtree. This is a function that can be put into
4416 `org-agenda-skip-function' for the duration of a command. An important
4417 use of this function is for the stuck project list."
4418 (let ((end (save-excursion (org-end-of-subtree t)))
4419 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4422 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4423 (and skip entry-end)))
4425 (defun org-agenda-skip-entry-if (&rest conditions)
4426 "Skip entry if any of CONDITIONS is true.
4427 See `org-agenda-skip-if' for details."
4428 (org-agenda-skip-if nil conditions))
4430 (defun org-agenda-skip-subtree-if (&rest conditions)
4431 "Skip entry if any of CONDITIONS is true.
4432 See `org-agenda-skip-if' for details."
4433 (org-agenda-skip-if t conditions))
4435 (defun org-agenda-skip-if (subtree conditions)
4436 "Checks current entity for CONDITIONS.
4437 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4438 the entry (i.e. the text before the next heading) is checked.
4440 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4441 from different tests. Valid conditions are:
4443 scheduled Check if there is a scheduled cookie
4444 notscheduled Check if there is no scheduled cookie
4445 deadline Check if there is a deadline
4446 notdeadline Check if there is no deadline
4447 timestamp Check if there is a timestamp (also deadline or scheduled)
4448 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4449 regexp Check if regexp matches
4450 notregexp Check if regexp does not match.
4451 todo Check if TODO keyword matches
4452 nottodo Check if TODO keyword does not match
4454 The regexp is taken from the conditions list, it must come right after
4455 the `regexp' or `notregexp' element.
4457 `todo' and `nottodo' accept as an argument a list of todo
4458 keywords, which may include \"*\" to match any todo keyword.
4460 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4462 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4464 Instead of a list, a keyword class may be given. For example:
4466 (org-agenda-skip-entry-if 'nottodo 'done)
4468 would skip entries that haven't been marked with any of \"DONE\"
4469 keywords. Possible classes are: `todo', `done', `any'.
4471 If any of these conditions is met, this function returns the end point of
4472 the entity, causing the search to continue from there. This is a function
4473 that can be put into `org-agenda-skip-function' for the duration of a command."
4475 (org-back-to-heading t)
4478 (progn (org-end-of-subtree t) (point))
4479 (progn (outline-next-heading) (1- (point)))))
4483 (and (memq 'scheduled conditions)
4484 (re-search-forward org-scheduled-time-regexp end t))
4485 (and (memq 'notscheduled conditions)
4486 (not (re-search-forward org-scheduled-time-regexp end t)))
4487 (and (memq 'deadline conditions)
4488 (re-search-forward org-deadline-time-regexp end t))
4489 (and (memq 'notdeadline conditions)
4490 (not (re-search-forward org-deadline-time-regexp end t)))
4491 (and (memq 'timestamp conditions)
4492 (re-search-forward org-ts-regexp end t))
4493 (and (memq 'nottimestamp conditions)
4494 (not (re-search-forward org-ts-regexp end t)))
4495 (and (setq m (memq 'regexp conditions))
4497 (re-search-forward (nth 1 m) end t))
4498 (and (setq m (memq 'notregexp conditions))
4500 (not (re-search-forward (nth 1 m) end t)))
4502 (setq m (memq 'nottodo conditions))
4503 (setq m (memq 'todo-unblocked conditions))
4504 (setq m (memq 'nottodo-unblocked conditions))
4505 (setq m (memq 'todo conditions)))
4506 (org-agenda-skip-if-todo m end)))
4509 (defun org-agenda-skip-if-todo (args end)
4510 "Helper function for `org-agenda-skip-if', do not use it directly.
4511 ARGS is a list with first element either `todo', `nottodo',
4512 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4513 a list of TODO keywords, or a state symbol `todo' or `done' or
4515 (let ((kw (car args))
4521 ((listp arg) ;; list of keywords
4522 (if (member "*" arg)
4523 (mapcar 'substring-no-properties org-todo-keywords-1)
4525 ((symbolp arg) ;; keyword class name
4528 (org-delete-all org-done-keywords
4529 (mapcar 'substring-no-properties
4530 org-todo-keywords-1)))
4531 ((eq arg 'done) org-done-keywords)
4533 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4535 (concat "^\\*+[ \t]+\\<\\("
4536 (mapconcat 'identity todo-wds "\\|")
4539 ((eq kw 'todo) (re-search-forward todo-re end t))
4540 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4541 ((eq kw 'todo-unblocked)
4543 (while (re-search-forward todo-re end t)
4544 (or (org-entry-blocked-p) (throw 'unblocked t)))
4546 ((eq kw 'nottodo-unblocked)
4548 (while (re-search-forward todo-re end t)
4549 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4554 (defun org-agenda-list-stuck-projects (&rest ignore)
4555 "Create agenda view for projects that are stuck.
4556 Stuck projects are project that have no next actions. For the definitions
4557 of what a project is and how to check if it stuck, customize the variable
4558 `org-stuck-projects'."
4560 (let* ((org-agenda-skip-function
4561 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4562 ;; We could have used org-agenda-skip-if here.
4563 (org-agenda-overriding-header
4564 (or org-agenda-overriding-header "List of stuck projects: "))
4565 (matcher (nth 0 org-stuck-projects))
4566 (todo (nth 1 org-stuck-projects))
4567 (todo-wds (if (member "*" todo)
4569 (org-prepare-agenda-buffers (org-agenda-files
4572 org-done-keywords-for-agenda
4573 (copy-sequence org-todo-keywords-for-agenda)))
4575 (todo-re (concat "^\\*+[ \t]+\\("
4576 (mapconcat 'identity todo-wds "\\|")
4578 (tags (nth 2 org-stuck-projects))
4579 (tags-re (if (member "*" tags)
4580 (concat org-outline-regexp-bol
4581 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4583 (concat org-outline-regexp-bol
4585 (mapconcat 'identity tags "\\|")
4586 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4587 (gen-re (nth 3 org-stuck-projects))
4593 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4595 (setq org-agenda-skip-regexp
4597 (mapconcat 'identity re-list "\\|")
4598 (error "No information how to identify unstuck projects")))
4599 (org-tags-view nil matcher)
4600 (with-current-buffer org-agenda-buffer-name
4601 (setq org-agenda-redo-command
4602 '(org-agenda-list-stuck-projects
4603 (or current-prefix-arg org-last-arg))))))
4605 ;;; Diary integration
4607 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4608 (defvar diary-list-entries-hook)
4609 (defvar diary-time-regexp)
4610 (defun org-get-entries-from-diary (date)
4611 "Get the (Emacs Calendar) diary entries for DATE."
4612 (require 'diary-lib)
4613 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4614 (diary-display-hook '(fancy-diary-display))
4615 (diary-display-function 'fancy-diary-display)
4617 (diary-list-entries-hook
4618 (cons 'org-diary-default-entry diary-list-entries-hook))
4619 (diary-file-name-prefix-function nil) ; turn this feature off
4620 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4622 (org-disable-agenda-to-diary t))
4624 (save-window-excursion
4625 (funcall (if (fboundp 'diary-list-entries)
4626 'diary-list-entries 'list-diary-entries)
4628 (if (not (get-buffer diary-fancy-buffer))
4630 (with-current-buffer diary-fancy-buffer
4631 (setq buffer-read-only nil)
4632 (if (zerop (buffer-size))
4635 ;; Omit the date and other unnecessary stuff
4636 (org-agenda-cleanup-fancy-diary)
4637 ;; Add prefix to each line and extend the text properties
4638 (if (zerop (buffer-size))
4640 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4643 (insert entries) (goto-char (point-min))
4644 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4645 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4646 (replace-match (concat "; " (match-string 1)))))
4648 (set-buffer-modified-p nil)
4649 (kill-buffer diary-fancy-buffer)))
4651 (setq entries (org-split-string entries "\n"))
4655 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4656 ;; Extend the text properties to the beginning of the line
4657 (org-add-props x (text-properties-at (1- (length x)) x)
4658 'type "diary" 'date date 'face 'org-agenda-diary))
4661 (defvar org-agenda-cleanup-fancy-diary-hook nil
4662 "Hook run when the fancy diary buffer is cleaned up.")
4664 (defun org-agenda-cleanup-fancy-diary ()
4665 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4666 This gets rid of the date, the underline under the date, and
4667 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4668 date. It also removes lines that contain only whitespace."
4669 (goto-char (point-min))
4670 (if (looking-at ".*?:[ \t]*")
4673 (re-search-forward "\n=+$" nil t)
4675 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4676 (re-search-forward "\n=+$" nil t)
4677 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4678 (goto-char (point-min))
4679 (while (re-search-forward "^ +\n" nil t)
4681 (goto-char (point-min))
4682 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4684 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4686 ;; Make sure entries from the diary have the right text properties.
4687 (eval-after-load "diary-lib"
4688 '(if (boundp 'diary-modify-entry-list-string-function)
4689 ;; We can rely on the hook, nothing to do
4691 ;; Hook not available, must use advice to make this work
4692 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4693 "Make the position visible."
4694 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4697 (setq string (org-modify-diary-entry-string string))))))
4699 (defun org-modify-diary-entry-string (string)
4700 "Add text properties to string, allowing org-mode to act on it."
4701 (org-add-props string nil
4702 'mouse-face 'highlight
4703 'help-echo (if buffer-file-name
4704 (format "mouse-2 or RET jump to diary file %s"
4705 (abbreviate-file-name buffer-file-name))
4707 'org-agenda-diary-link t
4708 'org-marker (org-agenda-new-marker (point-at-bol))))
4710 (defun org-diary-default-entry ()
4711 "Add a dummy entry to the diary.
4712 Needed to avoid empty dates which mess up holiday display."
4713 ;; Catch the error if dealing with the new add-to-diary-alist
4714 (when org-disable-agenda-to-diary
4716 (org-add-to-diary-list original-date "Org-mode dummy" "")
4718 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4720 (defun org-add-to-diary-list (&rest args)
4721 (if (fboundp 'diary-add-to-list)
4722 (apply 'diary-add-to-list args)
4723 (apply 'add-to-diary-list args)))
4725 (defvar org-diary-last-run-time nil)
4728 (defun org-diary (&rest args)
4729 "Return diary information from org-files.
4730 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4731 It accesses org files and extracts information from those files to be
4732 listed in the diary. The function accepts arguments specifying what
4733 items should be listed. For a list of arguments allowed here, see the
4734 variable `org-agenda-entry-types'.
4736 The call in the diary file should look like this:
4738 &%%(org-diary) ~/path/to/some/orgfile.org
4740 Use a separate line for each org file to check. Or, if you omit the file name,
4741 all files listed in `org-agenda-files' will be checked automatically:
4745 If you don't give any arguments (as in the example above), the default
4746 arguments (:deadline :scheduled :timestamp :sexp) are used.
4747 So the example above may also be written as
4749 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4751 The function expects the lisp variables `entry' and `date' to be provided
4752 by the caller, because this is how the calendar works. Don't use this
4753 function from a program - use `org-agenda-get-day-entries' instead."
4754 (when (> (- (org-float-time)
4755 org-agenda-last-marker-time)
4757 ;; I am not sure if this works with sticky agendas, because the marker
4758 ;; list is then no longer a global variable.
4759 (org-agenda-reset-markers))
4760 ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
4761 (when (buffer-live-p org-agenda-buffer)
4762 (org-compile-prefix-format 'agenda))
4763 (org-set-sorting-strategy 'agenda)
4764 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4765 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4767 (org-agenda-files t)))
4768 (time (org-float-time))
4770 (when (or (not org-diary-last-run-time)
4772 org-diary-last-run-time)
4774 (org-prepare-agenda-buffers files))
4775 (setq org-diary-last-run-time time)
4776 ;; If this is called during org-agenda, don't return any entries to
4777 ;; the calendar. Org Agenda will list these entries itself.
4778 (if org-disable-agenda-to-diary (setq files nil))
4779 (while (setq file (pop files))
4780 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4781 (setq results (append results rtn)))
4783 (concat (org-finalize-agenda-entries results) "\n"))))
4785 ;;; Agenda entry finders
4787 (defun org-agenda-get-day-entries (file date &rest args)
4788 "Does the work for `org-diary' and `org-agenda'.
4789 FILE is the path to a file to be checked for entries. DATE is date like
4790 the one returned by `calendar-current-date'. ARGS are symbols indicating
4791 which kind of entries should be extracted. For details about these, see
4792 the documentation of `org-diary'."
4793 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4794 (let* ((org-startup-folded nil)
4795 (org-startup-align-all-tables nil)
4796 (buffer (if (file-exists-p file)
4797 (org-get-agenda-file-buffer file)
4798 (error "No such file %s" file)))
4799 arg results rtn deadline-results)
4801 ;; If file does not exist, make sure an error message ends up in diary
4802 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4803 (with-current-buffer buffer
4804 (unless (derived-mode-p 'org-mode)
4805 (error "Agenda file %s is not in `org-mode'" file))
4806 (let ((case-fold-search nil))
4809 (if org-agenda-restrict
4810 (narrow-to-region org-agenda-restrict-begin
4811 org-agenda-restrict-end)
4813 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4814 (while (setq arg (pop args))
4816 ((and (eq arg :todo)
4817 (equal date (calendar-gregorian-from-absolute
4819 (setq rtn (org-agenda-get-todos))
4820 (setq results (append results rtn)))
4821 ((eq arg :timestamp)
4822 (setq rtn (org-agenda-get-blocks))
4823 (setq results (append results rtn))
4824 (setq rtn (org-agenda-get-timestamps deadline-results))
4825 (setq results (append results rtn)))
4827 (setq rtn (org-agenda-get-sexps))
4828 (setq results (append results rtn)))
4829 ((eq arg :scheduled)
4830 (setq rtn (org-agenda-get-scheduled deadline-results))
4831 (setq results (append results rtn)))
4833 (setq rtn (org-agenda-get-progress))
4834 (setq results (append results rtn)))
4836 (setq rtn (org-agenda-get-deadlines))
4837 (setq deadline-results (copy-sequence rtn))
4838 (setq results (append results rtn))))))))
4841 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4842 (defun org-agenda-get-todos ()
4843 "Return the TODO information for agenda display."
4844 (let* ((props (list 'face nil
4845 'done-face 'org-agenda-done
4846 'org-not-done-regexp org-not-done-regexp
4847 'org-todo-regexp org-todo-regexp
4848 'org-complex-heading-regexp org-complex-heading-regexp
4849 'mouse-face 'highlight
4851 (format "mouse-2 or RET jump to org file %s"
4852 (abbreviate-file-name buffer-file-name))))
4853 (regexp (format org-heading-keyword-regexp-format
4855 ((and org-select-this-todo-keyword
4856 (equal org-select-this-todo-keyword "*"))
4858 (org-select-this-todo-keyword
4860 (mapconcat 'identity
4862 org-select-this-todo-keyword
4865 (t org-not-done-regexp))))
4866 marker priority category org-category-pos tags todo-state
4868 (goto-char (point-min))
4869 (while (re-search-forward regexp nil t)
4874 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4875 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4876 (goto-char (1+ beg))
4877 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4879 (goto-char (match-beginning 2))
4880 (setq marker (org-agenda-new-marker (match-beginning 0))
4881 category (org-get-category)
4882 org-category-pos (get-text-property (point) 'org-category-position)
4884 (buffer-substring (match-beginning 2) (match-end 0)))
4885 tags (org-get-tags-at (point))
4886 txt (org-agenda-format-item "" txt category tags)
4887 priority (1+ (org-get-priority txt))
4888 todo-state (org-get-todo-state))
4889 (org-add-props txt props
4890 'org-marker marker 'org-hd-marker marker
4891 'priority priority 'org-category category
4892 'org-category-position org-category-pos
4893 'type "todo" 'todo-state todo-state)
4895 (if org-agenda-todo-list-sublevels
4896 (goto-char (match-end 2))
4897 (org-end-of-subtree 'invisible))))
4900 (defun org-agenda-todo-custom-ignore-p (time n)
4901 "Check whether timestamp is farther away then n number of days.
4902 This function is invoked if `org-agenda-todo-ignore-deadlines',
4903 `org-agenda-todo-ignore-scheduled' or
4904 `org-agenda-todo-ignore-timestamp' is set to an integer."
4905 (let ((days (org-days-to-time time)))
4911 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4913 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4914 (when (or org-agenda-todo-ignore-with-date
4915 org-agenda-todo-ignore-scheduled
4916 org-agenda-todo-ignore-deadlines
4917 org-agenda-todo-ignore-timestamp)
4918 (setq end (or end (save-excursion (outline-next-heading) (point))))
4920 (or (and org-agenda-todo-ignore-with-date
4921 (re-search-forward org-ts-regexp end t))
4922 (and org-agenda-todo-ignore-scheduled
4923 (re-search-forward org-scheduled-time-regexp end t)
4925 ((eq org-agenda-todo-ignore-scheduled 'future)
4926 (> (org-days-to-time (match-string 1)) 0))
4927 ((eq org-agenda-todo-ignore-scheduled 'past)
4928 (<= (org-days-to-time (match-string 1)) 0))
4929 ((numberp org-agenda-todo-ignore-scheduled)
4930 (org-agenda-todo-custom-ignore-p
4931 (match-string 1) org-agenda-todo-ignore-scheduled))
4933 (and org-agenda-todo-ignore-deadlines
4934 (re-search-forward org-deadline-time-regexp end t)
4936 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4937 ((eq org-agenda-todo-ignore-deadlines 'far)
4938 (not (org-deadline-close (match-string 1))))
4939 ((eq org-agenda-todo-ignore-deadlines 'future)
4940 (> (org-days-to-time (match-string 1)) 0))
4941 ((eq org-agenda-todo-ignore-deadlines 'past)
4942 (<= (org-days-to-time (match-string 1)) 0))
4943 ((numberp org-agenda-todo-ignore-deadlines)
4944 (org-agenda-todo-custom-ignore-p
4945 (match-string 1) org-agenda-todo-ignore-deadlines))
4946 (t (org-deadline-close (match-string 1)))))
4947 (and org-agenda-todo-ignore-timestamp
4948 (let ((buffer (current-buffer))
4951 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4953 ;; Copy current buffer into a temporary one
4955 (insert-buffer-substring buffer start end)
4956 (goto-char (point-min))
4957 ;; Delete SCHEDULED and DEADLINE items
4958 (while (re-search-forward regexp end t)
4959 (delete-region (match-beginning 0) (match-end 0)))
4960 (goto-char (point-min))
4961 ;; No search for timestamp left
4962 (when (re-search-forward org-ts-regexp nil t)
4964 ((eq org-agenda-todo-ignore-timestamp 'future)
4965 (> (org-days-to-time (match-string 1)) 0))
4966 ((eq org-agenda-todo-ignore-timestamp 'past)
4967 (<= (org-days-to-time (match-string 1)) 0))
4968 ((numberp org-agenda-todo-ignore-timestamp)
4969 (org-agenda-todo-custom-ignore-p
4970 (match-string 1) org-agenda-todo-ignore-timestamp))
4973 (defconst org-agenda-no-heading-message
4974 "No heading for this item in buffer or region.")
4976 (defun org-agenda-get-timestamps (&optional deadline-results)
4977 "Return the date stamp information for agenda display."
4978 (let* ((props (list 'face 'org-agenda-calendar-event
4979 'org-not-done-regexp org-not-done-regexp
4980 'org-todo-regexp org-todo-regexp
4981 'org-complex-heading-regexp org-complex-heading-regexp
4982 'mouse-face 'highlight
4984 (format "mouse-2 or RET jump to org file %s"
4985 (abbreviate-file-name buffer-file-name))))
4986 (d1 (calendar-absolute-from-gregorian date))
4988 (deadline-position-alist
4989 (mapcar (lambda (a) (and (setq mm (get-text-property
4990 0 'org-hd-marker a))
4991 (cons (marker-position mm) a)))
4993 (remove-re org-ts-regexp)
4996 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5000 (car org-time-stamp-formats)
5001 (apply 'encode-time ; DATE bound by calendar
5002 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5004 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5005 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5006 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5007 donep tmp priority category org-category-pos ee txt timestr tags
5008 b0 b3 e3 head todo-state end-of-match show-all)
5009 (goto-char (point-min))
5010 (while (setq end-of-match (re-search-forward regexp nil t))
5011 (setq b0 (match-beginning 0)
5012 b3 (match-beginning 3) e3 (match-end 3)
5013 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5014 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5016 org-agenda-repeating-timestamp-show-all)))
5018 (and (org-at-date-range-p) (throw :skip nil))
5020 (if (and (match-end 1)
5021 (not (= d1 (org-time-string-to-absolute
5022 (match-string 1) d1 nil show-all
5023 (current-buffer) b0))))
5026 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5028 (setq tmp (buffer-substring (max (point-min)
5029 (- b0 org-ds-keyword-length))
5031 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5032 inactivep (= (char-after b0) ?\[)
5033 deadlinep (string-match org-deadline-regexp tmp)
5034 scheduledp (string-match org-scheduled-regexp tmp)
5035 closedp (and org-agenda-include-inactive-timestamps
5036 (string-match org-closed-string tmp))
5037 clockp (and org-agenda-include-inactive-timestamps
5038 (or (string-match org-clock-string tmp)
5039 (string-match "]-+\\'" tmp)))
5040 donep (member todo-state org-done-keywords))
5041 (if (or scheduledp deadlinep closedp clockp
5042 (and donep org-agenda-skip-timestamp-if-done))
5044 (if (string-match ">" timestr)
5045 ;; substring should only run to end of time stamp
5046 (setq timestr (substring timestr 0 (match-end 0))))
5047 (setq marker (org-agenda-new-marker b0)
5048 category (org-get-category b0)
5049 org-category-pos (get-text-property b0 'org-category-position))
5051 (if (not (re-search-backward org-outline-regexp-bol nil t))
5052 (setq txt org-agenda-no-heading-message)
5053 (goto-char (match-beginning 0))
5054 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5055 (assoc (point) deadline-position-alist))
5057 (setq hdmarker (org-agenda-new-marker)
5058 tags (org-get-tags-at))
5059 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5060 (setq head (or (match-string 1) ""))
5061 (setq txt (org-agenda-format-item
5062 (if inactivep org-agenda-inactive-leader nil)
5063 head category tags timestr
5065 (setq priority (org-get-priority txt))
5066 (org-add-props txt props
5067 'org-marker marker 'org-hd-marker hdmarker)
5068 (org-add-props txt nil 'priority priority
5069 'org-category category 'date date
5070 'org-category-position org-category-pos
5071 'todo-state todo-state
5074 (if org-agenda-skip-additional-timestamps-same-entry
5075 (outline-next-heading)
5076 (goto-char end-of-match))))
5079 (defun org-agenda-get-sexps ()
5080 "Return the sexp information for agenda display."
5081 (require 'diary-lib)
5082 (let* ((props (list 'face 'org-agenda-calendar-sexp
5083 'mouse-face 'highlight
5085 (format "mouse-2 or RET jump to org file %s"
5086 (abbreviate-file-name buffer-file-name))))
5088 marker category extra org-category-pos ee txt tags entry
5089 result beg b sexp sexp-entry todo-state)
5090 (goto-char (point-min))
5091 (while (re-search-forward regexp nil t)
5094 (setq beg (match-beginning 0))
5095 (goto-char (1- (match-end 0)))
5098 (setq sexp (buffer-substring b (point)))
5099 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5100 (org-trim (match-string 1))
5102 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5104 (setq marker (org-agenda-new-marker beg)
5105 category (org-get-category beg)
5106 org-category-pos (get-text-property beg 'org-category-position)
5107 todo-state (org-get-todo-state))
5109 (dolist (r (if (stringp result)
5111 result)) ;; we expect a list here
5112 (when (and org-agenda-diary-sexp-prefix
5113 (string-match org-agenda-diary-sexp-prefix r))
5114 (setq extra (match-string 0 r)
5115 r (replace-match "" nil nil r)))
5116 (if (string-match "\\S-" r)
5118 (setq txt "SEXP entry returned empty string"))
5120 (setq txt (org-agenda-format-item
5121 extra txt category tags 'time))
5122 (org-add-props txt props 'org-marker marker)
5123 (org-add-props txt nil
5124 'org-category category 'date date 'todo-state todo-state
5125 'org-category-position org-category-pos
5130 ;; Calendar sanity: define some functions that are independent of
5131 ;; `calendar-date-style'.
5132 ;; Normally I would like to use ISO format when calling the diary functions,
5133 ;; but to make sure we still have Emacs 22 compatibility we bind
5134 ;; also `european-calendar-style' and use european format
5135 (defun org-anniversary (year month day &optional mark)
5136 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5138 (let ((calendar-date-style 'european) (european-calendar-style t))
5139 (diary-anniversary day month year mark))))
5140 (defun org-cyclic (N year month day &optional mark)
5141 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5143 (let ((calendar-date-style 'european) (european-calendar-style t))
5144 (diary-cyclic N day month year mark))))
5145 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5146 "Like `diary-block', but with fixed (ISO) order of arguments."
5148 (let ((calendar-date-style 'european) (european-calendar-style t))
5149 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5150 (defun org-date (year month day &optional mark)
5151 "Like `diary-date', but with fixed (ISO) order of arguments."
5153 (let ((calendar-date-style 'european) (european-calendar-style t))
5154 (diary-date day month year mark))))
5155 (defalias 'org-float 'diary-float)
5157 ;; Define the` org-class' function
5158 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5159 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5160 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5161 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5162 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5163 `holidays', then any date that is known by the Emacs calendar to be a
5164 holiday will also be skipped."
5165 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5166 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5167 (d (calendar-absolute-from-gregorian date)))
5171 (= (calendar-day-of-week date) dayname)
5172 (or (not skip-weeks)
5175 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5176 (not (and (memq 'holidays skip-weeks)
5177 (calendar-check-holidays date)))
5180 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5181 "Like `org-class', but honor `calendar-date-style'.
5182 The order of the first 2 times 3 arguments depends on the variable
5183 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5184 So for American calendars, give this as MONTH DAY YEAR, for European as
5185 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5186 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5187 is any number of ISO weeks in the block period for which the item should
5190 This function is here only for backward compatibility and it is deprecated,
5191 please use `org-class' instead."
5192 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5193 (date2 (org-order-calendar-date-args m2 d2 y2)))
5195 (nth 2 date1) (car date1) (nth 1 date1)
5196 (nth 2 date2) (car date2) (nth 1 date2)
5197 dayname skip-weeks)))
5198 (make-obsolete 'org-diary-class 'org-class "")
5200 (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
5201 (defalias 'org-get-closed 'org-agenda-get-progress)
5202 (defun org-agenda-get-progress ()
5203 "Return the logged TODO entries for agenda display."
5204 (let* ((props (list 'mouse-face 'highlight
5205 'org-not-done-regexp org-not-done-regexp
5206 'org-todo-regexp org-todo-regexp
5207 'org-complex-heading-regexp org-complex-heading-regexp
5209 (format "mouse-2 or RET jump to org file %s"
5210 (abbreviate-file-name buffer-file-name))))
5211 (items (if (consp org-agenda-show-log-scoped)
5212 org-agenda-show-log-scoped
5213 (if (eq org-agenda-show-log-scoped 'clockcheck)
5215 org-agenda-log-mode-items)))
5219 (if (memq 'closed items) (concat "\\<" org-closed-string))
5220 (if (memq 'clock items) (concat "\\<" org-clock-string))
5221 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5222 (parts-re (if parts (mapconcat 'identity parts "\\|")
5223 (error "`org-agenda-log-mode-items' is empty")))
5225 "\\(" parts-re "\\)"
5230 (car org-time-stamp-formats)
5231 (apply 'encode-time ; DATE bound by calendar
5232 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5234 (org-agenda-search-headline-for-time nil)
5235 marker hdmarker priority category org-category-pos tags closedp
5236 statep clockp state ee txt extra timestr rest clocked)
5237 (goto-char (point-min))
5238 (while (re-search-forward regexp nil t)
5241 (setq marker (org-agenda-new-marker (match-beginning 0))
5242 closedp (equal (match-string 1) org-closed-string)
5243 statep (equal (string-to-char (match-string 1)) ?-)
5244 clockp (not (or closedp statep))
5245 state (and statep (match-string 2))
5246 category (org-get-category (match-beginning 0))
5247 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5248 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5249 (when (string-match "\\]" timestr)
5250 ;; substring should only run to end of time stamp
5251 (setq rest (substring timestr (match-end 0))
5252 timestr (substring timestr 0 (match-end 0)))
5253 (if (and (not closedp) (not statep)
5254 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5256 (progn (setq timestr (concat (substring timestr 0 -1)
5257 "-" (match-string 1 rest) "]"))
5258 (setq clocked (match-string 2 rest)))
5259 (setq clocked "-")))
5263 ((not org-agenda-log-mode-add-notes) nil)
5265 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5268 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5269 (match-string 1)))))
5270 (if (not (re-search-backward org-outline-regexp-bol nil t))
5271 (setq txt org-agenda-no-heading-message)
5272 (goto-char (match-beginning 0))
5273 (setq hdmarker (org-agenda-new-marker)
5274 tags (org-get-tags-at))
5275 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5276 (setq txt (match-string 1))
5278 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5279 (setq txt (concat (substring txt 0 (match-beginning 1))
5280 " - " extra " " (match-string 2 txt)))
5281 (setq txt (concat txt " - " extra))))
5282 (setq txt (org-agenda-format-item
5284 (closedp "Closed: ")
5285 (statep (concat "State: (" state ")"))
5286 (t (concat "Clocked: (" clocked ")")))
5287 txt category tags timestr)))
5288 (setq priority 100000)
5289 (org-add-props txt props
5290 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5291 'priority priority 'org-category category
5292 'org-category-position org-category-pos
5293 'type "closed" 'date date
5294 'undone-face 'org-warning 'done-face 'org-agenda-done)
5296 (goto-char (point-at-eol))))
5299 (defun org-agenda-show-clocking-issues ()
5300 "Add overlays, showing issues with clocking.
5301 See also the user option `org-agenda-clock-consistency-checks'."
5303 (let* ((pl org-agenda-clock-consistency-checks)
5304 (re (concat "^[ \t]*"
5307 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5308 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5311 (maxtime (org-hh:mm-string-to-minutes
5312 (or (plist-get pl :max-duration) "24:00")))
5313 (mintime (org-hh:mm-string-to-minutes
5314 (or (plist-get pl :min-duration) 0)))
5315 (maxgap (org-hh:mm-string-to-minutes
5316 ;; default 30:00 means never complain
5317 (or (plist-get pl :max-gap) "30:00")))
5318 (gapok (mapcar 'org-hh:mm-string-to-minutes
5319 (plist-get pl :gap-ok-around)))
5320 (def-face (or (plist-get pl :default-face)
5321 '((:background "DarkRed") (:foreground "white"))))
5322 issue face m te ts dt ov)
5323 (goto-char (point-min))
5324 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5325 (setq issue nil face def-face)
5327 (setq m (org-get-at-bol 'org-marker)
5329 (unless (and m (markerp m))
5330 (setq issue "No valid clock line") (throw 'next t))
5331 (org-with-point-at m
5333 (goto-char (point-at-bol))
5334 (unless (looking-at re)
5335 (error "No valid Clock line")
5337 (unless (match-end 3)
5338 (setq issue "No end time"
5339 face (or (plist-get pl :no-end-time-face) face))
5341 (setq ts (match-string 1)
5344 (apply 'encode-time (org-parse-time-string ts)))
5346 (apply 'encode-time (org-parse-time-string te)))
5349 ((> dt (* 60 maxtime))
5350 ;; a very long clocking chunk
5351 (setq issue (format "Clocking interval is very long: %s"
5352 (org-minutes-to-hh:mm-string
5353 (floor (/ (float dt) 60.))))
5354 face (or (plist-get pl :long-face) face)))
5355 ((< dt (* 60 mintime))
5356 ;; a very short clocking chunk
5357 (setq issue (format "Clocking interval is very short: %s"
5358 (org-minutes-to-hh:mm-string
5359 (floor (/ (float dt) 60.))))
5360 face (or (plist-get pl :short-face) face)))
5361 ((and (> tlend 0) (< ts tlend))
5362 ;; Two clock entries are overlapping
5363 (setq issue (format "Clocking overlap: %d minutes"
5364 (/ (- tlend ts) 60))
5365 face (or (plist-get pl :overlap-face) face)))
5366 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5367 ;; There is a gap, lets see if we need to report it
5368 (unless (org-agenda-check-clock-gap tlend ts gapok)
5369 (setq issue (format "Clocking gap: %d minutes"
5370 (/ (- ts tlend) 60))
5371 face (or (plist-get pl :gap-face) face))))
5373 (setq tlend (or te tlend) tlstart (or ts tlstart))
5375 ;; OK, there was some issue, add an overlay to show the issue
5376 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5377 (overlay-put ov 'before-string
5380 (format "%-43s" (concat " " issue))
5384 (overlay-put ov 'evaporate t)))))
5386 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5387 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5390 ;; there are no OK times for gaps...
5392 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5393 ;; This is more than 24 hours, so it is OK.
5394 ;; because we have at least one OK time, that must be in the
5395 ;; 24 hour interval.
5397 ;; We have a shorter gap.
5398 ;; Now we have to get the minute of the day when these times are
5399 (let* ((t1dec (decode-time (seconds-to-time t1)))
5400 (t2dec (decode-time (seconds-to-time t2)))
5401 ;; compute the minute on the day
5402 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5403 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5405 ;; if min2 is smaller than min1, this means it is on the next day.
5406 ;; Wrap it to after midnight.
5407 (setq min2 (+ min2 1440)))
5408 ;; Now check if any of the OK times is in the gap
5410 ;; Wrap the time to after midnight if necessary
5411 (if (< x min1) (setq x (+ x 1440)))
5412 ;; Check if in interval
5413 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5415 ;; Nope, this gap is not OK
5418 (defun org-agenda-get-deadlines ()
5419 "Return the deadline information for agenda display."
5420 (let* ((props (list 'mouse-face 'highlight
5421 'org-not-done-regexp org-not-done-regexp
5422 'org-todo-regexp org-todo-regexp
5423 'org-complex-heading-regexp org-complex-heading-regexp
5425 (format "mouse-2 or RET jump to org file %s"
5426 (abbreviate-file-name buffer-file-name))))
5427 (regexp org-deadline-time-regexp)
5428 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5429 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5430 d2 diff dfrac wdays pos pos1 category org-category-pos
5431 tags suppress-prewarning ee txt head face s todo-state
5432 show-all upcomingp donep timestr)
5433 (goto-char (point-min))
5434 (while (re-search-forward regexp nil t)
5435 (setq suppress-prewarning nil)
5438 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5440 (string-match org-scheduled-time-regexp
5441 (buffer-substring (point-at-bol)
5443 (setq suppress-prewarning
5444 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5445 org-agenda-skip-deadline-prewarning-if-scheduled
5447 (setq s (match-string 1)
5449 pos (1- (match-beginning 1))
5450 todo-state (save-match-data (org-get-todo-state))
5451 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5453 org-agenda-repeating-timestamp-show-all))
5454 d2 (org-time-string-to-absolute
5455 (match-string 1) d1 'past show-all
5456 (current-buffer) pos)
5458 wdays (if suppress-prewarning
5459 (let ((org-deadline-warning-days suppress-prewarning))
5462 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5463 upcomingp (and todayp (> diff 0)))
5464 ;; When to show a deadline in the calendar:
5465 ;; If the expiration is within wdays warning time.
5466 ;; Past-due deadlines are only shown on the current date
5467 (if (and (or (and (<= diff wdays)
5468 (and todayp (not org-agenda-only-exact-dates)))
5471 ;; (setq todo-state (org-get-todo-state))
5472 (setq donep (member todo-state org-done-keywords))
5474 (or org-agenda-skip-deadline-if-done
5477 (setq category (org-get-category)
5478 org-category-pos (get-text-property (point) 'org-category-position))
5479 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5480 (setq txt org-agenda-no-heading-message)
5481 (goto-char (match-end 0))
5482 (setq pos1 (match-beginning 0))
5483 (setq tags (org-get-tags-at pos1))
5484 (setq head (buffer-substring-no-properties
5486 (progn (skip-chars-forward "^\r\n")
5488 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5490 (concat (substring s (match-beginning 1)) " "))
5491 (setq timestr 'time))
5492 (setq txt (org-agenda-format-item
5494 (car org-agenda-deadline-leaders)
5496 (nth 1 org-agenda-deadline-leaders))
5498 (nth 1 org-agenda-deadline-leaders)
5500 (format (nth 1 org-agenda-deadline-leaders)
5503 (if (not (= diff 0)) nil timestr)))))
5505 (setq face (org-agenda-deadline-face dfrac))
5506 (org-add-props txt props
5507 'org-marker (org-agenda-new-marker pos)
5508 'org-hd-marker (org-agenda-new-marker pos1)
5509 'priority (+ (- diff)
5510 (org-get-priority txt))
5511 'org-category category
5512 'org-category-position org-category-pos
5513 'todo-state todo-state
5514 'type (if upcomingp "upcoming-deadline" "deadline")
5515 'date (if upcomingp date d2)
5516 'face (if donep 'org-agenda-done face)
5517 'undone-face face 'done-face 'org-agenda-done)
5521 (defun org-agenda-deadline-face (fraction)
5522 "Return the face to displaying a deadline item.
5523 FRACTION is what fraction of the head-warning time has passed."
5524 (let ((faces org-agenda-deadline-faces) f)
5526 (while (setq f (pop faces))
5527 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5529 (defun org-agenda-get-scheduled (&optional deadline-results)
5530 "Return the scheduled information for agenda display."
5531 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5532 'org-todo-regexp org-todo-regexp
5533 'org-complex-heading-regexp org-complex-heading-regexp
5534 'done-face 'org-agenda-done
5535 'mouse-face 'highlight
5537 (format "mouse-2 or RET jump to org file %s"
5538 (abbreviate-file-name buffer-file-name))))
5539 (regexp org-scheduled-time-regexp)
5540 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5541 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5543 (deadline-position-alist
5544 (mapcar (lambda (a) (and (setq mm (get-text-property
5545 0 'org-hd-marker a))
5546 (cons (marker-position mm) a)))
5548 d2 diff pos pos1 category org-category-pos tags donep
5549 ee txt head pastschedp todo-state face timestr s habitp show-all
5551 (goto-char (point-min))
5552 (while (re-search-forward regexp nil t)
5555 (setq s (match-string 1)
5557 pos (1- (match-beginning 1))
5558 todo-state (save-match-data (org-get-todo-state))
5559 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5561 org-agenda-repeating-timestamp-show-all))
5562 d2 (org-time-string-to-absolute
5563 (match-string 1) d1 'past show-all
5564 (current-buffer) pos)
5566 (setq pastschedp (and todayp (< diff 0)))
5567 (setq did-habit-check-p nil)
5568 ;; When to show a scheduled item in the calendar:
5569 ;; If it is on or past the date.
5570 (when (or (and (< diff 0)
5571 (< (abs diff) org-scheduled-past-days)
5572 (and todayp (not org-agenda-only-exact-dates)))
5574 ;; org-is-habit-p uses org-entry-get, which is expansive
5575 ;; so we go extra mile to only call it once
5577 org-habit-show-all-today
5578 (setq did-habit-check-p t)
5579 (setq habitp (and (functionp 'org-is-habit-p)
5580 (org-is-habit-p)))))
5582 (setq donep (member todo-state org-done-keywords))
5584 (or org-agenda-skip-scheduled-if-done
5586 (and (functionp 'org-is-habit-p)
5589 (setq habitp (if did-habit-check-p habitp
5590 (and (functionp 'org-is-habit-p)
5592 (setq category (org-get-category)
5593 org-category-pos (get-text-property (point) 'org-category-position))
5594 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5595 (setq txt org-agenda-no-heading-message)
5596 (goto-char (match-end 0))
5597 (setq pos1 (match-beginning 0))
5599 (if (or (not org-habit-show-habits)
5601 org-habit-show-habits-only-for-today))
5604 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5605 (and org-agenda-skip-scheduled-if-deadline-is-shown
5607 (setq mm (assoc pos1 deadline-position-alist)))
5609 (setq tags (org-get-tags-at))
5610 (setq head (buffer-substring-no-properties
5612 (progn (skip-chars-forward "^\r\n") (point))))
5613 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5615 (concat (substring s (match-beginning 1)) " "))
5616 (setq timestr 'time))
5617 (setq txt (org-agenda-format-item
5619 (car org-agenda-scheduled-leaders)
5620 (format (nth 1 org-agenda-scheduled-leaders)
5623 (if (not (= diff 0)) nil timestr)
5628 ((and (not habitp) pastschedp)
5629 'org-scheduled-previously)
5630 (todayp 'org-scheduled-today)
5632 habitp (and habitp (org-habit-parse-todo)))
5633 (org-add-props txt props
5635 'face (if donep 'org-agenda-done face)
5636 'org-marker (org-agenda-new-marker pos)
5637 'org-hd-marker (org-agenda-new-marker pos1)
5638 'type (if pastschedp "past-scheduled" "scheduled")
5639 'date (if pastschedp d2 date)
5640 'priority (if habitp
5641 (org-habit-get-priority habitp)
5642 (+ 94 (- 5 diff) (org-get-priority txt)))
5643 'org-category category
5644 'org-category-position org-category-pos
5646 'todo-state todo-state)
5650 (defun org-agenda-get-blocks ()
5651 "Return the date-range information for agenda display."
5652 (let* ((props (list 'face nil
5653 'org-not-done-regexp org-not-done-regexp
5654 'org-todo-regexp org-todo-regexp
5655 'org-complex-heading-regexp org-complex-heading-regexp
5656 'mouse-face 'highlight
5658 (format "mouse-2 or RET jump to org file %s"
5659 (abbreviate-file-name buffer-file-name))))
5660 (regexp org-tr-regexp)
5661 (d0 (calendar-absolute-from-gregorian date))
5662 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5663 todo-state tags pos head donep)
5664 (goto-char (point-min))
5665 (while (re-search-forward regexp nil t)
5669 (let ((start-time (match-string 1))
5670 (end-time (match-string 2)))
5671 (setq s1 (match-string 1)
5673 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5674 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5675 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5676 ;; Only allow days between the limits, because the normal
5677 ;; date stamps will catch the limits.
5679 (setq todo-state (org-get-todo-state))
5680 (setq donep (member todo-state org-done-keywords))
5681 (if (and donep org-agenda-skip-timestamp-if-done)
5683 (setq marker (org-agenda-new-marker (point)))
5684 (setq category (org-get-category)
5685 org-category-pos (get-text-property (point) 'org-category-position))
5686 (if (not (re-search-backward org-outline-regexp-bol nil t))
5687 (setq txt org-agenda-no-heading-message)
5688 (goto-char (match-beginning 0))
5689 (setq hdmarker (org-agenda-new-marker (point)))
5690 (setq tags (org-get-tags-at))
5691 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5692 (setq head (match-string 1))
5694 (if org-agenda-remove-timeranges-from-blocks
5696 "<" (regexp-quote s1) ".*?>"
5698 "<" (regexp-quote s2) ".*?>")
5700 (setq txt (org-agenda-format-item
5702 (nth (if (= d1 d2) 0 1)
5703 org-agenda-timerange-leaders)
5704 (1+ (- d0 d1)) (1+ (- d2 d1)))
5706 (cond ((and (= d1 d0) (= d2 d0))
5707 (concat "<" start-time ">--<" end-time ">"))
5709 (concat "<" start-time ">"))
5711 (concat "<" end-time ">"))
5714 (org-add-props txt props
5715 'org-marker marker 'org-hd-marker hdmarker
5716 'type "block" 'date date
5717 'todo-state todo-state
5718 'priority (org-get-priority txt) 'org-category category
5719 'org-category-position org-category-pos)
5722 ;; Sort the entries by expiration date.
5725 ;;; Agenda presentation and sorting
5727 (defvar org-prefix-has-time 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-tag nil
5731 "A flag, set by `org-compile-prefix-format'.
5732 The flag is set if the currently compiled format contains a `%T'.")
5733 (defvar org-prefix-has-effort nil
5734 "A flag, set by `org-compile-prefix-format'.
5735 The flag is set if the currently compiled format contains a `%e'.")
5736 (defvar org-prefix-category-length nil
5737 "Used by `org-compile-prefix-format' to remember the category field width.")
5738 (defvar org-prefix-category-max-length nil
5739 "Used by `org-compile-prefix-format' to remember the category field width.")
5741 (defun org-agenda-get-category-icon (category)
5742 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5743 (dolist (entry org-agenda-category-icon-alist)
5744 (when (org-string-match-p (car entry) category)
5745 (if (listp (cadr entry))
5746 (return (cadr entry))
5747 (return (apply 'create-image (cdr entry)))))))
5749 (defun org-agenda-format-item (extra txt &optional category tags dotime
5751 "Format TXT to be inserted into the agenda buffer.
5752 In particular, it adds the prefix and corresponding text properties. EXTRA
5753 must be a string and replaces the `%s' specifier in the prefix format.
5754 CATEGORY (string, symbol or nil) may be used to overrule the default
5755 category taken from local variable or file name. It will replace the `%c'
5756 specifier in the format. DOTIME, when non-nil, indicates that a
5757 time-of-day should be extracted from TXT for sorting of this entry, and for
5758 the `%t' specifier in the format. When DOTIME is a string, this string is
5759 searched for a time before TXT is. TAGS can be the tags of the headline.
5760 Any match of REMOVE-RE will be removed from TXT."
5761 ;; We keep the org-prefix-* variable values along with a compiled
5762 ;; formatter, so that multiple agendas existing at the same time, do
5763 ;; not step on each other toes.
5765 ;; It was inconvenient to make these variables buffer local in
5766 ;; Agenda buffers, because this function expects to be called with
5767 ;; the buffer where item comes from being current, and not agenda
5769 (let* ((bindings (car org-prefix-format-compiled))
5770 (formatter (cadr org-prefix-format-compiled)))
5771 (loop for (var value) in bindings
5774 ;; Diary entries sometimes have extra whitespace at the beginning
5775 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5777 ;; Fix the tags part in txt
5778 (setq txt (org-agenda-fix-displayed-tags
5780 org-agenda-show-inherited-tags
5781 org-agenda-hide-tags-regexp))
5782 (let* ((category (or category
5783 (if (stringp org-category)
5785 (and org-category (symbol-name org-category)))
5786 (if buffer-file-name
5787 (file-name-sans-extension
5788 (file-name-nondirectory buffer-file-name))
5790 (category-icon (org-agenda-get-category-icon category))
5791 (category-icon (if category-icon
5792 (propertize " " 'display category-icon)
5794 ;; time, tag, effort are needed for the eval of the prefix format
5795 (tag (if tags (nth (1- (length tags)) tags) ""))
5797 (ts (if dotime (concat
5798 (if (stringp dotime) dotime "")
5799 (and org-agenda-search-headline-for-time txt))))
5800 (time-of-day (and dotime (org-get-time-of-day ts)))
5801 stamp plain s0 s1 s2 rtn srp l
5802 duration thecategory)
5803 (and (derived-mode-p 'org-mode) buffer-file-name
5804 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5805 (when (and dotime time-of-day)
5806 ;; Extract starting and ending time and move them to prefix
5807 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5808 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5809 (setq s0 (match-string 0 ts)
5810 srp (and stamp (match-end 3))
5811 s1 (match-string (if plain 1 2) ts)
5812 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5814 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5815 ;; them, we might want to remove them there to avoid duplication.
5816 ;; The user can turn this off with a variable.
5817 (if (and org-prefix-has-time
5818 org-agenda-remove-times-when-in-prefix (or stamp plain)
5819 (string-match (concat (regexp-quote s0) " *") txt)
5820 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5821 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5822 (= (match-beginning 0) 0)
5824 (setq txt (replace-match "" nil nil txt))))
5825 ;; Normalize the time(s) to 24 hour
5826 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5827 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5829 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5830 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5832 (org-minutes-to-hh:mm-string
5833 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5835 ;; Compute the duration
5837 (setq duration (- (org-hh:mm-string-to-minutes s2)
5838 (org-hh:mm-string-to-minutes s1)))))
5840 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5842 ;; Tags are in the string
5843 (if (or (eq org-agenda-remove-tags t)
5844 (and org-agenda-remove-tags
5845 org-prefix-has-tag))
5846 (setq txt (replace-match "" t t txt))
5847 (setq txt (replace-match
5848 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5849 (match-string 2 txt))
5851 (when (derived-mode-p 'org-mode)
5855 (or (get-text-property 0 'org-hd-marker txt)
5856 (get-text-property 0 'org-marker txt)))
5859 (setq neffort (org-duration-string-to-minutes effort)
5860 effort (setq effort (concat "[" effort "]")))))
5861 ;; prevent erroring out with %e format when there is no effort
5862 (or effort (setq effort ""))
5865 (while (string-match remove-re txt)
5866 (setq txt (replace-match "" t t txt))))
5868 ;; Set org-heading property on `txt' to mark the start of the
5870 (add-text-properties 0 (length txt) '(org-heading t) txt)
5872 ;; Prepare the variables needed in the eval of the compiled format
5873 (setq time (cond (s2 (concat
5874 (org-agenda-time-of-day-to-ampm-maybe s1)
5875 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5876 (if org-agenda-timegrid-use-ampm " ")))
5878 (org-agenda-time-of-day-to-ampm-maybe s1)
5879 (if org-agenda-timegrid-use-ampm
5883 extra (or (and (not habitp) extra) "")
5884 category (if (symbolp category) (symbol-name category) category)
5885 thecategory (copy-sequence category))
5886 (if (string-match org-bracket-link-regexp category)
5888 (setq l (if (match-end 3)
5889 (- (match-end 3) (match-beginning 3))
5890 (- (match-end 1) (match-beginning 1))))
5891 (when (< l (or org-prefix-category-length 0))
5892 (setq category (copy-sequence category))
5893 (org-add-props category nil
5894 'extra-space (make-string
5895 (- org-prefix-category-length l 1) ?\ ))))
5896 (if (and org-prefix-category-max-length
5897 (>= (length category) org-prefix-category-max-length))
5898 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5899 ;; Evaluate the compiled format
5900 (setq rtn (concat (eval formatter) txt))
5902 ;; And finally add the text properties
5903 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5904 (org-add-props rtn nil
5905 'org-category (if thecategory (downcase thecategory) category)
5906 'tags (mapcar 'org-downcase-keep-props tags)
5907 'org-highest-priority org-highest-priority
5908 'org-lowest-priority org-lowest-priority
5909 'time-of-day time-of-day
5912 'effort-minutes neffort
5916 'format org-prefix-format-compiled
5919 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5920 "Remove tags string from TXT, and add a modified list of tags.
5921 The modified list may contain inherited tags, and tags matched by
5922 `org-agenda-hide-tags-regexp' will be removed."
5923 (when (or add-inherited hide-re)
5924 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5925 (setq txt (substring txt 0 (match-beginning 0))))
5928 (mapcar (lambda (tg)
5929 (if (or (and hide-re (string-match hide-re tg))
5930 (and (not add-inherited)
5931 (get-text-property 0 'inherited tg)))
5936 (let ((have-i (get-text-property 0 'inherited (car tags)))
5938 (setq txt (concat txt " :"
5941 (setq i (get-text-property 0 'inherited x))
5942 (if (and have-i (not i))
5948 (if have-i "::" ":"))))))
5951 (defun org-downcase-keep-props (s)
5952 (let ((props (text-properties-at 0 s)))
5953 (setq s (downcase s))
5954 (add-text-properties 0 (length s) props s)
5957 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5958 (defvar org-agenda-sorting-strategy-selected nil)
5960 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5962 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5963 ((and todayp (member 'today (car org-agenda-time-grid))))
5964 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5965 ((member 'weekly (car org-agenda-time-grid)))
5966 (t (throw 'exit list)))
5967 (let* ((have (delq nil (mapcar
5968 (lambda (x) (get-text-property 1 'time-of-day x))
5970 (string (nth 1 org-agenda-time-grid))
5971 (gridtimes (nth 2 org-agenda-time-grid))
5972 (req (car org-agenda-time-grid))
5973 (remove (member 'remove-match req))
5975 (if (and (member 'require-timed req) (not have))
5976 ;; don't show empty grid
5978 (while (setq time (pop gridtimes))
5979 (unless (and remove (member time have))
5980 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5981 (push (org-agenda-format-item
5983 (concat (substring time 0 -2) ":" (substring time -2)))
5986 2 (length (car new)) 'face 'org-time-grid (car new))))
5987 (when (and todayp org-agenda-show-current-time-in-grid)
5988 (push (org-agenda-format-item
5990 org-agenda-current-time-string
5992 (format-time-string "%H:%M "))
5995 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5997 (if (member 'time-up org-agenda-sorting-strategy-selected)
5999 (append list new)))))
6001 (defun org-compile-prefix-format (key)
6002 "Compile the prefix format into a Lisp form that can be evaluated.
6003 The resulting form and associated variable bindings is returned
6004 and stored in the variable `org-prefix-format-compiled'."
6005 (setq org-prefix-has-time nil org-prefix-has-tag nil
6006 org-prefix-category-length nil
6007 org-prefix-has-effort nil)
6009 ((stringp org-agenda-prefix-format)
6010 org-agenda-prefix-format)
6011 ((assq key org-agenda-prefix-format)
6012 (cdr (assq key org-agenda-prefix-format)))
6013 (t " %-12:c%?-12t% s")))
6015 varform vars var e c f opt)
6016 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6018 (setq var (or (cdr (assoc (match-string 4 s)
6019 '(("c" . category) ("t" . time) ("s" . extra)
6020 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6022 c (or (match-string 3 s) "")
6023 opt (match-beginning 1)
6024 start (1+ (match-beginning 0)))
6025 (if (equal var 'time) (setq org-prefix-has-time t))
6026 (if (equal var 'tag) (setq org-prefix-has-tag t))
6027 (if (equal var 'effort) (setq org-prefix-has-effort t))
6028 (setq f (concat "%" (match-string 2 s) "s"))
6029 (when (equal var 'category)
6030 (setq org-prefix-category-length
6031 (floor (abs (string-to-number (match-string 2 s)))))
6032 (setq org-prefix-category-max-length
6033 (let ((x (match-string 2 s)))
6035 (if (string-match "\\.[0-9]+" x)
6036 (string-to-number (substring (match-string 0 x) 1)))))))
6038 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6041 `(if (equal "" ,var)
6043 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6044 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6045 (setq s (replace-match "%s" t nil s))
6046 (push varform vars))
6047 (setq vars (nreverse vars))
6048 (with-current-buffer org-agenda-buffer
6049 (setq org-prefix-format-compiled
6051 `((org-prefix-has-time ,org-prefix-has-time)
6052 (org-prefix-has-tag ,org-prefix-has-tag)
6053 (org-prefix-category-length ,org-prefix-category-length)
6054 (org-prefix-has-effort ,org-prefix-has-effort))
6055 `(format ,s ,@vars))))))
6057 (defun org-set-sorting-strategy (key)
6058 (if (symbolp (car org-agenda-sorting-strategy))
6060 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6061 (setq org-agenda-sorting-strategy-selected
6062 (or (cdr (assq key org-agenda-sorting-strategy))
6063 (cdr (assq 'agenda org-agenda-sorting-strategy))
6064 '(time-up category-keep priority-down)))))
6066 (defun org-get-time-of-day (s &optional string mod24)
6067 "Check string S for a time of day.
6068 If found, return it as a military time number between 0 and 2400.
6069 If not found, return nil.
6070 The optional STRING argument forces conversion into a 5 character wide string
6074 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6075 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6076 (let* ((h (string-to-number (match-string 1 s)))
6077 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6078 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6079 (am-p (equal ampm "am"))
6080 (h1 (cond ((not ampm) h)
6081 ((= h 12) (if am-p 0 12))
6082 (t (+ h (if am-p 0 12)))))
6083 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6085 (t0 (+ (* 100 h2) m))
6086 (t1 (concat (if (>= h1 24) "+" " ")
6087 (if (and org-agenda-time-leading-zero
6088 (< t0 1000)) "0" "")
6089 (if (< t0 100) "0" "")
6090 (if (< t0 10) "0" "")
6091 (int-to-string t0))))
6092 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6094 (defvar org-agenda-before-sorting-filter-function nil
6095 "Function to be applied to agenda items prior to sorting.
6096 Prior to sorting also means just before they are inserted into the agenda.
6098 To aid sorting, you may revisit the original entries and add more text
6099 properties which will later be used by the sorting functions.
6101 The function should take a string argument, an agenda line.
6102 It has access to the text properties in that line, which contain among
6103 other things, the property `org-hd-marker' that points to the entry
6104 where the line comes from. Note that not all lines going into the agenda
6105 have this property, only most.
6107 The function should return the modified string. It is probably best
6108 to ONLY change text properties.
6110 You can also use this function as a filter, by returning nil for lines
6111 you don't want to have in the agenda at all. For this application, you
6112 could bind the variable in the options section of a custom command.")
6114 (defun org-finalize-agenda-entries (list &optional nosort)
6115 "Sort and concatenate the agenda items."
6116 (setq list (mapcar 'org-agenda-highlight-todo list))
6119 (when org-agenda-before-sorting-filter-function
6120 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6121 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6123 (defun org-agenda-highlight-todo (x)
6124 (let ((org-done-keywords org-done-keywords-for-agenda)
6125 (case-fold-search nil)
6129 (beginning-of-line 1)
6130 (setq re (org-get-at-bol 'org-todo-regexp))
6131 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6132 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6133 (add-text-properties (match-beginning 0) (match-end 1)
6134 (list 'face (org-get-todo-face 1)))
6135 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6136 (delete-region (match-beginning 1) (1- (match-end 0)))
6137 (goto-char (match-beginning 1))
6138 (insert (format org-agenda-todo-keyword-format s)))))
6139 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6140 (setq re (get-text-property 0 'org-todo-regexp x))
6142 ;; Test `pl' because if there's no heading content,
6143 ;; there's no point matching to highlight. Note
6144 ;; that if we didn't test `pl' first, and there
6145 ;; happened to be no keyword from `org-todo-regexp'
6146 ;; on this heading line, then the `equal' comparison
6147 ;; afterwards would spuriously succeed in the case
6148 ;; where `pl' is nil -- causing an args-out-of-range
6149 ;; error when we try to add text properties to text
6150 ;; that isn't there.
6152 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6154 (add-text-properties
6155 (or (match-end 1) (match-end 0)) (match-end 0)
6156 (list 'face (org-get-todo-face (match-string 2 x)))
6159 (setq x (concat (substring x 0 (match-end 1))
6160 (format org-agenda-todo-keyword-format
6162 (org-add-props " " (text-properties-at 0 x))
6163 (substring x (match-end 3)))))))
6166 (defsubst org-cmp-priority (a b)
6167 "Compare the priorities of string A and B."
6168 (let ((pa (or (get-text-property 1 'priority a) 0))
6169 (pb (or (get-text-property 1 'priority b) 0)))
6170 (cond ((> pa pb) +1)
6174 (defsubst org-cmp-effort (a b)
6175 "Compare the effort values of string A and B."
6176 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6177 (ea (or (get-text-property 1 'effort-minutes a) def))
6178 (eb (or (get-text-property 1 'effort-minutes b) def)))
6179 (cond ((> ea eb) +1)
6183 (defsubst org-cmp-category (a b)
6184 "Compare the string values of categories of strings A and B."
6185 (let ((ca (or (get-text-property 1 'org-category a) ""))
6186 (cb (or (get-text-property 1 'org-category b) "")))
6187 (cond ((string-lessp ca cb) -1)
6188 ((string-lessp cb ca) +1)
6191 (defsubst org-cmp-todo-state (a b)
6192 "Compare the todo states of strings A and B."
6193 (let* ((ma (or (get-text-property 1 'org-marker a)
6194 (get-text-property 1 'org-hd-marker a)))
6195 (mb (or (get-text-property 1 'org-marker b)
6196 (get-text-property 1 'org-hd-marker b)))
6197 (fa (and ma (marker-buffer ma)))
6198 (fb (and mb (marker-buffer mb)))
6200 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6201 (and fb (with-current-buffer fb org-todo-keywords-1))))
6202 (ta (or (get-text-property 1 'todo-state a) ""))
6203 (tb (or (get-text-property 1 'todo-state b) ""))
6204 (la (- (length (member ta todo-kwds))))
6205 (lb (- (length (member tb todo-kwds))))
6206 (donepa (member ta org-done-keywords-for-agenda))
6207 (donepb (member tb org-done-keywords-for-agenda)))
6208 (cond ((and donepa (not donepb)) -1)
6209 ((and (not donepa) donepb) +1)
6214 (defsubst org-cmp-alpha (a b)
6215 "Compare the headlines, alphabetically."
6216 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6217 (plb (text-property-any 0 (length b) 'org-heading t b))
6218 (ta (and pla (substring a pla)))
6219 (tb (and plb (substring b plb))))
6221 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6222 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6223 (setq ta (substring ta (match-end 0))))
6224 (setq ta (downcase ta)))
6226 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6227 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6228 (setq tb (substring tb (match-end 0))))
6229 (setq tb (downcase tb)))
6232 ((string-lessp ta tb) -1)
6233 ((string-lessp tb ta) +1)
6236 (defsubst org-cmp-tag (a b)
6237 "Compare the string values of the first tags of A and B."
6238 (let ((ta (car (last (get-text-property 1 'tags a))))
6239 (tb (car (last (get-text-property 1 'tags b)))))
6242 ((string-lessp ta tb) -1)
6243 ((string-lessp tb ta) +1)
6246 (defsubst org-cmp-time (a b)
6247 "Compare the time-of-day values of strings A and B."
6248 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6249 (ta (or (get-text-property 1 'time-of-day a) def))
6250 (tb (or (get-text-property 1 'time-of-day b) def)))
6251 (cond ((< ta tb) -1)
6255 (defsubst org-cmp-habit-p (a b)
6256 "Compare the todo states of strings A and B."
6257 (let ((ha (get-text-property 1 'org-habit-p a))
6258 (hb (get-text-property 1 'org-habit-p b)))
6259 (cond ((and ha (not hb)) -1)
6260 ((and (not ha) hb) +1)
6263 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6265 (defun org-entries-lessp (a b)
6266 "Predicate for sorting agenda entries."
6267 ;; The following variables will be used when the form is evaluated.
6268 ;; So even though the compiler complains, keep them.
6269 (let* ((ss org-agenda-sorting-strategy-selected)
6270 (time-up (and (org-em 'time-up 'time-down ss)
6271 (org-cmp-time a b)))
6272 (time-down (if time-up (- time-up) nil))
6273 (priority-up (and (org-em 'priority-up 'priority-down ss)
6274 (org-cmp-priority a b)))
6275 (priority-down (if priority-up (- priority-up) nil))
6276 (effort-up (and (org-em 'effort-up 'effort-down ss)
6277 (org-cmp-effort a b)))
6278 (effort-down (if effort-up (- effort-up) nil))
6279 (category-up (and (or (org-em 'category-up 'category-down ss)
6280 (memq 'category-keep ss))
6281 (org-cmp-category a b)))
6282 (category-down (if category-up (- category-up) nil))
6283 (category-keep (if category-up +1 nil))
6284 (tag-up (and (org-em 'tag-up 'tag-down ss)
6286 (tag-down (if tag-up (- tag-up) nil))
6287 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6288 (org-cmp-todo-state a b)))
6289 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6290 (habit-up (and (org-em 'habit-up 'habit-down ss)
6291 (org-cmp-habit-p a b)))
6292 (habit-down (if habit-up (- habit-up) nil))
6293 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6294 (org-cmp-alpha a b)))
6295 (alpha-down (if alpha-up (- alpha-up) nil))
6296 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6297 user-defined-up user-defined-down)
6298 (if (and need-user-cmp org-agenda-cmp-user-defined
6299 (functionp org-agenda-cmp-user-defined))
6300 (setq user-defined-up
6301 (funcall org-agenda-cmp-user-defined a b)
6302 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6304 (eval (cons 'or org-agenda-sorting-strategy-selected))
6305 '((-1 . t) (1 . nil) (nil . nil))))))
6307 ;;; Agenda restriction lock
6309 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6310 "Overlay to mark the headline to which agenda commands are restricted.")
6311 (overlay-put org-agenda-restriction-lock-overlay
6312 'face 'org-agenda-restriction-lock)
6313 (overlay-put org-agenda-restriction-lock-overlay
6314 'help-echo "Agendas are currently limited to this subtree.")
6315 (org-detach-overlay org-agenda-restriction-lock-overlay)
6317 (defun org-agenda-set-restriction-lock (&optional type)
6318 "Set restriction lock for agenda, to current subtree or file.
6319 Restriction will be the file if TYPE is `file', or if type is the
6320 universal prefix '(4), or if the cursor is before the first headline
6321 in the file. Otherwise, restriction will be to the current subtree."
6323 (and (equal type '(4)) (setq type 'file))
6326 ((org-at-heading-p) 'subtree)
6327 ((condition-case nil (org-back-to-heading t) (error nil))
6330 (if (eq type 'subtree)
6332 (setq org-agenda-restrict t)
6333 (setq org-agenda-overriding-restriction 'subtree)
6334 (put 'org-agenda-files 'org-restrict
6335 (list (buffer-file-name (buffer-base-buffer))))
6336 (org-back-to-heading t)
6337 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6338 (move-marker org-agenda-restrict-begin (point))
6339 (move-marker org-agenda-restrict-end
6340 (save-excursion (org-end-of-subtree t)))
6341 (message "Locking agenda restriction to subtree"))
6342 (put 'org-agenda-files 'org-restrict
6343 (list (buffer-file-name (buffer-base-buffer))))
6344 (setq org-agenda-restrict nil)
6345 (setq org-agenda-overriding-restriction 'file)
6346 (move-marker org-agenda-restrict-begin nil)
6347 (move-marker org-agenda-restrict-end nil)
6348 (message "Locking agenda restriction to file"))
6349 (setq current-prefix-arg nil)
6350 (org-agenda-maybe-redo))
6352 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6353 "Remove the agenda restriction lock."
6355 (org-detach-overlay org-agenda-restriction-lock-overlay)
6356 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6357 (setq org-agenda-overriding-restriction nil)
6358 (setq org-agenda-restrict nil)
6359 (put 'org-agenda-files 'org-restrict nil)
6360 (move-marker org-agenda-restrict-begin nil)
6361 (move-marker org-agenda-restrict-end nil)
6362 (setq current-prefix-arg nil)
6363 (message "Agenda restriction lock removed")
6364 (or noupdate (org-agenda-maybe-redo)))
6366 (defun org-agenda-maybe-redo ()
6367 "If there is any window showing the agenda view, update it."
6368 (let ((w (get-buffer-window org-agenda-buffer-name t))
6369 (w0 (selected-window)))
6374 (if org-agenda-overriding-restriction
6375 (message "Agenda view shifted to new %s restriction"
6376 org-agenda-overriding-restriction)
6377 (message "Agenda restriction lock removed")))))
6381 (defun org-agenda-check-type (error &rest types)
6382 "Check if agenda buffer is of allowed type.
6383 If ERROR is non-nil, throw an error, otherwise just return nil."
6384 (if (not org-agenda-type)
6385 (error "No Org agenda currently displayed")
6386 (if (memq org-agenda-type types)
6389 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6392 (defun org-agenda-Quit (&optional arg)
6393 "Exit agenda by removing the window or the buffer."
6395 (if org-agenda-columns-active
6397 (let ((buf (current-buffer)))
6398 (if (eq org-agenda-window-setup 'other-frame)
6400 (org-agenda-reset-markers)
6402 (org-columns-remove-overlays)
6403 (setq org-agenda-archives-mode nil)
6405 (and (not (eq org-agenda-window-setup 'current-window))
6406 (not (one-window-p))
6408 (org-agenda-reset-markers)
6410 (org-columns-remove-overlays)
6411 (setq org-agenda-archives-mode nil)))
6412 ;; Maybe restore the pre-agenda window configuration.
6413 (and org-agenda-restore-windows-after-quit
6414 (not (eq org-agenda-window-setup 'other-frame))
6415 org-pre-agenda-window-conf
6416 (set-window-configuration org-pre-agenda-window-conf))))
6418 (defun org-agenda-quit ()
6419 "Exit agenda by killing agenda buffer or burying it when
6420 `org-agenda-sticky' is non-NIL"
6422 (if org-agenda-columns-active
6424 (if org-agenda-sticky
6425 (let ((buf (current-buffer)))
6426 (if (eq org-agenda-window-setup 'other-frame)
6429 (and (not (eq org-agenda-window-setup 'current-window))
6430 (not (one-window-p))
6432 (with-current-buffer buf
6434 ;; Maybe restore the pre-agenda window configuration.
6435 (and org-agenda-restore-windows-after-quit
6436 (not (eq org-agenda-window-setup 'other-frame))
6437 org-pre-agenda-window-conf
6438 (set-window-configuration org-pre-agenda-window-conf))))
6439 (org-agenda-Quit))))
6441 (defun org-agenda-exit ()
6442 "Exit agenda by removing the window or the buffer.
6443 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6444 Org-mode buffers visited directly by the user will not be touched."
6446 (org-release-buffers org-agenda-new-buffers)
6447 (setq org-agenda-new-buffers nil)
6450 (defun org-agenda-kill-all-agenda-buffers ()
6451 "Kill all buffers in `org-agena-mode'.
6452 This is used when toggling sticky agendas. You can also explicitly invoke it
6456 (dolist (buf (buffer-list))
6457 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6459 (mapc 'kill-buffer blist)))
6461 (defun org-agenda-execute (arg)
6462 "Execute another agenda command, keeping same window.
6463 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6466 (let ((org-agenda-window-setup 'current-window))
6469 (defun org-agenda-redo ()
6471 When this is the global TODO list, a prefix argument will be interpreted."
6473 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6474 (org-agenda-sticky nil)
6475 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6476 org-agenda-buffer-name))
6477 (org-agenda-keep-modes t)
6478 (tag-filter org-agenda-tag-filter)
6479 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6480 (top-cat-filter org-agenda-top-category-filter)
6481 (cat-filter org-agenda-category-filter)
6482 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6483 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6484 (cols org-agenda-columns-active)
6485 (line (org-current-line))
6486 (window-line (- line (org-current-line (window-start))))
6487 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6488 (put 'org-agenda-tag-filter :preset-filter nil)
6489 (put 'org-agenda-category-filter :preset-filter nil)
6490 (and cols (org-columns-quit))
6491 (message "Rebuilding agenda buffer...")
6492 (org-let lprops '(eval org-agenda-redo-command))
6493 (setq org-agenda-undo-list nil
6494 org-agenda-pending-undo-list nil)
6495 (message "Rebuilding agenda buffer...done")
6496 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6497 (put 'org-agenda-category-filter :preset-filter cat-preset)
6498 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6499 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6500 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6501 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6502 (org-goto-line line)
6503 (recenter window-line)))
6505 (defvar org-global-tags-completion-table nil)
6506 (defvar org-agenda-filter-form nil)
6507 (defvar org-agenda-filtered-by-category nil)
6509 (defun org-agenda-filter-by-category (strip)
6510 "Keep only those lines in the agenda buffer that have a specific category.
6511 The category is that of the current line."
6513 (if org-agenda-filtered-by-category
6514 (org-agenda-filter-show-all-cat)
6515 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6516 (if cat (org-agenda-filter-apply
6517 (list (concat (if strip "-" "+") cat)) 'category)
6518 (error "No category at point")))))
6520 (defun org-find-top-category (&optional pos)
6522 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6523 (if pos (goto-char pos))
6524 ;; Skip up to the topmost parent
6525 (while (ignore-errors (outline-up-heading 1) t))
6527 (nth 4 (org-heading-components))))))
6529 (defvar org-agenda-filtered-by-top-category nil)
6531 (defun org-agenda-filter-by-top-category (strip)
6532 "Keep only those lines in the agenda buffer that have a specific category.
6533 The category is that of the current line."
6535 (if org-agenda-filtered-by-top-category
6537 (setq org-agenda-filtered-by-top-category nil
6538 org-agenda-top-category-filter nil)
6539 (org-agenda-filter-show-all-cat))
6540 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6541 (if cat (org-agenda-filter-top-category-apply cat strip)
6542 (error "No top-level category at point")))))
6544 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6545 "Keep only those lines in the agenda buffer that have a specific tag.
6546 The tag is selected with its fast selection letter, as configured.
6547 With prefix argument STRIP, remove all lines that do have the tag.
6548 A lisp caller can specify CHAR. NARROW means that the new tag should be
6549 used to narrow the search - the interactive user can also press `-' or `+'
6550 to switch to narrowing."
6552 (let* ((alist org-tag-alist-for-agenda)
6553 (tag-chars (mapconcat
6554 (lambda (x) (if (and (not (symbolp (car x)))
6556 (char-to-string (cdr x))
6559 (efforts (org-split-string
6560 (or (cdr (assoc (concat org-effort-property "_ALL")
6561 org-global-properties))
6562 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6564 (effort-op org-agenda-filter-effort-default-operator)
6566 (inhibit-read-only t)
6567 (current org-agenda-tag-filter)
6568 maybe-refresh a n tag)
6571 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6572 (if narrow "Narrow" "Filter") tag-chars
6573 (if org-agenda-auto-exclude-function "[RET], " ""))
6574 (setq char (read-char-exclusive)))
6575 (when (member char '(?+ ?-))
6577 (cond ((equal char ?-) (setq strip t narrow t))
6578 ((equal char ?+) (setq strip nil narrow t)))
6580 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6581 (setq char (read-char-exclusive)))
6582 (when (member char '(?< ?> ?= ??))
6583 ;; An effort operator
6584 (setq effort-op (char-to-string char))
6585 (setq alist nil) ; to make sure it will be interpreted as effort.
6586 (unless (equal char ??)
6587 (loop for i from 0 to 9 do
6591 (if (= i 9) "0" (int-to-string (1+ i)))
6592 "]" (nth i efforts))))
6593 (message "Effort%s: %s " effort-op effort-prompt)
6594 (setq char (read-char-exclusive))
6595 (when (or (< char ?0) (> char ?9))
6596 (error "Need 1-9,0 to select effort"))))
6597 (when (equal char ?\t)
6598 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6599 (org-set-local 'org-global-tags-completion-table
6600 (org-global-tags-completion-table)))
6601 (let ((completion-ignore-case t))
6602 (setq tag (org-icompleting-read
6603 "Tag: " org-global-tags-completion-table))))
6606 (org-agenda-filter-show-all-tag)
6607 (when org-agenda-auto-exclude-function
6608 (setq org-agenda-tag-filter '())
6609 (dolist (tag (org-agenda-get-represented-tags))
6610 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6612 (push modifier org-agenda-tag-filter))))
6613 (if (not (null org-agenda-tag-filter))
6614 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6615 (setq maybe-refresh t))
6617 (org-agenda-filter-show-all-tag)
6618 (when (get 'org-agenda-tag-filter :preset-filter)
6619 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6620 (setq maybe-refresh t))
6622 (setq org-agenda-tag-filter
6623 (mapcar (lambda(tag) (concat "+" tag))
6624 (org-get-at-bol 'tags)))
6625 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6626 (setq maybe-refresh t))
6627 ((or (equal char ?\ )
6628 (setq a (rassoc char alist))
6629 (and (>= char ?0) (<= char ?9)
6630 (setq n (if (= char ?0) 9 (- char ?0 1))
6631 tag (concat effort-op (nth n efforts))
6636 (and tag (setq a (cons tag nil))))
6637 (org-agenda-filter-show-all-tag)
6639 (setq org-agenda-tag-filter
6640 (cons (concat (if strip "-" "+") tag)
6641 (if narrow current nil)))
6642 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6643 (setq maybe-refresh t))
6644 (t (error "Invalid tag selection character %c" char)))
6645 (when (and maybe-refresh
6646 (eq org-agenda-clockreport-mode 'with-filter))
6647 (org-agenda-redo))))
6649 (defun org-agenda-get-represented-tags ()
6650 "Get a list of all tags currently represented in the agenda."
6653 (goto-char (point-min))
6654 (while (setq p (next-single-property-change (point) 'tags))
6656 (mapc (lambda (x) (add-to-list 'tags x))
6657 (get-text-property (point) 'tags))))
6660 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6661 "Refine the current filter. See `org-agenda-filter-by-tag'."
6663 (org-agenda-filter-by-tag strip char 'refine))
6665 (defun org-agenda-filter-make-matcher ()
6666 "Create the form that tests a line for agenda filter."
6668 ;; first compute the tag-filter matcher
6669 (dolist (x (delete-dups
6670 (append (get 'org-agenda-tag-filter
6671 :preset-filter) org-agenda-tag-filter)))
6672 (if (member x '("-" "+"))
6673 (setq f1 (if (equal x "-") 'tags '(not tags)))
6674 (if (string-match "[<=>?]" x)
6675 (setq f1 (org-agenda-filter-effort-form x))
6676 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6677 (if (equal (string-to-char x) ?-)
6678 (setq f1 (list 'not f1))))
6680 ;; then compute the category-filter matcher
6681 (dolist (x (delete-dups
6682 (append (get 'org-agenda-category-filter
6683 :preset-filter) org-agenda-category-filter)))
6684 (if (equal "-" (substring x 0 1))
6685 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6686 (setq f1 (list 'equal (substring x 1) 'cat)))
6688 (cons 'and (nreverse f))))
6690 (defun org-agenda-filter-effort-form (e)
6691 "Return the form to compare the effort of the current line with what E says.
6692 E looks like \"+<2:25\"."
6694 (setq e (substring e 1))
6695 (setq op (string-to-char e) e (substring e 1))
6696 (setq op (cond ((equal op ?<) '<=)
6700 (list 'org-agenda-compare-effort (list 'quote op)
6701 (org-duration-string-to-minutes e))))
6703 (defun org-agenda-compare-effort (op value)
6704 "Compare the effort of the current line with VALUE, using OP.
6705 If the line does not have an effort defined, return nil."
6706 (let ((eff (org-get-at-bol 'effort-minutes)))
6709 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6712 (defun org-agenda-filter-apply (filter type)
6713 "Set FILTER as the new agenda filter and apply it."
6716 (setq org-agenda-tag-filter filter)
6717 (setq org-agenda-category-filter filter))
6718 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6719 (if (and (eq type 'category)
6720 (not (equal (substring (car filter) 0 1) "-")))
6721 ;; Only set `org-agenda-filtered-by-category' to t
6722 ;; when a unique category is used as the filter
6723 (setq org-agenda-filtered-by-category t))
6724 (org-agenda-set-mode-name)
6726 (goto-char (point-min))
6728 (if (org-get-at-bol 'org-marker)
6730 (setq tags (org-get-at-bol 'tags) ; used in eval
6731 cat (get-text-property (point) 'org-category))
6732 (if (not (eval org-agenda-filter-form))
6733 (org-agenda-filter-hide-line type))
6734 (beginning-of-line 2))
6735 (beginning-of-line 2))))
6736 (if (get-char-property (point) 'invisible)
6737 (ignore-errors (org-agenda-previous-line)))))
6739 (defun org-agenda-filter-top-category-apply (category &optional negative)
6740 "Set FILTER as the new agenda filter and apply it."
6741 (org-agenda-set-mode-name)
6743 (goto-char (point-min))
6745 (let* ((pos (org-get-at-bol 'org-hd-marker))
6746 (topcat (and pos (org-find-top-category pos))))
6747 (if (and topcat (funcall (if negative 'identity 'not)
6748 (string= category topcat)))
6749 (org-agenda-filter-hide-line 'category)))
6750 (beginning-of-line 2)))
6751 (if (get-char-property (point) 'invisible)
6752 (org-agenda-previous-line))
6753 (setq org-agenda-top-category-filter category
6754 org-agenda-filtered-by-top-category t))
6756 (defun org-agenda-filter-hide-line (type)
6758 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6760 (overlay-put ov 'invisible t)
6761 (overlay-put ov 'type type)
6763 (push ov org-agenda-tag-filter-overlays)
6764 (push ov org-agenda-cat-filter-overlays))))
6766 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6767 (setq pos (or pos (point)))
6769 (dolist (ov (overlays-at pos))
6770 (when (and (overlay-get ov 'invisible)
6771 (eq (overlay-get ov 'type) 'tag))
6773 (if (< (overlay-start ov) (point-at-eol))
6774 (move-overlay ov (point-at-eol)
6775 (overlay-end ov)))))))
6777 (defun org-agenda-filter-show-all-tag nil
6778 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6779 (setq org-agenda-tag-filter-overlays nil
6780 org-agenda-tag-filter nil
6781 org-agenda-filter-form nil)
6782 (org-agenda-set-mode-name))
6784 (defun org-agenda-filter-show-all-cat nil
6785 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6786 (setq org-agenda-cat-filter-overlays nil
6787 org-agenda-filtered-by-category nil
6788 org-agenda-category-filter nil
6789 org-agenda-filter-form nil)
6790 (org-agenda-set-mode-name))
6792 (defun org-agenda-manipulate-query-add ()
6793 "Manipulate the query by adding a search term with positive selection.
6794 Positive selection means the term must be matched for selection of an entry."
6796 (org-agenda-manipulate-query ?\[))
6797 (defun org-agenda-manipulate-query-subtract ()
6798 "Manipulate the query by adding a search term with negative selection.
6799 Negative selection means term must not be matched for selection of an entry."
6801 (org-agenda-manipulate-query ?\]))
6802 (defun org-agenda-manipulate-query-add-re ()
6803 "Manipulate the query by adding a search regexp with positive selection.
6804 Positive selection means the regexp must match for selection of an entry."
6806 (org-agenda-manipulate-query ?\{))
6807 (defun org-agenda-manipulate-query-subtract-re ()
6808 "Manipulate the query by adding a search regexp with negative selection.
6809 Negative selection means regexp must not match for selection of an entry."
6811 (org-agenda-manipulate-query ?\}))
6812 (defun org-agenda-manipulate-query (char)
6814 ((memq org-agenda-type '(timeline agenda))
6815 (let ((org-agenda-include-inactive-timestamps t))
6817 (message "Display now includes inactive timestamps as well"))
6818 ((eq org-agenda-type 'search)
6820 'org-agenda-query-string
6821 (if org-agenda-last-search-view-search-was-boolean
6822 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6823 (?\{ . " +{}") (?\} . " -{}"))))
6825 (setq org-agenda-redo-command
6826 (list 'org-search-view
6828 org-agenda-query-string
6829 (+ (length org-agenda-query-string)
6830 (if (member char '(?\{ ?\})) 0 1))))
6831 (set-register org-agenda-query-register org-agenda-query-string)
6833 (t (error "Cannot manipulate query for %s-type agenda buffers"
6836 (defun org-add-to-string (var string)
6837 (set var (concat (symbol-value var) string)))
6839 (defun org-agenda-goto-date (date)
6840 "Jump to DATE in agenda."
6841 (interactive (list (let ((org-read-date-prefer-future
6842 (eval org-agenda-jump-prefer-future)))
6844 (org-agenda-list nil date))
6846 (defun org-agenda-goto-today ()
6849 (org-agenda-check-type t 'timeline 'agenda)
6850 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6852 (tdpos (goto-char tdpos))
6853 ((eq org-agenda-type 'agenda)
6854 (let* ((sd (org-agenda-compute-starting-span
6855 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6856 (org-agenda-overriding-arguments org-agenda-last-arguments))
6857 (setf (nth 1 org-agenda-overriding-arguments) sd)
6859 (org-agenda-find-same-or-today-or-agenda)))
6860 (t (error "Cannot find today")))))
6862 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6864 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6865 (text-property-any (point-min) (point-max) 'org-today t)
6866 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6869 (defun org-agenda-later (arg)
6870 "Go forward in time by thee current span.
6871 With prefix ARG, go forward that many times the current span."
6873 (org-agenda-check-type t 'agenda)
6874 (let* ((span org-agenda-current-span)
6875 (sd org-starting-day)
6876 (greg (calendar-gregorian-from-absolute sd))
6877 (cnt (org-get-at-bol 'org-day-cnt))
6881 (setq sd (+ arg sd)))
6883 (setq sd (+ (* 7 arg) sd)))
6885 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6886 sd (calendar-absolute-from-gregorian greg2))
6887 (setcar greg2 (1+ (car greg2))))
6889 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6890 sd (calendar-absolute-from-gregorian greg2))
6891 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6893 (setq sd (+ (* span arg) sd))))
6894 (let ((org-agenda-overriding-arguments
6895 (list (car org-agenda-last-arguments) sd span t)))
6897 (org-agenda-find-same-or-today-or-agenda cnt))))
6899 (defun org-agenda-earlier (arg)
6900 "Go backward in time by the current span.
6901 With prefix ARG, go backward that many times the current span."
6903 (org-agenda-later (- arg)))
6905 (defun org-agenda-view-mode-dispatch ()
6906 "Call one of the view mode commands."
6908 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6909 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6910 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
6911 (let ((a (read-char-exclusive)))
6913 (?\ (call-interactively 'org-agenda-reset-view))
6914 (?d (call-interactively 'org-agenda-day-view))
6915 (?w (call-interactively 'org-agenda-week-view))
6916 (?m (call-interactively 'org-agenda-month-view))
6917 (?y (call-interactively 'org-agenda-year-view))
6918 (?l (call-interactively 'org-agenda-log-mode))
6919 (?L (org-agenda-log-mode '(4)))
6920 (?c (org-agenda-log-mode 'clockcheck))
6921 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6922 (?a (call-interactively 'org-agenda-archives-mode))
6923 (?A (org-agenda-archives-mode 'files))
6924 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6925 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6926 (?G (call-interactively 'org-agenda-toggle-time-grid))
6927 (?D (call-interactively 'org-agenda-toggle-diary))
6928 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6929 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6930 (org-agenda-check-type t 'timeline 'agenda)
6932 (message "Display now includes inactive timestamps as well"))
6933 (?q (message "Abort"))
6934 (otherwise (error "Invalid key" )))))
6936 (defun org-agenda-reset-view ()
6937 "Switch to default view for agenda."
6939 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6940 (defun org-agenda-day-view (&optional day-of-year)
6941 "Switch to daily view for agenda.
6942 With argument DAY-OF-YEAR, switch to that day of the year."
6944 (org-agenda-change-time-span 'day day-of-year))
6945 (defun org-agenda-week-view (&optional iso-week)
6946 "Switch to daily view for agenda.
6947 With argument ISO-WEEK, switch to the corresponding ISO week.
6948 If ISO-WEEK has more then 2 digits, only the last two encode the
6949 week. Any digits before this encode a year. So 200712 means
6950 week 12 of year 2007. Years in the range 1938-2037 can also be
6951 written as 2-digit years."
6953 (org-agenda-change-time-span 'week iso-week))
6954 (defun org-agenda-month-view (&optional month)
6955 "Switch to monthly view for agenda.
6956 With argument MONTH, switch to that month."
6958 (org-agenda-change-time-span 'month month))
6959 (defun org-agenda-year-view (&optional year)
6960 "Switch to yearly view for agenda.
6961 With argument YEAR, switch to that year.
6962 If MONTH has more then 2 digits, only the last two encode the
6963 month. Any digits before this encode a year. So 200712 means
6964 December year 2007. Years in the range 1938-2037 can also be
6965 written as 2-digit years."
6968 (setq year (org-small-year-to-year year)))
6969 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6970 (org-agenda-change-time-span 'year year)
6973 (defun org-agenda-change-time-span (span &optional n)
6974 "Change the agenda view to SPAN.
6975 SPAN may be `day', `week', `month', `year'."
6976 (org-agenda-check-type t 'agenda)
6977 (if (and (not n) (equal org-agenda-current-span span))
6978 (error "Viewing span is already \"%s\"" span))
6979 (let* ((sd (or (org-get-at-bol 'day)
6981 (sd (org-agenda-compute-starting-span sd span n))
6982 (org-agenda-overriding-arguments
6983 (or org-agenda-overriding-arguments
6984 (list (car org-agenda-last-arguments) sd span t))))
6986 (org-agenda-find-same-or-today-or-agenda))
6987 (org-agenda-set-mode-name)
6988 (message "Switched to %s view" span))
6990 (defun org-agenda-compute-starting-span (sd span &optional n)
6991 "Compute starting date for agenda.
6992 SPAN may be `day', `week', `month', `year'. The return value
6993 is a cons cell with the starting date and the number of days,
6994 so that the date SD will be in that range."
6995 (let* ((greg (calendar-gregorian-from-absolute sd))
7002 (setq sd (+ (calendar-absolute-from-gregorian
7006 (let* ((nt (calendar-day-of-week
7007 (calendar-gregorian-from-absolute sd)))
7008 (d (if org-agenda-start-on-weekday
7009 (- nt org-agenda-start-on-weekday)
7012 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7016 (setq y1 (org-small-year-to-year (/ n 100))
7019 (calendar-absolute-from-iso
7021 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7024 (when (and n (> n 99))
7025 (setq y1 (org-small-year-to-year (/ n 100))
7027 (setq sd (calendar-absolute-from-gregorian
7028 (list (or n mg) 1 (or y1 yg))))))
7030 (setq sd (calendar-absolute-from-gregorian
7031 (list 1 1 (or n yg))))))
7034 (defun org-agenda-next-date-line (&optional arg)
7035 "Jump to the next line indicating a date in agenda buffer."
7037 (org-agenda-check-type t 'agenda 'timeline)
7038 (beginning-of-line 1)
7039 ;; This does not work if user makes date format that starts with a blank
7040 (if (looking-at "^\\S-") (forward-char 1))
7041 (if (not (re-search-forward "^\\S-" nil t arg))
7044 (error "No next date after this line in this buffer")))
7045 (goto-char (match-beginning 0)))
7047 (defun org-agenda-previous-date-line (&optional arg)
7048 "Jump to the previous line indicating a date in agenda buffer."
7050 (org-agenda-check-type t 'agenda 'timeline)
7051 (beginning-of-line 1)
7052 (if (not (re-search-backward "^\\S-" nil t arg))
7053 (error "No previous date before this line in this buffer")))
7055 ;; Initialize the highlight
7056 (defvar org-hl (make-overlay 1 1))
7057 (overlay-put org-hl 'face 'highlight)
7059 (defun org-highlight (begin end &optional buffer)
7060 "Highlight a region with overlay."
7061 (move-overlay org-hl begin end (or buffer (current-buffer))))
7063 (defun org-unhighlight ()
7064 "Detach overlay INDEX."
7065 (org-detach-overlay org-hl))
7067 ;; FIXME this is currently not used.
7068 (defun org-highlight-until-next-command (beg end &optional buffer)
7069 "Move the highlight overlay to BEG/END, remove it before the next command."
7070 (org-highlight beg end buffer)
7071 (add-hook 'pre-command-hook 'org-unhighlight-once))
7072 (defun org-unhighlight-once ()
7073 "Remove the highlight from its position, and this function from the hook."
7074 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7077 (defun org-agenda-follow-mode ()
7078 "Toggle follow mode in an agenda buffer."
7080 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7081 (org-agenda-set-mode-name)
7082 (org-agenda-do-context-action)
7083 (message "Follow mode is %s"
7084 (if org-agenda-follow-mode "on" "off")))
7086 (defun org-agenda-entry-text-mode (&optional arg)
7087 "Toggle entry text mode in an agenda buffer."
7089 (setq org-agenda-entry-text-mode (or (integerp arg)
7090 (not org-agenda-entry-text-mode)))
7091 (org-agenda-entry-text-hide)
7092 (and org-agenda-entry-text-mode
7093 (let ((org-agenda-entry-text-maxlines
7094 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7095 (org-agenda-entry-text-show)))
7096 (org-agenda-set-mode-name)
7097 (message "Entry text mode is %s. Maximum number of lines is %d"
7098 (if org-agenda-entry-text-mode "on" "off")
7099 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7101 (defun org-agenda-clockreport-mode (&optional with-filter)
7102 "Toggle clocktable mode in an agenda buffer.
7103 With prefix arg WITH-FILTER, make the clocktable respect the current
7106 (org-agenda-check-type t 'agenda)
7108 (setq org-agenda-clockreport-mode 'with-filter)
7109 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7110 (org-agenda-set-mode-name)
7112 (message "Clocktable mode is %s"
7113 (if org-agenda-clockreport-mode "on" "off")))
7115 (defun org-agenda-log-mode (&optional special)
7116 "Toggle log mode in an agenda buffer.
7117 With argument SPECIAL, show all possible log items, not only the ones
7118 configured in `org-agenda-log-mode-items'.
7119 With a double `C-u' prefix arg, show *only* log items, nothing else."
7121 (org-agenda-check-type t 'agenda 'timeline)
7122 (setq org-agenda-show-log
7124 ((equal special '(16)) 'only)
7125 ((eq special 'clockcheck)
7126 (if (eq org-agenda-show-log 'clockcheck)
7128 (special '(closed clock state))
7129 (t (not org-agenda-show-log))))
7130 (org-agenda-set-mode-name)
7132 (message "Log mode is %s"
7133 (if org-agenda-show-log "on" "off")))
7135 (defun org-agenda-archives-mode (&optional with-files)
7136 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7137 When called with a prefix argument, include all archive files as well."
7139 (setq org-agenda-archives-mode
7140 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7141 (org-agenda-set-mode-name)
7146 ((eq org-agenda-archives-mode nil)
7147 "No archives are included")
7148 ((eq org-agenda-archives-mode 'trees)
7149 (format "Trees with :%s: tag are included" org-archive-tag))
7150 ((eq org-agenda-archives-mode t)
7151 (format "Trees with :%s: tag and all active archive files are included"
7152 org-archive-tag)))))
7154 (defun org-agenda-toggle-diary ()
7155 "Toggle diary inclusion in an agenda buffer."
7157 (org-agenda-check-type t 'agenda)
7158 (setq org-agenda-include-diary (not org-agenda-include-diary))
7160 (org-agenda-set-mode-name)
7161 (message "Diary inclusion turned %s"
7162 (if org-agenda-include-diary "on" "off")))
7164 (defun org-agenda-toggle-deadlines ()
7165 "Toggle inclusion of entries with a deadline in an agenda buffer."
7167 (org-agenda-check-type t 'agenda)
7168 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7170 (org-agenda-set-mode-name)
7171 (message "Deadlines inclusion turned %s"
7172 (if org-agenda-include-deadlines "on" "off")))
7174 (defun org-agenda-toggle-time-grid ()
7175 "Toggle time grid in an agenda buffer."
7177 (org-agenda-check-type t 'agenda)
7178 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7180 (org-agenda-set-mode-name)
7181 (message "Time-grid turned %s"
7182 (if org-agenda-use-time-grid "on" "off")))
7184 (defun org-agenda-set-mode-name ()
7185 "Set the mode name to indicate all the small mode settings."
7188 (if (get 'org-agenda-files 'org-restrict) " []" "")
7190 '(:eval (org-agenda-span-name org-agenda-current-span))
7191 (if org-agenda-follow-mode " Follow" "")
7192 (if org-agenda-entry-text-mode " ETxt" "")
7193 (if org-agenda-include-diary " Diary" "")
7194 (if org-agenda-include-deadlines " Ddl" "")
7195 (if org-agenda-use-time-grid " Grid" "")
7196 (if (and (boundp 'org-habit-show-habits)
7197 org-habit-show-habits) " Habit" "")
7199 ((consp org-agenda-show-log) " LogAll")
7200 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7201 (org-agenda-show-log " Log")
7203 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7205 '(:eval (org-propertize
7210 (get 'org-agenda-category-filter :preset-filter)
7211 org-agenda-category-filter)
7214 'face 'org-agenda-filter-category
7215 'help-echo "Category used in filtering"))
7217 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7219 '(:eval (org-propertize
7224 (get 'org-agenda-tag-filter :preset-filter)
7225 org-agenda-tag-filter)
7228 'face 'org-agenda-filter-tags
7229 'help-echo "Tags used in filtering"))
7231 (if org-agenda-archives-mode
7232 (if (eq org-agenda-archives-mode t)
7234 (format " :%s:" org-archive-tag))
7236 (if org-agenda-clockreport-mode
7237 (if (eq org-agenda-clockreport-mode 'with-filter)
7238 " Clock{}" " Clock")
7240 (force-mode-line-update))
7242 (defun org-agenda-post-command-hook ()
7243 (setq org-agenda-type
7244 (or (get-text-property (point) 'org-agenda-type)
7245 (get-text-property (max (point-min) (1- (point)))
7246 'org-agenda-type))))
7248 (defun org-agenda-next-line ()
7249 "Move cursor to the next line, and show if follow mode is active."
7251 (call-interactively 'next-line)
7252 (org-agenda-do-context-action))
7254 (defun org-agenda-previous-line ()
7255 "Move cursor to the previous line, and show if follow-mode is active."
7257 (call-interactively 'previous-line)
7258 (org-agenda-do-context-action))
7260 (defun org-agenda-do-context-action ()
7261 "Show outline path and, maybe, follow mode window."
7262 (let ((m (org-get-at-bol 'org-marker)))
7263 (when (and (markerp m) (marker-buffer m))
7264 (and org-agenda-follow-mode
7265 (if org-agenda-follow-indirect
7266 (org-agenda-tree-to-indirect-buffer)
7268 (and org-agenda-show-outline-path
7269 (org-with-point-at m (org-display-outline-path t))))))
7271 (defun org-agenda-show-priority ()
7272 "Show the priority of the current item.
7273 This priority is composed of the main priority given with the [#A] cookies,
7274 and by additional input from the age of a schedules or deadline entry."
7276 (let* ((pri (org-get-at-bol 'priority)))
7277 (message "Priority is %d" (if pri pri -1000))))
7279 (defun org-agenda-show-tags ()
7280 "Show the tags applicable to the current item."
7282 (let* ((tags (org-get-at-bol 'tags)))
7284 (message "Tags are :%s:"
7285 (org-no-properties (mapconcat 'identity tags ":")))
7286 (message "No tags associated with this line"))))
7288 (defun org-agenda-goto (&optional highlight)
7289 "Go to the Org-mode file which contains the item at point."
7291 (let* ((marker (or (org-get-at-bol 'org-marker)
7292 (org-agenda-error)))
7293 (buffer (marker-buffer marker))
7294 (pos (marker-position marker)))
7295 (switch-to-buffer-other-window buffer)
7299 (when (derived-mode-p 'org-mode)
7300 (org-show-context 'agenda)
7302 (and (outline-next-heading)
7303 (org-flag-heading nil)))) ; show the next heading
7304 (when (outline-invisible-p)
7305 (show-entry)) ; display invisible text
7306 (recenter (/ (window-height) 2))
7307 (run-hooks 'org-agenda-after-show-hook)
7308 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7310 (defvar org-agenda-after-show-hook nil
7311 "Normal hook run after an item has been shown from the agenda.
7312 Point is in the buffer where the item originated.")
7314 (defun org-agenda-kill ()
7315 "Kill the entry or subtree belonging to the current agenda entry."
7317 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7318 (let* ((marker (or (org-get-at-bol 'org-marker)
7319 (org-agenda-error)))
7320 (buffer (marker-buffer marker))
7321 (pos (marker-position marker))
7322 (type (org-get-at-bol 'type))
7323 dbeg dend (n 0) conf)
7324 (org-with-remote-undo buffer
7325 (with-current-buffer buffer
7328 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7329 (setq dbeg (progn (org-back-to-heading t) (point))
7330 dend (org-end-of-subtree t t))
7331 (setq dbeg (point-at-bol)
7332 dend (min (point-max) (1+ (point-at-eol)))))
7334 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7335 (setq conf (or (eq t org-agenda-confirm-kill)
7336 (and (numberp org-agenda-confirm-kill)
7337 (> n org-agenda-confirm-kill))))
7340 (format "Delete entry with %d lines in buffer \"%s\"? "
7341 n (buffer-name buffer))))
7343 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7344 (with-current-buffer buffer (delete-region dbeg dend))
7345 (message "Agenda item and source killed"))))
7347 (defvar org-archive-default-command)
7348 (defun org-agenda-archive-default ()
7349 "Archive the entry or subtree belonging to the current agenda entry."
7351 (require 'org-archive)
7352 (org-agenda-archive-with org-archive-default-command))
7354 (defun org-agenda-archive-default-with-confirmation ()
7355 "Archive the entry or subtree belonging to the current agenda entry."
7357 (require 'org-archive)
7358 (org-agenda-archive-with org-archive-default-command 'confirm))
7360 (defun org-agenda-archive ()
7361 "Archive the entry or subtree belonging to the current agenda entry."
7363 (org-agenda-archive-with 'org-archive-subtree))
7365 (defun org-agenda-archive-to-archive-sibling ()
7366 "Move the entry to the archive sibling."
7368 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7370 (defun org-agenda-archive-with (cmd &optional confirm)
7371 "Move the entry to the archive sibling."
7373 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7374 (let* ((marker (or (org-get-at-bol 'org-marker)
7375 (org-agenda-error)))
7376 (buffer (marker-buffer marker))
7377 (pos (marker-position marker)))
7378 (org-with-remote-undo buffer
7379 (with-current-buffer buffer
7380 (if (derived-mode-p 'org-mode)
7382 (not (y-or-n-p "Archive this subtree or entry? ")))
7386 (org-remove-subtree-entries-from-agenda)
7387 (org-back-to-heading t)
7389 (error "Archiving works only in Org-mode files"))))))
7391 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7392 "Remove all lines in the agenda that correspond to a given subtree.
7393 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7394 If this information is not given, the function uses the tree at point."
7395 (let ((buf (or buf (current-buffer))) m p)
7397 (unless (and beg end)
7398 (org-back-to-heading t)
7400 (org-end-of-subtree t)
7402 (set-buffer (get-buffer org-agenda-buffer-name))
7404 (goto-char (point-max))
7405 (beginning-of-line 1)
7407 (when (and (setq m (org-get-at-bol 'org-marker))
7408 (equal buf (marker-buffer m))
7409 (setq p (marker-position m))
7412 (let ((inhibit-read-only t))
7413 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7414 (beginning-of-line 0))))))
7416 (defun org-agenda-refile (&optional goto rfloc no-update)
7417 "Refile the item at point."
7419 (if (equal goto '(16))
7420 (org-refile-goto-last-stored)
7421 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7422 (org-agenda-error)))
7423 (buffer (marker-buffer marker))
7424 (pos (marker-position marker))
7426 (org-refile-get-location
7427 (if goto "Goto" "Refile to") buffer
7428 org-refile-allow-creating-parent-nodes))))
7429 (with-current-buffer buffer
7434 (org-remove-subtree-entries-from-agenda)
7435 (org-refile goto buffer rfloc)))))
7436 (unless no-update (org-agenda-redo))))
7438 (defun org-agenda-open-link (&optional arg)
7439 "Follow the link in the current line, if any.
7440 This looks for a link in the displayed line in the agenda. It also looks
7441 at the text of the entry itself."
7443 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7444 (org-get-at-bol 'org-marker)))
7445 (buffer (and marker (marker-buffer marker)))
7446 (prefix (buffer-substring
7447 (point-at-bol) (point-at-eol))))
7450 (with-current-buffer buffer
7455 (org-offer-links-in-entry arg prefix)))))
7456 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7458 (beginning-of-line 1)
7459 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7460 (org-open-link-from-string (match-string 1)))
7461 (t (error "No link to open here")))))
7463 (defun org-agenda-copy-local-variable (var)
7464 "Get a variable from a referenced buffer and install it here."
7465 (let ((m (org-get-at-bol 'org-marker)))
7466 (when (and m (buffer-live-p (marker-buffer m)))
7467 (org-set-local var (with-current-buffer (marker-buffer m)
7468 (symbol-value var))))))
7470 (defun org-agenda-switch-to (&optional delete-other-windows)
7471 "Go to the Org-mode file which contains the item at point."
7473 (if (and org-return-follows-link
7474 (not (org-get-at-bol 'org-marker))
7475 (org-in-regexp org-bracket-link-regexp))
7476 (org-open-link-from-string (match-string 0))
7477 (let* ((marker (or (org-get-at-bol 'org-marker)
7478 (org-agenda-error)))
7479 (buffer (marker-buffer marker))
7480 (pos (marker-position marker)))
7481 (org-pop-to-buffer-same-window buffer)
7482 (and delete-other-windows (delete-other-windows))
7485 (when (derived-mode-p 'org-mode)
7486 (org-show-context 'agenda)
7488 (and (outline-next-heading)
7489 (org-flag-heading nil))) ; show the next heading
7490 (when (outline-invisible-p)
7491 (show-entry)))))) ; display invisible text
7493 (defun org-agenda-goto-mouse (ev)
7494 "Go to the Org-mode file which contains the item at the mouse click."
7496 (mouse-set-point ev)
7499 (defun org-agenda-show (&optional full-entry)
7500 "Display the Org-mode file which contains the item at point.
7501 With prefix argument FULL-ENTRY, make the entire entry visible
7502 if it was hidden in the outline."
7504 (let ((win (selected-window)))
7506 (let ((org-show-entry-below t))
7507 (org-agenda-goto t))
7508 (org-agenda-goto t))
7509 (select-window win)))
7511 (defvar org-agenda-show-window nil)
7512 (defun org-agenda-show-and-scroll-up (&optional arg)
7513 "Display the Org-mode file which contains the item at point.
7514 When called repeatedly, scroll the window that is displaying the buffer.
7515 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7516 `show-subtree' to display the item, so that drawers and logbooks stay
7519 (let ((win (selected-window)))
7520 (if (and (window-live-p org-agenda-show-window)
7521 (eq this-command last-command))
7523 (select-window org-agenda-show-window)
7524 (ignore-errors (scroll-up)))
7526 (if arg (org-show-entry) (show-subtree))
7527 (setq org-agenda-show-window (selected-window)))
7528 (select-window win)))
7530 (defun org-agenda-show-scroll-down ()
7531 "Scroll down the window showing the agenda."
7533 (let ((win (selected-window)))
7534 (when (window-live-p org-agenda-show-window)
7535 (select-window org-agenda-show-window)
7536 (ignore-errors (scroll-down))
7537 (select-window win))))
7539 (defun org-agenda-show-1 (&optional more)
7540 "Display the Org-mode file which contains the item at point.
7541 The prefix arg selects the amount of information to display:
7544 1 just show the entry according to defaults.
7545 2 show the children view
7546 3 show the subtree view
7547 4 show the entire subtree and any LOGBOOK drawers
7548 5 show the entire subtree and any drawers
7549 With prefix argument FULL-ENTRY, make the entire entry visible
7550 if it was hidden in the outline."
7552 (let ((win (selected-window)))
7554 (org-recenter-heading 1)
7559 (org-back-to-heading)
7560 (run-hook-with-args 'org-cycle-hook 'folded))
7561 (message "Remote: FOLDED"))
7562 ((and (org-called-interactively-p 'any) (= more 1))
7563 (message "Remote: show with default settings"))
7568 (org-back-to-heading)
7569 (run-hook-with-args 'org-cycle-hook 'children))
7570 (message "Remote: CHILDREN"))
7574 (org-back-to-heading)
7575 (run-hook-with-args 'org-cycle-hook 'subtree))
7576 (message "Remote: SUBTREE"))
7578 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7580 (concat "^[ \t]*:\\("
7581 (mapconcat 'regexp-quote org-drawers "\\|")
7585 (org-back-to-heading)
7586 (org-cycle-hide-drawers 'subtree)))
7587 (message "Remote: SUBTREE AND LOGBOOK"))
7590 (message "Remote: SUBTREE AND ALL DRAWERS")))
7591 (select-window win)))
7593 (defun org-recenter-heading (n)
7595 (org-back-to-heading)
7598 (defvar org-agenda-cycle-counter nil)
7599 (defun org-agenda-cycle-show (&optional n)
7600 "Show the current entry in another window, with default settings.
7601 Default settings are taken from `org-show-hierarchy-above' and siblings.
7602 When use repeatedly in immediate succession, the remote entry will cycle
7605 children -> subtree -> folded
7607 When called with a numeric prefix arg, that arg will be passed through to
7608 `org-agenda-show-1'. For the interpretation of that argument, see the
7609 docstring of `org-agenda-show-1'."
7612 (setq org-agenda-cycle-counter n)
7613 (if (not (eq last-command this-command))
7614 (setq org-agenda-cycle-counter 1)
7615 (if (equal org-agenda-cycle-counter 0)
7616 (setq org-agenda-cycle-counter 2)
7617 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7618 (if (> org-agenda-cycle-counter 3)
7619 (setq org-agenda-cycle-counter 0)))))
7620 (org-agenda-show-1 org-agenda-cycle-counter))
7622 (defun org-agenda-recenter (arg)
7623 "Display the Org-mode file which contains the item at point and recenter."
7625 (let ((win (selected-window)))
7628 (select-window win)))
7630 (defun org-agenda-show-mouse (ev)
7631 "Display the Org-mode file which contains the item at the mouse click."
7633 (mouse-set-point ev)
7636 (defun org-agenda-check-no-diary ()
7637 "Check if the entry is a diary link and abort if yes."
7638 (if (org-get-at-bol 'org-agenda-diary-link)
7639 (org-agenda-error)))
7641 (defun org-agenda-error ()
7642 (error "Command not allowed in this line"))
7644 (defun org-agenda-tree-to-indirect-buffer ()
7645 "Show the subtree corresponding to the current entry in an indirect buffer.
7646 This calls the command `org-tree-to-indirect-buffer' from the original
7648 With numerical prefix arg ARG, go up to this level and then take that tree.
7649 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7650 use the dedicated frame)."
7652 (if (and current-prefix-arg (listp current-prefix-arg))
7653 (org-agenda-do-tree-to-indirect-buffer)
7654 (let ((agenda-window (selected-window))
7656 (and org-last-indirect-buffer
7657 (get-buffer-window org-last-indirect-buffer))))
7658 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7661 (unless (and indirect-window (window-live-p indirect-window))
7662 (setq indirect-window (split-window agenda-window)))
7663 (select-window indirect-window)
7664 (switch-to-buffer org-last-indirect-buffer :norecord)
7665 (fit-window-to-buffer indirect-window))
7666 (select-window (get-buffer-window org-agenda-buffer-name))))))
7668 (defun org-agenda-do-tree-to-indirect-buffer ()
7669 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7670 (org-agenda-check-no-diary)
7671 (let* ((marker (or (org-get-at-bol 'org-marker)
7672 (org-agenda-error)))
7673 (buffer (marker-buffer marker))
7674 (pos (marker-position marker)))
7675 (with-current-buffer buffer
7678 (call-interactively 'org-tree-to-indirect-buffer)))))
7680 (defvar org-last-heading-marker (make-marker)
7681 "Marker pointing to the headline that last changed its TODO state
7682 by a remote command from the agenda.")
7684 (defun org-agenda-todo-nextset ()
7685 "Switch TODO entry to next sequence."
7687 (org-agenda-todo 'nextset))
7689 (defun org-agenda-todo-previousset ()
7690 "Switch TODO entry to previous sequence."
7692 (org-agenda-todo 'previousset))
7694 (defun org-agenda-todo (&optional arg)
7695 "Cycle TODO state of line at point, also in Org-mode file.
7696 This changes the line at point, all other lines in the agenda referring to
7697 the same tree node, and the headline of the tree node in the Org-mode file."
7699 (org-agenda-check-no-diary)
7700 (let* ((col (current-column))
7701 (marker (or (org-get-at-bol 'org-marker)
7702 (org-agenda-error)))
7703 (buffer (marker-buffer marker))
7704 (pos (marker-position marker))
7705 (hdmarker (org-get-at-bol 'org-hd-marker))
7706 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7707 (inhibit-read-only t)
7708 org-agenda-headline-snapshot-before-repeat newhead just-one)
7709 (org-with-remote-undo buffer
7710 (with-current-buffer buffer
7713 (org-show-context 'agenda)
7715 (and (outline-next-heading)
7716 (org-flag-heading nil))) ; show the next heading
7717 (let ((current-prefix-arg arg))
7718 (call-interactively 'org-todo))
7719 (and (bolp) (forward-char 1))
7720 (setq newhead (org-get-heading))
7721 (when (and (org-bound-and-true-p
7722 org-agenda-headline-snapshot-before-repeat)
7723 (not (equal org-agenda-headline-snapshot-before-repeat
7726 (setq newhead org-agenda-headline-snapshot-before-repeat
7729 (org-back-to-heading)
7730 (move-marker org-last-heading-marker (point))))
7731 (beginning-of-line 1)
7733 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7734 (org-move-to-column col))))
7736 (defun org-agenda-add-note (&optional arg)
7737 "Add a time-stamped note to the entry at point."
7739 (org-agenda-check-no-diary)
7740 (let* ((marker (or (org-get-at-bol 'org-marker)
7741 (org-agenda-error)))
7742 (buffer (marker-buffer marker))
7743 (pos (marker-position marker))
7744 (hdmarker (org-get-at-bol 'org-hd-marker))
7745 (inhibit-read-only t))
7746 (with-current-buffer buffer
7749 (org-show-context 'agenda)
7751 (and (outline-next-heading)
7752 (org-flag-heading nil))) ; show the next heading
7755 (defun org-agenda-change-all-lines (newhead hdmarker
7756 &optional fixface just-this)
7757 "Change all lines in the agenda buffer which match HDMARKER.
7758 The new content of the line will be NEWHEAD (as modified by
7759 `org-agenda-format-item'). HDMARKER is checked with
7760 `equal' against all `org-hd-marker' text properties in the file.
7761 If FIXFACE is non-nil, the face of each item is modified according to
7763 If JUST-THIS is non-nil, change just the current line, not all.
7764 If FORCE-TAGS is non nil, the car of it returns the new tags."
7765 (let* ((inhibit-read-only t)
7766 (line (org-current-line))
7767 (org-agenda-buffer (current-buffer))
7768 (thetags (with-current-buffer (marker-buffer hdmarker)
7769 (save-excursion (save-restriction (widen)
7770 (goto-char hdmarker)
7771 (org-get-tags-at)))))
7772 props m pl undone-face done-face finish new dotime cat tags)
7774 (goto-char (point-max))
7775 (beginning-of-line 1)
7777 (setq finish (bobp))
7778 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7779 (or (not just-this) (= (org-current-line) line))
7781 (setq props (text-properties-at (point))
7782 dotime (org-get-at-bol 'dotime)
7783 cat (org-get-at-bol 'org-category)
7786 (let ((org-prefix-format-compiled
7787 (or (get-text-property (point) 'format)
7788 org-prefix-format-compiled))
7789 (extra (org-get-at-bol 'extra)))
7790 (with-current-buffer (marker-buffer hdmarker)
7794 (org-agenda-format-item extra newhead cat tags dotime)))))
7795 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7796 undone-face (org-get-at-bol 'undone-face)
7797 done-face (org-get-at-bol 'done-face))
7798 (beginning-of-line 1)
7801 (and (looking-at ".*\n?") (replace-match "")))
7803 (replace-match new t t)
7804 (beginning-of-line 1)
7805 (add-text-properties (point-at-bol) (point-at-eol) props)
7807 (add-text-properties
7808 (point-at-bol) (point-at-eol)
7810 (if org-last-todo-state-is-todo
7811 undone-face done-face))))
7812 (org-agenda-highlight-todo 'line)
7813 (beginning-of-line 1))
7814 (t (error "Line update did not work"))))
7815 (beginning-of-line 0)))
7816 (org-finalize-agenda)))
7818 (defun org-agenda-align-tags (&optional line)
7819 "Align all tags in agenda items to `org-agenda-tags-column'."
7820 (let ((inhibit-read-only t) l c)
7822 (goto-char (if line (point-at-bol) (point-min)))
7823 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7824 (if line (point-at-eol) nil) t)
7825 (add-text-properties
7826 (match-beginning 2) (match-end 2)
7827 (list 'face (delq nil (let ((prop (get-text-property
7828 (match-beginning 2) 'face)))
7829 (or (listp prop) (setq prop (list prop)))
7830 (if (memq 'org-tag prop)
7832 (cons 'org-tag prop))))))
7833 (setq l (- (match-end 2) (match-beginning 2))
7834 c (if (< org-agenda-tags-column 0)
7835 (- (abs org-agenda-tags-column) l)
7836 org-agenda-tags-column))
7837 (delete-region (match-beginning 1) (match-end 1))
7838 (goto-char (match-beginning 1))
7839 (insert (org-add-props
7840 (make-string (max 1 (- c (current-column))) ?\ )
7841 (plist-put (copy-sequence (text-properties-at (point)))
7843 (goto-char (point-min))
7844 (org-font-lock-add-tag-faces (point-max)))))
7846 (defun org-agenda-priority-up ()
7847 "Increase the priority of line at point, also in Org-mode file."
7849 (org-agenda-priority 'up))
7851 (defun org-agenda-priority-down ()
7852 "Decrease the priority of line at point, also in Org-mode file."
7854 (org-agenda-priority 'down))
7856 (defun org-agenda-priority (&optional force-direction)
7857 "Set the priority of line at point, also in Org-mode file.
7858 This changes the line at point, all other lines in the agenda referring to
7859 the same tree node, and the headline of the tree node in the Org-mode file."
7861 (unless org-enable-priority-commands
7862 (error "Priority commands are disabled"))
7863 (org-agenda-check-no-diary)
7864 (let* ((marker (or (org-get-at-bol 'org-marker)
7865 (org-agenda-error)))
7866 (hdmarker (org-get-at-bol 'org-hd-marker))
7867 (buffer (marker-buffer hdmarker))
7868 (pos (marker-position hdmarker))
7869 (inhibit-read-only t)
7871 (org-with-remote-undo buffer
7872 (with-current-buffer buffer
7875 (org-show-context 'agenda)
7877 (and (outline-next-heading)
7878 (org-flag-heading nil))) ; show the next heading
7879 (funcall 'org-priority force-direction)
7881 (setq newhead (org-get-heading)))
7882 (org-agenda-change-all-lines newhead hdmarker)
7883 (beginning-of-line 1))))
7885 ;; FIXME: should fix the tags property of the agenda line.
7886 (defun org-agenda-set-tags (&optional tag onoff)
7887 "Set tags for the current headline."
7889 (org-agenda-check-no-diary)
7890 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7891 (call-interactively 'org-change-tag-in-region)
7892 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7893 (org-agenda-error)))
7894 (buffer (marker-buffer hdmarker))
7895 (pos (marker-position hdmarker))
7896 (inhibit-read-only t)
7898 (org-with-remote-undo buffer
7899 (with-current-buffer buffer
7903 (org-show-context 'agenda))
7905 (and (outline-next-heading)
7906 (org-flag-heading nil))) ; show the next heading
7909 (org-toggle-tag tag onoff)
7910 (call-interactively 'org-set-tags))
7912 (setq newhead (org-get-heading)))
7913 (org-agenda-change-all-lines newhead hdmarker)
7914 (beginning-of-line 1)))))
7916 (defun org-agenda-set-property ()
7917 "Set a property for the current headline."
7919 (org-agenda-check-no-diary)
7920 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7921 (org-agenda-error)))
7922 (buffer (marker-buffer hdmarker))
7923 (pos (marker-position hdmarker))
7924 (inhibit-read-only t)
7926 (org-with-remote-undo buffer
7927 (with-current-buffer buffer
7931 (org-show-context 'agenda))
7933 (and (outline-next-heading)
7934 (org-flag-heading nil))) ; show the next heading
7936 (call-interactively 'org-set-property)))))
7938 (defun org-agenda-set-effort ()
7939 "Set the effort property for the current headline."
7941 (org-agenda-check-no-diary)
7942 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7943 (org-agenda-error)))
7944 (buffer (marker-buffer hdmarker))
7945 (pos (marker-position hdmarker))
7946 (inhibit-read-only t)
7948 (org-with-remote-undo buffer
7949 (with-current-buffer buffer
7953 (org-show-context 'agenda))
7955 (and (outline-next-heading)
7956 (org-flag-heading nil))) ; show the next heading
7958 (call-interactively 'org-set-effort)
7960 (setq newhead (org-get-heading)))
7961 (org-agenda-change-all-lines newhead hdmarker))))
7963 (defun org-agenda-toggle-archive-tag ()
7964 "Toggle the archive tag for the current entry."
7966 (org-agenda-check-no-diary)
7967 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7968 (org-agenda-error)))
7969 (buffer (marker-buffer hdmarker))
7970 (pos (marker-position hdmarker))
7971 (inhibit-read-only t)
7973 (org-with-remote-undo buffer
7974 (with-current-buffer buffer
7977 (org-show-context 'agenda)
7979 (and (outline-next-heading)
7980 (org-flag-heading nil))) ; show the next heading
7981 (call-interactively 'org-toggle-archive-tag)
7983 (setq newhead (org-get-heading)))
7984 (org-agenda-change-all-lines newhead hdmarker)
7985 (beginning-of-line 1))))
7987 (defun org-agenda-do-date-later (arg)
7990 ((or (equal arg '(16))
7992 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7993 (setq this-command 'org-agenda-date-later-minutes)
7994 (org-agenda-date-later-minutes 1))
7995 ((or (equal arg '(4))
7997 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7998 (setq this-command 'org-agenda-date-later-hours)
7999 (org-agenda-date-later-hours 1))
8001 (org-agenda-date-later (prefix-numeric-value arg)))))
8003 (defun org-agenda-do-date-earlier (arg)
8006 ((or (equal arg '(16))
8008 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8009 (setq this-command 'org-agenda-date-earlier-minutes)
8010 (org-agenda-date-earlier-minutes 1))
8011 ((or (equal arg '(4))
8013 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8014 (setq this-command 'org-agenda-date-earlier-hours)
8015 (org-agenda-date-earlier-hours 1))
8017 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8019 (defun org-agenda-date-later (arg &optional what)
8020 "Change the date of this item to ARG day(s) later."
8022 (org-agenda-check-type t 'agenda 'timeline)
8023 (org-agenda-check-no-diary)
8024 (let* ((marker (or (org-get-at-bol 'org-marker)
8025 (org-agenda-error)))
8026 (buffer (marker-buffer marker))
8027 (pos (marker-position marker))
8029 (org-with-remote-undo buffer
8030 (with-current-buffer buffer
8033 (if (not (org-at-timestamp-p))
8034 (error "Cannot find time stamp"))
8035 (when (and org-agenda-move-date-from-past-immediately-to-today
8037 (or (not what) (eq what 'day))
8038 (not (save-match-data (org-at-date-range-p))))
8039 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8040 cdate (calendar-absolute-from-gregorian
8041 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8044 ;; immediately shift to today
8045 (setq arg (- today cdate))))
8046 (org-timestamp-change arg (or what 'day))
8047 (when (and (org-at-date-range-p)
8048 (re-search-backward org-tr-regexp-both (point-at-bol)))
8049 (let ((end org-last-changed-timestamp))
8050 (org-timestamp-change arg (or what 'day))
8051 (setq org-last-changed-timestamp
8052 (concat org-last-changed-timestamp "--" end)))))
8053 (org-agenda-show-new-time marker org-last-changed-timestamp))
8054 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8056 (defun org-agenda-date-earlier (arg &optional what)
8057 "Change the date of this item to ARG day(s) earlier."
8059 (org-agenda-date-later (- arg) what))
8061 (defun org-agenda-date-later-minutes (arg)
8062 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8064 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8065 (org-agenda-date-later arg 'minute))
8067 (defun org-agenda-date-earlier-minutes (arg)
8068 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8070 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8071 (org-agenda-date-earlier arg 'minute))
8073 (defun org-agenda-date-later-hours (arg)
8074 "Change the time of this item, in hour steps."
8076 (org-agenda-date-later arg 'hour))
8078 (defun org-agenda-date-earlier-hours (arg)
8079 "Change the time of this item, in hour steps."
8081 (org-agenda-date-earlier arg 'hour))
8083 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8084 "Show new date stamp via text properties."
8085 ;; We use text properties to make this undoable
8086 (let ((inhibit-read-only t)
8087 (buffer-invisibility-spec))
8088 (setq stamp (concat " " prefix " => " stamp))
8090 (goto-char (point-max))
8092 (when (equal marker (org-get-at-bol 'org-marker))
8093 (org-move-to-column (- (window-width) (length stamp)) t)
8094 (org-agenda-fix-tags-filter-overlays-at (point))
8095 (if (featurep 'xemacs)
8096 ;; Use `duplicable' property to trigger undo recording
8097 (let ((ex (make-extent nil nil))
8098 (gl (make-glyph stamp)))
8099 (set-glyph-face gl 'secondary-selection)
8100 (set-extent-properties
8101 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8102 (insert-extent ex (1- (point)) (point-at-eol)))
8103 (add-text-properties
8104 (1- (point)) (point-at-eol)
8105 (list 'display (org-add-props stamp nil
8106 'face 'secondary-selection))))
8107 (beginning-of-line 1))
8108 (beginning-of-line 0)))))
8110 (defun org-agenda-date-prompt (arg)
8111 "Change the date of this item. Date is prompted for, with default today.
8112 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8113 be used to request time specification in the time stamp."
8115 (org-agenda-check-type t 'agenda 'timeline)
8116 (org-agenda-check-no-diary)
8117 (let* ((marker (or (org-get-at-bol 'org-marker)
8118 (org-agenda-error)))
8119 (buffer (marker-buffer marker))
8120 (pos (marker-position marker)))
8121 (org-with-remote-undo buffer
8122 (with-current-buffer buffer
8125 (if (not (org-at-timestamp-p t))
8126 (error "Cannot find time stamp"))
8127 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8128 (org-agenda-show-new-time marker org-last-changed-timestamp))
8129 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8131 (defun org-agenda-schedule (arg &optional time)
8132 "Schedule the item at point.
8133 ARG is passed through to `org-schedule'."
8135 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8136 (org-agenda-check-no-diary)
8137 (let* ((marker (or (org-get-at-bol 'org-marker)
8138 (org-agenda-error)))
8139 (type (marker-insertion-type marker))
8140 (buffer (marker-buffer marker))
8141 (pos (marker-position marker))
8142 (org-insert-labeled-timestamps-at-point nil)
8144 (set-marker-insertion-type marker t)
8145 (org-with-remote-undo buffer
8146 (with-current-buffer buffer
8149 (setq ts (org-schedule arg time)))
8150 (org-agenda-show-new-time marker ts "S"))
8151 (message "Item scheduled for %s" ts)))
8153 (defun org-agenda-deadline (arg &optional time)
8154 "Schedule the item at point.
8155 ARG is passed through to `org-deadline'."
8157 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8158 (org-agenda-check-no-diary)
8159 (let* ((marker (or (org-get-at-bol 'org-marker)
8160 (org-agenda-error)))
8161 (buffer (marker-buffer marker))
8162 (pos (marker-position marker))
8163 (org-insert-labeled-timestamps-at-point nil)
8165 (org-with-remote-undo buffer
8166 (with-current-buffer buffer
8169 (setq ts (org-deadline arg time)))
8170 (org-agenda-show-new-time marker ts "D"))
8171 (message "Deadline for this item set to %s" ts)))
8173 (defun org-agenda-action ()
8174 "Select entry for agenda action, or execute an agenda action.
8175 This command prompts for another letter. Valid inputs are:
8177 m Mark the entry at point for an agenda action
8178 s Schedule the marked entry to the date at the cursor
8179 d Set the deadline of the marked entry to the date at the cursor
8180 r Call `org-remember' with cursor date as the default date
8181 c Call `org-capture' with cursor date as the default date
8182 SPC Show marked entry in other window
8183 TAB Visit marked entry in other window
8185 The cursor may be at a date in the calendar, or in the Org agenda."
8188 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8189 (setq ans (read-char-exclusive))
8193 (if (eq major-mode 'org-agenda-mode)
8194 (let ((m (or (org-get-at-bol 'org-hd-marker)
8195 (org-get-at-bol 'org-marker))))
8198 (move-marker org-agenda-action-marker
8199 (marker-position m) (marker-buffer m))
8200 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8201 (error "Don't know which entry to mark")))
8202 (error "This command works only in the agenda")))
8204 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8206 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8208 (org-agenda-do-action '(org-remember) t))
8210 (org-agenda-do-action '(org-capture) t))
8212 (let ((cw (selected-window)))
8213 (org-switch-to-buffer-other-window
8214 (marker-buffer org-agenda-action-marker))
8215 (goto-char org-agenda-action-marker)
8216 (org-show-context 'agenda)
8217 (select-window cw)))
8219 (org-switch-to-buffer-other-window
8220 (marker-buffer org-agenda-action-marker))
8221 (goto-char org-agenda-action-marker)
8222 (org-show-context 'agenda))
8223 (t (error "Invalid agenda action %c" ans)))))
8225 (defun org-agenda-do-action (form &optional current-buffer)
8226 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8227 (let ((org-overriding-default-time (org-get-cursor-date)))
8230 (if (not (marker-buffer org-agenda-action-marker))
8231 (error "No entry has been selected for agenda action")
8232 (with-current-buffer (marker-buffer org-agenda-action-marker)
8236 (goto-char org-agenda-action-marker)
8239 (defun org-agenda-clock-in (&optional arg)
8240 "Start the clock on the currently selected item."
8242 (org-agenda-check-no-diary)
8243 (if (equal arg '(4))
8245 (let* ((marker (or (org-get-at-bol 'org-marker)
8246 (org-agenda-error)))
8247 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8249 (pos (marker-position marker))
8251 (org-with-remote-undo (marker-buffer marker)
8252 (with-current-buffer (marker-buffer marker)
8255 (org-show-context 'agenda)
8257 (org-cycle-hide-drawers 'children)
8259 (setq newhead (org-get-heading)))
8260 (org-agenda-change-all-lines newhead hdmarker)))))
8262 (defun org-agenda-clock-out ()
8263 "Stop the currently running clock."
8265 (unless (marker-buffer org-clock-marker)
8266 (error "No running clock"))
8267 (let ((marker (make-marker)) newhead)
8268 (org-with-remote-undo (marker-buffer org-clock-marker)
8269 (with-current-buffer (marker-buffer org-clock-marker)
8273 (goto-char org-clock-marker)
8274 (org-back-to-heading t)
8275 (move-marker marker (point))
8277 (setq newhead (org-get-heading))))))
8278 (org-agenda-change-all-lines newhead marker)
8279 (move-marker marker nil)))
8281 (defun org-agenda-clock-cancel (&optional arg)
8282 "Cancel the currently running clock."
8284 (unless (marker-buffer org-clock-marker)
8285 (error "No running clock"))
8286 (org-with-remote-undo (marker-buffer org-clock-marker)
8287 (org-clock-cancel)))
8289 (defun org-agenda-clock-goto ()
8290 "Jump to the currently clocked in task within the agenda.
8291 If the currently clocked in task is not listed in the agenda
8292 buffer, display it in another window."
8296 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8297 (setq pos (overlay-start o))))
8298 (overlays-in (point-min) (point-max)))
8299 (cond (pos (goto-char pos))
8300 ;; If the currently clocked entry is not in the agenda
8301 ;; buffer, we visit it in another window:
8302 (org-clock-current-task
8303 (org-switch-to-buffer-other-window (org-clock-goto)))
8304 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8306 (defun org-agenda-diary-entry-in-org-file ()
8307 "Make a diary entry in the file `org-agenda-diary-file'."
8308 (let (d1 d2 char (text "") dp1 dp2)
8309 (if (equal (buffer-name) "*Calendar*")
8310 (setq d1 (calendar-cursor-to-date t)
8311 d2 (car calendar-mark-ring))
8312 (setq dp1 (get-text-property (point-at-bol) 'day))
8313 (unless dp1 (error "No date defined in current line"))
8314 (setq d1 (calendar-gregorian-from-absolute dp1)
8315 d2 (and (ignore-errors (mark))
8318 (setq dp2 (get-text-property (point-at-bol) 'day)))
8319 (calendar-gregorian-from-absolute dp2))))
8320 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8321 (setq char (read-char-exclusive))
8324 (setq text (read-string "Day entry: "))
8325 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8326 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8328 (setq d1 (list (car d1) (nth 1 d1)
8329 (read-number (format "Reference year [%d]: " (nth 2 d1))
8331 (setq text (read-string "Anniversary (use %d to show years): "))
8332 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8333 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8335 (setq text (read-string "Block entry: "))
8336 (unless (and d1 d2 (not (equal d1 d2)))
8337 (error "No block of days selected"))
8338 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8339 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8341 (org-switch-to-buffer-other-window
8342 (find-file-noselect org-agenda-diary-file))
8343 (require 'org-datetree)
8344 (org-datetree-find-date-create d1)
8346 (t (error "Invalid selection character `%c'" char)))))
8348 (defcustom org-agenda-insert-diary-strategy 'date-tree
8349 "Where in `org-agenda-diary-file' should new entries be added?
8352 date-tree in the date tree, as child of the date
8353 top-level as top-level entries at the end of the file."
8356 (const :tag "in a date tree" date-tree)
8357 (const :tag "as top level at end of file" top-level)))
8359 (defcustom org-agenda-insert-diary-extract-time nil
8360 "Non-nil means extract any time specification from the diary entry."
8365 (defcustom org-agenda-bulk-mark-char ">"
8366 "A single-character string to be used as the bulk mark."
8371 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8372 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8373 If TEXT is not empty, it will become the headline of the new entry, and
8374 the resulting entry will not be shown. When TEXT is empty, switch to
8375 `org-agenda-diary-file' and let the user finish the entry there."
8376 (let ((cw (current-window-configuration)))
8377 (org-switch-to-buffer-other-window
8378 (find-file-noselect org-agenda-diary-file))
8380 (goto-char (point-min))
8382 ((eq type 'anniversary)
8383 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8385 (or (org-at-heading-p t)
8387 (outline-next-heading)
8388 (insert "* Anniversaries\n\n")
8389 (beginning-of-line -1)))))
8390 (outline-next-heading)
8391 (org-back-over-empty-lines)
8394 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8395 (nth 2 d1) (car d1) (nth 1 d1) text)))
8397 (let ((org-prefix-has-time t)
8398 (org-agenda-time-leading-zero t)
8400 (if org-agenda-insert-diary-extract-time
8401 ;; Use org-agenda-format-item to parse text for a time-range and
8402 ;; remove it. FIXME: This is a hack, we should refactor
8403 ;; that function to make time extraction available separately
8404 (setq fmt (org-agenda-format-item nil text nil nil t)
8405 time (get-text-property 0 'time fmt)
8406 time2 (if (> (length time) 0)
8407 ;; split-string removes trailing ...... if
8408 ;; no end time given. First space
8409 ;; separates time from date.
8410 (concat " " (car (split-string time "\\.")))
8412 text (get-text-property 0 'txt fmt)))
8413 (if (eq org-agenda-insert-diary-strategy 'top-level)
8414 (org-agenda-insert-diary-as-top-level text)
8415 (require 'org-datetree)
8416 (org-datetree-find-date-create d1)
8417 (org-agenda-insert-diary-make-new-entry text))
8418 (org-insert-time-stamp (org-time-from-absolute
8419 (calendar-absolute-from-gregorian d1))
8420 nil nil nil nil time2))
8423 (if (> (calendar-absolute-from-gregorian d1)
8424 (calendar-absolute-from-gregorian d2))
8425 (setq d1 (prog1 d2 (setq d2 d1))))
8426 (if (eq org-agenda-insert-diary-strategy 'top-level)
8427 (org-agenda-insert-diary-as-top-level text)
8428 (require 'org-datetree)
8429 (org-datetree-find-date-create d1)
8430 (org-agenda-insert-diary-make-new-entry text))
8431 (org-insert-time-stamp (org-time-from-absolute
8432 (calendar-absolute-from-gregorian d1)))
8434 (org-insert-time-stamp (org-time-from-absolute
8435 (calendar-absolute-from-gregorian d2)))
8437 (if (string-match "\\S-" text)
8439 (set-window-configuration cw)
8440 (message "%s entry added to %s"
8441 (capitalize (symbol-name type))
8442 (abbreviate-file-name org-agenda-diary-file)))
8444 (message "Please finish entry here"))))
8446 (defun org-agenda-insert-diary-as-top-level (text)
8447 "Make new entry as a top-level entry at the end of the file.
8448 Add TEXT as headline, and position the cursor in the second line so that
8449 a timestamp can be added there."
8451 (goto-char (point-max))
8452 (or (bolp) (insert "\n"))
8453 (insert "* " text "\n")
8454 (if org-adapt-indentation (org-indent-to-column 2)))
8456 (defun org-agenda-insert-diary-make-new-entry (text)
8457 "Make new entry as last child of current entry.
8458 Add TEXT as headline, and position the cursor in the second line so that
8459 a timestamp can be added there."
8460 (let ((org-show-following-heading t)
8461 (org-show-siblings t)
8462 (org-show-hierarchy-above t)
8463 (org-show-entry-below t)
8465 (outline-next-heading)
8466 (org-back-over-empty-lines)
8467 (or (looking-at "[ \t]*$")
8468 (progn (insert "\n") (backward-char 1)))
8469 (org-insert-heading nil t)
8471 (setq col (current-column))
8473 (if org-adapt-indentation (org-indent-to-column col))
8474 (let ((org-show-following-heading t)
8475 (org-show-siblings t)
8476 (org-show-hierarchy-above t)
8477 (org-show-entry-below t))
8478 (org-show-context))))
8480 (defun org-agenda-diary-entry ()
8481 "Make a diary entry, like the `i' command from the calendar.
8482 All the standard commands work: block, weekly etc.
8483 When `org-agenda-diary-file' points to a file,
8484 `org-agenda-diary-entry-in-org-file' is called instead to create
8485 entries in that Org-mode file."
8487 (org-agenda-check-type t 'agenda 'timeline)
8488 (if (not (eq org-agenda-diary-file 'diary-file))
8489 (org-agenda-diary-entry-in-org-file)
8490 (require 'diary-lib)
8492 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8493 (read-char-exclusive)))
8494 (cmd (cdr (assoc char
8495 '((?d . insert-diary-entry)
8496 (?w . insert-weekly-diary-entry)
8497 (?m . insert-monthly-diary-entry)
8498 (?y . insert-yearly-diary-entry)
8499 (?a . insert-anniversary-diary-entry)
8500 (?b . insert-block-diary-entry)
8501 (?c . insert-cyclic-diary-entry)))))
8502 (oldf (symbol-function 'calendar-cursor-to-date))
8503 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8505 (mark (or (mark t) (point))))
8507 (error "No command associated with <%c>" char))
8508 (unless (and (get-text-property point 'day)
8509 (or (not (equal ?b char))
8510 (get-text-property mark 'day)))
8511 (error "Don't know which date to use for diary entry"))
8512 ;; We implement this by hacking the `calendar-cursor-to-date' function
8513 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8514 (let ((calendar-mark-ring
8515 (list (calendar-gregorian-from-absolute
8516 (or (get-text-property mark 'day)
8517 (get-text-property point 'day))))))
8520 (fset 'calendar-cursor-to-date
8521 (lambda (&optional error dummy)
8522 (calendar-gregorian-from-absolute
8523 (get-text-property point 'day))))
8524 (call-interactively cmd))
8525 (fset 'calendar-cursor-to-date oldf))))))
8527 (defun org-agenda-execute-calendar-command (cmd)
8528 "Execute a calendar command from the agenda, with the date associated to
8529 the cursor position."
8530 (org-agenda-check-type t 'agenda 'timeline)
8531 (require 'diary-lib)
8532 (unless (get-text-property (point) 'day)
8533 (error "Don't know which date to use for calendar command"))
8534 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8536 (date (calendar-gregorian-from-absolute
8537 (get-text-property point 'day)))
8538 ;; the following 2 vars are needed in the calendar
8539 (displayed-month (car date))
8540 (displayed-year (nth 2 date)))
8543 (fset 'calendar-cursor-to-date
8544 (lambda (&optional error dummy)
8545 (calendar-gregorian-from-absolute
8546 (get-text-property point 'day))))
8547 (call-interactively cmd))
8548 (fset 'calendar-cursor-to-date oldf))))
8550 (defun org-agenda-phases-of-moon ()
8551 "Display the phases of the moon for the 3 months around the cursor date."
8553 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8555 (defun org-agenda-holidays ()
8556 "Display the holidays for the 3 months around the cursor date."
8558 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8560 (defvar calendar-longitude)
8561 (defvar calendar-latitude)
8562 (defvar calendar-location-name)
8564 (defun org-agenda-sunrise-sunset (arg)
8565 "Display sunrise and sunset for the cursor date.
8566 Latitude and longitude can be specified with the variables
8567 `calendar-latitude' and `calendar-longitude'. When called with prefix
8568 argument, latitude and longitude will be prompted for."
8571 (let ((calendar-longitude (if arg nil calendar-longitude))
8572 (calendar-latitude (if arg nil calendar-latitude))
8573 (calendar-location-name
8574 (if arg "the given coordinates" calendar-location-name)))
8575 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8577 (defun org-agenda-goto-calendar ()
8578 "Open the Emacs calendar with the date at the cursor."
8580 (org-agenda-check-type t 'agenda 'timeline)
8581 (let* ((day (or (get-text-property (point) 'day)
8582 (error "Don't know which date to open in calendar")))
8583 (date (calendar-gregorian-from-absolute day))
8584 (calendar-move-hook nil)
8585 (calendar-view-holidays-initially-flag nil)
8586 (calendar-view-diary-initially-flag nil))
8588 (calendar-goto-date date)))
8591 (defun org-calendar-goto-agenda ()
8592 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8593 This is a command that has to be installed in `calendar-mode-map'."
8595 (org-agenda-list nil (calendar-absolute-from-gregorian
8596 (calendar-cursor-to-date))
8599 (defun org-agenda-convert-date ()
8601 (org-agenda-check-type t 'agenda 'timeline)
8602 (let ((day (get-text-property (point) 'day))
8605 (error "Don't know which date to convert"))
8606 (setq date (calendar-gregorian-from-absolute day))
8608 "Gregorian: " (calendar-date-string date) "\n"
8609 "ISO: " (calendar-iso-date-string date) "\n"
8610 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8611 "Julian: " (calendar-julian-date-string date) "\n"
8612 "Astron. JD: " (calendar-astro-date-string date)
8613 " (Julian date number at noon UTC)\n"
8614 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8615 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8616 "French: " (calendar-french-date-string date) "\n"
8617 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8618 "Mayan: " (calendar-mayan-date-string date) "\n"
8619 "Coptic: " (calendar-coptic-date-string date) "\n"
8620 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8621 "Persian: " (calendar-persian-date-string date) "\n"
8622 "Chinese: " (calendar-chinese-date-string date) "\n"))
8623 (with-output-to-temp-buffer "*Dates*"
8625 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8629 (defvar org-agenda-bulk-marked-entries nil
8630 "List of markers that refer to marked entries in the agenda.")
8632 (defun org-agenda-bulk-marked-p ()
8633 (eq (get-char-property (point-at-bol) 'type)
8634 'org-marked-entry-overlay))
8636 (defun org-agenda-bulk-mark (&optional arg)
8637 "Mark the entry at point for future bulk action."
8639 (dotimes (i (or arg 1))
8640 (unless (org-get-at-bol 'org-agenda-diary-link)
8641 (let* ((m (org-get-at-bol 'org-hd-marker))
8643 (unless (org-agenda-bulk-marked-p)
8644 (unless m (error "Nothing to mark at point"))
8645 (push m org-agenda-bulk-marked-entries)
8646 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8647 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8648 (org-get-todo-face "TODO")
8650 (overlay-put ov 'type 'org-marked-entry-overlay))
8651 (beginning-of-line 2)
8652 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8653 (beginning-of-line 2))
8654 (message "%d entries marked for bulk action"
8655 (length org-agenda-bulk-marked-entries))))))
8657 (defun org-agenda-bulk-mark-all ()
8658 "Mark all entries for future agenda bulk action."
8660 (org-agenda-bulk-mark-regexp "."))
8662 (defun org-agenda-bulk-mark-regexp (regexp)
8663 "Mark entries matching REGEXP for future agenda bulk action."
8664 (interactive "sMark entries matching regexp: ")
8665 (let ((entries-marked 0))
8667 (goto-char (point-min))
8668 (goto-char (next-single-property-change (point) 'txt))
8669 (while (re-search-forward regexp nil t)
8670 (when (string-match regexp (get-text-property (point) 'txt))
8671 (setq entries-marked (1+ entries-marked))
8672 (call-interactively 'org-agenda-bulk-mark))))
8673 (if (not entries-marked)
8674 (message "No entry matching this regexp."))))
8676 (defun org-agenda-bulk-unmark (&optional arg)
8677 "Unmark the entry at point for future bulk action."
8680 (org-agenda-bulk-unmark-all)
8681 (cond ((org-agenda-bulk-marked-p)
8682 (org-agenda-bulk-remove-overlays
8683 (point-at-bol) (+ 2 (point-at-bol)))
8684 (setq org-agenda-bulk-marked-entries
8685 (delete (org-get-at-bol 'org-hd-marker)
8686 org-agenda-bulk-marked-entries))
8687 (beginning-of-line 2)
8688 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8689 (beginning-of-line 2))
8690 (message "%d entries left marked for bulk action"
8691 (length org-agenda-bulk-marked-entries)))
8692 (t (message "No entry to unmark here")))))
8694 (defun org-agenda-bulk-toggle ()
8695 "Toggle marking the entry at point for bulk action."
8697 (if (org-agenda-bulk-marked-p)
8698 (org-agenda-bulk-unmark)
8699 (org-agenda-bulk-mark)))
8701 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8702 "Remove the mark overlays between BEG and END in the agenda buffer.
8703 BEG and END default to the buffer limits.
8705 This only removes the overlays, it does not remove the markers
8706 from the list in `org-agenda-bulk-marked-entries'."
8709 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8710 (delete-overlay ov)))
8711 (overlays-in (or beg (point-min)) (or end (point-max)))))
8713 (defun org-agenda-bulk-unmark-all ()
8714 "Remove all marks in the agenda buffer.
8715 This will remove the markers and the overlays."
8717 (if (null org-agenda-bulk-marked-entries)
8718 (message "No entry to unmark")
8719 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8720 (setq org-agenda-bulk-marked-entries nil)
8721 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8723 (defcustom org-agenda-persistent-marks nil
8724 "Non-nil means marked items will stay marked after a bulk action.
8725 You can interactively and temporarily toggle by typing `p' when you
8726 are prompted for a bulk action."
8731 (defun org-agenda-bulk-action (&optional arg)
8732 "Execute an remote-editing action on all marked entries.
8733 The prefix arg is passed through to the command if possible."
8735 ;; Make sure we have markers, and only valid ones
8736 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8739 (unless (and (markerp m)
8741 (buffer-live-p (marker-buffer m))
8742 (marker-position m))
8743 (error "Marker %s for bulk command is invalid" m)))
8744 org-agenda-bulk-marked-entries)
8746 ;; Prompt for the bulk command
8747 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8748 (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
8749 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
8750 (when org-agenda-bulk-custom-functions
8751 (concat " Custom: ["
8752 (mapconcat (lambda(f) (char-to-string (car f)))
8753 org-agenda-bulk-custom-functions "")
8756 (let* ((action (read-char-exclusive))
8757 (org-log-refile (if org-log-refile 'time nil))
8758 (entries (reverse org-agenda-bulk-marked-entries))
8760 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8763 (let ((org-agenda-persistent-marks
8764 (not org-agenda-persistent-marks)))
8765 (org-agenda-bulk-action)
8769 (setq cmd '(org-agenda-archive)))
8772 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8774 ((member action '(?r ?w))
8775 (setq rfloc (org-refile-get-location
8777 (marker-buffer (car org-agenda-bulk-marked-entries))
8778 org-refile-allow-creating-parent-nodes))
8780 (setcar (nthcdr 3 rfloc)
8781 (move-marker (make-marker) (nth 3 rfloc)
8782 (or (get-file-buffer (nth 1 rfloc))
8783 (find-buffer-visiting (nth 1 rfloc))
8784 (error "This should not happen")))))
8786 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8790 (setq state (org-icompleting-read
8792 (with-current-buffer (marker-buffer (car entries))
8793 (mapcar 'list org-todo-keywords-1))))
8794 (setq cmd `(let ((org-inhibit-blocking t)
8795 (org-inhibit-logging 'note))
8796 (org-agenda-todo ,state))))
8798 ((memq action '(?- ?+))
8799 (setq tag (org-icompleting-read
8800 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8801 (with-current-buffer (marker-buffer (car entries))
8804 (if (stringp (car x)) x)) org-tag-alist)))))
8805 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8807 ((memq action '(?s ?d))
8808 (let* ((date (unless arg
8811 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8812 (ans (if arg nil org-read-date-final-answer))
8813 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8814 (setq cmd `(let* ((bound (fboundp 'read-string))
8815 (old (and bound (symbol-function 'read-string))))
8818 (fset 'read-string (lambda (&rest ignore) ,ans))
8821 (fset 'read-string old)
8822 (fmakunbound 'read-string)))))))
8825 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8826 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8827 (let ((days (read-number
8828 (format "Scatter tasks across how many %sdays: "
8829 (if arg "week" "")) 7)))
8831 `(let ((distance (1+ (random ,days))))
8833 (let ((dist distance)
8835 (calendar-day-of-week
8836 (calendar-gregorian-from-absolute (org-today)))))
8837 (dotimes (i (1+ dist))
8838 (while (member day-of-week org-agenda-weekend-days)
8841 (if (= day-of-week 7)
8842 (setq day-of-week 0)))
8844 (if (= day-of-week 7)
8845 (setq day-of-week 0)))))
8846 ;; silently fail when try to replan a sexp entry
8848 (let* ((date (calendar-gregorian-from-absolute
8849 (+ (org-today) distance)))
8850 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8852 (org-agenda-schedule nil time))
8855 ((assoc action org-agenda-bulk-custom-functions)
8856 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8860 (setq cmd (list (intern
8861 (org-icompleting-read "Function: "
8862 obarray 'fboundp t nil nil)))))
8864 (t (error "Invalid bulk action")))
8866 ;; Sort the markers, to make sure that parents are handled before children
8867 (setq entries (sort entries
8870 ((equal (marker-buffer a) (marker-buffer b))
8871 (< (marker-position a) (marker-position b)))
8873 (string< (buffer-name (marker-buffer a))
8874 (buffer-name (marker-buffer b))))))))
8876 ;; Now loop over all markers and apply cmd
8877 (while (setq e (pop entries))
8878 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8880 (progn (message "Skipping removed entry at %s" e)
8881 (setq cntskip (1+ cntskip)))
8883 (let (org-loop-over-headlines-in-active-region)
8885 (when (not org-agenda-persistent-marks)
8886 (setq org-agenda-bulk-marked-entries
8887 (delete e org-agenda-bulk-marked-entries)))
8888 (setq cnt (1+ cnt))))
8889 (when (not org-agenda-persistent-marks)
8890 (org-agenda-bulk-unmark-all))
8891 (when redo-at-end (org-agenda-redo))
8892 (message "Acted on %d entries%s%s"
8896 (format ", skipped %d (disappeared before their turn)"
8898 (if (not org-agenda-persistent-marks)
8899 "" " (kept marked)"))))))
8903 (defun org-agenda-show-the-flagging-note ()
8904 "Display the flagging note in the other window.
8905 When called a second time in direct sequence, offer to remove the FLAGGING
8906 tag and (if present) the flagging note."
8908 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8909 (win (selected-window))
8910 note heading newhead)
8912 (error "No linked entry at point"))
8913 (if (and (eq this-command last-command)
8914 (y-or-n-p "Unflag and remove any flagging note? "))
8916 (org-agenda-remove-flag hdmarker)
8917 (let ((win (get-buffer-window "*Flagging Note*")))
8918 (and win (delete-window win)))
8919 (message "Entry unflagged"))
8920 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8922 (error "No flagging note"))
8924 (org-switch-to-buffer-other-window "*Flagging Note*")
8927 (goto-char (point-min))
8928 (while (re-search-forward "\\\\n" nil t)
8929 (replace-match "\n" t t))
8930 (goto-char (point-min))
8932 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8934 (defun org-agenda-remove-flag (marker)
8935 "Remove the FLAGGED tag and any flagging note in the entry."
8937 (org-with-point-at marker
8938 (org-toggle-tag "FLAGGED" 'off)
8939 (org-entry-delete nil "THEFLAGGINGNOTE")
8940 (setq newhead (org-get-heading)))
8941 (org-agenda-change-all-lines newhead marker)
8942 (message "Entry unflagged")))
8944 (defun org-agenda-get-any-marker (&optional pos)
8945 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8946 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8948 ;;; Appointment reminders
8950 (defvar appt-time-msg-list)
8953 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8954 "Activate appointments found in `org-agenda-files'.
8955 With a \\[universal-argument] prefix, refresh the list of
8958 If FILTER is t, interactively prompt the user for a regular
8959 expression, and filter out entries that don't match it.
8961 If FILTER is a string, use this string as a regular expression
8962 for filtering entries out.
8964 If FILTER is a function, filter out entries against which
8965 calling the function returns nil. This function takes one
8966 argument: an entry from `org-agenda-get-day-entries'.
8968 FILTER can also be an alist with the car of each cell being
8969 either 'headline or 'category. For example:
8971 '((headline \"IMPORTANT\")
8972 (category \"Work\"))
8974 will only add headlines containing IMPORTANT or headlines
8975 belonging to the \"Work\" category.
8977 ARGS are symbols indicating what kind of entries to consider.
8978 By default `org-agenda-to-appt' will use :deadline, :scheduled
8979 and :timestamp entries. See the docstring of `org-diary' for
8980 details and examples.
8982 If an entry as a APPT_WARNTIME property, its value will be used
8983 to override `appt-message-warning-time'."
8985 (if refresh (setq appt-time-msg-list nil))
8987 (setq filter (read-from-minibuffer "Regexp filter: ")))
8988 (let* ((cnt 0) ; count added events
8989 (scope (or args '(:deadline :scheduled :timestamp)))
8990 (org-agenda-new-buffers nil)
8991 (org-deadline-warning-days 0)
8992 ;; Do not use `org-today' here because appt only takes
8993 ;; time and without date as argument, so it may pass wrong
8994 ;; information otherwise
8995 (today (org-date-to-gregorian
8996 (time-to-days (current-time))))
8997 (org-agenda-restrict nil)
8998 (files (org-agenda-files 'unrestricted)) entries file
8999 (org-agenda-buffer nil))
9000 ;; Get all entries which may contain an appt
9001 (org-prepare-agenda-buffers files)
9002 (while (setq file (pop files))
9006 (apply 'org-agenda-get-day-entries
9007 file today scope)))))
9008 ;; Map thru entries and find if we should filter them out
9011 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9012 (cat (get-text-property 1 'org-category x))
9013 (tod (get-text-property 1 'time-of-day x))
9014 (ok (or (null filter)
9015 (and (stringp filter) (string-match filter evt))
9016 (and (functionp filter) (funcall filter x))
9018 (let ((cat-filter (cadr (assoc 'category filter)))
9019 (evt-filter (cadr (assoc 'headline filter))))
9020 (or (and (stringp cat-filter)
9021 (string-match cat-filter cat))
9022 (and (stringp evt-filter)
9023 (string-match evt-filter evt)))))))
9024 (wrn (org-entry-get (point) "APPT_WARNTIME")))
9025 ;; FIXME: Shall we remove text-properties for the appt text?
9026 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9028 (setq tod (concat "00" (number-to-string tod))
9029 tod (when (string-match
9030 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9031 (concat (match-string 1 tod) ":"
9032 (match-string 2 tod))))
9033 (if (version< emacs-version "23.3")
9035 (appt-add tod evt wrn))
9036 (setq cnt (1+ cnt))))) entries)
9037 (org-release-buffers org-agenda-new-buffers)
9039 (message "No event to add")
9040 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9042 (defun org-agenda-todayp (date)
9043 "Does DATE mean today, when considering `org-extend-today-until'?"
9044 (let ((today (org-today))
9045 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9049 (defun org-agenda-todo-yesterday (&optional arg)
9050 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9052 (let* ((hour (third (decode-time
9053 (org-current-time))))
9054 (org-extend-today-until (1+ hour)))
9055 (org-agenda-todo arg)))
9057 (provide 'org-agenda)
9059 ;;; org-agenda.el ends here