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
) ; defined in calendar.el
90 (defvar org-clock-current-task nil
) ; defined in org-clock.el
91 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
92 (defvar org-habit-show-habits
) ; defined in org-habit.el
93 (defvar org-habit-show-habits-only-for-today
)
94 (defvar org-habit-show-all-today
)
96 ;; Defined somewhere in this file, but used before definition.
97 (defvar org-agenda-buffer-name
"*Org Agenda*")
98 (defvar org-agenda-overriding-header nil
)
99 (defvar org-agenda-title-append nil
)
100 (org-no-warnings (defvar entry
)) ;; unprefixed, from calendar.el
101 (org-no-warnings (defvar date
)) ;; unprefixed, from calendar.el
102 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
104 (defvar org-agenda-undo-list nil
105 "List of undoable operations in the agenda since last refresh.")
106 (defvar org-agenda-pending-undo-list nil
107 "In a series of undo commands, this is the list of remaining undo items.")
109 (defcustom org-agenda-confirm-kill
1
110 "When set, remote killing from the agenda buffer needs confirmation.
111 When t, a confirmation is always needed. When a number N, confirmation is
112 only needed when the text to be killed contains more than N non-white lines."
115 (const :tag
"Never" nil
)
116 (const :tag
"Always" t
)
117 (integer :tag
"When more than N lines")))
119 (defcustom org-agenda-compact-blocks nil
120 "Non-nil means make the block agenda more compact.
121 This is done globally by leaving out lines like the agenda span
122 name and week number or the separator lines."
126 (defcustom org-agenda-block-separator ?
=
127 "The separator between blocks in the agenda.
128 If this is a string, it will be used as the separator, with a newline added.
129 If it is a character, it will be repeated to fill the window width.
130 If nil the separator is disabled. In `org-agenda-custom-commands' this
131 addresses the separator between the current and the previous block."
134 (const :tag
"Disabled" nil
)
138 (defgroup org-agenda-export nil
139 "Options concerning exporting agenda views in Org-mode."
140 :tag
"Org Agenda Export"
143 (defcustom org-agenda-with-colors t
144 "Non-nil means use colors in agenda views."
145 :group
'org-agenda-export
148 (defcustom org-agenda-exporter-settings nil
149 "Alist of variable/value pairs that should be active during agenda export.
150 This is a good place to set options for ps-print and for htmlize.
151 Note that the way this is implemented, the values will be evaluated
152 before assigned to the variables. So make sure to quote values you do
153 *not* want evaluated, for example
155 (setq org-agenda-exporter-settings
156 \\='((ps-print-color-p \\='black-white)))"
157 :group
'org-agenda-export
161 (sexp :tag
"Value"))))
163 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
164 "Hook run in a temporary buffer before writing the agenda to an export file.
165 A useful function for this hook is `org-agenda-add-entry-text'."
166 :group
'org-agenda-export
168 :options
'(org-agenda-add-entry-text))
170 (defcustom org-agenda-add-entry-text-maxlines
0
171 "Maximum number of entry text lines to be added to agenda.
172 This is only relevant when `org-agenda-add-entry-text' is part of
173 `org-agenda-before-write-hook', which is the default.
174 When this is 0, nothing will happen. When it is greater than 0, it
175 specifies the maximum number of lines that will be added for each entry
176 that is listed in the agenda view.
178 Note that this variable is not used during display, only when exporting
179 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
180 and `org-agenda-entry-text-maxlines'."
184 (defcustom org-agenda-add-entry-text-descriptive-links t
185 "Non-nil means export org-links as descriptive links in agenda added text.
186 This variable applies to the text added to the agenda when
187 `org-agenda-add-entry-text-maxlines' is larger than 0.
188 When this variable nil, the URL will (also) be shown."
192 (defcustom org-agenda-export-html-style nil
193 "The style specification for exported HTML Agenda files.
194 If this variable contains a string, it will replace the default <style>
195 section as produced by `htmlize'.
196 Since there are different ways of setting style information, this variable
197 needs to contain the full HTML structure to provide a style, including the
198 surrounding HTML tags. The style specifications should include definitions
199 the fonts used by the agenda, here is an example:
201 <style type=\"text/css\">
202 p { font-weight: normal; color: gray; }
203 .org-agenda-structure {
218 .title { text-align: center; }
219 .todo, .deadline { color: red; }
220 .done { color: green; }
223 or, if you want to keep the style in a file,
225 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
227 As the value of this option simply gets inserted into the HTML <head> header,
228 you can \"misuse\" it to also add other text to the header."
229 :group
'org-agenda-export
230 :group
'org-export-html
235 (defcustom org-agenda-persistent-filter nil
236 "When set, keep filters from one agenda view to the next."
240 (defgroup org-agenda-custom-commands nil
241 "Options concerning agenda views in Org-mode."
242 :tag
"Org Agenda Custom Commands"
245 (defconst org-sorting-choice
247 (const time-up
) (const time-down
)
248 (const timestamp-up
) (const timestamp-down
)
249 (const scheduled-up
) (const scheduled-down
)
250 (const deadline-up
) (const deadline-down
)
251 (const ts-up
) (const ts-down
)
252 (const tsia-up
) (const tsia-down
)
253 (const category-keep
) (const category-up
) (const category-down
)
254 (const tag-down
) (const tag-up
)
255 (const priority-up
) (const priority-down
)
256 (const todo-state-up
) (const todo-state-down
)
257 (const effort-up
) (const effort-down
)
258 (const habit-up
) (const habit-down
)
259 (const alpha-up
) (const alpha-down
)
260 (const user-defined-up
) (const user-defined-down
))
263 ;; Keep custom values for `org-agenda-filter-preset' compatible with
264 ;; the new variable `org-agenda-tag-filter-preset'.
265 (org-defvaralias 'org-agenda-filter-preset
'org-agenda-tag-filter-preset
)
266 (org-defvaralias 'org-agenda-filter
'org-agenda-tag-filter
)
268 (defvar org-agenda-entry-types
'(:deadline
:scheduled
:timestamp
:sexp
)
269 "List of types searched for when creating the daily/weekly agenda.
270 This variable is a list of symbols that controls the types of
271 items that appear in the daily/weekly agenda. Allowed symbols in this
274 :timestamp List items containing a date stamp or date range matching
275 the selected date. This includes sexp entries in angular
278 :sexp List entries resulting from plain diary-like sexps.
280 :deadline List deadline due on that date. When the date is today,
281 also list any deadlines past due, or due within
282 `org-deadline-warning-days'. `:deadline' must appear before
283 `:scheduled' if the setting of
284 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
287 :deadline* Same as above, but only include the deadline if it has an
288 hour specification as [h]h:mm.
290 :scheduled List all items which are scheduled for the given date.
291 The diary for *today* also contains items which were
292 scheduled earlier and are not yet marked DONE.
294 :scheduled* Same as above, but only include the scheduled item if it
295 has an hour specification as [h]h:mm.
297 By default, all four non-starred types are turned on.
299 When :scheduled* or :deadline* are included, :schedule or :deadline
302 Never set this variable globally using `setq', because then it
303 will apply to all future agenda commands. Instead, bind it with
304 `let' to scope it dynamically into the agenda-constructing
305 command. A good way to set it is through options in
306 `org-agenda-custom-commands'. For a more flexible (though
307 somewhat less efficient) way of determining what is included in
308 the daily/weekly agenda, see `org-agenda-skip-function'.")
310 (defconst org-agenda-custom-commands-local-options
311 `(repeat :tag
"Local settings for this command. Remember to quote values"
312 (choice :tag
"Setting"
313 (list :tag
"Heading for this block"
314 (const org-agenda-overriding-header
)
315 (string :tag
"Headline"))
316 (list :tag
"Files to be searched"
317 (const org-agenda-files
)
319 (const :format
"" quote
)
321 (list :tag
"Sorting strategy"
322 (const org-agenda-sorting-strategy
)
324 (const :format
"" quote
)
326 ,org-sorting-choice
)))
327 (list :tag
"Prefix format"
328 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
330 (list :tag
"Number of days in agenda"
331 (const org-agenda-span
)
332 (choice (const :tag
"Day" day
)
333 (const :tag
"Week" week
)
334 (const :tag
"Fortnight" fortnight
)
335 (const :tag
"Month" month
)
336 (const :tag
"Year" year
)
337 (integer :tag
"Custom")))
338 (list :tag
"Fixed starting date"
339 (const org-agenda-start-day
)
340 (string :value
"2007-11-01"))
341 (list :tag
"Start on day of week"
342 (const org-agenda-start-on-weekday
)
344 (const :tag
"Today" nil
)
345 (integer :tag
"Weekday No.")))
346 (list :tag
"Include data from diary"
347 (const org-agenda-include-diary
)
349 (list :tag
"Deadline Warning days"
350 (const org-deadline-warning-days
)
352 (list :tag
"Category filter preset"
353 (const org-agenda-category-filter-preset
)
355 (const :format
"" quote
)
357 (string :tag
"+category or -category"))))
358 (list :tag
"Tags filter preset"
359 (const org-agenda-tag-filter-preset
)
361 (const :format
"" quote
)
363 (string :tag
"+tag or -tag"))))
364 (list :tag
"Effort filter preset"
365 (const org-agenda-effort-filter-preset
)
367 (const :format
"" quote
)
369 (string :tag
"+=10 or -=10 or +<10 or ->10"))))
370 (list :tag
"Regexp filter preset"
371 (const org-agenda-regexp-filter-preset
)
373 (const :format
"" quote
)
375 (string :tag
"+regexp or -regexp"))))
376 (list :tag
"Set daily/weekly entry types"
377 (const org-agenda-entry-types
)
379 (const :format
"" quote
)
380 (set :greedy t
:value
,org-agenda-entry-types
387 (list :tag
"Standard skipping condition"
388 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
389 (const org-agenda-skip-function
)
391 (const :format
"" quote
)
394 :tag
"Skipping range"
395 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
396 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
397 (repeat :inline t
:tag
"Conditions for skipping"
399 :tag
"Condition type"
400 (list :tag
"Regexp matches" :inline t
401 (const :format
"" 'regexp
)
403 (list :tag
"Regexp does not match" :inline t
404 (const :format
"" 'notregexp
)
406 (list :tag
"TODO state is" :inline t
409 (const :tag
"Any not-done state" 'todo
)
410 (const :tag
"Any done state" 'done
)
411 (const :tag
"Any state" 'any
)
412 (list :tag
"Keyword list"
413 (const :format
"" quote
)
414 (repeat (string :tag
"Keyword")))))
415 (list :tag
"TODO state is not" :inline t
418 (const :tag
"Any not-done state" 'todo
)
419 (const :tag
"Any done state" 'done
)
420 (const :tag
"Any state" 'any
)
421 (list :tag
"Keyword list"
422 (const :format
"" quote
)
423 (repeat (string :tag
"Keyword")))))
424 (const :tag
"scheduled" 'scheduled
)
425 (const :tag
"not scheduled" 'notscheduled
)
426 (const :tag
"deadline" 'deadline
)
427 (const :tag
"no deadline" 'notdeadline
)
428 (const :tag
"timestamp" 'timestamp
)
429 (const :tag
"no timestamp" 'nottimestamp
))))))
430 (list :tag
"Non-standard skipping condition"
431 :value
(org-agenda-skip-function)
432 (const org-agenda-skip-function
)
433 (sexp :tag
"Function or form (quoted!)"))
434 (list :tag
"Any variable"
435 (variable :tag
"Variable")
436 (sexp :tag
"Value (sexp)"))))
437 "Selection of examples for agenda command settings.
438 This will be spliced into the custom type of
439 `org-agenda-custom-commands'.")
442 (defcustom org-agenda-custom-commands
443 '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
444 "Custom commands for the agenda.
445 These commands will be offered on the splash screen displayed by the
446 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
448 (key desc type match settings files)
450 key The key (one or more characters as a string) to be associated
452 desc A description of the command, when omitted or nil, a default
453 description is built using MATCH.
454 type The command type, any of the following symbols:
455 agenda The daily/weekly agenda.
456 todo Entries with a specific TODO keyword, in all agenda files.
457 search Entries containing search words entry or headline.
458 tags Tags/Property/TODO match in all agenda files.
459 tags-todo Tags/P/T match in all agenda files, TODO entries only.
460 todo-tree Sparse tree of specific TODO keyword in *current* file.
461 tags-tree Sparse tree with all tags matches in *current* file.
462 occur-tree Occur sparse tree for *current* file.
463 ... A user-defined function.
464 match What to search for:
465 - a single keyword for TODO keyword searches
466 - a tags match expression for tags searches
467 - a word search expression for text searches.
468 - a regular expression for occur searches
469 For all other commands, this should be the empty string.
470 settings A list of option settings, similar to that in a let form, so like
471 this: ((opt1 val1) (opt2 val2) ...). The values will be
472 evaluated at the moment of execution, so quote them when needed.
473 files A list of files file to write the produced agenda buffer to
474 with the command `org-store-agenda-views'.
475 If a file name ends in \".html\", an HTML version of the buffer
476 is written out. If it ends in \".ps\", a postscript version is
477 produced. Otherwise, only the plain text is written to the file.
479 You can also define a set of commands, to create a composite agenda buffer.
480 In this case, an entry looks like this:
482 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
486 desc A description string to be displayed in the dispatcher menu.
487 cmd An agenda command, similar to the above. However, tree commands
488 are not allowed, but instead you can get agenda and global todo list.
489 So valid commands for a set are:
490 (agenda \"\" settings)
491 (alltodo \"\" settings)
492 (stuck \"\" settings)
493 (todo \"match\" settings files)
494 (search \"match\" settings files)
495 (tags \"match\" settings files)
496 (tags-todo \"match\" settings files)
498 Each command can carry a list of options, and another set of options can be
499 given for the whole set of commands. Individual command options take
500 precedence over the general options.
502 When using several characters as key to a command, the first characters
503 are prefix commands. For the dispatcher to display useful information, you
504 should provide a description for the prefix, like
506 (setq org-agenda-custom-commands
507 \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
508 (\"hl\" tags \"+HOME+Lisa\")
509 (\"hp\" tags \"+HOME+Peter\")
510 (\"hk\" tags \"+HOME+Kim\")))"
511 :group
'org-agenda-custom-commands
513 (choice :value
("x" "Describe command here" tags
"" nil
)
514 (list :tag
"Single command"
515 (string :tag
"Access Key(s) ")
516 (option (string :tag
"Description"))
518 (const :tag
"Agenda" agenda
)
519 (const :tag
"TODO list" alltodo
)
520 (const :tag
"Search words" search
)
521 (const :tag
"Stuck projects" stuck
)
522 (const :tag
"Tags/Property match (all agenda files)" tags
)
523 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
524 (const :tag
"TODO keyword search (all agenda files)" todo
)
525 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
526 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
527 (const :tag
"Occur tree (current buffer)" occur-tree
)
528 (sexp :tag
"Other, user-defined function"))
529 (string :tag
"Match (only for some commands)")
530 ,org-agenda-custom-commands-local-options
531 (option (repeat :tag
"Export" (file :tag
"Export to"))))
532 (list :tag
"Command series, all agenda files"
533 (string :tag
"Access Key(s)")
534 (string :tag
"Description ")
535 (repeat :tag
"Component"
538 (const :format
"" agenda
)
539 (const :tag
"" :format
"" "")
540 ,org-agenda-custom-commands-local-options
)
541 (list :tag
"TODO list (all keywords)"
542 (const :format
"" alltodo
)
543 (const :tag
"" :format
"" "")
544 ,org-agenda-custom-commands-local-options
)
545 (list :tag
"Search words"
546 (const :format
"" search
)
547 (string :tag
"Match")
548 ,org-agenda-custom-commands-local-options
)
549 (list :tag
"Stuck projects"
550 (const :format
"" stuck
)
551 (const :tag
"" :format
"" "")
552 ,org-agenda-custom-commands-local-options
)
553 (list :tag
"Tags search"
554 (const :format
"" tags
)
555 (string :tag
"Match")
556 ,org-agenda-custom-commands-local-options
)
557 (list :tag
"Tags search, TODO entries only"
558 (const :format
"" tags-todo
)
559 (string :tag
"Match")
560 ,org-agenda-custom-commands-local-options
)
561 (list :tag
"TODO keyword search"
562 (const :format
"" todo
)
563 (string :tag
"Match")
564 ,org-agenda-custom-commands-local-options
)
565 (list :tag
"Other, user-defined function"
566 (symbol :tag
"function")
567 (string :tag
"Match")
568 ,org-agenda-custom-commands-local-options
)))
570 (repeat :tag
"Settings for entire command set"
571 (list (variable :tag
"Any variable")
572 (sexp :tag
"Value")))
573 (option (repeat :tag
"Export" (file :tag
"Export to"))))
574 (cons :tag
"Prefix key documentation"
575 (string :tag
"Access Key(s)")
576 (string :tag
"Description ")))))
578 (defcustom org-agenda-query-register ?o
579 "The register holding the current query string.
580 The purpose of this is that if you construct a query string interactively,
581 you can then use it to define a custom command."
582 :group
'org-agenda-custom-commands
585 (defcustom org-stuck-projects
586 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
587 "How to identify stuck projects.
588 This is a list of four items:
589 1. A tags/todo/property matcher string that is used to identify a project.
590 See the manual for a description of tag and property searches.
591 The entire tree below a headline matched by this is considered one project.
592 2. A list of TODO keywords identifying non-stuck projects.
593 If the project subtree contains any headline with one of these todo
594 keywords, the project is considered to be not stuck. If you specify
595 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
596 3. A list of tags identifying non-stuck projects.
597 If the project subtree contains any headline with one of these tags,
598 the project is considered to be not stuck. If you specify \"*\" as
599 a tag, any tag will mark the project unstuck. Note that this is about
600 the explicit presence of a tag somewhere in the subtree, inherited
601 tags do not count here. If inherited tags make a project not stuck,
602 use \"-TAG\" in the tags part of the matcher under (1.) above.
603 4. An arbitrary regular expression matching non-stuck projects.
605 If the project turns out to be not stuck, search continues also in the
606 subtree to see if any of the subtasks have project status.
608 See also the variable `org-tags-match-list-sublevels' which applies
609 to projects matched by this search as well.
611 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
612 or `C-c a #' to produce the list."
613 :group
'org-agenda-custom-commands
615 (string :tag
"Tags/TODO match to identify a project")
616 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
617 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
618 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
620 (defgroup org-agenda-skip nil
621 "Options concerning skipping parts of agenda files."
622 :tag
"Org Agenda Skip"
625 (defcustom org-agenda-skip-function-global nil
626 "Function to be called at each match during agenda construction.
627 If this function returns nil, the current match should not be skipped.
628 If the function decided to skip an agenda match, is must return the
629 buffer position from which the search should be continued.
630 This may also be a Lisp form, which will be evaluated.
632 This variable will be applied to every agenda match, including
633 tags/property searches and TODO lists. So try to make the test function
634 do its checking as efficiently as possible. To implement a skipping
635 condition just for specific agenda commands, use the variable
636 `org-agenda-skip-function' which can be set in the options section
637 of custom agenda commands."
638 :group
'org-agenda-skip
641 (defgroup org-agenda-daily
/weekly nil
642 "Options concerning the daily/weekly agenda."
643 :tag
"Org Agenda Daily/Weekly"
645 (defgroup org-agenda-todo-list nil
646 "Options concerning the global todo list agenda view."
647 :tag
"Org Agenda Todo List"
649 (defgroup org-agenda-match-view nil
650 "Options concerning the general tags/property/todo match agenda view."
651 :tag
"Org Agenda Match View"
653 (defgroup org-agenda-search-view nil
654 "Options concerning the search agenda view."
655 :tag
"Org Agenda Search View"
658 (defvar org-agenda-archives-mode nil
659 "Non-nil means the agenda will include archived items.
660 If this is the symbol `trees', trees in the selected agenda scope
661 that are marked with the ARCHIVE tag will be included anyway. When this is
662 t, also all archive files associated with the current selection of agenda
663 files will be included.")
665 (defcustom org-agenda-restriction-lock-highlight-subtree t
666 "Non-nil means highlight the whole subtree when restriction is active.
667 Otherwise only highlight the headline. Highlighting the whole subtree is
668 useful to ensure no edits happen beyond the restricted region."
672 (defcustom org-agenda-skip-comment-trees t
673 "Non-nil means skip trees that start with the COMMENT keyword.
674 When nil, these trees are also scanned by agenda commands."
675 :group
'org-agenda-skip
678 (defcustom org-agenda-todo-list-sublevels t
679 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
680 When nil, the sublevels of a TODO entry are not checked, resulting in
681 potentially much shorter TODO lists."
682 :group
'org-agenda-skip
683 :group
'org-agenda-todo-list
686 (defcustom org-agenda-todo-ignore-with-date nil
687 "Non-nil means don't show entries with a date in the global todo list.
688 You can use this if you prefer to mark mere appointments with a TODO keyword,
689 but don't want them to show up in the TODO list.
690 When this is set, it also covers deadlines and scheduled items, the settings
691 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
693 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
694 :group
'org-agenda-skip
695 :group
'org-agenda-todo-list
698 (defcustom org-agenda-todo-ignore-timestamp nil
699 "Non-nil means don't show entries with a timestamp.
700 This applies when creating the global todo list.
703 past Don't show entries for today or in the past.
705 future Don't show entries with a timestamp in the future.
706 The idea behind this is that if it has a future
707 timestamp, you don't want to think about it until the
710 all Don't show any entries with a timestamp in the global todo list.
711 The idea behind this is that by setting a timestamp, you
712 have already \"taken care\" of this item.
714 This variable can also have an integer as a value. If positive (N),
715 todos with a timestamp N or more days in the future will be ignored. If
716 negative (-N), todos with a timestamp N or more days in the past will be
717 ignored. If 0, todos with a timestamp either today or in the future will
718 be ignored. For example, a value of -1 will exclude todos with a
719 timestamp in the past (yesterday or earlier), while a value of 7 will
720 exclude todos with a timestamp a week or more in the future.
722 See also `org-agenda-todo-ignore-with-date'.
723 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
724 to make his option also apply to the tags-todo list."
725 :group
'org-agenda-skip
726 :group
'org-agenda-todo-list
729 (const :tag
"Ignore future timestamp todos" future
)
730 (const :tag
"Ignore past or present timestamp todos" past
)
731 (const :tag
"Ignore all timestamp todos" all
)
732 (const :tag
"Show timestamp todos" nil
)
733 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
735 (defcustom org-agenda-todo-ignore-scheduled nil
736 "Non-nil means, ignore some scheduled TODO items when making TODO list.
737 This applies when creating the global todo list.
740 past Don't show entries scheduled today or in the past.
742 future Don't show entries scheduled in the future.
743 The idea behind this is that by scheduling it, you don't want to
744 think about it until the scheduled date.
746 all Don't show any scheduled entries in the global todo list.
747 The idea behind this is that by scheduling it, you have already
748 \"taken care\" of this item.
750 t Same as `all', for backward compatibility.
752 This variable can also have an integer as a value. See
753 `org-agenda-todo-ignore-timestamp' for more details.
755 See also `org-agenda-todo-ignore-with-date'.
756 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
757 to make his option also apply to the tags-todo list."
758 :group
'org-agenda-skip
759 :group
'org-agenda-todo-list
761 (const :tag
"Ignore future-scheduled todos" future
)
762 (const :tag
"Ignore past- or present-scheduled todos" past
)
763 (const :tag
"Ignore all scheduled todos" all
)
764 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
765 (const :tag
"Show scheduled todos" nil
)
766 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
768 (defcustom org-agenda-todo-ignore-deadlines nil
769 "Non-nil means ignore some deadline TODO items when making TODO list.
770 There are different motivations for using different values, please think
771 carefully when configuring this variable.
773 This applies when creating the global todo list.
776 near Don't show near deadline entries. A deadline is near when it is
777 closer than `org-deadline-warning-days' days. The idea behind this
778 is that such items will appear in the agenda anyway.
780 far Don't show TODO entries where a deadline has been defined, but
781 the deadline is not near. This is useful if you don't want to
782 use the todo list to figure out what to do now.
784 past Don't show entries with a deadline timestamp for today or in the past.
786 future Don't show entries with a deadline timestamp in the future, not even
787 when they become `near' ones. Use it with caution.
789 all Ignore all TODO entries that do have a deadline.
791 t Same as `near', for backward compatibility.
793 This variable can also have an integer as a value. See
794 `org-agenda-todo-ignore-timestamp' for more details.
796 See also `org-agenda-todo-ignore-with-date'.
797 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
798 to make his option also apply to the tags-todo list."
799 :group
'org-agenda-skip
800 :group
'org-agenda-todo-list
802 (const :tag
"Ignore near deadlines" near
)
803 (const :tag
"Ignore near deadlines (compatibility)" t
)
804 (const :tag
"Ignore far deadlines" far
)
805 (const :tag
"Ignore all TODOs with a deadlines" all
)
806 (const :tag
"Show all TODOs, even if they have a deadline" nil
)
807 (integer :tag
"Ignore if N or more days in past(-) or future(+).")))
809 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
810 "Time unit to use when possibly ignoring an agenda item.
812 See the docstring of various `org-agenda-todo-ignore-*' options.
813 The default is to compare time stamps using days. An item is thus
814 considered to be in the future if it is at least one day after today.
815 Non-nil means to compare time stamps using seconds. An item is then
816 considered future if it has a time value later than current time."
817 :group
'org-agenda-skip
818 :group
'org-agenda-todo-list
820 :package-version
'(Org .
"8.0")
822 (const :tag
"Compare time with days" nil
)
823 (const :tag
"Compare time with seconds" t
)))
825 (defcustom org-agenda-tags-todo-honor-ignore-options nil
826 "Non-nil means honor todo-list ignores options also in tags-todo search.
828 `org-agenda-todo-ignore-with-date',
829 `org-agenda-todo-ignore-timestamp',
830 `org-agenda-todo-ignore-scheduled',
831 `org-agenda-todo-ignore-deadlines'
832 make the global TODO list skip entries that have time stamps of certain
833 kinds. If this option is set, the same options will also apply for the
834 tags-todo search, which is the general tags/property matcher
835 restricted to unfinished TODO entries only."
836 :group
'org-agenda-skip
837 :group
'org-agenda-todo-list
838 :group
'org-agenda-match-view
841 (defcustom org-agenda-skip-scheduled-if-done nil
842 "Non-nil means don't show scheduled items in agenda when they are done.
843 This is relevant for the daily/weekly agenda, not for the TODO list. And
844 it applies only to the actual date of the scheduling. Warnings about
845 an item with a past scheduling dates are always turned off when the item
847 :group
'org-agenda-skip
848 :group
'org-agenda-daily
/weekly
851 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
852 "Non-nil means skip scheduling line if same entry shows because of deadline.
854 In the agenda of today, an entry can show up multiple times
855 because it is both scheduled and has a nearby deadline, and maybe
856 a plain time stamp as well.
858 When this variable is nil, the entry will be shown several times.
860 When set to t, then only the deadline is shown and the fact that
861 the entry is scheduled today or was scheduled previously is not
864 When set to the symbol `not-today', skip scheduled previously,
865 but not scheduled today.
867 When set to the symbol `repeated-after-deadline', skip scheduled
868 items if they are repeated beyond the current deadline."
869 :group
'org-agenda-skip
870 :group
'org-agenda-daily
/weekly
872 (const :tag
"Never" nil
)
873 (const :tag
"Always" t
)
874 (const :tag
"Not when scheduled today" not-today
)
875 (const :tag
"When repeated past deadline" repeated-after-deadline
)))
877 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
878 "Non-nil means skip timestamp line if same entry shows because of deadline.
879 In the agenda of today, an entry can show up multiple times
880 because it has both a plain timestamp and has a nearby deadline.
881 When this variable is t, then only the deadline is shown and the
882 fact that the entry has a timestamp for or including today is not
883 shown. When this variable is nil, the entry will be shown
885 :group
'org-agenda-skip
886 :group
'org-agenda-daily
/weekly
889 (const :tag
"Never" nil
)
890 (const :tag
"Always" t
)))
892 (defcustom org-agenda-skip-deadline-if-done nil
893 "Non-nil means don't show deadlines when the corresponding item is done.
894 When nil, the deadline is still shown and should give you a happy feeling.
895 This is relevant for the daily/weekly agenda. And it applied only to the
896 actually date of the deadline. Warnings about approaching and past-due
897 deadlines are always turned off when the item is DONE."
898 :group
'org-agenda-skip
899 :group
'org-agenda-daily
/weekly
902 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
903 "Non-nil means skip deadline prewarning when entry is also scheduled.
904 This will apply on all days where a prewarning for the deadline would
905 be shown, but not at the day when the entry is actually due. On that day,
906 the deadline will be shown anyway.
907 This variable may be set to nil, t, the symbol `pre-scheduled',
908 or a number which will then give the number of days before the actual
909 deadline when the prewarnings should resume. The symbol `pre-scheduled'
910 eliminates the deadline prewarning only prior to the scheduled date.
911 This can be used in a workflow where the first showing of the deadline will
912 trigger you to schedule it, and then you don't want to be reminded of it
913 because you will take care of it on the day when scheduled."
914 :group
'org-agenda-skip
915 :group
'org-agenda-daily
/weekly
918 (const :tag
"Always show prewarning" nil
)
919 (const :tag
"Remove prewarning prior to scheduled date" pre-scheduled
)
920 (const :tag
"Remove prewarning if entry is scheduled" t
)
921 (integer :tag
"Restart prewarning N days before deadline")))
923 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
924 "Non-nil means skip scheduled delay when entry also has a deadline.
925 This variable may be set to nil, t, the symbol `post-deadline',
926 or a number which will then give the number of days after the actual
927 scheduled date when the delay should expire. The symbol `post-deadline'
928 eliminates the schedule delay when the date is posterior to the deadline."
929 :group
'org-agenda-skip
930 :group
'org-agenda-daily
/weekly
932 :package-version
'(Org .
"8.0")
934 (const :tag
"Always honor delay" nil
)
935 (const :tag
"Ignore delay if posterior to the deadline" post-deadline
)
936 (const :tag
"Ignore delay if entry has a deadline" t
)
937 (integer :tag
"Honor delay up until N days after the scheduled date")))
939 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
940 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
941 When non-nil, after the search for timestamps has matched once in an
942 entry, the rest of the entry will not be searched."
943 :group
'org-agenda-skip
946 (defcustom org-agenda-skip-timestamp-if-done nil
947 "Non-nil means don't select item by timestamp or -range if it is DONE."
948 :group
'org-agenda-skip
949 :group
'org-agenda-daily
/weekly
952 (defcustom org-agenda-dim-blocked-tasks t
953 "Non-nil means dim blocked tasks in the agenda display.
954 This causes some overhead during agenda construction, but if you
955 have turned on `org-enforce-todo-dependencies',
956 `org-enforce-todo-checkbox-dependencies', or any other blocking
957 mechanism, this will create useful feedback in the agenda.
959 Instead of t, this variable can also have the value `invisible'.
960 Then blocked tasks will be invisible and only become visible when
961 they become unblocked. An exemption to this behavior is when a task is
962 blocked because of unchecked checkboxes below it. Since checkboxes do
963 not show up in the agenda views, making this task invisible you remove any
964 trace from agenda views that there is something to do. Therefore, a task
965 that is blocked because of checkboxes will never be made invisible, it
966 will only be dimmed."
967 :group
'org-agenda-daily
/weekly
968 :group
'org-agenda-todo-list
971 (const :tag
"Do not dim" nil
)
972 (const :tag
"Dim to a gray face" t
)
973 (const :tag
"Make invisible" invisible
)))
975 (defcustom org-timeline-show-empty-dates
3
976 "Non-nil means `org-timeline' also shows dates without an entry.
977 When nil, only the days which actually have entries are shown.
978 When t, all days between the first and the last date are shown.
979 When an integer, show also empty dates, but if there is a gap of more than
980 N days, just insert a special line indicating the size of the gap."
981 :group
'org-agenda-skip
983 (const :tag
"None" nil
)
985 (integer :tag
"at most")))
987 (defgroup org-agenda-startup nil
988 "Options concerning initial settings in the Agenda in Org Mode."
989 :tag
"Org Agenda Startup"
992 (defcustom org-agenda-menu-show-matcher t
993 "Non-nil means show the match string in the agenda dispatcher menu.
994 When nil, the matcher string is not shown, but is put into the help-echo
995 property so than moving the mouse over the command shows it.
996 Setting it to nil is good if matcher strings are very long and/or if
997 you want to use two-columns display (see `org-agenda-menu-two-columns')."
1002 (define-obsolete-variable-alias 'org-agenda-menu-two-column
'org-agenda-menu-two-columns
"24.3")
1004 (defcustom org-agenda-menu-two-columns nil
1005 "Non-nil means, use two columns to show custom commands in the dispatcher.
1006 If you use this, you probably want to set `org-agenda-menu-show-matcher'
1012 (define-obsolete-variable-alias 'org-finalize-agenda-hook
'org-agenda-finalize-hook
"24.3")
1013 (defcustom org-agenda-finalize-hook nil
1014 "Hook run just before displaying an agenda buffer.
1015 The buffer is still writable when the hook is called.
1017 You can modify some of the buffer substrings but you should be
1018 extra careful not to modify the text properties of the agenda
1019 headlines as the agenda display heavily relies on them."
1020 :group
'org-agenda-startup
1023 (defcustom org-agenda-mouse-1-follows-link nil
1024 "Non-nil means mouse-1 on a link will follow the link in the agenda.
1025 A longer mouse click will still set point. Does not work on XEmacs.
1026 Needs to be set before org.el is loaded."
1027 :group
'org-agenda-startup
1030 (defcustom org-agenda-start-with-follow-mode nil
1031 "The initial value of follow mode in a newly created agenda window."
1032 :group
'org-agenda-startup
1035 (defcustom org-agenda-follow-indirect nil
1036 "Non-nil means `org-agenda-follow-mode' displays only the
1037 current item's tree, in an indirect buffer."
1042 (defcustom org-agenda-show-outline-path t
1043 "Non-nil means show outline path in echo area after line motion."
1044 :group
'org-agenda-startup
1047 (defcustom org-agenda-start-with-entry-text-mode nil
1048 "The initial value of entry-text-mode in a newly created agenda window."
1049 :group
'org-agenda-startup
1052 (defcustom org-agenda-entry-text-maxlines
5
1053 "Number of text lines to be added when `E' is pressed in the agenda.
1055 Note that this variable only used during agenda display. Add add entry text
1056 when exporting the agenda, configure the variable
1057 `org-agenda-add-entry-ext-maxlines'."
1061 (defcustom org-agenda-entry-text-exclude-regexps nil
1062 "List of regular expressions to clean up entry text.
1063 The complete matches of all regular expressions in this list will be
1064 removed from entry text before it is shown in the agenda."
1066 :type
'(repeat (regexp)))
1068 (defcustom org-agenda-entry-text-leaders
" > "
1069 "Text prepended to the entry text in agenda buffers."
1071 :package-version
'(Org .
"8.0")
1075 (defvar org-agenda-entry-text-cleanup-hook nil
1076 "Hook that is run after basic cleanup of entry text to be shown in agenda.
1077 This cleanup is done in a temporary buffer, so the function may inspect and
1078 change the entire buffer.
1079 Some default stuff like drawers and scheduling/deadline dates will already
1080 have been removed when this is called, as will any matches for regular
1081 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
1083 (defvar org-agenda-include-inactive-timestamps nil
1084 "Non-nil means include inactive time stamps in agenda and timeline.
1085 Dynamically scoped.")
1087 (defgroup org-agenda-windows nil
1088 "Options concerning the windows used by the Agenda in Org Mode."
1089 :tag
"Org Agenda Windows"
1092 (defcustom org-agenda-window-setup
'reorganize-frame
1093 "How the agenda buffer should be displayed.
1094 Possible values for this option are:
1096 current-window Show agenda in the current window, keeping all other windows.
1097 other-window Use `switch-to-buffer-other-window' to display agenda.
1098 only-window Show agenda, deleting all other windows.
1099 reorganize-frame Show only two windows on the current frame, the current
1100 window and the agenda.
1101 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1102 Also, when exiting the agenda, kill that frame.
1103 See also the variable `org-agenda-restore-windows-after-quit'."
1104 :group
'org-agenda-windows
1106 (const current-window
)
1108 (const other-window
)
1110 (const reorganize-frame
)))
1112 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
1113 "The min and max height of the agenda window as a fraction of frame height.
1114 The value of the variable is a cons cell with two numbers between 0 and 1.
1115 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1116 :group
'org-agenda-windows
1117 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
1119 (defcustom org-agenda-restore-windows-after-quit nil
1120 "Non-nil means restore window configuration upon exiting agenda.
1121 Before the window configuration is changed for displaying the agenda,
1122 the current status is recorded. When the agenda is exited with
1123 `q' or `x' and this option is set, the old state is restored. If
1124 `org-agenda-window-setup' is `other-frame', the value of this
1125 option will be ignored."
1126 :group
'org-agenda-windows
1129 (defcustom org-agenda-ndays nil
1130 "Number of days to include in overview display.
1132 Obsolete, see `org-agenda-span'."
1133 :group
'org-agenda-daily
/weekly
1134 :type
'(choice (const nil
)
1137 (make-obsolete-variable 'org-agenda-ndays
'org-agenda-span
"24.1")
1139 (defcustom org-agenda-span
'week
1140 "Number of days to include in overview display.
1141 Can be day, week, month, year, or any number of days.
1142 Custom commands can set this variable in the options section."
1143 :group
'org-agenda-daily
/weekly
1144 :type
'(choice (const :tag
"Day" day
)
1145 (const :tag
"Week" week
)
1146 (const :tag
"Fortnight" fortnight
)
1147 (const :tag
"Month" month
)
1148 (const :tag
"Year" year
)
1149 (integer :tag
"Custom")))
1151 (defcustom org-agenda-start-on-weekday
1
1152 "Non-nil means start the overview always on the specified weekday.
1153 0 denotes Sunday, 1 denotes Monday, etc.
1154 When nil, always start on the current day.
1155 Custom commands can set this variable in the options section."
1156 :group
'org-agenda-daily
/weekly
1157 :type
'(choice (const :tag
"Today" nil
)
1158 (integer :tag
"Weekday No.")))
1160 (defcustom org-agenda-show-all-dates t
1161 "Non-nil means `org-agenda' shows every day in the selected range.
1162 When nil, only the days which actually have entries are shown."
1163 :group
'org-agenda-daily
/weekly
1166 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
1167 "Format string for displaying dates in the agenda.
1168 Used by the daily/weekly agenda and by the timeline. This should be
1169 a format string understood by `format-time-string', or a function returning
1170 the formatted date as a string. The function must take a single argument,
1171 a calendar-style date list like (month day year)."
1172 :group
'org-agenda-daily
/weekly
1174 (string :tag
"Format string")
1175 (function :tag
"Function")))
1177 (defun org-agenda-format-date-aligned (date)
1178 "Format a DATE string for display in the daily/weekly agenda, or timeline.
1179 This function makes sure that dates are aligned for easy reading."
1181 (let* ((dayname (calendar-day-name date
))
1183 (day-of-week (calendar-day-of-week date
))
1185 (monthname (calendar-month-name month
))
1187 (iso-week (org-days-to-iso-week
1188 (calendar-absolute-from-gregorian date
)))
1189 (weekyear (cond ((and (= month
1) (>= iso-week
52))
1191 ((and (= month
12) (<= iso-week
1))
1194 (weekstring (if (= day-of-week
1)
1195 (format " W%02d" iso-week
)
1197 (format "%-10s %2d %s %4d%s"
1198 dayname day monthname year weekstring
)))
1200 (defcustom org-agenda-time-leading-zero nil
1201 "Non-nil means use leading zero for military times in agenda.
1202 For example, 9:30am would become 09:30 rather than 9:30."
1203 :group
'org-agenda-daily
/weekly
1207 (defcustom org-agenda-timegrid-use-ampm nil
1208 "When set, show AM/PM style timestamps on the timegrid."
1213 (defun org-agenda-time-of-day-to-ampm (time)
1214 "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
1215 (let* ((hour-number (string-to-number (substring time
0 -
3)))
1216 (minute (substring time -
2))
1219 ((equal hour-number
12)
1223 (setq hour-number
(- hour-number
12))))
1225 (if org-agenda-time-leading-zero
1226 (format "%02d" hour-number
)
1227 (format "%02s" (number-to-string hour-number
)))
1230 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1231 "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
1232 (if org-agenda-timegrid-use-ampm
1233 (org-agenda-time-of-day-to-ampm time
)
1236 (defcustom org-agenda-weekend-days
'(6 0)
1237 "Which days are weekend?
1238 These days get the special face `org-agenda-date-weekend' in the agenda
1239 and timeline buffers."
1240 :group
'org-agenda-daily
/weekly
1241 :type
'(set :greedy t
1242 (const :tag
"Monday" 1)
1243 (const :tag
"Tuesday" 2)
1244 (const :tag
"Wednesday" 3)
1245 (const :tag
"Thursday" 4)
1246 (const :tag
"Friday" 5)
1247 (const :tag
"Saturday" 6)
1248 (const :tag
"Sunday" 0)))
1250 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1251 "Non-nil means jump to today when moving a past date forward in time.
1252 When using S-right in the agenda to move a a date forward, and the date
1253 stamp currently points to the past, the first key press will move it
1254 to today. WHen nil, just move one day forward even if the date stays
1256 :group
'org-agenda-daily
/weekly
1260 (defcustom org-agenda-include-diary nil
1261 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1262 Custom commands can set this variable in the options section."
1263 :group
'org-agenda-daily
/weekly
1266 (defcustom org-agenda-include-deadlines t
1267 "If non-nil, include entries within their deadline warning period.
1268 Custom commands can set this variable in the options section."
1269 :group
'org-agenda-daily
/weekly
1273 (defcustom org-agenda-repeating-timestamp-show-all t
1274 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1275 When set to a list of strings, only show occurrences of repeating
1276 stamps for these TODO keywords. When nil, only one occurrence is
1277 shown, either today or the nearest into the future."
1278 :group
'org-agenda-daily
/weekly
1280 (const :tag
"Show repeating stamps" t
)
1281 (repeat :tag
"Show repeating stamps for these TODO keywords"
1282 (string :tag
"TODO Keyword"))
1283 (const :tag
"Don't show repeating stamps" nil
)))
1285 (defcustom org-scheduled-past-days
10000
1286 "Number of days to continue listing scheduled items not marked DONE.
1287 When an item is scheduled on a date, it shows up in the agenda on
1288 this day and will be listed until it is marked done or for the
1289 number of days given here."
1290 :group
'org-agenda-daily
/weekly
1293 (defcustom org-agenda-log-mode-items
'(closed clock
)
1294 "List of items that should be shown in agenda log mode.
1295 \\<org-agenda-mode-map>\
1296 This list may contain the following symbols:
1298 closed Show entries that have been closed on that day.
1299 clock Show entries that have received clocked time on that day.
1300 state Show all logged state changes.
1301 Note that instead of changing this variable, you can also press \
1302 `\\[universal-argument] \\[org-agenda-log-mode]' in
1303 the agenda to display all available LOG items temporarily."
1304 :group
'org-agenda-daily
/weekly
1305 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1307 (defcustom org-agenda-clock-consistency-checks
1308 '(:max-duration
"10:00" :min-duration
0 :max-gap
"0:05"
1309 :gap-ok-around
("4:00")
1310 :default-face
((:background
"DarkRed") (:foreground
"white"))
1311 :overlap-face nil
:gap-face nil
:no-end-time-face nil
1312 :long-face nil
:short-face nil
)
1313 "This is a property list, with the following keys:
1315 :max-duration Mark clocking chunks that are longer than this time.
1316 This is a time string like \"HH:MM\", or the number
1317 of minutes as an integer.
1319 :min-duration Mark clocking chunks that are shorter that this.
1320 This is a time string like \"HH:MM\", or the number
1321 of minutes as an integer.
1323 :max-gap Mark gaps between clocking chunks that are longer than
1324 this duration. A number of minutes, or a string
1327 :gap-ok-around List of times during the day which are usually not working
1328 times. When a gap is detected, but the gap contains any
1329 of these times, the gap is *not* reported. For example,
1330 if this is (\"4:00\" \"13:00\") then gaps that contain
1331 4:00 in the morning (i.e. the night) and 13:00
1332 (i.e. a typical lunch time) do not cause a warning.
1333 You should have at least one time during the night in this
1334 list, or otherwise the first task each morning will trigger
1335 a warning because it follows a long gap.
1337 Furthermore, the following properties can be used to define faces for
1340 :default-face the default face, if the specific face is undefined
1341 :overlap-face face for overlapping clocks
1342 :gap-face face for gaps between clocks
1343 :no-end-time-face face for incomplete clocks
1344 :long-face face for clock intervals that are too long
1345 :short-face face for clock intervals that are too short"
1346 :group
'org-agenda-daily
/weekly
1351 (defcustom org-agenda-log-mode-add-notes t
1352 "Non-nil means add first line of notes to log entries in agenda views.
1353 If a log item like a state change or a clock entry is associated with
1354 notes, the first line of these notes will be added to the entry in the
1356 :group
'org-agenda-daily
/weekly
1359 (defcustom org-agenda-start-with-log-mode nil
1360 "The initial value of log-mode in a newly created agenda window.
1361 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1362 explanations on the possible values."
1363 :group
'org-agenda-startup
1364 :group
'org-agenda-daily
/weekly
1365 :type
'(choice (const :tag
"Don't show log items" nil
)
1366 (const :tag
"Show only log items" only
)
1367 (const :tag
"Show all possible log items" clockcheck
)
1368 (repeat :tag
"Choose among possible values for `org-agenda-log-mode-items'"
1369 (choice (const :tag
"Show closed log items" closed
)
1370 (const :tag
"Show clocked log items" clock
)
1371 (const :tag
"Show all logged state changes" state
)))))
1373 (defcustom org-agenda-start-with-clockreport-mode nil
1374 "The initial value of clockreport-mode in a newly created agenda window."
1375 :group
'org-agenda-startup
1376 :group
'org-agenda-daily
/weekly
1379 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1380 "Property list with parameters for the clocktable in clockreport mode.
1381 This is the display mode that shows a clock table in the daily/weekly
1382 agenda, the properties for this dynamic block can be set here.
1383 The usual clocktable parameters are allowed here, but you cannot set
1384 the properties :name, :tstart, :tend, :block, and :scope - these will
1385 be overwritten to make sure the content accurately reflects the
1386 current display in the agenda."
1387 :group
'org-agenda-daily
/weekly
1390 (defcustom org-agenda-search-view-always-boolean nil
1391 "Non-nil means the search string is interpreted as individual parts.
1393 The search string for search view can either be interpreted as a phrase,
1394 or as a list of snippets that define a boolean search for a number of
1397 When this is non-nil, the string will be split on whitespace, and each
1398 snippet will be searched individually, and all must match in order to
1399 select an entry. A snippet is then a single string of non-white
1400 characters, or a string in double quotes, or a regexp in {} braces.
1401 If a snippet is preceded by \"-\", the snippet must *not* match.
1402 \"+\" is syntactic sugar for positive selection. Each snippet may
1403 be found as a full word or a partial word, but see the variable
1404 `org-agenda-search-view-force-full-words'.
1406 When this is nil, search will look for the entire search phrase as one,
1407 with each space character matching any amount of whitespace, including
1410 Even when this is nil, you can still switch to Boolean search dynamically
1411 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1412 is a regexp marked with braces like \"{abc}\", this will also switch to
1414 :group
'org-agenda-search-view
1418 (org-defvaralias 'org-agenda-search-view-search-words-only
1419 'org-agenda-search-view-always-boolean
)
1421 (defcustom org-agenda-search-view-force-full-words nil
1422 "Non-nil means, search words must be matches as complete words.
1423 When nil, they may also match part of a word."
1424 :group
'org-agenda-search-view
1428 (defcustom org-agenda-search-view-max-outline-level
0
1429 "Maximum outline level to display in search view.
1430 E.g. when this is set to 1, the search view will only
1431 show headlines of level 1. When set to 0, the default
1432 value, don't limit agenda view by outline level."
1433 :group
'org-agenda-search-view
1435 :package-version
'(Org .
"8.3")
1438 (defgroup org-agenda-time-grid nil
1439 "Options concerning the time grid in the Org-mode Agenda."
1440 :tag
"Org Agenda Time Grid"
1443 (defcustom org-agenda-search-headline-for-time t
1444 "Non-nil means search headline for a time-of-day.
1445 If the headline contains a time-of-day in one format or another, it will
1446 be used to sort the entry into the time sequence of items for a day.
1447 Some people have time stamps in the headline that refer to the creation
1448 time or so, and then this produces an unwanted side effect. If this is
1449 the case for your, use this variable to turn off searching the headline
1451 :group
'org-agenda-time-grid
1454 (defcustom org-agenda-use-time-grid t
1455 "Non-nil means show a time grid in the agenda schedule.
1456 A time grid is a set of lines for specific times (like every two hours between
1457 8:00 and 20:00). The items scheduled for a day at specific times are
1458 sorted in between these lines.
1459 For details about when the grid will be shown, and what it will look like, see
1460 the variable `org-agenda-time-grid'."
1461 :group
'org-agenda-time-grid
1464 (defcustom org-agenda-time-grid
1465 '((daily today require-timed
)
1467 (800 1000 1200 1400 1600 1800 2000))
1469 "The settings for time grid for agenda display.
1470 This is a list of three items. The first item is again a list. It contains
1471 symbols specifying conditions when the grid should be displayed:
1473 daily if the agenda shows a single day
1474 weekly if the agenda shows an entire week
1475 today show grid on current date, independent of daily/weekly display
1476 require-timed show grid only if at least one item has a time specification
1477 remove-match skip grid times already present in an entry
1479 The second item is a string which will be placed behind the grid time.
1481 The third item is a list of integers, indicating the times that should have
1483 :group
'org-agenda-time-grid
1486 (set :greedy t
:tag
"Grid Display Options"
1487 (const :tag
"Show grid in single day agenda display" daily
)
1488 (const :tag
"Show grid in weekly agenda display" weekly
)
1489 (const :tag
"Always show grid for today" today
)
1490 (const :tag
"Show grid only if any timed entries are present"
1492 (const :tag
"Skip grid times already present in an entry"
1494 (string :tag
"Grid String")
1495 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1497 (defcustom org-agenda-show-current-time-in-grid t
1498 "Non-nil means show the current time in the time grid."
1499 :group
'org-agenda-time-grid
1503 (defcustom org-agenda-current-time-string
1504 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1505 "The string for the current time marker in the agenda."
1506 :group
'org-agenda-time-grid
1510 (defgroup org-agenda-sorting nil
1511 "Options concerning sorting in the Org-mode Agenda."
1512 :tag
"Org Agenda Sorting"
1515 (defcustom org-agenda-sorting-strategy
1516 '((agenda habit-down time-up priority-down category-keep
)
1517 (todo priority-down category-keep
)
1518 (tags priority-down category-keep
)
1519 (search category-keep
))
1520 "Sorting structure for the agenda items of a single day.
1521 This is a list of symbols which will be used in sequence to determine
1522 if an entry should be listed before another entry. The following
1523 symbols are recognized:
1525 time-up Put entries with time-of-day indications first, early first
1526 time-down Put entries with time-of-day indications first, late first
1527 timestamp-up Sort by any timestamp, early first
1528 timestamp-down Sort by any timestamp, late first
1529 scheduled-up Sort by scheduled timestamp, early first
1530 scheduled-down Sort by scheduled timestamp, late first
1531 deadline-up Sort by deadline timestamp, early first
1532 deadline-down Sort by deadline timestamp, late first
1533 ts-up Sort by active timestamp, early first
1534 ts-down Sort by active timestamp, late first
1535 tsia-up Sort by inactive timestamp, early first
1536 tsia-down Sort by inactive timestamp, late first
1537 category-keep Keep the default order of categories, corresponding to the
1538 sequence in `org-agenda-files'.
1539 category-up Sort alphabetically by category, A-Z.
1540 category-down Sort alphabetically by category, Z-A.
1541 tag-up Sort alphabetically by last tag, A-Z.
1542 tag-down Sort alphabetically by last tag, Z-A.
1543 priority-up Sort numerically by priority, high priority last.
1544 priority-down Sort numerically by priority, high priority first.
1545 todo-state-up Sort by todo state, tasks that are done last.
1546 todo-state-down Sort by todo state, tasks that are done first.
1547 effort-up Sort numerically by estimated effort, high effort last.
1548 effort-down Sort numerically by estimated effort, high effort first.
1549 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1550 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1551 habit-up Put entries that are habits first
1552 habit-down Put entries that are habits last
1553 alpha-up Sort headlines alphabetically
1554 alpha-down Sort headlines alphabetically, reversed
1556 The different possibilities will be tried in sequence, and testing stops
1557 if one comparison returns a \"not-equal\". For example, the default
1558 '(time-up category-keep priority-down)
1559 means: Pull out all entries having a specified time of day and sort them,
1560 in order to make a time schedule for the current day the first thing in the
1561 agenda listing for the day. Of the entries without a time indication, keep
1562 the grouped in categories, don't sort the categories, but keep them in
1563 the sequence given in `org-agenda-files'. Within each category sort by
1566 Leaving out `category-keep' would mean that items will be sorted across
1567 categories by priority.
1569 Instead of a single list, this can also be a set of list for specific
1570 contents, with a context symbol in the car of the list, any of
1571 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1573 Custom commands can bind this variable in the options section."
1574 :group
'org-agenda-sorting
1576 (repeat :tag
"General" ,org-sorting-choice
)
1577 (list :tag
"Individually"
1578 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1579 (repeat ,org-sorting-choice
))
1580 (cons (const :tag
"Strategy for TODO lists" todo
)
1581 (repeat ,org-sorting-choice
))
1582 (cons (const :tag
"Strategy for Tags matches" tags
)
1583 (repeat ,org-sorting-choice
))
1584 (cons (const :tag
"Strategy for search matches" search
)
1585 (repeat ,org-sorting-choice
)))))
1587 (defcustom org-agenda-cmp-user-defined nil
1588 "A function to define the comparison `user-defined'.
1589 This function must receive two arguments, agenda entry a and b.
1590 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1591 the user comparison, return nil.
1592 When this is defined, you can make `user-defined-up' and `user-defined-down'
1593 part of an agenda sorting strategy."
1594 :group
'org-agenda-sorting
1597 (defcustom org-sort-agenda-notime-is-late t
1598 "Non-nil means items without time are considered late.
1599 This is only relevant for sorting. When t, items which have no explicit
1600 time like 15:30 will be considered as 99:01, i.e. later than any items which
1601 do have a time. When nil, the default time is before 0:00. You can use this
1602 option to decide if the schedule for today should come before or after timeless
1604 :group
'org-agenda-sorting
1607 (defcustom org-sort-agenda-noeffort-is-high t
1608 "Non-nil means items without effort estimate are sorted as high effort.
1609 This also applies when filtering an agenda view with respect to the
1610 < or > effort operator. Then, tasks with no effort defined will be treated
1611 as tasks with high effort.
1612 When nil, such items are sorted as 0 minutes effort."
1613 :group
'org-agenda-sorting
1616 (defgroup org-agenda-line-format nil
1617 "Options concerning the entry prefix in the Org-mode agenda display."
1618 :tag
"Org Agenda Line Format"
1621 (defcustom org-agenda-prefix-format
1622 '((agenda .
" %i %-12:c%?-12t% s")
1624 (todo .
" %i %-12:c")
1625 (tags .
" %i %-12:c")
1626 (search .
" %i %-12:c"))
1627 "Format specifications for the prefix of items in the agenda views.
1628 An alist with five entries, each for the different agenda types. The
1629 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1630 The values are format strings.
1632 This format works similar to a printf format, with the following meaning:
1634 %c the category of the item, \"Diary\" for entries from the diary,
1635 or as given by the CATEGORY keyword or derived from the file name
1636 %e the effort required by the item
1637 %l the level of the item (insert X space(s) if item is of level X)
1638 %i the icon category of the item, see `org-agenda-category-icon-alist'
1639 %T the last tag of the item (ignore inherited tags, which come first)
1640 %t the HH:MM time-of-day specification if one applies to the entry
1641 %s Scheduling/Deadline information, a short string
1642 %b show breadcrumbs, i.e., the names of the higher levels
1643 %(expression) Eval EXPRESSION and replace the control string
1646 All specifiers work basically like the standard `%s' of printf, but may
1647 contain two additional characters: a question mark just after the `%'
1648 and a whitespace/punctuation character just before the final letter.
1650 If the first character after `%' is a question mark, the entire field
1651 will only be included if the corresponding value applies to the current
1652 entry. This is useful for fields which should have fixed width when
1653 present, but zero width when absent. For example, \"%?-12t\" will
1654 result in a 12 character time field if a time of the day is specified,
1655 but will completely disappear in entries which do not contain a time.
1657 If there is punctuation or whitespace character just before the
1658 final format letter, this character will be appended to the field
1659 value if the value is not empty. For example, the format
1660 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1661 the category is empty, no additional colon is inserted.
1663 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1666 - Indent the line with two space characters
1667 - Give the category a 12 chars wide field, padded with whitespace on
1668 the right (because of `-'). Append a colon if there is a category
1670 - If there is a time-of-day, put it into a 12 chars wide field. If no
1671 time, don't put in an empty field, just skip it (because of '?').
1672 - Finally, put the scheduling information.
1674 See also the variables `org-agenda-remove-times-when-in-prefix' and
1675 `org-agenda-remove-tags'.
1677 Custom commands can set this variable in the options section."
1679 (string :tag
"General format")
1680 (list :greedy t
:tag
"View dependent"
1681 (cons (const agenda
) (string :tag
"Format"))
1682 (cons (const timeline
) (string :tag
"Format"))
1683 (cons (const todo
) (string :tag
"Format"))
1684 (cons (const tags
) (string :tag
"Format"))
1685 (cons (const search
) (string :tag
"Format"))))
1686 :group
'org-agenda-line-format
)
1688 (defvar org-prefix-format-compiled nil
1689 "The compiled prefix format and associated variables.
1690 This is a list where first element is a list of variable bindings, and second
1691 element is the compiled format expression. See the variable
1692 `org-agenda-prefix-format'.")
1694 (defcustom org-agenda-todo-keyword-format
"%-1s"
1695 "Format for the TODO keyword in agenda lines.
1696 Set this to something like \"%-12s\" if you want all TODO keywords
1697 to occupy a fixed space in the agenda display."
1698 :group
'org-agenda-line-format
1701 (defcustom org-agenda-diary-sexp-prefix nil
1702 "A regexp that matches part of a diary sexp entry
1703 which should be treated as scheduling/deadline information in
1706 For example, you can use this to extract the `diary-remind-message' from
1707 `diary-remind' entries."
1708 :group
'org-agenda-line-format
1709 :type
'(choice (const :tag
"None" nil
) (regexp :tag
"Regexp")))
1711 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1712 "Text preceding timerange entries in the agenda view.
1713 This is a list with two strings. The first applies when the range
1714 is entirely on one day. The second applies if the range spans several days.
1715 The strings may have two \"%d\" format specifiers which will be filled
1716 with the sequence number of the days, and the total number of days in the
1717 range, respectively."
1718 :group
'org-agenda-line-format
1720 (string :tag
"Deadline today ")
1721 (choice :tag
"Deadline relative"
1722 (string :tag
"Format string")
1725 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1726 "Text preceding scheduled items in the agenda view.
1727 This is a list with two strings. The first applies when the item is
1728 scheduled on the current day. The second applies when it has been scheduled
1729 previously, it may contain a %d indicating that this is the nth time that
1730 this item is scheduled, due to automatic rescheduling of unfinished items
1731 for the following day. So this number is one larger than the number of days
1732 that passed since this item was scheduled first."
1733 :group
'org-agenda-line-format
1735 :package-version
'(Org .
"8.0")
1737 (string :tag
"Scheduled today ")
1738 (string :tag
"Scheduled previously")))
1740 (defcustom org-agenda-inactive-leader
"["
1741 "Text preceding item pulled into the agenda by inactive time stamps.
1742 These entries are added to the agenda when pressing \"[\"."
1743 :group
'org-agenda-line-format
1747 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: " "%2d d. ago: ")
1748 "Text preceding deadline items in the agenda view.
1749 This is a list with three strings. The first applies when the item has its
1750 deadline on the current day. The second applies when the deadline is in the
1751 future, the third one when it is in the past. The strings may contain %d
1752 to capture the number of days."
1753 :group
'org-agenda-line-format
1755 :package-version
'(Org .
"8.0")
1757 (string :tag
"Deadline today ")
1758 (string :tag
"Deadline in the future ")
1759 (string :tag
"Deadline in the past ")))
1761 (defcustom org-agenda-remove-times-when-in-prefix t
1762 "Non-nil means remove duplicate time specifications in agenda items.
1763 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1764 time-of-day specification in a headline or diary entry is extracted and
1765 placed into the prefix. If this option is non-nil, the original specification
1766 \(a timestamp or -range, or just a plain time(range) specification like
1767 11:30-4pm) will be removed for agenda display. This makes the agenda less
1769 The option can be t or nil. It may also be the symbol `beg', indicating
1770 that the time should only be removed when it is located at the beginning of
1771 the headline/diary entry."
1772 :group
'org-agenda-line-format
1774 (const :tag
"Always" t
)
1775 (const :tag
"Never" nil
)
1776 (const :tag
"When at beginning of entry" beg
)))
1778 (defcustom org-agenda-remove-timeranges-from-blocks nil
1779 "Non-nil means remove time ranges specifications in agenda
1780 items that span on several days."
1781 :group
'org-agenda-line-format
1785 (defcustom org-agenda-default-appointment-duration nil
1786 "Default duration for appointments that only have a starting time.
1787 When nil, no duration is specified in such cases.
1788 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1789 :group
'org-agenda-line-format
1791 (integer :tag
"Minutes")
1792 (const :tag
"No default duration")))
1794 (defcustom org-agenda-show-inherited-tags t
1795 "Non-nil means show inherited tags in each agenda line.
1797 When this option is set to `always', it take precedences over
1798 `org-agenda-use-tag-inheritance' and inherited tags are shown
1801 When this option is set to t (the default), inherited tags are
1802 shown when they are available, i.e. when the value of
1803 `org-agenda-use-tag-inheritance' has been taken into account.
1805 This can be set to a list of agenda types in which the agenda
1806 must display the inherited tags. Available types are `todo',
1807 `agenda', `search' and `timeline'.
1809 When set to nil, never show inherited tags in agenda lines."
1810 :group
'org-agenda-line-format
1814 (const :tag
"Show inherited tags when available" t
)
1815 (const :tag
"Always show inherited tags" always
)
1816 (repeat :tag
"Show inherited tags only in selected agenda types"
1817 (symbol :tag
"Agenda type"))))
1819 (defcustom org-agenda-use-tag-inheritance
'(todo search timeline agenda
)
1820 "List of agenda view types where to use tag inheritance.
1822 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1823 controlled by `org-use-tag-inheritance'. In other agenda types,
1824 `org-use-tag-inheritance' is not used for the selection of the
1825 agenda entries. Still, you may want the agenda to be aware of
1826 the inherited tags anyway, e.g. for later tag filtering.
1828 Allowed value are `todo', `search', `timeline' and `agenda'.
1830 This variable has no effect if `org-agenda-show-inherited-tags'
1831 is set to `always'. In that case, the agenda is aware of those
1834 The default value sets tags in every agenda type. Setting this
1835 option to nil will speed up non-tags agenda view a lot."
1839 (const :tag
"Use tag inheritance in all agenda types" t
)
1840 (repeat :tag
"Use tag inheritance in selected agenda types"
1841 (symbol :tag
"Agenda type"))))
1843 (defcustom org-agenda-hide-tags-regexp nil
1844 "Regular expression used to filter away specific tags in agenda views.
1845 This means that these tags will be present, but not be shown in the agenda
1846 line. Secondary filtering will still work on the hidden tags.
1847 Nil means don't hide any tags."
1848 :group
'org-agenda-line-format
1850 (const :tag
"Hide none" nil
)
1851 (string :tag
"Regexp ")))
1853 (defcustom org-agenda-remove-tags nil
1854 "Non-nil means remove the tags from the headline copy in the agenda.
1855 When this is the symbol `prefix', only remove tags when
1856 `org-agenda-prefix-format' contains a `%T' specifier."
1857 :group
'org-agenda-line-format
1859 (const :tag
"Always" t
)
1860 (const :tag
"Never" nil
)
1861 (const :tag
"When prefix format contains %T" prefix
)))
1863 (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
1864 'org-agenda-remove-tags
)
1866 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1867 "Shift tags in agenda items to this column.
1868 If this number is positive, it specifies the column. If it is negative,
1869 it means that the tags should be flushright to that column. For example,
1870 -80 works well for a normal 80 character screen."
1871 :group
'org-agenda-line-format
1874 (org-defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
)
1876 (defcustom org-agenda-fontify-priorities
'cookies
1877 "Non-nil means highlight low and high priorities in agenda.
1878 When t, the highest priority entries are bold, lowest priority italic.
1879 However, settings in `org-priority-faces' will overrule these faces.
1880 When this variable is the symbol `cookies', only fontify the
1881 cookies, not the entire task.
1882 This may also be an association list of priority faces, whose
1883 keys are the character values of `org-highest-priority',
1884 `org-default-priority', and `org-lowest-priority' (the default values
1885 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1886 color as a string, or a list like `(:background \"Red\")'.
1887 If it is a color, the variable `org-faces-easy-properties'
1888 determines if it is a foreground or a background color."
1889 :group
'org-agenda-line-format
1891 (const :tag
"Never" nil
)
1892 (const :tag
"Defaults" t
)
1893 (const :tag
"Cookies only" cookies
)
1894 (repeat :tag
"Specify"
1895 (list (character :tag
"Priority" :value ?A
)
1896 (choice :tag
"Face "
1897 (string :tag
"Color")
1898 (sexp :tag
"Face"))))))
1900 (defcustom org-agenda-day-face-function nil
1901 "Function called to determine what face should be used to display a day.
1902 The only argument passed to that function is the day. It should
1903 returns a face, or nil if does not want to specify a face and let
1904 the normal rules apply."
1905 :group
'org-agenda-line-format
1907 :type
'(choice (const nil
) (function)))
1909 (defcustom org-agenda-category-icon-alist nil
1910 "Alist of category icon to be displayed in agenda views.
1912 Each entry should have the following format:
1914 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1916 Where CATEGORY-REGEXP is a regexp matching the categories where
1917 the icon should be displayed.
1918 FILE-OR-DATA either a file path or a string containing image data.
1920 The other fields can be omitted safely if not needed:
1921 TYPE indicates the image type.
1922 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1924 PROPS are additional image attributes to assign to the image,
1925 like, e.g. `:ascent center'.
1927 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1929 If you want to set the display properties yourself, just put a
1930 list as second element:
1932 (CATEGORY-REGEXP (MY PROPERTY LIST))
1934 For example, to display a 16px horizontal space for Emacs
1935 category, you can use:
1937 (\"Emacs\" \\='(space . (:width (16))))"
1938 :group
'org-agenda-line-format
1940 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1941 :value-type
(choice (list :tag
"Icon"
1942 (string :tag
"File or data")
1943 (symbol :tag
"Type")
1944 (boolean :tag
"Data?")
1945 (repeat :tag
"Extra image properties" :inline t symbol
))
1946 (list :tag
"Display properties" sexp
))))
1948 (defgroup org-agenda-column-view nil
1949 "Options concerning column view in the agenda."
1950 :tag
"Org Agenda Column View"
1953 (defcustom org-agenda-view-columns-initially nil
1954 "When non-nil, switch to columns view right after creating the agenda."
1955 :group
'org-agenda-column-view
1958 :package-version
'(Org .
"9.0")
1961 (defcustom org-agenda-columns-show-summaries t
1962 "Non-nil means show summaries for columns displayed in the agenda view."
1963 :group
'org-agenda-column-view
1966 (defcustom org-agenda-columns-compute-summary-properties t
1967 "Non-nil means recompute all summary properties before column view.
1968 When column view in the agenda is listing properties that have a summary
1969 operator, it can go to all relevant buffers and recompute the summaries
1970 there. This can mean overhead for the agenda column view, but is necessary
1971 to have thing up to date.
1972 As a special case, a CLOCKSUM property also makes sure that the clock
1973 computations are current."
1974 :group
'org-agenda-column-view
1977 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1978 "Non-nil means the duration of an appointment will add to day effort.
1979 The property to which appointment durations will be added is the one given
1980 in the option `org-effort-property'. If an appointment does not have
1981 an end time, `org-agenda-default-appointment-duration' will be used. If that
1982 is not set, an appointment without end time will not contribute to the time
1984 :group
'org-agenda-column-view
1987 (defcustom org-agenda-auto-exclude-function nil
1988 "A function called with a tag to decide if it is filtered on \
1989 \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
1990 The sole argument to the function, which is called once for each
1991 possible tag, is a string giving the name of the tag. The
1992 function should return either nil if the tag should be included
1993 as normal, or \"-<TAG>\" to exclude the tag.
1994 Note that for the purpose of tag filtering, only the lower-case version of
1995 all tags will be considered, so that this function will only ever see
1996 the lower-case version of all tags."
1998 :type
'(choice (const nil
) (function)))
2000 (defcustom org-agenda-bulk-custom-functions nil
2001 "Alist of characters and custom functions for bulk actions.
2002 For example, this value makes those two functions available:
2004 \\='((?R set-category)
2007 With selected entries in an agenda buffer, `B R' will call
2008 the custom function `set-category' on the selected entries.
2009 Note that functions in this alist don't need to be quoted."
2014 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
2015 "Execute BODY with point at location given by `org-hd-marker' property.
2016 If STRING is non-nil, the text property will be fetched from position 0
2017 in that string. If STRING is nil, it will be fetched from the beginning
2018 of the current line."
2019 (org-with-gensyms (marker)
2020 `(let ((,marker
(get-text-property (if ,string
0 (point-at-bol))
2021 'org-hd-marker
,string
)))
2022 (with-current-buffer (marker-buffer ,marker
)
2026 (def-edebug-spec org-agenda-with-point-at-orig-entry
(form body
))
2028 (defun org-add-agenda-custom-command (entry)
2029 "Replace or add a command in `org-agenda-custom-commands'.
2030 This is mostly for hacking and trying a new command - once the command
2031 works you probably want to add it to `org-agenda-custom-commands' for good."
2032 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
2034 (setcdr ass
(cdr entry
))
2035 (push entry org-agenda-custom-commands
))))
2037 ;;; Define the org-agenda-mode
2039 (defvar org-agenda-mode-map
(make-sparse-keymap)
2040 "Keymap for `org-agenda-mode'.")
2041 (org-defvaralias 'org-agenda-keymap
'org-agenda-mode-map
)
2043 (defvar org-agenda-menu
) ; defined later in this file.
2044 (defvar org-agenda-restrict nil
) ; defined later in this file.
2045 (defvar org-agenda-follow-mode nil
)
2046 (defvar org-agenda-entry-text-mode nil
)
2047 (defvar org-agenda-clockreport-mode nil
)
2048 (defvar org-agenda-show-log nil
)
2049 (defvar org-agenda-redo-command nil
)
2050 (defvar org-agenda-query-string nil
)
2051 (defvar org-agenda-mode-hook nil
2052 "Hook run after `org-agenda-mode' is turned on.
2053 The buffer is still writable when this hook is called.")
2054 (defvar org-agenda-type nil
)
2055 (defvar org-agenda-force-single-file nil
)
2056 (defvar org-agenda-bulk-marked-entries nil
2057 "List of markers that refer to marked entries in the agenda.")
2058 (defvar org-agenda-current-date nil
2059 "Active date when building the agenda.")
2061 ;;; Multiple agenda buffers support
2063 (defcustom org-agenda-sticky nil
2064 "Non-nil means agenda q key will bury agenda buffers.
2065 Agenda commands will then show existing buffer instead of generating new ones.
2066 When nil, `q' will kill the single agenda buffer."
2073 (defun org-toggle-sticky-agenda (&optional arg
)
2074 "Toggle `org-agenda-sticky'."
2076 (let ((new-value (if arg
2077 (> (prefix-numeric-value arg
) 0)
2078 (not org-agenda-sticky
))))
2079 (if (equal new-value org-agenda-sticky
)
2080 (and (org-called-interactively-p 'interactive
)
2081 (message "Sticky agenda was already %s"
2082 (if org-agenda-sticky
"enabled" "disabled")))
2083 (setq org-agenda-sticky new-value
)
2084 (org-agenda-kill-all-agenda-buffers)
2085 (and (org-called-interactively-p 'interactive
)
2086 (message "Sticky agenda %s"
2087 (if org-agenda-sticky
"enabled" "disabled"))))))
2089 (defvar org-agenda-buffer nil
2090 "Agenda buffer currently being generated.")
2092 (defvar org-agenda-last-prefix-arg nil
)
2093 (defvar org-agenda-this-buffer-name nil
)
2094 (defvar org-agenda-doing-sticky-redo nil
)
2095 (defvar org-agenda-this-buffer-is-sticky nil
)
2096 (defvar org-agenda-last-indirect-buffer nil
2097 "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
2099 (defconst org-agenda-local-vars
2100 '(org-agenda-this-buffer-name
2101 org-agenda-undo-list
2102 org-agenda-pending-undo-list
2103 org-agenda-follow-mode
2104 org-agenda-entry-text-mode
2105 org-agenda-clockreport-mode
2107 org-agenda-redo-command
2108 org-agenda-query-string
2110 org-agenda-bulk-marked-entries
2111 org-agenda-undo-has-started-in
2113 org-agenda-pre-window-conf
2114 org-agenda-columns-active
2115 org-agenda-tag-filter
2116 org-agenda-category-filter
2117 org-agenda-top-headline-filter
2118 org-agenda-regexp-filter
2119 org-agenda-effort-filter
2121 org-agenda-last-search-view-search-was-boolean
2122 org-agenda-last-indirect-buffer
2123 org-agenda-filtered-by-category
2124 org-agenda-filter-form
2125 org-agenda-cycle-counter
2126 org-agenda-last-prefix-arg
)
2127 "Variables that must be local in agenda buffers to allow multiple buffers.")
2129 (defun org-agenda-mode ()
2130 "Mode for time-sorted view on action items in Org-mode files.
2132 The following commands are available:
2134 \\{org-agenda-mode-map}"
2136 (cond (org-agenda-doing-sticky-redo
2137 ;; Refreshing sticky agenda-buffer
2139 ;; Preserve the value of `org-agenda-local-vars' variables,
2140 ;; while letting `kill-all-local-variables' kill the rest
2141 (let ((save (buffer-local-variables)))
2142 (kill-all-local-variables)
2143 (mapc 'make-local-variable org-agenda-local-vars
)
2145 (let ((var (car elem
))
2148 (member var org-agenda-local-vars
))
2150 (setq-local org-agenda-this-buffer-is-sticky t
))
2152 ;; Creating a sticky Agenda buffer for the first time
2153 (kill-all-local-variables)
2154 (mapc 'make-local-variable org-agenda-local-vars
)
2155 (setq-local org-agenda-this-buffer-is-sticky t
))
2157 ;; Creating a non-sticky agenda buffer
2158 (kill-all-local-variables)
2159 (setq-local org-agenda-this-buffer-is-sticky nil
)))
2160 (setq org-agenda-undo-list nil
2161 org-agenda-pending-undo-list nil
2162 org-agenda-bulk-marked-entries nil
)
2163 (setq major-mode
'org-agenda-mode
)
2164 ;; Keep global-font-lock-mode from turning on font-lock-mode
2165 (setq-local font-lock-global-modes
(list 'not major-mode
))
2166 (setq mode-name
"Org-Agenda")
2167 (setq indent-tabs-mode nil
)
2168 (use-local-map org-agenda-mode-map
)
2169 (easy-menu-add org-agenda-menu
)
2170 (if org-startup-truncated
(setq truncate-lines t
))
2171 (setq-local line-move-visual nil
)
2172 (org-add-hook 'post-command-hook
'org-agenda-update-agenda-type nil
'local
)
2173 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
2174 ;; Make sure properties are removed when copying text
2175 (org-add-hook 'filter-buffer-substring-functions
2176 (lambda (fun start end delete
)
2177 (substring-no-properties (funcall fun start end delete
)))
2179 (unless org-agenda-keep-modes
2180 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2181 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
))
2182 (setq org-agenda-show-log org-agenda-start-with-log-mode
)
2183 (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
)
2184 (add-to-invisibility-spec '(org-filtered))
2185 (add-to-invisibility-spec '(org-link))
2187 '("Agenda") "Agenda Files"
2191 (if (get 'org-agenda-files
'org-restrict
)
2192 "Restricted to single file"
2194 '(org-edit-agenda-file-list)
2195 (not (get 'org-agenda-files
'org-restrict
)))
2197 (mapcar 'org-file-menu-entry
(org-agenda-files))))
2198 (org-agenda-set-mode-name)
2200 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
2201 (list 'org-agenda-mode-hook
)))
2203 (substitute-key-definition 'undo
'org-agenda-undo
2204 org-agenda-mode-map global-map
)
2205 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
2206 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
2207 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
2208 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
2209 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
2210 (org-defkey org-agenda-mode-map
[(meta down
)] 'org-agenda-drag-line-forward
)
2211 (org-defkey org-agenda-mode-map
[(meta up
)] 'org-agenda-drag-line-backward
)
2212 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
2213 (org-defkey org-agenda-mode-map
"\M-m" 'org-agenda-bulk-toggle
)
2214 (org-defkey org-agenda-mode-map
"*" 'org-agenda-bulk-mark-all
)
2215 (org-defkey org-agenda-mode-map
"\M-*" 'org-agenda-bulk-toggle-all
)
2216 (org-defkey org-agenda-mode-map
"#" 'org-agenda-dim-blocked-tasks
)
2217 (org-defkey org-agenda-mode-map
"%" 'org-agenda-bulk-mark-regexp
)
2218 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
2219 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-unmark-all
)
2220 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
2221 (org-defkey org-agenda-mode-map
"k" 'org-agenda-capture
)
2222 (org-defkey org-agenda-mode-map
"A" 'org-agenda-append-agenda
)
2223 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
2224 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
2225 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
2226 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
2227 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
2228 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
2229 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
2230 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
2231 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
2232 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
2233 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2234 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2235 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2236 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2237 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2238 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2239 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2240 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2241 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2242 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2243 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2244 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2245 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2246 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2247 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2248 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2249 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2250 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2251 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2252 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2253 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2254 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2256 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2257 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2258 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2259 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2260 (while l (org-defkey org-agenda-mode-map
2261 (int-to-string (pop l)) 'digit-argument)))
2263 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2264 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2265 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2266 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2267 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2268 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2269 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2270 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2271 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2272 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2273 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2274 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2275 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2276 'org-clock-modify-effort-estimate)
2277 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2278 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2279 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2280 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2281 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2282 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2283 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2284 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2285 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2286 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2287 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2288 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2289 (substitute-key-definition 'next-line 'org-agenda-next-line
2290 org-agenda-mode-map global-map)
2291 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2292 org-agenda-mode-map global-map)
2293 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2294 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2295 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2296 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2297 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2298 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2299 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2300 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2301 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2302 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2303 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2304 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2305 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2306 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2307 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2308 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2309 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2310 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2311 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2312 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2313 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2314 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2315 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2316 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2317 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2318 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2319 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2320 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2321 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2322 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2324 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2325 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2326 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2327 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2328 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2329 (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
2330 (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
2331 (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
2332 (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
2333 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2334 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
2335 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2336 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2337 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2338 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2340 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2341 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2343 (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
2344 (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
2346 (when org-agenda-mouse-1-follows-link
2347 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2348 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2353 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2354 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2355 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2356 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2359 ["Day View" org-agenda-day-view
2360 :active (org-agenda-check-type nil 'agenda)
2361 :style radio :selected (eq org-agenda-current-span 'day)
2362 :keys "v d (or just d)"]
2363 ["Week View" org-agenda-week-view
2364 :active (org-agenda-check-type nil 'agenda)
2365 :style radio :selected (eq org-agenda-current-span 'week)
2367 ["Fortnight View" org-agenda-fortnight-view
2368 :active (org-agenda-check-type nil 'agenda)
2369 :style radio :selected (eq org-agenda-current-span 'fortnight)
2371 ["Month View" org-agenda-month-view
2372 :active (org-agenda-check-type nil 'agenda)
2373 :style radio :selected (eq org-agenda-current-span 'month)
2375 ["Year View" org-agenda-year-view
2376 :active (org-agenda-check-type nil 'agenda)
2377 :style radio :selected (eq org-agenda-current-span 'year)
2380 ["Include Diary" org-agenda-toggle-diary
2381 :style toggle :selected org-agenda-include-diary
2382 :active (org-agenda-check-type nil 'agenda)]
2383 ["Include Deadlines" org-agenda-toggle-deadlines
2384 :style toggle :selected org-agenda-include-deadlines
2385 :active (org-agenda-check-type nil 'agenda)]
2386 ["Use Time Grid" org-agenda-toggle-time-grid
2387 :style toggle :selected org-agenda-use-time-grid
2388 :active (org-agenda-check-type nil 'agenda)]
2390 ["Show clock report" org-agenda-clockreport-mode
2391 :style toggle :selected org-agenda-clockreport-mode
2392 :active (org-agenda-check-type nil 'agenda)]
2393 ["Show some entry text" org-agenda-entry-text-mode
2394 :style toggle :selected org-agenda-entry-text-mode
2397 ["Show Logbook entries" org-agenda-log-mode
2398 :style toggle :selected org-agenda-show-log
2399 :active (org-agenda-check-type nil 'agenda 'timeline)
2400 :keys "v l (or just l)"]
2401 ["Include archived trees" org-agenda-archives-mode
2402 :style toggle :selected org-agenda-archives-mode :active t
2404 ["Include archive files" (org-agenda-archives-mode t)
2405 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2408 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2409 ["Write view to file" org-agenda-write t]
2410 ["Rebuild buffer" org-agenda-redo t]
2411 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2413 ["Show original entry" org-agenda-show t]
2414 ["Go To (other window)" org-agenda-goto t]
2415 ["Go To (this window)" org-agenda-switch-to t]
2416 ["Capture with cursor date" org-agenda-capture t]
2417 ["Follow Mode" org-agenda-follow-mode
2418 :style toggle :selected org-agenda-follow-mode :active t]
2419 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2422 ["Cycle TODO" org-agenda-todo t]
2423 ["Next TODO set" org-agenda-todo-nextset t]
2424 ["Previous TODO set" org-agenda-todo-previousset t]
2425 ["Add note" org-agenda-add-note t])
2426 ("Archive/Refile/Delete"
2427 ["Archive default" org-agenda-archive-default t]
2428 ["Archive default" org-agenda-archive-default-with-confirmation t]
2429 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2430 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2431 ["Archive subtree" org-agenda-archive t]
2433 ["Refile" org-agenda-refile t]
2435 ["Delete subtree" org-agenda-kill t])
2437 ["Mark entry" org-agenda-bulk-mark t]
2438 ["Mark all" org-agenda-bulk-mark-all t]
2439 ["Unmark entry" org-agenda-bulk-unmark t]
2440 ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
2441 ["Toggle mark" org-agenda-bulk-toggle t]
2442 ["Toggle all" org-agenda-bulk-toggle-all t]
2443 ["Mark regexp" org-agenda-bulk-mark-regexp t])
2444 ["Act on all marked" org-agenda-bulk-action t]
2446 ("Tags and Properties"
2447 ["Show all Tags" org-agenda-show-tags t]
2448 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2449 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2451 ["Column View" org-columns t])
2452 ("Deadline/Schedule"
2453 ["Schedule" org-agenda-schedule t]
2454 ["Set Deadline" org-agenda-deadline t]
2456 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2457 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2458 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2459 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2460 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2461 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2462 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2464 ["Clock in" org-agenda-clock-in t]
2465 ["Clock out" org-agenda-clock-out t]
2466 ["Clock cancel" org-agenda-clock-cancel t]
2467 ["Goto running clock" org-clock-goto t]
2469 ["Set Effort" org-agenda-set-effort t]
2470 ["Change clocked effort" org-clock-modify-effort-estimate
2471 (org-clock-is-active)])
2473 ["Set Priority" org-agenda-priority t]
2474 ["Increase Priority" org-agenda-priority-up t]
2475 ["Decrease Priority" org-agenda-priority-down t]
2476 ["Show Priority" org-show-priority t])
2478 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2479 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2480 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2481 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2482 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2483 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2485 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2487 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2490 ["Push Files and Views" org-mobile-push t]
2491 ["Get Captured and Flagged" org-mobile-pull t]
2492 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2493 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2495 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2497 ["Quit" org-agenda-quit t]
2498 ["Exit and Release Buffers" org-agenda-exit t]
2503 (defvar org-agenda-allow-remote-undo t
2504 "Non-nil means allow remote undo from the agenda buffer.")
2505 (defvar org-agenda-undo-has-started-in nil
2506 "Buffers that have already seen `undo-start' in the current undo sequence.")
2508 (defun org-agenda-undo ()
2509 "Undo a remote editing step in the agenda.
2510 This undoes changes both in the agenda buffer and in the remote buffer
2511 that have been changed along."
2513 (or org-agenda-allow-remote-undo
2514 (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2515 (if (not (eq this-command last-command))
2516 (setq org-agenda-undo-has-started-in nil
2517 org-agenda-pending-undo-list org-agenda-undo-list))
2518 (if (not org-agenda-pending-undo-list)
2519 (user-error "No further undo information"))
2520 (let* ((entry (pop org-agenda-pending-undo-list))
2521 buf line cmd rembuf)
2522 (setq cmd (pop entry) line (pop entry))
2523 (setq rembuf (nth 2 entry))
2524 (org-with-remote-undo rembuf
2525 (while (bufferp (setq buf (pop entry)))
2527 (with-current-buffer buf
2528 (let ((last-undo-buffer buf)
2529 (inhibit-read-only t))
2530 (unless (memq buf org-agenda-undo-has-started-in)
2531 (push buf org-agenda-undo-has-started-in)
2532 (make-local-variable 'pending-undo-list)
2534 (while (and pending-undo-list
2535 (listp pending-undo-list)
2536 (not (car pending-undo-list)))
2537 (pop pending-undo-list))
2539 (org-goto-line line)
2540 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2542 (defun org-verify-change-for-undo (l1 l2)
2543 "Verify that a real change occurred between the undo lists L1 and L2."
2544 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2545 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2550 (defvar org-agenda-restrict-begin (make-marker))
2551 (defvar org-agenda-restrict-end (make-marker))
2552 (defvar org-agenda-last-dispatch-buffer nil)
2553 (defvar org-agenda-overriding-restriction nil)
2555 (defcustom org-agenda-custom-commands-contexts nil
2556 "Alist of custom agenda keys and contextual rules.
2558 For example, if you have a custom agenda command \"p\" and you
2559 want this command to be accessible only from plain text files,
2562 \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
2564 Here are the available contexts definitions:
2566 in-file: command displayed only in matching files
2567 in-mode: command displayed only in matching modes
2568 not-in-file: command not displayed in matching files
2569 not-in-mode: command not displayed in matching modes
2570 in-buffer: command displayed only in matching buffers
2571 not-in-buffer: command not displayed in matching buffers
2572 [function]: a custom function taking no argument
2574 If you define several checks, the agenda command will be
2575 accessible if there is at least one valid check.
2577 You can also bind a key to another agenda custom command
2578 depending on contextual rules.
2580 \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
2582 Here it means: in .txt files, use \"p\" as the key for the
2583 agenda command otherwise associated with \"q\". (The command
2584 originally associated with \"q\" is not displayed to avoid
2587 :group 'org-agenda-custom-commands
2588 :type '(repeat (list :tag "Rule"
2589 (string :tag " Agenda key")
2590 (string :tag "Replace by command")
2591 (repeat :tag "Available when"
2593 (cons :tag "Condition"
2595 (const :tag "In file" in-file)
2596 (const :tag "Not in file" not-in-file)
2597 (const :tag "In buffer" in-buffer)
2598 (const :tag "Not in buffer" not-in-buffer)
2599 (const :tag "In mode" in-mode)
2600 (const :tag "Not in mode" not-in-mode))
2602 (function :tag "Custom function"))))))
2604 (defcustom org-agenda-max-entries nil
2605 "Maximum number of entries to display in an agenda.
2606 This can be nil (no limit) or an integer or an alist of agenda
2607 types with an associated number of entries to display in this
2610 :package-version '(Org . "8.0")
2611 :group 'org-agenda-custom-commands
2612 :type '(choice (symbol :tag "No limit" nil)
2613 (integer :tag "Max number of entries")
2615 (cons (choice :tag "Agenda type"
2621 (integer :tag "Max number of entries")))))
2623 (defcustom org-agenda-max-todos nil
2624 "Maximum number of TODOs to display in an agenda.
2625 This can be nil (no limit) or an integer or an alist of agenda
2626 types with an associated number of entries to display in this
2629 :package-version '(Org . "8.0")
2630 :group 'org-agenda-custom-commands
2631 :type '(choice (symbol :tag "No limit" nil)
2632 (integer :tag "Max number of TODOs")
2634 (cons (choice :tag "Agenda type"
2640 (integer :tag "Max number of TODOs")))))
2642 (defcustom org-agenda-max-tags nil
2643 "Maximum number of tagged entries to display in an agenda.
2644 This can be nil (no limit) or an integer or an alist of agenda
2645 types with an associated number of entries to display in this
2648 :package-version '(Org . "8.0")
2649 :group 'org-agenda-custom-commands
2650 :type '(choice (symbol :tag "No limit" nil)
2651 (integer :tag "Max number of tagged entries")
2653 (cons (choice :tag "Agenda type"
2659 (integer :tag "Max number of tagged entries")))))
2661 (defcustom org-agenda-max-effort nil
2662 "Maximum cumulated effort duration for the agenda.
2663 This can be nil (no limit) or a number of minutes (as an integer)
2664 or an alist of agenda types with an associated number of minutes
2665 to limit entries to in this type."
2667 :package-version '(Org . "8.0")
2668 :group 'org-agenda-custom-commands
2669 :type '(choice (symbol :tag "No limit" nil)
2670 (integer :tag "Max number of minutes")
2672 (cons (choice :tag "Agenda type"
2678 (integer :tag "Max number of minutes")))))
2680 (defvar org-keys nil)
2681 (defvar org-match nil)
2683 (defun org-agenda (&optional arg org-keys restriction)
2684 "Dispatch agenda commands to collect entries to the agenda buffer.
2685 Prompts for a command to execute. Any prefix arg will be passed
2686 on to the selected command. The default selections are:
2688 a Call `org-agenda-list' to display the agenda for current day or week.
2689 t Call `org-todo-list' to display the global todo list.
2690 T Call `org-todo-list' to display the global todo list, select only
2691 entries with a specific TODO keyword (the user gets a prompt).
2692 m Call `org-tags-view' to display headlines with tags matching
2693 a condition (the user is prompted for the condition).
2694 M Like `m', but select only TODO entries, no ordinary headlines.
2695 L Create a timeline for the current buffer.
2696 e Export views to associated files.
2697 s Search entries for keywords.
2698 S Search entries for keywords, only with TODO keywords.
2699 / Multi occur across all agenda files and also files listed
2700 in `org-agenda-text-search-extra-files'.
2701 < Restrict agenda commands to buffer, subtree, or region.
2702 Press several times to get the desired effect.
2703 > Remove a previous restriction.
2704 # List \"stuck\" projects.
2705 ! Configure what \"stuck\" means.
2706 C Configure custom agenda commands.
2708 More commands can be added by configuring the variable
2709 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2710 searches can be pre-defined in this way.
2712 If the current buffer is in Org-mode and visiting a file, you can also
2713 first press `<' once to indicate that the agenda should be temporarily
2714 \(until the next use of \\[org-agenda]) restricted to the current file.
2715 Pressing `<' twice means to restrict to the current subtree or region
2719 (let* ((prefix-descriptions nil)
2720 (org-agenda-buffer-name org-agenda-buffer-name)
2721 (org-agenda-window-setup (if (equal (buffer-name)
2722 org-agenda-buffer-name)
2724 org-agenda-window-setup))
2725 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2726 (org-agenda-custom-commands
2727 ;; normalize different versions
2731 (cond ((stringp (cdr x))
2732 (push x prefix-descriptions)
2734 ((stringp (nth 1 x)) x)
2735 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2736 (t (cons (car x) (cons "" (cdr x))))))
2737 org-agenda-custom-commands)))
2738 (org-agenda-custom-commands
2739 (org-contextualize-keys
2740 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2741 (buf (current-buffer))
2742 (bfn (buffer-file-name (buffer-base-buffer)))
2743 entry key type org-match lprops ans)
2744 ;; Turn off restriction unless there is an overriding one,
2745 (unless org-agenda-overriding-restriction
2746 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2747 ;; There is a request to keep the file list in place
2748 (put 'org-agenda-files 'org-restrict nil))
2749 (setq org-agenda-restrict nil)
2750 (move-marker org-agenda-restrict-begin nil)
2751 (move-marker org-agenda-restrict-end nil))
2752 ;; Delete old local properties
2753 (put 'org-agenda-redo-command 'org-lprops nil)
2754 ;; Delete previously set last-arguments
2755 (put 'org-agenda-redo-command 'last-args nil)
2756 ;; Remember where this call originated
2757 (setq org-agenda-last-dispatch-buffer (current-buffer))
2759 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2761 restriction (cdr ans)))
2762 ;; If we have sticky agenda buffers, set a name for the buffer,
2763 ;; depending on the invoking keys. The user may still set this
2764 ;; as a command option, which will overwrite what we do here.
2765 (if org-agenda-sticky
2766 (setq org-agenda-buffer-name
2767 (format "*Org Agenda(%s)*" org-keys)))
2768 ;; Establish the restriction, if any
2769 (when (and (not org-agenda-overriding-restriction) restriction)
2770 (put 'org-agenda-files 'org-restrict (list bfn))
2772 ((eq restriction 'region)
2773 (setq org-agenda-restrict (current-buffer))
2774 (move-marker org-agenda-restrict-begin (region-beginning))
2775 (move-marker org-agenda-restrict-end (region-end)))
2776 ((eq restriction 'subtree)
2778 (setq org-agenda-restrict (current-buffer))
2779 (org-back-to-heading t)
2780 (move-marker org-agenda-restrict-begin (point))
2781 (move-marker org-agenda-restrict-end
2782 (progn (org-end-of-subtree t)))))))
2784 ;; For example the todo list should not need it (but does...)
2786 ((setq entry (assoc org-keys org-agenda-custom-commands))
2787 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2789 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2790 lprops (nth 4 entry))
2791 (if org-agenda-sticky
2792 (setq org-agenda-buffer-name
2793 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2794 (format "*Org Agenda(%s)*" org-keys))))
2795 (put 'org-agenda-redo-command 'org-lprops lprops)
2798 (org-let lprops '(org-agenda-list current-prefix-arg)))
2800 (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
2802 (org-let lprops '(org-todo-list current-prefix-arg)))
2804 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2806 (org-let lprops '(org-agenda-list-stuck-projects
2807 current-prefix-arg)))
2809 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2810 ((eq type 'tags-todo)
2811 (org-let lprops '(org-tags-view '(4) org-match)))
2813 (org-let lprops '(org-todo-list org-match)))
2814 ((eq type 'tags-tree)
2815 (org-check-for-org-mode)
2816 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2817 ((eq type 'todo-tree)
2818 (org-check-for-org-mode)
2820 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2821 (regexp-quote org-match) "\\>"))))
2822 ((eq type 'occur-tree)
2823 (org-check-for-org-mode)
2824 (org-let lprops '(org-occur org-match)))
2826 (org-let lprops '(funcall type org-match)))
2828 (org-let lprops '(funcall type org-match)))
2829 (t (user-error "Invalid custom agenda command type %s" type))))
2830 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2831 ((equal org-keys "C")
2832 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2833 (customize-variable 'org-agenda-custom-commands))
2834 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2835 ((equal org-keys "s") (call-interactively 'org-search-view))
2836 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2837 ((equal org-keys "t") (call-interactively 'org-todo-list))
2838 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2839 ((equal org-keys "m") (call-interactively 'org-tags-view))
2840 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2841 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2842 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2846 (unless (current-message)
2847 (let* ((m (org-agenda-get-any-marker))
2848 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2851 "FLAGGING-NOTE ([?] for more info): "
2853 (replace-regexp-in-string
2855 (copy-sequence note))
2856 nil 'face 'org-warning)))))))
2858 ((equal org-keys "L")
2859 (unless (derived-mode-p 'org-mode)
2860 (user-error "This is not an Org-mode file"))
2862 (put 'org-agenda-files 'org-restrict (list bfn))
2863 (org-call-with-arg 'org-timeline arg)))
2864 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2865 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2866 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2867 (t (user-error "Invalid agenda key"))))))
2869 (defvar org-agenda-multi)
2871 (defun org-agenda-append-agenda ()
2872 "Append another agenda view to the current one.
2873 This function allows interactive building of block agendas.
2874 Agenda views are separated by `org-agenda-block-separator'."
2876 (unless (derived-mode-p 'org-agenda-mode)
2877 (user-error "Can only append from within agenda buffer"))
2878 (let ((org-agenda-multi t))
2881 (org-agenda-finalize)
2882 (setq buffer-read-only t)
2883 (org-agenda-fit-window-to-buffer)))
2885 (defun org-agenda-normalize-custom-commands (cmds)
2886 "Normalize custom commands CMDS."
2890 (cond ((stringp (cdr x)) nil)
2891 ((stringp (nth 1 x)) x)
2892 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2893 (t (cons (car x) (cons "" (cdr x))))))
2896 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2897 "The user interface for selecting an agenda command."
2899 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2900 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2901 (region-p (org-region-active-p))
2902 (custom org-agenda-custom-commands)
2904 restriction second-time
2905 c entry key type match prefixes rmheader header-end custom1 desc
2906 line lines left right n n1)
2907 (save-window-excursion
2908 (delete-other-windows)
2909 (org-switch-to-buffer-other-window " *Agenda Commands*")
2911 (insert (eval-when-compile
2913 "Press key for an agenda command: < Buffer, subtree/region restriction
2914 -------------------------------- > Remove restriction
2915 a Agenda for current week or day e Export agenda views
2916 t List of all TODO entries T Entries with special TODO kwd
2917 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2918 s Search for keywords S Like s, but only TODO entries
2919 L Timeline for current buffer # List stuck projects (!=configure)
2920 / Multi-occur C Configure custom agenda commands
2921 ? Find :FLAGGED: entries * Toggle sticky agenda views
2924 (while (string-match
2925 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2927 (setq start (match-end 0))
2928 (add-text-properties (match-beginning 2) (match-end 2)
2929 '(face bold) header))
2931 (setq header-end (point-marker))
2933 (setq custom1 custom)
2934 (when (eq rmheader t)
2936 (re-search-forward ":" nil t)
2937 (delete-region (match-end 0) (point-at-eol))
2940 (delete-region (match-end 0) (point-at-eol))
2941 (move-marker header-end (match-end 0)))
2942 (goto-char header-end)
2943 (delete-region (point) (point-max))
2945 ;; Produce all the lines that describe custom commands and prefixes
2947 (while (setq entry (pop custom1))
2948 (setq key (car entry) desc (nth 1 entry)
2950 match (nth 3 entry))
2951 (if (> (length key) 1)
2952 (add-to-list 'prefixes (string-to-char key))
2956 (org-add-props (copy-sequence key)
2959 ((string-match "\\S-" desc) desc)
2960 ((eq type 'agenda) "Agenda for current week or day")
2961 ((eq type 'agenda*) "Appointments for current week or day")
2962 ((eq type 'alltodo) "List of all TODO entries")
2963 ((eq type 'search) "Word search")
2964 ((eq type 'stuck) "List of stuck projects")
2965 ((eq type 'todo) "TODO keyword")
2966 ((eq type 'tags) "Tags query")
2967 ((eq type 'tags-todo) "Tags (TODO)")
2968 ((eq type 'tags-tree) "Tags tree")
2969 ((eq type 'todo-tree) "TODO kwd tree")
2970 ((eq type 'occur-tree) "Occur tree")
2971 ((functionp type) (if (symbolp type)
2973 "Lambda expression"))
2975 (if org-agenda-menu-show-matcher
2980 (setq match (copy-sequence match))
2981 (org-add-props match nil 'face 'org-warning))
2983 (format "set of %d commands" (length type))))))
2984 (if (org-string-nw-p match)
2985 (add-text-properties
2986 0 (length line) (list 'help-echo
2987 (concat "Matcher: " match)) line)))
2989 (setq lines (nreverse lines))
2994 (org-add-props (char-to-string x)
2996 (or (cdr (assoc (concat selstring
2998 prefix-descriptions))
3003 ;; Check if we should display in two columns
3004 (if org-agenda-menu-two-columns
3006 (setq n (length lines)
3007 n1 (+ (/ n 2) (mod n 2))
3008 right (nthcdr n1 lines)
3009 left (copy-sequence lines))
3010 (setcdr (nthcdr (1- n1) left) nil))
3011 (setq left lines right nil))
3013 (insert "\n" (pop left))
3015 (if (< (current-column) 40)
3016 (move-to-column 40 t)
3018 (insert (pop right))))
3020 ;; Make the window the right size
3021 (goto-char (point-min))
3023 (if (not (pos-visible-in-window-p (point-max)))
3024 (org-fit-window-to-buffer))
3025 (setq second-time t)
3026 (org-fit-window-to-buffer))
3028 ;; Ask for selection
3029 (message "Press key for agenda command%s:"
3030 (if (or restrict-ok org-agenda-overriding-restriction)
3031 (if org-agenda-overriding-restriction
3032 " (restriction lock active)"
3034 (format " (restricted to %s)" restriction)
3037 (setq c (read-char-exclusive))
3040 ((assoc (char-to-string c) custom)
3041 (setq selstring (concat selstring (char-to-string c)))
3042 (throw 'exit (cons selstring restriction)))
3044 (setq selstring (concat selstring (char-to-string c))
3046 rmheader (or rmheader t)
3047 custom (delq nil (mapcar
3049 (if (or (= (length (car x)) 1)
3050 (/= (string-to-char (car x)) c))
3052 (cons (substring (car x) 1) (cdr x))))
3055 (call-interactively 'org-toggle-sticky-agenda)
3057 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
3058 (message "Restriction is only possible in Org-mode buffers")
3061 (org-agenda-remove-restriction-lock 'noupdate)
3062 (setq restriction 'buffer))
3064 (org-agenda-remove-restriction-lock 'noupdate)
3065 (setq restriction (if region-p 'region 'subtree)))
3067 (org-agenda-remove-restriction-lock 'noupdate)
3070 ((eq restriction 'buffer)
3071 (if region-p 'region 'subtree))
3072 ((memq restriction '(subtree region))
3076 (org-agenda-remove-restriction-lock 'noupdate)
3077 (setq restriction nil))
3078 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
3079 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
3080 ((and (> (length selstring) 0) (eq c ?\d))
3082 (org-agenda-get-restriction-and-command prefix-descriptions))
3084 ((equal c ?q) (error "Abort"))
3085 (t (user-error "Invalid key %c" c))))))))
3087 (defun org-agenda-fit-window-to-buffer ()
3088 "Fit the window to the buffer size."
3089 (and (memq org-agenda-window-setup '(reorganize-frame))
3090 (fboundp 'fit-window-to-buffer)
3091 (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
3092 (= (car org-agenda-window-frame-fractions) 1.0))
3093 (delete-other-windows)
3094 (org-fit-window-to-buffer
3096 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3097 (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
3099 (defvar org-cmd nil)
3100 (defvar org-agenda-overriding-cmd nil)
3101 (defvar org-agenda-overriding-arguments nil)
3102 (defvar org-agenda-overriding-cmd-arguments nil)
3103 (defun org-agenda-run-series (name series)
3104 "Run agenda NAME as a SERIES of agenda commands."
3105 (org-let (nth 1 series) '(org-agenda-prepare name))
3106 ;; We need to reset agenda markers here, because when constructing a
3107 ;; block agenda, the individual blocks do not do that.
3108 (org-agenda-reset-markers)
3109 (let* ((org-agenda-multi t)
3110 (redo (list 'org-agenda-run-series name (list 'quote series)))
3112 (gprops (nth 1 series))
3113 match ;; The byte compiler incorrectly complains about this. Keep it!
3114 org-cmd type lprops)
3115 (while (setq org-cmd (pop cmds))
3116 (setq type (car org-cmd)
3117 match (eval (nth 1 org-cmd))
3118 lprops (nth 2 org-cmd))
3119 (let ((org-agenda-overriding-arguments
3120 (if (eq org-agenda-overriding-cmd org-cmd)
3121 (or org-agenda-overriding-arguments
3122 org-agenda-overriding-cmd-arguments))))
3125 (org-let2 gprops lprops
3126 '(call-interactively 'org-agenda-list)))
3128 (org-let2 gprops lprops
3129 '(funcall 'org-agenda-list nil nil t)))
3131 (org-let2 gprops lprops
3132 '(call-interactively 'org-todo-list)))
3134 (org-let2 gprops lprops
3135 '(org-search-view current-prefix-arg match nil)))
3137 (org-let2 gprops lprops
3138 '(call-interactively 'org-agenda-list-stuck-projects)))
3140 (org-let2 gprops lprops
3141 '(org-tags-view current-prefix-arg match)))
3142 ((eq type 'tags-todo)
3143 (org-let2 gprops lprops
3144 '(org-tags-view '(4) match)))
3146 (org-let2 gprops lprops
3147 '(org-todo-list match)))
3149 (org-let2 gprops lprops
3150 '(funcall type match)))
3151 (t (error "Invalid type in command series")))))
3153 (let ((inhibit-read-only t))
3154 (add-text-properties (point-min) (point-max)
3155 `(org-series t org-series-redo-cmd ,redo)))
3156 (setq org-agenda-redo-command redo)
3157 (goto-char (point-min)))
3158 (org-agenda-fit-window-to-buffer)
3159 (org-let (nth 1 series) '(org-agenda-finalize)))
3162 (defmacro org-batch-agenda (cmd-key &rest parameters)
3163 "Run an agenda command in batch mode and send the result to STDOUT.
3164 If CMD-KEY is a string of length 1, it is used as a key in
3165 `org-agenda-custom-commands' and triggers this command. If it is a
3166 longer string it is used as a tags/todo match string.
3167 Parameters are alternating variable names and values that will be bound
3168 before running the agenda command."
3169 (org-eval-in-environment (org-make-parameter-alist parameters)
3170 (let (org-agenda-sticky)
3171 (if (> (length cmd-key) 1)
3172 (org-tags-view nil cmd-key)
3173 (org-agenda nil cmd-key))))
3174 (set-buffer org-agenda-buffer-name)
3175 (princ (buffer-string)))
3177 (defvar org-agenda-info nil)
3180 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3181 "Run an agenda command in batch mode and send the result to STDOUT.
3182 If CMD-KEY is a string of length 1, it is used as a key in
3183 `org-agenda-custom-commands' and triggers this command. If it is a
3184 longer string it is used as a tags/todo match string.
3185 Parameters are alternating variable names and values that will be bound
3186 before running the agenda command.
3188 The output gives a line for each selected agenda item. Each
3189 item is a list of comma-separated values, like this:
3191 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3193 category The category of the item
3194 head The headline, without TODO kwd, TAGS and PRIORITY
3195 type The type of the agenda entry, can be
3196 todo selected in TODO match
3197 tagsmatch selected in tags match
3198 diary imported from diary
3199 deadline a deadline on given date
3200 scheduled scheduled on given date
3201 timestamp entry has timestamp on given date
3202 closed entry was closed on given date
3203 upcoming-deadline warning about deadline
3204 past-scheduled forwarded scheduled item
3205 block entry has date block including g. date
3206 todo The todo keyword, if any
3207 tags All tags including inherited ones, separated by colons
3208 date The relevant date, like 2007-2-14
3209 time The time, like 15:00-16:50
3210 extra Sting with extra planning info
3211 priority-l The priority letter if any was given
3212 priority-n The computed numerical priority
3213 agenda-day The day in the agenda where this is listed"
3214 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3215 (org-make-parameter-alist parameters))
3216 (if (> (length cmd-key) 2)
3217 (org-tags-view nil cmd-key)
3218 (org-agenda nil cmd-key)))
3219 (set-buffer org-agenda-buffer-name)
3220 (let* ((lines (org-split-string (buffer-string) "\n"))
3222 (while (setq line (pop lines))
3224 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3225 (setq org-agenda-info
3226 (org-fix-agenda-info (text-properties-at 0 line)))
3228 (mapconcat 'org-agenda-export-csv-mapper
3229 '(org-category txt type todo tags date time extra
3230 priority-letter priority agenda-day)
3234 (defun org-fix-agenda-info (props)
3235 "Make sure all properties on an agenda item have a canonical form.
3236 This ensures the export commands can easily use it."
3238 (when (setq tmp (plist-get props 'tags))
3239 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3240 (when (setq tmp (plist-get props 'date))
3241 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3242 (let ((calendar-date-display-form '(year "-" month "-" day)))
3243 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3245 (setq tmp (calendar-date-string tmp)))
3246 (setq props (plist-put props 'date tmp)))
3247 (when (setq tmp (plist-get props 'day))
3248 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3249 (let ((calendar-date-display-form '(year "-" month "-" day)))
3250 (setq tmp (calendar-date-string tmp)))
3251 (setq props (plist-put props 'day tmp))
3252 (setq props (plist-put props 'agenda-day tmp)))
3253 (when (setq tmp (plist-get props 'txt))
3254 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3255 (plist-put props 'priority-letter (match-string 1 tmp))
3256 (setq tmp (replace-match "" t t tmp)))
3257 (when (and (setq re (plist-get props 'org-todo-regexp))
3258 (setq re (concat "\\`\\.*" re " ?"))
3259 (string-match re tmp))
3260 (plist-put props 'todo (match-string 1 tmp))
3261 (setq tmp (replace-match "" t t tmp)))
3262 (plist-put props 'txt tmp)))
3265 (defun org-agenda-export-csv-mapper (prop)
3266 (let ((res (plist-get org-agenda-info prop)))
3271 (t (prin1-to-string res))))
3272 (while (string-match "," res)
3273 (setq res (replace-match ";" t t res)))
3277 (defun org-store-agenda-views (&rest parameters)
3278 "Store agenda views."
3280 (eval (list 'org-batch-store-agenda-views)))
3283 (defmacro org-batch-store-agenda-views (&rest parameters)
3284 "Run all custom agenda commands that have a file argument."
3285 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3287 (dir default-directory)
3288 (pars (org-make-parameter-alist parameters))
3289 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3290 (save-window-excursion
3292 (setq cmd (pop cmds)
3293 thiscmdkey (car cmd)
3294 thiscmdcmd (cdr cmd)
3295 match (nth 2 thiscmdcmd)
3296 bufname (if org-agenda-sticky
3297 (or (and (stringp match)
3298 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3299 (format "*Org Agenda(%s)*" thiscmdkey))
3300 org-agenda-buffer-name)
3301 cmd-or-set (nth 2 cmd)
3302 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3303 files (nth (if (listp cmd-or-set) 4 5) cmd))
3304 (if (stringp files) (setq files (list files)))
3306 (org-eval-in-environment (append org-agenda-exporter-settings
3308 (org-agenda nil thiscmdkey))
3309 (set-buffer bufname)
3311 (org-eval-in-environment (append org-agenda-exporter-settings
3313 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3314 (and (get-buffer bufname)
3315 (kill-buffer bufname)))))))
3317 (defvar org-agenda-current-span nil
3318 "The current span used in the agenda view.") ; local variable in the agenda buffer
3319 (defun org-agenda-mark-header-line (pos)
3320 "Mark the line at POS as an agenda structure header."
3323 (put-text-property (point-at-bol) (point-at-eol)
3324 'org-agenda-structural-header t)
3325 (when org-agenda-title-append
3326 (put-text-property (point-at-bol) (point-at-eol)
3327 'org-agenda-title-append org-agenda-title-append))))
3329 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3330 (defvar org-agenda-write-buffer-name "Agenda View")
3331 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3332 "Write the current buffer (an agenda view) as a file.
3334 Depending on the extension of the file name, plain text (.txt),
3335 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3336 If the extension is .ics, translate visible agenda into iCalendar
3337 format. If the extension is .org, collect all subtrees
3338 corresponding to the agenda entries and add them in an .org file.
3340 With prefix argument OPEN, open the new file immediately. If
3341 NOSETTINGS is given, do not scope the settings of
3342 `org-agenda-exporter-settings' into the export commands. This is
3343 used when the settings have already been scoped and we do not
3344 wish to overrule other, higher priority settings. If
3345 AGENDA-BUFFER-NAME is provided, use this as the buffer name for
3346 the agenda to write."
3347 (interactive "FWrite agenda to file: \nP")
3348 (if (or (not (file-writable-p file))
3349 (and (file-exists-p file)
3350 (if (org-called-interactively-p 'any)
3351 (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
3352 (user-error "Cannot write agenda to file %s" file))
3353 (org-let (if nosettings nil org-agenda-exporter-settings)
3355 (save-window-excursion
3356 (let ((bs (copy-sequence (buffer-string))) beg content)
3358 (rename-buffer org-agenda-write-buffer-name t)
3359 (set-buffer-modified-p nil)
3361 (org-agenda-remove-marked-text 'invisible 'org-filtered)
3362 (run-hooks 'org-agenda-before-write-hook)
3364 ((org-bound-and-true-p org-mobile-creating-agendas)
3365 (org-mobile-write-agenda-for-mobile file))
3366 ((string-match "\\.org\\'" file)
3367 (let (content p m message-log-max)
3368 (goto-char (point-min))
3369 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3371 (setq m (get-text-property (point) 'org-hd-marker))
3373 (push (save-excursion
3374 (set-buffer (marker-buffer m))
3376 (org-copy-subtree 1 nil t t)
3381 (dolist (s content) (org-paste-subtree 1 s))
3383 (kill-buffer (current-buffer))
3384 (message "Org file written to %s" file)))
3385 ((string-match "\\.html?\\'" file)
3387 (set-buffer (htmlize-buffer (current-buffer)))
3388 (when org-agenda-export-html-style
3389 ;; replace <style> section with org-agenda-export-html-style
3390 (goto-char (point-min))
3391 (kill-region (- (search-forward "<style") 6)
3392 (search-forward "</style>"))
3393 (insert org-agenda-export-html-style))
3395 (kill-buffer (current-buffer))
3396 (message "HTML written to %s" file))
3397 ((string-match "\\.ps\\'" file)
3399 (ps-print-buffer-with-faces file)
3400 (message "Postscript written to %s" file))
3401 ((string-match "\\.pdf\\'" file)
3403 (ps-print-buffer-with-faces
3404 (concat (file-name-sans-extension file) ".ps"))
3405 (call-process "ps2pdf" nil nil nil
3407 (concat (file-name-sans-extension file) ".ps"))
3408 (expand-file-name file))
3409 (delete-file (concat (file-name-sans-extension file) ".ps"))
3410 (message "PDF written to %s" file))
3411 ((string-match "\\.ics\\'" file)
3412 (require 'ox-icalendar)
3413 (org-icalendar-export-current-agenda (expand-file-name file)))
3415 (let ((bs (buffer-string)))
3420 (kill-buffer (current-buffer))
3421 (message "Plain text written to %s" file))))))))
3422 (set-buffer (or agenda-bufname
3423 (and (org-called-interactively-p 'any) (buffer-name))
3424 org-agenda-buffer-name)))
3425 (when open (org-open-file file)))
3427 (defun org-agenda-remove-marked-text (property &optional value)
3428 "Delete all text marked with VALUE of PROPERTY.
3429 VALUE defaults to t."
3431 (setq value (or value t))
3432 (while (setq beg (text-property-any (point-min) (point-max)
3435 beg (or (next-single-property-change beg property)
3438 (defun org-agenda-add-entry-text ()
3439 "Add entry text to agenda lines.
3440 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3441 entry text following headings shown in the agenda.
3442 Drawers will be excluded, also the line with scheduling/deadline info."
3443 (when (and (> org-agenda-add-entry-text-maxlines 0)
3444 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3446 (goto-char (point-min))
3448 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3449 (beginning-of-line 2)
3450 (setq txt (org-agenda-get-some-entry-text
3451 m org-agenda-add-entry-text-maxlines " > "))
3453 (if (string-match "\\S-" txt)
3455 (or (eobp) (forward-char 1))))))))
3457 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3459 "Extract entry text from MARKER, at most N-LINES lines.
3460 This will ignore drawers etc, just get the text.
3461 If INDENT is given, prefix every line with this string. If KEEP is
3462 given, it is a list of symbols, defining stuff that should not be
3463 removed from the entry content. Currently only `planning' is allowed here."
3464 (let (txt drawer-re kwd-time-re ind)
3466 (with-current-buffer (marker-buffer marker)
3467 (if (not (derived-mode-p 'org-mode))
3474 (setq txt (buffer-substring
3475 (min (1+ (point)) (point-max))
3476 (progn (outline-next-heading) (point)))
3477 drawer-re org-drawer-regexp
3478 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3482 (when org-agenda-add-entry-text-descriptive-links
3483 (goto-char (point-min))
3484 (while (org-activate-bracket-links (point-max))
3485 (add-text-properties (match-beginning 0) (match-end 0)
3487 (goto-char (point-min))
3488 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3489 (set-text-properties (match-beginning 0) (match-end 0)
3491 (goto-char (point-min))
3492 (while (re-search-forward drawer-re nil t)
3495 (progn (re-search-forward
3496 "^[ \t]*:END:.*\n?" nil 'move)
3498 (unless (member 'planning keep)
3499 (goto-char (point-min))
3500 (while (re-search-forward kwd-time-re nil t)
3501 (replace-match "")))
3502 (goto-char (point-min))
3503 (when org-agenda-entry-text-exclude-regexps
3504 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3505 (while (setq re (pop re-list))
3506 (goto-char (point-min))
3507 (while (re-search-forward re nil t)
3508 (replace-match "")))))
3509 (goto-char (point-max))
3510 (skip-chars-backward " \t\n")
3511 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3513 ;; find and remove min common indentation
3514 (goto-char (point-min))
3515 (untabify (point-min) (point-max))
3516 (setq ind (org-get-indentation))
3518 (unless (looking-at "[ \t]*$")
3519 (setq ind (min ind (org-get-indentation))))
3520 (beginning-of-line 2))
3521 (goto-char (point-min))
3523 (unless (looking-at "[ \t]*$")
3524 (move-to-column ind)
3525 (delete-region (point-at-bol) (point)))
3526 (beginning-of-line 2))
3528 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3530 (goto-char (point-min))
3532 (while (and (not (eobp)) (re-search-forward "^" nil t))
3533 (replace-match indent t t)))
3534 (goto-char (point-min))
3535 (while (looking-at "[ \t]*\n") (replace-match ""))
3536 (goto-char (point-max))
3537 (when (> (org-current-line)
3539 (org-goto-line (1+ n-lines))
3541 (setq txt (buffer-substring (point-min) (point)))))))))
3544 (defun org-check-for-org-mode ()
3545 "Make sure current buffer is in org-mode. Error if not."
3546 (or (derived-mode-p 'org-mode)
3547 (error "Cannot execute org-mode agenda command on buffer in %s"
3550 ;;; Agenda prepare and finalize
3552 (defvar org-agenda-multi nil) ; dynamically scoped
3553 (defvar org-agenda-pre-window-conf nil)
3554 (defvar org-agenda-columns-active nil)
3555 (defvar org-agenda-name nil)
3556 (defvar org-agenda-tag-filter nil)
3557 (defvar org-agenda-category-filter nil)
3558 (defvar org-agenda-regexp-filter nil)
3559 (defvar org-agenda-effort-filter nil)
3560 (defvar org-agenda-top-headline-filter nil)
3561 (defvar org-agenda-tag-filter-preset nil
3562 "A preset of the tags filter used for secondary agenda filtering.
3563 This must be a list of strings, each string must be a single tag preceded
3565 This variable should not be set directly, but agenda custom commands can
3566 bind it in the options section. The preset filter is a global property of
3567 the entire agenda view. In a block agenda, it will not work reliably to
3568 define a filter for one of the individual blocks. You need to set it in
3569 the global options and expect it to be applied to the entire view.")
3571 (defvar org-agenda-category-filter-preset nil
3572 "A preset of the category filter used for secondary agenda filtering.
3573 This must be a list of strings, each string must be a single category
3574 preceded by \"+\" or \"-\".
3575 This variable should not be set directly, but agenda custom commands can
3576 bind it in the options section. The preset filter is a global property of
3577 the entire agenda view. In a block agenda, it will not work reliably to
3578 define a filter for one of the individual blocks. You need to set it in
3579 the global options and expect it to be applied to the entire view.")
3581 (defvar org-agenda-regexp-filter-preset nil
3582 "A preset of the regexp filter used for secondary agenda filtering.
3583 This must be a list of strings, each string must be a single regexp
3584 preceded by \"+\" or \"-\".
3585 This variable should not be set directly, but agenda custom commands can
3586 bind it in the options section. The preset filter is a global property of
3587 the entire agenda view. In a block agenda, it will not work reliably to
3588 define a filter for one of the individual blocks. You need to set it in
3589 the global options and expect it to be applied to the entire view.")
3591 (defvar org-agenda-effort-filter-preset nil
3592 "A preset of the effort condition used for secondary agenda filtering.
3593 This must be a list of strings, each string must be a single regexp
3594 preceded by \"+\" or \"-\".
3595 This variable should not be set directly, but agenda custom commands can
3596 bind it in the options section. The preset filter is a global property of
3597 the entire agenda view. In a block agenda, it will not work reliably to
3598 define a filter for one of the individual blocks. You need to set it in
3599 the global options and expect it to be applied to the entire view.")
3601 (defun org-agenda-use-sticky-p ()
3602 "Return non-nil if an agenda buffer named
3603 `org-agenda-buffer-name' exists and should be shown instead of
3604 generating a new one."
3606 ;; turned off by user
3608 ;; For multi-agenda buffer already exists
3609 (not org-agenda-multi)
3611 (get-buffer org-agenda-buffer-name)
3612 ;; C-u parameter is same as last call
3613 (with-current-buffer (get-buffer org-agenda-buffer-name)
3615 (equal current-prefix-arg
3616 org-agenda-last-prefix-arg)
3617 ;; In case user turned stickiness on, while having existing
3618 ;; Agenda buffer active, don't reuse that buffer, because it
3619 ;; does not have org variables local
3620 org-agenda-this-buffer-is-sticky))))
3622 (defun org-agenda-prepare-window (abuf filter-alist)
3623 "Setup agenda buffer in the window.
3624 ABUF is the buffer for the agenda window.
3625 FILTER-ALIST is an alist of filters we need to apply when
3626 `org-agenda-persistent-filter' is non-nil."
3627 (let* ((awin (get-buffer-window abuf)) wconf)
3629 ((equal (current-buffer) abuf) nil)
3630 (awin (select-window awin))
3631 ((not (setq wconf (current-window-configuration))))
3632 ((equal org-agenda-window-setup 'current-window)
3633 (org-pop-to-buffer-same-window abuf))
3634 ((equal org-agenda-window-setup 'other-window)
3635 (org-switch-to-buffer-other-window abuf))
3636 ((equal org-agenda-window-setup 'other-frame)
3637 (switch-to-buffer-other-frame abuf))
3638 ((eq org-agenda-window-setup 'only-window)
3639 (delete-other-windows)
3640 (org-pop-to-buffer-same-window abuf))
3641 ((equal org-agenda-window-setup 'reorganize-frame)
3642 (delete-other-windows)
3643 (org-switch-to-buffer-other-window abuf)))
3644 (setq org-agenda-tag-filter (cdr (assoc 'tag filter-alist)))
3645 (setq org-agenda-category-filter (cdr (assoc 'cat filter-alist)))
3646 (setq org-agenda-effort-filter (cdr (assoc 'effort filter-alist)))
3647 (setq org-agenda-regexp-filter (cdr (assoc 're filter-alist)))
3648 ;; Additional test in case agenda is invoked from within agenda
3649 ;; buffer via elisp link.
3650 (unless (equal (current-buffer) abuf)
3651 (org-pop-to-buffer-same-window abuf))
3652 (setq org-agenda-pre-window-conf
3653 (or wconf org-agenda-pre-window-conf))))
3655 (defun org-agenda-prepare (&optional name)
3656 (let ((filter-alist (if org-agenda-persistent-filter
3657 (with-current-buffer
3658 (get-buffer-create org-agenda-buffer-name)
3659 (list `(tag . ,org-agenda-tag-filter)
3660 `(re . ,org-agenda-regexp-filter)
3661 `(effort . ,org-agenda-effort-filter)
3662 `(cat . ,org-agenda-category-filter))))))
3663 (if (org-agenda-use-sticky-p)
3665 (put 'org-agenda-tag-filter :preset-filter nil)
3666 (put 'org-agenda-category-filter :preset-filter nil)
3667 (put 'org-agenda-regexp-filter :preset-filter nil)
3668 ;; Popup existing buffer
3669 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
3671 (message "Sticky Agenda buffer, use `r' to refresh")
3672 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3673 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3674 (setq org-todo-keywords-for-agenda nil)
3675 (put 'org-agenda-tag-filter :preset-filter
3676 org-agenda-tag-filter-preset)
3677 (put 'org-agenda-category-filter :preset-filter
3678 org-agenda-category-filter-preset)
3679 (put 'org-agenda-regexp-filter :preset-filter
3680 org-agenda-regexp-filter-preset)
3681 (put 'org-agenda-effort-filter :preset-filter
3682 org-agenda-effort-filter-preset)
3683 (if org-agenda-multi
3685 (setq buffer-read-only nil)
3686 (goto-char (point-max))
3687 (unless (or (bobp) org-agenda-compact-blocks
3688 (not org-agenda-block-separator))
3690 (if (stringp org-agenda-block-separator)
3691 org-agenda-block-separator
3692 (make-string (window-width) org-agenda-block-separator))
3694 (narrow-to-region (point) (point-max)))
3695 (setq org-done-keywords-for-agenda nil)
3696 ;; Setting any org variables that are in org-agenda-local-vars
3697 ;; list need to be done after the prepare call
3698 (org-agenda-prepare-window
3699 (get-buffer-create org-agenda-buffer-name) filter-alist)
3700 (setq buffer-read-only nil)
3701 (org-agenda-reset-markers)
3702 (let ((inhibit-read-only t)) (erase-buffer))
3704 (setq org-agenda-buffer (current-buffer))
3705 (setq org-agenda-contributing-files nil)
3706 (setq org-agenda-columns-active nil)
3707 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3708 (setq org-todo-keywords-for-agenda
3709 (org-uniquify org-todo-keywords-for-agenda))
3710 (setq org-done-keywords-for-agenda
3711 (org-uniquify org-done-keywords-for-agenda))
3712 (setq org-agenda-last-prefix-arg current-prefix-arg)
3713 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3714 (and name (not org-agenda-name)
3715 (setq-local org-agenda-name name)))
3716 (setq buffer-read-only nil))))
3718 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3719 (defun org-agenda-finalize ()
3720 "Finishing touch for the agenda buffer, called just before displaying it."
3721 (unless org-agenda-multi
3723 (let ((inhibit-read-only t))
3724 (goto-char (point-min))
3726 (while (org-activate-bracket-links (point-max))
3727 (add-text-properties (match-beginning 0) (match-end 0)
3730 (while (org-activate-plain-links (point-max))
3731 (add-text-properties (match-beginning 0) (match-end 0)
3733 (unless (eq org-agenda-remove-tags t)
3734 (org-agenda-align-tags))
3735 (unless org-agenda-with-colors
3736 (remove-text-properties (point-min) (point-max) '(face nil)))
3737 (if (and (boundp 'org-agenda-overriding-columns-format)
3738 org-agenda-overriding-columns-format)
3739 (setq-local org-agenda-overriding-columns-format
3740 org-agenda-overriding-columns-format))
3741 (if (and (boundp 'org-agenda-view-columns-initially)
3742 org-agenda-view-columns-initially)
3743 (org-agenda-columns))
3744 (when org-agenda-fontify-priorities
3745 (org-agenda-fontify-priorities))
3746 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3747 (org-agenda-dim-blocked-tasks))
3748 (org-agenda-mark-clocking-task)
3749 (when org-agenda-entry-text-mode
3750 (org-agenda-entry-text-hide)
3751 (org-agenda-entry-text-show))
3752 (if (and (functionp 'org-habit-insert-consistency-graphs)
3753 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3754 (org-habit-insert-consistency-graphs))
3755 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3756 (unless (or (eq org-agenda-show-inherited-tags 'always)
3757 (and (listp org-agenda-show-inherited-tags)
3758 (memq org-agenda-type org-agenda-show-inherited-tags))
3759 (and (eq org-agenda-show-inherited-tags t)
3760 (or (eq org-agenda-use-tag-inheritance t)
3761 (and (listp org-agenda-use-tag-inheritance)
3762 (not (memq org-agenda-type
3763 org-agenda-use-tag-inheritance))))))
3766 (goto-char (point-min))
3767 (while (equal (forward-line) 0)
3768 (when (setq mrk (get-text-property (point) 'org-hd-marker))
3769 (put-text-property (point-at-bol) (point-at-eol)
3770 'tags (org-with-point-at mrk
3772 (mapcar 'downcase (org-get-tags-at))))))))))
3773 (run-hooks 'org-agenda-finalize-hook)
3774 (when org-agenda-top-headline-filter
3775 (org-agenda-filter-top-headline-apply
3776 org-agenda-top-headline-filter))
3777 (when org-agenda-tag-filter
3778 (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
3779 (when (get 'org-agenda-tag-filter :preset-filter)
3780 (org-agenda-filter-apply
3781 (get 'org-agenda-tag-filter :preset-filter) 'tag t))
3782 (when org-agenda-category-filter
3783 (org-agenda-filter-apply org-agenda-category-filter 'category))
3784 (when (get 'org-agenda-category-filter :preset-filter)
3785 (org-agenda-filter-apply
3786 (get 'org-agenda-category-filter :preset-filter) 'category))
3787 (when org-agenda-regexp-filter
3788 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
3789 (when (get 'org-agenda-regexp-filter :preset-filter)
3790 (org-agenda-filter-apply
3791 (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
3792 (when org-agenda-effort-filter
3793 (org-agenda-filter-apply org-agenda-effort-filter 'effort))
3794 (when (get 'org-agenda-effort-filter :preset-filter)
3795 (org-agenda-filter-apply
3796 (get 'org-agenda-effort-filter :preset-filter) 'effort))
3797 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3799 (defun org-agenda-mark-clocking-task ()
3800 "Mark the current clock entry in the agenda if it is present."
3801 ;; We need to widen when `org-agenda-finalize' is called from
3802 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3803 (when org-clock-current-task
3806 (org-agenda-unmark-clocking-task)
3807 (when (marker-buffer org-clock-hd-marker)
3809 (goto-char (point-min))
3811 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3813 (when (equal (org-get-at-bol 'org-hd-marker)
3814 org-clock-hd-marker)
3815 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3816 (overlay-put ov 'type 'org-agenda-clocking)
3817 (overlay-put ov 'face 'org-agenda-clocking)
3818 (overlay-put ov 'help-echo
3819 "The clock is running in this item")))))))))
3821 (defun org-agenda-unmark-clocking-task ()
3822 "Unmark the current clocking task."
3824 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3825 (delete-overlay o)))
3826 (overlays-in (point-min) (point-max))))
3828 (defun org-agenda-fontify-priorities ()
3829 "Make highest priority lines bold, and lowest italic."
3831 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3832 (delete-overlay o)))
3833 (overlays-in (point-min) (point-max)))
3836 (goto-char (point-min))
3837 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3838 (setq h (or (get-char-property (point) 'org-highest-priority)
3839 org-highest-priority)
3840 l (or (get-char-property (point) 'org-lowest-priority)
3841 org-lowest-priority)
3842 p (string-to-char (match-string 1))
3843 b (match-beginning 0)
3844 e (if (eq org-agenda-fontify-priorities 'cookies)
3847 ov (make-overlay b e))
3851 (cond ((org-face-from-face-or-color
3853 (cdr (assoc p org-priority-faces))))
3854 ((and (listp org-agenda-fontify-priorities)
3855 (org-face-from-face-or-color
3857 (cdr (assoc p org-agenda-fontify-priorities)))))
3858 ((equal p l) 'italic)
3859 ((equal p h) 'bold))))
3860 (if special-face (list special-face 'org-priority) 'org-priority)))
3861 (overlay-put ov 'org-type 'org-priority)))))
3863 (defvar org-depend-tag-blocked)
3865 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3866 "Dim currently blocked TODOs in the agenda display.
3867 When INVISIBLE is non-nil, hide currently blocked TODO instead of
3870 (when (org-called-interactively-p 'interactive)
3871 (message "Dim or hide blocked tasks..."))
3872 (dolist (o (overlays-in (point-min) (point-max)))
3873 (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
3874 (delete-overlay o)))
3876 (let ((inhibit-read-only t)
3877 (org-depend-tag-blocked nil)
3878 org-blocked-by-checkboxes)
3879 (goto-char (point-min))
3880 (while (let ((pos (text-property-not-all
3881 (point) (point-max) 'todo-state nil)))
3882 (when pos (goto-char pos)))
3883 (setq org-blocked-by-checkboxes nil)
3884 (let ((marker (org-get-at-bol 'org-hd-marker)))
3885 (when (and (markerp marker)
3886 (with-current-buffer (marker-buffer marker)
3887 (save-excursion (goto-char marker)
3888 (org-entry-blocked-p))))
3889 ;; Entries blocked by checkboxes cannot be made invisible.
3890 ;; See `org-agenda-dim-blocked-tasks' for details.
3891 (let* ((really-invisible
3892 (and (not org-blocked-by-checkboxes)
3893 (or invisible (eq org-agenda-dim-blocked-tasks
3895 (ov (make-overlay (if really-invisible (line-end-position 0)
3896 (line-beginning-position))
3897 (line-end-position))))
3898 (if really-invisible (overlay-put ov 'invisible t)
3899 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3900 (overlay-put ov 'org-type 'org-blocked-todo))))
3902 (when (org-called-interactively-p 'interactive)
3903 (message "Dim or hide blocked tasks...done")))
3905 (defvar org-agenda-skip-function nil
3906 "Function to be called at each match during agenda construction.
3907 If this function returns nil, the current match should not be skipped.
3908 Otherwise, the function must return a position from where the search
3909 should be continued.
3910 This may also be a Lisp form, it will be evaluated.
3911 Never set this variable using `setq' or so, because then it will apply
3912 to all future agenda commands. If you do want a global skipping condition,
3913 use the option `org-agenda-skip-function-global' instead.
3914 The correct usage for `org-agenda-skip-function' is to bind it with
3915 `let' to scope it dynamically into the agenda-constructing command.
3916 A good way to set it is through options in `org-agenda-custom-commands'.")
3918 (defun org-agenda-skip ()
3919 "Throw to `:skip' in places that should be skipped.
3920 Also moves point to the end of the skipped region, so that search can
3921 continue from there."
3922 (let ((p (point-at-bol)) to)
3924 (save-excursion (goto-char p) (looking-at comment-start-skip))
3925 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3926 (get-text-property p :org-archived)
3927 (org-end-of-subtree t))
3928 (and org-agenda-skip-comment-trees
3929 (get-text-property p :org-comment)
3930 (org-end-of-subtree t))
3931 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3932 (org-agenda-skip-eval org-agenda-skip-function)))
3934 (org-in-src-block-p t))
3937 (defun org-agenda-skip-eval (form)
3938 "If FORM is a function or a list, call (or eval) it and return the result.
3939 `save-excursion' and `save-match-data' are wrapped around the call, so point
3940 and match data are returned to the previous state no matter what these
3944 (or (setq fp (functionp form))
3952 (defvar org-agenda-markers nil
3953 "List of all currently active markers created by `org-agenda'.")
3954 (defvar org-agenda-last-marker-time (org-float-time)
3955 "Creation time of the last agenda marker.")
3957 (defun org-agenda-new-marker (&optional pos)
3958 "Return a new agenda marker.
3959 Maker is at point, or at POS if non-nil. Org mode keeps a list of
3960 these markers and resets them when they are no longer in use."
3961 (let ((m (copy-marker (or pos (point)) t)))
3962 (setq org-agenda-last-marker-time (org-float-time))
3963 (if org-agenda-buffer
3964 (with-current-buffer org-agenda-buffer
3965 (push m org-agenda-markers))
3966 (push m org-agenda-markers))
3969 (defun org-agenda-reset-markers ()
3970 "Reset markers created by `org-agenda'."
3971 (while org-agenda-markers
3972 (move-marker (pop org-agenda-markers) nil)))
3974 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3975 "Save relative positions of markers in region.
3976 This check for agenda markers in all agenda buffers currently active."
3977 (dolist (buf (buffer-list))
3978 (with-current-buffer buf
3979 (when (eq major-mode 'org-agenda-mode)
3980 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3981 org-agenda-markers)))))
3985 (defun org-agenda-entry-text-show-here ()
3986 "Add some text from the entry as context to the current line."
3988 (setq m (org-get-at-bol 'org-hd-marker))
3989 (unless (marker-buffer m)
3990 (error "No marker points to an entry here"))
3991 (setq txt (concat "\n" (org-no-properties
3992 (org-agenda-get-some-entry-text
3993 m org-agenda-entry-text-maxlines
3994 org-agenda-entry-text-leaders))))
3995 (when (string-match "\\S-" txt)
3996 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3997 (overlay-put o 'evaporate t)
3998 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3999 (overlay-put o 'after-string txt))))
4001 (defun org-agenda-entry-text-show ()
4002 "Add entry context for all agenda lines."
4005 (goto-char (point-max))
4006 (beginning-of-line 1)
4008 (when (org-get-at-bol 'org-hd-marker)
4009 (org-agenda-entry-text-show-here))
4010 (beginning-of-line 0))))
4012 (defun org-agenda-entry-text-hide ()
4013 "Remove any shown entry context."
4016 (if (eq (overlay-get o 'org-overlay-type)
4017 'agenda-entry-content)
4018 (progn (delete-overlay o) t)))
4019 (overlays-in (point-min) (point-max)))))
4021 (defun org-agenda-get-day-face (date)
4022 "Return the face DATE should be displayed with."
4023 (cond ((and (functionp org-agenda-day-face-function)
4024 (funcall org-agenda-day-face-function date)))
4025 ((org-agenda-today-p date) 'org-agenda-date-today)
4026 ((memq (calendar-day-of-week date) org-agenda-weekend-days)
4027 'org-agenda-date-weekend)
4028 (t 'org-agenda-date)))
4032 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
4033 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
4035 (defun org-timeline (&optional dotodo)
4036 "Show a time-sorted view of the entries in the current org file.
4037 Only entries with a time stamp of today or later will be listed. With
4038 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
4039 under the current date.
4040 If the buffer contains an active region, only check the region for
4044 (org-agenda-show-log-scoped org-agenda-show-log)
4045 (org-agenda-show-log org-agenda-show-log-scoped)
4046 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
4048 (date (calendar-current-date))
4049 (beg (if (org-region-active-p) (region-beginning) (point-min)))
4050 (end (if (org-region-active-p) (region-end) (point-max)))
4051 (day-numbers (org-get-all-dates
4053 t org-agenda-show-log-scoped ; always include today
4054 org-timeline-show-empty-dates))
4055 (org-deadline-warning-days 0)
4056 (org-agenda-only-exact-dates t)
4061 (setq org-agenda-redo-command
4063 (list (list 'org-agenda-show-log 'org-agenda-show-log))
4064 (list 'org-switch-to-buffer-other-window (current-buffer))
4065 (list 'org-timeline (list 'quote dotodo))))
4066 (put 'org-agenda-redo-command 'org-lprops nil)
4068 ;; Remove past dates from the list of dates.
4069 (setq day-numbers (delq nil (mapcar (lambda(x)
4070 (if (>= x today) x nil))
4072 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
4073 (org-compile-prefix-format 'timeline)
4074 (org-set-sorting-strategy 'timeline)
4075 (if org-agenda-show-log-scoped (push :closed args))
4076 (push :timestamp args)
4077 (push :deadline args)
4078 (push :scheduled args)
4080 (if dotodo (push :todo args))
4081 (insert "Timeline of file " entry "\n")
4082 (add-text-properties (point-min) (point)
4083 (list 'face 'org-agenda-structure))
4084 (org-agenda-mark-header-line (point-min))
4085 (while (setq d (pop day-numbers))
4086 (if (and (listp d) (eq (car d) :omitted))
4089 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
4090 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
4091 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
4092 (if (and (>= d today)
4097 (insert (make-string 79 ?-) "\n")))
4098 (setq date (calendar-gregorian-from-absolute d))
4100 (setq rtn (and (not emptyp)
4101 (apply 'org-agenda-get-day-entries entry
4103 (if (or rtn (equal d today) org-timeline-show-empty-dates)
4106 (if (stringp org-agenda-format-date)
4107 (format-time-string org-agenda-format-date
4108 (org-time-from-absolute date))
4109 (funcall org-agenda-format-date date))
4111 (put-text-property s (1- (point)) 'face
4112 (org-agenda-get-day-face date))
4113 (put-text-property s (1- (point)) 'org-date-line t)
4114 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4116 (put-text-property s (1- (point)) 'org-today t))
4117 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
4118 (put-text-property s (1- (point)) 'day d)))))
4119 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
4121 (add-text-properties
4122 (point-min) (point-max)
4123 `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
4124 (org-agenda-finalize)
4125 (setq buffer-read-only t)))
4127 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
4128 "Return a list of all relevant day numbers from BEG to END buffer positions.
4129 If NO-RANGES is non-nil, include only the start and end dates of a range,
4130 not every single day in the range. If FORCE-TODAY is non-nil, make
4131 sure that TODAY is included in the list. If INACTIVE is non-nil, also
4132 inactive time stamps (those in square brackets) are included.
4133 When EMPTY is non-nil, also include days without any entries."
4135 (if pre-re pre-re "")
4136 (if inactive org-ts-regexp-both org-ts-regexp)))
4137 dates dates1 date day day1 day2 ts1 ts2 pos)
4139 (setq dates (list (org-today))))
4142 (while (re-search-forward re end t)
4143 (setq day (time-to-days (org-time-string-to-time
4144 (substring (match-string 1) 0 10)
4145 (current-buffer) (match-beginning 0))))
4146 (or (memq day dates) (push day dates)))
4149 (while (re-search-forward org-tr-regexp end t)
4150 (setq pos (match-beginning 0))
4151 (setq ts1 (substring (match-string 1) 0 10)
4152 ts2 (substring (match-string 2) 0 10)
4153 day1 (time-to-days (org-time-string-to-time
4154 ts1 (current-buffer) pos))
4155 day2 (time-to-days (org-time-string-to-time
4156 ts2 (current-buffer) pos)))
4157 (while (< (setq day1 (1+ day1)) day2)
4158 (or (memq day1 dates) (push day1 dates)))))
4159 (setq dates (sort dates '<))
4161 (while (setq day (pop dates))
4162 (setq day2 (car dates))
4164 (when (and day2 empty)
4165 (if (or (eq empty t)
4166 (and (numberp empty) (<= (- day2 day) empty)))
4167 (while (< (setq day (1+ day)) day2)
4168 (push (list day) dates1))
4169 (push (cons :omitted (- day2 day)) dates1))))
4170 (setq dates (nreverse dates1)))
4173 ;;; Agenda Daily/Weekly
4175 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4176 "Start day for the agenda view.
4177 Custom commands can set this variable in the options section.
4178 This is usually a string like \"2007-11-01\", \"+2d\" or any other
4179 input allowed when reading a date through the Org calendar.
4180 See the docstring of `org-read-date' for details.")
4181 (defvar org-starting-day nil) ; local variable in the agenda buffer
4182 (defvar org-arg-loc nil) ; local variable
4184 (defvar org-agenda-buffer-tmp-name nil)
4186 (defun org-agenda-list (&optional arg start-day span with-hour)
4187 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4188 The view will be for the current day or week, but from the overview buffer
4189 you will be able to go to other days/weeks.
4191 With a numeric prefix argument in an interactive call, the agenda will
4192 span ARG days. Lisp programs should instead specify SPAN to change
4193 the number of days. SPAN defaults to `org-agenda-span'.
4195 START-DAY defaults to TODAY, or to the most recent match for the weekday
4196 given in `org-agenda-start-on-weekday'.
4198 When WITH-HOUR is non-nil, only include scheduled and deadline
4199 items if they have an hour specification like [h]h:mm."
4201 (if org-agenda-overriding-arguments
4202 (setq arg (car org-agenda-overriding-arguments)
4203 start-day (nth 1 org-agenda-overriding-arguments)
4204 span (nth 2 org-agenda-overriding-arguments)))
4205 (if (and (integerp arg) (> arg 0))
4206 (setq span arg arg nil))
4208 (setq org-agenda-buffer-name
4209 (or org-agenda-buffer-tmp-name
4210 (if org-agenda-sticky
4211 (cond ((and org-keys (stringp org-match))
4212 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4214 (format "*Org Agenda(%s)*" org-keys))
4215 (t "*Org Agenda(a)*")))
4216 org-agenda-buffer-name))
4217 (org-agenda-prepare "Day/Week")
4218 (setq start-day (or start-day org-agenda-start-day))
4219 (if (stringp start-day)
4220 ;; Convert to an absolute day number
4221 (setq start-day (time-to-days (org-read-date nil t start-day))))
4222 (org-compile-prefix-format 'agenda)
4223 (org-set-sorting-strategy 'agenda)
4224 (let* ((span (org-agenda-ndays-to-span
4225 (or span org-agenda-ndays org-agenda-span)))
4227 (sd (or start-day today))
4228 (ndays (org-agenda-span-to-ndays span sd))
4229 (org-agenda-start-on-weekday
4230 (if (or (eq ndays 7) (eq ndays 14))
4231 org-agenda-start-on-weekday))
4232 (thefiles (org-agenda-files nil 'ifmode))
4234 (start (if (or (null org-agenda-start-on-weekday)
4237 (let* ((nt (calendar-day-of-week
4238 (calendar-gregorian-from-absolute sd)))
4239 (n1 org-agenda-start-on-weekday)
4241 (- sd (+ (if (< d 0) 7 0) d)))))
4242 (day-numbers (list start))
4244 (inhibit-redisplay (not debug-on-error))
4245 (org-agenda-show-log-scoped org-agenda-show-log)
4246 s e rtn rtnall file date d start-pos end-pos todayp
4247 clocktable-start clocktable-end filter)
4248 (setq org-agenda-redo-command
4249 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
4250 (dotimes (n (1- ndays))
4251 (push (1+ (car day-numbers)) day-numbers))
4252 (setq day-numbers (nreverse day-numbers))
4253 (setq clocktable-start (car day-numbers)
4254 clocktable-end (1+ (or (org-last day-numbers) 0)))
4255 (setq-local org-starting-day (car day-numbers))
4256 (setq-local org-arg-loc arg)
4257 (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
4258 (unless org-agenda-compact-blocks
4259 (let* ((d1 (car day-numbers))
4260 (d2 (org-last day-numbers))
4261 (w1 (org-days-to-iso-week d1))
4262 (w2 (org-days-to-iso-week d2)))
4264 (if org-agenda-overriding-header
4265 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4266 nil 'face 'org-agenda-structure) "\n")
4267 (insert (org-agenda-span-name span)
4269 (if (< (- d2 d1) 350)
4271 (format " (W%02d)" w1)
4272 (format " (W%02d-W%02d)" w1 w2))
4275 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4277 (org-agenda-mark-header-line s))
4278 (while (setq d (pop day-numbers))
4279 (setq date (calendar-gregorian-from-absolute d)
4281 (if (or (setq todayp (= d today))
4282 (and (not start-pos) (= d sd)))
4283 (setq start-pos (point))
4284 (if (and start-pos (not end-pos))
4285 (setq end-pos (point))))
4286 (setq files thefiles
4288 (while (setq file (pop files))
4290 (org-check-agenda-file file)
4291 (let ((org-agenda-entry-types org-agenda-entry-types))
4292 ;; Starred types override non-starred equivalents
4293 (when (member :deadline* org-agenda-entry-types)
4294 (setq org-agenda-entry-types
4295 (delq :deadline org-agenda-entry-types)))
4296 (when (member :scheduled* org-agenda-entry-types)
4297 (setq org-agenda-entry-types
4298 (delq :scheduled org-agenda-entry-types)))
4301 (when (member :deadline org-agenda-entry-types)
4302 (setq org-agenda-entry-types
4303 (delq :deadline org-agenda-entry-types))
4304 (push :deadline* org-agenda-entry-types))
4305 (when (member :scheduled org-agenda-entry-types)
4306 (setq org-agenda-entry-types
4307 (delq :scheduled org-agenda-entry-types))
4308 (push :scheduled* org-agenda-entry-types)))
4309 (unless org-agenda-include-deadlines
4310 (setq org-agenda-entry-types
4311 (delq :deadline* (delq :deadline org-agenda-entry-types))))
4313 ((memq org-agenda-show-log-scoped '(only clockcheck))
4314 (setq rtn (org-agenda-get-day-entries
4315 file date :closed)))
4316 (org-agenda-show-log-scoped
4317 (setq rtn (apply 'org-agenda-get-day-entries
4319 (append '(:closed) org-agenda-entry-types))))
4321 (setq rtn (apply 'org-agenda-get-day-entries
4323 org-agenda-entry-types)))))
4324 (setq rtnall (append rtnall rtn)))) ;; all entries
4325 (if org-agenda-include-diary
4326 (let ((org-agenda-search-headline-for-time t))
4327 (require 'diary-lib)
4328 (setq rtn (org-get-entries-from-diary date))
4329 (setq rtnall (append rtnall rtn))))
4330 (if (or rtnall org-agenda-show-all-dates)
4332 (setq day-cnt (1+ day-cnt))
4334 (if (stringp org-agenda-format-date)
4335 (format-time-string org-agenda-format-date
4336 (org-time-from-absolute date))
4337 (funcall org-agenda-format-date date))
4339 (put-text-property s (1- (point)) 'face
4340 (org-agenda-get-day-face date))
4341 (put-text-property s (1- (point)) 'org-date-line t)
4342 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4343 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4345 (put-text-property s (1- (point)) 'org-today t))
4347 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4348 (if rtnall (insert ;; all entries
4349 (org-agenda-finalize-entries rtnall 'agenda)
4351 (put-text-property s (1- (point)) 'day d)
4352 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4353 (when (and org-agenda-clockreport-mode clocktable-start)
4354 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4355 ;; the above line is to ensure the restricted range!
4356 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4358 (setq p (org-plist-delete p :block))
4359 (setq p (plist-put p :tstart clocktable-start))
4360 (setq p (plist-put p :tend clocktable-end))
4361 (setq p (plist-put p :scope 'agenda))
4362 (setq tbl (apply 'org-clock-get-clocktable p))
4364 (goto-char (point-min))
4365 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4366 (unless (and (pos-visible-in-window-p (point-min))
4367 (pos-visible-in-window-p (point-max)))
4368 (goto-char (1- (point-max)))
4370 (if (not (pos-visible-in-window-p (or start-pos 1)))
4372 (goto-char (or start-pos 1))
4374 (goto-char (or start-pos 1))
4375 (add-text-properties (point-min) (point-max)
4376 `(org-agenda-type agenda
4377 org-last-args (,arg ,start-day ,span)
4378 org-redo-cmd ,org-agenda-redo-command
4379 org-series-cmd ,org-cmd))
4380 (if (eq org-agenda-show-log-scoped 'clockcheck)
4381 (org-agenda-show-clocking-issues))
4382 (org-agenda-finalize)
4383 (setq buffer-read-only t)
4386 (defun org-agenda-ndays-to-span (n)
4387 "Return a span symbol for a span of N days, or N if none matches."
4388 (cond ((symbolp n) n)
4391 ((= n 14) 'fortnight)
4394 (defun org-agenda-span-to-ndays (span &optional start-day)
4395 "Return ndays from SPAN, possibly starting at START-DAY.
4396 START-DAY is an absolute time value."
4397 (cond ((numberp span) span)
4400 ((eq span 'fortnight) 14)
4402 (let ((date (calendar-gregorian-from-absolute start-day)))
4403 (calendar-last-day-of-month (car date) (caddr date))))
4405 (let ((date (calendar-gregorian-from-absolute start-day)))
4406 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4408 (defun org-agenda-span-name (span)
4409 "Return a SPAN name."
4413 (capitalize (symbol-name span))
4414 (format "%d days" span))))
4416 ;;; Agenda word search
4418 (defvar org-agenda-search-history nil)
4420 (defvar org-search-syntax-table nil
4421 "Special syntax table for org-mode search.
4422 In this table, we have single quotes not as word constituents, to
4423 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4425 (defvar org-mode-syntax-table) ; From org.el
4426 (defun org-search-syntax-table ()
4427 (unless org-search-syntax-table
4428 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4429 (modify-syntax-entry ?' "." org-search-syntax-table)
4430 (modify-syntax-entry ?` "." org-search-syntax-table))
4431 org-search-syntax-table)
4433 (defvar org-agenda-last-search-view-search-was-boolean nil)
4436 (defun org-search-view (&optional todo-only string edit-at)
4437 "Show all entries that contain a phrase or words or regular expressions.
4439 With optional prefix argument TODO-ONLY, only consider entries that are
4440 TODO entries. The argument STRING can be used to pass a default search
4441 string into this function. If EDIT-AT is non-nil, it means that the
4442 user should get a chance to edit this string, with cursor at position
4445 The search string can be viewed either as a phrase that should be found as
4446 is, or it can be broken into a number of snippets, each of which must match
4447 in a Boolean way to select an entry. The default depends on the variable
4448 `org-agenda-search-view-always-boolean'.
4449 Even if this is turned off (the default) you can always switch to
4450 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4452 The default is a direct search of the whole phrase, where each space in
4453 the search string can expand to an arbitrary amount of whitespace,
4456 If using a Boolean search, the search string is split on whitespace and
4457 each snippet is searched separately, with logical AND to select an entry.
4458 Words prefixed with a minus must *not* occur in the entry. Words without
4459 a prefix or prefixed with a plus must occur in the entry. Matching is
4460 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4461 match whole words, not parts of a word) if
4462 `org-agenda-search-view-force-full-words' is set (default is nil).
4464 Boolean search snippets enclosed by curly braces are interpreted as
4465 regular expressions that must or (when preceded with \"-\") must not
4466 match in the entry. Snippets enclosed into double quotes will be taken
4467 as a whole, to include whitespace.
4469 - If the search string starts with an asterisk, search only in headlines.
4470 - If (possibly after the leading star) the search string starts with an
4471 exclamation mark, this also means to look at TODO entries only, an effect
4472 that can also be achieved with a prefix argument.
4473 - If (possibly after star and exclamation mark) the search string starts
4474 with a colon, this will mean that the (non-regexp) snippets of the
4475 Boolean search must match as full words.
4477 This command searches the agenda files, and in addition the files listed
4478 in `org-agenda-text-search-extra-files'."
4480 (if org-agenda-overriding-arguments
4481 (setq todo-only (car org-agenda-overriding-arguments)
4482 string (nth 1 org-agenda-overriding-arguments)
4483 edit-at (nth 2 org-agenda-overriding-arguments)))
4484 (let* ((props (list 'face nil
4485 'done-face 'org-agenda-done
4486 'org-not-done-regexp org-not-done-regexp
4487 'org-todo-regexp org-todo-regexp
4488 'org-complex-heading-regexp org-complex-heading-regexp
4489 'mouse-face 'highlight
4490 'help-echo (format "mouse-2 or RET jump to location")))
4491 (full-words org-agenda-search-view-force-full-words)
4492 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4493 regexp rtn rtnall files file pos inherited-tags
4494 marker category level tags c neg re boolean
4495 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4496 (unless (and (not edit-at)
4498 (string-match "\\S-" string))
4499 (setq string (read-string
4500 (if org-agenda-search-view-always-boolean
4501 "[+-]Word/{Regexp} ...: "
4502 "Phrase or [+-]Word/{Regexp} ...: ")
4504 ((integerp edit-at) (cons string edit-at))
4506 'org-agenda-search-history)))
4508 (if org-agenda-sticky
4509 (setq org-agenda-buffer-name
4510 (if (stringp string)
4511 (format "*Org Agenda(%s:%s)*"
4512 (or org-keys (or (and todo-only "S") "s")) string)
4513 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4514 (org-agenda-prepare "SEARCH")
4515 (org-compile-prefix-format 'search)
4516 (org-set-sorting-strategy 'search)
4517 (setq org-agenda-redo-command
4518 (list 'org-search-view (if todo-only t nil)
4519 (list 'if 'current-prefix-arg nil string)))
4520 (setq org-agenda-query-string string)
4521 (if (equal (string-to-char string) ?*)
4523 words (substring string 1))
4524 (setq words string))
4525 (when (equal (string-to-char words) ?!)
4527 words (substring words 1)))
4528 (when (equal (string-to-char words) ?:)
4530 words (substring words 1)))
4531 (if (or org-agenda-search-view-always-boolean
4532 (member (string-to-char words) '(?- ?+ ?\{)))
4534 (setq words (org-split-string words))
4536 (while (setq w (pop words))
4537 (while (and (string-match "\\\\\\'" w) words)
4538 (setq w (concat (substring w 0 -1) " " (pop words))))
4540 (setq words (nreverse www) www nil)
4541 (while (setq w (pop words))
4542 (when (and (string-match "\\`[-+]?{" w)
4543 (not (string-match "}\\'" w)))
4544 (while (and words (not (string-match "}\\'" (car words))))
4545 (setq w (concat w " " (pop words))))
4546 (setq w (concat w " " (pop words))))
4548 (setq words (nreverse www)))
4549 (setq org-agenda-last-search-view-search-was-boolean boolean)
4552 (while (setq w (pop words))
4553 (if (or (equal (substring w 0 1) "\"")
4554 (and (> (length w) 1)
4555 (member (substring w 0 1) '("+" "-"))
4556 (equal (substring w 1 2) "\"")))
4557 (while (and words (not (equal (substring w -1) "\"")))
4558 (setq w (concat w " " (pop words)))))
4559 (and (string-match "\\`\\([-+]?\\)\"" w)
4560 (setq w (replace-match "\\1" nil nil w)))
4561 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4563 (setq words (nreverse wds))))
4566 (setq c (string-to-char w))
4568 (setq neg t w (substring w 1))
4570 (setq neg nil w (substring w 1))
4572 (if (string-match "\\`{.*}\\'" w)
4573 (setq re (substring w 1 -1))
4575 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4576 (setq re (regexp-quote (downcase w)))))
4577 (if neg (push re regexps-) (push re regexps+)))
4579 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4581 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4583 (setq regexp org-outline-regexp-bol)
4584 (setq regexp (pop regexps+))
4585 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4587 (setq files (org-agenda-files nil 'ifmode))
4588 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4589 (pop org-agenda-text-search-extra-files)
4590 (setq files (org-add-archive-files files)))
4591 (setq files (append files org-agenda-text-search-extra-files)
4593 (while (setq file (pop files))
4596 (org-check-agenda-file file)
4597 (setq buffer (if (file-exists-p file)
4598 (org-get-agenda-file-buffer file)
4599 (error "No such file %s" file)))
4601 ;; If file does not exist, make sure an error message is sent
4602 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4604 (with-current-buffer buffer
4605 (with-syntax-table (org-search-syntax-table)
4606 (unless (derived-mode-p 'org-mode)
4607 (error "Agenda file %s is not in `org-mode'" file))
4608 (let ((case-fold-search t))
4611 (if (eq buffer org-agenda-restrict)
4612 (narrow-to-region org-agenda-restrict-begin
4613 org-agenda-restrict-end)
4615 (goto-char (point-min))
4616 (unless (or (org-at-heading-p)
4617 (outline-next-heading))
4618 (throw 'nextfile t))
4619 (goto-char (max (point-min) (1- (point))))
4620 (while (re-search-forward regexp nil t)
4621 (org-back-to-heading t)
4622 (while (and (not (zerop org-agenda-search-view-max-outline-level))
4623 (> (org-reduced-level (org-outline-level))
4624 org-agenda-search-view-max-outline-level)
4626 (org-back-to-heading t)))
4627 (skip-chars-forward "* ")
4628 (setq beg (point-at-bol)
4631 (outline-next-heading)
4632 (while (and (not (zerop org-agenda-search-view-max-outline-level))
4633 (> (org-reduced-level (org-outline-level))
4634 org-agenda-search-view-max-outline-level)
4636 (outline-next-heading)))
4642 (setq str (buffer-substring-no-properties
4644 (if hdl-only (point-at-eol) end)))
4645 (mapc (lambda (wr) (when (string-match wr str)
4646 (goto-char (1- end))
4649 (mapc (lambda (wr) (unless (string-match wr str)
4650 (goto-char (1- end))
4653 (cons (concat "^\\*+[ \t]+"
4654 org-not-done-regexp)
4658 (setq marker (org-agenda-new-marker (point))
4659 category (org-get-category)
4660 level (make-string (org-reduced-level (org-outline-level)) ? )
4662 (or (eq org-agenda-show-inherited-tags 'always)
4663 (and (listp org-agenda-show-inherited-tags)
4664 (memq 'todo org-agenda-show-inherited-tags))
4665 (and (eq org-agenda-show-inherited-tags t)
4666 (or (eq org-agenda-use-tag-inheritance t)
4667 (memq 'todo org-agenda-use-tag-inheritance))))
4668 tags (org-get-tags-at nil (not inherited-tags))
4669 txt (org-agenda-format-item
4671 (buffer-substring-no-properties
4672 beg1 (point-at-eol))
4673 level category tags t))
4674 (org-add-props txt props
4675 'org-marker marker 'org-hd-marker marker
4676 'org-todo-regexp org-todo-regexp
4678 'org-complex-heading-regexp org-complex-heading-regexp
4682 (goto-char (1- end))))))))))
4683 (setq rtn (nreverse ee))
4684 (setq rtnall (append rtnall rtn)))
4685 (if org-agenda-overriding-header
4686 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4687 nil 'face 'org-agenda-structure) "\n")
4688 (insert "Search words: ")
4689 (add-text-properties (point-min) (1- (point))
4690 (list 'face 'org-agenda-structure))
4692 (insert string "\n")
4693 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4695 (unless org-agenda-multi
4696 (insert (substitute-command-keys "\
4697 Press `\\[org-agenda-manipulate-query-add]', \
4698 `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
4699 `\\[org-agenda-manipulate-query-add-re]', \
4700 `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
4701 `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
4702 (add-text-properties pos (1- (point))
4703 (list 'face 'org-agenda-structure))))
4704 (org-agenda-mark-header-line (point-min))
4706 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4707 (goto-char (point-min))
4708 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4709 (add-text-properties (point-min) (point-max)
4710 `(org-agenda-type search
4711 org-last-args (,todo-only ,string ,edit-at)
4712 org-redo-cmd ,org-agenda-redo-command
4713 org-series-cmd ,org-cmd))
4714 (org-agenda-finalize)
4715 (setq buffer-read-only t))))
4717 ;;; Agenda TODO list
4719 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4720 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4722 (if (or (equal keywords "ALL") (not keywords))
4723 (propertize "ALL" 'face 'warning)
4726 (propertize kw 'face (org-get-todo-face kw)))
4727 (org-split-string keywords "|")
4731 (defvar org-select-this-todo-keyword nil)
4732 (defvar org-last-arg nil)
4735 (defun org-todo-list (&optional arg)
4736 "Show all (not done) TODO entries from all agenda file in a single list.
4737 The prefix arg can be used to select a specific TODO keyword and limit
4738 the list to these. When using \\[universal-argument], you will be prompted
4739 for a keyword. A numeric prefix directly selects the Nth keyword in
4740 `org-todo-keywords-1'."
4742 (if org-agenda-overriding-arguments
4743 (setq arg org-agenda-overriding-arguments))
4744 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4745 (let* ((today (org-today))
4746 (date (calendar-gregorian-from-absolute today))
4747 (kwds org-todo-keywords-for-agenda)
4748 (completion-ignore-case t)
4749 (org-select-this-todo-keyword
4750 (if (stringp arg) arg
4751 (and arg (integerp arg) (> arg 0)
4752 (nth (1- arg) kwds))))
4753 rtn rtnall files file pos)
4754 (when (equal arg '(4))
4755 (setq org-select-this-todo-keyword
4756 (completing-read "Keyword (or KWD1|K2D2|...): "
4757 (mapcar #'list kwds) nil nil)))
4758 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4760 (if org-agenda-sticky
4761 (setq org-agenda-buffer-name
4762 (if (stringp org-select-this-todo-keyword)
4763 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4764 org-select-this-todo-keyword)
4765 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4766 (org-agenda-prepare "TODO")
4767 (org-compile-prefix-format 'todo)
4768 (org-set-sorting-strategy 'todo)
4769 (setq org-agenda-redo-command
4770 `(org-todo-list (or (and (numberp current-prefix-arg)
4772 ,org-select-this-todo-keyword
4773 current-prefix-arg ,arg)))
4774 (setq files (org-agenda-files nil 'ifmode)
4776 (while (setq file (pop files))
4778 (org-check-agenda-file file)
4779 (setq rtn (org-agenda-get-day-entries file date :todo))
4780 (setq rtnall (append rtnall rtn))))
4781 (if org-agenda-overriding-header
4782 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4783 nil 'face 'org-agenda-structure) "\n")
4784 (insert "Global list of TODO items of type: ")
4785 (add-text-properties (point-min) (1- (point))
4786 (list 'face 'org-agenda-structure
4789 (or org-select-this-todo-keyword "ALL"))))
4790 (org-agenda-mark-header-line (point-min))
4791 (insert (org-agenda-propertize-selected-todo-keywords
4792 org-select-this-todo-keyword))
4794 (unless org-agenda-multi
4795 (insert (substitute-command-keys "Available with \
4796 `N \\[org-agenda-redo]': (0)[ALL]"))
4799 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4800 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4805 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4806 (org-agenda-mark-header-line (point-min))
4808 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4809 (goto-char (point-min))
4810 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4811 (add-text-properties (point-min) (point-max)
4812 `(org-agenda-type todo
4814 org-redo-cmd ,org-agenda-redo-command
4815 org-series-cmd ,org-cmd))
4816 (org-agenda-finalize)
4817 (setq buffer-read-only t))))
4819 ;;; Agenda tags match
4822 (defun org-tags-view (&optional todo-only match)
4823 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4824 The prefix arg TODO-ONLY limits the search to TODO entries."
4826 (if org-agenda-overriding-arguments
4827 (setq todo-only (car org-agenda-overriding-arguments)
4828 match (nth 1 org-agenda-overriding-arguments)))
4829 (let* ((org-tags-match-list-sublevels
4830 org-tags-match-list-sublevels)
4831 (completion-ignore-case t)
4832 rtn rtnall files file pos matcher
4834 (when (and (stringp match) (not (string-match "\\S-" match)))
4837 (if org-agenda-sticky
4838 (setq org-agenda-buffer-name
4840 (format "*Org Agenda(%s:%s)*"
4841 (or org-keys (or (and todo-only "M") "m")) match)
4842 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4843 ;; Prepare agendas (and `org-tag-alist-for-agenda') before
4844 ;; expanding tags within `org-make-tags-matcher'
4845 (org-agenda-prepare (concat "TAGS " match))
4846 (setq org--matcher-tags-todo-only todo-only
4847 matcher (org-make-tags-matcher match)
4849 matcher (cdr matcher))
4850 (org-compile-prefix-format 'tags)
4851 (org-set-sorting-strategy 'tags)
4852 (setq org-agenda-query-string match)
4853 (setq org-agenda-redo-command
4854 (list 'org-tags-view
4855 org--matcher-tags-todo-only
4856 `(if current-prefix-arg nil ,org-agenda-query-string)))
4857 (setq files (org-agenda-files nil 'ifmode)
4859 (while (setq file (pop files))
4861 (org-check-agenda-file file)
4862 (setq buffer (if (file-exists-p file)
4863 (org-get-agenda-file-buffer file)
4864 (error "No such file %s" file)))
4866 ;; If file does not exist, error message to agenda
4868 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4869 rtnall (append rtnall rtn))
4870 (with-current-buffer buffer
4871 (unless (derived-mode-p 'org-mode)
4872 (error "Agenda file %s is not in `org-mode'" file))
4875 (if (eq buffer org-agenda-restrict)
4876 (narrow-to-region org-agenda-restrict-begin
4877 org-agenda-restrict-end)
4879 (setq rtn (org-scan-tags 'agenda
4881 org--matcher-tags-todo-only))
4882 (setq rtnall (append rtnall rtn))))))))
4883 (if org-agenda-overriding-header
4884 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4885 nil 'face 'org-agenda-structure) "\n")
4886 (insert "Headlines with TAGS match: ")
4887 (add-text-properties (point-min) (1- (point))
4888 (list 'face 'org-agenda-structure
4890 (concat "Match: " match)))
4893 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4895 (unless org-agenda-multi
4896 (insert (substitute-command-keys
4897 "Press `\\[universal-argument] \\[org-agenda-redo]' \
4898 to search again with new search string\n")))
4899 (add-text-properties pos (1- (point))
4900 (list 'face 'org-agenda-structure)))
4901 (org-agenda-mark-header-line (point-min))
4903 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4904 (goto-char (point-min))
4905 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4906 (add-text-properties
4907 (point-min) (point-max)
4908 `(org-agenda-type tags
4909 org-last-args (,org--matcher-tags-todo-only ,match)
4910 org-redo-cmd ,org-agenda-redo-command
4911 org-series-cmd ,org-cmd))
4912 (org-agenda-finalize)
4913 (setq buffer-read-only t))))
4915 ;;; Agenda Finding stuck projects
4917 (defvar org-agenda-skip-regexp nil
4918 "Regular expression used in skipping subtrees for the agenda.
4919 This is basically a temporary global variable that can be set and then
4920 used by user-defined selections using `org-agenda-skip-function'.")
4922 (defvar org-agenda-overriding-header nil
4923 "When set during agenda, todo and tags searches it replaces the header.
4924 This variable should not be set directly, but custom commands can bind it
4925 in the options section.")
4927 (defun org-agenda-skip-entry-when-regexp-matches ()
4928 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4929 If yes, it returns the end position of this entry, causing agenda commands
4930 to skip the entry but continuing the search in the subtree. This is a
4931 function that can be put into `org-agenda-skip-function' for the duration
4933 (let ((end (save-excursion (org-end-of-subtree t)))
4936 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4939 (defun org-agenda-skip-subtree-when-regexp-matches ()
4940 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4941 If yes, it returns the end position of this tree, causing agenda commands
4942 to skip this subtree. This is a function that can be put into
4943 `org-agenda-skip-function' for the duration of a command."
4944 (let ((end (save-excursion (org-end-of-subtree t)))
4947 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4950 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4951 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4952 If yes, it returns the end position of the current entry (NOT the tree),
4953 causing agenda commands to skip the entry but continuing the search in
4954 the subtree. This is a function that can be put into
4955 `org-agenda-skip-function' for the duration of a command. An important
4956 use of this function is for the stuck project list."
4957 (let ((end (save-excursion (org-end-of-subtree t)))
4958 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4961 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4962 (and skip entry-end)))
4964 (defun org-agenda-skip-entry-if (&rest conditions)
4965 "Skip entry if any of CONDITIONS is true.
4966 See `org-agenda-skip-if' for details."
4967 (org-agenda-skip-if nil conditions))
4969 (defun org-agenda-skip-subtree-if (&rest conditions)
4970 "Skip subtree if any of CONDITIONS is true.
4971 See `org-agenda-skip-if' for details."
4972 (org-agenda-skip-if t conditions))
4974 (defun org-agenda-skip-if (subtree conditions)
4975 "Checks current entity for CONDITIONS.
4976 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4977 the entry (i.e. the text before the next heading) is checked.
4979 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4980 from different tests. Valid conditions are:
4982 scheduled Check if there is a scheduled cookie
4983 notscheduled Check if there is no scheduled cookie
4984 deadline Check if there is a deadline
4985 notdeadline Check if there is no deadline
4986 timestamp Check if there is a timestamp (also deadline or scheduled)
4987 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4988 regexp Check if regexp matches
4989 notregexp Check if regexp does not match.
4990 todo Check if TODO keyword matches
4991 nottodo Check if TODO keyword does not match
4993 The regexp is taken from the conditions list, it must come right after
4994 the `regexp' or `notregexp' element.
4996 `todo' and `nottodo' accept as an argument a list of todo
4997 keywords, which may include \"*\" to match any todo keyword.
4999 (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
5001 would skip all entries with \"TODO\" or \"WAITING\" keywords.
5003 Instead of a list, a keyword class may be given. For example:
5005 (org-agenda-skip-entry-if \\='nottodo \\='done)
5007 would skip entries that haven't been marked with any of \"DONE\"
5008 keywords. Possible classes are: `todo', `done', `any'.
5010 If any of these conditions is met, this function returns the end point of
5011 the entity, causing the search to continue from there. This is a function
5012 that can be put into `org-agenda-skip-function' for the duration of a command."
5014 (org-back-to-heading t)
5017 (progn (org-end-of-subtree t) (point))
5018 (progn (outline-next-heading) (1- (point)))))
5022 (and (memq 'scheduled conditions)
5023 (re-search-forward org-scheduled-time-regexp end t))
5024 (and (memq 'notscheduled conditions)
5025 (not (re-search-forward org-scheduled-time-regexp end t)))
5026 (and (memq 'deadline conditions)
5027 (re-search-forward org-deadline-time-regexp end t))
5028 (and (memq 'notdeadline conditions)
5029 (not (re-search-forward org-deadline-time-regexp end t)))
5030 (and (memq 'timestamp conditions)
5031 (re-search-forward org-ts-regexp end t))
5032 (and (memq 'nottimestamp conditions)
5033 (not (re-search-forward org-ts-regexp end t)))
5034 (and (setq m (memq 'regexp conditions))
5036 (re-search-forward (nth 1 m) end t))
5037 (and (setq m (memq 'notregexp conditions))
5039 (not (re-search-forward (nth 1 m) end t)))
5041 (setq m (memq 'nottodo conditions))
5042 (setq m (memq 'todo-unblocked conditions))
5043 (setq m (memq 'nottodo-unblocked conditions))
5044 (setq m (memq 'todo conditions)))
5045 (org-agenda-skip-if-todo m end)))
5048 (defun org-agenda-skip-if-todo (args end)
5049 "Helper function for `org-agenda-skip-if', do not use it directly.
5050 ARGS is a list with first element either `todo', `nottodo',
5051 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
5052 a list of TODO keywords, or a state symbol `todo' or `done' or
5054 (let ((kw (car args))
5060 ((listp arg) ;; list of keywords
5061 (if (member "*" arg)
5062 (mapcar 'substring-no-properties org-todo-keywords-1)
5064 ((symbolp arg) ;; keyword class name
5067 (org-delete-all org-done-keywords
5068 (mapcar 'substring-no-properties
5069 org-todo-keywords-1)))
5070 ((eq arg 'done) org-done-keywords)
5072 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
5074 (concat "^\\*+[ \t]+\\<\\("
5075 (mapconcat 'identity todo-wds "\\|")
5078 ((eq kw 'todo) (re-search-forward todo-re end t))
5079 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
5080 ((eq kw 'todo-unblocked)
5082 (while (re-search-forward todo-re end t)
5083 (or (org-entry-blocked-p) (throw 'unblocked t)))
5085 ((eq kw 'nottodo-unblocked)
5087 (while (re-search-forward todo-re end t)
5088 (or (org-entry-blocked-p) (throw 'unblocked nil)))
5093 (defun org-agenda-list-stuck-projects (&rest ignore)
5094 "Create agenda view for projects that are stuck.
5095 Stuck projects are project that have no next actions. For the definitions
5096 of what a project is and how to check if it stuck, customize the variable
5097 `org-stuck-projects'."
5099 (let* ((org-agenda-skip-function
5100 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5101 ;; We could have used org-agenda-skip-if here.
5102 (org-agenda-overriding-header
5103 (or org-agenda-overriding-header "List of stuck projects: "))
5104 (matcher (nth 0 org-stuck-projects))
5105 (todo (nth 1 org-stuck-projects))
5106 (todo-wds (if (member "*" todo)
5108 (org-agenda-prepare-buffers (org-agenda-files
5111 org-done-keywords-for-agenda
5112 (copy-sequence org-todo-keywords-for-agenda)))
5114 (todo-re (concat "^\\*+[ \t]+\\("
5115 (mapconcat 'identity todo-wds "\\|")
5117 (tags (nth 2 org-stuck-projects))
5118 (tags-re (if (member "*" tags)
5119 (concat org-outline-regexp-bol
5120 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5122 (concat org-outline-regexp-bol
5124 (mapconcat 'identity tags "\\|")
5125 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5126 (gen-re (nth 3 org-stuck-projects))
5132 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5134 (setq org-agenda-skip-regexp
5136 (mapconcat 'identity re-list "\\|")
5137 (error "No information how to identify unstuck projects")))
5138 (org-tags-view nil matcher)
5139 (setq org-agenda-buffer-name (buffer-name))
5140 (with-current-buffer org-agenda-buffer-name
5141 (setq org-agenda-redo-command
5142 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5144 ;;; Diary integration
5146 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5147 (defvar diary-list-entries-hook)
5148 (defvar diary-time-regexp)
5149 (defun org-get-entries-from-diary (date)
5150 "Get the (Emacs Calendar) diary entries for DATE."
5151 (require 'diary-lib)
5152 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5153 (diary-display-function 'diary-fancy-display)
5155 (diary-list-entries-hook
5156 (cons 'org-diary-default-entry diary-list-entries-hook))
5157 (diary-file-name-prefix nil) ; turn this feature off
5158 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5160 (org-disable-agenda-to-diary t))
5162 (save-window-excursion
5163 (funcall (if (fboundp 'diary-list-entries)
5164 'diary-list-entries 'list-diary-entries)
5166 (if (not (get-buffer diary-fancy-buffer))
5168 (with-current-buffer diary-fancy-buffer
5169 (setq buffer-read-only nil)
5170 (if (zerop (buffer-size))
5173 ;; Omit the date and other unnecessary stuff
5174 (org-agenda-cleanup-fancy-diary)
5175 ;; Add prefix to each line and extend the text properties
5176 (if (zerop (buffer-size))
5178 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5181 (insert entries) (goto-char (point-min))
5182 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5183 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5184 (replace-match (concat "; " (match-string 1)))))
5186 (set-buffer-modified-p nil)
5187 (kill-buffer diary-fancy-buffer)))
5189 (setq entries (org-split-string entries "\n"))
5193 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5194 ;; Extend the text properties to the beginning of the line
5195 (org-add-props x (text-properties-at (1- (length x)) x)
5196 'type "diary" 'date date 'face 'org-agenda-diary))
5199 (defvar org-agenda-cleanup-fancy-diary-hook nil
5200 "Hook run when the fancy diary buffer is cleaned up.")
5202 (defun org-agenda-cleanup-fancy-diary ()
5203 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5204 This gets rid of the date, the underline under the date, and
5205 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5206 date. It also removes lines that contain only whitespace."
5207 (goto-char (point-min))
5208 (if (looking-at ".*?:[ \t]*")
5211 (re-search-forward "\n=+$" nil t)
5213 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5214 (re-search-forward "\n=+$" nil t)
5215 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5216 (goto-char (point-min))
5217 (while (re-search-forward "^ +\n" nil t)
5219 (goto-char (point-min))
5220 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5222 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5224 ;; Make sure entries from the diary have the right text properties.
5225 (eval-after-load "diary-lib"
5226 '(if (boundp 'diary-modify-entry-list-string-function)
5227 ;; We can rely on the hook, nothing to do
5229 ;; Hook not available, must use advice to make this work
5230 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5231 "Make the position visible."
5232 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5235 (setq string (org-modify-diary-entry-string string))))))
5237 (defun org-modify-diary-entry-string (string)
5238 "Add text properties to string, allowing org-mode to act on it."
5239 (org-add-props string nil
5240 'mouse-face 'highlight
5241 'help-echo (if buffer-file-name
5242 (format "mouse-2 or RET jump to diary file %s"
5243 (abbreviate-file-name buffer-file-name))
5245 'org-agenda-diary-link t
5246 'org-marker (org-agenda-new-marker (point-at-bol))))
5248 (defun org-diary-default-entry ()
5249 "Add a dummy entry to the diary.
5250 Needed to avoid empty dates which mess up holiday display."
5251 ;; Catch the error if dealing with the new add-to-diary-alist
5252 (when org-disable-agenda-to-diary
5254 (org-add-to-diary-list original-date "Org-mode dummy" "")
5256 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5258 (defun org-add-to-diary-list (&rest args)
5259 (if (fboundp 'diary-add-to-list)
5260 (apply 'diary-add-to-list args)
5261 (apply 'add-to-diary-list args)))
5263 (defvar org-diary-last-run-time nil)
5266 (defun org-diary (&rest args)
5267 "Return diary information from org files.
5268 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5269 It accesses org files and extracts information from those files to be
5270 listed in the diary. The function accepts arguments specifying what
5271 items should be listed. For a list of arguments allowed here, see the
5272 variable `org-agenda-entry-types'.
5274 The call in the diary file should look like this:
5276 &%%(org-diary) ~/path/to/some/orgfile.org
5278 Use a separate line for each org file to check. Or, if you omit the file name,
5279 all files listed in `org-agenda-files' will be checked automatically:
5283 If you don't give any arguments (as in the example above), the default value
5284 of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
5285 So the example above may also be written as
5287 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5289 The function expects the lisp variables `entry' and `date' to be provided
5290 by the caller, because this is how the calendar works. Don't use this
5291 function from a program - use `org-agenda-get-day-entries' instead."
5292 (when (> (- (org-float-time)
5293 org-agenda-last-marker-time)
5295 ;; I am not sure if this works with sticky agendas, because the marker
5296 ;; list is then no longer a global variable.
5297 (org-agenda-reset-markers))
5298 (org-compile-prefix-format 'agenda)
5299 (org-set-sorting-strategy 'agenda)
5300 (setq args (or args org-agenda-entry-types))
5301 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5303 (org-agenda-files t)))
5304 (time (org-float-time))
5306 (when (or (not org-diary-last-run-time)
5308 org-diary-last-run-time)
5310 (org-agenda-prepare-buffers files))
5311 (setq org-diary-last-run-time time)
5312 ;; If this is called during org-agenda, don't return any entries to
5313 ;; the calendar. Org Agenda will list these entries itself.
5314 (if org-disable-agenda-to-diary (setq files nil))
5315 (while (setq file (pop files))
5316 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5317 (setq results (append results rtn)))
5320 (mapcar (lambda (i) (replace-regexp-in-string
5321 org-bracket-link-regexp "\\3" i)) results))
5322 (concat (org-agenda-finalize-entries results) "\n"))))
5324 ;;; Agenda entry finders
5326 (defun org-agenda--timestamp-to-absolute (&rest args)
5327 "Call `org-time-string-to-absolute' with ARGS.
5328 However, throw `:skip' whenever an error is raised."
5330 (apply #'org-time-string-to-absolute args)
5331 (org-diary-sexp-no-match (throw :skip nil))
5333 (message "%s; Skipping entry" (error-message-string e))
5334 (throw :skip nil))))
5336 (defun org-agenda-get-day-entries (file date &rest args)
5337 "Does the work for `org-diary' and `org-agenda'.
5338 FILE is the path to a file to be checked for entries. DATE is date like
5339 the one returned by `calendar-current-date'. ARGS are symbols indicating
5340 which kind of entries should be extracted. For details about these, see
5341 the documentation of `org-diary'."
5342 (let* ((org-startup-folded nil)
5343 (org-startup-align-all-tables nil)
5344 (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
5345 (error "No such file %s" file))))
5347 ;; If file does not exist, signal it in diary nonetheless.
5348 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5349 (with-current-buffer buffer
5350 (unless (derived-mode-p 'org-mode)
5351 (error "Agenda file %s is not in `org-mode'" file))
5352 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5353 (setf org-agenda-current-date date)
5356 (if (eq buffer org-agenda-restrict)
5357 (narrow-to-region org-agenda-restrict-begin
5358 org-agenda-restrict-end)
5360 ;; Rationalize ARGS. Also make sure `:deadline' comes
5361 ;; first in order to populate DEADLINES before passing it.
5363 ;; We use `delq' since `org-uniquify' duplicates ARGS,
5364 ;; guarding us from modifying `org-agenda-entry-types'.
5365 (setf args (org-uniquify (or args org-agenda-entry-types)))
5366 (when (and (memq :scheduled args) (memq :scheduled* args))
5367 (setf args (delq :scheduled* args)))
5369 ((memq :deadline args)
5370 (setf args (cons :deadline
5371 (delq :deadline (delq :deadline* args)))))
5372 ((memq :deadline* args)
5373 (setf args (cons :deadline* (delq :deadline* args)))))
5374 ;; Collect list of headlines. Return them flattened.
5375 (let ((case-fold-search nil) results deadlines)
5376 (dolist (arg args (apply #'nconc (nreverse results)))
5378 ((and :todo (guard (org-agenda-today-p date)))
5379 (push (org-agenda-get-todos) results))
5381 (push (org-agenda-get-blocks) results)
5382 (push (org-agenda-get-timestamps deadlines) results))
5384 (push (org-agenda-get-sexps) results))
5386 (push (org-agenda-get-scheduled deadlines) results))
5388 (push (org-agenda-get-scheduled deadlines t) results))
5390 (push (org-agenda-get-progress) results))
5392 (setf deadlines (org-agenda-get-deadlines))
5393 (push deadlines results))
5395 (setf deadlines (org-agenda-get-deadlines t))
5396 (push deadlines results)))))))))))
5398 (defsubst org-em (x y list)
5399 "Is X or Y a member of LIST?"
5400 (or (memq x list) (memq y list)))
5402 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5403 (defvar org-agenda-sorting-strategy-selected nil)
5405 (defun org-agenda-entry-get-agenda-timestamp (pom)
5406 "Retrieve timestamp information for sorting agenda views.
5407 Given a point or marker POM, returns a cons cell of the timestamp
5408 and the timestamp type relevant for the sorting strategy in
5409 `org-agenda-sorting-strategy-selected'."
5410 (let (ts ts-date-type)
5412 (cond ((org-em 'scheduled-up 'scheduled-down
5413 org-agenda-sorting-strategy-selected)
5414 (setq ts (org-entry-get pom "SCHEDULED")
5415 ts-date-type " scheduled"))
5416 ((org-em 'deadline-up 'deadline-down
5417 org-agenda-sorting-strategy-selected)
5418 (setq ts (org-entry-get pom "DEADLINE")
5419 ts-date-type " deadline"))
5420 ((org-em 'ts-up 'ts-down
5421 org-agenda-sorting-strategy-selected)
5422 (setq ts (org-entry-get pom "TIMESTAMP")
5423 ts-date-type " timestamp"))
5424 ((org-em 'tsia-up 'tsia-down
5425 org-agenda-sorting-strategy-selected)
5426 (setq ts (org-entry-get pom "TIMESTAMP_IA")
5427 ts-date-type " timestamp_ia"))
5428 ((org-em 'timestamp-up 'timestamp-down
5429 org-agenda-sorting-strategy-selected)
5430 (setq ts (or (org-entry-get pom "SCHEDULED")
5431 (org-entry-get pom "DEADLINE")
5432 (org-entry-get pom "TIMESTAMP")
5433 (org-entry-get pom "TIMESTAMP_IA"))
5435 (t (setq ts-date-type "")))
5436 (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
5439 (defun org-agenda-get-todos ()
5440 "Return the TODO information for agenda display."
5441 (let* ((props (list 'face nil
5442 'done-face 'org-agenda-done
5443 'org-not-done-regexp org-not-done-regexp
5444 'org-todo-regexp org-todo-regexp
5445 'org-complex-heading-regexp org-complex-heading-regexp
5446 'mouse-face 'highlight
5448 (format "mouse-2 or RET jump to org file %s"
5449 (abbreviate-file-name buffer-file-name))))
5450 (regexp (format org-heading-keyword-regexp-format
5452 ((and org-select-this-todo-keyword
5453 (equal org-select-this-todo-keyword "*"))
5455 (org-select-this-todo-keyword
5457 (mapconcat 'identity
5459 org-select-this-todo-keyword
5462 (t org-not-done-regexp))))
5463 marker priority category level tags todo-state
5464 ts-date ts-date-type ts-date-pair
5465 ee txt beg end inherited-tags todo-state-end-pos)
5466 (goto-char (point-min))
5467 (while (re-search-forward regexp nil t)
5472 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5473 (unless (and (setq todo-state (org-get-todo-state))
5474 (setq todo-state-end-pos (match-end 2)))
5477 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5478 (goto-char (1+ beg))
5479 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5481 (goto-char (match-beginning 2))
5482 (setq marker (org-agenda-new-marker (match-beginning 0))
5483 category (org-get-category)
5484 ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
5485 ts-date (car ts-date-pair)
5486 ts-date-type (cdr ts-date-pair)
5487 txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
5489 (or (eq org-agenda-show-inherited-tags 'always)
5490 (and (listp org-agenda-show-inherited-tags)
5491 (memq 'todo org-agenda-show-inherited-tags))
5492 (and (eq org-agenda-show-inherited-tags t)
5493 (or (eq org-agenda-use-tag-inheritance t)
5494 (memq 'todo org-agenda-use-tag-inheritance))))
5495 tags (org-get-tags-at nil (not inherited-tags))
5496 level (make-string (org-reduced-level (org-outline-level)) ? )
5497 txt (org-agenda-format-item "" txt level category tags t)
5498 priority (1+ (org-get-priority txt)))
5499 (org-add-props txt props
5500 'org-marker marker 'org-hd-marker marker
5504 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5506 (if org-agenda-todo-list-sublevels
5507 (goto-char todo-state-end-pos)
5508 (org-end-of-subtree 'invisible))))
5511 (defun org-agenda-todo-custom-ignore-p (time n)
5512 "Check whether timestamp is farther away than n number of days.
5513 This function is invoked if `org-agenda-todo-ignore-deadlines',
5514 `org-agenda-todo-ignore-scheduled' or
5515 `org-agenda-todo-ignore-timestamp' is set to an integer."
5516 (let ((days (org-time-stamp-to-now
5517 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5523 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5525 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5526 (when (or org-agenda-todo-ignore-with-date
5527 org-agenda-todo-ignore-scheduled
5528 org-agenda-todo-ignore-deadlines
5529 org-agenda-todo-ignore-timestamp)
5530 (setq end (or end (save-excursion (outline-next-heading) (point))))
5532 (or (and org-agenda-todo-ignore-with-date
5533 (re-search-forward org-ts-regexp end t))
5534 (and org-agenda-todo-ignore-scheduled
5535 (re-search-forward org-scheduled-time-regexp end t)
5537 ((eq org-agenda-todo-ignore-scheduled 'future)
5538 (> (org-time-stamp-to-now
5539 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5540 ((eq org-agenda-todo-ignore-scheduled 'past)
5541 (<= (org-time-stamp-to-now
5542 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5543 ((numberp org-agenda-todo-ignore-scheduled)
5544 (org-agenda-todo-custom-ignore-p
5545 (match-string 1) org-agenda-todo-ignore-scheduled))
5547 (and org-agenda-todo-ignore-deadlines
5548 (re-search-forward org-deadline-time-regexp end t)
5550 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5551 ((eq org-agenda-todo-ignore-deadlines 'far)
5552 (not (org-deadline-close (match-string 1))))
5553 ((eq org-agenda-todo-ignore-deadlines 'future)
5554 (> (org-time-stamp-to-now
5555 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5556 ((eq org-agenda-todo-ignore-deadlines 'past)
5557 (<= (org-time-stamp-to-now
5558 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5559 ((numberp org-agenda-todo-ignore-deadlines)
5560 (org-agenda-todo-custom-ignore-p
5561 (match-string 1) org-agenda-todo-ignore-deadlines))
5562 (t (org-deadline-close (match-string 1)))))
5563 (and org-agenda-todo-ignore-timestamp
5564 (let ((buffer (current-buffer))
5567 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5569 ;; Copy current buffer into a temporary one
5571 (insert-buffer-substring buffer start end)
5572 (goto-char (point-min))
5573 ;; Delete SCHEDULED and DEADLINE items
5574 (while (re-search-forward regexp end t)
5575 (delete-region (match-beginning 0) (match-end 0)))
5576 (goto-char (point-min))
5577 ;; No search for timestamp left
5578 (when (re-search-forward org-ts-regexp nil t)
5580 ((eq org-agenda-todo-ignore-timestamp 'future)
5581 (> (org-time-stamp-to-now
5582 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5583 ((eq org-agenda-todo-ignore-timestamp 'past)
5584 (<= (org-time-stamp-to-now
5585 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5586 ((numberp org-agenda-todo-ignore-timestamp)
5587 (org-agenda-todo-custom-ignore-p
5588 (match-string 1) org-agenda-todo-ignore-timestamp))
5591 (defun org-agenda-get-timestamps (&optional deadline-results)
5592 "Return the date stamp information for agenda display."
5593 (let* ((props (list 'face 'org-agenda-calendar-event
5594 'org-not-done-regexp org-not-done-regexp
5595 'org-todo-regexp org-todo-regexp
5596 'org-complex-heading-regexp org-complex-heading-regexp
5597 'mouse-face 'highlight
5599 (format "mouse-2 or RET jump to org file %s"
5600 (abbreviate-file-name buffer-file-name))))
5601 (d1 (calendar-absolute-from-gregorian date))
5603 (deadline-position-alist
5604 (mapcar (lambda (a) (and (setq mm (get-text-property
5605 0 'org-hd-marker a))
5606 (cons (marker-position mm) a)))
5608 (remove-re org-ts-regexp)
5611 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5615 (car org-time-stamp-formats)
5616 (apply 'encode-time ; DATE bound by calendar
5617 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5619 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5620 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5621 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5622 donep tmp priority category level ee txt timestr tags
5623 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5624 inherited-tags ts-date)
5625 (goto-char (point-min))
5626 (while (setq end-of-match (re-search-forward regexp nil t))
5627 (setq b0 (match-beginning 0)
5628 b3 (match-beginning 3) e3 (match-end 3)
5629 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5630 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5631 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5633 org-agenda-repeating-timestamp-show-all)))
5635 (and (org-at-date-range-p) (throw :skip nil))
5637 (if (and (match-end 1)
5638 (not (= d1 (org-agenda--timestamp-to-absolute
5639 (match-string 1) d1 nil show-all
5640 (current-buffer) b0))))
5643 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5645 (setq tmp (buffer-substring (max (point-min)
5646 (- b0 org-ds-keyword-length))
5648 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5649 inactivep (= (char-after b0) ?\[)
5650 deadlinep (string-match org-deadline-regexp tmp)
5651 scheduledp (string-match org-scheduled-regexp tmp)
5652 closedp (and org-agenda-include-inactive-timestamps
5653 (string-match org-closed-string tmp))
5654 clockp (and org-agenda-include-inactive-timestamps
5655 (or (string-match org-clock-string tmp)
5656 (string-match "]-+\\'" tmp)))
5657 warntime (get-text-property (point) 'org-appt-warntime)
5658 donep (member todo-state org-done-keywords))
5659 (if (or scheduledp deadlinep closedp clockp
5660 (and donep org-agenda-skip-timestamp-if-done))
5662 (if (string-match ">" timestr)
5663 ;; substring should only run to end of time stamp
5664 (setq timestr (substring timestr 0 (match-end 0))))
5665 (setq marker (org-agenda-new-marker b0)
5666 category (org-get-category b0))
5668 (if (not (re-search-backward org-outline-regexp-bol nil t))
5670 (goto-char (match-beginning 0))
5671 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5672 (assoc (point) deadline-position-alist))
5674 (setq hdmarker (org-agenda-new-marker)
5676 (or (eq org-agenda-show-inherited-tags 'always)
5677 (and (listp org-agenda-show-inherited-tags)
5678 (memq 'agenda org-agenda-show-inherited-tags))
5679 (and (eq org-agenda-show-inherited-tags t)
5680 (or (eq org-agenda-use-tag-inheritance t)
5681 (memq 'agenda org-agenda-use-tag-inheritance))))
5682 tags (org-get-tags-at nil (not inherited-tags))
5683 level (make-string (org-reduced-level (org-outline-level)) ? ))
5684 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5685 (setq head (or (match-string 1) ""))
5686 (setq txt (org-agenda-format-item
5687 (if inactivep org-agenda-inactive-leader nil)
5688 head level category tags timestr
5690 (setq priority (org-get-priority txt))
5691 (org-add-props txt props 'priority priority
5692 'org-marker marker 'org-hd-marker hdmarker
5696 (ignore-errors (org-time-string-to-absolute timestr))
5697 'todo-state todo-state
5701 (if org-agenda-skip-additional-timestamps-same-entry
5702 (outline-next-heading)
5703 (goto-char end-of-match))))
5706 (defun org-agenda-get-sexps ()
5707 "Return the sexp information for agenda display."
5708 (require 'diary-lib)
5709 (let* ((props (list 'face 'org-agenda-calendar-sexp
5710 'mouse-face 'highlight
5712 (format "mouse-2 or RET jump to org file %s"
5713 (abbreviate-file-name buffer-file-name))))
5715 marker category extra level ee txt tags entry
5716 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5717 (goto-char (point-min))
5718 (while (re-search-forward regexp nil t)
5721 (setq beg (match-beginning 0))
5722 (goto-char (1- (match-end 0)))
5725 (setq sexp (buffer-substring b (point)))
5726 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5727 (org-trim (match-string 1))
5729 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5731 (setq marker (org-agenda-new-marker beg)
5732 level (make-string (org-reduced-level (org-outline-level)) ? )
5733 category (org-get-category beg)
5735 (or (eq org-agenda-show-inherited-tags 'always)
5736 (and (listp org-agenda-show-inherited-tags)
5737 (memq 'agenda org-agenda-show-inherited-tags))
5738 (and (eq org-agenda-show-inherited-tags t)
5739 (or (eq org-agenda-use-tag-inheritance t)
5740 (memq 'agenda org-agenda-use-tag-inheritance))))
5741 tags (org-get-tags-at nil (not inherited-tags))
5742 todo-state (org-get-todo-state)
5743 warntime (get-text-property (point) 'org-appt-warntime)
5746 (dolist (r (if (stringp result)
5748 result)) ;; we expect a list here
5749 (when (and org-agenda-diary-sexp-prefix
5750 (string-match org-agenda-diary-sexp-prefix r))
5751 (setq extra (match-string 0 r)
5752 r (replace-match "" nil nil r)))
5753 (if (string-match "\\S-" r)
5755 (setq txt "SEXP entry returned empty string"))
5756 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5757 (org-add-props txt props 'org-marker marker
5758 'date date 'todo-state todo-state
5759 'level level 'type "sexp" 'warntime warntime)
5763 ;; Calendar sanity: define some functions that are independent of
5764 ;; `calendar-date-style'.
5765 ;; Normally I would like to use ISO format when calling the diary functions,
5766 ;; but to make sure we still have Emacs 22 compatibility we bind
5767 ;; also `european-calendar-style' and use european format
5768 (defun org-anniversary (year month day &optional mark)
5769 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5771 (let ((calendar-date-style 'european) (european-calendar-style t))
5772 (diary-anniversary day month year mark))))
5773 (defun org-cyclic (N year month day &optional mark)
5774 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5776 (let ((calendar-date-style 'european) (european-calendar-style t))
5777 (diary-cyclic N day month year mark))))
5778 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5779 "Like `diary-block', but with fixed (ISO) order of arguments."
5781 (let ((calendar-date-style 'european) (european-calendar-style t))
5782 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5783 (defun org-date (year month day &optional mark)
5784 "Like `diary-date', but with fixed (ISO) order of arguments."
5786 (let ((calendar-date-style 'european) (european-calendar-style t))
5787 (diary-date day month year mark))))
5789 ;; Define the `org-class' function
5790 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5791 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5792 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5793 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5794 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5795 `holidays', then any date that is known by the Emacs calendar to be a
5796 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5797 then those holidays will be skipped."
5798 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5799 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5800 (d (calendar-absolute-from-gregorian date))
5801 (h (when skip-weeks (calendar-check-holidays date))))
5805 (= (calendar-day-of-week date) dayname)
5806 (or (not skip-weeks)
5809 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5810 (not (or (and h (memq 'holidays skip-weeks))
5811 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5814 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5815 "Like `org-class', but honor `calendar-date-style'.
5816 The order of the first 2 times 3 arguments depends on the variable
5817 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5818 So for American calendars, give this as MONTH DAY YEAR, for European as
5819 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5820 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5821 is any number of ISO weeks in the block period for which the item should
5824 This function is here only for backward compatibility and it is deprecated,
5825 please use `org-class' instead."
5826 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5827 (date2 (org-order-calendar-date-args m2 d2 y2)))
5829 (nth 2 date1) (car date1) (nth 1 date1)
5830 (nth 2 date2) (car date2) (nth 1 date2)
5831 dayname skip-weeks)))
5832 (make-obsolete 'org-diary-class 'org-class "")
5834 (defalias 'org-get-closed 'org-agenda-get-progress)
5835 (defun org-agenda-get-progress ()
5836 "Return the logged TODO entries for agenda display."
5837 (let* ((props (list 'mouse-face 'highlight
5838 'org-not-done-regexp org-not-done-regexp
5839 'org-todo-regexp org-todo-regexp
5840 'org-complex-heading-regexp org-complex-heading-regexp
5842 (format "mouse-2 or RET jump to org file %s"
5843 (abbreviate-file-name buffer-file-name))))
5844 (items (if (consp org-agenda-show-log-scoped)
5845 org-agenda-show-log-scoped
5846 (if (eq org-agenda-show-log-scoped 'clockcheck)
5848 org-agenda-log-mode-items)))
5852 (if (memq 'closed items) (concat "\\<" org-closed-string))
5853 (if (memq 'clock items) (concat "\\<" org-clock-string))
5854 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5855 (parts-re (if parts (mapconcat 'identity parts "\\|")
5856 (error "`org-agenda-log-mode-items' is empty")))
5858 "\\(" parts-re "\\)"
5863 (car org-time-stamp-formats)
5864 (apply 'encode-time ; DATE bound by calendar
5865 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5867 (org-agenda-search-headline-for-time nil)
5868 marker hdmarker priority category level tags closedp
5869 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5870 (goto-char (point-min))
5871 (while (re-search-forward regexp nil t)
5874 (setq marker (org-agenda-new-marker (match-beginning 0))
5875 closedp (equal (match-string 1) org-closed-string)
5876 statep (equal (string-to-char (match-string 1)) ?-)
5877 clockp (not (or closedp statep))
5878 state (and statep (match-string 2))
5879 category (org-get-category (match-beginning 0))
5880 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5881 (when (string-match "\\]" timestr)
5882 ;; substring should only run to end of time stamp
5883 (setq rest (substring timestr (match-end 0))
5884 timestr (substring timestr 0 (match-end 0)))
5885 (if (and (not closedp) (not statep)
5886 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5888 (progn (setq timestr (concat (substring timestr 0 -1)
5889 "-" (match-string 1 rest) "]"))
5890 (setq clocked (match-string 2 rest)))
5891 (setq clocked "-")))
5895 ((not org-agenda-log-mode-add-notes) nil)
5897 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5900 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5901 (match-string 1)))))
5902 (if (not (re-search-backward org-outline-regexp-bol nil t))
5904 (goto-char (match-beginning 0))
5905 (setq hdmarker (org-agenda-new-marker)
5907 (or (eq org-agenda-show-inherited-tags 'always)
5908 (and (listp org-agenda-show-inherited-tags)
5909 (memq 'todo org-agenda-show-inherited-tags))
5910 (and (eq org-agenda-show-inherited-tags t)
5911 (or (eq org-agenda-use-tag-inheritance t)
5912 (memq 'todo org-agenda-use-tag-inheritance))))
5913 tags (org-get-tags-at nil (not inherited-tags))
5914 level (make-string (org-reduced-level (org-outline-level)) ? ))
5915 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5916 (setq txt (match-string 1))
5918 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5919 (setq txt (concat (substring txt 0 (match-beginning 1))
5920 " - " extra " " (match-string 2 txt)))
5921 (setq txt (concat txt " - " extra))))
5922 (setq txt (org-agenda-format-item
5924 (closedp "Closed: ")
5925 (statep (concat "State: (" state ")"))
5926 (t (concat "Clocked: (" clocked ")")))
5927 txt level category tags timestr)))
5928 (setq priority 100000)
5929 (org-add-props txt props
5930 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5931 'priority priority 'level level
5932 'type "closed" 'date date
5933 'undone-face 'org-warning 'done-face 'org-agenda-done)
5935 (goto-char (point-at-eol))))
5938 (defun org-agenda-show-clocking-issues ()
5939 "Add overlays, showing issues with clocking.
5940 See also the user option `org-agenda-clock-consistency-checks'."
5942 (let* ((org-time-clocksum-use-effort-durations nil)
5943 (pl org-agenda-clock-consistency-checks)
5944 (re (concat "^[ \t]*"
5947 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5948 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5951 (maxtime (org-hh:mm-string-to-minutes
5952 (or (plist-get pl :max-duration) "24:00")))
5953 (mintime (org-hh:mm-string-to-minutes
5954 (or (plist-get pl :min-duration) 0)))
5955 (maxgap (org-hh:mm-string-to-minutes
5956 ;; default 30:00 means never complain
5957 (or (plist-get pl :max-gap) "30:00")))
5958 (gapok (mapcar 'org-hh:mm-string-to-minutes
5959 (plist-get pl :gap-ok-around)))
5960 (def-face (or (plist-get pl :default-face)
5961 '((:background "DarkRed") (:foreground "white"))))
5962 issue face m te ts dt ov)
5963 (goto-char (point-min))
5964 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5965 (setq issue nil face def-face)
5967 (setq m (org-get-at-bol 'org-marker)
5969 (unless (and m (markerp m))
5970 (setq issue "No valid clock line") (throw 'next t))
5971 (org-with-point-at m
5973 (goto-char (point-at-bol))
5974 (unless (looking-at re)
5975 (error "No valid Clock line")
5977 (unless (match-end 3)
5978 (setq issue "No end time"
5979 face (or (plist-get pl :no-end-time-face) face))
5981 (setq ts (match-string 1)
5984 (apply 'encode-time (org-parse-time-string ts)))
5986 (apply 'encode-time (org-parse-time-string te)))
5989 ((> dt (* 60 maxtime))
5990 ;; a very long clocking chunk
5991 (setq issue (format "Clocking interval is very long: %s"
5992 (org-minutes-to-clocksum-string
5993 (floor (/ (float dt) 60.))))
5994 face (or (plist-get pl :long-face) face)))
5995 ((< dt (* 60 mintime))
5996 ;; a very short clocking chunk
5997 (setq issue (format "Clocking interval is very short: %s"
5998 (org-minutes-to-clocksum-string
5999 (floor (/ (float dt) 60.))))
6000 face (or (plist-get pl :short-face) face)))
6001 ((and (> tlend 0) (< ts tlend))
6002 ;; Two clock entries are overlapping
6003 (setq issue (format "Clocking overlap: %d minutes"
6004 (/ (- tlend ts) 60))
6005 face (or (plist-get pl :overlap-face) face)))
6006 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
6007 ;; There is a gap, lets see if we need to report it
6008 (unless (org-agenda-check-clock-gap tlend ts gapok)
6009 (setq issue (format "Clocking gap: %d minutes"
6010 (/ (- ts tlend) 60))
6011 face (or (plist-get pl :gap-face) face))))
6013 (setq tlend (or te tlend) tlstart (or ts tlstart))
6015 ;; OK, there was some issue, add an overlay to show the issue
6016 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
6017 (overlay-put ov 'before-string
6020 (format "%-43s" (concat " " issue))
6024 (overlay-put ov 'evaporate t)))))
6026 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
6027 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
6030 ;; there are no OK times for gaps...
6032 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
6033 ;; This is more than 24 hours, so it is OK.
6034 ;; because we have at least one OK time, that must be in the
6035 ;; 24 hour interval.
6037 ;; We have a shorter gap.
6038 ;; Now we have to get the minute of the day when these times are
6039 (let* ((t1dec (decode-time (seconds-to-time t1)))
6040 (t2dec (decode-time (seconds-to-time t2)))
6041 ;; compute the minute on the day
6042 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
6043 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
6045 ;; if min2 is smaller than min1, this means it is on the next day.
6046 ;; Wrap it to after midnight.
6047 (setq min2 (+ min2 1440)))
6048 ;; Now check if any of the OK times is in the gap
6050 ;; Wrap the time to after midnight if necessary
6051 (if (< x min1) (setq x (+ x 1440)))
6052 ;; Check if in interval
6053 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
6055 ;; Nope, this gap is not OK
6058 (defun org-agenda-get-deadlines (&optional with-hour)
6059 "Return the deadline information for agenda display.
6060 When WITH-HOUR is non-nil, only return deadlines with an hour
6061 specification like [h]h:mm."
6062 (let* ((props (list 'mouse-face 'highlight
6063 'org-not-done-regexp org-not-done-regexp
6064 'org-todo-regexp org-todo-regexp
6065 'org-complex-heading-regexp org-complex-heading-regexp
6067 (format "mouse-2 or RET jump to org file %s"
6068 (abbreviate-file-name buffer-file-name))))
6069 (regexp (if with-hour
6070 org-deadline-time-hour-regexp
6071 org-deadline-time-regexp))
6072 (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
6073 (current (calendar-absolute-from-gregorian date))
6075 (goto-char (point-min))
6076 (while (re-search-forward regexp nil t)
6078 (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
6080 (let* ((s (match-string 1))
6081 (pos (1- (match-beginning 1)))
6082 (todo-state (save-match-data (org-get-todo-state)))
6083 (donep (member todo-state org-done-keywords))
6084 (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6086 org-agenda-repeating-timestamp-show-all)))
6087 ;; DEADLINE is the current scheduled date. When it
6088 ;; contains a repeater and SHOW-ALL is non-nil,
6089 ;; LAST-REPEAT is the repeat closest to CURRENT.
6090 ;; Otherwise, LAST-REPEAT is equal to DEADLINE.
6091 (last-repeat (org-agenda--timestamp-to-absolute
6092 s current 'past show-all (current-buffer) pos))
6093 (deadline (org-agenda--timestamp-to-absolute s current))
6094 (diff (- last-repeat current))
6095 (suppress-prewarning
6097 (and org-agenda-skip-deadline-prewarning-if-scheduled
6098 (org-entry-get nil "SCHEDULED"))))
6100 ((not scheduled) nil)
6101 ;; The current item has a scheduled date, so
6102 ;; evaluate its prewarning lead time.
6103 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
6104 ;; Use global prewarning-restart lead time.
6105 org-agenda-skip-deadline-prewarning-if-scheduled)
6106 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
6108 ;; Set pre-warning to no earlier than SCHEDULED.
6110 (org-agenda--timestamp-to-absolute
6111 scheduled current 'past show-all
6115 (1+ (search-forward org-deadline-string)))))
6116 org-deadline-warning-days))
6117 ;; Set pre-warning to deadline.
6119 (wdays (if suppress-prewarning
6120 (let ((org-deadline-warning-days suppress-prewarning))
6122 (org-get-wdays s))))
6123 ;; When to show a deadline in the calendar: if the
6124 ;; expiration is within WDAYS warning time. Past-due
6125 ;; deadlines are only shown on the current date
6126 (unless (or (and (<= diff wdays)
6127 (and todayp (not org-agenda-only-exact-dates)))
6130 ;; Skip done tasks if `org-agenda-skip-deadline-if-done' is
6131 ;; non-nil or if it isn't applicable to CURRENT deadline.
6133 (or org-agenda-skip-deadline-if-done
6134 (/= deadline current)))
6137 (re-search-backward "^\\*+[ \t]+" nil t)
6138 (goto-char (match-end 0))
6139 (let* ((category (org-get-category))
6141 (make-string (org-reduced-level (org-outline-level)) ?\s))
6142 (head (buffer-substring (point) (line-end-position)))
6144 (or (eq org-agenda-show-inherited-tags 'always)
6145 (and (listp org-agenda-show-inherited-tags)
6146 (memq 'agenda org-agenda-show-inherited-tags))
6147 (and (eq org-agenda-show-inherited-tags t)
6148 (or (eq org-agenda-use-tag-inheritance t)
6150 org-agenda-use-tag-inheritance)))))
6151 (tags (org-get-tags-at nil (not inherited-tags)))
6153 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6154 (concat (substring s (match-beginning 1)) " ")
6157 (org-agenda-format-item
6158 ;; For past deadlines, make sure to report time
6159 ;; difference since date S, not since closest
6161 (let ((diff (if (< (org-today) current) diff
6162 (- deadline current))))
6163 (if (= diff 0) (car org-agenda-deadline-leaders)
6164 (let ((future (nth 1 org-agenda-deadline-leaders))
6165 (past (nth 2 org-agenda-deadline-leaders)))
6166 (cond ((> diff 0) (format future diff))
6167 ((string= future past) (format past diff))
6168 (t (format past (abs diff)))))))
6169 head level category tags
6170 (and (= diff 0) timestr)))
6171 (face (org-agenda-deadline-face
6172 (- 1 (/ (float (- deadline current)) (max wdays 1)))))
6173 (upcomingp (and todayp (> diff 0)))
6174 (warntime (get-text-property (point) 'org-appt-warntime)))
6175 (org-add-props item props
6176 'org-marker (org-agenda-new-marker pos)
6177 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
6181 'priority (- (org-get-priority item) diff)
6182 'todo-state todo-state
6183 'type (if upcomingp "upcoming-deadline" "deadline")
6184 'date (if upcomingp date deadline)
6185 'face (if donep 'org-agenda-done face)
6187 'done-face 'org-agenda-done)
6188 (push item deadline-items))))))
6189 (nreverse deadline-items)))
6191 (defun org-agenda-deadline-face (fraction)
6192 "Return the face to displaying a deadline item.
6193 FRACTION is what fraction of the head-warning time has passed."
6194 (let ((faces org-agenda-deadline-faces) f)
6196 (while (setq f (pop faces))
6197 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6199 (defun org-agenda-get-scheduled (&optional deadlines with-hour)
6200 "Return the scheduled information for agenda display.
6201 Optional argument DEADLINES is a list of deadline items to be
6202 displayed in agenda view. When WITH-HOUR is non-nil, only return
6203 scheduled items with an hour specification like [h]h:mm."
6204 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6205 'org-todo-regexp org-todo-regexp
6206 'org-complex-heading-regexp org-complex-heading-regexp
6207 'done-face 'org-agenda-done
6208 'mouse-face 'highlight
6210 (format "mouse-2 or RET jump to org file %s"
6211 (abbreviate-file-name buffer-file-name))))
6212 (regexp (if with-hour
6213 org-scheduled-time-hour-regexp
6214 org-scheduled-time-regexp))
6215 (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
6216 (current (calendar-absolute-from-gregorian date))
6219 (let ((m (get-text-property 0 'org-hd-marker d)))
6220 (and m (marker-position m))))
6223 (goto-char (point-min))
6224 (while (re-search-forward regexp nil t)
6226 (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
6228 (let* ((s (match-string 1))
6229 (pos (1- (match-beginning 1)))
6230 (todo-state (save-match-data (org-get-todo-state)))
6231 (donep (member todo-state org-done-keywords))
6232 (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6234 org-agenda-repeating-timestamp-show-all)))
6235 ;; SCHEDULE is the current scheduled date. When it
6236 ;; contains a repeater and SHOW-ALL is non-nil,
6237 ;; LAST-REPEAT is the repeat closest to CURRENT.
6238 ;; Otherwise, LAST-REPEAT is equal to SCHEDULE.
6239 (last-repeat (org-agenda--timestamp-to-absolute
6240 s current 'past show-all (current-buffer) pos))
6241 (schedule (org-agenda--timestamp-to-absolute s current))
6242 (diff (- last-repeat current))
6243 (warntime (get-text-property (point) 'org-appt-warntime))
6244 (pastschedp (< schedule (org-today)))
6245 (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
6247 (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
6248 (org-entry-get nil "DEADLINE"))))
6250 ((not deadline) nil)
6251 ;; The current item has a deadline date, so
6252 ;; evaluate its delay time.
6253 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6254 ;; Use global delay time.
6255 (- org-agenda-skip-scheduled-delay-if-deadline))
6256 ((eq org-agenda-skip-scheduled-delay-if-deadline
6258 ;; Set delay to no later than DEADLINE. If
6259 ;; DEADLINE has a repeater, compare last schedule
6260 ;; repeat and last deadline repeat.
6262 (org-agenda--timestamp-to-absolute
6263 deadline current 'past show-all
6267 (1+ (search-forward org-deadline-string)))))
6268 org-scheduled-delay-days))
6272 ;; Nullify delay when a repeater triggered already
6273 ;; and the delay is of the form --Xd.
6274 ((and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6275 (/= schedule last-repeat))
6278 (let ((org-scheduled-delay-days suppress-delay))
6279 (org-get-wdays s t t)))
6280 (t (org-get-wdays s t)))))
6281 ;; Only show a scheduled item in the calendar if it is on or
6282 ;; past the current date. Skip it if it has been displayed
6283 ;; for more than `org-scheduled-past-days'.
6284 (unless (or (and (>= ddays 0) (= diff (- ddays)))
6285 (and (< (+ diff ddays) 0)
6286 (< (abs diff) org-scheduled-past-days)
6287 (and todayp (not org-agenda-only-exact-dates)))
6290 (bound-and-true-p org-habit-show-all-today)))
6292 ;; Skip done habits, or tasks if
6293 ;; `org-agenda-skip-deadline-if-done' is non-nil or if it
6294 ;; was scheduled in the past anyway.
6296 (or org-agenda-skip-scheduled-if-done
6297 (/= schedule current)
6300 ;; Skip entry if it already appears as a deadline, per
6301 ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
6302 ;; doesn't apply to habits.
6303 (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
6305 (or (not (assq (line-beginning-position 0) deadline-pos))
6308 (`repeated-after-deadline
6310 (time-to-days (org-get-deadline-time (point)))))
6311 (`not-today pastschedp)
6315 ;; Skip habits if `org-habit-show-habits' is nil, or if we
6316 ;; only show them for today.
6318 (or (not (bound-and-true-p org-habit-show-habits))
6321 org-habit-show-habits-only-for-today))))
6324 (re-search-backward "^\\*+[ \t]+" nil t)
6325 (goto-char (match-end 0))
6326 (let* ((category (org-get-category))
6328 (or (eq org-agenda-show-inherited-tags 'always)
6329 (and (listp org-agenda-show-inherited-tags)
6330 (memq 'agenda org-agenda-show-inherited-tags))
6331 (and (eq org-agenda-show-inherited-tags t)
6332 (or (eq org-agenda-use-tag-inheritance t)
6334 org-agenda-use-tag-inheritance)))))
6335 (tags (org-get-tags-at nil (not inherited-tags)))
6337 (make-string (org-reduced-level (org-outline-level)) ?\s))
6338 (head (buffer-substring (point) (line-end-position)))
6340 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6341 (concat (substring s (match-beginning 1)) " ")
6343 (item (org-agenda-format-item
6344 ;; For past scheduled dates, make sure to
6345 ;; report time difference since SCHEDULE,
6346 ;; not since closest repeater.
6347 (let ((diff (if (< (org-today) current) diff
6348 (- schedule current))))
6349 (if (= diff 0) (car org-agenda-scheduled-leaders)
6350 (format (nth 1 org-agenda-scheduled-leaders)
6352 head level category tags
6353 (and (= diff 0) timestr)
6355 (face (cond ((and (not habitp) pastschedp)
6356 'org-scheduled-previously)
6357 (todayp 'org-scheduled-today)
6358 (t 'org-scheduled)))
6359 (habitp (and habitp (org-habit-parse-todo))))
6360 (org-add-props item props
6362 'face (if donep 'org-agenda-done face)
6363 'org-marker (org-agenda-new-marker pos)
6364 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
6365 'type (if pastschedp "past-scheduled" "scheduled")
6366 'date (if pastschedp schedule date)
6370 'priority (if habitp (org-habit-get-priority habitp)
6371 (+ 94 (- 5 diff) (org-get-priority item)))
6373 'todo-state todo-state)
6374 (push item scheduled-items))))))
6375 (nreverse scheduled-items)))
6377 (defun org-agenda-get-blocks ()
6378 "Return the date-range information for agenda display."
6379 (let* ((props (list 'face nil
6380 'org-not-done-regexp org-not-done-regexp
6381 'org-todo-regexp org-todo-regexp
6382 'org-complex-heading-regexp org-complex-heading-regexp
6383 'mouse-face 'highlight
6385 (format "mouse-2 or RET jump to org file %s"
6386 (abbreviate-file-name buffer-file-name))))
6387 (regexp org-tr-regexp)
6388 (d0 (calendar-absolute-from-gregorian date))
6389 marker hdmarker ee txt d1 d2 s1 s2 category
6390 level todo-state tags pos head donep inherited-tags)
6391 (goto-char (point-min))
6392 (while (re-search-forward regexp nil t)
6396 (let ((start-time (match-string 1))
6397 (end-time (match-string 2)))
6398 (setq s1 (match-string 1)
6400 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6401 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6402 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6403 ;; Only allow days between the limits, because the normal
6404 ;; date stamps will catch the limits.
6406 (setq todo-state (org-get-todo-state))
6407 (setq donep (member todo-state org-done-keywords))
6408 (if (and donep org-agenda-skip-timestamp-if-done)
6410 (setq marker (org-agenda-new-marker (point))
6411 category (org-get-category))
6412 (if (not (re-search-backward org-outline-regexp-bol nil t))
6414 (goto-char (match-beginning 0))
6415 (setq hdmarker (org-agenda-new-marker (point))
6417 (or (eq org-agenda-show-inherited-tags 'always)
6418 (and (listp org-agenda-show-inherited-tags)
6419 (memq 'agenda org-agenda-show-inherited-tags))
6420 (and (eq org-agenda-show-inherited-tags t)
6421 (or (eq org-agenda-use-tag-inheritance t)
6422 (memq 'agenda org-agenda-use-tag-inheritance))))
6424 tags (org-get-tags-at nil (not inherited-tags)))
6425 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6426 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6427 (setq head (match-string 1))
6429 (if org-agenda-remove-timeranges-from-blocks
6431 "<" (regexp-quote s1) ".*?>"
6433 "<" (regexp-quote s2) ".*?>")
6435 (setq txt (org-agenda-format-item
6437 (nth (if (= d1 d2) 0 1)
6438 org-agenda-timerange-leaders)
6439 (1+ (- d0 d1)) (1+ (- d2 d1)))
6440 head level category tags
6441 (cond ((and (= d1 d0) (= d2 d0))
6442 (concat "<" start-time ">--<" end-time ">"))
6444 (concat "<" start-time ">"))
6446 (concat "<" end-time ">")))
6448 (org-add-props txt props
6449 'org-marker marker 'org-hd-marker hdmarker
6450 'type "block" 'date date
6452 'todo-state todo-state
6453 'priority (org-get-priority txt))
6456 ;; Sort the entries by expiration date.
6459 ;;; Agenda presentation and sorting
6461 (defvar org-prefix-has-time nil
6462 "A flag, set by `org-compile-prefix-format'.
6463 The flag is set if the currently compiled format contains a `%t'.")
6464 (defvar org-prefix-has-tag nil
6465 "A flag, set by `org-compile-prefix-format'.
6466 The flag is set if the currently compiled format contains a `%T'.")
6467 (defvar org-prefix-has-effort nil
6468 "A flag, set by `org-compile-prefix-format'.
6469 The flag is set if the currently compiled format contains a `%e'.")
6470 (defvar org-prefix-has-breadcrumbs nil
6471 "A flag, set by `org-compile-prefix-format'.
6472 The flag is set if the currently compiled format contains a `%b'.")
6473 (defvar org-prefix-category-length nil
6474 "Used by `org-compile-prefix-format' to remember the category field width.")
6475 (defvar org-prefix-category-max-length nil
6476 "Used by `org-compile-prefix-format' to remember the category field width.")
6478 (defun org-agenda-get-category-icon (category)
6479 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6480 (dolist (entry org-agenda-category-icon-alist)
6481 (when (org-string-match-p (car entry) category)
6482 (if (listp (cadr entry))
6483 (return (cadr entry))
6484 (return (apply 'create-image (cdr entry)))))))
6486 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6488 "Format TXT to be inserted into the agenda buffer.
6489 In particular, add the prefix and corresponding text properties.
6491 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6492 LEVEL may be a string to replace the `%l' specifier.
6493 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6494 category taken from local variable or file name. It will replace the `%c'
6495 specifier in the format.
6496 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6497 TXT for sorting of this entry, and for the `%t' specifier in the format.
6498 When DOTIME is a string, this string is searched for a time before TXT is.
6499 TAGS can be the tags of the headline.
6500 Any match of REMOVE-RE will be removed from TXT."
6501 ;; We keep the org-prefix-* variable values along with a compiled
6502 ;; formatter, so that multiple agendas existing at the same time do
6503 ;; not step on each other toes.
6505 ;; It was inconvenient to make these variables buffer local in
6506 ;; Agenda buffers, because this function expects to be called with
6507 ;; the buffer where item comes from being current, and not agenda
6509 (let* ((bindings (car org-prefix-format-compiled))
6510 (formatter (cadr org-prefix-format-compiled)))
6511 (loop for (var value) in bindings
6514 ;; Diary entries sometimes have extra whitespace at the beginning
6515 (setq txt (org-trim txt))
6517 ;; Fix the tags part in txt
6518 (setq txt (org-agenda-fix-displayed-tags
6520 org-agenda-show-inherited-tags
6521 org-agenda-hide-tags-regexp))
6523 (let* ((category (or category
6524 (if buffer-file-name
6525 (file-name-sans-extension
6526 (file-name-nondirectory buffer-file-name))
6528 (category-icon (org-agenda-get-category-icon category))
6529 (category-icon (if category-icon
6530 (propertize " " 'display category-icon)
6532 (effort (and (not (string= txt ""))
6533 (get-text-property 1 'effort txt)))
6534 ;; time, tag, effort are needed for the eval of the prefix format
6535 (tag (if tags (nth (1- (length tags)) tags) ""))
6537 (ts (if dotime (concat
6538 (if (stringp dotime) dotime "")
6539 (and org-agenda-search-headline-for-time txt))))
6540 (time-of-day (and dotime (org-get-time-of-day ts)))
6541 stamp plain s0 s1 s2 rtn srp l
6542 duration breadcrumbs)
6543 (and (derived-mode-p 'org-mode) buffer-file-name
6544 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6545 (when (and dotime time-of-day)
6546 ;; Extract starting and ending time and move them to prefix
6547 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6548 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6549 (setq s0 (match-string 0 ts)
6550 srp (and stamp (match-end 3))
6551 s1 (match-string (if plain 1 2) ts)
6552 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6554 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6555 ;; them, we might want to remove them there to avoid duplication.
6556 ;; The user can turn this off with a variable.
6557 (if (and org-prefix-has-time
6558 org-agenda-remove-times-when-in-prefix (or stamp plain)
6559 (string-match (concat (regexp-quote s0) " *") txt)
6560 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6561 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6562 (= (match-beginning 0) 0)
6564 (setq txt (replace-match "" nil nil txt))))
6565 ;; Normalize the time(s) to 24 hour
6566 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6567 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6569 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6570 (let (org-time-clocksum-use-effort-durations)
6571 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6573 (org-minutes-to-clocksum-string
6574 (+ (org-hh:mm-string-to-minutes s1)
6575 org-agenda-default-appointment-duration)))))
6577 ;; Compute the duration
6579 (setq duration (- (org-hh:mm-string-to-minutes s2)
6580 (org-hh:mm-string-to-minutes s1)))))
6582 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6584 ;; Tags are in the string
6585 (if (or (eq org-agenda-remove-tags t)
6586 (and org-agenda-remove-tags
6587 org-prefix-has-tag))
6588 (setq txt (replace-match "" t t txt))
6589 (setq txt (replace-match
6590 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6591 (match-string 2 txt))
6595 (while (string-match remove-re txt)
6596 (setq txt (replace-match "" t t txt))))
6598 ;; Set org-heading property on `txt' to mark the start of the
6600 (add-text-properties 0 (length txt) '(org-heading t) txt)
6602 ;; Prepare the variables needed in the eval of the compiled format
6603 (if org-prefix-has-breadcrumbs
6604 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6605 (let ((s (org-display-outline-path nil nil "->" t)))
6606 (if (eq "" s) "" (concat s "->"))))))
6607 (setq time (cond (s2 (concat
6608 (org-agenda-time-of-day-to-ampm-maybe s1)
6609 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6610 (if org-agenda-timegrid-use-ampm " ")))
6612 (org-agenda-time-of-day-to-ampm-maybe s1)
6613 (if org-agenda-timegrid-use-ampm
6617 extra (or (and (not habitp) extra) "")
6618 category (if (symbolp category) (symbol-name category) category)
6619 level (or level ""))
6620 (if (string-match org-bracket-link-regexp category)
6622 (setq l (if (match-end 3)
6623 (- (match-end 3) (match-beginning 3))
6624 (- (match-end 1) (match-beginning 1))))
6625 (when (< l (or org-prefix-category-length 0))
6626 (setq category (copy-sequence category))
6627 (org-add-props category nil
6628 'extra-space (make-string
6629 (- org-prefix-category-length l 1) ?\ ))))
6630 (if (and org-prefix-category-max-length
6631 (>= (length category) org-prefix-category-max-length))
6632 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6633 ;; Evaluate the compiled format
6634 (setq rtn (concat (eval formatter) txt))
6636 ;; And finally add the text properties
6637 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6638 (org-add-props rtn nil
6639 'org-category category
6640 'tags (mapcar 'org-downcase-keep-props tags)
6641 'org-highest-priority org-highest-priority
6642 'org-lowest-priority org-lowest-priority
6643 'time-of-day time-of-day
6645 'breadcrumbs breadcrumbs
6650 'format org-prefix-format-compiled
6653 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6654 "Remove tags string from TXT, and add a modified list of tags.
6655 The modified list may contain inherited tags, and tags matched by
6656 `org-agenda-hide-tags-regexp' will be removed."
6657 (when (or add-inherited hide-re)
6658 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6659 (setq txt (substring txt 0 (match-beginning 0))))
6662 (mapcar (lambda (tg)
6663 (if (or (and hide-re (string-match hide-re tg))
6664 (and (not add-inherited)
6665 (get-text-property 0 'inherited tg)))
6670 (let ((have-i (get-text-property 0 'inherited (car tags)))
6672 (setq txt (concat txt " :"
6675 (setq i (get-text-property 0 'inherited x))
6676 (if (and have-i (not i))
6682 (if have-i "::" ":"))))))
6685 (defun org-downcase-keep-props (s)
6686 (let ((props (text-properties-at 0 s)))
6687 (setq s (downcase s))
6688 (add-text-properties 0 (length s) props s)
6691 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6693 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6694 "Add a time-grid for agenda items which need it.
6696 LIST is the list of agenda items formatted by `org-agenda-list'.
6697 NDAYS is the span of the current agenda view.
6698 TODAYP is t when the current agenda view is on today."
6700 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6701 ((and todayp (member 'today (car org-agenda-time-grid))))
6702 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6703 ((member 'weekly (car org-agenda-time-grid)))
6704 (t (throw 'exit list)))
6705 (let* ((have (delq nil (mapcar
6706 (lambda (x) (get-text-property 1 'time-of-day x))
6708 (string (nth 1 org-agenda-time-grid))
6709 (gridtimes (nth 2 org-agenda-time-grid))
6710 (req (car org-agenda-time-grid))
6711 (remove (member 'remove-match req))
6713 (if (and (member 'require-timed req) (not have))
6714 ;; don't show empty grid
6716 (while (setq time (pop gridtimes))
6717 (unless (and remove (member time have))
6718 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6719 (push (org-agenda-format-item
6720 nil string nil "" nil
6721 (concat (substring time 0 -2) ":" (substring time -2)))
6724 2 (length (car new)) 'face 'org-time-grid (car new))))
6725 (when (and todayp org-agenda-show-current-time-in-grid)
6726 (push (org-agenda-format-item
6727 nil org-agenda-current-time-string nil "" nil
6728 (format-time-string "%H:%M "))
6731 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6733 (if (member 'time-up org-agenda-sorting-strategy-selected)
6735 (append list new)))))
6737 (defun org-compile-prefix-format (key)
6738 "Compile the prefix format into a Lisp form that can be evaluated.
6739 The resulting form and associated variable bindings is returned
6740 and stored in the variable `org-prefix-format-compiled'."
6741 (setq org-prefix-has-time nil
6742 org-prefix-has-tag nil
6743 org-prefix-category-length nil
6744 org-prefix-has-effort nil
6745 org-prefix-has-breadcrumbs nil)
6747 ((stringp org-agenda-prefix-format)
6748 org-agenda-prefix-format)
6749 ((assq key org-agenda-prefix-format)
6750 (cdr (assq key org-agenda-prefix-format)))
6751 (t " %-12:c%?-12t% s")))
6753 varform vars var e c f opt)
6754 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6756 (setq var (or (cdr (assoc (match-string 4 s)
6757 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6758 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6760 c (or (match-string 3 s) "")
6761 opt (match-beginning 1)
6762 start (1+ (match-beginning 0)))
6763 (if (equal var 'time) (setq org-prefix-has-time t))
6764 (if (equal var 'tag) (setq org-prefix-has-tag t))
6765 (if (equal var 'effort) (setq org-prefix-has-effort t))
6766 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6767 (setq f (concat "%" (match-string 2 s) "s"))
6768 (when (equal var 'category)
6769 (setq org-prefix-category-length
6770 (floor (abs (string-to-number (match-string 2 s)))))
6771 (setq org-prefix-category-max-length
6772 (let ((x (match-string 2 s)))
6774 (if (string-match "\\.[0-9]+" x)
6775 (string-to-number (substring (match-string 0 x) 1)))))))
6777 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6780 `(if (or (equal "" ,var) (equal nil ,var))
6782 (format ,f (concat ,var ,c))))
6784 `(format ,f (if (or (equal ,var "")
6785 (equal ,var nil)) ""
6786 (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6787 (setq s (replace-match "%s" t nil s))
6788 (push varform vars))
6789 (setq vars (nreverse vars))
6790 (with-current-buffer (or org-agenda-buffer (current-buffer))
6791 (setq org-prefix-format-compiled
6793 `((org-prefix-has-time ,org-prefix-has-time)
6794 (org-prefix-has-tag ,org-prefix-has-tag)
6795 (org-prefix-category-length ,org-prefix-category-length)
6796 (org-prefix-has-effort ,org-prefix-has-effort)
6797 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6798 `(format ,s ,@vars))))))
6800 (defun org-set-sorting-strategy (key)
6801 (if (symbolp (car org-agenda-sorting-strategy))
6803 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6804 (setq org-agenda-sorting-strategy-selected
6805 (or (cdr (assq key org-agenda-sorting-strategy))
6806 (cdr (assq 'agenda org-agenda-sorting-strategy))
6807 '(time-up category-keep priority-down)))))
6809 (defun org-get-time-of-day (s &optional string mod24)
6810 "Check string S for a time of day.
6811 If found, return it as a military time number between 0 and 2400.
6812 If not found, return nil.
6813 The optional STRING argument forces conversion into a 5 character wide string
6818 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6819 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6820 (not (eq (get-text-property 1 'face s) 'org-link)))
6821 (let* ((h (string-to-number (match-string 1 s)))
6822 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6823 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6824 (am-p (equal ampm "am"))
6825 (h1 (cond ((not ampm) h)
6826 ((= h 12) (if am-p 0 12))
6827 (t (+ h (if am-p 0 12)))))
6828 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6830 (t0 (+ (* 100 h2) m))
6831 (t1 (concat (if (>= h1 24) "+" " ")
6832 (if (and org-agenda-time-leading-zero
6833 (< t0 1000)) "0" "")
6834 (if (< t0 100) "0" "")
6835 (if (< t0 10) "0" "")
6836 (int-to-string t0))))
6837 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6839 (defvar org-agenda-before-sorting-filter-function nil
6840 "Function to be applied to agenda items prior to sorting.
6841 Prior to sorting also means just before they are inserted into the agenda.
6843 To aid sorting, you may revisit the original entries and add more text
6844 properties which will later be used by the sorting functions.
6846 The function should take a string argument, an agenda line.
6847 It has access to the text properties in that line, which contain among
6848 other things, the property `org-hd-marker' that points to the entry
6849 where the line comes from. Note that not all lines going into the agenda
6850 have this property, only most.
6852 The function should return the modified string. It is probably best
6853 to ONLY change text properties.
6855 You can also use this function as a filter, by returning nil for lines
6856 you don't want to have in the agenda at all. For this application, you
6857 could bind the variable in the options section of a custom command.")
6859 (defun org-agenda-finalize-entries (list &optional type)
6860 "Sort, limit and concatenate the LIST of agenda items.
6861 The optional argument TYPE tells the agenda type."
6862 (let ((max-effort (cond ((listp org-agenda-max-effort)
6863 (cdr (assoc type org-agenda-max-effort)))
6864 (t org-agenda-max-effort)))
6865 (max-todo (cond ((listp org-agenda-max-todos)
6866 (cdr (assoc type org-agenda-max-todos)))
6867 (t org-agenda-max-todos)))
6868 (max-tags (cond ((listp org-agenda-max-tags)
6869 (cdr (assoc type org-agenda-max-tags)))
6870 (t org-agenda-max-tags)))
6871 (max-entries (cond ((listp org-agenda-max-entries)
6872 (cdr (assoc type org-agenda-max-entries)))
6873 (t org-agenda-max-entries))))
6874 (when org-agenda-before-sorting-filter-function
6878 org-agenda-before-sorting-filter-function list))))
6879 (setq list (mapcar 'org-agenda-highlight-todo list)
6880 list (mapcar 'identity (sort list 'org-entries-lessp)))
6882 (setq list (org-agenda-limit-entries
6883 list 'effort-minutes max-effort
6884 (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
6887 (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
6889 (setq list (org-agenda-limit-entries list 'tags max-tags)))
6891 (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
6892 (mapconcat 'identity list "\n")))
6894 (defun org-agenda-limit-entries (list prop limit &optional fn)
6895 "Limit the number of agenda entries."
6896 (let ((include (and limit (< limit 0))))
6898 (let ((fun (or fn (lambda (p) (if p 1))))
6903 (let ((pval (funcall
6904 fun (get-text-property (1- (length e))
6906 (if pval (setq lim (+ lim pval)))
6907 (cond ((and pval (<= lim (abs limit))) e)
6908 ((and include (not pval)) e))))
6912 (defun org-agenda-limit-interactively (remove)
6913 "In agenda, interactively limit entries to various maximums."
6916 (progn (setq org-agenda-max-entries nil
6917 org-agenda-max-todos nil
6918 org-agenda-max-tags nil
6919 org-agenda-max-effort nil)
6921 (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
6922 (msg (cond ((= max ?E) "How many minutes? ")
6923 ((= max ?e) "How many entries? ")
6924 ((= max ?t) "How many TODO entries? ")
6925 ((= max ?T) "How many tagged entries? ")
6926 (t (user-error "Wrong input"))))
6927 (num (string-to-number (read-from-minibuffer msg))))
6928 (cond ((equal max ?e)
6929 (let ((org-agenda-max-entries num)) (org-agenda-redo)))
6931 (let ((org-agenda-max-todos num)) (org-agenda-redo)))
6933 (let ((org-agenda-max-tags num)) (org-agenda-redo)))
6935 (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
6936 (org-agenda-fit-window-to-buffer))
6938 (defun org-agenda-highlight-todo (x)
6939 (let ((org-done-keywords org-done-keywords-for-agenda)
6940 (case-fold-search nil)
6944 (beginning-of-line 1)
6945 (setq re (org-get-at-bol 'org-todo-regexp))
6946 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6947 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6948 (add-text-properties (match-beginning 0) (match-end 1)
6949 (list 'face (org-get-todo-face 1)))
6950 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6951 (delete-region (match-beginning 1) (1- (match-end 0)))
6952 (goto-char (match-beginning 1))
6953 (insert (format org-agenda-todo-keyword-format s)))))
6954 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6955 (setq re (get-text-property 0 'org-todo-regexp x))
6957 ;; Test `pl' because if there's no heading content,
6958 ;; there's no point matching to highlight. Note
6959 ;; that if we didn't test `pl' first, and there
6960 ;; happened to be no keyword from `org-todo-regexp'
6961 ;; on this heading line, then the `equal' comparison
6962 ;; afterwards would spuriously succeed in the case
6963 ;; where `pl' is nil -- causing an args-out-of-range
6964 ;; error when we try to add text properties to text
6965 ;; that isn't there.
6967 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6969 (add-text-properties
6970 (or (match-end 1) (match-end 0)) (match-end 0)
6971 (list 'face (org-get-todo-face (match-string 2 x)))
6974 (setq x (concat (substring x 0 (match-end 1))
6975 (format org-agenda-todo-keyword-format
6977 (org-add-props " " (text-properties-at 0 x))
6978 (substring x (match-end 3)))))))
6981 (defsubst org-cmp-values (a b property)
6982 "Compare the numeric value of text PROPERTY for string A and B."
6983 (let ((pa (or (get-text-property (1- (length a)) property a) 0))
6984 (pb (or (get-text-property (1- (length b)) property b) 0)))
6985 (cond ((> pa pb) +1)
6988 (defsubst org-cmp-effort (a b)
6989 "Compare the effort values of string A and B."
6990 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6991 (ea (or (get-text-property (1- (length a)) 'effort-minutes a) def))
6992 (eb (or (get-text-property (1- (length b)) 'effort-minutes b) def)))
6993 (cond ((> ea eb) +1)
6996 (defsubst org-cmp-category (a b)
6997 "Compare the string values of categories of strings A and B."
6998 (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
6999 (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
7000 (cond ((string-lessp ca cb) -1)
7001 ((string-lessp cb ca) +1))))
7003 (defsubst org-cmp-todo-state (a b)
7004 "Compare the todo states of strings A and B."
7005 (let* ((ma (or (get-text-property 1 'org-marker a)
7006 (get-text-property 1 'org-hd-marker a)))
7007 (mb (or (get-text-property 1 'org-marker b)
7008 (get-text-property 1 'org-hd-marker b)))
7009 (fa (and ma (marker-buffer ma)))
7010 (fb (and mb (marker-buffer mb)))
7012 (or (and fa (with-current-buffer fa org-todo-keywords-1))
7013 (and fb (with-current-buffer fb org-todo-keywords-1))))
7014 (ta (or (get-text-property 1 'todo-state a) ""))
7015 (tb (or (get-text-property 1 'todo-state b) ""))
7016 (la (- (length (member ta todo-kwds))))
7017 (lb (- (length (member tb todo-kwds))))
7018 (donepa (member ta org-done-keywords-for-agenda))
7019 (donepb (member tb org-done-keywords-for-agenda)))
7020 (cond ((and donepa (not donepb)) -1)
7021 ((and (not donepa) donepb) +1)
7025 (defsubst org-cmp-alpha (a b)
7026 "Compare the headlines, alphabetically."
7027 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
7028 (plb (text-property-any 0 (length b) 'org-heading t b))
7029 (ta (and pla (substring a pla)))
7030 (tb (and plb (substring b plb))))
7032 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
7033 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
7034 (setq ta (substring ta (match-end 0))))
7035 (setq ta (downcase ta)))
7037 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
7038 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
7039 (setq tb (substring tb (match-end 0))))
7040 (setq tb (downcase tb)))
7043 ((string-lessp ta tb) -1)
7044 ((string-lessp tb ta) +1))))
7046 (defsubst org-cmp-tag (a b)
7047 "Compare the string values of the first tags of A and B."
7048 (let ((ta (car (last (get-text-property 1 'tags a))))
7049 (tb (car (last (get-text-property 1 'tags b)))))
7052 ((string-lessp ta tb) -1)
7053 ((string-lessp tb ta) +1))))
7055 (defsubst org-cmp-time (a b)
7056 "Compare the time-of-day values of strings A and B."
7057 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
7058 (ta (or (get-text-property 1 'time-of-day a) def))
7059 (tb (or (get-text-property 1 'time-of-day b) def)))
7060 (cond ((< ta tb) -1)
7063 (defsubst org-cmp-ts (a b type)
7064 "Compare the timestamps values of entries A and B.
7065 When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
7066 \"timestamp_ia\", compare within each of these type. When TYPE
7067 is the empty string, compare all timestamps without respect of
7069 (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
7070 (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
7071 (get-text-property 1 'ts-date a))
7073 (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
7074 (get-text-property 1 'ts-date b))
7076 (cond ((< ta tb) -1)
7079 (defsubst org-cmp-habit-p (a b)
7080 "Compare the todo states of strings A and B."
7081 (let ((ha (get-text-property 1 'org-habit-p a))
7082 (hb (get-text-property 1 'org-habit-p b)))
7083 (cond ((and ha (not hb)) -1)
7084 ((and (not ha) hb) +1))))
7086 (defun org-entries-lessp (a b)
7087 "Predicate for sorting agenda entries."
7088 ;; The following variables will be used when the form is evaluated.
7089 ;; So even though the compiler complains, keep them.
7090 (let* ((ss org-agenda-sorting-strategy-selected)
7091 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
7092 (org-cmp-ts a b "")))
7093 (timestamp-down (if timestamp-up (- timestamp-up) nil))
7094 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
7095 (org-cmp-ts a b "scheduled")))
7096 (scheduled-down (if scheduled-up (- scheduled-up) nil))
7097 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
7098 (org-cmp-ts a b "deadline")))
7099 (deadline-down (if deadline-up (- deadline-up) nil))
7100 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
7101 (org-cmp-ts a b "timestamp_ia")))
7102 (tsia-down (if tsia-up (- tsia-up) nil))
7103 (ts-up (and (org-em 'ts-up 'ts-down ss)
7104 (org-cmp-ts a b "timestamp")))
7105 (ts-down (if ts-up (- ts-up) nil))
7106 (time-up (and (org-em 'time-up 'time-down ss)
7107 (org-cmp-time a b)))
7108 (time-down (if time-up (- time-up) nil))
7109 (stats-up (and (org-em 'stats-up 'stats-down ss)
7110 (org-cmp-values a b 'org-stats)))
7111 (stats-down (if stats-up (- stats-up) nil))
7112 (priority-up (and (org-em 'priority-up 'priority-down ss)
7113 (org-cmp-values a b 'priority)))
7114 (priority-down (if priority-up (- priority-up) nil))
7115 (effort-up (and (org-em 'effort-up 'effort-down ss)
7116 (org-cmp-effort a b)))
7117 (effort-down (if effort-up (- effort-up) nil))
7118 (category-up (and (or (org-em 'category-up 'category-down ss)
7119 (memq 'category-keep ss))
7120 (org-cmp-category a b)))
7121 (category-down (if category-up (- category-up) nil))
7122 (category-keep (if category-up +1 nil))
7123 (tag-up (and (org-em 'tag-up 'tag-down ss)
7125 (tag-down (if tag-up (- tag-up) nil))
7126 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
7127 (org-cmp-todo-state a b)))
7128 (todo-state-down (if todo-state-up (- todo-state-up) nil))
7129 (habit-up (and (org-em 'habit-up 'habit-down ss)
7130 (org-cmp-habit-p a b)))
7131 (habit-down (if habit-up (- habit-up) nil))
7132 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
7133 (org-cmp-alpha a b)))
7134 (alpha-down (if alpha-up (- alpha-up) nil))
7135 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
7136 user-defined-up user-defined-down)
7137 (if (and need-user-cmp org-agenda-cmp-user-defined
7138 (functionp org-agenda-cmp-user-defined))
7139 (setq user-defined-up
7140 (funcall org-agenda-cmp-user-defined a b)
7141 user-defined-down (if user-defined-up (- user-defined-up) nil)))
7143 (eval (cons 'or org-agenda-sorting-strategy-selected))
7144 '((-1 . t) (1 . nil) (nil . nil))))))
7146 ;;; Agenda restriction lock
7148 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
7149 "Overlay to mark the headline to which agenda commands are restricted.")
7150 (overlay-put org-agenda-restriction-lock-overlay
7151 'face 'org-agenda-restriction-lock)
7152 (overlay-put org-agenda-restriction-lock-overlay
7153 'help-echo "Agendas are currently limited to this subtree.")
7154 (org-detach-overlay org-agenda-restriction-lock-overlay)
7157 (defun org-agenda-set-restriction-lock (&optional type)
7158 "Set restriction lock for agenda, to current subtree or file.
7159 Restriction will be the file if TYPE is `file', or if type is the
7160 universal prefix \\='(4), or if the cursor is before the first headline
7161 in the file. Otherwise, restriction will be to the current subtree."
7163 (org-agenda-remove-restriction-lock 'noupdate)
7164 (and (equal type '(4)) (setq type 'file))
7167 ((org-at-heading-p) 'subtree)
7168 ((condition-case nil (org-back-to-heading t) (error nil))
7171 (if (eq type 'subtree)
7173 (setq org-agenda-restrict (current-buffer))
7174 (setq org-agenda-overriding-restriction 'subtree)
7175 (put 'org-agenda-files 'org-restrict
7176 (list (buffer-file-name (buffer-base-buffer))))
7177 (org-back-to-heading t)
7178 (move-overlay org-agenda-restriction-lock-overlay
7180 (if org-agenda-restriction-lock-highlight-subtree
7181 (save-excursion (org-end-of-subtree t t) (point))
7183 (move-marker org-agenda-restrict-begin (point))
7184 (move-marker org-agenda-restrict-end
7185 (save-excursion (org-end-of-subtree t t)))
7186 (message "Locking agenda restriction to subtree"))
7187 (put 'org-agenda-files 'org-restrict
7188 (list (buffer-file-name (buffer-base-buffer))))
7189 (setq org-agenda-restrict nil)
7190 (setq org-agenda-overriding-restriction 'file)
7191 (move-marker org-agenda-restrict-begin nil)
7192 (move-marker org-agenda-restrict-end nil)
7193 (message "Locking agenda restriction to file"))
7194 (setq current-prefix-arg nil)
7195 (org-agenda-maybe-redo))
7197 (defun org-agenda-remove-restriction-lock (&optional noupdate)
7198 "Remove the agenda restriction lock."
7200 (org-detach-overlay org-agenda-restriction-lock-overlay)
7201 (org-detach-overlay org-speedbar-restriction-lock-overlay)
7202 (setq org-agenda-overriding-restriction nil)
7203 (setq org-agenda-restrict nil)
7204 (put 'org-agenda-files 'org-restrict nil)
7205 (move-marker org-agenda-restrict-begin nil)
7206 (move-marker org-agenda-restrict-end nil)
7207 (setq current-prefix-arg nil)
7208 (message "Agenda restriction lock removed")
7209 (or noupdate (org-agenda-maybe-redo)))
7211 (defun org-agenda-maybe-redo ()
7212 "If there is any window showing the agenda view, update it."
7213 (let ((w (get-buffer-window (or org-agenda-this-buffer-name
7214 org-agenda-buffer-name)
7216 (w0 (selected-window)))
7221 (if org-agenda-overriding-restriction
7222 (message "Agenda view shifted to new %s restriction"
7223 org-agenda-overriding-restriction)
7224 (message "Agenda restriction lock removed")))))
7228 (defun org-agenda-check-type (error &rest types)
7229 "Check if agenda buffer is of allowed type.
7230 If ERROR is non-nil, throw an error, otherwise just return nil.
7231 Allowed types are `agenda' `timeline' `todo' `tags' `search'."
7232 (if (not org-agenda-type)
7233 (error "No Org agenda currently displayed")
7234 (if (memq org-agenda-type types)
7237 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7240 (defun org-agenda-Quit ()
7241 "Exit the agenda, killing the agenda buffer.
7242 Like `org-agenda-quit', but kill the buffer even when
7243 `org-agenda-sticky' is non-nil."
7247 (defun org-agenda-quit ()
7250 When `org-agenda-sticky' is non-nil, bury the agenda buffer
7251 instead of killing it.
7253 When `org-agenda-restore-windows-after-quit' is non-nil, restore
7254 the pre-agenda window configuration.
7256 When column view is active, exit column view instead of the
7259 (org-agenda--quit org-agenda-sticky))
7261 (defun org-agenda--quit (&optional bury)
7262 (if org-agenda-columns-active
7264 (let ((wconf org-agenda-pre-window-conf)
7265 (buf (current-buffer))
7266 (org-agenda-last-indirect-window
7267 (and (eq org-indirect-buffer-display 'other-window)
7268 org-agenda-last-indirect-buffer
7269 (get-buffer-window org-agenda-last-indirect-buffer))))
7271 ((eq org-agenda-window-setup 'other-frame)
7273 ((and org-agenda-restore-windows-after-quit
7275 ;; Maybe restore the pre-agenda window configuration. Reset
7276 ;; `org-agenda-pre-window-conf' before running
7277 ;; `set-window-configuration', which loses the current buffer.
7278 (setq org-agenda-pre-window-conf nil)
7279 (set-window-configuration wconf))
7281 (when org-agenda-last-indirect-window
7282 (delete-window org-agenda-last-indirect-window))
7283 (and (not (eq org-agenda-window-setup 'current-window))
7284 (not (one-window-p))
7287 ;; Set the agenda buffer as the current buffer instead of
7288 ;; passing it as an argument to `bury-buffer' so that
7289 ;; `bury-buffer' removes it from the window.
7290 (with-current-buffer buf
7293 (setq org-agenda-archives-mode nil
7294 org-agenda-buffer nil)))))
7296 (defun org-agenda-exit ()
7297 "Exit the agenda, killing Org buffers loaded by the agenda.
7298 Like `org-agenda-Quit', but kill any buffers that were created by
7299 the agenda. Org buffers visited directly by the user will not be
7300 touched. Also, exit the agenda even if it is in column view."
7302 (when org-agenda-columns-active
7304 (org-release-buffers org-agenda-new-buffers)
7305 (setq org-agenda-new-buffers nil)
7308 (defun org-agenda-kill-all-agenda-buffers ()
7309 "Kill all buffers in `org-agenda-mode'.
7310 This is used when toggling sticky agendas."
7313 (dolist (buf (buffer-list))
7314 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7316 (mapc 'kill-buffer blist)))
7318 (defun org-agenda-execute (arg)
7319 "Execute another agenda command, keeping same window.
7320 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7323 (let ((org-agenda-window-setup 'current-window))
7326 (defun org-agenda-redo (&optional all)
7327 "Rebuild possibly ALL agenda view(s) in the current buffer."
7329 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7330 (cpa (unless (eq all t) current-prefix-arg))
7331 (org-agenda-doing-sticky-redo org-agenda-sticky)
7332 (org-agenda-sticky nil)
7333 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7334 org-agenda-buffer-name))
7335 (org-agenda-keep-modes t)
7336 (tag-filter org-agenda-tag-filter)
7337 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7338 (top-hl-filter org-agenda-top-headline-filter)
7339 (cat-filter org-agenda-category-filter)
7340 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7341 (re-filter org-agenda-regexp-filter)
7342 (re-preset (get 'org-agenda-regexp-filter :preset-filter))
7343 (effort-filter org-agenda-effort-filter)
7344 (effort-preset (get 'org-agenda-effort-filter :preset-filter))
7345 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7346 (cols org-agenda-columns-active)
7347 (line (org-current-line))
7348 (window-line (- line (org-current-line (window-start))))
7349 (lprops (get 'org-agenda-redo-command 'org-lprops))
7350 (redo-cmd (get-text-property p 'org-redo-cmd))
7351 (last-args (get-text-property p 'org-last-args))
7352 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7353 (org-agenda-overriding-cmd-arguments
7355 (cond ((listp last-args)
7356 (cons (or cpa (car last-args)) (cdr last-args)))
7357 ((stringp last-args)
7359 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7360 (put 'org-agenda-tag-filter :preset-filter nil)
7361 (put 'org-agenda-category-filter :preset-filter nil)
7362 (put 'org-agenda-regexp-filter :preset-filter nil)
7363 (put 'org-agenda-effort-filter :preset-filter nil)
7364 (and cols (org-columns-quit))
7365 (message "Rebuilding agenda buffer...")
7367 (eval series-redo-cmd)
7368 (org-let lprops redo-cmd))
7369 (setq org-agenda-undo-list nil
7370 org-agenda-pending-undo-list nil
7371 org-agenda-tag-filter tag-filter
7372 org-agenda-category-filter cat-filter
7373 org-agenda-regexp-filter re-filter
7374 org-agenda-effort-filter effort-filter
7375 org-agenda-top-headline-filter top-hl-filter)
7376 (message "Rebuilding agenda buffer...done")
7377 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7378 (put 'org-agenda-category-filter :preset-filter cat-preset)
7379 (put 'org-agenda-regexp-filter :preset-filter re-preset)
7380 (put 'org-agenda-effort-filter :preset-filter effort-preset)
7381 (let ((tag (or tag-filter tag-preset))
7382 (cat (or cat-filter cat-preset))
7383 (effort (or effort-filter effort-preset))
7384 (re (or re-filter re-preset)))
7385 (when tag (org-agenda-filter-apply tag 'tag t))
7386 (when cat (org-agenda-filter-apply cat 'category))
7387 (when effort (org-agenda-filter-apply effort 'effort))
7388 (when re (org-agenda-filter-apply re 'regexp)))
7389 (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
7390 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7391 (org-goto-line line)
7392 (recenter window-line)))
7394 (defvar org-global-tags-completion-table nil)
7395 (defvar org-agenda-filter-form nil)
7396 (defvar org-agenda-filtered-by-category nil)
7398 (defun org-agenda-filter-by-category (strip)
7399 "Filter lines in the agenda buffer that have a specific category.
7400 The category is that of the current line.
7401 Without prefix argument, keep only the lines of that category.
7402 With a prefix argument, exclude the lines of that category.
7405 (if (and org-agenda-filtered-by-category
7406 org-agenda-category-filter)
7407 (org-agenda-filter-show-all-cat)
7408 (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
7411 (org-agenda-filter-apply
7412 (push (concat "-" cat) org-agenda-category-filter) 'category))
7414 (org-agenda-filter-apply
7415 (setq org-agenda-category-filter
7416 (list (concat "+" cat))) 'category))
7417 (t (error "No category at point"))))))
7419 (defun org-find-top-headline (&optional pos)
7420 "Find the topmost parent headline and return it."
7422 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7423 (if pos (goto-char pos))
7424 ;; Skip up to the topmost parent
7425 (while (ignore-errors (outline-up-heading 1) t))
7427 (nth 4 (org-heading-components))))))
7429 (defvar org-agenda-filtered-by-top-headline nil)
7430 (defun org-agenda-filter-by-top-headline (strip)
7431 "Keep only those lines that are descendants from the same top headline.
7432 The top headline is that of the current line."
7434 (if org-agenda-filtered-by-top-headline
7436 (setq org-agenda-filtered-by-top-headline nil
7437 org-agenda-top-headline-filter nil)
7438 (org-agenda-filter-show-all-top-filter))
7439 (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
7440 (if toph (org-agenda-filter-top-headline-apply toph strip)
7441 (error "No top-level headline at point")))))
7443 (defvar org-agenda-regexp-filter nil)
7444 (defun org-agenda-filter-by-regexp (strip)
7445 "Filter agenda entries by a regular expression.
7446 Regexp filters are cumulative.
7447 With no prefix argument, keep entries matching the regexp.
7448 With one prefix argument, filter out entries matching the regexp.
7449 With two prefix arguments, remove the regexp filters."
7451 (if (not (equal strip '(16)))
7452 (let ((flt (concat (if (equal strip '(4)) "-" "+")
7453 (read-from-minibuffer
7454 (if (equal strip '(4))
7455 "Filter out entries matching regexp: "
7456 "Narrow to entries matching regexp: ")))))
7457 (push flt org-agenda-regexp-filter)
7458 (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
7459 (org-agenda-filter-show-all-re)
7460 (message "Regexp filter removed")))
7462 (defvar org-agenda-effort-filter nil)
7463 (defun org-agenda-filter-by-effort (strip)
7464 "Filter agenda entries by effort.
7465 With no prefix argument, keep entries matching the effort condition.
7466 With one prefix argument, filter out entries matching the condition.
7467 With two prefix arguments, remove the effort filters."
7469 (cond ((member strip '(nil 4))
7470 (let ((efforts (org-split-string
7471 (or (cdr (assoc (concat org-effort-property "_ALL")
7472 org-global-properties))
7473 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7477 (while (not (member op '(?< ?> ?=)))
7478 (setq op (read-char-exclusive "Effort operator? (> = or <)")))
7479 (loop for i from 0 to 9 do
7483 (if (= i 9) "0" (int-to-string (1+ i)))
7484 "]" (nth i efforts))))
7485 (message "Effort %s%s" (char-to-string op) effort-prompt)
7486 (while (or (< eff 0) (> eff 9))
7487 (setq eff (string-to-number (char-to-string (read-char-exclusive)))))
7488 (setq org-agenda-effort-filter
7489 (list (concat (if strip "-" "+")
7490 (char-to-string op) (nth (1- eff) efforts))))
7491 (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
7492 (t (org-agenda-filter-show-all-effort)
7493 (message "Effort filter removed"))))
7495 (defun org-agenda-filter-remove-all ()
7496 "Remove all filters from the current agenda buffer."
7498 (when org-agenda-tag-filter
7499 (org-agenda-filter-show-all-tag))
7500 (when org-agenda-category-filter
7501 (org-agenda-filter-show-all-cat))
7502 (when org-agenda-regexp-filter
7503 (org-agenda-filter-show-all-re))
7504 (when org-agenda-top-headline-filter
7505 (org-agenda-filter-show-all-top-filter))
7506 (when org-agenda-effort-filter
7507 (org-agenda-filter-show-all-effort))
7508 (org-agenda-finalize))
7510 (defun org-agenda-filter-by-tag (arg &optional char exclude)
7511 "Keep only those lines in the agenda buffer that have a specific tag.
7512 The tag is selected with its fast selection letter, as
7513 configured. With a single \\[universal-argument] prefix ARG,
7514 exclude the agenda search. With a double \\[universal-argument]
7515 prefix ARG, filter the literal tag. I.e. don't filter on all its
7518 A lisp caller can specify CHAR. EXCLUDE means that the new tag should be
7519 used to exclude the search - the interactive user can also press `-' or `+'
7520 to switch between filtering and excluding."
7522 (let* ((alist org-tag-alist-for-agenda)
7523 (tag-chars (mapconcat
7524 (lambda (x) (if (and (not (symbolp (car x)))
7526 (char-to-string (cdr x))
7528 org-tag-alist-for-agenda ""))
7529 (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
7530 (string-to-list tag-chars)))
7531 (exclude (or exclude (equal arg '(4))))
7532 (expand (not (equal arg '(16))))
7533 (inhibit-read-only t)
7534 (current org-agenda-tag-filter)
7537 (while (not (memq char valid-char-list))
7539 "%s by tag [%s ], [TAB], %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
7540 (if exclude "Exclude" "Filter") tag-chars
7541 (if org-agenda-auto-exclude-function "[RET], " "")
7542 (if expand "" ", no grouptag expand"))
7543 (setq char (read-char-exclusive))
7544 ;; Excluding or filtering down
7545 (cond ((eq char ?-) (setq exclude t))
7546 ((eq char ?+) (setq exclude nil)))))
7548 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7549 (setq-local org-global-tags-completion-table
7550 (org-global-tags-completion-table)))
7551 (let ((completion-ignore-case t))
7552 (setq tag (completing-read
7553 "Tag: " org-global-tags-completion-table))))
7556 (org-agenda-filter-show-all-tag)
7557 (when org-agenda-auto-exclude-function
7558 (setq org-agenda-tag-filter nil)
7559 (dolist (tag (org-agenda-get-represented-tags))
7560 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7562 (push modifier org-agenda-tag-filter))))
7563 (if (not (null org-agenda-tag-filter))
7564 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
7566 (org-agenda-filter-show-all-tag)
7567 (when (get 'org-agenda-tag-filter :preset-filter)
7568 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
7570 (setq org-agenda-tag-filter
7571 (mapcar (lambda(tag) (concat "+" tag))
7572 (org-get-at-bol 'tags)))
7573 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
7574 ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
7576 (setq a (rassoc char alist))
7577 (and tag (setq a (cons tag nil))))
7578 (org-agenda-filter-show-all-tag)
7580 (setq org-agenda-tag-filter
7581 (cons (concat (if exclude "-" "+") tag)
7583 (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
7584 (t (error "Invalid tag selection character %c" char)))))
7586 (defun org-agenda-get-represented-tags ()
7587 "Get a list of all tags currently represented in the agenda."
7590 (goto-char (point-min))
7591 (while (setq p (next-single-property-change (point) 'tags))
7593 (mapc (lambda (x) (add-to-list 'tags x))
7594 (get-text-property (point) 'tags))))
7598 (defun org-agenda-filter-make-matcher (filter type &optional expand)
7599 "Create the form that tests a line for agenda filter. Optional
7600 argument EXPAND can be used for the TYPE tag and will expand the
7601 tags in the FILTER if any of the tags in FILTER are grouptags."
7608 (append (get 'org-agenda-tag-filter :preset-filter)
7611 (let ((op (string-to-char x)))
7612 (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
7614 (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
7617 ((eq type 'category)
7620 (append (get 'org-agenda-category-filter :preset-filter)
7623 (if (equal "-" (substring x 0 1))
7624 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7625 (setq f1 (list 'equal (substring x 1) 'cat)))
7631 (append (get 'org-agenda-regexp-filter :preset-filter)
7634 (if (equal "-" (substring x 0 1))
7635 (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
7636 (setq f1 (list 'string-match (substring x 1) 'txt)))
7642 (append (get 'org-agenda-effort-filter :preset-filter)
7645 (push (org-agenda-filter-effort-form x) f))))
7646 (cons 'and (nreverse f))))
7648 (defun org-agenda-filter-make-matcher-tag-exp (tags op)
7649 "Return a form associated to tag-expression TAGS.
7650 Build a form testing a line for agenda filter for
7651 tag-expressions. OP is an operator of type CHAR that allows the
7652 function to set the right switches in the returned form."
7654 ;; Any of the expressions can match if OP is +, all must match if
7655 ;; the operator is -.
7656 (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
7657 (let* ((tag (substring x 1))
7659 ((string= "" tag) '(not tags))
7660 ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
7662 (list 'org-match-any-p (substring tag 1 -1) 'tags))
7663 (t (list 'member (downcase tag) 'tags)))))
7664 (push (if (eq op ?-) (list 'not f) f) form)))))
7666 (defun org-agenda-filter-effort-form (e)
7667 "Return the form to compare the effort of the current line with what E says.
7668 E looks like \"+<2:25\"."
7670 (setq e (substring e 1))
7671 (setq op (string-to-char e) e (substring e 1))
7672 (setq op (cond ((equal op ?<) '<=)
7676 (list 'org-agenda-compare-effort (list 'quote op)
7677 (org-duration-string-to-minutes e))))
7679 (defun org-agenda-compare-effort (op value)
7680 "Compare the effort of the current line with VALUE, using OP.
7681 If the line does not have an effort defined, return nil."
7682 (let ((eff (org-get-at-eol 'effort-minutes 1)))
7683 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 -1))
7686 (defun org-agenda-filter-expand-tags (filter &optional no-operator)
7687 "Expand group tags in FILTER for the agenda.
7688 When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
7690 (let ((case-fold-search t) rtn)
7694 (if (string-match "^\\([+-]\\)\\(.+\\)" f)
7695 (setq dir (match-string 1 f) f0 (match-string 2 f))
7696 (setq dir (if no-operator "" "+") f0 f))
7697 (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
7698 (org-tags-expand f0 t t))
7704 (defun org-agenda-filter-apply (filter type &optional expand)
7705 "Set FILTER as the new agenda filter and apply it. Optional
7706 argument EXPAND can be used for the TYPE tag and will expand the
7707 tags in the FILTER if any of the tags in FILTER are grouptags."
7708 ;; Deactivate `org-agenda-entry-text-mode' when filtering
7709 (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
7711 (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
7712 ;; Only set `org-agenda-filtered-by-category' to t when a unique
7713 ;; category is used as the filter:
7714 (setq org-agenda-filtered-by-category
7715 (and (eq type 'category)
7716 (not (equal (substring (car filter) 0 1) "-"))))
7717 (org-agenda-set-mode-name)
7719 (goto-char (point-min))
7721 (if (org-get-at-bol 'org-marker)
7723 (setq tags (org-get-at-bol 'tags)
7724 cat (org-get-at-eol 'org-category 1)
7725 txt (org-get-at-bol 'txt))
7726 (if (not (eval org-agenda-filter-form))
7727 (org-agenda-filter-hide-line type))
7728 (beginning-of-line 2))
7729 (beginning-of-line 2))))
7730 (if (get-char-property (point) 'invisible)
7731 (ignore-errors (org-agenda-previous-line)))))
7733 (defun org-agenda-filter-top-headline-apply (hl &optional negative)
7734 "Filter by top headline HL."
7735 (org-agenda-set-mode-name)
7737 (goto-char (point-min))
7739 (let* ((pos (org-get-at-bol 'org-hd-marker))
7740 (tophl (and pos (org-find-top-headline pos))))
7741 (if (and tophl (funcall (if negative 'identity 'not)
7742 (string= hl tophl)))
7743 (org-agenda-filter-hide-line 'top-headline)))
7744 (beginning-of-line 2)))
7745 (if (get-char-property (point) 'invisible)
7746 (org-agenda-previous-line))
7747 (setq org-agenda-top-headline-filter hl
7748 org-agenda-filtered-by-top-headline t))
7750 (defun org-agenda-filter-hide-line (type)
7751 "Hide lines with TYPE in the agenda buffer."
7752 (let* ((b (max (point-min) (1- (point-at-bol))))
7754 (let ((inhibit-read-only t))
7755 (add-text-properties
7756 b e `(invisible org-filtered org-filter-type ,type)))))
7758 (defun org-agenda-remove-filter (type)
7760 "Remove filter of type TYPE from the agenda buffer."
7762 (goto-char (point-min))
7763 (let ((inhibit-read-only t) pos)
7764 (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
7766 (remove-text-properties
7767 (point) (next-single-property-change (point) 'org-filter-type)
7768 `(invisible org-filtered org-filter-type ,type))))
7769 (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
7770 (setq org-agenda-filter-form nil)
7771 (org-agenda-set-mode-name)
7772 (org-agenda-finalize)))
7774 (defun org-agenda-filter-show-all-tag nil
7775 (org-agenda-remove-filter 'tag))
7776 (defun org-agenda-filter-show-all-re nil
7777 (org-agenda-remove-filter 'regexp))
7778 (defun org-agenda-filter-show-all-effort nil
7779 (org-agenda-remove-filter 'effort))
7780 (defun org-agenda-filter-show-all-cat nil
7781 (org-agenda-remove-filter 'category))
7782 (defun org-agenda-filter-show-all-top-filter nil
7783 (org-agenda-remove-filter 'top-headline))
7785 (defun org-agenda-manipulate-query-add ()
7786 "Manipulate the query by adding a search term with positive selection.
7787 Positive selection means the term must be matched for selection of an entry."
7789 (org-agenda-manipulate-query ?\[))
7790 (defun org-agenda-manipulate-query-subtract ()
7791 "Manipulate the query by adding a search term with negative selection.
7792 Negative selection means term must not be matched for selection of an entry."
7794 (org-agenda-manipulate-query ?\]))
7795 (defun org-agenda-manipulate-query-add-re ()
7796 "Manipulate the query by adding a search regexp with positive selection.
7797 Positive selection means the regexp must match for selection of an entry."
7799 (org-agenda-manipulate-query ?\{))
7800 (defun org-agenda-manipulate-query-subtract-re ()
7801 "Manipulate the query by adding a search regexp with negative selection.
7802 Negative selection means regexp must not match for selection of an entry."
7804 (org-agenda-manipulate-query ?\}))
7805 (defun org-agenda-manipulate-query (char)
7807 ((memq org-agenda-type '(timeline agenda))
7808 (let ((org-agenda-include-inactive-timestamps t))
7810 (message "Display now includes inactive timestamps as well"))
7811 ((eq org-agenda-type 'search)
7813 'org-agenda-query-string
7814 (if org-agenda-last-search-view-search-was-boolean
7815 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7816 (?\{ . " +{}") (?\} . " -{}"))))
7818 (setq org-agenda-redo-command
7819 (list 'org-search-view
7820 (car (get-text-property (min (1- (point-max)) (point))
7822 org-agenda-query-string
7823 (+ (length org-agenda-query-string)
7824 (if (member char '(?\{ ?\})) 0 1))))
7825 (set-register org-agenda-query-register org-agenda-query-string)
7826 (let ((org-agenda-overriding-arguments
7827 (cdr org-agenda-redo-command)))
7829 (t (error "Cannot manipulate query for %s-type agenda buffers"
7832 (defun org-add-to-string (var string)
7833 (set var (concat (symbol-value var) string)))
7835 (defun org-agenda-goto-date (span)
7836 "Jump to DATE in agenda."
7838 (let* ((org-read-date-prefer-future
7839 (eval org-agenda-jump-prefer-future))
7840 (date (org-read-date))
7841 (day (time-to-days (org-time-string-to-time date)))
7842 (org-agenda-sticky-orig org-agenda-sticky)
7843 (org-agenda-buffer-tmp-name (buffer-name))
7844 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7845 (0-arg (or current-prefix-arg (car args)))
7846 (2-arg (nth 2 args))
7847 (with-hour-p (nth 4 org-agenda-redo-command))
7848 (newcmd (list 'org-agenda-list 0-arg date
7849 (org-agenda-span-to-ndays
7850 2-arg (org-time-string-to-absolute date))
7852 (newargs (cdr newcmd))
7853 (inhibit-read-only t)
7855 (if (not (org-agenda-check-type t 'agenda))
7856 (error "Not available in non-agenda views")
7857 (add-text-properties (point-min) (point-max)
7858 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7860 (goto-char (point-min))
7861 (while (not (or (= (or (get-text-property (point) 'day) 0) day)
7862 (save-excursion (move-beginning-of-line 2) (eobp))))
7863 (move-beginning-of-line 2))
7864 (setq org-agenda-sticky org-agenda-sticky-orig
7865 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7867 (defun org-agenda-goto-today ()
7870 (org-agenda-check-type t 'timeline 'agenda)
7871 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7872 (curspan (nth 2 args))
7873 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7875 (tdpos (goto-char tdpos))
7876 ((eq org-agenda-type 'agenda)
7877 (let* ((sd (org-agenda-compute-starting-span
7878 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7879 (org-agenda-overriding-arguments args))
7880 (setf (nth 1 org-agenda-overriding-arguments) sd)
7882 (org-agenda-find-same-or-today-or-agenda)))
7883 (t (error "Cannot find today")))))
7885 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7887 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7888 (text-property-any (point-min) (point-max) 'org-today t)
7889 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7890 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7891 (org-agenda-backward-block))
7894 (defun org-agenda-backward-block ()
7895 "Move backward by one agenda block."
7897 (org-agenda-forward-block 'backward))
7899 (defun org-agenda-forward-block (&optional backward)
7900 "Move forward by one agenda block.
7901 When optional argument BACKWARD is set, go backward"
7903 (cond ((not (derived-mode-p 'org-agenda-mode))
7905 "Cannot execute this command outside of org-agenda-mode buffers"))
7906 ((looking-at (if backward "\\`" "\\'"))
7907 (message "Already at the %s block" (if backward "first" "last")))
7908 (t (let ((pos (prog1 (point)
7909 (ignore-errors (if backward (backward-char 1)
7910 (move-end-of-line 1)))))
7912 'previous-single-property-change
7913 'next-single-property-change))
7915 (while (and (setq dest (funcall
7916 f (point) 'org-agenda-structural-header))
7917 (not (get-text-property
7918 (point) 'org-agenda-structural-header)))
7921 (if moved (move-beginning-of-line 1)
7922 (goto-char (if backward (point-min) (point-max)))
7923 (move-beginning-of-line 1)
7924 (message "No %s block" (if backward "previous" "further")))))))
7926 (defun org-agenda-later (arg)
7927 "Go forward in time by the current span.
7928 With prefix ARG, go forward that many times the current span."
7930 (org-agenda-check-type t 'agenda)
7931 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7932 (span (or (nth 2 args) org-agenda-current-span))
7933 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7934 (greg (calendar-gregorian-from-absolute sd))
7935 (cnt (org-get-at-bol 'org-day-cnt))
7939 (setq sd (+ (* span arg) sd)))
7941 (setq sd (+ arg sd)))
7943 (setq sd (+ (* 7 arg) sd)))
7944 ((eq span 'fortnight)
7945 (setq sd (+ (* 14 arg) sd)))
7947 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7948 sd (calendar-absolute-from-gregorian greg2))
7949 (setcar greg2 (1+ (car greg2))))
7951 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7952 sd (calendar-absolute-from-gregorian greg2))
7953 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7955 (setq sd (+ (* span arg) sd))))
7956 (let ((org-agenda-overriding-cmd
7957 ;; `cmd' may have been set by `org-agenda-run-series' which
7958 ;; uses `org-agenda-overriding-cmd' to decide whether
7959 ;; overriding is allowed for `cmd'
7960 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7961 (org-agenda-overriding-arguments
7962 (list (car args) sd span)))
7964 (org-agenda-find-same-or-today-or-agenda cnt))))
7966 (defun org-agenda-earlier (arg)
7967 "Go backward in time by the current span.
7968 With prefix ARG, go backward that many times the current span."
7970 (org-agenda-later (- arg)))
7972 (defun org-agenda-view-mode-dispatch ()
7973 "Call one of the view mode commands."
7975 (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
7976 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7977 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7978 (let ((a (read-char-exclusive)))
7980 (?\ (call-interactively 'org-agenda-reset-view))
7981 (?d (call-interactively 'org-agenda-day-view))
7982 (?w (call-interactively 'org-agenda-week-view))
7983 (?t (call-interactively 'org-agenda-fortnight-view))
7984 (?m (call-interactively 'org-agenda-month-view))
7985 (?y (call-interactively 'org-agenda-year-view))
7986 (?l (call-interactively 'org-agenda-log-mode))
7987 (?L (org-agenda-log-mode '(4)))
7988 (?c (org-agenda-log-mode 'clockcheck))
7989 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7990 (?a (call-interactively 'org-agenda-archives-mode))
7991 (?A (org-agenda-archives-mode 'files))
7992 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7993 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7994 (?G (call-interactively 'org-agenda-toggle-time-grid))
7995 (?D (call-interactively 'org-agenda-toggle-diary))
7996 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7997 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7998 (org-agenda-check-type t 'timeline 'agenda)
8000 (message "Display now includes inactive timestamps as well"))
8001 (?q (message "Abort"))
8002 (otherwise (error "Invalid key" )))))
8004 (defun org-agenda-reset-view ()
8005 "Switch to default view for agenda."
8007 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
8008 (defun org-agenda-day-view (&optional day-of-month)
8009 "Switch to daily view for agenda.
8010 With argument DAY-OF-MONTH, switch to that day of the month."
8012 (org-agenda-change-time-span 'day day-of-month))
8013 (defun org-agenda-week-view (&optional iso-week)
8014 "Switch to daily view for agenda.
8015 With argument ISO-WEEK, switch to the corresponding ISO week.
8016 If ISO-WEEK has more then 2 digits, only the last two encode the
8017 week. Any digits before this encode a year. So 200712 means
8018 week 12 of year 2007. Years in the range 1938-2037 can also be
8019 written as 2-digit years."
8021 (org-agenda-change-time-span 'week iso-week))
8022 (defun org-agenda-fortnight-view (&optional iso-week)
8023 "Switch to daily view for agenda.
8024 With argument ISO-WEEK, switch to the corresponding ISO week.
8025 If ISO-WEEK has more then 2 digits, only the last two encode the
8026 week. Any digits before this encode a year. So 200712 means
8027 week 12 of year 2007. Years in the range 1938-2037 can also be
8028 written as 2-digit years."
8030 (org-agenda-change-time-span 'fortnight iso-week))
8031 (defun org-agenda-month-view (&optional month)
8032 "Switch to monthly view for agenda.
8033 With argument MONTH, switch to that month."
8035 (org-agenda-change-time-span 'month month))
8036 (defun org-agenda-year-view (&optional year)
8037 "Switch to yearly view for agenda.
8038 With argument YEAR, switch to that year.
8039 If MONTH has more then 2 digits, only the last two encode the
8040 month. Any digits before this encode a year. So 200712 means
8041 December year 2007. Years in the range 1938-2037 can also be
8042 written as 2-digit years."
8045 (setq year (org-small-year-to-year year)))
8046 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
8047 (org-agenda-change-time-span 'year year)
8050 (defun org-agenda-change-time-span (span &optional n)
8051 "Change the agenda view to SPAN.
8052 SPAN may be `day', `week', `fortnight', `month', `year'."
8053 (org-agenda-check-type t 'agenda)
8054 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
8055 (curspan (nth 2 args)))
8056 (if (and (not n) (equal curspan span))
8057 (error "Viewing span is already \"%s\"" span))
8058 (let* ((sd (or (org-get-at-bol 'day)
8061 (sd (org-agenda-compute-starting-span sd span n))
8062 (org-agenda-overriding-cmd
8063 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
8064 (org-agenda-overriding-arguments
8065 (list (car args) sd span)))
8067 (org-agenda-find-same-or-today-or-agenda))
8068 (org-agenda-set-mode-name)
8069 (message "Switched to %s view" span)))
8071 (defun org-agenda-compute-starting-span (sd span &optional n)
8072 "Compute starting date for agenda.
8073 SPAN may be `day', `week', `fortnight', `month', `year'. The return value
8074 is a cons cell with the starting date and the number of days,
8075 so that the date SD will be in that range."
8076 (let* ((greg (calendar-gregorian-from-absolute sd))
8083 (setq sd (+ (calendar-absolute-from-gregorian
8086 ((or (eq span 'week) (eq span 'fortnight))
8087 (let* ((nt (calendar-day-of-week
8088 (calendar-gregorian-from-absolute sd)))
8089 (d (if org-agenda-start-on-weekday
8090 (- nt org-agenda-start-on-weekday)
8093 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
8097 (setq y1 (org-small-year-to-year (/ n 100))
8100 (calendar-iso-to-absolute
8102 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
8105 (when (and n (> n 99))
8106 (setq y1 (org-small-year-to-year (/ n 100))
8108 (setq sd (calendar-absolute-from-gregorian
8109 (list (or n mg) 1 (or y1 yg))))))
8111 (setq sd (calendar-absolute-from-gregorian
8112 (list 1 1 (or n yg))))))
8115 (defun org-agenda-next-date-line (&optional arg)
8116 "Jump to the next line indicating a date in agenda buffer."
8118 (org-agenda-check-type t 'agenda 'timeline)
8119 (beginning-of-line 1)
8120 ;; This does not work if user makes date format that starts with a blank
8121 (if (looking-at "^\\S-") (forward-char 1))
8122 (if (not (re-search-forward "^\\S-" nil t arg))
8125 (error "No next date after this line in this buffer")))
8126 (goto-char (match-beginning 0)))
8128 (defun org-agenda-previous-date-line (&optional arg)
8129 "Jump to the previous line indicating a date in agenda buffer."
8131 (org-agenda-check-type t 'agenda 'timeline)
8132 (beginning-of-line 1)
8133 (if (not (re-search-backward "^\\S-" nil t arg))
8134 (error "No previous date before this line in this buffer")))
8136 ;; Initialize the highlight
8137 (defvar org-hl (make-overlay 1 1))
8138 (overlay-put org-hl 'face 'highlight)
8140 (defun org-highlight (begin end &optional buffer)
8141 "Highlight a region with overlay."
8142 (move-overlay org-hl begin end (or buffer (current-buffer))))
8144 (defun org-unhighlight ()
8145 "Detach overlay INDEX."
8146 (org-detach-overlay org-hl))
8148 (defun org-unhighlight-once ()
8149 "Remove the highlight from its position, and this function from the hook."
8150 (remove-hook 'pre-command-hook 'org-unhighlight-once)
8153 (defvar org-agenda-pre-follow-window-conf nil)
8154 (defun org-agenda-follow-mode ()
8155 "Toggle follow mode in an agenda buffer."
8157 (unless org-agenda-follow-mode
8158 (setq org-agenda-pre-follow-window-conf
8159 (current-window-configuration)))
8160 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
8161 (unless org-agenda-follow-mode
8162 (set-window-configuration org-agenda-pre-follow-window-conf))
8163 (org-agenda-set-mode-name)
8164 (org-agenda-do-context-action)
8165 (message "Follow mode is %s"
8166 (if org-agenda-follow-mode "on" "off")))
8168 (defun org-agenda-entry-text-mode (&optional arg)
8169 "Toggle entry text mode in an agenda buffer."
8171 (if (or org-agenda-tag-filter
8172 org-agenda-category-filter
8173 org-agenda-regexp-filter
8174 org-agenda-top-headline-filter)
8175 (user-error "Can't show entry text in filtered views")
8176 (setq org-agenda-entry-text-mode (or (integerp arg)
8177 (not org-agenda-entry-text-mode)))
8178 (org-agenda-entry-text-hide)
8179 (and org-agenda-entry-text-mode
8180 (let ((org-agenda-entry-text-maxlines
8181 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8182 (org-agenda-entry-text-show)))
8183 (org-agenda-set-mode-name)
8184 (message "Entry text mode is %s%s"
8185 (if org-agenda-entry-text-mode "on" "off")
8186 (if (not org-agenda-entry-text-mode) ""
8187 (format " (maximum number of lines is %d)"
8188 (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
8190 (defun org-agenda-clockreport-mode ()
8191 "Toggle clocktable mode in an agenda buffer."
8193 (org-agenda-check-type t 'agenda)
8194 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
8195 (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
8196 (org-agenda-set-mode-name)
8198 (message "Clocktable mode is %s"
8199 (if org-agenda-clockreport-mode "on" "off")))
8201 (defun org-agenda-log-mode (&optional special)
8202 "Toggle log mode in an agenda buffer.
8203 With argument SPECIAL, show all possible log items, not only the ones
8204 configured in `org-agenda-log-mode-items'.
8205 With a double \\[universal-argument] prefix arg, show *only* \
8206 log items, nothing else."
8208 (org-agenda-check-type t 'agenda 'timeline)
8209 (setq org-agenda-show-log
8211 ((equal special '(16)) 'only)
8212 ((eq special 'clockcheck)
8213 (if (eq org-agenda-show-log 'clockcheck)
8215 (special '(closed clock state))
8216 (t (not org-agenda-show-log))))
8217 (setq org-agenda-start-with-log-mode org-agenda-show-log)
8218 (org-agenda-set-mode-name)
8220 (message "Log mode is %s"
8221 (if org-agenda-show-log "on" "off")))
8223 (defun org-agenda-archives-mode (&optional with-files)
8224 "Toggle inclusion of items in trees marked with :ARCHIVE:.
8225 When called with a prefix argument, include all archive files as well."
8227 (setq org-agenda-archives-mode
8228 (if with-files t (if org-agenda-archives-mode nil 'trees)))
8229 (org-agenda-set-mode-name)
8234 ((eq org-agenda-archives-mode nil)
8235 "No archives are included")
8236 ((eq org-agenda-archives-mode 'trees)
8237 (format "Trees with :%s: tag are included" org-archive-tag))
8238 ((eq org-agenda-archives-mode t)
8239 (format "Trees with :%s: tag and all active archive files are included"
8240 org-archive-tag)))))
8242 (defun org-agenda-toggle-diary ()
8243 "Toggle diary inclusion in an agenda buffer."
8245 (org-agenda-check-type t 'agenda)
8246 (setq org-agenda-include-diary (not org-agenda-include-diary))
8248 (org-agenda-set-mode-name)
8249 (message "Diary inclusion turned %s"
8250 (if org-agenda-include-diary "on" "off")))
8252 (defun org-agenda-toggle-deadlines ()
8253 "Toggle inclusion of entries with a deadline in an agenda buffer."
8255 (org-agenda-check-type t 'agenda)
8256 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
8258 (org-agenda-set-mode-name)
8259 (message "Deadlines inclusion turned %s"
8260 (if org-agenda-include-deadlines "on" "off")))
8262 (defun org-agenda-toggle-time-grid ()
8263 "Toggle time grid in an agenda buffer."
8265 (org-agenda-check-type t 'agenda)
8266 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
8268 (org-agenda-set-mode-name)
8269 (message "Time-grid turned %s"
8270 (if org-agenda-use-time-grid "on" "off")))
8272 (defun org-agenda-set-mode-name ()
8273 "Set the mode name to indicate all the small mode settings."
8276 (if (get 'org-agenda-files 'org-restrict) " []" "")
8278 '(:eval (org-agenda-span-name org-agenda-current-span))
8279 (if org-agenda-follow-mode " Follow" "")
8280 (if org-agenda-entry-text-mode " ETxt" "")
8281 (if org-agenda-include-diary " Diary" "")
8282 (if org-agenda-include-deadlines " Ddl" "")
8283 (if org-agenda-use-time-grid " Grid" "")
8284 (if (and (boundp 'org-habit-show-habits)
8285 org-habit-show-habits) " Habit" "")
8287 ((consp org-agenda-show-log) " LogAll")
8288 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
8289 (org-agenda-show-log " Log")
8291 (if (or org-agenda-category-filter
8292 (get 'org-agenda-category-filter :preset-filter))
8293 '(:eval (org-propertize
8298 (get 'org-agenda-category-filter :preset-filter)
8299 org-agenda-category-filter)
8302 'face 'org-agenda-filter-category
8303 'help-echo "Category used in filtering")) "")
8304 (if (or org-agenda-tag-filter
8305 (get 'org-agenda-tag-filter :preset-filter))
8306 '(:eval (org-propertize
8311 (get 'org-agenda-tag-filter :preset-filter)
8312 org-agenda-tag-filter)
8315 'face 'org-agenda-filter-tags
8316 'help-echo "Tags used in filtering")) "")
8317 (if (or org-agenda-effort-filter
8318 (get 'org-agenda-effort-filter :preset-filter))
8319 '(:eval (org-propertize
8324 (get 'org-agenda-effort-filter :preset-filter)
8325 org-agenda-effort-filter)
8328 'face 'org-agenda-filter-effort
8329 'help-echo "Effort conditions used in filtering")) "")
8330 (if (or org-agenda-regexp-filter
8331 (get 'org-agenda-regexp-filter :preset-filter))
8332 '(:eval (org-propertize
8337 (get 'org-agenda-regexp-filter :preset-filter)
8338 org-agenda-regexp-filter)
8341 'face 'org-agenda-filter-regexp
8342 'help-echo "Regexp used in filtering")) "")
8343 (if org-agenda-archives-mode
8344 (if (eq org-agenda-archives-mode t)
8346 (format " :%s:" org-archive-tag))
8348 (if org-agenda-clockreport-mode " Clock" "")))
8349 (force-mode-line-update))
8351 (define-obsolete-function-alias
8352 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
8354 (defun org-agenda-update-agenda-type ()
8355 "Update the agenda type after each command."
8356 (setq org-agenda-type
8357 (or (get-text-property (point) 'org-agenda-type)
8358 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
8360 (defun org-agenda-next-line ()
8361 "Move cursor to the next line, and show if follow mode is active."
8363 (call-interactively 'next-line)
8364 (org-agenda-do-context-action))
8366 (defun org-agenda-previous-line ()
8367 "Move cursor to the previous line, and show if follow-mode is active."
8369 (call-interactively 'previous-line)
8370 (org-agenda-do-context-action))
8372 (defun org-agenda-next-item (n)
8373 "Move cursor to next agenda item."
8375 (let ((col (current-column)))
8377 (when (next-single-property-change (point-at-eol) 'org-marker)
8378 (move-end-of-line 1)
8379 (goto-char (next-single-property-change (point) 'org-marker))))
8380 (org-move-to-column col))
8381 (org-agenda-do-context-action))
8383 (defun org-agenda-previous-item (n)
8384 "Move cursor to next agenda item."
8387 (let ((col (current-column))
8388 (goto (save-excursion
8389 (move-end-of-line 0)
8390 (previous-single-property-change (point) 'org-marker))))
8391 (if goto (goto-char goto))
8392 (org-move-to-column col)))
8393 (org-agenda-do-context-action))
8395 (defun org-agenda-do-context-action ()
8396 "Show outline path and, maybe, follow mode window."
8397 (let ((m (org-get-at-bol 'org-marker)))
8398 (when (and (markerp m) (marker-buffer m))
8399 (and org-agenda-follow-mode
8400 (if org-agenda-follow-indirect
8401 (org-agenda-tree-to-indirect-buffer nil)
8403 (and org-agenda-show-outline-path
8404 (org-with-point-at m (org-display-outline-path t))))))
8406 (defun org-agenda-show-tags ()
8407 "Show the tags applicable to the current item."
8409 (let* ((tags (org-get-at-bol 'tags)))
8411 (message "Tags are :%s:"
8412 (org-no-properties (mapconcat 'identity tags ":")))
8413 (message "No tags associated with this line"))))
8415 (defun org-agenda-goto (&optional highlight)
8416 "Go to the entry at point in the corresponding Org-mode file."
8418 (let* ((marker (or (org-get-at-bol 'org-marker)
8419 (org-agenda-error)))
8420 (buffer (marker-buffer marker))
8421 (pos (marker-position marker)))
8422 (switch-to-buffer-other-window buffer)
8426 (when (derived-mode-p 'org-mode)
8427 (org-show-context 'agenda)
8429 (and (outline-next-heading)
8430 (org-flag-heading nil))) ; show the next heading
8431 (when (outline-invisible-p)
8432 (outline-show-entry)) ; display invisible text
8433 (recenter (/ (window-height) 2))
8434 (org-back-to-heading t)
8435 (if (re-search-forward org-complex-heading-regexp nil t)
8436 (goto-char (match-beginning 4))))
8437 (run-hooks 'org-agenda-after-show-hook)
8438 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8440 (defvar org-agenda-after-show-hook nil
8441 "Normal hook run after an item has been shown from the agenda.
8442 Point is in the buffer where the item originated.")
8444 (defun org-agenda-kill ()
8445 "Kill the entry or subtree belonging to the current agenda entry."
8447 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8448 (let* ((bufname-orig (buffer-name))
8449 (marker (or (org-get-at-bol 'org-marker)
8450 (org-agenda-error)))
8451 (buffer (marker-buffer marker))
8452 (pos (marker-position marker))
8453 (type (org-get-at-bol 'type))
8454 dbeg dend (n 0) conf)
8455 (org-with-remote-undo buffer
8456 (with-current-buffer buffer
8459 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8460 (setq dbeg (progn (org-back-to-heading t) (point))
8461 dend (org-end-of-subtree t t))
8462 (setq dbeg (point-at-bol)
8463 dend (min (point-max) (1+ (point-at-eol)))))
8465 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8466 (setq conf (or (eq t org-agenda-confirm-kill)
8467 (and (numberp org-agenda-confirm-kill)
8468 (> n org-agenda-confirm-kill))))
8471 (format "Delete entry with %d lines in buffer \"%s\"? "
8472 n (buffer-name buffer))))
8474 (let ((org-agenda-buffer-name bufname-orig))
8475 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8476 (with-current-buffer buffer (delete-region dbeg dend))
8477 (message "Agenda item and source killed"))))
8479 (defvar org-archive-default-command) ; defined in org-archive.el
8480 (defun org-agenda-archive-default ()
8481 "Archive the entry or subtree belonging to the current agenda entry."
8483 (require 'org-archive)
8484 (org-agenda-archive-with org-archive-default-command))
8486 (defun org-agenda-archive-default-with-confirmation ()
8487 "Archive the entry or subtree belonging to the current agenda entry."
8489 (require 'org-archive)
8490 (org-agenda-archive-with org-archive-default-command 'confirm))
8492 (defun org-agenda-archive ()
8493 "Archive the entry or subtree belonging to the current agenda entry."
8495 (org-agenda-archive-with 'org-archive-subtree))
8497 (defun org-agenda-archive-to-archive-sibling ()
8498 "Move the entry to the archive sibling."
8500 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8502 (defun org-agenda-archive-with (cmd &optional confirm)
8503 "Move the entry to the archive sibling."
8505 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8506 (let* ((bufname-orig (buffer-name))
8507 (marker (or (org-get-at-bol 'org-marker)
8508 (org-agenda-error)))
8509 (buffer (marker-buffer marker))
8510 (pos (marker-position marker)))
8511 (org-with-remote-undo buffer
8512 (with-current-buffer buffer
8513 (if (derived-mode-p 'org-mode)
8515 (not (y-or-n-p "Archive this subtree or entry? ")))
8517 (save-window-excursion
8519 (let ((org-agenda-buffer-name bufname-orig))
8520 (org-remove-subtree-entries-from-agenda))
8521 (org-back-to-heading t)
8523 (error "Archiving works only in Org-mode files"))))))
8525 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8526 "Remove all lines in the agenda that correspond to a given subtree.
8527 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8528 If this information is not given, the function uses the tree at point."
8529 (let ((buf (or buf (current-buffer))) m p)
8531 (unless (and beg end)
8532 (org-back-to-heading t)
8534 (org-end-of-subtree t)
8536 (set-buffer (get-buffer org-agenda-buffer-name))
8538 (goto-char (point-max))
8539 (beginning-of-line 1)
8541 (when (and (setq m (org-get-at-bol 'org-marker))
8542 (equal buf (marker-buffer m))
8543 (setq p (marker-position m))
8546 (let ((inhibit-read-only t))
8547 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8548 (beginning-of-line 0))))))
8550 (defun org-agenda-refile (&optional goto rfloc no-update)
8551 "Refile the item at point.
8553 When GOTO is 0 or \\='(64) or a triple \\[universal-argument] prefix argument,
8554 clear the refile cache.
8555 When GOTO is \\='(16) or a double \\[universal-argument] prefix argument,
8556 go to the location of the last refiled item.
8557 RFLOC can be a refile location obtained in a different way.
8558 When NO-UPDATE is non-nil, don't redo the agenda buffer."
8561 ((member goto '(0 (64)))
8562 (org-refile-cache-clear))
8564 (org-refile-goto-last-stored))
8566 (let* ((buffer-orig (buffer-name))
8567 (marker (or (org-get-at-bol 'org-hd-marker)
8568 (org-agenda-error)))
8569 (buffer (marker-buffer marker))
8570 (pos (marker-position marker))
8572 (org-refile-get-location
8573 (if goto "Goto" "Refile to") buffer
8574 org-refile-allow-creating-parent-nodes))))
8575 (with-current-buffer buffer
8580 (let ((org-agenda-buffer-name buffer-orig))
8581 (org-remove-subtree-entries-from-agenda))
8582 (org-refile goto buffer rfloc)))))
8583 (unless no-update (org-agenda-redo)))))
8585 (defun org-agenda-open-link (&optional arg)
8586 "Open the link(s) in the current entry, if any.
8587 This looks for a link in the displayed line in the agenda.
8588 It also looks at the text of the entry itself."
8590 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8591 (org-get-at-bol 'org-marker)))
8592 (buffer (and marker (marker-buffer marker)))
8593 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8594 (lkall (and buffer (org-offer-links-in-entry
8595 buffer marker arg prefix)))
8597 (lk (if (stringp lk0) (list lk0) lk0))
8603 (with-current-buffer buffer
8604 (setq trg (and (string-match org-bracket-link-regexp l)
8605 (match-string 1 l)))
8606 (if (or (not trg) (string-match org-any-link-re trg))
8611 (when (search-forward l nil lkend)
8612 (goto-char (match-beginning 0))
8613 (org-open-at-point))))
8614 ;; This is an internal link, widen the buffer
8615 (switch-to-buffer-other-window buffer)
8618 (when (search-forward l nil lkend)
8619 (goto-char (match-beginning 0))
8620 (org-open-at-point)))))
8622 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8624 (beginning-of-line 1)
8625 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8626 (org-open-link-from-string (match-string 1)))
8627 (t (message "No link to open here")))))
8629 (defun org-agenda-copy-local-variable (var)
8630 "Get a variable from a referenced buffer and install it here."
8631 (let ((m (org-get-at-bol 'org-marker)))
8632 (when (and m (buffer-live-p (marker-buffer m)))
8633 (set (make-local-variable var)
8634 (with-current-buffer (marker-buffer m)
8635 (symbol-value var))))))
8637 (defun org-agenda-switch-to (&optional delete-other-windows)
8638 "Go to the Org mode file which contains the item at point.
8639 When optional argument DELETE-OTHER-WINDOWS is non-nil, the
8640 displayed Org file fills the frame."
8642 (if (and org-return-follows-link
8643 (not (org-get-at-bol 'org-marker))
8644 (org-in-regexp org-bracket-link-regexp))
8645 (org-open-link-from-string (match-string 0))
8646 (let* ((marker (or (org-get-at-bol 'org-marker)
8647 (org-agenda-error)))
8648 (buffer (marker-buffer marker))
8649 (pos (marker-position marker)))
8650 (unless buffer (user-error "Trying to switch to non-existent buffer"))
8651 (org-pop-to-buffer-same-window buffer)
8652 (when delete-other-windows (delete-other-windows))
8655 (when (derived-mode-p 'org-mode)
8656 (org-show-context 'agenda)
8657 (run-hooks 'org-agenda-after-show-hook)))))
8659 (defun org-agenda-goto-mouse (ev)
8660 "Go to the Org-mode file which contains the item at the mouse click."
8662 (mouse-set-point ev)
8665 (defun org-agenda-show (&optional full-entry)
8666 "Display the Org-mode file which contains the item at point.
8667 With prefix argument FULL-ENTRY, make the entire entry visible
8668 if it was hidden in the outline."
8670 (let ((win (selected-window)))
8672 (when full-entry (org-show-entry))
8673 (select-window win)))
8675 (defvar org-agenda-show-window nil)
8676 (defun org-agenda-show-and-scroll-up (&optional arg)
8677 "Display the Org-mode file which contains the item at point.
8678 When called repeatedly, scroll the window that is displaying the buffer.
8679 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8680 `show-subtree' to display the item, so that drawers and logbooks stay
8683 (let ((win (selected-window)))
8684 (if (and (window-live-p org-agenda-show-window)
8685 (eq this-command last-command))
8687 (select-window org-agenda-show-window)
8688 (ignore-errors (scroll-up)))
8690 (if arg (org-show-entry) (outline-show-subtree))
8691 (setq org-agenda-show-window (selected-window)))
8692 (select-window win)))
8694 (defun org-agenda-show-scroll-down ()
8695 "Scroll down the window showing the agenda."
8697 (let ((win (selected-window)))
8698 (when (window-live-p org-agenda-show-window)
8699 (select-window org-agenda-show-window)
8700 (ignore-errors (scroll-down))
8701 (select-window win))))
8703 (defun org-agenda-show-1 (&optional more)
8704 "Display the Org-mode file which contains the item at point.
8705 The prefix arg selects the amount of information to display:
8708 1 just show the entry according to defaults.
8709 2 show the children view
8710 3 show the subtree view
8711 4 show the entire subtree and any LOGBOOK drawers
8712 5 show the entire subtree and any drawers
8713 With prefix argument FULL-ENTRY, make the entire entry visible
8714 if it was hidden in the outline."
8716 (let ((win (selected-window)))
8718 (org-back-to-heading)
8719 (set-window-start (selected-window) (point-at-bol))
8722 (outline-hide-subtree)
8724 (org-back-to-heading)
8725 (run-hook-with-args 'org-cycle-hook 'folded))
8726 (message "Remote: FOLDED"))
8727 ((and (org-called-interactively-p 'any) (= more 1))
8728 (message "Remote: show with default settings"))
8730 (outline-show-entry)
8733 (org-back-to-heading)
8734 (run-hook-with-args 'org-cycle-hook 'children))
8735 (message "Remote: CHILDREN"))
8737 (outline-show-subtree)
8739 (org-back-to-heading)
8740 (run-hook-with-args 'org-cycle-hook 'subtree))
8741 (message "Remote: SUBTREE"))
8743 (outline-show-subtree)
8745 (org-back-to-heading)
8746 (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
8747 (message "Remote: SUBTREE AND LOGBOOK"))
8749 (outline-show-subtree)
8750 (message "Remote: SUBTREE AND ALL DRAWERS")))
8751 (select-window win)))
8753 (defvar org-agenda-cycle-counter nil)
8754 (defun org-agenda-cycle-show (&optional n)
8755 "Show the current entry in another window, with default settings.
8757 Default settings are taken from `org-show-context-detail'. When
8758 use repeatedly in immediate succession, the remote entry will
8759 cycle through visibility
8761 children -> subtree -> folded
8763 When called with a numeric prefix arg, that arg will be passed through to
8764 `org-agenda-show-1'. For the interpretation of that argument, see the
8765 docstring of `org-agenda-show-1'."
8768 (setq org-agenda-cycle-counter n)
8769 (if (not (eq last-command this-command))
8770 (setq org-agenda-cycle-counter 1)
8771 (if (equal org-agenda-cycle-counter 0)
8772 (setq org-agenda-cycle-counter 2)
8773 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8774 (if (> org-agenda-cycle-counter 3)
8775 (setq org-agenda-cycle-counter 0)))))
8776 (org-agenda-show-1 org-agenda-cycle-counter))
8778 (defun org-agenda-recenter (arg)
8779 "Display the Org-mode file which contains the item at point and recenter."
8781 (let ((win (selected-window)))
8784 (select-window win)))
8786 (defun org-agenda-show-mouse (ev)
8787 "Display the Org-mode file which contains the item at the mouse click."
8789 (mouse-set-point ev)
8792 (defun org-agenda-check-no-diary ()
8793 "Check if the entry is a diary link and abort if yes."
8794 (if (org-get-at-bol 'org-agenda-diary-link)
8795 (org-agenda-error)))
8797 (defun org-agenda-error ()
8798 "Throw an error when a command is not allowed in the agenda."
8799 (user-error "Command not allowed in this line"))
8801 (defun org-agenda-tree-to-indirect-buffer (arg)
8802 "Show the subtree corresponding to the current entry in an indirect buffer.
8803 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8805 With a numerical prefix ARG, go up to this level and then take that tree.
8806 With a negative numeric ARG, go up by this number of levels.
8807 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8808 use the dedicated frame)."
8810 (if current-prefix-arg
8811 (org-agenda-do-tree-to-indirect-buffer arg)
8812 (let ((agenda-buffer (buffer-name))
8813 (agenda-window (selected-window))
8815 (and org-last-indirect-buffer
8816 (get-buffer-window org-last-indirect-buffer))))
8817 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8818 (unless (or (eq org-indirect-buffer-display 'new-frame)
8819 (eq org-indirect-buffer-display 'dedicated-frame))
8821 (unless (and indirect-window (window-live-p indirect-window))
8822 (setq indirect-window (split-window agenda-window)))
8823 (and indirect-window (select-window indirect-window))
8824 (switch-to-buffer org-last-indirect-buffer :norecord)
8825 (fit-window-to-buffer indirect-window)))
8826 (select-window (get-buffer-window agenda-buffer))
8827 (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
8829 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8830 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8831 (org-agenda-check-no-diary)
8832 (let* ((marker (or (org-get-at-bol 'org-marker)
8833 (org-agenda-error)))
8834 (buffer (marker-buffer marker))
8835 (pos (marker-position marker)))
8836 (with-current-buffer buffer
8839 (funcall 'org-tree-to-indirect-buffer arg)))))
8841 (defvar org-last-heading-marker (make-marker)
8842 "Marker pointing to the headline that last changed its TODO state
8843 by a remote command from the agenda.")
8845 (defun org-agenda-todo-nextset ()
8846 "Switch TODO entry to next sequence."
8848 (org-agenda-todo 'nextset))
8850 (defun org-agenda-todo-previousset ()
8851 "Switch TODO entry to previous sequence."
8853 (org-agenda-todo 'previousset))
8855 (defun org-agenda-todo (&optional arg)
8856 "Cycle TODO state of line at point, also in Org-mode file.
8857 This changes the line at point, all other lines in the agenda referring to
8858 the same tree node, and the headline of the tree node in the Org-mode file."
8860 (org-agenda-check-no-diary)
8861 (let* ((col (current-column))
8862 (marker (or (org-get-at-bol 'org-marker)
8863 (org-agenda-error)))
8864 (buffer (marker-buffer marker))
8865 (pos (marker-position marker))
8866 (hdmarker (org-get-at-bol 'org-hd-marker))
8867 (todayp (org-agenda-today-p (org-get-at-bol 'day)))
8868 (inhibit-read-only t)
8869 org-agenda-headline-snapshot-before-repeat newhead just-one)
8870 (org-with-remote-undo buffer
8871 (with-current-buffer buffer
8874 (org-show-context 'agenda)
8876 (and (outline-next-heading)
8877 (org-flag-heading nil))) ; show the next heading
8878 (let ((current-prefix-arg arg))
8879 (call-interactively 'org-todo))
8880 (and (bolp) (forward-char 1))
8881 (setq newhead (org-get-heading))
8882 (when (and (org-bound-and-true-p
8883 org-agenda-headline-snapshot-before-repeat)
8884 (not (equal org-agenda-headline-snapshot-before-repeat
8887 (setq newhead org-agenda-headline-snapshot-before-repeat
8890 (org-back-to-heading)
8891 (move-marker org-last-heading-marker (point))))
8892 (beginning-of-line 1)
8893 (save-window-excursion
8894 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8895 (when (org-bound-and-true-p org-clock-out-when-done)
8896 (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
8898 (org-agenda-unmark-clocking-task))
8899 (org-move-to-column col)
8900 (org-agenda-mark-clocking-task))))
8902 (defun org-agenda-add-note (&optional arg)
8903 "Add a time-stamped note to the entry at point."
8905 (org-agenda-check-no-diary)
8906 (let* ((marker (or (org-get-at-bol 'org-marker)
8907 (org-agenda-error)))
8908 (buffer (marker-buffer marker))
8909 (pos (marker-position marker))
8910 (hdmarker (org-get-at-bol 'org-hd-marker))
8911 (inhibit-read-only t))
8912 (with-current-buffer buffer
8915 (org-show-context 'agenda)
8917 (and (outline-next-heading)
8918 (org-flag-heading nil))) ; show the next heading
8921 (defun org-agenda-change-all-lines (newhead hdmarker
8922 &optional fixface just-this)
8923 "Change all lines in the agenda buffer which match HDMARKER.
8924 The new content of the line will be NEWHEAD (as modified by
8925 `org-agenda-format-item'). HDMARKER is checked with
8926 `equal' against all `org-hd-marker' text properties in the file.
8927 If FIXFACE is non-nil, the face of each item is modified according to
8929 If JUST-THIS is non-nil, change just the current line, not all.
8930 If FORCE-TAGS is non nil, the car of it returns the new tags."
8931 (let* ((inhibit-read-only t)
8932 (line (org-current-line))
8933 (org-agenda-buffer (current-buffer))
8934 (thetags (with-current-buffer (marker-buffer hdmarker)
8935 (save-excursion (save-restriction (widen)
8936 (goto-char hdmarker)
8937 (org-get-tags-at)))))
8938 props m pl undone-face done-face finish new dotime level cat tags)
8940 (goto-char (point-max))
8941 (beginning-of-line 1)
8943 (setq finish (bobp))
8944 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8945 (or (not just-this) (= (org-current-line) line))
8947 (setq props (text-properties-at (point))
8948 dotime (org-get-at-bol 'dotime)
8949 cat (org-get-at-eol 'org-category 1)
8950 level (org-get-at-bol 'level)
8953 (let ((org-prefix-format-compiled
8954 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8955 org-prefix-format-compiled))
8956 (extra (org-get-at-bol 'extra)))
8957 (with-current-buffer (marker-buffer hdmarker)
8961 (org-agenda-format-item extra newhead level cat tags dotime)))))
8962 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8963 undone-face (org-get-at-bol 'undone-face)
8964 done-face (org-get-at-bol 'done-face))
8965 (beginning-of-line 1)
8968 (and (looking-at ".*\n?") (replace-match "")))
8970 (replace-match new t t)
8971 (beginning-of-line 1)
8972 (add-text-properties (point-at-bol) (point-at-eol) props)
8974 (add-text-properties
8975 (point-at-bol) (point-at-eol)
8977 (if org-last-todo-state-is-todo
8978 undone-face done-face))))
8979 (org-agenda-highlight-todo 'line)
8980 (beginning-of-line 1))
8981 (t (error "Line update did not work")))
8983 (narrow-to-region (point-at-bol) (point-at-eol))
8984 (org-agenda-finalize)))
8985 (beginning-of-line 0)))))
8987 (defun org-agenda-align-tags (&optional line)
8988 "Align all tags in agenda items to `org-agenda-tags-column'."
8989 (let ((inhibit-read-only t) l c)
8991 (goto-char (if line (point-at-bol) (point-min)))
8992 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8993 (if line (point-at-eol) nil) t)
8994 (add-text-properties
8995 (match-beginning 2) (match-end 2)
8996 (list 'face (delq nil (let ((prop (get-text-property
8997 (match-beginning 2) 'face)))
8998 (or (listp prop) (setq prop (list prop)))
8999 (if (memq 'org-tag prop)
9001 (cons 'org-tag prop))))))
9002 (setq l (- (match-end 2) (match-beginning 2))
9003 c (if (< org-agenda-tags-column 0)
9004 (- (abs org-agenda-tags-column) l)
9005 org-agenda-tags-column))
9006 (delete-region (match-beginning 1) (match-end 1))
9007 (goto-char (match-beginning 1))
9008 (insert (org-add-props
9009 (make-string (max 1 (- c (current-column))) ?\ )
9010 (plist-put (copy-sequence (text-properties-at (point)))
9012 (goto-char (point-min))
9013 (org-font-lock-add-tag-faces (point-max)))))
9015 (defun org-agenda-priority-up ()
9016 "Increase the priority of line at point, also in Org-mode file."
9018 (org-agenda-priority 'up))
9020 (defun org-agenda-priority-down ()
9021 "Decrease the priority of line at point, also in Org-mode file."
9023 (org-agenda-priority 'down))
9025 (defun org-agenda-priority (&optional force-direction)
9026 "Set the priority of line at point, also in Org-mode file.
9027 This changes the line at point, all other lines in the agenda referring to
9028 the same tree node, and the headline of the tree node in the Org-mode file.
9029 Called with a universal prefix arg, show the priority instead of setting it."
9031 (if (equal force-direction '(4))
9033 (unless org-enable-priority-commands
9034 (error "Priority commands are disabled"))
9035 (org-agenda-check-no-diary)
9036 (let* ((col (current-column))
9037 (marker (or (org-get-at-bol 'org-marker)
9038 (org-agenda-error)))
9039 (hdmarker (org-get-at-bol 'org-hd-marker))
9040 (buffer (marker-buffer hdmarker))
9041 (pos (marker-position hdmarker))
9042 (inhibit-read-only t)
9044 (org-with-remote-undo buffer
9045 (with-current-buffer buffer
9048 (org-show-context 'agenda)
9050 (and (outline-next-heading)
9051 (org-flag-heading nil))) ; show the next heading
9052 (funcall 'org-priority force-direction)
9054 (setq newhead (org-get-heading)))
9055 (org-agenda-change-all-lines newhead hdmarker)
9056 (org-move-to-column col)))))
9058 ;; FIXME: should fix the tags property of the agenda line.
9059 (defun org-agenda-set-tags (&optional tag onoff)
9060 "Set tags for the current headline."
9062 (org-agenda-check-no-diary)
9063 (if (and (org-region-active-p) (org-called-interactively-p 'any))
9064 (call-interactively 'org-change-tag-in-region)
9065 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9066 (org-agenda-error)))
9067 (buffer (marker-buffer hdmarker))
9068 (pos (marker-position hdmarker))
9069 (inhibit-read-only t)
9071 (org-with-remote-undo buffer
9072 (with-current-buffer buffer
9076 (org-show-context 'agenda))
9078 (and (outline-next-heading)
9079 (org-flag-heading nil))) ; show the next heading
9082 (org-toggle-tag tag onoff)
9083 (call-interactively 'org-set-tags))
9085 (setq newhead (org-get-heading)))
9086 (org-agenda-change-all-lines newhead hdmarker)
9087 (beginning-of-line 1)))))
9089 (defun org-agenda-set-property ()
9090 "Set a property for the current headline."
9092 (org-agenda-check-no-diary)
9093 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9094 (org-agenda-error)))
9095 (buffer (marker-buffer hdmarker))
9096 (pos (marker-position hdmarker))
9097 (inhibit-read-only t)
9099 (org-with-remote-undo buffer
9100 (with-current-buffer buffer
9104 (org-show-context 'agenda))
9106 (and (outline-next-heading)
9107 (org-flag-heading nil))) ; show the next heading
9109 (call-interactively 'org-set-property)))))
9111 (defun org-agenda-set-effort ()
9112 "Set the effort property for the current headline."
9114 (org-agenda-check-no-diary)
9115 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9116 (org-agenda-error)))
9117 (buffer (marker-buffer hdmarker))
9118 (pos (marker-position hdmarker))
9119 (inhibit-read-only t)
9121 (org-with-remote-undo buffer
9122 (with-current-buffer buffer
9126 (org-show-context 'agenda))
9128 (and (outline-next-heading)
9129 (org-flag-heading nil))) ; show the next heading
9131 (call-interactively 'org-set-effort)
9133 (setq newhead (org-get-heading)))
9134 (org-agenda-change-all-lines newhead hdmarker))))
9136 (defun org-agenda-toggle-archive-tag ()
9137 "Toggle the archive tag for the current entry."
9139 (org-agenda-check-no-diary)
9140 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
9141 (org-agenda-error)))
9142 (buffer (marker-buffer hdmarker))
9143 (pos (marker-position hdmarker))
9144 (inhibit-read-only t)
9146 (org-with-remote-undo buffer
9147 (with-current-buffer buffer
9150 (org-show-context 'agenda)
9152 (and (outline-next-heading)
9153 (org-flag-heading nil))) ; show the next heading
9154 (call-interactively 'org-toggle-archive-tag)
9156 (setq newhead (org-get-heading)))
9157 (org-agenda-change-all-lines newhead hdmarker)
9158 (beginning-of-line 1))))
9160 (defun org-agenda-do-date-later (arg)
9163 ((or (equal arg '(16))
9165 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9166 (setq this-command 'org-agenda-date-later-minutes)
9167 (org-agenda-date-later-minutes 1))
9168 ((or (equal arg '(4))
9170 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9171 (setq this-command 'org-agenda-date-later-hours)
9172 (org-agenda-date-later-hours 1))
9174 (org-agenda-date-later (prefix-numeric-value arg)))))
9176 (defun org-agenda-do-date-earlier (arg)
9179 ((or (equal arg '(16))
9181 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
9182 (setq this-command 'org-agenda-date-earlier-minutes)
9183 (org-agenda-date-earlier-minutes 1))
9184 ((or (equal arg '(4))
9186 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
9187 (setq this-command 'org-agenda-date-earlier-hours)
9188 (org-agenda-date-earlier-hours 1))
9190 (org-agenda-date-earlier (prefix-numeric-value arg)))))
9192 (defun org-agenda-date-later (arg &optional what)
9193 "Change the date of this item to ARG day(s) later."
9195 (org-agenda-check-type t 'agenda 'timeline)
9196 (org-agenda-check-no-diary)
9197 (let* ((marker (or (org-get-at-bol 'org-marker)
9198 (org-agenda-error)))
9199 (buffer (marker-buffer marker))
9200 (pos (marker-position marker))
9202 (org-with-remote-undo buffer
9203 (with-current-buffer buffer
9206 (if (not (org-at-timestamp-p))
9207 (error "Cannot find time stamp"))
9208 (when (and org-agenda-move-date-from-past-immediately-to-today
9210 (or (not what) (eq what 'day))
9211 (not (save-match-data (org-at-date-range-p))))
9212 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
9213 cdate (calendar-absolute-from-gregorian
9214 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
9217 ;; immediately shift to today
9218 (setq arg (- today cdate))))
9219 (org-timestamp-change arg (or what 'day))
9220 (when (and (org-at-date-range-p)
9221 (re-search-backward org-tr-regexp-both (point-at-bol)))
9222 (let ((end org-last-changed-timestamp))
9223 (org-timestamp-change arg (or what 'day))
9224 (setq org-last-changed-timestamp
9225 (concat org-last-changed-timestamp "--" end)))))
9226 (org-agenda-show-new-time marker org-last-changed-timestamp))
9227 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9229 (defun org-agenda-date-earlier (arg &optional what)
9230 "Change the date of this item to ARG day(s) earlier."
9232 (org-agenda-date-later (- arg) what))
9234 (defun org-agenda-date-later-minutes (arg)
9235 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9237 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9238 (org-agenda-date-later arg 'minute))
9240 (defun org-agenda-date-earlier-minutes (arg)
9241 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9243 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9244 (org-agenda-date-earlier arg 'minute))
9246 (defun org-agenda-date-later-hours (arg)
9247 "Change the time of this item, in hour steps."
9249 (org-agenda-date-later arg 'hour))
9251 (defun org-agenda-date-earlier-hours (arg)
9252 "Change the time of this item, in hour steps."
9254 (org-agenda-date-earlier arg 'hour))
9256 (defun org-agenda-show-new-time (marker stamp &optional prefix)
9257 "Show new date stamp via text properties."
9258 ;; We use text properties to make this undoable
9259 (let ((inhibit-read-only t))
9260 (setq stamp (concat prefix " => " stamp " "))
9262 (goto-char (point-max))
9264 (when (equal marker (org-get-at-bol 'org-marker))
9265 (remove-text-properties (point-at-bol) (point-at-eol) '(display))
9266 (org-move-to-column (- (window-width) (length stamp)) t)
9267 (if (featurep 'xemacs)
9268 ;; Use `duplicable' property to trigger undo recording
9269 (let ((ex (make-extent nil nil))
9270 (gl (make-glyph stamp)))
9271 (set-glyph-face gl 'secondary-selection)
9272 (set-extent-properties
9273 ex (list 'invisible t 'end-glyph gl 'duplicable t))
9274 (insert-extent ex (1- (point)) (point-at-eol)))
9275 (add-text-properties
9276 (1- (point)) (point-at-eol)
9277 (list 'display (org-add-props stamp nil
9278 'face '(secondary-selection default)))))
9279 (beginning-of-line 1))
9280 (beginning-of-line 0)))))
9282 (defun org-agenda-date-prompt (arg)
9283 "Change the date of this item. Date is prompted for, with default today.
9284 The prefix ARG is passed to the `org-time-stamp' command and can therefore
9285 be used to request time specification in the time stamp."
9287 (org-agenda-check-type t 'agenda 'timeline)
9288 (org-agenda-check-no-diary)
9289 (let* ((marker (or (org-get-at-bol 'org-marker)
9290 (org-agenda-error)))
9291 (buffer (marker-buffer marker))
9292 (pos (marker-position marker)))
9293 (org-with-remote-undo buffer
9294 (with-current-buffer buffer
9297 (if (not (org-at-timestamp-p t))
9298 (error "Cannot find time stamp"))
9299 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
9300 (org-agenda-show-new-time marker org-last-changed-timestamp))
9301 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9303 (defun org-agenda-schedule (arg &optional time)
9304 "Schedule the item at point.
9305 ARG is passed through to `org-schedule'."
9307 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9308 (org-agenda-check-no-diary)
9309 (let* ((marker (or (org-get-at-bol 'org-marker)
9310 (org-agenda-error)))
9311 (type (marker-insertion-type marker))
9312 (buffer (marker-buffer marker))
9313 (pos (marker-position marker))
9315 (set-marker-insertion-type marker t)
9316 (org-with-remote-undo buffer
9317 (with-current-buffer buffer
9320 (setq ts (org-schedule arg time)))
9321 (org-agenda-show-new-time marker ts " S"))
9324 (defun org-agenda-deadline (arg &optional time)
9325 "Schedule the item at point.
9326 ARG is passed through to `org-deadline'."
9328 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9329 (org-agenda-check-no-diary)
9330 (let* ((marker (or (org-get-at-bol 'org-marker)
9331 (org-agenda-error)))
9332 (buffer (marker-buffer marker))
9333 (pos (marker-position marker))
9335 (org-with-remote-undo buffer
9336 (with-current-buffer buffer
9339 (setq ts (org-deadline arg time)))
9340 (org-agenda-show-new-time marker ts " D"))
9343 (defun org-agenda-clock-in (&optional arg)
9344 "Start the clock on the currently selected item."
9346 (org-agenda-check-no-diary)
9347 (if (equal arg '(4))
9349 (let* ((marker (or (org-get-at-bol 'org-marker)
9350 (org-agenda-error)))
9351 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
9352 (pos (marker-position marker))
9353 (col (current-column))
9355 (org-with-remote-undo (marker-buffer marker)
9356 (with-current-buffer (marker-buffer marker)
9359 (org-show-context 'agenda)
9361 (org-cycle-hide-drawers 'children)
9363 (setq newhead (org-get-heading)))
9364 (org-agenda-change-all-lines newhead hdmarker))
9365 (org-move-to-column col))))
9367 (defun org-agenda-clock-out ()
9368 "Stop the currently running clock."
9370 (unless (marker-buffer org-clock-marker)
9371 (error "No running clock"))
9372 (let ((marker (make-marker)) (col (current-column)) newhead)
9373 (org-with-remote-undo (marker-buffer org-clock-marker)
9374 (with-current-buffer (marker-buffer org-clock-marker)
9378 (goto-char org-clock-marker)
9379 (org-back-to-heading t)
9380 (move-marker marker (point))
9382 (setq newhead (org-get-heading))))))
9383 (org-agenda-change-all-lines newhead marker)
9384 (move-marker marker nil)
9385 (org-move-to-column col)
9386 (org-agenda-unmark-clocking-task)))
9388 (defun org-agenda-clock-cancel (&optional arg)
9389 "Cancel the currently running clock."
9391 (unless (marker-buffer org-clock-marker)
9392 (user-error "No running clock"))
9393 (org-with-remote-undo (marker-buffer org-clock-marker)
9394 (org-clock-cancel)))
9396 (defun org-agenda-clock-goto ()
9397 "Jump to the currently clocked in task within the agenda.
9398 If the currently clocked in task is not listed in the agenda
9399 buffer, display it in another window."
9403 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
9404 (setq pos (overlay-start o))))
9405 (overlays-in (point-min) (point-max)))
9406 (cond (pos (goto-char pos))
9407 ;; If the currently clocked entry is not in the agenda
9408 ;; buffer, we visit it in another window:
9409 (org-clock-current-task
9410 (org-switch-to-buffer-other-window (org-clock-goto)))
9411 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
9413 (defun org-agenda-diary-entry-in-org-file ()
9414 "Make a diary entry in the file `org-agenda-diary-file'."
9415 (let (d1 d2 char (text "") dp1 dp2)
9416 (if (equal (buffer-name) "*Calendar*")
9417 (setq d1 (calendar-cursor-to-date t)
9418 d2 (car calendar-mark-ring))
9419 (setq dp1 (get-text-property (point-at-bol) 'day))
9420 (unless dp1 (user-error "No date defined in current line"))
9421 (setq d1 (calendar-gregorian-from-absolute dp1)
9422 d2 (and (ignore-errors (mark))
9425 (setq dp2 (get-text-property (point-at-bol) 'day)))
9426 (calendar-gregorian-from-absolute dp2))))
9427 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9428 (setq char (read-char-exclusive))
9431 (setq text (read-string "Day entry: "))
9432 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9433 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9435 (setq d1 (list (car d1) (nth 1 d1)
9436 (read-number (format "Reference year [%d]: " (nth 2 d1))
9438 (setq text (read-string "Anniversary (use %d to show years): "))
9439 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9440 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9442 (setq text (read-string "Block entry: "))
9443 (unless (and d1 d2 (not (equal d1 d2)))
9444 (user-error "No block of days selected"))
9445 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9446 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9448 (org-switch-to-buffer-other-window
9449 (find-file-noselect org-agenda-diary-file))
9450 (require 'org-datetree)
9451 (org-datetree-find-date-create d1)
9453 (t (user-error "Invalid selection character `%c'" char)))))
9455 (defcustom org-agenda-insert-diary-strategy 'date-tree
9456 "Where in `org-agenda-diary-file' should new entries be added?
9459 date-tree in the date tree, as first child of the date
9460 date-tree-last in the date tree, as last child of the date
9461 top-level as top-level entries at the end of the file."
9464 (const :tag "first in a date tree" date-tree)
9465 (const :tag "last in a date tree" date-tree-last)
9466 (const :tag "as top level at end of file" top-level)))
9468 (defcustom org-agenda-insert-diary-extract-time nil
9469 "Non-nil means extract any time specification from the diary entry."
9474 (defcustom org-agenda-bulk-mark-char ">"
9475 "A single-character string to be used as the bulk mark."
9480 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9481 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9482 If TEXT is not empty, it will become the headline of the new entry, and
9483 the resulting entry will not be shown. When TEXT is empty, switch to
9484 `org-agenda-diary-file' and let the user finish the entry there."
9485 (let ((cw (current-window-configuration)))
9486 (org-switch-to-buffer-other-window
9487 (find-file-noselect org-agenda-diary-file))
9489 (goto-char (point-min))
9491 ((eq type 'anniversary)
9492 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9494 (or (org-at-heading-p t)
9496 (outline-next-heading)
9497 (insert "* Anniversaries\n\n")
9498 (beginning-of-line -1)))))
9499 (outline-next-heading)
9500 (org-back-over-empty-lines)
9503 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9504 (nth 2 d1) (car d1) (nth 1 d1) text)))
9506 (let ((org-prefix-has-time t)
9507 (org-agenda-time-leading-zero t)
9509 (if org-agenda-insert-diary-extract-time
9510 ;; Use org-agenda-format-item to parse text for a time-range and
9511 ;; remove it. FIXME: This is a hack, we should refactor
9512 ;; that function to make time extraction available separately
9513 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9514 time (get-text-property 0 'time fmt)
9515 time2 (if (> (length time) 0)
9516 ;; split-string removes trailing ...... if
9517 ;; no end time given. First space
9518 ;; separates time from date.
9519 (concat " " (car (split-string time "\\.")))
9521 text (get-text-property 0 'txt fmt)))
9522 (if (eq org-agenda-insert-diary-strategy 'top-level)
9523 (org-agenda-insert-diary-as-top-level text)
9524 (require 'org-datetree)
9525 (org-datetree-find-date-create d1)
9526 (org-agenda-insert-diary-make-new-entry text))
9527 (org-insert-time-stamp (org-time-from-absolute
9528 (calendar-absolute-from-gregorian d1))
9529 nil nil nil nil time2))
9532 (if (> (calendar-absolute-from-gregorian d1)
9533 (calendar-absolute-from-gregorian d2))
9534 (setq d1 (prog1 d2 (setq d2 d1))))
9535 (if (eq org-agenda-insert-diary-strategy 'top-level)
9536 (org-agenda-insert-diary-as-top-level text)
9537 (require 'org-datetree)
9538 (org-datetree-find-date-create d1)
9539 (org-agenda-insert-diary-make-new-entry text))
9540 (org-insert-time-stamp (org-time-from-absolute
9541 (calendar-absolute-from-gregorian d1)))
9543 (org-insert-time-stamp (org-time-from-absolute
9544 (calendar-absolute-from-gregorian d2)))
9546 (if (string-match "\\S-" text)
9548 (set-window-configuration cw)
9549 (message "%s entry added to %s"
9550 (capitalize (symbol-name type))
9551 (abbreviate-file-name org-agenda-diary-file)))
9553 (message "Please finish entry here"))))
9555 (defun org-agenda-insert-diary-as-top-level (text)
9556 "Make new entry as a top-level entry at the end of the file.
9557 Add TEXT as headline, and position the cursor in the second line so that
9558 a timestamp can be added there."
9560 (goto-char (point-max))
9561 (unless (bolp) (insert "\n"))
9562 (org-insert-heading nil t t)
9564 (org-end-of-meta-data)
9565 (unless (bolp) (insert "\n"))
9566 (when org-adapt-indentation (org-indent-to-column 2)))
9568 (defun org-agenda-insert-diary-make-new-entry (text)
9569 "Make a new entry with TEXT as a child of the current subtree.
9570 Position the point in the heading's first body line so that
9571 a timestamp can be added there."
9573 ((eq org-agenda-insert-diary-strategy 'date-tree-last)
9575 (org-insert-heading '(4) t)
9578 (outline-next-heading)
9579 (org-back-over-empty-lines)
9580 (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
9581 (org-insert-heading nil t)
9583 (let ((col (current-column)))
9585 (org-end-of-meta-data)
9586 ;; Ensure point is left on a blank line, at proper indentation.
9587 (unless (bolp) (insert "\n"))
9588 (unless (org-looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
9589 (when org-adapt-indentation (org-indent-to-column col)))
9590 (org-show-set-visibility 'lineage))
9592 (defun org-agenda-diary-entry ()
9593 "Make a diary entry, like the `i' command from the calendar.
9594 All the standard commands work: block, weekly etc.
9595 When `org-agenda-diary-file' points to a file,
9596 `org-agenda-diary-entry-in-org-file' is called instead to create
9597 entries in that Org-mode file."
9599 (if (not (eq org-agenda-diary-file 'diary-file))
9600 (org-agenda-diary-entry-in-org-file)
9601 (require 'diary-lib)
9603 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9604 (read-char-exclusive)))
9605 (cmd (cdr (assoc char
9606 '((?d . diary-insert-entry)
9607 (?w . diary-insert-weekly-entry)
9608 (?m . diary-insert-monthly-entry)
9609 (?y . diary-insert-yearly-entry)
9610 (?a . diary-insert-anniversary-entry)
9611 (?b . diary-insert-block-entry)
9612 (?c . diary-insert-cyclic-entry)))))
9613 (oldf (symbol-function 'calendar-cursor-to-date))
9614 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9616 (mark (or (mark t) (point))))
9618 (user-error "No command associated with <%c>" char))
9619 (unless (and (get-text-property point 'day)
9620 (or (not (equal ?b char))
9621 (get-text-property mark 'day)))
9622 (user-error "Don't know which date to use for diary entry"))
9623 ;; We implement this by hacking the `calendar-cursor-to-date' function
9624 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9625 (let ((calendar-mark-ring
9626 (list (calendar-gregorian-from-absolute
9627 (or (get-text-property mark 'day)
9628 (get-text-property point 'day))))))
9631 (fset 'calendar-cursor-to-date
9632 (lambda (&optional error dummy)
9633 (calendar-gregorian-from-absolute
9634 (get-text-property point 'day))))
9635 (call-interactively cmd))
9636 (fset 'calendar-cursor-to-date oldf))))))
9638 (defun org-agenda-execute-calendar-command (cmd)
9639 "Execute a calendar command from the agenda with date from cursor."
9640 (org-agenda-check-type t 'agenda 'timeline)
9641 (require 'diary-lib)
9642 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9643 (user-error "Don't know which date to use for the calendar command"))
9644 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9646 (date (calendar-gregorian-from-absolute
9647 (get-text-property point 'day)))
9648 ;; the following 2 vars are needed in the calendar
9649 (displayed-month (car date))
9650 (displayed-year (nth 2 date)))
9653 (fset 'calendar-cursor-to-date
9654 (lambda (&optional error dummy)
9655 (calendar-gregorian-from-absolute
9656 (get-text-property point 'day))))
9657 (call-interactively cmd))
9658 (fset 'calendar-cursor-to-date oldf))))
9660 (defun org-agenda-phases-of-moon ()
9661 "Display the phases of the moon for the 3 months around the cursor date."
9663 (org-agenda-execute-calendar-command 'calendar-lunar-phases))
9665 (defun org-agenda-holidays ()
9666 "Display the holidays for the 3 months around the cursor date."
9668 (org-agenda-execute-calendar-command 'calendar-list-holidays))
9670 (defvar calendar-longitude) ; defined in calendar.el
9671 (defvar calendar-latitude) ; defined in calendar.el
9672 (defvar calendar-location-name) ; defined in calendar.el
9674 (defun org-agenda-sunrise-sunset (arg)
9675 "Display sunrise and sunset for the cursor date.
9676 Latitude and longitude can be specified with the variables
9677 `calendar-latitude' and `calendar-longitude'. When called with prefix
9678 argument, latitude and longitude will be prompted for."
9681 (let ((calendar-longitude (if arg nil calendar-longitude))
9682 (calendar-latitude (if arg nil calendar-latitude))
9683 (calendar-location-name
9684 (if arg "the given coordinates" calendar-location-name)))
9685 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9687 (defun org-agenda-goto-calendar ()
9688 "Open the Emacs calendar with the date at the cursor."
9690 (org-agenda-check-type t 'agenda 'timeline)
9691 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9692 (user-error "Don't know which date to open in calendar")))
9693 (date (calendar-gregorian-from-absolute day))
9694 (calendar-move-hook nil)
9695 (calendar-view-holidays-initially-flag nil)
9696 (calendar-view-diary-initially-flag nil))
9698 (calendar-goto-date date)))
9701 (defun org-calendar-goto-agenda ()
9702 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9703 This is a command that has to be installed in `calendar-mode-map'."
9705 ;; Temporarily disable sticky agenda since user clearly wants to
9706 ;; refresh view anyway.
9707 (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
9708 (org-agenda-sticky nil))
9709 (org-agenda-list nil (calendar-absolute-from-gregorian
9710 (calendar-cursor-to-date))
9713 (defun org-agenda-convert-date ()
9715 (org-agenda-check-type t 'agenda 'timeline)
9716 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9719 (user-error "Don't know which date to convert"))
9720 (setq date (calendar-gregorian-from-absolute day))
9722 "Gregorian: " (calendar-date-string date) "\n"
9723 "ISO: " (calendar-iso-date-string date) "\n"
9724 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9725 "Julian: " (calendar-julian-date-string date) "\n"
9726 "Astron. JD: " (calendar-astro-date-string date)
9727 " (Julian date number at noon UTC)\n"
9728 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9729 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9730 "French: " (calendar-french-date-string date) "\n"
9731 "Bahá’Ã: " (calendar-bahai-date-string date) " (until sunset)\n"
9732 "Mayan: " (calendar-mayan-date-string date) "\n"
9733 "Coptic: " (calendar-coptic-date-string date) "\n"
9734 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9735 "Persian: " (calendar-persian-date-string date) "\n"
9736 "Chinese: " (calendar-chinese-date-string date) "\n"))
9737 (with-output-to-temp-buffer "*Dates*"
9739 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9743 (defun org-agenda-bulk-marked-p ()
9744 (eq (get-char-property (point-at-bol) 'type)
9745 'org-marked-entry-overlay))
9747 (defun org-agenda-bulk-mark (&optional arg)
9748 "Mark the entry at point for future bulk action."
9750 (dotimes (i (or arg 1))
9751 (unless (org-get-at-bol 'org-agenda-diary-link)
9752 (let* ((m (org-get-at-bol 'org-hd-marker))
9754 (unless (org-agenda-bulk-marked-p)
9755 (unless m (user-error "Nothing to mark at point"))
9756 (push m org-agenda-bulk-marked-entries)
9757 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9758 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9759 (org-get-todo-face "TODO")
9761 (overlay-put ov 'type 'org-marked-entry-overlay))
9764 (goto-char (next-single-property-change (point) 'org-hd-marker)))
9765 (beginning-of-line 2))
9766 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9767 (beginning-of-line 2))
9768 (message "%d entries marked for bulk action"
9769 (length org-agenda-bulk-marked-entries))))))
9771 (defun org-agenda-bulk-mark-all ()
9772 "Mark all entries for future agenda bulk action."
9774 (org-agenda-bulk-mark-regexp "."))
9776 (defun org-agenda-bulk-mark-regexp (regexp)
9777 "Mark entries matching REGEXP for future agenda bulk action."
9778 (interactive "sMark entries matching regexp: ")
9779 (let ((entries-marked 0) txt-at-point)
9781 (goto-char (point-min))
9782 (goto-char (next-single-property-change (point) 'org-hd-marker))
9783 (while (and (re-search-forward regexp nil t)
9784 (setq txt-at-point (get-text-property (point) 'txt)))
9785 (when (string-match regexp txt-at-point)
9786 (setq entries-marked (1+ entries-marked))
9787 (call-interactively 'org-agenda-bulk-mark))))
9788 (if (not entries-marked)
9789 (message "No entry matching this regexp."))))
9791 (defun org-agenda-bulk-unmark (&optional arg)
9792 "Unmark the entry at point for future bulk action."
9795 (org-agenda-bulk-unmark-all)
9796 (cond ((org-agenda-bulk-marked-p)
9797 (org-agenda-bulk-remove-overlays
9798 (point-at-bol) (+ 2 (point-at-bol)))
9799 (setq org-agenda-bulk-marked-entries
9800 (delete (org-get-at-bol 'org-hd-marker)
9801 org-agenda-bulk-marked-entries))
9804 (goto-char (next-single-property-change (point) 'txt)))
9805 (beginning-of-line 2))
9806 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9807 (beginning-of-line 2))
9808 (message "%d entries left marked for bulk action"
9809 (length org-agenda-bulk-marked-entries)))
9810 (t (message "No entry to unmark here")))))
9812 (defun org-agenda-bulk-toggle-all ()
9813 "Toggle all marks for bulk action."
9816 (goto-char (point-min))
9817 (while (ignore-errors
9818 (goto-char (next-single-property-change (point) 'org-hd-marker)))
9819 (org-agenda-bulk-toggle))))
9821 (defun org-agenda-bulk-toggle ()
9822 "Toggle the mark at point for bulk action."
9824 (if (org-agenda-bulk-marked-p)
9825 (org-agenda-bulk-unmark)
9826 (org-agenda-bulk-mark)))
9828 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9829 "Remove the mark overlays between BEG and END in the agenda buffer.
9830 BEG and END default to the buffer limits.
9832 This only removes the overlays, it does not remove the markers
9833 from the list in `org-agenda-bulk-marked-entries'."
9836 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9837 (delete-overlay ov)))
9838 (overlays-in (or beg (point-min)) (or end (point-max)))))
9840 (defun org-agenda-bulk-unmark-all ()
9841 "Remove all marks in the agenda buffer.
9842 This will remove the markers and the overlays."
9844 (if (null org-agenda-bulk-marked-entries)
9845 (message "No entry to unmark")
9846 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9847 (setq org-agenda-bulk-marked-entries nil)
9848 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9850 (defcustom org-agenda-persistent-marks nil
9851 "Non-nil means marked items will stay marked after a bulk action.
9852 You can toggle this interactively by typing `p' when prompted for a
9858 (defun org-agenda-bulk-action (&optional arg)
9859 "Execute an remote-editing action on all marked entries.
9860 The prefix arg is passed through to the command if possible."
9862 ;; Make sure we have markers, and only valid ones
9863 (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
9866 (unless (and (markerp m)
9868 (buffer-live-p (marker-buffer m))
9869 (marker-position m))
9870 (user-error "Marker %s for bulk command is invalid" m)))
9871 org-agenda-bulk-marked-entries)
9873 ;; Prompt for the bulk command
9874 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9875 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9876 "[S]catter [f]unction "
9877 (when org-agenda-bulk-custom-functions
9878 (concat " Custom: ["
9879 (mapconcat (lambda(f) (char-to-string (car f)))
9880 org-agenda-bulk-custom-functions "")
9883 (let* ((action (read-char-exclusive))
9884 (org-log-refile (if org-log-refile 'time nil))
9885 (entries (reverse org-agenda-bulk-marked-entries))
9886 (org-overriding-default-time
9887 (if (get-text-property (point) 'org-agenda-date-header)
9888 (org-get-cursor-date)))
9890 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9893 (let ((org-agenda-persistent-marks
9894 (not org-agenda-persistent-marks)))
9895 (org-agenda-bulk-action)
9899 (setq cmd '(org-agenda-archive)))
9902 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9904 ((member action '(?r ?w))
9905 (setq rfloc (org-refile-get-location
9907 (marker-buffer (car entries))
9908 org-refile-allow-creating-parent-nodes))
9910 (setcar (nthcdr 3 rfloc)
9911 (move-marker (make-marker) (nth 3 rfloc)
9912 (or (get-file-buffer (nth 1 rfloc))
9913 (find-buffer-visiting (nth 1 rfloc))
9914 (error "This should not happen")))))
9916 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9920 (setq state (completing-read
9922 (with-current-buffer (marker-buffer (car entries))
9923 (mapcar #'list org-todo-keywords-1))))
9924 (setq cmd `(let ((org-inhibit-blocking t)
9925 (org-inhibit-logging 'note))
9926 (org-agenda-todo ,state))))
9928 ((memq action '(?- ?+))
9929 (setq tag (completing-read
9930 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9931 (with-current-buffer (marker-buffer (car entries))
9934 (if (stringp (car x)) x)) org-tag-alist)))))
9935 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9937 ((memq action '(?s ?d))
9942 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9943 org-overriding-default-time)))
9944 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9945 (setq cmd `(eval '(,c1 arg ,time)))))
9948 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9949 (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9950 (let ((days (read-number
9951 (format "Scatter tasks across how many %sdays: "
9952 (if arg "week" "")) 7)))
9954 `(let ((distance (1+ (random ,days))))
9956 (let ((dist distance)
9958 (calendar-day-of-week
9959 (calendar-gregorian-from-absolute (org-today)))))
9960 (dotimes (i (1+ dist))
9961 (while (member day-of-week org-agenda-weekend-days)
9964 (if (= day-of-week 7)
9965 (setq day-of-week 0)))
9967 (if (= day-of-week 7)
9968 (setq day-of-week 0)))))
9969 ;; silently fail when try to replan a sexp entry
9971 (let* ((date (calendar-gregorian-from-absolute
9972 (+ (org-today) distance)))
9973 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9975 (org-agenda-schedule nil time))
9978 ((assoc action org-agenda-bulk-custom-functions)
9979 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9983 (setq cmd (list (intern
9984 (completing-read "Function: "
9985 obarray 'fboundp t nil nil)))))
9987 (t (user-error "Invalid bulk action")))
9989 ;; Sort the markers, to make sure that parents are handled before children
9990 (setq entries (sort entries
9993 ((equal (marker-buffer a) (marker-buffer b))
9994 (< (marker-position a) (marker-position b)))
9996 (string< (buffer-name (marker-buffer a))
9997 (buffer-name (marker-buffer b))))))))
9999 ;; Now loop over all markers and apply cmd
10000 (while (setq e (pop entries))
10001 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
10003 (progn (message "Skipping removed entry at %s" e)
10004 (setq cntskip (1+ cntskip)))
10006 (let (org-loop-over-headlines-in-active-region)
10008 ;; `post-command-hook' is not run yet. We make sure any
10009 ;; pending log note is processed.
10010 (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
10011 (memq 'org-add-log-note post-command-hook))
10012 (org-add-log-note))
10013 (setq cnt (1+ cnt))))
10014 (when redo-at-end (org-agenda-redo))
10015 (unless org-agenda-persistent-marks
10016 (org-agenda-bulk-unmark-all))
10017 (message "Acted on %d entries%s%s"
10021 (format ", skipped %d (disappeared before their turn)"
10023 (if (not org-agenda-persistent-marks)
10024 "" " (kept marked)"))))))
10026 (defun org-agenda-capture (&optional with-time)
10027 "Call `org-capture' with the date at point.
10028 With a `C-1' prefix, use the HH:MM value at point (if any) or the
10029 current HH:MM time."
10031 (if (not (eq major-mode 'org-agenda-mode))
10032 (user-error "You cannot do this outside of agenda buffers")
10033 (let ((org-overriding-default-time
10034 (org-get-cursor-date (equal with-time 1))))
10035 (call-interactively 'org-capture))))
10037 ;;; Dragging agenda lines forward/backward
10039 (defun org-agenda-reapply-filters ()
10040 "Re-apply all agenda filters."
10042 (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
10043 `((,org-agenda-tag-filter tag)
10044 (,org-agenda-category-filter category)
10045 (,org-agenda-regexp-filter regexp)
10046 (,org-agenda-effort-filter effort)
10047 (,(get 'org-agenda-tag-filter :preset-filter) tag)
10048 (,(get 'org-agenda-category-filter :preset-filter) category)
10049 (,(get 'org-agenda-effort-filter :preset-filter) effort)
10050 (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
10052 (defun org-agenda-drag-line-forward (arg &optional backward)
10053 "Drag an agenda line forward by ARG lines.
10054 When the optional argument `backward' is non-nil, move backward."
10056 (let ((inhibit-read-only t) lst line)
10057 (if (or (not (get-text-property (point) 'txt))
10060 (move-beginning-of-line (if backward 0 2))
10061 (push (not (get-text-property (point) 'txt)) lst))
10063 (message "Cannot move line forward")
10064 (let ((end (save-excursion (move-beginning-of-line 2) (point))))
10065 (move-beginning-of-line 1)
10066 (setq line (buffer-substring (point) end))
10067 (delete-region (point) end)
10068 (move-beginning-of-line (funcall (if backward '1- '1+) arg))
10070 (org-agenda-reapply-filters)
10071 (org-agenda-mark-clocking-task)
10072 (move-beginning-of-line 0)))))
10074 (defun org-agenda-drag-line-backward (arg)
10075 "Drag an agenda line backward by ARG lines."
10077 (org-agenda-drag-line-forward arg t))
10081 (defun org-agenda-show-the-flagging-note ()
10082 "Display the flagging note in the other window.
10083 When called a second time in direct sequence, offer to remove the FLAGGING
10084 tag and (if present) the flagging note."
10086 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
10087 (win (selected-window))
10088 note heading newhead)
10090 (user-error "No linked entry at point"))
10091 (if (and (eq this-command last-command)
10092 (y-or-n-p "Unflag and remove any flagging note? "))
10094 (org-agenda-remove-flag hdmarker)
10095 (let ((win (get-buffer-window "*Flagging Note*")))
10096 (and win (delete-window win)))
10097 (message "Entry unflagged"))
10098 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
10100 (user-error "No flagging note"))
10101 (org-kill-new note)
10102 (org-switch-to-buffer-other-window "*Flagging Note*")
10105 (goto-char (point-min))
10106 (while (re-search-forward "\\\\n" nil t)
10107 (replace-match "\n" t t))
10108 (goto-char (point-min))
10109 (select-window win)
10110 (message (substitute-command-keys "Flagging note pushed to kill ring. \
10111 Press \\[org-agenda-show-the-flagging-note] again to remove tag and note")))))
10113 (defun org-agenda-remove-flag (marker)
10114 "Remove the FLAGGED tag and any flagging note in the entry."
10116 (org-with-point-at marker
10117 (org-toggle-tag "FLAGGED" 'off)
10118 (org-entry-delete nil "THEFLAGGINGNOTE")
10119 (setq newhead (org-get-heading)))
10120 (org-agenda-change-all-lines newhead marker)
10121 (message "Entry unflagged")))
10123 (defun org-agenda-get-any-marker (&optional pos)
10124 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
10125 (get-text-property (or pos (point-at-bol)) 'org-marker)))
10127 ;;; Appointment reminders
10129 (defvar appt-time-msg-list) ; defined in appt.el
10132 (defun org-agenda-to-appt (&optional refresh filter &rest args)
10133 "Activate appointments found in `org-agenda-files'.
10134 With a \\[universal-argument] prefix, refresh the list of
10137 If FILTER is t, interactively prompt the user for a regular
10138 expression, and filter out entries that don't match it.
10140 If FILTER is a string, use this string as a regular expression
10141 for filtering entries out.
10143 If FILTER is a function, filter out entries against which
10144 calling the function returns nil. This function takes one
10145 argument: an entry from `org-agenda-get-day-entries'.
10147 FILTER can also be an alist with the car of each cell being
10148 either `headline' or `category'. For example:
10150 \\='((headline \"IMPORTANT\")
10151 (category \"Work\"))
10153 will only add headlines containing IMPORTANT or headlines
10154 belonging to the \"Work\" category.
10156 ARGS are symbols indicating what kind of entries to consider.
10157 By default `org-agenda-to-appt' will use :deadline*, :scheduled*
10158 \(i.e., deadlines and scheduled items with a hh:mm specification)
10159 and :timestamp entries. See the docstring of `org-diary' for
10160 details and examples.
10162 If an entry has a APPT_WARNTIME property, its value will be used
10163 to override `appt-message-warning-time'."
10165 (if refresh (setq appt-time-msg-list nil))
10167 (setq filter (read-from-minibuffer "Regexp filter: ")))
10168 (let* ((cnt 0) ; count added events
10169 (scope (or args '(:deadline* :scheduled* :timestamp)))
10170 (org-agenda-new-buffers nil)
10171 (org-deadline-warning-days 0)
10172 ;; Do not use `org-today' here because appt only takes
10173 ;; time and without date as argument, so it may pass wrong
10174 ;; information otherwise
10175 (today (org-date-to-gregorian
10176 (time-to-days (current-time))))
10177 (org-agenda-restrict nil)
10178 (files (org-agenda-files 'unrestricted)) entries file
10179 (org-agenda-buffer nil))
10180 ;; Get all entries which may contain an appt
10181 (org-agenda-prepare-buffers files)
10182 (while (setq file (pop files))
10186 (apply 'org-agenda-get-day-entries
10187 file today scope)))))
10188 ;; Map thru entries and find if we should filter them out
10191 (let* ((evt (org-trim
10192 (replace-regexp-in-string
10193 org-bracket-link-regexp "\\3"
10194 (or (get-text-property 1 'txt x) ""))))
10195 (cat (get-text-property (1- (length x)) 'org-category x))
10196 (tod (get-text-property 1 'time-of-day x))
10197 (ok (or (null filter)
10198 (and (stringp filter) (string-match filter evt))
10199 (and (functionp filter) (funcall filter x))
10200 (and (listp filter)
10201 (let ((cat-filter (cadr (assoc 'category filter)))
10202 (evt-filter (cadr (assoc 'headline filter))))
10203 (or (and (stringp cat-filter)
10204 (string-match cat-filter cat))
10205 (and (stringp evt-filter)
10206 (string-match evt-filter evt)))))))
10207 (wrn (get-text-property 1 'warntime x)))
10208 ;; FIXME: Shall we remove text-properties for the appt text?
10209 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
10210 (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
10211 (setq tod (concat "00" (number-to-string tod))
10212 tod (when (string-match
10213 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
10214 (concat (match-string 1 tod) ":"
10215 (match-string 2 tod))))
10216 (if (version< emacs-version "23.3")
10218 (appt-add tod evt wrn))
10219 (setq cnt (1+ cnt))))) entries)
10220 (org-release-buffers org-agenda-new-buffers)
10222 (message "No event to add")
10223 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
10225 (defun org-agenda-today-p (date)
10226 "Non nil when DATE means today.
10227 DATE is either a list of the form (month day year) or a number of
10228 days as returned by `calendar-absolute-from-gregorian' or
10229 `org-today'. This function considers `org-extend-today-until'
10230 when defining today."
10232 (if (consp date) (calendar-absolute-from-gregorian date) date)))
10233 (define-obsolete-function-alias 'org-agenda-todayp 'org-agenda-today-p "25.1")
10235 (defun org-agenda-todo-yesterday (&optional arg)
10236 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
10238 (let* ((org-use-effective-time t)
10239 (hour (third (decode-time
10240 (org-current-time))))
10241 (org-extend-today-until (1+ hour)))
10242 (org-agenda-todo arg)))
10244 (provide 'org-agenda)
10246 ;;; org-agenda.el ends here