1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 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.
53 (declare-function diary-add-to-list
"diary-lib"
54 (date string specifier
&optional marker globcolor literal
))
55 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
56 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
57 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
58 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
59 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
60 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
61 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
62 (declare-function calendar-goto-date
"cal-move" (date))
63 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
64 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
65 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
66 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
67 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
68 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
69 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
70 (declare-function calendar-check-holidays
"holidays" (date))
72 (declare-function org-datetree-find-date-create
"org-datetree"
73 (date &optional keep-restriction
))
74 (declare-function org-columns-quit
"org-colview" ())
75 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
76 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line
))
79 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
80 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
81 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
82 (declare-function org-pop-to-buffer-same-window
"org-compat"
83 (&optional buffer-or-name norecord label
))
84 (declare-function org-agenda-columns
"org-colview" ())
85 (declare-function org-add-archive-files
"org-archive" (files))
86 (declare-function org-capture
"org-capture" (&optional goto keys
))
88 (defvar calendar-mode-map
) ; defined in calendar.el
89 (defvar org-clock-current-task nil
) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
91 (defvar org-habit-show-habits
) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today
)
93 (defvar org-habit-show-all-today
)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name
"*Org Agenda*")
97 (defvar org-agenda-overriding-header nil
)
98 (defvar org-agenda-title-append nil
)
99 (org-no-warnings (defvar entry
)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date
)) ;; unprefixed, from calendar.el
101 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill
1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
114 (const :tag
"Never" nil
)
115 (const :tag
"Always" t
)
116 (integer :tag
"When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
125 (defcustom org-agenda-block-separator ?
=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
133 (const :tag
"Disabled" nil
)
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag
"Org Agenda Export"
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group
'org-agenda-export
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group
'org-agenda-export
160 (sexp :tag
"Value"))))
162 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group
'org-agenda-export
167 :options
'(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines
0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group
'org-agenda-export
229 :group
'org-export-html
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag
"Org Agenda Custom Commands"
242 (defconst org-sorting-choice
244 (const time-up
) (const time-down
)
245 (const timestamp-up
) (const timestamp-down
)
246 (const scheduled-up
) (const scheduled-down
)
247 (const deadline-up
) (const deadline-down
)
248 (const ts-up
) (const ts-down
)
249 (const tsia-up
) (const tsia-down
)
250 (const category-keep
) (const category-up
) (const category-down
)
251 (const tag-down
) (const tag-up
)
252 (const priority-up
) (const priority-down
)
253 (const todo-state-up
) (const todo-state-down
)
254 (const effort-up
) (const effort-down
)
255 (const habit-up
) (const habit-down
)
256 (const alpha-up
) (const alpha-down
)
257 (const user-defined-up
) (const user-defined-down
))
260 ;; Keep custom values for `org-agenda-filter-preset' compatible with
261 ;; the new variable `org-agenda-tag-filter-preset'.
262 (org-defvaralias 'org-agenda-filter-preset
'org-agenda-tag-filter-preset
)
263 (org-defvaralias 'org-agenda-filter
'org-agenda-tag-filter
)
265 (defvar org-agenda-entry-types
'(:deadline
:scheduled
:timestamp
:sexp
)
266 "List of types searched for when creating the daily/weekly agenda.
267 This variable is a list of symbols that controls the types of
268 items that appear in the daily/weekly agenda. Allowed symbols in this
271 :timestamp List items containing a date stamp or date range matching
272 the selected date. This includes sexp entries in angular
275 :sexp List entries resulting from plain diary-like sexps.
277 :deadline List deadline due on that date. When the date is today,
278 also list any deadlines past due, or due within
279 `org-deadline-warning-days'. `:deadline' must appear before
280 `:scheduled' if the setting of
281 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
284 :deadline* Same as above, but only include the deadline if it has an
285 hour specification as [h]h:mm.
287 :scheduled List all items which are scheduled for the given date.
288 The diary for *today* also contains items which were
289 scheduled earlier and are not yet marked DONE.
291 :scheduled* Same as above, but only include the scheduled item if it
292 has an hour specification as [h]h:mm.
294 By default, all four non-starred types are turned on.
296 When :scheduled* or :deadline* are included, :schedule or :deadline
299 Never set this variable globally using `setq', because then it
300 will apply to all future agenda commands. Instead, bind it with
301 `let' to scope it dynamically into the agenda-constructing
302 command. A good way to set it is through options in
303 `org-agenda-custom-commands'. For a more flexible (though
304 somewhat less efficient) way of determining what is included in
305 the daily/weekly agenda, see `org-agenda-skip-function'.")
307 (defconst org-agenda-custom-commands-local-options
308 `(repeat :tag
"Local settings for this command. Remember to quote values"
309 (choice :tag
"Setting"
310 (list :tag
"Heading for this block"
311 (const org-agenda-overriding-header
)
312 (string :tag
"Headline"))
313 (list :tag
"Files to be searched"
314 (const org-agenda-files
)
316 (const :format
"" quote
)
318 (list :tag
"Sorting strategy"
319 (const org-agenda-sorting-strategy
)
321 (const :format
"" quote
)
323 ,org-sorting-choice
)))
324 (list :tag
"Prefix format"
325 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
327 (list :tag
"Number of days in agenda"
328 (const org-agenda-span
)
329 (choice (const :tag
"Day" 'day
)
330 (const :tag
"Week" 'week
)
331 (const :tag
"Month" 'month
)
332 (const :tag
"Year" 'year
)
333 (integer :tag
"Custom")))
334 (list :tag
"Fixed starting date"
335 (const org-agenda-start-day
)
336 (string :value
"2007-11-01"))
337 (list :tag
"Start on day of week"
338 (const org-agenda-start-on-weekday
)
340 (const :tag
"Today" nil
)
341 (integer :tag
"Weekday No.")))
342 (list :tag
"Include data from diary"
343 (const org-agenda-include-diary
)
345 (list :tag
"Deadline Warning days"
346 (const org-deadline-warning-days
)
348 (list :tag
"Category filter preset"
349 (const org-agenda-category-filter-preset
)
351 (const :format
"" quote
)
353 (string :tag
"+category or -category"))))
354 (list :tag
"Tags filter preset"
355 (const org-agenda-tag-filter-preset
)
357 (const :format
"" quote
)
359 (string :tag
"+tag or -tag"))))
360 (list :tag
"Regexp filter preset"
361 (const org-agenda-regexp-filter-preset
)
363 (const :format
"" quote
)
365 (string :tag
"+regexp or -regexp"))))
366 (list :tag
"Set daily/weekly entry types"
367 (const org-agenda-entry-types
)
369 (const :format
"" quote
)
370 (set :greedy t
:value
,org-agenda-entry-types
377 (list :tag
"Standard skipping condition"
378 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
379 (const org-agenda-skip-function
)
381 (const :format
"" quote
)
384 :tag
"Skipping range"
385 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
386 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
387 (repeat :inline t
:tag
"Conditions for skipping"
389 :tag
"Condition type"
390 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
391 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
392 (list :tag
"TODO state is" :inline t
395 (const :tag
"any not-done state" 'todo
)
396 (const :tag
"any done state" 'done
)
397 (const :tag
"any state" 'any
)
398 (list :tag
"Keyword list"
399 (const :format
"" quote
)
400 (repeat (string :tag
"Keyword")))))
401 (list :tag
"TODO state is not" :inline t
404 (const :tag
"any not-done state" 'todo
)
405 (const :tag
"any done state" 'done
)
406 (const :tag
"any state" 'any
)
407 (list :tag
"Keyword list"
408 (const :format
"" quote
)
409 (repeat (string :tag
"Keyword")))))
410 (const :tag
"scheduled" 'scheduled
)
411 (const :tag
"not scheduled" 'notscheduled
)
412 (const :tag
"deadline" 'deadline
)
413 (const :tag
"no deadline" 'notdeadline
)
414 (const :tag
"timestamp" 'timestamp
)
415 (const :tag
"no timestamp" 'nottimestamp
))))))
416 (list :tag
"Non-standard skipping condition"
417 :value
(org-agenda-skip-function)
418 (const org-agenda-skip-function
)
419 (sexp :tag
"Function or form (quoted!)"))
420 (list :tag
"Any variable"
421 (variable :tag
"Variable")
422 (sexp :tag
"Value (sexp)"))))
423 "Selection of examples for agenda command settings.
424 This will be spliced into the custom type of
425 `org-agenda-custom-commands'.")
428 (defcustom org-agenda-custom-commands
429 '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
430 "Custom commands for the agenda.
431 These commands will be offered on the splash screen displayed by the
432 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
434 (key desc type match settings files)
436 key The key (one or more characters as a string) to be associated
438 desc A description of the command, when omitted or nil, a default
439 description is built using MATCH.
440 type The command type, any of the following symbols:
441 agenda The daily/weekly agenda.
442 todo Entries with a specific TODO keyword, in all agenda files.
443 search Entries containing search words entry or headline.
444 tags Tags/Property/TODO match in all agenda files.
445 tags-todo Tags/P/T match in all agenda files, TODO entries only.
446 todo-tree Sparse tree of specific TODO keyword in *current* file.
447 tags-tree Sparse tree with all tags matches in *current* file.
448 occur-tree Occur sparse tree for *current* file.
449 ... A user-defined function.
450 match What to search for:
451 - a single keyword for TODO keyword searches
452 - a tags match expression for tags searches
453 - a word search expression for text searches.
454 - a regular expression for occur searches
455 For all other commands, this should be the empty string.
456 settings A list of option settings, similar to that in a let form, so like
457 this: ((opt1 val1) (opt2 val2) ...). The values will be
458 evaluated at the moment of execution, so quote them when needed.
459 files A list of files file to write the produced agenda buffer to
460 with the command `org-store-agenda-views'.
461 If a file name ends in \".html\", an HTML version of the buffer
462 is written out. If it ends in \".ps\", a postscript version is
463 produced. Otherwise, only the plain text is written to the file.
465 You can also define a set of commands, to create a composite agenda buffer.
466 In this case, an entry looks like this:
468 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
472 desc A description string to be displayed in the dispatcher menu.
473 cmd An agenda command, similar to the above. However, tree commands
474 are not allowed, but instead you can get agenda and global todo list.
475 So valid commands for a set are:
476 (agenda \"\" settings)
477 (alltodo \"\" settings)
478 (stuck \"\" settings)
479 (todo \"match\" settings files)
480 (search \"match\" settings files)
481 (tags \"match\" settings files)
482 (tags-todo \"match\" settings files)
484 Each command can carry a list of options, and another set of options can be
485 given for the whole set of commands. Individual command options take
486 precedence over the general options.
488 When using several characters as key to a command, the first characters
489 are prefix commands. For the dispatcher to display useful information, you
490 should provide a description for the prefix, like
492 (setq org-agenda-custom-commands
493 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
494 (\"hl\" tags \"+HOME+Lisa\")
495 (\"hp\" tags \"+HOME+Peter\")
496 (\"hk\" tags \"+HOME+Kim\")))"
497 :group
'org-agenda-custom-commands
499 (choice :value
("x" "Describe command here" tags
"" nil
)
500 (list :tag
"Single command"
501 (string :tag
"Access Key(s) ")
502 (option (string :tag
"Description"))
504 (const :tag
"Agenda" agenda
)
505 (const :tag
"TODO list" alltodo
)
506 (const :tag
"Search words" search
)
507 (const :tag
"Stuck projects" stuck
)
508 (const :tag
"Tags/Property match (all agenda files)" tags
)
509 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
510 (const :tag
"TODO keyword search (all agenda files)" todo
)
511 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
512 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
513 (const :tag
"Occur tree (current buffer)" occur-tree
)
514 (sexp :tag
"Other, user-defined function"))
515 (string :tag
"Match (only for some commands)")
516 ,org-agenda-custom-commands-local-options
517 (option (repeat :tag
"Export" (file :tag
"Export to"))))
518 (list :tag
"Command series, all agenda files"
519 (string :tag
"Access Key(s)")
520 (string :tag
"Description ")
521 (repeat :tag
"Component"
524 (const :format
"" agenda
)
525 (const :tag
"" :format
"" "")
526 ,org-agenda-custom-commands-local-options
)
527 (list :tag
"TODO list (all keywords)"
528 (const :format
"" alltodo
)
529 (const :tag
"" :format
"" "")
530 ,org-agenda-custom-commands-local-options
)
531 (list :tag
"Search words"
532 (const :format
"" search
)
533 (string :tag
"Match")
534 ,org-agenda-custom-commands-local-options
)
535 (list :tag
"Stuck projects"
536 (const :format
"" stuck
)
537 (const :tag
"" :format
"" "")
538 ,org-agenda-custom-commands-local-options
)
539 (list :tag
"Tags search"
540 (const :format
"" tags
)
541 (string :tag
"Match")
542 ,org-agenda-custom-commands-local-options
)
543 (list :tag
"Tags search, TODO entries only"
544 (const :format
"" tags-todo
)
545 (string :tag
"Match")
546 ,org-agenda-custom-commands-local-options
)
547 (list :tag
"TODO keyword search"
548 (const :format
"" todo
)
549 (string :tag
"Match")
550 ,org-agenda-custom-commands-local-options
)
551 (list :tag
"Other, user-defined function"
552 (symbol :tag
"function")
553 (string :tag
"Match")
554 ,org-agenda-custom-commands-local-options
)))
556 (repeat :tag
"Settings for entire command set"
557 (list (variable :tag
"Any variable")
558 (sexp :tag
"Value")))
559 (option (repeat :tag
"Export" (file :tag
"Export to"))))
560 (cons :tag
"Prefix key documentation"
561 (string :tag
"Access Key(s)")
562 (string :tag
"Description ")))))
564 (defcustom org-agenda-query-register ?o
565 "The register holding the current query string.
566 The purpose of this is that if you construct a query string interactively,
567 you can then use it to define a custom command."
568 :group
'org-agenda-custom-commands
571 (defcustom org-stuck-projects
572 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
573 "How to identify stuck projects.
574 This is a list of four items:
575 1. A tags/todo/property matcher string that is used to identify a project.
576 See the manual for a description of tag and property searches.
577 The entire tree below a headline matched by this is considered one project.
578 2. A list of TODO keywords identifying non-stuck projects.
579 If the project subtree contains any headline with one of these todo
580 keywords, the project is considered to be not stuck. If you specify
581 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
582 3. A list of tags identifying non-stuck projects.
583 If the project subtree contains any headline with one of these tags,
584 the project is considered to be not stuck. If you specify \"*\" as
585 a tag, any tag will mark the project unstuck. Note that this is about
586 the explicit presence of a tag somewhere in the subtree, inherited
587 tags do not count here. If inherited tags make a project not stuck,
588 use \"-TAG\" in the tags part of the matcher under (1.) above.
589 4. An arbitrary regular expression matching non-stuck projects.
591 If the project turns out to be not stuck, search continues also in the
592 subtree to see if any of the subtasks have project status.
594 See also the variable `org-tags-match-list-sublevels' which applies
595 to projects matched by this search as well.
597 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
598 or `C-c a #' to produce the list."
599 :group
'org-agenda-custom-commands
601 (string :tag
"Tags/TODO match to identify a project")
602 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
603 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
604 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
606 (defcustom org-agenda-filter-effort-default-operator
"<"
607 "The default operator for effort estimate filtering.
608 If you select an effort estimate limit without first pressing an operator,
609 this one will be used."
610 :group
'org-agenda-custom-commands
611 :type
'(choice (const :tag
"less or equal" "<")
612 (const :tag
"greater or equal"">")
613 (const :tag
"equal" "=")))
615 (defgroup org-agenda-skip nil
616 "Options concerning skipping parts of agenda files."
617 :tag
"Org Agenda Skip"
620 (defcustom org-agenda-skip-function-global nil
621 "Function to be called at each match during agenda construction.
622 If this function returns nil, the current match should not be skipped.
623 If the function decided to skip an agenda match, is must return the
624 buffer position from which the search should be continued.
625 This may also be a Lisp form, which will be evaluated.
627 This variable will be applied to every agenda match, including
628 tags/property searches and TODO lists. So try to make the test function
629 do its checking as efficiently as possible. To implement a skipping
630 condition just for specific agenda commands, use the variable
631 `org-agenda-skip-function' which can be set in the options section
632 of custom agenda commands."
633 :group
'org-agenda-skip
636 (defgroup org-agenda-daily
/weekly nil
637 "Options concerning the daily/weekly agenda."
638 :tag
"Org Agenda Daily/Weekly"
640 (defgroup org-agenda-todo-list nil
641 "Options concerning the global todo list agenda view."
642 :tag
"Org Agenda Todo List"
644 (defgroup org-agenda-match-view nil
645 "Options concerning the general tags/property/todo match agenda view."
646 :tag
"Org Agenda Match View"
648 (defgroup org-agenda-search-view nil
649 "Options concerning the general tags/property/todo match agenda view."
650 :tag
"Org Agenda Match View"
653 (defvar org-agenda-archives-mode nil
654 "Non-nil means the agenda will include archived items.
655 If this is the symbol `trees', trees in the selected agenda scope
656 that are marked with the ARCHIVE tag will be included anyway. When this is
657 t, also all archive files associated with the current selection of agenda
658 files will be included.")
660 (defcustom org-agenda-restriction-lock-highlight-subtree t
661 "Non-nil means highlight the whole subtree when restriction is active.
662 Otherwise only highlight the headline. Highlighting the whole subtree is
663 useful to ensure no edits happen beyond the restricted region."
667 (defcustom org-agenda-skip-comment-trees t
668 "Non-nil means skip trees that start with the COMMENT keyword.
669 When nil, these trees are also scanned by agenda commands."
670 :group
'org-agenda-skip
673 (defcustom org-agenda-todo-list-sublevels t
674 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
675 When nil, the sublevels of a TODO entry are not checked, resulting in
676 potentially much shorter TODO lists."
677 :group
'org-agenda-skip
678 :group
'org-agenda-todo-list
681 (defcustom org-agenda-todo-ignore-with-date nil
682 "Non-nil means don't show entries with a date in the global todo list.
683 You can use this if you prefer to mark mere appointments with a TODO keyword,
684 but don't want them to show up in the TODO list.
685 When this is set, it also covers deadlines and scheduled items, the settings
686 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
688 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
689 :group
'org-agenda-skip
690 :group
'org-agenda-todo-list
693 (defcustom org-agenda-todo-ignore-timestamp nil
694 "Non-nil means don't show entries with a timestamp.
695 This applies when creating the global todo list.
698 past Don't show entries for today or in the past.
700 future Don't show entries with a timestamp in the future.
701 The idea behind this is that if it has a future
702 timestamp, you don't want to think about it until the
705 all Don't show any entries with a timestamp in the global todo list.
706 The idea behind this is that by setting a timestamp, you
707 have already \"taken care\" of this item.
709 This variable can also have an integer as a value. If positive (N),
710 todos with a timestamp N or more days in the future will be ignored. If
711 negative (-N), todos with a timestamp N or more days in the past will be
712 ignored. If 0, todos with a timestamp either today or in the future will
713 be ignored. For example, a value of -1 will exclude todos with a
714 timestamp in the past (yesterday or earlier), while a value of 7 will
715 exclude todos with a timestamp a week or more in the future.
717 See also `org-agenda-todo-ignore-with-date'.
718 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
719 to make his option also apply to the tags-todo list."
720 :group
'org-agenda-skip
721 :group
'org-agenda-todo-list
724 (const :tag
"Ignore future timestamp todos" future
)
725 (const :tag
"Ignore past or present timestamp todos" past
)
726 (const :tag
"Ignore all timestamp todos" all
)
727 (const :tag
"Show timestamp todos" nil
)
728 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
730 (defcustom org-agenda-todo-ignore-scheduled nil
731 "Non-nil means, ignore some scheduled TODO items when making TODO list.
732 This applies when creating the global todo list.
735 past Don't show entries scheduled today or in the past.
737 future Don't show entries scheduled in the future.
738 The idea behind this is that by scheduling it, you don't want to
739 think about it until the scheduled date.
741 all Don't show any scheduled entries in the global todo list.
742 The idea behind this is that by scheduling it, you have already
743 \"taken care\" of this item.
745 t Same as `all', for backward compatibility.
747 This variable can also have an integer as a value. See
748 `org-agenda-todo-ignore-timestamp' for more details.
750 See also `org-agenda-todo-ignore-with-date'.
751 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
752 to make his option also apply to the tags-todo list."
753 :group
'org-agenda-skip
754 :group
'org-agenda-todo-list
756 (const :tag
"Ignore future-scheduled todos" future
)
757 (const :tag
"Ignore past- or present-scheduled todos" past
)
758 (const :tag
"Ignore all scheduled todos" all
)
759 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
760 (const :tag
"Show scheduled todos" nil
)
761 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
763 (defcustom org-agenda-todo-ignore-deadlines nil
764 "Non-nil means ignore some deadlined TODO items when making TODO list.
765 There are different motivations for using different values, please think
766 carefully when configuring this variable.
768 This applies when creating the global todo list.
771 near Don't show near deadline entries. A deadline is near when it is
772 closer than `org-deadline-warning-days' days. The idea behind this
773 is that such items will appear in the agenda anyway.
775 far Don't show TODO entries where a deadline has been defined, but
776 the deadline is not near. This is useful if you don't want to
777 use the todo list to figure out what to do now.
779 past Don't show entries with a deadline timestamp for today or in the past.
781 future Don't show entries with a deadline timestamp in the future, not even
782 when they become `near' ones. Use it with caution.
784 all Ignore all TODO entries that do have a deadline.
786 t Same as `near', for backward compatibility.
788 This variable can also have an integer as a value. See
789 `org-agenda-todo-ignore-timestamp' for more details.
791 See also `org-agenda-todo-ignore-with-date'.
792 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
793 to make his option also apply to the tags-todo list."
794 :group
'org-agenda-skip
795 :group
'org-agenda-todo-list
797 (const :tag
"Ignore near deadlines" near
)
798 (const :tag
"Ignore near deadlines (compatibility)" t
)
799 (const :tag
"Ignore far deadlines" far
)
800 (const :tag
"Ignore all TODOs with a deadlines" all
)
801 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
802 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
804 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
805 "Time unit to use when possibly ignoring an agenda item.
807 See the docstring of various `org-agenda-todo-ignore-*' options.
808 The default is to compare time stamps using days. An item is thus
809 considered to be in the future if it is at least one day after today.
810 Non-nil means to compare time stamps using seconds. An item is then
811 considered future if it has a time value later than current time."
812 :group
'org-agenda-skip
813 :group
'org-agenda-todo-list
815 :package-version
'(Org .
"8.0")
817 (const :tag
"Compare time with days" nil
)
818 (const :tag
"Compare time with seconds" t
)))
820 (defcustom org-agenda-tags-todo-honor-ignore-options nil
821 "Non-nil means honor todo-list ignores options also in tags-todo search.
823 `org-agenda-todo-ignore-with-date',
824 `org-agenda-todo-ignore-timestamp',
825 `org-agenda-todo-ignore-scheduled',
826 `org-agenda-todo-ignore-deadlines'
827 make the global TODO list skip entries that have time stamps of certain
828 kinds. If this option is set, the same options will also apply for the
829 tags-todo search, which is the general tags/property matcher
830 restricted to unfinished TODO entries only."
831 :group
'org-agenda-skip
832 :group
'org-agenda-todo-list
833 :group
'org-agenda-match-view
836 (defcustom org-agenda-skip-scheduled-if-done nil
837 "Non-nil means don't show scheduled items in agenda when they are done.
838 This is relevant for the daily/weekly agenda, not for the TODO list. And
839 it applies only to the actual date of the scheduling. Warnings about
840 an item with a past scheduling dates are always turned off when the item
842 :group
'org-agenda-skip
843 :group
'org-agenda-daily
/weekly
846 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
847 "Non-nil means skip scheduling line if same entry shows because of deadline.
849 In the agenda of today, an entry can show up multiple times
850 because it is both scheduled and has a nearby deadline, and maybe
851 a plain time stamp as well.
853 When this variable is nil, the entry will be shown several times.
855 When set to t, then only the deadline is shown and the fact that
856 the entry is scheduled today or was scheduled previously is not
859 When set to the symbol `not-today', skip scheduled previously,
860 but not scheduled today.
862 When set to the symbol `repeated-after-deadline', skip scheduled
863 items if they are repeated beyond the current dealine."
864 :group
'org-agenda-skip
865 :group
'org-agenda-daily
/weekly
867 (const :tag
"Never" nil
)
868 (const :tag
"Always" t
)
869 (const :tag
"Not when scheduled today" not-today
)
870 (const :tag
"When repeated past deadline" repeated-after-deadline
)))
872 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
873 "Non-nil means skip timestamp line if same entry shows because of deadline.
874 In the agenda of today, an entry can show up multiple times
875 because it has both a plain timestamp and has a nearby deadline.
876 When this variable is t, then only the deadline is shown and the
877 fact that the entry has a timestamp for or including today is not
878 shown. When this variable is nil, the entry will be shown
880 :group
'org-agenda-skip
881 :group
'org-agenda-daily
/weekly
884 (const :tag
"Never" nil
)
885 (const :tag
"Always" t
)))
887 (defcustom org-agenda-skip-deadline-if-done nil
888 "Non-nil means don't show deadlines when the corresponding item is done.
889 When nil, the deadline is still shown and should give you a happy feeling.
890 This is relevant for the daily/weekly agenda. And it applied only to the
891 actually date of the deadline. Warnings about approaching and past-due
892 deadlines are always turned off when the item is DONE."
893 :group
'org-agenda-skip
894 :group
'org-agenda-daily
/weekly
897 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
898 "Non-nil means skip deadline prewarning when entry is also scheduled.
899 This will apply on all days where a prewarning for the deadline would
900 be shown, but not at the day when the entry is actually due. On that day,
901 the deadline will be shown anyway.
902 This variable may be set to nil, t, the symbol `pre-scheduled',
903 or a number which will then give the number of days before the actual
904 deadline when the prewarnings should resume. The symbol `pre-scheduled'
905 eliminates the deadline prewarning only prior to the scheduled date.
906 This can be used in a workflow where the first showing of the deadline will
907 trigger you to schedule it, and then you don't want to be reminded of it
908 because you will take care of it on the day when scheduled."
909 :group
'org-agenda-skip
910 :group
'org-agenda-daily
/weekly
913 (const :tag
"Always show prewarning" nil
)
914 (const :tag
"Remove prewarning prior to scheduled date" pre-scheduled
)
915 (const :tag
"Remove prewarning if entry is scheduled" t
)
916 (integer :tag
"Restart prewarning N days before deadline")))
918 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
919 "Non-nil means skip scheduled delay when entry also has a deadline.
920 This variable may be set to nil, t, the symbol `post-deadline',
921 or a number which will then give the number of days after the actual
922 scheduled date when the delay should expire. The symbol `post-deadline'
923 eliminates the schedule delay when the date is posterior to the deadline."
924 :group
'org-agenda-skip
925 :group
'org-agenda-daily
/weekly
927 :package-version
'(Org .
"8.0")
929 (const :tag
"Always honor delay" nil
)
930 (const :tag
"Ignore delay if posterior to the deadline" post-deadline
)
931 (const :tag
"Ignore delay if entry has a deadline" t
)
932 (integer :tag
"Honor delay up until N days after the scheduled date")))
934 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
935 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
936 When non-nil, after the search for timestamps has matched once in an
937 entry, the rest of the entry will not be searched."
938 :group
'org-agenda-skip
941 (defcustom org-agenda-skip-timestamp-if-done nil
942 "Non-nil means don't select item by timestamp or -range if it is DONE."
943 :group
'org-agenda-skip
944 :group
'org-agenda-daily
/weekly
947 (defcustom org-agenda-dim-blocked-tasks t
948 "Non-nil means dim blocked tasks in the agenda display.
949 This causes some overhead during agenda construction, but if you
950 have turned on `org-enforce-todo-dependencies',
951 `org-enforce-todo-checkbox-dependencies', or any other blocking
952 mechanism, this will create useful feedback in the agenda.
954 Instead of t, this variable can also have the value `invisible'.
955 Then blocked tasks will be invisible and only become visible when
956 they become unblocked. An exemption to this behavior is when a task is
957 blocked because of unchecked checkboxes below it. Since checkboxes do
958 not show up in the agenda views, making this task invisible you remove any
959 trace from agenda views that there is something to do. Therefore, a task
960 that is blocked because of checkboxes will never be made invisible, it
961 will only be dimmed."
962 :group
'org-agenda-daily
/weekly
963 :group
'org-agenda-todo-list
966 (const :tag
"Do not dim" nil
)
967 (const :tag
"Dim to a gray face" t
)
968 (const :tag
"Make invisible" invisible
)))
970 (defcustom org-timeline-show-empty-dates
3
971 "Non-nil means `org-timeline' also shows dates without an entry.
972 When nil, only the days which actually have entries are shown.
973 When t, all days between the first and the last date are shown.
974 When an integer, show also empty dates, but if there is a gap of more than
975 N days, just insert a special line indicating the size of the gap."
976 :group
'org-agenda-skip
978 (const :tag
"None" nil
)
980 (integer :tag
"at most")))
982 (defgroup org-agenda-startup nil
983 "Options concerning initial settings in the Agenda in Org Mode."
984 :tag
"Org Agenda Startup"
987 (defcustom org-agenda-menu-show-matcher t
988 "Non-nil means show the match string in the agenda dispatcher menu.
989 When nil, the matcher string is not shown, but is put into the help-echo
990 property so than moving the mouse over the command shows it.
991 Setting it to nil is good if matcher strings are very long and/or if
992 you want to use two-columns display (see `org-agenda-menu-two-columns')."
997 (define-obsolete-variable-alias 'org-agenda-menu-two-column
'org-agenda-menu-two-columns
"24.3")
999 (defcustom org-agenda-menu-two-columns nil
1000 "Non-nil means, use two columns to show custom commands in the dispatcher.
1001 If you use this, you probably want to set `org-agenda-menu-show-matcher'
1007 (define-obsolete-variable-alias 'org-finalize-agenda-hook
'org-agenda-finalize-hook
"24.3")
1008 (defcustom org-agenda-finalize-hook nil
1009 "Hook run just before displaying an agenda buffer.
1010 The buffer is still writable when the hook is called.
1012 You can modify some of the buffer substrings but you should be
1013 extra careful not to modify the text properties of the agenda
1014 headlines as the agenda display heavily relies on them."
1015 :group
'org-agenda-startup
1018 (defcustom org-agenda-mouse-1-follows-link nil
1019 "Non-nil means mouse-1 on a link will follow the link in the agenda.
1020 A longer mouse click will still set point. Does not work on XEmacs.
1021 Needs to be set before org.el is loaded."
1022 :group
'org-agenda-startup
1025 (defcustom org-agenda-start-with-follow-mode nil
1026 "The initial value of follow mode in a newly created agenda window."
1027 :group
'org-agenda-startup
1030 (defcustom org-agenda-follow-indirect nil
1031 "Non-nil means `org-agenda-follow-mode' displays only the
1032 current item's tree, in an indirect buffer."
1037 (defcustom org-agenda-show-outline-path t
1038 "Non-nil means show outline path in echo area after line motion."
1039 :group
'org-agenda-startup
1042 (defcustom org-agenda-start-with-entry-text-mode nil
1043 "The initial value of entry-text-mode in a newly created agenda window."
1044 :group
'org-agenda-startup
1047 (defcustom org-agenda-entry-text-maxlines
5
1048 "Number of text lines to be added when `E' is pressed in the agenda.
1050 Note that this variable only used during agenda display. Add add entry text
1051 when exporting the agenda, configure the variable
1052 `org-agenda-add-entry-ext-maxlines'."
1056 (defcustom org-agenda-entry-text-exclude-regexps nil
1057 "List of regular expressions to clean up entry text.
1058 The complete matches of all regular expressions in this list will be
1059 removed from entry text before it is shown in the agenda."
1061 :type
'(repeat (regexp)))
1063 (defcustom org-agenda-entry-text-leaders
" > "
1064 "Text prepended to the entry text in agenda buffers."
1066 :package-version
'(Org .
"8.0")
1070 (defvar org-agenda-entry-text-cleanup-hook nil
1071 "Hook that is run after basic cleanup of entry text to be shown in agenda.
1072 This cleanup is done in a temporary buffer, so the function may inspect and
1073 change the entire buffer.
1074 Some default stuff like drawers and scheduling/deadline dates will already
1075 have been removed when this is called, as will any matches for regular
1076 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
1078 (defvar org-agenda-include-inactive-timestamps nil
1079 "Non-nil means include inactive time stamps in agenda and timeline.
1080 Dynamically scoped.")
1082 (defgroup org-agenda-windows nil
1083 "Options concerning the windows used by the Agenda in Org Mode."
1084 :tag
"Org Agenda Windows"
1087 (defcustom org-agenda-window-setup
'reorganize-frame
1088 "How the agenda buffer should be displayed.
1089 Possible values for this option are:
1091 current-window Show agenda in the current window, keeping all other windows.
1092 other-window Use `switch-to-buffer-other-window' to display agenda.
1093 reorganize-frame Show only two windows on the current frame, the current
1094 window and the agenda.
1095 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1096 Also, when exiting the agenda, kill that frame.
1097 See also the variable `org-agenda-restore-windows-after-quit'."
1098 :group
'org-agenda-windows
1100 (const current-window
)
1102 (const other-window
)
1103 (const reorganize-frame
)))
1105 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
1106 "The min and max height of the agenda window as a fraction of frame height.
1107 The value of the variable is a cons cell with two numbers between 0 and 1.
1108 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1109 :group
'org-agenda-windows
1110 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
1112 (defcustom org-agenda-restore-windows-after-quit nil
1113 "Non-nil means restore window configuration upon exiting agenda.
1114 Before the window configuration is changed for displaying the agenda,
1115 the current status is recorded. When the agenda is exited with
1116 `q' or `x' and this option is set, the old state is restored. If
1117 `org-agenda-window-setup' is `other-frame', the value of this
1118 option will be ignored."
1119 :group
'org-agenda-windows
1122 (defcustom org-agenda-ndays nil
1123 "Number of days to include in overview display.
1125 Obsolete, see `org-agenda-span'."
1126 :group
'org-agenda-daily
/weekly
1129 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
1131 (defcustom org-agenda-span
'week
1132 "Number of days to include in overview display.
1133 Can be day, week, month, year, or any number of days.
1134 Custom commands can set this variable in the options section."
1135 :group
'org-agenda-daily
/weekly
1136 :type
'(choice (const :tag
"Day" day
)
1137 (const :tag
"Week" week
)
1138 (const :tag
"Month" month
)
1139 (const :tag
"Year" year
)
1140 (integer :tag
"Custom")))
1142 (defcustom org-agenda-start-on-weekday
1
1143 "Non-nil means start the overview always on the specified weekday.
1144 0 denotes Sunday, 1 denotes Monday, etc.
1145 When nil, always start on the current day.
1146 Custom commands can set this variable in the options section."
1147 :group
'org-agenda-daily
/weekly
1148 :type
'(choice (const :tag
"Today" nil
)
1149 (integer :tag
"Weekday No.")))
1151 (defcustom org-agenda-show-all-dates t
1152 "Non-nil means `org-agenda' shows every day in the selected range.
1153 When nil, only the days which actually have entries are shown."
1154 :group
'org-agenda-daily
/weekly
1157 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1158 "Format string for displaying dates in the agenda.
1159 Used by the daily/weekly agenda and by the timeline. This should be
1160 a format string understood by `format-time-string', or a function returning
1161 the formatted date as a string. The function must take a single argument,
1162 a calendar-style date list like (month day year)."
1163 :group
'org-agenda-daily
/weekly
1165 (string :tag
"Format string")
1166 (function :tag
"Function")))
1168 (defun org-agenda-format-date-aligned (date)
1169 "Format a DATE string for display in the daily/weekly agenda, or timeline.
1170 This function makes sure that dates are aligned for easy reading."
1172 (let* ((dayname (calendar-day-name date
))
1174 (day-of-week (calendar-day-of-week date
))
1176 (monthname (calendar-month-name month
))
1178 (iso-week (org-days-to-iso-week
1179 (calendar-absolute-from-gregorian date
)))
1180 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1182 ((and (= month
12) (<= iso-week
1))
1185 (weekstring (if (= day-of-week
1)
1186 (format " W%02d" iso-week
)
1188 (format "%-10s %2d %s %4d%s"
1189 dayname day monthname year weekstring
)))
1191 (defcustom org-agenda-time-leading-zero nil
1192 "Non-nil means use leading zero for military times in agenda.
1193 For example, 9:30am would become 09:30 rather than 9:30."
1194 :group
'org-agenda-daily
/weekly
1198 (defcustom org-agenda-timegrid-use-ampm nil
1199 "When set, show AM/PM style timestamps on the timegrid."
1204 (defun org-agenda-time-of-day-to-ampm (time)
1205 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1206 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1207 (minute (substring time -
2))
1210 ((equal hour-number
12)
1214 (setq hour-number
(- hour-number
12))))
1216 (if org-agenda-time-leading-zero
1217 (format "%02d" hour-number
)
1218 (format "%02s" (number-to-string hour-number
)))
1221 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1222 "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
1223 (if org-agenda-timegrid-use-ampm
1224 (org-agenda-time-of-day-to-ampm time
)
1227 (defcustom org-agenda-weekend-days
'(6 0)
1228 "Which days are weekend?
1229 These days get the special face `org-agenda-date-weekend' in the agenda
1230 and timeline buffers."
1231 :group
'org-agenda-daily
/weekly
1232 :type
'(set :greedy t
1233 (const :tag
"Monday" 1)
1234 (const :tag
"Tuesday" 2)
1235 (const :tag
"Wednesday" 3)
1236 (const :tag
"Thursday" 4)
1237 (const :tag
"Friday" 5)
1238 (const :tag
"Saturday" 6)
1239 (const :tag
"Sunday" 0)))
1241 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1242 "Non-nil means jump to today when moving a past date forward in time.
1243 When using S-right in the agenda to move a a date forward, and the date
1244 stamp currently points to the past, the first key press will move it
1245 to today. WHen nil, just move one day forward even if the date stays
1247 :group
'org-agenda-daily
/weekly
1251 (defcustom org-agenda-include-diary nil
1252 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1253 Custom commands can set this variable in the options section."
1254 :group
'org-agenda-daily
/weekly
1257 (defcustom org-agenda-include-deadlines t
1258 "If non-nil, include entries within their deadline warning period.
1259 Custom commands can set this variable in the options section."
1260 :group
'org-agenda-daily
/weekly
1264 (defcustom org-agenda-repeating-timestamp-show-all t
1265 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1266 When set to a list of strings, only show occurrences of repeating
1267 stamps for these TODO keywords. When nil, only one occurrence is
1268 shown, either today or the nearest into the future."
1269 :group
'org-agenda-daily
/weekly
1271 (const :tag
"Show repeating stamps" t
)
1272 (repeat :tag
"Show repeating stamps for these TODO keywords"
1273 (string :tag
"TODO Keyword"))
1274 (const :tag
"Don't show repeating stamps" nil
)))
1276 (defcustom org-scheduled-past-days
10000
1277 "Number of days to continue listing scheduled items not marked DONE.
1278 When an item is scheduled on a date, it shows up in the agenda on this
1279 day and will be listed until it is marked done for the number of days
1281 :group
'org-agenda-daily
/weekly
1284 (defcustom org-agenda-log-mode-items
'(closed clock
)
1285 "List of items that should be shown in agenda log mode.
1286 This list may contain the following symbols:
1288 closed Show entries that have been closed on that day.
1289 clock Show entries that have received clocked time on that day.
1290 state Show all logged state changes.
1291 Note that instead of changing this variable, you can also press `C-u l' in
1292 the agenda to display all available LOG items temporarily."
1293 :group
'org-agenda-daily
/weekly
1294 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1296 (defcustom org-agenda-clock-consistency-checks
1297 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1298 :gap-ok-around
("4:00")
1299 :default-face
((:background
"DarkRed") (:foreground
"white"))
1300 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1301 :long-face nil
:short-face nil
)
1302 "This is a property list, with the following keys:
1304 :max-duration Mark clocking chunks that are longer than this time.
1305 This is a time string like \"HH:MM\", or the number
1306 of minutes as an integer.
1308 :min-duration Mark clocking chunks that are shorter that this.
1309 This is a time string like \"HH:MM\", or the number
1310 of minutes as an integer.
1312 :max-gap Mark gaps between clocking chunks that are longer than
1313 this duration. A number of minutes, or a string
1316 :gap-ok-around List of times during the day which are usually not working
1317 times. When a gap is detected, but the gap contains any
1318 of these times, the gap is *not* reported. For example,
1319 if this is (\"4:00\" \"13:00\") then gaps that contain
1320 4:00 in the morning (i.e. the night) and 13:00
1321 (i.e. a typical lunch time) do not cause a warning.
1322 You should have at least one time during the night in this
1323 list, or otherwise the first task each morning will trigger
1324 a warning because it follows a long gap.
1326 Furthermore, the following properties can be used to define faces for
1329 :default-face the default face, if the specific face is undefined
1330 :overlap-face face for overlapping clocks
1331 :gap-face face for gaps between clocks
1332 :no-end-time-face face for incomplete clocks
1333 :long-face face for clock intervals that are too long
1334 :short-face face for clock intervals that are too short"
1335 :group
'org-agenda-daily
/weekly
1340 (defcustom org-agenda-log-mode-add-notes t
1341 "Non-nil means add first line of notes to log entries in agenda views.
1342 If a log item like a state change or a clock entry is associated with
1343 notes, the first line of these notes will be added to the entry in the
1345 :group
'org-agenda-daily
/weekly
1348 (defcustom org-agenda-start-with-log-mode nil
1349 "The initial value of log-mode in a newly created agenda window.
1350 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1351 explanations on the possible values."
1352 :group
'org-agenda-startup
1353 :group
'org-agenda-daily
/weekly
1354 :type
'(choice (const :tag
"Don't show log items" nil
)
1355 (const :tag
"Show only log items" 'only
)
1356 (const :tag
"Show all possible log items" 'clockcheck
)
1357 (repeat :tag
"Choose among possible values for `org-agenda-log-mode-items'"
1358 (choice (const :tag
"Show closed log items" 'closed
)
1359 (const :tag
"Show clocked log items" 'clock
)
1360 (const :tag
"Show all logged state changes" 'state
)))))
1362 (defcustom org-agenda-start-with-clockreport-mode nil
1363 "The initial value of clockreport-mode in a newly created agenda window."
1364 :group
'org-agenda-startup
1365 :group
'org-agenda-daily
/weekly
1368 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1369 "Property list with parameters for the clocktable in clockreport mode.
1370 This is the display mode that shows a clock table in the daily/weekly
1371 agenda, the properties for this dynamic block can be set here.
1372 The usual clocktable parameters are allowed here, but you cannot set
1373 the properties :name, :tstart, :tend, :block, and :scope - these will
1374 be overwritten to make sure the content accurately reflects the
1375 current display in the agenda."
1376 :group
'org-agenda-daily
/weekly
1379 (defcustom org-agenda-search-view-always-boolean nil
1380 "Non-nil means the search string is interpreted as individual parts.
1382 The search string for search view can either be interpreted as a phrase,
1383 or as a list of snippets that define a boolean search for a number of
1386 When this is non-nil, the string will be split on whitespace, and each
1387 snippet will be searched individually, and all must match in order to
1388 select an entry. A snippet is then a single string of non-white
1389 characters, or a string in double quotes, or a regexp in {} braces.
1390 If a snippet is preceded by \"-\", the snippet must *not* match.
1391 \"+\" is syntactic sugar for positive selection. Each snippet may
1392 be found as a full word or a partial word, but see the variable
1393 `org-agenda-search-view-force-full-words'.
1395 When this is nil, search will look for the entire search phrase as one,
1396 with each space character matching any amount of whitespace, including
1399 Even when this is nil, you can still switch to Boolean search dynamically
1400 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1401 is a regexp marked with braces like \"{abc}\", this will also switch to
1403 :group
'org-agenda-search-view
1407 (org-defvaralias 'org-agenda-search-view-search-words-only
1408 'org-agenda-search-view-always-boolean
)
1410 (defcustom org-agenda-search-view-force-full-words nil
1411 "Non-nil means, search words must be matches as complete words.
1412 When nil, they may also match part of a word."
1413 :group
'org-agenda-search-view
1417 (defcustom org-agenda-search-view-max-outline-level nil
1418 "Maximum outline level to display in search view.
1419 E.g. when this is set to 1, the search view will only
1420 show headlines of level 1."
1421 :group
'org-agenda-search-view
1423 :package-version
'(Org .
"8.0")
1426 (defgroup org-agenda-time-grid nil
1427 "Options concerning the time grid in the Org-mode Agenda."
1428 :tag
"Org Agenda Time Grid"
1431 (defcustom org-agenda-search-headline-for-time t
1432 "Non-nil means search headline for a time-of-day.
1433 If the headline contains a time-of-day in one format or another, it will
1434 be used to sort the entry into the time sequence of items for a day.
1435 Some people have time stamps in the headline that refer to the creation
1436 time or so, and then this produces an unwanted side effect. If this is
1437 the case for your, use this variable to turn off searching the headline
1439 :group
'org-agenda-time-grid
1442 (defcustom org-agenda-use-time-grid t
1443 "Non-nil means show a time grid in the agenda schedule.
1444 A time grid is a set of lines for specific times (like every two hours between
1445 8:00 and 20:00). The items scheduled for a day at specific times are
1446 sorted in between these lines.
1447 For details about when the grid will be shown, and what it will look like, see
1448 the variable `org-agenda-time-grid'."
1449 :group
'org-agenda-time-grid
1452 (defcustom org-agenda-time-grid
1453 '((daily today require-timed
)
1455 (800 1000 1200 1400 1600 1800 2000))
1457 "The settings for time grid for agenda display.
1458 This is a list of three items. The first item is again a list. It contains
1459 symbols specifying conditions when the grid should be displayed:
1461 daily if the agenda shows a single day
1462 weekly if the agenda shows an entire week
1463 today show grid on current date, independent of daily/weekly display
1464 require-timed show grid only if at least one item has a time specification
1466 The second item is a string which will be placed behind the grid time.
1468 The third item is a list of integers, indicating the times that should have
1470 :group
'org-agenda-time-grid
1473 (set :greedy t
:tag
"Grid Display Options"
1474 (const :tag
"Show grid in single day agenda display" daily
)
1475 (const :tag
"Show grid in weekly agenda display" weekly
)
1476 (const :tag
"Always show grid for today" today
)
1477 (const :tag
"Show grid only if any timed entries are present"
1479 (const :tag
"Skip grid times already present in an entry"
1481 (string :tag
"Grid String")
1482 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1484 (defcustom org-agenda-show-current-time-in-grid t
1485 "Non-nil means show the current time in the time grid."
1486 :group
'org-agenda-time-grid
1490 (defcustom org-agenda-current-time-string
1491 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1492 "The string for the current time marker in the agenda."
1493 :group
'org-agenda-time-grid
1497 (defgroup org-agenda-sorting nil
1498 "Options concerning sorting in the Org-mode Agenda."
1499 :tag
"Org Agenda Sorting"
1502 (defcustom org-agenda-sorting-strategy
1503 '((agenda habit-down time-up priority-down category-keep
)
1504 (todo priority-down category-keep
)
1505 (tags priority-down category-keep
)
1506 (search category-keep
))
1507 "Sorting structure for the agenda items of a single day.
1508 This is a list of symbols which will be used in sequence to determine
1509 if an entry should be listed before another entry. The following
1510 symbols are recognized:
1512 time-up Put entries with time-of-day indications first, early first
1513 time-down Put entries with time-of-day indications first, late first
1514 timestamp-up Sort by any timestamp, early first
1515 timestamp-down Sort by any timestamp, late first
1516 scheduled-up Sort by scheduled timestamp, early first
1517 scheduled-down Sort by scheduled timestamp, late first
1518 deadline-up Sort by deadline timestamp, early first
1519 deadline-down Sort by deadline timestamp, late first
1520 ts-up Sort by active timestamp, early first
1521 ts-down Sort by active timestamp, late first
1522 tsia-up Sort by inactive timestamp, early first
1523 tsia-down Sort by inactive timestamp, late first
1524 category-keep Keep the default order of categories, corresponding to the
1525 sequence in `org-agenda-files'.
1526 category-up Sort alphabetically by category, A-Z.
1527 category-down Sort alphabetically by category, Z-A.
1528 tag-up Sort alphabetically by last tag, A-Z.
1529 tag-down Sort alphabetically by last tag, Z-A.
1530 priority-up Sort numerically by priority, high priority last.
1531 priority-down Sort numerically by priority, high priority first.
1532 todo-state-up Sort by todo state, tasks that are done last.
1533 todo-state-down Sort by todo state, tasks that are done first.
1534 effort-up Sort numerically by estimated effort, high effort last.
1535 effort-down Sort numerically by estimated effort, high effort first.
1536 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1537 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1538 habit-up Put entries that are habits first
1539 habit-down Put entries that are habits last
1540 alpha-up Sort headlines alphabetically
1541 alpha-down Sort headlines alphabetically, reversed
1543 The different possibilities will be tried in sequence, and testing stops
1544 if one comparison returns a \"not-equal\". For example, the default
1545 '(time-up category-keep priority-down)
1546 means: Pull out all entries having a specified time of day and sort them,
1547 in order to make a time schedule for the current day the first thing in the
1548 agenda listing for the day. Of the entries without a time indication, keep
1549 the grouped in categories, don't sort the categories, but keep them in
1550 the sequence given in `org-agenda-files'. Within each category sort by
1553 Leaving out `category-keep' would mean that items will be sorted across
1554 categories by priority.
1556 Instead of a single list, this can also be a set of list for specific
1557 contents, with a context symbol in the car of the list, any of
1558 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1560 Custom commands can bind this variable in the options section."
1561 :group
'org-agenda-sorting
1563 (repeat :tag
"General" ,org-sorting-choice
)
1564 (list :tag
"Individually"
1565 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1566 (repeat ,org-sorting-choice
))
1567 (cons (const :tag
"Strategy for TODO lists" todo
)
1568 (repeat ,org-sorting-choice
))
1569 (cons (const :tag
"Strategy for Tags matches" tags
)
1570 (repeat ,org-sorting-choice
))
1571 (cons (const :tag
"Strategy for search matches" search
)
1572 (repeat ,org-sorting-choice
)))))
1574 (defcustom org-agenda-cmp-user-defined nil
1575 "A function to define the comparison `user-defined'.
1576 This function must receive two arguments, agenda entry a and b.
1577 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1578 the user comparison, return nil.
1579 When this is defined, you can make `user-defined-up' and `user-defined-down'
1580 part of an agenda sorting strategy."
1581 :group
'org-agenda-sorting
1584 (defcustom org-sort-agenda-notime-is-late t
1585 "Non-nil means items without time are considered late.
1586 This is only relevant for sorting. When t, items which have no explicit
1587 time like 15:30 will be considered as 99:01, i.e. later than any items which
1588 do have a time. When nil, the default time is before 0:00. You can use this
1589 option to decide if the schedule for today should come before or after timeless
1591 :group
'org-agenda-sorting
1594 (defcustom org-sort-agenda-noeffort-is-high t
1595 "Non-nil means items without effort estimate are sorted as high effort.
1596 This also applies when filtering an agenda view with respect to the
1597 < or > effort operator. Then, tasks with no effort defined will be treated
1598 as tasks with high effort.
1599 When nil, such items are sorted as 0 minutes effort."
1600 :group
'org-agenda-sorting
1603 (defgroup org-agenda-line-format nil
1604 "Options concerning the entry prefix in the Org-mode agenda display."
1605 :tag
"Org Agenda Line Format"
1608 (defcustom org-agenda-prefix-format
1609 '((agenda .
" %i %-12:c%?-12t% s")
1611 (todo .
" %i %-12:c")
1612 (tags .
" %i %-12:c")
1613 (search .
" %i %-12:c"))
1614 "Format specifications for the prefix of items in the agenda views.
1615 An alist with five entries, each for the different agenda types. The
1616 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1617 The values are format strings.
1619 This format works similar to a printf format, with the following meaning:
1621 %c the category of the item, \"Diary\" for entries from the diary,
1622 or as given by the CATEGORY keyword or derived from the file name
1623 %e the effort required by the item
1624 %l the level of the item (insert X space(s) if item is of level X)
1625 %i the icon category of the item, see `org-agenda-category-icon-alist'
1626 %T the last tag of the item (ignore inherited tags, which come first)
1627 %t the HH:MM time-of-day specification if one applies to the entry
1628 %s Scheduling/Deadline information, a short string
1629 %b show breadcrumbs, i.e., the names of the higher levels
1630 %(expression) Eval EXPRESSION and replace the control string
1633 All specifiers work basically like the standard `%s' of printf, but may
1634 contain two additional characters: a question mark just after the `%'
1635 and a whitespace/punctuation character just before the final letter.
1637 If the first character after `%' is a question mark, the entire field
1638 will only be included if the corresponding value applies to the current
1639 entry. This is useful for fields which should have fixed width when
1640 present, but zero width when absent. For example, \"%?-12t\" will
1641 result in a 12 character time field if a time of the day is specified,
1642 but will completely disappear in entries which do not contain a time.
1644 If there is punctuation or whitespace character just before the
1645 final format letter, this character will be appended to the field
1646 value if the value is not empty. For example, the format
1647 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1648 the category is empty, no additional colon is inserted.
1650 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1653 - Indent the line with two space characters
1654 - Give the category a 12 chars wide field, padded with whitespace on
1655 the right (because of `-'). Append a colon if there is a category
1657 - If there is a time-of-day, put it into a 12 chars wide field. If no
1658 time, don't put in an empty field, just skip it (because of '?').
1659 - Finally, put the scheduling information.
1661 See also the variables `org-agenda-remove-times-when-in-prefix' and
1662 `org-agenda-remove-tags'.
1664 Custom commands can set this variable in the options section."
1666 (string :tag
"General format")
1667 (list :greedy t
:tag
"View dependent"
1668 (cons (const agenda
) (string :tag
"Format"))
1669 (cons (const timeline
) (string :tag
"Format"))
1670 (cons (const todo
) (string :tag
"Format"))
1671 (cons (const tags
) (string :tag
"Format"))
1672 (cons (const search
) (string :tag
"Format"))))
1673 :group
'org-agenda-line-format
)
1675 (defvar org-prefix-format-compiled nil
1676 "The compiled prefix format and associated variables.
1677 This is a list where first element is a list of variable bindings, and second
1678 element is the compiled format expression. See the variable
1679 `org-agenda-prefix-format'.")
1681 (defcustom org-agenda-todo-keyword-format
"%-1s"
1682 "Format for the TODO keyword in agenda lines.
1683 Set this to something like \"%-12s\" if you want all TODO keywords
1684 to occupy a fixed space in the agenda display."
1685 :group
'org-agenda-line-format
1688 (defcustom org-agenda-diary-sexp-prefix nil
1689 "A regexp that matches part of a diary sexp entry
1690 which should be treated as scheduling/deadline information in
1693 For example, you can use this to extract the `diary-remind-message' from
1694 `diary-remind' entries."
1695 :group
'org-agenda-line-format
1696 :type
'(choice (const :tag
"None" nil
) (regexp :tag
"Regexp")))
1698 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1699 "Text preceding timerange entries in the agenda view.
1700 This is a list with two strings. The first applies when the range
1701 is entirely on one day. The second applies if the range spans several days.
1702 The strings may have two \"%d\" format specifiers which will be filled
1703 with the sequence number of the days, and the total number of days in the
1704 range, respectively."
1705 :group
'org-agenda-line-format
1707 (string :tag
"Deadline today ")
1708 (choice :tag
"Deadline relative"
1709 (string :tag
"Format string")
1712 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1713 "Text preceding scheduled items in the agenda view.
1714 This is a list with two strings. The first applies when the item is
1715 scheduled on the current day. The second applies when it has been scheduled
1716 previously, it may contain a %d indicating that this is the nth time that
1717 this item is scheduled, due to automatic rescheduling of unfinished items
1718 for the following day. So this number is one larger than the number of days
1719 that passed since this item was scheduled first."
1720 :group
'org-agenda-line-format
1722 :package-version
'(Org .
"8.0")
1724 (string :tag
"Scheduled today ")
1725 (string :tag
"Scheduled previously")))
1727 (defcustom org-agenda-inactive-leader
"["
1728 "Text preceding item pulled into the agenda by inactive time stamps.
1729 These entries are added to the agenda when pressing \"[\"."
1730 :group
'org-agenda-line-format
1733 (string :tag
"Scheduled today ")
1734 (string :tag
"Scheduled previously")))
1736 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: " "%2d d. ago: ")
1737 "Text preceding deadline items in the agenda view.
1738 This is a list with three strings. The first applies when the item has its
1739 deadline on the current day. The second applies when the deadline is in the
1740 future, the third one when it is in the past. The strings may contain %d
1741 to capture the number of days."
1742 :group
'org-agenda-line-format
1744 :package-version
'(Org .
"8.0")
1746 (string :tag
"Deadline today ")
1747 (choice :tag
"Deadline relative"
1748 (string :tag
"Format string")
1751 (defcustom org-agenda-remove-times-when-in-prefix t
1752 "Non-nil means remove duplicate time specifications in agenda items.
1753 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1754 time-of-day specification in a headline or diary entry is extracted and
1755 placed into the prefix. If this option is non-nil, the original specification
1756 \(a timestamp or -range, or just a plain time(range) specification like
1757 11:30-4pm) will be removed for agenda display. This makes the agenda less
1759 The option can be t or nil. It may also be the symbol `beg', indicating
1760 that the time should only be removed when it is located at the beginning of
1761 the headline/diary entry."
1762 :group
'org-agenda-line-format
1764 (const :tag
"Always" t
)
1765 (const :tag
"Never" nil
)
1766 (const :tag
"When at beginning of entry" beg
)))
1768 (defcustom org-agenda-remove-timeranges-from-blocks nil
1769 "Non-nil means remove time ranges specifications in agenda
1770 items that span on several days."
1771 :group
'org-agenda-line-format
1775 (defcustom org-agenda-default-appointment-duration nil
1776 "Default duration for appointments that only have a starting time.
1777 When nil, no duration is specified in such cases.
1778 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1779 :group
'org-agenda-line-format
1781 (integer :tag
"Minutes")
1782 (const :tag
"No default duration")))
1784 (defcustom org-agenda-show-inherited-tags t
1785 "Non-nil means show inherited tags in each agenda line.
1787 When this option is set to 'always, it take precedences over
1788 `org-agenda-use-tag-inheritance' and inherited tags are shown
1791 When this option is set to t (the default), inherited tags are
1792 shown when they are available, i.e. when the value of
1793 `org-agenda-use-tag-inheritance' has been taken into account.
1795 This can be set to a list of agenda types in which the agenda
1796 must display the inherited tags. Available types are 'todo,
1797 'agenda, 'search and 'timeline.
1799 When set to nil, never show inherited tags in agenda lines."
1800 :group
'org-agenda-line-format
1804 (const :tag
"Show inherited tags when available" t
)
1805 (const :tag
"Always show inherited tags" 'always
)
1806 (repeat :tag
"Show inherited tags only in selected agenda types"
1807 (symbol :tag
"Agenda type"))))
1809 (defcustom org-agenda-use-tag-inheritance
'(todo search timeline agenda
)
1810 "List of agenda view types where to use tag inheritance.
1812 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1813 controlled by `org-use-tag-inheritance'. In other agenda types,
1814 `org-use-tag-inheritance' is not used for the selection of the
1815 agenda entries. Still, you may want the agenda to be aware of
1816 the inherited tags anyway, e.g. for later tag filtering.
1818 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1820 This variable has no effect if `org-agenda-show-inherited-tags'
1821 is set to 'always. In that case, the agenda is aware of those
1824 The default value sets tags in every agenda type. Setting this
1825 option to nil will speed up non-tags agenda view a lot."
1829 (const :tag
"Use tag inheritance in all agenda types" t
)
1830 (repeat :tag
"Use tag inheritance in selected agenda types"
1831 (symbol :tag
"Agenda type"))))
1833 (defcustom org-agenda-hide-tags-regexp nil
1834 "Regular expression used to filter away specific tags in agenda views.
1835 This means that these tags will be present, but not be shown in the agenda
1836 line. Secondary filtering will still work on the hidden tags.
1837 Nil means don't hide any tags."
1838 :group
'org-agenda-line-format
1840 (const :tag
"Hide none" nil
)
1841 (string :tag
"Regexp ")))
1843 (defcustom org-agenda-remove-tags nil
1844 "Non-nil means remove the tags from the headline copy in the agenda.
1845 When this is the symbol `prefix', only remove tags when
1846 `org-agenda-prefix-format' contains a `%T' specifier."
1847 :group
'org-agenda-line-format
1849 (const :tag
"Always" t
)
1850 (const :tag
"Never" nil
)
1851 (const :tag
"When prefix format contains %T" prefix
)))
1853 (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
1854 'org-agenda-remove-tags
)
1856 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1857 "Shift tags in agenda items to this column.
1858 If this number is positive, it specifies the column. If it is negative,
1859 it means that the tags should be flushright to that column. For example,
1860 -80 works well for a normal 80 character screen."
1861 :group
'org-agenda-line-format
1864 (org-defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
)
1866 (defcustom org-agenda-fontify-priorities
'cookies
1867 "Non-nil means highlight low and high priorities in agenda.
1868 When t, the highest priority entries are bold, lowest priority italic.
1869 However, settings in `org-priority-faces' will overrule these faces.
1870 When this variable is the symbol `cookies', only fontify the
1871 cookies, not the entire task.
1872 This may also be an association list of priority faces, whose
1873 keys are the character values of `org-highest-priority',
1874 `org-default-priority', and `org-lowest-priority' (the default values
1875 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1876 color as a string, or a list like `(:background \"Red\")'.
1877 If it is a color, the variable `org-faces-easy-properties'
1878 determines if it is a foreground or a background color."
1879 :group
'org-agenda-line-format
1881 (const :tag
"Never" nil
)
1882 (const :tag
"Defaults" t
)
1883 (const :tag
"Cookies only" cookies
)
1884 (repeat :tag
"Specify"
1885 (list (character :tag
"Priority" :value ?A
)
1886 (choice :tag
"Face "
1887 (string :tag
"Color")
1888 (sexp :tag
"Face"))))))
1890 (defcustom org-agenda-day-face-function nil
1891 "Function called to determine what face should be used to display a day.
1892 The only argument passed to that function is the day. It should
1893 returns a face, or nil if does not want to specify a face and let
1894 the normal rules apply."
1895 :group
'org-agenda-line-format
1899 (defcustom org-agenda-category-icon-alist nil
1900 "Alist of category icon to be displayed in agenda views.
1902 Each entry should have the following format:
1904 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1906 Where CATEGORY-REGEXP is a regexp matching the categories where
1907 the icon should be displayed.
1908 FILE-OR-DATA either a file path or a string containing image data.
1910 The other fields can be omitted safely if not needed:
1911 TYPE indicates the image type.
1912 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1914 PROPS are additional image attributes to assign to the image,
1915 like, e.g. `:ascent center'.
1917 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1919 If you want to set the display properties yourself, just put a
1920 list as second element:
1922 (CATEGORY-REGEXP (MY PROPERTY LIST))
1924 For example, to display a 16px horizontal space for Emacs
1925 category, you can use:
1927 (\"Emacs\" '(space . (:width (16))))"
1928 :group
'org-agenda-line-format
1930 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1931 :value-type
(choice (list :tag
"Icon"
1932 (string :tag
"File or data")
1933 (symbol :tag
"Type")
1934 (boolean :tag
"Data?")
1935 (repeat :tag
"Extra image properties" :inline t symbol
))
1936 (list :tag
"Display properties" sexp
))))
1938 (defgroup org-agenda-column-view nil
1939 "Options concerning column view in the agenda."
1940 :tag
"Org Agenda Column View"
1943 (defcustom org-agenda-columns-show-summaries t
1944 "Non-nil means show summaries for columns displayed in the agenda view."
1945 :group
'org-agenda-column-view
1948 (defcustom org-agenda-columns-compute-summary-properties t
1949 "Non-nil means recompute all summary properties before column view.
1950 When column view in the agenda is listing properties that have a summary
1951 operator, it can go to all relevant buffers and recompute the summaries
1952 there. This can mean overhead for the agenda column view, but is necessary
1953 to have thing up to date.
1954 As a special case, a CLOCKSUM property also makes sure that the clock
1955 computations are current."
1956 :group
'org-agenda-column-view
1959 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1960 "Non-nil means the duration of an appointment will add to day effort.
1961 The property to which appointment durations will be added is the one given
1962 in the option `org-effort-property'. If an appointment does not have
1963 an end time, `org-agenda-default-appointment-duration' will be used. If that
1964 is not set, an appointment without end time will not contribute to the time
1966 :group
'org-agenda-column-view
1969 (defcustom org-agenda-auto-exclude-function nil
1970 "A function called with a tag to decide if it is filtered on '/ RET'.
1971 The sole argument to the function, which is called once for each
1972 possible tag, is a string giving the name of the tag. The
1973 function should return either nil if the tag should be included
1974 as normal, or \"-<TAG>\" to exclude the tag.
1975 Note that for the purpose of tag filtering, only the lower-case version of
1976 all tags will be considered, so that this function will only ever see
1977 the lower-case version of all tags."
1981 (defcustom org-agenda-bulk-custom-functions nil
1982 "Alist of characters and custom functions for bulk actions.
1983 For example, this value makes those two functions available:
1988 With selected entries in an agenda buffer, `B R' will call
1989 the custom function `set-category' on the selected entries.
1990 Note that functions in this alist don't need to be quoted."
1995 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
1996 "Execute BODY with point at location given by `org-hd-marker' property.
1997 If STRING is non-nil, the text property will be fetched from position 0
1998 in that string. If STRING is nil, it will be fetched from the beginning
1999 of the current line."
2000 (org-with-gensyms (marker)
2001 `(let ((,marker
(get-text-property (if string
0 (point-at-bol))
2002 'org-hd-marker
,string
)))
2003 (with-current-buffer (marker-buffer ,marker
)
2007 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
2009 (defun org-add-agenda-custom-command (entry)
2010 "Replace or add a command in `org-agenda-custom-commands'.
2011 This is mostly for hacking and trying a new command - once the command
2012 works you probably want to add it to `org-agenda-custom-commands' for good."
2013 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
2015 (setcdr ass
(cdr entry
))
2016 (push entry org-agenda-custom-commands
))))
2018 ;;; Define the org-agenda-mode
2020 (defvar org-agenda-mode-map
(make-sparse-keymap)
2021 "Keymap for `org-agenda-mode'.")
2022 (org-defvaralias 'org-agenda-keymap
'org-agenda-mode-map
)
2024 (defvar org-agenda-menu
) ; defined later in this file.
2025 (defvar org-agenda-restrict nil
) ; defined later in this file.
2026 (defvar org-agenda-follow-mode nil
)
2027 (defvar org-agenda-entry-text-mode nil
)
2028 (defvar org-agenda-clockreport-mode nil
)
2029 (defvar org-agenda-show-log nil
)
2030 (defvar org-agenda-redo-command nil
)
2031 (defvar org-agenda-query-string nil
)
2032 (defvar org-agenda-mode-hook nil
2033 "Hook run after `org-agenda-mode' is turned on.
2034 The buffer is still writable when this hook is called.")
2035 (defvar org-agenda-type nil
)
2036 (defvar org-agenda-force-single-file nil
)
2037 (defvar org-agenda-bulk-marked-entries nil
2038 "List of markers that refer to marked entries in the agenda.")
2040 ;;; Multiple agenda buffers support
2042 (defcustom org-agenda-sticky nil
2043 "Non-nil means agenda q key will bury agenda buffers.
2044 Agenda commands will then show existing buffer instead of generating new ones.
2045 When nil, `q' will kill the single agenda buffer."
2052 (defun org-toggle-sticky-agenda (&optional arg
)
2053 "Toggle `org-agenda-sticky'."
2055 (let ((new-value (if arg
2056 (> (prefix-numeric-value arg
) 0)
2057 (not org-agenda-sticky
))))
2058 (if (equal new-value org-agenda-sticky
)
2059 (and (org-called-interactively-p 'interactive
)
2060 (message "Sticky agenda was already %s"
2061 (if org-agenda-sticky
"enabled" "disabled")))
2062 (setq org-agenda-sticky new-value
)
2063 (org-agenda-kill-all-agenda-buffers)
2064 (and (org-called-interactively-p 'interactive
)
2065 (message "Sticky agenda was %s"
2066 (if org-agenda-sticky
"enabled" "disabled"))))))
2068 (defvar org-agenda-buffer nil
2069 "Agenda buffer currently being generated.")
2071 (defvar org-agenda-last-prefix-arg nil
)
2072 (defvar org-agenda-this-buffer-name nil
)
2073 (defvar org-agenda-doing-sticky-redo nil
)
2074 (defvar org-agenda-this-buffer-is-sticky nil
)
2076 (defconst org-agenda-local-vars
2077 '(org-agenda-this-buffer-name
2078 org-agenda-undo-list
2079 org-agenda-pending-undo-list
2080 org-agenda-follow-mode
2081 org-agenda-entry-text-mode
2082 org-agenda-clockreport-mode
2084 org-agenda-redo-command
2085 org-agenda-query-string
2087 org-agenda-bulk-marked-entries
2088 org-agenda-undo-has-started-in
2090 org-agenda-pre-window-conf
2091 org-agenda-columns-active
2092 org-agenda-tag-filter-overlays
2093 org-agenda-tag-filter
2094 org-agenda-cat-filter-overlays
2095 org-agenda-category-filter
2096 org-agenda-re-filter-overlays
2097 org-agenda-regexp-filter
2099 org-agenda-last-search-view-search-was-boolean
2100 org-agenda-filtered-by-category
2101 org-agenda-filter-form
2102 org-agenda-cycle-counter
2103 org-agenda-last-prefix-arg
)
2104 "Variables that must be local in agenda buffers to allow multiple buffers.")
2106 (defun org-agenda-mode ()
2107 "Mode for time-sorted view on action items in Org-mode files.
2109 The following commands are available:
2111 \\{org-agenda-mode-map}"
2113 (cond (org-agenda-doing-sticky-redo
2114 ;; Refreshing sticky agenda-buffer
2116 ;; Preserve the value of `org-agenda-local-vars' variables,
2117 ;; while letting `kill-all-local-variables' kill the rest
2118 (let ((save (buffer-local-variables)))
2119 (kill-all-local-variables)
2120 (mapc 'make-local-variable org-agenda-local-vars
)
2122 (let ((var (car elem
))
2125 (member var org-agenda-local-vars
))
2127 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
2129 ;; Creating a sticky Agenda buffer for the first time
2130 (kill-all-local-variables)
2131 (mapc 'make-local-variable org-agenda-local-vars
)
2132 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
2134 ;; Creating a non-sticky agenda buffer
2135 (kill-all-local-variables)
2136 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) nil
)))
2137 (setq org-agenda-undo-list nil
2138 org-agenda-pending-undo-list nil
2139 org-agenda-bulk-marked-entries nil
)
2140 (setq major-mode
'org-agenda-mode
)
2141 ;; Keep global-font-lock-mode from turning on font-lock-mode
2142 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
2143 (setq mode-name
"Org-Agenda")
2144 (use-local-map org-agenda-mode-map
)
2145 (easy-menu-add org-agenda-menu
)
2146 (if org-startup-truncated
(setq truncate-lines t
))
2147 (org-set-local 'line-move-visual nil
)
2148 (org-add-hook 'post-command-hook
'org-agenda-update-agenda-type nil
'local
)
2149 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
2150 ;; Make sure properties are removed when copying text
2151 (org-add-hook 'filter-buffer-substring-functions
2152 (lambda (fun start end delete
)
2153 (substring-no-properties (funcall fun start end delete
)))
2155 (unless org-agenda-keep-modes
2156 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2157 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2158 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2159 org-agenda-show-log org-agenda-start-with-log-mode
))
2162 '("Agenda") "Agenda Files"
2166 (if (get 'org-agenda-files
'org-restrict
)
2167 "Restricted to single file"
2169 '(org-edit-agenda-file-list)
2170 (not (get 'org-agenda-files
'org-restrict
)))
2172 (mapcar 'org-file-menu-entry
(org-agenda-files))))
2173 (org-agenda-set-mode-name)
2175 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
2176 (list 'org-agenda-mode-hook
)))
2178 (substitute-key-definition 'undo
'org-agenda-undo
2179 org-agenda-mode-map global-map
)
2180 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
2181 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
2182 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
2183 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
2184 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
2185 (org-defkey org-agenda-mode-map
[(meta down
)] 'org-agenda-drag-line-forward
)
2186 (org-defkey org-agenda-mode-map
[(meta up
)] 'org-agenda-drag-line-backward
)
2187 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
2188 (org-defkey org-agenda-mode-map
"\M-m" 'org-agenda-bulk-toggle
)
2189 (org-defkey org-agenda-mode-map
"*" 'org-agenda-bulk-mark-all
)
2190 (org-defkey org-agenda-mode-map
"\M-*" 'org-agenda-bulk-toggle-all
)
2191 (org-defkey org-agenda-mode-map
"#" 'org-agenda-dim-blocked-tasks
)
2192 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
2193 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
2194 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-unmark-all
)
2195 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
2196 (org-defkey org-agenda-mode-map
"k" 'org-agenda-capture
)
2197 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
2198 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
2199 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
2200 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
2201 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
2202 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
2203 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
2204 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
2205 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
2206 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
2207 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
2208 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2209 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2210 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2211 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2212 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2213 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2214 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2215 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2216 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2217 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2218 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2219 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2220 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2221 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2222 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2223 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2224 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2225 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2226 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2227 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2228 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2229 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2231 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2232 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2233 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2234 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2235 (while l (org-defkey org-agenda-mode-map
2236 (int-to-string (pop l)) 'digit-argument)))
2238 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2239 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2240 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2241 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2242 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2243 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2244 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2245 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2246 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2247 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2248 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2249 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2250 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2251 'org-clock-modify-effort-estimate)
2252 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2253 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2254 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2255 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2256 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2257 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2258 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2259 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2260 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2261 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2262 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2263 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2264 (substitute-key-definition 'next-line 'org-agenda-next-line
2265 org-agenda-mode-map global-map)
2266 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2267 org-agenda-mode-map global-map)
2268 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2269 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2270 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2271 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2272 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2273 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2274 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2275 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2276 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2277 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2278 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2279 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2280 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2281 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2282 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2283 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2284 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2285 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2286 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2287 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2288 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2289 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2290 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2291 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2292 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2293 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2294 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2295 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2296 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2297 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2299 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2300 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2301 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2302 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2303 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2304 (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
2305 (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
2306 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2307 (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
2308 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2309 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
2310 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2311 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2312 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2313 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2315 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2316 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2317 (when org-agenda-mouse-1-follows-link
2318 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2319 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2324 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2325 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2326 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2327 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2330 ["Day View" org-agenda-day-view
2331 :active (org-agenda-check-type nil 'agenda)
2332 :style radio :selected (eq org-agenda-current-span 'day)
2333 :keys "v d (or just d)"]
2334 ["Week View" org-agenda-week-view
2335 :active (org-agenda-check-type nil 'agenda)
2336 :style radio :selected (eq org-agenda-current-span 'week)
2337 :keys "v w (or just w)"]
2338 ["Month View" org-agenda-month-view
2339 :active (org-agenda-check-type nil 'agenda)
2340 :style radio :selected (eq org-agenda-current-span 'month)
2342 ["Year View" org-agenda-year-view
2343 :active (org-agenda-check-type nil 'agenda)
2344 :style radio :selected (eq org-agenda-current-span 'year)
2347 ["Include Diary" org-agenda-toggle-diary
2348 :style toggle :selected org-agenda-include-diary
2349 :active (org-agenda-check-type nil 'agenda)]
2350 ["Include Deadlines" org-agenda-toggle-deadlines
2351 :style toggle :selected org-agenda-include-deadlines
2352 :active (org-agenda-check-type nil 'agenda)]
2353 ["Use Time Grid" org-agenda-toggle-time-grid
2354 :style toggle :selected org-agenda-use-time-grid
2355 :active (org-agenda-check-type nil 'agenda)]
2357 ["Show clock report" org-agenda-clockreport-mode
2358 :style toggle :selected org-agenda-clockreport-mode
2359 :active (org-agenda-check-type nil 'agenda)]
2360 ["Show some entry text" org-agenda-entry-text-mode
2361 :style toggle :selected org-agenda-entry-text-mode
2364 ["Show Logbook entries" org-agenda-log-mode
2365 :style toggle :selected org-agenda-show-log
2366 :active (org-agenda-check-type nil 'agenda 'timeline)
2367 :keys "v l (or just l)"]
2368 ["Include archived trees" org-agenda-archives-mode
2369 :style toggle :selected org-agenda-archives-mode :active t
2371 ["Include archive files" (org-agenda-archives-mode t)
2372 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2375 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2376 ["Write view to file" org-agenda-write t]
2377 ["Rebuild buffer" org-agenda-redo t]
2378 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2380 ["Show original entry" org-agenda-show t]
2381 ["Go To (other window)" org-agenda-goto t]
2382 ["Go To (this window)" org-agenda-switch-to t]
2383 ["Capture with cursor date" org-agenda-capture t]
2384 ["Follow Mode" org-agenda-follow-mode
2385 :style toggle :selected org-agenda-follow-mode :active t]
2386 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2389 ["Cycle TODO" org-agenda-todo t]
2390 ["Next TODO set" org-agenda-todo-nextset t]
2391 ["Previous TODO set" org-agenda-todo-previousset t]
2392 ["Add note" org-agenda-add-note t])
2393 ("Archive/Refile/Delete"
2394 ["Archive default" org-agenda-archive-default t]
2395 ["Archive default" org-agenda-archive-default-with-confirmation t]
2396 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2397 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2398 ["Archive subtree" org-agenda-archive t]
2400 ["Refile" org-agenda-refile t]
2402 ["Delete subtree" org-agenda-kill t])
2404 ["Mark entry" org-agenda-bulk-mark t]
2405 ["Mark all" org-agenda-bulk-mark-all t]
2406 ["Unmark entry" org-agenda-bulk-unmark t]
2407 ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
2408 ["Toggle mark" org-agenda-bulk-toggle t]
2409 ["Toggle all" org-agenda-bulk-toggle-all t]
2410 ["Mark regexp" org-agenda-bulk-mark-regexp t])
2411 ["Act on all marked" org-agenda-bulk-action t]
2413 ("Tags and Properties"
2414 ["Show all Tags" org-agenda-show-tags t]
2415 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2416 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2418 ["Column View" org-columns t])
2419 ("Deadline/Schedule"
2420 ["Schedule" org-agenda-schedule t]
2421 ["Set Deadline" org-agenda-deadline t]
2423 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2424 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2425 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2426 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2427 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2428 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2429 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2431 ["Clock in" org-agenda-clock-in t]
2432 ["Clock out" org-agenda-clock-out t]
2433 ["Clock cancel" org-agenda-clock-cancel t]
2434 ["Goto running clock" org-clock-goto t]
2436 ["Set Effort" org-agenda-set-effort t]
2437 ["Change clocked effort" org-clock-modify-effort-estimate
2438 (org-clock-is-active)])
2440 ["Set Priority" org-agenda-priority t]
2441 ["Increase Priority" org-agenda-priority-up t]
2442 ["Decrease Priority" org-agenda-priority-down t]
2443 ["Show Priority" org-show-priority t])
2445 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2446 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2447 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2448 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2449 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2450 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2452 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2454 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2457 ["Push Files and Views" org-mobile-push t]
2458 ["Get Captured and Flagged" org-mobile-pull t]
2459 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2460 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2462 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2464 ["Quit" org-agenda-quit t]
2465 ["Exit and Release Buffers" org-agenda-exit t]
2470 (defvar org-agenda-allow-remote-undo t
2471 "Non-nil means allow remote undo from the agenda buffer.")
2472 (defvar org-agenda-undo-has-started-in nil
2473 "Buffers that have already seen `undo-start' in the current undo sequence.")
2475 (defun org-agenda-undo ()
2476 "Undo a remote editing step in the agenda.
2477 This undoes changes both in the agenda buffer and in the remote buffer
2478 that have been changed along."
2480 (or org-agenda-allow-remote-undo
2481 (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2482 (if (not (eq this-command last-command))
2483 (setq org-agenda-undo-has-started-in nil
2484 org-agenda-pending-undo-list org-agenda-undo-list))
2485 (if (not org-agenda-pending-undo-list)
2486 (user-error "No further undo information"))
2487 (let* ((entry (pop org-agenda-pending-undo-list))
2488 buf line cmd rembuf)
2489 (setq cmd (pop entry) line (pop entry))
2490 (setq rembuf (nth 2 entry))
2491 (org-with-remote-undo rembuf
2492 (while (bufferp (setq buf (pop entry)))
2494 (with-current-buffer buf
2495 (let ((last-undo-buffer buf)
2496 (inhibit-read-only t))
2497 (unless (memq buf org-agenda-undo-has-started-in)
2498 (push buf org-agenda-undo-has-started-in)
2499 (make-local-variable 'pending-undo-list)
2501 (while (and pending-undo-list
2502 (listp pending-undo-list)
2503 (not (car pending-undo-list)))
2504 (pop pending-undo-list))
2506 (org-goto-line line)
2507 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2509 (defun org-verify-change-for-undo (l1 l2)
2510 "Verify that a real change occurred between the undo lists L1 and L2."
2511 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2512 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2517 (defvar org-agenda-restrict-begin (make-marker))
2518 (defvar org-agenda-restrict-end (make-marker))
2519 (defvar org-agenda-last-dispatch-buffer nil)
2520 (defvar org-agenda-overriding-restriction nil)
2522 (defcustom org-agenda-custom-commands-contexts nil
2523 "Alist of custom agenda keys and contextual rules.
2525 For example, if you have a custom agenda command \"p\" and you
2526 want this command to be accessible only from plain text files,
2529 '((\"p\" ((in-file . \"\\.txt\"))))
2531 Here are the available contexts definitions:
2533 in-file: command displayed only in matching files
2534 in-mode: command displayed only in matching modes
2535 not-in-file: command not displayed in matching files
2536 not-in-mode: command not displayed in matching modes
2537 in-buffer: command displayed only in matching buffers
2538 not-in-buffer: command not displayed in matching buffers
2539 [function]: a custom function taking no argument
2541 If you define several checks, the agenda command will be
2542 accessible if there is at least one valid check.
2544 You can also bind a key to another agenda custom command
2545 depending on contextual rules.
2547 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2549 Here it means: in .txt files, use \"p\" as the key for the
2550 agenda command otherwise associated with \"q\". (The command
2551 originally associated with \"q\" is not displayed to avoid
2554 :group 'org-agenda-custom-commands
2555 :type '(repeat (list :tag "Rule"
2556 (string :tag " Agenda key")
2557 (string :tag "Replace by command")
2558 (repeat :tag "Available when"
2560 (cons :tag "Condition"
2562 (const :tag "In file" in-file)
2563 (const :tag "Not in file" not-in-file)
2564 (const :tag "In buffer" in-buffer)
2565 (const :tag "Not in buffer" not-in-buffer)
2566 (const :tag "In mode" in-mode)
2567 (const :tag "Not in mode" not-in-mode))
2569 (function :tag "Custom function"))))))
2571 (defcustom org-agenda-max-entries nil
2572 "Maximum number of entries to display in an agenda.
2573 This can be nil (no limit) or an integer or an alist of agenda
2574 types with an associated number of entries to display in this
2577 :package-version '(Org . "8.0")
2578 :group 'org-agenda-custom-commands
2579 :type '(choice (symbol :tag "No limit" nil)
2580 (integer :tag "Max number of entries")
2582 (cons (choice :tag "Agenda type"
2588 (integer :tag "Max number of entries")))))
2590 (defcustom org-agenda-max-todos nil
2591 "Maximum number of TODOs to display in an agenda.
2592 This can be nil (no limit) or an integer or an alist of agenda
2593 types with an associated number of entries to display in this
2596 :package-version '(Org . "8.0")
2597 :group 'org-agenda-custom-commands
2598 :type '(choice (symbol :tag "No limit" nil)
2599 (integer :tag "Max number of entries")
2601 (cons (choice :tag "Agenda type"
2607 (integer :tag "Max number of entries")))))
2609 (defcustom org-agenda-max-tags nil
2610 "Maximum number of tagged entries to display in an agenda.
2611 This can be nil (no limit) or an integer or an alist of agenda
2612 types with an associated number of entries to display in this
2615 :package-version '(Org . "8.0")
2616 :group 'org-agenda-custom-commands
2617 :type '(choice (symbol :tag "No limit" nil)
2618 (integer :tag "Max number of entries")
2620 (cons (choice :tag "Agenda type"
2626 (integer :tag "Max number of entries")))))
2628 (defcustom org-agenda-max-effort nil
2629 "Maximum cumulated effort duration for the agenda.
2630 This can be nil (no limit) or a number of minutes (as an integer)
2631 or an alist of agenda types with an associated number of minutes
2632 to limit entries to in this type."
2634 :package-version '(Org . "8.0")
2635 :group 'org-agenda-custom-commands
2636 :type '(choice (symbol :tag "No limit" nil)
2637 (integer :tag "Max number of entries")
2639 (cons (choice :tag "Agenda type"
2645 (integer :tag "Max number of entries")))))
2647 (defvar org-keys nil)
2648 (defvar org-match nil)
2650 (defun org-agenda (&optional arg org-keys restriction)
2651 "Dispatch agenda commands to collect entries to the agenda buffer.
2652 Prompts for a command to execute. Any prefix arg will be passed
2653 on to the selected command. The default selections are:
2655 a Call `org-agenda-list' to display the agenda for current day or week.
2656 t Call `org-todo-list' to display the global todo list.
2657 T Call `org-todo-list' to display the global todo list, select only
2658 entries with a specific TODO keyword (the user gets a prompt).
2659 m Call `org-tags-view' to display headlines with tags matching
2660 a condition (the user is prompted for the condition).
2661 M Like `m', but select only TODO entries, no ordinary headlines.
2662 L Create a timeline for the current buffer.
2663 e Export views to associated files.
2664 s Search entries for keywords.
2665 S Search entries for keywords, only with TODO keywords.
2666 / Multi occur across all agenda files and also files listed
2667 in `org-agenda-text-search-extra-files'.
2668 < Restrict agenda commands to buffer, subtree, or region.
2669 Press several times to get the desired effect.
2670 > Remove a previous restriction.
2671 # List \"stuck\" projects.
2672 ! Configure what \"stuck\" means.
2673 C Configure custom agenda commands.
2675 More commands can be added by configuring the variable
2676 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2677 searches can be pre-defined in this way.
2679 If the current buffer is in Org-mode and visiting a file, you can also
2680 first press `<' once to indicate that the agenda should be temporarily
2681 \(until the next use of \\[org-agenda]) restricted to the current file.
2682 Pressing `<' twice means to restrict to the current subtree or region
2686 (let* ((prefix-descriptions nil)
2687 (org-agenda-buffer-name org-agenda-buffer-name)
2688 (org-agenda-window-setup (if (equal (buffer-name)
2689 org-agenda-buffer-name)
2691 org-agenda-window-setup))
2692 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2693 (org-agenda-custom-commands
2694 ;; normalize different versions
2698 (cond ((stringp (cdr x))
2699 (push x prefix-descriptions)
2701 ((stringp (nth 1 x)) x)
2702 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2703 (t (cons (car x) (cons "" (cdr x))))))
2704 org-agenda-custom-commands)))
2705 (org-agenda-custom-commands
2706 (org-contextualize-keys
2707 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2708 (buf (current-buffer))
2709 (bfn (buffer-file-name (buffer-base-buffer)))
2710 entry key type org-match lprops ans)
2711 ;; Turn off restriction unless there is an overriding one,
2712 (unless org-agenda-overriding-restriction
2713 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2714 ;; There is a request to keep the file list in place
2715 (put 'org-agenda-files 'org-restrict nil))
2716 (setq org-agenda-restrict nil)
2717 (move-marker org-agenda-restrict-begin nil)
2718 (move-marker org-agenda-restrict-end nil))
2719 ;; Delete old local properties
2720 (put 'org-agenda-redo-command 'org-lprops nil)
2721 ;; Delete previously set last-arguments
2722 (put 'org-agenda-redo-command 'last-args nil)
2723 ;; Remember where this call originated
2724 (setq org-agenda-last-dispatch-buffer (current-buffer))
2726 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2728 restriction (cdr ans)))
2729 ;; If we have sticky agenda buffers, set a name for the buffer,
2730 ;; depending on the invoking keys. The user may still set this
2731 ;; as a command option, which will overwrite what we do here.
2732 (if org-agenda-sticky
2733 (setq org-agenda-buffer-name
2734 (format "*Org Agenda(%s)*" org-keys)))
2735 ;; Establish the restriction, if any
2736 (when (and (not org-agenda-overriding-restriction) restriction)
2737 (put 'org-agenda-files 'org-restrict (list bfn))
2739 ((eq restriction 'region)
2740 (setq org-agenda-restrict (current-buffer))
2741 (move-marker org-agenda-restrict-begin (region-beginning))
2742 (move-marker org-agenda-restrict-end (region-end)))
2743 ((eq restriction 'subtree)
2745 (setq org-agenda-restrict (current-buffer))
2746 (org-back-to-heading t)
2747 (move-marker org-agenda-restrict-begin (point))
2748 (move-marker org-agenda-restrict-end
2749 (progn (org-end-of-subtree t)))))))
2751 ;; For example the todo list should not need it (but does...)
2753 ((setq entry (assoc org-keys org-agenda-custom-commands))
2754 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2756 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2757 lprops (nth 4 entry))
2758 (if org-agenda-sticky
2759 (setq org-agenda-buffer-name
2760 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2761 (format "*Org Agenda(%s)*" org-keys))))
2762 (put 'org-agenda-redo-command 'org-lprops lprops)
2765 (org-let lprops '(org-agenda-list current-prefix-arg)))
2767 (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
2769 (org-let lprops '(org-todo-list current-prefix-arg)))
2771 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2773 (org-let lprops '(org-agenda-list-stuck-projects
2774 current-prefix-arg)))
2776 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2777 ((eq type 'tags-todo)
2778 (org-let lprops '(org-tags-view '(4) org-match)))
2780 (org-let lprops '(org-todo-list org-match)))
2781 ((eq type 'tags-tree)
2782 (org-check-for-org-mode)
2783 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2784 ((eq type 'todo-tree)
2785 (org-check-for-org-mode)
2787 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2788 (regexp-quote org-match) "\\>"))))
2789 ((eq type 'occur-tree)
2790 (org-check-for-org-mode)
2791 (org-let lprops '(org-occur org-match)))
2793 (org-let lprops '(funcall type org-match)))
2795 (org-let lprops '(funcall type org-match)))
2796 (t (user-error "Invalid custom agenda command type %s" type))))
2797 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2798 ((equal org-keys "C")
2799 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2800 (customize-variable 'org-agenda-custom-commands))
2801 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2802 ((equal org-keys "s") (call-interactively 'org-search-view))
2803 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2804 ((equal org-keys "t") (call-interactively 'org-todo-list))
2805 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2806 ((equal org-keys "m") (call-interactively 'org-tags-view))
2807 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2808 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2809 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2813 (unless (current-message)
2814 (let* ((m (org-agenda-get-any-marker))
2815 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2818 "FLAGGING-NOTE ([?] for more info): "
2820 (replace-regexp-in-string
2822 (copy-sequence note))
2823 nil 'face 'org-warning)))))))
2825 ((equal org-keys "L")
2826 (unless (derived-mode-p 'org-mode)
2827 (user-error "This is not an Org-mode file"))
2829 (put 'org-agenda-files 'org-restrict (list bfn))
2830 (org-call-with-arg 'org-timeline arg)))
2831 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2832 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2833 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2834 (t (user-error "Invalid agenda key"))))))
2836 (defun org-agenda-append-agenda ()
2837 "Append another agenda view to the current one.
2838 This function allows interactive building of block agendas.
2839 Agenda views are separated by `org-agenda-block-separator'."
2841 (unless (derived-mode-p 'org-agenda-mode)
2842 (user-error "Can only append from within agenda buffer"))
2843 (let ((org-agenda-multi t))
2846 (org-agenda-finalize)
2847 (setq buffer-read-only t)
2848 (org-agenda-fit-window-to-buffer)))
2850 (defun org-agenda-normalize-custom-commands (cmds)
2851 "Normalize custom commands CMDS."
2855 (cond ((stringp (cdr x)) nil)
2856 ((stringp (nth 1 x)) x)
2857 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2858 (t (cons (car x) (cons "" (cdr x))))))
2861 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2862 "The user interface for selecting an agenda command."
2864 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2865 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2866 (region-p (org-region-active-p))
2867 (custom org-agenda-custom-commands)
2869 restriction second-time
2870 c entry key type match prefixes rmheader header-end custom1 desc
2871 line lines left right n n1)
2872 (save-window-excursion
2873 (delete-other-windows)
2874 (org-switch-to-buffer-other-window " *Agenda Commands*")
2876 (insert (eval-when-compile
2878 "Press key for an agenda command: < Buffer, subtree/region restriction
2879 -------------------------------- > Remove restriction
2880 a Agenda for current week or day e Export agenda views
2881 t List of all TODO entries T Entries with special TODO kwd
2882 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2883 s Search for keywords S Like s, but only TODO entries
2884 L Timeline for current buffer # List stuck projects (!=configure)
2885 / Multi-occur C Configure custom agenda commands
2886 ? Find :FLAGGED: entries * Toggle sticky agenda views
2889 (while (string-match
2890 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2892 (setq start (match-end 0))
2893 (add-text-properties (match-beginning 2) (match-end 2)
2894 '(face bold) header))
2896 (setq header-end (point-marker))
2898 (setq custom1 custom)
2899 (when (eq rmheader t)
2901 (re-search-forward ":" nil t)
2902 (delete-region (match-end 0) (point-at-eol))
2905 (delete-region (match-end 0) (point-at-eol))
2906 (move-marker header-end (match-end 0)))
2907 (goto-char header-end)
2908 (delete-region (point) (point-max))
2910 ;; Produce all the lines that describe custom commands and prefixes
2912 (while (setq entry (pop custom1))
2913 (setq key (car entry) desc (nth 1 entry)
2915 match (nth 3 entry))
2916 (if (> (length key) 1)
2917 (add-to-list 'prefixes (string-to-char key))
2921 (org-add-props (copy-sequence key)
2924 ((string-match "\\S-" desc) desc)
2925 ((eq type 'agenda) "Agenda for current week or day")
2926 ((eq type 'agenda*) "Appointments for current week or day")
2927 ((eq type 'alltodo) "List of all TODO entries")
2928 ((eq type 'search) "Word search")
2929 ((eq type 'stuck) "List of stuck projects")
2930 ((eq type 'todo) "TODO keyword")
2931 ((eq type 'tags) "Tags query")
2932 ((eq type 'tags-todo) "Tags (TODO)")
2933 ((eq type 'tags-tree) "Tags tree")
2934 ((eq type 'todo-tree) "TODO kwd tree")
2935 ((eq type 'occur-tree) "Occur tree")
2936 ((functionp type) (if (symbolp type)
2938 "Lambda expression"))
2940 (if org-agenda-menu-show-matcher
2945 (setq match (copy-sequence match))
2946 (org-add-props match nil 'face 'org-warning))
2948 (format "set of %d commands" (length type))))))
2949 (if (org-string-nw-p match)
2950 (add-text-properties
2951 0 (length line) (list 'help-echo
2952 (concat "Matcher: " match)) line)))
2954 (setq lines (nreverse lines))
2959 (org-add-props (char-to-string x)
2961 (or (cdr (assoc (concat selstring
2963 prefix-descriptions))
2968 ;; Check if we should display in two columns
2969 (if org-agenda-menu-two-columns
2971 (setq n (length lines)
2972 n1 (+ (/ n 2) (mod n 2))
2973 right (nthcdr n1 lines)
2974 left (copy-sequence lines))
2975 (setcdr (nthcdr (1- n1) left) nil))
2976 (setq left lines right nil))
2978 (insert "\n" (pop left))
2980 (if (< (current-column) 40)
2981 (move-to-column 40 t)
2983 (insert (pop right))))
2985 ;; Make the window the right size
2986 (goto-char (point-min))
2988 (if (not (pos-visible-in-window-p (point-max)))
2989 (org-fit-window-to-buffer))
2990 (setq second-time t)
2991 (org-fit-window-to-buffer))
2993 ;; Ask for selection
2994 (message "Press key for agenda command%s:"
2995 (if (or restrict-ok org-agenda-overriding-restriction)
2996 (if org-agenda-overriding-restriction
2997 " (restriction lock active)"
2999 (format " (restricted to %s)" restriction)
3002 (setq c (read-char-exclusive))
3005 ((assoc (char-to-string c) custom)
3006 (setq selstring (concat selstring (char-to-string c)))
3007 (throw 'exit (cons selstring restriction)))
3009 (setq selstring (concat selstring (char-to-string c))
3011 rmheader (or rmheader t)
3012 custom (delq nil (mapcar
3014 (if (or (= (length (car x)) 1)
3015 (/= (string-to-char (car x)) c))
3017 (cons (substring (car x) 1) (cdr x))))
3020 (call-interactively 'org-toggle-sticky-agenda)
3022 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
3023 (message "Restriction is only possible in Org-mode buffers")
3026 (org-agenda-remove-restriction-lock 'noupdate)
3027 (setq restriction 'buffer))
3029 (org-agenda-remove-restriction-lock 'noupdate)
3030 (setq restriction (if region-p 'region 'subtree)))
3032 (org-agenda-remove-restriction-lock 'noupdate)
3035 ((eq restriction 'buffer)
3036 (if region-p 'region 'subtree))
3037 ((memq restriction '(subtree region))
3041 (org-agenda-remove-restriction-lock 'noupdate)
3042 (setq restriction nil))
3043 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
3044 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
3045 ((and (> (length selstring) 0) (eq c ?\d))
3047 (org-agenda-get-restriction-and-command prefix-descriptions))
3049 ((equal c ?q) (error "Abort"))
3050 (t (user-error "Invalid key %c" c))))))))
3052 (defun org-agenda-fit-window-to-buffer ()
3053 "Fit the window to the buffer size."
3054 (and (memq org-agenda-window-setup '(reorganize-frame))
3055 (fboundp 'fit-window-to-buffer)
3056 (org-fit-window-to-buffer
3058 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3059 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3061 (defvar org-cmd nil)
3062 (defvar org-agenda-overriding-cmd nil)
3063 (defvar org-agenda-overriding-arguments nil)
3064 (defvar org-agenda-overriding-cmd-arguments nil)
3065 (defun org-agenda-run-series (name series)
3066 "Run agenda NAME as a SERIES of agenda commands."
3067 (org-let (nth 1 series) '(org-agenda-prepare name))
3068 ;; We need to reset agenda markers here, because when constructing a
3069 ;; block agenda, the individual blocks do not do that.
3070 (org-agenda-reset-markers)
3071 (let* ((org-agenda-multi t)
3072 (redo (list 'org-agenda-run-series name (list 'quote series)))
3074 (gprops (nth 1 series))
3075 match ;; The byte compiler incorrectly complains about this. Keep it!
3076 org-cmd type lprops)
3077 (while (setq org-cmd (pop cmds))
3078 (setq type (car org-cmd)
3079 match (eval (nth 1 org-cmd))
3080 lprops (nth 2 org-cmd))
3081 (let ((org-agenda-overriding-arguments
3082 (if (eq org-agenda-overriding-cmd org-cmd)
3083 (or org-agenda-overriding-arguments
3084 org-agenda-overriding-cmd-arguments))))
3087 (org-let2 gprops lprops
3088 '(call-interactively 'org-agenda-list)))
3090 (org-let2 gprops lprops
3091 '(funcall 'org-agenda-list nil nil t)))
3093 (org-let2 gprops lprops
3094 '(call-interactively 'org-todo-list)))
3096 (org-let2 gprops lprops
3097 '(org-search-view current-prefix-arg match nil)))
3099 (org-let2 gprops lprops
3100 '(call-interactively 'org-agenda-list-stuck-projects)))
3102 (org-let2 gprops lprops
3103 '(org-tags-view current-prefix-arg match)))
3104 ((eq type 'tags-todo)
3105 (org-let2 gprops lprops
3106 '(org-tags-view '(4) match)))
3108 (org-let2 gprops lprops
3109 '(org-todo-list match)))
3111 (org-let2 gprops lprops
3112 '(funcall type match)))
3113 (t (error "Invalid type in command series")))))
3115 (let ((inhibit-read-only t))
3116 (add-text-properties (point-min) (point-max)
3117 `(org-series t org-series-redo-cmd ,redo)))
3118 (setq org-agenda-redo-command redo)
3119 (goto-char (point-min)))
3120 (org-agenda-fit-window-to-buffer)
3121 (org-let (nth 1 series) '(org-agenda-finalize)))
3124 (defmacro org-batch-agenda (cmd-key &rest parameters)
3125 "Run an agenda command in batch mode and send the result to STDOUT.
3126 If CMD-KEY is a string of length 1, it is used as a key in
3127 `org-agenda-custom-commands' and triggers this command. If it is a
3128 longer string it is used as a tags/todo match string.
3129 Parameters are alternating variable names and values that will be bound
3130 before running the agenda command."
3131 (org-eval-in-environment (org-make-parameter-alist parameters)
3132 (let (org-agenda-sticky)
3133 (if (> (length cmd-key) 2)
3134 (org-tags-view nil cmd-key)
3135 (org-agenda nil cmd-key))))
3136 (set-buffer org-agenda-buffer-name)
3137 (princ (buffer-string)))
3139 (defvar org-agenda-info nil)
3142 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3143 "Run an agenda command in batch mode and send the result to STDOUT.
3144 If CMD-KEY is a string of length 1, it is used as a key in
3145 `org-agenda-custom-commands' and triggers this command. If it is a
3146 longer string it is used as a tags/todo match string.
3147 Parameters are alternating variable names and values that will be bound
3148 before running the agenda command.
3150 The output gives a line for each selected agenda item. Each
3151 item is a list of comma-separated values, like this:
3153 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3155 category The category of the item
3156 head The headline, without TODO kwd, TAGS and PRIORITY
3157 type The type of the agenda entry, can be
3158 todo selected in TODO match
3159 tagsmatch selected in tags match
3160 diary imported from diary
3161 deadline a deadline on given date
3162 scheduled scheduled on given date
3163 timestamp entry has timestamp on given date
3164 closed entry was closed on given date
3165 upcoming-deadline warning about deadline
3166 past-scheduled forwarded scheduled item
3167 block entry has date block including g. date
3168 todo The todo keyword, if any
3169 tags All tags including inherited ones, separated by colons
3170 date The relevant date, like 2007-2-14
3171 time The time, like 15:00-16:50
3172 extra Sting with extra planning info
3173 priority-l The priority letter if any was given
3174 priority-n The computed numerical priority
3175 agenda-day The day in the agenda where this is listed"
3176 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3177 (org-make-parameter-alist parameters))
3178 (if (> (length cmd-key) 2)
3179 (org-tags-view nil cmd-key)
3180 (org-agenda nil cmd-key)))
3181 (set-buffer org-agenda-buffer-name)
3182 (let* ((lines (org-split-string (buffer-string) "\n"))
3184 (while (setq line (pop lines))
3186 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3187 (setq org-agenda-info
3188 (org-fix-agenda-info (text-properties-at 0 line)))
3190 (mapconcat 'org-agenda-export-csv-mapper
3191 '(org-category txt type todo tags date time extra
3192 priority-letter priority agenda-day)
3196 (defun org-fix-agenda-info (props)
3197 "Make sure all properties on an agenda item have a canonical form.
3198 This ensures the export commands can easily use it."
3200 (when (setq tmp (plist-get props 'tags))
3201 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3202 (when (setq tmp (plist-get props 'date))
3203 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3204 (let ((calendar-date-display-form '(year "-" month "-" day)))
3205 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3207 (setq tmp (calendar-date-string tmp)))
3208 (setq props (plist-put props 'date tmp)))
3209 (when (setq tmp (plist-get props 'day))
3210 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3211 (let ((calendar-date-display-form '(year "-" month "-" day)))
3212 (setq tmp (calendar-date-string tmp)))
3213 (setq props (plist-put props 'day tmp))
3214 (setq props (plist-put props 'agenda-day tmp)))
3215 (when (setq tmp (plist-get props 'txt))
3216 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3217 (plist-put props 'priority-letter (match-string 1 tmp))
3218 (setq tmp (replace-match "" t t tmp)))
3219 (when (and (setq re (plist-get props 'org-todo-regexp))
3220 (setq re (concat "\\`\\.*" re " ?"))
3221 (string-match re tmp))
3222 (plist-put props 'todo (match-string 1 tmp))
3223 (setq tmp (replace-match "" t t tmp)))
3224 (plist-put props 'txt tmp)))
3227 (defun org-agenda-export-csv-mapper (prop)
3228 (let ((res (plist-get org-agenda-info prop)))
3233 (t (prin1-to-string res))))
3234 (while (string-match "," res)
3235 (setq res (replace-match ";" t t res)))
3239 (defun org-store-agenda-views (&rest parameters)
3240 "Store agenda views."
3242 (eval (list 'org-batch-store-agenda-views)))
3245 (defmacro org-batch-store-agenda-views (&rest parameters)
3246 "Run all custom agenda commands that have a file argument."
3247 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3249 (dir default-directory)
3250 (pars (org-make-parameter-alist parameters))
3251 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3252 (save-window-excursion
3254 (setq cmd (pop cmds)
3255 thiscmdkey (car cmd)
3256 thiscmdcmd (cdr cmd)
3257 match (nth 2 thiscmdcmd)
3258 bufname (if org-agenda-sticky
3259 (or (and (stringp match)
3260 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3261 (format "*Org Agenda(%s)*" thiscmdkey))
3262 org-agenda-buffer-name)
3263 cmd-or-set (nth 2 cmd)
3264 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3265 files (nth (if (listp cmd-or-set) 4 5) cmd))
3266 (if (stringp files) (setq files (list files)))
3268 (org-eval-in-environment (append org-agenda-exporter-settings
3270 (org-agenda nil thiscmdkey))
3271 (set-buffer bufname)
3273 (org-eval-in-environment (append org-agenda-exporter-settings
3275 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3276 (and (get-buffer bufname)
3277 (kill-buffer bufname)))))))
3279 (defvar org-agenda-current-span nil
3280 "The current span used in the agenda view.") ; local variable in the agenda buffer
3281 (defun org-agenda-mark-header-line (pos)
3282 "Mark the line at POS as an agenda structure header."
3285 (put-text-property (point-at-bol) (point-at-eol)
3286 'org-agenda-structural-header t)
3287 (when org-agenda-title-append
3288 (put-text-property (point-at-bol) (point-at-eol)
3289 'org-agenda-title-append org-agenda-title-append))))
3291 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3292 (defvar org-agenda-write-buffer-name "Agenda View")
3293 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3294 "Write the current buffer (an agenda view) as a file.
3295 Depending on the extension of the file name, plain text (.txt),
3296 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3297 If the extension is .ics, run icalendar export over all files used
3298 to construct the agenda and limit the export to entries listed in the
3300 If the extension is .org, collect all subtrees corresponding to the
3301 agenda entries and add them in an .org file.
3302 With prefix argument OPEN, open the new file immediately.
3303 If NOSETTINGS is given, do not scope the settings of
3304 `org-agenda-exporter-settings' into the export commands. This is used when
3305 the settings have already been scoped and we do not wish to overrule other,
3306 higher priority settings.
3307 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3308 (interactive "FWrite agenda to file: \nP")
3309 (if (or (not (file-writable-p file))
3310 (and (file-exists-p file)
3311 (if (org-called-interactively-p 'any)
3312 (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
3313 (user-error "Cannot write agenda to file %s" file))
3314 (org-let (if nosettings nil org-agenda-exporter-settings)
3316 (save-window-excursion
3317 (org-agenda-mark-filtered-text)
3318 (let ((bs (copy-sequence (buffer-string))) beg content)
3319 (org-agenda-unmark-filtered-text)
3321 (rename-buffer org-agenda-write-buffer-name t)
3322 (set-buffer-modified-p nil)
3324 (org-agenda-remove-marked-text 'org-filtered)
3325 (while (setq beg (text-property-any (point-min) (point-max)
3328 beg (or (next-single-property-change beg 'org-filtered)
3330 (run-hooks 'org-agenda-before-write-hook)
3332 ((org-bound-and-true-p org-mobile-creating-agendas)
3333 (org-mobile-write-agenda-for-mobile file))
3334 ((string-match "\\.org\\'" file)
3335 (let (content p m message-log-max)
3336 (goto-char (point-min))
3337 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3339 (setq m (get-text-property (point) 'org-hd-marker))
3341 (push (save-excursion
3342 (set-buffer (marker-buffer m))
3344 (org-copy-subtree 1 nil t t)
3349 (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
3351 (kill-buffer (current-buffer))
3352 (message "Org file written to %s" file)))
3353 ((string-match "\\.html?\\'" file)
3355 (set-buffer (htmlize-buffer (current-buffer)))
3356 (when org-agenda-export-html-style
3357 ;; replace <style> section with org-agenda-export-html-style
3358 (goto-char (point-min))
3359 (kill-region (- (search-forward "<style") 6)
3360 (search-forward "</style>"))
3361 (insert org-agenda-export-html-style))
3363 (kill-buffer (current-buffer))
3364 (message "HTML written to %s" file))
3365 ((string-match "\\.ps\\'" file)
3367 (ps-print-buffer-with-faces file)
3368 (message "Postscript written to %s" file))
3369 ((string-match "\\.pdf\\'" file)
3371 (ps-print-buffer-with-faces
3372 (concat (file-name-sans-extension file) ".ps"))
3373 (call-process "ps2pdf" nil nil nil
3375 (concat (file-name-sans-extension file) ".ps"))
3376 (expand-file-name file))
3377 (delete-file (concat (file-name-sans-extension file) ".ps"))
3378 (message "PDF written to %s" file))
3379 ((string-match "\\.ics\\'" file)
3380 (require 'ox-icalendar)
3381 (org-icalendar-export-current-agenda (expand-file-name file)))
3383 (let ((bs (buffer-string)))
3388 (kill-buffer (current-buffer))
3389 (message "Plain text written to %s" file))))))))
3390 (set-buffer (or agenda-bufname
3391 (and (org-called-interactively-p 'any) (buffer-name))
3392 org-agenda-buffer-name)))
3393 (when open (org-open-file file)))
3395 (defvar org-agenda-tag-filter-overlays nil)
3396 (defvar org-agenda-cat-filter-overlays nil)
3397 (defvar org-agenda-re-filter-overlays nil)
3399 (defun org-agenda-mark-filtered-text ()
3400 "Mark all text hidden by filtering with a text property."
3401 (let ((inhibit-read-only t))
3404 (when (equal (overlay-buffer o) (current-buffer))
3406 (overlay-start o) (overlay-end o)
3408 (append org-agenda-tag-filter-overlays
3409 org-agenda-cat-filter-overlays
3410 org-agenda-re-filter-overlays))))
3412 (defun org-agenda-unmark-filtered-text ()
3413 "Remove the filtering text property."
3414 (let ((inhibit-read-only t))
3415 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3417 (defun org-agenda-remove-marked-text (property &optional value)
3418 "Delete all text marked with VALUE of PROPERTY.
3419 VALUE defaults to t."
3421 (setq value (or value t))
3422 (while (setq beg (text-property-any (point-min) (point-max)
3425 beg (or (next-single-property-change beg 'org-filtered)
3428 (defun org-agenda-add-entry-text ()
3429 "Add entry text to agenda lines.
3430 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3431 entry text following headings shown in the agenda.
3432 Drawers will be excluded, also the line with scheduling/deadline info."
3433 (when (and (> org-agenda-add-entry-text-maxlines 0)
3434 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3436 (goto-char (point-min))
3438 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3439 (beginning-of-line 2)
3440 (setq txt (org-agenda-get-some-entry-text
3441 m org-agenda-add-entry-text-maxlines " > "))
3443 (if (string-match "\\S-" txt)
3445 (or (eobp) (forward-char 1))))))))
3447 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3449 "Extract entry text from MARKER, at most N-LINES lines.
3450 This will ignore drawers etc, just get the text.
3451 If INDENT is given, prefix every line with this string. If KEEP is
3452 given, it is a list of symbols, defining stuff that should not be
3453 removed from the entry content. Currently only `planning' is allowed here."
3454 (let (txt drawer-re kwd-time-re ind)
3456 (with-current-buffer (marker-buffer marker)
3457 (if (not (derived-mode-p 'org-mode))
3464 (setq txt (buffer-substring
3465 (min (1+ (point)) (point-max))
3466 (progn (outline-next-heading) (point)))
3467 drawer-re org-drawer-regexp
3468 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3472 (when org-agenda-add-entry-text-descriptive-links
3473 (goto-char (point-min))
3474 (while (org-activate-bracket-links (point-max))
3475 (add-text-properties (match-beginning 0) (match-end 0)
3477 (goto-char (point-min))
3478 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3479 (set-text-properties (match-beginning 0) (match-end 0)
3481 (goto-char (point-min))
3482 (while (re-search-forward drawer-re nil t)
3485 (progn (re-search-forward
3486 "^[ \t]*:END:.*\n?" nil 'move)
3488 (unless (member 'planning keep)
3489 (goto-char (point-min))
3490 (while (re-search-forward kwd-time-re nil t)
3491 (replace-match "")))
3492 (goto-char (point-min))
3493 (when org-agenda-entry-text-exclude-regexps
3494 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3495 (while (setq re (pop re-list))
3496 (goto-char (point-min))
3497 (while (re-search-forward re nil t)
3498 (replace-match "")))))
3499 (goto-char (point-max))
3500 (skip-chars-backward " \t\n")
3501 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3503 ;; find and remove min common indentation
3504 (goto-char (point-min))
3505 (untabify (point-min) (point-max))
3506 (setq ind (org-get-indentation))
3508 (unless (looking-at "[ \t]*$")
3509 (setq ind (min ind (org-get-indentation))))
3510 (beginning-of-line 2))
3511 (goto-char (point-min))
3513 (unless (looking-at "[ \t]*$")
3514 (move-to-column ind)
3515 (delete-region (point-at-bol) (point)))
3516 (beginning-of-line 2))
3518 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3520 (goto-char (point-min))
3522 (while (and (not (eobp)) (re-search-forward "^" nil t))
3523 (replace-match indent t t)))
3524 (goto-char (point-min))
3525 (while (looking-at "[ \t]*\n") (replace-match ""))
3526 (goto-char (point-max))
3527 (when (> (org-current-line)
3529 (org-goto-line (1+ n-lines))
3531 (setq txt (buffer-substring (point-min) (point)))))))))
3534 (defun org-check-for-org-mode ()
3535 "Make sure current buffer is in org-mode. Error if not."
3536 (or (derived-mode-p 'org-mode)
3537 (error "Cannot execute org-mode agenda command on buffer in %s"
3540 ;;; Agenda prepare and finalize
3542 (defvar org-agenda-multi nil) ; dynamically scoped
3543 (defvar org-agenda-pre-window-conf nil)
3544 (defvar org-agenda-columns-active nil)
3545 (defvar org-agenda-name nil)
3546 (defvar org-agenda-tag-filter nil)
3547 (defvar org-agenda-category-filter nil)
3548 (defvar org-agenda-regexp-filter nil)
3549 (defvar org-agenda-top-headline-filter nil)
3550 (defvar org-agenda-tag-filter-while-redo nil)
3551 (defvar org-agenda-tag-filter-preset nil
3552 "A preset of the tags filter used for secondary agenda filtering.
3553 This must be a list of strings, each string must be a single tag preceded
3555 This variable should not be set directly, but agenda custom commands can
3556 bind it in the options section. The preset filter is a global property of
3557 the entire agenda view. In a block agenda, it will not work reliably to
3558 define a filter for one of the individual blocks. You need to set it in
3559 the global options and expect it to be applied to the entire view.")
3561 (defvar org-agenda-category-filter-preset nil
3562 "A preset of the category filter used for secondary agenda filtering.
3563 This must be a list of strings, each string must be a single category
3564 preceded by \"+\" or \"-\".
3565 This variable should not be set directly, but agenda custom commands can
3566 bind it in the options section. The preset filter is a global property of
3567 the entire agenda view. In a block agenda, it will not work reliably to
3568 define a filter for one of the individual blocks. You need to set it in
3569 the global options and expect it to be applied to the entire view.")
3571 (defvar org-agenda-regexp-filter-preset nil
3572 "A preset of the regexp filter used for secondary agenda filtering.
3573 This must be a list of strings, each string must be a single category
3574 preceded by \"+\" or \"-\".
3575 This variable should not be set directly, but agenda custom commands can
3576 bind it in the options section. The preset filter is a global property of
3577 the entire agenda view. In a block agenda, it will not work reliably to
3578 define a filter for one of the individual blocks. You need to set it in
3579 the global options and expect it to be applied to the entire view.")
3581 (defun org-agenda-use-sticky-p ()
3582 "Return non-nil if an agenda buffer named
3583 `org-agenda-buffer-name' exists and should be shown instead of
3584 generating a new one."
3586 ;; turned off by user
3588 ;; For multi-agenda buffer already exists
3589 (not org-agenda-multi)
3591 (get-buffer org-agenda-buffer-name)
3592 ;; C-u parameter is same as last call
3593 (with-current-buffer (get-buffer org-agenda-buffer-name)
3595 (equal current-prefix-arg
3596 org-agenda-last-prefix-arg)
3597 ;; In case user turned stickiness on, while having existing
3598 ;; Agenda buffer active, don't reuse that buffer, because it
3599 ;; does not have org variables local
3600 org-agenda-this-buffer-is-sticky))))
3602 (defun org-agenda-prepare-window (abuf)
3603 "Setup agenda buffer in the window."
3604 (let* ((awin (get-buffer-window abuf))
3607 ((equal (current-buffer) abuf) nil)
3608 (awin (select-window awin))
3609 ((not (setq wconf (current-window-configuration))))
3610 ((equal org-agenda-window-setup 'current-window)
3611 (org-pop-to-buffer-same-window abuf))
3612 ((equal org-agenda-window-setup 'other-window)
3613 (org-switch-to-buffer-other-window abuf))
3614 ((equal org-agenda-window-setup 'other-frame)
3615 (switch-to-buffer-other-frame abuf))
3616 ((equal org-agenda-window-setup 'reorganize-frame)
3617 (delete-other-windows)
3618 (org-switch-to-buffer-other-window abuf)))
3619 ;; additional test in case agenda is invoked from within agenda
3620 ;; buffer via elisp link
3621 (unless (equal (current-buffer) abuf)
3622 (org-pop-to-buffer-same-window abuf))
3623 (setq org-agenda-pre-window-conf
3624 (or org-agenda-pre-window-conf wconf))))
3626 (defun org-agenda-prepare (&optional name)
3627 (if (org-agenda-use-sticky-p)
3629 ;; Popup existing buffer
3630 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3631 (message "Sticky Agenda buffer, use `r' to refresh")
3632 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3633 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3634 (setq org-todo-keywords-for-agenda nil)
3635 (setq org-drawers-for-agenda nil)
3636 (unless org-agenda-persistent-filter
3637 (setq org-agenda-tag-filter nil
3638 org-agenda-category-filter nil
3639 org-agenda-regexp-filter nil))
3640 (put 'org-agenda-tag-filter :preset-filter
3641 org-agenda-tag-filter-preset)
3642 (put 'org-agenda-category-filter :preset-filter
3643 org-agenda-category-filter-preset)
3644 (put 'org-agenda-regexp-filter :preset-filter
3645 org-agenda-regexp-filter-preset)
3646 (if org-agenda-multi
3648 (setq buffer-read-only nil)
3649 (goto-char (point-max))
3650 (unless (or (bobp) org-agenda-compact-blocks
3651 (not org-agenda-block-separator))
3653 (if (stringp org-agenda-block-separator)
3654 org-agenda-block-separator
3655 (make-string (window-width) org-agenda-block-separator))
3657 (narrow-to-region (point) (point-max)))
3658 (setq org-done-keywords-for-agenda nil)
3660 ;; Setting any org variables that are in org-agenda-local-vars
3661 ;; list need to be done after the prepare call
3662 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3663 (setq buffer-read-only nil)
3664 (org-agenda-reset-markers)
3665 (let ((inhibit-read-only t)) (erase-buffer))
3667 (setq org-agenda-buffer (current-buffer))
3668 (setq org-agenda-contributing-files nil)
3669 (setq org-agenda-columns-active nil)
3670 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3671 (setq org-todo-keywords-for-agenda
3672 (org-uniquify org-todo-keywords-for-agenda))
3673 (setq org-done-keywords-for-agenda
3674 (org-uniquify org-done-keywords-for-agenda))
3675 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3676 (setq org-agenda-last-prefix-arg current-prefix-arg)
3677 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3678 (and name (not org-agenda-name)
3679 (org-set-local 'org-agenda-name name)))
3680 (setq buffer-read-only nil)))
3682 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3683 (defun org-agenda-finalize ()
3684 "Finishing touch for the agenda buffer, called just before displaying it."
3685 (unless org-agenda-multi
3687 (let ((inhibit-read-only t))
3688 (goto-char (point-min))
3690 (while (org-activate-bracket-links (point-max))
3691 (add-text-properties (match-beginning 0) (match-end 0)
3694 (while (org-activate-plain-links (point-max))
3695 (add-text-properties (match-beginning 0) (match-end 0)
3697 (unless (eq org-agenda-remove-tags t)
3698 (org-agenda-align-tags))
3699 (unless org-agenda-with-colors
3700 (remove-text-properties (point-min) (point-max) '(face nil)))
3701 (if (and (boundp 'org-agenda-overriding-columns-format)
3702 org-agenda-overriding-columns-format)
3703 (org-set-local 'org-agenda-overriding-columns-format
3704 org-agenda-overriding-columns-format))
3705 (if (and (boundp 'org-agenda-view-columns-initially)
3706 org-agenda-view-columns-initially)
3707 (org-agenda-columns))
3708 (when org-agenda-fontify-priorities
3709 (org-agenda-fontify-priorities))
3710 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3711 (org-agenda-dim-blocked-tasks))
3712 ;; We need to widen when `org-agenda-finalize' is called from
3713 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3714 (when org-clock-current-task
3717 (org-agenda-mark-clocking-task)))
3718 (when org-agenda-entry-text-mode
3719 (org-agenda-entry-text-hide)
3720 (org-agenda-entry-text-show))
3721 (if (and (functionp 'org-habit-insert-consistency-graphs)
3722 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3723 (org-habit-insert-consistency-graphs))
3724 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3725 (unless (or (eq org-agenda-show-inherited-tags 'always)
3726 (and (listp org-agenda-show-inherited-tags)
3727 (memq org-agenda-type org-agenda-show-inherited-tags))
3728 (and (eq org-agenda-show-inherited-tags t)
3729 (or (eq org-agenda-use-tag-inheritance t)
3730 (and (listp org-agenda-use-tag-inheritance)
3731 (not (memq org-agenda-type
3732 org-agenda-use-tag-inheritance))))))
3735 (goto-char (point-min))
3736 (while (equal (forward-line) 0)
3737 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3738 (get-text-property (point) 'org-hd-marker)))
3739 (put-text-property (point-at-bol) (point-at-eol)
3740 'tags (org-with-point-at mrk
3742 (mapcar 'downcase (org-get-tags-at))))))))))
3743 (run-hooks 'org-agenda-finalize-hook)
3744 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3745 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3746 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3747 (org-agenda-filter-apply org-agenda-category-filter 'category))
3748 (when (or org-agenda-regexp-filter (get 'org-agenda-regexp-filter :preset-filter))
3749 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
3750 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3752 (defun org-agenda-mark-clocking-task ()
3753 "Mark the current clock entry in the agenda if it is present."
3754 (org-agenda-unmark-clocking-task)
3755 (when (marker-buffer org-clock-hd-marker)
3757 (goto-char (point-min))
3759 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3761 (when (equal (org-get-at-bol 'org-hd-marker)
3762 org-clock-hd-marker)
3763 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3764 (overlay-put ov 'type 'org-agenda-clocking)
3765 (overlay-put ov 'face 'org-agenda-clocking)
3766 (overlay-put ov 'help-echo
3767 "The clock is running in this item")))))))
3769 (defun org-agenda-unmark-clocking-task ()
3770 "Unmark the current clocking task."
3772 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3773 (delete-overlay o)))
3774 (overlays-in (point-min) (point-max))))
3776 (defun org-agenda-fontify-priorities ()
3777 "Make highest priority lines bold, and lowest italic."
3779 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3780 (delete-overlay o)))
3781 (overlays-in (point-min) (point-max)))
3784 (goto-char (point-min))
3785 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3786 (setq h (or (get-char-property (point) 'org-highest-priority)
3787 org-highest-priority)
3788 l (or (get-char-property (point) 'org-lowest-priority)
3789 org-lowest-priority)
3790 p (string-to-char (match-string 1))
3791 b (match-beginning 0)
3792 e (if (eq org-agenda-fontify-priorities 'cookies)
3795 ov (make-overlay b e))
3798 (cons (cond ((org-face-from-face-or-color
3800 (cdr (assoc p org-priority-faces))))
3801 ((and (listp org-agenda-fontify-priorities)
3802 (org-face-from-face-or-color
3804 (cdr (assoc p org-agenda-fontify-priorities)))))
3805 ((equal p l) 'italic)
3806 ((equal p h) 'bold))
3808 (overlay-put ov 'org-type 'org-priority)))))
3810 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3811 "Dim currently blocked TODO's in the agenda display.
3812 When INVISIBLE is non-nil, hide currently blocked TODO instead of
3815 (when (org-called-interactively-p 'interactive)
3816 (message "Dim or hide blocked tasks..."))
3817 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3818 (delete-overlay o)))
3819 (overlays-in (point-min) (point-max)))
3821 (let ((inhibit-read-only t)
3822 (org-depend-tag-blocked nil)
3823 (invis (or (not (null invisible))
3824 (eq org-agenda-dim-blocked-tasks 'invisible)))
3825 org-blocked-by-checkboxes
3826 invis1 b e p ov h l)
3827 (goto-char (point-min))
3828 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3829 (and pos (goto-char (1+ pos))))
3830 (setq org-blocked-by-checkboxes nil invis1 invis)
3831 (let ((marker (org-get-at-bol 'org-hd-marker)))
3833 (with-current-buffer (marker-buffer marker)
3834 (save-excursion (goto-char marker)
3835 (org-entry-blocked-p))))
3836 (if org-blocked-by-checkboxes (setq invis1 nil))
3838 (max (point-min) (1- (point-at-bol)))
3841 ov (make-overlay b e))
3843 (overlay-put ov 'invisible t)
3844 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3845 (overlay-put ov 'org-type 'org-blocked-todo))))))
3846 (when (org-called-interactively-p 'interactive)
3847 (message "Dim or hide blocked tasks...done")))
3849 (defvar org-agenda-skip-function nil
3850 "Function to be called at each match during agenda construction.
3851 If this function returns nil, the current match should not be skipped.
3852 Otherwise, the function must return a position from where the search
3853 should be continued.
3854 This may also be a Lisp form, it will be evaluated.
3855 Never set this variable using `setq' or so, because then it will apply
3856 to all future agenda commands. If you do want a global skipping condition,
3857 use the option `org-agenda-skip-function-global' instead.
3858 The correct usage for `org-agenda-skip-function' is to bind it with
3859 `let' to scope it dynamically into the agenda-constructing command.
3860 A good way to set it is through options in `org-agenda-custom-commands'.")
3862 (defun org-agenda-skip ()
3863 "Throw to `:skip' in places that should be skipped.
3864 Also moves point to the end of the skipped region, so that search can
3865 continue from there."
3866 (let ((p (point-at-bol)) to)
3868 (save-excursion (goto-char p) (looking-at comment-start-skip))
3869 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3870 (get-text-property p :org-archived)
3871 (org-end-of-subtree t))
3872 (and org-agenda-skip-comment-trees
3873 (get-text-property p :org-comment)
3874 (org-end-of-subtree t))
3875 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3876 (org-agenda-skip-eval org-agenda-skip-function)))
3878 (org-in-src-block-p t))
3881 (defun org-agenda-skip-eval (form)
3882 "If FORM is a function or a list, call (or eval) it and return the result.
3883 `save-excursion' and `save-match-data' are wrapped around the call, so point
3884 and match data are returned to the previous state no matter what these
3888 (or (setq fp (functionp form))
3896 (defvar org-agenda-markers nil
3897 "List of all currently active markers created by `org-agenda'.")
3898 (defvar org-agenda-last-marker-time (org-float-time)
3899 "Creation time of the last agenda marker.")
3901 (defun org-agenda-new-marker (&optional pos)
3902 "Return a new agenda marker.
3903 Org-mode keeps a list of these markers and resets them when they are
3905 (let ((m (copy-marker (or pos (point)))))
3906 (setq org-agenda-last-marker-time (org-float-time))
3907 (if org-agenda-buffer
3908 (with-current-buffer org-agenda-buffer
3909 (push m org-agenda-markers))
3910 (push m org-agenda-markers))
3913 (defun org-agenda-reset-markers ()
3914 "Reset markers created by `org-agenda'."
3915 (while org-agenda-markers
3916 (move-marker (pop org-agenda-markers) nil)))
3918 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3919 "Save relative positions of markers in region.
3920 This check for agenda markers in all agenda buffers currently active."
3921 (dolist (buf (buffer-list))
3922 (with-current-buffer buf
3923 (when (eq major-mode 'org-agenda-mode)
3924 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3925 org-agenda-markers)))))
3929 (defun org-agenda-entry-text-show-here ()
3930 "Add some text from the entry as context to the current line."
3932 (setq m (org-get-at-bol 'org-hd-marker))
3933 (unless (marker-buffer m)
3934 (error "No marker points to an entry here"))
3935 (setq txt (concat "\n" (org-no-properties
3936 (org-agenda-get-some-entry-text
3937 m org-agenda-entry-text-maxlines
3938 org-agenda-entry-text-leaders))))
3939 (when (string-match "\\S-" txt)
3940 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3941 (overlay-put o 'evaporate t)
3942 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3943 (overlay-put o 'after-string txt))))
3945 (defun org-agenda-entry-text-show ()
3946 "Add entry context for all agenda lines."
3949 (goto-char (point-max))
3950 (beginning-of-line 1)
3952 (when (org-get-at-bol 'org-hd-marker)
3953 (org-agenda-entry-text-show-here))
3954 (beginning-of-line 0))))
3956 (defun org-agenda-entry-text-hide ()
3957 "Remove any shown entry context."
3960 (if (eq (overlay-get o 'org-overlay-type)
3961 'agenda-entry-content)
3962 (progn (delete-overlay o) t)))
3963 (overlays-in (point-min) (point-max)))))
3965 (defun org-agenda-get-day-face (date)
3966 "Return the face DATE should be displayed with."
3967 (or (and (functionp org-agenda-day-face-function)
3968 (funcall org-agenda-day-face-function date))
3969 (cond ((org-agenda-todayp date)
3970 'org-agenda-date-today)
3971 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3972 'org-agenda-date-weekend)
3973 (t 'org-agenda-date))))
3977 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3979 (defun org-timeline (&optional dotodo)
3980 "Show a time-sorted view of the entries in the current org file.
3981 Only entries with a time stamp of today or later will be listed. With
3982 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3983 under the current date.
3984 If the buffer contains an active region, only check the region for
3988 (org-agenda-show-log-scoped org-agenda-show-log)
3989 (org-agenda-show-log org-agenda-show-log-scoped)
3990 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3992 (date (calendar-current-date))
3993 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3994 (end (if (org-region-active-p) (region-end) (point-max)))
3995 (day-numbers (org-get-all-dates
3997 t org-agenda-show-log-scoped ; always include today
3998 org-timeline-show-empty-dates))
3999 (org-deadline-warning-days 0)
4000 (org-agenda-only-exact-dates t)
4005 (setq org-agenda-redo-command
4007 (list (list 'org-agenda-show-log 'org-agenda-show-log))
4008 (list 'org-switch-to-buffer-other-window (current-buffer))
4009 (list 'org-timeline (list 'quote dotodo))))
4010 (put 'org-agenda-redo-command 'org-lprops nil)
4012 ;; Remove past dates from the list of dates.
4013 (setq day-numbers (delq nil (mapcar (lambda(x)
4014 (if (>= x today) x nil))
4016 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
4017 (org-compile-prefix-format 'timeline)
4018 (org-set-sorting-strategy 'timeline)
4019 (if org-agenda-show-log-scoped (push :closed args))
4020 (push :timestamp args)
4021 (push :deadline args)
4022 (push :scheduled args)
4024 (if dotodo (push :todo args))
4025 (insert "Timeline of file " entry "\n")
4026 (add-text-properties (point-min) (point)
4027 (list 'face 'org-agenda-structure))
4028 (org-agenda-mark-header-line (point-min))
4029 (while (setq d (pop day-numbers))
4030 (if (and (listp d) (eq (car d) :omitted))
4033 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
4034 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
4035 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
4036 (if (and (>= d today)
4041 (insert (make-string 79 ?-) "\n")))
4042 (setq date (calendar-gregorian-from-absolute d))
4044 (setq rtn (and (not emptyp)
4045 (apply 'org-agenda-get-day-entries entry
4047 (if (or rtn (equal d today) org-timeline-show-empty-dates)
4050 (if (stringp org-agenda-format-date)
4051 (format-time-string org-agenda-format-date
4052 (org-time-from-absolute date))
4053 (funcall org-agenda-format-date date))
4055 (put-text-property s (1- (point)) 'face
4056 (org-agenda-get-day-face date))
4057 (put-text-property s (1- (point)) 'org-date-line t)
4058 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4060 (put-text-property s (1- (point)) 'org-today t))
4061 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
4062 (put-text-property s (1- (point)) 'day d)))))
4063 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
4065 (add-text-properties
4066 (point-min) (point-max)
4067 `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
4068 (org-agenda-finalize)
4069 (setq buffer-read-only t)))
4071 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
4072 "Return a list of all relevant day numbers from BEG to END buffer positions.
4073 If NO-RANGES is non-nil, include only the start and end dates of a range,
4074 not every single day in the range. If FORCE-TODAY is non-nil, make
4075 sure that TODAY is included in the list. If INACTIVE is non-nil, also
4076 inactive time stamps (those in square brackets) are included.
4077 When EMPTY is non-nil, also include days without any entries."
4079 (if pre-re pre-re "")
4080 (if inactive org-ts-regexp-both org-ts-regexp)))
4081 dates dates1 date day day1 day2 ts1 ts2 pos)
4083 (setq dates (list (org-today))))
4086 (while (re-search-forward re end t)
4087 (setq day (time-to-days (org-time-string-to-time
4088 (substring (match-string 1) 0 10)
4089 (current-buffer) (match-beginning 0))))
4090 (or (memq day dates) (push day dates)))
4093 (while (re-search-forward org-tr-regexp end t)
4094 (setq pos (match-beginning 0))
4095 (setq ts1 (substring (match-string 1) 0 10)
4096 ts2 (substring (match-string 2) 0 10)
4097 day1 (time-to-days (org-time-string-to-time
4098 ts1 (current-buffer) pos))
4099 day2 (time-to-days (org-time-string-to-time
4100 ts2 (current-buffer) pos)))
4101 (while (< (setq day1 (1+ day1)) day2)
4102 (or (memq day1 dates) (push day1 dates)))))
4103 (setq dates (sort dates '<))
4105 (while (setq day (pop dates))
4106 (setq day2 (car dates))
4108 (when (and day2 empty)
4109 (if (or (eq empty t)
4110 (and (numberp empty) (<= (- day2 day) empty)))
4111 (while (< (setq day (1+ day)) day2)
4112 (push (list day) dates1))
4113 (push (cons :omitted (- day2 day)) dates1))))
4114 (setq dates (nreverse dates1)))
4117 ;;; Agenda Daily/Weekly
4119 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4120 "Start day for the agenda view.
4121 Custom commands can set this variable in the options section.
4122 This is usually a string like \"2007-11-01\", \"+2d\" or any other
4123 input allowed when reading a date through the Org calendar.
4124 See the docstring of `org-read-date' for details.")
4125 (defvar org-starting-day nil) ; local variable in the agenda buffer
4126 (defvar org-arg-loc nil) ; local variable
4128 (defvar org-agenda-buffer-tmp-name nil)
4130 (defun org-agenda-list (&optional arg start-day span with-hour)
4131 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4132 The view will be for the current day or week, but from the overview buffer
4133 you will be able to go to other days/weeks.
4135 With a numeric prefix argument in an interactive call, the agenda will
4136 span ARG days. Lisp programs should instead specify SPAN to change
4137 the number of days. SPAN defaults to `org-agenda-span'.
4139 START-DAY defaults to TODAY, or to the most recent match for the weekday
4140 given in `org-agenda-start-on-weekday'.
4142 When WITH-HOUR is non-nil, only include scheduled and deadline
4143 items if they have an hour specification like [h]h:mm."
4145 (if org-agenda-overriding-arguments
4146 (setq arg (car org-agenda-overriding-arguments)
4147 start-day (nth 1 org-agenda-overriding-arguments)
4148 span (nth 2 org-agenda-overriding-arguments)))
4149 (if (and (integerp arg) (> arg 0))
4150 (setq span arg arg nil))
4152 (setq org-agenda-buffer-name
4153 (or org-agenda-buffer-tmp-name
4154 (if org-agenda-sticky
4155 (cond ((and org-keys (stringp org-match))
4156 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4158 (format "*Org Agenda(%s)*" org-keys))
4159 (t "*Org Agenda(a)*")))
4160 org-agenda-buffer-name))
4161 (org-agenda-prepare "Day/Week")
4162 (setq start-day (or start-day org-agenda-start-day))
4163 (if (stringp start-day)
4164 ;; Convert to an absolute day number
4165 (setq start-day (time-to-days (org-read-date nil t start-day))))
4166 (org-compile-prefix-format 'agenda)
4167 (org-set-sorting-strategy 'agenda)
4168 (let* ((span (org-agenda-ndays-to-span
4169 (or span org-agenda-ndays org-agenda-span)))
4171 (sd (or start-day today))
4172 (ndays (org-agenda-span-to-ndays span sd))
4173 (org-agenda-start-on-weekday
4175 org-agenda-start-on-weekday))
4176 (thefiles (org-agenda-files nil 'ifmode))
4178 (start (if (or (null org-agenda-start-on-weekday)
4181 (let* ((nt (calendar-day-of-week
4182 (calendar-gregorian-from-absolute sd)))
4183 (n1 org-agenda-start-on-weekday)
4185 (- sd (+ (if (< d 0) 7 0) d)))))
4186 (day-numbers (list start))
4188 (inhibit-redisplay (not debug-on-error))
4189 (org-agenda-show-log-scoped org-agenda-show-log)
4190 s e rtn rtnall file date d start-pos end-pos todayp
4191 clocktable-start clocktable-end filter)
4192 (setq org-agenda-redo-command
4193 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
4194 (dotimes (n (1- ndays))
4195 (push (1+ (car day-numbers)) day-numbers))
4196 (setq day-numbers (nreverse day-numbers))
4197 (setq clocktable-start (car day-numbers)
4198 clocktable-end (1+ (or (org-last day-numbers) 0)))
4199 (org-set-local 'org-starting-day (car day-numbers))
4200 (org-set-local 'org-arg-loc arg)
4201 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4202 (unless org-agenda-compact-blocks
4203 (let* ((d1 (car day-numbers))
4204 (d2 (org-last day-numbers))
4205 (w1 (org-days-to-iso-week d1))
4206 (w2 (org-days-to-iso-week d2)))
4208 (if org-agenda-overriding-header
4209 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4210 nil 'face 'org-agenda-structure) "\n")
4211 (insert (org-agenda-span-name span)
4213 (if (< (- d2 d1) 350)
4215 (format " (W%02d)" w1)
4216 (format " (W%02d-W%02d)" w1 w2))
4219 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4221 (org-agenda-mark-header-line s))
4222 (while (setq d (pop day-numbers))
4223 (setq date (calendar-gregorian-from-absolute d)
4225 (if (or (setq todayp (= d today))
4226 (and (not start-pos) (= d sd)))
4227 (setq start-pos (point))
4228 (if (and start-pos (not end-pos))
4229 (setq end-pos (point))))
4230 (setq files thefiles
4232 (while (setq file (pop files))
4234 (org-check-agenda-file file)
4235 (let ((org-agenda-entry-types org-agenda-entry-types))
4236 ;; Starred types override non-starred equivalents
4237 (when (member :deadline* org-agenda-entry-types)
4238 (setq org-agenda-entry-types
4239 (delq :deadline org-agenda-entry-types)))
4240 (when (member :scheduled* org-agenda-entry-types)
4241 (setq org-agenda-entry-types
4242 (delq :scheduled org-agenda-entry-types)))
4245 (when (member :deadline org-agenda-entry-types)
4246 (setq org-agenda-entry-types
4247 (delq :deadline org-agenda-entry-types))
4248 (push :deadline* org-agenda-entry-types))
4249 (when (member :scheduled org-agenda-entry-types)
4250 (setq org-agenda-entry-types
4251 (delq :scheduled org-agenda-entry-types))
4252 (push :scheduled* org-agenda-entry-types)))
4253 (unless org-agenda-include-deadlines
4254 (setq org-agenda-entry-types
4255 (delq :deadline* (delq :deadline org-agenda-entry-types))))
4257 ((memq org-agenda-show-log-scoped '(only clockcheck))
4258 (setq rtn (org-agenda-get-day-entries
4259 file date :closed)))
4260 (org-agenda-show-log-scoped
4261 (setq rtn (apply 'org-agenda-get-day-entries
4263 (append '(:closed) org-agenda-entry-types))))
4265 (setq rtn (apply 'org-agenda-get-day-entries
4267 org-agenda-entry-types)))))
4268 (setq rtnall (append rtnall rtn)))) ;; all entries
4269 (if org-agenda-include-diary
4270 (let ((org-agenda-search-headline-for-time t))
4271 (require 'diary-lib)
4272 (setq rtn (org-get-entries-from-diary date))
4273 (setq rtnall (append rtnall rtn))))
4274 (if (or rtnall org-agenda-show-all-dates)
4276 (setq day-cnt (1+ day-cnt))
4278 (if (stringp org-agenda-format-date)
4279 (format-time-string org-agenda-format-date
4280 (org-time-from-absolute date))
4281 (funcall org-agenda-format-date date))
4283 (put-text-property s (1- (point)) 'face
4284 (org-agenda-get-day-face date))
4285 (put-text-property s (1- (point)) 'org-date-line t)
4286 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4287 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4289 (put-text-property s (1- (point)) 'org-today t))
4291 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4292 (if rtnall (insert ;; all entries
4293 (org-agenda-finalize-entries rtnall 'agenda)
4295 (put-text-property s (1- (point)) 'day d)
4296 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4297 (when (and org-agenda-clockreport-mode clocktable-start)
4298 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4299 ;; the above line is to ensure the restricted range!
4300 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4302 (setq p (org-plist-delete p :block))
4303 (setq p (plist-put p :tstart clocktable-start))
4304 (setq p (plist-put p :tend clocktable-end))
4305 (setq p (plist-put p :scope 'agenda))
4306 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4307 (setq filter (or org-agenda-tag-filter-while-redo
4308 (get 'org-agenda-tag-filter :preset-filter))))
4309 (setq p (plist-put p :tags (mapconcat (lambda (x)
4310 (if (string-match "[<>=]" x)
4314 (setq tbl (apply 'org-clock-get-clocktable p))
4316 (goto-char (point-min))
4317 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4318 (unless (and (pos-visible-in-window-p (point-min))
4319 (pos-visible-in-window-p (point-max)))
4320 (goto-char (1- (point-max)))
4322 (if (not (pos-visible-in-window-p (or start-pos 1)))
4324 (goto-char (or start-pos 1))
4326 (goto-char (or start-pos 1))
4327 (add-text-properties (point-min) (point-max)
4328 `(org-agenda-type agenda
4329 org-last-args (,arg ,start-day ,span)
4330 org-redo-cmd ,org-agenda-redo-command
4331 org-series-cmd ,org-cmd))
4332 (if (eq org-agenda-show-log-scoped 'clockcheck)
4333 (org-agenda-show-clocking-issues))
4334 (org-agenda-finalize)
4335 (setq buffer-read-only t)
4338 (defun org-agenda-ndays-to-span (n)
4339 "Return a span symbol for a span of N days, or N if none matches."
4340 (cond ((symbolp n) n)
4345 (defun org-agenda-span-to-ndays (span &optional start-day)
4346 "Return ndays from SPAN, possibly starting at START-DAY.
4347 START-DAY is an absolute time value."
4348 (cond ((numberp span) span)
4352 (let ((date (calendar-gregorian-from-absolute start-day)))
4353 (calendar-last-day-of-month (car date) (caddr date))))
4355 (let ((date (calendar-gregorian-from-absolute start-day)))
4356 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4358 (defun org-agenda-span-name (span)
4359 "Return a SPAN name."
4363 (capitalize (symbol-name span))
4364 (format "%d days" span))))
4366 ;;; Agenda word search
4368 (defvar org-agenda-search-history nil)
4370 (defvar org-search-syntax-table nil
4371 "Special syntax table for org-mode search.
4372 In this table, we have single quotes not as word constituents, to
4373 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4375 (defvar org-mode-syntax-table) ; From org.el
4376 (defun org-search-syntax-table ()
4377 (unless org-search-syntax-table
4378 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4379 (modify-syntax-entry ?' "." org-search-syntax-table)
4380 (modify-syntax-entry ?` "." org-search-syntax-table))
4381 org-search-syntax-table)
4383 (defvar org-agenda-last-search-view-search-was-boolean nil)
4386 (defun org-search-view (&optional todo-only string edit-at)
4387 "Show all entries that contain a phrase or words or regular expressions.
4389 With optional prefix argument TODO-ONLY, only consider entries that are
4390 TODO entries. The argument STRING can be used to pass a default search
4391 string into this function. If EDIT-AT is non-nil, it means that the
4392 user should get a chance to edit this string, with cursor at position
4395 The search string can be viewed either as a phrase that should be found as
4396 is, or it can be broken into a number of snippets, each of which must match
4397 in a Boolean way to select an entry. The default depends on the variable
4398 `org-agenda-search-view-always-boolean'.
4399 Even if this is turned off (the default) you can always switch to
4400 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4402 The default is a direct search of the whole phrase, where each space in
4403 the search string can expand to an arbitrary amount of whitespace,
4406 If using a Boolean search, the search string is split on whitespace and
4407 each snippet is searched separately, with logical AND to select an entry.
4408 Words prefixed with a minus must *not* occur in the entry. Words without
4409 a prefix or prefixed with a plus must occur in the entry. Matching is
4410 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4411 match whole words, not parts of a word) if
4412 `org-agenda-search-view-force-full-words' is set (default is nil).
4414 Boolean search snippets enclosed by curly braces are interpreted as
4415 regular expressions that must or (when preceded with \"-\") must not
4416 match in the entry. Snippets enclosed into double quotes will be taken
4417 as a whole, to include whitespace.
4419 - If the search string starts with an asterisk, search only in headlines.
4420 - If (possibly after the leading star) the search string starts with an
4421 exclamation mark, this also means to look at TODO entries only, an effect
4422 that can also be achieved with a prefix argument.
4423 - If (possibly after star and exclamation mark) the search string starts
4424 with a colon, this will mean that the (non-regexp) snippets of the
4425 Boolean search must match as full words.
4427 This command searches the agenda files, and in addition the files listed
4428 in `org-agenda-text-search-extra-files'."
4430 (if org-agenda-overriding-arguments
4431 (setq todo-only (car org-agenda-overriding-arguments)
4432 string (nth 1 org-agenda-overriding-arguments)
4433 edit-at (nth 2 org-agenda-overriding-arguments)))
4434 (let* ((props (list 'face nil
4435 'done-face 'org-agenda-done
4436 'org-not-done-regexp org-not-done-regexp
4437 'org-todo-regexp org-todo-regexp
4438 'org-complex-heading-regexp org-complex-heading-regexp
4439 'mouse-face 'highlight
4440 'help-echo (format "mouse-2 or RET jump to location")))
4441 (full-words org-agenda-search-view-force-full-words)
4442 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4443 regexp rtn rtnall files file pos inherited-tags
4444 marker category category-pos level tags c neg re boolean
4445 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4446 (unless (and (not edit-at)
4448 (string-match "\\S-" string))
4449 (setq string (read-string
4450 (if org-agenda-search-view-always-boolean
4451 "[+-]Word/{Regexp} ...: "
4452 "Phrase or [+-]Word/{Regexp} ...: ")
4454 ((integerp edit-at) (cons string edit-at))
4456 'org-agenda-search-history)))
4458 (if org-agenda-sticky
4459 (setq org-agenda-buffer-name
4460 (if (stringp string)
4461 (format "*Org Agenda(%s:%s)*"
4462 (or org-keys (or (and todo-only "S") "s")) string)
4463 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4464 (org-agenda-prepare "SEARCH")
4465 (org-compile-prefix-format 'search)
4466 (org-set-sorting-strategy 'search)
4467 (setq org-agenda-redo-command
4468 (list 'org-search-view (if todo-only t nil)
4469 (list 'if 'current-prefix-arg nil string)))
4470 (setq org-agenda-query-string string)
4471 (if (equal (string-to-char string) ?*)
4473 words (substring string 1))
4474 (setq words string))
4475 (when (equal (string-to-char words) ?!)
4477 words (substring words 1)))
4478 (when (equal (string-to-char words) ?:)
4480 words (substring words 1)))
4481 (if (or org-agenda-search-view-always-boolean
4482 (member (string-to-char words) '(?- ?+ ?\{)))
4484 (setq words (org-split-string words))
4486 (while (setq w (pop words))
4487 (while (and (string-match "\\\\\\'" w) words)
4488 (setq w (concat (substring w 0 -1) " " (pop words))))
4490 (setq words (nreverse www) www nil)
4491 (while (setq w (pop words))
4492 (when (and (string-match "\\`[-+]?{" w)
4493 (not (string-match "}\\'" w)))
4494 (while (and words (not (string-match "}\\'" (car words))))
4495 (setq w (concat w " " (pop words))))
4496 (setq w (concat w " " (pop words))))
4498 (setq words (nreverse www)))
4499 (setq org-agenda-last-search-view-search-was-boolean boolean)
4502 (while (setq w (pop words))
4503 (if (or (equal (substring w 0 1) "\"")
4504 (and (> (length w) 1)
4505 (member (substring w 0 1) '("+" "-"))
4506 (equal (substring w 1 2) "\"")))
4507 (while (and words (not (equal (substring w -1) "\"")))
4508 (setq w (concat w " " (pop words)))))
4509 (and (string-match "\\`\\([-+]?\\)\"" w)
4510 (setq w (replace-match "\\1" nil nil w)))
4511 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4513 (setq words (nreverse wds))))
4516 (setq c (string-to-char w))
4518 (setq neg t w (substring w 1))
4520 (setq neg nil w (substring w 1))
4522 (if (string-match "\\`{.*}\\'" w)
4523 (setq re (substring w 1 -1))
4525 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4526 (setq re (regexp-quote (downcase w)))))
4527 (if neg (push re regexps-) (push re regexps+)))
4529 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4531 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4533 (setq regexp org-outline-regexp-bol)
4534 (setq regexp (pop regexps+))
4535 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4537 (setq files (org-agenda-files nil 'ifmode))
4538 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4539 (pop org-agenda-text-search-extra-files)
4540 (setq files (org-add-archive-files files)))
4541 (setq files (append files org-agenda-text-search-extra-files)
4543 (while (setq file (pop files))
4546 (org-check-agenda-file file)
4547 (setq buffer (if (file-exists-p file)
4548 (org-get-agenda-file-buffer file)
4549 (error "No such file %s" file)))
4551 ;; If file does not exist, make sure an error message is sent
4552 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4554 (with-current-buffer buffer
4555 (with-syntax-table (org-search-syntax-table)
4556 (unless (derived-mode-p 'org-mode)
4557 (error "Agenda file %s is not in `org-mode'" file))
4558 (let ((case-fold-search t))
4561 (if (eq buffer org-agenda-restrict)
4562 (narrow-to-region org-agenda-restrict-begin
4563 org-agenda-restrict-end)
4565 (goto-char (point-min))
4566 (unless (or (org-at-heading-p)
4567 (outline-next-heading))
4568 (throw 'nextfile t))
4569 (goto-char (max (point-min) (1- (point))))
4570 (while (re-search-forward regexp nil t)
4571 (org-back-to-heading t)
4572 (while (and org-agenda-search-view-max-outline-level
4573 (> (org-reduced-level (org-outline-level))
4574 org-agenda-search-view-max-outline-level)
4576 (outline-back-to-heading t)))
4577 (skip-chars-forward "* ")
4578 (setq beg (point-at-bol)
4581 (outline-next-heading)
4582 (while (and org-agenda-search-view-max-outline-level
4583 (> (org-reduced-level (org-outline-level))
4584 org-agenda-search-view-max-outline-level)
4586 (outline-next-heading)))
4592 (setq str (buffer-substring-no-properties
4594 (if hdl-only (point-at-eol) end)))
4595 (mapc (lambda (wr) (when (string-match wr str)
4596 (goto-char (1- end))
4599 (mapc (lambda (wr) (unless (string-match wr str)
4600 (goto-char (1- end))
4603 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4607 (setq marker (org-agenda-new-marker (point))
4608 category (org-get-category)
4609 level (make-string (org-reduced-level (org-outline-level)) ? )
4610 category-pos (get-text-property (point) 'org-category-position)
4612 (or (eq org-agenda-show-inherited-tags 'always)
4613 (and (listp org-agenda-show-inherited-tags)
4614 (memq 'todo org-agenda-show-inherited-tags))
4615 (and (eq org-agenda-show-inherited-tags t)
4616 (or (eq org-agenda-use-tag-inheritance t)
4617 (memq 'todo org-agenda-use-tag-inheritance))))
4618 tags (org-get-tags-at nil (not inherited-tags))
4619 txt (org-agenda-format-item
4621 (buffer-substring-no-properties
4622 beg1 (point-at-eol))
4623 level category tags t))
4624 (org-add-props txt props
4625 'org-marker marker 'org-hd-marker marker
4626 'org-todo-regexp org-todo-regexp
4628 'org-complex-heading-regexp org-complex-heading-regexp
4629 'priority 1000 'org-category category
4630 'org-category-position category-pos
4633 (goto-char (1- end))))))))))
4634 (setq rtn (nreverse ee))
4635 (setq rtnall (append rtnall rtn)))
4636 (if org-agenda-overriding-header
4637 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4638 nil 'face 'org-agenda-structure) "\n")
4639 (insert "Search words: ")
4640 (add-text-properties (point-min) (1- (point))
4641 (list 'face 'org-agenda-structure))
4643 (insert string "\n")
4644 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4646 (unless org-agenda-multi
4647 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4648 (add-text-properties pos (1- (point))
4649 (list 'face 'org-agenda-structure))))
4650 (org-agenda-mark-header-line (point-min))
4652 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4653 (goto-char (point-min))
4654 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4655 (add-text-properties (point-min) (point-max)
4656 `(org-agenda-type search
4657 org-last-args (,todo-only ,string ,edit-at)
4658 org-redo-cmd ,org-agenda-redo-command
4659 org-series-cmd ,org-cmd))
4660 (org-agenda-finalize)
4661 (setq buffer-read-only t))))
4663 ;;; Agenda TODO list
4665 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4666 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4668 (if (or (equal keywords "ALL") (not keywords))
4669 (propertize "ALL" 'face 'warning)
4672 (propertize kw 'face (org-get-todo-face kw)))
4673 (org-split-string keywords "|")
4677 (defvar org-select-this-todo-keyword nil)
4678 (defvar org-last-arg nil)
4681 (defun org-todo-list (&optional arg)
4682 "Show all (not done) TODO entries from all agenda file in a single list.
4683 The prefix arg can be used to select a specific TODO keyword and limit
4684 the list to these. When using \\[universal-argument], you will be prompted
4685 for a keyword. A numeric prefix directly selects the Nth keyword in
4686 `org-todo-keywords-1'."
4688 (if org-agenda-overriding-arguments
4689 (setq arg org-agenda-overriding-arguments))
4690 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4691 (let* ((today (org-today))
4692 (date (calendar-gregorian-from-absolute today))
4693 (kwds org-todo-keywords-for-agenda)
4694 (completion-ignore-case t)
4695 (org-select-this-todo-keyword
4696 (if (stringp arg) arg
4697 (and arg (integerp arg) (> arg 0)
4698 (nth (1- arg) kwds))))
4699 rtn rtnall files file pos)
4700 (when (equal arg '(4))
4701 (setq org-select-this-todo-keyword
4702 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4703 (mapcar 'list kwds) nil nil)))
4704 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4706 (if org-agenda-sticky
4707 (setq org-agenda-buffer-name
4708 (if (stringp org-select-this-todo-keyword)
4709 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4710 org-select-this-todo-keyword)
4711 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4712 (org-agenda-prepare "TODO")
4713 (org-compile-prefix-format 'todo)
4714 (org-set-sorting-strategy 'todo)
4715 (setq org-agenda-redo-command
4716 `(org-todo-list (or (and (numberp current-prefix-arg)
4718 ,org-select-this-todo-keyword
4719 current-prefix-arg ,arg)))
4720 (setq files (org-agenda-files nil 'ifmode)
4722 (while (setq file (pop files))
4724 (org-check-agenda-file file)
4725 (setq rtn (org-agenda-get-day-entries file date :todo))
4726 (setq rtnall (append rtnall rtn))))
4727 (if org-agenda-overriding-header
4728 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4729 nil 'face 'org-agenda-structure) "\n")
4730 (insert "Global list of TODO items of type: ")
4731 (add-text-properties (point-min) (1- (point))
4732 (list 'face 'org-agenda-structure
4735 (or org-select-this-todo-keyword "ALL"))))
4736 (org-agenda-mark-header-line (point-min))
4737 (insert (org-agenda-propertize-selected-todo-keywords
4738 org-select-this-todo-keyword))
4740 (unless org-agenda-multi
4741 (insert "Available with `N r': (0)[ALL]")
4744 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4745 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4750 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4751 (org-agenda-mark-header-line (point-min))
4753 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4754 (goto-char (point-min))
4755 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4756 (add-text-properties (point-min) (point-max)
4757 `(org-agenda-type todo
4759 org-redo-cmd ,org-agenda-redo-command
4760 org-series-cmd ,org-cmd))
4761 (org-agenda-finalize)
4762 (setq buffer-read-only t))))
4764 ;;; Agenda tags match
4767 (defun org-tags-view (&optional todo-only match)
4768 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4769 The prefix arg TODO-ONLY limits the search to TODO entries."
4771 (if org-agenda-overriding-arguments
4772 (setq todo-only (car org-agenda-overriding-arguments)
4773 match (nth 1 org-agenda-overriding-arguments)))
4774 (let* ((org-tags-match-list-sublevels
4775 org-tags-match-list-sublevels)
4776 (completion-ignore-case t)
4777 rtn rtnall files file pos matcher
4779 (when (and (stringp match) (not (string-match "\\S-" match)))
4782 (if org-agenda-sticky
4783 (setq org-agenda-buffer-name
4785 (format "*Org Agenda(%s:%s)*"
4786 (or org-keys (or (and todo-only "M") "m")) match)
4787 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4788 ;; Prepare agendas (and `org-tag-alist-for-agenda') before
4789 ;; expanding tags within `org-make-tags-matcher'
4790 (org-agenda-prepare (concat "TAGS " match))
4791 (setq matcher (org-make-tags-matcher match)
4792 match (car matcher) matcher (cdr matcher))
4793 (org-compile-prefix-format 'tags)
4794 (org-set-sorting-strategy 'tags)
4795 (setq org-agenda-query-string match)
4796 (setq org-agenda-redo-command
4797 (list 'org-tags-view `(quote ,todo-only)
4798 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4799 (setq files (org-agenda-files nil 'ifmode)
4801 (while (setq file (pop files))
4803 (org-check-agenda-file file)
4804 (setq buffer (if (file-exists-p file)
4805 (org-get-agenda-file-buffer file)
4806 (error "No such file %s" file)))
4808 ;; If file does not exist, error message to agenda
4810 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4811 rtnall (append rtnall rtn))
4812 (with-current-buffer buffer
4813 (unless (derived-mode-p 'org-mode)
4814 (error "Agenda file %s is not in `org-mode'" file))
4817 (if (eq buffer org-agenda-restrict)
4818 (narrow-to-region org-agenda-restrict-begin
4819 org-agenda-restrict-end)
4821 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4822 (setq rtnall (append rtnall rtn))))))))
4823 (if org-agenda-overriding-header
4824 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4825 nil 'face 'org-agenda-structure) "\n")
4826 (insert "Headlines with TAGS match: ")
4827 (add-text-properties (point-min) (1- (point))
4828 (list 'face 'org-agenda-structure
4830 (concat "Match: " match)))
4833 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4835 (unless org-agenda-multi
4836 (insert "Press `C-u r' to search again with new search string\n"))
4837 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4838 (org-agenda-mark-header-line (point-min))
4840 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4841 (goto-char (point-min))
4842 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4843 (add-text-properties (point-min) (point-max)
4844 `(org-agenda-type tags
4845 org-last-args (,todo-only ,match)
4846 org-redo-cmd ,org-agenda-redo-command
4847 org-series-cmd ,org-cmd))
4848 (org-agenda-finalize)
4849 (setq buffer-read-only t))))
4851 ;;; Agenda Finding stuck projects
4853 (defvar org-agenda-skip-regexp nil
4854 "Regular expression used in skipping subtrees for the agenda.
4855 This is basically a temporary global variable that can be set and then
4856 used by user-defined selections using `org-agenda-skip-function'.")
4858 (defvar org-agenda-overriding-header nil
4859 "When set during agenda, todo and tags searches it replaces the header.
4860 This variable should not be set directly, but custom commands can bind it
4861 in the options section.")
4863 (defun org-agenda-skip-entry-when-regexp-matches ()
4864 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4865 If yes, it returns the end position of this entry, causing agenda commands
4866 to skip the entry but continuing the search in the subtree. This is a
4867 function that can be put into `org-agenda-skip-function' for the duration
4869 (let ((end (save-excursion (org-end-of-subtree t)))
4872 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4875 (defun org-agenda-skip-subtree-when-regexp-matches ()
4876 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4877 If yes, it returns the end position of this tree, causing agenda commands
4878 to skip this subtree. This is a function that can be put into
4879 `org-agenda-skip-function' for the duration of a command."
4880 (let ((end (save-excursion (org-end-of-subtree t)))
4883 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4886 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4887 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4888 If yes, it returns the end position of the current entry (NOT the tree),
4889 causing agenda commands to skip the entry but continuing the search in
4890 the subtree. This is a function that can be put into
4891 `org-agenda-skip-function' for the duration of a command. An important
4892 use of this function is for the stuck project list."
4893 (let ((end (save-excursion (org-end-of-subtree t)))
4894 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4897 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4898 (and skip entry-end)))
4900 (defun org-agenda-skip-entry-if (&rest conditions)
4901 "Skip entry if any of CONDITIONS is true.
4902 See `org-agenda-skip-if' for details."
4903 (org-agenda-skip-if nil conditions))
4905 (defun org-agenda-skip-subtree-if (&rest conditions)
4906 "Skip entry if any of CONDITIONS is true.
4907 See `org-agenda-skip-if' for details."
4908 (org-agenda-skip-if t conditions))
4910 (defun org-agenda-skip-if (subtree conditions)
4911 "Checks current entity for CONDITIONS.
4912 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4913 the entry (i.e. the text before the next heading) is checked.
4915 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4916 from different tests. Valid conditions are:
4918 scheduled Check if there is a scheduled cookie
4919 notscheduled Check if there is no scheduled cookie
4920 deadline Check if there is a deadline
4921 notdeadline Check if there is no deadline
4922 timestamp Check if there is a timestamp (also deadline or scheduled)
4923 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4924 regexp Check if regexp matches
4925 notregexp Check if regexp does not match.
4926 todo Check if TODO keyword matches
4927 nottodo Check if TODO keyword does not match
4929 The regexp is taken from the conditions list, it must come right after
4930 the `regexp' or `notregexp' element.
4932 `todo' and `nottodo' accept as an argument a list of todo
4933 keywords, which may include \"*\" to match any todo keyword.
4935 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4937 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4939 Instead of a list, a keyword class may be given. For example:
4941 (org-agenda-skip-entry-if 'nottodo 'done)
4943 would skip entries that haven't been marked with any of \"DONE\"
4944 keywords. Possible classes are: `todo', `done', `any'.
4946 If any of these conditions is met, this function returns the end point of
4947 the entity, causing the search to continue from there. This is a function
4948 that can be put into `org-agenda-skip-function' for the duration of a command."
4950 (org-back-to-heading t)
4953 (progn (org-end-of-subtree t) (point))
4954 (progn (outline-next-heading) (1- (point)))))
4958 (and (memq 'scheduled conditions)
4959 (re-search-forward org-scheduled-time-regexp end t))
4960 (and (memq 'notscheduled conditions)
4961 (not (re-search-forward org-scheduled-time-regexp end t)))
4962 (and (memq 'deadline conditions)
4963 (re-search-forward org-deadline-time-regexp end t))
4964 (and (memq 'notdeadline conditions)
4965 (not (re-search-forward org-deadline-time-regexp end t)))
4966 (and (memq 'timestamp conditions)
4967 (re-search-forward org-ts-regexp end t))
4968 (and (memq 'nottimestamp conditions)
4969 (not (re-search-forward org-ts-regexp end t)))
4970 (and (setq m (memq 'regexp conditions))
4972 (re-search-forward (nth 1 m) end t))
4973 (and (setq m (memq 'notregexp conditions))
4975 (not (re-search-forward (nth 1 m) end t)))
4977 (setq m (memq 'nottodo conditions))
4978 (setq m (memq 'todo-unblocked conditions))
4979 (setq m (memq 'nottodo-unblocked conditions))
4980 (setq m (memq 'todo conditions)))
4981 (org-agenda-skip-if-todo m end)))
4984 (defun org-agenda-skip-if-todo (args end)
4985 "Helper function for `org-agenda-skip-if', do not use it directly.
4986 ARGS is a list with first element either `todo', `nottodo',
4987 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4988 a list of TODO keywords, or a state symbol `todo' or `done' or
4990 (let ((kw (car args))
4996 ((listp arg) ;; list of keywords
4997 (if (member "*" arg)
4998 (mapcar 'substring-no-properties org-todo-keywords-1)
5000 ((symbolp arg) ;; keyword class name
5003 (org-delete-all org-done-keywords
5004 (mapcar 'substring-no-properties
5005 org-todo-keywords-1)))
5006 ((eq arg 'done) org-done-keywords)
5008 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
5010 (concat "^\\*+[ \t]+\\<\\("
5011 (mapconcat 'identity todo-wds "\\|")
5014 ((eq kw 'todo) (re-search-forward todo-re end t))
5015 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
5016 ((eq kw 'todo-unblocked)
5018 (while (re-search-forward todo-re end t)
5019 (or (org-entry-blocked-p) (throw 'unblocked t)))
5021 ((eq kw 'nottodo-unblocked)
5023 (while (re-search-forward todo-re end t)
5024 (or (org-entry-blocked-p) (throw 'unblocked nil)))
5029 (defun org-agenda-list-stuck-projects (&rest ignore)
5030 "Create agenda view for projects that are stuck.
5031 Stuck projects are project that have no next actions. For the definitions
5032 of what a project is and how to check if it stuck, customize the variable
5033 `org-stuck-projects'."
5035 (let* ((org-agenda-skip-function
5036 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5037 ;; We could have used org-agenda-skip-if here.
5038 (org-agenda-overriding-header
5039 (or org-agenda-overriding-header "List of stuck projects: "))
5040 (matcher (nth 0 org-stuck-projects))
5041 (todo (nth 1 org-stuck-projects))
5042 (todo-wds (if (member "*" todo)
5044 (org-agenda-prepare-buffers (org-agenda-files
5047 org-done-keywords-for-agenda
5048 (copy-sequence org-todo-keywords-for-agenda)))
5050 (todo-re (concat "^\\*+[ \t]+\\("
5051 (mapconcat 'identity todo-wds "\\|")
5053 (tags (nth 2 org-stuck-projects))
5054 (tags-re (if (member "*" tags)
5055 (concat org-outline-regexp-bol
5056 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5058 (concat org-outline-regexp-bol
5060 (mapconcat 'identity tags "\\|")
5061 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5062 (gen-re (nth 3 org-stuck-projects))
5068 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5070 (setq org-agenda-skip-regexp
5072 (mapconcat 'identity re-list "\\|")
5073 (error "No information how to identify unstuck projects")))
5074 (org-tags-view nil matcher)
5075 (with-current-buffer org-agenda-buffer-name
5076 (setq org-agenda-redo-command
5077 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5079 ;;; Diary integration
5081 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5082 (defvar diary-list-entries-hook)
5083 (defvar diary-time-regexp)
5084 (defun org-get-entries-from-diary (date)
5085 "Get the (Emacs Calendar) diary entries for DATE."
5086 (require 'diary-lib)
5087 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5088 (diary-display-hook '(fancy-diary-display))
5089 (diary-display-function 'fancy-diary-display)
5091 (diary-list-entries-hook
5092 (cons 'org-diary-default-entry diary-list-entries-hook))
5093 (diary-file-name-prefix nil) ; turn this feature off
5094 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5096 (org-disable-agenda-to-diary t))
5098 (save-window-excursion
5099 (funcall (if (fboundp 'diary-list-entries)
5100 'diary-list-entries 'list-diary-entries)
5102 (if (not (get-buffer diary-fancy-buffer))
5104 (with-current-buffer diary-fancy-buffer
5105 (setq buffer-read-only nil)
5106 (if (zerop (buffer-size))
5109 ;; Omit the date and other unnecessary stuff
5110 (org-agenda-cleanup-fancy-diary)
5111 ;; Add prefix to each line and extend the text properties
5112 (if (zerop (buffer-size))
5114 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5117 (insert entries) (goto-char (point-min))
5118 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5119 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5120 (replace-match (concat "; " (match-string 1)))))
5122 (set-buffer-modified-p nil)
5123 (kill-buffer diary-fancy-buffer)))
5125 (setq entries (org-split-string entries "\n"))
5129 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5130 ;; Extend the text properties to the beginning of the line
5131 (org-add-props x (text-properties-at (1- (length x)) x)
5132 'type "diary" 'date date 'face 'org-agenda-diary))
5135 (defvar org-agenda-cleanup-fancy-diary-hook nil
5136 "Hook run when the fancy diary buffer is cleaned up.")
5138 (defun org-agenda-cleanup-fancy-diary ()
5139 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5140 This gets rid of the date, the underline under the date, and
5141 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5142 date. It also removes lines that contain only whitespace."
5143 (goto-char (point-min))
5144 (if (looking-at ".*?:[ \t]*")
5147 (re-search-forward "\n=+$" nil t)
5149 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5150 (re-search-forward "\n=+$" nil t)
5151 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5152 (goto-char (point-min))
5153 (while (re-search-forward "^ +\n" nil t)
5155 (goto-char (point-min))
5156 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5158 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5160 ;; Make sure entries from the diary have the right text properties.
5161 (eval-after-load "diary-lib"
5162 '(if (boundp 'diary-modify-entry-list-string-function)
5163 ;; We can rely on the hook, nothing to do
5165 ;; Hook not available, must use advice to make this work
5166 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5167 "Make the position visible."
5168 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5171 (setq string (org-modify-diary-entry-string string))))))
5173 (defun org-modify-diary-entry-string (string)
5174 "Add text properties to string, allowing org-mode to act on it."
5175 (org-add-props string nil
5176 'mouse-face 'highlight
5177 'help-echo (if buffer-file-name
5178 (format "mouse-2 or RET jump to diary file %s"
5179 (abbreviate-file-name buffer-file-name))
5181 'org-agenda-diary-link t
5182 'org-marker (org-agenda-new-marker (point-at-bol))))
5184 (defun org-diary-default-entry ()
5185 "Add a dummy entry to the diary.
5186 Needed to avoid empty dates which mess up holiday display."
5187 ;; Catch the error if dealing with the new add-to-diary-alist
5188 (when org-disable-agenda-to-diary
5190 (org-add-to-diary-list original-date "Org-mode dummy" "")
5192 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5194 (defun org-add-to-diary-list (&rest args)
5195 (if (fboundp 'diary-add-to-list)
5196 (apply 'diary-add-to-list args)
5197 (apply 'add-to-diary-list args)))
5199 (defvar org-diary-last-run-time nil)
5202 (defun org-diary (&rest args)
5203 "Return diary information from org files.
5204 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5205 It accesses org files and extracts information from those files to be
5206 listed in the diary. The function accepts arguments specifying what
5207 items should be listed. For a list of arguments allowed here, see the
5208 variable `org-agenda-entry-types'.
5210 The call in the diary file should look like this:
5212 &%%(org-diary) ~/path/to/some/orgfile.org
5214 Use a separate line for each org file to check. Or, if you omit the file name,
5215 all files listed in `org-agenda-files' will be checked automatically:
5219 If you don't give any arguments (as in the example above), the default value
5220 of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
5221 So the example above may also be written as
5223 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5225 The function expects the lisp variables `entry' and `date' to be provided
5226 by the caller, because this is how the calendar works. Don't use this
5227 function from a program - use `org-agenda-get-day-entries' instead."
5228 (when (> (- (org-float-time)
5229 org-agenda-last-marker-time)
5231 ;; I am not sure if this works with sticky agendas, because the marker
5232 ;; list is then no longer a global variable.
5233 (org-agenda-reset-markers))
5234 (org-compile-prefix-format 'agenda)
5235 (org-set-sorting-strategy 'agenda)
5236 (setq args (or args org-agenda-entry-types))
5237 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5239 (org-agenda-files t)))
5240 (time (org-float-time))
5242 (when (or (not org-diary-last-run-time)
5244 org-diary-last-run-time)
5246 (org-agenda-prepare-buffers files))
5247 (setq org-diary-last-run-time time)
5248 ;; If this is called during org-agenda, don't return any entries to
5249 ;; the calendar. Org Agenda will list these entries itself.
5250 (if org-disable-agenda-to-diary (setq files nil))
5251 (while (setq file (pop files))
5252 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5253 (setq results (append results rtn)))
5256 (mapcar (lambda (i) (replace-regexp-in-string
5257 org-bracket-link-regexp "\\3" i)) results))
5258 (concat (org-agenda-finalize-entries results) "\n"))))
5260 ;;; Agenda entry finders
5262 (defun org-agenda-get-day-entries (file date &rest args)
5263 "Does the work for `org-diary' and `org-agenda'.
5264 FILE is the path to a file to be checked for entries. DATE is date like
5265 the one returned by `calendar-current-date'. ARGS are symbols indicating
5266 which kind of entries should be extracted. For details about these, see
5267 the documentation of `org-diary'."
5268 (setq args (or args org-agenda-entry-types))
5269 (let* ((org-startup-folded nil)
5270 (org-startup-align-all-tables nil)
5271 (buffer (if (file-exists-p file)
5272 (org-get-agenda-file-buffer file)
5273 (error "No such file %s" file)))
5274 arg results rtn deadline-results)
5276 ;; If file does not exist, make sure an error message ends up in diary
5277 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5278 (with-current-buffer buffer
5279 (unless (derived-mode-p 'org-mode)
5280 (error "Agenda file %s is not in `org-mode'" file))
5281 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5282 (let ((case-fold-search nil))
5285 (if (eq buffer org-agenda-restrict)
5286 (narrow-to-region org-agenda-restrict-begin
5287 org-agenda-restrict-end)
5289 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5290 (while (setq arg (pop args))
5292 ((and (eq arg :todo)
5293 (equal date (calendar-gregorian-from-absolute
5295 (setq rtn (org-agenda-get-todos))
5296 (setq results (append results rtn)))
5297 ((eq arg :timestamp)
5298 (setq rtn (org-agenda-get-blocks))
5299 (setq results (append results rtn))
5300 (setq rtn (org-agenda-get-timestamps deadline-results))
5301 (setq results (append results rtn)))
5303 (setq rtn (org-agenda-get-sexps))
5304 (setq results (append results rtn)))
5305 ((eq arg :scheduled)
5306 (setq rtn (org-agenda-get-scheduled deadline-results))
5307 (setq results (append results rtn)))
5308 ((eq arg :scheduled*)
5309 (setq rtn (org-agenda-get-scheduled deadline-results t))
5310 (setq results (append results rtn)))
5312 (setq rtn (org-agenda-get-progress))
5313 (setq results (append results rtn)))
5315 (setq rtn (org-agenda-get-deadlines))
5316 (setq deadline-results (copy-sequence rtn))
5317 (setq results (append results rtn)))
5318 ((eq arg :deadline*)
5319 (setq rtn (org-agenda-get-deadlines t))
5320 (setq deadline-results (copy-sequence rtn))
5321 (setq results (append results rtn))))))))
5324 (defsubst org-em (x y list)
5325 "Is X or Y a member of LIST?"
5326 (or (memq x list) (memq y list)))
5328 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5329 (defvar org-agenda-sorting-strategy-selected nil)
5331 (defun org-agenda-get-todos ()
5332 "Return the TODO information for agenda display."
5333 (let* ((props (list 'face nil
5334 'done-face 'org-agenda-done
5335 'org-not-done-regexp org-not-done-regexp
5336 'org-todo-regexp org-todo-regexp
5337 'org-complex-heading-regexp org-complex-heading-regexp
5338 'mouse-face 'highlight
5340 (format "mouse-2 or RET jump to org file %s"
5341 (abbreviate-file-name buffer-file-name))))
5342 (regexp (format org-heading-keyword-regexp-format
5344 ((and org-select-this-todo-keyword
5345 (equal org-select-this-todo-keyword "*"))
5347 (org-select-this-todo-keyword
5349 (mapconcat 'identity
5351 org-select-this-todo-keyword
5354 (t org-not-done-regexp))))
5355 marker priority category category-pos level tags todo-state ts-date ts-date-type
5356 ee txt beg end inherited-tags todo-state-end-pos)
5357 (goto-char (point-min))
5358 (while (re-search-forward regexp nil t)
5363 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5364 (unless (and (setq todo-state (org-get-todo-state))
5365 (setq todo-state-end-pos (match-end 2)))
5368 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5369 (goto-char (1+ beg))
5370 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5372 (goto-char (match-beginning 2))
5373 (setq marker (org-agenda-new-marker (match-beginning 0))
5374 category (org-get-category)
5377 (cond ((org-em 'scheduled-up 'scheduled-down
5378 org-agenda-sorting-strategy-selected)
5379 (setq ts (org-entry-get (point) "SCHEDULED")
5380 ts-date-type " scheduled"))
5381 ((org-em 'deadline-up 'deadline-down
5382 org-agenda-sorting-strategy-selected)
5383 (setq ts (org-entry-get (point) "DEADLINE")
5384 ts-date-type " deadline"))
5385 ((org-em 'ts-up 'ts-down
5386 org-agenda-sorting-strategy-selected)
5387 (setq ts (org-entry-get (point) "TIMESTAMP")
5388 ts-date-type " timestamp"))
5389 ((org-em 'tsia-up 'tsia-down
5390 org-agenda-sorting-strategy-selected)
5391 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
5392 ts-date-type " timestamp_ia"))
5393 ((org-em 'timestamp-up 'timestamp-down
5394 org-agenda-sorting-strategy-selected)
5395 (setq ts (or (org-entry-get (point) "SCHEDULED")
5396 (org-entry-get (point) "DEADLINE")
5397 (org-entry-get (point) "TIMESTAMP")
5398 (org-entry-get (point) "TIMESTAMP_IA"))
5400 (t (setq ts-date-type "")))
5401 (when ts (ignore-errors (org-time-string-to-absolute ts)))))
5402 category-pos (get-text-property (point) 'org-category-position)
5404 (buffer-substring (match-beginning 2) (match-end 0)))
5406 (or (eq org-agenda-show-inherited-tags 'always)
5407 (and (listp org-agenda-show-inherited-tags)
5408 (memq 'todo org-agenda-show-inherited-tags))
5409 (and (eq org-agenda-show-inherited-tags t)
5410 (or (eq org-agenda-use-tag-inheritance t)
5411 (memq 'todo org-agenda-use-tag-inheritance))))
5412 tags (org-get-tags-at nil (not inherited-tags))
5413 level (make-string (org-reduced-level (org-outline-level)) ? )
5414 txt (org-agenda-format-item "" txt level category tags t)
5415 priority (1+ (org-get-priority txt)))
5416 (org-add-props txt props
5417 'org-marker marker 'org-hd-marker marker
5418 'priority priority 'org-category category
5421 'org-category-position category-pos
5422 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5424 (if org-agenda-todo-list-sublevels
5425 (goto-char todo-state-end-pos)
5426 (org-end-of-subtree 'invisible))))
5429 (defun org-agenda-todo-custom-ignore-p (time n)
5430 "Check whether timestamp is farther away than n number of days.
5431 This function is invoked if `org-agenda-todo-ignore-deadlines',
5432 `org-agenda-todo-ignore-scheduled' or
5433 `org-agenda-todo-ignore-timestamp' is set to an integer."
5434 (let ((days (org-time-stamp-to-now
5435 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5440 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5442 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5443 (when (or org-agenda-todo-ignore-with-date
5444 org-agenda-todo-ignore-scheduled
5445 org-agenda-todo-ignore-deadlines
5446 org-agenda-todo-ignore-timestamp)
5447 (setq end (or end (save-excursion (outline-next-heading) (point))))
5449 (or (and org-agenda-todo-ignore-with-date
5450 (re-search-forward org-ts-regexp end t))
5451 (and org-agenda-todo-ignore-scheduled
5452 (re-search-forward org-scheduled-time-regexp end t)
5454 ((eq org-agenda-todo-ignore-scheduled 'future)
5455 (> (org-time-stamp-to-now
5456 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5457 ((eq org-agenda-todo-ignore-scheduled 'past)
5458 (<= (org-time-stamp-to-now
5459 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5460 ((numberp org-agenda-todo-ignore-scheduled)
5461 (org-agenda-todo-custom-ignore-p
5462 (match-string 1) org-agenda-todo-ignore-scheduled))
5464 (and org-agenda-todo-ignore-deadlines
5465 (re-search-forward org-deadline-time-regexp end t)
5467 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5468 ((eq org-agenda-todo-ignore-deadlines 'far)
5469 (not (org-deadline-close (match-string 1))))
5470 ((eq org-agenda-todo-ignore-deadlines 'future)
5471 (> (org-time-stamp-to-now
5472 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5473 ((eq org-agenda-todo-ignore-deadlines 'past)
5474 (<= (org-time-stamp-to-now
5475 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5476 ((numberp org-agenda-todo-ignore-deadlines)
5477 (org-agenda-todo-custom-ignore-p
5478 (match-string 1) org-agenda-todo-ignore-deadlines))
5479 (t (org-deadline-close (match-string 1)))))
5480 (and org-agenda-todo-ignore-timestamp
5481 (let ((buffer (current-buffer))
5484 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5486 ;; Copy current buffer into a temporary one
5488 (insert-buffer-substring buffer start end)
5489 (goto-char (point-min))
5490 ;; Delete SCHEDULED and DEADLINE items
5491 (while (re-search-forward regexp end t)
5492 (delete-region (match-beginning 0) (match-end 0)))
5493 (goto-char (point-min))
5494 ;; No search for timestamp left
5495 (when (re-search-forward org-ts-regexp nil t)
5497 ((eq org-agenda-todo-ignore-timestamp 'future)
5498 (> (org-time-stamp-to-now
5499 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5500 ((eq org-agenda-todo-ignore-timestamp 'past)
5501 (<= (org-time-stamp-to-now
5502 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5503 ((numberp org-agenda-todo-ignore-timestamp)
5504 (org-agenda-todo-custom-ignore-p
5505 (match-string 1) org-agenda-todo-ignore-timestamp))
5508 (defun org-agenda-get-timestamps (&optional deadline-results)
5509 "Return the date stamp information for agenda display."
5510 (let* ((props (list 'face 'org-agenda-calendar-event
5511 'org-not-done-regexp org-not-done-regexp
5512 'org-todo-regexp org-todo-regexp
5513 'org-complex-heading-regexp org-complex-heading-regexp
5514 'mouse-face 'highlight
5516 (format "mouse-2 or RET jump to org file %s"
5517 (abbreviate-file-name buffer-file-name))))
5518 (d1 (calendar-absolute-from-gregorian date))
5520 (deadline-position-alist
5521 (mapcar (lambda (a) (and (setq mm (get-text-property
5522 0 'org-hd-marker a))
5523 (cons (marker-position mm) a)))
5525 (remove-re org-ts-regexp)
5528 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5532 (car org-time-stamp-formats)
5533 (apply 'encode-time ; DATE bound by calendar
5534 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5536 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5537 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5538 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5539 donep tmp priority category category-pos level ee txt timestr tags
5540 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5541 inherited-tags ts-date)
5542 (goto-char (point-min))
5543 (while (setq end-of-match (re-search-forward regexp nil t))
5544 (setq b0 (match-beginning 0)
5545 b3 (match-beginning 3) e3 (match-end 3)
5546 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5547 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5548 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5550 org-agenda-repeating-timestamp-show-all)))
5552 (and (org-at-date-range-p) (throw :skip nil))
5554 (if (and (match-end 1)
5555 (not (= d1 (org-time-string-to-absolute
5556 (match-string 1) d1 nil show-all
5557 (current-buffer) b0))))
5560 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5562 (setq tmp (buffer-substring (max (point-min)
5563 (- b0 org-ds-keyword-length))
5565 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5566 inactivep (= (char-after b0) ?\[)
5567 deadlinep (string-match org-deadline-regexp tmp)
5568 scheduledp (string-match org-scheduled-regexp tmp)
5569 closedp (and org-agenda-include-inactive-timestamps
5570 (string-match org-closed-string tmp))
5571 clockp (and org-agenda-include-inactive-timestamps
5572 (or (string-match org-clock-string tmp)
5573 (string-match "]-+\\'" tmp)))
5574 warntime (get-text-property (point) 'org-appt-warntime)
5575 donep (member todo-state org-done-keywords))
5576 (if (or scheduledp deadlinep closedp clockp
5577 (and donep org-agenda-skip-timestamp-if-done))
5579 (if (string-match ">" timestr)
5580 ;; substring should only run to end of time stamp
5581 (setq timestr (substring timestr 0 (match-end 0))))
5582 (setq marker (org-agenda-new-marker b0)
5583 category (org-get-category b0)
5584 category-pos (get-text-property b0 'org-category-position))
5586 (if (not (re-search-backward org-outline-regexp-bol nil t))
5588 (goto-char (match-beginning 0))
5589 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5590 (assoc (point) deadline-position-alist))
5592 (setq hdmarker (org-agenda-new-marker)
5594 (or (eq org-agenda-show-inherited-tags 'always)
5595 (and (listp org-agenda-show-inherited-tags)
5596 (memq 'agenda org-agenda-show-inherited-tags))
5597 (and (eq org-agenda-show-inherited-tags t)
5598 (or (eq org-agenda-use-tag-inheritance t)
5599 (memq 'agenda org-agenda-use-tag-inheritance))))
5600 tags (org-get-tags-at nil (not inherited-tags))
5601 level (make-string (org-reduced-level (org-outline-level)) ? ))
5602 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5603 (setq head (or (match-string 1) ""))
5604 (setq txt (org-agenda-format-item
5605 (if inactivep org-agenda-inactive-leader nil)
5606 head level category tags timestr
5608 (setq priority (org-get-priority txt))
5609 (org-add-props txt props 'priority priority
5610 'org-marker marker 'org-hd-marker hdmarker
5611 'org-category category 'date date
5614 (ignore-errors (org-time-string-to-absolute timestr))
5615 'org-category-position category-pos
5616 'todo-state todo-state
5620 (if org-agenda-skip-additional-timestamps-same-entry
5621 (outline-next-heading)
5622 (goto-char end-of-match))))
5625 (defun org-agenda-get-sexps ()
5626 "Return the sexp information for agenda display."
5627 (require 'diary-lib)
5628 (let* ((props (list 'face 'org-agenda-calendar-sexp
5629 'mouse-face 'highlight
5631 (format "mouse-2 or RET jump to org file %s"
5632 (abbreviate-file-name buffer-file-name))))
5634 marker category extra category-pos level ee txt tags entry
5635 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5636 (goto-char (point-min))
5637 (while (re-search-forward regexp nil t)
5640 (setq beg (match-beginning 0))
5641 (goto-char (1- (match-end 0)))
5644 (setq sexp (buffer-substring b (point)))
5645 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5646 (org-trim (match-string 1))
5648 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5650 (setq marker (org-agenda-new-marker beg)
5651 level (make-string (org-reduced-level (org-outline-level)) ? )
5652 category (org-get-category beg)
5653 category-pos (get-text-property beg 'org-category-position)
5655 (or (eq org-agenda-show-inherited-tags 'always)
5656 (and (listp org-agenda-show-inherited-tags)
5657 (memq 'agenda org-agenda-show-inherited-tags))
5658 (and (eq org-agenda-show-inherited-tags t)
5659 (or (eq org-agenda-use-tag-inheritance t)
5660 (memq 'agenda org-agenda-use-tag-inheritance))))
5661 tags (org-get-tags-at nil (not inherited-tags))
5662 todo-state (org-get-todo-state)
5663 warntime (get-text-property (point) 'org-appt-warntime)
5666 (dolist (r (if (stringp result)
5668 result)) ;; we expect a list here
5669 (when (and org-agenda-diary-sexp-prefix
5670 (string-match org-agenda-diary-sexp-prefix r))
5671 (setq extra (match-string 0 r)
5672 r (replace-match "" nil nil r)))
5673 (if (string-match "\\S-" r)
5675 (setq txt "SEXP entry returned empty string"))
5676 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5677 (org-add-props txt props 'org-marker marker
5678 'org-category category 'date date 'todo-state todo-state
5679 'org-category-position category-pos 'tags tags
5681 'type "sexp" 'warntime warntime)
5685 ;; Calendar sanity: define some functions that are independent of
5686 ;; `calendar-date-style'.
5687 ;; Normally I would like to use ISO format when calling the diary functions,
5688 ;; but to make sure we still have Emacs 22 compatibility we bind
5689 ;; also `european-calendar-style' and use european format
5690 (defun org-anniversary (year month day &optional mark)
5691 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5693 (let ((calendar-date-style 'european) (european-calendar-style t))
5694 (diary-anniversary day month year mark))))
5695 (defun org-cyclic (N year month day &optional mark)
5696 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5698 (let ((calendar-date-style 'european) (european-calendar-style t))
5699 (diary-cyclic N day month year mark))))
5700 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5701 "Like `diary-block', but with fixed (ISO) order of arguments."
5703 (let ((calendar-date-style 'european) (european-calendar-style t))
5704 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5705 (defun org-date (year month day &optional mark)
5706 "Like `diary-date', but with fixed (ISO) order of arguments."
5708 (let ((calendar-date-style 'european) (european-calendar-style t))
5709 (diary-date day month year mark))))
5711 ;; Define the` org-class' function
5712 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5713 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5714 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5715 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5716 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5717 `holidays', then any date that is known by the Emacs calendar to be a
5718 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5719 then those holidays will be skipped."
5720 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5721 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5722 (d (calendar-absolute-from-gregorian date))
5723 (h (when skip-weeks (calendar-check-holidays date))))
5727 (= (calendar-day-of-week date) dayname)
5728 (or (not skip-weeks)
5731 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5732 (not (or (and h (memq 'holidays skip-weeks))
5733 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5736 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5737 "Like `org-class', but honor `calendar-date-style'.
5738 The order of the first 2 times 3 arguments depends on the variable
5739 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5740 So for American calendars, give this as MONTH DAY YEAR, for European as
5741 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5742 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5743 is any number of ISO weeks in the block period for which the item should
5746 This function is here only for backward compatibility and it is deprecated,
5747 please use `org-class' instead."
5748 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5749 (date2 (org-order-calendar-date-args m2 d2 y2)))
5751 (nth 2 date1) (car date1) (nth 1 date1)
5752 (nth 2 date2) (car date2) (nth 1 date2)
5753 dayname skip-weeks)))
5754 (make-obsolete 'org-diary-class 'org-class "")
5756 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5757 (defalias 'org-get-closed 'org-agenda-get-progress)
5758 (defun org-agenda-get-progress ()
5759 "Return the logged TODO entries for agenda display."
5760 (let* ((props (list 'mouse-face 'highlight
5761 'org-not-done-regexp org-not-done-regexp
5762 'org-todo-regexp org-todo-regexp
5763 'org-complex-heading-regexp org-complex-heading-regexp
5765 (format "mouse-2 or RET jump to org file %s"
5766 (abbreviate-file-name buffer-file-name))))
5767 (items (if (consp org-agenda-show-log-scoped)
5768 org-agenda-show-log-scoped
5769 (if (eq org-agenda-show-log-scoped 'clockcheck)
5771 org-agenda-log-mode-items)))
5775 (if (memq 'closed items) (concat "\\<" org-closed-string))
5776 (if (memq 'clock items) (concat "\\<" org-clock-string))
5777 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5778 (parts-re (if parts (mapconcat 'identity parts "\\|")
5779 (error "`org-agenda-log-mode-items' is empty")))
5781 "\\(" parts-re "\\)"
5786 (car org-time-stamp-formats)
5787 (apply 'encode-time ; DATE bound by calendar
5788 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5790 (org-agenda-search-headline-for-time nil)
5791 marker hdmarker priority category category-pos level tags closedp
5792 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5793 (goto-char (point-min))
5794 (while (re-search-forward regexp nil t)
5797 (setq marker (org-agenda-new-marker (match-beginning 0))
5798 closedp (equal (match-string 1) org-closed-string)
5799 statep (equal (string-to-char (match-string 1)) ?-)
5800 clockp (not (or closedp statep))
5801 state (and statep (match-string 2))
5802 category (org-get-category (match-beginning 0))
5803 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5804 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5805 (when (string-match "\\]" timestr)
5806 ;; substring should only run to end of time stamp
5807 (setq rest (substring timestr (match-end 0))
5808 timestr (substring timestr 0 (match-end 0)))
5809 (if (and (not closedp) (not statep)
5810 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5812 (progn (setq timestr (concat (substring timestr 0 -1)
5813 "-" (match-string 1 rest) "]"))
5814 (setq clocked (match-string 2 rest)))
5815 (setq clocked "-")))
5819 ((not org-agenda-log-mode-add-notes) nil)
5821 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5824 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5825 (match-string 1)))))
5826 (if (not (re-search-backward org-outline-regexp-bol nil t))
5828 (goto-char (match-beginning 0))
5829 (setq hdmarker (org-agenda-new-marker)
5831 (or (eq org-agenda-show-inherited-tags 'always)
5832 (and (listp org-agenda-show-inherited-tags)
5833 (memq 'todo org-agenda-show-inherited-tags))
5834 (and (eq org-agenda-show-inherited-tags t)
5835 (or (eq org-agenda-use-tag-inheritance t)
5836 (memq 'todo org-agenda-use-tag-inheritance))))
5837 tags (org-get-tags-at nil (not inherited-tags))
5838 level (make-string (org-reduced-level (org-outline-level)) ? ))
5839 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5840 (setq txt (match-string 1))
5842 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5843 (setq txt (concat (substring txt 0 (match-beginning 1))
5844 " - " extra " " (match-string 2 txt)))
5845 (setq txt (concat txt " - " extra))))
5846 (setq txt (org-agenda-format-item
5848 (closedp "Closed: ")
5849 (statep (concat "State: (" state ")"))
5850 (t (concat "Clocked: (" clocked ")")))
5851 txt level category tags timestr)))
5852 (setq priority 100000)
5853 (org-add-props txt props
5854 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5855 'priority priority 'org-category category
5856 'org-category-position category-pos
5858 'type "closed" 'date date
5859 'undone-face 'org-warning 'done-face 'org-agenda-done)
5861 (goto-char (point-at-eol))))
5864 (defun org-agenda-show-clocking-issues ()
5865 "Add overlays, showing issues with clocking.
5866 See also the user option `org-agenda-clock-consistency-checks'."
5868 (let* ((org-time-clocksum-use-effort-durations nil)
5869 (pl org-agenda-clock-consistency-checks)
5870 (re (concat "^[ \t]*"
5873 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5874 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5877 (maxtime (org-hh:mm-string-to-minutes
5878 (or (plist-get pl :max-duration) "24:00")))
5879 (mintime (org-hh:mm-string-to-minutes
5880 (or (plist-get pl :min-duration) 0)))
5881 (maxgap (org-hh:mm-string-to-minutes
5882 ;; default 30:00 means never complain
5883 (or (plist-get pl :max-gap) "30:00")))
5884 (gapok (mapcar 'org-hh:mm-string-to-minutes
5885 (plist-get pl :gap-ok-around)))
5886 (def-face (or (plist-get pl :default-face)
5887 '((:background "DarkRed") (:foreground "white"))))
5888 issue face m te ts dt ov)
5889 (goto-char (point-min))
5890 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5891 (setq issue nil face def-face)
5893 (setq m (org-get-at-bol 'org-marker)
5895 (unless (and m (markerp m))
5896 (setq issue "No valid clock line") (throw 'next t))
5897 (org-with-point-at m
5899 (goto-char (point-at-bol))
5900 (unless (looking-at re)
5901 (error "No valid Clock line")
5903 (unless (match-end 3)
5904 (setq issue "No end time"
5905 face (or (plist-get pl :no-end-time-face) face))
5907 (setq ts (match-string 1)
5910 (apply 'encode-time (org-parse-time-string ts)))
5912 (apply 'encode-time (org-parse-time-string te)))
5915 ((> dt (* 60 maxtime))
5916 ;; a very long clocking chunk
5917 (setq issue (format "Clocking interval is very long: %s"
5918 (org-minutes-to-clocksum-string
5919 (floor (/ (float dt) 60.))))
5920 face (or (plist-get pl :long-face) face)))
5921 ((< dt (* 60 mintime))
5922 ;; a very short clocking chunk
5923 (setq issue (format "Clocking interval is very short: %s"
5924 (org-minutes-to-clocksum-string
5925 (floor (/ (float dt) 60.))))
5926 face (or (plist-get pl :short-face) face)))
5927 ((and (> tlend 0) (< ts tlend))
5928 ;; Two clock entries are overlapping
5929 (setq issue (format "Clocking overlap: %d minutes"
5930 (/ (- tlend ts) 60))
5931 face (or (plist-get pl :overlap-face) face)))
5932 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5933 ;; There is a gap, lets see if we need to report it
5934 (unless (org-agenda-check-clock-gap tlend ts gapok)
5935 (setq issue (format "Clocking gap: %d minutes"
5936 (/ (- ts tlend) 60))
5937 face (or (plist-get pl :gap-face) face))))
5939 (setq tlend (or te tlend) tlstart (or ts tlstart))
5941 ;; OK, there was some issue, add an overlay to show the issue
5942 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5943 (overlay-put ov 'before-string
5946 (format "%-43s" (concat " " issue))
5950 (overlay-put ov 'evaporate t)))))
5952 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5953 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5956 ;; there are no OK times for gaps...
5958 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5959 ;; This is more than 24 hours, so it is OK.
5960 ;; because we have at least one OK time, that must be in the
5961 ;; 24 hour interval.
5963 ;; We have a shorter gap.
5964 ;; Now we have to get the minute of the day when these times are
5965 (let* ((t1dec (decode-time (seconds-to-time t1)))
5966 (t2dec (decode-time (seconds-to-time t2)))
5967 ;; compute the minute on the day
5968 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5969 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5971 ;; if min2 is smaller than min1, this means it is on the next day.
5972 ;; Wrap it to after midnight.
5973 (setq min2 (+ min2 1440)))
5974 ;; Now check if any of the OK times is in the gap
5976 ;; Wrap the time to after midnight if necessary
5977 (if (< x min1) (setq x (+ x 1440)))
5978 ;; Check if in interval
5979 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5981 ;; Nope, this gap is not OK
5984 (defun org-agenda-get-deadlines (&optional with-hour)
5985 "Return the deadline information for agenda display.
5986 When WITH-HOUR is non-nil, only return deadlines with an hour
5987 specification like [h]h:mm."
5988 (let* ((props (list 'mouse-face 'highlight
5989 'org-not-done-regexp org-not-done-regexp
5990 'org-todo-regexp org-todo-regexp
5991 'org-complex-heading-regexp org-complex-heading-regexp
5993 (format "mouse-2 or RET jump to org file %s"
5994 (abbreviate-file-name buffer-file-name))))
5995 (regexp (if with-hour
5996 org-deadline-time-hour-regexp
5997 org-deadline-time-regexp))
5998 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5999 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6000 (dl0 (car org-agenda-deadline-leaders))
6001 (dl1 (nth 1 org-agenda-deadline-leaders))
6002 (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
6003 d2 diff dfrac wdays pos pos1 category category-pos level
6004 tags suppress-prewarning ee txt head face s todo-state
6005 show-all upcomingp donep timestr warntime inherited-tags ts-date)
6006 (goto-char (point-min))
6007 (while (re-search-forward regexp nil t)
6010 (setq s (match-string 1)
6012 pos (1- (match-beginning 1))
6013 todo-state (save-match-data (org-get-todo-state))
6014 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6016 org-agenda-repeating-timestamp-show-all))
6017 d2 (org-time-string-to-absolute
6018 s d1 'past show-all (current-buffer) pos)
6020 (setq suppress-prewarning
6021 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
6022 (let ((item (buffer-substring (point-at-bol)
6026 org-scheduled-time-regexp item)
6027 (match-string 1 item)))))))
6030 ;; The current item has a scheduled date (in ds), so
6031 ;; evaluate its prewarning lead time.
6032 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
6033 ;; Use global prewarning-restart lead time.
6034 org-agenda-skip-deadline-prewarning-if-scheduled)
6035 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
6037 ;; Set prewarning to no earlier than scheduled.
6038 (min (- d2 (org-time-string-to-absolute
6039 ds d1 'past show-all (current-buffer) pos))
6040 org-deadline-warning-days))
6041 ;; Set prewarning to deadline.
6043 (setq wdays (if suppress-prewarning
6044 (let ((org-deadline-warning-days suppress-prewarning))
6047 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
6048 upcomingp (and todayp (> diff 0)))
6049 ;; When to show a deadline in the calendar:
6050 ;; If the expiration is within wdays warning time.
6051 ;; Past-due deadlines are only shown on the current date
6052 (if (and (or (and (<= diff wdays)
6053 (and todayp (not org-agenda-only-exact-dates)))
6056 ;; (setq todo-state (org-get-todo-state))
6057 (setq donep (member todo-state org-done-keywords))
6059 (or org-agenda-skip-deadline-if-done
6062 (setq category (org-get-category)
6063 warntime (get-text-property (point) 'org-appt-warntime)
6064 category-pos (get-text-property (point) 'org-category-position))
6065 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6067 (goto-char (match-end 0))
6068 (setq pos1 (match-beginning 0))
6069 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6070 (setq inherited-tags
6071 (or (eq org-agenda-show-inherited-tags 'always)
6072 (and (listp org-agenda-show-inherited-tags)
6073 (memq 'agenda org-agenda-show-inherited-tags))
6074 (and (eq org-agenda-show-inherited-tags t)
6075 (or (eq org-agenda-use-tag-inheritance t)
6076 (memq 'agenda org-agenda-use-tag-inheritance))))
6077 tags (org-get-tags-at pos1 (not inherited-tags)))
6078 (setq head (buffer-substring
6080 (progn (skip-chars-forward "^\r\n")
6082 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6084 (concat (substring s (match-beginning 1)) " "))
6085 (setq timestr 'time))
6086 (setq txt (org-agenda-format-item
6087 (cond ((= diff 0) dl0)
6090 (funcall dl1 diff date)
6094 (funcall dl2 diff date)
6095 (format dl2 (if (string= dl2 dl1)
6096 diff (abs diff))))))
6097 head level category tags
6098 (if (not (= diff 0)) nil timestr)))))
6100 (setq face (org-agenda-deadline-face dfrac))
6101 (org-add-props txt props
6102 'org-marker (org-agenda-new-marker pos)
6106 'org-hd-marker (org-agenda-new-marker pos1)
6107 'priority (+ (- diff)
6108 (org-get-priority txt))
6109 'org-category category
6110 'org-category-position category-pos
6111 'todo-state todo-state
6112 'type (if upcomingp "upcoming-deadline" "deadline")
6113 'date (if upcomingp date d2)
6114 'face (if donep 'org-agenda-done face)
6115 'undone-face face 'done-face 'org-agenda-done)
6119 (defun org-agenda-deadline-face (fraction)
6120 "Return the face to displaying a deadline item.
6121 FRACTION is what fraction of the head-warning time has passed."
6122 (let ((faces org-agenda-deadline-faces) f)
6124 (while (setq f (pop faces))
6125 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6127 (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
6128 "Return the scheduled information for agenda display.
6129 When WITH-HOUR is non-nil, only return scheduled items with
6130 an hour specification like [h]h:mm."
6131 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6132 'org-todo-regexp org-todo-regexp
6133 'org-complex-heading-regexp org-complex-heading-regexp
6134 'done-face 'org-agenda-done
6135 'mouse-face 'highlight
6137 (format "mouse-2 or RET jump to org file %s"
6138 (abbreviate-file-name buffer-file-name))))
6139 (regexp (if with-hour
6140 org-scheduled-time-hour-regexp
6141 org-scheduled-time-regexp))
6142 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6143 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6145 (deadline-position-alist
6146 (mapcar (lambda (a) (and (setq mm (get-text-property
6147 0 'org-hd-marker a))
6148 (cons (marker-position mm) a)))
6150 d2 diff pos pos1 category category-pos level tags donep
6151 ee txt head pastschedp todo-state face timestr s habitp show-all
6152 did-habit-check-p warntime inherited-tags ts-date suppress-delay
6154 (goto-char (point-min))
6155 (while (re-search-forward regexp nil t)
6158 (setq s (match-string 1)
6160 pos (1- (match-beginning 1))
6161 todo-state (save-match-data (org-get-todo-state))
6162 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6164 org-agenda-repeating-timestamp-show-all))
6165 d2 (org-time-string-to-absolute
6166 s d1 'past show-all (current-buffer) pos)
6168 warntime (get-text-property (point) 'org-appt-warntime))
6169 (setq pastschedp (and todayp (< diff 0)))
6170 (setq did-habit-check-p nil)
6171 (setq suppress-delay
6172 (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
6173 (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
6176 org-deadline-time-regexp item)
6177 (match-string 1 item)))))))
6180 ;; The current item has a deadline date (in ds), so
6181 ;; evaluate its delay time.
6182 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6183 ;; Use global delay time.
6184 (- org-agenda-skip-scheduled-delay-if-deadline))
6185 ((eq org-agenda-skip-scheduled-delay-if-deadline
6187 ;; Set delay to no later than deadline.
6188 (min (- d2 (org-time-string-to-absolute
6189 ds d1 'past show-all (current-buffer) pos))
6190 org-scheduled-delay-days))
6192 (setq ddays (if suppress-delay
6193 (let ((org-scheduled-delay-days suppress-delay))
6194 (org-get-wdays s t t))
6195 (org-get-wdays s t)))
6196 ;; Use a delay of 0 when there is a repeater and the delay is
6198 (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6199 (< (org-time-string-to-absolute s)
6200 (org-time-string-to-absolute
6201 s d2 'past nil (current-buffer) pos)))
6203 ;; When to show a scheduled item in the calendar:
6204 ;; If it is on or past the date.
6205 (when (or (and (> ddays 0) (= diff (- ddays)))
6206 (and (zerop ddays) (= diff 0))
6207 (and (< (+ diff ddays) 0)
6208 (< (abs diff) org-scheduled-past-days)
6209 (and todayp (not org-agenda-only-exact-dates)))
6210 ;; org-is-habit-p uses org-entry-get, which is expansive
6211 ;; so we go extra mile to only call it once
6213 (boundp 'org-habit-show-all-today)
6214 org-habit-show-all-today
6215 (setq did-habit-check-p t)
6216 (setq habitp (and (functionp 'org-is-habit-p)
6217 (org-is-habit-p)))))
6219 (setq donep (member todo-state org-done-keywords))
6221 (or org-agenda-skip-scheduled-if-done
6223 (and (functionp 'org-is-habit-p)
6226 (setq habitp (if did-habit-check-p habitp
6227 (and (functionp 'org-is-habit-p)
6229 (setq category (org-get-category)
6230 category-pos (get-text-property (point) 'org-category-position))
6231 (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
6232 'repeated-after-deadline)
6233 (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
6235 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6237 (goto-char (match-end 0))
6238 (setq pos1 (match-beginning 0))
6240 (if (or (not org-habit-show-habits)
6242 (boundp 'org-habit-show-habits-only-for-today)
6243 org-habit-show-habits-only-for-today))
6246 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6247 (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
6249 (setq mm (assoc pos1 deadline-position-alist)))
6251 (setq inherited-tags
6252 (or (eq org-agenda-show-inherited-tags 'always)
6253 (and (listp org-agenda-show-inherited-tags)
6254 (memq 'agenda org-agenda-show-inherited-tags))
6255 (and (eq org-agenda-show-inherited-tags t)
6256 (or (eq org-agenda-use-tag-inheritance t)
6257 (memq 'agenda org-agenda-use-tag-inheritance))))
6259 tags (org-get-tags-at nil (not inherited-tags)))
6260 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6261 (setq head (buffer-substring
6263 (progn (skip-chars-forward "^\r\n") (point))))
6264 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6266 (concat (substring s (match-beginning 1)) " "))
6267 (setq timestr 'time))
6268 (setq txt (org-agenda-format-item
6270 (car org-agenda-scheduled-leaders)
6271 (format (nth 1 org-agenda-scheduled-leaders)
6273 head level category tags
6274 (if (not (= diff 0)) nil timestr)
6279 ((and (not habitp) pastschedp)
6280 'org-scheduled-previously)
6281 (todayp 'org-scheduled-today)
6283 habitp (and habitp (org-habit-parse-todo)))
6284 (org-add-props txt props
6286 'face (if donep 'org-agenda-done face)
6287 'org-marker (org-agenda-new-marker pos)
6288 'org-hd-marker (org-agenda-new-marker pos1)
6289 'type (if pastschedp "past-scheduled" "scheduled")
6290 'date (if pastschedp d2 date)
6294 'priority (if habitp
6295 (org-habit-get-priority habitp)
6296 (+ 94 (- 5 diff) (org-get-priority txt)))
6297 'org-category category
6298 'category-position category-pos
6300 'todo-state todo-state)
6304 (defun org-agenda-get-blocks ()
6305 "Return the date-range information for agenda display."
6306 (let* ((props (list 'face nil
6307 'org-not-done-regexp org-not-done-regexp
6308 'org-todo-regexp org-todo-regexp
6309 'org-complex-heading-regexp org-complex-heading-regexp
6310 'mouse-face 'highlight
6312 (format "mouse-2 or RET jump to org file %s"
6313 (abbreviate-file-name buffer-file-name))))
6314 (regexp org-tr-regexp)
6315 (d0 (calendar-absolute-from-gregorian date))
6316 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6317 level todo-state tags pos head donep inherited-tags)
6318 (goto-char (point-min))
6319 (while (re-search-forward regexp nil t)
6323 (let ((start-time (match-string 1))
6324 (end-time (match-string 2)))
6325 (setq s1 (match-string 1)
6327 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6328 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6329 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6330 ;; Only allow days between the limits, because the normal
6331 ;; date stamps will catch the limits.
6333 (setq todo-state (org-get-todo-state))
6334 (setq donep (member todo-state org-done-keywords))
6335 (if (and donep org-agenda-skip-timestamp-if-done)
6337 (setq marker (org-agenda-new-marker (point)))
6338 (setq category (org-get-category)
6339 category-pos (get-text-property (point) 'org-category-position))
6340 (if (not (re-search-backward org-outline-regexp-bol nil t))
6342 (goto-char (match-beginning 0))
6343 (setq hdmarker (org-agenda-new-marker (point))
6345 (or (eq org-agenda-show-inherited-tags 'always)
6346 (and (listp org-agenda-show-inherited-tags)
6347 (memq 'agenda org-agenda-show-inherited-tags))
6348 (and (eq org-agenda-show-inherited-tags t)
6349 (or (eq org-agenda-use-tag-inheritance t)
6350 (memq 'agenda org-agenda-use-tag-inheritance))))
6352 tags (org-get-tags-at nil (not inherited-tags)))
6353 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6354 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6355 (setq head (match-string 1))
6357 (if org-agenda-remove-timeranges-from-blocks
6359 "<" (regexp-quote s1) ".*?>"
6361 "<" (regexp-quote s2) ".*?>")
6363 (setq txt (org-agenda-format-item
6365 (nth (if (= d1 d2) 0 1)
6366 org-agenda-timerange-leaders)
6367 (1+ (- d0 d1)) (1+ (- d2 d1)))
6368 head level category tags
6369 (cond ((and (= d1 d0) (= d2 d0))
6370 (concat "<" start-time ">--<" end-time ">"))
6372 (concat "<" start-time ">"))
6374 (concat "<" end-time ">")))
6376 (org-add-props txt props
6377 'org-marker marker 'org-hd-marker hdmarker
6378 'type "block" 'date date
6380 'todo-state todo-state
6381 'priority (org-get-priority txt) 'org-category category
6382 'org-category-position category-pos)
6385 ;; Sort the entries by expiration date.
6388 ;;; Agenda presentation and sorting
6390 (defvar org-prefix-has-time nil
6391 "A flag, set by `org-compile-prefix-format'.
6392 The flag is set if the currently compiled format contains a `%t'.")
6393 (defvar org-prefix-has-tag nil
6394 "A flag, set by `org-compile-prefix-format'.
6395 The flag is set if the currently compiled format contains a `%T'.")
6396 (defvar org-prefix-has-effort nil
6397 "A flag, set by `org-compile-prefix-format'.
6398 The flag is set if the currently compiled format contains a `%e'.")
6399 (defvar org-prefix-has-breadcrumbs nil
6400 "A flag, set by `org-compile-prefix-format'.
6401 The flag is set if the currently compiled format contains a `%b'.")
6402 (defvar org-prefix-category-length nil
6403 "Used by `org-compile-prefix-format' to remember the category field width.")
6404 (defvar org-prefix-category-max-length nil
6405 "Used by `org-compile-prefix-format' to remember the category field width.")
6407 (defun org-agenda-get-category-icon (category)
6408 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6409 (dolist (entry org-agenda-category-icon-alist)
6410 (when (org-string-match-p (car entry) category)
6411 (if (listp (cadr entry))
6412 (return (cadr entry))
6413 (return (apply 'create-image (cdr entry)))))))
6415 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6417 "Format TXT to be inserted into the agenda buffer.
6418 In particular, add the prefix and corresponding text properties.
6420 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6421 LEVEL may be a string to replace the `%l' specifier.
6422 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6423 category taken from local variable or file name. It will replace the `%c'
6424 specifier in the format.
6425 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6426 TXT for sorting of this entry, and for the `%t' specifier in the format.
6427 When DOTIME is a string, this string is searched for a time before TXT is.
6428 TAGS can be the tags of the headline.
6429 Any match of REMOVE-RE will be removed from TXT."
6430 ;; We keep the org-prefix-* variable values along with a compiled
6431 ;; formatter, so that multiple agendas existing at the same time do
6432 ;; not step on each other toes.
6434 ;; It was inconvenient to make these variables buffer local in
6435 ;; Agenda buffers, because this function expects to be called with
6436 ;; the buffer where item comes from being current, and not agenda
6438 (let* ((bindings (car org-prefix-format-compiled))
6439 (formatter (cadr org-prefix-format-compiled)))
6440 (loop for (var value) in bindings
6443 ;; Diary entries sometimes have extra whitespace at the beginning
6444 (setq txt (org-trim txt))
6446 ;; Fix the tags part in txt
6447 (setq txt (org-agenda-fix-displayed-tags
6449 org-agenda-show-inherited-tags
6450 org-agenda-hide-tags-regexp))
6452 (let* ((category (or category
6453 (if (stringp org-category)
6455 (and org-category (symbol-name org-category)))
6456 (if buffer-file-name
6457 (file-name-sans-extension
6458 (file-name-nondirectory buffer-file-name))
6460 (category-icon (org-agenda-get-category-icon category))
6461 (category-icon (if category-icon
6462 (propertize " " 'display category-icon)
6464 ;; time, tag, effort are needed for the eval of the prefix format
6465 (tag (if tags (nth (1- (length tags)) tags) ""))
6467 (ts (if dotime (concat
6468 (if (stringp dotime) dotime "")
6469 (and org-agenda-search-headline-for-time txt))))
6470 (time-of-day (and dotime (org-get-time-of-day ts)))
6471 stamp plain s0 s1 s2 rtn srp l
6472 duration thecategory breadcrumbs)
6473 (and (derived-mode-p 'org-mode) buffer-file-name
6474 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6475 (when (and dotime time-of-day)
6476 ;; Extract starting and ending time and move them to prefix
6477 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6478 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6479 (setq s0 (match-string 0 ts)
6480 srp (and stamp (match-end 3))
6481 s1 (match-string (if plain 1 2) ts)
6482 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6484 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6485 ;; them, we might want to remove them there to avoid duplication.
6486 ;; The user can turn this off with a variable.
6487 (if (and org-prefix-has-time
6488 org-agenda-remove-times-when-in-prefix (or stamp plain)
6489 (string-match (concat (regexp-quote s0) " *") txt)
6490 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6491 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6492 (= (match-beginning 0) 0)
6494 (setq txt (replace-match "" nil nil txt))))
6495 ;; Normalize the time(s) to 24 hour
6496 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6497 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6499 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6500 (let (org-time-clocksum-use-effort-durations)
6501 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6503 (org-minutes-to-clocksum-string
6504 (+ (org-hh:mm-string-to-minutes s1)
6505 org-agenda-default-appointment-duration)))))
6507 ;; Compute the duration
6509 (setq duration (- (org-hh:mm-string-to-minutes s2)
6510 (org-hh:mm-string-to-minutes s1)))))
6512 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6514 ;; Tags are in the string
6515 (if (or (eq org-agenda-remove-tags t)
6516 (and org-agenda-remove-tags
6517 org-prefix-has-tag))
6518 (setq txt (replace-match "" t t txt))
6519 (setq txt (replace-match
6520 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6521 (match-string 2 txt))
6523 (when (derived-mode-p 'org-mode)
6524 (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
6526 ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
6527 ;; current buffer, so move this check outside of above
6529 (setq neffort (org-duration-string-to-minutes effort)
6530 effort (setq effort (concat "[" effort "]")))
6531 ;; prevent erroring out with %e format when there is no effort
6535 (while (string-match remove-re txt)
6536 (setq txt (replace-match "" t t txt))))
6538 ;; Set org-heading property on `txt' to mark the start of the
6540 (add-text-properties 0 (length txt) '(org-heading t) txt)
6542 ;; Prepare the variables needed in the eval of the compiled format
6543 (if org-prefix-has-breadcrumbs
6544 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6545 (let ((s (org-display-outline-path nil nil "->" t)))
6546 (if (eq "" s) "" (concat s "->"))))))
6547 (setq time (cond (s2 (concat
6548 (org-agenda-time-of-day-to-ampm-maybe s1)
6549 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6550 (if org-agenda-timegrid-use-ampm " ")))
6552 (org-agenda-time-of-day-to-ampm-maybe s1)
6553 (if org-agenda-timegrid-use-ampm
6557 extra (or (and (not habitp) extra) "")
6558 category (if (symbolp category) (symbol-name category) category)
6559 thecategory (copy-sequence category)
6560 level (or level ""))
6561 (if (string-match org-bracket-link-regexp category)
6563 (setq l (if (match-end 3)
6564 (- (match-end 3) (match-beginning 3))
6565 (- (match-end 1) (match-beginning 1))))
6566 (when (< l (or org-prefix-category-length 0))
6567 (setq category (copy-sequence category))
6568 (org-add-props category nil
6569 'extra-space (make-string
6570 (- org-prefix-category-length l 1) ?\ ))))
6571 (if (and org-prefix-category-max-length
6572 (>= (length category) org-prefix-category-max-length))
6573 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6574 ;; Evaluate the compiled format
6575 (setq rtn (concat (eval formatter) txt))
6577 ;; And finally add the text properties
6578 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6579 (org-add-props rtn nil
6580 'org-category (if thecategory (downcase thecategory) category)
6581 'tags (mapcar 'org-downcase-keep-props tags)
6582 'org-highest-priority org-highest-priority
6583 'org-lowest-priority org-lowest-priority
6584 'time-of-day time-of-day
6587 'effort-minutes neffort
6588 'breadcrumbs breadcrumbs
6593 'format org-prefix-format-compiled
6596 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6597 "Remove tags string from TXT, and add a modified list of tags.
6598 The modified list may contain inherited tags, and tags matched by
6599 `org-agenda-hide-tags-regexp' will be removed."
6600 (when (or add-inherited hide-re)
6601 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6602 (setq txt (substring txt 0 (match-beginning 0))))
6605 (mapcar (lambda (tg)
6606 (if (or (and hide-re (string-match hide-re tg))
6607 (and (not add-inherited)
6608 (get-text-property 0 'inherited tg)))
6613 (let ((have-i (get-text-property 0 'inherited (car tags)))
6615 (setq txt (concat txt " :"
6618 (setq i (get-text-property 0 'inherited x))
6619 (if (and have-i (not i))
6625 (if have-i "::" ":"))))))
6628 (defun org-downcase-keep-props (s)
6629 (let ((props (text-properties-at 0 s)))
6630 (setq s (downcase s))
6631 (add-text-properties 0 (length s) props s)
6634 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6636 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6637 "Add a time-grid for agenda items which need it.
6639 LIST is the list of agenda items formatted by `org-agenda-list'.
6640 NDAYS is the span of the current agenda view.
6641 TODAYP is `t' when the current agenda view is on today."
6643 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6644 ((and todayp (member 'today (car org-agenda-time-grid))))
6645 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6646 ((member 'weekly (car org-agenda-time-grid)))
6647 (t (throw 'exit list)))
6648 (let* ((have (delq nil (mapcar
6649 (lambda (x) (get-text-property 1 'time-of-day x))
6651 (string (nth 1 org-agenda-time-grid))
6652 (gridtimes (nth 2 org-agenda-time-grid))
6653 (req (car org-agenda-time-grid))
6654 (remove (member 'remove-match req))
6656 (if (and (member 'require-timed req) (not have))
6657 ;; don't show empty grid
6659 (while (setq time (pop gridtimes))
6660 (unless (and remove (member time have))
6661 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6662 (push (org-agenda-format-item
6663 nil string nil "" nil
6664 (concat (substring time 0 -2) ":" (substring time -2)))
6667 2 (length (car new)) 'face 'org-time-grid (car new))))
6668 (when (and todayp org-agenda-show-current-time-in-grid)
6669 (push (org-agenda-format-item
6670 nil org-agenda-current-time-string nil "" nil
6671 (format-time-string "%H:%M "))
6674 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6676 (if (member 'time-up org-agenda-sorting-strategy-selected)
6678 (append list new)))))
6680 (defun org-compile-prefix-format (key)
6681 "Compile the prefix format into a Lisp form that can be evaluated.
6682 The resulting form and associated variable bindings is returned
6683 and stored in the variable `org-prefix-format-compiled'."
6684 (setq org-prefix-has-time nil
6685 org-prefix-has-tag nil
6686 org-prefix-category-length nil
6687 org-prefix-has-effort nil
6688 org-prefix-has-breadcrumbs nil)
6690 ((stringp org-agenda-prefix-format)
6691 org-agenda-prefix-format)
6692 ((assq key org-agenda-prefix-format)
6693 (cdr (assq key org-agenda-prefix-format)))
6694 (t " %-12:c%?-12t% s")))
6696 varform vars var e c f opt)
6697 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6699 (setq var (or (cdr (assoc (match-string 4 s)
6700 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6701 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6703 c (or (match-string 3 s) "")
6704 opt (match-beginning 1)
6705 start (1+ (match-beginning 0)))
6706 (if (equal var 'time) (setq org-prefix-has-time t))
6707 (if (equal var 'tag) (setq org-prefix-has-tag t))
6708 (if (equal var 'effort) (setq org-prefix-has-effort t))
6709 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6710 (setq f (concat "%" (match-string 2 s) "s"))
6711 (when (equal var 'category)
6712 (setq org-prefix-category-length
6713 (floor (abs (string-to-number (match-string 2 s)))))
6714 (setq org-prefix-category-max-length
6715 (let ((x (match-string 2 s)))
6717 (if (string-match "\\.[0-9]+" x)
6718 (string-to-number (substring (match-string 0 x) 1)))))))
6720 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6723 `(if (equal "" ,var)
6725 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6726 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6727 (setq s (replace-match "%s" t nil s))
6728 (push varform vars))
6729 (setq vars (nreverse vars))
6730 (with-current-buffer (or org-agenda-buffer (current-buffer))
6731 (setq org-prefix-format-compiled
6733 `((org-prefix-has-time ,org-prefix-has-time)
6734 (org-prefix-has-tag ,org-prefix-has-tag)
6735 (org-prefix-category-length ,org-prefix-category-length)
6736 (org-prefix-has-effort ,org-prefix-has-effort)
6737 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6738 `(format ,s ,@vars))))))
6740 (defun org-set-sorting-strategy (key)
6741 (if (symbolp (car org-agenda-sorting-strategy))
6743 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6744 (setq org-agenda-sorting-strategy-selected
6745 (or (cdr (assq key org-agenda-sorting-strategy))
6746 (cdr (assq 'agenda org-agenda-sorting-strategy))
6747 '(time-up category-keep priority-down)))))
6749 (defun org-get-time-of-day (s &optional string mod24)
6750 "Check string S for a time of day.
6751 If found, return it as a military time number between 0 and 2400.
6752 If not found, return nil.
6753 The optional STRING argument forces conversion into a 5 character wide string
6757 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6758 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6759 (let* ((h (string-to-number (match-string 1 s)))
6760 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6761 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6762 (am-p (equal ampm "am"))
6763 (h1 (cond ((not ampm) h)
6764 ((= h 12) (if am-p 0 12))
6765 (t (+ h (if am-p 0 12)))))
6766 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6768 (t0 (+ (* 100 h2) m))
6769 (t1 (concat (if (>= h1 24) "+" " ")
6770 (if (and org-agenda-time-leading-zero
6771 (< t0 1000)) "0" "")
6772 (if (< t0 100) "0" "")
6773 (if (< t0 10) "0" "")
6774 (int-to-string t0))))
6775 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6777 (defvar org-agenda-before-sorting-filter-function nil
6778 "Function to be applied to agenda items prior to sorting.
6779 Prior to sorting also means just before they are inserted into the agenda.
6781 To aid sorting, you may revisit the original entries and add more text
6782 properties which will later be used by the sorting functions.
6784 The function should take a string argument, an agenda line.
6785 It has access to the text properties in that line, which contain among
6786 other things, the property `org-hd-marker' that points to the entry
6787 where the line comes from. Note that not all lines going into the agenda
6788 have this property, only most.
6790 The function should return the modified string. It is probably best
6791 to ONLY change text properties.
6793 You can also use this function as a filter, by returning nil for lines
6794 you don't want to have in the agenda at all. For this application, you
6795 could bind the variable in the options section of a custom command.")
6797 (defun org-agenda-finalize-entries (list &optional type)
6798 "Sort, limit and concatenate the LIST of agenda items.
6799 The optional argument TYPE tells the agenda type."
6800 (let ((max-effort (cond ((listp org-agenda-max-effort)
6801 (cdr (assoc type org-agenda-max-effort)))
6802 (t org-agenda-max-effort)))
6803 (max-todo (cond ((listp org-agenda-max-todos)
6804 (cdr (assoc type org-agenda-max-todos)))
6805 (t org-agenda-max-todos)))
6806 (max-tags (cond ((listp org-agenda-max-tags)
6807 (cdr (assoc type org-agenda-max-tags)))
6808 (t org-agenda-max-tags)))
6809 (max-entries (cond ((listp org-agenda-max-entries)
6810 (cdr (assoc type org-agenda-max-entries)))
6811 (t org-agenda-max-entries))) l)
6812 (when org-agenda-before-sorting-filter-function
6816 org-agenda-before-sorting-filter-function list))))
6817 (setq list (mapcar 'org-agenda-highlight-todo list)
6818 list (mapcar 'identity (sort list 'org-entries-lessp)))
6820 (setq list (org-agenda-limit-entries
6821 list 'effort-minutes max-effort 'identity)))
6823 (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
6825 (setq list (org-agenda-limit-entries list 'tags max-tags)))
6827 (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
6828 (mapconcat 'identity list "\n")))
6830 (defun org-agenda-limit-entries (list prop limit &optional fn)
6831 "Limit the number of agenda entries."
6832 (let ((include (and limit (< limit 0))))
6834 (let ((fun (or fn (lambda (p) (if p 1))))
6839 (let ((pval (funcall fun (get-text-property 1 prop e))))
6840 (if pval (setq lim (+ lim pval)))
6841 (cond ((and pval (<= lim (abs limit))) e)
6842 ((and include (not pval)) e))))
6846 (defun org-agenda-limit-interactively ()
6847 "In agenda, interactively limit entries to various maximums."
6849 (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
6850 (num (string-to-number (read-from-minibuffer "How many? "))))
6851 (cond ((equal max ?e)
6852 (let ((org-agenda-max-entries num)) (org-agenda-redo)))
6854 (let ((org-agenda-max-todos num)) (org-agenda-redo)))
6856 (let ((org-agenda-max-tags num)) (org-agenda-redo)))
6858 (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
6859 (org-agenda-fit-window-to-buffer))
6861 (defun org-agenda-highlight-todo (x)
6862 (let ((org-done-keywords org-done-keywords-for-agenda)
6863 (case-fold-search nil)
6867 (beginning-of-line 1)
6868 (setq re (org-get-at-bol 'org-todo-regexp))
6869 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6870 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6871 (add-text-properties (match-beginning 0) (match-end 1)
6872 (list 'face (org-get-todo-face 1)))
6873 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6874 (delete-region (match-beginning 1) (1- (match-end 0)))
6875 (goto-char (match-beginning 1))
6876 (insert (format org-agenda-todo-keyword-format s)))))
6877 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6878 (setq re (get-text-property 0 'org-todo-regexp x))
6880 ;; Test `pl' because if there's no heading content,
6881 ;; there's no point matching to highlight. Note
6882 ;; that if we didn't test `pl' first, and there
6883 ;; happened to be no keyword from `org-todo-regexp'
6884 ;; on this heading line, then the `equal' comparison
6885 ;; afterwards would spuriously succeed in the case
6886 ;; where `pl' is nil -- causing an args-out-of-range
6887 ;; error when we try to add text properties to text
6888 ;; that isn't there.
6890 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6892 (add-text-properties
6893 (or (match-end 1) (match-end 0)) (match-end 0)
6894 (list 'face (org-get-todo-face (match-string 2 x)))
6897 (setq x (concat (substring x 0 (match-end 1))
6898 (format org-agenda-todo-keyword-format
6900 (org-add-props " " (text-properties-at 0 x))
6901 (substring x (match-end 3)))))))
6904 (defsubst org-cmp-priority (a b)
6905 "Compare the priorities of string A and B."
6906 (let ((pa (or (get-text-property 1 'priority a) 0))
6907 (pb (or (get-text-property 1 'priority b) 0)))
6908 (cond ((> pa pb) +1)
6911 (defsubst org-cmp-effort (a b)
6912 "Compare the effort values of string A and B."
6913 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6914 (ea (or (get-text-property 1 'effort-minutes a) def))
6915 (eb (or (get-text-property 1 'effort-minutes b) def)))
6916 (cond ((> ea eb) +1)
6919 (defsubst org-cmp-category (a b)
6920 "Compare the string values of categories of strings A and B."
6921 (let ((ca (or (get-text-property 1 'org-category a) ""))
6922 (cb (or (get-text-property 1 'org-category b) "")))
6923 (cond ((string-lessp ca cb) -1)
6924 ((string-lessp cb ca) +1))))
6926 (defsubst org-cmp-todo-state (a b)
6927 "Compare the todo states of strings A and B."
6928 (let* ((ma (or (get-text-property 1 'org-marker a)
6929 (get-text-property 1 'org-hd-marker a)))
6930 (mb (or (get-text-property 1 'org-marker b)
6931 (get-text-property 1 'org-hd-marker b)))
6932 (fa (and ma (marker-buffer ma)))
6933 (fb (and mb (marker-buffer mb)))
6935 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6936 (and fb (with-current-buffer fb org-todo-keywords-1))))
6937 (ta (or (get-text-property 1 'todo-state a) ""))
6938 (tb (or (get-text-property 1 'todo-state b) ""))
6939 (la (- (length (member ta todo-kwds))))
6940 (lb (- (length (member tb todo-kwds))))
6941 (donepa (member ta org-done-keywords-for-agenda))
6942 (donepb (member tb org-done-keywords-for-agenda)))
6943 (cond ((and donepa (not donepb)) -1)
6944 ((and (not donepa) donepb) +1)
6948 (defsubst org-cmp-alpha (a b)
6949 "Compare the headlines, alphabetically."
6950 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6951 (plb (text-property-any 0 (length b) 'org-heading t b))
6952 (ta (and pla (substring a pla)))
6953 (tb (and plb (substring b plb))))
6955 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6956 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6957 (setq ta (substring ta (match-end 0))))
6958 (setq ta (downcase ta)))
6960 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6961 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6962 (setq tb (substring tb (match-end 0))))
6963 (setq tb (downcase tb)))
6966 ((string-lessp ta tb) -1)
6967 ((string-lessp tb ta) +1))))
6969 (defsubst org-cmp-tag (a b)
6970 "Compare the string values of the first tags of A and B."
6971 (let ((ta (car (last (get-text-property 1 'tags a))))
6972 (tb (car (last (get-text-property 1 'tags b)))))
6975 ((string-lessp ta tb) -1)
6976 ((string-lessp tb ta) +1))))
6978 (defsubst org-cmp-time (a b)
6979 "Compare the time-of-day values of strings A and B."
6980 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6981 (ta (or (get-text-property 1 'time-of-day a) def))
6982 (tb (or (get-text-property 1 'time-of-day b) def)))
6983 (cond ((< ta tb) -1)
6986 (defsubst org-cmp-ts (a b &optional type)
6987 "Compare the timestamps values of entries A and B.
6988 When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
6989 \"timestamp_ia\", compare within each of these type. When TYPE
6990 is the empty string, compare all timestamps without respect of
6992 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6993 (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
6994 (get-text-property 1 'ts-date a)) def))
6995 (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
6996 (get-text-property 1 'ts-date b)) def)))
6997 (cond ((< ta tb) -1)
7000 (defsubst org-cmp-habit-p (a b)
7001 "Compare the todo states of strings A and B."
7002 (let ((ha (get-text-property 1 'org-habit-p a))
7003 (hb (get-text-property 1 'org-habit-p b)))
7004 (cond ((and ha (not hb)) -1)
7005 ((and (not ha) hb) +1))))
7007 (defun org-entries-lessp (a b)
7008 "Predicate for sorting agenda entries."
7009 ;; The following variables will be used when the form is evaluated.
7010 ;; So even though the compiler complains, keep them.
7011 (let* ((ss org-agenda-sorting-strategy-selected)
7012 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
7013 (org-cmp-ts a b "")))
7014 (timestamp-down (if timestamp-up (- timestamp-up) nil))
7015 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
7016 (org-cmp-ts a b "scheduled")))
7017 (scheduled-down (if scheduled-up (- scheduled-up) nil))
7018 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
7019 (org-cmp-ts a b "deadline")))
7020 (deadline-down (if deadline-up (- deadline-up) nil))
7021 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
7022 (org-cmp-ts a b "iatimestamp_ia")))
7023 (tsia-down (if tsia-up (- tsia-up) nil))
7024 (ts-up (and (org-em 'ts-up 'ts-down ss)
7025 (org-cmp-ts a b "timestamp")))
7026 (ts-down (if ts-up (- ts-up) nil))
7027 (time-up (and (org-em 'time-up 'time-down ss)
7028 (org-cmp-time a b)))
7029 (time-down (if time-up (- time-up) nil))
7030 (priority-up (and (org-em 'priority-up 'priority-down ss)
7031 (org-cmp-priority a b)))
7032 (priority-down (if priority-up (- priority-up) nil))
7033 (effort-up (and (org-em 'effort-up 'effort-down ss)
7034 (org-cmp-effort a b)))
7035 (effort-down (if effort-up (- effort-up) nil))
7036 (category-up (and (or (org-em 'category-up 'category-down ss)
7037 (memq 'category-keep ss))
7038 (org-cmp-category a b)))
7039 (category-down (if category-up (- category-up) nil))
7040 (category-keep (if category-up +1 nil))
7041 (tag-up (and (org-em 'tag-up 'tag-down ss)
7043 (tag-down (if tag-up (- tag-up) nil))
7044 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
7045 (org-cmp-todo-state a b)))
7046 (todo-state-down (if todo-state-up (- todo-state-up) nil))
7047 (habit-up (and (org-em 'habit-up 'habit-down ss)
7048 (org-cmp-habit-p a b)))
7049 (habit-down (if habit-up (- habit-up) nil))
7050 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
7051 (org-cmp-alpha a b)))
7052 (alpha-down (if alpha-up (- alpha-up) nil))
7053 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
7054 user-defined-up user-defined-down)
7055 (if (and need-user-cmp org-agenda-cmp-user-defined
7056 (functionp org-agenda-cmp-user-defined))
7057 (setq user-defined-up
7058 (funcall org-agenda-cmp-user-defined a b)
7059 user-defined-down (if user-defined-up (- user-defined-up) nil)))
7061 (eval (cons 'or org-agenda-sorting-strategy-selected))
7062 '((-1 . t) (1 . nil) (nil . nil))))))
7064 ;;; Agenda restriction lock
7066 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
7067 "Overlay to mark the headline to which agenda commands are restricted.")
7068 (overlay-put org-agenda-restriction-lock-overlay
7069 'face 'org-agenda-restriction-lock)
7070 (overlay-put org-agenda-restriction-lock-overlay
7071 'help-echo "Agendas are currently limited to this subtree.")
7072 (org-detach-overlay org-agenda-restriction-lock-overlay)
7074 (defun org-agenda-set-restriction-lock (&optional type)
7075 "Set restriction lock for agenda, to current subtree or file.
7076 Restriction will be the file if TYPE is `file', or if type is the
7077 universal prefix '(4), or if the cursor is before the first headline
7078 in the file. Otherwise, restriction will be to the current subtree."
7080 (and (equal type '(4)) (setq type 'file))
7083 ((org-at-heading-p) 'subtree)
7084 ((condition-case nil (org-back-to-heading t) (error nil))
7087 (if (eq type 'subtree)
7089 (setq org-agenda-restrict (current-buffer))
7090 (setq org-agenda-overriding-restriction 'subtree)
7091 (put 'org-agenda-files 'org-restrict
7092 (list (buffer-file-name (buffer-base-buffer))))
7093 (org-back-to-heading t)
7094 (move-overlay org-agenda-restriction-lock-overlay
7096 (if org-agenda-restriction-lock-highlight-subtree
7097 (save-excursion (org-end-of-subtree t t) (point))
7099 (move-marker org-agenda-restrict-begin (point))
7100 (move-marker org-agenda-restrict-end
7101 (save-excursion (org-end-of-subtree t t)))
7102 (message "Locking agenda restriction to subtree"))
7103 (put 'org-agenda-files 'org-restrict
7104 (list (buffer-file-name (buffer-base-buffer))))
7105 (setq org-agenda-restrict nil)
7106 (setq org-agenda-overriding-restriction 'file)
7107 (move-marker org-agenda-restrict-begin nil)
7108 (move-marker org-agenda-restrict-end nil)
7109 (message "Locking agenda restriction to file"))
7110 (setq current-prefix-arg nil)
7111 (org-agenda-maybe-redo))
7113 (defun org-agenda-remove-restriction-lock (&optional noupdate)
7114 "Remove the agenda restriction lock."
7116 (org-detach-overlay org-agenda-restriction-lock-overlay)
7117 (org-detach-overlay org-speedbar-restriction-lock-overlay)
7118 (setq org-agenda-overriding-restriction nil)
7119 (setq org-agenda-restrict nil)
7120 (put 'org-agenda-files 'org-restrict nil)
7121 (move-marker org-agenda-restrict-begin nil)
7122 (move-marker org-agenda-restrict-end nil)
7123 (setq current-prefix-arg nil)
7124 (message "Agenda restriction lock removed")
7125 (or noupdate (org-agenda-maybe-redo)))
7127 (defun org-agenda-maybe-redo ()
7128 "If there is any window showing the agenda view, update it."
7129 (let ((w (get-buffer-window org-agenda-buffer-name t))
7130 (w0 (selected-window)))
7135 (if org-agenda-overriding-restriction
7136 (message "Agenda view shifted to new %s restriction"
7137 org-agenda-overriding-restriction)
7138 (message "Agenda restriction lock removed")))))
7142 (defun org-agenda-check-type (error &rest types)
7143 "Check if agenda buffer is of allowed type.
7144 If ERROR is non-nil, throw an error, otherwise just return nil.
7145 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
7146 (if (not org-agenda-type)
7147 (error "No Org agenda currently displayed")
7148 (if (memq org-agenda-type types)
7151 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7154 (defun org-agenda-Quit ()
7155 "Exit the agenda and kill buffers loaded by `org-agenda'.
7156 Also restore the window configuration."
7158 (if org-agenda-columns-active
7160 (let ((buf (current-buffer)))
7161 (if (eq org-agenda-window-setup 'other-frame)
7163 (org-agenda-reset-markers)
7165 (org-columns-remove-overlays)
7166 (setq org-agenda-archives-mode nil)
7168 (and (not (eq org-agenda-window-setup 'current-window))
7169 (not (one-window-p))
7171 (org-agenda-reset-markers)
7173 (org-columns-remove-overlays)
7174 (setq org-agenda-archives-mode nil)))
7175 (setq org-agenda-buffer nil)
7176 ;; Maybe restore the pre-agenda window configuration.
7177 (and org-agenda-restore-windows-after-quit
7178 (not (eq org-agenda-window-setup 'other-frame))
7179 org-agenda-pre-window-conf
7180 (set-window-configuration org-agenda-pre-window-conf)
7181 (setq org-agenda-pre-window-conf nil))))
7183 (defun org-agenda-quit ()
7184 "Exit the agenda and restore the window configuration.
7185 When `org-agenda-sticky' is non-nil, only bury the agenda."
7187 (if (and (eq org-indirect-buffer-display 'other-window)
7188 org-last-indirect-buffer)
7189 (let ((org-last-indirect-window
7190 (get-buffer-window org-last-indirect-buffer)))
7191 (if org-last-indirect-window
7192 (delete-window org-last-indirect-window))))
7193 (if org-agenda-columns-active
7195 (if org-agenda-sticky
7196 (let ((buf (current-buffer)))
7197 (if (eq org-agenda-window-setup 'other-frame)
7200 (and (not (eq org-agenda-window-setup 'current-window))
7201 (not (one-window-p))
7203 (with-current-buffer buf
7205 ;; Maybe restore the pre-agenda window configuration.
7206 (and org-agenda-restore-windows-after-quit
7207 (not (eq org-agenda-window-setup 'other-frame))
7208 org-agenda-pre-window-conf
7209 (set-window-configuration org-agenda-pre-window-conf)
7210 (setq org-agenda-pre-window-conf nil))))
7211 (org-agenda-Quit))))
7213 (defun org-agenda-exit ()
7214 "Exit the agenda and restore the window configuration.
7215 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7216 buffers visited directly by the user will not be touched."
7218 (org-release-buffers org-agenda-new-buffers)
7219 (setq org-agenda-new-buffers nil)
7222 (defun org-agenda-kill-all-agenda-buffers ()
7223 "Kill all buffers in `org-agenda-mode'.
7224 This is used when toggling sticky agendas.
7225 You can also explicitly invoke it with `C-c a C-k'."
7228 (dolist (buf (buffer-list))
7229 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7231 (mapc 'kill-buffer blist)))
7233 (defun org-agenda-execute (arg)
7234 "Execute another agenda command, keeping same window.
7235 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7238 (let ((org-agenda-window-setup 'current-window))
7241 (defun org-agenda-redo (&optional all)
7242 "Rebuild possibly ALL agenda view(s) in the current buffer."
7244 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7245 (cpa (unless (eq all t) current-prefix-arg))
7246 (org-agenda-doing-sticky-redo org-agenda-sticky)
7247 (org-agenda-sticky nil)
7248 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7249 org-agenda-buffer-name))
7250 (org-agenda-keep-modes t)
7251 (tag-filter org-agenda-tag-filter)
7252 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7253 (top-hl-filter org-agenda-top-headline-filter)
7254 (cat-filter org-agenda-category-filter)
7255 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7256 (re-filter org-agenda-regexp-filter)
7257 (re-preset (get 'org-agenda-regexp-filter :preset-filter))
7258 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7259 (cols org-agenda-columns-active)
7260 (line (org-current-line))
7261 (window-line (- line (org-current-line (window-start))))
7262 (lprops (get 'org-agenda-redo-command 'org-lprops))
7263 (redo-cmd (get-text-property p 'org-redo-cmd))
7264 (last-args (get-text-property p 'org-last-args))
7265 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7266 (org-agenda-overriding-cmd-arguments
7268 (cond ((listp last-args)
7269 (cons (or cpa (car last-args)) (cdr last-args)))
7270 ((stringp last-args)
7272 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7273 (put 'org-agenda-tag-filter :preset-filter nil)
7274 (put 'org-agenda-category-filter :preset-filter nil)
7275 (put 'org-agenda-regexp-filter :preset-filter nil)
7276 (and cols (org-columns-quit))
7277 (message "Rebuilding agenda buffer...")
7279 (eval series-redo-cmd)
7280 (org-let lprops redo-cmd))
7281 (setq org-agenda-undo-list nil
7282 org-agenda-pending-undo-list nil
7283 org-agenda-tag-filter tag-filter
7284 org-agenda-category-filter cat-filter
7285 org-agenda-regexp-filter re-filter
7286 org-agenda-top-headline-filter top-hl-filter)
7287 (message "Rebuilding agenda buffer...done")
7288 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7289 (put 'org-agenda-category-filter :preset-filter cat-preset)
7290 (put 'org-agenda-regexp-filter :preset-filter re-preset)
7291 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7292 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7293 (and (or re-filter re-preset) (org-agenda-filter-apply re-filter 'regexp))
7294 (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
7295 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7296 (org-goto-line line)
7297 (recenter window-line)))
7299 (defvar org-global-tags-completion-table nil)
7300 (defvar org-agenda-filter-form nil)
7301 (defvar org-agenda-filtered-by-category nil)
7303 (defun org-agenda-filter-by-category (strip)
7304 "Keep only those lines in the agenda buffer that have a specific category.
7305 The category is that of the current line."
7307 (if (and org-agenda-filtered-by-category
7308 org-agenda-category-filter)
7309 (org-agenda-filter-show-all-cat)
7310 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7313 (org-agenda-filter-apply
7314 (push (concat "-" cat) org-agenda-category-filter) 'category))
7316 (org-agenda-filter-apply
7317 (setq org-agenda-category-filter
7318 (list (concat "+" cat))) 'category))
7319 ((error "No category at point"))))))
7321 (defun org-find-top-headline (&optional pos)
7322 "Find the topmost parent headline and return it."
7324 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7325 (if pos (goto-char pos))
7326 ;; Skip up to the topmost parent
7327 (while (ignore-errors (outline-up-heading 1) t))
7329 (nth 4 (org-heading-components))))))
7331 (defvar org-agenda-filtered-by-top-headline nil)
7332 (defun org-agenda-filter-by-top-headline (strip)
7333 "Keep only those lines that are descendants from the same top headline.
7334 The top headline is that of the current line."
7336 (if org-agenda-filtered-by-top-headline
7338 (setq org-agenda-filtered-by-top-headline nil
7339 org-agenda-top-headline-filter nil)
7340 (org-agenda-filter-show-all-cat))
7341 (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
7342 (if cat (org-agenda-filter-top-headline-apply cat strip)
7343 (error "No top-level category at point")))))
7345 (defvar org-agenda-regexp-filter nil)
7346 (defun org-agenda-filter-by-regexp (strip)
7347 "Filter agenda entries by a regular expression.
7348 Regexp filters are cumulative.
7349 With no prefix argument, keep entries matching the regexp.
7350 With one prefix argument, filter out entries matching the regexp.
7351 With two prefix arguments, remove the regexp filters."
7353 (if (not (equal strip '(16)))
7354 (let ((flt (concat (if (equal strip '(4)) "-" "+")
7355 (read-from-minibuffer
7356 (if (equal strip '(4))
7357 "Filter out entries matching regexp: "
7358 "Narrow to entries matching regexp: ")))))
7359 (push flt org-agenda-regexp-filter)
7360 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
7361 (org-agenda-filter-show-all-re)
7362 (message "Regexp filter removed")))
7364 (defun org-agenda-filter-remove-all ()
7365 "Remove all filters from the current agenda buffer."
7367 (when org-agenda-tag-filter
7368 (org-agenda-filter-show-all-tag))
7369 (when org-agenda-category-filter
7370 (org-agenda-filter-show-all-cat))
7371 (when org-agenda-regexp-filter
7372 (org-agenda-filter-show-all-re)))
7374 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7375 "Keep only those lines in the agenda buffer that have a specific tag.
7376 The tag is selected with its fast selection letter, as configured.
7377 With prefix argument STRIP, remove all lines that do have the tag.
7378 A lisp caller can specify CHAR. NARROW means that the new tag should be
7379 used to narrow the search - the interactive user can also press `-' or `+'
7380 to switch to narrowing."
7382 (let* ((alist org-tag-alist-for-agenda)
7383 (tag-chars (mapconcat
7384 (lambda (x) (if (and (not (symbolp (car x)))
7386 (char-to-string (cdr x))
7389 (efforts (org-split-string
7390 (or (cdr (assoc (concat org-effort-property "_ALL")
7391 org-global-properties))
7392 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7394 (effort-op org-agenda-filter-effort-default-operator)
7396 (inhibit-read-only t)
7397 (current org-agenda-tag-filter)
7398 maybe-refresh a n tag)
7401 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7402 (if narrow "Narrow" "Filter") tag-chars
7403 (if org-agenda-auto-exclude-function "[RET], " ""))
7404 (setq char (read-char-exclusive)))
7405 (when (member char '(?+ ?-))
7407 (cond ((equal char ?-) (setq strip t narrow t))
7408 ((equal char ?+) (setq strip nil narrow t)))
7410 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7411 (setq char (read-char-exclusive)))
7412 (when (member char '(?< ?> ?= ??))
7413 ;; An effort operator
7414 (setq effort-op (char-to-string char))
7415 (setq alist nil) ; to make sure it will be interpreted as effort.
7416 (unless (equal char ??)
7417 (loop for i from 0 to 9 do
7421 (if (= i 9) "0" (int-to-string (1+ i)))
7422 "]" (nth i efforts))))
7423 (message "Effort%s: %s " effort-op effort-prompt)
7424 (setq char (read-char-exclusive))
7425 (when (or (< char ?0) (> char ?9))
7426 (error "Need 1-9,0 to select effort"))))
7427 (when (equal char ?\t)
7428 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7429 (org-set-local 'org-global-tags-completion-table
7430 (org-global-tags-completion-table)))
7431 (let ((completion-ignore-case t))
7432 (setq tag (org-icompleting-read
7433 "Tag: " org-global-tags-completion-table))))
7436 (org-agenda-filter-show-all-tag)
7437 (when org-agenda-auto-exclude-function
7438 (setq org-agenda-tag-filter nil)
7439 (dolist (tag (org-agenda-get-represented-tags))
7440 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7442 (push modifier org-agenda-tag-filter))))
7443 (if (not (null org-agenda-tag-filter))
7444 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7445 (setq maybe-refresh t))
7447 (org-agenda-filter-show-all-tag)
7448 (when (get 'org-agenda-tag-filter :preset-filter)
7449 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7450 (setq maybe-refresh t))
7452 (setq org-agenda-tag-filter
7453 (mapcar (lambda(tag) (concat "+" tag))
7454 (org-get-at-bol 'tags)))
7455 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7456 (setq maybe-refresh t))
7457 ((or (equal char ?\ )
7458 (setq a (rassoc char alist))
7459 (and (>= char ?0) (<= char ?9)
7460 (setq n (if (= char ?0) 9 (- char ?0 1))
7461 tag (concat effort-op (nth n efforts))
7466 (and tag (setq a (cons tag nil))))
7467 (org-agenda-filter-show-all-tag)
7469 (setq org-agenda-tag-filter
7470 (cons (concat (if strip "-" "+") tag)
7471 (if narrow current nil)))
7472 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7473 (setq maybe-refresh t))
7474 (t (error "Invalid tag selection character %c" char)))
7475 (when (and maybe-refresh
7476 (eq org-agenda-clockreport-mode 'with-filter))
7477 (org-agenda-redo))))
7479 (defun org-agenda-get-represented-tags ()
7480 "Get a list of all tags currently represented in the agenda."
7483 (goto-char (point-min))
7484 (while (setq p (next-single-property-change (point) 'tags))
7486 (mapc (lambda (x) (add-to-list 'tags x))
7487 (get-text-property (point) 'tags))))
7490 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7491 "Refine the current filter. See `org-agenda-filter-by-tag'."
7493 (org-agenda-filter-by-tag strip char 'refine))
7495 (defun org-agenda-filter-make-matcher (filter type)
7496 "Create the form that tests a line for agenda filter."
7503 (append (get 'org-agenda-tag-filter :preset-filter)
7506 (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
7508 (lambda (nf0 nf01 fltr notgroup op)
7510 (if (member x '("-" "+"))
7511 (setq nf01 (if (equal x "-") 'tags '(not tags)))
7512 (if (string-match "[<=>?]" x)
7513 (setq nf01 (org-agenda-filter-effort-form x))
7514 (setq nf01 (list 'member (downcase (substring x 1))
7516 (when (equal (string-to-char x) ?-)
7517 (setq nf01 (list 'not nf01))
7518 (when (not notgroup) (setq op 'and))))
7521 (push (cons 'and nf0) f)
7522 (push (cons (or op 'or) nf0) f)))))
7523 (if (equal nfilter filter)
7524 (funcall ffunc f1 f filter t nil)
7525 (funcall ffunc nf1 nf nfilter nil nil)))))
7527 ((eq type 'category)
7530 (append (get 'org-agenda-category-filter :preset-filter)
7533 (if (equal "-" (substring x 0 1))
7534 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7535 (setq f1 (list 'equal (substring x 1) 'cat)))
7541 (append (get 'org-agenda-regexp-filter :preset-filter)
7544 (if (equal "-" (substring x 0 1))
7545 (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
7546 (setq f1 (list 'string-match (substring x 1) 'txt)))
7548 (cons 'and (nreverse f))))
7550 (defun org-agenda-filter-effort-form (e)
7551 "Return the form to compare the effort of the current line with what E says.
7552 E looks like \"+<2:25\"."
7554 (setq e (substring e 1))
7555 (setq op (string-to-char e) e (substring e 1))
7556 (setq op (cond ((equal op ?<) '<=)
7560 (list 'org-agenda-compare-effort (list 'quote op)
7561 (org-duration-string-to-minutes e))))
7563 (defun org-agenda-compare-effort (op value)
7564 "Compare the effort of the current line with VALUE, using OP.
7565 If the line does not have an effort defined, return nil."
7566 (let ((eff (org-get-at-bol 'effort-minutes)))
7569 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7572 (defun org-agenda-filter-expand-tags (filter &optional no-operator)
7573 "Expand group tags in FILTER for the agenda.
7574 When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
7576 (let ((case-fold-search t) rtn)
7580 (if (string-match "^\\([+-]\\)\\(.+\\)" f)
7581 (setq dir (match-string 1 f) f0 (match-string 2 f))
7582 (setq dir (if no-operator "" "+") f0 f))
7583 (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
7584 (org-tags-expand f0 t t))
7590 (defun org-agenda-filter-apply (filter type)
7591 "Set FILTER as the new agenda filter and apply it."
7592 ;; Deactivate `org-agenda-entry-text-mode' when filtering
7593 (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
7595 (setq org-agenda-filter-form
7596 (org-agenda-filter-make-matcher filter type))
7597 (if (and (eq type 'category)
7598 (not (equal (substring (car filter) 0 1) "-")))
7599 ;; Only set `org-agenda-filtered-by-category' to t
7600 ;; when a unique category is used as the filter
7601 (setq org-agenda-filtered-by-category t))
7602 (org-agenda-set-mode-name)
7604 (goto-char (point-min))
7606 (if (org-get-at-bol 'org-marker)
7608 (setq tags ; used in eval
7611 (org-agenda-filter-expand-tags (list f) t))
7612 (org-get-at-bol 'tags)))
7613 cat (get-text-property (point) 'org-category)
7614 txt (get-text-property (point) 'txt))
7615 (if (not (eval org-agenda-filter-form))
7616 (org-agenda-filter-hide-line type))
7617 (beginning-of-line 2))
7618 (beginning-of-line 2))))
7619 (if (get-char-property (point) 'invisible)
7620 (ignore-errors (org-agenda-previous-line)))))
7622 (defun org-agenda-filter-top-headline-apply (hl &optional negative)
7623 "Filter by top headline HL."
7624 (org-agenda-set-mode-name)
7626 (goto-char (point-min))
7628 (let* ((pos (org-get-at-bol 'org-hd-marker))
7629 (tophl (and pos (org-find-top-headline pos))))
7630 (if (and tophl (funcall (if negative 'identity 'not)
7631 (string= hl tophl)))
7632 (org-agenda-filter-hide-line 'category)))
7633 (beginning-of-line 2)))
7634 (if (get-char-property (point) 'invisible)
7635 (org-agenda-previous-line))
7636 (setq org-agenda-top-headline-filter hl
7637 org-agenda-filtered-by-top-headline t))
7639 (defun org-agenda-filter-hide-line (type)
7640 "Hide lines with TYPE in the agenda buffer."
7642 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7644 (overlay-put ov 'invisible t)
7645 (overlay-put ov 'type type)
7646 (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays))
7647 ((eq type 'category) (push ov org-agenda-cat-filter-overlays))
7648 ((eq type 'regexp) (push ov org-agenda-re-filter-overlays)))))
7650 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7651 (setq pos (or pos (point)))
7653 (dolist (ov (overlays-at pos))
7654 (when (and (overlay-get ov 'invisible)
7655 (eq (overlay-get ov 'type) 'tag))
7657 (if (< (overlay-start ov) (point-at-eol))
7658 (move-overlay ov (point-at-eol)
7659 (overlay-end ov)))))))
7661 (defun org-agenda-filter-show-all-tag nil
7662 "Remove tag filter overlays from the agenda buffer."
7663 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7664 (setq org-agenda-tag-filter-overlays nil
7665 org-agenda-tag-filter nil
7666 org-agenda-filter-form nil)
7667 (org-agenda-set-mode-name))
7669 (defun org-agenda-filter-show-all-re nil
7670 "Remove regexp filter overlays from the agenda buffer."
7671 (mapc 'delete-overlay org-agenda-re-filter-overlays)
7672 (setq org-agenda-re-filter-overlays nil
7673 org-agenda-regexp-filter nil
7674 org-agenda-filter-form nil)
7675 (org-agenda-set-mode-name))
7677 (defun org-agenda-filter-show-all-cat nil
7678 "Remove category filter overlays from the agenda buffer."
7679 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7680 (setq org-agenda-cat-filter-overlays nil
7681 org-agenda-filtered-by-category nil
7682 org-agenda-category-filter nil
7683 org-agenda-filter-form nil)
7684 (org-agenda-set-mode-name))
7686 (defun org-agenda-manipulate-query-add ()
7687 "Manipulate the query by adding a search term with positive selection.
7688 Positive selection means the term must be matched for selection of an entry."
7690 (org-agenda-manipulate-query ?\[))
7691 (defun org-agenda-manipulate-query-subtract ()
7692 "Manipulate the query by adding a search term with negative selection.
7693 Negative selection means term must not be matched for selection of an entry."
7695 (org-agenda-manipulate-query ?\]))
7696 (defun org-agenda-manipulate-query-add-re ()
7697 "Manipulate the query by adding a search regexp with positive selection.
7698 Positive selection means the regexp must match for selection of an entry."
7700 (org-agenda-manipulate-query ?\{))
7701 (defun org-agenda-manipulate-query-subtract-re ()
7702 "Manipulate the query by adding a search regexp with negative selection.
7703 Negative selection means regexp must not match for selection of an entry."
7705 (org-agenda-manipulate-query ?\}))
7706 (defun org-agenda-manipulate-query (char)
7708 ((memq org-agenda-type '(timeline agenda))
7709 (let ((org-agenda-include-inactive-timestamps t))
7711 (message "Display now includes inactive timestamps as well"))
7712 ((eq org-agenda-type 'search)
7714 'org-agenda-query-string
7715 (if org-agenda-last-search-view-search-was-boolean
7716 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7717 (?\{ . " +{}") (?\} . " -{}"))))
7719 (setq org-agenda-redo-command
7720 (list 'org-search-view
7721 (car (get-text-property (min (1- (point-max)) (point))
7723 org-agenda-query-string
7724 (+ (length org-agenda-query-string)
7725 (if (member char '(?\{ ?\})) 0 1))))
7726 (set-register org-agenda-query-register org-agenda-query-string)
7727 (let ((org-agenda-overriding-arguments
7728 (cdr org-agenda-redo-command)))
7730 (t (error "Cannot manipulate query for %s-type agenda buffers"
7733 (defun org-add-to-string (var string)
7734 (set var (concat (symbol-value var) string)))
7736 (defun org-agenda-goto-date (span)
7737 "Jump to DATE in agenda."
7739 (let* ((org-read-date-prefer-future
7740 (eval org-agenda-jump-prefer-future))
7741 (date (org-read-date))
7742 (day (time-to-days (org-time-string-to-time date)))
7743 (org-agenda-sticky-orig org-agenda-sticky)
7744 (org-agenda-buffer-tmp-name (buffer-name))
7745 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7746 (0-arg (or current-prefix-arg (car args)))
7747 (2-arg (nth 2 args))
7748 (with-hour-p (nth 4 org-agenda-redo-command))
7749 (newcmd (list 'org-agenda-list 0-arg date
7750 (org-agenda-span-to-ndays
7751 2-arg (org-time-string-to-absolute date))
7753 (newargs (cdr newcmd))
7754 (inhibit-read-only t)
7756 (if (not (org-agenda-check-type t 'agenda))
7757 (error "Not available in non-agenda views")
7758 (add-text-properties (point-min) (point-max)
7759 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7761 (goto-char (point-min))
7762 (while (not (or (= (or (get-text-property (point) 'day) 0) day)
7763 (save-excursion (move-beginning-of-line 2) (eobp))))
7764 (move-beginning-of-line 2))
7765 (setq org-agenda-sticky org-agenda-sticky-orig
7766 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7768 (defun org-agenda-goto-today ()
7771 (org-agenda-check-type t 'timeline 'agenda)
7772 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7773 (curspan (nth 2 args))
7774 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7776 (tdpos (goto-char tdpos))
7777 ((eq org-agenda-type 'agenda)
7778 (let* ((sd (org-agenda-compute-starting-span
7779 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7780 (org-agenda-overriding-arguments args))
7781 (setf (nth 1 org-agenda-overriding-arguments) sd)
7783 (org-agenda-find-same-or-today-or-agenda)))
7784 (t (error "Cannot find today")))))
7786 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7788 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7789 (text-property-any (point-min) (point-max) 'org-today t)
7790 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7791 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7792 (org-agenda-goto-block-beginning))
7795 (defun org-agenda-goto-block-beginning ()
7796 "Go the agenda block beginning."
7798 (if (not (derived-mode-p 'org-agenda-mode))
7799 (error "Cannot execute this command outside of org-agenda-mode buffers")
7802 (unless (looking-at "\\'")
7804 (let* ((prop 'org-agenda-structural-header)
7805 (p (previous-single-property-change (point) prop))
7806 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7807 (1- (point))) prop)))
7808 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7810 (error "Cannot find the beginning of the blog")
7812 (move-beginning-of-line 1)))))
7814 (defun org-agenda-later (arg)
7815 "Go forward in time by the current span.
7816 With prefix ARG, go forward that many times the current span."
7818 (org-agenda-check-type t 'agenda)
7819 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7820 (span (or (nth 2 args) org-agenda-current-span))
7821 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7822 (greg (calendar-gregorian-from-absolute sd))
7823 (cnt (org-get-at-bol 'org-day-cnt))
7827 (setq sd (+ (* span arg) sd)))
7829 (setq sd (+ arg sd)))
7831 (setq sd (+ (* 7 arg) sd)))
7833 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7834 sd (calendar-absolute-from-gregorian greg2))
7835 (setcar greg2 (1+ (car greg2))))
7837 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7838 sd (calendar-absolute-from-gregorian greg2))
7839 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7841 (setq sd (+ (* span arg) sd))))
7842 (let ((org-agenda-overriding-cmd
7843 ;; `cmd' may have been set by `org-agenda-run-series' which
7844 ;; uses `org-agenda-overriding-cmd' to decide whether
7845 ;; overriding is allowed for `cmd'
7846 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7847 (org-agenda-overriding-arguments
7848 (list (car args) sd span)))
7850 (org-agenda-find-same-or-today-or-agenda cnt))))
7852 (defun org-agenda-earlier (arg)
7853 "Go backward in time by the current span.
7854 With prefix ARG, go backward that many times the current span."
7856 (org-agenda-later (- arg)))
7858 (defun org-agenda-view-mode-dispatch ()
7859 "Call one of the view mode commands."
7861 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7862 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7863 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7864 (let ((a (read-char-exclusive)))
7866 (?\ (call-interactively 'org-agenda-reset-view))
7867 (?d (call-interactively 'org-agenda-day-view))
7868 (?w (call-interactively 'org-agenda-week-view))
7869 (?m (call-interactively 'org-agenda-month-view))
7870 (?y (call-interactively 'org-agenda-year-view))
7871 (?l (call-interactively 'org-agenda-log-mode))
7872 (?L (org-agenda-log-mode '(4)))
7873 (?c (org-agenda-log-mode 'clockcheck))
7874 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7875 (?a (call-interactively 'org-agenda-archives-mode))
7876 (?A (org-agenda-archives-mode 'files))
7877 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7878 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7879 (?G (call-interactively 'org-agenda-toggle-time-grid))
7880 (?D (call-interactively 'org-agenda-toggle-diary))
7881 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7882 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7883 (org-agenda-check-type t 'timeline 'agenda)
7885 (message "Display now includes inactive timestamps as well"))
7886 (?q (message "Abort"))
7887 (otherwise (error "Invalid key" )))))
7889 (defun org-agenda-reset-view ()
7890 "Switch to default view for agenda."
7892 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7893 (defun org-agenda-day-view (&optional day-of-month)
7894 "Switch to daily view for agenda.
7895 With argument DAY-OF-MONTH, switch to that day of the month."
7897 (org-agenda-change-time-span 'day day-of-month))
7898 (defun org-agenda-week-view (&optional iso-week)
7899 "Switch to daily view for agenda.
7900 With argument ISO-WEEK, switch to the corresponding ISO week.
7901 If ISO-WEEK has more then 2 digits, only the last two encode the
7902 week. Any digits before this encode a year. So 200712 means
7903 week 12 of year 2007. Years in the range 1938-2037 can also be
7904 written as 2-digit years."
7906 (org-agenda-change-time-span 'week iso-week))
7907 (defun org-agenda-month-view (&optional month)
7908 "Switch to monthly view for agenda.
7909 With argument MONTH, switch to that month."
7911 (org-agenda-change-time-span 'month month))
7912 (defun org-agenda-year-view (&optional year)
7913 "Switch to yearly view for agenda.
7914 With argument YEAR, switch to that year.
7915 If MONTH has more then 2 digits, only the last two encode the
7916 month. Any digits before this encode a year. So 200712 means
7917 December year 2007. Years in the range 1938-2037 can also be
7918 written as 2-digit years."
7921 (setq year (org-small-year-to-year year)))
7922 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7923 (org-agenda-change-time-span 'year year)
7926 (defun org-agenda-change-time-span (span &optional n)
7927 "Change the agenda view to SPAN.
7928 SPAN may be `day', `week', `month', `year'."
7929 (org-agenda-check-type t 'agenda)
7930 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7931 (curspan (nth 2 args)))
7932 (if (and (not n) (equal curspan span))
7933 (error "Viewing span is already \"%s\"" span))
7934 (let* ((sd (or (org-get-at-bol 'day)
7937 (sd (org-agenda-compute-starting-span sd span n))
7938 (org-agenda-overriding-cmd
7939 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7940 (org-agenda-overriding-arguments
7941 (list (car args) sd span)))
7943 (org-agenda-find-same-or-today-or-agenda))
7944 (org-agenda-set-mode-name)
7945 (message "Switched to %s view" span)))
7947 (defun org-agenda-compute-starting-span (sd span &optional n)
7948 "Compute starting date for agenda.
7949 SPAN may be `day', `week', `month', `year'. The return value
7950 is a cons cell with the starting date and the number of days,
7951 so that the date SD will be in that range."
7952 (let* ((greg (calendar-gregorian-from-absolute sd))
7959 (setq sd (+ (calendar-absolute-from-gregorian
7963 (let* ((nt (calendar-day-of-week
7964 (calendar-gregorian-from-absolute sd)))
7965 (d (if org-agenda-start-on-weekday
7966 (- nt org-agenda-start-on-weekday)
7969 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7973 (setq y1 (org-small-year-to-year (/ n 100))
7976 (calendar-absolute-from-iso
7978 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7981 (when (and n (> n 99))
7982 (setq y1 (org-small-year-to-year (/ n 100))
7984 (setq sd (calendar-absolute-from-gregorian
7985 (list (or n mg) 1 (or y1 yg))))))
7987 (setq sd (calendar-absolute-from-gregorian
7988 (list 1 1 (or n yg))))))
7991 (defun org-agenda-next-date-line (&optional arg)
7992 "Jump to the next line indicating a date in agenda buffer."
7994 (org-agenda-check-type t 'agenda 'timeline)
7995 (beginning-of-line 1)
7996 ;; This does not work if user makes date format that starts with a blank
7997 (if (looking-at "^\\S-") (forward-char 1))
7998 (if (not (re-search-forward "^\\S-" nil t arg))
8001 (error "No next date after this line in this buffer")))
8002 (goto-char (match-beginning 0)))
8004 (defun org-agenda-previous-date-line (&optional arg)
8005 "Jump to the previous line indicating a date in agenda buffer."
8007 (org-agenda-check-type t 'agenda 'timeline)
8008 (beginning-of-line 1)
8009 (if (not (re-search-backward "^\\S-" nil t arg))
8010 (error "No previous date before this line in this buffer")))
8012 ;; Initialize the highlight
8013 (defvar org-hl (make-overlay 1 1))
8014 (overlay-put org-hl 'face 'highlight)
8016 (defun org-highlight (begin end &optional buffer)
8017 "Highlight a region with overlay."
8018 (move-overlay org-hl begin end (or buffer (current-buffer))))
8020 (defun org-unhighlight ()
8021 "Detach overlay INDEX."
8022 (org-detach-overlay org-hl))
8024 (defun org-unhighlight-once ()
8025 "Remove the highlight from its position, and this function from the hook."
8026 (remove-hook 'pre-command-hook 'org-unhighlight-once)
8029 (defvar org-agenda-pre-follow-window-conf nil)
8030 (defun org-agenda-follow-mode ()
8031 "Toggle follow mode in an agenda buffer."
8033 (unless org-agenda-follow-mode
8034 (setq org-agenda-pre-follow-window-conf
8035 (current-window-configuration)))
8036 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
8037 (unless org-agenda-follow-mode
8038 (set-window-configuration org-agenda-pre-follow-window-conf))
8039 (org-agenda-set-mode-name)
8040 (org-agenda-do-context-action)
8041 (message "Follow mode is %s"
8042 (if org-agenda-follow-mode "on" "off")))
8044 (defun org-agenda-entry-text-mode (&optional arg)
8045 "Toggle entry text mode in an agenda buffer."
8047 (if (or org-agenda-tag-filter
8048 org-agenda-category-filter
8049 org-agenda-regexp-filter
8050 org-agenda-top-headline-filter)
8051 (user-error "Can't show entry text in filtered views")
8052 (setq org-agenda-entry-text-mode (or (integerp arg)
8053 (not org-agenda-entry-text-mode)))
8054 (org-agenda-entry-text-hide)
8055 (and org-agenda-entry-text-mode
8056 (let ((org-agenda-entry-text-maxlines
8057 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8058 (org-agenda-entry-text-show)))
8059 (org-agenda-set-mode-name)
8060 (message "Entry text mode is %s%s"
8061 (if org-agenda-entry-text-mode "on" "off")
8062 (if (not org-agenda-entry-text-mode) ""
8063 (format " (maximum number of lines is %d)"
8064 (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
8066 (defun org-agenda-clockreport-mode (&optional with-filter)
8067 "Toggle clocktable mode in an agenda buffer.
8068 With prefix arg WITH-FILTER, make the clocktable respect the current
8071 (org-agenda-check-type t 'agenda)
8073 (setq org-agenda-clockreport-mode 'with-filter)
8074 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
8075 (org-agenda-set-mode-name)
8077 (message "Clocktable mode is %s"
8078 (if org-agenda-clockreport-mode "on" "off")))
8080 (defun org-agenda-log-mode (&optional special)
8081 "Toggle log mode in an agenda buffer.
8082 With argument SPECIAL, show all possible log items, not only the ones
8083 configured in `org-agenda-log-mode-items'.
8084 With a double `C-u' prefix arg, show *only* log items, nothing else."
8086 (org-agenda-check-type t 'agenda 'timeline)
8087 (setq org-agenda-show-log
8089 ((equal special '(16)) 'only)
8090 ((eq special 'clockcheck)
8091 (if (eq org-agenda-show-log 'clockcheck)
8093 (special '(closed clock state))
8094 (t (not org-agenda-show-log))))
8095 (org-agenda-set-mode-name)
8097 (message "Log mode is %s"
8098 (if org-agenda-show-log "on" "off")))
8100 (defun org-agenda-archives-mode (&optional with-files)
8101 "Toggle inclusion of items in trees marked with :ARCHIVE:.
8102 When called with a prefix argument, include all archive files as well."
8104 (setq org-agenda-archives-mode
8105 (if with-files t (if org-agenda-archives-mode nil 'trees)))
8106 (org-agenda-set-mode-name)
8111 ((eq org-agenda-archives-mode nil)
8112 "No archives are included")
8113 ((eq org-agenda-archives-mode 'trees)
8114 (format "Trees with :%s: tag are included" org-archive-tag))
8115 ((eq org-agenda-archives-mode t)
8116 (format "Trees with :%s: tag and all active archive files are included"
8117 org-archive-tag)))))
8119 (defun org-agenda-toggle-diary ()
8120 "Toggle diary inclusion in an agenda buffer."
8122 (org-agenda-check-type t 'agenda)
8123 (setq org-agenda-include-diary (not org-agenda-include-diary))
8125 (org-agenda-set-mode-name)
8126 (message "Diary inclusion turned %s"
8127 (if org-agenda-include-diary "on" "off")))
8129 (defun org-agenda-toggle-deadlines ()
8130 "Toggle inclusion of entries with a deadline in an agenda buffer."
8132 (org-agenda-check-type t 'agenda)
8133 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
8135 (org-agenda-set-mode-name)
8136 (message "Deadlines inclusion turned %s"
8137 (if org-agenda-include-deadlines "on" "off")))
8139 (defun org-agenda-toggle-time-grid ()
8140 "Toggle time grid in an agenda buffer."
8142 (org-agenda-check-type t 'agenda)
8143 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
8145 (org-agenda-set-mode-name)
8146 (message "Time-grid turned %s"
8147 (if org-agenda-use-time-grid "on" "off")))
8149 (defun org-agenda-set-mode-name ()
8150 "Set the mode name to indicate all the small mode settings."
8153 (if (get 'org-agenda-files 'org-restrict) " []" "")
8155 '(:eval (org-agenda-span-name org-agenda-current-span))
8156 (if org-agenda-follow-mode " Follow" "")
8157 (if org-agenda-entry-text-mode " ETxt" "")
8158 (if org-agenda-include-diary " Diary" "")
8159 (if org-agenda-include-deadlines " Ddl" "")
8160 (if org-agenda-use-time-grid " Grid" "")
8161 (if (and (boundp 'org-habit-show-habits)
8162 org-habit-show-habits) " Habit" "")
8164 ((consp org-agenda-show-log) " LogAll")
8165 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
8166 (org-agenda-show-log " Log")
8168 (if (or org-agenda-category-filter
8169 (get 'org-agenda-category-filter :preset-filter))
8170 '(:eval (org-propertize
8175 (get 'org-agenda-category-filter :preset-filter)
8176 org-agenda-category-filter)
8179 'face 'org-agenda-filter-category
8180 'help-echo "Category used in filtering")) "")
8181 (if (or org-agenda-tag-filter
8182 (get 'org-agenda-tag-filter :preset-filter))
8183 '(:eval (org-propertize
8188 (get 'org-agenda-tag-filter :preset-filter)
8189 org-agenda-tag-filter)
8192 'face 'org-agenda-filter-tags
8193 'help-echo "Tags used in filtering")) "")
8194 (if (or org-agenda-regexp-filter
8195 (get 'org-agenda-regexp-filter :preset-filter))
8196 '(:eval (org-propertize
8201 (get 'org-agenda-regexp-filter :preset-filter)
8202 org-agenda-regexp-filter)
8205 'face 'org-agenda-filter-regexp
8206 'help-echo "Regexp used in filtering")) "")
8207 (if org-agenda-archives-mode
8208 (if (eq org-agenda-archives-mode t)
8210 (format " :%s:" org-archive-tag))
8212 (if org-agenda-clockreport-mode
8213 (if (eq org-agenda-clockreport-mode 'with-filter)
8214 " Clock{}" " Clock")
8216 (force-mode-line-update))
8218 (define-obsolete-function-alias
8219 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
8221 (defun org-agenda-update-agenda-type ()
8222 "Update the agenda type after each command."
8223 (setq org-agenda-type
8224 (or (get-text-property (point) 'org-agenda-type)
8225 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
8227 (defun org-agenda-next-line ()
8228 "Move cursor to the next line, and show if follow mode is active."
8230 (call-interactively 'next-line)
8231 (org-agenda-do-context-action))
8233 (defun org-agenda-previous-line ()
8234 "Move cursor to the previous line, and show if follow-mode is active."
8236 (call-interactively 'previous-line)
8237 (org-agenda-do-context-action))
8239 (defun org-agenda-next-item (n)
8240 "Move cursor to next agenda item."
8242 (let ((col (current-column)))
8244 (when (next-single-property-change (point-at-eol) 'org-marker)
8245 (move-end-of-line 1)
8246 (goto-char (next-single-property-change (point) 'org-marker))))
8247 (org-move-to-column col))
8248 (org-agenda-do-context-action))
8250 (defun org-agenda-previous-item (n)
8251 "Move cursor to next agenda item."
8254 (let ((col (current-column))
8255 (goto (save-excursion
8256 (move-end-of-line 0)
8257 (previous-single-property-change (point) 'org-marker))))
8258 (if goto (goto-char goto))
8259 (org-move-to-column col)))
8260 (org-agenda-do-context-action))
8262 (defun org-agenda-do-context-action ()
8263 "Show outline path and, maybe, follow mode window."
8264 (let ((m (org-get-at-bol 'org-marker)))
8265 (when (and (markerp m) (marker-buffer m))
8266 (and org-agenda-follow-mode
8267 (if org-agenda-follow-indirect
8268 (org-agenda-tree-to-indirect-buffer nil)
8270 (and org-agenda-show-outline-path
8271 (org-with-point-at m (org-display-outline-path t))))))
8273 (defun org-agenda-show-tags ()
8274 "Show the tags applicable to the current item."
8276 (let* ((tags (org-get-at-bol 'tags)))
8278 (message "Tags are :%s:"
8279 (org-no-properties (mapconcat 'identity tags ":")))
8280 (message "No tags associated with this line"))))
8282 (defun org-agenda-goto (&optional highlight)
8283 "Go to the Org-mode file which contains the item at point."
8285 (let* ((marker (or (org-get-at-bol 'org-marker)
8286 (org-agenda-error)))
8287 (buffer (marker-buffer marker))
8288 (pos (marker-position marker)))
8289 (switch-to-buffer-other-window buffer)
8293 (when (derived-mode-p 'org-mode)
8294 (org-show-context 'agenda)
8296 (and (outline-next-heading)
8297 (org-flag-heading nil)))) ; show the next heading
8298 (when (outline-invisible-p)
8299 (show-entry)) ; display invisible text
8300 (recenter (/ (window-height) 2))
8301 (run-hooks 'org-agenda-after-show-hook)
8302 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8304 (defvar org-agenda-after-show-hook nil
8305 "Normal hook run after an item has been shown from the agenda.
8306 Point is in the buffer where the item originated.")
8308 (defun org-agenda-kill ()
8309 "Kill the entry or subtree belonging to the current agenda entry."
8311 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8312 (let* ((bufname-orig (buffer-name))
8313 (marker (or (org-get-at-bol 'org-marker)
8314 (org-agenda-error)))
8315 (buffer (marker-buffer marker))
8316 (pos (marker-position marker))
8317 (type (org-get-at-bol 'type))
8318 dbeg dend (n 0) conf)
8319 (org-with-remote-undo buffer
8320 (with-current-buffer buffer
8323 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8324 (setq dbeg (progn (org-back-to-heading t) (point))
8325 dend (org-end-of-subtree t t))
8326 (setq dbeg (point-at-bol)
8327 dend (min (point-max) (1+ (point-at-eol)))))
8329 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8330 (setq conf (or (eq t org-agenda-confirm-kill)
8331 (and (numberp org-agenda-confirm-kill)
8332 (> n org-agenda-confirm-kill))))
8335 (format "Delete entry with %d lines in buffer \"%s\"? "
8336 n (buffer-name buffer))))
8338 (let ((org-agenda-buffer-name bufname-orig))
8339 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8340 (with-current-buffer buffer (delete-region dbeg dend))
8341 (message "Agenda item and source killed"))))
8343 (defvar org-archive-default-command) ; defined in org-archive.el
8344 (defun org-agenda-archive-default ()
8345 "Archive the entry or subtree belonging to the current agenda entry."
8347 (require 'org-archive)
8348 (org-agenda-archive-with org-archive-default-command))
8350 (defun org-agenda-archive-default-with-confirmation ()
8351 "Archive the entry or subtree belonging to the current agenda entry."
8353 (require 'org-archive)
8354 (org-agenda-archive-with org-archive-default-command 'confirm))
8356 (defun org-agenda-archive ()
8357 "Archive the entry or subtree belonging to the current agenda entry."
8359 (org-agenda-archive-with 'org-archive-subtree))
8361 (defun org-agenda-archive-to-archive-sibling ()
8362 "Move the entry to the archive sibling."
8364 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8366 (defun org-agenda-archive-with (cmd &optional confirm)
8367 "Move the entry to the archive sibling."
8369 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8370 (let* ((bufname-orig (buffer-name))
8371 (marker (or (org-get-at-bol 'org-marker)
8372 (org-agenda-error)))
8373 (buffer (marker-buffer marker))
8374 (pos (marker-position marker)))
8375 (org-with-remote-undo buffer
8376 (with-current-buffer buffer
8377 (if (derived-mode-p 'org-mode)
8379 (not (y-or-n-p "Archive this subtree or entry? ")))
8381 (save-window-excursion
8383 (let ((org-agenda-buffer-name bufname-orig))
8384 (org-remove-subtree-entries-from-agenda))
8385 (org-back-to-heading t)
8387 (error "Archiving works only in Org-mode files"))))))
8389 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8390 "Remove all lines in the agenda that correspond to a given subtree.
8391 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8392 If this information is not given, the function uses the tree at point."
8393 (let ((buf (or buf (current-buffer))) m p)
8395 (unless (and beg end)
8396 (org-back-to-heading t)
8398 (org-end-of-subtree t)
8400 (set-buffer (get-buffer org-agenda-buffer-name))
8402 (goto-char (point-max))
8403 (beginning-of-line 1)
8405 (when (and (setq m (org-get-at-bol 'org-marker))
8406 (equal buf (marker-buffer m))
8407 (setq p (marker-position m))
8410 (let ((inhibit-read-only t))
8411 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8412 (beginning-of-line 0))))))
8414 (defun org-agenda-refile (&optional goto rfloc no-update)
8415 "Refile the item at point.
8417 When GOTO is 0 or '(64), clear the refile cache.
8418 When GOTO is '(16), go to the location of the last refiled item.
8419 RFLOC can be a refile location obtained in a different way.
8420 When NO-UPDATE is non-nil, don't redo the agenda buffer."
8423 ((member goto '(0 (64)))
8424 (org-refile-cache-clear))
8426 (org-refile-goto-last-stored))
8428 (let* ((buffer-orig (buffer-name))
8429 (marker (or (org-get-at-bol 'org-hd-marker)
8430 (org-agenda-error)))
8431 (buffer (marker-buffer marker))
8432 (pos (marker-position marker))
8434 (org-refile-get-location
8435 (if goto "Goto" "Refile to") buffer
8436 org-refile-allow-creating-parent-nodes))))
8437 (with-current-buffer buffer
8442 (let ((org-agenda-buffer-name buffer-orig))
8443 (org-remove-subtree-entries-from-agenda))
8444 (org-refile goto buffer rfloc)))))
8445 (unless no-update (org-agenda-redo)))))
8447 (defun org-agenda-open-link (&optional arg)
8448 "Open the link(s) in the current entry, if any.
8449 This looks for a link in the displayed line in the agenda.
8450 It also looks at the text of the entry itself."
8452 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8453 (org-get-at-bol 'org-marker)))
8454 (buffer (and marker (marker-buffer marker)))
8455 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8456 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8458 (lk (if (stringp lk0) (list lk0) lk0))
8464 (with-current-buffer buffer
8465 (setq trg (and (string-match org-bracket-link-regexp l)
8466 (match-string 1 l)))
8467 (if (or (not trg) (string-match org-any-link-re trg))
8472 (when (search-forward l nil lkend)
8473 (goto-char (match-beginning 0))
8474 (org-open-at-point))))
8475 ;; This is an internal link, widen the buffer
8476 (switch-to-buffer-other-window buffer)
8479 (when (search-forward l nil lkend)
8480 (goto-char (match-beginning 0))
8481 (org-open-at-point)))))
8483 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8485 (beginning-of-line 1)
8486 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8487 (org-open-link-from-string (match-string 1)))
8488 (t (message "No link to open here")))))
8490 (defun org-agenda-copy-local-variable (var)
8491 "Get a variable from a referenced buffer and install it here."
8492 (let ((m (org-get-at-bol 'org-marker)))
8493 (when (and m (buffer-live-p (marker-buffer m)))
8494 (org-set-local var (with-current-buffer (marker-buffer m)
8495 (symbol-value var))))))
8497 (defun org-agenda-switch-to (&optional delete-other-windows)
8498 "Go to the Org-mode file which contains the item at point."
8500 (if (and org-return-follows-link
8501 (not (org-get-at-bol 'org-marker))
8502 (org-in-regexp org-bracket-link-regexp))
8503 (org-open-link-from-string (match-string 0))
8504 (let* ((marker (or (org-get-at-bol 'org-marker)
8505 (org-agenda-error)))
8506 (buffer (marker-buffer marker))
8507 (pos (marker-position marker)))
8508 (org-pop-to-buffer-same-window buffer)
8509 (and delete-other-windows (delete-other-windows))
8512 (when (derived-mode-p 'org-mode)
8513 (org-show-context 'agenda)
8515 (and (outline-next-heading)
8516 (org-flag-heading nil))) ; show the next heading
8517 (when (outline-invisible-p)
8518 (show-entry)) ; display invisible text
8519 (run-hooks 'org-agenda-after-show-hook)))))
8521 (defun org-agenda-goto-mouse (ev)
8522 "Go to the Org-mode file which contains the item at the mouse click."
8524 (mouse-set-point ev)
8527 (defun org-agenda-show (&optional full-entry)
8528 "Display the Org-mode file which contains the item at point.
8529 With prefix argument FULL-ENTRY, make the entire entry visible
8530 if it was hidden in the outline."
8532 (let ((win (selected-window)))
8534 (let ((org-show-entry-below t))
8535 (org-agenda-goto t))
8536 (org-agenda-goto t))
8537 (select-window win)))
8539 (defvar org-agenda-show-window nil)
8540 (defun org-agenda-show-and-scroll-up (&optional arg)
8541 "Display the Org-mode file which contains the item at point.
8542 When called repeatedly, scroll the window that is displaying the buffer.
8543 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8544 `show-subtree' to display the item, so that drawers and logbooks stay
8547 (let ((win (selected-window)))
8548 (if (and (window-live-p org-agenda-show-window)
8549 (eq this-command last-command))
8551 (select-window org-agenda-show-window)
8552 (ignore-errors (scroll-up)))
8554 (if arg (org-show-entry) (show-subtree))
8555 (setq org-agenda-show-window (selected-window)))
8556 (select-window win)))
8558 (defun org-agenda-show-scroll-down ()
8559 "Scroll down the window showing the agenda."
8561 (let ((win (selected-window)))
8562 (when (window-live-p org-agenda-show-window)
8563 (select-window org-agenda-show-window)
8564 (ignore-errors (scroll-down))
8565 (select-window win))))
8567 (defun org-agenda-show-1 (&optional more)
8568 "Display the Org-mode file which contains the item at point.
8569 The prefix arg selects the amount of information to display:
8572 1 just show the entry according to defaults.
8573 2 show the children view
8574 3 show the subtree view
8575 4 show the entire subtree and any LOGBOOK drawers
8576 5 show the entire subtree and any drawers
8577 With prefix argument FULL-ENTRY, make the entire entry visible
8578 if it was hidden in the outline."
8580 (let ((win (selected-window)))
8582 (org-recenter-heading 1)
8587 (org-back-to-heading)
8588 (run-hook-with-args 'org-cycle-hook 'folded))
8589 (message "Remote: FOLDED"))
8590 ((and (org-called-interactively-p 'any) (= more 1))
8591 (message "Remote: show with default settings"))
8596 (org-back-to-heading)
8597 (run-hook-with-args 'org-cycle-hook 'children))
8598 (message "Remote: CHILDREN"))
8602 (org-back-to-heading)
8603 (run-hook-with-args 'org-cycle-hook 'subtree))
8604 (message "Remote: SUBTREE"))
8606 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8608 (concat "^[ \t]*:\\("
8609 (mapconcat 'regexp-quote org-drawers "\\|")
8613 (org-back-to-heading)
8614 (org-cycle-hide-drawers 'subtree)))
8615 (message "Remote: SUBTREE AND LOGBOOK"))
8618 (message "Remote: SUBTREE AND ALL DRAWERS")))
8619 (select-window win)))
8621 (defun org-recenter-heading (n)
8623 (org-back-to-heading)
8626 (defvar org-agenda-cycle-counter nil)
8627 (defun org-agenda-cycle-show (&optional n)
8628 "Show the current entry in another window, with default settings.
8629 Default settings are taken from `org-show-hierarchy-above' and siblings.
8630 When use repeatedly in immediate succession, the remote entry will cycle
8633 children -> subtree -> folded
8635 When called with a numeric prefix arg, that arg will be passed through to
8636 `org-agenda-show-1'. For the interpretation of that argument, see the
8637 docstring of `org-agenda-show-1'."
8640 (setq org-agenda-cycle-counter n)
8641 (if (not (eq last-command this-command))
8642 (setq org-agenda-cycle-counter 1)
8643 (if (equal org-agenda-cycle-counter 0)
8644 (setq org-agenda-cycle-counter 2)
8645 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8646 (if (> org-agenda-cycle-counter 3)
8647 (setq org-agenda-cycle-counter 0)))))
8648 (org-agenda-show-1 org-agenda-cycle-counter))
8650 (defun org-agenda-recenter (arg)
8651 "Display the Org-mode file which contains the item at point and recenter."
8653 (let ((win (selected-window)))
8656 (select-window win)))
8658 (defun org-agenda-show-mouse (ev)
8659 "Display the Org-mode file which contains the item at the mouse click."
8661 (mouse-set-point ev)
8664 (defun org-agenda-check-no-diary ()
8665 "Check if the entry is a diary link and abort if yes."
8666 (if (org-get-at-bol 'org-agenda-diary-link)
8667 (org-agenda-error)))
8669 (defun org-agenda-error ()
8670 (error "Command not allowed in this line"))
8672 (defun org-agenda-tree-to-indirect-buffer (arg)
8673 "Show the subtree corresponding to the current entry in an indirect buffer.
8674 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8676 With a numerical prefix ARG, go up to this level and then take that tree.
8677 With a negative numeric ARG, go up by this number of levels.
8678 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8679 use the dedicated frame)."
8681 (if current-prefix-arg
8682 (org-agenda-do-tree-to-indirect-buffer arg)
8683 (let ((agenda-buffer (buffer-name))
8684 (agenda-window (selected-window))
8686 (and org-last-indirect-buffer
8687 (get-buffer-window org-last-indirect-buffer))))
8688 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8689 (unless (or (eq org-indirect-buffer-display 'new-frame)
8690 (eq org-indirect-buffer-display 'dedicated-frame))
8692 (unless (and indirect-window (window-live-p indirect-window))
8693 (setq indirect-window (split-window agenda-window)))
8694 (and indirect-window (select-window indirect-window))
8695 (switch-to-buffer org-last-indirect-buffer :norecord)
8696 (fit-window-to-buffer indirect-window)))
8697 (select-window (get-buffer-window agenda-buffer)))))
8699 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8700 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8701 (org-agenda-check-no-diary)
8702 (let* ((marker (or (org-get-at-bol 'org-marker)
8703 (org-agenda-error)))
8704 (buffer (marker-buffer marker))
8705 (pos (marker-position marker)))
8706 (with-current-buffer buffer
8709 (funcall 'org-tree-to-indirect-buffer arg)))))
8711 (defvar org-last-heading-marker (make-marker)
8712 "Marker pointing to the headline that last changed its TODO state
8713 by a remote command from the agenda.")
8715 (defun org-agenda-todo-nextset ()
8716 "Switch TODO entry to next sequence."
8718 (org-agenda-todo 'nextset))
8720 (defun org-agenda-todo-previousset ()
8721 "Switch TODO entry to previous sequence."
8723 (org-agenda-todo 'previousset))
8725 (defun org-agenda-todo (&optional arg)
8726 "Cycle TODO state of line at point, also in Org-mode file.
8727 This changes the line at point, all other lines in the agenda referring to
8728 the same tree node, and the headline of the tree node in the Org-mode file."
8730 (org-agenda-check-no-diary)
8731 (let* ((col (current-column))
8732 (marker (or (org-get-at-bol 'org-marker)
8733 (org-agenda-error)))
8734 (buffer (marker-buffer marker))
8735 (pos (marker-position marker))
8736 (hdmarker (org-get-at-bol 'org-hd-marker))
8737 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8738 (inhibit-read-only t)
8739 org-agenda-headline-snapshot-before-repeat newhead just-one)
8740 (org-with-remote-undo buffer
8741 (with-current-buffer buffer
8744 (org-show-context 'agenda)
8746 (and (outline-next-heading)
8747 (org-flag-heading nil))) ; show the next heading
8748 (let ((current-prefix-arg arg))
8749 (call-interactively 'org-todo))
8750 (and (bolp) (forward-char 1))
8751 (setq newhead (org-get-heading))
8752 (when (and (org-bound-and-true-p
8753 org-agenda-headline-snapshot-before-repeat)
8754 (not (equal org-agenda-headline-snapshot-before-repeat
8757 (setq newhead org-agenda-headline-snapshot-before-repeat
8760 (org-back-to-heading)
8761 (move-marker org-last-heading-marker (point))))
8762 (beginning-of-line 1)
8764 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8765 (org-move-to-column col))))
8767 (defun org-agenda-add-note (&optional arg)
8768 "Add a time-stamped note to the entry at point."
8770 (org-agenda-check-no-diary)
8771 (let* ((marker (or (org-get-at-bol 'org-marker)
8772 (org-agenda-error)))
8773 (buffer (marker-buffer marker))
8774 (pos (marker-position marker))
8775 (hdmarker (org-get-at-bol 'org-hd-marker))
8776 (inhibit-read-only t))
8777 (with-current-buffer buffer
8780 (org-show-context 'agenda)
8782 (and (outline-next-heading)
8783 (org-flag-heading nil))) ; show the next heading
8786 (defun org-agenda-change-all-lines (newhead hdmarker
8787 &optional fixface just-this)
8788 "Change all lines in the agenda buffer which match HDMARKER.
8789 The new content of the line will be NEWHEAD (as modified by
8790 `org-agenda-format-item'). HDMARKER is checked with
8791 `equal' against all `org-hd-marker' text properties in the file.
8792 If FIXFACE is non-nil, the face of each item is modified according to
8794 If JUST-THIS is non-nil, change just the current line, not all.
8795 If FORCE-TAGS is non nil, the car of it returns the new tags."
8796 (let* ((inhibit-read-only t)
8797 (line (org-current-line))
8798 (org-agenda-buffer (current-buffer))
8799 (thetags (with-current-buffer (marker-buffer hdmarker)
8800 (save-excursion (save-restriction (widen)
8801 (goto-char hdmarker)
8802 (org-get-tags-at)))))
8803 props m pl undone-face done-face finish new dotime level cat tags)
8805 (goto-char (point-max))
8806 (beginning-of-line 1)
8808 (setq finish (bobp))
8809 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8810 (or (not just-this) (= (org-current-line) line))
8812 (setq props (text-properties-at (point))
8813 dotime (org-get-at-bol 'dotime)
8814 cat (org-get-at-bol 'org-category)
8815 level (org-get-at-bol 'level)
8818 (let ((org-prefix-format-compiled
8819 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8820 org-prefix-format-compiled))
8821 (extra (org-get-at-bol 'extra)))
8822 (with-current-buffer (marker-buffer hdmarker)
8826 (org-agenda-format-item extra newhead level cat tags dotime)))))
8827 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8828 undone-face (org-get-at-bol 'undone-face)
8829 done-face (org-get-at-bol 'done-face))
8830 (beginning-of-line 1)
8833 (and (looking-at ".*\n?") (replace-match "")))
8835 (replace-match new t t)
8836 (beginning-of-line 1)
8837 (add-text-properties (point-at-bol) (point-at-eol) props)
8839 (add-text-properties
8840 (point-at-bol) (point-at-eol)
8842 (if org-last-todo-state-is-todo
8843 undone-face done-face))))
8844 (org-agenda-highlight-todo 'line)
8845 (beginning-of-line 1))
8846 (t (error "Line update did not work")))
8848 (narrow-to-region (point-at-bol) (point-at-eol))
8849 (org-agenda-finalize)))
8850 (beginning-of-line 0)))))
8852 (defun org-agenda-align-tags (&optional line)
8853 "Align all tags in agenda items to `org-agenda-tags-column'."
8854 (let ((inhibit-read-only t) l c)
8856 (goto-char (if line (point-at-bol) (point-min)))
8857 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8858 (if line (point-at-eol) nil) t)
8859 (add-text-properties
8860 (match-beginning 2) (match-end 2)
8861 (list 'face (delq nil (let ((prop (get-text-property
8862 (match-beginning 2) 'face)))
8863 (or (listp prop) (setq prop (list prop)))
8864 (if (memq 'org-tag prop)
8866 (cons 'org-tag prop))))))
8867 (setq l (- (match-end 2) (match-beginning 2))
8868 c (if (< org-agenda-tags-column 0)
8869 (- (abs org-agenda-tags-column) l)
8870 org-agenda-tags-column))
8871 (delete-region (match-beginning 1) (match-end 1))
8872 (goto-char (match-beginning 1))
8873 (insert (org-add-props
8874 (make-string (max 1 (- c (current-column))) ?\ )
8875 (plist-put (copy-sequence (text-properties-at (point)))
8877 (goto-char (point-min))
8878 (org-font-lock-add-tag-faces (point-max)))))
8880 (defun org-agenda-priority-up ()
8881 "Increase the priority of line at point, also in Org-mode file."
8883 (org-agenda-priority 'up))
8885 (defun org-agenda-priority-down ()
8886 "Decrease the priority of line at point, also in Org-mode file."
8888 (org-agenda-priority 'down))
8890 (defun org-agenda-priority (&optional force-direction)
8891 "Set the priority of line at point, also in Org-mode file.
8892 This changes the line at point, all other lines in the agenda referring to
8893 the same tree node, and the headline of the tree node in the Org-mode file.
8894 Called with a universal prefix arg, show the priority instead of setting it."
8896 (if (equal force-direction '(4))
8898 (unless org-enable-priority-commands
8899 (error "Priority commands are disabled"))
8900 (org-agenda-check-no-diary)
8901 (let* ((marker (or (org-get-at-bol 'org-marker)
8902 (org-agenda-error)))
8903 (hdmarker (org-get-at-bol 'org-hd-marker))
8904 (buffer (marker-buffer hdmarker))
8905 (pos (marker-position hdmarker))
8906 (inhibit-read-only t)
8908 (org-with-remote-undo buffer
8909 (with-current-buffer buffer
8912 (org-show-context 'agenda)
8914 (and (outline-next-heading)
8915 (org-flag-heading nil))) ; show the next heading
8916 (funcall 'org-priority force-direction)
8918 (setq newhead (org-get-heading)))
8919 (org-agenda-change-all-lines newhead hdmarker)
8920 (beginning-of-line 1)))))
8922 ;; FIXME: should fix the tags property of the agenda line.
8923 (defun org-agenda-set-tags (&optional tag onoff)
8924 "Set tags for the current headline."
8926 (org-agenda-check-no-diary)
8927 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8928 (call-interactively 'org-change-tag-in-region)
8929 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8930 (org-agenda-error)))
8931 (buffer (marker-buffer hdmarker))
8932 (pos (marker-position hdmarker))
8933 (inhibit-read-only t)
8935 (org-with-remote-undo buffer
8936 (with-current-buffer buffer
8940 (org-show-context 'agenda))
8942 (and (outline-next-heading)
8943 (org-flag-heading nil))) ; show the next heading
8946 (org-toggle-tag tag onoff)
8947 (call-interactively 'org-set-tags))
8949 (setq newhead (org-get-heading)))
8950 (org-agenda-change-all-lines newhead hdmarker)
8951 (beginning-of-line 1)))))
8953 (defun org-agenda-set-property ()
8954 "Set a property for the current headline."
8956 (org-agenda-check-no-diary)
8957 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8958 (org-agenda-error)))
8959 (buffer (marker-buffer hdmarker))
8960 (pos (marker-position hdmarker))
8961 (inhibit-read-only t)
8963 (org-with-remote-undo buffer
8964 (with-current-buffer buffer
8968 (org-show-context 'agenda))
8970 (and (outline-next-heading)
8971 (org-flag-heading nil))) ; show the next heading
8973 (call-interactively 'org-set-property)))))
8975 (defun org-agenda-set-effort ()
8976 "Set the effort property for the current headline."
8978 (org-agenda-check-no-diary)
8979 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8980 (org-agenda-error)))
8981 (buffer (marker-buffer hdmarker))
8982 (pos (marker-position hdmarker))
8983 (inhibit-read-only t)
8985 (org-with-remote-undo buffer
8986 (with-current-buffer buffer
8990 (org-show-context 'agenda))
8992 (and (outline-next-heading)
8993 (org-flag-heading nil))) ; show the next heading
8995 (call-interactively 'org-set-effort)
8997 (setq newhead (org-get-heading)))
8998 (org-agenda-change-all-lines newhead hdmarker))))
9000 (defun org-agenda-toggle-archive-tag ()
9001 "Toggle the archive tag for the current entry."
9003 (org-agenda-check-no-diary)
9004 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9005 (org-agenda-error)))
9006 (buffer (marker-buffer hdmarker))
9007 (pos (marker-position hdmarker))
9008 (inhibit-read-only t)
9010 (org-with-remote-undo buffer
9011 (with-current-buffer buffer
9014 (org-show-context 'agenda)
9016 (and (outline-next-heading)
9017 (org-flag-heading nil))) ; show the next heading
9018 (call-interactively 'org-toggle-archive-tag)
9020 (setq newhead (org-get-heading)))
9021 (org-agenda-change-all-lines newhead hdmarker)
9022 (beginning-of-line 1))))
9024 (defun org-agenda-do-date-later (arg)
9027 ((or (equal arg '(16))
9029 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9030 (setq this-command 'org-agenda-date-later-minutes)
9031 (org-agenda-date-later-minutes 1))
9032 ((or (equal arg '(4))
9034 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9035 (setq this-command 'org-agenda-date-later-hours)
9036 (org-agenda-date-later-hours 1))
9038 (org-agenda-date-later (prefix-numeric-value arg)))))
9040 (defun org-agenda-do-date-earlier (arg)
9043 ((or (equal arg '(16))
9045 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9046 (setq this-command 'org-agenda-date-earlier-minutes)
9047 (org-agenda-date-earlier-minutes 1))
9048 ((or (equal arg '(4))
9050 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9051 (setq this-command 'org-agenda-date-earlier-hours)
9052 (org-agenda-date-earlier-hours 1))
9054 (org-agenda-date-earlier (prefix-numeric-value arg)))))
9056 (defun org-agenda-date-later (arg &optional what)
9057 "Change the date of this item to ARG day(s) later."
9059 (org-agenda-check-type t 'agenda 'timeline)
9060 (org-agenda-check-no-diary)
9061 (let* ((marker (or (org-get-at-bol 'org-marker)
9062 (org-agenda-error)))
9063 (buffer (marker-buffer marker))
9064 (pos (marker-position marker))
9066 (org-with-remote-undo buffer
9067 (with-current-buffer buffer
9070 (if (not (org-at-timestamp-p))
9071 (error "Cannot find time stamp"))
9072 (when (and org-agenda-move-date-from-past-immediately-to-today
9074 (or (not what) (eq what 'day))
9075 (not (save-match-data (org-at-date-range-p))))
9076 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
9077 cdate (calendar-absolute-from-gregorian
9078 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
9081 ;; immediately shift to today
9082 (setq arg (- today cdate))))
9083 (org-timestamp-change arg (or what 'day))
9084 (when (and (org-at-date-range-p)
9085 (re-search-backward org-tr-regexp-both (point-at-bol)))
9086 (let ((end org-last-changed-timestamp))
9087 (org-timestamp-change arg (or what 'day))
9088 (setq org-last-changed-timestamp
9089 (concat org-last-changed-timestamp "--" end)))))
9090 (org-agenda-show-new-time marker org-last-changed-timestamp))
9091 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9093 (defun org-agenda-date-earlier (arg &optional what)
9094 "Change the date of this item to ARG day(s) earlier."
9096 (org-agenda-date-later (- arg) what))
9098 (defun org-agenda-date-later-minutes (arg)
9099 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9101 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9102 (org-agenda-date-later arg 'minute))
9104 (defun org-agenda-date-earlier-minutes (arg)
9105 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9107 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9108 (org-agenda-date-earlier arg 'minute))
9110 (defun org-agenda-date-later-hours (arg)
9111 "Change the time of this item, in hour steps."
9113 (org-agenda-date-later arg 'hour))
9115 (defun org-agenda-date-earlier-hours (arg)
9116 "Change the time of this item, in hour steps."
9118 (org-agenda-date-earlier arg 'hour))
9120 (defun org-agenda-show-new-time (marker stamp &optional prefix)
9121 "Show new date stamp via text properties."
9122 ;; We use text properties to make this undoable
9123 (let ((inhibit-read-only t))
9124 (setq stamp (concat prefix " => " stamp " "))
9126 (goto-char (point-max))
9128 (when (equal marker (org-get-at-bol 'org-marker))
9129 (org-move-to-column (- (window-width) (length stamp)) t)
9130 (org-agenda-fix-tags-filter-overlays-at (point))
9131 (if (featurep 'xemacs)
9132 ;; Use `duplicable' property to trigger undo recording
9133 (let ((ex (make-extent nil nil))
9134 (gl (make-glyph stamp)))
9135 (set-glyph-face gl 'secondary-selection)
9136 (set-extent-properties
9137 ex (list 'invisible t 'end-glyph gl 'duplicable t))
9138 (insert-extent ex (1- (point)) (point-at-eol)))
9139 (add-text-properties
9140 (1- (point)) (point-at-eol)
9141 (list 'display (org-add-props stamp nil
9142 'face 'secondary-selection))))
9143 (beginning-of-line 1))
9144 (beginning-of-line 0)))))
9146 (defun org-agenda-date-prompt (arg)
9147 "Change the date of this item. Date is prompted for, with default today.
9148 The prefix ARG is passed to the `org-time-stamp' command and can therefore
9149 be used to request time specification in the time stamp."
9151 (org-agenda-check-type t 'agenda 'timeline)
9152 (org-agenda-check-no-diary)
9153 (let* ((marker (or (org-get-at-bol 'org-marker)
9154 (org-agenda-error)))
9155 (buffer (marker-buffer marker))
9156 (pos (marker-position marker)))
9157 (org-with-remote-undo buffer
9158 (with-current-buffer buffer
9161 (if (not (org-at-timestamp-p t))
9162 (error "Cannot find time stamp"))
9163 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
9164 (org-agenda-show-new-time marker org-last-changed-timestamp))
9165 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9167 (defun org-agenda-schedule (arg &optional time)
9168 "Schedule the item at point.
9169 ARG is passed through to `org-schedule'."
9171 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9172 (org-agenda-check-no-diary)
9173 (let* ((marker (or (org-get-at-bol 'org-marker)
9174 (org-agenda-error)))
9175 (type (marker-insertion-type marker))
9176 (buffer (marker-buffer marker))
9177 (pos (marker-position marker))
9178 (org-insert-labeled-timestamps-at-point nil)
9180 (set-marker-insertion-type marker t)
9181 (org-with-remote-undo buffer
9182 (with-current-buffer buffer
9185 (setq ts (org-schedule arg time)))
9186 (org-agenda-show-new-time marker ts " S"))
9189 (defun org-agenda-deadline (arg &optional time)
9190 "Schedule the item at point.
9191 ARG is passed through to `org-deadline'."
9193 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9194 (org-agenda-check-no-diary)
9195 (let* ((marker (or (org-get-at-bol 'org-marker)
9196 (org-agenda-error)))
9197 (buffer (marker-buffer marker))
9198 (pos (marker-position marker))
9199 (org-insert-labeled-timestamps-at-point nil)
9201 (org-with-remote-undo buffer
9202 (with-current-buffer buffer
9205 (setq ts (org-deadline arg time)))
9206 (org-agenda-show-new-time marker ts " D"))
9209 (defun org-agenda-clock-in (&optional arg)
9210 "Start the clock on the currently selected item."
9212 (org-agenda-check-no-diary)
9213 (if (equal arg '(4))
9215 (let* ((marker (or (org-get-at-bol 'org-marker)
9216 (org-agenda-error)))
9217 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
9218 (pos (marker-position marker))
9219 (col (current-column))
9221 (org-with-remote-undo (marker-buffer marker)
9222 (with-current-buffer (marker-buffer marker)
9225 (org-show-context 'agenda)
9227 (org-cycle-hide-drawers 'children)
9229 (setq newhead (org-get-heading)))
9230 (org-agenda-change-all-lines newhead hdmarker))
9231 (org-move-to-column col))))
9233 (defun org-agenda-clock-out ()
9234 "Stop the currently running clock."
9236 (unless (marker-buffer org-clock-marker)
9237 (error "No running clock"))
9238 (let ((marker (make-marker)) (col (current-column)) newhead)
9239 (org-with-remote-undo (marker-buffer org-clock-marker)
9240 (with-current-buffer (marker-buffer org-clock-marker)
9244 (goto-char org-clock-marker)
9245 (org-back-to-heading t)
9246 (move-marker marker (point))
9248 (setq newhead (org-get-heading))))))
9249 (org-agenda-change-all-lines newhead marker)
9250 (move-marker marker nil)
9251 (org-move-to-column col)
9252 (org-agenda-unmark-clocking-task)))
9254 (defun org-agenda-clock-cancel (&optional arg)
9255 "Cancel the currently running clock."
9257 (unless (marker-buffer org-clock-marker)
9258 (user-error "No running clock"))
9259 (org-with-remote-undo (marker-buffer org-clock-marker)
9260 (org-clock-cancel)))
9262 (defun org-agenda-clock-goto ()
9263 "Jump to the currently clocked in task within the agenda.
9264 If the currently clocked in task is not listed in the agenda
9265 buffer, display it in another window."
9269 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
9270 (setq pos (overlay-start o))))
9271 (overlays-in (point-min) (point-max)))
9272 (cond (pos (goto-char pos))
9273 ;; If the currently clocked entry is not in the agenda
9274 ;; buffer, we visit it in another window:
9275 (org-clock-current-task
9276 (org-switch-to-buffer-other-window (org-clock-goto)))
9277 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
9279 (defun org-agenda-diary-entry-in-org-file ()
9280 "Make a diary entry in the file `org-agenda-diary-file'."
9281 (let (d1 d2 char (text "") dp1 dp2)
9282 (if (equal (buffer-name) "*Calendar*")
9283 (setq d1 (calendar-cursor-to-date t)
9284 d2 (car calendar-mark-ring))
9285 (setq dp1 (get-text-property (point-at-bol) 'day))
9286 (unless dp1 (user-error "No date defined in current line"))
9287 (setq d1 (calendar-gregorian-from-absolute dp1)
9288 d2 (and (ignore-errors (mark))
9291 (setq dp2 (get-text-property (point-at-bol) 'day)))
9292 (calendar-gregorian-from-absolute dp2))))
9293 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9294 (setq char (read-char-exclusive))
9297 (setq text (read-string "Day entry: "))
9298 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9299 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9301 (setq d1 (list (car d1) (nth 1 d1)
9302 (read-number (format "Reference year [%d]: " (nth 2 d1))
9304 (setq text (read-string "Anniversary (use %d to show years): "))
9305 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9306 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9308 (setq text (read-string "Block entry: "))
9309 (unless (and d1 d2 (not (equal d1 d2)))
9310 (user-error "No block of days selected"))
9311 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9312 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9314 (org-switch-to-buffer-other-window
9315 (find-file-noselect org-agenda-diary-file))
9316 (require 'org-datetree)
9317 (org-datetree-find-date-create d1)
9319 (t (user-error "Invalid selection character `%c'" char)))))
9321 (defcustom org-agenda-insert-diary-strategy 'date-tree
9322 "Where in `org-agenda-diary-file' should new entries be added?
9325 date-tree in the date tree, as child of the date
9326 top-level as top-level entries at the end of the file."
9329 (const :tag "in a date tree" date-tree)
9330 (const :tag "as top level at end of file" top-level)))
9332 (defcustom org-agenda-insert-diary-extract-time nil
9333 "Non-nil means extract any time specification from the diary entry."
9338 (defcustom org-agenda-bulk-mark-char ">"
9339 "A single-character string to be used as the bulk mark."
9344 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9345 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9346 If TEXT is not empty, it will become the headline of the new entry, and
9347 the resulting entry will not be shown. When TEXT is empty, switch to
9348 `org-agenda-diary-file' and let the user finish the entry there."
9349 (let ((cw (current-window-configuration)))
9350 (org-switch-to-buffer-other-window
9351 (find-file-noselect org-agenda-diary-file))
9353 (goto-char (point-min))
9355 ((eq type 'anniversary)
9356 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9358 (or (org-at-heading-p t)
9360 (outline-next-heading)
9361 (insert "* Anniversaries\n\n")
9362 (beginning-of-line -1)))))
9363 (outline-next-heading)
9364 (org-back-over-empty-lines)
9367 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9368 (nth 2 d1) (car d1) (nth 1 d1) text)))
9370 (let ((org-prefix-has-time t)
9371 (org-agenda-time-leading-zero t)
9373 (if org-agenda-insert-diary-extract-time
9374 ;; Use org-agenda-format-item to parse text for a time-range and
9375 ;; remove it. FIXME: This is a hack, we should refactor
9376 ;; that function to make time extraction available separately
9377 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9378 time (get-text-property 0 'time fmt)
9379 time2 (if (> (length time) 0)
9380 ;; split-string removes trailing ...... if
9381 ;; no end time given. First space
9382 ;; separates time from date.
9383 (concat " " (car (split-string time "\\.")))
9385 text (get-text-property 0 'txt fmt)))
9386 (if (eq org-agenda-insert-diary-strategy 'top-level)
9387 (org-agenda-insert-diary-as-top-level text)
9388 (require 'org-datetree)
9389 (org-datetree-find-date-create d1)
9390 (org-agenda-insert-diary-make-new-entry text))
9391 (org-insert-time-stamp (org-time-from-absolute
9392 (calendar-absolute-from-gregorian d1))
9393 nil nil nil nil time2))
9396 (if (> (calendar-absolute-from-gregorian d1)
9397 (calendar-absolute-from-gregorian d2))
9398 (setq d1 (prog1 d2 (setq d2 d1))))
9399 (if (eq org-agenda-insert-diary-strategy 'top-level)
9400 (org-agenda-insert-diary-as-top-level text)
9401 (require 'org-datetree)
9402 (org-datetree-find-date-create d1)
9403 (org-agenda-insert-diary-make-new-entry text))
9404 (org-insert-time-stamp (org-time-from-absolute
9405 (calendar-absolute-from-gregorian d1)))
9407 (org-insert-time-stamp (org-time-from-absolute
9408 (calendar-absolute-from-gregorian d2)))
9410 (if (string-match "\\S-" text)
9412 (set-window-configuration cw)
9413 (message "%s entry added to %s"
9414 (capitalize (symbol-name type))
9415 (abbreviate-file-name org-agenda-diary-file)))
9417 (message "Please finish entry here"))))
9419 (defun org-agenda-insert-diary-as-top-level (text)
9420 "Make new entry as a top-level entry at the end of the file.
9421 Add TEXT as headline, and position the cursor in the second line so that
9422 a timestamp can be added there."
9424 (goto-char (point-max))
9425 (or (bolp) (insert "\n"))
9426 (insert "* " text "\n")
9427 (if org-adapt-indentation (org-indent-to-column 2)))
9429 (defun org-agenda-insert-diary-make-new-entry (text)
9430 "Make new entry as last child of current entry.
9431 Add TEXT as headline, and position the cursor in the second line so that
9432 a timestamp can be added there."
9433 (let ((org-show-following-heading t)
9434 (org-show-siblings t)
9435 (org-show-hierarchy-above t)
9436 (org-show-entry-below t)
9438 (outline-next-heading)
9439 (org-back-over-empty-lines)
9440 (or (looking-at "[ \t]*$")
9441 (progn (insert "\n") (backward-char 1)))
9442 (org-insert-heading nil t)
9444 (setq col (current-column))
9446 (if org-adapt-indentation (org-indent-to-column col))
9447 (let ((org-show-following-heading t)
9448 (org-show-siblings t)
9449 (org-show-hierarchy-above t)
9450 (org-show-entry-below t))
9451 (org-show-context))))
9453 (defun org-agenda-diary-entry ()
9454 "Make a diary entry, like the `i' command from the calendar.
9455 All the standard commands work: block, weekly etc.
9456 When `org-agenda-diary-file' points to a file,
9457 `org-agenda-diary-entry-in-org-file' is called instead to create
9458 entries in that Org-mode file."
9460 (if (not (eq org-agenda-diary-file 'diary-file))
9461 (org-agenda-diary-entry-in-org-file)
9462 (require 'diary-lib)
9464 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9465 (read-char-exclusive)))
9466 (cmd (cdr (assoc char
9467 '((?d . insert-diary-entry)
9468 (?w . insert-weekly-diary-entry)
9469 (?m . insert-monthly-diary-entry)
9470 (?y . insert-yearly-diary-entry)
9471 (?a . insert-anniversary-diary-entry)
9472 (?b . insert-block-diary-entry)
9473 (?c . insert-cyclic-diary-entry)))))
9474 (oldf (symbol-function 'calendar-cursor-to-date))
9475 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9477 (mark (or (mark t) (point))))
9479 (user-error "No command associated with <%c>" char))
9480 (unless (and (get-text-property point 'day)
9481 (or (not (equal ?b char))
9482 (get-text-property mark 'day)))
9483 (user-error "Don't know which date to use for diary entry"))
9484 ;; We implement this by hacking the `calendar-cursor-to-date' function
9485 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9486 (let ((calendar-mark-ring
9487 (list (calendar-gregorian-from-absolute
9488 (or (get-text-property mark 'day)
9489 (get-text-property point 'day))))))
9492 (fset 'calendar-cursor-to-date
9493 (lambda (&optional error dummy)
9494 (calendar-gregorian-from-absolute
9495 (get-text-property point 'day))))
9496 (call-interactively cmd))
9497 (fset 'calendar-cursor-to-date oldf))))))
9499 (defun org-agenda-execute-calendar-command (cmd)
9500 "Execute a calendar command from the agenda with date from cursor."
9501 (org-agenda-check-type t 'agenda 'timeline)
9502 (require 'diary-lib)
9503 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9504 (user-error "Don't know which date to use for the calendar command"))
9505 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9507 (date (calendar-gregorian-from-absolute
9508 (get-text-property point 'day)))
9509 ;; the following 2 vars are needed in the calendar
9510 (displayed-month (car date))
9511 (displayed-year (nth 2 date)))
9514 (fset 'calendar-cursor-to-date
9515 (lambda (&optional error dummy)
9516 (calendar-gregorian-from-absolute
9517 (get-text-property point 'day))))
9518 (call-interactively cmd))
9519 (fset 'calendar-cursor-to-date oldf))))
9521 (defun org-agenda-phases-of-moon ()
9522 "Display the phases of the moon for the 3 months around the cursor date."
9524 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9526 (defun org-agenda-holidays ()
9527 "Display the holidays for the 3 months around the cursor date."
9529 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9531 (defvar calendar-longitude) ; defined in calendar.el
9532 (defvar calendar-latitude) ; defined in calendar.el
9533 (defvar calendar-location-name) ; defined in calendar.el
9535 (defun org-agenda-sunrise-sunset (arg)
9536 "Display sunrise and sunset for the cursor date.
9537 Latitude and longitude can be specified with the variables
9538 `calendar-latitude' and `calendar-longitude'. When called with prefix
9539 argument, latitude and longitude will be prompted for."
9542 (let ((calendar-longitude (if arg nil calendar-longitude))
9543 (calendar-latitude (if arg nil calendar-latitude))
9544 (calendar-location-name
9545 (if arg "the given coordinates" calendar-location-name)))
9546 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9548 (defun org-agenda-goto-calendar ()
9549 "Open the Emacs calendar with the date at the cursor."
9551 (org-agenda-check-type t 'agenda 'timeline)
9552 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9553 (user-error "Don't know which date to open in calendar")))
9554 (date (calendar-gregorian-from-absolute day))
9555 (calendar-move-hook nil)
9556 (calendar-view-holidays-initially-flag nil)
9557 (calendar-view-diary-initially-flag nil))
9559 (calendar-goto-date date)))
9562 (defun org-calendar-goto-agenda ()
9563 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9564 This is a command that has to be installed in `calendar-mode-map'."
9566 (org-agenda-list nil (calendar-absolute-from-gregorian
9567 (calendar-cursor-to-date))
9570 (defun org-agenda-convert-date ()
9572 (org-agenda-check-type t 'agenda 'timeline)
9573 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9576 (user-error "Don't know which date to convert"))
9577 (setq date (calendar-gregorian-from-absolute day))
9579 "Gregorian: " (calendar-date-string date) "\n"
9580 "ISO: " (calendar-iso-date-string date) "\n"
9581 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9582 "Julian: " (calendar-julian-date-string date) "\n"
9583 "Astron. JD: " (calendar-astro-date-string date)
9584 " (Julian date number at noon UTC)\n"
9585 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9586 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9587 "French: " (calendar-french-date-string date) "\n"
9588 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9589 "Mayan: " (calendar-mayan-date-string date) "\n"
9590 "Coptic: " (calendar-coptic-date-string date) "\n"
9591 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9592 "Persian: " (calendar-persian-date-string date) "\n"
9593 "Chinese: " (calendar-chinese-date-string date) "\n"))
9594 (with-output-to-temp-buffer "*Dates*"
9596 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9600 (defun org-agenda-bulk-marked-p ()
9601 (eq (get-char-property (point-at-bol) 'type)
9602 'org-marked-entry-overlay))
9604 (defun org-agenda-bulk-mark (&optional arg)
9605 "Mark the entry at point for future bulk action."
9607 (dotimes (i (or arg 1))
9608 (unless (org-get-at-bol 'org-agenda-diary-link)
9609 (let* ((m (org-get-at-bol 'org-hd-marker))
9611 (unless (org-agenda-bulk-marked-p)
9612 (unless m (user-error "Nothing to mark at point"))
9613 (push m org-agenda-bulk-marked-entries)
9614 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9615 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9616 (org-get-todo-face "TODO")
9618 (overlay-put ov 'type 'org-marked-entry-overlay))
9621 (goto-char (next-single-property-change (point) 'txt)))
9622 (beginning-of-line 2))
9623 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9624 (beginning-of-line 2))
9625 (message "%d entries marked for bulk action"
9626 (length org-agenda-bulk-marked-entries))))))
9628 (defun org-agenda-bulk-mark-all ()
9629 "Mark all entries for future agenda bulk action."
9631 (org-agenda-bulk-mark-regexp "."))
9633 (defun org-agenda-bulk-mark-regexp (regexp)
9634 "Mark entries matching REGEXP for future agenda bulk action."
9635 (interactive "sMark entries matching regexp: ")
9636 (let ((entries-marked 0) txt-at-point)
9638 (goto-char (point-min))
9639 (goto-char (next-single-property-change (point) 'txt))
9640 (while (and (re-search-forward regexp nil t)
9641 (setq txt-at-point (get-text-property (point) 'txt)))
9642 (when (string-match regexp txt-at-point)
9643 (setq entries-marked (1+ entries-marked))
9644 (call-interactively 'org-agenda-bulk-mark))))
9645 (if (not entries-marked)
9646 (message "No entry matching this regexp."))))
9648 (defun org-agenda-bulk-unmark (&optional arg)
9649 "Unmark the entry at point for future bulk action."
9652 (org-agenda-bulk-unmark-all)
9653 (cond ((org-agenda-bulk-marked-p)
9654 (org-agenda-bulk-remove-overlays
9655 (point-at-bol) (+ 2 (point-at-bol)))
9656 (setq org-agenda-bulk-marked-entries
9657 (delete (org-get-at-bol 'org-hd-marker)
9658 org-agenda-bulk-marked-entries))
9661 (goto-char (next-single-property-change (point) 'txt)))
9662 (beginning-of-line 2))
9663 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9664 (beginning-of-line 2))
9665 (message "%d entries left marked for bulk action"
9666 (length org-agenda-bulk-marked-entries)))
9667 (t (message "No entry to unmark here")))))
9669 (defun org-agenda-bulk-toggle-all ()
9670 "Toggle all marks for bulk action."
9673 (goto-char (point-min))
9674 (while (ignore-errors
9675 (goto-char (next-single-property-change (point) 'txt)))
9676 (org-agenda-bulk-toggle))))
9678 (defun org-agenda-bulk-toggle ()
9679 "Toggle the mark at point for bulk action."
9681 (if (org-agenda-bulk-marked-p)
9682 (org-agenda-bulk-unmark)
9683 (org-agenda-bulk-mark)))
9685 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9686 "Remove the mark overlays between BEG and END in the agenda buffer.
9687 BEG and END default to the buffer limits.
9689 This only removes the overlays, it does not remove the markers
9690 from the list in `org-agenda-bulk-marked-entries'."
9693 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9694 (delete-overlay ov)))
9695 (overlays-in (or beg (point-min)) (or end (point-max)))))
9697 (defun org-agenda-bulk-unmark-all ()
9698 "Remove all marks in the agenda buffer.
9699 This will remove the markers and the overlays."
9701 (if (null org-agenda-bulk-marked-entries)
9702 (message "No entry to unmark")
9703 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9704 (setq org-agenda-bulk-marked-entries nil)
9705 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9707 (defcustom org-agenda-persistent-marks nil
9708 "Non-nil means marked items will stay marked after a bulk action.
9709 You can toggle this interactively by typing `p' when prompted for a
9715 (defun org-agenda-bulk-action (&optional arg)
9716 "Execute an remote-editing action on all marked entries.
9717 The prefix arg is passed through to the command if possible."
9719 ;; Make sure we have markers, and only valid ones
9720 (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
9723 (unless (and (markerp m)
9725 (buffer-live-p (marker-buffer m))
9726 (marker-position m))
9727 (user-error "Marker %s for bulk command is invalid" m)))
9728 org-agenda-bulk-marked-entries)
9730 ;; Prompt for the bulk command
9731 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9732 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9733 "[S]catter [f]unction "
9734 (when org-agenda-bulk-custom-functions
9735 (concat " Custom: ["
9736 (mapconcat (lambda(f) (char-to-string (car f)))
9737 org-agenda-bulk-custom-functions "")
9740 (let* ((action (read-char-exclusive))
9741 (org-log-refile (if org-log-refile 'time nil))
9742 (entries (reverse org-agenda-bulk-marked-entries))
9743 (org-overriding-default-time
9744 (if (get-text-property (point) 'org-agenda-date-header)
9745 (org-get-cursor-date)))
9747 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9750 (let ((org-agenda-persistent-marks
9751 (not org-agenda-persistent-marks)))
9752 (org-agenda-bulk-action)
9756 (setq cmd '(org-agenda-archive)))
9759 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9761 ((member action '(?r ?w))
9762 (setq rfloc (org-refile-get-location
9764 (marker-buffer (car entries))
9765 org-refile-allow-creating-parent-nodes))
9767 (setcar (nthcdr 3 rfloc)
9768 (move-marker (make-marker) (nth 3 rfloc)
9769 (or (get-file-buffer (nth 1 rfloc))
9770 (find-buffer-visiting (nth 1 rfloc))
9771 (error "This should not happen")))))
9773 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9777 (setq state (org-icompleting-read
9779 (with-current-buffer (marker-buffer (car entries))
9780 (mapcar 'list org-todo-keywords-1))))
9781 (setq cmd `(let ((org-inhibit-blocking t)
9782 (org-inhibit-logging 'note))
9783 (org-agenda-todo ,state))))
9785 ((memq action '(?- ?+))
9786 (setq tag (org-icompleting-read
9787 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9788 (with-current-buffer (marker-buffer (car entries))
9791 (if (stringp (car x)) x)) org-tag-alist)))))
9792 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9794 ((memq action '(?s ?d))
9799 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9800 org-overriding-default-time)))
9801 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9802 (setq cmd `(eval '(,c1 arg ,time)))))
9805 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9806 (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9807 (let ((days (read-number
9808 (format "Scatter tasks across how many %sdays: "
9809 (if arg "week" "")) 7)))
9811 `(let ((distance (1+ (random ,days))))
9813 (let ((dist distance)
9815 (calendar-day-of-week
9816 (calendar-gregorian-from-absolute (org-today)))))
9817 (dotimes (i (1+ dist))
9818 (while (member day-of-week org-agenda-weekend-days)
9821 (if (= day-of-week 7)
9822 (setq day-of-week 0)))
9824 (if (= day-of-week 7)
9825 (setq day-of-week 0)))))
9826 ;; silently fail when try to replan a sexp entry
9828 (let* ((date (calendar-gregorian-from-absolute
9829 (+ (org-today) distance)))
9830 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9832 (org-agenda-schedule nil time))
9835 ((assoc action org-agenda-bulk-custom-functions)
9836 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9840 (setq cmd (list (intern
9841 (org-icompleting-read "Function: "
9842 obarray 'fboundp t nil nil)))))
9844 (t (user-error "Invalid bulk action")))
9846 ;; Sort the markers, to make sure that parents are handled before children
9847 (setq entries (sort entries
9850 ((equal (marker-buffer a) (marker-buffer b))
9851 (< (marker-position a) (marker-position b)))
9853 (string< (buffer-name (marker-buffer a))
9854 (buffer-name (marker-buffer b))))))))
9856 ;; Now loop over all markers and apply cmd
9857 (while (setq e (pop entries))
9858 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9860 (progn (message "Skipping removed entry at %s" e)
9861 (setq cntskip (1+ cntskip)))
9863 (let (org-loop-over-headlines-in-active-region)
9865 (setq cnt (1+ cnt))))
9866 (when redo-at-end (org-agenda-redo))
9867 (unless org-agenda-persistent-marks
9868 (org-agenda-bulk-unmark-all))
9869 (message "Acted on %d entries%s%s"
9873 (format ", skipped %d (disappeared before their turn)"
9875 (if (not org-agenda-persistent-marks)
9876 "" " (kept marked)"))))))
9878 (defun org-agenda-capture (&optional with-time)
9879 "Call `org-capture' with the date at point.
9880 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9881 current HH:MM time."
9883 (if (not (eq major-mode 'org-agenda-mode))
9884 (user-error "You cannot do this outside of agenda buffers")
9885 (let ((org-overriding-default-time
9886 (org-get-cursor-date (equal with-time 1))))
9887 (call-interactively 'org-capture))))
9889 ;;; Dragging agenda lines forward/backward
9891 (defun org-agenda-drag-line-forward (arg)
9892 "Drag an agenda line forward by ARG lines."
9894 (let ((inhibit-read-only t) lst)
9897 (beginning-of-line 2)
9898 (push (not (get-text-property (point) 'txt)) lst))
9900 (message "Cannot move line forward")
9901 (org-drag-line-forward arg))))
9903 (defun org-agenda-drag-line-backward (arg)
9904 "Drag an agenda line backward by ARG lines."
9906 (let ((inhibit-read-only t) lst)
9909 (beginning-of-line 0)
9910 (push (not (get-text-property (point) 'txt)) lst))
9912 (message "Cannot move line backward")
9913 (org-drag-line-backward arg))))
9917 (defun org-agenda-show-the-flagging-note ()
9918 "Display the flagging note in the other window.
9919 When called a second time in direct sequence, offer to remove the FLAGGING
9920 tag and (if present) the flagging note."
9922 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9923 (win (selected-window))
9924 note heading newhead)
9926 (user-error "No linked entry at point"))
9927 (if (and (eq this-command last-command)
9928 (y-or-n-p "Unflag and remove any flagging note? "))
9930 (org-agenda-remove-flag hdmarker)
9931 (let ((win (get-buffer-window "*Flagging Note*")))
9932 (and win (delete-window win)))
9933 (message "Entry unflagged"))
9934 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9936 (user-error "No flagging note"))
9938 (org-switch-to-buffer-other-window "*Flagging Note*")
9941 (goto-char (point-min))
9942 (while (re-search-forward "\\\\n" nil t)
9943 (replace-match "\n" t t))
9944 (goto-char (point-min))
9946 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9948 (defun org-agenda-remove-flag (marker)
9949 "Remove the FLAGGED tag and any flagging note in the entry."
9951 (org-with-point-at marker
9952 (org-toggle-tag "FLAGGED" 'off)
9953 (org-entry-delete nil "THEFLAGGINGNOTE")
9954 (setq newhead (org-get-heading)))
9955 (org-agenda-change-all-lines newhead marker)
9956 (message "Entry unflagged")))
9958 (defun org-agenda-get-any-marker (&optional pos)
9959 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9960 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9962 ;;; Appointment reminders
9964 (defvar appt-time-msg-list) ; defined in appt.el
9967 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9968 "Activate appointments found in `org-agenda-files'.
9969 With a \\[universal-argument] prefix, refresh the list of
9972 If FILTER is t, interactively prompt the user for a regular
9973 expression, and filter out entries that don't match it.
9975 If FILTER is a string, use this string as a regular expression
9976 for filtering entries out.
9978 If FILTER is a function, filter out entries against which
9979 calling the function returns nil. This function takes one
9980 argument: an entry from `org-agenda-get-day-entries'.
9982 FILTER can also be an alist with the car of each cell being
9983 either 'headline or 'category. For example:
9985 '((headline \"IMPORTANT\")
9986 (category \"Work\"))
9988 will only add headlines containing IMPORTANT or headlines
9989 belonging to the \"Work\" category.
9991 ARGS are symbols indicating what kind of entries to consider.
9992 By default `org-agenda-to-appt' will use :deadline*, :scheduled*
9993 \(i.e., deadlines and scheduled items with a hh:mm specification)
9994 and :timestamp entries. See the docstring of `org-diary' for
9995 details and examples.
9997 If an entry has a APPT_WARNTIME property, its value will be used
9998 to override `appt-message-warning-time'."
10000 (if refresh (setq appt-time-msg-list nil))
10002 (setq filter (read-from-minibuffer "Regexp filter: ")))
10003 (let* ((cnt 0) ; count added events
10004 (scope (or args '(:deadline* :scheduled* :timestamp)))
10005 (org-agenda-new-buffers nil)
10006 (org-deadline-warning-days 0)
10007 ;; Do not use `org-today' here because appt only takes
10008 ;; time and without date as argument, so it may pass wrong
10009 ;; information otherwise
10010 (today (org-date-to-gregorian
10011 (time-to-days (current-time))))
10012 (org-agenda-restrict nil)
10013 (files (org-agenda-files 'unrestricted)) entries file
10014 (org-agenda-buffer nil))
10015 ;; Get all entries which may contain an appt
10016 (org-agenda-prepare-buffers files)
10017 (while (setq file (pop files))
10021 (apply 'org-agenda-get-day-entries
10022 file today scope)))))
10023 ;; Map thru entries and find if we should filter them out
10026 (let* ((evt (org-trim
10027 (replace-regexp-in-string
10028 org-bracket-link-regexp "\\3"
10029 (or (get-text-property 1 'txt x) ""))))
10030 (cat (get-text-property 1 'org-category x))
10031 (tod (get-text-property 1 'time-of-day x))
10032 (ok (or (null filter)
10033 (and (stringp filter) (string-match filter evt))
10034 (and (functionp filter) (funcall filter x))
10035 (and (listp filter)
10036 (let ((cat-filter (cadr (assoc 'category filter)))
10037 (evt-filter (cadr (assoc 'headline filter))))
10038 (or (and (stringp cat-filter)
10039 (string-match cat-filter cat))
10040 (and (stringp evt-filter)
10041 (string-match evt-filter evt)))))))
10042 (wrn (get-text-property 1 'warntime x)))
10043 ;; FIXME: Shall we remove text-properties for the appt text?
10044 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
10046 (setq tod (concat "00" (number-to-string tod))
10047 tod (when (string-match
10048 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
10049 (concat (match-string 1 tod) ":"
10050 (match-string 2 tod))))
10051 (if (version< emacs-version "23.3")
10053 (appt-add tod evt wrn))
10054 (setq cnt (1+ cnt))))) entries)
10055 (org-release-buffers org-agenda-new-buffers)
10057 (message "No event to add")
10058 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
10060 (defun org-agenda-todayp (date)
10061 "Does DATE mean today, when considering `org-extend-today-until'?"
10062 (let ((today (org-today))
10063 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
10067 (defun org-agenda-todo-yesterday (&optional arg)
10068 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
10070 (let* ((hour (third (decode-time
10071 (org-current-time))))
10072 (org-extend-today-until (1+ hour)))
10073 (org-agenda-todo arg)))
10075 (provide 'org-agenda)
10077 ;;; org-agenda.el ends here