1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2014 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-columns-remove-overlays
"org-colview" ())
73 (declare-function org-datetree-find-date-create
"org-datetree"
74 (date &optional keep-restriction
))
75 (declare-function org-columns-quit
"org-colview" ())
76 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
77 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
78 (declare-function org-habit-insert-consistency-graphs
79 "org-habit" (&optional line
))
80 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
81 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
82 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
83 (declare-function org-pop-to-buffer-same-window
"org-compat"
84 (&optional buffer-or-name norecord label
))
85 (declare-function org-agenda-columns
"org-colview" ())
86 (declare-function org-add-archive-files
"org-archive" (files))
87 (declare-function org-capture
"org-capture" (&optional goto keys
))
89 (defvar calendar-mode-map
) ; defined in calendar.el
90 (defvar org-clock-current-task nil
) ; defined in org-clock.el
91 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
92 (defvar org-habit-show-habits
) ; defined in org-habit.el
93 (defvar org-habit-show-habits-only-for-today
)
94 (defvar org-habit-show-all-today
)
96 ;; Defined somewhere in this file, but used before definition.
97 (defvar org-agenda-buffer-name
"*Org Agenda*")
98 (defvar org-agenda-overriding-header nil
)
99 (defvar org-agenda-title-append nil
)
100 (org-no-warnings (defvar entry
)) ;; unprefixed, from calendar.el
101 (org-no-warnings (defvar date
)) ;; unprefixed, from calendar.el
102 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
104 (defvar org-agenda-undo-list nil
105 "List of undoable operations in the agenda since last refresh.")
106 (defvar org-agenda-pending-undo-list nil
107 "In a series of undo commands, this is the list of remaining undo items.")
109 (defcustom org-agenda-confirm-kill
1
110 "When set, remote killing from the agenda buffer needs confirmation.
111 When t, a confirmation is always needed. When a number N, confirmation is
112 only needed when the text to be killed contains more than N non-white lines."
115 (const :tag
"Never" nil
)
116 (const :tag
"Always" t
)
117 (integer :tag
"When more than N lines")))
119 (defcustom org-agenda-compact-blocks nil
120 "Non-nil means make the block agenda more compact.
121 This is done globally by leaving out lines like the agenda span
122 name and week number or the separator lines."
126 (defcustom org-agenda-block-separator ?
=
127 "The separator between blocks in the agenda.
128 If this is a string, it will be used as the separator, with a newline added.
129 If it is a character, it will be repeated to fill the window width.
130 If nil the separator is disabled. In `org-agenda-custom-commands' this
131 addresses the separator between the current and the previous block."
134 (const :tag
"Disabled" nil
)
138 (defgroup org-agenda-export nil
139 "Options concerning exporting agenda views in Org-mode."
140 :tag
"Org Agenda Export"
143 (defcustom org-agenda-with-colors t
144 "Non-nil means use colors in agenda views."
145 :group
'org-agenda-export
148 (defcustom org-agenda-exporter-settings nil
149 "Alist of variable/value pairs that should be active during agenda export.
150 This is a good place to set options for ps-print and for htmlize.
151 Note that the way this is implemented, the values will be evaluated
152 before assigned to the variables. So make sure to quote values you do
153 *not* want evaluated, for example
155 (setq org-agenda-exporter-settings
156 '((ps-print-color-p 'black-white)))"
157 :group
'org-agenda-export
161 (sexp :tag
"Value"))))
163 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
164 "Hook run in a temporary buffer before writing the agenda to an export file.
165 A useful function for this hook is `org-agenda-add-entry-text'."
166 :group
'org-agenda-export
168 :options
'(org-agenda-add-entry-text))
170 (defcustom org-agenda-add-entry-text-maxlines
0
171 "Maximum number of entry text lines to be added to agenda.
172 This is only relevant when `org-agenda-add-entry-text' is part of
173 `org-agenda-before-write-hook', which is the default.
174 When this is 0, nothing will happen. When it is greater than 0, it
175 specifies the maximum number of lines that will be added for each entry
176 that is listed in the agenda view.
178 Note that this variable is not used during display, only when exporting
179 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
180 and `org-agenda-entry-text-maxlines'."
184 (defcustom org-agenda-add-entry-text-descriptive-links t
185 "Non-nil means export org-links as descriptive links in agenda added text.
186 This variable applies to the text added to the agenda when
187 `org-agenda-add-entry-text-maxlines' is larger than 0.
188 When this variable nil, the URL will (also) be shown."
192 (defcustom org-agenda-export-html-style nil
193 "The style specification for exported HTML Agenda files.
194 If this variable contains a string, it will replace the default <style>
195 section as produced by `htmlize'.
196 Since there are different ways of setting style information, this variable
197 needs to contain the full HTML structure to provide a style, including the
198 surrounding HTML tags. The style specifications should include definitions
199 the fonts used by the agenda, here is an example:
201 <style type=\"text/css\">
202 p { font-weight: normal; color: gray; }
203 .org-agenda-structure {
218 .title { text-align: center; }
219 .todo, .deadline { color: red; }
220 .done { color: green; }
223 or, if you want to keep the style in a file,
225 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
227 As the value of this option simply gets inserted into the HTML <head> header,
228 you can \"misuse\" it to also add other text to the header."
229 :group
'org-agenda-export
230 :group
'org-export-html
235 (defcustom org-agenda-persistent-filter nil
236 "When set, keep filters from one agenda view to the next."
240 (defgroup org-agenda-custom-commands nil
241 "Options concerning agenda views in Org-mode."
242 :tag
"Org Agenda Custom Commands"
245 (defconst org-sorting-choice
247 (const time-up
) (const time-down
)
248 (const timestamp-up
) (const timestamp-down
)
249 (const scheduled-up
) (const scheduled-down
)
250 (const deadline-up
) (const deadline-down
)
251 (const ts-up
) (const ts-down
)
252 (const tsia-up
) (const tsia-down
)
253 (const category-keep
) (const category-up
) (const category-down
)
254 (const tag-down
) (const tag-up
)
255 (const priority-up
) (const priority-down
)
256 (const todo-state-up
) (const todo-state-down
)
257 (const effort-up
) (const effort-down
)
258 (const habit-up
) (const habit-down
)
259 (const alpha-up
) (const alpha-down
)
260 (const user-defined-up
) (const user-defined-down
))
263 ;; Keep custom values for `org-agenda-filter-preset' compatible with
264 ;; the new variable `org-agenda-tag-filter-preset'.
265 (org-defvaralias 'org-agenda-filter-preset
'org-agenda-tag-filter-preset
)
266 (org-defvaralias 'org-agenda-filter
'org-agenda-tag-filter
)
268 (defvar org-agenda-entry-types
'(:deadline
:scheduled
:timestamp
:sexp
)
269 "List of types searched for when creating the daily/weekly agenda.
270 This variable is a list of symbols that controls the types of
271 items that appear in the daily/weekly agenda. Allowed symbols in this
274 :timestamp List items containing a date stamp or date range matching
275 the selected date. This includes sexp entries in angular
278 :sexp List entries resulting from plain diary-like sexps.
280 :deadline List deadline due on that date. When the date is today,
281 also list any deadlines past due, or due within
282 `org-deadline-warning-days'. `:deadline' must appear before
283 `:scheduled' if the setting of
284 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
287 :deadline* Same as above, but only include the deadline if it has an
288 hour specification as [h]h:mm.
290 :scheduled List all items which are scheduled for the given date.
291 The diary for *today* also contains items which were
292 scheduled earlier and are not yet marked DONE.
294 :scheduled* Same as above, but only include the scheduled item if it
295 has an hour specification as [h]h:mm.
297 By default, all four non-starred types are turned on.
299 When :scheduled* or :deadline* are included, :schedule or :deadline
302 Never set this variable globally using `setq', because then it
303 will apply to all future agenda commands. Instead, bind it with
304 `let' to scope it dynamically into the agenda-constructing
305 command. A good way to set it is through options in
306 `org-agenda-custom-commands'. For a more flexible (though
307 somewhat less efficient) way of determining what is included in
308 the daily/weekly agenda, see `org-agenda-skip-function'.")
310 (defconst org-agenda-custom-commands-local-options
311 `(repeat :tag
"Local settings for this command. Remember to quote values"
312 (choice :tag
"Setting"
313 (list :tag
"Heading for this block"
314 (const org-agenda-overriding-header
)
315 (string :tag
"Headline"))
316 (list :tag
"Files to be searched"
317 (const org-agenda-files
)
319 (const :format
"" quote
)
321 (list :tag
"Sorting strategy"
322 (const org-agenda-sorting-strategy
)
324 (const :format
"" quote
)
326 ,org-sorting-choice
)))
327 (list :tag
"Prefix format"
328 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
330 (list :tag
"Number of days in agenda"
331 (const org-agenda-span
)
332 (choice (const :tag
"Day" day
)
333 (const :tag
"Week" week
)
334 (const :tag
"Fortnight" fortnight
)
335 (const :tag
"Month" month
)
336 (const :tag
"Year" year
)
337 (integer :tag
"Custom")))
338 (list :tag
"Fixed starting date"
339 (const org-agenda-start-day
)
340 (string :value
"2007-11-01"))
341 (list :tag
"Start on day of week"
342 (const org-agenda-start-on-weekday
)
344 (const :tag
"Today" nil
)
345 (integer :tag
"Weekday No.")))
346 (list :tag
"Include data from diary"
347 (const org-agenda-include-diary
)
349 (list :tag
"Deadline Warning days"
350 (const org-deadline-warning-days
)
352 (list :tag
"Category filter preset"
353 (const org-agenda-category-filter-preset
)
355 (const :format
"" quote
)
357 (string :tag
"+category or -category"))))
358 (list :tag
"Tags filter preset"
359 (const org-agenda-tag-filter-preset
)
361 (const :format
"" quote
)
363 (string :tag
"+tag or -tag"))))
364 (list :tag
"Effort filter preset"
365 (const org-agenda-effort-filter-preset
)
367 (const :format
"" quote
)
369 (string :tag
"+=10 or -=10 or +<10 or ->10"))))
370 (list :tag
"Regexp filter preset"
371 (const org-agenda-regexp-filter-preset
)
373 (const :format
"" quote
)
375 (string :tag
"+regexp or -regexp"))))
376 (list :tag
"Set daily/weekly entry types"
377 (const org-agenda-entry-types
)
379 (const :format
"" quote
)
380 (set :greedy t
:value
,org-agenda-entry-types
387 (list :tag
"Standard skipping condition"
388 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
389 (const org-agenda-skip-function
)
391 (const :format
"" quote
)
394 :tag
"Skipping range"
395 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
396 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
397 (repeat :inline t
:tag
"Conditions for skipping"
399 :tag
"Condition type"
400 (list :tag
"Regexp matches" :inline t
401 (const :format
"" 'regexp
)
403 (list :tag
"Regexp does not match" :inline t
404 (const :format
"" 'notregexp
)
406 (list :tag
"TODO state is" :inline t
409 (const :tag
"Any not-done state" 'todo
)
410 (const :tag
"Any done state" 'done
)
411 (const :tag
"Any state" 'any
)
412 (list :tag
"Keyword list"
413 (const :format
"" quote
)
414 (repeat (string :tag
"Keyword")))))
415 (list :tag
"TODO state is not" :inline t
418 (const :tag
"Any not-done state" 'todo
)
419 (const :tag
"Any done state" 'done
)
420 (const :tag
"Any state" 'any
)
421 (list :tag
"Keyword list"
422 (const :format
"" quote
)
423 (repeat (string :tag
"Keyword")))))
424 (const :tag
"scheduled" 'scheduled
)
425 (const :tag
"not scheduled" 'notscheduled
)
426 (const :tag
"deadline" 'deadline
)
427 (const :tag
"no deadline" 'notdeadline
)
428 (const :tag
"timestamp" 'timestamp
)
429 (const :tag
"no timestamp" 'nottimestamp
))))))
430 (list :tag
"Non-standard skipping condition"
431 :value
(org-agenda-skip-function)
432 (const org-agenda-skip-function
)
433 (sexp :tag
"Function or form (quoted!)"))
434 (list :tag
"Any variable"
435 (variable :tag
"Variable")
436 (sexp :tag
"Value (sexp)"))))
437 "Selection of examples for agenda command settings.
438 This will be spliced into the custom type of
439 `org-agenda-custom-commands'.")
442 (defcustom org-agenda-custom-commands
443 '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
444 "Custom commands for the agenda.
445 These commands will be offered on the splash screen displayed by the
446 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
448 (key desc type match settings files)
450 key The key (one or more characters as a string) to be associated
452 desc A description of the command, when omitted or nil, a default
453 description is built using MATCH.
454 type The command type, any of the following symbols:
455 agenda The daily/weekly agenda.
456 todo Entries with a specific TODO keyword, in all agenda files.
457 search Entries containing search words entry or headline.
458 tags Tags/Property/TODO match in all agenda files.
459 tags-todo Tags/P/T match in all agenda files, TODO entries only.
460 todo-tree Sparse tree of specific TODO keyword in *current* file.
461 tags-tree Sparse tree with all tags matches in *current* file.
462 occur-tree Occur sparse tree for *current* file.
463 ... A user-defined function.
464 match What to search for:
465 - a single keyword for TODO keyword searches
466 - a tags match expression for tags searches
467 - a word search expression for text searches.
468 - a regular expression for occur searches
469 For all other commands, this should be the empty string.
470 settings A list of option settings, similar to that in a let form, so like
471 this: ((opt1 val1) (opt2 val2) ...). The values will be
472 evaluated at the moment of execution, so quote them when needed.
473 files A list of files file to write the produced agenda buffer to
474 with the command `org-store-agenda-views'.
475 If a file name ends in \".html\", an HTML version of the buffer
476 is written out. If it ends in \".ps\", a postscript version is
477 produced. Otherwise, only the plain text is written to the file.
479 You can also define a set of commands, to create a composite agenda buffer.
480 In this case, an entry looks like this:
482 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
486 desc A description string to be displayed in the dispatcher menu.
487 cmd An agenda command, similar to the above. However, tree commands
488 are not allowed, but instead you can get agenda and global todo list.
489 So valid commands for a set are:
490 (agenda \"\" settings)
491 (alltodo \"\" settings)
492 (stuck \"\" settings)
493 (todo \"match\" settings files)
494 (search \"match\" settings files)
495 (tags \"match\" settings files)
496 (tags-todo \"match\" settings files)
498 Each command can carry a list of options, and another set of options can be
499 given for the whole set of commands. Individual command options take
500 precedence over the general options.
502 When using several characters as key to a command, the first characters
503 are prefix commands. For the dispatcher to display useful information, you
504 should provide a description for the prefix, like
506 (setq org-agenda-custom-commands
507 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
508 (\"hl\" tags \"+HOME+Lisa\")
509 (\"hp\" tags \"+HOME+Peter\")
510 (\"hk\" tags \"+HOME+Kim\")))"
511 :group
'org-agenda-custom-commands
513 (choice :value
("x" "Describe command here" tags
"" nil
)
514 (list :tag
"Single command"
515 (string :tag
"Access Key(s) ")
516 (option (string :tag
"Description"))
518 (const :tag
"Agenda" agenda
)
519 (const :tag
"TODO list" alltodo
)
520 (const :tag
"Search words" search
)
521 (const :tag
"Stuck projects" stuck
)
522 (const :tag
"Tags/Property match (all agenda files)" tags
)
523 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
524 (const :tag
"TODO keyword search (all agenda files)" todo
)
525 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
526 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
527 (const :tag
"Occur tree (current buffer)" occur-tree
)
528 (sexp :tag
"Other, user-defined function"))
529 (string :tag
"Match (only for some commands)")
530 ,org-agenda-custom-commands-local-options
531 (option (repeat :tag
"Export" (file :tag
"Export to"))))
532 (list :tag
"Command series, all agenda files"
533 (string :tag
"Access Key(s)")
534 (string :tag
"Description ")
535 (repeat :tag
"Component"
538 (const :format
"" agenda
)
539 (const :tag
"" :format
"" "")
540 ,org-agenda-custom-commands-local-options
)
541 (list :tag
"TODO list (all keywords)"
542 (const :format
"" alltodo
)
543 (const :tag
"" :format
"" "")
544 ,org-agenda-custom-commands-local-options
)
545 (list :tag
"Search words"
546 (const :format
"" search
)
547 (string :tag
"Match")
548 ,org-agenda-custom-commands-local-options
)
549 (list :tag
"Stuck projects"
550 (const :format
"" stuck
)
551 (const :tag
"" :format
"" "")
552 ,org-agenda-custom-commands-local-options
)
553 (list :tag
"Tags search"
554 (const :format
"" tags
)
555 (string :tag
"Match")
556 ,org-agenda-custom-commands-local-options
)
557 (list :tag
"Tags search, TODO entries only"
558 (const :format
"" tags-todo
)
559 (string :tag
"Match")
560 ,org-agenda-custom-commands-local-options
)
561 (list :tag
"TODO keyword search"
562 (const :format
"" todo
)
563 (string :tag
"Match")
564 ,org-agenda-custom-commands-local-options
)
565 (list :tag
"Other, user-defined function"
566 (symbol :tag
"function")
567 (string :tag
"Match")
568 ,org-agenda-custom-commands-local-options
)))
570 (repeat :tag
"Settings for entire command set"
571 (list (variable :tag
"Any variable")
572 (sexp :tag
"Value")))
573 (option (repeat :tag
"Export" (file :tag
"Export to"))))
574 (cons :tag
"Prefix key documentation"
575 (string :tag
"Access Key(s)")
576 (string :tag
"Description ")))))
578 (defcustom org-agenda-query-register ?o
579 "The register holding the current query string.
580 The purpose of this is that if you construct a query string interactively,
581 you can then use it to define a custom command."
582 :group
'org-agenda-custom-commands
585 (defcustom org-stuck-projects
586 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
587 "How to identify stuck projects.
588 This is a list of four items:
589 1. A tags/todo/property matcher string that is used to identify a project.
590 See the manual for a description of tag and property searches.
591 The entire tree below a headline matched by this is considered one project.
592 2. A list of TODO keywords identifying non-stuck projects.
593 If the project subtree contains any headline with one of these todo
594 keywords, the project is considered to be not stuck. If you specify
595 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
596 3. A list of tags identifying non-stuck projects.
597 If the project subtree contains any headline with one of these tags,
598 the project is considered to be not stuck. If you specify \"*\" as
599 a tag, any tag will mark the project unstuck. Note that this is about
600 the explicit presence of a tag somewhere in the subtree, inherited
601 tags do not count here. If inherited tags make a project not stuck,
602 use \"-TAG\" in the tags part of the matcher under (1.) above.
603 4. An arbitrary regular expression matching non-stuck projects.
605 If the project turns out to be not stuck, search continues also in the
606 subtree to see if any of the subtasks have project status.
608 See also the variable `org-tags-match-list-sublevels' which applies
609 to projects matched by this search as well.
611 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
612 or `C-c a #' to produce the list."
613 :group
'org-agenda-custom-commands
615 (string :tag
"Tags/TODO match to identify a project")
616 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
617 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
618 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
620 (defgroup org-agenda-skip nil
621 "Options concerning skipping parts of agenda files."
622 :tag
"Org Agenda Skip"
625 (defcustom org-agenda-skip-function-global nil
626 "Function to be called at each match during agenda construction.
627 If this function returns nil, the current match should not be skipped.
628 If the function decided to skip an agenda match, is must return the
629 buffer position from which the search should be continued.
630 This may also be a Lisp form, which will be evaluated.
632 This variable will be applied to every agenda match, including
633 tags/property searches and TODO lists. So try to make the test function
634 do its checking as efficiently as possible. To implement a skipping
635 condition just for specific agenda commands, use the variable
636 `org-agenda-skip-function' which can be set in the options section
637 of custom agenda commands."
638 :group
'org-agenda-skip
641 (defgroup org-agenda-daily
/weekly nil
642 "Options concerning the daily/weekly agenda."
643 :tag
"Org Agenda Daily/Weekly"
645 (defgroup org-agenda-todo-list nil
646 "Options concerning the global todo list agenda view."
647 :tag
"Org Agenda Todo List"
649 (defgroup org-agenda-match-view nil
650 "Options concerning the general tags/property/todo match agenda view."
651 :tag
"Org Agenda Match View"
653 (defgroup org-agenda-search-view nil
654 "Options concerning the search agenda view."
655 :tag
"Org Agenda Search View"
658 (defvar org-agenda-archives-mode nil
659 "Non-nil means the agenda will include archived items.
660 If this is the symbol `trees', trees in the selected agenda scope
661 that are marked with the ARCHIVE tag will be included anyway. When this is
662 t, also all archive files associated with the current selection of agenda
663 files will be included.")
665 (defcustom org-agenda-restriction-lock-highlight-subtree t
666 "Non-nil means highlight the whole subtree when restriction is active.
667 Otherwise only highlight the headline. Highlighting the whole subtree is
668 useful to ensure no edits happen beyond the restricted region."
672 (defcustom org-agenda-skip-comment-trees t
673 "Non-nil means skip trees that start with the COMMENT keyword.
674 When nil, these trees are also scanned by agenda commands."
675 :group
'org-agenda-skip
678 (defcustom org-agenda-todo-list-sublevels t
679 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
680 When nil, the sublevels of a TODO entry are not checked, resulting in
681 potentially much shorter TODO lists."
682 :group
'org-agenda-skip
683 :group
'org-agenda-todo-list
686 (defcustom org-agenda-todo-ignore-with-date nil
687 "Non-nil means don't show entries with a date in the global todo list.
688 You can use this if you prefer to mark mere appointments with a TODO keyword,
689 but don't want them to show up in the TODO list.
690 When this is set, it also covers deadlines and scheduled items, the settings
691 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
693 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
694 :group
'org-agenda-skip
695 :group
'org-agenda-todo-list
698 (defcustom org-agenda-todo-ignore-timestamp nil
699 "Non-nil means don't show entries with a timestamp.
700 This applies when creating the global todo list.
703 past Don't show entries for today or in the past.
705 future Don't show entries with a timestamp in the future.
706 The idea behind this is that if it has a future
707 timestamp, you don't want to think about it until the
710 all Don't show any entries with a timestamp in the global todo list.
711 The idea behind this is that by setting a timestamp, you
712 have already \"taken care\" of this item.
714 This variable can also have an integer as a value. If positive (N),
715 todos with a timestamp N or more days in the future will be ignored. If
716 negative (-N), todos with a timestamp N or more days in the past will be
717 ignored. If 0, todos with a timestamp either today or in the future will
718 be ignored. For example, a value of -1 will exclude todos with a
719 timestamp in the past (yesterday or earlier), while a value of 7 will
720 exclude todos with a timestamp a week or more in the future.
722 See also `org-agenda-todo-ignore-with-date'.
723 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
724 to make his option also apply to the tags-todo list."
725 :group
'org-agenda-skip
726 :group
'org-agenda-todo-list
729 (const :tag
"Ignore future timestamp todos" future
)
730 (const :tag
"Ignore past or present timestamp todos" past
)
731 (const :tag
"Ignore all timestamp todos" all
)
732 (const :tag
"Show timestamp todos" nil
)
733 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
735 (defcustom org-agenda-todo-ignore-scheduled nil
736 "Non-nil means, ignore some scheduled TODO items when making TODO list.
737 This applies when creating the global todo list.
740 past Don't show entries scheduled today or in the past.
742 future Don't show entries scheduled in the future.
743 The idea behind this is that by scheduling it, you don't want to
744 think about it until the scheduled date.
746 all Don't show any scheduled entries in the global todo list.
747 The idea behind this is that by scheduling it, you have already
748 \"taken care\" of this item.
750 t Same as `all', for backward compatibility.
752 This variable can also have an integer as a value. See
753 `org-agenda-todo-ignore-timestamp' for more details.
755 See also `org-agenda-todo-ignore-with-date'.
756 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
757 to make his option also apply to the tags-todo list."
758 :group
'org-agenda-skip
759 :group
'org-agenda-todo-list
761 (const :tag
"Ignore future-scheduled todos" future
)
762 (const :tag
"Ignore past- or present-scheduled todos" past
)
763 (const :tag
"Ignore all scheduled todos" all
)
764 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
765 (const :tag
"Show scheduled todos" nil
)
766 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
768 (defcustom org-agenda-todo-ignore-deadlines nil
769 "Non-nil means ignore some deadline TODO items when making TODO list.
770 There are different motivations for using different values, please think
771 carefully when configuring this variable.
773 This applies when creating the global todo list.
776 near Don't show near deadline entries. A deadline is near when it is
777 closer than `org-deadline-warning-days' days. The idea behind this
778 is that such items will appear in the agenda anyway.
780 far Don't show TODO entries where a deadline has been defined, but
781 the deadline is not near. This is useful if you don't want to
782 use the todo list to figure out what to do now.
784 past Don't show entries with a deadline timestamp for today or in the past.
786 future Don't show entries with a deadline timestamp in the future, not even
787 when they become `near' ones. Use it with caution.
789 all Ignore all TODO entries that do have a deadline.
791 t Same as `near', for backward compatibility.
793 This variable can also have an integer as a value. See
794 `org-agenda-todo-ignore-timestamp' for more details.
796 See also `org-agenda-todo-ignore-with-date'.
797 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
798 to make his option also apply to the tags-todo list."
799 :group
'org-agenda-skip
800 :group
'org-agenda-todo-list
802 (const :tag
"Ignore near deadlines" near
)
803 (const :tag
"Ignore near deadlines (compatibility)" t
)
804 (const :tag
"Ignore far deadlines" far
)
805 (const :tag
"Ignore all TODOs with a deadlines" all
)
806 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
807 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
809 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
810 "Time unit to use when possibly ignoring an agenda item.
812 See the docstring of various `org-agenda-todo-ignore-*' options.
813 The default is to compare time stamps using days. An item is thus
814 considered to be in the future if it is at least one day after today.
815 Non-nil means to compare time stamps using seconds. An item is then
816 considered future if it has a time value later than current time."
817 :group
'org-agenda-skip
818 :group
'org-agenda-todo-list
820 :package-version
'(Org .
"8.0")
822 (const :tag
"Compare time with days" nil
)
823 (const :tag
"Compare time with seconds" t
)))
825 (defcustom org-agenda-tags-todo-honor-ignore-options nil
826 "Non-nil means honor todo-list ignores options also in tags-todo search.
828 `org-agenda-todo-ignore-with-date',
829 `org-agenda-todo-ignore-timestamp',
830 `org-agenda-todo-ignore-scheduled',
831 `org-agenda-todo-ignore-deadlines'
832 make the global TODO list skip entries that have time stamps of certain
833 kinds. If this option is set, the same options will also apply for the
834 tags-todo search, which is the general tags/property matcher
835 restricted to unfinished TODO entries only."
836 :group
'org-agenda-skip
837 :group
'org-agenda-todo-list
838 :group
'org-agenda-match-view
841 (defcustom org-agenda-skip-scheduled-if-done nil
842 "Non-nil means don't show scheduled items in agenda when they are done.
843 This is relevant for the daily/weekly agenda, not for the TODO list. And
844 it applies only to the actual date of the scheduling. Warnings about
845 an item with a past scheduling dates are always turned off when the item
847 :group
'org-agenda-skip
848 :group
'org-agenda-daily
/weekly
851 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
852 "Non-nil means skip scheduling line if same entry shows because of deadline.
854 In the agenda of today, an entry can show up multiple times
855 because it is both scheduled and has a nearby deadline, and maybe
856 a plain time stamp as well.
858 When this variable is nil, the entry will be shown several times.
860 When set to t, then only the deadline is shown and the fact that
861 the entry is scheduled today or was scheduled previously is not
864 When set to the symbol `not-today', skip scheduled previously,
865 but not scheduled today.
867 When set to the symbol `repeated-after-deadline', skip scheduled
868 items if they are repeated beyond the current deadline."
869 :group
'org-agenda-skip
870 :group
'org-agenda-daily
/weekly
872 (const :tag
"Never" nil
)
873 (const :tag
"Always" t
)
874 (const :tag
"Not when scheduled today" not-today
)
875 (const :tag
"When repeated past deadline" repeated-after-deadline
)))
877 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
878 "Non-nil means skip timestamp line if same entry shows because of deadline.
879 In the agenda of today, an entry can show up multiple times
880 because it has both a plain timestamp and has a nearby deadline.
881 When this variable is t, then only the deadline is shown and the
882 fact that the entry has a timestamp for or including today is not
883 shown. When this variable is nil, the entry will be shown
885 :group
'org-agenda-skip
886 :group
'org-agenda-daily
/weekly
889 (const :tag
"Never" nil
)
890 (const :tag
"Always" t
)))
892 (defcustom org-agenda-skip-deadline-if-done nil
893 "Non-nil means don't show deadlines when the corresponding item is done.
894 When nil, the deadline is still shown and should give you a happy feeling.
895 This is relevant for the daily/weekly agenda. And it applied only to the
896 actually date of the deadline. Warnings about approaching and past-due
897 deadlines are always turned off when the item is DONE."
898 :group
'org-agenda-skip
899 :group
'org-agenda-daily
/weekly
902 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
903 "Non-nil means skip deadline prewarning when entry is also scheduled.
904 This will apply on all days where a prewarning for the deadline would
905 be shown, but not at the day when the entry is actually due. On that day,
906 the deadline will be shown anyway.
907 This variable may be set to nil, t, the symbol `pre-scheduled',
908 or a number which will then give the number of days before the actual
909 deadline when the prewarnings should resume. The symbol `pre-scheduled'
910 eliminates the deadline prewarning only prior to the scheduled date.
911 This can be used in a workflow where the first showing of the deadline will
912 trigger you to schedule it, and then you don't want to be reminded of it
913 because you will take care of it on the day when scheduled."
914 :group
'org-agenda-skip
915 :group
'org-agenda-daily
/weekly
918 (const :tag
"Always show prewarning" nil
)
919 (const :tag
"Remove prewarning prior to scheduled date" pre-scheduled
)
920 (const :tag
"Remove prewarning if entry is scheduled" t
)
921 (integer :tag
"Restart prewarning N days before deadline")))
923 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
924 "Non-nil means skip scheduled delay when entry also has a deadline.
925 This variable may be set to nil, t, the symbol `post-deadline',
926 or a number which will then give the number of days after the actual
927 scheduled date when the delay should expire. The symbol `post-deadline'
928 eliminates the schedule delay when the date is posterior to the deadline."
929 :group
'org-agenda-skip
930 :group
'org-agenda-daily
/weekly
932 :package-version
'(Org .
"8.0")
934 (const :tag
"Always honor delay" nil
)
935 (const :tag
"Ignore delay if posterior to the deadline" post-deadline
)
936 (const :tag
"Ignore delay if entry has a deadline" t
)
937 (integer :tag
"Honor delay up until N days after the scheduled date")))
939 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
940 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
941 When non-nil, after the search for timestamps has matched once in an
942 entry, the rest of the entry will not be searched."
943 :group
'org-agenda-skip
946 (defcustom org-agenda-skip-timestamp-if-done nil
947 "Non-nil means don't select item by timestamp or -range if it is DONE."
948 :group
'org-agenda-skip
949 :group
'org-agenda-daily
/weekly
952 (defcustom org-agenda-dim-blocked-tasks t
953 "Non-nil means dim blocked tasks in the agenda display.
954 This causes some overhead during agenda construction, but if you
955 have turned on `org-enforce-todo-dependencies',
956 `org-enforce-todo-checkbox-dependencies', or any other blocking
957 mechanism, this will create useful feedback in the agenda.
959 Instead of t, this variable can also have the value `invisible'.
960 Then blocked tasks will be invisible and only become visible when
961 they become unblocked. An exemption to this behavior is when a task is
962 blocked because of unchecked checkboxes below it. Since checkboxes do
963 not show up in the agenda views, making this task invisible you remove any
964 trace from agenda views that there is something to do. Therefore, a task
965 that is blocked because of checkboxes will never be made invisible, it
966 will only be dimmed."
967 :group
'org-agenda-daily
/weekly
968 :group
'org-agenda-todo-list
971 (const :tag
"Do not dim" nil
)
972 (const :tag
"Dim to a gray face" t
)
973 (const :tag
"Make invisible" invisible
)))
975 (defcustom org-timeline-show-empty-dates
3
976 "Non-nil means `org-timeline' also shows dates without an entry.
977 When nil, only the days which actually have entries are shown.
978 When t, all days between the first and the last date are shown.
979 When an integer, show also empty dates, but if there is a gap of more than
980 N days, just insert a special line indicating the size of the gap."
981 :group
'org-agenda-skip
983 (const :tag
"None" nil
)
985 (integer :tag
"at most")))
987 (defgroup org-agenda-startup nil
988 "Options concerning initial settings in the Agenda in Org Mode."
989 :tag
"Org Agenda Startup"
992 (defcustom org-agenda-menu-show-matcher t
993 "Non-nil means show the match string in the agenda dispatcher menu.
994 When nil, the matcher string is not shown, but is put into the help-echo
995 property so than moving the mouse over the command shows it.
996 Setting it to nil is good if matcher strings are very long and/or if
997 you want to use two-columns display (see `org-agenda-menu-two-columns')."
1002 (define-obsolete-variable-alias 'org-agenda-menu-two-column
'org-agenda-menu-two-columns
"24.3")
1004 (defcustom org-agenda-menu-two-columns nil
1005 "Non-nil means, use two columns to show custom commands in the dispatcher.
1006 If you use this, you probably want to set `org-agenda-menu-show-matcher'
1012 (define-obsolete-variable-alias 'org-finalize-agenda-hook
'org-agenda-finalize-hook
"24.3")
1013 (defcustom org-agenda-finalize-hook nil
1014 "Hook run just before displaying an agenda buffer.
1015 The buffer is still writable when the hook is called.
1017 You can modify some of the buffer substrings but you should be
1018 extra careful not to modify the text properties of the agenda
1019 headlines as the agenda display heavily relies on them."
1020 :group
'org-agenda-startup
1023 (defcustom org-agenda-mouse-1-follows-link nil
1024 "Non-nil means mouse-1 on a link will follow the link in the agenda.
1025 A longer mouse click will still set point. Does not work on XEmacs.
1026 Needs to be set before org.el is loaded."
1027 :group
'org-agenda-startup
1030 (defcustom org-agenda-start-with-follow-mode nil
1031 "The initial value of follow mode in a newly created agenda window."
1032 :group
'org-agenda-startup
1035 (defcustom org-agenda-follow-indirect nil
1036 "Non-nil means `org-agenda-follow-mode' displays only the
1037 current item's tree, in an indirect buffer."
1042 (defcustom org-agenda-show-outline-path t
1043 "Non-nil means show outline path in echo area after line motion."
1044 :group
'org-agenda-startup
1047 (defcustom org-agenda-start-with-entry-text-mode nil
1048 "The initial value of entry-text-mode in a newly created agenda window."
1049 :group
'org-agenda-startup
1052 (defcustom org-agenda-entry-text-maxlines
5
1053 "Number of text lines to be added when `E' is pressed in the agenda.
1055 Note that this variable only used during agenda display. Add add entry text
1056 when exporting the agenda, configure the variable
1057 `org-agenda-add-entry-ext-maxlines'."
1061 (defcustom org-agenda-entry-text-exclude-regexps nil
1062 "List of regular expressions to clean up entry text.
1063 The complete matches of all regular expressions in this list will be
1064 removed from entry text before it is shown in the agenda."
1066 :type
'(repeat (regexp)))
1068 (defcustom org-agenda-entry-text-leaders
" > "
1069 "Text prepended to the entry text in agenda buffers."
1071 :package-version
'(Org .
"8.0")
1075 (defvar org-agenda-entry-text-cleanup-hook nil
1076 "Hook that is run after basic cleanup of entry text to be shown in agenda.
1077 This cleanup is done in a temporary buffer, so the function may inspect and
1078 change the entire buffer.
1079 Some default stuff like drawers and scheduling/deadline dates will already
1080 have been removed when this is called, as will any matches for regular
1081 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
1083 (defvar org-agenda-include-inactive-timestamps nil
1084 "Non-nil means include inactive time stamps in agenda and timeline.
1085 Dynamically scoped.")
1087 (defgroup org-agenda-windows nil
1088 "Options concerning the windows used by the Agenda in Org Mode."
1089 :tag
"Org Agenda Windows"
1092 (defcustom org-agenda-window-setup
'reorganize-frame
1093 "How the agenda buffer should be displayed.
1094 Possible values for this option are:
1096 current-window Show agenda in the current window, keeping all other windows.
1097 other-window Use `switch-to-buffer-other-window' to display agenda.
1098 reorganize-frame Show only two windows on the current frame, the current
1099 window and the agenda.
1100 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1101 Also, when exiting the agenda, kill that frame.
1102 See also the variable `org-agenda-restore-windows-after-quit'."
1103 :group
'org-agenda-windows
1105 (const current-window
)
1107 (const other-window
)
1108 (const reorganize-frame
)))
1110 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
1111 "The min and max height of the agenda window as a fraction of frame height.
1112 The value of the variable is a cons cell with two numbers between 0 and 1.
1113 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1114 :group
'org-agenda-windows
1115 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
1117 (defcustom org-agenda-restore-windows-after-quit nil
1118 "Non-nil means restore window configuration upon exiting agenda.
1119 Before the window configuration is changed for displaying the agenda,
1120 the current status is recorded. When the agenda is exited with
1121 `q' or `x' and this option is set, the old state is restored. If
1122 `org-agenda-window-setup' is `other-frame', the value of this
1123 option will be ignored."
1124 :group
'org-agenda-windows
1127 (defcustom org-agenda-ndays nil
1128 "Number of days to include in overview display.
1130 Obsolete, see `org-agenda-span'."
1131 :group
'org-agenda-daily
/weekly
1132 :type
'(choice (const nil
)
1135 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
1137 (defcustom org-agenda-span
'week
1138 "Number of days to include in overview display.
1139 Can be day, week, month, year, or any number of days.
1140 Custom commands can set this variable in the options section."
1141 :group
'org-agenda-daily
/weekly
1142 :type
'(choice (const :tag
"Day" day
)
1143 (const :tag
"Week" week
)
1144 (const :tag
"Fortnight" fortnight
)
1145 (const :tag
"Month" month
)
1146 (const :tag
"Year" year
)
1147 (integer :tag
"Custom")))
1149 (defcustom org-agenda-start-on-weekday
1
1150 "Non-nil means start the overview always on the specified weekday.
1151 0 denotes Sunday, 1 denotes Monday, etc.
1152 When nil, always start on the current day.
1153 Custom commands can set this variable in the options section."
1154 :group
'org-agenda-daily
/weekly
1155 :type
'(choice (const :tag
"Today" nil
)
1156 (integer :tag
"Weekday No.")))
1158 (defcustom org-agenda-show-all-dates t
1159 "Non-nil means `org-agenda' shows every day in the selected range.
1160 When nil, only the days which actually have entries are shown."
1161 :group
'org-agenda-daily
/weekly
1164 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1165 "Format string for displaying dates in the agenda.
1166 Used by the daily/weekly agenda and by the timeline. This should be
1167 a format string understood by `format-time-string', or a function returning
1168 the formatted date as a string. The function must take a single argument,
1169 a calendar-style date list like (month day year)."
1170 :group
'org-agenda-daily
/weekly
1172 (string :tag
"Format string")
1173 (function :tag
"Function")))
1175 (defun org-agenda-format-date-aligned (date)
1176 "Format a DATE string for display in the daily/weekly agenda, or timeline.
1177 This function makes sure that dates are aligned for easy reading."
1179 (let* ((dayname (calendar-day-name date
))
1181 (day-of-week (calendar-day-of-week date
))
1183 (monthname (calendar-month-name month
))
1185 (iso-week (org-days-to-iso-week
1186 (calendar-absolute-from-gregorian date
)))
1187 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1189 ((and (= month
12) (<= iso-week
1))
1192 (weekstring (if (= day-of-week
1)
1193 (format " W%02d" iso-week
)
1195 (format "%-10s %2d %s %4d%s"
1196 dayname day monthname year weekstring
)))
1198 (defcustom org-agenda-time-leading-zero nil
1199 "Non-nil means use leading zero for military times in agenda.
1200 For example, 9:30am would become 09:30 rather than 9:30."
1201 :group
'org-agenda-daily
/weekly
1205 (defcustom org-agenda-timegrid-use-ampm nil
1206 "When set, show AM/PM style timestamps on the timegrid."
1211 (defun org-agenda-time-of-day-to-ampm (time)
1212 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1213 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1214 (minute (substring time -
2))
1217 ((equal hour-number
12)
1221 (setq hour-number
(- hour-number
12))))
1223 (if org-agenda-time-leading-zero
1224 (format "%02d" hour-number
)
1225 (format "%02s" (number-to-string hour-number
)))
1228 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1229 "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
1230 (if org-agenda-timegrid-use-ampm
1231 (org-agenda-time-of-day-to-ampm time
)
1234 (defcustom org-agenda-weekend-days
'(6 0)
1235 "Which days are weekend?
1236 These days get the special face `org-agenda-date-weekend' in the agenda
1237 and timeline buffers."
1238 :group
'org-agenda-daily
/weekly
1239 :type
'(set :greedy t
1240 (const :tag
"Monday" 1)
1241 (const :tag
"Tuesday" 2)
1242 (const :tag
"Wednesday" 3)
1243 (const :tag
"Thursday" 4)
1244 (const :tag
"Friday" 5)
1245 (const :tag
"Saturday" 6)
1246 (const :tag
"Sunday" 0)))
1248 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1249 "Non-nil means jump to today when moving a past date forward in time.
1250 When using S-right in the agenda to move a a date forward, and the date
1251 stamp currently points to the past, the first key press will move it
1252 to today. WHen nil, just move one day forward even if the date stays
1254 :group
'org-agenda-daily
/weekly
1258 (defcustom org-agenda-include-diary nil
1259 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1260 Custom commands can set this variable in the options section."
1261 :group
'org-agenda-daily
/weekly
1264 (defcustom org-agenda-include-deadlines t
1265 "If non-nil, include entries within their deadline warning period.
1266 Custom commands can set this variable in the options section."
1267 :group
'org-agenda-daily
/weekly
1271 (defcustom org-agenda-repeating-timestamp-show-all t
1272 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1273 When set to a list of strings, only show occurrences of repeating
1274 stamps for these TODO keywords. When nil, only one occurrence is
1275 shown, either today or the nearest into the future."
1276 :group
'org-agenda-daily
/weekly
1278 (const :tag
"Show repeating stamps" t
)
1279 (repeat :tag
"Show repeating stamps for these TODO keywords"
1280 (string :tag
"TODO Keyword"))
1281 (const :tag
"Don't show repeating stamps" nil
)))
1283 (defcustom org-scheduled-past-days
10000
1284 "Number of days to continue listing scheduled items not marked DONE.
1285 When an item is scheduled on a date, it shows up in the agenda on this
1286 day and will be listed until it is marked done for the number of days
1288 :group
'org-agenda-daily
/weekly
1291 (defcustom org-agenda-log-mode-items
'(closed clock
)
1292 "List of items that should be shown in agenda log mode.
1293 This list may contain the following symbols:
1295 closed Show entries that have been closed on that day.
1296 clock Show entries that have received clocked time on that day.
1297 state Show all logged state changes.
1298 Note that instead of changing this variable, you can also press `C-u l' in
1299 the agenda to display all available LOG items temporarily."
1300 :group
'org-agenda-daily
/weekly
1301 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1303 (defcustom org-agenda-clock-consistency-checks
1304 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1305 :gap-ok-around
("4:00")
1306 :default-face
((:background
"DarkRed") (:foreground
"white"))
1307 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1308 :long-face nil
:short-face nil
)
1309 "This is a property list, with the following keys:
1311 :max-duration Mark clocking chunks that are longer than this time.
1312 This is a time string like \"HH:MM\", or the number
1313 of minutes as an integer.
1315 :min-duration Mark clocking chunks that are shorter that this.
1316 This is a time string like \"HH:MM\", or the number
1317 of minutes as an integer.
1319 :max-gap Mark gaps between clocking chunks that are longer than
1320 this duration. A number of minutes, or a string
1323 :gap-ok-around List of times during the day which are usually not working
1324 times. When a gap is detected, but the gap contains any
1325 of these times, the gap is *not* reported. For example,
1326 if this is (\"4:00\" \"13:00\") then gaps that contain
1327 4:00 in the morning (i.e. the night) and 13:00
1328 (i.e. a typical lunch time) do not cause a warning.
1329 You should have at least one time during the night in this
1330 list, or otherwise the first task each morning will trigger
1331 a warning because it follows a long gap.
1333 Furthermore, the following properties can be used to define faces for
1336 :default-face the default face, if the specific face is undefined
1337 :overlap-face face for overlapping clocks
1338 :gap-face face for gaps between clocks
1339 :no-end-time-face face for incomplete clocks
1340 :long-face face for clock intervals that are too long
1341 :short-face face for clock intervals that are too short"
1342 :group
'org-agenda-daily
/weekly
1347 (defcustom org-agenda-log-mode-add-notes t
1348 "Non-nil means add first line of notes to log entries in agenda views.
1349 If a log item like a state change or a clock entry is associated with
1350 notes, the first line of these notes will be added to the entry in the
1352 :group
'org-agenda-daily
/weekly
1355 (defcustom org-agenda-start-with-log-mode nil
1356 "The initial value of log-mode in a newly created agenda window.
1357 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1358 explanations on the possible values."
1359 :group
'org-agenda-startup
1360 :group
'org-agenda-daily
/weekly
1361 :type
'(choice (const :tag
"Don't show log items" nil
)
1362 (const :tag
"Show only log items" only
)
1363 (const :tag
"Show all possible log items" clockcheck
)
1364 (repeat :tag
"Choose among possible values for `org-agenda-log-mode-items'"
1365 (choice (const :tag
"Show closed log items" closed
)
1366 (const :tag
"Show clocked log items" clock
)
1367 (const :tag
"Show all logged state changes" state
)))))
1369 (defcustom org-agenda-start-with-clockreport-mode nil
1370 "The initial value of clockreport-mode in a newly created agenda window."
1371 :group
'org-agenda-startup
1372 :group
'org-agenda-daily
/weekly
1375 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1376 "Property list with parameters for the clocktable in clockreport mode.
1377 This is the display mode that shows a clock table in the daily/weekly
1378 agenda, the properties for this dynamic block can be set here.
1379 The usual clocktable parameters are allowed here, but you cannot set
1380 the properties :name, :tstart, :tend, :block, and :scope - these will
1381 be overwritten to make sure the content accurately reflects the
1382 current display in the agenda."
1383 :group
'org-agenda-daily
/weekly
1386 (defcustom org-agenda-search-view-always-boolean nil
1387 "Non-nil means the search string is interpreted as individual parts.
1389 The search string for search view can either be interpreted as a phrase,
1390 or as a list of snippets that define a boolean search for a number of
1393 When this is non-nil, the string will be split on whitespace, and each
1394 snippet will be searched individually, and all must match in order to
1395 select an entry. A snippet is then a single string of non-white
1396 characters, or a string in double quotes, or a regexp in {} braces.
1397 If a snippet is preceded by \"-\", the snippet must *not* match.
1398 \"+\" is syntactic sugar for positive selection. Each snippet may
1399 be found as a full word or a partial word, but see the variable
1400 `org-agenda-search-view-force-full-words'.
1402 When this is nil, search will look for the entire search phrase as one,
1403 with each space character matching any amount of whitespace, including
1406 Even when this is nil, you can still switch to Boolean search dynamically
1407 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1408 is a regexp marked with braces like \"{abc}\", this will also switch to
1410 :group
'org-agenda-search-view
1414 (org-defvaralias 'org-agenda-search-view-search-words-only
1415 'org-agenda-search-view-always-boolean
)
1417 (defcustom org-agenda-search-view-force-full-words nil
1418 "Non-nil means, search words must be matches as complete words.
1419 When nil, they may also match part of a word."
1420 :group
'org-agenda-search-view
1424 (defcustom org-agenda-search-view-max-outline-level
0
1425 "Maximum outline level to display in search view.
1426 E.g. when this is set to 1, the search view will only
1427 show headlines of level 1. When set to 0, the default
1428 value, don't limit agenda view by outline level."
1429 :group
'org-agenda-search-view
1431 :package-version
'(Org .
"8.3")
1434 (defgroup org-agenda-time-grid nil
1435 "Options concerning the time grid in the Org-mode Agenda."
1436 :tag
"Org Agenda Time Grid"
1439 (defcustom org-agenda-search-headline-for-time t
1440 "Non-nil means search headline for a time-of-day.
1441 If the headline contains a time-of-day in one format or another, it will
1442 be used to sort the entry into the time sequence of items for a day.
1443 Some people have time stamps in the headline that refer to the creation
1444 time or so, and then this produces an unwanted side effect. If this is
1445 the case for your, use this variable to turn off searching the headline
1447 :group
'org-agenda-time-grid
1450 (defcustom org-agenda-use-time-grid t
1451 "Non-nil means show a time grid in the agenda schedule.
1452 A time grid is a set of lines for specific times (like every two hours between
1453 8:00 and 20:00). The items scheduled for a day at specific times are
1454 sorted in between these lines.
1455 For details about when the grid will be shown, and what it will look like, see
1456 the variable `org-agenda-time-grid'."
1457 :group
'org-agenda-time-grid
1460 (defcustom org-agenda-time-grid
1461 '((daily today require-timed
)
1463 (800 1000 1200 1400 1600 1800 2000))
1465 "The settings for time grid for agenda display.
1466 This is a list of three items. The first item is again a list. It contains
1467 symbols specifying conditions when the grid should be displayed:
1469 daily if the agenda shows a single day
1470 weekly if the agenda shows an entire week
1471 today show grid on current date, independent of daily/weekly display
1472 require-timed show grid only if at least one item has a time specification
1473 remove-match skip grid times already present in an entry
1475 The second item is a string which will be placed behind the grid time.
1477 The third item is a list of integers, indicating the times that should have
1479 :group
'org-agenda-time-grid
1482 (set :greedy t
:tag
"Grid Display Options"
1483 (const :tag
"Show grid in single day agenda display" daily
)
1484 (const :tag
"Show grid in weekly agenda display" weekly
)
1485 (const :tag
"Always show grid for today" today
)
1486 (const :tag
"Show grid only if any timed entries are present"
1488 (const :tag
"Skip grid times already present in an entry"
1490 (string :tag
"Grid String")
1491 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1493 (defcustom org-agenda-show-current-time-in-grid t
1494 "Non-nil means show the current time in the time grid."
1495 :group
'org-agenda-time-grid
1499 (defcustom org-agenda-current-time-string
1500 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1501 "The string for the current time marker in the agenda."
1502 :group
'org-agenda-time-grid
1506 (defgroup org-agenda-sorting nil
1507 "Options concerning sorting in the Org-mode Agenda."
1508 :tag
"Org Agenda Sorting"
1511 (defcustom org-agenda-sorting-strategy
1512 '((agenda habit-down time-up priority-down category-keep
)
1513 (todo priority-down category-keep
)
1514 (tags priority-down category-keep
)
1515 (search category-keep
))
1516 "Sorting structure for the agenda items of a single day.
1517 This is a list of symbols which will be used in sequence to determine
1518 if an entry should be listed before another entry. The following
1519 symbols are recognized:
1521 time-up Put entries with time-of-day indications first, early first
1522 time-down Put entries with time-of-day indications first, late first
1523 timestamp-up Sort by any timestamp, early first
1524 timestamp-down Sort by any timestamp, late first
1525 scheduled-up Sort by scheduled timestamp, early first
1526 scheduled-down Sort by scheduled timestamp, late first
1527 deadline-up Sort by deadline timestamp, early first
1528 deadline-down Sort by deadline timestamp, late first
1529 ts-up Sort by active timestamp, early first
1530 ts-down Sort by active timestamp, late first
1531 tsia-up Sort by inactive timestamp, early first
1532 tsia-down Sort by inactive timestamp, late first
1533 category-keep Keep the default order of categories, corresponding to the
1534 sequence in `org-agenda-files'.
1535 category-up Sort alphabetically by category, A-Z.
1536 category-down Sort alphabetically by category, Z-A.
1537 tag-up Sort alphabetically by last tag, A-Z.
1538 tag-down Sort alphabetically by last tag, Z-A.
1539 priority-up Sort numerically by priority, high priority last.
1540 priority-down Sort numerically by priority, high priority first.
1541 todo-state-up Sort by todo state, tasks that are done last.
1542 todo-state-down Sort by todo state, tasks that are done first.
1543 effort-up Sort numerically by estimated effort, high effort last.
1544 effort-down Sort numerically by estimated effort, high effort first.
1545 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1546 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1547 habit-up Put entries that are habits first
1548 habit-down Put entries that are habits last
1549 alpha-up Sort headlines alphabetically
1550 alpha-down Sort headlines alphabetically, reversed
1552 The different possibilities will be tried in sequence, and testing stops
1553 if one comparison returns a \"not-equal\". For example, the default
1554 '(time-up category-keep priority-down)
1555 means: Pull out all entries having a specified time of day and sort them,
1556 in order to make a time schedule for the current day the first thing in the
1557 agenda listing for the day. Of the entries without a time indication, keep
1558 the grouped in categories, don't sort the categories, but keep them in
1559 the sequence given in `org-agenda-files'. Within each category sort by
1562 Leaving out `category-keep' would mean that items will be sorted across
1563 categories by priority.
1565 Instead of a single list, this can also be a set of list for specific
1566 contents, with a context symbol in the car of the list, any of
1567 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1569 Custom commands can bind this variable in the options section."
1570 :group
'org-agenda-sorting
1572 (repeat :tag
"General" ,org-sorting-choice
)
1573 (list :tag
"Individually"
1574 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1575 (repeat ,org-sorting-choice
))
1576 (cons (const :tag
"Strategy for TODO lists" todo
)
1577 (repeat ,org-sorting-choice
))
1578 (cons (const :tag
"Strategy for Tags matches" tags
)
1579 (repeat ,org-sorting-choice
))
1580 (cons (const :tag
"Strategy for search matches" search
)
1581 (repeat ,org-sorting-choice
)))))
1583 (defcustom org-agenda-cmp-user-defined nil
1584 "A function to define the comparison `user-defined'.
1585 This function must receive two arguments, agenda entry a and b.
1586 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1587 the user comparison, return nil.
1588 When this is defined, you can make `user-defined-up' and `user-defined-down'
1589 part of an agenda sorting strategy."
1590 :group
'org-agenda-sorting
1593 (defcustom org-sort-agenda-notime-is-late t
1594 "Non-nil means items without time are considered late.
1595 This is only relevant for sorting. When t, items which have no explicit
1596 time like 15:30 will be considered as 99:01, i.e. later than any items which
1597 do have a time. When nil, the default time is before 0:00. You can use this
1598 option to decide if the schedule for today should come before or after timeless
1600 :group
'org-agenda-sorting
1603 (defcustom org-sort-agenda-noeffort-is-high t
1604 "Non-nil means items without effort estimate are sorted as high effort.
1605 This also applies when filtering an agenda view with respect to the
1606 < or > effort operator. Then, tasks with no effort defined will be treated
1607 as tasks with high effort.
1608 When nil, such items are sorted as 0 minutes effort."
1609 :group
'org-agenda-sorting
1612 (defgroup org-agenda-line-format nil
1613 "Options concerning the entry prefix in the Org-mode agenda display."
1614 :tag
"Org Agenda Line Format"
1617 (defcustom org-agenda-prefix-format
1618 '((agenda .
" %i %-12:c%?-12t% s")
1620 (todo .
" %i %-12:c")
1621 (tags .
" %i %-12:c")
1622 (search .
" %i %-12:c"))
1623 "Format specifications for the prefix of items in the agenda views.
1624 An alist with five entries, each for the different agenda types. The
1625 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1626 The values are format strings.
1628 This format works similar to a printf format, with the following meaning:
1630 %c the category of the item, \"Diary\" for entries from the diary,
1631 or as given by the CATEGORY keyword or derived from the file name
1632 %e the effort required by the item
1633 %l the level of the item (insert X space(s) if item is of level X)
1634 %i the icon category of the item, see `org-agenda-category-icon-alist'
1635 %T the last tag of the item (ignore inherited tags, which come first)
1636 %t the HH:MM time-of-day specification if one applies to the entry
1637 %s Scheduling/Deadline information, a short string
1638 %b show breadcrumbs, i.e., the names of the higher levels
1639 %(expression) Eval EXPRESSION and replace the control string
1642 All specifiers work basically like the standard `%s' of printf, but may
1643 contain two additional characters: a question mark just after the `%'
1644 and a whitespace/punctuation character just before the final letter.
1646 If the first character after `%' is a question mark, the entire field
1647 will only be included if the corresponding value applies to the current
1648 entry. This is useful for fields which should have fixed width when
1649 present, but zero width when absent. For example, \"%?-12t\" will
1650 result in a 12 character time field if a time of the day is specified,
1651 but will completely disappear in entries which do not contain a time.
1653 If there is punctuation or whitespace character just before the
1654 final format letter, this character will be appended to the field
1655 value if the value is not empty. For example, the format
1656 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1657 the category is empty, no additional colon is inserted.
1659 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1662 - Indent the line with two space characters
1663 - Give the category a 12 chars wide field, padded with whitespace on
1664 the right (because of `-'). Append a colon if there is a category
1666 - If there is a time-of-day, put it into a 12 chars wide field. If no
1667 time, don't put in an empty field, just skip it (because of '?').
1668 - Finally, put the scheduling information.
1670 See also the variables `org-agenda-remove-times-when-in-prefix' and
1671 `org-agenda-remove-tags'.
1673 Custom commands can set this variable in the options section."
1675 (string :tag
"General format")
1676 (list :greedy t
:tag
"View dependent"
1677 (cons (const agenda
) (string :tag
"Format"))
1678 (cons (const timeline
) (string :tag
"Format"))
1679 (cons (const todo
) (string :tag
"Format"))
1680 (cons (const tags
) (string :tag
"Format"))
1681 (cons (const search
) (string :tag
"Format"))))
1682 :group
'org-agenda-line-format
)
1684 (defvar org-prefix-format-compiled nil
1685 "The compiled prefix format and associated variables.
1686 This is a list where first element is a list of variable bindings, and second
1687 element is the compiled format expression. See the variable
1688 `org-agenda-prefix-format'.")
1690 (defcustom org-agenda-todo-keyword-format
"%-1s"
1691 "Format for the TODO keyword in agenda lines.
1692 Set this to something like \"%-12s\" if you want all TODO keywords
1693 to occupy a fixed space in the agenda display."
1694 :group
'org-agenda-line-format
1697 (defcustom org-agenda-diary-sexp-prefix nil
1698 "A regexp that matches part of a diary sexp entry
1699 which should be treated as scheduling/deadline information in
1702 For example, you can use this to extract the `diary-remind-message' from
1703 `diary-remind' entries."
1704 :group
'org-agenda-line-format
1705 :type
'(choice (const :tag
"None" nil
) (regexp :tag
"Regexp")))
1707 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1708 "Text preceding timerange entries in the agenda view.
1709 This is a list with two strings. The first applies when the range
1710 is entirely on one day. The second applies if the range spans several days.
1711 The strings may have two \"%d\" format specifiers which will be filled
1712 with the sequence number of the days, and the total number of days in the
1713 range, respectively."
1714 :group
'org-agenda-line-format
1716 (string :tag
"Deadline today ")
1717 (choice :tag
"Deadline relative"
1718 (string :tag
"Format string")
1721 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1722 "Text preceding scheduled items in the agenda view.
1723 This is a list with two strings. The first applies when the item is
1724 scheduled on the current day. The second applies when it has been scheduled
1725 previously, it may contain a %d indicating that this is the nth time that
1726 this item is scheduled, due to automatic rescheduling of unfinished items
1727 for the following day. So this number is one larger than the number of days
1728 that passed since this item was scheduled first."
1729 :group
'org-agenda-line-format
1731 :package-version
'(Org .
"8.0")
1733 (string :tag
"Scheduled today ")
1734 (string :tag
"Scheduled previously")))
1736 (defcustom org-agenda-inactive-leader
"["
1737 "Text preceding item pulled into the agenda by inactive time stamps.
1738 These entries are added to the agenda when pressing \"[\"."
1739 :group
'org-agenda-line-format
1743 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: " "%2d d. ago: ")
1744 "Text preceding deadline items in the agenda view.
1745 This is a list with three strings. The first applies when the item has its
1746 deadline on the current day. The second applies when the deadline is in the
1747 future, the third one when it is in the past. The strings may contain %d
1748 to capture the number of days."
1749 :group
'org-agenda-line-format
1751 :package-version
'(Org .
"8.0")
1753 (string :tag
"Deadline today ")
1754 (string :tag
"Deadline in the future ")
1755 (string :tag
"Deadline in the past ")))
1757 (defcustom org-agenda-remove-times-when-in-prefix t
1758 "Non-nil means remove duplicate time specifications in agenda items.
1759 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1760 time-of-day specification in a headline or diary entry is extracted and
1761 placed into the prefix. If this option is non-nil, the original specification
1762 \(a timestamp or -range, or just a plain time(range) specification like
1763 11:30-4pm) will be removed for agenda display. This makes the agenda less
1765 The option can be t or nil. It may also be the symbol `beg', indicating
1766 that the time should only be removed when it is located at the beginning of
1767 the headline/diary entry."
1768 :group
'org-agenda-line-format
1770 (const :tag
"Always" t
)
1771 (const :tag
"Never" nil
)
1772 (const :tag
"When at beginning of entry" beg
)))
1774 (defcustom org-agenda-remove-timeranges-from-blocks nil
1775 "Non-nil means remove time ranges specifications in agenda
1776 items that span on several days."
1777 :group
'org-agenda-line-format
1781 (defcustom org-agenda-default-appointment-duration nil
1782 "Default duration for appointments that only have a starting time.
1783 When nil, no duration is specified in such cases.
1784 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1785 :group
'org-agenda-line-format
1787 (integer :tag
"Minutes")
1788 (const :tag
"No default duration")))
1790 (defcustom org-agenda-show-inherited-tags t
1791 "Non-nil means show inherited tags in each agenda line.
1793 When this option is set to 'always, it take precedences over
1794 `org-agenda-use-tag-inheritance' and inherited tags are shown
1797 When this option is set to t (the default), inherited tags are
1798 shown when they are available, i.e. when the value of
1799 `org-agenda-use-tag-inheritance' has been taken into account.
1801 This can be set to a list of agenda types in which the agenda
1802 must display the inherited tags. Available types are 'todo,
1803 'agenda, 'search and 'timeline.
1805 When set to nil, never show inherited tags in agenda lines."
1806 :group
'org-agenda-line-format
1810 (const :tag
"Show inherited tags when available" t
)
1811 (const :tag
"Always show inherited tags" always
)
1812 (repeat :tag
"Show inherited tags only in selected agenda types"
1813 (symbol :tag
"Agenda type"))))
1815 (defcustom org-agenda-use-tag-inheritance
'(todo search timeline agenda
)
1816 "List of agenda view types where to use tag inheritance.
1818 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1819 controlled by `org-use-tag-inheritance'. In other agenda types,
1820 `org-use-tag-inheritance' is not used for the selection of the
1821 agenda entries. Still, you may want the agenda to be aware of
1822 the inherited tags anyway, e.g. for later tag filtering.
1824 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1826 This variable has no effect if `org-agenda-show-inherited-tags'
1827 is set to 'always. In that case, the agenda is aware of those
1830 The default value sets tags in every agenda type. Setting this
1831 option to nil will speed up non-tags agenda view a lot."
1835 (const :tag
"Use tag inheritance in all agenda types" t
)
1836 (repeat :tag
"Use tag inheritance in selected agenda types"
1837 (symbol :tag
"Agenda type"))))
1839 (defcustom org-agenda-hide-tags-regexp nil
1840 "Regular expression used to filter away specific tags in agenda views.
1841 This means that these tags will be present, but not be shown in the agenda
1842 line. Secondary filtering will still work on the hidden tags.
1843 Nil means don't hide any tags."
1844 :group
'org-agenda-line-format
1846 (const :tag
"Hide none" nil
)
1847 (string :tag
"Regexp ")))
1849 (defcustom org-agenda-remove-tags nil
1850 "Non-nil means remove the tags from the headline copy in the agenda.
1851 When this is the symbol `prefix', only remove tags when
1852 `org-agenda-prefix-format' contains a `%T' specifier."
1853 :group
'org-agenda-line-format
1855 (const :tag
"Always" t
)
1856 (const :tag
"Never" nil
)
1857 (const :tag
"When prefix format contains %T" prefix
)))
1859 (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
1860 'org-agenda-remove-tags
)
1862 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1863 "Shift tags in agenda items to this column.
1864 If this number is positive, it specifies the column. If it is negative,
1865 it means that the tags should be flushright to that column. For example,
1866 -80 works well for a normal 80 character screen."
1867 :group
'org-agenda-line-format
1870 (org-defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
)
1872 (defcustom org-agenda-fontify-priorities
'cookies
1873 "Non-nil means highlight low and high priorities in agenda.
1874 When t, the highest priority entries are bold, lowest priority italic.
1875 However, settings in `org-priority-faces' will overrule these faces.
1876 When this variable is the symbol `cookies', only fontify the
1877 cookies, not the entire task.
1878 This may also be an association list of priority faces, whose
1879 keys are the character values of `org-highest-priority',
1880 `org-default-priority', and `org-lowest-priority' (the default values
1881 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1882 color as a string, or a list like `(:background \"Red\")'.
1883 If it is a color, the variable `org-faces-easy-properties'
1884 determines if it is a foreground or a background color."
1885 :group
'org-agenda-line-format
1887 (const :tag
"Never" nil
)
1888 (const :tag
"Defaults" t
)
1889 (const :tag
"Cookies only" cookies
)
1890 (repeat :tag
"Specify"
1891 (list (character :tag
"Priority" :value ?A
)
1892 (choice :tag
"Face "
1893 (string :tag
"Color")
1894 (sexp :tag
"Face"))))))
1896 (defcustom org-agenda-day-face-function nil
1897 "Function called to determine what face should be used to display a day.
1898 The only argument passed to that function is the day. It should
1899 returns a face, or nil if does not want to specify a face and let
1900 the normal rules apply."
1901 :group
'org-agenda-line-format
1903 :type
'(choice (const nil
) (function)))
1905 (defcustom org-agenda-category-icon-alist nil
1906 "Alist of category icon to be displayed in agenda views.
1908 Each entry should have the following format:
1910 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1912 Where CATEGORY-REGEXP is a regexp matching the categories where
1913 the icon should be displayed.
1914 FILE-OR-DATA either a file path or a string containing image data.
1916 The other fields can be omitted safely if not needed:
1917 TYPE indicates the image type.
1918 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1920 PROPS are additional image attributes to assign to the image,
1921 like, e.g. `:ascent center'.
1923 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1925 If you want to set the display properties yourself, just put a
1926 list as second element:
1928 (CATEGORY-REGEXP (MY PROPERTY LIST))
1930 For example, to display a 16px horizontal space for Emacs
1931 category, you can use:
1933 (\"Emacs\" '(space . (:width (16))))"
1934 :group
'org-agenda-line-format
1936 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1937 :value-type
(choice (list :tag
"Icon"
1938 (string :tag
"File or data")
1939 (symbol :tag
"Type")
1940 (boolean :tag
"Data?")
1941 (repeat :tag
"Extra image properties" :inline t symbol
))
1942 (list :tag
"Display properties" sexp
))))
1944 (defgroup org-agenda-column-view nil
1945 "Options concerning column view in the agenda."
1946 :tag
"Org Agenda Column View"
1949 (defcustom org-agenda-columns-show-summaries t
1950 "Non-nil means show summaries for columns displayed in the agenda view."
1951 :group
'org-agenda-column-view
1954 (defcustom org-agenda-columns-compute-summary-properties t
1955 "Non-nil means recompute all summary properties before column view.
1956 When column view in the agenda is listing properties that have a summary
1957 operator, it can go to all relevant buffers and recompute the summaries
1958 there. This can mean overhead for the agenda column view, but is necessary
1959 to have thing up to date.
1960 As a special case, a CLOCKSUM property also makes sure that the clock
1961 computations are current."
1962 :group
'org-agenda-column-view
1965 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1966 "Non-nil means the duration of an appointment will add to day effort.
1967 The property to which appointment durations will be added is the one given
1968 in the option `org-effort-property'. If an appointment does not have
1969 an end time, `org-agenda-default-appointment-duration' will be used. If that
1970 is not set, an appointment without end time will not contribute to the time
1972 :group
'org-agenda-column-view
1975 (defcustom org-agenda-auto-exclude-function nil
1976 "A function called with a tag to decide if it is filtered on '/ RET'.
1977 The sole argument to the function, which is called once for each
1978 possible tag, is a string giving the name of the tag. The
1979 function should return either nil if the tag should be included
1980 as normal, or \"-<TAG>\" to exclude the tag.
1981 Note that for the purpose of tag filtering, only the lower-case version of
1982 all tags will be considered, so that this function will only ever see
1983 the lower-case version of all tags."
1985 :type
'(choice (const nil
) (function)))
1987 (defcustom org-agenda-bulk-custom-functions nil
1988 "Alist of characters and custom functions for bulk actions.
1989 For example, this value makes those two functions available:
1994 With selected entries in an agenda buffer, `B R' will call
1995 the custom function `set-category' on the selected entries.
1996 Note that functions in this alist don't need to be quoted."
2001 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
2002 "Execute BODY with point at location given by `org-hd-marker' property.
2003 If STRING is non-nil, the text property will be fetched from position 0
2004 in that string. If STRING is nil, it will be fetched from the beginning
2005 of the current line."
2006 (org-with-gensyms (marker)
2007 `(let ((,marker
(get-text-property (if string
0 (point-at-bol))
2008 'org-hd-marker
,string
)))
2009 (with-current-buffer (marker-buffer ,marker
)
2013 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
2015 (defun org-add-agenda-custom-command (entry)
2016 "Replace or add a command in `org-agenda-custom-commands'.
2017 This is mostly for hacking and trying a new command - once the command
2018 works you probably want to add it to `org-agenda-custom-commands' for good."
2019 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
2021 (setcdr ass
(cdr entry
))
2022 (push entry org-agenda-custom-commands
))))
2024 ;;; Define the org-agenda-mode
2026 (defvar org-agenda-mode-map
(make-sparse-keymap)
2027 "Keymap for `org-agenda-mode'.")
2028 (org-defvaralias 'org-agenda-keymap
'org-agenda-mode-map
)
2030 (defvar org-agenda-menu
) ; defined later in this file.
2031 (defvar org-agenda-restrict nil
) ; defined later in this file.
2032 (defvar org-agenda-follow-mode nil
)
2033 (defvar org-agenda-entry-text-mode nil
)
2034 (defvar org-agenda-clockreport-mode nil
)
2035 (defvar org-agenda-show-log nil
)
2036 (defvar org-agenda-redo-command nil
)
2037 (defvar org-agenda-query-string nil
)
2038 (defvar org-agenda-mode-hook nil
2039 "Hook run after `org-agenda-mode' is turned on.
2040 The buffer is still writable when this hook is called.")
2041 (defvar org-agenda-type nil
)
2042 (defvar org-agenda-force-single-file nil
)
2043 (defvar org-agenda-bulk-marked-entries nil
2044 "List of markers that refer to marked entries in the agenda.")
2046 ;;; Multiple agenda buffers support
2048 (defcustom org-agenda-sticky nil
2049 "Non-nil means agenda q key will bury agenda buffers.
2050 Agenda commands will then show existing buffer instead of generating new ones.
2051 When nil, `q' will kill the single agenda buffer."
2058 (defun org-toggle-sticky-agenda (&optional arg
)
2059 "Toggle `org-agenda-sticky'."
2061 (let ((new-value (if arg
2062 (> (prefix-numeric-value arg
) 0)
2063 (not org-agenda-sticky
))))
2064 (if (equal new-value org-agenda-sticky
)
2065 (and (org-called-interactively-p 'interactive
)
2066 (message "Sticky agenda was already %s"
2067 (if org-agenda-sticky
"enabled" "disabled")))
2068 (setq org-agenda-sticky new-value
)
2069 (org-agenda-kill-all-agenda-buffers)
2070 (and (org-called-interactively-p 'interactive
)
2071 (message "Sticky agenda was %s"
2072 (if org-agenda-sticky
"enabled" "disabled"))))))
2074 (defvar org-agenda-buffer nil
2075 "Agenda buffer currently being generated.")
2077 (defvar org-agenda-last-prefix-arg nil
)
2078 (defvar org-agenda-this-buffer-name nil
)
2079 (defvar org-agenda-doing-sticky-redo nil
)
2080 (defvar org-agenda-this-buffer-is-sticky nil
)
2082 (defconst org-agenda-local-vars
2083 '(org-agenda-this-buffer-name
2084 org-agenda-undo-list
2085 org-agenda-pending-undo-list
2086 org-agenda-follow-mode
2087 org-agenda-entry-text-mode
2088 org-agenda-clockreport-mode
2090 org-agenda-redo-command
2091 org-agenda-query-string
2093 org-agenda-bulk-marked-entries
2094 org-agenda-undo-has-started-in
2096 org-agenda-pre-window-conf
2097 org-agenda-columns-active
2098 org-agenda-tag-filter
2099 org-agenda-category-filter
2100 org-agenda-top-headline-filter
2101 org-agenda-regexp-filter
2102 org-agenda-effort-filter
2104 org-agenda-last-search-view-search-was-boolean
2105 org-agenda-filtered-by-category
2106 org-agenda-filter-form
2107 org-agenda-cycle-counter
2108 org-agenda-last-prefix-arg
)
2109 "Variables that must be local in agenda buffers to allow multiple buffers.")
2111 (defun org-agenda-mode ()
2112 "Mode for time-sorted view on action items in Org-mode files.
2114 The following commands are available:
2116 \\{org-agenda-mode-map}"
2118 (cond (org-agenda-doing-sticky-redo
2119 ;; Refreshing sticky agenda-buffer
2121 ;; Preserve the value of `org-agenda-local-vars' variables,
2122 ;; while letting `kill-all-local-variables' kill the rest
2123 (let ((save (buffer-local-variables)))
2124 (kill-all-local-variables)
2125 (mapc 'make-local-variable org-agenda-local-vars
)
2127 (let ((var (car elem
))
2130 (member var org-agenda-local-vars
))
2132 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
2134 ;; Creating a sticky Agenda buffer for the first time
2135 (kill-all-local-variables)
2136 (mapc 'make-local-variable org-agenda-local-vars
)
2137 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) t
))
2139 ;; Creating a non-sticky agenda buffer
2140 (kill-all-local-variables)
2141 (set (make-local-variable 'org-agenda-this-buffer-is-sticky
) nil
)))
2142 (setq org-agenda-undo-list nil
2143 org-agenda-pending-undo-list nil
2144 org-agenda-bulk-marked-entries nil
)
2145 (setq major-mode
'org-agenda-mode
)
2146 ;; Keep global-font-lock-mode from turning on font-lock-mode
2147 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
2148 (setq mode-name
"Org-Agenda")
2149 (setq indent-tabs-mode nil
)
2150 (use-local-map org-agenda-mode-map
)
2151 (easy-menu-add org-agenda-menu
)
2152 (if org-startup-truncated
(setq truncate-lines t
))
2153 (org-set-local 'line-move-visual nil
)
2154 (org-add-hook 'post-command-hook
'org-agenda-update-agenda-type nil
'local
)
2155 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
2156 ;; Make sure properties are removed when copying text
2157 (org-add-hook 'filter-buffer-substring-functions
2158 (lambda (fun start end delete
)
2159 (substring-no-properties (funcall fun start end delete
)))
2161 (unless org-agenda-keep-modes
2162 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2163 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
))
2164 (setq org-agenda-show-log org-agenda-start-with-log-mode
)
2165 (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
)
2166 (add-to-invisibility-spec '(org-filtered))
2167 (add-to-invisibility-spec '(org-link))
2169 '("Agenda") "Agenda Files"
2173 (if (get 'org-agenda-files
'org-restrict
)
2174 "Restricted to single file"
2176 '(org-edit-agenda-file-list)
2177 (not (get 'org-agenda-files
'org-restrict
)))
2179 (mapcar 'org-file-menu-entry
(org-agenda-files))))
2180 (org-agenda-set-mode-name)
2182 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
2183 (list 'org-agenda-mode-hook
)))
2185 (substitute-key-definition 'undo
'org-agenda-undo
2186 org-agenda-mode-map global-map
)
2187 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
2188 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
2189 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
2190 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
2191 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
2192 (org-defkey org-agenda-mode-map
[(meta down
)] 'org-agenda-drag-line-forward
)
2193 (org-defkey org-agenda-mode-map
[(meta up
)] 'org-agenda-drag-line-backward
)
2194 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
2195 (org-defkey org-agenda-mode-map
"\M-m" 'org-agenda-bulk-toggle
)
2196 (org-defkey org-agenda-mode-map
"*" 'org-agenda-bulk-mark-all
)
2197 (org-defkey org-agenda-mode-map
"\M-*" 'org-agenda-bulk-toggle-all
)
2198 (org-defkey org-agenda-mode-map
"#" 'org-agenda-dim-blocked-tasks
)
2199 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
2200 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
2201 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-unmark-all
)
2202 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
2203 (org-defkey org-agenda-mode-map
"k" 'org-agenda-capture
)
2204 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
2205 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
2206 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
2207 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
2208 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
2209 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
2210 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
2211 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
2212 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
2213 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
2214 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
2215 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2216 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2217 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2218 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2219 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2220 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2221 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2222 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2223 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2224 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2225 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2226 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2227 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2228 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2229 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2230 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2231 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2232 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2233 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2234 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2235 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2236 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2238 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2239 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2240 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2241 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2242 (while l (org-defkey org-agenda-mode-map
2243 (int-to-string (pop l)) 'digit-argument)))
2245 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2246 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2247 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2248 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2249 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2250 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2251 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2252 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2253 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2254 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2255 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2256 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2257 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2258 'org-clock-modify-effort-estimate)
2259 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2260 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2261 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2262 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2263 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2264 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2265 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2266 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2267 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2268 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2269 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2270 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2271 (substitute-key-definition 'next-line 'org-agenda-next-line
2272 org-agenda-mode-map global-map)
2273 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2274 org-agenda-mode-map global-map)
2275 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2276 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2277 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2278 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2279 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2280 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2281 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2282 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2283 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2284 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2285 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2286 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2287 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2288 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2289 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2290 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2291 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2292 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2293 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2294 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2295 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2296 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2297 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2298 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2299 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2300 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2301 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2302 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2303 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2304 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2306 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2307 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2308 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2309 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2310 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2311 (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
2312 (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
2313 (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
2314 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2315 (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
2316 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2317 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
2318 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2319 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2320 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2321 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2323 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2324 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2326 (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
2327 (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
2329 (when org-agenda-mouse-1-follows-link
2330 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2331 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2336 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2337 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2338 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2339 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2342 ["Day View" org-agenda-day-view
2343 :active (org-agenda-check-type nil 'agenda)
2344 :style radio :selected (eq org-agenda-current-span 'day)
2345 :keys "v d (or just d)"]
2346 ["Week View" org-agenda-week-view
2347 :active (org-agenda-check-type nil 'agenda)
2348 :style radio :selected (eq org-agenda-current-span 'week)
2350 ["Fortnight View" org-agenda-fortnight-view
2351 :active (org-agenda-check-type nil 'agenda)
2352 :style radio :selected (eq org-agenda-current-span 'fortnight)
2354 ["Month View" org-agenda-month-view
2355 :active (org-agenda-check-type nil 'agenda)
2356 :style radio :selected (eq org-agenda-current-span 'month)
2358 ["Year View" org-agenda-year-view
2359 :active (org-agenda-check-type nil 'agenda)
2360 :style radio :selected (eq org-agenda-current-span 'year)
2363 ["Include Diary" org-agenda-toggle-diary
2364 :style toggle :selected org-agenda-include-diary
2365 :active (org-agenda-check-type nil 'agenda)]
2366 ["Include Deadlines" org-agenda-toggle-deadlines
2367 :style toggle :selected org-agenda-include-deadlines
2368 :active (org-agenda-check-type nil 'agenda)]
2369 ["Use Time Grid" org-agenda-toggle-time-grid
2370 :style toggle :selected org-agenda-use-time-grid
2371 :active (org-agenda-check-type nil 'agenda)]
2373 ["Show clock report" org-agenda-clockreport-mode
2374 :style toggle :selected org-agenda-clockreport-mode
2375 :active (org-agenda-check-type nil 'agenda)]
2376 ["Show some entry text" org-agenda-entry-text-mode
2377 :style toggle :selected org-agenda-entry-text-mode
2380 ["Show Logbook entries" org-agenda-log-mode
2381 :style toggle :selected org-agenda-show-log
2382 :active (org-agenda-check-type nil 'agenda 'timeline)
2383 :keys "v l (or just l)"]
2384 ["Include archived trees" org-agenda-archives-mode
2385 :style toggle :selected org-agenda-archives-mode :active t
2387 ["Include archive files" (org-agenda-archives-mode t)
2388 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2391 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2392 ["Write view to file" org-agenda-write t]
2393 ["Rebuild buffer" org-agenda-redo t]
2394 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2396 ["Show original entry" org-agenda-show t]
2397 ["Go To (other window)" org-agenda-goto t]
2398 ["Go To (this window)" org-agenda-switch-to t]
2399 ["Capture with cursor date" org-agenda-capture t]
2400 ["Follow Mode" org-agenda-follow-mode
2401 :style toggle :selected org-agenda-follow-mode :active t]
2402 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2405 ["Cycle TODO" org-agenda-todo t]
2406 ["Next TODO set" org-agenda-todo-nextset t]
2407 ["Previous TODO set" org-agenda-todo-previousset t]
2408 ["Add note" org-agenda-add-note t])
2409 ("Archive/Refile/Delete"
2410 ["Archive default" org-agenda-archive-default t]
2411 ["Archive default" org-agenda-archive-default-with-confirmation t]
2412 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2413 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2414 ["Archive subtree" org-agenda-archive t]
2416 ["Refile" org-agenda-refile t]
2418 ["Delete subtree" org-agenda-kill t])
2420 ["Mark entry" org-agenda-bulk-mark t]
2421 ["Mark all" org-agenda-bulk-mark-all t]
2422 ["Unmark entry" org-agenda-bulk-unmark t]
2423 ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
2424 ["Toggle mark" org-agenda-bulk-toggle t]
2425 ["Toggle all" org-agenda-bulk-toggle-all t]
2426 ["Mark regexp" org-agenda-bulk-mark-regexp t])
2427 ["Act on all marked" org-agenda-bulk-action t]
2429 ("Tags and Properties"
2430 ["Show all Tags" org-agenda-show-tags t]
2431 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2432 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2434 ["Column View" org-columns t])
2435 ("Deadline/Schedule"
2436 ["Schedule" org-agenda-schedule t]
2437 ["Set Deadline" org-agenda-deadline t]
2439 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2440 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2441 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2442 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2443 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2444 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2445 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2447 ["Clock in" org-agenda-clock-in t]
2448 ["Clock out" org-agenda-clock-out t]
2449 ["Clock cancel" org-agenda-clock-cancel t]
2450 ["Goto running clock" org-clock-goto t]
2452 ["Set Effort" org-agenda-set-effort t]
2453 ["Change clocked effort" org-clock-modify-effort-estimate
2454 (org-clock-is-active)])
2456 ["Set Priority" org-agenda-priority t]
2457 ["Increase Priority" org-agenda-priority-up t]
2458 ["Decrease Priority" org-agenda-priority-down t]
2459 ["Show Priority" org-show-priority t])
2461 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2462 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2463 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2464 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2465 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2466 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2468 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2470 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2473 ["Push Files and Views" org-mobile-push t]
2474 ["Get Captured and Flagged" org-mobile-pull t]
2475 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2476 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2478 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2480 ["Quit" org-agenda-quit t]
2481 ["Exit and Release Buffers" org-agenda-exit t]
2486 (defvar org-agenda-allow-remote-undo t
2487 "Non-nil means allow remote undo from the agenda buffer.")
2488 (defvar org-agenda-undo-has-started-in nil
2489 "Buffers that have already seen `undo-start' in the current undo sequence.")
2491 (defun org-agenda-undo ()
2492 "Undo a remote editing step in the agenda.
2493 This undoes changes both in the agenda buffer and in the remote buffer
2494 that have been changed along."
2496 (or org-agenda-allow-remote-undo
2497 (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2498 (if (not (eq this-command last-command))
2499 (setq org-agenda-undo-has-started-in nil
2500 org-agenda-pending-undo-list org-agenda-undo-list))
2501 (if (not org-agenda-pending-undo-list)
2502 (user-error "No further undo information"))
2503 (let* ((entry (pop org-agenda-pending-undo-list))
2504 buf line cmd rembuf)
2505 (setq cmd (pop entry) line (pop entry))
2506 (setq rembuf (nth 2 entry))
2507 (org-with-remote-undo rembuf
2508 (while (bufferp (setq buf (pop entry)))
2510 (with-current-buffer buf
2511 (let ((last-undo-buffer buf)
2512 (inhibit-read-only t))
2513 (unless (memq buf org-agenda-undo-has-started-in)
2514 (push buf org-agenda-undo-has-started-in)
2515 (make-local-variable 'pending-undo-list)
2517 (while (and pending-undo-list
2518 (listp pending-undo-list)
2519 (not (car pending-undo-list)))
2520 (pop pending-undo-list))
2522 (org-goto-line line)
2523 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2525 (defun org-verify-change-for-undo (l1 l2)
2526 "Verify that a real change occurred between the undo lists L1 and L2."
2527 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2528 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2533 (defvar org-agenda-restrict-begin (make-marker))
2534 (defvar org-agenda-restrict-end (make-marker))
2535 (defvar org-agenda-last-dispatch-buffer nil)
2536 (defvar org-agenda-overriding-restriction nil)
2538 (defcustom org-agenda-custom-commands-contexts nil
2539 "Alist of custom agenda keys and contextual rules.
2541 For example, if you have a custom agenda command \"p\" and you
2542 want this command to be accessible only from plain text files,
2545 '((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
2547 Here are the available contexts definitions:
2549 in-file: command displayed only in matching files
2550 in-mode: command displayed only in matching modes
2551 not-in-file: command not displayed in matching files
2552 not-in-mode: command not displayed in matching modes
2553 in-buffer: command displayed only in matching buffers
2554 not-in-buffer: command not displayed in matching buffers
2555 [function]: a custom function taking no argument
2557 If you define several checks, the agenda command will be
2558 accessible if there is at least one valid check.
2560 You can also bind a key to another agenda custom command
2561 depending on contextual rules.
2563 '((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
2565 Here it means: in .txt files, use \"p\" as the key for the
2566 agenda command otherwise associated with \"q\". (The command
2567 originally associated with \"q\" is not displayed to avoid
2570 :group 'org-agenda-custom-commands
2571 :type '(repeat (list :tag "Rule"
2572 (string :tag " Agenda key")
2573 (string :tag "Replace by command")
2574 (repeat :tag "Available when"
2576 (cons :tag "Condition"
2578 (const :tag "In file" in-file)
2579 (const :tag "Not in file" not-in-file)
2580 (const :tag "In buffer" in-buffer)
2581 (const :tag "Not in buffer" not-in-buffer)
2582 (const :tag "In mode" in-mode)
2583 (const :tag "Not in mode" not-in-mode))
2585 (function :tag "Custom function"))))))
2587 (defcustom org-agenda-max-entries nil
2588 "Maximum number of entries to display in an agenda.
2589 This can be nil (no limit) or an integer or an alist of agenda
2590 types with an associated number of entries to display in this
2593 :package-version '(Org . "8.0")
2594 :group 'org-agenda-custom-commands
2595 :type '(choice (symbol :tag "No limit" nil)
2596 (integer :tag "Max number of entries")
2598 (cons (choice :tag "Agenda type"
2604 (integer :tag "Max number of entries")))))
2606 (defcustom org-agenda-max-todos nil
2607 "Maximum number of TODOs to display in an agenda.
2608 This can be nil (no limit) or an integer or an alist of agenda
2609 types with an associated number of entries to display in this
2612 :package-version '(Org . "8.0")
2613 :group 'org-agenda-custom-commands
2614 :type '(choice (symbol :tag "No limit" nil)
2615 (integer :tag "Max number of TODOs")
2617 (cons (choice :tag "Agenda type"
2623 (integer :tag "Max number of TODOs")))))
2625 (defcustom org-agenda-max-tags nil
2626 "Maximum number of tagged entries to display in an agenda.
2627 This can be nil (no limit) or an integer or an alist of agenda
2628 types with an associated number of entries to display in this
2631 :package-version '(Org . "8.0")
2632 :group 'org-agenda-custom-commands
2633 :type '(choice (symbol :tag "No limit" nil)
2634 (integer :tag "Max number of tagged entries")
2636 (cons (choice :tag "Agenda type"
2642 (integer :tag "Max number of tagged entries")))))
2644 (defcustom org-agenda-max-effort nil
2645 "Maximum cumulated effort duration for the agenda.
2646 This can be nil (no limit) or a number of minutes (as an integer)
2647 or an alist of agenda types with an associated number of minutes
2648 to limit entries to in this type."
2650 :package-version '(Org . "8.0")
2651 :group 'org-agenda-custom-commands
2652 :type '(choice (symbol :tag "No limit" nil)
2653 (integer :tag "Max number of minutes")
2655 (cons (choice :tag "Agenda type"
2661 (integer :tag "Max number of minutes")))))
2663 (defvar org-keys nil)
2664 (defvar org-match nil)
2666 (defun org-agenda (&optional arg org-keys restriction)
2667 "Dispatch agenda commands to collect entries to the agenda buffer.
2668 Prompts for a command to execute. Any prefix arg will be passed
2669 on to the selected command. The default selections are:
2671 a Call `org-agenda-list' to display the agenda for current day or week.
2672 t Call `org-todo-list' to display the global todo list.
2673 T Call `org-todo-list' to display the global todo list, select only
2674 entries with a specific TODO keyword (the user gets a prompt).
2675 m Call `org-tags-view' to display headlines with tags matching
2676 a condition (the user is prompted for the condition).
2677 M Like `m', but select only TODO entries, no ordinary headlines.
2678 L Create a timeline for the current buffer.
2679 e Export views to associated files.
2680 s Search entries for keywords.
2681 S Search entries for keywords, only with TODO keywords.
2682 / Multi occur across all agenda files and also files listed
2683 in `org-agenda-text-search-extra-files'.
2684 < Restrict agenda commands to buffer, subtree, or region.
2685 Press several times to get the desired effect.
2686 > Remove a previous restriction.
2687 # List \"stuck\" projects.
2688 ! Configure what \"stuck\" means.
2689 C Configure custom agenda commands.
2691 More commands can be added by configuring the variable
2692 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2693 searches can be pre-defined in this way.
2695 If the current buffer is in Org-mode and visiting a file, you can also
2696 first press `<' once to indicate that the agenda should be temporarily
2697 \(until the next use of \\[org-agenda]) restricted to the current file.
2698 Pressing `<' twice means to restrict to the current subtree or region
2702 (let* ((prefix-descriptions nil)
2703 (org-agenda-buffer-name org-agenda-buffer-name)
2704 (org-agenda-window-setup (if (equal (buffer-name)
2705 org-agenda-buffer-name)
2707 org-agenda-window-setup))
2708 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2709 (org-agenda-custom-commands
2710 ;; normalize different versions
2714 (cond ((stringp (cdr x))
2715 (push x prefix-descriptions)
2717 ((stringp (nth 1 x)) x)
2718 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2719 (t (cons (car x) (cons "" (cdr x))))))
2720 org-agenda-custom-commands)))
2721 (org-agenda-custom-commands
2722 (org-contextualize-keys
2723 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2724 (buf (current-buffer))
2725 (bfn (buffer-file-name (buffer-base-buffer)))
2726 entry key type org-match lprops ans)
2727 ;; Turn off restriction unless there is an overriding one,
2728 (unless org-agenda-overriding-restriction
2729 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2730 ;; There is a request to keep the file list in place
2731 (put 'org-agenda-files 'org-restrict nil))
2732 (setq org-agenda-restrict nil)
2733 (move-marker org-agenda-restrict-begin nil)
2734 (move-marker org-agenda-restrict-end nil))
2735 ;; Delete old local properties
2736 (put 'org-agenda-redo-command 'org-lprops nil)
2737 ;; Delete previously set last-arguments
2738 (put 'org-agenda-redo-command 'last-args nil)
2739 ;; Remember where this call originated
2740 (setq org-agenda-last-dispatch-buffer (current-buffer))
2742 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2744 restriction (cdr ans)))
2745 ;; If we have sticky agenda buffers, set a name for the buffer,
2746 ;; depending on the invoking keys. The user may still set this
2747 ;; as a command option, which will overwrite what we do here.
2748 (if org-agenda-sticky
2749 (setq org-agenda-buffer-name
2750 (format "*Org Agenda(%s)*" org-keys)))
2751 ;; Establish the restriction, if any
2752 (when (and (not org-agenda-overriding-restriction) restriction)
2753 (put 'org-agenda-files 'org-restrict (list bfn))
2755 ((eq restriction 'region)
2756 (setq org-agenda-restrict (current-buffer))
2757 (move-marker org-agenda-restrict-begin (region-beginning))
2758 (move-marker org-agenda-restrict-end (region-end)))
2759 ((eq restriction 'subtree)
2761 (setq org-agenda-restrict (current-buffer))
2762 (org-back-to-heading t)
2763 (move-marker org-agenda-restrict-begin (point))
2764 (move-marker org-agenda-restrict-end
2765 (progn (org-end-of-subtree t)))))))
2767 ;; For example the todo list should not need it (but does...)
2769 ((setq entry (assoc org-keys org-agenda-custom-commands))
2770 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2772 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2773 lprops (nth 4 entry))
2774 (if org-agenda-sticky
2775 (setq org-agenda-buffer-name
2776 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2777 (format "*Org Agenda(%s)*" org-keys))))
2778 (put 'org-agenda-redo-command 'org-lprops lprops)
2781 (org-let lprops '(org-agenda-list current-prefix-arg)))
2783 (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
2785 (org-let lprops '(org-todo-list current-prefix-arg)))
2787 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2789 (org-let lprops '(org-agenda-list-stuck-projects
2790 current-prefix-arg)))
2792 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2793 ((eq type 'tags-todo)
2794 (org-let lprops '(org-tags-view '(4) org-match)))
2796 (org-let lprops '(org-todo-list org-match)))
2797 ((eq type 'tags-tree)
2798 (org-check-for-org-mode)
2799 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2800 ((eq type 'todo-tree)
2801 (org-check-for-org-mode)
2803 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2804 (regexp-quote org-match) "\\>"))))
2805 ((eq type 'occur-tree)
2806 (org-check-for-org-mode)
2807 (org-let lprops '(org-occur org-match)))
2809 (org-let lprops '(funcall type org-match)))
2811 (org-let lprops '(funcall type org-match)))
2812 (t (user-error "Invalid custom agenda command type %s" type))))
2813 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2814 ((equal org-keys "C")
2815 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2816 (customize-variable 'org-agenda-custom-commands))
2817 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2818 ((equal org-keys "s") (call-interactively 'org-search-view))
2819 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2820 ((equal org-keys "t") (call-interactively 'org-todo-list))
2821 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2822 ((equal org-keys "m") (call-interactively 'org-tags-view))
2823 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2824 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2825 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2829 (unless (current-message)
2830 (let* ((m (org-agenda-get-any-marker))
2831 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2834 "FLAGGING-NOTE ([?] for more info): "
2836 (replace-regexp-in-string
2838 (copy-sequence note))
2839 nil 'face 'org-warning)))))))
2841 ((equal org-keys "L")
2842 (unless (derived-mode-p 'org-mode)
2843 (user-error "This is not an Org-mode file"))
2845 (put 'org-agenda-files 'org-restrict (list bfn))
2846 (org-call-with-arg 'org-timeline arg)))
2847 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2848 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2849 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2850 (t (user-error "Invalid agenda key"))))))
2852 (defvar org-agenda-multi)
2854 (defun org-agenda-append-agenda ()
2855 "Append another agenda view to the current one.
2856 This function allows interactive building of block agendas.
2857 Agenda views are separated by `org-agenda-block-separator'."
2859 (unless (derived-mode-p 'org-agenda-mode)
2860 (user-error "Can only append from within agenda buffer"))
2861 (let ((org-agenda-multi t))
2864 (org-agenda-finalize)
2865 (setq buffer-read-only t)
2866 (org-agenda-fit-window-to-buffer)))
2868 (defun org-agenda-normalize-custom-commands (cmds)
2869 "Normalize custom commands CMDS."
2873 (cond ((stringp (cdr x)) nil)
2874 ((stringp (nth 1 x)) x)
2875 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2876 (t (cons (car x) (cons "" (cdr x))))))
2879 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2880 "The user interface for selecting an agenda command."
2882 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2883 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2884 (region-p (org-region-active-p))
2885 (custom org-agenda-custom-commands)
2887 restriction second-time
2888 c entry key type match prefixes rmheader header-end custom1 desc
2889 line lines left right n n1)
2890 (save-window-excursion
2891 (delete-other-windows)
2892 (org-switch-to-buffer-other-window " *Agenda Commands*")
2894 (insert (eval-when-compile
2896 "Press key for an agenda command: < Buffer, subtree/region restriction
2897 -------------------------------- > Remove restriction
2898 a Agenda for current week or day e Export agenda views
2899 t List of all TODO entries T Entries with special TODO kwd
2900 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2901 s Search for keywords S Like s, but only TODO entries
2902 L Timeline for current buffer # List stuck projects (!=configure)
2903 / Multi-occur C Configure custom agenda commands
2904 ? Find :FLAGGED: entries * Toggle sticky agenda views
2907 (while (string-match
2908 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2910 (setq start (match-end 0))
2911 (add-text-properties (match-beginning 2) (match-end 2)
2912 '(face bold) header))
2914 (setq header-end (point-marker))
2916 (setq custom1 custom)
2917 (when (eq rmheader t)
2919 (re-search-forward ":" nil t)
2920 (delete-region (match-end 0) (point-at-eol))
2923 (delete-region (match-end 0) (point-at-eol))
2924 (move-marker header-end (match-end 0)))
2925 (goto-char header-end)
2926 (delete-region (point) (point-max))
2928 ;; Produce all the lines that describe custom commands and prefixes
2930 (while (setq entry (pop custom1))
2931 (setq key (car entry) desc (nth 1 entry)
2933 match (nth 3 entry))
2934 (if (> (length key) 1)
2935 (add-to-list 'prefixes (string-to-char key))
2939 (org-add-props (copy-sequence key)
2942 ((string-match "\\S-" desc) desc)
2943 ((eq type 'agenda) "Agenda for current week or day")
2944 ((eq type 'agenda*) "Appointments for current week or day")
2945 ((eq type 'alltodo) "List of all TODO entries")
2946 ((eq type 'search) "Word search")
2947 ((eq type 'stuck) "List of stuck projects")
2948 ((eq type 'todo) "TODO keyword")
2949 ((eq type 'tags) "Tags query")
2950 ((eq type 'tags-todo) "Tags (TODO)")
2951 ((eq type 'tags-tree) "Tags tree")
2952 ((eq type 'todo-tree) "TODO kwd tree")
2953 ((eq type 'occur-tree) "Occur tree")
2954 ((functionp type) (if (symbolp type)
2956 "Lambda expression"))
2958 (if org-agenda-menu-show-matcher
2963 (setq match (copy-sequence match))
2964 (org-add-props match nil 'face 'org-warning))
2966 (format "set of %d commands" (length type))))))
2967 (if (org-string-nw-p match)
2968 (add-text-properties
2969 0 (length line) (list 'help-echo
2970 (concat "Matcher: " match)) line)))
2972 (setq lines (nreverse lines))
2977 (org-add-props (char-to-string x)
2979 (or (cdr (assoc (concat selstring
2981 prefix-descriptions))
2986 ;; Check if we should display in two columns
2987 (if org-agenda-menu-two-columns
2989 (setq n (length lines)
2990 n1 (+ (/ n 2) (mod n 2))
2991 right (nthcdr n1 lines)
2992 left (copy-sequence lines))
2993 (setcdr (nthcdr (1- n1) left) nil))
2994 (setq left lines right nil))
2996 (insert "\n" (pop left))
2998 (if (< (current-column) 40)
2999 (move-to-column 40 t)
3001 (insert (pop right))))
3003 ;; Make the window the right size
3004 (goto-char (point-min))
3006 (if (not (pos-visible-in-window-p (point-max)))
3007 (org-fit-window-to-buffer))
3008 (setq second-time t)
3009 (org-fit-window-to-buffer))
3011 ;; Ask for selection
3012 (message "Press key for agenda command%s:"
3013 (if (or restrict-ok org-agenda-overriding-restriction)
3014 (if org-agenda-overriding-restriction
3015 " (restriction lock active)"
3017 (format " (restricted to %s)" restriction)
3020 (setq c (read-char-exclusive))
3023 ((assoc (char-to-string c) custom)
3024 (setq selstring (concat selstring (char-to-string c)))
3025 (throw 'exit (cons selstring restriction)))
3027 (setq selstring (concat selstring (char-to-string c))
3029 rmheader (or rmheader t)
3030 custom (delq nil (mapcar
3032 (if (or (= (length (car x)) 1)
3033 (/= (string-to-char (car x)) c))
3035 (cons (substring (car x) 1) (cdr x))))
3038 (call-interactively 'org-toggle-sticky-agenda)
3040 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
3041 (message "Restriction is only possible in Org-mode buffers")
3044 (org-agenda-remove-restriction-lock 'noupdate)
3045 (setq restriction 'buffer))
3047 (org-agenda-remove-restriction-lock 'noupdate)
3048 (setq restriction (if region-p 'region 'subtree)))
3050 (org-agenda-remove-restriction-lock 'noupdate)
3053 ((eq restriction 'buffer)
3054 (if region-p 'region 'subtree))
3055 ((memq restriction '(subtree region))
3059 (org-agenda-remove-restriction-lock 'noupdate)
3060 (setq restriction nil))
3061 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
3062 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
3063 ((and (> (length selstring) 0) (eq c ?\d))
3065 (org-agenda-get-restriction-and-command prefix-descriptions))
3067 ((equal c ?q) (error "Abort"))
3068 (t (user-error "Invalid key %c" c))))))))
3070 (defun org-agenda-fit-window-to-buffer ()
3071 "Fit the window to the buffer size."
3072 (and (memq org-agenda-window-setup '(reorganize-frame))
3073 (fboundp 'fit-window-to-buffer)
3074 (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
3075 (= (car org-agenda-window-frame-fractions) 1.0))
3076 (delete-other-windows)
3077 (org-fit-window-to-buffer
3079 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3080 (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
3082 (defvar org-cmd nil)
3083 (defvar org-agenda-overriding-cmd nil)
3084 (defvar org-agenda-overriding-arguments nil)
3085 (defvar org-agenda-overriding-cmd-arguments nil)
3086 (defun org-agenda-run-series (name series)
3087 "Run agenda NAME as a SERIES of agenda commands."
3088 (org-let (nth 1 series) '(org-agenda-prepare name))
3089 ;; We need to reset agenda markers here, because when constructing a
3090 ;; block agenda, the individual blocks do not do that.
3091 (org-agenda-reset-markers)
3092 (let* ((org-agenda-multi t)
3093 (redo (list 'org-agenda-run-series name (list 'quote series)))
3095 (gprops (nth 1 series))
3096 match ;; The byte compiler incorrectly complains about this. Keep it!
3097 org-cmd type lprops)
3098 (while (setq org-cmd (pop cmds))
3099 (setq type (car org-cmd)
3100 match (eval (nth 1 org-cmd))
3101 lprops (nth 2 org-cmd))
3102 (let ((org-agenda-overriding-arguments
3103 (if (eq org-agenda-overriding-cmd org-cmd)
3104 (or org-agenda-overriding-arguments
3105 org-agenda-overriding-cmd-arguments))))
3108 (org-let2 gprops lprops
3109 '(call-interactively 'org-agenda-list)))
3111 (org-let2 gprops lprops
3112 '(funcall 'org-agenda-list nil nil t)))
3114 (org-let2 gprops lprops
3115 '(call-interactively 'org-todo-list)))
3117 (org-let2 gprops lprops
3118 '(org-search-view current-prefix-arg match nil)))
3120 (org-let2 gprops lprops
3121 '(call-interactively 'org-agenda-list-stuck-projects)))
3123 (org-let2 gprops lprops
3124 '(org-tags-view current-prefix-arg match)))
3125 ((eq type 'tags-todo)
3126 (org-let2 gprops lprops
3127 '(org-tags-view '(4) match)))
3129 (org-let2 gprops lprops
3130 '(org-todo-list match)))
3132 (org-let2 gprops lprops
3133 '(funcall type match)))
3134 (t (error "Invalid type in command series")))))
3136 (let ((inhibit-read-only t))
3137 (add-text-properties (point-min) (point-max)
3138 `(org-series t org-series-redo-cmd ,redo)))
3139 (setq org-agenda-redo-command redo)
3140 (goto-char (point-min)))
3141 (org-agenda-fit-window-to-buffer)
3142 (org-let (nth 1 series) '(org-agenda-finalize)))
3145 (defmacro org-batch-agenda (cmd-key &rest parameters)
3146 "Run an agenda command in batch mode and send the result to STDOUT.
3147 If CMD-KEY is a string of length 1, it is used as a key in
3148 `org-agenda-custom-commands' and triggers this command. If it is a
3149 longer string it is used as a tags/todo match string.
3150 Parameters are alternating variable names and values that will be bound
3151 before running the agenda command."
3152 (org-eval-in-environment (org-make-parameter-alist parameters)
3153 (let (org-agenda-sticky)
3154 (if (> (length cmd-key) 2)
3155 (org-tags-view nil cmd-key)
3156 (org-agenda nil cmd-key))))
3157 (set-buffer org-agenda-buffer-name)
3158 (princ (buffer-string)))
3160 (defvar org-agenda-info nil)
3163 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3164 "Run an agenda command in batch mode and send the result to STDOUT.
3165 If CMD-KEY is a string of length 1, it is used as a key in
3166 `org-agenda-custom-commands' and triggers this command. If it is a
3167 longer string it is used as a tags/todo match string.
3168 Parameters are alternating variable names and values that will be bound
3169 before running the agenda command.
3171 The output gives a line for each selected agenda item. Each
3172 item is a list of comma-separated values, like this:
3174 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3176 category The category of the item
3177 head The headline, without TODO kwd, TAGS and PRIORITY
3178 type The type of the agenda entry, can be
3179 todo selected in TODO match
3180 tagsmatch selected in tags match
3181 diary imported from diary
3182 deadline a deadline on given date
3183 scheduled scheduled on given date
3184 timestamp entry has timestamp on given date
3185 closed entry was closed on given date
3186 upcoming-deadline warning about deadline
3187 past-scheduled forwarded scheduled item
3188 block entry has date block including g. date
3189 todo The todo keyword, if any
3190 tags All tags including inherited ones, separated by colons
3191 date The relevant date, like 2007-2-14
3192 time The time, like 15:00-16:50
3193 extra Sting with extra planning info
3194 priority-l The priority letter if any was given
3195 priority-n The computed numerical priority
3196 agenda-day The day in the agenda where this is listed"
3197 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3198 (org-make-parameter-alist parameters))
3199 (if (> (length cmd-key) 2)
3200 (org-tags-view nil cmd-key)
3201 (org-agenda nil cmd-key)))
3202 (set-buffer org-agenda-buffer-name)
3203 (let* ((lines (org-split-string (buffer-string) "\n"))
3205 (while (setq line (pop lines))
3207 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3208 (setq org-agenda-info
3209 (org-fix-agenda-info (text-properties-at 0 line)))
3211 (mapconcat 'org-agenda-export-csv-mapper
3212 '(org-category txt type todo tags date time extra
3213 priority-letter priority agenda-day)
3217 (defun org-fix-agenda-info (props)
3218 "Make sure all properties on an agenda item have a canonical form.
3219 This ensures the export commands can easily use it."
3221 (when (setq tmp (plist-get props 'tags))
3222 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3223 (when (setq tmp (plist-get props 'date))
3224 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3225 (let ((calendar-date-display-form '(year "-" month "-" day)))
3226 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3228 (setq tmp (calendar-date-string tmp)))
3229 (setq props (plist-put props 'date tmp)))
3230 (when (setq tmp (plist-get props 'day))
3231 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3232 (let ((calendar-date-display-form '(year "-" month "-" day)))
3233 (setq tmp (calendar-date-string tmp)))
3234 (setq props (plist-put props 'day tmp))
3235 (setq props (plist-put props 'agenda-day tmp)))
3236 (when (setq tmp (plist-get props 'txt))
3237 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3238 (plist-put props 'priority-letter (match-string 1 tmp))
3239 (setq tmp (replace-match "" t t tmp)))
3240 (when (and (setq re (plist-get props 'org-todo-regexp))
3241 (setq re (concat "\\`\\.*" re " ?"))
3242 (string-match re tmp))
3243 (plist-put props 'todo (match-string 1 tmp))
3244 (setq tmp (replace-match "" t t tmp)))
3245 (plist-put props 'txt tmp)))
3248 (defun org-agenda-export-csv-mapper (prop)
3249 (let ((res (plist-get org-agenda-info prop)))
3254 (t (prin1-to-string res))))
3255 (while (string-match "," res)
3256 (setq res (replace-match ";" t t res)))
3260 (defun org-store-agenda-views (&rest parameters)
3261 "Store agenda views."
3263 (eval (list 'org-batch-store-agenda-views)))
3266 (defmacro org-batch-store-agenda-views (&rest parameters)
3267 "Run all custom agenda commands that have a file argument."
3268 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3270 (dir default-directory)
3271 (pars (org-make-parameter-alist parameters))
3272 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3273 (save-window-excursion
3275 (setq cmd (pop cmds)
3276 thiscmdkey (car cmd)
3277 thiscmdcmd (cdr cmd)
3278 match (nth 2 thiscmdcmd)
3279 bufname (if org-agenda-sticky
3280 (or (and (stringp match)
3281 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3282 (format "*Org Agenda(%s)*" thiscmdkey))
3283 org-agenda-buffer-name)
3284 cmd-or-set (nth 2 cmd)
3285 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3286 files (nth (if (listp cmd-or-set) 4 5) cmd))
3287 (if (stringp files) (setq files (list files)))
3289 (org-eval-in-environment (append org-agenda-exporter-settings
3291 (org-agenda nil thiscmdkey))
3292 (set-buffer bufname)
3294 (org-eval-in-environment (append org-agenda-exporter-settings
3296 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3297 (and (get-buffer bufname)
3298 (kill-buffer bufname)))))))
3300 (defvar org-agenda-current-span nil
3301 "The current span used in the agenda view.") ; local variable in the agenda buffer
3302 (defun org-agenda-mark-header-line (pos)
3303 "Mark the line at POS as an agenda structure header."
3306 (put-text-property (point-at-bol) (point-at-eol)
3307 'org-agenda-structural-header t)
3308 (when org-agenda-title-append
3309 (put-text-property (point-at-bol) (point-at-eol)
3310 'org-agenda-title-append org-agenda-title-append))))
3312 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3313 (defvar org-agenda-write-buffer-name "Agenda View")
3314 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3315 "Write the current buffer (an agenda view) as a file.
3317 Depending on the extension of the file name, plain text (.txt),
3318 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3319 If the extension is .ics, translate visible agenda into iCalendar
3320 format. If the extension is .org, collect all subtrees
3321 corresponding to the agenda entries and add them in an .org file.
3323 With prefix argument OPEN, open the new file immediately. If
3324 NOSETTINGS is given, do not scope the settings of
3325 `org-agenda-exporter-settings' into the export commands. This is
3326 used when the settings have already been scoped and we do not
3327 wish to overrule other, higher priority settings. If
3328 AGENDA-BUFFER-NAME is provided, use this as the buffer name for
3329 the agenda to write."
3330 (interactive "FWrite agenda to file: \nP")
3331 (if (or (not (file-writable-p file))
3332 (and (file-exists-p file)
3333 (if (org-called-interactively-p 'any)
3334 (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
3335 (user-error "Cannot write agenda to file %s" file))
3336 (org-let (if nosettings nil org-agenda-exporter-settings)
3338 (save-window-excursion
3339 (let ((bs (copy-sequence (buffer-string))) beg content)
3341 (rename-buffer org-agenda-write-buffer-name t)
3342 (set-buffer-modified-p nil)
3344 (org-agenda-remove-marked-text 'org-filtered)
3345 (run-hooks 'org-agenda-before-write-hook)
3347 ((org-bound-and-true-p org-mobile-creating-agendas)
3348 (org-mobile-write-agenda-for-mobile file))
3349 ((string-match "\\.org\\'" file)
3350 (let (content p m message-log-max)
3351 (goto-char (point-min))
3352 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3354 (setq m (get-text-property (point) 'org-hd-marker))
3356 (push (save-excursion
3357 (set-buffer (marker-buffer m))
3359 (org-copy-subtree 1 nil t t)
3364 (dolist (s content) (org-paste-subtree 1 s))
3366 (kill-buffer (current-buffer))
3367 (message "Org file written to %s" file)))
3368 ((string-match "\\.html?\\'" file)
3370 (set-buffer (htmlize-buffer (current-buffer)))
3371 (when org-agenda-export-html-style
3372 ;; replace <style> section with org-agenda-export-html-style
3373 (goto-char (point-min))
3374 (kill-region (- (search-forward "<style") 6)
3375 (search-forward "</style>"))
3376 (insert org-agenda-export-html-style))
3378 (kill-buffer (current-buffer))
3379 (message "HTML written to %s" file))
3380 ((string-match "\\.ps\\'" file)
3382 (ps-print-buffer-with-faces file)
3383 (message "Postscript written to %s" file))
3384 ((string-match "\\.pdf\\'" file)
3386 (ps-print-buffer-with-faces
3387 (concat (file-name-sans-extension file) ".ps"))
3388 (call-process "ps2pdf" nil nil nil
3390 (concat (file-name-sans-extension file) ".ps"))
3391 (expand-file-name file))
3392 (delete-file (concat (file-name-sans-extension file) ".ps"))
3393 (message "PDF written to %s" file))
3394 ((string-match "\\.ics\\'" file)
3395 (require 'ox-icalendar)
3396 (org-icalendar-export-current-agenda (expand-file-name file)))
3398 (let ((bs (buffer-string)))
3403 (kill-buffer (current-buffer))
3404 (message "Plain text written to %s" file))))))))
3405 (set-buffer (or agenda-bufname
3406 (and (org-called-interactively-p 'any) (buffer-name))
3407 org-agenda-buffer-name)))
3408 (when open (org-open-file file)))
3410 (defun org-agenda-remove-marked-text (property &optional value)
3411 "Delete all text marked with VALUE of PROPERTY.
3412 VALUE defaults to t."
3414 (setq value (or value t))
3415 (while (setq beg (text-property-any (point-min) (point-max)
3418 beg (or (next-single-property-change beg property)
3421 (defun org-agenda-add-entry-text ()
3422 "Add entry text to agenda lines.
3423 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3424 entry text following headings shown in the agenda.
3425 Drawers will be excluded, also the line with scheduling/deadline info."
3426 (when (and (> org-agenda-add-entry-text-maxlines 0)
3427 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3429 (goto-char (point-min))
3431 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3432 (beginning-of-line 2)
3433 (setq txt (org-agenda-get-some-entry-text
3434 m org-agenda-add-entry-text-maxlines " > "))
3436 (if (string-match "\\S-" txt)
3438 (or (eobp) (forward-char 1))))))))
3440 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3442 "Extract entry text from MARKER, at most N-LINES lines.
3443 This will ignore drawers etc, just get the text.
3444 If INDENT is given, prefix every line with this string. If KEEP is
3445 given, it is a list of symbols, defining stuff that should not be
3446 removed from the entry content. Currently only `planning' is allowed here."
3447 (let (txt drawer-re kwd-time-re ind)
3449 (with-current-buffer (marker-buffer marker)
3450 (if (not (derived-mode-p 'org-mode))
3457 (setq txt (buffer-substring
3458 (min (1+ (point)) (point-max))
3459 (progn (outline-next-heading) (point)))
3460 drawer-re org-drawer-regexp
3461 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3465 (when org-agenda-add-entry-text-descriptive-links
3466 (goto-char (point-min))
3467 (while (org-activate-bracket-links (point-max))
3468 (add-text-properties (match-beginning 0) (match-end 0)
3470 (goto-char (point-min))
3471 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3472 (set-text-properties (match-beginning 0) (match-end 0)
3474 (goto-char (point-min))
3475 (while (re-search-forward drawer-re nil t)
3478 (progn (re-search-forward
3479 "^[ \t]*:END:.*\n?" nil 'move)
3481 (unless (member 'planning keep)
3482 (goto-char (point-min))
3483 (while (re-search-forward kwd-time-re nil t)
3484 (replace-match "")))
3485 (goto-char (point-min))
3486 (when org-agenda-entry-text-exclude-regexps
3487 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3488 (while (setq re (pop re-list))
3489 (goto-char (point-min))
3490 (while (re-search-forward re nil t)
3491 (replace-match "")))))
3492 (goto-char (point-max))
3493 (skip-chars-backward " \t\n")
3494 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3496 ;; find and remove min common indentation
3497 (goto-char (point-min))
3498 (untabify (point-min) (point-max))
3499 (setq ind (org-get-indentation))
3501 (unless (looking-at "[ \t]*$")
3502 (setq ind (min ind (org-get-indentation))))
3503 (beginning-of-line 2))
3504 (goto-char (point-min))
3506 (unless (looking-at "[ \t]*$")
3507 (move-to-column ind)
3508 (delete-region (point-at-bol) (point)))
3509 (beginning-of-line 2))
3511 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3513 (goto-char (point-min))
3515 (while (and (not (eobp)) (re-search-forward "^" nil t))
3516 (replace-match indent t t)))
3517 (goto-char (point-min))
3518 (while (looking-at "[ \t]*\n") (replace-match ""))
3519 (goto-char (point-max))
3520 (when (> (org-current-line)
3522 (org-goto-line (1+ n-lines))
3524 (setq txt (buffer-substring (point-min) (point)))))))))
3527 (defun org-check-for-org-mode ()
3528 "Make sure current buffer is in org-mode. Error if not."
3529 (or (derived-mode-p 'org-mode)
3530 (error "Cannot execute org-mode agenda command on buffer in %s"
3533 ;;; Agenda prepare and finalize
3535 (defvar org-agenda-multi nil) ; dynamically scoped
3536 (defvar org-agenda-pre-window-conf nil)
3537 (defvar org-agenda-columns-active nil)
3538 (defvar org-agenda-name nil)
3539 (defvar org-agenda-tag-filter nil)
3540 (defvar org-agenda-category-filter nil)
3541 (defvar org-agenda-regexp-filter nil)
3542 (defvar org-agenda-effort-filter nil)
3543 (defvar org-agenda-top-headline-filter nil)
3544 (defvar org-agenda-tag-filter-preset nil
3545 "A preset of the tags filter used for secondary agenda filtering.
3546 This must be a list of strings, each string must be a single tag preceded
3548 This variable should not be set directly, but agenda custom commands can
3549 bind it in the options section. The preset filter is a global property of
3550 the entire agenda view. In a block agenda, it will not work reliably to
3551 define a filter for one of the individual blocks. You need to set it in
3552 the global options and expect it to be applied to the entire view.")
3554 (defvar org-agenda-category-filter-preset nil
3555 "A preset of the category filter used for secondary agenda filtering.
3556 This must be a list of strings, each string must be a single category
3557 preceded by \"+\" or \"-\".
3558 This variable should not be set directly, but agenda custom commands can
3559 bind it in the options section. The preset filter is a global property of
3560 the entire agenda view. In a block agenda, it will not work reliably to
3561 define a filter for one of the individual blocks. You need to set it in
3562 the global options and expect it to be applied to the entire view.")
3564 (defvar org-agenda-regexp-filter-preset nil
3565 "A preset of the regexp filter used for secondary agenda filtering.
3566 This must be a list of strings, each string must be a single regexp
3567 preceded by \"+\" or \"-\".
3568 This variable should not be set directly, but agenda custom commands can
3569 bind it in the options section. The preset filter is a global property of
3570 the entire agenda view. In a block agenda, it will not work reliably to
3571 define a filter for one of the individual blocks. You need to set it in
3572 the global options and expect it to be applied to the entire view.")
3574 (defvar org-agenda-effort-filter-preset nil
3575 "A preset of the effort condition used for secondary agenda filtering.
3576 This must be a list of strings, each string must be a single regexp
3577 preceded by \"+\" or \"-\".
3578 This variable should not be set directly, but agenda custom commands can
3579 bind it in the options section. The preset filter is a global property of
3580 the entire agenda view. In a block agenda, it will not work reliably to
3581 define a filter for one of the individual blocks. You need to set it in
3582 the global options and expect it to be applied to the entire view.")
3584 (defun org-agenda-use-sticky-p ()
3585 "Return non-nil if an agenda buffer named
3586 `org-agenda-buffer-name' exists and should be shown instead of
3587 generating a new one."
3589 ;; turned off by user
3591 ;; For multi-agenda buffer already exists
3592 (not org-agenda-multi)
3594 (get-buffer org-agenda-buffer-name)
3595 ;; C-u parameter is same as last call
3596 (with-current-buffer (get-buffer org-agenda-buffer-name)
3598 (equal current-prefix-arg
3599 org-agenda-last-prefix-arg)
3600 ;; In case user turned stickiness on, while having existing
3601 ;; Agenda buffer active, don't reuse that buffer, because it
3602 ;; does not have org variables local
3603 org-agenda-this-buffer-is-sticky))))
3605 (defun org-agenda-prepare-window (abuf filter-alist)
3606 "Setup agenda buffer in the window.
3607 ABUF is the buffer for the agenda window.
3608 FILTER-ALIST is an alist of filters we need to apply when
3609 `org-agenda-persistent-filter' is non-nil."
3610 (let* ((awin (get-buffer-window abuf)) wconf)
3612 ((equal (current-buffer) abuf) nil)
3613 (awin (select-window awin))
3614 ((not (setq wconf (current-window-configuration))))
3615 ((equal org-agenda-window-setup 'current-window)
3616 (org-pop-to-buffer-same-window abuf))
3617 ((equal org-agenda-window-setup 'other-window)
3618 (org-switch-to-buffer-other-window abuf))
3619 ((equal org-agenda-window-setup 'other-frame)
3620 (switch-to-buffer-other-frame abuf))
3621 ((equal org-agenda-window-setup 'reorganize-frame)
3622 (delete-other-windows)
3623 (org-switch-to-buffer-other-window abuf)))
3624 (setq org-agenda-tag-filter (cdr (assoc 'tag filter-alist)))
3625 (setq org-agenda-category-filter (cdr (assoc 'cat filter-alist)))
3626 (setq org-agenda-effort-filter (cdr (assoc 'effort filter-alist)))
3627 (setq org-agenda-regexp-filter (cdr (assoc 're filter-alist)))
3628 ;; Additional test in case agenda is invoked from within agenda
3629 ;; buffer via elisp link.
3630 (unless (equal (current-buffer) abuf)
3631 (org-pop-to-buffer-same-window abuf))
3632 (setq org-agenda-pre-window-conf
3633 (or org-agenda-pre-window-conf wconf))))
3635 (defun org-agenda-prepare (&optional name)
3636 (let ((filter-alist (if org-agenda-persistent-filter
3637 (list `(tag . ,org-agenda-tag-filter)
3638 `(re . ,org-agenda-regexp-filter)
3639 `(effort . ,org-agenda-effort-filter)
3640 `(car . ,org-agenda-category-filter)))))
3641 (if (org-agenda-use-sticky-p)
3643 (put 'org-agenda-tag-filter :preset-filter nil)
3644 (put 'org-agenda-category-filter :preset-filter nil)
3645 (put 'org-agenda-regexp-filter :preset-filter nil)
3646 ;; Popup existing buffer
3647 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
3649 (message "Sticky Agenda buffer, use `r' to refresh")
3650 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3651 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3652 (setq org-todo-keywords-for-agenda nil)
3653 (put 'org-agenda-tag-filter :preset-filter
3654 org-agenda-tag-filter-preset)
3655 (put 'org-agenda-category-filter :preset-filter
3656 org-agenda-category-filter-preset)
3657 (put 'org-agenda-regexp-filter :preset-filter
3658 org-agenda-regexp-filter-preset)
3659 (put 'org-agenda-effort-filter :preset-filter
3660 org-agenda-effort-filter-preset)
3661 (if org-agenda-multi
3663 (setq buffer-read-only nil)
3664 (goto-char (point-max))
3665 (unless (or (bobp) org-agenda-compact-blocks
3666 (not org-agenda-block-separator))
3668 (if (stringp org-agenda-block-separator)
3669 org-agenda-block-separator
3670 (make-string (window-width) org-agenda-block-separator))
3672 (narrow-to-region (point) (point-max)))
3673 (setq org-done-keywords-for-agenda nil)
3674 ;; Setting any org variables that are in org-agenda-local-vars
3675 ;; list need to be done after the prepare call
3676 (org-agenda-prepare-window
3677 (get-buffer-create org-agenda-buffer-name) filter-alist)
3678 (setq buffer-read-only nil)
3679 (org-agenda-reset-markers)
3680 (let ((inhibit-read-only t)) (erase-buffer))
3682 (setq org-agenda-buffer (current-buffer))
3683 (setq org-agenda-contributing-files nil)
3684 (setq org-agenda-columns-active nil)
3685 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3686 (setq org-todo-keywords-for-agenda
3687 (org-uniquify org-todo-keywords-for-agenda))
3688 (setq org-done-keywords-for-agenda
3689 (org-uniquify org-done-keywords-for-agenda))
3690 (setq org-agenda-last-prefix-arg current-prefix-arg)
3691 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3692 (and name (not org-agenda-name)
3693 (org-set-local 'org-agenda-name name)))
3694 (setq buffer-read-only nil))))
3696 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3697 (defun org-agenda-finalize ()
3698 "Finishing touch for the agenda buffer, called just before displaying it."
3699 (unless org-agenda-multi
3701 (let ((inhibit-read-only t))
3702 (goto-char (point-min))
3704 (while (org-activate-bracket-links (point-max))
3705 (add-text-properties (match-beginning 0) (match-end 0)
3708 (while (org-activate-plain-links (point-max))
3709 (add-text-properties (match-beginning 0) (match-end 0)
3711 (unless (eq org-agenda-remove-tags t)
3712 (org-agenda-align-tags))
3713 (unless org-agenda-with-colors
3714 (remove-text-properties (point-min) (point-max) '(face nil)))
3715 (if (and (boundp 'org-agenda-overriding-columns-format)
3716 org-agenda-overriding-columns-format)
3717 (org-set-local 'org-agenda-overriding-columns-format
3718 org-agenda-overriding-columns-format))
3719 (if (and (boundp 'org-agenda-view-columns-initially)
3720 org-agenda-view-columns-initially)
3721 (org-agenda-columns))
3722 (when org-agenda-fontify-priorities
3723 (org-agenda-fontify-priorities))
3724 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3725 (org-agenda-dim-blocked-tasks))
3726 (org-agenda-mark-clocking-task)
3727 (when org-agenda-entry-text-mode
3728 (org-agenda-entry-text-hide)
3729 (org-agenda-entry-text-show))
3730 (if (and (functionp 'org-habit-insert-consistency-graphs)
3731 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3732 (org-habit-insert-consistency-graphs))
3733 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3734 (unless (or (eq org-agenda-show-inherited-tags 'always)
3735 (and (listp org-agenda-show-inherited-tags)
3736 (memq org-agenda-type org-agenda-show-inherited-tags))
3737 (and (eq org-agenda-show-inherited-tags t)
3738 (or (eq org-agenda-use-tag-inheritance t)
3739 (and (listp org-agenda-use-tag-inheritance)
3740 (not (memq org-agenda-type
3741 org-agenda-use-tag-inheritance))))))
3744 (goto-char (point-min))
3745 (while (equal (forward-line) 0)
3746 (when (setq mrk (get-text-property (point) 'org-hd-marker))
3747 (put-text-property (point-at-bol) (point-at-eol)
3748 'tags (org-with-point-at mrk
3750 (mapcar 'downcase (org-get-tags-at))))))))))
3751 (run-hooks 'org-agenda-finalize-hook)
3752 (when org-agenda-top-headline-filter
3753 (org-agenda-filter-top-headline-apply
3754 org-agenda-top-headline-filter))
3755 (when org-agenda-tag-filter
3756 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3757 (when (get 'org-agenda-tag-filter :preset-filter)
3758 (org-agenda-filter-apply
3759 (get 'org-agenda-tag-filter :preset-filter) 'tag))
3760 (when org-agenda-category-filter
3761 (org-agenda-filter-apply org-agenda-category-filter 'category))
3762 (when (get 'org-agenda-category-filter :preset-filter)
3763 (org-agenda-filter-apply
3764 (get 'org-agenda-category-filter :preset-filter) 'category))
3765 (when org-agenda-regexp-filter
3766 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
3767 (when (get 'org-agenda-regexp-filter :preset-filter)
3768 (org-agenda-filter-apply
3769 (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
3770 (when org-agenda-effort-filter
3771 (org-agenda-filter-apply org-agenda-effort-filter 'effort))
3772 (when (get 'org-agenda-effort-filter :preset-filter)
3773 (org-agenda-filter-apply
3774 (get 'org-agenda-effort-filter :preset-filter) 'effort))
3775 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3777 (defun org-agenda-mark-clocking-task ()
3778 "Mark the current clock entry in the agenda if it is present."
3779 ;; We need to widen when `org-agenda-finalize' is called from
3780 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3781 (when org-clock-current-task
3784 (org-agenda-unmark-clocking-task)
3785 (when (marker-buffer org-clock-hd-marker)
3787 (goto-char (point-min))
3789 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3791 (when (equal (org-get-at-bol 'org-hd-marker)
3792 org-clock-hd-marker)
3793 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3794 (overlay-put ov 'type 'org-agenda-clocking)
3795 (overlay-put ov 'face 'org-agenda-clocking)
3796 (overlay-put ov 'help-echo
3797 "The clock is running in this item")))))))))
3799 (defun org-agenda-unmark-clocking-task ()
3800 "Unmark the current clocking task."
3802 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3803 (delete-overlay o)))
3804 (overlays-in (point-min) (point-max))))
3806 (defun org-agenda-fontify-priorities ()
3807 "Make highest priority lines bold, and lowest italic."
3809 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3810 (delete-overlay o)))
3811 (overlays-in (point-min) (point-max)))
3814 (goto-char (point-min))
3815 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3816 (setq h (or (get-char-property (point) 'org-highest-priority)
3817 org-highest-priority)
3818 l (or (get-char-property (point) 'org-lowest-priority)
3819 org-lowest-priority)
3820 p (string-to-char (match-string 1))
3821 b (match-beginning 0)
3822 e (if (eq org-agenda-fontify-priorities 'cookies)
3825 ov (make-overlay b e))
3828 (cons (cond ((org-face-from-face-or-color
3830 (cdr (assoc p org-priority-faces))))
3831 ((and (listp org-agenda-fontify-priorities)
3832 (org-face-from-face-or-color
3834 (cdr (assoc p org-agenda-fontify-priorities)))))
3835 ((equal p l) 'italic)
3836 ((equal p h) 'bold))
3838 (overlay-put ov 'org-type 'org-priority)))))
3840 (defvar org-depend-tag-blocked)
3842 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3843 "Dim currently blocked TODO's in the agenda display.
3844 When INVISIBLE is non-nil, hide currently blocked TODO instead of
3847 (when (org-called-interactively-p 'interactive)
3848 (message "Dim or hide blocked tasks..."))
3849 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3850 (delete-overlay o)))
3851 (overlays-in (point-min) (point-max)))
3853 (let ((inhibit-read-only t)
3854 (org-depend-tag-blocked nil)
3855 (invis (or (not (null invisible))
3856 (eq org-agenda-dim-blocked-tasks 'invisible)))
3857 org-blocked-by-checkboxes
3858 invis1 b e p ov h l)
3859 (goto-char (point-min))
3860 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3861 (and pos (goto-char (1+ pos))))
3862 (setq org-blocked-by-checkboxes nil invis1 invis)
3863 (let ((marker (org-get-at-bol 'org-hd-marker)))
3865 (with-current-buffer (marker-buffer marker)
3866 (save-excursion (goto-char marker)
3867 (org-entry-blocked-p))))
3868 (if org-blocked-by-checkboxes (setq invis1 nil))
3870 (max (point-min) (1- (point-at-bol)))
3873 ov (make-overlay b e))
3875 (progn (overlay-put ov 'invisible t)
3876 (overlay-put ov 'intangible t))
3877 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3878 (overlay-put ov 'org-type 'org-blocked-todo))))))
3879 (when (org-called-interactively-p 'interactive)
3880 (message "Dim or hide blocked tasks...done")))
3882 (defvar org-agenda-skip-function nil
3883 "Function to be called at each match during agenda construction.
3884 If this function returns nil, the current match should not be skipped.
3885 Otherwise, the function must return a position from where the search
3886 should be continued.
3887 This may also be a Lisp form, it will be evaluated.
3888 Never set this variable using `setq' or so, because then it will apply
3889 to all future agenda commands. If you do want a global skipping condition,
3890 use the option `org-agenda-skip-function-global' instead.
3891 The correct usage for `org-agenda-skip-function' is to bind it with
3892 `let' to scope it dynamically into the agenda-constructing command.
3893 A good way to set it is through options in `org-agenda-custom-commands'.")
3895 (defun org-agenda-skip ()
3896 "Throw to `:skip' in places that should be skipped.
3897 Also moves point to the end of the skipped region, so that search can
3898 continue from there."
3899 (let ((p (point-at-bol)) to)
3901 (save-excursion (goto-char p) (looking-at comment-start-skip))
3902 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3903 (get-text-property p :org-archived)
3904 (org-end-of-subtree t))
3905 (and org-agenda-skip-comment-trees
3906 (get-text-property p :org-comment)
3907 (org-end-of-subtree t))
3908 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3909 (org-agenda-skip-eval org-agenda-skip-function)))
3911 (org-in-src-block-p t))
3914 (defun org-agenda-skip-eval (form)
3915 "If FORM is a function or a list, call (or eval) it and return the result.
3916 `save-excursion' and `save-match-data' are wrapped around the call, so point
3917 and match data are returned to the previous state no matter what these
3921 (or (setq fp (functionp form))
3929 (defvar org-agenda-markers nil
3930 "List of all currently active markers created by `org-agenda'.")
3931 (defvar org-agenda-last-marker-time (org-float-time)
3932 "Creation time of the last agenda marker.")
3934 (defun org-agenda-new-marker (&optional pos)
3935 "Return a new agenda marker.
3936 Org-mode keeps a list of these markers and resets them when they are
3938 (let ((m (copy-marker (or pos (point)))))
3939 (setq org-agenda-last-marker-time (org-float-time))
3940 (if org-agenda-buffer
3941 (with-current-buffer org-agenda-buffer
3942 (push m org-agenda-markers))
3943 (push m org-agenda-markers))
3946 (defun org-agenda-reset-markers ()
3947 "Reset markers created by `org-agenda'."
3948 (while org-agenda-markers
3949 (move-marker (pop org-agenda-markers) nil)))
3951 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3952 "Save relative positions of markers in region.
3953 This check for agenda markers in all agenda buffers currently active."
3954 (dolist (buf (buffer-list))
3955 (with-current-buffer buf
3956 (when (eq major-mode 'org-agenda-mode)
3957 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3958 org-agenda-markers)))))
3962 (defun org-agenda-entry-text-show-here ()
3963 "Add some text from the entry as context to the current line."
3965 (setq m (org-get-at-bol 'org-hd-marker))
3966 (unless (marker-buffer m)
3967 (error "No marker points to an entry here"))
3968 (setq txt (concat "\n" (org-no-properties
3969 (org-agenda-get-some-entry-text
3970 m org-agenda-entry-text-maxlines
3971 org-agenda-entry-text-leaders))))
3972 (when (string-match "\\S-" txt)
3973 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3974 (overlay-put o 'evaporate t)
3975 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3976 (overlay-put o 'after-string txt))))
3978 (defun org-agenda-entry-text-show ()
3979 "Add entry context for all agenda lines."
3982 (goto-char (point-max))
3983 (beginning-of-line 1)
3985 (when (org-get-at-bol 'org-hd-marker)
3986 (org-agenda-entry-text-show-here))
3987 (beginning-of-line 0))))
3989 (defun org-agenda-entry-text-hide ()
3990 "Remove any shown entry context."
3993 (if (eq (overlay-get o 'org-overlay-type)
3994 'agenda-entry-content)
3995 (progn (delete-overlay o) t)))
3996 (overlays-in (point-min) (point-max)))))
3998 (defun org-agenda-get-day-face (date)
3999 "Return the face DATE should be displayed with."
4000 (or (and (functionp org-agenda-day-face-function)
4001 (funcall org-agenda-day-face-function date))
4002 (cond ((org-agenda-todayp date)
4003 'org-agenda-date-today)
4004 ((member (calendar-day-of-week date) org-agenda-weekend-days)
4005 'org-agenda-date-weekend)
4006 (t 'org-agenda-date))))
4010 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
4011 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
4013 (defun org-timeline (&optional dotodo)
4014 "Show a time-sorted view of the entries in the current org file.
4015 Only entries with a time stamp of today or later will be listed. With
4016 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
4017 under the current date.
4018 If the buffer contains an active region, only check the region for
4022 (org-agenda-show-log-scoped org-agenda-show-log)
4023 (org-agenda-show-log org-agenda-show-log-scoped)
4024 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
4026 (date (calendar-current-date))
4027 (beg (if (org-region-active-p) (region-beginning) (point-min)))
4028 (end (if (org-region-active-p) (region-end) (point-max)))
4029 (day-numbers (org-get-all-dates
4031 t org-agenda-show-log-scoped ; always include today
4032 org-timeline-show-empty-dates))
4033 (org-deadline-warning-days 0)
4034 (org-agenda-only-exact-dates t)
4039 (setq org-agenda-redo-command
4041 (list (list 'org-agenda-show-log 'org-agenda-show-log))
4042 (list 'org-switch-to-buffer-other-window (current-buffer))
4043 (list 'org-timeline (list 'quote dotodo))))
4044 (put 'org-agenda-redo-command 'org-lprops nil)
4046 ;; Remove past dates from the list of dates.
4047 (setq day-numbers (delq nil (mapcar (lambda(x)
4048 (if (>= x today) x nil))
4050 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
4051 (org-compile-prefix-format 'timeline)
4052 (org-set-sorting-strategy 'timeline)
4053 (if org-agenda-show-log-scoped (push :closed args))
4054 (push :timestamp args)
4055 (push :deadline args)
4056 (push :scheduled args)
4058 (if dotodo (push :todo args))
4059 (insert "Timeline of file " entry "\n")
4060 (add-text-properties (point-min) (point)
4061 (list 'face 'org-agenda-structure))
4062 (org-agenda-mark-header-line (point-min))
4063 (while (setq d (pop day-numbers))
4064 (if (and (listp d) (eq (car d) :omitted))
4067 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
4068 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
4069 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
4070 (if (and (>= d today)
4075 (insert (make-string 79 ?-) "\n")))
4076 (setq date (calendar-gregorian-from-absolute d))
4078 (setq rtn (and (not emptyp)
4079 (apply 'org-agenda-get-day-entries entry
4081 (if (or rtn (equal d today) org-timeline-show-empty-dates)
4084 (if (stringp org-agenda-format-date)
4085 (format-time-string org-agenda-format-date
4086 (org-time-from-absolute date))
4087 (funcall org-agenda-format-date date))
4089 (put-text-property s (1- (point)) 'face
4090 (org-agenda-get-day-face date))
4091 (put-text-property s (1- (point)) 'org-date-line t)
4092 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4094 (put-text-property s (1- (point)) 'org-today t))
4095 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
4096 (put-text-property s (1- (point)) 'day d)))))
4097 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
4099 (add-text-properties
4100 (point-min) (point-max)
4101 `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
4102 (org-agenda-finalize)
4103 (setq buffer-read-only t)))
4105 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
4106 "Return a list of all relevant day numbers from BEG to END buffer positions.
4107 If NO-RANGES is non-nil, include only the start and end dates of a range,
4108 not every single day in the range. If FORCE-TODAY is non-nil, make
4109 sure that TODAY is included in the list. If INACTIVE is non-nil, also
4110 inactive time stamps (those in square brackets) are included.
4111 When EMPTY is non-nil, also include days without any entries."
4113 (if pre-re pre-re "")
4114 (if inactive org-ts-regexp-both org-ts-regexp)))
4115 dates dates1 date day day1 day2 ts1 ts2 pos)
4117 (setq dates (list (org-today))))
4120 (while (re-search-forward re end t)
4121 (setq day (time-to-days (org-time-string-to-time
4122 (substring (match-string 1) 0 10)
4123 (current-buffer) (match-beginning 0))))
4124 (or (memq day dates) (push day dates)))
4127 (while (re-search-forward org-tr-regexp end t)
4128 (setq pos (match-beginning 0))
4129 (setq ts1 (substring (match-string 1) 0 10)
4130 ts2 (substring (match-string 2) 0 10)
4131 day1 (time-to-days (org-time-string-to-time
4132 ts1 (current-buffer) pos))
4133 day2 (time-to-days (org-time-string-to-time
4134 ts2 (current-buffer) pos)))
4135 (while (< (setq day1 (1+ day1)) day2)
4136 (or (memq day1 dates) (push day1 dates)))))
4137 (setq dates (sort dates '<))
4139 (while (setq day (pop dates))
4140 (setq day2 (car dates))
4142 (when (and day2 empty)
4143 (if (or (eq empty t)
4144 (and (numberp empty) (<= (- day2 day) empty)))
4145 (while (< (setq day (1+ day)) day2)
4146 (push (list day) dates1))
4147 (push (cons :omitted (- day2 day)) dates1))))
4148 (setq dates (nreverse dates1)))
4151 ;;; Agenda Daily/Weekly
4153 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4154 "Start day for the agenda view.
4155 Custom commands can set this variable in the options section.
4156 This is usually a string like \"2007-11-01\", \"+2d\" or any other
4157 input allowed when reading a date through the Org calendar.
4158 See the docstring of `org-read-date' for details.")
4159 (defvar org-starting-day nil) ; local variable in the agenda buffer
4160 (defvar org-arg-loc nil) ; local variable
4162 (defvar org-agenda-buffer-tmp-name nil)
4164 (defun org-agenda-list (&optional arg start-day span with-hour)
4165 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4166 The view will be for the current day or week, but from the overview buffer
4167 you will be able to go to other days/weeks.
4169 With a numeric prefix argument in an interactive call, the agenda will
4170 span ARG days. Lisp programs should instead specify SPAN to change
4171 the number of days. SPAN defaults to `org-agenda-span'.
4173 START-DAY defaults to TODAY, or to the most recent match for the weekday
4174 given in `org-agenda-start-on-weekday'.
4176 When WITH-HOUR is non-nil, only include scheduled and deadline
4177 items if they have an hour specification like [h]h:mm."
4179 (if org-agenda-overriding-arguments
4180 (setq arg (car org-agenda-overriding-arguments)
4181 start-day (nth 1 org-agenda-overriding-arguments)
4182 span (nth 2 org-agenda-overriding-arguments)))
4183 (if (and (integerp arg) (> arg 0))
4184 (setq span arg arg nil))
4186 (setq org-agenda-buffer-name
4187 (or org-agenda-buffer-tmp-name
4188 (if org-agenda-sticky
4189 (cond ((and org-keys (stringp org-match))
4190 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4192 (format "*Org Agenda(%s)*" org-keys))
4193 (t "*Org Agenda(a)*")))
4194 org-agenda-buffer-name))
4195 (org-agenda-prepare "Day/Week")
4196 (setq start-day (or start-day org-agenda-start-day))
4197 (if (stringp start-day)
4198 ;; Convert to an absolute day number
4199 (setq start-day (time-to-days (org-read-date nil t start-day))))
4200 (org-compile-prefix-format 'agenda)
4201 (org-set-sorting-strategy 'agenda)
4202 (let* ((span (org-agenda-ndays-to-span
4203 (or span org-agenda-ndays org-agenda-span)))
4205 (sd (or start-day today))
4206 (ndays (org-agenda-span-to-ndays span sd))
4207 (org-agenda-start-on-weekday
4208 (if (or (eq ndays 7) (eq ndays 14))
4209 org-agenda-start-on-weekday))
4210 (thefiles (org-agenda-files nil 'ifmode))
4212 (start (if (or (null org-agenda-start-on-weekday)
4215 (let* ((nt (calendar-day-of-week
4216 (calendar-gregorian-from-absolute sd)))
4217 (n1 org-agenda-start-on-weekday)
4219 (- sd (+ (if (< d 0) 7 0) d)))))
4220 (day-numbers (list start))
4222 (inhibit-redisplay (not debug-on-error))
4223 (org-agenda-show-log-scoped org-agenda-show-log)
4224 s e rtn rtnall file date d start-pos end-pos todayp
4225 clocktable-start clocktable-end filter)
4226 (setq org-agenda-redo-command
4227 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
4228 (dotimes (n (1- ndays))
4229 (push (1+ (car day-numbers)) day-numbers))
4230 (setq day-numbers (nreverse day-numbers))
4231 (setq clocktable-start (car day-numbers)
4232 clocktable-end (1+ (or (org-last day-numbers) 0)))
4233 (org-set-local 'org-starting-day (car day-numbers))
4234 (org-set-local 'org-arg-loc arg)
4235 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4236 (unless org-agenda-compact-blocks
4237 (let* ((d1 (car day-numbers))
4238 (d2 (org-last day-numbers))
4239 (w1 (org-days-to-iso-week d1))
4240 (w2 (org-days-to-iso-week d2)))
4242 (if org-agenda-overriding-header
4243 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4244 nil 'face 'org-agenda-structure) "\n")
4245 (insert (org-agenda-span-name span)
4247 (if (< (- d2 d1) 350)
4249 (format " (W%02d)" w1)
4250 (format " (W%02d-W%02d)" w1 w2))
4253 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4255 (org-agenda-mark-header-line s))
4256 (while (setq d (pop day-numbers))
4257 (setq date (calendar-gregorian-from-absolute d)
4259 (if (or (setq todayp (= d today))
4260 (and (not start-pos) (= d sd)))
4261 (setq start-pos (point))
4262 (if (and start-pos (not end-pos))
4263 (setq end-pos (point))))
4264 (setq files thefiles
4266 (while (setq file (pop files))
4268 (org-check-agenda-file file)
4269 (let ((org-agenda-entry-types org-agenda-entry-types))
4270 ;; Starred types override non-starred equivalents
4271 (when (member :deadline* org-agenda-entry-types)
4272 (setq org-agenda-entry-types
4273 (delq :deadline org-agenda-entry-types)))
4274 (when (member :scheduled* org-agenda-entry-types)
4275 (setq org-agenda-entry-types
4276 (delq :scheduled org-agenda-entry-types)))
4279 (when (member :deadline org-agenda-entry-types)
4280 (setq org-agenda-entry-types
4281 (delq :deadline org-agenda-entry-types))
4282 (push :deadline* org-agenda-entry-types))
4283 (when (member :scheduled org-agenda-entry-types)
4284 (setq org-agenda-entry-types
4285 (delq :scheduled org-agenda-entry-types))
4286 (push :scheduled* org-agenda-entry-types)))
4287 (unless org-agenda-include-deadlines
4288 (setq org-agenda-entry-types
4289 (delq :deadline* (delq :deadline org-agenda-entry-types))))
4291 ((memq org-agenda-show-log-scoped '(only clockcheck))
4292 (setq rtn (org-agenda-get-day-entries
4293 file date :closed)))
4294 (org-agenda-show-log-scoped
4295 (setq rtn (apply 'org-agenda-get-day-entries
4297 (append '(:closed) org-agenda-entry-types))))
4299 (setq rtn (apply 'org-agenda-get-day-entries
4301 org-agenda-entry-types)))))
4302 (setq rtnall (append rtnall rtn)))) ;; all entries
4303 (if org-agenda-include-diary
4304 (let ((org-agenda-search-headline-for-time t))
4305 (require 'diary-lib)
4306 (setq rtn (org-get-entries-from-diary date))
4307 (setq rtnall (append rtnall rtn))))
4308 (if (or rtnall org-agenda-show-all-dates)
4310 (setq day-cnt (1+ day-cnt))
4312 (if (stringp org-agenda-format-date)
4313 (format-time-string org-agenda-format-date
4314 (org-time-from-absolute date))
4315 (funcall org-agenda-format-date date))
4317 (put-text-property s (1- (point)) 'face
4318 (org-agenda-get-day-face date))
4319 (put-text-property s (1- (point)) 'org-date-line t)
4320 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4321 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4323 (put-text-property s (1- (point)) 'org-today t))
4325 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4326 (if rtnall (insert ;; all entries
4327 (org-agenda-finalize-entries rtnall 'agenda)
4329 (put-text-property s (1- (point)) 'day d)
4330 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4331 (when (and org-agenda-clockreport-mode clocktable-start)
4332 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4333 ;; the above line is to ensure the restricted range!
4334 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4336 (setq p (org-plist-delete p :block))
4337 (setq p (plist-put p :tstart clocktable-start))
4338 (setq p (plist-put p :tend clocktable-end))
4339 (setq p (plist-put p :scope 'agenda))
4340 (setq tbl (apply 'org-clock-get-clocktable p))
4342 (goto-char (point-min))
4343 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4344 (unless (and (pos-visible-in-window-p (point-min))
4345 (pos-visible-in-window-p (point-max)))
4346 (goto-char (1- (point-max)))
4348 (if (not (pos-visible-in-window-p (or start-pos 1)))
4350 (goto-char (or start-pos 1))
4352 (goto-char (or start-pos 1))
4353 (add-text-properties (point-min) (point-max)
4354 `(org-agenda-type agenda
4355 org-last-args (,arg ,start-day ,span)
4356 org-redo-cmd ,org-agenda-redo-command
4357 org-series-cmd ,org-cmd))
4358 (if (eq org-agenda-show-log-scoped 'clockcheck)
4359 (org-agenda-show-clocking-issues))
4360 (org-agenda-finalize)
4361 (setq buffer-read-only t)
4364 (defun org-agenda-ndays-to-span (n)
4365 "Return a span symbol for a span of N days, or N if none matches."
4366 (cond ((symbolp n) n)
4369 ((= n 14) 'fortnight)
4372 (defun org-agenda-span-to-ndays (span &optional start-day)
4373 "Return ndays from SPAN, possibly starting at START-DAY.
4374 START-DAY is an absolute time value."
4375 (cond ((numberp span) span)
4378 ((eq span 'fortnight) 14)
4380 (let ((date (calendar-gregorian-from-absolute start-day)))
4381 (calendar-last-day-of-month (car date) (caddr date))))
4383 (let ((date (calendar-gregorian-from-absolute start-day)))
4384 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4386 (defun org-agenda-span-name (span)
4387 "Return a SPAN name."
4391 (capitalize (symbol-name span))
4392 (format "%d days" span))))
4394 ;;; Agenda word search
4396 (defvar org-agenda-search-history nil)
4398 (defvar org-search-syntax-table nil
4399 "Special syntax table for org-mode search.
4400 In this table, we have single quotes not as word constituents, to
4401 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4403 (defvar org-mode-syntax-table) ; From org.el
4404 (defun org-search-syntax-table ()
4405 (unless org-search-syntax-table
4406 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4407 (modify-syntax-entry ?' "." org-search-syntax-table)
4408 (modify-syntax-entry ?` "." org-search-syntax-table))
4409 org-search-syntax-table)
4411 (defvar org-agenda-last-search-view-search-was-boolean nil)
4414 (defun org-search-view (&optional todo-only string edit-at)
4415 "Show all entries that contain a phrase or words or regular expressions.
4417 With optional prefix argument TODO-ONLY, only consider entries that are
4418 TODO entries. The argument STRING can be used to pass a default search
4419 string into this function. If EDIT-AT is non-nil, it means that the
4420 user should get a chance to edit this string, with cursor at position
4423 The search string can be viewed either as a phrase that should be found as
4424 is, or it can be broken into a number of snippets, each of which must match
4425 in a Boolean way to select an entry. The default depends on the variable
4426 `org-agenda-search-view-always-boolean'.
4427 Even if this is turned off (the default) you can always switch to
4428 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4430 The default is a direct search of the whole phrase, where each space in
4431 the search string can expand to an arbitrary amount of whitespace,
4434 If using a Boolean search, the search string is split on whitespace and
4435 each snippet is searched separately, with logical AND to select an entry.
4436 Words prefixed with a minus must *not* occur in the entry. Words without
4437 a prefix or prefixed with a plus must occur in the entry. Matching is
4438 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4439 match whole words, not parts of a word) if
4440 `org-agenda-search-view-force-full-words' is set (default is nil).
4442 Boolean search snippets enclosed by curly braces are interpreted as
4443 regular expressions that must or (when preceded with \"-\") must not
4444 match in the entry. Snippets enclosed into double quotes will be taken
4445 as a whole, to include whitespace.
4447 - If the search string starts with an asterisk, search only in headlines.
4448 - If (possibly after the leading star) the search string starts with an
4449 exclamation mark, this also means to look at TODO entries only, an effect
4450 that can also be achieved with a prefix argument.
4451 - If (possibly after star and exclamation mark) the search string starts
4452 with a colon, this will mean that the (non-regexp) snippets of the
4453 Boolean search must match as full words.
4455 This command searches the agenda files, and in addition the files listed
4456 in `org-agenda-text-search-extra-files'."
4458 (if org-agenda-overriding-arguments
4459 (setq todo-only (car org-agenda-overriding-arguments)
4460 string (nth 1 org-agenda-overriding-arguments)
4461 edit-at (nth 2 org-agenda-overriding-arguments)))
4462 (let* ((props (list 'face nil
4463 'done-face 'org-agenda-done
4464 'org-not-done-regexp org-not-done-regexp
4465 'org-todo-regexp org-todo-regexp
4466 'org-complex-heading-regexp org-complex-heading-regexp
4467 'mouse-face 'highlight
4468 'help-echo (format "mouse-2 or RET jump to location")))
4469 (full-words org-agenda-search-view-force-full-words)
4470 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4471 regexp rtn rtnall files file pos inherited-tags
4472 marker category level tags c neg re boolean
4473 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4474 (unless (and (not edit-at)
4476 (string-match "\\S-" string))
4477 (setq string (read-string
4478 (if org-agenda-search-view-always-boolean
4479 "[+-]Word/{Regexp} ...: "
4480 "Phrase or [+-]Word/{Regexp} ...: ")
4482 ((integerp edit-at) (cons string edit-at))
4484 'org-agenda-search-history)))
4486 (if org-agenda-sticky
4487 (setq org-agenda-buffer-name
4488 (if (stringp string)
4489 (format "*Org Agenda(%s:%s)*"
4490 (or org-keys (or (and todo-only "S") "s")) string)
4491 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4492 (org-agenda-prepare "SEARCH")
4493 (org-compile-prefix-format 'search)
4494 (org-set-sorting-strategy 'search)
4495 (setq org-agenda-redo-command
4496 (list 'org-search-view (if todo-only t nil)
4497 (list 'if 'current-prefix-arg nil string)))
4498 (setq org-agenda-query-string string)
4499 (if (equal (string-to-char string) ?*)
4501 words (substring string 1))
4502 (setq words string))
4503 (when (equal (string-to-char words) ?!)
4505 words (substring words 1)))
4506 (when (equal (string-to-char words) ?:)
4508 words (substring words 1)))
4509 (if (or org-agenda-search-view-always-boolean
4510 (member (string-to-char words) '(?- ?+ ?\{)))
4512 (setq words (org-split-string words))
4514 (while (setq w (pop words))
4515 (while (and (string-match "\\\\\\'" w) words)
4516 (setq w (concat (substring w 0 -1) " " (pop words))))
4518 (setq words (nreverse www) www nil)
4519 (while (setq w (pop words))
4520 (when (and (string-match "\\`[-+]?{" w)
4521 (not (string-match "}\\'" w)))
4522 (while (and words (not (string-match "}\\'" (car words))))
4523 (setq w (concat w " " (pop words))))
4524 (setq w (concat w " " (pop words))))
4526 (setq words (nreverse www)))
4527 (setq org-agenda-last-search-view-search-was-boolean boolean)
4530 (while (setq w (pop words))
4531 (if (or (equal (substring w 0 1) "\"")
4532 (and (> (length w) 1)
4533 (member (substring w 0 1) '("+" "-"))
4534 (equal (substring w 1 2) "\"")))
4535 (while (and words (not (equal (substring w -1) "\"")))
4536 (setq w (concat w " " (pop words)))))
4537 (and (string-match "\\`\\([-+]?\\)\"" w)
4538 (setq w (replace-match "\\1" nil nil w)))
4539 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4541 (setq words (nreverse wds))))
4544 (setq c (string-to-char w))
4546 (setq neg t w (substring w 1))
4548 (setq neg nil w (substring w 1))
4550 (if (string-match "\\`{.*}\\'" w)
4551 (setq re (substring w 1 -1))
4553 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4554 (setq re (regexp-quote (downcase w)))))
4555 (if neg (push re regexps-) (push re regexps+)))
4557 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4559 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4561 (setq regexp org-outline-regexp-bol)
4562 (setq regexp (pop regexps+))
4563 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4565 (setq files (org-agenda-files nil 'ifmode))
4566 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4567 (pop org-agenda-text-search-extra-files)
4568 (setq files (org-add-archive-files files)))
4569 (setq files (append files org-agenda-text-search-extra-files)
4571 (while (setq file (pop files))
4574 (org-check-agenda-file file)
4575 (setq buffer (if (file-exists-p file)
4576 (org-get-agenda-file-buffer file)
4577 (error "No such file %s" file)))
4579 ;; If file does not exist, make sure an error message is sent
4580 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4582 (with-current-buffer buffer
4583 (with-syntax-table (org-search-syntax-table)
4584 (unless (derived-mode-p 'org-mode)
4585 (error "Agenda file %s is not in `org-mode'" file))
4586 (let ((case-fold-search t))
4589 (if (eq buffer org-agenda-restrict)
4590 (narrow-to-region org-agenda-restrict-begin
4591 org-agenda-restrict-end)
4593 (goto-char (point-min))
4594 (unless (or (org-at-heading-p)
4595 (outline-next-heading))
4596 (throw 'nextfile t))
4597 (goto-char (max (point-min) (1- (point))))
4598 (while (re-search-forward regexp nil t)
4599 (org-back-to-heading t)
4600 (while (and (not (zerop org-agenda-search-view-max-outline-level))
4601 (> (org-reduced-level (org-outline-level))
4602 org-agenda-search-view-max-outline-level)
4604 (outline-back-to-heading t)))
4605 (skip-chars-forward "* ")
4606 (setq beg (point-at-bol)
4609 (outline-next-heading)
4610 (while (and (not (zerop org-agenda-search-view-max-outline-level))
4611 (> (org-reduced-level (org-outline-level))
4612 org-agenda-search-view-max-outline-level)
4614 (outline-next-heading)))
4620 (setq str (buffer-substring-no-properties
4622 (if hdl-only (point-at-eol) end)))
4623 (mapc (lambda (wr) (when (string-match wr str)
4624 (goto-char (1- end))
4627 (mapc (lambda (wr) (unless (string-match wr str)
4628 (goto-char (1- end))
4631 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4635 (setq marker (org-agenda-new-marker (point))
4636 category (org-get-category)
4637 level (make-string (org-reduced-level (org-outline-level)) ? )
4639 (or (eq org-agenda-show-inherited-tags 'always)
4640 (and (listp org-agenda-show-inherited-tags)
4641 (memq 'todo org-agenda-show-inherited-tags))
4642 (and (eq org-agenda-show-inherited-tags t)
4643 (or (eq org-agenda-use-tag-inheritance t)
4644 (memq 'todo org-agenda-use-tag-inheritance))))
4645 tags (org-get-tags-at nil (not inherited-tags))
4646 txt (org-agenda-format-item
4648 (buffer-substring-no-properties
4649 beg1 (point-at-eol))
4650 level category tags t))
4651 (org-add-props txt props
4652 'org-marker marker 'org-hd-marker marker
4653 'org-todo-regexp org-todo-regexp
4655 'org-complex-heading-regexp org-complex-heading-regexp
4659 (goto-char (1- end))))))))))
4660 (setq rtn (nreverse ee))
4661 (setq rtnall (append rtnall rtn)))
4662 (if org-agenda-overriding-header
4663 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4664 nil 'face 'org-agenda-structure) "\n")
4665 (insert "Search words: ")
4666 (add-text-properties (point-min) (1- (point))
4667 (list 'face 'org-agenda-structure))
4669 (insert string "\n")
4670 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4672 (unless org-agenda-multi
4673 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4674 (add-text-properties pos (1- (point))
4675 (list 'face 'org-agenda-structure))))
4676 (org-agenda-mark-header-line (point-min))
4678 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4679 (goto-char (point-min))
4680 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4681 (add-text-properties (point-min) (point-max)
4682 `(org-agenda-type search
4683 org-last-args (,todo-only ,string ,edit-at)
4684 org-redo-cmd ,org-agenda-redo-command
4685 org-series-cmd ,org-cmd))
4686 (org-agenda-finalize)
4687 (setq buffer-read-only t))))
4689 ;;; Agenda TODO list
4691 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4692 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4694 (if (or (equal keywords "ALL") (not keywords))
4695 (propertize "ALL" 'face 'warning)
4698 (propertize kw 'face (org-get-todo-face kw)))
4699 (org-split-string keywords "|")
4703 (defvar org-select-this-todo-keyword nil)
4704 (defvar org-last-arg nil)
4707 (defun org-todo-list (&optional arg)
4708 "Show all (not done) TODO entries from all agenda file in a single list.
4709 The prefix arg can be used to select a specific TODO keyword and limit
4710 the list to these. When using \\[universal-argument], you will be prompted
4711 for a keyword. A numeric prefix directly selects the Nth keyword in
4712 `org-todo-keywords-1'."
4714 (if org-agenda-overriding-arguments
4715 (setq arg org-agenda-overriding-arguments))
4716 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4717 (let* ((today (org-today))
4718 (date (calendar-gregorian-from-absolute today))
4719 (kwds org-todo-keywords-for-agenda)
4720 (completion-ignore-case t)
4721 (org-select-this-todo-keyword
4722 (if (stringp arg) arg
4723 (and arg (integerp arg) (> arg 0)
4724 (nth (1- arg) kwds))))
4725 rtn rtnall files file pos)
4726 (when (equal arg '(4))
4727 (setq org-select-this-todo-keyword
4728 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4729 (mapcar 'list kwds) nil nil)))
4730 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4732 (if org-agenda-sticky
4733 (setq org-agenda-buffer-name
4734 (if (stringp org-select-this-todo-keyword)
4735 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4736 org-select-this-todo-keyword)
4737 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4738 (org-agenda-prepare "TODO")
4739 (org-compile-prefix-format 'todo)
4740 (org-set-sorting-strategy 'todo)
4741 (setq org-agenda-redo-command
4742 `(org-todo-list (or (and (numberp current-prefix-arg)
4744 ,org-select-this-todo-keyword
4745 current-prefix-arg ,arg)))
4746 (setq files (org-agenda-files nil 'ifmode)
4748 (while (setq file (pop files))
4750 (org-check-agenda-file file)
4751 (setq rtn (org-agenda-get-day-entries file date :todo))
4752 (setq rtnall (append rtnall rtn))))
4753 (if org-agenda-overriding-header
4754 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4755 nil 'face 'org-agenda-structure) "\n")
4756 (insert "Global list of TODO items of type: ")
4757 (add-text-properties (point-min) (1- (point))
4758 (list 'face 'org-agenda-structure
4761 (or org-select-this-todo-keyword "ALL"))))
4762 (org-agenda-mark-header-line (point-min))
4763 (insert (org-agenda-propertize-selected-todo-keywords
4764 org-select-this-todo-keyword))
4766 (unless org-agenda-multi
4767 (insert "Available with `N r': (0)[ALL]")
4770 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4771 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4776 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4777 (org-agenda-mark-header-line (point-min))
4779 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4780 (goto-char (point-min))
4781 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4782 (add-text-properties (point-min) (point-max)
4783 `(org-agenda-type todo
4785 org-redo-cmd ,org-agenda-redo-command
4786 org-series-cmd ,org-cmd))
4787 (org-agenda-finalize)
4788 (setq buffer-read-only t))))
4790 ;;; Agenda tags match
4793 (defun org-tags-view (&optional todo-only match)
4794 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4795 The prefix arg TODO-ONLY limits the search to TODO entries."
4797 (if org-agenda-overriding-arguments
4798 (setq todo-only (car org-agenda-overriding-arguments)
4799 match (nth 1 org-agenda-overriding-arguments)))
4800 (let* ((org-tags-match-list-sublevels
4801 org-tags-match-list-sublevels)
4802 (completion-ignore-case t)
4803 rtn rtnall files file pos matcher
4805 (when (and (stringp match) (not (string-match "\\S-" match)))
4808 (if org-agenda-sticky
4809 (setq org-agenda-buffer-name
4811 (format "*Org Agenda(%s:%s)*"
4812 (or org-keys (or (and todo-only "M") "m")) match)
4813 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4814 ;; Prepare agendas (and `org-tag-alist-for-agenda') before
4815 ;; expanding tags within `org-make-tags-matcher'
4816 (org-agenda-prepare (concat "TAGS " match))
4817 (setq matcher (org-make-tags-matcher match)
4818 match (car matcher) matcher (cdr matcher))
4819 (org-compile-prefix-format 'tags)
4820 (org-set-sorting-strategy 'tags)
4821 (setq org-agenda-query-string match)
4822 (setq org-agenda-redo-command
4823 (list 'org-tags-view `(quote ,todo-only)
4824 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4825 (setq files (org-agenda-files nil 'ifmode)
4827 (while (setq file (pop files))
4829 (org-check-agenda-file file)
4830 (setq buffer (if (file-exists-p file)
4831 (org-get-agenda-file-buffer file)
4832 (error "No such file %s" file)))
4834 ;; If file does not exist, error message to agenda
4836 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4837 rtnall (append rtnall rtn))
4838 (with-current-buffer buffer
4839 (unless (derived-mode-p 'org-mode)
4840 (error "Agenda file %s is not in `org-mode'" file))
4843 (if (eq buffer org-agenda-restrict)
4844 (narrow-to-region org-agenda-restrict-begin
4845 org-agenda-restrict-end)
4847 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4848 (setq rtnall (append rtnall rtn))))))))
4849 (if org-agenda-overriding-header
4850 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4851 nil 'face 'org-agenda-structure) "\n")
4852 (insert "Headlines with TAGS match: ")
4853 (add-text-properties (point-min) (1- (point))
4854 (list 'face 'org-agenda-structure
4856 (concat "Match: " match)))
4859 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4861 (unless org-agenda-multi
4862 (insert "Press `C-u r' to search again with new search string\n"))
4863 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4864 (org-agenda-mark-header-line (point-min))
4866 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4867 (goto-char (point-min))
4868 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4869 (add-text-properties (point-min) (point-max)
4870 `(org-agenda-type tags
4871 org-last-args (,todo-only ,match)
4872 org-redo-cmd ,org-agenda-redo-command
4873 org-series-cmd ,org-cmd))
4874 (org-agenda-finalize)
4875 (setq buffer-read-only t))))
4877 ;;; Agenda Finding stuck projects
4879 (defvar org-agenda-skip-regexp nil
4880 "Regular expression used in skipping subtrees for the agenda.
4881 This is basically a temporary global variable that can be set and then
4882 used by user-defined selections using `org-agenda-skip-function'.")
4884 (defvar org-agenda-overriding-header nil
4885 "When set during agenda, todo and tags searches it replaces the header.
4886 This variable should not be set directly, but custom commands can bind it
4887 in the options section.")
4889 (defun org-agenda-skip-entry-when-regexp-matches ()
4890 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4891 If yes, it returns the end position of this entry, causing agenda commands
4892 to skip the entry but continuing the search in the subtree. This is a
4893 function that can be put into `org-agenda-skip-function' for the duration
4895 (let ((end (save-excursion (org-end-of-subtree t)))
4898 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4901 (defun org-agenda-skip-subtree-when-regexp-matches ()
4902 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4903 If yes, it returns the end position of this tree, causing agenda commands
4904 to skip this subtree. This is a function that can be put into
4905 `org-agenda-skip-function' for the duration of a command."
4906 (let ((end (save-excursion (org-end-of-subtree t)))
4909 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4912 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4913 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4914 If yes, it returns the end position of the current entry (NOT the tree),
4915 causing agenda commands to skip the entry but continuing the search in
4916 the subtree. This is a function that can be put into
4917 `org-agenda-skip-function' for the duration of a command. An important
4918 use of this function is for the stuck project list."
4919 (let ((end (save-excursion (org-end-of-subtree t)))
4920 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4923 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4924 (and skip entry-end)))
4926 (defun org-agenda-skip-entry-if (&rest conditions)
4927 "Skip entry if any of CONDITIONS is true.
4928 See `org-agenda-skip-if' for details."
4929 (org-agenda-skip-if nil conditions))
4931 (defun org-agenda-skip-subtree-if (&rest conditions)
4932 "Skip subtree if any of CONDITIONS is true.
4933 See `org-agenda-skip-if' for details."
4934 (org-agenda-skip-if t conditions))
4936 (defun org-agenda-skip-if (subtree conditions)
4937 "Checks current entity for CONDITIONS.
4938 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4939 the entry (i.e. the text before the next heading) is checked.
4941 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4942 from different tests. Valid conditions are:
4944 scheduled Check if there is a scheduled cookie
4945 notscheduled Check if there is no scheduled cookie
4946 deadline Check if there is a deadline
4947 notdeadline Check if there is no deadline
4948 timestamp Check if there is a timestamp (also deadline or scheduled)
4949 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4950 regexp Check if regexp matches
4951 notregexp Check if regexp does not match.
4952 todo Check if TODO keyword matches
4953 nottodo Check if TODO keyword does not match
4955 The regexp is taken from the conditions list, it must come right after
4956 the `regexp' or `notregexp' element.
4958 `todo' and `nottodo' accept as an argument a list of todo
4959 keywords, which may include \"*\" to match any todo keyword.
4961 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4963 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4965 Instead of a list, a keyword class may be given. For example:
4967 (org-agenda-skip-entry-if 'nottodo 'done)
4969 would skip entries that haven't been marked with any of \"DONE\"
4970 keywords. Possible classes are: `todo', `done', `any'.
4972 If any of these conditions is met, this function returns the end point of
4973 the entity, causing the search to continue from there. This is a function
4974 that can be put into `org-agenda-skip-function' for the duration of a command."
4976 (org-back-to-heading t)
4979 (progn (org-end-of-subtree t) (point))
4980 (progn (outline-next-heading) (1- (point)))))
4984 (and (memq 'scheduled conditions)
4985 (re-search-forward org-scheduled-time-regexp end t))
4986 (and (memq 'notscheduled conditions)
4987 (not (re-search-forward org-scheduled-time-regexp end t)))
4988 (and (memq 'deadline conditions)
4989 (re-search-forward org-deadline-time-regexp end t))
4990 (and (memq 'notdeadline conditions)
4991 (not (re-search-forward org-deadline-time-regexp end t)))
4992 (and (memq 'timestamp conditions)
4993 (re-search-forward org-ts-regexp end t))
4994 (and (memq 'nottimestamp conditions)
4995 (not (re-search-forward org-ts-regexp end t)))
4996 (and (setq m (memq 'regexp conditions))
4998 (re-search-forward (nth 1 m) end t))
4999 (and (setq m (memq 'notregexp conditions))
5001 (not (re-search-forward (nth 1 m) end t)))
5003 (setq m (memq 'nottodo conditions))
5004 (setq m (memq 'todo-unblocked conditions))
5005 (setq m (memq 'nottodo-unblocked conditions))
5006 (setq m (memq 'todo conditions)))
5007 (org-agenda-skip-if-todo m end)))
5010 (defun org-agenda-skip-if-todo (args end)
5011 "Helper function for `org-agenda-skip-if', do not use it directly.
5012 ARGS is a list with first element either `todo', `nottodo',
5013 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
5014 a list of TODO keywords, or a state symbol `todo' or `done' or
5016 (let ((kw (car args))
5022 ((listp arg) ;; list of keywords
5023 (if (member "*" arg)
5024 (mapcar 'substring-no-properties org-todo-keywords-1)
5026 ((symbolp arg) ;; keyword class name
5029 (org-delete-all org-done-keywords
5030 (mapcar 'substring-no-properties
5031 org-todo-keywords-1)))
5032 ((eq arg 'done) org-done-keywords)
5034 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
5036 (concat "^\\*+[ \t]+\\<\\("
5037 (mapconcat 'identity todo-wds "\\|")
5040 ((eq kw 'todo) (re-search-forward todo-re end t))
5041 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
5042 ((eq kw 'todo-unblocked)
5044 (while (re-search-forward todo-re end t)
5045 (or (org-entry-blocked-p) (throw 'unblocked t)))
5047 ((eq kw 'nottodo-unblocked)
5049 (while (re-search-forward todo-re end t)
5050 (or (org-entry-blocked-p) (throw 'unblocked nil)))
5055 (defun org-agenda-list-stuck-projects (&rest ignore)
5056 "Create agenda view for projects that are stuck.
5057 Stuck projects are project that have no next actions. For the definitions
5058 of what a project is and how to check if it stuck, customize the variable
5059 `org-stuck-projects'."
5061 (let* ((org-agenda-skip-function
5062 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5063 ;; We could have used org-agenda-skip-if here.
5064 (org-agenda-overriding-header
5065 (or org-agenda-overriding-header "List of stuck projects: "))
5066 (matcher (nth 0 org-stuck-projects))
5067 (todo (nth 1 org-stuck-projects))
5068 (todo-wds (if (member "*" todo)
5070 (org-agenda-prepare-buffers (org-agenda-files
5073 org-done-keywords-for-agenda
5074 (copy-sequence org-todo-keywords-for-agenda)))
5076 (todo-re (concat "^\\*+[ \t]+\\("
5077 (mapconcat 'identity todo-wds "\\|")
5079 (tags (nth 2 org-stuck-projects))
5080 (tags-re (if (member "*" tags)
5081 (concat org-outline-regexp-bol
5082 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5084 (concat org-outline-regexp-bol
5086 (mapconcat 'identity tags "\\|")
5087 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5088 (gen-re (nth 3 org-stuck-projects))
5094 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5096 (setq org-agenda-skip-regexp
5098 (mapconcat 'identity re-list "\\|")
5099 (error "No information how to identify unstuck projects")))
5100 (org-tags-view nil matcher)
5101 (setq org-agenda-buffer-name (buffer-name))
5102 (with-current-buffer org-agenda-buffer-name
5103 (setq org-agenda-redo-command
5104 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5106 ;;; Diary integration
5108 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5109 (defvar diary-list-entries-hook)
5110 (defvar diary-time-regexp)
5111 (defun org-get-entries-from-diary (date)
5112 "Get the (Emacs Calendar) diary entries for DATE."
5113 (require 'diary-lib)
5114 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5115 (diary-display-function 'diary-fancy-display)
5117 (diary-list-entries-hook
5118 (cons 'org-diary-default-entry diary-list-entries-hook))
5119 (diary-file-name-prefix nil) ; turn this feature off
5120 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5122 (org-disable-agenda-to-diary t))
5124 (save-window-excursion
5125 (funcall (if (fboundp 'diary-list-entries)
5126 'diary-list-entries 'list-diary-entries)
5128 (if (not (get-buffer diary-fancy-buffer))
5130 (with-current-buffer diary-fancy-buffer
5131 (setq buffer-read-only nil)
5132 (if (zerop (buffer-size))
5135 ;; Omit the date and other unnecessary stuff
5136 (org-agenda-cleanup-fancy-diary)
5137 ;; Add prefix to each line and extend the text properties
5138 (if (zerop (buffer-size))
5140 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5143 (insert entries) (goto-char (point-min))
5144 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5145 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5146 (replace-match (concat "; " (match-string 1)))))
5148 (set-buffer-modified-p nil)
5149 (kill-buffer diary-fancy-buffer)))
5151 (setq entries (org-split-string entries "\n"))
5155 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5156 ;; Extend the text properties to the beginning of the line
5157 (org-add-props x (text-properties-at (1- (length x)) x)
5158 'type "diary" 'date date 'face 'org-agenda-diary))
5161 (defvar org-agenda-cleanup-fancy-diary-hook nil
5162 "Hook run when the fancy diary buffer is cleaned up.")
5164 (defun org-agenda-cleanup-fancy-diary ()
5165 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5166 This gets rid of the date, the underline under the date, and
5167 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5168 date. It also removes lines that contain only whitespace."
5169 (goto-char (point-min))
5170 (if (looking-at ".*?:[ \t]*")
5173 (re-search-forward "\n=+$" nil t)
5175 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5176 (re-search-forward "\n=+$" nil t)
5177 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5178 (goto-char (point-min))
5179 (while (re-search-forward "^ +\n" nil t)
5181 (goto-char (point-min))
5182 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5184 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5186 ;; Make sure entries from the diary have the right text properties.
5187 (eval-after-load "diary-lib"
5188 '(if (boundp 'diary-modify-entry-list-string-function)
5189 ;; We can rely on the hook, nothing to do
5191 ;; Hook not available, must use advice to make this work
5192 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5193 "Make the position visible."
5194 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5197 (setq string (org-modify-diary-entry-string string))))))
5199 (defun org-modify-diary-entry-string (string)
5200 "Add text properties to string, allowing org-mode to act on it."
5201 (org-add-props string nil
5202 'mouse-face 'highlight
5203 'help-echo (if buffer-file-name
5204 (format "mouse-2 or RET jump to diary file %s"
5205 (abbreviate-file-name buffer-file-name))
5207 'org-agenda-diary-link t
5208 'org-marker (org-agenda-new-marker (point-at-bol))))
5210 (defun org-diary-default-entry ()
5211 "Add a dummy entry to the diary.
5212 Needed to avoid empty dates which mess up holiday display."
5213 ;; Catch the error if dealing with the new add-to-diary-alist
5214 (when org-disable-agenda-to-diary
5216 (org-add-to-diary-list original-date "Org-mode dummy" "")
5218 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5220 (defun org-add-to-diary-list (&rest args)
5221 (if (fboundp 'diary-add-to-list)
5222 (apply 'diary-add-to-list args)
5223 (apply 'add-to-diary-list args)))
5225 (defvar org-diary-last-run-time nil)
5228 (defun org-diary (&rest args)
5229 "Return diary information from org files.
5230 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5231 It accesses org files and extracts information from those files to be
5232 listed in the diary. The function accepts arguments specifying what
5233 items should be listed. For a list of arguments allowed here, see the
5234 variable `org-agenda-entry-types'.
5236 The call in the diary file should look like this:
5238 &%%(org-diary) ~/path/to/some/orgfile.org
5240 Use a separate line for each org file to check. Or, if you omit the file name,
5241 all files listed in `org-agenda-files' will be checked automatically:
5245 If you don't give any arguments (as in the example above), the default value
5246 of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
5247 So the example above may also be written as
5249 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5251 The function expects the lisp variables `entry' and `date' to be provided
5252 by the caller, because this is how the calendar works. Don't use this
5253 function from a program - use `org-agenda-get-day-entries' instead."
5254 (when (> (- (org-float-time)
5255 org-agenda-last-marker-time)
5257 ;; I am not sure if this works with sticky agendas, because the marker
5258 ;; list is then no longer a global variable.
5259 (org-agenda-reset-markers))
5260 (org-compile-prefix-format 'agenda)
5261 (org-set-sorting-strategy 'agenda)
5262 (setq args (or args org-agenda-entry-types))
5263 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5265 (org-agenda-files t)))
5266 (time (org-float-time))
5268 (when (or (not org-diary-last-run-time)
5270 org-diary-last-run-time)
5272 (org-agenda-prepare-buffers files))
5273 (setq org-diary-last-run-time time)
5274 ;; If this is called during org-agenda, don't return any entries to
5275 ;; the calendar. Org Agenda will list these entries itself.
5276 (if org-disable-agenda-to-diary (setq files nil))
5277 (while (setq file (pop files))
5278 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5279 (setq results (append results rtn)))
5282 (mapcar (lambda (i) (replace-regexp-in-string
5283 org-bracket-link-regexp "\\3" i)) results))
5284 (concat (org-agenda-finalize-entries results) "\n"))))
5286 ;;; Agenda entry finders
5288 (defun org-agenda-get-day-entries (file date &rest args)
5289 "Does the work for `org-diary' and `org-agenda'.
5290 FILE is the path to a file to be checked for entries. DATE is date like
5291 the one returned by `calendar-current-date'. ARGS are symbols indicating
5292 which kind of entries should be extracted. For details about these, see
5293 the documentation of `org-diary'."
5294 (setq args (or args org-agenda-entry-types))
5295 (let* ((org-startup-folded nil)
5296 (org-startup-align-all-tables nil)
5297 (buffer (if (file-exists-p file)
5298 (org-get-agenda-file-buffer file)
5299 (error "No such file %s" file)))
5300 arg results rtn deadline-results)
5302 ;; If file does not exist, make sure an error message ends up in diary
5303 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5304 (with-current-buffer buffer
5305 (unless (derived-mode-p 'org-mode)
5306 (error "Agenda file %s is not in `org-mode'" file))
5307 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5308 (let ((case-fold-search nil))
5311 (if (eq buffer org-agenda-restrict)
5312 (narrow-to-region org-agenda-restrict-begin
5313 org-agenda-restrict-end)
5315 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5316 (while (setq arg (pop args))
5318 ((and (eq arg :todo)
5319 (equal date (calendar-gregorian-from-absolute
5321 (setq rtn (org-agenda-get-todos))
5322 (setq results (append results rtn)))
5323 ((eq arg :timestamp)
5324 (setq rtn (org-agenda-get-blocks))
5325 (setq results (append results rtn))
5326 (setq rtn (org-agenda-get-timestamps deadline-results))
5327 (setq results (append results rtn)))
5329 (setq rtn (org-agenda-get-sexps))
5330 (setq results (append results rtn)))
5331 ((eq arg :scheduled)
5332 (setq rtn (org-agenda-get-scheduled deadline-results))
5333 (setq results (append results rtn)))
5334 ((eq arg :scheduled*)
5335 (setq rtn (org-agenda-get-scheduled deadline-results t))
5336 (setq results (append results rtn)))
5338 (setq rtn (org-agenda-get-progress))
5339 (setq results (append results rtn)))
5341 (setq rtn (org-agenda-get-deadlines))
5342 (setq deadline-results (copy-sequence rtn))
5343 (setq results (append results rtn)))
5344 ((eq arg :deadline*)
5345 (setq rtn (org-agenda-get-deadlines t))
5346 (setq deadline-results (copy-sequence rtn))
5347 (setq results (append results rtn))))))))
5350 (defsubst org-em (x y list)
5351 "Is X or Y a member of LIST?"
5352 (or (memq x list) (memq y list)))
5354 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5355 (defvar org-agenda-sorting-strategy-selected nil)
5357 (defun org-agenda-get-todos ()
5358 "Return the TODO information for agenda display."
5359 (let* ((props (list 'face nil
5360 'done-face 'org-agenda-done
5361 'org-not-done-regexp org-not-done-regexp
5362 'org-todo-regexp org-todo-regexp
5363 'org-complex-heading-regexp org-complex-heading-regexp
5364 'mouse-face 'highlight
5366 (format "mouse-2 or RET jump to org file %s"
5367 (abbreviate-file-name buffer-file-name))))
5368 (regexp (format org-heading-keyword-regexp-format
5370 ((and org-select-this-todo-keyword
5371 (equal org-select-this-todo-keyword "*"))
5373 (org-select-this-todo-keyword
5375 (mapconcat 'identity
5377 org-select-this-todo-keyword
5380 (t org-not-done-regexp))))
5381 marker priority category level tags todo-state ts-date ts-date-type
5382 ee txt beg end inherited-tags todo-state-end-pos)
5383 (goto-char (point-min))
5384 (while (re-search-forward regexp nil t)
5389 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5390 (unless (and (setq todo-state (org-get-todo-state))
5391 (setq todo-state-end-pos (match-end 2)))
5394 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5395 (goto-char (1+ beg))
5396 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5398 (goto-char (match-beginning 2))
5399 (setq marker (org-agenda-new-marker (match-beginning 0))
5400 category (org-get-category)
5403 (cond ((org-em 'scheduled-up 'scheduled-down
5404 org-agenda-sorting-strategy-selected)
5405 (setq ts (org-entry-get (point) "SCHEDULED")
5406 ts-date-type " scheduled"))
5407 ((org-em 'deadline-up 'deadline-down
5408 org-agenda-sorting-strategy-selected)
5409 (setq ts (org-entry-get (point) "DEADLINE")
5410 ts-date-type " deadline"))
5411 ((org-em 'ts-up 'ts-down
5412 org-agenda-sorting-strategy-selected)
5413 (setq ts (org-entry-get (point) "TIMESTAMP")
5414 ts-date-type " timestamp"))
5415 ((org-em 'tsia-up 'tsia-down
5416 org-agenda-sorting-strategy-selected)
5417 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
5418 ts-date-type " timestamp_ia"))
5419 ((org-em 'timestamp-up 'timestamp-down
5420 org-agenda-sorting-strategy-selected)
5421 (setq ts (or (org-entry-get (point) "SCHEDULED")
5422 (org-entry-get (point) "DEADLINE")
5423 (org-entry-get (point) "TIMESTAMP")
5424 (org-entry-get (point) "TIMESTAMP_IA"))
5426 (t (setq ts-date-type "")))
5427 (when ts (ignore-errors (org-time-string-to-absolute ts)))))
5428 txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
5430 (or (eq org-agenda-show-inherited-tags 'always)
5431 (and (listp org-agenda-show-inherited-tags)
5432 (memq 'todo org-agenda-show-inherited-tags))
5433 (and (eq org-agenda-show-inherited-tags t)
5434 (or (eq org-agenda-use-tag-inheritance t)
5435 (memq 'todo org-agenda-use-tag-inheritance))))
5436 tags (org-get-tags-at nil (not inherited-tags))
5437 level (make-string (org-reduced-level (org-outline-level)) ? )
5438 txt (org-agenda-format-item "" txt level category tags t)
5439 priority (1+ (org-get-priority txt)))
5440 (org-add-props txt props
5441 'org-marker marker 'org-hd-marker marker
5445 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5447 (if org-agenda-todo-list-sublevels
5448 (goto-char todo-state-end-pos)
5449 (org-end-of-subtree 'invisible))))
5452 (defun org-agenda-todo-custom-ignore-p (time n)
5453 "Check whether timestamp is farther away than n number of days.
5454 This function is invoked if `org-agenda-todo-ignore-deadlines',
5455 `org-agenda-todo-ignore-scheduled' or
5456 `org-agenda-todo-ignore-timestamp' is set to an integer."
5457 (let ((days (org-time-stamp-to-now
5458 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5464 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5466 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5467 (when (or org-agenda-todo-ignore-with-date
5468 org-agenda-todo-ignore-scheduled
5469 org-agenda-todo-ignore-deadlines
5470 org-agenda-todo-ignore-timestamp)
5471 (setq end (or end (save-excursion (outline-next-heading) (point))))
5473 (or (and org-agenda-todo-ignore-with-date
5474 (re-search-forward org-ts-regexp end t))
5475 (and org-agenda-todo-ignore-scheduled
5476 (re-search-forward org-scheduled-time-regexp end t)
5478 ((eq org-agenda-todo-ignore-scheduled 'future)
5479 (> (org-time-stamp-to-now
5480 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5481 ((eq org-agenda-todo-ignore-scheduled 'past)
5482 (<= (org-time-stamp-to-now
5483 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5484 ((numberp org-agenda-todo-ignore-scheduled)
5485 (org-agenda-todo-custom-ignore-p
5486 (match-string 1) org-agenda-todo-ignore-scheduled))
5488 (and org-agenda-todo-ignore-deadlines
5489 (re-search-forward org-deadline-time-regexp end t)
5491 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5492 ((eq org-agenda-todo-ignore-deadlines 'far)
5493 (not (org-deadline-close (match-string 1))))
5494 ((eq org-agenda-todo-ignore-deadlines 'future)
5495 (> (org-time-stamp-to-now
5496 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5497 ((eq org-agenda-todo-ignore-deadlines 'past)
5498 (<= (org-time-stamp-to-now
5499 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5500 ((numberp org-agenda-todo-ignore-deadlines)
5501 (org-agenda-todo-custom-ignore-p
5502 (match-string 1) org-agenda-todo-ignore-deadlines))
5503 (t (org-deadline-close (match-string 1)))))
5504 (and org-agenda-todo-ignore-timestamp
5505 (let ((buffer (current-buffer))
5508 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5510 ;; Copy current buffer into a temporary one
5512 (insert-buffer-substring buffer start end)
5513 (goto-char (point-min))
5514 ;; Delete SCHEDULED and DEADLINE items
5515 (while (re-search-forward regexp end t)
5516 (delete-region (match-beginning 0) (match-end 0)))
5517 (goto-char (point-min))
5518 ;; No search for timestamp left
5519 (when (re-search-forward org-ts-regexp nil t)
5521 ((eq org-agenda-todo-ignore-timestamp 'future)
5522 (> (org-time-stamp-to-now
5523 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5524 ((eq org-agenda-todo-ignore-timestamp 'past)
5525 (<= (org-time-stamp-to-now
5526 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5527 ((numberp org-agenda-todo-ignore-timestamp)
5528 (org-agenda-todo-custom-ignore-p
5529 (match-string 1) org-agenda-todo-ignore-timestamp))
5532 (defun org-agenda-get-timestamps (&optional deadline-results)
5533 "Return the date stamp information for agenda display."
5534 (let* ((props (list 'face 'org-agenda-calendar-event
5535 'org-not-done-regexp org-not-done-regexp
5536 'org-todo-regexp org-todo-regexp
5537 'org-complex-heading-regexp org-complex-heading-regexp
5538 'mouse-face 'highlight
5540 (format "mouse-2 or RET jump to org file %s"
5541 (abbreviate-file-name buffer-file-name))))
5542 (d1 (calendar-absolute-from-gregorian date))
5544 (deadline-position-alist
5545 (mapcar (lambda (a) (and (setq mm (get-text-property
5546 0 'org-hd-marker a))
5547 (cons (marker-position mm) a)))
5549 (remove-re org-ts-regexp)
5552 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5556 (car org-time-stamp-formats)
5557 (apply 'encode-time ; DATE bound by calendar
5558 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5560 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5561 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5562 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5563 donep tmp priority category level ee txt timestr tags
5564 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5565 inherited-tags ts-date)
5566 (goto-char (point-min))
5567 (while (setq end-of-match (re-search-forward regexp nil t))
5568 (setq b0 (match-beginning 0)
5569 b3 (match-beginning 3) e3 (match-end 3)
5570 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5571 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5572 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5574 org-agenda-repeating-timestamp-show-all)))
5576 (and (org-at-date-range-p) (throw :skip nil))
5578 (if (and (match-end 1)
5579 (not (= d1 (org-time-string-to-absolute
5580 (match-string 1) d1 nil show-all
5581 (current-buffer) b0))))
5584 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5586 (setq tmp (buffer-substring (max (point-min)
5587 (- b0 org-ds-keyword-length))
5589 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5590 inactivep (= (char-after b0) ?\[)
5591 deadlinep (string-match org-deadline-regexp tmp)
5592 scheduledp (string-match org-scheduled-regexp tmp)
5593 closedp (and org-agenda-include-inactive-timestamps
5594 (string-match org-closed-string tmp))
5595 clockp (and org-agenda-include-inactive-timestamps
5596 (or (string-match org-clock-string tmp)
5597 (string-match "]-+\\'" tmp)))
5598 warntime (get-text-property (point) 'org-appt-warntime)
5599 donep (member todo-state org-done-keywords))
5600 (if (or scheduledp deadlinep closedp clockp
5601 (and donep org-agenda-skip-timestamp-if-done))
5603 (if (string-match ">" timestr)
5604 ;; substring should only run to end of time stamp
5605 (setq timestr (substring timestr 0 (match-end 0))))
5606 (setq marker (org-agenda-new-marker b0)
5607 category (org-get-category b0))
5609 (if (not (re-search-backward org-outline-regexp-bol nil t))
5611 (goto-char (match-beginning 0))
5612 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5613 (assoc (point) deadline-position-alist))
5615 (setq hdmarker (org-agenda-new-marker)
5617 (or (eq org-agenda-show-inherited-tags 'always)
5618 (and (listp org-agenda-show-inherited-tags)
5619 (memq 'agenda org-agenda-show-inherited-tags))
5620 (and (eq org-agenda-show-inherited-tags t)
5621 (or (eq org-agenda-use-tag-inheritance t)
5622 (memq 'agenda org-agenda-use-tag-inheritance))))
5623 tags (org-get-tags-at nil (not inherited-tags))
5624 level (make-string (org-reduced-level (org-outline-level)) ? ))
5625 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5626 (setq head (or (match-string 1) ""))
5627 (setq txt (org-agenda-format-item
5628 (if inactivep org-agenda-inactive-leader nil)
5629 head level category tags timestr
5631 (setq priority (org-get-priority txt))
5632 (org-add-props txt props 'priority priority
5633 'org-marker marker 'org-hd-marker hdmarker
5637 (ignore-errors (org-time-string-to-absolute timestr))
5638 'todo-state todo-state
5642 (if org-agenda-skip-additional-timestamps-same-entry
5643 (outline-next-heading)
5644 (goto-char end-of-match))))
5647 (defun org-agenda-get-sexps ()
5648 "Return the sexp information for agenda display."
5649 (require 'diary-lib)
5650 (let* ((props (list 'face 'org-agenda-calendar-sexp
5651 'mouse-face 'highlight
5653 (format "mouse-2 or RET jump to org file %s"
5654 (abbreviate-file-name buffer-file-name))))
5656 marker category extra level ee txt tags entry
5657 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5658 (goto-char (point-min))
5659 (while (re-search-forward regexp nil t)
5662 (setq beg (match-beginning 0))
5663 (goto-char (1- (match-end 0)))
5666 (setq sexp (buffer-substring b (point)))
5667 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5668 (org-trim (match-string 1))
5670 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5672 (setq marker (org-agenda-new-marker beg)
5673 level (make-string (org-reduced-level (org-outline-level)) ? )
5674 category (org-get-category beg)
5676 (or (eq org-agenda-show-inherited-tags 'always)
5677 (and (listp org-agenda-show-inherited-tags)
5678 (memq 'agenda org-agenda-show-inherited-tags))
5679 (and (eq org-agenda-show-inherited-tags t)
5680 (or (eq org-agenda-use-tag-inheritance t)
5681 (memq 'agenda org-agenda-use-tag-inheritance))))
5682 tags (org-get-tags-at nil (not inherited-tags))
5683 todo-state (org-get-todo-state)
5684 warntime (get-text-property (point) 'org-appt-warntime)
5687 (dolist (r (if (stringp result)
5689 result)) ;; we expect a list here
5690 (when (and org-agenda-diary-sexp-prefix
5691 (string-match org-agenda-diary-sexp-prefix r))
5692 (setq extra (match-string 0 r)
5693 r (replace-match "" nil nil r)))
5694 (if (string-match "\\S-" r)
5696 (setq txt "SEXP entry returned empty string"))
5697 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5698 (org-add-props txt props 'org-marker marker
5699 'date date 'todo-state todo-state
5700 'level level 'type "sexp" 'warntime warntime)
5704 ;; Calendar sanity: define some functions that are independent of
5705 ;; `calendar-date-style'.
5706 ;; Normally I would like to use ISO format when calling the diary functions,
5707 ;; but to make sure we still have Emacs 22 compatibility we bind
5708 ;; also `european-calendar-style' and use european format
5709 (defun org-anniversary (year month day &optional mark)
5710 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5712 (let ((calendar-date-style 'european) (european-calendar-style t))
5713 (diary-anniversary day month year mark))))
5714 (defun org-cyclic (N year month day &optional mark)
5715 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5717 (let ((calendar-date-style 'european) (european-calendar-style t))
5718 (diary-cyclic N day month year mark))))
5719 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5720 "Like `diary-block', but with fixed (ISO) order of arguments."
5722 (let ((calendar-date-style 'european) (european-calendar-style t))
5723 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5724 (defun org-date (year month day &optional mark)
5725 "Like `diary-date', but with fixed (ISO) order of arguments."
5727 (let ((calendar-date-style 'european) (european-calendar-style t))
5728 (diary-date day month year mark))))
5730 ;; Define the` org-class' function
5731 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5732 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5733 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5734 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5735 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5736 `holidays', then any date that is known by the Emacs calendar to be a
5737 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5738 then those holidays will be skipped."
5739 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5740 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5741 (d (calendar-absolute-from-gregorian date))
5742 (h (when skip-weeks (calendar-check-holidays date))))
5746 (= (calendar-day-of-week date) dayname)
5747 (or (not skip-weeks)
5750 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5751 (not (or (and h (memq 'holidays skip-weeks))
5752 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5755 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5756 "Like `org-class', but honor `calendar-date-style'.
5757 The order of the first 2 times 3 arguments depends on the variable
5758 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5759 So for American calendars, give this as MONTH DAY YEAR, for European as
5760 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5761 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5762 is any number of ISO weeks in the block period for which the item should
5765 This function is here only for backward compatibility and it is deprecated,
5766 please use `org-class' instead."
5767 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5768 (date2 (org-order-calendar-date-args m2 d2 y2)))
5770 (nth 2 date1) (car date1) (nth 1 date1)
5771 (nth 2 date2) (car date2) (nth 1 date2)
5772 dayname skip-weeks)))
5773 (make-obsolete 'org-diary-class 'org-class "")
5775 (defalias 'org-get-closed 'org-agenda-get-progress)
5776 (defun org-agenda-get-progress ()
5777 "Return the logged TODO entries for agenda display."
5778 (let* ((props (list 'mouse-face 'highlight
5779 'org-not-done-regexp org-not-done-regexp
5780 'org-todo-regexp org-todo-regexp
5781 'org-complex-heading-regexp org-complex-heading-regexp
5783 (format "mouse-2 or RET jump to org file %s"
5784 (abbreviate-file-name buffer-file-name))))
5785 (items (if (consp org-agenda-show-log-scoped)
5786 org-agenda-show-log-scoped
5787 (if (eq org-agenda-show-log-scoped 'clockcheck)
5789 org-agenda-log-mode-items)))
5793 (if (memq 'closed items) (concat "\\<" org-closed-string))
5794 (if (memq 'clock items) (concat "\\<" org-clock-string))
5795 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5796 (parts-re (if parts (mapconcat 'identity parts "\\|")
5797 (error "`org-agenda-log-mode-items' is empty")))
5799 "\\(" parts-re "\\)"
5804 (car org-time-stamp-formats)
5805 (apply 'encode-time ; DATE bound by calendar
5806 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5808 (org-agenda-search-headline-for-time nil)
5809 marker hdmarker priority category level tags closedp
5810 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5811 (goto-char (point-min))
5812 (while (re-search-forward regexp nil t)
5815 (setq marker (org-agenda-new-marker (match-beginning 0))
5816 closedp (equal (match-string 1) org-closed-string)
5817 statep (equal (string-to-char (match-string 1)) ?-)
5818 clockp (not (or closedp statep))
5819 state (and statep (match-string 2))
5820 category (org-get-category (match-beginning 0))
5821 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5822 (when (string-match "\\]" timestr)
5823 ;; substring should only run to end of time stamp
5824 (setq rest (substring timestr (match-end 0))
5825 timestr (substring timestr 0 (match-end 0)))
5826 (if (and (not closedp) (not statep)
5827 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5829 (progn (setq timestr (concat (substring timestr 0 -1)
5830 "-" (match-string 1 rest) "]"))
5831 (setq clocked (match-string 2 rest)))
5832 (setq clocked "-")))
5836 ((not org-agenda-log-mode-add-notes) nil)
5838 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5841 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5842 (match-string 1)))))
5843 (if (not (re-search-backward org-outline-regexp-bol nil t))
5845 (goto-char (match-beginning 0))
5846 (setq hdmarker (org-agenda-new-marker)
5848 (or (eq org-agenda-show-inherited-tags 'always)
5849 (and (listp org-agenda-show-inherited-tags)
5850 (memq 'todo org-agenda-show-inherited-tags))
5851 (and (eq org-agenda-show-inherited-tags t)
5852 (or (eq org-agenda-use-tag-inheritance t)
5853 (memq 'todo org-agenda-use-tag-inheritance))))
5854 tags (org-get-tags-at nil (not inherited-tags))
5855 level (make-string (org-reduced-level (org-outline-level)) ? ))
5856 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5857 (setq txt (match-string 1))
5859 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5860 (setq txt (concat (substring txt 0 (match-beginning 1))
5861 " - " extra " " (match-string 2 txt)))
5862 (setq txt (concat txt " - " extra))))
5863 (setq txt (org-agenda-format-item
5865 (closedp "Closed: ")
5866 (statep (concat "State: (" state ")"))
5867 (t (concat "Clocked: (" clocked ")")))
5868 txt level category tags timestr)))
5869 (setq priority 100000)
5870 (org-add-props txt props
5871 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5872 'priority priority 'level level
5873 'type "closed" 'date date
5874 'undone-face 'org-warning 'done-face 'org-agenda-done)
5876 (goto-char (point-at-eol))))
5879 (defun org-agenda-show-clocking-issues ()
5880 "Add overlays, showing issues with clocking.
5881 See also the user option `org-agenda-clock-consistency-checks'."
5883 (let* ((org-time-clocksum-use-effort-durations nil)
5884 (pl org-agenda-clock-consistency-checks)
5885 (re (concat "^[ \t]*"
5888 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5889 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5892 (maxtime (org-hh:mm-string-to-minutes
5893 (or (plist-get pl :max-duration) "24:00")))
5894 (mintime (org-hh:mm-string-to-minutes
5895 (or (plist-get pl :min-duration) 0)))
5896 (maxgap (org-hh:mm-string-to-minutes
5897 ;; default 30:00 means never complain
5898 (or (plist-get pl :max-gap) "30:00")))
5899 (gapok (mapcar 'org-hh:mm-string-to-minutes
5900 (plist-get pl :gap-ok-around)))
5901 (def-face (or (plist-get pl :default-face)
5902 '((:background "DarkRed") (:foreground "white"))))
5903 issue face m te ts dt ov)
5904 (goto-char (point-min))
5905 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5906 (setq issue nil face def-face)
5908 (setq m (org-get-at-bol 'org-marker)
5910 (unless (and m (markerp m))
5911 (setq issue "No valid clock line") (throw 'next t))
5912 (org-with-point-at m
5914 (goto-char (point-at-bol))
5915 (unless (looking-at re)
5916 (error "No valid Clock line")
5918 (unless (match-end 3)
5919 (setq issue "No end time"
5920 face (or (plist-get pl :no-end-time-face) face))
5922 (setq ts (match-string 1)
5925 (apply 'encode-time (org-parse-time-string ts)))
5927 (apply 'encode-time (org-parse-time-string te)))
5930 ((> dt (* 60 maxtime))
5931 ;; a very long clocking chunk
5932 (setq issue (format "Clocking interval is very long: %s"
5933 (org-minutes-to-clocksum-string
5934 (floor (/ (float dt) 60.))))
5935 face (or (plist-get pl :long-face) face)))
5936 ((< dt (* 60 mintime))
5937 ;; a very short clocking chunk
5938 (setq issue (format "Clocking interval is very short: %s"
5939 (org-minutes-to-clocksum-string
5940 (floor (/ (float dt) 60.))))
5941 face (or (plist-get pl :short-face) face)))
5942 ((and (> tlend 0) (< ts tlend))
5943 ;; Two clock entries are overlapping
5944 (setq issue (format "Clocking overlap: %d minutes"
5945 (/ (- tlend ts) 60))
5946 face (or (plist-get pl :overlap-face) face)))
5947 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5948 ;; There is a gap, lets see if we need to report it
5949 (unless (org-agenda-check-clock-gap tlend ts gapok)
5950 (setq issue (format "Clocking gap: %d minutes"
5951 (/ (- ts tlend) 60))
5952 face (or (plist-get pl :gap-face) face))))
5954 (setq tlend (or te tlend) tlstart (or ts tlstart))
5956 ;; OK, there was some issue, add an overlay to show the issue
5957 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5958 (overlay-put ov 'before-string
5961 (format "%-43s" (concat " " issue))
5965 (overlay-put ov 'evaporate t)))))
5967 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5968 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5971 ;; there are no OK times for gaps...
5973 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5974 ;; This is more than 24 hours, so it is OK.
5975 ;; because we have at least one OK time, that must be in the
5976 ;; 24 hour interval.
5978 ;; We have a shorter gap.
5979 ;; Now we have to get the minute of the day when these times are
5980 (let* ((t1dec (decode-time (seconds-to-time t1)))
5981 (t2dec (decode-time (seconds-to-time t2)))
5982 ;; compute the minute on the day
5983 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5984 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5986 ;; if min2 is smaller than min1, this means it is on the next day.
5987 ;; Wrap it to after midnight.
5988 (setq min2 (+ min2 1440)))
5989 ;; Now check if any of the OK times is in the gap
5991 ;; Wrap the time to after midnight if necessary
5992 (if (< x min1) (setq x (+ x 1440)))
5993 ;; Check if in interval
5994 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5996 ;; Nope, this gap is not OK
5999 (defun org-agenda-get-deadlines (&optional with-hour)
6000 "Return the deadline information for agenda display.
6001 When WITH-HOUR is non-nil, only return deadlines with an hour
6002 specification like [h]h:mm."
6003 (let* ((props (list 'mouse-face 'highlight
6004 'org-not-done-regexp org-not-done-regexp
6005 'org-todo-regexp org-todo-regexp
6006 'org-complex-heading-regexp org-complex-heading-regexp
6008 (format "mouse-2 or RET jump to org file %s"
6009 (abbreviate-file-name buffer-file-name))))
6010 (regexp (if with-hour
6011 org-deadline-time-hour-regexp
6012 org-deadline-time-regexp))
6013 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6014 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6015 (dl0 (car org-agenda-deadline-leaders))
6016 (dl1 (nth 1 org-agenda-deadline-leaders))
6017 (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
6018 d2 diff dfrac wdays pos pos1 category level
6019 tags suppress-prewarning ee txt head face s todo-state
6020 show-all upcomingp donep timestr warntime inherited-tags ts-date)
6021 (goto-char (point-min))
6022 (while (re-search-forward regexp nil t)
6025 (setq s (match-string 1)
6027 pos (1- (match-beginning 1))
6028 todo-state (save-match-data (org-get-todo-state))
6029 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6031 org-agenda-repeating-timestamp-show-all))
6032 d2 (org-time-string-to-absolute
6033 s d1 'past show-all (current-buffer) pos)
6035 (setq suppress-prewarning
6036 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
6037 (let ((item (buffer-substring (point-at-bol)
6041 org-scheduled-time-regexp item)
6042 (match-string 1 item)))))))
6045 ;; The current item has a scheduled date (in ds), so
6046 ;; evaluate its prewarning lead time.
6047 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
6048 ;; Use global prewarning-restart lead time.
6049 org-agenda-skip-deadline-prewarning-if-scheduled)
6050 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
6052 ;; Set prewarning to no earlier than scheduled.
6053 (min (- d2 (org-time-string-to-absolute
6054 ds d1 'past show-all (current-buffer) pos))
6055 org-deadline-warning-days))
6056 ;; Set prewarning to deadline.
6058 (setq wdays (if suppress-prewarning
6059 (let ((org-deadline-warning-days suppress-prewarning))
6062 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
6063 upcomingp (and todayp (> diff 0)))
6064 ;; When to show a deadline in the calendar:
6065 ;; If the expiration is within wdays warning time.
6066 ;; Past-due deadlines are only shown on the current date
6067 (if (and (or (and (<= diff wdays)
6068 (and todayp (not org-agenda-only-exact-dates)))
6071 ;; (setq todo-state (org-get-todo-state))
6072 (setq donep (member todo-state org-done-keywords))
6074 (or org-agenda-skip-deadline-if-done
6077 (setq category (org-get-category)
6078 warntime (get-text-property (point) 'org-appt-warntime))
6079 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6081 (goto-char (match-end 0))
6082 (setq pos1 (match-beginning 0))
6083 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6084 (setq inherited-tags
6085 (or (eq org-agenda-show-inherited-tags 'always)
6086 (and (listp org-agenda-show-inherited-tags)
6087 (memq 'agenda org-agenda-show-inherited-tags))
6088 (and (eq org-agenda-show-inherited-tags t)
6089 (or (eq org-agenda-use-tag-inheritance t)
6090 (memq 'agenda org-agenda-use-tag-inheritance))))
6091 tags (org-get-tags-at pos1 (not inherited-tags)))
6092 (setq head (buffer-substring
6094 (progn (skip-chars-forward "^\r\n")
6096 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6098 (concat (substring s (match-beginning 1)) " "))
6099 (setq timestr 'time))
6100 (setq txt (org-agenda-format-item
6101 (cond ((= diff 0) dl0)
6104 (funcall dl1 diff date)
6108 (funcall dl2 diff date)
6109 (format dl2 (if (string= dl2 dl1)
6110 diff (abs diff))))))
6111 head level category tags
6112 (if (not (= diff 0)) nil timestr)))))
6114 (setq face (org-agenda-deadline-face dfrac))
6115 (org-add-props txt props
6116 'org-marker (org-agenda-new-marker pos)
6120 'org-hd-marker (org-agenda-new-marker pos1)
6121 'priority (+ (- diff)
6122 (org-get-priority txt))
6123 'todo-state todo-state
6124 'type (if upcomingp "upcoming-deadline" "deadline")
6125 'date (if upcomingp date d2)
6126 'face (if donep 'org-agenda-done face)
6127 'undone-face face 'done-face 'org-agenda-done)
6131 (defun org-agenda-deadline-face (fraction)
6132 "Return the face to displaying a deadline item.
6133 FRACTION is what fraction of the head-warning time has passed."
6134 (let ((faces org-agenda-deadline-faces) f)
6136 (while (setq f (pop faces))
6137 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6139 (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
6140 "Return the scheduled information for agenda display.
6141 When WITH-HOUR is non-nil, only return scheduled items with
6142 an hour specification like [h]h:mm."
6143 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6144 'org-todo-regexp org-todo-regexp
6145 'org-complex-heading-regexp org-complex-heading-regexp
6146 'done-face 'org-agenda-done
6147 'mouse-face 'highlight
6149 (format "mouse-2 or RET jump to org file %s"
6150 (abbreviate-file-name buffer-file-name))))
6151 (regexp (if with-hour
6152 org-scheduled-time-hour-regexp
6153 org-scheduled-time-regexp))
6154 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6155 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6157 (deadline-position-alist
6158 (mapcar (lambda (a) (and (setq mm (get-text-property
6159 0 'org-hd-marker a))
6160 (cons (marker-position mm) a)))
6162 d2 diff pos pos1 category level tags donep
6163 ee txt head pastschedp todo-state face timestr s habitp show-all
6164 did-habit-check-p warntime inherited-tags ts-date suppress-delay
6166 (goto-char (point-min))
6167 (while (re-search-forward regexp nil t)
6170 (setq s (match-string 1)
6172 pos (1- (match-beginning 1))
6173 todo-state (save-match-data (org-get-todo-state))
6174 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6176 org-agenda-repeating-timestamp-show-all))
6177 d2 (org-time-string-to-absolute
6178 s d1 'past show-all (current-buffer) pos)
6180 warntime (get-text-property (point) 'org-appt-warntime))
6181 (setq pastschedp (and todayp (< diff 0)))
6182 (setq did-habit-check-p nil)
6183 (setq suppress-delay
6184 (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
6185 (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
6188 org-deadline-time-regexp item)
6189 (match-string 1 item)))))))
6192 ;; The current item has a deadline date (in ds), so
6193 ;; evaluate its delay time.
6194 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6195 ;; Use global delay time.
6196 (- org-agenda-skip-scheduled-delay-if-deadline))
6197 ((eq org-agenda-skip-scheduled-delay-if-deadline
6199 ;; Set delay to no later than deadline.
6200 (min (- d2 (org-time-string-to-absolute
6201 ds d1 'past show-all (current-buffer) pos))
6202 org-scheduled-delay-days))
6204 (setq ddays (if suppress-delay
6205 (let ((org-scheduled-delay-days suppress-delay))
6206 (org-get-wdays s t t))
6207 (org-get-wdays s t)))
6208 ;; Use a delay of 0 when there is a repeater and the delay is
6210 (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6211 (< (org-time-string-to-absolute s)
6212 (org-time-string-to-absolute
6213 s d2 'past nil (current-buffer) pos)))
6215 ;; When to show a scheduled item in the calendar:
6216 ;; If it is on or past the date.
6217 (when (or (and (> ddays 0) (= diff (- ddays)))
6218 (and (zerop ddays) (= diff 0))
6219 (and (< (+ diff ddays) 0)
6220 (< (abs diff) org-scheduled-past-days)
6221 (and todayp (not org-agenda-only-exact-dates)))
6222 ;; org-is-habit-p uses org-entry-get, which is expansive
6223 ;; so we go extra mile to only call it once
6225 (boundp 'org-habit-show-all-today)
6226 org-habit-show-all-today
6227 (setq did-habit-check-p t)
6228 (setq habitp (and (functionp 'org-is-habit-p)
6229 (org-is-habit-p)))))
6231 (setq donep (member todo-state org-done-keywords))
6233 (or org-agenda-skip-scheduled-if-done
6235 (and (functionp 'org-is-habit-p)
6238 (setq habitp (if did-habit-check-p habitp
6239 (and (functionp 'org-is-habit-p)
6241 (setq category (org-get-category))
6242 (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
6243 'repeated-after-deadline)
6244 (org-get-deadline-time (point))
6245 (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
6247 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6249 (goto-char (match-end 0))
6250 (setq pos1 (match-beginning 0))
6252 (if (or (not org-habit-show-habits)
6254 (boundp 'org-habit-show-habits-only-for-today)
6255 org-habit-show-habits-only-for-today))
6258 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6259 (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
6261 (setq mm (assoc pos1 deadline-position-alist)))
6263 (setq inherited-tags
6264 (or (eq org-agenda-show-inherited-tags 'always)
6265 (and (listp org-agenda-show-inherited-tags)
6266 (memq 'agenda org-agenda-show-inherited-tags))
6267 (and (eq org-agenda-show-inherited-tags t)
6268 (or (eq org-agenda-use-tag-inheritance t)
6269 (memq 'agenda org-agenda-use-tag-inheritance))))
6271 tags (org-get-tags-at nil (not inherited-tags)))
6272 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6273 (setq head (buffer-substring
6275 (progn (skip-chars-forward "^\r\n") (point))))
6276 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6278 (concat (substring s (match-beginning 1)) " "))
6279 (setq timestr 'time))
6280 (setq txt (org-agenda-format-item
6282 (car org-agenda-scheduled-leaders)
6283 (format (nth 1 org-agenda-scheduled-leaders)
6285 head level category tags
6286 (if (not (= diff 0)) nil timestr)
6291 ((and (not habitp) pastschedp)
6292 'org-scheduled-previously)
6293 (todayp 'org-scheduled-today)
6295 habitp (and habitp (org-habit-parse-todo)))
6296 (org-add-props txt props
6298 'face (if donep 'org-agenda-done face)
6299 'org-marker (org-agenda-new-marker pos)
6300 'org-hd-marker (org-agenda-new-marker pos1)
6301 'type (if pastschedp "past-scheduled" "scheduled")
6302 'date (if pastschedp d2 date)
6306 'priority (if habitp
6307 (org-habit-get-priority habitp)
6308 (+ 94 (- 5 diff) (org-get-priority txt)))
6310 'todo-state todo-state)
6314 (defun org-agenda-get-blocks ()
6315 "Return the date-range information for agenda display."
6316 (let* ((props (list 'face nil
6317 'org-not-done-regexp org-not-done-regexp
6318 'org-todo-regexp org-todo-regexp
6319 'org-complex-heading-regexp org-complex-heading-regexp
6320 'mouse-face 'highlight
6322 (format "mouse-2 or RET jump to org file %s"
6323 (abbreviate-file-name buffer-file-name))))
6324 (regexp org-tr-regexp)
6325 (d0 (calendar-absolute-from-gregorian date))
6326 marker hdmarker ee txt d1 d2 s1 s2 category
6327 level todo-state tags pos head donep inherited-tags)
6328 (goto-char (point-min))
6329 (while (re-search-forward regexp nil t)
6333 (let ((start-time (match-string 1))
6334 (end-time (match-string 2)))
6335 (setq s1 (match-string 1)
6337 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6338 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6339 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6340 ;; Only allow days between the limits, because the normal
6341 ;; date stamps will catch the limits.
6343 (setq todo-state (org-get-todo-state))
6344 (setq donep (member todo-state org-done-keywords))
6345 (if (and donep org-agenda-skip-timestamp-if-done)
6347 (setq marker (org-agenda-new-marker (point))
6348 category (org-get-category))
6349 (if (not (re-search-backward org-outline-regexp-bol nil t))
6351 (goto-char (match-beginning 0))
6352 (setq hdmarker (org-agenda-new-marker (point))
6354 (or (eq org-agenda-show-inherited-tags 'always)
6355 (and (listp org-agenda-show-inherited-tags)
6356 (memq 'agenda org-agenda-show-inherited-tags))
6357 (and (eq org-agenda-show-inherited-tags t)
6358 (or (eq org-agenda-use-tag-inheritance t)
6359 (memq 'agenda org-agenda-use-tag-inheritance))))
6361 tags (org-get-tags-at nil (not inherited-tags)))
6362 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6363 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6364 (setq head (match-string 1))
6366 (if org-agenda-remove-timeranges-from-blocks
6368 "<" (regexp-quote s1) ".*?>"
6370 "<" (regexp-quote s2) ".*?>")
6372 (setq txt (org-agenda-format-item
6374 (nth (if (= d1 d2) 0 1)
6375 org-agenda-timerange-leaders)
6376 (1+ (- d0 d1)) (1+ (- d2 d1)))
6377 head level category tags
6378 (cond ((and (= d1 d0) (= d2 d0))
6379 (concat "<" start-time ">--<" end-time ">"))
6381 (concat "<" start-time ">"))
6383 (concat "<" end-time ">")))
6385 (org-add-props txt props
6386 'org-marker marker 'org-hd-marker hdmarker
6387 'type "block" 'date date
6389 'todo-state todo-state
6390 'priority (org-get-priority txt))
6393 ;; Sort the entries by expiration date.
6396 ;;; Agenda presentation and sorting
6398 (defvar org-prefix-has-time nil
6399 "A flag, set by `org-compile-prefix-format'.
6400 The flag is set if the currently compiled format contains a `%t'.")
6401 (defvar org-prefix-has-tag nil
6402 "A flag, set by `org-compile-prefix-format'.
6403 The flag is set if the currently compiled format contains a `%T'.")
6404 (defvar org-prefix-has-effort nil
6405 "A flag, set by `org-compile-prefix-format'.
6406 The flag is set if the currently compiled format contains a `%e'.")
6407 (defvar org-prefix-has-breadcrumbs nil
6408 "A flag, set by `org-compile-prefix-format'.
6409 The flag is set if the currently compiled format contains a `%b'.")
6410 (defvar org-prefix-category-length nil
6411 "Used by `org-compile-prefix-format' to remember the category field width.")
6412 (defvar org-prefix-category-max-length nil
6413 "Used by `org-compile-prefix-format' to remember the category field width.")
6415 (defun org-agenda-get-category-icon (category)
6416 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6417 (dolist (entry org-agenda-category-icon-alist)
6418 (when (org-string-match-p (car entry) category)
6419 (if (listp (cadr entry))
6420 (return (cadr entry))
6421 (return (apply 'create-image (cdr entry)))))))
6423 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6425 "Format TXT to be inserted into the agenda buffer.
6426 In particular, add the prefix and corresponding text properties.
6428 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6429 LEVEL may be a string to replace the `%l' specifier.
6430 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6431 category taken from local variable or file name. It will replace the `%c'
6432 specifier in the format.
6433 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6434 TXT for sorting of this entry, and for the `%t' specifier in the format.
6435 When DOTIME is a string, this string is searched for a time before TXT is.
6436 TAGS can be the tags of the headline.
6437 Any match of REMOVE-RE will be removed from TXT."
6438 ;; We keep the org-prefix-* variable values along with a compiled
6439 ;; formatter, so that multiple agendas existing at the same time do
6440 ;; not step on each other toes.
6442 ;; It was inconvenient to make these variables buffer local in
6443 ;; Agenda buffers, because this function expects to be called with
6444 ;; the buffer where item comes from being current, and not agenda
6446 (let* ((bindings (car org-prefix-format-compiled))
6447 (formatter (cadr org-prefix-format-compiled)))
6448 (loop for (var value) in bindings
6451 ;; Diary entries sometimes have extra whitespace at the beginning
6452 (setq txt (org-trim txt))
6454 ;; Fix the tags part in txt
6455 (setq txt (org-agenda-fix-displayed-tags
6457 org-agenda-show-inherited-tags
6458 org-agenda-hide-tags-regexp))
6460 (let* ((category (or category
6461 (if buffer-file-name
6462 (file-name-sans-extension
6463 (file-name-nondirectory buffer-file-name))
6465 (category-icon (org-agenda-get-category-icon category))
6466 (category-icon (if category-icon
6467 (propertize " " 'display category-icon)
6469 (effort (and (not (string= txt ""))
6470 (get-text-property 1 'effort txt)))
6471 ;; time, tag, effort are needed for the eval of the prefix format
6472 (tag (if tags (nth (1- (length tags)) tags) ""))
6474 (ts (if dotime (concat
6475 (if (stringp dotime) dotime "")
6476 (and org-agenda-search-headline-for-time txt))))
6477 (time-of-day (and dotime (org-get-time-of-day ts)))
6478 stamp plain s0 s1 s2 rtn srp l
6479 duration breadcrumbs)
6480 (and (derived-mode-p 'org-mode) buffer-file-name
6481 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6482 (when (and dotime time-of-day)
6483 ;; Extract starting and ending time and move them to prefix
6484 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6485 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6486 (setq s0 (match-string 0 ts)
6487 srp (and stamp (match-end 3))
6488 s1 (match-string (if plain 1 2) ts)
6489 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6491 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6492 ;; them, we might want to remove them there to avoid duplication.
6493 ;; The user can turn this off with a variable.
6494 (if (and org-prefix-has-time
6495 org-agenda-remove-times-when-in-prefix (or stamp plain)
6496 (string-match (concat (regexp-quote s0) " *") txt)
6497 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6498 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6499 (= (match-beginning 0) 0)
6501 (setq txt (replace-match "" nil nil txt))))
6502 ;; Normalize the time(s) to 24 hour
6503 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6504 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6506 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6507 (let (org-time-clocksum-use-effort-durations)
6508 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6510 (org-minutes-to-clocksum-string
6511 (+ (org-hh:mm-string-to-minutes s1)
6512 org-agenda-default-appointment-duration)))))
6514 ;; Compute the duration
6516 (setq duration (- (org-hh:mm-string-to-minutes s2)
6517 (org-hh:mm-string-to-minutes s1)))))
6519 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6521 ;; Tags are in the string
6522 (if (or (eq org-agenda-remove-tags t)
6523 (and org-agenda-remove-tags
6524 org-prefix-has-tag))
6525 (setq txt (replace-match "" t t txt))
6526 (setq txt (replace-match
6527 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6528 (match-string 2 txt))
6532 (while (string-match remove-re txt)
6533 (setq txt (replace-match "" t t txt))))
6535 ;; Set org-heading property on `txt' to mark the start of the
6537 (add-text-properties 0 (length txt) '(org-heading t) txt)
6539 ;; Prepare the variables needed in the eval of the compiled format
6540 (if org-prefix-has-breadcrumbs
6541 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6542 (let ((s (org-display-outline-path nil nil "->" t)))
6543 (if (eq "" s) "" (concat s "->"))))))
6544 (setq time (cond (s2 (concat
6545 (org-agenda-time-of-day-to-ampm-maybe s1)
6546 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6547 (if org-agenda-timegrid-use-ampm " ")))
6549 (org-agenda-time-of-day-to-ampm-maybe s1)
6550 (if org-agenda-timegrid-use-ampm
6554 extra (or (and (not habitp) extra) "")
6555 category (if (symbolp category) (symbol-name category) category)
6556 level (or level ""))
6557 (if (string-match org-bracket-link-regexp category)
6559 (setq l (if (match-end 3)
6560 (- (match-end 3) (match-beginning 3))
6561 (- (match-end 1) (match-beginning 1))))
6562 (when (< l (or org-prefix-category-length 0))
6563 (setq category (copy-sequence category))
6564 (org-add-props category nil
6565 'extra-space (make-string
6566 (- org-prefix-category-length l 1) ?\ ))))
6567 (if (and org-prefix-category-max-length
6568 (>= (length category) org-prefix-category-max-length))
6569 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6570 ;; Evaluate the compiled format
6571 (setq rtn (concat (eval formatter) txt))
6573 ;; And finally add the text properties
6574 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6575 (org-add-props rtn nil
6576 'org-category category
6577 'tags (mapcar 'org-downcase-keep-props tags)
6578 'org-highest-priority org-highest-priority
6579 'org-lowest-priority org-lowest-priority
6580 'time-of-day time-of-day
6582 'breadcrumbs breadcrumbs
6587 'format org-prefix-format-compiled
6590 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6591 "Remove tags string from TXT, and add a modified list of tags.
6592 The modified list may contain inherited tags, and tags matched by
6593 `org-agenda-hide-tags-regexp' will be removed."
6594 (when (or add-inherited hide-re)
6595 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6596 (setq txt (substring txt 0 (match-beginning 0))))
6599 (mapcar (lambda (tg)
6600 (if (or (and hide-re (string-match hide-re tg))
6601 (and (not add-inherited)
6602 (get-text-property 0 'inherited tg)))
6607 (let ((have-i (get-text-property 0 'inherited (car tags)))
6609 (setq txt (concat txt " :"
6612 (setq i (get-text-property 0 'inherited x))
6613 (if (and have-i (not i))
6619 (if have-i "::" ":"))))))
6622 (defun org-downcase-keep-props (s)
6623 (let ((props (text-properties-at 0 s)))
6624 (setq s (downcase s))
6625 (add-text-properties 0 (length s) props s)
6628 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6630 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6631 "Add a time-grid for agenda items which need it.
6633 LIST is the list of agenda items formatted by `org-agenda-list'.
6634 NDAYS is the span of the current agenda view.
6635 TODAYP is `t' when the current agenda view is on today."
6637 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6638 ((and todayp (member 'today (car org-agenda-time-grid))))
6639 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6640 ((member 'weekly (car org-agenda-time-grid)))
6641 (t (throw 'exit list)))
6642 (let* ((have (delq nil (mapcar
6643 (lambda (x) (get-text-property 1 'time-of-day x))
6645 (string (nth 1 org-agenda-time-grid))
6646 (gridtimes (nth 2 org-agenda-time-grid))
6647 (req (car org-agenda-time-grid))
6648 (remove (member 'remove-match req))
6650 (if (and (member 'require-timed req) (not have))
6651 ;; don't show empty grid
6653 (while (setq time (pop gridtimes))
6654 (unless (and remove (member time have))
6655 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6656 (push (org-agenda-format-item
6657 nil string nil "" nil
6658 (concat (substring time 0 -2) ":" (substring time -2)))
6661 2 (length (car new)) 'face 'org-time-grid (car new))))
6662 (when (and todayp org-agenda-show-current-time-in-grid)
6663 (push (org-agenda-format-item
6664 nil org-agenda-current-time-string nil "" nil
6665 (format-time-string "%H:%M "))
6668 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6670 (if (member 'time-up org-agenda-sorting-strategy-selected)
6672 (append list new)))))
6674 (defun org-compile-prefix-format (key)
6675 "Compile the prefix format into a Lisp form that can be evaluated.
6676 The resulting form and associated variable bindings is returned
6677 and stored in the variable `org-prefix-format-compiled'."
6678 (setq org-prefix-has-time nil
6679 org-prefix-has-tag nil
6680 org-prefix-category-length nil
6681 org-prefix-has-effort nil
6682 org-prefix-has-breadcrumbs nil)
6684 ((stringp org-agenda-prefix-format)
6685 org-agenda-prefix-format)
6686 ((assq key org-agenda-prefix-format)
6687 (cdr (assq key org-agenda-prefix-format)))
6688 (t " %-12:c%?-12t% s")))
6690 varform vars var e c f opt)
6691 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6693 (setq var (or (cdr (assoc (match-string 4 s)
6694 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6695 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6697 c (or (match-string 3 s) "")
6698 opt (match-beginning 1)
6699 start (1+ (match-beginning 0)))
6700 (if (equal var 'time) (setq org-prefix-has-time t))
6701 (if (equal var 'tag) (setq org-prefix-has-tag t))
6702 (if (equal var 'effort) (setq org-prefix-has-effort t))
6703 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6704 (setq f (concat "%" (match-string 2 s) "s"))
6705 (when (equal var 'category)
6706 (setq org-prefix-category-length
6707 (floor (abs (string-to-number (match-string 2 s)))))
6708 (setq org-prefix-category-max-length
6709 (let ((x (match-string 2 s)))
6711 (if (string-match "\\.[0-9]+" x)
6712 (string-to-number (substring (match-string 0 x) 1)))))))
6714 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6717 `(if (or (equal "" ,var) (equal nil ,var))
6719 (format ,f (concat ,var ,c))))
6721 `(format ,f (if (or (equal ,var "")
6722 (equal ,var nil)) ""
6723 (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6724 (setq s (replace-match "%s" t nil s))
6725 (push varform vars))
6726 (setq vars (nreverse vars))
6727 (with-current-buffer (or org-agenda-buffer (current-buffer))
6728 (setq org-prefix-format-compiled
6730 `((org-prefix-has-time ,org-prefix-has-time)
6731 (org-prefix-has-tag ,org-prefix-has-tag)
6732 (org-prefix-category-length ,org-prefix-category-length)
6733 (org-prefix-has-effort ,org-prefix-has-effort)
6734 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6735 `(format ,s ,@vars))))))
6737 (defun org-set-sorting-strategy (key)
6738 (if (symbolp (car org-agenda-sorting-strategy))
6740 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6741 (setq org-agenda-sorting-strategy-selected
6742 (or (cdr (assq key org-agenda-sorting-strategy))
6743 (cdr (assq 'agenda org-agenda-sorting-strategy))
6744 '(time-up category-keep priority-down)))))
6746 (defun org-get-time-of-day (s &optional string mod24)
6747 "Check string S for a time of day.
6748 If found, return it as a military time number between 0 and 2400.
6749 If not found, return nil.
6750 The optional STRING argument forces conversion into a 5 character wide string
6755 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6756 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6757 (not (eq (get-text-property 1 'face s) 'org-link)))
6758 (let* ((h (string-to-number (match-string 1 s)))
6759 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6760 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6761 (am-p (equal ampm "am"))
6762 (h1 (cond ((not ampm) h)
6763 ((= h 12) (if am-p 0 12))
6764 (t (+ h (if am-p 0 12)))))
6765 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6767 (t0 (+ (* 100 h2) m))
6768 (t1 (concat (if (>= h1 24) "+" " ")
6769 (if (and org-agenda-time-leading-zero
6770 (< t0 1000)) "0" "")
6771 (if (< t0 100) "0" "")
6772 (if (< t0 10) "0" "")
6773 (int-to-string t0))))
6774 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6776 (defvar org-agenda-before-sorting-filter-function nil
6777 "Function to be applied to agenda items prior to sorting.
6778 Prior to sorting also means just before they are inserted into the agenda.
6780 To aid sorting, you may revisit the original entries and add more text
6781 properties which will later be used by the sorting functions.
6783 The function should take a string argument, an agenda line.
6784 It has access to the text properties in that line, which contain among
6785 other things, the property `org-hd-marker' that points to the entry
6786 where the line comes from. Note that not all lines going into the agenda
6787 have this property, only most.
6789 The function should return the modified string. It is probably best
6790 to ONLY change text properties.
6792 You can also use this function as a filter, by returning nil for lines
6793 you don't want to have in the agenda at all. For this application, you
6794 could bind the variable in the options section of a custom command.")
6796 (defun org-agenda-finalize-entries (list &optional type)
6797 "Sort, limit and concatenate the LIST of agenda items.
6798 The optional argument TYPE tells the agenda type."
6799 (let ((max-effort (cond ((listp org-agenda-max-effort)
6800 (cdr (assoc type org-agenda-max-effort)))
6801 (t org-agenda-max-effort)))
6802 (max-todo (cond ((listp org-agenda-max-todos)
6803 (cdr (assoc type org-agenda-max-todos)))
6804 (t org-agenda-max-todos)))
6805 (max-tags (cond ((listp org-agenda-max-tags)
6806 (cdr (assoc type org-agenda-max-tags)))
6807 (t org-agenda-max-tags)))
6808 (max-entries (cond ((listp org-agenda-max-entries)
6809 (cdr (assoc type org-agenda-max-entries)))
6810 (t org-agenda-max-entries))))
6811 (when org-agenda-before-sorting-filter-function
6815 org-agenda-before-sorting-filter-function list))))
6816 (setq list (mapcar 'org-agenda-highlight-todo list)
6817 list (mapcar 'identity (sort list 'org-entries-lessp)))
6819 (setq list (org-agenda-limit-entries
6820 list 'effort-minutes max-effort
6821 (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
6824 (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
6826 (setq list (org-agenda-limit-entries list 'tags max-tags)))
6828 (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
6829 (mapconcat 'identity list "\n")))
6831 (defun org-agenda-limit-entries (list prop limit &optional fn)
6832 "Limit the number of agenda entries."
6833 (let ((include (and limit (< limit 0))))
6835 (let ((fun (or fn (lambda (p) (if p 1))))
6840 (let ((pval (funcall
6841 fun (get-text-property (1- (length e))
6843 (if pval (setq lim (+ lim pval)))
6844 (cond ((and pval (<= lim (abs limit))) e)
6845 ((and include (not pval)) e))))
6849 (defun org-agenda-limit-interactively (remove)
6850 "In agenda, interactively limit entries to various maximums."
6853 (progn (setq org-agenda-max-entries nil
6854 org-agenda-max-todos nil
6855 org-agenda-max-tags nil
6856 org-agenda-max-effort nil)
6858 (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
6859 (msg (cond ((= max ?E) "How many minutes? ")
6860 ((= max ?e) "How many entries? ")
6861 ((= max ?t) "How many TODO entries? ")
6862 ((= max ?T) "How many tagged entries? ")
6863 (t (user-error "Wrong input"))))
6864 (num (string-to-number (read-from-minibuffer msg))))
6865 (cond ((equal max ?e)
6866 (let ((org-agenda-max-entries num)) (org-agenda-redo)))
6868 (let ((org-agenda-max-todos num)) (org-agenda-redo)))
6870 (let ((org-agenda-max-tags num)) (org-agenda-redo)))
6872 (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
6873 (org-agenda-fit-window-to-buffer))
6875 (defun org-agenda-highlight-todo (x)
6876 (let ((org-done-keywords org-done-keywords-for-agenda)
6877 (case-fold-search nil)
6881 (beginning-of-line 1)
6882 (setq re (org-get-at-bol 'org-todo-regexp))
6883 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6884 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6885 (add-text-properties (match-beginning 0) (match-end 1)
6886 (list 'face (org-get-todo-face 1)))
6887 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6888 (delete-region (match-beginning 1) (1- (match-end 0)))
6889 (goto-char (match-beginning 1))
6890 (insert (format org-agenda-todo-keyword-format s)))))
6891 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6892 (setq re (get-text-property 0 'org-todo-regexp x))
6894 ;; Test `pl' because if there's no heading content,
6895 ;; there's no point matching to highlight. Note
6896 ;; that if we didn't test `pl' first, and there
6897 ;; happened to be no keyword from `org-todo-regexp'
6898 ;; on this heading line, then the `equal' comparison
6899 ;; afterwards would spuriously succeed in the case
6900 ;; where `pl' is nil -- causing an args-out-of-range
6901 ;; error when we try to add text properties to text
6902 ;; that isn't there.
6904 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6906 (add-text-properties
6907 (or (match-end 1) (match-end 0)) (match-end 0)
6908 (list 'face (org-get-todo-face (match-string 2 x)))
6911 (setq x (concat (substring x 0 (match-end 1))
6912 (format org-agenda-todo-keyword-format
6914 (org-add-props " " (text-properties-at 0 x))
6915 (substring x (match-end 3)))))))
6918 (defsubst org-cmp-values (a b property)
6919 "Compare the numeric value of text PROPERTY for string A and B."
6920 (let ((pa (or (get-text-property (1- (length a)) property a) 0))
6921 (pb (or (get-text-property (1- (length b)) property b) 0)))
6922 (cond ((> pa pb) +1)
6925 (defsubst org-cmp-effort (a b)
6926 "Compare the effort values of string A and B."
6927 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6928 (ea (or (get-text-property (1- (length a)) 'effort-minutes a) def))
6929 (eb (or (get-text-property (1- (length b)) 'effort-minutes b) def)))
6930 (cond ((> ea eb) +1)
6933 (defsubst org-cmp-category (a b)
6934 "Compare the string values of categories of strings A and B."
6935 (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
6936 (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
6937 (cond ((string-lessp ca cb) -1)
6938 ((string-lessp cb ca) +1))))
6940 (defsubst org-cmp-todo-state (a b)
6941 "Compare the todo states of strings A and B."
6942 (let* ((ma (or (get-text-property 1 'org-marker a)
6943 (get-text-property 1 'org-hd-marker a)))
6944 (mb (or (get-text-property 1 'org-marker b)
6945 (get-text-property 1 'org-hd-marker b)))
6946 (fa (and ma (marker-buffer ma)))
6947 (fb (and mb (marker-buffer mb)))
6949 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6950 (and fb (with-current-buffer fb org-todo-keywords-1))))
6951 (ta (or (get-text-property 1 'todo-state a) ""))
6952 (tb (or (get-text-property 1 'todo-state b) ""))
6953 (la (- (length (member ta todo-kwds))))
6954 (lb (- (length (member tb todo-kwds))))
6955 (donepa (member ta org-done-keywords-for-agenda))
6956 (donepb (member tb org-done-keywords-for-agenda)))
6957 (cond ((and donepa (not donepb)) -1)
6958 ((and (not donepa) donepb) +1)
6962 (defsubst org-cmp-alpha (a b)
6963 "Compare the headlines, alphabetically."
6964 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6965 (plb (text-property-any 0 (length b) 'org-heading t b))
6966 (ta (and pla (substring a pla)))
6967 (tb (and plb (substring b plb))))
6969 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6970 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6971 (setq ta (substring ta (match-end 0))))
6972 (setq ta (downcase ta)))
6974 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6975 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6976 (setq tb (substring tb (match-end 0))))
6977 (setq tb (downcase tb)))
6980 ((string-lessp ta tb) -1)
6981 ((string-lessp tb ta) +1))))
6983 (defsubst org-cmp-tag (a b)
6984 "Compare the string values of the first tags of A and B."
6985 (let ((ta (car (last (get-text-property 1 'tags a))))
6986 (tb (car (last (get-text-property 1 'tags b)))))
6989 ((string-lessp ta tb) -1)
6990 ((string-lessp tb ta) +1))))
6992 (defsubst org-cmp-time (a b)
6993 "Compare the time-of-day values of strings A and B."
6994 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6995 (ta (or (get-text-property 1 'time-of-day a) def))
6996 (tb (or (get-text-property 1 'time-of-day b) def)))
6997 (cond ((< ta tb) -1)
7000 (defsubst org-cmp-ts (a b type)
7001 "Compare the timestamps values of entries A and B.
7002 When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
7003 \"timestamp_ia\", compare within each of these type. When TYPE
7004 is the empty string, compare all timestamps without respect of
7006 (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
7007 (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
7008 (get-text-property 1 'ts-date a))
7010 (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
7011 (get-text-property 1 'ts-date b))
7013 (cond ((< ta tb) -1)
7016 (defsubst org-cmp-habit-p (a b)
7017 "Compare the todo states of strings A and B."
7018 (let ((ha (get-text-property 1 'org-habit-p a))
7019 (hb (get-text-property 1 'org-habit-p b)))
7020 (cond ((and ha (not hb)) -1)
7021 ((and (not ha) hb) +1))))
7023 (defun org-entries-lessp (a b)
7024 "Predicate for sorting agenda entries."
7025 ;; The following variables will be used when the form is evaluated.
7026 ;; So even though the compiler complains, keep them.
7027 (let* ((ss org-agenda-sorting-strategy-selected)
7028 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
7029 (org-cmp-ts a b "")))
7030 (timestamp-down (if timestamp-up (- timestamp-up) nil))
7031 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
7032 (org-cmp-ts a b "scheduled")))
7033 (scheduled-down (if scheduled-up (- scheduled-up) nil))
7034 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
7035 (org-cmp-ts a b "deadline")))
7036 (deadline-down (if deadline-up (- deadline-up) nil))
7037 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
7038 (org-cmp-ts a b "timestamp_ia")))
7039 (tsia-down (if tsia-up (- tsia-up) nil))
7040 (ts-up (and (org-em 'ts-up 'ts-down ss)
7041 (org-cmp-ts a b "timestamp")))
7042 (ts-down (if ts-up (- ts-up) nil))
7043 (time-up (and (org-em 'time-up 'time-down ss)
7044 (org-cmp-time a b)))
7045 (time-down (if time-up (- time-up) nil))
7046 (stats-up (and (org-em 'stats-up 'stats-down ss)
7047 (org-cmp-values a b 'org-stats)))
7048 (stats-down (if stats-up (- stats-up) nil))
7049 (priority-up (and (org-em 'priority-up 'priority-down ss)
7050 (org-cmp-values a b 'priority)))
7051 (priority-down (if priority-up (- priority-up) nil))
7052 (effort-up (and (org-em 'effort-up 'effort-down ss)
7053 (org-cmp-effort a b)))
7054 (effort-down (if effort-up (- effort-up) nil))
7055 (category-up (and (or (org-em 'category-up 'category-down ss)
7056 (memq 'category-keep ss))
7057 (org-cmp-category a b)))
7058 (category-down (if category-up (- category-up) nil))
7059 (category-keep (if category-up +1 nil))
7060 (tag-up (and (org-em 'tag-up 'tag-down ss)
7062 (tag-down (if tag-up (- tag-up) nil))
7063 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
7064 (org-cmp-todo-state a b)))
7065 (todo-state-down (if todo-state-up (- todo-state-up) nil))
7066 (habit-up (and (org-em 'habit-up 'habit-down ss)
7067 (org-cmp-habit-p a b)))
7068 (habit-down (if habit-up (- habit-up) nil))
7069 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
7070 (org-cmp-alpha a b)))
7071 (alpha-down (if alpha-up (- alpha-up) nil))
7072 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
7073 user-defined-up user-defined-down)
7074 (if (and need-user-cmp org-agenda-cmp-user-defined
7075 (functionp org-agenda-cmp-user-defined))
7076 (setq user-defined-up
7077 (funcall org-agenda-cmp-user-defined a b)
7078 user-defined-down (if user-defined-up (- user-defined-up) nil)))
7080 (eval (cons 'or org-agenda-sorting-strategy-selected))
7081 '((-1 . t) (1 . nil) (nil . nil))))))
7083 ;;; Agenda restriction lock
7085 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
7086 "Overlay to mark the headline to which agenda commands are restricted.")
7087 (overlay-put org-agenda-restriction-lock-overlay
7088 'face 'org-agenda-restriction-lock)
7089 (overlay-put org-agenda-restriction-lock-overlay
7090 'help-echo "Agendas are currently limited to this subtree.")
7091 (org-detach-overlay org-agenda-restriction-lock-overlay)
7094 (defun org-agenda-set-restriction-lock (&optional type)
7095 "Set restriction lock for agenda, to current subtree or file.
7096 Restriction will be the file if TYPE is `file', or if type is the
7097 universal prefix '(4), or if the cursor is before the first headline
7098 in the file. Otherwise, restriction will be to the current subtree."
7100 (org-agenda-remove-restriction-lock 'noupdate)
7101 (and (equal type '(4)) (setq type 'file))
7104 ((org-at-heading-p) 'subtree)
7105 ((condition-case nil (org-back-to-heading t) (error nil))
7108 (if (eq type 'subtree)
7110 (setq org-agenda-restrict (current-buffer))
7111 (setq org-agenda-overriding-restriction 'subtree)
7112 (put 'org-agenda-files 'org-restrict
7113 (list (buffer-file-name (buffer-base-buffer))))
7114 (org-back-to-heading t)
7115 (move-overlay org-agenda-restriction-lock-overlay
7117 (if org-agenda-restriction-lock-highlight-subtree
7118 (save-excursion (org-end-of-subtree t t) (point))
7120 (move-marker org-agenda-restrict-begin (point))
7121 (move-marker org-agenda-restrict-end
7122 (save-excursion (org-end-of-subtree t t)))
7123 (message "Locking agenda restriction to subtree"))
7124 (put 'org-agenda-files 'org-restrict
7125 (list (buffer-file-name (buffer-base-buffer))))
7126 (setq org-agenda-restrict nil)
7127 (setq org-agenda-overriding-restriction 'file)
7128 (move-marker org-agenda-restrict-begin nil)
7129 (move-marker org-agenda-restrict-end nil)
7130 (message "Locking agenda restriction to file"))
7131 (setq current-prefix-arg nil)
7132 (org-agenda-maybe-redo))
7134 (defun org-agenda-remove-restriction-lock (&optional noupdate)
7135 "Remove the agenda restriction lock."
7137 (org-detach-overlay org-agenda-restriction-lock-overlay)
7138 (org-detach-overlay org-speedbar-restriction-lock-overlay)
7139 (setq org-agenda-overriding-restriction nil)
7140 (setq org-agenda-restrict nil)
7141 (put 'org-agenda-files 'org-restrict nil)
7142 (move-marker org-agenda-restrict-begin nil)
7143 (move-marker org-agenda-restrict-end nil)
7144 (setq current-prefix-arg nil)
7145 (message "Agenda restriction lock removed")
7146 (or noupdate (org-agenda-maybe-redo)))
7148 (defun org-agenda-maybe-redo ()
7149 "If there is any window showing the agenda view, update it."
7150 (let ((w (get-buffer-window org-agenda-buffer-name t))
7151 (w0 (selected-window)))
7156 (if org-agenda-overriding-restriction
7157 (message "Agenda view shifted to new %s restriction"
7158 org-agenda-overriding-restriction)
7159 (message "Agenda restriction lock removed")))))
7163 (defun org-agenda-check-type (error &rest types)
7164 "Check if agenda buffer is of allowed type.
7165 If ERROR is non-nil, throw an error, otherwise just return nil.
7166 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
7167 (if (not org-agenda-type)
7168 (error "No Org agenda currently displayed")
7169 (if (memq org-agenda-type types)
7172 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7175 (defun org-agenda-Quit ()
7176 "Exit the agenda and kill buffers loaded by `org-agenda'.
7177 Also restore the window configuration."
7179 (if org-agenda-columns-active
7181 (let ((buf (current-buffer)))
7182 (if (eq org-agenda-window-setup 'other-frame)
7184 (org-agenda-reset-markers)
7186 (org-columns-remove-overlays)
7187 (setq org-agenda-archives-mode nil)
7189 (and (not (eq org-agenda-window-setup 'current-window))
7190 (not (one-window-p))
7192 (org-agenda-reset-markers)
7194 (org-columns-remove-overlays)
7195 (setq org-agenda-archives-mode nil)))
7196 (setq org-agenda-buffer nil)
7197 ;; Maybe restore the pre-agenda window configuration.
7198 (and org-agenda-restore-windows-after-quit
7199 (not (eq org-agenda-window-setup 'other-frame))
7200 org-agenda-pre-window-conf
7201 (set-window-configuration org-agenda-pre-window-conf)
7202 (setq org-agenda-pre-window-conf nil))))
7204 (defun org-agenda-quit ()
7205 "Exit the agenda and restore the window configuration.
7206 When `org-agenda-sticky' is non-nil, only bury the agenda."
7208 (if (and (eq org-indirect-buffer-display 'other-window)
7209 org-last-indirect-buffer)
7210 (let ((org-last-indirect-window
7211 (get-buffer-window org-last-indirect-buffer)))
7212 (if org-last-indirect-window
7213 (delete-window org-last-indirect-window))))
7214 (if org-agenda-columns-active
7216 (if org-agenda-sticky
7217 (let ((buf (current-buffer)))
7218 (if (eq org-agenda-window-setup 'other-frame)
7221 (and (not (eq org-agenda-window-setup 'current-window))
7222 (not (one-window-p))
7224 (with-current-buffer buf
7226 ;; Maybe restore the pre-agenda window configuration.
7227 (and org-agenda-restore-windows-after-quit
7228 (not (eq org-agenda-window-setup 'other-frame))
7229 org-agenda-pre-window-conf
7230 (set-window-configuration org-agenda-pre-window-conf)
7231 (setq org-agenda-pre-window-conf nil))))
7232 (org-agenda-Quit))))
7234 (defun org-agenda-exit ()
7235 "Exit the agenda and restore the window configuration.
7236 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7237 buffers visited directly by the user will not be touched."
7239 (org-release-buffers org-agenda-new-buffers)
7240 (setq org-agenda-new-buffers nil)
7243 (defun org-agenda-kill-all-agenda-buffers ()
7244 "Kill all buffers in `org-agenda-mode'.
7245 This is used when toggling sticky agendas.
7246 You can also explicitly invoke it with `C-c a C-k'."
7249 (dolist (buf (buffer-list))
7250 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7252 (mapc 'kill-buffer blist)))
7254 (defun org-agenda-execute (arg)
7255 "Execute another agenda command, keeping same window.
7256 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7259 (let ((org-agenda-window-setup 'current-window))
7262 (defun org-agenda-redo (&optional all)
7263 "Rebuild possibly ALL agenda view(s) in the current buffer."
7265 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7266 (cpa (unless (eq all t) current-prefix-arg))
7267 (org-agenda-doing-sticky-redo org-agenda-sticky)
7268 (org-agenda-sticky nil)
7269 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7270 org-agenda-buffer-name))
7271 (org-agenda-keep-modes t)
7272 (tag-filter org-agenda-tag-filter)
7273 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7274 (top-hl-filter org-agenda-top-headline-filter)
7275 (cat-filter org-agenda-category-filter)
7276 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7277 (re-filter org-agenda-regexp-filter)
7278 (re-preset (get 'org-agenda-regexp-filter :preset-filter))
7279 (effort-filter org-agenda-effort-filter)
7280 (effort-preset (get 'org-agenda-effort-filter :preset-filter))
7281 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7282 (cols org-agenda-columns-active)
7283 (line (org-current-line))
7284 (window-line (- line (org-current-line (window-start))))
7285 (lprops (get 'org-agenda-redo-command 'org-lprops))
7286 (redo-cmd (get-text-property p 'org-redo-cmd))
7287 (last-args (get-text-property p 'org-last-args))
7288 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7289 (org-agenda-overriding-cmd-arguments
7291 (cond ((listp last-args)
7292 (cons (or cpa (car last-args)) (cdr last-args)))
7293 ((stringp last-args)
7295 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7296 (put 'org-agenda-tag-filter :preset-filter nil)
7297 (put 'org-agenda-category-filter :preset-filter nil)
7298 (put 'org-agenda-regexp-filter :preset-filter nil)
7299 (put 'org-agenda-effort-filter :preset-filter nil)
7300 (and cols (org-columns-quit))
7301 (message "Rebuilding agenda buffer...")
7303 (eval series-redo-cmd)
7304 (org-let lprops redo-cmd))
7305 (setq org-agenda-undo-list nil
7306 org-agenda-pending-undo-list nil
7307 org-agenda-tag-filter tag-filter
7308 org-agenda-category-filter cat-filter
7309 org-agenda-regexp-filter re-filter
7310 org-agenda-effort-filter effort-filter
7311 org-agenda-top-headline-filter top-hl-filter)
7312 (message "Rebuilding agenda buffer...done")
7313 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7314 (put 'org-agenda-category-filter :preset-filter cat-preset)
7315 (put 'org-agenda-regexp-filter :preset-filter re-preset)
7316 (put 'org-agenda-effort-filter :preset-filter effort-preset)
7317 (let ((tag (or tag-filter tag-preset))
7318 (cat (or cat-filter cat-preset))
7319 (effort (or effort-filter effort-preset))
7320 (re (or re-filter re-preset)))
7321 (when tag (org-agenda-filter-apply tag 'tag))
7322 (when cat (org-agenda-filter-apply cat 'category))
7323 (when effort (org-agenda-filter-apply effort 'effort))
7324 (when re (org-agenda-filter-apply re 'regexp)))
7325 (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
7326 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7327 (org-goto-line line)
7328 (recenter window-line)))
7330 (defvar org-global-tags-completion-table nil)
7331 (defvar org-agenda-filter-form nil)
7332 (defvar org-agenda-filtered-by-category nil)
7334 (defun org-agenda-filter-by-category (strip)
7335 "Keep only those lines in the agenda buffer that have a specific category.
7336 The category is that of the current line."
7338 (if (and org-agenda-filtered-by-category
7339 org-agenda-category-filter)
7340 (org-agenda-filter-show-all-cat)
7341 (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
7344 (org-agenda-filter-apply
7345 (push (concat "-" cat) org-agenda-category-filter) 'category))
7347 (org-agenda-filter-apply
7348 (setq org-agenda-category-filter
7349 (list (concat "+" cat))) 'category))
7350 (t (error "No category at point"))))))
7352 (defun org-find-top-headline (&optional pos)
7353 "Find the topmost parent headline and return it."
7355 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7356 (if pos (goto-char pos))
7357 ;; Skip up to the topmost parent
7358 (while (ignore-errors (outline-up-heading 1) t))
7360 (nth 4 (org-heading-components))))))
7362 (defvar org-agenda-filtered-by-top-headline nil)
7363 (defun org-agenda-filter-by-top-headline (strip)
7364 "Keep only those lines that are descendants from the same top headline.
7365 The top headline is that of the current line."
7367 (if org-agenda-filtered-by-top-headline
7369 (setq org-agenda-filtered-by-top-headline nil
7370 org-agenda-top-headline-filter nil)
7371 (org-agenda-filter-show-all-top-filter))
7372 (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
7373 (if toph (org-agenda-filter-top-headline-apply toph strip)
7374 (error "No top-level headline at point")))))
7376 (defvar org-agenda-regexp-filter nil)
7377 (defun org-agenda-filter-by-regexp (strip)
7378 "Filter agenda entries by a regular expression.
7379 Regexp filters are cumulative.
7380 With no prefix argument, keep entries matching the regexp.
7381 With one prefix argument, filter out entries matching the regexp.
7382 With two prefix arguments, remove the regexp filters."
7384 (if (not (equal strip '(16)))
7385 (let ((flt (concat (if (equal strip '(4)) "-" "+")
7386 (read-from-minibuffer
7387 (if (equal strip '(4))
7388 "Filter out entries matching regexp: "
7389 "Narrow to entries matching regexp: ")))))
7390 (push flt org-agenda-regexp-filter)
7391 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
7392 (org-agenda-filter-show-all-re)
7393 (message "Regexp filter removed")))
7395 (defvar org-agenda-effort-filter nil)
7396 (defun org-agenda-filter-by-effort (strip)
7397 "Filter agenda entries by effort.
7398 With no prefix argument, keep entries matching the effort condition.
7399 With one prefix argument, filter out entries matching the condition.
7400 With two prefix arguments, remove the effort filters."
7402 (cond ((member strip '(nil 4))
7403 (let ((efforts (org-split-string
7404 (or (cdr (assoc (concat org-effort-property "_ALL")
7405 org-global-properties))
7406 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7410 (while (not (member op '(?< ?> ?=)))
7411 (setq op (read-char-exclusive "Effort operator? (> = or <)")))
7412 (loop for i from 0 to 9 do
7416 (if (= i 9) "0" (int-to-string (1+ i)))
7417 "]" (nth i efforts))))
7418 (message "Effort %s%s" (char-to-string op) effort-prompt)
7419 (while (or (< eff 0) (> eff 9))
7420 (setq eff (string-to-number (char-to-string (read-char-exclusive)))))
7421 (setq org-agenda-effort-filter
7422 (list (concat (if strip "-" "+")
7423 (char-to-string op) (nth (1- eff) efforts))))
7424 (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
7425 (t (org-agenda-filter-show-all-effort)
7426 (message "Effort filter removed"))))
7428 (defun org-agenda-filter-remove-all ()
7429 "Remove all filters from the current agenda buffer."
7431 (when org-agenda-tag-filter
7432 (org-agenda-filter-show-all-tag))
7433 (when org-agenda-category-filter
7434 (org-agenda-filter-show-all-cat))
7435 (when org-agenda-regexp-filter
7436 (org-agenda-filter-show-all-re))
7437 (when org-agenda-top-headline-filter
7438 (org-agenda-filter-show-all-top-filter))
7439 (when org-agenda-effort-filter
7440 (org-agenda-filter-show-all-effort))
7441 (org-agenda-finalize))
7443 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7444 "Keep only those lines in the agenda buffer that have a specific tag.
7445 The tag is selected with its fast selection letter, as configured.
7446 With prefix argument STRIP, remove all lines that do have the tag.
7447 A lisp caller can specify CHAR. NARROW means that the new tag should be
7448 used to narrow the search - the interactive user can also press `-' or `+'
7449 to switch to narrowing."
7451 (let* ((alist org-tag-alist-for-agenda)
7452 (tag-chars (mapconcat
7453 (lambda (x) (if (and (not (symbolp (car x)))
7455 (char-to-string (cdr x))
7458 (inhibit-read-only t)
7459 (current org-agenda-tag-filter)
7463 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow"
7464 (if narrow "Narrow" "Filter") tag-chars
7465 (if org-agenda-auto-exclude-function "[RET], " ""))
7466 (setq char (read-char-exclusive)))
7467 (when (member char '(?+ ?-))
7469 (cond ((equal char ?-) (setq strip t narrow t))
7470 ((equal char ?+) (setq strip nil narrow t)))
7472 "Narrow by tag [%s ], [TAB], [/]:off" tag-chars)
7473 (setq char (read-char-exclusive)))
7474 (when (equal char ?\t)
7475 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7476 (org-set-local 'org-global-tags-completion-table
7477 (org-global-tags-completion-table)))
7478 (let ((completion-ignore-case t))
7479 (setq tag (org-icompleting-read
7480 "Tag: " org-global-tags-completion-table))))
7483 (org-agenda-filter-show-all-tag)
7484 (when org-agenda-auto-exclude-function
7485 (setq org-agenda-tag-filter nil)
7486 (dolist (tag (org-agenda-get-represented-tags))
7487 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7489 (push modifier org-agenda-tag-filter))))
7490 (if (not (null org-agenda-tag-filter))
7491 (org-agenda-filter-apply org-agenda-tag-filter 'tag))))
7493 (org-agenda-filter-show-all-tag)
7494 (when (get 'org-agenda-tag-filter :preset-filter)
7495 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7497 (setq org-agenda-tag-filter
7498 (mapcar (lambda(tag) (concat "+" tag))
7499 (org-get-at-bol 'tags)))
7500 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7501 ((or (equal char ?\ )
7502 (setq a (rassoc char alist))
7503 (and tag (setq a (cons tag nil))))
7504 (org-agenda-filter-show-all-tag)
7506 (setq org-agenda-tag-filter
7507 (cons (concat (if strip "-" "+") tag)
7508 (if narrow current nil)))
7509 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7510 (t (error "Invalid tag selection character %c" char)))))
7512 (defun org-agenda-get-represented-tags ()
7513 "Get a list of all tags currently represented in the agenda."
7516 (goto-char (point-min))
7517 (while (setq p (next-single-property-change (point) 'tags))
7519 (mapc (lambda (x) (add-to-list 'tags x))
7520 (get-text-property (point) 'tags))))
7523 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7524 "Refine the current filter. See `org-agenda-filter-by-tag'."
7526 (org-agenda-filter-by-tag strip char 'refine))
7528 (defun org-agenda-filter-make-matcher (filter type)
7529 "Create the form that tests a line for agenda filter."
7536 (append (get 'org-agenda-tag-filter :preset-filter)
7539 (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
7541 (lambda (nf0 nf01 fltr notgroup op)
7543 (if (member x '("-" "+"))
7544 (setq nf01 (if (equal x "-") 'tags '(not tags)))
7545 (setq nf01 (list 'member (downcase (substring x 1))
7547 (when (equal (string-to-char x) ?-)
7548 (setq nf01 (list 'not nf01))
7549 (when (not notgroup) (setq op 'and))))
7552 (push (cons 'and nf0) f)
7553 (push (cons (or op 'or) nf0) f)))))
7554 (cond ((equal filter '("+"))
7555 (setq f (list (list 'not 'tags))))
7556 ((equal nfilter filter)
7557 (funcall ffunc f1 f filter t nil))
7558 (t (funcall ffunc nf1 nf nfilter nil nil))))))
7560 ((eq type 'category)
7563 (append (get 'org-agenda-category-filter :preset-filter)
7566 (if (equal "-" (substring x 0 1))
7567 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7568 (setq f1 (list 'equal (substring x 1) 'cat)))
7574 (append (get 'org-agenda-regexp-filter :preset-filter)
7577 (if (equal "-" (substring x 0 1))
7578 (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
7579 (setq f1 (list 'string-match (substring x 1) 'txt)))
7585 (append (get 'org-agenda-effort-filter :preset-filter)
7588 (push (org-agenda-filter-effort-form x) f))))
7589 (cons 'and (nreverse f))))
7591 (defun org-agenda-filter-effort-form (e)
7592 "Return the form to compare the effort of the current line with what E says.
7593 E looks like \"+<2:25\"."
7595 (setq e (substring e 1))
7596 (setq op (string-to-char e) e (substring e 1))
7597 (setq op (cond ((equal op ?<) '<=)
7601 (list 'org-agenda-compare-effort (list 'quote op)
7602 (org-duration-string-to-minutes e))))
7604 (defun org-agenda-compare-effort (op value)
7605 "Compare the effort of the current line with VALUE, using OP.
7606 If the line does not have an effort defined, return nil."
7607 (let ((eff (org-get-at-eol 'effort-minutes 1)))
7608 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 -1))
7611 (defun org-agenda-filter-expand-tags (filter &optional no-operator)
7612 "Expand group tags in FILTER for the agenda.
7613 When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
7615 (let ((case-fold-search t) rtn)
7619 (if (string-match "^\\([+-]\\)\\(.+\\)" f)
7620 (setq dir (match-string 1 f) f0 (match-string 2 f))
7621 (setq dir (if no-operator "" "+") f0 f))
7622 (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
7623 (org-tags-expand f0 t t))
7629 (defun org-agenda-filter-apply (filter type)
7630 "Set FILTER as the new agenda filter and apply it."
7631 ;; Deactivate `org-agenda-entry-text-mode' when filtering
7632 (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
7634 (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type))
7635 ;; Only set `org-agenda-filtered-by-category' to t when a unique
7636 ;; category is used as the filter:
7637 (setq org-agenda-filtered-by-category
7638 (and (eq type 'category)
7639 (not (equal (substring (car filter) 0 1) "-"))))
7640 (org-agenda-set-mode-name)
7642 (goto-char (point-min))
7644 (if (org-get-at-bol 'org-marker)
7646 (setq tags ; used in eval
7649 (org-agenda-filter-expand-tags (list f) t))
7650 (org-get-at-bol 'tags)))
7651 cat (org-get-at-eol 'org-category 1)
7652 txt (org-get-at-eol 'txt 1))
7653 (if (not (eval org-agenda-filter-form))
7654 (org-agenda-filter-hide-line type))
7655 (beginning-of-line 2))
7656 (beginning-of-line 2))))
7657 (if (get-char-property (point) 'invisible)
7658 (ignore-errors (org-agenda-previous-line)))))
7660 (defun org-agenda-filter-top-headline-apply (hl &optional negative)
7661 "Filter by top headline HL."
7662 (org-agenda-set-mode-name)
7664 (goto-char (point-min))
7666 (let* ((pos (org-get-at-bol 'org-hd-marker))
7667 (tophl (and pos (org-find-top-headline pos))))
7668 (if (and tophl (funcall (if negative 'identity 'not)
7669 (string= hl tophl)))
7670 (org-agenda-filter-hide-line 'top-headline)))
7671 (beginning-of-line 2)))
7672 (if (get-char-property (point) 'invisible)
7673 (org-agenda-previous-line))
7674 (setq org-agenda-top-headline-filter hl
7675 org-agenda-filtered-by-top-headline t))
7677 (defun org-agenda-filter-hide-line (type)
7678 "Hide lines with TYPE in the agenda buffer."
7679 (let* ((b (max (point-min) (1- (point-at-bol))))
7681 (let ((inhibit-read-only t))
7682 (add-text-properties
7683 b e `(invisible org-filtered org-filter-type ,type)))))
7685 (defun org-agenda-remove-filter (type)
7687 "Remove filter of type TYPE from the agenda buffer."
7689 (goto-char (point-min))
7690 (let ((inhibit-read-only t) pos)
7691 (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
7693 (remove-text-properties
7694 (point) (next-single-property-change (point) 'org-filter-type)
7695 `(invisible org-filtered org-filter-type ,type))))
7696 (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
7697 (setq org-agenda-filter-form nil)
7698 (org-agenda-set-mode-name)
7699 (org-agenda-finalize)))
7701 (defun org-agenda-filter-show-all-tag nil
7702 (org-agenda-remove-filter 'tag))
7703 (defun org-agenda-filter-show-all-re nil
7704 (org-agenda-remove-filter 'regexp))
7705 (defun org-agenda-filter-show-all-effort nil
7706 (org-agenda-remove-filter 'effort))
7707 (defun org-agenda-filter-show-all-cat nil
7708 (org-agenda-remove-filter 'category))
7709 (defun org-agenda-filter-show-all-top-filter nil
7710 (org-agenda-remove-filter 'top-headline))
7712 (defun org-agenda-manipulate-query-add ()
7713 "Manipulate the query by adding a search term with positive selection.
7714 Positive selection means the term must be matched for selection of an entry."
7716 (org-agenda-manipulate-query ?\[))
7717 (defun org-agenda-manipulate-query-subtract ()
7718 "Manipulate the query by adding a search term with negative selection.
7719 Negative selection means term must not be matched for selection of an entry."
7721 (org-agenda-manipulate-query ?\]))
7722 (defun org-agenda-manipulate-query-add-re ()
7723 "Manipulate the query by adding a search regexp with positive selection.
7724 Positive selection means the regexp must match for selection of an entry."
7726 (org-agenda-manipulate-query ?\{))
7727 (defun org-agenda-manipulate-query-subtract-re ()
7728 "Manipulate the query by adding a search regexp with negative selection.
7729 Negative selection means regexp must not match for selection of an entry."
7731 (org-agenda-manipulate-query ?\}))
7732 (defun org-agenda-manipulate-query (char)
7734 ((memq org-agenda-type '(timeline agenda))
7735 (let ((org-agenda-include-inactive-timestamps t))
7737 (message "Display now includes inactive timestamps as well"))
7738 ((eq org-agenda-type 'search)
7740 'org-agenda-query-string
7741 (if org-agenda-last-search-view-search-was-boolean
7742 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7743 (?\{ . " +{}") (?\} . " -{}"))))
7745 (setq org-agenda-redo-command
7746 (list 'org-search-view
7747 (car (get-text-property (min (1- (point-max)) (point))
7749 org-agenda-query-string
7750 (+ (length org-agenda-query-string)
7751 (if (member char '(?\{ ?\})) 0 1))))
7752 (set-register org-agenda-query-register org-agenda-query-string)
7753 (let ((org-agenda-overriding-arguments
7754 (cdr org-agenda-redo-command)))
7756 (t (error "Cannot manipulate query for %s-type agenda buffers"
7759 (defun org-add-to-string (var string)
7760 (set var (concat (symbol-value var) string)))
7762 (defun org-agenda-goto-date (span)
7763 "Jump to DATE in agenda."
7765 (let* ((org-read-date-prefer-future
7766 (eval org-agenda-jump-prefer-future))
7767 (date (org-read-date))
7768 (day (time-to-days (org-time-string-to-time date)))
7769 (org-agenda-sticky-orig org-agenda-sticky)
7770 (org-agenda-buffer-tmp-name (buffer-name))
7771 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7772 (0-arg (or current-prefix-arg (car args)))
7773 (2-arg (nth 2 args))
7774 (with-hour-p (nth 4 org-agenda-redo-command))
7775 (newcmd (list 'org-agenda-list 0-arg date
7776 (org-agenda-span-to-ndays
7777 2-arg (org-time-string-to-absolute date))
7779 (newargs (cdr newcmd))
7780 (inhibit-read-only t)
7782 (if (not (org-agenda-check-type t 'agenda))
7783 (error "Not available in non-agenda views")
7784 (add-text-properties (point-min) (point-max)
7785 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7787 (goto-char (point-min))
7788 (while (not (or (= (or (get-text-property (point) 'day) 0) day)
7789 (save-excursion (move-beginning-of-line 2) (eobp))))
7790 (move-beginning-of-line 2))
7791 (setq org-agenda-sticky org-agenda-sticky-orig
7792 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7794 (defun org-agenda-goto-today ()
7797 (org-agenda-check-type t 'timeline 'agenda)
7798 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7799 (curspan (nth 2 args))
7800 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7802 (tdpos (goto-char tdpos))
7803 ((eq org-agenda-type 'agenda)
7804 (let* ((sd (org-agenda-compute-starting-span
7805 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7806 (org-agenda-overriding-arguments args))
7807 (setf (nth 1 org-agenda-overriding-arguments) sd)
7809 (org-agenda-find-same-or-today-or-agenda)))
7810 (t (error "Cannot find today")))))
7812 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7814 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7815 (text-property-any (point-min) (point-max) 'org-today t)
7816 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7817 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7818 (org-agenda-backward-block))
7821 (defun org-agenda-backward-block ()
7822 "Move backward by one agenda block."
7824 (org-agenda-forward-block 'backward))
7826 (defun org-agenda-forward-block (&optional backward)
7827 "Move forward by one agenda block.
7828 When optional argument BACKWARD is set, go backward"
7830 (cond ((not (derived-mode-p 'org-agenda-mode))
7832 "Cannot execute this command outside of org-agenda-mode buffers"))
7833 ((looking-at (if backward "\\`" "\\'"))
7834 (message "Already at the %s block" (if backward "first" "last")))
7835 (t (let ((pos (prog1 (point)
7836 (ignore-errors (if backward (backward-char 1)
7837 (move-end-of-line 1)))))
7839 'previous-single-property-change
7840 'next-single-property-change))
7842 (while (and (setq dest (funcall
7843 f (point) 'org-agenda-structural-header))
7844 (not (get-text-property
7845 (point) 'org-agenda-structural-header)))
7848 (if moved (move-beginning-of-line 1)
7849 (goto-char (if backward (point-min) (point-max)))
7850 (move-beginning-of-line 1)
7851 (message "No %s block" (if backward "previous" "further")))))))
7853 (defun org-agenda-later (arg)
7854 "Go forward in time by the current span.
7855 With prefix ARG, go forward that many times the current span."
7857 (org-agenda-check-type t 'agenda)
7858 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7859 (span (or (nth 2 args) org-agenda-current-span))
7860 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7861 (greg (calendar-gregorian-from-absolute sd))
7862 (cnt (org-get-at-bol 'org-day-cnt))
7866 (setq sd (+ (* span arg) sd)))
7868 (setq sd (+ arg sd)))
7870 (setq sd (+ (* 7 arg) sd)))
7871 ((eq span 'fortnight)
7872 (setq sd (+ (* 14 arg) sd)))
7874 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7875 sd (calendar-absolute-from-gregorian greg2))
7876 (setcar greg2 (1+ (car greg2))))
7878 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7879 sd (calendar-absolute-from-gregorian greg2))
7880 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7882 (setq sd (+ (* span arg) sd))))
7883 (let ((org-agenda-overriding-cmd
7884 ;; `cmd' may have been set by `org-agenda-run-series' which
7885 ;; uses `org-agenda-overriding-cmd' to decide whether
7886 ;; overriding is allowed for `cmd'
7887 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7888 (org-agenda-overriding-arguments
7889 (list (car args) sd span)))
7891 (org-agenda-find-same-or-today-or-agenda cnt))))
7893 (defun org-agenda-earlier (arg)
7894 "Go backward in time by the current span.
7895 With prefix ARG, go backward that many times the current span."
7897 (org-agenda-later (- arg)))
7899 (defun org-agenda-view-mode-dispatch ()
7900 "Call one of the view mode commands."
7902 (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
7903 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7904 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7905 (let ((a (read-char-exclusive)))
7907 (?\ (call-interactively 'org-agenda-reset-view))
7908 (?d (call-interactively 'org-agenda-day-view))
7909 (?w (call-interactively 'org-agenda-week-view))
7910 (?t (call-interactively 'org-agenda-fortnight-view))
7911 (?m (call-interactively 'org-agenda-month-view))
7912 (?y (call-interactively 'org-agenda-year-view))
7913 (?l (call-interactively 'org-agenda-log-mode))
7914 (?L (org-agenda-log-mode '(4)))
7915 (?c (org-agenda-log-mode 'clockcheck))
7916 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7917 (?a (call-interactively 'org-agenda-archives-mode))
7918 (?A (org-agenda-archives-mode 'files))
7919 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7920 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7921 (?G (call-interactively 'org-agenda-toggle-time-grid))
7922 (?D (call-interactively 'org-agenda-toggle-diary))
7923 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7924 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7925 (org-agenda-check-type t 'timeline 'agenda)
7927 (message "Display now includes inactive timestamps as well"))
7928 (?q (message "Abort"))
7929 (otherwise (error "Invalid key" )))))
7931 (defun org-agenda-reset-view ()
7932 "Switch to default view for agenda."
7934 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7935 (defun org-agenda-day-view (&optional day-of-month)
7936 "Switch to daily view for agenda.
7937 With argument DAY-OF-MONTH, switch to that day of the month."
7939 (org-agenda-change-time-span 'day day-of-month))
7940 (defun org-agenda-week-view (&optional iso-week)
7941 "Switch to daily view for agenda.
7942 With argument ISO-WEEK, switch to the corresponding ISO week.
7943 If ISO-WEEK has more then 2 digits, only the last two encode the
7944 week. Any digits before this encode a year. So 200712 means
7945 week 12 of year 2007. Years in the range 1938-2037 can also be
7946 written as 2-digit years."
7948 (org-agenda-change-time-span 'week iso-week))
7949 (defun org-agenda-fortnight-view (&optional iso-week)
7950 "Switch to daily view for agenda.
7951 With argument ISO-WEEK, switch to the corresponding ISO week.
7952 If ISO-WEEK has more then 2 digits, only the last two encode the
7953 week. Any digits before this encode a year. So 200712 means
7954 week 12 of year 2007. Years in the range 1938-2037 can also be
7955 written as 2-digit years."
7957 (org-agenda-change-time-span 'fortnight iso-week))
7958 (defun org-agenda-month-view (&optional month)
7959 "Switch to monthly view for agenda.
7960 With argument MONTH, switch to that month."
7962 (org-agenda-change-time-span 'month month))
7963 (defun org-agenda-year-view (&optional year)
7964 "Switch to yearly view for agenda.
7965 With argument YEAR, switch to that year.
7966 If MONTH has more then 2 digits, only the last two encode the
7967 month. Any digits before this encode a year. So 200712 means
7968 December year 2007. Years in the range 1938-2037 can also be
7969 written as 2-digit years."
7972 (setq year (org-small-year-to-year year)))
7973 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7974 (org-agenda-change-time-span 'year year)
7977 (defun org-agenda-change-time-span (span &optional n)
7978 "Change the agenda view to SPAN.
7979 SPAN may be `day', `week', `fortnight', `month', `year'."
7980 (org-agenda-check-type t 'agenda)
7981 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7982 (curspan (nth 2 args)))
7983 (if (and (not n) (equal curspan span))
7984 (error "Viewing span is already \"%s\"" span))
7985 (let* ((sd (or (org-get-at-bol 'day)
7988 (sd (org-agenda-compute-starting-span sd span n))
7989 (org-agenda-overriding-cmd
7990 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7991 (org-agenda-overriding-arguments
7992 (list (car args) sd span)))
7994 (org-agenda-find-same-or-today-or-agenda))
7995 (org-agenda-set-mode-name)
7996 (message "Switched to %s view" span)))
7998 (defun org-agenda-compute-starting-span (sd span &optional n)
7999 "Compute starting date for agenda.
8000 SPAN may be `day', `week', `fortnight', `month', `year'. The return value
8001 is a cons cell with the starting date and the number of days,
8002 so that the date SD will be in that range."
8003 (let* ((greg (calendar-gregorian-from-absolute sd))
8010 (setq sd (+ (calendar-absolute-from-gregorian
8013 ((or (eq span 'week) (eq span 'fortnight))
8014 (let* ((nt (calendar-day-of-week
8015 (calendar-gregorian-from-absolute sd)))
8016 (d (if org-agenda-start-on-weekday
8017 (- nt org-agenda-start-on-weekday)
8020 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
8024 (setq y1 (org-small-year-to-year (/ n 100))
8027 (calendar-absolute-from-iso
8029 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
8032 (when (and n (> n 99))
8033 (setq y1 (org-small-year-to-year (/ n 100))
8035 (setq sd (calendar-absolute-from-gregorian
8036 (list (or n mg) 1 (or y1 yg))))))
8038 (setq sd (calendar-absolute-from-gregorian
8039 (list 1 1 (or n yg))))))
8042 (defun org-agenda-next-date-line (&optional arg)
8043 "Jump to the next line indicating a date in agenda buffer."
8045 (org-agenda-check-type t 'agenda 'timeline)
8046 (beginning-of-line 1)
8047 ;; This does not work if user makes date format that starts with a blank
8048 (if (looking-at "^\\S-") (forward-char 1))
8049 (if (not (re-search-forward "^\\S-" nil t arg))
8052 (error "No next date after this line in this buffer")))
8053 (goto-char (match-beginning 0)))
8055 (defun org-agenda-previous-date-line (&optional arg)
8056 "Jump to the previous line indicating a date in agenda buffer."
8058 (org-agenda-check-type t 'agenda 'timeline)
8059 (beginning-of-line 1)
8060 (if (not (re-search-backward "^\\S-" nil t arg))
8061 (error "No previous date before this line in this buffer")))
8063 ;; Initialize the highlight
8064 (defvar org-hl (make-overlay 1 1))
8065 (overlay-put org-hl 'face 'highlight)
8067 (defun org-highlight (begin end &optional buffer)
8068 "Highlight a region with overlay."
8069 (move-overlay org-hl begin end (or buffer (current-buffer))))
8071 (defun org-unhighlight ()
8072 "Detach overlay INDEX."
8073 (org-detach-overlay org-hl))
8075 (defun org-unhighlight-once ()
8076 "Remove the highlight from its position, and this function from the hook."
8077 (remove-hook 'pre-command-hook 'org-unhighlight-once)
8080 (defvar org-agenda-pre-follow-window-conf nil)
8081 (defun org-agenda-follow-mode ()
8082 "Toggle follow mode in an agenda buffer."
8084 (unless org-agenda-follow-mode
8085 (setq org-agenda-pre-follow-window-conf
8086 (current-window-configuration)))
8087 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
8088 (unless org-agenda-follow-mode
8089 (set-window-configuration org-agenda-pre-follow-window-conf))
8090 (org-agenda-set-mode-name)
8091 (org-agenda-do-context-action)
8092 (message "Follow mode is %s"
8093 (if org-agenda-follow-mode "on" "off")))
8095 (defun org-agenda-entry-text-mode (&optional arg)
8096 "Toggle entry text mode in an agenda buffer."
8098 (if (or org-agenda-tag-filter
8099 org-agenda-category-filter
8100 org-agenda-regexp-filter
8101 org-agenda-top-headline-filter)
8102 (user-error "Can't show entry text in filtered views")
8103 (setq org-agenda-entry-text-mode (or (integerp arg)
8104 (not org-agenda-entry-text-mode)))
8105 (org-agenda-entry-text-hide)
8106 (and org-agenda-entry-text-mode
8107 (let ((org-agenda-entry-text-maxlines
8108 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8109 (org-agenda-entry-text-show)))
8110 (org-agenda-set-mode-name)
8111 (message "Entry text mode is %s%s"
8112 (if org-agenda-entry-text-mode "on" "off")
8113 (if (not org-agenda-entry-text-mode) ""
8114 (format " (maximum number of lines is %d)"
8115 (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
8117 (defun org-agenda-clockreport-mode ()
8118 "Toggle clocktable mode in an agenda buffer."
8120 (org-agenda-check-type t 'agenda)
8121 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
8122 (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
8123 (org-agenda-set-mode-name)
8125 (message "Clocktable mode is %s"
8126 (if org-agenda-clockreport-mode "on" "off")))
8128 (defun org-agenda-log-mode (&optional special)
8129 "Toggle log mode in an agenda buffer.
8130 With argument SPECIAL, show all possible log items, not only the ones
8131 configured in `org-agenda-log-mode-items'.
8132 With a double `C-u' prefix arg, show *only* log items, nothing else."
8134 (org-agenda-check-type t 'agenda 'timeline)
8135 (setq org-agenda-show-log
8137 ((equal special '(16)) 'only)
8138 ((eq special 'clockcheck)
8139 (if (eq org-agenda-show-log 'clockcheck)
8141 (special '(closed clock state))
8142 (t (not org-agenda-show-log))))
8143 (setq org-agenda-start-with-log-mode org-agenda-show-log)
8144 (org-agenda-set-mode-name)
8146 (message "Log mode is %s"
8147 (if org-agenda-show-log "on" "off")))
8149 (defun org-agenda-archives-mode (&optional with-files)
8150 "Toggle inclusion of items in trees marked with :ARCHIVE:.
8151 When called with a prefix argument, include all archive files as well."
8153 (setq org-agenda-archives-mode
8154 (if with-files t (if org-agenda-archives-mode nil 'trees)))
8155 (org-agenda-set-mode-name)
8160 ((eq org-agenda-archives-mode nil)
8161 "No archives are included")
8162 ((eq org-agenda-archives-mode 'trees)
8163 (format "Trees with :%s: tag are included" org-archive-tag))
8164 ((eq org-agenda-archives-mode t)
8165 (format "Trees with :%s: tag and all active archive files are included"
8166 org-archive-tag)))))
8168 (defun org-agenda-toggle-diary ()
8169 "Toggle diary inclusion in an agenda buffer."
8171 (org-agenda-check-type t 'agenda)
8172 (setq org-agenda-include-diary (not org-agenda-include-diary))
8174 (org-agenda-set-mode-name)
8175 (message "Diary inclusion turned %s"
8176 (if org-agenda-include-diary "on" "off")))
8178 (defun org-agenda-toggle-deadlines ()
8179 "Toggle inclusion of entries with a deadline in an agenda buffer."
8181 (org-agenda-check-type t 'agenda)
8182 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
8184 (org-agenda-set-mode-name)
8185 (message "Deadlines inclusion turned %s"
8186 (if org-agenda-include-deadlines "on" "off")))
8188 (defun org-agenda-toggle-time-grid ()
8189 "Toggle time grid in an agenda buffer."
8191 (org-agenda-check-type t 'agenda)
8192 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
8194 (org-agenda-set-mode-name)
8195 (message "Time-grid turned %s"
8196 (if org-agenda-use-time-grid "on" "off")))
8198 (defun org-agenda-set-mode-name ()
8199 "Set the mode name to indicate all the small mode settings."
8202 (if (get 'org-agenda-files 'org-restrict) " []" "")
8204 '(:eval (org-agenda-span-name org-agenda-current-span))
8205 (if org-agenda-follow-mode " Follow" "")
8206 (if org-agenda-entry-text-mode " ETxt" "")
8207 (if org-agenda-include-diary " Diary" "")
8208 (if org-agenda-include-deadlines " Ddl" "")
8209 (if org-agenda-use-time-grid " Grid" "")
8210 (if (and (boundp 'org-habit-show-habits)
8211 org-habit-show-habits) " Habit" "")
8213 ((consp org-agenda-show-log) " LogAll")
8214 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
8215 (org-agenda-show-log " Log")
8217 (if (or org-agenda-category-filter
8218 (get 'org-agenda-category-filter :preset-filter))
8219 '(:eval (org-propertize
8224 (get 'org-agenda-category-filter :preset-filter)
8225 org-agenda-category-filter)
8228 'face 'org-agenda-filter-category
8229 'help-echo "Category used in filtering")) "")
8230 (if (or org-agenda-tag-filter
8231 (get 'org-agenda-tag-filter :preset-filter))
8232 '(:eval (org-propertize
8237 (get 'org-agenda-tag-filter :preset-filter)
8238 org-agenda-tag-filter)
8241 'face 'org-agenda-filter-tags
8242 'help-echo "Tags used in filtering")) "")
8243 (if (or org-agenda-effort-filter
8244 (get 'org-agenda-effort-filter :preset-filter))
8245 '(:eval (org-propertize
8250 (get 'org-agenda-effort-filter :preset-filter)
8251 org-agenda-effort-filter)
8254 'face 'org-agenda-filter-effort
8255 'help-echo "Effort conditions used in filtering")) "")
8256 (if (or org-agenda-regexp-filter
8257 (get 'org-agenda-regexp-filter :preset-filter))
8258 '(:eval (org-propertize
8263 (get 'org-agenda-regexp-filter :preset-filter)
8264 org-agenda-regexp-filter)
8267 'face 'org-agenda-filter-regexp
8268 'help-echo "Regexp used in filtering")) "")
8269 (if org-agenda-archives-mode
8270 (if (eq org-agenda-archives-mode t)
8272 (format " :%s:" org-archive-tag))
8274 (if org-agenda-clockreport-mode " Clock" "")))
8275 (force-mode-line-update))
8277 (define-obsolete-function-alias
8278 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
8280 (defun org-agenda-update-agenda-type ()
8281 "Update the agenda type after each command."
8282 (setq org-agenda-type
8283 (or (get-text-property (point) 'org-agenda-type)
8284 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
8286 (defun org-agenda-next-line ()
8287 "Move cursor to the next line, and show if follow mode is active."
8289 (call-interactively 'next-line)
8290 (org-agenda-do-context-action))
8292 (defun org-agenda-previous-line ()
8293 "Move cursor to the previous line, and show if follow-mode is active."
8295 (call-interactively 'previous-line)
8296 (org-agenda-do-context-action))
8298 (defun org-agenda-next-item (n)
8299 "Move cursor to next agenda item."
8301 (let ((col (current-column)))
8303 (when (next-single-property-change (point-at-eol) 'org-marker)
8304 (move-end-of-line 1)
8305 (goto-char (next-single-property-change (point) 'org-marker))))
8306 (org-move-to-column col))
8307 (org-agenda-do-context-action))
8309 (defun org-agenda-previous-item (n)
8310 "Move cursor to next agenda item."
8313 (let ((col (current-column))
8314 (goto (save-excursion
8315 (move-end-of-line 0)
8316 (previous-single-property-change (point) 'org-marker))))
8317 (if goto (goto-char goto))
8318 (org-move-to-column col)))
8319 (org-agenda-do-context-action))
8321 (defun org-agenda-do-context-action ()
8322 "Show outline path and, maybe, follow mode window."
8323 (let ((m (org-get-at-bol 'org-marker)))
8324 (when (and (markerp m) (marker-buffer m))
8325 (and org-agenda-follow-mode
8326 (if org-agenda-follow-indirect
8327 (org-agenda-tree-to-indirect-buffer nil)
8329 (and org-agenda-show-outline-path
8330 (org-with-point-at m (org-display-outline-path t))))))
8332 (defun org-agenda-show-tags ()
8333 "Show the tags applicable to the current item."
8335 (let* ((tags (org-get-at-bol 'tags)))
8337 (message "Tags are :%s:"
8338 (org-no-properties (mapconcat 'identity tags ":")))
8339 (message "No tags associated with this line"))))
8341 (defun org-agenda-goto (&optional highlight)
8342 "Go to the entry at point in the corresponding Org-mode file."
8344 (let* ((marker (or (org-get-at-bol 'org-marker)
8345 (org-agenda-error)))
8346 (buffer (marker-buffer marker))
8347 (pos (marker-position marker)))
8348 (switch-to-buffer-other-window buffer)
8352 (when (derived-mode-p 'org-mode)
8353 (org-show-context 'agenda)
8355 (and (outline-next-heading)
8356 (org-flag-heading nil)))) ; show the next heading
8357 (when (outline-invisible-p)
8358 (show-entry)) ; display invisible text
8359 (recenter (/ (window-height) 2))
8360 (org-back-to-heading t)
8361 (if (re-search-forward org-complex-heading-regexp nil t)
8362 (goto-char (match-beginning 4)))
8363 (run-hooks 'org-agenda-after-show-hook)
8364 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8366 (defvar org-agenda-after-show-hook nil
8367 "Normal hook run after an item has been shown from the agenda.
8368 Point is in the buffer where the item originated.")
8370 (defun org-agenda-kill ()
8371 "Kill the entry or subtree belonging to the current agenda entry."
8373 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8374 (let* ((bufname-orig (buffer-name))
8375 (marker (or (org-get-at-bol 'org-marker)
8376 (org-agenda-error)))
8377 (buffer (marker-buffer marker))
8378 (pos (marker-position marker))
8379 (type (org-get-at-bol 'type))
8380 dbeg dend (n 0) conf)
8381 (org-with-remote-undo buffer
8382 (with-current-buffer buffer
8385 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8386 (setq dbeg (progn (org-back-to-heading t) (point))
8387 dend (org-end-of-subtree t t))
8388 (setq dbeg (point-at-bol)
8389 dend (min (point-max) (1+ (point-at-eol)))))
8391 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8392 (setq conf (or (eq t org-agenda-confirm-kill)
8393 (and (numberp org-agenda-confirm-kill)
8394 (> n org-agenda-confirm-kill))))
8397 (format "Delete entry with %d lines in buffer \"%s\"? "
8398 n (buffer-name buffer))))
8400 (let ((org-agenda-buffer-name bufname-orig))
8401 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8402 (with-current-buffer buffer (delete-region dbeg dend))
8403 (message "Agenda item and source killed"))))
8405 (defvar org-archive-default-command) ; defined in org-archive.el
8406 (defun org-agenda-archive-default ()
8407 "Archive the entry or subtree belonging to the current agenda entry."
8409 (require 'org-archive)
8410 (org-agenda-archive-with org-archive-default-command))
8412 (defun org-agenda-archive-default-with-confirmation ()
8413 "Archive the entry or subtree belonging to the current agenda entry."
8415 (require 'org-archive)
8416 (org-agenda-archive-with org-archive-default-command 'confirm))
8418 (defun org-agenda-archive ()
8419 "Archive the entry or subtree belonging to the current agenda entry."
8421 (org-agenda-archive-with 'org-archive-subtree))
8423 (defun org-agenda-archive-to-archive-sibling ()
8424 "Move the entry to the archive sibling."
8426 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8428 (defun org-agenda-archive-with (cmd &optional confirm)
8429 "Move the entry to the archive sibling."
8431 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8432 (let* ((bufname-orig (buffer-name))
8433 (marker (or (org-get-at-bol 'org-marker)
8434 (org-agenda-error)))
8435 (buffer (marker-buffer marker))
8436 (pos (marker-position marker)))
8437 (org-with-remote-undo buffer
8438 (with-current-buffer buffer
8439 (if (derived-mode-p 'org-mode)
8441 (not (y-or-n-p "Archive this subtree or entry? ")))
8443 (save-window-excursion
8445 (let ((org-agenda-buffer-name bufname-orig))
8446 (org-remove-subtree-entries-from-agenda))
8447 (org-back-to-heading t)
8449 (error "Archiving works only in Org-mode files"))))))
8451 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8452 "Remove all lines in the agenda that correspond to a given subtree.
8453 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8454 If this information is not given, the function uses the tree at point."
8455 (let ((buf (or buf (current-buffer))) m p)
8457 (unless (and beg end)
8458 (org-back-to-heading t)
8460 (org-end-of-subtree t)
8462 (set-buffer (get-buffer org-agenda-buffer-name))
8464 (goto-char (point-max))
8465 (beginning-of-line 1)
8467 (when (and (setq m (org-get-at-bol 'org-marker))
8468 (equal buf (marker-buffer m))
8469 (setq p (marker-position m))
8472 (let ((inhibit-read-only t))
8473 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8474 (beginning-of-line 0))))))
8476 (defun org-agenda-refile (&optional goto rfloc no-update)
8477 "Refile the item at point.
8479 When GOTO is 0 or '(64) or \\[universal-argument] \\[universal-argument] \\[universal-argument], clear the refile cache.
8480 When GOTO is '(16) or \\[universal-argument] \\[universal-argument], go to the location of the last refiled item.
8481 RFLOC can be a refile location obtained in a different way.
8482 When NO-UPDATE is non-nil, don't redo the agenda buffer."
8485 ((member goto '(0 (64)))
8486 (org-refile-cache-clear))
8488 (org-refile-goto-last-stored))
8490 (let* ((buffer-orig (buffer-name))
8491 (marker (or (org-get-at-bol 'org-hd-marker)
8492 (org-agenda-error)))
8493 (buffer (marker-buffer marker))
8494 (pos (marker-position marker))
8496 (org-refile-get-location
8497 (if goto "Goto" "Refile to") buffer
8498 org-refile-allow-creating-parent-nodes))))
8499 (with-current-buffer buffer
8504 (let ((org-agenda-buffer-name buffer-orig))
8505 (org-remove-subtree-entries-from-agenda))
8506 (org-refile goto buffer rfloc)))))
8507 (unless no-update (org-agenda-redo)))))
8509 (defun org-agenda-open-link (&optional arg)
8510 "Open the link(s) in the current entry, if any.
8511 This looks for a link in the displayed line in the agenda.
8512 It also looks at the text of the entry itself."
8514 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8515 (org-get-at-bol 'org-marker)))
8516 (buffer (and marker (marker-buffer marker)))
8517 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8518 (lkall (and buffer (org-offer-links-in-entry
8519 buffer marker arg prefix)))
8521 (lk (if (stringp lk0) (list lk0) lk0))
8527 (with-current-buffer buffer
8528 (setq trg (and (string-match org-bracket-link-regexp l)
8529 (match-string 1 l)))
8530 (if (or (not trg) (string-match org-any-link-re trg))
8535 (when (search-forward l nil lkend)
8536 (goto-char (match-beginning 0))
8537 (org-open-at-point))))
8538 ;; This is an internal link, widen the buffer
8539 (switch-to-buffer-other-window buffer)
8542 (when (search-forward l nil lkend)
8543 (goto-char (match-beginning 0))
8544 (org-open-at-point)))))
8546 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8548 (beginning-of-line 1)
8549 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8550 (org-open-link-from-string (match-string 1)))
8551 (t (message "No link to open here")))))
8553 (defun org-agenda-copy-local-variable (var)
8554 "Get a variable from a referenced buffer and install it here."
8555 (let ((m (org-get-at-bol 'org-marker)))
8556 (when (and m (buffer-live-p (marker-buffer m)))
8557 (org-set-local var (with-current-buffer (marker-buffer m)
8558 (symbol-value var))))))
8560 (defun org-agenda-switch-to (&optional delete-other-windows)
8561 "Go to the Org-mode file which contains the item at point."
8563 (if (and org-return-follows-link
8564 (not (org-get-at-bol 'org-marker))
8565 (org-in-regexp org-bracket-link-regexp))
8566 (org-open-link-from-string (match-string 0))
8567 (let* ((marker (or (org-get-at-bol 'org-marker)
8568 (org-agenda-error)))
8569 (buffer (marker-buffer marker))
8570 (pos (marker-position marker)))
8571 (org-pop-to-buffer-same-window buffer)
8572 (and delete-other-windows (delete-other-windows))
8575 (org-back-to-heading t)
8576 (when (derived-mode-p 'org-mode)
8577 (org-show-context 'agenda)
8579 (and (outline-next-heading)
8580 (org-flag-heading nil))) ; show the next heading
8581 (when (outline-invisible-p)
8582 (show-entry)) ; display invisible text
8583 (run-hooks 'org-agenda-after-show-hook)))))
8585 (defun org-agenda-goto-mouse (ev)
8586 "Go to the Org-mode file which contains the item at the mouse click."
8588 (mouse-set-point ev)
8591 (defun org-agenda-show (&optional full-entry)
8592 "Display the Org-mode file which contains the item at point.
8593 With prefix argument FULL-ENTRY, make the entire entry visible
8594 if it was hidden in the outline."
8596 (let ((win (selected-window)))
8598 (let ((org-show-entry-below t))
8599 (org-agenda-goto t))
8600 (org-agenda-goto t))
8601 (select-window win)))
8603 (defvar org-agenda-show-window nil)
8604 (defun org-agenda-show-and-scroll-up (&optional arg)
8605 "Display the Org-mode file which contains the item at point.
8606 When called repeatedly, scroll the window that is displaying the buffer.
8607 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8608 `show-subtree' to display the item, so that drawers and logbooks stay
8611 (let ((win (selected-window)))
8612 (if (and (window-live-p org-agenda-show-window)
8613 (eq this-command last-command))
8615 (select-window org-agenda-show-window)
8616 (ignore-errors (scroll-up)))
8618 (if arg (org-show-entry) (show-subtree))
8619 (setq org-agenda-show-window (selected-window)))
8620 (select-window win)))
8622 (defun org-agenda-show-scroll-down ()
8623 "Scroll down the window showing the agenda."
8625 (let ((win (selected-window)))
8626 (when (window-live-p org-agenda-show-window)
8627 (select-window org-agenda-show-window)
8628 (ignore-errors (scroll-down))
8629 (select-window win))))
8631 (defun org-agenda-show-1 (&optional more)
8632 "Display the Org-mode file which contains the item at point.
8633 The prefix arg selects the amount of information to display:
8636 1 just show the entry according to defaults.
8637 2 show the children view
8638 3 show the subtree view
8639 4 show the entire subtree and any LOGBOOK drawers
8640 5 show the entire subtree and any drawers
8641 With prefix argument FULL-ENTRY, make the entire entry visible
8642 if it was hidden in the outline."
8644 (let ((win (selected-window)))
8646 (org-back-to-heading)
8647 (set-window-start (selected-window) (point-at-bol))
8652 (org-back-to-heading)
8653 (run-hook-with-args 'org-cycle-hook 'folded))
8654 (message "Remote: FOLDED"))
8655 ((and (org-called-interactively-p 'any) (= more 1))
8656 (message "Remote: show with default settings"))
8661 (org-back-to-heading)
8662 (run-hook-with-args 'org-cycle-hook 'children))
8663 (message "Remote: CHILDREN"))
8667 (org-back-to-heading)
8668 (run-hook-with-args 'org-cycle-hook 'subtree))
8669 (message "Remote: SUBTREE"))
8673 (org-back-to-heading)
8674 (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
8675 (message "Remote: SUBTREE AND LOGBOOK"))
8678 (message "Remote: SUBTREE AND ALL DRAWERS")))
8679 (select-window win)))
8681 (defvar org-agenda-cycle-counter nil)
8682 (defun org-agenda-cycle-show (&optional n)
8683 "Show the current entry in another window, with default settings.
8684 Default settings are taken from `org-show-hierarchy-above' and siblings.
8685 When use repeatedly in immediate succession, the remote entry will cycle
8688 children -> subtree -> folded
8690 When called with a numeric prefix arg, that arg will be passed through to
8691 `org-agenda-show-1'. For the interpretation of that argument, see the
8692 docstring of `org-agenda-show-1'."
8695 (setq org-agenda-cycle-counter n)
8696 (if (not (eq last-command this-command))
8697 (setq org-agenda-cycle-counter 1)
8698 (if (equal org-agenda-cycle-counter 0)
8699 (setq org-agenda-cycle-counter 2)
8700 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8701 (if (> org-agenda-cycle-counter 3)
8702 (setq org-agenda-cycle-counter 0)))))
8703 (org-agenda-show-1 org-agenda-cycle-counter))
8705 (defun org-agenda-recenter (arg)
8706 "Display the Org-mode file which contains the item at point and recenter."
8708 (let ((win (selected-window)))
8711 (select-window win)))
8713 (defun org-agenda-show-mouse (ev)
8714 "Display the Org-mode file which contains the item at the mouse click."
8716 (mouse-set-point ev)
8719 (defun org-agenda-check-no-diary ()
8720 "Check if the entry is a diary link and abort if yes."
8721 (if (org-get-at-bol 'org-agenda-diary-link)
8722 (org-agenda-error)))
8724 (defun org-agenda-error ()
8725 "Throw an error when a command is not allowed in the agenda."
8726 (user-error "Command not allowed in this line"))
8728 (defun org-agenda-tree-to-indirect-buffer (arg)
8729 "Show the subtree corresponding to the current entry in an indirect buffer.
8730 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8732 With a numerical prefix ARG, go up to this level and then take that tree.
8733 With a negative numeric ARG, go up by this number of levels.
8734 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8735 use the dedicated frame)."
8737 (if current-prefix-arg
8738 (org-agenda-do-tree-to-indirect-buffer arg)
8739 (let ((agenda-buffer (buffer-name))
8740 (agenda-window (selected-window))
8742 (and org-last-indirect-buffer
8743 (get-buffer-window org-last-indirect-buffer))))
8744 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8745 (unless (or (eq org-indirect-buffer-display 'new-frame)
8746 (eq org-indirect-buffer-display 'dedicated-frame))
8748 (unless (and indirect-window (window-live-p indirect-window))
8749 (setq indirect-window (split-window agenda-window)))
8750 (and indirect-window (select-window indirect-window))
8751 (switch-to-buffer org-last-indirect-buffer :norecord)
8752 (fit-window-to-buffer indirect-window)))
8753 (select-window (get-buffer-window agenda-buffer)))))
8755 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8756 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8757 (org-agenda-check-no-diary)
8758 (let* ((marker (or (org-get-at-bol 'org-marker)
8759 (org-agenda-error)))
8760 (buffer (marker-buffer marker))
8761 (pos (marker-position marker)))
8762 (with-current-buffer buffer
8765 (funcall 'org-tree-to-indirect-buffer arg)))))
8767 (defvar org-last-heading-marker (make-marker)
8768 "Marker pointing to the headline that last changed its TODO state
8769 by a remote command from the agenda.")
8771 (defun org-agenda-todo-nextset ()
8772 "Switch TODO entry to next sequence."
8774 (org-agenda-todo 'nextset))
8776 (defun org-agenda-todo-previousset ()
8777 "Switch TODO entry to previous sequence."
8779 (org-agenda-todo 'previousset))
8781 (defun org-agenda-todo (&optional arg)
8782 "Cycle TODO state of line at point, also in Org-mode file.
8783 This changes the line at point, all other lines in the agenda referring to
8784 the same tree node, and the headline of the tree node in the Org-mode file."
8786 (org-agenda-check-no-diary)
8787 (let* ((col (current-column))
8788 (marker (or (org-get-at-bol 'org-marker)
8789 (org-agenda-error)))
8790 (buffer (marker-buffer marker))
8791 (pos (marker-position marker))
8792 (hdmarker (org-get-at-bol 'org-hd-marker))
8793 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8794 (inhibit-read-only t)
8795 org-agenda-headline-snapshot-before-repeat newhead just-one)
8796 (org-with-remote-undo buffer
8797 (with-current-buffer buffer
8800 (org-show-context 'agenda)
8802 (and (outline-next-heading)
8803 (org-flag-heading nil))) ; show the next heading
8804 (let ((current-prefix-arg arg))
8805 (call-interactively 'org-todo))
8806 (and (bolp) (forward-char 1))
8807 (setq newhead (org-get-heading))
8808 (when (and (org-bound-and-true-p
8809 org-agenda-headline-snapshot-before-repeat)
8810 (not (equal org-agenda-headline-snapshot-before-repeat
8813 (setq newhead org-agenda-headline-snapshot-before-repeat
8816 (org-back-to-heading)
8817 (move-marker org-last-heading-marker (point))))
8818 (beginning-of-line 1)
8819 (save-window-excursion
8820 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8821 (when (org-bound-and-true-p org-clock-out-when-done)
8822 (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
8824 (org-agenda-unmark-clocking-task))
8825 (org-move-to-column col)
8826 (org-agenda-mark-clocking-task))))
8828 (defun org-agenda-add-note (&optional arg)
8829 "Add a time-stamped note to the entry at point."
8831 (org-agenda-check-no-diary)
8832 (let* ((marker (or (org-get-at-bol 'org-marker)
8833 (org-agenda-error)))
8834 (buffer (marker-buffer marker))
8835 (pos (marker-position marker))
8836 (hdmarker (org-get-at-bol 'org-hd-marker))
8837 (inhibit-read-only t))
8838 (with-current-buffer buffer
8841 (org-show-context 'agenda)
8843 (and (outline-next-heading)
8844 (org-flag-heading nil))) ; show the next heading
8847 (defun org-agenda-change-all-lines (newhead hdmarker
8848 &optional fixface just-this)
8849 "Change all lines in the agenda buffer which match HDMARKER.
8850 The new content of the line will be NEWHEAD (as modified by
8851 `org-agenda-format-item'). HDMARKER is checked with
8852 `equal' against all `org-hd-marker' text properties in the file.
8853 If FIXFACE is non-nil, the face of each item is modified according to
8855 If JUST-THIS is non-nil, change just the current line, not all.
8856 If FORCE-TAGS is non nil, the car of it returns the new tags."
8857 (let* ((inhibit-read-only t)
8858 (line (org-current-line))
8859 (org-agenda-buffer (current-buffer))
8860 (thetags (with-current-buffer (marker-buffer hdmarker)
8861 (save-excursion (save-restriction (widen)
8862 (goto-char hdmarker)
8863 (org-get-tags-at)))))
8864 props m pl undone-face done-face finish new dotime level cat tags)
8866 (goto-char (point-max))
8867 (beginning-of-line 1)
8869 (setq finish (bobp))
8870 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8871 (or (not just-this) (= (org-current-line) line))
8873 (setq props (text-properties-at (point))
8874 dotime (org-get-at-bol 'dotime)
8875 cat (org-get-at-eol 'org-category 1)
8876 level (org-get-at-bol 'level)
8879 (let ((org-prefix-format-compiled
8880 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8881 org-prefix-format-compiled))
8882 (extra (org-get-at-bol 'extra)))
8883 (with-current-buffer (marker-buffer hdmarker)
8887 (org-agenda-format-item extra newhead level cat tags dotime)))))
8888 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8889 undone-face (org-get-at-bol 'undone-face)
8890 done-face (org-get-at-bol 'done-face))
8891 (beginning-of-line 1)
8894 (and (looking-at ".*\n?") (replace-match "")))
8896 (replace-match new t t)
8897 (beginning-of-line 1)
8898 (add-text-properties (point-at-bol) (point-at-eol) props)
8900 (add-text-properties
8901 (point-at-bol) (point-at-eol)
8903 (if org-last-todo-state-is-todo
8904 undone-face done-face))))
8905 (org-agenda-highlight-todo 'line)
8906 (beginning-of-line 1))
8907 (t (error "Line update did not work")))
8909 (narrow-to-region (point-at-bol) (point-at-eol))
8910 (org-agenda-finalize)))
8911 (beginning-of-line 0)))))
8913 (defun org-agenda-align-tags (&optional line)
8914 "Align all tags in agenda items to `org-agenda-tags-column'."
8915 (let ((inhibit-read-only t) l c)
8917 (goto-char (if line (point-at-bol) (point-min)))
8918 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8919 (if line (point-at-eol) nil) t)
8920 (add-text-properties
8921 (match-beginning 2) (match-end 2)
8922 (list 'face (delq nil (let ((prop (get-text-property
8923 (match-beginning 2) 'face)))
8924 (or (listp prop) (setq prop (list prop)))
8925 (if (memq 'org-tag prop)
8927 (cons 'org-tag prop))))))
8928 (setq l (- (match-end 2) (match-beginning 2))
8929 c (if (< org-agenda-tags-column 0)
8930 (- (abs org-agenda-tags-column) l)
8931 org-agenda-tags-column))
8932 (delete-region (match-beginning 1) (match-end 1))
8933 (goto-char (match-beginning 1))
8934 (insert (org-add-props
8935 (make-string (max 1 (- c (current-column))) ?\ )
8936 (plist-put (copy-sequence (text-properties-at (point)))
8938 (goto-char (point-min))
8939 (org-font-lock-add-tag-faces (point-max)))))
8941 (defun org-agenda-priority-up ()
8942 "Increase the priority of line at point, also in Org-mode file."
8944 (org-agenda-priority 'up))
8946 (defun org-agenda-priority-down ()
8947 "Decrease the priority of line at point, also in Org-mode file."
8949 (org-agenda-priority 'down))
8951 (defun org-agenda-priority (&optional force-direction)
8952 "Set the priority of line at point, also in Org-mode file.
8953 This changes the line at point, all other lines in the agenda referring to
8954 the same tree node, and the headline of the tree node in the Org-mode file.
8955 Called with a universal prefix arg, show the priority instead of setting it."
8957 (if (equal force-direction '(4))
8959 (unless org-enable-priority-commands
8960 (error "Priority commands are disabled"))
8961 (org-agenda-check-no-diary)
8962 (let* ((col (current-column))
8963 (marker (or (org-get-at-bol 'org-marker)
8964 (org-agenda-error)))
8965 (hdmarker (org-get-at-bol 'org-hd-marker))
8966 (buffer (marker-buffer hdmarker))
8967 (pos (marker-position hdmarker))
8968 (inhibit-read-only t)
8970 (org-with-remote-undo buffer
8971 (with-current-buffer buffer
8974 (org-show-context 'agenda)
8976 (and (outline-next-heading)
8977 (org-flag-heading nil))) ; show the next heading
8978 (funcall 'org-priority force-direction)
8980 (setq newhead (org-get-heading)))
8981 (org-agenda-change-all-lines newhead hdmarker)
8982 (org-move-to-column col)))))
8984 ;; FIXME: should fix the tags property of the agenda line.
8985 (defun org-agenda-set-tags (&optional tag onoff)
8986 "Set tags for the current headline."
8988 (org-agenda-check-no-diary)
8989 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8990 (call-interactively 'org-change-tag-in-region)
8991 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8992 (org-agenda-error)))
8993 (buffer (marker-buffer hdmarker))
8994 (pos (marker-position hdmarker))
8995 (inhibit-read-only t)
8997 (org-with-remote-undo buffer
8998 (with-current-buffer buffer
9002 (org-show-context 'agenda))
9004 (and (outline-next-heading)
9005 (org-flag-heading nil))) ; show the next heading
9008 (org-toggle-tag tag onoff)
9009 (call-interactively 'org-set-tags))
9011 (setq newhead (org-get-heading)))
9012 (org-agenda-change-all-lines newhead hdmarker)
9013 (beginning-of-line 1)))))
9015 (defun org-agenda-set-property ()
9016 "Set a property for the current headline."
9018 (org-agenda-check-no-diary)
9019 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9020 (org-agenda-error)))
9021 (buffer (marker-buffer hdmarker))
9022 (pos (marker-position hdmarker))
9023 (inhibit-read-only t)
9025 (org-with-remote-undo buffer
9026 (with-current-buffer buffer
9030 (org-show-context 'agenda))
9032 (and (outline-next-heading)
9033 (org-flag-heading nil))) ; show the next heading
9035 (call-interactively 'org-set-property)))))
9037 (defun org-agenda-set-effort ()
9038 "Set the effort property for the current headline."
9040 (org-agenda-check-no-diary)
9041 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9042 (org-agenda-error)))
9043 (buffer (marker-buffer hdmarker))
9044 (pos (marker-position hdmarker))
9045 (inhibit-read-only t)
9047 (org-with-remote-undo buffer
9048 (with-current-buffer buffer
9052 (org-show-context 'agenda))
9054 (and (outline-next-heading)
9055 (org-flag-heading nil))) ; show the next heading
9057 (call-interactively 'org-set-effort)
9059 (setq newhead (org-get-heading)))
9060 (org-agenda-change-all-lines newhead hdmarker))))
9062 (defun org-agenda-toggle-archive-tag ()
9063 "Toggle the archive tag for the current entry."
9065 (org-agenda-check-no-diary)
9066 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9067 (org-agenda-error)))
9068 (buffer (marker-buffer hdmarker))
9069 (pos (marker-position hdmarker))
9070 (inhibit-read-only t)
9072 (org-with-remote-undo buffer
9073 (with-current-buffer buffer
9076 (org-show-context 'agenda)
9078 (and (outline-next-heading)
9079 (org-flag-heading nil))) ; show the next heading
9080 (call-interactively 'org-toggle-archive-tag)
9082 (setq newhead (org-get-heading)))
9083 (org-agenda-change-all-lines newhead hdmarker)
9084 (beginning-of-line 1))))
9086 (defun org-agenda-do-date-later (arg)
9089 ((or (equal arg '(16))
9091 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9092 (setq this-command 'org-agenda-date-later-minutes)
9093 (org-agenda-date-later-minutes 1))
9094 ((or (equal arg '(4))
9096 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9097 (setq this-command 'org-agenda-date-later-hours)
9098 (org-agenda-date-later-hours 1))
9100 (org-agenda-date-later (prefix-numeric-value arg)))))
9102 (defun org-agenda-do-date-earlier (arg)
9105 ((or (equal arg '(16))
9107 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9108 (setq this-command 'org-agenda-date-earlier-minutes)
9109 (org-agenda-date-earlier-minutes 1))
9110 ((or (equal arg '(4))
9112 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9113 (setq this-command 'org-agenda-date-earlier-hours)
9114 (org-agenda-date-earlier-hours 1))
9116 (org-agenda-date-earlier (prefix-numeric-value arg)))))
9118 (defun org-agenda-date-later (arg &optional what)
9119 "Change the date of this item to ARG day(s) later."
9121 (org-agenda-check-type t 'agenda 'timeline)
9122 (org-agenda-check-no-diary)
9123 (let* ((marker (or (org-get-at-bol 'org-marker)
9124 (org-agenda-error)))
9125 (buffer (marker-buffer marker))
9126 (pos (marker-position marker))
9128 (org-with-remote-undo buffer
9129 (with-current-buffer buffer
9132 (if (not (org-at-timestamp-p))
9133 (error "Cannot find time stamp"))
9134 (when (and org-agenda-move-date-from-past-immediately-to-today
9136 (or (not what) (eq what 'day))
9137 (not (save-match-data (org-at-date-range-p))))
9138 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
9139 cdate (calendar-absolute-from-gregorian
9140 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
9143 ;; immediately shift to today
9144 (setq arg (- today cdate))))
9145 (org-timestamp-change arg (or what 'day))
9146 (when (and (org-at-date-range-p)
9147 (re-search-backward org-tr-regexp-both (point-at-bol)))
9148 (let ((end org-last-changed-timestamp))
9149 (org-timestamp-change arg (or what 'day))
9150 (setq org-last-changed-timestamp
9151 (concat org-last-changed-timestamp "--" end)))))
9152 (org-agenda-show-new-time marker org-last-changed-timestamp))
9153 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9155 (defun org-agenda-date-earlier (arg &optional what)
9156 "Change the date of this item to ARG day(s) earlier."
9158 (org-agenda-date-later (- arg) what))
9160 (defun org-agenda-date-later-minutes (arg)
9161 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9163 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9164 (org-agenda-date-later arg 'minute))
9166 (defun org-agenda-date-earlier-minutes (arg)
9167 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9169 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9170 (org-agenda-date-earlier arg 'minute))
9172 (defun org-agenda-date-later-hours (arg)
9173 "Change the time of this item, in hour steps."
9175 (org-agenda-date-later arg 'hour))
9177 (defun org-agenda-date-earlier-hours (arg)
9178 "Change the time of this item, in hour steps."
9180 (org-agenda-date-earlier arg 'hour))
9182 (defun org-agenda-show-new-time (marker stamp &optional prefix)
9183 "Show new date stamp via text properties."
9184 ;; We use text properties to make this undoable
9185 (let ((inhibit-read-only t))
9186 (setq stamp (concat prefix " => " stamp " "))
9188 (goto-char (point-max))
9190 (when (equal marker (org-get-at-bol 'org-marker))
9191 (remove-text-properties (point-at-bol) (point-at-eol) '(display))
9192 (org-move-to-column (- (window-width) (length stamp)) t)
9193 (if (featurep 'xemacs)
9194 ;; Use `duplicable' property to trigger undo recording
9195 (let ((ex (make-extent nil nil))
9196 (gl (make-glyph stamp)))
9197 (set-glyph-face gl 'secondary-selection)
9198 (set-extent-properties
9199 ex (list 'invisible t 'end-glyph gl 'duplicable t))
9200 (insert-extent ex (1- (point)) (point-at-eol)))
9201 (add-text-properties
9202 (1- (point)) (point-at-eol)
9203 (list 'display (org-add-props stamp nil
9204 'face '(secondary-selection default)))))
9205 (beginning-of-line 1))
9206 (beginning-of-line 0)))))
9208 (defun org-agenda-date-prompt (arg)
9209 "Change the date of this item. Date is prompted for, with default today.
9210 The prefix ARG is passed to the `org-time-stamp' command and can therefore
9211 be used to request time specification in the time stamp."
9213 (org-agenda-check-type t 'agenda 'timeline)
9214 (org-agenda-check-no-diary)
9215 (let* ((marker (or (org-get-at-bol 'org-marker)
9216 (org-agenda-error)))
9217 (buffer (marker-buffer marker))
9218 (pos (marker-position marker)))
9219 (org-with-remote-undo buffer
9220 (with-current-buffer buffer
9223 (if (not (org-at-timestamp-p t))
9224 (error "Cannot find time stamp"))
9225 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
9226 (org-agenda-show-new-time marker org-last-changed-timestamp))
9227 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9229 (defun org-agenda-schedule (arg &optional time)
9230 "Schedule the item at point.
9231 ARG is passed through to `org-schedule'."
9233 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9234 (org-agenda-check-no-diary)
9235 (let* ((marker (or (org-get-at-bol 'org-marker)
9236 (org-agenda-error)))
9237 (type (marker-insertion-type marker))
9238 (buffer (marker-buffer marker))
9239 (pos (marker-position marker))
9240 (org-insert-labeled-timestamps-at-point nil)
9242 (set-marker-insertion-type marker t)
9243 (org-with-remote-undo buffer
9244 (with-current-buffer buffer
9247 (setq ts (org-schedule arg time)))
9248 (org-agenda-show-new-time marker ts " S"))
9251 (defun org-agenda-deadline (arg &optional time)
9252 "Schedule the item at point.
9253 ARG is passed through to `org-deadline'."
9255 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9256 (org-agenda-check-no-diary)
9257 (let* ((marker (or (org-get-at-bol 'org-marker)
9258 (org-agenda-error)))
9259 (buffer (marker-buffer marker))
9260 (pos (marker-position marker))
9261 (org-insert-labeled-timestamps-at-point nil)
9263 (org-with-remote-undo buffer
9264 (with-current-buffer buffer
9267 (setq ts (org-deadline arg time)))
9268 (org-agenda-show-new-time marker ts " D"))
9271 (defun org-agenda-clock-in (&optional arg)
9272 "Start the clock on the currently selected item."
9274 (org-agenda-check-no-diary)
9275 (if (equal arg '(4))
9277 (let* ((marker (or (org-get-at-bol 'org-marker)
9278 (org-agenda-error)))
9279 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
9280 (pos (marker-position marker))
9281 (col (current-column))
9283 (org-with-remote-undo (marker-buffer marker)
9284 (with-current-buffer (marker-buffer marker)
9287 (org-show-context 'agenda)
9289 (org-cycle-hide-drawers 'children)
9291 (setq newhead (org-get-heading)))
9292 (org-agenda-change-all-lines newhead hdmarker))
9293 (org-move-to-column col))))
9295 (defun org-agenda-clock-out ()
9296 "Stop the currently running clock."
9298 (unless (marker-buffer org-clock-marker)
9299 (error "No running clock"))
9300 (let ((marker (make-marker)) (col (current-column)) newhead)
9301 (org-with-remote-undo (marker-buffer org-clock-marker)
9302 (with-current-buffer (marker-buffer org-clock-marker)
9306 (goto-char org-clock-marker)
9307 (org-back-to-heading t)
9308 (move-marker marker (point))
9310 (setq newhead (org-get-heading))))))
9311 (org-agenda-change-all-lines newhead marker)
9312 (move-marker marker nil)
9313 (org-move-to-column col)
9314 (org-agenda-unmark-clocking-task)))
9316 (defun org-agenda-clock-cancel (&optional arg)
9317 "Cancel the currently running clock."
9319 (unless (marker-buffer org-clock-marker)
9320 (user-error "No running clock"))
9321 (org-with-remote-undo (marker-buffer org-clock-marker)
9322 (org-clock-cancel)))
9324 (defun org-agenda-clock-goto ()
9325 "Jump to the currently clocked in task within the agenda.
9326 If the currently clocked in task is not listed in the agenda
9327 buffer, display it in another window."
9331 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
9332 (setq pos (overlay-start o))))
9333 (overlays-in (point-min) (point-max)))
9334 (cond (pos (goto-char pos))
9335 ;; If the currently clocked entry is not in the agenda
9336 ;; buffer, we visit it in another window:
9337 (org-clock-current-task
9338 (org-switch-to-buffer-other-window (org-clock-goto)))
9339 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
9341 (defun org-agenda-diary-entry-in-org-file ()
9342 "Make a diary entry in the file `org-agenda-diary-file'."
9343 (let (d1 d2 char (text "") dp1 dp2)
9344 (if (equal (buffer-name) "*Calendar*")
9345 (setq d1 (calendar-cursor-to-date t)
9346 d2 (car calendar-mark-ring))
9347 (setq dp1 (get-text-property (point-at-bol) 'day))
9348 (unless dp1 (user-error "No date defined in current line"))
9349 (setq d1 (calendar-gregorian-from-absolute dp1)
9350 d2 (and (ignore-errors (mark))
9353 (setq dp2 (get-text-property (point-at-bol) 'day)))
9354 (calendar-gregorian-from-absolute dp2))))
9355 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9356 (setq char (read-char-exclusive))
9359 (setq text (read-string "Day entry: "))
9360 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9361 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9363 (setq d1 (list (car d1) (nth 1 d1)
9364 (read-number (format "Reference year [%d]: " (nth 2 d1))
9366 (setq text (read-string "Anniversary (use %d to show years): "))
9367 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9368 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9370 (setq text (read-string "Block entry: "))
9371 (unless (and d1 d2 (not (equal d1 d2)))
9372 (user-error "No block of days selected"))
9373 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9374 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9376 (org-switch-to-buffer-other-window
9377 (find-file-noselect org-agenda-diary-file))
9378 (require 'org-datetree)
9379 (org-datetree-find-date-create d1)
9381 (t (user-error "Invalid selection character `%c'" char)))))
9383 (defcustom org-agenda-insert-diary-strategy 'date-tree
9384 "Where in `org-agenda-diary-file' should new entries be added?
9387 date-tree in the date tree, as child of the date
9388 top-level as top-level entries at the end of the file."
9391 (const :tag "in a date tree" date-tree)
9392 (const :tag "as top level at end of file" top-level)))
9394 (defcustom org-agenda-insert-diary-extract-time nil
9395 "Non-nil means extract any time specification from the diary entry."
9400 (defcustom org-agenda-bulk-mark-char ">"
9401 "A single-character string to be used as the bulk mark."
9406 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9407 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9408 If TEXT is not empty, it will become the headline of the new entry, and
9409 the resulting entry will not be shown. When TEXT is empty, switch to
9410 `org-agenda-diary-file' and let the user finish the entry there."
9411 (let ((cw (current-window-configuration)))
9412 (org-switch-to-buffer-other-window
9413 (find-file-noselect org-agenda-diary-file))
9415 (goto-char (point-min))
9417 ((eq type 'anniversary)
9418 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9420 (or (org-at-heading-p t)
9422 (outline-next-heading)
9423 (insert "* Anniversaries\n\n")
9424 (beginning-of-line -1)))))
9425 (outline-next-heading)
9426 (org-back-over-empty-lines)
9429 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9430 (nth 2 d1) (car d1) (nth 1 d1) text)))
9432 (let ((org-prefix-has-time t)
9433 (org-agenda-time-leading-zero t)
9435 (if org-agenda-insert-diary-extract-time
9436 ;; Use org-agenda-format-item to parse text for a time-range and
9437 ;; remove it. FIXME: This is a hack, we should refactor
9438 ;; that function to make time extraction available separately
9439 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9440 time (get-text-property 0 'time fmt)
9441 time2 (if (> (length time) 0)
9442 ;; split-string removes trailing ...... if
9443 ;; no end time given. First space
9444 ;; separates time from date.
9445 (concat " " (car (split-string time "\\.")))
9447 text (get-text-property 0 'txt fmt)))
9448 (if (eq org-agenda-insert-diary-strategy 'top-level)
9449 (org-agenda-insert-diary-as-top-level text)
9450 (require 'org-datetree)
9451 (org-datetree-find-date-create d1)
9452 (org-agenda-insert-diary-make-new-entry text))
9453 (org-insert-time-stamp (org-time-from-absolute
9454 (calendar-absolute-from-gregorian d1))
9455 nil nil nil nil time2))
9458 (if (> (calendar-absolute-from-gregorian d1)
9459 (calendar-absolute-from-gregorian d2))
9460 (setq d1 (prog1 d2 (setq d2 d1))))
9461 (if (eq org-agenda-insert-diary-strategy 'top-level)
9462 (org-agenda-insert-diary-as-top-level text)
9463 (require 'org-datetree)
9464 (org-datetree-find-date-create d1)
9465 (org-agenda-insert-diary-make-new-entry text))
9466 (org-insert-time-stamp (org-time-from-absolute
9467 (calendar-absolute-from-gregorian d1)))
9469 (org-insert-time-stamp (org-time-from-absolute
9470 (calendar-absolute-from-gregorian d2)))
9472 (if (string-match "\\S-" text)
9474 (set-window-configuration cw)
9475 (message "%s entry added to %s"
9476 (capitalize (symbol-name type))
9477 (abbreviate-file-name org-agenda-diary-file)))
9479 (message "Please finish entry here"))))
9481 (defun org-agenda-insert-diary-as-top-level (text)
9482 "Make new entry as a top-level entry at the end of the file.
9483 Add TEXT as headline, and position the cursor in the second line so that
9484 a timestamp can be added there."
9486 (goto-char (point-max))
9487 (or (bolp) (insert "\n"))
9488 (insert "* " text "\n")
9489 (if org-adapt-indentation (org-indent-to-column 2)))
9491 (defun org-agenda-insert-diary-make-new-entry (text)
9492 "Make a new entry with TEXT as the first child of the current subtree.
9493 Position the point in the line right after the new heading so
9494 that a timestamp can be added there."
9495 (let ((org-show-following-heading t)
9496 (org-show-siblings t)
9497 (org-show-hierarchy-above t)
9498 (org-show-entry-below t)
9500 (outline-next-heading)
9501 (org-back-over-empty-lines)
9502 (or (looking-at "[ \t]*$")
9503 (progn (insert "\n") (backward-char 1)))
9504 (org-insert-heading nil t)
9506 (setq col (current-column))
9508 (if org-adapt-indentation (org-indent-to-column col))
9509 (let ((org-show-following-heading t)
9510 (org-show-siblings t)
9511 (org-show-hierarchy-above t)
9512 (org-show-entry-below t))
9513 (org-show-context))))
9515 (defun org-agenda-diary-entry ()
9516 "Make a diary entry, like the `i' command from the calendar.
9517 All the standard commands work: block, weekly etc.
9518 When `org-agenda-diary-file' points to a file,
9519 `org-agenda-diary-entry-in-org-file' is called instead to create
9520 entries in that Org-mode file."
9522 (if (not (eq org-agenda-diary-file 'diary-file))
9523 (org-agenda-diary-entry-in-org-file)
9524 (require 'diary-lib)
9526 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9527 (read-char-exclusive)))
9528 (cmd (cdr (assoc char
9529 '((?d . insert-diary-entry)
9530 (?w . insert-weekly-diary-entry)
9531 (?m . insert-monthly-diary-entry)
9532 (?y . insert-yearly-diary-entry)
9533 (?a . insert-anniversary-diary-entry)
9534 (?b . insert-block-diary-entry)
9535 (?c . insert-cyclic-diary-entry)))))
9536 (oldf (symbol-function 'calendar-cursor-to-date))
9537 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9539 (mark (or (mark t) (point))))
9541 (user-error "No command associated with <%c>" char))
9542 (unless (and (get-text-property point 'day)
9543 (or (not (equal ?b char))
9544 (get-text-property mark 'day)))
9545 (user-error "Don't know which date to use for diary entry"))
9546 ;; We implement this by hacking the `calendar-cursor-to-date' function
9547 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9548 (let ((calendar-mark-ring
9549 (list (calendar-gregorian-from-absolute
9550 (or (get-text-property mark 'day)
9551 (get-text-property point 'day))))))
9554 (fset 'calendar-cursor-to-date
9555 (lambda (&optional error dummy)
9556 (calendar-gregorian-from-absolute
9557 (get-text-property point 'day))))
9558 (call-interactively cmd))
9559 (fset 'calendar-cursor-to-date oldf))))))
9561 (defun org-agenda-execute-calendar-command (cmd)
9562 "Execute a calendar command from the agenda with date from cursor."
9563 (org-agenda-check-type t 'agenda 'timeline)
9564 (require 'diary-lib)
9565 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9566 (user-error "Don't know which date to use for the calendar command"))
9567 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9569 (date (calendar-gregorian-from-absolute
9570 (get-text-property point 'day)))
9571 ;; the following 2 vars are needed in the calendar
9572 (displayed-month (car date))
9573 (displayed-year (nth 2 date)))
9576 (fset 'calendar-cursor-to-date
9577 (lambda (&optional error dummy)
9578 (calendar-gregorian-from-absolute
9579 (get-text-property point 'day))))
9580 (call-interactively cmd))
9581 (fset 'calendar-cursor-to-date oldf))))
9583 (defun org-agenda-phases-of-moon ()
9584 "Display the phases of the moon for the 3 months around the cursor date."
9586 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9588 (defun org-agenda-holidays ()
9589 "Display the holidays for the 3 months around the cursor date."
9591 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9593 (defvar calendar-longitude) ; defined in calendar.el
9594 (defvar calendar-latitude) ; defined in calendar.el
9595 (defvar calendar-location-name) ; defined in calendar.el
9597 (defun org-agenda-sunrise-sunset (arg)
9598 "Display sunrise and sunset for the cursor date.
9599 Latitude and longitude can be specified with the variables
9600 `calendar-latitude' and `calendar-longitude'. When called with prefix
9601 argument, latitude and longitude will be prompted for."
9604 (let ((calendar-longitude (if arg nil calendar-longitude))
9605 (calendar-latitude (if arg nil calendar-latitude))
9606 (calendar-location-name
9607 (if arg "the given coordinates" calendar-location-name)))
9608 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9610 (defun org-agenda-goto-calendar ()
9611 "Open the Emacs calendar with the date at the cursor."
9613 (org-agenda-check-type t 'agenda 'timeline)
9614 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9615 (user-error "Don't know which date to open in calendar")))
9616 (date (calendar-gregorian-from-absolute day))
9617 (calendar-move-hook nil)
9618 (calendar-view-holidays-initially-flag nil)
9619 (calendar-view-diary-initially-flag nil))
9621 (calendar-goto-date date)))
9624 (defun org-calendar-goto-agenda ()
9625 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9626 This is a command that has to be installed in `calendar-mode-map'."
9628 (org-agenda-list nil (calendar-absolute-from-gregorian
9629 (calendar-cursor-to-date))
9632 (defun org-agenda-convert-date ()
9634 (org-agenda-check-type t 'agenda 'timeline)
9635 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9638 (user-error "Don't know which date to convert"))
9639 (setq date (calendar-gregorian-from-absolute day))
9641 "Gregorian: " (calendar-date-string date) "\n"
9642 "ISO: " (calendar-iso-date-string date) "\n"
9643 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9644 "Julian: " (calendar-julian-date-string date) "\n"
9645 "Astron. JD: " (calendar-astro-date-string date)
9646 " (Julian date number at noon UTC)\n"
9647 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9648 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9649 "French: " (calendar-french-date-string date) "\n"
9650 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9651 "Mayan: " (calendar-mayan-date-string date) "\n"
9652 "Coptic: " (calendar-coptic-date-string date) "\n"
9653 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9654 "Persian: " (calendar-persian-date-string date) "\n"
9655 "Chinese: " (calendar-chinese-date-string date) "\n"))
9656 (with-output-to-temp-buffer "*Dates*"
9658 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9662 (defun org-agenda-bulk-marked-p ()
9663 (eq (get-char-property (point-at-bol) 'type)
9664 'org-marked-entry-overlay))
9666 (defun org-agenda-bulk-mark (&optional arg)
9667 "Mark the entry at point for future bulk action."
9669 (dotimes (i (or arg 1))
9670 (unless (org-get-at-bol 'org-agenda-diary-link)
9671 (let* ((m (org-get-at-bol 'org-hd-marker))
9673 (unless (org-agenda-bulk-marked-p)
9674 (unless m (user-error "Nothing to mark at point"))
9675 (push m org-agenda-bulk-marked-entries)
9676 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9677 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9678 (org-get-todo-face "TODO")
9680 (overlay-put ov 'type 'org-marked-entry-overlay))
9683 (goto-char (next-single-property-change (point) 'org-hd-marker)))
9684 (beginning-of-line 2))
9685 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9686 (beginning-of-line 2))
9687 (message "%d entries marked for bulk action"
9688 (length org-agenda-bulk-marked-entries))))))
9690 (defun org-agenda-bulk-mark-all ()
9691 "Mark all entries for future agenda bulk action."
9693 (org-agenda-bulk-mark-regexp "."))
9695 (defun org-agenda-bulk-mark-regexp (regexp)
9696 "Mark entries matching REGEXP for future agenda bulk action."
9697 (interactive "sMark entries matching regexp: ")
9698 (let ((entries-marked 0) txt-at-point)
9700 (goto-char (point-min))
9701 (goto-char (next-single-property-change (point) 'org-hd-marker))
9702 (while (and (re-search-forward regexp nil t)
9703 (setq txt-at-point (get-text-property (point) 'txt)))
9704 (when (string-match regexp txt-at-point)
9705 (setq entries-marked (1+ entries-marked))
9706 (call-interactively 'org-agenda-bulk-mark))))
9707 (if (not entries-marked)
9708 (message "No entry matching this regexp."))))
9710 (defun org-agenda-bulk-unmark (&optional arg)
9711 "Unmark the entry at point for future bulk action."
9714 (org-agenda-bulk-unmark-all)
9715 (cond ((org-agenda-bulk-marked-p)
9716 (org-agenda-bulk-remove-overlays
9717 (point-at-bol) (+ 2 (point-at-bol)))
9718 (setq org-agenda-bulk-marked-entries
9719 (delete (org-get-at-bol 'org-hd-marker)
9720 org-agenda-bulk-marked-entries))
9723 (goto-char (next-single-property-change (point) 'txt)))
9724 (beginning-of-line 2))
9725 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9726 (beginning-of-line 2))
9727 (message "%d entries left marked for bulk action"
9728 (length org-agenda-bulk-marked-entries)))
9729 (t (message "No entry to unmark here")))))
9731 (defun org-agenda-bulk-toggle-all ()
9732 "Toggle all marks for bulk action."
9735 (goto-char (point-min))
9736 (while (ignore-errors
9737 (goto-char (next-single-property-change (point) 'org-hd-marker)))
9738 (org-agenda-bulk-toggle))))
9740 (defun org-agenda-bulk-toggle ()
9741 "Toggle the mark at point for bulk action."
9743 (if (org-agenda-bulk-marked-p)
9744 (org-agenda-bulk-unmark)
9745 (org-agenda-bulk-mark)))
9747 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9748 "Remove the mark overlays between BEG and END in the agenda buffer.
9749 BEG and END default to the buffer limits.
9751 This only removes the overlays, it does not remove the markers
9752 from the list in `org-agenda-bulk-marked-entries'."
9755 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9756 (delete-overlay ov)))
9757 (overlays-in (or beg (point-min)) (or end (point-max)))))
9759 (defun org-agenda-bulk-unmark-all ()
9760 "Remove all marks in the agenda buffer.
9761 This will remove the markers and the overlays."
9763 (if (null org-agenda-bulk-marked-entries)
9764 (message "No entry to unmark")
9765 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9766 (setq org-agenda-bulk-marked-entries nil)
9767 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9769 (defcustom org-agenda-persistent-marks nil
9770 "Non-nil means marked items will stay marked after a bulk action.
9771 You can toggle this interactively by typing `p' when prompted for a
9777 (defun org-agenda-bulk-action (&optional arg)
9778 "Execute an remote-editing action on all marked entries.
9779 The prefix arg is passed through to the command if possible."
9781 ;; Make sure we have markers, and only valid ones
9782 (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
9785 (unless (and (markerp m)
9787 (buffer-live-p (marker-buffer m))
9788 (marker-position m))
9789 (user-error "Marker %s for bulk command is invalid" m)))
9790 org-agenda-bulk-marked-entries)
9792 ;; Prompt for the bulk command
9793 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9794 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9795 "[S]catter [f]unction "
9796 (when org-agenda-bulk-custom-functions
9797 (concat " Custom: ["
9798 (mapconcat (lambda(f) (char-to-string (car f)))
9799 org-agenda-bulk-custom-functions "")
9802 (let* ((action (read-char-exclusive))
9803 (org-log-refile (if org-log-refile 'time nil))
9804 (entries (reverse org-agenda-bulk-marked-entries))
9805 (org-overriding-default-time
9806 (if (get-text-property (point) 'org-agenda-date-header)
9807 (org-get-cursor-date)))
9809 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9812 (let ((org-agenda-persistent-marks
9813 (not org-agenda-persistent-marks)))
9814 (org-agenda-bulk-action)
9818 (setq cmd '(org-agenda-archive)))
9821 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9823 ((member action '(?r ?w))
9824 (setq rfloc (org-refile-get-location
9826 (marker-buffer (car entries))
9827 org-refile-allow-creating-parent-nodes))
9829 (setcar (nthcdr 3 rfloc)
9830 (move-marker (make-marker) (nth 3 rfloc)
9831 (or (get-file-buffer (nth 1 rfloc))
9832 (find-buffer-visiting (nth 1 rfloc))
9833 (error "This should not happen")))))
9835 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9839 (setq state (org-icompleting-read
9841 (with-current-buffer (marker-buffer (car entries))
9842 (mapcar 'list org-todo-keywords-1))))
9843 (setq cmd `(let ((org-inhibit-blocking t)
9844 (org-inhibit-logging 'note))
9845 (org-agenda-todo ,state))))
9847 ((memq action '(?- ?+))
9848 (setq tag (org-icompleting-read
9849 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9850 (with-current-buffer (marker-buffer (car entries))
9853 (if (stringp (car x)) x)) org-tag-alist)))))
9854 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9856 ((memq action '(?s ?d))
9861 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9862 org-overriding-default-time)))
9863 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9864 (setq cmd `(eval '(,c1 arg ,time)))))
9867 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9868 (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9869 (let ((days (read-number
9870 (format "Scatter tasks across how many %sdays: "
9871 (if arg "week" "")) 7)))
9873 `(let ((distance (1+ (random ,days))))
9875 (let ((dist distance)
9877 (calendar-day-of-week
9878 (calendar-gregorian-from-absolute (org-today)))))
9879 (dotimes (i (1+ dist))
9880 (while (member day-of-week org-agenda-weekend-days)
9883 (if (= day-of-week 7)
9884 (setq day-of-week 0)))
9886 (if (= day-of-week 7)
9887 (setq day-of-week 0)))))
9888 ;; silently fail when try to replan a sexp entry
9890 (let* ((date (calendar-gregorian-from-absolute
9891 (+ (org-today) distance)))
9892 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9894 (org-agenda-schedule nil time))
9897 ((assoc action org-agenda-bulk-custom-functions)
9898 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9902 (setq cmd (list (intern
9903 (org-icompleting-read "Function: "
9904 obarray 'fboundp t nil nil)))))
9906 (t (user-error "Invalid bulk action")))
9908 ;; Sort the markers, to make sure that parents are handled before children
9909 (setq entries (sort entries
9912 ((equal (marker-buffer a) (marker-buffer b))
9913 (< (marker-position a) (marker-position b)))
9915 (string< (buffer-name (marker-buffer a))
9916 (buffer-name (marker-buffer b))))))))
9918 ;; Now loop over all markers and apply cmd
9919 (while (setq e (pop entries))
9920 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9922 (progn (message "Skipping removed entry at %s" e)
9923 (setq cntskip (1+ cntskip)))
9925 (let (org-loop-over-headlines-in-active-region)
9927 (setq cnt (1+ cnt))))
9928 (when redo-at-end (org-agenda-redo))
9929 (unless org-agenda-persistent-marks
9930 (org-agenda-bulk-unmark-all))
9931 (message "Acted on %d entries%s%s"
9935 (format ", skipped %d (disappeared before their turn)"
9937 (if (not org-agenda-persistent-marks)
9938 "" " (kept marked)"))))))
9940 (defun org-agenda-capture (&optional with-time)
9941 "Call `org-capture' with the date at point.
9942 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9943 current HH:MM time."
9945 (if (not (eq major-mode 'org-agenda-mode))
9946 (user-error "You cannot do this outside of agenda buffers")
9947 (let ((org-overriding-default-time
9948 (org-get-cursor-date (equal with-time 1))))
9949 (call-interactively 'org-capture))))
9951 ;;; Dragging agenda lines forward/backward
9953 (defun org-agenda-reapply-filters ()
9954 "Re-apply all agenda filters."
9956 (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f))))
9957 `((,org-agenda-tag-filter tag)
9958 (,org-agenda-category-filter category)
9959 (,org-agenda-regexp-filter regexp)
9960 (,org-agenda-effort-filter effort)
9961 (,(get 'org-agenda-tag-filter :preset-filter) tag)
9962 (,(get 'org-agenda-category-filter :preset-filter) category)
9963 (,(get 'org-agenda-effort-filter :preset-filter) effort)
9964 (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
9966 (defun org-agenda-drag-line-forward (arg &optional backward)
9967 "Drag an agenda line forward by ARG lines.
9968 When the optional argument `backward' is non-nil, move backward."
9970 (let ((inhibit-read-only t) lst line)
9971 (if (or (not (get-text-property (point) 'txt))
9974 (move-beginning-of-line (if backward 0 2))
9975 (push (not (get-text-property (point) 'txt)) lst))
9977 (message "Cannot move line forward")
9978 (let ((end (save-excursion (move-beginning-of-line 2) (point))))
9979 (move-beginning-of-line 1)
9980 (setq line (buffer-substring (point) end))
9981 (delete-region (point) end)
9982 (move-beginning-of-line (funcall (if backward '1- '1+) arg))
9984 (org-agenda-reapply-filters)
9985 (org-agenda-mark-clocking-task)
9986 (move-beginning-of-line 0)))))
9988 (defun org-agenda-drag-line-backward (arg)
9989 "Drag an agenda line backward by ARG lines."
9991 (org-agenda-drag-line-forward arg t))
9995 (defun org-agenda-show-the-flagging-note ()
9996 "Display the flagging note in the other window.
9997 When called a second time in direct sequence, offer to remove the FLAGGING
9998 tag and (if present) the flagging note."
10000 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
10001 (win (selected-window))
10002 note heading newhead)
10004 (user-error "No linked entry at point"))
10005 (if (and (eq this-command last-command)
10006 (y-or-n-p "Unflag and remove any flagging note? "))
10008 (org-agenda-remove-flag hdmarker)
10009 (let ((win (get-buffer-window "*Flagging Note*")))
10010 (and win (delete-window win)))
10011 (message "Entry unflagged"))
10012 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
10014 (user-error "No flagging note"))
10015 (org-kill-new note)
10016 (org-switch-to-buffer-other-window "*Flagging Note*")
10019 (goto-char (point-min))
10020 (while (re-search-forward "\\\\n" nil t)
10021 (replace-match "\n" t t))
10022 (goto-char (point-min))
10023 (select-window win)
10024 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
10026 (defun org-agenda-remove-flag (marker)
10027 "Remove the FLAGGED tag and any flagging note in the entry."
10029 (org-with-point-at marker
10030 (org-toggle-tag "FLAGGED" 'off)
10031 (org-entry-delete nil "THEFLAGGINGNOTE")
10032 (setq newhead (org-get-heading)))
10033 (org-agenda-change-all-lines newhead marker)
10034 (message "Entry unflagged")))
10036 (defun org-agenda-get-any-marker (&optional pos)
10037 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
10038 (get-text-property (or pos (point-at-bol)) 'org-marker)))
10040 ;;; Appointment reminders
10042 (defvar appt-time-msg-list) ; defined in appt.el
10045 (defun org-agenda-to-appt (&optional refresh filter &rest args)
10046 "Activate appointments found in `org-agenda-files'.
10047 With a \\[universal-argument] prefix, refresh the list of
10050 If FILTER is t, interactively prompt the user for a regular
10051 expression, and filter out entries that don't match it.
10053 If FILTER is a string, use this string as a regular expression
10054 for filtering entries out.
10056 If FILTER is a function, filter out entries against which
10057 calling the function returns nil. This function takes one
10058 argument: an entry from `org-agenda-get-day-entries'.
10060 FILTER can also be an alist with the car of each cell being
10061 either 'headline or 'category. For example:
10063 '((headline \"IMPORTANT\")
10064 (category \"Work\"))
10066 will only add headlines containing IMPORTANT or headlines
10067 belonging to the \"Work\" category.
10069 ARGS are symbols indicating what kind of entries to consider.
10070 By default `org-agenda-to-appt' will use :deadline*, :scheduled*
10071 \(i.e., deadlines and scheduled items with a hh:mm specification)
10072 and :timestamp entries. See the docstring of `org-diary' for
10073 details and examples.
10075 If an entry has a APPT_WARNTIME property, its value will be used
10076 to override `appt-message-warning-time'."
10078 (if refresh (setq appt-time-msg-list nil))
10080 (setq filter (read-from-minibuffer "Regexp filter: ")))
10081 (let* ((cnt 0) ; count added events
10082 (scope (or args '(:deadline* :scheduled* :timestamp)))
10083 (org-agenda-new-buffers nil)
10084 (org-deadline-warning-days 0)
10085 ;; Do not use `org-today' here because appt only takes
10086 ;; time and without date as argument, so it may pass wrong
10087 ;; information otherwise
10088 (today (org-date-to-gregorian
10089 (time-to-days (current-time))))
10090 (org-agenda-restrict nil)
10091 (files (org-agenda-files 'unrestricted)) entries file
10092 (org-agenda-buffer nil))
10093 ;; Get all entries which may contain an appt
10094 (org-agenda-prepare-buffers files)
10095 (while (setq file (pop files))
10099 (apply 'org-agenda-get-day-entries
10100 file today scope)))))
10101 ;; Map thru entries and find if we should filter them out
10104 (let* ((evt (org-trim
10105 (replace-regexp-in-string
10106 org-bracket-link-regexp "\\3"
10107 (or (get-text-property 1 'txt x) ""))))
10108 (cat (get-text-property (1- (length x)) 'org-category x))
10109 (tod (get-text-property 1 'time-of-day x))
10110 (ok (or (null filter)
10111 (and (stringp filter) (string-match filter evt))
10112 (and (functionp filter) (funcall filter x))
10113 (and (listp filter)
10114 (let ((cat-filter (cadr (assoc 'category filter)))
10115 (evt-filter (cadr (assoc 'headline filter))))
10116 (or (and (stringp cat-filter)
10117 (string-match cat-filter cat))
10118 (and (stringp evt-filter)
10119 (string-match evt-filter evt)))))))
10120 (wrn (get-text-property 1 'warntime x)))
10121 ;; FIXME: Shall we remove text-properties for the appt text?
10122 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
10124 (setq tod (concat "00" (number-to-string tod))
10125 tod (when (string-match
10126 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
10127 (concat (match-string 1 tod) ":"
10128 (match-string 2 tod))))
10129 (if (version< emacs-version "23.3")
10131 (appt-add tod evt wrn))
10132 (setq cnt (1+ cnt))))) entries)
10133 (org-release-buffers org-agenda-new-buffers)
10135 (message "No event to add")
10136 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
10138 (defun org-agenda-todayp (date)
10139 "Does DATE mean today, when considering `org-extend-today-until'?"
10140 (let ((today (org-today))
10141 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
10145 (defun org-agenda-todo-yesterday (&optional arg)
10146 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
10148 (let* ((hour (third (decode-time
10149 (org-current-time))))
10150 (org-extend-today-until (1+ hour)))
10151 (org-agenda-todo arg)))
10153 (provide 'org-agenda)
10155 ;;; org-agenda.el ends here