1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2016 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-iso-to-absolute
"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
)
90 (defvar org-clock-current-task
)
91 (defvar org-current-tag-alist
)
92 (defvar org-mobile-force-id-on-agenda-items
)
93 (defvar org-habit-show-habits
)
94 (defvar org-habit-show-habits-only-for-today
)
95 (defvar org-habit-show-all-today
)
97 ;; Defined somewhere in this file, but used before definition.
98 (defvar org-agenda-buffer-name
"*Org Agenda*")
99 (defvar org-agenda-overriding-header nil
)
100 (defvar org-agenda-title-append nil
)
101 (org-no-warnings (defvar entry
)) ;; unprefixed, from calendar.el
102 (org-no-warnings (defvar date
)) ;; unprefixed, from calendar.el
103 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
105 (defvar org-agenda-undo-list nil
106 "List of undoable operations in the agenda since last refresh.")
107 (defvar org-agenda-pending-undo-list nil
108 "In a series of undo commands, this is the list of remaining undo items.")
110 (defcustom org-agenda-confirm-kill
1
111 "When set, remote killing from the agenda buffer needs confirmation.
112 When t, a confirmation is always needed. When a number N, confirmation is
113 only needed when the text to be killed contains more than N non-white lines."
116 (const :tag
"Never" nil
)
117 (const :tag
"Always" t
)
118 (integer :tag
"When more than N lines")))
120 (defcustom org-agenda-compact-blocks nil
121 "Non-nil means make the block agenda more compact.
122 This is done globally by leaving out lines like the agenda span
123 name and week number or the separator lines."
127 (defcustom org-agenda-block-separator ?
=
128 "The separator between blocks in the agenda.
129 If this is a string, it will be used as the separator, with a newline added.
130 If it is a character, it will be repeated to fill the window width.
131 If nil the separator is disabled. In `org-agenda-custom-commands' this
132 addresses the separator between the current and the previous block."
135 (const :tag
"Disabled" nil
)
139 (defgroup org-agenda-export nil
140 "Options concerning exporting agenda views in Org-mode."
141 :tag
"Org Agenda Export"
144 (defcustom org-agenda-with-colors t
145 "Non-nil means use colors in agenda views."
146 :group
'org-agenda-export
149 (defcustom org-agenda-exporter-settings nil
150 "Alist of variable/value pairs that should be active during agenda export.
151 This is a good place to set options for ps-print and for htmlize.
152 Note that the way this is implemented, the values will be evaluated
153 before assigned to the variables. So make sure to quote values you do
154 *not* want evaluated, for example
156 (setq org-agenda-exporter-settings
157 \\='((ps-print-color-p \\='black-white)))"
158 :group
'org-agenda-export
162 (sexp :tag
"Value"))))
164 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
165 "Hook run in a temporary buffer before writing the agenda to an export file.
166 A useful function for this hook is `org-agenda-add-entry-text'."
167 :group
'org-agenda-export
169 :options
'(org-agenda-add-entry-text))
171 (defcustom org-agenda-add-entry-text-maxlines
0
172 "Maximum number of entry text lines to be added to agenda.
173 This is only relevant when `org-agenda-add-entry-text' is part of
174 `org-agenda-before-write-hook', which is the default.
175 When this is 0, nothing will happen. When it is greater than 0, it
176 specifies the maximum number of lines that will be added for each entry
177 that is listed in the agenda view.
179 Note that this variable is not used during display, only when exporting
180 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
181 and `org-agenda-entry-text-maxlines'."
185 (defcustom org-agenda-add-entry-text-descriptive-links t
186 "Non-nil means export org-links as descriptive links in agenda added text.
187 This variable applies to the text added to the agenda when
188 `org-agenda-add-entry-text-maxlines' is larger than 0.
189 When this variable nil, the URL will (also) be shown."
193 (defcustom org-agenda-export-html-style nil
194 "The style specification for exported HTML Agenda files.
195 If this variable contains a string, it will replace the default <style>
196 section as produced by `htmlize'.
197 Since there are different ways of setting style information, this variable
198 needs to contain the full HTML structure to provide a style, including the
199 surrounding HTML tags. The style specifications should include definitions
200 the fonts used by the agenda, here is an example:
202 <style type=\"text/css\">
203 p { font-weight: normal; color: gray; }
204 .org-agenda-structure {
219 .title { text-align: center; }
220 .todo, .deadline { color: red; }
221 .done { color: green; }
224 or, if you want to keep the style in a file,
226 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
228 As the value of this option simply gets inserted into the HTML <head> header,
229 you can \"misuse\" it to also add other text to the header."
230 :group
'org-agenda-export
231 :group
'org-export-html
236 (defcustom org-agenda-persistent-filter nil
237 "When set, keep filters from one agenda view to the next."
241 (defgroup org-agenda-custom-commands nil
242 "Options concerning agenda views in Org-mode."
243 :tag
"Org Agenda Custom Commands"
246 (defconst org-sorting-choice
248 (const time-up
) (const time-down
)
249 (const timestamp-up
) (const timestamp-down
)
250 (const scheduled-up
) (const scheduled-down
)
251 (const deadline-up
) (const deadline-down
)
252 (const ts-up
) (const ts-down
)
253 (const tsia-up
) (const tsia-down
)
254 (const category-keep
) (const category-up
) (const category-down
)
255 (const tag-down
) (const tag-up
)
256 (const priority-up
) (const priority-down
)
257 (const todo-state-up
) (const todo-state-down
)
258 (const effort-up
) (const effort-down
)
259 (const habit-up
) (const habit-down
)
260 (const alpha-up
) (const alpha-down
)
261 (const user-defined-up
) (const user-defined-down
))
264 ;; Keep custom values for `org-agenda-filter-preset' compatible with
265 ;; the new variable `org-agenda-tag-filter-preset'.
266 (org-defvaralias 'org-agenda-filter-preset
'org-agenda-tag-filter-preset
)
267 (org-defvaralias 'org-agenda-filter
'org-agenda-tag-filter
)
269 (defvar org-agenda-entry-types
'(:deadline
:scheduled
:timestamp
:sexp
)
270 "List of types searched for when creating the daily/weekly agenda.
271 This variable is a list of symbols that controls the types of
272 items that appear in the daily/weekly agenda. Allowed symbols in this
275 :timestamp List items containing a date stamp or date range matching
276 the selected date. This includes sexp entries in angular
279 :sexp List entries resulting from plain diary-like sexps.
281 :deadline List deadline due on that date. When the date is today,
282 also list any deadlines past due, or due within
283 `org-deadline-warning-days'. `:deadline' must appear before
284 `:scheduled' if the setting of
285 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
288 :deadline* Same as above, but only include the deadline if it has an
289 hour specification as [h]h:mm.
291 :scheduled List all items which are scheduled for the given date.
292 The diary for *today* also contains items which were
293 scheduled earlier and are not yet marked DONE.
295 :scheduled* Same as above, but only include the scheduled item if it
296 has an hour specification as [h]h:mm.
298 By default, all four non-starred types are turned on.
300 When :scheduled* or :deadline* are included, :schedule or :deadline
303 Never set this variable globally using `setq', because then it
304 will apply to all future agenda commands. Instead, bind it with
305 `let' to scope it dynamically into the agenda-constructing
306 command. A good way to set it is through options in
307 `org-agenda-custom-commands'. For a more flexible (though
308 somewhat less efficient) way of determining what is included in
309 the daily/weekly agenda, see `org-agenda-skip-function'.")
311 (defconst org-agenda-custom-commands-local-options
312 `(repeat :tag
"Local settings for this command. Remember to quote values"
313 (choice :tag
"Setting"
314 (list :tag
"Heading for this block"
315 (const org-agenda-overriding-header
)
316 (string :tag
"Headline"))
317 (list :tag
"Files to be searched"
318 (const org-agenda-files
)
320 (const :format
"" quote
)
322 (list :tag
"Sorting strategy"
323 (const org-agenda-sorting-strategy
)
325 (const :format
"" quote
)
327 ,org-sorting-choice
)))
328 (list :tag
"Prefix format"
329 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
331 (list :tag
"Number of days in agenda"
332 (const org-agenda-span
)
333 (choice (const :tag
"Day" day
)
334 (const :tag
"Week" week
)
335 (const :tag
"Fortnight" fortnight
)
336 (const :tag
"Month" month
)
337 (const :tag
"Year" year
)
338 (integer :tag
"Custom")))
339 (list :tag
"Fixed starting date"
340 (const org-agenda-start-day
)
341 (string :value
"2007-11-01"))
342 (list :tag
"Start on day of week"
343 (const org-agenda-start-on-weekday
)
345 (const :tag
"Today" nil
)
346 (integer :tag
"Weekday No.")))
347 (list :tag
"Include data from diary"
348 (const org-agenda-include-diary
)
350 (list :tag
"Deadline Warning days"
351 (const org-deadline-warning-days
)
353 (list :tag
"Category filter preset"
354 (const org-agenda-category-filter-preset
)
356 (const :format
"" quote
)
358 (string :tag
"+category or -category"))))
359 (list :tag
"Tags filter preset"
360 (const org-agenda-tag-filter-preset
)
362 (const :format
"" quote
)
364 (string :tag
"+tag or -tag"))))
365 (list :tag
"Effort filter preset"
366 (const org-agenda-effort-filter-preset
)
368 (const :format
"" quote
)
370 (string :tag
"+=10 or -=10 or +<10 or ->10"))))
371 (list :tag
"Regexp filter preset"
372 (const org-agenda-regexp-filter-preset
)
374 (const :format
"" quote
)
376 (string :tag
"+regexp or -regexp"))))
377 (list :tag
"Set daily/weekly entry types"
378 (const org-agenda-entry-types
)
380 (const :format
"" quote
)
381 (set :greedy t
:value
,org-agenda-entry-types
388 (list :tag
"Standard skipping condition"
389 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
390 (const org-agenda-skip-function
)
392 (const :format
"" quote
)
395 :tag
"Skipping range"
396 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
397 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
398 (repeat :inline t
:tag
"Conditions for skipping"
400 :tag
"Condition type"
401 (list :tag
"Regexp matches" :inline t
402 (const :format
"" 'regexp
)
404 (list :tag
"Regexp does not match" :inline t
405 (const :format
"" 'notregexp
)
407 (list :tag
"TODO state is" :inline t
410 (const :tag
"Any not-done state" 'todo
)
411 (const :tag
"Any done state" 'done
)
412 (const :tag
"Any state" 'any
)
413 (list :tag
"Keyword list"
414 (const :format
"" quote
)
415 (repeat (string :tag
"Keyword")))))
416 (list :tag
"TODO state is not" :inline t
419 (const :tag
"Any not-done state" 'todo
)
420 (const :tag
"Any done state" 'done
)
421 (const :tag
"Any state" 'any
)
422 (list :tag
"Keyword list"
423 (const :format
"" quote
)
424 (repeat (string :tag
"Keyword")))))
425 (const :tag
"scheduled" 'scheduled
)
426 (const :tag
"not scheduled" 'notscheduled
)
427 (const :tag
"deadline" 'deadline
)
428 (const :tag
"no deadline" 'notdeadline
)
429 (const :tag
"timestamp" 'timestamp
)
430 (const :tag
"no timestamp" 'nottimestamp
))))))
431 (list :tag
"Non-standard skipping condition"
432 :value
(org-agenda-skip-function)
433 (const org-agenda-skip-function
)
434 (sexp :tag
"Function or form (quoted!)"))
435 (list :tag
"Any variable"
436 (variable :tag
"Variable")
437 (sexp :tag
"Value (sexp)"))))
438 "Selection of examples for agenda command settings.
439 This will be spliced into the custom type of
440 `org-agenda-custom-commands'.")
443 (defcustom org-agenda-custom-commands
444 '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
445 "Custom commands for the agenda.
446 These commands will be offered on the splash screen displayed by the
447 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
449 (key desc type match settings files)
451 key The key (one or more characters as a string) to be associated
453 desc A description of the command, when omitted or nil, a default
454 description is built using MATCH.
455 type The command type, any of the following symbols:
456 agenda The daily/weekly agenda.
457 todo Entries with a specific TODO keyword, in all agenda files.
458 search Entries containing search words entry or headline.
459 tags Tags/Property/TODO match in all agenda files.
460 tags-todo Tags/P/T match in all agenda files, TODO entries only.
461 todo-tree Sparse tree of specific TODO keyword in *current* file.
462 tags-tree Sparse tree with all tags matches in *current* file.
463 occur-tree Occur sparse tree for *current* file.
464 ... A user-defined function.
465 match What to search for:
466 - a single keyword for TODO keyword searches
467 - a tags match expression for tags searches
468 - a word search expression for text searches.
469 - a regular expression for occur searches
470 For all other commands, this should be the empty string.
471 settings A list of option settings, similar to that in a let form, so like
472 this: ((opt1 val1) (opt2 val2) ...). The values will be
473 evaluated at the moment of execution, so quote them when needed.
474 files A list of files file to write the produced agenda buffer to
475 with the command `org-store-agenda-views'.
476 If a file name ends in \".html\", an HTML version of the buffer
477 is written out. If it ends in \".ps\", a postscript version is
478 produced. Otherwise, only the plain text is written to the file.
480 You can also define a set of commands, to create a composite agenda buffer.
481 In this case, an entry looks like this:
483 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
487 desc A description string to be displayed in the dispatcher menu.
488 cmd An agenda command, similar to the above. However, tree commands
489 are not allowed, but instead you can get agenda and global todo list.
490 So valid commands for a set are:
491 (agenda \"\" settings)
492 (alltodo \"\" settings)
493 (stuck \"\" settings)
494 (todo \"match\" settings files)
495 (search \"match\" settings files)
496 (tags \"match\" settings files)
497 (tags-todo \"match\" settings files)
499 Each command can carry a list of options, and another set of options can be
500 given for the whole set of commands. Individual command options take
501 precedence over the general options.
503 When using several characters as key to a command, the first characters
504 are prefix commands. For the dispatcher to display useful information, you
505 should provide a description for the prefix, like
507 (setq org-agenda-custom-commands
508 \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
509 (\"hl\" tags \"+HOME+Lisa\")
510 (\"hp\" tags \"+HOME+Peter\")
511 (\"hk\" tags \"+HOME+Kim\")))"
512 :group
'org-agenda-custom-commands
514 (choice :value
("x" "Describe command here" tags
"" nil
)
515 (list :tag
"Single command"
516 (string :tag
"Access Key(s) ")
517 (option (string :tag
"Description"))
519 (const :tag
"Agenda" agenda
)
520 (const :tag
"TODO list" alltodo
)
521 (const :tag
"Search words" search
)
522 (const :tag
"Stuck projects" stuck
)
523 (const :tag
"Tags/Property match (all agenda files)" tags
)
524 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
525 (const :tag
"TODO keyword search (all agenda files)" todo
)
526 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
527 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
528 (const :tag
"Occur tree (current buffer)" occur-tree
)
529 (sexp :tag
"Other, user-defined function"))
530 (string :tag
"Match (only for some commands)")
531 ,org-agenda-custom-commands-local-options
532 (option (repeat :tag
"Export" (file :tag
"Export to"))))
533 (list :tag
"Command series, all agenda files"
534 (string :tag
"Access Key(s)")
535 (string :tag
"Description ")
536 (repeat :tag
"Component"
539 (const :format
"" agenda
)
540 (const :tag
"" :format
"" "")
541 ,org-agenda-custom-commands-local-options
)
542 (list :tag
"TODO list (all keywords)"
543 (const :format
"" alltodo
)
544 (const :tag
"" :format
"" "")
545 ,org-agenda-custom-commands-local-options
)
546 (list :tag
"Search words"
547 (const :format
"" search
)
548 (string :tag
"Match")
549 ,org-agenda-custom-commands-local-options
)
550 (list :tag
"Stuck projects"
551 (const :format
"" stuck
)
552 (const :tag
"" :format
"" "")
553 ,org-agenda-custom-commands-local-options
)
554 (list :tag
"Tags search"
555 (const :format
"" tags
)
556 (string :tag
"Match")
557 ,org-agenda-custom-commands-local-options
)
558 (list :tag
"Tags search, TODO entries only"
559 (const :format
"" tags-todo
)
560 (string :tag
"Match")
561 ,org-agenda-custom-commands-local-options
)
562 (list :tag
"TODO keyword search"
563 (const :format
"" todo
)
564 (string :tag
"Match")
565 ,org-agenda-custom-commands-local-options
)
566 (list :tag
"Other, user-defined function"
567 (symbol :tag
"function")
568 (string :tag
"Match")
569 ,org-agenda-custom-commands-local-options
)))
571 (repeat :tag
"Settings for entire command set"
572 (list (variable :tag
"Any variable")
573 (sexp :tag
"Value")))
574 (option (repeat :tag
"Export" (file :tag
"Export to"))))
575 (cons :tag
"Prefix key documentation"
576 (string :tag
"Access Key(s)")
577 (string :tag
"Description ")))))
579 (defcustom org-agenda-query-register ?o
580 "The register holding the current query string.
581 The purpose of this is that if you construct a query string interactively,
582 you can then use it to define a custom command."
583 :group
'org-agenda-custom-commands
586 (defcustom org-stuck-projects
587 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
588 "How to identify stuck projects.
589 This is a list of four items:
590 1. A tags/todo/property matcher string that is used to identify a project.
591 See the manual for a description of tag and property searches.
592 The entire tree below a headline matched by this is considered one project.
593 2. A list of TODO keywords identifying non-stuck projects.
594 If the project subtree contains any headline with one of these todo
595 keywords, the project is considered to be not stuck. If you specify
596 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
597 3. A list of tags identifying non-stuck projects.
598 If the project subtree contains any headline with one of these tags,
599 the project is considered to be not stuck. If you specify \"*\" as
600 a tag, any tag will mark the project unstuck. Note that this is about
601 the explicit presence of a tag somewhere in the subtree, inherited
602 tags do not count here. If inherited tags make a project not stuck,
603 use \"-TAG\" in the tags part of the matcher under (1.) above.
604 4. An arbitrary regular expression matching non-stuck projects.
606 If the project turns out to be not stuck, search continues also in the
607 subtree to see if any of the subtasks have project status.
609 See also the variable `org-tags-match-list-sublevels' which applies
610 to projects matched by this search as well.
612 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
613 or `C-c a #' to produce the list."
614 :group
'org-agenda-custom-commands
616 (string :tag
"Tags/TODO match to identify a project")
617 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
618 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
619 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
621 (defgroup org-agenda-skip nil
622 "Options concerning skipping parts of agenda files."
623 :tag
"Org Agenda Skip"
626 (defcustom org-agenda-skip-function-global nil
627 "Function to be called at each match during agenda construction.
628 If this function returns nil, the current match should not be skipped.
629 If the function decided to skip an agenda match, is must return the
630 buffer position from which the search should be continued.
631 This may also be a Lisp form, which will be evaluated.
633 This variable will be applied to every agenda match, including
634 tags/property searches and TODO lists. So try to make the test function
635 do its checking as efficiently as possible. To implement a skipping
636 condition just for specific agenda commands, use the variable
637 `org-agenda-skip-function' which can be set in the options section
638 of custom agenda commands."
639 :group
'org-agenda-skip
642 (defgroup org-agenda-daily
/weekly nil
643 "Options concerning the daily/weekly agenda."
644 :tag
"Org Agenda Daily/Weekly"
646 (defgroup org-agenda-todo-list nil
647 "Options concerning the global todo list agenda view."
648 :tag
"Org Agenda Todo List"
650 (defgroup org-agenda-match-view nil
651 "Options concerning the general tags/property/todo match agenda view."
652 :tag
"Org Agenda Match View"
654 (defgroup org-agenda-search-view nil
655 "Options concerning the search agenda view."
656 :tag
"Org Agenda Search View"
659 (defvar org-agenda-archives-mode nil
660 "Non-nil means the agenda will include archived items.
661 If this is the symbol `trees', trees in the selected agenda scope
662 that are marked with the ARCHIVE tag will be included anyway. When this is
663 t, also all archive files associated with the current selection of agenda
664 files will be included.")
666 (defcustom org-agenda-restriction-lock-highlight-subtree t
667 "Non-nil means highlight the whole subtree when restriction is active.
668 Otherwise only highlight the headline. Highlighting the whole subtree is
669 useful to ensure no edits happen beyond the restricted region."
673 (defcustom org-agenda-skip-comment-trees t
674 "Non-nil means skip trees that start with the COMMENT keyword.
675 When nil, these trees are also scanned by agenda commands."
676 :group
'org-agenda-skip
679 (defcustom org-agenda-todo-list-sublevels t
680 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
681 When nil, the sublevels of a TODO entry are not checked, resulting in
682 potentially much shorter TODO lists."
683 :group
'org-agenda-skip
684 :group
'org-agenda-todo-list
687 (defcustom org-agenda-todo-ignore-with-date nil
688 "Non-nil means don't show entries with a date in the global todo list.
689 You can use this if you prefer to mark mere appointments with a TODO keyword,
690 but don't want them to show up in the TODO list.
691 When this is set, it also covers deadlines and scheduled items, the settings
692 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
694 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
695 :group
'org-agenda-skip
696 :group
'org-agenda-todo-list
699 (defcustom org-agenda-todo-ignore-timestamp nil
700 "Non-nil means don't show entries with a timestamp.
701 This applies when creating the global todo list.
704 past Don't show entries for today or in the past.
706 future Don't show entries with a timestamp in the future.
707 The idea behind this is that if it has a future
708 timestamp, you don't want to think about it until the
711 all Don't show any entries with a timestamp in the global todo list.
712 The idea behind this is that by setting a timestamp, you
713 have already \"taken care\" of this item.
715 This variable can also have an integer as a value. If positive (N),
716 todos with a timestamp N or more days in the future will be ignored. If
717 negative (-N), todos with a timestamp N or more days in the past will be
718 ignored. If 0, todos with a timestamp either today or in the future will
719 be ignored. For example, a value of -1 will exclude todos with a
720 timestamp in the past (yesterday or earlier), while a value of 7 will
721 exclude todos with a timestamp a week or more in the future.
723 See also `org-agenda-todo-ignore-with-date'.
724 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
725 to make his option also apply to the tags-todo list."
726 :group
'org-agenda-skip
727 :group
'org-agenda-todo-list
730 (const :tag
"Ignore future timestamp todos" future
)
731 (const :tag
"Ignore past or present timestamp todos" past
)
732 (const :tag
"Ignore all timestamp todos" all
)
733 (const :tag
"Show timestamp todos" nil
)
734 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
736 (defcustom org-agenda-todo-ignore-scheduled nil
737 "Non-nil means, ignore some scheduled TODO items when making TODO list.
738 This applies when creating the global todo list.
741 past Don't show entries scheduled today or in the past.
743 future Don't show entries scheduled in the future.
744 The idea behind this is that by scheduling it, you don't want to
745 think about it until the scheduled date.
747 all Don't show any scheduled entries in the global todo list.
748 The idea behind this is that by scheduling it, you have already
749 \"taken care\" of this item.
751 t Same as `all', for backward compatibility.
753 This variable can also have an integer as a value. See
754 `org-agenda-todo-ignore-timestamp' for more details.
756 See also `org-agenda-todo-ignore-with-date'.
757 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
758 to make his option also apply to the tags-todo list."
759 :group
'org-agenda-skip
760 :group
'org-agenda-todo-list
762 (const :tag
"Ignore future-scheduled todos" future
)
763 (const :tag
"Ignore past- or present-scheduled todos" past
)
764 (const :tag
"Ignore all scheduled todos" all
)
765 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
766 (const :tag
"Show scheduled todos" nil
)
767 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
769 (defcustom org-agenda-todo-ignore-deadlines nil
770 "Non-nil means ignore some deadline TODO items when making TODO list.
771 There are different motivations for using different values, please think
772 carefully when configuring this variable.
774 This applies when creating the global todo list.
777 near Don't show near deadline entries. A deadline is near when it is
778 closer than `org-deadline-warning-days' days. The idea behind this
779 is that such items will appear in the agenda anyway.
781 far Don't show TODO entries where a deadline has been defined, but
782 the deadline is not near. This is useful if you don't want to
783 use the todo list to figure out what to do now.
785 past Don't show entries with a deadline timestamp for today or in the past.
787 future Don't show entries with a deadline timestamp in the future, not even
788 when they become `near' ones. Use it with caution.
790 all Ignore all TODO entries that do have a deadline.
792 t Same as `near', for backward compatibility.
794 This variable can also have an integer as a value. See
795 `org-agenda-todo-ignore-timestamp' for more details.
797 See also `org-agenda-todo-ignore-with-date'.
798 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
799 to make his option also apply to the tags-todo list."
800 :group
'org-agenda-skip
801 :group
'org-agenda-todo-list
803 (const :tag
"Ignore near deadlines" near
)
804 (const :tag
"Ignore near deadlines (compatibility)" t
)
805 (const :tag
"Ignore far deadlines" far
)
806 (const :tag
"Ignore all TODOs with a deadlines" all
)
807 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
808 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
810 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
811 "Time unit to use when possibly ignoring an agenda item.
813 See the docstring of various `org-agenda-todo-ignore-*' options.
814 The default is to compare time stamps using days. An item is thus
815 considered to be in the future if it is at least one day after today.
816 Non-nil means to compare time stamps using seconds. An item is then
817 considered future if it has a time value later than current time."
818 :group
'org-agenda-skip
819 :group
'org-agenda-todo-list
821 :package-version
'(Org .
"8.0")
823 (const :tag
"Compare time with days" nil
)
824 (const :tag
"Compare time with seconds" t
)))
826 (defcustom org-agenda-tags-todo-honor-ignore-options nil
827 "Non-nil means honor todo-list ignores options also in tags-todo search.
829 `org-agenda-todo-ignore-with-date',
830 `org-agenda-todo-ignore-timestamp',
831 `org-agenda-todo-ignore-scheduled',
832 `org-agenda-todo-ignore-deadlines'
833 make the global TODO list skip entries that have time stamps of certain
834 kinds. If this option is set, the same options will also apply for the
835 tags-todo search, which is the general tags/property matcher
836 restricted to unfinished TODO entries only."
837 :group
'org-agenda-skip
838 :group
'org-agenda-todo-list
839 :group
'org-agenda-match-view
842 (defcustom org-agenda-skip-scheduled-if-done nil
843 "Non-nil means don't show scheduled items in agenda when they are done.
844 This is relevant for the daily/weekly agenda, not for the TODO list. And
845 it applies only to the actual date of the scheduling. Warnings about
846 an item with a past scheduling dates are always turned off when the item
848 :group
'org-agenda-skip
849 :group
'org-agenda-daily
/weekly
852 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
853 "Non-nil means skip scheduling line if same entry shows because of deadline.
855 In the agenda of today, an entry can show up multiple times
856 because it is both scheduled and has a nearby deadline, and maybe
857 a plain time stamp as well.
859 When this variable is nil, the entry will be shown several times.
861 When set to t, then only the deadline is shown and the fact that
862 the entry is scheduled today or was scheduled previously is not
865 When set to the symbol `not-today', skip scheduled previously,
866 but not scheduled today.
868 When set to the symbol `repeated-after-deadline', skip scheduled
869 items if they are repeated beyond the current deadline."
870 :group
'org-agenda-skip
871 :group
'org-agenda-daily
/weekly
873 (const :tag
"Never" nil
)
874 (const :tag
"Always" t
)
875 (const :tag
"Not when scheduled today" not-today
)
876 (const :tag
"When repeated past deadline" repeated-after-deadline
)))
878 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
879 "Non-nil means skip timestamp line if same entry shows because of deadline.
880 In the agenda of today, an entry can show up multiple times
881 because it has both a plain timestamp and has a nearby deadline.
882 When this variable is t, then only the deadline is shown and the
883 fact that the entry has a timestamp for or including today is not
884 shown. When this variable is nil, the entry will be shown
886 :group
'org-agenda-skip
887 :group
'org-agenda-daily
/weekly
890 (const :tag
"Never" nil
)
891 (const :tag
"Always" t
)))
893 (defcustom org-agenda-skip-deadline-if-done nil
894 "Non-nil means don't show deadlines when the corresponding item is done.
895 When nil, the deadline is still shown and should give you a happy feeling.
896 This is relevant for the daily/weekly agenda. And it applied only to the
897 actually date of the deadline. Warnings about approaching and past-due
898 deadlines are always turned off when the item is DONE."
899 :group
'org-agenda-skip
900 :group
'org-agenda-daily
/weekly
903 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
904 "Non-nil means skip deadline prewarning when entry is also scheduled.
905 This will apply on all days where a prewarning for the deadline would
906 be shown, but not at the day when the entry is actually due. On that day,
907 the deadline will be shown anyway.
908 This variable may be set to nil, t, the symbol `pre-scheduled',
909 or a number which will then give the number of days before the actual
910 deadline when the prewarnings should resume. The symbol `pre-scheduled'
911 eliminates the deadline prewarning only prior to the scheduled date.
912 This can be used in a workflow where the first showing of the deadline will
913 trigger you to schedule it, and then you don't want to be reminded of it
914 because you will take care of it on the day when scheduled."
915 :group
'org-agenda-skip
916 :group
'org-agenda-daily
/weekly
919 (const :tag
"Always show prewarning" nil
)
920 (const :tag
"Remove prewarning prior to scheduled date" pre-scheduled
)
921 (const :tag
"Remove prewarning if entry is scheduled" t
)
922 (integer :tag
"Restart prewarning N days before deadline")))
924 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
925 "Non-nil means skip scheduled delay when entry also has a deadline.
926 This variable may be set to nil, t, the symbol `post-deadline',
927 or a number which will then give the number of days after the actual
928 scheduled date when the delay should expire. The symbol `post-deadline'
929 eliminates the schedule delay when the date is posterior to the deadline."
930 :group
'org-agenda-skip
931 :group
'org-agenda-daily
/weekly
933 :package-version
'(Org .
"8.0")
935 (const :tag
"Always honor delay" nil
)
936 (const :tag
"Ignore delay if posterior to the deadline" post-deadline
)
937 (const :tag
"Ignore delay if entry has a deadline" t
)
938 (integer :tag
"Honor delay up until N days after the scheduled date")))
940 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
941 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
942 When non-nil, after the search for timestamps has matched once in an
943 entry, the rest of the entry will not be searched."
944 :group
'org-agenda-skip
947 (defcustom org-agenda-skip-timestamp-if-done nil
948 "Non-nil means don't select item by timestamp or -range if it is DONE."
949 :group
'org-agenda-skip
950 :group
'org-agenda-daily
/weekly
953 (defcustom org-agenda-dim-blocked-tasks t
954 "Non-nil means dim blocked tasks in the agenda display.
955 This causes some overhead during agenda construction, but if you
956 have turned on `org-enforce-todo-dependencies',
957 `org-enforce-todo-checkbox-dependencies', or any other blocking
958 mechanism, this will create useful feedback in the agenda.
960 Instead of t, this variable can also have the value `invisible'.
961 Then blocked tasks will be invisible and only become visible when
962 they become unblocked. An exemption to this behavior is when a task is
963 blocked because of unchecked checkboxes below it. Since checkboxes do
964 not show up in the agenda views, making this task invisible you remove any
965 trace from agenda views that there is something to do. Therefore, a task
966 that is blocked because of checkboxes will never be made invisible, it
967 will only be dimmed."
968 :group
'org-agenda-daily
/weekly
969 :group
'org-agenda-todo-list
972 (const :tag
"Do not dim" nil
)
973 (const :tag
"Dim to a gray face" t
)
974 (const :tag
"Make invisible" invisible
)))
976 (defcustom org-timeline-show-empty-dates
3
977 "Non-nil means `org-timeline' also shows dates without an entry.
978 When nil, only the days which actually have entries are shown.
979 When t, all days between the first and the last date are shown.
980 When an integer, show also empty dates, but if there is a gap of more than
981 N days, just insert a special line indicating the size of the gap."
982 :group
'org-agenda-skip
984 (const :tag
"None" nil
)
986 (integer :tag
"at most")))
988 (defgroup org-agenda-startup nil
989 "Options concerning initial settings in the Agenda in Org Mode."
990 :tag
"Org Agenda Startup"
993 (defcustom org-agenda-menu-show-matcher t
994 "Non-nil means show the match string in the agenda dispatcher menu.
995 When nil, the matcher string is not shown, but is put into the help-echo
996 property so than moving the mouse over the command shows it.
997 Setting it to nil is good if matcher strings are very long and/or if
998 you want to use two-columns display (see `org-agenda-menu-two-columns')."
1003 (define-obsolete-variable-alias 'org-agenda-menu-two-column
'org-agenda-menu-two-columns
"24.3")
1005 (defcustom org-agenda-menu-two-columns nil
1006 "Non-nil means, use two columns to show custom commands in the dispatcher.
1007 If you use this, you probably want to set `org-agenda-menu-show-matcher'
1013 (define-obsolete-variable-alias 'org-finalize-agenda-hook
'org-agenda-finalize-hook
"24.3")
1014 (defcustom org-agenda-finalize-hook nil
1015 "Hook run just before displaying an agenda buffer.
1016 The buffer is still writable when the hook is called.
1018 You can modify some of the buffer substrings but you should be
1019 extra careful not to modify the text properties of the agenda
1020 headlines as the agenda display heavily relies on them."
1021 :group
'org-agenda-startup
1024 (defcustom org-agenda-mouse-1-follows-link nil
1025 "Non-nil means mouse-1 on a link will follow the link in the agenda.
1026 A longer mouse click will still set point. Does not work on XEmacs.
1027 Needs to be set before org.el is loaded."
1028 :group
'org-agenda-startup
1031 (defcustom org-agenda-start-with-follow-mode nil
1032 "The initial value of follow mode in a newly created agenda window."
1033 :group
'org-agenda-startup
1036 (defcustom org-agenda-follow-indirect nil
1037 "Non-nil means `org-agenda-follow-mode' displays only the
1038 current item's tree, in an indirect buffer."
1043 (defcustom org-agenda-show-outline-path t
1044 "Non-nil means show outline path in echo area after line motion."
1045 :group
'org-agenda-startup
1048 (defcustom org-agenda-start-with-entry-text-mode nil
1049 "The initial value of entry-text-mode in a newly created agenda window."
1050 :group
'org-agenda-startup
1053 (defcustom org-agenda-entry-text-maxlines
5
1054 "Number of text lines to be added when `E' is pressed in the agenda.
1056 Note that this variable only used during agenda display. Add add entry text
1057 when exporting the agenda, configure the variable
1058 `org-agenda-add-entry-ext-maxlines'."
1062 (defcustom org-agenda-entry-text-exclude-regexps nil
1063 "List of regular expressions to clean up entry text.
1064 The complete matches of all regular expressions in this list will be
1065 removed from entry text before it is shown in the agenda."
1067 :type
'(repeat (regexp)))
1069 (defcustom org-agenda-entry-text-leaders
" > "
1070 "Text prepended to the entry text in agenda buffers."
1072 :package-version
'(Org .
"8.0")
1076 (defvar org-agenda-entry-text-cleanup-hook nil
1077 "Hook that is run after basic cleanup of entry text to be shown in agenda.
1078 This cleanup is done in a temporary buffer, so the function may inspect and
1079 change the entire buffer.
1080 Some default stuff like drawers and scheduling/deadline dates will already
1081 have been removed when this is called, as will any matches for regular
1082 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
1084 (defvar org-agenda-include-inactive-timestamps nil
1085 "Non-nil means include inactive time stamps in agenda and timeline.
1086 Dynamically scoped.")
1088 (defgroup org-agenda-windows nil
1089 "Options concerning the windows used by the Agenda in Org Mode."
1090 :tag
"Org Agenda Windows"
1093 (defcustom org-agenda-window-setup
'reorganize-frame
1094 "How the agenda buffer should be displayed.
1095 Possible values for this option are:
1097 current-window Show agenda in the current window, keeping all other windows.
1098 other-window Use `switch-to-buffer-other-window' to display agenda.
1099 only-window Show agenda, deleting all other windows.
1100 reorganize-frame Show only two windows on the current frame, the current
1101 window and the agenda.
1102 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1103 Also, when exiting the agenda, kill that frame.
1104 See also the variable `org-agenda-restore-windows-after-quit'."
1105 :group
'org-agenda-windows
1107 (const current-window
)
1109 (const other-window
)
1111 (const reorganize-frame
)))
1113 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
1114 "The min and max height of the agenda window as a fraction of frame height.
1115 The value of the variable is a cons cell with two numbers between 0 and 1.
1116 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1117 :group
'org-agenda-windows
1118 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
1120 (defcustom org-agenda-restore-windows-after-quit nil
1121 "Non-nil means restore window configuration upon exiting agenda.
1122 Before the window configuration is changed for displaying the agenda,
1123 the current status is recorded. When the agenda is exited with
1124 `q' or `x' and this option is set, the old state is restored. If
1125 `org-agenda-window-setup' is `other-frame', the value of this
1126 option will be ignored."
1127 :group
'org-agenda-windows
1130 (defcustom org-agenda-ndays nil
1131 "Number of days to include in overview display.
1133 Obsolete, see `org-agenda-span'."
1134 :group
'org-agenda-daily
/weekly
1135 :type
'(choice (const nil
)
1138 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
1140 (defcustom org-agenda-span
'week
1141 "Number of days to include in overview display.
1142 Can be day, week, month, year, or any number of days.
1143 Custom commands can set this variable in the options section."
1144 :group
'org-agenda-daily
/weekly
1145 :type
'(choice (const :tag
"Day" day
)
1146 (const :tag
"Week" week
)
1147 (const :tag
"Fortnight" fortnight
)
1148 (const :tag
"Month" month
)
1149 (const :tag
"Year" year
)
1150 (integer :tag
"Custom")))
1152 (defcustom org-agenda-start-on-weekday
1
1153 "Non-nil means start the overview always on the specified weekday.
1154 0 denotes Sunday, 1 denotes Monday, etc.
1155 When nil, always start on the current day.
1156 Custom commands can set this variable in the options section."
1157 :group
'org-agenda-daily
/weekly
1158 :type
'(choice (const :tag
"Today" nil
)
1159 (integer :tag
"Weekday No.")))
1161 (defcustom org-agenda-show-all-dates t
1162 "Non-nil means `org-agenda' shows every day in the selected range.
1163 When nil, only the days which actually have entries are shown."
1164 :group
'org-agenda-daily
/weekly
1167 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1168 "Format string for displaying dates in the agenda.
1169 Used by the daily/weekly agenda and by the timeline. This should be
1170 a format string understood by `format-time-string', or a function returning
1171 the formatted date as a string. The function must take a single argument,
1172 a calendar-style date list like (month day year)."
1173 :group
'org-agenda-daily
/weekly
1175 (string :tag
"Format string")
1176 (function :tag
"Function")))
1178 (defun org-agenda-format-date-aligned (date)
1179 "Format a DATE string for display in the daily/weekly agenda, or timeline.
1180 This function makes sure that dates are aligned for easy reading."
1182 (let* ((dayname (calendar-day-name date
))
1184 (day-of-week (calendar-day-of-week date
))
1186 (monthname (calendar-month-name month
))
1188 (iso-week (org-days-to-iso-week
1189 (calendar-absolute-from-gregorian date
)))
1190 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1192 ((and (= month
12) (<= iso-week
1))
1195 (weekstring (if (= day-of-week
1)
1196 (format " W%02d" iso-week
)
1198 (format "%-10s %2d %s %4d%s"
1199 dayname day monthname year weekstring
)))
1201 (defcustom org-agenda-time-leading-zero nil
1202 "Non-nil means use leading zero for military times in agenda.
1203 For example, 9:30am would become 09:30 rather than 9:30."
1204 :group
'org-agenda-daily
/weekly
1208 (defcustom org-agenda-timegrid-use-ampm nil
1209 "When set, show AM/PM style timestamps on the timegrid."
1214 (defun org-agenda-time-of-day-to-ampm (time)
1215 "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
1216 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1217 (minute (substring time -
2))
1220 ((equal hour-number
12)
1224 (setq hour-number
(- hour-number
12))))
1226 (if org-agenda-time-leading-zero
1227 (format "%02d" hour-number
)
1228 (format "%02s" (number-to-string hour-number
)))
1231 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1232 "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
1233 (if org-agenda-timegrid-use-ampm
1234 (org-agenda-time-of-day-to-ampm time
)
1237 (defcustom org-agenda-weekend-days
'(6 0)
1238 "Which days are weekend?
1239 These days get the special face `org-agenda-date-weekend' in the agenda
1240 and timeline buffers."
1241 :group
'org-agenda-daily
/weekly
1242 :type
'(set :greedy t
1243 (const :tag
"Monday" 1)
1244 (const :tag
"Tuesday" 2)
1245 (const :tag
"Wednesday" 3)
1246 (const :tag
"Thursday" 4)
1247 (const :tag
"Friday" 5)
1248 (const :tag
"Saturday" 6)
1249 (const :tag
"Sunday" 0)))
1251 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1252 "Non-nil means jump to today when moving a past date forward in time.
1253 When using S-right in the agenda to move a a date forward, and the date
1254 stamp currently points to the past, the first key press will move it
1255 to today. WHen nil, just move one day forward even if the date stays
1257 :group
'org-agenda-daily
/weekly
1261 (defcustom org-agenda-include-diary nil
1262 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1263 Custom commands can set this variable in the options section."
1264 :group
'org-agenda-daily
/weekly
1267 (defcustom org-agenda-include-deadlines t
1268 "If non-nil, include entries within their deadline warning period.
1269 Custom commands can set this variable in the options section."
1270 :group
'org-agenda-daily
/weekly
1274 (defcustom org-agenda-repeating-timestamp-show-all t
1275 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1276 When set to a list of strings, only show occurrences of repeating
1277 stamps for these TODO keywords. When nil, only one occurrence is
1278 shown, either today or the nearest into the future."
1279 :group
'org-agenda-daily
/weekly
1281 (const :tag
"Show repeating stamps" t
)
1282 (repeat :tag
"Show repeating stamps for these TODO keywords"
1283 (string :tag
"TODO Keyword"))
1284 (const :tag
"Don't show repeating stamps" nil
)))
1286 (defcustom org-scheduled-past-days
10000
1287 "Number of days to continue listing scheduled items not marked DONE.
1288 When an item is scheduled on a date, it shows up in the agenda on
1289 this day and will be listed until it is marked done or for the
1290 number of days given here."
1291 :group
'org-agenda-daily
/weekly
1294 (defcustom org-agenda-log-mode-items
'(closed clock
)
1295 "List of items that should be shown in agenda log mode.
1296 \\<org-agenda-mode-map>\
1297 This list may contain the following symbols:
1299 closed Show entries that have been closed on that day.
1300 clock Show entries that have received clocked time on that day.
1301 state Show all logged state changes.
1302 Note that instead of changing this variable, you can also press \
1303 `\\[universal-argument] \\[org-agenda-log-mode]' in
1304 the agenda to display all available LOG items temporarily."
1305 :group
'org-agenda-daily
/weekly
1306 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1308 (defcustom org-agenda-clock-consistency-checks
1309 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1310 :gap-ok-around
("4:00")
1311 :default-face
((:background
"DarkRed") (:foreground
"white"))
1312 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1313 :long-face nil
:short-face nil
)
1314 "This is a property list, with the following keys:
1316 :max-duration Mark clocking chunks that are longer than this time.
1317 This is a time string like \"HH:MM\", or the number
1318 of minutes as an integer.
1320 :min-duration Mark clocking chunks that are shorter that this.
1321 This is a time string like \"HH:MM\", or the number
1322 of minutes as an integer.
1324 :max-gap Mark gaps between clocking chunks that are longer than
1325 this duration. A number of minutes, or a string
1328 :gap-ok-around List of times during the day which are usually not working
1329 times. When a gap is detected, but the gap contains any
1330 of these times, the gap is *not* reported. For example,
1331 if this is (\"4:00\" \"13:00\") then gaps that contain
1332 4:00 in the morning (i.e. the night) and 13:00
1333 (i.e. a typical lunch time) do not cause a warning.
1334 You should have at least one time during the night in this
1335 list, or otherwise the first task each morning will trigger
1336 a warning because it follows a long gap.
1338 Furthermore, the following properties can be used to define faces for
1341 :default-face the default face, if the specific face is undefined
1342 :overlap-face face for overlapping clocks
1343 :gap-face face for gaps between clocks
1344 :no-end-time-face face for incomplete clocks
1345 :long-face face for clock intervals that are too long
1346 :short-face face for clock intervals that are too short"
1347 :group
'org-agenda-daily
/weekly
1352 (defcustom org-agenda-log-mode-add-notes t
1353 "Non-nil means add first line of notes to log entries in agenda views.
1354 If a log item like a state change or a clock entry is associated with
1355 notes, the first line of these notes will be added to the entry in the
1357 :group
'org-agenda-daily
/weekly
1360 (defcustom org-agenda-start-with-log-mode nil
1361 "The initial value of log-mode in a newly created agenda window.
1362 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1363 explanations on the possible values."
1364 :group
'org-agenda-startup
1365 :group
'org-agenda-daily
/weekly
1366 :type
'(choice (const :tag
"Don't show log items" nil
)
1367 (const :tag
"Show only log items" only
)
1368 (const :tag
"Show all possible log items" clockcheck
)
1369 (repeat :tag
"Choose among possible values for `org-agenda-log-mode-items'"
1370 (choice (const :tag
"Show closed log items" closed
)
1371 (const :tag
"Show clocked log items" clock
)
1372 (const :tag
"Show all logged state changes" state
)))))
1374 (defcustom org-agenda-start-with-clockreport-mode nil
1375 "The initial value of clockreport-mode in a newly created agenda window."
1376 :group
'org-agenda-startup
1377 :group
'org-agenda-daily
/weekly
1380 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1381 "Property list with parameters for the clocktable in clockreport mode.
1382 This is the display mode that shows a clock table in the daily/weekly
1383 agenda, the properties for this dynamic block can be set here.
1384 The usual clocktable parameters are allowed here, but you cannot set
1385 the properties :name, :tstart, :tend, :block, and :scope - these will
1386 be overwritten to make sure the content accurately reflects the
1387 current display in the agenda."
1388 :group
'org-agenda-daily
/weekly
1391 (defcustom org-agenda-search-view-always-boolean nil
1392 "Non-nil means the search string is interpreted as individual parts.
1394 The search string for search view can either be interpreted as a phrase,
1395 or as a list of snippets that define a boolean search for a number of
1398 When this is non-nil, the string will be split on whitespace, and each
1399 snippet will be searched individually, and all must match in order to
1400 select an entry. A snippet is then a single string of non-white
1401 characters, or a string in double quotes, or a regexp in {} braces.
1402 If a snippet is preceded by \"-\", the snippet must *not* match.
1403 \"+\" is syntactic sugar for positive selection. Each snippet may
1404 be found as a full word or a partial word, but see the variable
1405 `org-agenda-search-view-force-full-words'.
1407 When this is nil, search will look for the entire search phrase as one,
1408 with each space character matching any amount of whitespace, including
1411 Even when this is nil, you can still switch to Boolean search dynamically
1412 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1413 is a regexp marked with braces like \"{abc}\", this will also switch to
1415 :group
'org-agenda-search-view
1419 (org-defvaralias 'org-agenda-search-view-search-words-only
1420 'org-agenda-search-view-always-boolean
)
1422 (defcustom org-agenda-search-view-force-full-words nil
1423 "Non-nil means, search words must be matches as complete words.
1424 When nil, they may also match part of a word."
1425 :group
'org-agenda-search-view
1429 (defcustom org-agenda-search-view-max-outline-level
0
1430 "Maximum outline level to display in search view.
1431 E.g. when this is set to 1, the search view will only
1432 show headlines of level 1. When set to 0, the default
1433 value, don't limit agenda view by outline level."
1434 :group
'org-agenda-search-view
1436 :package-version
'(Org .
"8.3")
1439 (defgroup org-agenda-time-grid nil
1440 "Options concerning the time grid in the Org-mode Agenda."
1441 :tag
"Org Agenda Time Grid"
1444 (defcustom org-agenda-search-headline-for-time t
1445 "Non-nil means search headline for a time-of-day.
1446 If the headline contains a time-of-day in one format or another, it will
1447 be used to sort the entry into the time sequence of items for a day.
1448 Some people have time stamps in the headline that refer to the creation
1449 time or so, and then this produces an unwanted side effect. If this is
1450 the case for your, use this variable to turn off searching the headline
1452 :group
'org-agenda-time-grid
1455 (defcustom org-agenda-use-time-grid t
1456 "Non-nil means show a time grid in the agenda schedule.
1457 A time grid is a set of lines for specific times (like every two hours between
1458 8:00 and 20:00). The items scheduled for a day at specific times are
1459 sorted in between these lines.
1460 For details about when the grid will be shown, and what it will look like, see
1461 the variable `org-agenda-time-grid'."
1462 :group
'org-agenda-time-grid
1465 (defcustom org-agenda-time-grid
1466 '((daily today require-timed
)
1468 (800 1000 1200 1400 1600 1800 2000))
1470 "The settings for time grid for agenda display.
1471 This is a list of three items. The first item is again a list. It contains
1472 symbols specifying conditions when the grid should be displayed:
1474 daily if the agenda shows a single day
1475 weekly if the agenda shows an entire week
1476 today show grid on current date, independent of daily/weekly display
1477 require-timed show grid only if at least one item has a time specification
1478 remove-match skip grid times already present in an entry
1480 The second item is a string which will be placed behind the grid time.
1482 The third item is a list of integers, indicating the times that should have
1484 :group
'org-agenda-time-grid
1487 (set :greedy t
:tag
"Grid Display Options"
1488 (const :tag
"Show grid in single day agenda display" daily
)
1489 (const :tag
"Show grid in weekly agenda display" weekly
)
1490 (const :tag
"Always show grid for today" today
)
1491 (const :tag
"Show grid only if any timed entries are present"
1493 (const :tag
"Skip grid times already present in an entry"
1495 (string :tag
"Grid String")
1496 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1498 (defcustom org-agenda-show-current-time-in-grid t
1499 "Non-nil means show the current time in the time grid."
1500 :group
'org-agenda-time-grid
1504 (defcustom org-agenda-current-time-string
1505 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1506 "The string for the current time marker in the agenda."
1507 :group
'org-agenda-time-grid
1511 (defgroup org-agenda-sorting nil
1512 "Options concerning sorting in the Org-mode Agenda."
1513 :tag
"Org Agenda Sorting"
1516 (defcustom org-agenda-sorting-strategy
1517 '((agenda habit-down time-up priority-down category-keep
)
1518 (todo priority-down category-keep
)
1519 (tags priority-down category-keep
)
1520 (search category-keep
))
1521 "Sorting structure for the agenda items of a single day.
1522 This is a list of symbols which will be used in sequence to determine
1523 if an entry should be listed before another entry. The following
1524 symbols are recognized:
1526 time-up Put entries with time-of-day indications first, early first
1527 time-down Put entries with time-of-day indications first, late first
1528 timestamp-up Sort by any timestamp, early first
1529 timestamp-down Sort by any timestamp, late first
1530 scheduled-up Sort by scheduled timestamp, early first
1531 scheduled-down Sort by scheduled timestamp, late first
1532 deadline-up Sort by deadline timestamp, early first
1533 deadline-down Sort by deadline timestamp, late first
1534 ts-up Sort by active timestamp, early first
1535 ts-down Sort by active timestamp, late first
1536 tsia-up Sort by inactive timestamp, early first
1537 tsia-down Sort by inactive timestamp, late first
1538 category-keep Keep the default order of categories, corresponding to the
1539 sequence in `org-agenda-files'.
1540 category-up Sort alphabetically by category, A-Z.
1541 category-down Sort alphabetically by category, Z-A.
1542 tag-up Sort alphabetically by last tag, A-Z.
1543 tag-down Sort alphabetically by last tag, Z-A.
1544 priority-up Sort numerically by priority, high priority last.
1545 priority-down Sort numerically by priority, high priority first.
1546 todo-state-up Sort by todo state, tasks that are done last.
1547 todo-state-down Sort by todo state, tasks that are done first.
1548 effort-up Sort numerically by estimated effort, high effort last.
1549 effort-down Sort numerically by estimated effort, high effort first.
1550 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1551 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1552 habit-up Put entries that are habits first
1553 habit-down Put entries that are habits last
1554 alpha-up Sort headlines alphabetically
1555 alpha-down Sort headlines alphabetically, reversed
1557 The different possibilities will be tried in sequence, and testing stops
1558 if one comparison returns a \"not-equal\". For example, the default
1559 '(time-up category-keep priority-down)
1560 means: Pull out all entries having a specified time of day and sort them,
1561 in order to make a time schedule for the current day the first thing in the
1562 agenda listing for the day. Of the entries without a time indication, keep
1563 the grouped in categories, don't sort the categories, but keep them in
1564 the sequence given in `org-agenda-files'. Within each category sort by
1567 Leaving out `category-keep' would mean that items will be sorted across
1568 categories by priority.
1570 Instead of a single list, this can also be a set of list for specific
1571 contents, with a context symbol in the car of the list, any of
1572 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1574 Custom commands can bind this variable in the options section."
1575 :group
'org-agenda-sorting
1577 (repeat :tag
"General" ,org-sorting-choice
)
1578 (list :tag
"Individually"
1579 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1580 (repeat ,org-sorting-choice
))
1581 (cons (const :tag
"Strategy for TODO lists" todo
)
1582 (repeat ,org-sorting-choice
))
1583 (cons (const :tag
"Strategy for Tags matches" tags
)
1584 (repeat ,org-sorting-choice
))
1585 (cons (const :tag
"Strategy for search matches" search
)
1586 (repeat ,org-sorting-choice
)))))
1588 (defcustom org-agenda-cmp-user-defined nil
1589 "A function to define the comparison `user-defined'.
1590 This function must receive two arguments, agenda entry a and b.
1591 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1592 the user comparison, return nil.
1593 When this is defined, you can make `user-defined-up' and `user-defined-down'
1594 part of an agenda sorting strategy."
1595 :group
'org-agenda-sorting
1598 (defcustom org-sort-agenda-notime-is-late t
1599 "Non-nil means items without time are considered late.
1600 This is only relevant for sorting. When t, items which have no explicit
1601 time like 15:30 will be considered as 99:01, i.e. later than any items which
1602 do have a time. When nil, the default time is before 0:00. You can use this
1603 option to decide if the schedule for today should come before or after timeless
1605 :group
'org-agenda-sorting
1608 (defcustom org-sort-agenda-noeffort-is-high t
1609 "Non-nil means items without effort estimate are sorted as high effort.
1610 This also applies when filtering an agenda view with respect to the
1611 < or > effort operator. Then, tasks with no effort defined will be treated
1612 as tasks with high effort.
1613 When nil, such items are sorted as 0 minutes effort."
1614 :group
'org-agenda-sorting
1617 (defgroup org-agenda-line-format nil
1618 "Options concerning the entry prefix in the Org-mode agenda display."
1619 :tag
"Org Agenda Line Format"
1622 (defcustom org-agenda-prefix-format
1623 '((agenda .
" %i %-12:c%?-12t% s")
1625 (todo .
" %i %-12:c")
1626 (tags .
" %i %-12:c")
1627 (search .
" %i %-12:c"))
1628 "Format specifications for the prefix of items in the agenda views.
1629 An alist with five entries, each for the different agenda types. The
1630 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1631 The values are format strings.
1633 This format works similar to a printf format, with the following meaning:
1635 %c the category of the item, \"Diary\" for entries from the diary,
1636 or as given by the CATEGORY keyword or derived from the file name
1637 %e the effort required by the item
1638 %l the level of the item (insert X space(s) if item is of level X)
1639 %i the icon category of the item, see `org-agenda-category-icon-alist'
1640 %T the last tag of the item (ignore inherited tags, which come first)
1641 %t the HH:MM time-of-day specification if one applies to the entry
1642 %s Scheduling/Deadline information, a short string
1643 %b show breadcrumbs, i.e., the names of the higher levels
1644 %(expression) Eval EXPRESSION and replace the control string
1647 All specifiers work basically like the standard `%s' of printf, but may
1648 contain two additional characters: a question mark just after the `%'
1649 and a whitespace/punctuation character just before the final letter.
1651 If the first character after `%' is a question mark, the entire field
1652 will only be included if the corresponding value applies to the current
1653 entry. This is useful for fields which should have fixed width when
1654 present, but zero width when absent. For example, \"%?-12t\" will
1655 result in a 12 character time field if a time of the day is specified,
1656 but will completely disappear in entries which do not contain a time.
1658 If there is punctuation or whitespace character just before the
1659 final format letter, this character will be appended to the field
1660 value if the value is not empty. For example, the format
1661 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1662 the category is empty, no additional colon is inserted.
1664 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1667 - Indent the line with two space characters
1668 - Give the category a 12 chars wide field, padded with whitespace on
1669 the right (because of `-'). Append a colon if there is a category
1671 - If there is a time-of-day, put it into a 12 chars wide field. If no
1672 time, don't put in an empty field, just skip it (because of '?').
1673 - Finally, put the scheduling information.
1675 See also the variables `org-agenda-remove-times-when-in-prefix' and
1676 `org-agenda-remove-tags'.
1678 Custom commands can set this variable in the options section."
1680 (string :tag
"General format")
1681 (list :greedy t
:tag
"View dependent"
1682 (cons (const agenda
) (string :tag
"Format"))
1683 (cons (const timeline
) (string :tag
"Format"))
1684 (cons (const todo
) (string :tag
"Format"))
1685 (cons (const tags
) (string :tag
"Format"))
1686 (cons (const search
) (string :tag
"Format"))))
1687 :group
'org-agenda-line-format
)
1689 (defvar org-prefix-format-compiled nil
1690 "The compiled prefix format and associated variables.
1691 This is a list where first element is a list of variable bindings, and second
1692 element is the compiled format expression. See the variable
1693 `org-agenda-prefix-format'.")
1695 (defcustom org-agenda-todo-keyword-format
"%-1s"
1696 "Format for the TODO keyword in agenda lines.
1697 Set this to something like \"%-12s\" if you want all TODO keywords
1698 to occupy a fixed space in the agenda display."
1699 :group
'org-agenda-line-format
1702 (defcustom org-agenda-diary-sexp-prefix nil
1703 "A regexp that matches part of a diary sexp entry
1704 which should be treated as scheduling/deadline information in
1707 For example, you can use this to extract the `diary-remind-message' from
1708 `diary-remind' entries."
1709 :group
'org-agenda-line-format
1710 :type
'(choice (const :tag
"None" nil
) (regexp :tag
"Regexp")))
1712 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1713 "Text preceding timerange entries in the agenda view.
1714 This is a list with two strings. The first applies when the range
1715 is entirely on one day. The second applies if the range spans several days.
1716 The strings may have two \"%d\" format specifiers which will be filled
1717 with the sequence number of the days, and the total number of days in the
1718 range, respectively."
1719 :group
'org-agenda-line-format
1721 (string :tag
"Deadline today ")
1722 (choice :tag
"Deadline relative"
1723 (string :tag
"Format string")
1726 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1727 "Text preceding scheduled items in the agenda view.
1728 This is a list with two strings. The first applies when the item is
1729 scheduled on the current day. The second applies when it has been scheduled
1730 previously, it may contain a %d indicating that this is the nth time that
1731 this item is scheduled, due to automatic rescheduling of unfinished items
1732 for the following day. So this number is one larger than the number of days
1733 that passed since this item was scheduled first."
1734 :group
'org-agenda-line-format
1736 :package-version
'(Org .
"8.0")
1738 (string :tag
"Scheduled today ")
1739 (string :tag
"Scheduled previously")))
1741 (defcustom org-agenda-inactive-leader
"["
1742 "Text preceding item pulled into the agenda by inactive time stamps.
1743 These entries are added to the agenda when pressing \"[\"."
1744 :group
'org-agenda-line-format
1748 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: " "%2d d. ago: ")
1749 "Text preceding deadline items in the agenda view.
1750 This is a list with three strings. The first applies when the item has its
1751 deadline on the current day. The second applies when the deadline is in the
1752 future, the third one when it is in the past. The strings may contain %d
1753 to capture the number of days."
1754 :group
'org-agenda-line-format
1756 :package-version
'(Org .
"8.0")
1758 (string :tag
"Deadline today ")
1759 (string :tag
"Deadline in the future ")
1760 (string :tag
"Deadline in the past ")))
1762 (defcustom org-agenda-remove-times-when-in-prefix t
1763 "Non-nil means remove duplicate time specifications in agenda items.
1764 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1765 time-of-day specification in a headline or diary entry is extracted and
1766 placed into the prefix. If this option is non-nil, the original specification
1767 \(a timestamp or -range, or just a plain time(range) specification like
1768 11:30-4pm) will be removed for agenda display. This makes the agenda less
1770 The option can be t or nil. It may also be the symbol `beg', indicating
1771 that the time should only be removed when it is located at the beginning of
1772 the headline/diary entry."
1773 :group
'org-agenda-line-format
1775 (const :tag
"Always" t
)
1776 (const :tag
"Never" nil
)
1777 (const :tag
"When at beginning of entry" beg
)))
1779 (defcustom org-agenda-remove-timeranges-from-blocks nil
1780 "Non-nil means remove time ranges specifications in agenda
1781 items that span on several days."
1782 :group
'org-agenda-line-format
1786 (defcustom org-agenda-default-appointment-duration nil
1787 "Default duration for appointments that only have a starting time.
1788 When nil, no duration is specified in such cases.
1789 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1790 :group
'org-agenda-line-format
1792 (integer :tag
"Minutes")
1793 (const :tag
"No default duration")))
1795 (defcustom org-agenda-show-inherited-tags t
1796 "Non-nil means show inherited tags in each agenda line.
1798 When this option is set to `always', it take precedences over
1799 `org-agenda-use-tag-inheritance' and inherited tags are shown
1802 When this option is set to t (the default), inherited tags are
1803 shown when they are available, i.e. when the value of
1804 `org-agenda-use-tag-inheritance' has been taken into account.
1806 This can be set to a list of agenda types in which the agenda
1807 must display the inherited tags. Available types are `todo',
1808 `agenda', `search' and `timeline'.
1810 When set to nil, never show inherited tags in agenda lines."
1811 :group
'org-agenda-line-format
1815 (const :tag
"Show inherited tags when available" t
)
1816 (const :tag
"Always show inherited tags" always
)
1817 (repeat :tag
"Show inherited tags only in selected agenda types"
1818 (symbol :tag
"Agenda type"))))
1820 (defcustom org-agenda-use-tag-inheritance
'(todo search timeline agenda
)
1821 "List of agenda view types where to use tag inheritance.
1823 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1824 controlled by `org-use-tag-inheritance'. In other agenda types,
1825 `org-use-tag-inheritance' is not used for the selection of the
1826 agenda entries. Still, you may want the agenda to be aware of
1827 the inherited tags anyway, e.g. for later tag filtering.
1829 Allowed value are `todo', `search', `timeline' and `agenda'.
1831 This variable has no effect if `org-agenda-show-inherited-tags'
1832 is set to `always'. In that case, the agenda is aware of those
1835 The default value sets tags in every agenda type. Setting this
1836 option to nil will speed up non-tags agenda view a lot."
1840 (const :tag
"Use tag inheritance in all agenda types" t
)
1841 (repeat :tag
"Use tag inheritance in selected agenda types"
1842 (symbol :tag
"Agenda type"))))
1844 (defcustom org-agenda-hide-tags-regexp nil
1845 "Regular expression used to filter away specific tags in agenda views.
1846 This means that these tags will be present, but not be shown in the agenda
1847 line. Secondary filtering will still work on the hidden tags.
1848 Nil means don't hide any tags."
1849 :group
'org-agenda-line-format
1851 (const :tag
"Hide none" nil
)
1852 (string :tag
"Regexp ")))
1854 (defcustom org-agenda-remove-tags nil
1855 "Non-nil means remove the tags from the headline copy in the agenda.
1856 When this is the symbol `prefix', only remove tags when
1857 `org-agenda-prefix-format' contains a `%T' specifier."
1858 :group
'org-agenda-line-format
1860 (const :tag
"Always" t
)
1861 (const :tag
"Never" nil
)
1862 (const :tag
"When prefix format contains %T" prefix
)))
1864 (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
1865 'org-agenda-remove-tags
)
1867 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1868 "Shift tags in agenda items to this column.
1869 If this number is positive, it specifies the column. If it is negative,
1870 it means that the tags should be flushright to that column. For example,
1871 -80 works well for a normal 80 character screen."
1872 :group
'org-agenda-line-format
1875 (org-defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
)
1877 (defcustom org-agenda-fontify-priorities
'cookies
1878 "Non-nil means highlight low and high priorities in agenda.
1879 When t, the highest priority entries are bold, lowest priority italic.
1880 However, settings in `org-priority-faces' will overrule these faces.
1881 When this variable is the symbol `cookies', only fontify the
1882 cookies, not the entire task.
1883 This may also be an association list of priority faces, whose
1884 keys are the character values of `org-highest-priority',
1885 `org-default-priority', and `org-lowest-priority' (the default values
1886 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1887 color as a string, or a list like `(:background \"Red\")'.
1888 If it is a color, the variable `org-faces-easy-properties'
1889 determines if it is a foreground or a background color."
1890 :group
'org-agenda-line-format
1892 (const :tag
"Never" nil
)
1893 (const :tag
"Defaults" t
)
1894 (const :tag
"Cookies only" cookies
)
1895 (repeat :tag
"Specify"
1896 (list (character :tag
"Priority" :value ?A
)
1897 (choice :tag
"Face "
1898 (string :tag
"Color")
1899 (sexp :tag
"Face"))))))
1901 (defcustom org-agenda-day-face-function nil
1902 "Function called to determine what face should be used to display a day.
1903 The only argument passed to that function is the day. It should
1904 returns a face, or nil if does not want to specify a face and let
1905 the normal rules apply."
1906 :group
'org-agenda-line-format
1908 :type
'(choice (const nil
) (function)))
1910 (defcustom org-agenda-category-icon-alist nil
1911 "Alist of category icon to be displayed in agenda views.
1913 Each entry should have the following format:
1915 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1917 Where CATEGORY-REGEXP is a regexp matching the categories where
1918 the icon should be displayed.
1919 FILE-OR-DATA either a file path or a string containing image data.
1921 The other fields can be omitted safely if not needed:
1922 TYPE indicates the image type.
1923 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1925 PROPS are additional image attributes to assign to the image,
1926 like, e.g. `:ascent center'.
1928 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1930 If you want to set the display properties yourself, just put a
1931 list as second element:
1933 (CATEGORY-REGEXP (MY PROPERTY LIST))
1935 For example, to display a 16px horizontal space for Emacs
1936 category, you can use:
1938 (\"Emacs\" \\='(space . (:width (16))))"
1939 :group
'org-agenda-line-format
1941 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1942 :value-type
(choice (list :tag
"Icon"
1943 (string :tag
"File or data")
1944 (symbol :tag
"Type")
1945 (boolean :tag
"Data?")
1946 (repeat :tag
"Extra image properties" :inline t symbol
))
1947 (list :tag
"Display properties" sexp
))))
1949 (defgroup org-agenda-column-view nil
1950 "Options concerning column view in the agenda."
1951 :tag
"Org Agenda Column View"
1954 (defcustom org-agenda-view-columns-initially nil
1955 "When non-nil, switch to columns view right after creating the agenda."
1956 :group
'org-agenda-column-view
1959 :package-version
'(Org .
"9.0")
1962 (defcustom org-agenda-columns-show-summaries t
1963 "Non-nil means show summaries for columns displayed in the agenda view."
1964 :group
'org-agenda-column-view
1967 (defcustom org-agenda-columns-compute-summary-properties t
1968 "Non-nil means recompute all summary properties before column view.
1969 When column view in the agenda is listing properties that have a summary
1970 operator, it can go to all relevant buffers and recompute the summaries
1971 there. This can mean overhead for the agenda column view, but is necessary
1972 to have thing up to date.
1973 As a special case, a CLOCKSUM property also makes sure that the clock
1974 computations are current."
1975 :group
'org-agenda-column-view
1978 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1979 "Non-nil means the duration of an appointment will add to day effort.
1980 The property to which appointment durations will be added is the one given
1981 in the option `org-effort-property'. If an appointment does not have
1982 an end time, `org-agenda-default-appointment-duration' will be used. If that
1983 is not set, an appointment without end time will not contribute to the time
1985 :group
'org-agenda-column-view
1988 (defcustom org-agenda-auto-exclude-function nil
1989 "A function called with a tag to decide if it is filtered on \
1990 \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
1991 The sole argument to the function, which is called once for each
1992 possible tag, is a string giving the name of the tag. The
1993 function should return either nil if the tag should be included
1994 as normal, or \"-<TAG>\" to exclude the tag.
1995 Note that for the purpose of tag filtering, only the lower-case version of
1996 all tags will be considered, so that this function will only ever see
1997 the lower-case version of all tags."
1999 :type
'(choice (const nil
) (function)))
2001 (defcustom org-agenda-bulk-custom-functions nil
2002 "Alist of characters and custom functions for bulk actions.
2003 For example, this value makes those two functions available:
2005 \\='((?R set-category)
2008 With selected entries in an agenda buffer, `B R' will call
2009 the custom function `set-category' on the selected entries.
2010 Note that functions in this alist don't need to be quoted."
2015 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
2016 "Execute BODY with point at location given by `org-hd-marker' property.
2017 If STRING is non-nil, the text property will be fetched from position 0
2018 in that string. If STRING is nil, it will be fetched from the beginning
2019 of the current line."
2020 (org-with-gensyms (marker)
2021 `(let ((,marker
(get-text-property (if ,string
0 (point-at-bol))
2022 'org-hd-marker
,string
)))
2023 (with-current-buffer (marker-buffer ,marker
)
2027 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
2029 (defun org-add-agenda-custom-command (entry)
2030 "Replace or add a command in `org-agenda-custom-commands'.
2031 This is mostly for hacking and trying a new command - once the command
2032 works you probably want to add it to `org-agenda-custom-commands' for good."
2033 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
2035 (setcdr ass
(cdr entry
))
2036 (push entry org-agenda-custom-commands
))))
2038 ;;; Define the org-agenda-mode
2040 (defvar org-agenda-mode-map
(make-sparse-keymap)
2041 "Keymap for `org-agenda-mode'.")
2042 (org-defvaralias 'org-agenda-keymap
'org-agenda-mode-map
)
2044 (defvar org-agenda-menu
) ; defined later in this file.
2045 (defvar org-agenda-restrict nil
) ; defined later in this file.
2046 (defvar org-agenda-follow-mode nil
)
2047 (defvar org-agenda-entry-text-mode nil
)
2048 (defvar org-agenda-clockreport-mode nil
)
2049 (defvar org-agenda-show-log nil
)
2050 (defvar org-agenda-redo-command nil
)
2051 (defvar org-agenda-query-string nil
)
2052 (defvar org-agenda-mode-hook nil
2053 "Hook run after `org-agenda-mode' is turned on.
2054 The buffer is still writable when this hook is called.")
2055 (defvar org-agenda-type nil
)
2056 (defvar org-agenda-force-single-file nil
)
2057 (defvar org-agenda-bulk-marked-entries nil
2058 "List of markers that refer to marked entries in the agenda.")
2059 (defvar org-agenda-current-date nil
2060 "Active date when building the agenda.")
2062 ;;; Multiple agenda buffers support
2064 (defcustom org-agenda-sticky nil
2065 "Non-nil means agenda q key will bury agenda buffers.
2066 Agenda commands will then show existing buffer instead of generating new ones.
2067 When nil, `q' will kill the single agenda buffer."
2074 (defun org-toggle-sticky-agenda (&optional arg
)
2075 "Toggle `org-agenda-sticky'."
2077 (let ((new-value (if arg
2078 (> (prefix-numeric-value arg
) 0)
2079 (not org-agenda-sticky
))))
2080 (if (equal new-value org-agenda-sticky
)
2081 (and (org-called-interactively-p 'interactive
)
2082 (message "Sticky agenda was already %s"
2083 (if org-agenda-sticky
"enabled" "disabled")))
2084 (setq org-agenda-sticky new-value
)
2085 (org-agenda-kill-all-agenda-buffers)
2086 (and (org-called-interactively-p 'interactive
)
2087 (message "Sticky agenda %s"
2088 (if org-agenda-sticky
"enabled" "disabled"))))))
2090 (defvar org-agenda-buffer nil
2091 "Agenda buffer currently being generated.")
2093 (defvar org-agenda-last-prefix-arg nil
)
2094 (defvar org-agenda-this-buffer-name nil
)
2095 (defvar org-agenda-doing-sticky-redo nil
)
2096 (defvar org-agenda-this-buffer-is-sticky nil
)
2097 (defvar org-agenda-last-indirect-buffer nil
2098 "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
2100 (defconst org-agenda-local-vars
2101 '(org-agenda-this-buffer-name
2102 org-agenda-undo-list
2103 org-agenda-pending-undo-list
2104 org-agenda-follow-mode
2105 org-agenda-entry-text-mode
2106 org-agenda-clockreport-mode
2108 org-agenda-redo-command
2109 org-agenda-query-string
2111 org-agenda-bulk-marked-entries
2112 org-agenda-undo-has-started-in
2114 org-agenda-pre-window-conf
2115 org-agenda-columns-active
2116 org-agenda-tag-filter
2117 org-agenda-category-filter
2118 org-agenda-top-headline-filter
2119 org-agenda-regexp-filter
2120 org-agenda-effort-filter
2122 org-agenda-last-search-view-search-was-boolean
2123 org-agenda-last-indirect-buffer
2124 org-agenda-filtered-by-category
2125 org-agenda-filter-form
2126 org-agenda-cycle-counter
2127 org-agenda-last-prefix-arg
)
2128 "Variables that must be local in agenda buffers to allow multiple buffers.")
2130 (defun org-agenda-mode ()
2131 "Mode for time-sorted view on action items in Org-mode files.
2133 The following commands are available:
2135 \\{org-agenda-mode-map}"
2137 (cond (org-agenda-doing-sticky-redo
2138 ;; Refreshing sticky agenda-buffer
2140 ;; Preserve the value of `org-agenda-local-vars' variables,
2141 ;; while letting `kill-all-local-variables' kill the rest
2142 (let ((save (buffer-local-variables)))
2143 (kill-all-local-variables)
2144 (mapc 'make-local-variable org-agenda-local-vars
)
2146 (let ((var (car elem
))
2149 (member var org-agenda-local-vars
))
2151 (setq-local org-agenda-this-buffer-is-sticky t
))
2153 ;; Creating a sticky Agenda buffer for the first time
2154 (kill-all-local-variables)
2155 (mapc 'make-local-variable org-agenda-local-vars
)
2156 (setq-local org-agenda-this-buffer-is-sticky t
))
2158 ;; Creating a non-sticky agenda buffer
2159 (kill-all-local-variables)
2160 (setq-local org-agenda-this-buffer-is-sticky nil
)))
2161 (setq org-agenda-undo-list nil
2162 org-agenda-pending-undo-list nil
2163 org-agenda-bulk-marked-entries nil
)
2164 (setq major-mode
'org-agenda-mode
)
2165 ;; Keep global-font-lock-mode from turning on font-lock-mode
2166 (setq-local font-lock-global-modes
(list 'not major-mode
))
2167 (setq mode-name
"Org-Agenda")
2168 (setq indent-tabs-mode nil
)
2169 (use-local-map org-agenda-mode-map
)
2170 (easy-menu-add org-agenda-menu
)
2171 (if org-startup-truncated
(setq truncate-lines t
))
2172 (setq-local line-move-visual nil
)
2173 (org-add-hook 'post-command-hook
'org-agenda-update-agenda-type nil
'local
)
2174 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
2175 ;; Make sure properties are removed when copying text
2176 (org-add-hook 'filter-buffer-substring-functions
2177 (lambda (fun start end delete
)
2178 (substring-no-properties (funcall fun start end delete
)))
2180 (unless org-agenda-keep-modes
2181 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2182 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
))
2183 (setq org-agenda-show-log org-agenda-start-with-log-mode
)
2184 (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
)
2185 (add-to-invisibility-spec '(org-filtered))
2186 (add-to-invisibility-spec '(org-link))
2188 '("Agenda") "Agenda Files"
2192 (if (get 'org-agenda-files
'org-restrict
)
2193 "Restricted to single file"
2195 '(org-edit-agenda-file-list)
2196 (not (get 'org-agenda-files
'org-restrict
)))
2198 (mapcar 'org-file-menu-entry
(org-agenda-files))))
2199 (org-agenda-set-mode-name)
2201 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
2202 (list 'org-agenda-mode-hook
)))
2204 (substitute-key-definition 'undo
'org-agenda-undo
2205 org-agenda-mode-map global-map
)
2206 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
2207 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
2208 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
2209 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
2210 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
2211 (org-defkey org-agenda-mode-map
[(meta down
)] 'org-agenda-drag-line-forward
)
2212 (org-defkey org-agenda-mode-map
[(meta up
)] 'org-agenda-drag-line-backward
)
2213 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
2214 (org-defkey org-agenda-mode-map
"\M-m" 'org-agenda-bulk-toggle
)
2215 (org-defkey org-agenda-mode-map
"*" 'org-agenda-bulk-mark-all
)
2216 (org-defkey org-agenda-mode-map
"\M-*" 'org-agenda-bulk-toggle-all
)
2217 (org-defkey org-agenda-mode-map
"#" 'org-agenda-dim-blocked-tasks
)
2218 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
2219 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
2220 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-unmark-all
)
2221 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
2222 (org-defkey org-agenda-mode-map
"k" 'org-agenda-capture
)
2223 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
2224 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
2225 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
2226 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
2227 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
2228 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
2229 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
2230 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
2231 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
2232 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
2233 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
2234 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2235 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2236 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2237 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2238 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2239 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2240 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2241 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2242 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2243 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2244 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2245 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2246 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2247 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2248 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2249 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2250 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2251 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2252 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2253 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2254 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2255 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2257 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2258 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2259 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2260 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2261 (while l (org-defkey org-agenda-mode-map
2262 (int-to-string (pop l)) 'digit-argument)))
2264 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2265 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2266 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2267 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2268 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2269 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2270 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2271 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2272 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2273 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2274 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2275 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2276 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2277 'org-clock-modify-effort-estimate)
2278 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2279 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2280 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2281 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2282 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2283 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2284 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2285 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2286 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2287 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2288 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2289 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2290 (substitute-key-definition 'next-line 'org-agenda-next-line
2291 org-agenda-mode-map global-map)
2292 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2293 org-agenda-mode-map global-map)
2294 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2295 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2296 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2297 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2298 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2299 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2300 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2301 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2302 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2303 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2304 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2305 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2306 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2307 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2308 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2309 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2310 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2311 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2312 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2313 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2314 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2315 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2316 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2317 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2318 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2319 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2320 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2321 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2322 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2323 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2325 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2326 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2327 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2328 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2329 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2330 (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
2331 (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
2332 (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
2333 (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
2334 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2335 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
2336 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2337 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2338 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2339 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2341 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2342 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2344 (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
2345 (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
2347 (when org-agenda-mouse-1-follows-link
2348 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2349 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2354 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2355 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2356 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2357 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2360 ["Day View" org-agenda-day-view
2361 :active (org-agenda-check-type nil 'agenda)
2362 :style radio :selected (eq org-agenda-current-span 'day)
2363 :keys "v d (or just d)"]
2364 ["Week View" org-agenda-week-view
2365 :active (org-agenda-check-type nil 'agenda)
2366 :style radio :selected (eq org-agenda-current-span 'week)
2368 ["Fortnight View" org-agenda-fortnight-view
2369 :active (org-agenda-check-type nil 'agenda)
2370 :style radio :selected (eq org-agenda-current-span 'fortnight)
2372 ["Month View" org-agenda-month-view
2373 :active (org-agenda-check-type nil 'agenda)
2374 :style radio :selected (eq org-agenda-current-span 'month)
2376 ["Year View" org-agenda-year-view
2377 :active (org-agenda-check-type nil 'agenda)
2378 :style radio :selected (eq org-agenda-current-span 'year)
2381 ["Include Diary" org-agenda-toggle-diary
2382 :style toggle :selected org-agenda-include-diary
2383 :active (org-agenda-check-type nil 'agenda)]
2384 ["Include Deadlines" org-agenda-toggle-deadlines
2385 :style toggle :selected org-agenda-include-deadlines
2386 :active (org-agenda-check-type nil 'agenda)]
2387 ["Use Time Grid" org-agenda-toggle-time-grid
2388 :style toggle :selected org-agenda-use-time-grid
2389 :active (org-agenda-check-type nil 'agenda)]
2391 ["Show clock report" org-agenda-clockreport-mode
2392 :style toggle :selected org-agenda-clockreport-mode
2393 :active (org-agenda-check-type nil 'agenda)]
2394 ["Show some entry text" org-agenda-entry-text-mode
2395 :style toggle :selected org-agenda-entry-text-mode
2398 ["Show Logbook entries" org-agenda-log-mode
2399 :style toggle :selected org-agenda-show-log
2400 :active (org-agenda-check-type nil 'agenda 'timeline)
2401 :keys "v l (or just l)"]
2402 ["Include archived trees" org-agenda-archives-mode
2403 :style toggle :selected org-agenda-archives-mode :active t
2405 ["Include archive files" (org-agenda-archives-mode t)
2406 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2409 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2410 ["Write view to file" org-agenda-write t]
2411 ["Rebuild buffer" org-agenda-redo t]
2412 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2414 ["Show original entry" org-agenda-show t]
2415 ["Go To (other window)" org-agenda-goto t]
2416 ["Go To (this window)" org-agenda-switch-to t]
2417 ["Capture with cursor date" org-agenda-capture t]
2418 ["Follow Mode" org-agenda-follow-mode
2419 :style toggle :selected org-agenda-follow-mode :active t]
2420 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2423 ["Cycle TODO" org-agenda-todo t]
2424 ["Next TODO set" org-agenda-todo-nextset t]
2425 ["Previous TODO set" org-agenda-todo-previousset t]
2426 ["Add note" org-agenda-add-note t])
2427 ("Archive/Refile/Delete"
2428 ["Archive default" org-agenda-archive-default t]
2429 ["Archive default" org-agenda-archive-default-with-confirmation t]
2430 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2431 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2432 ["Archive subtree" org-agenda-archive t]
2434 ["Refile" org-agenda-refile t]
2436 ["Delete subtree" org-agenda-kill t])
2438 ["Mark entry" org-agenda-bulk-mark t]
2439 ["Mark all" org-agenda-bulk-mark-all t]
2440 ["Unmark entry" org-agenda-bulk-unmark t]
2441 ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
2442 ["Toggle mark" org-agenda-bulk-toggle t]
2443 ["Toggle all" org-agenda-bulk-toggle-all t]
2444 ["Mark regexp" org-agenda-bulk-mark-regexp t])
2445 ["Act on all marked" org-agenda-bulk-action t]
2447 ("Tags and Properties"
2448 ["Show all Tags" org-agenda-show-tags t]
2449 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2450 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2452 ["Column View" org-columns t])
2453 ("Deadline/Schedule"
2454 ["Schedule" org-agenda-schedule t]
2455 ["Set Deadline" org-agenda-deadline t]
2457 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2458 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2459 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2460 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2461 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2462 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2463 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2465 ["Clock in" org-agenda-clock-in t]
2466 ["Clock out" org-agenda-clock-out t]
2467 ["Clock cancel" org-agenda-clock-cancel t]
2468 ["Goto running clock" org-clock-goto t]
2470 ["Set Effort" org-agenda-set-effort t]
2471 ["Change clocked effort" org-clock-modify-effort-estimate
2472 (org-clock-is-active)])
2474 ["Set Priority" org-agenda-priority t]
2475 ["Increase Priority" org-agenda-priority-up t]
2476 ["Decrease Priority" org-agenda-priority-down t]
2477 ["Show Priority" org-show-priority t])
2479 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2480 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2481 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2482 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2483 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2484 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2486 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2488 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2491 ["Push Files and Views" org-mobile-push t]
2492 ["Get Captured and Flagged" org-mobile-pull t]
2493 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2494 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2496 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2498 ["Quit" org-agenda-quit t]
2499 ["Exit and Release Buffers" org-agenda-exit t]
2504 (defvar org-agenda-allow-remote-undo t
2505 "Non-nil means allow remote undo from the agenda buffer.")
2506 (defvar org-agenda-undo-has-started-in nil
2507 "Buffers that have already seen `undo-start' in the current undo sequence.")
2509 (defun org-agenda-undo ()
2510 "Undo a remote editing step in the agenda.
2511 This undoes changes both in the agenda buffer and in the remote buffer
2512 that have been changed along."
2514 (or org-agenda-allow-remote-undo
2515 (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2516 (if (not (eq this-command last-command))
2517 (setq org-agenda-undo-has-started-in nil
2518 org-agenda-pending-undo-list org-agenda-undo-list))
2519 (if (not org-agenda-pending-undo-list)
2520 (user-error "No further undo information"))
2521 (let* ((entry (pop org-agenda-pending-undo-list))
2522 buf line cmd rembuf)
2523 (setq cmd (pop entry) line (pop entry))
2524 (setq rembuf (nth 2 entry))
2525 (org-with-remote-undo rembuf
2526 (while (bufferp (setq buf (pop entry)))
2528 (with-current-buffer buf
2529 (let ((last-undo-buffer buf)
2530 (inhibit-read-only t))
2531 (unless (memq buf org-agenda-undo-has-started-in)
2532 (push buf org-agenda-undo-has-started-in)
2533 (make-local-variable 'pending-undo-list)
2535 (while (and pending-undo-list
2536 (listp pending-undo-list)
2537 (not (car pending-undo-list)))
2538 (pop pending-undo-list))
2540 (org-goto-line line)
2541 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2543 (defun org-verify-change-for-undo (l1 l2)
2544 "Verify that a real change occurred between the undo lists L1 and L2."
2545 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2546 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2551 (defvar org-agenda-restrict-begin (make-marker))
2552 (defvar org-agenda-restrict-end (make-marker))
2553 (defvar org-agenda-last-dispatch-buffer nil)
2554 (defvar org-agenda-overriding-restriction nil)
2556 (defcustom org-agenda-custom-commands-contexts nil
2557 "Alist of custom agenda keys and contextual rules.
2559 For example, if you have a custom agenda command \"p\" and you
2560 want this command to be accessible only from plain text files,
2563 \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
2565 Here are the available contexts definitions:
2567 in-file: command displayed only in matching files
2568 in-mode: command displayed only in matching modes
2569 not-in-file: command not displayed in matching files
2570 not-in-mode: command not displayed in matching modes
2571 in-buffer: command displayed only in matching buffers
2572 not-in-buffer: command not displayed in matching buffers
2573 [function]: a custom function taking no argument
2575 If you define several checks, the agenda command will be
2576 accessible if there is at least one valid check.
2578 You can also bind a key to another agenda custom command
2579 depending on contextual rules.
2581 \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
2583 Here it means: in .txt files, use \"p\" as the key for the
2584 agenda command otherwise associated with \"q\". (The command
2585 originally associated with \"q\" is not displayed to avoid
2588 :group 'org-agenda-custom-commands
2589 :type '(repeat (list :tag "Rule"
2590 (string :tag " Agenda key")
2591 (string :tag "Replace by command")
2592 (repeat :tag "Available when"
2594 (cons :tag "Condition"
2596 (const :tag "In file" in-file)
2597 (const :tag "Not in file" not-in-file)
2598 (const :tag "In buffer" in-buffer)
2599 (const :tag "Not in buffer" not-in-buffer)
2600 (const :tag "In mode" in-mode)
2601 (const :tag "Not in mode" not-in-mode))
2603 (function :tag "Custom function"))))))
2605 (defcustom org-agenda-max-entries nil
2606 "Maximum number of entries to display in an agenda.
2607 This can be nil (no limit) or an integer or an alist of agenda
2608 types with an associated number of entries to display in this
2611 :package-version '(Org . "8.0")
2612 :group 'org-agenda-custom-commands
2613 :type '(choice (symbol :tag "No limit" nil)
2614 (integer :tag "Max number of entries")
2616 (cons (choice :tag "Agenda type"
2622 (integer :tag "Max number of entries")))))
2624 (defcustom org-agenda-max-todos nil
2625 "Maximum number of TODOs to display in an agenda.
2626 This can be nil (no limit) or an integer or an alist of agenda
2627 types with an associated number of entries to display in this
2630 :package-version '(Org . "8.0")
2631 :group 'org-agenda-custom-commands
2632 :type '(choice (symbol :tag "No limit" nil)
2633 (integer :tag "Max number of TODOs")
2635 (cons (choice :tag "Agenda type"
2641 (integer :tag "Max number of TODOs")))))
2643 (defcustom org-agenda-max-tags nil
2644 "Maximum number of tagged entries to display in an agenda.
2645 This can be nil (no limit) or an integer or an alist of agenda
2646 types with an associated number of entries to display in this
2649 :package-version '(Org . "8.0")
2650 :group 'org-agenda-custom-commands
2651 :type '(choice (symbol :tag "No limit" nil)
2652 (integer :tag "Max number of tagged entries")
2654 (cons (choice :tag "Agenda type"
2660 (integer :tag "Max number of tagged entries")))))
2662 (defcustom org-agenda-max-effort nil
2663 "Maximum cumulated effort duration for the agenda.
2664 This can be nil (no limit) or a number of minutes (as an integer)
2665 or an alist of agenda types with an associated number of minutes
2666 to limit entries to in this type."
2668 :package-version '(Org . "8.0")
2669 :group 'org-agenda-custom-commands
2670 :type '(choice (symbol :tag "No limit" nil)
2671 (integer :tag "Max number of minutes")
2673 (cons (choice :tag "Agenda type"
2679 (integer :tag "Max number of minutes")))))
2681 (defvar org-keys nil)
2682 (defvar org-match nil)
2684 (defun org-agenda (&optional arg org-keys restriction)
2685 "Dispatch agenda commands to collect entries to the agenda buffer.
2686 Prompts for a command to execute. Any prefix arg will be passed
2687 on to the selected command. The default selections are:
2689 a Call `org-agenda-list' to display the agenda for current day or week.
2690 t Call `org-todo-list' to display the global todo list.
2691 T Call `org-todo-list' to display the global todo list, select only
2692 entries with a specific TODO keyword (the user gets a prompt).
2693 m Call `org-tags-view' to display headlines with tags matching
2694 a condition (the user is prompted for the condition).
2695 M Like `m', but select only TODO entries, no ordinary headlines.
2696 L Create a timeline for the current buffer.
2697 e Export views to associated files.
2698 s Search entries for keywords.
2699 S Search entries for keywords, only with TODO keywords.
2700 / Multi occur across all agenda files and also files listed
2701 in `org-agenda-text-search-extra-files'.
2702 < Restrict agenda commands to buffer, subtree, or region.
2703 Press several times to get the desired effect.
2704 > Remove a previous restriction.
2705 # List \"stuck\" projects.
2706 ! Configure what \"stuck\" means.
2707 C Configure custom agenda commands.
2709 More commands can be added by configuring the variable
2710 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2711 searches can be pre-defined in this way.
2713 If the current buffer is in Org-mode and visiting a file, you can also
2714 first press `<' once to indicate that the agenda should be temporarily
2715 \(until the next use of \\[org-agenda]) restricted to the current file.
2716 Pressing `<' twice means to restrict to the current subtree or region
2720 (let* ((prefix-descriptions nil)
2721 (org-agenda-buffer-name org-agenda-buffer-name)
2722 (org-agenda-window-setup (if (equal (buffer-name)
2723 org-agenda-buffer-name)
2725 org-agenda-window-setup))
2726 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2727 (org-agenda-custom-commands
2728 ;; normalize different versions
2732 (cond ((stringp (cdr x))
2733 (push x prefix-descriptions)
2735 ((stringp (nth 1 x)) x)
2736 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2737 (t (cons (car x) (cons "" (cdr x))))))
2738 org-agenda-custom-commands)))
2739 (org-agenda-custom-commands
2740 (org-contextualize-keys
2741 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2742 (buf (current-buffer))
2743 (bfn (buffer-file-name (buffer-base-buffer)))
2744 entry key type org-match lprops ans)
2745 ;; Turn off restriction unless there is an overriding one,
2746 (unless org-agenda-overriding-restriction
2747 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2748 ;; There is a request to keep the file list in place
2749 (put 'org-agenda-files 'org-restrict nil))
2750 (setq org-agenda-restrict nil)
2751 (move-marker org-agenda-restrict-begin nil)
2752 (move-marker org-agenda-restrict-end nil))
2753 ;; Delete old local properties
2754 (put 'org-agenda-redo-command 'org-lprops nil)
2755 ;; Delete previously set last-arguments
2756 (put 'org-agenda-redo-command 'last-args nil)
2757 ;; Remember where this call originated
2758 (setq org-agenda-last-dispatch-buffer (current-buffer))
2760 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2762 restriction (cdr ans)))
2763 ;; If we have sticky agenda buffers, set a name for the buffer,
2764 ;; depending on the invoking keys. The user may still set this
2765 ;; as a command option, which will overwrite what we do here.
2766 (if org-agenda-sticky
2767 (setq org-agenda-buffer-name
2768 (format "*Org Agenda(%s)*" org-keys)))
2769 ;; Establish the restriction, if any
2770 (when (and (not org-agenda-overriding-restriction) restriction)
2771 (put 'org-agenda-files 'org-restrict (list bfn))
2773 ((eq restriction 'region)
2774 (setq org-agenda-restrict (current-buffer))
2775 (move-marker org-agenda-restrict-begin (region-beginning))
2776 (move-marker org-agenda-restrict-end (region-end)))
2777 ((eq restriction 'subtree)
2779 (setq org-agenda-restrict (current-buffer))
2780 (org-back-to-heading t)
2781 (move-marker org-agenda-restrict-begin (point))
2782 (move-marker org-agenda-restrict-end
2783 (progn (org-end-of-subtree t)))))))
2785 ;; For example the todo list should not need it (but does...)
2787 ((setq entry (assoc org-keys org-agenda-custom-commands))
2788 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2790 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2791 lprops (nth 4 entry))
2792 (if org-agenda-sticky
2793 (setq org-agenda-buffer-name
2794 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2795 (format "*Org Agenda(%s)*" org-keys))))
2796 (put 'org-agenda-redo-command 'org-lprops lprops)
2799 (org-let lprops '(org-agenda-list current-prefix-arg)))
2801 (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
2803 (org-let lprops '(org-todo-list current-prefix-arg)))
2805 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2807 (org-let lprops '(org-agenda-list-stuck-projects
2808 current-prefix-arg)))
2810 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2811 ((eq type 'tags-todo)
2812 (org-let lprops '(org-tags-view '(4) org-match)))
2814 (org-let lprops '(org-todo-list org-match)))
2815 ((eq type 'tags-tree)
2816 (org-check-for-org-mode)
2817 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2818 ((eq type 'todo-tree)
2819 (org-check-for-org-mode)
2821 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2822 (regexp-quote org-match) "\\>"))))
2823 ((eq type 'occur-tree)
2824 (org-check-for-org-mode)
2825 (org-let lprops '(org-occur org-match)))
2827 (org-let lprops '(funcall type org-match)))
2829 (org-let lprops '(funcall type org-match)))
2830 (t (user-error "Invalid custom agenda command type %s" type))))
2831 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2832 ((equal org-keys "C")
2833 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2834 (customize-variable 'org-agenda-custom-commands))
2835 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2836 ((equal org-keys "s") (call-interactively 'org-search-view))
2837 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2838 ((equal org-keys "t") (call-interactively 'org-todo-list))
2839 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2840 ((equal org-keys "m") (call-interactively 'org-tags-view))
2841 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2842 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2843 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2847 (unless (current-message)
2848 (let* ((m (org-agenda-get-any-marker))
2849 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2852 "FLAGGING-NOTE ([?] for more info): "
2854 (replace-regexp-in-string
2856 (copy-sequence note))
2857 nil 'face 'org-warning)))))))
2859 ((equal org-keys "L")
2860 (unless (derived-mode-p 'org-mode)
2861 (user-error "This is not an Org-mode file"))
2863 (put 'org-agenda-files 'org-restrict (list bfn))
2864 (org-call-with-arg 'org-timeline arg)))
2865 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2866 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2867 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2868 (t (user-error "Invalid agenda key"))))))
2870 (defvar org-agenda-multi)
2872 (defun org-agenda-append-agenda ()
2873 "Append another agenda view to the current one.
2874 This function allows interactive building of block agendas.
2875 Agenda views are separated by `org-agenda-block-separator'."
2877 (unless (derived-mode-p 'org-agenda-mode)
2878 (user-error "Can only append from within agenda buffer"))
2879 (let ((org-agenda-multi t))
2882 (org-agenda-finalize)
2883 (setq buffer-read-only t)
2884 (org-agenda-fit-window-to-buffer)))
2886 (defun org-agenda-normalize-custom-commands (cmds)
2887 "Normalize custom commands CMDS."
2891 (cond ((stringp (cdr x)) nil)
2892 ((stringp (nth 1 x)) x)
2893 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2894 (t (cons (car x) (cons "" (cdr x))))))
2897 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2898 "The user interface for selecting an agenda command."
2900 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2901 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2902 (region-p (org-region-active-p))
2903 (custom org-agenda-custom-commands)
2905 restriction second-time
2906 c entry key type match prefixes rmheader header-end custom1 desc
2907 line lines left right n n1)
2908 (save-window-excursion
2909 (delete-other-windows)
2910 (org-switch-to-buffer-other-window " *Agenda Commands*")
2912 (insert (eval-when-compile
2914 "Press key for an agenda command: < Buffer, subtree/region restriction
2915 -------------------------------- > Remove restriction
2916 a Agenda for current week or day e Export agenda views
2917 t List of all TODO entries T Entries with special TODO kwd
2918 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2919 s Search for keywords S Like s, but only TODO entries
2920 L Timeline for current buffer # List stuck projects (!=configure)
2921 / Multi-occur C Configure custom agenda commands
2922 ? Find :FLAGGED: entries * Toggle sticky agenda views
2925 (while (string-match
2926 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2928 (setq start (match-end 0))
2929 (add-text-properties (match-beginning 2) (match-end 2)
2930 '(face bold) header))
2932 (setq header-end (point-marker))
2934 (setq custom1 custom)
2935 (when (eq rmheader t)
2937 (re-search-forward ":" nil t)
2938 (delete-region (match-end 0) (point-at-eol))
2941 (delete-region (match-end 0) (point-at-eol))
2942 (move-marker header-end (match-end 0)))
2943 (goto-char header-end)
2944 (delete-region (point) (point-max))
2946 ;; Produce all the lines that describe custom commands and prefixes
2948 (while (setq entry (pop custom1))
2949 (setq key (car entry) desc (nth 1 entry)
2951 match (nth 3 entry))
2952 (if (> (length key) 1)
2953 (add-to-list 'prefixes (string-to-char key))
2957 (org-add-props (copy-sequence key)
2960 ((string-match "\\S-" desc) desc)
2961 ((eq type 'agenda) "Agenda for current week or day")
2962 ((eq type 'agenda*) "Appointments for current week or day")
2963 ((eq type 'alltodo) "List of all TODO entries")
2964 ((eq type 'search) "Word search")
2965 ((eq type 'stuck) "List of stuck projects")
2966 ((eq type 'todo) "TODO keyword")
2967 ((eq type 'tags) "Tags query")
2968 ((eq type 'tags-todo) "Tags (TODO)")
2969 ((eq type 'tags-tree) "Tags tree")
2970 ((eq type 'todo-tree) "TODO kwd tree")
2971 ((eq type 'occur-tree) "Occur tree")
2972 ((functionp type) (if (symbolp type)
2974 "Lambda expression"))
2976 (if org-agenda-menu-show-matcher
2981 (setq match (copy-sequence match))
2982 (org-add-props match nil 'face 'org-warning))
2984 (format "set of %d commands" (length type))))))
2985 (if (org-string-nw-p match)
2986 (add-text-properties
2987 0 (length line) (list 'help-echo
2988 (concat "Matcher: " match)) line)))
2990 (setq lines (nreverse lines))
2995 (org-add-props (char-to-string x)
2997 (or (cdr (assoc (concat selstring
2999 prefix-descriptions))
3004 ;; Check if we should display in two columns
3005 (if org-agenda-menu-two-columns
3007 (setq n (length lines)
3008 n1 (+ (/ n 2) (mod n 2))
3009 right (nthcdr n1 lines)
3010 left (copy-sequence lines))
3011 (setcdr (nthcdr (1- n1) left) nil))
3012 (setq left lines right nil))
3014 (insert "\n" (pop left))
3016 (if (< (current-column) 40)
3017 (move-to-column 40 t)
3019 (insert (pop right))))
3021 ;; Make the window the right size
3022 (goto-char (point-min))
3024 (if (not (pos-visible-in-window-p (point-max)))
3025 (org-fit-window-to-buffer))
3026 (setq second-time t)
3027 (org-fit-window-to-buffer))
3029 ;; Ask for selection
3030 (message "Press key for agenda command%s:"
3031 (if (or restrict-ok org-agenda-overriding-restriction)
3032 (if org-agenda-overriding-restriction
3033 " (restriction lock active)"
3035 (format " (restricted to %s)" restriction)
3038 (setq c (read-char-exclusive))
3041 ((assoc (char-to-string c) custom)
3042 (setq selstring (concat selstring (char-to-string c)))
3043 (throw 'exit (cons selstring restriction)))
3045 (setq selstring (concat selstring (char-to-string c))
3047 rmheader (or rmheader t)
3048 custom (delq nil (mapcar
3050 (if (or (= (length (car x)) 1)
3051 (/= (string-to-char (car x)) c))
3053 (cons (substring (car x) 1) (cdr x))))
3056 (call-interactively 'org-toggle-sticky-agenda)
3058 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
3059 (message "Restriction is only possible in Org-mode buffers")
3062 (org-agenda-remove-restriction-lock 'noupdate)
3063 (setq restriction 'buffer))
3065 (org-agenda-remove-restriction-lock 'noupdate)
3066 (setq restriction (if region-p 'region 'subtree)))
3068 (org-agenda-remove-restriction-lock 'noupdate)
3071 ((eq restriction 'buffer)
3072 (if region-p 'region 'subtree))
3073 ((memq restriction '(subtree region))
3077 (org-agenda-remove-restriction-lock 'noupdate)
3078 (setq restriction nil))
3079 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
3080 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
3081 ((and (> (length selstring) 0) (eq c ?\d))
3083 (org-agenda-get-restriction-and-command prefix-descriptions))
3085 ((equal c ?q) (error "Abort"))
3086 (t (user-error "Invalid key %c" c))))))))
3088 (defun org-agenda-fit-window-to-buffer ()
3089 "Fit the window to the buffer size."
3090 (and (memq org-agenda-window-setup '(reorganize-frame))
3091 (fboundp 'fit-window-to-buffer)
3092 (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
3093 (= (car org-agenda-window-frame-fractions) 1.0))
3094 (delete-other-windows)
3095 (org-fit-window-to-buffer
3097 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3098 (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
3100 (defvar org-cmd nil)
3101 (defvar org-agenda-overriding-cmd nil)
3102 (defvar org-agenda-overriding-arguments nil)
3103 (defvar org-agenda-overriding-cmd-arguments nil)
3104 (defun org-agenda-run-series (name series)
3105 "Run agenda NAME as a SERIES of agenda commands."
3106 (org-let (nth 1 series) '(org-agenda-prepare name))
3107 ;; We need to reset agenda markers here, because when constructing a
3108 ;; block agenda, the individual blocks do not do that.
3109 (org-agenda-reset-markers)
3110 (let* ((org-agenda-multi t)
3111 (redo (list 'org-agenda-run-series name (list 'quote series)))
3113 (gprops (nth 1 series))
3114 match ;; The byte compiler incorrectly complains about this. Keep it!
3115 org-cmd type lprops)
3116 (while (setq org-cmd (pop cmds))
3117 (setq type (car org-cmd))
3118 (setq match (eval (nth 1 org-cmd)))
3119 (setq lprops (nth 2 org-cmd))
3120 (let ((org-agenda-overriding-arguments
3121 (if (eq org-agenda-overriding-cmd org-cmd)
3122 (or org-agenda-overriding-arguments
3123 org-agenda-overriding-cmd-arguments))))
3126 (org-let2 gprops lprops
3127 '(call-interactively 'org-agenda-list)))
3129 (org-let2 gprops lprops
3130 '(funcall 'org-agenda-list nil nil t)))
3132 (org-let2 gprops lprops
3133 '(call-interactively 'org-todo-list)))
3135 (org-let2 gprops lprops
3136 '(org-search-view current-prefix-arg match nil)))
3138 (org-let2 gprops lprops
3139 '(call-interactively 'org-agenda-list-stuck-projects)))
3141 (org-let2 gprops lprops
3142 '(org-tags-view current-prefix-arg match)))
3143 ((eq type 'tags-todo)
3144 (org-let2 gprops lprops
3145 '(org-tags-view '(4) match)))
3147 (org-let2 gprops lprops
3148 '(org-todo-list match)))
3150 (org-let2 gprops lprops
3151 '(funcall type match)))
3152 (t (error "Invalid type in command series")))))
3154 (let ((inhibit-read-only t))
3155 (add-text-properties (point-min) (point-max)
3156 `(org-series t org-series-redo-cmd ,redo)))
3157 (setq org-agenda-redo-command redo)
3158 (goto-char (point-min)))
3159 (org-agenda-fit-window-to-buffer)
3160 (org-let (nth 1 series) '(org-agenda-finalize)))
3163 (defmacro org-batch-agenda (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."
3170 (org-eval-in-environment (org-make-parameter-alist parameters)
3171 (let (org-agenda-sticky)
3172 (if (> (length cmd-key) 1)
3173 (org-tags-view nil cmd-key)
3174 (org-agenda nil cmd-key))))
3175 (set-buffer org-agenda-buffer-name)
3176 (princ (buffer-string)))
3178 (defvar org-agenda-info nil)
3181 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3182 "Run an agenda command in batch mode and send the result to STDOUT.
3183 If CMD-KEY is a string of length 1, it is used as a key in
3184 `org-agenda-custom-commands' and triggers this command. If it is a
3185 longer string it is used as a tags/todo match string.
3186 Parameters are alternating variable names and values that will be bound
3187 before running the agenda command.
3189 The output gives a line for each selected agenda item. Each
3190 item is a list of comma-separated values, like this:
3192 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3194 category The category of the item
3195 head The headline, without TODO kwd, TAGS and PRIORITY
3196 type The type of the agenda entry, can be
3197 todo selected in TODO match
3198 tagsmatch selected in tags match
3199 diary imported from diary
3200 deadline a deadline on given date
3201 scheduled scheduled on given date
3202 timestamp entry has timestamp on given date
3203 closed entry was closed on given date
3204 upcoming-deadline warning about deadline
3205 past-scheduled forwarded scheduled item
3206 block entry has date block including g. date
3207 todo The todo keyword, if any
3208 tags All tags including inherited ones, separated by colons
3209 date The relevant date, like 2007-2-14
3210 time The time, like 15:00-16:50
3211 extra Sting with extra planning info
3212 priority-l The priority letter if any was given
3213 priority-n The computed numerical priority
3214 agenda-day The day in the agenda where this is listed"
3215 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3216 (org-make-parameter-alist parameters))
3217 (if (> (length cmd-key) 2)
3218 (org-tags-view nil cmd-key)
3219 (org-agenda nil cmd-key)))
3220 (set-buffer org-agenda-buffer-name)
3221 (let* ((lines (org-split-string (buffer-string) "\n"))
3223 (while (setq line (pop lines))
3225 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3226 (setq org-agenda-info
3227 (org-fix-agenda-info (text-properties-at 0 line)))
3229 (mapconcat 'org-agenda-export-csv-mapper
3230 '(org-category txt type todo tags date time extra
3231 priority-letter priority agenda-day)
3235 (defun org-fix-agenda-info (props)
3236 "Make sure all properties on an agenda item have a canonical form.
3237 This ensures the export commands can easily use it."
3239 (when (setq tmp (plist-get props 'tags))
3240 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3241 (when (setq tmp (plist-get props 'date))
3242 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3243 (let ((calendar-date-display-form '(year "-" month "-" day)))
3244 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3246 (setq tmp (calendar-date-string tmp)))
3247 (setq props (plist-put props 'date tmp)))
3248 (when (setq tmp (plist-get props 'day))
3249 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3250 (let ((calendar-date-display-form '(year "-" month "-" day)))
3251 (setq tmp (calendar-date-string tmp)))
3252 (setq props (plist-put props 'day tmp))
3253 (setq props (plist-put props 'agenda-day tmp)))
3254 (when (setq tmp (plist-get props 'txt))
3255 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3256 (plist-put props 'priority-letter (match-string 1 tmp))
3257 (setq tmp (replace-match "" t t tmp)))
3258 (when (and (setq re (plist-get props 'org-todo-regexp))
3259 (setq re (concat "\\`\\.*" re " ?"))
3260 (string-match re tmp))
3261 (plist-put props 'todo (match-string 1 tmp))
3262 (setq tmp (replace-match "" t t tmp)))
3263 (plist-put props 'txt tmp)))
3266 (defun org-agenda-export-csv-mapper (prop)
3267 (let ((res (plist-get org-agenda-info prop)))
3272 (t (prin1-to-string res))))
3273 (while (string-match "," res)
3274 (setq res (replace-match ";" t t res)))
3278 (defun org-store-agenda-views (&rest parameters)
3279 "Store agenda views."
3281 (eval (list 'org-batch-store-agenda-views)))
3284 (defmacro org-batch-store-agenda-views (&rest parameters)
3285 "Run all custom agenda commands that have a file argument."
3286 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3288 (dir default-directory)
3289 (pars (org-make-parameter-alist parameters))
3290 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3291 (save-window-excursion
3293 (setq cmd (pop cmds)
3294 thiscmdkey (car cmd)
3295 thiscmdcmd (cdr cmd)
3296 match (nth 2 thiscmdcmd)
3297 bufname (if org-agenda-sticky
3298 (or (and (stringp match)
3299 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3300 (format "*Org Agenda(%s)*" thiscmdkey))
3301 org-agenda-buffer-name)
3302 cmd-or-set (nth 2 cmd)
3303 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3304 files (nth (if (listp cmd-or-set) 4 5) cmd))
3305 (if (stringp files) (setq files (list files)))
3307 (org-eval-in-environment (append org-agenda-exporter-settings
3309 (org-agenda nil thiscmdkey))
3310 (set-buffer bufname)
3312 (org-eval-in-environment (append org-agenda-exporter-settings
3314 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3315 (and (get-buffer bufname)
3316 (kill-buffer bufname)))))))
3318 (defvar org-agenda-current-span nil
3319 "The current span used in the agenda view.") ; local variable in the agenda buffer
3320 (defun org-agenda-mark-header-line (pos)
3321 "Mark the line at POS as an agenda structure header."
3324 (put-text-property (point-at-bol) (point-at-eol)
3325 'org-agenda-structural-header t)
3326 (when org-agenda-title-append
3327 (put-text-property (point-at-bol) (point-at-eol)
3328 'org-agenda-title-append org-agenda-title-append))))
3330 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3331 (defvar org-agenda-write-buffer-name "Agenda View")
3332 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3333 "Write the current buffer (an agenda view) as a file.
3335 Depending on the extension of the file name, plain text (.txt),
3336 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3337 If the extension is .ics, translate visible agenda into iCalendar
3338 format. If the extension is .org, collect all subtrees
3339 corresponding to the agenda entries and add them in an .org file.
3341 With prefix argument OPEN, open the new file immediately. If
3342 NOSETTINGS is given, do not scope the settings of
3343 `org-agenda-exporter-settings' into the export commands. This is
3344 used when the settings have already been scoped and we do not
3345 wish to overrule other, higher priority settings. If
3346 AGENDA-BUFFER-NAME is provided, use this as the buffer name for
3347 the agenda to write."
3348 (interactive "FWrite agenda to file: \nP")
3349 (if (or (not (file-writable-p file))
3350 (and (file-exists-p file)
3351 (if (org-called-interactively-p 'any)
3352 (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
3353 (user-error "Cannot write agenda to file %s" file))
3354 (org-let (if nosettings nil org-agenda-exporter-settings)
3356 (save-window-excursion
3357 (let ((bs (copy-sequence (buffer-string))) beg content)
3359 (rename-buffer org-agenda-write-buffer-name t)
3360 (set-buffer-modified-p nil)
3362 (org-agenda-remove-marked-text 'invisible 'org-filtered)
3363 (run-hooks 'org-agenda-before-write-hook)
3365 ((org-bound-and-true-p org-mobile-creating-agendas)
3366 (org-mobile-write-agenda-for-mobile file))
3367 ((string-match "\\.org\\'" file)
3368 (let (content p m message-log-max)
3369 (goto-char (point-min))
3370 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3372 (setq m (get-text-property (point) 'org-hd-marker))
3374 (push (save-excursion
3375 (set-buffer (marker-buffer m))
3377 (org-copy-subtree 1 nil t t)
3382 (dolist (s content) (org-paste-subtree 1 s))
3384 (kill-buffer (current-buffer))
3385 (message "Org file written to %s" file)))
3386 ((string-match "\\.html?\\'" file)
3388 (set-buffer (htmlize-buffer (current-buffer)))
3389 (when org-agenda-export-html-style
3390 ;; replace <style> section with org-agenda-export-html-style
3391 (goto-char (point-min))
3392 (kill-region (- (search-forward "<style") 6)
3393 (search-forward "</style>"))
3394 (insert org-agenda-export-html-style))
3396 (kill-buffer (current-buffer))
3397 (message "HTML written to %s" file))
3398 ((string-match "\\.ps\\'" file)
3400 (ps-print-buffer-with-faces file)
3401 (message "Postscript written to %s" file))
3402 ((string-match "\\.pdf\\'" file)
3404 (ps-print-buffer-with-faces
3405 (concat (file-name-sans-extension file) ".ps"))
3406 (call-process "ps2pdf" nil nil nil
3408 (concat (file-name-sans-extension file) ".ps"))
3409 (expand-file-name file))
3410 (delete-file (concat (file-name-sans-extension file) ".ps"))
3411 (message "PDF written to %s" file))
3412 ((string-match "\\.ics\\'" file)
3413 (require 'ox-icalendar)
3414 (org-icalendar-export-current-agenda (expand-file-name file)))
3416 (let ((bs (buffer-string)))
3421 (kill-buffer (current-buffer))
3422 (message "Plain text written to %s" file))))))))
3423 (set-buffer (or agenda-bufname
3424 (and (org-called-interactively-p 'any) (buffer-name))
3425 org-agenda-buffer-name)))
3426 (when open (org-open-file file)))
3428 (defun org-agenda-remove-marked-text (property &optional value)
3429 "Delete all text marked with VALUE of PROPERTY.
3430 VALUE defaults to t."
3432 (setq value (or value t))
3433 (while (setq beg (text-property-any (point-min) (point-max)
3436 beg (or (next-single-property-change beg property)
3439 (defun org-agenda-add-entry-text ()
3440 "Add entry text to agenda lines.
3441 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3442 entry text following headings shown in the agenda.
3443 Drawers will be excluded, also the line with scheduling/deadline info."
3444 (when (and (> org-agenda-add-entry-text-maxlines 0)
3445 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3447 (goto-char (point-min))
3449 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3450 (beginning-of-line 2)
3451 (setq txt (org-agenda-get-some-entry-text
3452 m org-agenda-add-entry-text-maxlines " > "))
3454 (if (string-match "\\S-" txt)
3456 (or (eobp) (forward-char 1))))))))
3458 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3460 "Extract entry text from MARKER, at most N-LINES lines.
3461 This will ignore drawers etc, just get the text.
3462 If INDENT is given, prefix every line with this string. If KEEP is
3463 given, it is a list of symbols, defining stuff that should not be
3464 removed from the entry content. Currently only `planning' is allowed here."
3465 (let (txt drawer-re kwd-time-re ind)
3467 (with-current-buffer (marker-buffer marker)
3468 (if (not (derived-mode-p 'org-mode))
3475 (setq txt (buffer-substring
3476 (min (1+ (point)) (point-max))
3477 (progn (outline-next-heading) (point)))
3478 drawer-re org-drawer-regexp
3479 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3483 (when org-agenda-add-entry-text-descriptive-links
3484 (goto-char (point-min))
3485 (while (org-activate-bracket-links (point-max))
3486 (add-text-properties (match-beginning 0) (match-end 0)
3488 (goto-char (point-min))
3489 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3490 (set-text-properties (match-beginning 0) (match-end 0)
3492 (goto-char (point-min))
3493 (while (re-search-forward drawer-re nil t)
3496 (progn (re-search-forward
3497 "^[ \t]*:END:.*\n?" nil 'move)
3499 (unless (member 'planning keep)
3500 (goto-char (point-min))
3501 (while (re-search-forward kwd-time-re nil t)
3502 (replace-match "")))
3503 (goto-char (point-min))
3504 (when org-agenda-entry-text-exclude-regexps
3505 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3506 (while (setq re (pop re-list))
3507 (goto-char (point-min))
3508 (while (re-search-forward re nil t)
3509 (replace-match "")))))
3510 (goto-char (point-max))
3511 (skip-chars-backward " \t\n")
3512 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3514 ;; find and remove min common indentation
3515 (goto-char (point-min))
3516 (untabify (point-min) (point-max))
3517 (setq ind (org-get-indentation))
3519 (unless (looking-at "[ \t]*$")
3520 (setq ind (min ind (org-get-indentation))))
3521 (beginning-of-line 2))
3522 (goto-char (point-min))
3524 (unless (looking-at "[ \t]*$")
3525 (move-to-column ind)
3526 (delete-region (point-at-bol) (point)))
3527 (beginning-of-line 2))
3529 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3531 (goto-char (point-min))
3533 (while (and (not (eobp)) (re-search-forward "^" nil t))
3534 (replace-match indent t t)))
3535 (goto-char (point-min))
3536 (while (looking-at "[ \t]*\n") (replace-match ""))
3537 (goto-char (point-max))
3538 (when (> (org-current-line)
3540 (org-goto-line (1+ n-lines))
3542 (setq txt (buffer-substring (point-min) (point)))))))))
3545 (defun org-check-for-org-mode ()
3546 "Make sure current buffer is in org-mode. Error if not."
3547 (or (derived-mode-p 'org-mode)
3548 (error "Cannot execute org-mode agenda command on buffer in %s"
3551 ;;; Agenda prepare and finalize
3553 (defvar org-agenda-multi nil) ; dynamically scoped
3554 (defvar org-agenda-pre-window-conf nil)
3555 (defvar org-agenda-columns-active nil)
3556 (defvar org-agenda-name nil)
3557 (defvar org-agenda-tag-filter nil)
3558 (defvar org-agenda-category-filter nil)
3559 (defvar org-agenda-regexp-filter nil)
3560 (defvar org-agenda-effort-filter nil)
3561 (defvar org-agenda-top-headline-filter nil)
3562 (defvar org-agenda-tag-filter-preset nil
3563 "A preset of the tags filter used for secondary agenda filtering.
3564 This must be a list of strings, each string must be a single tag preceded
3566 This variable should not be set directly, but agenda custom commands can
3567 bind it in the options section. The preset filter is a global property of
3568 the entire agenda view. In a block agenda, it will not work reliably to
3569 define a filter for one of the individual blocks. You need to set it in
3570 the global options and expect it to be applied to the entire view.")
3572 (defvar org-agenda-category-filter-preset nil
3573 "A preset of the category filter used for secondary agenda filtering.
3574 This must be a list of strings, each string must be a single category
3575 preceded by \"+\" or \"-\".
3576 This variable should not be set directly, but agenda custom commands can
3577 bind it in the options section. The preset filter is a global property of
3578 the entire agenda view. In a block agenda, it will not work reliably to
3579 define a filter for one of the individual blocks. You need to set it in
3580 the global options and expect it to be applied to the entire view.")
3582 (defvar org-agenda-regexp-filter-preset nil
3583 "A preset of the regexp filter used for secondary agenda filtering.
3584 This must be a list of strings, each string must be a single regexp
3585 preceded by \"+\" or \"-\".
3586 This variable should not be set directly, but agenda custom commands can
3587 bind it in the options section. The preset filter is a global property of
3588 the entire agenda view. In a block agenda, it will not work reliably to
3589 define a filter for one of the individual blocks. You need to set it in
3590 the global options and expect it to be applied to the entire view.")
3592 (defvar org-agenda-effort-filter-preset nil
3593 "A preset of the effort condition used for secondary agenda filtering.
3594 This must be a list of strings, each string must be a single regexp
3595 preceded by \"+\" or \"-\".
3596 This variable should not be set directly, but agenda custom commands can
3597 bind it in the options section. The preset filter is a global property of
3598 the entire agenda view. In a block agenda, it will not work reliably to
3599 define a filter for one of the individual blocks. You need to set it in
3600 the global options and expect it to be applied to the entire view.")
3602 (defun org-agenda-use-sticky-p ()
3603 "Return non-nil if an agenda buffer named
3604 `org-agenda-buffer-name' exists and should be shown instead of
3605 generating a new one."
3607 ;; turned off by user
3609 ;; For multi-agenda buffer already exists
3610 (not org-agenda-multi)
3612 (get-buffer org-agenda-buffer-name)
3613 ;; C-u parameter is same as last call
3614 (with-current-buffer (get-buffer org-agenda-buffer-name)
3616 (equal current-prefix-arg
3617 org-agenda-last-prefix-arg)
3618 ;; In case user turned stickiness on, while having existing
3619 ;; Agenda buffer active, don't reuse that buffer, because it
3620 ;; does not have org variables local
3621 org-agenda-this-buffer-is-sticky))))
3623 (defun org-agenda-prepare-window (abuf filter-alist)
3624 "Setup agenda buffer in the window.
3625 ABUF is the buffer for the agenda window.
3626 FILTER-ALIST is an alist of filters we need to apply when
3627 `org-agenda-persistent-filter' is non-nil."
3628 (let* ((awin (get-buffer-window abuf)) wconf)
3630 ((equal (current-buffer) abuf) nil)
3631 (awin (select-window awin))
3632 ((not (setq wconf (current-window-configuration))))
3633 ((equal org-agenda-window-setup 'current-window)
3634 (org-pop-to-buffer-same-window abuf))
3635 ((equal org-agenda-window-setup 'other-window)
3636 (org-switch-to-buffer-other-window abuf))
3637 ((equal org-agenda-window-setup 'other-frame)
3638 (switch-to-buffer-other-frame abuf))
3639 ((eq org-agenda-window-setup 'only-window)
3640 (delete-other-windows)
3641 (org-pop-to-buffer-same-window abuf))
3642 ((equal org-agenda-window-setup 'reorganize-frame)
3643 (delete-other-windows)
3644 (org-switch-to-buffer-other-window abuf)))
3645 (setq org-agenda-tag-filter (cdr (assoc 'tag filter-alist)))
3646 (setq org-agenda-category-filter (cdr (assoc 'cat filter-alist)))
3647 (setq org-agenda-effort-filter (cdr (assoc 'effort filter-alist)))
3648 (setq org-agenda-regexp-filter (cdr (assoc 're filter-alist)))
3649 ;; Additional test in case agenda is invoked from within agenda
3650 ;; buffer via elisp link.
3651 (unless (equal (current-buffer) abuf)
3652 (org-pop-to-buffer-same-window abuf))
3653 (setq org-agenda-pre-window-conf
3654 (or wconf org-agenda-pre-window-conf))))
3656 (defun org-agenda-prepare (&optional name)
3657 (let ((filter-alist (if org-agenda-persistent-filter
3658 (with-current-buffer
3659 (get-buffer-create org-agenda-buffer-name)
3660 (list `(tag . ,org-agenda-tag-filter)
3661 `(re . ,org-agenda-regexp-filter)
3662 `(effort . ,org-agenda-effort-filter)
3663 `(cat . ,org-agenda-category-filter))))))
3664 (if (org-agenda-use-sticky-p)
3666 (put 'org-agenda-tag-filter :preset-filter nil)
3667 (put 'org-agenda-category-filter :preset-filter nil)
3668 (put 'org-agenda-regexp-filter :preset-filter nil)
3669 ;; Popup existing buffer
3670 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
3672 (message "Sticky Agenda buffer, use `r' to refresh")
3673 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3674 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3675 (setq org-todo-keywords-for-agenda nil)
3676 (put 'org-agenda-tag-filter :preset-filter
3677 org-agenda-tag-filter-preset)
3678 (put 'org-agenda-category-filter :preset-filter
3679 org-agenda-category-filter-preset)
3680 (put 'org-agenda-regexp-filter :preset-filter
3681 org-agenda-regexp-filter-preset)
3682 (put 'org-agenda-effort-filter :preset-filter
3683 org-agenda-effort-filter-preset)
3684 (if org-agenda-multi
3686 (setq buffer-read-only nil)
3687 (goto-char (point-max))
3688 (unless (or (bobp) org-agenda-compact-blocks
3689 (not org-agenda-block-separator))
3691 (if (stringp org-agenda-block-separator)
3692 org-agenda-block-separator
3693 (make-string (window-width) org-agenda-block-separator))
3695 (narrow-to-region (point) (point-max)))
3696 (setq org-done-keywords-for-agenda nil)
3697 ;; Setting any org variables that are in org-agenda-local-vars
3698 ;; list need to be done after the prepare call
3699 (org-agenda-prepare-window
3700 (get-buffer-create org-agenda-buffer-name) filter-alist)
3701 (setq buffer-read-only nil)
3702 (org-agenda-reset-markers)
3703 (let ((inhibit-read-only t)) (erase-buffer))
3705 (setq org-agenda-buffer (current-buffer))
3706 (setq org-agenda-contributing-files nil)
3707 (setq org-agenda-columns-active nil)
3708 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3709 (setq org-todo-keywords-for-agenda
3710 (org-uniquify org-todo-keywords-for-agenda))
3711 (setq org-done-keywords-for-agenda
3712 (org-uniquify org-done-keywords-for-agenda))
3713 (setq org-agenda-last-prefix-arg current-prefix-arg)
3714 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3715 (and name (not org-agenda-name)
3716 (setq-local org-agenda-name name)))
3717 (setq buffer-read-only nil))))
3719 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3720 (defun org-agenda-finalize ()
3721 "Finishing touch for the agenda buffer, called just before displaying it."
3722 (unless org-agenda-multi
3724 (let ((inhibit-read-only t))
3725 (goto-char (point-min))
3727 (while (org-activate-bracket-links (point-max))
3728 (add-text-properties (match-beginning 0) (match-end 0)
3731 (while (org-activate-plain-links (point-max))
3732 (add-text-properties (match-beginning 0) (match-end 0)
3734 (unless (eq org-agenda-remove-tags t)
3735 (org-agenda-align-tags))
3736 (unless org-agenda-with-colors
3737 (remove-text-properties (point-min) (point-max) '(face nil)))
3738 (if (and (boundp 'org-agenda-overriding-columns-format)
3739 org-agenda-overriding-columns-format)
3740 (setq-local org-agenda-overriding-columns-format
3741 org-agenda-overriding-columns-format))
3742 (if (and (boundp 'org-agenda-view-columns-initially)
3743 org-agenda-view-columns-initially)
3744 (org-agenda-columns))
3745 (when org-agenda-fontify-priorities
3746 (org-agenda-fontify-priorities))
3747 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3748 (org-agenda-dim-blocked-tasks))
3749 (org-agenda-mark-clocking-task)
3750 (when org-agenda-entry-text-mode
3751 (org-agenda-entry-text-hide)
3752 (org-agenda-entry-text-show))
3753 (if (and (functionp 'org-habit-insert-consistency-graphs)
3754 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3755 (org-habit-insert-consistency-graphs))
3756 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3757 (unless (or (eq org-agenda-show-inherited-tags 'always)
3758 (and (listp org-agenda-show-inherited-tags)
3759 (memq org-agenda-type org-agenda-show-inherited-tags))
3760 (and (eq org-agenda-show-inherited-tags t)
3761 (or (eq org-agenda-use-tag-inheritance t)
3762 (and (listp org-agenda-use-tag-inheritance)
3763 (not (memq org-agenda-type
3764 org-agenda-use-tag-inheritance))))))
3767 (goto-char (point-min))
3768 (while (equal (forward-line) 0)
3769 (when (setq mrk (get-text-property (point) 'org-hd-marker))
3770 (put-text-property (point-at-bol) (point-at-eol)
3771 'tags (org-with-point-at mrk
3773 (mapcar 'downcase (org-get-tags-at))))))))))
3774 (run-hooks 'org-agenda-finalize-hook)
3775 (when org-agenda-top-headline-filter
3776 (org-agenda-filter-top-headline-apply
3777 org-agenda-top-headline-filter))
3778 (when org-agenda-tag-filter
3779 (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
3780 (when (get 'org-agenda-tag-filter :preset-filter)
3781 (org-agenda-filter-apply
3782 (get 'org-agenda-tag-filter :preset-filter) 'tag t))
3783 (when org-agenda-category-filter
3784 (org-agenda-filter-apply org-agenda-category-filter 'category))
3785 (when (get 'org-agenda-category-filter :preset-filter)
3786 (org-agenda-filter-apply
3787 (get 'org-agenda-category-filter :preset-filter) 'category))
3788 (when org-agenda-regexp-filter
3789 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
3790 (when (get 'org-agenda-regexp-filter :preset-filter)
3791 (org-agenda-filter-apply
3792 (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
3793 (when org-agenda-effort-filter
3794 (org-agenda-filter-apply org-agenda-effort-filter 'effort))
3795 (when (get 'org-agenda-effort-filter :preset-filter)
3796 (org-agenda-filter-apply
3797 (get 'org-agenda-effort-filter :preset-filter) 'effort))
3798 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3800 (defun org-agenda-mark-clocking-task ()
3801 "Mark the current clock entry in the agenda if it is present."
3802 ;; We need to widen when `org-agenda-finalize' is called from
3803 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3804 (when (bound-and-true-p org-clock-current-task)
3807 (org-agenda-unmark-clocking-task)
3808 (when (marker-buffer org-clock-hd-marker)
3810 (goto-char (point-min))
3812 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3814 (when (equal (org-get-at-bol 'org-hd-marker)
3815 org-clock-hd-marker)
3816 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3817 (overlay-put ov 'type 'org-agenda-clocking)
3818 (overlay-put ov 'face 'org-agenda-clocking)
3819 (overlay-put ov 'help-echo
3820 "The clock is running in this item")))))))))
3822 (defun org-agenda-unmark-clocking-task ()
3823 "Unmark the current clocking task."
3825 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3826 (delete-overlay o)))
3827 (overlays-in (point-min) (point-max))))
3829 (defun org-agenda-fontify-priorities ()
3830 "Make highest priority lines bold, and lowest italic."
3832 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3833 (delete-overlay o)))
3834 (overlays-in (point-min) (point-max)))
3837 (goto-char (point-min))
3838 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3839 (setq h (or (get-char-property (point) 'org-highest-priority)
3840 org-highest-priority)
3841 l (or (get-char-property (point) 'org-lowest-priority)
3842 org-lowest-priority)
3843 p (string-to-char (match-string 1))
3844 b (match-beginning 0)
3845 e (if (eq org-agenda-fontify-priorities 'cookies)
3848 ov (make-overlay b e))
3852 (cond ((org-face-from-face-or-color
3854 (cdr (assoc p org-priority-faces))))
3855 ((and (listp org-agenda-fontify-priorities)
3856 (org-face-from-face-or-color
3858 (cdr (assoc p org-agenda-fontify-priorities)))))
3859 ((equal p l) 'italic)
3860 ((equal p h) 'bold))))
3861 (if special-face (list special-face 'org-priority) 'org-priority)))
3862 (overlay-put ov 'org-type 'org-priority)))))
3864 (defvar org-depend-tag-blocked)
3866 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3867 "Dim currently blocked TODOs in the agenda display.
3868 When INVISIBLE is non-nil, hide currently blocked TODO instead of
3871 (when (org-called-interactively-p 'interactive)
3872 (message "Dim or hide blocked tasks..."))
3873 (dolist (o (overlays-in (point-min) (point-max)))
3874 (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
3875 (delete-overlay o)))
3877 (let ((inhibit-read-only t)
3878 (org-depend-tag-blocked nil)
3879 org-blocked-by-checkboxes)
3880 (goto-char (point-min))
3881 (while (let ((pos (text-property-not-all
3882 (point) (point-max) 'todo-state nil)))
3883 (when pos (goto-char pos)))
3884 (setq org-blocked-by-checkboxes nil)
3885 (let ((marker (org-get-at-bol 'org-hd-marker)))
3886 (when (and (markerp marker)
3887 (with-current-buffer (marker-buffer marker)
3888 (save-excursion (goto-char marker)
3889 (org-entry-blocked-p))))
3890 ;; Entries blocked by checkboxes cannot be made invisible.
3891 ;; See `org-agenda-dim-blocked-tasks' for details.
3892 (let* ((really-invisible
3893 (and (not org-blocked-by-checkboxes)
3894 (or invisible (eq org-agenda-dim-blocked-tasks
3896 (ov (make-overlay (if really-invisible (line-end-position 0)
3897 (line-beginning-position))
3898 (line-end-position))))
3899 (if really-invisible (overlay-put ov 'invisible t)
3900 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3901 (overlay-put ov 'org-type 'org-blocked-todo))))
3903 (when (org-called-interactively-p 'interactive)
3904 (message "Dim or hide blocked tasks...done")))
3906 (defvar org-agenda-skip-function nil
3907 "Function to be called at each match during agenda construction.
3908 If this function returns nil, the current match should not be skipped.
3909 Otherwise, the function must return a position from where the search
3910 should be continued.
3911 This may also be a Lisp form, it will be evaluated.
3912 Never set this variable using `setq' or so, because then it will apply
3913 to all future agenda commands. If you do want a global skipping condition,
3914 use the option `org-agenda-skip-function-global' instead.
3915 The correct usage for `org-agenda-skip-function' is to bind it with
3916 `let' to scope it dynamically into the agenda-constructing command.
3917 A good way to set it is through options in `org-agenda-custom-commands'.")
3919 (defun org-agenda-skip ()
3920 "Throw to `:skip' in places that should be skipped.
3921 Also moves point to the end of the skipped region, so that search can
3922 continue from there."
3923 (let ((p (point-at-bol)) to)
3925 (save-excursion (goto-char p) (looking-at comment-start-skip))
3926 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3927 (get-text-property p :org-archived)
3928 (org-end-of-subtree t))
3929 (and org-agenda-skip-comment-trees
3930 (get-text-property p :org-comment)
3931 (org-end-of-subtree t))
3932 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3933 (org-agenda-skip-eval org-agenda-skip-function)))
3935 (org-in-src-block-p t))
3938 (defun org-agenda-skip-eval (form)
3939 "If FORM is a function or a list, call (or eval) it and return the result.
3940 `save-excursion' and `save-match-data' are wrapped around the call, so point
3941 and match data are returned to the previous state no matter what these
3945 (or (setq fp (functionp form))
3953 (defvar org-agenda-markers nil
3954 "List of all currently active markers created by `org-agenda'.")
3955 (defvar org-agenda-last-marker-time (org-float-time)
3956 "Creation time of the last agenda marker.")
3958 (defun org-agenda-new-marker (&optional pos)
3959 "Return a new agenda marker.
3960 Maker is at point, or at POS if non-nil. Org mode keeps a list of
3961 these markers and resets them when they are no longer in use."
3962 (let ((m (copy-marker (or pos (point)) t)))
3963 (setq org-agenda-last-marker-time (org-float-time))
3964 (if org-agenda-buffer
3965 (with-current-buffer org-agenda-buffer
3966 (push m org-agenda-markers))
3967 (push m org-agenda-markers))
3970 (defun org-agenda-reset-markers ()
3971 "Reset markers created by `org-agenda'."
3972 (while org-agenda-markers
3973 (move-marker (pop org-agenda-markers) nil)))
3975 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3976 "Save relative positions of markers in region.
3977 This check for agenda markers in all agenda buffers currently active."
3978 (dolist (buf (buffer-list))
3979 (with-current-buffer buf
3980 (when (eq major-mode 'org-agenda-mode)
3981 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3982 org-agenda-markers)))))
3986 (defun org-agenda-entry-text-show-here ()
3987 "Add some text from the entry as context to the current line."
3989 (setq m (org-get-at-bol 'org-hd-marker))
3990 (unless (marker-buffer m)
3991 (error "No marker points to an entry here"))
3992 (setq txt (concat "\n" (org-no-properties
3993 (org-agenda-get-some-entry-text
3994 m org-agenda-entry-text-maxlines
3995 org-agenda-entry-text-leaders))))
3996 (when (string-match "\\S-" txt)
3997 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3998 (overlay-put o 'evaporate t)
3999 (overlay-put o 'org-overlay-type 'agenda-entry-content)
4000 (overlay-put o 'after-string txt))))
4002 (defun org-agenda-entry-text-show ()
4003 "Add entry context for all agenda lines."
4006 (goto-char (point-max))
4007 (beginning-of-line 1)
4009 (when (org-get-at-bol 'org-hd-marker)
4010 (org-agenda-entry-text-show-here))
4011 (beginning-of-line 0))))
4013 (defun org-agenda-entry-text-hide ()
4014 "Remove any shown entry context."
4017 (if (eq (overlay-get o 'org-overlay-type)
4018 'agenda-entry-content)
4019 (progn (delete-overlay o) t)))
4020 (overlays-in (point-min) (point-max)))))
4022 (defun org-agenda-get-day-face (date)
4023 "Return the face DATE should be displayed with."
4024 (cond ((and (functionp org-agenda-day-face-function)
4025 (funcall org-agenda-day-face-function date)))
4026 ((org-agenda-today-p date) 'org-agenda-date-today)
4027 ((memq (calendar-day-of-week date) org-agenda-weekend-days)
4028 'org-agenda-date-weekend)
4029 (t 'org-agenda-date)))
4033 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
4034 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
4036 (defun org-timeline (&optional dotodo)
4037 "Show a time-sorted view of the entries in the current org file.
4038 Only entries with a time stamp of today or later will be listed. With
4039 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
4040 under the current date.
4041 If the buffer contains an active region, only check the region for
4045 (org-agenda-show-log-scoped org-agenda-show-log)
4046 (org-agenda-show-log org-agenda-show-log-scoped)
4047 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
4049 (date (calendar-current-date))
4050 (beg (if (org-region-active-p) (region-beginning) (point-min)))
4051 (end (if (org-region-active-p) (region-end) (point-max)))
4052 (day-numbers (org-get-all-dates
4054 t org-agenda-show-log-scoped ; always include today
4055 org-timeline-show-empty-dates))
4056 (org-deadline-warning-days 0)
4057 (org-agenda-only-exact-dates t)
4062 (setq org-agenda-redo-command
4064 (list (list 'org-agenda-show-log 'org-agenda-show-log))
4065 (list 'org-switch-to-buffer-other-window (current-buffer))
4066 (list 'org-timeline (list 'quote dotodo))))
4067 (put 'org-agenda-redo-command 'org-lprops nil)
4069 ;; Remove past dates from the list of dates.
4070 (setq day-numbers (delq nil (mapcar (lambda(x)
4071 (if (>= x today) x nil))
4073 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
4074 (org-compile-prefix-format 'timeline)
4075 (org-set-sorting-strategy 'timeline)
4076 (if org-agenda-show-log-scoped (push :closed args))
4077 (push :timestamp args)
4078 (push :deadline args)
4079 (push :scheduled args)
4081 (if dotodo (push :todo args))
4082 (insert "Timeline of file " entry "\n")
4083 (add-text-properties (point-min) (point)
4084 (list 'face 'org-agenda-structure))
4085 (org-agenda-mark-header-line (point-min))
4086 (while (setq d (pop day-numbers))
4087 (if (and (listp d) (eq (car d) :omitted))
4090 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
4091 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
4092 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
4093 (if (and (>= d today)
4098 (insert (make-string 79 ?-) "\n")))
4099 (setq date (calendar-gregorian-from-absolute d))
4101 (setq rtn (and (not emptyp)
4102 (apply 'org-agenda-get-day-entries entry
4104 (if (or rtn (equal d today) org-timeline-show-empty-dates)
4107 (if (stringp org-agenda-format-date)
4108 (format-time-string org-agenda-format-date
4109 (org-time-from-absolute date))
4110 (funcall org-agenda-format-date date))
4112 (put-text-property s (1- (point)) 'face
4113 (org-agenda-get-day-face date))
4114 (put-text-property s (1- (point)) 'org-date-line t)
4115 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4117 (put-text-property s (1- (point)) 'org-today t))
4118 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
4119 (put-text-property s (1- (point)) 'day d)))))
4120 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
4122 (add-text-properties
4123 (point-min) (point-max)
4124 `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
4125 (org-agenda-finalize)
4126 (setq buffer-read-only t)))
4128 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
4129 "Return a list of all relevant day numbers from BEG to END buffer positions.
4130 If NO-RANGES is non-nil, include only the start and end dates of a range,
4131 not every single day in the range. If FORCE-TODAY is non-nil, make
4132 sure that TODAY is included in the list. If INACTIVE is non-nil, also
4133 inactive time stamps (those in square brackets) are included.
4134 When EMPTY is non-nil, also include days without any entries."
4136 (if pre-re pre-re "")
4137 (if inactive org-ts-regexp-both org-ts-regexp)))
4138 dates dates1 date day day1 day2 ts1 ts2 pos)
4140 (setq dates (list (org-today))))
4143 (while (re-search-forward re end t)
4144 (setq day (time-to-days (org-time-string-to-time
4145 (substring (match-string 1) 0 10)
4146 (current-buffer) (match-beginning 0))))
4147 (or (memq day dates) (push day dates)))
4150 (while (re-search-forward org-tr-regexp end t)
4151 (setq pos (match-beginning 0))
4152 (setq ts1 (substring (match-string 1) 0 10)
4153 ts2 (substring (match-string 2) 0 10)
4154 day1 (time-to-days (org-time-string-to-time
4155 ts1 (current-buffer) pos))
4156 day2 (time-to-days (org-time-string-to-time
4157 ts2 (current-buffer) pos)))
4158 (while (< (setq day1 (1+ day1)) day2)
4159 (or (memq day1 dates) (push day1 dates)))))
4160 (setq dates (sort dates '<))
4162 (while (setq day (pop dates))
4163 (setq day2 (car dates))
4165 (when (and day2 empty)
4166 (if (or (eq empty t)
4167 (and (numberp empty) (<= (- day2 day) empty)))
4168 (while (< (setq day (1+ day)) day2)
4169 (push (list day) dates1))
4170 (push (cons :omitted (- day2 day)) dates1))))
4171 (setq dates (nreverse dates1)))
4174 ;;; Agenda Daily/Weekly
4176 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4177 "Start day for the agenda view.
4178 Custom commands can set this variable in the options section.
4179 This is usually a string like \"2007-11-01\", \"+2d\" or any other
4180 input allowed when reading a date through the Org calendar.
4181 See the docstring of `org-read-date' for details.")
4182 (defvar org-starting-day nil) ; local variable in the agenda buffer
4183 (defvar org-arg-loc nil) ; local variable
4185 (defvar org-agenda-buffer-tmp-name nil)
4187 (defun org-agenda-list (&optional arg start-day span with-hour)
4188 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4189 The view will be for the current day or week, but from the overview buffer
4190 you will be able to go to other days/weeks.
4192 With a numeric prefix argument in an interactive call, the agenda will
4193 span ARG days. Lisp programs should instead specify SPAN to change
4194 the number of days. SPAN defaults to `org-agenda-span'.
4196 START-DAY defaults to TODAY, or to the most recent match for the weekday
4197 given in `org-agenda-start-on-weekday'.
4199 When WITH-HOUR is non-nil, only include scheduled and deadline
4200 items if they have an hour specification like [h]h:mm."
4202 (if org-agenda-overriding-arguments
4203 (setq arg (car org-agenda-overriding-arguments)
4204 start-day (nth 1 org-agenda-overriding-arguments)
4205 span (nth 2 org-agenda-overriding-arguments)))
4206 (if (and (integerp arg) (> arg 0))
4207 (setq span arg arg nil))
4209 (setq org-agenda-buffer-name
4210 (or org-agenda-buffer-tmp-name
4211 (if org-agenda-sticky
4212 (cond ((and org-keys (stringp org-match))
4213 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4215 (format "*Org Agenda(%s)*" org-keys))
4216 (t "*Org Agenda(a)*")))
4217 org-agenda-buffer-name))
4218 (org-agenda-prepare "Day/Week")
4219 (setq start-day (or start-day org-agenda-start-day))
4220 (if (stringp start-day)
4221 ;; Convert to an absolute day number
4222 (setq start-day (time-to-days (org-read-date nil t start-day))))
4223 (org-compile-prefix-format 'agenda)
4224 (org-set-sorting-strategy 'agenda)
4225 (let* ((span (org-agenda-ndays-to-span
4226 (or span org-agenda-ndays org-agenda-span)))
4228 (sd (or start-day today))
4229 (ndays (org-agenda-span-to-ndays span sd))
4230 (org-agenda-start-on-weekday
4231 (if (or (eq ndays 7) (eq ndays 14))
4232 org-agenda-start-on-weekday))
4233 (thefiles (org-agenda-files nil 'ifmode))
4235 (start (if (or (null org-agenda-start-on-weekday)
4238 (let* ((nt (calendar-day-of-week
4239 (calendar-gregorian-from-absolute sd)))
4240 (n1 org-agenda-start-on-weekday)
4242 (- sd (+ (if (< d 0) 7 0) d)))))
4243 (day-numbers (list start))
4245 (inhibit-redisplay (not debug-on-error))
4246 (org-agenda-show-log-scoped org-agenda-show-log)
4247 s e rtn rtnall file date d start-pos end-pos todayp
4248 clocktable-start clocktable-end filter)
4249 (setq org-agenda-redo-command
4250 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
4251 (dotimes (n (1- ndays))
4252 (push (1+ (car day-numbers)) day-numbers))
4253 (setq day-numbers (nreverse day-numbers))
4254 (setq clocktable-start (car day-numbers)
4255 clocktable-end (1+ (or (org-last day-numbers) 0)))
4256 (setq-local org-starting-day (car day-numbers))
4257 (setq-local org-arg-loc arg)
4258 (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
4259 (unless org-agenda-compact-blocks
4260 (let* ((d1 (car day-numbers))
4261 (d2 (org-last day-numbers))
4262 (w1 (org-days-to-iso-week d1))
4263 (w2 (org-days-to-iso-week d2)))
4265 (if org-agenda-overriding-header
4266 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4267 nil 'face 'org-agenda-structure) "\n")
4268 (insert (org-agenda-span-name span)
4270 (if (< (- d2 d1) 350)
4272 (format " (W%02d)" w1)
4273 (format " (W%02d-W%02d)" w1 w2))
4276 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4278 (org-agenda-mark-header-line s))
4279 (while (setq d (pop day-numbers))
4280 (setq date (calendar-gregorian-from-absolute d)
4282 (if (or (setq todayp (= d today))
4283 (and (not start-pos) (= d sd)))
4284 (setq start-pos (point))
4285 (if (and start-pos (not end-pos))
4286 (setq end-pos (point))))
4287 (setq files thefiles
4289 (while (setq file (pop files))
4291 (org-check-agenda-file file)
4292 (let ((org-agenda-entry-types org-agenda-entry-types))
4293 ;; Starred types override non-starred equivalents
4294 (when (member :deadline* org-agenda-entry-types)
4295 (setq org-agenda-entry-types
4296 (delq :deadline org-agenda-entry-types)))
4297 (when (member :scheduled* org-agenda-entry-types)
4298 (setq org-agenda-entry-types
4299 (delq :scheduled org-agenda-entry-types)))
4302 (when (member :deadline org-agenda-entry-types)
4303 (setq org-agenda-entry-types
4304 (delq :deadline org-agenda-entry-types))
4305 (push :deadline* org-agenda-entry-types))
4306 (when (member :scheduled org-agenda-entry-types)
4307 (setq org-agenda-entry-types
4308 (delq :scheduled org-agenda-entry-types))
4309 (push :scheduled* org-agenda-entry-types)))
4310 (unless org-agenda-include-deadlines
4311 (setq org-agenda-entry-types
4312 (delq :deadline* (delq :deadline org-agenda-entry-types))))
4314 ((memq org-agenda-show-log-scoped '(only clockcheck))
4315 (setq rtn (org-agenda-get-day-entries
4316 file date :closed)))
4317 (org-agenda-show-log-scoped
4318 (setq rtn (apply 'org-agenda-get-day-entries
4320 (append '(:closed) org-agenda-entry-types))))
4322 (setq rtn (apply 'org-agenda-get-day-entries
4324 org-agenda-entry-types)))))
4325 (setq rtnall (append rtnall rtn)))) ;; all entries
4326 (if org-agenda-include-diary
4327 (let ((org-agenda-search-headline-for-time t))
4328 (require 'diary-lib)
4329 (setq rtn (org-get-entries-from-diary date))
4330 (setq rtnall (append rtnall rtn))))
4331 (if (or rtnall org-agenda-show-all-dates)
4333 (setq day-cnt (1+ day-cnt))
4335 (if (stringp org-agenda-format-date)
4336 (format-time-string org-agenda-format-date
4337 (org-time-from-absolute date))
4338 (funcall org-agenda-format-date date))
4340 (put-text-property s (1- (point)) 'face
4341 (org-agenda-get-day-face date))
4342 (put-text-property s (1- (point)) 'org-date-line t)
4343 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4344 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4346 (put-text-property s (1- (point)) 'org-today t))
4348 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4349 (if rtnall (insert ;; all entries
4350 (org-agenda-finalize-entries rtnall 'agenda)
4352 (put-text-property s (1- (point)) 'day d)
4353 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4354 (when (and org-agenda-clockreport-mode clocktable-start)
4355 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4356 ;; the above line is to ensure the restricted range!
4357 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4359 (setq p (org-plist-delete p :block))
4360 (setq p (plist-put p :tstart clocktable-start))
4361 (setq p (plist-put p :tend clocktable-end))
4362 (setq p (plist-put p :scope 'agenda))
4363 (setq tbl (apply 'org-clock-get-clocktable p))
4365 (goto-char (point-min))
4366 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4367 (unless (and (pos-visible-in-window-p (point-min))
4368 (pos-visible-in-window-p (point-max)))
4369 (goto-char (1- (point-max)))
4371 (if (not (pos-visible-in-window-p (or start-pos 1)))
4373 (goto-char (or start-pos 1))
4375 (goto-char (or start-pos 1))
4376 (add-text-properties (point-min) (point-max)
4377 `(org-agenda-type agenda
4378 org-last-args (,arg ,start-day ,span)
4379 org-redo-cmd ,org-agenda-redo-command
4380 org-series-cmd ,org-cmd))
4381 (if (eq org-agenda-show-log-scoped 'clockcheck)
4382 (org-agenda-show-clocking-issues))
4383 (org-agenda-finalize)
4384 (setq buffer-read-only t)
4387 (defun org-agenda-ndays-to-span (n)
4388 "Return a span symbol for a span of N days, or N if none matches."
4389 (cond ((symbolp n) n)
4392 ((= n 14) 'fortnight)
4395 (defun org-agenda-span-to-ndays (span &optional start-day)
4396 "Return ndays from SPAN, possibly starting at START-DAY.
4397 START-DAY is an absolute time value."
4398 (cond ((numberp span) span)
4401 ((eq span 'fortnight) 14)
4403 (let ((date (calendar-gregorian-from-absolute start-day)))
4404 (calendar-last-day-of-month (car date) (caddr date))))
4406 (let ((date (calendar-gregorian-from-absolute start-day)))
4407 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4409 (defun org-agenda-span-name (span)
4410 "Return a SPAN name."
4414 (capitalize (symbol-name span))
4415 (format "%d days" span))))
4417 ;;; Agenda word search
4419 (defvar org-agenda-search-history nil)
4421 (defvar org-search-syntax-table nil
4422 "Special syntax table for org-mode search.
4423 In this table, we have single quotes not as word constituents, to
4424 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4426 (defvar org-mode-syntax-table) ; From org.el
4427 (defun org-search-syntax-table ()
4428 (unless org-search-syntax-table
4429 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4430 (modify-syntax-entry ?' "." org-search-syntax-table)
4431 (modify-syntax-entry ?` "." org-search-syntax-table))
4432 org-search-syntax-table)
4434 (defvar org-agenda-last-search-view-search-was-boolean nil)
4437 (defun org-search-view (&optional todo-only string edit-at)
4438 "Show all entries that contain a phrase or words or regular expressions.
4440 With optional prefix argument TODO-ONLY, only consider entries that are
4441 TODO entries. The argument STRING can be used to pass a default search
4442 string into this function. If EDIT-AT is non-nil, it means that the
4443 user should get a chance to edit this string, with cursor at position
4446 The search string can be viewed either as a phrase that should be found as
4447 is, or it can be broken into a number of snippets, each of which must match
4448 in a Boolean way to select an entry. The default depends on the variable
4449 `org-agenda-search-view-always-boolean'.
4450 Even if this is turned off (the default) you can always switch to
4451 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4453 The default is a direct search of the whole phrase, where each space in
4454 the search string can expand to an arbitrary amount of whitespace,
4457 If using a Boolean search, the search string is split on whitespace and
4458 each snippet is searched separately, with logical AND to select an entry.
4459 Words prefixed with a minus must *not* occur in the entry. Words without
4460 a prefix or prefixed with a plus must occur in the entry. Matching is
4461 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4462 match whole words, not parts of a word) if
4463 `org-agenda-search-view-force-full-words' is set (default is nil).
4465 Boolean search snippets enclosed by curly braces are interpreted as
4466 regular expressions that must or (when preceded with \"-\") must not
4467 match in the entry. Snippets enclosed into double quotes will be taken
4468 as a whole, to include whitespace.
4470 - If the search string starts with an asterisk, search only in headlines.
4471 - If (possibly after the leading star) the search string starts with an
4472 exclamation mark, this also means to look at TODO entries only, an effect
4473 that can also be achieved with a prefix argument.
4474 - If (possibly after star and exclamation mark) the search string starts
4475 with a colon, this will mean that the (non-regexp) snippets of the
4476 Boolean search must match as full words.
4478 This command searches the agenda files, and in addition the files listed
4479 in `org-agenda-text-search-extra-files'."
4481 (if org-agenda-overriding-arguments
4482 (setq todo-only (car org-agenda-overriding-arguments)
4483 string (nth 1 org-agenda-overriding-arguments)
4484 edit-at (nth 2 org-agenda-overriding-arguments)))
4485 (let* ((props (list 'face nil
4486 'done-face 'org-agenda-done
4487 'org-not-done-regexp org-not-done-regexp
4488 'org-todo-regexp org-todo-regexp
4489 'org-complex-heading-regexp org-complex-heading-regexp
4490 'mouse-face 'highlight
4491 'help-echo (format "mouse-2 or RET jump to location")))
4492 (full-words org-agenda-search-view-force-full-words)
4493 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4494 regexp rtn rtnall files file pos inherited-tags
4495 marker category level tags c neg re boolean
4496 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4497 (unless (and (not edit-at)
4499 (string-match "\\S-" string))
4500 (setq string (read-string
4501 (if org-agenda-search-view-always-boolean
4502 "[+-]Word/{Regexp} ...: "
4503 "Phrase or [+-]Word/{Regexp} ...: ")
4505 ((integerp edit-at) (cons string edit-at))
4507 'org-agenda-search-history)))
4509 (if org-agenda-sticky
4510 (setq org-agenda-buffer-name
4511 (if (stringp string)
4512 (format "*Org Agenda(%s:%s)*"
4513 (or org-keys (or (and todo-only "S") "s")) string)
4514 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4515 (org-agenda-prepare "SEARCH")
4516 (org-compile-prefix-format 'search)
4517 (org-set-sorting-strategy 'search)
4518 (setq org-agenda-redo-command
4519 (list 'org-search-view (if todo-only t nil)
4520 (list 'if 'current-prefix-arg nil string)))
4521 (setq org-agenda-query-string string)
4522 (if (equal (string-to-char string) ?*)
4524 words (substring string 1))
4525 (setq words string))
4526 (when (equal (string-to-char words) ?!)
4528 words (substring words 1)))
4529 (when (equal (string-to-char words) ?:)
4531 words (substring words 1)))
4532 (if (or org-agenda-search-view-always-boolean
4533 (member (string-to-char words) '(?- ?+ ?\{)))
4535 (setq words (org-split-string words))
4537 (while (setq w (pop words))
4538 (while (and (string-match "\\\\\\'" w) words)
4539 (setq w (concat (substring w 0 -1) " " (pop words))))
4541 (setq words (nreverse www) www nil)
4542 (while (setq w (pop words))
4543 (when (and (string-match "\\`[-+]?{" w)
4544 (not (string-match "}\\'" w)))
4545 (while (and words (not (string-match "}\\'" (car words))))
4546 (setq w (concat w " " (pop words))))
4547 (setq w (concat w " " (pop words))))
4549 (setq words (nreverse www)))
4550 (setq org-agenda-last-search-view-search-was-boolean boolean)
4553 (while (setq w (pop words))
4554 (if (or (equal (substring w 0 1) "\"")
4555 (and (> (length w) 1)
4556 (member (substring w 0 1) '("+" "-"))
4557 (equal (substring w 1 2) "\"")))
4558 (while (and words (not (equal (substring w -1) "\"")))
4559 (setq w (concat w " " (pop words)))))
4560 (and (string-match "\\`\\([-+]?\\)\"" w)
4561 (setq w (replace-match "\\1" nil nil w)))
4562 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4564 (setq words (nreverse wds))))
4567 (setq c (string-to-char w))
4569 (setq neg t w (substring w 1))
4571 (setq neg nil w (substring w 1))
4573 (if (string-match "\\`{.*}\\'" w)
4574 (setq re (substring w 1 -1))
4576 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4577 (setq re (regexp-quote (downcase w)))))
4578 (if neg (push re regexps-) (push re regexps+)))
4580 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4582 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4584 (setq regexp org-outline-regexp-bol)
4585 (setq regexp (pop regexps+))
4586 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4588 (setq files (org-agenda-files nil 'ifmode))
4589 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4590 (pop org-agenda-text-search-extra-files)
4591 (setq files (org-add-archive-files files)))
4592 (setq files (append files org-agenda-text-search-extra-files)
4594 (while (setq file (pop files))
4597 (org-check-agenda-file file)
4598 (setq buffer (if (file-exists-p file)
4599 (org-get-agenda-file-buffer file)
4600 (error "No such file %s" file)))
4602 ;; If file does not exist, make sure an error message is sent
4603 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4605 (with-current-buffer buffer
4606 (with-syntax-table (org-search-syntax-table)
4607 (unless (derived-mode-p 'org-mode)
4608 (error "Agenda file %s is not in `org-mode'" file))
4609 (let ((case-fold-search t))
4612 (if (eq buffer org-agenda-restrict)
4613 (narrow-to-region org-agenda-restrict-begin
4614 org-agenda-restrict-end)
4616 (goto-char (point-min))
4617 (unless (or (org-at-heading-p)
4618 (outline-next-heading))
4619 (throw 'nextfile t))
4620 (goto-char (max (point-min) (1- (point))))
4621 (while (re-search-forward regexp nil t)
4622 (org-back-to-heading t)
4623 (while (and (not (zerop org-agenda-search-view-max-outline-level))
4624 (> (org-reduced-level (org-outline-level))
4625 org-agenda-search-view-max-outline-level)
4627 (org-back-to-heading t)))
4628 (skip-chars-forward "* ")
4629 (setq beg (point-at-bol)
4632 (outline-next-heading)
4633 (while (and (not (zerop org-agenda-search-view-max-outline-level))
4634 (> (org-reduced-level (org-outline-level))
4635 org-agenda-search-view-max-outline-level)
4637 (outline-next-heading)))
4643 (setq str (buffer-substring-no-properties
4645 (if hdl-only (point-at-eol) end)))
4646 (mapc (lambda (wr) (when (string-match wr str)
4647 (goto-char (1- end))
4650 (mapc (lambda (wr) (unless (string-match wr str)
4651 (goto-char (1- end))
4654 (cons (concat "^\\*+[ \t]+"
4655 org-not-done-regexp)
4659 (setq marker (org-agenda-new-marker (point))
4660 category (org-get-category)
4661 level (make-string (org-reduced-level (org-outline-level)) ? )
4663 (or (eq org-agenda-show-inherited-tags 'always)
4664 (and (listp org-agenda-show-inherited-tags)
4665 (memq 'todo org-agenda-show-inherited-tags))
4666 (and (eq org-agenda-show-inherited-tags t)
4667 (or (eq org-agenda-use-tag-inheritance t)
4668 (memq 'todo org-agenda-use-tag-inheritance))))
4669 tags (org-get-tags-at nil (not inherited-tags))
4670 txt (org-agenda-format-item
4672 (buffer-substring-no-properties
4673 beg1 (point-at-eol))
4674 level category tags t))
4675 (org-add-props txt props
4676 'org-marker marker 'org-hd-marker marker
4677 'org-todo-regexp org-todo-regexp
4679 'org-complex-heading-regexp org-complex-heading-regexp
4683 (goto-char (1- end))))))))))
4684 (setq rtn (nreverse ee))
4685 (setq rtnall (append rtnall rtn)))
4686 (if org-agenda-overriding-header
4687 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4688 nil 'face 'org-agenda-structure) "\n")
4689 (insert "Search words: ")
4690 (add-text-properties (point-min) (1- (point))
4691 (list 'face 'org-agenda-structure))
4693 (insert string "\n")
4694 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4696 (unless org-agenda-multi
4697 (insert (substitute-command-keys "\
4698 Press `\\[org-agenda-manipulate-query-add]', \
4699 `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
4700 `\\[org-agenda-manipulate-query-add-re]', \
4701 `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
4702 `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
4703 (add-text-properties pos (1- (point))
4704 (list 'face 'org-agenda-structure))))
4705 (org-agenda-mark-header-line (point-min))
4707 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4708 (goto-char (point-min))
4709 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4710 (add-text-properties (point-min) (point-max)
4711 `(org-agenda-type search
4712 org-last-args (,todo-only ,string ,edit-at)
4713 org-redo-cmd ,org-agenda-redo-command
4714 org-series-cmd ,org-cmd))
4715 (org-agenda-finalize)
4716 (setq buffer-read-only t))))
4718 ;;; Agenda TODO list
4720 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4721 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4723 (if (or (equal keywords "ALL") (not keywords))
4724 (propertize "ALL" 'face 'warning)
4727 (propertize kw 'face (org-get-todo-face kw)))
4728 (org-split-string keywords "|")
4732 (defvar org-select-this-todo-keyword nil)
4733 (defvar org-last-arg nil)
4736 (defun org-todo-list (&optional arg)
4737 "Show all (not done) TODO entries from all agenda file in a single list.
4738 The prefix arg can be used to select a specific TODO keyword and limit
4739 the list to these. When using \\[universal-argument], you will be prompted
4740 for a keyword. A numeric prefix directly selects the Nth keyword in
4741 `org-todo-keywords-1'."
4743 (if org-agenda-overriding-arguments
4744 (setq arg org-agenda-overriding-arguments))
4745 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4746 (let* ((today (org-today))
4747 (date (calendar-gregorian-from-absolute today))
4748 (kwds org-todo-keywords-for-agenda)
4749 (completion-ignore-case t)
4750 (org-select-this-todo-keyword
4751 (if (stringp arg) arg
4752 (and arg (integerp arg) (> arg 0)
4753 (nth (1- arg) kwds))))
4754 rtn rtnall files file pos)
4755 (when (equal arg '(4))
4756 (setq org-select-this-todo-keyword
4757 (completing-read "Keyword (or KWD1|K2D2|...): "
4758 (mapcar #'list kwds) nil nil)))
4759 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4761 (if org-agenda-sticky
4762 (setq org-agenda-buffer-name
4763 (if (stringp org-select-this-todo-keyword)
4764 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4765 org-select-this-todo-keyword)
4766 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4767 (org-agenda-prepare "TODO")
4768 (org-compile-prefix-format 'todo)
4769 (org-set-sorting-strategy 'todo)
4770 (setq org-agenda-redo-command
4771 `(org-todo-list (or (and (numberp current-prefix-arg)
4773 ,org-select-this-todo-keyword
4774 current-prefix-arg ,arg)))
4775 (setq files (org-agenda-files nil 'ifmode)
4777 (while (setq file (pop files))
4779 (org-check-agenda-file file)
4780 (setq rtn (org-agenda-get-day-entries file date :todo))
4781 (setq rtnall (append rtnall rtn))))
4782 (if org-agenda-overriding-header
4783 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4784 nil 'face 'org-agenda-structure) "\n")
4785 (insert "Global list of TODO items of type: ")
4786 (add-text-properties (point-min) (1- (point))
4787 (list 'face 'org-agenda-structure
4790 (or org-select-this-todo-keyword "ALL"))))
4791 (org-agenda-mark-header-line (point-min))
4792 (insert (org-agenda-propertize-selected-todo-keywords
4793 org-select-this-todo-keyword))
4795 (unless org-agenda-multi
4796 (insert (substitute-command-keys "Available with \
4797 `N \\[org-agenda-redo]': (0)[ALL]"))
4800 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4801 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4806 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4807 (org-agenda-mark-header-line (point-min))
4809 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4810 (goto-char (point-min))
4811 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4812 (add-text-properties (point-min) (point-max)
4813 `(org-agenda-type todo
4815 org-redo-cmd ,org-agenda-redo-command
4816 org-series-cmd ,org-cmd))
4817 (org-agenda-finalize)
4818 (setq buffer-read-only t))))
4820 ;;; Agenda tags match
4823 (defun org-tags-view (&optional todo-only match)
4824 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4825 The prefix arg TODO-ONLY limits the search to TODO entries."
4827 (if org-agenda-overriding-arguments
4828 (setq todo-only (car org-agenda-overriding-arguments)
4829 match (nth 1 org-agenda-overriding-arguments)))
4830 (let* ((org-tags-match-list-sublevels
4831 org-tags-match-list-sublevels)
4832 (completion-ignore-case t)
4833 rtn rtnall files file pos matcher
4835 (when (and (stringp match) (not (string-match "\\S-" match)))
4838 (if org-agenda-sticky
4839 (setq org-agenda-buffer-name
4841 (format "*Org Agenda(%s:%s)*"
4842 (or org-keys (or (and todo-only "M") "m")) match)
4843 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4844 ;; Prepare agendas (and `org-tag-alist-for-agenda') before
4845 ;; expanding tags within `org-make-tags-matcher'
4846 (org-agenda-prepare (concat "TAGS " match))
4847 (setq org--matcher-tags-todo-only todo-only
4848 matcher (org-make-tags-matcher match)
4850 matcher (cdr matcher))
4851 (org-compile-prefix-format 'tags)
4852 (org-set-sorting-strategy 'tags)
4853 (setq org-agenda-query-string match)
4854 (setq org-agenda-redo-command
4855 (list 'org-tags-view
4856 `(quote ,org--matcher-tags-todo-only)
4857 `(if current-prefix-arg nil ,org-agenda-query-string)))
4858 (setq files (org-agenda-files nil 'ifmode)
4860 (while (setq file (pop files))
4862 (org-check-agenda-file file)
4863 (setq buffer (if (file-exists-p file)
4864 (org-get-agenda-file-buffer file)
4865 (error "No such file %s" file)))
4867 ;; If file does not exist, error message to agenda
4869 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4870 rtnall (append rtnall rtn))
4871 (with-current-buffer buffer
4872 (unless (derived-mode-p 'org-mode)
4873 (error "Agenda file %s is not in `org-mode'" file))
4876 (if (eq buffer org-agenda-restrict)
4877 (narrow-to-region org-agenda-restrict-begin
4878 org-agenda-restrict-end)
4880 (setq rtn (org-scan-tags 'agenda
4882 org--matcher-tags-todo-only))
4883 (setq rtnall (append rtnall rtn))))))))
4884 (if org-agenda-overriding-header
4885 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4886 nil 'face 'org-agenda-structure) "\n")
4887 (insert "Headlines with TAGS match: ")
4888 (add-text-properties (point-min) (1- (point))
4889 (list 'face 'org-agenda-structure
4891 (concat "Match: " match)))
4894 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4896 (unless org-agenda-multi
4897 (insert (substitute-command-keys
4898 "Press `\\[universal-argument] \\[org-agenda-redo]' \
4899 to search again with new search string\n")))
4900 (add-text-properties pos (1- (point))
4901 (list 'face 'org-agenda-structure)))
4902 (org-agenda-mark-header-line (point-min))
4904 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4905 (goto-char (point-min))
4906 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4907 (add-text-properties
4908 (point-min) (point-max)
4909 `(org-agenda-type tags
4910 org-last-args (,org--matcher-tags-todo-only ,match)
4911 org-redo-cmd ,org-agenda-redo-command
4912 org-series-cmd ,org-cmd))
4913 (org-agenda-finalize)
4914 (setq buffer-read-only t))))
4916 ;;; Agenda Finding stuck projects
4918 (defvar org-agenda-skip-regexp nil
4919 "Regular expression used in skipping subtrees for the agenda.
4920 This is basically a temporary global variable that can be set and then
4921 used by user-defined selections using `org-agenda-skip-function'.")
4923 (defvar org-agenda-overriding-header nil
4924 "When set during agenda, todo and tags searches it replaces the header.
4925 This variable should not be set directly, but custom commands can bind it
4926 in the options section.")
4928 (defun org-agenda-skip-entry-when-regexp-matches ()
4929 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4930 If yes, it returns the end position of this entry, causing agenda commands
4931 to skip the entry but continuing the search in the subtree. This is a
4932 function that can be put into `org-agenda-skip-function' for the duration
4934 (let ((end (save-excursion (org-end-of-subtree t)))
4937 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4940 (defun org-agenda-skip-subtree-when-regexp-matches ()
4941 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4942 If yes, it returns the end position of this tree, causing agenda commands
4943 to skip this subtree. This is a function that can be put into
4944 `org-agenda-skip-function' for the duration of a command."
4945 (let ((end (save-excursion (org-end-of-subtree t)))
4948 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4951 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4952 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4953 If yes, it returns the end position of the current entry (NOT the tree),
4954 causing agenda commands to skip the entry but continuing the search in
4955 the subtree. This is a function that can be put into
4956 `org-agenda-skip-function' for the duration of a command. An important
4957 use of this function is for the stuck project list."
4958 (let ((end (save-excursion (org-end-of-subtree t)))
4959 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4962 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4963 (and skip entry-end)))
4965 (defun org-agenda-skip-entry-if (&rest conditions)
4966 "Skip entry if any of CONDITIONS is true.
4967 See `org-agenda-skip-if' for details."
4968 (org-agenda-skip-if nil conditions))
4970 (defun org-agenda-skip-subtree-if (&rest conditions)
4971 "Skip subtree if any of CONDITIONS is true.
4972 See `org-agenda-skip-if' for details."
4973 (org-agenda-skip-if t conditions))
4975 (defun org-agenda-skip-if (subtree conditions)
4976 "Checks current entity for CONDITIONS.
4977 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4978 the entry (i.e. the text before the next heading) is checked.
4980 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4981 from different tests. Valid conditions are:
4983 scheduled Check if there is a scheduled cookie
4984 notscheduled Check if there is no scheduled cookie
4985 deadline Check if there is a deadline
4986 notdeadline Check if there is no deadline
4987 timestamp Check if there is a timestamp (also deadline or scheduled)
4988 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4989 regexp Check if regexp matches
4990 notregexp Check if regexp does not match.
4991 todo Check if TODO keyword matches
4992 nottodo Check if TODO keyword does not match
4994 The regexp is taken from the conditions list, it must come right after
4995 the `regexp' or `notregexp' element.
4997 `todo' and `nottodo' accept as an argument a list of todo
4998 keywords, which may include \"*\" to match any todo keyword.
5000 (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
5002 would skip all entries with \"TODO\" or \"WAITING\" keywords.
5004 Instead of a list, a keyword class may be given. For example:
5006 (org-agenda-skip-entry-if \\='nottodo \\='done)
5008 would skip entries that haven't been marked with any of \"DONE\"
5009 keywords. Possible classes are: `todo', `done', `any'.
5011 If any of these conditions is met, this function returns the end point of
5012 the entity, causing the search to continue from there. This is a function
5013 that can be put into `org-agenda-skip-function' for the duration of a command."
5015 (org-back-to-heading t)
5018 (progn (org-end-of-subtree t) (point))
5019 (progn (outline-next-heading) (1- (point)))))
5023 (and (memq 'scheduled conditions)
5024 (re-search-forward org-scheduled-time-regexp end t))
5025 (and (memq 'notscheduled conditions)
5026 (not (re-search-forward org-scheduled-time-regexp end t)))
5027 (and (memq 'deadline conditions)
5028 (re-search-forward org-deadline-time-regexp end t))
5029 (and (memq 'notdeadline conditions)
5030 (not (re-search-forward org-deadline-time-regexp end t)))
5031 (and (memq 'timestamp conditions)
5032 (re-search-forward org-ts-regexp end t))
5033 (and (memq 'nottimestamp conditions)
5034 (not (re-search-forward org-ts-regexp end t)))
5035 (and (setq m (memq 'regexp conditions))
5037 (re-search-forward (nth 1 m) end t))
5038 (and (setq m (memq 'notregexp conditions))
5040 (not (re-search-forward (nth 1 m) end t)))
5042 (setq m (memq 'nottodo conditions))
5043 (setq m (memq 'todo-unblocked conditions))
5044 (setq m (memq 'nottodo-unblocked conditions))
5045 (setq m (memq 'todo conditions)))
5046 (org-agenda-skip-if-todo m end)))
5049 (defun org-agenda-skip-if-todo (args end)
5050 "Helper function for `org-agenda-skip-if', do not use it directly.
5051 ARGS is a list with first element either `todo', `nottodo',
5052 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
5053 a list of TODO keywords, or a state symbol `todo' or `done' or
5055 (let ((kw (car args))
5061 ((listp arg) ;; list of keywords
5062 (if (member "*" arg)
5063 (mapcar 'substring-no-properties org-todo-keywords-1)
5065 ((symbolp arg) ;; keyword class name
5068 (org-delete-all org-done-keywords
5069 (mapcar 'substring-no-properties
5070 org-todo-keywords-1)))
5071 ((eq arg 'done) org-done-keywords)
5073 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
5075 (concat "^\\*+[ \t]+\\<\\("
5076 (mapconcat 'identity todo-wds "\\|")
5079 ((eq kw 'todo) (re-search-forward todo-re end t))
5080 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
5081 ((eq kw 'todo-unblocked)
5083 (while (re-search-forward todo-re end t)
5084 (or (org-entry-blocked-p) (throw 'unblocked t)))
5086 ((eq kw 'nottodo-unblocked)
5088 (while (re-search-forward todo-re end t)
5089 (or (org-entry-blocked-p) (throw 'unblocked nil)))
5094 (defun org-agenda-list-stuck-projects (&rest ignore)
5095 "Create agenda view for projects that are stuck.
5096 Stuck projects are project that have no next actions. For the definitions
5097 of what a project is and how to check if it stuck, customize the variable
5098 `org-stuck-projects'."
5100 (let* ((org-agenda-skip-function
5101 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5102 ;; We could have used org-agenda-skip-if here.
5103 (org-agenda-overriding-header
5104 (or org-agenda-overriding-header "List of stuck projects: "))
5105 (matcher (nth 0 org-stuck-projects))
5106 (todo (nth 1 org-stuck-projects))
5107 (todo-wds (if (member "*" todo)
5109 (org-agenda-prepare-buffers (org-agenda-files
5112 org-done-keywords-for-agenda
5113 (copy-sequence org-todo-keywords-for-agenda)))
5115 (todo-re (concat "^\\*+[ \t]+\\("
5116 (mapconcat 'identity todo-wds "\\|")
5118 (tags (nth 2 org-stuck-projects))
5119 (tags-re (if (member "*" tags)
5120 (concat org-outline-regexp-bol
5121 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5123 (concat org-outline-regexp-bol
5125 (mapconcat 'identity tags "\\|")
5126 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5127 (gen-re (nth 3 org-stuck-projects))
5133 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5135 (setq org-agenda-skip-regexp
5137 (mapconcat 'identity re-list "\\|")
5138 (error "No information how to identify unstuck projects")))
5139 (org-tags-view nil matcher)
5140 (setq org-agenda-buffer-name (buffer-name))
5141 (with-current-buffer org-agenda-buffer-name
5142 (setq org-agenda-redo-command
5143 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5145 ;;; Diary integration
5147 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5148 (defvar diary-list-entries-hook)
5149 (defvar diary-time-regexp)
5150 (defun org-get-entries-from-diary (date)
5151 "Get the (Emacs Calendar) diary entries for DATE."
5152 (require 'diary-lib)
5153 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5154 (diary-display-function 'diary-fancy-display)
5156 (diary-list-entries-hook
5157 (cons 'org-diary-default-entry diary-list-entries-hook))
5158 (diary-file-name-prefix nil) ; turn this feature off
5159 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5161 (org-disable-agenda-to-diary t))
5163 (save-window-excursion
5164 (funcall (if (fboundp 'diary-list-entries)
5165 'diary-list-entries 'list-diary-entries)
5167 (if (not (get-buffer diary-fancy-buffer))
5169 (with-current-buffer diary-fancy-buffer
5170 (setq buffer-read-only nil)
5171 (if (zerop (buffer-size))
5174 ;; Omit the date and other unnecessary stuff
5175 (org-agenda-cleanup-fancy-diary)
5176 ;; Add prefix to each line and extend the text properties
5177 (if (zerop (buffer-size))
5179 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5182 (insert entries) (goto-char (point-min))
5183 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5184 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5185 (replace-match (concat "; " (match-string 1)))))
5187 (set-buffer-modified-p nil)
5188 (kill-buffer diary-fancy-buffer)))
5190 (setq entries (org-split-string entries "\n"))
5194 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5195 ;; Extend the text properties to the beginning of the line
5196 (org-add-props x (text-properties-at (1- (length x)) x)
5197 'type "diary" 'date date 'face 'org-agenda-diary))
5200 (defvar org-agenda-cleanup-fancy-diary-hook nil
5201 "Hook run when the fancy diary buffer is cleaned up.")
5203 (defun org-agenda-cleanup-fancy-diary ()
5204 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5205 This gets rid of the date, the underline under the date, and
5206 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5207 date. It also removes lines that contain only whitespace."
5208 (goto-char (point-min))
5209 (if (looking-at ".*?:[ \t]*")
5212 (re-search-forward "\n=+$" nil t)
5214 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5215 (re-search-forward "\n=+$" nil t)
5216 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5217 (goto-char (point-min))
5218 (while (re-search-forward "^ +\n" nil t)
5220 (goto-char (point-min))
5221 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5223 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5225 ;; Make sure entries from the diary have the right text properties.
5226 (eval-after-load "diary-lib"
5227 '(if (boundp 'diary-modify-entry-list-string-function)
5228 ;; We can rely on the hook, nothing to do
5230 ;; Hook not available, must use advice to make this work
5231 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5232 "Make the position visible."
5233 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5236 (setq string (org-modify-diary-entry-string string))))))
5238 (defun org-modify-diary-entry-string (string)
5239 "Add text properties to string, allowing org-mode to act on it."
5240 (org-add-props string nil
5241 'mouse-face 'highlight
5242 'help-echo (if buffer-file-name
5243 (format "mouse-2 or RET jump to diary file %s"
5244 (abbreviate-file-name buffer-file-name))
5246 'org-agenda-diary-link t
5247 'org-marker (org-agenda-new-marker (point-at-bol))))
5249 (defun org-diary-default-entry ()
5250 "Add a dummy entry to the diary.
5251 Needed to avoid empty dates which mess up holiday display."
5252 ;; Catch the error if dealing with the new add-to-diary-alist
5253 (when org-disable-agenda-to-diary
5255 (org-add-to-diary-list original-date "Org-mode dummy" "")
5257 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5259 (defun org-add-to-diary-list (&rest args)
5260 (if (fboundp 'diary-add-to-list)
5261 (apply 'diary-add-to-list args)
5262 (apply 'add-to-diary-list args)))
5264 (defvar org-diary-last-run-time nil)
5267 (defun org-diary (&rest args)
5268 "Return diary information from org files.
5269 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5270 It accesses org files and extracts information from those files to be
5271 listed in the diary. The function accepts arguments specifying what
5272 items should be listed. For a list of arguments allowed here, see the
5273 variable `org-agenda-entry-types'.
5275 The call in the diary file should look like this:
5277 &%%(org-diary) ~/path/to/some/orgfile.org
5279 Use a separate line for each org file to check. Or, if you omit the file name,
5280 all files listed in `org-agenda-files' will be checked automatically:
5284 If you don't give any arguments (as in the example above), the default value
5285 of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
5286 So the example above may also be written as
5288 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5290 The function expects the lisp variables `entry' and `date' to be provided
5291 by the caller, because this is how the calendar works. Don't use this
5292 function from a program - use `org-agenda-get-day-entries' instead."
5293 (when (> (- (org-float-time)
5294 org-agenda-last-marker-time)
5296 ;; I am not sure if this works with sticky agendas, because the marker
5297 ;; list is then no longer a global variable.
5298 (org-agenda-reset-markers))
5299 (org-compile-prefix-format 'agenda)
5300 (org-set-sorting-strategy 'agenda)
5301 (setq args (or args org-agenda-entry-types))
5302 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5304 (org-agenda-files t)))
5305 (time (org-float-time))
5307 (when (or (not org-diary-last-run-time)
5309 org-diary-last-run-time)
5311 (org-agenda-prepare-buffers files))
5312 (setq org-diary-last-run-time time)
5313 ;; If this is called during org-agenda, don't return any entries to
5314 ;; the calendar. Org Agenda will list these entries itself.
5315 (if org-disable-agenda-to-diary (setq files nil))
5316 (while (setq file (pop files))
5317 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5318 (setq results (append results rtn)))
5321 (mapcar (lambda (i) (replace-regexp-in-string
5322 org-bracket-link-regexp "\\3" i)) results))
5323 (concat (org-agenda-finalize-entries results) "\n"))))
5325 ;;; Agenda entry finders
5327 (defun org-agenda--timestamp-to-absolute (&rest args)
5328 "Call `org-time-string-to-absolute' with ARGS.
5329 However, throw `:skip' whenever an error is raised."
5331 (apply #'org-time-string-to-absolute args)
5332 (org-diary-sexp-no-match (throw :skip nil))
5334 (message "%s; Skipping entry" (error-message-string e))
5335 (throw :skip nil))))
5337 (defun org-agenda-get-day-entries (file date &rest args)
5338 "Does the work for `org-diary' and `org-agenda'.
5339 FILE is the path to a file to be checked for entries. DATE is date like
5340 the one returned by `calendar-current-date'. ARGS are symbols indicating
5341 which kind of entries should be extracted. For details about these, see
5342 the documentation of `org-diary'."
5343 (let* ((org-startup-folded nil)
5344 (org-startup-align-all-tables nil)
5345 (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
5346 (error "No such file %s" file))))
5348 ;; If file does not exist, signal it in diary nonetheless.
5349 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5350 (with-current-buffer buffer
5351 (unless (derived-mode-p 'org-mode)
5352 (error "Agenda file %s is not in `org-mode'" file))
5353 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5354 (setf org-agenda-current-date date)
5357 (if (eq buffer org-agenda-restrict)
5358 (narrow-to-region org-agenda-restrict-begin
5359 org-agenda-restrict-end)
5361 ;; Rationalize ARGS. Also make sure `:deadline' comes
5362 ;; first in order to populate DEADLINES before passing it.
5364 ;; We use `delq' since `org-uniquify' duplicates ARGS,
5365 ;; guarding us from modifying `org-agenda-entry-types'.
5366 (setf args (org-uniquify (or args org-agenda-entry-types)))
5367 (when (and (memq :scheduled args) (memq :scheduled* args))
5368 (setf args (delq :scheduled* args)))
5370 ((memq :deadline args)
5371 (setf args (cons :deadline
5372 (delq :deadline (delq :deadline* args)))))
5373 ((memq :deadline* args)
5374 (setf args (cons :deadline* (delq :deadline* args)))))
5375 ;; Collect list of headlines. Return them flattened.
5376 (let ((case-fold-search nil) results deadlines)
5377 (dolist (arg args (apply #'nconc (nreverse results)))
5379 ((and :todo (guard (org-agenda-today-p date)))
5380 (push (org-agenda-get-todos) results))
5382 (push (org-agenda-get-blocks) results)
5383 (push (org-agenda-get-timestamps deadlines) results))
5385 (push (org-agenda-get-sexps) results))
5387 (push (org-agenda-get-scheduled deadlines) results))
5389 (push (org-agenda-get-scheduled deadlines t) results))
5391 (push (org-agenda-get-progress) results))
5393 (setf deadlines (org-agenda-get-deadlines))
5394 (push deadlines results))
5396 (setf deadlines (org-agenda-get-deadlines t))
5397 (push deadlines results)))))))))))
5399 (defsubst org-em (x y list)
5400 "Is X or Y a member of LIST?"
5401 (or (memq x list) (memq y list)))
5403 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5404 (defvar org-agenda-sorting-strategy-selected nil)
5406 (defun org-agenda-entry-get-agenda-timestamp (pom)
5407 "Retrieve timestamp information for sorting agenda views.
5408 Given a point or marker POM, returns a cons cell of the timestamp
5409 and the timestamp type relevant for the sorting strategy in
5410 `org-agenda-sorting-strategy-selected'."
5411 (let (ts ts-date-type)
5413 (cond ((org-em 'scheduled-up 'scheduled-down
5414 org-agenda-sorting-strategy-selected)
5415 (setq ts (org-entry-get pom "SCHEDULED")
5416 ts-date-type " scheduled"))
5417 ((org-em 'deadline-up 'deadline-down
5418 org-agenda-sorting-strategy-selected)
5419 (setq ts (org-entry-get pom "DEADLINE")
5420 ts-date-type " deadline"))
5421 ((org-em 'ts-up 'ts-down
5422 org-agenda-sorting-strategy-selected)
5423 (setq ts (org-entry-get pom "TIMESTAMP")
5424 ts-date-type " timestamp"))
5425 ((org-em 'tsia-up 'tsia-down
5426 org-agenda-sorting-strategy-selected)
5427 (setq ts (org-entry-get pom "TIMESTAMP_IA")
5428 ts-date-type " timestamp_ia"))
5429 ((org-em 'timestamp-up 'timestamp-down
5430 org-agenda-sorting-strategy-selected)
5431 (setq ts (or (org-entry-get pom "SCHEDULED")
5432 (org-entry-get pom "DEADLINE")
5433 (org-entry-get pom "TIMESTAMP")
5434 (org-entry-get pom "TIMESTAMP_IA"))
5436 (t (setq ts-date-type "")))
5437 (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
5440 (defun org-agenda-get-todos ()
5441 "Return the TODO information for agenda display."
5442 (let* ((props (list 'face nil
5443 'done-face 'org-agenda-done
5444 'org-not-done-regexp org-not-done-regexp
5445 'org-todo-regexp org-todo-regexp
5446 'org-complex-heading-regexp org-complex-heading-regexp
5447 'mouse-face 'highlight
5449 (format "mouse-2 or RET jump to org file %s"
5450 (abbreviate-file-name buffer-file-name))))
5451 (regexp (format org-heading-keyword-regexp-format
5453 ((and org-select-this-todo-keyword
5454 (equal org-select-this-todo-keyword "*"))
5456 (org-select-this-todo-keyword
5458 (mapconcat 'identity
5460 org-select-this-todo-keyword
5463 (t org-not-done-regexp))))
5464 marker priority category level tags todo-state
5465 ts-date ts-date-type ts-date-pair
5466 ee txt beg end inherited-tags todo-state-end-pos)
5467 (goto-char (point-min))
5468 (while (re-search-forward regexp nil t)
5473 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5474 (unless (and (setq todo-state (org-get-todo-state))
5475 (setq todo-state-end-pos (match-end 2)))
5478 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5479 (goto-char (1+ beg))
5480 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5482 (goto-char (match-beginning 2))
5483 (setq marker (org-agenda-new-marker (match-beginning 0))
5484 category (org-get-category)
5485 ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
5486 ts-date (car ts-date-pair)
5487 ts-date-type (cdr ts-date-pair)
5488 txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
5490 (or (eq org-agenda-show-inherited-tags 'always)
5491 (and (listp org-agenda-show-inherited-tags)
5492 (memq 'todo org-agenda-show-inherited-tags))
5493 (and (eq org-agenda-show-inherited-tags t)
5494 (or (eq org-agenda-use-tag-inheritance t)
5495 (memq 'todo org-agenda-use-tag-inheritance))))
5496 tags (org-get-tags-at nil (not inherited-tags))
5497 level (make-string (org-reduced-level (org-outline-level)) ? )
5498 txt (org-agenda-format-item "" txt level category tags t)
5499 priority (1+ (org-get-priority txt)))
5500 (org-add-props txt props
5501 'org-marker marker 'org-hd-marker marker
5505 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5507 (if org-agenda-todo-list-sublevels
5508 (goto-char todo-state-end-pos)
5509 (org-end-of-subtree 'invisible))))
5512 (defun org-agenda-todo-custom-ignore-p (time n)
5513 "Check whether timestamp is farther away than n number of days.
5514 This function is invoked if `org-agenda-todo-ignore-deadlines',
5515 `org-agenda-todo-ignore-scheduled' or
5516 `org-agenda-todo-ignore-timestamp' is set to an integer."
5517 (let ((days (org-time-stamp-to-now
5518 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5524 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5526 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5527 (when (or org-agenda-todo-ignore-with-date
5528 org-agenda-todo-ignore-scheduled
5529 org-agenda-todo-ignore-deadlines
5530 org-agenda-todo-ignore-timestamp)
5531 (setq end (or end (save-excursion (outline-next-heading) (point))))
5533 (or (and org-agenda-todo-ignore-with-date
5534 (re-search-forward org-ts-regexp end t))
5535 (and org-agenda-todo-ignore-scheduled
5536 (re-search-forward org-scheduled-time-regexp end t)
5538 ((eq org-agenda-todo-ignore-scheduled 'future)
5539 (> (org-time-stamp-to-now
5540 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5541 ((eq org-agenda-todo-ignore-scheduled 'past)
5542 (<= (org-time-stamp-to-now
5543 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5544 ((numberp org-agenda-todo-ignore-scheduled)
5545 (org-agenda-todo-custom-ignore-p
5546 (match-string 1) org-agenda-todo-ignore-scheduled))
5548 (and org-agenda-todo-ignore-deadlines
5549 (re-search-forward org-deadline-time-regexp end t)
5551 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5552 ((eq org-agenda-todo-ignore-deadlines 'far)
5553 (not (org-deadline-close (match-string 1))))
5554 ((eq org-agenda-todo-ignore-deadlines 'future)
5555 (> (org-time-stamp-to-now
5556 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5557 ((eq org-agenda-todo-ignore-deadlines 'past)
5558 (<= (org-time-stamp-to-now
5559 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5560 ((numberp org-agenda-todo-ignore-deadlines)
5561 (org-agenda-todo-custom-ignore-p
5562 (match-string 1) org-agenda-todo-ignore-deadlines))
5563 (t (org-deadline-close (match-string 1)))))
5564 (and org-agenda-todo-ignore-timestamp
5565 (let ((buffer (current-buffer))
5568 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5570 ;; Copy current buffer into a temporary one
5572 (insert-buffer-substring buffer start end)
5573 (goto-char (point-min))
5574 ;; Delete SCHEDULED and DEADLINE items
5575 (while (re-search-forward regexp end t)
5576 (delete-region (match-beginning 0) (match-end 0)))
5577 (goto-char (point-min))
5578 ;; No search for timestamp left
5579 (when (re-search-forward org-ts-regexp nil t)
5581 ((eq org-agenda-todo-ignore-timestamp 'future)
5582 (> (org-time-stamp-to-now
5583 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5584 ((eq org-agenda-todo-ignore-timestamp 'past)
5585 (<= (org-time-stamp-to-now
5586 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5587 ((numberp org-agenda-todo-ignore-timestamp)
5588 (org-agenda-todo-custom-ignore-p
5589 (match-string 1) org-agenda-todo-ignore-timestamp))
5592 (defun org-agenda-get-timestamps (&optional deadline-results)
5593 "Return the date stamp information for agenda display."
5594 (let* ((props (list 'face 'org-agenda-calendar-event
5595 'org-not-done-regexp org-not-done-regexp
5596 'org-todo-regexp org-todo-regexp
5597 'org-complex-heading-regexp org-complex-heading-regexp
5598 'mouse-face 'highlight
5600 (format "mouse-2 or RET jump to org file %s"
5601 (abbreviate-file-name buffer-file-name))))
5602 (d1 (calendar-absolute-from-gregorian date))
5604 (deadline-position-alist
5605 (mapcar (lambda (a) (and (setq mm (get-text-property
5606 0 'org-hd-marker a))
5607 (cons (marker-position mm) a)))
5609 (remove-re org-ts-regexp)
5612 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5616 (car org-time-stamp-formats)
5617 (apply 'encode-time ; DATE bound by calendar
5618 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5620 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5621 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5622 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5623 donep tmp priority category level ee txt timestr tags
5624 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5625 inherited-tags ts-date)
5626 (goto-char (point-min))
5627 (while (setq end-of-match (re-search-forward regexp nil t))
5628 (setq b0 (match-beginning 0)
5629 b3 (match-beginning 3) e3 (match-end 3)
5630 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5631 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5632 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5634 org-agenda-repeating-timestamp-show-all)))
5636 (and (org-at-date-range-p) (throw :skip nil))
5638 (if (and (match-end 1)
5639 (not (= d1 (org-agenda--timestamp-to-absolute
5640 (match-string 1) d1 nil show-all
5641 (current-buffer) b0))))
5644 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5646 (setq tmp (buffer-substring (max (point-min)
5647 (- b0 org-ds-keyword-length))
5649 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5650 inactivep (= (char-after b0) ?\[)
5651 deadlinep (string-match org-deadline-regexp tmp)
5652 scheduledp (string-match org-scheduled-regexp tmp)
5653 closedp (and org-agenda-include-inactive-timestamps
5654 (string-match org-closed-string tmp))
5655 clockp (and org-agenda-include-inactive-timestamps
5656 (or (string-match org-clock-string tmp)
5657 (string-match "]-+\\'" tmp)))
5658 warntime (get-text-property (point) 'org-appt-warntime)
5659 donep (member todo-state org-done-keywords))
5660 (if (or scheduledp deadlinep closedp clockp
5661 (and donep org-agenda-skip-timestamp-if-done))
5663 (if (string-match ">" timestr)
5664 ;; substring should only run to end of time stamp
5665 (setq timestr (substring timestr 0 (match-end 0))))
5666 (setq marker (org-agenda-new-marker b0)
5667 category (org-get-category b0))
5669 (if (not (re-search-backward org-outline-regexp-bol nil t))
5671 (goto-char (match-beginning 0))
5672 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5673 (assoc (point) deadline-position-alist))
5675 (setq hdmarker (org-agenda-new-marker)
5677 (or (eq org-agenda-show-inherited-tags 'always)
5678 (and (listp org-agenda-show-inherited-tags)
5679 (memq 'agenda org-agenda-show-inherited-tags))
5680 (and (eq org-agenda-show-inherited-tags t)
5681 (or (eq org-agenda-use-tag-inheritance t)
5682 (memq 'agenda org-agenda-use-tag-inheritance))))
5683 tags (org-get-tags-at nil (not inherited-tags))
5684 level (make-string (org-reduced-level (org-outline-level)) ? ))
5685 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5686 (setq head (or (match-string 1) ""))
5687 (setq txt (org-agenda-format-item
5688 (if inactivep org-agenda-inactive-leader nil)
5689 head level category tags timestr
5691 (setq priority (org-get-priority txt))
5692 (org-add-props txt props 'priority priority
5693 'org-marker marker 'org-hd-marker hdmarker
5697 (ignore-errors (org-time-string-to-absolute timestr))
5698 'todo-state todo-state
5702 (if org-agenda-skip-additional-timestamps-same-entry
5703 (outline-next-heading)
5704 (goto-char end-of-match))))
5707 (defun org-agenda-get-sexps ()
5708 "Return the sexp information for agenda display."
5709 (require 'diary-lib)
5710 (let* ((props (list 'face 'org-agenda-calendar-sexp
5711 'mouse-face 'highlight
5713 (format "mouse-2 or RET jump to org file %s"
5714 (abbreviate-file-name buffer-file-name))))
5716 marker category extra level ee txt tags entry
5717 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5718 (goto-char (point-min))
5719 (while (re-search-forward regexp nil t)
5722 (setq beg (match-beginning 0))
5723 (goto-char (1- (match-end 0)))
5726 (setq sexp (buffer-substring b (point)))
5727 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5728 (org-trim (match-string 1))
5730 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5732 (setq marker (org-agenda-new-marker beg)
5733 level (make-string (org-reduced-level (org-outline-level)) ? )
5734 category (org-get-category beg)
5736 (or (eq org-agenda-show-inherited-tags 'always)
5737 (and (listp org-agenda-show-inherited-tags)
5738 (memq 'agenda org-agenda-show-inherited-tags))
5739 (and (eq org-agenda-show-inherited-tags t)
5740 (or (eq org-agenda-use-tag-inheritance t)
5741 (memq 'agenda org-agenda-use-tag-inheritance))))
5742 tags (org-get-tags-at nil (not inherited-tags))
5743 todo-state (org-get-todo-state)
5744 warntime (get-text-property (point) 'org-appt-warntime)
5747 (dolist (r (if (stringp result)
5749 result)) ;; we expect a list here
5750 (when (and org-agenda-diary-sexp-prefix
5751 (string-match org-agenda-diary-sexp-prefix r))
5752 (setq extra (match-string 0 r)
5753 r (replace-match "" nil nil r)))
5754 (if (string-match "\\S-" r)
5756 (setq txt "SEXP entry returned empty string"))
5757 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5758 (org-add-props txt props 'org-marker marker
5759 'date date 'todo-state todo-state
5760 'level level 'type "sexp" 'warntime warntime)
5764 ;; Calendar sanity: define some functions that are independent of
5765 ;; `calendar-date-style'.
5766 ;; Normally I would like to use ISO format when calling the diary functions,
5767 ;; but to make sure we still have Emacs 22 compatibility we bind
5768 ;; also `european-calendar-style' and use european format
5769 (defun org-anniversary (year month day &optional mark)
5770 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5772 (let ((calendar-date-style 'european) (european-calendar-style t))
5773 (diary-anniversary day month year mark))))
5774 (defun org-cyclic (N year month day &optional mark)
5775 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5777 (let ((calendar-date-style 'european) (european-calendar-style t))
5778 (diary-cyclic N day month year mark))))
5779 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5780 "Like `diary-block', but with fixed (ISO) order of arguments."
5782 (let ((calendar-date-style 'european) (european-calendar-style t))
5783 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5784 (defun org-date (year month day &optional mark)
5785 "Like `diary-date', but with fixed (ISO) order of arguments."
5787 (let ((calendar-date-style 'european) (european-calendar-style t))
5788 (diary-date day month year mark))))
5790 ;; Define the `org-class' function
5791 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5792 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5793 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5794 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5795 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5796 `holidays', then any date that is known by the Emacs calendar to be a
5797 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5798 then those holidays will be skipped."
5799 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5800 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5801 (d (calendar-absolute-from-gregorian date))
5802 (h (when skip-weeks (calendar-check-holidays date))))
5806 (= (calendar-day-of-week date) dayname)
5807 (or (not skip-weeks)
5810 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5811 (not (or (and h (memq 'holidays skip-weeks))
5812 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5815 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5816 "Like `org-class', but honor `calendar-date-style'.
5817 The order of the first 2 times 3 arguments depends on the variable
5818 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5819 So for American calendars, give this as MONTH DAY YEAR, for European as
5820 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5821 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5822 is any number of ISO weeks in the block period for which the item should
5825 This function is here only for backward compatibility and it is deprecated,
5826 please use `org-class' instead."
5827 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5828 (date2 (org-order-calendar-date-args m2 d2 y2)))
5830 (nth 2 date1) (car date1) (nth 1 date1)
5831 (nth 2 date2) (car date2) (nth 1 date2)
5832 dayname skip-weeks)))
5833 (make-obsolete 'org-diary-class 'org-class "")
5835 (defalias 'org-get-closed 'org-agenda-get-progress)
5836 (defun org-agenda-get-progress ()
5837 "Return the logged TODO entries for agenda display."
5838 (let* ((props (list 'mouse-face 'highlight
5839 'org-not-done-regexp org-not-done-regexp
5840 'org-todo-regexp org-todo-regexp
5841 'org-complex-heading-regexp org-complex-heading-regexp
5843 (format "mouse-2 or RET jump to org file %s"
5844 (abbreviate-file-name buffer-file-name))))
5845 (items (if (consp org-agenda-show-log-scoped)
5846 org-agenda-show-log-scoped
5847 (if (eq org-agenda-show-log-scoped 'clockcheck)
5849 org-agenda-log-mode-items)))
5853 (if (memq 'closed items) (concat "\\<" org-closed-string))
5854 (if (memq 'clock items) (concat "\\<" org-clock-string))
5855 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5856 (parts-re (if parts (mapconcat 'identity parts "\\|")
5857 (error "`org-agenda-log-mode-items' is empty")))
5859 "\\(" parts-re "\\)"
5864 (car org-time-stamp-formats)
5865 (apply 'encode-time ; DATE bound by calendar
5866 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5868 (org-agenda-search-headline-for-time nil)
5869 marker hdmarker priority category level tags closedp
5870 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5871 (goto-char (point-min))
5872 (while (re-search-forward regexp nil t)
5875 (setq marker (org-agenda-new-marker (match-beginning 0))
5876 closedp (equal (match-string 1) org-closed-string)
5877 statep (equal (string-to-char (match-string 1)) ?-)
5878 clockp (not (or closedp statep))
5879 state (and statep (match-string 2))
5880 category (org-get-category (match-beginning 0))
5881 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5882 (when (string-match "\\]" timestr)
5883 ;; substring should only run to end of time stamp
5884 (setq rest (substring timestr (match-end 0))
5885 timestr (substring timestr 0 (match-end 0)))
5886 (if (and (not closedp) (not statep)
5887 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5889 (progn (setq timestr (concat (substring timestr 0 -1)
5890 "-" (match-string 1 rest) "]"))
5891 (setq clocked (match-string 2 rest)))
5892 (setq clocked "-")))
5896 ((not org-agenda-log-mode-add-notes) nil)
5898 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5901 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5902 (match-string 1)))))
5903 (if (not (re-search-backward org-outline-regexp-bol nil t))
5905 (goto-char (match-beginning 0))
5906 (setq hdmarker (org-agenda-new-marker)
5908 (or (eq org-agenda-show-inherited-tags 'always)
5909 (and (listp org-agenda-show-inherited-tags)
5910 (memq 'todo org-agenda-show-inherited-tags))
5911 (and (eq org-agenda-show-inherited-tags t)
5912 (or (eq org-agenda-use-tag-inheritance t)
5913 (memq 'todo org-agenda-use-tag-inheritance))))
5914 tags (org-get-tags-at nil (not inherited-tags))
5915 level (make-string (org-reduced-level (org-outline-level)) ? ))
5916 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5917 (setq txt (match-string 1))
5919 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5920 (setq txt (concat (substring txt 0 (match-beginning 1))
5921 " - " extra " " (match-string 2 txt)))
5922 (setq txt (concat txt " - " extra))))
5923 (setq txt (org-agenda-format-item
5925 (closedp "Closed: ")
5926 (statep (concat "State: (" state ")"))
5927 (t (concat "Clocked: (" clocked ")")))
5928 txt level category tags timestr)))
5929 (setq priority 100000)
5930 (org-add-props txt props
5931 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5932 'priority priority 'level level
5933 'type "closed" 'date date
5934 'undone-face 'org-warning 'done-face 'org-agenda-done)
5936 (goto-char (point-at-eol))))
5939 (defun org-agenda-show-clocking-issues ()
5940 "Add overlays, showing issues with clocking.
5941 See also the user option `org-agenda-clock-consistency-checks'."
5943 (let* ((org-time-clocksum-use-effort-durations nil)
5944 (pl org-agenda-clock-consistency-checks)
5945 (re (concat "^[ \t]*"
5948 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5949 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5952 (maxtime (org-hh:mm-string-to-minutes
5953 (or (plist-get pl :max-duration) "24:00")))
5954 (mintime (org-hh:mm-string-to-minutes
5955 (or (plist-get pl :min-duration) 0)))
5956 (maxgap (org-hh:mm-string-to-minutes
5957 ;; default 30:00 means never complain
5958 (or (plist-get pl :max-gap) "30:00")))
5959 (gapok (mapcar 'org-hh:mm-string-to-minutes
5960 (plist-get pl :gap-ok-around)))
5961 (def-face (or (plist-get pl :default-face)
5962 '((:background "DarkRed") (:foreground "white"))))
5963 issue face m te ts dt ov)
5964 (goto-char (point-min))
5965 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5966 (setq issue nil face def-face)
5968 (setq m (org-get-at-bol 'org-marker)
5970 (unless (and m (markerp m))
5971 (setq issue "No valid clock line") (throw 'next t))
5972 (org-with-point-at m
5974 (goto-char (point-at-bol))
5975 (unless (looking-at re)
5976 (error "No valid Clock line")
5978 (unless (match-end 3)
5979 (setq issue "No end time"
5980 face (or (plist-get pl :no-end-time-face) face))
5982 (setq ts (match-string 1)
5985 (apply 'encode-time (org-parse-time-string ts)))
5987 (apply 'encode-time (org-parse-time-string te)))
5990 ((> dt (* 60 maxtime))
5991 ;; a very long clocking chunk
5992 (setq issue (format "Clocking interval is very long: %s"
5993 (org-minutes-to-clocksum-string
5994 (floor (/ (float dt) 60.))))
5995 face (or (plist-get pl :long-face) face)))
5996 ((< dt (* 60 mintime))
5997 ;; a very short clocking chunk
5998 (setq issue (format "Clocking interval is very short: %s"
5999 (org-minutes-to-clocksum-string
6000 (floor (/ (float dt) 60.))))
6001 face (or (plist-get pl :short-face) face)))
6002 ((and (> tlend 0) (< ts tlend))
6003 ;; Two clock entries are overlapping
6004 (setq issue (format "Clocking overlap: %d minutes"
6005 (/ (- tlend ts) 60))
6006 face (or (plist-get pl :overlap-face) face)))
6007 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
6008 ;; There is a gap, lets see if we need to report it
6009 (unless (org-agenda-check-clock-gap tlend ts gapok)
6010 (setq issue (format "Clocking gap: %d minutes"
6011 (/ (- ts tlend) 60))
6012 face (or (plist-get pl :gap-face) face))))
6014 (setq tlend (or te tlend) tlstart (or ts tlstart))
6016 ;; OK, there was some issue, add an overlay to show the issue
6017 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
6018 (overlay-put ov 'before-string
6021 (format "%-43s" (concat " " issue))
6025 (overlay-put ov 'evaporate t)))))
6027 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
6028 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
6031 ;; there are no OK times for gaps...
6033 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
6034 ;; This is more than 24 hours, so it is OK.
6035 ;; because we have at least one OK time, that must be in the
6036 ;; 24 hour interval.
6038 ;; We have a shorter gap.
6039 ;; Now we have to get the minute of the day when these times are
6040 (let* ((t1dec (decode-time (seconds-to-time t1)))
6041 (t2dec (decode-time (seconds-to-time t2)))
6042 ;; compute the minute on the day
6043 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
6044 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
6046 ;; if min2 is smaller than min1, this means it is on the next day.
6047 ;; Wrap it to after midnight.
6048 (setq min2 (+ min2 1440)))
6049 ;; Now check if any of the OK times is in the gap
6051 ;; Wrap the time to after midnight if necessary
6052 (if (< x min1) (setq x (+ x 1440)))
6053 ;; Check if in interval
6054 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
6056 ;; Nope, this gap is not OK
6059 (defun org-agenda-get-deadlines (&optional with-hour)
6060 "Return the deadline information for agenda display.
6061 When WITH-HOUR is non-nil, only return deadlines with an hour
6062 specification like [h]h:mm."
6063 (let* ((props (list 'mouse-face 'highlight
6064 'org-not-done-regexp org-not-done-regexp
6065 'org-todo-regexp org-todo-regexp
6066 'org-complex-heading-regexp org-complex-heading-regexp
6068 (format "mouse-2 or RET jump to org file %s"
6069 (abbreviate-file-name buffer-file-name))))
6070 (regexp (if with-hour
6071 org-deadline-time-hour-regexp
6072 org-deadline-time-regexp))
6073 (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
6074 (current (calendar-absolute-from-gregorian date))
6076 (goto-char (point-min))
6077 (while (re-search-forward regexp nil t)
6079 (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
6081 (let* ((s (match-string 1))
6082 (pos (1- (match-beginning 1)))
6083 (todo-state (save-match-data (org-get-todo-state)))
6084 (donep (member todo-state org-done-keywords))
6085 (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6087 org-agenda-repeating-timestamp-show-all)))
6088 ;; DEADLINE is the current scheduled date. When it
6089 ;; contains a repeater and SHOW-ALL is non-nil,
6090 ;; LAST-REPEAT is the repeat closest to CURRENT.
6091 ;; Otherwise, LAST-REPEAT is equal to DEADLINE.
6092 (last-repeat (org-agenda--timestamp-to-absolute
6093 s current 'past show-all (current-buffer) pos))
6094 (deadline (org-agenda--timestamp-to-absolute s current))
6095 (diff (- last-repeat current))
6096 (suppress-prewarning
6098 (and org-agenda-skip-deadline-prewarning-if-scheduled
6099 (org-entry-get nil "SCHEDULED"))))
6101 ((not scheduled) nil)
6102 ;; The current item has a scheduled date, so
6103 ;; evaluate its prewarning lead time.
6104 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
6105 ;; Use global prewarning-restart lead time.
6106 org-agenda-skip-deadline-prewarning-if-scheduled)
6107 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
6109 ;; Set pre-warning to no earlier than SCHEDULED.
6111 (org-agenda--timestamp-to-absolute
6112 scheduled current 'past show-all
6116 (1+ (search-forward org-deadline-string)))))
6117 org-deadline-warning-days))
6118 ;; Set pre-warning to deadline.
6120 (wdays (if suppress-prewarning
6121 (let ((org-deadline-warning-days suppress-prewarning))
6123 (org-get-wdays s))))
6124 ;; When to show a deadline in the calendar: if the
6125 ;; expiration is within WDAYS warning time. Past-due
6126 ;; deadlines are only shown on the current date
6127 (unless (or (and (<= diff wdays)
6128 (and todayp (not org-agenda-only-exact-dates)))
6131 ;; Skip done tasks if `org-agenda-skip-deadline-if-done' is
6132 ;; non-nil or if it isn't applicable to CURRENT deadline.
6134 (or org-agenda-skip-deadline-if-done
6135 (/= deadline current)))
6138 (re-search-backward "^\\*+[ \t]+" nil t)
6139 (goto-char (match-end 0))
6140 (let* ((category (org-get-category))
6142 (make-string (org-reduced-level (org-outline-level)) ?\s))
6143 (head (buffer-substring (point) (line-end-position)))
6145 (or (eq org-agenda-show-inherited-tags 'always)
6146 (and (listp org-agenda-show-inherited-tags)
6147 (memq 'agenda org-agenda-show-inherited-tags))
6148 (and (eq org-agenda-show-inherited-tags t)
6149 (or (eq org-agenda-use-tag-inheritance t)
6151 org-agenda-use-tag-inheritance)))))
6152 (tags (org-get-tags-at nil (not inherited-tags)))
6154 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6155 (concat (substring s (match-beginning 1)) " ")
6158 (org-agenda-format-item
6159 ;; For past deadlines, make sure to report time
6160 ;; difference since date S, not since closest
6162 (let ((diff (if (< (org-today) current) diff
6163 (- deadline current))))
6164 (if (= diff 0) (car org-agenda-deadline-leaders)
6165 (let ((future (nth 1 org-agenda-deadline-leaders))
6166 (past (nth 2 org-agenda-deadline-leaders)))
6167 (cond ((> diff 0) (format future diff))
6168 ((string= future past) (format past diff))
6169 (t (format past (abs diff)))))))
6170 head level category tags
6171 (and (= diff 0) timestr)))
6172 (face (org-agenda-deadline-face
6173 (- 1 (/ (float (- deadline current)) (max wdays 1)))))
6174 (upcomingp (and todayp (> diff 0)))
6175 (warntime (get-text-property (point) 'org-appt-warntime)))
6176 (org-add-props item props
6177 'org-marker (org-agenda-new-marker pos)
6178 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
6182 'priority (- (org-get-priority item) diff)
6183 'todo-state todo-state
6184 'type (if upcomingp "upcoming-deadline" "deadline")
6185 'date (if upcomingp date deadline)
6186 'face (if donep 'org-agenda-done face)
6188 'done-face 'org-agenda-done)
6189 (push item deadline-items))))))
6190 (nreverse deadline-items)))
6192 (defun org-agenda-deadline-face (fraction)
6193 "Return the face to displaying a deadline item.
6194 FRACTION is what fraction of the head-warning time has passed."
6195 (let ((faces org-agenda-deadline-faces) f)
6197 (while (setq f (pop faces))
6198 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6200 (defun org-agenda-get-scheduled (&optional deadlines with-hour)
6201 "Return the scheduled information for agenda display.
6202 Optional argument DEADLINES is a list of deadline items to be
6203 displayed in agenda view. When WITH-HOUR is non-nil, only return
6204 scheduled items with an hour specification like [h]h:mm."
6205 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6206 'org-todo-regexp org-todo-regexp
6207 'org-complex-heading-regexp org-complex-heading-regexp
6208 'done-face 'org-agenda-done
6209 'mouse-face 'highlight
6211 (format "mouse-2 or RET jump to org file %s"
6212 (abbreviate-file-name buffer-file-name))))
6213 (regexp (if with-hour
6214 org-scheduled-time-hour-regexp
6215 org-scheduled-time-regexp))
6216 (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
6217 (current (calendar-absolute-from-gregorian date))
6220 (let ((m (get-text-property 0 'org-hd-marker d)))
6221 (and m (marker-position m))))
6224 (goto-char (point-min))
6225 (while (re-search-forward regexp nil t)
6227 (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
6229 (let* ((s (match-string 1))
6230 (pos (1- (match-beginning 1)))
6231 (todo-state (save-match-data (org-get-todo-state)))
6232 (donep (member todo-state org-done-keywords))
6233 (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6235 org-agenda-repeating-timestamp-show-all)))
6236 ;; SCHEDULE is the current scheduled date. When it
6237 ;; contains a repeater and SHOW-ALL is non-nil,
6238 ;; LAST-REPEAT is the repeat closest to CURRENT.
6239 ;; Otherwise, LAST-REPEAT is equal to SCHEDULE.
6240 (last-repeat (org-agenda--timestamp-to-absolute
6241 s current 'past show-all (current-buffer) pos))
6242 (schedule (org-agenda--timestamp-to-absolute s current))
6243 (diff (- last-repeat current))
6244 (warntime (get-text-property (point) 'org-appt-warntime))
6245 (pastschedp (< schedule (org-today)))
6246 (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
6248 (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
6249 (org-entry-get nil "DEADLINE"))))
6251 ((not deadline) nil)
6252 ;; The current item has a deadline date, so
6253 ;; evaluate its delay time.
6254 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6255 ;; Use global delay time.
6256 (- org-agenda-skip-scheduled-delay-if-deadline))
6257 ((eq org-agenda-skip-scheduled-delay-if-deadline
6259 ;; Set delay to no later than DEADLINE. If
6260 ;; DEADLINE has a repeater, compare last schedule
6261 ;; repeat and last deadline repeat.
6263 (org-agenda--timestamp-to-absolute
6264 deadline current 'past show-all
6268 (1+ (search-forward org-deadline-string)))))
6269 org-scheduled-delay-days))
6273 ;; Nullify delay when a repeater triggered already
6274 ;; and the delay is of the form --Xd.
6275 ((and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6276 (/= schedule last-repeat))
6279 (let ((org-scheduled-delay-days suppress-delay))
6280 (org-get-wdays s t t)))
6281 (t (org-get-wdays s t)))))
6282 ;; Only show a scheduled item in the calendar if it is on or
6283 ;; past the current date. Skip it if it has been displayed
6284 ;; for more than `org-scheduled-past-days'.
6285 (unless (or (and (>= ddays 0) (= diff (- ddays)))
6286 (and (< (+ diff ddays) 0)
6287 (< (abs diff) org-scheduled-past-days)
6288 (and todayp (not org-agenda-only-exact-dates)))
6291 (bound-and-true-p org-habit-show-all-today)))
6293 ;; Skip done habits, or tasks if
6294 ;; `org-agenda-skip-deadline-if-done' is non-nil or if it
6295 ;; was scheduled in the past anyway.
6297 (or org-agenda-skip-scheduled-if-done
6298 (/= schedule current)
6301 ;; Skip entry if it already appears as a deadline, per
6302 ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
6303 ;; doesn't apply to habits.
6304 (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
6306 (or (not (assq (line-beginning-position 0) deadline-pos))
6309 (`repeated-after-deadline
6311 (time-to-days (org-get-deadline-time (point)))))
6312 (`not-today pastschedp)
6316 ;; Skip habits if `org-habit-show-habits' is nil, or if we
6317 ;; only show them for today.
6319 (or (not (bound-and-true-p org-habit-show-habits))
6322 org-habit-show-habits-only-for-today))))
6325 (re-search-backward "^\\*+[ \t]+" nil t)
6326 (goto-char (match-end 0))
6327 (let* ((category (org-get-category))
6329 (or (eq org-agenda-show-inherited-tags 'always)
6330 (and (listp org-agenda-show-inherited-tags)
6331 (memq 'agenda org-agenda-show-inherited-tags))
6332 (and (eq org-agenda-show-inherited-tags t)
6333 (or (eq org-agenda-use-tag-inheritance t)
6335 org-agenda-use-tag-inheritance)))))
6336 (tags (org-get-tags-at nil (not inherited-tags)))
6338 (make-string (org-reduced-level (org-outline-level)) ?\s))
6339 (head (buffer-substring (point) (line-end-position)))
6341 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6342 (concat (substring s (match-beginning 1)) " ")
6344 (item (org-agenda-format-item
6345 ;; For past scheduled dates, make sure to
6346 ;; report time difference since SCHEDULE,
6347 ;; not since closest repeater.
6348 (let ((diff (if (< (org-today) current) diff
6349 (- schedule current))))
6350 (if (= diff 0) (car org-agenda-scheduled-leaders)
6351 (format (nth 1 org-agenda-scheduled-leaders)
6353 head level category tags
6354 (and (= diff 0) timestr)
6356 (face (cond ((and (not habitp) pastschedp)
6357 'org-scheduled-previously)
6358 (todayp 'org-scheduled-today)
6359 (t 'org-scheduled)))
6360 (habitp (and habitp (org-habit-parse-todo))))
6361 (org-add-props item props
6363 'face (if donep 'org-agenda-done face)
6364 'org-marker (org-agenda-new-marker pos)
6365 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
6366 'type (if pastschedp "past-scheduled" "scheduled")
6367 'date (if pastschedp schedule date)
6371 'priority (if habitp (org-habit-get-priority habitp)
6372 (+ 94 (- 5 diff) (org-get-priority item)))
6374 'todo-state todo-state)
6375 (push item scheduled-items))))))
6376 (nreverse scheduled-items)))
6378 (defun org-agenda-get-blocks ()
6379 "Return the date-range information for agenda display."
6380 (let* ((props (list 'face nil
6381 'org-not-done-regexp org-not-done-regexp
6382 'org-todo-regexp org-todo-regexp
6383 'org-complex-heading-regexp org-complex-heading-regexp
6384 'mouse-face 'highlight
6386 (format "mouse-2 or RET jump to org file %s"
6387 (abbreviate-file-name buffer-file-name))))
6388 (regexp org-tr-regexp)
6389 (d0 (calendar-absolute-from-gregorian date))
6390 marker hdmarker ee txt d1 d2 s1 s2 category
6391 level todo-state tags pos head donep inherited-tags)
6392 (goto-char (point-min))
6393 (while (re-search-forward regexp nil t)
6397 (let ((start-time (match-string 1))
6398 (end-time (match-string 2)))
6399 (setq s1 (match-string 1)
6401 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6402 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6403 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6404 ;; Only allow days between the limits, because the normal
6405 ;; date stamps will catch the limits.
6407 (setq todo-state (org-get-todo-state))
6408 (setq donep (member todo-state org-done-keywords))
6409 (if (and donep org-agenda-skip-timestamp-if-done)
6411 (setq marker (org-agenda-new-marker (point))
6412 category (org-get-category))
6413 (if (not (re-search-backward org-outline-regexp-bol nil t))
6415 (goto-char (match-beginning 0))
6416 (setq hdmarker (org-agenda-new-marker (point))
6418 (or (eq org-agenda-show-inherited-tags 'always)
6419 (and (listp org-agenda-show-inherited-tags)
6420 (memq 'agenda org-agenda-show-inherited-tags))
6421 (and (eq org-agenda-show-inherited-tags t)
6422 (or (eq org-agenda-use-tag-inheritance t)
6423 (memq 'agenda org-agenda-use-tag-inheritance))))
6425 tags (org-get-tags-at nil (not inherited-tags)))
6426 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6427 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6428 (setq head (match-string 1))
6430 (if org-agenda-remove-timeranges-from-blocks
6432 "<" (regexp-quote s1) ".*?>"
6434 "<" (regexp-quote s2) ".*?>")
6436 (setq txt (org-agenda-format-item
6438 (nth (if (= d1 d2) 0 1)
6439 org-agenda-timerange-leaders)
6440 (1+ (- d0 d1)) (1+ (- d2 d1)))
6441 head level category tags
6442 (cond ((and (= d1 d0) (= d2 d0))
6443 (concat "<" start-time ">--<" end-time ">"))
6445 (concat "<" start-time ">"))
6447 (concat "<" end-time ">")))
6449 (org-add-props txt props
6450 'org-marker marker 'org-hd-marker hdmarker
6451 'type "block" 'date date
6453 'todo-state todo-state
6454 'priority (org-get-priority txt))
6457 ;; Sort the entries by expiration date.
6460 ;;; Agenda presentation and sorting
6462 (defvar org-prefix-has-time nil
6463 "A flag, set by `org-compile-prefix-format'.
6464 The flag is set if the currently compiled format contains a `%t'.")
6465 (defvar org-prefix-has-tag nil
6466 "A flag, set by `org-compile-prefix-format'.
6467 The flag is set if the currently compiled format contains a `%T'.")
6468 (defvar org-prefix-has-effort nil
6469 "A flag, set by `org-compile-prefix-format'.
6470 The flag is set if the currently compiled format contains a `%e'.")
6471 (defvar org-prefix-has-breadcrumbs nil
6472 "A flag, set by `org-compile-prefix-format'.
6473 The flag is set if the currently compiled format contains a `%b'.")
6474 (defvar org-prefix-category-length nil
6475 "Used by `org-compile-prefix-format' to remember the category field width.")
6476 (defvar org-prefix-category-max-length nil
6477 "Used by `org-compile-prefix-format' to remember the category field width.")
6479 (defun org-agenda-get-category-icon (category)
6480 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6481 (dolist (entry org-agenda-category-icon-alist)
6482 (when (org-string-match-p (car entry) category)
6483 (if (listp (cadr entry))
6484 (return (cadr entry))
6485 (return (apply 'create-image (cdr entry)))))))
6487 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6489 "Format TXT to be inserted into the agenda buffer.
6490 In particular, add the prefix and corresponding text properties.
6492 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6493 LEVEL may be a string to replace the `%l' specifier.
6494 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6495 category taken from local variable or file name. It will replace the `%c'
6496 specifier in the format.
6497 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6498 TXT for sorting of this entry, and for the `%t' specifier in the format.
6499 When DOTIME is a string, this string is searched for a time before TXT is.
6500 TAGS can be the tags of the headline.
6501 Any match of REMOVE-RE will be removed from TXT."
6502 ;; We keep the org-prefix-* variable values along with a compiled
6503 ;; formatter, so that multiple agendas existing at the same time do
6504 ;; not step on each other toes.
6506 ;; It was inconvenient to make these variables buffer local in
6507 ;; Agenda buffers, because this function expects to be called with
6508 ;; the buffer where item comes from being current, and not agenda
6510 (let* ((bindings (car org-prefix-format-compiled))
6511 (formatter (cadr org-prefix-format-compiled)))
6512 (loop for (var value) in bindings
6515 ;; Diary entries sometimes have extra whitespace at the beginning
6516 (setq txt (org-trim txt))
6518 ;; Fix the tags part in txt
6519 (setq txt (org-agenda-fix-displayed-tags
6521 org-agenda-show-inherited-tags
6522 org-agenda-hide-tags-regexp))
6524 (let* ((category (or category
6525 (if buffer-file-name
6526 (file-name-sans-extension
6527 (file-name-nondirectory buffer-file-name))
6529 (category-icon (org-agenda-get-category-icon category))
6530 (category-icon (if category-icon
6531 (propertize " " 'display category-icon)
6533 (effort (and (not (string= txt ""))
6534 (get-text-property 1 'effort txt)))
6535 ;; time, tag, effort are needed for the eval of the prefix format
6536 (tag (if tags (nth (1- (length tags)) tags) ""))
6538 (ts (if dotime (concat
6539 (if (stringp dotime) dotime "")
6540 (and org-agenda-search-headline-for-time txt))))
6541 (time-of-day (and dotime (org-get-time-of-day ts)))
6542 stamp plain s0 s1 s2 rtn srp l
6543 duration breadcrumbs)
6544 (and (derived-mode-p 'org-mode) buffer-file-name
6545 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6546 (when (and dotime time-of-day)
6547 ;; Extract starting and ending time and move them to prefix
6548 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6549 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6550 (setq s0 (match-string 0 ts)
6551 srp (and stamp (match-end 3))
6552 s1 (match-string (if plain 1 2) ts)
6553 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6555 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6556 ;; them, we might want to remove them there to avoid duplication.
6557 ;; The user can turn this off with a variable.
6558 (if (and org-prefix-has-time
6559 org-agenda-remove-times-when-in-prefix (or stamp plain)
6560 (string-match (concat (regexp-quote s0) " *") txt)
6561 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6562 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6563 (= (match-beginning 0) 0)
6565 (setq txt (replace-match "" nil nil txt))))
6566 ;; Normalize the time(s) to 24 hour
6567 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6568 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6570 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6571 (let (org-time-clocksum-use-effort-durations)
6572 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6574 (org-minutes-to-clocksum-string
6575 (+ (org-hh:mm-string-to-minutes s1)
6576 org-agenda-default-appointment-duration)))))
6578 ;; Compute the duration
6580 (setq duration (- (org-hh:mm-string-to-minutes s2)
6581 (org-hh:mm-string-to-minutes s1)))))
6583 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6585 ;; Tags are in the string
6586 (if (or (eq org-agenda-remove-tags t)
6587 (and org-agenda-remove-tags
6588 org-prefix-has-tag))
6589 (setq txt (replace-match "" t t txt))
6590 (setq txt (replace-match
6591 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6592 (match-string 2 txt))
6596 (while (string-match remove-re txt)
6597 (setq txt (replace-match "" t t txt))))
6599 ;; Set org-heading property on `txt' to mark the start of the
6601 (add-text-properties 0 (length txt) '(org-heading t) txt)
6603 ;; Prepare the variables needed in the eval of the compiled format
6604 (if org-prefix-has-breadcrumbs
6605 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6606 (let ((s (org-display-outline-path nil nil "->" t)))
6607 (if (eq "" s) "" (concat s "->"))))))
6608 (setq time (cond (s2 (concat
6609 (org-agenda-time-of-day-to-ampm-maybe s1)
6610 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6611 (if org-agenda-timegrid-use-ampm " ")))
6613 (org-agenda-time-of-day-to-ampm-maybe s1)
6614 (if org-agenda-timegrid-use-ampm
6618 extra (or (and (not habitp) extra) "")
6619 category (if (symbolp category) (symbol-name category) category)
6620 level (or level ""))
6621 (if (string-match org-bracket-link-regexp category)
6623 (setq l (if (match-end 3)
6624 (- (match-end 3) (match-beginning 3))
6625 (- (match-end 1) (match-beginning 1))))
6626 (when (< l (or org-prefix-category-length 0))
6627 (setq category (copy-sequence category))
6628 (org-add-props category nil
6629 'extra-space (make-string
6630 (- org-prefix-category-length l 1) ?\ ))))
6631 (if (and org-prefix-category-max-length
6632 (>= (length category) org-prefix-category-max-length))
6633 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6634 ;; Evaluate the compiled format
6635 (setq rtn (concat (eval formatter) txt))
6637 ;; And finally add the text properties
6638 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6639 (org-add-props rtn nil
6640 'org-category category
6641 'tags (mapcar 'org-downcase-keep-props tags)
6642 'org-highest-priority org-highest-priority
6643 'org-lowest-priority org-lowest-priority
6644 'time-of-day time-of-day
6646 'breadcrumbs breadcrumbs
6651 'format org-prefix-format-compiled
6654 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6655 "Remove tags string from TXT, and add a modified list of tags.
6656 The modified list may contain inherited tags, and tags matched by
6657 `org-agenda-hide-tags-regexp' will be removed."
6658 (when (or add-inherited hide-re)
6659 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6660 (setq txt (substring txt 0 (match-beginning 0))))
6663 (mapcar (lambda (tg)
6664 (if (or (and hide-re (string-match hide-re tg))
6665 (and (not add-inherited)
6666 (get-text-property 0 'inherited tg)))
6671 (let ((have-i (get-text-property 0 'inherited (car tags)))
6673 (setq txt (concat txt " :"
6676 (setq i (get-text-property 0 'inherited x))
6677 (if (and have-i (not i))
6683 (if have-i "::" ":"))))))
6686 (defun org-downcase-keep-props (s)
6687 (let ((props (text-properties-at 0 s)))
6688 (setq s (downcase s))
6689 (add-text-properties 0 (length s) props s)
6692 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6694 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6695 "Add a time-grid for agenda items which need it.
6697 LIST is the list of agenda items formatted by `org-agenda-list'.
6698 NDAYS is the span of the current agenda view.
6699 TODAYP is t when the current agenda view is on today."
6701 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6702 ((and todayp (member 'today (car org-agenda-time-grid))))
6703 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6704 ((member 'weekly (car org-agenda-time-grid)))
6705 (t (throw 'exit list)))
6706 (let* ((have (delq nil (mapcar
6707 (lambda (x) (get-text-property 1 'time-of-day x))
6709 (string (nth 1 org-agenda-time-grid))
6710 (gridtimes (nth 2 org-agenda-time-grid))
6711 (req (car org-agenda-time-grid))
6712 (remove (member 'remove-match req))
6714 (if (and (member 'require-timed req) (not have))
6715 ;; don't show empty grid
6717 (while (setq time (pop gridtimes))
6718 (unless (and remove (member time have))
6719 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6720 (push (org-agenda-format-item
6721 nil string nil "" nil
6722 (concat (substring time 0 -2) ":" (substring time -2)))
6725 2 (length (car new)) 'face 'org-time-grid (car new))))
6726 (when (and todayp org-agenda-show-current-time-in-grid)
6727 (push (org-agenda-format-item
6728 nil org-agenda-current-time-string nil "" nil
6729 (format-time-string "%H:%M "))
6732 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6734 (if (member 'time-up org-agenda-sorting-strategy-selected)
6736 (append list new)))))
6738 (defun org-compile-prefix-format (key)
6739 "Compile the prefix format into a Lisp form that can be evaluated.
6740 The resulting form and associated variable bindings is returned
6741 and stored in the variable `org-prefix-format-compiled'."
6742 (setq org-prefix-has-time nil
6743 org-prefix-has-tag nil
6744 org-prefix-category-length nil
6745 org-prefix-has-effort nil
6746 org-prefix-has-breadcrumbs nil)
6748 ((stringp org-agenda-prefix-format)
6749 org-agenda-prefix-format)
6750 ((assq key org-agenda-prefix-format)
6751 (cdr (assq key org-agenda-prefix-format)))
6752 (t " %-12:c%?-12t% s")))
6754 varform vars var e c f opt)
6755 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6757 (setq var (or (cdr (assoc (match-string 4 s)
6758 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6759 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6761 c (or (match-string 3 s) "")
6762 opt (match-beginning 1)
6763 start (1+ (match-beginning 0)))
6764 (if (equal var 'time) (setq org-prefix-has-time t))
6765 (if (equal var 'tag) (setq org-prefix-has-tag t))
6766 (if (equal var 'effort) (setq org-prefix-has-effort t))
6767 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6768 (setq f (concat "%" (match-string 2 s) "s"))
6769 (when (equal var 'category)
6770 (setq org-prefix-category-length
6771 (floor (abs (string-to-number (match-string 2 s)))))
6772 (setq org-prefix-category-max-length
6773 (let ((x (match-string 2 s)))
6775 (if (string-match "\\.[0-9]+" x)
6776 (string-to-number (substring (match-string 0 x) 1)))))))
6778 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6781 `(if (or (equal "" ,var) (equal nil ,var))
6783 (format ,f (concat ,var ,c))))
6785 `(format ,f (if (or (equal ,var "")
6786 (equal ,var nil)) ""
6787 (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6788 (setq s (replace-match "%s" t nil s))
6789 (push varform vars))
6790 (setq vars (nreverse vars))
6791 (with-current-buffer (or org-agenda-buffer (current-buffer))
6792 (setq org-prefix-format-compiled
6794 `((org-prefix-has-time ,org-prefix-has-time)
6795 (org-prefix-has-tag ,org-prefix-has-tag)
6796 (org-prefix-category-length ,org-prefix-category-length)
6797 (org-prefix-has-effort ,org-prefix-has-effort)
6798 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6799 `(format ,s ,@vars))))))
6801 (defun org-set-sorting-strategy (key)
6802 (if (symbolp (car org-agenda-sorting-strategy))
6804 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6805 (setq org-agenda-sorting-strategy-selected
6806 (or (cdr (assq key org-agenda-sorting-strategy))
6807 (cdr (assq 'agenda org-agenda-sorting-strategy))
6808 '(time-up category-keep priority-down)))))
6810 (defun org-get-time-of-day (s &optional string mod24)
6811 "Check string S for a time of day.
6812 If found, return it as a military time number between 0 and 2400.
6813 If not found, return nil.
6814 The optional STRING argument forces conversion into a 5 character wide string
6819 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6820 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6821 (not (eq (get-text-property 1 'face s) 'org-link)))
6822 (let* ((h (string-to-number (match-string 1 s)))
6823 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6824 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6825 (am-p (equal ampm "am"))
6826 (h1 (cond ((not ampm) h)
6827 ((= h 12) (if am-p 0 12))
6828 (t (+ h (if am-p 0 12)))))
6829 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6831 (t0 (+ (* 100 h2) m))
6832 (t1 (concat (if (>= h1 24) "+" " ")
6833 (if (and org-agenda-time-leading-zero
6834 (< t0 1000)) "0" "")
6835 (if (< t0 100) "0" "")
6836 (if (< t0 10) "0" "")
6837 (int-to-string t0))))
6838 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6840 (defvar org-agenda-before-sorting-filter-function nil
6841 "Function to be applied to agenda items prior to sorting.
6842 Prior to sorting also means just before they are inserted into the agenda.
6844 To aid sorting, you may revisit the original entries and add more text
6845 properties which will later be used by the sorting functions.
6847 The function should take a string argument, an agenda line.
6848 It has access to the text properties in that line, which contain among
6849 other things, the property `org-hd-marker' that points to the entry
6850 where the line comes from. Note that not all lines going into the agenda
6851 have this property, only most.
6853 The function should return the modified string. It is probably best
6854 to ONLY change text properties.
6856 You can also use this function as a filter, by returning nil for lines
6857 you don't want to have in the agenda at all. For this application, you
6858 could bind the variable in the options section of a custom command.")
6860 (defun org-agenda-finalize-entries (list &optional type)
6861 "Sort, limit and concatenate the LIST of agenda items.
6862 The optional argument TYPE tells the agenda type."
6863 (let ((max-effort (cond ((listp org-agenda-max-effort)
6864 (cdr (assoc type org-agenda-max-effort)))
6865 (t org-agenda-max-effort)))
6866 (max-todo (cond ((listp org-agenda-max-todos)
6867 (cdr (assoc type org-agenda-max-todos)))
6868 (t org-agenda-max-todos)))
6869 (max-tags (cond ((listp org-agenda-max-tags)
6870 (cdr (assoc type org-agenda-max-tags)))
6871 (t org-agenda-max-tags)))
6872 (max-entries (cond ((listp org-agenda-max-entries)
6873 (cdr (assoc type org-agenda-max-entries)))
6874 (t org-agenda-max-entries))))
6875 (when org-agenda-before-sorting-filter-function
6879 org-agenda-before-sorting-filter-function list))))
6880 (setq list (mapcar 'org-agenda-highlight-todo list)
6881 list (mapcar 'identity (sort list 'org-entries-lessp)))
6883 (setq list (org-agenda-limit-entries
6884 list 'effort-minutes max-effort
6885 (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
6888 (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
6890 (setq list (org-agenda-limit-entries list 'tags max-tags)))
6892 (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
6893 (mapconcat 'identity list "\n")))
6895 (defun org-agenda-limit-entries (list prop limit &optional fn)
6896 "Limit the number of agenda entries."
6897 (let ((include (and limit (< limit 0))))
6899 (let ((fun (or fn (lambda (p) (if p 1))))
6904 (let ((pval (funcall
6905 fun (get-text-property (1- (length e))
6907 (if pval (setq lim (+ lim pval)))
6908 (cond ((and pval (<= lim (abs limit))) e)
6909 ((and include (not pval)) e))))
6913 (defun org-agenda-limit-interactively (remove)
6914 "In agenda, interactively limit entries to various maximums."
6917 (progn (setq org-agenda-max-entries nil
6918 org-agenda-max-todos nil
6919 org-agenda-max-tags nil
6920 org-agenda-max-effort nil)
6922 (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
6923 (msg (cond ((= max ?E) "How many minutes? ")
6924 ((= max ?e) "How many entries? ")
6925 ((= max ?t) "How many TODO entries? ")
6926 ((= max ?T) "How many tagged entries? ")
6927 (t (user-error "Wrong input"))))
6928 (num (string-to-number (read-from-minibuffer msg))))
6929 (cond ((equal max ?e)
6930 (let ((org-agenda-max-entries num)) (org-agenda-redo)))
6932 (let ((org-agenda-max-todos num)) (org-agenda-redo)))
6934 (let ((org-agenda-max-tags num)) (org-agenda-redo)))
6936 (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
6937 (org-agenda-fit-window-to-buffer))
6939 (defun org-agenda-highlight-todo (x)
6940 (let ((org-done-keywords org-done-keywords-for-agenda)
6941 (case-fold-search nil)
6945 (beginning-of-line 1)
6946 (setq re (org-get-at-bol 'org-todo-regexp))
6947 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6948 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6949 (add-text-properties (match-beginning 0) (match-end 1)
6950 (list 'face (org-get-todo-face 1)))
6951 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6952 (delete-region (match-beginning 1) (1- (match-end 0)))
6953 (goto-char (match-beginning 1))
6954 (insert (format org-agenda-todo-keyword-format s)))))
6955 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6956 (setq re (get-text-property 0 'org-todo-regexp x))
6958 ;; Test `pl' because if there's no heading content,
6959 ;; there's no point matching to highlight. Note
6960 ;; that if we didn't test `pl' first, and there
6961 ;; happened to be no keyword from `org-todo-regexp'
6962 ;; on this heading line, then the `equal' comparison
6963 ;; afterwards would spuriously succeed in the case
6964 ;; where `pl' is nil -- causing an args-out-of-range
6965 ;; error when we try to add text properties to text
6966 ;; that isn't there.
6968 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6970 (add-text-properties
6971 (or (match-end 1) (match-end 0)) (match-end 0)
6972 (list 'face (org-get-todo-face (match-string 2 x)))
6975 (setq x (concat (substring x 0 (match-end 1))
6976 (format org-agenda-todo-keyword-format
6978 (org-add-props " " (text-properties-at 0 x))
6979 (substring x (match-end 3)))))))
6982 (defsubst org-cmp-values (a b property)
6983 "Compare the numeric value of text PROPERTY for string A and B."
6984 (let ((pa (or (get-text-property (1- (length a)) property a) 0))
6985 (pb (or (get-text-property (1- (length b)) property b) 0)))
6986 (cond ((> pa pb) +1)
6989 (defsubst org-cmp-effort (a b)
6990 "Compare the effort values of string A and B."
6991 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6992 (ea (or (get-text-property (1- (length a)) 'effort-minutes a) def))
6993 (eb (or (get-text-property (1- (length b)) 'effort-minutes b) def)))
6994 (cond ((> ea eb) +1)
6997 (defsubst org-cmp-category (a b)
6998 "Compare the string values of categories of strings A and B."
6999 (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
7000 (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
7001 (cond ((string-lessp ca cb) -1)
7002 ((string-lessp cb ca) +1))))
7004 (defsubst org-cmp-todo-state (a b)
7005 "Compare the todo states of strings A and B."
7006 (let* ((ma (or (get-text-property 1 'org-marker a)
7007 (get-text-property 1 'org-hd-marker a)))
7008 (mb (or (get-text-property 1 'org-marker b)
7009 (get-text-property 1 'org-hd-marker b)))
7010 (fa (and ma (marker-buffer ma)))
7011 (fb (and mb (marker-buffer mb)))
7013 (or (and fa (with-current-buffer fa org-todo-keywords-1))
7014 (and fb (with-current-buffer fb org-todo-keywords-1))))
7015 (ta (or (get-text-property 1 'todo-state a) ""))
7016 (tb (or (get-text-property 1 'todo-state b) ""))
7017 (la (- (length (member ta todo-kwds))))
7018 (lb (- (length (member tb todo-kwds))))
7019 (donepa (member ta org-done-keywords-for-agenda))
7020 (donepb (member tb org-done-keywords-for-agenda)))
7021 (cond ((and donepa (not donepb)) -1)
7022 ((and (not donepa) donepb) +1)
7026 (defsubst org-cmp-alpha (a b)
7027 "Compare the headlines, alphabetically."
7028 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
7029 (plb (text-property-any 0 (length b) 'org-heading t b))
7030 (ta (and pla (substring a pla)))
7031 (tb (and plb (substring b plb))))
7033 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
7034 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
7035 (setq ta (substring ta (match-end 0))))
7036 (setq ta (downcase ta)))
7038 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
7039 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
7040 (setq tb (substring tb (match-end 0))))
7041 (setq tb (downcase tb)))
7044 ((string-lessp ta tb) -1)
7045 ((string-lessp tb ta) +1))))
7047 (defsubst org-cmp-tag (a b)
7048 "Compare the string values of the first tags of A and B."
7049 (let ((ta (car (last (get-text-property 1 'tags a))))
7050 (tb (car (last (get-text-property 1 'tags b)))))
7053 ((string-lessp ta tb) -1)
7054 ((string-lessp tb ta) +1))))
7056 (defsubst org-cmp-time (a b)
7057 "Compare the time-of-day values of strings A and B."
7058 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
7059 (ta (or (get-text-property 1 'time-of-day a) def))
7060 (tb (or (get-text-property 1 'time-of-day b) def)))
7061 (cond ((< ta tb) -1)
7064 (defsubst org-cmp-ts (a b type)
7065 "Compare the timestamps values of entries A and B.
7066 When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
7067 \"timestamp_ia\", compare within each of these type. When TYPE
7068 is the empty string, compare all timestamps without respect of
7070 (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
7071 (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
7072 (get-text-property 1 'ts-date a))
7074 (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
7075 (get-text-property 1 'ts-date b))
7077 (cond ((< ta tb) -1)
7080 (defsubst org-cmp-habit-p (a b)
7081 "Compare the todo states of strings A and B."
7082 (let ((ha (get-text-property 1 'org-habit-p a))
7083 (hb (get-text-property 1 'org-habit-p b)))
7084 (cond ((and ha (not hb)) -1)
7085 ((and (not ha) hb) +1))))
7087 (defun org-entries-lessp (a b)
7088 "Predicate for sorting agenda entries."
7089 ;; The following variables will be used when the form is evaluated.
7090 ;; So even though the compiler complains, keep them.
7091 (let* ((ss org-agenda-sorting-strategy-selected)
7092 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
7093 (org-cmp-ts a b "")))
7094 (timestamp-down (if timestamp-up (- timestamp-up) nil))
7095 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
7096 (org-cmp-ts a b "scheduled")))
7097 (scheduled-down (if scheduled-up (- scheduled-up) nil))
7098 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
7099 (org-cmp-ts a b "deadline")))
7100 (deadline-down (if deadline-up (- deadline-up) nil))
7101 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
7102 (org-cmp-ts a b "timestamp_ia")))
7103 (tsia-down (if tsia-up (- tsia-up) nil))
7104 (ts-up (and (org-em 'ts-up 'ts-down ss)
7105 (org-cmp-ts a b "timestamp")))
7106 (ts-down (if ts-up (- ts-up) nil))
7107 (time-up (and (org-em 'time-up 'time-down ss)
7108 (org-cmp-time a b)))
7109 (time-down (if time-up (- time-up) nil))
7110 (stats-up (and (org-em 'stats-up 'stats-down ss)
7111 (org-cmp-values a b 'org-stats)))
7112 (stats-down (if stats-up (- stats-up) nil))
7113 (priority-up (and (org-em 'priority-up 'priority-down ss)
7114 (org-cmp-values a b 'priority)))
7115 (priority-down (if priority-up (- priority-up) nil))
7116 (effort-up (and (org-em 'effort-up 'effort-down ss)
7117 (org-cmp-effort a b)))
7118 (effort-down (if effort-up (- effort-up) nil))
7119 (category-up (and (or (org-em 'category-up 'category-down ss)
7120 (memq 'category-keep ss))
7121 (org-cmp-category a b)))
7122 (category-down (if category-up (- category-up) nil))
7123 (category-keep (if category-up +1 nil))
7124 (tag-up (and (org-em 'tag-up 'tag-down ss)
7126 (tag-down (if tag-up (- tag-up) nil))
7127 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
7128 (org-cmp-todo-state a b)))
7129 (todo-state-down (if todo-state-up (- todo-state-up) nil))
7130 (habit-up (and (org-em 'habit-up 'habit-down ss)
7131 (org-cmp-habit-p a b)))
7132 (habit-down (if habit-up (- habit-up) nil))
7133 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
7134 (org-cmp-alpha a b)))
7135 (alpha-down (if alpha-up (- alpha-up) nil))
7136 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
7137 user-defined-up user-defined-down)
7138 (if (and need-user-cmp org-agenda-cmp-user-defined
7139 (functionp org-agenda-cmp-user-defined))
7140 (setq user-defined-up
7141 (funcall org-agenda-cmp-user-defined a b)
7142 user-defined-down (if user-defined-up (- user-defined-up) nil)))
7144 (eval (cons 'or org-agenda-sorting-strategy-selected))
7145 '((-1 . t) (1 . nil) (nil . nil))))))
7147 ;;; Agenda restriction lock
7149 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
7150 "Overlay to mark the headline to which agenda commands are restricted.")
7151 (overlay-put org-agenda-restriction-lock-overlay
7152 'face 'org-agenda-restriction-lock)
7153 (overlay-put org-agenda-restriction-lock-overlay
7154 'help-echo "Agendas are currently limited to this subtree.")
7155 (org-detach-overlay org-agenda-restriction-lock-overlay)
7158 (defun org-agenda-set-restriction-lock (&optional type)
7159 "Set restriction lock for agenda, to current subtree or file.
7160 Restriction will be the file if TYPE is `file', or if type is the
7161 universal prefix \\='(4), or if the cursor is before the first headline
7162 in the file. Otherwise, restriction will be to the current subtree."
7164 (org-agenda-remove-restriction-lock 'noupdate)
7165 (and (equal type '(4)) (setq type 'file))
7168 ((org-at-heading-p) 'subtree)
7169 ((condition-case nil (org-back-to-heading t) (error nil))
7172 (if (eq type 'subtree)
7174 (setq org-agenda-restrict (current-buffer))
7175 (setq org-agenda-overriding-restriction 'subtree)
7176 (put 'org-agenda-files 'org-restrict
7177 (list (buffer-file-name (buffer-base-buffer))))
7178 (org-back-to-heading t)
7179 (move-overlay org-agenda-restriction-lock-overlay
7181 (if org-agenda-restriction-lock-highlight-subtree
7182 (save-excursion (org-end-of-subtree t t) (point))
7184 (move-marker org-agenda-restrict-begin (point))
7185 (move-marker org-agenda-restrict-end
7186 (save-excursion (org-end-of-subtree t t)))
7187 (message "Locking agenda restriction to subtree"))
7188 (put 'org-agenda-files 'org-restrict
7189 (list (buffer-file-name (buffer-base-buffer))))
7190 (setq org-agenda-restrict nil)
7191 (setq org-agenda-overriding-restriction 'file)
7192 (move-marker org-agenda-restrict-begin nil)
7193 (move-marker org-agenda-restrict-end nil)
7194 (message "Locking agenda restriction to file"))
7195 (setq current-prefix-arg nil)
7196 (org-agenda-maybe-redo))
7198 (defun org-agenda-remove-restriction-lock (&optional noupdate)
7199 "Remove the agenda restriction lock."
7201 (org-detach-overlay org-agenda-restriction-lock-overlay)
7202 (org-detach-overlay org-speedbar-restriction-lock-overlay)
7203 (setq org-agenda-overriding-restriction nil)
7204 (setq org-agenda-restrict nil)
7205 (put 'org-agenda-files 'org-restrict nil)
7206 (move-marker org-agenda-restrict-begin nil)
7207 (move-marker org-agenda-restrict-end nil)
7208 (setq current-prefix-arg nil)
7209 (message "Agenda restriction lock removed")
7210 (or noupdate (org-agenda-maybe-redo)))
7212 (defun org-agenda-maybe-redo ()
7213 "If there is any window showing the agenda view, update it."
7214 (let ((w (get-buffer-window (or org-agenda-this-buffer-name
7215 org-agenda-buffer-name)
7217 (w0 (selected-window)))
7222 (if org-agenda-overriding-restriction
7223 (message "Agenda view shifted to new %s restriction"
7224 org-agenda-overriding-restriction)
7225 (message "Agenda restriction lock removed")))))
7229 (defun org-agenda-check-type (error &rest types)
7230 "Check if agenda buffer is of allowed type.
7231 If ERROR is non-nil, throw an error, otherwise just return nil.
7232 Allowed types are `agenda' `timeline' `todo' `tags' `search'."
7233 (if (not org-agenda-type)
7234 (error "No Org agenda currently displayed")
7235 (if (memq org-agenda-type types)
7238 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7241 (defun org-agenda-Quit ()
7242 "Exit the agenda, killing the agenda buffer.
7243 Like `org-agenda-quit', but kill the buffer even when
7244 `org-agenda-sticky' is non-nil."
7248 (defun org-agenda-quit ()
7251 When `org-agenda-sticky' is non-nil, bury the agenda buffer
7252 instead of killing it.
7254 When `org-agenda-restore-windows-after-quit' is non-nil, restore
7255 the pre-agenda window configuration.
7257 When column view is active, exit column view instead of the
7260 (org-agenda--quit org-agenda-sticky))
7262 (defun org-agenda--quit (&optional bury)
7263 (if org-agenda-columns-active
7265 (let ((wconf org-agenda-pre-window-conf)
7266 (buf (current-buffer))
7267 (org-agenda-last-indirect-window
7268 (and (eq org-indirect-buffer-display 'other-window)
7269 org-agenda-last-indirect-buffer
7270 (get-buffer-window org-agenda-last-indirect-buffer))))
7272 ((eq org-agenda-window-setup 'other-frame)
7274 ((and org-agenda-restore-windows-after-quit
7276 ;; Maybe restore the pre-agenda window configuration. Reset
7277 ;; `org-agenda-pre-window-conf' before running
7278 ;; `set-window-configuration', which loses the current buffer.
7279 (setq org-agenda-pre-window-conf nil)
7280 (set-window-configuration wconf))
7282 (when org-agenda-last-indirect-window
7283 (delete-window org-agenda-last-indirect-window))
7284 (and (not (eq org-agenda-window-setup 'current-window))
7285 (not (one-window-p))
7288 ;; Set the agenda buffer as the current buffer instead of
7289 ;; passing it as an argument to `bury-buffer' so that
7290 ;; `bury-buffer' removes it from the window.
7291 (with-current-buffer buf
7294 (setq org-agenda-archives-mode nil
7295 org-agenda-buffer nil)))))
7297 (defun org-agenda-exit ()
7298 "Exit the agenda, killing Org buffers loaded by the agenda.
7299 Like `org-agenda-Quit', but kill any buffers that were created by
7300 the agenda. Org buffers visited directly by the user will not be
7301 touched. Also, exit the agenda even if it is in column view."
7303 (when org-agenda-columns-active
7305 (org-release-buffers org-agenda-new-buffers)
7306 (setq org-agenda-new-buffers nil)
7309 (defun org-agenda-kill-all-agenda-buffers ()
7310 "Kill all buffers in `org-agenda-mode'.
7311 This is used when toggling sticky agendas."
7314 (dolist (buf (buffer-list))
7315 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7317 (mapc 'kill-buffer blist)))
7319 (defun org-agenda-execute (arg)
7320 "Execute another agenda command, keeping same window.
7321 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7324 (let ((org-agenda-window-setup 'current-window))
7327 (defun org-agenda-redo (&optional all)
7328 "Rebuild possibly ALL agenda view(s) in the current buffer."
7330 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7331 (cpa (unless (eq all t) current-prefix-arg))
7332 (org-agenda-doing-sticky-redo org-agenda-sticky)
7333 (org-agenda-sticky nil)
7334 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7335 org-agenda-buffer-name))
7336 (org-agenda-keep-modes t)
7337 (tag-filter org-agenda-tag-filter)
7338 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7339 (top-hl-filter org-agenda-top-headline-filter)
7340 (cat-filter org-agenda-category-filter)
7341 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7342 (re-filter org-agenda-regexp-filter)
7343 (re-preset (get 'org-agenda-regexp-filter :preset-filter))
7344 (effort-filter org-agenda-effort-filter)
7345 (effort-preset (get 'org-agenda-effort-filter :preset-filter))
7346 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7347 (cols org-agenda-columns-active)
7348 (line (org-current-line))
7349 (window-line (- line (org-current-line (window-start))))
7350 (lprops (get 'org-agenda-redo-command 'org-lprops))
7351 (redo-cmd (get-text-property p 'org-redo-cmd))
7352 (last-args (get-text-property p 'org-last-args))
7353 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7354 (org-agenda-overriding-cmd-arguments
7356 (cond ((listp last-args)
7357 (cons (or cpa (car last-args)) (cdr last-args)))
7358 ((stringp last-args)
7360 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7361 (put 'org-agenda-tag-filter :preset-filter nil)
7362 (put 'org-agenda-category-filter :preset-filter nil)
7363 (put 'org-agenda-regexp-filter :preset-filter nil)
7364 (put 'org-agenda-effort-filter :preset-filter nil)
7365 (and cols (org-columns-quit))
7366 (message "Rebuilding agenda buffer...")
7368 (eval series-redo-cmd)
7369 (org-let lprops redo-cmd))
7370 (setq org-agenda-undo-list nil
7371 org-agenda-pending-undo-list nil
7372 org-agenda-tag-filter tag-filter
7373 org-agenda-category-filter cat-filter
7374 org-agenda-regexp-filter re-filter
7375 org-agenda-effort-filter effort-filter
7376 org-agenda-top-headline-filter top-hl-filter)
7377 (message "Rebuilding agenda buffer...done")
7378 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7379 (put 'org-agenda-category-filter :preset-filter cat-preset)
7380 (put 'org-agenda-regexp-filter :preset-filter re-preset)
7381 (put 'org-agenda-effort-filter :preset-filter effort-preset)
7382 (let ((tag (or tag-filter tag-preset))
7383 (cat (or cat-filter cat-preset))
7384 (effort (or effort-filter effort-preset))
7385 (re (or re-filter re-preset)))
7386 (when tag (org-agenda-filter-apply tag 'tag t))
7387 (when cat (org-agenda-filter-apply cat 'category))
7388 (when effort (org-agenda-filter-apply effort 'effort))
7389 (when re (org-agenda-filter-apply re 'regexp)))
7390 (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
7391 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7392 (org-goto-line line)
7393 (recenter window-line)))
7395 (defvar org-global-tags-completion-table nil)
7396 (defvar org-agenda-filter-form nil)
7397 (defvar org-agenda-filtered-by-category nil)
7399 (defun org-agenda-filter-by-category (strip)
7400 "Filter lines in the agenda buffer that have a specific category.
7401 The category is that of the current line.
7402 Without prefix argument, keep only the lines of that category.
7403 With a prefix argument, exclude the lines of that category.
7406 (if (and org-agenda-filtered-by-category
7407 org-agenda-category-filter)
7408 (org-agenda-filter-show-all-cat)
7409 (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
7412 (org-agenda-filter-apply
7413 (push (concat "-" cat) org-agenda-category-filter) 'category))
7415 (org-agenda-filter-apply
7416 (setq org-agenda-category-filter
7417 (list (concat "+" cat))) 'category))
7418 (t (error "No category at point"))))))
7420 (defun org-find-top-headline (&optional pos)
7421 "Find the topmost parent headline and return it."
7423 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7424 (if pos (goto-char pos))
7425 ;; Skip up to the topmost parent
7426 (while (ignore-errors (outline-up-heading 1) t))
7428 (nth 4 (org-heading-components))))))
7430 (defvar org-agenda-filtered-by-top-headline nil)
7431 (defun org-agenda-filter-by-top-headline (strip)
7432 "Keep only those lines that are descendants from the same top headline.
7433 The top headline is that of the current line."
7435 (if org-agenda-filtered-by-top-headline
7437 (setq org-agenda-filtered-by-top-headline nil
7438 org-agenda-top-headline-filter nil)
7439 (org-agenda-filter-show-all-top-filter))
7440 (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
7441 (if toph (org-agenda-filter-top-headline-apply toph strip)
7442 (error "No top-level headline at point")))))
7444 (defvar org-agenda-regexp-filter nil)
7445 (defun org-agenda-filter-by-regexp (strip)
7446 "Filter agenda entries by a regular expression.
7447 Regexp filters are cumulative.
7448 With no prefix argument, keep entries matching the regexp.
7449 With one prefix argument, filter out entries matching the regexp.
7450 With two prefix arguments, remove the regexp filters."
7452 (if (not (equal strip '(16)))
7453 (let ((flt (concat (if (equal strip '(4)) "-" "+")
7454 (read-from-minibuffer
7455 (if (equal strip '(4))
7456 "Filter out entries matching regexp: "
7457 "Narrow to entries matching regexp: ")))))
7458 (push flt org-agenda-regexp-filter)
7459 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
7460 (org-agenda-filter-show-all-re)
7461 (message "Regexp filter removed")))
7463 (defvar org-agenda-effort-filter nil)
7464 (defun org-agenda-filter-by-effort (strip)
7465 "Filter agenda entries by effort.
7466 With no prefix argument, keep entries matching the effort condition.
7467 With one prefix argument, filter out entries matching the condition.
7468 With two prefix arguments, remove the effort filters."
7470 (cond ((member strip '(nil 4))
7471 (let ((efforts (org-split-string
7472 (or (cdr (assoc (concat org-effort-property "_ALL")
7473 org-global-properties))
7474 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7478 (while (not (member op '(?< ?> ?=)))
7479 (setq op (read-char-exclusive "Effort operator? (> = or <)")))
7480 (loop for i from 0 to 9 do
7484 (if (= i 9) "0" (int-to-string (1+ i)))
7485 "]" (nth i efforts))))
7486 (message "Effort %s%s" (char-to-string op) effort-prompt)
7487 (while (or (< eff 0) (> eff 9))
7488 (setq eff (string-to-number (char-to-string (read-char-exclusive)))))
7489 (setq org-agenda-effort-filter
7490 (list (concat (if strip "-" "+")
7491 (char-to-string op) (nth (1- eff) efforts))))
7492 (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
7493 (t (org-agenda-filter-show-all-effort)
7494 (message "Effort filter removed"))))
7496 (defun org-agenda-filter-remove-all ()
7497 "Remove all filters from the current agenda buffer."
7499 (when org-agenda-tag-filter
7500 (org-agenda-filter-show-all-tag))
7501 (when org-agenda-category-filter
7502 (org-agenda-filter-show-all-cat))
7503 (when org-agenda-regexp-filter
7504 (org-agenda-filter-show-all-re))
7505 (when org-agenda-top-headline-filter
7506 (org-agenda-filter-show-all-top-filter))
7507 (when org-agenda-effort-filter
7508 (org-agenda-filter-show-all-effort))
7509 (org-agenda-finalize))
7511 (defun org-agenda-filter-by-tag (arg &optional char exclude)
7512 "Keep only those lines in the agenda buffer that have a specific tag.
7513 The tag is selected with its fast selection letter, as
7514 configured. With a single \\[universal-argument] prefix ARG,
7515 exclude the agenda search. With a double \\[universal-argument]
7516 prefix ARG, filter the literal tag. I.e. don't filter on all its
7519 A lisp caller can specify CHAR. EXCLUDE means that the new tag should be
7520 used to exclude the search - the interactive user can also press `-' or `+'
7521 to switch between filtering and excluding."
7523 (let* ((alist org-tag-alist-for-agenda)
7524 (tag-chars (mapconcat
7525 (lambda (x) (if (and (not (symbolp (car x)))
7527 (char-to-string (cdr x))
7529 org-tag-alist-for-agenda ""))
7530 (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
7531 (string-to-list tag-chars)))
7532 (exclude (or exclude (equal arg '(4))))
7533 (expand (not (equal arg '(16))))
7534 (inhibit-read-only t)
7535 (current org-agenda-tag-filter)
7538 (while (not (memq char valid-char-list))
7540 "%s by tag [%s ], [TAB], %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
7541 (if exclude "Exclude" "Filter") tag-chars
7542 (if org-agenda-auto-exclude-function "[RET], " "")
7543 (if expand "" ", no grouptag expand"))
7544 (setq char (read-char-exclusive))
7545 ;; Excluding or filtering down
7546 (cond ((eq char ?-) (setq exclude t))
7547 ((eq char ?+) (setq exclude nil)))))
7549 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7550 (setq-local org-global-tags-completion-table
7551 (org-global-tags-completion-table)))
7552 (let ((completion-ignore-case t))
7553 (setq tag (completing-read
7554 "Tag: " org-global-tags-completion-table))))
7557 (org-agenda-filter-show-all-tag)
7558 (when org-agenda-auto-exclude-function
7559 (setq org-agenda-tag-filter nil)
7560 (dolist (tag (org-agenda-get-represented-tags))
7561 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7563 (push modifier org-agenda-tag-filter))))
7564 (if (not (null org-agenda-tag-filter))
7565 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
7567 (org-agenda-filter-show-all-tag)
7568 (when (get 'org-agenda-tag-filter :preset-filter)
7569 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
7571 (setq org-agenda-tag-filter
7572 (mapcar (lambda(tag) (concat "+" tag))
7573 (org-get-at-bol 'tags)))
7574 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
7575 ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
7577 (setq a (rassoc char alist))
7578 (and tag (setq a (cons tag nil))))
7579 (org-agenda-filter-show-all-tag)
7581 (setq org-agenda-tag-filter
7582 (cons (concat (if exclude "-" "+") tag)
7584 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
7585 (t (error "Invalid tag selection character %c" char)))))
7587 (defun org-agenda-get-represented-tags ()
7588 "Get a list of all tags currently represented in the agenda."
7591 (goto-char (point-min))
7592 (while (setq p (next-single-property-change (point) 'tags))
7594 (mapc (lambda (x) (add-to-list 'tags x))
7595 (get-text-property (point) 'tags))))
7599 (defun org-agenda-filter-make-matcher (filter type &optional expand)
7600 "Create the form that tests a line for agenda filter. Optional
7601 argument EXPAND can be used for the TYPE tag and will expand the
7602 tags in the FILTER if any of the tags in FILTER are grouptags."
7609 (append (get 'org-agenda-tag-filter :preset-filter)
7612 (let ((op (string-to-char x)))
7613 (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
7615 (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
7618 ((eq type 'category)
7621 (append (get 'org-agenda-category-filter :preset-filter)
7624 (if (equal "-" (substring x 0 1))
7625 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7626 (setq f1 (list 'equal (substring x 1) 'cat)))
7632 (append (get 'org-agenda-regexp-filter :preset-filter)
7635 (if (equal "-" (substring x 0 1))
7636 (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
7637 (setq f1 (list 'string-match (substring x 1) 'txt)))
7643 (append (get 'org-agenda-effort-filter :preset-filter)
7646 (push (org-agenda-filter-effort-form x) f))))
7647 (cons 'and (nreverse f))))
7649 (defun org-agenda-filter-make-matcher-tag-exp (tags op)
7650 "Return a form associated to tag-expression TAGS.
7651 Build a form testing a line for agenda filter for
7652 tag-expressions. OP is an operator of type CHAR that allows the
7653 function to set the right switches in the returned form."
7655 ;; Any of the expressions can match if OP is +, all must match if
7656 ;; the operator is -.
7657 (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
7658 (let* ((tag (substring x 1))
7660 ((string= "" tag) '(not tags))
7661 ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
7663 (list 'org-match-any-p (substring tag 1 -1) 'tags))
7664 (t (list 'member (downcase tag) 'tags)))))
7665 (push (if (eq op ?-) (list 'not f) f) form)))))
7667 (defun org-agenda-filter-effort-form (e)
7668 "Return the form to compare the effort of the current line with what E says.
7669 E looks like \"+<2:25\"."
7671 (setq e (substring e 1))
7672 (setq op (string-to-char e) e (substring e 1))
7673 (setq op (cond ((equal op ?<) '<=)
7677 (list 'org-agenda-compare-effort (list 'quote op)
7678 (org-duration-string-to-minutes e))))
7680 (defun org-agenda-compare-effort (op value)
7681 "Compare the effort of the current line with VALUE, using OP.
7682 If the line does not have an effort defined, return nil."
7683 (let ((eff (org-get-at-eol 'effort-minutes 1)))
7684 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 -1))
7687 (defun org-agenda-filter-expand-tags (filter &optional no-operator)
7688 "Expand group tags in FILTER for the agenda.
7689 When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
7691 (let ((case-fold-search t) rtn)
7695 (if (string-match "^\\([+-]\\)\\(.+\\)" f)
7696 (setq dir (match-string 1 f) f0 (match-string 2 f))
7697 (setq dir (if no-operator "" "+") f0 f))
7698 (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
7699 (org-tags-expand f0 t t))
7705 (defun org-agenda-filter-apply (filter type &optional expand)
7706 "Set FILTER as the new agenda filter and apply it. Optional
7707 argument EXPAND can be used for the TYPE tag and will expand the
7708 tags in the FILTER if any of the tags in FILTER are grouptags."
7709 ;; Deactivate `org-agenda-entry-text-mode' when filtering
7710 (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
7712 (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
7713 ;; Only set `org-agenda-filtered-by-category' to t when a unique
7714 ;; category is used as the filter:
7715 (setq org-agenda-filtered-by-category
7716 (and (eq type 'category)
7717 (not (equal (substring (car filter) 0 1) "-"))))
7718 (org-agenda-set-mode-name)
7720 (goto-char (point-min))
7722 (if (org-get-at-bol 'org-marker)
7724 (setq tags (org-get-at-bol 'tags)
7725 cat (org-get-at-eol 'org-category 1)
7726 txt (org-get-at-bol 'txt))
7727 (if (not (eval org-agenda-filter-form))
7728 (org-agenda-filter-hide-line type))
7729 (beginning-of-line 2))
7730 (beginning-of-line 2))))
7731 (if (get-char-property (point) 'invisible)
7732 (ignore-errors (org-agenda-previous-line)))))
7734 (defun org-agenda-filter-top-headline-apply (hl &optional negative)
7735 "Filter by top headline HL."
7736 (org-agenda-set-mode-name)
7738 (goto-char (point-min))
7740 (let* ((pos (org-get-at-bol 'org-hd-marker))
7741 (tophl (and pos (org-find-top-headline pos))))
7742 (if (and tophl (funcall (if negative 'identity 'not)
7743 (string= hl tophl)))
7744 (org-agenda-filter-hide-line 'top-headline)))
7745 (beginning-of-line 2)))
7746 (if (get-char-property (point) 'invisible)
7747 (org-agenda-previous-line))
7748 (setq org-agenda-top-headline-filter hl
7749 org-agenda-filtered-by-top-headline t))
7751 (defun org-agenda-filter-hide-line (type)
7752 "Hide lines with TYPE in the agenda buffer."
7753 (let* ((b (max (point-min) (1- (point-at-bol))))
7755 (let ((inhibit-read-only t))
7756 (add-text-properties
7757 b e `(invisible org-filtered org-filter-type ,type)))))
7759 (defun org-agenda-remove-filter (type)
7761 "Remove filter of type TYPE from the agenda buffer."
7763 (goto-char (point-min))
7764 (let ((inhibit-read-only t) pos)
7765 (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
7767 (remove-text-properties
7768 (point) (next-single-property-change (point) 'org-filter-type)
7769 `(invisible org-filtered org-filter-type ,type))))
7770 (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
7771 (setq org-agenda-filter-form nil)
7772 (org-agenda-set-mode-name)
7773 (org-agenda-finalize)))
7775 (defun org-agenda-filter-show-all-tag nil
7776 (org-agenda-remove-filter 'tag))
7777 (defun org-agenda-filter-show-all-re nil
7778 (org-agenda-remove-filter 'regexp))
7779 (defun org-agenda-filter-show-all-effort nil
7780 (org-agenda-remove-filter 'effort))
7781 (defun org-agenda-filter-show-all-cat nil
7782 (org-agenda-remove-filter 'category))
7783 (defun org-agenda-filter-show-all-top-filter nil
7784 (org-agenda-remove-filter 'top-headline))
7786 (defun org-agenda-manipulate-query-add ()
7787 "Manipulate the query by adding a search term with positive selection.
7788 Positive selection means the term must be matched for selection of an entry."
7790 (org-agenda-manipulate-query ?\[))
7791 (defun org-agenda-manipulate-query-subtract ()
7792 "Manipulate the query by adding a search term with negative selection.
7793 Negative selection means term must not be matched for selection of an entry."
7795 (org-agenda-manipulate-query ?\]))
7796 (defun org-agenda-manipulate-query-add-re ()
7797 "Manipulate the query by adding a search regexp with positive selection.
7798 Positive selection means the regexp must match for selection of an entry."
7800 (org-agenda-manipulate-query ?\{))
7801 (defun org-agenda-manipulate-query-subtract-re ()
7802 "Manipulate the query by adding a search regexp with negative selection.
7803 Negative selection means regexp must not match for selection of an entry."
7805 (org-agenda-manipulate-query ?\}))
7806 (defun org-agenda-manipulate-query (char)
7808 ((memq org-agenda-type '(timeline agenda))
7809 (let ((org-agenda-include-inactive-timestamps t))
7811 (message "Display now includes inactive timestamps as well"))
7812 ((eq org-agenda-type 'search)
7814 'org-agenda-query-string
7815 (if org-agenda-last-search-view-search-was-boolean
7816 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7817 (?\{ . " +{}") (?\} . " -{}"))))
7819 (setq org-agenda-redo-command
7820 (list 'org-search-view
7821 (car (get-text-property (min (1- (point-max)) (point))
7823 org-agenda-query-string
7824 (+ (length org-agenda-query-string)
7825 (if (member char '(?\{ ?\})) 0 1))))
7826 (set-register org-agenda-query-register org-agenda-query-string)
7827 (let ((org-agenda-overriding-arguments
7828 (cdr org-agenda-redo-command)))
7830 (t (error "Cannot manipulate query for %s-type agenda buffers"
7833 (defun org-add-to-string (var string)
7834 (set var (concat (symbol-value var) string)))
7836 (defun org-agenda-goto-date (span)
7837 "Jump to DATE in agenda."
7839 (let* ((org-read-date-prefer-future
7840 (eval org-agenda-jump-prefer-future))
7841 (date (org-read-date))
7842 (day (time-to-days (org-time-string-to-time date)))
7843 (org-agenda-sticky-orig org-agenda-sticky)
7844 (org-agenda-buffer-tmp-name (buffer-name))
7845 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7846 (0-arg (or current-prefix-arg (car args)))
7847 (2-arg (nth 2 args))
7848 (with-hour-p (nth 4 org-agenda-redo-command))
7849 (newcmd (list 'org-agenda-list 0-arg date
7850 (org-agenda-span-to-ndays
7851 2-arg (org-time-string-to-absolute date))
7853 (newargs (cdr newcmd))
7854 (inhibit-read-only t)
7856 (if (not (org-agenda-check-type t 'agenda))
7857 (error "Not available in non-agenda views")
7858 (add-text-properties (point-min) (point-max)
7859 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7861 (goto-char (point-min))
7862 (while (not (or (= (or (get-text-property (point) 'day) 0) day)
7863 (save-excursion (move-beginning-of-line 2) (eobp))))
7864 (move-beginning-of-line 2))
7865 (setq org-agenda-sticky org-agenda-sticky-orig
7866 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7868 (defun org-agenda-goto-today ()
7871 (org-agenda-check-type t 'timeline 'agenda)
7872 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7873 (curspan (nth 2 args))
7874 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7876 (tdpos (goto-char tdpos))
7877 ((eq org-agenda-type 'agenda)
7878 (let* ((sd (org-agenda-compute-starting-span
7879 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7880 (org-agenda-overriding-arguments args))
7881 (setf (nth 1 org-agenda-overriding-arguments) sd)
7883 (org-agenda-find-same-or-today-or-agenda)))
7884 (t (error "Cannot find today")))))
7886 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7888 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7889 (text-property-any (point-min) (point-max) 'org-today t)
7890 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7891 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7892 (org-agenda-backward-block))
7895 (defun org-agenda-backward-block ()
7896 "Move backward by one agenda block."
7898 (org-agenda-forward-block 'backward))
7900 (defun org-agenda-forward-block (&optional backward)
7901 "Move forward by one agenda block.
7902 When optional argument BACKWARD is set, go backward"
7904 (cond ((not (derived-mode-p 'org-agenda-mode))
7906 "Cannot execute this command outside of org-agenda-mode buffers"))
7907 ((looking-at (if backward "\\`" "\\'"))
7908 (message "Already at the %s block" (if backward "first" "last")))
7909 (t (let ((pos (prog1 (point)
7910 (ignore-errors (if backward (backward-char 1)
7911 (move-end-of-line 1)))))
7913 'previous-single-property-change
7914 'next-single-property-change))
7916 (while (and (setq dest (funcall
7917 f (point) 'org-agenda-structural-header))
7918 (not (get-text-property
7919 (point) 'org-agenda-structural-header)))
7922 (if moved (move-beginning-of-line 1)
7923 (goto-char (if backward (point-min) (point-max)))
7924 (move-beginning-of-line 1)
7925 (message "No %s block" (if backward "previous" "further")))))))
7927 (defun org-agenda-later (arg)
7928 "Go forward in time by the current span.
7929 With prefix ARG, go forward that many times the current span."
7931 (org-agenda-check-type t 'agenda)
7932 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7933 (span (or (nth 2 args) org-agenda-current-span))
7934 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7935 (greg (calendar-gregorian-from-absolute sd))
7936 (cnt (org-get-at-bol 'org-day-cnt))
7940 (setq sd (+ (* span arg) sd)))
7942 (setq sd (+ arg sd)))
7944 (setq sd (+ (* 7 arg) sd)))
7945 ((eq span 'fortnight)
7946 (setq sd (+ (* 14 arg) sd)))
7948 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7949 sd (calendar-absolute-from-gregorian greg2))
7950 (setcar greg2 (1+ (car greg2))))
7952 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7953 sd (calendar-absolute-from-gregorian greg2))
7954 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7956 (setq sd (+ (* span arg) sd))))
7957 (let ((org-agenda-overriding-cmd
7958 ;; `cmd' may have been set by `org-agenda-run-series' which
7959 ;; uses `org-agenda-overriding-cmd' to decide whether
7960 ;; overriding is allowed for `cmd'
7961 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7962 (org-agenda-overriding-arguments
7963 (list (car args) sd span)))
7965 (org-agenda-find-same-or-today-or-agenda cnt))))
7967 (defun org-agenda-earlier (arg)
7968 "Go backward in time by the current span.
7969 With prefix ARG, go backward that many times the current span."
7971 (org-agenda-later (- arg)))
7973 (defun org-agenda-view-mode-dispatch ()
7974 "Call one of the view mode commands."
7976 (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
7977 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7978 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7979 (let ((a (read-char-exclusive)))
7981 (?\ (call-interactively 'org-agenda-reset-view))
7982 (?d (call-interactively 'org-agenda-day-view))
7983 (?w (call-interactively 'org-agenda-week-view))
7984 (?t (call-interactively 'org-agenda-fortnight-view))
7985 (?m (call-interactively 'org-agenda-month-view))
7986 (?y (call-interactively 'org-agenda-year-view))
7987 (?l (call-interactively 'org-agenda-log-mode))
7988 (?L (org-agenda-log-mode '(4)))
7989 (?c (org-agenda-log-mode 'clockcheck))
7990 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7991 (?a (call-interactively 'org-agenda-archives-mode))
7992 (?A (org-agenda-archives-mode 'files))
7993 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7994 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7995 (?G (call-interactively 'org-agenda-toggle-time-grid))
7996 (?D (call-interactively 'org-agenda-toggle-diary))
7997 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7998 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7999 (org-agenda-check-type t 'timeline 'agenda)
8001 (message "Display now includes inactive timestamps as well"))
8002 (?q (message "Abort"))
8003 (otherwise (error "Invalid key" )))))
8005 (defun org-agenda-reset-view ()
8006 "Switch to default view for agenda."
8008 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
8009 (defun org-agenda-day-view (&optional day-of-month)
8010 "Switch to daily view for agenda.
8011 With argument DAY-OF-MONTH, switch to that day of the month."
8013 (org-agenda-change-time-span 'day day-of-month))
8014 (defun org-agenda-week-view (&optional iso-week)
8015 "Switch to daily view for agenda.
8016 With argument ISO-WEEK, switch to the corresponding ISO week.
8017 If ISO-WEEK has more then 2 digits, only the last two encode the
8018 week. Any digits before this encode a year. So 200712 means
8019 week 12 of year 2007. Years in the range 1938-2037 can also be
8020 written as 2-digit years."
8022 (org-agenda-change-time-span 'week iso-week))
8023 (defun org-agenda-fortnight-view (&optional iso-week)
8024 "Switch to daily view for agenda.
8025 With argument ISO-WEEK, switch to the corresponding ISO week.
8026 If ISO-WEEK has more then 2 digits, only the last two encode the
8027 week. Any digits before this encode a year. So 200712 means
8028 week 12 of year 2007. Years in the range 1938-2037 can also be
8029 written as 2-digit years."
8031 (org-agenda-change-time-span 'fortnight iso-week))
8032 (defun org-agenda-month-view (&optional month)
8033 "Switch to monthly view for agenda.
8034 With argument MONTH, switch to that month."
8036 (org-agenda-change-time-span 'month month))
8037 (defun org-agenda-year-view (&optional year)
8038 "Switch to yearly view for agenda.
8039 With argument YEAR, switch to that year.
8040 If MONTH has more then 2 digits, only the last two encode the
8041 month. Any digits before this encode a year. So 200712 means
8042 December year 2007. Years in the range 1938-2037 can also be
8043 written as 2-digit years."
8046 (setq year (org-small-year-to-year year)))
8047 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
8048 (org-agenda-change-time-span 'year year)
8051 (defun org-agenda-change-time-span (span &optional n)
8052 "Change the agenda view to SPAN.
8053 SPAN may be `day', `week', `fortnight', `month', `year'."
8054 (org-agenda-check-type t 'agenda)
8055 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
8056 (curspan (nth 2 args)))
8057 (if (and (not n) (equal curspan span))
8058 (error "Viewing span is already \"%s\"" span))
8059 (let* ((sd (or (org-get-at-bol 'day)
8062 (sd (org-agenda-compute-starting-span sd span n))
8063 (org-agenda-overriding-cmd
8064 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
8065 (org-agenda-overriding-arguments
8066 (list (car args) sd span)))
8068 (org-agenda-find-same-or-today-or-agenda))
8069 (org-agenda-set-mode-name)
8070 (message "Switched to %s view" span)))
8072 (defun org-agenda-compute-starting-span (sd span &optional n)
8073 "Compute starting date for agenda.
8074 SPAN may be `day', `week', `fortnight', `month', `year'. The return value
8075 is a cons cell with the starting date and the number of days,
8076 so that the date SD will be in that range."
8077 (let* ((greg (calendar-gregorian-from-absolute sd))
8084 (setq sd (+ (calendar-absolute-from-gregorian
8087 ((or (eq span 'week) (eq span 'fortnight))
8088 (let* ((nt (calendar-day-of-week
8089 (calendar-gregorian-from-absolute sd)))
8090 (d (if org-agenda-start-on-weekday
8091 (- nt org-agenda-start-on-weekday)
8094 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
8098 (setq y1 (org-small-year-to-year (/ n 100))
8101 (calendar-iso-to-absolute
8103 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
8106 (when (and n (> n 99))
8107 (setq y1 (org-small-year-to-year (/ n 100))
8109 (setq sd (calendar-absolute-from-gregorian
8110 (list (or n mg) 1 (or y1 yg))))))
8112 (setq sd (calendar-absolute-from-gregorian
8113 (list 1 1 (or n yg))))))
8116 (defun org-agenda-next-date-line (&optional arg)
8117 "Jump to the next line indicating a date in agenda buffer."
8119 (org-agenda-check-type t 'agenda 'timeline)
8120 (beginning-of-line 1)
8121 ;; This does not work if user makes date format that starts with a blank
8122 (if (looking-at "^\\S-") (forward-char 1))
8123 (if (not (re-search-forward "^\\S-" nil t arg))
8126 (error "No next date after this line in this buffer")))
8127 (goto-char (match-beginning 0)))
8129 (defun org-agenda-previous-date-line (&optional arg)
8130 "Jump to the previous line indicating a date in agenda buffer."
8132 (org-agenda-check-type t 'agenda 'timeline)
8133 (beginning-of-line 1)
8134 (if (not (re-search-backward "^\\S-" nil t arg))
8135 (error "No previous date before this line in this buffer")))
8137 ;; Initialize the highlight
8138 (defvar org-hl (make-overlay 1 1))
8139 (overlay-put org-hl 'face 'highlight)
8141 (defun org-highlight (begin end &optional buffer)
8142 "Highlight a region with overlay."
8143 (move-overlay org-hl begin end (or buffer (current-buffer))))
8145 (defun org-unhighlight ()
8146 "Detach overlay INDEX."
8147 (org-detach-overlay org-hl))
8149 (defun org-unhighlight-once ()
8150 "Remove the highlight from its position, and this function from the hook."
8151 (remove-hook 'pre-command-hook 'org-unhighlight-once)
8154 (defvar org-agenda-pre-follow-window-conf nil)
8155 (defun org-agenda-follow-mode ()
8156 "Toggle follow mode in an agenda buffer."
8158 (unless org-agenda-follow-mode
8159 (setq org-agenda-pre-follow-window-conf
8160 (current-window-configuration)))
8161 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
8162 (unless org-agenda-follow-mode
8163 (set-window-configuration org-agenda-pre-follow-window-conf))
8164 (org-agenda-set-mode-name)
8165 (org-agenda-do-context-action)
8166 (message "Follow mode is %s"
8167 (if org-agenda-follow-mode "on" "off")))
8169 (defun org-agenda-entry-text-mode (&optional arg)
8170 "Toggle entry text mode in an agenda buffer."
8172 (if (or org-agenda-tag-filter
8173 org-agenda-category-filter
8174 org-agenda-regexp-filter
8175 org-agenda-top-headline-filter)
8176 (user-error "Can't show entry text in filtered views")
8177 (setq org-agenda-entry-text-mode (or (integerp arg)
8178 (not org-agenda-entry-text-mode)))
8179 (org-agenda-entry-text-hide)
8180 (and org-agenda-entry-text-mode
8181 (let ((org-agenda-entry-text-maxlines
8182 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8183 (org-agenda-entry-text-show)))
8184 (org-agenda-set-mode-name)
8185 (message "Entry text mode is %s%s"
8186 (if org-agenda-entry-text-mode "on" "off")
8187 (if (not org-agenda-entry-text-mode) ""
8188 (format " (maximum number of lines is %d)"
8189 (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
8191 (defun org-agenda-clockreport-mode ()
8192 "Toggle clocktable mode in an agenda buffer."
8194 (org-agenda-check-type t 'agenda)
8195 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
8196 (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
8197 (org-agenda-set-mode-name)
8199 (message "Clocktable mode is %s"
8200 (if org-agenda-clockreport-mode "on" "off")))
8202 (defun org-agenda-log-mode (&optional special)
8203 "Toggle log mode in an agenda buffer.
8204 With argument SPECIAL, show all possible log items, not only the ones
8205 configured in `org-agenda-log-mode-items'.
8206 With a double \\[universal-argument] prefix arg, show *only* \
8207 log items, nothing else."
8209 (org-agenda-check-type t 'agenda 'timeline)
8210 (setq org-agenda-show-log
8212 ((equal special '(16)) 'only)
8213 ((eq special 'clockcheck)
8214 (if (eq org-agenda-show-log 'clockcheck)
8216 (special '(closed clock state))
8217 (t (not org-agenda-show-log))))
8218 (setq org-agenda-start-with-log-mode org-agenda-show-log)
8219 (org-agenda-set-mode-name)
8221 (message "Log mode is %s"
8222 (if org-agenda-show-log "on" "off")))
8224 (defun org-agenda-archives-mode (&optional with-files)
8225 "Toggle inclusion of items in trees marked with :ARCHIVE:.
8226 When called with a prefix argument, include all archive files as well."
8228 (setq org-agenda-archives-mode
8229 (if with-files t (if org-agenda-archives-mode nil 'trees)))
8230 (org-agenda-set-mode-name)
8235 ((eq org-agenda-archives-mode nil)
8236 "No archives are included")
8237 ((eq org-agenda-archives-mode 'trees)
8238 (format "Trees with :%s: tag are included" org-archive-tag))
8239 ((eq org-agenda-archives-mode t)
8240 (format "Trees with :%s: tag and all active archive files are included"
8241 org-archive-tag)))))
8243 (defun org-agenda-toggle-diary ()
8244 "Toggle diary inclusion in an agenda buffer."
8246 (org-agenda-check-type t 'agenda)
8247 (setq org-agenda-include-diary (not org-agenda-include-diary))
8249 (org-agenda-set-mode-name)
8250 (message "Diary inclusion turned %s"
8251 (if org-agenda-include-diary "on" "off")))
8253 (defun org-agenda-toggle-deadlines ()
8254 "Toggle inclusion of entries with a deadline in an agenda buffer."
8256 (org-agenda-check-type t 'agenda)
8257 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
8259 (org-agenda-set-mode-name)
8260 (message "Deadlines inclusion turned %s"
8261 (if org-agenda-include-deadlines "on" "off")))
8263 (defun org-agenda-toggle-time-grid ()
8264 "Toggle time grid in an agenda buffer."
8266 (org-agenda-check-type t 'agenda)
8267 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
8269 (org-agenda-set-mode-name)
8270 (message "Time-grid turned %s"
8271 (if org-agenda-use-time-grid "on" "off")))
8273 (defun org-agenda-set-mode-name ()
8274 "Set the mode name to indicate all the small mode settings."
8277 (if (get 'org-agenda-files 'org-restrict) " []" "")
8279 '(:eval (org-agenda-span-name org-agenda-current-span))
8280 (if org-agenda-follow-mode " Follow" "")
8281 (if org-agenda-entry-text-mode " ETxt" "")
8282 (if org-agenda-include-diary " Diary" "")
8283 (if org-agenda-include-deadlines " Ddl" "")
8284 (if org-agenda-use-time-grid " Grid" "")
8285 (if (and (boundp 'org-habit-show-habits)
8286 org-habit-show-habits) " Habit" "")
8288 ((consp org-agenda-show-log) " LogAll")
8289 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
8290 (org-agenda-show-log " Log")
8292 (if (or org-agenda-category-filter
8293 (get 'org-agenda-category-filter :preset-filter))
8294 '(:eval (org-propertize
8299 (get 'org-agenda-category-filter :preset-filter)
8300 org-agenda-category-filter)
8303 'face 'org-agenda-filter-category
8304 'help-echo "Category used in filtering")) "")
8305 (if (or org-agenda-tag-filter
8306 (get 'org-agenda-tag-filter :preset-filter))
8307 '(:eval (org-propertize
8312 (get 'org-agenda-tag-filter :preset-filter)
8313 org-agenda-tag-filter)
8316 'face 'org-agenda-filter-tags
8317 'help-echo "Tags used in filtering")) "")
8318 (if (or org-agenda-effort-filter
8319 (get 'org-agenda-effort-filter :preset-filter))
8320 '(:eval (org-propertize
8325 (get 'org-agenda-effort-filter :preset-filter)
8326 org-agenda-effort-filter)
8329 'face 'org-agenda-filter-effort
8330 'help-echo "Effort conditions used in filtering")) "")
8331 (if (or org-agenda-regexp-filter
8332 (get 'org-agenda-regexp-filter :preset-filter))
8333 '(:eval (org-propertize
8338 (get 'org-agenda-regexp-filter :preset-filter)
8339 org-agenda-regexp-filter)
8342 'face 'org-agenda-filter-regexp
8343 'help-echo "Regexp used in filtering")) "")
8344 (if org-agenda-archives-mode
8345 (if (eq org-agenda-archives-mode t)
8347 (format " :%s:" org-archive-tag))
8349 (if org-agenda-clockreport-mode " Clock" "")))
8350 (force-mode-line-update))
8352 (define-obsolete-function-alias
8353 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
8355 (defun org-agenda-update-agenda-type ()
8356 "Update the agenda type after each command."
8357 (setq org-agenda-type
8358 (or (get-text-property (point) 'org-agenda-type)
8359 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
8361 (defun org-agenda-next-line ()
8362 "Move cursor to the next line, and show if follow mode is active."
8364 (call-interactively 'next-line)
8365 (org-agenda-do-context-action))
8367 (defun org-agenda-previous-line ()
8368 "Move cursor to the previous line, and show if follow-mode is active."
8370 (call-interactively 'previous-line)
8371 (org-agenda-do-context-action))
8373 (defun org-agenda-next-item (n)
8374 "Move cursor to next agenda item."
8376 (let ((col (current-column)))
8378 (when (next-single-property-change (point-at-eol) 'org-marker)
8379 (move-end-of-line 1)
8380 (goto-char (next-single-property-change (point) 'org-marker))))
8381 (org-move-to-column col))
8382 (org-agenda-do-context-action))
8384 (defun org-agenda-previous-item (n)
8385 "Move cursor to next agenda item."
8388 (let ((col (current-column))
8389 (goto (save-excursion
8390 (move-end-of-line 0)
8391 (previous-single-property-change (point) 'org-marker))))
8392 (if goto (goto-char goto))
8393 (org-move-to-column col)))
8394 (org-agenda-do-context-action))
8396 (defun org-agenda-do-context-action ()
8397 "Show outline path and, maybe, follow mode window."
8398 (let ((m (org-get-at-bol 'org-marker)))
8399 (when (and (markerp m) (marker-buffer m))
8400 (and org-agenda-follow-mode
8401 (if org-agenda-follow-indirect
8402 (org-agenda-tree-to-indirect-buffer nil)
8404 (and org-agenda-show-outline-path
8405 (org-with-point-at m (org-display-outline-path t))))))
8407 (defun org-agenda-show-tags ()
8408 "Show the tags applicable to the current item."
8410 (let* ((tags (org-get-at-bol 'tags)))
8412 (message "Tags are :%s:"
8413 (org-no-properties (mapconcat 'identity tags ":")))
8414 (message "No tags associated with this line"))))
8416 (defun org-agenda-goto (&optional highlight)
8417 "Go to the entry at point in the corresponding Org-mode file."
8419 (let* ((marker (or (org-get-at-bol 'org-marker)
8420 (org-agenda-error)))
8421 (buffer (marker-buffer marker))
8422 (pos (marker-position marker)))
8423 (switch-to-buffer-other-window buffer)
8427 (when (derived-mode-p 'org-mode)
8428 (org-show-context 'agenda)
8430 (and (outline-next-heading)
8431 (org-flag-heading nil))) ; show the next heading
8432 (when (outline-invisible-p)
8433 (outline-show-entry)) ; display invisible text
8434 (recenter (/ (window-height) 2))
8435 (org-back-to-heading t)
8436 (if (re-search-forward org-complex-heading-regexp nil t)
8437 (goto-char (match-beginning 4))))
8438 (run-hooks 'org-agenda-after-show-hook)
8439 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8441 (defvar org-agenda-after-show-hook nil
8442 "Normal hook run after an item has been shown from the agenda.
8443 Point is in the buffer where the item originated.")
8445 (defun org-agenda-kill ()
8446 "Kill the entry or subtree belonging to the current agenda entry."
8448 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8449 (let* ((bufname-orig (buffer-name))
8450 (marker (or (org-get-at-bol 'org-marker)
8451 (org-agenda-error)))
8452 (buffer (marker-buffer marker))
8453 (pos (marker-position marker))
8454 (type (org-get-at-bol 'type))
8455 dbeg dend (n 0) conf)
8456 (org-with-remote-undo buffer
8457 (with-current-buffer buffer
8460 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8461 (setq dbeg (progn (org-back-to-heading t) (point))
8462 dend (org-end-of-subtree t t))
8463 (setq dbeg (point-at-bol)
8464 dend (min (point-max) (1+ (point-at-eol)))))
8466 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8467 (setq conf (or (eq t org-agenda-confirm-kill)
8468 (and (numberp org-agenda-confirm-kill)
8469 (> n org-agenda-confirm-kill))))
8472 (format "Delete entry with %d lines in buffer \"%s\"? "
8473 n (buffer-name buffer))))
8475 (let ((org-agenda-buffer-name bufname-orig))
8476 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8477 (with-current-buffer buffer (delete-region dbeg dend))
8478 (message "Agenda item and source killed"))))
8480 (defvar org-archive-default-command) ; defined in org-archive.el
8481 (defun org-agenda-archive-default ()
8482 "Archive the entry or subtree belonging to the current agenda entry."
8484 (require 'org-archive)
8485 (org-agenda-archive-with org-archive-default-command))
8487 (defun org-agenda-archive-default-with-confirmation ()
8488 "Archive the entry or subtree belonging to the current agenda entry."
8490 (require 'org-archive)
8491 (org-agenda-archive-with org-archive-default-command 'confirm))
8493 (defun org-agenda-archive ()
8494 "Archive the entry or subtree belonging to the current agenda entry."
8496 (org-agenda-archive-with 'org-archive-subtree))
8498 (defun org-agenda-archive-to-archive-sibling ()
8499 "Move the entry to the archive sibling."
8501 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8503 (defun org-agenda-archive-with (cmd &optional confirm)
8504 "Move the entry to the archive sibling."
8506 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8507 (let* ((bufname-orig (buffer-name))
8508 (marker (or (org-get-at-bol 'org-marker)
8509 (org-agenda-error)))
8510 (buffer (marker-buffer marker))
8511 (pos (marker-position marker)))
8512 (org-with-remote-undo buffer
8513 (with-current-buffer buffer
8514 (if (derived-mode-p 'org-mode)
8516 (not (y-or-n-p "Archive this subtree or entry? ")))
8518 (save-window-excursion
8520 (let ((org-agenda-buffer-name bufname-orig))
8521 (org-remove-subtree-entries-from-agenda))
8522 (org-back-to-heading t)
8524 (error "Archiving works only in Org-mode files"))))))
8526 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8527 "Remove all lines in the agenda that correspond to a given subtree.
8528 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8529 If this information is not given, the function uses the tree at point."
8530 (let ((buf (or buf (current-buffer))) m p)
8532 (unless (and beg end)
8533 (org-back-to-heading t)
8535 (org-end-of-subtree t)
8537 (set-buffer (get-buffer org-agenda-buffer-name))
8539 (goto-char (point-max))
8540 (beginning-of-line 1)
8542 (when (and (setq m (org-get-at-bol 'org-marker))
8543 (equal buf (marker-buffer m))
8544 (setq p (marker-position m))
8547 (let ((inhibit-read-only t))
8548 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8549 (beginning-of-line 0))))))
8551 (defun org-agenda-refile (&optional goto rfloc no-update)
8552 "Refile the item at point.
8554 When GOTO is 0 or \\='(64) or a triple \\[universal-argument] prefix argument,
8555 clear the refile cache.
8556 When GOTO is \\='(16) or a double \\[universal-argument] prefix argument,
8557 go to the location of the last refiled item.
8558 RFLOC can be a refile location obtained in a different way.
8559 When NO-UPDATE is non-nil, don't redo the agenda buffer."
8562 ((member goto '(0 (64)))
8563 (org-refile-cache-clear))
8565 (org-refile-goto-last-stored))
8567 (let* ((buffer-orig (buffer-name))
8568 (marker (or (org-get-at-bol 'org-hd-marker)
8569 (org-agenda-error)))
8570 (buffer (marker-buffer marker))
8571 (pos (marker-position marker))
8573 (org-refile-get-location
8574 (if goto "Goto" "Refile to") buffer
8575 org-refile-allow-creating-parent-nodes))))
8576 (with-current-buffer buffer
8581 (let ((org-agenda-buffer-name buffer-orig))
8582 (org-remove-subtree-entries-from-agenda))
8583 (org-refile goto buffer rfloc)))))
8584 (unless no-update (org-agenda-redo)))))
8586 (defun org-agenda-open-link (&optional arg)
8587 "Open the link(s) in the current entry, if any.
8588 This looks for a link in the displayed line in the agenda.
8589 It also looks at the text of the entry itself."
8591 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8592 (org-get-at-bol 'org-marker)))
8593 (buffer (and marker (marker-buffer marker)))
8594 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8595 (lkall (and buffer (org-offer-links-in-entry
8596 buffer marker arg prefix)))
8598 (lk (if (stringp lk0) (list lk0) lk0))
8604 (with-current-buffer buffer
8605 (setq trg (and (string-match org-bracket-link-regexp l)
8606 (match-string 1 l)))
8607 (if (or (not trg) (string-match org-any-link-re trg))
8612 (when (search-forward l nil lkend)
8613 (goto-char (match-beginning 0))
8614 (org-open-at-point))))
8615 ;; This is an internal link, widen the buffer
8616 (switch-to-buffer-other-window buffer)
8619 (when (search-forward l nil lkend)
8620 (goto-char (match-beginning 0))
8621 (org-open-at-point)))))
8623 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8625 (beginning-of-line 1)
8626 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8627 (org-open-link-from-string (match-string 1)))
8628 (t (message "No link to open here")))))
8630 (defun org-agenda-copy-local-variable (var)
8631 "Get a variable from a referenced buffer and install it here."
8632 (let ((m (org-get-at-bol 'org-marker)))
8633 (when (and m (buffer-live-p (marker-buffer m)))
8634 (set (make-local-variable var)
8635 (with-current-buffer (marker-buffer m)
8636 (symbol-value var))))))
8638 (defun org-agenda-switch-to (&optional delete-other-windows)
8639 "Go to the Org mode file which contains the item at point.
8640 When optional argument DELETE-OTHER-WINDOWS is non-nil, the
8641 displayed Org file fills the frame."
8643 (if (and org-return-follows-link
8644 (not (org-get-at-bol 'org-marker))
8645 (org-in-regexp org-bracket-link-regexp))
8646 (org-open-link-from-string (match-string 0))
8647 (let* ((marker (or (org-get-at-bol 'org-marker)
8648 (org-agenda-error)))
8649 (buffer (marker-buffer marker))
8650 (pos (marker-position marker)))
8651 (unless buffer (user-error "Trying to switch to non-existent buffer"))
8652 (org-pop-to-buffer-same-window buffer)
8653 (when delete-other-windows (delete-other-windows))
8656 (when (derived-mode-p 'org-mode)
8657 (org-show-context 'agenda)
8658 (run-hooks 'org-agenda-after-show-hook)))))
8660 (defun org-agenda-goto-mouse (ev)
8661 "Go to the Org-mode file which contains the item at the mouse click."
8663 (mouse-set-point ev)
8666 (defun org-agenda-show (&optional full-entry)
8667 "Display the Org-mode file which contains the item at point.
8668 With prefix argument FULL-ENTRY, make the entire entry visible
8669 if it was hidden in the outline."
8671 (let ((win (selected-window)))
8673 (when full-entry (org-show-entry))
8674 (select-window win)))
8676 (defvar org-agenda-show-window nil)
8677 (defun org-agenda-show-and-scroll-up (&optional arg)
8678 "Display the Org-mode file which contains the item at point.
8679 When called repeatedly, scroll the window that is displaying the buffer.
8680 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8681 `show-subtree' to display the item, so that drawers and logbooks stay
8684 (let ((win (selected-window)))
8685 (if (and (window-live-p org-agenda-show-window)
8686 (eq this-command last-command))
8688 (select-window org-agenda-show-window)
8689 (ignore-errors (scroll-up)))
8691 (if arg (org-show-entry) (outline-show-subtree))
8692 (setq org-agenda-show-window (selected-window)))
8693 (select-window win)))
8695 (defun org-agenda-show-scroll-down ()
8696 "Scroll down the window showing the agenda."
8698 (let ((win (selected-window)))
8699 (when (window-live-p org-agenda-show-window)
8700 (select-window org-agenda-show-window)
8701 (ignore-errors (scroll-down))
8702 (select-window win))))
8704 (defun org-agenda-show-1 (&optional more)
8705 "Display the Org-mode file which contains the item at point.
8706 The prefix arg selects the amount of information to display:
8709 1 just show the entry according to defaults.
8710 2 show the children view
8711 3 show the subtree view
8712 4 show the entire subtree and any LOGBOOK drawers
8713 5 show the entire subtree and any drawers
8714 With prefix argument FULL-ENTRY, make the entire entry visible
8715 if it was hidden in the outline."
8717 (let ((win (selected-window)))
8719 (org-back-to-heading)
8720 (set-window-start (selected-window) (point-at-bol))
8723 (outline-hide-subtree)
8725 (org-back-to-heading)
8726 (run-hook-with-args 'org-cycle-hook 'folded))
8727 (message "Remote: FOLDED"))
8728 ((and (org-called-interactively-p 'any) (= more 1))
8729 (message "Remote: show with default settings"))
8731 (outline-show-entry)
8734 (org-back-to-heading)
8735 (run-hook-with-args 'org-cycle-hook 'children))
8736 (message "Remote: CHILDREN"))
8738 (outline-show-subtree)
8740 (org-back-to-heading)
8741 (run-hook-with-args 'org-cycle-hook 'subtree))
8742 (message "Remote: SUBTREE"))
8744 (outline-show-subtree)
8746 (org-back-to-heading)
8747 (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
8748 (message "Remote: SUBTREE AND LOGBOOK"))
8750 (outline-show-subtree)
8751 (message "Remote: SUBTREE AND ALL DRAWERS")))
8752 (select-window win)))
8754 (defvar org-agenda-cycle-counter nil)
8755 (defun org-agenda-cycle-show (&optional n)
8756 "Show the current entry in another window, with default settings.
8758 Default settings are taken from `org-show-context-detail'. When
8759 use repeatedly in immediate succession, the remote entry will
8760 cycle through visibility
8762 children -> subtree -> folded
8764 When called with a numeric prefix arg, that arg will be passed through to
8765 `org-agenda-show-1'. For the interpretation of that argument, see the
8766 docstring of `org-agenda-show-1'."
8769 (setq org-agenda-cycle-counter n)
8770 (if (not (eq last-command this-command))
8771 (setq org-agenda-cycle-counter 1)
8772 (if (equal org-agenda-cycle-counter 0)
8773 (setq org-agenda-cycle-counter 2)
8774 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8775 (if (> org-agenda-cycle-counter 3)
8776 (setq org-agenda-cycle-counter 0)))))
8777 (org-agenda-show-1 org-agenda-cycle-counter))
8779 (defun org-agenda-recenter (arg)
8780 "Display the Org-mode file which contains the item at point and recenter."
8782 (let ((win (selected-window)))
8785 (select-window win)))
8787 (defun org-agenda-show-mouse (ev)
8788 "Display the Org-mode file which contains the item at the mouse click."
8790 (mouse-set-point ev)
8793 (defun org-agenda-check-no-diary ()
8794 "Check if the entry is a diary link and abort if yes."
8795 (if (org-get-at-bol 'org-agenda-diary-link)
8796 (org-agenda-error)))
8798 (defun org-agenda-error ()
8799 "Throw an error when a command is not allowed in the agenda."
8800 (user-error "Command not allowed in this line"))
8802 (defun org-agenda-tree-to-indirect-buffer (arg)
8803 "Show the subtree corresponding to the current entry in an indirect buffer.
8804 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8806 With a numerical prefix ARG, go up to this level and then take that tree.
8807 With a negative numeric ARG, go up by this number of levels.
8808 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8809 use the dedicated frame)."
8811 (if current-prefix-arg
8812 (org-agenda-do-tree-to-indirect-buffer arg)
8813 (let ((agenda-buffer (buffer-name))
8814 (agenda-window (selected-window))
8816 (and org-last-indirect-buffer
8817 (get-buffer-window org-last-indirect-buffer))))
8818 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8819 (unless (or (eq org-indirect-buffer-display 'new-frame)
8820 (eq org-indirect-buffer-display 'dedicated-frame))
8822 (unless (and indirect-window (window-live-p indirect-window))
8823 (setq indirect-window (split-window agenda-window)))
8824 (and indirect-window (select-window indirect-window))
8825 (switch-to-buffer org-last-indirect-buffer :norecord)
8826 (fit-window-to-buffer indirect-window)))
8827 (select-window (get-buffer-window agenda-buffer))
8828 (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
8830 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8831 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8832 (org-agenda-check-no-diary)
8833 (let* ((marker (or (org-get-at-bol 'org-marker)
8834 (org-agenda-error)))
8835 (buffer (marker-buffer marker))
8836 (pos (marker-position marker)))
8837 (with-current-buffer buffer
8840 (funcall 'org-tree-to-indirect-buffer arg)))))
8842 (defvar org-last-heading-marker (make-marker)
8843 "Marker pointing to the headline that last changed its TODO state
8844 by a remote command from the agenda.")
8846 (defun org-agenda-todo-nextset ()
8847 "Switch TODO entry to next sequence."
8849 (org-agenda-todo 'nextset))
8851 (defun org-agenda-todo-previousset ()
8852 "Switch TODO entry to previous sequence."
8854 (org-agenda-todo 'previousset))
8856 (defun org-agenda-todo (&optional arg)
8857 "Cycle TODO state of line at point, also in Org-mode file.
8858 This changes the line at point, all other lines in the agenda referring to
8859 the same tree node, and the headline of the tree node in the Org-mode file."
8861 (org-agenda-check-no-diary)
8862 (let* ((col (current-column))
8863 (marker (or (org-get-at-bol 'org-marker)
8864 (org-agenda-error)))
8865 (buffer (marker-buffer marker))
8866 (pos (marker-position marker))
8867 (hdmarker (org-get-at-bol 'org-hd-marker))
8868 (todayp (org-agenda-today-p (org-get-at-bol 'day)))
8869 (inhibit-read-only t)
8870 org-agenda-headline-snapshot-before-repeat newhead just-one)
8871 (org-with-remote-undo buffer
8872 (with-current-buffer buffer
8875 (org-show-context 'agenda)
8877 (and (outline-next-heading)
8878 (org-flag-heading nil))) ; show the next heading
8879 (let ((current-prefix-arg arg))
8880 (call-interactively 'org-todo))
8881 (and (bolp) (forward-char 1))
8882 (setq newhead (org-get-heading))
8883 (when (and (org-bound-and-true-p
8884 org-agenda-headline-snapshot-before-repeat)
8885 (not (equal org-agenda-headline-snapshot-before-repeat
8888 (setq newhead org-agenda-headline-snapshot-before-repeat
8891 (org-back-to-heading)
8892 (move-marker org-last-heading-marker (point))))
8893 (beginning-of-line 1)
8894 (save-window-excursion
8895 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8896 (when (org-bound-and-true-p org-clock-out-when-done)
8897 (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
8899 (org-agenda-unmark-clocking-task))
8900 (org-move-to-column col)
8901 (org-agenda-mark-clocking-task))))
8903 (defun org-agenda-add-note (&optional arg)
8904 "Add a time-stamped note to the entry at point."
8906 (org-agenda-check-no-diary)
8907 (let* ((marker (or (org-get-at-bol 'org-marker)
8908 (org-agenda-error)))
8909 (buffer (marker-buffer marker))
8910 (pos (marker-position marker))
8911 (hdmarker (org-get-at-bol 'org-hd-marker))
8912 (inhibit-read-only t))
8913 (with-current-buffer buffer
8916 (org-show-context 'agenda)
8918 (and (outline-next-heading)
8919 (org-flag-heading nil))) ; show the next heading
8922 (defun org-agenda-change-all-lines (newhead hdmarker
8923 &optional fixface just-this)
8924 "Change all lines in the agenda buffer which match HDMARKER.
8925 The new content of the line will be NEWHEAD (as modified by
8926 `org-agenda-format-item'). HDMARKER is checked with
8927 `equal' against all `org-hd-marker' text properties in the file.
8928 If FIXFACE is non-nil, the face of each item is modified according to
8930 If JUST-THIS is non-nil, change just the current line, not all.
8931 If FORCE-TAGS is non nil, the car of it returns the new tags."
8932 (let* ((inhibit-read-only t)
8933 (line (org-current-line))
8934 (org-agenda-buffer (current-buffer))
8935 (thetags (with-current-buffer (marker-buffer hdmarker)
8936 (save-excursion (save-restriction (widen)
8937 (goto-char hdmarker)
8938 (org-get-tags-at)))))
8939 props m pl undone-face done-face finish new dotime level cat tags)
8941 (goto-char (point-max))
8942 (beginning-of-line 1)
8944 (setq finish (bobp))
8945 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8946 (or (not just-this) (= (org-current-line) line))
8948 (setq props (text-properties-at (point))
8949 dotime (org-get-at-bol 'dotime)
8950 cat (org-get-at-eol 'org-category 1)
8951 level (org-get-at-bol 'level)
8954 (let ((org-prefix-format-compiled
8955 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8956 org-prefix-format-compiled))
8957 (extra (org-get-at-bol 'extra)))
8958 (with-current-buffer (marker-buffer hdmarker)
8962 (org-agenda-format-item extra newhead level cat tags dotime)))))
8963 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8964 undone-face (org-get-at-bol 'undone-face)
8965 done-face (org-get-at-bol 'done-face))
8966 (beginning-of-line 1)
8969 (and (looking-at ".*\n?") (replace-match "")))
8971 (replace-match new t t)
8972 (beginning-of-line 1)
8973 (add-text-properties (point-at-bol) (point-at-eol) props)
8975 (add-text-properties
8976 (point-at-bol) (point-at-eol)
8978 (if org-last-todo-state-is-todo
8979 undone-face done-face))))
8980 (org-agenda-highlight-todo 'line)
8981 (beginning-of-line 1))
8982 (t (error "Line update did not work")))
8984 (narrow-to-region (point-at-bol) (point-at-eol))
8985 (org-agenda-finalize)))
8986 (beginning-of-line 0)))))
8988 (defun org-agenda-align-tags (&optional line)
8989 "Align all tags in agenda items to `org-agenda-tags-column'."
8990 (let ((inhibit-read-only t) l c)
8992 (goto-char (if line (point-at-bol) (point-min)))
8993 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8994 (if line (point-at-eol) nil) t)
8995 (add-text-properties
8996 (match-beginning 2) (match-end 2)
8997 (list 'face (delq nil (let ((prop (get-text-property
8998 (match-beginning 2) 'face)))
8999 (or (listp prop) (setq prop (list prop)))
9000 (if (memq 'org-tag prop)
9002 (cons 'org-tag prop))))))
9003 (setq l (- (match-end 2) (match-beginning 2))
9004 c (if (< org-agenda-tags-column 0)
9005 (- (abs org-agenda-tags-column) l)
9006 org-agenda-tags-column))
9007 (delete-region (match-beginning 1) (match-end 1))
9008 (goto-char (match-beginning 1))
9009 (insert (org-add-props
9010 (make-string (max 1 (- c (current-column))) ?\ )
9011 (plist-put (copy-sequence (text-properties-at (point)))
9013 (goto-char (point-min))
9014 (org-font-lock-add-tag-faces (point-max)))))
9016 (defun org-agenda-priority-up ()
9017 "Increase the priority of line at point, also in Org-mode file."
9019 (org-agenda-priority 'up))
9021 (defun org-agenda-priority-down ()
9022 "Decrease the priority of line at point, also in Org-mode file."
9024 (org-agenda-priority 'down))
9026 (defun org-agenda-priority (&optional force-direction)
9027 "Set the priority of line at point, also in Org-mode file.
9028 This changes the line at point, all other lines in the agenda referring to
9029 the same tree node, and the headline of the tree node in the Org-mode file.
9030 Called with a universal prefix arg, show the priority instead of setting it."
9032 (if (equal force-direction '(4))
9034 (unless org-enable-priority-commands
9035 (error "Priority commands are disabled"))
9036 (org-agenda-check-no-diary)
9037 (let* ((col (current-column))
9038 (marker (or (org-get-at-bol 'org-marker)
9039 (org-agenda-error)))
9040 (hdmarker (org-get-at-bol 'org-hd-marker))
9041 (buffer (marker-buffer hdmarker))
9042 (pos (marker-position hdmarker))
9043 (inhibit-read-only t)
9045 (org-with-remote-undo buffer
9046 (with-current-buffer buffer
9049 (org-show-context 'agenda)
9051 (and (outline-next-heading)
9052 (org-flag-heading nil))) ; show the next heading
9053 (funcall 'org-priority force-direction)
9055 (setq newhead (org-get-heading)))
9056 (org-agenda-change-all-lines newhead hdmarker)
9057 (org-move-to-column col)))))
9059 ;; FIXME: should fix the tags property of the agenda line.
9060 (defun org-agenda-set-tags (&optional tag onoff)
9061 "Set tags for the current headline."
9063 (org-agenda-check-no-diary)
9064 (if (and (org-region-active-p) (org-called-interactively-p 'any))
9065 (call-interactively 'org-change-tag-in-region)
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
9077 (org-show-context 'agenda))
9079 (and (outline-next-heading)
9080 (org-flag-heading nil))) ; show the next heading
9083 (org-toggle-tag tag onoff)
9084 (call-interactively 'org-set-tags))
9086 (setq newhead (org-get-heading)))
9087 (org-agenda-change-all-lines newhead hdmarker)
9088 (beginning-of-line 1)))))
9090 (defun org-agenda-set-property ()
9091 "Set a property for the current headline."
9093 (org-agenda-check-no-diary)
9094 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9095 (org-agenda-error)))
9096 (buffer (marker-buffer hdmarker))
9097 (pos (marker-position hdmarker))
9098 (inhibit-read-only t)
9100 (org-with-remote-undo buffer
9101 (with-current-buffer buffer
9105 (org-show-context 'agenda))
9107 (and (outline-next-heading)
9108 (org-flag-heading nil))) ; show the next heading
9110 (call-interactively 'org-set-property)))))
9112 (defun org-agenda-set-effort ()
9113 "Set the effort property for the current headline."
9115 (org-agenda-check-no-diary)
9116 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9117 (org-agenda-error)))
9118 (buffer (marker-buffer hdmarker))
9119 (pos (marker-position hdmarker))
9120 (inhibit-read-only t)
9122 (org-with-remote-undo buffer
9123 (with-current-buffer buffer
9127 (org-show-context 'agenda))
9129 (and (outline-next-heading)
9130 (org-flag-heading nil))) ; show the next heading
9132 (call-interactively 'org-set-effort)
9134 (setq newhead (org-get-heading)))
9135 (org-agenda-change-all-lines newhead hdmarker))))
9137 (defun org-agenda-toggle-archive-tag ()
9138 "Toggle the archive tag for the current entry."
9140 (org-agenda-check-no-diary)
9141 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9142 (org-agenda-error)))
9143 (buffer (marker-buffer hdmarker))
9144 (pos (marker-position hdmarker))
9145 (inhibit-read-only t)
9147 (org-with-remote-undo buffer
9148 (with-current-buffer buffer
9151 (org-show-context 'agenda)
9153 (and (outline-next-heading)
9154 (org-flag-heading nil))) ; show the next heading
9155 (call-interactively 'org-toggle-archive-tag)
9157 (setq newhead (org-get-heading)))
9158 (org-agenda-change-all-lines newhead hdmarker)
9159 (beginning-of-line 1))))
9161 (defun org-agenda-do-date-later (arg)
9164 ((or (equal arg '(16))
9166 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9167 (setq this-command 'org-agenda-date-later-minutes)
9168 (org-agenda-date-later-minutes 1))
9169 ((or (equal arg '(4))
9171 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9172 (setq this-command 'org-agenda-date-later-hours)
9173 (org-agenda-date-later-hours 1))
9175 (org-agenda-date-later (prefix-numeric-value arg)))))
9177 (defun org-agenda-do-date-earlier (arg)
9180 ((or (equal arg '(16))
9182 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9183 (setq this-command 'org-agenda-date-earlier-minutes)
9184 (org-agenda-date-earlier-minutes 1))
9185 ((or (equal arg '(4))
9187 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9188 (setq this-command 'org-agenda-date-earlier-hours)
9189 (org-agenda-date-earlier-hours 1))
9191 (org-agenda-date-earlier (prefix-numeric-value arg)))))
9193 (defun org-agenda-date-later (arg &optional what)
9194 "Change the date of this item to ARG day(s) later."
9196 (org-agenda-check-type t 'agenda 'timeline)
9197 (org-agenda-check-no-diary)
9198 (let* ((marker (or (org-get-at-bol 'org-marker)
9199 (org-agenda-error)))
9200 (buffer (marker-buffer marker))
9201 (pos (marker-position marker))
9203 (org-with-remote-undo buffer
9204 (with-current-buffer buffer
9207 (if (not (org-at-timestamp-p))
9208 (error "Cannot find time stamp"))
9209 (when (and org-agenda-move-date-from-past-immediately-to-today
9211 (or (not what) (eq what 'day))
9212 (not (save-match-data (org-at-date-range-p))))
9213 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
9214 cdate (calendar-absolute-from-gregorian
9215 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
9218 ;; immediately shift to today
9219 (setq arg (- today cdate))))
9220 (org-timestamp-change arg (or what 'day))
9221 (when (and (org-at-date-range-p)
9222 (re-search-backward org-tr-regexp-both (point-at-bol)))
9223 (let ((end org-last-changed-timestamp))
9224 (org-timestamp-change arg (or what 'day))
9225 (setq org-last-changed-timestamp
9226 (concat org-last-changed-timestamp "--" end)))))
9227 (org-agenda-show-new-time marker org-last-changed-timestamp))
9228 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9230 (defun org-agenda-date-earlier (arg &optional what)
9231 "Change the date of this item to ARG day(s) earlier."
9233 (org-agenda-date-later (- arg) what))
9235 (defun org-agenda-date-later-minutes (arg)
9236 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9238 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9239 (org-agenda-date-later arg 'minute))
9241 (defun org-agenda-date-earlier-minutes (arg)
9242 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9244 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9245 (org-agenda-date-earlier arg 'minute))
9247 (defun org-agenda-date-later-hours (arg)
9248 "Change the time of this item, in hour steps."
9250 (org-agenda-date-later arg 'hour))
9252 (defun org-agenda-date-earlier-hours (arg)
9253 "Change the time of this item, in hour steps."
9255 (org-agenda-date-earlier arg 'hour))
9257 (defun org-agenda-show-new-time (marker stamp &optional prefix)
9258 "Show new date stamp via text properties."
9259 ;; We use text properties to make this undoable
9260 (let ((inhibit-read-only t))
9261 (setq stamp (concat prefix " => " stamp " "))
9263 (goto-char (point-max))
9265 (when (equal marker (org-get-at-bol 'org-marker))
9266 (remove-text-properties (point-at-bol) (point-at-eol) '(display))
9267 (org-move-to-column (- (window-width) (length stamp)) t)
9268 (if (featurep 'xemacs)
9269 ;; Use `duplicable' property to trigger undo recording
9270 (let ((ex (make-extent nil nil))
9271 (gl (make-glyph stamp)))
9272 (set-glyph-face gl 'secondary-selection)
9273 (set-extent-properties
9274 ex (list 'invisible t 'end-glyph gl 'duplicable t))
9275 (insert-extent ex (1- (point)) (point-at-eol)))
9276 (add-text-properties
9277 (1- (point)) (point-at-eol)
9278 (list 'display (org-add-props stamp nil
9279 'face '(secondary-selection default)))))
9280 (beginning-of-line 1))
9281 (beginning-of-line 0)))))
9283 (defun org-agenda-date-prompt (arg)
9284 "Change the date of this item. Date is prompted for, with default today.
9285 The prefix ARG is passed to the `org-time-stamp' command and can therefore
9286 be used to request time specification in the time stamp."
9288 (org-agenda-check-type t 'agenda 'timeline)
9289 (org-agenda-check-no-diary)
9290 (let* ((marker (or (org-get-at-bol 'org-marker)
9291 (org-agenda-error)))
9292 (buffer (marker-buffer marker))
9293 (pos (marker-position marker)))
9294 (org-with-remote-undo buffer
9295 (with-current-buffer buffer
9298 (if (not (org-at-timestamp-p t))
9299 (error "Cannot find time stamp"))
9300 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
9301 (org-agenda-show-new-time marker org-last-changed-timestamp))
9302 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9304 (defun org-agenda-schedule (arg &optional time)
9305 "Schedule the item at point.
9306 ARG is passed through to `org-schedule'."
9308 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9309 (org-agenda-check-no-diary)
9310 (let* ((marker (or (org-get-at-bol 'org-marker)
9311 (org-agenda-error)))
9312 (type (marker-insertion-type marker))
9313 (buffer (marker-buffer marker))
9314 (pos (marker-position marker))
9316 (set-marker-insertion-type marker t)
9317 (org-with-remote-undo buffer
9318 (with-current-buffer buffer
9321 (setq ts (org-schedule arg time)))
9322 (org-agenda-show-new-time marker ts " S"))
9325 (defun org-agenda-deadline (arg &optional time)
9326 "Schedule the item at point.
9327 ARG is passed through to `org-deadline'."
9329 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9330 (org-agenda-check-no-diary)
9331 (let* ((marker (or (org-get-at-bol 'org-marker)
9332 (org-agenda-error)))
9333 (buffer (marker-buffer marker))
9334 (pos (marker-position marker))
9336 (org-with-remote-undo buffer
9337 (with-current-buffer buffer
9340 (setq ts (org-deadline arg time)))
9341 (org-agenda-show-new-time marker ts " D"))
9344 (defun org-agenda-clock-in (&optional arg)
9345 "Start the clock on the currently selected item."
9347 (org-agenda-check-no-diary)
9348 (if (equal arg '(4))
9350 (let* ((marker (or (org-get-at-bol 'org-marker)
9351 (org-agenda-error)))
9352 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
9353 (pos (marker-position marker))
9354 (col (current-column))
9356 (org-with-remote-undo (marker-buffer marker)
9357 (with-current-buffer (marker-buffer marker)
9360 (org-show-context 'agenda)
9362 (org-cycle-hide-drawers 'children)
9364 (setq newhead (org-get-heading)))
9365 (org-agenda-change-all-lines newhead hdmarker))
9366 (org-move-to-column col))))
9368 (defun org-agenda-clock-out ()
9369 "Stop the currently running clock."
9371 (unless (marker-buffer org-clock-marker)
9372 (error "No running clock"))
9373 (let ((marker (make-marker)) (col (current-column)) newhead)
9374 (org-with-remote-undo (marker-buffer org-clock-marker)
9375 (with-current-buffer (marker-buffer org-clock-marker)
9379 (goto-char org-clock-marker)
9380 (org-back-to-heading t)
9381 (move-marker marker (point))
9383 (setq newhead (org-get-heading))))))
9384 (org-agenda-change-all-lines newhead marker)
9385 (move-marker marker nil)
9386 (org-move-to-column col)
9387 (org-agenda-unmark-clocking-task)))
9389 (defun org-agenda-clock-cancel (&optional arg)
9390 "Cancel the currently running clock."
9392 (unless (marker-buffer org-clock-marker)
9393 (user-error "No running clock"))
9394 (org-with-remote-undo (marker-buffer org-clock-marker)
9395 (org-clock-cancel)))
9397 (defun org-agenda-clock-goto ()
9398 "Jump to the currently clocked in task within the agenda.
9399 If the currently clocked in task is not listed in the agenda
9400 buffer, display it in another window."
9404 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
9405 (setq pos (overlay-start o))))
9406 (overlays-in (point-min) (point-max)))
9407 (cond (pos (goto-char pos))
9408 ;; If the currently clocked entry is not in the agenda
9409 ;; buffer, we visit it in another window:
9410 ((bound-and-true-p org-clock-current-task)
9411 (org-switch-to-buffer-other-window (org-clock-goto)))
9412 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
9414 (defun org-agenda-diary-entry-in-org-file ()
9415 "Make a diary entry in the file `org-agenda-diary-file'."
9416 (let (d1 d2 char (text "") dp1 dp2)
9417 (if (equal (buffer-name) "*Calendar*")
9418 (setq d1 (calendar-cursor-to-date t)
9419 d2 (car calendar-mark-ring))
9420 (setq dp1 (get-text-property (point-at-bol) 'day))
9421 (unless dp1 (user-error "No date defined in current line"))
9422 (setq d1 (calendar-gregorian-from-absolute dp1)
9423 d2 (and (ignore-errors (mark))
9426 (setq dp2 (get-text-property (point-at-bol) 'day)))
9427 (calendar-gregorian-from-absolute dp2))))
9428 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9429 (setq char (read-char-exclusive))
9432 (setq text (read-string "Day entry: "))
9433 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9434 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9436 (setq d1 (list (car d1) (nth 1 d1)
9437 (read-number (format "Reference year [%d]: " (nth 2 d1))
9439 (setq text (read-string "Anniversary (use %d to show years): "))
9440 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9441 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9443 (setq text (read-string "Block entry: "))
9444 (unless (and d1 d2 (not (equal d1 d2)))
9445 (user-error "No block of days selected"))
9446 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9447 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9449 (org-switch-to-buffer-other-window
9450 (find-file-noselect org-agenda-diary-file))
9451 (require 'org-datetree)
9452 (org-datetree-find-date-create d1)
9454 (t (user-error "Invalid selection character `%c'" char)))))
9456 (defcustom org-agenda-insert-diary-strategy 'date-tree
9457 "Where in `org-agenda-diary-file' should new entries be added?
9460 date-tree in the date tree, as first child of the date
9461 date-tree-last in the date tree, as last child of the date
9462 top-level as top-level entries at the end of the file."
9465 (const :tag "first in a date tree" date-tree)
9466 (const :tag "last in a date tree" date-tree-last)
9467 (const :tag "as top level at end of file" top-level)))
9469 (defcustom org-agenda-insert-diary-extract-time nil
9470 "Non-nil means extract any time specification from the diary entry."
9475 (defcustom org-agenda-bulk-mark-char ">"
9476 "A single-character string to be used as the bulk mark."
9481 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9482 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9483 If TEXT is not empty, it will become the headline of the new entry, and
9484 the resulting entry will not be shown. When TEXT is empty, switch to
9485 `org-agenda-diary-file' and let the user finish the entry there."
9486 (let ((cw (current-window-configuration)))
9487 (org-switch-to-buffer-other-window
9488 (find-file-noselect org-agenda-diary-file))
9490 (goto-char (point-min))
9492 ((eq type 'anniversary)
9493 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9495 (or (org-at-heading-p t)
9497 (outline-next-heading)
9498 (insert "* Anniversaries\n\n")
9499 (beginning-of-line -1)))))
9500 (outline-next-heading)
9501 (org-back-over-empty-lines)
9504 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9505 (nth 2 d1) (car d1) (nth 1 d1) text)))
9507 (let ((org-prefix-has-time t)
9508 (org-agenda-time-leading-zero t)
9510 (if org-agenda-insert-diary-extract-time
9511 ;; Use org-agenda-format-item to parse text for a time-range and
9512 ;; remove it. FIXME: This is a hack, we should refactor
9513 ;; that function to make time extraction available separately
9514 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9515 time (get-text-property 0 'time fmt)
9516 time2 (if (> (length time) 0)
9517 ;; split-string removes trailing ...... if
9518 ;; no end time given. First space
9519 ;; separates time from date.
9520 (concat " " (car (split-string time "\\.")))
9522 text (get-text-property 0 'txt fmt)))
9523 (if (eq org-agenda-insert-diary-strategy 'top-level)
9524 (org-agenda-insert-diary-as-top-level text)
9525 (require 'org-datetree)
9526 (org-datetree-find-date-create d1)
9527 (org-agenda-insert-diary-make-new-entry text))
9528 (org-insert-time-stamp (org-time-from-absolute
9529 (calendar-absolute-from-gregorian d1))
9530 nil nil nil nil time2))
9533 (if (> (calendar-absolute-from-gregorian d1)
9534 (calendar-absolute-from-gregorian d2))
9535 (setq d1 (prog1 d2 (setq d2 d1))))
9536 (if (eq org-agenda-insert-diary-strategy 'top-level)
9537 (org-agenda-insert-diary-as-top-level text)
9538 (require 'org-datetree)
9539 (org-datetree-find-date-create d1)
9540 (org-agenda-insert-diary-make-new-entry text))
9541 (org-insert-time-stamp (org-time-from-absolute
9542 (calendar-absolute-from-gregorian d1)))
9544 (org-insert-time-stamp (org-time-from-absolute
9545 (calendar-absolute-from-gregorian d2)))
9547 (if (string-match "\\S-" text)
9549 (set-window-configuration cw)
9550 (message "%s entry added to %s"
9551 (capitalize (symbol-name type))
9552 (abbreviate-file-name org-agenda-diary-file)))
9554 (message "Please finish entry here"))))
9556 (defun org-agenda-insert-diary-as-top-level (text)
9557 "Make new entry as a top-level entry at the end of the file.
9558 Add TEXT as headline, and position the cursor in the second line so that
9559 a timestamp can be added there."
9561 (goto-char (point-max))
9562 (unless (bolp) (insert "\n"))
9563 (org-insert-heading nil t t)
9565 (org-end-of-meta-data)
9566 (unless (bolp) (insert "\n"))
9567 (when org-adapt-indentation (org-indent-to-column 2)))
9569 (defun org-agenda-insert-diary-make-new-entry (text)
9570 "Make a new entry with TEXT as a child of the current subtree.
9571 Position the point in the heading's first body line so that
9572 a timestamp can be added there."
9574 ((eq org-agenda-insert-diary-strategy 'date-tree-last)
9576 (org-insert-heading '(4) t)
9579 (outline-next-heading)
9580 (org-back-over-empty-lines)
9581 (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
9582 (org-insert-heading nil t)
9584 (let ((col (current-column)))
9586 (org-end-of-meta-data)
9587 ;; Ensure point is left on a blank line, at proper indentation.
9588 (unless (bolp) (insert "\n"))
9589 (unless (org-looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
9590 (when org-adapt-indentation (org-indent-to-column col)))
9591 (org-show-set-visibility 'lineage))
9593 (defun org-agenda-diary-entry ()
9594 "Make a diary entry, like the `i' command from the calendar.
9595 All the standard commands work: block, weekly etc.
9596 When `org-agenda-diary-file' points to a file,
9597 `org-agenda-diary-entry-in-org-file' is called instead to create
9598 entries in that Org-mode file."
9600 (if (not (eq org-agenda-diary-file 'diary-file))
9601 (org-agenda-diary-entry-in-org-file)
9602 (require 'diary-lib)
9604 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9605 (read-char-exclusive)))
9606 (cmd (cdr (assoc char
9607 '((?d . diary-insert-entry)
9608 (?w . diary-insert-weekly-entry)
9609 (?m . diary-insert-monthly-entry)
9610 (?y . diary-insert-yearly-entry)
9611 (?a . diary-insert-anniversary-entry)
9612 (?b . diary-insert-block-entry)
9613 (?c . diary-insert-cyclic-entry)))))
9614 (oldf (symbol-function 'calendar-cursor-to-date))
9615 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9617 (mark (or (mark t) (point))))
9619 (user-error "No command associated with <%c>" char))
9620 (unless (and (get-text-property point 'day)
9621 (or (not (equal ?b char))
9622 (get-text-property mark 'day)))
9623 (user-error "Don't know which date to use for diary entry"))
9624 ;; We implement this by hacking the `calendar-cursor-to-date' function
9625 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9626 (let ((calendar-mark-ring
9627 (list (calendar-gregorian-from-absolute
9628 (or (get-text-property mark 'day)
9629 (get-text-property point 'day))))))
9632 (fset 'calendar-cursor-to-date
9633 (lambda (&optional error dummy)
9634 (calendar-gregorian-from-absolute
9635 (get-text-property point 'day))))
9636 (call-interactively cmd))
9637 (fset 'calendar-cursor-to-date oldf))))))
9639 (defun org-agenda-execute-calendar-command (cmd)
9640 "Execute a calendar command from the agenda with date from cursor."
9641 (org-agenda-check-type t 'agenda 'timeline)
9642 (require 'diary-lib)
9643 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9644 (user-error "Don't know which date to use for the calendar command"))
9645 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9647 (date (calendar-gregorian-from-absolute
9648 (get-text-property point 'day)))
9649 ;; the following 2 vars are needed in the calendar
9650 (displayed-month (car date))
9651 (displayed-year (nth 2 date)))
9654 (fset 'calendar-cursor-to-date
9655 (lambda (&optional error dummy)
9656 (calendar-gregorian-from-absolute
9657 (get-text-property point 'day))))
9658 (call-interactively cmd))
9659 (fset 'calendar-cursor-to-date oldf))))
9661 (defun org-agenda-phases-of-moon ()
9662 "Display the phases of the moon for the 3 months around the cursor date."
9664 (org-agenda-execute-calendar-command 'calendar-lunar-phases))
9666 (defun org-agenda-holidays ()
9667 "Display the holidays for the 3 months around the cursor date."
9669 (org-agenda-execute-calendar-command 'calendar-list-holidays))
9671 (defvar calendar-longitude) ; defined in calendar.el
9672 (defvar calendar-latitude) ; defined in calendar.el
9673 (defvar calendar-location-name) ; defined in calendar.el
9675 (defun org-agenda-sunrise-sunset (arg)
9676 "Display sunrise and sunset for the cursor date.
9677 Latitude and longitude can be specified with the variables
9678 `calendar-latitude' and `calendar-longitude'. When called with prefix
9679 argument, latitude and longitude will be prompted for."
9682 (let ((calendar-longitude (if arg nil calendar-longitude))
9683 (calendar-latitude (if arg nil calendar-latitude))
9684 (calendar-location-name
9685 (if arg "the given coordinates" calendar-location-name)))
9686 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9688 (defun org-agenda-goto-calendar ()
9689 "Open the Emacs calendar with the date at the cursor."
9691 (org-agenda-check-type t 'agenda 'timeline)
9692 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9693 (user-error "Don't know which date to open in calendar")))
9694 (date (calendar-gregorian-from-absolute day))
9695 (calendar-move-hook nil)
9696 (calendar-view-holidays-initially-flag nil)
9697 (calendar-view-diary-initially-flag nil))
9699 (calendar-goto-date date)))
9702 (defun org-calendar-goto-agenda ()
9703 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9704 This is a command that has to be installed in `calendar-mode-map'."
9706 ;; Temporarily disable sticky agenda since user clearly wants to
9707 ;; refresh view anyway.
9708 (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
9709 (org-agenda-sticky nil))
9710 (org-agenda-list nil (calendar-absolute-from-gregorian
9711 (calendar-cursor-to-date))
9714 (defun org-agenda-convert-date ()
9716 (org-agenda-check-type t 'agenda 'timeline)
9717 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9720 (user-error "Don't know which date to convert"))
9721 (setq date (calendar-gregorian-from-absolute day))
9723 "Gregorian: " (calendar-date-string date) "\n"
9724 "ISO: " (calendar-iso-date-string date) "\n"
9725 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9726 "Julian: " (calendar-julian-date-string date) "\n"
9727 "Astron. JD: " (calendar-astro-date-string date)
9728 " (Julian date number at noon UTC)\n"
9729 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9730 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9731 "French: " (calendar-french-date-string date) "\n"
9732 "Bahá’Ã: " (calendar-bahai-date-string date) " (until sunset)\n"
9733 "Mayan: " (calendar-mayan-date-string date) "\n"
9734 "Coptic: " (calendar-coptic-date-string date) "\n"
9735 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9736 "Persian: " (calendar-persian-date-string date) "\n"
9737 "Chinese: " (calendar-chinese-date-string date) "\n"))
9738 (with-output-to-temp-buffer "*Dates*"
9740 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9744 (defun org-agenda-bulk-marked-p ()
9745 (eq (get-char-property (point-at-bol) 'type)
9746 'org-marked-entry-overlay))
9748 (defun org-agenda-bulk-mark (&optional arg)
9749 "Mark the entry at point for future bulk action."
9751 (dotimes (i (or arg 1))
9752 (unless (org-get-at-bol 'org-agenda-diary-link)
9753 (let* ((m (org-get-at-bol 'org-hd-marker))
9755 (unless (org-agenda-bulk-marked-p)
9756 (unless m (user-error "Nothing to mark at point"))
9757 (push m org-agenda-bulk-marked-entries)
9758 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9759 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9760 (org-get-todo-face "TODO")
9762 (overlay-put ov 'type 'org-marked-entry-overlay))
9765 (goto-char (next-single-property-change (point) 'org-hd-marker)))
9766 (beginning-of-line 2))
9767 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9768 (beginning-of-line 2))
9769 (message "%d entries marked for bulk action"
9770 (length org-agenda-bulk-marked-entries))))))
9772 (defun org-agenda-bulk-mark-all ()
9773 "Mark all entries for future agenda bulk action."
9775 (org-agenda-bulk-mark-regexp "."))
9777 (defun org-agenda-bulk-mark-regexp (regexp)
9778 "Mark entries matching REGEXP for future agenda bulk action."
9779 (interactive "sMark entries matching regexp: ")
9780 (let ((entries-marked 0) txt-at-point)
9782 (goto-char (point-min))
9783 (goto-char (next-single-property-change (point) 'org-hd-marker))
9784 (while (and (re-search-forward regexp nil t)
9785 (setq txt-at-point (get-text-property (point) 'txt)))
9786 (when (string-match regexp txt-at-point)
9787 (setq entries-marked (1+ entries-marked))
9788 (call-interactively 'org-agenda-bulk-mark))))
9789 (if (not entries-marked)
9790 (message "No entry matching this regexp."))))
9792 (defun org-agenda-bulk-unmark (&optional arg)
9793 "Unmark the entry at point for future bulk action."
9796 (org-agenda-bulk-unmark-all)
9797 (cond ((org-agenda-bulk-marked-p)
9798 (org-agenda-bulk-remove-overlays
9799 (point-at-bol) (+ 2 (point-at-bol)))
9800 (setq org-agenda-bulk-marked-entries
9801 (delete (org-get-at-bol 'org-hd-marker)
9802 org-agenda-bulk-marked-entries))
9805 (goto-char (next-single-property-change (point) 'txt)))
9806 (beginning-of-line 2))
9807 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9808 (beginning-of-line 2))
9809 (message "%d entries left marked for bulk action"
9810 (length org-agenda-bulk-marked-entries)))
9811 (t (message "No entry to unmark here")))))
9813 (defun org-agenda-bulk-toggle-all ()
9814 "Toggle all marks for bulk action."
9817 (goto-char (point-min))
9818 (while (ignore-errors
9819 (goto-char (next-single-property-change (point) 'org-hd-marker)))
9820 (org-agenda-bulk-toggle))))
9822 (defun org-agenda-bulk-toggle ()
9823 "Toggle the mark at point for bulk action."
9825 (if (org-agenda-bulk-marked-p)
9826 (org-agenda-bulk-unmark)
9827 (org-agenda-bulk-mark)))
9829 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9830 "Remove the mark overlays between BEG and END in the agenda buffer.
9831 BEG and END default to the buffer limits.
9833 This only removes the overlays, it does not remove the markers
9834 from the list in `org-agenda-bulk-marked-entries'."
9837 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9838 (delete-overlay ov)))
9839 (overlays-in (or beg (point-min)) (or end (point-max)))))
9841 (defun org-agenda-bulk-unmark-all ()
9842 "Remove all marks in the agenda buffer.
9843 This will remove the markers and the overlays."
9845 (if (null org-agenda-bulk-marked-entries)
9846 (message "No entry to unmark")
9847 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9848 (setq org-agenda-bulk-marked-entries nil)
9849 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9851 (defcustom org-agenda-persistent-marks nil
9852 "Non-nil means marked items will stay marked after a bulk action.
9853 You can toggle this interactively by typing `p' when prompted for a
9859 (defun org-agenda-bulk-action (&optional arg)
9860 "Execute an remote-editing action on all marked entries.
9861 The prefix arg is passed through to the command if possible."
9863 ;; Make sure we have markers, and only valid ones
9864 (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
9867 (unless (and (markerp m)
9869 (buffer-live-p (marker-buffer m))
9870 (marker-position m))
9871 (user-error "Marker %s for bulk command is invalid" m)))
9872 org-agenda-bulk-marked-entries)
9874 ;; Prompt for the bulk command
9875 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9876 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9877 "[S]catter [f]unction "
9878 (when org-agenda-bulk-custom-functions
9879 (concat " Custom: ["
9880 (mapconcat (lambda(f) (char-to-string (car f)))
9881 org-agenda-bulk-custom-functions "")
9884 (let* ((action (read-char-exclusive))
9885 (org-log-refile (if org-log-refile 'time nil))
9886 (entries (reverse org-agenda-bulk-marked-entries))
9887 (org-overriding-default-time
9888 (if (get-text-property (point) 'org-agenda-date-header)
9889 (org-get-cursor-date)))
9891 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9894 (let ((org-agenda-persistent-marks
9895 (not org-agenda-persistent-marks)))
9896 (org-agenda-bulk-action)
9900 (setq cmd '(org-agenda-archive)))
9903 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9905 ((member action '(?r ?w))
9906 (setq rfloc (org-refile-get-location
9908 (marker-buffer (car entries))
9909 org-refile-allow-creating-parent-nodes))
9911 (setcar (nthcdr 3 rfloc)
9912 (move-marker (make-marker) (nth 3 rfloc)
9913 (or (get-file-buffer (nth 1 rfloc))
9914 (find-buffer-visiting (nth 1 rfloc))
9915 (error "This should not happen")))))
9917 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9921 (setq state (completing-read
9923 (with-current-buffer (marker-buffer (car entries))
9924 (mapcar #'list org-todo-keywords-1))))
9925 (setq cmd `(let ((org-inhibit-blocking t)
9926 (org-inhibit-logging 'note))
9927 (org-agenda-todo ,state))))
9929 ((memq action '(?- ?+))
9930 (setq tag (completing-read
9931 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9932 (with-current-buffer (marker-buffer (car entries))
9934 (mapcar (lambda (x) (and (stringp (car x)) x))
9935 org-current-tag-alist)))))
9936 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9938 ((memq action '(?s ?d))
9943 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9944 org-overriding-default-time)))
9945 (c1 (if (eq action ?s) 'org-agenda-schedule
9946 'org-agenda-deadline)))
9947 ;; Make sure to not prompt for a note when bulk
9948 ;; rescheduling as Org cannot cope with simultaneous Org.
9949 ;; Besides, it could be annoying depending on the number
9950 ;; of items re-scheduled.
9951 (setq cmd `(eval '(let ((org-log-reschedule
9952 (and org-log-reschedule 'time)))
9953 (,c1 arg ,time))))))
9956 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9957 (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9958 (let ((days (read-number
9959 (format "Scatter tasks across how many %sdays: "
9960 (if arg "week" "")) 7)))
9962 `(let ((distance (1+ (random ,days))))
9964 (let ((dist distance)
9966 (calendar-day-of-week
9967 (calendar-gregorian-from-absolute (org-today)))))
9968 (dotimes (i (1+ dist))
9969 (while (member day-of-week org-agenda-weekend-days)
9972 (if (= day-of-week 7)
9973 (setq day-of-week 0)))
9975 (if (= day-of-week 7)
9976 (setq day-of-week 0)))))
9977 ;; silently fail when try to replan a sexp entry
9979 (let* ((date (calendar-gregorian-from-absolute
9980 (+ (org-today) distance)))
9981 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9983 (org-agenda-schedule nil time))
9986 ((assoc action org-agenda-bulk-custom-functions)
9987 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9991 (setq cmd (list (intern
9992 (completing-read "Function: "
9993 obarray 'fboundp t nil nil)))))
9995 (t (user-error "Invalid bulk action")))
9997 ;; Sort the markers, to make sure that parents are handled before children
9998 (setq entries (sort entries
10001 ((equal (marker-buffer a) (marker-buffer b))
10002 (< (marker-position a) (marker-position b)))
10004 (string< (buffer-name (marker-buffer a))
10005 (buffer-name (marker-buffer b))))))))
10007 ;; Now loop over all markers and apply cmd
10008 (while (setq e (pop entries))
10009 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
10011 (progn (message "Skipping removed entry at %s" e)
10012 (setq cntskip (1+ cntskip)))
10014 (let (org-loop-over-headlines-in-active-region)
10016 ;; `post-command-hook' is not run yet. We make sure any
10017 ;; pending log note is processed.
10018 (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
10019 (memq 'org-add-log-note post-command-hook))
10020 (org-add-log-note))
10021 (setq cnt (1+ cnt))))
10022 (when redo-at-end (org-agenda-redo))
10023 (unless org-agenda-persistent-marks
10024 (org-agenda-bulk-unmark-all))
10025 (message "Acted on %d entries%s%s"
10029 (format ", skipped %d (disappeared before their turn)"
10031 (if (not org-agenda-persistent-marks)
10032 "" " (kept marked)"))))))
10034 (defun org-agenda-capture (&optional with-time)
10035 "Call `org-capture' with the date at point.
10036 With a `C-1' prefix, use the HH:MM value at point (if any) or the
10037 current HH:MM time."
10039 (if (not (eq major-mode 'org-agenda-mode))
10040 (user-error "You cannot do this outside of agenda buffers")
10041 (let ((org-overriding-default-time
10042 (org-get-cursor-date (equal with-time 1))))
10043 (call-interactively 'org-capture))))
10045 ;;; Dragging agenda lines forward/backward
10047 (defun org-agenda-reapply-filters ()
10048 "Re-apply all agenda filters."
10050 (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
10051 `((,org-agenda-tag-filter tag)
10052 (,org-agenda-category-filter category)
10053 (,org-agenda-regexp-filter regexp)
10054 (,org-agenda-effort-filter effort)
10055 (,(get 'org-agenda-tag-filter :preset-filter) tag)
10056 (,(get 'org-agenda-category-filter :preset-filter) category)
10057 (,(get 'org-agenda-effort-filter :preset-filter) effort)
10058 (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
10060 (defun org-agenda-drag-line-forward (arg &optional backward)
10061 "Drag an agenda line forward by ARG lines.
10062 When the optional argument `backward' is non-nil, move backward."
10064 (let ((inhibit-read-only t) lst line)
10065 (if (or (not (get-text-property (point) 'txt))
10068 (move-beginning-of-line (if backward 0 2))
10069 (push (not (get-text-property (point) 'txt)) lst))
10071 (message "Cannot move line forward")
10072 (let ((end (save-excursion (move-beginning-of-line 2) (point))))
10073 (move-beginning-of-line 1)
10074 (setq line (buffer-substring (point) end))
10075 (delete-region (point) end)
10076 (move-beginning-of-line (funcall (if backward '1- '1+) arg))
10078 (org-agenda-reapply-filters)
10079 (org-agenda-mark-clocking-task)
10080 (move-beginning-of-line 0)))))
10082 (defun org-agenda-drag-line-backward (arg)
10083 "Drag an agenda line backward by ARG lines."
10085 (org-agenda-drag-line-forward arg t))
10089 (defun org-agenda-show-the-flagging-note ()
10090 "Display the flagging note in the other window.
10091 When called a second time in direct sequence, offer to remove the FLAGGING
10092 tag and (if present) the flagging note."
10094 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
10095 (win (selected-window))
10096 note heading newhead)
10098 (user-error "No linked entry at point"))
10099 (if (and (eq this-command last-command)
10100 (y-or-n-p "Unflag and remove any flagging note? "))
10102 (org-agenda-remove-flag hdmarker)
10103 (let ((win (get-buffer-window "*Flagging Note*")))
10104 (and win (delete-window win)))
10105 (message "Entry unflagged"))
10106 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
10108 (user-error "No flagging note"))
10109 (org-kill-new note)
10110 (org-switch-to-buffer-other-window "*Flagging Note*")
10113 (goto-char (point-min))
10114 (while (re-search-forward "\\\\n" nil t)
10115 (replace-match "\n" t t))
10116 (goto-char (point-min))
10117 (select-window win)
10118 (message "%s" (substitute-command-keys "Flagging note pushed to \
10119 kill ring. Press \\[org-agenda-show-the-flagging-note] again to remove \
10122 (defun org-agenda-remove-flag (marker)
10123 "Remove the FLAGGED tag and any flagging note in the entry."
10125 (org-with-point-at marker
10126 (org-toggle-tag "FLAGGED" 'off)
10127 (org-entry-delete nil "THEFLAGGINGNOTE")
10128 (setq newhead (org-get-heading)))
10129 (org-agenda-change-all-lines newhead marker)
10130 (message "Entry unflagged")))
10132 (defun org-agenda-get-any-marker (&optional pos)
10133 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
10134 (get-text-property (or pos (point-at-bol)) 'org-marker)))
10136 ;;; Appointment reminders
10138 (defvar appt-time-msg-list) ; defined in appt.el
10141 (defun org-agenda-to-appt (&optional refresh filter &rest args)
10142 "Activate appointments found in `org-agenda-files'.
10143 With a \\[universal-argument] prefix, refresh the list of
10146 If FILTER is t, interactively prompt the user for a regular
10147 expression, and filter out entries that don't match it.
10149 If FILTER is a string, use this string as a regular expression
10150 for filtering entries out.
10152 If FILTER is a function, filter out entries against which
10153 calling the function returns nil. This function takes one
10154 argument: an entry from `org-agenda-get-day-entries'.
10156 FILTER can also be an alist with the car of each cell being
10157 either `headline' or `category'. For example:
10159 \\='((headline \"IMPORTANT\")
10160 (category \"Work\"))
10162 will only add headlines containing IMPORTANT or headlines
10163 belonging to the \"Work\" category.
10165 ARGS are symbols indicating what kind of entries to consider.
10166 By default `org-agenda-to-appt' will use :deadline*, :scheduled*
10167 \(i.e., deadlines and scheduled items with a hh:mm specification)
10168 and :timestamp entries. See the docstring of `org-diary' for
10169 details and examples.
10171 If an entry has a APPT_WARNTIME property, its value will be used
10172 to override `appt-message-warning-time'."
10174 (if refresh (setq appt-time-msg-list nil))
10176 (setq filter (read-from-minibuffer "Regexp filter: ")))
10177 (let* ((cnt 0) ; count added events
10178 (scope (or args '(:deadline* :scheduled* :timestamp)))
10179 (org-agenda-new-buffers nil)
10180 (org-deadline-warning-days 0)
10181 ;; Do not use `org-today' here because appt only takes
10182 ;; time and without date as argument, so it may pass wrong
10183 ;; information otherwise
10184 (today (org-date-to-gregorian
10185 (time-to-days (current-time))))
10186 (org-agenda-restrict nil)
10187 (files (org-agenda-files 'unrestricted)) entries file
10188 (org-agenda-buffer nil))
10189 ;; Get all entries which may contain an appt
10190 (org-agenda-prepare-buffers files)
10191 (while (setq file (pop files))
10195 (apply 'org-agenda-get-day-entries
10196 file today scope)))))
10197 ;; Map thru entries and find if we should filter them out
10200 (let* ((evt (org-trim
10201 (replace-regexp-in-string
10202 org-bracket-link-regexp "\\3"
10203 (or (get-text-property 1 'txt x) ""))))
10204 (cat (get-text-property (1- (length x)) 'org-category x))
10205 (tod (get-text-property 1 'time-of-day x))
10206 (ok (or (null filter)
10207 (and (stringp filter) (string-match filter evt))
10208 (and (functionp filter) (funcall filter x))
10209 (and (listp filter)
10210 (let ((cat-filter (cadr (assoc 'category filter)))
10211 (evt-filter (cadr (assoc 'headline filter))))
10212 (or (and (stringp cat-filter)
10213 (string-match cat-filter cat))
10214 (and (stringp evt-filter)
10215 (string-match evt-filter evt)))))))
10216 (wrn (get-text-property 1 'warntime x)))
10217 ;; FIXME: Shall we remove text-properties for the appt text?
10218 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
10219 (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
10220 (setq tod (concat "00" (number-to-string tod)))
10221 (setq tod (when (string-match
10222 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
10223 (concat (match-string 1 tod) ":"
10224 (match-string 2 tod))))
10225 (when (if (version< emacs-version "23.3")
10227 (appt-add tod evt wrn))
10228 (setq cnt (1+ cnt))))))
10230 (org-release-buffers org-agenda-new-buffers)
10232 (message "No event to add")
10233 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
10235 (defun org-agenda-today-p (date)
10236 "Non nil when DATE means today.
10237 DATE is either a list of the form (month day year) or a number of
10238 days as returned by `calendar-absolute-from-gregorian' or
10239 `org-today'. This function considers `org-extend-today-until'
10240 when defining today."
10242 (if (consp date) (calendar-absolute-from-gregorian date) date)))
10243 (define-obsolete-function-alias 'org-agenda-todayp 'org-agenda-today-p "25.1")
10245 (defun org-agenda-todo-yesterday (&optional arg)
10246 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
10248 (let* ((org-use-effective-time t)
10249 (hour (third (decode-time
10250 (org-current-time))))
10251 (org-extend-today-until (1+ hour)))
10252 (org-agenda-todo arg)))
10254 (provide 'org-agenda)
10256 ;;; org-agenda.el ends here